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 namespace nfd {
43 
44 namespace fw {
45 class Strategy;
46 } // namespace fw
47 
52 class Forwarder
53 {
54 public:
55  Forwarder();
56 
58  ~Forwarder();
59 
60  const ForwarderCounters&
61  getCounters() const
62  {
63  return m_counters;
64  }
65 
66 public: // faces and policies
67  FaceTable&
69  {
70  return m_faceTable;
71  }
72 
77  Face*
78  getFace(FaceId id) const
79  {
80  return m_faceTable.get(id);
81  }
82 
87  void
88  addFace(shared_ptr<Face> face)
89  {
90  m_faceTable.add(face);
91  }
92 
95  {
96  return *m_unsolicitedDataPolicy;
97  }
98 
99  void
100  setUnsolicitedDataPolicy(unique_ptr<fw::UnsolicitedDataPolicy> policy)
101  {
102  BOOST_ASSERT(policy != nullptr);
103  m_unsolicitedDataPolicy = std::move(policy);
104  }
105 
106 public: // forwarding entrypoints and tables
111  void
112  startProcessInterest(Face& face, const Interest& interest);
113 
118  void
119  startProcessData(Face& face, const Data& data);
120 
125  void
126  startProcessNack(Face& face, const lp::Nack& nack);
127 
128  NameTree&
130  {
131  return m_nameTree;
132  }
133 
134  Fib&
136  {
137  return m_fib;
138  }
139 
140  Pit&
142  {
143  return m_pit;
144  }
145 
146  Cs&
148  {
149  return m_cs;
150  }
151 
152  Measurements&
154  {
155  return m_measurements;
156  }
157 
158  StrategyChoice&
160  {
161  return m_strategyChoice;
162  }
163 
166  {
167  return m_deadNonceList;
168  }
169 
172  {
173  return m_networkRegionTable;
174  }
175 
176 PUBLIC_WITH_TESTS_ELSE_PRIVATE: // pipelines
179  VIRTUAL_WITH_TESTS void
180  onIncomingInterest(Face& inFace, const Interest& interest);
181 
184  VIRTUAL_WITH_TESTS void
185  onInterestLoop(Face& inFace, const Interest& interest);
186 
189  VIRTUAL_WITH_TESTS void
190  onContentStoreMiss(const Face& inFace, const shared_ptr<pit::Entry>& pitEntry, const Interest& interest);
191 
194  VIRTUAL_WITH_TESTS void
195  onContentStoreHit(const Face& inFace, const shared_ptr<pit::Entry>& pitEntry,
196  const Interest& interest, const Data& data);
197 
200  VIRTUAL_WITH_TESTS void
201  onOutgoingInterest(const shared_ptr<pit::Entry>& pitEntry, Face& outFace, const Interest& interest);
202 
205  VIRTUAL_WITH_TESTS void
206  onInterestReject(const shared_ptr<pit::Entry>& pitEntry);
207 
210  VIRTUAL_WITH_TESTS void
211  onInterestUnsatisfied(const shared_ptr<pit::Entry>& pitEntry);
212 
217  VIRTUAL_WITH_TESTS void
218  onInterestFinalize(const shared_ptr<pit::Entry>& pitEntry, bool isSatisfied,
219  time::milliseconds dataFreshnessPeriod = time::milliseconds(-1));
220 
223  VIRTUAL_WITH_TESTS void
224  onIncomingData(Face& inFace, const Data& data);
225 
228  VIRTUAL_WITH_TESTS void
229  onDataUnsolicited(Face& inFace, const Data& data);
230 
233  VIRTUAL_WITH_TESTS void
234  onOutgoingData(const Data& data, Face& outFace);
235 
238  VIRTUAL_WITH_TESTS void
239  onIncomingNack(Face& inFace, const lp::Nack& nack);
240 
243  VIRTUAL_WITH_TESTS void
244  onOutgoingNack(const shared_ptr<pit::Entry>& pitEntry, const Face& outFace, const lp::NackHeader& nack);
245 
247  VIRTUAL_WITH_TESTS void
248  setUnsatisfyTimer(const shared_ptr<pit::Entry>& pitEntry);
249 
250  VIRTUAL_WITH_TESTS void
251  setStragglerTimer(const shared_ptr<pit::Entry>& pitEntry, bool isSatisfied,
252  time::milliseconds dataFreshnessPeriod = time::milliseconds(-1));
253 
254  VIRTUAL_WITH_TESTS void
255  cancelUnsatisfyAndStragglerTimer(pit::Entry& pitEntry);
256 
261  VIRTUAL_WITH_TESTS void
262  insertDeadNonceList(pit::Entry& pitEntry, bool isSatisfied,
263  time::milliseconds dataFreshnessPeriod, Face* upstream);
264 
267 #ifdef WITH_TESTS
268  virtual void
269  dispatchToStrategy(pit::Entry& pitEntry, function<void(fw::Strategy&)> trigger)
270 #else
271  template<class Function>
272  void
273  dispatchToStrategy(pit::Entry& pitEntry, Function trigger)
274 #endif
275  {
276  trigger(m_strategyChoice.findEffectiveStrategy(pitEntry));
277  }
278 
279 private:
280  ForwarderCounters m_counters;
281 
282  FaceTable m_faceTable;
283  unique_ptr<fw::UnsolicitedDataPolicy> m_unsolicitedDataPolicy;
284 
285  NameTree m_nameTree;
286  Fib m_fib;
287  Pit m_pit;
288  Cs m_cs;
289  Measurements m_measurements;
290  StrategyChoice m_strategyChoice;
291  DeadNonceList m_deadNonceList;
292  NetworkRegionTable m_networkRegionTable;
293 
294  // allow Strategy (base class) to enter pipelines
295  friend class fw::Strategy;
296 };
297 
298 } // namespace nfd
299 
300 #endif // NFD_DAEMON_FW_FORWARDER_HPP
main class of NFD
Definition: forwarder.hpp:52
Copyright (c) 2014-2016, Regents of the University of California, Arizona Board of Regents...
Fib & getFib()
Definition: forwarder.hpp:135
StrategyChoice & getStrategyChoice()
Definition: forwarder.hpp:159
container of all faces
Definition: face-table.hpp:37
Face * get(FaceId id) const
get face by FaceId
Definition: face-table.cpp:45
#define PROTECTED_WITH_TESTS_ELSE_PRIVATE
Definition: common.hpp:41
DeadNonceList & getDeadNonceList()
Definition: forwarder.hpp:165
an Interest table entry
Definition: pit-entry.hpp:57
void add(shared_ptr< Face > face)
add a face
Definition: face-table.cpp:61
Copyright (c) 2014-2015, Regents of the University of California, Arizona Board of Regents...
Pit & getPit()
Definition: forwarder.hpp:141
stores a collection of producer region names
void startProcessInterest(Face &face, const Interest &interest)
start incoming Interest processing
Definition: forwarder.cpp:76
represents the Dead Nonce list
void setUnsolicitedDataPolicy(unique_ptr< fw::UnsolicitedDataPolicy > policy)
Definition: forwarder.hpp:100
determines how to process an unsolicited Data
NameTree & getNameTree()
Definition: forwarder.hpp:129
FaceTable & getFaceTable()
Definition: forwarder.hpp:68
void addFace(shared_ptr< Face > face)
add new Face
Definition: forwarder.hpp:88
counters provided by Forwarder
represents a forwarding strategy
Definition: strategy.hpp:37
#define VIRTUAL_WITH_TESTS
Copyright (c) 2014-2016, Regents of the University of California, Arizona Board of Regents...
Definition: common.hpp:38
#define PUBLIC_WITH_TESTS_ELSE_PRIVATE
Definition: common.hpp:40
const ForwarderCounters & getCounters() const
Definition: forwarder.hpp:61
fw::UnsolicitedDataPolicy & getUnsolicitedDataPolicy() const
Definition: forwarder.hpp:94
uint64_t FaceId
identifies a face
Definition: face.hpp:39
void startProcessData(Face &face, const Data &data)
start incoming Data processing
Definition: forwarder.cpp:95
Measurements & getMeasurements()
Definition: forwarder.hpp:153
NetworkRegionTable & getNetworkRegionTable()
Definition: forwarder.hpp:171
Face * getFace(FaceId id) const
get existing Face
Definition: forwarder.hpp:78
void startProcessNack(Face &face, const lp::Nack &nack)
start incoming Nack processing
Definition: forwarder.cpp:104