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" |
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
82 current_cwnd = expected_cwnd; | 82 current_cwnd = expected_cwnd; |
83 // Testing Reno mode increase. | 83 // Testing Reno mode increase. |
84 for (int i = 0; i < 48; ++i) { | 84 for (int i = 0; i < 48; ++i) { |
85 for (uint32 n = 1; n < current_cwnd / kNConnectionAlpha; ++n) { | 85 for (uint32 n = 1; n < current_cwnd / kNConnectionAlpha; ++n) { |
86 // Call once per ACK, causing cwnd growth in Reno mode. | 86 // Call once per ACK, causing cwnd growth in Reno mode. |
87 cubic_.CongestionWindowAfterAck(current_cwnd, rtt_min); | 87 cubic_.CongestionWindowAfterAck(current_cwnd, rtt_min); |
88 } | 88 } |
89 // Advance current time so that cwnd update is allowed to happen by Cubic. | 89 // Advance current time so that cwnd update is allowed to happen by Cubic. |
90 clock_.AdvanceTime(hundred_ms_); | 90 clock_.AdvanceTime(hundred_ms_); |
91 current_cwnd = cubic_.CongestionWindowAfterAck(current_cwnd, rtt_min); | 91 current_cwnd = cubic_.CongestionWindowAfterAck(current_cwnd, rtt_min); |
92 EXPECT_NEAR(expected_cwnd - 10, stats_.cwnd_increase_reno_mode, 1); | 92 EXPECT_NEAR(expected_cwnd - 10, stats_.cwnd_increase_congestion_avoidance, |
| 93 1); |
93 EXPECT_NEAR(1u, stats_.cwnd_increase_cubic_mode, 1); | 94 EXPECT_NEAR(1u, stats_.cwnd_increase_cubic_mode, 1); |
94 expected_cwnd++; | 95 expected_cwnd++; |
95 } | 96 } |
96 uint32 old_cwnd = current_cwnd; | 97 uint32 old_cwnd = current_cwnd; |
97 stats_.cwnd_increase_cubic_mode = 0; | 98 stats_.cwnd_increase_cubic_mode = 0; |
98 stats_.cwnd_increase_reno_mode = 0; | 99 stats_.cwnd_increase_congestion_avoidance = 0; |
99 | 100 |
100 // Testing Cubic mode increase. | 101 // Testing Cubic mode increase. |
101 for (int i = 0; i < 52; ++i) { | 102 for (int i = 0; i < 52; ++i) { |
102 for (uint32 n = 1; n < current_cwnd; ++n) { | 103 for (uint32 n = 1; n < current_cwnd; ++n) { |
103 // Call once per ACK. | 104 // Call once per ACK. |
104 cubic_.CongestionWindowAfterAck(current_cwnd, rtt_min); | 105 cubic_.CongestionWindowAfterAck(current_cwnd, rtt_min); |
105 } | 106 } |
106 clock_.AdvanceTime(hundred_ms_); | 107 clock_.AdvanceTime(hundred_ms_); |
107 current_cwnd = cubic_.CongestionWindowAfterAck(current_cwnd, rtt_min); | 108 current_cwnd = cubic_.CongestionWindowAfterAck(current_cwnd, rtt_min); |
108 } | 109 } |
109 // Total time elapsed so far; add min_rtt (0.1s) here as well. | 110 // Total time elapsed so far; add min_rtt (0.1s) here as well. |
110 float elapsed_time_s = 10.0f + 0.1f; | 111 float elapsed_time_s = 10.0f + 0.1f; |
111 // |expected_cwnd| is initial value of cwnd + K * t^3, where K = 0.4. | 112 // |expected_cwnd| is initial value of cwnd + K * t^3, where K = 0.4. |
112 expected_cwnd = 11 + (elapsed_time_s * elapsed_time_s * elapsed_time_s * 410) | 113 expected_cwnd = 11 + (elapsed_time_s * elapsed_time_s * elapsed_time_s * 410) |
113 / 1024; | 114 / 1024; |
114 EXPECT_EQ(expected_cwnd - old_cwnd, stats_.cwnd_increase_cubic_mode); | 115 EXPECT_EQ(expected_cwnd - old_cwnd, stats_.cwnd_increase_cubic_mode); |
115 EXPECT_EQ(0u, stats_.cwnd_increase_reno_mode); | 116 EXPECT_EQ(expected_cwnd - old_cwnd, |
| 117 stats_.cwnd_increase_congestion_avoidance); |
116 } | 118 } |
117 | 119 |
118 | 120 |
119 TEST_F(CubicTest, LossEvents) { | 121 TEST_F(CubicTest, LossEvents) { |
120 const QuicTime::Delta rtt_min = hundred_ms_; | 122 const QuicTime::Delta rtt_min = hundred_ms_; |
121 uint32 current_cwnd = 422; | 123 uint32 current_cwnd = 422; |
122 uint32 expected_cwnd = current_cwnd + 1; | 124 uint32 expected_cwnd = current_cwnd + 1; |
123 // Initialize the state. | 125 // Initialize the state. |
124 clock_.AdvanceTime(one_ms_); | 126 clock_.AdvanceTime(one_ms_); |
125 EXPECT_EQ(expected_cwnd, | 127 EXPECT_EQ(expected_cwnd, |
(...skipping 17 matching lines...) Expand all Loading... |
143 cubic_.CongestionWindowAfterAck(current_cwnd, rtt_min)); | 145 cubic_.CongestionWindowAfterAck(current_cwnd, rtt_min)); |
144 expected_cwnd = static_cast<int>(current_cwnd * kNConnectionBeta); | 146 expected_cwnd = static_cast<int>(current_cwnd * kNConnectionBeta); |
145 EXPECT_EQ(expected_cwnd, | 147 EXPECT_EQ(expected_cwnd, |
146 cubic_.CongestionWindowAfterPacketLoss(current_cwnd)); | 148 cubic_.CongestionWindowAfterPacketLoss(current_cwnd)); |
147 current_cwnd = expected_cwnd; | 149 current_cwnd = expected_cwnd; |
148 // First update after loss to initialize the epoch. | 150 // First update after loss to initialize the epoch. |
149 current_cwnd = cubic_.CongestionWindowAfterAck(current_cwnd, rtt_min); | 151 current_cwnd = cubic_.CongestionWindowAfterAck(current_cwnd, rtt_min); |
150 uint32 old_cwnd = current_cwnd; | 152 uint32 old_cwnd = current_cwnd; |
151 // Cubic phase. | 153 // Cubic phase. |
152 stats_.cwnd_increase_cubic_mode = 0; | 154 stats_.cwnd_increase_cubic_mode = 0; |
153 stats_.cwnd_increase_reno_mode = 0; | 155 stats_.cwnd_increase_congestion_avoidance = 0; |
154 for (int i = 0; i < 40 ; ++i) { | 156 for (int i = 0; i < 40 ; ++i) { |
155 clock_.AdvanceTime(hundred_ms_); | 157 clock_.AdvanceTime(hundred_ms_); |
156 current_cwnd = cubic_.CongestionWindowAfterAck(current_cwnd, rtt_min); | 158 current_cwnd = cubic_.CongestionWindowAfterAck(current_cwnd, rtt_min); |
157 } | 159 } |
158 expected_cwnd = 422; | 160 expected_cwnd = 422; |
159 EXPECT_EQ(expected_cwnd, current_cwnd); | 161 EXPECT_EQ(expected_cwnd, current_cwnd); |
160 EXPECT_EQ(expected_cwnd - old_cwnd, stats_.cwnd_increase_cubic_mode); | 162 EXPECT_EQ(expected_cwnd - old_cwnd, stats_.cwnd_increase_cubic_mode); |
161 EXPECT_EQ(0u, stats_.cwnd_increase_reno_mode); | 163 EXPECT_EQ(expected_cwnd - old_cwnd, |
| 164 stats_.cwnd_increase_congestion_avoidance); |
162 } | 165 } |
163 | 166 |
164 } // namespace test | 167 } // namespace test |
165 } // namespace net | 168 } // namespace net |
OLD | NEW |