Skip to main content

NetemConfig

Struct NetemConfig 

Source
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

Source

pub const fn new() -> Self

Create a new network emulator configuration with default values.

Default: no delay, no loss, no rate limit, seed 0.

Source

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
Source

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
Source

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)
Source

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
Source

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)
Source

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)
Source

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

Source

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.

Source

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 smoothly
  • 0.5: Medium correlation, delays change gradually
  • 0.75: High correlation, delays are very similar to previous
  • 1.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.

Source

pub fn loss(self, loss: impl Into<LossModel>) -> Self

Set the loss model.

See LossModel for available options.

Source

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)
Source

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 immediately
  • 10: Every 10th packet is sent immediately

Combined with latency, this creates realistic reordering patterns.

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
Source

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 u64 for random behavior in production

Trait Implementations§

Source§

impl Clone for NetemConfig

Source§

fn clone(&self) -> NetemConfig

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for NetemConfig

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for NetemConfig

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl Copy for NetemConfig

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> CryptoSafe for T
where T: Send + Sync + Debug,

Source§

impl<T> CryptoSafe for T