QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 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 |
| 3 | // found in the LICENSE file. |
| 4 | |
| 5 | #include "net/third_party/quiche/src/quic/core/quic_sent_packet_manager.h" |
| 6 | |
| 7 | #include <algorithm> |
vasilvv | 872e7a3 | 2019-03-12 16:42:44 -0700 | [diff] [blame] | 8 | #include <string> |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 9 | |
| 10 | #include "net/third_party/quiche/src/quic/core/congestion_control/general_loss_algorithm.h" |
| 11 | #include "net/third_party/quiche/src/quic/core/congestion_control/pacing_sender.h" |
| 12 | #include "net/third_party/quiche/src/quic/core/crypto/crypto_protocol.h" |
dschinazi | 56fb53e | 2019-06-21 15:30:04 -0700 | [diff] [blame] | 13 | #include "net/third_party/quiche/src/quic/core/proto/cached_network_parameters_proto.h" |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 14 | #include "net/third_party/quiche/src/quic/core/quic_connection_stats.h" |
wub | 967ba57 | 2019-04-01 09:27:52 -0700 | [diff] [blame] | 15 | #include "net/third_party/quiche/src/quic/core/quic_types.h" |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 16 | #include "net/third_party/quiche/src/quic/core/quic_utils.h" |
| 17 | #include "net/third_party/quiche/src/quic/platform/api/quic_bug_tracker.h" |
| 18 | #include "net/third_party/quiche/src/quic/platform/api/quic_flag_utils.h" |
| 19 | #include "net/third_party/quiche/src/quic/platform/api/quic_flags.h" |
| 20 | #include "net/third_party/quiche/src/quic/platform/api/quic_logging.h" |
| 21 | #include "net/third_party/quiche/src/quic/platform/api/quic_map_util.h" |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 22 | |
| 23 | namespace quic { |
| 24 | |
| 25 | namespace { |
| 26 | static const int64_t kDefaultRetransmissionTimeMs = 500; |
| 27 | static const int64_t kMaxRetransmissionTimeMs = 60000; |
| 28 | // Maximum number of exponential backoffs used for RTO timeouts. |
| 29 | static const size_t kMaxRetransmissions = 10; |
| 30 | // Maximum number of packets retransmitted upon an RTO. |
| 31 | static const size_t kMaxRetransmissionsOnTimeout = 2; |
| 32 | // The path degrading delay is the sum of this number of consecutive RTO delays. |
| 33 | const size_t kNumRetransmissionDelaysForPathDegradingDelay = 2; |
| 34 | |
| 35 | // Ensure the handshake timer isnt't faster than 10ms. |
| 36 | // This limits the tenth retransmitted packet to 10s after the initial CHLO. |
| 37 | static const int64_t kMinHandshakeTimeoutMs = 10; |
| 38 | |
| 39 | // Sends up to two tail loss probes before firing an RTO, |
| 40 | // per draft RFC draft-dukkipati-tcpm-tcp-loss-probe. |
| 41 | static const size_t kDefaultMaxTailLossProbes = 2; |
| 42 | |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 43 | // Returns true of retransmissions of the specified type should retransmit |
| 44 | // the frames directly (as opposed to resulting in a loss notification). |
| 45 | inline bool ShouldForceRetransmission(TransmissionType transmission_type) { |
| 46 | return transmission_type == HANDSHAKE_RETRANSMISSION || |
| 47 | transmission_type == TLP_RETRANSMISSION || |
| 48 | transmission_type == PROBING_RETRANSMISSION || |
fayang | 73d0ac4 | 2019-10-31 12:45:31 -0700 | [diff] [blame] | 49 | transmission_type == RTO_RETRANSMISSION || |
| 50 | transmission_type == PTO_RETRANSMISSION; |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 51 | } |
| 52 | |
fayang | 4ba5598 | 2019-05-13 05:53:22 -0700 | [diff] [blame] | 53 | // If pacing rate is accurate, > 2 burst token is not likely to help first ACK |
| 54 | // to arrive earlier, and overly large burst token could cause incast packet |
| 55 | // losses. |
| 56 | static const uint32_t kConservativeUnpacedBurst = 2; |
| 57 | |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 58 | } // namespace |
| 59 | |
| 60 | #define ENDPOINT \ |
| 61 | (unacked_packets_.perspective() == Perspective::IS_SERVER ? "Server: " \ |
| 62 | : "Client: ") |
| 63 | |
| 64 | QuicSentPacketManager::QuicSentPacketManager( |
| 65 | Perspective perspective, |
| 66 | const QuicClock* clock, |
QUICHE team | 73957f1 | 2019-04-18 16:21:52 -0700 | [diff] [blame] | 67 | QuicRandom* random, |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 68 | QuicConnectionStats* stats, |
fayang | 3be090d | 2020-02-11 14:05:08 -0800 | [diff] [blame] | 69 | CongestionControlType congestion_control_type) |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 70 | : unacked_packets_(perspective), |
| 71 | clock_(clock), |
QUICHE team | 73957f1 | 2019-04-18 16:21:52 -0700 | [diff] [blame] | 72 | random_(random), |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 73 | stats_(stats), |
| 74 | debug_delegate_(nullptr), |
| 75 | network_change_visitor_(nullptr), |
| 76 | initial_congestion_window_(kInitialCongestionWindow), |
ianswett | 34030d0 | 2020-04-10 07:57:15 -0700 | [diff] [blame] | 77 | loss_algorithm_(&uber_loss_algorithm_), |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 78 | consecutive_rto_count_(0), |
| 79 | consecutive_tlp_count_(0), |
| 80 | consecutive_crypto_retransmission_count_(0), |
| 81 | pending_timer_transmission_count_(0), |
| 82 | max_tail_loss_probes_(kDefaultMaxTailLossProbes), |
| 83 | max_rto_packets_(kMaxRetransmissionsOnTimeout), |
| 84 | enable_half_rtt_tail_loss_probe_(false), |
| 85 | using_pacing_(false), |
| 86 | use_new_rto_(false), |
| 87 | conservative_handshake_retransmits_(false), |
| 88 | min_tlp_timeout_( |
| 89 | QuicTime::Delta::FromMilliseconds(kMinTailLossProbeTimeoutMs)), |
| 90 | min_rto_timeout_( |
| 91 | QuicTime::Delta::FromMilliseconds(kMinRetransmissionTimeMs)), |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 92 | largest_mtu_acked_(0), |
fayang | 63a1984 | 2020-01-23 02:51:28 -0800 | [diff] [blame] | 93 | handshake_finished_(false), |
fkastenholz | 59c653b | 2019-07-15 09:55:53 -0700 | [diff] [blame] | 94 | peer_max_ack_delay_( |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 95 | QuicTime::Delta::FromMilliseconds(kDefaultDelayedAckTimeMs)), |
| 96 | rtt_updated_(false), |
QUICHE team | 9929cc4 | 2019-03-13 08:17:43 -0700 | [diff] [blame] | 97 | acked_packets_iter_(last_ack_frame_.packets.rbegin()), |
fayang | 5d01198 | 2020-05-13 14:14:38 -0700 | [diff] [blame] | 98 | pto_enabled_(GetQuicReloadableFlag(quic_default_on_pto)), |
fayang | ce0a316 | 2019-08-15 09:05:36 -0700 | [diff] [blame] | 99 | max_probe_packets_per_pto_(2), |
| 100 | consecutive_pto_count_(0), |
fayang | 19d2d5b | 2019-09-11 14:22:03 -0700 | [diff] [blame] | 101 | handshake_mode_disabled_(false), |
fayang | 4c908f0 | 2019-11-01 07:26:17 -0700 | [diff] [blame] | 102 | skip_packet_number_for_pto_(false), |
| 103 | always_include_max_ack_delay_for_pto_timeout_(true), |
fayang | 7085a6d | 2019-11-04 07:03:57 -0800 | [diff] [blame] | 104 | pto_exponential_backoff_start_point_(0), |
fayang | 75db434 | 2019-11-04 13:29:14 -0800 | [diff] [blame] | 105 | pto_rttvar_multiplier_(4), |
fayang | 4aa2240 | 2020-01-07 11:36:07 -0800 | [diff] [blame] | 106 | num_tlp_timeout_ptos_(0), |
fayang | 9a0e1bd | 2020-02-19 13:13:04 -0800 | [diff] [blame] | 107 | one_rtt_packet_acked_(false), |
fayang | 2ccfbcf | 2020-02-28 12:37:08 -0800 | [diff] [blame] | 108 | one_rtt_packet_sent_(false), |
fayang | c2fd610 | 2020-03-02 17:27:38 -0800 | [diff] [blame] | 109 | first_pto_srtt_multiplier_(0), |
fayang | bc9f56f | 2020-06-19 03:49:22 -0700 | [diff] [blame] | 110 | use_standard_deviation_for_pto_(false), |
| 111 | pto_multiplier_without_rtt_samples_(3) { |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 112 | SetSendAlgorithm(congestion_control_type); |
fayang | 5d01198 | 2020-05-13 14:14:38 -0700 | [diff] [blame] | 113 | if (pto_enabled_) { |
| 114 | QUIC_RELOADABLE_FLAG_COUNT_N(quic_default_on_pto, 1, 2); |
| 115 | // TODO(fayang): change the default values when deprecating |
| 116 | // quic_default_on_pto. |
| 117 | first_pto_srtt_multiplier_ = 1.5; |
| 118 | pto_rttvar_multiplier_ = 2; |
| 119 | } |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 120 | } |
| 121 | |
| 122 | QuicSentPacketManager::~QuicSentPacketManager() {} |
| 123 | |
| 124 | void QuicSentPacketManager::SetFromConfig(const QuicConfig& config) { |
| 125 | const Perspective perspective = unacked_packets_.perspective(); |
| 126 | if (config.HasReceivedInitialRoundTripTimeUs() && |
| 127 | config.ReceivedInitialRoundTripTimeUs() > 0) { |
| 128 | if (!config.HasClientSentConnectionOption(kNRTT, perspective)) { |
| 129 | SetInitialRtt(QuicTime::Delta::FromMicroseconds( |
| 130 | config.ReceivedInitialRoundTripTimeUs())); |
| 131 | } |
| 132 | } else if (config.HasInitialRoundTripTimeUsToSend() && |
| 133 | config.GetInitialRoundTripTimeUsToSend() > 0) { |
| 134 | SetInitialRtt(QuicTime::Delta::FromMicroseconds( |
| 135 | config.GetInitialRoundTripTimeUsToSend())); |
| 136 | } |
ianswett | 43eefae | 2019-08-02 12:27:15 -0700 | [diff] [blame] | 137 | if (config.HasReceivedMaxAckDelayMs()) { |
| 138 | peer_max_ack_delay_ = |
| 139 | QuicTime::Delta::FromMilliseconds(config.ReceivedMaxAckDelayMs()); |
| 140 | } |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 141 | if (config.HasClientSentConnectionOption(kMAD0, perspective)) { |
| 142 | rtt_stats_.set_ignore_max_ack_delay(true); |
| 143 | } |
| 144 | if (config.HasClientSentConnectionOption(kMAD1, perspective)) { |
ianswett | 43eefae | 2019-08-02 12:27:15 -0700 | [diff] [blame] | 145 | rtt_stats_.set_initial_max_ack_delay(peer_max_ack_delay_); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 146 | } |
ianswett | ad65ab9 | 2019-10-28 07:19:07 -0700 | [diff] [blame] | 147 | if (config.HasClientSentConnectionOption(kMAD2, perspective)) { |
| 148 | // Set the minimum to the alarm granularity. |
ianswett | 8f90e51 | 2019-12-18 10:50:27 -0800 | [diff] [blame] | 149 | min_tlp_timeout_ = kAlarmGranularity; |
ianswett | ad65ab9 | 2019-10-28 07:19:07 -0700 | [diff] [blame] | 150 | } |
| 151 | if (config.HasClientSentConnectionOption(kMAD3, perspective)) { |
| 152 | // Set the minimum to the alarm granularity. |
ianswett | 8f90e51 | 2019-12-18 10:50:27 -0800 | [diff] [blame] | 153 | min_rto_timeout_ = kAlarmGranularity; |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 154 | } |
| 155 | |
fayang | 961eaa0 | 2020-01-10 13:04:22 -0800 | [diff] [blame] | 156 | if (config.HasClientSentConnectionOption(k2PTO, perspective)) { |
| 157 | pto_enabled_ = true; |
| 158 | } |
| 159 | if (config.HasClientSentConnectionOption(k1PTO, perspective)) { |
| 160 | pto_enabled_ = true; |
| 161 | max_probe_packets_per_pto_ = 1; |
fayang | ce0a316 | 2019-08-15 09:05:36 -0700 | [diff] [blame] | 162 | } |
| 163 | |
fayang | 91ab42f | 2020-01-13 17:18:48 -0800 | [diff] [blame] | 164 | if (config.HasClientSentConnectionOption(kPTOS, perspective)) { |
fayang | 4c908f0 | 2019-11-01 07:26:17 -0700 | [diff] [blame] | 165 | if (!pto_enabled_) { |
| 166 | QUIC_PEER_BUG |
| 167 | << "PTO is not enabled when receiving PTOS connection option."; |
| 168 | pto_enabled_ = true; |
| 169 | max_probe_packets_per_pto_ = 1; |
| 170 | } |
| 171 | skip_packet_number_for_pto_ = true; |
| 172 | } |
| 173 | |
fayang | 7085a6d | 2019-11-04 07:03:57 -0800 | [diff] [blame] | 174 | if (pto_enabled_) { |
| 175 | if (config.HasClientSentConnectionOption(kPTOA, perspective)) { |
fayang | 7085a6d | 2019-11-04 07:03:57 -0800 | [diff] [blame] | 176 | always_include_max_ack_delay_for_pto_timeout_ = false; |
| 177 | } |
| 178 | if (config.HasClientSentConnectionOption(kPEB1, perspective)) { |
fayang | 7085a6d | 2019-11-04 07:03:57 -0800 | [diff] [blame] | 179 | StartExponentialBackoffAfterNthPto(1); |
| 180 | } |
| 181 | if (config.HasClientSentConnectionOption(kPEB2, perspective)) { |
fayang | 7085a6d | 2019-11-04 07:03:57 -0800 | [diff] [blame] | 182 | StartExponentialBackoffAfterNthPto(2); |
| 183 | } |
fayang | 75db434 | 2019-11-04 13:29:14 -0800 | [diff] [blame] | 184 | if (config.HasClientSentConnectionOption(kPVS1, perspective)) { |
fayang | 75db434 | 2019-11-04 13:29:14 -0800 | [diff] [blame] | 185 | pto_rttvar_multiplier_ = 2; |
| 186 | } |
fayang | 4aa2240 | 2020-01-07 11:36:07 -0800 | [diff] [blame] | 187 | if (config.HasClientSentConnectionOption(kPAG1, perspective)) { |
| 188 | QUIC_CODE_COUNT(one_aggressive_pto); |
| 189 | num_tlp_timeout_ptos_ = 1; |
| 190 | } |
| 191 | if (config.HasClientSentConnectionOption(kPAG2, perspective)) { |
| 192 | QUIC_CODE_COUNT(two_aggressive_ptos); |
| 193 | num_tlp_timeout_ptos_ = 2; |
| 194 | } |
fayang | a3745bc | 2020-04-06 10:51:03 -0700 | [diff] [blame] | 195 | if (config.HasClientSentConnectionOption(kPLE1, perspective) || |
| 196 | config.HasClientSentConnectionOption(kTLPR, perspective)) { |
| 197 | first_pto_srtt_multiplier_ = 0.5; |
| 198 | } else if (config.HasClientSentConnectionOption(kPLE2, perspective)) { |
| 199 | first_pto_srtt_multiplier_ = 1.5; |
fayang | 2ccfbcf | 2020-02-28 12:37:08 -0800 | [diff] [blame] | 200 | } |
fayang | bc9f56f | 2020-06-19 03:49:22 -0700 | [diff] [blame] | 201 | if (config.HasClientSentConnectionOption(kAPTO, perspective)) { |
| 202 | pto_multiplier_without_rtt_samples_ = 1.5; |
| 203 | } |
fayang | b86cd3f | 2020-04-06 09:04:25 -0700 | [diff] [blame] | 204 | if (config.HasClientSentConnectionOption(kPSDA, perspective)) { |
fayang | c2fd610 | 2020-03-02 17:27:38 -0800 | [diff] [blame] | 205 | use_standard_deviation_for_pto_ = true; |
| 206 | rtt_stats_.EnableStandardDeviationCalculation(); |
| 207 | } |
fayang | 4c908f0 | 2019-11-01 07:26:17 -0700 | [diff] [blame] | 208 | } |
| 209 | |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 210 | // Configure congestion control. |
| 211 | if (config.HasClientRequestedIndependentOption(kTBBR, perspective)) { |
| 212 | SetSendAlgorithm(kBBR); |
| 213 | } |
wub | a9a43cb | 2019-07-17 15:22:42 -0700 | [diff] [blame] | 214 | if (GetQuicReloadableFlag(quic_allow_client_enabled_bbr_v2) && |
| 215 | config.HasClientRequestedIndependentOption(kB2ON, perspective)) { |
| 216 | QUIC_RELOADABLE_FLAG_COUNT(quic_allow_client_enabled_bbr_v2); |
| 217 | SetSendAlgorithm(kBBRv2); |
| 218 | } |
| 219 | |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 220 | if (config.HasClientRequestedIndependentOption(kRENO, perspective)) { |
| 221 | SetSendAlgorithm(kRenoBytes); |
| 222 | } else if (config.HasClientRequestedIndependentOption(kBYTE, perspective) || |
| 223 | (GetQuicReloadableFlag(quic_default_to_bbr) && |
| 224 | config.HasClientRequestedIndependentOption(kQBIC, perspective))) { |
| 225 | SetSendAlgorithm(kCubicBytes); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 226 | } |
wub | a9a43cb | 2019-07-17 15:22:42 -0700 | [diff] [blame] | 227 | |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 228 | // Initial window. |
| 229 | if (GetQuicReloadableFlag(quic_unified_iw_options)) { |
| 230 | if (config.HasClientRequestedIndependentOption(kIW03, perspective)) { |
| 231 | initial_congestion_window_ = 3; |
| 232 | send_algorithm_->SetInitialCongestionWindowInPackets(3); |
| 233 | } |
| 234 | if (config.HasClientRequestedIndependentOption(kIW10, perspective)) { |
| 235 | initial_congestion_window_ = 10; |
| 236 | send_algorithm_->SetInitialCongestionWindowInPackets(10); |
| 237 | } |
| 238 | if (config.HasClientRequestedIndependentOption(kIW20, perspective)) { |
| 239 | initial_congestion_window_ = 20; |
| 240 | send_algorithm_->SetInitialCongestionWindowInPackets(20); |
| 241 | } |
| 242 | if (config.HasClientRequestedIndependentOption(kIW50, perspective)) { |
| 243 | initial_congestion_window_ = 50; |
| 244 | send_algorithm_->SetInitialCongestionWindowInPackets(50); |
| 245 | } |
| 246 | } |
fayang | 402103c | 2020-01-10 13:36:24 -0800 | [diff] [blame] | 247 | if (GetQuicReloadableFlag(quic_bbr_mitigate_overly_large_bandwidth_sample) && |
| 248 | config.HasClientRequestedIndependentOption(kBWS5, perspective)) { |
| 249 | initial_congestion_window_ = 10; |
| 250 | send_algorithm_->SetInitialCongestionWindowInPackets(10); |
| 251 | } |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 252 | |
danzh | 88e3e05 | 2019-06-13 11:47:18 -0700 | [diff] [blame] | 253 | using_pacing_ = !GetQuicFlag(FLAGS_quic_disable_pacing_for_perf_tests); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 254 | |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 255 | if (config.HasClientSentConnectionOption(kNTLP, perspective)) { |
| 256 | max_tail_loss_probes_ = 0; |
| 257 | } |
| 258 | if (config.HasClientSentConnectionOption(k1TLP, perspective)) { |
| 259 | max_tail_loss_probes_ = 1; |
| 260 | } |
| 261 | if (config.HasClientSentConnectionOption(k1RTO, perspective)) { |
| 262 | max_rto_packets_ = 1; |
| 263 | } |
| 264 | if (config.HasClientSentConnectionOption(kTLPR, perspective)) { |
| 265 | enable_half_rtt_tail_loss_probe_ = true; |
| 266 | } |
| 267 | if (config.HasClientSentConnectionOption(kNRTO, perspective)) { |
| 268 | use_new_rto_ = true; |
| 269 | } |
| 270 | // Configure loss detection. |
fayang | a590b75 | 2020-01-13 06:37:35 -0800 | [diff] [blame] | 271 | if (config.HasClientRequestedIndependentOption(kILD0, perspective)) { |
fayang | 3be090d | 2020-02-11 14:05:08 -0800 | [diff] [blame] | 272 | uber_loss_algorithm_.SetReorderingShift(kDefaultIetfLossDelayShift); |
| 273 | uber_loss_algorithm_.DisableAdaptiveReorderingThreshold(); |
fayang | a590b75 | 2020-01-13 06:37:35 -0800 | [diff] [blame] | 274 | } |
| 275 | if (config.HasClientRequestedIndependentOption(kILD1, perspective)) { |
fayang | a590b75 | 2020-01-13 06:37:35 -0800 | [diff] [blame] | 276 | uber_loss_algorithm_.SetReorderingShift(kDefaultLossDelayShift); |
fayang | 3be090d | 2020-02-11 14:05:08 -0800 | [diff] [blame] | 277 | uber_loss_algorithm_.DisableAdaptiveReorderingThreshold(); |
fayang | a590b75 | 2020-01-13 06:37:35 -0800 | [diff] [blame] | 278 | } |
| 279 | if (config.HasClientRequestedIndependentOption(kILD2, perspective)) { |
fayang | a590b75 | 2020-01-13 06:37:35 -0800 | [diff] [blame] | 280 | uber_loss_algorithm_.EnableAdaptiveReorderingThreshold(); |
fayang | 3be090d | 2020-02-11 14:05:08 -0800 | [diff] [blame] | 281 | uber_loss_algorithm_.SetReorderingShift(kDefaultIetfLossDelayShift); |
fayang | a590b75 | 2020-01-13 06:37:35 -0800 | [diff] [blame] | 282 | } |
| 283 | if (config.HasClientRequestedIndependentOption(kILD3, perspective)) { |
fayang | a590b75 | 2020-01-13 06:37:35 -0800 | [diff] [blame] | 284 | uber_loss_algorithm_.SetReorderingShift(kDefaultLossDelayShift); |
| 285 | uber_loss_algorithm_.EnableAdaptiveReorderingThreshold(); |
| 286 | } |
| 287 | if (config.HasClientRequestedIndependentOption(kILD4, perspective)) { |
fayang | a590b75 | 2020-01-13 06:37:35 -0800 | [diff] [blame] | 288 | uber_loss_algorithm_.SetReorderingShift(kDefaultLossDelayShift); |
| 289 | uber_loss_algorithm_.EnableAdaptiveReorderingThreshold(); |
| 290 | uber_loss_algorithm_.EnableAdaptiveTimeThreshold(); |
fayang | b0c7b4b | 2019-09-12 06:45:24 -0700 | [diff] [blame] | 291 | } |
fayang | 72e0263 | 2020-04-21 10:59:49 -0700 | [diff] [blame] | 292 | if (config.HasClientRequestedIndependentOption(kRUNT, perspective)) { |
fayang | 84427fc | 2020-03-09 12:43:26 -0700 | [diff] [blame] | 293 | uber_loss_algorithm_.DisablePacketThresholdForRuntPackets(); |
| 294 | } |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 295 | if (config.HasClientSentConnectionOption(kCONH, perspective)) { |
| 296 | conservative_handshake_retransmits_ = true; |
| 297 | } |
| 298 | send_algorithm_->SetFromConfig(config, perspective); |
wub | 5b00053 | 2020-04-07 08:29:03 -0700 | [diff] [blame] | 299 | loss_algorithm_->SetFromConfig(config, perspective); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 300 | |
| 301 | if (network_change_visitor_ != nullptr) { |
| 302 | network_change_visitor_->OnCongestionChange(); |
| 303 | } |
| 304 | } |
| 305 | |
wub | d09f1a6 | 2020-05-04 06:57:40 -0700 | [diff] [blame] | 306 | void QuicSentPacketManager::ApplyConnectionOptions( |
| 307 | const QuicTagVector& connection_options) { |
| 308 | send_algorithm_->ApplyConnectionOptions(connection_options); |
| 309 | } |
| 310 | |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 311 | void QuicSentPacketManager::ResumeConnectionState( |
| 312 | const CachedNetworkParameters& cached_network_params, |
| 313 | bool max_bandwidth_resumption) { |
| 314 | QuicBandwidth bandwidth = QuicBandwidth::FromBytesPerSecond( |
| 315 | max_bandwidth_resumption |
| 316 | ? cached_network_params.max_bandwidth_estimate_bytes_per_second() |
| 317 | : cached_network_params.bandwidth_estimate_bytes_per_second()); |
| 318 | QuicTime::Delta rtt = |
| 319 | QuicTime::Delta::FromMilliseconds(cached_network_params.min_rtt_ms()); |
QUICHE team | b4e187c | 2019-11-14 06:22:50 -0800 | [diff] [blame] | 320 | // This calls the old AdjustNetworkParameters interface, and fills certain |
| 321 | // fields in SendAlgorithmInterface::NetworkParams |
| 322 | // (e.g., quic_bbr_fix_pacing_rate) using GFE flags. |
| 323 | AdjustNetworkParameters(SendAlgorithmInterface::NetworkParams( |
| 324 | bandwidth, rtt, /*allow_cwnd_to_decrease = */ false)); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 325 | } |
| 326 | |
fayang | f1b99dc | 2019-05-14 06:29:18 -0700 | [diff] [blame] | 327 | void QuicSentPacketManager::AdjustNetworkParameters( |
QUICHE team | fdcfe3b | 2019-11-06 10:54:25 -0800 | [diff] [blame] | 328 | const SendAlgorithmInterface::NetworkParams& params) { |
QUICHE team | b4e187c | 2019-11-14 06:22:50 -0800 | [diff] [blame] | 329 | const QuicBandwidth& bandwidth = params.bandwidth; |
| 330 | const QuicTime::Delta& rtt = params.rtt; |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 331 | if (!rtt.IsZero()) { |
| 332 | SetInitialRtt(rtt); |
| 333 | } |
fayang | be83ecd | 2019-04-26 13:58:09 -0700 | [diff] [blame] | 334 | const QuicByteCount old_cwnd = send_algorithm_->GetCongestionWindow(); |
fayang | 6c2d64f | 2019-05-20 17:12:05 -0700 | [diff] [blame] | 335 | if (GetQuicReloadableFlag(quic_conservative_bursts) && using_pacing_ && |
| 336 | !bandwidth.IsZero()) { |
fayang | 4ba5598 | 2019-05-13 05:53:22 -0700 | [diff] [blame] | 337 | QUIC_RELOADABLE_FLAG_COUNT(quic_conservative_bursts); |
| 338 | pacing_sender_.SetBurstTokens(kConservativeUnpacedBurst); |
| 339 | } |
QUICHE team | b4e187c | 2019-11-14 06:22:50 -0800 | [diff] [blame] | 340 | send_algorithm_->AdjustNetworkParameters(params); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 341 | if (debug_delegate_ != nullptr) { |
fayang | be83ecd | 2019-04-26 13:58:09 -0700 | [diff] [blame] | 342 | debug_delegate_->OnAdjustNetworkParameters( |
QUICHE team | 780461d | 2020-05-07 12:14:50 -0700 | [diff] [blame] | 343 | bandwidth, rtt.IsZero() ? rtt_stats_.MinOrInitialRtt() : rtt, old_cwnd, |
| 344 | send_algorithm_->GetCongestionWindow()); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 345 | } |
| 346 | } |
| 347 | |
wub | 44e3305 | 2020-03-03 17:11:40 -0800 | [diff] [blame] | 348 | void QuicSentPacketManager::SetLossDetectionTuner( |
| 349 | std::unique_ptr<LossDetectionTunerInterface> tuner) { |
| 350 | uber_loss_algorithm_.SetLossDetectionTuner(std::move(tuner)); |
| 351 | } |
| 352 | |
| 353 | void QuicSentPacketManager::OnConfigNegotiated() { |
| 354 | loss_algorithm_->OnConfigNegotiated(); |
| 355 | } |
| 356 | |
| 357 | void QuicSentPacketManager::OnConnectionClosed() { |
| 358 | loss_algorithm_->OnConnectionClosed(); |
| 359 | } |
| 360 | |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 361 | void QuicSentPacketManager::SetHandshakeConfirmed() { |
fayang | 63a1984 | 2020-01-23 02:51:28 -0800 | [diff] [blame] | 362 | if (!handshake_finished_) { |
| 363 | handshake_finished_ = true; |
vasilvv | 975c235 | 2019-10-03 16:53:57 -0400 | [diff] [blame] | 364 | NeuterHandshakePackets(); |
| 365 | } |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 366 | } |
| 367 | |
fayang | 3eb8221 | 2019-04-16 12:05:46 -0700 | [diff] [blame] | 368 | void QuicSentPacketManager::PostProcessNewlyAckedPackets( |
fayang | f8e918b | 2019-07-16 13:03:16 -0700 | [diff] [blame] | 369 | QuicPacketNumber ack_packet_number, |
vasilvv | 923b6d2 | 2020-03-23 11:17:58 -0700 | [diff] [blame] | 370 | EncryptionLevel ack_decrypted_level, |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 371 | const QuicAckFrame& ack_frame, |
| 372 | QuicTime ack_receive_time, |
| 373 | bool rtt_updated, |
| 374 | QuicByteCount prior_bytes_in_flight) { |
fayang | cff885a | 2019-10-22 07:39:04 -0700 | [diff] [blame] | 375 | unacked_packets_.NotifyAggregatedStreamFrameAcked( |
| 376 | last_ack_frame_.ack_delay_time); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 377 | InvokeLossDetection(ack_receive_time); |
| 378 | // Ignore losses in RTO mode. |
| 379 | if (consecutive_rto_count_ > 0 && !use_new_rto_) { |
| 380 | packets_lost_.clear(); |
| 381 | } |
| 382 | MaybeInvokeCongestionEvent(rtt_updated, prior_bytes_in_flight, |
| 383 | ack_receive_time); |
| 384 | unacked_packets_.RemoveObsoletePackets(); |
| 385 | |
| 386 | sustained_bandwidth_recorder_.RecordEstimate( |
| 387 | send_algorithm_->InRecovery(), send_algorithm_->InSlowStart(), |
| 388 | send_algorithm_->BandwidthEstimate(), ack_receive_time, clock_->WallNow(), |
| 389 | rtt_stats_.smoothed_rtt()); |
| 390 | |
| 391 | // Anytime we are making forward progress and have a new RTT estimate, reset |
| 392 | // the backoff counters. |
| 393 | if (rtt_updated) { |
| 394 | if (consecutive_rto_count_ > 0) { |
| 395 | // If the ack acknowledges data sent prior to the RTO, |
| 396 | // the RTO was spurious. |
| 397 | if (LargestAcked(ack_frame) < first_rto_transmission_) { |
| 398 | // Replace SRTT with latest_rtt and increase the variance to prevent |
| 399 | // a spurious RTO from happening again. |
| 400 | rtt_stats_.ExpireSmoothedMetrics(); |
| 401 | } else { |
| 402 | if (!use_new_rto_) { |
| 403 | send_algorithm_->OnRetransmissionTimeout(true); |
| 404 | } |
| 405 | } |
| 406 | } |
fayang | 2a379bf | 2020-05-18 11:49:25 -0700 | [diff] [blame] | 407 | // Records the max consecutive RTO or PTO before forward progress has been |
| 408 | // made. |
| 409 | if (consecutive_rto_count_ > |
| 410 | stats_->max_consecutive_rto_with_forward_progress) { |
| 411 | stats_->max_consecutive_rto_with_forward_progress = |
| 412 | consecutive_rto_count_; |
| 413 | } else if (consecutive_pto_count_ > |
| 414 | stats_->max_consecutive_rto_with_forward_progress) { |
| 415 | stats_->max_consecutive_rto_with_forward_progress = |
| 416 | consecutive_pto_count_; |
| 417 | } |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 418 | // Reset all retransmit counters any time a new packet is acked. |
| 419 | consecutive_rto_count_ = 0; |
| 420 | consecutive_tlp_count_ = 0; |
fayang | ce0a316 | 2019-08-15 09:05:36 -0700 | [diff] [blame] | 421 | consecutive_pto_count_ = 0; |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 422 | consecutive_crypto_retransmission_count_ = 0; |
| 423 | } |
| 424 | |
| 425 | if (debug_delegate_ != nullptr) { |
vasilvv | 923b6d2 | 2020-03-23 11:17:58 -0700 | [diff] [blame] | 426 | debug_delegate_->OnIncomingAck( |
| 427 | ack_packet_number, ack_decrypted_level, ack_frame, ack_receive_time, |
| 428 | LargestAcked(ack_frame), rtt_updated, GetLeastUnacked()); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 429 | } |
| 430 | // Remove packets below least unacked from all_packets_acked_ and |
| 431 | // last_ack_frame_. |
| 432 | last_ack_frame_.packets.RemoveUpTo(unacked_packets_.GetLeastUnacked()); |
| 433 | last_ack_frame_.received_packet_times.clear(); |
| 434 | } |
| 435 | |
| 436 | void QuicSentPacketManager::MaybeInvokeCongestionEvent( |
| 437 | bool rtt_updated, |
| 438 | QuicByteCount prior_in_flight, |
| 439 | QuicTime event_time) { |
| 440 | if (!rtt_updated && packets_acked_.empty() && packets_lost_.empty()) { |
| 441 | return; |
| 442 | } |
| 443 | if (using_pacing_) { |
| 444 | pacing_sender_.OnCongestionEvent(rtt_updated, prior_in_flight, event_time, |
| 445 | packets_acked_, packets_lost_); |
| 446 | } else { |
| 447 | send_algorithm_->OnCongestionEvent(rtt_updated, prior_in_flight, event_time, |
| 448 | packets_acked_, packets_lost_); |
| 449 | } |
| 450 | packets_acked_.clear(); |
| 451 | packets_lost_.clear(); |
| 452 | if (network_change_visitor_ != nullptr) { |
| 453 | network_change_visitor_->OnCongestionChange(); |
| 454 | } |
| 455 | } |
| 456 | |
renjietang | c008008 | 2020-05-26 18:35:19 -0700 | [diff] [blame] | 457 | void QuicSentPacketManager::RetransmitZeroRttPackets() { |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 458 | QuicPacketNumber packet_number = unacked_packets_.GetLeastUnacked(); |
ianswett | 898306b | 2019-04-23 11:05:57 -0700 | [diff] [blame] | 459 | for (QuicUnackedPacketMap::iterator it = unacked_packets_.begin(); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 460 | it != unacked_packets_.end(); ++it, ++packet_number) { |
renjietang | c008008 | 2020-05-26 18:35:19 -0700 | [diff] [blame] | 461 | if (it->encryption_level == ENCRYPTION_ZERO_RTT) { |
ianswett | 0400465 | 2019-09-03 18:46:57 -0700 | [diff] [blame] | 462 | if (it->in_flight) { |
ianswett | 898306b | 2019-04-23 11:05:57 -0700 | [diff] [blame] | 463 | // Remove 0-RTT packets and packets of the wrong version from flight, |
| 464 | // because neither can be processed by the peer. |
| 465 | unacked_packets_.RemoveFromInFlight(&*it); |
| 466 | } |
| 467 | if (unacked_packets_.HasRetransmittableFrames(*it)) { |
renjietang | c0e6668 | 2020-06-02 11:11:37 -0700 | [diff] [blame] | 468 | MarkForRetransmission(packet_number, ALL_ZERO_RTT_RETRANSMISSION); |
ianswett | 898306b | 2019-04-23 11:05:57 -0700 | [diff] [blame] | 469 | } |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 470 | } |
| 471 | } |
| 472 | } |
| 473 | |
| 474 | void QuicSentPacketManager::NeuterUnencryptedPackets() { |
wub | f4ab965 | 2020-02-20 14:45:43 -0800 | [diff] [blame] | 475 | for (QuicPacketNumber packet_number : |
| 476 | unacked_packets_.NeuterUnencryptedPackets()) { |
wub | 6486321 | 2020-05-28 10:33:59 -0700 | [diff] [blame] | 477 | send_algorithm_->OnPacketNeutered(packet_number); |
wub | f4ab965 | 2020-02-20 14:45:43 -0800 | [diff] [blame] | 478 | } |
fayang | 4283494 | 2020-03-30 10:56:15 -0700 | [diff] [blame] | 479 | if (handshake_mode_disabled_) { |
| 480 | consecutive_pto_count_ = 0; |
| 481 | uber_loss_algorithm_.ResetLossDetection(INITIAL_DATA); |
| 482 | } |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 483 | } |
| 484 | |
| 485 | void QuicSentPacketManager::NeuterHandshakePackets() { |
wub | f4ab965 | 2020-02-20 14:45:43 -0800 | [diff] [blame] | 486 | for (QuicPacketNumber packet_number : |
| 487 | unacked_packets_.NeuterHandshakePackets()) { |
wub | 6486321 | 2020-05-28 10:33:59 -0700 | [diff] [blame] | 488 | send_algorithm_->OnPacketNeutered(packet_number); |
wub | f4ab965 | 2020-02-20 14:45:43 -0800 | [diff] [blame] | 489 | } |
fayang | 4283494 | 2020-03-30 10:56:15 -0700 | [diff] [blame] | 490 | if (handshake_mode_disabled_) { |
| 491 | consecutive_pto_count_ = 0; |
| 492 | uber_loss_algorithm_.ResetLossDetection(HANDSHAKE_DATA); |
| 493 | } |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 494 | } |
| 495 | |
fayang | 4c908f0 | 2019-11-01 07:26:17 -0700 | [diff] [blame] | 496 | bool QuicSentPacketManager::ShouldAddMaxAckDelay() const { |
| 497 | DCHECK(pto_enabled_); |
| 498 | if (always_include_max_ack_delay_for_pto_timeout_) { |
| 499 | return true; |
| 500 | } |
| 501 | if (!unacked_packets_ |
| 502 | .GetLargestSentRetransmittableOfPacketNumberSpace(APPLICATION_DATA) |
| 503 | .IsInitialized() || |
| 504 | unacked_packets_.GetLargestSentRetransmittableOfPacketNumberSpace( |
| 505 | APPLICATION_DATA) < |
| 506 | FirstSendingPacketNumber() + kMinReceivedBeforeAckDecimation - 1) { |
| 507 | // Peer is doing TCP style acking. Expect an immediate ACK if more than 1 |
| 508 | // packet are outstanding. |
| 509 | if (unacked_packets_.packets_in_flight() >= |
| 510 | kDefaultRetransmittablePacketsBeforeAck) { |
| 511 | return false; |
| 512 | } |
| 513 | } else if (unacked_packets_.packets_in_flight() >= |
| 514 | kMaxRetransmittablePacketsBeforeAck) { |
| 515 | // Peer is doing ack decimation. Expect an immediate ACK if >= 10 |
| 516 | // packets are outstanding. |
| 517 | return false; |
| 518 | } |
| 519 | if (skip_packet_number_for_pto_ && consecutive_pto_count_ > 0) { |
| 520 | // An immediate ACK is expected when doing PTOS. Please note, this will miss |
| 521 | // cases when PTO fires and turns out to be spurious. |
| 522 | return false; |
| 523 | } |
| 524 | return true; |
| 525 | } |
| 526 | |
fayang | 18ff23b | 2020-01-28 09:19:00 -0800 | [diff] [blame] | 527 | QuicTime QuicSentPacketManager::GetEarliestPacketSentTimeForPto( |
| 528 | PacketNumberSpace* packet_number_space) const { |
| 529 | DCHECK(supports_multiple_packet_number_spaces()); |
| 530 | QuicTime earliest_sent_time = QuicTime::Zero(); |
| 531 | for (int8_t i = 0; i < NUM_PACKET_NUMBER_SPACES; ++i) { |
| 532 | const QuicTime sent_time = unacked_packets_.GetLastInFlightPacketSentTime( |
| 533 | static_cast<PacketNumberSpace>(i)); |
fayang | 9a0e1bd | 2020-02-19 13:13:04 -0800 | [diff] [blame] | 534 | if (!ShouldArmPtoForApplicationData() && i == APPLICATION_DATA) { |
fayang | 18ff23b | 2020-01-28 09:19:00 -0800 | [diff] [blame] | 535 | continue; |
| 536 | } |
fayang | 9a0e1bd | 2020-02-19 13:13:04 -0800 | [diff] [blame] | 537 | if (!sent_time.IsInitialized() || (earliest_sent_time.IsInitialized() && |
| 538 | earliest_sent_time <= sent_time)) { |
| 539 | continue; |
fayang | 18ff23b | 2020-01-28 09:19:00 -0800 | [diff] [blame] | 540 | } |
fayang | 9a0e1bd | 2020-02-19 13:13:04 -0800 | [diff] [blame] | 541 | earliest_sent_time = sent_time; |
| 542 | *packet_number_space = static_cast<PacketNumberSpace>(i); |
fayang | 18ff23b | 2020-01-28 09:19:00 -0800 | [diff] [blame] | 543 | } |
fayang | 9a0e1bd | 2020-02-19 13:13:04 -0800 | [diff] [blame] | 544 | |
fayang | 18ff23b | 2020-01-28 09:19:00 -0800 | [diff] [blame] | 545 | return earliest_sent_time; |
| 546 | } |
| 547 | |
fayang | 9a0e1bd | 2020-02-19 13:13:04 -0800 | [diff] [blame] | 548 | bool QuicSentPacketManager::ShouldArmPtoForApplicationData() const { |
| 549 | DCHECK(supports_multiple_packet_number_spaces()); |
| 550 | // Application data must be ignored before handshake completes (1-RTT key |
| 551 | // is available). Not arming PTO for application data to prioritize the |
| 552 | // completion of handshake. On the server side, handshake_finished_ |
| 553 | // indicates handshake complete (and confirmed). On the client side, |
| 554 | // one_rtt_packet_sent_ indicates handshake complete (while handshake |
| 555 | // confirmation will happen later). |
| 556 | return handshake_finished_ || |
| 557 | (unacked_packets_.perspective() == Perspective::IS_CLIENT && |
| 558 | one_rtt_packet_sent_); |
| 559 | } |
| 560 | |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 561 | void QuicSentPacketManager::MarkForRetransmission( |
| 562 | QuicPacketNumber packet_number, |
| 563 | TransmissionType transmission_type) { |
| 564 | QuicTransmissionInfo* transmission_info = |
| 565 | unacked_packets_.GetMutableTransmissionInfo(packet_number); |
fayang | cff885a | 2019-10-22 07:39:04 -0700 | [diff] [blame] | 566 | // A previous RTO retransmission may cause connection close; packets without |
| 567 | // retransmittable frames can be marked for loss retransmissions. |
| 568 | QUIC_BUG_IF(transmission_type != LOSS_RETRANSMISSION && |
| 569 | transmission_type != RTO_RETRANSMISSION && |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 570 | !unacked_packets_.HasRetransmittableFrames(*transmission_info)) |
renjietang | 2b5e662 | 2020-06-02 15:19:40 -0700 | [diff] [blame] | 571 | << "transmission_type: " << transmission_type; |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 572 | // Handshake packets should never be sent as probing retransmissions. |
fayang | 73d0ac4 | 2019-10-31 12:45:31 -0700 | [diff] [blame] | 573 | DCHECK(!transmission_info->has_crypto_handshake || |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 574 | transmission_type != PROBING_RETRANSMISSION); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 575 | |
| 576 | HandleRetransmission(transmission_type, transmission_info); |
| 577 | |
| 578 | // Update packet state according to transmission type. |
| 579 | transmission_info->state = |
| 580 | QuicUtils::RetransmissionTypeToPacketState(transmission_type); |
| 581 | } |
| 582 | |
| 583 | void QuicSentPacketManager::HandleRetransmission( |
| 584 | TransmissionType transmission_type, |
| 585 | QuicTransmissionInfo* transmission_info) { |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 586 | if (ShouldForceRetransmission(transmission_type)) { |
| 587 | // TODO(fayang): Consider to make RTO and PROBING retransmission |
| 588 | // strategies be configurable by applications. Today, TLP, RTO and PROBING |
| 589 | // retransmissions are handled similarly, i.e., always retranmist the |
| 590 | // oldest outstanding data. This is not ideal in general because different |
| 591 | // applications may want different strategies. For example, some |
| 592 | // applications may want to use higher priority stream data for bandwidth |
| 593 | // probing, and some applications want to consider RTO is an indication of |
| 594 | // loss, etc. |
| 595 | unacked_packets_.RetransmitFrames(*transmission_info, transmission_type); |
| 596 | return; |
| 597 | } |
| 598 | |
| 599 | unacked_packets_.NotifyFramesLost(*transmission_info, transmission_type); |
| 600 | if (transmission_info->retransmittable_frames.empty()) { |
| 601 | return; |
| 602 | } |
| 603 | |
| 604 | if (transmission_type == LOSS_RETRANSMISSION) { |
| 605 | // Record the first packet sent after loss, which allows to wait 1 |
| 606 | // more RTT before giving up on this lost packet. |
| 607 | transmission_info->retransmission = |
| 608 | unacked_packets_.largest_sent_packet() + 1; |
| 609 | } else { |
| 610 | // Clear the recorded first packet sent after loss when version or |
| 611 | // encryption changes. |
| 612 | transmission_info->retransmission.Clear(); |
| 613 | } |
| 614 | } |
| 615 | |
| 616 | void QuicSentPacketManager::RecordOneSpuriousRetransmission( |
| 617 | const QuicTransmissionInfo& info) { |
| 618 | stats_->bytes_spuriously_retransmitted += info.bytes_sent; |
| 619 | ++stats_->packets_spuriously_retransmitted; |
| 620 | if (debug_delegate_ != nullptr) { |
| 621 | debug_delegate_->OnSpuriousPacketRetransmission(info.transmission_type, |
| 622 | info.bytes_sent); |
| 623 | } |
| 624 | } |
| 625 | |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 626 | void QuicSentPacketManager::MarkPacketHandled(QuicPacketNumber packet_number, |
| 627 | QuicTransmissionInfo* info, |
fayang | 19d2d5b | 2019-09-11 14:22:03 -0700 | [diff] [blame] | 628 | QuicTime ack_receive_time, |
QUICHE team | 9467db0 | 2019-05-30 09:38:45 -0700 | [diff] [blame] | 629 | QuicTime::Delta ack_delay_time, |
| 630 | QuicTime receive_timestamp) { |
fayang | cff885a | 2019-10-22 07:39:04 -0700 | [diff] [blame] | 631 | // Try to aggregate acked stream frames if acked packet is not a |
| 632 | // retransmission. |
| 633 | if (info->transmission_type == NOT_RETRANSMISSION) { |
| 634 | unacked_packets_.MaybeAggregateAckedStreamFrame(*info, ack_delay_time, |
| 635 | receive_timestamp); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 636 | } else { |
fayang | cff885a | 2019-10-22 07:39:04 -0700 | [diff] [blame] | 637 | unacked_packets_.NotifyAggregatedStreamFrameAcked(ack_delay_time); |
| 638 | const bool new_data_acked = unacked_packets_.NotifyFramesAcked( |
| 639 | *info, ack_delay_time, receive_timestamp); |
| 640 | if (!new_data_acked && info->transmission_type != NOT_RETRANSMISSION) { |
| 641 | // Record as a spurious retransmission if this packet is a |
| 642 | // retransmission and no new data gets acked. |
| 643 | QUIC_DVLOG(1) << "Detect spurious retransmitted packet " << packet_number |
renjietang | 2b5e662 | 2020-06-02 15:19:40 -0700 | [diff] [blame] | 644 | << " transmission type: " << info->transmission_type; |
fayang | cc4ea6a | 2019-10-25 08:44:03 -0700 | [diff] [blame] | 645 | RecordOneSpuriousRetransmission(*info); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 646 | } |
| 647 | } |
fayang | cc4ea6a | 2019-10-25 08:44:03 -0700 | [diff] [blame] | 648 | if (info->state == LOST) { |
fayang | cff885a | 2019-10-22 07:39:04 -0700 | [diff] [blame] | 649 | // Record as a spurious loss as a packet previously declared lost gets |
| 650 | // acked. |
fayang | cff885a | 2019-10-22 07:39:04 -0700 | [diff] [blame] | 651 | const PacketNumberSpace packet_number_space = |
| 652 | unacked_packets_.GetPacketNumberSpace(info->encryption_level); |
| 653 | const QuicPacketNumber previous_largest_acked = |
| 654 | supports_multiple_packet_number_spaces() |
| 655 | ? unacked_packets_.GetLargestAckedOfPacketNumberSpace( |
| 656 | packet_number_space) |
| 657 | : unacked_packets_.largest_acked(); |
| 658 | QUIC_DVLOG(1) << "Packet " << packet_number |
| 659 | << " was detected lost spuriously, " |
| 660 | "previous_largest_acked: " |
| 661 | << previous_largest_acked; |
| 662 | loss_algorithm_->SpuriousLossDetected(unacked_packets_, rtt_stats_, |
| 663 | ack_receive_time, packet_number, |
| 664 | previous_largest_acked); |
wub | 02831dc | 2020-02-28 12:00:54 -0800 | [diff] [blame] | 665 | ++stats_->packet_spuriously_detected_lost; |
fayang | cff885a | 2019-10-22 07:39:04 -0700 | [diff] [blame] | 666 | } |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 667 | |
| 668 | if (network_change_visitor_ != nullptr && |
| 669 | info->bytes_sent > largest_mtu_acked_) { |
| 670 | largest_mtu_acked_ = info->bytes_sent; |
| 671 | network_change_visitor_->OnPathMtuIncreased(largest_mtu_acked_); |
| 672 | } |
| 673 | unacked_packets_.RemoveFromInFlight(info); |
| 674 | unacked_packets_.RemoveRetransmittability(info); |
| 675 | info->state = ACKED; |
| 676 | } |
| 677 | |
| 678 | bool QuicSentPacketManager::OnPacketSent( |
| 679 | SerializedPacket* serialized_packet, |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 680 | QuicTime sent_time, |
| 681 | TransmissionType transmission_type, |
| 682 | HasRetransmittableData has_retransmittable_data) { |
| 683 | QuicPacketNumber packet_number = serialized_packet->packet_number; |
| 684 | DCHECK_LE(FirstSendingPacketNumber(), packet_number); |
| 685 | DCHECK(!unacked_packets_.IsUnacked(packet_number)); |
| 686 | QUIC_BUG_IF(serialized_packet->encrypted_length == 0) |
| 687 | << "Cannot send empty packets."; |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 688 | if (pending_timer_transmission_count_ > 0) { |
| 689 | --pending_timer_transmission_count_; |
| 690 | } |
| 691 | |
| 692 | bool in_flight = has_retransmittable_data == HAS_RETRANSMITTABLE_DATA; |
| 693 | if (using_pacing_) { |
| 694 | pacing_sender_.OnPacketSent( |
| 695 | sent_time, unacked_packets_.bytes_in_flight(), packet_number, |
| 696 | serialized_packet->encrypted_length, has_retransmittable_data); |
| 697 | } else { |
| 698 | send_algorithm_->OnPacketSent( |
| 699 | sent_time, unacked_packets_.bytes_in_flight(), packet_number, |
| 700 | serialized_packet->encrypted_length, has_retransmittable_data); |
| 701 | } |
| 702 | |
fayang | 9a0e1bd | 2020-02-19 13:13:04 -0800 | [diff] [blame] | 703 | if (serialized_packet->encryption_level == ENCRYPTION_FORWARD_SECURE) { |
| 704 | one_rtt_packet_sent_ = true; |
| 705 | } |
| 706 | |
fayang | cff885a | 2019-10-22 07:39:04 -0700 | [diff] [blame] | 707 | unacked_packets_.AddSentPacket(serialized_packet, transmission_type, |
| 708 | sent_time, in_flight); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 709 | // Reset the retransmission timer anytime a pending packet is sent. |
| 710 | return in_flight; |
| 711 | } |
| 712 | |
fayang | 67f8227 | 2019-08-14 16:08:45 -0700 | [diff] [blame] | 713 | QuicSentPacketManager::RetransmissionTimeoutMode |
| 714 | QuicSentPacketManager::OnRetransmissionTimeout() { |
fayang | 5f13505 | 2019-08-22 17:59:40 -0700 | [diff] [blame] | 715 | DCHECK(unacked_packets_.HasInFlightPackets() || |
fayang | 63a1984 | 2020-01-23 02:51:28 -0800 | [diff] [blame] | 716 | (handshake_mode_disabled_ && !handshake_finished_)); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 717 | DCHECK_EQ(0u, pending_timer_transmission_count_); |
| 718 | // Handshake retransmission, timer based loss detection, TLP, and RTO are |
| 719 | // implemented with a single alarm. The handshake alarm is set when the |
| 720 | // handshake has not completed, the loss alarm is set when the loss detection |
| 721 | // algorithm says to, and the TLP and RTO alarms are set after that. |
| 722 | // The TLP alarm is always set to run for under an RTO. |
| 723 | switch (GetRetransmissionMode()) { |
| 724 | case HANDSHAKE_MODE: |
fayang | 5f13505 | 2019-08-22 17:59:40 -0700 | [diff] [blame] | 725 | DCHECK(!handshake_mode_disabled_); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 726 | ++stats_->crypto_retransmit_count; |
| 727 | RetransmitCryptoPackets(); |
fayang | 67f8227 | 2019-08-14 16:08:45 -0700 | [diff] [blame] | 728 | return HANDSHAKE_MODE; |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 729 | case LOSS_MODE: { |
| 730 | ++stats_->loss_timeout_count; |
| 731 | QuicByteCount prior_in_flight = unacked_packets_.bytes_in_flight(); |
| 732 | const QuicTime now = clock_->Now(); |
| 733 | InvokeLossDetection(now); |
| 734 | MaybeInvokeCongestionEvent(false, prior_in_flight, now); |
fayang | 67f8227 | 2019-08-14 16:08:45 -0700 | [diff] [blame] | 735 | return LOSS_MODE; |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 736 | } |
| 737 | case TLP_MODE: |
| 738 | ++stats_->tlp_count; |
| 739 | ++consecutive_tlp_count_; |
| 740 | pending_timer_transmission_count_ = 1; |
| 741 | // TLPs prefer sending new data instead of retransmitting data, so |
| 742 | // give the connection a chance to write before completing the TLP. |
fayang | 67f8227 | 2019-08-14 16:08:45 -0700 | [diff] [blame] | 743 | return TLP_MODE; |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 744 | case RTO_MODE: |
| 745 | ++stats_->rto_count; |
| 746 | RetransmitRtoPackets(); |
fayang | 67f8227 | 2019-08-14 16:08:45 -0700 | [diff] [blame] | 747 | return RTO_MODE; |
fayang | ce0a316 | 2019-08-15 09:05:36 -0700 | [diff] [blame] | 748 | case PTO_MODE: |
| 749 | QUIC_DVLOG(1) << ENDPOINT << "PTO mode"; |
| 750 | ++stats_->pto_count; |
fayang | af9903b | 2020-05-14 14:34:28 -0700 | [diff] [blame] | 751 | if (handshake_mode_disabled_ && !ShouldArmPtoForApplicationData()) { |
| 752 | ++stats_->crypto_retransmit_count; |
| 753 | } |
fayang | ce0a316 | 2019-08-15 09:05:36 -0700 | [diff] [blame] | 754 | ++consecutive_pto_count_; |
| 755 | pending_timer_transmission_count_ = max_probe_packets_per_pto_; |
| 756 | return PTO_MODE; |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 757 | } |
| 758 | } |
| 759 | |
| 760 | void QuicSentPacketManager::RetransmitCryptoPackets() { |
| 761 | DCHECK_EQ(HANDSHAKE_MODE, GetRetransmissionMode()); |
| 762 | ++consecutive_crypto_retransmission_count_; |
| 763 | bool packet_retransmitted = false; |
| 764 | QuicPacketNumber packet_number = unacked_packets_.GetLeastUnacked(); |
| 765 | std::vector<QuicPacketNumber> crypto_retransmissions; |
| 766 | for (QuicUnackedPacketMap::const_iterator it = unacked_packets_.begin(); |
| 767 | it != unacked_packets_.end(); ++it, ++packet_number) { |
| 768 | // Only retransmit frames which are in flight, and therefore have been sent. |
fayang | cff885a | 2019-10-22 07:39:04 -0700 | [diff] [blame] | 769 | if (!it->in_flight || it->state != OUTSTANDING || |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 770 | !it->has_crypto_handshake || |
| 771 | !unacked_packets_.HasRetransmittableFrames(*it)) { |
| 772 | continue; |
| 773 | } |
| 774 | packet_retransmitted = true; |
fayang | cff885a | 2019-10-22 07:39:04 -0700 | [diff] [blame] | 775 | crypto_retransmissions.push_back(packet_number); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 776 | ++pending_timer_transmission_count_; |
| 777 | } |
| 778 | DCHECK(packet_retransmitted) << "No crypto packets found to retransmit."; |
fayang | cff885a | 2019-10-22 07:39:04 -0700 | [diff] [blame] | 779 | for (QuicPacketNumber retransmission : crypto_retransmissions) { |
| 780 | MarkForRetransmission(retransmission, HANDSHAKE_RETRANSMISSION); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 781 | } |
| 782 | } |
| 783 | |
| 784 | bool QuicSentPacketManager::MaybeRetransmitTailLossProbe() { |
fayang | 62f867a | 2019-08-22 12:05:01 -0700 | [diff] [blame] | 785 | DCHECK(!pto_enabled_); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 786 | if (pending_timer_transmission_count_ == 0) { |
| 787 | return false; |
| 788 | } |
| 789 | if (!MaybeRetransmitOldestPacket(TLP_RETRANSMISSION)) { |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 790 | return false; |
| 791 | } |
| 792 | return true; |
| 793 | } |
| 794 | |
| 795 | bool QuicSentPacketManager::MaybeRetransmitOldestPacket(TransmissionType type) { |
| 796 | QuicPacketNumber packet_number = unacked_packets_.GetLeastUnacked(); |
| 797 | for (QuicUnackedPacketMap::const_iterator it = unacked_packets_.begin(); |
| 798 | it != unacked_packets_.end(); ++it, ++packet_number) { |
| 799 | // Only retransmit frames which are in flight, and therefore have been sent. |
fayang | cff885a | 2019-10-22 07:39:04 -0700 | [diff] [blame] | 800 | if (!it->in_flight || it->state != OUTSTANDING || |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 801 | !unacked_packets_.HasRetransmittableFrames(*it)) { |
| 802 | continue; |
| 803 | } |
| 804 | MarkForRetransmission(packet_number, type); |
| 805 | return true; |
| 806 | } |
| 807 | QUIC_DVLOG(1) |
| 808 | << "No retransmittable packets, so RetransmitOldestPacket failed."; |
| 809 | return false; |
| 810 | } |
| 811 | |
| 812 | void QuicSentPacketManager::RetransmitRtoPackets() { |
fayang | 62f867a | 2019-08-22 12:05:01 -0700 | [diff] [blame] | 813 | DCHECK(!pto_enabled_); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 814 | QUIC_BUG_IF(pending_timer_transmission_count_ > 0) |
| 815 | << "Retransmissions already queued:" << pending_timer_transmission_count_; |
| 816 | // Mark two packets for retransmission. |
| 817 | QuicPacketNumber packet_number = unacked_packets_.GetLeastUnacked(); |
| 818 | std::vector<QuicPacketNumber> retransmissions; |
| 819 | for (QuicUnackedPacketMap::const_iterator it = unacked_packets_.begin(); |
| 820 | it != unacked_packets_.end(); ++it, ++packet_number) { |
fayang | cff885a | 2019-10-22 07:39:04 -0700 | [diff] [blame] | 821 | if (it->state == OUTSTANDING && |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 822 | unacked_packets_.HasRetransmittableFrames(*it) && |
| 823 | pending_timer_transmission_count_ < max_rto_packets_) { |
fayang | e1e81d2 | 2020-01-06 11:41:34 -0800 | [diff] [blame] | 824 | DCHECK(it->in_flight); |
fayang | cff885a | 2019-10-22 07:39:04 -0700 | [diff] [blame] | 825 | retransmissions.push_back(packet_number); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 826 | ++pending_timer_transmission_count_; |
| 827 | } |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 828 | } |
| 829 | if (pending_timer_transmission_count_ > 0) { |
| 830 | if (consecutive_rto_count_ == 0) { |
| 831 | first_rto_transmission_ = unacked_packets_.largest_sent_packet() + 1; |
| 832 | } |
| 833 | ++consecutive_rto_count_; |
| 834 | } |
fayang | cff885a | 2019-10-22 07:39:04 -0700 | [diff] [blame] | 835 | for (QuicPacketNumber retransmission : retransmissions) { |
| 836 | MarkForRetransmission(retransmission, RTO_RETRANSMISSION); |
| 837 | } |
| 838 | if (retransmissions.empty()) { |
| 839 | QUIC_BUG_IF(pending_timer_transmission_count_ != 0); |
| 840 | // No packets to be RTO retransmitted, raise up a credit to allow |
| 841 | // connection to send. |
| 842 | QUIC_CODE_COUNT(no_packets_to_be_rto_retransmitted); |
| 843 | pending_timer_transmission_count_ = 1; |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 844 | } |
| 845 | } |
| 846 | |
fayang | ce0a316 | 2019-08-15 09:05:36 -0700 | [diff] [blame] | 847 | void QuicSentPacketManager::MaybeSendProbePackets() { |
| 848 | if (pending_timer_transmission_count_ == 0) { |
| 849 | return; |
| 850 | } |
fayang | 18ff23b | 2020-01-28 09:19:00 -0800 | [diff] [blame] | 851 | PacketNumberSpace packet_number_space; |
| 852 | if (supports_multiple_packet_number_spaces()) { |
| 853 | // Find out the packet number space to send probe packets. |
| 854 | if (!GetEarliestPacketSentTimeForPto(&packet_number_space) |
| 855 | .IsInitialized()) { |
fayang | aecfd53 | 2020-04-28 12:35:12 -0700 | [diff] [blame] | 856 | QUIC_BUG_IF(unacked_packets_.perspective() == Perspective::IS_SERVER) |
| 857 | << "earlist_sent_time not initialized when trying to send PTO " |
| 858 | "retransmissions"; |
fayang | 18ff23b | 2020-01-28 09:19:00 -0800 | [diff] [blame] | 859 | return; |
| 860 | } |
| 861 | } |
fayang | ce0a316 | 2019-08-15 09:05:36 -0700 | [diff] [blame] | 862 | QuicPacketNumber packet_number = unacked_packets_.GetLeastUnacked(); |
| 863 | std::vector<QuicPacketNumber> probing_packets; |
| 864 | for (QuicUnackedPacketMap::const_iterator it = unacked_packets_.begin(); |
| 865 | it != unacked_packets_.end(); ++it, ++packet_number) { |
| 866 | if (it->state == OUTSTANDING && |
fayang | 18ff23b | 2020-01-28 09:19:00 -0800 | [diff] [blame] | 867 | unacked_packets_.HasRetransmittableFrames(*it) && |
| 868 | (!supports_multiple_packet_number_spaces() || |
| 869 | unacked_packets_.GetPacketNumberSpace(it->encryption_level) == |
| 870 | packet_number_space)) { |
fayang | e1e81d2 | 2020-01-06 11:41:34 -0800 | [diff] [blame] | 871 | DCHECK(it->in_flight); |
fayang | ce0a316 | 2019-08-15 09:05:36 -0700 | [diff] [blame] | 872 | probing_packets.push_back(packet_number); |
| 873 | if (probing_packets.size() == pending_timer_transmission_count_) { |
| 874 | break; |
| 875 | } |
| 876 | } |
| 877 | } |
| 878 | |
| 879 | for (QuicPacketNumber retransmission : probing_packets) { |
| 880 | QUIC_DVLOG(1) << ENDPOINT << "Marking " << retransmission |
| 881 | << " for probing retransmission"; |
fayang | 73d0ac4 | 2019-10-31 12:45:31 -0700 | [diff] [blame] | 882 | MarkForRetransmission(retransmission, PTO_RETRANSMISSION); |
fayang | ce0a316 | 2019-08-15 09:05:36 -0700 | [diff] [blame] | 883 | } |
| 884 | // It is possible that there is not enough outstanding data for probing. |
| 885 | } |
| 886 | |
| 887 | void QuicSentPacketManager::AdjustPendingTimerTransmissions() { |
| 888 | if (pending_timer_transmission_count_ < max_probe_packets_per_pto_) { |
| 889 | // There are packets sent already, clear credit. |
| 890 | pending_timer_transmission_count_ = 0; |
| 891 | return; |
| 892 | } |
| 893 | // No packet gets sent, leave 1 credit to allow data to be write eventually. |
| 894 | pending_timer_transmission_count_ = 1; |
| 895 | } |
| 896 | |
fayang | 08a6c95 | 2019-09-18 14:29:45 -0700 | [diff] [blame] | 897 | void QuicSentPacketManager::EnableIetfPtoAndLossDetection() { |
fayang | 5d01198 | 2020-05-13 14:14:38 -0700 | [diff] [blame] | 898 | if (pto_enabled_) { |
| 899 | QUIC_RELOADABLE_FLAG_COUNT_N(quic_default_on_pto, 2, 2); |
| 900 | // Disable handshake mode. |
| 901 | handshake_mode_disabled_ = true; |
| 902 | return; |
| 903 | } |
fayang | 5f13505 | 2019-08-22 17:59:40 -0700 | [diff] [blame] | 904 | pto_enabled_ = true; |
| 905 | handshake_mode_disabled_ = true; |
fayang | 1c2d1ab | 2020-03-11 12:08:41 -0700 | [diff] [blame] | 906 | // Default to 1 packet per PTO and skip a packet number. Arm the 1st PTO with |
| 907 | // max of earliest in flight sent time + PTO delay and 1.5 * srtt from |
| 908 | // last in flight packet. |
| 909 | max_probe_packets_per_pto_ = 1; |
| 910 | skip_packet_number_for_pto_ = true; |
| 911 | first_pto_srtt_multiplier_ = 1.5; |
fayang | 5f13505 | 2019-08-22 17:59:40 -0700 | [diff] [blame] | 912 | } |
| 913 | |
fayang | 7085a6d | 2019-11-04 07:03:57 -0800 | [diff] [blame] | 914 | void QuicSentPacketManager::StartExponentialBackoffAfterNthPto( |
| 915 | size_t exponential_backoff_start_point) { |
| 916 | pto_exponential_backoff_start_point_ = exponential_backoff_start_point; |
| 917 | } |
| 918 | |
fayang | a39d036 | 2020-06-22 08:57:35 -0700 | [diff] [blame^] | 919 | void QuicSentPacketManager::RetransmitDataOfSpaceIfAny( |
| 920 | PacketNumberSpace space) { |
fayang | 7d4b017 | 2020-06-18 14:05:45 -0700 | [diff] [blame] | 921 | DCHECK(supports_multiple_packet_number_spaces()); |
fayang | a39d036 | 2020-06-22 08:57:35 -0700 | [diff] [blame^] | 922 | if (!unacked_packets_.GetLastInFlightPacketSentTime(space).IsInitialized()) { |
| 923 | // No in flight data of space. |
fayang | 7d4b017 | 2020-06-18 14:05:45 -0700 | [diff] [blame] | 924 | return; |
| 925 | } |
| 926 | QuicPacketNumber packet_number = unacked_packets_.GetLeastUnacked(); |
| 927 | for (QuicUnackedPacketMap::const_iterator it = unacked_packets_.begin(); |
| 928 | it != unacked_packets_.end(); ++it, ++packet_number) { |
| 929 | if (it->state == OUTSTANDING && |
| 930 | unacked_packets_.HasRetransmittableFrames(*it) && |
fayang | a39d036 | 2020-06-22 08:57:35 -0700 | [diff] [blame^] | 931 | unacked_packets_.GetPacketNumberSpace(it->encryption_level) == space) { |
fayang | 7d4b017 | 2020-06-18 14:05:45 -0700 | [diff] [blame] | 932 | DCHECK(it->in_flight); |
| 933 | MarkForRetransmission(packet_number, PTO_RETRANSMISSION); |
| 934 | return; |
| 935 | } |
| 936 | } |
| 937 | } |
| 938 | |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 939 | QuicSentPacketManager::RetransmissionTimeoutMode |
| 940 | QuicSentPacketManager::GetRetransmissionMode() const { |
fayang | 5f13505 | 2019-08-22 17:59:40 -0700 | [diff] [blame] | 941 | DCHECK(unacked_packets_.HasInFlightPackets() || |
fayang | 63a1984 | 2020-01-23 02:51:28 -0800 | [diff] [blame] | 942 | (handshake_mode_disabled_ && !handshake_finished_)); |
| 943 | if (!handshake_mode_disabled_ && !handshake_finished_ && |
fayang | 5f13505 | 2019-08-22 17:59:40 -0700 | [diff] [blame] | 944 | unacked_packets_.HasPendingCryptoPackets()) { |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 945 | return HANDSHAKE_MODE; |
| 946 | } |
| 947 | if (loss_algorithm_->GetLossTimeout() != QuicTime::Zero()) { |
| 948 | return LOSS_MODE; |
| 949 | } |
fayang | 62f867a | 2019-08-22 12:05:01 -0700 | [diff] [blame] | 950 | if (pto_enabled_) { |
fayang | ce0a316 | 2019-08-15 09:05:36 -0700 | [diff] [blame] | 951 | return PTO_MODE; |
| 952 | } |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 953 | if (consecutive_tlp_count_ < max_tail_loss_probes_) { |
ianswett | 7ddb34f | 2019-07-15 12:17:43 -0700 | [diff] [blame] | 954 | if (unacked_packets_.HasUnackedRetransmittableFrames()) { |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 955 | return TLP_MODE; |
| 956 | } |
| 957 | } |
| 958 | return RTO_MODE; |
| 959 | } |
| 960 | |
| 961 | void QuicSentPacketManager::InvokeLossDetection(QuicTime time) { |
| 962 | if (!packets_acked_.empty()) { |
| 963 | DCHECK_LE(packets_acked_.front().packet_number, |
| 964 | packets_acked_.back().packet_number); |
| 965 | largest_newly_acked_ = packets_acked_.back().packet_number; |
| 966 | } |
wub | aa51f0e | 2020-05-12 15:08:16 -0700 | [diff] [blame] | 967 | LossDetectionInterface::DetectionStats detection_stats = |
| 968 | loss_algorithm_->DetectLosses(unacked_packets_, time, rtt_stats_, |
| 969 | largest_newly_acked_, packets_acked_, |
| 970 | &packets_lost_); |
| 971 | |
| 972 | if (detection_stats.sent_packets_max_sequence_reordering > |
| 973 | stats_->sent_packets_max_sequence_reordering) { |
| 974 | stats_->sent_packets_max_sequence_reordering = |
| 975 | detection_stats.sent_packets_max_sequence_reordering; |
| 976 | } |
| 977 | |
wub | d8b383e | 2020-05-22 07:24:39 -0700 | [diff] [blame] | 978 | stats_->sent_packets_num_borderline_time_reorderings += |
| 979 | detection_stats.sent_packets_num_borderline_time_reorderings; |
| 980 | |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 981 | for (const LostPacket& packet : packets_lost_) { |
wub | e330aa4 | 2020-02-27 07:49:09 -0800 | [diff] [blame] | 982 | QuicTransmissionInfo* info = |
| 983 | unacked_packets_.GetMutableTransmissionInfo(packet.packet_number); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 984 | ++stats_->packets_lost; |
wub | e330aa4 | 2020-02-27 07:49:09 -0800 | [diff] [blame] | 985 | if (time > info->sent_time) { |
| 986 | stats_->total_loss_detection_time = |
| 987 | stats_->total_loss_detection_time + (time - info->sent_time); |
| 988 | } |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 989 | if (debug_delegate_ != nullptr) { |
vasilvv | 923b6d2 | 2020-03-23 11:17:58 -0700 | [diff] [blame] | 990 | debug_delegate_->OnPacketLoss(packet.packet_number, |
| 991 | info->encryption_level, LOSS_RETRANSMISSION, |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 992 | time); |
| 993 | } |
wub | e330aa4 | 2020-02-27 07:49:09 -0800 | [diff] [blame] | 994 | unacked_packets_.RemoveFromInFlight(info); |
| 995 | |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 996 | MarkForRetransmission(packet.packet_number, LOSS_RETRANSMISSION); |
| 997 | } |
| 998 | } |
| 999 | |
| 1000 | bool QuicSentPacketManager::MaybeUpdateRTT(QuicPacketNumber largest_acked, |
| 1001 | QuicTime::Delta ack_delay_time, |
| 1002 | QuicTime ack_receive_time) { |
| 1003 | // We rely on ack_delay_time to compute an RTT estimate, so we |
| 1004 | // only update rtt when the largest observed gets acked. |
| 1005 | if (!unacked_packets_.IsUnacked(largest_acked)) { |
| 1006 | return false; |
| 1007 | } |
| 1008 | // We calculate the RTT based on the highest ACKed packet number, the lower |
| 1009 | // packet numbers will include the ACK aggregation delay. |
| 1010 | const QuicTransmissionInfo& transmission_info = |
| 1011 | unacked_packets_.GetTransmissionInfo(largest_acked); |
| 1012 | // Ensure the packet has a valid sent time. |
| 1013 | if (transmission_info.sent_time == QuicTime::Zero()) { |
| 1014 | QUIC_BUG << "Acked packet has zero sent time, largest_acked:" |
| 1015 | << largest_acked; |
| 1016 | return false; |
| 1017 | } |
| 1018 | if (transmission_info.sent_time > ack_receive_time) { |
| 1019 | QUIC_CODE_COUNT(quic_receive_acked_before_sending); |
| 1020 | } |
| 1021 | |
| 1022 | QuicTime::Delta send_delta = ack_receive_time - transmission_info.sent_time; |
wub | 44e3305 | 2020-03-03 17:11:40 -0800 | [diff] [blame] | 1023 | const bool min_rtt_available = !rtt_stats_.min_rtt().IsZero(); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 1024 | rtt_stats_.UpdateRtt(send_delta, ack_delay_time, ack_receive_time); |
| 1025 | |
wub | 44e3305 | 2020-03-03 17:11:40 -0800 | [diff] [blame] | 1026 | if (!min_rtt_available && !rtt_stats_.min_rtt().IsZero()) { |
| 1027 | loss_algorithm_->OnMinRttAvailable(); |
| 1028 | } |
| 1029 | |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 1030 | return true; |
| 1031 | } |
| 1032 | |
| 1033 | QuicTime::Delta QuicSentPacketManager::TimeUntilSend(QuicTime now) const { |
| 1034 | // The TLP logic is entirely contained within QuicSentPacketManager, so the |
| 1035 | // send algorithm does not need to be consulted. |
| 1036 | if (pending_timer_transmission_count_ > 0) { |
| 1037 | return QuicTime::Delta::Zero(); |
| 1038 | } |
| 1039 | |
| 1040 | if (using_pacing_) { |
| 1041 | return pacing_sender_.TimeUntilSend(now, |
| 1042 | unacked_packets_.bytes_in_flight()); |
| 1043 | } |
| 1044 | |
| 1045 | return send_algorithm_->CanSend(unacked_packets_.bytes_in_flight()) |
| 1046 | ? QuicTime::Delta::Zero() |
| 1047 | : QuicTime::Delta::Infinite(); |
| 1048 | } |
| 1049 | |
| 1050 | const QuicTime QuicSentPacketManager::GetRetransmissionTime() const { |
fayang | 5f13505 | 2019-08-22 17:59:40 -0700 | [diff] [blame] | 1051 | if (!unacked_packets_.HasInFlightPackets() && |
fayang | 63a1984 | 2020-01-23 02:51:28 -0800 | [diff] [blame] | 1052 | (!handshake_mode_disabled_ || handshake_finished_ || |
fayang | 5f13505 | 2019-08-22 17:59:40 -0700 | [diff] [blame] | 1053 | unacked_packets_.perspective() == Perspective::IS_SERVER)) { |
| 1054 | // Do not set the timer if there is nothing in flight. However, to avoid |
| 1055 | // handshake deadlock due to anti-amplification limit, client needs to set |
| 1056 | // PTO timer when the handshake is not confirmed even there is nothing in |
| 1057 | // flight. |
| 1058 | return QuicTime::Zero(); |
| 1059 | } |
| 1060 | if (pending_timer_transmission_count_ > 0) { |
| 1061 | // Do not set the timer if there is any credit left. |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 1062 | return QuicTime::Zero(); |
| 1063 | } |
fayang | d090723 | 2020-06-02 12:56:48 -0700 | [diff] [blame] | 1064 | PacketNumberSpace packet_number_space; |
| 1065 | if (GetQuicReloadableFlag(quic_fix_server_pto_timeout) && |
| 1066 | supports_multiple_packet_number_spaces() && |
| 1067 | unacked_packets_.perspective() == Perspective::IS_SERVER && |
| 1068 | !GetEarliestPacketSentTimeForPto(&packet_number_space).IsInitialized()) { |
| 1069 | // Do not set the timer on the server side if the only in flight packets are |
| 1070 | // half RTT data. |
| 1071 | QUIC_RELOADABLE_FLAG_COUNT(quic_fix_server_pto_timeout); |
| 1072 | return QuicTime::Zero(); |
| 1073 | } |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 1074 | switch (GetRetransmissionMode()) { |
| 1075 | case HANDSHAKE_MODE: |
| 1076 | return unacked_packets_.GetLastCryptoPacketSentTime() + |
| 1077 | GetCryptoRetransmissionDelay(); |
| 1078 | case LOSS_MODE: |
| 1079 | return loss_algorithm_->GetLossTimeout(); |
| 1080 | case TLP_MODE: { |
fayang | 62f867a | 2019-08-22 12:05:01 -0700 | [diff] [blame] | 1081 | DCHECK(!pto_enabled_); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 1082 | // TODO(ianswett): When CWND is available, it would be preferable to |
| 1083 | // set the timer based on the earliest retransmittable packet. |
| 1084 | // Base the updated timer on the send time of the last packet. |
ianswett | 479fea3 | 2019-09-04 02:51:01 -0700 | [diff] [blame] | 1085 | const QuicTime sent_time = |
| 1086 | unacked_packets_.GetLastInFlightPacketSentTime(); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 1087 | const QuicTime tlp_time = sent_time + GetTailLossProbeDelay(); |
| 1088 | // Ensure the TLP timer never gets set to a time in the past. |
| 1089 | return std::max(clock_->ApproximateNow(), tlp_time); |
| 1090 | } |
| 1091 | case RTO_MODE: { |
fayang | 62f867a | 2019-08-22 12:05:01 -0700 | [diff] [blame] | 1092 | DCHECK(!pto_enabled_); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 1093 | // The RTO is based on the first outstanding packet. |
ianswett | 479fea3 | 2019-09-04 02:51:01 -0700 | [diff] [blame] | 1094 | const QuicTime sent_time = |
| 1095 | unacked_packets_.GetLastInFlightPacketSentTime(); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 1096 | QuicTime rto_time = sent_time + GetRetransmissionDelay(); |
| 1097 | // Wait for TLP packets to be acked before an RTO fires. |
ianswett | 479fea3 | 2019-09-04 02:51:01 -0700 | [diff] [blame] | 1098 | QuicTime tlp_time = sent_time + GetTailLossProbeDelay(); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 1099 | return std::max(tlp_time, rto_time); |
| 1100 | } |
fayang | ce0a316 | 2019-08-15 09:05:36 -0700 | [diff] [blame] | 1101 | case PTO_MODE: { |
fayang | 18ff23b | 2020-01-28 09:19:00 -0800 | [diff] [blame] | 1102 | if (!supports_multiple_packet_number_spaces()) { |
fayang | c5d9b2c | 2020-03-02 11:12:26 -0800 | [diff] [blame] | 1103 | if (first_pto_srtt_multiplier_ > 0 && |
fayang | 2ccfbcf | 2020-02-28 12:37:08 -0800 | [diff] [blame] | 1104 | unacked_packets_.HasInFlightPackets() && |
| 1105 | consecutive_pto_count_ == 0) { |
| 1106 | // Arm 1st PTO with earliest in flight sent time, and make sure at |
fayang | c5d9b2c | 2020-03-02 11:12:26 -0800 | [diff] [blame] | 1107 | // least first_pto_srtt_multiplier_ * RTT has been passed since last |
| 1108 | // in flight packet. |
fayang | 2ccfbcf | 2020-02-28 12:37:08 -0800 | [diff] [blame] | 1109 | return std::max( |
| 1110 | clock_->ApproximateNow(), |
| 1111 | std::max(unacked_packets_.GetFirstInFlightTransmissionInfo() |
| 1112 | ->sent_time + |
| 1113 | GetProbeTimeoutDelay(), |
| 1114 | unacked_packets_.GetLastInFlightPacketSentTime() + |
fayang | c5d9b2c | 2020-03-02 11:12:26 -0800 | [diff] [blame] | 1115 | first_pto_srtt_multiplier_ * |
| 1116 | rtt_stats_.SmoothedOrInitialRtt())); |
fayang | 2ccfbcf | 2020-02-28 12:37:08 -0800 | [diff] [blame] | 1117 | } |
fayang | 18ff23b | 2020-01-28 09:19:00 -0800 | [diff] [blame] | 1118 | // Ensure PTO never gets set to a time in the past. |
| 1119 | return std::max(clock_->ApproximateNow(), |
| 1120 | unacked_packets_.GetLastInFlightPacketSentTime() + |
| 1121 | GetProbeTimeoutDelay()); |
| 1122 | } |
| 1123 | |
fayang | 3ecc53b | 2020-03-12 07:12:03 -0700 | [diff] [blame] | 1124 | PacketNumberSpace packet_number_space = NUM_PACKET_NUMBER_SPACES; |
fayang | 2ccfbcf | 2020-02-28 12:37:08 -0800 | [diff] [blame] | 1125 | // earliest_right_edge is the earliest sent time of the last in flight |
| 1126 | // packet of all packet number spaces. |
fayang | aecfd53 | 2020-04-28 12:35:12 -0700 | [diff] [blame] | 1127 | QuicTime earliest_right_edge = |
fayang | 2ccfbcf | 2020-02-28 12:37:08 -0800 | [diff] [blame] | 1128 | GetEarliestPacketSentTimeForPto(&packet_number_space); |
fayang | aecfd53 | 2020-04-28 12:35:12 -0700 | [diff] [blame] | 1129 | if (!earliest_right_edge.IsInitialized()) { |
| 1130 | // Arm PTO from now if there is no in flight packets. |
| 1131 | earliest_right_edge = clock_->ApproximateNow(); |
| 1132 | } |
fayang | c5d9b2c | 2020-03-02 11:12:26 -0800 | [diff] [blame] | 1133 | if (first_pto_srtt_multiplier_ > 0 && |
fayang | 2ccfbcf | 2020-02-28 12:37:08 -0800 | [diff] [blame] | 1134 | packet_number_space == APPLICATION_DATA && |
| 1135 | consecutive_pto_count_ == 0) { |
| 1136 | const QuicTransmissionInfo* first_application_info = |
| 1137 | unacked_packets_.GetFirstInFlightTransmissionInfoOfSpace( |
| 1138 | APPLICATION_DATA); |
| 1139 | if (first_application_info != nullptr) { |
| 1140 | // Arm 1st PTO with earliest in flight sent time, and make sure at |
fayang | c5d9b2c | 2020-03-02 11:12:26 -0800 | [diff] [blame] | 1141 | // least first_pto_srtt_multiplier_ * RTT has been passed since last |
| 1142 | // in flight packet. Only do this for application data. |
fayang | 2ccfbcf | 2020-02-28 12:37:08 -0800 | [diff] [blame] | 1143 | return std::max( |
| 1144 | clock_->ApproximateNow(), |
| 1145 | std::max( |
| 1146 | first_application_info->sent_time + GetProbeTimeoutDelay(), |
fayang | c5d9b2c | 2020-03-02 11:12:26 -0800 | [diff] [blame] | 1147 | earliest_right_edge + first_pto_srtt_multiplier_ * |
| 1148 | rtt_stats_.SmoothedOrInitialRtt())); |
fayang | 2ccfbcf | 2020-02-28 12:37:08 -0800 | [diff] [blame] | 1149 | } |
| 1150 | } |
ianswett | 479fea3 | 2019-09-04 02:51:01 -0700 | [diff] [blame] | 1151 | return std::max(clock_->ApproximateNow(), |
fayang | 2ccfbcf | 2020-02-28 12:37:08 -0800 | [diff] [blame] | 1152 | earliest_right_edge + GetProbeTimeoutDelay()); |
fayang | ce0a316 | 2019-08-15 09:05:36 -0700 | [diff] [blame] | 1153 | } |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 1154 | } |
| 1155 | DCHECK(false); |
| 1156 | return QuicTime::Zero(); |
| 1157 | } |
| 1158 | |
| 1159 | const QuicTime::Delta QuicSentPacketManager::GetPathDegradingDelay() const { |
fayang | 1640cc2 | 2020-03-21 14:11:02 -0700 | [diff] [blame] | 1160 | return GetNConsecutiveRetransmissionTimeoutDelay( |
| 1161 | max_tail_loss_probes_ + kNumRetransmissionDelaysForPathDegradingDelay); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 1162 | } |
| 1163 | |
fayang | ddd3e9d | 2020-06-03 11:00:19 -0700 | [diff] [blame] | 1164 | const QuicTime::Delta QuicSentPacketManager::GetNetworkBlackholeDelay( |
| 1165 | int8_t num_rtos_for_blackhole_detection) const { |
fayang | b59c6f1 | 2020-03-23 15:06:14 -0700 | [diff] [blame] | 1166 | return GetNConsecutiveRetransmissionTimeoutDelay( |
fayang | ddd3e9d | 2020-06-03 11:00:19 -0700 | [diff] [blame] | 1167 | max_tail_loss_probes_ + num_rtos_for_blackhole_detection); |
fayang | b59c6f1 | 2020-03-23 15:06:14 -0700 | [diff] [blame] | 1168 | } |
| 1169 | |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 1170 | const QuicTime::Delta QuicSentPacketManager::GetCryptoRetransmissionDelay() |
| 1171 | const { |
| 1172 | // This is equivalent to the TailLossProbeDelay, but slightly more aggressive |
| 1173 | // because crypto handshake messages don't incur a delayed ack time. |
| 1174 | QuicTime::Delta srtt = rtt_stats_.SmoothedOrInitialRtt(); |
| 1175 | int64_t delay_ms; |
| 1176 | if (conservative_handshake_retransmits_) { |
| 1177 | // Using the delayed ack time directly could cause conservative handshake |
| 1178 | // retransmissions to actually be more aggressive than the default. |
fkastenholz | 59c653b | 2019-07-15 09:55:53 -0700 | [diff] [blame] | 1179 | delay_ms = std::max(peer_max_ack_delay_.ToMilliseconds(), |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 1180 | static_cast<int64_t>(2 * srtt.ToMilliseconds())); |
| 1181 | } else { |
| 1182 | delay_ms = std::max(kMinHandshakeTimeoutMs, |
| 1183 | static_cast<int64_t>(1.5 * srtt.ToMilliseconds())); |
| 1184 | } |
| 1185 | return QuicTime::Delta::FromMilliseconds( |
| 1186 | delay_ms << consecutive_crypto_retransmission_count_); |
| 1187 | } |
| 1188 | |
fayang | 1640cc2 | 2020-03-21 14:11:02 -0700 | [diff] [blame] | 1189 | const QuicTime::Delta QuicSentPacketManager::GetTailLossProbeDelay() const { |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 1190 | QuicTime::Delta srtt = rtt_stats_.SmoothedOrInitialRtt(); |
fayang | 1640cc2 | 2020-03-21 14:11:02 -0700 | [diff] [blame] | 1191 | if (enable_half_rtt_tail_loss_probe_ && consecutive_tlp_count_ == 0u) { |
zhongyi | 1b2f783 | 2019-06-14 13:31:34 -0700 | [diff] [blame] | 1192 | if (unacked_packets().HasUnackedStreamData()) { |
| 1193 | // Enable TLPR if there are pending data packets. |
| 1194 | return std::max(min_tlp_timeout_, srtt * 0.5); |
| 1195 | } |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 1196 | } |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 1197 | if (!unacked_packets_.HasMultipleInFlightPackets()) { |
| 1198 | // This expression really should be using the delayed ack time, but in TCP |
| 1199 | // MinRTO was traditionally set to 2x the delayed ack timer and this |
| 1200 | // expression assumed QUIC did the same. |
| 1201 | return std::max(2 * srtt, 1.5 * srtt + (min_rto_timeout_ * 0.5)); |
| 1202 | } |
| 1203 | return std::max(min_tlp_timeout_, 2 * srtt); |
| 1204 | } |
| 1205 | |
fayang | 1640cc2 | 2020-03-21 14:11:02 -0700 | [diff] [blame] | 1206 | const QuicTime::Delta QuicSentPacketManager::GetRetransmissionDelay() const { |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 1207 | QuicTime::Delta retransmission_delay = QuicTime::Delta::Zero(); |
| 1208 | if (rtt_stats_.smoothed_rtt().IsZero()) { |
| 1209 | // We are in the initial state, use default timeout values. |
| 1210 | retransmission_delay = |
| 1211 | QuicTime::Delta::FromMilliseconds(kDefaultRetransmissionTimeMs); |
| 1212 | } else { |
| 1213 | retransmission_delay = |
| 1214 | rtt_stats_.smoothed_rtt() + 4 * rtt_stats_.mean_deviation(); |
| 1215 | if (retransmission_delay < min_rto_timeout_) { |
| 1216 | retransmission_delay = min_rto_timeout_; |
| 1217 | } |
| 1218 | } |
| 1219 | |
| 1220 | // Calculate exponential back off. |
| 1221 | retransmission_delay = |
| 1222 | retransmission_delay * |
fayang | 1640cc2 | 2020-03-21 14:11:02 -0700 | [diff] [blame] | 1223 | (1 << std::min<size_t>(consecutive_rto_count_, kMaxRetransmissions)); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 1224 | |
| 1225 | if (retransmission_delay.ToMilliseconds() > kMaxRetransmissionTimeMs) { |
| 1226 | return QuicTime::Delta::FromMilliseconds(kMaxRetransmissionTimeMs); |
| 1227 | } |
| 1228 | return retransmission_delay; |
| 1229 | } |
| 1230 | |
fayang | ce0a316 | 2019-08-15 09:05:36 -0700 | [diff] [blame] | 1231 | const QuicTime::Delta QuicSentPacketManager::GetProbeTimeoutDelay() const { |
fayang | 62f867a | 2019-08-22 12:05:01 -0700 | [diff] [blame] | 1232 | DCHECK(pto_enabled_); |
fayang | ce0a316 | 2019-08-15 09:05:36 -0700 | [diff] [blame] | 1233 | if (rtt_stats_.smoothed_rtt().IsZero()) { |
fayang | 6c7313c | 2020-04-23 12:10:35 -0700 | [diff] [blame] | 1234 | // Respect kMinHandshakeTimeoutMs to avoid a potential amplification attack. |
| 1235 | QUIC_BUG_IF(rtt_stats_.initial_rtt().IsZero()); |
fayang | bc9f56f | 2020-06-19 03:49:22 -0700 | [diff] [blame] | 1236 | return std::max( |
| 1237 | pto_multiplier_without_rtt_samples_ * rtt_stats_.initial_rtt(), |
| 1238 | QuicTime::Delta::FromMilliseconds(kMinHandshakeTimeoutMs)) * |
fayang | 6c7313c | 2020-04-23 12:10:35 -0700 | [diff] [blame] | 1239 | (1 << consecutive_pto_count_); |
fayang | ce0a316 | 2019-08-15 09:05:36 -0700 | [diff] [blame] | 1240 | } |
fayang | c2fd610 | 2020-03-02 17:27:38 -0800 | [diff] [blame] | 1241 | const QuicTime::Delta rtt_var = use_standard_deviation_for_pto_ |
| 1242 | ? rtt_stats_.GetStandardOrMeanDeviation() |
| 1243 | : rtt_stats_.mean_deviation(); |
fayang | 4aa2240 | 2020-01-07 11:36:07 -0800 | [diff] [blame] | 1244 | QuicTime::Delta pto_delay = |
fayang | ce0a316 | 2019-08-15 09:05:36 -0700 | [diff] [blame] | 1245 | rtt_stats_.smoothed_rtt() + |
fayang | c2fd610 | 2020-03-02 17:27:38 -0800 | [diff] [blame] | 1246 | std::max(pto_rttvar_multiplier_ * rtt_var, kAlarmGranularity) + |
fayang | 4c908f0 | 2019-11-01 07:26:17 -0700 | [diff] [blame] | 1247 | (ShouldAddMaxAckDelay() ? peer_max_ack_delay_ : QuicTime::Delta::Zero()); |
fayang | 4aa2240 | 2020-01-07 11:36:07 -0800 | [diff] [blame] | 1248 | pto_delay = |
| 1249 | pto_delay * (1 << (consecutive_pto_count_ - |
| 1250 | std::min(consecutive_pto_count_, |
| 1251 | pto_exponential_backoff_start_point_))); |
| 1252 | if (consecutive_pto_count_ < num_tlp_timeout_ptos_) { |
| 1253 | // Make first n PTOs similar to TLPs. |
| 1254 | if (pto_delay > 2 * rtt_stats_.smoothed_rtt()) { |
| 1255 | QUIC_CODE_COUNT(quic_delayed_pto); |
| 1256 | pto_delay = std::max(kAlarmGranularity, 2 * rtt_stats_.smoothed_rtt()); |
| 1257 | } else { |
| 1258 | QUIC_CODE_COUNT(quic_faster_pto); |
| 1259 | } |
| 1260 | } |
| 1261 | return pto_delay; |
fayang | ce0a316 | 2019-08-15 09:05:36 -0700 | [diff] [blame] | 1262 | } |
| 1263 | |
wub | 967ba57 | 2019-04-01 09:27:52 -0700 | [diff] [blame] | 1264 | QuicTime::Delta QuicSentPacketManager::GetSlowStartDuration() const { |
wub | be29b9e | 2019-11-24 06:56:04 -0800 | [diff] [blame] | 1265 | if (send_algorithm_->GetCongestionControlType() == kBBR || |
| 1266 | send_algorithm_->GetCongestionControlType() == kBBRv2) { |
| 1267 | return stats_->slowstart_duration.GetTotalElapsedTime( |
| 1268 | clock_->ApproximateNow()); |
wub | 967ba57 | 2019-04-01 09:27:52 -0700 | [diff] [blame] | 1269 | } |
wub | be29b9e | 2019-11-24 06:56:04 -0800 | [diff] [blame] | 1270 | return QuicTime::Delta::Infinite(); |
wub | 967ba57 | 2019-04-01 09:27:52 -0700 | [diff] [blame] | 1271 | } |
| 1272 | |
vasilvv | c48c871 | 2019-03-11 13:38:16 -0700 | [diff] [blame] | 1273 | std::string QuicSentPacketManager::GetDebugState() const { |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 1274 | return send_algorithm_->GetDebugState(); |
| 1275 | } |
| 1276 | |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 1277 | void QuicSentPacketManager::SetSendAlgorithm( |
| 1278 | CongestionControlType congestion_control_type) { |
wub | 32a9f8a | 2020-03-16 09:01:35 -0700 | [diff] [blame] | 1279 | if (send_algorithm_ && |
| 1280 | send_algorithm_->GetCongestionControlType() == congestion_control_type) { |
| 1281 | return; |
wub | 18773d6 | 2020-01-28 14:14:06 -0800 | [diff] [blame] | 1282 | } |
wub | 32a9f8a | 2020-03-16 09:01:35 -0700 | [diff] [blame] | 1283 | |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 1284 | SetSendAlgorithm(SendAlgorithmInterface::Create( |
QUICHE team | 73957f1 | 2019-04-18 16:21:52 -0700 | [diff] [blame] | 1285 | clock_, &rtt_stats_, &unacked_packets_, congestion_control_type, random_, |
wub | 0abcd8f | 2020-03-30 16:24:50 -0700 | [diff] [blame] | 1286 | stats_, initial_congestion_window_, send_algorithm_.get())); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 1287 | } |
| 1288 | |
| 1289 | void QuicSentPacketManager::SetSendAlgorithm( |
| 1290 | SendAlgorithmInterface* send_algorithm) { |
| 1291 | send_algorithm_.reset(send_algorithm); |
| 1292 | pacing_sender_.set_sender(send_algorithm); |
| 1293 | } |
| 1294 | |
| 1295 | void QuicSentPacketManager::OnConnectionMigration(AddressChangeType type) { |
| 1296 | if (type == PORT_CHANGE || type == IPV4_SUBNET_CHANGE) { |
| 1297 | // Rtt and cwnd do not need to be reset when the peer address change is |
| 1298 | // considered to be caused by NATs. |
| 1299 | return; |
| 1300 | } |
| 1301 | consecutive_rto_count_ = 0; |
| 1302 | consecutive_tlp_count_ = 0; |
fayang | ce0a316 | 2019-08-15 09:05:36 -0700 | [diff] [blame] | 1303 | consecutive_pto_count_ = 0; |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 1304 | rtt_stats_.OnConnectionMigration(); |
| 1305 | send_algorithm_->OnConnectionMigration(); |
| 1306 | } |
| 1307 | |
| 1308 | void QuicSentPacketManager::OnAckFrameStart(QuicPacketNumber largest_acked, |
| 1309 | QuicTime::Delta ack_delay_time, |
| 1310 | QuicTime ack_receive_time) { |
| 1311 | DCHECK(packets_acked_.empty()); |
| 1312 | DCHECK_LE(largest_acked, unacked_packets_.largest_sent_packet()); |
wub | 81c9b66 | 2020-02-14 09:08:07 -0800 | [diff] [blame] | 1313 | if (ack_delay_time > peer_max_ack_delay()) { |
wub | 8ee29a0 | 2019-12-12 13:06:48 -0800 | [diff] [blame] | 1314 | ack_delay_time = peer_max_ack_delay(); |
| 1315 | } |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 1316 | rtt_updated_ = |
| 1317 | MaybeUpdateRTT(largest_acked, ack_delay_time, ack_receive_time); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 1318 | last_ack_frame_.ack_delay_time = ack_delay_time; |
| 1319 | acked_packets_iter_ = last_ack_frame_.packets.rbegin(); |
| 1320 | } |
| 1321 | |
| 1322 | void QuicSentPacketManager::OnAckRange(QuicPacketNumber start, |
| 1323 | QuicPacketNumber end) { |
| 1324 | if (!last_ack_frame_.largest_acked.IsInitialized() || |
| 1325 | end > last_ack_frame_.largest_acked + 1) { |
| 1326 | // Largest acked increases. |
| 1327 | unacked_packets_.IncreaseLargestAcked(end - 1); |
| 1328 | last_ack_frame_.largest_acked = end - 1; |
| 1329 | } |
| 1330 | // Drop ack ranges which ack packets below least_unacked. |
| 1331 | QuicPacketNumber least_unacked = unacked_packets_.GetLeastUnacked(); |
| 1332 | if (least_unacked.IsInitialized() && end <= least_unacked) { |
| 1333 | return; |
| 1334 | } |
| 1335 | start = std::max(start, least_unacked); |
| 1336 | do { |
| 1337 | QuicPacketNumber newly_acked_start = start; |
| 1338 | if (acked_packets_iter_ != last_ack_frame_.packets.rend()) { |
| 1339 | newly_acked_start = std::max(start, acked_packets_iter_->max()); |
| 1340 | } |
| 1341 | for (QuicPacketNumber acked = end - 1; acked >= newly_acked_start; |
| 1342 | --acked) { |
| 1343 | // Check if end is above the current range. If so add newly acked packets |
| 1344 | // in descending order. |
| 1345 | packets_acked_.push_back(AckedPacket(acked, 0, QuicTime::Zero())); |
| 1346 | if (acked == FirstSendingPacketNumber()) { |
| 1347 | break; |
| 1348 | } |
| 1349 | } |
| 1350 | if (acked_packets_iter_ == last_ack_frame_.packets.rend() || |
| 1351 | start > acked_packets_iter_->min()) { |
| 1352 | // Finish adding all newly acked packets. |
| 1353 | return; |
| 1354 | } |
| 1355 | end = std::min(end, acked_packets_iter_->min()); |
| 1356 | ++acked_packets_iter_; |
| 1357 | } while (start < end); |
| 1358 | } |
| 1359 | |
| 1360 | void QuicSentPacketManager::OnAckTimestamp(QuicPacketNumber packet_number, |
| 1361 | QuicTime timestamp) { |
| 1362 | last_ack_frame_.received_packet_times.push_back({packet_number, timestamp}); |
| 1363 | for (AckedPacket& packet : packets_acked_) { |
| 1364 | if (packet.packet_number == packet_number) { |
| 1365 | packet.receive_timestamp = timestamp; |
| 1366 | return; |
| 1367 | } |
| 1368 | } |
| 1369 | } |
| 1370 | |
fayang | 3eb8221 | 2019-04-16 12:05:46 -0700 | [diff] [blame] | 1371 | AckResult QuicSentPacketManager::OnAckFrameEnd( |
| 1372 | QuicTime ack_receive_time, |
fayang | f8e918b | 2019-07-16 13:03:16 -0700 | [diff] [blame] | 1373 | QuicPacketNumber ack_packet_number, |
fayang | 3eb8221 | 2019-04-16 12:05:46 -0700 | [diff] [blame] | 1374 | EncryptionLevel ack_decrypted_level) { |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 1375 | QuicByteCount prior_bytes_in_flight = unacked_packets_.bytes_in_flight(); |
| 1376 | // Reverse packets_acked_ so that it is in ascending order. |
wub | c0a1df4 | 2019-11-15 08:49:59 -0800 | [diff] [blame] | 1377 | std::reverse(packets_acked_.begin(), packets_acked_.end()); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 1378 | for (AckedPacket& acked_packet : packets_acked_) { |
| 1379 | QuicTransmissionInfo* info = |
| 1380 | unacked_packets_.GetMutableTransmissionInfo(acked_packet.packet_number); |
| 1381 | if (!QuicUtils::IsAckable(info->state)) { |
| 1382 | if (info->state == ACKED) { |
| 1383 | QUIC_BUG << "Trying to ack an already acked packet: " |
| 1384 | << acked_packet.packet_number |
| 1385 | << ", last_ack_frame_: " << last_ack_frame_ |
| 1386 | << ", least_unacked: " << unacked_packets_.GetLeastUnacked() |
| 1387 | << ", packets_acked_: " << packets_acked_; |
| 1388 | } else { |
renjietang | b4ebb1d | 2020-05-27 18:15:51 -0700 | [diff] [blame] | 1389 | QUIC_PEER_BUG << "Received " << ack_decrypted_level |
fayang | 3eb8221 | 2019-04-16 12:05:46 -0700 | [diff] [blame] | 1390 | << " ack for unackable packet: " |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 1391 | << acked_packet.packet_number << " with state: " |
| 1392 | << QuicUtils::SentPacketStateToString(info->state); |
fayang | 3eb8221 | 2019-04-16 12:05:46 -0700 | [diff] [blame] | 1393 | if (supports_multiple_packet_number_spaces()) { |
| 1394 | if (info->state == NEVER_SENT) { |
| 1395 | return UNSENT_PACKETS_ACKED; |
| 1396 | } |
| 1397 | return UNACKABLE_PACKETS_ACKED; |
| 1398 | } |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 1399 | } |
| 1400 | continue; |
| 1401 | } |
renjietang | b4ebb1d | 2020-05-27 18:15:51 -0700 | [diff] [blame] | 1402 | QUIC_DVLOG(1) << ENDPOINT << "Got an " << ack_decrypted_level |
fayang | 19d2d5b | 2019-09-11 14:22:03 -0700 | [diff] [blame] | 1403 | << " ack for packet " << acked_packet.packet_number |
| 1404 | << " , state: " |
| 1405 | << QuicUtils::SentPacketStateToString(info->state); |
fayang | 3eb8221 | 2019-04-16 12:05:46 -0700 | [diff] [blame] | 1406 | const PacketNumberSpace packet_number_space = |
fayang | bf3d286 | 2019-06-20 14:13:44 -0700 | [diff] [blame] | 1407 | unacked_packets_.GetPacketNumberSpace(info->encryption_level); |
fayang | 3eb8221 | 2019-04-16 12:05:46 -0700 | [diff] [blame] | 1408 | if (supports_multiple_packet_number_spaces() && |
| 1409 | QuicUtils::GetPacketNumberSpace(ack_decrypted_level) != |
| 1410 | packet_number_space) { |
| 1411 | return PACKETS_ACKED_IN_WRONG_PACKET_NUMBER_SPACE; |
| 1412 | } |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 1413 | last_ack_frame_.packets.Add(acked_packet.packet_number); |
fayang | 2f2915d | 2020-01-24 06:47:15 -0800 | [diff] [blame] | 1414 | if (info->encryption_level == ENCRYPTION_FORWARD_SECURE) { |
| 1415 | one_rtt_packet_acked_ = true; |
| 1416 | } |
QUICHE team | c264e36 | 2019-03-19 14:21:06 -0700 | [diff] [blame] | 1417 | largest_packet_peer_knows_is_acked_.UpdateMax(info->largest_acked); |
QUICHE team | c279cec | 2019-03-22 06:51:48 -0700 | [diff] [blame] | 1418 | if (supports_multiple_packet_number_spaces()) { |
fayang | 3eb8221 | 2019-04-16 12:05:46 -0700 | [diff] [blame] | 1419 | largest_packets_peer_knows_is_acked_[packet_number_space].UpdateMax( |
| 1420 | info->largest_acked); |
QUICHE team | c279cec | 2019-03-22 06:51:48 -0700 | [diff] [blame] | 1421 | } |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 1422 | // If data is associated with the most recent transmission of this |
| 1423 | // packet, then inform the caller. |
| 1424 | if (info->in_flight) { |
| 1425 | acked_packet.bytes_acked = info->bytes_sent; |
| 1426 | } else { |
| 1427 | // Unackable packets are skipped earlier. |
| 1428 | largest_newly_acked_ = acked_packet.packet_number; |
| 1429 | } |
fayang | bf3d286 | 2019-06-20 14:13:44 -0700 | [diff] [blame] | 1430 | unacked_packets_.MaybeUpdateLargestAckedOfPacketNumberSpace( |
| 1431 | packet_number_space, acked_packet.packet_number); |
fayang | 19d2d5b | 2019-09-11 14:22:03 -0700 | [diff] [blame] | 1432 | MarkPacketHandled(acked_packet.packet_number, info, ack_receive_time, |
QUICHE team | 9467db0 | 2019-05-30 09:38:45 -0700 | [diff] [blame] | 1433 | last_ack_frame_.ack_delay_time, |
| 1434 | acked_packet.receive_timestamp); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 1435 | } |
| 1436 | const bool acked_new_packet = !packets_acked_.empty(); |
vasilvv | 923b6d2 | 2020-03-23 11:17:58 -0700 | [diff] [blame] | 1437 | PostProcessNewlyAckedPackets(ack_packet_number, ack_decrypted_level, |
| 1438 | last_ack_frame_, ack_receive_time, rtt_updated_, |
fayang | 3eb8221 | 2019-04-16 12:05:46 -0700 | [diff] [blame] | 1439 | prior_bytes_in_flight); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 1440 | |
fayang | 3eb8221 | 2019-04-16 12:05:46 -0700 | [diff] [blame] | 1441 | return acked_new_packet ? PACKETS_NEWLY_ACKED : NO_PACKETS_NEWLY_ACKED; |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 1442 | } |
| 1443 | |
| 1444 | void QuicSentPacketManager::SetDebugDelegate(DebugDelegate* debug_delegate) { |
| 1445 | debug_delegate_ = debug_delegate; |
| 1446 | } |
| 1447 | |
| 1448 | void QuicSentPacketManager::OnApplicationLimited() { |
| 1449 | if (using_pacing_) { |
| 1450 | pacing_sender_.OnApplicationLimited(); |
| 1451 | } |
| 1452 | send_algorithm_->OnApplicationLimited(unacked_packets_.bytes_in_flight()); |
| 1453 | if (debug_delegate_ != nullptr) { |
| 1454 | debug_delegate_->OnApplicationLimited(); |
| 1455 | } |
| 1456 | } |
| 1457 | |
wub | ed245d2 | 2020-05-07 10:46:00 -0700 | [diff] [blame] | 1458 | NextReleaseTimeResult QuicSentPacketManager::GetNextReleaseTime() const { |
| 1459 | if (!using_pacing_) { |
| 1460 | return {QuicTime::Zero(), false}; |
| 1461 | } |
| 1462 | |
| 1463 | return pacing_sender_.GetNextReleaseTime(); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 1464 | } |
| 1465 | |
| 1466 | void QuicSentPacketManager::SetInitialRtt(QuicTime::Delta rtt) { |
| 1467 | const QuicTime::Delta min_rtt = |
| 1468 | QuicTime::Delta::FromMicroseconds(kMinInitialRoundTripTimeUs); |
| 1469 | const QuicTime::Delta max_rtt = |
| 1470 | QuicTime::Delta::FromMicroseconds(kMaxInitialRoundTripTimeUs); |
| 1471 | rtt_stats_.set_initial_rtt(std::max(min_rtt, std::min(max_rtt, rtt))); |
| 1472 | } |
| 1473 | |
QUICHE team | c279cec | 2019-03-22 06:51:48 -0700 | [diff] [blame] | 1474 | void QuicSentPacketManager::EnableMultiplePacketNumberSpacesSupport() { |
fayang | 18ff23b | 2020-01-28 09:19:00 -0800 | [diff] [blame] | 1475 | EnableIetfPtoAndLossDetection(); |
QUICHE team | c279cec | 2019-03-22 06:51:48 -0700 | [diff] [blame] | 1476 | unacked_packets_.EnableMultiplePacketNumberSpacesSupport(); |
| 1477 | } |
| 1478 | |
| 1479 | QuicPacketNumber QuicSentPacketManager::GetLargestAckedPacket( |
| 1480 | EncryptionLevel decrypted_packet_level) const { |
| 1481 | DCHECK(supports_multiple_packet_number_spaces()); |
| 1482 | return unacked_packets_.GetLargestAckedOfPacketNumberSpace( |
| 1483 | QuicUtils::GetPacketNumberSpace(decrypted_packet_level)); |
| 1484 | } |
| 1485 | |
QUICHE team | c279cec | 2019-03-22 06:51:48 -0700 | [diff] [blame] | 1486 | QuicPacketNumber QuicSentPacketManager::GetLargestPacketPeerKnowsIsAcked( |
| 1487 | EncryptionLevel decrypted_packet_level) const { |
| 1488 | DCHECK(supports_multiple_packet_number_spaces()); |
| 1489 | return largest_packets_peer_knows_is_acked_[QuicUtils::GetPacketNumberSpace( |
| 1490 | decrypted_packet_level)]; |
| 1491 | } |
| 1492 | |
fayang | 1640cc2 | 2020-03-21 14:11:02 -0700 | [diff] [blame] | 1493 | QuicTime::Delta |
| 1494 | QuicSentPacketManager::GetNConsecutiveRetransmissionTimeoutDelay( |
| 1495 | int num_timeouts) const { |
| 1496 | QuicTime::Delta total_delay = QuicTime::Delta::Zero(); |
| 1497 | const QuicTime::Delta srtt = rtt_stats_.SmoothedOrInitialRtt(); |
| 1498 | int num_tlps = |
| 1499 | std::min(num_timeouts, static_cast<int>(max_tail_loss_probes_)); |
| 1500 | num_timeouts -= num_tlps; |
| 1501 | if (num_tlps > 0) { |
| 1502 | if (enable_half_rtt_tail_loss_probe_ && |
| 1503 | unacked_packets().HasUnackedStreamData()) { |
| 1504 | total_delay = total_delay + std::max(min_tlp_timeout_, srtt * 0.5); |
| 1505 | --num_tlps; |
| 1506 | } |
| 1507 | if (num_tlps > 0) { |
| 1508 | const QuicTime::Delta tlp_delay = |
| 1509 | std::max(2 * srtt, unacked_packets_.HasMultipleInFlightPackets() |
| 1510 | ? min_tlp_timeout_ |
| 1511 | : (1.5 * srtt + (min_rto_timeout_ * 0.5))); |
| 1512 | total_delay = total_delay + num_tlps * tlp_delay; |
| 1513 | } |
| 1514 | } |
| 1515 | if (num_timeouts == 0) { |
| 1516 | return total_delay; |
| 1517 | } |
| 1518 | |
| 1519 | const QuicTime::Delta retransmission_delay = |
| 1520 | rtt_stats_.smoothed_rtt().IsZero() |
| 1521 | ? QuicTime::Delta::FromMilliseconds(kDefaultRetransmissionTimeMs) |
| 1522 | : std::max(srtt + 4 * rtt_stats_.mean_deviation(), min_rto_timeout_); |
| 1523 | total_delay = total_delay + ((1 << num_timeouts) - 1) * retransmission_delay; |
| 1524 | return total_delay; |
| 1525 | } |
| 1526 | |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 1527 | #undef ENDPOINT // undef for jumbo builds |
| 1528 | } // namespace quic |