pub struct NetemConfig { /* private fields */ }Expand description
Configuration for the network emulator.
Use the builder pattern to configure the emulator:
use std::time::Duration;
use str0m_netem::{NetemConfig, LossModel, GilbertElliot};
let config = NetemConfig::new()
.latency(Duration::from_millis(50))
.jitter(Duration::from_millis(10))
.loss(GilbertElliot::wifi())
.seed(42);Implementations§
Source§impl NetemConfig
impl NetemConfig
Sourcepub const fn new() -> Self
pub const fn new() -> Self
Create a new network emulator configuration with default values.
Default: no delay, no loss, no rate limit, seed 0.
Sourcepub fn wifi() -> Self
pub fn wifi() -> Self
Good WiFi: low latency, minimal loss, high bandwidth.
Simulates a typical home/office WiFi connection with good signal.
- Latency: 5ms (local network)
- Jitter: 2ms
- Loss: ~1% bursty (GilbertElliot::wifi)
- Bandwidth: 100 Mbps with 200 KB buffer
Sourcepub fn wifi_lossy() -> Self
pub fn wifi_lossy() -> Self
Lossy WiFi: poor signal, more interference and loss.
Simulates WiFi with weak signal or interference.
- Latency: 15ms
- Jitter: 10ms
- Loss: ~5% bursty (GilbertElliot::wifi_lossy)
- Bandwidth: 50 Mbps with 100 KB buffer
Sourcepub fn wifi_congested() -> Self
pub fn wifi_congested() -> Self
Congested WiFi: shared connection with competing traffic.
Simulates a home WiFi where others are streaming video, causing buffer bloat and bandwidth contention.
- Latency: 10ms
- Jitter: 20ms (high due to competing traffic)
- Loss: ~10% (buffer overflow from congestion)
- Bandwidth: 5 Mbps with 30 KB buffer (your share of the link)
Sourcepub fn cellular() -> Self
pub fn cellular() -> Self
Cellular/4G: moderate latency with occasional handoff loss.
Simulates a mobile LTE/4G connection.
- Latency: 50ms
- Jitter: 15ms
- Loss: ~2% bursty (handoffs, signal fading)
- Bandwidth: 30 Mbps with 100 KB buffer
Sourcepub fn satellite() -> Self
pub fn satellite() -> Self
Satellite (GEO): very high latency, weather-related loss bursts.
Simulates a geostationary satellite link (e.g., Viasat, HughesNet).
- Latency: 600ms (round-trip to GEO orbit)
- Jitter: 30ms
- Loss: ~3% bursty (weather, atmospheric)
- Bandwidth: 15 Mbps with 500 KB buffer (large buffer for high BDP)
Sourcepub fn congested() -> Self
pub fn congested() -> Self
Congested network: high latency/jitter, frequent loss, throttled.
Simulates a severely congested network path.
- Latency: 80ms
- Jitter: 40ms
- Loss: ~10% (queue overflow)
- Bandwidth: 10 Mbps with 50 KB buffer (small buffer causes loss)
Sourcepub fn latency(self, latency: Duration) -> Self
pub fn latency(self, latency: Duration) -> Self
Set fixed delay added to every packet.
This simulates the propagation delay of a network link. For example:
- LAN: 0-1ms
- Same city: 5-20ms
- Cross-country: 30-70ms
- Intercontinental: 100-200ms
- Satellite (GEO): 500-700ms
The actual send time is: arrival_time + latency + random_jitter
Sourcepub fn jitter(self, jitter: Duration) -> Self
pub fn jitter(self, jitter: Duration) -> Self
Set random variation added to the latency (uniform distribution).
Each packet gets a random delay in the range [-jitter, +jitter] added
to its base latency. This simulates the variable queuing delays in routers.
For example, with latency(50ms) and jitter(10ms), packets will have
delays uniformly distributed between 40ms and 60ms.
Real networks typically have jitter of 1-30ms depending on congestion.
Sourcepub fn delay_correlation(self, correlation: Probability) -> Self
pub fn delay_correlation(self, correlation: Probability) -> Self
Set correlation between consecutive delay values.
Controls how similar each packet’s delay is to the previous packet’s delay. This models the fact that network conditions change gradually, not randomly.
0.0: Each packet’s jitter is completely independent (unrealistic)0.25: Low correlation, delays vary somewhat smoothly0.5: Medium correlation, delays change gradually0.75: High correlation, delays are very similar to previous1.0: Perfect correlation, all packets get the same jitter (no variation)
Formula: next_jitter = random * (1 - correlation) + last_jitter * correlation
A value around 0.25-0.5 is realistic for most networks.
Sourcepub fn loss(self, loss: impl Into<LossModel>) -> Self
pub fn loss(self, loss: impl Into<LossModel>) -> Self
Set the loss model.
See LossModel for available options.
Sourcepub fn duplicate(self, probability: Probability) -> Self
pub fn duplicate(self, probability: Probability) -> Self
Set probability that each packet is duplicated.
When a packet is duplicated, both the original and the copy are sent with the same delay. This simulates network equipment bugs or misconfigured routing that causes packets to be sent twice.
0.0: No duplication (normal)0.01: 1% of packets are duplicated (rare but happens)0.1: 10% duplication (severe misconfiguration)
Sourcepub fn reorder_gap(self, gap: u32) -> Self
pub fn reorder_gap(self, gap: u32) -> Self
Set reordering by sending every Nth packet immediately.
Every Nth packet bypasses the delay queue and is sent immediately, causing it to arrive before packets that were sent earlier. This simulates multi-path routing where packets take different routes.
3: Every 3rd packet is sent immediately10: Every 10th packet is sent immediately
Combined with latency, this creates realistic reordering patterns.
Sourcepub fn link(self, rate: Bitrate, buffer: DataSize) -> Self
pub fn link(self, rate: Bitrate, buffer: DataSize) -> Self
Set a bottleneck link with rate limiting and finite buffer.
Simulates a network link with limited capacity. When packets arrive faster than the link can transmit, they queue up. When the queue (buffer) is full, packets are dropped (tail drop), simulating congestion-induced loss.
§Example
use std::time::Duration;
use str0m_netem::{NetemConfig, Bitrate, DataSize};
// 10 Mbps link with 200KB buffer (~160ms at full rate)
let config = NetemConfig::new()
.latency(Duration::from_millis(50))
.link(Bitrate::mbps(10), DataSize::bytes(200_000));§Behavior
- Below capacity: packets flow with minimal queuing delay
- At capacity: queuing delay increases as buffer fills
- Over capacity: buffer fills, then excess packets are dropped
Sourcepub fn seed(self, seed: u64) -> Self
pub fn seed(self, seed: u64) -> Self
Set seed for the random number generator.
Using the same seed produces identical packet loss/delay patterns, which is essential for reproducible tests. Different seeds produce different (but deterministic) random sequences.
- Use a fixed seed (e.g.,
42) for reproducible tests - Use
std::time::SystemTime::now().duration_since(UNIX_EPOCH).as_nanos() as u64for random behavior in production
Trait Implementations§
Source§impl Clone for NetemConfig
impl Clone for NetemConfig
Source§fn clone(&self) -> NetemConfig
fn clone(&self) -> NetemConfig
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more