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 20 matching lines...) Expand all Loading... | |
31 | 31 |
32 // Only exponentially back off the handshake timer 5 times due to a timeout. | 32 // Only exponentially back off the handshake timer 5 times due to a timeout. |
33 static const size_t kMaxHandshakeRetransmissionBackoffs = 5; | 33 static const size_t kMaxHandshakeRetransmissionBackoffs = 5; |
34 static const size_t kMinHandshakeTimeoutMs = 10; | 34 static const size_t kMinHandshakeTimeoutMs = 10; |
35 | 35 |
36 // Sends up to two tail loss probes before firing an RTO, | 36 // Sends up to two tail loss probes before firing an RTO, |
37 // per draft RFC draft-dukkipati-tcpm-tcp-loss-probe. | 37 // per draft RFC draft-dukkipati-tcpm-tcp-loss-probe. |
38 static const size_t kDefaultMaxTailLossProbes = 2; | 38 static const size_t kDefaultMaxTailLossProbes = 2; |
39 static const int64 kMinTailLossProbeTimeoutMs = 10; | 39 static const int64 kMinTailLossProbeTimeoutMs = 10; |
40 | 40 |
41 // Number of samples before we force a new recent min rtt to be captured. | |
42 static const size_t kNumMinRttSamplesAfterQuiescence = 2; | |
43 | |
41 bool HasCryptoHandshake(const TransmissionInfo& transmission_info) { | 44 bool HasCryptoHandshake(const TransmissionInfo& transmission_info) { |
42 if (transmission_info.retransmittable_frames == NULL) { | 45 if (transmission_info.retransmittable_frames == NULL) { |
43 return false; | 46 return false; |
44 } | 47 } |
45 return transmission_info.retransmittable_frames->HasCryptoHandshake() == | 48 return transmission_info.retransmittable_frames->HasCryptoHandshake() == |
46 IS_HANDSHAKE; | 49 IS_HANDSHAKE; |
47 } | 50 } |
48 | 51 |
49 } // namespace | 52 } // namespace |
50 | 53 |
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
164 QuicUnackedPacketMap::const_iterator it = unacked_packets_.begin(); | 167 QuicUnackedPacketMap::const_iterator it = unacked_packets_.begin(); |
165 while (it != unacked_packets_.end()) { | 168 while (it != unacked_packets_.end()) { |
166 QuicPacketSequenceNumber sequence_number = it->first; | 169 QuicPacketSequenceNumber sequence_number = it->first; |
167 if (sequence_number > received_info.largest_observed) { | 170 if (sequence_number > received_info.largest_observed) { |
168 // These packets are still in flight. | 171 // These packets are still in flight. |
169 break; | 172 break; |
170 } | 173 } |
171 | 174 |
172 if (IsAwaitingPacket(received_info, sequence_number)) { | 175 if (IsAwaitingPacket(received_info, sequence_number)) { |
173 // Remove any packets not being tracked by the send algorithm, allowing | 176 // Remove any packets not being tracked by the send algorithm, allowing |
174 // the high water mark to be raised if necessary. | 177 // the high water mark to be raised if necessary. |
wtc
2014/05/19 18:58:40
I'm wondering if this comment needs to be updated,
Ian Swett
2014/05/19 20:20:41
It could be updated. A better comment might be "R
ramant (doing other things)
2014/05/20 03:22:32
Done.
ramant (doing other things)
2014/05/20 03:22:32
Updated the comment per Ian.
| |
175 if (QuicUnackedPacketMap::IsSentAndNotPending(it->second)) { | 178 if (QuicUnackedPacketMap::IsForRttOnly(it->second)) { |
176 it = MarkPacketHandled(sequence_number, delta_largest_observed); | 179 it = MarkPacketHandled(sequence_number, delta_largest_observed); |
177 } else { | 180 } else { |
178 // Consider it multiple nacks when there is a gap between the missing | 181 // Consider it multiple nacks when there is a gap between the missing |
179 // packet and the largest observed, since the purpose of a nack | 182 // packet and the largest observed, since the purpose of a nack |
180 // threshold is to tolerate re-ordering. This handles both StretchAcks | 183 // threshold is to tolerate re-ordering. This handles both StretchAcks |
181 // and Forward Acks. | 184 // and Forward Acks. |
182 // The nack count only increases when the largest observed increases. | 185 // The nack count only increases when the largest observed increases. |
183 size_t min_nacks = received_info.largest_observed - sequence_number; | 186 size_t min_nacks = received_info.largest_observed - sequence_number; |
184 // Truncated acks can nack the largest observed, so use a min of 1. | 187 // Truncated acks can nack the largest observed, so use a min of 1. |
185 if (min_nacks == 0) { | 188 if (min_nacks == 0) { |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
254 for (QuicUnackedPacketMap::const_iterator it = unacked_packets_.begin(); | 257 for (QuicUnackedPacketMap::const_iterator it = unacked_packets_.begin(); |
255 it != unacked_packets_.end(); ++it) { | 258 it != unacked_packets_.end(); ++it) { |
256 const RetransmittableFrames* frames = | 259 const RetransmittableFrames* frames = |
257 it->second.retransmittable_frames; | 260 it->second.retransmittable_frames; |
258 if (frames != NULL && frames->encryption_level() == ENCRYPTION_NONE) { | 261 if (frames != NULL && frames->encryption_level() == ENCRYPTION_NONE) { |
259 // Once you're forward secure, no unencrypted packets will be sent, crypto | 262 // Once you're forward secure, no unencrypted packets will be sent, crypto |
260 // or otherwise. Unencrypted packets are neutered and abandoned, to ensure | 263 // or otherwise. Unencrypted packets are neutered and abandoned, to ensure |
261 // they are not retransmitted or considered lost from a congestion control | 264 // they are not retransmitted or considered lost from a congestion control |
262 // perspective. | 265 // perspective. |
263 pending_retransmissions_.erase(it->first); | 266 pending_retransmissions_.erase(it->first); |
264 // TODO(ianswett): This may cause packets to linger forever in the | |
265 // UnackedPacketMap. | |
266 unacked_packets_.NeuterPacket(it->first); | |
267 unacked_packets_.SetNotPending(it->first); | 267 unacked_packets_.SetNotPending(it->first); |
268 // TODO(ianswett): Clean this up so UnackedPacketMap maintains the correct | |
269 // invariants between the various transmissions for NeuterPacket. | |
270 SequenceNumberSet all_transmissions = *it->second.all_transmissions; | |
271 for (SequenceNumberSet::const_iterator all_it = all_transmissions.begin(); | |
272 all_it != all_transmissions.end(); ++all_it) { | |
273 unacked_packets_.NeuterPacket(*all_it); | |
274 } | |
268 } | 275 } |
269 } | 276 } |
270 } | 277 } |
271 | 278 |
272 void QuicSentPacketManager::MarkForRetransmission( | 279 void QuicSentPacketManager::MarkForRetransmission( |
273 QuicPacketSequenceNumber sequence_number, | 280 QuicPacketSequenceNumber sequence_number, |
274 TransmissionType transmission_type) { | 281 TransmissionType transmission_type) { |
275 const TransmissionInfo& transmission_info = | 282 const TransmissionInfo& transmission_info = |
276 unacked_packets_.GetTransmissionInfo(sequence_number); | 283 unacked_packets_.GetTransmissionInfo(sequence_number); |
277 LOG_IF(DFATAL, transmission_info.retransmittable_frames == NULL); | 284 LOG_IF(DFATAL, transmission_info.retransmittable_frames == NULL); |
(...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
433 TransmissionType transmission_type, | 440 TransmissionType transmission_type, |
434 HasRetransmittableData has_retransmittable_data) { | 441 HasRetransmittableData has_retransmittable_data) { |
435 DCHECK_LT(0u, sequence_number); | 442 DCHECK_LT(0u, sequence_number); |
436 LOG_IF(DFATAL, bytes == 0) << "Cannot send empty packets."; | 443 LOG_IF(DFATAL, bytes == 0) << "Cannot send empty packets."; |
437 // In rare circumstances, the packet could be serialized, sent, and then acked | 444 // In rare circumstances, the packet could be serialized, sent, and then acked |
438 // before OnPacketSent is called. | 445 // before OnPacketSent is called. |
439 if (!unacked_packets_.IsUnacked(sequence_number)) { | 446 if (!unacked_packets_.IsUnacked(sequence_number)) { |
440 return false; | 447 return false; |
441 } | 448 } |
442 | 449 |
443 // Only track packets as pending that the send algorithm wants us to track. | 450 if (unacked_packets_.bytes_in_flight() == 0) { |
444 if (!send_algorithm_->OnPacketSent(sent_time, | 451 // TODO(ianswett): Consider being less aggressive to force a new |
445 unacked_packets_.bytes_in_flight(), | 452 // recent_min_rtt, likely by not discarding a relatively new sample. |
446 sequence_number, | 453 DVLOG(1) << "Sampling a new recent min rtt within 2 samples. currently:" |
447 bytes, | 454 << rtt_stats_.recent_min_rtt().ToMilliseconds() << "ms"; |
448 has_retransmittable_data)) { | 455 rtt_stats_.SampleNewRecentMinRtt(kNumMinRttSamplesAfterQuiescence); |
449 unacked_packets_.SetSent(sequence_number, sent_time, bytes, false); | |
450 // Do not reset the retransmission timer, since the packet isn't tracked. | |
451 return false; | |
452 } | 456 } |
453 | 457 |
454 const bool set_retransmission_timer = !unacked_packets_.HasPendingPackets(); | 458 // Only track packets as pending that the send algorithm wants us to track. |
459 const bool pending = | |
460 send_algorithm_->OnPacketSent(sent_time, | |
461 unacked_packets_.bytes_in_flight(), | |
462 sequence_number, | |
463 bytes, | |
464 has_retransmittable_data); | |
465 unacked_packets_.SetSent(sequence_number, sent_time, bytes, pending); | |
455 | 466 |
456 unacked_packets_.SetSent(sequence_number, sent_time, bytes, true); | 467 // Reset the retransmission timer anytime a pending packet is sent. |
457 | 468 return pending; |
458 // Reset the retransmission timer anytime a packet is sent in tail loss probe | |
459 // mode or before the crypto handshake has completed. | |
460 return set_retransmission_timer || GetRetransmissionMode() != RTO_MODE; | |
461 } | 469 } |
462 | 470 |
463 void QuicSentPacketManager::OnRetransmissionTimeout() { | 471 void QuicSentPacketManager::OnRetransmissionTimeout() { |
464 DCHECK(unacked_packets_.HasPendingPackets()); | 472 DCHECK(unacked_packets_.HasPendingPackets()); |
465 // Handshake retransmission, timer based loss detection, TLP, and RTO are | 473 // Handshake retransmission, timer based loss detection, TLP, and RTO are |
466 // implemented with a single alarm. The handshake alarm is set when the | 474 // implemented with a single alarm. The handshake alarm is set when the |
467 // handshake has not completed, the loss alarm is set when the loss detection | 475 // handshake has not completed, the loss alarm is set when the loss detection |
468 // algorithm says to, and the TLP and RTO alarms are set after that. | 476 // algorithm says to, and the TLP and RTO alarms are set after that. |
469 // The TLP alarm is always set to run for under an RTO. | 477 // The TLP alarm is always set to run for under an RTO. |
470 switch (GetRetransmissionMode()) { | 478 switch (GetRetransmissionMode()) { |
(...skipping 295 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
766 return; | 774 return; |
767 } | 775 } |
768 | 776 |
769 using_pacing_ = true; | 777 using_pacing_ = true; |
770 send_algorithm_.reset( | 778 send_algorithm_.reset( |
771 new PacingSender(send_algorithm_.release(), | 779 new PacingSender(send_algorithm_.release(), |
772 QuicTime::Delta::FromMicroseconds(1))); | 780 QuicTime::Delta::FromMicroseconds(1))); |
773 } | 781 } |
774 | 782 |
775 } // namespace net | 783 } // namespace net |
OLD | NEW |