30 #include <ndn-cxx/util/random.hpp> 46 NDN_THROW(std::invalid_argument(
"NccStrategy does not accept parameters"));
49 NDN_THROW(std::invalid_argument(
50 "NccStrategy does not support version " + to_string(*parsed.
version)));
58 static Name strategyName(
"/localhost/nfd/strategy/ncc/%FD%01");
64 const shared_ptr<pit::Entry>& pitEntry)
68 if (nexthops.size() == 0) {
83 size_t nUpstreams = nexthops.size();
86 if (bestFace !=
nullptr && fibEntry.
hasNextHop(*bestFace) &&
91 deferRange = time::microseconds((deferFirst.count() + 1) / 2);
99 auto firstEligibleNexthop = std::find_if(nexthops.begin(), nexthops.end(),
101 Face& outFace = nexthop.getFace();
105 if (firstEligibleNexthop != nexthops.end()) {
106 this->
sendInterest(pitEntry, firstEligibleNexthop->getFace(), interest);
114 shared_ptr<Face> previousFace = meInfo.
previousFace.lock();
115 if (previousFace !=
nullptr && fibEntry.
hasNextHop(*previousFace) &&
121 if (nUpstreams > 0) {
123 time::microseconds((2 * deferRange.count() + nUpstreams - 1) / nUpstreams));
139 if (inFace ==
nullptr) {
142 shared_ptr<pit::Entry> pitEntry = pitEntryWeak.lock();
143 if (pitEntry ==
nullptr) {
146 auto inRecord = pitEntry->getInRecord(*inFace);
147 if (inRecord == pitEntry->in_end()) {
150 const Interest& interest = inRecord->getInterest();
156 BOOST_ASSERT(pitEntryInfo !=
nullptr);
160 shared_ptr<Face> previousFace = meInfo.
previousFace.lock();
161 if (previousFace !=
nullptr && fibEntry.
hasNextHop(*previousFace) &&
167 bool isForwarded =
false;
168 for (
const auto& nexthop : fibEntry.
getNextHops()) {
169 Face& face = nexthop.getFace();
179 std::uniform_int_distribution<time::nanoseconds::rep> dist(0, pitEntryInfo->
maxInterval.count() - 1);
180 time::nanoseconds deferNext(dist(ndn::random::getRandomNumberEngine()));
189 shared_ptr<pit::Entry> pitEntry = pitEntryWeak.lock();
190 if (pitEntry ==
nullptr) {
196 if (measurementsEntry ==
nullptr) {
213 if (!pitEntry->hasInRecords()) {
222 if (measurementsEntry ==
nullptr) {
235 if (pitEntryInfo !=
nullptr) {
242 if (bestFace.get() == &ingress.
face)
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()
340 bestFaceTimeout.cancel();
341 propagateTimer.cancel();
bool canForwardToLegacy(const pit::Entry &pitEntry, const Face &face)
decide whether Interest can be forwarded to face
static const int ADJUST_PREDICT_UP_SHIFT
Main class of NFD's forwarding engine.
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
void extendLifetime(Entry &entry, const time::nanoseconds &lifetime)
extend lifetime of an entry
weak_ptr< Face > bestFace
std::pair< T *, bool > insertStrategyInfo(A &&... args)
Insert a StrategyInfo item.
weak_ptr< Face > previousFace
Represents a Measurements entry.
static const int UPDATE_MEASUREMENTS_N_LEVELS
time::microseconds prediction
scheduler::EventId bestFaceTimeout
timer that expires when best face does not respond within predicted time
static const time::nanoseconds MEASUREMENTS_LIFETIME
StrategyInfo on pit::Entry.
static Name makeInstanceName(const Name &input, const Name &strategyName)
Construct a strategy instance name.
void doPropagate(FaceId inFaceId, weak_ptr< pit::Entry > pitEntryWeak)
propagate to another upstream
const fib::Entry & lookupFib(const pit::Entry &pitEntry) const
Performs a FIB lookup, considering Link object if present.
MeasurementsAccessor & getMeasurements()
shared_ptr< Face > getBestFace()
Scheduler & getScheduler()
Returns the global Scheduler instance for the calling thread.
bool hasNextHop(const Face &face) const
MeasurementsEntryInfo & getMeasurementsEntryInfo(measurements::Entry *entry)
scheduler::EventId propagateTimer
timer for propagating to another face
void inheritFrom(const MeasurementsEntryInfo &other)
Represents a face-endpoint pair in the forwarder.
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)
Entry * getParent(const Entry &child)
find or insert a Measurements entry for child's parent
static const time::microseconds MIN_PREDICTION
void afterReceiveInterest(const FaceEndpoint &ingress, const Interest &interest, const shared_ptr< pit::Entry > &pitEntry) override
Trigger after Interest is received.
generalization of a network interface
Represents a collection of nexthops.
PartialName parameters
parameter components
bool hasPendingOutRecords(const pit::Entry &pitEntry)
determine whether pitEntry has any pending out-records
static const int ADJUST_PREDICT_DOWN_SHIFT
Represents a forwarding strategy.
This file contains common algorithms used by forwarding strategies.
const NextHopList & getNextHops() const
static ParsedInstanceName parseInstanceName(const Name &input)
Parse a strategy instance name.
static const Name & getStrategyName()
void beforeSatisfyInterest(const shared_ptr< pit::Entry > &pitEntry, const FaceEndpoint &ingress, const Data &data) override
Trigger before PIT entry is satisfied.
static const time::microseconds INITIAL_PREDICTION
StrategyInfo on measurements::Entry.
static const time::microseconds DEFER_FIRST_WITHOUT_BEST_FACE
NFD_REGISTER_STRATEGY(SelfLearningStrategy)
Represents a nexthop record in a 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 ...
uint64_t FaceId
Identifies a face.
Face * getFace(FaceId id) const
void rejectPendingInterest(const shared_ptr< pit::Entry > &pitEntry)
Schedule the PIT entry for immediate deletion.
pit::OutRecord * sendInterest(const shared_ptr< pit::Entry > &pitEntry, Face &egress, const Interest &interest)
Send an Interest packet.
Entry * get(const Name &name)
find or insert a Measurements entry for name
optional< uint64_t > version
whether strategyName contains a version component