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"
30 #include "strategy-registry.hpp"
32 
33 namespace nfd {
34 namespace fw {
35 
38 class Strategy : public enable_shared_from_this<Strategy>, noncopyable
39 {
40 public:
48  Strategy(Forwarder& forwarder, const Name& name);
49 
50  virtual
51  ~Strategy();
52 
55  const Name&
56  getName() const
57  {
58  return m_name;
59  }
60 
61 public: // triggers
79  virtual void
80  afterReceiveInterest(const Face& inFace, const Interest& interest,
81  const shared_ptr<pit::Entry>& pitEntry) = 0;
82 
93  virtual void
94  beforeSatisfyInterest(const shared_ptr<pit::Entry>& pitEntry,
95  const Face& inFace, const Data& data);
96 
110  virtual void
111  beforeExpirePendingInterest(const shared_ptr<pit::Entry>& pitEntry);
112 
126  virtual void
127  afterReceiveNack(const Face& inFace, const lp::Nack& nack,
128  const shared_ptr<pit::Entry>& pitEntry);
129 
130 protected: // actions
137  VIRTUAL_WITH_TESTS void
138  sendInterest(const shared_ptr<pit::Entry>& pitEntry, Face& outFace,
139  bool wantNewNonce = false)
140  {
141  m_forwarder.onOutgoingInterest(pitEntry, outFace, wantNewNonce);
142  }
143 
150  VIRTUAL_WITH_TESTS void
151  rejectPendingInterest(const shared_ptr<pit::Entry>& pitEntry)
152  {
153  m_forwarder.onInterestReject(pitEntry);
154  }
155 
163  VIRTUAL_WITH_TESTS void
164  sendNack(const shared_ptr<pit::Entry>& pitEntry, const Face& outFace,
165  const lp::NackHeader& header)
166  {
167  m_forwarder.onOutgoingNack(pitEntry, outFace, header);
168  }
169 
177  void
178  sendNacks(const shared_ptr<pit::Entry>& pitEntry, const lp::NackHeader& header,
179  std::initializer_list<const Face*> exceptFaces = std::initializer_list<const Face*>());
180 
181 protected: // accessors
184  const fib::Entry&
185  lookupFib(const pit::Entry& pitEntry) const;
186 
187  MeasurementsAccessor&
189  {
190  return m_measurements;
191  }
192 
193  Face*
194  getFace(FaceId id) const
195  {
196  return m_forwarder.getFace(id);
197  }
198 
199  const FaceTable&
200  getFaceTable() const
201  {
202  return m_forwarder.getFaceTable();
203  }
204 
205 protected: // accessors
206  signal::Signal<FaceTable, Face&>& afterAddFace;
207  signal::Signal<FaceTable, Face&>& beforeRemoveFace;
208 
209 private:
210  Name m_name;
211 
216  Forwarder& m_forwarder;
217 
218  MeasurementsAccessor m_measurements;
219 };
220 
221 } // namespace fw
222 } // namespace nfd
223 
224 #endif // NFD_DAEMON_FW_STRATEGY_HPP
main class of NFD
Definition: forwarder.hpp:52
Strategy(Forwarder &forwarder, const Name &name)
construct a strategy instance
Definition: strategy.cpp:35
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:69
const FaceTable & getFaceTable() const
Definition: strategy.hpp:200
virtual void afterReceiveInterest(const Face &inFace, const Interest &interest, const shared_ptr< pit::Entry > &pitEntry)=0
trigger after Interest is received
represents a FIB entry
Definition: fib-entry.hpp:51
void sendNack(const shared_ptr< pit::Entry > &pitEntry, const Face &outFace, const lp::NackHeader &header)
send Nack to outFace
Definition: strategy.hpp:164
container of all faces
Definition: face-table.hpp:37
virtual void beforeSatisfyInterest(const shared_ptr< pit::Entry > &pitEntry, const Face &inFace, const Data &data)
trigger before PIT entry is satisfied
Definition: strategy.cpp:47
MeasurementsAccessor & getMeasurements()
Definition: strategy.hpp:188
an Interest table entry
Definition: pit-entry.hpp:57
Copyright (c) 2014-2015, Regents of the University of California, Arizona Board of Regents...
Definition: algorithm.hpp:32
signal::Signal< FaceTable, Face & > & afterAddFace
Definition: strategy.hpp:206
virtual void afterReceiveNack(const Face &inFace, const lp::Nack &nack, const shared_ptr< pit::Entry > &pitEntry)
trigger after Nack is received
Definition: strategy.cpp:61
const Name & getName() const
Definition: strategy.hpp:56
FaceTable & getFaceTable()
Definition: forwarder.hpp:68
represents a forwarding strategy
Definition: strategy.hpp:38
#define VIRTUAL_WITH_TESTS
Copyright (c) 2014-2016, Regents of the University of California, Arizona Board of Regents...
Definition: common.hpp:37
signal::Signal< FaceTable, Face & > & beforeRemoveFace
Definition: strategy.hpp:207
virtual void beforeExpirePendingInterest(const shared_ptr< pit::Entry > &pitEntry)
trigger before PIT entry expires
Definition: strategy.cpp:55
uint64_t FaceId
identifies a face
Definition: face.hpp:39
void sendInterest(const shared_ptr< pit::Entry > &pitEntry, Face &outFace, bool wantNewNonce=false)
send Interest to outFace
Definition: strategy.hpp:138
virtual ~Strategy()
Face * getFace(FaceId id) const
Definition: strategy.hpp:194
void rejectPendingInterest(const shared_ptr< pit::Entry > &pitEntry)
decide that a pending Interest cannot be forwarded
Definition: strategy.hpp:151
const fib::Entry & lookupFib(const pit::Entry &pitEntry) const
performs a FIB lookup, considering Link object if present
Definition: strategy.cpp:91
Face * getFace(FaceId id) const
get existing Face
Definition: forwarder.hpp:78