NS-3 based Named Data Networking (NDN) simulator
ndnSIM 2.3: 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 
276  VIRTUAL_WITH_TESTS void
277  setUnsatisfyTimer(const shared_ptr<pit::Entry>& pitEntry);
278 
279  VIRTUAL_WITH_TESTS void
280  setStragglerTimer(const shared_ptr<pit::Entry>& pitEntry, bool isSatisfied,
281  ndn::optional<time::milliseconds> dataFreshnessPeriod = ndn::nullopt);
282 
283  VIRTUAL_WITH_TESTS void
284  cancelUnsatisfyAndStragglerTimer(pit::Entry& pitEntry);
285 
290  VIRTUAL_WITH_TESTS void
291  insertDeadNonceList(pit::Entry& pitEntry, bool isSatisfied,
292  ndn::optional<time::milliseconds> dataFreshnessPeriod, Face* upstream);
293 
296 #ifdef WITH_TESTS
297  virtual void
298  dispatchToStrategy(pit::Entry& pitEntry, function<void(fw::Strategy&)> trigger)
299 #else
300  template<class Function>
301  void
302  dispatchToStrategy(pit::Entry& pitEntry, Function trigger)
303 #endif
304  {
305  trigger(m_strategyChoice.findEffectiveStrategy(pitEntry));
306  }
307 
308 private:
309  ForwarderCounters m_counters;
310 
311  FaceTable m_faceTable;
312  unique_ptr<fw::UnsolicitedDataPolicy> m_unsolicitedDataPolicy;
313 
314  NameTree m_nameTree;
315  Fib m_fib;
316  Pit m_pit;
317  Cs m_cs;
318  Measurements m_measurements;
319  StrategyChoice m_strategyChoice;
320  DeadNonceList m_deadNonceList;
321  NetworkRegionTable m_networkRegionTable;
322  shared_ptr<Face> m_csFace;
323 
324  ns3::Ptr<ns3::ndn::ContentStore> m_csFromNdnSim;
325 
326  // allow Strategy (base class) to enter pipelines
327  friend class fw::Strategy;
328 };
329 
330 } // namespace nfd
331 
332 #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
Face * getFace(FaceId id) const
get existing Face
Definition: forwarder.hpp:80
represents the Dead Nonce list
counters provided by Forwarder
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
#define VIRTUAL_WITH_TESTS
Definition: common.hpp:38
void startProcessInterest(Face &face, const Interest &interest)
start incoming Interest processing
Definition: forwarder.hpp:114
const ForwarderCounters & getCounters() const
Definition: forwarder.hpp:63
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
represents a Network Nack
Definition: nack.hpp:40
ndn Face
Definition: face-impl.hpp:41
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
void startProcessData(Face &face, const Data &data)
start incoming Data processing
Definition: forwarder.hpp:124
Forwarder
Definition: forwarder.cpp:38
represents a forwarding strategy
Definition: strategy.hpp:37
void setCsFromNdnSim(ns3::Ptr< ns3::ndn::ContentStore > cs)
Definition: forwarder.hpp:189
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
fw::UnsolicitedDataPolicy & getUnsolicitedDataPolicy() const
Definition: forwarder.hpp:96
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