Initial import: ICE-NET research docs and Rust workspace (v0.4)
Some checks failed
rust-ci / checks (push) Has been cancelled
Some checks failed
rust-ci / checks (push) Has been cancelled
- 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)
This commit is contained in:
commit
2e61688eb3
141 changed files with 13993 additions and 0 deletions
8
workspace/crates/icenet-routing/Cargo.toml
Normal file
8
workspace/crates/icenet-routing/Cargo.toml
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
[package]
|
||||
name = "icenet-routing"
|
||||
version.workspace = true
|
||||
edition.workspace = true
|
||||
license.workspace = true
|
||||
|
||||
[dependencies]
|
||||
icenet-core = { path = "../icenet-core" }
|
||||
138
workspace/crates/icenet-routing/src/lib.rs
Normal file
138
workspace/crates/icenet-routing/src/lib.rs
Normal file
|
|
@ -0,0 +1,138 @@
|
|||
//! Deterministic, constrained shortest-path selection for graph experiments.
|
||||
//!
|
||||
//! This crate does not claim to predict radio-wave propagation.
|
||||
#![forbid(unsafe_code)]
|
||||
#![warn(missing_docs)]
|
||||
|
||||
use std::cmp::Reverse;
|
||||
use std::collections::{BTreeMap, BTreeSet, BinaryHeap};
|
||||
|
||||
use icenet_core::{LinkKind, NodeId, TrafficClass};
|
||||
|
||||
/// Fixed per-hop framing and turnaround cost, in milliseconds of airtime.
|
||||
pub const HOP_OVERHEAD_MS: u64 = 10;
|
||||
|
||||
/// An undirected available/disabled link in the simulated topology.
|
||||
#[derive(Clone, Copy, Debug)]
|
||||
pub struct Link {
|
||||
/// First endpoint.
|
||||
pub a: NodeId,
|
||||
/// Second endpoint.
|
||||
pub b: NodeId,
|
||||
/// Category used for eligibility and nominal throughput.
|
||||
pub kind: LinkKind,
|
||||
/// Whether the link is currently available.
|
||||
pub enabled: bool,
|
||||
}
|
||||
|
||||
/// Result of a constrained route lookup.
|
||||
#[derive(Clone, Debug, Eq, PartialEq)]
|
||||
pub struct Path {
|
||||
/// Ordered endpoint IDs, including source and destination.
|
||||
pub nodes: Vec<NodeId>,
|
||||
/// Index into the `links` slice of every hop, in travel order.
|
||||
///
|
||||
/// Parallel links between the same two nodes stay distinguishable.
|
||||
pub links: Vec<usize>,
|
||||
/// Illustrative serialization latency, not a real RTT estimate.
|
||||
pub estimated_ms: u64,
|
||||
}
|
||||
|
||||
/// Returns a deterministic eligible path, or `None` when disconnected.
|
||||
///
|
||||
/// # Arguments
|
||||
/// - `nodes`: Active node IDs in the simulated graph.
|
||||
/// - `links`: Candidate undirected links.
|
||||
/// - `class`: Declared class; it is raised to the size-derived effective class
|
||||
/// (see [`TrafficClass::effective_for`]) before slow radio links are judged.
|
||||
/// - `size_bytes`: Data size for illustrative weighted costs.
|
||||
///
|
||||
/// # Returns
|
||||
/// A path optimized for approximate serialization cost.
|
||||
#[must_use]
|
||||
pub fn choose_path(
|
||||
nodes: &[NodeId],
|
||||
links: &[Link],
|
||||
source: NodeId,
|
||||
destination: NodeId,
|
||||
class: TrafficClass,
|
||||
size_bytes: u64,
|
||||
) -> Option<Path> {
|
||||
let class = class.effective_for(size_bytes);
|
||||
let active: BTreeSet<NodeId> = nodes.iter().copied().collect();
|
||||
if !active.contains(&source) || !active.contains(&destination) {
|
||||
return None;
|
||||
}
|
||||
let mut distances = BTreeMap::<NodeId, u128>::new();
|
||||
let mut previous = BTreeMap::<NodeId, (NodeId, usize)>::new();
|
||||
let mut seen = BTreeSet::<NodeId>::new();
|
||||
let mut frontier = BinaryHeap::<Reverse<(u128, NodeId)>>::new();
|
||||
let mut adjacency = BTreeMap::<NodeId, Vec<(NodeId, LinkKind, usize)>>::new();
|
||||
for (index, link) in links.iter().enumerate().filter(|(_, link)| link.enabled) {
|
||||
if !active.contains(&link.a) || !active.contains(&link.b) {
|
||||
continue;
|
||||
}
|
||||
adjacency
|
||||
.entry(link.a)
|
||||
.or_default()
|
||||
.push((link.b, link.kind, index));
|
||||
adjacency
|
||||
.entry(link.b)
|
||||
.or_default()
|
||||
.push((link.a, link.kind, index));
|
||||
}
|
||||
distances.insert(source, 0);
|
||||
frontier.push(Reverse((0, source)));
|
||||
while let Some(Reverse((cost, current))) = frontier.pop() {
|
||||
if !seen.insert(current) {
|
||||
continue;
|
||||
}
|
||||
if current == destination {
|
||||
break;
|
||||
}
|
||||
let Some(neighbours) = adjacency.get(¤t) else {
|
||||
continue;
|
||||
};
|
||||
for &(next, kind, index) in neighbours {
|
||||
if kind == LinkKind::SlowRadio && !class.allows_slow_radio() {
|
||||
continue;
|
||||
}
|
||||
if seen.contains(&next) {
|
||||
continue;
|
||||
}
|
||||
let transfer_ms = u128::from(kind.transfer_ms(size_bytes));
|
||||
let proposed = cost
|
||||
.saturating_add(transfer_ms)
|
||||
.saturating_add(u128::from(HOP_OVERHEAD_MS));
|
||||
let known = distances.get(&next).copied();
|
||||
if known.is_none_or(|value| proposed < value) {
|
||||
distances.insert(next, proposed);
|
||||
previous.insert(next, (current, index));
|
||||
frontier.push(Reverse((proposed, next)));
|
||||
} else if known == Some(proposed)
|
||||
&& previous
|
||||
.get(&next)
|
||||
.is_some_and(|&(parent, parent_link)| (current, index) < (parent, parent_link))
|
||||
{
|
||||
previous.insert(next, (current, index));
|
||||
}
|
||||
}
|
||||
}
|
||||
let cost = *distances.get(&destination)?;
|
||||
let mut steps = vec![destination];
|
||||
let mut used = Vec::new();
|
||||
let mut node = destination;
|
||||
while node != source {
|
||||
let &(parent, link) = previous.get(&node)?;
|
||||
node = parent;
|
||||
steps.push(node);
|
||||
used.push(link);
|
||||
}
|
||||
steps.reverse();
|
||||
used.reverse();
|
||||
Some(Path {
|
||||
nodes: steps,
|
||||
links: used,
|
||||
estimated_ms: u64::try_from(cost).unwrap_or(u64::MAX),
|
||||
})
|
||||
}
|
||||
111
workspace/crates/icenet-routing/tests/routing.rs
Normal file
111
workspace/crates/icenet-routing/tests/routing.rs
Normal file
|
|
@ -0,0 +1,111 @@
|
|||
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)]);
|
||||
}
|
||||
}
|
||||
79
workspace/crates/icenet-routing/tests/size_limits.rs
Normal file
79
workspace/crates/icenet-routing/tests/size_limits.rs
Normal file
|
|
@ -0,0 +1,79 @@
|
|||
//! Size limits: a payload label cannot smuggle bulk data onto a slow radio.
|
||||
use icenet_core::{LinkKind, NodeId, TrafficClass};
|
||||
use icenet_routing::{Link, choose_path};
|
||||
|
||||
fn slow_pair() -> ([NodeId; 2], [Link; 1]) {
|
||||
let nodes = [NodeId(1), NodeId(2)];
|
||||
let links = [Link {
|
||||
a: nodes[0],
|
||||
b: nodes[1],
|
||||
kind: LinkKind::SlowRadio,
|
||||
enabled: true,
|
||||
}];
|
||||
(nodes, links)
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn oversized_text_is_treated_as_bulk_and_refused_on_slow_radio() {
|
||||
let (nodes, links) = slow_pair();
|
||||
let at_limit = TrafficClass::TEXT_MAX_BYTES;
|
||||
assert!(
|
||||
choose_path(
|
||||
&nodes,
|
||||
&links,
|
||||
nodes[0],
|
||||
nodes[1],
|
||||
TrafficClass::Text,
|
||||
at_limit
|
||||
)
|
||||
.is_some()
|
||||
);
|
||||
assert!(
|
||||
choose_path(
|
||||
&nodes,
|
||||
&links,
|
||||
nodes[0],
|
||||
nodes[1],
|
||||
TrafficClass::Text,
|
||||
at_limit + 1
|
||||
)
|
||||
.is_none()
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn oversized_control_is_treated_as_text_then_bulk() {
|
||||
let (nodes, links) = slow_pair();
|
||||
let control = TrafficClass::Control;
|
||||
let just_over = TrafficClass::CONTROL_MAX_BYTES + 1;
|
||||
assert!(choose_path(&nodes, &links, nodes[0], nodes[1], control, just_over).is_some());
|
||||
assert!(choose_path(&nodes, &links, nodes[0], nodes[1], control, 1_000_000).is_none());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn path_reports_the_index_of_every_link_it_uses() {
|
||||
let nodes = [NodeId(1), NodeId(2), NodeId(3)];
|
||||
let links = [
|
||||
Link {
|
||||
a: nodes[0],
|
||||
b: nodes[1],
|
||||
kind: LinkKind::SlowRadio,
|
||||
enabled: false,
|
||||
},
|
||||
Link {
|
||||
a: nodes[0],
|
||||
b: nodes[1],
|
||||
kind: LinkKind::Wired,
|
||||
enabled: true,
|
||||
},
|
||||
Link {
|
||||
a: nodes[1],
|
||||
b: nodes[2],
|
||||
kind: LinkKind::Wired,
|
||||
enabled: true,
|
||||
},
|
||||
];
|
||||
let path =
|
||||
choose_path(&nodes, &links, nodes[0], nodes[2], TrafficClass::Text, 10).expect("connected");
|
||||
assert_eq!(path.links, [1, 2]);
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue