Skip to main content

Crate pamoja_routing

Crate pamoja_routing 

Source
Expand description

Cost-aware mesh routing for the pamoja SDK.

Flooding gets a packet across a mesh by having every node rebroadcast it, which always works but is expensive: every node spends airtime and power on every packet. Once a mesh has settled, most traffic goes to a few known places, and a node that remembers the way can forward a packet to just the right neighbor instead of shouting it to the whole network. That is routing, and on the cheap radios this SDK targets the saving in airtime and battery is the difference between a network that lasts and one that does not.

This crate is the decision layer for that, as pure logic with no radio and no allocation:

  • Router - a fixed-size table that learns the way to a node from the traffic it already hears: when a packet from a distant node arrives via a neighbor, that neighbor is the way back, at the cost the packet reports. The table keeps the cheapest way it knows to each destination and forgets the most expensive when it runs out of room.
  • Router::forward - the per-packet decision: deliver a packet that is for this node, relay one toward a known destination, or flood when there is no route yet. That last case is where this layer hands back to the flooding in pamoja-mesh, so routing is an optimization over flooding, never a single point of failure.

Nodes are identified by the same address a pamoja-mesh frame carries, so the two compose directly: learn from a received frame’s source and the neighbor it came from, then ask forward where the next one should go.

§Examples

use pamoja_routing::{Forward, Router};

// A gateway, node 1, on a farm mesh: the pump at node 9 is out of its range, and two
// fence posts, nodes 5 and 7, relay for it.
let (gateway, pump, east_post, west_post, weather_mast) = (1, 9, 5, 7, 32);
let mut router: Router<16> = Router::new(gateway);

// The pump's traffic arrives through the east post, two hops out.
router.observe(pump, east_post, 2);
assert_eq!(router.forward(pump), Forward::Relay(east_post));

// A cheaper way to the pump turns up through the west post, and the router prefers it.
router.observe(pump, west_post, 1);
assert_eq!(router.forward(pump), Forward::Relay(west_post));

// With no route to the weather mast yet, the router falls back to flooding.
assert_eq!(router.forward(weather_mast), Forward::Flood);

Structs§

DynamicRouter
A routing table whose size is chosen when it is built, rather than at compile time.
Route
A learned route to a destination: the neighbor to send through, and the cost.
Router
A fixed-size routing table for one node.

Enums§

Forward
What to do with a packet bound for a given destination.