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"));
55 static const auto strategyName =
Name(
"/localhost/nfd/strategy/access").appendVersion(1);
61 const shared_ptr<pit::Entry>& pitEntry)
64 switch (suppressResult) {
66 return afterReceiveNewInterest(interest, ingress, pitEntry);
68 return afterReceiveRetxInterest(interest, ingress, pitEntry);
70 NFD_LOG_DEBUG(interest <<
" interestFrom " << ingress <<
" retx-suppress");
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(interest, ingress, pitEntry, *mi, fibEntry);
90 if (isSentToLastNexthop) {
95 NFD_LOG_DEBUG(interest <<
" interestFrom " << ingress <<
" new-interest no-mi");
101 size_t nMulticastSent = this->multicast(interest, ingress.
face, pitEntry, fibEntry);
103 if (nMulticastSent == 0) {
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(interest, ingress.
face, pitEntry, fibEntry);
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
147 if (!this->
sendInterest(interest, *outFace, pitEntry)) {
152 PitInfo* pi = pitEntry->insertStrategyInfo<PitInfo>().first;
154 [
this, pitWeak = weak_ptr<pit::Entry>(pitEntry), face = ingress.
face.getId(), nh = mi.lastNexthop] {
155 afterRtoTimeout(pitWeak, face, nh);
162 AccessStrategy::afterRtoTimeout(
const weak_ptr<pit::Entry>& pitWeak,
165 shared_ptr<pit::Entry> pitEntry = pitWeak.lock();
167 BOOST_ASSERT(pitEntry !=
nullptr);
170 if (inFace ==
nullptr) {
171 NFD_LOG_DEBUG(pitEntry->getInterest() <<
" timeoutFrom " << firstOutFaceId
172 <<
" inFace-gone " << inFaceId);
176 auto inRecord = pitEntry->getInRecord(*inFace);
180 BOOST_ASSERT(inRecord != pitEntry->in_end());
182 const Interest& interest = inRecord->getInterest();
185 NFD_LOG_DEBUG(pitEntry->getInterest() <<
" timeoutFrom " << firstOutFaceId
186 <<
" multicast-except " << firstOutFaceId);
187 this->multicast(interest, *inFace, pitEntry, fibEntry, firstOutFaceId);
191 AccessStrategy::multicast(
const Interest& interest,
const Face& inFace,
192 const shared_ptr<pit::Entry>& pitEntry,
const fib::Entry& fibEntry,
196 for (
const auto& nexthop : fibEntry.
getNextHops()) {
197 Face& outFace = nexthop.getFace();
198 if (&outFace == &inFace || outFace.getId() == exceptFace ||
202 NFD_LOG_DEBUG(pitEntry->getInterest() <<
" interestTo " << outFace.getId() <<
" multicast");
212 const shared_ptr<pit::Entry>& pitEntry)
214 PitInfo* pi = pitEntry->getStrategyInfo<PitInfo>();
216 pi->rtoTimer.cancel();
219 if (!pitEntry->hasInRecords()) {
220 NFD_LOG_DEBUG(pitEntry->getInterest() <<
" dataFrom " << ingress <<
" not-fastest");
224 auto outRecord = pitEntry->getOutRecord(ingress.
face);
225 if (outRecord == pitEntry->out_end()) {
226 NFD_LOG_DEBUG(pitEntry->getInterest() <<
" dataFrom " << ingress <<
" no-out-record");
231 NFD_LOG_DEBUG(pitEntry->getInterest() <<
" dataFrom " << ingress
233 this->updateMeasurements(ingress.
face, data, rtt);
239 auto ret = m_fit.emplace(std::piecewise_construct,
240 std::forward_as_tuple(inFace.getId()),
241 std::forward_as_tuple(m_rttEstimatorOpts));
242 FaceInfo& fi = ret.first->second;
243 fi.rtt.addMeasurement(rtt);
245 MtInfo* mi = this->addPrefixMeasurements(data);
246 if (mi->lastNexthop != inFace.getId()) {
247 mi->lastNexthop = inFace.getId();
251 mi->rtt.addMeasurement(rtt);
255 std::tuple<Name, AccessStrategy::MtInfo*>
256 AccessStrategy::findPrefixMeasurements(
const pit::Entry& pitEntry)
260 return std::make_tuple(
Name(),
nullptr);
263 auto mi = me->getStrategyInfo<MtInfo>();
267 return std::make_tuple(me->getName(), mi);
270 AccessStrategy::MtInfo*
271 AccessStrategy::addPrefixMeasurements(
const Data& data)
280 BOOST_ASSERT(me !=
nullptr);
PartialName getPrefix(ssize_t nComponents) const
Returns a prefix of the name.
Interest is retransmission and should be forwarded.
static ParsedInstanceName parseInstanceName(const Name &input)
Parse a strategy instance name.
#define NFD_LOG_INIT(name)
std::string to_string(const T &val)
Represents a face-endpoint pair in the forwarder.
PartialName parameters
parameter components
static time_point now() noexcept
Face * getFace(FaceId id) const
boost::chrono::microseconds microseconds
Main class of NFD's forwarding engine.
Interest is retransmission and should be suppressed.
void setInstanceName(const Name &name)
Set strategy instance name.
Represents an Interest packet.
void extendLifetime(Entry &entry, const time::nanoseconds &lifetime)
extend lifetime of an entry
Entry * findLongestPrefixMatch(const Name &name, const EntryPredicate &pred=AnyEntry()) const
perform a longest prefix match for name
NFD_VIRTUAL_WITH_TESTS void rejectPendingInterest(const shared_ptr< pit::Entry > &pitEntry)
Schedule the PIT entry for immediate deletion.
Scheduler & getScheduler()
Returns the global Scheduler instance for the calling thread.
Represents a Measurements entry.
NDN_CXX_NODISCARD bool empty() const
Checks if the name is empty, i.e.
Copyright (c) 2011-2015 Regents of the University of California.
MeasurementsAccessor & getMeasurements()
Interest is new (not a retransmission)
static const Name & getStrategyName()
NFD_REGISTER_STRATEGY(AccessStrategy)
const Name & getName() const noexcept
Get name.
Represents an absolute name.
std::pair< T *, bool > insertStrategyInfo(A &&... args)
Insert a StrategyInfo item.
Represents a forwarding strategy.
void afterReceiveInterest(const Interest &interest, const FaceEndpoint &ingress, const shared_ptr< pit::Entry > &pitEntry) override
Trigger after an Interest is received.
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.
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.
void beforeSatisfyInterest(const Data &data, const FaceEndpoint &ingress, const shared_ptr< pit::Entry > &pitEntry) override
trigger before PIT entry is satisfied
const NextHopList & getNextHops() const
RetxSuppressionResult decidePerPitEntry(pit::Entry &pitEntry) const
determines whether Interest is a retransmission, and if so, whether it shall be forwarded or suppress...
NFD_VIRTUAL_WITH_TESTS pit::OutRecord * sendInterest(const Interest &interest, Face &egress, const shared_ptr< pit::Entry > &pitEntry)
Send an Interest packet.
Represents a Data packet.
AccessStrategy(Forwarder &forwarder, const Name &name=getStrategyName())
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.
const FaceId INVALID_FACEID
indicates an invalid FaceId
boost::chrono::nanoseconds nanoseconds
bool hasNextHop(const Face &face) const