OLD | NEW |
1 // Copyright (c) 2015 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "net/quic/congestion_control/tcp_cubic_sender_bytes.h" | 5 #include "net/quic/congestion_control/tcp_cubic_sender_bytes.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <cstdint> | 8 #include <cstdint> |
9 #include <memory> | 9 #include <memory> |
10 | 10 |
(...skipping 213 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
224 expected_send_window += kDefaultTCPMSS; | 224 expected_send_window += kDefaultTCPMSS; |
225 EXPECT_EQ(expected_send_window, sender_->GetCongestionWindow()); | 225 EXPECT_EQ(expected_send_window, sender_->GetCongestionWindow()); |
226 | 226 |
227 // Now RTO and ensure slow start gets reset. | 227 // Now RTO and ensure slow start gets reset. |
228 EXPECT_TRUE(sender_->hybrid_slow_start().started()); | 228 EXPECT_TRUE(sender_->hybrid_slow_start().started()); |
229 sender_->OnRetransmissionTimeout(true); | 229 sender_->OnRetransmissionTimeout(true); |
230 EXPECT_FALSE(sender_->hybrid_slow_start().started()); | 230 EXPECT_FALSE(sender_->hybrid_slow_start().started()); |
231 } | 231 } |
232 | 232 |
233 TEST_F(TcpCubicSenderBytesTest, SlowStartPacketLossWithLargeReduction) { | 233 TEST_F(TcpCubicSenderBytesTest, SlowStartPacketLossWithLargeReduction) { |
| 234 FLAGS_quic_sslr_limit_reduction = true; |
234 QuicConfig config; | 235 QuicConfig config; |
235 QuicTagVector options; | 236 QuicTagVector options; |
236 options.push_back(kSSLR); | 237 options.push_back(kSSLR); |
237 QuicConfigPeer::SetReceivedConnectionOptions(&config, options); | 238 QuicConfigPeer::SetReceivedConnectionOptions(&config, options); |
238 sender_->SetFromConfig(config, Perspective::IS_SERVER); | 239 sender_->SetFromConfig(config, Perspective::IS_SERVER); |
239 | 240 |
240 sender_->SetNumEmulatedConnections(1); | 241 sender_->SetNumEmulatedConnections(1); |
241 const int kNumberOfAcks = 10; | 242 const int kNumberOfAcks = (kDefaultWindowTCP / (2 * kDefaultTCPMSS)) - 1; |
242 for (int i = 0; i < kNumberOfAcks; ++i) { | 243 for (int i = 0; i < kNumberOfAcks; ++i) { |
243 // Send our full send window. | 244 // Send our full send window. |
244 SendAvailableSendWindow(); | 245 SendAvailableSendWindow(); |
245 AckNPackets(2); | 246 AckNPackets(2); |
246 } | 247 } |
247 SendAvailableSendWindow(); | 248 SendAvailableSendWindow(); |
248 QuicByteCount expected_send_window = | 249 QuicByteCount expected_send_window = |
249 kDefaultWindowTCP + (kDefaultTCPMSS * 2 * kNumberOfAcks); | 250 kDefaultWindowTCP + (kDefaultTCPMSS * 2 * kNumberOfAcks); |
250 EXPECT_EQ(expected_send_window, sender_->GetCongestionWindow()); | 251 EXPECT_EQ(expected_send_window, sender_->GetCongestionWindow()); |
251 | 252 |
252 // Lose a packet to exit slow start. We should now have fallen out of | 253 // Lose a packet to exit slow start. We should now have fallen out of |
253 // slow start with a window reduced by 1. | 254 // slow start with a window reduced by 1. |
254 LoseNPackets(1); | 255 LoseNPackets(1); |
255 expected_send_window -= kDefaultTCPMSS; | 256 expected_send_window -= kDefaultTCPMSS; |
256 EXPECT_EQ(expected_send_window, sender_->GetCongestionWindow()); | 257 EXPECT_EQ(expected_send_window, sender_->GetCongestionWindow()); |
257 | 258 |
258 // Lose 5 packets in recovery and verify that congestion window is reduced | 259 // Lose 5 packets in recovery and verify that congestion window is reduced |
259 // further. | 260 // further. |
260 LoseNPackets(5); | 261 LoseNPackets(5); |
261 expected_send_window -= 5 * kDefaultTCPMSS; | 262 expected_send_window -= 5 * kDefaultTCPMSS; |
262 EXPECT_EQ(expected_send_window, sender_->GetCongestionWindow()); | 263 EXPECT_EQ(expected_send_window, sender_->GetCongestionWindow()); |
| 264 // Lose another 10 packets and ensure it reduces below half the peak CWND, |
| 265 // because we never acked the full IW. |
| 266 LoseNPackets(10); |
| 267 expected_send_window -= 10 * kDefaultTCPMSS; |
| 268 EXPECT_EQ(expected_send_window, sender_->GetCongestionWindow()); |
263 | 269 |
264 size_t packets_in_recovery_window = expected_send_window / kDefaultTCPMSS; | 270 size_t packets_in_recovery_window = expected_send_window / kDefaultTCPMSS; |
265 | 271 |
266 // Recovery phase. We need to ack every packet in the recovery window before | 272 // Recovery phase. We need to ack every packet in the recovery window before |
267 // we exit recovery. | 273 // we exit recovery. |
268 size_t number_of_packets_in_window = expected_send_window / kDefaultTCPMSS; | 274 size_t number_of_packets_in_window = expected_send_window / kDefaultTCPMSS; |
269 DVLOG(1) << "number_packets: " << number_of_packets_in_window; | 275 DVLOG(1) << "number_packets: " << number_of_packets_in_window; |
270 AckNPackets(packets_in_recovery_window); | 276 AckNPackets(packets_in_recovery_window); |
271 SendAvailableSendWindow(); | 277 SendAvailableSendWindow(); |
272 EXPECT_EQ(expected_send_window, sender_->GetCongestionWindow()); | 278 EXPECT_EQ(expected_send_window, sender_->GetCongestionWindow()); |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
312 expected_send_window -= kDefaultTCPMSS; | 318 expected_send_window -= kDefaultTCPMSS; |
313 EXPECT_EQ(expected_send_window, sender_->GetCongestionWindow()); | 319 EXPECT_EQ(expected_send_window, sender_->GetCongestionWindow()); |
314 | 320 |
315 // Lose 10 packets in recovery and verify that congestion window is reduced | 321 // Lose 10 packets in recovery and verify that congestion window is reduced |
316 // by 5 packets. | 322 // by 5 packets. |
317 LoseNPackets(10, kDefaultTCPMSS / 2); | 323 LoseNPackets(10, kDefaultTCPMSS / 2); |
318 expected_send_window -= 5 * kDefaultTCPMSS; | 324 expected_send_window -= 5 * kDefaultTCPMSS; |
319 EXPECT_EQ(expected_send_window, sender_->GetCongestionWindow()); | 325 EXPECT_EQ(expected_send_window, sender_->GetCongestionWindow()); |
320 } | 326 } |
321 | 327 |
| 328 TEST_F(TcpCubicSenderBytesTest, SlowStartPacketLossWithMaxHalfReduction) { |
| 329 FLAGS_quic_sslr_limit_reduction = true; |
| 330 QuicConfig config; |
| 331 QuicTagVector options; |
| 332 options.push_back(kSSLR); |
| 333 QuicConfigPeer::SetReceivedConnectionOptions(&config, options); |
| 334 sender_->SetFromConfig(config, Perspective::IS_SERVER); |
| 335 |
| 336 sender_->SetNumEmulatedConnections(1); |
| 337 const int kNumberOfAcks = kInitialCongestionWindowPackets / 2; |
| 338 for (int i = 0; i < kNumberOfAcks; ++i) { |
| 339 // Send our full send window. |
| 340 SendAvailableSendWindow(); |
| 341 AckNPackets(2); |
| 342 } |
| 343 SendAvailableSendWindow(); |
| 344 QuicByteCount expected_send_window = |
| 345 kDefaultWindowTCP + (kDefaultTCPMSS * 2 * kNumberOfAcks); |
| 346 EXPECT_EQ(expected_send_window, sender_->GetCongestionWindow()); |
| 347 |
| 348 // Lose a packet to exit slow start. We should now have fallen out of |
| 349 // slow start with a window reduced by 1. |
| 350 LoseNPackets(1); |
| 351 expected_send_window -= kDefaultTCPMSS; |
| 352 EXPECT_EQ(expected_send_window, sender_->GetCongestionWindow()); |
| 353 |
| 354 // Lose half the outstanding packets in recovery and verify the congestion |
| 355 // window is only reduced by a max of half. |
| 356 LoseNPackets(kNumberOfAcks * 2); |
| 357 expected_send_window -= (kNumberOfAcks * 2 - 1) * kDefaultTCPMSS; |
| 358 EXPECT_EQ(expected_send_window, sender_->GetCongestionWindow()); |
| 359 LoseNPackets(5); |
| 360 EXPECT_EQ(expected_send_window, sender_->GetCongestionWindow()); |
| 361 } |
| 362 |
322 TEST_F(TcpCubicSenderBytesTest, NoPRRWhenLessThanOnePacketInFlight) { | 363 TEST_F(TcpCubicSenderBytesTest, NoPRRWhenLessThanOnePacketInFlight) { |
323 SendAvailableSendWindow(); | 364 SendAvailableSendWindow(); |
324 LoseNPackets(kInitialCongestionWindowPackets - 1); | 365 LoseNPackets(kInitialCongestionWindowPackets - 1); |
325 AckNPackets(1); | 366 AckNPackets(1); |
326 // PRR will allow 2 packets for every ack during recovery. | 367 // PRR will allow 2 packets for every ack during recovery. |
327 EXPECT_EQ(2, SendAvailableSendWindow()); | 368 EXPECT_EQ(2, SendAvailableSendWindow()); |
328 // Simulate abandoning all packets by supplying a bytes_in_flight of 0. | 369 // Simulate abandoning all packets by supplying a bytes_in_flight of 0. |
329 // PRR should now allow a packet to be sent, even though prr's state variables | 370 // PRR should now allow a packet to be sent, even though prr's state variables |
330 // believe it has sent enough packets. | 371 // believe it has sent enough packets. |
331 EXPECT_EQ(QuicTime::Delta::Zero(), sender_->TimeUntilSend(clock_.Now(), 0)); | 372 EXPECT_EQ(QuicTime::Delta::Zero(), sender_->TimeUntilSend(clock_.Now(), 0)); |
(...skipping 357 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
689 sender_->ResumeConnectionState(cached_network_params, false); | 730 sender_->ResumeConnectionState(cached_network_params, false); |
690 EXPECT_EQ(kNumberOfPackets * kDefaultTCPMSS, sender_->GetCongestionWindow()); | 731 EXPECT_EQ(kNumberOfPackets * kDefaultTCPMSS, sender_->GetCongestionWindow()); |
691 | 732 |
692 // Resumed CWND is limited to be in a sensible range. | 733 // Resumed CWND is limited to be in a sensible range. |
693 cached_network_params.set_bandwidth_estimate_bytes_per_second( | 734 cached_network_params.set_bandwidth_estimate_bytes_per_second( |
694 (kMaxCongestionWindow + 1) * kDefaultTCPMSS); | 735 (kMaxCongestionWindow + 1) * kDefaultTCPMSS); |
695 sender_->ResumeConnectionState(cached_network_params, false); | 736 sender_->ResumeConnectionState(cached_network_params, false); |
696 EXPECT_EQ(kMaxCongestionWindow * kDefaultTCPMSS, | 737 EXPECT_EQ(kMaxCongestionWindow * kDefaultTCPMSS, |
697 sender_->GetCongestionWindow()); | 738 sender_->GetCongestionWindow()); |
698 | 739 |
699 cached_network_params.set_bandwidth_estimate_bytes_per_second( | 740 if (FLAGS_quic_no_lower_bw_resumption_limit) { |
700 (kMinCongestionWindowForBandwidthResumption - 1) * kDefaultTCPMSS); | 741 // Resume with an illegal value of 0 and verify the server uses 1 instead. |
701 sender_->ResumeConnectionState(cached_network_params, false); | 742 cached_network_params.set_bandwidth_estimate_bytes_per_second(0); |
702 EXPECT_EQ(kMinCongestionWindowForBandwidthResumption * kDefaultTCPMSS, | 743 sender_->ResumeConnectionState(cached_network_params, false); |
703 sender_->GetCongestionWindow()); | 744 EXPECT_EQ(sender_->min_congestion_window(), sender_->GetCongestionWindow()); |
| 745 } else { |
| 746 cached_network_params.set_bandwidth_estimate_bytes_per_second( |
| 747 (kMinCongestionWindowForBandwidthResumption - 1) * kDefaultTCPMSS); |
| 748 sender_->ResumeConnectionState(cached_network_params, false); |
| 749 EXPECT_EQ(kMinCongestionWindowForBandwidthResumption * kDefaultTCPMSS, |
| 750 sender_->GetCongestionWindow()); |
| 751 } |
704 | 752 |
705 // Resume to the max value. | 753 // Resume to the max value. |
706 cached_network_params.set_max_bandwidth_estimate_bytes_per_second( | 754 cached_network_params.set_max_bandwidth_estimate_bytes_per_second( |
707 (kMinCongestionWindowForBandwidthResumption + 10) * kDefaultTCPMSS); | 755 kMaxCongestionWindow * kDefaultTCPMSS); |
708 sender_->ResumeConnectionState(cached_network_params, true); | 756 sender_->ResumeConnectionState(cached_network_params, true); |
709 EXPECT_EQ((kMinCongestionWindowForBandwidthResumption + 10) * kDefaultTCPMSS, | 757 EXPECT_EQ(kMaxCongestionWindow * kDefaultTCPMSS, |
710 sender_->GetCongestionWindow()); | 758 sender_->GetCongestionWindow()); |
711 } | 759 } |
712 | 760 |
713 TEST_F(TcpCubicSenderBytesTest, PaceBelowCWND) { | 761 TEST_F(TcpCubicSenderBytesTest, PaceBelowCWND) { |
714 QuicConfig config; | 762 QuicConfig config; |
715 | 763 |
716 // Verify that kCOPT: kMIN4 forces the min CWND to 1 packet, but allows up | 764 // Verify that kCOPT: kMIN4 forces the min CWND to 1 packet, but allows up |
717 // to 4 to be sent. | 765 // to 4 to be sent. |
718 QuicTagVector options; | 766 QuicTagVector options; |
719 options.push_back(kMIN4); | 767 options.push_back(kMIN4); |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
757 // Resets cwnd and slow start threshold on connection migrations. | 805 // Resets cwnd and slow start threshold on connection migrations. |
758 sender_->OnConnectionMigration(); | 806 sender_->OnConnectionMigration(); |
759 EXPECT_EQ(kDefaultWindowTCP, sender_->GetCongestionWindow()); | 807 EXPECT_EQ(kDefaultWindowTCP, sender_->GetCongestionWindow()); |
760 EXPECT_EQ(kMaxCongestionWindow * kDefaultTCPMSS, | 808 EXPECT_EQ(kMaxCongestionWindow * kDefaultTCPMSS, |
761 sender_->GetSlowStartThreshold()); | 809 sender_->GetSlowStartThreshold()); |
762 EXPECT_FALSE(sender_->hybrid_slow_start().started()); | 810 EXPECT_FALSE(sender_->hybrid_slow_start().started()); |
763 } | 811 } |
764 | 812 |
765 } // namespace test | 813 } // namespace test |
766 } // namespace net | 814 } // namespace net |
OLD | NEW |