Expand description
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
}
}
}Structs§
- Bitrate
- A data rate expressed as bits per second(bps).
- Data
Size - A data size expressed in bytes.
- Gilbert
Elliot - Gilbert-Elliot loss model with two states: GOOD and BAD.
- Link
- A bottleneck link with rate limiting and finite buffer.
- Netem
- Sans-IO network emulator.
- Netem
Config - Configuration for the network emulator.
- Probability
- Probability in range 0.0..=1.0
- Random
Loss - Random loss model configuration.
Enums§
- Input
- Input events to the network emulator.
- Loss
Model - Loss model for packet dropping.
- Output
- Output events from the network emulator.
Traits§
- WithLen
- Trait for getting the length of packet data (used for rate limiting).