File
Blob: firmware/vendor/str0m/tests/bwe/estimate.rs
| 1 | //! BWE estimate behavior tests (capping, recovery, convergence). |
| 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 estimate_capped_by_max_bitrate() -> Result<(), RtcError> { |
| 13 | init_log(); |
| 14 | init_crypto_default(); |
| 15 | |
| 16 | let plan = vec![ |
| 17 | Step::Conditions { |
| 18 | description: "High capacity network (10 Mbps)", |
| 19 | config: NetemConfig::new() |
| 20 | .latency(Duration::from_millis(10)) |
| 21 | .link(Bitrate::mbps(10), DataSize::kbytes(200)) |
| 22 | .seed(42), |
| 23 | }, |
| 24 | Step::Media { |
| 25 | description: "Send at 2 Mbps with 3 Mbps max", |
| 26 | desired_bitrate: Bitrate::mbps(3), // max_bitrate |
| 27 | media_send_rate: Bitrate::mbps(2), |
| 28 | }, |
| 29 | Step::Run { |
| 30 | description: "Let probes discover high capacity", |
| 31 | duration: Duration::from_secs(10), |
| 32 | }, |
| 33 | // Estimate should not exceed 3 Mbps despite 10 Mbps capacity |
| 34 | Step::Check { |
| 35 | description: "Estimate capped at max_bitrate", |
| 36 | at_least: Bitrate::mbps(2), |
| 37 | }, |
| 38 | ]; |
| 39 | |
| 40 | let (mut l, mut r) = connect_with_bwe(Bitrate::mbps(2), Bitrate::mbps(3)); |
| 41 | let mut ctx = BweTestContext::new(&mut l, &mut r); |
| 42 | ctx.run_plan(&mut l, &mut r, &plan)?; |
| 43 | |
| 44 | Ok(()) |
| 45 | } |
| 46 | |
| 47 | #[test] |
| 48 | fn estimate_recovers_after_capacity_restoration() -> Result<(), RtcError> { |
| 49 | init_log(); |
| 50 | init_crypto_default(); |
| 51 | |
| 52 | let plan = vec![ |
| 53 | Step::Conditions { |
| 54 | description: "Good network initially", |
| 55 | config: NetemConfig::new() |
| 56 | .latency(Duration::from_millis(20)) |
| 57 | .link(Bitrate::mbps(5), DataSize::kbytes(100)) |
| 58 | .seed(42), |
| 59 | }, |
| 60 | Step::Media { |
| 61 | description: "Send at 2 Mbps", |
| 62 | desired_bitrate: Bitrate::mbps(5), |
| 63 | media_send_rate: Bitrate::mbps(2), |
| 64 | }, |
| 65 | Step::Run { |
| 66 | description: "Establish baseline", |
| 67 | duration: Duration::from_secs(5), |
| 68 | }, |
| 69 | Step::Check { |
| 70 | description: "Good estimate", |
| 71 | at_least: Bitrate::mbps(2), |
| 72 | }, |
| 73 | // Degrade network temporarily |
| 74 | Step::Conditions { |
| 75 | description: "Degrade to 1 Mbps", |
| 76 | config: NetemConfig::new() |
| 77 | .latency(Duration::from_millis(40)) |
| 78 | .link(Bitrate::mbps(1), DataSize::kbytes(50)) |
| 79 | .seed(42), |
| 80 | }, |
| 81 | Step::Run { |
| 82 | description: "Estimate drops to lower capacity", |
| 83 | duration: Duration::from_secs(2), |
| 84 | }, |
| 85 | Step::Check { |
| 86 | description: "Estimate reduced to ~1 Mbps", |
| 87 | at_least: Bitrate::kbps(400), |
| 88 | }, |
| 89 | // Reduce send rate to avoid overwhelming the low estimate |
| 90 | Step::Media { |
| 91 | description: "Reduce send rate to allow AIMD recovery", |
| 92 | desired_bitrate: Bitrate::mbps(5), |
| 93 | media_send_rate: Bitrate::kbps(500), // Send at ~estimate level |
| 94 | }, |
| 95 | // Restore network capacity |
| 96 | Step::Conditions { |
| 97 | description: "Restore to 5 Mbps", |
| 98 | config: NetemConfig::new() |
| 99 | .latency(Duration::from_millis(20)) |
| 100 | .link(Bitrate::mbps(5), DataSize::kbytes(100)) |
| 101 | .seed(42), |
| 102 | }, |
| 103 | // Initial recovery should be via AIMD (no probes immediately after restoration) |
| 104 | Step::Run { |
| 105 | description: "Initial AIMD recovery period", |
| 106 | duration: Duration::from_secs(3), |
| 107 | }, |
| 108 | Step::AssertNoProbes { |
| 109 | description: "No probes during initial AIMD recovery", |
| 110 | }, |
| 111 | Step::Check { |
| 112 | description: "AIMD recovery is very slow after severe degradation", |
| 113 | at_least: Bitrate::kbps(350), |
| 114 | }, |
| 115 | // Further recovery via AIMD and eventually exponential probes |
| 116 | Step::Run { |
| 117 | description: "Continue recovery (slow due to low threshold)", |
| 118 | duration: Duration::from_secs(25), |
| 119 | }, |
| 120 | Step::Check { |
| 121 | description: "Recovery remains slow (threshold adapted down)", |
| 122 | at_least: Bitrate::mbps(1), |
| 123 | }, |
| 124 | ]; |
| 125 | |
| 126 | let (mut l, mut r) = connect_with_bwe(Bitrate::mbps(2), Bitrate::mbps(5)); |
| 127 | let mut ctx = BweTestContext::new(&mut l, &mut r); |
| 128 | ctx.run_plan(&mut l, &mut r, &plan)?; |
| 129 | |
| 130 | Ok(()) |
| 131 | } |
| 132 | |
| 133 | #[test] |
| 134 | fn estimate_converges_to_actual_capacity() -> Result<(), RtcError> { |
| 135 | init_log(); |
| 136 | init_crypto_default(); |
| 137 | |
| 138 | let plan = vec![ |
| 139 | Step::Conditions { |
| 140 | description: "Network with 2 Mbps capacity", |
| 141 | config: NetemConfig::new() |
| 142 | .latency(Duration::from_millis(20)) |
| 143 | .link(Bitrate::mbps(2), DataSize::kbytes(100)) |
| 144 | .seed(42), |
| 145 | }, |
| 146 | Step::Media { |
| 147 | description: "Send at 1.5 Mbps", |
| 148 | desired_bitrate: Bitrate::mbps(5), |
| 149 | media_send_rate: Bitrate::mbps(1), |
| 150 | }, |
| 151 | Step::Run { |
| 152 | description: "Allow convergence over 15 seconds", |
| 153 | duration: Duration::from_secs(15), |
| 154 | }, |
| 155 | // Estimate should converge close to 2 Mbps capacity |
| 156 | Step::Check { |
| 157 | description: "Estimate converges near capacity", |
| 158 | at_least: Bitrate::mbps(1), |
| 159 | }, |
| 160 | ]; |
| 161 | |
| 162 | let (mut l, mut r) = connect_with_bwe(Bitrate::mbps(1), Bitrate::mbps(5)); |
| 163 | let mut ctx = BweTestContext::new(&mut l, &mut r); |
| 164 | ctx.run_plan(&mut l, &mut r, &plan)?; |
| 165 | |
| 166 | Ok(()) |
| 167 | } |