OLD | NEW |
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 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/congestion_control/pacing_sender.h" | 5 #include "net/quic/congestion_control/pacing_sender.h" |
6 | 6 |
7 #include "base/logging.h" | 7 #include "base/logging.h" |
8 #include "base/memory/scoped_ptr.h" | 8 #include "base/memory/scoped_ptr.h" |
9 #include "net/quic/quic_protocol.h" | 9 #include "net/quic/quic_protocol.h" |
10 #include "net/quic/test_tools/mock_clock.h" | 10 #include "net/quic/test_tools/mock_clock.h" |
11 #include "net/quic/test_tools/quic_test_utils.h" | 11 #include "net/quic/test_tools/quic_test_utils.h" |
12 #include "testing/gtest/include/gtest/gtest.h" | 12 #include "testing/gtest/include/gtest/gtest.h" |
13 | 13 |
14 using testing::Return; | 14 using testing::Return; |
15 using testing::StrictMock; | 15 using testing::StrictMock; |
16 using testing::_; | 16 using testing::_; |
17 | 17 |
18 namespace net { | 18 namespace net { |
19 namespace test { | 19 namespace test { |
20 | 20 |
21 const QuicByteCount kBytesInFlight = 1024; | 21 const QuicByteCount kBytesInFlight = 1024; |
| 22 const int kInitialBurstPackets = 10; |
22 | 23 |
23 class PacingSenderTest : public ::testing::Test { | 24 class PacingSenderTest : public ::testing::Test { |
24 protected: | 25 protected: |
25 PacingSenderTest() | 26 PacingSenderTest() |
26 : zero_time_(QuicTime::Delta::Zero()), | 27 : zero_time_(QuicTime::Delta::Zero()), |
27 infinite_time_(QuicTime::Delta::Infinite()), | 28 infinite_time_(QuicTime::Delta::Infinite()), |
28 sequence_number_(1), | 29 sequence_number_(1), |
29 mock_sender_(new StrictMock<MockSendAlgorithm>()), | 30 mock_sender_(new StrictMock<MockSendAlgorithm>()), |
30 pacing_sender_(new PacingSender(mock_sender_, | 31 pacing_sender_(new PacingSender(mock_sender_, |
31 QuicTime::Delta::FromMilliseconds(1), | 32 QuicTime::Delta::FromMilliseconds(1), |
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
135 TEST_F(PacingSenderTest, VariousSending) { | 136 TEST_F(PacingSenderTest, VariousSending) { |
136 // Start the test in slow start. | 137 // Start the test in slow start. |
137 EXPECT_CALL(*mock_sender_, InSlowStart()).WillRepeatedly(Return(true)); | 138 EXPECT_CALL(*mock_sender_, InSlowStart()).WillRepeatedly(Return(true)); |
138 | 139 |
139 // Configure bandwith of 1 packet per 2 ms, for which the pacing rate | 140 // Configure bandwith of 1 packet per 2 ms, for which the pacing rate |
140 // will be 1 packet per 1 ms. | 141 // will be 1 packet per 1 ms. |
141 EXPECT_CALL(*mock_sender_, BandwidthEstimate()) | 142 EXPECT_CALL(*mock_sender_, BandwidthEstimate()) |
142 .WillRepeatedly(Return(QuicBandwidth::FromBytesAndTimeDelta( | 143 .WillRepeatedly(Return(QuicBandwidth::FromBytesAndTimeDelta( |
143 kMaxPacketSize, QuicTime::Delta::FromMilliseconds(2)))); | 144 kMaxPacketSize, QuicTime::Delta::FromMilliseconds(2)))); |
144 | 145 |
145 // Send a whole pile of packets, and verify that they are not paced. | |
146 for (int i = 0 ; i < 1000; ++i) { | |
147 CheckPacketIsSentImmediately(); | |
148 } | |
149 | |
150 // Now update the RTT and verify that packets are actually paced. | 146 // Now update the RTT and verify that packets are actually paced. |
151 EXPECT_CALL(*mock_sender_, OnCongestionEvent(true, kBytesInFlight, _, _)); | 147 EXPECT_CALL(*mock_sender_, OnCongestionEvent(true, kBytesInFlight, _, _)); |
152 SendAlgorithmInterface::CongestionVector empty_map; | 148 SendAlgorithmInterface::CongestionVector empty_map; |
153 pacing_sender_->OnCongestionEvent(true, kBytesInFlight, empty_map, empty_map); | 149 pacing_sender_->OnCongestionEvent(true, kBytesInFlight, empty_map, empty_map); |
154 | 150 |
155 CheckPacketIsSentImmediately(); | 151 CheckPacketIsSentImmediately(); |
156 CheckPacketIsSentImmediately(); | 152 CheckPacketIsSentImmediately(); |
157 CheckPacketIsSentImmediately(); | 153 CheckPacketIsSentImmediately(); |
158 | 154 |
159 // The first packet was a "make up", then we sent two packets "into the | 155 // The first packet was a "make up", then we sent two packets "into the |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
210 TEST_F(PacingSenderTest, CongestionAvoidanceSending) { | 206 TEST_F(PacingSenderTest, CongestionAvoidanceSending) { |
211 // Start the test in congestion avoidance. | 207 // Start the test in congestion avoidance. |
212 EXPECT_CALL(*mock_sender_, InSlowStart()).WillRepeatedly(Return(false)); | 208 EXPECT_CALL(*mock_sender_, InSlowStart()).WillRepeatedly(Return(false)); |
213 | 209 |
214 // Configure bandwith of 1 packet per 2 ms, for which the pacing rate | 210 // Configure bandwith of 1 packet per 2 ms, for which the pacing rate |
215 // will be 1 packet per 1 ms. | 211 // will be 1 packet per 1 ms. |
216 EXPECT_CALL(*mock_sender_, BandwidthEstimate()) | 212 EXPECT_CALL(*mock_sender_, BandwidthEstimate()) |
217 .WillRepeatedly(Return(QuicBandwidth::FromBytesAndTimeDelta( | 213 .WillRepeatedly(Return(QuicBandwidth::FromBytesAndTimeDelta( |
218 kMaxPacketSize, QuicTime::Delta::FromMilliseconds(2)))); | 214 kMaxPacketSize, QuicTime::Delta::FromMilliseconds(2)))); |
219 | 215 |
220 // Send a whole pile of packets, and verify that they are not paced. | |
221 for (int i = 0 ; i < 1000; ++i) { | |
222 CheckPacketIsSentImmediately(); | |
223 } | |
224 | |
225 // Now update the RTT and verify that packets are actually paced. | 216 // Now update the RTT and verify that packets are actually paced. |
226 EXPECT_CALL(*mock_sender_, OnCongestionEvent(true, kBytesInFlight, _, _)); | 217 EXPECT_CALL(*mock_sender_, OnCongestionEvent(true, kBytesInFlight, _, _)); |
227 SendAlgorithmInterface::CongestionVector empty_map; | 218 SendAlgorithmInterface::CongestionVector empty_map; |
228 pacing_sender_->OnCongestionEvent(true, kBytesInFlight, empty_map, empty_map); | 219 pacing_sender_->OnCongestionEvent(true, kBytesInFlight, empty_map, empty_map); |
229 | 220 |
230 CheckPacketIsSentImmediately(); | 221 CheckPacketIsSentImmediately(); |
231 CheckPacketIsSentImmediately(); | 222 CheckPacketIsSentImmediately(); |
232 | 223 |
233 // The first packet was a "make up", then we sent two packets "into the | 224 // The first packet was a "make up", then we sent two packets "into the |
234 // future", so the delay should be 2200us. | 225 // future", so the delay should be 2200us. |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
289 EXPECT_CALL(*mock_sender_, BandwidthEstimate()) | 280 EXPECT_CALL(*mock_sender_, BandwidthEstimate()) |
290 .WillRepeatedly(Return(QuicBandwidth::FromBytesAndTimeDelta( | 281 .WillRepeatedly(Return(QuicBandwidth::FromBytesAndTimeDelta( |
291 kMaxPacketSize, QuicTime::Delta::FromMilliseconds(2)))); | 282 kMaxPacketSize, QuicTime::Delta::FromMilliseconds(2)))); |
292 | 283 |
293 // Update the RTT and verify that the first 10 packets aren't paced. | 284 // Update the RTT and verify that the first 10 packets aren't paced. |
294 EXPECT_CALL(*mock_sender_, OnCongestionEvent(true, kBytesInFlight, _, _)); | 285 EXPECT_CALL(*mock_sender_, OnCongestionEvent(true, kBytesInFlight, _, _)); |
295 SendAlgorithmInterface::CongestionVector empty_map; | 286 SendAlgorithmInterface::CongestionVector empty_map; |
296 pacing_sender_->OnCongestionEvent(true, kBytesInFlight, empty_map, empty_map); | 287 pacing_sender_->OnCongestionEvent(true, kBytesInFlight, empty_map, empty_map); |
297 | 288 |
298 // Send 10 packets, and verify that they are not paced. | 289 // Send 10 packets, and verify that they are not paced. |
299 for (int i = 0 ; i < 10; ++i) { | 290 for (int i = 0 ; i < kInitialBurstPackets; ++i) { |
300 CheckPacketIsSentImmediately(); | 291 CheckPacketIsSentImmediately(); |
301 } | 292 } |
302 | 293 |
| 294 // The first packet was a "make up", then we sent two packets "into the |
| 295 // future", so the delay should be 2ms. |
303 CheckPacketIsSentImmediately(); | 296 CheckPacketIsSentImmediately(); |
304 CheckPacketIsSentImmediately(); | 297 CheckPacketIsSentImmediately(); |
305 CheckPacketIsSentImmediately(); | 298 CheckPacketIsSentImmediately(); |
| 299 CheckPacketIsDelayed(QuicTime::Delta::FromMilliseconds(2)); |
306 | 300 |
307 // The first packet was a "make up", then we sent two packets "into the | |
308 // future", so the delay should be 2. | |
309 CheckPacketIsDelayed(QuicTime::Delta::FromMilliseconds(2)); | |
310 clock_.AdvanceTime(QuicTime::Delta::FromMilliseconds(5)); | 301 clock_.AdvanceTime(QuicTime::Delta::FromMilliseconds(5)); |
311 CheckPacketIsSentImmediately(); | 302 CheckPacketIsSentImmediately(); |
312 | 303 |
| 304 // Next time TimeUntilSend is called with no bytes in flight, the tokens |
| 305 // should be refilled and there should be no delay. |
| 306 EXPECT_CALL(*mock_sender_, |
| 307 TimeUntilSend(clock_.Now(), |
| 308 0, |
| 309 HAS_RETRANSMITTABLE_DATA)). |
| 310 WillOnce(Return(zero_time_)); |
| 311 EXPECT_EQ(zero_time_, |
| 312 pacing_sender_->TimeUntilSend(clock_.Now(), |
| 313 0, |
| 314 HAS_RETRANSMITTABLE_DATA)); |
| 315 for (int i = 0 ; i < kInitialBurstPackets; ++i) { |
| 316 CheckPacketIsSentImmediately(); |
| 317 } |
| 318 |
| 319 // The first packet was a "make up", then we sent two packets "into the |
| 320 // future", so the delay should be 2ms. |
| 321 CheckPacketIsSentImmediately(); |
| 322 CheckPacketIsSentImmediately(); |
| 323 CheckPacketIsSentImmediately(); |
| 324 CheckPacketIsDelayed(QuicTime::Delta::FromMilliseconds(2)); |
| 325 } |
| 326 |
| 327 TEST_F(PacingSenderTest, InitialBurstNoRttMeasurement) { |
| 328 pacing_sender_.reset(); |
| 329 mock_sender_ = new StrictMock<MockSendAlgorithm>(); |
| 330 pacing_sender_.reset(new PacingSender(mock_sender_, |
| 331 QuicTime::Delta::FromMilliseconds(1), |
| 332 10)); |
| 333 // Start the test in slow start. |
| 334 EXPECT_CALL(*mock_sender_, InSlowStart()).WillRepeatedly(Return(true)); |
| 335 |
| 336 // Configure bandwith of 1 packet per 2 ms, for which the pacing rate |
| 337 // will be 1 packet per 1 ms. |
| 338 EXPECT_CALL(*mock_sender_, BandwidthEstimate()) |
| 339 .WillRepeatedly(Return(QuicBandwidth::FromBytesAndTimeDelta( |
| 340 kMaxPacketSize, QuicTime::Delta::FromMilliseconds(2)))); |
| 341 |
| 342 // Send 10 packets, and verify that they are not paced. |
| 343 for (int i = 0 ; i < kInitialBurstPackets; ++i) { |
| 344 CheckPacketIsSentImmediately(); |
| 345 } |
| 346 |
| 347 // The first packet was a "make up", then we sent two packets "into the |
| 348 // future", so the delay should be 2ms. |
| 349 CheckPacketIsSentImmediately(); |
| 350 CheckPacketIsSentImmediately(); |
| 351 CheckPacketIsSentImmediately(); |
| 352 CheckPacketIsDelayed(QuicTime::Delta::FromMilliseconds(2)); |
| 353 |
| 354 |
| 355 clock_.AdvanceTime(QuicTime::Delta::FromMilliseconds(5)); |
| 356 CheckPacketIsSentImmediately(); |
| 357 |
313 // Next time TimeUntilSend is called with no bytes in flight, the tokens | 358 // Next time TimeUntilSend is called with no bytes in flight, the tokens |
314 // should be refilled and there should be no delay. | 359 // should be refilled and there should be no delay. |
315 EXPECT_CALL(*mock_sender_, | 360 EXPECT_CALL(*mock_sender_, |
316 TimeUntilSend(clock_.Now(), | 361 TimeUntilSend(clock_.Now(), |
317 0, | 362 0, |
318 HAS_RETRANSMITTABLE_DATA)). | 363 HAS_RETRANSMITTABLE_DATA)). |
319 WillOnce(Return(zero_time_)); | 364 WillOnce(Return(zero_time_)); |
320 EXPECT_EQ(zero_time_, | 365 EXPECT_EQ(zero_time_, |
321 pacing_sender_->TimeUntilSend(clock_.Now(), | 366 pacing_sender_->TimeUntilSend(clock_.Now(), |
322 0, | 367 0, |
323 HAS_RETRANSMITTABLE_DATA)); | 368 HAS_RETRANSMITTABLE_DATA)); |
324 for (int i = 0 ; i < 10; ++i) { | 369 // Send 10 packets, and verify that they are not paced. |
| 370 for (int i = 0 ; i < kInitialBurstPackets; ++i) { |
325 CheckPacketIsSentImmediately(); | 371 CheckPacketIsSentImmediately(); |
326 } | 372 } |
327 | 373 |
| 374 // The first packet was a "make up", then we sent two packets "into the |
| 375 // future", so the delay should be 2ms. |
328 CheckPacketIsSentImmediately(); | 376 CheckPacketIsSentImmediately(); |
329 CheckPacketIsSentImmediately(); | 377 CheckPacketIsSentImmediately(); |
330 CheckPacketIsSentImmediately(); | 378 CheckPacketIsSentImmediately(); |
331 | |
332 CheckPacketIsDelayed(QuicTime::Delta::FromMilliseconds(2)); | 379 CheckPacketIsDelayed(QuicTime::Delta::FromMilliseconds(2)); |
333 } | 380 } |
334 | 381 |
335 } // namespace test | 382 } // namespace test |
336 } // namespace net | 383 } // namespace net |
OLD | NEW |