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 "net/quic/congestion_control/quic_send_scheduler.h" | 7 #include "net/quic/congestion_control/quic_send_scheduler.h" |
8 | 8 |
9 namespace { | 9 namespace { |
10 // Constants based on TCP defaults. | 10 // Constants based on TCP defaults. |
(...skipping 12 matching lines...) Expand all Loading... |
23 cubic_(clock), | 23 cubic_(clock), |
24 reno_(reno), | 24 reno_(reno), |
25 congestion_window_count_(0), | 25 congestion_window_count_(0), |
26 receiver_congestion_window_in_bytes_(kDefaultReceiveWindow), | 26 receiver_congestion_window_in_bytes_(kDefaultReceiveWindow), |
27 last_received_accumulated_number_of_lost_packets_(0), | 27 last_received_accumulated_number_of_lost_packets_(0), |
28 bytes_in_flight_(0), | 28 bytes_in_flight_(0), |
29 update_end_sequence_number_(true), | 29 update_end_sequence_number_(true), |
30 end_sequence_number_(0), | 30 end_sequence_number_(0), |
31 congestion_window_(kInitialCongestionWindow), | 31 congestion_window_(kInitialCongestionWindow), |
32 slowstart_threshold_(kMaxCongestionWindow), | 32 slowstart_threshold_(kMaxCongestionWindow), |
33 delay_min_() { | 33 delay_min_(QuicTime::Delta::Zero()) { |
34 } | 34 } |
35 | 35 |
36 void TcpCubicSender::OnIncomingQuicCongestionFeedbackFrame( | 36 void TcpCubicSender::OnIncomingQuicCongestionFeedbackFrame( |
37 const QuicCongestionFeedbackFrame& feedback) { | 37 const QuicCongestionFeedbackFrame& feedback) { |
38 if (last_received_accumulated_number_of_lost_packets_ != | 38 if (last_received_accumulated_number_of_lost_packets_ != |
39 feedback.tcp.accumulated_number_of_lost_packets) { | 39 feedback.tcp.accumulated_number_of_lost_packets) { |
40 int recovered_lost_packets = | 40 int recovered_lost_packets = |
41 last_received_accumulated_number_of_lost_packets_ - | 41 last_received_accumulated_number_of_lost_packets_ - |
42 feedback.tcp.accumulated_number_of_lost_packets; | 42 feedback.tcp.accumulated_number_of_lost_packets; |
43 last_received_accumulated_number_of_lost_packets_ = | 43 last_received_accumulated_number_of_lost_packets_ = |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
90 if (AvailableCongestionWindow() == 0) { | 90 if (AvailableCongestionWindow() == 0) { |
91 update_end_sequence_number_ = false; | 91 update_end_sequence_number_ = false; |
92 DLOG(INFO) << "Stop update end sequence number @" << sequence_number; | 92 DLOG(INFO) << "Stop update end sequence number @" << sequence_number; |
93 } | 93 } |
94 } | 94 } |
95 } | 95 } |
96 | 96 |
97 QuicTime::Delta TcpCubicSender::TimeUntilSend(bool retransmit) { | 97 QuicTime::Delta TcpCubicSender::TimeUntilSend(bool retransmit) { |
98 if (retransmit) { | 98 if (retransmit) { |
99 // For TCP we can always send a retransmit immediately. | 99 // For TCP we can always send a retransmit immediately. |
100 return QuicTime::Delta(); | 100 return QuicTime::Delta::Zero(); |
101 } | 101 } |
102 if (AvailableCongestionWindow() == 0) { | 102 if (AvailableCongestionWindow() == 0) { |
103 return QuicTime::Delta::Infinite(); | 103 return QuicTime::Delta::Infinite(); |
104 } | 104 } |
105 return QuicTime::Delta(); | 105 return QuicTime::Delta::Zero(); |
106 } | 106 } |
107 | 107 |
108 size_t TcpCubicSender::AvailableCongestionWindow() { | 108 size_t TcpCubicSender::AvailableCongestionWindow() { |
109 if (bytes_in_flight_ > CongestionWindow()) { | 109 if (bytes_in_flight_ > CongestionWindow()) { |
110 return 0; | 110 return 0; |
111 } | 111 } |
112 return CongestionWindow() - bytes_in_flight_; | 112 return CongestionWindow() - bytes_in_flight_; |
113 } | 113 } |
114 | 114 |
115 size_t TcpCubicSender::CongestionWindow() { | 115 size_t TcpCubicSender::CongestionWindow() { |
116 // What's the current congestion window in bytes. | 116 // What's the current congestion window in bytes. |
117 return std::min(receiver_congestion_window_in_bytes_, | 117 return std::min(receiver_congestion_window_in_bytes_, |
118 static_cast<int>(congestion_window_ * kMaxSegmentSize)); | 118 static_cast<int>(congestion_window_ * kMaxSegmentSize)); |
119 } | 119 } |
120 | 120 |
121 int TcpCubicSender::BandwidthEstimate() { | 121 int TcpCubicSender::BandwidthEstimate() { |
122 // TODO(pwestin): make a long term estimate, based on RTT and loss rate? or | 122 // TODO(pwestin): make a long term estimate, based on RTT and loss rate? or |
123 // instantaneous estimate? | 123 // instantaneous estimate? |
124 // Throughput ~= (1/RTT)*sqrt(3/2p) | 124 // Throughput ~= (1/RTT)*sqrt(3/2p) |
125 return kNoValidEstimate; | 125 return kNoValidEstimate; |
126 } | 126 } |
127 | 127 |
128 void TcpCubicSender::Reset() { | 128 void TcpCubicSender::Reset() { |
129 delay_min_ = QuicTime::Delta(); // Reset to 0. | 129 delay_min_ = QuicTime::Delta::Zero(); |
130 hybrid_slow_start_.Restart(); | 130 hybrid_slow_start_.Restart(); |
131 } | 131 } |
132 | 132 |
133 bool TcpCubicSender::IsCwndLimited() const { | 133 bool TcpCubicSender::IsCwndLimited() const { |
134 const size_t congestion_window_bytes = congestion_window_ * kMaxSegmentSize; | 134 const size_t congestion_window_bytes = congestion_window_ * kMaxSegmentSize; |
135 if (bytes_in_flight_ >= congestion_window_bytes) { | 135 if (bytes_in_flight_ >= congestion_window_bytes) { |
136 return true; | 136 return true; |
137 } | 137 } |
138 const size_t tcp_max_burst = kMaxBurstLength * kMaxSegmentSize; | 138 const size_t tcp_max_burst = kMaxBurstLength * kMaxSegmentSize; |
139 const size_t left = congestion_window_bytes - bytes_in_flight_; | 139 const size_t left = congestion_window_bytes - bytes_in_flight_; |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
206 hybrid_slow_start_.Reset(end_sequence_number_); | 206 hybrid_slow_start_.Reset(end_sequence_number_); |
207 } | 207 } |
208 hybrid_slow_start_.Update(rtt, delay_min_); | 208 hybrid_slow_start_.Update(rtt, delay_min_); |
209 if (hybrid_slow_start_.Exit()) { | 209 if (hybrid_slow_start_.Exit()) { |
210 slowstart_threshold_ = congestion_window_; | 210 slowstart_threshold_ = congestion_window_; |
211 } | 211 } |
212 } | 212 } |
213 } | 213 } |
214 | 214 |
215 } // namespace net | 215 } // namespace net |
OLD | NEW |