NS-3 based Named Data Networking (NDN) simulator
ndnSIM 2.0: NDN, CCN, CCNx, content centric networks
API Documentation
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
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 
107 
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:
119  signal::Signal<Forwarder, pit::Entry, Face, Data> beforeSatisfyInterest;
120 
124  signal::Signal<Forwarder, pit::Entry> beforeExpirePendingInterest;
125 
126 PUBLIC_WITH_TESTS_ELSE_PRIVATE: // pipelines
129  VIRTUAL_WITH_TESTS void
130  onIncomingInterest(Face& inFace, const Interest& interest);
131 
134  VIRTUAL_WITH_TESTS void
135  onInterestLoop(Face& inFace, const Interest& interest,
136  shared_ptr<pit::Entry> pitEntry);
137 
140  VIRTUAL_WITH_TESTS void
141  onOutgoingInterest(shared_ptr<pit::Entry> pitEntry, Face& outFace,
142  bool wantNewNonce = false);
143 
146  VIRTUAL_WITH_TESTS void
147  onInterestReject(shared_ptr<pit::Entry> pitEntry);
148 
151  VIRTUAL_WITH_TESTS void
152  onInterestUnsatisfied(shared_ptr<pit::Entry> pitEntry);
153 
158  VIRTUAL_WITH_TESTS void
159  onInterestFinalize(shared_ptr<pit::Entry> pitEntry, bool isSatisfied,
160  const time::milliseconds& dataFreshnessPeriod = time::milliseconds(-1));
161 
164  VIRTUAL_WITH_TESTS void
165  onIncomingData(Face& inFace, const Data& data);
166 
169  VIRTUAL_WITH_TESTS void
170  onDataUnsolicited(Face& inFace, const Data& data);
171 
174  VIRTUAL_WITH_TESTS void
175  onOutgoingData(const Data& data, Face& outFace);
176 
178  VIRTUAL_WITH_TESTS void
179  setUnsatisfyTimer(shared_ptr<pit::Entry> pitEntry);
180 
181  VIRTUAL_WITH_TESTS void
182  setStragglerTimer(shared_ptr<pit::Entry> pitEntry, bool isSatisfied,
183  const time::milliseconds& dataFreshnessPeriod = time::milliseconds(-1));
184 
185  VIRTUAL_WITH_TESTS void
186  cancelUnsatisfyAndStragglerTimer(shared_ptr<pit::Entry> pitEntry);
187 
192  VIRTUAL_WITH_TESTS void
193  insertDeadNonceList(pit::Entry& pitEntry, bool isSatisfied,
194  const time::milliseconds& dataFreshnessPeriod,
195  Face* upstream);
196 
198 #ifdef WITH_TESTS
199  virtual void
200  dispatchToStrategy(shared_ptr<pit::Entry> pitEntry, function<void(fw::Strategy*)> trigger);
201 #else
202  template<class Function>
203  void
204  dispatchToStrategy(shared_ptr<pit::Entry> pitEntry, Function trigger);
205 #endif
206 
207 private:
208  ForwarderCounters m_counters;
209 
210  FaceTable m_faceTable;
211 
212  // tables
213  NameTree m_nameTree;
214  Fib m_fib;
215  Pit m_pit;
216  Cs m_cs;
217  Measurements m_measurements;
218  StrategyChoice m_strategyChoice;
219  DeadNonceList m_deadNonceList;
220  shared_ptr<NullFace> m_csFace;
221 
222  ns3::Ptr<ns3::ndn::ContentStore> m_csFromNdnSim;
223 
224  static const Name LOCALHOST_NAME;
225 
226  // allow Strategy (base class) to enter pipelines
227  friend class fw::Strategy;
228 };
229 
230 inline const ForwarderCounters&
232 {
233  return m_counters;
234 }
235 
236 inline FaceTable&
238 {
239  return m_faceTable;
240 }
241 
242 inline shared_ptr<Face>
244 {
245  return m_faceTable.get(id);
246 }
247 
248 inline void
249 Forwarder::addFace(shared_ptr<Face> face)
250 {
251  m_faceTable.add(face);
252 }
253 
254 inline void
255 Forwarder::onInterest(Face& face, const Interest& interest)
256 {
257  this->onIncomingInterest(face, interest);
258 }
259 
260 inline void
261 Forwarder::onData(Face& face, const Data& data)
262 {
263  this->onIncomingData(face, data);
264 }
265 
266 inline NameTree&
268 {
269  return m_nameTree;
270 }
271 
272 inline Fib&
274 {
275  return m_fib;
276 }
277 
278 inline Pit&
280 {
281  return m_pit;
282 }
283 
284 inline Cs&
286 {
287  return m_cs;
288 }
289 
290 inline Measurements&
292 {
293  return m_measurements;
294 }
295 
296 inline StrategyChoice&
298 {
299  return m_strategyChoice;
300 }
301 
302 inline DeadNonceList&
304 {
305  return m_deadNonceList;
306 }
307 
308 inline void
309 Forwarder::setCsFromNdnSim(ns3::Ptr<ns3::ndn::ContentStore> cs)
310 {
311  m_csFromNdnSim = cs;
312 }
313 
314 #ifdef WITH_TESTS
315 inline void
316 Forwarder::dispatchToStrategy(shared_ptr<pit::Entry> pitEntry, function<void(fw::Strategy*)> trigger)
317 #else
318 template<class Function>
319 inline void
320 Forwarder::dispatchToStrategy(shared_ptr<pit::Entry> pitEntry, Function trigger)
321 #endif
322 {
323  fw::Strategy& strategy = m_strategyChoice.findEffectiveStrategy(*pitEntry);
324  trigger(&strategy);
325 }
326 
327 } // namespace nfd
328 
329 #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:297
FaceTable & getFaceTable()
Definition: forwarder.hpp:237
void addFace(shared_ptr< Face > face)
add new Face
Definition: forwarder.hpp:249
void add(shared_ptr< Face > face)
Definition: face-table.cpp:59
main class of NFD
Definition: forwarder.hpp:54
represents the FIB
Definition: fib.hpp:44
DeadNonceList & getDeadNonceList()
Definition: forwarder.hpp:303
represents the Interest Table
Definition: pit.hpp:48
represents a face
Definition: face.hpp:59
#define PROTECTED_WITH_TESTS_ELSE_PRIVATE
Definition: common.hpp:40
const ForwarderCounters & getCounters() const
Definition: forwarder.hpp:231
container of all Faces
Definition: face-table.hpp:38
represents a PIT entry
Definition: pit-entry.hpp:67
void onData(Face &face, const Data &data)
Definition: forwarder.hpp:261
signal::Signal< Forwarder, pit::Entry > beforeExpirePendingInterest
trigger before PIT entry expires
Definition: forwarder.hpp:124
Class Name Tree.
Definition: name-tree.hpp:79
Measurements & getMeasurements()
Definition: forwarder.hpp:291
identifies a face
Fib & getFib()
Definition: forwarder.hpp:273
represents Content Store
Definition: cs.hpp:111
shared_ptr< Face > getFace(FaceId id) const
get existing Face
Definition: forwarder.hpp:243
represents a forwarding strategy
Definition: strategy.hpp:37
void setCsFromNdnSim(ns3::Ptr< ns3::ndn::ContentStore > cs)
Definition: forwarder.hpp:309
#define VIRTUAL_WITH_TESTS
Copyright (c) 2014, Regents of the University of California, Arizona Board of Regents, Colorado State University, University Pierre & Marie Curie, Sorbonne University, Washington University in St.
Definition: common.hpp:37
void onInterest(Face &face, const Interest &interest)
Definition: forwarder.hpp:255
#define PUBLIC_WITH_TESTS_ELSE_PRIVATE
Definition: common.hpp:39
shared_ptr< Face > get(FaceId id) const
Definition: face-table.cpp:46
NameTree & getNameTree()
Definition: forwarder.hpp:267
Pit & getPit()
Definition: forwarder.hpp:279