| OLD | NEW |
| (Empty) |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "net/quic/congestion_control/cubic.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 CubicTest : public ::testing::Test { | |
| 21 protected: | |
| 22 CubicTest() | |
| 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 Cubic cubic_; | |
| 30 }; | |
| 31 | |
| 32 TEST_F(CubicTest, AboveOrigin) { | |
| 33 // Convex growth. | |
| 34 const QuicTime::Delta rtt_min = hundred_ms_; | |
| 35 QuicPacketCount current_cwnd = 10; | |
| 36 QuicPacketCount expected_cwnd = current_cwnd + 1; | |
| 37 // Initialize the state. | |
| 38 clock_.AdvanceTime(one_ms_); | |
| 39 EXPECT_EQ(expected_cwnd, | |
| 40 cubic_.CongestionWindowAfterAck(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; n < current_cwnd / kNConnectionAlpha; ++n) { | |
| 45 // Call once per ACK. | |
| 46 EXPECT_NEAR(current_cwnd, | |
| 47 cubic_.CongestionWindowAfterAck(current_cwnd, rtt_min), 1); | |
| 48 } | |
| 49 clock_.AdvanceTime(hundred_ms_); | |
| 50 current_cwnd = cubic_.CongestionWindowAfterAck(current_cwnd, rtt_min); | |
| 51 EXPECT_NEAR(expected_cwnd, current_cwnd, 1); | |
| 52 expected_cwnd++; | |
| 53 } | |
| 54 // Cubic phase. | |
| 55 for (int i = 0; i < 52; ++i) { | |
| 56 for (QuicPacketCount n = 1; n < current_cwnd; ++n) { | |
| 57 // Call once per ACK. | |
| 58 EXPECT_EQ(current_cwnd, | |
| 59 cubic_.CongestionWindowAfterAck(current_cwnd, rtt_min)); | |
| 60 } | |
| 61 clock_.AdvanceTime(hundred_ms_); | |
| 62 current_cwnd = cubic_.CongestionWindowAfterAck(current_cwnd, rtt_min); | |
| 63 } | |
| 64 // Total time elapsed so far; add min_rtt (0.1s) here as well. | |
| 65 float elapsed_time_s = 10.0f + 0.1f; | |
| 66 // |expected_cwnd| is initial value of cwnd + K * t^3, where K = 0.4. | |
| 67 expected_cwnd = | |
| 68 11 + (elapsed_time_s * elapsed_time_s * elapsed_time_s * 410) / 1024; | |
| 69 EXPECT_EQ(expected_cwnd, current_cwnd); | |
| 70 } | |
| 71 | |
| 72 TEST_F(CubicTest, LossEvents) { | |
| 73 const QuicTime::Delta rtt_min = hundred_ms_; | |
| 74 QuicPacketCount current_cwnd = 422; | |
| 75 QuicPacketCount expected_cwnd = current_cwnd + 1; | |
| 76 // Initialize the state. | |
| 77 clock_.AdvanceTime(one_ms_); | |
| 78 EXPECT_EQ(expected_cwnd, | |
| 79 cubic_.CongestionWindowAfterAck(current_cwnd, rtt_min)); | |
| 80 expected_cwnd = static_cast<QuicPacketCount>(current_cwnd * kNConnectionBeta); | |
| 81 EXPECT_EQ(expected_cwnd, | |
| 82 cubic_.CongestionWindowAfterPacketLoss(current_cwnd)); | |
| 83 expected_cwnd = static_cast<QuicPacketCount>(current_cwnd * kNConnectionBeta); | |
| 84 EXPECT_EQ(expected_cwnd, | |
| 85 cubic_.CongestionWindowAfterPacketLoss(current_cwnd)); | |
| 86 } | |
| 87 | |
| 88 TEST_F(CubicTest, BelowOrigin) { | |
| 89 // Concave growth. | |
| 90 const QuicTime::Delta rtt_min = hundred_ms_; | |
| 91 QuicPacketCount current_cwnd = 422; | |
| 92 QuicPacketCount expected_cwnd = current_cwnd + 1; | |
| 93 // Initialize the state. | |
| 94 clock_.AdvanceTime(one_ms_); | |
| 95 EXPECT_EQ(expected_cwnd, | |
| 96 cubic_.CongestionWindowAfterAck(current_cwnd, rtt_min)); | |
| 97 expected_cwnd = static_cast<QuicPacketCount>(current_cwnd * kNConnectionBeta); | |
| 98 EXPECT_EQ(expected_cwnd, | |
| 99 cubic_.CongestionWindowAfterPacketLoss(current_cwnd)); | |
| 100 current_cwnd = expected_cwnd; | |
| 101 // First update after loss to initialize the epoch. | |
| 102 current_cwnd = cubic_.CongestionWindowAfterAck(current_cwnd, rtt_min); | |
| 103 // Cubic phase. | |
| 104 for (int i = 0; i < 40; ++i) { | |
| 105 clock_.AdvanceTime(hundred_ms_); | |
| 106 current_cwnd = cubic_.CongestionWindowAfterAck(current_cwnd, rtt_min); | |
| 107 } | |
| 108 expected_cwnd = 422; | |
| 109 EXPECT_EQ(expected_cwnd, current_cwnd); | |
| 110 } | |
| 111 | |
| 112 } // namespace test | |
| 113 } // namespace net | |
| OLD | NEW |