30 #include <boost/range/adaptor/map.hpp> 31 #include <boost/range/algorithm/copy.hpp> 39 Strategy::getRegistry()
41 static Registry registry;
45 Strategy::Registry::const_iterator
46 Strategy::find(
const Name& instanceName)
48 const Registry& registry = getRegistry();
54 auto found = registry.lower_bound(parsed.strategyName);
55 if (found != registry.end()) {
56 if (parsed.strategyName.getPrefix(-1).isPrefixOf(found->first)) {
57 NFD_LOG_TRACE(
"find " << instanceName <<
" versioned found=" << found->first);
62 NFD_LOG_TRACE(
"find " << instanceName <<
" versioned not-found");
63 return registry.end();
68 if (!parsed.strategyName.empty()) {
69 auto found = registry.lower_bound(parsed.strategyName.getSuccessor());
70 if (found != registry.begin()) {
72 if (parsed.strategyName.isPrefixOf(found->first)) {
73 NFD_LOG_TRACE(
"find " << instanceName <<
" unversioned found=" << found->first);
79 NFD_LOG_TRACE(
"find " << instanceName <<
" unversioned not-found");
80 return registry.end();
86 return Strategy::find(instanceName) != getRegistry().end();
92 auto found = Strategy::find(instanceName);
93 if (found == getRegistry().end()) {
98 unique_ptr<Strategy> instance = found->second(forwarder, instanceName);
99 NFD_LOG_DEBUG(
"create " << instanceName <<
" found=" << found->first <<
100 " created=" << instance->getInstanceName());
101 BOOST_ASSERT(!instance->getInstanceName().empty());
108 return Strategy::find(instanceNameA) == Strategy::find(instanceNameB);
114 std::set<Name> strategyNames;
115 boost::copy(getRegistry() | boost::adaptors::map_keys,
116 std::inserter(strategyNames, strategyNames.end()));
117 return strategyNames;
123 for (ssize_t i = input.
size() - 1; i > 0; --i) {
124 if (input[i].isVersion()) {
136 bool hasVersion = std::any_of(input.
rbegin(), input.
rend(),
138 return hasVersion ? input :
Name(input).append(strategyName.
at(-1));
142 : afterAddFace(forwarder.getFaceTable().afterAdd)
143 , beforeRemoveFace(forwarder.getFaceTable().beforeRemove)
144 , m_forwarder(forwarder)
145 , m_measurements(m_forwarder.getMeasurements(), m_forwarder.getStrategyChoice(), *this)
153 const Face& inFace,
const Data& data)
155 NFD_LOG_DEBUG(
"beforeSatisfyInterest pitEntry=" << pitEntry->getName() <<
156 " inFace=" << inFace.
getId() <<
" data=" << data.
getName());
161 const Face& inFace,
const Data& data)
163 NFD_LOG_DEBUG(
"afterContentStoreHit pitEntry=" << pitEntry->getName() <<
164 " inFace=" << inFace.
getId() <<
" data=" << data.
getName());
166 this->
sendData(pitEntry, data, inFace);
171 const Face& inFace,
const Data& data)
173 NFD_LOG_DEBUG(
"afterReceiveData pitEntry=" << pitEntry->getName() <<
174 " inFace=" << inFace.
getId() <<
" data=" << data.
getName());
183 const shared_ptr<pit::Entry>& pitEntry)
186 " pitEntry=" << pitEntry->getName());
198 BOOST_ASSERT(pitEntry->getInterest().matchesData(data));
202 pitEntry->deleteInRecord(outFace);
204 m_forwarder.onOutgoingData(data, *const_pointer_cast<Face>(outFace.shared_from_this()));
210 std::set<Face*> pendingDownstreams;
214 for (
const pit::InRecord& inRecord : pitEntry->getInRecords()) {
215 if (inRecord.getExpiry() > now) {
216 if (inRecord.getFace().getId() == inFace.
getId() &&
220 pendingDownstreams.insert(&inRecord.getFace());
224 for (
const Face* pendingDownstream : pendingDownstreams) {
225 this->
sendData(pitEntry, data, *pendingDownstream);
231 std::initializer_list<const Face*> exceptFaces)
234 std::unordered_set<const Face*> downstreams;
235 std::transform(pitEntry->in_begin(), pitEntry->in_end(), std::inserter(downstreams, downstreams.end()),
240 for (
const Face* exceptFace : exceptFaces) {
241 downstreams.erase(exceptFace);
245 for (
const Face* downstream : downstreams) {
246 this->
sendNack(pitEntry, *downstream, header);
272 if (fibEntry->hasNextHops()) {
273 if (fibEntry->getPrefix().size() == 0) {
275 NFD_LOG_TRACE(
"lookupFib inConsumerRegion found=" << fibEntry->getPrefix());
279 NFD_LOG_TRACE(
"lookupFib delegation=" << del.name <<
" found=" << fibEntry->getPrefix());
283 BOOST_ASSERT(fibEntry->getPrefix().size() == 0);
285 BOOST_ASSERT(fibEntry !=
nullptr && fibEntry->getPrefix().size() == 0);
constexpr nullopt_t nullopt
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
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.
#define NFD_LOG_DEBUG(expression)
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
#define NFD_LOG_TRACE(expression)
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.
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
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)
static bool areSameType(const Name &instanceNameA, const Name &instanceNameB)
const Name & getName() const