36 const time::milliseconds BestRouteStrategy2::RETX_SUPPRESSION_INITIAL(10);
37 const time::milliseconds BestRouteStrategy2::RETX_SUPPRESSION_MAX(250);
41 , m_retxSuppression(RETX_SUPPRESSION_INITIAL,
47 BOOST_THROW_EXCEPTION(std::invalid_argument(
"BestRouteStrategy2 does not accept parameters"));
50 BOOST_THROW_EXCEPTION(std::invalid_argument(
51 "BestRouteStrategy2 does not support version " + std::to_string(*parsed.
version)));
59 static Name strategyName(
"/localhost/nfd/strategy/best-route/%FD%04");
74 const shared_ptr<pit::Entry>& pitEntry,
75 bool wantUnused =
false,
76 time::steady_clock::TimePoint now = time::steady_clock::TimePoint::min())
78 const Face& outFace = nexthop.
getFace();
81 if (&outFace == &inFace)
91 if (outRecord != pitEntry->out_end() && outRecord->getExpiry() > now) {
102 static inline fib::NextHopList::const_iterator
105 const shared_ptr<pit::Entry>& pitEntry)
107 fib::NextHopList::const_iterator found = nexthops.end();
108 time::steady_clock::TimePoint earliestRenewed = time::steady_clock::TimePoint::max();
109 for (fib::NextHopList::const_iterator it = nexthops.begin(); it != nexthops.end(); ++it) {
113 BOOST_ASSERT(outRecord != pitEntry->out_end());
114 if (outRecord->getLastRenewed() < earliestRenewed) {
116 earliestRenewed = outRecord->getLastRenewed();
124 const shared_ptr<pit::Entry>& pitEntry)
135 fib::NextHopList::const_iterator it = nexthops.end();
139 it = std::find_if(nexthops.begin(), nexthops.end(),
141 false, time::steady_clock::TimePoint::min()));
143 if (it == nexthops.end()) {
144 NFD_LOG_DEBUG(interest <<
" from=" << inFace.getId() <<
" noNextHop");
146 lp::NackHeader nackHeader;
147 nackHeader.setReason(lp::NackReason::NO_ROUTE);
148 this->
sendNack(pitEntry, inFace, nackHeader);
154 Face& outFace = it->getFace();
157 <<
" newPitEntry-to=" << outFace.getId());
162 it = std::find_if(nexthops.begin(), nexthops.end(),
164 true, time::steady_clock::now()));
165 if (it != nexthops.end()) {
166 Face& outFace = it->getFace();
169 <<
" retransmit-unused-to=" << outFace.getId());
175 if (it == nexthops.end()) {
176 NFD_LOG_DEBUG(interest <<
" from=" << inFace.getId() <<
" retransmitNoNextHop");
179 Face& outFace = it->getFace();
182 <<
" retransmit-retry-to=" << outFace.getId());
190 inline lp::NackReason
193 if (x == lp::NackReason::NONE) {
196 if (y == lp::NackReason::NONE) {
199 return static_cast<lp::NackReason
>(std::min(static_cast<int>(x), static_cast<int>(y)));
204 const shared_ptr<pit::Entry>& pitEntry)
206 int nOutRecordsNotNacked = 0;
207 Face* lastFaceNotNacked =
nullptr;
208 lp::NackReason leastSevereReason = lp::NackReason::NONE;
210 const lp::NackHeader* inNack = outR.getIncomingNack();
211 if (inNack ==
nullptr) {
212 ++nOutRecordsNotNacked;
213 lastFaceNotNacked = &outR.getFace();
220 lp::NackHeader outNack;
221 outNack.setReason(leastSevereReason);
223 if (nOutRecordsNotNacked == 1) {
224 BOOST_ASSERT(lastFaceNotNacked !=
nullptr);
226 if (inR != pitEntry->in_end()) {
228 NFD_LOG_DEBUG(nack.getInterest() <<
" nack-from=" << inFace.getId() <<
229 " nack=" << nack.getReason() <<
230 " nack-to(bidirectional)=" << lastFaceNotNacked->getId() <<
231 " out-nack=" << outNack.getReason());
232 this->
sendNack(pitEntry, *lastFaceNotNacked, outNack);
237 if (nOutRecordsNotNacked > 0) {
238 NFD_LOG_DEBUG(nack.getInterest() <<
" nack-from=" << inFace.getId() <<
239 " nack=" << nack.getReason() <<
240 " waiting=" << nOutRecordsNotNacked);
245 NFD_LOG_DEBUG(nack.getInterest() <<
" nack-from=" << inFace.getId() <<
246 " nack=" << nack.getReason() <<
247 " nack-to=all out-nack=" << outNack.getReason());
void setInstanceName(const Name &name)
set strategy instance name
#define NFD_LOG_DEBUG(expression)
void sendNacks(const shared_ptr< pit::Entry > &pitEntry, const lp::NackHeader &header, std::initializer_list< const Face * > exceptFaces=std::initializer_list< const Face * >())
send Nack to every face that has an in-record, except those in exceptFaces
contains information about an Interest toward an outgoing face
static const Name & getStrategyName()
Interest is retransmission and should be suppressed.
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
static bool isNextHopEligible(const Face &inFace, const Interest &interest, const fib::NextHop &nexthop, const shared_ptr< pit::Entry > &pitEntry, bool wantUnused=false, time::steady_clock::TimePoint now=time::steady_clock::TimePoint::min())
determines whether a NextHop is eligible
BestRouteStrategy2(Forwarder &forwarder, const Name &name=getStrategyName())
static Name makeInstanceName(const Name &input, const Name &strategyName)
construct a strategy instance name
Table::const_iterator iterator
Copyright (c) 2014-2015, Regents of the University of California, Arizona Board of Regents...
virtual Result decide(const Face &inFace, const Interest &interest, pit::Entry &pitEntry) const override
determines whether Interest is a retransmission, and if so, whether it shall be forwarded or suppress...
lp::NackReason compareLessSevere(lp::NackReason x, lp::NackReason y)
#define NFD_REGISTER_STRATEGY(S)
registers a strategy
a retransmission suppression decision algorithm that suppresses retransmissions using exponential bac...
std::vector< fib::NextHop > NextHopList
virtual void afterReceiveNack(const Face &inFace, const lp::Nack &nack, const shared_ptr< pit::Entry > &pitEntry) override
trigger after Nack is received
PartialName parameters
parameter components
virtual void afterReceiveInterest(const Face &inFace, const Interest &interest, const shared_ptr< pit::Entry > &pitEntry) override
trigger after Interest is received
ndn::optional< uint64_t > version
whether strategyName contains a version component
represents a forwarding strategy
Copyright (c) 2014-2016, Regents of the University of California, Arizona Board of Regents...
Interest is new (not a retransmission)
#define NFD_LOG_INIT(name)
static 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
static ParsedInstanceName parseInstanceName(const Name &input)
parse a strategy instance name
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 rejectPendingInterest(const shared_ptr< pit::Entry > &pitEntry)
decide that a pending Interest cannot be forwarded
const fib::Entry & lookupFib(const pit::Entry &pitEntry) const
performs a FIB lookup, considering Link object if present