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,
191  const Interest& interest);
192 
195  VIRTUAL_WITH_TESTS void
196  onContentStoreHit(const Face& inFace, const shared_ptr<pit::Entry>& pitEntry,
197  const Interest& interest, const Data& data);
198 
201  VIRTUAL_WITH_TESTS void
202  onOutgoingInterest(const shared_ptr<pit::Entry>& pitEntry, Face& outFace,
203  bool wantNewNonce = false);
204 
207  VIRTUAL_WITH_TESTS void
208  onInterestReject(const shared_ptr<pit::Entry>& pitEntry);
209 
212  VIRTUAL_WITH_TESTS void
213  onInterestUnsatisfied(const shared_ptr<pit::Entry>& pitEntry);
214 
219  VIRTUAL_WITH_TESTS void
220  onInterestFinalize(const shared_ptr<pit::Entry>& pitEntry, bool isSatisfied,
221  time::milliseconds dataFreshnessPeriod = time::milliseconds(-1));
222 
225  VIRTUAL_WITH_TESTS void
226  onIncomingData(Face& inFace, const Data& data);
227 
230  VIRTUAL_WITH_TESTS void
231  onDataUnsolicited(Face& inFace, const Data& data);
232 
235  VIRTUAL_WITH_TESTS void
236  onOutgoingData(const Data& data, Face& outFace);
237 
240  VIRTUAL_WITH_TESTS void
241  onIncomingNack(Face& inFace, const lp::Nack& nack);
242 
245  VIRTUAL_WITH_TESTS void
246  onOutgoingNack(const shared_ptr<pit::Entry>& pitEntry, const Face& outFace, const lp::NackHeader& nack);
247 
249  VIRTUAL_WITH_TESTS void
250  setUnsatisfyTimer(const shared_ptr<pit::Entry>& pitEntry);
251 
252  VIRTUAL_WITH_TESTS void
253  setStragglerTimer(const shared_ptr<pit::Entry>& pitEntry, bool isSatisfied,
254  time::milliseconds dataFreshnessPeriod = time::milliseconds(-1));
255 
256  VIRTUAL_WITH_TESTS void
257  cancelUnsatisfyAndStragglerTimer(pit::Entry& pitEntry);
258 
263  VIRTUAL_WITH_TESTS void
264  insertDeadNonceList(pit::Entry& pitEntry, bool isSatisfied,
265  time::milliseconds dataFreshnessPeriod, Face* upstream);
266 
269 #ifdef WITH_TESTS
270  virtual void
271  dispatchToStrategy(pit::Entry& pitEntry, function<void(fw::Strategy&)> trigger)
272 #else
273  template<class Function>
274  void
275  dispatchToStrategy(pit::Entry& pitEntry, Function trigger)
276 #endif
277  {
278  trigger(m_strategyChoice.findEffectiveStrategy(pitEntry));
279  }
280 
281 private:
282  ForwarderCounters m_counters;
283 
284  FaceTable m_faceTable;
285  unique_ptr<fw::UnsolicitedDataPolicy> m_unsolicitedDataPolicy;
286 
287  NameTree m_nameTree;
288  Fib m_fib;
289  Pit m_pit;
290  Cs m_cs;
291  Measurements m_measurements;
292  StrategyChoice m_strategyChoice;
293  DeadNonceList m_deadNonceList;
294  NetworkRegionTable m_networkRegionTable;
295 
296  // allow Strategy (base class) to enter pipelines
297  friend class fw::Strategy;
298 };
299 
300 } // namespace nfd
301 
302 #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:42
#define PROTECTED_WITH_TESTS_ELSE_PRIVATE
Definition: common.hpp:40
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:58
Copyright (c) 2014-2015, Regents of the University of California, Arizona Board of Regents...
Definition: algorithm.hpp:32
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:71
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:38
#define VIRTUAL_WITH_TESTS
Copyright (c) 2014-2016, Regents of the University of California, Arizona Board of Regents...
Definition: common.hpp:37
#define PUBLIC_WITH_TESTS_ELSE_PRIVATE
Definition: common.hpp:39
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:90
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:99