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"
39 
40 #include "ns3/ndnSIM/model/cs/ndn-content-store.hpp"
41 
42 namespace nfd {
43 
44 namespace fw {
45 class Strategy;
46 } // namespace fw
47 
48 class NullFace;
49 
54 class Forwarder
55 {
56 public:
57  Forwarder();
58 
60  ~Forwarder();
61 
62  const ForwarderCounters&
63  getCounters() const;
64 
65 public: // faces
66  FaceTable&
67  getFaceTable();
68 
73  shared_ptr<Face>
74  getFace(FaceId id) const;
75 
80  void
81  addFace(shared_ptr<Face> face);
82 
83 public: // forwarding entrypoints and tables
84  void
85  onInterest(Face& face, const Interest& interest);
86 
87  void
88  onData(Face& face, const Data& data);
89 
90  NameTree&
91  getNameTree();
92 
93  Fib&
94  getFib();
95 
96  Pit&
97  getPit();
98 
99  Cs&
100  getCs();
101 
102  Measurements&
103  getMeasurements();
104 
106  getStrategyChoice();
107 
109  getDeadNonceList();
110 
111 public: // allow enabling ndnSIM content store (will be removed in the future)
112  void
113  setCsFromNdnSim(ns3::Ptr<ns3::ndn::ContentStore> cs);
114 
115 public:
120 
125 
126 PUBLIC_WITH_TESTS_ELSE_PRIVATE: // pipelines
129  VIRTUAL_WITH_TESTS void
130  onIncomingInterest(Face& inFace, const Interest& interest);
131 
134  void
135  onContentStoreMiss(const Face& inFace, shared_ptr<pit::Entry> pitEntry, const Interest& interest);
136 
139  void
140  onContentStoreHit(const Face& inFace, shared_ptr<pit::Entry> pitEntry,
141  const Interest& interest, const Data& data);
142 
145  VIRTUAL_WITH_TESTS void
146  onInterestLoop(Face& inFace, const Interest& interest,
147  shared_ptr<pit::Entry> pitEntry);
148 
151  VIRTUAL_WITH_TESTS void
152  onOutgoingInterest(shared_ptr<pit::Entry> pitEntry, Face& outFace,
153  bool wantNewNonce = false);
154 
157  VIRTUAL_WITH_TESTS void
158  onInterestReject(shared_ptr<pit::Entry> pitEntry);
159 
162  VIRTUAL_WITH_TESTS void
163  onInterestUnsatisfied(shared_ptr<pit::Entry> pitEntry);
164 
169  VIRTUAL_WITH_TESTS void
170  onInterestFinalize(shared_ptr<pit::Entry> pitEntry, bool isSatisfied,
171  const time::milliseconds& dataFreshnessPeriod = time::milliseconds(-1));
172 
175  VIRTUAL_WITH_TESTS void
176  onIncomingData(Face& inFace, const Data& data);
177 
180  VIRTUAL_WITH_TESTS void
181  onDataUnsolicited(Face& inFace, const Data& data);
182 
185  VIRTUAL_WITH_TESTS void
186  onOutgoingData(const Data& data, Face& outFace);
187 
189  VIRTUAL_WITH_TESTS void
190  setUnsatisfyTimer(shared_ptr<pit::Entry> pitEntry);
191 
192  VIRTUAL_WITH_TESTS void
193  setStragglerTimer(shared_ptr<pit::Entry> pitEntry, bool isSatisfied,
194  const time::milliseconds& dataFreshnessPeriod = time::milliseconds(-1));
195 
196  VIRTUAL_WITH_TESTS void
197  cancelUnsatisfyAndStragglerTimer(shared_ptr<pit::Entry> pitEntry);
198 
203  VIRTUAL_WITH_TESTS void
204  insertDeadNonceList(pit::Entry& pitEntry, bool isSatisfied,
205  const time::milliseconds& dataFreshnessPeriod,
206  Face* upstream);
207 
209 #ifdef WITH_TESTS
210  virtual void
211  dispatchToStrategy(shared_ptr<pit::Entry> pitEntry, function<void(fw::Strategy*)> trigger);
212 #else
213  template<class Function>
214  void
215  dispatchToStrategy(shared_ptr<pit::Entry> pitEntry, Function trigger);
216 #endif
217 
218 private:
219  ForwarderCounters m_counters;
220 
221  FaceTable m_faceTable;
222 
223  // tables
224  NameTree m_nameTree;
225  Fib m_fib;
226  Pit m_pit;
227  Cs m_cs;
228  Measurements m_measurements;
229  StrategyChoice m_strategyChoice;
230  DeadNonceList m_deadNonceList;
231  shared_ptr<NullFace> m_csFace;
232 
233  ns3::Ptr<ns3::ndn::ContentStore> m_csFromNdnSim;
234 
235  static const Name LOCALHOST_NAME;
236 
237  // allow Strategy (base class) to enter pipelines
238  friend class fw::Strategy;
239 };
240 
241 inline const ForwarderCounters&
243 {
244  return m_counters;
245 }
246 
247 inline FaceTable&
249 {
250  return m_faceTable;
251 }
252 
253 inline shared_ptr<Face>
255 {
256  return m_faceTable.get(id);
257 }
258 
259 inline void
260 Forwarder::addFace(shared_ptr<Face> face)
261 {
262  m_faceTable.add(face);
263 }
264 
265 inline void
266 Forwarder::onInterest(Face& face, const Interest& interest)
267 {
268  this->onIncomingInterest(face, interest);
269 }
270 
271 inline void
272 Forwarder::onData(Face& face, const Data& data)
273 {
274  this->onIncomingData(face, data);
275 }
276 
277 inline NameTree&
279 {
280  return m_nameTree;
281 }
282 
283 inline Fib&
285 {
286  return m_fib;
287 }
288 
289 inline Pit&
291 {
292  return m_pit;
293 }
294 
295 inline Cs&
297 {
298  return m_cs;
299 }
300 
301 inline Measurements&
303 {
304  return m_measurements;
305 }
306 
307 inline StrategyChoice&
309 {
310  return m_strategyChoice;
311 }
312 
313 inline DeadNonceList&
315 {
316  return m_deadNonceList;
317 }
318 
319 inline void
320 Forwarder::setCsFromNdnSim(ns3::Ptr<ns3::ndn::ContentStore> cs)
321 {
322  m_csFromNdnSim = cs;
323 }
324 
325 #ifdef WITH_TESTS
326 inline void
327 Forwarder::dispatchToStrategy(shared_ptr<pit::Entry> pitEntry, function<void(fw::Strategy*)> trigger)
328 #else
329 template<class Function>
330 inline void
331 Forwarder::dispatchToStrategy(shared_ptr<pit::Entry> pitEntry, Function trigger)
332 #endif
333 {
334  fw::Strategy& strategy = m_strategyChoice.findEffectiveStrategy(*pitEntry);
335  trigger(&strategy);
336 }
337 
338 } // namespace nfd
339 
340 #endif // NFD_DAEMON_FW_FORWARDER_HPP
signal::Signal< Forwarder, pit::Entry, Face, Data > beforeSatisfyInterest
trigger before PIT entry is satisfied
Definition: forwarder.hpp:119
represents the Dead Nonce list
represents the Strategy Choice table
contains counters on forwarder
StrategyChoice & getStrategyChoice()
Definition: forwarder.hpp:308
Copyright (c) 2014-2015, Regents of the University of California, Arizona Board of Regents...
FaceTable & getFaceTable()
Definition: forwarder.hpp:248
void addFace(shared_ptr< Face > face)
add new Face
Definition: forwarder.hpp:260
main class of NFD
Definition: forwarder.hpp:54
represents the FIB
Definition: fib.hpp:44
DeadNonceList & getDeadNonceList()
Definition: forwarder.hpp:314
represents an Interest packet
Definition: interest.hpp:45
#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 face
Definition: face.hpp:57
const ForwarderCounters & getCounters() const
Definition: forwarder.hpp:242
container of all Faces
Definition: face-table.hpp:38
Copyright (c) 2011-2015 Regents of the University of California.
Definition: ndn-common.hpp:38
represents a PIT entry
Definition: pit-entry.hpp:67
void onData(Face &face, const Data &data)
Definition: forwarder.hpp:272
signal::Signal< Forwarder, pit::Entry > beforeExpirePendingInterest
trigger before PIT entry expires
Definition: forwarder.hpp:124
#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:302
identifies a face
Fib & getFib()
Definition: forwarder.hpp:284
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:254
represents a forwarding strategy
Definition: strategy.hpp:38
void setCsFromNdnSim(ns3::Ptr< ns3::ndn::ContentStore > cs)
Definition: forwarder.hpp:320
void onInterest(Face &face, const Interest &interest)
Definition: forwarder.hpp:266
#define PUBLIC_WITH_TESTS_ELSE_PRIVATE
Definition: common.hpp:39
represents a Data packet
Definition: data.hpp:39
NameTree & getNameTree()
Definition: forwarder.hpp:278
Pit & getPit()
Definition: forwarder.hpp:290