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::NeuterUnencryptedPackets() { | 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()) { |
257 const RetransmittableFrames* frames = | 256 const RetransmittableFrames* frames = |
(...skipping 12 matching lines...) Expand all Loading... |
270 ++unacked_it; | 269 ++unacked_it; |
271 } | 270 } |
272 } | 271 } |
273 | 272 |
274 void QuicSentPacketManager::MarkForRetransmission( | 273 void QuicSentPacketManager::MarkForRetransmission( |
275 QuicPacketSequenceNumber sequence_number, | 274 QuicPacketSequenceNumber sequence_number, |
276 TransmissionType transmission_type) { | 275 TransmissionType transmission_type) { |
277 const TransmissionInfo& transmission_info = | 276 const TransmissionInfo& transmission_info = |
278 unacked_packets_.GetTransmissionInfo(sequence_number); | 277 unacked_packets_.GetTransmissionInfo(sequence_number); |
279 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 } |
280 // 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 |
281 // retransmissions for the same data, which is not ideal. | 283 // retransmissions for the same data, which is not ideal. |
282 if (ContainsKey(pending_retransmissions_, sequence_number)) { | 284 if (ContainsKey(pending_retransmissions_, sequence_number)) { |
283 return; | 285 return; |
284 } | 286 } |
285 | 287 |
286 pending_retransmissions_[sequence_number] = transmission_type; | 288 pending_retransmissions_[sequence_number] = transmission_type; |
287 } | 289 } |
288 | 290 |
289 bool QuicSentPacketManager::HasPendingRetransmissions() const { | 291 bool QuicSentPacketManager::HasPendingRetransmissions() const { |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
348 | 350 |
349 QuicUnackedPacketMap::const_iterator QuicSentPacketManager::MarkPacketHandled( | 351 QuicUnackedPacketMap::const_iterator QuicSentPacketManager::MarkPacketHandled( |
350 QuicPacketSequenceNumber sequence_number, | 352 QuicPacketSequenceNumber sequence_number, |
351 QuicTime::Delta delta_largest_observed) { | 353 QuicTime::Delta delta_largest_observed) { |
352 if (!unacked_packets_.IsUnacked(sequence_number)) { | 354 if (!unacked_packets_.IsUnacked(sequence_number)) { |
353 LOG(DFATAL) << "Packet is not unacked: " << sequence_number; | 355 LOG(DFATAL) << "Packet is not unacked: " << sequence_number; |
354 return unacked_packets_.end(); | 356 return unacked_packets_.end(); |
355 } | 357 } |
356 const TransmissionInfo& transmission_info = | 358 const TransmissionInfo& transmission_info = |
357 unacked_packets_.GetTransmissionInfo(sequence_number); | 359 unacked_packets_.GetTransmissionInfo(sequence_number); |
358 // If this packet is pending, remove it and inform the send algorithm. | 360 // If this packet is pending, remove it. |
359 if (transmission_info.pending) { | 361 if (transmission_info.pending) { |
360 unacked_packets_.SetNotPending(sequence_number); | 362 unacked_packets_.SetNotPending(sequence_number); |
361 } | 363 } |
362 | 364 |
363 SequenceNumberSet all_transmissions = *transmission_info.all_transmissions; | 365 SequenceNumberSet all_transmissions = *transmission_info.all_transmissions; |
364 SequenceNumberSet::reverse_iterator all_transmissions_it = | 366 SequenceNumberSet::reverse_iterator all_transmissions_it = |
365 all_transmissions.rbegin(); | 367 all_transmissions.rbegin(); |
366 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. |
367 if (newest_transmission != sequence_number) { | 376 if (newest_transmission != sequence_number) { |
368 stats_->bytes_spuriously_retransmitted += transmission_info.bytes_sent; | 377 stats_->bytes_spuriously_retransmitted += transmission_info.bytes_sent; |
369 ++stats_->packets_spuriously_retransmitted; | 378 ++stats_->packets_spuriously_retransmitted; |
370 } | 379 } |
371 | 380 |
372 // The AckNotifierManager needs to be notified about the most recent | 381 // The AckNotifierManager needs to be notified about the most recent |
373 // transmission, since that's the one only one it tracks. | 382 // transmission, since that's the one only one it tracks. |
374 ack_notifier_manager_.OnPacketAcked(newest_transmission, | 383 ack_notifier_manager_.OnPacketAcked(newest_transmission, |
375 delta_largest_observed); | 384 delta_largest_observed); |
376 | 385 |
| 386 // TODO(ianswett): Instead of handling all crypto packets in a special way, |
| 387 // only handle NULL encrypted packets in a special way. |
377 bool has_crypto_handshake = HasCryptoHandshake( | 388 bool has_crypto_handshake = HasCryptoHandshake( |
378 unacked_packets_.GetTransmissionInfo(newest_transmission)); | 389 unacked_packets_.GetTransmissionInfo(newest_transmission)); |
379 while (all_transmissions_it != all_transmissions.rend()) { | 390 while (all_transmissions_it != all_transmissions.rend()) { |
380 QuicPacketSequenceNumber previous_transmission = *all_transmissions_it; | 391 QuicPacketSequenceNumber previous_transmission = *all_transmissions_it; |
381 const TransmissionInfo& transmission_info = | 392 const TransmissionInfo& transmission_info = |
382 unacked_packets_.GetTransmissionInfo(previous_transmission); | 393 unacked_packets_.GetTransmissionInfo(previous_transmission); |
383 // If this packet was marked for retransmission, don't bother retransmitting | 394 DCHECK(!ContainsKey(pending_retransmissions_, previous_transmission)); |
384 // it anymore. | |
385 pending_retransmissions_.erase(previous_transmission); | |
386 if (has_crypto_handshake) { | 395 if (has_crypto_handshake) { |
387 // 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, |
388 // 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. |
389 unacked_packets_.SetNotPending(previous_transmission); | 398 unacked_packets_.SetNotPending(previous_transmission); |
390 } | 399 } |
391 if (!transmission_info.pending) { | 400 if (!transmission_info.pending) { |
392 unacked_packets_.RemovePacket(previous_transmission); | 401 unacked_packets_.RemovePacket(previous_transmission); |
393 } else { | 402 } else { |
394 unacked_packets_.NeuterPacket(previous_transmission); | 403 unacked_packets_.NeuterPacket(previous_transmission); |
395 } | 404 } |
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
495 it != unacked_packets_.end(); ++it) { | 504 it != unacked_packets_.end(); ++it) { |
496 QuicPacketSequenceNumber sequence_number = it->first; | 505 QuicPacketSequenceNumber sequence_number = it->first; |
497 const RetransmittableFrames* frames = it->second.retransmittable_frames; | 506 const RetransmittableFrames* frames = it->second.retransmittable_frames; |
498 // Only retransmit frames which are pending, and therefore have been sent. | 507 // Only retransmit frames which are pending, and therefore have been sent. |
499 if (!it->second.pending || frames == NULL || | 508 if (!it->second.pending || frames == NULL || |
500 frames->HasCryptoHandshake() != IS_HANDSHAKE) { | 509 frames->HasCryptoHandshake() != IS_HANDSHAKE) { |
501 continue; | 510 continue; |
502 } | 511 } |
503 packet_retransmitted = true; | 512 packet_retransmitted = true; |
504 MarkForRetransmission(sequence_number, HANDSHAKE_RETRANSMISSION); | 513 MarkForRetransmission(sequence_number, HANDSHAKE_RETRANSMISSION); |
505 // Abandon all the crypto retransmissions now so they're not lost later. | |
506 unacked_packets_.SetNotPending(sequence_number); | |
507 } | 514 } |
508 DCHECK(packet_retransmitted) << "No crypto packets found to retransmit."; | 515 DCHECK(packet_retransmitted) << "No crypto packets found to retransmit."; |
509 } | 516 } |
510 | 517 |
511 void QuicSentPacketManager::RetransmitOldestPacket() { | 518 void QuicSentPacketManager::RetransmitOldestPacket() { |
512 DCHECK_EQ(TLP_MODE, GetRetransmissionMode()); | 519 DCHECK_EQ(TLP_MODE, GetRetransmissionMode()); |
513 ++consecutive_tlp_count_; | 520 ++consecutive_tlp_count_; |
514 for (QuicUnackedPacketMap::const_iterator it = unacked_packets_.begin(); | 521 for (QuicUnackedPacketMap::const_iterator it = unacked_packets_.begin(); |
515 it != unacked_packets_.end(); ++it) { | 522 it != unacked_packets_.end(); ++it) { |
516 QuicPacketSequenceNumber sequence_number = it->first; | 523 QuicPacketSequenceNumber sequence_number = it->first; |
(...skipping 17 matching lines...) Expand all Loading... |
534 DVLOG(1) << "OnRetransmissionTimeout() fired with " | 541 DVLOG(1) << "OnRetransmissionTimeout() fired with " |
535 << unacked_packets_.GetNumUnackedPackets() << " unacked packets."; | 542 << unacked_packets_.GetNumUnackedPackets() << " unacked packets."; |
536 | 543 |
537 // Request retransmission of all retransmittable packets when the RTO | 544 // Request retransmission of all retransmittable packets when the RTO |
538 // fires, and let the congestion manager decide how many to send | 545 // fires, and let the congestion manager decide how many to send |
539 // immediately and the remaining packets will be queued. | 546 // immediately and the remaining packets will be queued. |
540 // Abandon any non-retransmittable packets that are sufficiently old. | 547 // Abandon any non-retransmittable packets that are sufficiently old. |
541 bool packets_retransmitted = false; | 548 bool packets_retransmitted = false; |
542 for (QuicUnackedPacketMap::const_iterator it = unacked_packets_.begin(); | 549 for (QuicUnackedPacketMap::const_iterator it = unacked_packets_.begin(); |
543 it != unacked_packets_.end(); ++it) { | 550 it != unacked_packets_.end(); ++it) { |
544 unacked_packets_.SetNotPending(it->first); | |
545 if (it->second.retransmittable_frames != NULL) { | 551 if (it->second.retransmittable_frames != NULL) { |
546 packets_retransmitted = true; | 552 packets_retransmitted = true; |
547 MarkForRetransmission(it->first, RTO_RETRANSMISSION); | 553 MarkForRetransmission(it->first, RTO_RETRANSMISSION); |
| 554 } else { |
| 555 unacked_packets_.SetNotPending(it->first); |
548 } | 556 } |
549 } | 557 } |
550 | 558 |
551 send_algorithm_->OnRetransmissionTimeout(packets_retransmitted); | 559 send_algorithm_->OnRetransmissionTimeout(packets_retransmitted); |
552 if (packets_retransmitted) { | 560 if (packets_retransmitted) { |
553 ++consecutive_rto_count_; | 561 ++consecutive_rto_count_; |
554 } | 562 } |
555 } | 563 } |
556 | 564 |
557 QuicSentPacketManager::RetransmissionTimeoutMode | 565 QuicSentPacketManager::RetransmissionTimeoutMode |
(...skipping 29 matching lines...) Expand all Loading... |
587 for (SequenceNumberSet::const_iterator it = lost_packets.begin(); | 595 for (SequenceNumberSet::const_iterator it = lost_packets.begin(); |
588 it != lost_packets.end(); ++it) { | 596 it != lost_packets.end(); ++it) { |
589 QuicPacketSequenceNumber sequence_number = *it; | 597 QuicPacketSequenceNumber sequence_number = *it; |
590 const TransmissionInfo& transmission_info = | 598 const TransmissionInfo& transmission_info = |
591 unacked_packets_.GetTransmissionInfo(sequence_number); | 599 unacked_packets_.GetTransmissionInfo(sequence_number); |
592 // 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 |
593 // 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 |
594 // until it's known whether the FEC packet arrived. | 602 // until it's known whether the FEC packet arrived. |
595 ++stats_->packets_lost; | 603 ++stats_->packets_lost; |
596 packets_lost_[sequence_number] = transmission_info; | 604 packets_lost_[sequence_number] = transmission_info; |
597 unacked_packets_.SetNotPending(sequence_number); | |
598 | 605 |
599 if (transmission_info.retransmittable_frames != NULL) { | 606 if (transmission_info.retransmittable_frames != NULL) { |
600 MarkForRetransmission(sequence_number, LOSS_RETRANSMISSION); | 607 MarkForRetransmission(sequence_number, LOSS_RETRANSMISSION); |
601 } else { | 608 } else { |
602 // Since we will not retransmit this, we need to remove it from | 609 // Since we will not retransmit this, we need to remove it from |
603 // unacked_packets_. This is either the current transmission of | 610 // unacked_packets_. This is either the current transmission of |
604 // a packet whose previous transmission has been acked, or it | 611 // a packet whose previous transmission has been acked, a packet that has |
605 // is a packet that has been TLP retransmitted. | 612 // been TLP retransmitted, or an FEC packet. |
| 613 unacked_packets_.SetNotPending(sequence_number); |
606 unacked_packets_.RemovePacket(sequence_number); | 614 unacked_packets_.RemovePacket(sequence_number); |
607 } | 615 } |
608 } | 616 } |
609 } | 617 } |
610 | 618 |
611 bool QuicSentPacketManager::MaybeUpdateRTT( | 619 bool QuicSentPacketManager::MaybeUpdateRTT( |
612 const ReceivedPacketInfo& received_info, | 620 const ReceivedPacketInfo& received_info, |
613 const QuicTime& ack_receive_time) { | 621 const QuicTime& ack_receive_time) { |
614 if (!unacked_packets_.IsUnacked(received_info.largest_observed)) { | 622 if (!unacked_packets_.IsUnacked(received_info.largest_observed)) { |
615 return false; | 623 return false; |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
668 case HANDSHAKE_MODE: | 676 case HANDSHAKE_MODE: |
669 return clock_->ApproximateNow().Add(GetCryptoRetransmissionDelay()); | 677 return clock_->ApproximateNow().Add(GetCryptoRetransmissionDelay()); |
670 case LOSS_MODE: | 678 case LOSS_MODE: |
671 return loss_algorithm_->GetLossTimeout(); | 679 return loss_algorithm_->GetLossTimeout(); |
672 case TLP_MODE: { | 680 case TLP_MODE: { |
673 // TODO(ianswett): When CWND is available, it would be preferable to | 681 // TODO(ianswett): When CWND is available, it would be preferable to |
674 // set the timer based on the earliest retransmittable packet. | 682 // set the timer based on the earliest retransmittable packet. |
675 // Base the updated timer on the send time of the last packet. | 683 // Base the updated timer on the send time of the last packet. |
676 const QuicTime sent_time = unacked_packets_.GetLastPacketSentTime(); | 684 const QuicTime sent_time = unacked_packets_.GetLastPacketSentTime(); |
677 const QuicTime tlp_time = sent_time.Add(GetTailLossProbeDelay()); | 685 const QuicTime tlp_time = sent_time.Add(GetTailLossProbeDelay()); |
678 // Ensure the tlp timer never gets set to a time in the past. | 686 // Ensure the TLP timer never gets set to a time in the past. |
679 return QuicTime::Max(clock_->ApproximateNow(), tlp_time); | 687 return QuicTime::Max(clock_->ApproximateNow(), tlp_time); |
680 } | 688 } |
681 case RTO_MODE: { | 689 case RTO_MODE: { |
682 // The RTO is based on the first pending packet. | 690 // The RTO is based on the first pending packet. |
683 const QuicTime sent_time = | 691 const QuicTime sent_time = |
684 unacked_packets_.GetFirstPendingPacketSentTime(); | 692 unacked_packets_.GetFirstPendingPacketSentTime(); |
685 QuicTime rto_timeout = sent_time.Add(GetRetransmissionDelay()); | 693 QuicTime rto_timeout = sent_time.Add(GetRetransmissionDelay()); |
686 // Always wait at least 1.5 * RTT from now. | 694 // Always wait at least 1.5 * RTT from now. |
687 QuicTime min_timeout = clock_->ApproximateNow().Add( | 695 QuicTime min_timeout = clock_->ApproximateNow().Add( |
688 rtt_stats_.SmoothedRtt().Multiply(1.5)); | 696 rtt_stats_.SmoothedRtt().Multiply(1.5)); |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
758 return; | 766 return; |
759 } | 767 } |
760 | 768 |
761 using_pacing_ = true; | 769 using_pacing_ = true; |
762 send_algorithm_.reset( | 770 send_algorithm_.reset( |
763 new PacingSender(send_algorithm_.release(), | 771 new PacingSender(send_algorithm_.release(), |
764 QuicTime::Delta::FromMicroseconds(1))); | 772 QuicTime::Delta::FromMicroseconds(1))); |
765 } | 773 } |
766 | 774 |
767 } // namespace net | 775 } // namespace net |
OLD | NEW |