nfd::fw::RandomStrategy Class Reference

A forwarding strategy that randomly chooses a nexthop. More...

#include <daemon/fw/random-strategy.hpp>

+ Inheritance diagram for nfd::fw::RandomStrategy:
+ Collaboration diagram for nfd::fw::RandomStrategy:

Public Member Functions

 RandomStrategy (Forwarder &forwarder, const Name &name=getStrategyName())
 
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. More...
 
virtual void afterNewNextHop (const fib::NextHop &nextHop, const shared_ptr< pit::Entry > &pitEntry)
 Trigger after a new nexthop is added. More...
 
virtual void afterReceiveData (const Data &data, const FaceEndpoint &ingress, const shared_ptr< pit::Entry > &pitEntry)
 Trigger after Data is received. More...
 
void afterReceiveInterest (const Interest &interest, const FaceEndpoint &ingress, const shared_ptr< pit::Entry > &pitEntry) override
 Trigger after an Interest is received. More...
 
void afterReceiveNack (const lp::Nack &nack, const FaceEndpoint &ingress, const shared_ptr< pit::Entry > &pitEntry) override
 Trigger after a Nack is received. More...
 
virtual void beforeSatisfyInterest (const Data &data, const FaceEndpoint &ingress, const shared_ptr< pit::Entry > &pitEntry)
 Trigger before a PIT entry is satisfied. More...
 
const Name & getInstanceName () const noexcept
 Returns the strategy's instance name. More...
 
virtual void onDroppedInterest (const Interest &interest, Face &egress)
 Trigger after an Interest is dropped (e.g., for exceeding allowed retransmissions). More...
 
virtual void onInterestLoop (const Interest &interest, const FaceEndpoint &ingress)
 Trigger after an Interest loop is detected. More...
 

Static Public Member Functions

static bool areSameType (const Name &instanceNameA, const Name &instanceNameB)
 Returns whether two names will instantiate the same strategy type. More...
 
static bool canCreate (const Name &instanceName)
 Returns whether a strategy instance can be created from instanceName. More...
 
static unique_ptr< Strategycreate (const Name &instanceName, Forwarder &forwarder)
 Returns a strategy instance created from instanceName. More...
 
static const Name & getStrategyName ()
 
static std::set< Name > listRegistered ()
 Returns all registered versioned strategy names. More...
 
template<typename S >
static void registerType (const Name &strategyName=S::getStrategyName())
 Register a strategy type. More...
 

Protected Member Functions

FacegetFace (FaceId id) const noexcept
 
const FaceTablegetFaceTable () const noexcept
 
MeasurementsAccessorgetMeasurements () noexcept
 
const fib::EntrylookupFib (const pit::Entry &pitEntry) const
 Performs a FIB lookup, considering Link object if present. More...
 
void processNack (const lp::Nack &nack, const Face &inFace, const shared_ptr< pit::Entry > &pitEntry)
 
void rejectPendingInterest (const shared_ptr< pit::Entry > &pitEntry)
 Schedule the PIT entry for immediate deletion. More...
 
bool sendData (const Data &data, Face &egress, const shared_ptr< pit::Entry > &pitEntry)
 Send a Data packet. More...
 
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...
 
pit::OutRecordsendInterest (const Interest &interest, Face &egress, const shared_ptr< pit::Entry > &pitEntry)
 Send an Interest packet. More...
 
bool sendNack (const lp::Nack &nack, Face &egress)
 Send a Nack packet without going through the outgoing Nack pipeline. More...
 
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...
 
void setInstanceName (const Name &name) noexcept
 Set strategy instance name. More...
 

Static Protected Member Functions

static Name makeInstanceName (const Name &input, const Name &strategyName)
 Construct a strategy instance name. More...
 
static ParsedInstanceName parseInstanceName (const Name &input)
 Parse a strategy instance name. More...
 
static StrategyParameters parseParameters (const PartialName &params)
 Parse strategy parameters encoded in a strategy instance name. More...
 

Protected Attributes

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

Detailed Description

A forwarding strategy that randomly chooses a nexthop.

Sends the incoming Interest to a random outgoing face, excluding the incoming face.

Definition at line 39 of file random-strategy.hpp.

Constructor & Destructor Documentation

◆ RandomStrategy()

nfd::fw::RandomStrategy::RandomStrategy ( Forwarder forwarder,
const Name &  name = getStrategyName() 
)
explicit

Definition at line 36 of file random-strategy.cpp.

Member Function Documentation

◆ afterContentStoreHit()

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

Trigger after a matching Data is found in the Content Store.

In the base class, this method sends data to ingress.

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.

Definition at line 187 of file strategy.cpp.

◆ afterNewNextHop()

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

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 229 of file strategy.cpp.

◆ afterReceiveData()

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

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 205 of file strategy.cpp.

◆ afterReceiveInterest()

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

Trigger after an Interest is received.

The Interest:

  • has not exceeded HopLimit
  • does not violate Scope
  • has 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.

Implements nfd::fw::Strategy.

Definition at line 59 of file random-strategy.cpp.

◆ afterReceiveNack()

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

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 from nfd::fw::Strategy.

Definition at line 82 of file random-strategy.cpp.

◆ areSameType()

bool nfd::fw::Strategy::areSameType ( const Name &  instanceNameA,
const Name &  instanceNameB 
)
staticinherited

Returns whether two names will instantiate the same strategy type.

Definition at line 108 of file strategy.cpp.

◆ beforeSatisfyInterest()

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

Trigger before a 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 are 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, 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::asf::AsfStrategy, and nfd::fw::AccessStrategy.

Definition at line 197 of file strategy.cpp.

◆ canCreate()

bool nfd::fw::Strategy::canCreate ( const Name &  instanceName)
staticinherited

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 the same rules as create(), but does not attempt to construct an instance.

Definition at line 86 of file strategy.cpp.

◆ create()

unique_ptr< Strategy > nfd::fw::Strategy::create ( const Name &  instanceName,
Forwarder forwarder 
)
staticinherited

Returns a strategy instance created from instanceName.

Return values
nullptrif canCreate(instanceName) == false
Exceptions
std::invalid_argumentstrategy type constructor does not accept the specified version or parameters

Definition at line 92 of file strategy.cpp.

◆ getFace()

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

Definition at line 405 of file strategy.hpp.

◆ getFaceTable()

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

Definition at line 411 of file strategy.hpp.

◆ getInstanceName()

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

Returns the strategy's instance name.

The instance name is assigned during instantiation. It contains a version component and may have extra parameter components.

Definition at line 126 of file strategy.hpp.

◆ getMeasurements()

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

Definition at line 399 of file strategy.hpp.

◆ getStrategyName()

const Name & nfd::fw::RandomStrategy::getStrategyName ( )
static

Definition at line 52 of file random-strategy.cpp.

◆ listRegistered()

std::set< Name > nfd::fw::Strategy::listRegistered ( )
staticinherited

Returns all registered versioned strategy names.

Definition at line 114 of file strategy.cpp.

◆ lookupFib()

const fib::Entry & nfd::fw::Strategy::lookupFib ( const pit::Entry pitEntry) const
protectedinherited

Performs a FIB lookup, considering Link object if present.

Definition at line 313 of file strategy.cpp.

◆ makeInstanceName()

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

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.

◆ onDroppedInterest()

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

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

In the base class, this method does nothing.

Definition at line 223 of file strategy.cpp.

◆ onInterestLoop()

void nfd::fw::Strategy::onInterestLoop ( const Interest &  interest,
const FaceEndpoint ingress 
)
virtualinherited

Trigger after an Interest loop is detected.

The Interest:

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

In the base class, this method sends a Nack with reason DUPLICATE to ingress.

Reimplemented in nfd::fw::MulticastStrategy.

Definition at line 177 of file strategy.cpp.

◆ parseInstanceName()

Strategy::ParsedInstanceName nfd::fw::Strategy::parseInstanceName ( const Name &  input)
staticprotectedinherited

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.

◆ parseParameters()

StrategyParameters nfd::fw::Strategy::parseParameters ( const PartialName &  params)
staticprotectedinherited

Parse strategy parameters encoded in a strategy instance name.

Parameters
paramsencoded parameters, typically obtained from a call to parseInstanceName()
Exceptions
std::invalid_argumentthe encoding format is invalid or unsupported by this implementation

Definition at line 144 of file strategy.cpp.

◆ processNack()

void nfd::fw::ProcessNackTraitsBase::processNack ( const lp::Nack &  nack,
const Face inFace,
const shared_ptr< pit::Entry > &  pitEntry 
)
protectedinherited

Definition at line 34 of file process-nack-traits.cpp.

◆ registerType()

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

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 57 of file strategy.hpp.

◆ rejectPendingInterest()

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

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 335 of file strategy.hpp.

◆ sendData()

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

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 247 of file strategy.cpp.

◆ sendDataToAll()

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

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 269 of file strategy.cpp.

◆ sendInterest()

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

Send an Interest packet.

Parameters
interestthe Interest packet
egressface through which to send out the Interest
pitEntrythe PIT entry
Returns
A pointer to the out-record created or nullptr if the Interest was dropped

Definition at line 236 of file strategy.cpp.

◆ sendNack() [1/2]

bool nfd::fw::Strategy::sendNack ( const lp::Nack &  nack,
Face egress 
)
inlineprotectedinherited

Send a Nack packet without going through the outgoing Nack pipeline.

Parameters
nackthe Nack packet
egressface through which to send out the Nack
Returns
Whether the Nack was sent (true) or dropped (false)

Definition at line 364 of file strategy.hpp.

◆ sendNack() [2/2]

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

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 351 of file strategy.hpp.

◆ sendNacks()

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

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 291 of file strategy.cpp.

◆ setExpiryTimer()

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

Schedule the PIT entry to be erased after duration.

Definition at line 386 of file strategy.hpp.

◆ setInstanceName()

void nfd::fw::Strategy::setInstanceName ( const Name &  name)
inlineprotectednoexceptinherited

Set strategy instance name.

Note
This must be called by strategy subclass constructor.

Definition at line 448 of file strategy.hpp.

Member Data Documentation

◆ afterAddFace

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

Definition at line 473 of file strategy.hpp.

◆ beforeRemoveFace

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

Definition at line 474 of file strategy.hpp.