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-2018, 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  onInterestFinalize(const shared_ptr<pit::Entry>& pitEntry);
216 
219  VIRTUAL_WITH_TESTS void
220  onIncomingData(Face& inFace, const Data& data);
221 
224  VIRTUAL_WITH_TESTS void
225  onDataUnsolicited(Face& inFace, const Data& data);
226 
229  VIRTUAL_WITH_TESTS void
230  onOutgoingData(const Data& data, Face& outFace);
231 
234  VIRTUAL_WITH_TESTS void
235  onIncomingNack(Face& inFace, const lp::Nack& nack);
236 
239  VIRTUAL_WITH_TESTS void
240  onOutgoingNack(const shared_ptr<pit::Entry>& pitEntry, const Face& outFace, const lp::NackHeader& nack);
241 
242  VIRTUAL_WITH_TESTS void
243  onDroppedInterest(Face& outFace, const Interest& interest);
244 
248  void
249  setExpiryTimer(const shared_ptr<pit::Entry>& pitEntry, time::milliseconds duration);
250 
255  VIRTUAL_WITH_TESTS void
256  insertDeadNonceList(pit::Entry& pitEntry, Face* upstream);
257 
260 #ifdef WITH_TESTS
261  virtual void
262  dispatchToStrategy(pit::Entry& pitEntry, std::function<void(fw::Strategy&)> trigger)
263 #else
264  template<class Function>
265  void
266  dispatchToStrategy(pit::Entry& pitEntry, Function trigger)
267 #endif
268  {
269  trigger(m_strategyChoice.findEffectiveStrategy(pitEntry));
270  }
271 
272 private:
273  ForwarderCounters m_counters;
274 
275  FaceTable m_faceTable;
276  unique_ptr<fw::UnsolicitedDataPolicy> m_unsolicitedDataPolicy;
277 
278  NameTree m_nameTree;
279  Fib m_fib;
280  Pit m_pit;
281  Cs m_cs;
282  Measurements m_measurements;
283  StrategyChoice m_strategyChoice;
284  DeadNonceList m_deadNonceList;
285  NetworkRegionTable m_networkRegionTable;
286 
287  // allow Strategy (base class) to enter pipelines
288  friend class fw::Strategy;
289 };
290 
291 } // namespace nfd
292 
293 #endif // NFD_DAEMON_FW_FORWARDER_HPP
main class of NFD
Definition: forwarder.hpp:52
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:59
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