From 6e03980ef1317b28f9995be42ac1f019c7820a61 Mon Sep 17 00:00:00 2001 From: Luke Curley Date: Thu, 29 Oct 2026 10:10:27 -0700 Subject: [PATCH 1/6] chore(quest): claim quest/m1/api-audit/congestion-names.md Quest-Claim: 4178ee1f0ee82e5a From 1b9b8a4a56596791e9333d5e8f70110f48e9299d Mon Sep 17 00:00:00 2001 From: Luke Curley Date: Thu, 29 Oct 2026 10:17:20 -0700 Subject: [PATCH 2/6] refactor(congestion)!: namespace configs and remove downcasting Co-Authored-By: GPT-6.1 Sol --- quest/m1/api-audit/congestion-names.md | 28 ++++-- rs/moq-congestion/Cargo.toml | 2 +- rs/moq-congestion/README.md | 4 + rs/moq-congestion/src/bbr3/bench.rs | 2 +- rs/moq-congestion/src/bbr3/mod.rs | 116 +++++++++------------- rs/moq-congestion/src/cubic.rs | 23 ++--- rs/moq-congestion/src/lib.rs | 24 ++--- rs/moq-congestion/src/unlimited.rs | 9 +- rs/moq-quic/MIGRATE.md | 2 +- rs/moq-quic/README.md | 4 +- rs/moq-quic/benches/common/mod.rs | 13 +-- rs/moq-quic/src/config/transport/mod.rs | 4 +- rs/moq-quic/src/connection/mod.rs | 2 +- rs/moq-quic/src/tests/characterize/mod.rs | 2 +- rs/moq-quic/src/tests/mod.rs | 48 +++------ rs/moq-quic/src/tests/probe.rs | 51 +--------- rs/moq-quic/src/tests/util.rs | 2 +- rs/moq-tokio/src/quic/backend.rs | 32 +++--- rs/moq-uring/src/quic/driver/mod.rs | 4 +- 19 files changed, 144 insertions(+), 228 deletions(-) diff --git a/quest/m1/api-audit/congestion-names.md b/quest/m1/api-audit/congestion-names.md index 6584d982780..fc5ea27c998 100644 --- a/quest/m1/api-audit/congestion-names.md +++ b/quest/m1/api-audit/congestion-names.md @@ -13,6 +13,19 @@ Non-goals: new controller signals or a controller framework, and ## Plan +The implementation is complete in [the draft PR](https://github.com/moq-dev/moq/pull/7258). +Remaining work is local validation: run `quest gate just ci` on a host where +the Cargo launcher can execute the selected commands and the Nix builder can +create user namespaces for the runner-image check. This host refused both +(`mbx`: `Argument list too long`; runner image: `/proc/self/uid_map` denied). +The affected crates pass `just rs check`, including all targets and docs. +The congestion, QUIC, and Tokio suites pass all 1,297 tests. io_uring's suite +also needs enough user-wide memlock: a serial run passed 80 tests but failed +49 during ring setup at this host's shared 8 MiB limit. Local review found no +remaining implementation issue. Finish the full gate and io_uring tests, +review any resulting fixes, then remove this quest and its links and mark +the PR ready. Do not merge or enqueue it. + Decided 2026-10-27 from the release-to-main API audit (maintainer picked each option): @@ -24,15 +37,14 @@ option): 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. +- **Remove `into_any`**: selection tests use observable behavior and metrics. + QUIC's duplicate inspection of ProbeRTT internals and the test-only BBR3 + accessors are removed; the direct controller tests cover those model + invariants, and QUIC retains the media deadline check. 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. + (`congestion: Arc`, defaulting to + `congestion::bbr3::Config`); its uses, tests, and bench use the new names. 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. diff --git a/rs/moq-congestion/Cargo.toml b/rs/moq-congestion/Cargo.toml index d79e64598f9..a864568dd38 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 de14ca649ee..2a00ed87aea 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 `moq_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 db58d731f40..412793d5b2f 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 59a62cf4679..c2fe085c772 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}; @@ -523,20 +521,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 { @@ -1937,8 +1923,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), @@ -1954,10 +1940,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 @@ -1969,7 +1951,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, @@ -1983,7 +1965,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))` @@ -2000,7 +1982,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 @@ -2020,7 +2002,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)) } @@ -2048,7 +2030,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, @@ -2184,7 +2166,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(), @@ -2370,8 +2352,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(); @@ -2384,7 +2366,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, @@ -2435,7 +2417,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 @@ -2513,7 +2495,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(); @@ -2673,7 +2655,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 @@ -2772,7 +2754,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(); @@ -2943,7 +2925,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 @@ -2995,7 +2977,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; @@ -3013,7 +2995,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); @@ -3094,7 +3076,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(); @@ -3286,7 +3268,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(); @@ -3467,7 +3449,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 @@ -3607,9 +3589,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); @@ -3756,7 +3738,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. @@ -3940,7 +3922,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(); @@ -4194,7 +4176,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(); @@ -4393,7 +4375,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(); @@ -4695,9 +4677,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); @@ -4977,9 +4959,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); @@ -5227,9 +5209,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); @@ -5448,9 +5430,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); @@ -5670,9 +5652,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); @@ -5935,9 +5917,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); @@ -6211,7 +6193,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(); @@ -6472,9 +6454,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); @@ -6714,9 +6696,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); @@ -6953,7 +6935,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. @@ -8033,9 +8015,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 a45e32909fb..02d35a0e722 100644 --- a/rs/moq-congestion/src/lib.rs +++ b/rs/moq-congestion/src/lib.rs @@ -8,17 +8,18 @@ use moq_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; @@ -99,8 +100,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, @@ -109,7 +110,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 @@ -117,9 +118,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. @@ -198,7 +196,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) @@ -229,7 +227,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 11a13e91236..c94247e464b 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 f4f728d57be..a32630beb62 100644 --- a/rs/moq-quic/README.md +++ b/rs/moq-quic/README.md @@ -39,7 +39,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. @@ -78,7 +78,7 @@ Changes on top of the upstream commit, besides the renames: - **Stopped after a local reset**: moq-tokio's driver resolves `SendStream::stopped` with `None` once the stream is reset locally, as it already did once the reset was acknowledged and the stream freed. No stream event reports a local reset, so quinn leaves a pending `stopped` waiting, and its waker registered, until the connection closes. Not offered upstream yet; quinn 0.11 has the same gap. - **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. `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 within 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. `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 within 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. Recheck the BBR3 changes when porting quinn#2481 updates, or if it merges. diff --git a/rs/moq-quic/benches/common/mod.rs b/rs/moq-quic/benches/common/mod.rs index 143c1ab10b7..bc9f282078c 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 moq_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, LeaseError, RandomConnectionIdGenerator, ReadError, StreamEvent, StreamId, VarInt, client, @@ -705,8 +704,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() @@ -720,13 +719,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 1684e978b08..6450a8c0e06 100644 --- a/rs/moq-quic/src/config/transport/mod.rs +++ b/rs/moq-quic/src/config/transport/mod.rs @@ -142,7 +142,7 @@ pub struct Config { pub ack_frequency: 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 @@ -276,7 +276,7 @@ impl Default for Config { ack_frequency: 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 9973889acfd..a0b23fb9a1f 100644 --- a/rs/moq-quic/src/connection/mod.rs +++ b/rs/moq-quic/src/connection/mod.rs @@ -1501,7 +1501,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 9a1d08cd3d1..fa6e18e2827 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}, @@ -483,8 +482,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() @@ -494,22 +493,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(); @@ -5785,8 +5780,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() @@ -5799,17 +5794,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(), @@ -5883,13 +5874,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()) } @@ -6012,8 +5999,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() @@ -6023,10 +6010,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. @@ -6039,7 +6022,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()); @@ -6733,7 +6716,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(), @@ -6741,5 +6724,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 20d716aab2a..014673d2a70 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}" ); @@ -270,7 +264,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; @@ -293,7 +287,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::) @@ -367,15 +360,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 { @@ -979,7 +963,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, @@ -987,33 +971,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/util.rs b/rs/moq-quic/src/tests/util.rs index ef61060da26..4890024f062 100644 --- a/rs/moq-quic/src/tests/util.rs +++ b/rs/moq-quic/src/tests/util.rs @@ -866,7 +866,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 5f344469d0f..243f7a09f78 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), } } @@ -972,8 +972,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 { @@ -984,13 +983,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 @@ -1022,7 +1024,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. @@ -1049,24 +1051,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-uring/src/quic/driver/mod.rs b/rs/moq-uring/src/quic/driver/mod.rs index a55ed4c0004..cf4f149ff82 100644 --- a/rs/moq-uring/src/quic/driver/mod.rs +++ b/rs/moq-uring/src/quic/driver/mod.rs @@ -266,9 +266,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. From 39974dc80a92a7733048effb1f1a96ce997b8434 Mon Sep 17 00:00:00 2001 From: Luke Curley Date: Fri, 30 Oct 2026 21:58:42 -0700 Subject: [PATCH 3/6] quest: finish moq-congestion's first-publish names Co-Authored-By: Claude Opus 5.5 --- quest/m1/api-audit/README.md | 1 - quest/m1/api-audit/congestion-names.md | 51 -------------------------- quest/m1/quic-api/README.md | 3 +- 3 files changed, 1 insertion(+), 54 deletions(-) delete mode 100644 quest/m1/api-audit/congestion-names.md diff --git a/quest/m1/api-audit/README.md b/quest/m1/api-audit/README.md index 37e07504fdf..73c222040ca 100644 --- a/quest/m1/api-audit/README.md +++ b/quest/m1/api-audit/README.md @@ -77,7 +77,6 @@ Rejected in planning: - [Demand is wanted, everywhere](/quest/m1/api-audit/wanted.md) - every `used`/`unused` pair becomes `wanted()` and `wanted_changed()`, and unused ones go - [QMux datagrams obey or refuse their policy](/quest/m1/api-audit/qmux-datagrams.md) - `Session.datagrams` is the DOM interface, its high-water mark is live, and the inert settings throw - [No constructible internal handles](/quest/m1/api-audit/internal-constructors.md) - `Rendition`, `Lister`, `Arrivals`, and e2ee's generations get private constructors, and a lint rule stops new ones -- [moq-congestion's first-publish names](/quest/m1/api-audit/congestion-names.md) - `bbr3::Config`, `cubic::Config`, `Metrics`, `Factory`, and no `into_any` ## Related diff --git a/quest/m1/api-audit/congestion-names.md b/quest/m1/api-audit/congestion-names.md deleted file mode 100644 index fc5ea27c998..00000000000 --- a/quest/m1/api-audit/congestion-names.md +++ /dev/null @@ -1,51 +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 - -The implementation is complete in [the draft PR](https://github.com/moq-dev/moq/pull/7258). -Remaining work is local validation: run `quest gate just ci` on a host where -the Cargo launcher can execute the selected commands and the Nix builder can -create user namespaces for the runner-image check. This host refused both -(`mbx`: `Argument list too long`; runner image: `/proc/self/uid_map` denied). -The affected crates pass `just rs check`, including all targets and docs. -The congestion, QUIC, and Tokio suites pass all 1,297 tests. io_uring's suite -also needs enough user-wide memlock: a serial run passed 80 tests but failed -49 during ring setup at this host's shared 8 MiB limit. Local review found no -remaining implementation issue. Finish the full gate and io_uring tests, -review any resulting fixes, then remove this quest and its links and mark -the PR ready. Do not merge or enqueue it. - -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`**: selection tests use observable behavior and metrics. - QUIC's duplicate inspection of ProbeRTT internals and the test-only BBR3 - accessors are removed; the direct controller tests cover those model - invariants, and QUIC retains the media deadline check. 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::bbr3::Config`); its uses, tests, and bench use the new names. - -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. From 0a73bad085716eb0763f88b6f0fd1f3338a833d8 Mon Sep 17 00:00:00 2001 From: quest fixer Date: Sun, 1 Nov 2026 11:58:52 -0800 Subject: [PATCH 4/6] docs(congestion): follow Metrics rename in probe link --- rs/moq-congestion/src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rs/moq-congestion/src/lib.rs b/rs/moq-congestion/src/lib.rs index 9bd648d5c16..a5dbc9422cd 100644 --- a/rs/moq-congestion/src/lib.rs +++ b/rs/moq-congestion/src/lib.rs @@ -50,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 From 8778db55297b29a805ac8eb6222fc4af168a23ca Mon Sep 17 00:00:00 2001 From: quest fixer Date: Sun, 1 Nov 2026 12:01:38 -0800 Subject: [PATCH 5/6] test(quic): follow congestion API renames in base tests --- rs/moq-quic/src/tests/receive_ts.rs | 6 +----- rs/moq-tokio/tests/integration/receive_ts.rs | 6 +----- rs/moq-tokio/tests/integration/sim.rs | 2 +- 3 files changed, 3 insertions(+), 11 deletions(-) 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-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); From 3f8257dc57338bcad6797756a58f71feab19d703 Mon Sep 17 00:00:00 2001 From: Luke Curley Date: Sun, 1 Nov 2026 13:28:06 -0800 Subject: [PATCH 6/6] quest: follow congestion API renames in quic-realtime quests Co-Authored-By: Claude Opus 5.5 --- quest/m2/quic-realtime/README.md | 2 +- quest/m2/quic-realtime/gcc.md | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/quest/m2/quic-realtime/README.md b/quest/m2/quic-realtime/README.md index 2192afeb0b0..e608a88ff52 100644 --- a/quest/m2/quic-realtime/README.md +++ b/quest/m2/quic-realtime/README.md @@ -70,7 +70,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