1 // Copyright 2019 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "quiche/quic/core/congestion_control/bbr2_probe_rtt.h"
6
7 #include "quiche/quic/core/congestion_control/bbr2_sender.h"
8 #include "quiche/quic/core/quic_time.h"
9 #include "quiche/quic/platform/api/quic_logging.h"
10
11 namespace quic {
12
Enter(QuicTime,const Bbr2CongestionEvent *)13 void Bbr2ProbeRttMode::Enter(QuicTime /*now*/,
14 const Bbr2CongestionEvent* /*congestion_event*/) {
15 model_->set_pacing_gain(1.0);
16 model_->set_cwnd_gain(1.0);
17 exit_time_ = QuicTime::Zero();
18 }
19
OnCongestionEvent(QuicByteCount,QuicTime,const AckedPacketVector &,const LostPacketVector &,const Bbr2CongestionEvent & congestion_event)20 Bbr2Mode Bbr2ProbeRttMode::OnCongestionEvent(
21 QuicByteCount /*prior_in_flight*/, QuicTime /*event_time*/,
22 const AckedPacketVector& /*acked_packets*/,
23 const LostPacketVector& /*lost_packets*/,
24 const Bbr2CongestionEvent& congestion_event) {
25 if (exit_time_ == QuicTime::Zero()) {
26 if (congestion_event.bytes_in_flight <= InflightTarget() ||
27 congestion_event.bytes_in_flight <=
28 sender_->GetMinimumCongestionWindow()) {
29 exit_time_ = congestion_event.event_time + Params().probe_rtt_duration;
30 QUIC_DVLOG(2) << sender_ << " PROBE_RTT exit time set to " << exit_time_
31 << ". bytes_inflight:" << congestion_event.bytes_in_flight
32 << ", inflight_target:" << InflightTarget()
33 << ", min_congestion_window:"
34 << sender_->GetMinimumCongestionWindow() << " @ "
35 << congestion_event.event_time;
36 }
37 return Bbr2Mode::PROBE_RTT;
38 }
39
40 return congestion_event.event_time > exit_time_ ? Bbr2Mode::PROBE_BW
41 : Bbr2Mode::PROBE_RTT;
42 }
43
InflightTarget() const44 QuicByteCount Bbr2ProbeRttMode::InflightTarget() const {
45 return model_->BDP(model_->MaxBandwidth(),
46 Params().probe_rtt_inflight_target_bdp_fraction);
47 }
48
GetCwndLimits() const49 Limits<QuicByteCount> Bbr2ProbeRttMode::GetCwndLimits() const {
50 QuicByteCount inflight_upper_bound =
51 std::min(model_->inflight_lo(), model_->inflight_hi_with_headroom());
52 return NoGreaterThan(std::min(inflight_upper_bound, InflightTarget()));
53 }
54
OnExitQuiescence(QuicTime now,QuicTime)55 Bbr2Mode Bbr2ProbeRttMode::OnExitQuiescence(
56 QuicTime now, QuicTime /*quiescence_start_time*/) {
57 if (now > exit_time_) {
58 return Bbr2Mode::PROBE_BW;
59 }
60 return Bbr2Mode::PROBE_RTT;
61 }
62
ExportDebugState() const63 Bbr2ProbeRttMode::DebugState Bbr2ProbeRttMode::ExportDebugState() const {
64 DebugState s;
65 s.inflight_target = InflightTarget();
66 s.exit_time = exit_time_;
67 return s;
68 }
69
operator <<(std::ostream & os,const Bbr2ProbeRttMode::DebugState & state)70 std::ostream& operator<<(std::ostream& os,
71 const Bbr2ProbeRttMode::DebugState& state) {
72 os << "[PROBE_RTT] inflight_target: " << state.inflight_target << "\n";
73 os << "[PROBE_RTT] exit_time: " << state.exit_time << "\n";
74 return os;
75 }
76
Params() const77 const Bbr2Params& Bbr2ProbeRttMode::Params() const { return sender_->Params(); }
78
79 } // namespace quic
80