NS-3 based Named Data Networking (NDN) simulator
ndnSIM 2.3: 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; -*- */
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 
184 protected: // actions
190  VIRTUAL_WITH_TESTS void
191  sendInterest(const shared_ptr<pit::Entry>& pitEntry, Face& outFace,
192  const Interest& interest)
193  {
194  m_forwarder.onOutgoingInterest(pitEntry, outFace, interest);
195  }
196 
203  VIRTUAL_WITH_TESTS void
204  rejectPendingInterest(const shared_ptr<pit::Entry>& pitEntry)
205  {
206  m_forwarder.onInterestReject(pitEntry);
207  }
208 
216  VIRTUAL_WITH_TESTS void
217  sendNack(const shared_ptr<pit::Entry>& pitEntry, const Face& outFace,
218  const lp::NackHeader& header)
219  {
220  m_forwarder.onOutgoingNack(pitEntry, outFace, header);
221  }
222 
230  void
231  sendNacks(const shared_ptr<pit::Entry>& pitEntry, const lp::NackHeader& header,
232  std::initializer_list<const Face*> exceptFaces = std::initializer_list<const Face*>());
233 
234 protected: // accessors
237  const fib::Entry&
238  lookupFib(const pit::Entry& pitEntry) const;
239 
240  MeasurementsAccessor&
242  {
243  return m_measurements;
244  }
245 
246  Face*
247  getFace(FaceId id) const
248  {
249  return m_forwarder.getFace(id);
250  }
251 
252  const FaceTable&
253  getFaceTable() const
254  {
255  return m_forwarder.getFaceTable();
256  }
257 
258 protected: // instance name
260  {
264  };
265 
270  static ParsedInstanceName
271  parseInstanceName(const Name& input);
272 
283  static Name
284  makeInstanceName(const Name& input, const Name& strategyName);
285 
289  void
291  {
292  m_name = name;
293  }
294 
295 private: // registry
296  typedef std::function<unique_ptr<Strategy>(Forwarder& forwarder, const Name& strategyName)> CreateFunc;
297  typedef std::map<Name, CreateFunc> Registry; // indexed by strategy name
298 
299  static Registry&
300  getRegistry();
301 
302  static Registry::const_iterator
303  find(const Name& instanceName);
304 
305 protected: // accessors
308 
309 private: // instance fields
310  Name m_name;
311 
316  Forwarder& m_forwarder;
317 
318  MeasurementsAccessor m_measurements;
319 };
320 
321 } // namespace fw
322 } // namespace nfd
323 
328 #define NFD_REGISTER_STRATEGY(S) \
329 static class NfdAuto ## S ## StrategyRegistrationClass \
330 { \
331 public: \
332  NfdAuto ## S ## StrategyRegistrationClass() \
333  { \
334  ::nfd::fw::Strategy::registerType<S>(); \
335  } \
336 } g_nfdAuto ## S ## StrategyRegistrationVariable
337 
338 #endif // NFD_DAEMON_FW_STRATEGY_HPP
signal::Signal< FaceTable, Face & > & afterAddFace
Definition: strategy.hpp:306
Face * getFace(FaceId id) const
get existing Face
Definition: forwarder.hpp:80
static ParsedInstanceName parseInstanceName(const Name &input)
parse a strategy instance name
Definition: strategy.cpp:121
static std::set< Name > listRegistered()
Definition: strategy.cpp:112
represents a FIB entry
Definition: fib-entry.hpp:51
PartialName parameters
parameter components
Definition: strategy.hpp:263
void sendNack(const shared_ptr< pit::Entry > &pitEntry, const Face &outFace, const lp::NackHeader &header)
send Nack to outFace
Definition: strategy.hpp:217
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:174
const FaceTable & getFaceTable() const
Definition: strategy.hpp:253
Strategy(Forwarder &forwarder)
construct a strategy instance
Definition: strategy.cpp:141
#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:290
represents an Interest packet
Definition: interest.hpp:42
provides a lightweight signal / event system
Definition: signal.hpp:50
const Name & getInstanceName() const
Definition: strategy.hpp:110
ndn::optional< uint64_t > version
whether strategyName contains a version component
Definition: strategy.hpp:262
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()
ndn Face
Definition: face-impl.hpp:41
FaceTable & getFaceTable()
Definition: forwarder.hpp:70
Name strategyName
strategy name without parameters
Definition: strategy.hpp:261
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:241
an Interest table entry
Definition: pit-entry.hpp:57
Name PartialName
Represents an arbitrary sequence of name components.
Definition: name.hpp:38
const fib::Entry & lookupFib(const pit::Entry &pitEntry) const
performs a FIB lookup, considering Link object if present
Definition: strategy.cpp:196
void rejectPendingInterest(const shared_ptr< pit::Entry > &pitEntry)
decide that a pending Interest cannot be forwarded
Definition: strategy.hpp:204
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:307
represents a forwarding strategy
Definition: strategy.hpp:37
static const Name & getStrategyName()
static unique_ptr< Strategy > create(const Name &instanceName, Forwarder &forwarder)
Definition: strategy.cpp:90
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:191
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
Definition: strategy.hpp:247