1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
//! Real kernel packet chaos (`tc qdisc ... netem`) for a sandboxed test's
//! own loopback interface.
//!
//! Re-exports [`nlink`]'s typed `netem` builder directly rather than
//! wrapping it — there is no `gateflow`-specific behavior to add on top
//! of "build a [`NetemConfig`], hand it to
//! [`crate::netns::fork_and_enter_with_chaos`]". A wrapper type here
//! would just be a second name for the same thing.
//!
//! # Example
//!
//! ```no_run
//! use gateflow::chaos::{NetemConfig, Percent};
//! use gateflow::netns::fork_and_enter_with_chaos;
//! use std::time::Duration;
//!
//! let netem = NetemConfig::new()
//! .delay(Duration::from_millis(100))
//! .loss(Percent::new(1.0))
//! .build();
//!
//! fork_and_enter_with_chaos(netem, || {
//! // sockets bound to 127.0.0.1 in here see real ~100ms delay and
//! // ~1% loss, enforced by the kernel's own netem qdisc — not
//! // simulated.
//! 0
//! })?;
//! # Ok::<(), gateflow::Error>(())
//! ```
//!
//! # Why this works on loopback
//!
//! `netem` is an *egress* qdisc: it applies to packets as they leave an
//! interface. Loopback traffic still leaves through `lo` on its way back
//! to itself, so a root `netem` qdisc on `lo` really does delay/drop/
//! reorder ordinary `127.0.0.1` traffic — this is the same trick used
//! outside Rust entirely (`tc qdisc add dev lo root netem delay 100ms`)
//! to test local-latency sensitivity without touching a real network.
pub use Percent;
pub use NetemConfig;