File
Blob: firmware/vendor/str0m/tests/bwe/changing.rs
| 1 | //! BWE test with changing network bandwidth conditions. |
| 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 | pub fn bwe_changing_bandwidth() -> Result<(), RtcError> { |
| 13 | init_log(); |
| 14 | init_crypto_default(); |
| 15 | |
| 16 | let plan = vec![ |
| 17 | // Phase 1: High bandwidth (10 Mbps) - above send rate, no constraint |
| 18 | Step::Conditions { |
| 19 | description: "High bandwidth conditions", |
| 20 | config: NetemConfig::new() |
| 21 | .latency(Duration::from_millis(10)) |
| 22 | .jitter(Duration::from_millis(2)) |
| 23 | .link(Bitrate::mbps(10), DataSize::kbytes(200)) |
| 24 | .seed(42), |
| 25 | }, |
| 26 | Step::Media { |
| 27 | description: "Probe for high bandwidth", |
| 28 | desired_bitrate: Bitrate::mbps(5), |
| 29 | media_send_rate: Bitrate::mbps(1), |
| 30 | }, |
| 31 | Step::Run { |
| 32 | description: "Wait for high bandwidth", |
| 33 | duration: Duration::from_secs(20), |
| 34 | }, |
| 35 | Step::Check { |
| 36 | // BWE should discover high bandwidth (10 Mbps link) |
| 37 | // Should be well above the send rate |
| 38 | description: "Ensure we have high bandwidth", |
| 39 | at_least: Bitrate::mbps(5), |
| 40 | }, |
| 41 | // Phase 2: Low bandwidth (1 Mbps) - below send rate, constrains it |
| 42 | Step::Conditions { |
| 43 | description: "Bad network conditions", |
| 44 | config: NetemConfig::new() |
| 45 | .latency(Duration::from_millis(10)) |
| 46 | .jitter(Duration::from_millis(20)) |
| 47 | .link(Bitrate::kbps(800), DataSize::kbytes(50)) |
| 48 | .seed(42), |
| 49 | }, |
| 50 | Step::Run { |
| 51 | description: "Run bad conditions", |
| 52 | duration: Duration::from_secs(5), |
| 53 | }, |
| 54 | Step::Check { |
| 55 | // BWE should detect the reduced bandwidth and lower estimate |
| 56 | // Link is 1 Mbps, so estimate should be constrained to ~1 Mbps |
| 57 | description: "Lower estimate for bad conditions", |
| 58 | at_least: Bitrate::kbps(500), |
| 59 | }, |
| 60 | // Drop the send rate. |
| 61 | Step::Media { |
| 62 | description: "Drop the send rate for bad conditions", |
| 63 | desired_bitrate: Bitrate::mbps(5), |
| 64 | media_send_rate: Bitrate::kbps(600), |
| 65 | }, |
| 66 | // Should stabilize |
| 67 | Step::Run { |
| 68 | description: "Wait for bad conditions stabilization", |
| 69 | duration: Duration::from_secs(10), |
| 70 | }, |
| 71 | Step::Check { |
| 72 | // BWE should detect the reduced bandwidth and lower estimate |
| 73 | // Link is 1 Mbps, so estimate should be constrained to ~1 Mbps |
| 74 | description: "Bad conditions stabilized", |
| 75 | at_least: Bitrate::kbps(400), |
| 76 | }, |
| 77 | // Phase 3: Switch back to high bandwidth (10 Mbps) |
| 78 | Step::Conditions { |
| 79 | description: "High bandwidth conditions", |
| 80 | config: NetemConfig::new() |
| 81 | .latency(Duration::from_millis(10)) |
| 82 | .jitter(Duration::from_millis(2)) |
| 83 | .link(Bitrate::mbps(10), DataSize::kbytes(200)) |
| 84 | .seed(42), |
| 85 | }, |
| 86 | Step::Run { |
| 87 | description: "Wait for high bandwidth to recover", |
| 88 | duration: Duration::from_secs(40), |
| 89 | }, |
| 90 | Step::Check { |
| 91 | // BWE should recover and discover high bandwidth again |
| 92 | // Should be higher than the constrained phase 2 |
| 93 | description: "High bandwidth should recover", |
| 94 | at_least: Bitrate::mbps(3), |
| 95 | }, |
| 96 | ]; |
| 97 | |
| 98 | let (mut l, mut r) = connect_with_bwe(Bitrate::mbps(1), Bitrate::mbps(5)); |
| 99 | |
| 100 | let mut ctx = BweTestContext::new(&mut l, &mut r); |
| 101 | |
| 102 | // Run the plan that changes bandwidth conditions |
| 103 | ctx.run_plan(&mut l, &mut r, &plan)?; |
| 104 | |
| 105 | Ok(()) |
| 106 | } |