| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 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 | 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_SENT_PACKET_MANAGER_H_ | 5 #ifndef NET_QUIC_QUIC_SENT_PACKET_MANAGER_H_ |
| 6 #define NET_QUIC_QUIC_SENT_PACKET_MANAGER_H_ | 6 #define NET_QUIC_QUIC_SENT_PACKET_MANAGER_H_ |
| 7 | 7 |
| 8 #include <deque> | 8 #include <deque> |
| 9 #include <list> | 9 #include <list> |
| 10 #include <map> | 10 #include <map> |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 72 const QuicClock* clock, | 72 const QuicClock* clock, |
| 73 CongestionFeedbackType congestion_type); | 73 CongestionFeedbackType congestion_type); |
| 74 virtual ~QuicSentPacketManager(); | 74 virtual ~QuicSentPacketManager(); |
| 75 | 75 |
| 76 virtual void SetFromConfig(const QuicConfig& config); | 76 virtual void SetFromConfig(const QuicConfig& config); |
| 77 | 77 |
| 78 virtual void SetMaxPacketSize(QuicByteCount max_packet_size); | 78 virtual void SetMaxPacketSize(QuicByteCount max_packet_size); |
| 79 | 79 |
| 80 // Called when a new packet is serialized. If the packet contains | 80 // Called when a new packet is serialized. If the packet contains |
| 81 // retransmittable data, it will be added to the unacked packet map. | 81 // retransmittable data, it will be added to the unacked packet map. |
| 82 void OnSerializedPacket(const SerializedPacket& serialized_packet, | 82 void OnSerializedPacket(const SerializedPacket& serialized_packet); |
| 83 QuicTime serialized_time); | |
| 84 | 83 |
| 85 // Called when a packet is retransmitted with a new sequence number. | 84 // Called when a packet is retransmitted with a new sequence number. |
| 86 // Replaces the old entry in the unacked packet map with the new | 85 // Replaces the old entry in the unacked packet map with the new |
| 87 // sequence number. | 86 // sequence number. |
| 88 void OnRetransmittedPacket(QuicPacketSequenceNumber old_sequence_number, | 87 void OnRetransmittedPacket(QuicPacketSequenceNumber old_sequence_number, |
| 89 QuicPacketSequenceNumber new_sequence_number); | 88 QuicPacketSequenceNumber new_sequence_number); |
| 90 | 89 |
| 91 // Processes the incoming ack and returns true if the retransmission or ack | 90 // Processes the incoming ack and returns true if the retransmission or ack |
| 92 // alarm should be reset. | 91 // alarm should be reset. |
| 93 bool OnIncomingAck(const ReceivedPacketInfo& received_info, | 92 bool OnIncomingAck(const ReceivedPacketInfo& received_info, |
| 94 QuicTime ack_receive_time); | 93 QuicTime ack_receive_time); |
| 95 | 94 |
| 96 // Discards any information for the packet corresponding to |sequence_number|. | 95 // Discards any information for the packet corresponding to |sequence_number|. |
| 97 // If this packet has been retransmitted, information on those packets | 96 // If this packet has been retransmitted, information on those packets |
| 98 // will be discarded as well. | 97 // will be discarded as well. |
| 99 void DiscardUnackedPacket(QuicPacketSequenceNumber sequence_number); | 98 void DiscardUnackedPacket(QuicPacketSequenceNumber sequence_number); |
| 100 | 99 |
| 101 // Discards all information about fec packet |sequence_number|. | |
| 102 void DiscardFecPacket(QuicPacketSequenceNumber sequence_number); | |
| 103 | |
| 104 // Returns true if the non-FEC packet |sequence_number| is unacked. | 100 // Returns true if the non-FEC packet |sequence_number| is unacked. |
| 105 bool IsUnacked(QuicPacketSequenceNumber sequence_number) const; | 101 bool IsUnacked(QuicPacketSequenceNumber sequence_number) const; |
| 106 | 102 |
| 107 // Requests retransmission of all unacked packets of |retransmission_type|. | 103 // Requests retransmission of all unacked packets of |retransmission_type|. |
| 108 void RetransmitUnackedPackets(RetransmissionType retransmission_type); | 104 void RetransmitUnackedPackets(RetransmissionType retransmission_type); |
| 109 | 105 |
| 110 // Returns true if the unacked packet |sequence_number| has retransmittable | 106 // Returns true if the unacked packet |sequence_number| has retransmittable |
| 111 // frames. This will only return false if the packet has been acked, if a | 107 // frames. This will only return false if the packet has been acked, if a |
| 112 // previous transmission of this packet was ACK'd, or if this packet has been | 108 // previous transmission of this packet was ACK'd, or if this packet has been |
| 113 // retransmitted as with different sequence number. | 109 // retransmitted as with different sequence number. |
| 114 bool HasRetransmittableFrames(QuicPacketSequenceNumber sequence_number) const; | 110 bool HasRetransmittableFrames(QuicPacketSequenceNumber sequence_number) const; |
| 115 | 111 |
| 116 // Returns true if there are pending retransmissions. | 112 // Returns true if there are pending retransmissions. |
| 117 bool HasPendingRetransmissions() const; | 113 bool HasPendingRetransmissions() const; |
| 118 | 114 |
| 119 // Retrieves the next pending retransmission. | 115 // Retrieves the next pending retransmission. |
| 120 PendingRetransmission NextPendingRetransmission(); | 116 PendingRetransmission NextPendingRetransmission(); |
| 121 | 117 |
| 122 // Returns the time the fec packet was sent. | |
| 123 QuicTime GetFecSentTime(QuicPacketSequenceNumber sequence_number) const; | |
| 124 | |
| 125 // Returns true if there are any unacked packets. | |
| 126 bool HasUnackedPackets() const; | 118 bool HasUnackedPackets() const; |
| 127 | 119 |
| 128 // Returns the number of unacked packets which have retransmittable frames. | 120 // Returns the number of unacked packets which have retransmittable frames. |
| 129 size_t GetNumRetransmittablePackets() const; | 121 size_t GetNumRetransmittablePackets() const; |
| 130 | 122 |
| 131 // Returns true if there are any unacked FEC packets. | |
| 132 bool HasUnackedFecPackets() const; | |
| 133 | |
| 134 // Returns the smallest sequence number of a sent packet which has not been | 123 // Returns the smallest sequence number of a sent packet which has not been |
| 135 // acked by the peer. Excludes any packets which have been retransmitted | 124 // acked by the peer. Excludes any packets which have been retransmitted |
| 136 // with a new sequence number. If all packets have been acked, returns the | 125 // with a new sequence number. If all packets have been acked, returns the |
| 137 // sequence number of the next packet that will be sent. | 126 // sequence number of the next packet that will be sent. |
| 138 QuicPacketSequenceNumber GetLeastUnackedSentPacket() const; | 127 QuicPacketSequenceNumber GetLeastUnackedSentPacket() const; |
| 139 | 128 |
| 140 // Returns the smallest sequence number of a sent fec packet which has not | |
| 141 // been acked by the peer. If all packets have been acked, returns the | |
| 142 // sequence number of the next packet that will be sent. | |
| 143 QuicPacketSequenceNumber GetLeastUnackedFecPacket() const; | |
| 144 | |
| 145 // Returns the set of sequence numbers of all unacked packets. | 129 // Returns the set of sequence numbers of all unacked packets. |
| 130 // Test only. |
| 146 SequenceNumberSet GetUnackedPackets() const; | 131 SequenceNumberSet GetUnackedPackets() const; |
| 147 | 132 |
| 148 // Returns true if |sequence_number| is a previous transmission of packet. | 133 // Returns true if |sequence_number| is a previous transmission of packet. |
| 149 bool IsPreviousTransmission(QuicPacketSequenceNumber sequence_number) const; | 134 bool IsPreviousTransmission(QuicPacketSequenceNumber sequence_number) const; |
| 150 | 135 |
| 151 // TODO(ianswett): Combine the congestion control related methods below with | 136 // TODO(ianswett): Combine the congestion control related methods below with |
| 152 // some of the methods above and cleanup the resulting code. | 137 // some of the methods above and cleanup the resulting code. |
| 153 // Called when we have received an ack frame from peer. | 138 // Called when we have received an ack frame from peer. |
| 154 // Returns a set containing all the sequence numbers to be nack retransmitted | 139 // Returns a set containing all the sequence numbers to be nack retransmitted |
| 155 // as a result of the ack. | 140 // as a result of the ack. |
| (...skipping 10 matching lines...) Expand all Loading... |
| 166 // the number of bytes sent and if they were retransmitted. | 151 // the number of bytes sent and if they were retransmitted. |
| 167 virtual void OnPacketSent(QuicPacketSequenceNumber sequence_number, | 152 virtual void OnPacketSent(QuicPacketSequenceNumber sequence_number, |
| 168 QuicTime sent_time, | 153 QuicTime sent_time, |
| 169 QuicByteCount bytes, | 154 QuicByteCount bytes, |
| 170 TransmissionType transmission_type, | 155 TransmissionType transmission_type, |
| 171 HasRetransmittableData has_retransmittable_data); | 156 HasRetransmittableData has_retransmittable_data); |
| 172 | 157 |
| 173 // Called when the retransmission timer expires. | 158 // Called when the retransmission timer expires. |
| 174 virtual void OnRetransmissionTimeout(); | 159 virtual void OnRetransmissionTimeout(); |
| 175 | 160 |
| 176 // Called when the fec timout timer expires. Returns the next timeout of the | |
| 177 // FEC timer if it should be reset, and QuicTime::Zero() otherwise. | |
| 178 virtual QuicTime OnAbandonFecTimeout(); | |
| 179 | |
| 180 // Called when a packet is timed out, such as an RTO. Removes the bytes from | 161 // Called when a packet is timed out, such as an RTO. Removes the bytes from |
| 181 // the congestion manager, but does not change the congestion window size. | 162 // the congestion manager, but does not change the congestion window size. |
| 182 virtual void OnPacketAbandoned(QuicPacketSequenceNumber sequence_number); | 163 virtual void OnPacketAbandoned(QuicPacketSequenceNumber sequence_number); |
| 183 | 164 |
| 184 // Calculate the time until we can send the next packet to the wire. | 165 // Calculate the time until we can send the next packet to the wire. |
| 185 // Note 1: When kUnknownWaitTime is returned, there is no need to poll | 166 // Note 1: When kUnknownWaitTime is returned, there is no need to poll |
| 186 // TimeUntilSend again until we receive an OnIncomingAckFrame event. | 167 // TimeUntilSend again until we receive an OnIncomingAckFrame event. |
| 187 // Note 2: Send algorithms may or may not use |retransmit| in their | 168 // Note 2: Send algorithms may or may not use |retransmit| in their |
| 188 // calculations. | 169 // calculations. |
| 189 virtual QuicTime::Delta TimeUntilSend(QuicTime now, | 170 virtual QuicTime::Delta TimeUntilSend(QuicTime now, |
| (...skipping 23 matching lines...) Expand all Loading... |
| 213 void MaybeEnablePacing(); | 194 void MaybeEnablePacing(); |
| 214 | 195 |
| 215 bool using_pacing() const { return using_pacing_; } | 196 bool using_pacing() const { return using_pacing_; } |
| 216 | 197 |
| 217 | 198 |
| 218 private: | 199 private: |
| 219 friend class test::QuicConnectionPeer; | 200 friend class test::QuicConnectionPeer; |
| 220 friend class test::QuicSentPacketManagerPeer; | 201 friend class test::QuicSentPacketManagerPeer; |
| 221 | 202 |
| 222 struct TransmissionInfo { | 203 struct TransmissionInfo { |
| 223 TransmissionInfo() {} | 204 TransmissionInfo() |
| 205 : retransmittable_frames(NULL), |
| 206 sequence_number_length(PACKET_1BYTE_SEQUENCE_NUMBER), |
| 207 sent_time(QuicTime::Zero()) { } |
| 224 TransmissionInfo(RetransmittableFrames* retransmittable_frames, | 208 TransmissionInfo(RetransmittableFrames* retransmittable_frames, |
| 225 QuicSequenceNumberLength sequence_number_length) | 209 QuicSequenceNumberLength sequence_number_length) |
| 226 : retransmittable_frames(retransmittable_frames), | 210 : retransmittable_frames(retransmittable_frames), |
| 227 sequence_number_length(sequence_number_length) { | 211 sequence_number_length(sequence_number_length), |
| 212 sent_time(QuicTime::Zero()) { |
| 228 } | 213 } |
| 229 | 214 |
| 230 RetransmittableFrames* retransmittable_frames; | 215 RetransmittableFrames* retransmittable_frames; |
| 231 QuicSequenceNumberLength sequence_number_length; | 216 QuicSequenceNumberLength sequence_number_length; |
| 217 // Zero when the packet is serialized, non-zero once it's sent. |
| 218 QuicTime sent_time; |
| 232 }; | 219 }; |
| 233 | 220 |
| 234 typedef linked_hash_map<QuicPacketSequenceNumber, | 221 typedef linked_hash_map<QuicPacketSequenceNumber, |
| 235 TransmissionInfo> UnackedPacketMap; | 222 TransmissionInfo> UnackedPacketMap; |
| 236 typedef linked_hash_map<QuicPacketSequenceNumber, | 223 typedef linked_hash_map<QuicPacketSequenceNumber, |
| 237 QuicTime> UnackedFecPacketMap; | |
| 238 typedef linked_hash_map<QuicPacketSequenceNumber, | |
| 239 TransmissionType> PendingRetransmissionMap; | 224 TransmissionType> PendingRetransmissionMap; |
| 240 typedef base::hash_map<QuicPacketSequenceNumber, SequenceNumberSet*> | 225 typedef base::hash_map<QuicPacketSequenceNumber, SequenceNumberSet*> |
| 241 PreviousTransmissionMap; | 226 PreviousTransmissionMap; |
| 242 | 227 |
| 243 // Process the incoming ack looking for newly ack'd data packets. | 228 // Process the incoming ack looking for newly ack'd data packets. |
| 244 void HandleAckForSentPackets(const ReceivedPacketInfo& received_info); | 229 void HandleAckForSentPackets(const ReceivedPacketInfo& received_info); |
| 245 | 230 |
| 246 // Process the incoming ack looking for newly ack'd FEC packets. | |
| 247 void HandleAckForSentFecPackets(const ReceivedPacketInfo& received_info); | |
| 248 | |
| 249 // Update the RTT if the ack is for the largest acked sequence number. | 231 // Update the RTT if the ack is for the largest acked sequence number. |
| 250 void MaybeUpdateRTT(const ReceivedPacketInfo& received_info, | 232 void MaybeUpdateRTT(const ReceivedPacketInfo& received_info, |
| 251 const QuicTime& ack_receive_time); | 233 const QuicTime& ack_receive_time); |
| 252 | 234 |
| 253 // Marks |sequence_number| as having been seen by the peer. Returns an | 235 // Marks |sequence_number| as having been seen by the peer. Returns an |
| 254 // iterator to the next remaining unacked packet. | 236 // iterator to the next remaining unacked packet. |
| 255 UnackedPacketMap::iterator MarkPacketReceivedByPeer( | 237 UnackedPacketMap::iterator MarkPacketReceivedByPeer( |
| 256 QuicPacketSequenceNumber sequence_number); | 238 QuicPacketSequenceNumber sequence_number); |
| 257 | 239 |
| 258 // Simply removes the entries, if any, from the unacked packet map | 240 // Simply removes the entries, if any, from the unacked packet map |
| (...skipping 15 matching lines...) Expand all Loading... |
| 274 // most recently transmitted as. | 256 // most recently transmitted as. |
| 275 QuicPacketSequenceNumber GetMostRecentTransmission( | 257 QuicPacketSequenceNumber GetMostRecentTransmission( |
| 276 QuicPacketSequenceNumber sequence_number) const; | 258 QuicPacketSequenceNumber sequence_number) const; |
| 277 | 259 |
| 278 // Clears up to |num_to_clear| previous transmissions in order to make room | 260 // Clears up to |num_to_clear| previous transmissions in order to make room |
| 279 // in the ack frame for new acks. | 261 // in the ack frame for new acks. |
| 280 void ClearPreviousRetransmissions(size_t num_to_clear); | 262 void ClearPreviousRetransmissions(size_t num_to_clear); |
| 281 | 263 |
| 282 void CleanupPacketHistory(); | 264 void CleanupPacketHistory(); |
| 283 | 265 |
| 284 // When new packets are created which may be retransmitted, they are added | 266 // Newly serialized retransmittable and fec packets are added to this map, |
| 285 // to this map, which contains owning pointers to the contained frames. If | 267 // which contains owning pointers to any contained frames. If a packet is |
| 286 // a packet is retransmitted, this map will contain entries for both the old | 268 // retransmitted, this map will contain entries for both the old and the new |
| 287 // and the new packet. The old packet's retransmittable frames entry will be | 269 // packet. The old packet's retransmittable frames entry will be NULL, while |
| 288 // NULL, while the new packet's entry will contain the frames to retransmit. | 270 // the new packet's entry will contain the frames to retransmit. |
| 289 // If the old packet is acked before the new packet, then the old entry will | 271 // If the old packet is acked before the new packet, then the old entry will |
| 290 // be removed from the map and the new entry's retransmittable frames will be | 272 // be removed from the map and the new entry's retransmittable frames will be |
| 291 // set to NULL. | 273 // set to NULL. |
| 292 UnackedPacketMap unacked_packets_; | 274 UnackedPacketMap unacked_packets_; |
| 293 | 275 |
| 294 // Pending fec packets that have not been acked yet. These packets need to be | |
| 295 // cleared out of the cgst_window after a timeout since FEC packets are never | |
| 296 // retransmitted. | |
| 297 UnackedFecPacketMap unacked_fec_packets_; | |
| 298 | |
| 299 // Pending retransmissions which have not been packetized and sent yet. | 276 // Pending retransmissions which have not been packetized and sent yet. |
| 300 PendingRetransmissionMap pending_retransmissions_; | 277 PendingRetransmissionMap pending_retransmissions_; |
| 301 | 278 |
| 302 // Map from sequence number to set of all sequence number that this packet has | 279 // Map from sequence number to set of all sequence number that this packet has |
| 303 // been transmitted as. If a packet has not been retransmitted, it will not | 280 // been transmitted as. If a packet has not been retransmitted, it will not |
| 304 // have an entry in this map. If any transmission of a packet has been acked | 281 // have an entry in this map. If any transmission of a packet has been acked |
| 305 // it will not have an entry in this map. | 282 // it will not have an entry in this map. |
| 306 PreviousTransmissionMap previous_transmissions_map_; | 283 PreviousTransmissionMap previous_transmissions_map_; |
| 307 | 284 |
| 308 // Tracks if the connection was created by the server. | 285 // Tracks if the connection was created by the server. |
| (...skipping 17 matching lines...) Expand all Loading... |
| 326 // Number of times the RTO timer has fired in a row without receiving an ack. | 303 // Number of times the RTO timer has fired in a row without receiving an ack. |
| 327 size_t consecutive_rto_count_; | 304 size_t consecutive_rto_count_; |
| 328 bool using_pacing_; | 305 bool using_pacing_; |
| 329 | 306 |
| 330 DISALLOW_COPY_AND_ASSIGN(QuicSentPacketManager); | 307 DISALLOW_COPY_AND_ASSIGN(QuicSentPacketManager); |
| 331 }; | 308 }; |
| 332 | 309 |
| 333 } // namespace net | 310 } // namespace net |
| 334 | 311 |
| 335 #endif // NET_QUIC_QUIC_SENT_PACKET_MANAGER_H_ | 312 #endif // NET_QUIC_QUIC_SENT_PACKET_MANAGER_H_ |
| OLD | NEW |