blob: b01390d1d590692bc04a981c7862a1b6b2a47d23 [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_RECEIVED_PACKET_MANAGER_H_
6#define QUICHE_QUIC_CORE_QUIC_RECEIVED_PACKET_MANAGER_H_
7
QUICHE teama6ef0a62019-03-07 20:34:33 -05008#include "net/third_party/quiche/src/quic/core/quic_config.h"
9#include "net/third_party/quiche/src/quic/core/quic_framer.h"
10#include "net/third_party/quiche/src/quic/core/quic_packets.h"
11#include "net/third_party/quiche/src/quic/platform/api/quic_export.h"
12
13namespace quic {
14
15class RttStats;
16
17namespace test {
18class QuicConnectionPeer;
19class QuicReceivedPacketManagerPeer;
QUICHE teamb23daa72019-03-21 08:37:48 -070020class UberReceivedPacketManagerPeer;
QUICHE teama6ef0a62019-03-07 20:34:33 -050021} // namespace test
22
23struct QuicConnectionStats;
24
25// Records all received packets by a connection.
26class QUIC_EXPORT_PRIVATE QuicReceivedPacketManager {
27 public:
QUICHE team1dfa46b2019-03-22 10:39:10 -070028 QuicReceivedPacketManager();
QUICHE teama6ef0a62019-03-07 20:34:33 -050029 explicit QuicReceivedPacketManager(QuicConnectionStats* stats);
30 QuicReceivedPacketManager(const QuicReceivedPacketManager&) = delete;
31 QuicReceivedPacketManager& operator=(const QuicReceivedPacketManager&) =
32 delete;
33 virtual ~QuicReceivedPacketManager();
34
35 void SetFromConfig(const QuicConfig& config, Perspective perspective);
36
37 // Updates the internal state concerning which packets have been received.
38 // header: the packet header.
39 // timestamp: the arrival time of the packet.
40 virtual void RecordPacketReceived(const QuicPacketHeader& header,
41 QuicTime receipt_time);
42
43 // Checks whether |packet_number| is missing and less than largest observed.
44 virtual bool IsMissing(QuicPacketNumber packet_number);
45
46 // Checks if we're still waiting for the packet with |packet_number|.
QUICHE teamb23daa72019-03-21 08:37:48 -070047 virtual bool IsAwaitingPacket(QuicPacketNumber packet_number) const;
QUICHE teama6ef0a62019-03-07 20:34:33 -050048
49 // Retrieves a frame containing a QuicAckFrame. The ack frame may not be
50 // changed outside QuicReceivedPacketManager and must be serialized before
51 // another packet is received, or it will change.
52 const QuicFrame GetUpdatedAckFrame(QuicTime approximate_now);
53
54 // Deletes all missing packets before least unacked. The connection won't
55 // process any packets with packet number before |least_unacked| that it
56 // received after this call.
57 void DontWaitForPacketsBefore(QuicPacketNumber least_unacked);
58
59 // Called to update ack_timeout_ to the time when an ACK needs to be sent. A
60 // caller can decide whether and when to send an ACK by retrieving
61 // ack_timeout_. If ack_timeout_ is not initialized, no ACK needs to be sent.
62 // Otherwise, ACK needs to be sent by the specified time.
63 void MaybeUpdateAckTimeout(bool should_last_packet_instigate_acks,
64 QuicPacketNumber last_received_packet_number,
65 QuicTime time_of_last_received_packet,
66 QuicTime now,
ianswett309987e2019-08-02 13:16:26 -070067 const RttStats* rtt_stats);
QUICHE teama6ef0a62019-03-07 20:34:33 -050068
69 // Resets ACK related states, called after an ACK is successfully sent.
70 void ResetAckStates();
71
72 // Returns true if there are any missing packets.
73 bool HasMissingPackets() const;
74
75 // Returns true when there are new missing packets to be reported within 3
76 // packets of the largest observed.
77 virtual bool HasNewMissingPackets() const;
78
QUICHE teamb23daa72019-03-21 08:37:48 -070079 QuicPacketNumber peer_least_packet_awaiting_ack() const {
QUICHE teama6ef0a62019-03-07 20:34:33 -050080 return peer_least_packet_awaiting_ack_;
81 }
82
83 virtual bool ack_frame_updated() const;
84
85 QuicPacketNumber GetLargestObserved() const;
86
fayang6dba4902019-06-17 10:04:23 -070087 // Returns peer first sending packet number to our best knowledge. Considers
88 // least_received_packet_number_ as peer first sending packet number. Please
89 // note, this function should only be called when at least one packet has been
90 // received.
QUICHE teama6ef0a62019-03-07 20:34:33 -050091 QuicPacketNumber PeerFirstSendingPacketNumber() const;
92
fayang5d92c412020-02-19 12:10:31 -080093 // Returns true if ack frame is empty.
94 bool IsAckFrameEmpty() const;
95
QUICHE team1dfa46b2019-03-22 10:39:10 -070096 void set_connection_stats(QuicConnectionStats* stats) { stats_ = stats; }
97
QUICHE teama6ef0a62019-03-07 20:34:33 -050098 // For logging purposes.
99 const QuicAckFrame& ack_frame() const { return ack_frame_; }
100
101 void set_max_ack_ranges(size_t max_ack_ranges) {
102 max_ack_ranges_ = max_ack_ranges;
103 }
104
105 void set_save_timestamps(bool save_timestamps) {
106 save_timestamps_ = save_timestamps;
107 }
108
109 size_t min_received_before_ack_decimation() const {
110 return min_received_before_ack_decimation_;
111 }
112 void set_min_received_before_ack_decimation(size_t new_value) {
113 min_received_before_ack_decimation_ = new_value;
114 }
115
116 size_t ack_frequency_before_ack_decimation() const {
117 return ack_frequency_before_ack_decimation_;
118 }
119 void set_ack_frequency_before_ack_decimation(size_t new_value) {
120 DCHECK_GT(new_value, 0u);
121 ack_frequency_before_ack_decimation_ = new_value;
122 }
123
ianswett309987e2019-08-02 13:16:26 -0700124 QuicTime::Delta local_max_ack_delay() const { return local_max_ack_delay_; }
125 void set_local_max_ack_delay(QuicTime::Delta local_max_ack_delay) {
126 local_max_ack_delay_ = local_max_ack_delay;
127 }
128
QUICHE teama6ef0a62019-03-07 20:34:33 -0500129 QuicTime ack_timeout() const { return ack_timeout_; }
130
QUICHE teama6ef0a62019-03-07 20:34:33 -0500131 private:
132 friend class test::QuicConnectionPeer;
133 friend class test::QuicReceivedPacketManagerPeer;
QUICHE teamb23daa72019-03-21 08:37:48 -0700134 friend class test::UberReceivedPacketManagerPeer;
QUICHE teama6ef0a62019-03-07 20:34:33 -0500135
136 // Sets ack_timeout_ to |time| if ack_timeout_ is not initialized or > time.
137 void MaybeUpdateAckTimeoutTo(QuicTime time);
138
139 // Least packet number of the the packet sent by the peer for which it
140 // hasn't received an ack.
141 QuicPacketNumber peer_least_packet_awaiting_ack_;
142
143 // Received packet information used to produce acks.
144 QuicAckFrame ack_frame_;
145
146 // True if |ack_frame_| has been updated since UpdateReceivedPacketInfo was
147 // last called.
148 bool ack_frame_updated_;
149
150 // Maximum number of ack ranges allowed to be stored in the ack frame.
151 size_t max_ack_ranges_;
152
153 // The time we received the largest_observed packet number, or zero if
154 // no packet numbers have been received since UpdateReceivedPacketInfo.
155 // Needed for calculating ack_delay_time.
156 QuicTime time_largest_observed_;
157
158 // If true, save timestamps in the ack_frame_.
159 bool save_timestamps_;
160
161 // Least packet number received from peer.
162 QuicPacketNumber least_received_packet_number_;
163
164 QuicConnectionStats* stats_;
165
166 AckMode ack_mode_;
167 // How many retransmittable packets have arrived without sending an ack.
168 QuicPacketCount num_retransmittable_packets_received_since_last_ack_sent_;
169 // Ack decimation will start happening after this many packets are received.
170 size_t min_received_before_ack_decimation_;
171 // Before ack decimation starts (if enabled), we ack every n-th packet.
172 size_t ack_frequency_before_ack_decimation_;
173 // The max delay in fraction of min_rtt to use when sending decimated acks.
174 float ack_decimation_delay_;
175 // When true, removes ack decimation's max number of packets(10) before
176 // sending an ack.
177 bool unlimited_ack_decimation_;
178 // When true, use a 1ms delayed ack timer if it's been an SRTT since a packet
179 // was received.
180 bool fast_ack_after_quiescence_;
ianswett95cf3832020-01-21 07:58:25 -0800181 // When true, only send 1 immediate ACK when reordering is detected.
182 bool one_immediate_ack_;
QUICHE teama6ef0a62019-03-07 20:34:33 -0500183
ianswett309987e2019-08-02 13:16:26 -0700184 // The local node's maximum ack delay time. This is the maximum amount of
185 // time to wait before sending an acknowledgement.
186 QuicTime::Delta local_max_ack_delay_;
QUICHE teama6ef0a62019-03-07 20:34:33 -0500187 // Time that an ACK needs to be sent. 0 means no ACK is pending. Used when
188 // decide_when_to_send_acks_ is true.
189 QuicTime ack_timeout_;
190
191 // The time the previous ack-instigating packet was received and processed.
192 QuicTime time_of_previous_received_packet_;
193 // Whether the most recent packet was missing before it was received.
194 bool was_last_packet_missing_;
195
196 // Last sent largest acked, which gets updated when ACK was successfully sent.
197 QuicPacketNumber last_sent_largest_acked_;
QUICHE teama6ef0a62019-03-07 20:34:33 -0500198};
199
200} // namespace quic
201
202#endif // QUICHE_QUIC_CORE_QUIC_RECEIVED_PACKET_MANAGER_H_