NS-3 based Named Data Networking (NDN) simulator
ndnSIM 2.3: NDN, CCN, CCNx, content centric networks
API Documentation
forwarder.hpp
Go to the documentation of this file.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
26 #ifndef NFD_DAEMON_FW_FORWARDER_HPP
27 #define NFD_DAEMON_FW_FORWARDER_HPP
28 
29 #include "core/common.hpp"
30 #include "core/scheduler.hpp"
31 #include "forwarder-counters.hpp"
32 #include "face-table.hpp"
34 #include "table/fib.hpp"
35 #include "table/pit.hpp"
36 #include "table/cs.hpp"
37 #include "table/measurements.hpp"
41 
42 #include "ns3/ndnSIM/model/cs/ndn-content-store.hpp"
43 
44 namespace nfd {
45 
46 namespace fw {
47 class Strategy;
48 } // namespace fw
49 
54 class Forwarder
55 {
56 public:
57  Forwarder();
58 
60  ~Forwarder();
61 
62  const ForwarderCounters&
63  getCounters() const
64  {
65  return m_counters;
66  }
67 
68 public: // faces and policies
69  FaceTable&
71  {
72  return m_faceTable;
73  }
74 
79  Face*
80  getFace(FaceId id) const
81  {
82  return m_faceTable.get(id);
83  }
84 
89  void
90  addFace(shared_ptr<Face> face)
91  {
92  m_faceTable.add(face);
93  }
94 
97  {
98  return *m_unsolicitedDataPolicy;
99  }
100 
101  void
102  setUnsolicitedDataPolicy(unique_ptr<fw::UnsolicitedDataPolicy> policy)
103  {
104  BOOST_ASSERT(policy != nullptr);
105  m_unsolicitedDataPolicy = std::move(policy);
106  }
107 
108 public: // forwarding entrypoints and tables
113  void
114  startProcessInterest(Face& face, const Interest& interest);
115 
120  void
121  startProcessData(Face& face, const Data& data);
122 
127  void
128  startProcessNack(Face& face, const lp::Nack& nack);
129 
130  NameTree&
132  {
133  return m_nameTree;
134  }
135 
136  Fib&
138  {
139  return m_fib;
140  }
141 
142  Pit&
144  {
145  return m_pit;
146  }
147 
148  Cs&
150  {
151  return m_cs;
152  }
153 
154  Measurements&
156  {
157  return m_measurements;
158  }
159 
162  {
163  return m_strategyChoice;
164  }
165 
168  {
169  return m_deadNonceList;
170  }
171 
174  {
175  return m_networkRegionTable;
176  }
177 
178 public: // allow enabling ndnSIM content store (will be removed in the future)
179  void
180  setCsFromNdnSim(ns3::Ptr<ns3::ndn::ContentStore> cs)
181  {
182  m_csFromNdnSim = cs;
183  }
184 
185 public:
190 
195 
196 PUBLIC_WITH_TESTS_ELSE_PRIVATE: // pipelines
199  VIRTUAL_WITH_TESTS void
200  onIncomingInterest(Face& inFace, const Interest& interest);
201 
204  VIRTUAL_WITH_TESTS void
205  onInterestLoop(Face& inFace, const Interest& interest);
206 
209  VIRTUAL_WITH_TESTS void
210  onContentStoreMiss(const Face& inFace, const shared_ptr<pit::Entry>& pitEntry, const Interest& interest);
211 
214  VIRTUAL_WITH_TESTS void
215  onContentStoreHit(const Face& inFace, const shared_ptr<pit::Entry>& pitEntry,
216  const Interest& interest, const Data& data);
217 
220  VIRTUAL_WITH_TESTS void
221  onOutgoingInterest(const shared_ptr<pit::Entry>& pitEntry, Face& outFace, const Interest& interest);
222 
225  VIRTUAL_WITH_TESTS void
226  onInterestReject(const shared_ptr<pit::Entry>& pitEntry);
227 
230  VIRTUAL_WITH_TESTS void
231  onInterestUnsatisfied(const shared_ptr<pit::Entry>& pitEntry);
232 
237  VIRTUAL_WITH_TESTS void
238  onInterestFinalize(const shared_ptr<pit::Entry>& pitEntry, bool isSatisfied,
239  time::milliseconds dataFreshnessPeriod = time::milliseconds(-1));
240 
243  VIRTUAL_WITH_TESTS void
244  onIncomingData(Face& inFace, const Data& data);
245 
248  VIRTUAL_WITH_TESTS void
249  onDataUnsolicited(Face& inFace, const Data& data);
250 
253  VIRTUAL_WITH_TESTS void
254  onOutgoingData(const Data& data, Face& outFace);
255 
258  VIRTUAL_WITH_TESTS void
259  onIncomingNack(Face& inFace, const lp::Nack& nack);
260 
263  VIRTUAL_WITH_TESTS void
264  onOutgoingNack(const shared_ptr<pit::Entry>& pitEntry, const Face& outFace, const lp::NackHeader& nack);
265 
267  VIRTUAL_WITH_TESTS void
268  setUnsatisfyTimer(const shared_ptr<pit::Entry>& pitEntry);
269 
270  VIRTUAL_WITH_TESTS void
271  setStragglerTimer(const shared_ptr<pit::Entry>& pitEntry, bool isSatisfied,
272  time::milliseconds dataFreshnessPeriod = time::milliseconds(-1));
273 
274  VIRTUAL_WITH_TESTS void
275  cancelUnsatisfyAndStragglerTimer(pit::Entry& pitEntry);
276 
281  VIRTUAL_WITH_TESTS void
282  insertDeadNonceList(pit::Entry& pitEntry, bool isSatisfied,
283  time::milliseconds dataFreshnessPeriod, Face* upstream);
284 
287 #ifdef WITH_TESTS
288  virtual void
289  dispatchToStrategy(pit::Entry& pitEntry, function<void(fw::Strategy&)> trigger)
290 #else
291  template<class Function>
292  void
293  dispatchToStrategy(pit::Entry& pitEntry, Function trigger)
294 #endif
295  {
296  trigger(m_strategyChoice.findEffectiveStrategy(pitEntry));
297  }
298 
299 private:
300  ForwarderCounters m_counters;
301 
302  FaceTable m_faceTable;
303  unique_ptr<fw::UnsolicitedDataPolicy> m_unsolicitedDataPolicy;
304 
305  NameTree m_nameTree;
306  Fib m_fib;
307  Pit m_pit;
308  Cs m_cs;
309  Measurements m_measurements;
310  StrategyChoice m_strategyChoice;
311  DeadNonceList m_deadNonceList;
312  NetworkRegionTable m_networkRegionTable;
313  shared_ptr<Face> m_csFace;
314 
315  ns3::Ptr<ns3::ndn::ContentStore> m_csFromNdnSim;
316 
317  // allow Strategy (base class) to enter pipelines
318  friend class fw::Strategy;
319 };
320 
321 } // namespace nfd
322 
323 #endif // NFD_DAEMON_FW_FORWARDER_HPP
#define PUBLIC_WITH_TESTS_ELSE_PRIVATE
Definition: common.hpp:40
signal::Signal< Forwarder, pit::Entry, Face, Data > beforeSatisfyInterest
trigger before PIT entry is satisfied
Definition: forwarder.hpp:189
const ForwarderCounters & getCounters() const
Definition: forwarder.hpp:63
represents the Dead Nonce list
counters provided by Forwarder
generalization of a network interface
Definition: face.hpp:67
Copyright (c) 2014-2016, Regents of the University of California, Arizona Board of Regents...
DeadNonceList & getDeadNonceList()
Definition: forwarder.hpp:167
void addFace(shared_ptr< Face > face)
add new Face
Definition: forwarder.hpp:90
Fib & getFib()
Definition: forwarder.hpp:137
determines how to process an unsolicited Data
#define VIRTUAL_WITH_TESTS
Copyright (c) 2014-2016, Regents of the University of California, Arizona Board of Regents...
Definition: common.hpp:38
main class of NFD
Definition: forwarder.hpp:54
represents an Interest packet
Definition: interest.hpp:42
stores a collection of producer region names
StrategyChoice & getStrategyChoice()
Definition: forwarder.hpp:161
provides a lightweight signal / event system
represents a Network Nack
Definition: nack.hpp:40
represents the Interest Table
Definition: pit.hpp:46
FaceTable & getFaceTable()
Definition: forwarder.hpp:70
container of all faces
Definition: face-table.hpp:37
Copyright (c) 2011-2015 Regents of the University of California.
Definition: ndn-common.hpp:40
an Interest table entry
Definition: pit-entry.hpp:57
signal::Signal< Forwarder, pit::Entry > beforeExpirePendingInterest
trigger before PIT entry expires
Definition: forwarder.hpp:194
represents the Forwarding Information Base (FIB)
Definition: fib.hpp:47
represents the Measurements table
Forwarder
Definition: forwarder.cpp:37
represents the ContentStore
Definition: cs.hpp:65
fw::UnsolicitedDataPolicy & getUnsolicitedDataPolicy() const
Definition: forwarder.hpp:96
represents a forwarding strategy
Definition: strategy.hpp:38
a common index structure for FIB, PIT, StrategyChoice, and Measurements
Definition: name-tree.hpp:36
void setCsFromNdnSim(ns3::Ptr< ns3::ndn::ContentStore > cs)
Definition: forwarder.hpp:180
represents the Strategy Choice table
NetworkRegionTable & getNetworkRegionTable()
Definition: forwarder.hpp:173
Measurements & getMeasurements()
Definition: forwarder.hpp:155
Pit & getPit()
Definition: forwarder.hpp:143
#define PROTECTED_WITH_TESTS_ELSE_PRIVATE
Definition: common.hpp:41
uint64_t FaceId
identifies a face
Definition: face.hpp:39
represents a Data packet
Definition: data.hpp:37
represents a Network NACK header
Definition: nack-header.hpp:52
NameTree & getNameTree()
Definition: forwarder.hpp:131
void setUnsolicitedDataPolicy(unique_ptr< fw::UnsolicitedDataPolicy > policy)
Definition: forwarder.hpp:102
Face * getFace(FaceId id) const
get existing Face
Definition: forwarder.hpp:80