pub struct Rib { /* private fields */ }Expand description
The Routing Information Base.
Sits between routing protocols / static config and the FIB. Each route is
stored with an origin value that identifies who installed it, and an
optional expiration time. When routes change the caller invokes
apply_to_fib to push the computed best nexthops into the FIB.
§RIB-to-FIB computation
For each name prefix the RIB collapses all registered routes to a single
FibEntry by selecting, per unique face_id, the route with the lowest
cost (ties broken by lowest origin value). The resulting nexthop set is
atomically written to the FIB via Fib::set_nexthops.
§Multiple concurrent protocols
Each protocol uses a distinct origin value. All their routes coexist in the
RIB; the FIB sees only the best computed result. Stopping a protocol with
flush_origin removes its routes and recomputes the FIB for affected
prefixes, revealing routes from other protocols that may have been shadowed.
§Note on discovery-managed routes
Discovery protocols (link-local neighbor discovery) write directly to the
FIB via EngineDiscoveryContext. Those routes are not tracked in the
RIB. For a given prefix, the RIB and discovery subsystem should not both
manage the same face — in practice they target disjoint prefix ranges
(/ndn/local/… for discovery, global prefixes for routing protocols).
Implementations§
Source§impl Rib
impl Rib
pub fn new() -> Self
Sourcepub fn add(&self, prefix: &Name, route: RibRoute) -> bool
pub fn add(&self, prefix: &Name, route: RibRoute) -> bool
Register or update a route.
Routes are keyed by (face_id, origin). If a route with the same key
already exists, it is replaced. Returns true if the FIB should be
recomputed for this prefix (i.e. something actually changed).
Sourcepub fn remove(&self, prefix: &Name, face_id: FaceId, origin: u64) -> bool
pub fn remove(&self, prefix: &Name, face_id: FaceId, origin: u64) -> bool
Remove a specific (face_id, origin) route from a prefix.
Returns true if the route was found and removed.
Sourcepub fn remove_nexthop(&self, prefix: &Name, face_id: FaceId) -> bool
pub fn remove_nexthop(&self, prefix: &Name, face_id: FaceId) -> bool
Remove all routes for (prefix, face_id) regardless of origin.
Returns true if any routes were removed.
Sourcepub fn flush_origin(&self, origin: u64) -> Vec<Name>
pub fn flush_origin(&self, origin: u64) -> Vec<Name>
Remove all routes registered by origin.
Returns the list of affected prefixes. Callers should call
apply_to_fib for each returned prefix to update the FIB.
Sourcepub fn flush_face(&self, face_id: FaceId) -> Vec<Name>
pub fn flush_face(&self, face_id: FaceId) -> Vec<Name>
Remove all routes via face_id.
Returns the list of affected prefixes. Callers should call
apply_to_fib for each returned prefix to update the FIB.
Sourcepub fn drain_expired(&self) -> Vec<Name>
pub fn drain_expired(&self) -> Vec<Name>
Drain all expired entries.
Returns the list of affected prefixes. Callers should call
apply_to_fib for each returned prefix to update the FIB.
Sourcepub fn apply_to_fib(&self, prefix: &Name, fib: &Fib)
pub fn apply_to_fib(&self, prefix: &Name, fib: &Fib)
Compute the best nexthops for prefix and apply them to the FIB.
For each unique face_id, selects the route with the lowest cost (ties
broken by lowest origin value). Atomically replaces the FIB entry with
the computed nexthops, or removes the entry if no routes remain.
Sourcepub fn handle_face_down(&self, face_id: FaceId, fib: &Fib)
pub fn handle_face_down(&self, face_id: FaceId, fib: &Fib)
Handle a face going down: flush all RIB routes via that face and recompute affected FIB entries.
Call this alongside Fib::remove_face for a complete face teardown.
The two operations are complementary: Fib::remove_face cleans up
discovery-managed routes that are not tracked in the RIB; this method
cleans up routing-protocol-managed routes.