ndn-embeds 0.1.0
Lightweight NDN protocol stack for embedded systems
Loading...
Searching...
No Matches
ndn::Forwarder Class Reference

NDN Forwarder. More...

#include <ndn/forwarder.hpp>

Classes

struct  Stats
 Forwarder statistics. More...
 

Public Member Functions

 Forwarder ()
 Constructor.
 
Error init (size_t csMaxEntries=CS_DEFAULT_ENTRIES)
 Initialize the Forwarder.
 
Face management
Error addFace (Face *face)
 Add a Face.
 
void removeFace (FaceId faceId)
 Remove a Face.
 
Application API (consumer)
Error expressInterest (const Interest &interest, DataCallback onData, TimeoutCallback onTimeout=nullptr)
 Send an Interest and wait for Data.
 
Error sendInterest (const Interest &interest)
 Send an Interest (without PIT registration)
 
Application API (producer)
Error registerPrefix (const Name &prefix, InterestCallback callback)
 Register a prefix.
 
Error registerPrefix (std::string_view prefixUri, InterestCallback callback)
 Register a prefix (URI string version)
 
void unregisterPrefix (const Name &prefix)
 Unregister a prefix.
 
Error putData (const Data &data)
 Send Data.
 
FIB route management
Error addRoute (const Name &prefix, FaceId faceId, uint8_t cost=0)
 Add a route.
 
Error addRoute (std::string_view prefixUri, FaceId faceId, uint8_t cost=0)
 Add a route (URI string version)
 
Event processing
void processEvents ()
 Process events.
 
Statistics
const Statsstats () const
 Get statistics.
 
Access to internal components
Pitpit ()
 Get reference to PIT (for testing)
 
ContentStorecs ()
 Get reference to Content Store (for testing)
 
Fibfib ()
 Get reference to FIB (for testing)
 

Detailed Description

NDN Forwarder.

The central class responsible for NDN packet forwarding. Provides the following features:

  • Face management (add/remove)
  • Interest/Data forwarding
  • Application API (expressInterest, registerPrefix, putData)
  • Integrated PIT, CS, and FIB management
// Initialize the Forwarder
Forwarder forwarder;
forwarder.init();
// Add a Face
EspNowFace espNowFace;
forwarder.addFace(&espNowFace);
// Register a prefix (producer)
forwarder.registerPrefix("/sensor", [&](const Interest& interest, FaceId face) {
Data data;
data.setName(interest.name());
data.setContent("25.5 C");
forwarder.putData(data);
});
// Send an Interest (consumer)
Interest interest;
interest.setName("/sensor/temperature");
forwarder.expressInterest(interest, [](const Data& data) {
printf("Received: %.*s\n", (int)data.contentSize(), data.content());
});
// Event loop
while (true) {
forwarder.processEvents();
vTaskDelay(pdMS_TO_TICKS(10));
}
NDN Data packet.
Definition data.hpp:49
size_t contentSize() const
Get the content size.
Definition data.hpp:141
const uint8_t * content() const
Get a pointer to the content data.
Definition data.hpp:135
Error setContent(const uint8_t *data, size_t size)
Set binary data as content.
Definition data.cpp:26
Data & setName(const Name &name)
Set the Name (supports method chaining)
Definition data.cpp:12
ESP-NOW Face.
NDN Forwarder.
Definition forwarder.hpp:99
Error addFace(Face *face)
Add a Face.
Definition forwarder.cpp:37
Error registerPrefix(const Name &prefix, InterestCallback callback)
Register a prefix.
Error expressInterest(const Interest &interest, DataCallback onData, TimeoutCallback onTimeout=nullptr)
Send an Interest and wait for Data.
Definition forwarder.cpp:81
Error putData(const Data &data)
Send Data.
Error init(size_t csMaxEntries=CS_DEFAULT_ENTRIES)
Initialize the Forwarder.
Definition forwarder.cpp:18
void processEvents()
Process events.
NDN Interest packet.
Definition interest.hpp:50
Interest & setName(const Name &name)
Set the Name (supports method chaining)
Definition interest.cpp:13
const Name & name() const
Get the Name (const reference)
Definition interest.hpp:105
uint16_t FaceId
Face identifier.
Definition common.hpp:96

Definition at line 99 of file forwarder.hpp.

Constructor & Destructor Documentation

◆ Forwarder()

ndn::Forwarder::Forwarder ( )

Constructor.

Definition at line 12 of file forwarder.cpp.

Member Function Documentation

◆ addFace()

Error ndn::Forwarder::addFace ( Face face)

Add a Face.

Parameters
facePointer to the Face to add
Returns
Error::Success on success, Error::Full when at capacity

Definition at line 37 of file forwarder.cpp.

References ndn::FACE_ID_INVALID, ndn::Face::id(), and ndn::Face::setPacketCallback().

◆ addRoute() [1/2]

Error ndn::Forwarder::addRoute ( const Name prefix,
FaceId  faceId,
uint8_t  cost = 0 
)

Add a route.

Parameters
prefixName prefix
faceIdNext-hop Face ID
costCost (default: 0)
Returns
Error::Success on success

Definition at line 169 of file forwarder.cpp.

References ndn::Fib::addRoute().

◆ addRoute() [2/2]

Error ndn::Forwarder::addRoute ( std::string_view  prefixUri,
FaceId  faceId,
uint8_t  cost = 0 
)

Add a route (URI string version)

Parameters
prefixUriPrefix URI string
faceIdNext-hop Face ID
costCost (default: 0)
Returns
Error::Success on success

Definition at line 173 of file forwarder.cpp.

References ndn::Fib::addRoute(), and ndn::Name::fromUri().

◆ cs()

ContentStore & ndn::Forwarder::cs ( )
inline

Get reference to Content Store (for testing)

Returns
Reference to ContentStore

Definition at line 286 of file forwarder.hpp.

◆ expressInterest()

Error ndn::Forwarder::expressInterest ( const Interest interest,
DataCallback  onData,
TimeoutCallback  onTimeout = nullptr 
)

Send an Interest and wait for Data.

Creates a PIT entry and forwards the Interest. The onData callback is called when Data is received. The onTimeout callback is called on timeout.

Parameters
interestInterest to send
onDataCallback on Data reception
onTimeoutCallback on timeout (optional)
Returns
Error::Success on success

Definition at line 81 of file forwarder.cpp.

References ndn::FACE_ID_LOCAL, ndn::Pit::insert(), and ndn::Forwarder::Stats::interestsSent.

Referenced by ndn::expressInterest().

◆ fib()

Fib & ndn::Forwarder::fib ( )
inline

Get reference to FIB (for testing)

Returns
Reference to FIB

Definition at line 292 of file forwarder.hpp.

◆ init()

Error ndn::Forwarder::init ( size_t  csMaxEntries = CS_DEFAULT_ENTRIES)

Initialize the Forwarder.

Initializes the Content Store with the specified size.

Parameters
csMaxEntriesMaximum number of Content Store entries (default: CS_DEFAULT_ENTRIES)
Returns
Error::Success on success, error code on CS initialization failure

Definition at line 18 of file forwarder.cpp.

References ndn::ContentStore::init().

◆ pit()

Pit & ndn::Forwarder::pit ( )
inline

Get reference to PIT (for testing)

Returns
Reference to PIT

Definition at line 280 of file forwarder.hpp.

◆ processEvents()

void ndn::Forwarder::processEvents ( )

Process events.

Performs timeout processing and other tasks. Must be called periodically.

Definition at line 181 of file forwarder.cpp.

References ndn::currentTimeMs(), ndn::ContentStore::evictStale(), ndn::PitEntry::name(), and ndn::Pit::processTimeouts().

Referenced by ndn::processEvents().

◆ putData()

Error ndn::Forwarder::putData ( const Data data)

Send Data.

Looks up the PIT entry and forwards Data to the matching Faces. The Data is also stored in the cache.

Parameters
dataData to send
Returns
Error::Success on success

Definition at line 150 of file forwarder.cpp.

References ndn::currentTimeMs(), ndn::PitEntry::faceCount(), ndn::Pit::find(), ndn::ContentStore::insert(), ndn::Data::name(), and ndn::Pit::remove().

Referenced by ndn::putData().

◆ registerPrefix() [1/2]

Error ndn::Forwarder::registerPrefix ( const Name prefix,
InterestCallback  callback 
)

Register a prefix.

The callback is called when an Interest matching the specified prefix is received.

Parameters
prefixName prefix to register
callbackCallback on Interest reception
Returns
Error::Success on success, Error::Full when at capacity

Definition at line 117 of file forwarder.cpp.

References ndn::Fib::addRoute(), and ndn::FACE_ID_LOCAL.

Referenced by ndn::registerPrefix(), and registerPrefix().

◆ registerPrefix() [2/2]

Error ndn::Forwarder::registerPrefix ( std::string_view  prefixUri,
InterestCallback  callback 
)

Register a prefix (URI string version)

Parameters
prefixUriPrefix URI string
callbackCallback on Interest reception
Returns
Error::Success on success

Definition at line 132 of file forwarder.cpp.

References ndn::Name::fromUri(), and registerPrefix().

◆ removeFace()

void ndn::Forwarder::removeFace ( FaceId  faceId)

Remove a Face.

Related next-hops are also removed from the FIB.

Parameters
faceIdID of the Face to remove

Definition at line 69 of file forwarder.cpp.

References ndn::Fib::removeFace().

◆ sendInterest()

Error ndn::Forwarder::sendInterest ( const Interest interest)

Send an Interest (without PIT registration)

Used when Data is not expected, such as for Sync Interests.

Parameters
interestInterest to send
Returns
Error::Success on success

Definition at line 110 of file forwarder.cpp.

References ndn::FACE_ID_LOCAL, and ndn::Forwarder::Stats::interestsSent.

◆ stats()

const Stats & ndn::Forwarder::stats ( ) const
inline

Get statistics.

Returns
Const reference to statistics

Definition at line 269 of file forwarder.hpp.

◆ unregisterPrefix()

void ndn::Forwarder::unregisterPrefix ( const Name prefix)

Unregister a prefix.

Parameters
prefixName prefix to unregister

Definition at line 140 of file forwarder.cpp.

References ndn::FACE_ID_LOCAL, and ndn::Fib::removeRoute().


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