31 #include <boost/range/adaptor/map.hpp> 32 #include <boost/range/algorithm/copy.hpp> 40 Strategy::getRegistry()
42 static Registry registry;
46 Strategy::Registry::const_iterator
47 Strategy::find(
const Name& instanceName)
49 const Registry& registry = getRegistry();
55 auto found = registry.lower_bound(parsed.strategyName);
56 if (found != registry.end()) {
57 if (parsed.strategyName.getPrefix(-1).isPrefixOf(found->first)) {
58 NFD_LOG_TRACE(
"find " << instanceName <<
" versioned found=" << found->first);
63 NFD_LOG_TRACE(
"find " << instanceName <<
" versioned not-found");
64 return registry.end();
69 if (!parsed.strategyName.empty()) {
70 auto found = registry.lower_bound(parsed.strategyName.getSuccessor());
71 if (found != registry.begin()) {
73 if (parsed.strategyName.isPrefixOf(found->first)) {
74 NFD_LOG_TRACE(
"find " << instanceName <<
" unversioned found=" << found->first);
80 NFD_LOG_TRACE(
"find " << instanceName <<
" unversioned not-found");
81 return registry.end();
87 return Strategy::find(instanceName) != getRegistry().end();
93 auto found = Strategy::find(instanceName);
94 if (found == getRegistry().end()) {
99 unique_ptr<Strategy> instance = found->second(forwarder, instanceName);
100 NFD_LOG_DEBUG(
"create " << instanceName <<
" found=" << found->first <<
101 " created=" << instance->getInstanceName());
102 BOOST_ASSERT(!instance->getInstanceName().empty());
109 return Strategy::find(instanceNameA) == Strategy::find(instanceNameB);
115 std::set<Name> strategyNames;
116 boost::copy(getRegistry() | boost::adaptors::map_keys,
117 std::inserter(strategyNames, strategyNames.end()));
118 return strategyNames;
124 for (ssize_t i = input.
size() - 1; i > 0; --i) {
125 if (input[i].isVersion()) {
137 bool hasVersion = std::any_of(input.
rbegin(), input.
rend(),
139 return hasVersion ? input :
Name(input).append(strategyName.
at(-1));
143 : afterAddFace(forwarder.getFaceTable().afterAdd)
144 , beforeRemoveFace(forwarder.getFaceTable().beforeRemove)
145 , m_forwarder(forwarder)
146 , m_measurements(m_forwarder.getMeasurements(), m_forwarder.getStrategyChoice(), *this)
154 const Face& inFace,
const Data& data)
156 NFD_LOG_DEBUG(
"beforeSatisfyInterest pitEntry=" << pitEntry->getName() <<
157 " inFace=" << inFace.
getId() <<
" data=" << data.
getName());
162 const Face& inFace,
const Data& data)
164 NFD_LOG_DEBUG(
"afterContentStoreHit pitEntry=" << pitEntry->getName() <<
165 " inFace=" << inFace.
getId() <<
" data=" << data.
getName());
167 this->
sendData(pitEntry, data, inFace);
172 const Face& inFace,
const Data& data)
174 NFD_LOG_DEBUG(
"afterReceiveData pitEntry=" << pitEntry->getName() <<
175 " inFace=" << inFace.
getId() <<
" data=" << data.
getName());
184 const shared_ptr<pit::Entry>& pitEntry)
187 " pitEntry=" << pitEntry->getName());
199 BOOST_ASSERT(pitEntry->getInterest().matchesData(data));
203 pitEntry->deleteInRecord(outFace);
205 m_forwarder.onOutgoingData(data, *const_pointer_cast<Face>(outFace.shared_from_this()));
211 std::set<Face*> pendingDownstreams;
215 for (
const pit::InRecord& inRecord : pitEntry->getInRecords()) {
216 if (inRecord.getExpiry() > now) {
217 if (inRecord.getFace().getId() == inFace.
getId() &&
221 pendingDownstreams.insert(&inRecord.getFace());
225 for (
const Face* pendingDownstream : pendingDownstreams) {
226 this->
sendData(pitEntry, data, *pendingDownstream);
232 std::initializer_list<const Face*> exceptFaces)
235 std::unordered_set<const Face*> downstreams;
236 std::transform(pitEntry->in_begin(), pitEntry->in_end(), std::inserter(downstreams, downstreams.end()),
241 for (
const Face* exceptFace : exceptFaces) {
242 downstreams.erase(exceptFace);
246 for (
const Face* downstream : downstreams) {
247 this->
sendNack(pitEntry, *downstream, header);
273 if (fibEntry->hasNextHops()) {
274 if (fibEntry->getPrefix().size() == 0) {
276 NFD_LOG_TRACE(
"lookupFib inConsumerRegion found=" << fibEntry->getPrefix());
280 NFD_LOG_TRACE(
"lookupFib delegation=" << del.name <<
" found=" << fibEntry->getPrefix());
284 BOOST_ASSERT(fibEntry->getPrefix().size() == 0);
286 BOOST_ASSERT(fibEntry !=
nullptr && fibEntry->getPrefix().size() == 0);
Declares the global pseudorandom number generator (PRNG) for NFD.
PartialName getPrefix(ssize_t nComponents) const
Extract a prefix of the name.
const Name & getPrefix() const
static ParsedInstanceName parseInstanceName(const Name &input)
parse a strategy instance name
const Name & getName() const
Get name.
static std::set< Name > listRegistered()
generalization of a network interface
static time_point now() noexcept
void sendNack(const shared_ptr< pit::Entry > &pitEntry, const Face &outFace, const lp::NackHeader &header)
send Nack to outFace
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
contains information about an Interest from an incoming face
virtual void afterContentStoreHit(const shared_ptr< pit::Entry > &pitEntry, const Face &inFace, const Data &data)
trigger after a Data is matched in CS
Strategy(Forwarder &forwarder)
construct a strategy instance
const_reverse_iterator rend() const
Reverse end iterator.
Represents an Interest packet.
const_reverse_iterator rbegin() const
Reverse begin iterator.
const Entry & findLongestPrefixMatch(const Name &prefix) const
performs a longest prefix match
represents a Network Nack
virtual void afterReceiveNack(const Face &inFace, const lp::Nack &nack, const shared_ptr< pit::Entry > &pitEntry)
trigger after Nack is received
const Component & at(ssize_t i) const
Get the component at the given index.
bool isInProducerRegion(const DelegationList &forwardingHint) const
determines whether an Interest has reached a producer region
virtual void onDroppedInterest(const Face &outFace, const Interest &interest)
trigger after Interest dropped for exceeding allowed retransmissions
Copyright (c) 2011-2015 Regents of the University of California.
virtual void afterReceiveData(const shared_ptr< pit::Entry > &pitEntry, const Face &inFace, const Data &data)
trigger after Data is received
represents the Forwarding Information Base (FIB)
Name PartialName
Represents an arbitrary sequence of name components.
virtual void beforeSatisfyInterest(const shared_ptr< pit::Entry > &pitEntry, const Face &inFace, const Data &data)
trigger before PIT entry is satisfied
Represents an absolute name.
const Interest & getInterest() const
size_t size() const
Get number of components.
represents a forwarding strategy
void sendData(const shared_ptr< pit::Entry > &pitEntry, const Data &data, const Face &outFace)
send data to outFace
static unique_ptr< Strategy > create(const Name &instanceName, Forwarder &forwarder)
Represents a name component.
const fib::Entry & lookupFib(const pit::Entry &pitEntry) const
performs a FIB lookup, considering Link object if present
bool empty() const noexcept
NetworkRegionTable & getNetworkRegionTable()
const DelegationList & getForwardingHint() const
represents a list of Delegations
static Name makeInstanceName(const Name &input, const Name &strategyName)
construct a strategy instance name
void sendDataToAll(const shared_ptr< pit::Entry > &pitEntry, const Face &inFace, const Data &data)
send data to all matched and qualified faces
bool isVersion() const
Check if the component is version per NDN naming conventions.
static bool canCreate(const Name &instanceName)
#define NFD_LOG_INIT(name)
Represents a Data packet.
PartialName getSubName(ssize_t iStartComponent, size_t nComponents=npos) const
Extract some components as a sub-name (PartialName)
const nullopt_t nullopt((nullopt_t::init()))
static bool areSameType(const Name &instanceNameA, const Name &instanceNameB)
const Name & getName() const