From 2eef9fa56a76d616ebb35dc27cd78bb62ded1bae Mon Sep 17 00:00:00 2001 From: Luke Curley Date: Sun, 15 Nov 2026 03:19:08 -0800 Subject: [PATCH 1/2] chore(quest): claim quest/m1/bbr3-references/probe-rtt.md Quest-Claim: b8ac7594f97e8940 From 01e7e8eb0e2de76e149f2039c0e922fd009860b3 Mon Sep 17 00:00:00 2001 From: Luke Curley Date: Sun, 15 Nov 2026 03:45:50 -0800 Subject: [PATCH 2/2] fix(moq-congestion): BBR3 schedules ProbeRTT as draft-07 does BBR3 now enters ProbeRTT when its 10 s min_rtt filter expires instead of on draft-06's separate 5 s ProbeRTTInterval, caps ProbeRTT at half the BDP of the expiring min_rtt (BBR.probe_rtt_cwnd), saves the window before entering ProbeRTT, and replaces ack_phase and is_bw_probe_sample with is_bw_probe_stopping and check_probe_loss. Doc links cite draft-07. The application-limited ProbeRTT skip stays: a skip now adopts the expired window's lowest RTT sample as min_rtt, so a base RTT that rose is learned, and spurious-loss undo restores the skip's congestion evidence. Co-Authored-By: Claude Opus 5.5 --- quest/m1/bbr3-references/probe-rtt.md | 43 -- rs/moq-congestion/src/bbr3/max_filter.rs | 4 +- rs/moq-congestion/src/bbr3/mod.rs | 837 ++++++++++++----------- rs/moq-congestion/src/pacer.rs | 2 +- rs/moq-congestion/src/rate.rs | 12 +- 5 files changed, 435 insertions(+), 463 deletions(-) delete mode 100644 quest/m1/bbr3-references/probe-rtt.md diff --git a/quest/m1/bbr3-references/probe-rtt.md b/quest/m1/bbr3-references/probe-rtt.md deleted file mode 100644 index f3ad54d07fb..00000000000 --- a/quest/m1/bbr3-references/probe-rtt.md +++ /dev/null @@ -1,43 +0,0 @@ -# [M] BBR3 schedules ProbeRTT as draft-07 does - -## Goal - -BBR3 enters ProbeRTT when its 10 s `min_rtt` filter expires, as -[draft-07](https://www.ietf.org/archive/id/draft-ietf-ccwg-bbr-07.html#section-5.3.4) -does, halving ProbeRTT's cost for a backlogged sender, while an -application-limited sender still skips it and still learns a base RTT that -rose. - -## Plan - -draft-07 drops the 5 s `ProbeRTTInterval` and the `probe_rtt_min_delay`, -`probe_rtt_min_stamp`, and `probe_rtt_expired` fields, adds -`BBR.probe_rtt_cwnd` (half the BDP from the old `min_rtt`) to -`ProbeRTTCwnd()`, calls `SaveCwnd()` before `EnterProbeRTT()` (ours saves -after, so `prior_cwnd` only ratchets up), and replaces `ack_phase` with -`is_bw_probe_stopping` and `is_bw_probe_sample` with `check_probe_loss`. -Adopt all of it, citing -07 anchors throughout `rs/moq-congestion/src/bbr3/`. -QUICHE BBR3 also uses a 10 s period. - -The application-limited ProbeRTT skip stays. Decided 2026-11-14 (agent pick -after the maintainer answered "I don't know", for review), keeping the -skip's benefit for media: - -- ✅ Spurious-loss undo restores `probe_rtt_skip_congested` to its value - when the episode began, since a loss proven spurious was not congestion, - while a CE or real loss earlier in the interval still denies the skip. - Save it with the other undo state in `enter_recovery`; restarting the - interval clears the saved value too. -- ✅ A skipped expiry adopts the expired window's lowest RTT sample as - `min_rtt` instead of only refreshing its stamp, so a base RTT that rose - is learned without running ProbeRTT; an application-limited sender's - samples carry little self-induced queue. -- Rejected: QUICHE BBRv1's kBBR7 guard (run ProbeRTT when RTT drifted past - 12.5%), which would put ProbeRTT's half-BDP cap back on media; and denying - the skip only on loss above the 2% threshold, which needs measurement. - -The cut-short probe advance on ProbeRTT entry relies on the removed -PROBE_STARTING and PROBE_FEEDBACK phases; express it with -`check_probe_loss || is_bw_probe_stopping`. Test the 10 s schedule, the -save order, a base-RTT rise while application-limited, and a spurious loss -during a skip. diff --git a/rs/moq-congestion/src/bbr3/max_filter.rs b/rs/moq-congestion/src/bbr3/max_filter.rs index 7bb5a4b2f4a..eec2699d014 100644 --- a/rs/moq-congestion/src/bbr3/max_filter.rs +++ b/rs/moq-congestion/src/bbr3/max_filter.rs @@ -98,8 +98,8 @@ impl Default for MaxFilter { #[derive(Debug, Copy, Clone, Default)] struct MaxSample { - /// `round` count, not a timestamp as per - /// can also be a count of cycle as per + /// `round` count, not a timestamp as per + /// can also be a count of cycle as per round: u64, value: Option, } diff --git a/rs/moq-congestion/src/bbr3/mod.rs b/rs/moq-congestion/src/bbr3/mod.rs index e6c965b22b5..bec8cbed8b2 100644 --- a/rs/moq-congestion/src/bbr3/mod.rs +++ b/rs/moq-congestion/src/bbr3/mod.rs @@ -18,10 +18,10 @@ use crate::{ }; use crate::{Duration, Instant}; -/// equivalent to BBR.MaxBwFilterLen +/// equivalent to BBR.MaxBwFilterLen const MAX_BW_FILTER_LEN: usize = 2; -/// equivalent to BBR.ExtraAckedFilterLen +/// equivalent to BBR.ExtraAckedFilterLen const EXTRA_ACKED_FILTER_LEN: usize = 10; /// the minimum for the maximum datagram size @@ -32,22 +32,22 @@ const MAX_DATAGRAM_SIZE: u64 = 65527; /// 64 KBytes in bytes /// one of the default high values for `set_send_quantum` -/// +/// const HIGH_PACE_MAX_QUANTUM: u64 = 64 * 1024; /// equivalent to BBR.StartupPacingGain: A constant specifying the minimum gain value for /// calculating the pacing rate that will allow the sending rate to double each round (4 * ln(2) ~= -/// 2.77) BBRStartupPacingGain; used in Startup mode for BBR.pacing_gain. -/// +/// 2.77) BBRStartupPacingGain; used in Startup mode for BBR.pacing_gain. +/// const STARTUP_PACING_GAIN: f64 = 2.773; -/// default pacing gain is 1, when cruising, probing for RTT or refilling +/// default pacing gain is 1, when cruising, probing for RTT or refilling const DEFAULT_PACING_GAIN: f64 = 1.0; -/// pacing gain when probing bandwidth down +/// pacing gain when probing bandwidth down const PROBE_BW_DOWN_PACING_GAIN: f64 = 0.9; -/// pacing gain when probing bandwidth up +/// pacing gain when probing bandwidth up const PROBE_BW_UP_PACING_GAIN: f64 = 1.25; /// equivalent to BBR.PacingMarginPercent: The static discount factor of 1% used to scale BBR.bw to @@ -63,24 +63,20 @@ const DEFAULT_CWND_GAIN: f64 = 2.0; /// mode, to attempt to drain the estimated queue at the bottleneck link in one round-trip or less. /// As noted in BBRDrainPacingGain, any value at or below 1 / BBRStartupCwndGain = 1 / 2 = 0.5 will /// theoretically achieve this. BBR uses the value 0.5, which has been shown to offer good -/// performance when compared with other alternatives. +/// performance when compared with other alternatives. /// const DRAIN_PACING_GAIN: f64 = 1.0 / DEFAULT_CWND_GAIN; -/// cwnd gain used when probing up +/// cwnd gain used when probing up const PROBE_BW_UP_CWND_GAIN: f64 = 2.25; -/// cwnd gain used when probing RTT +/// cwnd gain used when probing RTT const PROBE_RTT_CWND_GAIN: f64 = 0.5; /// equivalent to BBR.ProbeRTTDuration: A constant specifying the minimum duration for which -/// ProbeRTT state holds C.inflight to BBR.MinPipeCwnd or fewer packets: 200 ms. +/// ProbeRTT state holds C.inflight to at most ProbeRTTCwnd(): 200 ms. const PROBE_RTT_DURATION_MS: u64 = 200; -/// equivalent to BBR.ProbeRTTInterval: A constant specifying the minimum time interval between -/// ProbeRTT states: 5 secs. -const PROBE_RTT_INTERVAL_SEC: u64 = 5; - /// equivalent to BBR.LossThresh: A constant specifying the maximum tolerated per-round-trip packet /// loss rate when probing for bandwidth (the default is 2%). const LOSS_THRESH: f64 = 0.02; @@ -102,36 +98,36 @@ const HEADROOM: f64 = 0.15; /// equivalent to BBR.MinRTTFilterLen: A constant specifying the length of the BBR.min_rtt min /// filter window, BBR.MinRTTFilterLen is 10 secs. -const MIN_RTT_FILTER_LEN: u64 = 10; +const MIN_RTT_FILTER_LEN: Duration = Duration::from_secs(10); /// multiplier used to check growth when validating if the full bandwidth has been reached -/// +/// const FULL_BW_GROWTH: f64 = 1.25; -/// maximum number of rounds needed before we consider that the pipe is full +/// maximum number of rounds needed before we consider that the pipe is full const MAX_FULL_BW_COUNT: u64 = 3; /// equivalent to BBRStartupFullLossCnt: the minimum number of discontiguous loss /// events observed within a single round trip before the STARTUP high-loss /// estimator is allowed to exit STARTUP. -/// +/// const STARTUP_FULL_LOSS_CNT: u64 = 6; /// when setting `bw_probe_up_rounds` when raising our inflight long term slope we don't go above -/// this +/// this const MAX_LONG_TERM_PROBE_UP_ROUNDS: u32 = 30; /// equivalent to T_reno_bound: the two candidate values for the round-trip bound used when /// deciding to coexist with Reno / CUBIC. The spec picks randomly between them /// (`T_reno_bound = pick_randomly_either({62, 63})`) for better mixing and fairness -/// convergence +/// convergence const RENO_ROUNDS_BOUNDS: [u64; 2] = [62, 63]; -/// minimum amount of time to wait before probing again +/// minimum amount of time to wait before probing again const MIN_PROBE_WAIT_MS: u64 = 2000; /// when waiting before probing again we add up to one second of added wait time -/// +/// const MAX_ADDED_PROBE_WAIT_MS: u64 = 1000; /// How often an application-limited sample advances the max-bw window, which no probe cycle @@ -141,73 +137,57 @@ const APP_LIMITED_CYCLE: Duration = Duration::from_millis(MIN_PROBE_WAIT_MS + MAX_ADDED_PROBE_WAIT_MS); /// Substates when probing bandwidth -/// +/// #[derive(Debug, Clone, Copy, Eq, PartialEq)] enum ProbeBwSubstate { /// Deceleration: sends slower than delivery rate to reduce queue - /// equivalent to ProbeBW_DOWN + /// equivalent to ProbeBW_DOWN Down, /// Cruising: sends at delivery rate to maintain high utilization - /// equivalent to ProbeBW_CRUISE + /// equivalent to ProbeBW_CRUISE Cruise, /// Refill: sends at BBR.bw for one RTT to fill pipe before probing up - /// equivalent to ProbeBW_REFILL + /// equivalent to ProbeBW_REFILL Refill, /// Acceleration: sends faster than delivery rate to probe for more bandwidth - /// equivalent to ProbeBW_UP + /// equivalent to ProbeBW_UP Up, } /// State Machine description from BBR3 -/// +/// #[derive(Debug, Clone, Copy, Eq, PartialEq)] enum BbrState { /// Initial state: rapidly probes for bandwidth using high pacing_gain - /// equivalent to Startup + /// equivalent to Startup Startup, /// Drains queue created during Startup by using low pacing_gain (< 1.0) - /// equivalent to Drain + /// equivalent to Drain Drain, /// Steady-state phase that cycles through bandwidth probing tactics - /// equivalent to ProbeBW states + /// equivalent to ProbeBW states ProbeBw(ProbeBwSubstate), /// Temporarily reduces inflight to measure true min_rtt - /// equivalent to ProbeRTT + /// equivalent to ProbeRTT ProbeRtt, } -/// Ack phases used during ProbeBW states -/// equivalent to BBR.ack_phase states -#[derive(Debug, Clone, Copy, Eq, PartialEq)] -enum AckPhase { - /// equivalent to ACKS_INIT - Init, - /// equivalent to ACKS_PROBE_STARTING - ProbeStarting, - /// equivalent to ACKS_PROBE_STOPPING - ProbeStopping, - /// equivalent to ACKS_REFILLING - Refilling, - /// equivalent to ACKS_PROBE_FEEDBACK - ProbeFeedback, -} - /// Experimental! Use at your own risk. /// /// Aims for reduced buffer bloat and improved performance over high bandwidth-delay product -/// networks. Based on +/// networks. Based on /// equivalent to a combination of BBR and C states -/// -/// +/// +/// #[derive(Debug, Clone)] pub(crate) struct Bbr3 { - /// equivalent to C.SMSS The Sender Maximum Send Size in bytes. + /// equivalent to C.SMSS The Sender Maximum Send Size in bytes. /// smss: u64, /// equivalent to C.InitialCwnd: The initial congestion window set by the transport protocol @@ -215,7 +195,7 @@ pub(crate) struct Bbr3 { initial_cwnd: u64, /// equivalent to the C rate-sampling fields: C.delivered, C.delivered_time, /// C.first_send_time, C.app_limited, and C.lost. - /// + /// rate: Sampler, /// equivalent to C.inflight: The connection's best estimate of the number of bytes outstanding /// in the network. This includes the number of bytes that have been sent and have not been @@ -250,23 +230,23 @@ pub(crate) struct Bbr3 { /// equivalent to BBR.pacing_gain: The dynamic gain factor used to scale BBR.bw to produce /// C.pacing_rate. pacing_gain: f64, - /// default pacing gain is 1, when cruising, probing for RTT or refilling + /// default pacing gain is 1, when cruising, probing for RTT or refilling default_pacing_gain: f64, - /// pacing gain when probing bandwidth down + /// pacing gain when probing bandwidth down probe_bw_down_pacing_gain: f64, - /// pacing gain when probing bandwidth up + /// pacing gain when probing bandwidth up probe_bw_up_pacing_gain: f64, /// equivalent to BBR.StartupPacingGain: A constant specifying the minimum gain value for /// calculating the pacing rate that will allow the sending rate to double each round (4 * - /// ln(2) ~= 2.77) BBRStartupPacingGain; used in Startup mode for BBR.pacing_gain. - /// + /// ln(2) ~= 2.77) BBRStartupPacingGain; used in Startup mode for BBR.pacing_gain. + /// startup_pacing_gain: f64, /// equivalent to BBR.DrainPacingGain: A constant specifying the pacing gain value used in /// Drain mode, to attempt to drain the estimated queue at the bottleneck link in one /// round-trip or less. As noted in BBRDrainPacingGain, any value at or below 1 / /// BBRStartupCwndGain = 1 / 2 = 0.5 will theoretically achieve this. BBR uses the value - /// 0.5, which has been shown to offer good performance when compared with other alternatives. - /// + /// 0.5, which has been shown to offer good performance when compared with other alternatives. + /// drain_pacing_gain: f64, /// equivalent to BBR.PacingMarginPercent: The static discount factor of 1% used to scale /// BBR.bw to produce C.pacing_rate. @@ -283,16 +263,16 @@ pub(crate) struct Bbr3 { /// here these numbers will not be security critical as they're only used to decide when to /// probe the connection next. probe_rng: Pcg32, - /// cwnd gain used when probing up + /// cwnd gain used when probing up probe_bw_up_cwnd_gain: f64, - /// cwnd gain used when probing RTT + /// cwnd gain used when probing RTT probe_rtt_cwnd_gain: f64, - /// equivalent to BBR.state: The current state of a BBR flow in the BBR state machine. - /// + /// equivalent to BBR.state: The current state of a BBR flow in the BBR state machine. + /// state: BbrState, /// equivalent to BBR.undo_state: the probing state a loss in the current recovery episode /// exited, to return to if the episode is declared spurious. - /// + /// undo_state: Option, /// equivalent to BBR.round_count: Count of packet-timed round trips elapsed so far. round_count: u64, @@ -309,7 +289,7 @@ pub(crate) struct Bbr3 { /// with endpoints that follow an "ACK every other packet" delayed-ACK policy: 4 * C.SMSS. min_pipe_cwnd: u64, /// equivalent to BBR.max_bw: The windowed maximum recent bandwidth sample, obtained using the - /// BBR delivery rate sampling algorithm in , + /// BBR delivery rate sampling algorithm in , /// measured during the current or previous bandwidth probing cycle (or during Startup, if the /// flow is still in that state). (Part of the long-term model.) max_bw: f64, @@ -401,7 +381,7 @@ pub(crate) struct Bbr3 { /// `has_seen_rtt`. BBRInitPacingRate uses C.srtt when there is one and 1ms otherwise; the /// initial rate here always takes 1ms, and Startup only raises it, so an application-limited /// flow that never leaves Startup would keep it for its whole life. - /// + /// has_seen_rtt: bool, /// equivalent to BBR.full_bw_now: A boolean that records whether BBR estimates that it has /// fully utilized its available bandwidth since it most recetly started looking. @@ -418,33 +398,36 @@ pub(crate) struct Bbr3 { /// equivalent to BBR.min_rtt_stamp: The wall clock time at which the current BBR.min_rtt /// sample was obtained. min_rtt_stamp: Option, + /// equivalent to BBR.min_rtt_expired: A boolean recording whether the BBR.min_rtt estimate + /// has expired and is due for a refresh. + min_rtt_expired: bool, + /// equivalent to BBR.MinRTTFilterLen: A constant specifying the length of the BBR.min_rtt min + /// filter window, BBR.MinRTTFilterLen is 10 secs. + min_rtt_filter_len: Duration, + /// The lowest RTT sample since BBR.min_rtt_stamp, after the one that set BBR.min_rtt, which a + /// skipped ProbeRTT adopts as BBR.min_rtt. + later_min_rtt: Duration, /// equivalent to BBR.ProbeRTTDuration: A constant specifying the minimum duration for which - /// ProbeRTT state holds C.inflight to BBR.MinPipeCwnd or fewer packets: 200 ms. + /// ProbeRTT state holds C.inflight to at most ProbeRTTCwnd(): 200 ms. probe_rtt_duration: Duration, - /// equivalent to BBR.ProbeRTTInterval: A constant specifying the minimum time interval between - /// ProbeRTT states: 5 secs. - probe_rtt_interval: Duration, - /// equivalent to BBR.probe_rtt_min_delay: The minimum RTT sample recorded in the last - /// ProbeRTTInterval. - probe_rtt_min_delay: Duration, - /// equivalent to BBR.probe_rtt_min_stamp: The wall clock time at which the current - /// BBR.probe_rtt_min_delay sample was obtained. - probe_rtt_min_stamp: Option, - /// equivalent to BBR.probe_rtt_expired: A boolean recording whether the - /// BBR.probe_rtt_min_delay has expired and is due for a refresh with an application idle - /// period or a transition into ProbeRTT state. - probe_rtt_expired: bool, - /// Whether the transport reported the flow application-limited since BBR.probe_rtt_min_stamp - /// last moved, which lets the due ProbeRTT be skipped. A flow that never ran out of data keeps + /// equivalent to BBR.probe_rtt_cwnd: The target congestion window cap for ProbeRTT state + /// (prior to applying the BBR.MinPipeCwnd floor), computed as 0.5 * estimated_BDP based on + /// the BBR.min_rtt sample when entering ProbeRTT, before it has expired. + probe_rtt_cwnd: u64, + /// Whether the transport reported the flow application-limited since BBR.min_rtt_stamp last + /// moved, which lets the due ProbeRTT be skipped. A flow that never ran out of data keeps /// entering ProbeRTT, where competing BBR flows converge. probe_rtt_skip_app_limited: bool, - /// Whether loss or CE signalled congestion since BBR.probe_rtt_min_stamp last moved, which - /// denies a skip. The flow then shares a full queue whose delay only ProbeRTT re-measures: - /// beside a loss-based flow, skipping would hold BBR.min_rtt below the queue that flow keeps - /// and yield to it. Persistent loss thus never postpones ProbeRTT. + /// Whether loss or CE signalled congestion since BBR.min_rtt_stamp last moved, which denies + /// a skip. The flow then shares a full queue whose delay only ProbeRTT re-measures: beside a + /// loss-based flow, skipping would hold BBR.min_rtt below the queue that flow keeps and yield + /// to it. Persistent loss thus never postpones ProbeRTT. probe_rtt_skip_congested: bool, + /// `probe_rtt_skip_congested` when the current recovery episode began, restored if the + /// episode is declared spurious: a loss that never happened was not congestion. + undo_probe_rtt_skip_congested: bool, /// equivalent to RS: Per-ACK Rate Sample State, from the last ACK that delivered a packet - /// + /// rs: Option, /// The last ACK's own rate sample, if it delivered a packet. A CE event is reported after /// its ACK ends, when `rs` may still hold an earlier ACK's sample. @@ -462,18 +445,22 @@ pub(crate) struct Bbr3 { /// state bw_probe_up_rounds: u32, /// equivalent to BBR.bw_probe_up_acked: bytes acknowledged since `inflight_longterm` last grew - /// + /// bw_probe_up_acked: u64, /// equivalent to BBR.probe_up_acked_per_inc: bytes to acknowledge per SMSS of /// `inflight_longterm` growth during probe up state - /// + /// probe_up_acked_per_inc: u64, /// equivalent to BBR.cycle_stamp: timestamp when we start probing down state cycle_stamp: Option, - /// equivalent to BBR.ack_phase: ACK phase during probing states - ack_phase: AckPhase, - /// equivalent to BBR.is_bw_probe_sample - bw_probe_samples: bool, + /// equivalent to BBR.is_bw_probe_stopping: A boolean tracking whether the flow has stopped + /// bandwidth probing but is still receiving ACK feedback from it. + /// + is_bw_probe_stopping: bool, + /// equivalent to BBR.check_probe_loss: A boolean tracking whether BBR checks packet losses + /// as feedback from a bandwidth-probing phase. + /// + check_probe_loss: bool, /// Whether the previous probe found excessive inflight, and whether this probe stopped at /// that bound to wait for its feedback before probing higher. prev_probe_too_high: bool, @@ -488,9 +475,10 @@ pub(crate) struct Bbr3 { /// round, so the short-term model responds to them as it does to loss ce_in_round: bool, /// count of discontiguous lost sequence ranges observed in the current round trip, for the - /// STARTUP high-loss exit's BBRStartupFullLossCnt criterion. The draft states the criterion - /// but names no variable for the count. Reset at each loss-round boundary. - /// + /// STARTUP high-loss exit's BBRStartupFullLossCnt criterion, as draft-06 read it. Draft-07's + /// BBR.loss_events_in_round counts Fast Recovery loss events instead. Reset at each + /// loss-round boundary. + /// loss_events_in_round: u64, /// The time when loss was first detected, causing the connection to enter fast recovery. A /// congestion event for a packet sent after this time starts a new recovery episode, while @@ -499,11 +487,11 @@ pub(crate) struct Bbr3 { recovery_start_time: Option, /// `round_count` when `recovery_start_time` was last set, used for the "in fast recovery for /// at least one full packet-timed round trip" criterion of the STARTUP high-loss exit - /// + /// recovery_start_round: u64, /// Whether the connection is currently in fast recovery, the first criterion of the STARTUP /// high-loss exit. Cleared once a packet sent after `recovery_start_time` is acknowledged. - /// + /// in_recovery: bool, /// Whether BBR has responded to CE marks in the current recovery episode. It limits that /// response to once per episode, and a marked episode's congestion is real, so its losses @@ -511,7 +499,7 @@ pub(crate) struct Bbr3 { ce_in_recovery: bool, /// equivalent to T_reno_bound: round-trip bound for the Reno-coexistence probe timer, /// re-picked from [`RENO_ROUNDS_BOUNDS`] each time the probe wait is randomized - /// + /// reno_rounds_bound: u64, /// equivalent to BBR.probe_rtt_done_stamp: timestamp when probe RTT state is finished probe_rtt_done_stamp: Option, @@ -527,11 +515,11 @@ pub(crate) struct Bbr3 { drain_start_round: u64, /// Number of ack-eliciting packets the peer may receive before sending an immediate ACK, /// as requested via the QUIC ACK frequency extension. Used when computing `offload_budget` - /// per . + /// per . ack_eliciting_threshold: u64, /// `max_ack_delay` we requested the peer to use via the QUIC ACK frequency extension. /// Used when computing `offload_budget` per - /// . + /// . max_ack_delay: Duration, /// Reads bottleneck queue growth from the peer's receive timestamps, when /// [`Config::delay_bound`] is set. @@ -544,7 +532,7 @@ pub(crate) struct Bbr3 { } impl Bbr3 { - /// equivalent to BBROnInit + /// equivalent to BBROnInit fn new(config: Arc, init: Init) -> Self { let probe_rng = Pcg32::seed_from_u64(init.seed); let smss = Ord::min( @@ -572,7 +560,7 @@ impl Bbr3 { .probe_bw_up_cwnd_gain .unwrap_or(PROBE_BW_UP_CWND_GAIN); let probe_rtt_cwnd_gain = config.probe_rtt_cwnd_gain.unwrap_or(PROBE_RTT_CWND_GAIN); - // the calculation for initial pacing rate described here + // the calculation for initial pacing rate described here let nominal_bandwidth = initial_cwnd as f64 / 0.001; let pacing_rate = startup_pacing_gain * nominal_bandwidth; Self { @@ -606,7 +594,7 @@ impl Bbr3 { round_start: true, next_round_delivered: 0, idle_restart: false, - min_pipe_cwnd, /* 4 * C.SMSS as defined in */ + min_pipe_cwnd, /* 4 * C.SMSS as defined in */ max_bw: 0.0, bw_shortterm: f64::INFINITY, undo_bw_shortterm: f64::INFINITY, @@ -633,15 +621,16 @@ impl Bbr3 { full_bw_count: 0, app_limited_rounds: 0, min_rtt_stamp: None, + min_rtt_expired: false, + min_rtt_filter_len: MIN_RTT_FILTER_LEN, + // Infinity, as for `min_rtt`: a min filter zero-initialized is never lowered. + later_min_rtt: Duration::from_secs(u64::MAX), probe_rtt_cwnd_gain, probe_rtt_duration: Duration::from_millis(PROBE_RTT_DURATION_MS), - probe_rtt_interval: Duration::from_secs(PROBE_RTT_INTERVAL_SEC), - // Infinity, as for `min_rtt`: a min filter zero-initialized is never lowered. - probe_rtt_min_delay: Duration::from_secs(u64::MAX), - probe_rtt_min_stamp: None, - probe_rtt_expired: false, + probe_rtt_cwnd: u64::MAX, probe_rtt_skip_app_limited: false, probe_rtt_skip_congested: false, + undo_probe_rtt_skip_congested: false, rs: None, ack_rs: None, rounds_since_bw_probe: 0, @@ -652,8 +641,8 @@ impl Bbr3 { bw_probe_up_acked: 0, probe_up_acked_per_inc: 0, cycle_stamp: None, - ack_phase: AckPhase::Init, - bw_probe_samples: false, + is_bw_probe_stopping: false, + check_probe_loss: false, prev_probe_too_high: false, undo_prev_probe_too_high: false, prev_probe_precautionary: false, @@ -683,7 +672,7 @@ impl Bbr3 { } } - /// equivalent to BBRUpdateModelAndState + /// equivalent to BBRUpdateModelAndState /// /// `prior_delivered` is P.delivered of the packet the ACK's sample came from, and /// `app_limited` the transport's report that the application ran out of data. @@ -707,7 +696,7 @@ impl Bbr3 { self.bound_bw_for_model(); } - /// equivalent to BBRUpdateLatestDeliverySignals + /// equivalent to BBRUpdateLatestDeliverySignals fn update_latest_delivery_signals(&mut self) { self.loss_round_start = false; if let Some(rate_sample) = self.rs { @@ -724,7 +713,7 @@ impl Bbr3 { } } - /// equivalent to BBRUpdateCongestionSignals + /// equivalent to BBRUpdateCongestionSignals fn update_congestion_signals(&mut self, prior_delivered: u64, app_limited: bool, now: Instant) { self.update_max_bw(prior_delivered, app_limited, now); if !self.loss_round_start { @@ -735,7 +724,7 @@ impl Bbr3 { self.ce_in_round = false; } - /// equivalent to BBRUpdateMaxBw + /// equivalent to BBRUpdateMaxBw /// /// The draft discards an application-limited sample below BBR.max_bw and advances the window /// only as a probe ends, as Linux BBRv3 and QUICHE BBR2 do. A flow the application holds @@ -768,7 +757,7 @@ impl Bbr3 { } } - /// equivalent to BBRUpdateRound + /// equivalent to BBRUpdateRound fn update_round(&mut self, prior_delivered: u64) { if prior_delivered >= self.next_round_delivered { self.start_round(); @@ -784,7 +773,7 @@ impl Bbr3 { } } - /// equivalent to BBRAdaptLowerBoundsFromCongestion + /// equivalent to BBRAdaptLowerBoundsFromCongestion fn adapt_lower_bounds_from_congestion(&mut self) { match self.state { BbrState::ProbeBw(ProbeBwSubstate::Refill) @@ -799,7 +788,7 @@ impl Bbr3 { } } - /// equivalent to BBRInitLowerBounds + /// equivalent to BBRInitLowerBounds fn init_lower_bounds(&mut self) { if self.bw_shortterm == f64::INFINITY { self.bw_shortterm = self.max_bw; @@ -809,7 +798,7 @@ impl Bbr3 { } } - /// equivalent to BBRLossLowerBounds + /// equivalent to BBRLossLowerBounds fn loss_lower_bounds(&mut self) { // gives max of both f64 self.bw_shortterm = [self.bw_latest, BETA * self.bw_shortterm] @@ -822,7 +811,7 @@ impl Bbr3 { ); } - /// equivalent to BBRUpdateACKAggregation + /// equivalent to BBRUpdateACKAggregation /// /// The delay bound expects delivery at BBR.bw without its own `bw_delay`: pacing below the /// delivery rate to drain a queue delivers faster than that bound while the queue lasts, @@ -860,7 +849,7 @@ impl Bbr3 { } } - /// equivalent to BBRCheckFullBWReached + /// equivalent to BBRCheckFullBWReached fn check_full_bw_reached(&mut self) { if self.full_bw_now || !self.round_start { return; @@ -884,7 +873,7 @@ impl Bbr3 { } } - /// equivalent to BBRCheckStartupDone + /// equivalent to BBRCheckStartupDone fn check_startup_done(&mut self) { self.check_startup_high_loss(); if self.state == BbrState::Startup && self.full_bw_reached { @@ -892,7 +881,7 @@ impl Bbr3 { } } - /// equivalent to BBRCheckStartupHighLoss + /// equivalent to BBRCheckStartupHighLoss fn check_startup_high_loss(&mut self) { if self.full_bw_reached { return; @@ -926,7 +915,7 @@ impl Bbr3 { /// First criterion of BBRCheckStartupHighLoss: "the connection has been in fast recovery /// for at least one full packet-timed round trip" - /// + /// fn in_recovery_for_a_full_round(&self) -> bool { self.in_recovery && self.round_count > self.recovery_start_round } @@ -938,7 +927,7 @@ impl Bbr3 { if self.recovery_start_time.is_some_and(|start| sent <= start) { return; } - // Not also per loss round, as draft-06's NoteLoss does: that contradicts its own prose + // Not also per loss round, as draft-07's NoteLoss does: that contradicts its own prose // and Linux's bbr_ssthresh, and would save a model this episode already cut. self.save_state_upon_loss(); self.recovery_start_time = Some(now); @@ -956,7 +945,7 @@ impl Bbr3 { } } - /// equivalent to BBREnterDrain + /// equivalent to BBREnterDrain fn enter_drain(&mut self) { self.state = BbrState::Drain; self.pacing_gain = self.drain_pacing_gain; @@ -964,7 +953,7 @@ impl Bbr3 { self.drain_start_round = self.round_count; } - /// equivalent to BBRCheckDrainDone + /// equivalent to BBRCheckDrainDone /// /// `Inflight(1.0)` takes BBR.bw, so a loss in Drain that lowers `bw_shortterm` also lowers /// the level Drain must reach. @@ -977,13 +966,13 @@ impl Bbr3 { } } - /// equivalent to BBREnterProbeBW + /// equivalent to BBREnterProbeBW fn enter_probe_bw(&mut self, now: Instant) { self.cwnd_gain = self.default_cwnd_gain; self.start_probe_bw_down(now); } - /// equivalent to BBRUpdateProbeBWCyclePhase + /// equivalent to BBRUpdateProbeBWCyclePhase fn update_probe_bw_cycle_phase(&mut self, newly_acked: u64, now: Instant) { if !self.full_bw_reached { return; @@ -1004,7 +993,7 @@ impl Bbr3 { BbrState::ProbeBw(ProbeBwSubstate::Cruise) if self.maybe_enter_probe_bw_refill(now) => { } BbrState::ProbeBw(ProbeBwSubstate::Refill) if self.round_start => { - self.bw_probe_samples = true; + self.check_probe_loss = true; self.start_probe_bw_up(); } BbrState::ProbeBw(ProbeBwSubstate::Up) if self.maybe_go_down(newly_acked) => { @@ -1032,18 +1021,15 @@ impl Bbr3 { } } - /// equivalent to BBRAdaptLongTermModel + /// equivalent to BBRAdaptLongTermModel /// /// The probe's feedback ends once, on the first round after it stops, so later losses are not /// taken as probe feedback and later rounds do not age the max-bw window again. Returns /// whether clean feedback from a precautionary probe started a new refill. fn adapt_long_term_model(&mut self, newly_acked: u64, now: Instant) -> bool { - if self.ack_phase == AckPhase::ProbeStarting && self.round_start { - self.ack_phase = AckPhase::ProbeFeedback; - } - if self.ack_phase == AckPhase::ProbeStopping && self.round_start { - self.bw_probe_samples = false; - self.ack_phase = AckPhase::Init; + if self.is_bw_probe_stopping && self.round_start { + self.check_probe_loss = false; + self.is_bw_probe_stopping = false; if let BbrState::ProbeBw(_) = self.state && let Some(rate_sample) = self.rs && !rate_sample.is_app_limited @@ -1076,7 +1062,7 @@ impl Bbr3 { false } - /// equivalent to BBRAdvanceMaxBwFilter + /// equivalent to BBRAdvanceMaxBwFilter /// /// The oldest cycle's samples leave the window. A cycle without samples is not a cycle, so /// it keeps the window, as Linux BBRv3's `bbr_advance_max_bw_filter` does; otherwise two @@ -1091,7 +1077,7 @@ impl Bbr3 { self.max_bw = self.max_bw_filter.iter().copied().fold(0.0, f64::max); } - /// equivalent to BBRIsTimeToProbeBW + /// equivalent to BBRIsTimeToProbeBW fn maybe_enter_probe_bw_refill(&mut self, now: Instant) -> bool { if self.has_elapsed_in_phase(self.bw_probe_wait, now) || self.is_reno_coexistence_probe_time() @@ -1103,7 +1089,7 @@ impl Bbr3 { false } - /// equivalent to BBRHasElapsedInPhase + /// equivalent to BBRHasElapsedInPhase fn has_elapsed_in_phase(&mut self, interval: Duration, now: Instant) -> bool { if let Some(cycle_stamp) = self.cycle_stamp { now > cycle_stamp.checked_add(interval).unwrap_or(cycle_stamp) @@ -1112,13 +1098,13 @@ impl Bbr3 { } } - /// equivalent to BBRIsRenoCoexistenceProbeTime + /// equivalent to BBRIsRenoCoexistenceProbeTime /// /// `reno_bdp = min(BBR.bdp, C.cwnd)` is a packet count in the spec, which quotes the BDPs it /// bounds against in packets ("25Mbps * 30 ms / (1514 bytes) ~= 62 packets"), so convert from /// bytes before comparing against a round count. Without a BDP estimate there is no /// Reno-equivalent round count to respect, and probing is left to `bw_probe_wait`. - /// + /// fn is_reno_coexistence_probe_time(&self) -> bool { let reno_rounds = self.target_inflight() / self.smss; if reno_rounds == 0 { @@ -1128,20 +1114,20 @@ impl Bbr3 { self.rounds_since_bw_probe >= rounds } - /// equivalent to BBRStartProbeBW_REFILL + /// equivalent to BBRStartProbeBW_REFILL fn start_probe_bw_refill(&mut self) { self.reset_short_term_model(); self.bw_probe_up_rounds = 0; self.bw_probe_up_acked = 0; self.prev_probe_precautionary = false; - self.ack_phase = AckPhase::Refilling; + self.is_bw_probe_stopping = false; self.start_round(); self.cwnd_gain = self.default_cwnd_gain; self.pacing_gain = self.default_pacing_gain; self.state = BbrState::ProbeBw(ProbeBwSubstate::Refill); } - /// equivalent to BBRIsTimeToCruise + /// equivalent to BBRIsTimeToCruise /// /// The one `Inflight` the draft computes from BBR.max_bw rather than BBR.bw. fn maybe_update_budget_and_time_to_cruise(&mut self) -> bool { @@ -1154,7 +1140,7 @@ impl Bbr3 { true } - /// equivalent to BBRInflight + /// equivalent to BBRInflight /// /// Takes the bandwidth explicitly, since the draft's callers pass BBR.bw or BBR.max_bw. fn get_inflight(&mut self, bw: f64, gain: f64) -> u64 { @@ -1162,7 +1148,7 @@ impl Bbr3 { self.quantization_budget(inflight_cap) } - /// equivalent to BBRIsTimeToGoDown + /// equivalent to BBRIsTimeToGoDown fn maybe_go_down(&mut self, newly_acked: u64) -> bool { let pre_ack_inflight = self.inflight.saturating_add(newly_acked); if self.prev_probe_too_high && pre_ack_inflight >= self.inflight_longterm { @@ -1180,7 +1166,7 @@ impl Bbr3 { false } - /// equivalent to BBRProbeInflightLongtermUpward + /// equivalent to BBRProbeInflightLongtermUpward /// /// Growing in whole packets lets the cwnd catch up between increments, so PROBE_UP sees the /// cwnd reach `inflight_longterm` and keeps probing while that bound is what limits it. Once @@ -1204,92 +1190,75 @@ impl Bbr3 { } } - /// equivalent to BBRUpdateMinRTT + /// equivalent to BBRUpdateMinRTT /// - /// The draft stamps `probe_rtt_min_stamp` at connection init, so the first ProbeRTT falls due - /// one `probe_rtt_interval` later. Before the first ack there is no RTT sample to stamp, so an - /// unset stamp counts as not yet expired and the first sample starts the interval. Counting it + /// The draft stamps BBR.min_rtt_stamp at connection init, so the first ProbeRTT falls due one + /// BBR.MinRTTFilterLen later. Before the first ack there is no RTT sample to stamp, so an + /// unset stamp counts as not yet expired and the first sample starts the filter. Counting it /// as expired instead would dip every connection into ProbeRTT on its very first ack, and so /// into `min_pipe_cwnd`, since `bw` is still 0. /// - /// An application-limited flow without congestion during the interval skips the due ProbeRTT, + /// An application-limited flow without congestion since the stamp skips the due ProbeRTT, /// as QUICHE BBRv1's kBBR8 does, which spares media its periodic window cut. Its near-floor /// kBBR7 also requires an application-limited interval, so kBBR8 covers it. /// - /// A skip moves only the stamps and keeps the values, so a base RTT that rose meanwhile is not - /// followed until congestion or an interval that never ran out of data brings ProbeRTT back. - /// BBR.min_rtt_stamp moves too, or BBR.min_rtt could expire into the high sample that opens - /// the next ProbeRTT. A lower BBR.min_rtt from before a ProbeRTT that measured a higher RTT - /// still expires first, since its filter is two ProbeRTT intervals long. An idle restart keeps - /// the draft's free refresh instead, sampling the drained path directly. + /// A skip adopts the expired window's lowest sample after the one that set BBR.min_rtt, so a + /// base RTT that rose is learned without ProbeRTT: an application-limited flow keeps little + /// queue of its own in its samples. An idle restart keeps the draft's free refresh instead, + /// sampling the drained path directly. fn update_min_rtt(&mut self, now: Instant) { - self.probe_rtt_expired = match self.probe_rtt_min_stamp { - Some(probe_rtt_min_stamp) => { - now > probe_rtt_min_stamp - .checked_add(self.probe_rtt_interval) - .unwrap_or(probe_rtt_min_stamp) - } - None => false, + self.min_rtt_expired = self + .min_rtt_stamp + .is_some_and(|stamp| now > stamp.checked_add(self.min_rtt_filter_len).unwrap_or(stamp)); + if self.min_rtt_expired { + self.probe_rtt_cwnd = self.bdp_multiple(self.bw, self.probe_rtt_cwnd_gain); + } + let Some(rate_sample) = self.rs else { + return; }; - if self.probe_rtt_expired + if self.min_rtt_expired && !self.idle_restart && self.probe_rtt_skip_app_limited && !self.probe_rtt_skip_congested { - self.probe_rtt_expired = false; - self.min_rtt_stamp = Some(now); - self.refresh_probe_rtt_min_stamp(now); - } - if let Some(rate_sample) = self.rs - && rate_sample.rtt >= Duration::from_secs(0) - && (rate_sample.rtt < self.probe_rtt_min_delay || self.probe_rtt_expired) - { - self.probe_rtt_min_delay = rate_sample.rtt; - self.refresh_probe_rtt_min_stamp(now); - } - - let min_rtt_expired; - if let Some(min_rtt_stamp) = self.min_rtt_stamp { - min_rtt_expired = now - > min_rtt_stamp - .checked_add(Duration::from_secs(MIN_RTT_FILTER_LEN)) - .unwrap_or(min_rtt_stamp); + self.min_rtt_expired = false; + self.min_rtt = Ord::min(self.later_min_rtt, rate_sample.rtt); + self.set_min_rtt_stamp(now); + } else if rate_sample.rtt < self.min_rtt || self.min_rtt_expired { + self.min_rtt = rate_sample.rtt; + self.set_min_rtt_stamp(now); } else { - min_rtt_expired = true; - } - if self.probe_rtt_min_delay < self.min_rtt || min_rtt_expired { - self.min_rtt = self.probe_rtt_min_delay; - self.min_rtt_stamp = self.probe_rtt_min_stamp; + self.later_min_rtt = Ord::min(self.later_min_rtt, rate_sample.rtt); } } - /// Restarts the ProbeRTT interval, which then gathers its own evidence for a skip. - fn refresh_probe_rtt_min_stamp(&mut self, now: Instant) { - self.probe_rtt_min_stamp = Some(now); + /// Restarts the BBR.min_rtt filter window, which then gathers its own samples and its own + /// evidence for a skip. + fn set_min_rtt_stamp(&mut self, now: Instant) { + self.min_rtt_stamp = Some(now); + self.later_min_rtt = Duration::from_secs(u64::MAX); self.probe_rtt_skip_app_limited = false; self.probe_rtt_skip_congested = false; + self.undo_probe_rtt_skip_congested = false; } - /// equivalent to BBRCheckProbeRTT + /// equivalent to BBRCheckProbeRTT fn check_probe_rtt(&mut self, now: Instant) { - if self.state != BbrState::ProbeRtt && self.probe_rtt_expired && !self.idle_restart { + if self.state != BbrState::ProbeRtt && self.min_rtt_expired && !self.idle_restart { // A probe cut short here still owes its max-bw window advance, which the draft never // pays: the round ending its feedback finishes inside ProbeRTT, and the round after // exit carries ProbeRTT's app-limited samples. Without this, a flow whose every probe // ProbeRTT interrupts keeps a stale maximum forever. if let BbrState::ProbeBw(_) = self.state - && matches!( - self.ack_phase, - AckPhase::ProbeStarting | AckPhase::ProbeFeedback | AckPhase::ProbeStopping - ) + && (self.check_probe_loss || self.is_bw_probe_stopping) && self.rs.is_some_and(|rs| !rs.is_app_limited) { self.advance_max_bw_filter(now); } - self.enter_probe_rtt(); self.save_cwnd(); + self.enter_probe_rtt(); self.probe_rtt_done_stamp = None; - self.ack_phase = AckPhase::ProbeStopping; + self.is_bw_probe_stopping = true; self.start_round(); } if self.state == BbrState::ProbeRtt { @@ -1302,7 +1271,7 @@ impl Bbr3 { } } - /// equivalent to BBRHandleProbeRTT + /// equivalent to BBRHandleProbeRTT fn handle_probe_rtt(&mut self, now: Instant) { // Packets sent at the reduced ProbeRTT window do not measure the path's capacity, whether // or not inflight fills that window, so this skips the starvation check's cwnd guard. @@ -1322,7 +1291,7 @@ impl Bbr3 { } } - /// equivalent to BBREnterProbeRTT + /// equivalent to BBREnterProbeRTT fn enter_probe_rtt(&mut self) { self.state = BbrState::ProbeRtt; self.prev_probe_precautionary = false; @@ -1330,7 +1299,7 @@ impl Bbr3 { self.cwnd_gain = self.probe_rtt_cwnd_gain; } - /// equivalent to BBRSaveCwnd + /// equivalent to BBRSaveCwnd fn save_cwnd(&mut self) { if !self.in_recovery && self.state != BbrState::ProbeRtt { self.prior_cwnd = self.cwnd; @@ -1339,7 +1308,7 @@ impl Bbr3 { } } - /// equivalent to BBRAdvanceLatestDeliverySignals + /// equivalent to BBRAdvanceLatestDeliverySignals fn advance_latest_delivery_signals(&mut self) { if self.loss_round_start && let Some(rate_sample) = self.rs @@ -1349,7 +1318,7 @@ impl Bbr3 { } } - /// equivalent to BBRBoundBWForModel + /// equivalent to BBRBoundBWForModel /// /// The delay bound's `bw_delay` bounds it too, infinite unless that is on. fn bound_bw_for_model(&mut self) { @@ -1360,9 +1329,8 @@ impl Bbr3 { .fold(f64::NAN, f64::min); } - /// equivalent to BBRStartProbeBW_UP + /// equivalent to BBRStartProbeBW_UP fn start_probe_bw_up(&mut self) { - self.ack_phase = AckPhase::ProbeStarting; self.start_round(); self.reset_full_bw(); if let Some(rate_sample) = self.rs { @@ -1374,14 +1342,14 @@ impl Bbr3 { self.raise_inflight_long_term_slope(); } - /// equivalent to BBRResetFullBW + /// equivalent to BBRResetFullBW fn reset_full_bw(&mut self) { self.full_bw = 0.0; self.full_bw_count = 0; self.full_bw_now = false; } - /// equivalent to BBRRaiseInflightLongtermSlope + /// equivalent to BBRRaiseInflightLongtermSlope fn raise_inflight_long_term_slope(&mut self) { let growth_this_round = 1u64 .checked_shl(self.bw_probe_up_rounds) @@ -1391,7 +1359,7 @@ impl Bbr3 { self.probe_up_acked_per_inc = Ord::max(self.cwnd / growth_this_round, self.smss); } - /// equivalent to BBRHandleRestartFromIdle + /// equivalent to BBRHandleRestartFromIdle fn handle_restart_from_idle(&mut self, now: Instant) { if self.inflight == 0 && self.rate.is_app_limited() { self.idle_restart = true; @@ -1410,23 +1378,23 @@ impl Bbr3 { } } - /// equivalent to BBRCheckProbeRTTDone + /// equivalent to BBRCheckProbeRTTDone fn check_probe_rtt_done(&mut self, now: Instant) { if let Some(probe_rtt_done_stamp) = self.probe_rtt_done_stamp && now > probe_rtt_done_stamp { - self.refresh_probe_rtt_min_stamp(now); + self.set_min_rtt_stamp(now); self.restore_cwnd(); self.exit_probe_rtt(now); } } - /// equivalent to BBRRestoreCwnd + /// equivalent to BBRRestoreCwnd fn restore_cwnd(&mut self) { self.cwnd = Ord::max(self.cwnd, self.prior_cwnd); } - /// equivalent to BBRExitProbeRTT + /// equivalent to BBRExitProbeRTT fn exit_probe_rtt(&mut self, now: Instant) { self.reset_short_term_model(); if self.full_bw_reached { @@ -1437,28 +1405,28 @@ impl Bbr3 { } } - /// equivalent to BBRStartProbeBW_CRUISE + /// equivalent to BBRStartProbeBW_CRUISE fn start_probe_bw_cruise(&mut self) { self.state = BbrState::ProbeBw(ProbeBwSubstate::Cruise); self.pacing_gain = self.default_pacing_gain; self.cwnd_gain = self.default_cwnd_gain; } - /// equivalent to BBREnterStartup + /// equivalent to BBREnterStartup fn enter_startup(&mut self) { self.state = BbrState::Startup; self.pacing_gain = self.startup_pacing_gain; self.cwnd_gain = self.default_cwnd_gain; } - /// equivalent to BBRUpdateControlParameters + /// equivalent to BBRUpdateControlParameters fn update_control_parameters(&mut self, newly_acked: u64) { self.set_pacing_rate(); self.set_send_quantum(); self.set_cwnd(newly_acked); } - /// equivalent to BBRSetCwnd + /// equivalent to BBRSetCwnd fn set_cwnd(&mut self, newly_acked: u64) { self.update_max_inflight(); if self.full_bw_reached { @@ -1471,7 +1439,7 @@ impl Bbr3 { self.bound_cwnd_for_model(); } - /// equivalent to BBRUpdateMaxInflight + /// equivalent to BBRUpdateMaxInflight /// /// Sized from BBR.bw, so the short-term bandwidth bound caps the window as well as the /// pacing rate. As the last BDP computed on each ACK, it also leaves BBR.bdp at @@ -1482,7 +1450,7 @@ impl Bbr3 { self.max_inflight = self.quantization_budget(inflight_cap); } - /// equivalent to BBRQuantizationBudget + /// equivalent to BBRQuantizationBudget fn quantization_budget(&mut self, inflight_cap: u64) -> u64 { self.update_offload_budget(); let mut inflight_cap = Ord::max(inflight_cap, self.offload_budget); @@ -1494,7 +1462,7 @@ impl Bbr3 { } /// equivalent to BBRUpdateOffloadBudget for QUIC per - /// . + /// . /// /// The delayed-ACK term accounts for the QUIC ACK frequency extension: /// `min(Ack-Eliciting Threshold, Requested Max Ack Delay * BBR.max_bw)`. @@ -1511,21 +1479,20 @@ impl Bbr3 { self.offload_budget = base.saturating_add(delayed_ack_term); } - /// equivalent to BBRBoundCwndForProbeRTT + /// equivalent to BBRBoundCwndForProbeRTT fn bound_cwnd_for_probe_rtt(&mut self) { if self.state == BbrState::ProbeRtt { self.cwnd = Ord::min(self.cwnd, self.probe_rtt_cwnd()); } } - /// equivalent to BBRProbeRTTCwnd + /// equivalent to BBRProbeRTTCwnd fn probe_rtt_cwnd(&mut self) -> u64 { - let mut probe_rtt_cwnd = self.bdp_multiple(self.bw, self.probe_rtt_cwnd_gain); - probe_rtt_cwnd = Ord::max(probe_rtt_cwnd, self.min_pipe_cwnd); - probe_rtt_cwnd + let probe_rtt_cwnd = self.bdp_multiple(self.bw, self.probe_rtt_cwnd_gain); + Ord::min(probe_rtt_cwnd, self.probe_rtt_cwnd).max(self.min_pipe_cwnd) } - /// equivalent to BBRBDPMultiple + /// equivalent to BBRBDPMultiple fn bdp_multiple(&mut self, bw: f64, gain: f64) -> u64 { if self.min_rtt == Duration::from_secs(u64::MAX) { return self.initial_cwnd; @@ -1534,7 +1501,7 @@ impl Bbr3 { (gain * self.bdp as f64) as u64 } - /// equivalent to BBRBoundCwndForModel + /// equivalent to BBRBoundCwndForModel fn bound_cwnd_for_model(&mut self) { let mut cap = u64::MAX; match self.state { @@ -1554,7 +1521,7 @@ impl Bbr3 { self.cwnd = Ord::min(self.cwnd, cap); } - /// equivalent to BBRInflightWithHeadroom + /// equivalent to BBRInflightWithHeadroom fn inflight_with_headroom(&self) -> u64 { if self.inflight_longterm == u64::MAX { return u64::MAX; @@ -1567,12 +1534,12 @@ impl Bbr3 { } } - /// equivalent to BBRSetPacingRate + /// equivalent to BBRSetPacingRate fn set_pacing_rate(&mut self) { self.set_pacing_rate_with_gain(self.pacing_gain); } - /// equivalent to BBRSetPacingRateWithGain + /// equivalent to BBRSetPacingRateWithGain fn set_pacing_rate_with_gain(&mut self, gain: f64) { if !self.has_seen_rtt && self.min_rtt != Duration::from_secs(u64::MAX) { self.init_pacing_rate_from_rtt(); @@ -1584,7 +1551,7 @@ impl Bbr3 { } /// equivalent to BBRInitPacingRate once an RTT is measured, as Linux BBR's - /// `bbr_init_pacing_rate_from_rtt`. + /// `bbr_init_pacing_rate_from_rtt`. /// /// BBR's own first RTT sample stands in for SRTT, which before an ACK holds just the /// configured initial RTT. A zero RTT is floored at 1us, as Linux does. @@ -1594,7 +1561,7 @@ impl Bbr3 { self.pacing_rate = self.startup_pacing_gain * self.initial_cwnd as f64 / rtt.as_secs_f64(); } - /// equivalent to BBRSetSendQuantum + /// equivalent to BBRSetSendQuantum fn set_send_quantum(&mut self) { // C.pacing_rate is in bytes/sec, so multiplying by 1ms is dividing by 1000. let mut quantum = (self.pacing_rate / 1000.0) as u64; @@ -1605,12 +1572,12 @@ impl Bbr3 { self.send_quantum = quantum; } - /// equivalent to BBRHandleLostPacket + /// equivalent to BBRHandleLostPacket fn process_lost_packet(&mut self, lost: &Lost, now: Instant) { self.rate.on_lost(lost.bytes); self.enter_recovery(now, lost.sent); self.note_loss(lost.new_burst); - if !self.bw_probe_samples { + if !self.check_probe_loss { return; } // Loss has no delivery-rate observation. Only its own flight and app-limit labels @@ -1622,12 +1589,12 @@ impl Bbr3 { } } - /// equivalent to BBRNoteLoss + /// equivalent to BBRNoteLoss /// /// `loss_events_in_round` counts discontiguous lost sequence ranges, not lost packets, so a /// run of consecutive lost packets is one event. The transport marks where a run starts, and /// the first loss of a round always opens a new range. - /// + /// fn note_loss(&mut self, new_burst: bool) { self.start_congestion_round(); self.loss_in_round = true; @@ -1636,7 +1603,7 @@ impl Bbr3 { } } - /// Opens the loss round on its first congestion signal, loss or CE, as draft-06's NoteLoss + /// Opens the loss round on its first congestion signal, loss or CE, as draft-07's NoteLoss /// does for loss, and denies a skip of the next ProbeRTT. fn start_congestion_round(&mut self) { if !self.loss_in_round && !self.ce_in_round { @@ -1648,7 +1615,7 @@ impl Bbr3 { /// Responds to newly reported CE marks as classic ECN: congestion that the bottleneck /// signalled instead of dropping packets. /// - /// Draft-06 section 3.7 requires treating CE as congestion without prescribing BBR's + /// Draft-07 section 3.7 requires treating CE as congestion without prescribing BBR's /// response. As RFC 9002 reduces its window once per recovery period, this responds once per /// recovery episode: Startup stops as it does on high loss, a bandwidth probe whose feedback /// is arriving stops as it does when loss shows inflight too high, and every other state @@ -1656,7 +1623,7 @@ impl Bbr3 { /// data, so it adds no /// lost bytes or loss events, and the transport reports only an increased CE count, so old /// marks never repeat the response. - /// + /// fn handle_ce(&mut self, now: Instant, sent: Instant) { self.enter_recovery(now, sent); if std::mem::replace(&mut self.ce_in_recovery, true) { @@ -1676,7 +1643,7 @@ impl Bbr3 { // The marked ACK's sample bounds the probe, since the event's own packet can be an // untracked ACK-only one. The probe's feedback can still be arriving after the ACK // itself ended the probe. - _ if self.bw_probe_samples => { + _ if self.check_probe_loss => { self.handle_inflight_too_high(now, self.ack_rs); } _ => {} @@ -1684,7 +1651,7 @@ impl Bbr3 { self.update_control_parameters(0); } - /// equivalent to BBRSaveStateUponLoss + /// equivalent to BBRSaveStateUponLoss /// /// Runs once per recovery episode, so later losses in it cannot overwrite the pre-episode /// model with one they already reduced. @@ -1696,6 +1663,7 @@ impl Bbr3 { _ => self.cwnd, }; self.undo_state = None; + self.undo_probe_rtt_skip_congested = self.probe_rtt_skip_congested; self.undo_prev_probe_too_high = self.prev_probe_too_high; self.undo_prev_probe_precautionary = self.prev_probe_precautionary; self.undo_bw_shortterm = self.bw_shortterm; @@ -1703,7 +1671,7 @@ impl Bbr3 { self.undo_inflight_longterm = self.inflight_longterm; } - /// equivalent to IsInflightTooHigh + /// equivalent to IsInflightTooHigh fn is_inflight_too_high(&self) -> bool { self.rs.is_some_and(Self::inflight_too_high) } @@ -1712,7 +1680,7 @@ impl Bbr3 { rate_sample.lost as f64 > rate_sample.tx_in_flight as f64 * LOSS_THRESH } - /// equivalent to BBRInflightAtLoss + /// equivalent to BBRInflightAtLoss /// We check at what prefix of packet did losses exceed `loss_thresh` fn inflight_at_loss(rate_sample: Sample, packet_size: u64) -> u64 { let inflight_prev = rate_sample.tx_in_flight.saturating_sub(packet_size) as f64; @@ -1721,11 +1689,11 @@ impl Bbr3 { (inflight_prev + lost_prefix) as u64 } - /// equivalent to BBRHandleInflightTooHigh + /// equivalent to BBRHandleInflightTooHigh /// /// `rs` is the sample that showed it, if any. fn handle_inflight_too_high(&mut self, now: Instant, rs: Option) { - self.bw_probe_samples = false; + self.check_probe_loss = false; self.prev_probe_too_high = true; self.prev_probe_precautionary = false; if let Some(rate_sample) = rs @@ -1743,31 +1711,31 @@ impl Bbr3 { } } - /// equivalent to BBRTargetInflight + /// equivalent to BBRTargetInflight fn target_inflight(&self) -> u64 { Ord::min(self.bdp, self.cwnd) } - /// equivalent to BBRResetShortTermModel + /// equivalent to BBRResetShortTermModel fn reset_short_term_model(&mut self) { self.bw_shortterm = f64::INFINITY; self.inflight_shortterm = u64::MAX; } - /// equivalent to BBRStartProbeBW_DOWN + /// equivalent to BBRStartProbeBW_DOWN fn start_probe_bw_down(&mut self, now: Instant) { self.reset_congestion_signals(); self.probe_up_acked_per_inc = u64::MAX; self.pick_probe_wait(); self.cycle_stamp = Some(now); - self.ack_phase = AckPhase::ProbeStopping; + self.is_bw_probe_stopping = true; self.start_round(); self.pacing_gain = self.probe_bw_down_pacing_gain; self.cwnd_gain = self.default_cwnd_gain; self.state = BbrState::ProbeBw(ProbeBwSubstate::Down); } - /// equivalent to BBRResetCongestionSignals + /// equivalent to BBRResetCongestionSignals fn reset_congestion_signals(&mut self) { self.loss_in_round = false; self.ce_in_round = false; @@ -1775,7 +1743,7 @@ impl Bbr3 { self.inflight_latest = 0; } - /// equivalent to BBRPickProbeWait + /// equivalent to BBRPickProbeWait fn pick_probe_wait(&mut self) { // 0 or 1 self.rounds_since_bw_probe = self.probe_rng.random_bool(0.5) as u64; @@ -1786,7 +1754,7 @@ impl Bbr3 { self.reno_rounds_bound = RENO_ROUNDS_BOUNDS[self.probe_rng.random_bool(0.5) as usize]; } - /// equivalent to BBRStartRound + /// equivalent to BBRStartRound fn start_round(&mut self) { self.next_round_delivered = self.rate.delivered(); } @@ -1889,8 +1857,8 @@ impl Bbr3 { impl Controller for Bbr3 { /// equivalent to BBROnTransmit and OnPacketSent: checks for a restart from idle, then takes /// the packet's delivery snapshot. - /// - /// + /// + /// fn on_sent(&mut self, sent: Sent) -> Packet { // The restart check reads C.inflight from before this packet. self.inflight = sent.in_flight.saturating_sub(sent.bytes.into()); @@ -1901,12 +1869,12 @@ impl Controller for Bbr3 { } /// Feeds C.is_cwnd_limited, which the transport provides. - /// + /// fn on_cwnd_limited(&mut self) { self.cwnd_limited_this_round = true; } - /// equivalent to CheckIfApplicationLimited + /// equivalent to CheckIfApplicationLimited /// /// A full window means the connection is window-limited, not starved, so it marks nothing. fn on_app_limited(&mut self, in_flight: u64) { @@ -1934,7 +1902,7 @@ impl Controller for Bbr3 { /// equivalent to UpdateRateSample, GenerateRateSample, BBRUpdateModelAndState, and /// BBRUpdateControlParameters - /// + /// fn on_ack(&mut self, ack: Ack<'_>) { // equivalent to RS.newly_acked. It is passed to the ACK's model steps rather than kept in // `rs`, so no later `set_cwnd` counts it again. @@ -1977,7 +1945,7 @@ impl Controller for Bbr3 { /// equivalent to the per-loss steps, which call BBRHandleLostPacket. Persistent congestion /// collapses the window to the minimum, here BBR.MinPipeCwnd. - /// + /// /// fn on_loss(&mut self, loss: Loss<'_>) { // C.inflight excludes lost bytes, and the next ACK may come after the next send. @@ -1992,12 +1960,12 @@ impl Controller for Bbr3 { /// The draft specifies no ECN response of its own, but CE marks MUST be treated as /// congestion; `handle_ce` responds to them. - /// + /// fn on_ce(&mut self, ce: Ce) { self.handle_ce(ce.now, ce.sent); } - /// equivalent to BBRHandleSpuriousLossDetection: + /// equivalent to BBRHandleSpuriousLossDetection: /// /// CE marks in the episode confirm its congestion, so nothing is undone. fn on_spurious_loss(&mut self) { @@ -2009,13 +1977,14 @@ impl Controller for Bbr3 { // packets declared lost. ProbeRTT's exit restores the rest. self.bound_cwnd_for_probe_rtt(); self.loss_in_round = false; + self.probe_rtt_skip_congested = self.undo_probe_rtt_skip_congested; self.reset_full_bw(); self.prev_probe_too_high = self.undo_prev_probe_too_high; // A precautionary stop still waiting for its feedback round waits again; once that // round has passed, the spurious loss cost the early refill for good. self.prev_probe_precautionary = self.undo_prev_probe_precautionary && self.state == BbrState::ProbeBw(ProbeBwSubstate::Down) - && self.ack_phase == AckPhase::ProbeStopping; + && self.is_bw_probe_stopping; self.bw_shortterm = [self.bw_shortterm, self.undo_bw_shortterm] .iter() .copied() @@ -2042,8 +2011,8 @@ impl Controller for Bbr3 { } /// Re-derives C.SMSS and BBR.MinPipeCwnd (4 * C.SMSS) from the new MTU. - /// - /// + /// + /// fn on_mtu_update(&mut self, new_mtu: u16) { self.smss = Ord::min( Ord::max(MIN_MAX_DATAGRAM_SIZE, new_mtu) as u64, @@ -2055,7 +2024,7 @@ impl Controller for Bbr3 { } /// Records the ACK frequency parameters BBRUpdateOffloadBudget uses for QUIC. - /// + /// fn on_ack_frequency_update( &mut self, ack_eliciting_threshold: u64, @@ -2069,7 +2038,7 @@ impl Controller for Bbr3 { self.cwnd } - /// Paces at C.pacing_rate. + /// Paces at C.pacing_rate. fn pace(&mut self, now: Instant, bytes: u64) -> Option { let rate = Rate { window: self.cwnd, @@ -2080,7 +2049,7 @@ impl Controller for Bbr3 { .delay(Duration::ZERO, bytes, self.smss as u16, now, rate) } - /// equivalent to C.send_quantum + /// equivalent to C.send_quantum fn burst(&self) -> Option { Some(self.send_quantum) } @@ -2595,7 +2564,7 @@ mod test { } /// A.1: Exiting STARTUP on a bandwidth plateau. - /// equivalent to: + /// equivalent to: /// Drives a flow through the real `on_sent`/`on_ack` /// path against a single-bottleneck simulator: constant bandwidth `BW`, /// constant propagation `RTT`, infinite buffer (no loss). Packets queue and @@ -2612,11 +2581,7 @@ mod test { const MSS: u64 = 1200; /// simulated bottleneck bandwidth: 100 Mbit/s in bytes/sec const BW: f64 = 12_500_000.0; - /// Simulated propagation RTT. Kept large (100ms) so the transient - /// ProbeRTT BBR enters on the first ack (its `probe_rtt_min_stamp` - /// starts unset, initializing `min_rtt`) spans fewer than - /// `MAX_FULL_BW_COUNT` rounds and cannot falsely complete the plateau - /// there; the flow bounces back to STARTUP and ramps cleanly. + /// Simulated propagation RTT (100ms). const RTT_NS: u64 = 100_000_000; // Drive the production default configuration. @@ -2624,9 +2589,7 @@ mod test { assert_eq!(sim.bbr.state, BbrState::Startup); // captured on the STARTUP -> DRAIN edge (DRAIN is only ever entered from - // STARTUP, via check_startup_done). BBR dips through a transient ProbeRTT - // right after the first ack, so we run until DRAIN rather than breaking on - // the first non-STARTUP state. + // STARTUP, via check_startup_done). let mut transition: Option<(u64, bool, bool, f64)> = None; sim.run( 1_000_000, @@ -2662,7 +2625,7 @@ mod test { } /// A.2: Exiting STARTUP on loss when application-limited. - /// equivalent to: + /// equivalent to: /// /// Drives a STARTUP flow whose delivery-rate samples are all app-limited (the /// app keeps only `APP_WINDOW` bytes outstanding, well below cwnd), so @@ -2730,8 +2693,7 @@ mod test { let mut startup_non_app_limited_samples = 0u64; // captured on the STARTUP -> DRAIN edge (DRAIN is only ever entered from - // STARTUP, via check_startup_done). A transient ProbeRTT dip right after - // the first ack bounces back to STARTUP, so we run until DRAIN. + // STARTUP, via check_startup_done). let mut transition: Option<(u64, bool, bool)> = None; for _ in 0..1_000_000 { @@ -2816,8 +2778,7 @@ mod test { // app-limited, so app-limiting (not a race with loss) kept the plateau // path from completing. The only packets sent non-app-limited are // the two warmup packets (pn 0 and 1, before app_limited was first set - // nonzero); the bound tolerates them in case they are acked in STARTUP (in - // practice they land in the transient first-ack ProbeRTT and are not counted). + // nonzero); the bound tolerates them in case they are acked in STARTUP. assert!( startup_app_limited_samples > 0, "no app-limited STARTUP samples observed" @@ -2835,7 +2796,7 @@ mod test { } /// A.3: Exiting DRAIN based on inflight. - /// equivalent to: + /// equivalent to: /// /// Drives a flow STARTUP -> DRAIN on the same infinite-buffer simulator as /// A.1, then keeps running through DRAIN. Entering DRAIN sets `pacing_gain` @@ -2930,7 +2891,7 @@ mod test { } /// A.4: Exiting DRAIN based on time. - /// equivalent to: + /// equivalent to: /// /// Same simulator as A.1/A.3, driven STARTUP -> DRAIN. On the DRAIN edge the /// link is cut, simulating a STARTUP bandwidth over-estimate: DRAIN keeps @@ -3102,7 +3063,7 @@ mod test { /// A.5: Exiting PROBE_UP on a bandwidth plateau. /// equivalent to BBRIsTimeToGoDown: - /// + /// /// /// Same infinite-buffer simulator as A.1/A.3 (constant `BW`, constant `RTT`, /// no loss), driven STARTUP -> DRAIN -> PROBE_BW until PROBE_BW cycles into @@ -3183,12 +3144,12 @@ mod test { 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; + sim.bbr.check_probe_loss = true; sim.lose(100 * MS, 0); assert!( - !sim.bbr.bw_probe_samples, + !sim.bbr.check_probe_loss, "loss stops the bandwidth probe before any ACK" ); assert!(sim.bbr.inflight_longterm < u64::MAX); @@ -3204,7 +3165,7 @@ mod test { sim.send(MS, 1); sim.ack(100 * MS, [0], false); let ack = sim.bbr.rs.unwrap(); - sim.bbr.bw_probe_samples = true; + sim.bbr.check_probe_loss = true; sim.lose(101 * MS, 10); @@ -3223,7 +3184,7 @@ mod test { /// A.6: Exiting PROBE_UP on loss when application-limited. /// equivalent to BBRHandleInflightTooHigh: - /// + /// /// /// NOTE: the loss-driven PROBE_UP exit runs through `handle_inflight_too_high` /// (BBRHandleInflightTooHigh), reached per-lost-packet from @@ -3240,7 +3201,7 @@ mod test { /// well below cwnd) so every fresh sample is app-limited, and 1-in-`LOSS_PERIOD` packets /// are dropped -> a per-round loss rate (4%) above `BBR.LossThresh` (2%). /// - /// In PROBE_UP `bw_probe_samples` is true, so each lost packet is fed through + /// In PROBE_UP `check_probe_loss` is true, so each lost packet is fed through /// `process_lost_packet`; the lost packet's own sample shows the loss exceed /// `LOSS_THRESH * tx_in_flight` and calls `handle_inflight_too_high`. Because /// the deciding sample is app-limited, the `!is_app_limited` guard in @@ -3506,8 +3467,8 @@ mod test { /// small fixed window (`APP_WINDOW`, well below cwnd) from the first packet so /// every sample is app-limited, and no packet is ever dropped. /// - /// Runs long enough (`ROUNDS_TO_OBSERVE`, several `probe_rtt_interval`s) to - /// cover multiple due ProbeRTTs, and asserts that: the flow only ever occupies + /// Runs long enough (`ROUNDS_TO_OBSERVE`, past `BBR.MinRTTFilterLen`) to + /// cover a due ProbeRTT, and asserts that: the flow only ever occupies /// STARTUP, every observed sample was application-limited, /// `full_bw_reached`/`full_bw_now` were never set, and `full_bw_count` never /// reached `MAX_FULL_BW_COUNT`. @@ -3528,7 +3489,7 @@ mod test { /// (4*MSS). const APP_WINDOW: u64 = 20 * MSS; /// rounds to observe before declaring "indefinitely". Each round is ~1 RTT - /// (100ms), so this spans ~16s, several `probe_rtt_interval`s of 5s. + /// (100ms), so this spans ~16s, past the 10s `BBR.MinRTTFilterLen`. const ROUNDS_TO_OBSERVE: u64 = 160; // bottleneck serialization time for one MSS-sized packet @@ -3670,7 +3631,7 @@ mod test { /// A.8: Exiting PROBE_DOWN on inflight. /// equivalent to BBRIsTimeToCruise: - /// + /// /// /// Same infinite-buffer simulator as A.5 (constant `BW`, constant `RTT`, no /// loss, sender always has data), driven STARTUP -> DRAIN -> PROBE_BW until @@ -3816,7 +3777,7 @@ mod test { /// A.9: Exiting PROBE_DOWN after max time, direct to PROBE_REFILL, bypassing /// PROBE_CRUISE. /// equivalent to BBRIsTimeToProbeBW: - /// + /// /// /// Drives the same single-bottleneck simulator as A.8 through /// STARTUP -> DRAIN -> PROBE_BW and on into the PROBE_DOWN that PROBE_UP cycles @@ -3830,7 +3791,7 @@ mod test { /// binding cruise threshold.) /// /// From that state it isolates the elapsed-time exit: it refreshes - /// `probe_rtt_min_stamp` so the periodic min-RTT re-probe (PROBE_RTT, cf. A.10) + /// `min_rtt_stamp` so the periodic min-RTT re-probe (PROBE_RTT, cf. A.10) /// cannot preempt, advances `now` just past `cycle_stamp + bw_probe_wait`, and /// drives `update_probe_bw_cycle_phase`. Because that function checks /// `BBRIsTimeToProbeBW` (the timer) *before* `BBRIsTimeToCruise`, and `C.inflight` @@ -3926,11 +3887,11 @@ mod test { bbr.reno_rounds_bound ); - // Isolate the elapsed-time exit. Refresh probe_rtt_min_stamp so the periodic + // Isolate the elapsed-time exit. Refresh min_rtt_stamp so the periodic // min-RTT re-probe (PROBE_RTT, cf. A.10) cannot preempt, then advance now just // past cycle_stamp + bw_probe_wait (has_elapsed_in_phase is a strict `>`) and // drive one cycle-phase step. - bbr.probe_rtt_min_stamp = Some(fire_at); + bbr.min_rtt_stamp = Some(fire_at); bbr.update_probe_bw_cycle_phase(0, fire_at); // A single cycle step took PROBE_DOWN straight to PROBE_REFILL, bypassing @@ -3950,27 +3911,27 @@ mod test { /// A.10: Entering and exiting PROBE_RTT. /// equivalent to BBRCheckProbeRTT / BBRHandleProbeRTT / BBRExitProbeRTT: - /// + /// /// /// Same infinite-buffer FIFO simulator as A.1/A.8 (constant link rate, /// constant propagation delay), driven STARTUP -> DRAIN -> PROBE_BW and then - /// left to run for more than `BBR.ProbeRTTInterval` (5 s). This is the - /// periodic min-RTT re-probe: once `BBR.probe_rtt_min_delay` has not been - /// lowered for a full ProbeRTTInterval, `update_min_rtt` flips - /// `BBR.probe_rtt_expired` true and `check_probe_rtt` enters PROBE_RTT. + /// left to run for more than `BBR.MinRTTFilterLen` (10 s). This is the + /// periodic min-RTT re-probe: once `BBR.min_rtt` has not been lowered for a + /// full MinRTTFilterLen, `update_min_rtt` flips `BBR.min_rtt_expired` true and + /// `check_probe_rtt` enters PROBE_RTT. /// - /// Why `probe_rtt_min_delay` stays put for the whole 5 s: with a constant link + /// Why `min_rtt` stays put for the whole 10 s: with a constant link /// rate and propagation delay, the smallest achievable RTT is the fixed floor /// `FWD + service + RET`, hit whenever the bottleneck queue is empty (every /// PROBE_DOWN drains to it). `update_min_rtt` only refreshes - /// `probe_rtt_min_stamp` on a *strictly* lower sample (`rtt < probe_rtt_min_delay`), + /// `min_rtt_stamp` on a *strictly* lower sample (`rtt < min_rtt`), /// so repeated floor-equal samples never move the stamp. The first ack stamps the - /// floor (~t=100 ms via the `probe_rtt_expired`-on-None branch); nothing beats it - /// afterward, so the stamp is frozen and expiry fires ~5 s later, comfortably - /// after STARTUP/DRAIN have handed off to PROBE_BW with `full_bw_reached` true. + /// floor (~t=100 ms); nothing beats it afterward, so the stamp is frozen and + /// expiry fires ~10 s later, comfortably after STARTUP/DRAIN have handed off to + /// PROBE_BW with `full_bw_reached` true. /// - /// On entry `check_probe_rtt` calls `enter_probe_rtt` (state -> ProbeRtt, - /// `cwnd_gain` -> `ProbeRTTCwndGain` = 0.5), saves the cwnd, clears + /// On entry `check_probe_rtt` saves the cwnd, then calls `enter_probe_rtt` + /// (state -> ProbeRtt, `cwnd_gain` -> `ProbeRTTCwndGain` = 0.5), clears /// `probe_rtt_done_stamp`, and starts a round. `bound_cwnd_for_probe_rtt` then /// caps `C.cwnd` at `BBRProbeRTTCwnd` (~0.5·BDP), so the sender stalls until /// `C.inflight` drains below that cap. When it does, `handle_probe_rtt` stamps @@ -3983,7 +3944,7 @@ mod test { /// cwnd cap so the sender resumes. /// /// Asserts that: the flow reached PROBE_BW with `full_bw_reached` true before any - /// PROBE_RTT entry; PROBE_RTT was entered only after ProbeRTTInterval (5 s) had + /// PROBE_RTT entry; PROBE_RTT was entered only after MinRTTFilterLen (10 s) had /// elapsed, with `cwnd_gain == ProbeRTTCwndGain` (0.5); the exit came at least /// ProbeRTTDuration (200 ms) *and* one round after `probe_rtt_done_stamp` was /// armed; and the flow transitioned back to PROBE_BW (Cruise) with @@ -4039,12 +4000,8 @@ mod test { reached_probe_bw = true; } - // Entry edge into PROBE_RTT: the periodic min-RTT re-probe we care - // about, i.e. the one after PROBE_BW. (A transient PROBE_RTT also - // fires on the very first ack, because probe_rtt_min_stamp starts - // unset so probe_rtt_expired is true at t=0; that one happens during - // STARTUP, exits straight back to STARTUP via !full_bw_reached, and - // is filtered out by the reached_probe_bw guard.) + // Entry edge into PROBE_RTT: the periodic min-RTT re-probe after + // PROBE_BW. if reached_probe_bw && probe_rtt_entry.is_none() && bbr.state == BbrState::ProbeRtt { probe_rtt_entry = Some((now_ns, bbr.cwnd_gain, bbr.round_count)); @@ -4080,15 +4037,14 @@ mod test { "BBR never reached PROBE_BW with full_bw_reached before PROBE_RTT" ); - // Entered PROBE_RTT, and only after ProbeRTTInterval (5 s) elapsed with - // probe_rtt_min_delay never lowered. + // Entered PROBE_RTT, and only after MinRTTFilterLen (10 s) elapsed with + // min_rtt never lowered. let (entry_ns, entry_cwnd_gain, entry_round) = probe_rtt_entry.expect("BBR never entered PROBE_RTT"); assert!( - entry_ns >= PROBE_RTT_INTERVAL_SEC * 1_000_000_000, - "PROBE_RTT entered before ProbeRTTInterval elapsed \ - (entry {entry_ns} ns vs interval {}s)", - PROBE_RTT_INTERVAL_SEC + entry_ns >= MIN_RTT_FILTER_LEN.as_nanos() as u64, + "PROBE_RTT entered before MinRTTFilterLen elapsed \ + (entry {entry_ns} ns vs {MIN_RTT_FILTER_LEN:?})" ); // cwnd_gain was set to ProbeRTTCwndGain (0.5) on entry. assert_eq!( @@ -4143,14 +4099,14 @@ mod test { /// A.11: Skipping PROBE_RTT due to application-limited (restart-from-idle) sending. /// equivalent to BBRHandleRestartFromIdle / BBRCheckProbeRTT: - /// + /// /// /// Same infinite-buffer FIFO simulator as A.10 (constant link rate, constant /// propagation delay), driven STARTUP -> DRAIN -> PROBE_BW. Then the /// application stops offering data: every in-flight packet is acked with no new /// sends, so `C.inflight` drains to 0 and the connection goes idle. Virtual time is - /// then advanced past `BBR.ProbeRTTInterval` (5 s) with nothing in flight, long - /// enough that the periodic min-RTT re-probe is due (`probe_rtt_expired` becomes + /// then advanced past `BBR.MinRTTFilterLen` (10 s) with nothing in flight, long + /// enough that the periodic min-RTT re-probe is due (`min_rtt_expired` becomes /// true on the next `update_min_rtt`), exactly the condition that drove the PROBE_RTT /// entry in A.10. /// @@ -4158,16 +4114,16 @@ mod test { /// first packet, `on_sent` calls `handle_restart_from_idle`: because /// `C.inflight` was 0 and the connection is application-limited (`C.app_limited != 0`), /// it sets `BBR.idle_restart = true`. On the resulting ack, `check_probe_rtt` sees - /// `probe_rtt_expired` true but refuses to `enter_probe_rtt` because of the + /// `min_rtt_expired` true but refuses to `enter_probe_rtt` because of the /// `!idle_restart` guard: an idle period is itself deemed a sufficient drain of the /// bottleneck queue, so a formal PROBE_RTT is unnecessary. `idle_restart` is then - /// cleared once a delivering ack arrives, and the refreshed `probe_rtt_min_stamp` + /// cleared once a delivering ack arrives, and the refreshed `min_rtt_stamp` /// keeps expiry from re-firing on the following acks. /// /// Asserts that: the flow reached PROBE_BW with `full_bw_reached` and then drained to - /// idle (`C.inflight == 0`) while still in PROBE_BW; more than ProbeRTTInterval (5 s) + /// idle (`C.inflight == 0`) while still in PROBE_BW; more than MinRTTFilterLen (10 s) /// elapsed during the idle gap; the first send after idle set `BBR.idle_restart`; and - /// although the min-RTT re-probe was due at that point (`probe_rtt_expired` true), the + /// although the min-RTT re-probe was due at that point (`min_rtt_expired` true), the /// connection never entered PROBE_RTT over the subsequent rounds. #[test] fn probe_bw_skips_probe_rtt_on_restart_from_idle() { @@ -4272,14 +4228,14 @@ mod test { ); let idle_start_ns = now_ns; - // Phase 3: stay idle past BBR.ProbeRTTInterval (5 s), so the periodic min-RTT + // Phase 3: stay idle past BBR.MinRTTFilterLen (10 s), so the periodic min-RTT // re-probe becomes due. Nothing is in flight, so no BBR callbacks fire; time just // advances. With no data to send during the gap, the connection is app-limited. - now_ns = idle_start_ns + PROBE_RTT_INTERVAL_SEC * 1_000_000_000 + 2 * RTT_NS; + now_ns = idle_start_ns + MIN_RTT_FILTER_LEN.as_nanos() as u64 + 2 * RTT_NS; bbr.bbr.rate.mark_app_limited(bbr.bbr.inflight); assert!( - now_ns - idle_start_ns >= PROBE_RTT_INTERVAL_SEC * 1_000_000_000, - "idle gap must exceed ProbeRTTInterval (5 s)" + now_ns - idle_start_ns >= MIN_RTT_FILTER_LEN.as_nanos() as u64, + "idle gap must exceed MinRTTFilterLen (10 s)" ); // Phase 4: the application resumes and sends one packet. handle_restart_from_idle @@ -4311,9 +4267,9 @@ mod test { ); // Phase 5: keep sending/acking. On the resume packet's ack the min-RTT re-probe is - // due (probe_rtt_expired true), yet PROBE_RTT must be skipped because idle_restart + // due (min_rtt_expired true), yet PROBE_RTT must be skipped because idle_restart // is set. Run enough rounds to prove it stays skipped. - let mut probe_rtt_expired_at_resume: Option = None; + let mut min_rtt_expired_at_resume: Option = None; let mut entered_probe_rtt = false; let mut acks_after_resume: u64 = 0; for _ in 0..2_000_000 { @@ -4350,8 +4306,8 @@ mod test { if p.pn == resume_pn { // Snapshot right after the restarting packet's ack: the re-probe was - // due (probe_rtt_expired) so only idle_restart could suppress entry. - probe_rtt_expired_at_resume = Some(bbr.probe_rtt_expired); + // due (min_rtt_expired) so only idle_restart could suppress entry. + min_rtt_expired_at_resume = Some(bbr.min_rtt_expired); } acks_after_resume += 1; @@ -4370,9 +4326,9 @@ mod test { // The min-RTT re-probe was due at resume (the same trigger that entered // PROBE_RTT in A.10), so idle_restart is the only thing that could suppress entry. assert_eq!( - probe_rtt_expired_at_resume, + min_rtt_expired_at_resume, Some(true), - "probe_rtt_expired should be true at resume (5 s elapsed), making the \ + "min_rtt_expired should be true at resume (10 s elapsed), making the \ PROBE_RTT skip attributable to idle_restart" ); // The connection skipped PROBE_RTT: idleness was a sufficient queue drain. @@ -4384,8 +4340,8 @@ mod test { /// A.12: Achieving expected STARTUP bandwidth on a link with ACK aggregation. /// equivalent to BBRUpdateACKAggregation / BBRUpdateMaxInflight: - /// - /// + /// + /// /// /// Same constant-rate FIFO simulator as A.1, with one change: the path /// aggregates ACKs. Instead of each served packet being acked as soon as it clears @@ -4588,8 +4544,8 @@ mod test { /// A.13: Achieving expected cruise bandwidth on a link with ACK aggregation. /// equivalent to BBRUpdateACKAggregation / BBRUpdateMaxInflight: - /// - /// + /// + /// /// /// The aggregation-in-STARTUP counterpart is A.12; this covers the same excess-data /// mechanism in the steady-state PROBE_BW cruise phase, where the aggregation estimate @@ -4880,8 +4836,8 @@ mod test { /// A.14: Correctly managing sub-packet BDPs. /// equivalent to BBRInflight / BBRQuantizationBudget (the BBR.MinPipeCwnd floor): - /// - /// + /// + /// /// /// On a very slow bottleneck the model-derived congestion window collapses below the /// pipelining minimum. `BBR.MinPipeCwnd` (4 * SMSS) is the floor that keeps enough packets @@ -5159,7 +5115,7 @@ mod test { /// A.15: Increasing bandwidth 10x and ensuring full bandwidth is reached. /// equivalent to BBRRaiseInflightLongtermSlope / BBRProbeInflightLongtermUpward: - /// + /// /// /// After PROBE_BW is reached at a low link rate, the bottleneck bandwidth jumps 10x. In /// PROBE_UP BBR grows `inflight_longterm` with an exponentially increasing per-round step so @@ -5410,7 +5366,7 @@ mod test { /// A.16: Decreasing bandwidth 10x and ensuring max bandwidth adapts down. /// Exercises the short-term loss response (`loss_lower_bounds`) and the windowed `max_bw` /// filter expiry (`advance_max_bw_filter`, `BBR.MaxBwFilterLen`): - /// + /// /// /// After PROBE_BW is reached at a high link rate, the bottleneck bandwidth drops 10x. The /// flow is still carrying ~BDP of the *old* (high) rate, so once the link slows the standing @@ -5621,7 +5577,7 @@ mod test { /// A.17: Handling token bucket policers. /// Exercises the short-term loss response (`init_lower_bounds` + `loss_lower_bounds`, driven /// from `adapt_lower_bounds_from_congestion`) settling the flow to a token-bucket policer's - /// token rate: + /// token rate: /// /// A token-bucket policer is not a queue. It holds a bucket of `BURST` bytes that refills at /// the token rate, admits a packet only if a token is available, and *drops* (never @@ -5841,7 +5797,7 @@ mod test { /// A.18: Handling spurious Fast Recovery (the loss-undo path). /// Exercises `save_state_upon_loss` (BBRSaveStateUponLoss) and `on_spurious_loss` /// (BBRHandleSpuriousLossDetection): - /// + /// /// /// Packet reordering (later packets delivered while earlier ones sit apparently missing) makes /// the transport's loss detector declare a Fast Recovery that never really happened: the "lost" @@ -6093,7 +6049,7 @@ mod test { /// A.19: Handling spurious RTO Recovery (the loss-undo path, RTO variant). /// Exercises `save_state_upon_loss` (BBRSaveStateUponLoss) and `on_spurious_loss` /// (BBRHandleSpuriousLossDetection): - /// + /// /// /// Where A.18 covers a spurious *Fast* Recovery (later packets keep being delivered while a few /// earlier ones look missing), this covers a spurious *RTO* Recovery: acknowledgements stop @@ -6352,7 +6308,7 @@ mod test { /// A.20: Entering and exiting PROBE_RTT during STARTUP. /// equivalent to BBRCheckProbeRTT / BBRHandleProbeRTT / BBRExitProbeRTT: - /// + /// /// /// A.10 covers the PROBE_RTT interlude that fires *after* PROBE_BW, where /// `full_bw_reached` is true and `exit_probe_rtt` therefore routes on to @@ -6369,16 +6325,9 @@ mod test { /// every sample is application-limited and `check_full_bw_reached` bails on its /// `is_app_limited` guard, `full_bw_reached` never arms and STARTUP persists. /// With a constant RTT the min-RTT floor never drops, so `update_min_rtt` - /// freezes `probe_rtt_min_stamp` and flips `BBR.probe_rtt_expired` true one - /// `BBR.ProbeRTTInterval` (5 s) after it was last stamped; `check_probe_rtt` - /// then enters PROBE_RTT, all while `full_bw_reached` is still false. - /// - /// A transient PROBE_RTT also fires on the very first ack (`probe_rtt_min_stamp` - /// starts unset, so `probe_rtt_expired` is true at t~0); its exit re-stamps - /// `probe_rtt_min_stamp`, so the *next* expiry (the one this test targets) - /// lands a full ProbeRTTInterval later, ~5 s into the still-running STARTUP. - /// The t~0 transient is filtered out by requiring the entry at - /// >= ProbeRTTInterval. + /// freezes `min_rtt_stamp` at the first ack and flips `BBR.min_rtt_expired` + /// true one `BBR.MinRTTFilterLen` (10 s) later; `check_probe_rtt` then enters + /// PROBE_RTT, all while `full_bw_reached` is still false. /// /// On entry `check_probe_rtt` runs `enter_probe_rtt` (state -> ProbeRtt, /// `cwnd_gain` -> ProbeRTTCwndGain 0.5) and clears `probe_rtt_done_stamp`; @@ -6393,7 +6342,7 @@ mod test { /// /// Asserts that: the flow only ever occupied STARTUP or PROBE_RTT (never /// advanced to DRAIN/PROBE_BW) and `full_bw_reached` was never set; the targeted - /// PROBE_RTT was entered only after ProbeRTTInterval (5 s) had elapsed, with + /// PROBE_RTT was entered only after MinRTTFilterLen (10 s) had elapsed, with /// `cwnd_gain == ProbeRTTCwndGain` (0.5) and `full_bw_reached` still false; /// `probe_rtt_done_stamp` armed once inflight drained below the cap; the /// interlude held for at least ProbeRTTDuration (200 ms) *and* one round after @@ -6414,10 +6363,10 @@ mod test { /// keeping `full_bw_reached` false and STARTUP alive (cf. A.7). Comfortably /// above `min_pipe_cwnd` (4*MSS). const APP_WINDOW: u64 = 20 * MSS; - /// round cap (~1 RTT each, so ~12 s): more than one ProbeRTTInterval (5 s) - /// plus a ProbeRTTDuration (200 ms), enough to capture the interval-expiry + /// round cap (~1 RTT each, so ~15 s): more than one MinRTTFilterLen (10 s) + /// plus a ProbeRTTDuration (200 ms), enough to capture the expiry /// interlude and its exit if the loop does not break earlier. - const ROUNDS_CAP: u64 = 120; + const ROUNDS_CAP: u64 = 150; // bottleneck serialization time for one MSS-sized packet let btl_service_ns: u64 = (MSS as f64 / BW * 1e9).round() as u64; @@ -6443,9 +6392,8 @@ mod test { let mut inflight: u64 = 0; let mut pn: u64 = 0; - // Captured on the targeted PROBE_RTT entry edge (first entry at or after - // ProbeRTTInterval, i.e. the genuine interval-expiry interlude, not the t~0 - // transient): (now_ns, cwnd_gain, full_bw_reached). + // Captured on the first PROBE_RTT entry edge, at or after MinRTTFilterLen: + // (now_ns, cwnd_gain, full_bw_reached). let mut entry: Option<(u64, f64, bool)> = None; // Captured when probe_rtt_done_stamp is first armed inside that interlude // (C.inflight has drained below the ProbeRTT cwnd cap): (now_ns, round). @@ -6514,9 +6462,8 @@ mod test { } } BbrState::ProbeRtt => { - // Target only the interval-expiry interlude (>= ProbeRTTInterval), - // skipping the t~0 unset-stamp transient. - if entry.is_none() && now_ns >= PROBE_RTT_INTERVAL_SEC * 1_000_000_000 { + // The expiry interlude, no sooner than MinRTTFilterLen. + if entry.is_none() && now_ns >= MIN_RTT_FILTER_LEN.as_nanos() as u64 { entry = Some((now_ns, bbr.cwnd_gain, bbr.full_bw_reached)); } // The moment probe_rtt_done_stamp is armed inside that interlude: @@ -6561,9 +6508,9 @@ mod test { "full_bw_reached must never be set on application-limited samples" ); - // Entered PROBE_RTT only after ProbeRTTInterval (5 s), still in STARTUP. `entry` - // is only set inside the `>= ProbeRTTInterval` guard above, so a successful - // `expect` already pins the interval-expiry timing. + // Entered PROBE_RTT only after MinRTTFilterLen (10 s), still in STARTUP. `entry` + // is only set inside the `>= MinRTTFilterLen` guard above, so a successful + // `expect` already pins the expiry timing. let (entry_ns, entry_cwnd_gain, entry_full_bw) = entry.expect("BBR never entered the interval-expiry PROBE_RTT during STARTUP"); assert!( @@ -6624,7 +6571,7 @@ mod test { /// A.21: Handling loss during PROBE_UP after `inflight_longterm` is set. /// equivalent to BBRHandleInflightTooHigh: - /// + /// /// /// The counterpart to A.6 (loss in PROBE_UP while application-limited, where the /// `!is_app_limited` guard makes `handle_inflight_too_high` leave @@ -6856,7 +6803,7 @@ mod test { } /// A.22: Handling application-limited sending during PROBE_REFILL. - /// equivalent to BBRUpdateMaxBw + /// equivalent to BBRUpdateMaxBw /// /// The `!is_app_limited` half of the `update_max_bw` guard /// (`delivery_rate >= BBR.max_bw || !RS.is_app_limited`) in isolation: an @@ -7404,7 +7351,7 @@ mod test { let mut sim = scripted(); sim.round(0, 100, 10 * MS); sim.bbr.full_bw_reached = true; - sim.bbr.bw_probe_samples = true; + sim.bbr.check_probe_loss = true; sim.bbr.bbr.enter_probe_bw(sim.at(10 * MS)); sim } @@ -7516,7 +7463,7 @@ mod test { assert_eq!(sim.bbr.state, BbrState::ProbeBw(ProbeBwSubstate::Cruise)); assert_eq!(sim.bbr.cycle_count, cycle + 1); assert_eq!(sim.bbr.max_bw, 12_000_000.0); - assert!(!sim.bbr.bw_probe_samples); + assert!(!sim.bbr.check_probe_loss); // Lose 10% of the next round. let first = sim.pn; @@ -7538,7 +7485,7 @@ mod test { sim.starve(); sim.round(10 * MS, 100, 20 * MS); assert!(sim.bbr.rs.unwrap().is_app_limited); - assert!(!sim.bbr.bw_probe_samples); + assert!(!sim.bbr.check_probe_loss); for i in 1..5 { sim.round(10 * MS + i * 20 * MS, 100, 20 * MS); @@ -7577,15 +7524,16 @@ mod test { #[test] fn probe_rtt_finishes_probe_feedback_once() { let mut sim = probed(); + sim.bbr.start_probe_bw_refill(); sim.bbr.start_probe_bw_up(); sim.round(10 * MS, 100, 10 * MS); - assert_eq!(sim.bbr.ack_phase, AckPhase::ProbeFeedback); + assert!(sim.bbr.check_probe_loss && !sim.bbr.is_bw_probe_stopping); let cycle = sim.bbr.cycle_count; // The min RTT expires on the next round. - sim.bbr.probe_rtt_interval = Duration::ZERO; + sim.bbr.min_rtt_filter_len = Duration::ZERO; sim.round(20 * MS, 100, 10 * MS); - sim.bbr.probe_rtt_interval = Duration::from_secs(PROBE_RTT_INTERVAL_SEC); + sim.bbr.min_rtt_filter_len = MIN_RTT_FILTER_LEN; assert_eq!(sim.bbr.state, BbrState::ProbeRtt); assert_eq!(sim.bbr.cycle_count, cycle + 1); @@ -7597,7 +7545,7 @@ mod test { } assert_eq!(sim.bbr.state, BbrState::ProbeBw(ProbeBwSubstate::Cruise)); assert_eq!(sim.bbr.cycle_count, cycle + 1); - assert!(!sim.bbr.bw_probe_samples); + assert!(!sim.bbr.check_probe_loss); for i in 0..5 { sim.round(now + i * 10 * MS, 100, 10 * MS); @@ -7609,9 +7557,9 @@ mod test { /// with a max-bw window that has since aged, so any unprotected sample replaces the maximum. fn probing_rtt() -> Sim { let mut sim = probed(); - sim.bbr.probe_rtt_interval = Duration::ZERO; + sim.bbr.min_rtt_filter_len = Duration::ZERO; sim.round(10 * MS, 100, 10 * MS); - sim.bbr.probe_rtt_interval = Duration::from_secs(PROBE_RTT_INTERVAL_SEC); + sim.bbr.min_rtt_filter_len = MIN_RTT_FILTER_LEN; assert_eq!(sim.bbr.state, BbrState::ProbeRtt); sim.bbr.max_bw_filter = [0.0; MAX_BW_FILTER_LEN]; sim @@ -7753,9 +7701,9 @@ mod test { let mut sim = probed(); let first = sim.pn; sim.send(10 * MS, 100); - sim.bbr.probe_rtt_interval = Duration::ZERO; + sim.bbr.min_rtt_filter_len = Duration::ZERO; sim.ack(20 * MS, first..first + 40, false); - sim.bbr.probe_rtt_interval = Duration::from_secs(PROBE_RTT_INTERVAL_SEC); + sim.bbr.min_rtt_filter_len = MIN_RTT_FILTER_LEN; assert_eq!(sim.bbr.state, BbrState::ProbeRtt); // Inflight reaches the ProbeRTT window, which the sender then fills. @@ -7826,8 +7774,8 @@ mod test { entries } - /// An application-limited flow skips every due ProbeRTT, even after its RTT rose well past - /// BBR.min_rtt, moving only the stamps: BBR.min_rtt keeps the old floor. + /// An application-limited flow skips every due ProbeRTT, and each skip adopts the lowest RTT + /// of the window that expired, so BBR.min_rtt follows a base RTT that rose within two windows. #[test] fn app_limited_skips_probe_rtt() { let mut sim = probed(); @@ -7839,16 +7787,18 @@ mod test { 20 * MS } }; - assert_eq!(pipeline(&mut sim, 10 * MS, 20_000 * MS, rtt, true), 0); + // The first window still holds the samples sent before the rise. + assert_eq!(pipeline(&mut sim, 10 * MS, 15_000 * MS, rtt, true), 0); assert_eq!(sim.bbr.min_rtt, Duration::from_millis(10)); - assert_eq!(sim.bbr.probe_rtt_min_delay, Duration::from_millis(10)); - assert!(sim.bbr.probe_rtt_min_stamp.unwrap() > sim.at(15_000 * MS)); - assert!(sim.bbr.min_rtt_stamp.unwrap() > sim.at(15_000 * MS)); + assert!(sim.bbr.min_rtt_stamp.unwrap() > sim.at(10_000 * MS)); + // The second holds only the risen RTT. + assert_eq!(pipeline(&mut sim, 15_000 * MS, 21_000 * MS, rtt, true), 0); + assert_eq!(sim.bbr.min_rtt, Duration::from_millis(20)); + assert!(sim.bbr.min_rtt_stamp.unwrap() > sim.at(20_000 * MS)); } /// Loss or CE in the interval means the flow shares a full queue, so an application-limited - /// flow enters ProbeRTT, and BBR.min_rtt expires into the higher RTT it measured even though - /// the next interval skips. + /// flow enters ProbeRTT, and BBR.min_rtt expires into the higher RTT it measured. #[test] fn congested_interval_enters_probe_rtt() { for ce in [false, true] { @@ -7864,17 +7814,82 @@ mod test { } } - /// A flow never application-limited enters ProbeRTT even with every RTT sample at - /// BBR.min_rtt, as competing bulk flows rely on. + /// A loss declared spurious was not congestion, so the interval still skips ProbeRTT; a real + /// loss earlier in the interval still denies the skip, unless the interval restarted since. + #[test] + fn spurious_loss_keeps_the_probe_rtt_skip() { + for (earlier, restart, entries) in [(false, false, 0), (true, false, 1), (true, true, 0)] { + let mut sim = probed(); + if earlier { + sim.send(10 * MS, 1); + sim.lose(20 * MS, sim.pn - 1); + } + // A packet sent after any earlier episode began opens a new one. + sim.send(25 * MS, 1); + sim.lose(30 * MS, sim.pn - 1); + assert!(sim.bbr.probe_rtt_skip_congested); + if restart { + // A lower RTT sample restarts the min_rtt filter, and the interval with it. + sim.send(40 * MS, 1); + sim.ack(45 * MS, [sim.pn - 1], false); + assert_eq!(sim.bbr.min_rtt, Duration::from_millis(5)); + } + sim.bbr.on_spurious_loss(); + let got = pipeline(&mut sim, 50 * MS, 12_000 * MS, |_| 10 * MS, true); + assert_eq!(got, entries, "earlier={earlier} restart={restart}"); + } + } + + /// A flow never application-limited enters ProbeRTT once BBR.MinRTTFilterLen passes without + /// a lower RTT sample, even with every sample at BBR.min_rtt, as competing bulk flows rely on. #[test] fn bulk_flow_at_min_rtt_enters_probe_rtt() { let mut sim = probed(); + let expiry_ns = 10 * MS + MIN_RTT_FILTER_LEN.as_nanos() as u64; assert_eq!( - pipeline(&mut sim, 10 * MS, 6000 * MS, |_| 10 * MS, false), + pipeline(&mut sim, 10 * MS, expiry_ns - 20 * MS, |_| 10 * MS, false), + 0 + ); + assert_eq!( + pipeline( + &mut sim, + expiry_ns - 20 * MS, + expiry_ns + 1000 * MS, + |_| 10 * MS, + false + ), 1 ); } + /// Entering ProbeRTT outside recovery saves the window it cuts, as SaveCwnd runs before + /// EnterProbeRTT, rather than keeping a larger window saved before. + #[test] + fn probe_rtt_saves_the_window_it_cuts() { + let mut sim = probed(); + let cwnd = sim.bbr.cwnd; + sim.bbr.prior_cwnd = 10 * cwnd; + sim.bbr.min_rtt_filter_len = Duration::ZERO; + sim.round(10 * MS, 1, 10 * MS); + assert_eq!(sim.bbr.state, BbrState::ProbeRtt); + assert_eq!(sim.bbr.prior_cwnd, cwnd); + } + + /// ProbeRTT caps the window at half the BDP of the BBR.min_rtt that expired, not of the + /// queued RTT that replaced it. + #[test] + fn probe_rtt_cwnd_keeps_the_expired_min_rtt() { + let mut sim = probed(); + sim.send(10 * MS, 100); + sim.bbr.min_rtt_filter_len = Duration::ZERO; + sim.ack(50 * MS, sim.pn - 100..sim.pn, false); + assert_eq!(sim.bbr.state, BbrState::ProbeRtt); + assert_eq!(sim.bbr.min_rtt, Duration::from_millis(40)); + // Half of the 120 KB BDP at 12 MB/s over 10ms. + assert_eq!(sim.bbr.probe_rtt_cwnd(), 60_000); + assert!(sim.bbr.cwnd <= 60_000); + } + /// A scripted `Sim` in PROBE_UP with a 100,000-byte long-term bound, a 10,000-byte BDP, a /// 20,000-byte cwnd, and ten packets in flight, so one lost packet is too much loss. fn probing_up() -> Sim { @@ -7882,7 +7897,7 @@ mod test { sim.round(0, 10, 10 * MS); sim.bbr.full_bw_reached = true; sim.bbr.start_probe_bw_up(); - sim.bbr.bw_probe_samples = true; + sim.bbr.check_probe_loss = true; sim.bbr.inflight_longterm = 100_000; sim.bbr.bdp = 10_000; sim.bbr.cwnd = 20_000; @@ -7953,7 +7968,7 @@ mod test { sim.ack(14 * MS, [11], false); sim.bbr.bbr.start_probe_bw_down(sim.at(14 * MS)); // The probe's feedback is still arriving, so a loss cuts the bound without a state change. - sim.bbr.bw_probe_samples = true; + sim.bbr.check_probe_loss = true; sim.lose(15 * MS, 10); // An ACK from the lost packet's flight cuts the window without ending the loss round. sim.ack(16 * MS, [12], false); @@ -7977,9 +7992,9 @@ mod test { sim.ack(20 * MS, [11], false); assert!(sim.bbr.cwnd < 20_000); // The min RTT expires on the following ACK. - sim.bbr.probe_rtt_interval = Duration::ZERO; + sim.bbr.min_rtt_filter_len = Duration::ZERO; sim.ack(21 * MS, 12..20, false); - sim.bbr.probe_rtt_interval = Duration::from_secs(PROBE_RTT_INTERVAL_SEC); + sim.bbr.min_rtt_filter_len = MIN_RTT_FILTER_LEN; assert_eq!(sim.bbr.state, BbrState::ProbeRtt); assert!(sim.bbr.in_recovery); let bound = sim.bbr.probe_rtt_cwnd(); @@ -8000,7 +8015,7 @@ mod test { #[test] fn probe_rtt_episode_keeps_the_saved_window() { let mut sim = probing_up(); - sim.bbr.probe_rtt_interval = Duration::ZERO; + sim.bbr.min_rtt_filter_len = Duration::ZERO; sim.ack(20 * MS, 10..20, false); assert_eq!(sim.bbr.state, BbrState::ProbeRtt); let saved = sim.bbr.prior_cwnd; @@ -8029,9 +8044,9 @@ mod test { assert_ne!(sim.bbr.state, BbrState::Startup); // The min RTT expires on the next round. - sim.bbr.probe_rtt_interval = Duration::ZERO; + sim.bbr.min_rtt_filter_len = Duration::ZERO; sim.round(20 * MS, 100, 10 * MS); - sim.bbr.probe_rtt_interval = Duration::from_secs(PROBE_RTT_INTERVAL_SEC); + sim.bbr.min_rtt_filter_len = MIN_RTT_FILTER_LEN; assert_eq!(sim.bbr.state, BbrState::ProbeRtt); sim.bbr.on_spurious_loss(); @@ -8477,7 +8492,7 @@ mod test { let risky_inflight = sim.bbr.inflight_longterm; sim.ack(20 * MS, 11..20, false); let wait_ns = sim.bbr.bw_probe_wait.as_nanos() as u64 + 30 * MS; - sim.bbr.probe_rtt_min_stamp = Some(sim.at(wait_ns)); + sim.bbr.min_rtt_stamp = Some(sim.at(wait_ns)); sim.round(wait_ns, 5, 10 * MS); assert_eq!(sim.bbr.state, BbrState::ProbeBw(ProbeBwSubstate::Refill)); sim.round(wait_ns + 10 * MS, 5, 10 * MS); @@ -8504,7 +8519,7 @@ mod test { let risky_inflight = sim.bbr.inflight_longterm; sim.ack(20 * MS, 11..20, false); let wait_ns = sim.bbr.bw_probe_wait.as_nanos() as u64 + 30 * MS; - sim.bbr.probe_rtt_min_stamp = Some(sim.at(wait_ns)); + sim.bbr.min_rtt_stamp = Some(sim.at(wait_ns)); sim.round(wait_ns, 5, 10 * MS); sim.round(wait_ns + 10 * MS, 5, 10 * MS); assert_eq!(sim.bbr.state, BbrState::ProbeBw(ProbeBwSubstate::Up)); diff --git a/rs/moq-congestion/src/pacer.rs b/rs/moq-congestion/src/pacer.rs index 85b3ea21104..a2ca0051a9e 100644 --- a/rs/moq-congestion/src/pacer.rs +++ b/rs/moq-congestion/src/pacer.rs @@ -211,7 +211,7 @@ pub(crate) struct Rate { /// smoothed RTT, sped up by 5/4. pub window: u64, /// Bytes per second, which takes precedence over the window when present. - /// + /// pub pacing_rate: Option, } diff --git a/rs/moq-congestion/src/rate.rs b/rs/moq-congestion/src/rate.rs index 34dd7a47461..e3cd06e517a 100644 --- a/rs/moq-congestion/src/rate.rs +++ b/rs/moq-congestion/src/rate.rs @@ -3,7 +3,7 @@ //! Follows draft-ietf-ccwg-bbr section 4.1 and Linux `tcp_rate.c`: each sent packet snapshots the //! connection's delivery counters, and each ACK turns its most recently sent packet's snapshot //! into a rate sample. -//! +//! use kio::clock::Instant; use std::num::NonZeroU16; @@ -14,7 +14,7 @@ use crate::{Ack, Sent}; /// Controller state for one sent packet, which the transport stores and hands back. /// /// Equivalent to the draft's per-packet `P` fields. -/// +/// #[derive(Debug, Clone, Copy)] pub struct Packet { /// equivalent to P.delivered: C.delivered when the packet was sent. @@ -53,7 +53,7 @@ impl Default for Packet { } /// A rate sample from one ACK, equivalent to the draft's `RS`. -/// +/// #[derive(Debug, Clone, Copy)] pub(crate) struct Sample { /// equivalent to RS.delivery_rate: bytes per second, or zero if the interval was too short to @@ -108,7 +108,7 @@ pub(crate) struct Sampler { impl Sampler { /// equivalent to OnPacketSent: snapshots the counters for this packet. - /// + /// pub fn on_sent(&mut self, sent: Sent) -> Packet { if sent.in_flight <= u64::from(sent.bytes) { self.first_send_time = Some(sent.now); @@ -130,7 +130,7 @@ impl Sampler { /// Samples the most recently sent packet acked, if any. A sample whose interval is shorter /// than `min_rtt` (or this sample's own RTT, if lower) carries no rate, as the draft discards /// it, but still describes the ACK. - /// + /// pub fn on_ack(&mut self, ack: &Ack<'_>, min_rtt: Duration) -> Option { for acked in ack.packets { self.delivered += u64::from(acked.bytes); @@ -182,7 +182,7 @@ impl Sampler { /// equivalent to marking C.app_limited: packets sent until `in_flight` more bytes are /// delivered are application-limited. - /// + /// pub fn mark_app_limited(&mut self, in_flight: u64) { self.app_limited = Ord::max(self.delivered + in_flight, 1); }