OLD | NEW |
1 // Copyright (c) 2015 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2015 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/congestion_control/tcp_cubic_sender_bytes.h" | 5 #include "net/quic/congestion_control/tcp_cubic_sender_bytes.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <cstdint> | 8 #include <cstdint> |
9 #include <memory> | 9 #include <memory> |
10 | 10 |
11 #include "base/logging.h" | 11 #include "base/logging.h" |
12 #include "net/quic/congestion_control/rtt_stats.h" | 12 #include "net/quic/congestion_control/rtt_stats.h" |
13 #include "net/quic/crypto/crypto_protocol.h" | 13 #include "net/quic/crypto/crypto_protocol.h" |
14 #include "net/quic/proto/cached_network_parameters.pb.h" | 14 #include "net/quic/proto/cached_network_parameters.pb.h" |
15 #include "net/quic/quic_flags.h" | 15 #include "net/quic/quic_flags.h" |
16 #include "net/quic/quic_protocol.h" | 16 #include "net/quic/quic_protocol.h" |
17 #include "net/quic/quic_utils.h" | 17 #include "net/quic/quic_utils.h" |
18 #include "net/quic/test_tools/mock_clock.h" | 18 #include "net/quic/test_tools/mock_clock.h" |
19 #include "net/quic/test_tools/quic_config_peer.h" | 19 #include "net/quic/test_tools/quic_config_peer.h" |
20 #include "net/quic/test_tools/quic_test_utils.h" | 20 #include "net/quic/test_tools/quic_test_utils.h" |
21 #include "testing/gtest/include/gtest/gtest.h" | 21 #include "testing/gtest/include/gtest/gtest.h" |
22 | 22 |
23 namespace net { | 23 namespace net { |
24 namespace test { | 24 namespace test { |
25 | 25 |
26 // TODO(ianswett): A number of theses tests were written with the assumption of | 26 // TODO(ianswett): A number of theses tests were written with the assumption of |
27 // an initial CWND of 10. They have carefully calculated values which should be | 27 // an initial CWND of 10. They have carefully calculated values which should be |
28 // updated to be based on kInitialCongestionWindow. | 28 // updated to be based on kInitialCongestionWindow. |
29 const uint32_t kInitialCongestionWindowPackets = 10; | 29 const uint32_t kInitialCongestionWindowPackets = 10; |
| 30 const uint32_t kMaxCongestionWindowPackets = 200; |
30 const uint32_t kDefaultWindowTCP = | 31 const uint32_t kDefaultWindowTCP = |
31 kInitialCongestionWindowPackets * kDefaultTCPMSS; | 32 kInitialCongestionWindowPackets * kDefaultTCPMSS; |
32 const float kRenoBeta = 0.7f; // Reno backoff factor. | 33 const float kRenoBeta = 0.7f; // Reno backoff factor. |
33 | 34 |
34 class TcpCubicSenderBytesPeer : public TcpCubicSenderBytes { | 35 class TcpCubicSenderBytesPeer : public TcpCubicSenderBytes { |
35 public: | 36 public: |
36 TcpCubicSenderBytesPeer(const QuicClock* clock, bool reno) | 37 TcpCubicSenderBytesPeer(const QuicClock* clock, bool reno) |
37 : TcpCubicSenderBytes(clock, | 38 : TcpCubicSenderBytes(clock, |
38 &rtt_stats_, | 39 &rtt_stats_, |
39 reno, | 40 reno, |
40 kInitialCongestionWindowPackets, | 41 kInitialCongestionWindowPackets, |
41 kMaxCongestionWindow, | 42 kMaxCongestionWindowPackets, |
42 &stats_) {} | 43 &stats_) {} |
43 | 44 |
44 const HybridSlowStart& hybrid_slow_start() const { | 45 const HybridSlowStart& hybrid_slow_start() const { |
45 return hybrid_slow_start_; | 46 return hybrid_slow_start_; |
46 } | 47 } |
47 | 48 |
48 float GetRenoBeta() const { return RenoBeta(); } | 49 float GetRenoBeta() const { return RenoBeta(); } |
49 | 50 |
50 RttStats rtt_stats_; | 51 RttStats rtt_stats_; |
51 QuicConnectionStats stats_; | 52 QuicConnectionStats stats_; |
(...skipping 673 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
725 cached_network_params.set_min_rtt_ms(1000); | 726 cached_network_params.set_min_rtt_ms(1000); |
726 | 727 |
727 // Make sure that a bandwidth estimate results in a changed CWND. | 728 // Make sure that a bandwidth estimate results in a changed CWND. |
728 cached_network_params.set_timestamp(clock_.WallNow().ToUNIXSeconds() - | 729 cached_network_params.set_timestamp(clock_.WallNow().ToUNIXSeconds() - |
729 (kNumSecondsPerHour - 1)); | 730 (kNumSecondsPerHour - 1)); |
730 sender_->ResumeConnectionState(cached_network_params, false); | 731 sender_->ResumeConnectionState(cached_network_params, false); |
731 EXPECT_EQ(kNumberOfPackets * kDefaultTCPMSS, sender_->GetCongestionWindow()); | 732 EXPECT_EQ(kNumberOfPackets * kDefaultTCPMSS, sender_->GetCongestionWindow()); |
732 | 733 |
733 // Resumed CWND is limited to be in a sensible range. | 734 // Resumed CWND is limited to be in a sensible range. |
734 cached_network_params.set_bandwidth_estimate_bytes_per_second( | 735 cached_network_params.set_bandwidth_estimate_bytes_per_second( |
735 (kMaxCongestionWindow + 1) * kDefaultTCPMSS); | 736 (kMaxCongestionWindowPackets + 1) * kDefaultTCPMSS); |
736 sender_->ResumeConnectionState(cached_network_params, false); | 737 sender_->ResumeConnectionState(cached_network_params, false); |
737 EXPECT_EQ(kMaxCongestionWindow * kDefaultTCPMSS, | 738 EXPECT_EQ(kMaxCongestionWindowPackets * kDefaultTCPMSS, |
738 sender_->GetCongestionWindow()); | 739 sender_->GetCongestionWindow()); |
739 | 740 |
740 if (FLAGS_quic_no_lower_bw_resumption_limit) { | 741 if (FLAGS_quic_no_lower_bw_resumption_limit) { |
741 // Resume with an illegal value of 0 and verify the server uses 1 instead. | 742 // Resume with an illegal value of 0 and verify the server uses 1 instead. |
742 cached_network_params.set_bandwidth_estimate_bytes_per_second(0); | 743 cached_network_params.set_bandwidth_estimate_bytes_per_second(0); |
743 sender_->ResumeConnectionState(cached_network_params, false); | 744 sender_->ResumeConnectionState(cached_network_params, false); |
744 EXPECT_EQ(sender_->min_congestion_window(), sender_->GetCongestionWindow()); | 745 EXPECT_EQ(sender_->min_congestion_window(), sender_->GetCongestionWindow()); |
745 } else { | 746 } else { |
746 cached_network_params.set_bandwidth_estimate_bytes_per_second( | 747 cached_network_params.set_bandwidth_estimate_bytes_per_second( |
747 (kMinCongestionWindowForBandwidthResumption - 1) * kDefaultTCPMSS); | 748 (kMinCongestionWindowForBandwidthResumption - 1) * kDefaultTCPMSS); |
748 sender_->ResumeConnectionState(cached_network_params, false); | 749 sender_->ResumeConnectionState(cached_network_params, false); |
749 EXPECT_EQ(kMinCongestionWindowForBandwidthResumption * kDefaultTCPMSS, | 750 EXPECT_EQ(kMinCongestionWindowForBandwidthResumption * kDefaultTCPMSS, |
750 sender_->GetCongestionWindow()); | 751 sender_->GetCongestionWindow()); |
751 } | 752 } |
752 | 753 |
753 // Resume to the max value. | 754 // Resume to the max value. |
754 cached_network_params.set_max_bandwidth_estimate_bytes_per_second( | 755 cached_network_params.set_max_bandwidth_estimate_bytes_per_second( |
755 kMaxCongestionWindow * kDefaultTCPMSS); | 756 kMaxCongestionWindowPackets * kDefaultTCPMSS); |
756 sender_->ResumeConnectionState(cached_network_params, true); | 757 sender_->ResumeConnectionState(cached_network_params, true); |
757 EXPECT_EQ(kMaxCongestionWindow * kDefaultTCPMSS, | 758 EXPECT_EQ(kMaxCongestionWindowPackets * kDefaultTCPMSS, |
758 sender_->GetCongestionWindow()); | 759 sender_->GetCongestionWindow()); |
759 } | 760 } |
760 | 761 |
761 TEST_F(TcpCubicSenderBytesTest, PaceBelowCWND) { | 762 TEST_F(TcpCubicSenderBytesTest, PaceBelowCWND) { |
762 QuicConfig config; | 763 QuicConfig config; |
763 | 764 |
764 // Verify that kCOPT: kMIN4 forces the min CWND to 1 packet, but allows up | 765 // Verify that kCOPT: kMIN4 forces the min CWND to 1 packet, but allows up |
765 // to 4 to be sent. | 766 // to 4 to be sent. |
766 QuicTagVector options; | 767 QuicTagVector options; |
767 options.push_back(kMIN4); | 768 options.push_back(kMIN4); |
(...skipping 30 matching lines...) Expand all Loading... |
798 | 799 |
799 // We should now have fallen out of slow start with a reduced window. Slow | 800 // We should now have fallen out of slow start with a reduced window. Slow |
800 // start threshold is also updated. | 801 // start threshold is also updated. |
801 expected_send_window *= kRenoBeta; | 802 expected_send_window *= kRenoBeta; |
802 EXPECT_EQ(expected_send_window, sender_->GetCongestionWindow()); | 803 EXPECT_EQ(expected_send_window, sender_->GetCongestionWindow()); |
803 EXPECT_EQ(expected_send_window, sender_->GetSlowStartThreshold()); | 804 EXPECT_EQ(expected_send_window, sender_->GetSlowStartThreshold()); |
804 | 805 |
805 // Resets cwnd and slow start threshold on connection migrations. | 806 // Resets cwnd and slow start threshold on connection migrations. |
806 sender_->OnConnectionMigration(); | 807 sender_->OnConnectionMigration(); |
807 EXPECT_EQ(kDefaultWindowTCP, sender_->GetCongestionWindow()); | 808 EXPECT_EQ(kDefaultWindowTCP, sender_->GetCongestionWindow()); |
808 EXPECT_EQ(kMaxCongestionWindow * kDefaultTCPMSS, | 809 EXPECT_EQ(kMaxCongestionWindowPackets * kDefaultTCPMSS, |
809 sender_->GetSlowStartThreshold()); | 810 sender_->GetSlowStartThreshold()); |
810 EXPECT_FALSE(sender_->hybrid_slow_start().started()); | 811 EXPECT_FALSE(sender_->hybrid_slow_start().started()); |
811 } | 812 } |
812 | 813 |
813 } // namespace test | 814 } // namespace test |
814 } // namespace net | 815 } // namespace net |
OLD | NEW |