44 BOOST_THROW_EXCEPTION(std::invalid_argument(
"NccStrategy does not accept parameters"));
47 BOOST_THROW_EXCEPTION(std::invalid_argument(
48 "NccStrategy does not support version " + std::to_string(*parsed.
version)));
56 static Name strategyName(
"/localhost/nfd/strategy/ncc/%FD%01");
62 const shared_ptr<pit::Entry>& pitEntry)
66 if (nexthops.size() == 0) {
81 size_t nUpstreams = nexthops.size();
84 if (bestFace !=
nullptr && fibEntry.
hasNextHop(*bestFace) &&
89 deferRange = time::microseconds((deferFirst.count() + 1) / 2);
98 auto firstEligibleNexthop = std::find_if(nexthops.begin(), nexthops.end(),
100 Face& outFace = nexthop.getFace();
104 if (firstEligibleNexthop != nexthops.end()) {
105 this->
sendInterest(pitEntry, firstEligibleNexthop->getFace(), interest);
113 shared_ptr<Face> previousFace = meInfo.
previousFace.lock();
114 if (previousFace !=
nullptr && fibEntry.
hasNextHop(*previousFace) &&
120 if (nUpstreams > 0) {
121 pitEntryInfo->
maxInterval = std::max(time::microseconds(1),
122 time::microseconds((2 * deferRange.count() + nUpstreams - 1) / nUpstreams));
137 Face* inFace = this->
getFace(inFaceId);
138 if (inFace ==
nullptr) {
141 shared_ptr<pit::Entry> pitEntry = pitEntryWeak.lock();
142 if (pitEntry ==
nullptr) {
145 pit::InRecordCollection::const_iterator inRecord = pitEntry->getInRecord(*inFace);
146 if (inRecord == pitEntry->in_end()) {
149 const Interest& interest = inRecord->getInterest();
155 BOOST_ASSERT(pitEntryInfo !=
nullptr);
159 shared_ptr<Face> previousFace = meInfo.
previousFace.lock();
160 if (previousFace !=
nullptr && fibEntry.
hasNextHop(*previousFace) &&
167 bool isForwarded =
false;
168 for (fib::NextHopList::const_iterator it = nexthops.begin(); it != nexthops.end(); ++it) {
169 Face& face = it->getFace();
179 std::uniform_int_distribution<time::nanoseconds::rep> dist(0, pitEntryInfo->
maxInterval.count() - 1);
180 time::nanoseconds deferNext = time::nanoseconds(dist(
getGlobalRng()));
189 shared_ptr<pit::Entry> pitEntry = pitEntryWeak.lock();
190 if (pitEntry ==
nullptr) {
196 if (measurementsEntry ==
nullptr) {
205 measurementsEntry = this->
getMeasurements().getParent(*measurementsEntry);
211 const Face& inFace,
const Data& data)
213 if (!pitEntry->hasInRecords()) {
222 if (measurementsEntry ==
nullptr) {
231 measurementsEntry = this->
getMeasurements().getParent(*measurementsEntry);
235 if (pitEntryInfo !=
nullptr) {
242 if (bestFace.get() == &inFace)
257 BOOST_ASSERT(entry !=
nullptr);
266 if (parentEntry !=
nullptr) {
279 : prediction(INITIAL_PREDICTION)
286 this->operator=(other);
292 shared_ptr<Face> best = this->
bestFace.lock();
293 if (best !=
nullptr) {
304 this->
bestFace =
const_cast<Face&
>(face).shared_from_this();
307 shared_ptr<Face>
bestFace = this->bestFace.lock();
308 if (bestFace.get() == &face) {
309 this->adjustPredictDown();
313 this->bestFace =
const_cast<Face&
>(face).shared_from_this();
318 NccStrategy::MeasurementsEntryInfo::adjustPredictDown()
332 NccStrategy::MeasurementsEntryInfo::ageBestFace()
bool canForwardToLegacy(const pit::Entry &pitEntry, const Face &face)
decide whether Interest can be forwarded to face
static const int ADJUST_PREDICT_UP_SHIFT
bool hasNextHop(const Face &face) const
void timeoutOnBestFace(weak_ptr< pit::Entry > pitEntryWeak)
best face did not reply within prediction
void setInstanceName(const Name &name)
set strategy instance name
time::microseconds maxInterval
maximum interval between forwarding to two nexthops except best and previous
weak_ptr< Face > bestFace
weak_ptr< Face > previousFace
represents a Measurements entry
static const int UPDATE_MEASUREMENTS_N_LEVELS
void cancel(const EventId &eventId)
cancel a scheduled event
time::microseconds prediction
virtual void beforeSatisfyInterest(const shared_ptr< pit::Entry > &pitEntry, const Face &inFace, const Data &data) override
trigger before PIT entry is satisfied
scheduler::EventId bestFaceTimeout
timer that expires when best face does not respond within predicted time
void sendInterest(const shared_ptr< pit::Entry > &pitEntry, Face &outFace, const Interest &interest)
send Interest to outFace
static const time::nanoseconds MEASUREMENTS_LIFETIME
StrategyInfo on pit::Entry.
static Name makeInstanceName(const Name &input, const Name &strategyName)
construct a strategy instance name
std::pair< T *, bool > insertStrategyInfo(A &&...args)
insert a StrategyInfo item
void doPropagate(FaceId inFaceId, weak_ptr< pit::Entry > pitEntryWeak)
propagate to another upstream
MeasurementsAccessor & getMeasurements()
#define NFD_REGISTER_STRATEGY(S)
registers a strategy
shared_ptr< Face > getBestFace()
MeasurementsEntryInfo & getMeasurementsEntryInfo(measurements::Entry *entry)
scheduler::EventId propagateTimer
timer for propagating to another face
void inheritFrom(const MeasurementsEntryInfo &other)
Copyright (c) 2014-2015, Regents of the University of California, Arizona Board of Regents...
static const time::microseconds DEFER_RANGE_WITHOUT_BEST_FACE
NccStrategy(Forwarder &forwarder, const Name &name=getStrategyName())
void updateBestFace(const Face &face)
std::vector< fib::NextHop > NextHopList
static const time::microseconds MIN_PREDICTION
PartialName parameters
parameter components
bool hasPendingOutRecords(const pit::Entry &pitEntry)
determine whether pitEntry has any pending out-records
ndn::optional< uint64_t > version
whether strategyName contains a version component
std::mt19937 & getGlobalRng()
static const int ADJUST_PREDICT_DOWN_SHIFT
represents a forwarding strategy
This file contains common algorithms used by forwarding strategies.
Declares the global pseudorandom number generator (PRNG) for NFD.
static ParsedInstanceName parseInstanceName(const Name &input)
parse a strategy instance name
EventId schedule(time::nanoseconds after, const EventCallback &event)
schedule an event
static const Name & getStrategyName()
static const time::microseconds INITIAL_PREDICTION
StrategyInfo on measurements::Entry.
static const time::microseconds DEFER_FIRST_WITHOUT_BEST_FACE
virtual ~PitEntryInfo() override
uint64_t FaceId
identifies a face
represents a nexthop record in FIB entry
static const time::microseconds MAX_PREDICTION
bool wouldViolateScope(const Face &inFace, const Interest &interest, const Face &outFace)
determine whether forwarding the Interest in pitEntry to outFace would violate scope ...
const NextHopList & getNextHops() const
Face * getFace(FaceId id) const
void rejectPendingInterest(const shared_ptr< pit::Entry > &pitEntry)
decide that a pending Interest cannot be forwarded
const fib::Entry & lookupFib(const pit::Entry &pitEntry) const
performs a FIB lookup, considering Link object if present
virtual void afterReceiveInterest(const Face &inFace, const Interest &interest, const shared_ptr< pit::Entry > &pitEntry) override
trigger after Interest is received