OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "base/basictypes.h" | 5 #include "base/basictypes.h" |
6 #include "base/logging.h" | 6 #include "base/logging.h" |
7 #include "net/quic/congestion_control/cubic.h" | 7 #include "net/quic/congestion_control/cubic.h" |
8 #include "net/quic/quic_connection_stats.h" | 8 #include "net/quic/quic_connection_stats.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" |
11 | 11 |
12 namespace net { | 12 namespace net { |
13 namespace test { | 13 namespace test { |
14 | 14 |
15 const float kBeta = 0.7f; // Default Cubic backoff factor. | 15 const float kBeta = 0.7f; // Default Cubic backoff factor. |
16 const uint32 kNumConnections = 2; | 16 const uint32 kNumConnections = 2; |
17 const float kNConnectionBeta = (kNumConnections - 1 + kBeta) / kNumConnections; | 17 const float kNConnectionBeta = (kNumConnections - 1 + kBeta) / kNumConnections; |
18 const float kNConnectionAlpha = 3 * kNumConnections * kNumConnections * | 18 const float kNConnectionAlpha = 3 * kNumConnections * kNumConnections * |
19 (1 - kNConnectionBeta) / (1 + kNConnectionBeta); | 19 (1 - kNConnectionBeta) / (1 + kNConnectionBeta); |
20 | 20 |
21 class CubicTest : public ::testing::Test { | 21 class CubicTest : public ::testing::Test { |
22 protected: | 22 protected: |
23 CubicTest() | 23 CubicTest() |
24 : one_ms_(QuicTime::Delta::FromMilliseconds(1)), | 24 : one_ms_(QuicTime::Delta::FromMilliseconds(1)), |
25 hundred_ms_(QuicTime::Delta::FromMilliseconds(100)), | 25 hundred_ms_(QuicTime::Delta::FromMilliseconds(100)), |
26 cubic_(&clock_, &stats_) { | 26 cubic_(&clock_) {} |
27 } | |
28 const QuicTime::Delta one_ms_; | 27 const QuicTime::Delta one_ms_; |
29 const QuicTime::Delta hundred_ms_; | 28 const QuicTime::Delta hundred_ms_; |
30 MockClock clock_; | 29 MockClock clock_; |
31 QuicConnectionStats stats_; | |
32 Cubic cubic_; | 30 Cubic cubic_; |
33 }; | 31 }; |
34 | 32 |
35 TEST_F(CubicTest, AboveOrigin) { | 33 TEST_F(CubicTest, AboveOrigin) { |
36 // Convex growth. | 34 // Convex growth. |
37 const QuicTime::Delta rtt_min = hundred_ms_; | 35 const QuicTime::Delta rtt_min = hundred_ms_; |
38 QuicPacketCount current_cwnd = 10; | 36 QuicPacketCount current_cwnd = 10; |
39 QuicPacketCount expected_cwnd = current_cwnd + 1; | 37 QuicPacketCount expected_cwnd = current_cwnd + 1; |
40 // Initialize the state. | 38 // Initialize the state. |
41 clock_.AdvanceTime(one_ms_); | 39 clock_.AdvanceTime(one_ms_); |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
82 current_cwnd = expected_cwnd; | 80 current_cwnd = expected_cwnd; |
83 // Testing Reno mode increase. | 81 // Testing Reno mode increase. |
84 for (int i = 0; i < 48; ++i) { | 82 for (int i = 0; i < 48; ++i) { |
85 for (QuicPacketCount n = 1; n < current_cwnd / kNConnectionAlpha; ++n) { | 83 for (QuicPacketCount n = 1; n < current_cwnd / kNConnectionAlpha; ++n) { |
86 // Call once per ACK, causing cwnd growth in Reno mode. | 84 // Call once per ACK, causing cwnd growth in Reno mode. |
87 cubic_.CongestionWindowAfterAck(current_cwnd, rtt_min); | 85 cubic_.CongestionWindowAfterAck(current_cwnd, rtt_min); |
88 } | 86 } |
89 // Advance current time so that cwnd update is allowed to happen by Cubic. | 87 // Advance current time so that cwnd update is allowed to happen by Cubic. |
90 clock_.AdvanceTime(hundred_ms_); | 88 clock_.AdvanceTime(hundred_ms_); |
91 current_cwnd = cubic_.CongestionWindowAfterAck(current_cwnd, rtt_min); | 89 current_cwnd = cubic_.CongestionWindowAfterAck(current_cwnd, rtt_min); |
92 EXPECT_NEAR(expected_cwnd - 10, stats_.cwnd_increase_congestion_avoidance, | |
93 1); | |
94 EXPECT_NEAR(1u, stats_.cwnd_increase_cubic_mode, 1); | |
95 expected_cwnd++; | 90 expected_cwnd++; |
96 } | 91 } |
97 QuicPacketCount old_cwnd = current_cwnd; | |
98 stats_.cwnd_increase_cubic_mode = 0; | |
99 stats_.cwnd_increase_congestion_avoidance = 0; | |
100 | 92 |
101 // Testing Cubic mode increase. | 93 // Testing Cubic mode increase. |
102 for (int i = 0; i < 52; ++i) { | 94 for (int i = 0; i < 52; ++i) { |
103 for (QuicPacketCount n = 1; n < current_cwnd; ++n) { | 95 for (QuicPacketCount n = 1; n < current_cwnd; ++n) { |
104 // Call once per ACK. | 96 // Call once per ACK. |
105 cubic_.CongestionWindowAfterAck(current_cwnd, rtt_min); | 97 cubic_.CongestionWindowAfterAck(current_cwnd, rtt_min); |
106 } | 98 } |
107 clock_.AdvanceTime(hundred_ms_); | 99 clock_.AdvanceTime(hundred_ms_); |
108 current_cwnd = cubic_.CongestionWindowAfterAck(current_cwnd, rtt_min); | 100 current_cwnd = cubic_.CongestionWindowAfterAck(current_cwnd, rtt_min); |
109 } | 101 } |
110 // Total time elapsed so far; add min_rtt (0.1s) here as well. | |
111 float elapsed_time_s = 10.0f + 0.1f; | |
112 // |expected_cwnd| is initial value of cwnd + K * t^3, where K = 0.4. | |
113 expected_cwnd = 11 + (elapsed_time_s * elapsed_time_s * elapsed_time_s * 410) | |
114 / 1024; | |
115 EXPECT_EQ(expected_cwnd - old_cwnd, stats_.cwnd_increase_cubic_mode); | |
116 EXPECT_EQ(expected_cwnd - old_cwnd, | |
117 stats_.cwnd_increase_congestion_avoidance); | |
118 } | 102 } |
119 | 103 |
120 | 104 |
121 TEST_F(CubicTest, LossEvents) { | 105 TEST_F(CubicTest, LossEvents) { |
122 const QuicTime::Delta rtt_min = hundred_ms_; | 106 const QuicTime::Delta rtt_min = hundred_ms_; |
123 QuicPacketCount current_cwnd = 422; | 107 QuicPacketCount current_cwnd = 422; |
124 QuicPacketCount expected_cwnd = current_cwnd + 1; | 108 QuicPacketCount expected_cwnd = current_cwnd + 1; |
125 // Initialize the state. | 109 // Initialize the state. |
126 clock_.AdvanceTime(one_ms_); | 110 clock_.AdvanceTime(one_ms_); |
127 EXPECT_EQ(expected_cwnd, | 111 EXPECT_EQ(expected_cwnd, |
(...skipping 14 matching lines...) Expand all Loading... |
142 // Initialize the state. | 126 // Initialize the state. |
143 clock_.AdvanceTime(one_ms_); | 127 clock_.AdvanceTime(one_ms_); |
144 EXPECT_EQ(expected_cwnd, | 128 EXPECT_EQ(expected_cwnd, |
145 cubic_.CongestionWindowAfterAck(current_cwnd, rtt_min)); | 129 cubic_.CongestionWindowAfterAck(current_cwnd, rtt_min)); |
146 expected_cwnd = static_cast<QuicPacketCount>(current_cwnd * kNConnectionBeta); | 130 expected_cwnd = static_cast<QuicPacketCount>(current_cwnd * kNConnectionBeta); |
147 EXPECT_EQ(expected_cwnd, | 131 EXPECT_EQ(expected_cwnd, |
148 cubic_.CongestionWindowAfterPacketLoss(current_cwnd)); | 132 cubic_.CongestionWindowAfterPacketLoss(current_cwnd)); |
149 current_cwnd = expected_cwnd; | 133 current_cwnd = expected_cwnd; |
150 // First update after loss to initialize the epoch. | 134 // First update after loss to initialize the epoch. |
151 current_cwnd = cubic_.CongestionWindowAfterAck(current_cwnd, rtt_min); | 135 current_cwnd = cubic_.CongestionWindowAfterAck(current_cwnd, rtt_min); |
152 QuicPacketCount old_cwnd = current_cwnd; | |
153 // Cubic phase. | 136 // Cubic phase. |
154 stats_.cwnd_increase_cubic_mode = 0; | |
155 stats_.cwnd_increase_congestion_avoidance = 0; | |
156 for (int i = 0; i < 40 ; ++i) { | 137 for (int i = 0; i < 40 ; ++i) { |
157 clock_.AdvanceTime(hundred_ms_); | 138 clock_.AdvanceTime(hundred_ms_); |
158 current_cwnd = cubic_.CongestionWindowAfterAck(current_cwnd, rtt_min); | 139 current_cwnd = cubic_.CongestionWindowAfterAck(current_cwnd, rtt_min); |
159 } | 140 } |
160 expected_cwnd = 422; | 141 expected_cwnd = 422; |
161 EXPECT_EQ(expected_cwnd, current_cwnd); | 142 EXPECT_EQ(expected_cwnd, current_cwnd); |
162 EXPECT_EQ(expected_cwnd - old_cwnd, stats_.cwnd_increase_cubic_mode); | |
163 EXPECT_EQ(expected_cwnd - old_cwnd, | |
164 stats_.cwnd_increase_congestion_avoidance); | |
165 } | 143 } |
166 | 144 |
167 } // namespace test | 145 } // namespace test |
168 } // namespace net | 146 } // namespace net |
OLD | NEW |