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 Name strategyName(
"/localhost/nfd/strategy/random/%FD%01");
61 const shared_ptr<pit::Entry>& pitEntry)
68 [&] (
const auto& nh) {
return isNextHopEligible(inFace, interest, nh, pitEntry); });
71 NFD_LOG_DEBUG(interest <<
" from=" << ingress <<
" no nexthop");
73 lp::NackHeader nackHeader;
74 nackHeader.setReason(lp::NackReason::NO_ROUTE);
75 this->
sendNack(pitEntry, ingress, nackHeader);
80 std::shuffle(nhs.begin(), nhs.end(), ndn::random::getRandomNumberEngine());
86 const shared_ptr<pit::Entry>& pitEntry)
Main class of NFD's forwarding engine.
void setInstanceName(const Name &name)
set strategy instance name
void sendNack(const shared_ptr< pit::Entry > &pitEntry, const FaceEndpoint &egress, const lp::NackHeader &header)
send Nack to egress
static Name makeInstanceName(const Name &input, const Name &strategyName)
construct a strategy instance name
const fib::Entry & lookupFib(const pit::Entry &pitEntry) const
performs a FIB lookup, considering Link object if present
void afterReceiveInterest(const FaceEndpoint &ingress, const Interest &interest, const shared_ptr< pit::Entry > &pitEntry) override
trigger after Interest is received
void sendInterest(const shared_ptr< pit::Entry > &pitEntry, const FaceEndpoint &egress, const Interest &interest)
send Interest to egress
Represents a face-endpoint pair in the forwarder.
void afterReceiveNack(const FaceEndpoint &ingress, const lp::Nack &nack, const shared_ptr< pit::Entry > &pitEntry) override
trigger after Nack is received
Copyright (c) 2014-2015, Regents of the University of California, Arizona Board of Regents...
bool isNextHopEligible(const Face &inFace, const Interest &interest, const fib::NextHop &nexthop, const shared_ptr< pit::Entry > &pitEntry, bool wantUnused, time::steady_clock::TimePoint now)
determines whether a NextHop is eligible i.e.
generalization of a network interface
Represents a collection of nexthops.
PartialName parameters
parameter components
RandomStrategy(Forwarder &forwarder, const Name &name=getStrategyName())
represents a forwarding strategy
This file contains common algorithms used by forwarding strategies.
const NextHopList & getNextHops() const
#define NFD_LOG_INIT(name)
static ParsedInstanceName parseInstanceName(const Name &input)
parse a strategy instance name
void processNack(const Face &inFace, const lp::Nack &nack, const shared_ptr< pit::Entry > &pitEntry)
NFD_REGISTER_STRATEGY(SelfLearningStrategy)
static const Name & getStrategyName()
void rejectPendingInterest(const shared_ptr< pit::Entry > &pitEntry)
schedule the PIT entry for immediate deletion
optional< uint64_t > version
whether strategyName contains a version component