1 // Copyright (c) 2014 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.
5 #include "net/quic/congestion_control/prr_sender.h"
7 #include "net/quic/quic_protocol.h"
12 // Constant based on TCP defaults.
13 const QuicByteCount kMaxSegmentSize
= kDefaultTCPMSS
;
16 PrrSender::PrrSender()
17 : bytes_sent_since_loss_(0),
18 bytes_delivered_since_loss_(0),
19 ack_count_since_loss_(0),
20 bytes_in_flight_before_loss_(0) {
23 void PrrSender::OnPacketSent(QuicByteCount sent_bytes
) {
24 bytes_sent_since_loss_
+= sent_bytes
;
27 void PrrSender::OnPacketLost(QuicByteCount bytes_in_flight
) {
28 bytes_sent_since_loss_
= 0;
29 bytes_in_flight_before_loss_
= bytes_in_flight
;
30 bytes_delivered_since_loss_
= 0;
31 ack_count_since_loss_
= 0;
34 void PrrSender::OnPacketAcked(QuicByteCount acked_bytes
) {
35 bytes_delivered_since_loss_
+= acked_bytes
;
36 ++ack_count_since_loss_
;
39 QuicTime::Delta
PrrSender::TimeUntilSend(
40 QuicByteCount congestion_window
,
41 QuicByteCount bytes_in_flight
,
42 QuicByteCount slowstart_threshold
) const {
43 // Return QuicTime::Zero In order to ensure limited transmit always works.
44 if (bytes_sent_since_loss_
== 0 || bytes_in_flight
< kMaxSegmentSize
) {
45 return QuicTime::Delta::Zero();
47 if (congestion_window
> bytes_in_flight
) {
48 // During PRR-SSRB, limit outgoing packets to 1 extra MSS per ack, instead
49 // of sending the entire available window. This prevents burst retransmits
50 // when more packets are lost than the CWND reduction.
51 // limit = MAX(prr_delivered - prr_out, DeliveredData) + MSS
52 if (bytes_delivered_since_loss_
+ ack_count_since_loss_
* kMaxSegmentSize
<=
53 bytes_sent_since_loss_
) {
54 return QuicTime::Delta::Infinite();
56 return QuicTime::Delta::Zero();
58 // Implement Proportional Rate Reduction (RFC6937).
59 // Checks a simplified version of the PRR formula that doesn't use division:
60 // AvailableSendWindow =
61 // CEIL(prr_delivered * ssthresh / BytesInFlightAtLoss) - prr_sent
62 if (bytes_delivered_since_loss_
* slowstart_threshold
>
63 bytes_sent_since_loss_
* bytes_in_flight_before_loss_
) {
64 return QuicTime::Delta::Zero();
66 return QuicTime::Delta::Infinite();