NS-3 based Named Data Networking (NDN) simulator
ndnSIM 2.0: NDN, CCN, CCNx, content centric networks
API Documentation
best-route-strategy2.cpp
Go to the documentation of this file.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
26 #include "best-route-strategy2.hpp"
27 #include "core/logger.hpp"
28 
29 namespace nfd {
30 namespace fw {
31 
32 NFD_LOG_INIT("BestRouteStrategy2");
33 
34 const Name BestRouteStrategy2::STRATEGY_NAME("ndn:/localhost/nfd/strategy/best-route/%FD%03");
36 
38  : Strategy(forwarder, name)
39 {
40 }
41 
47 static inline bool
48 predicate_NextHop_eligible(const shared_ptr<pit::Entry>& pitEntry,
49  const fib::NextHop& nexthop, FaceId currentDownstream,
50  bool wantUnused = false,
51  time::steady_clock::TimePoint now = time::steady_clock::TimePoint::min())
52 {
53  shared_ptr<Face> upstream = nexthop.getFace();
54 
55  // upstream is current downstream
56  if (upstream->getId() == currentDownstream)
57  return false;
58 
59  // forwarding would violate scope
60  if (pitEntry->violatesScope(*upstream))
61  return false;
62 
63  if (wantUnused) {
64  // NextHop must not have unexpired OutRecord
65  pit::OutRecordCollection::const_iterator outRecord = pitEntry->getOutRecord(*upstream);
66  if (outRecord != pitEntry->getOutRecords().end() &&
67  outRecord->getExpiry() > now) {
68  return false;
69  }
70  }
71 
72  return true;
73 }
74 
78 static inline fib::NextHopList::const_iterator
79 findEligibleNextHopWithEarliestOutRecord(const shared_ptr<pit::Entry>& pitEntry,
80  const fib::NextHopList& nexthops,
81  FaceId currentDownstream)
82 {
83  fib::NextHopList::const_iterator found = nexthops.end();
84  time::steady_clock::TimePoint earliestRenewed = time::steady_clock::TimePoint::max();
85  for (fib::NextHopList::const_iterator it = nexthops.begin(); it != nexthops.end(); ++it) {
86  if (!predicate_NextHop_eligible(pitEntry, *it, currentDownstream))
87  continue;
88  pit::OutRecordCollection::const_iterator outRecord = pitEntry->getOutRecord(*it->getFace());
89  BOOST_ASSERT(outRecord != pitEntry->getOutRecords().end());
90  if (outRecord->getLastRenewed() < earliestRenewed) {
91  found = it;
92  earliestRenewed = outRecord->getLastRenewed();
93  }
94  }
95  return found;
96 }
97 
98 void
100  const Interest& interest,
101  shared_ptr<fib::Entry> fibEntry,
102  shared_ptr<pit::Entry> pitEntry)
103 {
104  const fib::NextHopList& nexthops = fibEntry->getNextHops();
105  fib::NextHopList::const_iterator it = nexthops.end();
106 
107  RetxSuppression::Result suppression =
108  m_retxSuppression.decide(inFace, interest, *pitEntry);
109  if (suppression == RetxSuppression::NEW) {
110  // forward to nexthop with lowest cost except downstream
111  it = std::find_if(nexthops.begin(), nexthops.end(),
112  bind(&predicate_NextHop_eligible, pitEntry, _1, inFace.getId(),
113  false, time::steady_clock::TimePoint::min()));
114 
115  if (it == nexthops.end()) {
116  NFD_LOG_DEBUG(interest << " from=" << inFace.getId() << " noNextHop");
117  this->rejectPendingInterest(pitEntry);
118  return;
119  }
120 
121  shared_ptr<Face> outFace = it->getFace();
122  this->sendInterest(pitEntry, outFace);
123  NFD_LOG_DEBUG(interest << " from=" << inFace.getId()
124  << " newPitEntry-to=" << outFace->getId());
125  return;
126  }
127 
128  if (suppression == RetxSuppression::SUPPRESS) {
129  NFD_LOG_DEBUG(interest << " from=" << inFace.getId()
130  << " suppressed");
131  return;
132  }
133 
134  // find an unused upstream with lowest cost except downstream
135  it = std::find_if(nexthops.begin(), nexthops.end(),
136  bind(&predicate_NextHop_eligible, pitEntry, _1, inFace.getId(),
137  true, time::steady_clock::now()));
138  if (it != nexthops.end()) {
139  shared_ptr<Face> outFace = it->getFace();
140  this->sendInterest(pitEntry, outFace);
141  NFD_LOG_DEBUG(interest << " from=" << inFace.getId()
142  << " retransmit-unused-to=" << outFace->getId());
143  return;
144  }
145 
146  // find an eligible upstream that is used earliest
147  it = findEligibleNextHopWithEarliestOutRecord(pitEntry, nexthops, inFace.getId());
148  if (it == nexthops.end()) {
149  NFD_LOG_DEBUG(interest << " from=" << inFace.getId() << " retransmitNoNextHop");
150  }
151  else {
152  shared_ptr<Face> outFace = it->getFace();
153  this->sendInterest(pitEntry, outFace);
154  NFD_LOG_DEBUG(interest << " from=" << inFace.getId()
155  << " retransmit-retry-to=" << outFace->getId());
156  }
157 }
158 
159 } // namespace fw
160 } // namespace nfd
time_point TimePoint
Definition: time.hpp:108
virtual void afterReceiveInterest(const Face &inFace, const Interest &interest, shared_ptr< fib::Entry > fibEntry, shared_ptr< pit::Entry > pitEntry) 1
trigger after Interest is received
#define NFD_LOG_DEBUG(expression)
Definition: logger.hpp:36
static time_point now() noexcept
Definition: time.cpp:79
Best Route strategy version 3.
Interest is retransmission and should be suppressed.
main class of NFD
Definition: forwarder.hpp:54
represents an Interest packet
Definition: interest.hpp:45
represents a face
Definition: face.hpp:57
Interest is new (not a retransmission)
Copyright (c) 2011-2015 Regents of the University of California.
Definition: ndn-common.hpp:38
NFD_REGISTER_STRATEGY(AccessStrategy)
std::vector< fib::NextHop > NextHopList
Definition: fib-entry.hpp:48
identifies a face
Name abstraction to represent an absolute name.
Definition: name.hpp:46
void rejectPendingInterest(shared_ptr< pit::Entry > pitEntry)
decide that a pending Interest cannot be forwarded
Definition: strategy.hpp:169
represents a forwarding strategy
Definition: strategy.hpp:38
virtual Result decide(const Face &inFace, const Interest &interest, pit::Entry &pitEntry) const 1
determines whether Interest is a retransmission, and if so, whether it shall be forwarded or suppress...
const shared_ptr< Face > & getFace() const
Definition: fib-nexthop.cpp:38
static bool predicate_NextHop_eligible(const shared_ptr< pit::Entry > &pitEntry, const fib::NextHop &nexthop, FaceId currentDownstream, bool wantUnused=false, time::steady_clock::TimePoint now=time::steady_clock::TimePoint::min())
determines whether a NextHop is eligible
#define NFD_LOG_INIT(name)
Definition: logger.hpp:33
void sendInterest(shared_ptr< pit::Entry > pitEntry, shared_ptr< Face > outFace, bool wantNewNonce=false)
send Interest to outFace
Definition: strategy.hpp:161
BestRouteStrategy2(Forwarder &forwarder, const Name &name=STRATEGY_NAME)
FaceId getId() const
Definition: face.hpp:221
static fib::NextHopList::const_iterator findEligibleNextHopWithEarliestOutRecord(const shared_ptr< pit::Entry > &pitEntry, const fib::NextHopList &nexthops, FaceId currentDownstream)
pick an eligible NextHop with earliest OutRecord
represents a nexthop record in FIB entry
Definition: fib-nexthop.hpp:38