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