37 const time::milliseconds AsfStrategy::RETX_SUPPRESSION_INITIAL(10);
38 const time::milliseconds AsfStrategy::RETX_SUPPRESSION_MAX(250);
42 , m_measurements(getMeasurements())
43 , m_probing(m_measurements)
44 , m_maxSilentTimeouts(0)
45 , m_retxSuppression(RETX_SUPPRESSION_INITIAL,
55 BOOST_THROW_EXCEPTION(std::invalid_argument(
61 <<
", Num silent timeouts=" << m_maxSilentTimeouts);
67 static Name strategyName(
"/localhost/nfd/strategy/asf/%FD%03");
72 AsfStrategy::processParams(
const PartialName& parsed)
74 for (
const auto& component : parsed) {
75 std::string parsedStr(reinterpret_cast<const char*>(component.value()), component.value_size());
76 auto n = parsedStr.find(
"~");
77 if (n == std::string::npos) {
78 BOOST_THROW_EXCEPTION(std::invalid_argument(
"Format is <parameter>~<value>"));
81 auto f = parsedStr.substr(0, n);
82 auto s = parsedStr.substr(n + 1);
83 if (f ==
"probing-interval") {
86 else if (f ==
"n-silent-timeouts") {
87 m_maxSilentTimeouts = getParamValue(f, s);
90 BOOST_THROW_EXCEPTION(std::invalid_argument(
"Parameter should be probing-interval or n-silent-timeouts"));
96 AsfStrategy::getParamValue(
const std::string& param,
const std::string& value)
99 if (!value.empty() && value[0] ==
'-')
100 BOOST_THROW_EXCEPTION(boost::bad_lexical_cast());
102 return boost::lexical_cast<uint64_t>(value);
104 catch (
const boost::bad_lexical_cast&) {
105 BOOST_THROW_EXCEPTION(std::invalid_argument(
"Value of " + param +
" must be a non-negative integer"));
111 const shared_ptr<pit::Entry>& pitEntry)
116 switch (suppressResult) {
128 if (nexthops.size() == 0) {
129 sendNoRouteNack(inFace, interest, pitEntry);
134 Face* faceToUse = getBestFaceForForwarding(fibEntry, interest, inFace);
136 if (faceToUse ==
nullptr) {
137 sendNoRouteNack(inFace, interest, pitEntry);
144 forwardInterest(interest, fibEntry, pitEntry, *faceToUse);
150 if (faceToProbe !=
nullptr) {
151 bool wantNewNonce =
true;
152 forwardInterest(interest, fibEntry, pitEntry, *faceToProbe, wantNewNonce);
160 const Face& inFace,
const Data& data)
164 if (namespaceInfo ==
nullptr) {
165 NFD_LOG_TRACE(
"Could not find measurements entry for " << pitEntry->getName());
171 if (faceInfo ==
nullptr) {
186 const shared_ptr<pit::Entry>& pitEntry)
189 onTimeout(pitEntry->getName(), inFace.
getId());
196 AsfStrategy::forwardInterest(
const Interest& interest,
198 const shared_ptr<pit::Entry>& pitEntry,
205 probeInterest.refreshNonce();
206 NFD_LOG_TRACE(
"Sending probe for " << probeInterest << probeInterest.getNonce()
207 <<
" to FaceId: " << outFace.
getId());
220 if (!faceInfo.isTimeoutScheduled()) {
225 <<
" FaceId: " << outFace.
getId()
226 <<
" in " << time::duration_cast<time::milliseconds>(timeout) <<
" ms");
229 bind(&AsfStrategy::onTimeout,
this, interest.
getName(), outFace.
getId()));
231 faceInfo.setTimeoutEvent(
id, interest.
getName());
248 static const RttStats::Rtt SORTING_RTT_TIMEOUT = time::microseconds::max();
249 static const RttStats::Rtt SORTING_RTT_NO_MEASUREMENT = SORTING_RTT_TIMEOUT / 2;
252 return SORTING_RTT_TIMEOUT.count();
255 return SORTING_RTT_NO_MEASUREMENT.count();
258 return stats.
srtt.count();
263 AsfStrategy::getBestFaceForForwarding(
const fib::Entry& fibEntry,
const Interest& interest,
268 typedef std::function<bool(
const FaceStats&,
const FaceStats&)> FaceStatsPredicate;
269 typedef std::set<FaceStats, FaceStatsPredicate> FaceStatsSet;
271 FaceStatsSet rankedFaces(
272 [] (
const FaceStats& lhs,
const FaceStats& rhs) ->
bool {
277 if (lhsValue < rhsValue) {
280 else if (lhsValue == rhsValue) {
281 return lhs.cost < rhs.cost;
288 for (
const fib::NextHop& hop : fibEntry.
getNextHops()) {
289 Face& hopFace = hop.getFace();
296 FaceInfo* info = m_measurements.
getFaceInfo(fibEntry, interest, hopFace.getId());
298 if (info ==
nullptr) {
299 FaceStats stats = {&hopFace,
304 rankedFaces.insert(stats);
307 FaceStats stats = {&hopFace, info->getRtt(), info->getSrtt(), hop.getCost()};
308 rankedFaces.insert(stats);
314 if (it != rankedFaces.end()) {
325 NamespaceInfo* namespaceInfo = m_measurements.
getNamespaceInfo(interestName);
327 if (namespaceInfo ==
nullptr) {
328 NFD_LOG_TRACE(
"FibEntry for " << interestName <<
" has been removed since timeout scheduling");
334 if (it == namespaceInfo->end()) {
335 it = namespaceInfo->insert(faceId);
338 FaceInfo& faceInfo = it->second;
340 faceInfo.setNSilentTimeouts(faceInfo.getNSilentTimeouts() + 1);
342 if (faceInfo.getNSilentTimeouts() <= m_maxSilentTimeouts) {
343 NFD_LOG_TRACE(
"FaceId " << faceId <<
" for " << interestName <<
" has timed-out " 344 << faceInfo.getNSilentTimeouts() <<
" time(s), ignoring");
346 namespaceInfo->extendFaceInfoLifetime(faceInfo, faceId);
348 if (faceInfo.isTimeoutScheduled()) {
349 faceInfo.cancelTimeoutEvent(interestName);
353 NFD_LOG_TRACE(
"FaceId " << faceId <<
" for " << interestName <<
" has timed-out");
354 faceInfo.recordTimeout(interestName);
359 AsfStrategy::sendNoRouteNack(
const Face& inFace,
const Interest& interest,
360 const shared_ptr<pit::Entry>& pitEntry)
362 NFD_LOG_DEBUG(interest <<
" from=" << inFace.getId() <<
" noNextHop");
365 nackHeader.
setReason(lp::NackReason::NO_ROUTE);
366 this->
sendNack(pitEntry, inFace, nackHeader);
void beforeSatisfyInterest(const shared_ptr< pit::Entry > &pitEntry, const Face &inFace, const Data &data) override
trigger before PIT entry is satisfied
Interest is retransmission and should be forwarded.
const Name & getPrefix() const
static ParsedInstanceName parseInstanceName(const Name &input)
parse a strategy instance name
FaceInfo * get(FaceId faceId)
const Name & getName() const
Get name.
void recordRtt(const shared_ptr< pit::Entry > &pitEntry, const Face &inFace)
time::microseconds Duration
generalization of a network interface
PartialName parameters
parameter components
void sendNack(const shared_ptr< pit::Entry > &pitEntry, const Face &outFace, const lp::NackHeader &header)
send Nack to outFace
NFD_REGISTER_STRATEGY(AsfStrategy)
void extendFaceInfoLifetime(FaceInfo &info, FaceId faceId)
FaceInfo & getOrCreateFaceInfo(const fib::Entry &fibEntry, const Interest &interest, FaceId faceId)
static const Name & getStrategyName()
Interest is retransmission and should be suppressed.
void setInstanceName(const Name &name)
set strategy instance name
Represents an Interest packet.
stores stategy information about each face in this namespace
static const Rtt RTT_TIMEOUT
Represents a collection of nexthops.
void cancelTimeoutEvent(const Name &prefix)
represents a Network Nack
void setProbingInterval(size_t probingInterval)
NackReason getReason() const
Table::const_iterator iterator
bool isProbingNeeded(const fib::Entry &fibEntry, const Interest &interest)
time::milliseconds getProbingInterval() const
Copyright (c) 2011-2015 Regents of the University of California.
Interest is new (not a retransmission)
Name PartialName
Represents an arbitrary sequence of name components.
NamespaceInfo & getOrCreateNamespaceInfo(const fib::Entry &fibEntry, const Interest &interest)
static const Rtt RTT_NO_MEASUREMENT
void rejectPendingInterest(const shared_ptr< pit::Entry > &pitEntry)
schedule the PIT entry for immediate deletion
Represents an absolute name.
Face * getFaceToProbe(const Face &inFace, const Interest &interest, const fib::Entry &fibEntry, const Face &faceUsed)
Strategy information for each face in a namespace.
represents a forwarding strategy
void afterReceiveNack(const Face &inFace, const lp::Nack &nack, const shared_ptr< pit::Entry > &pitEntry) override
trigger after Nack is received
optional< uint64_t > version
whether strategyName contains a version component
void afterReceiveInterest(const Face &inFace, const Interest &interest, const shared_ptr< pit::Entry > &pitEntry) override
trigger after Interest is received
NamespaceInfo * getNamespaceInfo(const Name &prefix)
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
EventId schedule(time::nanoseconds after, const EventCallback &event)
Schedule an event.
static Name makeInstanceName(const Name &input, const Name &strategyName)
construct a strategy instance name
void afterForwardingProbe(const fib::Entry &fibEntry, const Interest &interest)
FaceInfo * getFaceInfo(const fib::Entry &fibEntry, const Interest &interest, FaceId faceId)
std::string to_string(const V &v)
const NextHopList & getNextHops() const
double getValueForSorting(const FaceStats &stats)
uint64_t FaceId
identifies a face
A handle of scheduled event.
#define NFD_LOG_INIT(name)
Represents a Data packet.
a retransmission suppression decision algorithm that suppresses retransmissions using exponential bac...
void sendInterest(const shared_ptr< pit::Entry > &pitEntry, Face &outFace, const Interest &interest)
send Interest to outFace
AsfStrategy(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
Adaptive SRTT-based Forwarding Strategy.
RetxSuppressionResult decidePerPitEntry(pit::Entry &pitEntry)
determines whether Interest is a retransmission per pit entry and if so, whether it shall be forwarde...
bool isTimeoutScheduled() const
const Interest & getInterest() const
time::duration< double, boost::micro > Rtt
const Name & getName() const