| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "net/quic/congestion_control/tcp_cubic_sender.h" | 5 #include "net/quic/congestion_control/tcp_cubic_sender.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 | 8 |
| 9 #include "base/metrics/histogram.h" | 9 #include "base/metrics/histogram.h" |
| 10 #include "net/quic/congestion_control/prr_sender.h" | 10 #include "net/quic/congestion_control/prr_sender.h" |
| 11 #include "net/quic/congestion_control/rtt_stats.h" | 11 #include "net/quic/congestion_control/rtt_stats.h" |
| 12 #include "net/quic/crypto/crypto_protocol.h" | 12 #include "net/quic/crypto/crypto_protocol.h" |
| 13 | 13 |
| 14 using std::max; | 14 using std::max; |
| 15 using std::min; | 15 using std::min; |
| 16 | 16 |
| 17 namespace net { | 17 namespace net { |
| 18 | 18 |
| 19 namespace { | 19 namespace { |
| 20 // Constants based on TCP defaults. | 20 // Constants based on TCP defaults. |
| 21 // The minimum cwnd based on RFC 3782 (TCP NewReno) for cwnd reductions on a | 21 // The minimum cwnd based on RFC 3782 (TCP NewReno) for cwnd reductions on a |
| 22 // fast retransmission. The cwnd after a timeout is still 1. | 22 // fast retransmission. The cwnd after a timeout is still 1. |
| 23 const QuicPacketCount kMinimumCongestionWindow = 2; | 23 const QuicPacketCount kMinimumCongestionWindow = 2; |
| 24 const QuicByteCount kMaxSegmentSize = kDefaultTCPMSS; | 24 const QuicByteCount kMaxSegmentSize = kDefaultTCPMSS; |
| 25 const int64 kInitialCongestionWindow = 10; | 25 const int64 kInitialCongestionWindow = 10; |
| 26 const int kMaxBurstLength = 3; | 26 const int kMaxBurstLength = 3; |
| 27 const float kRenoBeta = 0.7f; // Reno backoff factor. | 27 const float kRenoBeta = 0.7f; // Reno backoff factor. |
| 28 const uint32 kDefaultNumConnections = 2; // N-connection emulation. |
| 28 } // namespace | 29 } // namespace |
| 29 | 30 |
| 30 TcpCubicSender::TcpCubicSender( | 31 TcpCubicSender::TcpCubicSender( |
| 31 const QuicClock* clock, | 32 const QuicClock* clock, |
| 32 const RttStats* rtt_stats, | 33 const RttStats* rtt_stats, |
| 33 bool reno, | 34 bool reno, |
| 34 QuicPacketCount max_tcp_congestion_window, | 35 QuicPacketCount max_tcp_congestion_window, |
| 35 QuicConnectionStats* stats) | 36 QuicConnectionStats* stats) |
| 36 : hybrid_slow_start_(clock), | 37 : hybrid_slow_start_(clock), |
| 37 cubic_(clock, stats), | 38 cubic_(clock, stats), |
| 38 rtt_stats_(rtt_stats), | 39 rtt_stats_(rtt_stats), |
| 39 stats_(stats), | 40 stats_(stats), |
| 40 reno_(reno), | 41 reno_(reno), |
| 41 num_connections_(2), | 42 num_connections_(kDefaultNumConnections), |
| 42 congestion_window_count_(0), | 43 congestion_window_count_(0), |
| 43 largest_sent_sequence_number_(0), | 44 largest_sent_sequence_number_(0), |
| 44 largest_acked_sequence_number_(0), | 45 largest_acked_sequence_number_(0), |
| 45 largest_sent_at_last_cutback_(0), | 46 largest_sent_at_last_cutback_(0), |
| 46 congestion_window_(kInitialCongestionWindow), | 47 congestion_window_(kInitialCongestionWindow), |
| 47 previous_congestion_window_(0), | 48 previous_congestion_window_(0), |
| 48 slowstart_threshold_(max_tcp_congestion_window), | 49 slowstart_threshold_(max_tcp_congestion_window), |
| 49 previous_slowstart_threshold_(0), | 50 previous_slowstart_threshold_(0), |
| 50 last_cutback_exited_slowstart_(false), | 51 last_cutback_exited_slowstart_(false), |
| 51 max_tcp_congestion_window_(max_tcp_congestion_window) { | 52 max_tcp_congestion_window_(max_tcp_congestion_window) { |
| (...skipping 17 matching lines...) Expand all Loading... |
| 69 config.ReceivedInitialCongestionWindow()); | 70 config.ReceivedInitialCongestionWindow()); |
| 70 } | 71 } |
| 71 } | 72 } |
| 72 } | 73 } |
| 73 | 74 |
| 74 void TcpCubicSender::SetNumEmulatedConnections(int num_connections) { | 75 void TcpCubicSender::SetNumEmulatedConnections(int num_connections) { |
| 75 num_connections_ = max(1, num_connections); | 76 num_connections_ = max(1, num_connections); |
| 76 cubic_.SetNumConnections(num_connections_); | 77 cubic_.SetNumConnections(num_connections_); |
| 77 } | 78 } |
| 78 | 79 |
| 80 float TcpCubicSender::RenoBeta() const { |
| 81 // kNConnectionBeta is the backoff factor after loss for our N-connection |
| 82 // emulation, which emulates the effective backoff of an ensemble of N |
| 83 // TCP-Reno connections on a single loss event. The effective multiplier is |
| 84 // computed as: |
| 85 return (num_connections_ - 1 + kRenoBeta) / num_connections_; |
| 86 } |
| 87 |
| 79 void TcpCubicSender::OnCongestionEvent( | 88 void TcpCubicSender::OnCongestionEvent( |
| 80 bool rtt_updated, | 89 bool rtt_updated, |
| 81 QuicByteCount bytes_in_flight, | 90 QuicByteCount bytes_in_flight, |
| 82 const CongestionVector& acked_packets, | 91 const CongestionVector& acked_packets, |
| 83 const CongestionVector& lost_packets) { | 92 const CongestionVector& lost_packets) { |
| 84 if (rtt_updated && InSlowStart() && | 93 if (rtt_updated && InSlowStart() && |
| 85 hybrid_slow_start_.ShouldExitSlowStart(rtt_stats_->latest_rtt(), | 94 hybrid_slow_start_.ShouldExitSlowStart(rtt_stats_->latest_rtt(), |
| 86 rtt_stats_->MinRtt(), | 95 rtt_stats_->MinRtt(), |
| 87 congestion_window_)) { | 96 congestion_window_)) { |
| 88 slowstart_threshold_ = congestion_window_; | 97 slowstart_threshold_ = congestion_window_; |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 127 } | 136 } |
| 128 ++stats_->tcp_loss_events; | 137 ++stats_->tcp_loss_events; |
| 129 last_cutback_exited_slowstart_ = InSlowStart(); | 138 last_cutback_exited_slowstart_ = InSlowStart(); |
| 130 if (InSlowStart()) { | 139 if (InSlowStart()) { |
| 131 ++stats_->slowstart_packets_lost; | 140 ++stats_->slowstart_packets_lost; |
| 132 } | 141 } |
| 133 | 142 |
| 134 prr_.OnPacketLost(bytes_in_flight); | 143 prr_.OnPacketLost(bytes_in_flight); |
| 135 | 144 |
| 136 if (reno_) { | 145 if (reno_) { |
| 137 congestion_window_ = congestion_window_ * kRenoBeta; | 146 congestion_window_ = congestion_window_ * RenoBeta(); |
| 138 } else { | 147 } else { |
| 139 congestion_window_ = | 148 congestion_window_ = |
| 140 cubic_.CongestionWindowAfterPacketLoss(congestion_window_); | 149 cubic_.CongestionWindowAfterPacketLoss(congestion_window_); |
| 141 } | 150 } |
| 142 slowstart_threshold_ = congestion_window_; | 151 slowstart_threshold_ = congestion_window_; |
| 143 // Enforce TCP's minimum congestion window of 2*MSS. | 152 // Enforce TCP's minimum congestion window of 2*MSS. |
| 144 if (congestion_window_ < kMinimumCongestionWindow) { | 153 if (congestion_window_ < kMinimumCongestionWindow) { |
| 145 congestion_window_ = kMinimumCongestionWindow; | 154 congestion_window_ = kMinimumCongestionWindow; |
| 146 } | 155 } |
| 147 largest_sent_at_last_cutback_ = largest_sent_sequence_number_; | 156 largest_sent_at_last_cutback_ = largest_sent_sequence_number_; |
| (...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 317 congestion_window_ = previous_congestion_window_; | 326 congestion_window_ = previous_congestion_window_; |
| 318 slowstart_threshold_ = previous_slowstart_threshold_; | 327 slowstart_threshold_ = previous_slowstart_threshold_; |
| 319 previous_congestion_window_ = 0; | 328 previous_congestion_window_ = 0; |
| 320 } | 329 } |
| 321 | 330 |
| 322 CongestionControlType TcpCubicSender::GetCongestionControlType() const { | 331 CongestionControlType TcpCubicSender::GetCongestionControlType() const { |
| 323 return reno_ ? kReno : kCubic; | 332 return reno_ ? kReno : kCubic; |
| 324 } | 333 } |
| 325 | 334 |
| 326 } // namespace net | 335 } // namespace net |
| OLD | NEW |