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
7
workspace/crates/icenet-core/Cargo.toml
Normal file
7
workspace/crates/icenet-core/Cargo.toml
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
[package]
|
||||
name = "icenet-core"
|
||||
version.workspace = true
|
||||
edition.workspace = true
|
||||
license.workspace = true
|
||||
|
||||
[dependencies]
|
||||
106
workspace/crates/icenet-core/src/lib.rs
Normal file
106
workspace/crates/icenet-core/src/lib.rs
Normal file
|
|
@ -0,0 +1,106 @@
|
|||
//! Shared, platform-independent types for ICE-NET prototypes.
|
||||
//!
|
||||
//! These numeric node IDs are simulation placeholders, not cryptographic IDs.
|
||||
#![forbid(unsafe_code)]
|
||||
#![warn(missing_docs)]
|
||||
|
||||
/// An ICE-NET node identifier in the current prototype.
|
||||
#[derive(Clone, Copy, Debug, Eq, PartialEq, Ord, PartialOrd, Hash)]
|
||||
pub struct NodeId(pub u64);
|
||||
|
||||
/// An ICE-NET application service identifier; not a TCP/UDP port.
|
||||
#[derive(Clone, Copy, Debug, Eq, PartialEq, Ord, PartialOrd, Hash)]
|
||||
pub struct ServiceId(pub u64);
|
||||
|
||||
/// User-facing classes of traffic.
|
||||
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
|
||||
pub enum TrafficClass {
|
||||
/// Tiny announcements and routing control messages.
|
||||
Control,
|
||||
/// Small user messages that may use a slow radio link.
|
||||
Text,
|
||||
/// Bulk transfers, including photos and files.
|
||||
Bulk,
|
||||
}
|
||||
|
||||
impl TrafficClass {
|
||||
/// Largest payload that may travel as [`TrafficClass::Control`].
|
||||
pub const CONTROL_MAX_BYTES: u64 = 256;
|
||||
/// Largest payload that may travel as [`TrafficClass::Text`].
|
||||
///
|
||||
/// Equals the wire frame payload limit, so one text is one frame.
|
||||
pub const TEXT_MAX_BYTES: u64 = 4_096;
|
||||
|
||||
/// Returns whether slow radio links are eligible for this traffic class.
|
||||
pub const fn allows_slow_radio(self) -> bool {
|
||||
!matches!(self, Self::Bulk)
|
||||
}
|
||||
|
||||
/// Returns the class a payload of `bytes` is actually treated as.
|
||||
///
|
||||
/// The label is chosen by the sender and cannot be trusted: an oversized
|
||||
/// `Control` becomes `Text` and an oversized `Text` becomes `Bulk`, so a
|
||||
/// large payload can never claim a slow radio. `Bulk` never shrinks.
|
||||
pub const fn effective_for(self, bytes: u64) -> Self {
|
||||
match self {
|
||||
Self::Control if bytes <= Self::CONTROL_MAX_BYTES => Self::Control,
|
||||
Self::Control | Self::Text if bytes <= Self::TEXT_MAX_BYTES => Self::Text,
|
||||
_ => Self::Bulk,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Abstract physical or tunnel link categories used by the simulator.
|
||||
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
|
||||
pub enum LinkKind {
|
||||
/// Low-throughput, long-range radio.
|
||||
SlowRadio,
|
||||
/// Directional Wi-Fi or comparable fast wireless communication.
|
||||
FastWireless,
|
||||
/// Wired fiber or Ethernet-style backhaul.
|
||||
Wired,
|
||||
/// A best-effort internet tunnel.
|
||||
Internet,
|
||||
}
|
||||
|
||||
impl LinkKind {
|
||||
/// Returns an illustrative bitrate, not a measured hardware capability.
|
||||
pub const fn demo_bps(self) -> u64 {
|
||||
match self {
|
||||
Self::SlowRadio => 1_000,
|
||||
Self::FastWireless => 20_000_000,
|
||||
Self::Wired => 100_000_000,
|
||||
Self::Internet => 10_000_000,
|
||||
}
|
||||
}
|
||||
|
||||
/// Returns illustrative serialization time for `bytes`, rounded up.
|
||||
///
|
||||
/// A zero-byte payload costs one byte, so the result is always at least
|
||||
/// one millisecond for a nonzero bitrate.
|
||||
pub const fn transfer_ms(self, bytes: u64) -> u64 {
|
||||
let bitrate = self.demo_bps() as u128;
|
||||
if bitrate == 0 {
|
||||
return u64::MAX;
|
||||
}
|
||||
let transfer = ((if bytes == 0 { 1 } else { bytes }) as u128)
|
||||
.saturating_mul(8_000)
|
||||
.saturating_add(bitrate - 1)
|
||||
/ bitrate;
|
||||
if transfer > u64::MAX as u128 {
|
||||
u64::MAX
|
||||
} else {
|
||||
transfer as u64
|
||||
}
|
||||
}
|
||||
|
||||
/// Returns a short display name.
|
||||
pub const fn label(self) -> &'static str {
|
||||
match self {
|
||||
Self::SlowRadio => "LoRa (slow)",
|
||||
Self::FastWireless => "Wi-Fi (fast)",
|
||||
Self::Wired => "Wired",
|
||||
Self::Internet => "Internet",
|
||||
}
|
||||
}
|
||||
}
|
||||
41
workspace/crates/icenet-core/tests/types.rs
Normal file
41
workspace/crates/icenet-core/tests/types.rs
Normal file
|
|
@ -0,0 +1,41 @@
|
|||
use icenet_core::{LinkKind, NodeId, ServiceId, TrafficClass};
|
||||
|
||||
#[test]
|
||||
fn slow_radio_is_not_allowed_for_bulk() {
|
||||
assert!(TrafficClass::Text.allows_slow_radio());
|
||||
assert!(TrafficClass::Control.allows_slow_radio());
|
||||
assert!(!TrafficClass::Bulk.allows_slow_radio());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn service_id_is_not_limited_to_tcp_ports() {
|
||||
assert!(ServiceId(77_777).0 > 65_535);
|
||||
assert_eq!(NodeId(42), NodeId(42));
|
||||
assert!(LinkKind::FastWireless.demo_bps() > LinkKind::SlowRadio.demo_bps());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn transfer_time_uses_ceiling_and_a_nonzero_minimum() {
|
||||
assert_eq!(LinkKind::SlowRadio.transfer_ms(1), 8);
|
||||
assert_eq!(LinkKind::Wired.transfer_ms(1), 1);
|
||||
assert_eq!(LinkKind::FastWireless.transfer_ms(0), 1);
|
||||
assert_eq!(LinkKind::SlowRadio.transfer_ms(1_000), 8_000);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn class_is_derived_from_size_not_only_from_the_label() {
|
||||
use TrafficClass::{Bulk, Control, Text};
|
||||
assert_eq!(
|
||||
Control.effective_for(TrafficClass::CONTROL_MAX_BYTES),
|
||||
Control
|
||||
);
|
||||
assert_eq!(
|
||||
Control.effective_for(TrafficClass::CONTROL_MAX_BYTES + 1),
|
||||
Text
|
||||
);
|
||||
assert_eq!(Text.effective_for(TrafficClass::TEXT_MAX_BYTES), Text);
|
||||
assert_eq!(Text.effective_for(TrafficClass::TEXT_MAX_BYTES + 1), Bulk);
|
||||
assert_eq!(Control.effective_for(5_000_000), Bulk);
|
||||
// A Bulk label never shrinks, however small the payload is.
|
||||
assert_eq!(Bulk.effective_for(1), Bulk);
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue