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 BOOST_THROW_EXCEPTION(std::invalid_argument(
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 BOOST_THROW_EXCEPTION(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 BOOST_THROW_EXCEPTION(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 BOOST_THROW_EXCEPTION(boost::bad_lexical_cast());
103 return boost::lexical_cast<uint64_t>(value);
105 catch (
const boost::bad_lexical_cast&) {
106 BOOST_THROW_EXCEPTION(std::invalid_argument(
"Value of " + param +
" must be a non-negative integer"));
112 const shared_ptr<pit::Entry>& pitEntry)
117 switch (suppressResult) {
129 if (nexthops.size() == 0) {
130 sendNoRouteNack(inFace, interest, pitEntry);
135 Face* faceToUse = getBestFaceForForwarding(fibEntry, interest, inFace);
137 if (faceToUse ==
nullptr) {
138 sendNoRouteNack(inFace, interest, pitEntry);
145 forwardInterest(interest, fibEntry, pitEntry, *faceToUse);
151 if (faceToProbe !=
nullptr) {
152 bool wantNewNonce =
true;
153 forwardInterest(interest, fibEntry, pitEntry, *faceToProbe, wantNewNonce);
161 const Face& inFace,
const Data& data)
165 if (namespaceInfo ==
nullptr) {
166 NFD_LOG_TRACE(
"Could not find measurements entry for " << pitEntry->getName());
172 if (faceInfo ==
nullptr) {
187 const shared_ptr<pit::Entry>& pitEntry)
190 onTimeout(pitEntry->getName(), inFace.
getId());
197 AsfStrategy::forwardInterest(
const Interest& interest,
199 const shared_ptr<pit::Entry>& pitEntry,
206 probeInterest.refreshNonce();
207 NFD_LOG_TRACE(
"Sending probe for " << probeInterest << probeInterest.getNonce()
208 <<
" to FaceId: " << outFace.
getId());
221 if (!faceInfo.isTimeoutScheduled()) {
226 <<
" FaceId: " << outFace.
getId()
227 <<
" in " << time::duration_cast<time::milliseconds>(timeout) <<
" ms");
230 bind(&AsfStrategy::onTimeout,
this, interest.
getName(), outFace.
getId()));
232 faceInfo.setTimeoutEvent(
id, interest.
getName());
249 static const RttStats::Rtt SORTING_RTT_TIMEOUT = time::microseconds::max();
250 static const RttStats::Rtt SORTING_RTT_NO_MEASUREMENT = SORTING_RTT_TIMEOUT / 2;
253 return SORTING_RTT_TIMEOUT.count();
256 return SORTING_RTT_NO_MEASUREMENT.count();
259 return stats.
srtt.count();
264 AsfStrategy::getBestFaceForForwarding(
const fib::Entry& fibEntry,
const Interest& interest,
269 typedef std::function<bool(const FaceStats&, const FaceStats&)> FaceStatsPredicate;
270 typedef std::set<FaceStats, FaceStatsPredicate> FaceStatsSet;
272 FaceStatsSet rankedFaces(
273 [] (
const FaceStats& lhs,
const FaceStats& rhs) ->
bool {
278 if (lhsValue < rhsValue) {
281 else if (lhsValue == rhsValue) {
282 return lhs.cost < rhs.cost;
289 for (
const fib::NextHop& hop : fibEntry.
getNextHops()) {
290 Face& hopFace = hop.getFace();
297 FaceInfo* info = m_measurements.
getFaceInfo(fibEntry, interest, hopFace.getId());
299 if (info ==
nullptr) {
300 FaceStats stats = {&hopFace,
305 rankedFaces.insert(stats);
308 FaceStats stats = {&hopFace, info->getRtt(), info->getSrtt(), hop.getCost()};
309 rankedFaces.insert(stats);
315 if (it != rankedFaces.end()) {
326 NamespaceInfo* namespaceInfo = m_measurements.
getNamespaceInfo(interestName);
328 if (namespaceInfo ==
nullptr) {
329 NFD_LOG_TRACE(
"FibEntry for " << interestName <<
" has been removed since timeout scheduling");
335 if (it == namespaceInfo->end()) {
336 it = namespaceInfo->insert(faceId);
339 FaceInfo& faceInfo = it->second;
341 faceInfo.setNSilentTimeouts(faceInfo.getNSilentTimeouts() + 1);
343 if (faceInfo.getNSilentTimeouts() <= m_maxSilentTimeouts) {
344 NFD_LOG_TRACE(
"FaceId " << faceId <<
" for " << interestName <<
" has timed-out " 345 << faceInfo.getNSilentTimeouts() <<
" time(s), ignoring");
347 namespaceInfo->extendFaceInfoLifetime(faceInfo, faceId);
349 if (faceInfo.isTimeoutScheduled()) {
350 faceInfo.cancelTimeoutEvent(interestName);
354 NFD_LOG_TRACE(
"FaceId " << faceId <<
" for " << interestName <<
" has timed-out");
355 faceInfo.recordTimeout(interestName);
360 AsfStrategy::sendNoRouteNack(
const Face& inFace,
const Interest& interest,
361 const shared_ptr<pit::Entry>& pitEntry)
363 NFD_LOG_DEBUG(interest <<
" from=" << inFace.getId() <<
" noNextHop");
366 nackHeader.
setReason(lp::NackReason::NO_ROUTE);
367 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
time::microseconds Duration
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)
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
#define NFD_LOG_DEBUG(expression)
stores stategy information about each face in this namespace
static const Rtt RTT_TIMEOUT
void cancelTimeoutEvent(const Name &prefix)
ndn::optional< uint64_t > version
whether strategyName contains a version component
represents a Network Nack
void setProbingInterval(size_t probingInterval)
NackReason getReason() const
Table::const_iterator iterator
std::shared_ptr< ns3::EventId > EventId
bool isProbingNeeded(const fib::Entry &fibEntry, const Interest &interest)
#define NFD_LOG_TRACE(expression)
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.
std::vector< fib::NextHop > NextHopList
NamespaceInfo & getOrCreateNamespaceInfo(const fib::Entry &fibEntry, const Interest &interest)
static const Rtt RTT_NO_MEASUREMENT
void rejectPendingInterest(const shared_ptr< pit::Entry > &pitEntry)
decide that a pending Interest cannot be forwarded
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
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
#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