OLD | NEW |
| (Empty) |
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. | |
4 | |
5 #ifndef NET_QUIC_QUIC_UNACKED_PACKET_MAP_H_ | |
6 #define NET_QUIC_QUIC_UNACKED_PACKET_MAP_H_ | |
7 | |
8 #include <deque> | |
9 | |
10 #include "net/quic/quic_protocol.h" | |
11 | |
12 namespace net { | |
13 | |
14 // Class which tracks unacked packets for three purposes: | |
15 // 1) Track retransmittable data, including multiple transmissions of frames. | |
16 // 2) Track packets and bytes in flight for congestion control. | |
17 // 3) Track sent time of packets to provide RTT measurements from acks. | |
18 class NET_EXPORT_PRIVATE QuicUnackedPacketMap { | |
19 public: | |
20 QuicUnackedPacketMap(); | |
21 ~QuicUnackedPacketMap(); | |
22 | |
23 // Adds |serialized_packet| to the map and marks it as sent at |sent_time|. | |
24 // Marks the packet as in flight if |set_in_flight| is true. | |
25 // Packets marked as in flight are expected to be marked as missing when they | |
26 // don't arrive, indicating the need for retransmission. | |
27 // |old_sequence_number| is the sequence number of the previous transmission, | |
28 // or 0 if there was none. | |
29 void AddSentPacket(const SerializedPacket& serialized_packet, | |
30 QuicPacketSequenceNumber old_sequence_number, | |
31 TransmissionType transmission_type, | |
32 QuicTime sent_time, | |
33 QuicByteCount bytes_sent, | |
34 bool set_in_flight); | |
35 | |
36 // Returns true if the packet |sequence_number| is unacked. | |
37 bool IsUnacked(QuicPacketSequenceNumber sequence_number) const; | |
38 | |
39 // Sets the nack count to the max of the current nack count and |min_nacks|. | |
40 void NackPacket(QuicPacketSequenceNumber sequence_number, | |
41 QuicPacketCount min_nacks); | |
42 | |
43 // Marks |sequence_number| as no longer in flight. | |
44 void RemoveFromInFlight(QuicPacketSequenceNumber sequence_number); | |
45 | |
46 // Returns true if the unacked packet |sequence_number| has retransmittable | |
47 // frames. This will return false if the packet has been acked, if a | |
48 // previous transmission of this packet was ACK'd, or if this packet has been | |
49 // retransmitted as with different sequence number, or if the packet never | |
50 // had any retransmittable packets in the first place. | |
51 bool HasRetransmittableFrames(QuicPacketSequenceNumber sequence_number) const; | |
52 | |
53 // Returns true if there are any unacked packets. | |
54 bool HasUnackedPackets() const; | |
55 | |
56 // Returns true if there are any unacked packets which have retransmittable | |
57 // frames. | |
58 bool HasUnackedRetransmittableFrames() const; | |
59 | |
60 // Returns the largest sequence number that has been sent. | |
61 QuicPacketSequenceNumber largest_sent_packet() const { | |
62 return largest_sent_packet_; | |
63 } | |
64 | |
65 // Returns the largest sequence number that has been acked. | |
66 QuicPacketSequenceNumber largest_observed() const { | |
67 return largest_observed_; | |
68 } | |
69 | |
70 // Returns the sum of bytes from all packets in flight. | |
71 QuicByteCount bytes_in_flight() const { | |
72 return bytes_in_flight_; | |
73 } | |
74 | |
75 // Returns the smallest sequence number of a serialized packet which has not | |
76 // been acked by the peer. If there are no unacked packets, returns 0. | |
77 QuicPacketSequenceNumber GetLeastUnacked() const; | |
78 | |
79 // Restores the in flight status for a packet that was previously sent. | |
80 void RestoreInFlight(QuicPacketSequenceNumber sequence_number); | |
81 | |
82 // Clears all previous transmissions in order to make room in the ack frame | |
83 // for newly acked packets. | |
84 void ClearAllPreviousRetransmissions(); | |
85 | |
86 typedef std::deque<TransmissionInfo> UnackedPacketMap; | |
87 | |
88 typedef UnackedPacketMap::const_iterator const_iterator; | |
89 | |
90 const_iterator begin() const { return unacked_packets_.begin(); } | |
91 const_iterator end() const { return unacked_packets_.end(); } | |
92 | |
93 // Returns true if there are unacked packets that are in flight. | |
94 bool HasInFlightPackets() const; | |
95 | |
96 // Returns the TransmissionInfo associated with |sequence_number|, which | |
97 // must be unacked. | |
98 const TransmissionInfo& GetTransmissionInfo( | |
99 QuicPacketSequenceNumber sequence_number) const; | |
100 | |
101 // Returns the time that the last unacked packet was sent. | |
102 QuicTime GetLastPacketSentTime() const; | |
103 | |
104 // Returns the time that the first in flight packet was sent. | |
105 QuicTime GetFirstInFlightPacketSentTime() const; | |
106 | |
107 // Returns the number of unacked packets. | |
108 size_t GetNumUnackedPacketsDebugOnly() const; | |
109 | |
110 // Returns true if there are multiple packets in flight. | |
111 bool HasMultipleInFlightPackets() const; | |
112 | |
113 // Returns true if there are any pending crypto packets. | |
114 bool HasPendingCryptoPackets() const; | |
115 | |
116 // Removes any retransmittable frames from this transmission or an associated | |
117 // transmission. It removes now useless transmissions, and disconnects any | |
118 // other packets from other transmissions. | |
119 void RemoveRetransmittability(QuicPacketSequenceNumber sequence_number); | |
120 | |
121 // Removes any other retransmissions and marks all transmissions unackable. | |
122 void RemoveAckability(TransmissionInfo* info); | |
123 | |
124 // Increases the largest observed. Any packets less or equal to | |
125 // |largest_acked_packet| are discarded if they are only for the RTT purposes. | |
126 void IncreaseLargestObserved(QuicPacketSequenceNumber largest_observed); | |
127 | |
128 // Remove any packets no longer needed for retransmission, congestion, or | |
129 // RTT measurement purposes. | |
130 void RemoveObsoletePackets(); | |
131 | |
132 private: | |
133 // Called when a packet is retransmitted with a new sequence number. | |
134 // |old_sequence_number| will remain unacked, but will have no | |
135 // retransmittable data associated with it. Retransmittable frames will be | |
136 // transferred to |info| and all_transmissions will be populated. | |
137 void TransferRetransmissionInfo(QuicPacketSequenceNumber old_sequence_number, | |
138 QuicPacketSequenceNumber new_sequence_number, | |
139 TransmissionType transmission_type, | |
140 TransmissionInfo* info); | |
141 | |
142 void MaybeRemoveRetransmittableFrames(TransmissionInfo* transmission_info); | |
143 | |
144 // Returns true if packet may be useful for an RTT measurement. | |
145 bool IsPacketUsefulForMeasuringRtt(QuicPacketSequenceNumber sequence_number, | |
146 const TransmissionInfo& info) const; | |
147 | |
148 // Returns true if packet may be useful for congestion control purposes. | |
149 bool IsPacketUsefulForCongestionControl( | |
150 QuicPacketSequenceNumber sequence_number, | |
151 const TransmissionInfo& info) const; | |
152 | |
153 // Returns true if packet may be associated with retransmittable data | |
154 // directly or through retransmissions. | |
155 bool IsPacketUsefulForRetransmittableData( | |
156 QuicPacketSequenceNumber sequence_number, | |
157 const TransmissionInfo& info) const; | |
158 | |
159 // Returns true if the packet no longer has a purpose in the map. | |
160 bool IsPacketUseless(QuicPacketSequenceNumber sequence_number, | |
161 const TransmissionInfo& info) const; | |
162 | |
163 // Returns true if the packet is useless or it's only purpose is RTT | |
164 // measurement, and it's old enough that is unlikely to ever happen. | |
165 bool IsPacketRemovable(QuicPacketSequenceNumber sequence_number, | |
166 const TransmissionInfo& info) const; | |
167 | |
168 QuicPacketSequenceNumber largest_sent_packet_; | |
169 QuicPacketSequenceNumber largest_observed_; | |
170 | |
171 // Newly serialized retransmittable and fec packets are added to this map, | |
172 // which contains owning pointers to any contained frames. If a packet is | |
173 // retransmitted, this map will contain entries for both the old and the new | |
174 // packet. The old packet's retransmittable frames entry will be nullptr, | |
175 // while the new packet's entry will contain the frames to retransmit. | |
176 // If the old packet is acked before the new packet, then the old entry will | |
177 // be removed from the map and the new entry's retransmittable frames will be | |
178 // set to nullptr. | |
179 UnackedPacketMap unacked_packets_; | |
180 // The packet at the 0th index of unacked_packets_. | |
181 QuicPacketSequenceNumber least_unacked_; | |
182 | |
183 QuicByteCount bytes_in_flight_; | |
184 // Number of retransmittable crypto handshake packets. | |
185 size_t pending_crypto_packet_count_; | |
186 | |
187 DISALLOW_COPY_AND_ASSIGN(QuicUnackedPacketMap); | |
188 }; | |
189 | |
190 } // namespace net | |
191 | |
192 #endif // NET_QUIC_QUIC_UNACKED_PACKET_MAP_H_ | |
OLD | NEW |