diff --git a/quest/m1/api-audit/README.md b/quest/m1/api-audit/README.md index 61f5a0b44c8..69dac2c2d8f 100644 --- a/quest/m1/api-audit/README.md +++ b/quest/m1/api-audit/README.md @@ -75,7 +75,6 @@ Rejected in planning: - [Two broadcast resolutions](/quest/m1/api-audit/resolve/README.md) - Rust, JS, and the bindings resolve a broadcast with `request(path, epoch)` or `follow(path, epoch)`, and every racy two-step caller is gone - [Routes are the origin API](/quest/m1/api-audit/route/README.md) - apps announce exact or prefix routes through one `Route` handle that owns its broadcast and carries an `identity`, prefix routes can serve a held broadcast, and readers get a listing plus `follow` -- [moq-congestion's first-publish names](/quest/m1/api-audit/congestion-names.md) - `bbr3::Config`, `cubic::Config`, `Metrics`, `Factory`, and no `into_any` - [@moq/net names the origin read side](/quest/m1/api-audit/origin-reader.md) - `Origin.Reader`, which `Origin.Table` extends, replaces `Pick` lists ## Related diff --git a/quest/m1/api-audit/congestion-names.md b/quest/m1/api-audit/congestion-names.md deleted file mode 100644 index 6584d982780..00000000000 --- a/quest/m1/api-audit/congestion-names.md +++ /dev/null @@ -1,39 +0,0 @@ -# [S] moq-congestion's first-publish names - -## Goal - -`moq-congestion` first publishes with namespaced names and no downcasting: -`bbr3::Config`, `cubic::Config`, `Metrics`, and `Factory`, with `Bbr3`, -`Cubic`, and `Unlimited` at the crate root, and no `Controller::into_any`. -Every caller in moq-quic, moq-tokio, moq-uring, and the benches uses the new -names. - -Non-goals: new controller signals or a controller framework, and -`clone_box`, which QUIC path migration needs. - -## Plan - -Decided 2026-10-27 from the release-to-main API audit (maintainer picked each -option): - -- The crate is still 0.1.0 and unpublished, and - [noq adopts moq-congestion](/quest/m2/noq-congestion.md) starts after the - m1 cut publishes it, so the rename costs one change now and nothing later. -- **Namespace** (chosen over keeping the quinn-style names that noq's - adapter would read more easily): make `bbr3` and `cubic` public modules - exporting `Config`. Rename `ControllerMetrics` to `Metrics` and - `ControllerFactory` to `Factory`. Keep `Bbr3`, `Cubic`, `Unlimited`, - `Controller`, `Packet`, and the event structs at the root. -- **Remove `into_any`**: its only callers are the moq-tokio tests in - `rs/moq-tokio/src/quic/backend.rs` that assert which controller a factory - built. Check the selection another way (such as observable behavior or - metrics) or drop an assertion that only restates the `match`. noq's adapter - keeps its own `into_any` on its side of the boundary. -- moq-quic's `transport::Config` already nests the controller factory - (`congestion: Arc`, defaulting to - `congestion::Bbr3Config`); rename its uses, its tests, and its bench to the - new names here. - -Public API: breaking in moq-congestion (unpublished) and in the moq-quic, -moq-tokio, and moq-uring re-exports or signatures that name these types. -Wire: none. diff --git a/quest/m1/quic-api/README.md b/quest/m1/quic-api/README.md index a1b4b76533b..034e06aa6af 100644 --- a/quest/m1/quic-api/README.md +++ b/quest/m1/quic-api/README.md @@ -9,8 +9,7 @@ error type per direction, terminal operations that consume their handle, plain config structs, and no quinn compatibility baggage. Consumers lose the workarounds quinn's shape forced on them. -Non-goals: the congestion controller API -([its names](/quest/m1/api-audit/congestion-names.md)), a +Non-goals: the congestion controller API, a buffer pool ([QUIC I/O boundary](/quest/m2/quic-io-boundary.md)), and the non-QUIC backends' move off `web_transport_trait`, which has landed. diff --git a/quest/m2/quic-realtime/README.md b/quest/m2/quic-realtime/README.md index 5770fc0ecf3..f15e8f5fa39 100644 --- a/quest/m2/quic-realtime/README.md +++ b/quest/m2/quic-realtime/README.md @@ -91,7 +91,7 @@ Remaining work once the candidates finish (this README's own job): - Delete the losing candidates' code. - Decide who asks for receive timestamps. The spike added `transport::Config::receive_timestamps`, off by default, and the maintainer - kept it on 2026-10-30. The winner decides whether its `ControllerFactory` + kept it on 2026-10-30. The winner decides whether its `Factory` turns them on instead, so only `Realtime` sessions pay the ACK bytes. - Wire the winner's moq-shaper run into the nightly so a regression in queuing delay shows up. diff --git a/quest/m2/quic-realtime/gcc.md b/quest/m2/quic-realtime/gcc.md index f4cdb97519c..33b399288a8 100644 --- a/quest/m2/quic-realtime/gcc.md +++ b/quest/m2/quic-realtime/gcc.md @@ -21,7 +21,7 @@ fork. Controller's per-packet send and receive instants; drop the parts that only serve RTCP or probe clusters unless the comparison needs them. - GCC outputs a target rate and pacing rate; map them to the Controller's - window and `ControllerMetrics::{pacing_rate, bandwidth_estimate}`, keeping + window and `Metrics::{pacing_rate, bandwidth_estimate}`, keeping its congestion-window pushback as the inflight bound. - Keep the BSD license and PATENTS file with the vendored code. - Implement `Controller::probes` and report `probe_inflight` so moq-quic's diff --git a/rs/moq-congestion/Cargo.toml b/rs/moq-congestion/Cargo.toml index aa9eedf09b7..7e71c22d833 100644 --- a/rs/moq-congestion/Cargo.toml +++ b/rs/moq-congestion/Cargo.toml @@ -8,7 +8,7 @@ repository = "https://github.com/moq-dev/moq" license = "MIT OR Apache-2.0" [features] -# Test-only `Bbr3Config::probe_rng_seed`, for moq-quic's deterministic transport tests. +# Test-only `bbr3::Config::probe_rng_seed`, for moq-quic's deterministic transport tests. testing = [] [dependencies] diff --git a/rs/moq-congestion/README.md b/rs/moq-congestion/README.md index 898d009fb12..051cb2ed53a 100644 --- a/rs/moq-congestion/README.md +++ b/rs/moq-congestion/README.md @@ -4,6 +4,10 @@ BBR3, Cubic, and Unlimited congestion controllers, consumed by moq-quic and the The controllers take explicit `kio::clock::Instant` values and never drive a runtime. The `Controller` trait names no transport types: `on_sent` returns an opaque per-packet state that the transport stores and hands back with each acknowledgement or loss, and the controller paces its own sends. +Construct controllers with `Factory::build` on an `Arc`, `Arc`, or `Arc`. `Bbr3`, `Cubic`, `Unlimited`, and `Metrics` live at the crate root. + +For callers of the unpublished API, replace `Bbr3Config` with `bbr3::Config`, `CubicConfig` with `cubic::Config`, `ControllerFactory` with `Factory`, and `ControllerMetrics` with `Metrics`. Remove `Controller::into_any` from custom implementations; inspect the controller's behavior or metrics instead of downcasting. `clone_box` still copies controller state for path migration. The test-only `Bbr3::probing_rtt` and `min_rtt` accessors are removed; model internals are tested in this crate. + The code was extracted from [moq-quic](../moq-quic), under the same MIT or Apache-2.0 license. Cubic originated in quinn; BBR3 was ported from moq-dev/noq and carries the fixes listed in [moq-quic's fork history](../moq-quic/README.md). Controller tests run with `just rs test -p moq-congestion`. The per-packet benchmark runs nightly, or locally with: diff --git a/rs/moq-congestion/src/bbr3/bench.rs b/rs/moq-congestion/src/bbr3/bench.rs index 6856018cd9d..6cc91f6b01c 100644 --- a/rs/moq-congestion/src/bbr3/bench.rs +++ b/rs/moq-congestion/src/bbr3/bench.rs @@ -17,7 +17,7 @@ const PACKET: u16 = 1200; fn measure(flight: usize, batch: usize, steady: bool) -> (Duration, usize) { let base = Instant::now(); let region = Region::new(ALLOCATOR); - let config = Bbr3Config { + let config = Config { probe_rng_seed: Some([7; 16]), ..Default::default() }; diff --git a/rs/moq-congestion/src/bbr3/mod.rs b/rs/moq-congestion/src/bbr3/mod.rs index 3dbfdfa29f8..6a1b718645b 100644 --- a/rs/moq-congestion/src/bbr3/mod.rs +++ b/rs/moq-congestion/src/bbr3/mod.rs @@ -2,7 +2,6 @@ mod bench; mod max_filter; -use std::any::Any; #[cfg(test)] use std::collections::VecDeque; use std::sync::Arc; @@ -14,8 +13,7 @@ use crate::bbr3::max_filter::MaxFilter; use crate::pacer::{Pacer, Rate}; use crate::rate::{Sample, Sampler}; use crate::{ - Ack, BASE_DATAGRAM_SIZE, Ce, Controller, ControllerFactory, ControllerMetrics, Init, Loss, - Lost, Packet, Sent, + Ack, BASE_DATAGRAM_SIZE, Ce, Controller, Factory, Init, Loss, Lost, Metrics, Packet, Sent, }; use crate::{Duration, Instant}; @@ -526,20 +524,8 @@ pub struct Bbr3 { } impl Bbr3 { - /// Whether the controller is in ProbeRTT, for transport tests. - #[cfg(any(test, feature = "testing"))] - pub fn probing_rtt(&self) -> bool { - self.state == BbrState::ProbeRtt - } - - /// The windowed minimum RTT the model uses, for transport tests. - #[cfg(any(test, feature = "testing"))] - pub fn min_rtt(&self) -> Duration { - self.min_rtt - } - /// equivalent to BBROnInit - fn new(config: Arc, init: Init) -> Self { + fn new(config: Arc, init: Init) -> Self { let probe_rng = if let Some(probe_seed) = config.probe_rng_seed { Pcg32::from_seed(probe_seed) } else { @@ -1964,8 +1950,8 @@ impl Controller for Bbr3 { Some(self.send_quantum) } - fn metrics(&self) -> ControllerMetrics { - ControllerMetrics { + fn metrics(&self) -> Metrics { + Metrics { congestion_window: self.window(), ssthresh: None, pacing_rate: Some(self.pacing_rate.round() as u64), @@ -1981,10 +1967,6 @@ impl Controller for Bbr3 { fn clone_box(&self) -> Box { Box::new(self.clone()) } - - fn into_any(self: Box) -> Box { - self - } } /// Configuration for the `Bbr3` congestion controller @@ -1996,7 +1978,7 @@ impl Controller for Bbr3 { /// `pacing_margin_percent` is used to set a margin when calculating the `pacing_rate` in order /// to not send at 100% capacity when calculating pacing. #[derive(Debug, Clone)] -pub struct Bbr3Config { +pub struct Config { initial_window: u64, probe_rng_seed: Option<[u8; 16]>, startup_pacing_gain: Option, @@ -2010,7 +1992,7 @@ pub struct Bbr3Config { default_cwnd_gain: Option, } -impl Bbr3Config { +impl Config { /// Default limit on the amount of outstanding data in bytes. /// /// Recommended value: `min(10 * max_datagram_size, max(2 * max_datagram_size, 14720))` @@ -2027,7 +2009,7 @@ impl Bbr3Config { } } -impl Default for Bbr3Config { +impl Default for Config { fn default() -> Self { Self { // Bounded by the datagram size a path starts at, not [`MAX_DATAGRAM_SIZE`] (the @@ -2047,7 +2029,7 @@ impl Default for Bbr3Config { } } -impl ControllerFactory for Bbr3Config { +impl Factory for Config { fn build(self: Arc, init: Init) -> Box { Box::new(Bbr3::new(self, init)) } @@ -2075,7 +2057,7 @@ mod test { } impl Driver { - fn new(config: Arc, mtu: u16) -> Self { + fn new(config: Arc, mtu: u16) -> Self { let init = Init { now: Instant::now(), mtu, @@ -2213,7 +2195,7 @@ mod test { } impl Sim { - fn new(config: Bbr3Config, mss: u64, bw: f64, rtt_ns: u64) -> Self { + fn new(config: Config, mss: u64, bw: f64, rtt_ns: u64) -> Self { Self { bbr: Driver::new(Arc::new(config), mss as u16), base: Instant::now(), @@ -2405,8 +2387,8 @@ mod test { #[test] fn default_probe_schedule_replays() { - let mut first = Driver::new(Arc::new(Bbr3Config::default()), 2500); - let mut replay = Driver::new(Arc::new(Bbr3Config::default()), 2500); + let mut first = Driver::new(Arc::new(Config::default()), 2500); + let mut replay = Driver::new(Arc::new(Config::default()), 2500); for _ in 0..8 { first.pick_probe_wait(); replay.pick_probe_wait(); @@ -2419,7 +2401,7 @@ mod test { #[test] fn test_probe_rng() { let seed: [u8; 16] = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16]; - let config = Bbr3Config { + let config = Config { initial_window: 14720.clamp(2 * BASE_DATAGRAM_SIZE, 10 * BASE_DATAGRAM_SIZE), probe_rng_seed: Some(seed), startup_pacing_gain: None, @@ -2470,7 +2452,7 @@ mod test { const RTT_NS: u64 = 100_000_000; // Drive the production default configuration. - let mut sim = Sim::new(Bbr3Config::default(), MSS, BW, RTT_NS); + let mut sim = Sim::new(Config::default(), MSS, BW, RTT_NS); assert_eq!(sim.bbr.state, BbrState::Startup); // captured on the STARTUP -> DRAIN edge (DRAIN is only ever entered from @@ -2548,7 +2530,7 @@ mod test { let btl_service_ns: u64 = (MSS as f64 / BW * 1e9).round() as u64; // Drive the production default configuration. - let mut bbr = Driver::new(Arc::new(Bbr3Config::default()), MSS as u16); + let mut bbr = Driver::new(Arc::new(Config::default()), MSS as u16); assert_eq!(bbr.state, BbrState::Startup); let base = Instant::now(); @@ -2708,7 +2690,7 @@ mod test { const RTT_NS: u64 = 100_000_000; // Drive the production default configuration. - let mut sim = Sim::new(Bbr3Config::default(), MSS, BW, RTT_NS); + let mut sim = Sim::new(Config::default(), MSS, BW, RTT_NS); assert_eq!(sim.bbr.state, BbrState::Startup); // pacing_gain observed on the STARTUP -> DRAIN edge (0.5), and the round @@ -2807,7 +2789,7 @@ mod test { const DRAIN_BW_FACTOR: f64 = 0.8 * DRAIN_PACING_GAIN; // Drive the production default configuration. - let mut bbr = Driver::new(Arc::new(Bbr3Config::default()), MSS as u16); + let mut bbr = Driver::new(Arc::new(Config::default()), MSS as u16); assert_eq!(bbr.state, BbrState::Startup); let base = Instant::now(); @@ -2978,7 +2960,7 @@ mod test { const RTT_NS: u64 = 100_000_000; // Drive the production default configuration. - let mut sim = Sim::new(Bbr3Config::default(), MSS, BW, RTT_NS); + let mut sim = Sim::new(Config::default(), MSS, BW, RTT_NS); assert_eq!(sim.bbr.state, BbrState::Startup); // Whether the flow has reached the PROBE_UP phase of PROBE_BW; the go-down @@ -3030,7 +3012,7 @@ mod test { /// Loss probing does not require an ACK's delivery-rate observation. #[test] fn loss_before_first_ack_bounds_inflight() { - let mut sim = Sim::new(Bbr3Config::default(), 1200, 1_250_000.0, 100 * MS); + let mut sim = Sim::new(Config::default(), 1200, 1_250_000.0, 100 * MS); sim.send(0, 10); assert!(sim.bbr.rs.is_none()); sim.bbr.bw_probe_samples = true; @@ -3048,7 +3030,7 @@ mod test { /// Loss uses its packet's labels without relabeling the preceding or following ACK. #[test] fn loss_between_acks_preserves_ack_sample() { - let mut sim = Sim::new(Bbr3Config::default(), 1200, 1_250_000.0, 100 * MS); + let mut sim = Sim::new(Config::default(), 1200, 1_250_000.0, 100 * MS); sim.send(0, 10); sim.bbr.rate.app_limited = 1; sim.send(MS, 1); @@ -3129,7 +3111,7 @@ mod test { let btl_service_ns: u64 = (MSS as f64 / BW * 1e9).round() as u64; // Drive the production default configuration. - let mut bbr = Driver::new(Arc::new(Bbr3Config::default()), MSS as u16); + let mut bbr = Driver::new(Arc::new(Config::default()), MSS as u16); assert_eq!(bbr.state, BbrState::Startup); let base = Instant::now(); @@ -3321,7 +3303,7 @@ mod test { let btl_service_ns: u64 = (MSS as f64 / BW * 1e9).round() as u64; // Drive the production default configuration. - let mut bbr = Driver::new(Arc::new(Bbr3Config::default()), MSS as u16); + let mut bbr = Driver::new(Arc::new(Config::default()), MSS as u16); assert_eq!(bbr.state, BbrState::Startup); let base = Instant::now(); @@ -3502,7 +3484,7 @@ mod test { const RTT_NS: u64 = 100_000_000; // Drive the production default configuration. - let mut sim = Sim::new(Bbr3Config::default(), MSS, BW, RTT_NS); + let mut sim = Sim::new(Config::default(), MSS, BW, RTT_NS); assert_eq!(sim.bbr.state, BbrState::Startup); // Whether the flow has reached the PROBE_UP phase; the PROBE_DOWN we care @@ -3642,9 +3624,9 @@ mod test { // Drive the production default configuration with a fixed probe RNG seed so // bw_probe_wait is deterministic; its exact value does not matter here since // the deadline is computed from it below. - let config = Bbr3Config { + let config = Config { probe_rng_seed: Some([6; 16]), - ..Bbr3Config::default() + ..Config::default() }; let mut sim = Sim::new(config, MSS, BW, RTT_NS); assert_eq!(sim.bbr.state, BbrState::Startup); @@ -3791,7 +3773,7 @@ mod test { const RTT_NS: u64 = 100_000_000; // Held constant (no queue-shaping hacks) so the min RTT floor is deterministic. - let mut sim = Sim::new(Bbr3Config::default(), MSS, BW, RTT_NS); + let mut sim = Sim::new(Config::default(), MSS, BW, RTT_NS); assert_eq!(sim.bbr.state, BbrState::Startup); // Whether the flow reached PROBE_BW with full_bw_reached before PROBE_RTT. @@ -3975,7 +3957,7 @@ mod test { let btl_service_ns: u64 = (MSS as f64 / BW * 1e9).round() as u64; - let mut bbr = Driver::new(Arc::new(Bbr3Config::default()), MSS as u16); + let mut bbr = Driver::new(Arc::new(Config::default()), MSS as u16); assert_eq!(bbr.state, BbrState::Startup); let base = Instant::now(); @@ -4229,7 +4211,7 @@ mod test { let btl_service_ns: u64 = (MSS as f64 / BW * 1e9).round() as u64; // Drive the production default configuration. - let mut bbr = Driver::new(Arc::new(Bbr3Config::default()), MSS as u16); + let mut bbr = Driver::new(Arc::new(Config::default()), MSS as u16); assert_eq!(bbr.state, BbrState::Startup); let base = Instant::now(); @@ -4428,7 +4410,7 @@ mod test { let btl_service_ns: u64 = (MSS as f64 / BW * 1e9).round() as u64; // Drive the production default configuration. - let mut bbr = Driver::new(Arc::new(Bbr3Config::default()), MSS as u16); + let mut bbr = Driver::new(Arc::new(Config::default()), MSS as u16); assert_eq!(bbr.state, BbrState::Startup); let base = Instant::now(); @@ -4730,9 +4712,9 @@ mod test { // Seed the probe RNG so the PROBE_BW bw-probe wait (hence the cruise sojourn length) is // deterministic and the pair-count target below is not flaky. let seed: [u8; 16] = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16]; - let config = Bbr3Config { + let config = Config { probe_rng_seed: Some(seed), - ..Bbr3Config::default() + ..Config::default() }; let mut bbr = Driver::new(Arc::new(config), MSS as u16); assert_eq!(bbr.state, BbrState::Startup); @@ -5012,9 +4994,9 @@ mod test { // Seed the probe RNG so the PROBE_BW cycle timing (hence when PROBE_UP is entered) is // deterministic. let seed: [u8; 16] = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16]; - let config = Bbr3Config { + let config = Config { probe_rng_seed: Some(seed), - ..Bbr3Config::default() + ..Config::default() }; let mut bbr = Driver::new(Arc::new(config), MSS as u16); assert_eq!(bbr.state, BbrState::Startup); @@ -5262,9 +5244,9 @@ mod test { // Seed the probe RNG so the PROBE_BW cycle timing is deterministic. let seed: [u8; 16] = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16]; - let config = Bbr3Config { + let config = Config { probe_rng_seed: Some(seed), - ..Bbr3Config::default() + ..Config::default() }; let mut bbr = Driver::new(Arc::new(config), MSS as u16); assert_eq!(bbr.state, BbrState::Startup); @@ -5483,9 +5465,9 @@ mod test { // Seed the probe RNG so the PROBE_BW cycle timing is deterministic. let seed: [u8; 16] = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16]; - let config = Bbr3Config { + let config = Config { probe_rng_seed: Some(seed), - ..Bbr3Config::default() + ..Config::default() }; let mut bbr = Driver::new(Arc::new(config), MSS as u16); assert_eq!(bbr.state, BbrState::Startup); @@ -5705,9 +5687,9 @@ mod test { // Seed the probe RNG so the PROBE_BW cycle timing (hence when PROBE_UP is entered) is // deterministic. let seed: [u8; 16] = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16]; - let config = Bbr3Config { + let config = Config { probe_rng_seed: Some(seed), - ..Bbr3Config::default() + ..Config::default() }; let mut bbr = Driver::new(Arc::new(config), MSS as u16); assert_eq!(bbr.state, BbrState::Startup); @@ -5970,9 +5952,9 @@ mod test { // Seed the probe RNG so the PROBE_BW cycle timing (hence when PROBE_UP is entered) is // deterministic. let seed: [u8; 16] = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16]; - let config = Bbr3Config { + let config = Config { probe_rng_seed: Some(seed), - ..Bbr3Config::default() + ..Config::default() }; let mut bbr = Driver::new(Arc::new(config), MSS as u16); assert_eq!(bbr.state, BbrState::Startup); @@ -6246,7 +6228,7 @@ mod test { let btl_service_ns: u64 = (MSS as f64 / BW * 1e9).round() as u64; // Drive the production default configuration. - let mut bbr = Driver::new(Arc::new(Bbr3Config::default()), MSS as u16); + let mut bbr = Driver::new(Arc::new(Config::default()), MSS as u16); assert_eq!(bbr.state, BbrState::Startup); let base = Instant::now(); @@ -6507,9 +6489,9 @@ mod test { // Seed the probe RNG so the PROBE_BW cycle timing (hence when each PROBE_UP is // entered) is deterministic. let seed: [u8; 16] = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16]; - let config = Bbr3Config { + let config = Config { probe_rng_seed: Some(seed), - ..Bbr3Config::default() + ..Config::default() }; let mut bbr = Driver::new(Arc::new(config), MSS as u16); assert_eq!(bbr.state, BbrState::Startup); @@ -6749,9 +6731,9 @@ mod test { // Pin this scenario's probe schedule: once app-limiting lifts at the // PROBE_REFILL -> PROBE_UP edge the flow does genuine PROBE_BW cycling, whose // phase timing is RNG-driven (cf. sibling probing tests). - let config = Bbr3Config { + let config = Config { probe_rng_seed: Some([6; 16]), - ..Bbr3Config::default() + ..Config::default() }; let mut bbr = Driver::new(Arc::new(config), MSS as u16); assert_eq!(bbr.state, BbrState::Startup); @@ -6988,7 +6970,7 @@ mod test { /// A scripted `Sim` with 1200-byte packets; the link parameters are unused. fn scripted() -> Sim { - Sim::new(Bbr3Config::default(), 1200, 1e6, 10 * MS) + Sim::new(Config::default(), 1200, 1e6, 10 * MS) } /// The first ACK's sample reaches the model: 1200 bytes in 10ms is 120 KB/s. @@ -8123,9 +8105,9 @@ mod test { #[test] fn sustained_ce_bounds_the_queue_and_recovers() { const SEC: u64 = 1_000_000_000; - let config = || Bbr3Config { + let config = || Config { probe_rng_seed: Some([7; 16]), - ..Bbr3Config::default() + ..Config::default() }; let mut control = Sim::new(config(), 1200, LINK_BW, LINK_RTT); let mut marked = Sim::new(config(), 1200, LINK_BW, LINK_RTT); diff --git a/rs/moq-congestion/src/cubic.rs b/rs/moq-congestion/src/cubic.rs index b43a2ce5ea8..8a99b2d40c1 100644 --- a/rs/moq-congestion/src/cubic.rs +++ b/rs/moq-congestion/src/cubic.rs @@ -1,8 +1,7 @@ -use std::any::Any; use std::cmp; use std::sync::Arc; -use super::{Ack, BASE_DATAGRAM_SIZE, Ce, Controller, ControllerFactory, Init, Loss, Packet, Sent}; +use super::{Ack, BASE_DATAGRAM_SIZE, Ce, Controller, Factory, Init, Loss, Packet, Sent}; use crate::pacer::{Pacer, Rate}; use crate::{Duration, Instant}; @@ -84,7 +83,7 @@ pub struct Cubic { } impl Cubic { - fn new(config: Arc, init: Init) -> Self { + fn new(config: Arc, init: Init) -> Self { Self { state: State { window: config.initial_window, @@ -287,8 +286,8 @@ impl Controller for Cubic { .delay(self.rtt, bytes, self.current_mtu as u16, now, rate) } - fn metrics(&self) -> super::ControllerMetrics { - super::ControllerMetrics { + fn metrics(&self) -> super::Metrics { + super::Metrics { congestion_window: self.window(), ssthresh: Some(self.state.ssthresh), pacing_rate: None, @@ -301,19 +300,15 @@ impl Controller for Cubic { fn clone_box(&self) -> Box { Box::new(self.clone()) } - - fn into_any(self: Box) -> Box { - self - } } /// Configuration for the `Cubic` congestion controller #[derive(Debug, Clone)] -pub struct CubicConfig { +pub struct Config { initial_window: u64, } -impl CubicConfig { +impl Config { /// Default limit on the amount of outstanding data in bytes. /// /// Recommended value: `min(10 * max_datagram_size, max(2 * max_datagram_size, 14720))` @@ -323,7 +318,7 @@ impl CubicConfig { } } -impl Default for CubicConfig { +impl Default for Config { fn default() -> Self { Self { initial_window: 14720.clamp(2 * BASE_DATAGRAM_SIZE, 10 * BASE_DATAGRAM_SIZE), @@ -331,7 +326,7 @@ impl Default for CubicConfig { } } -impl ControllerFactory for CubicConfig { +impl Factory for Config { fn build(self: Arc, init: Init) -> Box { Box::new(Cubic::new(self, init)) } @@ -342,7 +337,7 @@ mod tests { fn cubic(now: Instant) -> Cubic { Cubic::new( - Arc::new(CubicConfig::default()), + Arc::new(Config::default()), Init { now, mtu: BASE_DATAGRAM_SIZE as u16, diff --git a/rs/moq-congestion/src/lib.rs b/rs/moq-congestion/src/lib.rs index ccb566de3c2..a5dbc9422cd 100644 --- a/rs/moq-congestion/src/lib.rs +++ b/rs/moq-congestion/src/lib.rs @@ -8,17 +8,18 @@ use kio::clock::Instant; use std::time::Duration; -use std::any::Any; use std::sync::Arc; -mod bbr3; -mod cubic; +/// BBRv3 congestion control. +pub mod bbr3; +/// CUBIC congestion control. +pub mod cubic; mod pacer; mod rate; mod unlimited; -pub use bbr3::{Bbr3, Bbr3Config}; -pub use cubic::{Cubic, CubicConfig}; +pub use bbr3::Bbr3; +pub use cubic::Cubic; pub use rate::Packet; pub use unlimited::Unlimited; @@ -49,7 +50,7 @@ pub trait Controller: Send + Sync { fn on_app_limited(&mut self, in_flight: u64) {} /// A transmit poll drained the source, then filled the rest with bandwidth-probe duplicates - /// or was held back by [`ControllerMetrics::probe_inflight`] or the probe's own pace. + /// or was held back by [`Metrics::probe_inflight`] or the probe's own pace. /// /// Reports the poll [`Controller::on_app_limited`] would have reported without the probe, /// with `in_flight` bytes outstanding. A controller that probes decides which of its @@ -111,8 +112,8 @@ pub trait Controller: Send + Sync { /// Retrieve implementation-specific metrics used to populate connection statistics and `qlog` /// traces when they are enabled - fn metrics(&self) -> ControllerMetrics { - ControllerMetrics { + fn metrics(&self) -> Metrics { + Metrics { congestion_window: self.window(), ssthresh: None, pacing_rate: None, @@ -121,7 +122,7 @@ pub trait Controller: Send + Sync { } } - /// Whether the controller ever reports [`ControllerMetrics::probe_inflight`], so an + /// Whether the controller ever reports [`Metrics::probe_inflight`], so an /// application-limited sender can probe for bandwidth through it fn probes(&self) -> bool { false @@ -129,9 +130,6 @@ pub trait Controller: Send + Sync { /// Duplicate the controller's state fn clone_box(&self) -> Box; - - /// Returns Self for use in down-casting to extract implementation details - fn into_any(self: Box) -> Box; } /// A packet the transport just sent. @@ -215,7 +213,7 @@ pub struct Ce { /// Common congestion controller metrics used for statistics and logging #[derive(Default)] -pub struct ControllerMetrics { +pub struct Metrics { /// Congestion window (bytes) pub congestion_window: u64, /// Slow start threshold (bytes) @@ -246,7 +244,7 @@ pub struct Init { } /// Constructs controllers on demand -pub trait ControllerFactory { +pub trait Factory { /// Construct a fresh `Controller` fn build(self: Arc, init: Init) -> Box; } diff --git a/rs/moq-congestion/src/unlimited.rs b/rs/moq-congestion/src/unlimited.rs index ace02b1c9a9..f3aa7d10cad 100644 --- a/rs/moq-congestion/src/unlimited.rs +++ b/rs/moq-congestion/src/unlimited.rs @@ -1,7 +1,6 @@ -use std::any::Any; use std::sync::Arc; -use super::{Ack, Ce, Controller, ControllerFactory, Init, Loss, Packet, Sent}; +use super::{Ack, Ce, Controller, Factory, Init, Loss, Packet, Sent}; use crate::Instant; /// No congestion control: a window that never shrinks, and no pacing. @@ -34,13 +33,9 @@ impl Controller for Unlimited { fn clone_box(&self) -> Box { Box::new(*self) } - - fn into_any(self: Box) -> Box { - self - } } -impl ControllerFactory for Unlimited { +impl Factory for Unlimited { fn build(self: Arc, _init: Init) -> Box { Box::new(*self) } diff --git a/rs/moq-quic/MIGRATE.md b/rs/moq-quic/MIGRATE.md index e48541053a2..ca642eda946 100644 --- a/rs/moq-quic/MIGRATE.md +++ b/rs/moq-quic/MIGRATE.md @@ -82,4 +82,4 @@ targets run through the hidden `fuzz` module behind the `fuzz` feature; see ### `congestion::NewReno` removed `congestion::NewReno` and `congestion::NewRenoConfig` are gone. -Use `Bbr3Config` (the default) or `CubicConfig` instead. +Use `bbr3::Config` (the default) or `cubic::Config` instead. diff --git a/rs/moq-quic/README.md b/rs/moq-quic/README.md index aa452c23016..1f2df38cfda 100644 --- a/rs/moq-quic/README.md +++ b/rs/moq-quic/README.md @@ -44,7 +44,7 @@ Changes on top of the upstream commit, besides the renames: - **Plain configs**: `transport`, `client`, `server`, and `endpoint` configs are structs with public fields instead of setters, validated when an endpoint is built or dials. `Limits` is the one spelling of the windows and stream count, at construction and on a live connection, where it also changes the stream receive window. - **Close events**: a local close reports `connection::Error::LocallyClosed` with its code and reason as the connection's `ConnectionLost`, a handshake that idles out reports `HandshakeTimeout`, and close reasons are strings, lossily decoded. - **No early data**: TLS never offers or accepts 0-RTT, and early packets are discarded without decryption. The early keys, remembered transport parameters, stream rollback, and early-session driver APIs are removed. Session tickets still resume 1-RTT handshakes. MoQ's CONNECT and authorization already wait for the handshake. -- **BBR3**, from [quinn#2481](https://github.com/quinn-rs/quinn/pull/2481) at [`55f74c0d`](https://github.com/quinn-rs/quinn/pull/2481/commits/55f74c0dd0738b5ad7d7676c0b2869a547783f83) (open upstream), rebased onto the fork point with authorship kept. It replaces quinn's BBR and is the default controller. It carries the BBR correctness fixes moq-dev/noq shipped in `moq-noq` 1.3.1, and with them the `Controller` changes BBR needs: per-packet send and loss callbacks, `on_cwnd_limited`, `on_app_limited`, `on_ack_frequency_update`, and controller-owned pacing and burst size. `ControllerMetrics` rates are bytes per second. +- **BBR3**, from [quinn#2481](https://github.com/quinn-rs/quinn/pull/2481) at [`55f74c0d`](https://github.com/quinn-rs/quinn/pull/2481/commits/55f74c0dd0738b5ad7d7676c0b2869a547783f83) (open upstream), rebased onto the fork point with authorship kept. It replaces quinn's BBR and is the default controller. It carries the BBR correctness fixes moq-dev/noq shipped in `moq-noq` 1.3.1, and with them the `Controller` changes BBR needs: per-packet send and loss callbacks, `on_cwnd_limited`, `on_app_limited`, `on_ack_frequency_update`, and controller-owned pacing and burst size. `Metrics` rates are bytes per second. - **BBR3 loss samples**: a lost packet supplies its own inflight, loss, and application-limited state without borrowing or overwriting the ACK sample, including before the first ACK observation. This follows draft-06 and Google Linux BBRv3; upstream submission waits on quinn#2481 for the same callback adaptation as packet retirement. - **BBR3 packet retirement**: per-space packet lookup and round-indexed expiry retire completed snapshots incrementally, preserving the extra ACK batch of metadata for late loss callbacks. The bounded indexes handle sparse packet numbers without walking the live flight. Upstream submission is deferred while quinn#2481 remains open: this fork also carries the packet-space and loss callback adaptations, so a port needs to target that implementation after its shape settles. - **Classic ECN for BBR3**, ported from [moq-dev/noq#12](https://github.com/moq-dev/noq/pull/12): CE exits Startup, stops a bandwidth probe, or lowers the short-term model, once per recovery episode, instead of counting as a loss. @@ -85,7 +85,7 @@ Changes on top of the upstream commit, besides the renames: - **Namespaced streams** (`send`, `recv`, `stream`): quinn's `SendStream`, `RecvStream`, and their error zoo become `send::Stream` and `recv::Stream` with one `send::Error` (streams and datagrams) and one `recv::Error` (reads and leases), adding `Blocked`, and `Closed` for an ID the stream no longer has state for. `send::Stream::write` takes `&mut impl Buf`, splitting a `Bytes` source off without a copy, in place of `write` and `write_chunks`, and `Datagrams::send` takes `impl Buf` the same way, so a chained header costs no copy. An outgoing stream's `send::End` (finished and acknowledged, stopped, or reset) stays queryable until `send::Stream::release`, so a driver needs no table of its own for the fire-once `Finished` and `Stopped` events. A `send::Offset` comes only from `offset()` and is tagged to its stream, so `reset_at` and `acked` cannot be handed one past the data written. A port touching a public stream method has to be redone against these names. - **Connection limits** (`Limits`, `Connection::set_limits`, and the drivers' `set_limits`): one validated call changes a live connection's stream limit and windows, refusing values a peer would reject and changing nothing then. moq-tokio and moq-uring re-export the type, so both runtimes check limits the same way. Not offered upstream: it only bundles quinn's existing setters. - **Indexed send buffer** (`SendBuffer::get`): each retained write keeps its stream offset, and a STREAM frame's data comes from one binary search, instead of quinn walking every write from the oldest unacknowledged one for each piece, which costs a triangular number of visits when many small writes are in flight. Not offered upstream yet. -- **Bandwidth probing** (`Connection::set_probe_target`, `connection/bandwidth_probe.rs`): an application-limited sender below its target fills the headroom BBR3 opens, in Startup and in one ProbeBW\_UP per probe wait, with duplicates of STREAM data still in flight, paced to the target, so the controller's samples measure the path rather than the application. That inflight bounds an attempt like a window once it sends its first duplicate; media alone past it, as beside another flow's standing queue, leaves the sender application-limited. `Controller::probes` and `ControllerMetrics::probe_inflight` tell the sender when and how far it may fill; CUBIC never does. A duplicate is never retransmitted, a reset or stopped stream's data is never resent, and a loss retransmits only the ranges no copy delivered (`SendBuffer::retransmit`). An attempt that raises nothing for two round trips, or ends short of the target, sits out 3 s and then 4 s before retrying the same target; reaching the target or a new one retries at once. `PathStats::sent_bandwidth_probe_bytes` counts the redundant bytes. A cherry-pick touching `poll_transmit`'s space loop or `populate_packet` has to keep the probe after the ordinary frames. Not offered upstream. +- **Bandwidth probing** (`Connection::set_probe_target`, `connection/bandwidth_probe.rs`): an application-limited sender below its target fills the headroom BBR3 opens, in Startup and in one ProbeBW\_UP per probe wait, with duplicates of STREAM data still in flight, paced to the target, so the controller's samples measure the path rather than the application. That inflight bounds an attempt like a window once it sends its first duplicate; media alone past it, as beside another flow's standing queue, leaves the sender application-limited. `Controller::probes` and `Metrics::probe_inflight` tell the sender when and how far it may fill; CUBIC never does. A duplicate is never retransmitted, a reset or stopped stream's data is never resent, and a loss retransmits only the ranges no copy delivered (`SendBuffer::retransmit`). An attempt that raises nothing for two round trips, or ends short of the target, sits out 3 s and then 4 s before retrying the same target; reaching the target or a new one retries at once. `PathStats::sent_bandwidth_probe_bytes` counts the redundant bytes. A cherry-pick touching `poll_transmit`'s space loop or `populate_packet` has to keep the probe after the ordinary frames. Not offered upstream. - **Exact datagram overhead** (`Datagram::max_payload`): `Datagrams::max_size` subtracts the frame type and the length's actual varint size from the path budget and the peer's `max_datagram_frame_size`, instead of `Datagram::SIZE_BOUND`'s worst-case 8-byte length. RFC 9221 section 3 counts the frame type and length in the limit, so a peer advertising 1200 bytes (quicly does) accepts a 1197-byte payload, where reserving 8 bytes allows only 1191. quinn has the same behaviour; not offered upstream yet. A limit too small for even an empty frame, including RFC 9221's 0 for no support, makes `max_size` return `None` instead of accepting an empty payload. - **Waits** (`connection/waits.rs`): every wait is a `poll_*` taking the caller's `&kio::Waiter`, so a driver keeps no waiter tables of its own: `recv::Chunks::poll_next`, `recv::Stream::poll_lease`, `send::Stream::poll_write`, `poll_end`, and `poll_acked`, `Streams::poll_accept` and `poll_open`, `Datagrams::poll_recv`, and `Connection::poll_connected`, `poll_handshake_confirmed`, and `poll_closed`, over QUIC and QMux alike. The stream engine wakes each list where it reports the matching `StreamEvent` (`StreamsState::notify`), and wakes connection-blocked writers as soon as the window has room (`StreamsState::unblock`) rather than when `poll` next runs, so a port touching an event site has to keep the wake. A lost connection wakes every waiter, and each wait drains what arrived (accepted streams, readable bytes, datagrams) before it fails, a stream wait with `ConnectionLost`. Not offered upstream: quinn keeps its wakers in the async layer. diff --git a/rs/moq-quic/benches/common/mod.rs b/rs/moq-quic/benches/common/mod.rs index 12c4b20417d..2f915dd34a8 100644 --- a/rs/moq-quic/benches/common/mod.rs +++ b/rs/moq-quic/benches/common/mod.rs @@ -8,7 +8,6 @@ //! host descheduling the benchmark does not inflate them. use std::{ - any::Any, collections::{HashMap, VecDeque}, net::{Ipv6Addr, SocketAddr}, num::NonZeroU64, @@ -23,7 +22,7 @@ use criterion::{ measurement::{Measurement, ValueFormatter, WallTime}, }; use kio::clock::Instant; -use moq_congestion::{Ack, Ce, Controller, ControllerFactory, ControllerMetrics, Init, Loss, Packet, Sent}; +use moq_congestion::{Ack, Ce, Controller, Factory, Init, Loss, Metrics, Packet, Sent}; use moq_quic::{ ConnectionId, ConnectionIdGenerator, Event, RandomConnectionIdGenerator, StreamEvent, VarInt, client, connection::Connection, @@ -706,8 +705,8 @@ impl Controller for Unlimited { None } - fn metrics(&self) -> ControllerMetrics { - ControllerMetrics { + fn metrics(&self) -> Metrics { + Metrics { congestion_window: WINDOW, probe_inflight: self.probe.then_some(WINDOW), ..Default::default() @@ -721,13 +720,9 @@ impl Controller for Unlimited { fn clone_box(&self) -> Box { Box::new(*self) } - - fn into_any(self: Box) -> Box { - self - } } -impl ControllerFactory for Unlimited { +impl Factory for Unlimited { fn build(self: Arc, _init: Init) -> Box { Box::new(*self) } diff --git a/rs/moq-quic/src/config/transport/mod.rs b/rs/moq-quic/src/config/transport/mod.rs index 4032c9e2e1b..56c27dd18fc 100644 --- a/rs/moq-quic/src/config/transport/mod.rs +++ b/rs/moq-quic/src/config/transport/mod.rs @@ -161,7 +161,7 @@ pub struct Config { pub receive_timestamps: Option, /// How to construct each connection's congestion controller, BBRv3 by default - pub congestion: Arc, + pub congestion: Arc, /// An outbound rate limit for each connection, in bytes per second, or `None` (the default) /// for none @@ -311,7 +311,7 @@ impl Default for Config { receive_timestamps: None, congestion: Arc::new({ - let config = congestion::Bbr3Config::default(); + let config = congestion::bbr3::Config::default(); #[cfg(test)] let config = { let mut config = config; diff --git a/rs/moq-quic/src/connection/mod.rs b/rs/moq-quic/src/connection/mod.rs index e87c0212714..c7ce9b5a447 100644 --- a/rs/moq-quic/src/connection/mod.rs +++ b/rs/moq-quic/src/connection/mod.rs @@ -1595,7 +1595,7 @@ impl Connection { /// A congestion controller stops raising its estimate once the application sends less than /// the path carries. While the controller probes for bandwidth below this target, the sender /// fills the inflight it allows - /// ([`probe_inflight`](crate::congestion::ControllerMetrics::probe_inflight)) with duplicates + /// ([`probe_inflight`](crate::congestion::Metrics::probe_inflight)) with duplicates /// of STREAM data still in flight, sending no more than the target in all, so the probe /// measures the path. Duplicates count against congestion control, as /// [`PathStats::sent_bandwidth_probe_bytes`]. A reset stream's data is never sent again. An diff --git a/rs/moq-quic/src/tests/characterize/mod.rs b/rs/moq-quic/src/tests/characterize/mod.rs index 392148a8774..504380f6b0d 100644 --- a/rs/moq-quic/src/tests/characterize/mod.rs +++ b/rs/moq-quic/src/tests/characterize/mod.rs @@ -19,7 +19,7 @@ mod schedule; /// The transport every characterization pair runs: Cubic with deterministic packet numbers fn transport() -> transport::Config { transport::Config { - congestion: Arc::new(congestion::CubicConfig::default()), + congestion: Arc::new(congestion::cubic::Config::default()), deterministic_packet_numbers: true, ..transport::Config::default() } diff --git a/rs/moq-quic/src/tests/mod.rs b/rs/moq-quic/src/tests/mod.rs index 304be041a60..1398d7bcf57 100644 --- a/rs/moq-quic/src/tests/mod.rs +++ b/rs/moq-quic/src/tests/mod.rs @@ -1,6 +1,5 @@ use crate::cid_generator::HashedConnectionIdGenerator; use std::{ - any::Any, collections::{BTreeMap, BTreeSet}, convert::TryInto, iter, mem, @@ -31,7 +30,7 @@ use super::*; use crate::{ Duration, Instant, cid_generator::{ConnectionIdGenerator, RandomConnectionIdGenerator}, - congestion::{self, Controller, ControllerFactory, ControllerMetrics}, + congestion::{self, Controller, Factory, Metrics}, connection::{Connection, Error as ConnectionError}, crypto::rustls::QuicServerConfig, endpoint::{Accepting, ConnectionHandle, DatagramEvent, Dial, Endpoint, Incoming, Received}, @@ -484,8 +483,8 @@ fn stats_include_congestion_controller_bandwidth_estimate() { None } - fn metrics(&self) -> ControllerMetrics { - ControllerMetrics { + fn metrics(&self) -> Metrics { + Metrics { congestion_window: WINDOW, bandwidth_estimate: Some(BANDWIDTH_ESTIMATE), ..Default::default() @@ -495,22 +494,18 @@ fn stats_include_congestion_controller_bandwidth_estimate() { fn clone_box(&self) -> Box { Box::new(self.clone()) } - - fn into_any(self: Box) -> Box { - self - } } - struct TestControllerFactory; + struct TestFactory; - impl ControllerFactory for TestControllerFactory { + impl Factory for TestFactory { fn build(self: Arc, _init: congestion::Init) -> Box { Box::new(TestController) } } let transport = transport::Config { - congestion: Arc::new(TestControllerFactory), + congestion: Arc::new(TestFactory), ..transport::Config::default() }; let mut config = client_config(); @@ -5969,8 +5964,8 @@ impl Controller for PacingOnlyController { self.pacer.pace(now) } - fn metrics(&self) -> ControllerMetrics { - ControllerMetrics { + fn metrics(&self) -> Metrics { + Metrics { congestion_window: self.window(), pacing_rate: Some(Self::RATE), ..Default::default() @@ -5983,17 +5978,13 @@ impl Controller for PacingOnlyController { pacer: self.pacer.clone(), }) } - - fn into_any(self: Box) -> Box { - self - } } struct PacingOnlyConfig { cwnd_limited_reports: Arc, } -impl ControllerFactory for PacingOnlyConfig { +impl Factory for PacingOnlyConfig { fn build(self: Arc, _init: congestion::Init) -> Box { Box::new(PacingOnlyController { cwnd_limited_reports: self.cwnd_limited_reports.clone(), @@ -6067,13 +6058,9 @@ impl Controller for FixedQuantumController { fn clone_box(&self) -> Box { Box::new(self.clone()) } - - fn into_any(self: Box) -> Box { - self - } } -impl ControllerFactory for FixedQuantumController { +impl Factory for FixedQuantumController { fn build(self: Arc, _init: congestion::Init) -> Box { Box::new((*self).clone()) } @@ -6196,8 +6183,8 @@ impl Controller for PacketRecorder { self.pacer.pace(now) } - fn metrics(&self) -> ControllerMetrics { - ControllerMetrics { + fn metrics(&self) -> Metrics { + Metrics { congestion_window: self.window, pacing_rate: self.pacing_rate, ..Default::default() @@ -6207,10 +6194,6 @@ impl Controller for PacketRecorder { fn clone_box(&self) -> Box { Box::new(self.clone()) } - - fn into_any(self: Box) -> Box { - self - } } /// Gives every controller it builds, one per path per side, a log of its own. @@ -6223,7 +6206,7 @@ struct PacketRecorderFactory { pacing_rate: Option, } -impl ControllerFactory for PacketRecorderFactory { +impl Factory for PacketRecorderFactory { fn build(self: Arc, _init: congestion::Init) -> Box { let log = PacketLog::default(); self.logs.lock().unwrap().push(log.clone()); @@ -6936,7 +6919,7 @@ fn upload( } #[test] -fn default_controller_is_bbr3() { +fn default_controller_supports_bandwidth_probing() { let factory = transport::Config::default().congestion; let controller = factory.build(congestion::Init { now: Instant::now(), @@ -6944,5 +6927,6 @@ fn default_controller_is_bbr3() { rtt: Duration::from_millis(333), max_pacing_rate: None, }); - assert!(controller.into_any().downcast::().is_ok()); + assert!(controller.probes()); + assert!(controller.metrics().pacing_rate.is_some()); } diff --git a/rs/moq-quic/src/tests/probe.rs b/rs/moq-quic/src/tests/probe.rs index 3937ef7cbe6..ad1dbae270c 100644 --- a/rs/moq-quic/src/tests/probe.rs +++ b/rs/moq-quic/src/tests/probe.rs @@ -8,12 +8,12 @@ //! `just rs quic-sim`, holding each budget on the mean across [`SEEDS`], since one seed's outcome //! beside a competing upload is a coin flip. //! -//! The same media trace without a target also checks when BBR3 skips ProbeRTT. +//! The same media trace without a target also checks keyframe delivery deadlines. use std::collections::HashMap; use super::*; -use crate::congestion::{Bbr3, CubicConfig}; +use crate::congestion::cubic; /// The media's bitrate, 2 Mbit/s, which the probe has to see past const MEDIA: u64 = 250_000; @@ -131,10 +131,6 @@ struct Outcome { expired: u64, /// Samples taken while the controller allowed a probe probing: u64, - /// ProbeRTT entries the samples caught, each lasting longer than the sampling interval - probe_rtts: u64, - /// The largest minimum RTT the controller's model held at a sample - min_rtt: Duration, /// The most media bytes written and not yet read at a sample: the sender's backlog plus /// what is in flight unread: u64, @@ -211,8 +207,6 @@ impl Outcome { competitor = self.competitor, expired = self.expired, probing = self.probing, - probe_rtts = self.probe_rtts, - min_rtt = ?self.min_rtt, unread = self.unread, "Mbit/s {estimates}" ); @@ -273,7 +267,7 @@ fn run(scenario: &Scenario) -> Outcome { let competitor = scenario.competitor.map(|upload| { let mut transport = transport::Config::default(); if let Upload::Cubic = upload { - transport.congestion = Arc::new(CubicConfig::default()); + transport.congestion = Arc::new(cubic::Config::default()); } let mut config = client_config(); config.transport = transport; @@ -296,7 +290,6 @@ fn run(scenario: &Scenario) -> Outcome { let mut next_frame = 0u64; let mut next_sample = start; let mut next_rate = 1; - let mut probing_rtt = false; let mut competing = competitor.map(|(client, server)| { let id = pair.client_streams(client).open(Dir::Uni, Default::default()).unwrap(); (client, server, id, None::) @@ -370,15 +363,6 @@ fn run(scenario: &Scenario) -> Outcome { if now >= next_sample { let estimate = conn.stats().path.bandwidth_estimate.unwrap_or(0); outcome.probing += conn.congestion_state().metrics().probe_inflight.is_some() as u64; - let bbr = conn - .congestion_state() - .clone_box() - .into_any() - .downcast::() - .expect("BBR3"); - outcome.probe_rtts += (bbr.probing_rtt() && !probing_rtt) as u64; - probing_rtt = bbr.probing_rtt(); - outcome.min_rtt = outcome.min_rtt.max(bbr.min_rtt()); let read: u64 = readings.values().map(|r| r.read).sum(); outcome.unread = outcome.unread.max(outcome.unique - read); outcome.samples.push(Sample { @@ -1028,7 +1012,7 @@ fn rtt_200ms() { /// past the deadline, but between bursts the flow is application-limited without loss, so it /// skips ProbeRTT. #[test] -fn borderline_skips_probe_rtt() { +fn borderline_frames_meet_deadline() { let _guard = subscribe(); let outcome = run(&Scenario { target: 0, @@ -1036,33 +1020,6 @@ fn borderline_skips_probe_rtt() { ..Scenario::default() }); outcome.report("borderline"); - assert_eq!(outcome.probe_rtts, 0); let slowest = *outcome.delays.last().expect("delivered"); assert!(slowest < DEADLINE, "a frame took {slowest:?}"); } - -/// Below the media's bitrate, behind a queue that holds a standing delay and still overflows -/// -/// The overflow's losses deny every skip, so the flow enters each ProbeRTT due, one per 5s -/// interval after its exit, and the model's minimum stays below the path's mean RTT rather than -/// creeping up through the queue. -#[test] -fn overflow_keeps_probe_rtt() { - let _guard = subscribe(); - let scenario = Scenario { - target: 0, - rates: vec![(Duration::ZERO, 187_500)], - buffer: 15_000, - ..Scenario::default() - }; - let outcome = run(&scenario); - outcome.report("overflow"); - assert!(outcome.queue.dropped > 0, "the queue never overflowed"); - assert!(outcome.probe_rtts >= scenario.duration.as_secs() / 5 - 1); - let mean_rtt = 2 * scenario.latency + outcome.queue.mean_delay(); - assert!( - outcome.min_rtt < mean_rtt, - "min RTT {:?} crept past the mean RTT {mean_rtt:?}", - outcome.min_rtt - ); -} diff --git a/rs/moq-quic/src/tests/receive_ts.rs b/rs/moq-quic/src/tests/receive_ts.rs index 65f872b90e7..8bdab106709 100644 --- a/rs/moq-quic/src/tests/receive_ts.rs +++ b/rs/moq-quic/src/tests/receive_ts.rs @@ -98,13 +98,9 @@ impl Controller for Recorder { fn clone_box(&self) -> Box { Box::new(self.clone()) } - - fn into_any(self: Box) -> Box { - self - } } -impl ControllerFactory for Recorder { +impl Factory for Recorder { fn build(self: Arc, _init: congestion::Init) -> Box { Box::new((*self).clone()) } diff --git a/rs/moq-quic/src/tests/util.rs b/rs/moq-quic/src/tests/util.rs index 1a94755b49e..3ae406e3d0e 100644 --- a/rs/moq-quic/src/tests/util.rs +++ b/rs/moq-quic/src/tests/util.rs @@ -730,7 +730,7 @@ pub(super) fn client_config_with_deterministic_pns() -> client::Config { /// leave at once, while BBR3 paces from its own rate and releases a burst nanoseconds later. pub(super) fn cubic_transport() -> transport::Config { transport::Config { - congestion: Arc::new(congestion::CubicConfig::default()), + congestion: Arc::new(congestion::cubic::Config::default()), ..transport::Config::default() } } diff --git a/rs/moq-tokio/src/quic/backend.rs b/rs/moq-tokio/src/quic/backend.rs index 7fe873b77a3..f7e20e97aec 100644 --- a/rs/moq-tokio/src/quic/backend.rs +++ b/rs/moq-tokio/src/quic/backend.rs @@ -70,10 +70,10 @@ fn apply_qlog(transport: &mut driver::transport::Config, quic: &Resolved, role: } /// The controller factory for a congestion control family. moq-quic's BBR is v3. -fn congestion_factory(family: CongestionControl) -> Arc { +fn congestion_factory(family: CongestionControl) -> Arc { match family { - CongestionControl::Loss => Arc::new(moq_congestion::CubicConfig::default()), - CongestionControl::Delay => Arc::new(moq_congestion::Bbr3Config::default()), + CongestionControl::Loss => Arc::new(moq_congestion::cubic::Config::default()), + CongestionControl::Delay => Arc::new(moq_congestion::bbr3::Config::default()), CongestionControl::None => Arc::new(moq_congestion::Unlimited), } } @@ -971,8 +971,7 @@ mod tests { assert_eq!(limits.send_window.unwrap().get(), crate::quic::DEFAULT_SEND_WINDOW); } - /// Build a controller from each family's factory and downcast it to the - /// concrete moq-quic implementation it must map to. + /// Each family supplies its advertised congestion behavior. #[test] fn congestion_factory_maps_each_family() { let init = moq_congestion::Init { @@ -983,13 +982,16 @@ mod tests { }; let loss = congestion_factory(CongestionControl::Loss).build(init); - assert!(loss.into_any().downcast::().is_ok()); + assert!(loss.metrics().ssthresh.is_some()); + assert!(!loss.probes()); let delay = congestion_factory(CongestionControl::Delay).build(init); - assert!(delay.into_any().downcast::().is_ok()); + assert!(delay.probes()); + assert!(delay.metrics().pacing_rate.is_some()); let none = congestion_factory(CongestionControl::None).build(init); - assert!(none.into_any().downcast::().is_ok()); + assert_eq!(none.window(), u64::MAX); + assert!(!none.probes()); } /// Loopback regression test: with the knob unset, live QUIC connections must run @@ -1021,7 +1023,7 @@ mod tests { let accepted = tokio::spawn(async move { let incoming = server.accept().await.expect("no incoming connection"); let conn = incoming.accept().expect("accept").await.expect("handshake"); - is_bbr3(&conn) + conn.congestion_state().probes() }); // tls::Connect has a private field, so it can't be built with a struct literal. @@ -1048,24 +1050,16 @@ mod tests { .expect("connect failed"); // web::Session derefs to the driver connection. - assert!(is_bbr3(&session), "client connection is not running BBRv3"); + assert!(session.congestion_state().probes(), "client controller cannot probe"); // BBRv3 can probe, so moq-net gets a target to write. #[cfg(feature = "net")] assert!(session.probe().is_some(), "BBRv3 connection has no probe target"); assert!( accepted.await.expect("server task panicked"), - "server connection is not running BBRv3" + "server controller cannot probe" ); }) .await .expect("test timed out"); } - - /// Whether a live connection is running BBRv3. - fn is_bbr3(conn: &driver::connection::Connection) -> bool { - conn.congestion_state() - .into_any() - .downcast::() - .is_ok() - } } diff --git a/rs/moq-tokio/tests/integration/receive_ts.rs b/rs/moq-tokio/tests/integration/receive_ts.rs index f75a21e68fe..cd3a7b7de87 100644 --- a/rs/moq-tokio/tests/integration/receive_ts.rs +++ b/rs/moq-tokio/tests/integration/receive_ts.rs @@ -86,13 +86,9 @@ impl Controller for Recorder { fn clone_box(&self) -> Box { Box::new(self.clone()) } - - fn into_any(self: Box) -> Box { - self - } } -impl congestion::ControllerFactory for Recorder { +impl congestion::Factory for Recorder { fn build(self: Arc, _init: congestion::Init) -> Box { Box::new((*self).clone()) } diff --git a/rs/moq-tokio/tests/integration/sim.rs b/rs/moq-tokio/tests/integration/sim.rs index 1be6c0b8618..da2471bec53 100644 --- a/rs/moq-tokio/tests/integration/sim.rs +++ b/rs/moq-tokio/tests/integration/sim.rs @@ -230,7 +230,7 @@ fn endpoint(seed: u64, host: u8) -> driver::endpoint::Config { /// The default transport, with BBR3's probe phases drawn from `seed` fn transport(seed: u64) -> driver::transport::Config { - let mut bbr = moq_congestion::Bbr3Config::default(); + let mut bbr = moq_congestion::bbr3::Config::default(); let mut probe = [0; 16]; probe[..8].copy_from_slice(&seed.to_le_bytes()); bbr.probe_rng_seed(probe); diff --git a/rs/moq-uring/src/quic/driver/mod.rs b/rs/moq-uring/src/quic/driver/mod.rs index 55175fad728..9217b33b368 100644 --- a/rs/moq-uring/src/quic/driver/mod.rs +++ b/rs/moq-uring/src/quic/driver/mod.rs @@ -265,9 +265,9 @@ fn transport_config(config: &transport::Config) -> Result { - Arc::new(moq_congestion::CubicConfig::default()) as Arc + Arc::new(moq_congestion::cubic::Config::default()) as Arc } - Congestion::Delay => Arc::new(moq_congestion::Bbr3Config::default()), + Congestion::Delay => Arc::new(moq_congestion::bbr3::Config::default()), Congestion::None => Arc::new(moq_congestion::Unlimited), }; // A value that cannot go on the wire is an error: clamping it would ignore what was set.