Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(83)

Side by Side Diff: net/quic/congestion_control/tcp_cubic_bytes_sender_test.cc

Issue 1785663003: Deprecate FLAG_quic_use_new_tcp_sender (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@115885351
Patch Set: Created 4 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright (c) 2015 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/quic/congestion_control/tcp_cubic_bytes_sender.h"
6
7 #include <algorithm>
8
9 #include "base/logging.h"
10 #include "base/memory/scoped_ptr.h"
11 #include "net/quic/congestion_control/rtt_stats.h"
12 #include "net/quic/crypto/crypto_protocol.h"
13 #include "net/quic/proto/cached_network_parameters.pb.h"
14 #include "net/quic/quic_flags.h"
15 #include "net/quic/quic_protocol.h"
16 #include "net/quic/quic_utils.h"
17 #include "net/quic/test_tools/mock_clock.h"
18 #include "net/quic/test_tools/quic_config_peer.h"
19 #include "net/quic/test_tools/quic_test_utils.h"
20 #include "testing/gtest/include/gtest/gtest.h"
21
22 namespace net {
23 namespace test {
24
25 // TODO(ianswett): A number of theses tests were written with the assumption of
26 // an initial CWND of 10. They have carefully calculated values which should be
27 // updated to be based on kInitialCongestionWindow.
28 const uint32_t kInitialCongestionWindowPackets = 10;
29 const uint32_t kDefaultWindowTCP =
30 kInitialCongestionWindowPackets * kDefaultTCPMSS;
31 const float kRenoBeta = 0.7f; // Reno backoff factor.
32
33 class TcpCubicBytesSenderPeer : public TcpCubicBytesSender {
34 public:
35 TcpCubicBytesSenderPeer(const QuicClock* clock, bool reno)
36 : TcpCubicBytesSender(clock,
37 &rtt_stats_,
38 reno,
39 kInitialCongestionWindowPackets,
40 kMaxCongestionWindow,
41 &stats_) {}
42
43 const HybridSlowStart& hybrid_slow_start() const {
44 return hybrid_slow_start_;
45 }
46
47 float GetRenoBeta() const { return RenoBeta(); }
48
49 RttStats rtt_stats_;
50 QuicConnectionStats stats_;
51 };
52
53 class TcpCubicBytesSenderTest : public ::testing::Test {
54 protected:
55 TcpCubicBytesSenderTest()
56 : one_ms_(QuicTime::Delta::FromMilliseconds(1)),
57 sender_(new TcpCubicBytesSenderPeer(&clock_, true)),
58 packet_number_(1),
59 acked_packet_number_(0),
60 bytes_in_flight_(0) {}
61
62 int SendAvailableSendWindow() {
63 // Send as long as TimeUntilSend returns Zero.
64 int packets_sent = 0;
65 bool can_send = sender_->TimeUntilSend(clock_.Now(), bytes_in_flight_,
66 HAS_RETRANSMITTABLE_DATA)
67 .IsZero();
68 while (can_send) {
69 sender_->OnPacketSent(clock_.Now(), bytes_in_flight_, packet_number_++,
70 kDefaultTCPMSS, HAS_RETRANSMITTABLE_DATA);
71 ++packets_sent;
72 bytes_in_flight_ += kDefaultTCPMSS;
73 can_send = sender_->TimeUntilSend(clock_.Now(), bytes_in_flight_,
74 HAS_RETRANSMITTABLE_DATA)
75 .IsZero();
76 }
77 return packets_sent;
78 }
79
80 // Normal is that TCP acks every other segment.
81 void AckNPackets(int n) {
82 sender_->rtt_stats_.UpdateRtt(QuicTime::Delta::FromMilliseconds(60),
83 QuicTime::Delta::Zero(), clock_.Now());
84 SendAlgorithmInterface::CongestionVector acked_packets;
85 SendAlgorithmInterface::CongestionVector lost_packets;
86 for (int i = 0; i < n; ++i) {
87 ++acked_packet_number_;
88 acked_packets.push_back(
89 std::make_pair(acked_packet_number_, kDefaultTCPMSS));
90 }
91 sender_->OnCongestionEvent(true, bytes_in_flight_, acked_packets,
92 lost_packets);
93 bytes_in_flight_ -= n * kDefaultTCPMSS;
94 clock_.AdvanceTime(one_ms_);
95 }
96
97 void LoseNPackets(int n) {
98 SendAlgorithmInterface::CongestionVector acked_packets;
99 SendAlgorithmInterface::CongestionVector lost_packets;
100 for (int i = 0; i < n; ++i) {
101 ++acked_packet_number_;
102 lost_packets.push_back(
103 std::make_pair(acked_packet_number_, kDefaultTCPMSS));
104 }
105 sender_->OnCongestionEvent(false, bytes_in_flight_, acked_packets,
106 lost_packets);
107 bytes_in_flight_ -= n * kDefaultTCPMSS;
108 }
109
110 // Does not increment acked_packet_number_.
111 void LosePacket(QuicPacketNumber packet_number) {
112 SendAlgorithmInterface::CongestionVector acked_packets;
113 SendAlgorithmInterface::CongestionVector lost_packets;
114 lost_packets.push_back(std::make_pair(packet_number, kDefaultTCPMSS));
115 sender_->OnCongestionEvent(false, bytes_in_flight_, acked_packets,
116 lost_packets);
117 bytes_in_flight_ -= kDefaultTCPMSS;
118 }
119
120 const QuicTime::Delta one_ms_;
121 MockClock clock_;
122 scoped_ptr<TcpCubicBytesSenderPeer> sender_;
123 QuicPacketNumber packet_number_;
124 QuicPacketNumber acked_packet_number_;
125 QuicByteCount bytes_in_flight_;
126 };
127
128 TEST_F(TcpCubicBytesSenderTest, SimpleSender) {
129 // At startup make sure we are at the default.
130 EXPECT_EQ(kDefaultWindowTCP, sender_->GetCongestionWindow());
131 // At startup make sure we can send.
132 EXPECT_TRUE(sender_->TimeUntilSend(clock_.Now(), 0, HAS_RETRANSMITTABLE_DATA)
133 .IsZero());
134 // Make sure we can send.
135 EXPECT_TRUE(sender_->TimeUntilSend(clock_.Now(), 0, HAS_RETRANSMITTABLE_DATA)
136 .IsZero());
137 // And that window is un-affected.
138 EXPECT_EQ(kDefaultWindowTCP, sender_->GetCongestionWindow());
139
140 // Fill the send window with data, then verify that we can't send.
141 SendAvailableSendWindow();
142 EXPECT_FALSE(sender_->TimeUntilSend(clock_.Now(),
143 sender_->GetCongestionWindow(),
144 HAS_RETRANSMITTABLE_DATA)
145 .IsZero());
146 }
147
148 TEST_F(TcpCubicBytesSenderTest, ApplicationLimitedSlowStart) {
149 // Send exactly 10 packets and ensure the CWND ends at 14 packets.
150 const int kNumberOfAcks = 5;
151 // At startup make sure we can send.
152 EXPECT_TRUE(sender_->TimeUntilSend(clock_.Now(), 0, HAS_RETRANSMITTABLE_DATA)
153 .IsZero());
154 // Make sure we can send.
155 EXPECT_TRUE(sender_->TimeUntilSend(clock_.Now(), 0, HAS_RETRANSMITTABLE_DATA)
156 .IsZero());
157
158 SendAvailableSendWindow();
159 for (int i = 0; i < kNumberOfAcks; ++i) {
160 AckNPackets(2);
161 }
162 QuicByteCount bytes_to_send = sender_->GetCongestionWindow();
163 // It's expected 2 acks will arrive when the bytes_in_flight are greater than
164 // half the CWND.
165 EXPECT_EQ(kDefaultWindowTCP + kDefaultTCPMSS * 2 * 2, bytes_to_send);
166 }
167
168 TEST_F(TcpCubicBytesSenderTest, ExponentialSlowStart) {
169 const int kNumberOfAcks = 20;
170 // At startup make sure we can send.
171 EXPECT_TRUE(sender_->TimeUntilSend(clock_.Now(), 0, HAS_RETRANSMITTABLE_DATA)
172 .IsZero());
173 EXPECT_EQ(QuicBandwidth::Zero(), sender_->BandwidthEstimate());
174 // Make sure we can send.
175 EXPECT_TRUE(sender_->TimeUntilSend(clock_.Now(), 0, HAS_RETRANSMITTABLE_DATA)
176 .IsZero());
177
178 for (int i = 0; i < kNumberOfAcks; ++i) {
179 // Send our full send window.
180 SendAvailableSendWindow();
181 AckNPackets(2);
182 }
183 const QuicByteCount cwnd = sender_->GetCongestionWindow();
184 EXPECT_EQ(kDefaultWindowTCP + kDefaultTCPMSS * 2 * kNumberOfAcks, cwnd);
185 EXPECT_EQ(QuicBandwidth::FromBytesAndTimeDelta(
186 cwnd, sender_->rtt_stats_.smoothed_rtt()),
187 sender_->BandwidthEstimate());
188 }
189
190 TEST_F(TcpCubicBytesSenderTest, SlowStartPacketLoss) {
191 sender_->SetNumEmulatedConnections(1);
192 const int kNumberOfAcks = 10;
193 for (int i = 0; i < kNumberOfAcks; ++i) {
194 // Send our full send window.
195 SendAvailableSendWindow();
196 AckNPackets(2);
197 }
198 SendAvailableSendWindow();
199 QuicByteCount expected_send_window =
200 kDefaultWindowTCP + (kDefaultTCPMSS * 2 * kNumberOfAcks);
201 EXPECT_EQ(expected_send_window, sender_->GetCongestionWindow());
202
203 // Lose a packet to exit slow start.
204 LoseNPackets(1);
205 size_t packets_in_recovery_window = expected_send_window / kDefaultTCPMSS;
206
207 // We should now have fallen out of slow start with a reduced window.
208 expected_send_window *= kRenoBeta;
209 EXPECT_EQ(expected_send_window, sender_->GetCongestionWindow());
210
211 // Recovery phase. We need to ack every packet in the recovery window before
212 // we exit recovery.
213 size_t number_of_packets_in_window = expected_send_window / kDefaultTCPMSS;
214 DVLOG(1) << "number_packets: " << number_of_packets_in_window;
215 AckNPackets(packets_in_recovery_window);
216 SendAvailableSendWindow();
217 EXPECT_EQ(expected_send_window, sender_->GetCongestionWindow());
218
219 // We need to ack an entire window before we increase CWND by 1.
220 AckNPackets(number_of_packets_in_window - 2);
221 SendAvailableSendWindow();
222 EXPECT_EQ(expected_send_window, sender_->GetCongestionWindow());
223
224 // Next ack should increase cwnd by 1.
225 AckNPackets(1);
226 expected_send_window += kDefaultTCPMSS;
227 EXPECT_EQ(expected_send_window, sender_->GetCongestionWindow());
228
229 // Now RTO and ensure slow start gets reset.
230 EXPECT_TRUE(sender_->hybrid_slow_start().started());
231 sender_->OnRetransmissionTimeout(true);
232 EXPECT_FALSE(sender_->hybrid_slow_start().started());
233 }
234
235 TEST_F(TcpCubicBytesSenderTest, SlowStartPacketLossWithLargeReduction) {
236 QuicConfig config;
237 QuicTagVector options;
238 options.push_back(kSSLR);
239 QuicConfigPeer::SetReceivedConnectionOptions(&config, options);
240 sender_->SetFromConfig(config, Perspective::IS_SERVER);
241
242 sender_->SetNumEmulatedConnections(1);
243 const int kNumberOfAcks = 10;
244 for (int i = 0; i < kNumberOfAcks; ++i) {
245 // Send our full send window.
246 SendAvailableSendWindow();
247 AckNPackets(2);
248 }
249 SendAvailableSendWindow();
250 QuicByteCount expected_send_window =
251 kDefaultWindowTCP + (kDefaultTCPMSS * 2 * kNumberOfAcks);
252 EXPECT_EQ(expected_send_window, sender_->GetCongestionWindow());
253
254 // Lose a packet to exit slow start. We should now have fallen out of
255 // slow start with a window reduced by 1.
256 LoseNPackets(1);
257 expected_send_window -= kDefaultTCPMSS;
258 EXPECT_EQ(expected_send_window, sender_->GetCongestionWindow());
259
260 // Lose 5 packets in recovery and verify that congestion window is reduced
261 // further.
262 LoseNPackets(5);
263 expected_send_window -= 5 * kDefaultTCPMSS;
264 EXPECT_EQ(expected_send_window, sender_->GetCongestionWindow());
265
266 size_t packets_in_recovery_window = expected_send_window / kDefaultTCPMSS;
267
268 // Recovery phase. We need to ack every packet in the recovery window before
269 // we exit recovery.
270 size_t number_of_packets_in_window = expected_send_window / kDefaultTCPMSS;
271 DVLOG(1) << "number_packets: " << number_of_packets_in_window;
272 AckNPackets(packets_in_recovery_window);
273 SendAvailableSendWindow();
274 EXPECT_EQ(expected_send_window, sender_->GetCongestionWindow());
275
276 // We need to ack an entire window before we increase CWND by 1.
277 AckNPackets(number_of_packets_in_window - 1);
278 SendAvailableSendWindow();
279 EXPECT_EQ(expected_send_window, sender_->GetCongestionWindow());
280
281 // Next ack should increase cwnd by 1.
282 AckNPackets(1);
283 expected_send_window += kDefaultTCPMSS;
284 EXPECT_EQ(expected_send_window, sender_->GetCongestionWindow());
285
286 // Now RTO and ensure slow start gets reset.
287 EXPECT_TRUE(sender_->hybrid_slow_start().started());
288 sender_->OnRetransmissionTimeout(true);
289 EXPECT_FALSE(sender_->hybrid_slow_start().started());
290 }
291
292 TEST_F(TcpCubicBytesSenderTest, NoPRRWhenLessThanOnePacketInFlight) {
293 SendAvailableSendWindow();
294 LoseNPackets(kInitialCongestionWindowPackets - 1);
295 AckNPackets(1);
296 // PRR will allow 2 packets for every ack during recovery.
297 EXPECT_EQ(2, SendAvailableSendWindow());
298 // Simulate abandoning all packets by supplying a bytes_in_flight of 0.
299 // PRR should now allow a packet to be sent, even though prr's state variables
300 // believe it has sent enough packets.
301 EXPECT_EQ(QuicTime::Delta::Zero(),
302 sender_->TimeUntilSend(clock_.Now(), 0, HAS_RETRANSMITTABLE_DATA));
303 }
304
305 TEST_F(TcpCubicBytesSenderTest, SlowStartPacketLossPRR) {
306 sender_->SetNumEmulatedConnections(1);
307 // Test based on the first example in RFC6937.
308 // Ack 10 packets in 5 acks to raise the CWND to 20, as in the example.
309 const int kNumberOfAcks = 5;
310 for (int i = 0; i < kNumberOfAcks; ++i) {
311 // Send our full send window.
312 SendAvailableSendWindow();
313 AckNPackets(2);
314 }
315 SendAvailableSendWindow();
316 QuicByteCount expected_send_window =
317 kDefaultWindowTCP + (kDefaultTCPMSS * 2 * kNumberOfAcks);
318 EXPECT_EQ(expected_send_window, sender_->GetCongestionWindow());
319
320 LoseNPackets(1);
321
322 // We should now have fallen out of slow start with a reduced window.
323 size_t send_window_before_loss = expected_send_window;
324 expected_send_window *= kRenoBeta;
325 EXPECT_EQ(expected_send_window, sender_->GetCongestionWindow());
326
327 // Testing TCP proportional rate reduction.
328 // We should send packets paced over the received acks for the remaining
329 // outstanding packets. The number of packets before we exit recovery is the
330 // original CWND minus the packet that has been lost and the one which
331 // triggered the loss.
332 size_t remaining_packets_in_recovery =
333 send_window_before_loss / kDefaultTCPMSS - 2;
334
335 for (size_t i = 0; i < remaining_packets_in_recovery; ++i) {
336 AckNPackets(1);
337 SendAvailableSendWindow();
338 EXPECT_EQ(expected_send_window, sender_->GetCongestionWindow());
339 }
340
341 // We need to ack another window before we increase CWND by 1.
342 size_t number_of_packets_in_window = expected_send_window / kDefaultTCPMSS;
343 for (size_t i = 0; i < number_of_packets_in_window; ++i) {
344 AckNPackets(1);
345 EXPECT_EQ(1, SendAvailableSendWindow());
346 EXPECT_EQ(expected_send_window, sender_->GetCongestionWindow());
347 }
348
349 AckNPackets(1);
350 expected_send_window += kDefaultTCPMSS;
351 EXPECT_EQ(expected_send_window, sender_->GetCongestionWindow());
352 }
353
354 TEST_F(TcpCubicBytesSenderTest, SlowStartBurstPacketLossPRR) {
355 sender_->SetNumEmulatedConnections(1);
356 // Test based on the second example in RFC6937, though we also implement
357 // forward acknowledgements, so the first two incoming acks will trigger
358 // PRR immediately.
359 // Ack 20 packets in 10 acks to raise the CWND to 30.
360 const int kNumberOfAcks = 10;
361 for (int i = 0; i < kNumberOfAcks; ++i) {
362 // Send our full send window.
363 SendAvailableSendWindow();
364 AckNPackets(2);
365 }
366 SendAvailableSendWindow();
367 QuicByteCount expected_send_window =
368 kDefaultWindowTCP + (kDefaultTCPMSS * 2 * kNumberOfAcks);
369 EXPECT_EQ(expected_send_window, sender_->GetCongestionWindow());
370
371 // Lose one more than the congestion window reduction, so that after loss,
372 // bytes_in_flight is lesser than the congestion window.
373 size_t send_window_after_loss = kRenoBeta * expected_send_window;
374 size_t num_packets_to_lose =
375 (expected_send_window - send_window_after_loss) / kDefaultTCPMSS + 1;
376 LoseNPackets(num_packets_to_lose);
377 // Immediately after the loss, ensure at least one packet can be sent.
378 // Losses without subsequent acks can occur with timer based loss detection.
379 EXPECT_TRUE(sender_->TimeUntilSend(clock_.Now(), bytes_in_flight_,
380 HAS_RETRANSMITTABLE_DATA)
381 .IsZero());
382 AckNPackets(1);
383
384 // We should now have fallen out of slow start with a reduced window.
385 expected_send_window *= kRenoBeta;
386 EXPECT_EQ(expected_send_window, sender_->GetCongestionWindow());
387
388 // Only 2 packets should be allowed to be sent, per PRR-SSRB.
389 EXPECT_EQ(2, SendAvailableSendWindow());
390
391 // Ack the next packet, which triggers another loss.
392 LoseNPackets(1);
393 AckNPackets(1);
394
395 // Send 2 packets to simulate PRR-SSRB.
396 EXPECT_EQ(2, SendAvailableSendWindow());
397
398 // Ack the next packet, which triggers another loss.
399 LoseNPackets(1);
400 AckNPackets(1);
401
402 // Send 2 packets to simulate PRR-SSRB.
403 EXPECT_EQ(2, SendAvailableSendWindow());
404
405 // Exit recovery and return to sending at the new rate.
406 for (int i = 0; i < kNumberOfAcks; ++i) {
407 AckNPackets(1);
408 EXPECT_EQ(1, SendAvailableSendWindow());
409 }
410 }
411
412 TEST_F(TcpCubicBytesSenderTest, RTOCongestionWindow) {
413 EXPECT_EQ(kDefaultWindowTCP, sender_->GetCongestionWindow());
414 // Expect the window to decrease to the minimum once the RTO fires and slow
415 // start threshold to be set to 1/2 of the CWND.
416 sender_->OnRetransmissionTimeout(true);
417 EXPECT_EQ(2 * kDefaultTCPMSS, sender_->GetCongestionWindow());
418 EXPECT_EQ(5u * kDefaultTCPMSS, sender_->GetSlowStartThreshold());
419 }
420
421 TEST_F(TcpCubicBytesSenderTest, RTOCongestionWindowNoRetransmission) {
422 EXPECT_EQ(kDefaultWindowTCP, sender_->GetCongestionWindow());
423
424 // Expect the window to remain unchanged if the RTO fires but no packets are
425 // retransmitted.
426 sender_->OnRetransmissionTimeout(false);
427 EXPECT_EQ(kDefaultWindowTCP, sender_->GetCongestionWindow());
428 }
429
430 TEST_F(TcpCubicBytesSenderTest, RetransmissionDelay) {
431 const int64_t kRttMs = 10;
432 const int64_t kDeviationMs = 3;
433 EXPECT_EQ(QuicTime::Delta::Zero(), sender_->RetransmissionDelay());
434
435 sender_->rtt_stats_.UpdateRtt(QuicTime::Delta::FromMilliseconds(kRttMs),
436 QuicTime::Delta::Zero(), clock_.Now());
437
438 // Initial value is to set the median deviation to half of the initial rtt,
439 // the median in then multiplied by a factor of 4 and finally the smoothed rtt
440 // is added which is the initial rtt.
441 QuicTime::Delta expected_delay =
442 QuicTime::Delta::FromMilliseconds(kRttMs + kRttMs / 2 * 4);
443 EXPECT_EQ(expected_delay, sender_->RetransmissionDelay());
444
445 for (int i = 0; i < 100; ++i) {
446 // Run to make sure that we converge.
447 sender_->rtt_stats_.UpdateRtt(
448 QuicTime::Delta::FromMilliseconds(kRttMs + kDeviationMs),
449 QuicTime::Delta::Zero(), clock_.Now());
450 sender_->rtt_stats_.UpdateRtt(
451 QuicTime::Delta::FromMilliseconds(kRttMs - kDeviationMs),
452 QuicTime::Delta::Zero(), clock_.Now());
453 }
454 expected_delay = QuicTime::Delta::FromMilliseconds(kRttMs + kDeviationMs * 4);
455
456 EXPECT_NEAR(kRttMs, sender_->rtt_stats_.smoothed_rtt().ToMilliseconds(), 1);
457 EXPECT_NEAR(expected_delay.ToMilliseconds(),
458 sender_->RetransmissionDelay().ToMilliseconds(), 1);
459 EXPECT_EQ(static_cast<int64_t>(
460 sender_->GetCongestionWindow() * kNumMicrosPerSecond /
461 sender_->rtt_stats_.smoothed_rtt().ToMicroseconds()),
462 sender_->BandwidthEstimate().ToBytesPerSecond());
463 }
464
465 TEST_F(TcpCubicBytesSenderTest, TcpCubicResetEpochOnQuiescence) {
466 const int kMaxCongestionWindow = 50;
467 const QuicByteCount kMaxCongestionWindowBytes =
468 kMaxCongestionWindow * kDefaultTCPMSS;
469 int num_sent = SendAvailableSendWindow();
470
471 // Make sure we fall out of slow start.
472 QuicByteCount saved_cwnd = sender_->GetCongestionWindow();
473 LoseNPackets(1);
474 EXPECT_GT(saved_cwnd, sender_->GetCongestionWindow());
475
476 // Ack the rest of the outstanding packets to get out of recovery.
477 for (int i = 1; i < num_sent; ++i) {
478 AckNPackets(1);
479 }
480 EXPECT_EQ(0u, bytes_in_flight_);
481
482 // Send a new window of data and ack all; cubic growth should occur.
483 saved_cwnd = sender_->GetCongestionWindow();
484 num_sent = SendAvailableSendWindow();
485 for (int i = 0; i < num_sent; ++i) {
486 AckNPackets(1);
487 }
488 EXPECT_LT(saved_cwnd, sender_->GetCongestionWindow());
489 EXPECT_GT(kMaxCongestionWindowBytes, sender_->GetCongestionWindow());
490 EXPECT_EQ(0u, bytes_in_flight_);
491
492 // Quiescent time of 100 seconds
493 clock_.AdvanceTime(QuicTime::Delta::FromMilliseconds(100000));
494
495 // Send new window of data and ack one packet. Cubic epoch should have
496 // been reset; ensure cwnd increase is not dramatic.
497 saved_cwnd = sender_->GetCongestionWindow();
498 SendAvailableSendWindow();
499 AckNPackets(1);
500 EXPECT_NEAR(saved_cwnd, sender_->GetCongestionWindow(), kDefaultTCPMSS);
501 EXPECT_GT(kMaxCongestionWindowBytes, sender_->GetCongestionWindow());
502 }
503
504 TEST_F(TcpCubicBytesSenderTest, MultipleLossesInOneWindow) {
505 SendAvailableSendWindow();
506 const QuicByteCount initial_window = sender_->GetCongestionWindow();
507 LosePacket(acked_packet_number_ + 1);
508 const QuicByteCount post_loss_window = sender_->GetCongestionWindow();
509 EXPECT_GT(initial_window, post_loss_window);
510 LosePacket(acked_packet_number_ + 3);
511 EXPECT_EQ(post_loss_window, sender_->GetCongestionWindow());
512 LosePacket(packet_number_ - 1);
513 EXPECT_EQ(post_loss_window, sender_->GetCongestionWindow());
514
515 // Lose a later packet and ensure the window decreases.
516 LosePacket(packet_number_);
517 EXPECT_GT(post_loss_window, sender_->GetCongestionWindow());
518 }
519
520 TEST_F(TcpCubicBytesSenderTest, DontTrackAckPackets) {
521 // Send a packet with no retransmittable data, and ensure it's not tracked.
522 EXPECT_FALSE(sender_->OnPacketSent(clock_.Now(), bytes_in_flight_,
523 packet_number_++, kDefaultTCPMSS,
524 NO_RETRANSMITTABLE_DATA));
525
526 // Send a data packet with retransmittable data, and ensure it is tracked.
527 EXPECT_TRUE(sender_->OnPacketSent(clock_.Now(), bytes_in_flight_,
528 packet_number_++, kDefaultTCPMSS,
529 HAS_RETRANSMITTABLE_DATA));
530 }
531
532 TEST_F(TcpCubicBytesSenderTest, ConfigureMaxInitialWindow) {
533 QuicConfig config;
534
535 // Verify that kCOPT: kIW10 forces the congestion window to the default of 10.
536 QuicTagVector options;
537 options.push_back(kIW10);
538 QuicConfigPeer::SetReceivedConnectionOptions(&config, options);
539 sender_->SetFromConfig(config, Perspective::IS_SERVER);
540 EXPECT_EQ(10u * kDefaultTCPMSS, sender_->GetCongestionWindow());
541 }
542
543 TEST_F(TcpCubicBytesSenderTest, 2ConnectionCongestionAvoidanceAtEndOfRecovery) {
544 sender_->SetNumEmulatedConnections(2);
545 // Ack 10 packets in 5 acks to raise the CWND to 20.
546 const int kNumberOfAcks = 5;
547 for (int i = 0; i < kNumberOfAcks; ++i) {
548 // Send our full send window.
549 SendAvailableSendWindow();
550 AckNPackets(2);
551 }
552 SendAvailableSendWindow();
553 QuicByteCount expected_send_window =
554 kDefaultWindowTCP + (kDefaultTCPMSS * 2 * kNumberOfAcks);
555 EXPECT_EQ(expected_send_window, sender_->GetCongestionWindow());
556
557 LoseNPackets(1);
558
559 // We should now have fallen out of slow start with a reduced window.
560 expected_send_window = expected_send_window * sender_->GetRenoBeta();
561 EXPECT_EQ(expected_send_window, sender_->GetCongestionWindow());
562
563 // No congestion window growth should occur in recovery phase, i.e., until the
564 // currently outstanding 20 packets are acked.
565 for (int i = 0; i < 10; ++i) {
566 // Send our full send window.
567 SendAvailableSendWindow();
568 EXPECT_TRUE(sender_->InRecovery());
569 AckNPackets(2);
570 EXPECT_EQ(expected_send_window, sender_->GetCongestionWindow());
571 }
572 EXPECT_FALSE(sender_->InRecovery());
573
574 // Out of recovery now. Congestion window should not grow for half an RTT.
575 size_t packets_in_send_window = expected_send_window / kDefaultTCPMSS;
576 SendAvailableSendWindow();
577 AckNPackets(packets_in_send_window / 2 - 2);
578 EXPECT_EQ(expected_send_window, sender_->GetCongestionWindow());
579
580 // Next ack should increase congestion window by 1MSS.
581 SendAvailableSendWindow();
582 AckNPackets(2);
583 expected_send_window += kDefaultTCPMSS;
584 packets_in_send_window += 1;
585 EXPECT_EQ(expected_send_window, sender_->GetCongestionWindow());
586
587 // Congestion window should remain steady again for half an RTT.
588 SendAvailableSendWindow();
589 AckNPackets(packets_in_send_window / 2 - 1);
590 EXPECT_EQ(expected_send_window, sender_->GetCongestionWindow());
591
592 // Next ack should cause congestion window to grow by 1MSS.
593 SendAvailableSendWindow();
594 AckNPackets(2);
595 expected_send_window += kDefaultTCPMSS;
596 EXPECT_EQ(expected_send_window, sender_->GetCongestionWindow());
597 }
598
599 TEST_F(TcpCubicBytesSenderTest, 1ConnectionCongestionAvoidanceAtEndOfRecovery) {
600 sender_->SetNumEmulatedConnections(1);
601 // Ack 10 packets in 5 acks to raise the CWND to 20.
602 const int kNumberOfAcks = 5;
603 for (int i = 0; i < kNumberOfAcks; ++i) {
604 // Send our full send window.
605 SendAvailableSendWindow();
606 AckNPackets(2);
607 }
608 SendAvailableSendWindow();
609 QuicByteCount expected_send_window =
610 kDefaultWindowTCP + (kDefaultTCPMSS * 2 * kNumberOfAcks);
611 EXPECT_EQ(expected_send_window, sender_->GetCongestionWindow());
612
613 LoseNPackets(1);
614
615 // We should now have fallen out of slow start with a reduced window.
616 expected_send_window *= kRenoBeta;
617 EXPECT_EQ(expected_send_window, sender_->GetCongestionWindow());
618
619 // No congestion window growth should occur in recovery phase, i.e., until the
620 // currently outstanding 20 packets are acked.
621 for (int i = 0; i < 10; ++i) {
622 // Send our full send window.
623 SendAvailableSendWindow();
624 EXPECT_TRUE(sender_->InRecovery());
625 AckNPackets(2);
626 EXPECT_EQ(expected_send_window, sender_->GetCongestionWindow());
627 }
628 EXPECT_FALSE(sender_->InRecovery());
629
630 // Out of recovery now. Congestion window should not grow during RTT.
631 for (uint64_t i = 0; i < expected_send_window / kDefaultTCPMSS - 2; i += 2) {
632 // Send our full send window.
633 SendAvailableSendWindow();
634 AckNPackets(2);
635 EXPECT_EQ(expected_send_window, sender_->GetCongestionWindow());
636 }
637
638 // Next ack should cause congestion window to grow by 1MSS.
639 SendAvailableSendWindow();
640 AckNPackets(2);
641 expected_send_window += kDefaultTCPMSS;
642 EXPECT_EQ(expected_send_window, sender_->GetCongestionWindow());
643 }
644
645 TEST_F(TcpCubicBytesSenderTest, BandwidthResumption) {
646 // Test that when provided with CachedNetworkParameters and opted in to the
647 // bandwidth resumption experiment, that the TcpCubicSender sets initial CWND
648 // appropriately.
649
650 // Set some common values.
651 CachedNetworkParameters cached_network_params;
652 const QuicPacketCount kNumberOfPackets = 123;
653 const int kBandwidthEstimateBytesPerSecond =
654 kNumberOfPackets * kDefaultTCPMSS;
655 cached_network_params.set_bandwidth_estimate_bytes_per_second(
656 kBandwidthEstimateBytesPerSecond);
657 cached_network_params.set_min_rtt_ms(1000);
658
659 // Make sure that a bandwidth estimate results in a changed CWND.
660 cached_network_params.set_timestamp(clock_.WallNow().ToUNIXSeconds() -
661 (kNumSecondsPerHour - 1));
662 sender_->ResumeConnectionState(cached_network_params, false);
663 EXPECT_EQ(kNumberOfPackets * kDefaultTCPMSS, sender_->GetCongestionWindow());
664
665 // Resumed CWND is limited to be in a sensible range.
666 cached_network_params.set_bandwidth_estimate_bytes_per_second(
667 (kMaxCongestionWindow + 1) * kDefaultTCPMSS);
668 sender_->ResumeConnectionState(cached_network_params, false);
669 EXPECT_EQ(kMaxCongestionWindow * kDefaultTCPMSS,
670 sender_->GetCongestionWindow());
671
672 cached_network_params.set_bandwidth_estimate_bytes_per_second(
673 (kMinCongestionWindowForBandwidthResumption - 1) * kDefaultTCPMSS);
674 sender_->ResumeConnectionState(cached_network_params, false);
675 EXPECT_EQ(kMinCongestionWindowForBandwidthResumption * kDefaultTCPMSS,
676 sender_->GetCongestionWindow());
677
678 // Resume to the max value.
679 cached_network_params.set_max_bandwidth_estimate_bytes_per_second(
680 (kMinCongestionWindowForBandwidthResumption + 10) * kDefaultTCPMSS);
681 sender_->ResumeConnectionState(cached_network_params, true);
682 EXPECT_EQ((kMinCongestionWindowForBandwidthResumption + 10) * kDefaultTCPMSS,
683 sender_->GetCongestionWindow());
684 }
685
686 TEST_F(TcpCubicBytesSenderTest, PaceBelowCWND) {
687 QuicConfig config;
688
689 // Verify that kCOPT: kMIN4 forces the min CWND to 1 packet, but allows up
690 // to 4 to be sent.
691 QuicTagVector options;
692 options.push_back(kMIN4);
693 QuicConfigPeer::SetReceivedConnectionOptions(&config, options);
694 sender_->SetFromConfig(config, Perspective::IS_SERVER);
695 sender_->OnRetransmissionTimeout(true);
696 EXPECT_EQ(kDefaultTCPMSS, sender_->GetCongestionWindow());
697 EXPECT_TRUE(sender_->TimeUntilSend(QuicTime::Zero(), kDefaultTCPMSS,
698 HAS_RETRANSMITTABLE_DATA)
699 .IsZero());
700 EXPECT_TRUE(sender_->TimeUntilSend(QuicTime::Zero(), 2 * kDefaultTCPMSS,
701 HAS_RETRANSMITTABLE_DATA)
702 .IsZero());
703 EXPECT_TRUE(sender_->TimeUntilSend(QuicTime::Zero(), 3 * kDefaultTCPMSS,
704 HAS_RETRANSMITTABLE_DATA)
705 .IsZero());
706 EXPECT_FALSE(sender_->TimeUntilSend(QuicTime::Zero(), 4 * kDefaultTCPMSS,
707 HAS_RETRANSMITTABLE_DATA)
708 .IsZero());
709 }
710
711 TEST_F(TcpCubicBytesSenderTest, ResetAfterConnectionMigration) {
712 // Starts from slow start.
713 sender_->SetNumEmulatedConnections(1);
714 const int kNumberOfAcks = 10;
715 for (int i = 0; i < kNumberOfAcks; ++i) {
716 // Send our full send window.
717 SendAvailableSendWindow();
718 AckNPackets(2);
719 }
720 SendAvailableSendWindow();
721 QuicByteCount expected_send_window =
722 kDefaultWindowTCP + (kDefaultTCPMSS * 2 * kNumberOfAcks);
723 EXPECT_EQ(expected_send_window, sender_->GetCongestionWindow());
724
725 // Loses a packet to exit slow start.
726 LoseNPackets(1);
727
728 // We should now have fallen out of slow start with a reduced window. Slow
729 // start threshold is also updated.
730 expected_send_window *= kRenoBeta;
731 EXPECT_EQ(expected_send_window, sender_->GetCongestionWindow());
732 EXPECT_EQ(expected_send_window, sender_->GetSlowStartThreshold());
733
734 // Resets cwnd and slow start threshold on connection migrations.
735 sender_->OnConnectionMigration();
736 EXPECT_EQ(kDefaultWindowTCP, sender_->GetCongestionWindow());
737 EXPECT_EQ(kMaxCongestionWindow * kDefaultTCPMSS,
738 sender_->GetSlowStartThreshold());
739 EXPECT_FALSE(sender_->hybrid_slow_start().started());
740 }
741
742 } // namespace test
743 } // namespace net
OLDNEW
« no previous file with comments | « net/quic/congestion_control/tcp_cubic_bytes_sender.cc ('k') | net/quic/congestion_control/tcp_cubic_sender.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698