blob: 352ca314c3434421f30c5ee671213d694ebb5385 [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
fayangd6b31432019-09-18 06:26:59 -0700111 // Grantor makes sure there are enough credits to retransmit a packet. When
112 // grantor is out of scope, remaining credits will be cleared.
113 class QUIC_EXPORT_PRIVATE ScopedCreditGrantor {
114 public:
115 explicit ScopedCreditGrantor(QuicSentPacketManager* manager);
116 ~ScopedCreditGrantor();
117
118 private:
119 QuicSentPacketManager* manager_;
120 // Indicates whether any credit has been granted.
121 bool credits_granted_;
122 };
123
QUICHE teama6ef0a62019-03-07 20:34:33 -0500124 QuicSentPacketManager(Perspective perspective,
125 const QuicClock* clock,
QUICHE team73957f12019-04-18 16:21:52 -0700126 QuicRandom* random,
QUICHE teama6ef0a62019-03-07 20:34:33 -0500127 QuicConnectionStats* stats,
128 CongestionControlType congestion_control_type,
129 LossDetectionType loss_type);
130 QuicSentPacketManager(const QuicSentPacketManager&) = delete;
131 QuicSentPacketManager& operator=(const QuicSentPacketManager&) = delete;
132 virtual ~QuicSentPacketManager();
133
134 virtual void SetFromConfig(const QuicConfig& config);
135
136 // Pass the CachedNetworkParameters to the send algorithm.
137 void ResumeConnectionState(
138 const CachedNetworkParameters& cached_network_params,
139 bool max_bandwidth_resumption);
140
141 void SetMaxPacingRate(QuicBandwidth max_pacing_rate) {
142 pacing_sender_.set_max_pacing_rate(max_pacing_rate);
143 }
144
145 QuicBandwidth MaxPacingRate() const {
146 return pacing_sender_.max_pacing_rate();
147 }
148
149 // Set handshake_confirmed_ to true and neuter packets in HANDSHAKE packet
150 // number space.
151 void SetHandshakeConfirmed();
152
153 // Requests retransmission of all unacked packets of |retransmission_type|.
154 // The behavior of this method depends on the value of |retransmission_type|:
155 // ALL_UNACKED_RETRANSMISSION - All unacked packets will be retransmitted.
156 // This can happen, for example, after a version negotiation packet has been
157 // received and all packets needs to be retransmitted with the new version.
158 // ALL_INITIAL_RETRANSMISSION - Only initially encrypted packets will be
159 // retransmitted. This can happen, for example, when a CHLO has been rejected
160 // and the previously encrypted data needs to be encrypted with a new key.
161 void RetransmitUnackedPackets(TransmissionType retransmission_type);
162
163 // Notify the sent packet manager of an external network measurement or
164 // prediction for either |bandwidth| or |rtt|; either can be empty.
fayangf1b99dc2019-05-14 06:29:18 -0700165 void AdjustNetworkParameters(QuicBandwidth bandwidth,
166 QuicTime::Delta rtt,
167 bool allow_cwnd_to_decrease);
QUICHE teama6ef0a62019-03-07 20:34:33 -0500168
169 // Retransmits the oldest pending packet there is still a tail loss probe
170 // pending. Invoked after OnRetransmissionTimeout.
171 bool MaybeRetransmitTailLossProbe();
172
173 // Retransmits the oldest pending packet.
174 bool MaybeRetransmitOldestPacket(TransmissionType type);
175
176 // Removes the retransmittable frames from all unencrypted packets to ensure
177 // they don't get retransmitted.
fayangbf3d2862019-06-20 14:13:44 -0700178 // TODO(fayang): Consider replace this function with NeuterHandshakePackets.
QUICHE teama6ef0a62019-03-07 20:34:33 -0500179 void NeuterUnencryptedPackets();
180
181 // Returns true if there are pending retransmissions.
182 // Not const because retransmissions may be cancelled before returning.
183 bool HasPendingRetransmissions() const {
184 return !pending_retransmissions_.empty();
185 }
186
187 // Retrieves the next pending retransmission. You must ensure that
188 // there are pending retransmissions prior to calling this function.
189 QuicPendingRetransmission NextPendingRetransmission();
190
191 // Returns true if there's outstanding crypto data.
192 bool HasUnackedCryptoPackets() const {
193 return unacked_packets_.HasPendingCryptoPackets();
194 }
195
196 // Returns true if there are packets in flight expecting to be acknowledged.
197 bool HasInFlightPackets() const {
198 return unacked_packets_.HasInFlightPackets();
199 }
200
201 // Returns the smallest packet number of a serialized packet which has not
202 // been acked by the peer.
203 QuicPacketNumber GetLeastUnacked() const {
204 return unacked_packets_.GetLeastUnacked();
205 }
206
207 // Called when we have sent bytes to the peer. This informs the manager both
208 // the number of bytes sent and if they were retransmitted. Returns true if
209 // the sender should reset the retransmission timer.
210 bool OnPacketSent(SerializedPacket* serialized_packet,
211 QuicPacketNumber original_packet_number,
212 QuicTime sent_time,
213 TransmissionType transmission_type,
214 HasRetransmittableData has_retransmittable_data);
215
fayang67f82272019-08-14 16:08:45 -0700216 // Called when the retransmission timer expires and returns the retransmission
217 // mode.
218 RetransmissionTimeoutMode OnRetransmissionTimeout();
QUICHE teama6ef0a62019-03-07 20:34:33 -0500219
220 // Calculate the time until we can send the next packet to the wire.
221 // Note 1: When kUnknownWaitTime is returned, there is no need to poll
222 // TimeUntilSend again until we receive an OnIncomingAckFrame event.
223 // Note 2: Send algorithms may or may not use |retransmit| in their
224 // calculations.
225 QuicTime::Delta TimeUntilSend(QuicTime now) const;
226
227 // Returns the current delay for the retransmission timer, which may send
228 // either a tail loss probe or do a full RTO. Returns QuicTime::Zero() if
229 // there are no retransmittable packets.
230 const QuicTime GetRetransmissionTime() const;
231
232 // Returns the current delay for the path degrading timer, which is used to
233 // notify the session that this connection is degrading.
234 const QuicTime::Delta GetPathDegradingDelay() const;
235
236 const RttStats* GetRttStats() const { return &rtt_stats_; }
237
238 // Returns the estimated bandwidth calculated by the congestion algorithm.
239 QuicBandwidth BandwidthEstimate() const {
240 return send_algorithm_->BandwidthEstimate();
241 }
242
243 const QuicSustainedBandwidthRecorder* SustainedBandwidthRecorder() const {
244 return &sustained_bandwidth_recorder_;
245 }
246
247 // Returns the size of the current congestion window in number of
248 // kDefaultTCPMSS-sized segments. Note, this is not the *available* window.
249 // Some send algorithms may not use a congestion window and will return 0.
250 QuicPacketCount GetCongestionWindowInTcpMss() const {
251 return send_algorithm_->GetCongestionWindow() / kDefaultTCPMSS;
252 }
253
254 // Returns the number of packets of length |max_packet_length| which fit in
255 // the current congestion window. More packets may end up in flight if the
256 // congestion window has been recently reduced, of if non-full packets are
257 // sent.
258 QuicPacketCount EstimateMaxPacketsInFlight(
259 QuicByteCount max_packet_length) const {
260 return send_algorithm_->GetCongestionWindow() / max_packet_length;
261 }
262
263 // Returns the size of the current congestion window size in bytes.
264 QuicByteCount GetCongestionWindowInBytes() const {
265 return send_algorithm_->GetCongestionWindow();
266 }
267
268 // Returns the size of the slow start congestion window in nume of 1460 byte
269 // TCP segments, aka ssthresh. Some send algorithms do not define a slow
270 // start threshold and will return 0.
271 QuicPacketCount GetSlowStartThresholdInTcpMss() const {
272 return send_algorithm_->GetSlowStartThreshold() / kDefaultTCPMSS;
273 }
274
wub967ba572019-04-01 09:27:52 -0700275 // Return the total time spent in slow start so far. If the sender is
276 // currently in slow start, the return value will include the duration between
277 // the most recent entry to slow start and now.
278 //
279 // Only implemented for BBR. Return QuicTime::Delta::Infinite() for other
280 // congestion controllers.
281 QuicTime::Delta GetSlowStartDuration() const;
282
QUICHE teama6ef0a62019-03-07 20:34:33 -0500283 // Returns debugging information about the state of the congestion controller.
vasilvvc48c8712019-03-11 13:38:16 -0700284 std::string GetDebugState() const;
QUICHE teama6ef0a62019-03-07 20:34:33 -0500285
286 // Returns the number of bytes that are considered in-flight, i.e. not lost or
287 // acknowledged.
288 QuicByteCount GetBytesInFlight() const {
289 return unacked_packets_.bytes_in_flight();
290 }
291
292 // No longer retransmit data for |stream_id|.
293 void CancelRetransmissionsForStream(QuicStreamId stream_id);
294
295 // Called when peer address changes and the connection migrates.
296 void OnConnectionMigration(AddressChangeType type);
297
298 // Called when an ack frame is initially parsed.
299 void OnAckFrameStart(QuicPacketNumber largest_acked,
300 QuicTime::Delta ack_delay_time,
301 QuicTime ack_receive_time);
302
303 // Called when ack range [start, end) is received. Populates packets_acked_
304 // with newly acked packets.
305 void OnAckRange(QuicPacketNumber start, QuicPacketNumber end);
306
307 // Called when a timestamp is processed. If it's present in packets_acked_,
308 // the timestamp field is set. Otherwise, the timestamp is ignored.
309 void OnAckTimestamp(QuicPacketNumber packet_number, QuicTime timestamp);
310
fayang3eb82212019-04-16 12:05:46 -0700311 // Called when an ack frame is parsed completely.
312 AckResult OnAckFrameEnd(QuicTime ack_receive_time,
fayangf8e918b2019-07-16 13:03:16 -0700313 QuicPacketNumber ack_packet_number,
fayang3eb82212019-04-16 12:05:46 -0700314 EncryptionLevel ack_decrypted_level);
QUICHE teama6ef0a62019-03-07 20:34:33 -0500315
316 // Called to enable/disable letting session decide what to write.
fayangd3016832019-08-08 07:24:45 -0700317 void SetSessionDecideWhatToWrite(bool session_decides_what_to_write);
QUICHE teama6ef0a62019-03-07 20:34:33 -0500318
QUICHE teamc279cec2019-03-22 06:51:48 -0700319 void EnableMultiplePacketNumberSpacesSupport();
320
QUICHE teama6ef0a62019-03-07 20:34:33 -0500321 void SetDebugDelegate(DebugDelegate* debug_delegate);
322
323 void SetPacingAlarmGranularity(QuicTime::Delta alarm_granularity) {
324 pacing_sender_.set_alarm_granularity(alarm_granularity);
325 }
326
327 QuicPacketNumber GetLargestObserved() const {
328 return unacked_packets_.largest_acked();
329 }
330
QUICHE teamc279cec2019-03-22 06:51:48 -0700331 QuicPacketNumber GetLargestAckedPacket(
332 EncryptionLevel decrypted_packet_level) const;
333
QUICHE teama6ef0a62019-03-07 20:34:33 -0500334 QuicPacketNumber GetLargestSentPacket() const {
335 return unacked_packets_.largest_sent_packet();
336 }
337
QUICHE teamc279cec2019-03-22 06:51:48 -0700338 QuicPacketNumber GetLargestSentPacket(
339 EncryptionLevel decrypted_packet_level) const;
340
341 QuicPacketNumber GetLargestPacketPeerKnowsIsAcked(
342 EncryptionLevel decrypted_packet_level) const;
343
QUICHE teama6ef0a62019-03-07 20:34:33 -0500344 void SetNetworkChangeVisitor(NetworkChangeVisitor* visitor) {
345 DCHECK(!network_change_visitor_);
346 DCHECK(visitor);
347 network_change_visitor_ = visitor;
348 }
349
350 bool InSlowStart() const { return send_algorithm_->InSlowStart(); }
351
352 size_t GetConsecutiveRtoCount() const { return consecutive_rto_count_; }
353
354 size_t GetConsecutiveTlpCount() const { return consecutive_tlp_count_; }
355
fayangce0a3162019-08-15 09:05:36 -0700356 size_t GetConsecutivePtoCount() const { return consecutive_pto_count_; }
357
QUICHE teama6ef0a62019-03-07 20:34:33 -0500358 void OnApplicationLimited();
359
360 const SendAlgorithmInterface* GetSendAlgorithm() const {
361 return send_algorithm_.get();
362 }
363
364 void SetSessionNotifier(SessionNotifierInterface* session_notifier) {
365 unacked_packets_.SetSessionNotifier(session_notifier);
366 }
367
368 QuicTime GetNextReleaseTime() const;
369
370 QuicPacketCount initial_congestion_window() const {
371 return initial_congestion_window_;
372 }
373
374 QuicPacketNumber largest_packet_peer_knows_is_acked() const {
fayang39915f92019-07-11 13:08:40 -0700375 DCHECK(!supports_multiple_packet_number_spaces());
QUICHE teama6ef0a62019-03-07 20:34:33 -0500376 return largest_packet_peer_knows_is_acked_;
377 }
378
379 bool handshake_confirmed() const { return handshake_confirmed_; }
380
381 bool session_decides_what_to_write() const {
382 return unacked_packets_.session_decides_what_to_write();
383 }
384
385 size_t pending_timer_transmission_count() const {
386 return pending_timer_transmission_count_;
387 }
388
fayangd6b31432019-09-18 06:26:59 -0700389 void set_pending_timer_transmission_count(size_t count) {
390 pending_timer_transmission_count_ = count;
391 }
392
fkastenholz59c653b2019-07-15 09:55:53 -0700393 QuicTime::Delta peer_max_ack_delay() const { return peer_max_ack_delay_; }
394
395 void set_peer_max_ack_delay(QuicTime::Delta peer_max_ack_delay) {
ianswett309987e2019-08-02 13:16:26 -0700396 // The delayed ack time should never be more than one half the min RTO time.
397 DCHECK_LE(peer_max_ack_delay, (min_rto_timeout_ * 0.5));
fkastenholz59c653b2019-07-15 09:55:53 -0700398 peer_max_ack_delay_ = peer_max_ack_delay;
QUICHE teama6ef0a62019-03-07 20:34:33 -0500399 }
400
401 const QuicUnackedPacketMap& unacked_packets() const {
402 return unacked_packets_;
403 }
404
405 // Sets the send algorithm to the given congestion control type and points the
406 // pacing sender at |send_algorithm_|. Can be called any number of times.
407 void SetSendAlgorithm(CongestionControlType congestion_control_type);
408
409 // Sets the send algorithm to |send_algorithm| and points the pacing sender at
410 // |send_algorithm_|. Takes ownership of |send_algorithm|. Can be called any
411 // number of times.
412 // Setting the send algorithm once the connection is underway is dangerous.
413 void SetSendAlgorithm(SendAlgorithmInterface* send_algorithm);
414
fayangce0a3162019-08-15 09:05:36 -0700415 // Sends up to max_probe_packets_per_pto_ probe packets.
416 void MaybeSendProbePackets();
417
418 // Called to adjust pending_timer_transmission_count_ accordingly.
419 void AdjustPendingTimerTransmissions();
420
fayang5f135052019-08-22 17:59:40 -0700421 // Called to disable HANDSHAKE_MODE, and only PTO and LOSS modes are used.
fayang08a6c952019-09-18 14:29:45 -0700422 // Also enable IETF loss detection.
423 void EnableIetfPtoAndLossDetection();
fayang5f135052019-08-22 17:59:40 -0700424
QUICHE teamc279cec2019-03-22 06:51:48 -0700425 bool supports_multiple_packet_number_spaces() const {
426 return unacked_packets_.supports_multiple_packet_number_spaces();
427 }
428
fayanga29eb242019-07-16 12:25:38 -0700429 bool fix_rto_retransmission() const { return fix_rto_retransmission_; }
430
fayang62f867a2019-08-22 12:05:01 -0700431 bool pto_enabled() const { return pto_enabled_; }
fayangce0a3162019-08-15 09:05:36 -0700432
fayang5f135052019-08-22 17:59:40 -0700433 bool handshake_mode_disabled() const { return handshake_mode_disabled_; }
434
QUICHE teama6ef0a62019-03-07 20:34:33 -0500435 private:
436 friend class test::QuicConnectionPeer;
437 friend class test::QuicSentPacketManagerPeer;
438
QUICHE teama6ef0a62019-03-07 20:34:33 -0500439 typedef QuicLinkedHashMap<QuicPacketNumber,
440 TransmissionType,
441 QuicPacketNumberHash>
442 PendingRetransmissionMap;
443
444 // Returns the current retransmission mode.
445 RetransmissionTimeoutMode GetRetransmissionMode() const;
446
447 // Retransmits all crypto stream packets.
448 void RetransmitCryptoPackets();
449
450 // Retransmits two packets for an RTO and removes any non-retransmittable
451 // packets from flight.
452 void RetransmitRtoPackets();
453
454 // Returns the timeout for retransmitting crypto handshake packets.
455 const QuicTime::Delta GetCryptoRetransmissionDelay() const;
456
457 // Returns the timeout for a new tail loss probe. |consecutive_tlp_count| is
458 // the number of consecutive tail loss probes that have already been sent.
459 const QuicTime::Delta GetTailLossProbeDelay(
460 size_t consecutive_tlp_count) const;
461
462 // Calls GetTailLossProbeDelay() with values from the current state of this
463 // packet manager as its params.
464 const QuicTime::Delta GetTailLossProbeDelay() const {
465 return GetTailLossProbeDelay(consecutive_tlp_count_);
466 }
467
468 // Returns the retransmission timeout, after which a full RTO occurs.
469 // |consecutive_rto_count| is the number of consecutive RTOs that have already
470 // occurred.
471 const QuicTime::Delta GetRetransmissionDelay(
472 size_t consecutive_rto_count) const;
473
474 // Calls GetRetransmissionDelay() with values from the current state of this
475 // packet manager as its params.
476 const QuicTime::Delta GetRetransmissionDelay() const {
477 return GetRetransmissionDelay(consecutive_rto_count_);
478 }
479
fayangce0a3162019-08-15 09:05:36 -0700480 // Returns the probe timeout.
481 const QuicTime::Delta GetProbeTimeoutDelay() const;
482
QUICHE teama6ef0a62019-03-07 20:34:33 -0500483 // Returns the newest transmission associated with a packet.
484 QuicPacketNumber GetNewestRetransmission(
485 QuicPacketNumber packet_number,
486 const QuicTransmissionInfo& transmission_info) const;
487
488 // Update the RTT if the ack is for the largest acked packet number.
489 // Returns true if the rtt was updated.
490 bool MaybeUpdateRTT(QuicPacketNumber largest_acked,
491 QuicTime::Delta ack_delay_time,
492 QuicTime ack_receive_time);
493
494 // Invokes the loss detection algorithm and loses and retransmits packets if
495 // necessary.
496 void InvokeLossDetection(QuicTime time);
497
498 // Invokes OnCongestionEvent if |rtt_updated| is true, there are pending acks,
499 // or pending losses. Clears pending acks and pending losses afterwards.
500 // |prior_in_flight| is the number of bytes in flight before the losses or
501 // acks, |event_time| is normally the timestamp of the ack packet which caused
502 // the event, although it can be the time at which loss detection was
503 // triggered.
504 void MaybeInvokeCongestionEvent(bool rtt_updated,
505 QuicByteCount prior_in_flight,
506 QuicTime event_time);
507
508 // Removes the retransmittability and in flight properties from the packet at
509 // |info| due to receipt by the peer.
510 void MarkPacketHandled(QuicPacketNumber packet_number,
511 QuicTransmissionInfo* info,
fayang19d2d5b2019-09-11 14:22:03 -0700512 QuicTime ack_receive_time,
QUICHE team9467db02019-05-30 09:38:45 -0700513 QuicTime::Delta ack_delay_time,
514 QuicTime receive_timestamp);
QUICHE teama6ef0a62019-03-07 20:34:33 -0500515
516 // Request that |packet_number| be retransmitted after the other pending
517 // retransmissions. Does not add it to the retransmissions if it's already
518 // a pending retransmission.
519 void MarkForRetransmission(QuicPacketNumber packet_number,
520 TransmissionType transmission_type);
521
522 // Performs whatever work is need to retransmit the data correctly, either
523 // by retransmitting the frames directly or by notifying that the frames
524 // are lost.
525 void HandleRetransmission(TransmissionType transmission_type,
526 QuicTransmissionInfo* transmission_info);
527
528 // Called after packets have been marked handled with last received ack frame.
fayangf8e918b2019-07-16 13:03:16 -0700529 void PostProcessNewlyAckedPackets(QuicPacketNumber ack_packet_number,
530 const QuicAckFrame& ack_frame,
fayang3eb82212019-04-16 12:05:46 -0700531 QuicTime ack_receive_time,
532 bool rtt_updated,
533 QuicByteCount prior_bytes_in_flight);
QUICHE teama6ef0a62019-03-07 20:34:33 -0500534
535 // Notify observers that packet with QuicTransmissionInfo |info| is a spurious
536 // retransmission. It is caller's responsibility to guarantee the packet with
537 // QuicTransmissionInfo |info| is a spurious retransmission before calling
538 // this function.
539 void RecordOneSpuriousRetransmission(const QuicTransmissionInfo& info);
540
541 // Notify observers about spurious retransmits of packet with
542 // QuicTransmissionInfo |info|.
543 void RecordSpuriousRetransmissions(const QuicTransmissionInfo& info,
544 QuicPacketNumber acked_packet_number);
545
546 // Sets the initial RTT of the connection.
547 void SetInitialRtt(QuicTime::Delta rtt);
548
wub37ec5962019-04-03 09:02:51 -0700549 // Should only be called from constructor.
550 LossDetectionInterface* GetInitialLossAlgorithm();
551
QUICHE teama6ef0a62019-03-07 20:34:33 -0500552 // Called when handshake is confirmed to remove the retransmittable frames
553 // from all packets of HANDSHAKE_DATA packet number space to ensure they don't
554 // get retransmitted and will eventually be removed from unacked packets map.
fayangbf3d2862019-06-20 14:13:44 -0700555 // Please note, this only applies to QUIC Crypto and needs to be changed when
556 // switches to IETF QUIC with QUIC TLS.
QUICHE teama6ef0a62019-03-07 20:34:33 -0500557 void NeuterHandshakePackets();
558
559 // Newly serialized retransmittable packets are added to this map, which
560 // contains owning pointers to any contained frames. If a packet is
561 // retransmitted, this map will contain entries for both the old and the new
562 // packet. The old packet's retransmittable frames entry will be nullptr,
563 // while the new packet's entry will contain the frames to retransmit.
564 // If the old packet is acked before the new packet, then the old entry will
565 // be removed from the map and the new entry's retransmittable frames will be
566 // set to nullptr.
567 QuicUnackedPacketMap unacked_packets_;
568
569 // Pending retransmissions which have not been packetized and sent yet.
570 PendingRetransmissionMap pending_retransmissions_;
571
572 const QuicClock* clock_;
QUICHE team73957f12019-04-18 16:21:52 -0700573 QuicRandom* random_;
QUICHE teama6ef0a62019-03-07 20:34:33 -0500574 QuicConnectionStats* stats_;
575
576 DebugDelegate* debug_delegate_;
577 NetworkChangeVisitor* network_change_visitor_;
578 QuicPacketCount initial_congestion_window_;
579 RttStats rtt_stats_;
580 std::unique_ptr<SendAlgorithmInterface> send_algorithm_;
581 // Not owned. Always points to |general_loss_algorithm_| outside of tests.
582 LossDetectionInterface* loss_algorithm_;
QUICHE teama6ef0a62019-03-07 20:34:33 -0500583 UberLossAlgorithm uber_loss_algorithm_;
584
585 // Tracks the first RTO packet. If any packet before that packet gets acked,
586 // it indicates the RTO was spurious and should be reversed(F-RTO).
587 QuicPacketNumber first_rto_transmission_;
588 // Number of times the RTO timer has fired in a row without receiving an ack.
589 size_t consecutive_rto_count_;
590 // Number of times the tail loss probe has been sent.
591 size_t consecutive_tlp_count_;
592 // Number of times the crypto handshake has been retransmitted.
593 size_t consecutive_crypto_retransmission_count_;
594 // Number of pending transmissions of TLP, RTO, or crypto packets.
595 size_t pending_timer_transmission_count_;
596 // Maximum number of tail loss probes to send before firing an RTO.
597 size_t max_tail_loss_probes_;
598 // Maximum number of packets to send upon RTO.
599 QuicPacketCount max_rto_packets_;
600 // If true, send the TLP at 0.5 RTT.
601 bool enable_half_rtt_tail_loss_probe_;
602 bool using_pacing_;
603 // If true, use the new RTO with loss based CWND reduction instead of the send
604 // algorithms's OnRetransmissionTimeout to reduce the congestion window.
605 bool use_new_rto_;
606 // If true, use a more conservative handshake retransmission policy.
607 bool conservative_handshake_retransmits_;
608 // The minimum TLP timeout.
609 QuicTime::Delta min_tlp_timeout_;
610 // The minimum RTO.
611 QuicTime::Delta min_rto_timeout_;
612 // Whether to use IETF style TLP that includes the max ack delay.
613 bool ietf_style_tlp_;
614 // IETF style TLP, but with a 2x multiplier instead of 1.5x.
615 bool ietf_style_2x_tlp_;
616
617 // Vectors packets acked and lost as a result of the last congestion event.
618 AckedPacketVector packets_acked_;
619 LostPacketVector packets_lost_;
620 // Largest newly acknowledged packet.
621 QuicPacketNumber largest_newly_acked_;
622 // Largest packet in bytes ever acknowledged.
623 QuicPacketLength largest_mtu_acked_;
624
625 // Replaces certain calls to |send_algorithm_| when |using_pacing_| is true.
626 // Calls into |send_algorithm_| for the underlying congestion control.
627 PacingSender pacing_sender_;
628
629 // Set to true after the crypto handshake has successfully completed. After
630 // this is true we no longer use HANDSHAKE_MODE, and further frames sent on
631 // the crypto stream (i.e. SCUP messages) are treated like normal
632 // retransmittable frames.
633 bool handshake_confirmed_;
634
635 // Records bandwidth from server to client in normal operation, over periods
636 // of time with no loss events.
637 QuicSustainedBandwidthRecorder sustained_bandwidth_recorder_;
638
639 // The largest acked value that was sent in an ack, which has then been acked.
640 QuicPacketNumber largest_packet_peer_knows_is_acked_;
QUICHE teamc279cec2019-03-22 06:51:48 -0700641 // The largest acked value that was sent in an ack, which has then been acked
642 // for per packet number space. Only used when connection supports multiple
643 // packet number spaces.
644 QuicPacketNumber
645 largest_packets_peer_knows_is_acked_[NUM_PACKET_NUMBER_SPACES];
QUICHE teama6ef0a62019-03-07 20:34:33 -0500646
fkastenholz59c653b2019-07-15 09:55:53 -0700647 // The maximum ACK delay time that the peer uses. Initialized to be the
648 // same as local_max_ack_delay_, may be changed via transport parameter
649 // negotiation.
650 QuicTime::Delta peer_max_ack_delay_;
QUICHE teama6ef0a62019-03-07 20:34:33 -0500651
652 // Latest received ack frame.
653 QuicAckFrame last_ack_frame_;
654
655 // Record whether RTT gets updated by last largest acked..
656 bool rtt_updated_;
657
658 // A reverse iterator of last_ack_frame_.packets. This is reset in
659 // OnAckRangeStart, and gradually moves in OnAckRange..
660 PacketNumberQueue::const_reverse_iterator acked_packets_iter_;
QUICHE team9929cc42019-03-13 08:17:43 -0700661
fayang62f867a2019-08-22 12:05:01 -0700662 // Indicates whether PTO mode has been enabled. PTO mode unifies TLP and RTO
663 // modes.
664 bool pto_enabled_;
fayangce0a3162019-08-15 09:05:36 -0700665
666 // Maximum number of probes to send when PTO fires.
667 size_t max_probe_packets_per_pto_;
668
669 // Number of times the PTO timer has fired in a row without receiving an ack.
670 size_t consecutive_pto_count_;
671
fayang67f82272019-08-14 16:08:45 -0700672 // Latched value of quic_fix_rto_retransmission3 and
fayangd3016832019-08-08 07:24:45 -0700673 // session_decides_what_to_write.
674 bool fix_rto_retransmission_;
fayang5f135052019-08-22 17:59:40 -0700675
676 // True if HANDSHAKE mode has been disabled.
677 bool handshake_mode_disabled_;
fayang19d2d5b2019-09-11 14:22:03 -0700678
679 // Latched value of quic_detect_spurious_loss.
680 const bool detect_spurious_losses_;
QUICHE teama6ef0a62019-03-07 20:34:33 -0500681};
682
683} // namespace quic
684
685#endif // QUICHE_QUIC_CORE_QUIC_SENT_PACKET_MANAGER_H_