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(
56 "AsfStrategy does not support version " + to_string(*parsed.
version)));
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) {
121 NFD_LOG_DEBUG(interest <<
" from=" << inFace.getId() <<
" suppressed");
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);
142 NFD_LOG_TRACE(
"Forwarding interest to face: " << faceToUse->getId());
144 forwardInterest(interest, fibEntry, pitEntry, *faceToUse);
148 Face* faceToProbe = m_probing.
getFaceToProbe(inFace, interest, fibEntry, *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());
170 FaceInfo* faceInfo = namespaceInfo->
get(inFace.getId());
171 if (faceInfo ==
nullptr) {
186 const shared_ptr<pit::Entry>& pitEntry)
188 NFD_LOG_DEBUG(
"Nack for " << nack.getInterest() <<
" from=" << inFace.getId() <<
": " << nack.getReason());
189 onTimeout(pitEntry->getName(), inFace.getId());
196 AsfStrategy::forwardInterest(
const Interest& interest,
198 const shared_ptr<pit::Entry>& pitEntry,
204 Interest probeInterest(interest);
205 probeInterest.refreshNonce();
206 NFD_LOG_TRACE(
"Sending probe for " << probeInterest << probeInterest.getNonce()
207 <<
" to FaceId: " << outFace.getId());
225 <<
" FaceId: " << outFace.getId()
226 <<
" in " << time::duration_cast<time::milliseconds>(timeout) <<
" ms");
229 bind(&AsfStrategy::onTimeout,
this, interest.getName(), outFace.getId()));
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;
289 Face& hopFace = hop.getFace();
291 if ((hopFace.getId() == inFace.getId() && hopFace.getLinkType() != ndn::nfd::LINK_TYPE_AD_HOC) ||
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()) {
323 AsfStrategy::onTimeout(
const Name& interestName,
const face::FaceId faceId)
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);
343 NFD_LOG_TRACE(
"FaceId " << faceId <<
" for " << interestName <<
" has timed-out " 353 NFD_LOG_TRACE(
"FaceId " << faceId <<
" for " << interestName <<
" has timed-out");
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");
364 lp::NackHeader nackHeader;
365 nackHeader.setReason(lp::NackReason::NO_ROUTE);
366 this->
sendNack(pitEntry, inFace, nackHeader);
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)
void extendFaceInfoLifetime(FaceInfo &info, FaceId faceId)
RttStats::Rtt getRtt() const
static const Name & getStrategyName()
NamespaceInfo * getNamespaceInfo(const Name &prefix)
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 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
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
Table::const_iterator iterator
void cancelTimeoutEvent(const Name &prefix)
FaceInfoTable::iterator find(FaceId faceId)
const Name & getPrefix() const
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)
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 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.
void setProbingInterval(size_t probingInterval)
void afterReceiveInterest(const Face &inFace, const Interest &interest, const shared_ptr< pit::Entry > &pitEntry) override
trigger after Interest is received
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
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 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