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-2020, 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 "face-table.hpp"
30 #include "forwarder-counters.hpp"
32 #include "face/face-endpoint.hpp"
33 #include "table/fib.hpp"
34 #include "table/pit.hpp"
35 #include "table/cs.hpp"
36 #include "table/measurements.hpp"
40 
41 namespace nfd {
42 
43 namespace fw {
44 class Strategy;
45 } // namespace fw
46 
51 class Forwarder
52 {
53 public:
54  explicit
55  Forwarder(FaceTable& faceTable);
56 
58  ~Forwarder();
59 
60  const ForwarderCounters&
61  getCounters() const
62  {
63  return m_counters;
64  }
65 
68  {
69  return *m_unsolicitedDataPolicy;
70  }
71 
72  void
73  setUnsolicitedDataPolicy(unique_ptr<fw::UnsolicitedDataPolicy> policy)
74  {
75  BOOST_ASSERT(policy != nullptr);
76  m_unsolicitedDataPolicy = std::move(policy);
77  }
78 
79 public: // forwarding entrypoints and tables
84  void
85  startProcessInterest(const FaceEndpoint& ingress, const Interest& interest)
86  {
87  this->onIncomingInterest(ingress, interest);
88  }
89 
94  void
95  startProcessData(const FaceEndpoint& ingress, const Data& data)
96  {
97  this->onIncomingData(ingress, data);
98  }
99 
104  void
105  startProcessNack(const FaceEndpoint& ingress, const lp::Nack& nack)
106  {
107  this->onIncomingNack(ingress, nack);
108  }
109 
114  void
115  startProcessNewNextHop(const Name& prefix, const fib::NextHop& nextHop)
116  {
117  this->onNewNextHop(prefix, nextHop);
118  }
119 
120  NameTree&
122  {
123  return m_nameTree;
124  }
125 
126  Fib&
128  {
129  return m_fib;
130  }
131 
132  Pit&
134  {
135  return m_pit;
136  }
137 
138  Cs&
140  {
141  return m_cs;
142  }
143 
144  Measurements&
146  {
147  return m_measurements;
148  }
149 
152  {
153  return m_strategyChoice;
154  }
155 
158  {
159  return m_deadNonceList;
160  }
161 
164  {
165  return m_networkRegionTable;
166  }
167 
168 PUBLIC_WITH_TESTS_ELSE_PRIVATE: // pipelines
171  VIRTUAL_WITH_TESTS void
172  onIncomingInterest(const FaceEndpoint& ingress, const Interest& interest);
173 
176  VIRTUAL_WITH_TESTS void
177  onInterestLoop(const FaceEndpoint& ingress, const Interest& interest);
178 
181  VIRTUAL_WITH_TESTS void
182  onContentStoreMiss(const FaceEndpoint& ingress,
183  const shared_ptr<pit::Entry>& pitEntry, const Interest& interest);
184 
187  VIRTUAL_WITH_TESTS void
188  onContentStoreHit(const FaceEndpoint& ingress, const shared_ptr<pit::Entry>& pitEntry,
189  const Interest& interest, const Data& data);
190 
195  onOutgoingInterest(const shared_ptr<pit::Entry>& pitEntry,
196  Face& egress, const Interest& interest);
197 
200  VIRTUAL_WITH_TESTS void
201  onInterestFinalize(const shared_ptr<pit::Entry>& pitEntry);
202 
205  VIRTUAL_WITH_TESTS void
206  onIncomingData(const FaceEndpoint& ingress, const Data& data);
207 
210  VIRTUAL_WITH_TESTS void
211  onDataUnsolicited(const FaceEndpoint& ingress, const Data& data);
212 
216  VIRTUAL_WITH_TESTS bool
217  onOutgoingData(const Data& data, Face& egress);
218 
221  VIRTUAL_WITH_TESTS void
222  onIncomingNack(const FaceEndpoint& ingress, const lp::Nack& nack);
223 
227  VIRTUAL_WITH_TESTS bool
228  onOutgoingNack(const shared_ptr<pit::Entry>& pitEntry,
229  Face& egress, const lp::NackHeader& nack);
230 
231  VIRTUAL_WITH_TESTS void
232  onDroppedInterest(const Face& egress, const Interest& interest);
233 
234  VIRTUAL_WITH_TESTS void
235  onNewNextHop(const Name& prefix, const fib::NextHop& nextHop);
236 
240  void
241  setExpiryTimer(const shared_ptr<pit::Entry>& pitEntry, time::milliseconds duration);
242 
247  VIRTUAL_WITH_TESTS void
248  insertDeadNonceList(pit::Entry& pitEntry, Face* upstream);
249 
252 #ifdef WITH_TESTS
253  virtual void
254  dispatchToStrategy(pit::Entry& pitEntry, std::function<void(fw::Strategy&)> trigger)
255 #else
256  template<class Function>
257  void
258  dispatchToStrategy(pit::Entry& pitEntry, Function trigger)
259 #endif
260  {
261  trigger(m_strategyChoice.findEffectiveStrategy(pitEntry));
262  }
263 
264 private:
265  ForwarderCounters m_counters;
266 
267  FaceTable& m_faceTable;
268  unique_ptr<fw::UnsolicitedDataPolicy> m_unsolicitedDataPolicy;
269 
270  NameTree m_nameTree;
271  Fib m_fib;
272  Pit m_pit;
273  Cs m_cs;
274  Measurements m_measurements;
275  StrategyChoice m_strategyChoice;
276  DeadNonceList m_deadNonceList;
277  NetworkRegionTable m_networkRegionTable;
278 
279  // allow Strategy (base class) to enter pipelines
280  friend class fw::Strategy;
281 };
282 
283 } // namespace nfd
284 
285 #endif // NFD_DAEMON_FW_FORWARDER_HPP
void startProcessNewNextHop(const Name &prefix, const fib::NextHop &nextHop)
start new nexthop processing
Definition: forwarder.hpp:115
Main class of NFD&#39;s forwarding engine.
Definition: forwarder.hpp:51
A common index structure for FIB, PIT, StrategyChoice, and Measurements.
Definition: name-tree.hpp:36
Represents the Strategy Choice table.
Contains information about an Interest toward an outgoing face.
Fib & getFib()
Definition: forwarder.hpp:127
StrategyChoice & getStrategyChoice()
Definition: forwarder.hpp:151
container of all faces
Definition: face-table.hpp:38
void startProcessData(const FaceEndpoint &ingress, const Data &data)
start incoming Data processing
Definition: forwarder.hpp:95
const ForwarderCounters & getCounters() const
Definition: forwarder.hpp:61
Represents the Forwarding Information Base (FIB)
Definition: fib.hpp:47
implements the Content Store
Definition: cs.hpp:44
#define PROTECTED_WITH_TESTS_ELSE_PRIVATE
Definition: common.hpp:42
DeadNonceList & getDeadNonceList()
Definition: forwarder.hpp:157
The Measurements table.
An Interest table entry.
Definition: pit-entry.hpp:58
fw::UnsolicitedDataPolicy & getUnsolicitedDataPolicy() const
Definition: forwarder.hpp:67
Represents a face-endpoint pair in the forwarder.
Copyright (c) 2014-2015, Regents of the University of California, Arizona Board of Regents...
Definition: algorithm.hpp:32
Pit & getPit()
Definition: forwarder.hpp:133
stores a collection of producer region names
Represents the Dead Nonce List.
void setUnsolicitedDataPolicy(unique_ptr< fw::UnsolicitedDataPolicy > policy)
Definition: forwarder.hpp:73
generalization of a network interface
Definition: face.hpp:54
determines how to process an unsolicited Data
NameTree & getNameTree()
Definition: forwarder.hpp:121
Counters provided by Forwarder.
Represents a forwarding strategy.
Definition: strategy.hpp:37
#define VIRTUAL_WITH_TESTS
Definition: common.hpp:39
Represents the Interest Table.
Definition: pit.hpp:47
#define PUBLIC_WITH_TESTS_ELSE_PRIVATE
Definition: common.hpp:41
void startProcessInterest(const FaceEndpoint &ingress, const Interest &interest)
start incoming Interest processing
Definition: forwarder.hpp:85
void startProcessNack(const FaceEndpoint &ingress, const lp::Nack &nack)
start incoming Nack processing
Definition: forwarder.hpp:105
Represents a nexthop record in a FIB entry.
Definition: fib-nexthop.hpp:37
Measurements & getMeasurements()
Definition: forwarder.hpp:145
NetworkRegionTable & getNetworkRegionTable()
Definition: forwarder.hpp:163