2 releases
| 0.1.1 | Dec 25, 2025 |
|---|---|
| 0.1.0 | Dec 17, 2025 |
#107 in Emulators
Used in str0m
84KB
1.5K
SLoC
Sans-IO network emulator inspired by Linux netem.
This crate provides a network emulator that can simulate:
- Latency and jitter
- Packet loss (random or bursty via Gilbert-Elliot model)
- Packet duplication
- Packet reordering
- Rate limiting
Sans-IO Pattern
This implementation follows the Sans-IO pattern: packets go in with timestamps, and decisions come out (drop, delay, duplicate). The caller handles actual I/O and timing.
Example
use std::time::{Duration, Instant};
use str0m_netem::{Netem, NetemConfig, Input, Output, LossModel, RandomLoss, Probability};
let config = NetemConfig::new()
.latency(Duration::from_millis(50))
.jitter(Duration::from_millis(10))
.loss(RandomLoss::new(Probability::new(0.01)))
.seed(42);
let mut netem: Netem<Vec<u8>> = Netem::new(config);
// Send a packet
let now = Instant::now();
netem.handle_input(Input::Packet(now, vec![1, 2, 3]));
// Poll for output
while let Some(output) = netem.poll_output() {
match output {
Output::Timeout(when) => {
// Wait until `when` and call handle_input with Input::Timeout
}
Output::Packet(data) => {
// Send the packet
}
}
}
str0m-netem
Internal crate for str0m providing Sans-IO network emulation. Used for testing str0m under simulated network conditions (latency, jitter, packet loss, rate limiting).
Dependencies
~3MB
~59K SLoC