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());
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.
getId() <<
" name=" << interest.getName());
199 if (interest.getTag<lp::PitToken>() !=
nullptr) {
200 Interest interest2 = interest;
201 interest2.removeTag<lp::PitToken>();
202 return m_forwarder.onOutgoingInterest(pitEntry, egress, interest2);
204 return m_forwarder.onOutgoingInterest(pitEntry, egress, interest);
210 NFD_LOG_DEBUG(
"afterNewNextHop pitEntry=" << pitEntry->getName()
217 BOOST_ASSERT(pitEntry->getInterest().matchesData(data));
219 shared_ptr<lp::PitToken> pitToken;
220 auto inRecord = pitEntry->getInRecord(egress);
221 if (inRecord != pitEntry->in_end()) {
222 pitToken = inRecord->getInterest().getTag<lp::PitToken>();
227 pitEntry->deleteInRecord(egress);
229 if (pitToken !=
nullptr) {
231 data2.setTag(pitToken);
232 return m_forwarder.onOutgoingData(data2, egress);
234 return m_forwarder.onOutgoingData(data, egress);
239 const Face& inFace,
const Data& data)
241 std::set<Face*> pendingDownstreams;
242 auto now = time::steady_clock::now();
245 for (
const pit::InRecord& inRecord : pitEntry->getInRecords()) {
246 if (inRecord.getExpiry() > now) {
247 if (inRecord.getFace().getId() == inFace.
getId() &&
248 inRecord.getFace().getLinkType() != ndn::nfd::LINK_TYPE_AD_HOC) {
251 pendingDownstreams.emplace(&inRecord.getFace());
255 for (
const auto& pendingDownstream : pendingDownstreams) {
256 this->
sendData(pitEntry, data, *pendingDownstream);
262 std::initializer_list<const Face*> exceptFaces)
265 std::unordered_set<Face*> downstreams;
266 std::transform(pitEntry->in_begin(), pitEntry->in_end(), std::inserter(downstreams, downstreams.end()),
270 for (
auto exceptFace : exceptFaces) {
271 downstreams.erase(const_cast<Face*>(exceptFace));
275 for (
auto downstream : downstreams) {
276 this->
sendNack(pitEntry, *downstream, header);
288 if (interest.getForwardingHint().empty()) {
295 const DelegationList& fh = interest.getForwardingHint();
300 for (
const Delegation& del : fh) {
302 if (fibEntry->hasNextHops()) {
303 if (fibEntry->getPrefix().size() == 0) {
305 NFD_LOG_TRACE(
"lookupFib inConsumerRegion found=" << fibEntry->getPrefix());
309 NFD_LOG_TRACE(
"lookupFib delegation=" << del.name <<
" found=" << fibEntry->getPrefix());
313 BOOST_ASSERT(fibEntry->getPrefix().size() == 0);
315 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.
bool sendNack(const shared_ptr< pit::Entry > &pitEntry, Face &egress, const lp::NackHeader &header)
Send a Nack packet.
Contains information about an Interest toward an outgoing face.
bool sendData(const shared_ptr< pit::Entry > &pitEntry, const Data &data, Face &egress)
Send a Data packet.
signal::Signal< FaceTable, Face > & beforeRemoveFace
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.
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...
virtual void onDroppedInterest(const Face &egress, const Interest &interest)
Trigger after Interest dropped (e.g., for exceeding allowed retransmissions)
Contains information about an Interest from an incoming face.
const Name & getPrefix() const
void sendDataToAll(const shared_ptr< pit::Entry > &pitEntry, const Face &inFace, const Data &data)
Send a Data packet to all matched and qualified faces.
const Entry & findLongestPrefixMatch(const Name &prefix) const
Performs a longest prefix match.
generalization of a network interface
void sendNacks(const shared_ptr< pit::Entry > &pitEntry, const lp::NackHeader &header, std::initializer_list< const Face *> exceptFaces={})
Send Nack to every face that has an in-record, except those in exceptFaces.
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.
#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.
virtual void beforeSatisfyInterest(const shared_ptr< pit::Entry > &pitEntry, const FaceEndpoint &ingress, const Data &data)
Trigger before PIT entry is satisfied.
NetworkRegionTable & getNetworkRegionTable()
pit::OutRecord * sendInterest(const shared_ptr< pit::Entry > &pitEntry, Face &egress, const Interest &interest)
Send an Interest packet.