forwarder.hpp
Go to the documentation of this file.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2 /*
3  * Copyright (c) 2014-2017, Regents of the University of California,
4  * Arizona Board of Regents,
5  * Colorado State University,
6  * University Pierre & Marie Curie, Sorbonne University,
7  * Washington University in St. Louis,
8  * Beijing Institute of Technology,
9  * The University of Memphis.
10  *
11  * This file is part of NFD (Named Data Networking Forwarding Daemon).
12  * See AUTHORS.md for complete list of NFD authors and contributors.
13  *
14  * NFD is free software: you can redistribute it and/or modify it under the terms
15  * of the GNU General Public License as published by the Free Software Foundation,
16  * either version 3 of the License, or (at your option) any later version.
17  *
18  * NFD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
19  * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
20  * PURPOSE. See the GNU General Public License for more details.
21  *
22  * You should have received a copy of the GNU General Public License along with
23  * NFD, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
24  */
25 
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  {
114  this->onIncomingInterest(face, interest);
115  }
116 
121  void
122  startProcessData(Face& face, const Data& data)
123  {
124  this->onIncomingData(face, data);
125  }
126 
131  void
132  startProcessNack(Face& face, const lp::Nack& nack)
133  {
134  this->onIncomingNack(face, nack);
135  }
136 
137  NameTree&
139  {
140  return m_nameTree;
141  }
142 
143  Fib&
145  {
146  return m_fib;
147  }
148 
149  Pit&
151  {
152  return m_pit;
153  }
154 
155  Cs&
157  {
158  return m_cs;
159  }
160 
161  Measurements&
163  {
164  return m_measurements;
165  }
166 
167  StrategyChoice&
169  {
170  return m_strategyChoice;
171  }
172 
175  {
176  return m_deadNonceList;
177  }
178 
181  {
182  return m_networkRegionTable;
183  }
184 
185 PUBLIC_WITH_TESTS_ELSE_PRIVATE: // pipelines
188  VIRTUAL_WITH_TESTS void
189  onIncomingInterest(Face& inFace, const Interest& interest);
190 
193  VIRTUAL_WITH_TESTS void
194  onInterestLoop(Face& inFace, const Interest& interest);
195 
198  VIRTUAL_WITH_TESTS void
199  onContentStoreMiss(const Face& inFace, const shared_ptr<pit::Entry>& pitEntry, const Interest& interest);
200 
203  VIRTUAL_WITH_TESTS void
204  onContentStoreHit(const Face& inFace, const shared_ptr<pit::Entry>& pitEntry,
205  const Interest& interest, const Data& data);
206 
209  VIRTUAL_WITH_TESTS void
210  onOutgoingInterest(const shared_ptr<pit::Entry>& pitEntry, Face& outFace, const Interest& interest);
211 
214  VIRTUAL_WITH_TESTS void
215  onInterestReject(const shared_ptr<pit::Entry>& pitEntry);
216 
219  VIRTUAL_WITH_TESTS void
220  onInterestUnsatisfied(const shared_ptr<pit::Entry>& pitEntry);
221 
226  VIRTUAL_WITH_TESTS void
227  onInterestFinalize(const shared_ptr<pit::Entry>& pitEntry, bool isSatisfied,
228  ndn::optional<time::milliseconds> dataFreshnessPeriod = ndn::nullopt);
229 
232  VIRTUAL_WITH_TESTS void
233  onIncomingData(Face& inFace, const Data& data);
234 
237  VIRTUAL_WITH_TESTS void
238  onDataUnsolicited(Face& inFace, const Data& data);
239 
242  VIRTUAL_WITH_TESTS void
243  onOutgoingData(const Data& data, Face& outFace);
244 
247  VIRTUAL_WITH_TESTS void
248  onIncomingNack(Face& inFace, const lp::Nack& nack);
249 
252  VIRTUAL_WITH_TESTS void
253  onOutgoingNack(const shared_ptr<pit::Entry>& pitEntry, const Face& outFace, const lp::NackHeader& nack);
254 
256  VIRTUAL_WITH_TESTS void
257  setUnsatisfyTimer(const shared_ptr<pit::Entry>& pitEntry);
258 
259  VIRTUAL_WITH_TESTS void
260  setStragglerTimer(const shared_ptr<pit::Entry>& pitEntry, bool isSatisfied,
261  ndn::optional<time::milliseconds> dataFreshnessPeriod = ndn::nullopt);
262 
263  VIRTUAL_WITH_TESTS void
264  cancelUnsatisfyAndStragglerTimer(pit::Entry& pitEntry);
265 
270  VIRTUAL_WITH_TESTS void
271  insertDeadNonceList(pit::Entry& pitEntry, bool isSatisfied,
272  ndn::optional<time::milliseconds> dataFreshnessPeriod, Face* upstream);
273 
276 #ifdef WITH_TESTS
277  virtual void
278  dispatchToStrategy(pit::Entry& pitEntry, function<void(fw::Strategy&)> trigger)
279 #else
280  template<class Function>
281  void
282  dispatchToStrategy(pit::Entry& pitEntry, Function trigger)
283 #endif
284  {
285  trigger(m_strategyChoice.findEffectiveStrategy(pitEntry));
286  }
287 
288 private:
289  ForwarderCounters m_counters;
290 
291  FaceTable m_faceTable;
292  unique_ptr<fw::UnsolicitedDataPolicy> m_unsolicitedDataPolicy;
293 
294  NameTree m_nameTree;
295  Fib m_fib;
296  Pit m_pit;
297  Cs m_cs;
298  Measurements m_measurements;
299  StrategyChoice m_strategyChoice;
300  DeadNonceList m_deadNonceList;
301  NetworkRegionTable m_networkRegionTable;
302 
303  // allow Strategy (base class) to enter pipelines
304  friend class fw::Strategy;
305 };
306 
307 } // namespace nfd
308 
309 #endif // NFD_DAEMON_FW_FORWARDER_HPP
main class of NFD
Definition: forwarder.hpp:52
implements the ContentStore
Fib & getFib()
Definition: forwarder.hpp:144
StrategyChoice & getStrategyChoice()
Definition: forwarder.hpp:168
container of all faces
Definition: face-table.hpp:37
#define PROTECTED_WITH_TESTS_ELSE_PRIVATE
Definition: common.hpp:41
DeadNonceList & getDeadNonceList()
Definition: forwarder.hpp:174
an Interest table entry
Definition: pit-entry.hpp:57
Copyright (c) 2014-2015, Regents of the University of California, Arizona Board of Regents...
Definition: algorithm.hpp:32
Pit & getPit()
Definition: forwarder.hpp:150
stores a collection of producer region names
void startProcessInterest(Face &face, const Interest &interest)
start incoming Interest processing
Definition: forwarder.hpp:112
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:138
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
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.hpp:122
Measurements & getMeasurements()
Definition: forwarder.hpp:162
NetworkRegionTable & getNetworkRegionTable()
Definition: forwarder.hpp:180
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.hpp:132