1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
|
// Copyright (c) 2013 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "base/logging.h"
#include "net/quic/congestion_control/channel_estimator.h"
#include "net/quic/test_tools/mock_clock.h"
#include "testing/gtest/include/gtest/gtest.h"
namespace net {
namespace test {
class ChannelEstimatorTest : public ::testing::Test {
protected:
virtual void SetUp() {
srand(1234);
packet_size_ = 1200;
sequence_number_ = 1;
}
QuicPacketSequenceNumber sequence_number_;
QuicByteCount packet_size_;
MockClock send_clock_;
MockClock receive_clock_;
ChannelEstimator channel_estimator_;
};
TEST_F(ChannelEstimatorTest, SimpleNonDetect) {
// In this test, the send times differ by the same delta as the receive times,
// so we haven't sent packets closely enough to detect "spreading," or
// effective bandwidth.
QuicTime::Delta delta = QuicTime::Delta::FromMilliseconds(10);
for (int i = 0; i < 1000; ++i) {
QuicTime send_time = send_clock_.ApproximateNow();
QuicTime receive_time = receive_clock_.ApproximateNow();
channel_estimator_.OnAcknowledgedPacket(sequence_number_++,
packet_size_,
send_time,
receive_time);
send_clock_.AdvanceTime(delta);
receive_clock_.AdvanceTime(delta);
}
QuicBandwidth estimate = QuicBandwidth::Zero();
EXPECT_EQ(kChannelEstimateUnknown,
channel_estimator_.GetChannelEstimate(&estimate));
EXPECT_TRUE(estimate.IsZero());
}
TEST_F(ChannelEstimatorTest, SimplePacketPairDetect) {
// In this test, we start by sending packet pairs back-to-back and
// add a receive side spreading that indicate an effective bandwidth.
// We do 2 testes with different effective bandwidth to make sure that we
// detect the new effective bandwidth.
QuicTime::Delta received_delta = QuicTime::Delta::FromMilliseconds(5);
QuicTime::Delta send_delta = QuicTime::Delta::FromMilliseconds(10);
for (int i = 0; i < 100; ++i) {
receive_clock_.AdvanceTime(received_delta);
QuicTime receive_time = receive_clock_.ApproximateNow();
QuicTime send_time = send_clock_.ApproximateNow();
channel_estimator_.OnAcknowledgedPacket(sequence_number_++,
packet_size_,
send_time,
receive_time);
receive_clock_.AdvanceTime(received_delta);
receive_time = receive_clock_.ApproximateNow();
channel_estimator_.OnAcknowledgedPacket(sequence_number_++,
packet_size_,
send_time,
receive_time);
send_clock_.AdvanceTime(send_delta);
}
QuicBandwidth estimate = QuicBandwidth::Zero();
EXPECT_EQ(kChannelEstimateGood,
channel_estimator_.GetChannelEstimate(&estimate));
EXPECT_EQ(QuicBandwidth::FromBytesAndTimeDelta(packet_size_, received_delta),
estimate);
received_delta = QuicTime::Delta::FromMilliseconds(1);
for (int i = 0; i < 100; ++i) {
receive_clock_.AdvanceTime(received_delta);
QuicTime receive_time = receive_clock_.ApproximateNow();
QuicTime send_time = send_clock_.ApproximateNow();
channel_estimator_.OnAcknowledgedPacket(sequence_number_++,
packet_size_,
send_time,
receive_time);
receive_clock_.AdvanceTime(received_delta);
receive_time = receive_clock_.ApproximateNow();
channel_estimator_.OnAcknowledgedPacket(sequence_number_++,
packet_size_,
send_time,
receive_time);
send_clock_.AdvanceTime(send_delta);
}
EXPECT_EQ(kChannelEstimateGood,
channel_estimator_.GetChannelEstimate(&estimate));
EXPECT_EQ(QuicBandwidth::FromBytesAndTimeDelta(packet_size_, received_delta),
estimate);
}
TEST_F(ChannelEstimatorTest, SimpleFlatSlope) {
// In this test, we send packet pairs back-to-back and add a slowly increasing
// receive side spreading. We expect the estimate to be good and that our
// mean receive side spreading is returned as the estimate.
QuicTime::Delta initial_received_delta = QuicTime::Delta::FromMilliseconds(5);
QuicTime::Delta received_delta = initial_received_delta;
QuicTime::Delta send_delta = QuicTime::Delta::FromMilliseconds(10);
for (int i = 0; i < 100; ++i) {
receive_clock_.AdvanceTime(received_delta);
QuicTime receive_time = receive_clock_.ApproximateNow();
QuicTime send_time = send_clock_.ApproximateNow();
channel_estimator_.OnAcknowledgedPacket(sequence_number_++,
packet_size_,
send_time,
receive_time);
receive_clock_.AdvanceTime(received_delta);
receive_time = receive_clock_.ApproximateNow();
channel_estimator_.OnAcknowledgedPacket(sequence_number_++,
packet_size_,
send_time,
receive_time);
send_clock_.AdvanceTime(send_delta);
received_delta = received_delta.Add(QuicTime::Delta::FromMicroseconds(10));
}
QuicBandwidth estimate = QuicBandwidth::Zero();
EXPECT_EQ(kChannelEstimateGood,
channel_estimator_.GetChannelEstimate(&estimate));
// Calculate our mean receive delta.
QuicTime::Delta increased_received_delta =
received_delta.Subtract(initial_received_delta);
QuicTime::Delta mean_received_delta = initial_received_delta.Add(
QuicTime::Delta::FromMicroseconds(
increased_received_delta.ToMicroseconds() / 2));
EXPECT_EQ(QuicBandwidth::FromBytesAndTimeDelta(packet_size_,
mean_received_delta), estimate);
}
TEST_F(ChannelEstimatorTest, SimpleMediumSlope) {
// In this test, we send packet pairs back-to-back and add an increasing
// receive side spreading. We expect the estimate to be uncertaint and that
// our mean receive side spreading is returned as the estimate.
QuicTime::Delta initial_received_delta = QuicTime::Delta::FromMilliseconds(5);
QuicTime::Delta received_delta = initial_received_delta;
QuicTime::Delta send_delta = QuicTime::Delta::FromMilliseconds(10);
for (int i = 0; i < 100; ++i) {
receive_clock_.AdvanceTime(received_delta);
QuicTime receive_time = receive_clock_.ApproximateNow();
QuicTime send_time = send_clock_.ApproximateNow();
channel_estimator_.OnAcknowledgedPacket(sequence_number_++,
packet_size_,
send_time,
receive_time);
receive_clock_.AdvanceTime(received_delta);
receive_time = receive_clock_.ApproximateNow();
channel_estimator_.OnAcknowledgedPacket(sequence_number_++,
packet_size_,
send_time,
receive_time);
send_clock_.AdvanceTime(send_delta);
received_delta = received_delta.Add(QuicTime::Delta::FromMicroseconds(50));
}
QuicBandwidth estimate = QuicBandwidth::Zero();
EXPECT_EQ(kChannelEstimateUncertain,
channel_estimator_.GetChannelEstimate(&estimate));
// Calculate our mean receive delta.
QuicTime::Delta increased_received_delta =
received_delta.Subtract(initial_received_delta);
QuicTime::Delta mean_received_delta = initial_received_delta.Add(
QuicTime::Delta::FromMicroseconds(
increased_received_delta.ToMicroseconds() / 2));
EXPECT_EQ(QuicBandwidth::FromBytesAndTimeDelta(packet_size_,
mean_received_delta), estimate);
}
TEST_F(ChannelEstimatorTest, SimpleSteepSlope) {
// In this test, we send packet pairs back-to-back and add a rapidly
// increasing receive side spreading. We expect the estimate to be uncertain
// and that our mean receive side spreading is returned as the estimate.
QuicTime::Delta initial_received_delta = QuicTime::Delta::FromMilliseconds(5);
QuicTime::Delta received_delta = initial_received_delta;
QuicTime::Delta send_delta = QuicTime::Delta::FromMilliseconds(10);
for (int i = 0; i < 100; ++i) {
receive_clock_.AdvanceTime(received_delta);
QuicTime receive_time = receive_clock_.ApproximateNow();
QuicTime send_time = send_clock_.ApproximateNow();
channel_estimator_.OnAcknowledgedPacket(sequence_number_++,
packet_size_,
send_time,
receive_time);
receive_clock_.AdvanceTime(received_delta);
receive_time = receive_clock_.ApproximateNow();
channel_estimator_.OnAcknowledgedPacket(sequence_number_++,
packet_size_,
send_time,
receive_time);
send_clock_.AdvanceTime(send_delta);
received_delta = received_delta.Add(QuicTime::Delta::FromMicroseconds(100));
}
QuicBandwidth estimate = QuicBandwidth::Zero();
EXPECT_EQ(kChannelEstimateUncertain,
channel_estimator_.GetChannelEstimate(&estimate));
// Calculate our mean receive delta.
QuicTime::Delta increased_received_delta =
received_delta.Subtract(initial_received_delta);
QuicTime::Delta mean_received_delta = initial_received_delta.Add(
QuicTime::Delta::FromMicroseconds(
increased_received_delta.ToMicroseconds() / 2));
EXPECT_EQ(QuicBandwidth::FromBytesAndTimeDelta(packet_size_,
mean_received_delta), estimate);
}
} // namespace test
} // namespace net
|