File
Blob: firmware/vendor/str0m/tests/bwe/delay.rs
| 1 | //! Delay-based bandwidth estimation tests. |
| 2 | |
| 3 | use std::time::Duration; |
| 4 | |
| 5 | use netem::{DataSize, NetemConfig}; |
| 6 | use str0m::RtcError; |
| 7 | use str0m::bwe::Bitrate; |
| 8 | |
| 9 | use crate::common::{BweTestContext, Step, connect_with_bwe, init_crypto_default, init_log}; |
| 10 | |
| 11 | #[test] |
| 12 | fn overuse_triggers_aimd_decrease() -> Result<(), RtcError> { |
| 13 | init_log(); |
| 14 | init_crypto_default(); |
| 15 | |
| 16 | let plan = vec![ |
| 17 | Step::Conditions { |
| 18 | description: "Start with stable network", |
| 19 | config: NetemConfig::new() |
| 20 | .latency(Duration::from_millis(20)) |
| 21 | .link(Bitrate::mbps(3), DataSize::kbytes(100)) |
| 22 | .seed(42), |
| 23 | }, |
| 24 | Step::Media { |
| 25 | description: "Send at 2 Mbps", |
| 26 | desired_bitrate: Bitrate::mbps(5), |
| 27 | media_send_rate: Bitrate::mbps(2), |
| 28 | }, |
| 29 | Step::Run { |
| 30 | description: "Establish stable estimate", |
| 31 | duration: Duration::from_secs(5), |
| 32 | }, |
| 33 | Step::Check { |
| 34 | description: "Estimate stabilizes around 2 Mbps", |
| 35 | at_least: Bitrate::mbps(2), |
| 36 | }, |
| 37 | // Introduce queuing delay to trigger overuse |
| 38 | Step::Conditions { |
| 39 | description: "Increase latency to cause queuing", |
| 40 | config: NetemConfig::new() |
| 41 | .latency(Duration::from_millis(100)) // Significant increase |
| 42 | .link(Bitrate::mbps(3), DataSize::kbytes(100)) |
| 43 | .seed(42), |
| 44 | }, |
| 45 | Step::Run { |
| 46 | description: "Wait for overuse detection", |
| 47 | duration: Duration::from_secs(2), |
| 48 | }, |
| 49 | Step::Check { |
| 50 | description: "Estimate drops due to overuse (AIMD decrease)", |
| 51 | at_least: Bitrate::mbps(1), |
| 52 | }, |
| 53 | ]; |
| 54 | |
| 55 | let (mut l, mut r) = connect_with_bwe(Bitrate::mbps(2), Bitrate::mbps(5)); |
| 56 | let mut ctx = BweTestContext::new(&mut l, &mut r); |
| 57 | ctx.run_plan(&mut l, &mut r, &plan)?; |
| 58 | |
| 59 | Ok(()) |
| 60 | } |
| 61 | |
| 62 | #[test] |
| 63 | fn underuse_allows_estimate_growth() -> Result<(), RtcError> { |
| 64 | init_log(); |
| 65 | init_crypto_default(); |
| 66 | |
| 67 | let plan = vec![ |
| 68 | Step::Conditions { |
| 69 | description: "High capacity network", |
| 70 | config: NetemConfig::new() |
| 71 | .latency(Duration::from_millis(10)) |
| 72 | .link(Bitrate::mbps(10), DataSize::kbytes(200)) |
| 73 | .seed(42), |
| 74 | }, |
| 75 | Step::Media { |
| 76 | description: "Start low, send consistently", |
| 77 | desired_bitrate: Bitrate::mbps(10), |
| 78 | media_send_rate: Bitrate::mbps(1), |
| 79 | }, |
| 80 | Step::Run { |
| 81 | description: "Initial estimate", |
| 82 | duration: Duration::from_secs(2), |
| 83 | }, |
| 84 | Step::Check { |
| 85 | description: "Baseline estimate established", |
| 86 | at_least: Bitrate::mbps(1), |
| 87 | }, |
| 88 | Step::Run { |
| 89 | description: "Allow estimate to grow", |
| 90 | duration: Duration::from_secs(10), |
| 91 | }, |
| 92 | Step::Check { |
| 93 | description: "Estimate grows under good conditions", |
| 94 | at_least: Bitrate::mbps(5), |
| 95 | }, |
| 96 | ]; |
| 97 | |
| 98 | let (mut l, mut r) = connect_with_bwe(Bitrate::mbps(1), Bitrate::mbps(10)); |
| 99 | let mut ctx = BweTestContext::new(&mut l, &mut r); |
| 100 | ctx.run_plan(&mut l, &mut r, &plan)?; |
| 101 | |
| 102 | Ok(()) |
| 103 | } |