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.
5 #include "net/quic/congestion_control/tcp_cubic_bytes_sender.h"
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/quic_protocol.h"
14 #include "net/quic/quic_utils.h"
15 #include "net/quic/test_tools/mock_clock.h"
16 #include "net/quic/test_tools/quic_config_peer.h"
17 #include "testing/gtest/include/gtest/gtest.h"
22 // TODO(ianswett): A number of theses tests were written with the assumption of
23 // an initial CWND of 10. They have carefully calculated values which should be
24 // updated to be based on kInitialCongestionWindowInsecure.
25 const uint32 kInitialCongestionWindowPackets
= 10;
26 const uint32 kDefaultWindowTCP
=
27 kInitialCongestionWindowPackets
* kDefaultTCPMSS
;
28 const float kRenoBeta
= 0.7f
; // Reno backoff factor.
30 class TcpCubicBytesSenderPeer
: public TcpCubicBytesSender
{
32 TcpCubicBytesSenderPeer(const QuicClock
* clock
, bool reno
)
33 : TcpCubicBytesSender(clock
,
36 kInitialCongestionWindowPackets
,
37 kMaxTcpCongestionWindow
,
40 const HybridSlowStart
& hybrid_slow_start() const {
41 return hybrid_slow_start_
;
44 float GetRenoBeta() const { return RenoBeta(); }
47 QuicConnectionStats stats_
;
50 class TcpCubicBytesSenderTest
: public ::testing::Test
{
52 TcpCubicBytesSenderTest()
53 : one_ms_(QuicTime::Delta::FromMilliseconds(1)),
54 sender_(new TcpCubicBytesSenderPeer(&clock_
, true)),
56 acked_sequence_number_(0),
58 standard_packet_
.bytes_sent
= kDefaultTCPMSS
;
61 int SendAvailableSendWindow() {
62 // Send as long as TimeUntilSend returns Zero.
64 bool can_send
= sender_
->TimeUntilSend(clock_
.Now(), bytes_in_flight_
,
65 HAS_RETRANSMITTABLE_DATA
).IsZero();
67 sender_
->OnPacketSent(clock_
.Now(), bytes_in_flight_
, sequence_number_
++,
68 kDefaultTCPMSS
, HAS_RETRANSMITTABLE_DATA
);
70 bytes_in_flight_
+= kDefaultTCPMSS
;
71 can_send
= sender_
->TimeUntilSend(clock_
.Now(), bytes_in_flight_
,
72 HAS_RETRANSMITTABLE_DATA
).IsZero();
77 // Normal is that TCP acks every other segment.
78 void AckNPackets(int n
) {
79 sender_
->rtt_stats_
.UpdateRtt(QuicTime::Delta::FromMilliseconds(60),
80 QuicTime::Delta::Zero(), clock_
.Now());
81 SendAlgorithmInterface::CongestionVector acked_packets
;
82 SendAlgorithmInterface::CongestionVector lost_packets
;
83 for (int i
= 0; i
< n
; ++i
) {
84 ++acked_sequence_number_
;
85 acked_packets
.push_back(
86 std::make_pair(acked_sequence_number_
, standard_packet_
));
88 sender_
->OnCongestionEvent(true, bytes_in_flight_
, acked_packets
,
90 bytes_in_flight_
-= n
* kDefaultTCPMSS
;
91 clock_
.AdvanceTime(one_ms_
);
94 void LoseNPackets(int n
) {
95 SendAlgorithmInterface::CongestionVector acked_packets
;
96 SendAlgorithmInterface::CongestionVector lost_packets
;
97 for (int i
= 0; i
< n
; ++i
) {
98 ++acked_sequence_number_
;
99 lost_packets
.push_back(
100 std::make_pair(acked_sequence_number_
, standard_packet_
));
102 sender_
->OnCongestionEvent(false, bytes_in_flight_
, acked_packets
,
104 bytes_in_flight_
-= n
* kDefaultTCPMSS
;
107 // Does not increment acked_sequence_number_.
108 void LosePacket(QuicPacketSequenceNumber sequence_number
) {
109 SendAlgorithmInterface::CongestionVector acked_packets
;
110 SendAlgorithmInterface::CongestionVector lost_packets
;
111 lost_packets
.push_back(std::make_pair(sequence_number
, standard_packet_
));
112 sender_
->OnCongestionEvent(false, bytes_in_flight_
, acked_packets
,
114 bytes_in_flight_
-= kDefaultTCPMSS
;
117 const QuicTime::Delta one_ms_
;
119 scoped_ptr
<TcpCubicBytesSenderPeer
> sender_
;
120 QuicPacketSequenceNumber sequence_number_
;
121 QuicPacketSequenceNumber acked_sequence_number_
;
122 QuicByteCount bytes_in_flight_
;
123 TransmissionInfo standard_packet_
;
126 TEST_F(TcpCubicBytesSenderTest
, SimpleSender
) {
127 // At startup make sure we are at the default.
128 EXPECT_EQ(kDefaultWindowTCP
, sender_
->GetCongestionWindow());
129 // At startup make sure we can send.
130 EXPECT_TRUE(sender_
->TimeUntilSend(clock_
.Now(), 0,
131 HAS_RETRANSMITTABLE_DATA
).IsZero());
132 // Make sure we can send.
133 EXPECT_TRUE(sender_
->TimeUntilSend(clock_
.Now(), 0,
134 HAS_RETRANSMITTABLE_DATA
).IsZero());
135 // And that window is un-affected.
136 EXPECT_EQ(kDefaultWindowTCP
, sender_
->GetCongestionWindow());
138 // Fill the send window with data, then verify that we can't send.
139 SendAvailableSendWindow();
140 EXPECT_FALSE(sender_
->TimeUntilSend(clock_
.Now(),
141 sender_
->GetCongestionWindow(),
142 HAS_RETRANSMITTABLE_DATA
).IsZero());
145 TEST_F(TcpCubicBytesSenderTest
, ApplicationLimitedSlowStart
) {
146 // Send exactly 10 packets and ensure the CWND ends at 14 packets.
147 const int kNumberOfAcks
= 5;
148 // At startup make sure we can send.
149 EXPECT_TRUE(sender_
->TimeUntilSend(clock_
.Now(), 0,
150 HAS_RETRANSMITTABLE_DATA
).IsZero());
151 // Make sure we can send.
152 EXPECT_TRUE(sender_
->TimeUntilSend(clock_
.Now(), 0,
153 HAS_RETRANSMITTABLE_DATA
).IsZero());
155 SendAvailableSendWindow();
156 for (int i
= 0; i
< kNumberOfAcks
; ++i
) {
159 QuicByteCount bytes_to_send
= sender_
->GetCongestionWindow();
160 // It's expected 2 acks will arrive when the bytes_in_flight are greater than
162 EXPECT_EQ(kDefaultWindowTCP
+ kDefaultTCPMSS
* 2 * 2, bytes_to_send
);
165 TEST_F(TcpCubicBytesSenderTest
, ExponentialSlowStart
) {
166 const int kNumberOfAcks
= 20;
167 // At startup make sure we can send.
168 EXPECT_TRUE(sender_
->TimeUntilSend(clock_
.Now(), 0,
169 HAS_RETRANSMITTABLE_DATA
).IsZero());
170 EXPECT_FALSE(sender_
->HasReliableBandwidthEstimate());
171 EXPECT_EQ(QuicBandwidth::Zero(), sender_
->BandwidthEstimate());
172 // Make sure we can send.
173 EXPECT_TRUE(sender_
->TimeUntilSend(clock_
.Now(), 0,
174 HAS_RETRANSMITTABLE_DATA
).IsZero());
176 for (int i
= 0; i
< kNumberOfAcks
; ++i
) {
177 // Send our full send window.
178 SendAvailableSendWindow();
181 const QuicByteCount cwnd
= sender_
->GetCongestionWindow();
182 EXPECT_EQ(kDefaultWindowTCP
+ kDefaultTCPMSS
* 2 * kNumberOfAcks
, cwnd
);
183 EXPECT_FALSE(sender_
->HasReliableBandwidthEstimate());
184 EXPECT_EQ(QuicBandwidth::FromBytesAndTimeDelta(
185 cwnd
, sender_
->rtt_stats_
.smoothed_rtt()),
186 sender_
->BandwidthEstimate());
189 TEST_F(TcpCubicBytesSenderTest
, SlowStartPacketLoss
) {
190 sender_
->SetNumEmulatedConnections(1);
191 const int kNumberOfAcks
= 10;
192 for (int i
= 0; i
< kNumberOfAcks
; ++i
) {
193 // Send our full send window.
194 SendAvailableSendWindow();
197 SendAvailableSendWindow();
198 QuicByteCount expected_send_window
=
199 kDefaultWindowTCP
+ (kDefaultTCPMSS
* 2 * kNumberOfAcks
);
200 EXPECT_EQ(expected_send_window
, sender_
->GetCongestionWindow());
202 // Lose a packet to exit slow start.
204 size_t packets_in_recovery_window
= expected_send_window
/ kDefaultTCPMSS
;
206 // We should now have fallen out of slow start with a reduced window.
207 expected_send_window
*= kRenoBeta
;
208 EXPECT_EQ(expected_send_window
, sender_
->GetCongestionWindow());
210 // Recovery phase. We need to ack every packet in the recovery window before
212 size_t number_of_packets_in_window
= expected_send_window
/ kDefaultTCPMSS
;
213 DVLOG(1) << "number_packets: " << number_of_packets_in_window
;
214 AckNPackets(packets_in_recovery_window
);
215 SendAvailableSendWindow();
216 EXPECT_EQ(expected_send_window
, sender_
->GetCongestionWindow());
218 // We need to ack an entire window before we increase CWND by 1.
219 AckNPackets(number_of_packets_in_window
- 2);
220 SendAvailableSendWindow();
221 EXPECT_EQ(expected_send_window
, sender_
->GetCongestionWindow());
223 // Next ack should increase cwnd by 1.
225 expected_send_window
+= kDefaultTCPMSS
;
226 EXPECT_EQ(expected_send_window
, sender_
->GetCongestionWindow());
228 // Now RTO and ensure slow start gets reset.
229 EXPECT_TRUE(sender_
->hybrid_slow_start().started());
230 sender_
->OnRetransmissionTimeout(true);
231 EXPECT_FALSE(sender_
->hybrid_slow_start().started());
234 TEST_F(TcpCubicBytesSenderTest
, NoPRRWhenLessThanOnePacketInFlight
) {
235 SendAvailableSendWindow();
236 LoseNPackets(kInitialCongestionWindowPackets
- 1);
238 // PRR will allow 2 packets for every ack during recovery.
239 EXPECT_EQ(2, SendAvailableSendWindow());
240 // Simulate abandoning all packets by supplying a bytes_in_flight of 0.
241 // PRR should now allow a packet to be sent, even though prr's state variables
242 // believe it has sent enough packets.
243 EXPECT_EQ(QuicTime::Delta::Zero(),
244 sender_
->TimeUntilSend(clock_
.Now(), 0, HAS_RETRANSMITTABLE_DATA
));
247 TEST_F(TcpCubicBytesSenderTest
, SlowStartPacketLossPRR
) {
248 sender_
->SetNumEmulatedConnections(1);
249 // Test based on the first example in RFC6937.
250 // Ack 10 packets in 5 acks to raise the CWND to 20, as in the example.
251 const int kNumberOfAcks
= 5;
252 for (int i
= 0; i
< kNumberOfAcks
; ++i
) {
253 // Send our full send window.
254 SendAvailableSendWindow();
257 SendAvailableSendWindow();
258 QuicByteCount expected_send_window
=
259 kDefaultWindowTCP
+ (kDefaultTCPMSS
* 2 * kNumberOfAcks
);
260 EXPECT_EQ(expected_send_window
, sender_
->GetCongestionWindow());
264 // We should now have fallen out of slow start with a reduced window.
265 size_t send_window_before_loss
= expected_send_window
;
266 expected_send_window
*= kRenoBeta
;
267 EXPECT_EQ(expected_send_window
, sender_
->GetCongestionWindow());
269 // Testing TCP proportional rate reduction.
270 // We should send packets paced over the received acks for the remaining
271 // outstanding packets. The number of packets before we exit recovery is the
272 // original CWND minus the packet that has been lost and the one which
273 // triggered the loss.
274 size_t remaining_packets_in_recovery
=
275 send_window_before_loss
/ kDefaultTCPMSS
- 2;
277 for (size_t i
= 0; i
< remaining_packets_in_recovery
; ++i
) {
279 SendAvailableSendWindow();
280 EXPECT_EQ(expected_send_window
, sender_
->GetCongestionWindow());
283 // We need to ack another window before we increase CWND by 1.
284 size_t number_of_packets_in_window
= expected_send_window
/ kDefaultTCPMSS
;
285 for (size_t i
= 0; i
< number_of_packets_in_window
; ++i
) {
287 EXPECT_EQ(1, SendAvailableSendWindow());
288 EXPECT_EQ(expected_send_window
, sender_
->GetCongestionWindow());
292 expected_send_window
+= kDefaultTCPMSS
;
293 EXPECT_EQ(expected_send_window
, sender_
->GetCongestionWindow());
296 TEST_F(TcpCubicBytesSenderTest
, SlowStartBurstPacketLossPRR
) {
297 sender_
->SetNumEmulatedConnections(1);
298 // Test based on the second example in RFC6937, though we also implement
299 // forward acknowledgements, so the first two incoming acks will trigger
301 // Ack 20 packets in 10 acks to raise the CWND to 30.
302 const int kNumberOfAcks
= 10;
303 for (int i
= 0; i
< kNumberOfAcks
; ++i
) {
304 // Send our full send window.
305 SendAvailableSendWindow();
308 SendAvailableSendWindow();
309 QuicByteCount expected_send_window
=
310 kDefaultWindowTCP
+ (kDefaultTCPMSS
* 2 * kNumberOfAcks
);
311 EXPECT_EQ(expected_send_window
, sender_
->GetCongestionWindow());
313 // Lose one more than the congestion window reduction, so that after loss,
314 // bytes_in_flight is lesser than the congestion window.
315 size_t send_window_after_loss
= kRenoBeta
* expected_send_window
;
316 size_t num_packets_to_lose
=
317 (expected_send_window
- send_window_after_loss
) / kDefaultTCPMSS
+ 1;
318 LoseNPackets(num_packets_to_lose
);
319 // Immediately after the loss, ensure at least one packet can be sent.
320 // Losses without subsequent acks can occur with timer based loss detection.
321 EXPECT_TRUE(sender_
->TimeUntilSend(clock_
.Now(), bytes_in_flight_
,
322 HAS_RETRANSMITTABLE_DATA
).IsZero());
325 // We should now have fallen out of slow start with a reduced window.
326 expected_send_window
*= kRenoBeta
;
327 EXPECT_EQ(expected_send_window
, sender_
->GetCongestionWindow());
329 // Only 2 packets should be allowed to be sent, per PRR-SSRB.
330 EXPECT_EQ(2, SendAvailableSendWindow());
332 // Ack the next packet, which triggers another loss.
336 // Send 2 packets to simulate PRR-SSRB.
337 EXPECT_EQ(2, SendAvailableSendWindow());
339 // Ack the next packet, which triggers another loss.
343 // Send 2 packets to simulate PRR-SSRB.
344 EXPECT_EQ(2, SendAvailableSendWindow());
346 // Exit recovery and return to sending at the new rate.
347 for (int i
= 0; i
< kNumberOfAcks
; ++i
) {
349 EXPECT_EQ(1, SendAvailableSendWindow());
353 TEST_F(TcpCubicBytesSenderTest
, RTOCongestionWindow
) {
354 EXPECT_EQ(kDefaultWindowTCP
, sender_
->GetCongestionWindow());
355 // Expect the window to decrease to the minimum once the RTO fires and slow
356 // start threshold to be set to 1/2 of the CWND.
357 sender_
->OnRetransmissionTimeout(true);
358 EXPECT_EQ(2 * kDefaultTCPMSS
, sender_
->GetCongestionWindow());
359 EXPECT_EQ(5u * kDefaultTCPMSS
, sender_
->GetSlowStartThreshold());
362 TEST_F(TcpCubicBytesSenderTest
, RTOCongestionWindowNoRetransmission
) {
363 EXPECT_EQ(kDefaultWindowTCP
, sender_
->GetCongestionWindow());
365 // Expect the window to remain unchanged if the RTO fires but no packets are
367 sender_
->OnRetransmissionTimeout(false);
368 EXPECT_EQ(kDefaultWindowTCP
, sender_
->GetCongestionWindow());
371 TEST_F(TcpCubicBytesSenderTest
, RetransmissionDelay
) {
372 const int64 kRttMs
= 10;
373 const int64 kDeviationMs
= 3;
374 EXPECT_EQ(QuicTime::Delta::Zero(), sender_
->RetransmissionDelay());
376 sender_
->rtt_stats_
.UpdateRtt(QuicTime::Delta::FromMilliseconds(kRttMs
),
377 QuicTime::Delta::Zero(), clock_
.Now());
379 // Initial value is to set the median deviation to half of the initial rtt,
380 // the median in then multiplied by a factor of 4 and finally the smoothed rtt
381 // is added which is the initial rtt.
382 QuicTime::Delta expected_delay
=
383 QuicTime::Delta::FromMilliseconds(kRttMs
+ kRttMs
/ 2 * 4);
384 EXPECT_EQ(expected_delay
, sender_
->RetransmissionDelay());
386 for (int i
= 0; i
< 100; ++i
) {
387 // Run to make sure that we converge.
388 sender_
->rtt_stats_
.UpdateRtt(
389 QuicTime::Delta::FromMilliseconds(kRttMs
+ kDeviationMs
),
390 QuicTime::Delta::Zero(), clock_
.Now());
391 sender_
->rtt_stats_
.UpdateRtt(
392 QuicTime::Delta::FromMilliseconds(kRttMs
- kDeviationMs
),
393 QuicTime::Delta::Zero(), clock_
.Now());
395 expected_delay
= QuicTime::Delta::FromMilliseconds(kRttMs
+ kDeviationMs
* 4);
397 EXPECT_NEAR(kRttMs
, sender_
->rtt_stats_
.smoothed_rtt().ToMilliseconds(), 1);
398 EXPECT_NEAR(expected_delay
.ToMilliseconds(),
399 sender_
->RetransmissionDelay().ToMilliseconds(), 1);
401 static_cast<int64
>(sender_
->GetCongestionWindow() * kNumMicrosPerSecond
/
402 sender_
->rtt_stats_
.smoothed_rtt().ToMicroseconds()),
403 sender_
->BandwidthEstimate().ToBytesPerSecond());
406 TEST_F(TcpCubicBytesSenderTest
, MultipleLossesInOneWindow
) {
407 SendAvailableSendWindow();
408 const QuicByteCount initial_window
= sender_
->GetCongestionWindow();
409 LosePacket(acked_sequence_number_
+ 1);
410 const QuicByteCount post_loss_window
= sender_
->GetCongestionWindow();
411 EXPECT_GT(initial_window
, post_loss_window
);
412 LosePacket(acked_sequence_number_
+ 3);
413 EXPECT_EQ(post_loss_window
, sender_
->GetCongestionWindow());
414 LosePacket(sequence_number_
- 1);
415 EXPECT_EQ(post_loss_window
, sender_
->GetCongestionWindow());
417 // Lose a later packet and ensure the window decreases.
418 LosePacket(sequence_number_
);
419 EXPECT_GT(post_loss_window
, sender_
->GetCongestionWindow());
422 TEST_F(TcpCubicBytesSenderTest
, DontTrackAckPackets
) {
423 // Send a packet with no retransmittable data, and ensure it's not tracked.
424 EXPECT_FALSE(sender_
->OnPacketSent(clock_
.Now(), bytes_in_flight_
,
425 sequence_number_
++, kDefaultTCPMSS
,
426 NO_RETRANSMITTABLE_DATA
));
428 // Send a data packet with retransmittable data, and ensure it is tracked.
429 EXPECT_TRUE(sender_
->OnPacketSent(clock_
.Now(), bytes_in_flight_
,
430 sequence_number_
++, kDefaultTCPMSS
,
431 HAS_RETRANSMITTABLE_DATA
));
434 TEST_F(TcpCubicBytesSenderTest
, ConfigureMaxInitialWindow
) {
437 // Verify that kCOPT: kIW10 forces the congestion window to the default of 10.
438 QuicTagVector options
;
439 options
.push_back(kIW10
);
440 QuicConfigPeer::SetReceivedConnectionOptions(&config
, options
);
441 sender_
->SetFromConfig(config
, Perspective::IS_SERVER
);
442 EXPECT_EQ(10u * kDefaultTCPMSS
, sender_
->GetCongestionWindow());
445 TEST_F(TcpCubicBytesSenderTest
, 2ConnectionCongestionAvoidanceAtEndOfRecovery
) {
446 sender_
->SetNumEmulatedConnections(2);
447 // Ack 10 packets in 5 acks to raise the CWND to 20.
448 const int kNumberOfAcks
= 5;
449 for (int i
= 0; i
< kNumberOfAcks
; ++i
) {
450 // Send our full send window.
451 SendAvailableSendWindow();
454 SendAvailableSendWindow();
455 QuicByteCount expected_send_window
=
456 kDefaultWindowTCP
+ (kDefaultTCPMSS
* 2 * kNumberOfAcks
);
457 EXPECT_EQ(expected_send_window
, sender_
->GetCongestionWindow());
461 // We should now have fallen out of slow start with a reduced window.
462 expected_send_window
= expected_send_window
* sender_
->GetRenoBeta();
463 EXPECT_EQ(expected_send_window
, sender_
->GetCongestionWindow());
465 // No congestion window growth should occur in recovery phase, i.e., until the
466 // currently outstanding 20 packets are acked.
467 for (int i
= 0; i
< 10; ++i
) {
468 // Send our full send window.
469 SendAvailableSendWindow();
470 EXPECT_TRUE(sender_
->InRecovery());
472 EXPECT_EQ(expected_send_window
, sender_
->GetCongestionWindow());
474 EXPECT_FALSE(sender_
->InRecovery());
476 // Out of recovery now. Congestion window should not grow for half an RTT.
477 size_t packets_in_send_window
= expected_send_window
/ kDefaultTCPMSS
;
478 SendAvailableSendWindow();
479 AckNPackets(packets_in_send_window
/ 2 - 2);
480 EXPECT_EQ(expected_send_window
, sender_
->GetCongestionWindow());
482 // Next ack should increase congestion window by 1MSS.
483 SendAvailableSendWindow();
485 expected_send_window
+= kDefaultTCPMSS
;
486 packets_in_send_window
+= 1;
487 EXPECT_EQ(expected_send_window
, sender_
->GetCongestionWindow());
489 // Congestion window should remain steady again for half an RTT.
490 SendAvailableSendWindow();
491 AckNPackets(packets_in_send_window
/ 2 - 1);
492 EXPECT_EQ(expected_send_window
, sender_
->GetCongestionWindow());
494 // Next ack should cause congestion window to grow by 1MSS.
495 SendAvailableSendWindow();
497 expected_send_window
+= kDefaultTCPMSS
;
498 EXPECT_EQ(expected_send_window
, sender_
->GetCongestionWindow());
501 TEST_F(TcpCubicBytesSenderTest
, 1ConnectionCongestionAvoidanceAtEndOfRecovery
) {
502 sender_
->SetNumEmulatedConnections(1);
503 // Ack 10 packets in 5 acks to raise the CWND to 20.
504 const int kNumberOfAcks
= 5;
505 for (int i
= 0; i
< kNumberOfAcks
; ++i
) {
506 // Send our full send window.
507 SendAvailableSendWindow();
510 SendAvailableSendWindow();
511 QuicByteCount expected_send_window
=
512 kDefaultWindowTCP
+ (kDefaultTCPMSS
* 2 * kNumberOfAcks
);
513 EXPECT_EQ(expected_send_window
, sender_
->GetCongestionWindow());
517 // We should now have fallen out of slow start with a reduced window.
518 expected_send_window
*= kRenoBeta
;
519 EXPECT_EQ(expected_send_window
, sender_
->GetCongestionWindow());
521 // No congestion window growth should occur in recovery phase, i.e., until the
522 // currently outstanding 20 packets are acked.
523 for (int i
= 0; i
< 10; ++i
) {
524 // Send our full send window.
525 SendAvailableSendWindow();
526 EXPECT_TRUE(sender_
->InRecovery());
528 EXPECT_EQ(expected_send_window
, sender_
->GetCongestionWindow());
530 EXPECT_FALSE(sender_
->InRecovery());
532 // Out of recovery now. Congestion window should not grow during RTT.
533 for (uint64 i
= 0; i
< expected_send_window
/ kDefaultTCPMSS
- 2; i
+= 2) {
534 // Send our full send window.
535 SendAvailableSendWindow();
537 EXPECT_EQ(expected_send_window
, sender_
->GetCongestionWindow());
540 // Next ack should cause congestion window to grow by 1MSS.
541 SendAvailableSendWindow();
543 expected_send_window
+= kDefaultTCPMSS
;
544 EXPECT_EQ(expected_send_window
, sender_
->GetCongestionWindow());
547 TEST_F(TcpCubicBytesSenderTest
, BandwidthResumption
) {
548 // Test that when provided with CachedNetworkParameters and opted in to the
549 // bandwidth resumption experiment, that the TcpCubicSender sets initial CWND
552 // Set some common values.
553 CachedNetworkParameters cached_network_params
;
554 const QuicPacketCount kNumberOfPackets
= 123;
555 const int kBandwidthEstimateBytesPerSecond
=
556 kNumberOfPackets
* kDefaultTCPMSS
;
557 cached_network_params
.set_bandwidth_estimate_bytes_per_second(
558 kBandwidthEstimateBytesPerSecond
);
559 cached_network_params
.set_min_rtt_ms(1000);
561 // Ensure that an old estimate is not used for bandwidth resumption.
562 cached_network_params
.set_timestamp(clock_
.WallNow().ToUNIXSeconds() -
563 (kNumSecondsPerHour
+ 1));
564 EXPECT_FALSE(sender_
->ResumeConnectionState(cached_network_params
, false));
565 EXPECT_EQ(10u * kDefaultTCPMSS
, sender_
->GetCongestionWindow());
567 // If the estimate is new enough, make sure it is used.
568 cached_network_params
.set_timestamp(clock_
.WallNow().ToUNIXSeconds() -
569 (kNumSecondsPerHour
- 1));
570 EXPECT_TRUE(sender_
->ResumeConnectionState(cached_network_params
, false));
571 EXPECT_EQ(kNumberOfPackets
* kDefaultTCPMSS
, sender_
->GetCongestionWindow());
573 // Resumed CWND is limited to be in a sensible range.
574 cached_network_params
.set_bandwidth_estimate_bytes_per_second(
575 (kMaxTcpCongestionWindow
+ 1) * kDefaultTCPMSS
);
576 EXPECT_TRUE(sender_
->ResumeConnectionState(cached_network_params
, false));
577 EXPECT_EQ(kMaxTcpCongestionWindow
* kDefaultTCPMSS
,
578 sender_
->GetCongestionWindow());
580 cached_network_params
.set_bandwidth_estimate_bytes_per_second(
581 (kMinCongestionWindowForBandwidthResumption
- 1) * kDefaultTCPMSS
);
582 EXPECT_TRUE(sender_
->ResumeConnectionState(cached_network_params
, false));
583 EXPECT_EQ(kMinCongestionWindowForBandwidthResumption
* kDefaultTCPMSS
,
584 sender_
->GetCongestionWindow());
586 // Resume to the max value.
587 cached_network_params
.set_max_bandwidth_estimate_bytes_per_second(
588 (kMinCongestionWindowForBandwidthResumption
+ 10) * kDefaultTCPMSS
);
589 EXPECT_TRUE(sender_
->ResumeConnectionState(cached_network_params
, true));
590 EXPECT_EQ((kMinCongestionWindowForBandwidthResumption
+ 10) * kDefaultTCPMSS
,
591 sender_
->GetCongestionWindow());