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%01");
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 forwardInterest(interest, fibEntry, pitEntry, *faceToUse);
104 Face* faceToProbe = m_probing.
getFaceToProbe(inFace, interest, fibEntry, *faceToUse);
106 if (faceToProbe !=
nullptr) {
107 bool wantNewNonce =
true;
108 forwardInterest(interest, fibEntry, pitEntry, *faceToProbe, wantNewNonce);
116 const Face& inFace,
const Data& data)
120 if (namespaceInfo ==
nullptr) {
121 NFD_LOG_TRACE(
"Could not find measurements entry for " << pitEntry->getName());
126 FaceInfo& faceInfo = namespaceInfo->
get(inFace.getId());
139 const shared_ptr<pit::Entry>& pitEntry)
141 NFD_LOG_DEBUG(
"Nack for " << nack.getInterest() <<
" from=" << inFace.getId() <<
": " << nack.getReason());
142 onTimeout(pitEntry->getName(), inFace.getId());
149 AsfStrategy::forwardInterest(
const Interest& interest,
151 const shared_ptr<pit::Entry>& pitEntry,
157 Interest probeInterest(interest);
158 probeInterest.refreshNonce();
159 NFD_LOG_TRACE(
"Sending probe for " << probeInterest << probeInterest.getNonce()
160 <<
" to FaceId: " << outFace.getId());
173 if (!faceInfo.isTimeoutScheduled()) {
178 <<
" FaceId: " << outFace.getId()
179 <<
" in " << time::duration_cast<time::milliseconds>(timeout) <<
" ms");
182 bind(&AsfStrategy::onTimeout,
this, interest.getName(), outFace.getId()));
184 faceInfo.setTimeoutEvent(
id, interest.getName());
201 static const RttStats::Rtt SORTING_RTT_TIMEOUT = time::microseconds::max();
202 static const RttStats::Rtt SORTING_RTT_NO_MEASUREMENT = SORTING_RTT_TIMEOUT / 2;
205 return SORTING_RTT_TIMEOUT.count();
208 return SORTING_RTT_NO_MEASUREMENT.count();
211 return stats.srtt.count();
216 AsfStrategy::getBestFaceForForwarding(
const fib::Entry& fibEntry,
const Interest& interest,
221 typedef std::function<bool(const FaceStats&, const FaceStats&)> FaceStatsPredicate;
222 typedef std::set<FaceStats, FaceStatsPredicate> FaceStatsSet;
224 FaceStatsSet rankedFaces(
225 [] (
const FaceStats& lhs,
const FaceStats& rhs) ->
bool {
230 if (lhsValue < rhsValue) {
233 else if (lhsValue == rhsValue) {
234 return lhs.cost < rhs.cost;
241 for (
const fib::NextHop& hop : fibEntry.
getNextHops()) {
242 Face& hopFace = hop.getFace();
244 if (hopFace.getId() == inFace.getId() ||
wouldViolateScope(inFace, interest, hopFace)) {
248 FaceInfo* info = m_measurements.
getFaceInfo(fibEntry, interest, hopFace);
250 if (info ==
nullptr) {
251 FaceStats stats = {&hopFace,
256 rankedFaces.insert(stats);
259 FaceStats stats = {&hopFace, info->getRtt(), info->getSrtt(), hop.getCost()};
260 rankedFaces.insert(stats);
266 if (it != rankedFaces.end()) {
275 AsfStrategy::onTimeout(
const Name& interestName,
face::FaceId faceId)
277 NFD_LOG_TRACE(
"FaceId: " << faceId <<
" for " << interestName <<
" has timed-out");
279 NamespaceInfo* namespaceInfo = m_measurements.
getNamespaceInfo(interestName);
281 if (namespaceInfo ==
nullptr) {
282 NFD_LOG_TRACE(
"FibEntry for " << interestName <<
" has been removed since timeout scheduling");
288 if (it == namespaceInfo->end()) {
289 it = namespaceInfo->insert(faceId);
292 FaceInfo& faceInfo = it->second;
293 faceInfo.recordTimeout(interestName);
297 AsfStrategy::sendNoRouteNack(
const Face& inFace,
const Interest& interest,
298 const shared_ptr<pit::Entry>& pitEntry)
300 NFD_LOG_DEBUG(interest <<
" from=" << inFace.getId() <<
" noNextHop");
302 lp::NackHeader nackHeader;
303 nackHeader.setReason(lp::NackReason::NO_ROUTE);
304 this->
sendNack(pitEntry, inFace, nackHeader);
void setInstanceName(const Name &name)
set strategy instance name
void afterForwardingProbe(const fib::Entry &fibEntry, const Interest &interest)
#define NFD_LOG_DEBUG(expression)
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)
Interest is retransmission and should be suppressed.
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
static Name makeInstanceName(const Name &input, const Name &strategyName)
construct a strategy instance name
time::duration< double, boost::micro > Rtt
FaceInfo & get(nfd::face::FaceId faceId)
Table::const_iterator iterator
void cancelTimeoutEvent(const Name &prefix)
FaceInfo * getFaceInfo(const fib::Entry &fibEntry, const Interest &interest, const Face &face)
const Name & getPrefix() const
Copyright (c) 2014-2015, Regents of the University of California, Arizona Board of Regents...
virtual Result decide(const Face &inFace, const Interest &interest, pit::Entry &pitEntry) const override
determines whether Interest is a retransmission, and if so, whether it shall be forwarded or suppress...
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
Interest is retransmission and should be forwarded.
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
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
Copyright (c) 2014-2016, Regents of the University of California, Arizona Board of Regents...
Interest is new (not a retransmission)
#define NFD_LOG_INIT(name)
EventId schedule(const time::nanoseconds &after, const Scheduler::Event &event)
schedule an event
static const Rtt RTT_TIMEOUT
static ParsedInstanceName parseInstanceName(const Name &input)
parse a strategy instance name
#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
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
Strategy information for each face in a namespace.
AsfStrategy(Forwarder &forwarder, const Name &name=getStrategyName())
static const Rtt RTT_NO_MEASUREMENT