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 | 10 |
11 using std::max; | 11 using std::max; |
| 12 using std::min; |
12 | 13 |
13 namespace net { | 14 namespace net { |
14 | 15 |
15 namespace { | 16 namespace { |
16 // Constants based on TCP defaults. | 17 // Constants based on TCP defaults. |
17 // The minimum cwnd based on RFC 3782 (TCP NewReno) for cwnd reductions on a | 18 // The minimum cwnd based on RFC 3782 (TCP NewReno) for cwnd reductions on a |
18 // fast retransmission. The cwnd after a timeout is still 1. | 19 // fast retransmission. The cwnd after a timeout is still 1. |
19 const QuicTcpCongestionWindow kMinimumCongestionWindow = 2; | 20 const QuicTcpCongestionWindow kMinimumCongestionWindow = 2; |
20 const int64 kHybridStartLowWindow = 16; | 21 const int64 kHybridStartLowWindow = 16; |
21 const QuicByteCount kMaxSegmentSize = kDefaultTCPMSS; | 22 const QuicByteCount kMaxSegmentSize = kDefaultTCPMSS; |
(...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
190 | 191 |
191 QuicByteCount TcpCubicSender::AvailableSendWindow() { | 192 QuicByteCount TcpCubicSender::AvailableSendWindow() { |
192 if (bytes_in_flight_ > SendWindow()) { | 193 if (bytes_in_flight_ > SendWindow()) { |
193 return 0; | 194 return 0; |
194 } | 195 } |
195 return SendWindow() - bytes_in_flight_; | 196 return SendWindow() - bytes_in_flight_; |
196 } | 197 } |
197 | 198 |
198 QuicByteCount TcpCubicSender::SendWindow() { | 199 QuicByteCount TcpCubicSender::SendWindow() { |
199 // What's the current send window in bytes. | 200 // What's the current send window in bytes. |
200 return std::min(receive_window_, GetCongestionWindow()); | 201 return min(receive_window_, GetCongestionWindow()); |
201 } | 202 } |
202 | 203 |
203 QuicBandwidth TcpCubicSender::BandwidthEstimate() const { | 204 QuicBandwidth TcpCubicSender::BandwidthEstimate() const { |
204 return QuicBandwidth::FromBytesAndTimeDelta(GetCongestionWindow(), | 205 return QuicBandwidth::FromBytesAndTimeDelta(GetCongestionWindow(), |
205 SmoothedRtt()); | 206 SmoothedRtt()); |
206 } | 207 } |
207 | 208 |
208 QuicTime::Delta TcpCubicSender::SmoothedRtt() const { | 209 QuicTime::Delta TcpCubicSender::SmoothedRtt() const { |
209 if (smoothed_rtt_.IsZero()) { | 210 if (smoothed_rtt_.IsZero()) { |
210 return QuicTime::Delta::FromMilliseconds(kInitialRttMs); | 211 return QuicTime::Delta::FromMilliseconds(kInitialRttMs); |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
261 if (reno_) { | 262 if (reno_) { |
262 // Classic Reno congestion avoidance provided for testing. | 263 // Classic Reno congestion avoidance provided for testing. |
263 if (congestion_window_count_ >= congestion_window_) { | 264 if (congestion_window_count_ >= congestion_window_) { |
264 congestion_window_++; | 265 congestion_window_++; |
265 congestion_window_count_ = 0; | 266 congestion_window_count_ = 0; |
266 } else { | 267 } else { |
267 congestion_window_count_++; | 268 congestion_window_count_++; |
268 } | 269 } |
269 DVLOG(1) << "Reno; congestion window:" << congestion_window_; | 270 DVLOG(1) << "Reno; congestion window:" << congestion_window_; |
270 } else { | 271 } else { |
271 congestion_window_ = std::min( | 272 congestion_window_ = min( |
272 max_tcp_congestion_window_, | 273 max_tcp_congestion_window_, |
273 cubic_.CongestionWindowAfterAck(congestion_window_, delay_min_)); | 274 cubic_.CongestionWindowAfterAck(congestion_window_, delay_min_)); |
274 DVLOG(1) << "Cubic; congestion window:" << congestion_window_; | 275 DVLOG(1) << "Cubic; congestion window:" << congestion_window_; |
275 } | 276 } |
276 } | 277 } |
277 } | 278 } |
278 } | 279 } |
279 | 280 |
280 void TcpCubicSender::OnRetransmissionTimeout() { | 281 void TcpCubicSender::OnRetransmissionTimeout() { |
281 cubic_.Reset(); | 282 cubic_.Reset(); |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
322 hybrid_slow_start_.Reset(end_sequence_number_); | 323 hybrid_slow_start_.Reset(end_sequence_number_); |
323 } | 324 } |
324 hybrid_slow_start_.Update(rtt, delay_min_); | 325 hybrid_slow_start_.Update(rtt, delay_min_); |
325 if (hybrid_slow_start_.Exit()) { | 326 if (hybrid_slow_start_.Exit()) { |
326 slowstart_threshold_ = congestion_window_; | 327 slowstart_threshold_ = congestion_window_; |
327 } | 328 } |
328 } | 329 } |
329 } | 330 } |
330 | 331 |
331 } // namespace net | 332 } // namespace net |
OLD | NEW |