ICE-NET/workspace/crates/icenet-routing/tests/routing.rs
loki5512344 2e61688eb3
Some checks failed
rust-ci / checks (push) Has been cancelled
Initial import: ICE-NET research docs and Rust workspace (v0.4)
- Rust workspace: 7 library crates, icenetd CLI, icenet-city (Slint GUI)
- Sim: fix false Delivered after a route cut, derive traffic class from
  payload size, per-link airtime slots (link capacity, queueing)
- Docs: single docs/STATUS.md for all figures, remove v0.2/egui leftovers,
  drop unimplemented seed claims, uncheck store-and-forward
- License: LGPL-3.0-or-later (LICENSE, LICENSES/GPL-3.0.txt)
2026-11-13 12:28:48 +01:00

111 lines
2.7 KiB
Rust

use icenet_core::{LinkKind, NodeId, TrafficClass};
use icenet_routing::{Link, choose_path};
#[test]
fn bulk_never_uses_slow_radio() {
let nodes = [NodeId(1), NodeId(2), NodeId(3)];
let links = [
Link {
a: nodes[0],
b: nodes[1],
kind: LinkKind::SlowRadio,
enabled: true,
},
Link {
a: nodes[1],
b: nodes[2],
kind: LinkKind::SlowRadio,
enabled: true,
},
];
assert!(
choose_path(
&nodes,
&links,
nodes[0],
nodes[2],
TrafficClass::Bulk,
50_000
)
.is_none()
);
assert!(choose_path(&nodes, &links, nodes[0], nodes[2], TrafficClass::Text, 10).is_some());
}
#[test]
fn chooses_fast_route_when_bulk_is_allowed() {
let nodes = [NodeId(1), NodeId(2), NodeId(3)];
let links = [
Link {
a: nodes[0],
b: nodes[1],
kind: LinkKind::FastWireless,
enabled: true,
},
Link {
a: nodes[1],
b: nodes[2],
kind: LinkKind::Wired,
enabled: true,
},
];
let chosen = choose_path(
&nodes,
&links,
nodes[0],
nodes[2],
TrafficClass::Bulk,
5_000_000,
);
assert_eq!(chosen.expect("connected").nodes, nodes);
}
#[test]
fn disabled_bridge_breaks_route() {
let nodes = [NodeId(1), NodeId(2)];
let links = [Link {
a: nodes[0],
b: nodes[1],
kind: LinkKind::Wired,
enabled: false,
}];
assert!(choose_path(&nodes, &links, nodes[0], nodes[1], TrafficClass::Text, 5).is_none());
}
#[test]
fn equal_cost_paths_use_a_stable_lexicographic_tie_break() {
let nodes = [NodeId(1), NodeId(2), NodeId(3), NodeId(4)];
let forward = [
Link {
a: nodes[0],
b: nodes[1],
kind: LinkKind::Wired,
enabled: true,
},
Link {
a: nodes[1],
b: nodes[3],
kind: LinkKind::Wired,
enabled: true,
},
Link {
a: nodes[0],
b: nodes[2],
kind: LinkKind::Wired,
enabled: true,
},
Link {
a: nodes[2],
b: nodes[3],
kind: LinkKind::Wired,
enabled: true,
},
];
let mut reversed = forward;
reversed.reverse();
for links in [&forward, &reversed] {
let path = choose_path(&nodes, links, nodes[0], nodes[3], TrafficClass::Text, 10)
.expect("diamond is connected");
assert_eq!(path.nodes, [NodeId(1), NodeId(2), NodeId(4)]);
}
}