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, 0) &&
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, 0) &&
120 if (nUpstreams > 0) {
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 auto 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, 0) &&
166 bool isForwarded =
false;
167 for (
const auto& nexthop : fibEntry.
getNextHops()) {
168 Face& face = nexthop.getFace();
178 std::uniform_int_distribution<time::nanoseconds::rep> dist(0, pitEntryInfo->
maxInterval.count() - 1);
179 time::nanoseconds deferNext = time::nanoseconds(dist(
getGlobalRng()));
188 shared_ptr<pit::Entry> pitEntry = pitEntryWeak.lock();
189 if (pitEntry ==
nullptr) {
195 if (measurementsEntry ==
nullptr) {
210 const Face& inFace,
const Data& data)
212 if (!pitEntry->hasInRecords()) {
221 if (measurementsEntry ==
nullptr) {
234 if (pitEntryInfo !=
nullptr) {
241 if (bestFace.get() == &inFace)
256 BOOST_ASSERT(entry !=
nullptr);
265 if (parentEntry !=
nullptr) {
278 : prediction(INITIAL_PREDICTION)
285 this->operator=(other);
291 shared_ptr<Face> best = this->bestFace.lock();
292 if (best !=
nullptr) {
295 this->bestFace = best = this->previousFace.lock();
302 if (this->bestFace.expired()) {
303 this->bestFace = const_cast<Face&>(face).shared_from_this();
306 shared_ptr<Face> bestFace = this->bestFace.lock();
307 if (bestFace.get() == &face) {
308 this->adjustPredictDown();
311 this->previousFace = this->bestFace;
312 this->bestFace = const_cast<Face&>(face).shared_from_this();
317 NccStrategy::MeasurementsEntryInfo::adjustPredictDown()
319 prediction = std::max(MIN_PREDICTION,
320 time::microseconds(prediction.count() - (prediction.count() >> ADJUST_PREDICT_DOWN_SHIFT)));
326 prediction = std::min(MAX_PREDICTION,
327 time::microseconds(prediction.count() + (prediction.count() >> ADJUST_PREDICT_UP_SHIFT)));
331 NccStrategy::MeasurementsEntryInfo::ageBestFace()
333 this->previousFace = this->bestFace;
334 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
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
bool hasNextHop(const Face &face, uint64_t endpointId) const
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
void cancel(EventId eventId)
Cancel a scheduled event.
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