| 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/quic_congestion_manager.h" | 5 #include "net/quic/congestion_control/quic_congestion_manager.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <map> | 8 #include <map> |
| 9 | 9 |
| 10 #include "base/stl_util.h" | 10 #include "base/stl_util.h" |
| 11 #include "net/quic/congestion_control/receive_algorithm_interface.h" | 11 #include "net/quic/congestion_control/receive_algorithm_interface.h" |
| 12 #include "net/quic/congestion_control/send_algorithm_interface.h" | 12 #include "net/quic/congestion_control/send_algorithm_interface.h" |
| 13 | 13 |
| 14 namespace { | 14 namespace { |
| 15 static const int kBitrateSmoothingPeriodMs = 1000; | 15 static const int kBitrateSmoothingPeriodMs = 1000; |
| 16 static const int kHistoryPeriodMs = 5000; | 16 static const int kHistoryPeriodMs = 5000; |
| 17 | 17 |
| 18 static const int kDefaultRetransmissionTimeMs = 500; | 18 static const int kDefaultRetransmissionTimeMs = 500; |
| 19 // TCP RFC calls for 1 second RTO however Linux differs from this default and |
| 20 // define the minimum RTO to 200ms, we will use the same until we have data to |
| 21 // support a higher or lower value. |
| 22 static const int kMinRetransmissionTimeMs = 200; |
| 23 static const int kMaxRetransmissionTimeMs = 10000; |
| 19 static const size_t kMaxRetransmissions = 10; | 24 static const size_t kMaxRetransmissions = 10; |
| 20 static const size_t kTailDropWindowSize = 5; | 25 static const size_t kTailDropWindowSize = 5; |
| 21 static const size_t kTailDropMaxRetransmissions = 4; | 26 static const size_t kTailDropMaxRetransmissions = 4; |
| 22 | 27 |
| 23 COMPILE_ASSERT(kHistoryPeriodMs >= kBitrateSmoothingPeriodMs, | 28 COMPILE_ASSERT(kHistoryPeriodMs >= kBitrateSmoothingPeriodMs, |
| 24 history_must_be_longer_or_equal_to_the_smoothing_period); | 29 history_must_be_longer_or_equal_to_the_smoothing_period); |
| 25 } // namespace | 30 } // namespace |
| 26 | 31 |
| 27 using std::map; | 32 using std::map; |
| 28 using std::min; | 33 using std::min; |
| (...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 145 return current_rtt_; | 150 return current_rtt_; |
| 146 } | 151 } |
| 147 | 152 |
| 148 const QuicTime::Delta QuicCongestionManager::DefaultRetransmissionTime() { | 153 const QuicTime::Delta QuicCongestionManager::DefaultRetransmissionTime() { |
| 149 return QuicTime::Delta::FromMilliseconds(kDefaultRetransmissionTimeMs); | 154 return QuicTime::Delta::FromMilliseconds(kDefaultRetransmissionTimeMs); |
| 150 } | 155 } |
| 151 | 156 |
| 152 const QuicTime::Delta QuicCongestionManager::GetRetransmissionDelay( | 157 const QuicTime::Delta QuicCongestionManager::GetRetransmissionDelay( |
| 153 size_t unacked_packets_count, | 158 size_t unacked_packets_count, |
| 154 size_t number_retransmissions) { | 159 size_t number_retransmissions) { |
| 155 // TODO(pwestin): This should take the RTT into account instead of a hard | 160 QuicTime::Delta retransmission_delay = send_algorithm_->RetransmissionDelay(); |
| 156 // coded kDefaultRetransmissionTimeMs. Ideally the variance of the RTT too. | 161 if (retransmission_delay.IsZero()) { |
| 157 if (unacked_packets_count <= kTailDropWindowSize) { | 162 // We are in the initial state, use default timeout values. |
| 158 if (number_retransmissions <= kTailDropMaxRetransmissions) { | 163 if (unacked_packets_count <= kTailDropWindowSize) { |
| 159 return QuicTime::Delta::FromMilliseconds(kDefaultRetransmissionTimeMs); | 164 if (number_retransmissions <= kTailDropMaxRetransmissions) { |
| 165 return QuicTime::Delta::FromMilliseconds(kDefaultRetransmissionTimeMs); |
| 166 } |
| 167 number_retransmissions -= kTailDropMaxRetransmissions; |
| 160 } | 168 } |
| 161 number_retransmissions -= kTailDropMaxRetransmissions; | 169 retransmission_delay = |
| 170 QuicTime::Delta::FromMilliseconds(kDefaultRetransmissionTimeMs); |
| 162 } | 171 } |
| 172 // Calcluate exponential back off. |
| 173 retransmission_delay = QuicTime::Delta::FromMilliseconds( |
| 174 retransmission_delay.ToMilliseconds() * static_cast<size_t>( |
| 175 (1 << min<size_t>(number_retransmissions, kMaxRetransmissions)))); |
| 163 | 176 |
| 164 return QuicTime::Delta::FromMilliseconds( | 177 if (retransmission_delay.ToMilliseconds() < kMinRetransmissionTimeMs) { |
| 165 kDefaultRetransmissionTimeMs * | 178 return QuicTime::Delta::FromMilliseconds(kMinRetransmissionTimeMs); |
| 166 (1 << min<size_t>(number_retransmissions, kMaxRetransmissions))); | 179 } |
| 180 if (retransmission_delay.ToMilliseconds() > kMaxRetransmissionTimeMs) { |
| 181 return QuicTime::Delta::FromMilliseconds(kMaxRetransmissionTimeMs); |
| 182 } |
| 183 return retransmission_delay; |
| 167 } | 184 } |
| 168 | 185 |
| 169 const QuicTime::Delta QuicCongestionManager::SmoothedRtt() { | 186 const QuicTime::Delta QuicCongestionManager::SmoothedRtt() { |
| 170 return send_algorithm_->SmoothedRtt(); | 187 return send_algorithm_->SmoothedRtt(); |
| 171 } | 188 } |
| 172 | 189 |
| 173 QuicBandwidth QuicCongestionManager::BandwidthEstimate() { | 190 QuicBandwidth QuicCongestionManager::BandwidthEstimate() { |
| 174 return send_algorithm_->BandwidthEstimate(); | 191 return send_algorithm_->BandwidthEstimate(); |
| 175 } | 192 } |
| 176 | 193 |
| 177 void QuicCongestionManager::CleanupPacketHistory() { | 194 void QuicCongestionManager::CleanupPacketHistory() { |
| 178 const QuicTime::Delta kHistoryPeriod = | 195 const QuicTime::Delta kHistoryPeriod = |
| 179 QuicTime::Delta::FromMilliseconds(kHistoryPeriodMs); | 196 QuicTime::Delta::FromMilliseconds(kHistoryPeriodMs); |
| 180 QuicTime now = clock_->ApproximateNow(); | 197 QuicTime now = clock_->ApproximateNow(); |
| 181 | 198 |
| 182 SendAlgorithmInterface::SentPacketsMap::iterator history_it = | 199 SendAlgorithmInterface::SentPacketsMap::iterator history_it = |
| 183 packet_history_map_.begin(); | 200 packet_history_map_.begin(); |
| 184 for (; history_it != packet_history_map_.end(); ++history_it) { | 201 for (; history_it != packet_history_map_.end(); ++history_it) { |
| 185 if (now.Subtract(history_it->second->SendTimestamp()) <= kHistoryPeriod) { | 202 if (now.Subtract(history_it->second->SendTimestamp()) <= kHistoryPeriod) { |
| 186 return; | 203 return; |
| 187 } | 204 } |
| 188 delete history_it->second; | 205 delete history_it->second; |
| 189 packet_history_map_.erase(history_it); | 206 packet_history_map_.erase(history_it); |
| 190 history_it = packet_history_map_.begin(); | 207 history_it = packet_history_map_.begin(); |
| 191 } | 208 } |
| 192 } | 209 } |
| 193 | 210 |
| 194 } // namespace net | 211 } // namespace net |
| OLD | NEW |