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-2018, 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  onInterestFinalize(const shared_ptr<pit::Entry>& pitEntry);
236 
239  VIRTUAL_WITH_TESTS void
240  onIncomingData(Face& inFace, const Data& data);
241 
244  VIRTUAL_WITH_TESTS void
245  onDataUnsolicited(Face& inFace, const Data& data);
246 
249  VIRTUAL_WITH_TESTS void
250  onOutgoingData(const Data& data, Face& outFace);
251 
254  VIRTUAL_WITH_TESTS void
255  onIncomingNack(Face& inFace, const lp::Nack& nack);
256 
259  VIRTUAL_WITH_TESTS void
260  onOutgoingNack(const shared_ptr<pit::Entry>& pitEntry, const Face& outFace, const lp::NackHeader& nack);
261 
262  VIRTUAL_WITH_TESTS void
263  onDroppedInterest(Face& outFace, const Interest& interest);
264 
268  void
269  setExpiryTimer(const shared_ptr<pit::Entry>& pitEntry, time::milliseconds duration);
270 
275  VIRTUAL_WITH_TESTS void
276  insertDeadNonceList(pit::Entry& pitEntry, Face* upstream);
277 
280 #ifdef WITH_TESTS
281  virtual void
282  dispatchToStrategy(pit::Entry& pitEntry, std::function<void(fw::Strategy&)> trigger)
283 #else
284  template<class Function>
285  void
286  dispatchToStrategy(pit::Entry& pitEntry, Function trigger)
287 #endif
288  {
289  trigger(m_strategyChoice.findEffectiveStrategy(pitEntry));
290  }
291 
292 private:
293  ForwarderCounters m_counters;
294 
295  FaceTable m_faceTable;
296  unique_ptr<fw::UnsolicitedDataPolicy> m_unsolicitedDataPolicy;
297 
298  NameTree m_nameTree;
299  Fib m_fib;
300  Pit m_pit;
301  Cs m_cs;
302  Measurements m_measurements;
303  StrategyChoice m_strategyChoice;
304  DeadNonceList m_deadNonceList;
305  NetworkRegionTable m_networkRegionTable;
306  shared_ptr<Face> m_csFace;
307 
308  ns3::Ptr<ns3::ndn::ContentStore> m_csFromNdnSim;
309 
310  // allow Strategy (base class) to enter pipelines
311  friend class fw::Strategy;
312 };
313 
314 } // namespace nfd
315 
316 #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
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
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:58
#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:45
represents a Network Nack
Definition: nack.hpp:40
represents the Interest Table
Definition: pit.hpp:47
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
the Measurements table
implements the Content Store
Definition: cs.hpp:48
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:38
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