29 #include <ndn-cxx/util/random.hpp>
43 NDN_THROW(std::invalid_argument(
"RandomStrategy does not accept parameters"));
46 NDN_THROW(std::invalid_argument(
47 "RandomStrategy does not support version " + to_string(*parsed.
version)));
55 static const auto strategyName = Name(
"/localhost/nfd/strategy/random").appendVersion(1);
61 const shared_ptr<pit::Entry>& pitEntry)
67 [&] (
const auto& nh) { return isNextHopEligible(ingress.face, interest, nh, pitEntry); });
70 NFD_LOG_DEBUG(interest <<
" from=" << ingress <<
" no nexthop");
72 lp::NackHeader nackHeader;
73 nackHeader.setReason(lp::NackReason::NO_ROUTE);
79 std::shuffle(nhs.begin(), nhs.end(), ndn::random::getRandomNumberEngine());
80 this->
sendInterest(interest, nhs.front().getFace(), pitEntry);
85 const shared_ptr<pit::Entry>& pitEntry)
Represents a face-endpoint pair in the forwarder.
Main class of NFD's forwarding engine.
const NextHopList & getNextHops() const
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())
Represents a forwarding strategy.
void setInstanceName(const Name &name)
Set strategy instance name.
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.
static Name makeInstanceName(const Name &input, const Name &strategyName)
Construct a strategy instance name.
This file contains common algorithms used by forwarding strategies.
#define NFD_LOG_INIT(name)
std::vector< NextHop > NextHopList
NFD_REGISTER_STRATEGY(SelfLearningStrategy)
Copyright (c) 2014-2015, Regents of the University of California, Arizona Board of Regents,...
optional< uint64_t > version
whether strategyName contains a version component
PartialName parameters
parameter components