| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef NET_QUIC_QUIC_UNACKED_PACKET_MAP_H_ | 5 #ifndef NET_QUIC_QUIC_UNACKED_PACKET_MAP_H_ |
| 6 #define NET_QUIC_QUIC_UNACKED_PACKET_MAP_H_ | 6 #define NET_QUIC_QUIC_UNACKED_PACKET_MAP_H_ |
| 7 | 7 |
| 8 #include "net/base/linked_hash_map.h" | 8 #include "net/base/linked_hash_map.h" |
| 9 #include "net/quic/quic_protocol.h" | 9 #include "net/quic/quic_protocol.h" |
| 10 | 10 |
| 11 namespace net { | 11 namespace net { |
| 12 | 12 |
| 13 // Class which tracks unacked packets, including those packets which are | 13 // Class which tracks unacked packets for three purposes: |
| 14 // currently pending, and the relationship between packets which | 14 // 1) Track retransmittable data, including multiple transmissions of frames. |
| 15 // contain the same data (via retransmissions) | 15 // 2) Track packets and bytes in flight for congestion control. |
| 16 // 3) Track sent time of packets to provide RTT measurements from acks. |
| 16 class NET_EXPORT_PRIVATE QuicUnackedPacketMap { | 17 class NET_EXPORT_PRIVATE QuicUnackedPacketMap { |
| 17 public: | 18 public: |
| 18 QuicUnackedPacketMap(); | 19 QuicUnackedPacketMap(); |
| 19 ~QuicUnackedPacketMap(); | 20 ~QuicUnackedPacketMap(); |
| 20 | 21 |
| 21 // Adds |serialized_packet| to the map. Does not mark it pending. | 22 // Adds |serialized_packet| to the map. Does not mark it in flight. |
| 22 void AddPacket(const SerializedPacket& serialized_packet); | 23 void AddPacket(const SerializedPacket& serialized_packet); |
| 23 | 24 |
| 24 // Called when a packet is retransmitted with a new sequence number. | 25 // Called when a packet is retransmitted with a new sequence number. |
| 25 // |old_sequence_number| will remain unacked, but will have no | 26 // |old_sequence_number| will remain unacked, but will have no |
| 26 // retransmittable data associated with it. |new_sequence_number| will | 27 // retransmittable data associated with it. |new_sequence_number| will |
| 27 // be both unacked and associated with retransmittable data. | 28 // be both unacked and associated with retransmittable data. |
| 28 void OnRetransmittedPacket(QuicPacketSequenceNumber old_sequence_number, | 29 void OnRetransmittedPacket(QuicPacketSequenceNumber old_sequence_number, |
| 29 QuicPacketSequenceNumber new_sequence_number); | 30 QuicPacketSequenceNumber new_sequence_number); |
| 30 | 31 |
| 31 // Returns true if the packet |sequence_number| is unacked. | 32 // Returns true if the packet |sequence_number| is unacked. |
| 32 bool IsUnacked(QuicPacketSequenceNumber sequence_number) const; | 33 bool IsUnacked(QuicPacketSequenceNumber sequence_number) const; |
| 33 | 34 |
| 34 // Sets the nack count to the max of the current nack count and |min_nacks|. | 35 // Sets the nack count to the max of the current nack count and |min_nacks|. |
| 35 void NackPacket(QuicPacketSequenceNumber sequence_number, | 36 void NackPacket(QuicPacketSequenceNumber sequence_number, |
| 36 size_t min_nacks); | 37 size_t min_nacks); |
| 37 | 38 |
| 38 // Marks |sequence_number| as no longer pending. | 39 // Marks |sequence_number| as no longer in flight. |
| 39 void SetNotPending(QuicPacketSequenceNumber sequence_number); | 40 void RemoveFromInFlight(QuicPacketSequenceNumber sequence_number); |
| 40 | 41 |
| 41 // Returns true if the unacked packet |sequence_number| has retransmittable | 42 // Returns true if the unacked packet |sequence_number| has retransmittable |
| 42 // frames. This will return false if the packet has been acked, if a | 43 // frames. This will return false if the packet has been acked, if a |
| 43 // previous transmission of this packet was ACK'd, or if this packet has been | 44 // previous transmission of this packet was ACK'd, or if this packet has been |
| 44 // retransmitted as with different sequence number, or if the packet never | 45 // retransmitted as with different sequence number, or if the packet never |
| 45 // had any retransmittable packets in the first place. | 46 // had any retransmittable packets in the first place. |
| 46 bool HasRetransmittableFrames(QuicPacketSequenceNumber sequence_number) const; | 47 bool HasRetransmittableFrames(QuicPacketSequenceNumber sequence_number) const; |
| 47 | 48 |
| 48 // Returns true if there are any unacked packets. | 49 // Returns true if there are any unacked packets. |
| 49 bool HasUnackedPackets() const; | 50 bool HasUnackedPackets() const; |
| 50 | 51 |
| 51 // Returns true if there are any unacked packets which have retransmittable | 52 // Returns true if there are any unacked packets which have retransmittable |
| 52 // frames. | 53 // frames. |
| 53 bool HasUnackedRetransmittableFrames() const; | 54 bool HasUnackedRetransmittableFrames() const; |
| 54 | 55 |
| 55 // Returns the largest sequence number that has been sent. | 56 // Returns the largest sequence number that has been sent. |
| 56 QuicPacketSequenceNumber largest_sent_packet() const { | 57 QuicPacketSequenceNumber largest_sent_packet() const { |
| 57 return largest_sent_packet_; | 58 return largest_sent_packet_; |
| 58 } | 59 } |
| 59 | 60 |
| 60 // Returns the sum of the bytes in all pending packets. | 61 // Returns the sum of bytes from all packets in flight. |
| 61 QuicByteCount bytes_in_flight() const { | 62 QuicByteCount bytes_in_flight() const { |
| 62 return bytes_in_flight_; | 63 return bytes_in_flight_; |
| 63 } | 64 } |
| 64 | 65 |
| 65 // Returns the smallest sequence number of a serialized packet which has not | 66 // Returns the smallest sequence number of a serialized packet which has not |
| 66 // been acked by the peer. If there are no unacked packets, returns 0. | 67 // been acked by the peer. If there are no unacked packets, returns 0. |
| 67 QuicPacketSequenceNumber GetLeastUnackedSentPacket() const; | 68 QuicPacketSequenceNumber GetLeastUnackedSentPacket() const; |
| 68 | 69 |
| 69 // Sets a packet as sent with the sent time |sent_time|. Marks the packet | 70 // Sets a packet as sent with the sent time |sent_time|. Marks the packet |
| 70 // as pending and tracks the |bytes_sent| if |set_pending| is true. | 71 // as in flight if |set_in_flight| is true. |
| 71 // Packets marked as pending are expected to be marked as missing when they | 72 // Packets marked as in flight are expected to be marked as missing when they |
| 72 // don't arrive, indicating the need for retransmission. | 73 // don't arrive, indicating the need for retransmission. |
| 73 void SetSent(QuicPacketSequenceNumber sequence_number, | 74 void SetSent(QuicPacketSequenceNumber sequence_number, |
| 74 QuicTime sent_time, | 75 QuicTime sent_time, |
| 75 QuicByteCount bytes_sent, | 76 QuicByteCount bytes_sent, |
| 76 bool set_pending); | 77 bool set_in_flight); |
| 77 | 78 |
| 78 // Clears up to |num_to_clear| previous transmissions in order to make room | 79 // Clears up to |num_to_clear| previous transmissions in order to make room |
| 79 // in the ack frame for new acks. | 80 // in the ack frame for new acks. |
| 80 void ClearPreviousRetransmissions(size_t num_to_clear); | 81 void ClearPreviousRetransmissions(size_t num_to_clear); |
| 81 | 82 |
| 82 typedef linked_hash_map<QuicPacketSequenceNumber, | 83 typedef linked_hash_map<QuicPacketSequenceNumber, |
| 83 TransmissionInfo> UnackedPacketMap; | 84 TransmissionInfo> UnackedPacketMap; |
| 84 | 85 |
| 85 typedef UnackedPacketMap::const_iterator const_iterator; | 86 typedef UnackedPacketMap::const_iterator const_iterator; |
| 86 | 87 |
| 87 const_iterator begin() const { return unacked_packets_.begin(); } | 88 const_iterator begin() const { return unacked_packets_.begin(); } |
| 88 const_iterator end() const { return unacked_packets_.end(); } | 89 const_iterator end() const { return unacked_packets_.end(); } |
| 89 | 90 |
| 90 // Returns true if there are unacked packets that are pending. | 91 // Returns true if there are unacked packets that are in flight. |
| 91 bool HasPendingPackets() const; | 92 bool HasInFlightPackets() const; |
| 92 | 93 |
| 93 // Returns the TransmissionInfo associated with |sequence_number|, which | 94 // Returns the TransmissionInfo associated with |sequence_number|, which |
| 94 // must be unacked. | 95 // must be unacked. |
| 95 const TransmissionInfo& GetTransmissionInfo( | 96 const TransmissionInfo& GetTransmissionInfo( |
| 96 QuicPacketSequenceNumber sequence_number) const; | 97 QuicPacketSequenceNumber sequence_number) const; |
| 97 | 98 |
| 98 // Returns the time that the last unacked packet was sent. | 99 // Returns the time that the last unacked packet was sent. |
| 99 QuicTime GetLastPacketSentTime() const; | 100 QuicTime GetLastPacketSentTime() const; |
| 100 | 101 |
| 101 // Returns the time that the first pending packet was sent. | 102 // Returns the time that the first in flight packet was sent. |
| 102 QuicTime GetFirstPendingPacketSentTime() const; | 103 QuicTime GetFirstInFlightPacketSentTime() const; |
| 103 | 104 |
| 104 // Returns the number of unacked packets. | 105 // Returns the number of unacked packets. |
| 105 size_t GetNumUnackedPackets() const; | 106 size_t GetNumUnackedPackets() const; |
| 106 | 107 |
| 107 // Returns true if there are multiple packet pending. | 108 // Returns true if there are multiple packets in flight. |
| 108 bool HasMultiplePendingPackets() const; | 109 bool HasMultipleInFlightPackets() const; |
| 109 | 110 |
| 110 // Returns true if there are any pending crypto packets. | 111 // Returns true if there are any pending crypto packets. |
| 111 bool HasPendingCryptoPackets() const; | 112 bool HasPendingCryptoPackets() const; |
| 112 | 113 |
| 113 // Removes any retransmittable frames from this transmission or an associated | 114 // Removes any retransmittable frames from this transmission or an associated |
| 114 | |
| 115 // transmission. It removes now useless transmissions, and disconnects any | 115 // transmission. It removes now useless transmissions, and disconnects any |
| 116 // other packets from other transmissions. | 116 // other packets from other transmissions. |
| 117 void RemoveRetransmittability(QuicPacketSequenceNumber sequence_number); | 117 void RemoveRetransmittability(QuicPacketSequenceNumber sequence_number); |
| 118 | 118 |
| 119 // Increases the largest observed. Any packets less or equal to | 119 // Increases the largest observed. Any packets less or equal to |
| 120 // |largest_acked_packet| are discarded if they are only for the RTT purposes. | 120 // |largest_acked_packet| are discarded if they are only for the RTT purposes. |
| 121 void IncreaseLargestObserved(QuicPacketSequenceNumber largest_observed); | 121 void IncreaseLargestObserved(QuicPacketSequenceNumber largest_observed); |
| 122 | 122 |
| 123 private: | 123 private: |
| 124 void MaybeRemoveRetransmittableFrames(TransmissionInfo* transmission_info); | 124 void MaybeRemoveRetransmittableFrames(TransmissionInfo* transmission_info); |
| 125 | 125 |
| 126 // Returns true if the packet no longer has a purpose in the map. | 126 // Returns true if the packet no longer has a purpose in the map. |
| 127 bool IsPacketUseless(UnackedPacketMap::const_iterator it); | 127 bool IsPacketUseless(UnackedPacketMap::const_iterator it) const; |
| 128 | 128 |
| 129 QuicPacketSequenceNumber largest_sent_packet_; | 129 QuicPacketSequenceNumber largest_sent_packet_; |
| 130 QuicPacketSequenceNumber largest_observed_; | 130 QuicPacketSequenceNumber largest_observed_; |
| 131 | 131 |
| 132 // Newly serialized retransmittable and fec packets are added to this map, | 132 // Newly serialized retransmittable and fec packets are added to this map, |
| 133 // which contains owning pointers to any contained frames. If a packet is | 133 // which contains owning pointers to any contained frames. If a packet is |
| 134 // retransmitted, this map will contain entries for both the old and the new | 134 // retransmitted, this map will contain entries for both the old and the new |
| 135 // packet. The old packet's retransmittable frames entry will be NULL, while | 135 // packet. The old packet's retransmittable frames entry will be NULL, while |
| 136 // the new packet's entry will contain the frames to retransmit. | 136 // the new packet's entry will contain the frames to retransmit. |
| 137 // If the old packet is acked before the new packet, then the old entry will | 137 // If the old packet is acked before the new packet, then the old entry will |
| 138 // be removed from the map and the new entry's retransmittable frames will be | 138 // be removed from the map and the new entry's retransmittable frames will be |
| 139 // set to NULL. | 139 // set to NULL. |
| 140 UnackedPacketMap unacked_packets_; | 140 UnackedPacketMap unacked_packets_; |
| 141 | 141 |
| 142 size_t bytes_in_flight_; | 142 size_t bytes_in_flight_; |
| 143 // Number of outstanding crypto handshake packets. | 143 // Number of retransmittable crypto handshake packets. |
| 144 size_t pending_crypto_packet_count_; | 144 size_t pending_crypto_packet_count_; |
| 145 | 145 |
| 146 DISALLOW_COPY_AND_ASSIGN(QuicUnackedPacketMap); | 146 DISALLOW_COPY_AND_ASSIGN(QuicUnackedPacketMap); |
| 147 }; | 147 }; |
| 148 | 148 |
| 149 } // namespace net | 149 } // namespace net |
| 150 | 150 |
| 151 #endif // NET_QUIC_QUIC_UNACKED_PACKET_MAP_H_ | 151 #endif // NET_QUIC_QUIC_UNACKED_PACKET_MAP_H_ |
| OLD | NEW |