44 BOOST_THROW_EXCEPTION(std::invalid_argument(
"NccStrategy does not accept parameters"));
47 BOOST_THROW_EXCEPTION(std::invalid_argument(
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));
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) {
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) {
211 const Face& inFace,
const Data& data)
213 if (!pitEntry->hasInRecords()) {
222 if (measurementsEntry ==
nullptr) {
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) {
296 this->bestFace = best = this->previousFace.lock();
303 if (this->bestFace.expired()) {
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();
312 this->previousFace = this->bestFace;
313 this->bestFace =
const_cast<Face&
>(
face).shared_from_this();
318 NccStrategy::MeasurementsEntryInfo::adjustPredictDown()
320 prediction = std::max(MIN_PREDICTION,
321 time::microseconds(prediction.count() - (prediction.count() >> ADJUST_PREDICT_DOWN_SHIFT)));
327 prediction = std::min(MAX_PREDICTION,
328 time::microseconds(prediction.count() + (prediction.count() >> ADJUST_PREDICT_UP_SHIFT)));
332 NccStrategy::MeasurementsEntryInfo::ageBestFace()
334 this->previousFace = this->bestFace;
335 this->bestFace.reset();
static const time::microseconds DEFER_FIRST_WITHOUT_BEST_FACE
bool canForwardToLegacy(const pit::Entry &pitEntry, const Face &face)
decide whether Interest can be forwarded to face
static const Name & getStrategyName()
Declares the global pseudorandom number generator (PRNG) for NFD.
static ParsedInstanceName parseInstanceName(const Name &input)
parse a strategy instance name
StrategyInfo on measurements::Entry.
void doPropagate(FaceId inFaceId, weak_ptr< pit::Entry > pitEntryWeak)
propagate to another upstream
shared_ptr< Face > getBestFace()
static const int UPDATE_MEASUREMENTS_N_LEVELS
generalization of a network interface
void cancel(const EventId &eventId)
Cancel a scheduled event.
PartialName parameters
parameter components
static const time::microseconds DEFER_RANGE_WITHOUT_BEST_FACE
NccStrategy(Forwarder &forwarder, const Name &name=getStrategyName())
Face * getFace(FaceId id) const
time::microseconds maxInterval
maximum interval between forwarding to two nexthops except best and previous
void setInstanceName(const Name &name)
set strategy instance name
Represents an Interest packet.
virtual void afterReceiveInterest(const Face &inFace, const Interest &interest, const shared_ptr< pit::Entry > &pitEntry) override
trigger after Interest is received
void extendLifetime(Entry &entry, const time::nanoseconds &lifetime)
extend lifetime of an entry
static const time::microseconds MIN_PREDICTION
Represents a collection of nexthops.
represents a Measurements entry
Copyright (c) 2011-2015 Regents of the University of California.
MeasurementsAccessor & getMeasurements()
void inheritFrom(const MeasurementsEntryInfo &other)
NFD_REGISTER_STRATEGY(AccessStrategy)
void timeoutOnBestFace(weak_ptr< pit::Entry > pitEntryWeak)
best face did not reply within prediction
static const time::nanoseconds MEASUREMENTS_LIFETIME
void rejectPendingInterest(const shared_ptr< pit::Entry > &pitEntry)
schedule the PIT entry for immediate deletion
Represents an absolute name.
scheduler::EventId propagateTimer
timer for propagating to another face
bool hasPendingOutRecords(const pit::Entry &pitEntry)
determine whether pitEntry has any pending out-records
std::pair< T *, bool > insertStrategyInfo(A &&... args)
insert a StrategyInfo item
scheduler::EventId bestFaceTimeout
timer that expires when best face does not respond within predicted time
StrategyInfo on pit::Entry.
represents a forwarding strategy
MeasurementsEntryInfo & getMeasurementsEntryInfo(measurements::Entry *entry)
std::mt19937 & getGlobalRng()
optional< uint64_t > version
whether strategyName contains a version component
This file contains common algorithms used by forwarding strategies.
const fib::Entry & lookupFib(const pit::Entry &pitEntry) const
performs a FIB lookup, considering Link object if present
time::microseconds prediction
EventId schedule(time::nanoseconds after, const EventCallback &event)
Schedule an event.
static const time::microseconds INITIAL_PREDICTION
Entry * get(const Name &name)
find or insert a Measurements entry for name
static Name makeInstanceName(const Name &input, const Name &strategyName)
construct a strategy instance name
std::string to_string(const V &v)
const NextHopList & getNextHops() const
uint64_t FaceId
identifies a face
void updateBestFace(const Face &face)
Represents a Data packet.
weak_ptr< Face > previousFace
virtual void beforeSatisfyInterest(const shared_ptr< pit::Entry > &pitEntry, const Face &inFace, const Data &data) override
trigger before PIT entry is satisfied
void sendInterest(const shared_ptr< pit::Entry > &pitEntry, Face &outFace, const Interest &interest)
send Interest to outFace
bool wouldViolateScope(const Face &inFace, const Interest &interest, const Face &outFace)
determine whether forwarding the Interest in pitEntry to outFace would violate scope ...
static const time::microseconds MAX_PREDICTION
Entry * getParent(const Entry &child)
find or insert a Measurements entry for child's parent
represents a nexthop record in FIB entry
virtual ~PitEntryInfo() override
bool hasNextHop(const Face &face) const