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 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
71 is_server_(is_server), | 71 is_server_(is_server), |
72 clock_(clock), | 72 clock_(clock), |
73 stats_(stats), | 73 stats_(stats), |
74 debug_delegate_(nullptr), | 74 debug_delegate_(nullptr), |
75 network_change_visitor_(nullptr), | 75 network_change_visitor_(nullptr), |
76 send_algorithm_(SendAlgorithmInterface::Create(clock, | 76 send_algorithm_(SendAlgorithmInterface::Create(clock, |
77 &rtt_stats_, | 77 &rtt_stats_, |
78 congestion_control_type, | 78 congestion_control_type, |
79 stats)), | 79 stats)), |
80 loss_algorithm_(LossDetectionInterface::Create(loss_type)), | 80 loss_algorithm_(LossDetectionInterface::Create(loss_type)), |
| 81 receive_buffer_bytes_(kDefaultSocketReceiveBuffer), |
81 least_packet_awaited_by_peer_(1), | 82 least_packet_awaited_by_peer_(1), |
82 first_rto_transmission_(0), | 83 first_rto_transmission_(0), |
83 consecutive_rto_count_(0), | 84 consecutive_rto_count_(0), |
84 consecutive_tlp_count_(0), | 85 consecutive_tlp_count_(0), |
85 consecutive_crypto_retransmission_count_(0), | 86 consecutive_crypto_retransmission_count_(0), |
86 pending_timer_transmission_count_(0), | 87 pending_timer_transmission_count_(0), |
87 max_tail_loss_probes_(kDefaultMaxTailLossProbes), | 88 max_tail_loss_probes_(kDefaultMaxTailLossProbes), |
88 using_pacing_(false), | 89 using_pacing_(false), |
89 handshake_confirmed_(false) { | 90 handshake_confirmed_(false) { |
90 } | 91 } |
91 | 92 |
92 QuicSentPacketManager::~QuicSentPacketManager() { | 93 QuicSentPacketManager::~QuicSentPacketManager() { |
93 } | 94 } |
94 | 95 |
95 void QuicSentPacketManager::SetFromConfig(const QuicConfig& config) { | 96 void QuicSentPacketManager::SetFromConfig(const QuicConfig& config) { |
96 if (config.HasReceivedInitialRoundTripTimeUs() && | 97 if (config.HasReceivedInitialRoundTripTimeUs() && |
97 config.ReceivedInitialRoundTripTimeUs() > 0) { | 98 config.ReceivedInitialRoundTripTimeUs() > 0) { |
98 rtt_stats_.set_initial_rtt_us(min(kMaxInitialRoundTripTimeUs, | 99 rtt_stats_.set_initial_rtt_us(min(kMaxInitialRoundTripTimeUs, |
99 config.ReceivedInitialRoundTripTimeUs())); | 100 config.ReceivedInitialRoundTripTimeUs())); |
100 } else if (config.HasInitialRoundTripTimeUsToSend()) { | 101 } else if (config.HasInitialRoundTripTimeUsToSend()) { |
101 rtt_stats_.set_initial_rtt_us( | 102 rtt_stats_.set_initial_rtt_us( |
102 min(kMaxInitialRoundTripTimeUs, | 103 min(kMaxInitialRoundTripTimeUs, |
103 config.GetInitialRoundTripTimeUsToSend())); | 104 config.GetInitialRoundTripTimeUsToSend())); |
104 } | 105 } |
105 // TODO(ianswett): BBR is currently a server only feature. | 106 // TODO(ianswett): BBR is currently a server only feature. |
106 if (config.HasReceivedConnectionOptions() && | 107 if (FLAGS_quic_allow_bbr && |
| 108 config.HasReceivedConnectionOptions() && |
107 ContainsQuicTag(config.ReceivedConnectionOptions(), kTBBR)) { | 109 ContainsQuicTag(config.ReceivedConnectionOptions(), kTBBR)) { |
108 if (FLAGS_quic_recent_min_rtt_window_s > 0) { | 110 if (FLAGS_quic_recent_min_rtt_window_s > 0) { |
109 rtt_stats_.set_recent_min_rtt_window( | 111 rtt_stats_.set_recent_min_rtt_window( |
110 QuicTime::Delta::FromSeconds(FLAGS_quic_recent_min_rtt_window_s)); | 112 QuicTime::Delta::FromSeconds(FLAGS_quic_recent_min_rtt_window_s)); |
111 } | 113 } |
112 send_algorithm_.reset( | 114 send_algorithm_.reset( |
113 SendAlgorithmInterface::Create(clock_, &rtt_stats_, kBBR, stats_)); | 115 SendAlgorithmInterface::Create(clock_, &rtt_stats_, kBBR, stats_)); |
114 } | 116 } |
115 if (config.HasReceivedConnectionOptions() && | 117 if (config.HasReceivedConnectionOptions() && |
116 ContainsQuicTag(config.ReceivedConnectionOptions(), kRENO)) { | 118 ContainsQuicTag(config.ReceivedConnectionOptions(), kRENO)) { |
117 send_algorithm_.reset( | 119 send_algorithm_.reset( |
118 SendAlgorithmInterface::Create(clock_, &rtt_stats_, kReno, stats_)); | 120 SendAlgorithmInterface::Create(clock_, &rtt_stats_, kReno, stats_)); |
119 } | 121 } |
120 if (HasClientSentConnectionOption(config, kPACE)) { | 122 if (HasClientSentConnectionOption(config, kPACE)) { |
121 EnablePacing(); | 123 EnablePacing(); |
122 } | 124 } |
123 if (HasClientSentConnectionOption(config, k1CON)) { | 125 if (HasClientSentConnectionOption(config, k1CON)) { |
124 send_algorithm_->SetNumEmulatedConnections(1); | 126 send_algorithm_->SetNumEmulatedConnections(1); |
125 } | 127 } |
| 128 if (HasClientSentConnectionOption(config, kNTLP)) { |
| 129 max_tail_loss_probes_ = 0; |
| 130 } |
126 if (config.HasReceivedConnectionOptions() && | 131 if (config.HasReceivedConnectionOptions() && |
127 ContainsQuicTag(config.ReceivedConnectionOptions(), kTIME)) { | 132 ContainsQuicTag(config.ReceivedConnectionOptions(), kTIME)) { |
128 loss_algorithm_.reset(LossDetectionInterface::Create(kTime)); | 133 loss_algorithm_.reset(LossDetectionInterface::Create(kTime)); |
129 } | 134 } |
| 135 if (config.HasReceivedSocketReceiveBuffer()) { |
| 136 receive_buffer_bytes_ = |
| 137 max(kMinSocketReceiveBuffer, |
| 138 static_cast<QuicByteCount>(config.ReceivedSocketReceiveBuffer())); |
| 139 } |
130 send_algorithm_->SetFromConfig(config, is_server_); | 140 send_algorithm_->SetFromConfig(config, is_server_); |
131 | 141 |
132 if (network_change_visitor_ != nullptr) { | 142 if (network_change_visitor_ != nullptr) { |
133 network_change_visitor_->OnCongestionWindowChange(GetCongestionWindow()); | 143 network_change_visitor_->OnCongestionWindowChange(GetCongestionWindow()); |
134 } | 144 } |
135 } | 145 } |
136 | 146 |
137 bool QuicSentPacketManager::HasClientSentConnectionOption( | 147 bool QuicSentPacketManager::HasClientSentConnectionOption( |
138 const QuicConfig& config, QuicTag tag) const { | 148 const QuicConfig& config, QuicTag tag) const { |
139 if (is_server_) { | 149 if (is_server_) { |
(...skipping 517 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
657 if (unacked_packets_.HasUnackedRetransmittableFrames()) { | 667 if (unacked_packets_.HasUnackedRetransmittableFrames()) { |
658 return TLP_MODE; | 668 return TLP_MODE; |
659 } | 669 } |
660 } | 670 } |
661 return RTO_MODE; | 671 return RTO_MODE; |
662 } | 672 } |
663 | 673 |
664 void QuicSentPacketManager::OnIncomingQuicCongestionFeedbackFrame( | 674 void QuicSentPacketManager::OnIncomingQuicCongestionFeedbackFrame( |
665 const QuicCongestionFeedbackFrame& frame, | 675 const QuicCongestionFeedbackFrame& frame, |
666 const QuicTime& feedback_receive_time) { | 676 const QuicTime& feedback_receive_time) { |
667 send_algorithm_->OnIncomingQuicCongestionFeedbackFrame( | 677 if (frame.type == kTCP) { |
668 frame, feedback_receive_time); | 678 receive_buffer_bytes_ = frame.tcp.receive_window; |
| 679 } |
669 } | 680 } |
670 | 681 |
671 void QuicSentPacketManager::InvokeLossDetection(QuicTime time) { | 682 void QuicSentPacketManager::InvokeLossDetection(QuicTime time) { |
672 SequenceNumberSet lost_packets = | 683 SequenceNumberSet lost_packets = |
673 loss_algorithm_->DetectLostPackets(unacked_packets_, | 684 loss_algorithm_->DetectLostPackets(unacked_packets_, |
674 time, | 685 time, |
675 unacked_packets_.largest_observed(), | 686 unacked_packets_.largest_observed(), |
676 rtt_stats_); | 687 rtt_stats_); |
677 for (SequenceNumberSet::const_iterator it = lost_packets.begin(); | 688 for (SequenceNumberSet::const_iterator it = lost_packets.begin(); |
678 it != lost_packets.end(); ++it) { | 689 it != lost_packets.end(); ++it) { |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
723 } | 734 } |
724 | 735 |
725 QuicTime::Delta QuicSentPacketManager::TimeUntilSend( | 736 QuicTime::Delta QuicSentPacketManager::TimeUntilSend( |
726 QuicTime now, | 737 QuicTime now, |
727 HasRetransmittableData retransmittable) { | 738 HasRetransmittableData retransmittable) { |
728 // The TLP logic is entirely contained within QuicSentPacketManager, so the | 739 // The TLP logic is entirely contained within QuicSentPacketManager, so the |
729 // send algorithm does not need to be consulted. | 740 // send algorithm does not need to be consulted. |
730 if (pending_timer_transmission_count_ > 0) { | 741 if (pending_timer_transmission_count_ > 0) { |
731 return QuicTime::Delta::Zero(); | 742 return QuicTime::Delta::Zero(); |
732 } | 743 } |
| 744 if (unacked_packets_.bytes_in_flight() >= receive_buffer_bytes_) { |
| 745 return QuicTime::Delta::Infinite(); |
| 746 } |
733 return send_algorithm_->TimeUntilSend( | 747 return send_algorithm_->TimeUntilSend( |
734 now, unacked_packets_.bytes_in_flight(), retransmittable); | 748 now, unacked_packets_.bytes_in_flight(), retransmittable); |
735 } | 749 } |
736 | 750 |
737 // Uses a 25ms delayed ack timer. Also helps with better signaling | 751 // Uses a 25ms delayed ack timer. Also helps with better signaling |
738 // in low-bandwidth (< ~384 kbps), where an ack is sent per packet. | 752 // in low-bandwidth (< ~384 kbps), where an ack is sent per packet. |
739 // Ensures that the Delayed Ack timer is always set to a value lesser | 753 // Ensures that the Delayed Ack timer is always set to a value lesser |
740 // than the retransmission timer's minimum value (MinRTO). We want the | 754 // than the retransmission timer's minimum value (MinRTO). We want the |
741 // delayed ack to get back to the QUIC peer before the sender's | 755 // delayed ack to get back to the QUIC peer before the sender's |
742 // retransmission timer triggers. Since we do not know the | 756 // retransmission timer triggers. Since we do not know the |
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
868 // Set up a pacing sender with a 1 millisecond alarm granularity, the same as | 882 // Set up a pacing sender with a 1 millisecond alarm granularity, the same as |
869 // the default granularity of the Linux kernel's FQ qdisc. | 883 // the default granularity of the Linux kernel's FQ qdisc. |
870 using_pacing_ = true; | 884 using_pacing_ = true; |
871 send_algorithm_.reset( | 885 send_algorithm_.reset( |
872 new PacingSender(send_algorithm_.release(), | 886 new PacingSender(send_algorithm_.release(), |
873 QuicTime::Delta::FromMilliseconds(1), | 887 QuicTime::Delta::FromMilliseconds(1), |
874 kInitialUnpacedBurst)); | 888 kInitialUnpacedBurst)); |
875 } | 889 } |
876 | 890 |
877 } // namespace net | 891 } // namespace net |
OLD | NEW |