26 #ifndef NFD_DAEMON_FW_STRATEGY_HPP
27 #define NFD_DAEMON_FW_STRATEGY_HPP
32 #include <boost/lexical_cast/try_lexical_convert.hpp>
36 class StrategyParameters;
55 BOOST_ASSERT(strategyName.size() > 1);
56 BOOST_ASSERT(strategyName.at(-1).isVersion());
57 auto r = getRegistry().insert_or_assign(strategyName, [] (
auto&&... args) {
58 return make_unique<S>(std::forward<decltype(args)>(args)...);
60 BOOST_VERIFY(r.second);
78 static unique_ptr<Strategy>
85 areSameType(
const Name& instanceNameA,
const Name& instanceNameB);
90 [[nodiscard]]
static std::set<Name>
157 const shared_ptr<pit::Entry>& pitEntry) = 0;
170 const shared_ptr<pit::Entry>& pitEntry);
196 const shared_ptr<pit::Entry>& pitEntry);
228 const shared_ptr<pit::Entry>& pitEntry);
256 const shared_ptr<pit::Entry>& pitEntry);
285 sendInterest(
const Interest& interest,
Face& egress,
const shared_ptr<pit::Entry>& pitEntry);
295 sendData(
const Data& data,
Face& egress,
const shared_ptr<pit::Entry>& pitEntry);
307 sendDataToAll(
const Data& data,
const shared_ptr<pit::Entry>& pitEntry,
const Face& inFace);
333 sendNack(
const lp::NackHeader& header,
Face& egress,
const shared_ptr<pit::Entry>& pitEntry)
335 return m_forwarder.onOutgoingNack(header, egress, pitEntry);
346 sendNacks(
const lp::NackHeader& header,
const shared_ptr<pit::Entry>& pitEntry,
347 std::initializer_list<const Face*> exceptFaces = {});
353 setExpiryTimer(
const shared_ptr<pit::Entry>& pitEntry, time::milliseconds duration)
355 m_forwarder.setExpiryTimer(pitEntry, duration);
368 return m_measurements;
380 return m_forwarder.m_faceTable;
430 using CreateFunc = std::function<unique_ptr<Strategy>(
Forwarder&,
const Name& )>;
431 using Registry = std::map<Name, CreateFunc>;
436 static Registry::const_iterator
437 find(
const Name& instanceName);
455 std::enable_if_t<std::is_signed_v<T>, T>
464 if (!boost::conversion::try_lexical_convert(it->second, val)) {
465 NDN_THROW(std::invalid_argument(key +
" value is malformed"));
471 std::enable_if_t<std::is_unsigned_v<T>, T>
479 if (it->second.find(
'-') != std::string::npos) {
480 NDN_THROW(std::invalid_argument(key +
" cannot be negative"));
484 if (!boost::conversion::try_lexical_convert(it->second, val)) {
485 NDN_THROW(std::invalid_argument(key +
" value is malformed"));
497 #define NFD_REGISTER_STRATEGY(S) \
498 static class NfdAuto ## S ## StrategyRegistrationClass \
501 NfdAuto ## S ## StrategyRegistrationClass() \
503 ::nfd::fw::Strategy::registerType<S>(); \
505 } g_nfdAuto ## S ## StrategyRegistrationVariable
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.
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.
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 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.