| OLD | NEW | 
|---|
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/quic_sent_packet_manager.h" | 5 #include "net/quic/quic_sent_packet_manager.h" | 
| 6 | 6 | 
| 7 #include <algorithm> | 7 #include <algorithm> | 
| 8 | 8 | 
| 9 #include "base/logging.h" | 9 #include "base/logging.h" | 
| 10 #include "base/stl_util.h" | 10 #include "base/stl_util.h" | 
| 11 #include "net/quic/congestion_control/pacing_sender.h" | 11 #include "net/quic/congestion_control/pacing_sender.h" | 
| 12 #include "net/quic/crypto/crypto_protocol.h" | 12 #include "net/quic/crypto/crypto_protocol.h" | 
| 13 #include "net/quic/proto/cached_network_parameters.pb.h" | 13 #include "net/quic/proto/cached_network_parameters.pb.h" | 
| 14 #include "net/quic/quic_connection_stats.h" | 14 #include "net/quic/quic_connection_stats.h" | 
| 15 #include "net/quic/quic_flags.h" | 15 #include "net/quic/quic_flags.h" | 
| 16 #include "net/quic/quic_utils_chromium.h" | 16 #include "net/quic/quic_utils_chromium.h" | 
| 17 | 17 | 
| 18 using std::max; | 18 using std::max; | 
| 19 using std::min; | 19 using std::min; | 
| 20 | 20 | 
| 21 namespace net { | 21 namespace net { | 
| 22 | 22 | 
| 23 // The length of the recent min rtt window in seconds. Windowing is disabled for | 23 // The length of the recent min rtt window in seconds. Windowing is disabled for | 
| 24 // values less than or equal to 0. | 24 // values less than or equal to 0. | 
| 25 int32 FLAGS_quic_recent_min_rtt_window_s = 60; | 25 int32_t FLAGS_quic_recent_min_rtt_window_s = 60; | 
| 26 | 26 | 
| 27 namespace { | 27 namespace { | 
| 28 static const int64 kDefaultRetransmissionTimeMs = 500; | 28 static const int64_t kDefaultRetransmissionTimeMs = 500; | 
| 29 // TCP RFC calls for 1 second RTO however Linux differs from this default and | 29 // TCP RFC calls for 1 second RTO however Linux differs from this default and | 
| 30 // define the minimum RTO to 200ms, we will use the same until we have data to | 30 // define the minimum RTO to 200ms, we will use the same until we have data to | 
| 31 // support a higher or lower value. | 31 // support a higher or lower value. | 
| 32 static const int64 kMinRetransmissionTimeMs = 200; | 32 static const int64_t kMinRetransmissionTimeMs = 200; | 
| 33 static const int64 kMaxRetransmissionTimeMs = 60000; | 33 static const int64_t kMaxRetransmissionTimeMs = 60000; | 
| 34 // Maximum number of exponential backoffs used for RTO timeouts. | 34 // Maximum number of exponential backoffs used for RTO timeouts. | 
| 35 static const size_t kMaxRetransmissions = 10; | 35 static const size_t kMaxRetransmissions = 10; | 
| 36 // Maximum number of packets retransmitted upon an RTO. | 36 // Maximum number of packets retransmitted upon an RTO. | 
| 37 static const size_t kMaxRetransmissionsOnTimeout = 2; | 37 static const size_t kMaxRetransmissionsOnTimeout = 2; | 
| 38 | 38 | 
| 39 // Ensure the handshake timer isnt't faster than 10ms. | 39 // Ensure the handshake timer isnt't faster than 10ms. | 
| 40 // This limits the tenth retransmitted packet to 10s after the initial CHLO. | 40 // This limits the tenth retransmitted packet to 10s after the initial CHLO. | 
| 41 static const int64 kMinHandshakeTimeoutMs = 10; | 41 static const int64_t kMinHandshakeTimeoutMs = 10; | 
| 42 | 42 | 
| 43 // Sends up to two tail loss probes before firing an RTO, | 43 // Sends up to two tail loss probes before firing an RTO, | 
| 44 // per draft RFC draft-dukkipati-tcpm-tcp-loss-probe. | 44 // per draft RFC draft-dukkipati-tcpm-tcp-loss-probe. | 
| 45 static const size_t kDefaultMaxTailLossProbes = 2; | 45 static const size_t kDefaultMaxTailLossProbes = 2; | 
| 46 static const int64 kMinTailLossProbeTimeoutMs = 10; | 46 static const int64_t kMinTailLossProbeTimeoutMs = 10; | 
| 47 | 47 | 
| 48 // Number of unpaced packets to send after quiescence. | 48 // Number of unpaced packets to send after quiescence. | 
| 49 static const size_t kInitialUnpacedBurst = 10; | 49 static const size_t kInitialUnpacedBurst = 10; | 
| 50 | 50 | 
| 51 bool HasCryptoHandshake(const TransmissionInfo& transmission_info) { | 51 bool HasCryptoHandshake(const TransmissionInfo& transmission_info) { | 
| 52   if (transmission_info.retransmittable_frames == nullptr) { | 52   if (transmission_info.retransmittable_frames == nullptr) { | 
| 53     return false; | 53     return false; | 
| 54   } | 54   } | 
| 55   return transmission_info.retransmittable_frames->HasCryptoHandshake() == | 55   return transmission_info.retransmittable_frames->HasCryptoHandshake() == | 
| 56          IS_HANDSHAKE; | 56          IS_HANDSHAKE; | 
| (...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 179 | 179 | 
| 180   if (network_change_visitor_ != nullptr) { | 180   if (network_change_visitor_ != nullptr) { | 
| 181     network_change_visitor_->OnCongestionWindowChange(); | 181     network_change_visitor_->OnCongestionWindowChange(); | 
| 182   } | 182   } | 
| 183 } | 183 } | 
| 184 | 184 | 
| 185 void QuicSentPacketManager::ResumeConnectionState( | 185 void QuicSentPacketManager::ResumeConnectionState( | 
| 186     const CachedNetworkParameters& cached_network_params, | 186     const CachedNetworkParameters& cached_network_params, | 
| 187     bool max_bandwidth_resumption) { | 187     bool max_bandwidth_resumption) { | 
| 188   if (cached_network_params.has_min_rtt_ms()) { | 188   if (cached_network_params.has_min_rtt_ms()) { | 
| 189     uint32 initial_rtt_us = | 189     uint32_t initial_rtt_us = | 
| 190         kNumMicrosPerMilli * cached_network_params.min_rtt_ms(); | 190         kNumMicrosPerMilli * cached_network_params.min_rtt_ms(); | 
| 191     rtt_stats_.set_initial_rtt_us( | 191     rtt_stats_.set_initial_rtt_us( | 
| 192         max(kMinInitialRoundTripTimeUs, | 192         max(kMinInitialRoundTripTimeUs, | 
| 193             min(kMaxInitialRoundTripTimeUs, initial_rtt_us))); | 193             min(kMaxInitialRoundTripTimeUs, initial_rtt_us))); | 
| 194   } | 194   } | 
| 195   send_algorithm_->ResumeConnectionState(cached_network_params, | 195   send_algorithm_->ResumeConnectionState(cached_network_params, | 
| 196                                          max_bandwidth_resumption); | 196                                          max_bandwidth_resumption); | 
| 197 } | 197 } | 
| 198 | 198 | 
| 199 void QuicSentPacketManager::SetNumOpenStreams(size_t num_streams) { | 199 void QuicSentPacketManager::SetNumOpenStreams(size_t num_streams) { | 
| (...skipping 669 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 869 } | 869 } | 
| 870 | 870 | 
| 871 const QuicTime::Delta QuicSentPacketManager::GetCryptoRetransmissionDelay() | 871 const QuicTime::Delta QuicSentPacketManager::GetCryptoRetransmissionDelay() | 
| 872     const { | 872     const { | 
| 873   // This is equivalent to the TailLossProbeDelay, but slightly more aggressive | 873   // This is equivalent to the TailLossProbeDelay, but slightly more aggressive | 
| 874   // because crypto handshake messages don't incur a delayed ack time. | 874   // because crypto handshake messages don't incur a delayed ack time. | 
| 875   QuicTime::Delta srtt = rtt_stats_.smoothed_rtt(); | 875   QuicTime::Delta srtt = rtt_stats_.smoothed_rtt(); | 
| 876   if (srtt.IsZero()) { | 876   if (srtt.IsZero()) { | 
| 877     srtt = QuicTime::Delta::FromMicroseconds(rtt_stats_.initial_rtt_us()); | 877     srtt = QuicTime::Delta::FromMicroseconds(rtt_stats_.initial_rtt_us()); | 
| 878   } | 878   } | 
| 879   int64 delay_ms = max(kMinHandshakeTimeoutMs, | 879   int64_t delay_ms = max(kMinHandshakeTimeoutMs, | 
| 880                        static_cast<int64>(1.5 * srtt.ToMilliseconds())); | 880                          static_cast<int64_t>(1.5 * srtt.ToMilliseconds())); | 
| 881   return QuicTime::Delta::FromMilliseconds( | 881   return QuicTime::Delta::FromMilliseconds( | 
| 882       delay_ms << consecutive_crypto_retransmission_count_); | 882       delay_ms << consecutive_crypto_retransmission_count_); | 
| 883 } | 883 } | 
| 884 | 884 | 
| 885 const QuicTime::Delta QuicSentPacketManager::GetTailLossProbeDelay() const { | 885 const QuicTime::Delta QuicSentPacketManager::GetTailLossProbeDelay() const { | 
| 886   QuicTime::Delta srtt = rtt_stats_.smoothed_rtt(); | 886   QuicTime::Delta srtt = rtt_stats_.smoothed_rtt(); | 
| 887   if (srtt.IsZero()) { | 887   if (srtt.IsZero()) { | 
| 888     srtt = QuicTime::Delta::FromMicroseconds(rtt_stats_.initial_rtt_us()); | 888     srtt = QuicTime::Delta::FromMicroseconds(rtt_stats_.initial_rtt_us()); | 
| 889   } | 889   } | 
| 890   if (enable_half_rtt_tail_loss_probe_ && consecutive_tlp_count_ == 0u) { | 890   if (enable_half_rtt_tail_loss_probe_ && consecutive_tlp_count_ == 0u) { | 
| 891     return QuicTime::Delta::FromMilliseconds( | 891     return QuicTime::Delta::FromMilliseconds( | 
| 892         max(kMinTailLossProbeTimeoutMs, | 892         max(kMinTailLossProbeTimeoutMs, | 
| 893             static_cast<int64>(0.5 * srtt.ToMilliseconds()))); | 893             static_cast<int64_t>(0.5 * srtt.ToMilliseconds()))); | 
| 894   } | 894   } | 
| 895   if (!unacked_packets_.HasMultipleInFlightPackets()) { | 895   if (!unacked_packets_.HasMultipleInFlightPackets()) { | 
| 896     return QuicTime::Delta::Max( | 896     return QuicTime::Delta::Max( | 
| 897         srtt.Multiply(2), | 897         srtt.Multiply(2), | 
| 898         srtt.Multiply(1.5).Add( | 898         srtt.Multiply(1.5).Add( | 
| 899             QuicTime::Delta::FromMilliseconds(kMinRetransmissionTimeMs / 2))); | 899             QuicTime::Delta::FromMilliseconds(kMinRetransmissionTimeMs / 2))); | 
| 900   } | 900   } | 
| 901   return QuicTime::Delta::FromMilliseconds( | 901   return QuicTime::Delta::FromMilliseconds( | 
| 902       max(kMinTailLossProbeTimeoutMs, | 902       max(kMinTailLossProbeTimeoutMs, | 
| 903           static_cast<int64>(2 * srtt.ToMilliseconds()))); | 903           static_cast<int64_t>(2 * srtt.ToMilliseconds()))); | 
| 904 } | 904 } | 
| 905 | 905 | 
| 906 const QuicTime::Delta QuicSentPacketManager::GetRetransmissionDelay() const { | 906 const QuicTime::Delta QuicSentPacketManager::GetRetransmissionDelay() const { | 
| 907   QuicTime::Delta retransmission_delay = send_algorithm_->RetransmissionDelay(); | 907   QuicTime::Delta retransmission_delay = send_algorithm_->RetransmissionDelay(); | 
| 908   if (retransmission_delay.IsZero()) { | 908   if (retransmission_delay.IsZero()) { | 
| 909     // We are in the initial state, use default timeout values. | 909     // We are in the initial state, use default timeout values. | 
| 910     retransmission_delay = | 910     retransmission_delay = | 
| 911         QuicTime::Delta::FromMilliseconds(kDefaultRetransmissionTimeMs); | 911         QuicTime::Delta::FromMilliseconds(kDefaultRetransmissionTimeMs); | 
| 912   } else if (retransmission_delay.ToMilliseconds() < kMinRetransmissionTimeMs) { | 912   } else if (retransmission_delay.ToMilliseconds() < kMinRetransmissionTimeMs) { | 
| 913     retransmission_delay = | 913     retransmission_delay = | 
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 993     // Rtt and cwnd do not need to be reset when the peer address change is | 993     // Rtt and cwnd do not need to be reset when the peer address change is | 
| 994     // considered to be caused by NATs. | 994     // considered to be caused by NATs. | 
| 995     return; | 995     return; | 
| 996   } | 996   } | 
| 997 | 997 | 
| 998   rtt_stats_.OnConnectionMigration(); | 998   rtt_stats_.OnConnectionMigration(); | 
| 999   send_algorithm_->OnConnectionMigration(); | 999   send_algorithm_->OnConnectionMigration(); | 
| 1000 } | 1000 } | 
| 1001 | 1001 | 
| 1002 }  // namespace net | 1002 }  // namespace net | 
| OLD | NEW | 
|---|