Implement precautionary bandwidth probing in BBRv3. Adds support for precautionary bandwidth probing in Bbr3Sender, along with the 'B3NP' connection option to disable it. When enabled, a probe following a cycle with excessive loss decelerates by exiting PROBE_UP upon reaching inflight_hi. If this precautionary probe completes a round trip without excessive loss, BBRv3 accelerates immediately into PROBE_REFILL. This change also refactors the bandwidth probe stopping logic and max bandwidth filter advancement across PROBE_DOWN and PROBE_CRUISE. PiperOrigin-RevId: 1024377675
diff --git a/quiche/quic/core/congestion_control/bbr2_misc.h b/quiche/quic/core/congestion_control/bbr2_misc.h index 367e319..7382981 100644 --- a/quiche/quic/core/congestion_control/bbr2_misc.h +++ b/quiche/quic/core/congestion_control/bbr2_misc.h
@@ -224,6 +224,9 @@ // Can be disabled by connection option 'B2RC'. bool enable_reno_coexistence = true; + // Can be disabled by connection option 'B3NP' in BBRv3. + bool enable_precautionary_probing = true; + // For experimentation to improve fast convergence upon loss. enum QuicBandwidthLoMode : uint8_t { DEFAULT = 0,
diff --git a/quiche/quic/core/congestion_control/bbr3_sender.cc b/quiche/quic/core/congestion_control/bbr3_sender.cc index e024049..6a406bc 100644 --- a/quiche/quic/core/congestion_control/bbr3_sender.cc +++ b/quiche/quic/core/congestion_control/bbr3_sender.cc
@@ -176,6 +176,9 @@ // so ensure we're not ignoring it. params_.probe_up_ignore_inflight_hi = false; } + if (ContainsQuicTag(connection_options, kB3NP)) { + params_.enable_precautionary_probing = false; + } } Limits<QuicByteCount> Bbr3Sender::GetCwndLimitsByMode() const { @@ -321,7 +324,7 @@ if (mode_ == Bbr2Mode::PROBE_BW) { if (probe_bw_.phase == ProbePhase::PROBE_NOT_STARTED) { - EnterProbeDown(/*probed_too_high=*/false, /*stopped_risky_probe=*/false, + EnterProbeDown(/*probed_too_high=*/false, /*precautionary=*/false, event_time); } else { QUICHE_DCHECK(probe_bw_.phase == ProbePhase::PROBE_CRUISE || @@ -558,8 +561,7 @@ if (mode_ != prev_mode) { QUICHE_DCHECK_EQ(mode_, Bbr2Mode::PROBE_BW); if (probe_bw_.phase == ProbePhase::PROBE_NOT_STARTED) { - EnterProbeDown(/*probed_too_high=*/false, /*stopped_risky_probe=*/false, - now); + EnterProbeDown(/*probed_too_high=*/false, /*precautionary=*/false, now); } else { QUICHE_DCHECK(probe_bw_.phase == ProbePhase::PROBE_CRUISE || probe_bw_.phase == ProbePhase::PROBE_REFILL); @@ -776,25 +778,12 @@ const Bbr2CongestionEvent& congestion_event) { QUICHE_DCHECK_EQ(probe_bw_.phase, ProbePhase::PROBE_DOWN); - if (probe_bw_.rounds_in_phase == 1 && congestion_event.end_of_round_trip) { - probe_bw_.is_sample_from_probing = false; - - if (!congestion_event.last_packet_send_state.is_app_limited) { - QUIC_DVLOG(2) - << this << " Advancing max bw filter after one round in PROBE_DOWN."; - model_.AdvanceMaxBandwidthFilter(); - probe_bw_.has_advanced_max_bw = true; - } - - if (probe_bw_.last_cycle_stopped_risky_probe && - !probe_bw_.last_cycle_probed_too_high) { - EnterProbeRefill(/*probe_up_rounds=*/0, congestion_event.event_time); - return; - } - } - MaybeAdaptUpperBounds(congestion_event); + if (MaybeFinishBwProbeStopping(congestion_event)) { + return; + } + if (IsTimeToProbeBandwidth(congestion_event)) { EnterProbeRefill(/*probe_up_rounds=*/0, congestion_event.event_time); return; @@ -856,6 +845,7 @@ params_.probe_bw_full_loss_count)) { if (probe_bw_.is_sample_from_probing) { probe_bw_.is_sample_from_probing = false; + probe_bw_.prev_probe_too_high = true; if (!send_state.is_app_limited || params_.max_probe_up_queue_rounds > 0) { const QuicByteCount inflight_target = GetTargetBytesInflight() * (1.0 - params_.beta); @@ -904,6 +894,33 @@ return ADAPTED_OK; } +bool Bbr3Sender::MaybeFinishBwProbeStopping( + const Bbr2CongestionEvent& congestion_event) { + if (!probe_bw_.is_bw_probe_stopping || !congestion_event.end_of_round_trip || + probe_bw_.cycle_start_time == congestion_event.event_time) { + return false; + } + + probe_bw_.is_sample_from_probing = false; + probe_bw_.is_bw_probe_stopping = false; + + if (!probe_bw_.has_advanced_max_bw && + !congestion_event.last_packet_send_state.is_app_limited) { + QUIC_DVLOG(2) << this + << " Advancing max bw filter one round after stopping probe."; + model_.AdvanceMaxBandwidthFilter(); + probe_bw_.has_advanced_max_bw = true; + } + + // Precautionary Bandwidth Probing: Acceleration. + if (params_.enable_precautionary_probing && + probe_bw_.prev_probe_precautionary && !probe_bw_.prev_probe_too_high) { + EnterProbeRefill(/*probe_up_rounds=*/0, congestion_event.event_time); + return true; + } + return false; +} + bool Bbr3Sender::IsTimeToProbeBandwidth( const Bbr2CongestionEvent& congestion_event) const { if (HasCycleLasted(probe_bw_.probe_wait_time, congestion_event)) { @@ -1047,7 +1064,9 @@ const Bbr2CongestionEvent& congestion_event) { QUICHE_DCHECK_EQ(probe_bw_.phase, ProbePhase::PROBE_CRUISE); MaybeAdaptUpperBounds(congestion_event); - QUICHE_DCHECK(!probe_bw_.is_sample_from_probing); + if (MaybeFinishBwProbeStopping(congestion_event)) { + return; + } if (IsTimeToProbeBandwidth(congestion_event)) { EnterProbeRefill(/*probe_up_rounds=*/0, congestion_event.event_time); @@ -1070,24 +1089,28 @@ void Bbr3Sender::UpdateProbeUp(const Bbr2CongestionEvent& congestion_event) { QUICHE_DCHECK_EQ(probe_bw_.phase, ProbePhase::PROBE_UP); if (MaybeAdaptUpperBounds(congestion_event) == ADAPTED_PROBED_TOO_HIGH) { - EnterProbeDown(/*probed_too_high=*/true, /*stopped_risky_probe=*/false, + EnterProbeDown(/*probed_too_high=*/true, /*precautionary=*/false, + congestion_event.event_time); + return; + } + + // Precautionary Bandwidth Probing: Deceleration. + if (params_.enable_precautionary_probing && probe_bw_.prev_probe_too_high && + congestion_event.prior_bytes_in_flight >= model_.inflight_hi()) { + QUIC_DVLOG(3) << this << " Stopping precautionary probe at inflight_hi." + << " prev_probe_too_high:" << probe_bw_.prev_probe_too_high + << ", prior_in_flight:" + << congestion_event.prior_bytes_in_flight + << ", inflight_hi:" << model_.inflight_hi(); + EnterProbeDown(/*probed_too_high=*/false, /*precautionary=*/true, congestion_event.event_time); return; } ProbeInflightHighUpward(congestion_event); - bool is_risky = false; bool is_queuing = false; - if (probe_bw_.last_cycle_probed_too_high && - congestion_event.prior_bytes_in_flight >= model_.inflight_hi()) { - is_risky = true; - QUIC_DVLOG(3) << this << " Probe is too risky. last_cycle_probed_too_high:" - << probe_bw_.last_cycle_probed_too_high - << ", prior_in_flight:" - << congestion_event.prior_bytes_in_flight - << ", inflight_hi:" << model_.inflight_hi(); - } else if (probe_bw_.rounds_in_phase > 0) { + if (probe_bw_.rounds_in_phase > 0) { if (params_.max_probe_up_queue_rounds > 0) { if (congestion_event.end_of_round_trip) { model_.CheckPersistentQueue(congestion_event, @@ -1120,13 +1143,13 @@ } } - if (is_risky || is_queuing) { - EnterProbeDown(/*probed_too_high=*/false, /*stopped_risky_probe=*/is_risky, + if (is_queuing) { + EnterProbeDown(/*probed_too_high=*/false, /*precautionary=*/false, congestion_event.event_time); } } -void Bbr3Sender::EnterProbeDown(bool probed_too_high, bool stopped_risky_probe, +void Bbr3Sender::EnterProbeDown(bool probed_too_high, bool precautionary, QuicTime now) { QUIC_DVLOG(2) << this << " Phase change: " << ProbePhaseToString(probe_bw_.phase) @@ -1134,10 +1157,9 @@ << "PROBE_DOWN" << " after " << now - probe_bw_.phase_start_time << ", or " << probe_bw_.rounds_in_phase << " rounds. probed_too_high:" << probed_too_high - << ", stopped_risky_probe:" << stopped_risky_probe << " @ " - << now; - probe_bw_.last_cycle_probed_too_high = probed_too_high; - probe_bw_.last_cycle_stopped_risky_probe = stopped_risky_probe; + << ", precautionary:" << precautionary << " @ " << now; + probe_bw_.prev_probe_too_high = probed_too_high; + probe_bw_.prev_probe_precautionary = precautionary; probe_bw_.cycle_start_time = now; probe_bw_.phase = ProbePhase::PROBE_DOWN; @@ -1158,13 +1180,11 @@ probe_bw_.probe_up_bytes = std::numeric_limits<QuicByteCount>::max(); probe_bw_.has_advanced_max_bw = false; + probe_bw_.is_bw_probe_stopping = true; model_.RestartRoundEarly(); } void Bbr3Sender::EnterProbeCruise(QuicTime now) { - if (probe_bw_.phase == ProbePhase::PROBE_DOWN) { - ExitProbeDown(); - } QUIC_DVLOG(2) << this << " Phase change: " << ProbePhaseToString(probe_bw_.phase) << " ==> " @@ -1176,12 +1196,15 @@ probe_bw_.phase = ProbePhase::PROBE_CRUISE; probe_bw_.rounds_in_phase = 0; probe_bw_.phase_start_time = now; - probe_bw_.is_sample_from_probing = false; } void Bbr3Sender::EnterProbeRefill(uint64_t probe_up_rounds, QuicTime now) { - if (probe_bw_.phase == ProbePhase::PROBE_DOWN) { - ExitProbeDown(); + if ((probe_bw_.phase == ProbePhase::PROBE_DOWN || + probe_bw_.phase == ProbePhase::PROBE_CRUISE) && + !probe_bw_.has_advanced_max_bw && !probe_bw_.prev_probe_precautionary) { + QUIC_DVLOG(2) << this << " Advancing max bw filter at end of cycle."; + model_.AdvanceMaxBandwidthFilter(); + probe_bw_.has_advanced_max_bw = true; } QUIC_DVLOG(2) << this << " Phase change: " << ProbePhaseToString(probe_bw_.phase) @@ -1195,7 +1218,8 @@ probe_bw_.rounds_in_phase = 0; probe_bw_.phase_start_time = now; probe_bw_.is_sample_from_probing = false; - probe_bw_.last_cycle_stopped_risky_probe = false; + probe_bw_.is_bw_probe_stopping = false; + probe_bw_.prev_probe_precautionary = false; model_.clear_bandwidth_lo(); model_.clear_inflight_lo(); @@ -1221,19 +1245,13 @@ model_.RestartRoundEarly(); } -void Bbr3Sender::ExitProbeDown() { - QUICHE_DCHECK_EQ(probe_bw_.phase, ProbePhase::PROBE_DOWN); - if (!probe_bw_.has_advanced_max_bw) { - QUIC_DVLOG(2) << this << " Advancing max bw filter at end of cycle."; - model_.AdvanceMaxBandwidthFilter(); - probe_bw_.has_advanced_max_bw = true; - } -} - void Bbr3Sender::EnterProbeRtt() { model_.set_pacing_gain(1.0); model_.set_cwnd_gain(1.0); probe_rtt_.exit_time = QuicTime::Zero(); + probe_bw_.is_bw_probe_stopping = false; + probe_bw_.is_sample_from_probing = false; + probe_bw_.prev_probe_precautionary = false; } Bbr2Mode Bbr3Sender::OnCongestionEventProbeRtt(
diff --git a/quiche/quic/core/congestion_control/bbr3_sender.h b/quiche/quic/core/congestion_control/bbr3_sender.h index ab4243d..5c7d518 100644 --- a/quiche/quic/core/congestion_control/bbr3_sender.h +++ b/quiche/quic/core/congestion_control/bbr3_sender.h
@@ -150,13 +150,12 @@ AdaptUpperBoundsResult MaybeAdaptUpperBounds( const Bbr2CongestionEvent& congestion_event); + bool MaybeFinishBwProbeStopping(const Bbr2CongestionEvent& congestion_event); - void EnterProbeDown(bool probed_too_high, bool stopped_risky_probe, - QuicTime now); + void EnterProbeDown(bool probed_too_high, bool precautionary, QuicTime now); void EnterProbeCruise(QuicTime now); void EnterProbeRefill(uint64_t probe_up_rounds, QuicTime now); void EnterProbeUp(QuicTime now); - void ExitProbeDown(); bool IsTimeToProbeBandwidth( const Bbr2CongestionEvent& congestion_event) const; @@ -232,9 +231,10 @@ // advanced once per cycle. bool has_advanced_max_bw = false; bool is_sample_from_probing = false; + bool is_bw_probe_stopping = false; - bool last_cycle_probed_too_high = false; - bool last_cycle_stopped_risky_probe = false; + bool prev_probe_too_high = false; + bool prev_probe_precautionary = false; } probe_bw_; // Probe RTT state.
diff --git a/quiche/quic/core/congestion_control/bbrx_simulator_test.cc b/quiche/quic/core/congestion_control/bbrx_simulator_test.cc index b48dbcd..e90fdbf 100644 --- a/quiche/quic/core/congestion_control/bbrx_simulator_test.cc +++ b/quiche/quic/core/congestion_control/bbrx_simulator_test.cc
@@ -1649,6 +1649,451 @@ round_count_at_drain_entry + 3); } +TEST_P(Bbr3DefaultTopologyTest, SimpleTransferSmallBufferB3NP) { + SetConnectionOption(kB3NP); + EXPECT_FALSE(sender_params().enable_precautionary_probing); + DefaultTopologyParams params; + params.switch_queue_capacity_in_bdp = 0.5; + CreateNetwork(params); + + DoSimpleTransfer(12 * 1024 * 1024, QuicTime::Delta::FromSeconds(30)); + EXPECT_TRUE(Bbr2ModeIsOneOf({Bbr2Mode::PROBE_BW, Bbr2Mode::PROBE_RTT})); + EXPECT_APPROX_EQ(params.BottleneckBandwidth(), + sender_debug_state().bandwidth_hi, 0.02f); + EXPECT_FALSE(sender_debug_state().last_sample_is_app_limited); +} + +// Verify Precautionary Bandwidth Probing decelerates early at inflight_hi after +// a lossy probe, and immediately accelerates back to PROBE_REFILL -> PROBE_UP +// one round trip later (even if PROBE_DOWN transitioned to PROBE_CRUISE early) +// when no excessive loss occurs. +TEST_P(Bbr3DefaultTopologyTest, PrecautionaryProbingAcceleratesWhenSafe) { + DefaultTopologyParams params; + CreateNetwork(params); + DriveOutOfStartup(params); + + const QuicTime::Delta probe_wait = + sender_params().probe_bw_probe_base_duration + + sender_params().probe_bw_probe_max_rand_duration + + QuicTime::Delta::FromMilliseconds(100); + + AckedPacketVector acked_packets; + QuicPacketNumber acked_packet_number = + sender_unacked_map()->GetLeastUnacked(); + for (const auto& info : *sender_unacked_map()) { + acked_packets.emplace_back(acked_packet_number++, info.bytes_sent, + std::nullopt); + } + + // Advance time past probe_wait_time to enter PROBE_REFILL. + QuicTime now = SimulatedNow() + probe_wait; + QuicPacketNumber next_packet_number = + sender_unacked_map()->largest_sent_packet() + 1; + sender_->OnCongestionEvent( + /*rtt_updated=*/true, sender_unacked_map()->bytes_in_flight(), now, + acked_packets, {}, 0, 0); + ASSERT_EQ(ProbePhase::PROBE_REFILL, sender_debug_state().probe_bw.phase); + + // Send and ACK one packet to exit app-limited and enter PROBE_UP. + sender_->OnPacketSent(now, /*bytes_in_flight=*/0, next_packet_number++, + kDefaultMaxPacketSize, HAS_RETRANSMITTABLE_DATA); + now = now + params.RTT(); + sender_->OnCongestionEvent( + /*rtt_updated=*/true, kDefaultMaxPacketSize, now, + {AckedPacket(next_packet_number - 1, kDefaultMaxPacketSize, + std::nullopt)}, + {}, 0, 0); + ASSERT_EQ(ProbePhase::PROBE_UP, sender_debug_state().probe_bw.phase); + + // Send 5 non-app-limited packets: ACK the first to advance the round boundary + // to the 5th packet, then incur 2 loss events in that round to exit PROBE_UP + // due to excessive loss, setting inflight_hi and prev_probe_too_high. + for (uint64_t i = 0; i < 5; ++i) { + sender_->OnPacketSent(now, /*bytes_in_flight=*/i * kDefaultMaxPacketSize, + next_packet_number++, kDefaultMaxPacketSize, + HAS_RETRANSMITTABLE_DATA); + } + now = now + params.RTT() * 0.4; + sender_->OnCongestionEvent( + /*rtt_updated=*/true, 5 * kDefaultMaxPacketSize, now, + {AckedPacket(next_packet_number - 5, kDefaultMaxPacketSize, + std::nullopt)}, + {}, 0, 0); + ASSERT_EQ(ProbePhase::PROBE_UP, sender_debug_state().probe_bw.phase); + + now = now + params.RTT() * 0.1; + sender_->OnCongestionEvent( + /*rtt_updated=*/true, 4 * kDefaultMaxPacketSize, now, + {AckedPacket(next_packet_number - 3, kDefaultMaxPacketSize, + std::nullopt)}, + {LostPacket(next_packet_number - 4, kDefaultMaxPacketSize)}, 0, 0); + ASSERT_EQ(ProbePhase::PROBE_UP, sender_debug_state().probe_bw.phase); + + now = now + params.RTT() * 0.1; + sender_->OnCongestionEvent( + /*rtt_updated=*/true, 2 * kDefaultMaxPacketSize, now, + {AckedPacket(next_packet_number - 1, kDefaultMaxPacketSize, + std::nullopt)}, + {LostPacket(next_packet_number - 2, kDefaultMaxPacketSize)}, 0, 0); + ASSERT_EQ(ProbePhase::PROBE_DOWN, sender_debug_state().probe_bw.phase); + + const QuicByteCount inflight_hi = sender_debug_state().inflight_hi; + ASSERT_LT(inflight_hi, Bbr2NetworkModel::inflight_hi_default()); + ASSERT_LT(inflight_hi, params.BDP()); + + // Advance past probe_wait_time to enter the next PROBE_REFILL -> PROBE_UP. + now = now + probe_wait; + sender_->OnPacketSent(now, /*bytes_in_flight=*/0, next_packet_number++, + kDefaultMaxPacketSize, HAS_RETRANSMITTABLE_DATA); + now = now + params.RTT(); + sender_->OnCongestionEvent( + /*rtt_updated=*/true, kDefaultMaxPacketSize, now, + {AckedPacket(next_packet_number - 1, kDefaultMaxPacketSize, + std::nullopt)}, + {}, 0, 0); + ASSERT_EQ(ProbePhase::PROBE_REFILL, sender_debug_state().probe_bw.phase); + + sender_->OnPacketSent(now, /*bytes_in_flight=*/0, next_packet_number++, + kDefaultMaxPacketSize, HAS_RETRANSMITTABLE_DATA); + now = now + params.RTT(); + sender_->OnCongestionEvent( + /*rtt_updated=*/true, kDefaultMaxPacketSize, now, + {AckedPacket(next_packet_number - 1, kDefaultMaxPacketSize, + std::nullopt)}, + {}, 0, 0); + ASSERT_EQ(ProbePhase::PROBE_UP, sender_debug_state().probe_bw.phase); + + // Send enough packets to reach inflight_hi. + const uint64_t packets_for_inflight_hi = + (inflight_hi + kDefaultMaxPacketSize - 1) / kDefaultMaxPacketSize; + const QuicPacketNumber first_probe_packet = next_packet_number; + for (uint64_t i = 0; i < packets_for_inflight_hi; ++i) { + sender_->OnPacketSent(now, /*bytes_in_flight=*/i * kDefaultMaxPacketSize, + next_packet_number++, kDefaultMaxPacketSize, + HAS_RETRANSMITTABLE_DATA); + } + QuicByteCount bytes_in_flight = + packets_for_inflight_hi * kDefaultMaxPacketSize; + + // Precautionary Bandwidth Probing: Deceleration stops PROBE_UP immediately + // once prior_bytes_in_flight >= inflight_hi. + now = now + params.RTT() * 0.5; + sender_->OnCongestionEvent( + /*rtt_updated=*/true, bytes_in_flight, now, + {AckedPacket(first_probe_packet, kDefaultMaxPacketSize, std::nullopt)}, + {}, 0, 0); + bytes_in_flight -= kDefaultMaxPacketSize; + ASSERT_EQ(ProbePhase::PROBE_DOWN, sender_debug_state().probe_bw.phase); + + // Send one sentinel packet in PROBE_DOWN, then ACK the rest of the probe + // flight so bytes_in_flight drains and transitions early to PROBE_CRUISE. + const QuicPacketNumber post_stop_packet = next_packet_number++; + sender_->OnPacketSent(now, bytes_in_flight, post_stop_packet, + kDefaultMaxPacketSize, HAS_RETRANSMITTABLE_DATA); + bytes_in_flight += kDefaultMaxPacketSize; + + AckedPacketVector remaining_probe_acks; + for (uint64_t i = 1; i < packets_for_inflight_hi; ++i) { + remaining_probe_acks.emplace_back(first_probe_packet + i, + kDefaultMaxPacketSize, std::nullopt); + } + now = now + params.RTT() * 0.2; + sender_->OnCongestionEvent(/*rtt_updated=*/true, bytes_in_flight, now, + remaining_probe_acks, {}, 0, 0); + bytes_in_flight = kDefaultMaxPacketSize; + ASSERT_EQ(ProbePhase::PROBE_CRUISE, sender_debug_state().probe_bw.phase); + + // Completing the round trip without excessive loss triggers Precautionary + // Bandwidth Probing: Acceleration directly into PROBE_REFILL. + now = now + params.RTT() * 0.8; + sender_->OnCongestionEvent( + /*rtt_updated=*/true, bytes_in_flight, now, + {AckedPacket(post_stop_packet, kDefaultMaxPacketSize, std::nullopt)}, {}, + 0, 0); + ASSERT_EQ(ProbePhase::PROBE_REFILL, sender_debug_state().probe_bw.phase); + + // Advance one round into the follow-up PROBE_UP and verify it now persists + // at inflight_hi instead of stopping early. + sender_->OnPacketSent(now, /*bytes_in_flight=*/0, next_packet_number++, + kDefaultMaxPacketSize, HAS_RETRANSMITTABLE_DATA); + now = now + params.RTT(); + sender_->OnCongestionEvent( + /*rtt_updated=*/true, kDefaultMaxPacketSize, now, + {AckedPacket(next_packet_number - 1, kDefaultMaxPacketSize, + std::nullopt)}, + {}, 0, 0); + ASSERT_EQ(ProbePhase::PROBE_UP, sender_debug_state().probe_bw.phase); + + const QuicPacketNumber second_probe_first_packet = next_packet_number; + for (uint64_t i = 0; i < packets_for_inflight_hi; ++i) { + sender_->OnPacketSent(now, /*bytes_in_flight=*/i * kDefaultMaxPacketSize, + next_packet_number++, kDefaultMaxPacketSize, + HAS_RETRANSMITTABLE_DATA); + } + now = now + params.RTT() * 0.5; + sender_->OnCongestionEvent( + /*rtt_updated=*/true, packets_for_inflight_hi * kDefaultMaxPacketSize, + now, + {AckedPacket(second_probe_first_packet, kDefaultMaxPacketSize, + std::nullopt)}, + {}, 0, 0); + EXPECT_EQ(ProbePhase::PROBE_UP, sender_debug_state().probe_bw.phase); +} + +// Verify Precautionary Bandwidth Probing does NOT re-accelerate into +// PROBE_REFILL if the precautionary probe itself suffers excessive loss +// detected after transitioning out of PROBE_UP. +TEST_P(Bbr3DefaultTopologyTest, PrecautionaryProbingDoesNotAccelerateOnLoss) { + DefaultTopologyParams params; + CreateNetwork(params); + DriveOutOfStartup(params); + + const QuicTime::Delta probe_wait = + sender_params().probe_bw_probe_base_duration + + sender_params().probe_bw_probe_max_rand_duration + + QuicTime::Delta::FromMilliseconds(100); + + AckedPacketVector acked_packets; + QuicPacketNumber acked_packet_number = + sender_unacked_map()->GetLeastUnacked(); + for (const auto& info : *sender_unacked_map()) { + acked_packets.emplace_back(acked_packet_number++, info.bytes_sent, + std::nullopt); + } + + QuicTime now = SimulatedNow() + probe_wait; + QuicPacketNumber next_packet_number = + sender_unacked_map()->largest_sent_packet() + 1; + sender_->OnCongestionEvent( + /*rtt_updated=*/true, sender_unacked_map()->bytes_in_flight(), now, + acked_packets, {}, 0, 0); + ASSERT_EQ(ProbePhase::PROBE_REFILL, sender_debug_state().probe_bw.phase); + + sender_->OnPacketSent(now, /*bytes_in_flight=*/0, next_packet_number++, + kDefaultMaxPacketSize, HAS_RETRANSMITTABLE_DATA); + now = now + params.RTT(); + sender_->OnCongestionEvent( + /*rtt_updated=*/true, kDefaultMaxPacketSize, now, + {AckedPacket(next_packet_number - 1, kDefaultMaxPacketSize, + std::nullopt)}, + {}, 0, 0); + ASSERT_EQ(ProbePhase::PROBE_UP, sender_debug_state().probe_bw.phase); + + // Trigger excessive loss in PROBE_UP to set inflight_hi and + // prev_probe_too_high. + for (uint64_t i = 0; i < 5; ++i) { + sender_->OnPacketSent(now, /*bytes_in_flight=*/i * kDefaultMaxPacketSize, + next_packet_number++, kDefaultMaxPacketSize, + HAS_RETRANSMITTABLE_DATA); + } + now = now + params.RTT() * 0.4; + sender_->OnCongestionEvent( + /*rtt_updated=*/true, 5 * kDefaultMaxPacketSize, now, + {AckedPacket(next_packet_number - 5, kDefaultMaxPacketSize, + std::nullopt)}, + {}, 0, 0); + now = now + params.RTT() * 0.1; + sender_->OnCongestionEvent( + /*rtt_updated=*/true, 4 * kDefaultMaxPacketSize, now, + {AckedPacket(next_packet_number - 3, kDefaultMaxPacketSize, + std::nullopt)}, + {LostPacket(next_packet_number - 4, kDefaultMaxPacketSize)}, 0, 0); + now = now + params.RTT() * 0.1; + sender_->OnCongestionEvent( + /*rtt_updated=*/true, 2 * kDefaultMaxPacketSize, now, + {AckedPacket(next_packet_number - 1, kDefaultMaxPacketSize, + std::nullopt)}, + {LostPacket(next_packet_number - 2, kDefaultMaxPacketSize)}, 0, 0); + ASSERT_EQ(ProbePhase::PROBE_DOWN, sender_debug_state().probe_bw.phase); + const QuicByteCount inflight_hi = sender_debug_state().inflight_hi; + + // Enter the next PROBE_REFILL -> PROBE_UP. + now = now + probe_wait; + sender_->OnPacketSent(now, /*bytes_in_flight=*/0, next_packet_number++, + kDefaultMaxPacketSize, HAS_RETRANSMITTABLE_DATA); + now = now + params.RTT(); + sender_->OnCongestionEvent( + /*rtt_updated=*/true, kDefaultMaxPacketSize, now, + {AckedPacket(next_packet_number - 1, kDefaultMaxPacketSize, + std::nullopt)}, + {}, 0, 0); + ASSERT_EQ(ProbePhase::PROBE_REFILL, sender_debug_state().probe_bw.phase); + + sender_->OnPacketSent(now, /*bytes_in_flight=*/0, next_packet_number++, + kDefaultMaxPacketSize, HAS_RETRANSMITTABLE_DATA); + now = now + params.RTT(); + sender_->OnCongestionEvent( + /*rtt_updated=*/true, kDefaultMaxPacketSize, now, + {AckedPacket(next_packet_number - 1, kDefaultMaxPacketSize, + std::nullopt)}, + {}, 0, 0); + ASSERT_EQ(ProbePhase::PROBE_UP, sender_debug_state().probe_bw.phase); + + // Reach inflight_hi to trigger Precautionary Deceleration into PROBE_DOWN. + const uint64_t packets_for_inflight_hi = + (inflight_hi + kDefaultMaxPacketSize - 1) / kDefaultMaxPacketSize; + ASSERT_GE(packets_for_inflight_hi, 5u); + const QuicPacketNumber first_probe_packet = next_packet_number; + for (uint64_t i = 0; i < packets_for_inflight_hi; ++i) { + sender_->OnPacketSent(now, /*bytes_in_flight=*/i * kDefaultMaxPacketSize, + next_packet_number++, kDefaultMaxPacketSize, + HAS_RETRANSMITTABLE_DATA); + } + QuicByteCount bytes_in_flight = + packets_for_inflight_hi * kDefaultMaxPacketSize; + + now = now + params.RTT() * 0.5; + sender_->OnCongestionEvent( + /*rtt_updated=*/true, bytes_in_flight, now, + {AckedPacket(first_probe_packet, kDefaultMaxPacketSize, std::nullopt)}, + {}, 0, 0); + bytes_in_flight -= kDefaultMaxPacketSize; + ASSERT_EQ(ProbePhase::PROBE_DOWN, sender_debug_state().probe_bw.phase); + + const QuicPacketNumber post_stop_packet = next_packet_number++; + sender_->OnPacketSent(now, bytes_in_flight, post_stop_packet, + kDefaultMaxPacketSize, HAS_RETRANSMITTABLE_DATA); + bytes_in_flight += kDefaultMaxPacketSize; + + // Report 2 loss events (>2% loss) on the packets sent during the + // precautionary probe while in PROBE_DOWN. + now = now + params.RTT() * 0.1; + sender_->OnCongestionEvent( + /*rtt_updated=*/true, bytes_in_flight, now, + {AckedPacket(first_probe_packet + 2, kDefaultMaxPacketSize, + std::nullopt)}, + {LostPacket(first_probe_packet + 1, kDefaultMaxPacketSize)}, 0, 0); + bytes_in_flight -= 2 * kDefaultMaxPacketSize; + + AckedPacketVector remaining_probe_acks; + for (uint64_t i = 4; i < packets_for_inflight_hi; ++i) { + remaining_probe_acks.emplace_back(first_probe_packet + i, + kDefaultMaxPacketSize, std::nullopt); + } + now = now + params.RTT() * 0.1; + sender_->OnCongestionEvent( + /*rtt_updated=*/true, bytes_in_flight, now, remaining_probe_acks, + {LostPacket(first_probe_packet + 3, kDefaultMaxPacketSize)}, 0, 0); + bytes_in_flight = kDefaultMaxPacketSize; + + // Finish the stopping round: because the precautionary probe suffered excess + // loss, BBRv3 must stay in PROBE_CRUISE rather than re-entering PROBE_REFILL. + now = now + params.RTT() * 0.8; + sender_->OnCongestionEvent( + /*rtt_updated=*/true, bytes_in_flight, now, + {AckedPacket(post_stop_packet, kDefaultMaxPacketSize, std::nullopt)}, {}, + 0, 0); + EXPECT_EQ(ProbePhase::PROBE_CRUISE, sender_debug_state().probe_bw.phase); +} + +// Verify the B3NP connection option disables Precautionary Bandwidth Probing. +TEST_P(Bbr3DefaultTopologyTest, PrecautionaryProbingDisabledByB3NP) { + SetConnectionOption(kB3NP); + ASSERT_FALSE(sender_params().enable_precautionary_probing); + + DefaultTopologyParams params; + CreateNetwork(params); + DriveOutOfStartup(params); + + const QuicTime::Delta probe_wait = + sender_params().probe_bw_probe_base_duration + + sender_params().probe_bw_probe_max_rand_duration + + QuicTime::Delta::FromMilliseconds(100); + + AckedPacketVector acked_packets; + QuicPacketNumber acked_packet_number = + sender_unacked_map()->GetLeastUnacked(); + for (const auto& info : *sender_unacked_map()) { + acked_packets.emplace_back(acked_packet_number++, info.bytes_sent, + std::nullopt); + } + + QuicTime now = SimulatedNow() + probe_wait; + QuicPacketNumber next_packet_number = + sender_unacked_map()->largest_sent_packet() + 1; + sender_->OnCongestionEvent( + /*rtt_updated=*/true, sender_unacked_map()->bytes_in_flight(), now, + acked_packets, {}, 0, 0); + ASSERT_EQ(ProbePhase::PROBE_REFILL, sender_debug_state().probe_bw.phase); + + sender_->OnPacketSent(now, /*bytes_in_flight=*/0, next_packet_number++, + kDefaultMaxPacketSize, HAS_RETRANSMITTABLE_DATA); + now = now + params.RTT(); + sender_->OnCongestionEvent( + /*rtt_updated=*/true, kDefaultMaxPacketSize, now, + {AckedPacket(next_packet_number - 1, kDefaultMaxPacketSize, + std::nullopt)}, + {}, 0, 0); + ASSERT_EQ(ProbePhase::PROBE_UP, sender_debug_state().probe_bw.phase); + + // Trigger excessive loss in PROBE_UP to set inflight_hi and + // prev_probe_too_high. + for (uint64_t i = 0; i < 5; ++i) { + sender_->OnPacketSent(now, /*bytes_in_flight=*/i * kDefaultMaxPacketSize, + next_packet_number++, kDefaultMaxPacketSize, + HAS_RETRANSMITTABLE_DATA); + } + now = now + params.RTT() * 0.4; + sender_->OnCongestionEvent( + /*rtt_updated=*/true, 5 * kDefaultMaxPacketSize, now, + {AckedPacket(next_packet_number - 5, kDefaultMaxPacketSize, + std::nullopt)}, + {}, 0, 0); + now = now + params.RTT() * 0.1; + sender_->OnCongestionEvent( + /*rtt_updated=*/true, 4 * kDefaultMaxPacketSize, now, + {AckedPacket(next_packet_number - 3, kDefaultMaxPacketSize, + std::nullopt)}, + {LostPacket(next_packet_number - 4, kDefaultMaxPacketSize)}, 0, 0); + now = now + params.RTT() * 0.1; + sender_->OnCongestionEvent( + /*rtt_updated=*/true, 2 * kDefaultMaxPacketSize, now, + {AckedPacket(next_packet_number - 1, kDefaultMaxPacketSize, + std::nullopt)}, + {LostPacket(next_packet_number - 2, kDefaultMaxPacketSize)}, 0, 0); + ASSERT_EQ(ProbePhase::PROBE_DOWN, sender_debug_state().probe_bw.phase); + const QuicByteCount inflight_hi = sender_debug_state().inflight_hi; + + // Enter the next PROBE_REFILL -> PROBE_UP. + now = now + probe_wait; + sender_->OnPacketSent(now, /*bytes_in_flight=*/0, next_packet_number++, + kDefaultMaxPacketSize, HAS_RETRANSMITTABLE_DATA); + now = now + params.RTT(); + sender_->OnCongestionEvent( + /*rtt_updated=*/true, kDefaultMaxPacketSize, now, + {AckedPacket(next_packet_number - 1, kDefaultMaxPacketSize, + std::nullopt)}, + {}, 0, 0); + ASSERT_EQ(ProbePhase::PROBE_REFILL, sender_debug_state().probe_bw.phase); + + sender_->OnPacketSent(now, /*bytes_in_flight=*/0, next_packet_number++, + kDefaultMaxPacketSize, HAS_RETRANSMITTABLE_DATA); + now = now + params.RTT(); + sender_->OnCongestionEvent( + /*rtt_updated=*/true, kDefaultMaxPacketSize, now, + {AckedPacket(next_packet_number - 1, kDefaultMaxPacketSize, + std::nullopt)}, + {}, 0, 0); + ASSERT_EQ(ProbePhase::PROBE_UP, sender_debug_state().probe_bw.phase); + + // Reach inflight_hi: with B3NP set, BBRv3 must NOT exit PROBE_UP early. + const uint64_t packets_for_inflight_hi = + (inflight_hi + kDefaultMaxPacketSize - 1) / kDefaultMaxPacketSize; + const QuicPacketNumber first_probe_packet = next_packet_number; + for (uint64_t i = 0; i < packets_for_inflight_hi; ++i) { + sender_->OnPacketSent(now, /*bytes_in_flight=*/i * kDefaultMaxPacketSize, + next_packet_number++, kDefaultMaxPacketSize, + HAS_RETRANSMITTABLE_DATA); + } + now = now + params.RTT() * 0.5; + sender_->OnCongestionEvent( + /*rtt_updated=*/true, packets_for_inflight_hi * kDefaultMaxPacketSize, + now, + {AckedPacket(first_probe_packet, kDefaultMaxPacketSize, std::nullopt)}, + {}, 0, 0); + EXPECT_EQ(ProbePhase::PROBE_UP, sender_debug_state().probe_bw.phase); +} + // Ensure that a connection that is app-limited and is at sufficiently low // bandwidth will not exit high gain phase, and similarly ensure that the // connection will exit low gain early if the number of bytes in flight is low.
diff --git a/quiche/quic/core/crypto/crypto_protocol.h b/quiche/quic/core/crypto/crypto_protocol.h index 009b032..6affa82 100644 --- a/quiche/quic/core/crypto/crypto_protocol.h +++ b/quiche/quic/core/crypto/crypto_protocol.h
@@ -198,6 +198,8 @@ DEFINE_STATIC_QUIC_TAG(BB2S); // Exit STARTUP on // min_bytes_in_flight for two // rounds in a row. +DEFINE_STATIC_QUIC_TAG(B3NP); // For BBRv3, disable precautionary + // bandwidth probing. DEFINE_STATIC_QUIC_TAG(NTLP); // No tail loss probe DEFINE_STATIC_QUIC_TAG(1TLP); // 1 tail loss probe DEFINE_STATIC_QUIC_TAG(1RTO); // Send 1 packet upon RTO