OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "net/quic/quic_sustained_bandwidth_recorder.h" | 5 #include "net/quic/quic_sustained_bandwidth_recorder.h" |
6 | 6 |
7 #include "net/quic/quic_bandwidth.h" | 7 #include "net/quic/quic_bandwidth.h" |
8 #include "net/quic/quic_time.h" | 8 #include "net/quic/quic_time.h" |
9 #include "testing/gtest/include/gtest/gtest.h" | 9 #include "testing/gtest/include/gtest/gtest.h" |
10 | 10 |
11 namespace net { | 11 namespace net { |
12 namespace test { | 12 namespace test { |
13 namespace { | 13 namespace { |
14 | 14 |
15 TEST(QuicSustainedBandwidthRecorderTest, BandwidthEstimates) { | 15 TEST(QuicSustainedBandwidthRecorderTest, BandwidthEstimates) { |
16 QuicSustainedBandwidthRecorder recorder; | 16 QuicSustainedBandwidthRecorder recorder; |
17 EXPECT_FALSE(recorder.HasEstimate()); | 17 EXPECT_FALSE(recorder.HasEstimate()); |
18 | 18 |
19 QuicTime estimate_time = QuicTime::Zero(); | 19 QuicTime estimate_time = QuicTime::Zero(); |
20 QuicWallTime wall_time = QuicWallTime::Zero(); | 20 QuicWallTime wall_time = QuicWallTime::Zero(); |
21 QuicTime::Delta srtt = QuicTime::Delta::FromMilliseconds(150); | 21 QuicTime::Delta srtt = QuicTime::Delta::FromMilliseconds(150); |
22 const int kBandwidthBitsPerSecond = 12345678; | 22 const int kBandwidthBitsPerSecond = 12345678; |
23 QuicBandwidth bandwidth = | 23 QuicBandwidth bandwidth = |
24 QuicBandwidth::FromBitsPerSecond(kBandwidthBitsPerSecond); | 24 QuicBandwidth::FromBitsPerSecond(kBandwidthBitsPerSecond); |
25 | 25 |
| 26 bool in_recovery = false; |
| 27 bool in_slow_start = false; |
| 28 |
26 // This triggers recording, but should not yield a valid estimate yet. | 29 // This triggers recording, but should not yield a valid estimate yet. |
27 recorder.RecordEstimate(true, false, bandwidth, estimate_time, wall_time, | 30 recorder.RecordEstimate(in_recovery, in_slow_start, bandwidth, estimate_time, |
28 srtt); | 31 wall_time, srtt); |
29 EXPECT_FALSE(recorder.HasEstimate()); | 32 EXPECT_FALSE(recorder.HasEstimate()); |
30 | 33 |
31 // Send a second reading, again this should not result in a valid estimate, | 34 // Send a second reading, again this should not result in a valid estimate, |
32 // as not enough time has passed. | 35 // as not enough time has passed. |
33 estimate_time = estimate_time.Add(srtt); | 36 estimate_time = estimate_time.Add(srtt); |
34 recorder.RecordEstimate(true, false, bandwidth, estimate_time, wall_time, | 37 recorder.RecordEstimate(in_recovery, in_slow_start, bandwidth, estimate_time, |
35 srtt); | 38 wall_time, srtt); |
36 EXPECT_FALSE(recorder.HasEstimate()); | 39 EXPECT_FALSE(recorder.HasEstimate()); |
37 | 40 |
38 // Now 3 * kSRTT has elapsed since first recording, expect a valid estimate. | 41 // Now 3 * kSRTT has elapsed since first recording, expect a valid estimate. |
39 estimate_time = estimate_time.Add(srtt); | 42 estimate_time = estimate_time.Add(srtt); |
40 estimate_time = estimate_time.Add(srtt); | 43 estimate_time = estimate_time.Add(srtt); |
41 recorder.RecordEstimate(true, false, bandwidth, estimate_time, wall_time, | 44 recorder.RecordEstimate(in_recovery, in_slow_start, bandwidth, estimate_time, |
42 srtt); | 45 wall_time, srtt); |
43 EXPECT_TRUE(recorder.HasEstimate()); | 46 EXPECT_TRUE(recorder.HasEstimate()); |
44 EXPECT_EQ(recorder.BandwidthEstimate(), bandwidth); | 47 EXPECT_EQ(recorder.BandwidthEstimate(), bandwidth); |
45 EXPECT_EQ(recorder.BandwidthEstimate(), recorder.MaxBandwidthEstimate()); | 48 EXPECT_EQ(recorder.BandwidthEstimate(), recorder.MaxBandwidthEstimate()); |
46 | 49 |
47 // Resetting, and sending a different estimate will only change output after | 50 // Resetting, and sending a different estimate will only change output after |
48 // a further 3 * kSRTT has passed. | 51 // a further 3 * kSRTT has passed. |
49 QuicBandwidth second_bandwidth = | 52 QuicBandwidth second_bandwidth = |
50 QuicBandwidth::FromBitsPerSecond(2 * kBandwidthBitsPerSecond); | 53 QuicBandwidth::FromBitsPerSecond(2 * kBandwidthBitsPerSecond); |
51 // Reset the recorder by passing in an unreliable measurement. | 54 // Reset the recorder by passing in a measurement while in recovery. |
52 recorder.RecordEstimate(false, false, second_bandwidth, estimate_time, | 55 in_recovery = true; |
| 56 recorder.RecordEstimate(in_recovery, in_slow_start, bandwidth, estimate_time, |
53 wall_time, srtt); | 57 wall_time, srtt); |
54 recorder.RecordEstimate(true, false, second_bandwidth, estimate_time, | 58 in_recovery = false; |
| 59 recorder.RecordEstimate(in_recovery, in_slow_start, bandwidth, estimate_time, |
55 wall_time, srtt); | 60 wall_time, srtt); |
56 EXPECT_EQ(recorder.BandwidthEstimate(), bandwidth); | 61 EXPECT_EQ(recorder.BandwidthEstimate(), bandwidth); |
57 | 62 |
58 estimate_time = estimate_time.Add(srtt.Multiply(3)); | 63 estimate_time = estimate_time.Add(srtt.Multiply(3)); |
59 const int32 kSeconds = 556677; | 64 const int32 kSeconds = 556677; |
60 QuicWallTime second_bandwidth_wall_time = | 65 QuicWallTime second_bandwidth_wall_time = |
61 QuicWallTime::FromUNIXSeconds(kSeconds); | 66 QuicWallTime::FromUNIXSeconds(kSeconds); |
62 recorder.RecordEstimate(true, false, second_bandwidth, estimate_time, | 67 recorder.RecordEstimate(in_recovery, in_slow_start, second_bandwidth, |
63 second_bandwidth_wall_time, srtt); | 68 estimate_time, second_bandwidth_wall_time, srtt); |
64 EXPECT_EQ(recorder.BandwidthEstimate(), second_bandwidth); | 69 EXPECT_EQ(recorder.BandwidthEstimate(), second_bandwidth); |
65 EXPECT_EQ(recorder.BandwidthEstimate(), recorder.MaxBandwidthEstimate()); | 70 EXPECT_EQ(recorder.BandwidthEstimate(), recorder.MaxBandwidthEstimate()); |
66 EXPECT_EQ(recorder.MaxBandwidthTimestamp(), kSeconds); | 71 EXPECT_EQ(recorder.MaxBandwidthTimestamp(), kSeconds); |
67 | 72 |
68 // Reset again, this time recording a lower bandwidth than before. | 73 // Reset again, this time recording a lower bandwidth than before. |
69 QuicBandwidth third_bandwidth = | 74 QuicBandwidth third_bandwidth = |
70 QuicBandwidth::FromBitsPerSecond(0.5 * kBandwidthBitsPerSecond); | 75 QuicBandwidth::FromBitsPerSecond(0.5 * kBandwidthBitsPerSecond); |
71 // Reset the recorder by passing in an unreliable measurement. | 76 // Reset the recorder by passing in an unreliable measurement. |
72 recorder.RecordEstimate(false, false, third_bandwidth, estimate_time, | 77 recorder.RecordEstimate(in_recovery, in_slow_start, third_bandwidth, |
73 wall_time, srtt); | 78 estimate_time, wall_time, srtt); |
74 recorder.RecordEstimate(true, false, third_bandwidth, estimate_time, | 79 recorder.RecordEstimate(in_recovery, in_slow_start, third_bandwidth, |
75 wall_time, srtt); | 80 estimate_time, wall_time, srtt); |
76 EXPECT_EQ(recorder.BandwidthEstimate(), second_bandwidth); | 81 EXPECT_EQ(recorder.BandwidthEstimate(), third_bandwidth); |
77 | 82 |
78 estimate_time = estimate_time.Add(srtt.Multiply(3)); | 83 estimate_time = estimate_time.Add(srtt.Multiply(3)); |
79 recorder.RecordEstimate(true, false, third_bandwidth, estimate_time, | 84 recorder.RecordEstimate(in_recovery, in_slow_start, third_bandwidth, |
80 wall_time, srtt); | 85 estimate_time, wall_time, srtt); |
81 EXPECT_EQ(recorder.BandwidthEstimate(), third_bandwidth); | 86 EXPECT_EQ(recorder.BandwidthEstimate(), third_bandwidth); |
82 | 87 |
83 // Max bandwidth should not have changed. | 88 // Max bandwidth should not have changed. |
84 EXPECT_LT(third_bandwidth, second_bandwidth); | 89 EXPECT_LT(third_bandwidth, second_bandwidth); |
85 EXPECT_EQ(recorder.MaxBandwidthEstimate(), second_bandwidth); | 90 EXPECT_EQ(recorder.MaxBandwidthEstimate(), second_bandwidth); |
86 EXPECT_EQ(recorder.MaxBandwidthTimestamp(), kSeconds); | 91 EXPECT_EQ(recorder.MaxBandwidthTimestamp(), kSeconds); |
87 } | 92 } |
88 | 93 |
89 TEST(QuicSustainedBandwidthRecorderTest, SlowStart) { | 94 TEST(QuicSustainedBandwidthRecorderTest, SlowStart) { |
90 // Verify that slow start status is correctly recorded. | 95 // Verify that slow start status is correctly recorded. |
91 QuicSustainedBandwidthRecorder recorder; | 96 QuicSustainedBandwidthRecorder recorder; |
92 EXPECT_FALSE(recorder.HasEstimate()); | 97 EXPECT_FALSE(recorder.HasEstimate()); |
93 | 98 |
94 QuicTime estimate_time = QuicTime::Zero(); | 99 QuicTime estimate_time = QuicTime::Zero(); |
95 QuicWallTime wall_time = QuicWallTime::Zero(); | 100 QuicWallTime wall_time = QuicWallTime::Zero(); |
96 QuicTime::Delta srtt = QuicTime::Delta::FromMilliseconds(150); | 101 QuicTime::Delta srtt = QuicTime::Delta::FromMilliseconds(150); |
97 const int kBandwidthBitsPerSecond = 12345678; | 102 const int kBandwidthBitsPerSecond = 12345678; |
98 QuicBandwidth bandwidth = | 103 QuicBandwidth bandwidth = |
99 QuicBandwidth::FromBitsPerSecond(kBandwidthBitsPerSecond); | 104 QuicBandwidth::FromBitsPerSecond(kBandwidthBitsPerSecond); |
100 | 105 |
| 106 bool in_recovery = false; |
101 bool in_slow_start = true; | 107 bool in_slow_start = true; |
102 | 108 |
103 // This triggers recording, but should not yield a valid estimate yet. | 109 // This triggers recording, but should not yield a valid estimate yet. |
104 recorder.RecordEstimate(true, in_slow_start, bandwidth, estimate_time, | 110 recorder.RecordEstimate(in_recovery, in_slow_start, bandwidth, estimate_time, |
105 wall_time, srtt); | 111 wall_time, srtt); |
106 | 112 |
107 // Now 3 * kSRTT has elapsed since first recording, expect a valid estimate. | 113 // Now 3 * kSRTT has elapsed since first recording, expect a valid estimate. |
108 estimate_time = estimate_time.Add(srtt.Multiply(3)); | 114 estimate_time = estimate_time.Add(srtt.Multiply(3)); |
109 recorder.RecordEstimate(true, in_slow_start, bandwidth, estimate_time, | 115 recorder.RecordEstimate(in_recovery, in_slow_start, bandwidth, estimate_time, |
110 wall_time, srtt); | 116 wall_time, srtt); |
111 EXPECT_TRUE(recorder.HasEstimate()); | 117 EXPECT_TRUE(recorder.HasEstimate()); |
112 EXPECT_TRUE(recorder.EstimateRecordedDuringSlowStart()); | 118 EXPECT_TRUE(recorder.EstimateRecordedDuringSlowStart()); |
113 | 119 |
114 // Now send another estimate, this time not in slow start. | 120 // Now send another estimate, this time not in slow start. |
115 estimate_time = estimate_time.Add(srtt.Multiply(3)); | 121 estimate_time = estimate_time.Add(srtt.Multiply(3)); |
116 in_slow_start = false; | 122 in_slow_start = false; |
117 recorder.RecordEstimate(true, in_slow_start, bandwidth, estimate_time, | 123 recorder.RecordEstimate(in_recovery, in_slow_start, bandwidth, estimate_time, |
118 wall_time, srtt); | 124 wall_time, srtt); |
119 EXPECT_TRUE(recorder.HasEstimate()); | 125 EXPECT_TRUE(recorder.HasEstimate()); |
120 EXPECT_FALSE(recorder.EstimateRecordedDuringSlowStart()); | 126 EXPECT_FALSE(recorder.EstimateRecordedDuringSlowStart()); |
121 } | 127 } |
122 | 128 |
123 } // namespace | 129 } // namespace |
124 } // namespace test | 130 } // namespace test |
125 } // namespace net | 131 } // namespace net |
OLD | NEW |