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