| 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 28 matching lines...) Expand all Loading... |
| 39 | 39 |
| 40 void InitPacingRate(QuicPacketCount burst_size, QuicBandwidth bandwidth) { | 40 void InitPacingRate(QuicPacketCount burst_size, QuicBandwidth bandwidth) { |
| 41 pacing_sender_.reset(); | 41 pacing_sender_.reset(); |
| 42 mock_sender_ = new StrictMock<MockSendAlgorithm>(); | 42 mock_sender_ = new StrictMock<MockSendAlgorithm>(); |
| 43 pacing_sender_.reset(new PacingSender( | 43 pacing_sender_.reset(new PacingSender( |
| 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 // 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 |
| 51 // permit it to be sent immediately. | 52 // permit it to be sent immediately. |
| 52 for (int i = 0; i < 2; ++i) { | 53 for (int i = 0; i < 2; ++i) { |
| 53 EXPECT_CALL(*mock_sender_, TimeUntilSend(clock_.Now(), bytes_in_flight, | 54 EXPECT_CALL(*mock_sender_, TimeUntilSend(clock_.Now(), bytes_in_flight, |
| 54 retransmittable_data)) | 55 retransmittable_data)) |
| 55 .WillOnce(Return(zero_time_)); | 56 .WillOnce(Return(zero_time_)); |
| 56 // Verify that the packet can be sent immediately. | 57 // Verify that the packet can be sent immediately. |
| 57 EXPECT_EQ(zero_time_, | 58 EXPECT_EQ(zero_time_, |
| 58 pacing_sender_->TimeUntilSend(clock_.Now(), bytes_in_flight, | 59 pacing_sender_->TimeUntilSend(clock_.Now(), bytes_in_flight, |
| 59 retransmittable_data)); | 60 retransmittable_data)); |
| 60 } | 61 } |
| 61 | 62 |
| 62 // Actually send the packet. | 63 // Actually send the packet. |
| 64 if (bytes_in_flight == 0) { |
| 65 EXPECT_CALL(*mock_sender_, InRecovery()).WillOnce(Return(in_recovery)); |
| 66 } |
| 63 EXPECT_CALL(*mock_sender_, | 67 EXPECT_CALL(*mock_sender_, |
| 64 OnPacketSent(clock_.Now(), bytes_in_flight, packet_number_, | 68 OnPacketSent(clock_.Now(), bytes_in_flight, packet_number_, |
| 65 kMaxPacketSize, retransmittable_data)); | 69 kMaxPacketSize, retransmittable_data)); |
| 66 pacing_sender_->OnPacketSent(clock_.Now(), bytes_in_flight, | 70 pacing_sender_->OnPacketSent(clock_.Now(), bytes_in_flight, |
| 67 packet_number_++, kMaxPacketSize, | 71 packet_number_++, kMaxPacketSize, |
| 68 retransmittable_data); | 72 retransmittable_data); |
| 69 } | 73 } |
| 70 | 74 |
| 71 void CheckPacketIsSentImmediately() { | 75 void CheckPacketIsSentImmediately() { |
| 72 CheckPacketIsSentImmediately(HAS_RETRANSMITTABLE_DATA, kBytesInFlight); | 76 CheckPacketIsSentImmediately(HAS_RETRANSMITTABLE_DATA, kBytesInFlight, |
| 77 false); |
| 73 } | 78 } |
| 74 | 79 |
| 75 void CheckAckIsSentImmediately() { | 80 void CheckAckIsSentImmediately() { |
| 76 CheckPacketIsSentImmediately(NO_RETRANSMITTABLE_DATA, kBytesInFlight); | 81 CheckPacketIsSentImmediately(NO_RETRANSMITTABLE_DATA, kBytesInFlight, |
| 82 false); |
| 77 } | 83 } |
| 78 | 84 |
| 79 void CheckPacketIsDelayed(QuicTime::Delta delay) { | 85 void CheckPacketIsDelayed(QuicTime::Delta delay) { |
| 80 // In order for the packet to be sendable, the underlying sender must | 86 // In order for the packet to be sendable, the underlying sender must |
| 81 // permit it to be sent immediately. | 87 // permit it to be sent immediately. |
| 82 for (int i = 0; i < 2; ++i) { | 88 for (int i = 0; i < 2; ++i) { |
| 83 EXPECT_CALL(*mock_sender_, TimeUntilSend(clock_.Now(), | 89 EXPECT_CALL(*mock_sender_, TimeUntilSend(clock_.Now(), |
| 84 kBytesInFlight, | 90 kBytesInFlight, |
| 85 HAS_RETRANSMITTABLE_DATA)) | 91 HAS_RETRANSMITTABLE_DATA)) |
| 86 .WillOnce(Return(zero_time_)); | 92 .WillOnce(Return(zero_time_)); |
| (...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 213 // future", so the delay should be 2ms. | 219 // future", so the delay should be 2ms. |
| 214 CheckPacketIsSentImmediately(); | 220 CheckPacketIsSentImmediately(); |
| 215 CheckPacketIsSentImmediately(); | 221 CheckPacketIsSentImmediately(); |
| 216 CheckPacketIsDelayed(QuicTime::Delta::FromMilliseconds(2)); | 222 CheckPacketIsDelayed(QuicTime::Delta::FromMilliseconds(2)); |
| 217 | 223 |
| 218 clock_.AdvanceTime(QuicTime::Delta::FromMilliseconds(5)); | 224 clock_.AdvanceTime(QuicTime::Delta::FromMilliseconds(5)); |
| 219 CheckPacketIsSentImmediately(); | 225 CheckPacketIsSentImmediately(); |
| 220 | 226 |
| 221 // Next time TimeUntilSend is called with no bytes in flight, pacing should | 227 // Next time TimeUntilSend is called with no bytes in flight, pacing should |
| 222 // allow a packet to be sent, and when it's sent, the tokens are refilled. | 228 // allow a packet to be sent, and when it's sent, the tokens are refilled. |
| 223 CheckPacketIsSentImmediately(HAS_RETRANSMITTABLE_DATA, 0); | 229 CheckPacketIsSentImmediately(HAS_RETRANSMITTABLE_DATA, 0, false); |
| 224 for (int i = 0; i < kInitialBurstPackets - 1; ++i) { | 230 for (int i = 0; i < kInitialBurstPackets - 1; ++i) { |
| 225 CheckPacketIsSentImmediately(); | 231 CheckPacketIsSentImmediately(); |
| 226 } | 232 } |
| 227 | 233 |
| 228 // The first packet was a "make up", then we sent two packets "into the | 234 // The first packet was a "make up", then we sent two packets "into the |
| 229 // future", so the delay should be 2ms. | 235 // future", so the delay should be 2ms. |
| 230 CheckPacketIsSentImmediately(); | 236 CheckPacketIsSentImmediately(); |
| 231 CheckPacketIsSentImmediately(); | 237 CheckPacketIsSentImmediately(); |
| 232 CheckPacketIsDelayed(QuicTime::Delta::FromMilliseconds(2)); | 238 CheckPacketIsDelayed(QuicTime::Delta::FromMilliseconds(2)); |
| 233 } | 239 } |
| (...skipping 15 matching lines...) Expand all Loading... |
| 249 CheckPacketIsSentImmediately(); | 255 CheckPacketIsSentImmediately(); |
| 250 CheckPacketIsSentImmediately(); | 256 CheckPacketIsSentImmediately(); |
| 251 CheckPacketIsDelayed(QuicTime::Delta::FromMilliseconds(2)); | 257 CheckPacketIsDelayed(QuicTime::Delta::FromMilliseconds(2)); |
| 252 | 258 |
| 253 | 259 |
| 254 clock_.AdvanceTime(QuicTime::Delta::FromMilliseconds(5)); | 260 clock_.AdvanceTime(QuicTime::Delta::FromMilliseconds(5)); |
| 255 CheckPacketIsSentImmediately(); | 261 CheckPacketIsSentImmediately(); |
| 256 | 262 |
| 257 // Next time TimeUntilSend is called with no bytes in flight, the tokens | 263 // Next time TimeUntilSend is called with no bytes in flight, the tokens |
| 258 // should be refilled and there should be no delay. | 264 // should be refilled and there should be no delay. |
| 259 CheckPacketIsSentImmediately(HAS_RETRANSMITTABLE_DATA, 0); | 265 CheckPacketIsSentImmediately(HAS_RETRANSMITTABLE_DATA, 0, false); |
| 260 // Send 10 packets, and verify that they are not paced. | 266 // Send 10 packets, and verify that they are not paced. |
| 261 for (int i = 0; i < kInitialBurstPackets - 1; ++i) { | 267 for (int i = 0; i < kInitialBurstPackets - 1; ++i) { |
| 262 CheckPacketIsSentImmediately(); | 268 CheckPacketIsSentImmediately(); |
| 263 } | 269 } |
| 264 | 270 |
| 265 // The first packet was a "make up", then we sent two packets "into the | 271 // The first packet was a "make up", then we sent two packets "into the |
| 266 // future", so the delay should be 2ms. | 272 // future", so the delay should be 2ms. |
| 267 CheckPacketIsSentImmediately(); | 273 CheckPacketIsSentImmediately(); |
| 268 CheckPacketIsSentImmediately(); | 274 CheckPacketIsSentImmediately(); |
| 269 CheckPacketIsDelayed(QuicTime::Delta::FromMilliseconds(2)); | 275 CheckPacketIsDelayed(QuicTime::Delta::FromMilliseconds(2)); |
| (...skipping 21 matching lines...) Expand all Loading... |
| 291 CheckPacketIsSentImmediately(); | 297 CheckPacketIsSentImmediately(); |
| 292 CheckPacketIsSentImmediately(); | 298 CheckPacketIsSentImmediately(); |
| 293 CheckPacketIsSentImmediately(); | 299 CheckPacketIsSentImmediately(); |
| 294 CheckPacketIsDelayed(QuicTime::Delta::FromMicroseconds(1500)); | 300 CheckPacketIsDelayed(QuicTime::Delta::FromMicroseconds(1500)); |
| 295 | 301 |
| 296 clock_.AdvanceTime(QuicTime::Delta::FromMilliseconds(5)); | 302 clock_.AdvanceTime(QuicTime::Delta::FromMilliseconds(5)); |
| 297 CheckPacketIsSentImmediately(); | 303 CheckPacketIsSentImmediately(); |
| 298 | 304 |
| 299 // Next time TimeUntilSend is called with no bytes in flight, the tokens | 305 // Next time TimeUntilSend is called with no bytes in flight, the tokens |
| 300 // should be refilled and there should be no delay. | 306 // should be refilled and there should be no delay. |
| 301 CheckPacketIsSentImmediately(HAS_RETRANSMITTABLE_DATA, 0); | 307 CheckPacketIsSentImmediately(HAS_RETRANSMITTABLE_DATA, 0, false); |
| 302 for (int i = 0; i < kInitialBurstPackets - 1; ++i) { | 308 for (int i = 0; i < kInitialBurstPackets - 1; ++i) { |
| 303 CheckPacketIsSentImmediately(); | 309 CheckPacketIsSentImmediately(); |
| 304 } | 310 } |
| 305 | 311 |
| 306 // The first packet was a "make up", then we sent two packets "into the | 312 // The first packet was a "make up", then we sent two packets "into the |
| 307 // future", so the delay should be 1.5ms. | 313 // future", so the delay should be 1.5ms. |
| 308 CheckPacketIsSentImmediately(); | 314 CheckPacketIsSentImmediately(); |
| 309 CheckPacketIsSentImmediately(); | 315 CheckPacketIsSentImmediately(); |
| 310 CheckPacketIsSentImmediately(); | 316 CheckPacketIsSentImmediately(); |
| 311 CheckPacketIsDelayed(QuicTime::Delta::FromMicroseconds(1500)); | 317 CheckPacketIsDelayed(QuicTime::Delta::FromMicroseconds(1500)); |
| 312 } | 318 } |
| 313 | 319 |
| 320 TEST_F(PacingSenderTest, NoBurstInRecovery) { |
| 321 // Configure pacing rate of 1 packet per 1 ms with no burst tokens. |
| 322 InitPacingRate(0, QuicBandwidth::FromBytesAndTimeDelta( |
| 323 kMaxPacketSize, QuicTime::Delta::FromMilliseconds(1))); |
| 324 |
| 325 UpdateRtt(); |
| 326 |
| 327 // Ensure only one packet is sent immediately and the rest are paced. |
| 328 CheckPacketIsSentImmediately(HAS_RETRANSMITTABLE_DATA, 0, true); |
| 329 CheckPacketIsSentImmediately(); |
| 330 CheckPacketIsDelayed(QuicTime::Delta::FromMilliseconds(2)); |
| 331 } |
| 332 |
| 314 } // namespace test | 333 } // namespace test |
| 315 } // namespace net | 334 } // namespace net |
| OLD | NEW |