diff --git a/quest/m1/bbr3-references/transitions.md b/quest/m1/bbr3-references/transitions.md deleted file mode 100644 index 90cdbe98e9e..00000000000 --- a/quest/m1/bbr3-references/transitions.md +++ /dev/null @@ -1,27 +0,0 @@ -# [XS] BBR3 clears congestion signals in Drain and floors its Reno probe time - -## Goal - -Leaving Startup charges a loss or CE mark once, and a small-BDP bulk flow -probes no more often than Linux's minimum of a few rounds. - -## Plan - -- `enter_drain` (`rs/moq-congestion/src/bbr3/mod.rs`) does not reset the - congestion signals as Linux does on Drain entry - ([tcp_bbr.c:1963](https://github.com/google/bbr/blob/90210de4b779d40496dee0b89081780eeddf2a60/net/ipv4/tcp_bbr.c#L1963)), - so the CE that ends Startup also cuts `bw_shortterm` and - `inflight_shortterm` one loss round later in Drain, contradicting the - ledger's once-per-episode CE response. Call `reset_congestion_signals()`. -- `is_reno_coexistence_probe_time` divides `min(BDP, cwnd)` by the MSS, - rounding down, with no floor: at 1 Mbit/s and 20 ms it probes every one or - two rounds, and DOWN can end before draining the probe's queue. Linux's - target goes through `bbr_inflight`, floored by the quantization budget - ([tcp_bbr.c:1010-1015](https://github.com/google/bbr/blob/90210de4b779d40496dee0b89081780eeddf2a60/net/ipv4/tcp_bbr.c#L1010-L1015)). - Floor the BDP at `max(bdp, offload budget, min_pipe_cwnd)`, round up, - then cap it at cwnd as Linux's `bbr_target_inflight` does, so a cwnd cut - by congestion still shortens the wait. - Application-limited flows are unaffected, since their UP lasts until loss. - -Test each. Caused by [moq-dev/moq#4921](https://github.com/moq-dev/moq/pull/4921), -which ported both from draft-06. diff --git a/rs/moq-congestion/src/bbr3/mod.rs b/rs/moq-congestion/src/bbr3/mod.rs index e6c965b22b5..9698eff0c87 100644 --- a/rs/moq-congestion/src/bbr3/mod.rs +++ b/rs/moq-congestion/src/bbr3/mod.rs @@ -957,7 +957,11 @@ impl Bbr3 { } /// equivalent to BBREnterDrain + /// + /// Clears the congestion signals as Linux does, so the loss or CE mark that ended Startup is + /// charged once, not again by the next loss round in Drain. fn enter_drain(&mut self) { + self.reset_congestion_signals(); self.state = BbrState::Drain; self.pacing_gain = self.drain_pacing_gain; self.cwnd_gain = self.default_cwnd_gain; @@ -1116,14 +1120,10 @@ impl Bbr3 { /// /// `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`. + /// bytes before comparing against a round count, rounding up as Linux does. /// fn is_reno_coexistence_probe_time(&self) -> bool { - let reno_rounds = self.target_inflight() / self.smss; - if reno_rounds == 0 { - return false; - } + let reno_rounds = self.target_inflight().div_ceil(self.smss); let rounds = Ord::min(reno_rounds, self.reno_rounds_bound); self.rounds_since_bw_probe >= rounds } @@ -1744,8 +1744,13 @@ impl Bbr3 { } /// equivalent to BBRTargetInflight + /// + /// The BDP is floored as `BBRInflight` floors it, by the offload budget and `min_pipe_cwnd` + /// (Linux's `bbr_target_inflight` goes through `bbr_inflight`), so a small-BDP flow probes + /// no more often than every few rounds. The cwnd then caps it, so a cut cwnd shortens the wait. fn target_inflight(&self) -> u64 { - Ord::min(self.bdp, self.cwnd) + let bdp = Ord::max(self.bdp, self.offload_budget); + Ord::min(Ord::max(bdp, self.min_pipe_cwnd), self.cwnd) } /// equivalent to BBRResetShortTermModel @@ -7642,7 +7647,13 @@ mod test { assert_eq!(bbr.bdp, bdp); let expected = bbr.bbr.quantization_budget(2 * bdp + bbr.bbr.extra_acked); assert_eq!(bbr.max_inflight, expected); - assert_eq!(bbr.target_inflight(), Ord::min(bdp, bbr.cwnd)); + assert_eq!( + bbr.target_inflight(), + Ord::min( + Ord::max(bdp, bbr.offload_budget.max(bbr.min_pipe_cwnd)), + bbr.cwnd + ) + ); } /// DRAIN waits for inflight to reach the BDP at BBR.bw, which a loss in DRAIN lowers below @@ -8095,6 +8106,59 @@ mod test { assert_eq!(sim.bbr.inflight_longterm, bdp); } + /// The CE that ends Startup is charged once: the next loss round in Drain does not cut the + /// short-term bounds again. + #[test] + fn drain_entry_clears_the_congestion_signals() { + let mut sim = scripted(); + sim.round(0, 10, 10 * MS); + sim.round_ce(10 * MS, 20, 10 * MS); + assert_eq!(sim.bbr.state, BbrState::Drain); + assert!(!sim.bbr.ce_in_round); + + // A flight above the BDP keeps DRAIN going while a new loss round ends. + let first = sim.pn; + sim.send(20 * MS, 100); + sim.ack(30 * MS, first..first + 1, false); + sim.ack(31 * MS, first + 1..first + 2, false); + assert_eq!(sim.bbr.state, BbrState::Drain); + assert_eq!(sim.bbr.bw_shortterm, f64::INFINITY); + assert_eq!(sim.bbr.inflight_shortterm, u64::MAX); + } + + /// A flow whose BDP is under a packet still waits `min_pipe_cwnd` worth of rounds before + /// probing for Reno coexistence, and a cwnd cut below its BDP shortens the wait. + #[test] + fn reno_probe_time_floors_a_small_bdp() { + let mut sim = probed(); + let bbr = &mut sim.bbr; + bbr.bdp = 100; + bbr.offload_budget = 0; + bbr.cwnd = 100_000; + assert_eq!(bbr.target_inflight(), bbr.min_pipe_cwnd); + bbr.reno_rounds_bound = 62; + bbr.rounds_since_bw_probe = 3; + assert!(!bbr.is_reno_coexistence_probe_time()); + bbr.rounds_since_bw_probe = 4; + assert!(bbr.is_reno_coexistence_probe_time()); + + // The floor holds a BDP the offload budget exceeds above `min_pipe_cwnd`. + bbr.offload_budget = 10 * 1200; + bbr.rounds_since_bw_probe = 9; + assert!(!bbr.is_reno_coexistence_probe_time()); + bbr.rounds_since_bw_probe = 10; + assert!(bbr.is_reno_coexistence_probe_time()); + + // A cut cwnd caps the target, and a partial packet rounds up. + bbr.bdp = 100 * 1200; + bbr.cwnd = 7 * 1200 - 1; + assert_eq!(bbr.target_inflight(), bbr.cwnd); + bbr.rounds_since_bw_probe = 6; + assert!(!bbr.is_reno_coexistence_probe_time()); + bbr.rounds_since_bw_probe = 7; + assert!(bbr.is_reno_coexistence_probe_time()); + } + /// CE ends a bandwidth probe as too much loss does, bounding inflight by the flight that drew /// the marks; the unmarked control keeps probing. #[test]