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 226 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
237 continue; | 237 continue; |
238 } | 238 } |
239 // If it had no other transmissions, we handle it above. If it has | 239 // If it had no other transmissions, we handle it above. If it has |
240 // other transmissions, one of them must have retransmittable frames, | 240 // other transmissions, one of them must have retransmittable frames, |
241 // so that gets resolved the same way as other retransmissions. | 241 // so that gets resolved the same way as other retransmissions. |
242 // TODO(ianswett): Consider adding a new retransmission type which removes | 242 // TODO(ianswett): Consider adding a new retransmission type which removes |
243 // all these old packets from unacked and retransmits them as new sequence | 243 // all these old packets from unacked and retransmits them as new sequence |
244 // numbers with no connection to the previous ones. | 244 // numbers with no connection to the previous ones. |
245 if (frames != NULL && (retransmission_type == ALL_PACKETS || | 245 if (frames != NULL && (retransmission_type == ALL_PACKETS || |
246 frames->encryption_level() == ENCRYPTION_INITIAL)) { | 246 frames->encryption_level() == ENCRYPTION_INITIAL)) { |
247 unacked_packets_.SetNotPending(unacked_it->first); | |
248 MarkForRetransmission(unacked_it->first, ALL_UNACKED_RETRANSMISSION); | 247 MarkForRetransmission(unacked_it->first, ALL_UNACKED_RETRANSMISSION); |
249 } | 248 } |
250 ++unacked_it; | 249 ++unacked_it; |
251 } | 250 } |
252 } | 251 } |
253 | 252 |
254 void QuicSentPacketManager::DiscardUnencryptedPackets() { | 253 void QuicSentPacketManager::NeuterUnencryptedPackets() { |
255 QuicUnackedPacketMap::const_iterator unacked_it = unacked_packets_.begin(); | 254 QuicUnackedPacketMap::const_iterator unacked_it = unacked_packets_.begin(); |
256 while (unacked_it != unacked_packets_.end()) { | 255 while (unacked_it != unacked_packets_.end()) { |
wtc
2014/05/13 18:49:23
Nit: in the new code, this loop can be a for loop
ramant (doing other things)
2014/05/14 05:33:29
Made this change in https://codereview.chromium.or
| |
257 const RetransmittableFrames* frames = | 256 const RetransmittableFrames* frames = |
258 unacked_it->second.retransmittable_frames; | 257 unacked_it->second.retransmittable_frames; |
259 if (frames != NULL && frames->encryption_level() == ENCRYPTION_NONE) { | 258 if (frames != NULL && frames->encryption_level() == ENCRYPTION_NONE) { |
260 // Once you're forward secure, no unencrypted packets will be sent. | 259 // Since once you're forward secure, no unencrypted packets will be sent, |
wtc
2014/05/13 18:49:23
Nit: "Since" and "once" sound a little redundant.
ramant (doing other things)
2014/05/14 05:33:29
Made this change in https://codereview.chromium.or
| |
261 // Additionally, it's likely the peer will be forward secure, and no acks | 260 // crypto or otherwise. Unencrypted packets are neutered and abandoned, to |
262 // for these packets will be received, so mark the packet as handled. | 261 // ensure they are not retransmitted or considered lost from a congestion |
262 // control perspective. | |
263 pending_retransmissions_.erase(unacked_it->first); | 263 pending_retransmissions_.erase(unacked_it->first); |
264 unacked_it = MarkPacketHandled(unacked_it->first, | 264 // TODO(ianswett): This may cause packets to linger forever in the |
265 QuicTime::Delta::Zero()); | 265 // UnackedPacketMap. |
266 continue; | 266 unacked_packets_.NeuterPacket(unacked_it->first); |
267 unacked_packets_.SetNotPending(unacked_it->first); | |
267 } | 268 } |
268 ++unacked_it; | 269 ++unacked_it; |
269 } | 270 } |
270 } | 271 } |
271 | 272 |
272 void QuicSentPacketManager::MarkForRetransmission( | 273 void QuicSentPacketManager::MarkForRetransmission( |
273 QuicPacketSequenceNumber sequence_number, | 274 QuicPacketSequenceNumber sequence_number, |
274 TransmissionType transmission_type) { | 275 TransmissionType transmission_type) { |
275 const TransmissionInfo& transmission_info = | 276 const TransmissionInfo& transmission_info = |
276 unacked_packets_.GetTransmissionInfo(sequence_number); | 277 unacked_packets_.GetTransmissionInfo(sequence_number); |
277 LOG_IF(DFATAL, transmission_info.retransmittable_frames == NULL); | 278 LOG_IF(DFATAL, transmission_info.retransmittable_frames == NULL); |
279 if (transmission_type != TLP_RETRANSMISSION) { | |
280 unacked_packets_.SetNotPending(sequence_number); | |
281 } | |
278 // TODO(ianswett): Currently the RTO can fire while there are pending NACK | 282 // TODO(ianswett): Currently the RTO can fire while there are pending NACK |
279 // retransmissions for the same data, which is not ideal. | 283 // retransmissions for the same data, which is not ideal. |
280 if (ContainsKey(pending_retransmissions_, sequence_number)) { | 284 if (ContainsKey(pending_retransmissions_, sequence_number)) { |
281 return; | 285 return; |
282 } | 286 } |
283 | 287 |
284 pending_retransmissions_[sequence_number] = transmission_type; | 288 pending_retransmissions_[sequence_number] = transmission_type; |
285 } | 289 } |
286 | 290 |
287 bool QuicSentPacketManager::HasPendingRetransmissions() const { | 291 bool QuicSentPacketManager::HasPendingRetransmissions() const { |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
330 | 334 |
331 const TransmissionInfo& transmission_info = | 335 const TransmissionInfo& transmission_info = |
332 unacked_packets_.GetTransmissionInfo(sequence_number); | 336 unacked_packets_.GetTransmissionInfo(sequence_number); |
333 // The AckNotifierManager needs to be notified for revived packets, | 337 // The AckNotifierManager needs to be notified for revived packets, |
334 // since it indicates the packet arrived from the appliction's perspective. | 338 // since it indicates the packet arrived from the appliction's perspective. |
335 if (transmission_info.retransmittable_frames) { | 339 if (transmission_info.retransmittable_frames) { |
336 ack_notifier_manager_.OnPacketAcked( | 340 ack_notifier_manager_.OnPacketAcked( |
337 sequence_number, delta_largest_observed); | 341 sequence_number, delta_largest_observed); |
338 } | 342 } |
339 | 343 |
340 unacked_packets_.NeuterIfPendingOrRemovePacket(sequence_number); | 344 if (!transmission_info.pending) { |
345 unacked_packets_.RemovePacket(sequence_number); | |
346 } else { | |
347 unacked_packets_.NeuterPacket(sequence_number); | |
348 } | |
341 } | 349 } |
342 | 350 |
343 QuicUnackedPacketMap::const_iterator QuicSentPacketManager::MarkPacketHandled( | 351 QuicUnackedPacketMap::const_iterator QuicSentPacketManager::MarkPacketHandled( |
344 QuicPacketSequenceNumber sequence_number, | 352 QuicPacketSequenceNumber sequence_number, |
345 QuicTime::Delta delta_largest_observed) { | 353 QuicTime::Delta delta_largest_observed) { |
346 if (!unacked_packets_.IsUnacked(sequence_number)) { | 354 if (!unacked_packets_.IsUnacked(sequence_number)) { |
347 LOG(DFATAL) << "Packet is not unacked: " << sequence_number; | 355 LOG(DFATAL) << "Packet is not unacked: " << sequence_number; |
348 return unacked_packets_.end(); | 356 return unacked_packets_.end(); |
349 } | 357 } |
350 const TransmissionInfo& transmission_info = | 358 const TransmissionInfo& transmission_info = |
351 unacked_packets_.GetTransmissionInfo(sequence_number); | 359 unacked_packets_.GetTransmissionInfo(sequence_number); |
352 // If this packet is pending, remove it and inform the send algorithm. | 360 // If this packet is pending, remove it. |
353 if (transmission_info.pending) { | 361 if (transmission_info.pending) { |
354 unacked_packets_.SetNotPending(sequence_number); | 362 unacked_packets_.SetNotPending(sequence_number); |
355 } | 363 } |
356 | 364 |
357 SequenceNumberSet all_transmissions = *transmission_info.all_transmissions; | 365 SequenceNumberSet all_transmissions = *transmission_info.all_transmissions; |
358 SequenceNumberSet::reverse_iterator all_transmissions_it = | 366 SequenceNumberSet::reverse_iterator all_transmissions_it = |
359 all_transmissions.rbegin(); | 367 all_transmissions.rbegin(); |
360 QuicPacketSequenceNumber newest_transmission = *all_transmissions_it; | 368 QuicPacketSequenceNumber newest_transmission = *all_transmissions_it; |
369 // Remove the most recent packet, if it is pending retransmission. | |
370 pending_retransmissions_.erase(newest_transmission); | |
371 | |
372 // Two cases for MarkPacketHandled: | |
373 // 1) Handle the most recent or a crypto packet, so remove all transmissions. | |
374 // 2) Handle old transmission, keep all other pending transmissions, | |
375 // but disassociate them from one another. | |
361 if (newest_transmission != sequence_number) { | 376 if (newest_transmission != sequence_number) { |
362 stats_->bytes_spuriously_retransmitted += transmission_info.bytes_sent; | 377 stats_->bytes_spuriously_retransmitted += transmission_info.bytes_sent; |
363 ++stats_->packets_spuriously_retransmitted; | 378 ++stats_->packets_spuriously_retransmitted; |
364 } | 379 } |
365 | 380 |
366 // The AckNotifierManager needs to be notified about the most recent | 381 // The AckNotifierManager needs to be notified about the most recent |
367 // transmission, since that's the one only one it tracks. | 382 // transmission, since that's the one only one it tracks. |
368 ack_notifier_manager_.OnPacketAcked(newest_transmission, | 383 ack_notifier_manager_.OnPacketAcked(newest_transmission, |
369 delta_largest_observed); | 384 delta_largest_observed); |
370 | 385 |
386 // TODO(ianswett): Instead of handling all crypto packets in a special way, | |
387 // only handle NULL encrypted packets in a special way. | |
371 bool has_crypto_handshake = HasCryptoHandshake( | 388 bool has_crypto_handshake = HasCryptoHandshake( |
372 unacked_packets_.GetTransmissionInfo(newest_transmission)); | 389 unacked_packets_.GetTransmissionInfo(newest_transmission)); |
373 while (all_transmissions_it != all_transmissions.rend()) { | 390 while (all_transmissions_it != all_transmissions.rend()) { |
374 QuicPacketSequenceNumber previous_transmission = *all_transmissions_it; | 391 QuicPacketSequenceNumber previous_transmission = *all_transmissions_it; |
375 // If this packet was marked for retransmission, don't bother retransmitting | 392 const TransmissionInfo& transmission_info = |
376 // it anymore. | 393 unacked_packets_.GetTransmissionInfo(previous_transmission); |
377 pending_retransmissions_.erase(previous_transmission); | 394 DCHECK(!ContainsKey(pending_retransmissions_, previous_transmission)); |
378 if (has_crypto_handshake) { | 395 if (has_crypto_handshake) { |
379 // If it's a crypto handshake packet, discard it and all retransmissions, | 396 // If it's a crypto handshake packet, discard it and all retransmissions, |
380 // since they won't be acked now that one has been processed. | 397 // since they won't be acked now that one has been processed. |
381 unacked_packets_.SetNotPending(previous_transmission); | 398 unacked_packets_.SetNotPending(previous_transmission); |
382 } | 399 } |
383 unacked_packets_.NeuterIfPendingOrRemovePacket(previous_transmission); | 400 if (!transmission_info.pending) { |
401 unacked_packets_.RemovePacket(previous_transmission); | |
402 } else { | |
403 unacked_packets_.NeuterPacket(previous_transmission); | |
404 } | |
384 ++all_transmissions_it; | 405 ++all_transmissions_it; |
385 } | 406 } |
386 | 407 |
387 QuicUnackedPacketMap::const_iterator next_unacked = unacked_packets_.begin(); | 408 QuicUnackedPacketMap::const_iterator next_unacked = unacked_packets_.begin(); |
388 while (next_unacked != unacked_packets_.end() && | 409 while (next_unacked != unacked_packets_.end() && |
389 next_unacked->first < sequence_number) { | 410 next_unacked->first < sequence_number) { |
390 ++next_unacked; | 411 ++next_unacked; |
391 } | 412 } |
392 return next_unacked; | 413 return next_unacked; |
393 } | 414 } |
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
483 it != unacked_packets_.end(); ++it) { | 504 it != unacked_packets_.end(); ++it) { |
484 QuicPacketSequenceNumber sequence_number = it->first; | 505 QuicPacketSequenceNumber sequence_number = it->first; |
485 const RetransmittableFrames* frames = it->second.retransmittable_frames; | 506 const RetransmittableFrames* frames = it->second.retransmittable_frames; |
486 // Only retransmit frames which are pending, and therefore have been sent. | 507 // Only retransmit frames which are pending, and therefore have been sent. |
487 if (!it->second.pending || frames == NULL || | 508 if (!it->second.pending || frames == NULL || |
488 frames->HasCryptoHandshake() != IS_HANDSHAKE) { | 509 frames->HasCryptoHandshake() != IS_HANDSHAKE) { |
489 continue; | 510 continue; |
490 } | 511 } |
491 packet_retransmitted = true; | 512 packet_retransmitted = true; |
492 MarkForRetransmission(sequence_number, HANDSHAKE_RETRANSMISSION); | 513 MarkForRetransmission(sequence_number, HANDSHAKE_RETRANSMISSION); |
493 // Abandon all the crypto retransmissions now so they're not lost later. | |
494 unacked_packets_.SetNotPending(sequence_number); | |
495 } | 514 } |
496 DCHECK(packet_retransmitted) << "No crypto packets found to retransmit."; | 515 DCHECK(packet_retransmitted) << "No crypto packets found to retransmit."; |
497 } | 516 } |
498 | 517 |
499 void QuicSentPacketManager::RetransmitOldestPacket() { | 518 void QuicSentPacketManager::RetransmitOldestPacket() { |
500 DCHECK_EQ(TLP_MODE, GetRetransmissionMode()); | 519 DCHECK_EQ(TLP_MODE, GetRetransmissionMode()); |
501 ++consecutive_tlp_count_; | 520 ++consecutive_tlp_count_; |
502 for (QuicUnackedPacketMap::const_iterator it = unacked_packets_.begin(); | 521 for (QuicUnackedPacketMap::const_iterator it = unacked_packets_.begin(); |
503 it != unacked_packets_.end(); ++it) { | 522 it != unacked_packets_.end(); ++it) { |
504 QuicPacketSequenceNumber sequence_number = it->first; | 523 QuicPacketSequenceNumber sequence_number = it->first; |
(...skipping 17 matching lines...) Expand all Loading... | |
522 DVLOG(1) << "OnRetransmissionTimeout() fired with " | 541 DVLOG(1) << "OnRetransmissionTimeout() fired with " |
523 << unacked_packets_.GetNumUnackedPackets() << " unacked packets."; | 542 << unacked_packets_.GetNumUnackedPackets() << " unacked packets."; |
524 | 543 |
525 // Request retransmission of all retransmittable packets when the RTO | 544 // Request retransmission of all retransmittable packets when the RTO |
526 // fires, and let the congestion manager decide how many to send | 545 // fires, and let the congestion manager decide how many to send |
527 // immediately and the remaining packets will be queued. | 546 // immediately and the remaining packets will be queued. |
528 // Abandon any non-retransmittable packets that are sufficiently old. | 547 // Abandon any non-retransmittable packets that are sufficiently old. |
529 bool packets_retransmitted = false; | 548 bool packets_retransmitted = false; |
530 for (QuicUnackedPacketMap::const_iterator it = unacked_packets_.begin(); | 549 for (QuicUnackedPacketMap::const_iterator it = unacked_packets_.begin(); |
531 it != unacked_packets_.end(); ++it) { | 550 it != unacked_packets_.end(); ++it) { |
532 unacked_packets_.SetNotPending(it->first); | |
533 if (it->second.retransmittable_frames != NULL) { | 551 if (it->second.retransmittable_frames != NULL) { |
534 packets_retransmitted = true; | 552 packets_retransmitted = true; |
535 MarkForRetransmission(it->first, RTO_RETRANSMISSION); | 553 MarkForRetransmission(it->first, RTO_RETRANSMISSION); |
554 } else { | |
555 unacked_packets_.SetNotPending(it->first); | |
536 } | 556 } |
537 } | 557 } |
538 | 558 |
539 send_algorithm_->OnRetransmissionTimeout(packets_retransmitted); | 559 send_algorithm_->OnRetransmissionTimeout(packets_retransmitted); |
540 if (packets_retransmitted) { | 560 if (packets_retransmitted) { |
541 ++consecutive_rto_count_; | 561 ++consecutive_rto_count_; |
542 } | 562 } |
543 } | 563 } |
544 | 564 |
545 QuicSentPacketManager::RetransmissionTimeoutMode | 565 QuicSentPacketManager::RetransmissionTimeoutMode |
(...skipping 29 matching lines...) Expand all Loading... | |
575 for (SequenceNumberSet::const_iterator it = lost_packets.begin(); | 595 for (SequenceNumberSet::const_iterator it = lost_packets.begin(); |
576 it != lost_packets.end(); ++it) { | 596 it != lost_packets.end(); ++it) { |
577 QuicPacketSequenceNumber sequence_number = *it; | 597 QuicPacketSequenceNumber sequence_number = *it; |
578 const TransmissionInfo& transmission_info = | 598 const TransmissionInfo& transmission_info = |
579 unacked_packets_.GetTransmissionInfo(sequence_number); | 599 unacked_packets_.GetTransmissionInfo(sequence_number); |
580 // TODO(ianswett): If it's expected the FEC packet may repair the loss, it | 600 // TODO(ianswett): If it's expected the FEC packet may repair the loss, it |
581 // should be recorded as a loss to the send algorithm, but not retransmitted | 601 // should be recorded as a loss to the send algorithm, but not retransmitted |
582 // until it's known whether the FEC packet arrived. | 602 // until it's known whether the FEC packet arrived. |
583 ++stats_->packets_lost; | 603 ++stats_->packets_lost; |
584 packets_lost_[sequence_number] = transmission_info; | 604 packets_lost_[sequence_number] = transmission_info; |
585 unacked_packets_.SetNotPending(sequence_number); | 605 DVLOG(1) << ENDPOINT << "Lost packet " << sequence_number; |
586 | 606 |
587 if (transmission_info.retransmittable_frames != NULL) { | 607 if (transmission_info.retransmittable_frames != NULL) { |
588 MarkForRetransmission(sequence_number, LOSS_RETRANSMISSION); | 608 MarkForRetransmission(sequence_number, LOSS_RETRANSMISSION); |
589 } else { | 609 } else { |
590 // Since we will not retransmit this, we need to remove it from | 610 // Since we will not retransmit this, we need to remove it from |
591 // unacked_packets_. This is either the current transmission of | 611 // unacked_packets_. This is either the current transmission of |
592 // a packet whose previous transmission has been acked, or it | 612 // a packet whose previous transmission has been acked, a packet that has |
593 // is a packet that has been TLP retransmitted. | 613 // been TLP retransmitted, or an FEC packet. |
594 unacked_packets_.NeuterIfPendingOrRemovePacket(sequence_number); | 614 unacked_packets_.SetNotPending(sequence_number); |
615 unacked_packets_.RemovePacket(sequence_number); | |
595 } | 616 } |
596 } | 617 } |
597 } | 618 } |
598 | 619 |
599 bool QuicSentPacketManager::MaybeUpdateRTT( | 620 bool QuicSentPacketManager::MaybeUpdateRTT( |
600 const ReceivedPacketInfo& received_info, | 621 const ReceivedPacketInfo& received_info, |
601 const QuicTime& ack_receive_time) { | 622 const QuicTime& ack_receive_time) { |
602 if (!unacked_packets_.IsUnacked(received_info.largest_observed)) { | 623 if (!unacked_packets_.IsUnacked(received_info.largest_observed)) { |
603 return false; | 624 return false; |
604 } | 625 } |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
656 case HANDSHAKE_MODE: | 677 case HANDSHAKE_MODE: |
657 return clock_->ApproximateNow().Add(GetCryptoRetransmissionDelay()); | 678 return clock_->ApproximateNow().Add(GetCryptoRetransmissionDelay()); |
658 case LOSS_MODE: | 679 case LOSS_MODE: |
659 return loss_algorithm_->GetLossTimeout(); | 680 return loss_algorithm_->GetLossTimeout(); |
660 case TLP_MODE: { | 681 case TLP_MODE: { |
661 // TODO(ianswett): When CWND is available, it would be preferable to | 682 // TODO(ianswett): When CWND is available, it would be preferable to |
662 // set the timer based on the earliest retransmittable packet. | 683 // set the timer based on the earliest retransmittable packet. |
663 // Base the updated timer on the send time of the last packet. | 684 // Base the updated timer on the send time of the last packet. |
664 const QuicTime sent_time = unacked_packets_.GetLastPacketSentTime(); | 685 const QuicTime sent_time = unacked_packets_.GetLastPacketSentTime(); |
665 const QuicTime tlp_time = sent_time.Add(GetTailLossProbeDelay()); | 686 const QuicTime tlp_time = sent_time.Add(GetTailLossProbeDelay()); |
666 // Ensure the tlp timer never gets set to a time in the past. | 687 // Ensure the TLP timer never gets set to a time in the past. |
667 return QuicTime::Max(clock_->ApproximateNow(), tlp_time); | 688 return QuicTime::Max(clock_->ApproximateNow(), tlp_time); |
668 } | 689 } |
669 case RTO_MODE: { | 690 case RTO_MODE: { |
670 // The RTO is based on the first pending packet. | 691 // The RTO is based on the first pending packet. |
671 const QuicTime sent_time = | 692 const QuicTime sent_time = |
672 unacked_packets_.GetFirstPendingPacketSentTime(); | 693 unacked_packets_.GetFirstPendingPacketSentTime(); |
673 QuicTime rto_timeout = sent_time.Add(GetRetransmissionDelay()); | 694 QuicTime rto_timeout = sent_time.Add(GetRetransmissionDelay()); |
674 // Always wait at least 1.5 * RTT from now. | 695 // Always wait at least 1.5 * RTT from now. |
675 QuicTime min_timeout = clock_->ApproximateNow().Add( | 696 QuicTime min_timeout = clock_->ApproximateNow().Add( |
676 rtt_stats_.SmoothedRtt().Multiply(1.5)); | 697 rtt_stats_.SmoothedRtt().Multiply(1.5)); |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
746 return; | 767 return; |
747 } | 768 } |
748 | 769 |
749 using_pacing_ = true; | 770 using_pacing_ = true; |
750 send_algorithm_.reset( | 771 send_algorithm_.reset( |
751 new PacingSender(send_algorithm_.release(), | 772 new PacingSender(send_algorithm_.release(), |
752 QuicTime::Delta::FromMicroseconds(1))); | 773 QuicTime::Delta::FromMicroseconds(1))); |
753 } | 774 } |
754 | 775 |
755 } // namespace net | 776 } // namespace net |
OLD | NEW |