pub struct DynamicRouter { /* private fields */ }Expand description
A routing table whose size is chosen when it is built, rather than at compile time.
Router fixes its capacity in the type, which suits a microcontroller that knows its
own limits. A gateway, or any caller reaching this through a language binding, does not
know the size until it runs, and a const generic cannot cross a foreign function
boundary at all. This is the same table with its slots on the heap, so both share one
implementation and answer identically.
Requires the alloc feature.
§Examples
use pamoja_routing::{DynamicRouter, Forward};
// A gateway sizes its table for the mesh it is actually serving.
let mut router = DynamicRouter::new(0x01, 512);
router.observe(0x09, 0x05, 2);
assert_eq!(router.forward(0x09), Forward::Relay(0x05));
assert_eq!(router.capacity(), 512);Implementations§
Source§impl DynamicRouter
impl DynamicRouter
Sourcepub fn observe(&mut self, origin: u32, via: u32, cost: u16) -> bool
pub fn observe(&mut self, origin: u32, via: u32, cost: u16) -> bool
Learns the way to a node from a packet heard from it.
§Arguments
origin- the node the packet came from, the destination this route reaches.via- the neighbour the packet arrived through, the next hop for this route.cost- the cost the packet reports for reachingoriginthroughvia.
§Returns
true if the table changed, false if the observation taught it nothing new.
Sourcepub fn forward(&self, dst: u32) -> Forward
pub fn forward(&self, dst: u32) -> Forward
Decides what to do with a packet bound for a destination.
§Arguments
dst- the packet’s destination.
§Returns
Forward::Deliver if the packet is for this node, Forward::Relay with the
next hop if a route is known, or Forward::Flood otherwise.
Sourcepub fn forget(&mut self, dst: u32)
pub fn forget(&mut self, dst: u32)
Forgets the route to a destination, if one is held.
§Arguments
dst- the destination whose route to drop.
Trait Implementations§
Source§impl Clone for DynamicRouter
impl Clone for DynamicRouter
Source§fn clone(&self) -> DynamicRouter
fn clone(&self) -> DynamicRouter
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more