RoutingProtocol

Trait RoutingProtocol 

Source
pub trait RoutingProtocol:
    Send
    + Sync
    + 'static {
    // Required methods
    fn origin(&self) -> u64;
    fn start(
        &self,
        handle: RoutingHandle,
        cancel: CancellationToken,
    ) -> JoinHandle<()>;
}
Expand description

A routing protocol that manages routes in the RIB.

Implementations run as Tokio background tasks. Each protocol registers routes under a distinct origin value, which the RIB uses to namespace them. Multiple protocols run concurrently; the RIB computes the best nexthops across all origins when building FIB entries.

§Object safety

The trait is object-safe. start takes &self — implementations clone their internal state (typically held in an Arc<Inner>) to move into the spawned task.

§Example

struct MyProtocol { inner: Arc<MyState> }

impl RoutingProtocol for MyProtocol {
    fn origin(&self) -> u64 { ndn_config::control_parameters::origin::STATIC }

    fn start(&self, handle: RoutingHandle, cancel: CancellationToken) -> JoinHandle<()> {
        let inner = Arc::clone(&self.inner);
        tokio::spawn(async move {
            inner.run(handle, cancel).await;
        })
    }
}

Required Methods§

Source

fn origin(&self) -> u64

Route origin value this protocol registers under.

Each running instance must use a unique value. Standard values are in ndn_config::control_parameters::origin (e.g. NLSR = 128). Custom protocols should use values in the range 64–127.

Source

fn start( &self, handle: RoutingHandle, cancel: CancellationToken, ) -> JoinHandle<()>

Start the protocol as a Tokio background task.

Should run until cancel is cancelled, then return. The implementation calls handle.rib.add() to register routes and handle.rib.apply_to_fib() to push changes into the FIB.

Routes are automatically flushed from the RIB when the protocol is stopped via RoutingManager::disable.

Implementors§