QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 1 | // Copyright 2013 The Chromium Authors. All rights reserved. |
| 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
| 5 | #ifndef QUICHE_QUIC_CORE_QUIC_RECEIVED_PACKET_MANAGER_H_ |
| 6 | #define QUICHE_QUIC_CORE_QUIC_RECEIVED_PACKET_MANAGER_H_ |
| 7 | |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 8 | #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 | |
| 13 | namespace quic { |
| 14 | |
| 15 | class RttStats; |
| 16 | |
| 17 | namespace test { |
| 18 | class QuicConnectionPeer; |
| 19 | class QuicReceivedPacketManagerPeer; |
QUICHE team | b23daa7 | 2019-03-21 08:37:48 -0700 | [diff] [blame] | 20 | class UberReceivedPacketManagerPeer; |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 21 | } // namespace test |
| 22 | |
| 23 | struct QuicConnectionStats; |
| 24 | |
| 25 | // Records all received packets by a connection. |
| 26 | class QUIC_EXPORT_PRIVATE QuicReceivedPacketManager { |
| 27 | public: |
QUICHE team | 1dfa46b | 2019-03-22 10:39:10 -0700 | [diff] [blame] | 28 | QuicReceivedPacketManager(); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 29 | 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 team | b23daa7 | 2019-03-21 08:37:48 -0700 | [diff] [blame] | 47 | virtual bool IsAwaitingPacket(QuicPacketNumber packet_number) const; |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 48 | |
| 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, |
| 67 | const RttStats* rtt_stats, |
| 68 | QuicTime::Delta delayed_ack_time); |
| 69 | |
| 70 | // Resets ACK related states, called after an ACK is successfully sent. |
| 71 | void ResetAckStates(); |
| 72 | |
| 73 | // Returns true if there are any missing packets. |
| 74 | bool HasMissingPackets() const; |
| 75 | |
| 76 | // Returns true when there are new missing packets to be reported within 3 |
| 77 | // packets of the largest observed. |
| 78 | virtual bool HasNewMissingPackets() const; |
| 79 | |
QUICHE team | b23daa7 | 2019-03-21 08:37:48 -0700 | [diff] [blame] | 80 | QuicPacketNumber peer_least_packet_awaiting_ack() const { |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 81 | return peer_least_packet_awaiting_ack_; |
| 82 | } |
| 83 | |
| 84 | virtual bool ack_frame_updated() const; |
| 85 | |
| 86 | QuicPacketNumber GetLargestObserved() const; |
| 87 | |
| 88 | // Returns peer first sending packet number to our best knowledge. If |
| 89 | // GetQuicRestartFlag(quic_enable_accept_random_ipn) is false, returns 1. |
| 90 | // Otherwise considers least_received_packet_number_ as peer first sending |
| 91 | // packet number. Please note, this function should only be called when at |
| 92 | // least one packet has been received. |
| 93 | QuicPacketNumber PeerFirstSendingPacketNumber() const; |
| 94 | |
QUICHE team | 1dfa46b | 2019-03-22 10:39:10 -0700 | [diff] [blame] | 95 | void set_connection_stats(QuicConnectionStats* stats) { stats_ = stats; } |
| 96 | |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 97 | // For logging purposes. |
| 98 | const QuicAckFrame& ack_frame() const { return ack_frame_; } |
| 99 | |
| 100 | void set_max_ack_ranges(size_t max_ack_ranges) { |
| 101 | max_ack_ranges_ = max_ack_ranges; |
| 102 | } |
| 103 | |
| 104 | void set_save_timestamps(bool save_timestamps) { |
| 105 | save_timestamps_ = save_timestamps; |
| 106 | } |
| 107 | |
| 108 | size_t min_received_before_ack_decimation() const { |
| 109 | return min_received_before_ack_decimation_; |
| 110 | } |
| 111 | void set_min_received_before_ack_decimation(size_t new_value) { |
| 112 | min_received_before_ack_decimation_ = new_value; |
| 113 | } |
| 114 | |
| 115 | size_t ack_frequency_before_ack_decimation() const { |
| 116 | return ack_frequency_before_ack_decimation_; |
| 117 | } |
| 118 | void set_ack_frequency_before_ack_decimation(size_t new_value) { |
| 119 | DCHECK_GT(new_value, 0u); |
| 120 | ack_frequency_before_ack_decimation_ = new_value; |
| 121 | } |
| 122 | |
| 123 | QuicTime ack_timeout() const { return ack_timeout_; } |
| 124 | |
| 125 | bool decide_when_to_send_acks() const { return decide_when_to_send_acks_; } |
| 126 | |
| 127 | private: |
| 128 | friend class test::QuicConnectionPeer; |
| 129 | friend class test::QuicReceivedPacketManagerPeer; |
QUICHE team | b23daa7 | 2019-03-21 08:37:48 -0700 | [diff] [blame] | 130 | friend class test::UberReceivedPacketManagerPeer; |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 131 | |
| 132 | // Sets ack_timeout_ to |time| if ack_timeout_ is not initialized or > time. |
| 133 | void MaybeUpdateAckTimeoutTo(QuicTime time); |
| 134 | |
| 135 | // Least packet number of the the packet sent by the peer for which it |
| 136 | // hasn't received an ack. |
| 137 | QuicPacketNumber peer_least_packet_awaiting_ack_; |
| 138 | |
| 139 | // Received packet information used to produce acks. |
| 140 | QuicAckFrame ack_frame_; |
| 141 | |
| 142 | // True if |ack_frame_| has been updated since UpdateReceivedPacketInfo was |
| 143 | // last called. |
| 144 | bool ack_frame_updated_; |
| 145 | |
| 146 | // Maximum number of ack ranges allowed to be stored in the ack frame. |
| 147 | size_t max_ack_ranges_; |
| 148 | |
| 149 | // The time we received the largest_observed packet number, or zero if |
| 150 | // no packet numbers have been received since UpdateReceivedPacketInfo. |
| 151 | // Needed for calculating ack_delay_time. |
| 152 | QuicTime time_largest_observed_; |
| 153 | |
| 154 | // If true, save timestamps in the ack_frame_. |
| 155 | bool save_timestamps_; |
| 156 | |
| 157 | // Least packet number received from peer. |
| 158 | QuicPacketNumber least_received_packet_number_; |
| 159 | |
| 160 | QuicConnectionStats* stats_; |
| 161 | |
| 162 | AckMode ack_mode_; |
| 163 | // How many retransmittable packets have arrived without sending an ack. |
| 164 | QuicPacketCount num_retransmittable_packets_received_since_last_ack_sent_; |
| 165 | // Ack decimation will start happening after this many packets are received. |
| 166 | size_t min_received_before_ack_decimation_; |
| 167 | // Before ack decimation starts (if enabled), we ack every n-th packet. |
| 168 | size_t ack_frequency_before_ack_decimation_; |
| 169 | // The max delay in fraction of min_rtt to use when sending decimated acks. |
| 170 | float ack_decimation_delay_; |
| 171 | // When true, removes ack decimation's max number of packets(10) before |
| 172 | // sending an ack. |
| 173 | bool unlimited_ack_decimation_; |
| 174 | // When true, use a 1ms delayed ack timer if it's been an SRTT since a packet |
| 175 | // was received. |
| 176 | bool fast_ack_after_quiescence_; |
| 177 | |
| 178 | // Time that an ACK needs to be sent. 0 means no ACK is pending. Used when |
| 179 | // decide_when_to_send_acks_ is true. |
| 180 | QuicTime ack_timeout_; |
| 181 | |
| 182 | // The time the previous ack-instigating packet was received and processed. |
| 183 | QuicTime time_of_previous_received_packet_; |
| 184 | // Whether the most recent packet was missing before it was received. |
| 185 | bool was_last_packet_missing_; |
| 186 | |
| 187 | // Last sent largest acked, which gets updated when ACK was successfully sent. |
| 188 | QuicPacketNumber last_sent_largest_acked_; |
| 189 | |
| 190 | // Latched value of quic_deprecate_ack_bundling_mode and |
| 191 | // quic_rpm_decides_when_to_send_acks. |
| 192 | const bool decide_when_to_send_acks_; |
| 193 | }; |
| 194 | |
| 195 | } // namespace quic |
| 196 | |
| 197 | #endif // QUICHE_QUIC_CORE_QUIC_RECEIVED_PACKET_MANAGER_H_ |