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