OLD | NEW |
(Empty) | |
| 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. |
| 4 |
| 5 #include "net/quic/congestion_control/prr_sender.h" |
| 6 |
| 7 #include "net/quic/quic_protocol.h" |
| 8 |
| 9 namespace net { |
| 10 |
| 11 namespace { |
| 12 // Constant based on TCP defaults. |
| 13 const QuicByteCount kMaxSegmentSize = kDefaultTCPMSS; |
| 14 } // namespace |
| 15 |
| 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) { |
| 21 } |
| 22 |
| 23 void PrrSender::OnPacketSent(QuicByteCount sent_bytes) { |
| 24 bytes_sent_since_loss_ += sent_bytes; |
| 25 } |
| 26 |
| 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; |
| 32 } |
| 33 |
| 34 void PrrSender::OnPacketAcked(QuicByteCount acked_bytes) { |
| 35 bytes_delivered_since_loss_ += acked_bytes; |
| 36 ++ack_count_since_loss_; |
| 37 } |
| 38 |
| 39 QuicTime::Delta PrrSender::TimeUntilSend( |
| 40 QuicByteCount congestion_window, |
| 41 QuicByteCount bytes_in_flight, |
| 42 QuicPacketCount 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(); |
| 46 } |
| 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(); |
| 55 } |
| 56 return QuicTime::Delta::Zero(); |
| 57 } |
| 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 * kMaxSegmentSize > |
| 63 bytes_sent_since_loss_ * bytes_in_flight_before_loss_) { |
| 64 return QuicTime::Delta::Zero(); |
| 65 } |
| 66 return QuicTime::Delta::Infinite(); |
| 67 } |
| 68 |
| 69 } // namespace net |
OLD | NEW |