29 #include <ndn-cxx/util/random.hpp>
42 NDN_THROW(std::invalid_argument(
"RandomStrategy does not accept parameters"));
45 NDN_THROW(std::invalid_argument(
"RandomStrategy does not support version " +
46 std::to_string(*parsed.
version)));
54 static const auto strategyName = Name(
"/localhost/nfd/strategy/random").appendVersion(1);
60 const shared_ptr<pit::Entry>& pitEntry)
66 [&] (
const auto& nh) { return isNextHopEligible(ingress.face, interest, nh, pitEntry); });
70 lp::NackHeader nackHeader;
71 nackHeader.setReason(lp::NackReason::NO_ROUTE);
77 std::shuffle(nhs.begin(), nhs.end(), ndn::random::getRandomNumberEngine());
78 this->
sendInterest(interest, nhs.front().getFace(), pitEntry);
83 const shared_ptr<pit::Entry>& pitEntry)
This file contains common algorithms used by forwarding strategies.
Represents a face-endpoint pair in the forwarder.
Main class of NFD's forwarding engine.
Represents an entry in the FIB.
const NextHopList & getNextHops() const noexcept
void processNack(const lp::Nack &nack, const Face &inFace, const shared_ptr< pit::Entry > &pitEntry)
A forwarding strategy that randomly chooses a nexthop.
static const Name & getStrategyName()
void afterReceiveNack(const lp::Nack &nack, const FaceEndpoint &ingress, const shared_ptr< pit::Entry > &pitEntry) override
Trigger after a Nack is received.
void afterReceiveInterest(const Interest &interest, const FaceEndpoint &ingress, const shared_ptr< pit::Entry > &pitEntry) override
Trigger after an Interest is received.
RandomStrategy(Forwarder &forwarder, const Name &name=getStrategyName())
Base class of all forwarding strategies.
void rejectPendingInterest(const shared_ptr< pit::Entry > &pitEntry)
Schedule the PIT entry for immediate deletion.
const fib::Entry & lookupFib(const pit::Entry &pitEntry) const
Performs a FIB lookup, considering Link object if present.
bool sendNack(const lp::NackHeader &header, Face &egress, const shared_ptr< pit::Entry > &pitEntry)
Send a Nack packet.
pit::OutRecord * sendInterest(const Interest &interest, Face &egress, const shared_ptr< pit::Entry > &pitEntry)
Send an Interest packet.
static ParsedInstanceName parseInstanceName(const Name &input)
Parse a strategy instance name.
void setInstanceName(const Name &name) noexcept
Set strategy instance name.
static Name makeInstanceName(const Name &input, const Name &strategyName)
Construct a strategy instance name.
#define NFD_LOG_INIT(name)
std::vector< NextHop > NextHopList
A collection of nexthops in a FIB entry.
NFD_REGISTER_STRATEGY(SelfLearningStrategy)
#define NFD_LOG_INTEREST_FROM(interest, ingress, msg)
Logs the reception of interest on ingress, followed by msg, at DEBUG level.
std::optional< uint64_t > version
The strategy version number, if present.
PartialName parameters
Parameter components, may be empty.