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/logging.h" | 5 #include "base/logging.h" |
6 #include "base/memory/scoped_ptr.h" | 6 #include "base/memory/scoped_ptr.h" |
7 #include "net/quic/congestion_control/hybrid_slow_start.h" | 7 #include "net/quic/congestion_control/hybrid_slow_start.h" |
8 #include "net/quic/test_tools/mock_clock.h" | 8 #include "net/quic/test_tools/mock_clock.h" |
9 #include "testing/gtest/include/gtest/gtest.h" | 9 #include "testing/gtest/include/gtest/gtest.h" |
10 | 10 |
(...skipping 36 matching lines...) Loading... |
47 } | 47 } |
48 EXPECT_TRUE(slow_start_->IsEndOfRound(sequence_number++)); | 48 EXPECT_TRUE(slow_start_->IsEndOfRound(sequence_number++)); |
49 } | 49 } |
50 | 50 |
51 // TODO(ianswett): Add tests which more realistically invoke the methods, | 51 // TODO(ianswett): Add tests which more realistically invoke the methods, |
52 // simulating how actual acks arrive and packets are sent. | 52 // simulating how actual acks arrive and packets are sent. |
53 TEST_F(HybridSlowStartTest, AckTrain) { | 53 TEST_F(HybridSlowStartTest, AckTrain) { |
54 // At a typical RTT 60 ms, assuming that the inter arrival timestamp is 1 ms, | 54 // At a typical RTT 60 ms, assuming that the inter arrival timestamp is 1 ms, |
55 // we expect to be able to send a burst of 30 packet before we trigger the | 55 // we expect to be able to send a burst of 30 packet before we trigger the |
56 // ack train detection. | 56 // ack train detection. |
57 const int kMaxLoopCount = 5; | 57 // Run this test for both enabled and disabled ack train detection. |
58 QuicPacketSequenceNumber sequence_number = 2; | 58 for (int i = 0; i < 2; ++i) { |
59 QuicPacketSequenceNumber end_sequence_number = 2; | 59 const bool ack_train_detection = (i == 1); |
60 for (int burst = 0; burst < kMaxLoopCount; ++burst) { | 60 slow_start_->set_ack_train_detection(ack_train_detection); |
| 61 |
| 62 const int kMaxLoopCount = 5; |
| 63 QuicPacketSequenceNumber sequence_number = 2; |
| 64 QuicPacketSequenceNumber end_sequence_number = 2; |
| 65 for (int burst = 0; burst < kMaxLoopCount; ++burst) { |
| 66 slow_start_->StartReceiveRound(end_sequence_number); |
| 67 do { |
| 68 clock_.AdvanceTime(one_ms_); |
| 69 EXPECT_FALSE(slow_start_->ShouldExitSlowStart(rtt_, rtt_, 100)); |
| 70 } while (!slow_start_->IsEndOfRound(sequence_number++)); |
| 71 end_sequence_number *= 2; // Exponential growth. |
| 72 } |
61 slow_start_->StartReceiveRound(end_sequence_number); | 73 slow_start_->StartReceiveRound(end_sequence_number); |
62 do { | 74 |
| 75 for (int n = 0; |
| 76 n < 29 && !slow_start_->IsEndOfRound(sequence_number++); ++n) { |
63 clock_.AdvanceTime(one_ms_); | 77 clock_.AdvanceTime(one_ms_); |
64 EXPECT_FALSE(slow_start_->ShouldExitSlowStart(rtt_, rtt_, 100)); | 78 EXPECT_FALSE(slow_start_->ShouldExitSlowStart(rtt_, rtt_, 100)); |
65 } while (!slow_start_->IsEndOfRound(sequence_number++)); | 79 } |
66 end_sequence_number *= 2; // Exponential growth. | 80 clock_.AdvanceTime(one_ms_); |
| 81 EXPECT_EQ(ack_train_detection, |
| 82 slow_start_->ShouldExitSlowStart(rtt_, rtt_, 100)); |
67 } | 83 } |
68 slow_start_->StartReceiveRound(end_sequence_number); | |
69 | |
70 for (int n = 0; | |
71 n < 29 && !slow_start_->IsEndOfRound(sequence_number++); ++n) { | |
72 clock_.AdvanceTime(one_ms_); | |
73 EXPECT_FALSE(slow_start_->ShouldExitSlowStart(rtt_, rtt_, 100)); | |
74 } | |
75 clock_.AdvanceTime(one_ms_); | |
76 EXPECT_TRUE(slow_start_->ShouldExitSlowStart(rtt_, rtt_, 100)); | |
77 } | 84 } |
78 | 85 |
79 TEST_F(HybridSlowStartTest, Delay) { | 86 TEST_F(HybridSlowStartTest, Delay) { |
80 // We expect to detect the increase at +1/16 of the RTT; hence at a typical | 87 // We expect to detect the increase at +1/16 of the RTT; hence at a typical |
81 // RTT of 60ms the detection will happen at 63.75 ms. | 88 // RTT of 60ms the detection will happen at 63.75 ms. |
82 const int kHybridStartMinSamples = 8; // Number of acks required to trigger. | 89 const int kHybridStartMinSamples = 8; // Number of acks required to trigger. |
83 | 90 |
84 QuicPacketSequenceNumber end_sequence_number = 1; | 91 QuicPacketSequenceNumber end_sequence_number = 1; |
85 slow_start_->StartReceiveRound(end_sequence_number++); | 92 slow_start_->StartReceiveRound(end_sequence_number++); |
86 | 93 |
87 // Will not trigger since our lowest RTT in our burst is the same as the long | 94 // Will not trigger since our lowest RTT in our burst is the same as the long |
88 // term RTT provided. | 95 // term RTT provided. |
89 for (int n = 0; n < kHybridStartMinSamples; ++n) { | 96 for (int n = 0; n < kHybridStartMinSamples; ++n) { |
90 EXPECT_FALSE(slow_start_->ShouldExitSlowStart( | 97 EXPECT_FALSE(slow_start_->ShouldExitSlowStart( |
91 rtt_.Add(QuicTime::Delta::FromMilliseconds(n)), rtt_, 100)); | 98 rtt_.Add(QuicTime::Delta::FromMilliseconds(n)), rtt_, 100)); |
92 } | 99 } |
93 slow_start_->StartReceiveRound(end_sequence_number++); | 100 slow_start_->StartReceiveRound(end_sequence_number++); |
94 for (int n = 1; n < kHybridStartMinSamples; ++n) { | 101 for (int n = 1; n < kHybridStartMinSamples; ++n) { |
95 EXPECT_FALSE(slow_start_->ShouldExitSlowStart( | 102 EXPECT_FALSE(slow_start_->ShouldExitSlowStart( |
96 rtt_.Add(QuicTime::Delta::FromMilliseconds(n + 5)), rtt_, 100)); | 103 rtt_.Add(QuicTime::Delta::FromMilliseconds(n + 5)), rtt_, 100)); |
97 } | 104 } |
98 // Expect to trigger since all packets in this burst was above the long term | 105 // Expect to trigger since all packets in this burst was above the long term |
99 // RTT provided. | 106 // RTT provided. |
100 EXPECT_TRUE(slow_start_->ShouldExitSlowStart( | 107 EXPECT_TRUE(slow_start_->ShouldExitSlowStart( |
101 rtt_.Add(QuicTime::Delta::FromMilliseconds(5)), rtt_, 100)); | 108 rtt_.Add(QuicTime::Delta::FromMilliseconds(5)), rtt_, 100)); |
102 } | 109 } |
103 | 110 |
104 } // namespace test | 111 } // namespace test |
105 } // namespace net | 112 } // namespace net |
OLD | NEW |