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, 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)
155 NFD_LOG_DEBUG(
"beforeSatisfyInterest pitEntry=" << pitEntry->getName()
156 <<
" in=" << ingress <<
" data=" << data.getName());
163 NFD_LOG_DEBUG(
"afterContentStoreHit pitEntry=" << pitEntry->getName()
164 <<
" in=" << ingress <<
" data=" << data.getName());
166 this->
sendData(pitEntry, data, ingress);
173 NFD_LOG_DEBUG(
"afterReceiveData pitEntry=" << pitEntry->getName()
174 <<
" in=" << ingress <<
" data=" << data.getName());
183 const shared_ptr<pit::Entry>& pitEntry)
185 NFD_LOG_DEBUG(
"afterReceiveNack in=" << ingress <<
" pitEntry=" << pitEntry->getName());
191 NFD_LOG_DEBUG(
"onDroppedInterest out=" << egress <<
" name=" << interest.getName());
198 BOOST_ASSERT(pitEntry->getInterest().matchesData(data));
204 m_forwarder.onOutgoingData(data, egress);
211 std::set<std::pair<Face*, EndpointId>> pendingDownstreams;
212 auto now = time::steady_clock::now();
215 for (
const pit::InRecord& inRecord : pitEntry->getInRecords()) {
216 if (inRecord.getExpiry() > now) {
217 if (inRecord.getFace().getId() == ingress.
face.getId() &&
218 inRecord.getEndpointId() == ingress.
endpoint &&
219 inRecord.getFace().getLinkType() != ndn::nfd::LINK_TYPE_AD_HOC) {
222 pendingDownstreams.emplace(&inRecord.getFace(), inRecord.getEndpointId());
226 for (
const auto& pendingDownstream : pendingDownstreams) {
227 this->
sendData(pitEntry, data,
FaceEndpoint(*pendingDownstream.first, pendingDownstream.second));
233 std::initializer_list<FaceEndpoint> exceptFaceEndpoints)
236 std::set<std::pair<Face*, EndpointId>> downstreams;
237 std::transform(pitEntry->in_begin(), pitEntry->in_end(), std::inserter(downstreams, downstreams.end()),
243 for (
const auto& exceptFaceEndpoint : exceptFaceEndpoints) {
244 downstreams.erase({&exceptFaceEndpoint.face, exceptFaceEndpoint.endpoint});
248 for (
const auto& downstream : downstreams) {
257 const Fib& fib = m_forwarder.
getFib();
261 if (interest.getForwardingHint().empty()) {
263 const fib::Entry& fibEntry = fib.findLongestPrefixMatch(pitEntry);
268 const DelegationList& fh = interest.getForwardingHint();
273 for (
const Delegation& del : fh) {
274 fibEntry = &fib.findLongestPrefixMatch(del.name);
275 if (fibEntry->hasNextHops()) {
276 if (fibEntry->getPrefix().size() == 0) {
278 NFD_LOG_TRACE(
"lookupFib inConsumerRegion found=" << fibEntry->getPrefix());
282 NFD_LOG_TRACE(
"lookupFib delegation=" << del.name <<
" found=" << fibEntry->getPrefix());
286 BOOST_ASSERT(fibEntry->getPrefix().size() == 0);
288 BOOST_ASSERT(fibEntry !=
nullptr && fibEntry->getPrefix().size() == 0);
const EndpointId endpoint
Main class of NFD forwarding engine.
Strategy(Forwarder &forwarder)
Construct a strategy instance.
const FaceTable & getFaceTable() const
void sendNack(const shared_ptr< pit::Entry > &pitEntry, const FaceEndpoint &egress, const lp::NackHeader &header)
send Nack to egress
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)
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 Name & getPrefix() const
Represents a face-endpoint pair in the forwarder.
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.
const Interest & getInterest() const
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)
signal::Signal< FaceTable, Face & > & beforeRemoveFace
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()
EndpointId getEndpointId() const
bool isInProducerRegion(const DelegationList &forwardingHint) const
determines whether an Interest has reached a producer region
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()
const fib::Entry & lookupFib(const pit::Entry &pitEntry) const
performs a FIB lookup, considering Link object if present