Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / net / quic / congestion_control / prr_sender.cc
blobe84bae8b7cb07962d889b20a8471fefe84b1badf
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"
9 namespace net {
11 namespace {
12 // Constant based on TCP defaults.
13 const QuicByteCount kMaxSegmentSize = kDefaultTCPMSS;
14 } // namespace
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 // if (FLAGS_?? && bytes_in_flight < congestion_window) {
44 // return QuicTime::Delta::Zero();
45 // }
46 // Return QuicTime::Zero In order to ensure limited transmit always works.
47 if (bytes_sent_since_loss_ == 0 || bytes_in_flight < kMaxSegmentSize) {
48 return QuicTime::Delta::Zero();
50 if (congestion_window > bytes_in_flight) {
51 // During PRR-SSRB, limit outgoing packets to 1 extra MSS per ack, instead
52 // of sending the entire available window. This prevents burst retransmits
53 // when more packets are lost than the CWND reduction.
54 // limit = MAX(prr_delivered - prr_out, DeliveredData) + MSS
55 if (bytes_delivered_since_loss_ + ack_count_since_loss_ * kMaxSegmentSize <=
56 bytes_sent_since_loss_) {
57 return QuicTime::Delta::Infinite();
59 return QuicTime::Delta::Zero();
61 // Implement Proportional Rate Reduction (RFC6937).
62 // Checks a simplified version of the PRR formula that doesn't use division:
63 // AvailableSendWindow =
64 // CEIL(prr_delivered * ssthresh / BytesInFlightAtLoss) - prr_sent
65 if (bytes_delivered_since_loss_ * slowstart_threshold >
66 bytes_sent_since_loss_ * bytes_in_flight_before_loss_) {
67 return QuicTime::Delta::Zero();
69 return QuicTime::Delta::Infinite();
72 } // namespace net