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 "net/third_party/quiche/src/quic/core/congestion_control/bbr2_probe_rtt.h"
6
7 #include "net/third_party/quiche/src/quic/core/congestion_control/bbr2_sender.h"
8 #include "net/third_party/quiche/src/quic/core/quic_time.h"
9 #include "net/third_party/quiche/src/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*/,
22 QuicTime /*event_time*/,
23 const AckedPacketVector& /*acked_packets*/,
24 const LostPacketVector& /*lost_packets*/,
25 const Bbr2CongestionEvent& congestion_event) {
26 if (exit_time_ == QuicTime::Zero()) {
27 if (congestion_event.bytes_in_flight <= InflightTarget() ||
28 congestion_event.bytes_in_flight <=
29 sender_->GetMinimumCongestionWindow()) {
30 exit_time_ = congestion_event.event_time + Params().probe_rtt_duration;
31 QUIC_DVLOG(2) << sender_ << " PROBE_RTT exit time set to " << exit_time_
32 << ". bytes_inflight:" << congestion_event.bytes_in_flight
33 << ", inflight_target:" << InflightTarget()
34 << ", min_congestion_window:"
35 << sender_->GetMinimumCongestionWindow() << " @ "
36 << congestion_event.event_time;
37 }
38 return Bbr2Mode::PROBE_RTT;
39 }
40
41 return congestion_event.event_time > exit_time_ ? Bbr2Mode::PROBE_BW
42 : Bbr2Mode::PROBE_RTT;
43 }
44
InflightTarget() const45 QuicByteCount Bbr2ProbeRttMode::InflightTarget() const {
46 return model_->BDP(model_->MaxBandwidth(),
47 Params().probe_rtt_inflight_target_bdp_fraction);
48 }
49
GetCwndLimits() const50 Limits<QuicByteCount> Bbr2ProbeRttMode::GetCwndLimits() const {
51 QuicByteCount inflight_upper_bound =
52 std::min(model_->inflight_lo(), model_->inflight_hi_with_headroom());
53 return NoGreaterThan(std::min(inflight_upper_bound, InflightTarget()));
54 }
55
OnExitQuiescence(QuicTime now,QuicTime)56 Bbr2Mode Bbr2ProbeRttMode::OnExitQuiescence(
57 QuicTime now,
58 QuicTime /*quiescence_start_time*/) {
59 if (now > exit_time_) {
60 return Bbr2Mode::PROBE_BW;
61 }
62 return Bbr2Mode::PROBE_RTT;
63 }
64
ExportDebugState() const65 Bbr2ProbeRttMode::DebugState Bbr2ProbeRttMode::ExportDebugState() const {
66 DebugState s;
67 s.inflight_target = InflightTarget();
68 s.exit_time = exit_time_;
69 return s;
70 }
71
operator <<(std::ostream & os,const Bbr2ProbeRttMode::DebugState & state)72 std::ostream& operator<<(std::ostream& os,
73 const Bbr2ProbeRttMode::DebugState& state) {
74 os << "[PROBE_RTT] inflight_target: " << state.inflight_target << "\n";
75 os << "[PROBE_RTT] exit_time: " << state.exit_time << "\n";
76 return os;
77 }
78
Params() const79 const Bbr2Params& Bbr2ProbeRttMode::Params() const {
80 return sender_->Params();
81 }
82
83 } // namespace quic
84