Switch global error menu icon to vectorized MD asset
[chromium-blink-merge.git] / net / quic / quic_unacked_packet_map.h
blob1926d31249d6ce6aafb37d37626213e9f59a167e
1 // Copyright 2014 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.
5 #ifndef NET_QUIC_QUIC_UNACKED_PACKET_MAP_H_
6 #define NET_QUIC_QUIC_UNACKED_PACKET_MAP_H_
8 #include <deque>
10 #include "net/quic/quic_protocol.h"
12 namespace net {
14 class AckNotifierManager;
16 // Class which tracks unacked packets for three purposes:
17 // 1) Track retransmittable data, including multiple transmissions of frames.
18 // 2) Track packets and bytes in flight for congestion control.
19 // 3) Track sent time of packets to provide RTT measurements from acks.
20 class NET_EXPORT_PRIVATE QuicUnackedPacketMap {
21 public:
22 // Initialize an instance of UnackedPacketMap. The AckNotifierManager
23 // provided to the constructor will be notified whenever a packet is removed
24 // from the map.
25 explicit QuicUnackedPacketMap(AckNotifierManager* ack_notifier_manager);
26 ~QuicUnackedPacketMap();
28 // Adds |serialized_packet| to the map and marks it as sent at |sent_time|.
29 // Marks the packet as in flight if |set_in_flight| is true.
30 // Packets marked as in flight are expected to be marked as missing when they
31 // don't arrive, indicating the need for retransmission.
32 // |old_packet_number| is the packet number of the previous transmission,
33 // or 0 if there was none.
34 void AddSentPacket(const SerializedPacket& serialized_packet,
35 QuicPacketNumber old_packet_number,
36 TransmissionType transmission_type,
37 QuicTime sent_time,
38 QuicByteCount bytes_sent,
39 bool set_in_flight);
41 // Returns true if the packet |packet_number| is unacked.
42 bool IsUnacked(QuicPacketNumber packet_number) const;
44 // Sets the nack count to the max of the current nack count and |min_nacks|.
45 void NackPacket(QuicPacketNumber packet_number, QuicPacketCount min_nacks);
47 // Marks |packet_number| as no longer in flight.
48 void RemoveFromInFlight(QuicPacketNumber packet_number);
50 // No longer retransmit data for |stream_id|.
51 void CancelRetransmissionsForStream(QuicStreamId stream_id);
53 // Returns true if the unacked packet |packet_number| has retransmittable
54 // frames. This will return false if the packet has been acked, if a
55 // previous transmission of this packet was ACK'd, or if this packet has been
56 // retransmitted as with different packet number, or if the packet never
57 // had any retransmittable packets in the first place.
58 bool HasRetransmittableFrames(QuicPacketNumber packet_number) const;
60 // Returns true if there are any unacked packets.
61 bool HasUnackedPackets() const;
63 // Returns true if there are any unacked packets which have retransmittable
64 // frames.
65 bool HasUnackedRetransmittableFrames() const;
67 // Returns the largest packet number that has been sent.
68 QuicPacketNumber largest_sent_packet() const { return largest_sent_packet_; }
70 // Returns the largest packet number that has been acked.
71 QuicPacketNumber largest_observed() const { return largest_observed_; }
73 // Returns the sum of bytes from all packets in flight.
74 QuicByteCount bytes_in_flight() const {
75 return bytes_in_flight_;
78 // Returns the smallest packet number of a serialized packet which has not
79 // been acked by the peer. If there are no unacked packets, returns 0.
80 QuicPacketNumber GetLeastUnacked() const;
82 // Clears all previous transmissions in order to make room in the ack frame
83 // for newly acked packets.
84 void ClearAllPreviousRetransmissions();
86 typedef std::deque<TransmissionInfo> UnackedPacketMap;
88 typedef UnackedPacketMap::const_iterator const_iterator;
90 const_iterator begin() const { return unacked_packets_.begin(); }
91 const_iterator end() const { return unacked_packets_.end(); }
93 // Returns true if there are unacked packets that are in flight.
94 bool HasInFlightPackets() const;
96 // Returns the TransmissionInfo associated with |packet_number|, which
97 // must be unacked.
98 const TransmissionInfo& GetTransmissionInfo(
99 QuicPacketNumber packet_number) const;
101 // Returns the time that the last unacked packet was sent.
102 QuicTime GetLastPacketSentTime() const;
104 // Returns the number of unacked packets.
105 size_t GetNumUnackedPacketsDebugOnly() const;
107 // Returns true if there are multiple packets in flight.
108 bool HasMultipleInFlightPackets() const;
110 // Returns true if there are any pending crypto packets.
111 bool HasPendingCryptoPackets() const;
113 // Removes any retransmittable frames from this transmission or an associated
114 // transmission. It removes now useless transmissions, and disconnects any
115 // other packets from other transmissions.
116 void RemoveRetransmittability(QuicPacketNumber packet_number);
118 // Removes any other retransmissions and marks all transmissions unackable.
119 void RemoveAckability(TransmissionInfo* info);
121 // Increases the largest observed. Any packets less or equal to
122 // |largest_acked_packet| are discarded if they are only for the RTT purposes.
123 void IncreaseLargestObserved(QuicPacketNumber largest_observed);
125 // Remove any packets no longer needed for retransmission, congestion, or
126 // RTT measurement purposes.
127 void RemoveObsoletePackets();
129 private:
130 // Called when a packet is retransmitted with a new packet number.
131 // |old_packet_number| will remain unacked, but will have no
132 // retransmittable data associated with it. Retransmittable frames will be
133 // transferred to |info| and all_transmissions will be populated.
134 void TransferRetransmissionInfo(QuicPacketNumber old_packet_number,
135 QuicPacketNumber new_packet_number,
136 TransmissionType transmission_type,
137 TransmissionInfo* info);
139 void MaybeRemoveRetransmittableFrames(TransmissionInfo* transmission_info);
141 // Returns true if packet may be useful for an RTT measurement.
142 bool IsPacketUsefulForMeasuringRtt(QuicPacketNumber packet_number,
143 const TransmissionInfo& info) const;
145 // Returns true if packet may be useful for congestion control purposes.
146 bool IsPacketUsefulForCongestionControl(const TransmissionInfo& info) const;
148 // Returns true if packet may be associated with retransmittable data
149 // directly or through retransmissions.
150 bool IsPacketUsefulForRetransmittableData(const TransmissionInfo& info) const;
152 // Returns true if the packet no longer has a purpose in the map.
153 bool IsPacketUseless(QuicPacketNumber packet_number,
154 const TransmissionInfo& info) const;
156 // Removes the packet with lowest packet number from the map.
157 void PopLeastUnacked();
159 QuicPacketNumber largest_sent_packet_;
160 QuicPacketNumber largest_observed_;
162 // Newly serialized retransmittable and fec packets are added to this map,
163 // which contains owning pointers to any contained frames. If a packet is
164 // retransmitted, this map will contain entries for both the old and the new
165 // packet. The old packet's retransmittable frames entry will be nullptr,
166 // while the new packet's entry will contain the frames to retransmit.
167 // If the old packet is acked before the new packet, then the old entry will
168 // be removed from the map and the new entry's retransmittable frames will be
169 // set to nullptr.
170 UnackedPacketMap unacked_packets_;
171 // The packet at the 0th index of unacked_packets_.
172 QuicPacketNumber least_unacked_;
174 QuicByteCount bytes_in_flight_;
175 // Number of retransmittable crypto handshake packets.
176 size_t pending_crypto_packet_count_;
178 // Notifier manager for ACK packets. We notify it every time we abandon a
179 // packet.
180 AckNotifierManager* ack_notifier_manager_;
182 DISALLOW_COPY_AND_ASSIGN(QuicUnackedPacketMap);
185 } // namespace net
187 #endif // NET_QUIC_QUIC_UNACKED_PACKET_MAP_H_