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) {
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()
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.
bool hasNextHop(const Face &face) const
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
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())
boost::posix_time::time_duration milliseconds(long duration)
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
weak_ptr< Face > bestFace
static const time::microseconds MIN_PREDICTION
ndn::optional< uint64_t > version
whether strategyName contains a version component
represents a Measurements entry
std::pair< T *, bool > insertStrategyInfo(A &&...args)
insert a StrategyInfo item
Copyright (c) 2011-2015 Regents of the University of California.
MeasurementsAccessor & getMeasurements()
void inheritFrom(const MeasurementsEntryInfo &other)
NFD_REGISTER_STRATEGY(AccessStrategy)
static const int ADJUST_PREDICT_DOWN_SHIFT
std::vector< fib::NextHop > NextHopList
void timeoutOnBestFace(weak_ptr< pit::Entry > pitEntryWeak)
best face did not reply within prediction
const fib::Entry & lookupFib(const pit::Entry &pitEntry) const
performs a FIB lookup, considering Link object if present
static const time::nanoseconds MEASUREMENTS_LIFETIME
void rejectPendingInterest(const shared_ptr< pit::Entry > &pitEntry)
decide that a pending Interest cannot be forwarded
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
scheduler::EventId bestFaceTimeout
timer that expires when best face does not respond within predicted time
static const int ADJUST_PREDICT_UP_SHIFT
const NextHopList & getNextHops() const
StrategyInfo on pit::Entry.
represents a forwarding strategy
MeasurementsEntryInfo & getMeasurementsEntryInfo(measurements::Entry *entry)
std::mt19937 & getGlobalRng()
This file contains common algorithms used by forwarding strategies.
time::microseconds prediction
EventId schedule(time::nanoseconds after, const EventCallback &event)
schedule an event
static const time::microseconds INITIAL_PREDICTION
static Name makeInstanceName(const Name &input, const Name &strategyName)
construct a strategy instance name
std::string to_string(const V &v)
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
represents a nexthop record in FIB entry
virtual ~PitEntryInfo() override
Face * getFace(FaceId id) const