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/proto/cached_network_parameters.pb.h"
14 #include "net/quic/quic_protocol.h"
15 #include "net/quic/quic_utils.h"
16 #include "net/quic/test_tools/mock_clock.h"
17 #include "net/quic/test_tools/quic_config_peer.h"
18 #include "testing/gtest/include/gtest/gtest.h"
23 // TODO(ianswett): A number of theses tests were written with the assumption of
24 // an initial CWND of 10. They have carefully calculated values which should be
25 // updated to be based on kInitialCongestionWindowInsecure.
26 const uint32 kInitialCongestionWindowPackets
= 10;
27 const uint32 kDefaultWindowTCP
=
28 kInitialCongestionWindowPackets
* kDefaultTCPMSS
;
29 const float kRenoBeta
= 0.7f
; // Reno backoff factor.
31 class TcpCubicBytesSenderPeer
: public TcpCubicBytesSender
{
33 TcpCubicBytesSenderPeer(const QuicClock
* clock
, bool reno
)
34 : TcpCubicBytesSender(clock
,
37 kInitialCongestionWindowPackets
,
38 kMaxTcpCongestionWindow
,
41 const HybridSlowStart
& hybrid_slow_start() const {
42 return hybrid_slow_start_
;
45 float GetRenoBeta() const { return RenoBeta(); }
48 QuicConnectionStats stats_
;
51 class TcpCubicBytesSenderTest
: public ::testing::Test
{
53 TcpCubicBytesSenderTest()
54 : one_ms_(QuicTime::Delta::FromMilliseconds(1)),
55 sender_(new TcpCubicBytesSenderPeer(&clock_
, true)),
57 acked_sequence_number_(0),
59 standard_packet_
.bytes_sent
= kDefaultTCPMSS
;
62 int SendAvailableSendWindow() {
63 // Send as long as TimeUntilSend returns Zero.
65 bool can_send
= sender_
->TimeUntilSend(clock_
.Now(), bytes_in_flight_
,
66 HAS_RETRANSMITTABLE_DATA
).IsZero();
68 sender_
->OnPacketSent(clock_
.Now(), bytes_in_flight_
, sequence_number_
++,
69 kDefaultTCPMSS
, HAS_RETRANSMITTABLE_DATA
);
71 bytes_in_flight_
+= kDefaultTCPMSS
;
72 can_send
= sender_
->TimeUntilSend(clock_
.Now(), bytes_in_flight_
,
73 HAS_RETRANSMITTABLE_DATA
).IsZero();
78 // Normal is that TCP acks every other segment.
79 void AckNPackets(int n
) {
80 sender_
->rtt_stats_
.UpdateRtt(QuicTime::Delta::FromMilliseconds(60),
81 QuicTime::Delta::Zero(), clock_
.Now());
82 SendAlgorithmInterface::CongestionVector acked_packets
;
83 SendAlgorithmInterface::CongestionVector lost_packets
;
84 for (int i
= 0; i
< n
; ++i
) {
85 ++acked_sequence_number_
;
86 acked_packets
.push_back(
87 std::make_pair(acked_sequence_number_
, standard_packet_
));
89 sender_
->OnCongestionEvent(true, bytes_in_flight_
, acked_packets
,
91 bytes_in_flight_
-= n
* kDefaultTCPMSS
;
92 clock_
.AdvanceTime(one_ms_
);
95 void LoseNPackets(int n
) {
96 SendAlgorithmInterface::CongestionVector acked_packets
;
97 SendAlgorithmInterface::CongestionVector lost_packets
;
98 for (int i
= 0; i
< n
; ++i
) {
99 ++acked_sequence_number_
;
100 lost_packets
.push_back(
101 std::make_pair(acked_sequence_number_
, standard_packet_
));
103 sender_
->OnCongestionEvent(false, bytes_in_flight_
, acked_packets
,
105 bytes_in_flight_
-= n
* kDefaultTCPMSS
;
108 // Does not increment acked_sequence_number_.
109 void LosePacket(QuicPacketSequenceNumber sequence_number
) {
110 SendAlgorithmInterface::CongestionVector acked_packets
;
111 SendAlgorithmInterface::CongestionVector lost_packets
;
112 lost_packets
.push_back(std::make_pair(sequence_number
, standard_packet_
));
113 sender_
->OnCongestionEvent(false, bytes_in_flight_
, acked_packets
,
115 bytes_in_flight_
-= kDefaultTCPMSS
;
118 const QuicTime::Delta one_ms_
;
120 scoped_ptr
<TcpCubicBytesSenderPeer
> sender_
;
121 QuicPacketSequenceNumber sequence_number_
;
122 QuicPacketSequenceNumber acked_sequence_number_
;
123 QuicByteCount bytes_in_flight_
;
124 TransmissionInfo standard_packet_
;
127 TEST_F(TcpCubicBytesSenderTest
, SimpleSender
) {
128 // At startup make sure we are at the default.
129 EXPECT_EQ(kDefaultWindowTCP
, sender_
->GetCongestionWindow());
130 // At startup make sure we can send.
131 EXPECT_TRUE(sender_
->TimeUntilSend(clock_
.Now(), 0,
132 HAS_RETRANSMITTABLE_DATA
).IsZero());
133 // Make sure we can send.
134 EXPECT_TRUE(sender_
->TimeUntilSend(clock_
.Now(), 0,
135 HAS_RETRANSMITTABLE_DATA
).IsZero());
136 // And that window is un-affected.
137 EXPECT_EQ(kDefaultWindowTCP
, sender_
->GetCongestionWindow());
139 // Fill the send window with data, then verify that we can't send.
140 SendAvailableSendWindow();
141 EXPECT_FALSE(sender_
->TimeUntilSend(clock_
.Now(),
142 sender_
->GetCongestionWindow(),
143 HAS_RETRANSMITTABLE_DATA
).IsZero());
146 TEST_F(TcpCubicBytesSenderTest
, ApplicationLimitedSlowStart
) {
147 // Send exactly 10 packets and ensure the CWND ends at 14 packets.
148 const int kNumberOfAcks
= 5;
149 // At startup make sure we can send.
150 EXPECT_TRUE(sender_
->TimeUntilSend(clock_
.Now(), 0,
151 HAS_RETRANSMITTABLE_DATA
).IsZero());
152 // Make sure we can send.
153 EXPECT_TRUE(sender_
->TimeUntilSend(clock_
.Now(), 0,
154 HAS_RETRANSMITTABLE_DATA
).IsZero());
156 SendAvailableSendWindow();
157 for (int i
= 0; i
< kNumberOfAcks
; ++i
) {
160 QuicByteCount bytes_to_send
= sender_
->GetCongestionWindow();
161 // It's expected 2 acks will arrive when the bytes_in_flight are greater than
163 EXPECT_EQ(kDefaultWindowTCP
+ kDefaultTCPMSS
* 2 * 2, bytes_to_send
);
166 TEST_F(TcpCubicBytesSenderTest
, ExponentialSlowStart
) {
167 const int kNumberOfAcks
= 20;
168 // At startup make sure we can send.
169 EXPECT_TRUE(sender_
->TimeUntilSend(clock_
.Now(), 0,
170 HAS_RETRANSMITTABLE_DATA
).IsZero());
171 EXPECT_FALSE(sender_
->HasReliableBandwidthEstimate());
172 EXPECT_EQ(QuicBandwidth::Zero(), sender_
->BandwidthEstimate());
173 // Make sure we can send.
174 EXPECT_TRUE(sender_
->TimeUntilSend(clock_
.Now(), 0,
175 HAS_RETRANSMITTABLE_DATA
).IsZero());
177 for (int i
= 0; i
< kNumberOfAcks
; ++i
) {
178 // Send our full send window.
179 SendAvailableSendWindow();
182 const QuicByteCount cwnd
= sender_
->GetCongestionWindow();
183 EXPECT_EQ(kDefaultWindowTCP
+ kDefaultTCPMSS
* 2 * kNumberOfAcks
, cwnd
);
184 EXPECT_FALSE(sender_
->HasReliableBandwidthEstimate());
185 EXPECT_EQ(QuicBandwidth::FromBytesAndTimeDelta(
186 cwnd
, sender_
->rtt_stats_
.smoothed_rtt()),
187 sender_
->BandwidthEstimate());
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();
198 SendAvailableSendWindow();
199 QuicByteCount expected_send_window
=
200 kDefaultWindowTCP
+ (kDefaultTCPMSS
* 2 * kNumberOfAcks
);
201 EXPECT_EQ(expected_send_window
, sender_
->GetCongestionWindow());
203 // Lose a packet to exit slow start.
205 size_t packets_in_recovery_window
= expected_send_window
/ kDefaultTCPMSS
;
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());
211 // Recovery phase. We need to ack every packet in the recovery window before
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());
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());
224 // Next ack should increase cwnd by 1.
226 expected_send_window
+= kDefaultTCPMSS
;
227 EXPECT_EQ(expected_send_window
, sender_
->GetCongestionWindow());
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());
235 TEST_F(TcpCubicBytesSenderTest
, NoPRRWhenLessThanOnePacketInFlight
) {
236 SendAvailableSendWindow();
237 LoseNPackets(kInitialCongestionWindowPackets
- 1);
239 // PRR will allow 2 packets for every ack during recovery.
240 EXPECT_EQ(2, SendAvailableSendWindow());
241 // Simulate abandoning all packets by supplying a bytes_in_flight of 0.
242 // PRR should now allow a packet to be sent, even though prr's state variables
243 // believe it has sent enough packets.
244 EXPECT_EQ(QuicTime::Delta::Zero(),
245 sender_
->TimeUntilSend(clock_
.Now(), 0, HAS_RETRANSMITTABLE_DATA
));
248 TEST_F(TcpCubicBytesSenderTest
, SlowStartPacketLossPRR
) {
249 sender_
->SetNumEmulatedConnections(1);
250 // Test based on the first example in RFC6937.
251 // Ack 10 packets in 5 acks to raise the CWND to 20, as in the example.
252 const int kNumberOfAcks
= 5;
253 for (int i
= 0; i
< kNumberOfAcks
; ++i
) {
254 // Send our full send window.
255 SendAvailableSendWindow();
258 SendAvailableSendWindow();
259 QuicByteCount expected_send_window
=
260 kDefaultWindowTCP
+ (kDefaultTCPMSS
* 2 * kNumberOfAcks
);
261 EXPECT_EQ(expected_send_window
, sender_
->GetCongestionWindow());
265 // We should now have fallen out of slow start with a reduced window.
266 size_t send_window_before_loss
= expected_send_window
;
267 expected_send_window
*= kRenoBeta
;
268 EXPECT_EQ(expected_send_window
, sender_
->GetCongestionWindow());
270 // Testing TCP proportional rate reduction.
271 // We should send packets paced over the received acks for the remaining
272 // outstanding packets. The number of packets before we exit recovery is the
273 // original CWND minus the packet that has been lost and the one which
274 // triggered the loss.
275 size_t remaining_packets_in_recovery
=
276 send_window_before_loss
/ kDefaultTCPMSS
- 2;
278 for (size_t i
= 0; i
< remaining_packets_in_recovery
; ++i
) {
280 SendAvailableSendWindow();
281 EXPECT_EQ(expected_send_window
, sender_
->GetCongestionWindow());
284 // We need to ack another window before we increase CWND by 1.
285 size_t number_of_packets_in_window
= expected_send_window
/ kDefaultTCPMSS
;
286 for (size_t i
= 0; i
< number_of_packets_in_window
; ++i
) {
288 EXPECT_EQ(1, SendAvailableSendWindow());
289 EXPECT_EQ(expected_send_window
, sender_
->GetCongestionWindow());
293 expected_send_window
+= kDefaultTCPMSS
;
294 EXPECT_EQ(expected_send_window
, sender_
->GetCongestionWindow());
297 TEST_F(TcpCubicBytesSenderTest
, SlowStartBurstPacketLossPRR
) {
298 sender_
->SetNumEmulatedConnections(1);
299 // Test based on the second example in RFC6937, though we also implement
300 // forward acknowledgements, so the first two incoming acks will trigger
302 // Ack 20 packets in 10 acks to raise the CWND to 30.
303 const int kNumberOfAcks
= 10;
304 for (int i
= 0; i
< kNumberOfAcks
; ++i
) {
305 // Send our full send window.
306 SendAvailableSendWindow();
309 SendAvailableSendWindow();
310 QuicByteCount expected_send_window
=
311 kDefaultWindowTCP
+ (kDefaultTCPMSS
* 2 * kNumberOfAcks
);
312 EXPECT_EQ(expected_send_window
, sender_
->GetCongestionWindow());
314 // Lose one more than the congestion window reduction, so that after loss,
315 // bytes_in_flight is lesser than the congestion window.
316 size_t send_window_after_loss
= kRenoBeta
* expected_send_window
;
317 size_t num_packets_to_lose
=
318 (expected_send_window
- send_window_after_loss
) / kDefaultTCPMSS
+ 1;
319 LoseNPackets(num_packets_to_lose
);
320 // Immediately after the loss, ensure at least one packet can be sent.
321 // Losses without subsequent acks can occur with timer based loss detection.
322 EXPECT_TRUE(sender_
->TimeUntilSend(clock_
.Now(), bytes_in_flight_
,
323 HAS_RETRANSMITTABLE_DATA
).IsZero());
326 // We should now have fallen out of slow start with a reduced window.
327 expected_send_window
*= kRenoBeta
;
328 EXPECT_EQ(expected_send_window
, sender_
->GetCongestionWindow());
330 // Only 2 packets should be allowed to be sent, per PRR-SSRB.
331 EXPECT_EQ(2, SendAvailableSendWindow());
333 // Ack the next packet, which triggers another loss.
337 // Send 2 packets to simulate PRR-SSRB.
338 EXPECT_EQ(2, SendAvailableSendWindow());
340 // Ack the next packet, which triggers another loss.
344 // Send 2 packets to simulate PRR-SSRB.
345 EXPECT_EQ(2, SendAvailableSendWindow());
347 // Exit recovery and return to sending at the new rate.
348 for (int i
= 0; i
< kNumberOfAcks
; ++i
) {
350 EXPECT_EQ(1, SendAvailableSendWindow());
354 TEST_F(TcpCubicBytesSenderTest
, RTOCongestionWindow
) {
355 EXPECT_EQ(kDefaultWindowTCP
, sender_
->GetCongestionWindow());
356 // Expect the window to decrease to the minimum once the RTO fires and slow
357 // start threshold to be set to 1/2 of the CWND.
358 sender_
->OnRetransmissionTimeout(true);
359 EXPECT_EQ(2 * kDefaultTCPMSS
, sender_
->GetCongestionWindow());
360 EXPECT_EQ(5u * kDefaultTCPMSS
, sender_
->GetSlowStartThreshold());
363 TEST_F(TcpCubicBytesSenderTest
, RTOCongestionWindowNoRetransmission
) {
364 EXPECT_EQ(kDefaultWindowTCP
, sender_
->GetCongestionWindow());
366 // Expect the window to remain unchanged if the RTO fires but no packets are
368 sender_
->OnRetransmissionTimeout(false);
369 EXPECT_EQ(kDefaultWindowTCP
, sender_
->GetCongestionWindow());
372 TEST_F(TcpCubicBytesSenderTest
, RetransmissionDelay
) {
373 const int64 kRttMs
= 10;
374 const int64 kDeviationMs
= 3;
375 EXPECT_EQ(QuicTime::Delta::Zero(), sender_
->RetransmissionDelay());
377 sender_
->rtt_stats_
.UpdateRtt(QuicTime::Delta::FromMilliseconds(kRttMs
),
378 QuicTime::Delta::Zero(), clock_
.Now());
380 // Initial value is to set the median deviation to half of the initial rtt,
381 // the median in then multiplied by a factor of 4 and finally the smoothed rtt
382 // is added which is the initial rtt.
383 QuicTime::Delta expected_delay
=
384 QuicTime::Delta::FromMilliseconds(kRttMs
+ kRttMs
/ 2 * 4);
385 EXPECT_EQ(expected_delay
, sender_
->RetransmissionDelay());
387 for (int i
= 0; i
< 100; ++i
) {
388 // Run to make sure that we converge.
389 sender_
->rtt_stats_
.UpdateRtt(
390 QuicTime::Delta::FromMilliseconds(kRttMs
+ kDeviationMs
),
391 QuicTime::Delta::Zero(), clock_
.Now());
392 sender_
->rtt_stats_
.UpdateRtt(
393 QuicTime::Delta::FromMilliseconds(kRttMs
- kDeviationMs
),
394 QuicTime::Delta::Zero(), clock_
.Now());
396 expected_delay
= QuicTime::Delta::FromMilliseconds(kRttMs
+ kDeviationMs
* 4);
398 EXPECT_NEAR(kRttMs
, sender_
->rtt_stats_
.smoothed_rtt().ToMilliseconds(), 1);
399 EXPECT_NEAR(expected_delay
.ToMilliseconds(),
400 sender_
->RetransmissionDelay().ToMilliseconds(), 1);
402 static_cast<int64
>(sender_
->GetCongestionWindow() * kNumMicrosPerSecond
/
403 sender_
->rtt_stats_
.smoothed_rtt().ToMicroseconds()),
404 sender_
->BandwidthEstimate().ToBytesPerSecond());
407 TEST_F(TcpCubicBytesSenderTest
, MultipleLossesInOneWindow
) {
408 SendAvailableSendWindow();
409 const QuicByteCount initial_window
= sender_
->GetCongestionWindow();
410 LosePacket(acked_sequence_number_
+ 1);
411 const QuicByteCount post_loss_window
= sender_
->GetCongestionWindow();
412 EXPECT_GT(initial_window
, post_loss_window
);
413 LosePacket(acked_sequence_number_
+ 3);
414 EXPECT_EQ(post_loss_window
, sender_
->GetCongestionWindow());
415 LosePacket(sequence_number_
- 1);
416 EXPECT_EQ(post_loss_window
, sender_
->GetCongestionWindow());
418 // Lose a later packet and ensure the window decreases.
419 LosePacket(sequence_number_
);
420 EXPECT_GT(post_loss_window
, sender_
->GetCongestionWindow());
423 TEST_F(TcpCubicBytesSenderTest
, DontTrackAckPackets
) {
424 // Send a packet with no retransmittable data, and ensure it's not tracked.
425 EXPECT_FALSE(sender_
->OnPacketSent(clock_
.Now(), bytes_in_flight_
,
426 sequence_number_
++, kDefaultTCPMSS
,
427 NO_RETRANSMITTABLE_DATA
));
429 // Send a data packet with retransmittable data, and ensure it is tracked.
430 EXPECT_TRUE(sender_
->OnPacketSent(clock_
.Now(), bytes_in_flight_
,
431 sequence_number_
++, kDefaultTCPMSS
,
432 HAS_RETRANSMITTABLE_DATA
));
435 TEST_F(TcpCubicBytesSenderTest
, ConfigureMaxInitialWindow
) {
438 // Verify that kCOPT: kIW10 forces the congestion window to the default of 10.
439 QuicTagVector options
;
440 options
.push_back(kIW10
);
441 QuicConfigPeer::SetReceivedConnectionOptions(&config
, options
);
442 sender_
->SetFromConfig(config
, Perspective::IS_SERVER
);
443 EXPECT_EQ(10u * kDefaultTCPMSS
, sender_
->GetCongestionWindow());
446 TEST_F(TcpCubicBytesSenderTest
, 2ConnectionCongestionAvoidanceAtEndOfRecovery
) {
447 sender_
->SetNumEmulatedConnections(2);
448 // Ack 10 packets in 5 acks to raise the CWND to 20.
449 const int kNumberOfAcks
= 5;
450 for (int i
= 0; i
< kNumberOfAcks
; ++i
) {
451 // Send our full send window.
452 SendAvailableSendWindow();
455 SendAvailableSendWindow();
456 QuicByteCount expected_send_window
=
457 kDefaultWindowTCP
+ (kDefaultTCPMSS
* 2 * kNumberOfAcks
);
458 EXPECT_EQ(expected_send_window
, sender_
->GetCongestionWindow());
462 // We should now have fallen out of slow start with a reduced window.
463 expected_send_window
= expected_send_window
* sender_
->GetRenoBeta();
464 EXPECT_EQ(expected_send_window
, sender_
->GetCongestionWindow());
466 // No congestion window growth should occur in recovery phase, i.e., until the
467 // currently outstanding 20 packets are acked.
468 for (int i
= 0; i
< 10; ++i
) {
469 // Send our full send window.
470 SendAvailableSendWindow();
471 EXPECT_TRUE(sender_
->InRecovery());
473 EXPECT_EQ(expected_send_window
, sender_
->GetCongestionWindow());
475 EXPECT_FALSE(sender_
->InRecovery());
477 // Out of recovery now. Congestion window should not grow for half an RTT.
478 size_t packets_in_send_window
= expected_send_window
/ kDefaultTCPMSS
;
479 SendAvailableSendWindow();
480 AckNPackets(packets_in_send_window
/ 2 - 2);
481 EXPECT_EQ(expected_send_window
, sender_
->GetCongestionWindow());
483 // Next ack should increase congestion window by 1MSS.
484 SendAvailableSendWindow();
486 expected_send_window
+= kDefaultTCPMSS
;
487 packets_in_send_window
+= 1;
488 EXPECT_EQ(expected_send_window
, sender_
->GetCongestionWindow());
490 // Congestion window should remain steady again for half an RTT.
491 SendAvailableSendWindow();
492 AckNPackets(packets_in_send_window
/ 2 - 1);
493 EXPECT_EQ(expected_send_window
, sender_
->GetCongestionWindow());
495 // Next ack should cause congestion window to grow by 1MSS.
496 SendAvailableSendWindow();
498 expected_send_window
+= kDefaultTCPMSS
;
499 EXPECT_EQ(expected_send_window
, sender_
->GetCongestionWindow());
502 TEST_F(TcpCubicBytesSenderTest
, 1ConnectionCongestionAvoidanceAtEndOfRecovery
) {
503 sender_
->SetNumEmulatedConnections(1);
504 // Ack 10 packets in 5 acks to raise the CWND to 20.
505 const int kNumberOfAcks
= 5;
506 for (int i
= 0; i
< kNumberOfAcks
; ++i
) {
507 // Send our full send window.
508 SendAvailableSendWindow();
511 SendAvailableSendWindow();
512 QuicByteCount expected_send_window
=
513 kDefaultWindowTCP
+ (kDefaultTCPMSS
* 2 * kNumberOfAcks
);
514 EXPECT_EQ(expected_send_window
, sender_
->GetCongestionWindow());
518 // We should now have fallen out of slow start with a reduced window.
519 expected_send_window
*= kRenoBeta
;
520 EXPECT_EQ(expected_send_window
, sender_
->GetCongestionWindow());
522 // No congestion window growth should occur in recovery phase, i.e., until the
523 // currently outstanding 20 packets are acked.
524 for (int i
= 0; i
< 10; ++i
) {
525 // Send our full send window.
526 SendAvailableSendWindow();
527 EXPECT_TRUE(sender_
->InRecovery());
529 EXPECT_EQ(expected_send_window
, sender_
->GetCongestionWindow());
531 EXPECT_FALSE(sender_
->InRecovery());
533 // Out of recovery now. Congestion window should not grow during RTT.
534 for (uint64 i
= 0; i
< expected_send_window
/ kDefaultTCPMSS
- 2; i
+= 2) {
535 // Send our full send window.
536 SendAvailableSendWindow();
538 EXPECT_EQ(expected_send_window
, sender_
->GetCongestionWindow());
541 // Next ack should cause congestion window to grow by 1MSS.
542 SendAvailableSendWindow();
544 expected_send_window
+= kDefaultTCPMSS
;
545 EXPECT_EQ(expected_send_window
, sender_
->GetCongestionWindow());
548 TEST_F(TcpCubicBytesSenderTest
, BandwidthResumption
) {
549 // Test that when provided with CachedNetworkParameters and opted in to the
550 // bandwidth resumption experiment, that the TcpCubicSender sets initial CWND
553 // Set some common values.
554 CachedNetworkParameters cached_network_params
;
555 const QuicPacketCount kNumberOfPackets
= 123;
556 const int kBandwidthEstimateBytesPerSecond
=
557 kNumberOfPackets
* kDefaultTCPMSS
;
558 cached_network_params
.set_bandwidth_estimate_bytes_per_second(
559 kBandwidthEstimateBytesPerSecond
);
560 cached_network_params
.set_min_rtt_ms(1000);
562 // Ensure that an old estimate is not used for bandwidth resumption.
563 cached_network_params
.set_timestamp(clock_
.WallNow().ToUNIXSeconds() -
564 (kNumSecondsPerHour
+ 1));
565 EXPECT_FALSE(sender_
->ResumeConnectionState(cached_network_params
, false));
566 EXPECT_EQ(10u * kDefaultTCPMSS
, sender_
->GetCongestionWindow());
568 // If the estimate is new enough, make sure it is used.
569 cached_network_params
.set_timestamp(clock_
.WallNow().ToUNIXSeconds() -
570 (kNumSecondsPerHour
- 1));
571 EXPECT_TRUE(sender_
->ResumeConnectionState(cached_network_params
, false));
572 EXPECT_EQ(kNumberOfPackets
* kDefaultTCPMSS
, sender_
->GetCongestionWindow());
574 // Resumed CWND is limited to be in a sensible range.
575 cached_network_params
.set_bandwidth_estimate_bytes_per_second(
576 (kMaxTcpCongestionWindow
+ 1) * kDefaultTCPMSS
);
577 EXPECT_TRUE(sender_
->ResumeConnectionState(cached_network_params
, false));
578 EXPECT_EQ(kMaxTcpCongestionWindow
* kDefaultTCPMSS
,
579 sender_
->GetCongestionWindow());
581 cached_network_params
.set_bandwidth_estimate_bytes_per_second(
582 (kMinCongestionWindowForBandwidthResumption
- 1) * kDefaultTCPMSS
);
583 EXPECT_TRUE(sender_
->ResumeConnectionState(cached_network_params
, false));
584 EXPECT_EQ(kMinCongestionWindowForBandwidthResumption
* kDefaultTCPMSS
,
585 sender_
->GetCongestionWindow());
587 // Resume to the max value.
588 cached_network_params
.set_max_bandwidth_estimate_bytes_per_second(
589 (kMinCongestionWindowForBandwidthResumption
+ 10) * kDefaultTCPMSS
);
590 EXPECT_TRUE(sender_
->ResumeConnectionState(cached_network_params
, true));
591 EXPECT_EQ((kMinCongestionWindowForBandwidthResumption
+ 10) * kDefaultTCPMSS
,
592 sender_
->GetCongestionWindow());