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:
- Start in GOOD state (low/no loss)
- Each packet, roll dice to potentially transition to BAD state (probability
p) - In BAD state, packets are lost with probability
h(default 100%) - 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
impl GilbertElliot
Sourcepub fn new() -> Self
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.
Sourcepub fn good_duration(self, avg_packets: f32) -> Self
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 average100.0: Burst starts every ~100 packets on average200.0: Burst starts every ~200 packets on average
Internally sets p = 1 / avg_packets.
Sourcepub fn bad_duration(self, avg_packets: f32) -> Self
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 burst5.0: ~5 packets lost per burst10.0: ~10 packets lost per burst (severe)
Internally sets r = 1 / avg_packets.
Sourcepub fn loss_in_bad(self, prob: Probability) -> Self
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.
Sourcepub fn loss_in_good(self, prob: Probability) -> Self
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.
Sourcepub fn wifi() -> Self
pub fn wifi() -> Self
Good WiFi: rare short bursts (~1% loss).
Models occasional interference causing brief packet loss.
Sourcepub fn wifi_lossy() -> Self
pub fn wifi_lossy() -> Self
Lossy WiFi: frequent short bursts (~5% loss).
Models poor WiFi signal with frequent interference.
Sourcepub fn cellular() -> Self
pub fn cellular() -> Self
Mobile/cellular: moderate bursts from handoffs (~2% loss).
Models cellular network with occasional handoffs and signal issues.
Trait Implementations§
Source§impl Clone for GilbertElliot
impl Clone for GilbertElliot
Source§fn clone(&self) -> GilbertElliot
fn clone(&self) -> GilbertElliot
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more