28 #include <boost/random/uniform_int_distribution.hpp> 52 shared_ptr<fib::Entry> fibEntry,
53 shared_ptr<pit::Entry> pitEntry)
56 if (nexthops.size() == 0) {
61 shared_ptr<PitEntryInfo> pitEntryInfo =
63 bool isNewPitEntry = !pitEntry->hasUnexpiredOutRecords();
68 shared_ptr<MeasurementsEntryInfo> measurementsEntryInfo =
73 size_t nUpstreams = nexthops.size();
75 shared_ptr<Face> bestFace = measurementsEntryInfo->getBestFace();
76 if (static_cast<bool>(bestFace) && fibEntry->hasNextHop(bestFace) &&
77 pitEntry->canForwardTo(*bestFace)) {
79 deferFirst = measurementsEntryInfo->prediction;
80 deferRange = time::microseconds((deferFirst.count() + 1) / 2);
84 measurementsEntryInfo->prediction,
89 auto firstEligibleNexthop = std::find_if(nexthops.begin(), nexthops.end(),
91 return pitEntry->canForwardTo(*nexthop.getFace());
93 if (firstEligibleNexthop != nexthops.end()) {
94 this->
sendInterest(pitEntry, firstEligibleNexthop->getFace());
98 shared_ptr<Face> previousFace = measurementsEntryInfo->previousFace.lock();
99 if (static_cast<bool>(previousFace) && fibEntry->hasNextHop(previousFace) &&
100 pitEntry->canForwardTo(*previousFace)) {
104 if (nUpstreams > 0) {
105 pitEntryInfo->maxInterval = std::max(time::microseconds(1),
106 time::microseconds((2 * deferRange.count() + nUpstreams - 1) / nUpstreams));
112 pitEntryInfo->maxInterval = deferFirst;
116 weak_ptr<pit::Entry>(pitEntry), weak_ptr<fib::Entry>(fibEntry)));
122 shared_ptr<pit::Entry> pitEntry = pitEntryWeak.lock();
123 if (!static_cast<bool>(pitEntry)) {
126 shared_ptr<fib::Entry> fibEntry = fibEntryWeak.lock();
127 if (!static_cast<bool>(fibEntry)) {
131 shared_ptr<PitEntryInfo> pitEntryInfo = pitEntry->getStrategyInfo<
PitEntryInfo>();
134 BOOST_ASSERT(static_cast<bool>(pitEntryInfo));
136 shared_ptr<MeasurementsEntryInfo> measurementsEntryInfo =
139 shared_ptr<Face> previousFace = measurementsEntryInfo->previousFace.lock();
140 if (static_cast<bool>(previousFace) && fibEntry->hasNextHop(previousFace) &&
141 pitEntry->canForwardTo(*previousFace)) {
146 bool isForwarded =
false;
147 for (fib::NextHopList::const_iterator it = nexthops.begin(); it != nexthops.end(); ++it) {
148 shared_ptr<Face>
face = it->getFace();
149 if (pitEntry->canForwardTo(*face)) {
157 boost::random::uniform_int_distribution<time::nanoseconds::rep> dist(0,
158 pitEntryInfo->maxInterval.count() - 1);
159 time::nanoseconds deferNext = time::nanoseconds(dist(
getGlobalRng()));
162 weak_ptr<pit::Entry>(pitEntry), weak_ptr<fib::Entry>(fibEntry)));
169 shared_ptr<pit::Entry> pitEntry = pitEntryWeak.lock();
170 if (!static_cast<bool>(pitEntry)) {
173 shared_ptr<measurements::Entry> measurementsEntry = this->
getMeasurements().
get(*pitEntry);
176 if (!static_cast<bool>(measurementsEntry)) {
182 shared_ptr<MeasurementsEntryInfo> measurementsEntryInfo =
184 measurementsEntryInfo->adjustPredictUp();
192 const Face& inFace,
const Data& data)
194 if (pitEntry->getInRecords().empty()) {
200 shared_ptr<measurements::Entry> measurementsEntry = this->
getMeasurements().
get(*pitEntry);
203 if (!static_cast<bool>(measurementsEntry)) {
209 shared_ptr<MeasurementsEntryInfo> measurementsEntryInfo =
211 measurementsEntryInfo->updateBestFace(inFace);
216 shared_ptr<PitEntryInfo> pitEntryInfo = pitEntry->getStrategyInfo<
PitEntryInfo>();
217 if (static_cast<bool>(pitEntryInfo)) {
222 shared_ptr<NccStrategy::MeasurementsEntryInfo>
225 shared_ptr<measurements::Entry> measurementsEntry = this->
getMeasurements().
get(*entry);
229 shared_ptr<NccStrategy::MeasurementsEntryInfo>
233 if (static_cast<bool>(info)) {
237 info = make_shared<MeasurementsEntryInfo>();
238 entry->setStrategyInfo(info);
241 if (static_cast<bool>(parentEntry)) {
243 BOOST_ASSERT(static_cast<bool>(parentInfo));
244 info->inheritFrom(*parentInfo);
252 time::microseconds(8192);
254 time::microseconds(127);
256 time::microseconds(160000);
259 : prediction(INITIAL_PREDICTION)
266 this->operator=(other);
271 shared_ptr<Face> best = this->
bestFace.lock();
272 if (static_cast<bool>(best)) {
282 this->
bestFace =
const_cast<Face&
>(face).shared_from_this();
285 shared_ptr<Face>
bestFace = this->bestFace.lock();
286 if (bestFace.get() == &face) {
287 this->adjustPredictDown();
291 this->bestFace =
const_cast<Face&
>(face).shared_from_this();
296 NccStrategy::MeasurementsEntryInfo::adjustPredictDown() {
308 NccStrategy::MeasurementsEntryInfo::ageBestFace() {
static const time::microseconds DEFER_FIRST_WITHOUT_BEST_FACE
static const Name STRATEGY_NAME
virtual void afterReceiveInterest(const Face &inFace, const Interest &interest, shared_ptr< fib::Entry > fibEntry, shared_ptr< pit::Entry > pitEntry) 1
trigger after Interest is received
StrategyInfo on measurements::Entry.
shared_ptr< Face > getBestFace()
static const int UPDATE_MEASUREMENTS_N_LEVELS
void cancel(const EventId &eventId)
cancel a scheduled event
static const time::microseconds DEFER_RANGE_WITHOUT_BEST_FACE
represents an Interest packet
NccStrategy(Forwarder &forwarder, const Name &name=STRATEGY_NAME)
shared_ptr< measurements::Entry > get(const Name &name)
find or insert a Measurements entry for name
shared_ptr< MeasurementsEntryInfo > getMeasurementsEntryInfo(shared_ptr< measurements::Entry > entry)
weak_ptr< Face > bestFace
static const time::microseconds MIN_PREDICTION
virtual void beforeSatisfyInterest(shared_ptr< pit::Entry > pitEntry, const Face &inFace, const Data &data) 1
trigger before PIT entry is satisfied
MeasurementsAccessor & getMeasurements()
Copyright (c) 2011-2015 Regents of the University of California.
void inheritFrom(const MeasurementsEntryInfo &other)
void doPropagate(weak_ptr< pit::Entry > pitEntryWeak, weak_ptr< fib::Entry > fibEntryWeak)
propagate to another upstream
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
static const time::nanoseconds MEASUREMENTS_LIFETIME
Name abstraction to represent an absolute name.
boost::random::mt19937 & getGlobalRng()
void rejectPendingInterest(shared_ptr< pit::Entry > pitEntry)
decide that a pending Interest cannot be forwarded
static const int ADJUST_PREDICT_UP_SHIFT
StrategyInfo on pit::Entry.
represents a forwarding strategy
void extendLifetime(measurements::Entry &entry, const time::nanoseconds &lifetime)
extend lifetime of an entry
time::microseconds prediction
EventId schedule(const time::nanoseconds &after, const Scheduler::Event &event)
schedule an event
static const time::microseconds INITIAL_PREDICTION
void sendInterest(shared_ptr< pit::Entry > pitEntry, shared_ptr< Face > outFace, bool wantNewNonce=false)
send Interest to outFace
void updateBestFace(const Face &face)
weak_ptr< Face > previousFace
static const time::microseconds MAX_PREDICTION
shared_ptr< measurements::Entry > getParent(const measurements::Entry &child)
find or insert a Measurements entry for child's parent
represents a nexthop record in FIB entry