Updating trunk VERSION from 2139.0 to 2140.0
[chromium-blink-merge.git] / net / quic / quic_unacked_packet_map.h
blob3c367f6e670c61892f5c9fc6270bf8f7de24df44
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 "net/base/linked_hash_map.h"
9 #include "net/quic/quic_protocol.h"
11 namespace net {
13 // Class which tracks unacked packets for three purposes:
14 // 1) Track retransmittable data, including multiple transmissions of frames.
15 // 2) Track packets and bytes in flight for congestion control.
16 // 3) Track sent time of packets to provide RTT measurements from acks.
17 class NET_EXPORT_PRIVATE QuicUnackedPacketMap {
18 public:
19 QuicUnackedPacketMap();
20 ~QuicUnackedPacketMap();
22 // Adds |serialized_packet| to the map. Does not mark it in flight.
23 void AddPacket(const SerializedPacket& serialized_packet);
25 // Called when a packet is retransmitted with a new sequence number.
26 // |old_sequence_number| will remain unacked, but will have no
27 // retransmittable data associated with it. |new_sequence_number| will
28 // be both unacked and associated with retransmittable data.
29 void OnRetransmittedPacket(QuicPacketSequenceNumber old_sequence_number,
30 QuicPacketSequenceNumber new_sequence_number,
31 TransmissionType transmission_type);
33 // Returns true if the packet |sequence_number| is unacked.
34 bool IsUnacked(QuicPacketSequenceNumber sequence_number) const;
36 // Sets the nack count to the max of the current nack count and |min_nacks|.
37 void NackPacket(QuicPacketSequenceNumber sequence_number,
38 size_t min_nacks);
40 // Marks |sequence_number| as no longer in flight.
41 void RemoveFromInFlight(QuicPacketSequenceNumber sequence_number);
43 // Returns true if the unacked packet |sequence_number| has retransmittable
44 // frames. This will return false if the packet has been acked, if a
45 // previous transmission of this packet was ACK'd, or if this packet has been
46 // retransmitted as with different sequence number, or if the packet never
47 // had any retransmittable packets in the first place.
48 bool HasRetransmittableFrames(QuicPacketSequenceNumber sequence_number) const;
50 // Returns true if there are any unacked packets.
51 bool HasUnackedPackets() const;
53 // Returns true if there are any unacked packets which have retransmittable
54 // frames.
55 bool HasUnackedRetransmittableFrames() const;
57 // Returns the largest sequence number that has been sent.
58 QuicPacketSequenceNumber largest_sent_packet() const {
59 return largest_sent_packet_;
62 // Returns the largest sequence number that has been acked.
63 QuicPacketSequenceNumber largest_observed() const {
64 return largest_observed_;
67 // Returns the sum of bytes from all packets in flight.
68 QuicByteCount bytes_in_flight() const {
69 return bytes_in_flight_;
72 // Returns the smallest sequence number of a serialized packet which has not
73 // been acked by the peer. If there are no unacked packets, returns 0.
74 QuicPacketSequenceNumber GetLeastUnackedSentPacket() const;
76 // Sets a packet as sent with the sent time |sent_time|. Marks the packet
77 // as in flight if |set_in_flight| is true.
78 // Packets marked as in flight are expected to be marked as missing when they
79 // don't arrive, indicating the need for retransmission.
80 void SetSent(QuicPacketSequenceNumber sequence_number,
81 QuicTime sent_time,
82 QuicByteCount bytes_sent,
83 bool set_in_flight);
85 // Restores the in flight status for a packet that was previously sent.
86 void RestoreInFlight(QuicPacketSequenceNumber sequence_number);
88 // Clears up to |num_to_clear| previous transmissions in order to make room
89 // in the ack frame for new acks.
90 void ClearPreviousRetransmissions(size_t num_to_clear);
92 typedef linked_hash_map<QuicPacketSequenceNumber,
93 TransmissionInfo> UnackedPacketMap;
95 typedef UnackedPacketMap::const_iterator const_iterator;
97 const_iterator begin() const { return unacked_packets_.begin(); }
98 const_iterator end() const { return unacked_packets_.end(); }
100 // Returns true if there are unacked packets that are in flight.
101 bool HasInFlightPackets() const;
103 // Returns the TransmissionInfo associated with |sequence_number|, which
104 // must be unacked.
105 const TransmissionInfo& GetTransmissionInfo(
106 QuicPacketSequenceNumber sequence_number) const;
108 // Returns the time that the last unacked packet was sent.
109 QuicTime GetLastPacketSentTime() const;
111 // Returns the time that the first in flight packet was sent.
112 QuicTime GetFirstInFlightPacketSentTime() const;
114 // Returns the number of unacked packets.
115 size_t GetNumUnackedPackets() const;
117 // Returns true if there are multiple packets in flight.
118 bool HasMultipleInFlightPackets() const;
120 // Returns true if there are any pending crypto packets.
121 bool HasPendingCryptoPackets() const;
123 // Removes any retransmittable frames from this transmission or an associated
124 // transmission. It removes now useless transmissions, and disconnects any
125 // other packets from other transmissions.
126 void RemoveRetransmittability(QuicPacketSequenceNumber sequence_number);
128 // Increases the largest observed. Any packets less or equal to
129 // |largest_acked_packet| are discarded if they are only for the RTT purposes.
130 void IncreaseLargestObserved(QuicPacketSequenceNumber largest_observed);
132 private:
133 void MaybeRemoveRetransmittableFrames(TransmissionInfo* transmission_info);
135 // Returns true if the packet no longer has a purpose in the map.
136 bool IsPacketUseless(UnackedPacketMap::const_iterator it) const;
138 QuicPacketSequenceNumber largest_sent_packet_;
139 QuicPacketSequenceNumber largest_observed_;
141 // Newly serialized retransmittable and fec packets are added to this map,
142 // which contains owning pointers to any contained frames. If a packet is
143 // retransmitted, this map will contain entries for both the old and the new
144 // packet. The old packet's retransmittable frames entry will be NULL, while
145 // the new packet's entry will contain the frames to retransmit.
146 // If the old packet is acked before the new packet, then the old entry will
147 // be removed from the map and the new entry's retransmittable frames will be
148 // set to NULL.
149 UnackedPacketMap unacked_packets_;
151 size_t bytes_in_flight_;
152 // Number of retransmittable crypto handshake packets.
153 size_t pending_crypto_packet_count_;
155 DISALLOW_COPY_AND_ASSIGN(QuicUnackedPacketMap);
158 } // namespace net
160 #endif // NET_QUIC_QUIC_UNACKED_PACKET_MAP_H_