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 | #ifndef QUICHE_QUIC_CORE_QUIC_SENT_PACKET_MANAGER_H_ |
| 6 | #define QUICHE_QUIC_CORE_QUIC_SENT_PACKET_MANAGER_H_ |
| 7 | |
| 8 | #include <cstddef> |
| 9 | #include <map> |
| 10 | #include <memory> |
| 11 | #include <set> |
vasilvv | 872e7a3 | 2019-03-12 16:42:44 -0700 | [diff] [blame] | 12 | #include <string> |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 13 | #include <utility> |
| 14 | #include <vector> |
| 15 | |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 16 | #include "net/third_party/quiche/src/quic/core/congestion_control/pacing_sender.h" |
| 17 | #include "net/third_party/quiche/src/quic/core/congestion_control/rtt_stats.h" |
| 18 | #include "net/third_party/quiche/src/quic/core/congestion_control/send_algorithm_interface.h" |
| 19 | #include "net/third_party/quiche/src/quic/core/congestion_control/uber_loss_algorithm.h" |
| 20 | #include "net/third_party/quiche/src/quic/core/proto/cached_network_parameters.pb.h" |
| 21 | #include "net/third_party/quiche/src/quic/core/quic_packets.h" |
| 22 | #include "net/third_party/quiche/src/quic/core/quic_pending_retransmission.h" |
| 23 | #include "net/third_party/quiche/src/quic/core/quic_sustained_bandwidth_recorder.h" |
| 24 | #include "net/third_party/quiche/src/quic/core/quic_transmission_info.h" |
| 25 | #include "net/third_party/quiche/src/quic/core/quic_types.h" |
| 26 | #include "net/third_party/quiche/src/quic/core/quic_unacked_packet_map.h" |
| 27 | #include "net/third_party/quiche/src/quic/platform/api/quic_containers.h" |
| 28 | #include "net/third_party/quiche/src/quic/platform/api/quic_export.h" |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 29 | |
| 30 | namespace quic { |
| 31 | |
| 32 | namespace test { |
| 33 | class QuicConnectionPeer; |
| 34 | class QuicSentPacketManagerPeer; |
| 35 | } // namespace test |
| 36 | |
| 37 | class QuicClock; |
| 38 | class QuicConfig; |
| 39 | struct QuicConnectionStats; |
| 40 | |
| 41 | // Class which tracks the set of packets sent on a QUIC connection and contains |
| 42 | // a send algorithm to decide when to send new packets. It keeps track of any |
| 43 | // retransmittable data associated with each packet. If a packet is |
| 44 | // retransmitted, it will keep track of each version of a packet so that if a |
| 45 | // previous transmission is acked, the data will not be retransmitted. |
| 46 | class QUIC_EXPORT_PRIVATE QuicSentPacketManager { |
| 47 | public: |
| 48 | // Interface which gets callbacks from the QuicSentPacketManager at |
| 49 | // interesting points. Implementations must not mutate the state of |
| 50 | // the packet manager or connection as a result of these callbacks. |
| 51 | class QUIC_EXPORT_PRIVATE DebugDelegate { |
| 52 | public: |
| 53 | virtual ~DebugDelegate() {} |
| 54 | |
| 55 | // Called when a spurious retransmission is detected. |
| 56 | virtual void OnSpuriousPacketRetransmission( |
| 57 | TransmissionType transmission_type, |
| 58 | QuicByteCount byte_size) {} |
| 59 | |
| 60 | virtual void OnIncomingAck(const QuicAckFrame& ack_frame, |
| 61 | QuicTime ack_receive_time, |
| 62 | QuicPacketNumber largest_observed, |
| 63 | bool rtt_updated, |
| 64 | QuicPacketNumber least_unacked_sent_packet) {} |
| 65 | |
| 66 | virtual void OnPacketLoss(QuicPacketNumber lost_packet_number, |
| 67 | TransmissionType transmission_type, |
| 68 | QuicTime detection_time) {} |
| 69 | |
| 70 | virtual void OnApplicationLimited() {} |
| 71 | |
| 72 | virtual void OnAdjustNetworkParameters(QuicBandwidth bandwidth, |
fayang | be83ecd | 2019-04-26 13:58:09 -0700 | [diff] [blame] | 73 | QuicTime::Delta rtt, |
| 74 | QuicByteCount old_cwnd, |
| 75 | QuicByteCount new_cwnd) {} |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 76 | }; |
| 77 | |
| 78 | // Interface which gets callbacks from the QuicSentPacketManager when |
| 79 | // network-related state changes. Implementations must not mutate the |
| 80 | // state of the packet manager as a result of these callbacks. |
| 81 | class QUIC_EXPORT_PRIVATE NetworkChangeVisitor { |
| 82 | public: |
| 83 | virtual ~NetworkChangeVisitor() {} |
| 84 | |
| 85 | // Called when congestion window or RTT may have changed. |
| 86 | virtual void OnCongestionChange() = 0; |
| 87 | |
| 88 | // Called when the Path MTU may have increased. |
| 89 | virtual void OnPathMtuIncreased(QuicPacketLength packet_size) = 0; |
| 90 | }; |
| 91 | |
| 92 | QuicSentPacketManager(Perspective perspective, |
| 93 | const QuicClock* clock, |
QUICHE team | 73957f1 | 2019-04-18 16:21:52 -0700 | [diff] [blame] | 94 | QuicRandom* random, |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 95 | QuicConnectionStats* stats, |
| 96 | CongestionControlType congestion_control_type, |
| 97 | LossDetectionType loss_type); |
| 98 | QuicSentPacketManager(const QuicSentPacketManager&) = delete; |
| 99 | QuicSentPacketManager& operator=(const QuicSentPacketManager&) = delete; |
| 100 | virtual ~QuicSentPacketManager(); |
| 101 | |
| 102 | virtual void SetFromConfig(const QuicConfig& config); |
| 103 | |
| 104 | // Pass the CachedNetworkParameters to the send algorithm. |
| 105 | void ResumeConnectionState( |
| 106 | const CachedNetworkParameters& cached_network_params, |
| 107 | bool max_bandwidth_resumption); |
| 108 | |
| 109 | void SetMaxPacingRate(QuicBandwidth max_pacing_rate) { |
| 110 | pacing_sender_.set_max_pacing_rate(max_pacing_rate); |
| 111 | } |
| 112 | |
| 113 | QuicBandwidth MaxPacingRate() const { |
| 114 | return pacing_sender_.max_pacing_rate(); |
| 115 | } |
| 116 | |
| 117 | // Set handshake_confirmed_ to true and neuter packets in HANDSHAKE packet |
| 118 | // number space. |
| 119 | void SetHandshakeConfirmed(); |
| 120 | |
| 121 | // Requests retransmission of all unacked packets of |retransmission_type|. |
| 122 | // The behavior of this method depends on the value of |retransmission_type|: |
| 123 | // ALL_UNACKED_RETRANSMISSION - All unacked packets will be retransmitted. |
| 124 | // This can happen, for example, after a version negotiation packet has been |
| 125 | // received and all packets needs to be retransmitted with the new version. |
| 126 | // ALL_INITIAL_RETRANSMISSION - Only initially encrypted packets will be |
| 127 | // retransmitted. This can happen, for example, when a CHLO has been rejected |
| 128 | // and the previously encrypted data needs to be encrypted with a new key. |
| 129 | void RetransmitUnackedPackets(TransmissionType retransmission_type); |
| 130 | |
| 131 | // Notify the sent packet manager of an external network measurement or |
| 132 | // prediction for either |bandwidth| or |rtt|; either can be empty. |
| 133 | void AdjustNetworkParameters(QuicBandwidth bandwidth, QuicTime::Delta rtt); |
| 134 | |
| 135 | // Retransmits the oldest pending packet there is still a tail loss probe |
| 136 | // pending. Invoked after OnRetransmissionTimeout. |
| 137 | bool MaybeRetransmitTailLossProbe(); |
| 138 | |
| 139 | // Retransmits the oldest pending packet. |
| 140 | bool MaybeRetransmitOldestPacket(TransmissionType type); |
| 141 | |
| 142 | // Removes the retransmittable frames from all unencrypted packets to ensure |
| 143 | // they don't get retransmitted. |
| 144 | // TODO(fayang): Consider remove this function when deprecating |
| 145 | // quic_use_uber_loss_algorithm. |
| 146 | void NeuterUnencryptedPackets(); |
| 147 | |
| 148 | // Returns true if there are pending retransmissions. |
| 149 | // Not const because retransmissions may be cancelled before returning. |
| 150 | bool HasPendingRetransmissions() const { |
| 151 | return !pending_retransmissions_.empty(); |
| 152 | } |
| 153 | |
| 154 | // Retrieves the next pending retransmission. You must ensure that |
| 155 | // there are pending retransmissions prior to calling this function. |
| 156 | QuicPendingRetransmission NextPendingRetransmission(); |
| 157 | |
| 158 | // Returns true if there's outstanding crypto data. |
| 159 | bool HasUnackedCryptoPackets() const { |
| 160 | return unacked_packets_.HasPendingCryptoPackets(); |
| 161 | } |
| 162 | |
| 163 | // Returns true if there are packets in flight expecting to be acknowledged. |
| 164 | bool HasInFlightPackets() const { |
| 165 | return unacked_packets_.HasInFlightPackets(); |
| 166 | } |
| 167 | |
| 168 | // Returns the smallest packet number of a serialized packet which has not |
| 169 | // been acked by the peer. |
| 170 | QuicPacketNumber GetLeastUnacked() const { |
| 171 | return unacked_packets_.GetLeastUnacked(); |
| 172 | } |
| 173 | |
| 174 | // Called when we have sent bytes to the peer. This informs the manager both |
| 175 | // the number of bytes sent and if they were retransmitted. Returns true if |
| 176 | // the sender should reset the retransmission timer. |
| 177 | bool OnPacketSent(SerializedPacket* serialized_packet, |
| 178 | QuicPacketNumber original_packet_number, |
| 179 | QuicTime sent_time, |
| 180 | TransmissionType transmission_type, |
| 181 | HasRetransmittableData has_retransmittable_data); |
| 182 | |
| 183 | // Called when the retransmission timer expires. |
| 184 | void OnRetransmissionTimeout(); |
| 185 | |
| 186 | // Calculate the time until we can send the next packet to the wire. |
| 187 | // Note 1: When kUnknownWaitTime is returned, there is no need to poll |
| 188 | // TimeUntilSend again until we receive an OnIncomingAckFrame event. |
| 189 | // Note 2: Send algorithms may or may not use |retransmit| in their |
| 190 | // calculations. |
| 191 | QuicTime::Delta TimeUntilSend(QuicTime now) const; |
| 192 | |
| 193 | // Returns the current delay for the retransmission timer, which may send |
| 194 | // either a tail loss probe or do a full RTO. Returns QuicTime::Zero() if |
| 195 | // there are no retransmittable packets. |
| 196 | const QuicTime GetRetransmissionTime() const; |
| 197 | |
| 198 | // Returns the current delay for the path degrading timer, which is used to |
| 199 | // notify the session that this connection is degrading. |
| 200 | const QuicTime::Delta GetPathDegradingDelay() const; |
| 201 | |
| 202 | const RttStats* GetRttStats() const { return &rtt_stats_; } |
| 203 | |
| 204 | // Returns the estimated bandwidth calculated by the congestion algorithm. |
| 205 | QuicBandwidth BandwidthEstimate() const { |
| 206 | return send_algorithm_->BandwidthEstimate(); |
| 207 | } |
| 208 | |
| 209 | const QuicSustainedBandwidthRecorder* SustainedBandwidthRecorder() const { |
| 210 | return &sustained_bandwidth_recorder_; |
| 211 | } |
| 212 | |
| 213 | // Returns the size of the current congestion window in number of |
| 214 | // kDefaultTCPMSS-sized segments. Note, this is not the *available* window. |
| 215 | // Some send algorithms may not use a congestion window and will return 0. |
| 216 | QuicPacketCount GetCongestionWindowInTcpMss() const { |
| 217 | return send_algorithm_->GetCongestionWindow() / kDefaultTCPMSS; |
| 218 | } |
| 219 | |
| 220 | // Returns the number of packets of length |max_packet_length| which fit in |
| 221 | // the current congestion window. More packets may end up in flight if the |
| 222 | // congestion window has been recently reduced, of if non-full packets are |
| 223 | // sent. |
| 224 | QuicPacketCount EstimateMaxPacketsInFlight( |
| 225 | QuicByteCount max_packet_length) const { |
| 226 | return send_algorithm_->GetCongestionWindow() / max_packet_length; |
| 227 | } |
| 228 | |
| 229 | // Returns the size of the current congestion window size in bytes. |
| 230 | QuicByteCount GetCongestionWindowInBytes() const { |
| 231 | return send_algorithm_->GetCongestionWindow(); |
| 232 | } |
| 233 | |
| 234 | // Returns the size of the slow start congestion window in nume of 1460 byte |
| 235 | // TCP segments, aka ssthresh. Some send algorithms do not define a slow |
| 236 | // start threshold and will return 0. |
| 237 | QuicPacketCount GetSlowStartThresholdInTcpMss() const { |
| 238 | return send_algorithm_->GetSlowStartThreshold() / kDefaultTCPMSS; |
| 239 | } |
| 240 | |
wub | 967ba57 | 2019-04-01 09:27:52 -0700 | [diff] [blame] | 241 | // Return the total time spent in slow start so far. If the sender is |
| 242 | // currently in slow start, the return value will include the duration between |
| 243 | // the most recent entry to slow start and now. |
| 244 | // |
| 245 | // Only implemented for BBR. Return QuicTime::Delta::Infinite() for other |
| 246 | // congestion controllers. |
| 247 | QuicTime::Delta GetSlowStartDuration() const; |
| 248 | |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 249 | // Returns debugging information about the state of the congestion controller. |
vasilvv | c48c871 | 2019-03-11 13:38:16 -0700 | [diff] [blame] | 250 | std::string GetDebugState() const; |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 251 | |
| 252 | // Returns the number of bytes that are considered in-flight, i.e. not lost or |
| 253 | // acknowledged. |
| 254 | QuicByteCount GetBytesInFlight() const { |
| 255 | return unacked_packets_.bytes_in_flight(); |
| 256 | } |
| 257 | |
| 258 | // No longer retransmit data for |stream_id|. |
| 259 | void CancelRetransmissionsForStream(QuicStreamId stream_id); |
| 260 | |
| 261 | // Called when peer address changes and the connection migrates. |
| 262 | void OnConnectionMigration(AddressChangeType type); |
| 263 | |
| 264 | // Called when an ack frame is initially parsed. |
| 265 | void OnAckFrameStart(QuicPacketNumber largest_acked, |
| 266 | QuicTime::Delta ack_delay_time, |
| 267 | QuicTime ack_receive_time); |
| 268 | |
| 269 | // Called when ack range [start, end) is received. Populates packets_acked_ |
| 270 | // with newly acked packets. |
| 271 | void OnAckRange(QuicPacketNumber start, QuicPacketNumber end); |
| 272 | |
| 273 | // Called when a timestamp is processed. If it's present in packets_acked_, |
| 274 | // the timestamp field is set. Otherwise, the timestamp is ignored. |
| 275 | void OnAckTimestamp(QuicPacketNumber packet_number, QuicTime timestamp); |
| 276 | |
fayang | 3eb8221 | 2019-04-16 12:05:46 -0700 | [diff] [blame] | 277 | // Called when an ack frame is parsed completely. |
| 278 | AckResult OnAckFrameEnd(QuicTime ack_receive_time, |
| 279 | EncryptionLevel ack_decrypted_level); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 280 | |
| 281 | // Called to enable/disable letting session decide what to write. |
| 282 | void SetSessionDecideWhatToWrite(bool session_decides_what_to_write) { |
| 283 | unacked_packets_.SetSessionDecideWhatToWrite(session_decides_what_to_write); |
| 284 | } |
| 285 | |
QUICHE team | c279cec | 2019-03-22 06:51:48 -0700 | [diff] [blame] | 286 | void EnableMultiplePacketNumberSpacesSupport(); |
| 287 | |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 288 | void SetDebugDelegate(DebugDelegate* debug_delegate); |
| 289 | |
| 290 | void SetPacingAlarmGranularity(QuicTime::Delta alarm_granularity) { |
| 291 | pacing_sender_.set_alarm_granularity(alarm_granularity); |
| 292 | } |
| 293 | |
| 294 | QuicPacketNumber GetLargestObserved() const { |
| 295 | return unacked_packets_.largest_acked(); |
| 296 | } |
| 297 | |
QUICHE team | c279cec | 2019-03-22 06:51:48 -0700 | [diff] [blame] | 298 | QuicPacketNumber GetLargestAckedPacket( |
| 299 | EncryptionLevel decrypted_packet_level) const; |
| 300 | |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 301 | QuicPacketNumber GetLargestSentPacket() const { |
| 302 | return unacked_packets_.largest_sent_packet(); |
| 303 | } |
| 304 | |
QUICHE team | c279cec | 2019-03-22 06:51:48 -0700 | [diff] [blame] | 305 | QuicPacketNumber GetLargestSentPacket( |
| 306 | EncryptionLevel decrypted_packet_level) const; |
| 307 | |
| 308 | QuicPacketNumber GetLargestPacketPeerKnowsIsAcked( |
| 309 | EncryptionLevel decrypted_packet_level) const; |
| 310 | |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 311 | void SetNetworkChangeVisitor(NetworkChangeVisitor* visitor) { |
| 312 | DCHECK(!network_change_visitor_); |
| 313 | DCHECK(visitor); |
| 314 | network_change_visitor_ = visitor; |
| 315 | } |
| 316 | |
| 317 | bool InSlowStart() const { return send_algorithm_->InSlowStart(); } |
| 318 | |
| 319 | size_t GetConsecutiveRtoCount() const { return consecutive_rto_count_; } |
| 320 | |
| 321 | size_t GetConsecutiveTlpCount() const { return consecutive_tlp_count_; } |
| 322 | |
| 323 | void OnApplicationLimited(); |
| 324 | |
| 325 | const SendAlgorithmInterface* GetSendAlgorithm() const { |
| 326 | return send_algorithm_.get(); |
| 327 | } |
| 328 | |
| 329 | void SetSessionNotifier(SessionNotifierInterface* session_notifier) { |
| 330 | unacked_packets_.SetSessionNotifier(session_notifier); |
| 331 | } |
| 332 | |
| 333 | QuicTime GetNextReleaseTime() const; |
| 334 | |
| 335 | QuicPacketCount initial_congestion_window() const { |
| 336 | return initial_congestion_window_; |
| 337 | } |
| 338 | |
| 339 | QuicPacketNumber largest_packet_peer_knows_is_acked() const { |
| 340 | return largest_packet_peer_knows_is_acked_; |
| 341 | } |
| 342 | |
| 343 | bool handshake_confirmed() const { return handshake_confirmed_; } |
| 344 | |
| 345 | bool session_decides_what_to_write() const { |
| 346 | return unacked_packets_.session_decides_what_to_write(); |
| 347 | } |
| 348 | |
| 349 | size_t pending_timer_transmission_count() const { |
| 350 | return pending_timer_transmission_count_; |
| 351 | } |
| 352 | |
| 353 | QuicTime::Delta delayed_ack_time() const { return delayed_ack_time_; } |
| 354 | |
| 355 | void set_delayed_ack_time(QuicTime::Delta delayed_ack_time) { |
| 356 | // The delayed ack time should never be more than one half the min RTO time. |
| 357 | DCHECK_LE(delayed_ack_time, (min_rto_timeout_ * 0.5)); |
| 358 | delayed_ack_time_ = delayed_ack_time; |
| 359 | } |
| 360 | |
zhongyi | fbb2577 | 2019-04-10 16:54:08 -0700 | [diff] [blame] | 361 | bool enable_half_rtt_tail_loss_probe() const { |
| 362 | return enable_half_rtt_tail_loss_probe_; |
| 363 | } |
| 364 | |
| 365 | void set_enable_half_rtt_tail_loss_probe( |
| 366 | bool enable_half_rtt_tail_loss_probe) { |
| 367 | enable_half_rtt_tail_loss_probe_ = enable_half_rtt_tail_loss_probe; |
| 368 | } |
| 369 | |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 370 | const QuicUnackedPacketMap& unacked_packets() const { |
| 371 | return unacked_packets_; |
| 372 | } |
| 373 | |
| 374 | // Sets the send algorithm to the given congestion control type and points the |
| 375 | // pacing sender at |send_algorithm_|. Can be called any number of times. |
| 376 | void SetSendAlgorithm(CongestionControlType congestion_control_type); |
| 377 | |
| 378 | // Sets the send algorithm to |send_algorithm| and points the pacing sender at |
| 379 | // |send_algorithm_|. Takes ownership of |send_algorithm|. Can be called any |
| 380 | // number of times. |
| 381 | // Setting the send algorithm once the connection is underway is dangerous. |
| 382 | void SetSendAlgorithm(SendAlgorithmInterface* send_algorithm); |
| 383 | |
QUICHE team | 9929cc4 | 2019-03-13 08:17:43 -0700 | [diff] [blame] | 384 | bool tolerate_reneging() const { return tolerate_reneging_; } |
| 385 | |
QUICHE team | c279cec | 2019-03-22 06:51:48 -0700 | [diff] [blame] | 386 | bool supports_multiple_packet_number_spaces() const { |
| 387 | return unacked_packets_.supports_multiple_packet_number_spaces(); |
| 388 | } |
| 389 | |
QUICHE team | cd09802 | 2019-03-22 18:49:55 -0700 | [diff] [blame] | 390 | bool use_uber_loss_algorithm() const { |
| 391 | return unacked_packets_.use_uber_loss_algorithm(); |
| 392 | } |
| 393 | |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 394 | private: |
| 395 | friend class test::QuicConnectionPeer; |
| 396 | friend class test::QuicSentPacketManagerPeer; |
| 397 | |
| 398 | // The retransmission timer is a single timer which switches modes depending |
| 399 | // upon connection state. |
| 400 | enum RetransmissionTimeoutMode { |
| 401 | // A conventional TCP style RTO. |
| 402 | RTO_MODE, |
| 403 | // A tail loss probe. By default, QUIC sends up to two before RTOing. |
| 404 | TLP_MODE, |
| 405 | // Retransmission of handshake packets prior to handshake completion. |
| 406 | HANDSHAKE_MODE, |
| 407 | // Re-invoke the loss detection when a packet is not acked before the |
| 408 | // loss detection algorithm expects. |
| 409 | LOSS_MODE, |
| 410 | }; |
| 411 | |
| 412 | typedef QuicLinkedHashMap<QuicPacketNumber, |
| 413 | TransmissionType, |
| 414 | QuicPacketNumberHash> |
| 415 | PendingRetransmissionMap; |
| 416 | |
| 417 | // Returns the current retransmission mode. |
| 418 | RetransmissionTimeoutMode GetRetransmissionMode() const; |
| 419 | |
| 420 | // Retransmits all crypto stream packets. |
| 421 | void RetransmitCryptoPackets(); |
| 422 | |
| 423 | // Retransmits two packets for an RTO and removes any non-retransmittable |
| 424 | // packets from flight. |
| 425 | void RetransmitRtoPackets(); |
| 426 | |
| 427 | // Returns the timeout for retransmitting crypto handshake packets. |
| 428 | const QuicTime::Delta GetCryptoRetransmissionDelay() const; |
| 429 | |
| 430 | // Returns the timeout for a new tail loss probe. |consecutive_tlp_count| is |
| 431 | // the number of consecutive tail loss probes that have already been sent. |
| 432 | const QuicTime::Delta GetTailLossProbeDelay( |
| 433 | size_t consecutive_tlp_count) const; |
| 434 | |
| 435 | // Calls GetTailLossProbeDelay() with values from the current state of this |
| 436 | // packet manager as its params. |
| 437 | const QuicTime::Delta GetTailLossProbeDelay() const { |
| 438 | return GetTailLossProbeDelay(consecutive_tlp_count_); |
| 439 | } |
| 440 | |
| 441 | // Returns the retransmission timeout, after which a full RTO occurs. |
| 442 | // |consecutive_rto_count| is the number of consecutive RTOs that have already |
| 443 | // occurred. |
| 444 | const QuicTime::Delta GetRetransmissionDelay( |
| 445 | size_t consecutive_rto_count) const; |
| 446 | |
| 447 | // Calls GetRetransmissionDelay() with values from the current state of this |
| 448 | // packet manager as its params. |
| 449 | const QuicTime::Delta GetRetransmissionDelay() const { |
| 450 | return GetRetransmissionDelay(consecutive_rto_count_); |
| 451 | } |
| 452 | |
| 453 | // Returns the newest transmission associated with a packet. |
| 454 | QuicPacketNumber GetNewestRetransmission( |
| 455 | QuicPacketNumber packet_number, |
| 456 | const QuicTransmissionInfo& transmission_info) const; |
| 457 | |
| 458 | // Update the RTT if the ack is for the largest acked packet number. |
| 459 | // Returns true if the rtt was updated. |
| 460 | bool MaybeUpdateRTT(QuicPacketNumber largest_acked, |
| 461 | QuicTime::Delta ack_delay_time, |
| 462 | QuicTime ack_receive_time); |
| 463 | |
| 464 | // Invokes the loss detection algorithm and loses and retransmits packets if |
| 465 | // necessary. |
| 466 | void InvokeLossDetection(QuicTime time); |
| 467 | |
| 468 | // Invokes OnCongestionEvent if |rtt_updated| is true, there are pending acks, |
| 469 | // or pending losses. Clears pending acks and pending losses afterwards. |
| 470 | // |prior_in_flight| is the number of bytes in flight before the losses or |
| 471 | // acks, |event_time| is normally the timestamp of the ack packet which caused |
| 472 | // the event, although it can be the time at which loss detection was |
| 473 | // triggered. |
| 474 | void MaybeInvokeCongestionEvent(bool rtt_updated, |
| 475 | QuicByteCount prior_in_flight, |
| 476 | QuicTime event_time); |
| 477 | |
| 478 | // Removes the retransmittability and in flight properties from the packet at |
| 479 | // |info| due to receipt by the peer. |
| 480 | void MarkPacketHandled(QuicPacketNumber packet_number, |
| 481 | QuicTransmissionInfo* info, |
| 482 | QuicTime::Delta ack_delay_time); |
| 483 | |
| 484 | // Request that |packet_number| be retransmitted after the other pending |
| 485 | // retransmissions. Does not add it to the retransmissions if it's already |
| 486 | // a pending retransmission. |
| 487 | void MarkForRetransmission(QuicPacketNumber packet_number, |
| 488 | TransmissionType transmission_type); |
| 489 | |
| 490 | // Performs whatever work is need to retransmit the data correctly, either |
| 491 | // by retransmitting the frames directly or by notifying that the frames |
| 492 | // are lost. |
| 493 | void HandleRetransmission(TransmissionType transmission_type, |
| 494 | QuicTransmissionInfo* transmission_info); |
| 495 | |
| 496 | // Called after packets have been marked handled with last received ack frame. |
fayang | 3eb8221 | 2019-04-16 12:05:46 -0700 | [diff] [blame] | 497 | void PostProcessNewlyAckedPackets(const QuicAckFrame& ack_frame, |
| 498 | QuicTime ack_receive_time, |
| 499 | bool rtt_updated, |
| 500 | QuicByteCount prior_bytes_in_flight); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 501 | |
| 502 | // Notify observers that packet with QuicTransmissionInfo |info| is a spurious |
| 503 | // retransmission. It is caller's responsibility to guarantee the packet with |
| 504 | // QuicTransmissionInfo |info| is a spurious retransmission before calling |
| 505 | // this function. |
| 506 | void RecordOneSpuriousRetransmission(const QuicTransmissionInfo& info); |
| 507 | |
| 508 | // Notify observers about spurious retransmits of packet with |
| 509 | // QuicTransmissionInfo |info|. |
| 510 | void RecordSpuriousRetransmissions(const QuicTransmissionInfo& info, |
| 511 | QuicPacketNumber acked_packet_number); |
| 512 | |
| 513 | // Sets the initial RTT of the connection. |
| 514 | void SetInitialRtt(QuicTime::Delta rtt); |
| 515 | |
wub | 37ec596 | 2019-04-03 09:02:51 -0700 | [diff] [blame] | 516 | // Should only be called from constructor. |
| 517 | LossDetectionInterface* GetInitialLossAlgorithm(); |
| 518 | |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 519 | // Called when handshake is confirmed to remove the retransmittable frames |
| 520 | // from all packets of HANDSHAKE_DATA packet number space to ensure they don't |
| 521 | // get retransmitted and will eventually be removed from unacked packets map. |
| 522 | // Only used when quic_use_uber_loss_algorithm is true. Please note, this only |
| 523 | // applies to QUIC Crypto and needs to be changed when switches to IETF QUIC |
| 524 | // with QUIC TLS. |
| 525 | void NeuterHandshakePackets(); |
| 526 | |
| 527 | // Newly serialized retransmittable packets are added to this map, which |
| 528 | // contains owning pointers to any contained frames. If a packet is |
| 529 | // retransmitted, this map will contain entries for both the old and the new |
| 530 | // packet. The old packet's retransmittable frames entry will be nullptr, |
| 531 | // while the new packet's entry will contain the frames to retransmit. |
| 532 | // If the old packet is acked before the new packet, then the old entry will |
| 533 | // be removed from the map and the new entry's retransmittable frames will be |
| 534 | // set to nullptr. |
| 535 | QuicUnackedPacketMap unacked_packets_; |
| 536 | |
| 537 | // Pending retransmissions which have not been packetized and sent yet. |
| 538 | PendingRetransmissionMap pending_retransmissions_; |
| 539 | |
| 540 | const QuicClock* clock_; |
QUICHE team | 73957f1 | 2019-04-18 16:21:52 -0700 | [diff] [blame] | 541 | QuicRandom* random_; |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 542 | QuicConnectionStats* stats_; |
| 543 | |
| 544 | DebugDelegate* debug_delegate_; |
| 545 | NetworkChangeVisitor* network_change_visitor_; |
| 546 | QuicPacketCount initial_congestion_window_; |
| 547 | RttStats rtt_stats_; |
| 548 | std::unique_ptr<SendAlgorithmInterface> send_algorithm_; |
| 549 | // Not owned. Always points to |general_loss_algorithm_| outside of tests. |
| 550 | LossDetectionInterface* loss_algorithm_; |
| 551 | // TODO(fayang): Remove general_loss_algorithm_ when deprecating |
| 552 | // quic_use_uber_loss_algorithm. |
| 553 | GeneralLossAlgorithm general_loss_algorithm_; |
| 554 | UberLossAlgorithm uber_loss_algorithm_; |
| 555 | |
| 556 | // Tracks the first RTO packet. If any packet before that packet gets acked, |
| 557 | // it indicates the RTO was spurious and should be reversed(F-RTO). |
| 558 | QuicPacketNumber first_rto_transmission_; |
| 559 | // Number of times the RTO timer has fired in a row without receiving an ack. |
| 560 | size_t consecutive_rto_count_; |
| 561 | // Number of times the tail loss probe has been sent. |
| 562 | size_t consecutive_tlp_count_; |
| 563 | // Number of times the crypto handshake has been retransmitted. |
| 564 | size_t consecutive_crypto_retransmission_count_; |
| 565 | // Number of pending transmissions of TLP, RTO, or crypto packets. |
| 566 | size_t pending_timer_transmission_count_; |
| 567 | // Maximum number of tail loss probes to send before firing an RTO. |
| 568 | size_t max_tail_loss_probes_; |
| 569 | // Maximum number of packets to send upon RTO. |
| 570 | QuicPacketCount max_rto_packets_; |
| 571 | // If true, send the TLP at 0.5 RTT. |
| 572 | bool enable_half_rtt_tail_loss_probe_; |
| 573 | bool using_pacing_; |
| 574 | // If true, use the new RTO with loss based CWND reduction instead of the send |
| 575 | // algorithms's OnRetransmissionTimeout to reduce the congestion window. |
| 576 | bool use_new_rto_; |
| 577 | // If true, use a more conservative handshake retransmission policy. |
| 578 | bool conservative_handshake_retransmits_; |
| 579 | // The minimum TLP timeout. |
| 580 | QuicTime::Delta min_tlp_timeout_; |
| 581 | // The minimum RTO. |
| 582 | QuicTime::Delta min_rto_timeout_; |
| 583 | // Whether to use IETF style TLP that includes the max ack delay. |
| 584 | bool ietf_style_tlp_; |
| 585 | // IETF style TLP, but with a 2x multiplier instead of 1.5x. |
| 586 | bool ietf_style_2x_tlp_; |
| 587 | |
| 588 | // Vectors packets acked and lost as a result of the last congestion event. |
| 589 | AckedPacketVector packets_acked_; |
| 590 | LostPacketVector packets_lost_; |
| 591 | // Largest newly acknowledged packet. |
| 592 | QuicPacketNumber largest_newly_acked_; |
| 593 | // Largest packet in bytes ever acknowledged. |
| 594 | QuicPacketLength largest_mtu_acked_; |
| 595 | |
| 596 | // Replaces certain calls to |send_algorithm_| when |using_pacing_| is true. |
| 597 | // Calls into |send_algorithm_| for the underlying congestion control. |
| 598 | PacingSender pacing_sender_; |
| 599 | |
| 600 | // Set to true after the crypto handshake has successfully completed. After |
| 601 | // this is true we no longer use HANDSHAKE_MODE, and further frames sent on |
| 602 | // the crypto stream (i.e. SCUP messages) are treated like normal |
| 603 | // retransmittable frames. |
| 604 | bool handshake_confirmed_; |
| 605 | |
| 606 | // Records bandwidth from server to client in normal operation, over periods |
| 607 | // of time with no loss events. |
| 608 | QuicSustainedBandwidthRecorder sustained_bandwidth_recorder_; |
| 609 | |
| 610 | // The largest acked value that was sent in an ack, which has then been acked. |
| 611 | QuicPacketNumber largest_packet_peer_knows_is_acked_; |
QUICHE team | c279cec | 2019-03-22 06:51:48 -0700 | [diff] [blame] | 612 | // The largest acked value that was sent in an ack, which has then been acked |
| 613 | // for per packet number space. Only used when connection supports multiple |
| 614 | // packet number spaces. |
| 615 | QuicPacketNumber |
| 616 | largest_packets_peer_knows_is_acked_[NUM_PACKET_NUMBER_SPACES]; |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 617 | |
| 618 | // The maximum amount of time to wait before sending an acknowledgement. |
| 619 | // The recovery code assumes the delayed ack time is the same on both sides. |
| 620 | QuicTime::Delta delayed_ack_time_; |
| 621 | |
| 622 | // Latest received ack frame. |
| 623 | QuicAckFrame last_ack_frame_; |
| 624 | |
| 625 | // Record whether RTT gets updated by last largest acked.. |
| 626 | bool rtt_updated_; |
| 627 | |
| 628 | // A reverse iterator of last_ack_frame_.packets. This is reset in |
| 629 | // OnAckRangeStart, and gradually moves in OnAckRange.. |
| 630 | PacketNumberQueue::const_reverse_iterator acked_packets_iter_; |
QUICHE team | 9929cc4 | 2019-03-13 08:17:43 -0700 | [diff] [blame] | 631 | |
| 632 | // Latched value of quic_tolerate_reneging. |
| 633 | const bool tolerate_reneging_; |
ianswett | 898306b | 2019-04-23 11:05:57 -0700 | [diff] [blame] | 634 | |
| 635 | // Latched value of quic_loss_removes_from_inflight. |
| 636 | const bool loss_removes_from_inflight_; |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 637 | }; |
| 638 | |
| 639 | } // namespace quic |
| 640 | |
| 641 | #endif // QUICHE_QUIC_CORE_QUIC_SENT_PACKET_MANAGER_H_ |