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
16
workspace/apps/icenet-city/Cargo.toml
Normal file
16
workspace/apps/icenet-city/Cargo.toml
Normal file
|
|
@ -0,0 +1,16 @@
|
|||
[package]
|
||||
name = "icenet-city"
|
||||
version.workspace = true
|
||||
edition.workspace = true
|
||||
license.workspace = true
|
||||
build = "build.rs"
|
||||
|
||||
[dependencies]
|
||||
icenet-core = { path = "../../crates/icenet-core" }
|
||||
icenet-sim = { path = "../../crates/icenet-sim" }
|
||||
slint = { version = "=1.18.1", default-features = false, features = [
|
||||
"std", "backend-winit", "renderer-software", "compat-1-18",
|
||||
] }
|
||||
|
||||
[build-dependencies]
|
||||
slint-build = "=1.18.1"
|
||||
6
workspace/apps/icenet-city/build.rs
Normal file
6
workspace/apps/icenet-city/build.rs
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
//! Compile the declarative interface without including GUI code in domain crates.
|
||||
|
||||
/// Compiles the Slint UI into generated Rust bindings.
|
||||
fn main() {
|
||||
slint_build::compile("ui/main.slint").expect("Slint UI compilation failed");
|
||||
}
|
||||
5
workspace/apps/icenet-city/src/lib.rs
Normal file
5
workspace/apps/icenet-city/src/lib.rs
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
//! Slint application adapter for the deterministic ICE-NET city simulator.
|
||||
pub mod state;
|
||||
pub mod view;
|
||||
|
||||
slint::include_modules!();
|
||||
119
workspace/apps/icenet-city/src/main.rs
Normal file
119
workspace/apps/icenet-city/src/main.rs
Normal file
|
|
@ -0,0 +1,119 @@
|
|||
//! Standalone Slint GUI for offline ICE-NET city routing experiments.
|
||||
use icenet_city::{CityWindow, state::UiState, view};
|
||||
use slint::{ComponentHandle, Weak};
|
||||
use std::{cell::RefCell, rc::Rc};
|
||||
|
||||
/// Performs a state command and refreshes the window, if it still exists.
|
||||
fn apply(weak: &Weak<CityWindow>, state: &Rc<RefCell<UiState>>, change: impl FnOnce(&mut UiState)) {
|
||||
let mut state = state.borrow_mut();
|
||||
change(&mut state);
|
||||
if let Some(ui) = weak.upgrade() {
|
||||
view::refresh(&ui, &state);
|
||||
}
|
||||
}
|
||||
|
||||
/// Registers UI callbacks without allowing the simulator to depend on Slint.
|
||||
fn register_callbacks(ui: &CityWindow, state: Rc<RefCell<UiState>>) {
|
||||
{
|
||||
let state = state.clone();
|
||||
let weak = ui.as_weak();
|
||||
ui.on_send_text(move || apply(&weak, &state, |s| s.send(false)));
|
||||
}
|
||||
{
|
||||
let state = state.clone();
|
||||
let weak = ui.as_weak();
|
||||
ui.on_send_photo(move || apply(&weak, &state, |s| s.send(true)));
|
||||
}
|
||||
{
|
||||
let state = state.clone();
|
||||
let weak = ui.as_weak();
|
||||
ui.on_export_csv(move || apply(&weak, &state, UiState::export_default_csv));
|
||||
}
|
||||
{
|
||||
let state = state.clone();
|
||||
let weak = ui.as_weak();
|
||||
ui.on_export_json(move || apply(&weak, &state, UiState::export_default_json));
|
||||
}
|
||||
{
|
||||
let state = state.clone();
|
||||
let weak = ui.as_weak();
|
||||
ui.on_next_from(move || apply(&weak, &state, |s| s.cycle_endpoint(true)));
|
||||
}
|
||||
{
|
||||
let state = state.clone();
|
||||
let weak = ui.as_weak();
|
||||
ui.on_next_to(move || apply(&weak, &state, |s| s.cycle_endpoint(false)));
|
||||
}
|
||||
{
|
||||
let state = state.clone();
|
||||
let weak = ui.as_weak();
|
||||
ui.on_next_role(move || apply(&weak, &state, UiState::cycle_role));
|
||||
}
|
||||
{
|
||||
let state = state.clone();
|
||||
let weak = ui.as_weak();
|
||||
ui.on_next_link_kind(move || apply(&weak, &state, UiState::cycle_link_kind));
|
||||
}
|
||||
{
|
||||
let state = state.clone();
|
||||
let weak = ui.as_weak();
|
||||
ui.on_add_node(move || apply(&weak, &state, UiState::add_node));
|
||||
}
|
||||
{
|
||||
let state = state.clone();
|
||||
let weak = ui.as_weak();
|
||||
ui.on_connect_nodes(move || apply(&weak, &state, UiState::connect));
|
||||
}
|
||||
{
|
||||
let state = state.clone();
|
||||
let weak = ui.as_weak();
|
||||
ui.on_toggle_node(move |id| apply(&weak, &state, |s| s.toggle_node(id)));
|
||||
}
|
||||
{
|
||||
let state = state.clone();
|
||||
let weak = ui.as_weak();
|
||||
ui.on_toggle_link(move |index| apply(&weak, &state, |s| s.toggle_link(index)));
|
||||
}
|
||||
{
|
||||
let state = state.clone();
|
||||
ui.on_drag_start(move |id, x, y| state.borrow_mut().start_drag(id, x, y));
|
||||
}
|
||||
{
|
||||
let state = state.clone();
|
||||
let weak = ui.as_weak();
|
||||
ui.on_drag_move(move |x, y| {
|
||||
let mut state = state.borrow_mut();
|
||||
state.drag_to(x, y);
|
||||
if let Some(ui) = weak.upgrade() {
|
||||
view::drag(&ui, &state);
|
||||
}
|
||||
});
|
||||
}
|
||||
{
|
||||
let state = state.clone();
|
||||
let weak = ui.as_weak();
|
||||
ui.on_drag_end(move || apply(&weak, &state, UiState::end_drag));
|
||||
}
|
||||
{
|
||||
let state = state.clone();
|
||||
let weak = ui.as_weak();
|
||||
ui.on_advance(move |elapsed| {
|
||||
apply(&weak, &state, |s| {
|
||||
s.city.tick(u64::try_from(elapsed).unwrap_or(0));
|
||||
})
|
||||
});
|
||||
}
|
||||
{
|
||||
let weak = ui.as_weak();
|
||||
ui.on_reset_city(move || apply(&weak, &state, |s| *s = UiState::default()));
|
||||
}
|
||||
}
|
||||
|
||||
/// Starts the desktop simulator. The event loop is owned by Slint.
|
||||
fn main() -> Result<(), slint::PlatformError> {
|
||||
let ui = CityWindow::new()?;
|
||||
let state = Rc::new(RefCell::new(UiState::default()));
|
||||
view::refresh(&ui, &state.borrow());
|
||||
register_callbacks(&ui, state);
|
||||
ui.run()
|
||||
}
|
||||
194
workspace/apps/icenet-city/src/state.rs
Normal file
194
workspace/apps/icenet-city/src/state.rs
Normal file
|
|
@ -0,0 +1,194 @@
|
|||
//! GUI-independent commands applied to the city simulator.
|
||||
use std::{io, path::Path};
|
||||
|
||||
use icenet_core::{LinkKind, NodeId, TrafficClass};
|
||||
use icenet_sim::{City, DeviceRole, metrics};
|
||||
|
||||
const CSV_FILE: &str = "icenet-metrics.csv";
|
||||
const JSON_FILE: &str = "icenet-scenario.json";
|
||||
|
||||
/// Grab state for stable pointer dragging of one node.
|
||||
#[derive(Clone, Copy, Debug)]
|
||||
pub struct Drag {
|
||||
id: NodeId,
|
||||
node_x: f32,
|
||||
node_y: f32,
|
||||
pointer_x: f32,
|
||||
pointer_y: f32,
|
||||
}
|
||||
|
||||
/// Mutable state of the standalone city editor.
|
||||
#[derive(Debug)]
|
||||
pub struct UiState {
|
||||
/// Deterministic offline city graph.
|
||||
pub city: City,
|
||||
/// Current sender in the sample graph.
|
||||
pub from: NodeId,
|
||||
/// Current recipient in the sample graph.
|
||||
pub to: NodeId,
|
||||
/// New node role selected in the editor.
|
||||
pub role: DeviceRole,
|
||||
/// New link technology selected in the editor.
|
||||
pub link_kind: LinkKind,
|
||||
/// Human-readable result of the last export action.
|
||||
pub last_export: String,
|
||||
drag: Option<Drag>,
|
||||
}
|
||||
|
||||
impl Default for UiState {
|
||||
fn default() -> Self {
|
||||
Self {
|
||||
city: City::demo(),
|
||||
from: NodeId(1),
|
||||
to: NodeId(3),
|
||||
role: DeviceRole::Client,
|
||||
link_kind: LinkKind::FastWireless,
|
||||
last_export: String::new(),
|
||||
drag: None,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl UiState {
|
||||
/// Cycles through available sender or recipient IDs.
|
||||
pub fn cycle_endpoint(&mut self, sender: bool) {
|
||||
let current = if sender { self.from } else { self.to };
|
||||
let ids: Vec<NodeId> = self.city.devices.iter().map(|d| d.id).collect();
|
||||
if ids.is_empty() {
|
||||
return;
|
||||
}
|
||||
let index = ids.iter().position(|id| *id == current).unwrap_or(0);
|
||||
let next = ids[(index + 1) % ids.len()];
|
||||
if sender {
|
||||
self.from = next;
|
||||
} else {
|
||||
self.to = next;
|
||||
}
|
||||
}
|
||||
|
||||
/// Cycles among client, relay and backbone device roles.
|
||||
pub fn cycle_role(&mut self) {
|
||||
self.role = match self.role {
|
||||
DeviceRole::Client => DeviceRole::Relay,
|
||||
DeviceRole::Relay => DeviceRole::Backbone,
|
||||
DeviceRole::Backbone => DeviceRole::Client,
|
||||
};
|
||||
}
|
||||
|
||||
/// Cycles among simulated radio, Wi-Fi, cable and internet links.
|
||||
pub fn cycle_link_kind(&mut self) {
|
||||
self.link_kind = match self.link_kind {
|
||||
LinkKind::SlowRadio => LinkKind::FastWireless,
|
||||
LinkKind::FastWireless => LinkKind::Wired,
|
||||
LinkKind::Wired => LinkKind::Internet,
|
||||
LinkKind::Internet => LinkKind::SlowRadio,
|
||||
};
|
||||
}
|
||||
|
||||
/// Adds a new device and selects it as recipient.
|
||||
pub fn add_node(&mut self) {
|
||||
let label = format!("New {:?} {}", self.role, self.city.devices.len() + 1);
|
||||
self.to = self.city.add_device(label, self.role);
|
||||
}
|
||||
|
||||
/// Adds a link between the selected endpoints, if valid.
|
||||
pub fn connect(&mut self) {
|
||||
self.city.add_link(self.from, self.to, self.link_kind);
|
||||
}
|
||||
|
||||
/// Toggles a device's online state.
|
||||
pub fn toggle_node(&mut self, id: i32) {
|
||||
let update = self
|
||||
.city
|
||||
.devices
|
||||
.iter()
|
||||
.find(|d| d.id.0 == id as u64)
|
||||
.map(|device| (device.id, !device.online));
|
||||
if let Some((id, online)) = update {
|
||||
self.city.set_device_online(id, online);
|
||||
}
|
||||
}
|
||||
|
||||
/// Toggles a link by its visible index.
|
||||
pub fn toggle_link(&mut self, index: i32) {
|
||||
if let Ok(index) = usize::try_from(index)
|
||||
&& let Some(enabled) = self.city.links.get(index).map(|link| !link.enabled)
|
||||
{
|
||||
self.city.set_link_enabled(index, enabled);
|
||||
}
|
||||
}
|
||||
|
||||
/// Remembers the node and pointer position when a drag begins.
|
||||
pub fn start_drag(&mut self, id: i32, pointer_x: f32, pointer_y: f32) {
|
||||
let id = NodeId(id as u64);
|
||||
if let Some(device) = self.city.devices.iter().find(|device| device.id == id) {
|
||||
self.drag = Some(Drag {
|
||||
id,
|
||||
node_x: device.x,
|
||||
node_y: device.y,
|
||||
pointer_x,
|
||||
pointer_y,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
/// Moves the grabbed node by the pointer delta from the drag start.
|
||||
pub fn drag_to(&mut self, pointer_x: f32, pointer_y: f32) {
|
||||
if let Some(drag) = self.drag {
|
||||
self.city.move_device(
|
||||
drag.id,
|
||||
(drag.node_x + pointer_x - drag.pointer_x).clamp(20.0, 520.0),
|
||||
(drag.node_y + pointer_y - drag.pointer_y).clamp(20.0, 310.0),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/// Releases the current drag, if any.
|
||||
pub fn end_drag(&mut self) {
|
||||
self.drag = None;
|
||||
}
|
||||
|
||||
/// Sends synthetic text or bulk data; no real bytes leave this process.
|
||||
pub fn send(&mut self, bulk: bool) {
|
||||
let (kind, size) = if bulk {
|
||||
(TrafficClass::Bulk, 5 * 1024 * 1024)
|
||||
} else {
|
||||
(TrafficClass::Text, 128)
|
||||
};
|
||||
self.city.send(self.from, self.to, kind, size);
|
||||
}
|
||||
|
||||
/// Writes deterministic message metrics to `path`.
|
||||
///
|
||||
/// # Errors
|
||||
/// Returns the underlying I/O error when the file cannot be written.
|
||||
pub fn export_csv(&mut self, path: &Path) -> io::Result<()> {
|
||||
std::fs::write(path, metrics::messages_csv(&self.city))?;
|
||||
self.last_export = format!("Exported {}", path.display());
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Writes the full scenario to `path` as deterministic JSON.
|
||||
///
|
||||
/// # Errors
|
||||
/// Returns the underlying I/O error when the file cannot be written.
|
||||
pub fn export_json(&mut self, path: &Path) -> io::Result<()> {
|
||||
std::fs::write(path, metrics::scenario_json(&self.city))?;
|
||||
self.last_export = format!("Exported {}", path.display());
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Writes `icenet-metrics.csv` in the process working directory.
|
||||
pub fn export_default_csv(&mut self) {
|
||||
if let Err(error) = self.export_csv(Path::new(CSV_FILE)) {
|
||||
self.last_export = format!("Export failed: {error}");
|
||||
}
|
||||
}
|
||||
|
||||
/// Writes `icenet-scenario.json` in the process working directory.
|
||||
pub fn export_default_json(&mut self) {
|
||||
if let Err(error) = self.export_json(Path::new(JSON_FILE)) {
|
||||
self.last_export = format!("Export failed: {error}");
|
||||
}
|
||||
}
|
||||
}
|
||||
140
workspace/apps/icenet-city/src/view.rs
Normal file
140
workspace/apps/icenet-city/src/view.rs
Normal file
|
|
@ -0,0 +1,140 @@
|
|||
//! Translate simulation state into Slint models without introducing UI into core crates.
|
||||
use crate::{CityWindow, UiLink, UiNode, state::UiState};
|
||||
use icenet_core::NodeId;
|
||||
use icenet_sim::{City, DeliveryState};
|
||||
use slint::{Color, Model, VecModel};
|
||||
|
||||
/// Updates node and link rows in place so an active drag is not interrupted.
|
||||
pub fn drag(ui: &CityWindow, state: &UiState) {
|
||||
if let Some(nodes) = ui.get_nodes().as_any().downcast_ref::<VecModel<UiNode>>() {
|
||||
for (index, device) in state.city.devices.iter().enumerate() {
|
||||
let Some(mut node) = nodes.row_data(index) else {
|
||||
continue;
|
||||
};
|
||||
node.px = device.x;
|
||||
node.py = device.y;
|
||||
nodes.set_row_data(index, node);
|
||||
}
|
||||
}
|
||||
if let Some(links) = ui.get_links().as_any().downcast_ref::<VecModel<UiLink>>() {
|
||||
for (index, link) in state.city.links.iter().enumerate() {
|
||||
let Some(mut row) = links.row_data(index) else {
|
||||
continue;
|
||||
};
|
||||
let (Some(a), Some(b)) = (device(&state.city, link.a), device(&state.city, link.b))
|
||||
else {
|
||||
continue;
|
||||
};
|
||||
row.ax = a.x;
|
||||
row.ay = a.y;
|
||||
row.bx = b.x;
|
||||
row.by = b.y;
|
||||
links.set_row_data(index, row);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn device(city: &City, id: NodeId) -> Option<&icenet_sim::Device> {
|
||||
city.devices.iter().find(|device| device.id == id)
|
||||
}
|
||||
|
||||
/// Applies one immutable simulator snapshot to the Slint window.
|
||||
pub fn refresh(ui: &CityWindow, state: &UiState) {
|
||||
let route = state
|
||||
.city
|
||||
.messages
|
||||
.last()
|
||||
.map(|m| m.route.as_slice())
|
||||
.unwrap_or(&[]);
|
||||
let nodes: Vec<UiNode> = state
|
||||
.city
|
||||
.devices
|
||||
.iter()
|
||||
.map(|device| UiNode {
|
||||
id: device.id.0 as i32,
|
||||
label: device.label.as_str().into(),
|
||||
px: device.x,
|
||||
py: device.y,
|
||||
online: device.online,
|
||||
})
|
||||
.collect();
|
||||
ui.set_nodes(VecModel::from_slice(&nodes));
|
||||
|
||||
let links: Vec<UiLink> = state
|
||||
.city
|
||||
.links
|
||||
.iter()
|
||||
.map(|link| {
|
||||
let a = state.city.devices.iter().find(|d| d.id == link.a);
|
||||
let b = state.city.devices.iter().find(|d| d.id == link.b);
|
||||
let (ax, ay, bx, by) = match (a, b) {
|
||||
(Some(a), Some(b)) => (a.x, a.y, b.x, b.y),
|
||||
_ => (0.0, 0.0, 0.0, 0.0),
|
||||
};
|
||||
let enabled =
|
||||
link.enabled && a.is_some_and(|n| n.online) && b.is_some_and(|n| n.online);
|
||||
let highlighted = route
|
||||
.windows(2)
|
||||
.any(|hop| hop == [link.a, link.b] || hop == [link.b, link.a]);
|
||||
UiLink {
|
||||
ax,
|
||||
ay,
|
||||
bx,
|
||||
by,
|
||||
title: format!("{} — {} / {}", link.a.0, link.b.0, link.kind.label()).into(),
|
||||
enabled,
|
||||
highlighted,
|
||||
color: if !enabled {
|
||||
Color::from_rgb_u8(78, 88, 99)
|
||||
} else {
|
||||
link_color(link.kind.label())
|
||||
},
|
||||
}
|
||||
})
|
||||
.collect();
|
||||
ui.set_links(VecModel::from_slice(&links));
|
||||
|
||||
let messages: Vec<slint::SharedString> = state
|
||||
.city
|
||||
.messages
|
||||
.iter()
|
||||
.rev()
|
||||
.take(12)
|
||||
.map(|message| {
|
||||
let status = match message.status {
|
||||
DeliveryState::Queued => "QUEUED",
|
||||
DeliveryState::InFlight => "IN_FLIGHT",
|
||||
DeliveryState::Delivered => "DELIVERED",
|
||||
DeliveryState::Expired => "EXPIRED",
|
||||
};
|
||||
format!(
|
||||
"#{} {} → {} | {:?} | {}",
|
||||
message.id, message.from.0, message.to.0, message.class, status
|
||||
)
|
||||
.into()
|
||||
})
|
||||
.collect();
|
||||
ui.set_messages(VecModel::from_slice(&messages));
|
||||
ui.set_clock(format!("Virtual clock: {} ms", state.city.now_ms).into());
|
||||
ui.set_from_label(endpoint_name(&state.city, state.from).into());
|
||||
ui.set_to_label(endpoint_name(&state.city, state.to).into());
|
||||
ui.set_role_label(format!("Role: {:?}", state.role).into());
|
||||
ui.set_link_label(format!("New link: {}", state.link_kind.label()).into());
|
||||
ui.set_export_status(state.last_export.as_str().into());
|
||||
}
|
||||
|
||||
fn endpoint_name(city: &City, id: NodeId) -> String {
|
||||
city.devices.iter().find(|n| n.id == id).map_or_else(
|
||||
|| format!("#{:?}", id.0),
|
||||
|n| format!("{} (#{})", n.label, id.0),
|
||||
)
|
||||
}
|
||||
|
||||
fn link_color(kind: &str) -> Color {
|
||||
match kind {
|
||||
"LoRa (slow)" => Color::from_rgb_u8(230, 177, 94),
|
||||
"Wi-Fi (fast)" => Color::from_rgb_u8(89, 174, 250),
|
||||
"Wired" => Color::from_rgb_u8(73, 222, 164),
|
||||
_ => Color::from_rgb_u8(195, 145, 255),
|
||||
}
|
||||
}
|
||||
11
workspace/apps/icenet-city/tests/smoke.rs
Normal file
11
workspace/apps/icenet-city/tests/smoke.rs
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
use icenet_core::{NodeId, TrafficClass};
|
||||
use icenet_sim::City;
|
||||
|
||||
#[test]
|
||||
fn city_example_contains_bulk_eligible_route() {
|
||||
let city = City::demo();
|
||||
assert!(
|
||||
city.route(NodeId(1), NodeId(3), TrafficClass::Bulk, 5_000_000)
|
||||
.is_some()
|
||||
);
|
||||
}
|
||||
100
workspace/apps/icenet-city/tests/state.rs
Normal file
100
workspace/apps/icenet-city/tests/state.rs
Normal file
|
|
@ -0,0 +1,100 @@
|
|||
//! Regression tests for UI commands with no graphical backend.
|
||||
use icenet_city::state::UiState;
|
||||
use icenet_core::{NodeId, TrafficClass};
|
||||
use icenet_sim::DeliveryState;
|
||||
|
||||
#[test]
|
||||
fn photo_avoids_slow_radio_after_fast_links_are_disabled() {
|
||||
let mut app = UiState::default();
|
||||
for index in [2, 3, 4, 5] {
|
||||
app.city.set_link_enabled(index, false);
|
||||
}
|
||||
app.send(true);
|
||||
assert_eq!(
|
||||
app.city.messages.last().unwrap().status,
|
||||
DeliveryState::Queued
|
||||
);
|
||||
assert!(
|
||||
app.city
|
||||
.route(NodeId(1), NodeId(3), TrafficClass::Text, 128)
|
||||
.is_some()
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn toggling_a_device_and_restarting_are_deterministic() {
|
||||
let mut app = UiState::default();
|
||||
app.toggle_node(2);
|
||||
assert!(
|
||||
!app.city
|
||||
.devices
|
||||
.iter()
|
||||
.find(|d| d.id == NodeId(2))
|
||||
.unwrap()
|
||||
.online
|
||||
);
|
||||
app = UiState::default();
|
||||
assert!(app.city.devices.iter().all(|d| d.online));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn editor_adds_a_link_and_cycles_endpoints() {
|
||||
let mut app = UiState::default();
|
||||
app.add_node();
|
||||
assert_eq!(app.to, NodeId(7));
|
||||
app.connect();
|
||||
assert!(
|
||||
app.city
|
||||
.links
|
||||
.iter()
|
||||
.any(|link| link.a == NodeId(1) && link.b == NodeId(7))
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn drag_uses_a_fixed_start_pointer_offset() {
|
||||
let mut app = UiState::default();
|
||||
app.start_drag(1, 409.0, 186.0);
|
||||
app.drag_to(470.0, 240.0);
|
||||
app.drag_to(530.0, 290.0);
|
||||
let node = app
|
||||
.city
|
||||
.devices
|
||||
.iter()
|
||||
.find(|device| device.id == NodeId(1))
|
||||
.expect("demo node");
|
||||
assert!((node.x - 191.0).abs() < f32::EPSILON);
|
||||
assert!((node.y - 189.0).abs() < f32::EPSILON);
|
||||
app.end_drag();
|
||||
app.drag_to(0.0, 0.0);
|
||||
let node = app
|
||||
.city
|
||||
.devices
|
||||
.iter()
|
||||
.find(|device| device.id == NodeId(1))
|
||||
.expect("demo node");
|
||||
assert!((node.x - 191.0).abs() < f32::EPSILON);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn exports_csv_and_json_to_requested_paths() {
|
||||
let mut app = UiState::default();
|
||||
app.send(false);
|
||||
let stamp = format!("icenet-test-{}", std::process::id());
|
||||
let csv_path = std::env::temp_dir().join(format!("{stamp}.csv"));
|
||||
let json_path = std::env::temp_dir().join(format!("{stamp}.json"));
|
||||
|
||||
app.export_csv(&csv_path).expect("csv export");
|
||||
let csv = std::fs::read_to_string(&csv_path).expect("read csv");
|
||||
assert!(csv.starts_with("id,from,to,class,bytes,status,"));
|
||||
assert_eq!(csv.lines().count(), 2);
|
||||
assert!(app.last_export.contains(&stamp));
|
||||
|
||||
app.export_json(&json_path).expect("json export");
|
||||
let json = std::fs::read_to_string(&json_path).expect("read json");
|
||||
assert!(json.contains("\"messages\""));
|
||||
assert!(json.contains("\"devices\""));
|
||||
|
||||
std::fs::remove_file(csv_path).expect("cleanup csv");
|
||||
std::fs::remove_file(json_path).expect("cleanup json");
|
||||
}
|
||||
206
workspace/apps/icenet-city/ui/main.slint
Normal file
206
workspace/apps/icenet-city/ui/main.slint
Normal file
|
|
@ -0,0 +1,206 @@
|
|||
// A desktop-only city topology editor; all networking logic stays in Rust crates.
|
||||
import { Button, ScrollView } from "std-widgets.slint";
|
||||
|
||||
export struct UiNode {
|
||||
id: int,
|
||||
label: string,
|
||||
px: float,
|
||||
py: float,
|
||||
online: bool,
|
||||
}
|
||||
|
||||
export struct UiLink {
|
||||
ax: float,
|
||||
ay: float,
|
||||
bx: float,
|
||||
by: float,
|
||||
title: string,
|
||||
enabled: bool,
|
||||
highlighted: bool,
|
||||
color: color,
|
||||
}
|
||||
|
||||
export component CityWindow inherits Window {
|
||||
title: "ICE-NET City Lab | Slint";
|
||||
preferred-width: 1140px;
|
||||
preferred-height: 760px;
|
||||
background: #0c131b;
|
||||
|
||||
in property <[UiNode]> nodes;
|
||||
in property <[UiLink]> links;
|
||||
in property <[string]> messages;
|
||||
in property <string> clock;
|
||||
in property <string> from-label;
|
||||
in property <string> to-label;
|
||||
in property <string> role-label;
|
||||
in property <string> link-label;
|
||||
in property <string> export-status;
|
||||
|
||||
callback send-text();
|
||||
callback send-photo();
|
||||
callback export-csv();
|
||||
callback export-json();
|
||||
callback next-from();
|
||||
callback next-to();
|
||||
callback next-role();
|
||||
callback next-link-kind();
|
||||
callback add-node();
|
||||
callback connect-nodes();
|
||||
callback toggle-node(int);
|
||||
callback toggle-link(int);
|
||||
callback drag-start(int, float, float);
|
||||
callback drag-move(float, float);
|
||||
callback drag-end();
|
||||
callback advance(int);
|
||||
callback reset-city();
|
||||
|
||||
HorizontalLayout {
|
||||
padding: 16px;
|
||||
spacing: 14px;
|
||||
side := Rectangle {
|
||||
width: 295px;
|
||||
background: #172533;
|
||||
border-radius: 12px;
|
||||
VerticalLayout {
|
||||
padding: 14px;
|
||||
spacing: 9px;
|
||||
Text { text: "ICE-NET / CITY LAB"; color: #6de0cb; font-size: 20px; font-weight: 700; }
|
||||
Text { text: "Offline graph simulation • no real radio"; color: #adc0ce; font-size: 12px; }
|
||||
Rectangle { height: 1px; background: #344557; }
|
||||
Text { text: "ROUTE"; color: #6de0cb; font-size: 13px; font-weight: 700; }
|
||||
Button { text: "From: " + root.from-label; clicked => { root.next-from(); } }
|
||||
Button { text: "To: " + root.to-label; clicked => { root.next-to(); } }
|
||||
HorizontalLayout {
|
||||
spacing: 5px;
|
||||
Button { text: "Text (128 B)"; clicked => { root.send-text(); } }
|
||||
Button { text: "Photo (5 MiB)"; clicked => { root.send-photo(); } }
|
||||
}
|
||||
Rectangle { height: 1px; background: #344557; }
|
||||
Text { text: "TOPOLOGY EDITOR"; color: #6de0cb; font-size: 13px; font-weight: 700; }
|
||||
Button { text: root.role-label; clicked => { root.next-role(); } }
|
||||
Button { text: "Add device"; clicked => { root.add-node(); } }
|
||||
Button { text: root.link-label; clicked => { root.next-link-kind(); } }
|
||||
Button { text: "Connect selected devices"; clicked => { root.connect-nodes(); } }
|
||||
Text { text: "DEVICES (CLICK TO TOGGLE)"; color: #b5c9d5; font-size: 12px; }
|
||||
ScrollView {
|
||||
height: 92px;
|
||||
VerticalLayout {
|
||||
spacing: 3px;
|
||||
for node in root.nodes: Button {
|
||||
text: node.label + (node.online ? " [ON]" : " [OFF]");
|
||||
clicked => { root.toggle-node(node.id); }
|
||||
}
|
||||
}
|
||||
}
|
||||
Text { text: "LINKS (CLICK TO TOGGLE)"; color: #b5c9d5; font-size: 12px; }
|
||||
ScrollView {
|
||||
height: 82px;
|
||||
VerticalLayout {
|
||||
spacing: 3px;
|
||||
for edge[index] in root.links: Button {
|
||||
text: edge.title + (edge.enabled ? " ON" : " OFF");
|
||||
clicked => { root.toggle-link(index); }
|
||||
}
|
||||
}
|
||||
}
|
||||
Text { text: root.clock; color: #adc0ce; font-size: 12px; }
|
||||
HorizontalLayout {
|
||||
spacing: 5px;
|
||||
Button { text: "+1 sec"; clicked => { root.advance(1000); } }
|
||||
Button { text: "+1 min"; clicked => { root.advance(60000); } }
|
||||
Button { text: "Reset"; clicked => { root.reset-city(); } }
|
||||
}
|
||||
HorizontalLayout {
|
||||
spacing: 5px;
|
||||
Button { text: "Export CSV"; clicked => { root.export-csv(); } }
|
||||
Button { text: "Export JSON"; clicked => { root.export-json(); } }
|
||||
}
|
||||
Text { text: root.export-status; color: #6de0cb; font-size: 11px; }
|
||||
}
|
||||
}
|
||||
content := Rectangle {
|
||||
background: #17212e;
|
||||
border-radius: 12px;
|
||||
VerticalLayout {
|
||||
padding: 16px;
|
||||
spacing: 12px;
|
||||
Text { text: "Network topology"; color: #e7f3f8; font-size: 21px; font-weight: 600; }
|
||||
Text { text: "Drag nodes. Thick links show the last selected route."; color: #9cb2c6; }
|
||||
graph := Rectangle {
|
||||
height: 355px;
|
||||
background: #101c29;
|
||||
border-radius: 8px;
|
||||
for edge in root.links: Path {
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
viewbox-x: 0;
|
||||
viewbox-y: 0;
|
||||
viewbox-width: parent.width / 1px;
|
||||
viewbox-height: parent.height / 1px;
|
||||
stroke: edge.highlighted ? #ffffff : edge.color;
|
||||
stroke-width: edge.highlighted ? 4px : 2px;
|
||||
MoveTo { x: edge.ax; y: edge.ay; }
|
||||
LineTo { x: edge.bx; y: edge.by; }
|
||||
}
|
||||
for node in root.nodes: Rectangle {
|
||||
x: (node.px - 17.0) * 1px;
|
||||
y: (node.py - 17.0) * 1px;
|
||||
width: 34px;
|
||||
height: 34px;
|
||||
border-radius: 17px;
|
||||
background: node.online ? #235b66 : #35404c;
|
||||
border-color: node.online ? #72d0e2 : #78808a;
|
||||
border-width: 2px;
|
||||
Text {
|
||||
text: node.id;
|
||||
color: #ffffff;
|
||||
horizontal-alignment: center;
|
||||
vertical-alignment: center;
|
||||
font-size: 13px;
|
||||
font-weight: 700;
|
||||
}
|
||||
TouchArea {
|
||||
mouse-cursor: pointer;
|
||||
pointer-event(event) => {
|
||||
if (event.kind == PointerEventKind.down) {
|
||||
root.drag-start(node.id,
|
||||
(self.absolute-position.x + self.mouse-x) / 1px,
|
||||
(self.absolute-position.y + self.mouse-y) / 1px);
|
||||
} else if (event.kind == PointerEventKind.up) {
|
||||
root.drag-end();
|
||||
}
|
||||
}
|
||||
moved => {
|
||||
if (self.pressed) {
|
||||
root.drag-move(
|
||||
(self.absolute-position.x + self.mouse-x) / 1px,
|
||||
(self.absolute-position.y + self.mouse-y) / 1px);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Text { text: "Message log"; color: #e7f3f8; font-size: 17px; font-weight: 600; }
|
||||
ScrollView {
|
||||
VerticalLayout {
|
||||
spacing: 6px;
|
||||
for line in root.messages: Rectangle {
|
||||
height: 28px;
|
||||
background: #233242;
|
||||
border-radius: 5px;
|
||||
Text {
|
||||
x: 9px;
|
||||
text: line;
|
||||
color: #d8e4ed;
|
||||
vertical-alignment: center;
|
||||
font-size: 12px;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Text { text: "Synthetic transmission estimates; not an RF model or a live network.";
|
||||
color: #91aabd; font-size: 11px; }
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue