Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(231)

Side by Side Diff: net/quic/quic_sent_packet_manager.cc

Issue 188333003: Land Recent QUIC Changes. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix compilation error - added NET_EXPORT_PRIVATE to QuicFixedUint32 Created 6 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « net/quic/quic_sent_packet_manager.h ('k') | net/quic/quic_sent_packet_manager_test.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 "base/logging.h" 7 #include "base/logging.h"
8 #include "base/stl_util.h" 8 #include "base/stl_util.h"
9 #include "net/quic/congestion_control/pacing_sender.h" 9 #include "net/quic/congestion_control/pacing_sender.h"
10 #include "net/quic/crypto/crypto_protocol.h" 10 #include "net/quic/crypto/crypto_protocol.h"
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
60 } 60 }
61 61
62 } // namespace 62 } // namespace
63 63
64 #define ENDPOINT (is_server_ ? "Server: " : " Client: ") 64 #define ENDPOINT (is_server_ ? "Server: " : " Client: ")
65 65
66 QuicSentPacketManager::QuicSentPacketManager(bool is_server, 66 QuicSentPacketManager::QuicSentPacketManager(bool is_server,
67 const QuicClock* clock, 67 const QuicClock* clock,
68 QuicConnectionStats* stats, 68 QuicConnectionStats* stats,
69 CongestionFeedbackType type) 69 CongestionFeedbackType type)
70 : unacked_packets_(is_server), 70 : unacked_packets_(),
71 is_server_(is_server), 71 is_server_(is_server),
72 clock_(clock), 72 clock_(clock),
73 stats_(stats), 73 stats_(stats),
74 send_algorithm_(SendAlgorithmInterface::Create(clock, type, stats)), 74 send_algorithm_(
75 SendAlgorithmInterface::Create(clock, &rtt_stats_, type, stats)),
75 loss_algorithm_(LossDetectionInterface::Create()), 76 loss_algorithm_(LossDetectionInterface::Create()),
76 rtt_sample_(QuicTime::Delta::Infinite()),
77 largest_observed_(0), 77 largest_observed_(0),
78 pending_crypto_packet_count_(0),
79 consecutive_rto_count_(0), 78 consecutive_rto_count_(0),
80 consecutive_tlp_count_(0), 79 consecutive_tlp_count_(0),
81 consecutive_crypto_retransmission_count_(0), 80 consecutive_crypto_retransmission_count_(0),
82 max_tail_loss_probes_(kDefaultMaxTailLossProbes), 81 max_tail_loss_probes_(kDefaultMaxTailLossProbes),
83 using_pacing_(false) { 82 using_pacing_(false) {
84 } 83 }
85 84
86 QuicSentPacketManager::~QuicSentPacketManager() { 85 QuicSentPacketManager::~QuicSentPacketManager() {
87 } 86 }
88 87
89 void QuicSentPacketManager::SetFromConfig(const QuicConfig& config) { 88 void QuicSentPacketManager::SetFromConfig(const QuicConfig& config) {
90 if (config.initial_round_trip_time_us() > 0 && 89 if (config.initial_round_trip_time_us() > 0) {
91 rtt_sample_.IsInfinite()) {
92 // The initial rtt should already be set on the client side. 90 // The initial rtt should already be set on the client side.
93 DVLOG_IF(1, !is_server_) 91 DVLOG_IF(1, !is_server_)
94 << "Client did not set an initial RTT, but did negotiate one."; 92 << "Client did not set an initial RTT, but did negotiate one.";
95 rtt_sample_ = 93 rtt_stats_.set_initial_rtt_us(config.initial_round_trip_time_us());
96 QuicTime::Delta::FromMicroseconds(config.initial_round_trip_time_us());
97 send_algorithm_->UpdateRtt(rtt_sample_);
98 } 94 }
99 if (config.congestion_control() == kPACE) { 95 if (config.congestion_control() == kPACE) {
100 MaybeEnablePacing(); 96 MaybeEnablePacing();
101 } 97 }
102 send_algorithm_->SetFromConfig(config, is_server_); 98 send_algorithm_->SetFromConfig(config, is_server_);
103 } 99 }
104 100
105 // TODO(ianswett): Combine this method with OnPacketSent once packets are always 101 // TODO(ianswett): Combine this method with OnPacketSent once packets are always
106 // sent in order and the connection tracks RetransmittableFrames for longer. 102 // sent in order and the connection tracks RetransmittableFrames for longer.
107 void QuicSentPacketManager::OnSerializedPacket( 103 void QuicSentPacketManager::OnSerializedPacket(
108 const SerializedPacket& serialized_packet) { 104 const SerializedPacket& serialized_packet) {
109 if (serialized_packet.retransmittable_frames) { 105 if (serialized_packet.retransmittable_frames) {
110 ack_notifier_manager_.OnSerializedPacket(serialized_packet); 106 ack_notifier_manager_.OnSerializedPacket(serialized_packet);
111
112 if (serialized_packet.retransmittable_frames->HasCryptoHandshake()
113 == IS_HANDSHAKE) {
114 ++pending_crypto_packet_count_;
115 }
116 } 107 }
117 108
118 unacked_packets_.AddPacket(serialized_packet); 109 unacked_packets_.AddPacket(serialized_packet);
119 } 110 }
120 111
121 void QuicSentPacketManager::OnRetransmittedPacket( 112 void QuicSentPacketManager::OnRetransmittedPacket(
122 QuicPacketSequenceNumber old_sequence_number, 113 QuicPacketSequenceNumber old_sequence_number,
123 QuicPacketSequenceNumber new_sequence_number) { 114 QuicPacketSequenceNumber new_sequence_number) {
124 DCHECK(ContainsKey(pending_retransmissions_, old_sequence_number)); 115 DCHECK(ContainsKey(pending_retransmissions_, old_sequence_number));
125 116
(...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after
306 } 297 }
307 298
308 SequenceNumberSet all_transmissions = *transmission_info.all_transmissions; 299 SequenceNumberSet all_transmissions = *transmission_info.all_transmissions;
309 SequenceNumberSet::reverse_iterator all_transmissions_it = 300 SequenceNumberSet::reverse_iterator all_transmissions_it =
310 all_transmissions.rbegin(); 301 all_transmissions.rbegin();
311 QuicPacketSequenceNumber newest_transmission = *all_transmissions_it; 302 QuicPacketSequenceNumber newest_transmission = *all_transmissions_it;
312 if (newest_transmission != sequence_number) { 303 if (newest_transmission != sequence_number) {
313 ++stats_->packets_spuriously_retransmitted; 304 ++stats_->packets_spuriously_retransmitted;
314 } 305 }
315 306
316 bool has_cryto_handshake = HasCryptoHandshake( 307 bool has_crypto_handshake = HasCryptoHandshake(
317 unacked_packets_.GetTransmissionInfo(newest_transmission)); 308 unacked_packets_.GetTransmissionInfo(newest_transmission));
318 if (has_cryto_handshake) {
319 --pending_crypto_packet_count_;
320 }
321 while (all_transmissions_it != all_transmissions.rend()) { 309 while (all_transmissions_it != all_transmissions.rend()) {
322 QuicPacketSequenceNumber previous_transmission = *all_transmissions_it; 310 QuicPacketSequenceNumber previous_transmission = *all_transmissions_it;
323 const QuicUnackedPacketMap::TransmissionInfo& transmission_info = 311 const QuicUnackedPacketMap::TransmissionInfo& transmission_info =
324 unacked_packets_.GetTransmissionInfo(previous_transmission); 312 unacked_packets_.GetTransmissionInfo(previous_transmission);
325 if (ContainsKey(pending_retransmissions_, previous_transmission)) { 313 if (ContainsKey(pending_retransmissions_, previous_transmission)) {
326 // Don't bother retransmitting this packet, if it has been 314 // Don't bother retransmitting this packet, if it has been
327 // marked for retransmission. 315 // marked for retransmission.
328 pending_retransmissions_.erase(previous_transmission); 316 pending_retransmissions_.erase(previous_transmission);
329 } 317 }
330 if (has_cryto_handshake) { 318 if (has_crypto_handshake) {
331 // If it's a crypto handshake packet, discard it and all retransmissions, 319 // If it's a crypto handshake packet, discard it and all retransmissions,
332 // since they won't be acked now that one has been processed. 320 // since they won't be acked now that one has been processed.
333 if (transmission_info.pending) { 321 if (transmission_info.pending) {
334 OnPacketAbandoned(previous_transmission); 322 OnPacketAbandoned(previous_transmission);
335 } 323 }
336 unacked_packets_.SetNotPending(previous_transmission); 324 unacked_packets_.SetNotPending(previous_transmission);
337 } 325 }
338 if (!transmission_info.pending) { 326 if (!transmission_info.pending) {
339 unacked_packets_.RemovePacket(previous_transmission); 327 unacked_packets_.RemovePacket(previous_transmission);
340 } else { 328 } else {
(...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after
492 480
493 send_algorithm_->OnRetransmissionTimeout(packets_retransmitted); 481 send_algorithm_->OnRetransmissionTimeout(packets_retransmitted);
494 if (packets_retransmitted) { 482 if (packets_retransmitted) {
495 ++consecutive_rto_count_; 483 ++consecutive_rto_count_;
496 } 484 }
497 } 485 }
498 486
499 QuicSentPacketManager::RetransmissionTimeoutMode 487 QuicSentPacketManager::RetransmissionTimeoutMode
500 QuicSentPacketManager::GetRetransmissionMode() const { 488 QuicSentPacketManager::GetRetransmissionMode() const {
501 DCHECK(unacked_packets_.HasPendingPackets()); 489 DCHECK(unacked_packets_.HasPendingPackets());
502 if (pending_crypto_packet_count_ > 0) { 490 if (unacked_packets_.HasPendingCryptoPackets()) {
503 return HANDSHAKE_MODE; 491 return HANDSHAKE_MODE;
504 } 492 }
505 if (loss_algorithm_->GetLossTimeout() != QuicTime::Zero()) { 493 if (loss_algorithm_->GetLossTimeout() != QuicTime::Zero()) {
506 return LOSS_MODE; 494 return LOSS_MODE;
507 } 495 }
508 if (consecutive_tlp_count_ < max_tail_loss_probes_) { 496 if (consecutive_tlp_count_ < max_tail_loss_probes_) {
509 if (unacked_packets_.HasUnackedRetransmittableFrames()) { 497 if (unacked_packets_.HasUnackedRetransmittableFrames()) {
510 return TLP_MODE; 498 return TLP_MODE;
511 } 499 }
512 } 500 }
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
555 } 543 }
556 544
557 InvokeLossDetection(ack_receive_time); 545 InvokeLossDetection(ack_receive_time);
558 } 546 }
559 547
560 void QuicSentPacketManager::InvokeLossDetection(QuicTime time) { 548 void QuicSentPacketManager::InvokeLossDetection(QuicTime time) {
561 SequenceNumberSet lost_packets = 549 SequenceNumberSet lost_packets =
562 loss_algorithm_->DetectLostPackets(unacked_packets_, 550 loss_algorithm_->DetectLostPackets(unacked_packets_,
563 time, 551 time,
564 largest_observed_, 552 largest_observed_,
565 send_algorithm_->SmoothedRtt(), 553 rtt_stats_);
566 rtt_sample_);
567 for (SequenceNumberSet::const_iterator it = lost_packets.begin(); 554 for (SequenceNumberSet::const_iterator it = lost_packets.begin();
568 it != lost_packets.end(); ++it) { 555 it != lost_packets.end(); ++it) {
569 QuicPacketSequenceNumber sequence_number = *it; 556 QuicPacketSequenceNumber sequence_number = *it;
570 // TODO(ianswett): If it's expected the FEC packet may repair the loss, it 557 // TODO(ianswett): If it's expected the FEC packet may repair the loss, it
571 // should be recorded as a loss to the send algorithm, but not retransmitted 558 // should be recorded as a loss to the send algorithm, but not retransmitted
572 // until it's known whether the FEC packet arrived. 559 // until it's known whether the FEC packet arrived.
573 ++stats_->packets_lost; 560 ++stats_->packets_lost;
574 send_algorithm_->OnPacketLost(sequence_number, time); 561 send_algorithm_->OnPacketLost(sequence_number, time);
575 OnPacketAbandoned(sequence_number); 562 OnPacketAbandoned(sequence_number);
576 563
(...skipping 19 matching lines...) Expand all
596 // sequence numbers will include the ACK aggregation delay. 583 // sequence numbers will include the ACK aggregation delay.
597 const QuicUnackedPacketMap::TransmissionInfo& transmission_info = 584 const QuicUnackedPacketMap::TransmissionInfo& transmission_info =
598 unacked_packets_.GetTransmissionInfo(received_info.largest_observed); 585 unacked_packets_.GetTransmissionInfo(received_info.largest_observed);
599 // Don't update the RTT if it hasn't been sent. 586 // Don't update the RTT if it hasn't been sent.
600 if (transmission_info.sent_time == QuicTime::Zero()) { 587 if (transmission_info.sent_time == QuicTime::Zero()) {
601 return; 588 return;
602 } 589 }
603 590
604 QuicTime::Delta send_delta = 591 QuicTime::Delta send_delta =
605 ack_receive_time.Subtract(transmission_info.sent_time); 592 ack_receive_time.Subtract(transmission_info.sent_time);
606 if (send_delta > received_info.delta_time_largest_observed) { 593 rtt_stats_.UpdateRtt(send_delta, received_info.delta_time_largest_observed);
607 rtt_sample_ = send_delta.Subtract( 594 send_algorithm_->UpdateRtt(rtt_stats_.latest_rtt());
608 received_info.delta_time_largest_observed);
609 } else if (rtt_sample_.IsInfinite()) {
610 // Even though we received information from the peer suggesting
611 // an invalid (negative) RTT, we can use the send delta as an
612 // approximation until we get a better estimate.
613 rtt_sample_ = send_delta;
614 }
615 send_algorithm_->UpdateRtt(rtt_sample_);
616 } 595 }
617 596
618 QuicTime::Delta QuicSentPacketManager::TimeUntilSend( 597 QuicTime::Delta QuicSentPacketManager::TimeUntilSend(
619 QuicTime now, 598 QuicTime now,
620 TransmissionType transmission_type, 599 TransmissionType transmission_type,
621 HasRetransmittableData retransmittable, 600 HasRetransmittableData retransmittable,
622 IsHandshake handshake) { 601 IsHandshake handshake) {
623 return send_algorithm_->TimeUntilSend(now, transmission_type, retransmittable, 602 return send_algorithm_->TimeUntilSend(now, transmission_type, retransmittable,
624 handshake); 603 handshake);
625 } 604 }
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
659 // of the last pending packet which still has retransmittable frames. 638 // of the last pending packet which still has retransmittable frames.
660 const QuicTime sent_time = unacked_packets_.GetLastPacketSentTime(); 639 const QuicTime sent_time = unacked_packets_.GetLastPacketSentTime();
661 const QuicTime tlp_time = sent_time.Add(GetTailLossProbeDelay()); 640 const QuicTime tlp_time = sent_time.Add(GetTailLossProbeDelay());
662 // Ensure the tlp timer never gets set to a time in the past. 641 // Ensure the tlp timer never gets set to a time in the past.
663 return QuicTime::Max(clock_->ApproximateNow(), tlp_time); 642 return QuicTime::Max(clock_->ApproximateNow(), tlp_time);
664 } 643 }
665 case RTO_MODE: { 644 case RTO_MODE: {
666 // The RTO is based on the first pending packet. 645 // The RTO is based on the first pending packet.
667 const QuicTime sent_time = 646 const QuicTime sent_time =
668 unacked_packets_.GetFirstPendingPacketSentTime(); 647 unacked_packets_.GetFirstPendingPacketSentTime();
669 // Always wait at least 1.5 * RTT after the first sent packet. 648 QuicTime rto_timeout = sent_time.Add(GetRetransmissionDelay());
649 // Always wait at least 1.5 * RTT from now.
670 QuicTime min_timeout = clock_->ApproximateNow().Add( 650 QuicTime min_timeout = clock_->ApproximateNow().Add(
671 SmoothedRtt().Multiply(1.5)); 651 SmoothedRtt().Multiply(1.5));
672 QuicTime rto_timeout = sent_time.Add(GetRetransmissionDelay());
673 652
674 return QuicTime::Max(min_timeout, rto_timeout); 653 return QuicTime::Max(min_timeout, rto_timeout);
675 } 654 }
676 } 655 }
677 DCHECK(false); 656 DCHECK(false);
678 return QuicTime::Zero(); 657 return QuicTime::Zero();
679 } 658 }
680 659
681 const QuicTime::Delta QuicSentPacketManager::GetCryptoRetransmissionDelay() 660 const QuicTime::Delta QuicSentPacketManager::GetCryptoRetransmissionDelay()
682 const { 661 const {
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
715 retransmission_delay = retransmission_delay.Multiply( 694 retransmission_delay = retransmission_delay.Multiply(
716 1 << min<size_t>(consecutive_rto_count_, kMaxRetransmissions)); 695 1 << min<size_t>(consecutive_rto_count_, kMaxRetransmissions));
717 696
718 if (retransmission_delay.ToMilliseconds() > kMaxRetransmissionTimeMs) { 697 if (retransmission_delay.ToMilliseconds() > kMaxRetransmissionTimeMs) {
719 return QuicTime::Delta::FromMilliseconds(kMaxRetransmissionTimeMs); 698 return QuicTime::Delta::FromMilliseconds(kMaxRetransmissionTimeMs);
720 } 699 }
721 return retransmission_delay; 700 return retransmission_delay;
722 } 701 }
723 702
724 const QuicTime::Delta QuicSentPacketManager::SmoothedRtt() const { 703 const QuicTime::Delta QuicSentPacketManager::SmoothedRtt() const {
725 return send_algorithm_->SmoothedRtt(); 704 return rtt_stats_.SmoothedRtt();
726 } 705 }
727 706
728 QuicBandwidth QuicSentPacketManager::BandwidthEstimate() const { 707 QuicBandwidth QuicSentPacketManager::BandwidthEstimate() const {
729 return send_algorithm_->BandwidthEstimate(); 708 return send_algorithm_->BandwidthEstimate();
730 } 709 }
731 710
732 QuicByteCount QuicSentPacketManager::GetCongestionWindow() const { 711 QuicByteCount QuicSentPacketManager::GetCongestionWindow() const {
733 return send_algorithm_->GetCongestionWindow(); 712 return send_algorithm_->GetCongestionWindow();
734 } 713 }
735 714
736 void QuicSentPacketManager::MaybeEnablePacing() { 715 void QuicSentPacketManager::MaybeEnablePacing() {
737 if (!FLAGS_enable_quic_pacing) { 716 if (!FLAGS_enable_quic_pacing) {
738 return; 717 return;
739 } 718 }
740 719
741 if (using_pacing_) { 720 if (using_pacing_) {
742 return; 721 return;
743 } 722 }
744 723
745 using_pacing_ = true; 724 using_pacing_ = true;
746 send_algorithm_.reset( 725 send_algorithm_.reset(
747 new PacingSender(send_algorithm_.release(), 726 new PacingSender(send_algorithm_.release(),
748 QuicTime::Delta::FromMicroseconds(1))); 727 QuicTime::Delta::FromMicroseconds(1)));
749 } 728 }
750 729
751 } // namespace net 730 } // namespace net
OLDNEW
« no previous file with comments | « net/quic/quic_sent_packet_manager.h ('k') | net/quic/quic_sent_packet_manager_test.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698