Embed the routing core
Select and apply a route
The wren-core crate has no third-party dependencies. A caller feeds candidates to Rib and applies the returned change to a Fib implementation. This example keeps the FIB in memory.
#![allow(unused)]
fn main() {
use wren_core::{Rib, Route, Protocol, Prefix, NextHop, Fib, MemoryFib};
let mut rib = Rib::new();
let mut fib = MemoryFib::default(); // or your own Fib implementation
let route = Route::new(
"10.0.0.0/24".parse::<Prefix>().unwrap(),
Protocol::Static,
vec![NextHop::via("192.0.2.1".parse().unwrap())],
0, // metric
);
if let Some(change) = rib.update(route) {
fib.apply(&change).unwrap(); // program your data plane
}
}
Identify a candidate
Within a routing table the candidate’s identity includes its prefix, origin protocol and source discriminator. Updating the same candidate replaces it. A different candidate may become the winner after a withdrawal.
Interpret the result
| RIB change | Consumer action |
|---|---|
Some(FibChange::Install(...)) | Install or replace the selected route. |
Some(FibChange::Remove(...)) (on withdrawal) | Remove the prefix after its last eligible route disappears. |
None | The selected forwarding entry is unchanged. |
Choose the backend
Use MemoryFib for in-process tests. A separate integration can implement Fib or consume the daemon’s route stream. To exercise route selection independently of Linux, run cargo test --locked -p wren-core from the workspace root. Core API and tests