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

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

Issue 2193073003: Move shared files in net/quic/ into net/quic/core/ (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: io_thread_unittest.cc Created 4 years, 4 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
« no previous file with comments | « net/quic/congestion_control/cubic_bytes.cc ('k') | net/quic/congestion_control/cubic_test.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "net/quic/congestion_control/cubic_bytes.h"
6
7 #include "base/logging.h"
8 #include "net/quic/test_tools/mock_clock.h"
9 #include "testing/gtest/include/gtest/gtest.h"
10
11 namespace net {
12 namespace test {
13
14 const float kBeta = 0.7f; // Default Cubic backoff factor.
15 const uint32_t kNumConnections = 2;
16 const float kNConnectionBeta = (kNumConnections - 1 + kBeta) / kNumConnections;
17 const float kNConnectionAlpha = 3 * kNumConnections * kNumConnections *
18 (1 - kNConnectionBeta) / (1 + kNConnectionBeta);
19
20 class CubicBytesTest : public ::testing::Test {
21 protected:
22 CubicBytesTest()
23 : one_ms_(QuicTime::Delta::FromMilliseconds(1)),
24 hundred_ms_(QuicTime::Delta::FromMilliseconds(100)),
25 cubic_(&clock_) {}
26 const QuicTime::Delta one_ms_;
27 const QuicTime::Delta hundred_ms_;
28 MockClock clock_;
29 CubicBytes cubic_;
30 };
31
32 TEST_F(CubicBytesTest, AboveOrigin) {
33 // Convex growth.
34 const QuicTime::Delta rtt_min = hundred_ms_;
35 QuicByteCount current_cwnd = 10 * kDefaultTCPMSS;
36 QuicByteCount expected_cwnd = current_cwnd + kDefaultTCPMSS;
37 // Initialize the state.
38 clock_.AdvanceTime(one_ms_);
39 EXPECT_EQ(expected_cwnd, cubic_.CongestionWindowAfterAck(
40 kDefaultTCPMSS, current_cwnd, rtt_min));
41 current_cwnd = expected_cwnd;
42 // Normal TCP phase.
43 for (int i = 0; i < 48; ++i) {
44 for (QuicPacketCount n = 1;
45 n < current_cwnd / kDefaultTCPMSS / kNConnectionAlpha; ++n) {
46 // Call once per ACK.
47 EXPECT_NEAR(current_cwnd, cubic_.CongestionWindowAfterAck(
48 kDefaultTCPMSS, current_cwnd, rtt_min),
49 kDefaultTCPMSS);
50 }
51 clock_.AdvanceTime(hundred_ms_);
52 current_cwnd =
53 cubic_.CongestionWindowAfterAck(kDefaultTCPMSS, current_cwnd, rtt_min);
54 EXPECT_NEAR(expected_cwnd, current_cwnd, kDefaultTCPMSS);
55 expected_cwnd += kDefaultTCPMSS;
56 }
57 // Cubic phase.
58 for (int i = 0; i < 52; ++i) {
59 for (QuicPacketCount n = 1; n < current_cwnd / kDefaultTCPMSS; ++n) {
60 // Call once per ACK.
61 EXPECT_NEAR(current_cwnd, cubic_.CongestionWindowAfterAck(
62 kDefaultTCPMSS, current_cwnd, rtt_min),
63 kDefaultTCPMSS);
64 }
65 clock_.AdvanceTime(hundred_ms_);
66 current_cwnd =
67 cubic_.CongestionWindowAfterAck(kDefaultTCPMSS, current_cwnd, rtt_min);
68 }
69 // Total time elapsed so far; add min_rtt (0.1s) here as well.
70 float elapsed_time_s = 10.0f + 0.1f;
71 // |expected_cwnd| is initial value of cwnd + K * t^3, where K = 0.4.
72 expected_cwnd =
73 11 + (elapsed_time_s * elapsed_time_s * elapsed_time_s * 410) / 1024;
74 EXPECT_EQ(expected_cwnd, current_cwnd / kDefaultTCPMSS);
75 }
76
77 TEST_F(CubicBytesTest, LossEvents) {
78 const QuicTime::Delta rtt_min = hundred_ms_;
79 QuicByteCount current_cwnd = 422 * kDefaultTCPMSS;
80 QuicPacketCount expected_cwnd = current_cwnd + kDefaultTCPMSS;
81 // Initialize the state.
82 clock_.AdvanceTime(one_ms_);
83 EXPECT_EQ(expected_cwnd, cubic_.CongestionWindowAfterAck(
84 kDefaultTCPMSS, current_cwnd, rtt_min));
85 expected_cwnd = static_cast<QuicPacketCount>(current_cwnd * kNConnectionBeta);
86 EXPECT_EQ(expected_cwnd,
87 cubic_.CongestionWindowAfterPacketLoss(current_cwnd));
88 expected_cwnd = static_cast<QuicPacketCount>(current_cwnd * kNConnectionBeta);
89 EXPECT_EQ(expected_cwnd,
90 cubic_.CongestionWindowAfterPacketLoss(current_cwnd));
91 }
92
93 TEST_F(CubicBytesTest, BelowOrigin) {
94 // Concave growth.
95 const QuicTime::Delta rtt_min = hundred_ms_;
96 QuicByteCount current_cwnd = 422 * kDefaultTCPMSS;
97 QuicPacketCount expected_cwnd = current_cwnd + kDefaultTCPMSS;
98 // Initialize the state.
99 clock_.AdvanceTime(one_ms_);
100 EXPECT_EQ(expected_cwnd, cubic_.CongestionWindowAfterAck(
101 kDefaultTCPMSS, current_cwnd, rtt_min));
102 expected_cwnd = static_cast<QuicPacketCount>(current_cwnd * kNConnectionBeta);
103 EXPECT_EQ(expected_cwnd,
104 cubic_.CongestionWindowAfterPacketLoss(current_cwnd));
105 current_cwnd = expected_cwnd;
106 // First update after loss to initialize the epoch.
107 current_cwnd =
108 cubic_.CongestionWindowAfterAck(kDefaultTCPMSS, current_cwnd, rtt_min);
109 // Cubic phase.
110 for (int i = 0; i < 40; ++i) {
111 clock_.AdvanceTime(hundred_ms_);
112 current_cwnd =
113 cubic_.CongestionWindowAfterAck(kDefaultTCPMSS, current_cwnd, rtt_min);
114 }
115 expected_cwnd = 422 * kDefaultTCPMSS;
116 EXPECT_EQ(expected_cwnd, current_cwnd);
117 }
118
119 } // namespace test
120 } // namespace net
OLDNEW
« no previous file with comments | « net/quic/congestion_control/cubic_bytes.cc ('k') | net/quic/congestion_control/cubic_test.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698