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 int kMaxBurstLength = 3; | 25 const int kMaxBurstLength = 3; |
26 const float kRenoBeta = 0.7f; // Reno backoff factor. | 26 const float kRenoBeta = 0.7f; // Reno backoff factor. |
27 const uint32 kDefaultNumConnections = 2; // N-connection emulation. | 27 const uint32 kDefaultNumConnections = 2; // N-connection emulation. |
28 } // namespace | 28 } // namespace |
29 | 29 |
30 TcpCubicSender::TcpCubicSender( | 30 TcpCubicSender::TcpCubicSender(const QuicClock* clock, |
31 const QuicClock* clock, | 31 const RttStats* rtt_stats, |
32 const RttStats* rtt_stats, | 32 bool reno, |
33 bool reno, | 33 QuicPacketCount initial_tcp_congestion_window, |
34 QuicPacketCount initial_tcp_congestion_window, | 34 QuicPacketCount max_tcp_congestion_window, |
35 QuicPacketCount max_tcp_congestion_window, | 35 QuicConnectionStats* stats) |
36 QuicConnectionStats* stats) | |
37 : hybrid_slow_start_(clock), | 36 : hybrid_slow_start_(clock), |
38 cubic_(clock, stats), | 37 cubic_(clock, stats), |
39 rtt_stats_(rtt_stats), | 38 rtt_stats_(rtt_stats), |
40 stats_(stats), | 39 stats_(stats), |
41 reno_(reno), | 40 reno_(reno), |
42 num_connections_(kDefaultNumConnections), | 41 num_connections_(kDefaultNumConnections), |
43 congestion_window_count_(0), | 42 congestion_window_count_(0), |
44 largest_sent_sequence_number_(0), | 43 largest_sent_sequence_number_(0), |
45 largest_acked_sequence_number_(0), | 44 largest_acked_sequence_number_(0), |
46 largest_sent_at_last_cutback_(0), | 45 largest_sent_at_last_cutback_(0), |
47 congestion_window_(initial_tcp_congestion_window), | 46 congestion_window_(initial_tcp_congestion_window), |
48 previous_congestion_window_(0), | 47 previous_congestion_window_(0), |
49 slowstart_threshold_(max_tcp_congestion_window), | 48 slowstart_threshold_(max_tcp_congestion_window), |
50 previous_slowstart_threshold_(0), | 49 previous_slowstart_threshold_(0), |
51 last_cutback_exited_slowstart_(false), | 50 last_cutback_exited_slowstart_(false), |
52 max_tcp_congestion_window_(max_tcp_congestion_window) { | 51 max_tcp_congestion_window_(max_tcp_congestion_window), |
53 } | 52 clock_(clock) {} |
54 | 53 |
55 TcpCubicSender::~TcpCubicSender() { | 54 TcpCubicSender::~TcpCubicSender() { |
56 UMA_HISTOGRAM_COUNTS("Net.QuicSession.FinalTcpCwnd", congestion_window_); | 55 UMA_HISTOGRAM_COUNTS("Net.QuicSession.FinalTcpCwnd", congestion_window_); |
57 } | 56 } |
58 | 57 |
59 void TcpCubicSender::SetFromConfig(const QuicConfig& config, | 58 void TcpCubicSender::SetFromConfig(const QuicConfig& config, |
60 bool is_server, | 59 bool is_server, |
61 bool using_pacing) { | 60 bool using_pacing) { |
62 if (is_server) { | 61 if (is_server) { |
63 if (config.HasReceivedConnectionOptions() && | 62 if (config.HasReceivedConnectionOptions() && |
64 ContainsQuicTag(config.ReceivedConnectionOptions(), kIW10)) { | 63 ContainsQuicTag(config.ReceivedConnectionOptions(), kIW10)) { |
65 // Initial window experiment. | 64 // Initial window experiment. |
66 congestion_window_ = 10; | 65 congestion_window_ = 10; |
67 } | 66 } |
68 if (using_pacing) { | 67 if (using_pacing) { |
69 // Disable the ack train mode in hystart when pacing is enabled, since it | 68 // Disable the ack train mode in hystart when pacing is enabled, since it |
70 // may be falsely triggered. | 69 // may be falsely triggered. |
71 hybrid_slow_start_.set_ack_train_detection(false); | 70 hybrid_slow_start_.set_ack_train_detection(false); |
72 } | 71 } |
73 } | 72 } |
74 } | 73 } |
75 | 74 |
| 75 void TcpCubicSender::ResumeConnectionState( |
| 76 const CachedNetworkParameters& cached_network_params) { |
| 77 // If the previous bandwidth estimate is less than an hour old, store in |
| 78 // preparation for doing bandwidth resumption. |
| 79 int64 seconds_since_estimate = |
| 80 clock_->WallNow().ToUNIXSeconds() - cached_network_params.timestamp(); |
| 81 if (seconds_since_estimate > kNumSecondsPerHour) { |
| 82 return; |
| 83 } |
| 84 |
| 85 QuicBandwidth bandwidth = QuicBandwidth::FromBytesPerSecond( |
| 86 cached_network_params.bandwidth_estimate_bytes_per_second()); |
| 87 QuicTime::Delta rtt_ms = |
| 88 QuicTime::Delta::FromMilliseconds(cached_network_params.min_rtt_ms()); |
| 89 congestion_window_ = bandwidth.ToBytesPerPeriod(rtt_ms) / kMaxPacketSize; |
| 90 |
| 91 // TODO(rjshade): Set appropriate CWND when previous connection was in slow |
| 92 // start at time of estimate. |
| 93 } |
| 94 |
76 void TcpCubicSender::SetNumEmulatedConnections(int num_connections) { | 95 void TcpCubicSender::SetNumEmulatedConnections(int num_connections) { |
77 num_connections_ = max(1, num_connections); | 96 num_connections_ = max(1, num_connections); |
78 cubic_.SetNumConnections(num_connections_); | 97 cubic_.SetNumConnections(num_connections_); |
79 } | 98 } |
80 | 99 |
81 float TcpCubicSender::RenoBeta() const { | 100 float TcpCubicSender::RenoBeta() const { |
82 // kNConnectionBeta is the backoff factor after loss for our N-connection | 101 // kNConnectionBeta is the backoff factor after loss for our N-connection |
83 // emulation, which emulates the effective backoff of an ensemble of N | 102 // emulation, which emulates the effective backoff of an ensemble of N |
84 // TCP-Reno connections on a single loss event. The effective multiplier is | 103 // TCP-Reno connections on a single loss event. The effective multiplier is |
85 // computed as: | 104 // computed as: |
(...skipping 248 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
334 congestion_window_ = previous_congestion_window_; | 353 congestion_window_ = previous_congestion_window_; |
335 slowstart_threshold_ = previous_slowstart_threshold_; | 354 slowstart_threshold_ = previous_slowstart_threshold_; |
336 previous_congestion_window_ = 0; | 355 previous_congestion_window_ = 0; |
337 } | 356 } |
338 | 357 |
339 CongestionControlType TcpCubicSender::GetCongestionControlType() const { | 358 CongestionControlType TcpCubicSender::GetCongestionControlType() const { |
340 return reno_ ? kReno : kCubic; | 359 return reno_ ? kReno : kCubic; |
341 } | 360 } |
342 | 361 |
343 } // namespace net | 362 } // namespace net |
OLD | NEW |