blob: c0242836877688066977e7a5f4d25e6933d8aab6 [file] [log] [blame]
QUICHE teama6ef0a62019-03-07 20:34:33 -05001// 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>
vasilvv872e7a32019-03-12 16:42:44 -070012#include <string>
QUICHE teama6ef0a62019-03-07 20:34:33 -050013#include <utility>
14#include <vector>
15
QUICHE teama6ef0a62019-03-07 20:34:33 -050016#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"
dschinazi56fb53e2019-06-21 15:30:04 -070020#include "net/third_party/quiche/src/quic/core/proto/cached_network_parameters_proto.h"
QUICHE teama6ef0a62019-03-07 20:34:33 -050021#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 teama6ef0a62019-03-07 20:34:33 -050029
30namespace quic {
31
32namespace test {
33class QuicConnectionPeer;
34class QuicSentPacketManagerPeer;
35} // namespace test
36
37class QuicClock;
38class QuicConfig;
39struct 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.
46class 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(
dschinazi17d42422019-06-18 16:35:07 -070057 TransmissionType /*transmission_type*/,
58 QuicByteCount /*byte_size*/) {}
QUICHE teama6ef0a62019-03-07 20:34:33 -050059
fayangf8e918b2019-07-16 13:03:16 -070060 virtual void OnIncomingAck(QuicPacketNumber /*ack_packet_number*/,
61 const QuicAckFrame& /*ack_frame*/,
dschinazi17d42422019-06-18 16:35:07 -070062 QuicTime /*ack_receive_time*/,
63 QuicPacketNumber /*largest_observed*/,
64 bool /*rtt_updated*/,
65 QuicPacketNumber /*least_unacked_sent_packet*/) {
66 }
QUICHE teama6ef0a62019-03-07 20:34:33 -050067
dschinazi17d42422019-06-18 16:35:07 -070068 virtual void OnPacketLoss(QuicPacketNumber /*lost_packet_number*/,
69 TransmissionType /*transmission_type*/,
70 QuicTime /*detection_time*/) {}
QUICHE teama6ef0a62019-03-07 20:34:33 -050071
72 virtual void OnApplicationLimited() {}
73
dschinazi17d42422019-06-18 16:35:07 -070074 virtual void OnAdjustNetworkParameters(QuicBandwidth /*bandwidth*/,
75 QuicTime::Delta /*rtt*/,
76 QuicByteCount /*old_cwnd*/,
77 QuicByteCount /*new_cwnd*/) {}
QUICHE teama6ef0a62019-03-07 20:34:33 -050078 };
79
80 // Interface which gets callbacks from the QuicSentPacketManager when
81 // network-related state changes. Implementations must not mutate the
82 // state of the packet manager as a result of these callbacks.
83 class QUIC_EXPORT_PRIVATE NetworkChangeVisitor {
84 public:
85 virtual ~NetworkChangeVisitor() {}
86
87 // Called when congestion window or RTT may have changed.
88 virtual void OnCongestionChange() = 0;
89
90 // Called when the Path MTU may have increased.
91 virtual void OnPathMtuIncreased(QuicPacketLength packet_size) = 0;
92 };
93
fayang67f82272019-08-14 16:08:45 -070094 // The retransmission timer is a single timer which switches modes depending
95 // upon connection state.
96 enum RetransmissionTimeoutMode {
97 // A conventional TCP style RTO.
98 RTO_MODE,
99 // A tail loss probe. By default, QUIC sends up to two before RTOing.
100 TLP_MODE,
101 // Retransmission of handshake packets prior to handshake completion.
102 HANDSHAKE_MODE,
103 // Re-invoke the loss detection when a packet is not acked before the
104 // loss detection algorithm expects.
105 LOSS_MODE,
fayangce0a3162019-08-15 09:05:36 -0700106 // A probe timeout. At least one probe packet must be sent when timer
107 // expires.
108 PTO_MODE,
fayang67f82272019-08-14 16:08:45 -0700109 };
110
QUICHE teama6ef0a62019-03-07 20:34:33 -0500111 QuicSentPacketManager(Perspective perspective,
112 const QuicClock* clock,
QUICHE team73957f12019-04-18 16:21:52 -0700113 QuicRandom* random,
QUICHE teama6ef0a62019-03-07 20:34:33 -0500114 QuicConnectionStats* stats,
115 CongestionControlType congestion_control_type,
116 LossDetectionType loss_type);
117 QuicSentPacketManager(const QuicSentPacketManager&) = delete;
118 QuicSentPacketManager& operator=(const QuicSentPacketManager&) = delete;
119 virtual ~QuicSentPacketManager();
120
121 virtual void SetFromConfig(const QuicConfig& config);
122
123 // Pass the CachedNetworkParameters to the send algorithm.
124 void ResumeConnectionState(
125 const CachedNetworkParameters& cached_network_params,
126 bool max_bandwidth_resumption);
127
128 void SetMaxPacingRate(QuicBandwidth max_pacing_rate) {
129 pacing_sender_.set_max_pacing_rate(max_pacing_rate);
130 }
131
132 QuicBandwidth MaxPacingRate() const {
133 return pacing_sender_.max_pacing_rate();
134 }
135
136 // Set handshake_confirmed_ to true and neuter packets in HANDSHAKE packet
137 // number space.
138 void SetHandshakeConfirmed();
139
140 // Requests retransmission of all unacked packets of |retransmission_type|.
141 // The behavior of this method depends on the value of |retransmission_type|:
142 // ALL_UNACKED_RETRANSMISSION - All unacked packets will be retransmitted.
143 // This can happen, for example, after a version negotiation packet has been
144 // received and all packets needs to be retransmitted with the new version.
145 // ALL_INITIAL_RETRANSMISSION - Only initially encrypted packets will be
146 // retransmitted. This can happen, for example, when a CHLO has been rejected
147 // and the previously encrypted data needs to be encrypted with a new key.
148 void RetransmitUnackedPackets(TransmissionType retransmission_type);
149
150 // Notify the sent packet manager of an external network measurement or
151 // prediction for either |bandwidth| or |rtt|; either can be empty.
fayangf1b99dc2019-05-14 06:29:18 -0700152 void AdjustNetworkParameters(QuicBandwidth bandwidth,
153 QuicTime::Delta rtt,
154 bool allow_cwnd_to_decrease);
QUICHE teama6ef0a62019-03-07 20:34:33 -0500155
156 // Retransmits the oldest pending packet there is still a tail loss probe
157 // pending. Invoked after OnRetransmissionTimeout.
158 bool MaybeRetransmitTailLossProbe();
159
160 // Retransmits the oldest pending packet.
161 bool MaybeRetransmitOldestPacket(TransmissionType type);
162
163 // Removes the retransmittable frames from all unencrypted packets to ensure
164 // they don't get retransmitted.
fayangbf3d2862019-06-20 14:13:44 -0700165 // TODO(fayang): Consider replace this function with NeuterHandshakePackets.
QUICHE teama6ef0a62019-03-07 20:34:33 -0500166 void NeuterUnencryptedPackets();
167
168 // Returns true if there are pending retransmissions.
169 // Not const because retransmissions may be cancelled before returning.
170 bool HasPendingRetransmissions() const {
171 return !pending_retransmissions_.empty();
172 }
173
174 // Retrieves the next pending retransmission. You must ensure that
175 // there are pending retransmissions prior to calling this function.
176 QuicPendingRetransmission NextPendingRetransmission();
177
178 // Returns true if there's outstanding crypto data.
179 bool HasUnackedCryptoPackets() const {
180 return unacked_packets_.HasPendingCryptoPackets();
181 }
182
183 // Returns true if there are packets in flight expecting to be acknowledged.
184 bool HasInFlightPackets() const {
185 return unacked_packets_.HasInFlightPackets();
186 }
187
188 // Returns the smallest packet number of a serialized packet which has not
189 // been acked by the peer.
190 QuicPacketNumber GetLeastUnacked() const {
191 return unacked_packets_.GetLeastUnacked();
192 }
193
194 // Called when we have sent bytes to the peer. This informs the manager both
195 // the number of bytes sent and if they were retransmitted. Returns true if
196 // the sender should reset the retransmission timer.
197 bool OnPacketSent(SerializedPacket* serialized_packet,
198 QuicPacketNumber original_packet_number,
199 QuicTime sent_time,
200 TransmissionType transmission_type,
201 HasRetransmittableData has_retransmittable_data);
202
fayang67f82272019-08-14 16:08:45 -0700203 // Called when the retransmission timer expires and returns the retransmission
204 // mode.
205 RetransmissionTimeoutMode OnRetransmissionTimeout();
QUICHE teama6ef0a62019-03-07 20:34:33 -0500206
207 // Calculate the time until we can send the next packet to the wire.
208 // Note 1: When kUnknownWaitTime is returned, there is no need to poll
209 // TimeUntilSend again until we receive an OnIncomingAckFrame event.
210 // Note 2: Send algorithms may or may not use |retransmit| in their
211 // calculations.
212 QuicTime::Delta TimeUntilSend(QuicTime now) const;
213
214 // Returns the current delay for the retransmission timer, which may send
215 // either a tail loss probe or do a full RTO. Returns QuicTime::Zero() if
216 // there are no retransmittable packets.
217 const QuicTime GetRetransmissionTime() const;
218
219 // Returns the current delay for the path degrading timer, which is used to
220 // notify the session that this connection is degrading.
221 const QuicTime::Delta GetPathDegradingDelay() const;
222
223 const RttStats* GetRttStats() const { return &rtt_stats_; }
224
225 // Returns the estimated bandwidth calculated by the congestion algorithm.
226 QuicBandwidth BandwidthEstimate() const {
227 return send_algorithm_->BandwidthEstimate();
228 }
229
230 const QuicSustainedBandwidthRecorder* SustainedBandwidthRecorder() const {
231 return &sustained_bandwidth_recorder_;
232 }
233
234 // Returns the size of the current congestion window in number of
235 // kDefaultTCPMSS-sized segments. Note, this is not the *available* window.
236 // Some send algorithms may not use a congestion window and will return 0.
237 QuicPacketCount GetCongestionWindowInTcpMss() const {
238 return send_algorithm_->GetCongestionWindow() / kDefaultTCPMSS;
239 }
240
241 // Returns the number of packets of length |max_packet_length| which fit in
242 // the current congestion window. More packets may end up in flight if the
243 // congestion window has been recently reduced, of if non-full packets are
244 // sent.
245 QuicPacketCount EstimateMaxPacketsInFlight(
246 QuicByteCount max_packet_length) const {
247 return send_algorithm_->GetCongestionWindow() / max_packet_length;
248 }
249
250 // Returns the size of the current congestion window size in bytes.
251 QuicByteCount GetCongestionWindowInBytes() const {
252 return send_algorithm_->GetCongestionWindow();
253 }
254
255 // Returns the size of the slow start congestion window in nume of 1460 byte
256 // TCP segments, aka ssthresh. Some send algorithms do not define a slow
257 // start threshold and will return 0.
258 QuicPacketCount GetSlowStartThresholdInTcpMss() const {
259 return send_algorithm_->GetSlowStartThreshold() / kDefaultTCPMSS;
260 }
261
wub967ba572019-04-01 09:27:52 -0700262 // Return the total time spent in slow start so far. If the sender is
263 // currently in slow start, the return value will include the duration between
264 // the most recent entry to slow start and now.
265 //
266 // Only implemented for BBR. Return QuicTime::Delta::Infinite() for other
267 // congestion controllers.
268 QuicTime::Delta GetSlowStartDuration() const;
269
QUICHE teama6ef0a62019-03-07 20:34:33 -0500270 // Returns debugging information about the state of the congestion controller.
vasilvvc48c8712019-03-11 13:38:16 -0700271 std::string GetDebugState() const;
QUICHE teama6ef0a62019-03-07 20:34:33 -0500272
273 // Returns the number of bytes that are considered in-flight, i.e. not lost or
274 // acknowledged.
275 QuicByteCount GetBytesInFlight() const {
276 return unacked_packets_.bytes_in_flight();
277 }
278
279 // No longer retransmit data for |stream_id|.
280 void CancelRetransmissionsForStream(QuicStreamId stream_id);
281
282 // Called when peer address changes and the connection migrates.
283 void OnConnectionMigration(AddressChangeType type);
284
285 // Called when an ack frame is initially parsed.
286 void OnAckFrameStart(QuicPacketNumber largest_acked,
287 QuicTime::Delta ack_delay_time,
288 QuicTime ack_receive_time);
289
290 // Called when ack range [start, end) is received. Populates packets_acked_
291 // with newly acked packets.
292 void OnAckRange(QuicPacketNumber start, QuicPacketNumber end);
293
294 // Called when a timestamp is processed. If it's present in packets_acked_,
295 // the timestamp field is set. Otherwise, the timestamp is ignored.
296 void OnAckTimestamp(QuicPacketNumber packet_number, QuicTime timestamp);
297
fayang3eb82212019-04-16 12:05:46 -0700298 // Called when an ack frame is parsed completely.
299 AckResult OnAckFrameEnd(QuicTime ack_receive_time,
fayangf8e918b2019-07-16 13:03:16 -0700300 QuicPacketNumber ack_packet_number,
fayang3eb82212019-04-16 12:05:46 -0700301 EncryptionLevel ack_decrypted_level);
QUICHE teama6ef0a62019-03-07 20:34:33 -0500302
303 // Called to enable/disable letting session decide what to write.
fayangd3016832019-08-08 07:24:45 -0700304 void SetSessionDecideWhatToWrite(bool session_decides_what_to_write);
QUICHE teama6ef0a62019-03-07 20:34:33 -0500305
QUICHE teamc279cec2019-03-22 06:51:48 -0700306 void EnableMultiplePacketNumberSpacesSupport();
307
QUICHE teama6ef0a62019-03-07 20:34:33 -0500308 void SetDebugDelegate(DebugDelegate* debug_delegate);
309
310 void SetPacingAlarmGranularity(QuicTime::Delta alarm_granularity) {
311 pacing_sender_.set_alarm_granularity(alarm_granularity);
312 }
313
314 QuicPacketNumber GetLargestObserved() const {
315 return unacked_packets_.largest_acked();
316 }
317
QUICHE teamc279cec2019-03-22 06:51:48 -0700318 QuicPacketNumber GetLargestAckedPacket(
319 EncryptionLevel decrypted_packet_level) const;
320
QUICHE teama6ef0a62019-03-07 20:34:33 -0500321 QuicPacketNumber GetLargestSentPacket() const {
322 return unacked_packets_.largest_sent_packet();
323 }
324
QUICHE teamc279cec2019-03-22 06:51:48 -0700325 QuicPacketNumber GetLargestSentPacket(
326 EncryptionLevel decrypted_packet_level) const;
327
328 QuicPacketNumber GetLargestPacketPeerKnowsIsAcked(
329 EncryptionLevel decrypted_packet_level) const;
330
QUICHE teama6ef0a62019-03-07 20:34:33 -0500331 void SetNetworkChangeVisitor(NetworkChangeVisitor* visitor) {
332 DCHECK(!network_change_visitor_);
333 DCHECK(visitor);
334 network_change_visitor_ = visitor;
335 }
336
337 bool InSlowStart() const { return send_algorithm_->InSlowStart(); }
338
339 size_t GetConsecutiveRtoCount() const { return consecutive_rto_count_; }
340
341 size_t GetConsecutiveTlpCount() const { return consecutive_tlp_count_; }
342
fayangce0a3162019-08-15 09:05:36 -0700343 size_t GetConsecutivePtoCount() const { return consecutive_pto_count_; }
344
QUICHE teama6ef0a62019-03-07 20:34:33 -0500345 void OnApplicationLimited();
346
347 const SendAlgorithmInterface* GetSendAlgorithm() const {
348 return send_algorithm_.get();
349 }
350
351 void SetSessionNotifier(SessionNotifierInterface* session_notifier) {
352 unacked_packets_.SetSessionNotifier(session_notifier);
353 }
354
355 QuicTime GetNextReleaseTime() const;
356
357 QuicPacketCount initial_congestion_window() const {
358 return initial_congestion_window_;
359 }
360
361 QuicPacketNumber largest_packet_peer_knows_is_acked() const {
fayang39915f92019-07-11 13:08:40 -0700362 DCHECK(!supports_multiple_packet_number_spaces());
QUICHE teama6ef0a62019-03-07 20:34:33 -0500363 return largest_packet_peer_knows_is_acked_;
364 }
365
366 bool handshake_confirmed() const { return handshake_confirmed_; }
367
368 bool session_decides_what_to_write() const {
369 return unacked_packets_.session_decides_what_to_write();
370 }
371
372 size_t pending_timer_transmission_count() const {
373 return pending_timer_transmission_count_;
374 }
375
fkastenholz59c653b2019-07-15 09:55:53 -0700376 QuicTime::Delta peer_max_ack_delay() const { return peer_max_ack_delay_; }
377
378 void set_peer_max_ack_delay(QuicTime::Delta peer_max_ack_delay) {
ianswett309987e2019-08-02 13:16:26 -0700379 // The delayed ack time should never be more than one half the min RTO time.
380 DCHECK_LE(peer_max_ack_delay, (min_rto_timeout_ * 0.5));
fkastenholz59c653b2019-07-15 09:55:53 -0700381 peer_max_ack_delay_ = peer_max_ack_delay;
QUICHE teama6ef0a62019-03-07 20:34:33 -0500382 }
383
384 const QuicUnackedPacketMap& unacked_packets() const {
385 return unacked_packets_;
386 }
387
388 // Sets the send algorithm to the given congestion control type and points the
389 // pacing sender at |send_algorithm_|. Can be called any number of times.
390 void SetSendAlgorithm(CongestionControlType congestion_control_type);
391
392 // Sets the send algorithm to |send_algorithm| and points the pacing sender at
393 // |send_algorithm_|. Takes ownership of |send_algorithm|. Can be called any
394 // number of times.
395 // Setting the send algorithm once the connection is underway is dangerous.
396 void SetSendAlgorithm(SendAlgorithmInterface* send_algorithm);
397
fayangce0a3162019-08-15 09:05:36 -0700398 // Sends up to max_probe_packets_per_pto_ probe packets.
399 void MaybeSendProbePackets();
400
401 // Called to adjust pending_timer_transmission_count_ accordingly.
402 void AdjustPendingTimerTransmissions();
403
QUICHE teamc279cec2019-03-22 06:51:48 -0700404 bool supports_multiple_packet_number_spaces() const {
405 return unacked_packets_.supports_multiple_packet_number_spaces();
406 }
407
zhongyi1b2f7832019-06-14 13:31:34 -0700408 bool ignore_tlpr_if_no_pending_stream_data() const {
409 return ignore_tlpr_if_no_pending_stream_data_;
410 }
411
fayanga29eb242019-07-16 12:25:38 -0700412 bool fix_rto_retransmission() const { return fix_rto_retransmission_; }
413
fayang62f867a2019-08-22 12:05:01 -0700414 bool pto_enabled() const { return pto_enabled_; }
fayangce0a3162019-08-15 09:05:36 -0700415
QUICHE teama6ef0a62019-03-07 20:34:33 -0500416 private:
417 friend class test::QuicConnectionPeer;
418 friend class test::QuicSentPacketManagerPeer;
419
QUICHE teama6ef0a62019-03-07 20:34:33 -0500420 typedef QuicLinkedHashMap<QuicPacketNumber,
421 TransmissionType,
422 QuicPacketNumberHash>
423 PendingRetransmissionMap;
424
425 // Returns the current retransmission mode.
426 RetransmissionTimeoutMode GetRetransmissionMode() const;
427
428 // Retransmits all crypto stream packets.
429 void RetransmitCryptoPackets();
430
431 // Retransmits two packets for an RTO and removes any non-retransmittable
432 // packets from flight.
433 void RetransmitRtoPackets();
434
435 // Returns the timeout for retransmitting crypto handshake packets.
436 const QuicTime::Delta GetCryptoRetransmissionDelay() const;
437
438 // Returns the timeout for a new tail loss probe. |consecutive_tlp_count| is
439 // the number of consecutive tail loss probes that have already been sent.
440 const QuicTime::Delta GetTailLossProbeDelay(
441 size_t consecutive_tlp_count) const;
442
443 // Calls GetTailLossProbeDelay() with values from the current state of this
444 // packet manager as its params.
445 const QuicTime::Delta GetTailLossProbeDelay() const {
446 return GetTailLossProbeDelay(consecutive_tlp_count_);
447 }
448
449 // Returns the retransmission timeout, after which a full RTO occurs.
450 // |consecutive_rto_count| is the number of consecutive RTOs that have already
451 // occurred.
452 const QuicTime::Delta GetRetransmissionDelay(
453 size_t consecutive_rto_count) const;
454
455 // Calls GetRetransmissionDelay() with values from the current state of this
456 // packet manager as its params.
457 const QuicTime::Delta GetRetransmissionDelay() const {
458 return GetRetransmissionDelay(consecutive_rto_count_);
459 }
460
fayangce0a3162019-08-15 09:05:36 -0700461 // Returns the probe timeout.
462 const QuicTime::Delta GetProbeTimeoutDelay() const;
463
QUICHE teama6ef0a62019-03-07 20:34:33 -0500464 // Returns the newest transmission associated with a packet.
465 QuicPacketNumber GetNewestRetransmission(
466 QuicPacketNumber packet_number,
467 const QuicTransmissionInfo& transmission_info) const;
468
469 // Update the RTT if the ack is for the largest acked packet number.
470 // Returns true if the rtt was updated.
471 bool MaybeUpdateRTT(QuicPacketNumber largest_acked,
472 QuicTime::Delta ack_delay_time,
473 QuicTime ack_receive_time);
474
475 // Invokes the loss detection algorithm and loses and retransmits packets if
476 // necessary.
477 void InvokeLossDetection(QuicTime time);
478
479 // Invokes OnCongestionEvent if |rtt_updated| is true, there are pending acks,
480 // or pending losses. Clears pending acks and pending losses afterwards.
481 // |prior_in_flight| is the number of bytes in flight before the losses or
482 // acks, |event_time| is normally the timestamp of the ack packet which caused
483 // the event, although it can be the time at which loss detection was
484 // triggered.
485 void MaybeInvokeCongestionEvent(bool rtt_updated,
486 QuicByteCount prior_in_flight,
487 QuicTime event_time);
488
489 // Removes the retransmittability and in flight properties from the packet at
490 // |info| due to receipt by the peer.
491 void MarkPacketHandled(QuicPacketNumber packet_number,
492 QuicTransmissionInfo* info,
QUICHE team9467db02019-05-30 09:38:45 -0700493 QuicTime::Delta ack_delay_time,
494 QuicTime receive_timestamp);
QUICHE teama6ef0a62019-03-07 20:34:33 -0500495
496 // Request that |packet_number| be retransmitted after the other pending
497 // retransmissions. Does not add it to the retransmissions if it's already
498 // a pending retransmission.
499 void MarkForRetransmission(QuicPacketNumber packet_number,
500 TransmissionType transmission_type);
501
502 // Performs whatever work is need to retransmit the data correctly, either
503 // by retransmitting the frames directly or by notifying that the frames
504 // are lost.
505 void HandleRetransmission(TransmissionType transmission_type,
506 QuicTransmissionInfo* transmission_info);
507
508 // Called after packets have been marked handled with last received ack frame.
fayangf8e918b2019-07-16 13:03:16 -0700509 void PostProcessNewlyAckedPackets(QuicPacketNumber ack_packet_number,
510 const QuicAckFrame& ack_frame,
fayang3eb82212019-04-16 12:05:46 -0700511 QuicTime ack_receive_time,
512 bool rtt_updated,
513 QuicByteCount prior_bytes_in_flight);
QUICHE teama6ef0a62019-03-07 20:34:33 -0500514
515 // Notify observers that packet with QuicTransmissionInfo |info| is a spurious
516 // retransmission. It is caller's responsibility to guarantee the packet with
517 // QuicTransmissionInfo |info| is a spurious retransmission before calling
518 // this function.
519 void RecordOneSpuriousRetransmission(const QuicTransmissionInfo& info);
520
521 // Notify observers about spurious retransmits of packet with
522 // QuicTransmissionInfo |info|.
523 void RecordSpuriousRetransmissions(const QuicTransmissionInfo& info,
524 QuicPacketNumber acked_packet_number);
525
526 // Sets the initial RTT of the connection.
527 void SetInitialRtt(QuicTime::Delta rtt);
528
wub37ec5962019-04-03 09:02:51 -0700529 // Should only be called from constructor.
530 LossDetectionInterface* GetInitialLossAlgorithm();
531
QUICHE teama6ef0a62019-03-07 20:34:33 -0500532 // Called when handshake is confirmed to remove the retransmittable frames
533 // from all packets of HANDSHAKE_DATA packet number space to ensure they don't
534 // get retransmitted and will eventually be removed from unacked packets map.
fayangbf3d2862019-06-20 14:13:44 -0700535 // Please note, this only applies to QUIC Crypto and needs to be changed when
536 // switches to IETF QUIC with QUIC TLS.
QUICHE teama6ef0a62019-03-07 20:34:33 -0500537 void NeuterHandshakePackets();
538
539 // Newly serialized retransmittable packets are added to this map, which
540 // contains owning pointers to any contained frames. If a packet is
541 // retransmitted, this map will contain entries for both the old and the new
542 // packet. The old packet's retransmittable frames entry will be nullptr,
543 // while the new packet's entry will contain the frames to retransmit.
544 // If the old packet is acked before the new packet, then the old entry will
545 // be removed from the map and the new entry's retransmittable frames will be
546 // set to nullptr.
547 QuicUnackedPacketMap unacked_packets_;
548
549 // Pending retransmissions which have not been packetized and sent yet.
550 PendingRetransmissionMap pending_retransmissions_;
551
552 const QuicClock* clock_;
QUICHE team73957f12019-04-18 16:21:52 -0700553 QuicRandom* random_;
QUICHE teama6ef0a62019-03-07 20:34:33 -0500554 QuicConnectionStats* stats_;
555
556 DebugDelegate* debug_delegate_;
557 NetworkChangeVisitor* network_change_visitor_;
558 QuicPacketCount initial_congestion_window_;
559 RttStats rtt_stats_;
560 std::unique_ptr<SendAlgorithmInterface> send_algorithm_;
561 // Not owned. Always points to |general_loss_algorithm_| outside of tests.
562 LossDetectionInterface* loss_algorithm_;
QUICHE teama6ef0a62019-03-07 20:34:33 -0500563 UberLossAlgorithm uber_loss_algorithm_;
564
565 // Tracks the first RTO packet. If any packet before that packet gets acked,
566 // it indicates the RTO was spurious and should be reversed(F-RTO).
567 QuicPacketNumber first_rto_transmission_;
568 // Number of times the RTO timer has fired in a row without receiving an ack.
569 size_t consecutive_rto_count_;
570 // Number of times the tail loss probe has been sent.
571 size_t consecutive_tlp_count_;
572 // Number of times the crypto handshake has been retransmitted.
573 size_t consecutive_crypto_retransmission_count_;
574 // Number of pending transmissions of TLP, RTO, or crypto packets.
575 size_t pending_timer_transmission_count_;
576 // Maximum number of tail loss probes to send before firing an RTO.
577 size_t max_tail_loss_probes_;
578 // Maximum number of packets to send upon RTO.
579 QuicPacketCount max_rto_packets_;
580 // If true, send the TLP at 0.5 RTT.
581 bool enable_half_rtt_tail_loss_probe_;
582 bool using_pacing_;
583 // If true, use the new RTO with loss based CWND reduction instead of the send
584 // algorithms's OnRetransmissionTimeout to reduce the congestion window.
585 bool use_new_rto_;
586 // If true, use a more conservative handshake retransmission policy.
587 bool conservative_handshake_retransmits_;
588 // The minimum TLP timeout.
589 QuicTime::Delta min_tlp_timeout_;
590 // The minimum RTO.
591 QuicTime::Delta min_rto_timeout_;
592 // Whether to use IETF style TLP that includes the max ack delay.
593 bool ietf_style_tlp_;
594 // IETF style TLP, but with a 2x multiplier instead of 1.5x.
595 bool ietf_style_2x_tlp_;
596
597 // Vectors packets acked and lost as a result of the last congestion event.
598 AckedPacketVector packets_acked_;
599 LostPacketVector packets_lost_;
600 // Largest newly acknowledged packet.
601 QuicPacketNumber largest_newly_acked_;
602 // Largest packet in bytes ever acknowledged.
603 QuicPacketLength largest_mtu_acked_;
604
605 // Replaces certain calls to |send_algorithm_| when |using_pacing_| is true.
606 // Calls into |send_algorithm_| for the underlying congestion control.
607 PacingSender pacing_sender_;
608
609 // Set to true after the crypto handshake has successfully completed. After
610 // this is true we no longer use HANDSHAKE_MODE, and further frames sent on
611 // the crypto stream (i.e. SCUP messages) are treated like normal
612 // retransmittable frames.
613 bool handshake_confirmed_;
614
615 // Records bandwidth from server to client in normal operation, over periods
616 // of time with no loss events.
617 QuicSustainedBandwidthRecorder sustained_bandwidth_recorder_;
618
619 // The largest acked value that was sent in an ack, which has then been acked.
620 QuicPacketNumber largest_packet_peer_knows_is_acked_;
QUICHE teamc279cec2019-03-22 06:51:48 -0700621 // The largest acked value that was sent in an ack, which has then been acked
622 // for per packet number space. Only used when connection supports multiple
623 // packet number spaces.
624 QuicPacketNumber
625 largest_packets_peer_knows_is_acked_[NUM_PACKET_NUMBER_SPACES];
QUICHE teama6ef0a62019-03-07 20:34:33 -0500626
fkastenholz59c653b2019-07-15 09:55:53 -0700627 // The maximum ACK delay time that the peer uses. Initialized to be the
628 // same as local_max_ack_delay_, may be changed via transport parameter
629 // negotiation.
630 QuicTime::Delta peer_max_ack_delay_;
QUICHE teama6ef0a62019-03-07 20:34:33 -0500631
632 // Latest received ack frame.
633 QuicAckFrame last_ack_frame_;
634
635 // Record whether RTT gets updated by last largest acked..
636 bool rtt_updated_;
637
638 // A reverse iterator of last_ack_frame_.packets. This is reset in
639 // OnAckRangeStart, and gradually moves in OnAckRange..
640 PacketNumberQueue::const_reverse_iterator acked_packets_iter_;
QUICHE team9929cc42019-03-13 08:17:43 -0700641
fayang62f867a2019-08-22 12:05:01 -0700642 // Indicates whether PTO mode has been enabled. PTO mode unifies TLP and RTO
643 // modes.
644 bool pto_enabled_;
fayangce0a3162019-08-15 09:05:36 -0700645
646 // Maximum number of probes to send when PTO fires.
647 size_t max_probe_packets_per_pto_;
648
649 // Number of times the PTO timer has fired in a row without receiving an ack.
650 size_t consecutive_pto_count_;
651
ianswett898306b2019-04-23 11:05:57 -0700652 // Latched value of quic_loss_removes_from_inflight.
653 const bool loss_removes_from_inflight_;
zhongyi1b2f7832019-06-14 13:31:34 -0700654
655 // Latched value of quic_ignore_tlpr_if_no_pending_stream_data.
656 const bool ignore_tlpr_if_no_pending_stream_data_;
fayanga29eb242019-07-16 12:25:38 -0700657
fayang67f82272019-08-14 16:08:45 -0700658 // Latched value of quic_fix_rto_retransmission3 and
fayangd3016832019-08-08 07:24:45 -0700659 // session_decides_what_to_write.
660 bool fix_rto_retransmission_;
QUICHE teama6ef0a62019-03-07 20:34:33 -0500661};
662
663} // namespace quic
664
665#endif // QUICHE_QUIC_CORE_QUIC_SENT_PACKET_MANAGER_H_