| 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" |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 44 mock_sender_, QuicTime::Delta::FromMilliseconds(1), burst_size)); | 44 mock_sender_, QuicTime::Delta::FromMilliseconds(1), burst_size)); |
| 45 EXPECT_CALL(*mock_sender_, PacingRate()).WillRepeatedly(Return(bandwidth)); | 45 EXPECT_CALL(*mock_sender_, PacingRate()).WillRepeatedly(Return(bandwidth)); |
| 46 } | 46 } |
| 47 | 47 |
| 48 void CheckPacketIsSentImmediately(HasRetransmittableData retransmittable_data, | 48 void CheckPacketIsSentImmediately(HasRetransmittableData retransmittable_data, |
| 49 QuicByteCount bytes_in_flight, | 49 QuicByteCount bytes_in_flight, |
| 50 bool in_recovery) { | 50 bool in_recovery) { |
| 51 // In order for the packet to be sendable, the underlying sender must | 51 // In order for the packet to be sendable, the underlying sender must |
| 52 // permit it to be sent immediately. | 52 // permit it to be sent immediately. |
| 53 for (int i = 0; i < 2; ++i) { | 53 for (int i = 0; i < 2; ++i) { |
| 54 EXPECT_CALL(*mock_sender_, TimeUntilSend(clock_.Now(), bytes_in_flight, | 54 EXPECT_CALL(*mock_sender_, TimeUntilSend(clock_.Now(), bytes_in_flight)) |
| 55 retransmittable_data)) | |
| 56 .WillOnce(Return(zero_time_)); | 55 .WillOnce(Return(zero_time_)); |
| 57 // Verify that the packet can be sent immediately. | 56 // Verify that the packet can be sent immediately. |
| 58 EXPECT_EQ(zero_time_, | 57 EXPECT_EQ(zero_time_, |
| 59 pacing_sender_->TimeUntilSend(clock_.Now(), bytes_in_flight, | 58 pacing_sender_->TimeUntilSend(clock_.Now(), bytes_in_flight)); |
| 60 retransmittable_data)); | |
| 61 } | 59 } |
| 62 | 60 |
| 63 // Actually send the packet. | 61 // Actually send the packet. |
| 64 if (bytes_in_flight == 0) { | 62 if (bytes_in_flight == 0) { |
| 65 EXPECT_CALL(*mock_sender_, InRecovery()).WillOnce(Return(in_recovery)); | 63 EXPECT_CALL(*mock_sender_, InRecovery()).WillOnce(Return(in_recovery)); |
| 66 } | 64 } |
| 67 EXPECT_CALL(*mock_sender_, | 65 EXPECT_CALL(*mock_sender_, |
| 68 OnPacketSent(clock_.Now(), bytes_in_flight, packet_number_, | 66 OnPacketSent(clock_.Now(), bytes_in_flight, packet_number_, |
| 69 kMaxPacketSize, retransmittable_data)); | 67 kMaxPacketSize, retransmittable_data)); |
| 70 pacing_sender_->OnPacketSent(clock_.Now(), bytes_in_flight, | 68 pacing_sender_->OnPacketSent(clock_.Now(), bytes_in_flight, |
| 71 packet_number_++, kMaxPacketSize, | 69 packet_number_++, kMaxPacketSize, |
| 72 retransmittable_data); | 70 retransmittable_data); |
| 73 } | 71 } |
| 74 | 72 |
| 75 void CheckPacketIsSentImmediately() { | 73 void CheckPacketIsSentImmediately() { |
| 76 CheckPacketIsSentImmediately(HAS_RETRANSMITTABLE_DATA, kBytesInFlight, | 74 CheckPacketIsSentImmediately(HAS_RETRANSMITTABLE_DATA, kBytesInFlight, |
| 77 false); | 75 false); |
| 78 } | 76 } |
| 79 | 77 |
| 80 void CheckAckIsSentImmediately() { | |
| 81 CheckPacketIsSentImmediately(NO_RETRANSMITTABLE_DATA, kBytesInFlight, | |
| 82 false); | |
| 83 } | |
| 84 | |
| 85 void CheckPacketIsDelayed(QuicTime::Delta delay) { | 78 void CheckPacketIsDelayed(QuicTime::Delta delay) { |
| 86 // In order for the packet to be sendable, the underlying sender must | 79 // In order for the packet to be sendable, the underlying sender must |
| 87 // permit it to be sent immediately. | 80 // permit it to be sent immediately. |
| 88 for (int i = 0; i < 2; ++i) { | 81 for (int i = 0; i < 2; ++i) { |
| 89 EXPECT_CALL(*mock_sender_, TimeUntilSend(clock_.Now(), kBytesInFlight, | 82 EXPECT_CALL(*mock_sender_, TimeUntilSend(clock_.Now(), kBytesInFlight)) |
| 90 HAS_RETRANSMITTABLE_DATA)) | |
| 91 .WillOnce(Return(zero_time_)); | 83 .WillOnce(Return(zero_time_)); |
| 92 // Verify that the packet is delayed. | 84 // Verify that the packet is delayed. |
| 93 EXPECT_EQ(delay.ToMicroseconds(), | 85 EXPECT_EQ(delay.ToMicroseconds(), |
| 94 pacing_sender_ | 86 pacing_sender_->TimeUntilSend(clock_.Now(), kBytesInFlight) |
| 95 ->TimeUntilSend(clock_.Now(), kBytesInFlight, | |
| 96 HAS_RETRANSMITTABLE_DATA) | |
| 97 .ToMicroseconds()); | 87 .ToMicroseconds()); |
| 98 } | 88 } |
| 99 } | 89 } |
| 100 | 90 |
| 101 void UpdateRtt() { | 91 void UpdateRtt() { |
| 102 EXPECT_CALL(*mock_sender_, OnCongestionEvent(true, kBytesInFlight, _, _)); | 92 EXPECT_CALL(*mock_sender_, OnCongestionEvent(true, kBytesInFlight, _, _)); |
| 103 SendAlgorithmInterface::CongestionVector empty_map; | 93 SendAlgorithmInterface::CongestionVector empty_map; |
| 104 pacing_sender_->OnCongestionEvent(true, kBytesInFlight, empty_map, | 94 pacing_sender_->OnCongestionEvent(true, kBytesInFlight, empty_map, |
| 105 empty_map); | 95 empty_map); |
| 106 } | 96 } |
| 107 | 97 |
| 108 const QuicTime::Delta zero_time_; | 98 const QuicTime::Delta zero_time_; |
| 109 const QuicTime::Delta infinite_time_; | 99 const QuicTime::Delta infinite_time_; |
| 110 MockClock clock_; | 100 MockClock clock_; |
| 111 QuicPacketNumber packet_number_; | 101 QuicPacketNumber packet_number_; |
| 112 StrictMock<MockSendAlgorithm>* mock_sender_; | 102 StrictMock<MockSendAlgorithm>* mock_sender_; |
| 113 scoped_ptr<PacingSender> pacing_sender_; | 103 scoped_ptr<PacingSender> pacing_sender_; |
| 114 }; | 104 }; |
| 115 | 105 |
| 116 TEST_F(PacingSenderTest, NoSend) { | 106 TEST_F(PacingSenderTest, NoSend) { |
| 117 for (int i = 0; i < 2; ++i) { | 107 for (int i = 0; i < 2; ++i) { |
| 118 EXPECT_CALL(*mock_sender_, TimeUntilSend(clock_.Now(), kBytesInFlight, | 108 EXPECT_CALL(*mock_sender_, TimeUntilSend(clock_.Now(), kBytesInFlight)) |
| 119 HAS_RETRANSMITTABLE_DATA)) | |
| 120 .WillOnce(Return(infinite_time_)); | 109 .WillOnce(Return(infinite_time_)); |
| 121 EXPECT_EQ(infinite_time_, | 110 EXPECT_EQ(infinite_time_, |
| 122 pacing_sender_->TimeUntilSend(clock_.Now(), kBytesInFlight, | 111 pacing_sender_->TimeUntilSend(clock_.Now(), kBytesInFlight)); |
| 123 HAS_RETRANSMITTABLE_DATA)); | |
| 124 } | 112 } |
| 125 } | 113 } |
| 126 | 114 |
| 127 TEST_F(PacingSenderTest, SendNow) { | 115 TEST_F(PacingSenderTest, SendNow) { |
| 128 for (int i = 0; i < 2; ++i) { | 116 for (int i = 0; i < 2; ++i) { |
| 129 EXPECT_CALL(*mock_sender_, TimeUntilSend(clock_.Now(), kBytesInFlight, | 117 EXPECT_CALL(*mock_sender_, TimeUntilSend(clock_.Now(), kBytesInFlight)) |
| 130 HAS_RETRANSMITTABLE_DATA)) | |
| 131 .WillOnce(Return(zero_time_)); | 118 .WillOnce(Return(zero_time_)); |
| 132 EXPECT_EQ(zero_time_, | 119 EXPECT_EQ(zero_time_, |
| 133 pacing_sender_->TimeUntilSend(clock_.Now(), kBytesInFlight, | 120 pacing_sender_->TimeUntilSend(clock_.Now(), kBytesInFlight)); |
| 134 HAS_RETRANSMITTABLE_DATA)); | |
| 135 } | 121 } |
| 136 } | 122 } |
| 137 | 123 |
| 138 TEST_F(PacingSenderTest, VariousSending) { | 124 TEST_F(PacingSenderTest, VariousSending) { |
| 139 // Configure pacing rate of 1 packet per 1 ms, no initial burst. | 125 // Configure pacing rate of 1 packet per 1 ms, no initial burst. |
| 140 InitPacingRate(0, QuicBandwidth::FromBytesAndTimeDelta( | 126 InitPacingRate(0, QuicBandwidth::FromBytesAndTimeDelta( |
| 141 kMaxPacketSize, QuicTime::Delta::FromMilliseconds(1))); | 127 kMaxPacketSize, QuicTime::Delta::FromMilliseconds(1))); |
| 142 | 128 |
| 143 // Now update the RTT and verify that packets are actually paced. | 129 // Now update the RTT and verify that packets are actually paced. |
| 144 UpdateRtt(); | 130 UpdateRtt(); |
| 145 | 131 |
| 146 CheckPacketIsSentImmediately(); | 132 CheckPacketIsSentImmediately(); |
| 147 CheckPacketIsSentImmediately(); | 133 CheckPacketIsSentImmediately(); |
| 148 | 134 |
| 149 // The first packet was a "make up", then we sent two packets "into the | 135 // The first packet was a "make up", then we sent two packets "into the |
| 150 // future", so the delay should be 2. | 136 // future", so the delay should be 2. |
| 151 CheckPacketIsDelayed(QuicTime::Delta::FromMilliseconds(2)); | 137 CheckPacketIsDelayed(QuicTime::Delta::FromMilliseconds(2)); |
| 152 | 138 |
| 153 // Wake up on time. | 139 // Wake up on time. |
| 154 clock_.AdvanceTime(QuicTime::Delta::FromMilliseconds(2)); | 140 clock_.AdvanceTime(QuicTime::Delta::FromMilliseconds(2)); |
| 155 CheckPacketIsSentImmediately(); | 141 CheckPacketIsSentImmediately(); |
| 156 CheckPacketIsSentImmediately(); | 142 CheckPacketIsSentImmediately(); |
| 157 CheckPacketIsDelayed(QuicTime::Delta::FromMilliseconds(2)); | 143 CheckPacketIsDelayed(QuicTime::Delta::FromMilliseconds(2)); |
| 158 CheckAckIsSentImmediately(); | |
| 159 | 144 |
| 160 // Wake up late. | 145 // Wake up late. |
| 161 clock_.AdvanceTime(QuicTime::Delta::FromMilliseconds(4)); | 146 clock_.AdvanceTime(QuicTime::Delta::FromMilliseconds(4)); |
| 162 CheckPacketIsSentImmediately(); | 147 CheckPacketIsSentImmediately(); |
| 163 CheckPacketIsSentImmediately(); | 148 CheckPacketIsSentImmediately(); |
| 164 CheckPacketIsSentImmediately(); | 149 CheckPacketIsSentImmediately(); |
| 165 CheckPacketIsSentImmediately(); | 150 CheckPacketIsSentImmediately(); |
| 166 CheckPacketIsDelayed(QuicTime::Delta::FromMilliseconds(2)); | 151 CheckPacketIsDelayed(QuicTime::Delta::FromMilliseconds(2)); |
| 167 | 152 |
| 168 // Wake up really late. | 153 // Wake up really late. |
| (...skipping 185 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 354 EXPECT_CALL(*mock_sender_, PacingRate()).WillOnce(Return(kBandwidth)); | 339 EXPECT_CALL(*mock_sender_, PacingRate()).WillOnce(Return(kBandwidth)); |
| 355 pacing_sender_->OnPacketSent(kTime, kBytes, 123u, kBytes, | 340 pacing_sender_->OnPacketSent(kTime, kBytes, 123u, kBytes, |
| 356 HAS_RETRANSMITTABLE_DATA); | 341 HAS_RETRANSMITTABLE_DATA); |
| 357 | 342 |
| 358 EXPECT_CALL(*mock_sender_, OnRetransmissionTimeout(true)); | 343 EXPECT_CALL(*mock_sender_, OnRetransmissionTimeout(true)); |
| 359 pacing_sender_->OnRetransmissionTimeout(true); | 344 pacing_sender_->OnRetransmissionTimeout(true); |
| 360 | 345 |
| 361 EXPECT_CALL(*mock_sender_, OnConnectionMigration()); | 346 EXPECT_CALL(*mock_sender_, OnConnectionMigration()); |
| 362 pacing_sender_->OnConnectionMigration(); | 347 pacing_sender_->OnConnectionMigration(); |
| 363 | 348 |
| 364 EXPECT_CALL(*mock_sender_, | 349 EXPECT_CALL(*mock_sender_, TimeUntilSend(kTime, kBytes)) |
| 365 TimeUntilSend(kTime, kBytes, HAS_RETRANSMITTABLE_DATA)) | |
| 366 .WillOnce(Return(kTimeDelta)); | 350 .WillOnce(Return(kTimeDelta)); |
| 367 pacing_sender_->TimeUntilSend(kTime, kBytes, HAS_RETRANSMITTABLE_DATA); | 351 pacing_sender_->TimeUntilSend(kTime, kBytes); |
| 368 | 352 |
| 369 EXPECT_CALL(*mock_sender_, PacingRate()).WillOnce(Return(kBandwidth)); | 353 EXPECT_CALL(*mock_sender_, PacingRate()).WillOnce(Return(kBandwidth)); |
| 370 EXPECT_EQ(kBandwidth, pacing_sender_->PacingRate()); | 354 EXPECT_EQ(kBandwidth, pacing_sender_->PacingRate()); |
| 371 | 355 |
| 372 EXPECT_CALL(*mock_sender_, BandwidthEstimate()).WillOnce(Return(kBandwidth)); | 356 EXPECT_CALL(*mock_sender_, BandwidthEstimate()).WillOnce(Return(kBandwidth)); |
| 373 EXPECT_EQ(kBandwidth, pacing_sender_->BandwidthEstimate()); | 357 EXPECT_EQ(kBandwidth, pacing_sender_->BandwidthEstimate()); |
| 374 | 358 |
| 375 EXPECT_CALL(*mock_sender_, RetransmissionDelay()) | 359 EXPECT_CALL(*mock_sender_, RetransmissionDelay()) |
| 376 .WillOnce(Return(kTimeDelta)); | 360 .WillOnce(Return(kTimeDelta)); |
| 377 EXPECT_EQ(kTimeDelta, pacing_sender_->RetransmissionDelay()); | 361 EXPECT_EQ(kTimeDelta, pacing_sender_->RetransmissionDelay()); |
| (...skipping 10 matching lines...) Expand all Loading... |
| 388 EXPECT_CALL(*mock_sender_, GetSlowStartThreshold()).WillOnce(Return(kBytes)); | 372 EXPECT_CALL(*mock_sender_, GetSlowStartThreshold()).WillOnce(Return(kBytes)); |
| 389 EXPECT_EQ(kBytes, pacing_sender_->GetSlowStartThreshold()); | 373 EXPECT_EQ(kBytes, pacing_sender_->GetSlowStartThreshold()); |
| 390 | 374 |
| 391 EXPECT_CALL(*mock_sender_, GetCongestionControlType()) | 375 EXPECT_CALL(*mock_sender_, GetCongestionControlType()) |
| 392 .WillOnce(Return(kReno)); | 376 .WillOnce(Return(kReno)); |
| 393 EXPECT_EQ(kReno, pacing_sender_->GetCongestionControlType()); | 377 EXPECT_EQ(kReno, pacing_sender_->GetCongestionControlType()); |
| 394 } | 378 } |
| 395 | 379 |
| 396 } // namespace test | 380 } // namespace test |
| 397 } // namespace net | 381 } // namespace net |
| OLD | NEW |