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 746 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
757 // packet numbers will include the ACK aggregation delay. | 757 // packet numbers will include the ACK aggregation delay. |
758 const TransmissionInfo& transmission_info = | 758 const TransmissionInfo& transmission_info = |
759 unacked_packets_.GetTransmissionInfo(ack_frame.largest_observed); | 759 unacked_packets_.GetTransmissionInfo(ack_frame.largest_observed); |
760 // Ensure the packet has a valid sent time. | 760 // Ensure the packet has a valid sent time. |
761 if (transmission_info.sent_time == QuicTime::Zero()) { | 761 if (transmission_info.sent_time == QuicTime::Zero()) { |
762 QUIC_BUG << "Acked packet has zero sent time, largest_observed:" | 762 QUIC_BUG << "Acked packet has zero sent time, largest_observed:" |
763 << ack_frame.largest_observed; | 763 << ack_frame.largest_observed; |
764 return false; | 764 return false; |
765 } | 765 } |
766 | 766 |
767 QuicTime::Delta send_delta = | 767 QuicTime::Delta send_delta = ack_receive_time - transmission_info.sent_time; |
768 ack_receive_time.Subtract(transmission_info.sent_time); | |
769 const int kMaxSendDeltaSeconds = 30; | 768 const int kMaxSendDeltaSeconds = 30; |
770 if (FLAGS_quic_socket_walltimestamps && | 769 if (FLAGS_quic_socket_walltimestamps && |
771 send_delta.ToSeconds() > kMaxSendDeltaSeconds) { | 770 send_delta.ToSeconds() > kMaxSendDeltaSeconds) { |
772 // 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. |
773 LOG(WARNING) << "Excessive send delta: " << send_delta.ToSeconds() | 772 LOG(WARNING) << "Excessive send delta: " << send_delta.ToSeconds() |
774 << ", setting to: " << kMaxSendDeltaSeconds; | 773 << ", setting to: " << kMaxSendDeltaSeconds; |
775 send_delta = QuicTime::Delta::FromSeconds(kMaxSendDeltaSeconds); | 774 send_delta = QuicTime::Delta::FromSeconds(kMaxSendDeltaSeconds); |
776 } | 775 } |
777 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); |
778 | 777 |
(...skipping 21 matching lines...) Expand all Loading... |
800 | 799 |
801 const QuicTime QuicSentPacketManager::GetRetransmissionTime() const { | 800 const QuicTime QuicSentPacketManager::GetRetransmissionTime() const { |
802 // 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 |
803 // queued a tlp transmission and it hasn't been sent yet. | 802 // queued a tlp transmission and it hasn't been sent yet. |
804 if (!unacked_packets_.HasInFlightPackets() || | 803 if (!unacked_packets_.HasInFlightPackets() || |
805 pending_timer_transmission_count_ > 0) { | 804 pending_timer_transmission_count_ > 0) { |
806 return QuicTime::Zero(); | 805 return QuicTime::Zero(); |
807 } | 806 } |
808 switch (GetRetransmissionMode()) { | 807 switch (GetRetransmissionMode()) { |
809 case HANDSHAKE_MODE: | 808 case HANDSHAKE_MODE: |
810 return clock_->ApproximateNow().Add(GetCryptoRetransmissionDelay()); | 809 return clock_->ApproximateNow() + GetCryptoRetransmissionDelay(); |
811 case LOSS_MODE: | 810 case LOSS_MODE: |
812 return loss_algorithm_->GetLossTimeout(); | 811 return loss_algorithm_->GetLossTimeout(); |
813 case TLP_MODE: { | 812 case TLP_MODE: { |
814 // TODO(ianswett): When CWND is available, it would be preferable to | 813 // TODO(ianswett): When CWND is available, it would be preferable to |
815 // set the timer based on the earliest retransmittable packet. | 814 // set the timer based on the earliest retransmittable packet. |
816 // 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. |
817 const QuicTime sent_time = unacked_packets_.GetLastPacketSentTime(); | 816 const QuicTime sent_time = unacked_packets_.GetLastPacketSentTime(); |
818 const QuicTime tlp_time = sent_time.Add(GetTailLossProbeDelay()); | 817 const QuicTime tlp_time = sent_time + GetTailLossProbeDelay(); |
819 // 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. |
820 return QuicTime::Max(clock_->ApproximateNow(), tlp_time); | 819 return QuicTime::Max(clock_->ApproximateNow(), tlp_time); |
821 } | 820 } |
822 case RTO_MODE: { | 821 case RTO_MODE: { |
823 // The RTO is based on the first outstanding packet. | 822 // The RTO is based on the first outstanding packet. |
824 const QuicTime sent_time = unacked_packets_.GetLastPacketSentTime(); | 823 const QuicTime sent_time = unacked_packets_.GetLastPacketSentTime(); |
825 QuicTime rto_time = sent_time.Add(GetRetransmissionDelay()); | 824 QuicTime rto_time = sent_time + GetRetransmissionDelay(); |
826 // Wait for TLP packets to be acked before an RTO fires. | 825 // Wait for TLP packets to be acked before an RTO fires. |
827 QuicTime tlp_time = | 826 QuicTime tlp_time = |
828 unacked_packets_.GetLastPacketSentTime().Add(GetTailLossProbeDelay()); | 827 unacked_packets_.GetLastPacketSentTime() + GetTailLossProbeDelay(); |
829 return QuicTime::Max(tlp_time, rto_time); | 828 return QuicTime::Max(tlp_time, rto_time); |
830 } | 829 } |
831 } | 830 } |
832 DCHECK(false); | 831 DCHECK(false); |
833 return QuicTime::Zero(); | 832 return QuicTime::Zero(); |
834 } | 833 } |
835 | 834 |
836 const QuicTime::Delta QuicSentPacketManager::GetCryptoRetransmissionDelay() | 835 const QuicTime::Delta QuicSentPacketManager::GetCryptoRetransmissionDelay() |
837 const { | 836 const { |
838 // 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... |
851 QuicTime::Delta srtt = rtt_stats_.smoothed_rtt(); | 850 QuicTime::Delta srtt = rtt_stats_.smoothed_rtt(); |
852 if (srtt.IsZero()) { | 851 if (srtt.IsZero()) { |
853 srtt = QuicTime::Delta::FromMicroseconds(rtt_stats_.initial_rtt_us()); | 852 srtt = QuicTime::Delta::FromMicroseconds(rtt_stats_.initial_rtt_us()); |
854 } | 853 } |
855 if (enable_half_rtt_tail_loss_probe_ && consecutive_tlp_count_ == 0u) { | 854 if (enable_half_rtt_tail_loss_probe_ && consecutive_tlp_count_ == 0u) { |
856 return QuicTime::Delta::FromMilliseconds( | 855 return QuicTime::Delta::FromMilliseconds( |
857 max(kMinTailLossProbeTimeoutMs, | 856 max(kMinTailLossProbeTimeoutMs, |
858 static_cast<int64_t>(0.5 * srtt.ToMilliseconds()))); | 857 static_cast<int64_t>(0.5 * srtt.ToMilliseconds()))); |
859 } | 858 } |
860 if (!unacked_packets_.HasMultipleInFlightPackets()) { | 859 if (!unacked_packets_.HasMultipleInFlightPackets()) { |
861 return QuicTime::Delta::Max( | 860 return QuicTime::Delta::Max(2 * srtt, |
862 srtt.Multiply(2), | 861 1.5 * srtt + QuicTime::Delta::FromMilliseconds( |
863 srtt.Multiply(1.5).Add( | 862 kMinRetransmissionTimeMs / 2)); |
864 QuicTime::Delta::FromMilliseconds(kMinRetransmissionTimeMs / 2))); | |
865 } | 863 } |
866 return QuicTime::Delta::FromMilliseconds( | 864 return QuicTime::Delta::FromMilliseconds( |
867 max(kMinTailLossProbeTimeoutMs, | 865 max(kMinTailLossProbeTimeoutMs, |
868 static_cast<int64_t>(2 * srtt.ToMilliseconds()))); | 866 static_cast<int64_t>(2 * srtt.ToMilliseconds()))); |
869 } | 867 } |
870 | 868 |
871 const QuicTime::Delta QuicSentPacketManager::GetRetransmissionDelay() const { | 869 const QuicTime::Delta QuicSentPacketManager::GetRetransmissionDelay() const { |
872 QuicTime::Delta retransmission_delay = send_algorithm_->RetransmissionDelay(); | 870 QuicTime::Delta retransmission_delay = send_algorithm_->RetransmissionDelay(); |
873 if (retransmission_delay.IsZero()) { | 871 if (retransmission_delay.IsZero()) { |
874 // We are in the initial state, use default timeout values. | 872 // We are in the initial state, use default timeout values. |
875 retransmission_delay = | 873 retransmission_delay = |
876 QuicTime::Delta::FromMilliseconds(kDefaultRetransmissionTimeMs); | 874 QuicTime::Delta::FromMilliseconds(kDefaultRetransmissionTimeMs); |
877 } else if (retransmission_delay.ToMilliseconds() < kMinRetransmissionTimeMs) { | 875 } else if (retransmission_delay.ToMilliseconds() < kMinRetransmissionTimeMs) { |
878 retransmission_delay = | 876 retransmission_delay = |
879 QuicTime::Delta::FromMilliseconds(kMinRetransmissionTimeMs); | 877 QuicTime::Delta::FromMilliseconds(kMinRetransmissionTimeMs); |
880 } | 878 } |
881 | 879 |
882 // Calculate exponential back off. | 880 // Calculate exponential back off. |
883 retransmission_delay = retransmission_delay.Multiply( | 881 retransmission_delay = |
884 1 << min<size_t>(consecutive_rto_count_, kMaxRetransmissions)); | 882 retransmission_delay * |
| 883 (1 << min<size_t>(consecutive_rto_count_, kMaxRetransmissions)); |
885 | 884 |
886 if (retransmission_delay.ToMilliseconds() > kMaxRetransmissionTimeMs) { | 885 if (retransmission_delay.ToMilliseconds() > kMaxRetransmissionTimeMs) { |
887 return QuicTime::Delta::FromMilliseconds(kMaxRetransmissionTimeMs); | 886 return QuicTime::Delta::FromMilliseconds(kMaxRetransmissionTimeMs); |
888 } | 887 } |
889 return retransmission_delay; | 888 return retransmission_delay; |
890 } | 889 } |
891 | 890 |
892 const RttStats* QuicSentPacketManager::GetRttStats() const { | 891 const RttStats* QuicSentPacketManager::GetRttStats() const { |
893 return &rtt_stats_; | 892 return &rtt_stats_; |
894 } | 893 } |
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1008 TransmissionInfo* QuicSentPacketManager::GetMutableTransmissionInfo( | 1007 TransmissionInfo* QuicSentPacketManager::GetMutableTransmissionInfo( |
1009 QuicPacketNumber packet_number) { | 1008 QuicPacketNumber packet_number) { |
1010 return unacked_packets_.GetMutableTransmissionInfo(packet_number); | 1009 return unacked_packets_.GetMutableTransmissionInfo(packet_number); |
1011 } | 1010 } |
1012 | 1011 |
1013 void QuicSentPacketManager::RemoveObsoletePackets() { | 1012 void QuicSentPacketManager::RemoveObsoletePackets() { |
1014 unacked_packets_.RemoveObsoletePackets(); | 1013 unacked_packets_.RemoveObsoletePackets(); |
1015 } | 1014 } |
1016 | 1015 |
1017 } // namespace net | 1016 } // namespace net |
OLD | NEW |