| 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 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 127 HAS_RETRANSMITTABLE_DATA)) | 127 HAS_RETRANSMITTABLE_DATA)) |
| 128 .WillOnce(Return(zero_time_)); | 128 .WillOnce(Return(zero_time_)); |
| 129 EXPECT_EQ(zero_time_, | 129 EXPECT_EQ(zero_time_, |
| 130 pacing_sender_->TimeUntilSend(clock_.Now(), | 130 pacing_sender_->TimeUntilSend(clock_.Now(), |
| 131 kBytesInFlight, | 131 kBytesInFlight, |
| 132 HAS_RETRANSMITTABLE_DATA)); | 132 HAS_RETRANSMITTABLE_DATA)); |
| 133 } | 133 } |
| 134 } | 134 } |
| 135 | 135 |
| 136 TEST_F(PacingSenderTest, VariousSending) { | 136 TEST_F(PacingSenderTest, VariousSending) { |
| 137 // Start the test in slow start. | 137 // Configure pacing rate of 1 packet per 1 ms. |
| 138 EXPECT_CALL(*mock_sender_, InSlowStart()).WillRepeatedly(Return(true)); | 138 EXPECT_CALL(*mock_sender_, PacingRate()) |
| 139 | |
| 140 // Configure bandwith of 1 packet per 2 ms, for which the pacing rate | |
| 141 // will be 1 packet per 1 ms. | |
| 142 EXPECT_CALL(*mock_sender_, BandwidthEstimate()) | |
| 143 .WillRepeatedly(Return(QuicBandwidth::FromBytesAndTimeDelta( | 139 .WillRepeatedly(Return(QuicBandwidth::FromBytesAndTimeDelta( |
| 144 kMaxPacketSize, QuicTime::Delta::FromMilliseconds(2)))); | 140 kMaxPacketSize, QuicTime::Delta::FromMilliseconds(1)))); |
| 145 | 141 |
| 146 // Now update the RTT and verify that packets are actually paced. | 142 // Now update the RTT and verify that packets are actually paced. |
| 147 EXPECT_CALL(*mock_sender_, OnCongestionEvent(true, kBytesInFlight, _, _)); | 143 EXPECT_CALL(*mock_sender_, OnCongestionEvent(true, kBytesInFlight, _, _)); |
| 148 SendAlgorithmInterface::CongestionVector empty_map; | 144 SendAlgorithmInterface::CongestionVector empty_map; |
| 149 pacing_sender_->OnCongestionEvent(true, kBytesInFlight, empty_map, empty_map); | 145 pacing_sender_->OnCongestionEvent(true, kBytesInFlight, empty_map, empty_map); |
| 150 | 146 |
| 151 CheckPacketIsSentImmediately(); | 147 CheckPacketIsSentImmediately(); |
| 152 CheckPacketIsSentImmediately(); | 148 CheckPacketIsSentImmediately(); |
| 153 CheckPacketIsSentImmediately(); | 149 CheckPacketIsSentImmediately(); |
| 154 | 150 |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 197 // Wake up too early. | 193 // Wake up too early. |
| 198 CheckPacketIsDelayed(QuicTime::Delta::FromMilliseconds(2)); | 194 CheckPacketIsDelayed(QuicTime::Delta::FromMilliseconds(2)); |
| 199 | 195 |
| 200 // Wake up early, but after enough time has passed to permit a send. | 196 // Wake up early, but after enough time has passed to permit a send. |
| 201 clock_.AdvanceTime(QuicTime::Delta::FromMilliseconds(1)); | 197 clock_.AdvanceTime(QuicTime::Delta::FromMilliseconds(1)); |
| 202 CheckPacketIsSentImmediately(); | 198 CheckPacketIsSentImmediately(); |
| 203 CheckPacketIsDelayed(QuicTime::Delta::FromMilliseconds(2)); | 199 CheckPacketIsDelayed(QuicTime::Delta::FromMilliseconds(2)); |
| 204 } | 200 } |
| 205 | 201 |
| 206 TEST_F(PacingSenderTest, CongestionAvoidanceSending) { | 202 TEST_F(PacingSenderTest, CongestionAvoidanceSending) { |
| 207 // Start the test in congestion avoidance. | 203 // Configure pacing rate of 1 packet per 1 ms. |
| 208 EXPECT_CALL(*mock_sender_, InSlowStart()).WillRepeatedly(Return(false)); | 204 EXPECT_CALL(*mock_sender_, PacingRate()) |
| 209 | |
| 210 // Configure bandwith of 1 packet per 2 ms, for which the pacing rate | |
| 211 // will be 1 packet per 1 ms. | |
| 212 EXPECT_CALL(*mock_sender_, BandwidthEstimate()) | |
| 213 .WillRepeatedly(Return(QuicBandwidth::FromBytesAndTimeDelta( | 205 .WillRepeatedly(Return(QuicBandwidth::FromBytesAndTimeDelta( |
| 214 kMaxPacketSize, QuicTime::Delta::FromMilliseconds(2)))); | 206 kMaxPacketSize * 1.25, QuicTime::Delta::FromMilliseconds(2)))); |
| 215 | 207 |
| 216 // Now update the RTT and verify that packets are actually paced. | 208 // Now update the RTT and verify that packets are actually paced. |
| 217 EXPECT_CALL(*mock_sender_, OnCongestionEvent(true, kBytesInFlight, _, _)); | 209 EXPECT_CALL(*mock_sender_, OnCongestionEvent(true, kBytesInFlight, _, _)); |
| 218 SendAlgorithmInterface::CongestionVector empty_map; | 210 SendAlgorithmInterface::CongestionVector empty_map; |
| 219 pacing_sender_->OnCongestionEvent(true, kBytesInFlight, empty_map, empty_map); | 211 pacing_sender_->OnCongestionEvent(true, kBytesInFlight, empty_map, empty_map); |
| 220 | 212 |
| 221 CheckPacketIsSentImmediately(); | 213 CheckPacketIsSentImmediately(); |
| 222 CheckPacketIsSentImmediately(); | 214 CheckPacketIsSentImmediately(); |
| 223 | 215 |
| 224 // The first packet was a "make up", then we sent two packets "into the | 216 // The first packet was a "make up", then we sent two packets "into the |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 265 CheckPacketIsSentImmediately(); | 257 CheckPacketIsSentImmediately(); |
| 266 CheckPacketIsDelayed(QuicTime::Delta::FromMicroseconds(2600)); | 258 CheckPacketIsDelayed(QuicTime::Delta::FromMicroseconds(2600)); |
| 267 } | 259 } |
| 268 | 260 |
| 269 TEST_F(PacingSenderTest, InitialBurst) { | 261 TEST_F(PacingSenderTest, InitialBurst) { |
| 270 pacing_sender_.reset(); | 262 pacing_sender_.reset(); |
| 271 mock_sender_ = new StrictMock<MockSendAlgorithm>(); | 263 mock_sender_ = new StrictMock<MockSendAlgorithm>(); |
| 272 pacing_sender_.reset(new PacingSender(mock_sender_, | 264 pacing_sender_.reset(new PacingSender(mock_sender_, |
| 273 QuicTime::Delta::FromMilliseconds(1), | 265 QuicTime::Delta::FromMilliseconds(1), |
| 274 10)); | 266 10)); |
| 275 // Start the test in slow start. | |
| 276 EXPECT_CALL(*mock_sender_, InSlowStart()).WillRepeatedly(Return(true)); | |
| 277 | 267 |
| 278 // Configure bandwith of 1 packet per 2 ms, for which the pacing rate | 268 // Configure pacing rate of 1 packet per 1 ms. |
| 279 // will be 1 packet per 1 ms. | 269 EXPECT_CALL(*mock_sender_, PacingRate()) |
| 280 EXPECT_CALL(*mock_sender_, BandwidthEstimate()) | |
| 281 .WillRepeatedly(Return(QuicBandwidth::FromBytesAndTimeDelta( | 270 .WillRepeatedly(Return(QuicBandwidth::FromBytesAndTimeDelta( |
| 282 kMaxPacketSize, QuicTime::Delta::FromMilliseconds(2)))); | 271 kMaxPacketSize, QuicTime::Delta::FromMilliseconds(1)))); |
| 283 | 272 |
| 284 // Update the RTT and verify that the first 10 packets aren't paced. | 273 // Update the RTT and verify that the first 10 packets aren't paced. |
| 285 EXPECT_CALL(*mock_sender_, OnCongestionEvent(true, kBytesInFlight, _, _)); | 274 EXPECT_CALL(*mock_sender_, OnCongestionEvent(true, kBytesInFlight, _, _)); |
| 286 SendAlgorithmInterface::CongestionVector empty_map; | 275 SendAlgorithmInterface::CongestionVector empty_map; |
| 287 pacing_sender_->OnCongestionEvent(true, kBytesInFlight, empty_map, empty_map); | 276 pacing_sender_->OnCongestionEvent(true, kBytesInFlight, empty_map, empty_map); |
| 288 | 277 |
| 289 // Send 10 packets, and verify that they are not paced. | 278 // Send 10 packets, and verify that they are not paced. |
| 290 for (int i = 0 ; i < kInitialBurstPackets; ++i) { | 279 for (int i = 0 ; i < kInitialBurstPackets; ++i) { |
| 291 CheckPacketIsSentImmediately(); | 280 CheckPacketIsSentImmediately(); |
| 292 } | 281 } |
| (...skipping 30 matching lines...) Expand all Loading... |
| 323 CheckPacketIsSentImmediately(); | 312 CheckPacketIsSentImmediately(); |
| 324 CheckPacketIsDelayed(QuicTime::Delta::FromMilliseconds(2)); | 313 CheckPacketIsDelayed(QuicTime::Delta::FromMilliseconds(2)); |
| 325 } | 314 } |
| 326 | 315 |
| 327 TEST_F(PacingSenderTest, InitialBurstNoRttMeasurement) { | 316 TEST_F(PacingSenderTest, InitialBurstNoRttMeasurement) { |
| 328 pacing_sender_.reset(); | 317 pacing_sender_.reset(); |
| 329 mock_sender_ = new StrictMock<MockSendAlgorithm>(); | 318 mock_sender_ = new StrictMock<MockSendAlgorithm>(); |
| 330 pacing_sender_.reset(new PacingSender(mock_sender_, | 319 pacing_sender_.reset(new PacingSender(mock_sender_, |
| 331 QuicTime::Delta::FromMilliseconds(1), | 320 QuicTime::Delta::FromMilliseconds(1), |
| 332 10)); | 321 10)); |
| 333 // Start the test in slow start. | |
| 334 EXPECT_CALL(*mock_sender_, InSlowStart()).WillRepeatedly(Return(true)); | |
| 335 | 322 |
| 336 // Configure bandwith of 1 packet per 2 ms, for which the pacing rate | 323 // Configure pacing rate of 1 packet per 1 ms. |
| 337 // will be 1 packet per 1 ms. | 324 EXPECT_CALL(*mock_sender_, PacingRate()) |
| 338 EXPECT_CALL(*mock_sender_, BandwidthEstimate()) | |
| 339 .WillRepeatedly(Return(QuicBandwidth::FromBytesAndTimeDelta( | 325 .WillRepeatedly(Return(QuicBandwidth::FromBytesAndTimeDelta( |
| 340 kMaxPacketSize, QuicTime::Delta::FromMilliseconds(2)))); | 326 kMaxPacketSize, QuicTime::Delta::FromMilliseconds(1)))); |
| 341 | 327 |
| 342 // Send 10 packets, and verify that they are not paced. | 328 // Send 10 packets, and verify that they are not paced. |
| 343 for (int i = 0 ; i < kInitialBurstPackets; ++i) { | 329 for (int i = 0 ; i < kInitialBurstPackets; ++i) { |
| 344 CheckPacketIsSentImmediately(); | 330 CheckPacketIsSentImmediately(); |
| 345 } | 331 } |
| 346 | 332 |
| 347 // The first packet was a "make up", then we sent two packets "into the | 333 // The first packet was a "make up", then we sent two packets "into the |
| 348 // future", so the delay should be 2ms. | 334 // future", so the delay should be 2ms. |
| 349 CheckPacketIsSentImmediately(); | 335 CheckPacketIsSentImmediately(); |
| 350 CheckPacketIsSentImmediately(); | 336 CheckPacketIsSentImmediately(); |
| (...skipping 23 matching lines...) Expand all Loading... |
| 374 // The first packet was a "make up", then we sent two packets "into the | 360 // The first packet was a "make up", then we sent two packets "into the |
| 375 // future", so the delay should be 2ms. | 361 // future", so the delay should be 2ms. |
| 376 CheckPacketIsSentImmediately(); | 362 CheckPacketIsSentImmediately(); |
| 377 CheckPacketIsSentImmediately(); | 363 CheckPacketIsSentImmediately(); |
| 378 CheckPacketIsSentImmediately(); | 364 CheckPacketIsSentImmediately(); |
| 379 CheckPacketIsDelayed(QuicTime::Delta::FromMilliseconds(2)); | 365 CheckPacketIsDelayed(QuicTime::Delta::FromMilliseconds(2)); |
| 380 } | 366 } |
| 381 | 367 |
| 382 } // namespace test | 368 } // namespace test |
| 383 } // namespace net | 369 } // namespace net |
| OLD | NEW |