| 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/core/congestion_control/cubic_bytes.h" | 5 #include "net/quic/core/congestion_control/cubic_bytes.h" |
| 6 | 6 |
| 7 #include "base/logging.h" | 7 #include "base/logging.h" |
| 8 #include "net/quic/core/quic_flags.h" | 8 #include "net/quic/core/quic_flags.h" |
| 9 #include "net/quic/test_tools/mock_clock.h" | 9 #include "net/quic/test_tools/mock_clock.h" |
| 10 #include "testing/gtest/include/gtest/gtest.h" | 10 #include "testing/gtest/include/gtest/gtest.h" |
| (...skipping 16 matching lines...) Expand all Loading... |
| 27 const QuicTime::Delta one_ms_; | 27 const QuicTime::Delta one_ms_; |
| 28 const QuicTime::Delta hundred_ms_; | 28 const QuicTime::Delta hundred_ms_; |
| 29 MockClock clock_; | 29 MockClock clock_; |
| 30 CubicBytes cubic_; | 30 CubicBytes cubic_; |
| 31 }; | 31 }; |
| 32 | 32 |
| 33 TEST_F(CubicBytesTest, AboveOrigin) { | 33 TEST_F(CubicBytesTest, AboveOrigin) { |
| 34 // Convex growth. | 34 // Convex growth. |
| 35 const QuicTime::Delta rtt_min = hundred_ms_; | 35 const QuicTime::Delta rtt_min = hundred_ms_; |
| 36 QuicByteCount current_cwnd = 10 * kDefaultTCPMSS; | 36 QuicByteCount current_cwnd = 10 * kDefaultTCPMSS; |
| 37 QuicByteCount expected_cwnd = | 37 QuicByteCount expected_cwnd = current_cwnd + (kDefaultTCPMSS / 2); |
| 38 current_cwnd + (FLAGS_quic_limit_cubic_cwnd_increase ? kDefaultTCPMSS / 2 | |
| 39 : kDefaultTCPMSS); | |
| 40 // Initialize the state. | 38 // Initialize the state. |
| 41 clock_.AdvanceTime(one_ms_); | 39 clock_.AdvanceTime(one_ms_); |
| 42 EXPECT_EQ(expected_cwnd, cubic_.CongestionWindowAfterAck( | 40 EXPECT_EQ(expected_cwnd, cubic_.CongestionWindowAfterAck( |
| 43 kDefaultTCPMSS, current_cwnd, rtt_min)); | 41 kDefaultTCPMSS, current_cwnd, rtt_min)); |
| 44 current_cwnd = expected_cwnd; | 42 current_cwnd = expected_cwnd; |
| 45 // Normal TCP phase. | 43 // Normal TCP phase. |
| 46 for (int i = 0; i < 48; ++i) { | 44 for (int i = 0; i < 48; ++i) { |
| 47 for (QuicPacketCount n = 1; | 45 for (QuicPacketCount n = 1; |
| 48 n < current_cwnd / kDefaultTCPMSS / kNConnectionAlpha; ++n) { | 46 n < current_cwnd / kDefaultTCPMSS / kNConnectionAlpha; ++n) { |
| 49 // Call once per ACK. | 47 // Call once per ACK. |
| (...skipping 23 matching lines...) Expand all Loading... |
| 73 float elapsed_time_s = 10.0f + 0.1f; | 71 float elapsed_time_s = 10.0f + 0.1f; |
| 74 // |expected_cwnd| is initial value of cwnd + K * t^3, where K = 0.4. | 72 // |expected_cwnd| is initial value of cwnd + K * t^3, where K = 0.4. |
| 75 expected_cwnd = | 73 expected_cwnd = |
| 76 11 + (elapsed_time_s * elapsed_time_s * elapsed_time_s * 410) / 1024; | 74 11 + (elapsed_time_s * elapsed_time_s * elapsed_time_s * 410) / 1024; |
| 77 EXPECT_EQ(expected_cwnd, current_cwnd / kDefaultTCPMSS); | 75 EXPECT_EQ(expected_cwnd, current_cwnd / kDefaultTCPMSS); |
| 78 } | 76 } |
| 79 | 77 |
| 80 TEST_F(CubicBytesTest, LossEvents) { | 78 TEST_F(CubicBytesTest, LossEvents) { |
| 81 const QuicTime::Delta rtt_min = hundred_ms_; | 79 const QuicTime::Delta rtt_min = hundred_ms_; |
| 82 QuicByteCount current_cwnd = 422 * kDefaultTCPMSS; | 80 QuicByteCount current_cwnd = 422 * kDefaultTCPMSS; |
| 83 QuicPacketCount expected_cwnd = | 81 QuicPacketCount expected_cwnd = current_cwnd + kDefaultTCPMSS / 2; |
| 84 current_cwnd + (FLAGS_quic_limit_cubic_cwnd_increase ? kDefaultTCPMSS / 2 | |
| 85 : kDefaultTCPMSS); | |
| 86 // Initialize the state. | 82 // Initialize the state. |
| 87 clock_.AdvanceTime(one_ms_); | 83 clock_.AdvanceTime(one_ms_); |
| 88 EXPECT_EQ(expected_cwnd, cubic_.CongestionWindowAfterAck( | 84 EXPECT_EQ(expected_cwnd, cubic_.CongestionWindowAfterAck( |
| 89 kDefaultTCPMSS, current_cwnd, rtt_min)); | 85 kDefaultTCPMSS, current_cwnd, rtt_min)); |
| 90 expected_cwnd = static_cast<QuicPacketCount>(current_cwnd * kNConnectionBeta); | 86 expected_cwnd = static_cast<QuicPacketCount>(current_cwnd * kNConnectionBeta); |
| 91 EXPECT_EQ(expected_cwnd, | 87 EXPECT_EQ(expected_cwnd, |
| 92 cubic_.CongestionWindowAfterPacketLoss(current_cwnd)); | 88 cubic_.CongestionWindowAfterPacketLoss(current_cwnd)); |
| 93 expected_cwnd = static_cast<QuicPacketCount>(current_cwnd * kNConnectionBeta); | 89 expected_cwnd = static_cast<QuicPacketCount>(current_cwnd * kNConnectionBeta); |
| 94 EXPECT_EQ(expected_cwnd, | 90 EXPECT_EQ(expected_cwnd, |
| 95 cubic_.CongestionWindowAfterPacketLoss(current_cwnd)); | 91 cubic_.CongestionWindowAfterPacketLoss(current_cwnd)); |
| 96 } | 92 } |
| 97 | 93 |
| 98 TEST_F(CubicBytesTest, BelowOrigin) { | 94 TEST_F(CubicBytesTest, BelowOrigin) { |
| 99 // Concave growth. | 95 // Concave growth. |
| 100 const QuicTime::Delta rtt_min = hundred_ms_; | 96 const QuicTime::Delta rtt_min = hundred_ms_; |
| 101 QuicByteCount current_cwnd = 422 * kDefaultTCPMSS; | 97 QuicByteCount current_cwnd = 422 * kDefaultTCPMSS; |
| 102 QuicPacketCount expected_cwnd = | 98 QuicPacketCount expected_cwnd = current_cwnd + kDefaultTCPMSS / 2; |
| 103 current_cwnd + (FLAGS_quic_limit_cubic_cwnd_increase ? kDefaultTCPMSS / 2 | |
| 104 : kDefaultTCPMSS); | |
| 105 // Initialize the state. | 99 // Initialize the state. |
| 106 clock_.AdvanceTime(one_ms_); | 100 clock_.AdvanceTime(one_ms_); |
| 107 EXPECT_EQ(expected_cwnd, cubic_.CongestionWindowAfterAck( | 101 EXPECT_EQ(expected_cwnd, cubic_.CongestionWindowAfterAck( |
| 108 kDefaultTCPMSS, current_cwnd, rtt_min)); | 102 kDefaultTCPMSS, current_cwnd, rtt_min)); |
| 109 expected_cwnd = static_cast<QuicPacketCount>(current_cwnd * kNConnectionBeta); | 103 expected_cwnd = static_cast<QuicPacketCount>(current_cwnd * kNConnectionBeta); |
| 110 EXPECT_EQ(expected_cwnd, | 104 EXPECT_EQ(expected_cwnd, |
| 111 cubic_.CongestionWindowAfterPacketLoss(current_cwnd)); | 105 cubic_.CongestionWindowAfterPacketLoss(current_cwnd)); |
| 112 current_cwnd = expected_cwnd; | 106 current_cwnd = expected_cwnd; |
| 113 // First update after loss to initialize the epoch. | 107 // First update after loss to initialize the epoch. |
| 114 current_cwnd = | 108 current_cwnd = |
| 115 cubic_.CongestionWindowAfterAck(kDefaultTCPMSS, current_cwnd, rtt_min); | 109 cubic_.CongestionWindowAfterAck(kDefaultTCPMSS, current_cwnd, rtt_min); |
| 116 // Cubic phase. | 110 // Cubic phase. |
| 117 for (int i = 0; i < 40; ++i) { | 111 for (int i = 0; i < 40; ++i) { |
| 118 clock_.AdvanceTime(hundred_ms_); | 112 clock_.AdvanceTime(hundred_ms_); |
| 119 current_cwnd = | 113 current_cwnd = |
| 120 cubic_.CongestionWindowAfterAck(kDefaultTCPMSS, current_cwnd, rtt_min); | 114 cubic_.CongestionWindowAfterAck(kDefaultTCPMSS, current_cwnd, rtt_min); |
| 121 } | 115 } |
| 122 expected_cwnd = | 116 expected_cwnd = 553632; |
| 123 FLAGS_quic_limit_cubic_cwnd_increase ? 553632 : 422 * kDefaultTCPMSS; | |
| 124 EXPECT_EQ(expected_cwnd, current_cwnd); | 117 EXPECT_EQ(expected_cwnd, current_cwnd); |
| 125 } | 118 } |
| 126 | 119 |
| 127 } // namespace test | 120 } // namespace test |
| 128 } // namespace net | 121 } // namespace net |
| OLD | NEW |