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(
63 static Name strategyName(
"/localhost/nfd/strategy/asf/%FD%02");
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 NFD_LOG_TRACE(
"Forwarding interest to face: " << faceToUse->getId());
102 forwardInterest(interest, fibEntry, pitEntry, *faceToUse);
108 if (faceToProbe !=
nullptr) {
109 bool wantNewNonce =
true;
110 forwardInterest(interest, fibEntry, pitEntry, *faceToProbe, wantNewNonce);
118 const Face& inFace,
const Data& data)
122 if (namespaceInfo ==
nullptr) {
123 NFD_LOG_TRACE(
"Could not find measurements entry for " << pitEntry->getName());
128 FaceInfo* faceInfo = namespaceInfo->
get(inFace.getId());
129 if (faceInfo ==
nullptr) {
144 const shared_ptr<pit::Entry>& pitEntry)
147 onTimeout(pitEntry->getName(), inFace.getId());
154 AsfStrategy::forwardInterest(
const Interest& interest,
156 const shared_ptr<pit::Entry>& pitEntry,
165 <<
" to FaceId: " << outFace.getId());
183 <<
" FaceId: " << outFace.getId()
187 bind(&AsfStrategy::onTimeout,
this, interest.
getName(), outFace.getId()));
206 static const RttStats::Rtt SORTING_RTT_TIMEOUT = time::microseconds::max();
207 static const RttStats::Rtt SORTING_RTT_NO_MEASUREMENT = SORTING_RTT_TIMEOUT / 2;
210 return SORTING_RTT_TIMEOUT.count();
213 return SORTING_RTT_NO_MEASUREMENT.count();
216 return stats.
srtt.count();
221 AsfStrategy::getBestFaceForForwarding(
const fib::Entry& fibEntry,
const Interest& interest,
226 typedef std::function<bool(const FaceStats&, const FaceStats&)> FaceStatsPredicate;
227 typedef std::set<FaceStats, FaceStatsPredicate> FaceStatsSet;
229 FaceStatsSet rankedFaces(
235 if (lhsValue < rhsValue) {
238 else if (lhsValue == rhsValue) {
247 Face& hopFace = hop.getFace();
254 FaceInfo* info = m_measurements.getFaceInfo(fibEntry, interest, hopFace);
256 if (info ==
nullptr) {
262 rankedFaces.insert(stats);
266 rankedFaces.insert(stats);
272 if (it != rankedFaces.end()) {
283 NFD_LOG_TRACE(
"FaceId: " << faceId <<
" for " << interestName <<
" has timed-out");
285 NamespaceInfo* namespaceInfo = m_measurements.getNamespaceInfo(interestName);
287 if (namespaceInfo ==
nullptr) {
288 NFD_LOG_TRACE(
"FibEntry for " << interestName <<
" has been removed since timeout scheduling");
294 if (it == namespaceInfo->
end()) {
295 it = namespaceInfo->
insert(faceId);
303 AsfStrategy::sendNoRouteNack(
const Face& inFace,
const Interest& interest,
304 const shared_ptr<pit::Entry>& pitEntry)
306 NFD_LOG_DEBUG(interest <<
" from=" << inFace.getId() <<
" noNextHop");
309 nackHeader.
setReason(lp::NackReason::NO_ROUTE);
310 this->
sendNack(pitEntry, inFace, nackHeader);
virtual 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 & getName() const
static ParsedInstanceName parseInstanceName(const Name &input)
parse a strategy instance name
FaceInfo & getOrCreateFaceInfo(const fib::Entry &fibEntry, const Interest &interest, const Face &face)
void recordRtt(const shared_ptr< pit::Entry > &pitEntry, const Face &inFace)
bool isTimeoutScheduled() const
void extendFaceInfoLifetime(FaceInfo &info, const Face &face)
PartialName parameters
parameter components
void sendNack(const shared_ptr< pit::Entry > &pitEntry, const Face &outFace, const lp::NackHeader &header)
send Nack to outFace
void refreshNonce()
Refresh nonce.
NFD_REGISTER_STRATEGY(AsfStrategy)
boost::posix_time::time_duration milliseconds(long duration)
RttStats::Rtt getSrtt() const
const Interest & getInterest() const
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)
FaceInfoTable::iterator end()
ndn::optional< uint64_t > version
whether strategyName contains a version component
uint32_t getNonce() const
Get nonce.
represents a Network Nack
Table::const_iterator iterator
NackReason getReason() const
std::shared_ptr< ns3::EventId > EventId
RttStats::Rtt getRtt() const
bool isProbingNeeded(const fib::Entry &fibEntry, const Interest &interest)
#define NFD_LOG_TRACE(expression)
Copyright (c) 2011-2015 Regents of the University of California.
Interest is new (not a retransmission)
FaceInfoTable::iterator find(nfd::face::FaceId faceId)
std::vector< fib::NextHop > NextHopList
const fib::Entry & lookupFib(const pit::Entry &pitEntry) const
performs a FIB lookup, considering Link object if present
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.
void setTimeoutEvent(const scheduler::EventId &id, const Name &interestName)
Face * getFaceToProbe(const Face &inFace, const Interest &interest, const fib::Entry &fibEntry, const Face &faceUsed)
RttEstimator::Duration computeRto() const
const NextHopList & getNextHops() const
Strategy information for each face in a namespace.
represents a forwarding strategy
const FaceInfoTable::iterator insert(nfd::face::FaceId faceId)
virtual void afterReceiveNack(const Face &inFace, const lp::Nack &nack, const shared_ptr< pit::Entry > &pitEntry) override
trigger after Nack is received
const Name & getName() const
Get name.
virtual 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.
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 recordTimeout(const Name &interestName)
void afterForwardingProbe(const fib::Entry &fibEntry, const Interest &interest)
std::string to_string(const V &v)
FaceInfo * get(nfd::face::FaceId faceId)
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...
const Name & getPrefix() const
time::duration< double, boost::micro > Rtt
represents a nexthop record in FIB entry