NS-3 based Named Data Networking (NDN) simulator
ndnSIM 2.5: NDN, CCN, CCNx, content centric networks
API Documentation
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 #include "ns3/ndnSIM/model/cs/ndn-content-store.hpp"
43 
44 namespace nfd {
45 
46 namespace fw {
47 class Strategy;
48 } // namespace fw
49 
54 class Forwarder
55 {
56 public:
57  Forwarder();
58 
60  ~Forwarder();
61 
62  const ForwarderCounters&
63  getCounters() const
64  {
65  return m_counters;
66  }
67 
68 public: // faces and policies
69  FaceTable&
71  {
72  return m_faceTable;
73  }
74 
79  Face*
80  getFace(FaceId id) const
81  {
82  return m_faceTable.get(id);
83  }
84 
89  void
90  addFace(shared_ptr<Face> face)
91  {
92  m_faceTable.add(face);
93  }
94 
97  {
98  return *m_unsolicitedDataPolicy;
99  }
100 
101  void
102  setUnsolicitedDataPolicy(unique_ptr<fw::UnsolicitedDataPolicy> policy)
103  {
104  BOOST_ASSERT(policy != nullptr);
105  m_unsolicitedDataPolicy = std::move(policy);
106  }
107 
108 public: // forwarding entrypoints and tables
113  void
115  {
116  this->onIncomingInterest(face, interest);
117  }
118 
123  void
125  {
126  this->onIncomingData(face, data);
127  }
128 
133  void
135  {
136  this->onIncomingNack(face, nack);
137  }
138 
139  NameTree&
141  {
142  return m_nameTree;
143  }
144 
145  Fib&
147  {
148  return m_fib;
149  }
150 
151  Pit&
153  {
154  return m_pit;
155  }
156 
157  Cs&
159  {
160  return m_cs;
161  }
162 
163  Measurements&
165  {
166  return m_measurements;
167  }
168 
171  {
172  return m_strategyChoice;
173  }
174 
177  {
178  return m_deadNonceList;
179  }
180 
183  {
184  return m_networkRegionTable;
185  }
186 
187 public: // allow enabling ndnSIM content store (will be removed in the future)
188  void
189  setCsFromNdnSim(ns3::Ptr<ns3::ndn::ContentStore> cs)
190  {
191  m_csFromNdnSim = cs;
192  }
193 
194 public:
199 
204 
205 PUBLIC_WITH_TESTS_ELSE_PRIVATE: // pipelines
208  VIRTUAL_WITH_TESTS void
209  onIncomingInterest(Face& inFace, const Interest& interest);
210 
213  VIRTUAL_WITH_TESTS void
214  onInterestLoop(Face& inFace, const Interest& interest);
215 
218  VIRTUAL_WITH_TESTS void
219  onContentStoreMiss(const Face& inFace, const shared_ptr<pit::Entry>& pitEntry, const Interest& interest);
220 
223  VIRTUAL_WITH_TESTS void
224  onContentStoreHit(const Face& inFace, const shared_ptr<pit::Entry>& pitEntry,
225  const Interest& interest, const Data& data);
226 
229  VIRTUAL_WITH_TESTS void
230  onOutgoingInterest(const shared_ptr<pit::Entry>& pitEntry, Face& outFace, const Interest& interest);
231 
234  VIRTUAL_WITH_TESTS void
235  onInterestReject(const shared_ptr<pit::Entry>& pitEntry);
236 
239  VIRTUAL_WITH_TESTS void
240  onInterestUnsatisfied(const shared_ptr<pit::Entry>& pitEntry);
241 
246  VIRTUAL_WITH_TESTS void
247  onInterestFinalize(const shared_ptr<pit::Entry>& pitEntry, bool isSatisfied,
248  ndn::optional<time::milliseconds> dataFreshnessPeriod = ndn::nullopt);
249 
252  VIRTUAL_WITH_TESTS void
253  onIncomingData(Face& inFace, const Data& data);
254 
257  VIRTUAL_WITH_TESTS void
258  onDataUnsolicited(Face& inFace, const Data& data);
259 
262  VIRTUAL_WITH_TESTS void
263  onOutgoingData(const Data& data, Face& outFace);
264 
267  VIRTUAL_WITH_TESTS void
268  onIncomingNack(Face& inFace, const lp::Nack& nack);
269 
272  VIRTUAL_WITH_TESTS void
273  onOutgoingNack(const shared_ptr<pit::Entry>& pitEntry, const Face& outFace, const lp::NackHeader& nack);
274 
275  VIRTUAL_WITH_TESTS void
276  onDroppedInterest(Face& outFace, const Interest& interest);
277 
279  VIRTUAL_WITH_TESTS void
280  setUnsatisfyTimer(const shared_ptr<pit::Entry>& pitEntry);
281 
282  VIRTUAL_WITH_TESTS void
283  setStragglerTimer(const shared_ptr<pit::Entry>& pitEntry, bool isSatisfied,
284  ndn::optional<time::milliseconds> dataFreshnessPeriod = ndn::nullopt);
285 
286  VIRTUAL_WITH_TESTS void
287  cancelUnsatisfyAndStragglerTimer(pit::Entry& pitEntry);
288 
293  VIRTUAL_WITH_TESTS void
294  insertDeadNonceList(pit::Entry& pitEntry, bool isSatisfied,
295  ndn::optional<time::milliseconds> dataFreshnessPeriod, Face* upstream);
296 
299 #ifdef WITH_TESTS
300  virtual void
301  dispatchToStrategy(pit::Entry& pitEntry, function<void(fw::Strategy&)> trigger)
302 #else
303  template<class Function>
304  void
305  dispatchToStrategy(pit::Entry& pitEntry, Function trigger)
306 #endif
307  {
308  trigger(m_strategyChoice.findEffectiveStrategy(pitEntry));
309  }
310 
311 private:
312  ForwarderCounters m_counters;
313 
314  FaceTable m_faceTable;
315  unique_ptr<fw::UnsolicitedDataPolicy> m_unsolicitedDataPolicy;
316 
317  NameTree m_nameTree;
318  Fib m_fib;
319  Pit m_pit;
320  Cs m_cs;
321  Measurements m_measurements;
322  StrategyChoice m_strategyChoice;
323  DeadNonceList m_deadNonceList;
324  NetworkRegionTable m_networkRegionTable;
325  shared_ptr<Face> m_csFace;
326 
327  ns3::Ptr<ns3::ndn::ContentStore> m_csFromNdnSim;
328 
329  // allow Strategy (base class) to enter pipelines
330  friend class fw::Strategy;
331 };
332 
333 } // namespace nfd
334 
335 #endif // NFD_DAEMON_FW_FORWARDER_HPP
#define PUBLIC_WITH_TESTS_ELSE_PRIVATE
Definition: common.hpp:40
signal::Signal< Forwarder, pit::Entry, Face, Data > beforeSatisfyInterest
trigger before PIT entry is satisfied
Definition: forwarder.hpp:198
constexpr nullopt_t nullopt
const ForwarderCounters & getCounters() const
Definition: forwarder.hpp:63
represents the Dead Nonce list
counters provided by Forwarder
generalization of a network interface
Definition: face.hpp:67
implements the ContentStore
DeadNonceList & getDeadNonceList()
Definition: forwarder.hpp:176
void addFace(shared_ptr< Face > face)
add new Face
Definition: forwarder.hpp:90
Fib & getFib()
Definition: forwarder.hpp:146
determines how to process an unsolicited Data
void add(shared_ptr< Face > face)
add a face
Definition: face-table.cpp:57
#define VIRTUAL_WITH_TESTS
Definition: common.hpp:38
void startProcessInterest(Face &face, const Interest &interest)
start incoming Interest processing
Definition: forwarder.hpp:114
main class of NFD
Definition: forwarder.hpp:54
represents an Interest packet
Definition: interest.hpp:42
stores a collection of producer region names
StrategyChoice & getStrategyChoice()
Definition: forwarder.hpp:170
provides a lightweight signal / event system
Definition: signal.hpp:50
Face * get(FaceId id) const
get face by FaceId
Definition: face-table.cpp:44
represents a Network Nack
Definition: nack.hpp:40
represents the Interest Table
Definition: pit.hpp:46
FaceTable & getFaceTable()
Definition: forwarder.hpp:70
container of all faces
Definition: face-table.hpp:37
Copyright (c) 2011-2015 Regents of the University of California.
Definition: ndn-common.hpp:40
an Interest table entry
Definition: pit-entry.hpp:57
signal::Signal< Forwarder, pit::Entry > beforeExpirePendingInterest
trigger before PIT entry expires
Definition: forwarder.hpp:203
represents the Forwarding Information Base (FIB)
Definition: fib.hpp:49
void startProcessData(Face &face, const Data &data)
start incoming Data processing
Definition: forwarder.hpp:124
fw::Strategy & findEffectiveStrategy(const Name &prefix) const
get effective strategy for prefix
represents the Measurements table
represents the ContentStore
Definition: cs.hpp:62
fw::UnsolicitedDataPolicy & getUnsolicitedDataPolicy() const
Definition: forwarder.hpp:96
represents a forwarding strategy
Definition: strategy.hpp:37
a common index structure for FIB, PIT, StrategyChoice, and Measurements
Definition: name-tree.hpp:36
void setCsFromNdnSim(ns3::Ptr< ns3::ndn::ContentStore > cs)
Definition: forwarder.hpp:189
represents the Strategy Choice table
NetworkRegionTable & getNetworkRegionTable()
Definition: forwarder.hpp:182
Measurements & getMeasurements()
Definition: forwarder.hpp:164
Pit & getPit()
Definition: forwarder.hpp:152
#define PROTECTED_WITH_TESTS_ELSE_PRIVATE
Definition: common.hpp:41
uint64_t FaceId
identifies a face
Definition: face.hpp:39
Represents a Data packet.
Definition: data.hpp:35
represents a Network NACK header
Definition: nack-header.hpp:59
NameTree & getNameTree()
Definition: forwarder.hpp:140
void setUnsolicitedDataPolicy(unique_ptr< fw::UnsolicitedDataPolicy > policy)
Definition: forwarder.hpp:102
void startProcessNack(Face &face, const lp::Nack &nack)
start incoming Nack processing
Definition: forwarder.hpp:134
Face * getFace(FaceId id) const
get existing Face
Definition: forwarder.hpp:80