Skip to content

Commit 1cd2019

Browse files
authored
feat(model): add bandwidth trace replay model (#13)
1 parent 1aae632 commit 1cd2019

File tree

6 files changed

+810
-6
lines changed

6 files changed

+810
-6
lines changed

.github/workflows/cargo-test.yml

Lines changed: 59 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ jobs:
3030
uses: Swatinem/rust-cache@v1
3131
- name: cargo test
3232
run: |
33-
cargo test --no-fail-fast --verbose --features mahimahi --features serde
33+
cargo test --no-fail-fast --verbose --features mahimahi --features serde --features truncated-normal
3434
3535
cargo-test-full:
3636
runs-on: ubuntu-latest
@@ -50,3 +50,61 @@ jobs:
5050
- name: cargo test
5151
run: |
5252
cargo test --no-fail-fast --verbose --features full
53+
54+
cargo-test-serde:
55+
runs-on: ubuntu-latest
56+
57+
steps:
58+
- name: Checkout
59+
uses: actions/checkout@v2
60+
61+
- name: Install latest nightly
62+
uses: actions-rs/toolchain@v1
63+
with:
64+
toolchain: stable
65+
override: true
66+
components: rustfmt, clippy
67+
- name: deal with rust cache
68+
uses: Swatinem/rust-cache@v1
69+
- name: cargo test
70+
run: |
71+
cargo test --no-fail-fast --verbose --features serde
72+
73+
cargo-test-mahimahi:
74+
runs-on: ubuntu-latest
75+
76+
steps:
77+
- name: Checkout
78+
uses: actions/checkout@v2
79+
80+
- name: Install latest nightly
81+
uses: actions-rs/toolchain@v1
82+
with:
83+
toolchain: stable
84+
override: true
85+
components: rustfmt, clippy
86+
- name: deal with rust cache
87+
uses: Swatinem/rust-cache@v1
88+
- name: cargo test
89+
run: |
90+
cargo test --no-fail-fast --verbose --features mahimahi --features serde
91+
92+
93+
cargo-test-truncated-normal:
94+
runs-on: ubuntu-latest
95+
96+
steps:
97+
- name: Checkout
98+
uses: actions/checkout@v2
99+
100+
- name: Install latest nightly
101+
uses: actions-rs/toolchain@v1
102+
with:
103+
toolchain: stable
104+
override: true
105+
components: rustfmt, clippy
106+
- name: deal with rust cache
107+
uses: Swatinem/rust-cache@v1
108+
- name: cargo test
109+
run: |
110+
cargo test --no-fail-fast --verbose --features truncated-normal --features serde

Cargo.toml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,12 @@ serde = { version = "1.0", features = ["derive"], optional = true }
2424
typetag = { version = "0.2.5", optional = true }
2525
humantime-serde = { version = "1.1.1", optional = true }
2626
human-bandwidth = { version = "0.1.1", optional = true }
27+
statrs = { version = "0.17.1", optional = true}
2728

2829
[dev-dependencies]
2930
serde_json = "1.0"
3031

32+
3133
[features]
3234
default = ["model"]
3335
model = ["bw-model", "delay-model", "loss-model", "duplicate-model"]
@@ -38,7 +40,8 @@ duplicate-model = ["dep:dyn-clone"]
3840
serde = ["dep:serde", "dep:typetag", "bandwidth/serde"]
3941
mahimahi = ["dep:itertools"]
4042
human = ["serde", "dep:humantime-serde", "dep:human-bandwidth", "human-bandwidth/serde"]
41-
full = ["model", "mahimahi", "human"]
43+
full = ["model", "mahimahi", "human", "truncated-normal"]
44+
truncated-normal = ["statrs"]
4245

4346
[package.metadata.docs.rs]
4447
all-features = true

src/lib.rs

Lines changed: 46 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -144,9 +144,9 @@ pub type LossPattern = Vec<f64>;
144144
/// The meaning of the duplicate_pattern sequence is:
145145
///
146146
/// - The probability on index 0 describes how likely a packet will be duplicated
147-
/// **if the previous packet was transmitted normally**.
147+
/// **if the previous packet was transmitted normally**.
148148
/// - The probability on index 1 describes how likely a packet will be duplicated
149-
/// **if the previous packet was duplicated**.
149+
/// **if the previous packet was duplicated**.
150150
/// - ...
151151
///
152152
/// For example, if the duplicate_pattern is [0.8, 0.1], and packet 100 is not duplicated, then the
@@ -216,6 +216,8 @@ pub trait DuplicateTrace: Send {
216216

217217
#[cfg(test)]
218218
mod test {
219+
use model::TraceBwConfig;
220+
219221
use self::model::bw::Forever;
220222

221223
use super::*;
@@ -346,6 +348,48 @@ mod test {
346348
);
347349
}
348350

351+
#[test]
352+
fn test_trace_bw() {
353+
let mut trace_bw = TraceBwConfig::new()
354+
.pattern(vec![
355+
(
356+
Duration::from_millis(1),
357+
vec![
358+
Bandwidth::from_kbps(29123),
359+
Bandwidth::from_kbps(41242),
360+
Bandwidth::from_kbps(7395),
361+
],
362+
),
363+
(
364+
Duration::from_millis(2),
365+
vec![Bandwidth::from_mbps(1), Bandwidth::from_kbps(8542)],
366+
),
367+
])
368+
.build();
369+
370+
assert_eq!(
371+
trace_bw.next_bw(),
372+
Some((Bandwidth::from_bps(29123000), Duration::from_millis(1)))
373+
);
374+
assert_eq!(
375+
trace_bw.next_bw(),
376+
Some((Bandwidth::from_bps(41242000), Duration::from_millis(1)))
377+
);
378+
assert_eq!(
379+
trace_bw.next_bw(),
380+
Some((Bandwidth::from_bps(7395000), Duration::from_millis(1)))
381+
);
382+
assert_eq!(
383+
trace_bw.next_bw(),
384+
Some((Bandwidth::from_bps(1000000), Duration::from_millis(2)))
385+
);
386+
assert_eq!(
387+
trace_bw.next_bw(),
388+
Some((Bandwidth::from_bps(8542000), Duration::from_millis(2)))
389+
);
390+
assert_eq!(trace_bw.next_bw(), None);
391+
}
392+
349393
#[test]
350394
#[cfg(feature = "serde")]
351395
fn test_model_serde() {

0 commit comments

Comments
 (0)