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-endpoint.hpp"
30 #include "face-table.hpp"
31 #include "forwarder-counters.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  Forwarder();
55 
57  ~Forwarder();
58 
59  const ForwarderCounters&
60  getCounters() const
61  {
62  return m_counters;
63  }
64 
65 public: // faces and policies
66  FaceTable&
68  {
69  return m_faceTable;
70  }
71 
76  Face*
77  getFace(FaceId id) const
78  {
79  return m_faceTable.get(id);
80  }
81 
86  void
87  addFace(shared_ptr<Face> face)
88  {
89  m_faceTable.add(face);
90  }
91 
94  {
95  return *m_unsolicitedDataPolicy;
96  }
97 
98  void
99  setUnsolicitedDataPolicy(unique_ptr<fw::UnsolicitedDataPolicy> policy)
100  {
101  BOOST_ASSERT(policy != nullptr);
102  m_unsolicitedDataPolicy = std::move(policy);
103  }
104 
105 public: // forwarding entrypoints and tables
110  void
111  startProcessInterest(const FaceEndpoint& ingress, const Interest& interest)
112  {
113  this->onIncomingInterest(ingress, interest);
114  }
115 
120  void
121  startProcessData(const FaceEndpoint& ingress, const Data& data)
122  {
123  this->onIncomingData(ingress, data);
124  }
125 
130  void
131  startProcessNack(const FaceEndpoint& ingress, const lp::Nack& nack)
132  {
133  this->onIncomingNack(ingress, nack);
134  }
135 
136  NameTree&
138  {
139  return m_nameTree;
140  }
141 
142  Fib&
144  {
145  return m_fib;
146  }
147 
148  Pit&
150  {
151  return m_pit;
152  }
153 
154  Cs&
156  {
157  return m_cs;
158  }
159 
160  Measurements&
162  {
163  return m_measurements;
164  }
165 
166  StrategyChoice&
168  {
169  return m_strategyChoice;
170  }
171 
174  {
175  return m_deadNonceList;
176  }
177 
180  {
181  return m_networkRegionTable;
182  }
183 
184 PUBLIC_WITH_TESTS_ELSE_PRIVATE: // pipelines
187  VIRTUAL_WITH_TESTS void
188  onIncomingInterest(const FaceEndpoint& ingress, const Interest& interest);
189 
192  VIRTUAL_WITH_TESTS void
193  onInterestLoop(const FaceEndpoint& ingress, const Interest& interest);
194 
197  VIRTUAL_WITH_TESTS void
198  onContentStoreMiss(const FaceEndpoint& ingress,
199  const shared_ptr<pit::Entry>& pitEntry, const Interest& interest);
200 
203  VIRTUAL_WITH_TESTS void
204  onContentStoreHit(const FaceEndpoint& ingress, 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,
211  const FaceEndpoint& egress, const Interest& interest);
212 
215  VIRTUAL_WITH_TESTS void
216  onInterestFinalize(const shared_ptr<pit::Entry>& pitEntry);
217 
220  VIRTUAL_WITH_TESTS void
221  onIncomingData(const FaceEndpoint& ingress, const Data& data);
222 
225  VIRTUAL_WITH_TESTS void
226  onDataUnsolicited(const FaceEndpoint& ingress, const Data& data);
227 
230  VIRTUAL_WITH_TESTS void
231  onOutgoingData(const Data& data, FaceEndpoint egress);
232 
235  VIRTUAL_WITH_TESTS void
236  onIncomingNack(const FaceEndpoint& ingress, const lp::Nack& nack);
237 
240  VIRTUAL_WITH_TESTS void
241  onOutgoingNack(const shared_ptr<pit::Entry>& pitEntry,
242  const FaceEndpoint& egress, const lp::NackHeader& nack);
243 
244  VIRTUAL_WITH_TESTS void
245  onDroppedInterest(const FaceEndpoint& egress, const Interest& interest);
246 
250  void
251  setExpiryTimer(const shared_ptr<pit::Entry>& pitEntry, time::milliseconds duration);
252 
257  VIRTUAL_WITH_TESTS void
258  insertDeadNonceList(pit::Entry& pitEntry, Face* upstream);
259 
262 #ifdef WITH_TESTS
263  virtual void
264  dispatchToStrategy(pit::Entry& pitEntry, std::function<void(fw::Strategy&)> trigger)
265 #else
266  template<class Function>
267  void
268  dispatchToStrategy(pit::Entry& pitEntry, Function trigger)
269 #endif
270  {
271  trigger(m_strategyChoice.findEffectiveStrategy(pitEntry));
272  }
273 
274 private:
275  ForwarderCounters m_counters;
276 
277  FaceTable m_faceTable;
278  unique_ptr<fw::UnsolicitedDataPolicy> m_unsolicitedDataPolicy;
279 
280  NameTree m_nameTree;
281  Fib m_fib;
282  Pit m_pit;
283  Cs m_cs;
284  Measurements m_measurements;
285  StrategyChoice m_strategyChoice;
286  DeadNonceList m_deadNonceList;
287  NetworkRegionTable m_networkRegionTable;
288 
289  // allow Strategy (base class) to enter pipelines
290  friend class fw::Strategy;
291 };
292 
293 } // namespace nfd
294 
295 #endif // NFD_DAEMON_FW_FORWARDER_HPP
Main class of NFD forwarding engine.
Definition: forwarder.hpp:51
Fib & getFib()
Definition: forwarder.hpp:143
StrategyChoice & getStrategyChoice()
Definition: forwarder.hpp:167
container of all faces
Definition: face-table.hpp:37
void startProcessData(const FaceEndpoint &ingress, const Data &data)
start incoming Data processing
Definition: forwarder.hpp:121
#define PROTECTED_WITH_TESTS_ELSE_PRIVATE
Definition: common.hpp:42
DeadNonceList & getDeadNonceList()
Definition: forwarder.hpp:173
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:149
stores a collection of producer region names
Represents the Dead Nonce List.
void setUnsolicitedDataPolicy(unique_ptr< fw::UnsolicitedDataPolicy > policy)
Definition: forwarder.hpp:99
determines how to process an unsolicited Data
NameTree & getNameTree()
Definition: forwarder.hpp:137
FaceTable & getFaceTable()
Definition: forwarder.hpp:67
void addFace(shared_ptr< Face > face)
add new Face
Definition: forwarder.hpp:87
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:60
fw::UnsolicitedDataPolicy & getUnsolicitedDataPolicy() const
Definition: forwarder.hpp:93
void startProcessInterest(const FaceEndpoint &ingress, const Interest &interest)
start incoming Interest processing
Definition: forwarder.hpp:111
void startProcessNack(const FaceEndpoint &ingress, const lp::Nack &nack)
start incoming Nack processing
Definition: forwarder.hpp:131
uint64_t FaceId
identifies a face
Definition: face.hpp:39
Measurements & getMeasurements()
Definition: forwarder.hpp:161
NetworkRegionTable & getNetworkRegionTable()
Definition: forwarder.hpp:179
Face * getFace(FaceId id) const
get existing Face
Definition: forwarder.hpp:77