OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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_packets.h" | 5 #include "net/quic/congestion_control/tcp_cubic_sender_packets.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <memory> | 8 #include <memory> |
9 | 9 |
10 #include "base/logging.h" | 10 #include "base/logging.h" |
(...skipping 221 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
232 expected_send_window += kDefaultTCPMSS; | 232 expected_send_window += kDefaultTCPMSS; |
233 EXPECT_EQ(expected_send_window, sender_->GetCongestionWindow()); | 233 EXPECT_EQ(expected_send_window, sender_->GetCongestionWindow()); |
234 | 234 |
235 // Now RTO and ensure slow start gets reset. | 235 // Now RTO and ensure slow start gets reset. |
236 EXPECT_TRUE(sender_->hybrid_slow_start().started()); | 236 EXPECT_TRUE(sender_->hybrid_slow_start().started()); |
237 sender_->OnRetransmissionTimeout(true); | 237 sender_->OnRetransmissionTimeout(true); |
238 EXPECT_FALSE(sender_->hybrid_slow_start().started()); | 238 EXPECT_FALSE(sender_->hybrid_slow_start().started()); |
239 } | 239 } |
240 | 240 |
241 TEST_F(TcpCubicSenderPacketsTest, SlowStartPacketLossWithLargeReduction) { | 241 TEST_F(TcpCubicSenderPacketsTest, SlowStartPacketLossWithLargeReduction) { |
| 242 FLAGS_quic_sslr_limit_reduction = true; |
242 QuicConfig config; | 243 QuicConfig config; |
243 QuicTagVector options; | 244 QuicTagVector options; |
244 options.push_back(kSSLR); | 245 options.push_back(kSSLR); |
245 QuicConfigPeer::SetReceivedConnectionOptions(&config, options); | 246 QuicConfigPeer::SetReceivedConnectionOptions(&config, options); |
246 sender_->SetFromConfig(config, Perspective::IS_SERVER); | 247 sender_->SetFromConfig(config, Perspective::IS_SERVER); |
247 | 248 |
248 sender_->SetNumEmulatedConnections(1); | 249 sender_->SetNumEmulatedConnections(1); |
249 const int kNumberOfAcks = 10; | 250 const int kNumberOfAcks = (kDefaultWindowTCP / (2 * kDefaultTCPMSS)) - 1; |
250 for (int i = 0; i < kNumberOfAcks; ++i) { | 251 for (int i = 0; i < kNumberOfAcks; ++i) { |
251 // Send our full send window. | 252 // Send our full send window. |
252 SendAvailableSendWindow(); | 253 SendAvailableSendWindow(); |
253 AckNPackets(2); | 254 AckNPackets(2); |
254 } | 255 } |
255 SendAvailableSendWindow(); | 256 SendAvailableSendWindow(); |
256 QuicByteCount expected_send_window = | 257 QuicByteCount expected_send_window = |
257 kDefaultWindowTCP + (kDefaultTCPMSS * 2 * kNumberOfAcks); | 258 kDefaultWindowTCP + (kDefaultTCPMSS * 2 * kNumberOfAcks); |
258 EXPECT_EQ(expected_send_window, sender_->GetCongestionWindow()); | 259 EXPECT_EQ(expected_send_window, sender_->GetCongestionWindow()); |
259 | 260 |
260 // Lose a packet to exit slow start. We should now have fallen out of | 261 // Lose a packet to exit slow start. We should now have fallen out of |
261 // slow start with a window reduced by 1. | 262 // slow start with a window reduced by 1. |
262 LoseNPackets(1); | 263 LoseNPackets(1); |
263 expected_send_window -= kDefaultTCPMSS; | 264 expected_send_window -= kDefaultTCPMSS; |
264 EXPECT_EQ(expected_send_window, sender_->GetCongestionWindow()); | 265 EXPECT_EQ(expected_send_window, sender_->GetCongestionWindow()); |
265 | 266 |
266 // Lose 5 packets in recovery and verify that congestion window is reduced | 267 // Lose 5 packets in recovery and verify that congestion window is reduced |
267 // further. | 268 // further. |
268 LoseNPackets(5); | 269 LoseNPackets(5); |
269 expected_send_window -= 5 * kDefaultTCPMSS; | 270 expected_send_window -= 5 * kDefaultTCPMSS; |
270 EXPECT_EQ(expected_send_window, sender_->GetCongestionWindow()); | 271 EXPECT_EQ(expected_send_window, sender_->GetCongestionWindow()); |
| 272 // Lose another 10 packets and ensure it reduces below half the peak CWND, |
| 273 // because we never acked the full IW. |
| 274 LoseNPackets(10); |
| 275 expected_send_window -= 10 * kDefaultTCPMSS; |
| 276 EXPECT_EQ(expected_send_window, sender_->GetCongestionWindow()); |
271 | 277 |
272 size_t packets_in_recovery_window = expected_send_window / kDefaultTCPMSS; | 278 size_t packets_in_recovery_window = expected_send_window / kDefaultTCPMSS; |
273 | 279 |
274 // Recovery phase. We need to ack every packet in the recovery window before | 280 // Recovery phase. We need to ack every packet in the recovery window before |
275 // we exit recovery. | 281 // we exit recovery. |
276 size_t number_of_packets_in_window = expected_send_window / kDefaultTCPMSS; | 282 size_t number_of_packets_in_window = expected_send_window / kDefaultTCPMSS; |
277 DVLOG(1) << "number_packets: " << number_of_packets_in_window; | 283 DVLOG(1) << "number_packets: " << number_of_packets_in_window; |
278 AckNPackets(packets_in_recovery_window); | 284 AckNPackets(packets_in_recovery_window); |
279 SendAvailableSendWindow(); | 285 SendAvailableSendWindow(); |
280 EXPECT_EQ(expected_send_window, sender_->GetCongestionWindow()); | 286 EXPECT_EQ(expected_send_window, sender_->GetCongestionWindow()); |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
320 expected_send_window -= kDefaultTCPMSS; | 326 expected_send_window -= kDefaultTCPMSS; |
321 EXPECT_EQ(expected_send_window, sender_->GetCongestionWindow()); | 327 EXPECT_EQ(expected_send_window, sender_->GetCongestionWindow()); |
322 | 328 |
323 // Lose 10 packets in recovery and verify that congestion window is reduced | 329 // Lose 10 packets in recovery and verify that congestion window is reduced |
324 // by 5 packets. | 330 // by 5 packets. |
325 LoseNPackets(10, kDefaultTCPMSS / 2); | 331 LoseNPackets(10, kDefaultTCPMSS / 2); |
326 expected_send_window -= 5 * kDefaultTCPMSS; | 332 expected_send_window -= 5 * kDefaultTCPMSS; |
327 EXPECT_EQ(expected_send_window, sender_->GetCongestionWindow()); | 333 EXPECT_EQ(expected_send_window, sender_->GetCongestionWindow()); |
328 } | 334 } |
329 | 335 |
| 336 TEST_F(TcpCubicSenderPacketsTest, SlowStartPacketLossWithMaxHalfReduction) { |
| 337 FLAGS_quic_sslr_limit_reduction = true; |
| 338 QuicConfig config; |
| 339 QuicTagVector options; |
| 340 options.push_back(kSSLR); |
| 341 QuicConfigPeer::SetReceivedConnectionOptions(&config, options); |
| 342 sender_->SetFromConfig(config, Perspective::IS_SERVER); |
| 343 |
| 344 sender_->SetNumEmulatedConnections(1); |
| 345 const int kNumberOfAcks = kInitialCongestionWindowPackets / 2; |
| 346 for (int i = 0; i < kNumberOfAcks; ++i) { |
| 347 // Send our full send window. |
| 348 SendAvailableSendWindow(); |
| 349 AckNPackets(2); |
| 350 } |
| 351 SendAvailableSendWindow(); |
| 352 QuicByteCount expected_send_window = |
| 353 kDefaultWindowTCP + (kDefaultTCPMSS * 2 * kNumberOfAcks); |
| 354 EXPECT_EQ(expected_send_window, sender_->GetCongestionWindow()); |
| 355 |
| 356 // Lose a packet to exit slow start. We should now have fallen out of |
| 357 // slow start with a window reduced by 1. |
| 358 LoseNPackets(1); |
| 359 expected_send_window -= kDefaultTCPMSS; |
| 360 EXPECT_EQ(expected_send_window, sender_->GetCongestionWindow()); |
| 361 |
| 362 // Lose half the outstanding packets in recovery and verify the congestion |
| 363 // window is only reduced by a max of half. |
| 364 LoseNPackets(kNumberOfAcks * 2); |
| 365 expected_send_window -= (kNumberOfAcks * 2 - 1) * kDefaultTCPMSS; |
| 366 EXPECT_EQ(expected_send_window, sender_->GetCongestionWindow()); |
| 367 LoseNPackets(5); |
| 368 EXPECT_EQ(expected_send_window, sender_->GetCongestionWindow()); |
| 369 } |
| 370 |
330 TEST_F(TcpCubicSenderPacketsTest, NoPRRWhenLessThanOnePacketInFlight) { | 371 TEST_F(TcpCubicSenderPacketsTest, NoPRRWhenLessThanOnePacketInFlight) { |
331 SendAvailableSendWindow(); | 372 SendAvailableSendWindow(); |
332 LoseNPackets(kInitialCongestionWindowPackets - 1); | 373 LoseNPackets(kInitialCongestionWindowPackets - 1); |
333 AckNPackets(1); | 374 AckNPackets(1); |
334 // PRR will allow 2 packets for every ack during recovery. | 375 // PRR will allow 2 packets for every ack during recovery. |
335 EXPECT_EQ(2, SendAvailableSendWindow()); | 376 EXPECT_EQ(2, SendAvailableSendWindow()); |
336 // Simulate abandoning all packets by supplying a bytes_in_flight of 0. | 377 // Simulate abandoning all packets by supplying a bytes_in_flight of 0. |
337 // PRR should now allow a packet to be sent, even though prr's state | 378 // PRR should now allow a packet to be sent, even though prr's state |
338 // variables believe it has sent enough packets. | 379 // variables believe it has sent enough packets. |
339 EXPECT_EQ(QuicTime::Delta::Zero(), sender_->TimeUntilSend(clock_.Now(), 0)); | 380 EXPECT_EQ(QuicTime::Delta::Zero(), sender_->TimeUntilSend(clock_.Now(), 0)); |
(...skipping 495 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
835 (kNumSecondsPerHour - 1)); | 876 (kNumSecondsPerHour - 1)); |
836 sender_->ResumeConnectionState(cached_network_params, false); | 877 sender_->ResumeConnectionState(cached_network_params, false); |
837 EXPECT_EQ(kNumberOfPackets, sender_->congestion_window()); | 878 EXPECT_EQ(kNumberOfPackets, sender_->congestion_window()); |
838 | 879 |
839 // Resumed CWND is limited to be in a sensible range. | 880 // Resumed CWND is limited to be in a sensible range. |
840 cached_network_params.set_bandwidth_estimate_bytes_per_second( | 881 cached_network_params.set_bandwidth_estimate_bytes_per_second( |
841 (kMaxCongestionWindow + 1) * kDefaultTCPMSS); | 882 (kMaxCongestionWindow + 1) * kDefaultTCPMSS); |
842 sender_->ResumeConnectionState(cached_network_params, false); | 883 sender_->ResumeConnectionState(cached_network_params, false); |
843 EXPECT_EQ(kMaxCongestionWindow, sender_->congestion_window()); | 884 EXPECT_EQ(kMaxCongestionWindow, sender_->congestion_window()); |
844 | 885 |
845 cached_network_params.set_bandwidth_estimate_bytes_per_second( | 886 if (FLAGS_quic_no_lower_bw_resumption_limit) { |
846 (kMinCongestionWindowForBandwidthResumption - 1) * kDefaultTCPMSS); | 887 // Resume with an illegal value of 0 and verify the server uses 1 instead. |
847 sender_->ResumeConnectionState(cached_network_params, false); | 888 cached_network_params.set_bandwidth_estimate_bytes_per_second(0); |
848 EXPECT_EQ(kMinCongestionWindowForBandwidthResumption, | 889 sender_->ResumeConnectionState(cached_network_params, false); |
849 sender_->congestion_window()); | 890 EXPECT_EQ(sender_->min_congestion_window(), sender_->congestion_window()); |
| 891 } else { |
| 892 cached_network_params.set_bandwidth_estimate_bytes_per_second( |
| 893 (kMinCongestionWindowForBandwidthResumption - 1) * kDefaultTCPMSS); |
| 894 sender_->ResumeConnectionState(cached_network_params, false); |
| 895 EXPECT_EQ(kMinCongestionWindowForBandwidthResumption, |
| 896 sender_->congestion_window()); |
| 897 } |
850 | 898 |
851 // Resume to the max value. | 899 // Resume to the max value. |
852 cached_network_params.set_max_bandwidth_estimate_bytes_per_second( | 900 cached_network_params.set_max_bandwidth_estimate_bytes_per_second( |
853 (kMinCongestionWindowForBandwidthResumption + 10) * kDefaultTCPMSS); | 901 kMaxCongestionWindow * kDefaultTCPMSS); |
854 sender_->ResumeConnectionState(cached_network_params, true); | 902 sender_->ResumeConnectionState(cached_network_params, true); |
855 EXPECT_EQ((kMinCongestionWindowForBandwidthResumption + 10) * kDefaultTCPMSS, | 903 EXPECT_EQ(kMaxCongestionWindow * kDefaultTCPMSS, |
856 sender_->GetCongestionWindow()); | 904 sender_->GetCongestionWindow()); |
857 } | 905 } |
858 | 906 |
859 TEST_F(TcpCubicSenderPacketsTest, PaceBelowCWND) { | 907 TEST_F(TcpCubicSenderPacketsTest, PaceBelowCWND) { |
860 QuicConfig config; | 908 QuicConfig config; |
861 | 909 |
862 // Verify that kCOPT: kMIN4 forces the min CWND to 1 packet, but allows up | 910 // Verify that kCOPT: kMIN4 forces the min CWND to 1 packet, but allows up |
863 // to 4 to be sent. | 911 // to 4 to be sent. |
864 QuicTagVector options; | 912 QuicTagVector options; |
865 options.push_back(kMIN4); | 913 options.push_back(kMIN4); |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
906 | 954 |
907 // Resets cwnd and slow start threshold on connection migrations. | 955 // Resets cwnd and slow start threshold on connection migrations. |
908 sender_->OnConnectionMigration(); | 956 sender_->OnConnectionMigration(); |
909 EXPECT_EQ(kDefaultWindowTCP, sender_->GetCongestionWindow()); | 957 EXPECT_EQ(kDefaultWindowTCP, sender_->GetCongestionWindow()); |
910 EXPECT_EQ(kMaxCongestionWindow, sender_->slowstart_threshold()); | 958 EXPECT_EQ(kMaxCongestionWindow, sender_->slowstart_threshold()); |
911 EXPECT_FALSE(sender_->hybrid_slow_start().started()); | 959 EXPECT_FALSE(sender_->hybrid_slow_start().started()); |
912 } | 960 } |
913 | 961 |
914 } // namespace test | 962 } // namespace test |
915 } // namespace net | 963 } // namespace net |
OLD | NEW |