|
ndn-embeds 0.1.0
Lightweight NDN protocol stack for embedded systems
|
#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 Stats & | stats () const |
| Get statistics. | |
Access to internal components | |
| Pit & | pit () |
| Get reference to PIT (for testing) | |
| ContentStore & | cs () |
| Get reference to Content Store (for testing) | |
| Fib & | fib () |
| Get reference to FIB (for testing) | |
NDN Forwarder.
The central class responsible for NDN packet forwarding. Provides the following features:
Definition at line 99 of file forwarder.hpp.
| ndn::Forwarder::Forwarder | ( | ) |
Constructor.
Definition at line 12 of file forwarder.cpp.
Add a Face.
| face | Pointer to the Face to add |
Definition at line 37 of file forwarder.cpp.
References ndn::FACE_ID_INVALID, ndn::Face::id(), and ndn::Face::setPacketCallback().
Add a route.
Definition at line 169 of file forwarder.cpp.
References ndn::Fib::addRoute().
Add a route (URI string version)
| prefixUri | Prefix URI string |
| faceId | Next-hop Face ID |
| cost | Cost (default: 0) |
Definition at line 173 of file forwarder.cpp.
References ndn::Fib::addRoute(), and ndn::Name::fromUri().
|
inline |
Get reference to Content Store (for testing)
Definition at line 286 of file forwarder.hpp.
| 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.
| interest | Interest to send |
| onData | Callback on Data reception |
| onTimeout | Callback on timeout (optional) |
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().
|
inline |
Get reference to FIB (for testing)
Definition at line 292 of file forwarder.hpp.
| Error ndn::Forwarder::init | ( | size_t | csMaxEntries = CS_DEFAULT_ENTRIES | ) |
Initialize the Forwarder.
Initializes the Content Store with the specified size.
| csMaxEntries | Maximum number of Content Store entries (default: CS_DEFAULT_ENTRIES) |
Definition at line 18 of file forwarder.cpp.
References ndn::ContentStore::init().
|
inline |
Get reference to PIT (for testing)
Definition at line 280 of file forwarder.hpp.
| 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().
Send Data.
Looks up the PIT entry and forwards Data to the matching Faces. The Data is also stored in the cache.
| data | Data to send |
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().
| 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.
Definition at line 117 of file forwarder.cpp.
References ndn::Fib::addRoute(), and ndn::FACE_ID_LOCAL.
Referenced by ndn::registerPrefix(), and registerPrefix().
| Error ndn::Forwarder::registerPrefix | ( | std::string_view | prefixUri, |
| InterestCallback | callback | ||
| ) |
Register a prefix (URI string version)
| prefixUri | Prefix URI string |
| callback | Callback on Interest reception |
Definition at line 132 of file forwarder.cpp.
References ndn::Name::fromUri(), and registerPrefix().
| void ndn::Forwarder::removeFace | ( | FaceId | faceId | ) |
Remove a Face.
Related next-hops are also removed from the FIB.
| faceId | ID of the Face to remove |
Definition at line 69 of file forwarder.cpp.
References ndn::Fib::removeFace().
Send an Interest (without PIT registration)
Used when Data is not expected, such as for Sync Interests.
| interest | Interest to send |
Definition at line 110 of file forwarder.cpp.
References ndn::FACE_ID_LOCAL, and ndn::Forwarder::Stats::interestsSent.
|
inline |
| void ndn::Forwarder::unregisterPrefix | ( | const Name & | prefix | ) |
Unregister a prefix.
| prefix | Name prefix to unregister |
Definition at line 140 of file forwarder.cpp.
References ndn::FACE_ID_LOCAL, and ndn::Fib::removeRoute().