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)
101 lines
3.2 KiB
Rust
101 lines
3.2 KiB
Rust
//! Link capacity: transmissions share a link in FIFO order instead of overlapping.
|
|
use icenet_core::{LinkKind, NodeId, TrafficClass};
|
|
use icenet_sim::{City, DeliveryState, DeviceRole, metrics};
|
|
|
|
fn pair(kind: LinkKind) -> (City, NodeId, NodeId) {
|
|
let mut city = City::empty();
|
|
let a = city.add_device("a".to_owned(), DeviceRole::Client);
|
|
let b = city.add_device("b".to_owned(), DeviceRole::Client);
|
|
assert!(city.add_link(a, b, kind));
|
|
(city, a, b)
|
|
}
|
|
|
|
fn delivered(city: &City) -> usize {
|
|
city.messages
|
|
.iter()
|
|
.filter(|m| m.status == DeliveryState::Delivered)
|
|
.count()
|
|
}
|
|
|
|
#[test]
|
|
fn texts_queue_behind_each_other_on_one_slow_link() {
|
|
let (mut city, a, b) = pair(LinkKind::SlowRadio);
|
|
// 200 B at 1 kbit/s is 1600 ms of airtime plus 10 ms overhead each.
|
|
for _ in 0..100 {
|
|
city.send(a, b, TrafficClass::Text, 200);
|
|
}
|
|
city.tick(2_000);
|
|
assert_eq!(delivered(&city), 1, "only one 1610 ms frame fits in 2 s");
|
|
city.tick(161_000 - 2_000);
|
|
assert_eq!(delivered(&city), 100);
|
|
}
|
|
|
|
#[test]
|
|
fn due_times_are_strictly_ordered_by_link_reservation() {
|
|
let (mut city, a, b) = pair(LinkKind::SlowRadio);
|
|
let first = city.send(a, b, TrafficClass::Text, 200);
|
|
let second = city.send(a, b, TrafficClass::Text, 200);
|
|
let due = |id| {
|
|
city.messages
|
|
.iter()
|
|
.find(|m| m.id == id)
|
|
.and_then(|m| m.due_ms)
|
|
};
|
|
assert_eq!(due(first), Some(1_610));
|
|
assert_eq!(due(second), Some(3_220));
|
|
}
|
|
|
|
#[test]
|
|
fn an_idle_link_does_not_delay_the_next_message() {
|
|
let (mut city, a, b) = pair(LinkKind::SlowRadio);
|
|
city.send(a, b, TrafficClass::Text, 200);
|
|
city.tick(10_000);
|
|
let id = city.send(a, b, TrafficClass::Text, 200);
|
|
let message = city.messages.iter().find(|m| m.id == id).expect("message");
|
|
assert_eq!(message.due_ms, Some(10_000 + 1_610));
|
|
}
|
|
|
|
#[test]
|
|
fn backlog_can_push_a_message_past_its_ttl() {
|
|
let (mut city, a, b) = pair(LinkKind::SlowRadio);
|
|
for _ in 0..3 {
|
|
city.send(a, b, TrafficClass::Text, 200);
|
|
}
|
|
let late = city.send_with_ttl(a, b, TrafficClass::Text, 200, 5_000);
|
|
city.tick(5_000);
|
|
let status = city
|
|
.messages
|
|
.iter()
|
|
.find(|m| m.id == late)
|
|
.expect("late")
|
|
.status;
|
|
assert_eq!(
|
|
status,
|
|
DeliveryState::Expired,
|
|
"airtime backlog ate the TTL"
|
|
);
|
|
}
|
|
|
|
#[test]
|
|
fn oversized_text_never_consumes_slow_radio_airtime() {
|
|
let (mut city, a, b) = pair(LinkKind::SlowRadio);
|
|
let id = city.send(a, b, TrafficClass::Text, 5_000_000);
|
|
let status = city
|
|
.messages
|
|
.iter()
|
|
.find(|m| m.id == id)
|
|
.expect("message")
|
|
.status;
|
|
assert_eq!(status, DeliveryState::Queued);
|
|
assert_eq!(city.link_airtime_ms(LinkKind::SlowRadio), 0);
|
|
assert_eq!(metrics::summarize(&city).slow_radio_airtime_ms, 0);
|
|
}
|
|
|
|
#[test]
|
|
fn airtime_is_reported_per_link_kind() {
|
|
let (mut city, a, b) = pair(LinkKind::SlowRadio);
|
|
city.send(a, b, TrafficClass::Text, 200);
|
|
assert_eq!(city.link_airtime_ms(LinkKind::SlowRadio), 1_610);
|
|
assert_eq!(city.link_airtime_ms(LinkKind::Wired), 0);
|
|
assert_eq!(metrics::summarize(&city).slow_radio_airtime_ms, 1_610);
|
|
}
|