A library for generating network emulation trace. Now only supported mahimahi.
Attention: This library is still under development. The API is not stable.
MSRV: 1.60
Use bandwidth model directly (model
or bw-model
feature should be enabled):
rust
use netem_trace::model::{BoundedNormalizedBwConfig, FixedBwConfig, NormalizedBwConfig};
use netem_trace::{Bandwidth, Duration, BwTrace};
let mut fixed_bw = FixedBwConfig::new()
.bw(Bandwidth::from_mbps(24))
.duration(Duration::from_secs(1))
.build();
assert_eq!(
fixed_bw.next_bw(),
Some((Bandwidth::from_mbps(24), Duration::from_secs(1)))
);
let mut normal_bw = NormalizedBwConfig::new()
.mean(Bandwidth::from_mbps(12))
.std_dev(Bandwidth::from_mbps(1))
.duration(Duration::from_secs(1))
.step(Duration::from_millis(100))
.seed(42)
.build();
assert_eq!(
normal_bw.next_bw(),
Some((Bandwidth::from_bps(12069427), Duration::from_millis(100)))
);
assert_eq!(
normal_bw.next_bw(),
Some((Bandwidth::from_bps(12132938), Duration::from_millis(100)))
);
let mut normal_bw = BoundedNormalizedBwConfig::new()
.mean(Bandwidth::from_mbps(12))
.std_dev(Bandwidth::from_mbps(1))
.duration(Duration::from_secs(1))
.step(Duration::from_millis(100))
.seed(42)
.upper_bound(Bandwidth::from_kbps(12100))
.lower_bound(Bandwidth::from_kbps(11900))
.build();
assert_eq!(
normal_bw.next_bw(),
Some((Bandwidth::from_bps(12069427), Duration::from_millis(100)))
);
assert_eq!(
normal_bw.next_bw(),
Some((Bandwidth::from_bps(12100000), Duration::from_millis(100)))
);
Produce traces in mahimahi format (mahimahi
feature should also be enabled):
rust
use netem_trace::model::{FixedBwConfig};
use netem_trace::{Bandwidth, Duration};
use netem_trace::{Mahimahi, MahimahiExt};
let mut fixed_bw = FixedBwConfig::new()
.bw(Bandwidth::from_mbps(24))
.duration(Duration::from_secs(1))
.build();
assert_eq!(
fixed_bw.mahimahi(&Duration::from_millis(5)),
[0, 0, 1, 1, 2, 2, 3, 3, 4, 4]
);
let mut fixed_bw = FixedBwConfig::new()
.bw(Bandwidth::from_mbps(12))
.duration(Duration::from_secs(1))
.build();
assert_eq!(
fixed_bw.mahimahi_to_string(&Duration::from_millis(5)),
"0\n1\n2\n3\n4"
);
let a = vec![
Box::new(
FixedBwConfig::new()
.bw(Bandwidth::from_mbps(12))
.duration(Duration::from_secs(1)),
) as Box<dyn BwTraceConfig>,
Box::new(
FixedBwConfig::new()
.bw(Bandwidth::from_mbps(24))
.duration(Duration::from_secs(1)),
) as Box<dyn BwTraceConfig>,
];
let mut c = Box::new(RepeatedBwPatternConfig::new().pattern(a).count(2)).into_model();
assert_eq!(c.mahimahi(&Duration::from_millis(5)), [0, 1, 2, 3, 4]);
Work with configuration files (serde
feature should also be enabled):
```rust use netemtrace::model::{FixedBwConfig, BwTraceConfig, RepeatedBwPatternConfig}; use netemtrace::{Bandwidth, Duration, BwTrace};
let a = vec![
Box::new(
FixedBwConfig::new()
.bw(Bandwidth::frommbps(12))
.duration(Duration::fromsecs(1)),
) as Box
You should follow our Code of Conduct.
See CONTRIBUTING GUIDELINES for contributing conventions.
Make sure to pass all the tests before submitting your code.
Yixin Shen |