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_drain.h"
6
7 #include "quiche/quic/core/congestion_control/bbr2_sender.h"
8 #include "quiche/quic/platform/api/quic_logging.h"
9
10 namespace quic {
11
OnCongestionEvent(QuicByteCount,QuicTime,const AckedPacketVector &,const LostPacketVector &,const Bbr2CongestionEvent & congestion_event)12 Bbr2Mode Bbr2DrainMode::OnCongestionEvent(
13 QuicByteCount /*prior_in_flight*/, QuicTime /*event_time*/,
14 const AckedPacketVector& /*acked_packets*/,
15 const LostPacketVector& /*lost_packets*/,
16 const Bbr2CongestionEvent& congestion_event) {
17 model_->set_pacing_gain(Params().drain_pacing_gain);
18
19 // Only STARTUP can transition to DRAIN, both of them use the same cwnd gain.
20 QUICHE_DCHECK_EQ(model_->cwnd_gain(), Params().drain_cwnd_gain);
21 model_->set_cwnd_gain(Params().drain_cwnd_gain);
22
23 QuicByteCount drain_target = DrainTarget();
24 if (congestion_event.bytes_in_flight <= drain_target) {
25 QUIC_DVLOG(3) << sender_ << " Exiting DRAIN. bytes_in_flight:"
26 << congestion_event.bytes_in_flight
27 << ", bdp:" << model_->BDP()
28 << ", drain_target:" << drain_target << " @ "
29 << congestion_event.event_time;
30 return Bbr2Mode::PROBE_BW;
31 }
32
33 QUIC_DVLOG(3) << sender_ << " Staying in DRAIN. bytes_in_flight:"
34 << congestion_event.bytes_in_flight << ", bdp:" << model_->BDP()
35 << ", drain_target:" << drain_target << " @ "
36 << congestion_event.event_time;
37 return Bbr2Mode::DRAIN;
38 }
39
DrainTarget() const40 QuicByteCount Bbr2DrainMode::DrainTarget() const {
41 QuicByteCount bdp = model_->BDP();
42 return std::max<QuicByteCount>(bdp, sender_->GetMinimumCongestionWindow());
43 }
44
ExportDebugState() const45 Bbr2DrainMode::DebugState Bbr2DrainMode::ExportDebugState() const {
46 DebugState s;
47 s.drain_target = DrainTarget();
48 return s;
49 }
50
operator <<(std::ostream & os,const Bbr2DrainMode::DebugState & state)51 std::ostream& operator<<(std::ostream& os,
52 const Bbr2DrainMode::DebugState& state) {
53 os << "[DRAIN] drain_target: " << state.drain_target << "\n";
54 return os;
55 }
56
Params() const57 const Bbr2Params& Bbr2DrainMode::Params() const { return sender_->Params(); }
58
59 } // namespace quic
60