File
Blob: firmware/vendor/str0m/tests/bwe/simple.rs
| 1 | //! Simple BWE tests under different network conditions (cellular, WiFi). |
| 2 | |
| 3 | use std::time::Duration; |
| 4 | |
| 5 | use netem::{Bitrate, NetemConfig}; |
| 6 | use str0m::RtcError; |
| 7 | |
| 8 | use crate::common::{BweTestContext, Step, connect_with_bwe}; |
| 9 | use crate::common::{init_crypto_default, init_log}; |
| 10 | |
| 11 | // Test bitrate layers |
| 12 | pub const LAYER_LOW: Bitrate = Bitrate::kbps(250); |
| 13 | pub const LAYER_MID: Bitrate = Bitrate::kbps(750); |
| 14 | pub const LAYER_TOP: Bitrate = Bitrate::kbps(1_500); |
| 15 | |
| 16 | // Standard ramp-up test plan |
| 17 | pub const RAMP_UP_SINGLE: &[Step] = &[ |
| 18 | Step::Conditions { |
| 19 | description: "Startup conditions", |
| 20 | config: NetemConfig::new(), |
| 21 | }, |
| 22 | Step::Media { |
| 23 | description: "Low layer ramping up to mid", |
| 24 | desired_bitrate: LAYER_MID, |
| 25 | media_send_rate: LAYER_LOW, |
| 26 | }, |
| 27 | Step::Run { |
| 28 | description: "Wait for mid", |
| 29 | duration: Duration::from_secs(20), |
| 30 | }, |
| 31 | Step::Check { |
| 32 | description: "Check enough for mid", |
| 33 | at_least: Bitrate::kbps(750), |
| 34 | }, |
| 35 | Step::Media { |
| 36 | description: "Mid layer ramping up to top", |
| 37 | desired_bitrate: LAYER_TOP, |
| 38 | media_send_rate: LAYER_MID, |
| 39 | }, |
| 40 | Step::Run { |
| 41 | description: "Wait for top", |
| 42 | duration: Duration::from_secs(20), |
| 43 | }, |
| 44 | Step::Check { |
| 45 | description: "Check enough for top", |
| 46 | at_least: Bitrate::kbps(1_500), |
| 47 | }, |
| 48 | Step::Media { |
| 49 | description: "Top layer", |
| 50 | desired_bitrate: LAYER_TOP, |
| 51 | media_send_rate: LAYER_TOP, |
| 52 | }, |
| 53 | Step::Run { |
| 54 | description: "Ensure top stabilizes", |
| 55 | duration: Duration::from_secs(10), |
| 56 | }, |
| 57 | Step::Check { |
| 58 | description: "Top is stable", |
| 59 | at_least: Bitrate::kbps(1_500), |
| 60 | }, |
| 61 | ]; |
| 62 | #[test] |
| 63 | pub fn bwe_cellular() -> Result<(), RtcError> { |
| 64 | init_log(); |
| 65 | init_crypto_default(); |
| 66 | |
| 67 | let mut plan = RAMP_UP_SINGLE.to_vec(); |
| 68 | plan[0] = Step::Conditions { |
| 69 | description: "Cellular conditions", |
| 70 | config: NetemConfig::cellular().seed(42), |
| 71 | }; |
| 72 | plan[2] = Step::Run { |
| 73 | description: "Wait for mid", |
| 74 | duration: Duration::from_secs(40), |
| 75 | }; |
| 76 | |
| 77 | let (mut l, mut r) = connect_with_bwe(LAYER_LOW, LAYER_MID); |
| 78 | |
| 79 | let mut ctx = BweTestContext::new(&mut l, &mut r); |
| 80 | |
| 81 | ctx.run_plan(&mut l, &mut r, &plan)?; |
| 82 | |
| 83 | Ok(()) |
| 84 | } |
| 85 | |
| 86 | #[test] |
| 87 | pub fn bwe_wifi_normal() -> Result<(), RtcError> { |
| 88 | init_log(); |
| 89 | init_crypto_default(); |
| 90 | |
| 91 | // WiFi: 100 Mbps link, 5ms latency, ~1% loss |
| 92 | let mut plan = RAMP_UP_SINGLE.to_vec(); |
| 93 | plan[0] = Step::Conditions { |
| 94 | description: "WiFi conditions", |
| 95 | config: NetemConfig::wifi().seed(42), |
| 96 | }; |
| 97 | |
| 98 | let (mut l, mut r) = connect_with_bwe(LAYER_LOW, LAYER_MID); |
| 99 | |
| 100 | let mut ctx = BweTestContext::new(&mut l, &mut r); |
| 101 | |
| 102 | ctx.run_plan(&mut l, &mut r, &RAMP_UP_SINGLE)?; |
| 103 | |
| 104 | Ok(()) |
| 105 | } |
| 106 | |
| 107 | #[test] |
| 108 | pub fn bwe_wifi_congested() -> Result<(), RtcError> { |
| 109 | init_log(); |
| 110 | init_crypto_default(); |
| 111 | |
| 112 | // Congested WiFi: 5 Mbps link, 10ms latency, ~10% loss |
| 113 | let mut plan = RAMP_UP_SINGLE.to_vec(); |
| 114 | plan[0] = Step::Conditions { |
| 115 | description: "Congested WiFi conditions", |
| 116 | config: NetemConfig::congested().seed(42), |
| 117 | }; |
| 118 | |
| 119 | let (mut l, mut r) = connect_with_bwe(LAYER_LOW, LAYER_MID); |
| 120 | |
| 121 | let mut ctx = BweTestContext::new(&mut l, &mut r); |
| 122 | |
| 123 | ctx.run_plan(&mut l, &mut r, &RAMP_UP_SINGLE)?; |
| 124 | |
| 125 | Ok(()) |
| 126 | } |