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 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
156 loss_algorithm_.reset(new GeneralLossAlgorithm(kTime)); | 156 loss_algorithm_.reset(new GeneralLossAlgorithm(kTime)); |
157 } | 157 } |
158 if (config.HasReceivedConnectionOptions() && | 158 if (config.HasReceivedConnectionOptions() && |
159 ContainsQuicTag(config.ReceivedConnectionOptions(), kATIM)) { | 159 ContainsQuicTag(config.ReceivedConnectionOptions(), kATIM)) { |
160 loss_algorithm_.reset(new GeneralLossAlgorithm(kAdaptiveTime)); | 160 loss_algorithm_.reset(new GeneralLossAlgorithm(kAdaptiveTime)); |
161 } | 161 } |
162 if (FLAGS_quic_loss_recovery_use_largest_acked && | 162 if (FLAGS_quic_loss_recovery_use_largest_acked && |
163 config.HasClientSentConnectionOption(kUNDO, perspective_)) { | 163 config.HasClientSentConnectionOption(kUNDO, perspective_)) { |
164 undo_pending_retransmits_ = true; | 164 undo_pending_retransmits_ = true; |
165 } | 165 } |
166 if (!FLAGS_quic_ignore_srbf && config.HasReceivedSocketReceiveBuffer()) { | |
167 receive_buffer_bytes_ = | |
168 max(kMinSocketReceiveBuffer, | |
169 static_cast<QuicByteCount>(config.ReceivedSocketReceiveBuffer())); | |
170 QuicByteCount max_cwnd_bytes = static_cast<QuicByteCount>( | |
171 receive_buffer_bytes_ * kConservativeReceiveBufferFraction); | |
172 send_algorithm_->SetMaxCongestionWindow(max_cwnd_bytes); | |
173 } | |
174 send_algorithm_->SetFromConfig(config, perspective_); | 166 send_algorithm_->SetFromConfig(config, perspective_); |
175 | 167 |
176 if (network_change_visitor_ != nullptr) { | 168 if (network_change_visitor_ != nullptr) { |
177 network_change_visitor_->OnCongestionChange(); | 169 network_change_visitor_->OnCongestionChange(); |
178 } | 170 } |
179 } | 171 } |
180 | 172 |
181 void QuicSentPacketManager::ResumeConnectionState( | 173 void QuicSentPacketManager::ResumeConnectionState( |
182 const CachedNetworkParameters& cached_network_params, | 174 const CachedNetworkParameters& cached_network_params, |
183 bool max_bandwidth_resumption) { | 175 bool max_bandwidth_resumption) { |
(...skipping 581 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
765 // packet numbers will include the ACK aggregation delay. | 757 // packet numbers will include the ACK aggregation delay. |
766 const TransmissionInfo& transmission_info = | 758 const TransmissionInfo& transmission_info = |
767 unacked_packets_.GetTransmissionInfo(ack_frame.largest_observed); | 759 unacked_packets_.GetTransmissionInfo(ack_frame.largest_observed); |
768 // Ensure the packet has a valid sent time. | 760 // Ensure the packet has a valid sent time. |
769 if (transmission_info.sent_time == QuicTime::Zero()) { | 761 if (transmission_info.sent_time == QuicTime::Zero()) { |
770 QUIC_BUG << "Acked packet has zero sent time, largest_observed:" | 762 QUIC_BUG << "Acked packet has zero sent time, largest_observed:" |
771 << ack_frame.largest_observed; | 763 << ack_frame.largest_observed; |
772 return false; | 764 return false; |
773 } | 765 } |
774 | 766 |
775 QuicTime::Delta send_delta = | 767 QuicTime::Delta send_delta = ack_receive_time - transmission_info.sent_time; |
776 ack_receive_time.Subtract(transmission_info.sent_time); | |
777 const int kMaxSendDeltaSeconds = 30; | 768 const int kMaxSendDeltaSeconds = 30; |
778 if (FLAGS_quic_socket_walltimestamps && | 769 if (FLAGS_quic_socket_walltimestamps && |
779 send_delta.ToSeconds() > kMaxSendDeltaSeconds) { | 770 send_delta.ToSeconds() > kMaxSendDeltaSeconds) { |
780 // send_delta can be very high if local clock is changed mid-connection. | 771 // send_delta can be very high if local clock is changed mid-connection. |
781 LOG(WARNING) << "Excessive send delta: " << send_delta.ToSeconds() | 772 LOG(WARNING) << "Excessive send delta: " << send_delta.ToSeconds() |
782 << ", setting to: " << kMaxSendDeltaSeconds; | 773 << ", setting to: " << kMaxSendDeltaSeconds; |
783 send_delta = QuicTime::Delta::FromSeconds(kMaxSendDeltaSeconds); | 774 send_delta = QuicTime::Delta::FromSeconds(kMaxSendDeltaSeconds); |
784 } | 775 } |
785 rtt_stats_.UpdateRtt(send_delta, ack_frame.ack_delay_time, ack_receive_time); | 776 rtt_stats_.UpdateRtt(send_delta, ack_frame.ack_delay_time, ack_receive_time); |
786 | 777 |
(...skipping 21 matching lines...) Expand all Loading... |
808 | 799 |
809 const QuicTime QuicSentPacketManager::GetRetransmissionTime() const { | 800 const QuicTime QuicSentPacketManager::GetRetransmissionTime() const { |
810 // Don't set the timer if there are no packets in flight or we've already | 801 // Don't set the timer if there are no packets in flight or we've already |
811 // queued a tlp transmission and it hasn't been sent yet. | 802 // queued a tlp transmission and it hasn't been sent yet. |
812 if (!unacked_packets_.HasInFlightPackets() || | 803 if (!unacked_packets_.HasInFlightPackets() || |
813 pending_timer_transmission_count_ > 0) { | 804 pending_timer_transmission_count_ > 0) { |
814 return QuicTime::Zero(); | 805 return QuicTime::Zero(); |
815 } | 806 } |
816 switch (GetRetransmissionMode()) { | 807 switch (GetRetransmissionMode()) { |
817 case HANDSHAKE_MODE: | 808 case HANDSHAKE_MODE: |
818 return clock_->ApproximateNow().Add(GetCryptoRetransmissionDelay()); | 809 return clock_->ApproximateNow() + GetCryptoRetransmissionDelay(); |
819 case LOSS_MODE: | 810 case LOSS_MODE: |
820 return loss_algorithm_->GetLossTimeout(); | 811 return loss_algorithm_->GetLossTimeout(); |
821 case TLP_MODE: { | 812 case TLP_MODE: { |
822 // TODO(ianswett): When CWND is available, it would be preferable to | 813 // TODO(ianswett): When CWND is available, it would be preferable to |
823 // set the timer based on the earliest retransmittable packet. | 814 // set the timer based on the earliest retransmittable packet. |
824 // Base the updated timer on the send time of the last packet. | 815 // Base the updated timer on the send time of the last packet. |
825 const QuicTime sent_time = unacked_packets_.GetLastPacketSentTime(); | 816 const QuicTime sent_time = unacked_packets_.GetLastPacketSentTime(); |
826 const QuicTime tlp_time = sent_time.Add(GetTailLossProbeDelay()); | 817 const QuicTime tlp_time = sent_time + GetTailLossProbeDelay(); |
827 // Ensure the TLP timer never gets set to a time in the past. | 818 // Ensure the TLP timer never gets set to a time in the past. |
828 return QuicTime::Max(clock_->ApproximateNow(), tlp_time); | 819 return QuicTime::Max(clock_->ApproximateNow(), tlp_time); |
829 } | 820 } |
830 case RTO_MODE: { | 821 case RTO_MODE: { |
831 // The RTO is based on the first outstanding packet. | 822 // The RTO is based on the first outstanding packet. |
832 const QuicTime sent_time = unacked_packets_.GetLastPacketSentTime(); | 823 const QuicTime sent_time = unacked_packets_.GetLastPacketSentTime(); |
833 QuicTime rto_time = sent_time.Add(GetRetransmissionDelay()); | 824 QuicTime rto_time = sent_time + GetRetransmissionDelay(); |
834 // Wait for TLP packets to be acked before an RTO fires. | 825 // Wait for TLP packets to be acked before an RTO fires. |
835 QuicTime tlp_time = | 826 QuicTime tlp_time = |
836 unacked_packets_.GetLastPacketSentTime().Add(GetTailLossProbeDelay()); | 827 unacked_packets_.GetLastPacketSentTime() + GetTailLossProbeDelay(); |
837 return QuicTime::Max(tlp_time, rto_time); | 828 return QuicTime::Max(tlp_time, rto_time); |
838 } | 829 } |
839 } | 830 } |
840 DCHECK(false); | 831 DCHECK(false); |
841 return QuicTime::Zero(); | 832 return QuicTime::Zero(); |
842 } | 833 } |
843 | 834 |
844 const QuicTime::Delta QuicSentPacketManager::GetCryptoRetransmissionDelay() | 835 const QuicTime::Delta QuicSentPacketManager::GetCryptoRetransmissionDelay() |
845 const { | 836 const { |
846 // This is equivalent to the TailLossProbeDelay, but slightly more aggressive | 837 // This is equivalent to the TailLossProbeDelay, but slightly more aggressive |
(...skipping 12 matching lines...) Expand all Loading... |
859 QuicTime::Delta srtt = rtt_stats_.smoothed_rtt(); | 850 QuicTime::Delta srtt = rtt_stats_.smoothed_rtt(); |
860 if (srtt.IsZero()) { | 851 if (srtt.IsZero()) { |
861 srtt = QuicTime::Delta::FromMicroseconds(rtt_stats_.initial_rtt_us()); | 852 srtt = QuicTime::Delta::FromMicroseconds(rtt_stats_.initial_rtt_us()); |
862 } | 853 } |
863 if (enable_half_rtt_tail_loss_probe_ && consecutive_tlp_count_ == 0u) { | 854 if (enable_half_rtt_tail_loss_probe_ && consecutive_tlp_count_ == 0u) { |
864 return QuicTime::Delta::FromMilliseconds( | 855 return QuicTime::Delta::FromMilliseconds( |
865 max(kMinTailLossProbeTimeoutMs, | 856 max(kMinTailLossProbeTimeoutMs, |
866 static_cast<int64_t>(0.5 * srtt.ToMilliseconds()))); | 857 static_cast<int64_t>(0.5 * srtt.ToMilliseconds()))); |
867 } | 858 } |
868 if (!unacked_packets_.HasMultipleInFlightPackets()) { | 859 if (!unacked_packets_.HasMultipleInFlightPackets()) { |
869 return QuicTime::Delta::Max( | 860 return QuicTime::Delta::Max(2 * srtt, |
870 srtt.Multiply(2), | 861 1.5 * srtt + QuicTime::Delta::FromMilliseconds( |
871 srtt.Multiply(1.5).Add( | 862 kMinRetransmissionTimeMs / 2)); |
872 QuicTime::Delta::FromMilliseconds(kMinRetransmissionTimeMs / 2))); | |
873 } | 863 } |
874 return QuicTime::Delta::FromMilliseconds( | 864 return QuicTime::Delta::FromMilliseconds( |
875 max(kMinTailLossProbeTimeoutMs, | 865 max(kMinTailLossProbeTimeoutMs, |
876 static_cast<int64_t>(2 * srtt.ToMilliseconds()))); | 866 static_cast<int64_t>(2 * srtt.ToMilliseconds()))); |
877 } | 867 } |
878 | 868 |
879 const QuicTime::Delta QuicSentPacketManager::GetRetransmissionDelay() const { | 869 const QuicTime::Delta QuicSentPacketManager::GetRetransmissionDelay() const { |
880 QuicTime::Delta retransmission_delay = send_algorithm_->RetransmissionDelay(); | 870 QuicTime::Delta retransmission_delay = send_algorithm_->RetransmissionDelay(); |
881 if (retransmission_delay.IsZero()) { | 871 if (retransmission_delay.IsZero()) { |
882 // We are in the initial state, use default timeout values. | 872 // We are in the initial state, use default timeout values. |
883 retransmission_delay = | 873 retransmission_delay = |
884 QuicTime::Delta::FromMilliseconds(kDefaultRetransmissionTimeMs); | 874 QuicTime::Delta::FromMilliseconds(kDefaultRetransmissionTimeMs); |
885 } else if (retransmission_delay.ToMilliseconds() < kMinRetransmissionTimeMs) { | 875 } else if (retransmission_delay.ToMilliseconds() < kMinRetransmissionTimeMs) { |
886 retransmission_delay = | 876 retransmission_delay = |
887 QuicTime::Delta::FromMilliseconds(kMinRetransmissionTimeMs); | 877 QuicTime::Delta::FromMilliseconds(kMinRetransmissionTimeMs); |
888 } | 878 } |
889 | 879 |
890 // Calculate exponential back off. | 880 // Calculate exponential back off. |
891 retransmission_delay = retransmission_delay.Multiply( | 881 retransmission_delay = |
892 1 << min<size_t>(consecutive_rto_count_, kMaxRetransmissions)); | 882 retransmission_delay * |
| 883 (1 << min<size_t>(consecutive_rto_count_, kMaxRetransmissions)); |
893 | 884 |
894 if (retransmission_delay.ToMilliseconds() > kMaxRetransmissionTimeMs) { | 885 if (retransmission_delay.ToMilliseconds() > kMaxRetransmissionTimeMs) { |
895 return QuicTime::Delta::FromMilliseconds(kMaxRetransmissionTimeMs); | 886 return QuicTime::Delta::FromMilliseconds(kMaxRetransmissionTimeMs); |
896 } | 887 } |
897 return retransmission_delay; | 888 return retransmission_delay; |
898 } | 889 } |
899 | 890 |
900 const RttStats* QuicSentPacketManager::GetRttStats() const { | 891 const RttStats* QuicSentPacketManager::GetRttStats() const { |
901 return &rtt_stats_; | 892 return &rtt_stats_; |
902 } | 893 } |
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1016 TransmissionInfo* QuicSentPacketManager::GetMutableTransmissionInfo( | 1007 TransmissionInfo* QuicSentPacketManager::GetMutableTransmissionInfo( |
1017 QuicPacketNumber packet_number) { | 1008 QuicPacketNumber packet_number) { |
1018 return unacked_packets_.GetMutableTransmissionInfo(packet_number); | 1009 return unacked_packets_.GetMutableTransmissionInfo(packet_number); |
1019 } | 1010 } |
1020 | 1011 |
1021 void QuicSentPacketManager::RemoveObsoletePackets() { | 1012 void QuicSentPacketManager::RemoveObsoletePackets() { |
1022 unacked_packets_.RemoveObsoletePackets(); | 1013 unacked_packets_.RemoveObsoletePackets(); |
1023 } | 1014 } |
1024 | 1015 |
1025 } // namespace net | 1016 } // namespace net |
OLD | NEW |