Skip to content

Commit

Permalink
test(transport): assert maximum bandwidth on gbit link
Browse files Browse the repository at this point in the history
This commit adds a basic smoke test using the `test-fixture` simulator,
asserting the expected bandwidth on a 1 gbit link.

Given mozilla#733, the current expected bandwidth
is limited by the fixed sized stream receive buffer (1MiB).
  • Loading branch information
mxinden committed Oct 26, 2024
1 parent 05b4af9 commit 04b2144
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 1 deletion.
43 changes: 43 additions & 0 deletions neqo-transport/tests/network.rs
Original file line number Diff line number Diff line change
Expand Up @@ -196,3 +196,46 @@ fn transfer_fixed_seed() {
sim.seed_str("117f65d90ee5c1a7fb685f3af502c7730ba5d31866b758d98f5e3c2117cf9b86");
sim.run();
}

#[test]
fn gbit_bandwidth() {
const MIB: usize = 1024 * 1024;
const TRANSFER_AMOUNT: usize = 100 * MIB;

for upload in [false, true] {
let sim = Simulator::new(
"gbit-bandwidth",
boxed![
ConnectionNode::default_client(if upload {
boxed![SendData::new(TRANSFER_AMOUNT)]
} else {
boxed![ReceiveData::new(TRANSFER_AMOUNT)]
}),
TailDrop::gbit_link(),
ConnectionNode::default_server(if upload {
boxed![ReceiveData::new(TRANSFER_AMOUNT)]
} else {
boxed![SendData::new(TRANSFER_AMOUNT)]
}),
TailDrop::gbit_link()
],
);

let simulated_time = sim.setup().run();
let bandwidth = TRANSFER_AMOUNT as f64 * 8.0 / simulated_time.as_secs_f64();

// Given Neqo's current static stream receive buffer of 1MiB, maximum
// bandwidth is below gbit link bandwidth.
//
// Tracked in https://github.com/mozilla/neqo/issues/733.
let maximum_bandwidth = MIB as f64 * 8.0 / 0.1; // bandwidth-delay-product / delay = bandwidth
let expected_utilization = 0.5;

assert!(
maximum_bandwidth * expected_utilization < bandwidth,
"with upload {upload} expected to reach {expected_utilization} of maximum bandwidth ({} Mbit/s) but got {} Mbit/s",
maximum_bandwidth / MIB as f64,
bandwidth / MIB as f64,
);
}
}
3 changes: 2 additions & 1 deletion test-fixture/src/sim/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -293,7 +293,7 @@ pub struct ReadySimulator {
}

impl ReadySimulator {
pub fn run(mut self) {
pub fn run(mut self) -> Duration {
let real_start = Instant::now();
let end = self.sim.process_loop(self.start, self.now);
let sim_time = end - self.now;
Expand All @@ -303,5 +303,6 @@ impl ReadySimulator {
wall = real_start.elapsed(),
);
self.sim.print_summary();
sim_time
}
}
9 changes: 9 additions & 0 deletions test-fixture/src/sim/taildrop.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,15 @@ impl TailDrop {
Self::new(200_000, 8_192, Duration::from_millis(50))
}

/// A tail drop queue on a 1 Gbps link with the default forward delay of
/// 50ms and a buffer equal to the bandwidth-delay-product.
pub const fn gbit_link() -> Self {
let rate = 1_000_000_000 / 8;
let delay = Duration::from_millis(50);
let capacity = rate / 20; // rate * 0.05
Self::new(rate, capacity, delay)
}

/// How "big" is this datagram, accounting for overheads.
/// This approximates by using the same overhead for storing in the queue
/// and for sending on the wire.
Expand Down

0 comments on commit 04b2144

Please sign in to comment.