Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1571)

Side by Side Diff: net/quic/congestion_control/cubic_test.cc

Issue 182523002: Land Recent QUIC Changes. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fixed rch's comments in Patch set 1 of CL 181463007 Created 6 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « net/quic/congestion_control/cubic.cc ('k') | net/quic/congestion_control/fix_rate_sender.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/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 kNumConnections = 2; 16 const uint32 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 CubicTest : public ::testing::Test { 21 class CubicTest : public ::testing::Test {
21 protected: 22 protected:
22 CubicTest() 23 CubicTest()
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_, &stats_) {
26 } 27 }
27 const QuicTime::Delta one_ms_; 28 const QuicTime::Delta one_ms_;
28 const QuicTime::Delta hundred_ms_; 29 const QuicTime::Delta hundred_ms_;
29 MockClock clock_; 30 MockClock clock_;
31 QuicConnectionStats stats_;
30 Cubic cubic_; 32 Cubic cubic_;
31 }; 33 };
32 34
33 TEST_F(CubicTest, AboveOrigin) { 35 TEST_F(CubicTest, AboveOrigin) {
34 // Convex growth. 36 // Convex growth.
35 const QuicTime::Delta rtt_min = hundred_ms_; 37 const QuicTime::Delta rtt_min = hundred_ms_;
36 uint32 current_cwnd = 10; 38 uint32 current_cwnd = 10;
37 uint32 expected_cwnd = current_cwnd + 1; 39 uint32 expected_cwnd = current_cwnd + 1;
38 // Initialize the state. 40 // Initialize the state.
39 clock_.AdvanceTime(one_ms_); 41 clock_.AdvanceTime(one_ms_);
40 EXPECT_EQ(expected_cwnd, 42 EXPECT_EQ(expected_cwnd,
41 cubic_.CongestionWindowAfterAck(current_cwnd, rtt_min)); 43 cubic_.CongestionWindowAfterAck(current_cwnd, rtt_min));
42 current_cwnd = expected_cwnd; 44 current_cwnd = expected_cwnd;
43 // Normal TCP phase. 45 // Normal TCP phase.
44 for (int i = 0; i < 48; ++i) { 46 for (int i = 0; i < 48; ++i) {
45 for (uint32 n = 1; n < current_cwnd / kNConnectionAlpha; ++n) { 47 for (uint32 n = 1; n < current_cwnd / kNConnectionAlpha; ++n) {
46 // Call once per ACK. 48 // Call once per ACK.
47 EXPECT_NEAR(current_cwnd, 49 EXPECT_NEAR(current_cwnd,
48 cubic_.CongestionWindowAfterAck(current_cwnd, rtt_min), 1); 50 cubic_.CongestionWindowAfterAck(current_cwnd, rtt_min), 1);
49 } 51 }
50 clock_.AdvanceTime(hundred_ms_); 52 clock_.AdvanceTime(hundred_ms_);
51 current_cwnd = cubic_.CongestionWindowAfterAck(current_cwnd, rtt_min); 53 current_cwnd = cubic_.CongestionWindowAfterAck(current_cwnd, rtt_min);
52 EXPECT_NEAR(expected_cwnd, current_cwnd, 1); 54 EXPECT_NEAR(expected_cwnd, current_cwnd, 1);
53 expected_cwnd++; 55 expected_cwnd++;
54 } 56 }
55 // Cubic phase. 57 // Cubic phase.
56 for (int j = 48; j < 100; ++j) { 58 for (int i = 0; i < 52; ++i) {
57 for (uint32 n = 1; n < current_cwnd; ++n) { 59 for (uint32 n = 1; n < current_cwnd; ++n) {
58 // Call once per ACK. 60 // Call once per ACK.
59 EXPECT_EQ(current_cwnd, 61 EXPECT_EQ(current_cwnd,
60 cubic_.CongestionWindowAfterAck(current_cwnd, rtt_min)); 62 cubic_.CongestionWindowAfterAck(current_cwnd, rtt_min));
61 } 63 }
62 clock_.AdvanceTime(hundred_ms_); 64 clock_.AdvanceTime(hundred_ms_);
63 current_cwnd = cubic_.CongestionWindowAfterAck(current_cwnd, rtt_min); 65 current_cwnd = cubic_.CongestionWindowAfterAck(current_cwnd, rtt_min);
64 } 66 }
65 float elapsed_time_s = 10.0f + 0.1f; // We need to add the RTT here. 67 // Total time elapsed so far; add min_rtt (0.1s) here as well.
68 float elapsed_time_s = 10.0f + 0.1f;
69 // expected_cwnd is initial value of cwnd + K * t^3, where K = 0.4.
66 expected_cwnd = 11 + (elapsed_time_s * elapsed_time_s * elapsed_time_s * 410) 70 expected_cwnd = 11 + (elapsed_time_s * elapsed_time_s * elapsed_time_s * 410)
67 / 1024; 71 / 1024;
68 EXPECT_EQ(expected_cwnd, current_cwnd); 72 EXPECT_EQ(expected_cwnd, current_cwnd);
69 } 73 }
70 74
75 TEST_F(CubicTest, CwndIncreaseStatsDuringConvexRegion) {
76 const QuicTime::Delta rtt_min = hundred_ms_;
77 uint32 current_cwnd = 10;
78 uint32 expected_cwnd = current_cwnd + 1;
79 // Initialize controller state.
80 clock_.AdvanceTime(one_ms_);
81 expected_cwnd = cubic_.CongestionWindowAfterAck(current_cwnd, rtt_min);
82 current_cwnd = expected_cwnd;
83 // Testing Reno mode increase.
84 for (int i = 0; i < 48; ++i) {
85 for (uint32 n = 1; n < current_cwnd / kNConnectionAlpha; ++n) {
86 // Call once per ACK, causing cwnd growth in Reno mode.
87 cubic_.CongestionWindowAfterAck(current_cwnd, rtt_min);
88 }
89 // Advance current time so that cwnd update is allowed to happen by Cubic.
90 clock_.AdvanceTime(hundred_ms_);
91 current_cwnd = cubic_.CongestionWindowAfterAck(current_cwnd, rtt_min);
92 EXPECT_NEAR(expected_cwnd - 10, stats_.cwnd_increase_reno_mode, 1);
93 EXPECT_NEAR(1u, stats_.cwnd_increase_cubic_mode, 1);
94 expected_cwnd++;
95 }
96 uint32 old_cwnd = current_cwnd;
97 stats_.cwnd_increase_cubic_mode = 0;
98 stats_.cwnd_increase_reno_mode = 0;
99
100 // Testing Cubic mode increase.
101 for (int i = 0; i < 52; ++i) {
102 for (uint32 n = 1; n < current_cwnd; ++n) {
103 // Call once per ACK.
104 cubic_.CongestionWindowAfterAck(current_cwnd, rtt_min);
105 }
106 clock_.AdvanceTime(hundred_ms_);
107 current_cwnd = cubic_.CongestionWindowAfterAck(current_cwnd, rtt_min);
108 }
109 // Total time elapsed so far; add min_rtt (0.1s) here as well.
110 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 = 11 + (elapsed_time_s * elapsed_time_s * elapsed_time_s * 410)
113 / 1024;
114 EXPECT_EQ(expected_cwnd - old_cwnd, stats_.cwnd_increase_cubic_mode);
115 EXPECT_EQ(0u, stats_.cwnd_increase_reno_mode);
116 }
117
118
71 TEST_F(CubicTest, LossEvents) { 119 TEST_F(CubicTest, LossEvents) {
72 const QuicTime::Delta rtt_min = hundred_ms_; 120 const QuicTime::Delta rtt_min = hundred_ms_;
73 uint32 current_cwnd = 422; 121 uint32 current_cwnd = 422;
74 uint32 expected_cwnd = current_cwnd + 1; 122 uint32 expected_cwnd = current_cwnd + 1;
75 // Initialize the state. 123 // Initialize the state.
76 clock_.AdvanceTime(one_ms_); 124 clock_.AdvanceTime(one_ms_);
77 EXPECT_EQ(expected_cwnd, 125 EXPECT_EQ(expected_cwnd,
78 cubic_.CongestionWindowAfterAck(current_cwnd, rtt_min)); 126 cubic_.CongestionWindowAfterAck(current_cwnd, rtt_min));
79 expected_cwnd = static_cast<int>(current_cwnd * kNConnectionBeta); 127 expected_cwnd = static_cast<int>(current_cwnd * kNConnectionBeta);
80 EXPECT_EQ(expected_cwnd, 128 EXPECT_EQ(expected_cwnd,
(...skipping 11 matching lines...) Expand all
92 // Initialize the state. 140 // Initialize the state.
93 clock_.AdvanceTime(one_ms_); 141 clock_.AdvanceTime(one_ms_);
94 EXPECT_EQ(expected_cwnd, 142 EXPECT_EQ(expected_cwnd,
95 cubic_.CongestionWindowAfterAck(current_cwnd, rtt_min)); 143 cubic_.CongestionWindowAfterAck(current_cwnd, rtt_min));
96 expected_cwnd = static_cast<int>(current_cwnd * kNConnectionBeta); 144 expected_cwnd = static_cast<int>(current_cwnd * kNConnectionBeta);
97 EXPECT_EQ(expected_cwnd, 145 EXPECT_EQ(expected_cwnd,
98 cubic_.CongestionWindowAfterPacketLoss(current_cwnd)); 146 cubic_.CongestionWindowAfterPacketLoss(current_cwnd));
99 current_cwnd = expected_cwnd; 147 current_cwnd = expected_cwnd;
100 // First update after loss to initialize the epoch. 148 // First update after loss to initialize the epoch.
101 current_cwnd = cubic_.CongestionWindowAfterAck(current_cwnd, rtt_min); 149 current_cwnd = cubic_.CongestionWindowAfterAck(current_cwnd, rtt_min);
150 uint32 old_cwnd = current_cwnd;
102 // Cubic phase. 151 // Cubic phase.
152 stats_.cwnd_increase_cubic_mode = 0;
153 stats_.cwnd_increase_reno_mode = 0;
103 for (int i = 0; i < 40 ; ++i) { 154 for (int i = 0; i < 40 ; ++i) {
104 clock_.AdvanceTime(hundred_ms_); 155 clock_.AdvanceTime(hundred_ms_);
105 current_cwnd = cubic_.CongestionWindowAfterAck(current_cwnd, rtt_min); 156 current_cwnd = cubic_.CongestionWindowAfterAck(current_cwnd, rtt_min);
106 } 157 }
107 expected_cwnd = 422; 158 expected_cwnd = 422;
108 EXPECT_EQ(expected_cwnd, current_cwnd); 159 EXPECT_EQ(expected_cwnd, current_cwnd);
160 EXPECT_EQ(expected_cwnd - old_cwnd, stats_.cwnd_increase_cubic_mode);
161 EXPECT_EQ(0u, stats_.cwnd_increase_reno_mode);
109 } 162 }
110 163
111 } // namespace test 164 } // namespace test
112 } // namespace net 165 } // namespace net
OLDNEW
« no previous file with comments | « net/quic/congestion_control/cubic.cc ('k') | net/quic/congestion_control/fix_rate_sender.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698