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 #include "net/quic/quic_sent_packet_manager.h" | 5 #include "net/quic/quic_sent_packet_manager.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 | 8 |
9 #include "base/logging.h" | 9 #include "base/logging.h" |
10 #include "base/stl_util.h" | 10 #include "base/stl_util.h" |
(...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
170 transmission_type); | 170 transmission_type); |
171 | 171 |
172 if (debug_delegate_ != NULL) { | 172 if (debug_delegate_ != NULL) { |
173 debug_delegate_->OnRetransmittedPacket(old_sequence_number, | 173 debug_delegate_->OnRetransmittedPacket(old_sequence_number, |
174 new_sequence_number, | 174 new_sequence_number, |
175 transmission_type, | 175 transmission_type, |
176 clock_->ApproximateNow()); | 176 clock_->ApproximateNow()); |
177 } | 177 } |
178 } | 178 } |
179 | 179 |
180 void QuicSentPacketManager::OnIncomingAck( | 180 void QuicSentPacketManager::OnIncomingAck(const QuicAckFrame& ack_frame, |
181 const ReceivedPacketInfo& received_info, | 181 QuicTime ack_receive_time) { |
182 QuicTime ack_receive_time) { | |
183 QuicByteCount bytes_in_flight = unacked_packets_.bytes_in_flight(); | 182 QuicByteCount bytes_in_flight = unacked_packets_.bytes_in_flight(); |
184 | 183 |
185 // We rely on delta_time_largest_observed to compute an RTT estimate, so | 184 // We rely on delta_time_largest_observed to compute an RTT estimate, so |
186 // we only update rtt when the largest observed gets acked. | 185 // we only update rtt when the largest observed gets acked. |
187 bool largest_observed_acked = MaybeUpdateRTT(received_info, ack_receive_time); | 186 bool largest_observed_acked = MaybeUpdateRTT(ack_frame, ack_receive_time); |
188 if (largest_observed_ < received_info.largest_observed) { | 187 if (largest_observed_ < ack_frame.largest_observed) { |
189 largest_observed_ = received_info.largest_observed; | 188 largest_observed_ = ack_frame.largest_observed; |
190 unacked_packets_.IncreaseLargestObserved(largest_observed_); | 189 unacked_packets_.IncreaseLargestObserved(largest_observed_); |
191 } | 190 } |
192 HandleAckForSentPackets(received_info); | 191 HandleAckForSentPackets(ack_frame); |
193 InvokeLossDetection(ack_receive_time); | 192 InvokeLossDetection(ack_receive_time); |
194 MaybeInvokeCongestionEvent(largest_observed_acked, bytes_in_flight); | 193 MaybeInvokeCongestionEvent(largest_observed_acked, bytes_in_flight); |
195 | 194 |
196 // If we have received a truncated ack, then we need to clear out some | 195 // If we have received a truncated ack, then we need to clear out some |
197 // previous transmissions to allow the peer to actually ACK new packets. | 196 // previous transmissions to allow the peer to actually ACK new packets. |
198 if (received_info.is_truncated) { | 197 if (ack_frame.is_truncated) { |
199 unacked_packets_.ClearPreviousRetransmissions( | 198 unacked_packets_.ClearPreviousRetransmissions( |
200 received_info.missing_packets.size() / 2); | 199 ack_frame.missing_packets.size() / 2); |
201 } | 200 } |
202 | 201 |
203 // Anytime we are making forward progress and have a new RTT estimate, reset | 202 // Anytime we are making forward progress and have a new RTT estimate, reset |
204 // the backoff counters. | 203 // the backoff counters. |
205 if (largest_observed_acked) { | 204 if (largest_observed_acked) { |
206 // Reset all retransmit counters any time a new packet is acked. | 205 // Reset all retransmit counters any time a new packet is acked. |
207 consecutive_rto_count_ = 0; | 206 consecutive_rto_count_ = 0; |
208 consecutive_tlp_count_ = 0; | 207 consecutive_tlp_count_ = 0; |
209 consecutive_crypto_retransmission_count_ = 0; | 208 consecutive_crypto_retransmission_count_ = 0; |
210 } | 209 } |
211 | 210 |
212 if (debug_delegate_ != NULL) { | 211 if (debug_delegate_ != NULL) { |
213 debug_delegate_->OnIncomingAck(received_info, | 212 debug_delegate_->OnIncomingAck(ack_frame, |
214 ack_receive_time, | 213 ack_receive_time, |
215 largest_observed_, | 214 largest_observed_, |
216 largest_observed_acked, | 215 largest_observed_acked, |
217 GetLeastUnackedSentPacket()); | 216 GetLeastUnackedSentPacket()); |
218 } | 217 } |
219 } | 218 } |
220 | 219 |
221 void QuicSentPacketManager::MaybeInvokeCongestionEvent( | 220 void QuicSentPacketManager::MaybeInvokeCongestionEvent( |
222 bool rtt_updated, QuicByteCount bytes_in_flight) { | 221 bool rtt_updated, QuicByteCount bytes_in_flight) { |
223 if (!rtt_updated && packets_acked_.empty() && packets_lost_.empty()) { | 222 if (!rtt_updated && packets_acked_.empty() && packets_lost_.empty()) { |
224 return; | 223 return; |
225 } | 224 } |
226 send_algorithm_->OnCongestionEvent(rtt_updated, bytes_in_flight, | 225 send_algorithm_->OnCongestionEvent(rtt_updated, bytes_in_flight, |
227 packets_acked_, packets_lost_); | 226 packets_acked_, packets_lost_); |
228 packets_acked_.clear(); | 227 packets_acked_.clear(); |
229 packets_lost_.clear(); | 228 packets_lost_.clear(); |
230 if (network_change_visitor_ != NULL) { | 229 if (network_change_visitor_ != NULL) { |
231 network_change_visitor_->OnCongestionWindowChange(GetCongestionWindow()); | 230 network_change_visitor_->OnCongestionWindowChange(GetCongestionWindow()); |
232 } | 231 } |
233 } | 232 } |
234 | 233 |
235 void QuicSentPacketManager::HandleAckForSentPackets( | 234 void QuicSentPacketManager::HandleAckForSentPackets( |
236 const ReceivedPacketInfo& received_info) { | 235 const QuicAckFrame& ack_frame) { |
237 // Go through the packets we have not received an ack for and see if this | 236 // Go through the packets we have not received an ack for and see if this |
238 // incoming_ack shows they've been seen by the peer. | 237 // incoming_ack shows they've been seen by the peer. |
239 QuicTime::Delta delta_largest_observed = | 238 QuicTime::Delta delta_largest_observed = |
240 received_info.delta_time_largest_observed; | 239 ack_frame.delta_time_largest_observed; |
241 QuicUnackedPacketMap::const_iterator it = unacked_packets_.begin(); | 240 QuicUnackedPacketMap::const_iterator it = unacked_packets_.begin(); |
242 while (it != unacked_packets_.end()) { | 241 while (it != unacked_packets_.end()) { |
243 QuicPacketSequenceNumber sequence_number = it->first; | 242 QuicPacketSequenceNumber sequence_number = it->first; |
244 if (sequence_number > received_info.largest_observed) { | 243 if (sequence_number > ack_frame.largest_observed) { |
245 // These packets are still in flight. | 244 // These packets are still in flight. |
246 break; | 245 break; |
247 } | 246 } |
248 | 247 |
249 if (IsAwaitingPacket(received_info, sequence_number)) { | 248 if (IsAwaitingPacket(ack_frame, sequence_number)) { |
250 // Consider it multiple nacks when there is a gap between the missing | 249 // Consider it multiple nacks when there is a gap between the missing |
251 // packet and the largest observed, since the purpose of a nack | 250 // packet and the largest observed, since the purpose of a nack |
252 // threshold is to tolerate re-ordering. This handles both StretchAcks | 251 // threshold is to tolerate re-ordering. This handles both StretchAcks |
253 // and Forward Acks. | 252 // and Forward Acks. |
254 // The nack count only increases when the largest observed increases. | 253 // The nack count only increases when the largest observed increases. |
255 size_t min_nacks = received_info.largest_observed - sequence_number; | 254 size_t min_nacks = ack_frame.largest_observed - sequence_number; |
256 // Truncated acks can nack the largest observed, so use a min of 1. | 255 // Truncated acks can nack the largest observed, so use a min of 1. |
257 if (min_nacks == 0) { | 256 if (min_nacks == 0) { |
258 min_nacks = 1; | 257 min_nacks = 1; |
259 } | 258 } |
260 unacked_packets_.NackPacket(sequence_number, min_nacks); | 259 unacked_packets_.NackPacket(sequence_number, min_nacks); |
261 ++it; | 260 ++it; |
262 continue; | 261 continue; |
263 } | 262 } |
264 // Packet was acked, so remove it from our unacked packet list. | 263 // Packet was acked, so remove it from our unacked packet list. |
265 DVLOG(1) << ENDPOINT << "Got an ack for packet " << sequence_number; | 264 DVLOG(1) << ENDPOINT << "Got an ack for packet " << sequence_number; |
266 // If data is associated with the most recent transmission of this | 265 // If data is associated with the most recent transmission of this |
267 // packet, then inform the caller. | 266 // packet, then inform the caller. |
268 if (it->second.in_flight) { | 267 if (it->second.in_flight) { |
269 packets_acked_[sequence_number] = it->second; | 268 packets_acked_[sequence_number] = it->second; |
270 } | 269 } |
271 it = MarkPacketHandled(it, delta_largest_observed); | 270 it = MarkPacketHandled(it, delta_largest_observed); |
272 } | 271 } |
273 | 272 |
274 // Discard any retransmittable frames associated with revived packets. | 273 // Discard any retransmittable frames associated with revived packets. |
275 for (SequenceNumberSet::const_iterator revived_it = | 274 for (SequenceNumberSet::const_iterator revived_it = |
276 received_info.revived_packets.begin(); | 275 ack_frame.revived_packets.begin(); |
277 revived_it != received_info.revived_packets.end(); ++revived_it) { | 276 revived_it != ack_frame.revived_packets.end(); ++revived_it) { |
278 MarkPacketRevived(*revived_it, delta_largest_observed); | 277 MarkPacketRevived(*revived_it, delta_largest_observed); |
279 } | 278 } |
280 } | 279 } |
281 | 280 |
282 bool QuicSentPacketManager::HasRetransmittableFrames( | 281 bool QuicSentPacketManager::HasRetransmittableFrames( |
283 QuicPacketSequenceNumber sequence_number) const { | 282 QuicPacketSequenceNumber sequence_number) const { |
284 return unacked_packets_.HasRetransmittableFrames(sequence_number); | 283 return unacked_packets_.HasRetransmittableFrames(sequence_number); |
285 } | 284 } |
286 | 285 |
287 void QuicSentPacketManager::RetransmitUnackedPackets( | 286 void QuicSentPacketManager::RetransmitUnackedPackets( |
(...skipping 410 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
698 // Since we will not retransmit this, we need to remove it from | 697 // Since we will not retransmit this, we need to remove it from |
699 // unacked_packets_. This is either the current transmission of | 698 // unacked_packets_. This is either the current transmission of |
700 // a packet whose previous transmission has been acked, a packet that has | 699 // a packet whose previous transmission has been acked, a packet that has |
701 // been TLP retransmitted, or an FEC packet. | 700 // been TLP retransmitted, or an FEC packet. |
702 unacked_packets_.RemoveFromInFlight(sequence_number); | 701 unacked_packets_.RemoveFromInFlight(sequence_number); |
703 } | 702 } |
704 } | 703 } |
705 } | 704 } |
706 | 705 |
707 bool QuicSentPacketManager::MaybeUpdateRTT( | 706 bool QuicSentPacketManager::MaybeUpdateRTT( |
708 const ReceivedPacketInfo& received_info, | 707 const QuicAckFrame& ack_frame, |
709 const QuicTime& ack_receive_time) { | 708 const QuicTime& ack_receive_time) { |
710 if (!unacked_packets_.IsUnacked(received_info.largest_observed)) { | 709 if (!unacked_packets_.IsUnacked(ack_frame.largest_observed)) { |
711 return false; | 710 return false; |
712 } | 711 } |
713 // We calculate the RTT based on the highest ACKed sequence number, the lower | 712 // We calculate the RTT based on the highest ACKed sequence number, the lower |
714 // sequence numbers will include the ACK aggregation delay. | 713 // sequence numbers will include the ACK aggregation delay. |
715 const TransmissionInfo& transmission_info = | 714 const TransmissionInfo& transmission_info = |
716 unacked_packets_.GetTransmissionInfo(received_info.largest_observed); | 715 unacked_packets_.GetTransmissionInfo(ack_frame.largest_observed); |
717 // Don't update the RTT if it hasn't been sent. | 716 // Don't update the RTT if it hasn't been sent. |
718 if (transmission_info.sent_time == QuicTime::Zero()) { | 717 if (transmission_info.sent_time == QuicTime::Zero()) { |
719 return false; | 718 return false; |
720 } | 719 } |
721 | 720 |
722 QuicTime::Delta send_delta = | 721 QuicTime::Delta send_delta = |
723 ack_receive_time.Subtract(transmission_info.sent_time); | 722 ack_receive_time.Subtract(transmission_info.sent_time); |
724 rtt_stats_.UpdateRtt( | 723 rtt_stats_.UpdateRtt( |
725 send_delta, received_info.delta_time_largest_observed, ack_receive_time); | 724 send_delta, ack_frame.delta_time_largest_observed, ack_receive_time); |
726 return true; | 725 return true; |
727 } | 726 } |
728 | 727 |
729 QuicTime::Delta QuicSentPacketManager::TimeUntilSend( | 728 QuicTime::Delta QuicSentPacketManager::TimeUntilSend( |
730 QuicTime now, | 729 QuicTime now, |
731 HasRetransmittableData retransmittable) { | 730 HasRetransmittableData retransmittable) { |
732 // The TLP logic is entirely contained within QuicSentPacketManager, so the | 731 // The TLP logic is entirely contained within QuicSentPacketManager, so the |
733 // send algorithm does not need to be consulted. | 732 // send algorithm does not need to be consulted. |
734 if (pending_tlp_transmission_) { | 733 if (pending_tlp_transmission_) { |
735 return QuicTime::Delta::Zero(); | 734 return QuicTime::Delta::Zero(); |
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
863 | 862 |
864 // Set up a pacing sender with a 5 millisecond alarm granularity. | 863 // Set up a pacing sender with a 5 millisecond alarm granularity. |
865 using_pacing_ = true; | 864 using_pacing_ = true; |
866 send_algorithm_.reset( | 865 send_algorithm_.reset( |
867 new PacingSender(send_algorithm_.release(), | 866 new PacingSender(send_algorithm_.release(), |
868 QuicTime::Delta::FromMilliseconds(5), | 867 QuicTime::Delta::FromMilliseconds(5), |
869 kInitialUnpacedBurst)); | 868 kInitialUnpacedBurst)); |
870 } | 869 } |
871 | 870 |
872 } // namespace net | 871 } // namespace net |
OLD | NEW |