QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 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 |
| 3 | // found in the LICENSE file. |
| 4 | |
| 5 | #include "net/third_party/quiche/src/quic/core/congestion_control/pacing_sender.h" |
| 6 | |
| 7 | #include <memory> |
bnc | 463f235 | 2019-10-10 04:49:34 -0700 | [diff] [blame] | 8 | #include <utility> |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 9 | |
| 10 | #include "net/third_party/quiche/src/quic/core/quic_packets.h" |
| 11 | #include "net/third_party/quiche/src/quic/platform/api/quic_flag_utils.h" |
| 12 | #include "net/third_party/quiche/src/quic/platform/api/quic_flags.h" |
| 13 | #include "net/third_party/quiche/src/quic/platform/api/quic_logging.h" |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 14 | #include "net/third_party/quiche/src/quic/platform/api/quic_test.h" |
| 15 | #include "net/third_party/quiche/src/quic/test_tools/mock_clock.h" |
| 16 | #include "net/third_party/quiche/src/quic/test_tools/quic_test_utils.h" |
| 17 | |
| 18 | using testing::_; |
| 19 | using testing::AtMost; |
| 20 | using testing::IsEmpty; |
| 21 | using testing::Return; |
| 22 | using testing::StrictMock; |
| 23 | |
| 24 | namespace quic { |
| 25 | namespace test { |
| 26 | |
| 27 | const QuicByteCount kBytesInFlight = 1024; |
| 28 | const int kInitialBurstPackets = 10; |
| 29 | |
| 30 | class PacingSenderTest : public QuicTest { |
| 31 | protected: |
| 32 | PacingSenderTest() |
| 33 | : zero_time_(QuicTime::Delta::Zero()), |
| 34 | infinite_time_(QuicTime::Delta::Infinite()), |
| 35 | packet_number_(1), |
| 36 | mock_sender_(new StrictMock<MockSendAlgorithm>()), |
| 37 | pacing_sender_(new PacingSender) { |
| 38 | pacing_sender_->set_sender(mock_sender_.get()); |
| 39 | // Pick arbitrary time. |
| 40 | clock_.AdvanceTime(QuicTime::Delta::FromMilliseconds(9)); |
| 41 | } |
| 42 | |
| 43 | ~PacingSenderTest() override {} |
| 44 | |
| 45 | void InitPacingRate(QuicPacketCount burst_size, QuicBandwidth bandwidth) { |
vasilvv | 0fc587f | 2019-09-06 13:33:08 -0700 | [diff] [blame] | 46 | mock_sender_ = std::make_unique<StrictMock<MockSendAlgorithm>>(); |
| 47 | pacing_sender_ = std::make_unique<PacingSender>(); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 48 | pacing_sender_->set_sender(mock_sender_.get()); |
| 49 | EXPECT_CALL(*mock_sender_, PacingRate(_)).WillRepeatedly(Return(bandwidth)); |
wub | 04a8359 | 2019-04-05 06:30:59 -0700 | [diff] [blame] | 50 | EXPECT_CALL(*mock_sender_, BandwidthEstimate()) |
| 51 | .WillRepeatedly(Return(bandwidth)); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 52 | if (burst_size == 0) { |
| 53 | EXPECT_CALL(*mock_sender_, OnCongestionEvent(_, _, _, _, _)); |
| 54 | LostPacketVector lost_packets; |
dschinazi | 66dea07 | 2019-04-09 11:41:06 -0700 | [diff] [blame] | 55 | lost_packets.push_back( |
| 56 | LostPacket(QuicPacketNumber(1), kMaxOutgoingPacketSize)); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 57 | AckedPacketVector empty; |
| 58 | pacing_sender_->OnCongestionEvent(true, 1234, clock_.Now(), empty, |
| 59 | lost_packets); |
| 60 | } else if (burst_size != kInitialBurstPackets) { |
| 61 | QUIC_LOG(FATAL) << "Unsupported burst_size " << burst_size |
| 62 | << " specificied, only 0 and " << kInitialBurstPackets |
| 63 | << " are supported."; |
| 64 | } |
| 65 | } |
| 66 | |
| 67 | void CheckPacketIsSentImmediately(HasRetransmittableData retransmittable_data, |
| 68 | QuicByteCount bytes_in_flight, |
| 69 | bool in_recovery, |
| 70 | bool cwnd_limited, |
| 71 | QuicPacketCount cwnd) { |
| 72 | // In order for the packet to be sendable, the underlying sender must |
| 73 | // permit it to be sent immediately. |
| 74 | for (int i = 0; i < 2; ++i) { |
| 75 | EXPECT_CALL(*mock_sender_, CanSend(bytes_in_flight)) |
| 76 | .WillOnce(Return(true)); |
| 77 | // Verify that the packet can be sent immediately. |
| 78 | EXPECT_EQ(zero_time_, |
| 79 | pacing_sender_->TimeUntilSend(clock_.Now(), bytes_in_flight)); |
| 80 | } |
| 81 | |
| 82 | // Actually send the packet. |
| 83 | if (bytes_in_flight == 0) { |
| 84 | EXPECT_CALL(*mock_sender_, InRecovery()).WillOnce(Return(in_recovery)); |
| 85 | } |
| 86 | EXPECT_CALL(*mock_sender_, |
| 87 | OnPacketSent(clock_.Now(), bytes_in_flight, packet_number_, |
dschinazi | 66dea07 | 2019-04-09 11:41:06 -0700 | [diff] [blame] | 88 | kMaxOutgoingPacketSize, retransmittable_data)); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 89 | EXPECT_CALL(*mock_sender_, GetCongestionWindow()) |
| 90 | .Times(AtMost(1)) |
| 91 | .WillRepeatedly(Return(cwnd * kDefaultTCPMSS)); |
dschinazi | 66dea07 | 2019-04-09 11:41:06 -0700 | [diff] [blame] | 92 | EXPECT_CALL(*mock_sender_, |
| 93 | CanSend(bytes_in_flight + kMaxOutgoingPacketSize)) |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 94 | .Times(AtMost(1)) |
| 95 | .WillRepeatedly(Return(!cwnd_limited)); |
| 96 | pacing_sender_->OnPacketSent(clock_.Now(), bytes_in_flight, |
dschinazi | 66dea07 | 2019-04-09 11:41:06 -0700 | [diff] [blame] | 97 | packet_number_++, kMaxOutgoingPacketSize, |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 98 | retransmittable_data); |
| 99 | } |
| 100 | |
| 101 | void CheckPacketIsSentImmediately() { |
| 102 | CheckPacketIsSentImmediately(HAS_RETRANSMITTABLE_DATA, kBytesInFlight, |
| 103 | false, false, 10); |
| 104 | } |
| 105 | |
| 106 | void CheckPacketIsDelayed(QuicTime::Delta delay) { |
| 107 | // In order for the packet to be sendable, the underlying sender must |
| 108 | // permit it to be sent immediately. |
| 109 | for (int i = 0; i < 2; ++i) { |
| 110 | EXPECT_CALL(*mock_sender_, CanSend(kBytesInFlight)) |
| 111 | .WillOnce(Return(true)); |
| 112 | // Verify that the packet is delayed. |
| 113 | EXPECT_EQ(delay.ToMicroseconds(), |
| 114 | pacing_sender_->TimeUntilSend(clock_.Now(), kBytesInFlight) |
| 115 | .ToMicroseconds()); |
| 116 | } |
| 117 | } |
| 118 | |
| 119 | void UpdateRtt() { |
| 120 | EXPECT_CALL(*mock_sender_, |
| 121 | OnCongestionEvent(true, kBytesInFlight, _, _, _)); |
| 122 | AckedPacketVector empty_acked; |
| 123 | LostPacketVector empty_lost; |
| 124 | pacing_sender_->OnCongestionEvent(true, kBytesInFlight, clock_.Now(), |
| 125 | empty_acked, empty_lost); |
| 126 | } |
| 127 | |
| 128 | void OnApplicationLimited() { pacing_sender_->OnApplicationLimited(); } |
| 129 | |
| 130 | const QuicTime::Delta zero_time_; |
| 131 | const QuicTime::Delta infinite_time_; |
| 132 | MockClock clock_; |
| 133 | QuicPacketNumber packet_number_; |
| 134 | std::unique_ptr<StrictMock<MockSendAlgorithm>> mock_sender_; |
| 135 | std::unique_ptr<PacingSender> pacing_sender_; |
| 136 | }; |
| 137 | |
| 138 | TEST_F(PacingSenderTest, NoSend) { |
| 139 | for (int i = 0; i < 2; ++i) { |
| 140 | EXPECT_CALL(*mock_sender_, CanSend(kBytesInFlight)).WillOnce(Return(false)); |
| 141 | EXPECT_EQ(infinite_time_, |
| 142 | pacing_sender_->TimeUntilSend(clock_.Now(), kBytesInFlight)); |
| 143 | } |
| 144 | } |
| 145 | |
| 146 | TEST_F(PacingSenderTest, SendNow) { |
| 147 | for (int i = 0; i < 2; ++i) { |
| 148 | EXPECT_CALL(*mock_sender_, CanSend(kBytesInFlight)).WillOnce(Return(true)); |
| 149 | EXPECT_EQ(zero_time_, |
| 150 | pacing_sender_->TimeUntilSend(clock_.Now(), kBytesInFlight)); |
| 151 | } |
| 152 | } |
| 153 | |
| 154 | TEST_F(PacingSenderTest, VariousSending) { |
| 155 | // Configure pacing rate of 1 packet per 1 ms, no initial burst. |
dschinazi | 66dea07 | 2019-04-09 11:41:06 -0700 | [diff] [blame] | 156 | InitPacingRate( |
| 157 | 0, QuicBandwidth::FromBytesAndTimeDelta( |
| 158 | kMaxOutgoingPacketSize, QuicTime::Delta::FromMilliseconds(1))); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 159 | |
| 160 | // Now update the RTT and verify that packets are actually paced. |
| 161 | UpdateRtt(); |
| 162 | |
| 163 | CheckPacketIsSentImmediately(); |
| 164 | CheckPacketIsSentImmediately(); |
| 165 | |
| 166 | // The first packet was a "make up", then we sent two packets "into the |
| 167 | // future", so the delay should be 2. |
| 168 | CheckPacketIsDelayed(QuicTime::Delta::FromMilliseconds(2)); |
| 169 | |
| 170 | // Wake up on time. |
| 171 | clock_.AdvanceTime(QuicTime::Delta::FromMilliseconds(2)); |
| 172 | CheckPacketIsSentImmediately(); |
| 173 | CheckPacketIsSentImmediately(); |
| 174 | CheckPacketIsDelayed(QuicTime::Delta::FromMilliseconds(2)); |
| 175 | |
| 176 | // Wake up late. |
| 177 | clock_.AdvanceTime(QuicTime::Delta::FromMilliseconds(4)); |
| 178 | CheckPacketIsSentImmediately(); |
| 179 | CheckPacketIsSentImmediately(); |
| 180 | CheckPacketIsSentImmediately(); |
| 181 | CheckPacketIsSentImmediately(); |
| 182 | CheckPacketIsDelayed(QuicTime::Delta::FromMilliseconds(2)); |
| 183 | |
| 184 | // Wake up really late. |
| 185 | clock_.AdvanceTime(QuicTime::Delta::FromMilliseconds(8)); |
| 186 | CheckPacketIsSentImmediately(); |
| 187 | CheckPacketIsSentImmediately(); |
| 188 | CheckPacketIsSentImmediately(); |
| 189 | CheckPacketIsSentImmediately(); |
| 190 | CheckPacketIsSentImmediately(); |
| 191 | CheckPacketIsSentImmediately(); |
| 192 | CheckPacketIsSentImmediately(); |
| 193 | CheckPacketIsSentImmediately(); |
| 194 | CheckPacketIsDelayed(QuicTime::Delta::FromMilliseconds(2)); |
| 195 | |
| 196 | // Wake up really late again, but application pause partway through. |
| 197 | clock_.AdvanceTime(QuicTime::Delta::FromMilliseconds(8)); |
| 198 | CheckPacketIsSentImmediately(); |
| 199 | CheckPacketIsSentImmediately(); |
| 200 | OnApplicationLimited(); |
| 201 | clock_.AdvanceTime(QuicTime::Delta::FromMilliseconds(100)); |
| 202 | CheckPacketIsSentImmediately(); |
| 203 | CheckPacketIsSentImmediately(); |
| 204 | CheckPacketIsDelayed(QuicTime::Delta::FromMilliseconds(2)); |
| 205 | // Wake up early, but after enough time has passed to permit a send. |
| 206 | clock_.AdvanceTime(QuicTime::Delta::FromMilliseconds(1)); |
| 207 | CheckPacketIsSentImmediately(); |
| 208 | } |
| 209 | |
| 210 | TEST_F(PacingSenderTest, InitialBurst) { |
| 211 | // Configure pacing rate of 1 packet per 1 ms. |
dschinazi | 66dea07 | 2019-04-09 11:41:06 -0700 | [diff] [blame] | 212 | InitPacingRate( |
| 213 | 10, QuicBandwidth::FromBytesAndTimeDelta( |
| 214 | kMaxOutgoingPacketSize, QuicTime::Delta::FromMilliseconds(1))); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 215 | |
| 216 | // Update the RTT and verify that the first 10 packets aren't paced. |
| 217 | UpdateRtt(); |
| 218 | |
| 219 | // Send 10 packets, and verify that they are not paced. |
| 220 | for (int i = 0; i < kInitialBurstPackets; ++i) { |
| 221 | CheckPacketIsSentImmediately(); |
| 222 | } |
| 223 | |
| 224 | // The first packet was a "make up", then we sent two packets "into the |
| 225 | // future", so the delay should be 2ms. |
| 226 | CheckPacketIsSentImmediately(); |
| 227 | CheckPacketIsSentImmediately(); |
| 228 | CheckPacketIsDelayed(QuicTime::Delta::FromMilliseconds(2)); |
| 229 | |
| 230 | clock_.AdvanceTime(QuicTime::Delta::FromMilliseconds(5)); |
| 231 | CheckPacketIsSentImmediately(); |
| 232 | |
| 233 | // Next time TimeUntilSend is called with no bytes in flight, pacing should |
| 234 | // allow a packet to be sent, and when it's sent, the tokens are refilled. |
| 235 | CheckPacketIsSentImmediately(HAS_RETRANSMITTABLE_DATA, 0, false, false, 10); |
| 236 | for (int i = 0; i < kInitialBurstPackets - 1; ++i) { |
| 237 | CheckPacketIsSentImmediately(); |
| 238 | } |
| 239 | |
| 240 | // The first packet was a "make up", then we sent two packets "into the |
| 241 | // future", so the delay should be 2ms. |
| 242 | CheckPacketIsSentImmediately(); |
| 243 | CheckPacketIsSentImmediately(); |
| 244 | CheckPacketIsDelayed(QuicTime::Delta::FromMilliseconds(2)); |
| 245 | } |
| 246 | |
| 247 | TEST_F(PacingSenderTest, InitialBurstNoRttMeasurement) { |
| 248 | // Configure pacing rate of 1 packet per 1 ms. |
dschinazi | 66dea07 | 2019-04-09 11:41:06 -0700 | [diff] [blame] | 249 | InitPacingRate( |
| 250 | 10, QuicBandwidth::FromBytesAndTimeDelta( |
| 251 | kMaxOutgoingPacketSize, QuicTime::Delta::FromMilliseconds(1))); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 252 | |
| 253 | // Send 10 packets, and verify that they are not paced. |
| 254 | for (int i = 0; i < kInitialBurstPackets; ++i) { |
| 255 | CheckPacketIsSentImmediately(); |
| 256 | } |
| 257 | |
| 258 | // The first packet was a "make up", then we sent two packets "into the |
| 259 | // future", so the delay should be 2ms. |
| 260 | CheckPacketIsSentImmediately(); |
| 261 | CheckPacketIsSentImmediately(); |
| 262 | CheckPacketIsDelayed(QuicTime::Delta::FromMilliseconds(2)); |
| 263 | |
| 264 | clock_.AdvanceTime(QuicTime::Delta::FromMilliseconds(5)); |
| 265 | CheckPacketIsSentImmediately(); |
| 266 | |
| 267 | // Next time TimeUntilSend is called with no bytes in flight, the tokens |
| 268 | // should be refilled and there should be no delay. |
| 269 | CheckPacketIsSentImmediately(HAS_RETRANSMITTABLE_DATA, 0, false, false, 10); |
| 270 | // Send 10 packets, and verify that they are not paced. |
| 271 | for (int i = 0; i < kInitialBurstPackets - 1; ++i) { |
| 272 | CheckPacketIsSentImmediately(); |
| 273 | } |
| 274 | |
| 275 | // The first packet was a "make up", then we sent two packets "into the |
| 276 | // future", so the delay should be 2ms. |
| 277 | CheckPacketIsSentImmediately(); |
| 278 | CheckPacketIsSentImmediately(); |
| 279 | CheckPacketIsDelayed(QuicTime::Delta::FromMilliseconds(2)); |
| 280 | } |
| 281 | |
| 282 | TEST_F(PacingSenderTest, FastSending) { |
wub | 0a564aa | 2019-07-02 14:59:39 -0700 | [diff] [blame] | 283 | // Ensure the pacing sender paces, even when the inter-packet spacing(0.5ms) |
| 284 | // is less than the pacing granularity(1ms). |
dschinazi | 66dea07 | 2019-04-09 11:41:06 -0700 | [diff] [blame] | 285 | InitPacingRate(10, QuicBandwidth::FromBytesAndTimeDelta( |
| 286 | 2 * kMaxOutgoingPacketSize, |
| 287 | QuicTime::Delta::FromMilliseconds(1))); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 288 | // Update the RTT and verify that the first 10 packets aren't paced. |
| 289 | UpdateRtt(); |
| 290 | |
| 291 | // Send 10 packets, and verify that they are not paced. |
| 292 | for (int i = 0; i < kInitialBurstPackets; ++i) { |
| 293 | CheckPacketIsSentImmediately(); |
| 294 | } |
| 295 | |
wub | 0a564aa | 2019-07-02 14:59:39 -0700 | [diff] [blame] | 296 | CheckPacketIsSentImmediately(); // Make up |
| 297 | CheckPacketIsSentImmediately(); // Lumpy token |
| 298 | CheckPacketIsSentImmediately(); // "In the future" but within granularity. |
| 299 | CheckPacketIsSentImmediately(); // Lumpy token |
| 300 | CheckPacketIsDelayed(QuicTime::Delta::FromMicroseconds(2000)); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 301 | |
| 302 | clock_.AdvanceTime(QuicTime::Delta::FromMilliseconds(5)); |
| 303 | CheckPacketIsSentImmediately(); |
| 304 | |
| 305 | // Next time TimeUntilSend is called with no bytes in flight, the tokens |
| 306 | // should be refilled and there should be no delay. |
| 307 | CheckPacketIsSentImmediately(HAS_RETRANSMITTABLE_DATA, 0, false, false, 10); |
| 308 | for (int i = 0; i < kInitialBurstPackets - 1; ++i) { |
| 309 | CheckPacketIsSentImmediately(); |
| 310 | } |
| 311 | |
| 312 | // The first packet was a "make up", then we sent two packets "into the |
| 313 | // future", so the delay should be 1.5ms. |
wub | 0a564aa | 2019-07-02 14:59:39 -0700 | [diff] [blame] | 314 | CheckPacketIsSentImmediately(); // Make up |
| 315 | CheckPacketIsSentImmediately(); // Lumpy token |
| 316 | CheckPacketIsSentImmediately(); // "In the future" but within granularity. |
| 317 | CheckPacketIsSentImmediately(); // Lumpy token |
| 318 | CheckPacketIsDelayed(QuicTime::Delta::FromMicroseconds(2000)); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 319 | } |
| 320 | |
| 321 | TEST_F(PacingSenderTest, NoBurstEnteringRecovery) { |
| 322 | // Configure pacing rate of 1 packet per 1 ms with no burst tokens. |
dschinazi | 66dea07 | 2019-04-09 11:41:06 -0700 | [diff] [blame] | 323 | InitPacingRate( |
| 324 | 0, QuicBandwidth::FromBytesAndTimeDelta( |
| 325 | kMaxOutgoingPacketSize, QuicTime::Delta::FromMilliseconds(1))); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 326 | // Sending a packet will set burst tokens. |
| 327 | CheckPacketIsSentImmediately(); |
| 328 | |
| 329 | // Losing a packet will set clear burst tokens. |
| 330 | LostPacketVector lost_packets; |
dschinazi | 66dea07 | 2019-04-09 11:41:06 -0700 | [diff] [blame] | 331 | lost_packets.push_back( |
| 332 | LostPacket(QuicPacketNumber(1), kMaxOutgoingPacketSize)); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 333 | AckedPacketVector empty_acked; |
| 334 | EXPECT_CALL(*mock_sender_, |
dschinazi | 66dea07 | 2019-04-09 11:41:06 -0700 | [diff] [blame] | 335 | OnCongestionEvent(true, kMaxOutgoingPacketSize, _, IsEmpty(), _)); |
| 336 | pacing_sender_->OnCongestionEvent(true, kMaxOutgoingPacketSize, clock_.Now(), |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 337 | empty_acked, lost_packets); |
| 338 | // One packet is sent immediately, because of 1ms pacing granularity. |
| 339 | CheckPacketIsSentImmediately(); |
| 340 | // Ensure packets are immediately paced. |
| 341 | EXPECT_CALL(*mock_sender_, CanSend(kDefaultTCPMSS)).WillOnce(Return(true)); |
| 342 | // Verify the next packet is paced and delayed 2ms due to granularity. |
| 343 | EXPECT_EQ(QuicTime::Delta::FromMilliseconds(2), |
| 344 | pacing_sender_->TimeUntilSend(clock_.Now(), kDefaultTCPMSS)); |
| 345 | CheckPacketIsDelayed(QuicTime::Delta::FromMilliseconds(2)); |
| 346 | } |
| 347 | |
| 348 | TEST_F(PacingSenderTest, NoBurstInRecovery) { |
| 349 | // Configure pacing rate of 1 packet per 1 ms with no burst tokens. |
dschinazi | 66dea07 | 2019-04-09 11:41:06 -0700 | [diff] [blame] | 350 | InitPacingRate( |
| 351 | 0, QuicBandwidth::FromBytesAndTimeDelta( |
| 352 | kMaxOutgoingPacketSize, QuicTime::Delta::FromMilliseconds(1))); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 353 | |
| 354 | UpdateRtt(); |
| 355 | |
| 356 | // Ensure only one packet is sent immediately and the rest are paced. |
| 357 | CheckPacketIsSentImmediately(HAS_RETRANSMITTABLE_DATA, 0, true, false, 10); |
| 358 | CheckPacketIsSentImmediately(); |
| 359 | CheckPacketIsDelayed(QuicTime::Delta::FromMilliseconds(2)); |
| 360 | } |
| 361 | |
| 362 | TEST_F(PacingSenderTest, CwndLimited) { |
| 363 | // Configure pacing rate of 1 packet per 1 ms, no initial burst. |
dschinazi | 66dea07 | 2019-04-09 11:41:06 -0700 | [diff] [blame] | 364 | InitPacingRate( |
| 365 | 0, QuicBandwidth::FromBytesAndTimeDelta( |
| 366 | kMaxOutgoingPacketSize, QuicTime::Delta::FromMilliseconds(1))); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 367 | |
| 368 | UpdateRtt(); |
| 369 | |
| 370 | CheckPacketIsSentImmediately(); |
| 371 | CheckPacketIsSentImmediately(); |
| 372 | // Packet 3 will be delayed 2ms. |
| 373 | CheckPacketIsDelayed(QuicTime::Delta::FromMilliseconds(2)); |
| 374 | |
| 375 | // Wake up on time. |
| 376 | clock_.AdvanceTime(QuicTime::Delta::FromMilliseconds(2)); |
| 377 | // After sending packet 3, cwnd is limited. |
| 378 | CheckPacketIsSentImmediately(HAS_RETRANSMITTABLE_DATA, kBytesInFlight, false, |
| 379 | true, 10); |
| 380 | |
| 381 | clock_.AdvanceTime(QuicTime::Delta::FromMilliseconds(100)); |
| 382 | // Verify pacing sender stops making up for lost time after sending packet 3. |
| 383 | // Packet 6 will be delayed 2ms. |
| 384 | CheckPacketIsSentImmediately(); |
| 385 | CheckPacketIsSentImmediately(); |
| 386 | CheckPacketIsDelayed(QuicTime::Delta::FromMilliseconds(2)); |
| 387 | } |
| 388 | |
| 389 | TEST_F(PacingSenderTest, LumpyPacingWithInitialBurstToken) { |
| 390 | // Set lumpy size to be 3, and cwnd faction to 0.5 |
wub | 4985598 | 2019-05-01 14:16:26 -0700 | [diff] [blame] | 391 | SetQuicFlag(FLAGS_quic_lumpy_pacing_size, 3); |
| 392 | SetQuicFlag(FLAGS_quic_lumpy_pacing_cwnd_fraction, 0.5f); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 393 | // Configure pacing rate of 1 packet per 1 ms. |
dschinazi | 66dea07 | 2019-04-09 11:41:06 -0700 | [diff] [blame] | 394 | InitPacingRate( |
| 395 | 10, QuicBandwidth::FromBytesAndTimeDelta( |
| 396 | kMaxOutgoingPacketSize, QuicTime::Delta::FromMilliseconds(1))); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 397 | UpdateRtt(); |
| 398 | |
| 399 | // Send 10 packets, and verify that they are not paced. |
| 400 | for (int i = 0; i < kInitialBurstPackets; ++i) { |
| 401 | CheckPacketIsSentImmediately(); |
| 402 | } |
| 403 | |
| 404 | CheckPacketIsSentImmediately(); |
| 405 | CheckPacketIsSentImmediately(); |
| 406 | CheckPacketIsSentImmediately(); |
| 407 | // Packet 14 will be delayed 3ms. |
| 408 | CheckPacketIsDelayed(QuicTime::Delta::FromMilliseconds(3)); |
| 409 | |
| 410 | // Wake up on time. |
| 411 | clock_.AdvanceTime(QuicTime::Delta::FromMilliseconds(3)); |
| 412 | CheckPacketIsSentImmediately(); |
| 413 | CheckPacketIsSentImmediately(); |
| 414 | CheckPacketIsSentImmediately(); |
| 415 | // Packet 17 will be delayed 3ms. |
| 416 | CheckPacketIsDelayed(QuicTime::Delta::FromMilliseconds(3)); |
| 417 | |
| 418 | // Application throttles sending. |
| 419 | OnApplicationLimited(); |
| 420 | clock_.AdvanceTime(QuicTime::Delta::FromMilliseconds(100)); |
| 421 | CheckPacketIsSentImmediately(); |
| 422 | CheckPacketIsSentImmediately(); |
| 423 | CheckPacketIsSentImmediately(); |
| 424 | // Packet 20 will be delayed 3ms. |
| 425 | CheckPacketIsDelayed(QuicTime::Delta::FromMilliseconds(3)); |
| 426 | |
| 427 | // Wake up on time. |
| 428 | clock_.AdvanceTime(QuicTime::Delta::FromMilliseconds(3)); |
| 429 | CheckPacketIsSentImmediately(); |
| 430 | // After sending packet 21, cwnd is limited. |
| 431 | CheckPacketIsSentImmediately(HAS_RETRANSMITTABLE_DATA, kBytesInFlight, false, |
| 432 | true, 10); |
| 433 | |
| 434 | clock_.AdvanceTime(QuicTime::Delta::FromMilliseconds(100)); |
| 435 | // Suppose cwnd size is 5, so that lumpy size becomes 2. |
| 436 | CheckPacketIsSentImmediately(HAS_RETRANSMITTABLE_DATA, kBytesInFlight, false, |
| 437 | false, 5); |
| 438 | CheckPacketIsSentImmediately(); |
| 439 | // Packet 24 will be delayed 2ms. |
| 440 | CheckPacketIsDelayed(QuicTime::Delta::FromMilliseconds(2)); |
| 441 | } |
| 442 | |
wub | 04a8359 | 2019-04-05 06:30:59 -0700 | [diff] [blame] | 443 | TEST_F(PacingSenderTest, NoLumpyPacingForLowBandwidthFlows) { |
| 444 | // Set lumpy size to be 3, and cwnd faction to 0.5 |
wub | 4985598 | 2019-05-01 14:16:26 -0700 | [diff] [blame] | 445 | SetQuicFlag(FLAGS_quic_lumpy_pacing_size, 3); |
| 446 | SetQuicFlag(FLAGS_quic_lumpy_pacing_cwnd_fraction, 0.5f); |
wub | 04a8359 | 2019-04-05 06:30:59 -0700 | [diff] [blame] | 447 | |
| 448 | // Configure pacing rate of 1 packet per 100 ms. |
| 449 | QuicTime::Delta inter_packet_delay = QuicTime::Delta::FromMilliseconds(100); |
dschinazi | 66dea07 | 2019-04-09 11:41:06 -0700 | [diff] [blame] | 450 | InitPacingRate(kInitialBurstPackets, |
| 451 | QuicBandwidth::FromBytesAndTimeDelta(kMaxOutgoingPacketSize, |
| 452 | inter_packet_delay)); |
wub | 04a8359 | 2019-04-05 06:30:59 -0700 | [diff] [blame] | 453 | UpdateRtt(); |
| 454 | |
| 455 | // Send kInitialBurstPackets packets, and verify that they are not paced. |
| 456 | for (int i = 0; i < kInitialBurstPackets; ++i) { |
| 457 | CheckPacketIsSentImmediately(); |
| 458 | } |
| 459 | |
| 460 | // The first packet after burst token exhausted is also sent immediately, |
| 461 | // because ideal_next_packet_send_time has not been set yet. |
| 462 | CheckPacketIsSentImmediately(); |
| 463 | |
| 464 | for (int i = 0; i < 200; ++i) { |
| 465 | CheckPacketIsDelayed(inter_packet_delay); |
| 466 | } |
| 467 | } |
| 468 | |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 469 | } // namespace test |
| 470 | } // namespace quic |