NS-3 based Named Data Networking (NDN) simulator
ndnSIM 2.5: NDN, CCN, CCNx, content centric networks
API Documentation
nfd::fw::Strategy Class Referenceabstract

Represents a forwarding strategy. More...

#include <strategy.hpp>

Inheritance diagram for nfd::fw::Strategy:
Collaboration diagram for nfd::fw::Strategy:

Classes

struct  ParsedInstanceName
 

Public Member Functions

 Strategy (Forwarder &forwarder)
 Construct a strategy instance. More...
 
virtual ~Strategy ()
 
const NamegetInstanceName () const
 
virtual void afterReceiveInterest (const Interest &interest, const FaceEndpoint &ingress, const shared_ptr< pit::Entry > &pitEntry)=0
 Trigger after an Interest is received. More...
 
virtual void afterReceiveLoopedInterest (const FaceEndpoint &ingress, const Interest &interest, pit::Entry &pitEntry)
 trigger after a looped Interest is received More...
 
virtual void beforeSatisfyInterest (const Data &data, const FaceEndpoint &ingress, const shared_ptr< pit::Entry > &pitEntry)
 trigger before PIT entry is satisfied More...
 
virtual void satisfyInterest (const shared_ptr< pit::Entry > &pitEntry, const FaceEndpoint &ingress, const Data &data, std::set< std::pair< Face *, EndpointId >> &satisfiedDownstreams, std::set< std::pair< Face *, EndpointId >> &unsatisfiedDownstreams)
 
virtual void afterContentStoreHit (const Data &data, const FaceEndpoint &ingress, const shared_ptr< pit::Entry > &pitEntry)
 trigger after a Data is matched in CS More...
 
virtual void afterReceiveData (const Data &data, const FaceEndpoint &ingress, const shared_ptr< pit::Entry > &pitEntry)
 trigger after Data is received More...
 
virtual void afterReceiveNack (const lp::Nack &nack, const FaceEndpoint &ingress, const shared_ptr< pit::Entry > &pitEntry)
 Trigger after a Nack is received. More...
 
virtual void onDroppedInterest (const Interest &interest, Face &egress)
 Trigger after an Interest is dropped (e.g., for exceeding allowed retransmissions). More...
 
virtual void afterNewNextHop (const fib::NextHop &nextHop, const shared_ptr< pit::Entry > &pitEntry)
 Trigger after a new nexthop is added. More...
 

Static Public Member Functions

template<typename S >
static void registerType (const Name &strategyName=S::getStrategyName())
 Register a strategy type. More...
 
static bool canCreate (const Name &instanceName)
 
static unique_ptr< Strategycreate (const Name &instanceName, Forwarder &forwarder)
 
static bool areSameType (const Name &instanceNameA, const Name &instanceNameB)
 
static std::set< NamelistRegistered ()
 
static const NamegetStrategyName ()
 

Protected Member Functions

NFD_VIRTUAL_WITH_TESTS pit::OutRecordsendInterest (const Interest &interest, Face &egress, const shared_ptr< pit::Entry > &pitEntry)
 Send an Interest packet. More...
 
NFD_VIRTUAL_WITH_TESTS bool sendData (const Data &data, Face &egress, const shared_ptr< pit::Entry > &pitEntry)
 Send a Data packet. More...
 
NFD_VIRTUAL_WITH_TESTS void sendDataToAll (const Data &data, const shared_ptr< pit::Entry > &pitEntry, const Face &inFace)
 Send a Data packet to all matched and qualified faces. More...
 
NFD_VIRTUAL_WITH_TESTS void rejectPendingInterest (const shared_ptr< pit::Entry > &pitEntry)
 Schedule the PIT entry for immediate deletion. More...
 
NFD_VIRTUAL_WITH_TESTS bool sendNack (const lp::NackHeader &header, Face &egress, const shared_ptr< pit::Entry > &pitEntry)
 Send a Nack packet. More...
 
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. More...
 
void setExpiryTimer (const shared_ptr< pit::Entry > &pitEntry, time::milliseconds duration)
 Schedule the PIT entry to be erased after duration. More...
 
const fib::EntrylookupFib (const pit::Entry &pitEntry) const
 Performs a FIB lookup, considering Link object if present. More...
 
MeasurementsAccessorgetMeasurements ()
 
FacegetFace (FaceId id) const
 
const FaceTablegetFaceTable () const
 
void setInstanceName (const Name &name)
 Set strategy instance name. More...
 

Static Protected Member Functions

static ParsedInstanceName parseInstanceName (const Name &input)
 Parse a strategy instance name. More...
 
static Name makeInstanceName (const Name &input, const Name &strategyName)
 Construct a strategy instance name. More...
 

Protected Attributes

signal::Signal< FaceTable, Face > & afterAddFace
 
signal::Signal< FaceTable, Face > & beforeRemoveFace
 

Detailed Description

Represents a forwarding strategy.

Definition at line 38 of file strategy.hpp.

Constructor & Destructor Documentation

◆ Strategy()

nfd::fw::Strategy::Strategy ( Forwarder forwarder)
explicit

Construct a strategy instance.

Parameters
forwardera reference to the forwarder, used to enable actions and accessors.
Note
Strategy subclass constructor must not retain a reference to forwarder.

Definition at line 143 of file strategy.cpp.

References ~Strategy().

Referenced by registerType().

◆ ~Strategy()

nfd::fw::Strategy::~Strategy ( )
virtualdefault

Referenced by registerType(), and Strategy().

Member Function Documentation

◆ registerType()

template<typename S >
static void nfd::fw::Strategy::registerType ( const Name strategyName = S::getStrategyName())
inlinestatic

Register a strategy type.

Template Parameters
Ssubclass of Strategy
Parameters
strategyNamestrategy program name, must contain version
Note
It is permitted to register the same strategy type under multiple names, which is useful in tests and for creating aliases.

Definition at line 49 of file strategy.hpp.

References areSameType(), canCreate(), create(), getStrategyName(), listRegistered(), Strategy(), and ~Strategy().

◆ canCreate()

bool nfd::fw::Strategy::canCreate ( const Name instanceName)
static
Returns
Whether a strategy instance can be created from instanceName
Parameters
instanceNamestrategy instance name, may contain version and parameters
Note
This function finds a strategy type using same rules as create , but does not attempt to construct an instance.

Definition at line 86 of file strategy.cpp.

Referenced by registerType().

◆ create()

unique_ptr< Strategy > nfd::fw::Strategy::create ( const Name instanceName,
Forwarder forwarder 
)
static
Returns
A strategy instance created from instanceName
Return values
nullptrif !canCreate(instanceName)
Exceptions
std::invalid_argumentstrategy type constructor does not accept specified version or parameters

Definition at line 92 of file strategy.cpp.

References websocketpp::http::status_code::found, and NFD_LOG_DEBUG.

Referenced by nfd::strategy_choice::StrategyChoice::insert(), registerType(), and nfd::strategy_choice::StrategyChoice::setDefaultStrategy().

◆ areSameType()

bool nfd::fw::Strategy::areSameType ( const Name instanceNameA,
const Name instanceNameB 
)
static
Returns
Whether instanceNameA and instanceNameA will initiate same strategy type

Definition at line 108 of file strategy.cpp.

Referenced by nfd::strategy_choice::clearStrategyInfo(), and registerType().

◆ listRegistered()

std::set< Name > nfd::fw::Strategy::listRegistered ( )
static
Returns
Registered versioned strategy names

Definition at line 114 of file strategy.cpp.

Referenced by registerType().

◆ getStrategyName()

static const Name& nfd::fw::Strategy::getStrategyName ( )
static
Returns
Strategy program name

The strategy name is defined by the strategy program. It must end with a version component.

Referenced by registerType().

◆ getInstanceName()

const Name& nfd::fw::Strategy::getInstanceName ( ) const
inline

◆ afterReceiveInterest()

virtual void nfd::fw::Strategy::afterReceiveInterest ( const Interest interest,
const FaceEndpoint ingress,
const shared_ptr< pit::Entry > &  pitEntry 
)
pure virtual

Trigger after an Interest is received.

The Interest:

  • has not exceeded HopLimit
  • does not violate Scope
  • is not looped
  • cannot be satisfied by ContentStore
  • is under a namespace managed by this strategy

The PIT entry is set to expire after InterestLifetime has elapsed at each downstream.

The strategy should decide whether and where to forward this Interest.

  • If the strategy decides to forward this Interest, invoke sendInterest() for each upstream, either now or shortly after via a scheduler event, but before the PIT entry expires. Optionally, the strategy can invoke setExpiryTimer() to adjust how long it would wait for a response.
  • If the strategy has already forwarded this Interest previously and decides to continue waiting, do nothing. Optionally, the strategy can invoke setExpiryTimer() to adjust how long it would wait for a response.
  • If the strategy concludes that this Interest cannot be satisfied, invoke rejectPendingInterest() to erase the PIT entry.
Warning
The strategy must not retain a copy of the pitEntry shared_ptr after this function returns, otherwise undefined behavior may occur. However, the strategy is allowed to construct and keep a weak_ptr to pitEntry.

Implemented in nfd::fw::SelfLearningStrategy, nfd::fw::BestRouteStrategy, nfd::fw::AccessStrategy, nfd::fw::asf::AsfStrategy, nfd::fw::RandomStrategy, and nfd::fw::MulticastStrategy.

Referenced by getInstanceName(), and nfd::Forwarder::onContentStoreMiss().

◆ afterReceiveLoopedInterest()

void nfd::fw::Strategy::afterReceiveLoopedInterest ( const FaceEndpoint ingress,
const Interest interest,
pit::Entry pitEntry 
)
virtual

trigger after a looped Interest is received

The Interest:

  • does not violate Scope
  • IS looped
  • cannot be satisfied by ContentStore
  • is under a namespace managed by this strategy

Definition at line 155 of file strategy.cpp.

References nfd::pit::Entry::getName(), and NFD_LOG_DEBUG.

Referenced by nfd::Forwarder::Forwarder(), and getInstanceName().

◆ beforeSatisfyInterest()

void nfd::fw::Strategy::beforeSatisfyInterest ( const Data data,
const FaceEndpoint ingress,
const shared_ptr< pit::Entry > &  pitEntry 
)
virtual

trigger before PIT entry is satisfied

This trigger is invoked when an incoming Data satisfies more than one PIT entry. The strategy can collect measurements information, but cannot manipulate Data forwarding. When an incoming Data satisfies only one PIT entry, afterReceiveData is invoked instead and given full control over Data forwarding. If a strategy does not override afterReceiveData, the default implementation invokes beforeSatisfyInterest.

Normally, PIT entries would be erased after receiving the first matching Data. If the strategy wishes to collect responses from additional upstream nodes, it should invoke setExpiryTimer within this function to prolong the PIT entry lifetime. If a Data arrives from another upstream during the extended PIT entry lifetime, this trigger will be invoked again. At that time, this function must invoke setExpiryTimer again to continue collecting more responses.

In this base class this method does nothing.

Warning
The strategy must not retain shared_ptr<pit::Entry>, otherwise undefined behavior may occur. However, the strategy is allowed to store weak_ptr<pit::Entry>.

Reimplemented in nfd::fw::AccessStrategy, and nfd::fw::asf::AsfStrategy.

Definition at line 163 of file strategy.cpp.

References ndn::Data::getName(), and NFD_LOG_DEBUG.

Referenced by afterReceiveData(), getInstanceName(), nfd::Forwarder::onContentStoreHit(), and satisfyInterest().

◆ satisfyInterest()

void nfd::fw::Strategy::satisfyInterest ( const shared_ptr< pit::Entry > &  pitEntry,
const FaceEndpoint ingress,
const Data data,
std::set< std::pair< Face *, EndpointId >> &  satisfiedDownstreams,
std::set< std::pair< Face *, EndpointId >> &  unsatisfiedDownstreams 
)
virtual

◆ afterContentStoreHit()

void nfd::fw::Strategy::afterContentStoreHit ( const Data data,
const FaceEndpoint ingress,
const shared_ptr< pit::Entry > &  pitEntry 
)
virtual

trigger after a Data is matched in CS

In the base class this method sends data to ingress

Definition at line 196 of file strategy.cpp.

References nfd::FaceEndpoint::face, ndn::Data::getName(), NFD_LOG_DEBUG, and sendData().

Referenced by getInstanceName(), and nfd::Forwarder::onContentStoreHit().

◆ afterReceiveData()

void nfd::fw::Strategy::afterReceiveData ( const Data data,
const FaceEndpoint ingress,
const shared_ptr< pit::Entry > &  pitEntry 
)
virtual

trigger after Data is received

This trigger is invoked when an incoming Data satisfies exactly one PIT entry, and gives the strategy full control over Data forwarding.

When this trigger is invoked:

  • The Data has been verified to satisfy the PIT entry.
  • The PIT entry expiry timer is set to now

Inside this function:

  • A strategy should return Data to downstream nodes via sendData() or sendDataToAll().
  • A strategy can modify the Data as long as it still satisfies the PIT entry, such as adding or removing congestion marks.
  • A strategy can delay Data forwarding by prolonging the PIT entry lifetime via setExpiryTimer(), and later forward the Data before the PIT entry is erased.
  • A strategy can collect measurements about the upstream.
  • A strategy can collect responses from additional upstream nodes by prolonging the PIT entry lifetime via setExpiryTimer() every time a Data is received. Note that only one Data should be returned to each downstream node.

In the base class, this method invokes beforeSatisfyInterest() and then returns the Data to all downstream faces via sendDataToAll().

Warning
The strategy must not retain a copy of the pitEntry shared_ptr after this function returns, otherwise undefined behavior may occur. However, the strategy is allowed to construct and keep a weak_ptr to pitEntry.

Reimplemented in nfd::fw::SelfLearningStrategy.

Definition at line 206 of file strategy.cpp.

References beforeSatisfyInterest(), nfd::FaceEndpoint::face, ndn::Data::getName(), NFD_LOG_DEBUG, and sendDataToAll().

Referenced by getInstanceName().

◆ afterReceiveNack()

void nfd::fw::Strategy::afterReceiveNack ( const lp::Nack nack,
const FaceEndpoint ingress,
const shared_ptr< pit::Entry > &  pitEntry 
)
virtual

Trigger after a Nack is received.

This trigger is invoked when an incoming Nack is received in response to an forwarded Interest. The Nack has been confirmed to be a response to the last Interest forwarded to that upstream, i.e. the PIT out-record exists and has a matching Nonce. The NackHeader has been recorded in the PIT out-record.

If the PIT entry is not yet satisfied, its expiry timer remains unchanged. Otherwise, the PIT entry will normally expire immediately after this function returns.

If the strategy wishes to collect responses from additional upstream nodes, it should invoke setExpiryTimer() within this function to prolong the PIT entry lifetime. If a Nack arrives from another upstream during the extended PIT entry lifetime, this trigger will be invoked again. At that time, the strategy must invoke setExpiryTimer() again to continue collecting more responses.

In the base class, this method does nothing.

Warning
The strategy must not retain a copy of the pitEntry shared_ptr after this function returns, otherwise undefined behavior may occur. However, the strategy is allowed to construct and keep a weak_ptr to pitEntry.

Reimplemented in nfd::fw::SelfLearningStrategy, nfd::fw::BestRouteStrategy, nfd::fw::asf::AsfStrategy, and nfd::fw::RandomStrategy.

Definition at line 217 of file strategy.cpp.

References NFD_LOG_DEBUG.

Referenced by getInstanceName(), and nfd::Forwarder::onIncomingNack().

◆ onDroppedInterest()

void nfd::fw::Strategy::onDroppedInterest ( const Interest interest,
Face egress 
)
virtual

Trigger after an Interest is dropped (e.g., for exceeding allowed retransmissions).

In the base class, this method does nothing.

Definition at line 224 of file strategy.cpp.

References ndn::Interest::getName(), and NFD_LOG_DEBUG.

Referenced by getInstanceName().

◆ afterNewNextHop()

void nfd::fw::Strategy::afterNewNextHop ( const fib::NextHop nextHop,
const shared_ptr< pit::Entry > &  pitEntry 
)
virtual

Trigger after a new nexthop is added.

The strategy should decide whether to send the buffered Interests to the new nexthop.

In the base class, this method does nothing.

Reimplemented in nfd::fw::MulticastStrategy.

Definition at line 230 of file strategy.cpp.

References nfd::fib::NextHop::getFace(), and NFD_LOG_DEBUG.

Referenced by getInstanceName(), and nfd::Forwarder::onNewNextHop().

◆ sendInterest()

pit::OutRecord * nfd::fw::Strategy::sendInterest ( const Interest interest,
Face egress,
const shared_ptr< pit::Entry > &  pitEntry 
)
protected

◆ sendData()

bool nfd::fw::Strategy::sendData ( const Data data,
Face egress,
const shared_ptr< pit::Entry > &  pitEntry 
)
protected

Send a Data packet.

Parameters
datathe Data packet
egressface through which to send out the Data
pitEntrythe PIT entry
Returns
Whether the Data was sent (true) or dropped (false)

Definition at line 248 of file strategy.cpp.

References nfd::Forwarder::onOutgoingData(), and ndn::TagHost::setTag().

Referenced by afterContentStoreHit(), getInstanceName(), and sendDataToAll().

◆ sendDataToAll()

void nfd::fw::Strategy::sendDataToAll ( const Data data,
const shared_ptr< pit::Entry > &  pitEntry,
const Face inFace 
)
protected

Send a Data packet to all matched and qualified faces.

A matched face qualifies if it is ad-hoc OR it is NOT inFace.

Parameters
datathe Data packet
pitEntrythe PIT entry
inFaceface on which the Data arrived

Definition at line 279 of file strategy.cpp.

References ndn::nfd::LINK_TYPE_AD_HOC, ndn::time::steady_clock::now(), and sendData().

Referenced by nfd::fw::SelfLearningStrategy::afterReceiveData(), afterReceiveData(), nfd::fw::SelfLearningStrategy::afterReceiveNack(), and getInstanceName().

◆ rejectPendingInterest()

NFD_VIRTUAL_WITH_TESTS void nfd::fw::Strategy::rejectPendingInterest ( const shared_ptr< pit::Entry > &  pitEntry)
inlineprotected

Schedule the PIT entry for immediate deletion.

This helper function sets the PIT entry expiry time to zero. The strategy should invoke this function when it concludes that the Interest cannot be forwarded and it does not want to wait for responses from existing upstream nodes.

Definition at line 319 of file strategy.hpp.

References NFD_VIRTUAL_WITH_TESTS, and setExpiryTimer().

Referenced by nfd::fw::RandomStrategy::afterReceiveInterest(), nfd::fw::AccessStrategy::afterReceiveInterest(), nfd::fw::BestRouteStrategy::afterReceiveInterest(), nfd::fw::SelfLearningStrategy::afterReceiveInterest(), and nfd::fw::asf::FaceStatsCompare::operator()().

◆ sendNack()

NFD_VIRTUAL_WITH_TESTS bool nfd::fw::Strategy::sendNack ( const lp::NackHeader header,
Face egress,
const shared_ptr< pit::Entry > &  pitEntry 
)
inlineprotected

Send a Nack packet.

The egress face must have a PIT in-record, otherwise this method has no effect.

Parameters
headerthe Nack header
egressface through which to send out the Nack
pitEntrythe PIT entry
Returns
Whether the Nack was sent (true) or dropped (false)

Definition at line 335 of file strategy.hpp.

References nfd::Forwarder::onOutgoingNack(), and sendNacks().

Referenced by nfd::fw::RandomStrategy::afterReceiveInterest(), nfd::fw::BestRouteStrategy::afterReceiveInterest(), nfd::fw::SelfLearningStrategy::afterReceiveInterest(), nfd::fw::asf::FaceStatsCompare::operator()(), and sendNacks().

◆ sendNacks()

void nfd::fw::Strategy::sendNacks ( const lp::NackHeader header,
const shared_ptr< pit::Entry > &  pitEntry,
std::initializer_list< const Face *>  exceptFaces = {} 
)
protected

Send Nack to every face that has an in-record, except those in exceptFaces.

Parameters
headerthe Nack header
pitEntrythe PIT entry
exceptFaceslist of faces that should be excluded from sending Nacks
Note
This is not an action, but a helper that invokes the sendNack() action.

Definition at line 309 of file strategy.cpp.

References sendNack().

Referenced by nfd::fw::SelfLearningStrategy::afterReceiveNack(), and sendNack().

◆ setExpiryTimer()

void nfd::fw::Strategy::setExpiryTimer ( const shared_ptr< pit::Entry > &  pitEntry,
time::milliseconds  duration 
)
inlineprotected

Schedule the PIT entry to be erased after duration.

Definition at line 355 of file strategy.hpp.

References lookupFib().

Referenced by nfd::fw::SelfLearningStrategy::afterReceiveNack(), nfd::fw::asf::AsfStrategy::beforeSatisfyInterest(), and rejectPendingInterest().

◆ lookupFib()

◆ getMeasurements()

MeasurementsAccessor& nfd::fw::Strategy::getMeasurements ( )
inlineprotected

Definition at line 368 of file strategy.hpp.

References Face.

Referenced by nfd::fw::AccessStrategy::beforeSatisfyInterest().

◆ getFace()

Face* nfd::fw::Strategy::getFace ( FaceId  id) const
inlineprotected

◆ getFaceTable()

const FaceTable& nfd::fw::Strategy::getFaceTable ( ) const
inlineprotected

Definition at line 380 of file strategy.hpp.

Referenced by nfd::fw::SelfLearningStrategy::afterReceiveNack(), and getFace().

◆ parseInstanceName()

Strategy::ParsedInstanceName nfd::fw::Strategy::parseInstanceName ( const Name input)
staticprotected

Parse a strategy instance name.

Parameters
inputstrategy instance name, may contain version and parameters
Exceptions
std::invalid_argumentinput format is unacceptable

Definition at line 123 of file strategy.cpp.

References ndn::Name::getPrefix(), ndn::Name::getSubName(), nonstd::optional_lite::nullopt, and ndn::Name::size().

Referenced by nfd::fw::AccessStrategy::AccessStrategy(), nfd::fw::asf::AsfStrategy::AsfStrategy(), nfd::fw::BestRouteStrategy::BestRouteStrategy(), nfd::fw::MulticastStrategy::MulticastStrategy(), nfd::fw::RandomStrategy::RandomStrategy(), and nfd::fw::SelfLearningStrategy::SelfLearningStrategy().

◆ makeInstanceName()

Name nfd::fw::Strategy::makeInstanceName ( const Name input,
const Name strategyName 
)
staticprotected

Construct a strategy instance name.

Parameters
inputstrategy instance name, may contain version and parameters
strategyNamestrategy name with version but without parameters; typically this should be getStrategyName()

If input contains a version component, return input unchanged. Otherwise, return input plus the version component taken from strategyName. This allows a strategy instance to be constructed with an unversioned name, but its final instance name should contain the version.

Definition at line 134 of file strategy.cpp.

References ndn::Name::at(), ndn::name::Component::isVersion(), ns3::ndn::Name, ndn::Name::rbegin(), and ndn::Name::rend().

Referenced by nfd::fw::AccessStrategy::AccessStrategy(), nfd::fw::asf::AsfStrategy::AsfStrategy(), nfd::fw::BestRouteStrategy::BestRouteStrategy(), nfd::fw::MulticastStrategy::MulticastStrategy(), nfd::fw::RandomStrategy::RandomStrategy(), and nfd::fw::SelfLearningStrategy::SelfLearningStrategy().

◆ setInstanceName()

void nfd::fw::Strategy::setInstanceName ( const Name name)
inlineprotected

Member Data Documentation

◆ afterAddFace

signal::Signal<FaceTable, Face>& nfd::fw::Strategy::afterAddFace
protected

Definition at line 433 of file strategy.hpp.

◆ beforeRemoveFace

signal::Signal<FaceTable, Face>& nfd::fw::Strategy::beforeRemoveFace
protected

Definition at line 434 of file strategy.hpp.


The documentation for this class was generated from the following files: