blob: 4b2fac8c716c5ae598a8542ff18e8346a3de6e5c [file] [log] [blame]
QUICHE team7872c772019-07-23 10:19:37 -04001// 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_sender.h"
6
7#include <cstddef>
8
9#include "net/third_party/quiche/src/quic/core/congestion_control/bandwidth_sampler.h"
10#include "net/third_party/quiche/src/quic/core/congestion_control/bbr2_drain.h"
11#include "net/third_party/quiche/src/quic/core/congestion_control/bbr2_misc.h"
12#include "net/third_party/quiche/src/quic/core/crypto/crypto_protocol.h"
13#include "net/third_party/quiche/src/quic/core/quic_bandwidth.h"
14#include "net/third_party/quiche/src/quic/core/quic_types.h"
wube4df93b2020-03-02 17:55:23 -080015#include "net/third_party/quiche/src/quic/platform/api/quic_flag_utils.h"
QUICHE team7872c772019-07-23 10:19:37 -040016#include "net/third_party/quiche/src/quic/platform/api/quic_logging.h"
17
18namespace quic {
19
20namespace {
21// Constants based on TCP defaults.
22// The minimum CWND to ensure delayed acks don't reduce bandwidth measurements.
23// Does not inflate the pacing rate.
24const QuicByteCount kDefaultMinimumCongestionWindow = 4 * kMaxSegmentSize;
25
26const float kInitialPacingGain = 2.885f;
27
28const int kMaxModeChangesPerCongestionEvent = 4;
29} // namespace
30
31// Call |member_function_call| based on the current Bbr2Mode we are in. e.g.
32//
33// auto result = BBR2_MODE_DISPATCH(Foo());
34//
35// is equivalent to:
36//
37// Bbr2ModeBase& Bbr2Sender::GetCurrentMode() {
38// if (mode_ == Bbr2Mode::STARTUP) { return startup_; }
39// if (mode_ == Bbr2Mode::DRAIN) { return drain_; }
40// ...
41// }
42// auto result = GetCurrentMode().Foo();
43//
44// Except that BBR2_MODE_DISPATCH guarantees the call to Foo() is non-virtual.
45//
46#define BBR2_MODE_DISPATCH(member_function_call) \
47 (mode_ == Bbr2Mode::STARTUP \
48 ? (startup_.member_function_call) \
49 : (mode_ == Bbr2Mode::PROBE_BW \
50 ? (probe_bw_.member_function_call) \
51 : (mode_ == Bbr2Mode::DRAIN \
52 ? (drain_.member_function_call) \
53 : (probe_rtt_or_die().member_function_call))))
54
55Bbr2Sender::Bbr2Sender(QuicTime now,
56 const RttStats* rtt_stats,
57 const QuicUnackedPacketMap* unacked_packets,
58 QuicPacketCount initial_cwnd_in_packets,
59 QuicPacketCount max_cwnd_in_packets,
60 QuicRandom* random,
wub0abcd8f2020-03-30 16:24:50 -070061 QuicConnectionStats* stats,
62 BbrSender* old_sender)
QUICHE team7872c772019-07-23 10:19:37 -040063 : mode_(Bbr2Mode::STARTUP),
64 rtt_stats_(rtt_stats),
65 unacked_packets_(unacked_packets),
66 random_(random),
wubbe29b9e2019-11-24 06:56:04 -080067 connection_stats_(stats),
QUICHE team7872c772019-07-23 10:19:37 -040068 params_(kDefaultMinimumCongestionWindow,
69 max_cwnd_in_packets * kDefaultTCPMSS),
70 model_(&params_,
71 rtt_stats->SmoothedOrInitialRtt(),
72 rtt_stats->last_update_time(),
73 /*cwnd_gain=*/1.0,
wub0abcd8f2020-03-30 16:24:50 -070074 /*pacing_gain=*/kInitialPacingGain,
75 old_sender ? &old_sender->sampler_ : nullptr),
wub7652d412019-08-13 15:11:40 -070076 initial_cwnd_(
QUICHE team7872c772019-07-23 10:19:37 -040077 cwnd_limits().ApplyLimits(initial_cwnd_in_packets * kDefaultTCPMSS)),
wub7652d412019-08-13 15:11:40 -070078 cwnd_(initial_cwnd_),
QUICHE team7872c772019-07-23 10:19:37 -040079 pacing_rate_(kInitialPacingGain * QuicBandwidth::FromBytesAndTimeDelta(
80 cwnd_,
81 rtt_stats->SmoothedOrInitialRtt())),
wubbe29b9e2019-11-24 06:56:04 -080082 startup_(this, &model_, now),
QUICHE team7872c772019-07-23 10:19:37 -040083 drain_(this, &model_),
84 probe_bw_(this, &model_),
85 probe_rtt_(this, &model_),
QUICHE team7872c772019-07-23 10:19:37 -040086 last_sample_is_app_limited_(false) {
87 QUIC_DVLOG(2) << this << " Initializing Bbr2Sender. mode:" << mode_
88 << ", PacingRate:" << pacing_rate_ << ", Cwnd:" << cwnd_
89 << ", CwndLimits:" << cwnd_limits() << " @ " << now;
90 DCHECK_EQ(mode_, Bbr2Mode::STARTUP);
91}
92
93void Bbr2Sender::SetFromConfig(const QuicConfig& config,
94 Perspective perspective) {
95 if (config.HasClientRequestedIndependentOption(kBBR9, perspective)) {
wubf9293232020-03-16 09:43:00 -070096 params_.flexible_app_limited = true;
QUICHE team7872c772019-07-23 10:19:37 -040097 }
wubf9293232020-03-16 09:43:00 -070098 if (config.HasClientRequestedIndependentOption(kB2NA, perspective)) {
99 params_.add_ack_height_to_queueing_threshold = false;
100 }
101 if (config.HasClientRequestedIndependentOption(kB2RP, perspective)) {
102 params_.avoid_unnecessary_probe_rtt = false;
103 }
wubcc13f592020-04-16 12:40:30 -0700104 if (GetQuicReloadableFlag(quic_bbr2_avoid_too_low_probe_bw_cwnd) &&
105 config.HasClientRequestedIndependentOption(kB2CL, perspective)) {
106 params_.avoid_too_low_probe_bw_cwnd = false;
107 }
ianswett1e9525d2020-04-16 14:42:51 -0700108 if (GetQuicReloadableFlag(quic_bbr2_fewer_startup_round_trips) &&
109 config.HasClientRequestedIndependentOption(k1RTT, perspective)) {
110 QUIC_RELOADABLE_FLAG_COUNT_N(quic_bbr2_fewer_startup_round_trips, 1, 2);
111 params_.startup_full_bw_rounds = 1;
112 }
113 if (GetQuicReloadableFlag(quic_bbr2_fewer_startup_round_trips) &&
114 config.HasClientRequestedIndependentOption(k2RTT, perspective)) {
115 QUIC_RELOADABLE_FLAG_COUNT_N(quic_bbr2_fewer_startup_round_trips, 2, 2);
116 params_.startup_full_bw_rounds = 2;
117 }
ianswett64634b22020-08-31 09:30:23 -0700118 if (config.HasClientRequestedIndependentOption(kB2LO, perspective)) {
ianswett9b94db42020-04-27 12:21:32 -0700119 params_.ignore_inflight_lo = true;
120 }
ianswett88554d62020-05-25 11:33:07 -0700121 if (GetQuicReloadableFlag(quic_bbr2_limit_inflight_hi) &&
122 config.HasClientRequestedIndependentOption(kB2HI, perspective)) {
123 QUIC_RELOADABLE_FLAG_COUNT(quic_bbr2_limit_inflight_hi);
124 params_.limit_inflight_hi_by_cwnd = true;
125 }
wubd09f1a62020-05-04 06:57:40 -0700126
127 ApplyConnectionOptions(config.ClientRequestedIndependentOptions(perspective));
128}
129
130void Bbr2Sender::ApplyConnectionOptions(
131 const QuicTagVector& connection_options) {
ianswett0c54e872020-05-18 12:24:05 -0700132 if (ContainsQuicTag(connection_options, kBBQ2)) {
wubd09f1a62020-05-04 06:57:40 -0700133 // 2 is the lower, derived gain for CWND.
134 params_.startup_cwnd_gain = 2;
135 params_.drain_cwnd_gain = 2;
136 }
wuba0d2a572020-07-16 14:30:57 -0700137 if (ContainsQuicTag(connection_options, kBSAO)) {
138 model_.EnableOverestimateAvoidance();
139 }
QUICHE team7872c772019-07-23 10:19:37 -0400140}
141
142Limits<QuicByteCount> Bbr2Sender::GetCwndLimitsByMode() const {
143 switch (mode_) {
144 case Bbr2Mode::STARTUP:
145 return startup_.GetCwndLimits();
146 case Bbr2Mode::PROBE_BW:
147 return probe_bw_.GetCwndLimits();
148 case Bbr2Mode::DRAIN:
149 return drain_.GetCwndLimits();
150 case Bbr2Mode::PROBE_RTT:
151 return probe_rtt_.GetCwndLimits();
152 default:
153 QUIC_NOTREACHED();
154 return Unlimited<QuicByteCount>();
155 }
156}
157
158const Limits<QuicByteCount>& Bbr2Sender::cwnd_limits() const {
wubf9293232020-03-16 09:43:00 -0700159 return params().cwnd_limits;
QUICHE team7872c772019-07-23 10:19:37 -0400160}
161
QUICHE teamfdcfe3b2019-11-06 10:54:25 -0800162void Bbr2Sender::AdjustNetworkParameters(const NetworkParams& params) {
wub5b8985a2020-09-08 07:45:36 -0700163 model_.UpdateNetworkParameters(params.rtt);
QUICHE team7872c772019-07-23 10:19:37 -0400164
165 if (mode_ == Bbr2Mode::STARTUP) {
166 const QuicByteCount prior_cwnd = cwnd_;
167
wub5b8985a2020-09-08 07:45:36 -0700168 QuicBandwidth effective_bandwidth =
169 std::max(params.bandwidth, model_.BandwidthEstimate());
170 cwnd_ = cwnd_limits().ApplyLimits(model_.BDP(effective_bandwidth));
wube4949fb2020-07-14 11:28:01 -0700171
QUICHE teamb4e187c2019-11-14 06:22:50 -0800172 if (!params.allow_cwnd_to_decrease) {
QUICHE team7872c772019-07-23 10:19:37 -0400173 cwnd_ = std::max(cwnd_, prior_cwnd);
174 }
wube4949fb2020-07-14 11:28:01 -0700175
wub5b8985a2020-09-08 07:45:36 -0700176 pacing_rate_ = std::max(pacing_rate_, QuicBandwidth::FromBytesAndTimeDelta(
177 cwnd_, model_.MinRtt()));
QUICHE team7872c772019-07-23 10:19:37 -0400178 }
179}
180
181void Bbr2Sender::SetInitialCongestionWindowInPackets(
182 QuicPacketCount congestion_window) {
183 if (mode_ == Bbr2Mode::STARTUP) {
184 // The cwnd limits is unchanged and still applies to the new cwnd.
185 cwnd_ = cwnd_limits().ApplyLimits(congestion_window * kDefaultTCPMSS);
186 }
187}
188
189void Bbr2Sender::OnCongestionEvent(bool /*rtt_updated*/,
190 QuicByteCount prior_in_flight,
191 QuicTime event_time,
192 const AckedPacketVector& acked_packets,
193 const LostPacketVector& lost_packets) {
194 QUIC_DVLOG(3) << this
195 << " OnCongestionEvent. prior_in_flight:" << prior_in_flight
196 << " prior_cwnd:" << cwnd_ << " @ " << event_time;
197 Bbr2CongestionEvent congestion_event;
198 congestion_event.prior_cwnd = cwnd_;
wuba545ca12019-12-11 19:27:43 -0800199 congestion_event.prior_bytes_in_flight = prior_in_flight;
QUICHE team7872c772019-07-23 10:19:37 -0400200 congestion_event.is_probing_for_bandwidth =
201 BBR2_MODE_DISPATCH(IsProbingForBandwidth());
202
203 model_.OnCongestionEventStart(event_time, acked_packets, lost_packets,
204 &congestion_event);
205
206 // Number of mode changes allowed for this congestion event.
207 int mode_changes_allowed = kMaxModeChangesPerCongestionEvent;
208 while (true) {
209 Bbr2Mode next_mode = BBR2_MODE_DISPATCH(
210 OnCongestionEvent(prior_in_flight, event_time, acked_packets,
211 lost_packets, congestion_event));
212
213 if (next_mode == mode_) {
214 break;
215 }
216
217 QUIC_DVLOG(2) << this << " Mode change: " << mode_ << " ==> " << next_mode
218 << " @ " << event_time;
wub81f488f2020-03-02 10:49:35 -0800219 BBR2_MODE_DISPATCH(Leave(event_time, &congestion_event));
QUICHE team7872c772019-07-23 10:19:37 -0400220 mode_ = next_mode;
wub81f488f2020-03-02 10:49:35 -0800221 BBR2_MODE_DISPATCH(Enter(event_time, &congestion_event));
QUICHE team7872c772019-07-23 10:19:37 -0400222 --mode_changes_allowed;
223 if (mode_changes_allowed < 0) {
224 QUIC_BUG << "Exceeded max number of mode changes per congestion event.";
225 break;
226 }
227 }
228
229 UpdatePacingRate(congestion_event.bytes_acked);
230 QUIC_BUG_IF(pacing_rate_.IsZero()) << "Pacing rate must not be zero!";
231
232 UpdateCongestionWindow(congestion_event.bytes_acked);
233 QUIC_BUG_IF(cwnd_ == 0u) << "Congestion window must not be zero!";
234
235 model_.OnCongestionEventFinish(unacked_packets_->GetLeastUnacked(),
236 congestion_event);
237 last_sample_is_app_limited_ = congestion_event.last_sample_is_app_limited;
wubf9293232020-03-16 09:43:00 -0700238 if (congestion_event.bytes_in_flight == 0 &&
239 params().avoid_unnecessary_probe_rtt) {
wube4df93b2020-03-02 17:55:23 -0800240 OnEnterQuiescence(event_time);
241 }
QUICHE team7872c772019-07-23 10:19:37 -0400242
243 QUIC_DVLOG(3)
244 << this << " END CongestionEvent(acked:" << acked_packets
245 << ", lost:" << lost_packets.size() << ") "
246 << ", Mode:" << mode_ << ", RttCount:" << model_.RoundTripCount()
wuba545ca12019-12-11 19:27:43 -0800247 << ", BytesInFlight:" << congestion_event.bytes_in_flight
QUICHE team7872c772019-07-23 10:19:37 -0400248 << ", PacingRate:" << PacingRate(0) << ", CWND:" << GetCongestionWindow()
249 << ", PacingGain:" << model_.pacing_gain()
250 << ", CwndGain:" << model_.cwnd_gain()
251 << ", BandwidthEstimate(kbps):" << BandwidthEstimate().ToKBitsPerSecond()
252 << ", MinRTT(us):" << model_.MinRtt().ToMicroseconds()
253 << ", BDP:" << model_.BDP(BandwidthEstimate())
254 << ", BandwidthLatest(kbps):"
255 << model_.bandwidth_latest().ToKBitsPerSecond()
256 << ", BandwidthLow(kbps):" << model_.bandwidth_lo().ToKBitsPerSecond()
257 << ", BandwidthHigh(kbps):" << model_.MaxBandwidth().ToKBitsPerSecond()
258 << ", InflightLatest:" << model_.inflight_latest()
259 << ", InflightLow:" << model_.inflight_lo()
260 << ", InflightHigh:" << model_.inflight_hi()
261 << ", TotalAcked:" << model_.total_bytes_acked()
262 << ", TotalLost:" << model_.total_bytes_lost()
263 << ", TotalSent:" << model_.total_bytes_sent() << " @ " << event_time;
264}
265
266void Bbr2Sender::UpdatePacingRate(QuicByteCount bytes_acked) {
267 if (BandwidthEstimate().IsZero()) {
268 return;
269 }
270
271 if (model_.total_bytes_acked() == bytes_acked) {
272 // After the first ACK, cwnd_ is still the initial congestion window.
273 pacing_rate_ = QuicBandwidth::FromBytesAndTimeDelta(cwnd_, model_.MinRtt());
274 return;
275 }
276
277 QuicBandwidth target_rate = model_.pacing_gain() * model_.BandwidthEstimate();
278 if (startup_.FullBandwidthReached()) {
279 pacing_rate_ = target_rate;
280 return;
281 }
282
283 if (target_rate > pacing_rate_) {
284 pacing_rate_ = target_rate;
285 }
286}
287
288void Bbr2Sender::UpdateCongestionWindow(QuicByteCount bytes_acked) {
289 QuicByteCount target_cwnd = GetTargetCongestionWindow(model_.cwnd_gain());
290
291 const QuicByteCount prior_cwnd = cwnd_;
292 if (startup_.FullBandwidthReached()) {
293 target_cwnd += model_.MaxAckHeight();
294 cwnd_ = std::min(prior_cwnd + bytes_acked, target_cwnd);
wub7652d412019-08-13 15:11:40 -0700295 } else if (prior_cwnd < target_cwnd || prior_cwnd < 2 * initial_cwnd_) {
QUICHE team7872c772019-07-23 10:19:37 -0400296 cwnd_ = prior_cwnd + bytes_acked;
297 }
298 const QuicByteCount desired_cwnd = cwnd_;
299
300 cwnd_ = GetCwndLimitsByMode().ApplyLimits(cwnd_);
301 const QuicByteCount model_limited_cwnd = cwnd_;
302
303 cwnd_ = cwnd_limits().ApplyLimits(cwnd_);
304
305 QUIC_DVLOG(3) << this << " Updating CWND. target_cwnd:" << target_cwnd
306 << ", max_ack_height:" << model_.MaxAckHeight()
307 << ", full_bw:" << startup_.FullBandwidthReached()
308 << ", bytes_acked:" << bytes_acked
309 << ", inflight_lo:" << model_.inflight_lo()
310 << ", inflight_hi:" << model_.inflight_hi() << ". (prior_cwnd) "
311 << prior_cwnd << " => (desired_cwnd) " << desired_cwnd
312 << " => (model_limited_cwnd) " << model_limited_cwnd
313 << " => (final_cwnd) " << cwnd_;
314}
315
316QuicByteCount Bbr2Sender::GetTargetCongestionWindow(float gain) const {
317 return std::max(model_.BDP(model_.BandwidthEstimate(), gain),
318 cwnd_limits().Min());
319}
320
321void Bbr2Sender::OnPacketSent(QuicTime sent_time,
322 QuicByteCount bytes_in_flight,
323 QuicPacketNumber packet_number,
324 QuicByteCount bytes,
325 HasRetransmittableData is_retransmittable) {
326 QUIC_DVLOG(3) << this << " OnPacketSent: pkn:" << packet_number
327 << ", bytes:" << bytes << ", cwnd:" << cwnd_
wuba545ca12019-12-11 19:27:43 -0800328 << ", inflight:" << bytes_in_flight + bytes
QUICHE team7872c772019-07-23 10:19:37 -0400329 << ", total_sent:" << model_.total_bytes_sent() + bytes
330 << ", total_acked:" << model_.total_bytes_acked()
331 << ", total_lost:" << model_.total_bytes_lost() << " @ "
332 << sent_time;
wubf9293232020-03-16 09:43:00 -0700333 if (bytes_in_flight == 0 && params().avoid_unnecessary_probe_rtt) {
wube4df93b2020-03-02 17:55:23 -0800334 OnExitQuiescence(sent_time);
335 }
QUICHE team7872c772019-07-23 10:19:37 -0400336 model_.OnPacketSent(sent_time, bytes_in_flight, packet_number, bytes,
337 is_retransmittable);
338}
339
wubf4ab9652020-02-20 14:45:43 -0800340void Bbr2Sender::OnPacketNeutered(QuicPacketNumber packet_number) {
341 model_.OnPacketNeutered(packet_number);
342}
343
QUICHE team7872c772019-07-23 10:19:37 -0400344bool Bbr2Sender::CanSend(QuicByteCount bytes_in_flight) {
345 const bool result = bytes_in_flight < GetCongestionWindow();
346 return result;
347}
348
349QuicByteCount Bbr2Sender::GetCongestionWindow() const {
350 // TODO(wub): Implement Recovery?
351 return cwnd_;
352}
353
354QuicBandwidth Bbr2Sender::PacingRate(QuicByteCount /*bytes_in_flight*/) const {
355 return pacing_rate_;
356}
357
358void Bbr2Sender::OnApplicationLimited(QuicByteCount bytes_in_flight) {
359 if (bytes_in_flight >= GetCongestionWindow()) {
360 return;
361 }
wubf9293232020-03-16 09:43:00 -0700362 if (params().flexible_app_limited && IsPipeSufficientlyFull()) {
QUICHE team7872c772019-07-23 10:19:37 -0400363 return;
364 }
365
366 model_.OnApplicationLimited();
367 QUIC_DVLOG(2) << this << " Becoming application limited. Last sent packet: "
368 << model_.last_sent_packet()
369 << ", CWND: " << GetCongestionWindow();
370}
371
wub29579902019-12-18 10:16:17 -0800372QuicByteCount Bbr2Sender::GetTargetBytesInflight() const {
373 QuicByteCount bdp = model_.BDP(model_.BandwidthEstimate());
374 return std::min(bdp, GetCongestionWindow());
375}
376
wub5cd49592019-11-25 15:17:13 -0800377void Bbr2Sender::PopulateConnectionStats(QuicConnectionStats* stats) const {
378 stats->num_ack_aggregation_epochs = model_.num_ack_aggregation_epochs();
379}
380
wube4df93b2020-03-02 17:55:23 -0800381void Bbr2Sender::OnEnterQuiescence(QuicTime now) {
382 last_quiescence_start_ = now;
383}
384
385void Bbr2Sender::OnExitQuiescence(QuicTime now) {
386 if (last_quiescence_start_ != QuicTime::Zero()) {
387 Bbr2Mode next_mode = BBR2_MODE_DISPATCH(
388 OnExitQuiescence(now, std::min(now, last_quiescence_start_)));
389 if (next_mode != mode_) {
390 BBR2_MODE_DISPATCH(Leave(now, nullptr));
391 mode_ = next_mode;
392 BBR2_MODE_DISPATCH(Enter(now, nullptr));
393 }
394 last_quiescence_start_ = QuicTime::Zero();
395 }
396}
397
QUICHE team7872c772019-07-23 10:19:37 -0400398bool Bbr2Sender::ShouldSendProbingPacket() const {
399 // TODO(wub): Implement ShouldSendProbingPacket properly.
400 if (!BBR2_MODE_DISPATCH(IsProbingForBandwidth())) {
401 return false;
402 }
403
404 // TODO(b/77975811): If the pipe is highly under-utilized, consider not
405 // sending a probing transmission, because the extra bandwidth is not needed.
406 // If flexible_app_limited is enabled, check if the pipe is sufficiently full.
wubf9293232020-03-16 09:43:00 -0700407 if (params().flexible_app_limited) {
QUICHE team7872c772019-07-23 10:19:37 -0400408 const bool is_pipe_sufficiently_full = IsPipeSufficientlyFull();
409 QUIC_DVLOG(3) << this << " CWND: " << GetCongestionWindow()
wuba545ca12019-12-11 19:27:43 -0800410 << ", inflight: " << unacked_packets_->bytes_in_flight()
QUICHE team7872c772019-07-23 10:19:37 -0400411 << ", pacing_rate: " << PacingRate(0)
wubf9293232020-03-16 09:43:00 -0700412 << ", flexible_app_limited: true, ShouldSendProbingPacket: "
QUICHE team7872c772019-07-23 10:19:37 -0400413 << !is_pipe_sufficiently_full;
414 return !is_pipe_sufficiently_full;
415 } else {
416 return true;
417 }
418}
419
420bool Bbr2Sender::IsPipeSufficientlyFull() const {
wuba545ca12019-12-11 19:27:43 -0800421 QuicByteCount bytes_in_flight = unacked_packets_->bytes_in_flight();
QUICHE team7872c772019-07-23 10:19:37 -0400422 // See if we need more bytes in flight to see more bandwidth.
423 if (mode_ == Bbr2Mode::STARTUP) {
424 // STARTUP exits if it doesn't observe a 25% bandwidth increase, so the CWND
425 // must be more than 25% above the target.
wuba545ca12019-12-11 19:27:43 -0800426 return bytes_in_flight >= GetTargetCongestionWindow(1.5);
QUICHE team7872c772019-07-23 10:19:37 -0400427 }
428 if (model_.pacing_gain() > 1) {
429 // Super-unity PROBE_BW doesn't exit until 1.25 * BDP is achieved.
wuba545ca12019-12-11 19:27:43 -0800430 return bytes_in_flight >= GetTargetCongestionWindow(model_.pacing_gain());
QUICHE team7872c772019-07-23 10:19:37 -0400431 }
432 // If bytes_in_flight are above the target congestion window, it should be
433 // possible to observe the same or more bandwidth if it's available.
wuba545ca12019-12-11 19:27:43 -0800434 return bytes_in_flight >= GetTargetCongestionWindow(1.1);
QUICHE team7872c772019-07-23 10:19:37 -0400435}
436
437std::string Bbr2Sender::GetDebugState() const {
438 std::ostringstream stream;
439 stream << ExportDebugState();
440 return stream.str();
441}
442
443Bbr2Sender::DebugState Bbr2Sender::ExportDebugState() const {
444 DebugState s;
445 s.mode = mode_;
446 s.round_trip_count = model_.RoundTripCount();
447 s.bandwidth_hi = model_.MaxBandwidth();
448 s.bandwidth_lo = model_.bandwidth_lo();
449 s.bandwidth_est = BandwidthEstimate();
wubb5a8b9e2019-10-18 03:07:25 -0700450 s.inflight_hi = model_.inflight_hi();
451 s.inflight_lo = model_.inflight_lo();
452 s.max_ack_height = model_.MaxAckHeight();
QUICHE team7872c772019-07-23 10:19:37 -0400453 s.min_rtt = model_.MinRtt();
454 s.min_rtt_timestamp = model_.MinRttTimestamp();
455 s.congestion_window = cwnd_;
456 s.pacing_rate = pacing_rate_;
457 s.last_sample_is_app_limited = last_sample_is_app_limited_;
458 s.end_of_app_limited_phase = model_.end_of_app_limited_phase();
459
460 s.startup = startup_.ExportDebugState();
461 s.drain = drain_.ExportDebugState();
462 s.probe_bw = probe_bw_.ExportDebugState();
463 s.probe_rtt = probe_rtt_.ExportDebugState();
464
465 return s;
466}
467
468std::ostream& operator<<(std::ostream& os, const Bbr2Sender::DebugState& s) {
469 os << "mode: " << s.mode << "\n";
470 os << "round_trip_count: " << s.round_trip_count << "\n";
471 os << "bandwidth_hi ~ lo ~ est: " << s.bandwidth_hi << " ~ " << s.bandwidth_lo
472 << " ~ " << s.bandwidth_est << "\n";
473 os << "min_rtt: " << s.min_rtt << "\n";
474 os << "min_rtt_timestamp: " << s.min_rtt_timestamp << "\n";
475 os << "congestion_window: " << s.congestion_window << "\n";
476 os << "pacing_rate: " << s.pacing_rate << "\n";
477 os << "last_sample_is_app_limited: " << s.last_sample_is_app_limited << "\n";
478
479 if (s.mode == Bbr2Mode::STARTUP) {
480 os << s.startup;
481 }
482
483 if (s.mode == Bbr2Mode::DRAIN) {
484 os << s.drain;
485 }
486
487 if (s.mode == Bbr2Mode::PROBE_BW) {
488 os << s.probe_bw;
489 }
490
491 if (s.mode == Bbr2Mode::PROBE_RTT) {
492 os << s.probe_rtt;
493 }
494
495 return os;
496}
497
498} // namespace quic