26 #ifndef NFD_DAEMON_FW_STRATEGY_HPP
27 #define NFD_DAEMON_FW_STRATEGY_HPP
32 #include <boost/lexical_cast/try_lexical_convert.hpp>
40 class StrategyParameters;
59 BOOST_ASSERT(strategyName.size() > 1);
60 BOOST_ASSERT(strategyName.at(-1).isVersion());
61 auto r = getRegistry().insert_or_assign(strategyName, [] (
auto&&... args) {
62 return make_unique<S>(std::forward<decltype(args)>(args)...);
64 BOOST_VERIFY(r.second);
82 static unique_ptr<Strategy>
89 areSameType(
const Name& instanceNameA,
const Name& instanceNameB);
94 [[nodiscard]]
static std::set<Name>
161 const shared_ptr<pit::Entry>& pitEntry) = 0;
188 const shared_ptr<pit::Entry>& pitEntry);
214 const shared_ptr<pit::Entry>& pitEntry);
246 const shared_ptr<pit::Entry>& pitEntry);
274 const shared_ptr<pit::Entry>& pitEntry);
303 sendInterest(
const Interest& interest,
Face& egress,
const shared_ptr<pit::Entry>& pitEntry);
313 sendData(
const Data& data,
Face& egress,
const shared_ptr<pit::Entry>& pitEntry);
325 sendDataToAll(
const Data& data,
const shared_ptr<pit::Entry>& pitEntry,
const Face& inFace);
351 sendNack(
const lp::NackHeader& header,
Face& egress,
const shared_ptr<pit::Entry>& pitEntry)
353 return m_forwarder.onOutgoingNack(header, egress, pitEntry);
379 sendNacks(
const lp::NackHeader& header,
const shared_ptr<pit::Entry>& pitEntry,
380 std::initializer_list<const Face*> exceptFaces = {});
386 setExpiryTimer(
const shared_ptr<pit::Entry>& pitEntry, time::milliseconds duration)
388 m_forwarder.setExpiryTimer(pitEntry, duration);
401 return m_measurements;
413 return m_forwarder.m_faceTable;
463 using CreateFunc = std::function<unique_ptr<Strategy>(
Forwarder&,
const Name& )>;
464 using Registry = std::map<Name, CreateFunc>;
469 static Registry::const_iterator
470 find(
const Name& instanceName);
488 std::enable_if_t<std::is_signed_v<T>, T>
497 if (!boost::conversion::try_lexical_convert(it->second, val)) {
498 NDN_THROW(std::invalid_argument(key +
" value is malformed"));
504 std::enable_if_t<std::is_unsigned_v<T>, T>
512 if (it->second.find(
'-') != std::string::npos) {
513 NDN_THROW(std::invalid_argument(key +
" cannot be negative"));
517 if (!boost::conversion::try_lexical_convert(it->second, val)) {
518 NDN_THROW(std::invalid_argument(key +
" value is malformed"));
531 #define NFD_REGISTER_STRATEGY(S) \
532 static class NfdAuto ## S ## StrategyRegistrationClass \
535 NfdAuto ## S ## StrategyRegistrationClass() \
537 ::nfd::fw::Strategy::registerType<S>(); \
539 } g_nfdAuto ## S ## StrategyRegistrationVariable
542 #define NFD_LOG_INTEREST_FROM(interest, ingress, msg) \
543 NFD_LOG_DEBUG("interest=" << (interest).getName() << \
544 " nonce=" << (interest).getNonce() << \
545 " from=" << (ingress) << \
549 #define NFD_LOG_DATA_FROM(data, ingress, msg) \
550 NFD_LOG_DEBUG("data=" << (data).getName() << \
551 " from=" << (ingress) << \
555 #define NFD_LOG_NACK_FROM(nack, ingress, msg) \
556 NFD_LOG_DEBUG("nack=" << (nack).getInterest().getName() << \
557 " nonce=" << (nack).getInterest().getNonce() << \
558 " reason=" << (nack).getReason() << \
559 " from=" << (ingress) << \
Represents a face-endpoint pair in the forwarder.
Face * get(FaceId id) const noexcept
Get face by FaceId.
Main class of NFD's forwarding engine.
Generalization of a network interface.
void sendNack(const lp::Nack &nack)
Send Nack.
Represents an entry in the FIB.
Represents a nexthop record in a FIB entry.
Base class of all forwarding strategies.
virtual void onDroppedInterest(const Interest &interest, Face &egress)
Trigger after an Interest is dropped (e.g., for exceeding allowed retransmissions).
virtual void afterContentStoreHit(const Data &data, const FaceEndpoint &ingress, const shared_ptr< pit::Entry > &pitEntry)
Trigger after a matching Data is found in the Content Store.
virtual void afterReceiveNack(const lp::Nack &nack, const FaceEndpoint &ingress, const shared_ptr< pit::Entry > &pitEntry)
Trigger after a Nack is received.
static void registerType(const Name &strategyName=S::getStrategyName())
Register a strategy type.
const Name & getInstanceName() const noexcept
Returns the strategy's instance name.
Face * getFace(FaceId id) const noexcept
static const Name & getStrategyName()
Returns the strategy's program name.
bool sendNack(const lp::Nack &nack, Face &egress)
Send a Nack packet without going through the outgoing Nack pipeline.
void rejectPendingInterest(const shared_ptr< pit::Entry > &pitEntry)
Schedule the PIT entry for immediate deletion.
const FaceTable & getFaceTable() const noexcept
void sendNacks(const lp::NackHeader &header, const shared_ptr< pit::Entry > &pitEntry, std::initializer_list< const Face * > exceptFaces={})
Send Nack to every face that has an in-record, except those in exceptFaces.
Strategy(Forwarder &forwarder)
Construct a strategy instance.
static bool canCreate(const Name &instanceName)
Returns whether a strategy instance can be created from instanceName.
const fib::Entry & lookupFib(const pit::Entry &pitEntry) const
Performs a FIB lookup, considering Link object if present.
bool sendNack(const lp::NackHeader &header, Face &egress, const shared_ptr< pit::Entry > &pitEntry)
Send a Nack packet.
signal::Signal< FaceTable, Face > & beforeRemoveFace
virtual void afterNewNextHop(const fib::NextHop &nextHop, const shared_ptr< pit::Entry > &pitEntry)
Trigger after a new nexthop is added.
pit::OutRecord * sendInterest(const Interest &interest, Face &egress, const shared_ptr< pit::Entry > &pitEntry)
Send an Interest packet.
bool sendData(const Data &data, Face &egress, const shared_ptr< pit::Entry > &pitEntry)
Send a Data packet.
static ParsedInstanceName parseInstanceName(const Name &input)
Parse a strategy instance name.
MeasurementsAccessor & getMeasurements() noexcept
void setExpiryTimer(const shared_ptr< pit::Entry > &pitEntry, time::milliseconds duration)
Schedule the PIT entry to be erased after duration.
void setInstanceName(const Name &name) noexcept
Set strategy instance name.
void sendDataToAll(const Data &data, const shared_ptr< pit::Entry > &pitEntry, const Face &inFace)
Send a Data packet to all matched and qualified faces.
virtual void onInterestLoop(const Interest &interest, const FaceEndpoint &ingress)
Trigger after an Interest loop is detected.
virtual void afterReceiveInterest(const Interest &interest, const FaceEndpoint &ingress, const shared_ptr< pit::Entry > &pitEntry)=0
Trigger after an Interest is received.
virtual void afterReceiveData(const Data &data, const FaceEndpoint &ingress, const shared_ptr< pit::Entry > &pitEntry)
Trigger after Data is received.
static std::set< Name > listRegistered()
Returns all registered versioned strategy names.
static StrategyParameters parseParameters(const PartialName ¶ms)
Parse strategy parameters encoded in a strategy instance name.
virtual void beforeSatisfyInterest(const Data &data, const FaceEndpoint &ingress, const shared_ptr< pit::Entry > &pitEntry)
Trigger before a PIT entry is satisfied.
signal::Signal< FaceTable, Face > & afterAddFace
static Name makeInstanceName(const Name &input, const Name &strategyName)
Construct a strategy instance name.
static unique_ptr< Strategy > create(const Name &instanceName, Forwarder &forwarder)
Returns a strategy instance created from instanceName.
static bool areSameType(const Name &instanceNameA, const Name &instanceNameB)
Returns whether two names will instantiate the same strategy type.
std::enable_if_t< std::is_signed_v< T >, T > getOrDefault(const key_type &key, const T &defaultVal) const
std::enable_if_t< std::is_unsigned_v< T >, T > getOrDefault(const key_type &key, const T &defaultVal) const
Allows fw::Strategy to access the portion of Measurements table under its namespace.
Represents an entry in the Interest table (PIT).
Contains information about an Interest toward an outgoing face.
#define NFD_PUBLIC_WITH_TESTS_ELSE_PROTECTED
#define NFD_VIRTUAL_WITH_TESTS
uint64_t FaceId
Identifies a face.
std::optional< uint64_t > version
The strategy version number, if present.
Name strategyName
Strategy name without parameters.
PartialName parameters
Parameter components, may be empty.