39 , m_rttEstimatorOpts(make_shared<RttEstimator::Options>())
40 , m_removeFaceConn(beforeRemoveFace.connect([this] (const
Face& face) { m_fit.erase(face.getId()); }))
44 NDN_THROW(std::invalid_argument(
"AccessStrategy does not accept parameters"));
47 NDN_THROW(std::invalid_argument(
"AccessStrategy does not support version " + to_string(*parsed.
version)));
55 static Name strategyName(
"/localhost/nfd/strategy/access/%FD%01");
61 const shared_ptr<pit::Entry>& pitEntry)
64 switch (suppressResult) {
66 return afterReceiveNewInterest(ingress, interest, pitEntry);
68 return afterReceiveRetxInterest(ingress, interest, pitEntry);
70 NFD_LOG_DEBUG(interest <<
" interestFrom " << ingress <<
" retx-suppress");
76 AccessStrategy::afterReceiveNewInterest(
const FaceEndpoint& ingress,
const Interest& interest,
77 const shared_ptr<pit::Entry>& pitEntry)
79 const auto& fibEntry = this->
lookupFib(*pitEntry);
82 std::tie(miName, mi) = this->findPrefixMeasurements(*pitEntry);
86 NFD_LOG_DEBUG(interest <<
" interestFrom " << ingress <<
" new-interest mi=" << miName);
89 bool isSentToLastNexthop = this->sendToLastNexthop(ingress, interest, pitEntry, *mi, fibEntry);
90 if (isSentToLastNexthop) {
95 NFD_LOG_DEBUG(interest <<
" interestFrom " << ingress <<
" new-interest no-mi");
101 size_t nMulticastSent = this->multicast(ingress.
face, interest, pitEntry, fibEntry);
103 if (nMulticastSent == 0) {
109 AccessStrategy::afterReceiveRetxInterest(
const FaceEndpoint& ingress,
const Interest& interest,
110 const shared_ptr<pit::Entry>& pitEntry)
112 const auto& fibEntry = this->
lookupFib(*pitEntry);
113 NFD_LOG_DEBUG(interest <<
" interestFrom " << ingress <<
" retx-forward");
114 this->multicast(ingress.
face, interest, pitEntry, fibEntry);
118 AccessStrategy::sendToLastNexthop(
const FaceEndpoint& ingress,
const Interest& interest,
119 const shared_ptr<pit::Entry>& pitEntry, MtInfo& mi,
123 NFD_LOG_DEBUG(pitEntry->getInterest() <<
" no-last-nexthop");
127 if (mi.lastNexthop == ingress.
face.
getId()) {
128 NFD_LOG_DEBUG(pitEntry->getInterest() <<
" last-nexthop-is-downstream");
133 if (outFace ==
nullptr || !fibEntry.
hasNextHop(*outFace)) {
134 NFD_LOG_DEBUG(pitEntry->getInterest() <<
" last-nexthop-gone");
139 NFD_LOG_DEBUG(pitEntry->getInterest() <<
" last-nexthop-violates-scope");
143 auto rto = mi.rtt.getEstimatedRto();
144 NFD_LOG_DEBUG(pitEntry->getInterest() <<
" interestTo " << mi.lastNexthop
145 <<
" last-nexthop rto=" << time::duration_cast<time::microseconds>(rto).count());
150 PitInfo* pi = pitEntry->insertStrategyInfo<PitInfo>().first;
152 [
this, pitWeak = weak_ptr<pit::Entry>(pitEntry), face = ingress.
face.
getId(),
153 endpoint = ingress.
endpoint, lastNexthop = mi.lastNexthop] {
154 afterRtoTimeout(pitWeak, face, endpoint, lastNexthop);
161 AccessStrategy::afterRtoTimeout(
const weak_ptr<pit::Entry>& pitWeak,
164 shared_ptr<pit::Entry> pitEntry = pitWeak.lock();
166 BOOST_ASSERT(pitEntry !=
nullptr);
169 if (inFace ==
nullptr) {
170 NFD_LOG_DEBUG(pitEntry->getInterest() <<
" timeoutFrom " << firstOutFaceId
171 <<
" inFace-gone " << inFaceId);
175 auto inRecord = pitEntry->getInRecord(*inFace);
179 BOOST_ASSERT(inRecord != pitEntry->in_end());
181 const Interest& interest = inRecord->getInterest();
184 NFD_LOG_DEBUG(pitEntry->getInterest() <<
" timeoutFrom " << firstOutFaceId
185 <<
" multicast-except " << firstOutFaceId);
186 this->multicast(*inFace, interest, pitEntry, fibEntry, firstOutFaceId);
190 AccessStrategy::multicast(
const Face& inFace,
const Interest& interest,
191 const shared_ptr<pit::Entry>& pitEntry,
const fib::Entry& fibEntry,
195 for (
const auto& nexthop : fibEntry.
getNextHops()) {
196 Face& outFace = nexthop.getFace();
197 if (&outFace == &inFace || outFace.
getId() == exceptFace ||
201 NFD_LOG_DEBUG(pitEntry->getInterest() <<
" interestTo " << outFace.
getId() <<
" multicast");
212 PitInfo* pi = pitEntry->getStrategyInfo<PitInfo>();
214 pi->rtoTimer.cancel();
217 if (!pitEntry->hasInRecords()) {
218 NFD_LOG_DEBUG(pitEntry->getInterest() <<
" dataFrom " << ingress <<
" not-fastest");
222 auto outRecord = pitEntry->getOutRecord(ingress.
face);
223 if (outRecord == pitEntry->out_end()) {
224 NFD_LOG_DEBUG(pitEntry->getInterest() <<
" dataFrom " << ingress <<
" no-out-record");
228 auto rtt = time::steady_clock::now() - outRecord->getLastRenewed();
229 NFD_LOG_DEBUG(pitEntry->getInterest() <<
" dataFrom " << ingress
230 <<
" rtt=" << time::duration_cast<time::microseconds>(rtt).count());
231 this->updateMeasurements(ingress.
face, data, rtt);
235 AccessStrategy::updateMeasurements(
const Face& inFace,
const Data& data, time::nanoseconds rtt)
237 auto ret = m_fit.emplace(std::piecewise_construct,
238 std::forward_as_tuple(inFace.
getId()),
239 std::forward_as_tuple(m_rttEstimatorOpts));
240 FaceInfo& fi = ret.first->second;
241 fi.rtt.addMeasurement(rtt);
243 MtInfo* mi = this->addPrefixMeasurements(data);
244 if (mi->lastNexthop != inFace.
getId()) {
245 mi->lastNexthop = inFace.
getId();
249 mi->rtt.addMeasurement(rtt);
253 std::tuple<Name, AccessStrategy::MtInfo*>
254 AccessStrategy::findPrefixMeasurements(
const pit::Entry& pitEntry)
258 return std::make_tuple(Name(),
nullptr);
262 BOOST_ASSERT(mi !=
nullptr);
265 return std::make_tuple(me->
getName(), mi);
268 AccessStrategy::MtInfo*
269 AccessStrategy::addPrefixMeasurements(
const Data& data)
272 if (!data.getName().empty()) {
278 BOOST_ASSERT(me !=
nullptr);
const EndpointId endpoint
Main class of NFD's forwarding engine.
Interest is retransmission and should be forwarded.
void setInstanceName(const Name &name)
set strategy instance name
void extendLifetime(Entry &entry, const time::nanoseconds &lifetime)
extend lifetime of an entry
std::pair< T *, bool > insertStrategyInfo(A &&... args)
Insert a StrategyInfo item.
Represents a Measurements entry.
Interest is retransmission and should be suppressed.
static Name makeInstanceName(const Name &input, const Name &strategyName)
construct a strategy instance name
AccessStrategy(Forwarder &forwarder, const Name &name=getStrategyName())
uint64_t EndpointId
Identifies a remote endpoint on the link.
const fib::Entry & lookupFib(const pit::Entry &pitEntry) const
performs a FIB lookup, considering Link object if present
MeasurementsAccessor & getMeasurements()
Scheduler & getScheduler()
Returns the global Scheduler instance for the calling thread.
void sendInterest(const shared_ptr< pit::Entry > &pitEntry, const FaceEndpoint &egress, const Interest &interest)
send Interest to egress
bool hasNextHop(const Face &face) const
Entry * findLongestPrefixMatch(const Name &name, const EntryPredicate &pred=AnyEntry()) const
perform a longest prefix match for name
Access Router Strategy version 1.
Represents a face-endpoint pair in the forwarder.
Copyright (c) 2014-2015, Regents of the University of California, Arizona Board of Regents...
Interest is new (not a retransmission)
generalization of a network interface
T * getStrategyInfo() const
Get a StrategyInfo item.
PartialName parameters
parameter components
void afterReceiveInterest(const FaceEndpoint &ingress, const Interest &interest, const shared_ptr< pit::Entry > &pitEntry) override
trigger after Interest is received
represents a forwarding strategy
This file contains common algorithms used by forwarding strategies.
const NextHopList & getNextHops() const
#define NFD_LOG_INIT(name)
static ParsedInstanceName parseInstanceName(const Name &input)
parse a strategy instance name
RetxSuppressionResult decidePerPitEntry(pit::Entry &pitEntry) const
determines whether Interest is a retransmission, and if so, whether it shall be forwarded or suppress...
static const Name & getStrategyName()
NFD_REGISTER_STRATEGY(SelfLearningStrategy)
bool wouldViolateScope(const Face &inFace, const Interest &interest, const Face &outFace)
determine whether forwarding the Interest in pitEntry to outFace would violate scope ...
const Name & getName() const
uint64_t FaceId
Identifies a face.
const FaceId INVALID_FACEID
indicates an invalid FaceId
Face * getFace(FaceId id) const
void beforeSatisfyInterest(const shared_ptr< pit::Entry > &pitEntry, const FaceEndpoint &ingress, const Data &data) override
trigger before PIT entry is satisfied
void rejectPendingInterest(const shared_ptr< pit::Entry > &pitEntry)
schedule the PIT entry for immediate deletion
Entry * get(const Name &name)
find or insert a Measurements entry for name
optional< uint64_t > version
whether strategyName contains a version component