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()) {
125 return {input.getPrefix(i + 1), input[i].toVersion(), input.getSubName(i + 1)};
128 return {input, ndn::nullopt, PartialName()};
134 BOOST_ASSERT(strategyName.at(-1).isVersion());
136 bool hasVersion = std::any_of(input.rbegin(), input.rend(),
137 [] (
const name::Component& comp) {
return comp.isVersion(); });
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();
202 if (interest.getForwardingHint().empty()) {
204 const fib::Entry& fibEntry = fib.findLongestPrefixMatch(pitEntry);
209 const DelegationList& fh = interest.getForwardingHint();
214 for (
const Delegation& del : fh) {
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);
Strategy(Forwarder &forwarder)
construct a strategy instance
#define NFD_LOG_DEBUG(expression)
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
const FaceTable & getFaceTable() const
void sendNack(const shared_ptr< pit::Entry > &pitEntry, const Face &outFace, const lp::NackHeader &header)
send Nack to outFace
virtual void beforeSatisfyInterest(const shared_ptr< pit::Entry > &pitEntry, const Face &inFace, const Data &data)
trigger before PIT entry is satisfied
static Name makeInstanceName(const Name &input, const Name &strategyName)
construct a strategy instance name
static bool canCreate(const Name &instanceName)
MeasurementsAccessor & getMeasurements()
static bool areSameType(const Name &instanceNameA, const Name &instanceNameB)
const Name & getPrefix() const
Copyright (c) 2014-2015, Regents of the University of California, Arizona Board of Regents...
signal::Signal< FaceTable, Face & > & afterAddFace
contains information about an Interest from an incoming face
virtual void afterReceiveNack(const Face &inFace, const lp::Nack &nack, const shared_ptr< pit::Entry > &pitEntry)
trigger after Nack is received
const Interest & getInterest() const
static unique_ptr< Strategy > create(const Name &instanceName, Forwarder &forwarder)
#define NFD_LOG_INIT(name)
signal::Signal< FaceTable, Face & > & beforeRemoveFace
Declares the global pseudorandom number generator (PRNG) for NFD.
static ParsedInstanceName parseInstanceName(const Name &input)
parse a strategy instance name
#define NFD_LOG_TRACE(expression)
static std::set< Name > listRegistered()
bool isInProducerRegion(const DelegationList &forwardingHint) const
determines whether an Interest has reached a producer region
virtual void beforeExpirePendingInterest(const shared_ptr< pit::Entry > &pitEntry)
trigger before PIT entry expires
NetworkRegionTable & getNetworkRegionTable()
const fib::Entry & lookupFib(const pit::Entry &pitEntry) const
performs a FIB lookup, considering Link object if present