OLD | NEW |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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/core/congestion_control/bbr_sender.h" | 5 #include "net/quic/core/congestion_control/bbr_sender.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <map> | 8 #include <map> |
9 #include <memory> | 9 #include <memory> |
10 | 10 |
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
84 Perspective::IS_SERVER, | 84 Perspective::IS_SERVER, |
85 /*connection_id=*/GetPeerInMemoryConnectionId(42)), | 85 /*connection_id=*/GetPeerInMemoryConnectionId(42)), |
86 competing_receiver_(&simulator_, | 86 competing_receiver_(&simulator_, |
87 "Competing receiver", | 87 "Competing receiver", |
88 "Competing sender", | 88 "Competing sender", |
89 Perspective::IS_SERVER, | 89 Perspective::IS_SERVER, |
90 /*connection_id=*/GetPeerInMemoryConnectionId(43)), | 90 /*connection_id=*/GetPeerInMemoryConnectionId(43)), |
91 receiver_multiplexer_("Receiver multiplexer", | 91 receiver_multiplexer_("Receiver multiplexer", |
92 {&receiver_, &competing_receiver_}) { | 92 {&receiver_, &competing_receiver_}) { |
93 // These will be changed by the appropriate tests as necessary. | 93 // These will be changed by the appropriate tests as necessary. |
94 FLAGS_quic_reloadable_flag_quic_bbr_keep_sending_at_recent_rate = false; | |
95 FLAGS_quic_reloadable_flag_quic_bbr_slow_recent_delivery = false; | 94 FLAGS_quic_reloadable_flag_quic_bbr_slow_recent_delivery = false; |
96 FLAGS_quic_reloadable_flag_quic_bbr_add_tso_cwnd = false; | 95 FLAGS_quic_reloadable_flag_quic_bbr_add_tso_cwnd = false; |
97 // TODO(ianswett): Determine why tests become flaky with CWND based on SRTT. | 96 // TODO(ianswett): Determine why tests become flaky with CWND based on SRTT. |
98 FLAGS_quic_reloadable_flag_quic_bbr_base_cwnd_on_srtt = false; | 97 FLAGS_quic_reloadable_flag_quic_bbr_base_cwnd_on_srtt = false; |
99 FLAGS_quic_reloadable_flag_quic_bbr_extra_conservation = true; | 98 FLAGS_quic_reloadable_flag_quic_bbr_extra_conservation = true; |
100 FLAGS_quic_reloadable_flag_quic_bbr_fix_conservation = true; | 99 FLAGS_quic_reloadable_flag_quic_bbr_fix_conservation2 = true; |
101 rtt_stats_ = bbr_sender_.connection()->sent_packet_manager().GetRttStats(); | 100 rtt_stats_ = bbr_sender_.connection()->sent_packet_manager().GetRttStats(); |
102 sender_ = SetupBbrSender(&bbr_sender_); | 101 sender_ = SetupBbrSender(&bbr_sender_); |
103 | 102 |
104 clock_ = simulator_.GetClock(); | 103 clock_ = simulator_.GetClock(); |
105 simulator_.set_random_generator(&random_); | 104 simulator_.set_random_generator(&random_); |
106 | 105 |
107 uint64_t seed = QuicRandom::GetInstance()->RandUint64(); | 106 uint64_t seed = QuicRandom::GetInstance()->RandUint64(); |
108 random_.set_seed(seed); | 107 random_.set_seed(seed); |
109 QUIC_LOG(INFO) << "BbrSenderTest simulator set up. Seed: " << seed; | 108 QUIC_LOG(INFO) << "BbrSenderTest simulator set up. Seed: " << seed; |
110 } | 109 } |
(...skipping 204 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
315 sender_->ExportDebugState().max_bandwidth); | 314 sender_->ExportDebugState().max_bandwidth); |
316 // TODO(ianswett): Expect 0 packets are lost once BBR no longer measures | 315 // TODO(ianswett): Expect 0 packets are lost once BBR no longer measures |
317 // bandwidth higher than the link rate. | 316 // bandwidth higher than the link rate. |
318 EXPECT_FALSE(sender_->ExportDebugState().last_sample_is_app_limited); | 317 EXPECT_FALSE(sender_->ExportDebugState().last_sample_is_app_limited); |
319 // The margin here is high, because the aggregation greatly increases | 318 // The margin here is high, because the aggregation greatly increases |
320 // smoothed rtt. | 319 // smoothed rtt. |
321 EXPECT_GE(kTestRtt * 4, rtt_stats_->smoothed_rtt()); | 320 EXPECT_GE(kTestRtt * 4, rtt_stats_->smoothed_rtt()); |
322 ExpectApproxEq(kTestRtt, rtt_stats_->min_rtt(), 0.12f); | 321 ExpectApproxEq(kTestRtt, rtt_stats_->min_rtt(), 0.12f); |
323 } | 322 } |
324 | 323 |
325 TEST_F(BbrSenderTest, SimpleTransfer2RTTAggregationKeepSending) { | |
326 FLAGS_quic_reloadable_flag_quic_bbr_ack_aggregation_bytes = false; | |
327 FLAGS_quic_reloadable_flag_quic_bbr_add_tso_cwnd = false; | |
328 FLAGS_quic_reloadable_flag_quic_bbr_keep_sending_at_recent_rate = true; | |
329 CreateDefaultSetup(); | |
330 // 2 RTTs of aggregation, with a max of 10kb. | |
331 EnableAggregation(10 * 1024, 2 * kTestRtt); | |
332 | |
333 // Transfer 12MB. | |
334 DoSimpleTransfer(12 * 1024 * 1024, QuicTime::Delta::FromSeconds(35)); | |
335 EXPECT_EQ(BbrSender::PROBE_BW, sender_->ExportDebugState().mode); | |
336 // It's possible to read a bandwidth as much as 50% too high with aggregation. | |
337 EXPECT_LE(kTestLinkBandwidth * 0.95f, | |
338 sender_->ExportDebugState().max_bandwidth); | |
339 // TODO(ianswett): Tighten this bound once we understand why BBR is | |
340 // overestimating bandwidth with aggregation. b/36022633 | |
341 EXPECT_GE(kTestLinkBandwidth * 1.5f, | |
342 sender_->ExportDebugState().max_bandwidth); | |
343 // TODO(ianswett): Expect 0 packets are lost once BBR no longer measures | |
344 // bandwidth higher than the link rate. | |
345 // TODO(vasilvv): figure out why the line below is occasionally flaky. | |
346 // EXPECT_FALSE(sender_->ExportDebugState().last_sample_is_app_limited); | |
347 // The margin here is high, because the aggregation greatly increases | |
348 // smoothed rtt. | |
349 EXPECT_GE(kTestRtt * 4.5, rtt_stats_->smoothed_rtt()); | |
350 ExpectApproxEq(kTestRtt, rtt_stats_->min_rtt(), 0.1f); | |
351 } | |
352 | |
353 // Test a simple long data transfer with 2 rtts of aggregation. | 324 // Test a simple long data transfer with 2 rtts of aggregation. |
354 TEST_F(BbrSenderTest, SimpleTransferAckDecimation) { | 325 TEST_F(BbrSenderTest, SimpleTransferAckDecimation) { |
355 FLAGS_quic_reloadable_flag_quic_bbr_ack_aggregation_bytes = true; | 326 FLAGS_quic_reloadable_flag_quic_bbr_ack_aggregation_bytes = true; |
356 // Decrease the CWND gain so extra CWND is required with stretch acks. | 327 // Decrease the CWND gain so extra CWND is required with stretch acks. |
357 FLAGS_quic_bbr_cwnd_gain = 1.0; | 328 FLAGS_quic_bbr_cwnd_gain = 1.0; |
358 sender_ = new BbrSender( | 329 sender_ = new BbrSender( |
359 rtt_stats_, | 330 rtt_stats_, |
360 QuicSentPacketManagerPeer::GetUnackedPacketMap( | 331 QuicSentPacketManagerPeer::GetUnackedPacketMap( |
361 QuicConnectionPeer::GetSentPacketManager(bbr_sender_.connection())), | 332 QuicConnectionPeer::GetSentPacketManager(bbr_sender_.connection())), |
362 kInitialCongestionWindowPackets, kDefaultMaxCongestionWindowPackets, | 333 kInitialCongestionWindowPackets, kDefaultMaxCongestionWindowPackets, |
(...skipping 16 matching lines...) Expand all Loading... |
379 sender_->ExportDebugState().max_bandwidth); | 350 sender_->ExportDebugState().max_bandwidth); |
380 // TODO(ianswett): Expect 0 packets are lost once BBR no longer measures | 351 // TODO(ianswett): Expect 0 packets are lost once BBR no longer measures |
381 // bandwidth higher than the link rate. | 352 // bandwidth higher than the link rate. |
382 EXPECT_FALSE(sender_->ExportDebugState().last_sample_is_app_limited); | 353 EXPECT_FALSE(sender_->ExportDebugState().last_sample_is_app_limited); |
383 // The margin here is high, because the aggregation greatly increases | 354 // The margin here is high, because the aggregation greatly increases |
384 // smoothed rtt. | 355 // smoothed rtt. |
385 EXPECT_GE(kTestRtt * 2, rtt_stats_->smoothed_rtt()); | 356 EXPECT_GE(kTestRtt * 2, rtt_stats_->smoothed_rtt()); |
386 ExpectApproxEq(kTestRtt, rtt_stats_->min_rtt(), 0.1f); | 357 ExpectApproxEq(kTestRtt, rtt_stats_->min_rtt(), 0.1f); |
387 } | 358 } |
388 | 359 |
389 TEST_F(BbrSenderTest, SimpleTransferAckDecimationKeepSending) { | |
390 FLAGS_quic_reloadable_flag_quic_bbr_ack_aggregation_bytes = false; | |
391 FLAGS_quic_reloadable_flag_quic_bbr_add_tso_cwnd = true; | |
392 FLAGS_quic_reloadable_flag_quic_bbr_keep_sending_at_recent_rate = true; | |
393 // Decrease the CWND gain so extra CWND is required with stretch acks. | |
394 FLAGS_quic_bbr_cwnd_gain = 1.0; | |
395 sender_ = new BbrSender( | |
396 rtt_stats_, | |
397 QuicSentPacketManagerPeer::GetUnackedPacketMap( | |
398 QuicConnectionPeer::GetSentPacketManager(bbr_sender_.connection())), | |
399 kInitialCongestionWindowPackets, kDefaultMaxCongestionWindowPackets, | |
400 &random_); | |
401 QuicConnectionPeer::SetSendAlgorithm(bbr_sender_.connection(), sender_); | |
402 // Enable Ack Decimation on the receiver. | |
403 QuicConnectionPeer::SetAckMode(receiver_.connection(), | |
404 QuicConnection::AckMode::ACK_DECIMATION); | |
405 CreateDefaultSetup(); | |
406 | |
407 // Transfer 12MB. | |
408 DoSimpleTransfer(12 * 1024 * 1024, QuicTime::Delta::FromSeconds(35)); | |
409 EXPECT_EQ(BbrSender::PROBE_BW, sender_->ExportDebugState().mode); | |
410 // It's possible to read a bandwidth as much as 50% too high with aggregation. | |
411 EXPECT_LE(kTestLinkBandwidth * 0.95f, | |
412 sender_->ExportDebugState().max_bandwidth); | |
413 // TODO(ianswett): Tighten this bound once we understand why BBR is | |
414 // overestimating bandwidth with aggregation. b/36022633 | |
415 EXPECT_GE(kTestLinkBandwidth * 1.5f, | |
416 sender_->ExportDebugState().max_bandwidth); | |
417 // TODO(ianswett): Expect 0 packets are lost once BBR no longer measures | |
418 // bandwidth higher than the link rate. | |
419 EXPECT_FALSE(sender_->ExportDebugState().last_sample_is_app_limited); | |
420 // The margin here is high, because the aggregation greatly increases | |
421 // smoothed rtt. | |
422 EXPECT_GE(kTestRtt * 2, rtt_stats_->smoothed_rtt()); | |
423 ExpectApproxEq(kTestRtt, rtt_stats_->min_rtt(), 0.1f); | |
424 } | |
425 | |
426 // Test a simple long data transfer with 2 rtts of aggregation. | 360 // Test a simple long data transfer with 2 rtts of aggregation. |
427 TEST_F(BbrSenderTest, | 361 TEST_F(BbrSenderTest, |
428 SimpleTransfer2RTTAggregationBytesWithIncreasedInflightLimit) { | 362 SimpleTransfer2RTTAggregationBytesWithIncreasedInflightLimit) { |
429 FLAGS_quic_reloadable_flag_quic_bbr_ack_aggregation_bytes = false; | 363 FLAGS_quic_reloadable_flag_quic_bbr_ack_aggregation_bytes = false; |
430 FLAGS_quic_reloadable_flag_quic_bbr_add_tso_cwnd = false; | 364 FLAGS_quic_reloadable_flag_quic_bbr_add_tso_cwnd = false; |
431 FLAGS_quic_reloadable_flag_quic_bbr_keep_sending_at_recent_rate = false; | |
432 FLAGS_quic_reloadable_flag_quic_bbr_slow_recent_delivery = true; | 365 FLAGS_quic_reloadable_flag_quic_bbr_slow_recent_delivery = true; |
433 FLAGS_quic_bbr_slow_delivery_threshold_multiplier = 0.5; | 366 FLAGS_quic_bbr_slow_delivery_threshold_multiplier = 0.5; |
434 FLAGS_quic_bbr_slow_delivery_cwnd_gain = 4.0; | 367 FLAGS_quic_bbr_slow_delivery_cwnd_gain = 4.0; |
435 CreateDefaultSetup(); | 368 CreateDefaultSetup(); |
436 // 2 RTTs of aggregation, with a max of 10kb. | 369 // 2 RTTs of aggregation, with a max of 10kb. |
437 EnableAggregation(10 * 1024, 2 * kTestRtt); | 370 EnableAggregation(10 * 1024, 2 * kTestRtt); |
438 | 371 |
439 // Transfer 12MB. | 372 // Transfer 12MB. |
440 DoSimpleTransfer(12 * 1024 * 1024, QuicTime::Delta::FromSeconds(35)); | 373 DoSimpleTransfer(12 * 1024 * 1024, QuicTime::Delta::FromSeconds(35)); |
441 EXPECT_EQ(BbrSender::PROBE_BW, sender_->ExportDebugState().mode); | 374 EXPECT_EQ(BbrSender::PROBE_BW, sender_->ExportDebugState().mode); |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
487 simulator_result = simulator_.RunUntilOrTimeout( | 420 simulator_result = simulator_.RunUntilOrTimeout( |
488 [this]() { | 421 [this]() { |
489 return sender_->ExportDebugState().recovery_state != | 422 return sender_->ExportDebugState().recovery_state != |
490 BbrSender::NOT_IN_RECOVERY; | 423 BbrSender::NOT_IN_RECOVERY; |
491 }, | 424 }, |
492 timeout); | 425 timeout); |
493 ASSERT_TRUE(simulator_result); | 426 ASSERT_TRUE(simulator_result); |
494 ASSERT_EQ(BbrSender::CONSERVATION, | 427 ASSERT_EQ(BbrSender::CONSERVATION, |
495 sender_->ExportDebugState().recovery_state); | 428 sender_->ExportDebugState().recovery_state); |
496 | 429 |
497 const QuicByteCount cwnd_at_recovery_start = sender_->GetCongestionWindow(); | |
498 simulator_result = simulator_.RunUntilOrTimeout( | 430 simulator_result = simulator_.RunUntilOrTimeout( |
499 [this, cwnd_at_recovery_start]() { | 431 [this]() { |
500 // Ensure that the CWND never drops due to conservation. | |
501 if (sender_->GetCongestionWindow() < cwnd_at_recovery_start) { | |
502 return true; | |
503 } | |
504 return sender_->ExportDebugState().recovery_state != | 432 return sender_->ExportDebugState().recovery_state != |
505 BbrSender::CONSERVATION; | 433 BbrSender::CONSERVATION; |
506 }, | 434 }, |
507 timeout); | 435 timeout); |
508 ASSERT_GE(sender_->GetCongestionWindow(), cwnd_at_recovery_start); | |
509 ASSERT_TRUE(simulator_result); | 436 ASSERT_TRUE(simulator_result); |
510 ASSERT_EQ(BbrSender::GROWTH, sender_->ExportDebugState().recovery_state); | 437 ASSERT_EQ(BbrSender::GROWTH, sender_->ExportDebugState().recovery_state); |
511 | 438 |
512 simulator_result = simulator_.RunUntilOrTimeout( | 439 simulator_result = simulator_.RunUntilOrTimeout( |
513 [this]() { | 440 [this]() { |
514 return sender_->ExportDebugState().recovery_state != BbrSender::GROWTH; | 441 return sender_->ExportDebugState().recovery_state != BbrSender::GROWTH; |
515 }, | 442 }, |
516 timeout); | 443 timeout); |
517 | 444 |
518 ASSERT_EQ(BbrSender::PROBE_BW, sender_->ExportDebugState().mode); | 445 ASSERT_EQ(BbrSender::PROBE_BW, sender_->ExportDebugState().mode); |
(...skipping 299 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
818 sender_->ResumeConnectionState(params, false); | 745 sender_->ResumeConnectionState(params, false); |
819 EXPECT_EQ(kTestLinkBandwidth, sender_->ExportDebugState().max_bandwidth); | 746 EXPECT_EQ(kTestLinkBandwidth, sender_->ExportDebugState().max_bandwidth); |
820 EXPECT_EQ(kTestLinkBandwidth, sender_->BandwidthEstimate()); | 747 EXPECT_EQ(kTestLinkBandwidth, sender_->BandwidthEstimate()); |
821 ExpectApproxEq(kTestRtt, sender_->ExportDebugState().min_rtt, 0.01f); | 748 ExpectApproxEq(kTestRtt, sender_->ExportDebugState().min_rtt, 0.01f); |
822 | 749 |
823 DriveOutOfStartup(); | 750 DriveOutOfStartup(); |
824 } | 751 } |
825 | 752 |
826 } // namespace test | 753 } // namespace test |
827 } // namespace net | 754 } // namespace net |
OLD | NEW |