30 #include <ndn-cxx/lp/pit-token.hpp> 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)) {
59 NFD_LOG_TRACE(
"find " << instanceName <<
" versioned found=" << 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)) {
75 NFD_LOG_TRACE(
"find " << instanceName <<
" unversioned found=" << 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);
101 NFD_LOG_DEBUG(
"create " << instanceName <<
" found=" << found->first
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()) {
127 return {input.getPrefix(i + 1), input[i].toVersion(), input.getSubName(i + 1)};
130 return {input, nullopt, PartialName()};
136 BOOST_ASSERT(strategyName.at(-1).isVersion());
138 bool hasVersion = std::any_of(input.rbegin(), input.rend(),
139 [] (
const name::Component& 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)
157 NFD_LOG_DEBUG(
"beforeSatisfyInterest pitEntry=" << pitEntry->getName()
158 <<
" in=" << ingress <<
" data=" << data.getName());
165 NFD_LOG_DEBUG(
"afterContentStoreHit pitEntry=" << pitEntry->getName()
166 <<
" in=" << ingress <<
" data=" << data.getName());
168 this->
sendData(pitEntry, data, ingress);
175 NFD_LOG_DEBUG(
"afterReceiveData pitEntry=" << pitEntry->getName()
176 <<
" in=" << ingress <<
" data=" << data.getName());
185 const shared_ptr<pit::Entry>& pitEntry)
187 NFD_LOG_DEBUG(
"afterReceiveNack in=" << ingress <<
" pitEntry=" << pitEntry->getName());
193 NFD_LOG_DEBUG(
"onDroppedInterest out=" << egress <<
" name=" << interest.getName());
200 if (interest.getTag<lp::PitToken>() !=
nullptr) {
201 Interest interest2 = interest;
202 interest2.removeTag<lp::PitToken>();
203 m_forwarder.onOutgoingInterest(pitEntry, egress, interest2);
206 m_forwarder.onOutgoingInterest(pitEntry, egress, interest);
212 NFD_LOG_DEBUG(
"afterNewNextHop pitEntry=" << pitEntry->getName()
220 BOOST_ASSERT(pitEntry->getInterest().matchesData(data));
222 shared_ptr<lp::PitToken> pitToken;
223 auto inRecord = pitEntry->getInRecord(egress.
face);
224 if (inRecord != pitEntry->in_end()) {
225 pitToken = inRecord->getInterest().getTag<lp::PitToken>();
230 pitEntry->deleteInRecord(egress.
face);
232 if (pitToken !=
nullptr) {
234 data2.setTag(pitToken);
235 m_forwarder.onOutgoingData(data2, egress);
238 m_forwarder.onOutgoingData(data, egress);
245 std::set<Face*> pendingDownstreams;
246 auto now = time::steady_clock::now();
249 for (
const pit::InRecord& inRecord : pitEntry->getInRecords()) {
250 if (inRecord.getExpiry() > now) {
251 if (inRecord.getFace().getId() == ingress.
face.
getId() &&
252 inRecord.getFace().getLinkType() != ndn::nfd::LINK_TYPE_AD_HOC) {
255 pendingDownstreams.emplace(&inRecord.getFace());
259 for (
const auto& pendingDownstream : pendingDownstreams) {
266 std::initializer_list<FaceEndpoint> exceptFaceEndpoints)
269 std::set<Face*> downstreams;
270 std::transform(pitEntry->in_begin(), pitEntry->in_end(), std::inserter(downstreams, downstreams.end()),
276 for (
const auto& exceptFaceEndpoint : exceptFaceEndpoints) {
277 downstreams.erase(&exceptFaceEndpoint.face);
281 for (
const auto& downstream : downstreams) {
294 if (interest.getForwardingHint().empty()) {
301 const DelegationList& fh = interest.getForwardingHint();
306 for (
const Delegation& del : fh) {
308 if (fibEntry->hasNextHops()) {
309 if (fibEntry->getPrefix().size() == 0) {
311 NFD_LOG_TRACE(
"lookupFib inConsumerRegion found=" << fibEntry->getPrefix());
315 NFD_LOG_TRACE(
"lookupFib delegation=" << del.name <<
" found=" << fibEntry->getPrefix());
319 BOOST_ASSERT(fibEntry->getPrefix().size() == 0);
321 BOOST_ASSERT(fibEntry !=
nullptr && fibEntry->getPrefix().size() == 0);
virtual void afterNewNextHop(const fib::NextHop &nextHop, const shared_ptr< pit::Entry > &pitEntry)
trigger after new nexthop is added
Main class of NFD's forwarding engine.
Strategy(Forwarder &forwarder)
Construct a strategy instance.
void sendNack(const shared_ptr< pit::Entry > &pitEntry, const FaceEndpoint &egress, const lp::NackHeader &header)
send Nack to egress
signal::Signal< FaceTable, Face > & beforeRemoveFace
void sendDataToAll(const shared_ptr< pit::Entry > &pitEntry, const FaceEndpoint &ingress, const Data &data)
send data to all matched and qualified face-endpoint pairs
static Name makeInstanceName(const Name &input, const Name &strategyName)
construct a strategy instance name
static bool canCreate(const Name &instanceName)
bool isInProducerRegion(const DelegationList &forwardingHint) const
determines whether an Interest has reached a producer region
Represents the Forwarding Information Base (FIB)
const fib::Entry & lookupFib(const pit::Entry &pitEntry) const
performs a FIB lookup, considering Link object if present
MeasurementsAccessor & getMeasurements()
virtual void afterReceiveNack(const FaceEndpoint &ingress, const lp::Nack &nack, const shared_ptr< pit::Entry > &pitEntry)
trigger after Nack is received
void sendInterest(const shared_ptr< pit::Entry > &pitEntry, const FaceEndpoint &egress, const Interest &interest)
send Interest to egress
static bool areSameType(const Name &instanceNameA, const Name &instanceNameB)
const Interest & getInterest() const
Represents a face-endpoint pair in the forwarder.
Copyright (c) 2014-2015, Regents of the University of California, Arizona Board of Regents...
Contains information about an Interest from an incoming face.
const Name & getPrefix() const
const Entry & findLongestPrefixMatch(const Name &prefix) const
Performs a longest prefix match.
static unique_ptr< Strategy > create(const Name &instanceName, Forwarder &forwarder)
virtual void afterContentStoreHit(const shared_ptr< pit::Entry > &pitEntry, const FaceEndpoint &ingress, const Data &data)
trigger after a Data is matched in CS
void sendData(const shared_ptr< pit::Entry > &pitEntry, const Data &data, const FaceEndpoint &egress)
send data to egress
#define NFD_LOG_INIT(name)
virtual void afterReceiveData(const shared_ptr< pit::Entry > &pitEntry, const FaceEndpoint &ingress, const Data &data)
trigger after Data is received
static ParsedInstanceName parseInstanceName(const Name &input)
parse a strategy instance name
static std::set< Name > listRegistered()
signal::Signal< FaceTable, Face > & afterAddFace
Represents a nexthop record in a FIB entry.
void sendNacks(const shared_ptr< pit::Entry > &pitEntry, const lp::NackHeader &header, std::initializer_list< FaceEndpoint > exceptFaceEndpoints={})
send Nack to every face-endpoint pair that has an in-record, except those in exceptFaceEndpoints ...
virtual void onDroppedInterest(const FaceEndpoint &egress, const Interest &interest)
trigger after Interest dropped for exceeding allowed retransmissions
virtual void beforeSatisfyInterest(const shared_ptr< pit::Entry > &pitEntry, const FaceEndpoint &ingress, const Data &data)
trigger before PIT entry is satisfied
NetworkRegionTable & getNetworkRegionTable()