32 #include <boost/range/adaptor/map.hpp> 33 #include <boost/range/algorithm/copy.hpp> 41 Strategy::getRegistry()
43 static Registry registry;
47 Strategy::Registry::const_iterator
48 Strategy::find(
const Name& instanceName)
50 const Registry& registry = getRegistry();
56 auto found = registry.lower_bound(parsed.strategyName);
57 if (
found != registry.end()) {
58 if (parsed.strategyName.getPrefix(-1).isPrefixOf(
found->first)) {
64 NFD_LOG_TRACE(
"find " << instanceName <<
" versioned not-found");
65 return registry.end();
70 if (!parsed.strategyName.empty()) {
71 auto found = registry.lower_bound(parsed.strategyName.getSuccessor());
72 if (
found != registry.begin()) {
74 if (parsed.strategyName.isPrefixOf(
found->first)) {
81 NFD_LOG_TRACE(
"find " << instanceName <<
" unversioned not-found");
82 return registry.end();
88 return Strategy::find(instanceName) != getRegistry().end();
94 auto found = Strategy::find(instanceName);
95 if (
found == getRegistry().end()) {
100 unique_ptr<Strategy> instance =
found->second(forwarder, instanceName);
102 <<
" created=" << instance->getInstanceName());
103 BOOST_ASSERT(!instance->getInstanceName().empty());
110 return Strategy::find(instanceNameA) == Strategy::find(instanceNameB);
116 std::set<Name> strategyNames;
117 boost::copy(getRegistry() | boost::adaptors::map_keys,
118 std::inserter(strategyNames, strategyNames.end()));
119 return strategyNames;
125 for (ssize_t i = input.
size() - 1; i > 0; --i) {
126 if (input[i].isVersion()) {
138 bool hasVersion = std::any_of(input.
rbegin(), input.
rend(),
139 [] (
const auto& comp) {
return comp.isVersion(); });
140 return hasVersion ? input :
Name(input).append(strategyName.
at(-1));
146 , m_forwarder(forwarder)
147 , m_measurements(m_forwarder.
getMeasurements(), m_forwarder.getStrategyChoice(), *this)
159 <<
" in=" << ingress);
164 const shared_ptr<pit::Entry>& pitEntry)
166 NFD_LOG_DEBUG(
"beforeSatisfyInterest pitEntry=" << pitEntry->getName()
167 <<
" in=" << ingress <<
" data=" << data.
getName());
173 std::set<std::pair<Face*, EndpointId>>& satisfiedDownstreams,
174 std::set<std::pair<Face*, EndpointId>>& unsatisfiedDownstreams)
176 NFD_LOG_DEBUG(
"satisfyInterest pitEntry=" << pitEntry->getName()
177 <<
" in=" << ingress <<
" data=" << data.
getName());
179 NFD_LOG_DEBUG(
"onIncomingData matching=" << pitEntry->getName());
184 for (
const pit::InRecord& inRecord : pitEntry->getInRecords()) {
185 if (inRecord.getExpiry() > now) {
186 satisfiedDownstreams.emplace(&inRecord.getFace(), 0);
197 const shared_ptr<pit::Entry>& pitEntry)
199 NFD_LOG_DEBUG(
"afterContentStoreHit pitEntry=" << pitEntry->getName()
200 <<
" in=" << ingress <<
" data=" << data.
getName());
207 const shared_ptr<pit::Entry>& pitEntry)
209 NFD_LOG_DEBUG(
"afterReceiveData pitEntry=" << pitEntry->getName()
210 <<
" in=" << ingress <<
" data=" << data.
getName());
218 const shared_ptr<pit::Entry>& pitEntry)
220 NFD_LOG_DEBUG(
"afterReceiveNack in=" << ingress <<
" pitEntry=" << pitEntry->getName());
232 NFD_LOG_DEBUG(
"afterNewNextHop pitEntry=" << pitEntry->getName()
233 <<
" nexthop=" << nextHop.
getFace().getId());
250 BOOST_ASSERT(pitEntry->getInterest().matchesData(data));
252 shared_ptr<lp::PitToken> pitToken;
253 auto inRecord = pitEntry->getInRecord(egress);
254 if (inRecord != pitEntry->in_end()) {
255 pitToken = inRecord->getInterest().getTag<
lp::PitToken>();
260 pitEntry->deleteInRecord(egress);
262 if (pitToken !=
nullptr) {
269 if (pitEntry->getInRecords().empty()) {
271 m_forwarder.setExpiryTimer(pitEntry, 0_ms);
274 pitEntry->isSatisfied =
true;
281 std::set<Face*> pendingDownstreams;
285 for (
const auto& inRecord : pitEntry->getInRecords()) {
286 if (inRecord.getExpiry() > now) {
287 if (inRecord.getFace().getId() == inFace.getId() &&
291 pendingDownstreams.emplace(&inRecord.getFace());
295 for (
const auto& pendingDownstream : pendingDownstreams) {
296 this->
sendData(data, *pendingDownstream, pitEntry);
299 pitEntry->clearInRecords();
302 m_forwarder.setExpiryTimer(pitEntry, 0_ms);
305 pitEntry->isSatisfied =
true;
310 std::initializer_list<const Face*> exceptFaces)
313 std::unordered_set<Face*> downstreams;
314 std::transform(pitEntry->in_begin(), pitEntry->in_end(),
315 std::inserter(downstreams, downstreams.end()),
316 [] (
const auto& inR) {
return &inR.getFace(); });
319 for (
auto exceptFace : exceptFaces) {
320 downstreams.erase(const_cast<Face*>(exceptFace));
324 for (
auto downstream : downstreams) {
325 this->
sendNack(header, *downstream, pitEntry);
349 for (
const auto& delegation : fh) {
351 if (fibEntry->hasNextHops()) {
352 if (fibEntry->getPrefix().size() == 0) {
354 NFD_LOG_TRACE(
"lookupFib inConsumerRegion found=" << fibEntry->getPrefix());
358 NFD_LOG_TRACE(
"lookupFib delegation=" << delegation <<
" found=" << fibEntry->getPrefix());
362 BOOST_ASSERT(fibEntry->getPrefix().size() == 0);
364 BOOST_ASSERT(fibEntry !=
nullptr && fibEntry->getPrefix().size() == 0);
virtual void satisfyInterest(const shared_ptr< pit::Entry > &pitEntry, const FaceEndpoint &ingress, const Data &data, std::set< std::pair< Face *, EndpointId >> &satisfiedDownstreams, std::set< std::pair< Face *, EndpointId >> &unsatisfiedDownstreams)
void setTag(shared_ptr< T > tag) const
set a tag item
PartialName getPrefix(ssize_t nComponents) const
Returns a prefix of the name.
virtual void afterNewNextHop(const fib::NextHop &nextHop, const shared_ptr< pit::Entry > &pitEntry)
Trigger after a new nexthop is added.
const Name & getPrefix() const
signal::Signal< FaceTable, Face > & beforeRemoveFace
static ParsedInstanceName parseInstanceName(const Name &input)
Parse a strategy instance name.
shared_ptr< T > getTag() const
get a tag item
void removeTag() const
remove tag item
#define NFD_LOG_INIT(name)
static std::set< Name > listRegistered()
span< const Name > getForwardingHint() const noexcept
void sendNacks(const lp::NackHeader &header, const shared_ptr< pit::Entry > &pitEntry, std::initializer_list< const Face *> exceptFaces={})
Send Nack to every face that has an in-record, except those in exceptFaces.
Represents a face-endpoint pair in the forwarder.
static time_point now() noexcept
Contains information about an Interest from an incoming face.
Strategy(Forwarder &forwarder)
Construct a strategy instance.
const_reverse_iterator rend() const
Reverse end iterator.
Main class of NFD's forwarding engine.
Represents an Interest packet.
const_reverse_iterator rbegin() const
Reverse begin iterator.
NFD_VIRTUAL_WITH_TESTS bool sendData(const Data &data, Face &egress, const shared_ptr< pit::Entry > &pitEntry)
Send a Data packet.
const Entry & findLongestPrefixMatch(const Name &prefix) const
Performs a longest prefix match.
NFD_VIRTUAL_WITH_TESTS pit::OutRecord * onOutgoingInterest(const Interest &interest, Face &egress, const shared_ptr< pit::Entry > &pitEntry)
outgoing Interest pipeline
virtual void afterContentStoreHit(const Data &data, const FaceEndpoint &ingress, const shared_ptr< pit::Entry > &pitEntry)
trigger after a Data is matched in CS
bool isInProducerRegion(span< const Name > forwardingHint) const
determines whether an Interest has reached a producer region
represents a Network Nack
virtual void afterReceiveLoopedInterest(const FaceEndpoint &ingress, const Interest &interest, pit::Entry &pitEntry)
trigger after a looped Interest is received
const Component & at(ssize_t i) const
Returns an immutable reference to the component at the specified index, with bounds checking...
NFD_VIRTUAL_WITH_TESTS bool onOutgoingData(const Data &data, Face &egress)
outgoing Data pipeline
NFD_VIRTUAL_WITH_TESTS void sendDataToAll(const Data &data, const shared_ptr< pit::Entry > &pitEntry, const Face &inFace)
Send a Data packet to all matched and qualified faces.
Copyright (c) 2011-2015 Regents of the University of California.
MeasurementsAccessor & getMeasurements()
Represents the Forwarding Information Base (FIB)
Name PartialName
Represents an arbitrary sequence of name components.
virtual void afterReceiveNack(const lp::Nack &nack, const FaceEndpoint &ingress, const shared_ptr< pit::Entry > &pitEntry)
Trigger after a Nack is received.
const Name & getName() const noexcept
Get name.
Represents an absolute name.
NFD_VIRTUAL_WITH_TESTS bool sendNack(const lp::NackHeader &header, Face &egress, const shared_ptr< pit::Entry > &pitEntry)
Send a Nack packet.
const Interest & getInterest() const
size_t size() const
Returns the number of components.
Represents a forwarding strategy.
static unique_ptr< Strategy > create(const Name &instanceName, Forwarder &forwarder)
const fib::Entry & lookupFib(const pit::Entry &pitEntry) const
Performs a FIB lookup, considering Link object if present.
signal::Signal< FaceTable, Face > & afterAddFace
const Name & getName() const noexcept
const Name & getName() const
NetworkRegionTable & getNetworkRegionTable()
Contains information about an Interest toward an outgoing face.
static Name makeInstanceName(const Name &input, const Name &strategyName)
Construct a strategy instance name.
bool isVersion() const
Check if the component is a version per NDN naming conventions.
static bool canCreate(const Name &instanceName)
NFD_VIRTUAL_WITH_TESTS pit::OutRecord * sendInterest(const Interest &interest, Face &egress, const shared_ptr< pit::Entry > &pitEntry)
Send an Interest packet.
Represents a Data packet.
virtual void onDroppedInterest(const Interest &interest, Face &egress)
Trigger after an Interest is dropped (e.g., for exceeding allowed retransmissions).
PartialName getSubName(ssize_t iStartComponent, size_t nComponents=npos) const
Extracts some components as a sub-name (PartialName).
const nullopt_t nullopt((nullopt_t::init()))
virtual void beforeSatisfyInterest(const Data &data, const FaceEndpoint &ingress, const shared_ptr< pit::Entry > &pitEntry)
trigger before PIT entry is satisfied
static bool areSameType(const Name &instanceNameA, const Name &instanceNameB)
virtual void afterReceiveData(const Data &data, const FaceEndpoint &ingress, const shared_ptr< pit::Entry > &pitEntry)
trigger after Data is received
represent a PIT token field
Represents a nexthop record in a FIB entry.