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-2019, 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 
150  StrategyChoice&
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 
193  VIRTUAL_WITH_TESTS void
194  onOutgoingInterest(const shared_ptr<pit::Entry>& pitEntry,
195  const FaceEndpoint& egress, const Interest& interest);
196 
199  VIRTUAL_WITH_TESTS void
200  onInterestFinalize(const shared_ptr<pit::Entry>& pitEntry);
201 
204  VIRTUAL_WITH_TESTS void
205  onIncomingData(const FaceEndpoint& ingress, const Data& data);
206 
209  VIRTUAL_WITH_TESTS void
210  onDataUnsolicited(const FaceEndpoint& ingress, const Data& data);
211 
214  VIRTUAL_WITH_TESTS void
215  onOutgoingData(const Data& data, const FaceEndpoint& egress);
216 
219  VIRTUAL_WITH_TESTS void
220  onIncomingNack(const FaceEndpoint& ingress, const lp::Nack& nack);
221 
224  VIRTUAL_WITH_TESTS void
225  onOutgoingNack(const shared_ptr<pit::Entry>& pitEntry,
226  const FaceEndpoint& egress, const lp::NackHeader& nack);
227 
228  VIRTUAL_WITH_TESTS void
229  onDroppedInterest(const FaceEndpoint& egress, const Interest& interest);
230 
231  VIRTUAL_WITH_TESTS void
232  onNewNextHop(const Name& prefix, const fib::NextHop& nextHop);
233 
237  void
238  setExpiryTimer(const shared_ptr<pit::Entry>& pitEntry, time::milliseconds duration);
239 
244  VIRTUAL_WITH_TESTS void
245  insertDeadNonceList(pit::Entry& pitEntry, Face* upstream);
246 
249 #ifdef WITH_TESTS
250  virtual void
251  dispatchToStrategy(pit::Entry& pitEntry, std::function<void(fw::Strategy&)> trigger)
252 #else
253  template<class Function>
254  void
255  dispatchToStrategy(pit::Entry& pitEntry, Function trigger)
256 #endif
257  {
258  trigger(m_strategyChoice.findEffectiveStrategy(pitEntry));
259  }
260 
261 private:
262  ForwarderCounters m_counters;
263 
264  FaceTable& m_faceTable;
265  unique_ptr<fw::UnsolicitedDataPolicy> m_unsolicitedDataPolicy;
266 
267  NameTree m_nameTree;
268  Fib m_fib;
269  Pit m_pit;
270  Cs m_cs;
271  Measurements m_measurements;
272  StrategyChoice m_strategyChoice;
273  DeadNonceList m_deadNonceList;
274  NetworkRegionTable m_networkRegionTable;
275 
276  // allow Strategy (base class) to enter pipelines
277  friend class fw::Strategy;
278 };
279 
280 } // namespace nfd
281 
282 #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
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
#define PROTECTED_WITH_TESTS_ELSE_PRIVATE
Definition: common.hpp:42
DeadNonceList & getDeadNonceList()
Definition: forwarder.hpp:157
An Interest table entry.
Definition: pit-entry.hpp:58
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
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
#define PUBLIC_WITH_TESTS_ELSE_PRIVATE
Definition: common.hpp:41
const ForwarderCounters & getCounters() const
Definition: forwarder.hpp:61
fw::UnsolicitedDataPolicy & getUnsolicitedDataPolicy() const
Definition: forwarder.hpp:67
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