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_maxSilentTimeouts(0)
46 , m_retxSuppression(RETX_SUPPRESSION_INITIAL,
56 NDN_THROW(std::invalid_argument(
57 "AsfStrategy does not support version " + to_string(*parsed.
version)));
62 <<
", Num silent timeouts=" << m_maxSilentTimeouts);
68 static Name strategyName(
"/localhost/nfd/strategy/asf/%FD%03");
73 AsfStrategy::processParams(
const PartialName& parsed)
75 for (
const auto& component : parsed) {
76 std::string parsedStr(reinterpret_cast<const char*>(component.value()), component.value_size());
77 auto n = parsedStr.find(
"~");
78 if (n == std::string::npos) {
79 NDN_THROW(std::invalid_argument(
"Format is <parameter>~<value>"));
82 auto f = parsedStr.substr(0, n);
83 auto s = parsedStr.substr(n + 1);
84 if (f ==
"probing-interval") {
87 else if (f ==
"n-silent-timeouts") {
88 m_maxSilentTimeouts = getParamValue(f, s);
91 NDN_THROW(std::invalid_argument(
"Parameter should be probing-interval or n-silent-timeouts"));
97 AsfStrategy::getParamValue(
const std::string& param,
const std::string& value)
100 if (!value.empty() && value[0] ==
'-')
101 NDN_THROW(boost::bad_lexical_cast());
103 return boost::lexical_cast<uint64_t>(value);
105 catch (
const boost::bad_lexical_cast&) {
106 NDN_THROW(std::invalid_argument(
"Value of " + param +
" must be a non-negative integer"));
111 AsfStrategy::sendAsfProbe(
const FaceEndpoint& ingress,
const Interest& interest,
112 const shared_ptr<pit::Entry>& pitEntry,
const Face& faceToUse,
115 Face* faceToProbe = m_probing.
getFaceToProbe(ingress.
face, interest, fibEntry, faceToUse);
116 if (faceToProbe !=
nullptr) {
117 forwardInterest(interest, fibEntry, pitEntry, *faceToProbe,
true);
124 const shared_ptr<pit::Entry>& pitEntry)
129 NFD_LOG_DEBUG(interest <<
" from=" << ingress <<
" suppressed");
137 if (nexthops.size() == 0) {
139 sendNoRouteNack(ingress, interest, pitEntry);
144 Face* faceToUse = getBestFaceForForwarding(fibEntry, interest, ingress.
face, pitEntry);
146 if (faceToUse ==
nullptr) {
147 sendNoRouteNack(ingress, interest, pitEntry);
152 NFD_LOG_TRACE(
"Forwarding interest to face: " << faceToUse->getId());
153 forwardInterest(interest, fibEntry, pitEntry, *faceToUse);
157 sendAsfProbe(ingress, interest, pitEntry, *faceToUse, fibEntry);
162 Face* faceToUse = getBestFaceForForwarding(fibEntry, interest, ingress.
face, pitEntry,
false);
164 if (faceToUse !=
nullptr) {
166 NFD_LOG_TRACE(
"Forwarding interest to face: " << faceToUse->getId());
167 forwardInterest(interest, fibEntry, pitEntry, *faceToUse);
173 auto it = nexthops.end();
175 if (it == nexthops.end()) {
176 NFD_LOG_DEBUG(interest <<
" from=" << ingress <<
" retransmitNoNextHop");
180 NFD_LOG_DEBUG(interest <<
" from=" << ingress <<
" retransmit-retry-to=" << egress);
191 if (namespaceInfo ==
nullptr) {
192 NFD_LOG_TRACE(
"Could not find measurements entry for " << pitEntry->getName());
198 if (faceInfo ==
nullptr) {
213 const shared_ptr<pit::Entry>& pitEntry)
215 NFD_LOG_DEBUG(
"Nack for " << nack.getInterest() <<
" from=" << ingress <<
": reason=" << nack.getReason());
216 onTimeout(pitEntry->getName(), ingress.
face.getId());
223 AsfStrategy::forwardInterest(
const Interest& interest,
225 const shared_ptr<pit::Entry>& pitEntry,
232 Interest probeInterest(interest);
233 probeInterest.refreshNonce();
234 NFD_LOG_TRACE(
"Sending probe for " << probeInterest << probeInterest.getNonce()
235 <<
" to: " << egress);
253 <<
" in " << time::duration_cast<time::milliseconds>(timeout) <<
" ms");
255 auto id =
getScheduler().schedule(timeout, bind(&AsfStrategy::onTimeout,
this,
256 interest.getName(), egress.face.getId()));
274 static const RttStats::Rtt SORTING_RTT_TIMEOUT = time::microseconds::max();
275 static const RttStats::Rtt SORTING_RTT_NO_MEASUREMENT = SORTING_RTT_TIMEOUT / 2;
278 return SORTING_RTT_TIMEOUT.count();
281 return SORTING_RTT_NO_MEASUREMENT.count();
284 return stats.srtt.count();
289 AsfStrategy::getBestFaceForForwarding(
const fib::Entry& fibEntry,
const Interest& interest,
290 const Face& inFace,
const shared_ptr<pit::Entry>& pitEntry,
295 typedef std::function<bool(const FaceStats&, const FaceStats&)> FaceStatsPredicate;
296 typedef std::set<FaceStats, FaceStatsPredicate> FaceStatsSet;
298 FaceStatsSet rankedFaces(
299 [] (
const FaceStats& lhs,
const FaceStats& rhs) ->
bool {
304 if (lhsValue < rhsValue) {
307 else if (lhsValue == rhsValue) {
308 return lhs.cost < rhs.cost;
315 auto now = time::steady_clock::now();
317 Face& hopFace = hop.getFace();
323 FaceInfo* info = m_measurements.getFaceInfo(fibEntry, interest, hopFace.getId());
325 if (info ==
nullptr) {
326 FaceStats stats = {&hopFace,
331 rankedFaces.insert(stats);
334 FaceStats stats = {&hopFace, info->
getRtt(), info->
getSrtt(), hop.getCost()};
335 rankedFaces.insert(stats);
341 if (it != rankedFaces.end()) {
350 AsfStrategy::onTimeout(
const Name& interestName,
const face::FaceId faceId)
352 NamespaceInfo* namespaceInfo = m_measurements.getNamespaceInfo(interestName);
354 if (namespaceInfo ==
nullptr) {
355 NFD_LOG_TRACE(
"FibEntry for " << interestName <<
" has been removed since timeout scheduling");
361 if (it == namespaceInfo->
end()) {
362 it = namespaceInfo->
insert(faceId);
370 NFD_LOG_TRACE(
"FaceId " << faceId <<
" for " << interestName <<
" has timed-out " 380 NFD_LOG_TRACE(
"FaceId " << faceId <<
" for " << interestName <<
" has timed-out");
386 AsfStrategy::sendNoRouteNack(
const FaceEndpoint& ingress,
const Interest& interest,
387 const shared_ptr<pit::Entry>& pitEntry)
389 NFD_LOG_DEBUG(interest <<
" from=" << ingress <<
" noNextHop");
391 lp::NackHeader nackHeader;
392 nackHeader.setReason(lp::NackReason::NO_ROUTE);
393 this->
sendNack(pitEntry, ingress, nackHeader);
Main class of NFD forwarding engine.
void setInstanceName(const Name &name)
set strategy instance name
void afterForwardingProbe(const fib::Entry &fibEntry, const Interest &interest)
void extendFaceInfoLifetime(FaceInfo &info, FaceId faceId)
RttStats::Rtt getRtt() const
static const Name & getStrategyName()
NamespaceInfo * getNamespaceInfo(const Name &prefix)
void sendNack(const shared_ptr< pit::Entry > &pitEntry, const FaceEndpoint &egress, const lp::NackHeader &header)
send Nack to egress
fib::NextHopList::const_iterator findEligibleNextHopWithEarliestOutRecord(const Face &inFace, const Interest &interest, const fib::NextHopList &nexthops, const shared_ptr< pit::Entry > &pitEntry)
pick an eligible NextHop with earliest out-record
NFD_REGISTER_STRATEGY(AsfStrategy)
void beforeSatisfyInterest(const shared_ptr< pit::Entry > &pitEntry, const FaceEndpoint &ingress, const Data &data) override
trigger before PIT entry is satisfied
FaceInfo & getOrCreateFaceInfo(const fib::Entry &fibEntry, const Interest &interest, FaceId faceId)
Interest is retransmission and should be suppressed.
FaceInfo * get(FaceId faceId)
static Name makeInstanceName(const Name &input, const Name &strategyName)
construct a strategy instance name
const FaceInfoTable::iterator insert(FaceId faceId)
RttStats::Rtt getSrtt() const
time::duration< double, boost::micro > Rtt
FaceInfoTable::iterator end()
time::microseconds Duration
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
Table::const_iterator iterator
void cancelTimeoutEvent(const Name &prefix)
FaceInfoTable::iterator find(FaceId faceId)
void afterReceiveNack(const FaceEndpoint &ingress, const lp::Nack &nack, const shared_ptr< pit::Entry > &pitEntry) override
trigger after Nack is received
const Name & getPrefix() const
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)
bool isNextHopEligible(const Face &inFace, const Interest &interest, const fib::NextHop &nexthop, const shared_ptr< pit::Entry > &pitEntry, bool wantUnused, time::steady_clock::TimePoint now)
determines whether a NextHop is eligible i.e.
a retransmission suppression decision algorithm that suppresses retransmissions using exponential bac...
NamespaceInfo & getOrCreateNamespaceInfo(const fib::Entry &fibEntry, const Interest &interest)
bool isProbingNeeded(const fib::Entry &fibEntry, const Interest &interest)
Represents a collection of nexthops.
PartialName parameters
parameter components
bool isTimeoutScheduled() const
void recordRtt(const shared_ptr< pit::Entry > &pitEntry, const Face &inFace)
time::milliseconds getProbingInterval() const
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
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
void setProbingInterval(size_t probingInterval)
size_t getNSilentTimeouts() const
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
void afterReceiveInterest(const FaceEndpoint &ingress, const Interest &interest, const shared_ptr< pit::Entry > &pitEntry) override
trigger after Interest is received
RttEstimator::Duration computeRto() const
Represents a nexthop record in a FIB entry.
const NextHopList & getNextHops() const
void setNSilentTimeouts(size_t nSilentTimeouts)
void rejectPendingInterest(const shared_ptr< pit::Entry > &pitEntry)
schedule the PIT entry for immediate deletion
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
optional< uint64_t > version
whether strategyName contains a version component