NS-3 based Named Data Networking (NDN) simulator
ndnSIM 2.5: NDN, CCN, CCNx, content centric networks
API Documentation
strategy.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_STRATEGY_HPP
27 #define NFD_DAEMON_FW_STRATEGY_HPP
28 
29 #include "forwarder.hpp"
31 
32 namespace nfd {
33 namespace fw {
34 
37 class Strategy : noncopyable
38 {
39 public: // registry
46  template<typename S>
47  static void
48  registerType(const Name& strategyName = S::getStrategyName())
49  {
50  BOOST_ASSERT(strategyName.size() > 1);
51  BOOST_ASSERT(strategyName.at(-1).isVersion());
52  Registry& registry = getRegistry();
53  BOOST_ASSERT(registry.count(strategyName) == 0);
54  registry[strategyName] = &make_unique<S, Forwarder&, const Name&>;
55  }
56 
62  static bool
63  canCreate(const Name& instanceName);
64 
70  static unique_ptr<Strategy>
71  create(const Name& instanceName, Forwarder& forwarder);
72 
75  static bool
76  areSameType(const Name& instanceNameA, const Name& instanceNameB);
77 
80  static std::set<Name>
82 
83 public: // constructor, destructor, strategy name
88  explicit
89  Strategy(Forwarder& forwarder);
90 
91  virtual
92  ~Strategy();
93 
94 #ifdef DOXYGEN
95 
100  static const Name&
101  getStrategyName();
102 #endif
103 
109  const Name&
111  {
112  return m_name;
113  }
114 
115 public: // triggers
133  virtual void
134  afterReceiveInterest(const Face& inFace, const Interest& interest,
135  const shared_ptr<pit::Entry>& pitEntry) = 0;
136 
147  virtual void
148  beforeSatisfyInterest(const shared_ptr<pit::Entry>& pitEntry,
149  const Face& inFace, const Data& data);
150 
164  virtual void
165  beforeExpirePendingInterest(const shared_ptr<pit::Entry>& pitEntry);
166 
180  virtual void
181  afterReceiveNack(const Face& inFace, const lp::Nack& nack,
182  const shared_ptr<pit::Entry>& pitEntry);
183 
188  virtual void
189  onDroppedInterest(const Face& outFace, const Interest& interest);
190 
191 protected: // actions
197  VIRTUAL_WITH_TESTS void
198  sendInterest(const shared_ptr<pit::Entry>& pitEntry, Face& outFace,
199  const Interest& interest)
200  {
201  m_forwarder.onOutgoingInterest(pitEntry, outFace, interest);
202  }
203 
210  VIRTUAL_WITH_TESTS void
211  rejectPendingInterest(const shared_ptr<pit::Entry>& pitEntry)
212  {
213  m_forwarder.onInterestReject(pitEntry);
214  }
215 
223  VIRTUAL_WITH_TESTS void
224  sendNack(const shared_ptr<pit::Entry>& pitEntry, const Face& outFace,
225  const lp::NackHeader& header)
226  {
227  m_forwarder.onOutgoingNack(pitEntry, outFace, header);
228  }
229 
237  void
238  sendNacks(const shared_ptr<pit::Entry>& pitEntry, const lp::NackHeader& header,
239  std::initializer_list<const Face*> exceptFaces = std::initializer_list<const Face*>());
240 
241 protected: // accessors
244  const fib::Entry&
245  lookupFib(const pit::Entry& pitEntry) const;
246 
249  {
250  return m_measurements;
251  }
252 
253  Face*
254  getFace(FaceId id) const
255  {
256  return m_forwarder.getFace(id);
257  }
258 
259  const FaceTable&
260  getFaceTable() const
261  {
262  return m_forwarder.getFaceTable();
263  }
264 
265 protected: // instance name
267  {
271  };
272 
277  static ParsedInstanceName
278  parseInstanceName(const Name& input);
279 
290  static Name
291  makeInstanceName(const Name& input, const Name& strategyName);
292 
296  void
298  {
299  m_name = name;
300  }
301 
302 private: // registry
303  typedef std::function<unique_ptr<Strategy>(Forwarder& forwarder, const Name& strategyName)> CreateFunc;
304  typedef std::map<Name, CreateFunc> Registry; // indexed by strategy name
305 
306  static Registry&
307  getRegistry();
308 
309  static Registry::const_iterator
310  find(const Name& instanceName);
311 
312 protected: // accessors
315 
316 private: // instance fields
317  Name m_name;
318 
323  Forwarder& m_forwarder;
324 
325  MeasurementsAccessor m_measurements;
326 };
327 
328 } // namespace fw
329 } // namespace nfd
330 
335 #define NFD_REGISTER_STRATEGY(S) \
336 static class NfdAuto ## S ## StrategyRegistrationClass \
337 { \
338 public: \
339  NfdAuto ## S ## StrategyRegistrationClass() \
340  { \
341  ::nfd::fw::Strategy::registerType<S>(); \
342  } \
343 } g_nfdAuto ## S ## StrategyRegistrationVariable
344 
345 #endif // NFD_DAEMON_FW_STRATEGY_HPP
signal::Signal< FaceTable, Face & > & afterAddFace
Definition: strategy.hpp:313
static ParsedInstanceName parseInstanceName(const Name &input)
parse a strategy instance name
Definition: strategy.cpp:121
static std::set< Name > listRegistered()
Definition: strategy.cpp:112
generalization of a network interface
Definition: face.hpp:67
represents a FIB entry
Definition: fib-entry.hpp:51
PartialName parameters
parameter components
Definition: strategy.hpp:270
void sendNack(const shared_ptr< pit::Entry > &pitEntry, const Face &outFace, const lp::NackHeader &header)
send Nack to outFace
Definition: strategy.hpp:224
Strategy(Forwarder &forwarder)
construct a strategy instance
Definition: strategy.cpp:141
Face * getFace(FaceId id) const
Definition: strategy.hpp:254
#define VIRTUAL_WITH_TESTS
Definition: common.hpp:38
virtual void beforeExpirePendingInterest(const shared_ptr< pit::Entry > &pitEntry)
trigger before PIT entry expires
Definition: strategy.cpp:160
main class of NFD
Definition: forwarder.hpp:54
void setInstanceName(const Name &name)
set strategy instance name
Definition: strategy.hpp:297
represents an Interest packet
Definition: interest.hpp:42
provides a lightweight signal / event system
Definition: signal.hpp:50
ndn::optional< uint64_t > version
whether strategyName contains a version component
Definition: strategy.hpp:269
represents a Network Nack
Definition: nack.hpp:40
virtual void afterReceiveNack(const Face &inFace, const lp::Nack &nack, const shared_ptr< pit::Entry > &pitEntry)
trigger after Nack is received
Definition: strategy.cpp:166
virtual ~Strategy()
FaceTable & getFaceTable()
Definition: forwarder.hpp:70
virtual void onDroppedInterest(const Face &outFace, const Interest &interest)
trigger after Interest dropped for exceeding allowed retransmissions
Definition: strategy.cpp:174
Name strategyName
strategy name without parameters
Definition: strategy.hpp:268
container of all faces
Definition: face-table.hpp:37
Copyright (c) 2011-2015 Regents of the University of California.
Definition: ndn-common.hpp:40
MeasurementsAccessor & getMeasurements()
Definition: strategy.hpp:248
an Interest table entry
Definition: pit-entry.hpp:57
Name PartialName
Represents an arbitrary sequence of name components.
Definition: name.hpp:38
void rejectPendingInterest(const shared_ptr< pit::Entry > &pitEntry)
decide that a pending Interest cannot be forwarded
Definition: strategy.hpp:211
virtual void beforeSatisfyInterest(const shared_ptr< pit::Entry > &pitEntry, const Face &inFace, const Data &data)
trigger before PIT entry is satisfied
Definition: strategy.cpp:152
Represents an absolute name.
Definition: name.hpp:42
signal::Signal< FaceTable, Face & > & beforeRemoveFace
Definition: strategy.hpp:314
represents a forwarding strategy
Definition: strategy.hpp:37
void sendNacks(const shared_ptr< pit::Entry > &pitEntry, const lp::NackHeader &header, std::initializer_list< const Face *> exceptFaces=std::initializer_list< const Face *>())
send Nack to every face that has an in-record, except those in exceptFaces
Definition: strategy.cpp:180
static const Name & getStrategyName()
allows Strategy to access portion of Measurements table under its namespace
static unique_ptr< Strategy > create(const Name &instanceName, Forwarder &forwarder)
Definition: strategy.cpp:90
const fib::Entry & lookupFib(const pit::Entry &pitEntry) const
performs a FIB lookup, considering Link object if present
Definition: strategy.cpp:202
const FaceTable & getFaceTable() const
Definition: strategy.hpp:260
const Name & getInstanceName() const
Definition: strategy.hpp:110
static Name makeInstanceName(const Name &input, const Name &strategyName)
construct a strategy instance name
Definition: strategy.cpp:132
virtual void afterReceiveInterest(const Face &inFace, const Interest &interest, const shared_ptr< pit::Entry > &pitEntry)=0
trigger after Interest is received
uint64_t FaceId
identifies a face
Definition: face.hpp:39
static bool canCreate(const Name &instanceName)
Definition: strategy.cpp:84
Represents a Data packet.
Definition: data.hpp:35
represents a Network NACK header
Definition: nack-header.hpp:59
void sendInterest(const shared_ptr< pit::Entry > &pitEntry, Face &outFace, const Interest &interest)
send Interest to outFace
Definition: strategy.hpp:198
static bool areSameType(const Name &instanceNameA, const Name &instanceNameB)
Definition: strategy.cpp:106
static void registerType(const Name &strategyName=S::getStrategyName())
register a strategy type
Definition: strategy.hpp:48
Face * getFace(FaceId id) const
get existing Face
Definition: forwarder.hpp:80