Skip to main content

GilbertElliot

Struct GilbertElliot 

Source
pub struct GilbertElliot { /* private fields */ }
Expand description

Gilbert-Elliot loss model with two states: GOOD and BAD.

This is a 2-state Markov chain that models bursty packet loss:

             p (enter burst)
        ┌──────────────────────┐
        │                      ▼
    ┌───────┐              ┌───────┐
    │ GOOD  │              │  BAD  │
    │(k=0%) │              │(h=100%)│
    └───────┘              └───────┘
        ▲                      │
        └──────────────────────┘
             r (exit burst)

How it works:

  1. Start in GOOD state (low/no loss)
  2. Each packet, roll dice to potentially transition to BAD state (probability p)
  3. In BAD state, packets are lost with probability h (default 100%)
  4. Each packet in BAD, roll dice to return to GOOD (probability r)

Key insight: The average number of packets before transitioning is 1/probability. So p = 0.01 means ~100 packets in GOOD before entering BAD, and r = 0.5 means ~2 packets in BAD before returning to GOOD.

§Example

use str0m_netem::GilbertElliot;

// Custom: lose ~3 packets every ~50 packets
let ge = GilbertElliot::new()
    .good_duration(50.0)   // stay in GOOD for ~50 packets
    .bad_duration(3.0);    // stay in BAD for ~3 packets (burst length)

// Or use a preset
let wifi = GilbertElliot::wifi();

Implementations§

Source§

impl GilbertElliot

Source

pub fn new() -> Self

Create a new Gilbert-Elliot model with default parameters.

Defaults produce no loss: stays in GOOD forever (p=0). Use the builder methods to configure loss behavior.

Source

pub fn good_duration(self, avg_packets: f32) -> Self

Set average number of packets in GOOD state before transitioning to BAD.

This controls how often bursts occur. Higher values = rarer bursts.

  • 50.0: Burst starts every ~50 packets on average
  • 100.0: Burst starts every ~100 packets on average
  • 200.0: Burst starts every ~200 packets on average

Internally sets p = 1 / avg_packets.

Source

pub fn bad_duration(self, avg_packets: f32) -> Self

Set average number of packets in BAD state (burst length).

This controls how long each burst lasts. Higher values = longer bursts.

  • 1.0: Single packet losses (not really bursty)
  • 2.0: ~2 packets lost per burst
  • 5.0: ~5 packets lost per burst
  • 10.0: ~10 packets lost per burst (severe)

Internally sets r = 1 / avg_packets.

Source

pub fn loss_in_bad(self, prob: Probability) -> Self

Set loss probability when in BAD state.

Default is 1.0 (100% loss in BAD state).

Setting this below 1.0 means some packets survive even during a burst, which can model partial outages or congestion that drops some but not all packets.

Source

pub fn loss_in_good(self, prob: Probability) -> Self

Set loss probability when in GOOD state.

Default is 0.0 (no loss in GOOD state).

Setting this above 0.0 adds a baseline random loss even outside of bursts, simulating a network that always has some background loss.

Source

pub fn wifi() -> Self

Good WiFi: rare short bursts (~1% loss).

Models occasional interference causing brief packet loss.

Source

pub fn wifi_lossy() -> Self

Lossy WiFi: frequent short bursts (~5% loss).

Models poor WiFi signal with frequent interference.

Source

pub fn cellular() -> Self

Mobile/cellular: moderate bursts from handoffs (~2% loss).

Models cellular network with occasional handoffs and signal issues.

Source

pub fn satellite() -> Self

Satellite: rare but longer bursts (~3% loss).

Models satellite link with weather-related outages.

Source

pub fn congested() -> Self

Congested network: frequent drops (~10% loss).

Models a heavily loaded network with queue overflow.

Trait Implementations§

Source§

impl Clone for GilbertElliot

Source§

fn clone(&self) -> GilbertElliot

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 GilbertElliot

Source§

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

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

impl Default for GilbertElliot

Source§

fn default() -> Self

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

impl From<GilbertElliot> for LossModel

Source§

fn from(value: GilbertElliot) -> Self

Converts to this type from the input type.
Source§

impl Copy for GilbertElliot

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