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; |
94 FLAGS_quic_reloadable_flag_quic_bbr_slow_recent_delivery = false; | 95 FLAGS_quic_reloadable_flag_quic_bbr_slow_recent_delivery = false; |
95 FLAGS_quic_reloadable_flag_quic_bbr_add_tso_cwnd = false; | 96 FLAGS_quic_reloadable_flag_quic_bbr_add_tso_cwnd = false; |
96 // TODO(ianswett): Determine why tests become flaky with CWND based on SRTT. | 97 // TODO(ianswett): Determine why tests become flaky with CWND based on SRTT. |
97 FLAGS_quic_reloadable_flag_quic_bbr_base_cwnd_on_srtt = false; | 98 FLAGS_quic_reloadable_flag_quic_bbr_base_cwnd_on_srtt = false; |
98 FLAGS_quic_reloadable_flag_quic_bbr_extra_conservation = true; | 99 FLAGS_quic_reloadable_flag_quic_bbr_extra_conservation = true; |
99 FLAGS_quic_reloadable_flag_quic_bbr_fix_conservation2 = true; | 100 FLAGS_quic_reloadable_flag_quic_bbr_fix_conservation = true; |
100 rtt_stats_ = bbr_sender_.connection()->sent_packet_manager().GetRttStats(); | 101 rtt_stats_ = bbr_sender_.connection()->sent_packet_manager().GetRttStats(); |
101 sender_ = SetupBbrSender(&bbr_sender_); | 102 sender_ = SetupBbrSender(&bbr_sender_); |
102 | 103 |
103 clock_ = simulator_.GetClock(); | 104 clock_ = simulator_.GetClock(); |
104 simulator_.set_random_generator(&random_); | 105 simulator_.set_random_generator(&random_); |
105 | 106 |
106 uint64_t seed = QuicRandom::GetInstance()->RandUint64(); | 107 uint64_t seed = QuicRandom::GetInstance()->RandUint64(); |
107 random_.set_seed(seed); | 108 random_.set_seed(seed); |
108 QUIC_LOG(INFO) << "BbrSenderTest simulator set up. Seed: " << seed; | 109 QUIC_LOG(INFO) << "BbrSenderTest simulator set up. Seed: " << seed; |
109 } | 110 } |
(...skipping 204 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
314 sender_->ExportDebugState().max_bandwidth); | 315 sender_->ExportDebugState().max_bandwidth); |
315 // TODO(ianswett): Expect 0 packets are lost once BBR no longer measures | 316 // TODO(ianswett): Expect 0 packets are lost once BBR no longer measures |
316 // bandwidth higher than the link rate. | 317 // bandwidth higher than the link rate. |
317 EXPECT_FALSE(sender_->ExportDebugState().last_sample_is_app_limited); | 318 EXPECT_FALSE(sender_->ExportDebugState().last_sample_is_app_limited); |
318 // The margin here is high, because the aggregation greatly increases | 319 // The margin here is high, because the aggregation greatly increases |
319 // smoothed rtt. | 320 // smoothed rtt. |
320 EXPECT_GE(kTestRtt * 4, rtt_stats_->smoothed_rtt()); | 321 EXPECT_GE(kTestRtt * 4, rtt_stats_->smoothed_rtt()); |
321 ExpectApproxEq(kTestRtt, rtt_stats_->min_rtt(), 0.12f); | 322 ExpectApproxEq(kTestRtt, rtt_stats_->min_rtt(), 0.12f); |
322 } | 323 } |
323 | 324 |
| 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 |
324 // Test a simple long data transfer with 2 rtts of aggregation. | 353 // Test a simple long data transfer with 2 rtts of aggregation. |
325 TEST_F(BbrSenderTest, SimpleTransferAckDecimation) { | 354 TEST_F(BbrSenderTest, SimpleTransferAckDecimation) { |
326 FLAGS_quic_reloadable_flag_quic_bbr_ack_aggregation_bytes = true; | 355 FLAGS_quic_reloadable_flag_quic_bbr_ack_aggregation_bytes = true; |
327 // Decrease the CWND gain so extra CWND is required with stretch acks. | 356 // Decrease the CWND gain so extra CWND is required with stretch acks. |
328 FLAGS_quic_bbr_cwnd_gain = 1.0; | 357 FLAGS_quic_bbr_cwnd_gain = 1.0; |
329 sender_ = new BbrSender( | 358 sender_ = new BbrSender( |
330 rtt_stats_, | 359 rtt_stats_, |
331 QuicSentPacketManagerPeer::GetUnackedPacketMap( | 360 QuicSentPacketManagerPeer::GetUnackedPacketMap( |
332 QuicConnectionPeer::GetSentPacketManager(bbr_sender_.connection())), | 361 QuicConnectionPeer::GetSentPacketManager(bbr_sender_.connection())), |
333 kInitialCongestionWindowPackets, kDefaultMaxCongestionWindowPackets, | 362 kInitialCongestionWindowPackets, kDefaultMaxCongestionWindowPackets, |
(...skipping 16 matching lines...) Expand all Loading... |
350 sender_->ExportDebugState().max_bandwidth); | 379 sender_->ExportDebugState().max_bandwidth); |
351 // TODO(ianswett): Expect 0 packets are lost once BBR no longer measures | 380 // TODO(ianswett): Expect 0 packets are lost once BBR no longer measures |
352 // bandwidth higher than the link rate. | 381 // bandwidth higher than the link rate. |
353 EXPECT_FALSE(sender_->ExportDebugState().last_sample_is_app_limited); | 382 EXPECT_FALSE(sender_->ExportDebugState().last_sample_is_app_limited); |
354 // The margin here is high, because the aggregation greatly increases | 383 // The margin here is high, because the aggregation greatly increases |
355 // smoothed rtt. | 384 // smoothed rtt. |
356 EXPECT_GE(kTestRtt * 2, rtt_stats_->smoothed_rtt()); | 385 EXPECT_GE(kTestRtt * 2, rtt_stats_->smoothed_rtt()); |
357 ExpectApproxEq(kTestRtt, rtt_stats_->min_rtt(), 0.1f); | 386 ExpectApproxEq(kTestRtt, rtt_stats_->min_rtt(), 0.1f); |
358 } | 387 } |
359 | 388 |
| 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 |
360 // Test a simple long data transfer with 2 rtts of aggregation. | 426 // Test a simple long data transfer with 2 rtts of aggregation. |
361 TEST_F(BbrSenderTest, | 427 TEST_F(BbrSenderTest, |
362 SimpleTransfer2RTTAggregationBytesWithIncreasedInflightLimit) { | 428 SimpleTransfer2RTTAggregationBytesWithIncreasedInflightLimit) { |
363 FLAGS_quic_reloadable_flag_quic_bbr_ack_aggregation_bytes = false; | 429 FLAGS_quic_reloadable_flag_quic_bbr_ack_aggregation_bytes = false; |
364 FLAGS_quic_reloadable_flag_quic_bbr_add_tso_cwnd = false; | 430 FLAGS_quic_reloadable_flag_quic_bbr_add_tso_cwnd = false; |
| 431 FLAGS_quic_reloadable_flag_quic_bbr_keep_sending_at_recent_rate = false; |
365 FLAGS_quic_reloadable_flag_quic_bbr_slow_recent_delivery = true; | 432 FLAGS_quic_reloadable_flag_quic_bbr_slow_recent_delivery = true; |
366 FLAGS_quic_bbr_slow_delivery_threshold_multiplier = 0.5; | 433 FLAGS_quic_bbr_slow_delivery_threshold_multiplier = 0.5; |
367 FLAGS_quic_bbr_slow_delivery_cwnd_gain = 4.0; | 434 FLAGS_quic_bbr_slow_delivery_cwnd_gain = 4.0; |
368 CreateDefaultSetup(); | 435 CreateDefaultSetup(); |
369 // 2 RTTs of aggregation, with a max of 10kb. | 436 // 2 RTTs of aggregation, with a max of 10kb. |
370 EnableAggregation(10 * 1024, 2 * kTestRtt); | 437 EnableAggregation(10 * 1024, 2 * kTestRtt); |
371 | 438 |
372 // Transfer 12MB. | 439 // Transfer 12MB. |
373 DoSimpleTransfer(12 * 1024 * 1024, QuicTime::Delta::FromSeconds(35)); | 440 DoSimpleTransfer(12 * 1024 * 1024, QuicTime::Delta::FromSeconds(35)); |
374 EXPECT_EQ(BbrSender::PROBE_BW, sender_->ExportDebugState().mode); | 441 EXPECT_EQ(BbrSender::PROBE_BW, sender_->ExportDebugState().mode); |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
420 simulator_result = simulator_.RunUntilOrTimeout( | 487 simulator_result = simulator_.RunUntilOrTimeout( |
421 [this]() { | 488 [this]() { |
422 return sender_->ExportDebugState().recovery_state != | 489 return sender_->ExportDebugState().recovery_state != |
423 BbrSender::NOT_IN_RECOVERY; | 490 BbrSender::NOT_IN_RECOVERY; |
424 }, | 491 }, |
425 timeout); | 492 timeout); |
426 ASSERT_TRUE(simulator_result); | 493 ASSERT_TRUE(simulator_result); |
427 ASSERT_EQ(BbrSender::CONSERVATION, | 494 ASSERT_EQ(BbrSender::CONSERVATION, |
428 sender_->ExportDebugState().recovery_state); | 495 sender_->ExportDebugState().recovery_state); |
429 | 496 |
| 497 const QuicByteCount cwnd_at_recovery_start = sender_->GetCongestionWindow(); |
430 simulator_result = simulator_.RunUntilOrTimeout( | 498 simulator_result = simulator_.RunUntilOrTimeout( |
431 [this]() { | 499 [this, cwnd_at_recovery_start]() { |
| 500 // Ensure that the CWND never drops due to conservation. |
| 501 if (sender_->GetCongestionWindow() < cwnd_at_recovery_start) { |
| 502 return true; |
| 503 } |
432 return sender_->ExportDebugState().recovery_state != | 504 return sender_->ExportDebugState().recovery_state != |
433 BbrSender::CONSERVATION; | 505 BbrSender::CONSERVATION; |
434 }, | 506 }, |
435 timeout); | 507 timeout); |
| 508 ASSERT_GE(sender_->GetCongestionWindow(), cwnd_at_recovery_start); |
436 ASSERT_TRUE(simulator_result); | 509 ASSERT_TRUE(simulator_result); |
437 ASSERT_EQ(BbrSender::GROWTH, sender_->ExportDebugState().recovery_state); | 510 ASSERT_EQ(BbrSender::GROWTH, sender_->ExportDebugState().recovery_state); |
438 | 511 |
439 simulator_result = simulator_.RunUntilOrTimeout( | 512 simulator_result = simulator_.RunUntilOrTimeout( |
440 [this]() { | 513 [this]() { |
441 return sender_->ExportDebugState().recovery_state != BbrSender::GROWTH; | 514 return sender_->ExportDebugState().recovery_state != BbrSender::GROWTH; |
442 }, | 515 }, |
443 timeout); | 516 timeout); |
444 | 517 |
445 ASSERT_EQ(BbrSender::PROBE_BW, sender_->ExportDebugState().mode); | 518 ASSERT_EQ(BbrSender::PROBE_BW, sender_->ExportDebugState().mode); |
(...skipping 299 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
745 sender_->ResumeConnectionState(params, false); | 818 sender_->ResumeConnectionState(params, false); |
746 EXPECT_EQ(kTestLinkBandwidth, sender_->ExportDebugState().max_bandwidth); | 819 EXPECT_EQ(kTestLinkBandwidth, sender_->ExportDebugState().max_bandwidth); |
747 EXPECT_EQ(kTestLinkBandwidth, sender_->BandwidthEstimate()); | 820 EXPECT_EQ(kTestLinkBandwidth, sender_->BandwidthEstimate()); |
748 ExpectApproxEq(kTestRtt, sender_->ExportDebugState().min_rtt, 0.01f); | 821 ExpectApproxEq(kTestRtt, sender_->ExportDebugState().min_rtt, 0.01f); |
749 | 822 |
750 DriveOutOfStartup(); | 823 DriveOutOfStartup(); |
751 } | 824 } |
752 | 825 |
753 } // namespace test | 826 } // namespace test |
754 } // namespace net | 827 } // namespace net |
OLD | NEW |