| 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 11 matching lines...) Expand all Loading... |
| 22 const QuicByteCount kBytesInFlight = 1024; | 22 const QuicByteCount kBytesInFlight = 1024; |
| 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(mock_sender_, | 32 pacing_sender_(new PacingSender) { |
| 33 QuicTime::Delta::FromMilliseconds(1), | 33 pacing_sender_->set_sender(mock_sender_.get()); |
| 34 0)) { | |
| 35 // Pick arbitrary time. | 34 // Pick arbitrary time. |
| 36 clock_.AdvanceTime(QuicTime::Delta::FromMilliseconds(9)); | 35 clock_.AdvanceTime(QuicTime::Delta::FromMilliseconds(9)); |
| 37 } | 36 } |
| 38 | 37 |
| 39 ~PacingSenderTest() override {} | 38 ~PacingSenderTest() override {} |
| 40 | 39 |
| 41 void InitPacingRate(QuicPacketCount burst_size, QuicBandwidth bandwidth) { | 40 void InitPacingRate(QuicPacketCount burst_size, QuicBandwidth bandwidth) { |
| 42 pacing_sender_.reset(); | 41 mock_sender_.reset(new StrictMock<MockSendAlgorithm>()); |
| 43 mock_sender_ = new StrictMock<MockSendAlgorithm>(); | 42 pacing_sender_.reset(new PacingSender); |
| 44 pacing_sender_.reset(new PacingSender( | 43 pacing_sender_->set_sender(mock_sender_.get()); |
| 45 mock_sender_, QuicTime::Delta::FromMilliseconds(1), burst_size)); | |
| 46 EXPECT_CALL(*mock_sender_, PacingRate(_)).WillRepeatedly(Return(bandwidth)); | 44 EXPECT_CALL(*mock_sender_, PacingRate(_)).WillRepeatedly(Return(bandwidth)); |
| 45 if (burst_size == 0) { |
| 46 EXPECT_CALL(*mock_sender_, OnCongestionEvent(_, _, _, _)); |
| 47 SendAlgorithmInterface::CongestionVector lost_packets; |
| 48 lost_packets.push_back(std::make_pair(1, kMaxPacketSize)); |
| 49 SendAlgorithmInterface::CongestionVector empty; |
| 50 pacing_sender_->OnCongestionEvent(true, 1234, empty, lost_packets); |
| 51 } else if (burst_size != kInitialBurstPackets) { |
| 52 LOG(FATAL) << "Unsupported burst_size " << burst_size |
| 53 << " specificied, only 0 and " << kInitialBurstPackets |
| 54 << " are supported."; |
| 55 } |
| 47 } | 56 } |
| 48 | 57 |
| 49 void CheckPacketIsSentImmediately(HasRetransmittableData retransmittable_data, | 58 void CheckPacketIsSentImmediately(HasRetransmittableData retransmittable_data, |
| 50 QuicByteCount bytes_in_flight, | 59 QuicByteCount bytes_in_flight, |
| 51 bool in_recovery) { | 60 bool in_recovery) { |
| 52 // 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 |
| 53 // permit it to be sent immediately. | 62 // permit it to be sent immediately. |
| 54 for (int i = 0; i < 2; ++i) { | 63 for (int i = 0; i < 2; ++i) { |
| 55 EXPECT_CALL(*mock_sender_, TimeUntilSend(clock_.Now(), bytes_in_flight)) | 64 EXPECT_CALL(*mock_sender_, TimeUntilSend(clock_.Now(), bytes_in_flight)) |
| 56 .WillOnce(Return(zero_time_)); | 65 .WillOnce(Return(zero_time_)); |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 93 EXPECT_CALL(*mock_sender_, OnCongestionEvent(true, kBytesInFlight, _, _)); | 102 EXPECT_CALL(*mock_sender_, OnCongestionEvent(true, kBytesInFlight, _, _)); |
| 94 SendAlgorithmInterface::CongestionVector empty_map; | 103 SendAlgorithmInterface::CongestionVector empty_map; |
| 95 pacing_sender_->OnCongestionEvent(true, kBytesInFlight, empty_map, | 104 pacing_sender_->OnCongestionEvent(true, kBytesInFlight, empty_map, |
| 96 empty_map); | 105 empty_map); |
| 97 } | 106 } |
| 98 | 107 |
| 99 const QuicTime::Delta zero_time_; | 108 const QuicTime::Delta zero_time_; |
| 100 const QuicTime::Delta infinite_time_; | 109 const QuicTime::Delta infinite_time_; |
| 101 MockClock clock_; | 110 MockClock clock_; |
| 102 QuicPacketNumber packet_number_; | 111 QuicPacketNumber packet_number_; |
| 103 StrictMock<MockSendAlgorithm>* mock_sender_; | 112 std::unique_ptr<StrictMock<MockSendAlgorithm>> mock_sender_; |
| 104 std::unique_ptr<PacingSender> pacing_sender_; | 113 std::unique_ptr<PacingSender> pacing_sender_; |
| 105 }; | 114 }; |
| 106 | 115 |
| 107 TEST_F(PacingSenderTest, NoSend) { | 116 TEST_F(PacingSenderTest, NoSend) { |
| 108 for (int i = 0; i < 2; ++i) { | 117 for (int i = 0; i < 2; ++i) { |
| 109 EXPECT_CALL(*mock_sender_, TimeUntilSend(clock_.Now(), kBytesInFlight)) | 118 EXPECT_CALL(*mock_sender_, TimeUntilSend(clock_.Now(), kBytesInFlight)) |
| 110 .WillOnce(Return(infinite_time_)); | 119 .WillOnce(Return(infinite_time_)); |
| 111 EXPECT_EQ(infinite_time_, | 120 EXPECT_EQ(infinite_time_, |
| 112 pacing_sender_->TimeUntilSend(clock_.Now(), kBytesInFlight)); | 121 pacing_sender_->TimeUntilSend(clock_.Now(), kBytesInFlight)); |
| 113 } | 122 } |
| (...skipping 215 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 329 kMaxPacketSize, QuicTime::Delta::FromMilliseconds(1))); | 338 kMaxPacketSize, QuicTime::Delta::FromMilliseconds(1))); |
| 330 | 339 |
| 331 UpdateRtt(); | 340 UpdateRtt(); |
| 332 | 341 |
| 333 // 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. |
| 334 CheckPacketIsSentImmediately(HAS_RETRANSMITTABLE_DATA, 0, true); | 343 CheckPacketIsSentImmediately(HAS_RETRANSMITTABLE_DATA, 0, true); |
| 335 CheckPacketIsSentImmediately(); | 344 CheckPacketIsSentImmediately(); |
| 336 CheckPacketIsDelayed(QuicTime::Delta::FromMilliseconds(2)); | 345 CheckPacketIsDelayed(QuicTime::Delta::FromMilliseconds(2)); |
| 337 } | 346 } |
| 338 | 347 |
| 339 TEST_F(PacingSenderTest, VerifyInnerSenderCalled) { | |
| 340 QuicBandwidth kBandwidth = QuicBandwidth::FromBitsPerSecond(1000); | |
| 341 QuicTime kTime = QuicTime::Infinite(); | |
| 342 QuicTime::Delta kTimeDelta = QuicTime::Delta::Infinite(); | |
| 343 QuicByteCount kBytes = 12345u; | |
| 344 | |
| 345 EXPECT_CALL(*mock_sender_, SetFromConfig(_, Perspective::IS_SERVER)); | |
| 346 QuicConfig config; | |
| 347 pacing_sender_->SetFromConfig(config, Perspective::IS_SERVER); | |
| 348 | |
| 349 EXPECT_CALL(*mock_sender_, ResumeConnectionState(_, true)); | |
| 350 CachedNetworkParameters cached_network_params; | |
| 351 pacing_sender_->ResumeConnectionState(cached_network_params, true); | |
| 352 | |
| 353 EXPECT_CALL(*mock_sender_, SetNumEmulatedConnections(2)); | |
| 354 pacing_sender_->SetNumEmulatedConnections(2); | |
| 355 | |
| 356 SendAlgorithmInterface::CongestionVector packets; | |
| 357 EXPECT_CALL(*mock_sender_, OnCongestionEvent(true, kBytes, packets, packets)); | |
| 358 pacing_sender_->OnCongestionEvent(true, kBytes, packets, packets); | |
| 359 | |
| 360 EXPECT_CALL(*mock_sender_, OnPacketSent(kTime, kBytes, 123u, kBytes, | |
| 361 HAS_RETRANSMITTABLE_DATA)); | |
| 362 EXPECT_CALL(*mock_sender_, PacingRate(_)).WillOnce(Return(kBandwidth)); | |
| 363 pacing_sender_->OnPacketSent(kTime, kBytes, 123u, kBytes, | |
| 364 HAS_RETRANSMITTABLE_DATA); | |
| 365 | |
| 366 EXPECT_CALL(*mock_sender_, OnRetransmissionTimeout(true)); | |
| 367 pacing_sender_->OnRetransmissionTimeout(true); | |
| 368 | |
| 369 EXPECT_CALL(*mock_sender_, OnConnectionMigration()); | |
| 370 pacing_sender_->OnConnectionMigration(); | |
| 371 | |
| 372 EXPECT_CALL(*mock_sender_, TimeUntilSend(kTime, kBytes)) | |
| 373 .WillOnce(Return(kTimeDelta)); | |
| 374 pacing_sender_->TimeUntilSend(kTime, kBytes); | |
| 375 | |
| 376 EXPECT_CALL(*mock_sender_, PacingRate(_)).WillOnce(Return(kBandwidth)); | |
| 377 EXPECT_EQ(kBandwidth, pacing_sender_->PacingRate(0)); | |
| 378 | |
| 379 EXPECT_CALL(*mock_sender_, BandwidthEstimate()).WillOnce(Return(kBandwidth)); | |
| 380 EXPECT_EQ(kBandwidth, pacing_sender_->BandwidthEstimate()); | |
| 381 | |
| 382 EXPECT_CALL(*mock_sender_, RetransmissionDelay()) | |
| 383 .WillOnce(Return(kTimeDelta)); | |
| 384 EXPECT_EQ(kTimeDelta, pacing_sender_->RetransmissionDelay()); | |
| 385 | |
| 386 EXPECT_CALL(*mock_sender_, GetCongestionWindow()).WillOnce(Return(kBytes)); | |
| 387 EXPECT_EQ(kBytes, pacing_sender_->GetCongestionWindow()); | |
| 388 | |
| 389 EXPECT_CALL(*mock_sender_, InSlowStart()).WillOnce(Return(true)); | |
| 390 EXPECT_TRUE(pacing_sender_->InSlowStart()); | |
| 391 | |
| 392 EXPECT_CALL(*mock_sender_, InRecovery()).WillOnce(Return(true)); | |
| 393 EXPECT_TRUE(pacing_sender_->InRecovery()); | |
| 394 | |
| 395 EXPECT_CALL(*mock_sender_, GetSlowStartThreshold()).WillOnce(Return(kBytes)); | |
| 396 EXPECT_EQ(kBytes, pacing_sender_->GetSlowStartThreshold()); | |
| 397 | |
| 398 EXPECT_CALL(*mock_sender_, GetCongestionControlType()) | |
| 399 .WillOnce(Return(kReno)); | |
| 400 EXPECT_EQ(kReno, pacing_sender_->GetCongestionControlType()); | |
| 401 } | |
| 402 | |
| 403 } // namespace test | 348 } // namespace test |
| 404 } // namespace net | 349 } // namespace net |
| OLD | NEW |