| 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/core/congestion_control/pacing_sender.h" | 5 #include "net/quic/core/congestion_control/pacing_sender.h" |
| 6 | 6 |
| 7 #include <memory> | 7 #include <memory> |
| 8 | 8 |
| 9 #include "base/logging.h" | 9 #include "base/logging.h" |
| 10 #include "net/quic/core/quic_protocol.h" | 10 #include "net/quic/core/quic_protocol.h" |
| (...skipping 12 matching lines...) Expand all Loading... |
| 23 const int kInitialBurstPackets = 10; | 23 const int kInitialBurstPackets = 10; |
| 24 | 24 |
| 25 class PacingSenderTest : public ::testing::Test { | 25 class PacingSenderTest : public ::testing::Test { |
| 26 protected: | 26 protected: |
| 27 PacingSenderTest() | 27 PacingSenderTest() |
| 28 : zero_time_(QuicTime::Delta::Zero()), | 28 : zero_time_(QuicTime::Delta::Zero()), |
| 29 infinite_time_(QuicTime::Delta::Infinite()), | 29 infinite_time_(QuicTime::Delta::Infinite()), |
| 30 packet_number_(1), | 30 packet_number_(1), |
| 31 mock_sender_(new StrictMock<MockSendAlgorithm>()), | 31 mock_sender_(new StrictMock<MockSendAlgorithm>()), |
| 32 pacing_sender_(new PacingSender) { | 32 pacing_sender_(new PacingSender) { |
| 33 pacing_sender_->SetSender(mock_sender_, true); | 33 pacing_sender_->set_sender(mock_sender_.get()); |
| 34 // Pick arbitrary time. | 34 // Pick arbitrary time. |
| 35 clock_.AdvanceTime(QuicTime::Delta::FromMilliseconds(9)); | 35 clock_.AdvanceTime(QuicTime::Delta::FromMilliseconds(9)); |
| 36 } | 36 } |
| 37 | 37 |
| 38 ~PacingSenderTest() override {} | 38 ~PacingSenderTest() override {} |
| 39 | 39 |
| 40 void InitPacingRate(QuicPacketCount burst_size, QuicBandwidth bandwidth) { | 40 void InitPacingRate(QuicPacketCount burst_size, QuicBandwidth bandwidth) { |
| 41 mock_sender_ = new StrictMock<MockSendAlgorithm>(); | 41 mock_sender_.reset(new StrictMock<MockSendAlgorithm>()); |
| 42 pacing_sender_.reset(new PacingSender); | 42 pacing_sender_.reset(new PacingSender); |
| 43 pacing_sender_->SetSender(mock_sender_, true); | 43 pacing_sender_->set_sender(mock_sender_.get()); |
| 44 EXPECT_CALL(*mock_sender_, PacingRate(_)).WillRepeatedly(Return(bandwidth)); | 44 EXPECT_CALL(*mock_sender_, PacingRate(_)).WillRepeatedly(Return(bandwidth)); |
| 45 if (burst_size == 0) { | 45 if (burst_size == 0) { |
| 46 EXPECT_CALL(*mock_sender_, OnCongestionEvent(_, _, _, _)); | 46 EXPECT_CALL(*mock_sender_, OnCongestionEvent(_, _, _, _)); |
| 47 SendAlgorithmInterface::CongestionVector lost_packets; | 47 SendAlgorithmInterface::CongestionVector lost_packets; |
| 48 lost_packets.push_back(std::make_pair(1, kMaxPacketSize)); | 48 lost_packets.push_back(std::make_pair(1, kMaxPacketSize)); |
| 49 SendAlgorithmInterface::CongestionVector empty; | 49 SendAlgorithmInterface::CongestionVector empty; |
| 50 pacing_sender_->OnCongestionEvent(true, 1234, empty, lost_packets); | 50 pacing_sender_->OnCongestionEvent(true, 1234, empty, lost_packets); |
| 51 } else if (burst_size != kInitialBurstPackets) { | 51 } else if (burst_size != kInitialBurstPackets) { |
| 52 LOG(FATAL) << "Unsupported burst_size specificied."; | 52 LOG(FATAL) << "Unsupported burst_size " << burst_size |
| 53 << " specificied, only 0 and " << kInitialBurstPackets |
| 54 << " are supported."; |
| 53 } | 55 } |
| 54 } | 56 } |
| 55 | 57 |
| 56 void CheckPacketIsSentImmediately(HasRetransmittableData retransmittable_data, | 58 void CheckPacketIsSentImmediately(HasRetransmittableData retransmittable_data, |
| 57 QuicByteCount bytes_in_flight, | 59 QuicByteCount bytes_in_flight, |
| 58 bool in_recovery) { | 60 bool in_recovery) { |
| 59 // In order for the packet to be sendable, the underlying sender must | 61 // In order for the packet to be sendable, the underlying sender must |
| 60 // permit it to be sent immediately. | 62 // permit it to be sent immediately. |
| 61 for (int i = 0; i < 2; ++i) { | 63 for (int i = 0; i < 2; ++i) { |
| 62 EXPECT_CALL(*mock_sender_, TimeUntilSend(clock_.Now(), bytes_in_flight)) | 64 EXPECT_CALL(*mock_sender_, TimeUntilSend(clock_.Now(), bytes_in_flight)) |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 100 EXPECT_CALL(*mock_sender_, OnCongestionEvent(true, kBytesInFlight, _, _)); | 102 EXPECT_CALL(*mock_sender_, OnCongestionEvent(true, kBytesInFlight, _, _)); |
| 101 SendAlgorithmInterface::CongestionVector empty_map; | 103 SendAlgorithmInterface::CongestionVector empty_map; |
| 102 pacing_sender_->OnCongestionEvent(true, kBytesInFlight, empty_map, | 104 pacing_sender_->OnCongestionEvent(true, kBytesInFlight, empty_map, |
| 103 empty_map); | 105 empty_map); |
| 104 } | 106 } |
| 105 | 107 |
| 106 const QuicTime::Delta zero_time_; | 108 const QuicTime::Delta zero_time_; |
| 107 const QuicTime::Delta infinite_time_; | 109 const QuicTime::Delta infinite_time_; |
| 108 MockClock clock_; | 110 MockClock clock_; |
| 109 QuicPacketNumber packet_number_; | 111 QuicPacketNumber packet_number_; |
| 110 StrictMock<MockSendAlgorithm>* mock_sender_; | 112 std::unique_ptr<StrictMock<MockSendAlgorithm>> mock_sender_; |
| 111 std::unique_ptr<PacingSender> pacing_sender_; | 113 std::unique_ptr<PacingSender> pacing_sender_; |
| 112 }; | 114 }; |
| 113 | 115 |
| 114 TEST_F(PacingSenderTest, NoSend) { | 116 TEST_F(PacingSenderTest, NoSend) { |
| 115 for (int i = 0; i < 2; ++i) { | 117 for (int i = 0; i < 2; ++i) { |
| 116 EXPECT_CALL(*mock_sender_, TimeUntilSend(clock_.Now(), kBytesInFlight)) | 118 EXPECT_CALL(*mock_sender_, TimeUntilSend(clock_.Now(), kBytesInFlight)) |
| 117 .WillOnce(Return(infinite_time_)); | 119 .WillOnce(Return(infinite_time_)); |
| 118 EXPECT_EQ(infinite_time_, | 120 EXPECT_EQ(infinite_time_, |
| 119 pacing_sender_->TimeUntilSend(clock_.Now(), kBytesInFlight)); | 121 pacing_sender_->TimeUntilSend(clock_.Now(), kBytesInFlight)); |
| 120 } | 122 } |
| (...skipping 215 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 336 kMaxPacketSize, QuicTime::Delta::FromMilliseconds(1))); | 338 kMaxPacketSize, QuicTime::Delta::FromMilliseconds(1))); |
| 337 | 339 |
| 338 UpdateRtt(); | 340 UpdateRtt(); |
| 339 | 341 |
| 340 // Ensure only one packet is sent immediately and the rest are paced. | 342 // Ensure only one packet is sent immediately and the rest are paced. |
| 341 CheckPacketIsSentImmediately(HAS_RETRANSMITTABLE_DATA, 0, true); | 343 CheckPacketIsSentImmediately(HAS_RETRANSMITTABLE_DATA, 0, true); |
| 342 CheckPacketIsSentImmediately(); | 344 CheckPacketIsSentImmediately(); |
| 343 CheckPacketIsDelayed(QuicTime::Delta::FromMilliseconds(2)); | 345 CheckPacketIsDelayed(QuicTime::Delta::FromMilliseconds(2)); |
| 344 } | 346 } |
| 345 | 347 |
| 346 TEST_F(PacingSenderTest, VerifyInnerSenderCalled) { | |
| 347 // Configure pacing rate of 1 packet per 1 ms with no burst tokens. | |
| 348 InitPacingRate(0, QuicBandwidth::FromBytesAndTimeDelta( | |
| 349 kMaxPacketSize, QuicTime::Delta::FromMilliseconds(1))); | |
| 350 QuicBandwidth kBandwidth = QuicBandwidth::FromBitsPerSecond(1000); | |
| 351 QuicTime kTime = QuicTime::Infinite(); | |
| 352 QuicTime::Delta kTimeDelta = QuicTime::Delta::Infinite(); | |
| 353 QuicByteCount kBytes = 12345u; | |
| 354 | |
| 355 EXPECT_CALL(*mock_sender_, SetFromConfig(_, Perspective::IS_SERVER)); | |
| 356 QuicConfig config; | |
| 357 pacing_sender_->SetFromConfig(config, Perspective::IS_SERVER); | |
| 358 | |
| 359 EXPECT_CALL(*mock_sender_, ResumeConnectionState(_, true)); | |
| 360 CachedNetworkParameters cached_network_params; | |
| 361 pacing_sender_->ResumeConnectionState(cached_network_params, true); | |
| 362 | |
| 363 EXPECT_CALL(*mock_sender_, SetNumEmulatedConnections(2)); | |
| 364 pacing_sender_->SetNumEmulatedConnections(2); | |
| 365 | |
| 366 SendAlgorithmInterface::CongestionVector packets; | |
| 367 EXPECT_CALL(*mock_sender_, OnCongestionEvent(true, kBytes, packets, packets)); | |
| 368 pacing_sender_->OnCongestionEvent(true, kBytes, packets, packets); | |
| 369 | |
| 370 EXPECT_CALL(*mock_sender_, OnPacketSent(kTime, kBytes, 123u, kBytes, | |
| 371 HAS_RETRANSMITTABLE_DATA)); | |
| 372 EXPECT_CALL(*mock_sender_, PacingRate(_)).WillOnce(Return(kBandwidth)); | |
| 373 pacing_sender_->OnPacketSent(kTime, kBytes, 123u, kBytes, | |
| 374 HAS_RETRANSMITTABLE_DATA); | |
| 375 | |
| 376 EXPECT_CALL(*mock_sender_, OnRetransmissionTimeout(true)); | |
| 377 pacing_sender_->OnRetransmissionTimeout(true); | |
| 378 | |
| 379 EXPECT_CALL(*mock_sender_, OnConnectionMigration()); | |
| 380 pacing_sender_->OnConnectionMigration(); | |
| 381 | |
| 382 EXPECT_CALL(*mock_sender_, TimeUntilSend(kTime, kBytes)) | |
| 383 .WillOnce(Return(kTimeDelta)); | |
| 384 pacing_sender_->TimeUntilSend(kTime, kBytes); | |
| 385 | |
| 386 EXPECT_CALL(*mock_sender_, PacingRate(_)).WillOnce(Return(kBandwidth)); | |
| 387 EXPECT_EQ(kBandwidth, pacing_sender_->PacingRate(0)); | |
| 388 | |
| 389 EXPECT_CALL(*mock_sender_, BandwidthEstimate()).WillOnce(Return(kBandwidth)); | |
| 390 EXPECT_EQ(kBandwidth, pacing_sender_->BandwidthEstimate()); | |
| 391 | |
| 392 EXPECT_CALL(*mock_sender_, RetransmissionDelay()) | |
| 393 .WillOnce(Return(kTimeDelta)); | |
| 394 EXPECT_EQ(kTimeDelta, pacing_sender_->RetransmissionDelay()); | |
| 395 | |
| 396 EXPECT_CALL(*mock_sender_, GetCongestionWindow()).WillOnce(Return(kBytes)); | |
| 397 EXPECT_EQ(kBytes, pacing_sender_->GetCongestionWindow()); | |
| 398 | |
| 399 EXPECT_CALL(*mock_sender_, InSlowStart()).WillOnce(Return(true)); | |
| 400 EXPECT_TRUE(pacing_sender_->InSlowStart()); | |
| 401 | |
| 402 EXPECT_CALL(*mock_sender_, InRecovery()).WillOnce(Return(true)); | |
| 403 EXPECT_TRUE(pacing_sender_->InRecovery()); | |
| 404 | |
| 405 EXPECT_CALL(*mock_sender_, GetSlowStartThreshold()).WillOnce(Return(kBytes)); | |
| 406 EXPECT_EQ(kBytes, pacing_sender_->GetSlowStartThreshold()); | |
| 407 | |
| 408 EXPECT_CALL(*mock_sender_, GetCongestionControlType()) | |
| 409 .WillOnce(Return(kReno)); | |
| 410 EXPECT_EQ(kReno, pacing_sender_->GetCongestionControlType()); | |
| 411 } | |
| 412 | |
| 413 } // namespace test | 348 } // namespace test |
| 414 } // namespace net | 349 } // namespace net |
| OLD | NEW |