38 const time::milliseconds AsfStrategy::RETX_SUPPRESSION_INITIAL(10);
39 const time::milliseconds AsfStrategy::RETX_SUPPRESSION_MAX(250);
43 , m_measurements(getMeasurements())
44 , m_probing(m_measurements)
45 , m_retxSuppression(RETX_SUPPRESSION_INITIAL,
51 BOOST_THROW_EXCEPTION(std::invalid_argument(
"AsfStrategy does not accept parameters"));
54 BOOST_THROW_EXCEPTION(std::invalid_argument(
55 "AsfStrategy does not support version " + std::to_string(*parsed.
version)));
63 static Name strategyName(
"/localhost/nfd/strategy/asf/%FD%02");
69 const shared_ptr<pit::Entry>& pitEntry)
74 switch (suppressResult) {
79 NFD_LOG_DEBUG(interest <<
" from=" << inFace.getId() <<
" suppressed");
86 if (nexthops.size() == 0) {
87 sendNoRouteNack(inFace, interest, pitEntry);
92 Face* faceToUse = getBestFaceForForwarding(fibEntry, interest, inFace);
94 if (faceToUse ==
nullptr) {
95 sendNoRouteNack(inFace, interest, pitEntry);
100 NFD_LOG_TRACE(
"Forwarding interest to face: " << faceToUse->getId());
102 forwardInterest(interest, fibEntry, pitEntry, *faceToUse);
106 Face* faceToProbe = m_probing.
getFaceToProbe(inFace, interest, fibEntry, *faceToUse);
108 if (faceToProbe !=
nullptr) {
109 bool wantNewNonce =
true;
110 forwardInterest(interest, fibEntry, pitEntry, *faceToProbe, wantNewNonce);
118 const Face& inFace,
const Data& data)
122 if (namespaceInfo ==
nullptr) {
123 NFD_LOG_TRACE(
"Could not find measurements entry for " << pitEntry->getName());
128 FaceInfo* faceInfo = namespaceInfo->
get(inFace.getId());
129 if (faceInfo ==
nullptr) {
144 const shared_ptr<pit::Entry>& pitEntry)
146 NFD_LOG_DEBUG(
"Nack for " << nack.getInterest() <<
" from=" << inFace.getId() <<
": " << nack.getReason());
147 onTimeout(pitEntry->getName(), inFace.getId());
154 AsfStrategy::forwardInterest(
const Interest& interest,
156 const shared_ptr<pit::Entry>& pitEntry,
162 Interest probeInterest(interest);
163 probeInterest.refreshNonce();
164 NFD_LOG_TRACE(
"Sending probe for " << probeInterest << probeInterest.getNonce()
165 <<
" to FaceId: " << outFace.getId());
183 <<
" FaceId: " << outFace.getId()
184 <<
" in " << time::duration_cast<time::milliseconds>(timeout) <<
" ms");
187 bind(&AsfStrategy::onTimeout,
this, interest.getName(), outFace.getId()));
206 static const RttStats::Rtt SORTING_RTT_TIMEOUT = time::microseconds::max();
207 static const RttStats::Rtt SORTING_RTT_NO_MEASUREMENT = SORTING_RTT_TIMEOUT / 2;
210 return SORTING_RTT_TIMEOUT.count();
213 return SORTING_RTT_NO_MEASUREMENT.count();
216 return stats.srtt.count();
221 AsfStrategy::getBestFaceForForwarding(
const fib::Entry& fibEntry,
const Interest& interest,
226 typedef std::function<bool(const FaceStats&, const FaceStats&)> FaceStatsPredicate;
227 typedef std::set<FaceStats, FaceStatsPredicate> FaceStatsSet;
229 FaceStatsSet rankedFaces(
230 [] (
const FaceStats& lhs,
const FaceStats& rhs) ->
bool {
235 if (lhsValue < rhsValue) {
238 else if (lhsValue == rhsValue) {
239 return lhs.cost < rhs.cost;
247 Face& hopFace = hop.getFace();
249 if ((hopFace.getId() == inFace.getId() && hopFace.getLinkType() != ndn::nfd::LINK_TYPE_AD_HOC) ||
254 FaceInfo* info = m_measurements.getFaceInfo(fibEntry, interest, hopFace);
256 if (info ==
nullptr) {
257 FaceStats stats = {&hopFace,
262 rankedFaces.insert(stats);
265 FaceStats stats = {&hopFace, info->
getRtt(), info->
getSrtt(), hop.getCost()};
266 rankedFaces.insert(stats);
272 if (it != rankedFaces.end()) {
281 AsfStrategy::onTimeout(
const Name& interestName,
face::FaceId faceId)
283 NFD_LOG_TRACE(
"FaceId: " << faceId <<
" for " << interestName <<
" has timed-out");
285 NamespaceInfo* namespaceInfo = m_measurements.getNamespaceInfo(interestName);
287 if (namespaceInfo ==
nullptr) {
288 NFD_LOG_TRACE(
"FibEntry for " << interestName <<
" has been removed since timeout scheduling");
294 if (it == namespaceInfo->
end()) {
295 it = namespaceInfo->
insert(faceId);
303 AsfStrategy::sendNoRouteNack(
const Face& inFace,
const Interest& interest,
304 const shared_ptr<pit::Entry>& pitEntry)
306 NFD_LOG_DEBUG(interest <<
" from=" << inFace.getId() <<
" noNextHop");
308 lp::NackHeader nackHeader;
309 nackHeader.setReason(lp::NackReason::NO_ROUTE);
310 this->
sendNack(pitEntry, inFace, nackHeader);
const FaceInfoTable::iterator insert(nfd::face::FaceId faceId)
Interest is retransmission and should be forwarded.
void setInstanceName(const Name &name)
set strategy instance name
void afterForwardingProbe(const fib::Entry &fibEntry, const Interest &interest)
#define NFD_LOG_DEBUG(expression)
RttStats::Rtt getRtt() const
FaceInfo & getOrCreateFaceInfo(const fib::Entry &fibEntry, const Interest &interest, const Face &face)
static const Name & getStrategyName()
time::microseconds Duration
NamespaceInfo * getNamespaceInfo(const Name &prefix)
virtual void beforeSatisfyInterest(const shared_ptr< pit::Entry > &pitEntry, const Face &inFace, const Data &data) override
trigger before PIT entry is satisfied
NFD_REGISTER_STRATEGY(AsfStrategy)
void extendFaceInfoLifetime(FaceInfo &info, const Face &face)
void sendInterest(const shared_ptr< pit::Entry > &pitEntry, Face &outFace, const Interest &interest)
send Interest to outFace
void sendNack(const shared_ptr< pit::Entry > &pitEntry, const Face &outFace, const lp::NackHeader &header)
send Nack to outFace
Interest is retransmission and should be suppressed.
static Name makeInstanceName(const Name &input, const Name &strategyName)
construct a strategy instance name
RttStats::Rtt getSrtt() const
time::duration< double, boost::micro > Rtt
FaceInfoTable::iterator end()
Table::const_iterator iterator
void cancelTimeoutEvent(const Name &prefix)
const Name & getPrefix() const
FaceInfo * get(nfd::face::FaceId faceId)
Copyright (c) 2014-2015, Regents of the University of California, Arizona Board of Regents...
Interest is new (not a retransmission)
a retransmission suppression decision algorithm that suppresses retransmissions using exponential bac...
NamespaceInfo & getOrCreateNamespaceInfo(const fib::Entry &fibEntry, const Interest &interest)
std::vector< fib::NextHop > NextHopList
bool isProbingNeeded(const fib::Entry &fibEntry, const Interest &interest)
PartialName parameters
parameter components
ndn::optional< uint64_t > version
whether strategyName contains a version component
bool isTimeoutScheduled() const
void recordRtt(const shared_ptr< pit::Entry > &pitEntry, const Face &inFace)
stores stategy information about each face in this namespace
RetxSuppressionResult decidePerPitEntry(pit::Entry &pitEntry)
determines whether Interest is a retransmission per pit entry and if so, whether it shall be forwarde...
represents a forwarding strategy
virtual void afterReceiveNack(const Face &inFace, const lp::Nack &nack, const shared_ptr< pit::Entry > &pitEntry) override
trigger after Nack is received
void recordTimeout(const Name &interestName)
This file contains common algorithms used by forwarding strategies.
void setTimeoutEvent(const scheduler::EventId &id, const Name &interestName)
#define NFD_LOG_INIT(name)
static const Rtt RTT_TIMEOUT
static ParsedInstanceName parseInstanceName(const Name &input)
parse a strategy instance name
EventId schedule(time::nanoseconds after, const EventCallback &event)
schedule an event
#define NFD_LOG_TRACE(expression)
virtual void afterReceiveInterest(const Face &inFace, const Interest &interest, const shared_ptr< pit::Entry > &pitEntry) override
trigger after Interest is received
double getValueForSorting(const FaceStats &stats)
Face * getFaceToProbe(const Face &inFace, const Interest &interest, const fib::Entry &fibEntry, const Face &faceUsed)
uint64_t FaceId
identifies a face
RttEstimator::Duration computeRto() const
represents a nexthop record in FIB entry
bool wouldViolateScope(const Face &inFace, const Interest &interest, const Face &outFace)
determine whether forwarding the Interest in pitEntry to outFace would violate scope ...
const NextHopList & getNextHops() const
void rejectPendingInterest(const shared_ptr< pit::Entry > &pitEntry)
decide that a pending Interest cannot be forwarded
const fib::Entry & lookupFib(const pit::Entry &pitEntry) const
performs a FIB lookup, considering Link object if present
FaceInfoTable::iterator find(nfd::face::FaceId faceId)
Strategy information for each face in a namespace.
AsfStrategy(Forwarder &forwarder, const Name &name=getStrategyName())
static const Rtt RTT_NO_MEASUREMENT