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 174 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
185 InvokeLossDetection(ack_receive_time); | 185 InvokeLossDetection(ack_receive_time); |
186 MaybeInvokeCongestionEvent(largest_observed_acked, bytes_in_flight); | 186 MaybeInvokeCongestionEvent(largest_observed_acked, bytes_in_flight); |
187 unacked_packets_.RemoveObsoletePackets(); | 187 unacked_packets_.RemoveObsoletePackets(); |
188 | 188 |
189 sustained_bandwidth_recorder_.RecordEstimate( | 189 sustained_bandwidth_recorder_.RecordEstimate( |
190 send_algorithm_->InRecovery(), | 190 send_algorithm_->InRecovery(), |
191 send_algorithm_->InSlowStart(), | 191 send_algorithm_->InSlowStart(), |
192 send_algorithm_->BandwidthEstimate(), | 192 send_algorithm_->BandwidthEstimate(), |
193 ack_receive_time, | 193 ack_receive_time, |
194 clock_->WallNow(), | 194 clock_->WallNow(), |
195 rtt_stats_.SmoothedRtt()); | 195 rtt_stats_.smoothed_rtt()); |
196 | 196 |
197 // If we have received a truncated ack, then we need to clear out some | 197 // If we have received a truncated ack, then we need to clear out some |
198 // previous transmissions to allow the peer to actually ACK new packets. | 198 // previous transmissions to allow the peer to actually ACK new packets. |
199 if (ack_frame.is_truncated) { | 199 if (ack_frame.is_truncated) { |
200 unacked_packets_.ClearAllPreviousRetransmissions(); | 200 unacked_packets_.ClearAllPreviousRetransmissions(); |
201 } | 201 } |
202 | 202 |
203 // Anytime we are making forward progress and have a new RTT estimate, reset | 203 // Anytime we are making forward progress and have a new RTT estimate, reset |
204 // the backoff counters. | 204 // the backoff counters. |
205 if (largest_observed_acked) { | 205 if (largest_observed_acked) { |
(...skipping 606 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
812 } | 812 } |
813 } | 813 } |
814 DCHECK(false); | 814 DCHECK(false); |
815 return QuicTime::Zero(); | 815 return QuicTime::Zero(); |
816 } | 816 } |
817 | 817 |
818 const QuicTime::Delta QuicSentPacketManager::GetCryptoRetransmissionDelay() | 818 const QuicTime::Delta QuicSentPacketManager::GetCryptoRetransmissionDelay() |
819 const { | 819 const { |
820 // This is equivalent to the TailLossProbeDelay, but slightly more aggressive | 820 // This is equivalent to the TailLossProbeDelay, but slightly more aggressive |
821 // because crypto handshake messages don't incur a delayed ack time. | 821 // because crypto handshake messages don't incur a delayed ack time. |
822 int64 delay_ms = | 822 QuicTime::Delta srtt = rtt_stats_.smoothed_rtt(); |
823 max(kMinHandshakeTimeoutMs, | 823 if (srtt.IsZero()) { |
824 static_cast<int64>(1.5 * rtt_stats_.SmoothedRtt().ToMilliseconds())); | 824 srtt = QuicTime::Delta::FromMicroseconds(rtt_stats_.initial_rtt_us()); |
| 825 } |
| 826 int64 delay_ms = max(kMinHandshakeTimeoutMs, |
| 827 static_cast<int64>(1.5 * srtt.ToMilliseconds())); |
825 return QuicTime::Delta::FromMilliseconds( | 828 return QuicTime::Delta::FromMilliseconds( |
826 delay_ms << consecutive_crypto_retransmission_count_); | 829 delay_ms << consecutive_crypto_retransmission_count_); |
827 } | 830 } |
828 | 831 |
829 const QuicTime::Delta QuicSentPacketManager::GetTailLossProbeDelay() const { | 832 const QuicTime::Delta QuicSentPacketManager::GetTailLossProbeDelay() const { |
830 QuicTime::Delta srtt = rtt_stats_.SmoothedRtt(); | 833 QuicTime::Delta srtt = rtt_stats_.smoothed_rtt(); |
| 834 if (srtt.IsZero()) { |
| 835 srtt = QuicTime::Delta::FromMicroseconds(rtt_stats_.initial_rtt_us()); |
| 836 } |
831 if (!unacked_packets_.HasMultipleInFlightPackets()) { | 837 if (!unacked_packets_.HasMultipleInFlightPackets()) { |
832 return QuicTime::Delta::Max( | 838 return QuicTime::Delta::Max( |
833 srtt.Multiply(2), srtt.Multiply(1.5).Add( | 839 srtt.Multiply(2), srtt.Multiply(1.5).Add( |
834 QuicTime::Delta::FromMilliseconds(kMinRetransmissionTimeMs / 2))); | 840 QuicTime::Delta::FromMilliseconds(kMinRetransmissionTimeMs / 2))); |
835 } | 841 } |
836 return QuicTime::Delta::FromMilliseconds( | 842 return QuicTime::Delta::FromMilliseconds( |
837 max(kMinTailLossProbeTimeoutMs, | 843 max(kMinTailLossProbeTimeoutMs, |
838 static_cast<int64>(2 * srtt.ToMilliseconds()))); | 844 static_cast<int64>(2 * srtt.ToMilliseconds()))); |
839 } | 845 } |
840 | 846 |
(...skipping 17 matching lines...) Expand all Loading... |
858 return QuicTime::Delta::FromMilliseconds(kMaxRetransmissionTimeMs); | 864 return QuicTime::Delta::FromMilliseconds(kMaxRetransmissionTimeMs); |
859 } | 865 } |
860 return retransmission_delay; | 866 return retransmission_delay; |
861 } | 867 } |
862 | 868 |
863 const RttStats* QuicSentPacketManager::GetRttStats() const { | 869 const RttStats* QuicSentPacketManager::GetRttStats() const { |
864 return &rtt_stats_; | 870 return &rtt_stats_; |
865 } | 871 } |
866 | 872 |
867 QuicBandwidth QuicSentPacketManager::BandwidthEstimate() const { | 873 QuicBandwidth QuicSentPacketManager::BandwidthEstimate() const { |
| 874 // TODO(ianswett): Remove BandwidthEstimate from SendAlgorithmInterface |
| 875 // and implement the logic here. |
868 return send_algorithm_->BandwidthEstimate(); | 876 return send_algorithm_->BandwidthEstimate(); |
869 } | 877 } |
870 | 878 |
871 bool QuicSentPacketManager::HasReliableBandwidthEstimate() const { | 879 bool QuicSentPacketManager::HasReliableBandwidthEstimate() const { |
872 return send_algorithm_->HasReliableBandwidthEstimate(); | 880 return send_algorithm_->HasReliableBandwidthEstimate(); |
873 } | 881 } |
874 | 882 |
875 const QuicSustainedBandwidthRecorder& | 883 const QuicSustainedBandwidthRecorder& |
876 QuicSentPacketManager::SustainedBandwidthRecorder() const { | 884 QuicSentPacketManager::SustainedBandwidthRecorder() const { |
877 return sustained_bandwidth_recorder_; | 885 return sustained_bandwidth_recorder_; |
878 } | 886 } |
879 | 887 |
880 QuicByteCount QuicSentPacketManager::GetCongestionWindow() const { | 888 QuicPacketCount QuicSentPacketManager::EstimateMaxPacketsInFlight( |
881 return send_algorithm_->GetCongestionWindow(); | 889 QuicByteCount max_packet_length) const { |
| 890 return send_algorithm_->GetCongestionWindow() / max_packet_length; |
882 } | 891 } |
883 | 892 |
884 QuicByteCount QuicSentPacketManager::GetSlowStartThreshold() const { | 893 QuicPacketCount QuicSentPacketManager::GetCongestionWindowInTcpMss() const { |
885 return send_algorithm_->GetSlowStartThreshold(); | 894 return send_algorithm_->GetCongestionWindow() / kDefaultTCPMSS; |
| 895 } |
| 896 |
| 897 QuicPacketCount QuicSentPacketManager::GetSlowStartThresholdInTcpMss() const { |
| 898 return send_algorithm_->GetSlowStartThreshold() / kDefaultTCPMSS; |
886 } | 899 } |
887 | 900 |
888 void QuicSentPacketManager::EnablePacing() { | 901 void QuicSentPacketManager::EnablePacing() { |
889 if (using_pacing_) { | 902 if (using_pacing_) { |
890 return; | 903 return; |
891 } | 904 } |
892 | 905 |
893 // Set up a pacing sender with a 1 millisecond alarm granularity, the same as | 906 // Set up a pacing sender with a 1 millisecond alarm granularity, the same as |
894 // the default granularity of the Linux kernel's FQ qdisc. | 907 // the default granularity of the Linux kernel's FQ qdisc. |
895 using_pacing_ = true; | 908 using_pacing_ = true; |
896 send_algorithm_.reset( | 909 send_algorithm_.reset( |
897 new PacingSender(send_algorithm_.release(), | 910 new PacingSender(send_algorithm_.release(), |
898 QuicTime::Delta::FromMilliseconds(1), | 911 QuicTime::Delta::FromMilliseconds(1), |
899 kInitialUnpacedBurst)); | 912 kInitialUnpacedBurst)); |
900 } | 913 } |
901 | 914 |
902 } // namespace net | 915 } // namespace net |
OLD | NEW |