NS-3 based Named Data Networking (NDN) simulator
ndnSIM 2.0: NDN, CCN, CCNx, content centric networks
API Documentation
strategy.cpp
Go to the documentation of this file.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
26 #include "strategy.hpp"
27 #include "forwarder.hpp"
28 #include "core/logger.hpp"
29 
30 namespace nfd {
31 namespace fw {
32 
33 NFD_LOG_INIT("Strategy");
34 
36  : afterAddFace(forwarder.getFaceTable().afterAdd)
37  , beforeRemoveFace(forwarder.getFaceTable().beforeRemove)
38  , m_name(name)
39  , m_forwarder(forwarder)
40  , m_measurements(m_forwarder.getMeasurements(),
41  m_forwarder.getStrategyChoice(), *this)
42 {
43 }
44 
46 {
47 }
48 
49 void
50 Strategy::beforeSatisfyInterest(shared_ptr<pit::Entry> pitEntry,
51  const Face& inFace, const Data& data)
52 {
53  NFD_LOG_DEBUG("beforeSatisfyInterest pitEntry=" << pitEntry->getName() <<
54  " inFace=" << inFace.getId() << " data=" << data.getName());
55 }
56 
57 void
58 Strategy::beforeExpirePendingInterest(shared_ptr<pit::Entry> pitEntry)
59 {
60  NFD_LOG_DEBUG("beforeExpirePendingInterest pitEntry=" << pitEntry->getName());
61 }
62 
63 void
64 Strategy::afterReceiveNack(const Face& inFace, const lp::Nack& nack,
65  shared_ptr<fib::Entry> fibEntry, shared_ptr<pit::Entry> pitEntry)
66 {
67  NFD_LOG_DEBUG("afterReceiveNack inFace=" << inFace.getId() <<
68  " pitEntry=" << pitEntry->getName());
69 }
70 
71 void
72 Strategy::sendNacks(shared_ptr<pit::Entry> pitEntry, const lp::NackHeader& header,
73  std::initializer_list<const Face*> exceptFaces)
74 {
75  // populate downstreams with all downstreams faces
76  std::unordered_set<const Face*> downstreams;
77  const pit::InRecordCollection& inRecords = pitEntry->getInRecords();
78  std::transform(inRecords.begin(), inRecords.end(), std::inserter(downstreams, downstreams.end()),
79  [] (const pit::InRecord& inR) { return inR.getFace().get(); });
80 
81  // delete excluded faces
82  // .erase in a loop is more efficient than std::set_difference between that requires sorted range
83  for (const Face* exceptFace : exceptFaces) {
84  downstreams.erase(exceptFace);
85  }
86 
87  // send Nacks
88  for (const Face* downstream : downstreams) {
89  this->sendNack(pitEntry, *downstream, header);
90  }
91  // warning: don't loop on pitEntry->getInRecords(), because InRecord is erased when sending Nack
92 }
93 
94 } // namespace fw
95 } // namespace nfd
std::list< InRecord > InRecordCollection
represents an unordered collection of InRecords
Definition: pit-entry.hpp:47
#define NFD_LOG_DEBUG(expression)
Definition: logger.hpp:55
shared_ptr< Face > getFace() const
const Name & getName() const
Get name of the Data packet.
Definition: data.hpp:360
contains information about an Interest from an incoming face
virtual void beforeSatisfyInterest(shared_ptr< pit::Entry > pitEntry, const Face &inFace, const Data &data)
trigger before PIT entry is satisfied
Definition: strategy.cpp:50
main class of NFD
Definition: forwarder.hpp:55
represents a Network Nack
Definition: nack.hpp:40
void sendNacks(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:72
virtual void beforeExpirePendingInterest(shared_ptr< pit::Entry > pitEntry)
trigger before PIT entry expires
Definition: strategy.cpp:58
virtual ~Strategy()
Definition: strategy.cpp:45
Copyright (c) 2011-2015 Regents of the University of California.
Definition: ndn-common.hpp:40
Strategy(Forwarder &forwarder, const Name &name)
construct a strategy instance
Definition: strategy.cpp:35
Name abstraction to represent an absolute name.
Definition: name.hpp:46
#define NFD_LOG_INIT(name)
Definition: logger.hpp:34
void sendNack(shared_ptr< pit::Entry > pitEntry, const Face &outFace, const lp::NackHeader &header)
send Nack to outFace
Definition: strategy.hpp:222
virtual void afterReceiveNack(const Face &inFace, const lp::Nack &nack, shared_ptr< fib::Entry > fibEntry, shared_ptr< pit::Entry > pitEntry)
trigger after Nack is received
Definition: strategy.cpp:64
represents a Data packet
Definition: data.hpp:39
represents a Network NACK header
Definition: nack-header.hpp:52