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)) {
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)) {
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);
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));
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());
162 NFD_LOG_DEBUG(
"beforeExpirePendingInterest pitEntry=" << pitEntry->getName());
167 const shared_ptr<pit::Entry>& pitEntry)
169 NFD_LOG_DEBUG(
"afterReceiveNack inFace=" << inFace.getId() <<
170 " pitEntry=" << pitEntry->getName());
175 std::initializer_list<const Face*> exceptFaces)
178 std::unordered_set<const Face*> downstreams;
179 std::transform(pitEntry->in_begin(), pitEntry->in_end(), std::inserter(downstreams, downstreams.end()),
184 for (
const Face* exceptFace : exceptFaces) {
185 downstreams.erase(exceptFace);
189 for (
const Face* downstream : downstreams) {
190 this->
sendNack(pitEntry, *downstream, header);
198 const Fib& fib = m_forwarder.
getFib();
204 const fib::Entry& fibEntry = fib.findLongestPrefixMatch(pitEntry);
215 fibEntry = &fib.findLongestPrefixMatch(del.name);
216 if (fibEntry->hasNextHops()) {
217 if (fibEntry->getPrefix().size() == 0) {
219 NFD_LOG_TRACE(
"lookupFib inConsumerRegion found=" << fibEntry->getPrefix());
223 NFD_LOG_TRACE(
"lookupFib delegation=" << del.name <<
" found=" << fibEntry->getPrefix());
227 BOOST_ASSERT(fibEntry->getPrefix().size() == 0);
229 BOOST_ASSERT(fibEntry !=
nullptr && fibEntry->getPrefix().size() == 0);
constexpr nullopt_t nullopt
Declares the global pseudorandom number generator (PRNG) for NFD.
signal::Signal< FaceTable, Face & > & afterAddFace
static ParsedInstanceName parseInstanceName(const Name &input)
parse a strategy instance name
static std::set< Name > listRegistered()
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
const FaceTable & getFaceTable() const
Strategy(Forwarder &forwarder)
construct a strategy instance
virtual void beforeExpirePendingInterest(const shared_ptr< pit::Entry > &pitEntry)
trigger before PIT entry expires
represents an Interest packet
#define NFD_LOG_DEBUG(expression)
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
#define NFD_LOG_TRACE(expression)
bool isVersion() const
Check if the component is version per NDN naming conventions.
Copyright (c) 2011-2015 Regents of the University of California.
const_reverse_iterator rend() const
Reverse end iterator.
MeasurementsAccessor & getMeasurements()
const Interest & getInterest() const
Name PartialName
Represents an arbitrary sequence of name components.
const fib::Entry & lookupFib(const pit::Entry &pitEntry) const
performs a FIB lookup, considering Link object if present
size_t size() const
Get number of 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.
signal::Signal< FaceTable, Face & > & beforeRemoveFace
const Component & at(ssize_t i) const
Get the component at the given index.
const_reverse_iterator rbegin() const
Reverse begin iterator.
const DelegationList & getForwardingHint() const
const Name & getName() const
Get name.
static unique_ptr< Strategy > create(const Name &instanceName, Forwarder &forwarder)
Component holds a read-only name component value.
bool empty() const noexcept
NetworkRegionTable & getNetworkRegionTable()
represents a list of Delegations
static Name makeInstanceName(const Name &input, const Name &strategyName)
construct a strategy instance name
PartialName getSubName(ssize_t iStartComponent, size_t nComponents=npos) const
Extract some components as a sub-name (PartialName)
PartialName getPrefix(ssize_t nComponents) const
Extract a prefix of the name.
static bool canCreate(const Name &instanceName)
#define NFD_LOG_INIT(name)
Represents a Data packet.
bool isInProducerRegion(const DelegationList &forwardingHint) const
determines whether an Interest has reached a producer region
const Name & getPrefix() const
static bool areSameType(const Name &instanceNameA, const Name &instanceNameB)