NS-3 based Named Data Networking (NDN) simulator
ndnSIM 2.0: 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 "common.hpp"
30 #include "core/scheduler.hpp"
31 #include "forwarder-counters.hpp"
32 #include "face-table.hpp"
33 #include "table/fib.hpp"
34 #include "table/pit.hpp"
35 #include "table/cs.hpp"
36 #include "table/measurements.hpp"
40 
41 #include "ns3/ndnSIM/model/cs/ndn-content-store.hpp"
42 
43 namespace nfd {
44 
45 namespace fw {
46 class Strategy;
47 } // namespace fw
48 
49 class NullFace;
50 
55 class Forwarder
56 {
57 public:
58  Forwarder();
59 
61  ~Forwarder();
62 
63  const ForwarderCounters&
64  getCounters() const;
65 
66 public: // faces
67  FaceTable&
68  getFaceTable();
69 
74  shared_ptr<Face>
75  getFace(FaceId id) const;
76 
81  void
82  addFace(shared_ptr<Face> face);
83 
84 public: // forwarding entrypoints and tables
89  void
90  startProcessInterest(Face& face, const Interest& interest);
91 
96  void
97  startProcessData(Face& face, const Data& data);
98 
103  void
104  startProcessNack(Face& face, const lp::Nack& nack);
105 
106  NameTree&
107  getNameTree();
108 
109  Fib&
110  getFib();
111 
112  Pit&
113  getPit();
114 
115  Cs&
116  getCs();
117 
118  Measurements&
119  getMeasurements();
120 
122  getStrategyChoice();
123 
125  getDeadNonceList();
126 
128  getNetworkRegionTable();
129 
130 public: // allow enabling ndnSIM content store (will be removed in the future)
131  void
132  setCsFromNdnSim(ns3::Ptr<ns3::ndn::ContentStore> cs);
133 
134 public:
139 
144 
145 PUBLIC_WITH_TESTS_ELSE_PRIVATE: // pipelines
148  VIRTUAL_WITH_TESTS void
149  onIncomingInterest(Face& inFace, const Interest& interest);
150 
153  VIRTUAL_WITH_TESTS void
154  onInterestLoop(Face& inFace, const Interest& interest);
155 
158  VIRTUAL_WITH_TESTS void
159  onContentStoreMiss(const Face& inFace, shared_ptr<pit::Entry> pitEntry, const Interest& interest);
160 
163  VIRTUAL_WITH_TESTS void
164  onContentStoreHit(const Face& inFace, shared_ptr<pit::Entry> pitEntry,
165  const Interest& interest, const Data& data);
166 
169  VIRTUAL_WITH_TESTS void
170  onOutgoingInterest(shared_ptr<pit::Entry> pitEntry, Face& outFace,
171  bool wantNewNonce = false);
172 
175  VIRTUAL_WITH_TESTS void
176  onInterestReject(shared_ptr<pit::Entry> pitEntry);
177 
180  VIRTUAL_WITH_TESTS void
181  onInterestUnsatisfied(shared_ptr<pit::Entry> pitEntry);
182 
187  VIRTUAL_WITH_TESTS void
188  onInterestFinalize(shared_ptr<pit::Entry> pitEntry, bool isSatisfied,
189  const time::milliseconds& dataFreshnessPeriod = time::milliseconds(-1));
190 
193  VIRTUAL_WITH_TESTS void
194  onIncomingData(Face& inFace, const Data& data);
195 
198  VIRTUAL_WITH_TESTS void
199  onDataUnsolicited(Face& inFace, const Data& data);
200 
203  VIRTUAL_WITH_TESTS void
204  onOutgoingData(const Data& data, Face& outFace);
205 
208  VIRTUAL_WITH_TESTS void
209  onIncomingNack(Face& inFace, const lp::Nack& nack);
210 
213  VIRTUAL_WITH_TESTS void
214  onOutgoingNack(shared_ptr<pit::Entry> pitEntry, const Face& outFace, const lp::NackHeader& nack);
215 
217  VIRTUAL_WITH_TESTS void
218  setUnsatisfyTimer(shared_ptr<pit::Entry> pitEntry);
219 
220  VIRTUAL_WITH_TESTS void
221  setStragglerTimer(shared_ptr<pit::Entry> pitEntry, bool isSatisfied,
222  const time::milliseconds& dataFreshnessPeriod = time::milliseconds(-1));
223 
224  VIRTUAL_WITH_TESTS void
225  cancelUnsatisfyAndStragglerTimer(shared_ptr<pit::Entry> pitEntry);
226 
231  VIRTUAL_WITH_TESTS void
232  insertDeadNonceList(pit::Entry& pitEntry, bool isSatisfied,
233  const time::milliseconds& dataFreshnessPeriod,
234  Face* upstream);
235 
237 #ifdef WITH_TESTS
238  virtual void
239  dispatchToStrategy(shared_ptr<pit::Entry> pitEntry, function<void(fw::Strategy*)> trigger);
240 #else
241  template<class Function>
242  void
243  dispatchToStrategy(shared_ptr<pit::Entry> pitEntry, Function trigger);
244 #endif
245 
246 private:
247  ForwarderCounters m_counters;
248 
249  FaceTable m_faceTable;
250 
251  // tables
252  NameTree m_nameTree;
253  Fib m_fib;
254  Pit m_pit;
255  Cs m_cs;
256  Measurements m_measurements;
257  StrategyChoice m_strategyChoice;
258  DeadNonceList m_deadNonceList;
259  NetworkRegionTable m_networkRegionTable;
260  shared_ptr<Face> m_csFace;
261 
262  ns3::Ptr<ns3::ndn::ContentStore> m_csFromNdnSim;
263 
264  static const Name LOCALHOST_NAME;
265 
266  // allow Strategy (base class) to enter pipelines
267  friend class fw::Strategy;
268 };
269 
270 inline const ForwarderCounters&
272 {
273  return m_counters;
274 }
275 
276 inline FaceTable&
278 {
279  return m_faceTable;
280 }
281 
282 inline shared_ptr<Face>
284 {
285  return m_faceTable.get(id);
286 }
287 
288 inline void
289 Forwarder::addFace(shared_ptr<Face> face)
290 {
291  m_faceTable.add(face);
292 }
293 
294 inline NameTree&
296 {
297  return m_nameTree;
298 }
299 
300 inline Fib&
302 {
303  return m_fib;
304 }
305 
306 inline Pit&
308 {
309  return m_pit;
310 }
311 
312 inline Cs&
314 {
315  return m_cs;
316 }
317 
318 inline Measurements&
320 {
321  return m_measurements;
322 }
323 
324 inline StrategyChoice&
326 {
327  return m_strategyChoice;
328 }
329 
330 inline DeadNonceList&
332 {
333  return m_deadNonceList;
334 }
335 
336 inline NetworkRegionTable&
338 {
339  return m_networkRegionTable;
340 }
341 
342 inline void
343 Forwarder::setCsFromNdnSim(ns3::Ptr<ns3::ndn::ContentStore> cs)
344 {
345  m_csFromNdnSim = cs;
346 }
347 
348 #ifdef WITH_TESTS
349 inline void
350 Forwarder::dispatchToStrategy(shared_ptr<pit::Entry> pitEntry, function<void(fw::Strategy*)> trigger)
351 #else
352 template<class Function>
353 inline void
354 Forwarder::dispatchToStrategy(shared_ptr<pit::Entry> pitEntry, Function trigger)
355 #endif
356 {
357  fw::Strategy& strategy = m_strategyChoice.findEffectiveStrategy(*pitEntry);
358  trigger(&strategy);
359 }
360 
361 } // namespace nfd
362 
363 #endif // NFD_DAEMON_FW_FORWARDER_HPP
signal::Signal< Forwarder, pit::Entry, Face, Data > beforeSatisfyInterest
trigger before PIT entry is satisfied
Definition: forwarder.hpp:138
represents the Dead Nonce list
represents the Strategy Choice table
counters provided by Forwarder
StrategyChoice & getStrategyChoice()
Definition: forwarder.hpp:325
Copyright (c) 2014-2016, Regents of the University of California, Arizona Board of Regents...
FaceTable & getFaceTable()
Definition: forwarder.hpp:277
void addFace(shared_ptr< Face > face)
add new Face
Definition: forwarder.hpp:289
main class of NFD
Definition: forwarder.hpp:55
represents the FIB
Definition: fib.hpp:44
DeadNonceList & getDeadNonceList()
Definition: forwarder.hpp:331
represents an Interest packet
Definition: interest.hpp:45
stores a collection of producer region names
#define PROTECTED_WITH_TESTS_ELSE_PRIVATE
Definition: common.hpp:40
represents the Measurements table
provides a lightweight signal / event system
represents the Interest Table
Definition: pit.hpp:48
represents a Network Nack
Definition: nack.hpp:40
container of all Faces
Definition: face-table.hpp:38
Copyright (c) 2011-2015 Regents of the University of California.
Definition: ndn-common.hpp:40
represents a PIT entry
Definition: pit-entry.hpp:69
signal::Signal< Forwarder, pit::Entry > beforeExpirePendingInterest
trigger before PIT entry expires
Definition: forwarder.hpp:143
#define VIRTUAL_WITH_TESTS
Copyright (c) 2014-2015, Regents of the University of California, Arizona Board of Regents...
Definition: common.hpp:37
Class Name Tree.
Definition: name-tree.hpp:79
Measurements & getMeasurements()
Definition: forwarder.hpp:319
Fib & getFib()
Definition: forwarder.hpp:301
Name abstraction to represent an absolute name.
Definition: name.hpp:46
Forwarder
Definition: forwarder.cpp:38
shared_ptr< Face > getFace(FaceId id) const
get existing Face
Definition: forwarder.hpp:283
represents the ContentStore
Definition: cs.hpp:65
represents a forwarding strategy
Definition: strategy.hpp:38
void setCsFromNdnSim(ns3::Ptr< ns3::ndn::ContentStore > cs)
Definition: forwarder.hpp:343
NetworkRegionTable & getNetworkRegionTable()
Definition: forwarder.hpp:337
const ForwarderCounters & getCounters() const
Definition: forwarder.hpp:271
#define PUBLIC_WITH_TESTS_ELSE_PRIVATE
Definition: common.hpp:39
uint64_t FaceId
identifies a face
Definition: face.hpp:39
represents a Data packet
Definition: data.hpp:39
represents a Network NACK header
Definition: nack-header.hpp:52
NameTree & getNameTree()
Definition: forwarder.hpp:295
Pit & getPit()
Definition: forwarder.hpp:307