1 // Copyright 2019 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.
4
5 #include <memory>
6 #include <optional>
7 #include <sstream>
8 #include <utility>
9
10 #include "absl/strings/str_cat.h"
11 #include "quiche/quic/core/congestion_control/bbr2_misc.h"
12 #include "quiche/quic/core/congestion_control/bbr2_sender.h"
13 #include "quiche/quic/core/congestion_control/bbr_sender.h"
14 #include "quiche/quic/core/congestion_control/tcp_cubic_sender_bytes.h"
15 #include "quiche/quic/core/quic_bandwidth.h"
16 #include "quiche/quic/core/quic_packet_number.h"
17 #include "quiche/quic/core/quic_types.h"
18 #include "quiche/quic/platform/api/quic_expect_bug.h"
19 #include "quiche/quic/platform/api/quic_flags.h"
20 #include "quiche/quic/platform/api/quic_logging.h"
21 #include "quiche/quic/platform/api/quic_test.h"
22 #include "quiche/quic/test_tools/quic_config_peer.h"
23 #include "quiche/quic/test_tools/quic_connection_peer.h"
24 #include "quiche/quic/test_tools/quic_sent_packet_manager_peer.h"
25 #include "quiche/quic/test_tools/quic_test_utils.h"
26 #include "quiche/quic/test_tools/send_algorithm_test_result.pb.h"
27 #include "quiche/quic/test_tools/send_algorithm_test_utils.h"
28 #include "quiche/quic/test_tools/simulator/link.h"
29 #include "quiche/quic/test_tools/simulator/quic_endpoint.h"
30 #include "quiche/quic/test_tools/simulator/simulator.h"
31 #include "quiche/quic/test_tools/simulator/switch.h"
32 #include "quiche/quic/test_tools/simulator/traffic_policer.h"
33 #include "quiche/common/platform/api/quiche_command_line_flags.h"
34
35 using testing::AllOf;
36 using testing::Ge;
37 using testing::Le;
38
39 DEFINE_QUICHE_COMMAND_LINE_FLAG(
40 std::string, quic_bbr2_test_regression_mode, "",
41 "One of a) 'record' to record test result (one file per test), or "
42 "b) 'regress' to regress against recorded results, or "
43 "c) <anything else> for non-regression mode.");
44
45 namespace quic {
46
47 using CyclePhase = Bbr2ProbeBwMode::CyclePhase;
48
49 namespace test {
50
51 // Use the initial CWND of 10, as 32 is too much for the test network.
52 const uint32_t kDefaultInitialCwndPackets = 10;
53 const uint32_t kDefaultInitialCwndBytes =
54 kDefaultInitialCwndPackets * kDefaultTCPMSS;
55
56 struct LinkParams {
LinkParamsquic::test::LinkParams57 LinkParams(int64_t kilo_bits_per_sec, int64_t delay_us)
58 : bandwidth(QuicBandwidth::FromKBitsPerSecond(kilo_bits_per_sec)),
59 delay(QuicTime::Delta::FromMicroseconds(delay_us)) {}
60 QuicBandwidth bandwidth;
61 QuicTime::Delta delay;
62 };
63
64 struct TrafficPolicerParams {
65 std::string name = "policer";
66 QuicByteCount initial_burst_size;
67 QuicByteCount max_bucket_size;
68 QuicBandwidth target_bandwidth = QuicBandwidth::Zero();
69 };
70
71 // All Bbr2DefaultTopologyTests uses the default network topology:
72 //
73 // Sender
74 // |
75 // | <-- local_link
76 // |
77 // Network switch
78 // * <-- the bottleneck queue in the direction
79 // | of the receiver
80 // |
81 // | <-- test_link
82 // |
83 // |
84 // Receiver
85 class DefaultTopologyParams {
86 public:
87 LinkParams local_link = {10000, 2000};
88 LinkParams test_link = {4000, 30000};
89
90 const simulator::SwitchPortNumber switch_port_count = 2;
91 // Network switch queue capacity, in number of BDPs.
92 float switch_queue_capacity_in_bdp = 2;
93
94 std::optional<TrafficPolicerParams> sender_policer_params;
95
BottleneckBandwidth() const96 QuicBandwidth BottleneckBandwidth() const {
97 return std::min(local_link.bandwidth, test_link.bandwidth);
98 }
99
100 // Round trip time of a single full size packet.
RTT() const101 QuicTime::Delta RTT() const {
102 return 2 * (local_link.delay + test_link.delay +
103 local_link.bandwidth.TransferTime(kMaxOutgoingPacketSize) +
104 test_link.bandwidth.TransferTime(kMaxOutgoingPacketSize));
105 }
106
BDP() const107 QuicByteCount BDP() const { return BottleneckBandwidth() * RTT(); }
108
SwitchQueueCapacity() const109 QuicByteCount SwitchQueueCapacity() const {
110 return switch_queue_capacity_in_bdp * BDP();
111 }
112
ToString() const113 std::string ToString() const {
114 std::ostringstream os;
115 os << "{ BottleneckBandwidth: " << BottleneckBandwidth()
116 << " RTT: " << RTT() << " BDP: " << BDP()
117 << " BottleneckQueueSize: " << SwitchQueueCapacity() << "}";
118 return os.str();
119 }
120 };
121
122 class Bbr2SimulatorTest : public QuicTest {
123 protected:
Bbr2SimulatorTest()124 Bbr2SimulatorTest() : simulator_(&random_) {
125 // Prevent the server(receiver), which only sends acks, from closing
126 // connection due to too many outstanding packets.
127 SetQuicFlag(quic_max_tracked_packet_count, 1000000);
128 }
129
SetUp()130 void SetUp() override {
131 if (quiche::GetQuicheCommandLineFlag(
132 FLAGS_quic_bbr2_test_regression_mode) == "regress") {
133 SendAlgorithmTestResult expected;
134 ASSERT_TRUE(LoadSendAlgorithmTestResult(&expected));
135 random_seed_ = expected.random_seed();
136 } else {
137 random_seed_ = QuicRandom::GetInstance()->RandUint64();
138 }
139 random_.set_seed(random_seed_);
140 QUIC_LOG(INFO) << "Using random seed: " << random_seed_;
141 }
142
~Bbr2SimulatorTest()143 ~Bbr2SimulatorTest() override {
144 const std::string regression_mode =
145 quiche::GetQuicheCommandLineFlag(FLAGS_quic_bbr2_test_regression_mode);
146 const QuicTime::Delta simulated_duration =
147 SimulatedNow() - QuicTime::Zero();
148 if (regression_mode == "record") {
149 RecordSendAlgorithmTestResult(random_seed_,
150 simulated_duration.ToMicroseconds());
151 } else if (regression_mode == "regress") {
152 CompareSendAlgorithmTestResult(simulated_duration.ToMicroseconds());
153 }
154 }
155
SimulatedNow() const156 QuicTime SimulatedNow() const { return simulator_.GetClock()->Now(); }
157
158 uint64_t random_seed_;
159 SimpleRandom random_;
160 simulator::Simulator simulator_;
161 };
162
163 class Bbr2DefaultTopologyTest : public Bbr2SimulatorTest {
164 protected:
Bbr2DefaultTopologyTest()165 Bbr2DefaultTopologyTest()
166 : sender_endpoint_(&simulator_, "Sender", "Receiver",
167 Perspective::IS_CLIENT, TestConnectionId(42)),
168 receiver_endpoint_(&simulator_, "Receiver", "Sender",
169 Perspective::IS_SERVER, TestConnectionId(42)) {
170 sender_ = SetupBbr2Sender(&sender_endpoint_, /*old_sender=*/nullptr);
171 }
172
~Bbr2DefaultTopologyTest()173 ~Bbr2DefaultTopologyTest() {
174 const auto* test_info =
175 ::testing::UnitTest::GetInstance()->current_test_info();
176 const Bbr2Sender::DebugState& debug_state = sender_->ExportDebugState();
177 QUIC_LOG(INFO) << "Bbr2DefaultTopologyTest." << test_info->name()
178 << " completed at simulated time: "
179 << SimulatedNow().ToDebuggingValue() / 1e6
180 << " sec. packet loss:"
181 << sender_loss_rate_in_packets() * 100
182 << "%, bw_hi:" << debug_state.bandwidth_hi;
183 }
184
GetUnackedMap(QuicConnection * connection)185 QuicUnackedPacketMap* GetUnackedMap(QuicConnection* connection) {
186 return QuicSentPacketManagerPeer::GetUnackedPacketMap(
187 QuicConnectionPeer::GetSentPacketManager(connection));
188 }
189
SetupBbr2Sender(simulator::QuicEndpoint * endpoint,BbrSender * old_sender)190 Bbr2Sender* SetupBbr2Sender(simulator::QuicEndpoint* endpoint,
191 BbrSender* old_sender) {
192 // Ownership of the sender will be overtaken by the endpoint.
193 Bbr2Sender* sender = new Bbr2Sender(
194 endpoint->connection()->clock()->Now(),
195 endpoint->connection()->sent_packet_manager().GetRttStats(),
196 GetUnackedMap(endpoint->connection()), kDefaultInitialCwndPackets,
197 GetQuicFlag(quic_max_congestion_window), &random_,
198 QuicConnectionPeer::GetStats(endpoint->connection()), old_sender);
199 QuicConnectionPeer::SetSendAlgorithm(endpoint->connection(), sender);
200 const int kTestMaxPacketSize = 1350;
201 endpoint->connection()->SetMaxPacketLength(kTestMaxPacketSize);
202 endpoint->RecordTrace();
203 return sender;
204 }
205
CreateNetwork(const DefaultTopologyParams & params)206 void CreateNetwork(const DefaultTopologyParams& params) {
207 QUIC_LOG(INFO) << "CreateNetwork with parameters: " << params.ToString();
208 switch_ = std::make_unique<simulator::Switch>(&simulator_, "Switch",
209 params.switch_port_count,
210 params.SwitchQueueCapacity());
211
212 // WARNING: The order to add links to network_links_ matters, because some
213 // tests adjusts the link bandwidth on the fly.
214
215 // Local link connects sender and port 1.
216 network_links_.push_back(std::make_unique<simulator::SymmetricLink>(
217 &sender_endpoint_, switch_->port(1), params.local_link.bandwidth,
218 params.local_link.delay));
219
220 // Test link connects receiver and port 2.
221 if (params.sender_policer_params.has_value()) {
222 const TrafficPolicerParams& policer_params =
223 params.sender_policer_params.value();
224 sender_policer_ = std::make_unique<simulator::TrafficPolicer>(
225 &simulator_, policer_params.name, policer_params.initial_burst_size,
226 policer_params.max_bucket_size, policer_params.target_bandwidth,
227 switch_->port(2));
228 network_links_.push_back(std::make_unique<simulator::SymmetricLink>(
229 &receiver_endpoint_, sender_policer_.get(),
230 params.test_link.bandwidth, params.test_link.delay));
231 } else {
232 network_links_.push_back(std::make_unique<simulator::SymmetricLink>(
233 &receiver_endpoint_, switch_->port(2), params.test_link.bandwidth,
234 params.test_link.delay));
235 }
236 }
237
TestLink()238 simulator::SymmetricLink* TestLink() { return network_links_[1].get(); }
239
DoSimpleTransfer(QuicByteCount transfer_size,QuicTime::Delta timeout)240 void DoSimpleTransfer(QuicByteCount transfer_size, QuicTime::Delta timeout) {
241 sender_endpoint_.AddBytesToTransfer(transfer_size);
242 // TODO(wub): consider rewriting this to run until the receiver actually
243 // receives the intended amount of bytes.
244 bool simulator_result = simulator_.RunUntilOrTimeout(
245 [this]() { return sender_endpoint_.bytes_to_transfer() == 0; },
246 timeout);
247 EXPECT_TRUE(simulator_result)
248 << "Simple transfer failed. Bytes remaining: "
249 << sender_endpoint_.bytes_to_transfer();
250 QUIC_LOG(INFO) << "Simple transfer state: " << sender_->ExportDebugState();
251 }
252
253 // Drive the simulator by sending enough data to enter PROBE_BW.
DriveOutOfStartup(const DefaultTopologyParams & params)254 void DriveOutOfStartup(const DefaultTopologyParams& params) {
255 ASSERT_FALSE(sender_->ExportDebugState().startup.full_bandwidth_reached);
256 DoSimpleTransfer(1024 * 1024, QuicTime::Delta::FromSeconds(15));
257 EXPECT_EQ(Bbr2Mode::PROBE_BW, sender_->ExportDebugState().mode);
258 EXPECT_APPROX_EQ(params.BottleneckBandwidth(),
259 sender_->ExportDebugState().bandwidth_hi, 0.02f);
260 }
261
262 // Send |bytes|-sized bursts of data |number_of_bursts| times, waiting for
263 // |wait_time| between each burst.
SendBursts(const DefaultTopologyParams & params,size_t number_of_bursts,QuicByteCount bytes,QuicTime::Delta wait_time)264 void SendBursts(const DefaultTopologyParams& params, size_t number_of_bursts,
265 QuicByteCount bytes, QuicTime::Delta wait_time) {
266 ASSERT_EQ(0u, sender_endpoint_.bytes_to_transfer());
267 for (size_t i = 0; i < number_of_bursts; i++) {
268 sender_endpoint_.AddBytesToTransfer(bytes);
269
270 // Transfer data and wait for three seconds between each transfer.
271 simulator_.RunFor(wait_time);
272
273 // Ensure the connection did not time out.
274 ASSERT_TRUE(sender_endpoint_.connection()->connected());
275 ASSERT_TRUE(receiver_endpoint_.connection()->connected());
276 }
277
278 simulator_.RunFor(wait_time + params.RTT());
279 ASSERT_EQ(0u, sender_endpoint_.bytes_to_transfer());
280 }
281
282 template <class TerminationPredicate>
SendUntilOrTimeout(TerminationPredicate termination_predicate,QuicTime::Delta timeout)283 bool SendUntilOrTimeout(TerminationPredicate termination_predicate,
284 QuicTime::Delta timeout) {
285 EXPECT_EQ(0u, sender_endpoint_.bytes_to_transfer());
286 const QuicTime deadline = SimulatedNow() + timeout;
287 do {
288 sender_endpoint_.AddBytesToTransfer(4 * kDefaultTCPMSS);
289 if (simulator_.RunUntilOrTimeout(
290 [this]() { return sender_endpoint_.bytes_to_transfer() == 0; },
291 deadline - SimulatedNow()) &&
292 termination_predicate()) {
293 return true;
294 }
295 } while (SimulatedNow() < deadline);
296 return false;
297 }
298
EnableAggregation(QuicByteCount aggregation_bytes,QuicTime::Delta aggregation_timeout)299 void EnableAggregation(QuicByteCount aggregation_bytes,
300 QuicTime::Delta aggregation_timeout) {
301 switch_->port_queue(1)->EnableAggregation(aggregation_bytes,
302 aggregation_timeout);
303 }
304
SetConnectionOption(QuicTag option)305 void SetConnectionOption(QuicTag option) {
306 SetConnectionOption(std::move(option), sender_);
307 }
308
SetConnectionOption(QuicTag option,Bbr2Sender * sender)309 void SetConnectionOption(QuicTag option, Bbr2Sender* sender) {
310 QuicConfig config;
311 QuicTagVector options;
312 options.push_back(option);
313 QuicConfigPeer::SetReceivedConnectionOptions(&config, options);
314 sender->SetFromConfig(config, Perspective::IS_SERVER);
315 }
316
Bbr2ModeIsOneOf(const std::vector<Bbr2Mode> & expected_modes) const317 bool Bbr2ModeIsOneOf(const std::vector<Bbr2Mode>& expected_modes) const {
318 const Bbr2Mode mode = sender_->ExportDebugState().mode;
319 for (Bbr2Mode expected_mode : expected_modes) {
320 if (mode == expected_mode) {
321 return true;
322 }
323 }
324 return false;
325 }
326
rtt_stats()327 const RttStats* rtt_stats() {
328 return sender_endpoint_.connection()->sent_packet_manager().GetRttStats();
329 }
330
sender_connection()331 QuicConnection* sender_connection() { return sender_endpoint_.connection(); }
332
sender_debug_state() const333 Bbr2Sender::DebugState sender_debug_state() const {
334 return sender_->ExportDebugState();
335 }
336
sender_connection_stats()337 const QuicConnectionStats& sender_connection_stats() {
338 return sender_connection()->GetStats();
339 }
340
sender_unacked_map()341 QuicUnackedPacketMap* sender_unacked_map() {
342 return GetUnackedMap(sender_connection());
343 }
344
sender_loss_rate_in_packets()345 float sender_loss_rate_in_packets() {
346 return static_cast<float>(sender_connection_stats().packets_lost) /
347 sender_connection_stats().packets_sent;
348 }
349
350 simulator::QuicEndpoint sender_endpoint_;
351 simulator::QuicEndpoint receiver_endpoint_;
352 Bbr2Sender* sender_;
353
354 std::unique_ptr<simulator::Switch> switch_;
355 std::unique_ptr<simulator::TrafficPolicer> sender_policer_;
356 std::vector<std::unique_ptr<simulator::SymmetricLink>> network_links_;
357 };
358
TEST_F(Bbr2DefaultTopologyTest,NormalStartup)359 TEST_F(Bbr2DefaultTopologyTest, NormalStartup) {
360 DefaultTopologyParams params;
361 CreateNetwork(params);
362
363 // Run until the full bandwidth is reached and check how many rounds it was.
364 sender_endpoint_.AddBytesToTransfer(12 * 1024 * 1024);
365 QuicRoundTripCount max_bw_round = 0;
366 QuicBandwidth max_bw(QuicBandwidth::Zero());
367 bool simulator_result = simulator_.RunUntilOrTimeout(
368 [this, &max_bw, &max_bw_round]() {
369 if (max_bw * 1.001 < sender_->ExportDebugState().bandwidth_hi) {
370 max_bw = sender_->ExportDebugState().bandwidth_hi;
371 max_bw_round = sender_->ExportDebugState().round_trip_count;
372 }
373 return sender_->ExportDebugState().startup.full_bandwidth_reached;
374 },
375 QuicTime::Delta::FromSeconds(5));
376 ASSERT_TRUE(simulator_result);
377 EXPECT_EQ(Bbr2Mode::DRAIN, sender_->ExportDebugState().mode);
378 EXPECT_EQ(3u, sender_->ExportDebugState().round_trip_count - max_bw_round);
379 EXPECT_EQ(
380 3u,
381 sender_->ExportDebugState().startup.round_trips_without_bandwidth_growth);
382 EXPECT_EQ(0u, sender_connection_stats().packets_lost);
383 EXPECT_APPROX_EQ(params.BottleneckBandwidth(),
384 sender_->ExportDebugState().bandwidth_hi, 0.01f);
385 EXPECT_FALSE(sender_->ExportDebugState().last_sample_is_app_limited);
386 }
387
TEST_F(Bbr2DefaultTopologyTest,NormalStartupB207)388 TEST_F(Bbr2DefaultTopologyTest, NormalStartupB207) {
389 SetConnectionOption(kB207);
390 DefaultTopologyParams params;
391 CreateNetwork(params);
392
393 // Run until the full bandwidth is reached and check how many rounds it was.
394 sender_endpoint_.AddBytesToTransfer(12 * 1024 * 1024);
395 QuicRoundTripCount max_bw_round = 0;
396 QuicBandwidth max_bw(QuicBandwidth::Zero());
397 bool simulator_result = simulator_.RunUntilOrTimeout(
398 [this, &max_bw, &max_bw_round]() {
399 if (max_bw < sender_->ExportDebugState().bandwidth_hi) {
400 max_bw = sender_->ExportDebugState().bandwidth_hi;
401 max_bw_round = sender_->ExportDebugState().round_trip_count;
402 }
403 return sender_->ExportDebugState().startup.full_bandwidth_reached;
404 },
405 QuicTime::Delta::FromSeconds(5));
406 ASSERT_TRUE(simulator_result);
407 EXPECT_EQ(Bbr2Mode::DRAIN, sender_->ExportDebugState().mode);
408 EXPECT_EQ(1u, sender_->ExportDebugState().round_trip_count - max_bw_round);
409 EXPECT_EQ(
410 1u,
411 sender_->ExportDebugState().startup.round_trips_without_bandwidth_growth);
412 EXPECT_APPROX_EQ(params.BottleneckBandwidth(),
413 sender_->ExportDebugState().bandwidth_hi, 0.01f);
414 EXPECT_EQ(0u, sender_connection_stats().packets_lost);
415 }
416
417 // Add extra_acked to CWND in STARTUP and exit STARTUP on a persistent queue.
TEST_F(Bbr2DefaultTopologyTest,NormalStartupB207andB205)418 TEST_F(Bbr2DefaultTopologyTest, NormalStartupB207andB205) {
419 SetConnectionOption(kB205);
420 SetConnectionOption(kB207);
421 DefaultTopologyParams params;
422 CreateNetwork(params);
423
424 // Run until the full bandwidth is reached and check how many rounds it was.
425 sender_endpoint_.AddBytesToTransfer(12 * 1024 * 1024);
426 QuicRoundTripCount max_bw_round = 0;
427 QuicBandwidth max_bw(QuicBandwidth::Zero());
428 bool simulator_result = simulator_.RunUntilOrTimeout(
429 [this, &max_bw, &max_bw_round]() {
430 if (max_bw < sender_->ExportDebugState().bandwidth_hi) {
431 max_bw = sender_->ExportDebugState().bandwidth_hi;
432 max_bw_round = sender_->ExportDebugState().round_trip_count;
433 }
434 return sender_->ExportDebugState().startup.full_bandwidth_reached;
435 },
436 QuicTime::Delta::FromSeconds(5));
437 ASSERT_TRUE(simulator_result);
438 EXPECT_EQ(Bbr2Mode::DRAIN, sender_->ExportDebugState().mode);
439 EXPECT_EQ(1u, sender_->ExportDebugState().round_trip_count - max_bw_round);
440 EXPECT_EQ(
441 2u,
442 sender_->ExportDebugState().startup.round_trips_without_bandwidth_growth);
443 EXPECT_APPROX_EQ(params.BottleneckBandwidth(),
444 sender_->ExportDebugState().bandwidth_hi, 0.01f);
445 EXPECT_EQ(0u, sender_connection_stats().packets_lost);
446 }
447
448 // Add extra_acked to CWND in STARTUP and exit STARTUP on a persistent queue.
TEST_F(Bbr2DefaultTopologyTest,NormalStartupBB2S)449 TEST_F(Bbr2DefaultTopologyTest, NormalStartupBB2S) {
450 SetQuicReloadableFlag(quic_bbr2_probe_two_rounds, true);
451 SetConnectionOption(kBB2S);
452 DefaultTopologyParams params;
453 CreateNetwork(params);
454
455 // Run until the full bandwidth is reached and check how many rounds it was.
456 sender_endpoint_.AddBytesToTransfer(12 * 1024 * 1024);
457 QuicRoundTripCount max_bw_round = 0;
458 QuicBandwidth max_bw(QuicBandwidth::Zero());
459 bool simulator_result = simulator_.RunUntilOrTimeout(
460 [this, &max_bw, &max_bw_round]() {
461 if (max_bw * 1.001 < sender_->ExportDebugState().bandwidth_hi) {
462 max_bw = sender_->ExportDebugState().bandwidth_hi;
463 max_bw_round = sender_->ExportDebugState().round_trip_count;
464 }
465 return sender_->ExportDebugState().startup.full_bandwidth_reached;
466 },
467 QuicTime::Delta::FromSeconds(5));
468 ASSERT_TRUE(simulator_result);
469 EXPECT_EQ(Bbr2Mode::DRAIN, sender_->ExportDebugState().mode);
470 // BB2S reduces 3 rounds without bandwidth growth to 2.
471 EXPECT_EQ(2u, sender_->ExportDebugState().round_trip_count - max_bw_round);
472 EXPECT_EQ(
473 2u,
474 sender_->ExportDebugState().startup.round_trips_without_bandwidth_growth);
475 EXPECT_APPROX_EQ(params.BottleneckBandwidth(),
476 sender_->ExportDebugState().bandwidth_hi, 0.01f);
477 EXPECT_EQ(0u, sender_connection_stats().packets_lost);
478 }
479
480 // Test a simple long data transfer in the default setup.
TEST_F(Bbr2DefaultTopologyTest,SimpleTransfer)481 TEST_F(Bbr2DefaultTopologyTest, SimpleTransfer) {
482 DefaultTopologyParams params;
483 CreateNetwork(params);
484
485 // At startup make sure we are at the default.
486 EXPECT_EQ(kDefaultInitialCwndBytes, sender_->GetCongestionWindow());
487 // At startup make sure we can send.
488 EXPECT_TRUE(sender_->CanSend(0));
489 // And that window is un-affected.
490 EXPECT_EQ(kDefaultInitialCwndBytes, sender_->GetCongestionWindow());
491
492 // Verify that Sender is in slow start.
493 EXPECT_TRUE(sender_->InSlowStart());
494
495 // Verify that pacing rate is based on the initial RTT.
496 QuicBandwidth expected_pacing_rate = QuicBandwidth::FromBytesAndTimeDelta(
497 2.885 * kDefaultInitialCwndBytes, rtt_stats()->initial_rtt());
498 EXPECT_APPROX_EQ(expected_pacing_rate.ToBitsPerSecond(),
499 sender_->PacingRate(0).ToBitsPerSecond(), 0.01f);
500
501 ASSERT_GE(params.BDP(), kDefaultInitialCwndBytes + kDefaultTCPMSS);
502
503 DoSimpleTransfer(12 * 1024 * 1024, QuicTime::Delta::FromSeconds(30));
504 EXPECT_TRUE(Bbr2ModeIsOneOf({Bbr2Mode::PROBE_BW, Bbr2Mode::PROBE_RTT}));
505 EXPECT_EQ(0u, sender_connection_stats().packets_lost);
506 EXPECT_FALSE(sender_->ExportDebugState().last_sample_is_app_limited);
507
508 // The margin here is quite high, since there exists a possibility that the
509 // connection just exited high gain cycle.
510 EXPECT_APPROX_EQ(params.RTT(), rtt_stats()->smoothed_rtt(), 1.0f);
511 }
512
TEST_F(Bbr2DefaultTopologyTest,SimpleTransferB2RC)513 TEST_F(Bbr2DefaultTopologyTest, SimpleTransferB2RC) {
514 SetConnectionOption(kB2RC);
515 DefaultTopologyParams params;
516 CreateNetwork(params);
517
518 // Transfer 12MB.
519 DoSimpleTransfer(12 * 1024 * 1024, QuicTime::Delta::FromSeconds(35));
520 EXPECT_TRUE(Bbr2ModeIsOneOf({Bbr2Mode::PROBE_BW, Bbr2Mode::PROBE_RTT}));
521
522 EXPECT_APPROX_EQ(params.BottleneckBandwidth(),
523 sender_->ExportDebugState().bandwidth_hi, 0.01f);
524
525 EXPECT_LE(sender_loss_rate_in_packets(), 0.05);
526 // The margin here is high, because the aggregation greatly increases
527 // smoothed rtt.
528 EXPECT_GE(params.RTT() * 4, rtt_stats()->smoothed_rtt());
529 EXPECT_APPROX_EQ(params.RTT(), rtt_stats()->min_rtt(), 0.2f);
530 }
531
TEST_F(Bbr2DefaultTopologyTest,SimpleTransferB201)532 TEST_F(Bbr2DefaultTopologyTest, SimpleTransferB201) {
533 SetConnectionOption(kB201);
534 DefaultTopologyParams params;
535 CreateNetwork(params);
536
537 // Transfer 12MB.
538 DoSimpleTransfer(12 * 1024 * 1024, QuicTime::Delta::FromSeconds(35));
539 EXPECT_TRUE(Bbr2ModeIsOneOf({Bbr2Mode::PROBE_BW, Bbr2Mode::PROBE_RTT}));
540
541 EXPECT_APPROX_EQ(params.BottleneckBandwidth(),
542 sender_->ExportDebugState().bandwidth_hi, 0.01f);
543
544 EXPECT_LE(sender_loss_rate_in_packets(), 0.05);
545 // The margin here is high, because the aggregation greatly increases
546 // smoothed rtt.
547 EXPECT_GE(params.RTT() * 4, rtt_stats()->smoothed_rtt());
548 EXPECT_APPROX_EQ(params.RTT(), rtt_stats()->min_rtt(), 0.2f);
549 }
550
TEST_F(Bbr2DefaultTopologyTest,SimpleTransferB206)551 TEST_F(Bbr2DefaultTopologyTest, SimpleTransferB206) {
552 SetConnectionOption(kB206);
553 DefaultTopologyParams params;
554 CreateNetwork(params);
555
556 // Transfer 12MB.
557 DoSimpleTransfer(12 * 1024 * 1024, QuicTime::Delta::FromSeconds(35));
558 EXPECT_TRUE(Bbr2ModeIsOneOf({Bbr2Mode::PROBE_BW, Bbr2Mode::PROBE_RTT}));
559
560 EXPECT_APPROX_EQ(params.BottleneckBandwidth(),
561 sender_->ExportDebugState().bandwidth_hi, 0.01f);
562
563 EXPECT_LE(sender_loss_rate_in_packets(), 0.05);
564 // The margin here is high, because the aggregation greatly increases
565 // smoothed rtt.
566 EXPECT_GE(params.RTT() * 4, rtt_stats()->smoothed_rtt());
567 EXPECT_APPROX_EQ(params.RTT(), rtt_stats()->min_rtt(), 0.2f);
568 }
569
TEST_F(Bbr2DefaultTopologyTest,SimpleTransferB207)570 TEST_F(Bbr2DefaultTopologyTest, SimpleTransferB207) {
571 SetConnectionOption(kB207);
572 DefaultTopologyParams params;
573 CreateNetwork(params);
574
575 // Transfer 12MB.
576 DoSimpleTransfer(12 * 1024 * 1024, QuicTime::Delta::FromSeconds(35));
577 EXPECT_TRUE(Bbr2ModeIsOneOf({Bbr2Mode::PROBE_BW, Bbr2Mode::PROBE_RTT}));
578
579 EXPECT_APPROX_EQ(params.BottleneckBandwidth(),
580 sender_->ExportDebugState().bandwidth_hi, 0.01f);
581
582 EXPECT_LE(sender_loss_rate_in_packets(), 0.05);
583 // The margin here is high, because the aggregation greatly increases
584 // smoothed rtt.
585 EXPECT_GE(params.RTT() * 4, rtt_stats()->smoothed_rtt());
586 EXPECT_APPROX_EQ(params.RTT(), rtt_stats()->min_rtt(), 0.2f);
587 }
588
TEST_F(Bbr2DefaultTopologyTest,SimpleTransferBBRB)589 TEST_F(Bbr2DefaultTopologyTest, SimpleTransferBBRB) {
590 SetConnectionOption(kBBRB);
591 DefaultTopologyParams params;
592 CreateNetwork(params);
593
594 // Transfer 12MB.
595 DoSimpleTransfer(12 * 1024 * 1024, QuicTime::Delta::FromSeconds(35));
596 EXPECT_TRUE(Bbr2ModeIsOneOf({Bbr2Mode::PROBE_BW, Bbr2Mode::PROBE_RTT}));
597
598 EXPECT_APPROX_EQ(params.BottleneckBandwidth(),
599 sender_->ExportDebugState().bandwidth_hi, 0.01f);
600
601 EXPECT_LE(sender_loss_rate_in_packets(), 0.05);
602 // The margin here is high, because the aggregation greatly increases
603 // smoothed rtt.
604 EXPECT_GE(params.RTT() * 4, rtt_stats()->smoothed_rtt());
605 EXPECT_APPROX_EQ(params.RTT(), rtt_stats()->min_rtt(), 0.2f);
606 }
607
TEST_F(Bbr2DefaultTopologyTest,SimpleTransferBBR4)608 TEST_F(Bbr2DefaultTopologyTest, SimpleTransferBBR4) {
609 SetQuicReloadableFlag(quic_bbr2_extra_acked_window, true);
610 SetConnectionOption(kBBR4);
611 DefaultTopologyParams params;
612 CreateNetwork(params);
613
614 // Transfer 12MB.
615 DoSimpleTransfer(12 * 1024 * 1024, QuicTime::Delta::FromSeconds(35));
616 EXPECT_TRUE(Bbr2ModeIsOneOf({Bbr2Mode::PROBE_BW, Bbr2Mode::PROBE_RTT}));
617
618 EXPECT_APPROX_EQ(params.BottleneckBandwidth(),
619 sender_->ExportDebugState().bandwidth_hi, 0.01f);
620
621 EXPECT_LE(sender_loss_rate_in_packets(), 0.05);
622 // The margin here is high, because the aggregation greatly increases
623 // smoothed rtt.
624 EXPECT_GE(params.RTT() * 4, rtt_stats()->smoothed_rtt());
625 EXPECT_APPROX_EQ(params.RTT(), rtt_stats()->min_rtt(), 0.2f);
626 }
627
TEST_F(Bbr2DefaultTopologyTest,SimpleTransferBBR5)628 TEST_F(Bbr2DefaultTopologyTest, SimpleTransferBBR5) {
629 SetQuicReloadableFlag(quic_bbr2_extra_acked_window, true);
630 SetConnectionOption(kBBR5);
631 DefaultTopologyParams params;
632 CreateNetwork(params);
633
634 // Transfer 12MB.
635 DoSimpleTransfer(12 * 1024 * 1024, QuicTime::Delta::FromSeconds(35));
636 EXPECT_TRUE(Bbr2ModeIsOneOf({Bbr2Mode::PROBE_BW, Bbr2Mode::PROBE_RTT}));
637
638 EXPECT_APPROX_EQ(params.BottleneckBandwidth(),
639 sender_->ExportDebugState().bandwidth_hi, 0.01f);
640
641 EXPECT_LE(sender_loss_rate_in_packets(), 0.05);
642 // The margin here is high, because the aggregation greatly increases
643 // smoothed rtt.
644 EXPECT_GE(params.RTT() * 4, rtt_stats()->smoothed_rtt());
645 EXPECT_APPROX_EQ(params.RTT(), rtt_stats()->min_rtt(), 0.2f);
646 }
647
TEST_F(Bbr2DefaultTopologyTest,SimpleTransferBBQ1)648 TEST_F(Bbr2DefaultTopologyTest, SimpleTransferBBQ1) {
649 SetConnectionOption(kBBQ1);
650 DefaultTopologyParams params;
651 CreateNetwork(params);
652
653 // Transfer 12MB.
654 DoSimpleTransfer(12 * 1024 * 1024, QuicTime::Delta::FromSeconds(35));
655 EXPECT_TRUE(Bbr2ModeIsOneOf({Bbr2Mode::PROBE_BW, Bbr2Mode::PROBE_RTT}));
656
657 EXPECT_APPROX_EQ(params.BottleneckBandwidth(),
658 sender_->ExportDebugState().bandwidth_hi, 0.01f);
659
660 EXPECT_LE(sender_loss_rate_in_packets(), 0.05);
661 // The margin here is high, because the aggregation greatly increases
662 // smoothed rtt.
663 EXPECT_GE(params.RTT() * 4, rtt_stats()->smoothed_rtt());
664 EXPECT_APPROX_EQ(params.RTT(), rtt_stats()->min_rtt(), 0.2f);
665 }
666
TEST_F(Bbr2DefaultTopologyTest,SimpleTransferSmallBuffer)667 TEST_F(Bbr2DefaultTopologyTest, SimpleTransferSmallBuffer) {
668 DefaultTopologyParams params;
669 params.switch_queue_capacity_in_bdp = 0.5;
670 CreateNetwork(params);
671
672 DoSimpleTransfer(12 * 1024 * 1024, QuicTime::Delta::FromSeconds(30));
673 EXPECT_TRUE(Bbr2ModeIsOneOf({Bbr2Mode::PROBE_BW, Bbr2Mode::PROBE_RTT}));
674 EXPECT_APPROX_EQ(params.BottleneckBandwidth(),
675 sender_->ExportDebugState().bandwidth_hi, 0.02f);
676 EXPECT_GE(sender_connection_stats().packets_lost, 0u);
677 EXPECT_FALSE(sender_->ExportDebugState().last_sample_is_app_limited);
678 }
679
TEST_F(Bbr2DefaultTopologyTest,SimpleTransferSmallBufferB2H2)680 TEST_F(Bbr2DefaultTopologyTest, SimpleTransferSmallBufferB2H2) {
681 SetConnectionOption(kB2H2);
682 DefaultTopologyParams params;
683 params.switch_queue_capacity_in_bdp = 0.5;
684 CreateNetwork(params);
685
686 DoSimpleTransfer(12 * 1024 * 1024, QuicTime::Delta::FromSeconds(30));
687 EXPECT_TRUE(Bbr2ModeIsOneOf({Bbr2Mode::PROBE_BW, Bbr2Mode::PROBE_RTT}));
688 EXPECT_APPROX_EQ(params.BottleneckBandwidth(),
689 sender_->ExportDebugState().bandwidth_hi, 0.02f);
690 EXPECT_GE(sender_connection_stats().packets_lost, 0u);
691 EXPECT_FALSE(sender_->ExportDebugState().last_sample_is_app_limited);
692 }
693
TEST_F(Bbr2DefaultTopologyTest,SimpleTransfer2RTTAggregationBytes)694 TEST_F(Bbr2DefaultTopologyTest, SimpleTransfer2RTTAggregationBytes) {
695 SetConnectionOption(kBSAO);
696 DefaultTopologyParams params;
697 CreateNetwork(params);
698 // 2 RTTs of aggregation, with a max of 10kb.
699 EnableAggregation(10 * 1024, 2 * params.RTT());
700
701 // Transfer 12MB.
702 DoSimpleTransfer(12 * 1024 * 1024, QuicTime::Delta::FromSeconds(35));
703 EXPECT_TRUE(Bbr2ModeIsOneOf({Bbr2Mode::PROBE_BW, Bbr2Mode::PROBE_RTT}));
704
705 EXPECT_APPROX_EQ(params.BottleneckBandwidth(),
706 sender_->ExportDebugState().bandwidth_hi, 0.01f);
707
708 EXPECT_EQ(sender_loss_rate_in_packets(), 0);
709 // The margin here is high, because both link level aggregation and ack
710 // decimation can greatly increase smoothed rtt.
711 EXPECT_GE(params.RTT() * 5, rtt_stats()->smoothed_rtt());
712 EXPECT_APPROX_EQ(params.RTT(), rtt_stats()->min_rtt(), 0.2f);
713 }
714
TEST_F(Bbr2DefaultTopologyTest,SimpleTransfer2RTTAggregationBytesB201)715 TEST_F(Bbr2DefaultTopologyTest, SimpleTransfer2RTTAggregationBytesB201) {
716 SetConnectionOption(kB201);
717 DefaultTopologyParams params;
718 CreateNetwork(params);
719 // 2 RTTs of aggregation, with a max of 10kb.
720 EnableAggregation(10 * 1024, 2 * params.RTT());
721
722 // Transfer 12MB.
723 DoSimpleTransfer(12 * 1024 * 1024, QuicTime::Delta::FromSeconds(35));
724 EXPECT_TRUE(Bbr2ModeIsOneOf({Bbr2Mode::PROBE_BW, Bbr2Mode::PROBE_RTT}));
725
726 // TODO(wub): Tighten the error bound once BSAO is default enabled.
727 EXPECT_APPROX_EQ(params.BottleneckBandwidth(),
728 sender_->ExportDebugState().bandwidth_hi, 0.5f);
729
730 EXPECT_LE(sender_loss_rate_in_packets(), 0.01);
731 // The margin here is high, because both link level aggregation and ack
732 // decimation can greatly increase smoothed rtt.
733 EXPECT_GE(params.RTT() * 5, rtt_stats()->smoothed_rtt());
734 EXPECT_APPROX_EQ(params.RTT(), rtt_stats()->min_rtt(), 0.2f);
735 }
736
TEST_F(Bbr2DefaultTopologyTest,SimpleTransferAckDecimation)737 TEST_F(Bbr2DefaultTopologyTest, SimpleTransferAckDecimation) {
738 SetConnectionOption(kBSAO);
739 DefaultTopologyParams params;
740 CreateNetwork(params);
741
742 // Transfer 12MB.
743 DoSimpleTransfer(12 * 1024 * 1024, QuicTime::Delta::FromSeconds(35));
744 EXPECT_TRUE(Bbr2ModeIsOneOf({Bbr2Mode::PROBE_BW, Bbr2Mode::PROBE_RTT}));
745
746 EXPECT_APPROX_EQ(params.BottleneckBandwidth(),
747 sender_->ExportDebugState().bandwidth_hi, 0.01f);
748
749 EXPECT_LE(sender_loss_rate_in_packets(), 0.001);
750 EXPECT_FALSE(sender_->ExportDebugState().last_sample_is_app_limited);
751 // The margin here is high, because the aggregation greatly increases
752 // smoothed rtt.
753 EXPECT_GE(params.RTT() * 3, rtt_stats()->smoothed_rtt());
754 EXPECT_APPROX_EQ(params.RTT(), rtt_stats()->min_rtt(), 0.1f);
755 }
756
757 // Test Bbr2's reaction to a 100x bandwidth decrease during a transfer.
TEST_F(Bbr2DefaultTopologyTest,QUIC_SLOW_TEST (BandwidthDecrease))758 TEST_F(Bbr2DefaultTopologyTest, QUIC_SLOW_TEST(BandwidthDecrease)) {
759 DefaultTopologyParams params;
760 params.local_link.bandwidth = QuicBandwidth::FromKBitsPerSecond(15000);
761 params.test_link.bandwidth = QuicBandwidth::FromKBitsPerSecond(10000);
762 CreateNetwork(params);
763
764 sender_endpoint_.AddBytesToTransfer(20 * 1024 * 1024);
765
766 // We can transfer ~12MB in the first 10 seconds. The rest ~8MB needs about
767 // 640 seconds.
768 simulator_.RunFor(QuicTime::Delta::FromSeconds(10));
769 EXPECT_TRUE(Bbr2ModeIsOneOf({Bbr2Mode::PROBE_BW, Bbr2Mode::PROBE_RTT}));
770 QUIC_LOG(INFO) << "Bandwidth decreasing at time " << SimulatedNow();
771
772 EXPECT_APPROX_EQ(params.test_link.bandwidth,
773 sender_->ExportDebugState().bandwidth_est, 0.1f);
774 EXPECT_EQ(0u, sender_connection_stats().packets_lost);
775
776 // Now decrease the bottleneck bandwidth from 10Mbps to 100Kbps.
777 params.test_link.bandwidth = QuicBandwidth::FromKBitsPerSecond(100);
778 TestLink()->set_bandwidth(params.test_link.bandwidth);
779
780 bool simulator_result = simulator_.RunUntilOrTimeout(
781 [this]() { return sender_endpoint_.bytes_to_transfer() == 0; },
782 QuicTime::Delta::FromSeconds(800));
783 EXPECT_TRUE(simulator_result);
784 }
785
786 // Test Bbr2's reaction to a 100x bandwidth increase during a transfer with B203
TEST_F(Bbr2DefaultTopologyTest,QUIC_SLOW_TEST (BandwidthIncreaseB203))787 TEST_F(Bbr2DefaultTopologyTest, QUIC_SLOW_TEST(BandwidthIncreaseB203)) {
788 SetConnectionOption(kB203);
789 DefaultTopologyParams params;
790 params.local_link.bandwidth = QuicBandwidth::FromKBitsPerSecond(15000);
791 params.test_link.bandwidth = QuicBandwidth::FromKBitsPerSecond(100);
792 CreateNetwork(params);
793
794 sender_endpoint_.AddBytesToTransfer(20 * 1024 * 1024);
795
796 simulator_.RunFor(QuicTime::Delta::FromSeconds(15));
797 EXPECT_TRUE(Bbr2ModeIsOneOf({Bbr2Mode::PROBE_BW, Bbr2Mode::PROBE_RTT}));
798 QUIC_LOG(INFO) << "Bandwidth increasing at time " << SimulatedNow();
799
800 EXPECT_APPROX_EQ(params.test_link.bandwidth,
801 sender_->ExportDebugState().bandwidth_est, 0.1f);
802 EXPECT_LE(sender_loss_rate_in_packets(), 0.30);
803
804 // Now increase the bottleneck bandwidth from 100Kbps to 10Mbps.
805 params.test_link.bandwidth = QuicBandwidth::FromKBitsPerSecond(10000);
806 TestLink()->set_bandwidth(params.test_link.bandwidth);
807
808 bool simulator_result = simulator_.RunUntilOrTimeout(
809 [this]() { return sender_endpoint_.bytes_to_transfer() == 0; },
810 QuicTime::Delta::FromSeconds(50));
811 EXPECT_TRUE(simulator_result);
812 // Ensure the full bandwidth is discovered.
813 EXPECT_APPROX_EQ(params.test_link.bandwidth,
814 sender_->ExportDebugState().bandwidth_hi, 0.02f);
815 }
816
817 // Test Bbr2's reaction to a 100x bandwidth increase during a transfer with BBQ0
TEST_F(Bbr2DefaultTopologyTest,QUIC_SLOW_TEST (BandwidthIncreaseBBQ0))818 TEST_F(Bbr2DefaultTopologyTest, QUIC_SLOW_TEST(BandwidthIncreaseBBQ0)) {
819 SetConnectionOption(kBBQ0);
820 DefaultTopologyParams params;
821 params.local_link.bandwidth = QuicBandwidth::FromKBitsPerSecond(15000);
822 params.test_link.bandwidth = QuicBandwidth::FromKBitsPerSecond(100);
823 CreateNetwork(params);
824
825 sender_endpoint_.AddBytesToTransfer(10 * 1024 * 1024);
826
827 simulator_.RunFor(QuicTime::Delta::FromSeconds(15));
828 EXPECT_TRUE(Bbr2ModeIsOneOf({Bbr2Mode::PROBE_BW, Bbr2Mode::PROBE_RTT}));
829 QUIC_LOG(INFO) << "Bandwidth increasing at time " << SimulatedNow();
830
831 EXPECT_APPROX_EQ(params.test_link.bandwidth,
832 sender_->ExportDebugState().bandwidth_est, 0.1f);
833 EXPECT_LE(sender_loss_rate_in_packets(), 0.30);
834
835 // Now increase the bottleneck bandwidth from 100Kbps to 10Mbps.
836 params.test_link.bandwidth = QuicBandwidth::FromKBitsPerSecond(10000);
837 TestLink()->set_bandwidth(params.test_link.bandwidth);
838
839 bool simulator_result = simulator_.RunUntilOrTimeout(
840 [this]() { return sender_endpoint_.bytes_to_transfer() == 0; },
841 QuicTime::Delta::FromSeconds(50));
842 EXPECT_TRUE(simulator_result);
843 // Ensure the full bandwidth is discovered.
844 EXPECT_APPROX_EQ(params.test_link.bandwidth,
845 sender_->ExportDebugState().bandwidth_hi, 0.02f);
846 }
847
848 // Test Bbr2's reaction to a 100x bandwidth increase during a transfer with BBQ0
849 // in the presence of ACK aggregation.
TEST_F(Bbr2DefaultTopologyTest,QUIC_SLOW_TEST (BandwidthIncreaseBBQ0Aggregation))850 TEST_F(Bbr2DefaultTopologyTest,
851 QUIC_SLOW_TEST(BandwidthIncreaseBBQ0Aggregation)) {
852 SetConnectionOption(kBBQ0);
853 DefaultTopologyParams params;
854 params.local_link.bandwidth = QuicBandwidth::FromKBitsPerSecond(15000);
855 params.test_link.bandwidth = QuicBandwidth::FromKBitsPerSecond(100);
856 CreateNetwork(params);
857
858 // 2 RTTs of aggregation, with a max of 10kb.
859 EnableAggregation(10 * 1024, 2 * params.RTT());
860
861 // Reduce the payload to 2MB because 10MB takes too long.
862 sender_endpoint_.AddBytesToTransfer(2 * 1024 * 1024);
863
864 simulator_.RunFor(QuicTime::Delta::FromSeconds(15));
865 EXPECT_TRUE(Bbr2ModeIsOneOf({Bbr2Mode::PROBE_BW, Bbr2Mode::PROBE_RTT}));
866 QUIC_LOG(INFO) << "Bandwidth increasing at time " << SimulatedNow();
867
868 // This is much farther off when aggregation is present,
869 // Ideally BSAO or another option would fix this.
870 // TODO(ianswett) Make these bound tighter once overestimation is reduced.
871 EXPECT_APPROX_EQ(params.test_link.bandwidth,
872 sender_->ExportDebugState().bandwidth_est, 0.6f);
873 EXPECT_LE(sender_loss_rate_in_packets(), 0.35);
874
875 // Now increase the bottleneck bandwidth from 100Kbps to 10Mbps.
876 params.test_link.bandwidth = QuicBandwidth::FromKBitsPerSecond(10000);
877 TestLink()->set_bandwidth(params.test_link.bandwidth);
878
879 bool simulator_result = simulator_.RunUntilOrTimeout(
880 [this]() { return sender_endpoint_.bytes_to_transfer() == 0; },
881 QuicTime::Delta::FromSeconds(50));
882 EXPECT_TRUE(simulator_result);
883 // Ensure at least 10% of full bandwidth is discovered.
884 EXPECT_APPROX_EQ(params.test_link.bandwidth,
885 sender_->ExportDebugState().bandwidth_hi, 0.90f);
886 }
887
888 // Test Bbr2's reaction to a 100x bandwidth increase during a transfer with B202
TEST_F(Bbr2DefaultTopologyTest,QUIC_SLOW_TEST (BandwidthIncreaseB202))889 TEST_F(Bbr2DefaultTopologyTest, QUIC_SLOW_TEST(BandwidthIncreaseB202)) {
890 SetConnectionOption(kB202);
891 DefaultTopologyParams params;
892 params.local_link.bandwidth = QuicBandwidth::FromKBitsPerSecond(15000);
893 params.test_link.bandwidth = QuicBandwidth::FromKBitsPerSecond(100);
894 CreateNetwork(params);
895
896 sender_endpoint_.AddBytesToTransfer(10 * 1024 * 1024);
897
898 simulator_.RunFor(QuicTime::Delta::FromSeconds(15));
899 EXPECT_TRUE(Bbr2ModeIsOneOf({Bbr2Mode::PROBE_BW, Bbr2Mode::PROBE_RTT}));
900 QUIC_LOG(INFO) << "Bandwidth increasing at time " << SimulatedNow();
901
902 EXPECT_APPROX_EQ(params.test_link.bandwidth,
903 sender_->ExportDebugState().bandwidth_est, 0.1f);
904 EXPECT_LE(sender_loss_rate_in_packets(), 0.30);
905
906 // Now increase the bottleneck bandwidth from 100Kbps to 10Mbps.
907 params.test_link.bandwidth = QuicBandwidth::FromKBitsPerSecond(10000);
908 TestLink()->set_bandwidth(params.test_link.bandwidth);
909
910 bool simulator_result = simulator_.RunUntilOrTimeout(
911 [this]() { return sender_endpoint_.bytes_to_transfer() == 0; },
912 QuicTime::Delta::FromSeconds(50));
913 EXPECT_TRUE(simulator_result);
914 // Ensure the full bandwidth is discovered.
915 EXPECT_APPROX_EQ(params.test_link.bandwidth,
916 sender_->ExportDebugState().bandwidth_hi, 0.1f);
917 }
918
919 // Test Bbr2's reaction to a 100x bandwidth increase during a transfer with B202
920 // in the presence of ACK aggregation.
TEST_F(Bbr2DefaultTopologyTest,QUIC_SLOW_TEST (BandwidthIncreaseB202Aggregation))921 TEST_F(Bbr2DefaultTopologyTest,
922 QUIC_SLOW_TEST(BandwidthIncreaseB202Aggregation)) {
923 SetConnectionOption(kB202);
924 DefaultTopologyParams params;
925 params.local_link.bandwidth = QuicBandwidth::FromKBitsPerSecond(15000);
926 params.test_link.bandwidth = QuicBandwidth::FromKBitsPerSecond(100);
927 CreateNetwork(params);
928
929 // 2 RTTs of aggregation, with a max of 10kb.
930 EnableAggregation(10 * 1024, 2 * params.RTT());
931
932 // Reduce the payload to 2MB because 10MB takes too long.
933 sender_endpoint_.AddBytesToTransfer(2 * 1024 * 1024);
934
935 simulator_.RunFor(QuicTime::Delta::FromSeconds(15));
936 EXPECT_TRUE(Bbr2ModeIsOneOf({Bbr2Mode::PROBE_BW, Bbr2Mode::PROBE_RTT}));
937 QUIC_LOG(INFO) << "Bandwidth increasing at time " << SimulatedNow();
938
939 // This is much farther off when aggregation is present,
940 // Ideally BSAO or another option would fix this.
941 EXPECT_APPROX_EQ(params.test_link.bandwidth,
942 sender_->ExportDebugState().bandwidth_est, 0.6f);
943 EXPECT_LE(sender_loss_rate_in_packets(), 0.35);
944
945 // Now increase the bottleneck bandwidth from 100Kbps to 10Mbps.
946 params.test_link.bandwidth = QuicBandwidth::FromKBitsPerSecond(10000);
947 TestLink()->set_bandwidth(params.test_link.bandwidth);
948
949 bool simulator_result = simulator_.RunUntilOrTimeout(
950 [this]() { return sender_endpoint_.bytes_to_transfer() == 0; },
951 QuicTime::Delta::FromSeconds(50));
952 EXPECT_TRUE(simulator_result);
953 // Ensure at least 10% of full bandwidth is discovered.
954 EXPECT_APPROX_EQ(params.test_link.bandwidth,
955 sender_->ExportDebugState().bandwidth_hi, 0.92f);
956 }
957
958 // Test Bbr2's reaction to a 100x bandwidth increase during a transfer.
TEST_F(Bbr2DefaultTopologyTest,QUIC_SLOW_TEST (BandwidthIncrease))959 TEST_F(Bbr2DefaultTopologyTest, QUIC_SLOW_TEST(BandwidthIncrease)) {
960 DefaultTopologyParams params;
961 params.local_link.bandwidth = QuicBandwidth::FromKBitsPerSecond(15000);
962 params.test_link.bandwidth = QuicBandwidth::FromKBitsPerSecond(100);
963 CreateNetwork(params);
964
965 sender_endpoint_.AddBytesToTransfer(10 * 1024 * 1024);
966
967 simulator_.RunFor(QuicTime::Delta::FromSeconds(15));
968 EXPECT_TRUE(Bbr2ModeIsOneOf({Bbr2Mode::PROBE_BW, Bbr2Mode::PROBE_RTT}));
969 QUIC_LOG(INFO) << "Bandwidth increasing at time " << SimulatedNow();
970
971 EXPECT_APPROX_EQ(params.test_link.bandwidth,
972 sender_->ExportDebugState().bandwidth_est, 0.1f);
973 EXPECT_LE(sender_loss_rate_in_packets(), 0.30);
974
975 // Now increase the bottleneck bandwidth from 100Kbps to 10Mbps.
976 params.test_link.bandwidth = QuicBandwidth::FromKBitsPerSecond(10000);
977 TestLink()->set_bandwidth(params.test_link.bandwidth);
978
979 bool simulator_result = simulator_.RunUntilOrTimeout(
980 [this]() { return sender_endpoint_.bytes_to_transfer() == 0; },
981 QuicTime::Delta::FromSeconds(50));
982 EXPECT_TRUE(simulator_result);
983 // Ensure the full bandwidth is discovered.
984 EXPECT_APPROX_EQ(params.test_link.bandwidth,
985 sender_->ExportDebugState().bandwidth_hi, 0.02f);
986 }
987
988 // Test Bbr2's reaction to a 100x bandwidth increase during a transfer in the
989 // presence of ACK aggregation.
TEST_F(Bbr2DefaultTopologyTest,QUIC_SLOW_TEST (BandwidthIncreaseAggregation))990 TEST_F(Bbr2DefaultTopologyTest, QUIC_SLOW_TEST(BandwidthIncreaseAggregation)) {
991 DefaultTopologyParams params;
992 params.local_link.bandwidth = QuicBandwidth::FromKBitsPerSecond(15000);
993 params.test_link.bandwidth = QuicBandwidth::FromKBitsPerSecond(100);
994 CreateNetwork(params);
995
996 // 2 RTTs of aggregation, with a max of 10kb.
997 EnableAggregation(10 * 1024, 2 * params.RTT());
998
999 // Reduce the payload to 2MB because 10MB takes too long.
1000 sender_endpoint_.AddBytesToTransfer(2 * 1024 * 1024);
1001
1002 simulator_.RunFor(QuicTime::Delta::FromSeconds(15));
1003 EXPECT_TRUE(Bbr2ModeIsOneOf({Bbr2Mode::PROBE_BW, Bbr2Mode::PROBE_RTT}));
1004 QUIC_LOG(INFO) << "Bandwidth increasing at time " << SimulatedNow();
1005
1006 // This is much farther off when aggregation is present,
1007 // Ideally BSAO or another option would fix this.
1008 EXPECT_APPROX_EQ(params.test_link.bandwidth,
1009 sender_->ExportDebugState().bandwidth_est, 0.60f);
1010 EXPECT_LE(sender_loss_rate_in_packets(), 0.35);
1011
1012 // Now increase the bottleneck bandwidth from 100Kbps to 10Mbps.
1013 params.test_link.bandwidth = QuicBandwidth::FromKBitsPerSecond(10000);
1014 TestLink()->set_bandwidth(params.test_link.bandwidth);
1015
1016 bool simulator_result = simulator_.RunUntilOrTimeout(
1017 [this]() { return sender_endpoint_.bytes_to_transfer() == 0; },
1018 QuicTime::Delta::FromSeconds(50));
1019 EXPECT_TRUE(simulator_result);
1020 // Ensure at least 10% of full bandwidth is discovered.
1021 EXPECT_APPROX_EQ(params.test_link.bandwidth,
1022 sender_->ExportDebugState().bandwidth_hi, 0.91f);
1023 }
1024
1025 // Test Bbr2's reaction to a 100x bandwidth increase during a transfer with BBHI
TEST_F(Bbr2DefaultTopologyTest,QUIC_SLOW_TEST (BandwidthIncreaseBBHI))1026 TEST_F(Bbr2DefaultTopologyTest, QUIC_SLOW_TEST(BandwidthIncreaseBBHI)) {
1027 SetQuicReloadableFlag(quic_bbr2_simplify_inflight_hi, true);
1028 SetConnectionOption(kBBHI);
1029 DefaultTopologyParams params;
1030 params.local_link.bandwidth = QuicBandwidth::FromKBitsPerSecond(15000);
1031 params.test_link.bandwidth = QuicBandwidth::FromKBitsPerSecond(100);
1032 CreateNetwork(params);
1033
1034 sender_endpoint_.AddBytesToTransfer(10 * 1024 * 1024);
1035
1036 simulator_.RunFor(QuicTime::Delta::FromSeconds(15));
1037 EXPECT_TRUE(Bbr2ModeIsOneOf({Bbr2Mode::PROBE_BW, Bbr2Mode::PROBE_RTT}));
1038 QUIC_LOG(INFO) << "Bandwidth increasing at time " << SimulatedNow();
1039
1040 EXPECT_APPROX_EQ(params.test_link.bandwidth,
1041 sender_->ExportDebugState().bandwidth_est, 0.1f);
1042 EXPECT_LE(sender_loss_rate_in_packets(), 0.30);
1043
1044 // Now increase the bottleneck bandwidth from 100Kbps to 10Mbps.
1045 params.test_link.bandwidth = QuicBandwidth::FromKBitsPerSecond(10000);
1046 TestLink()->set_bandwidth(params.test_link.bandwidth);
1047
1048 bool simulator_result = simulator_.RunUntilOrTimeout(
1049 [this]() { return sender_endpoint_.bytes_to_transfer() == 0; },
1050 QuicTime::Delta::FromSeconds(50));
1051 EXPECT_TRUE(simulator_result);
1052 // Ensure the full bandwidth is discovered.
1053 EXPECT_APPROX_EQ(params.test_link.bandwidth,
1054 sender_->ExportDebugState().bandwidth_hi, 0.02f);
1055 }
1056
1057 // Test Bbr2's reaction to a 100x bandwidth increase during a transfer with BBHI
1058 // in the presence of ACK aggregation.
TEST_F(Bbr2DefaultTopologyTest,QUIC_SLOW_TEST (BandwidthIncreaseBBHIAggregation))1059 TEST_F(Bbr2DefaultTopologyTest,
1060 QUIC_SLOW_TEST(BandwidthIncreaseBBHIAggregation)) {
1061 SetQuicReloadableFlag(quic_bbr2_simplify_inflight_hi, true);
1062 SetConnectionOption(kBBHI);
1063 DefaultTopologyParams params;
1064 params.local_link.bandwidth = QuicBandwidth::FromKBitsPerSecond(15000);
1065 params.test_link.bandwidth = QuicBandwidth::FromKBitsPerSecond(100);
1066 CreateNetwork(params);
1067
1068 // 2 RTTs of aggregation, with a max of 10kb.
1069 EnableAggregation(10 * 1024, 2 * params.RTT());
1070
1071 // Reduce the payload to 2MB because 10MB takes too long.
1072 sender_endpoint_.AddBytesToTransfer(2 * 1024 * 1024);
1073
1074 simulator_.RunFor(QuicTime::Delta::FromSeconds(15));
1075 EXPECT_TRUE(Bbr2ModeIsOneOf({Bbr2Mode::PROBE_BW, Bbr2Mode::PROBE_RTT}));
1076 QUIC_LOG(INFO) << "Bandwidth increasing at time " << SimulatedNow();
1077
1078 // This is much farther off when aggregation is present,
1079 // Ideally BSAO or another option would fix this.
1080 EXPECT_APPROX_EQ(params.test_link.bandwidth,
1081 sender_->ExportDebugState().bandwidth_est, 0.60f);
1082 EXPECT_LE(sender_loss_rate_in_packets(), 0.35);
1083
1084 // Now increase the bottleneck bandwidth from 100Kbps to 10Mbps.
1085 params.test_link.bandwidth = QuicBandwidth::FromKBitsPerSecond(10000);
1086 TestLink()->set_bandwidth(params.test_link.bandwidth);
1087
1088 bool simulator_result = simulator_.RunUntilOrTimeout(
1089 [this]() { return sender_endpoint_.bytes_to_transfer() == 0; },
1090 QuicTime::Delta::FromSeconds(50));
1091 EXPECT_TRUE(simulator_result);
1092 // Ensure the full bandwidth is discovered.
1093 EXPECT_APPROX_EQ(params.test_link.bandwidth,
1094 sender_->ExportDebugState().bandwidth_hi, 0.90f);
1095 }
1096
1097 // Test Bbr2's reaction to a 100x bandwidth increase during a transfer with BBHI
1098 // and B202, which changes the exit criteria to be based on
1099 // min_bytes_in_flight_in_round, in the presence of ACK aggregation.
TEST_F(Bbr2DefaultTopologyTest,QUIC_SLOW_TEST (BandwidthIncreaseBBHI_B202Aggregation))1100 TEST_F(Bbr2DefaultTopologyTest,
1101 QUIC_SLOW_TEST(BandwidthIncreaseBBHI_B202Aggregation)) {
1102 SetQuicReloadableFlag(quic_bbr2_simplify_inflight_hi, true);
1103 SetConnectionOption(kBBHI);
1104 SetConnectionOption(kB202);
1105 DefaultTopologyParams params;
1106 params.local_link.bandwidth = QuicBandwidth::FromKBitsPerSecond(15000);
1107 params.test_link.bandwidth = QuicBandwidth::FromKBitsPerSecond(100);
1108 CreateNetwork(params);
1109
1110 // 2 RTTs of aggregation, with a max of 10kb.
1111 EnableAggregation(10 * 1024, 2 * params.RTT());
1112
1113 // Reduce the payload to 2MB because 10MB takes too long.
1114 sender_endpoint_.AddBytesToTransfer(2 * 1024 * 1024);
1115
1116 simulator_.RunFor(QuicTime::Delta::FromSeconds(15));
1117 EXPECT_TRUE(Bbr2ModeIsOneOf({Bbr2Mode::PROBE_BW, Bbr2Mode::PROBE_RTT}));
1118 QUIC_LOG(INFO) << "Bandwidth increasing at time " << SimulatedNow();
1119
1120 // This is much farther off when aggregation is present,
1121 // Ideally BSAO or another option would fix this.
1122 EXPECT_APPROX_EQ(params.test_link.bandwidth,
1123 sender_->ExportDebugState().bandwidth_est, 0.60f);
1124 EXPECT_LE(sender_loss_rate_in_packets(), 0.35);
1125
1126 // Now increase the bottleneck bandwidth from 100Kbps to 10Mbps.
1127 params.test_link.bandwidth = QuicBandwidth::FromKBitsPerSecond(10000);
1128 TestLink()->set_bandwidth(params.test_link.bandwidth);
1129
1130 bool simulator_result = simulator_.RunUntilOrTimeout(
1131 [this]() { return sender_endpoint_.bytes_to_transfer() == 0; },
1132 QuicTime::Delta::FromSeconds(50));
1133 EXPECT_TRUE(simulator_result);
1134 // Ensure at least 18% of the bandwidth is discovered.
1135 EXPECT_APPROX_EQ(params.test_link.bandwidth,
1136 sender_->ExportDebugState().bandwidth_hi, 0.85f);
1137 }
1138
1139 // Test Bbr2's reaction to a 100x bandwidth increase during a transfer with B204
TEST_F(Bbr2DefaultTopologyTest,QUIC_SLOW_TEST (BandwidthIncreaseB204))1140 TEST_F(Bbr2DefaultTopologyTest, QUIC_SLOW_TEST(BandwidthIncreaseB204)) {
1141 SetConnectionOption(kB204);
1142 DefaultTopologyParams params;
1143 params.local_link.bandwidth = QuicBandwidth::FromKBitsPerSecond(15000);
1144 params.test_link.bandwidth = QuicBandwidth::FromKBitsPerSecond(100);
1145 CreateNetwork(params);
1146
1147 sender_endpoint_.AddBytesToTransfer(10 * 1024 * 1024);
1148
1149 simulator_.RunFor(QuicTime::Delta::FromSeconds(15));
1150 EXPECT_TRUE(Bbr2ModeIsOneOf({Bbr2Mode::PROBE_BW, Bbr2Mode::PROBE_RTT}));
1151 QUIC_LOG(INFO) << "Bandwidth increasing at time " << SimulatedNow();
1152
1153 EXPECT_APPROX_EQ(params.test_link.bandwidth,
1154 sender_->ExportDebugState().bandwidth_est, 0.1f);
1155 EXPECT_LE(sender_loss_rate_in_packets(), 0.25);
1156 EXPECT_LE(sender_->ExportDebugState().max_ack_height, 2000u);
1157
1158 // Now increase the bottleneck bandwidth from 100Kbps to 10Mbps.
1159 params.test_link.bandwidth = QuicBandwidth::FromKBitsPerSecond(10000);
1160 TestLink()->set_bandwidth(params.test_link.bandwidth);
1161
1162 bool simulator_result = simulator_.RunUntilOrTimeout(
1163 [this]() { return sender_endpoint_.bytes_to_transfer() == 0; },
1164 QuicTime::Delta::FromSeconds(50));
1165 EXPECT_TRUE(simulator_result);
1166 // Ensure the full bandwidth is discovered.
1167 EXPECT_APPROX_EQ(params.test_link.bandwidth,
1168 sender_->ExportDebugState().bandwidth_hi, 0.02f);
1169 }
1170
1171 // Test Bbr2's reaction to a 100x bandwidth increase during a transfer with B204
1172 // in the presence of ACK aggregation.
TEST_F(Bbr2DefaultTopologyTest,QUIC_SLOW_TEST (BandwidthIncreaseB204Aggregation))1173 TEST_F(Bbr2DefaultTopologyTest,
1174 QUIC_SLOW_TEST(BandwidthIncreaseB204Aggregation)) {
1175 SetConnectionOption(kB204);
1176 DefaultTopologyParams params;
1177 params.local_link.bandwidth = QuicBandwidth::FromKBitsPerSecond(15000);
1178 params.test_link.bandwidth = QuicBandwidth::FromKBitsPerSecond(100);
1179 CreateNetwork(params);
1180
1181 // 2 RTTs of aggregation, with a max of 10kb.
1182 EnableAggregation(10 * 1024, 2 * params.RTT());
1183
1184 // Reduce the payload to 2MB because 10MB takes too long.
1185 sender_endpoint_.AddBytesToTransfer(2 * 1024 * 1024);
1186
1187 simulator_.RunFor(QuicTime::Delta::FromSeconds(15));
1188 EXPECT_TRUE(Bbr2ModeIsOneOf({Bbr2Mode::PROBE_BW, Bbr2Mode::PROBE_RTT}));
1189 QUIC_LOG(INFO) << "Bandwidth increasing at time " << SimulatedNow();
1190
1191 // This is much farther off when aggregation is present, and B204 actually
1192 // is increasing overestimation, which is surprising.
1193 // Ideally BSAO or another option would fix this.
1194 EXPECT_APPROX_EQ(params.test_link.bandwidth,
1195 sender_->ExportDebugState().bandwidth_est, 0.60f);
1196 EXPECT_LE(sender_loss_rate_in_packets(), 0.35);
1197 EXPECT_LE(sender_->ExportDebugState().max_ack_height, 10000u);
1198
1199 // Now increase the bottleneck bandwidth from 100Kbps to 10Mbps.
1200 params.test_link.bandwidth = QuicBandwidth::FromKBitsPerSecond(10000);
1201 TestLink()->set_bandwidth(params.test_link.bandwidth);
1202
1203 bool simulator_result = simulator_.RunUntilOrTimeout(
1204 [this]() { return sender_endpoint_.bytes_to_transfer() == 0; },
1205 QuicTime::Delta::FromSeconds(50));
1206 EXPECT_TRUE(simulator_result);
1207 // Ensure at least 10% of full bandwidth is discovered.
1208 EXPECT_APPROX_EQ(params.test_link.bandwidth,
1209 sender_->ExportDebugState().bandwidth_hi, 0.95f);
1210 }
1211
1212 // Test Bbr2's reaction to a 100x bandwidth increase during a transfer with B205
TEST_F(Bbr2DefaultTopologyTest,QUIC_SLOW_TEST (BandwidthIncreaseB205))1213 TEST_F(Bbr2DefaultTopologyTest, QUIC_SLOW_TEST(BandwidthIncreaseB205)) {
1214 SetConnectionOption(kB205);
1215 DefaultTopologyParams params;
1216 params.local_link.bandwidth = QuicBandwidth::FromKBitsPerSecond(15000);
1217 params.test_link.bandwidth = QuicBandwidth::FromKBitsPerSecond(100);
1218 CreateNetwork(params);
1219
1220 sender_endpoint_.AddBytesToTransfer(10 * 1024 * 1024);
1221
1222 simulator_.RunFor(QuicTime::Delta::FromSeconds(15));
1223 EXPECT_TRUE(Bbr2ModeIsOneOf({Bbr2Mode::PROBE_BW, Bbr2Mode::PROBE_RTT}));
1224 QUIC_LOG(INFO) << "Bandwidth increasing at time " << SimulatedNow();
1225
1226 EXPECT_APPROX_EQ(params.test_link.bandwidth,
1227 sender_->ExportDebugState().bandwidth_est, 0.1f);
1228 EXPECT_LE(sender_loss_rate_in_packets(), 0.10);
1229
1230 // Now increase the bottleneck bandwidth from 100Kbps to 10Mbps.
1231 params.test_link.bandwidth = QuicBandwidth::FromKBitsPerSecond(10000);
1232 TestLink()->set_bandwidth(params.test_link.bandwidth);
1233
1234 bool simulator_result = simulator_.RunUntilOrTimeout(
1235 [this]() { return sender_endpoint_.bytes_to_transfer() == 0; },
1236 QuicTime::Delta::FromSeconds(50));
1237 EXPECT_TRUE(simulator_result);
1238 // Ensure the full bandwidth is discovered.
1239 EXPECT_APPROX_EQ(params.test_link.bandwidth,
1240 sender_->ExportDebugState().bandwidth_hi, 0.1f);
1241 }
1242
1243 // Test Bbr2's reaction to a 100x bandwidth increase during a transfer with B205
1244 // in the presence of ACK aggregation.
TEST_F(Bbr2DefaultTopologyTest,QUIC_SLOW_TEST (BandwidthIncreaseB205Aggregation))1245 TEST_F(Bbr2DefaultTopologyTest,
1246 QUIC_SLOW_TEST(BandwidthIncreaseB205Aggregation)) {
1247 SetConnectionOption(kB205);
1248 DefaultTopologyParams params;
1249 params.local_link.bandwidth = QuicBandwidth::FromKBitsPerSecond(15000);
1250 params.test_link.bandwidth = QuicBandwidth::FromKBitsPerSecond(100);
1251 CreateNetwork(params);
1252
1253 // 2 RTTs of aggregation, with a max of 10kb.
1254 EnableAggregation(10 * 1024, 2 * params.RTT());
1255
1256 // Reduce the payload to 2MB because 10MB takes too long.
1257 sender_endpoint_.AddBytesToTransfer(2 * 1024 * 1024);
1258
1259 simulator_.RunFor(QuicTime::Delta::FromSeconds(15));
1260 EXPECT_TRUE(Bbr2ModeIsOneOf({Bbr2Mode::PROBE_BW, Bbr2Mode::PROBE_RTT}));
1261 QUIC_LOG(INFO) << "Bandwidth increasing at time " << SimulatedNow();
1262
1263 // This is much farther off when aggregation is present,
1264 // Ideally BSAO or another option would fix this.
1265 EXPECT_APPROX_EQ(params.test_link.bandwidth,
1266 sender_->ExportDebugState().bandwidth_est, 0.45f);
1267 EXPECT_LE(sender_loss_rate_in_packets(), 0.15);
1268
1269 // Now increase the bottleneck bandwidth from 100Kbps to 10Mbps.
1270 params.test_link.bandwidth = QuicBandwidth::FromKBitsPerSecond(10000);
1271 TestLink()->set_bandwidth(params.test_link.bandwidth);
1272
1273 bool simulator_result = simulator_.RunUntilOrTimeout(
1274 [this]() { return sender_endpoint_.bytes_to_transfer() == 0; },
1275 QuicTime::Delta::FromSeconds(50));
1276 EXPECT_TRUE(simulator_result);
1277 // Ensure at least 5% of full bandwidth is discovered.
1278 EXPECT_APPROX_EQ(params.test_link.bandwidth,
1279 sender_->ExportDebugState().bandwidth_hi, 0.9f);
1280 }
1281
1282 // Test Bbr2's reaction to a 100x bandwidth increase during a transfer with BB2U
TEST_F(Bbr2DefaultTopologyTest,QUIC_SLOW_TEST (BandwidthIncreaseBB2U))1283 TEST_F(Bbr2DefaultTopologyTest, QUIC_SLOW_TEST(BandwidthIncreaseBB2U)) {
1284 SetQuicReloadableFlag(quic_bbr2_probe_two_rounds, true);
1285 SetConnectionOption(kBB2U);
1286 DefaultTopologyParams params;
1287 params.local_link.bandwidth = QuicBandwidth::FromKBitsPerSecond(15000);
1288 params.test_link.bandwidth = QuicBandwidth::FromKBitsPerSecond(100);
1289 CreateNetwork(params);
1290
1291 sender_endpoint_.AddBytesToTransfer(10 * 1024 * 1024);
1292
1293 simulator_.RunFor(QuicTime::Delta::FromSeconds(15));
1294 EXPECT_TRUE(Bbr2ModeIsOneOf({Bbr2Mode::PROBE_BW, Bbr2Mode::PROBE_RTT}));
1295 QUIC_LOG(INFO) << "Bandwidth increasing at time " << SimulatedNow();
1296
1297 EXPECT_APPROX_EQ(params.test_link.bandwidth,
1298 sender_->ExportDebugState().bandwidth_est, 0.1f);
1299 EXPECT_LE(sender_loss_rate_in_packets(), 0.25);
1300
1301 // Now increase the bottleneck bandwidth from 100Kbps to 10Mbps.
1302 params.test_link.bandwidth = QuicBandwidth::FromKBitsPerSecond(10000);
1303 TestLink()->set_bandwidth(params.test_link.bandwidth);
1304
1305 bool simulator_result = simulator_.RunUntilOrTimeout(
1306 [this]() { return sender_endpoint_.bytes_to_transfer() == 0; },
1307 QuicTime::Delta::FromSeconds(50));
1308 EXPECT_TRUE(simulator_result);
1309 // Ensure the full bandwidth is discovered.
1310 EXPECT_APPROX_EQ(params.test_link.bandwidth,
1311 sender_->ExportDebugState().bandwidth_hi, 0.1f);
1312 }
1313
1314 // Test Bbr2's reaction to a 100x bandwidth increase during a transfer with BB2U
1315 // in the presence of ACK aggregation.
TEST_F(Bbr2DefaultTopologyTest,QUIC_SLOW_TEST (BandwidthIncreaseBB2UAggregation))1316 TEST_F(Bbr2DefaultTopologyTest,
1317 QUIC_SLOW_TEST(BandwidthIncreaseBB2UAggregation)) {
1318 SetQuicReloadableFlag(quic_bbr2_probe_two_rounds, true);
1319 SetConnectionOption(kBB2U);
1320 DefaultTopologyParams params;
1321 params.local_link.bandwidth = QuicBandwidth::FromKBitsPerSecond(15000);
1322 params.test_link.bandwidth = QuicBandwidth::FromKBitsPerSecond(100);
1323 CreateNetwork(params);
1324
1325 // 2 RTTs of aggregation, with a max of 10kb.
1326 EnableAggregation(10 * 1024, 2 * params.RTT());
1327
1328 // Reduce the payload to 5MB because 10MB takes too long.
1329 sender_endpoint_.AddBytesToTransfer(5 * 1024 * 1024);
1330
1331 simulator_.RunFor(QuicTime::Delta::FromSeconds(15));
1332 EXPECT_TRUE(Bbr2ModeIsOneOf({Bbr2Mode::PROBE_BW, Bbr2Mode::PROBE_RTT}));
1333 QUIC_LOG(INFO) << "Bandwidth increasing at time " << SimulatedNow();
1334
1335 // This is much farther off when aggregation is present,
1336 // Ideally BSAO or another option would fix this.
1337 EXPECT_APPROX_EQ(params.test_link.bandwidth,
1338 sender_->ExportDebugState().bandwidth_est, 0.45f);
1339 EXPECT_LE(sender_loss_rate_in_packets(), 0.30);
1340
1341 // Now increase the bottleneck bandwidth from 100Kbps to 10Mbps.
1342 params.test_link.bandwidth = QuicBandwidth::FromKBitsPerSecond(10000);
1343 TestLink()->set_bandwidth(params.test_link.bandwidth);
1344
1345 bool simulator_result = simulator_.RunUntilOrTimeout(
1346 [this]() { return sender_endpoint_.bytes_to_transfer() == 0; },
1347 QuicTime::Delta::FromSeconds(50));
1348 EXPECT_TRUE(simulator_result);
1349 // Ensure at least 15% of the full bandwidth is observed.
1350 EXPECT_APPROX_EQ(params.test_link.bandwidth,
1351 sender_->ExportDebugState().bandwidth_hi, 0.85f);
1352 }
1353
1354 // Test Bbr2's reaction to a 100x bandwidth increase during a transfer with BB2U
1355 // and BBHI in the presence of ACK aggregation.
TEST_F(Bbr2DefaultTopologyTest,QUIC_SLOW_TEST (BandwidthIncreaseBB2UandBBHIAggregation))1356 TEST_F(Bbr2DefaultTopologyTest,
1357 QUIC_SLOW_TEST(BandwidthIncreaseBB2UandBBHIAggregation)) {
1358 SetQuicReloadableFlag(quic_bbr2_probe_two_rounds, true);
1359 SetConnectionOption(kBB2U);
1360 SetQuicReloadableFlag(quic_bbr2_simplify_inflight_hi, true);
1361 SetConnectionOption(kBBHI);
1362 DefaultTopologyParams params;
1363 params.local_link.bandwidth = QuicBandwidth::FromKBitsPerSecond(15000);
1364 params.test_link.bandwidth = QuicBandwidth::FromKBitsPerSecond(100);
1365 CreateNetwork(params);
1366
1367 // 2 RTTs of aggregation, with a max of 10kb.
1368 EnableAggregation(10 * 1024, 2 * params.RTT());
1369
1370 // Reduce the payload to 5MB because 10MB takes too long.
1371 sender_endpoint_.AddBytesToTransfer(5 * 1024 * 1024);
1372
1373 simulator_.RunFor(QuicTime::Delta::FromSeconds(15));
1374 EXPECT_TRUE(Bbr2ModeIsOneOf({Bbr2Mode::PROBE_BW, Bbr2Mode::PROBE_RTT}));
1375 QUIC_LOG(INFO) << "Bandwidth increasing at time " << SimulatedNow();
1376
1377 // This is much farther off when aggregation is present,
1378 // Ideally BSAO or another option would fix this.
1379 EXPECT_APPROX_EQ(params.test_link.bandwidth,
1380 sender_->ExportDebugState().bandwidth_est, 0.45f);
1381 EXPECT_LE(sender_loss_rate_in_packets(), 0.30);
1382
1383 // Now increase the bottleneck bandwidth from 100Kbps to 10Mbps.
1384 params.test_link.bandwidth = QuicBandwidth::FromKBitsPerSecond(10000);
1385 TestLink()->set_bandwidth(params.test_link.bandwidth);
1386
1387 bool simulator_result = simulator_.RunUntilOrTimeout(
1388 [this]() { return sender_endpoint_.bytes_to_transfer() == 0; },
1389 QuicTime::Delta::FromSeconds(50));
1390 EXPECT_TRUE(simulator_result);
1391 // Ensure at least 15% of the full bandwidth is observed.
1392 EXPECT_APPROX_EQ(params.test_link.bandwidth,
1393 sender_->ExportDebugState().bandwidth_hi, 0.85f);
1394 }
1395
1396 // Test the number of losses incurred by the startup phase in a situation when
1397 // the buffer is less than BDP.
TEST_F(Bbr2DefaultTopologyTest,PacketLossOnSmallBufferStartup)1398 TEST_F(Bbr2DefaultTopologyTest, PacketLossOnSmallBufferStartup) {
1399 DefaultTopologyParams params;
1400 params.switch_queue_capacity_in_bdp = 0.5;
1401 CreateNetwork(params);
1402
1403 DriveOutOfStartup(params);
1404 // Packet loss is smaller with a CWND gain of 2 than 2.889.
1405 EXPECT_LE(sender_loss_rate_in_packets(), 0.05);
1406 }
1407
1408 // Test the number of losses decreases with packet-conservation pacing.
TEST_F(Bbr2DefaultTopologyTest,PacketLossBBQ6SmallBufferStartup)1409 TEST_F(Bbr2DefaultTopologyTest, PacketLossBBQ6SmallBufferStartup) {
1410 SetConnectionOption(kBBQ2); // Increase CWND gain.
1411 SetConnectionOption(kBBQ6);
1412 DefaultTopologyParams params;
1413 params.switch_queue_capacity_in_bdp = 0.5;
1414 CreateNetwork(params);
1415
1416 DriveOutOfStartup(params);
1417 EXPECT_LE(sender_loss_rate_in_packets(), 0.0575);
1418 // bandwidth_lo is cleared exiting STARTUP.
1419 EXPECT_EQ(sender_->ExportDebugState().bandwidth_lo,
1420 QuicBandwidth::Infinite());
1421 }
1422
1423 // Test the number of losses decreases with min_rtt packet-conservation pacing.
TEST_F(Bbr2DefaultTopologyTest,PacketLossBBQ7SmallBufferStartup)1424 TEST_F(Bbr2DefaultTopologyTest, PacketLossBBQ7SmallBufferStartup) {
1425 SetConnectionOption(kBBQ2); // Increase CWND gain.
1426 SetConnectionOption(kBBQ7);
1427 DefaultTopologyParams params;
1428 params.switch_queue_capacity_in_bdp = 0.5;
1429 CreateNetwork(params);
1430
1431 DriveOutOfStartup(params);
1432 EXPECT_LE(sender_loss_rate_in_packets(), 0.06);
1433 // bandwidth_lo is cleared exiting STARTUP.
1434 EXPECT_EQ(sender_->ExportDebugState().bandwidth_lo,
1435 QuicBandwidth::Infinite());
1436 }
1437
1438 // Test the number of losses decreases with Inflight packet-conservation pacing.
TEST_F(Bbr2DefaultTopologyTest,PacketLossBBQ8SmallBufferStartup)1439 TEST_F(Bbr2DefaultTopologyTest, PacketLossBBQ8SmallBufferStartup) {
1440 SetConnectionOption(kBBQ2); // Increase CWND gain.
1441 SetConnectionOption(kBBQ8);
1442 DefaultTopologyParams params;
1443 params.switch_queue_capacity_in_bdp = 0.5;
1444 CreateNetwork(params);
1445
1446 DriveOutOfStartup(params);
1447 EXPECT_LE(sender_loss_rate_in_packets(), 0.065);
1448 // bandwidth_lo is cleared exiting STARTUP.
1449 EXPECT_EQ(sender_->ExportDebugState().bandwidth_lo,
1450 QuicBandwidth::Infinite());
1451 }
1452
1453 // Test the number of losses decreases with CWND packet-conservation pacing.
TEST_F(Bbr2DefaultTopologyTest,PacketLossBBQ9SmallBufferStartup)1454 TEST_F(Bbr2DefaultTopologyTest, PacketLossBBQ9SmallBufferStartup) {
1455 SetConnectionOption(kBBQ2); // Increase CWND gain.
1456 SetConnectionOption(kBBQ9);
1457 DefaultTopologyParams params;
1458 params.switch_queue_capacity_in_bdp = 0.5;
1459 CreateNetwork(params);
1460
1461 DriveOutOfStartup(params);
1462 EXPECT_LE(sender_loss_rate_in_packets(), 0.065);
1463 // bandwidth_lo is cleared exiting STARTUP.
1464 EXPECT_EQ(sender_->ExportDebugState().bandwidth_lo,
1465 QuicBandwidth::Infinite());
1466 }
1467
1468 // Verify the behavior of the algorithm in the case when the connection sends
1469 // small bursts of data after sending continuously for a while.
TEST_F(Bbr2DefaultTopologyTest,ApplicationLimitedBursts)1470 TEST_F(Bbr2DefaultTopologyTest, ApplicationLimitedBursts) {
1471 DefaultTopologyParams params;
1472 CreateNetwork(params);
1473
1474 EXPECT_FALSE(sender_->HasGoodBandwidthEstimateForResumption());
1475 DriveOutOfStartup(params);
1476 EXPECT_FALSE(sender_->ExportDebugState().last_sample_is_app_limited);
1477 EXPECT_TRUE(sender_->HasGoodBandwidthEstimateForResumption());
1478
1479 SendBursts(params, 20, 512, QuicTime::Delta::FromSeconds(3));
1480 EXPECT_TRUE(sender_->ExportDebugState().last_sample_is_app_limited);
1481 EXPECT_TRUE(sender_->HasGoodBandwidthEstimateForResumption());
1482 EXPECT_APPROX_EQ(params.BottleneckBandwidth(),
1483 sender_->ExportDebugState().bandwidth_hi, 0.01f);
1484 }
1485
1486 // Verify the behavior of the algorithm in the case when the connection sends
1487 // small bursts of data and then starts sending continuously.
TEST_F(Bbr2DefaultTopologyTest,ApplicationLimitedBurstsWithoutPrior)1488 TEST_F(Bbr2DefaultTopologyTest, ApplicationLimitedBurstsWithoutPrior) {
1489 DefaultTopologyParams params;
1490 CreateNetwork(params);
1491
1492 SendBursts(params, 40, 512, QuicTime::Delta::FromSeconds(3));
1493 EXPECT_TRUE(sender_->ExportDebugState().last_sample_is_app_limited);
1494
1495 DriveOutOfStartup(params);
1496 EXPECT_APPROX_EQ(params.BottleneckBandwidth(),
1497 sender_->ExportDebugState().bandwidth_hi, 0.01f);
1498 EXPECT_FALSE(sender_->ExportDebugState().last_sample_is_app_limited);
1499 }
1500
1501 // Verify that the DRAIN phase works correctly.
TEST_F(Bbr2DefaultTopologyTest,Drain)1502 TEST_F(Bbr2DefaultTopologyTest, Drain) {
1503 DefaultTopologyParams params;
1504 CreateNetwork(params);
1505
1506 const QuicTime::Delta timeout = QuicTime::Delta::FromSeconds(10);
1507 // Get the queue at the bottleneck, which is the outgoing queue at the port to
1508 // which the receiver is connected.
1509 const simulator::Queue* queue = switch_->port_queue(2);
1510 bool simulator_result;
1511
1512 // We have no intention of ever finishing this transfer.
1513 sender_endpoint_.AddBytesToTransfer(100 * 1024 * 1024);
1514
1515 // Run the startup, and verify that it fills up the queue.
1516 ASSERT_EQ(Bbr2Mode::STARTUP, sender_->ExportDebugState().mode);
1517 simulator_result = simulator_.RunUntilOrTimeout(
1518 [this]() {
1519 return sender_->ExportDebugState().mode != Bbr2Mode::STARTUP;
1520 },
1521 timeout);
1522 ASSERT_TRUE(simulator_result);
1523 ASSERT_EQ(Bbr2Mode::DRAIN, sender_->ExportDebugState().mode);
1524 EXPECT_APPROX_EQ(sender_->BandwidthEstimate() * (1 / 2.885f),
1525 sender_->PacingRate(0), 0.01f);
1526
1527 // BBR uses CWND gain of 2 during STARTUP, hence it will fill the buffer with
1528 // approximately 1 BDP. Here, we use 0.95 to give some margin for error.
1529 EXPECT_GE(queue->bytes_queued(), 0.95 * params.BDP());
1530
1531 // Observe increased RTT due to bufferbloat.
1532 const QuicTime::Delta queueing_delay =
1533 params.test_link.bandwidth.TransferTime(queue->bytes_queued());
1534 EXPECT_APPROX_EQ(params.RTT() + queueing_delay, rtt_stats()->latest_rtt(),
1535 0.1f);
1536
1537 // Transition to the drain phase and verify that it makes the queue
1538 // have at most a BDP worth of packets.
1539 simulator_result = simulator_.RunUntilOrTimeout(
1540 [this]() { return sender_->ExportDebugState().mode != Bbr2Mode::DRAIN; },
1541 timeout);
1542 ASSERT_TRUE(simulator_result);
1543 ASSERT_EQ(Bbr2Mode::PROBE_BW, sender_->ExportDebugState().mode);
1544 EXPECT_LE(queue->bytes_queued(), params.BDP());
1545
1546 // Wait for a few round trips and ensure we're in appropriate phase of gain
1547 // cycling before taking an RTT measurement.
1548 const QuicRoundTripCount start_round_trip =
1549 sender_->ExportDebugState().round_trip_count;
1550 simulator_result = simulator_.RunUntilOrTimeout(
1551 [this, start_round_trip]() {
1552 const auto& debug_state = sender_->ExportDebugState();
1553 QuicRoundTripCount rounds_passed =
1554 debug_state.round_trip_count - start_round_trip;
1555 return rounds_passed >= 4 && debug_state.mode == Bbr2Mode::PROBE_BW &&
1556 debug_state.probe_bw.phase == CyclePhase::PROBE_REFILL;
1557 },
1558 timeout);
1559 ASSERT_TRUE(simulator_result);
1560
1561 // Observe the bufferbloat go away.
1562 EXPECT_APPROX_EQ(params.RTT(), rtt_stats()->smoothed_rtt(), 0.1f);
1563 }
1564
1565 // Ensure that a connection that is app-limited and is at sufficiently low
1566 // bandwidth will not exit high gain phase, and similarly ensure that the
1567 // connection will exit low gain early if the number of bytes in flight is low.
TEST_F(Bbr2DefaultTopologyTest,InFlightAwareGainCycling)1568 TEST_F(Bbr2DefaultTopologyTest, InFlightAwareGainCycling) {
1569 DefaultTopologyParams params;
1570 CreateNetwork(params);
1571 DriveOutOfStartup(params);
1572
1573 const QuicTime::Delta timeout = QuicTime::Delta::FromSeconds(5);
1574 bool simulator_result;
1575
1576 // Start a few cycles prior to the high gain one.
1577 simulator_result = SendUntilOrTimeout(
1578 [this]() {
1579 return sender_->ExportDebugState().probe_bw.phase ==
1580 CyclePhase::PROBE_REFILL;
1581 },
1582 timeout);
1583 ASSERT_TRUE(simulator_result);
1584
1585 // Send at 10% of available rate. Run for 3 seconds, checking in the middle
1586 // and at the end. The pacing gain should be high throughout.
1587 QuicBandwidth target_bandwidth = 0.1f * params.BottleneckBandwidth();
1588 QuicTime::Delta burst_interval = QuicTime::Delta::FromMilliseconds(300);
1589 for (int i = 0; i < 2; i++) {
1590 SendBursts(params, 5, target_bandwidth * burst_interval, burst_interval);
1591 EXPECT_EQ(Bbr2Mode::PROBE_BW, sender_->ExportDebugState().mode);
1592 EXPECT_EQ(CyclePhase::PROBE_UP, sender_->ExportDebugState().probe_bw.phase);
1593 EXPECT_APPROX_EQ(params.BottleneckBandwidth(),
1594 sender_->ExportDebugState().bandwidth_hi, 0.02f);
1595 }
1596
1597 if (GetQuicReloadableFlag(quic_pacing_remove_non_initial_burst)) {
1598 QuicSentPacketManagerPeer::GetPacingSender(
1599 &sender_connection()->sent_packet_manager())
1600 ->SetBurstTokens(10);
1601 }
1602
1603 // Now that in-flight is almost zero and the pacing gain is still above 1,
1604 // send approximately 1.4 BDPs worth of data. This should cause the PROBE_BW
1605 // mode to enter low gain cycle(PROBE_DOWN), and exit it earlier than one
1606 // min_rtt due to running out of data to send.
1607 sender_endpoint_.AddBytesToTransfer(1.4 * params.BDP());
1608 simulator_result = simulator_.RunUntilOrTimeout(
1609 [this]() {
1610 return sender_->ExportDebugState().probe_bw.phase ==
1611 CyclePhase::PROBE_DOWN;
1612 },
1613 timeout);
1614 ASSERT_TRUE(simulator_result);
1615 simulator_.RunFor(0.75 * sender_->ExportDebugState().min_rtt);
1616 EXPECT_EQ(Bbr2Mode::PROBE_BW, sender_->ExportDebugState().mode);
1617 EXPECT_EQ(CyclePhase::PROBE_CRUISE,
1618 sender_->ExportDebugState().probe_bw.phase);
1619 }
1620
1621 // Test exiting STARTUP earlier upon loss due to loss.
TEST_F(Bbr2DefaultTopologyTest,ExitStartupDueToLoss)1622 TEST_F(Bbr2DefaultTopologyTest, ExitStartupDueToLoss) {
1623 DefaultTopologyParams params;
1624 params.switch_queue_capacity_in_bdp = 0.5;
1625 CreateNetwork(params);
1626
1627 // Run until the full bandwidth is reached and check how many rounds it was.
1628 sender_endpoint_.AddBytesToTransfer(12 * 1024 * 1024);
1629 QuicRoundTripCount max_bw_round = 0;
1630 QuicBandwidth max_bw(QuicBandwidth::Zero());
1631 bool simulator_result = simulator_.RunUntilOrTimeout(
1632 [this, &max_bw, &max_bw_round]() {
1633 if (max_bw < sender_->ExportDebugState().bandwidth_hi) {
1634 max_bw = sender_->ExportDebugState().bandwidth_hi;
1635 max_bw_round = sender_->ExportDebugState().round_trip_count;
1636 }
1637 return sender_->ExportDebugState().startup.full_bandwidth_reached;
1638 },
1639 QuicTime::Delta::FromSeconds(5));
1640 ASSERT_TRUE(simulator_result);
1641 EXPECT_EQ(Bbr2Mode::DRAIN, sender_->ExportDebugState().mode);
1642 EXPECT_GE(2u, sender_->ExportDebugState().round_trip_count - max_bw_round);
1643 EXPECT_EQ(
1644 1u,
1645 sender_->ExportDebugState().startup.round_trips_without_bandwidth_growth);
1646 EXPECT_NE(0u, sender_connection_stats().packets_lost);
1647 EXPECT_FALSE(sender_->ExportDebugState().last_sample_is_app_limited);
1648
1649 EXPECT_GT(sender_->ExportDebugState().inflight_hi, 1.2f * params.BDP());
1650 }
1651
1652 // Test exiting STARTUP earlier upon loss due to loss when connection option
1653 // B2SL is used.
TEST_F(Bbr2DefaultTopologyTest,ExitStartupDueToLossB2SL)1654 TEST_F(Bbr2DefaultTopologyTest, ExitStartupDueToLossB2SL) {
1655 SetConnectionOption(kB2SL);
1656 DefaultTopologyParams params;
1657 params.switch_queue_capacity_in_bdp = 0.5;
1658 CreateNetwork(params);
1659
1660 // Run until the full bandwidth is reached and check how many rounds it was.
1661 sender_endpoint_.AddBytesToTransfer(12 * 1024 * 1024);
1662 QuicRoundTripCount max_bw_round = 0;
1663 QuicBandwidth max_bw(QuicBandwidth::Zero());
1664 bool simulator_result = simulator_.RunUntilOrTimeout(
1665 [this, &max_bw, &max_bw_round]() {
1666 if (max_bw < sender_->ExportDebugState().bandwidth_hi) {
1667 max_bw = sender_->ExportDebugState().bandwidth_hi;
1668 max_bw_round = sender_->ExportDebugState().round_trip_count;
1669 }
1670 return sender_->ExportDebugState().startup.full_bandwidth_reached;
1671 },
1672 QuicTime::Delta::FromSeconds(5));
1673 ASSERT_TRUE(simulator_result);
1674 EXPECT_EQ(Bbr2Mode::DRAIN, sender_->ExportDebugState().mode);
1675 EXPECT_GE(2u, sender_->ExportDebugState().round_trip_count - max_bw_round);
1676 EXPECT_EQ(
1677 1u,
1678 sender_->ExportDebugState().startup.round_trips_without_bandwidth_growth);
1679 EXPECT_NE(0u, sender_connection_stats().packets_lost);
1680 EXPECT_FALSE(sender_->ExportDebugState().last_sample_is_app_limited);
1681
1682 EXPECT_APPROX_EQ(sender_->ExportDebugState().inflight_hi, params.BDP(), 0.1f);
1683 }
1684
1685 // Verifies that in STARTUP, if we exceed loss threshold in a round, we exit
1686 // STARTUP at the end of the round even if there's enough bandwidth growth.
TEST_F(Bbr2DefaultTopologyTest,ExitStartupDueToLossB2NE)1687 TEST_F(Bbr2DefaultTopologyTest, ExitStartupDueToLossB2NE) {
1688 // Set up flags such that any loss will be considered "too high".
1689 SetQuicFlag(quic_bbr2_default_startup_full_loss_count, 0);
1690 SetQuicFlag(quic_bbr2_default_loss_threshold, 0.0);
1691
1692 sender_ = SetupBbr2Sender(&sender_endpoint_, /*old_sender=*/nullptr);
1693
1694 SetConnectionOption(kB2NE);
1695 DefaultTopologyParams params;
1696 params.switch_queue_capacity_in_bdp = 0.5;
1697 CreateNetwork(params);
1698
1699 // Run until the full bandwidth is reached and check how many rounds it was.
1700 sender_endpoint_.AddBytesToTransfer(12 * 1024 * 1024);
1701 QuicRoundTripCount max_bw_round = 0;
1702 QuicBandwidth max_bw(QuicBandwidth::Zero());
1703 bool simulator_result = simulator_.RunUntilOrTimeout(
1704 [this, &max_bw, &max_bw_round]() {
1705 if (max_bw < sender_->ExportDebugState().bandwidth_hi) {
1706 max_bw = sender_->ExportDebugState().bandwidth_hi;
1707 max_bw_round = sender_->ExportDebugState().round_trip_count;
1708 }
1709 return sender_->ExportDebugState().startup.full_bandwidth_reached;
1710 },
1711 QuicTime::Delta::FromSeconds(5));
1712 ASSERT_TRUE(simulator_result);
1713 EXPECT_EQ(Bbr2Mode::DRAIN, sender_->ExportDebugState().mode);
1714 EXPECT_EQ(sender_->ExportDebugState().round_trip_count, max_bw_round);
1715 EXPECT_EQ(
1716 0u,
1717 sender_->ExportDebugState().startup.round_trips_without_bandwidth_growth);
1718 EXPECT_NE(0u, sender_connection_stats().packets_lost);
1719 }
1720
TEST_F(Bbr2DefaultTopologyTest,SenderPoliced)1721 TEST_F(Bbr2DefaultTopologyTest, SenderPoliced) {
1722 DefaultTopologyParams params;
1723 params.sender_policer_params = TrafficPolicerParams();
1724 params.sender_policer_params->initial_burst_size = 1000 * 10;
1725 params.sender_policer_params->max_bucket_size = 1000 * 100;
1726 params.sender_policer_params->target_bandwidth =
1727 params.BottleneckBandwidth() * 0.25;
1728
1729 CreateNetwork(params);
1730
1731 ASSERT_GE(params.BDP(), kDefaultInitialCwndBytes + kDefaultTCPMSS);
1732
1733 DoSimpleTransfer(3 * 1024 * 1024, QuicTime::Delta::FromSeconds(30));
1734 EXPECT_TRUE(Bbr2ModeIsOneOf({Bbr2Mode::PROBE_BW, Bbr2Mode::PROBE_RTT}));
1735 // TODO(wub): Fix (long-term) bandwidth overestimation in policer mode, then
1736 // reduce the loss rate upper bound.
1737 EXPECT_LE(sender_loss_rate_in_packets(), 0.30);
1738 }
1739
1740 // TODO(wub): Add other slowstart stats to BBRv2.
TEST_F(Bbr2DefaultTopologyTest,StartupStats)1741 TEST_F(Bbr2DefaultTopologyTest, StartupStats) {
1742 DefaultTopologyParams params;
1743 CreateNetwork(params);
1744
1745 DriveOutOfStartup(params);
1746 ASSERT_FALSE(sender_->InSlowStart());
1747
1748 const QuicConnectionStats& stats = sender_connection_stats();
1749 // The test explicitly replaces the default-created send algorithm with the
1750 // one created by the test. slowstart_count increaments every time a BBR
1751 // sender is created.
1752 EXPECT_GE(stats.slowstart_count, 1u);
1753 EXPECT_FALSE(stats.slowstart_duration.IsRunning());
1754 EXPECT_THAT(stats.slowstart_duration.GetTotalElapsedTime(),
1755 AllOf(Ge(QuicTime::Delta::FromMilliseconds(500)),
1756 Le(QuicTime::Delta::FromMilliseconds(1500))));
1757 EXPECT_EQ(stats.slowstart_duration.GetTotalElapsedTime(),
1758 QuicConnectionPeer::GetSentPacketManager(sender_connection())
1759 ->GetSlowStartDuration());
1760 }
1761
TEST_F(Bbr2DefaultTopologyTest,ProbeUpAdaptInflightHiGradually)1762 TEST_F(Bbr2DefaultTopologyTest, ProbeUpAdaptInflightHiGradually) {
1763 DefaultTopologyParams params;
1764 CreateNetwork(params);
1765
1766 DriveOutOfStartup(params);
1767
1768 AckedPacketVector acked_packets;
1769 QuicPacketNumber acked_packet_number =
1770 sender_unacked_map()->GetLeastUnacked();
1771 for (auto& info : *sender_unacked_map()) {
1772 acked_packets.emplace_back(acked_packet_number++, info.bytes_sent,
1773 SimulatedNow());
1774 }
1775
1776 // Advance time significantly so the OnCongestionEvent enters PROBE_REFILL.
1777 QuicTime now = SimulatedNow() + QuicTime::Delta::FromSeconds(5);
1778 auto next_packet_number = sender_unacked_map()->largest_sent_packet() + 1;
1779 sender_->OnCongestionEvent(
1780 /*rtt_updated=*/true, sender_unacked_map()->bytes_in_flight(), now,
1781 acked_packets, {}, 0, 0);
1782 ASSERT_EQ(CyclePhase::PROBE_REFILL,
1783 sender_->ExportDebugState().probe_bw.phase);
1784
1785 // Send and Ack one packet to exit app limited and enter PROBE_UP.
1786 sender_->OnPacketSent(now, /*bytes_in_flight=*/0, next_packet_number++,
1787 kDefaultMaxPacketSize, HAS_RETRANSMITTABLE_DATA);
1788 now = now + params.RTT();
1789 sender_->OnCongestionEvent(
1790 /*rtt_updated=*/true, kDefaultMaxPacketSize, now,
1791 {AckedPacket(next_packet_number - 1, kDefaultMaxPacketSize, now)}, {}, 0,
1792 0);
1793 ASSERT_EQ(CyclePhase::PROBE_UP, sender_->ExportDebugState().probe_bw.phase);
1794
1795 // Send 2 packets and lose the first one(50% loss) to exit PROBE_UP.
1796 for (uint64_t i = 0; i < 2; ++i) {
1797 sender_->OnPacketSent(now, /*bytes_in_flight=*/i * kDefaultMaxPacketSize,
1798 next_packet_number++, kDefaultMaxPacketSize,
1799 HAS_RETRANSMITTABLE_DATA);
1800 }
1801 now = now + params.RTT();
1802 sender_->OnCongestionEvent(
1803 /*rtt_updated=*/true, 2 * kDefaultMaxPacketSize, now,
1804 {AckedPacket(next_packet_number - 1, kDefaultMaxPacketSize, now)},
1805 {LostPacket(next_packet_number - 2, kDefaultMaxPacketSize)}, 0, 0);
1806
1807 QuicByteCount inflight_hi = sender_->ExportDebugState().inflight_hi;
1808 EXPECT_LT(2 * kDefaultMaxPacketSize, inflight_hi);
1809 }
1810
1811 // Ensures bandwidth estimate does not change after a loss only event.
TEST_F(Bbr2DefaultTopologyTest,LossOnlyCongestionEvent)1812 TEST_F(Bbr2DefaultTopologyTest, LossOnlyCongestionEvent) {
1813 DefaultTopologyParams params;
1814 CreateNetwork(params);
1815
1816 DriveOutOfStartup(params);
1817 EXPECT_FALSE(sender_->ExportDebugState().last_sample_is_app_limited);
1818
1819 // Send some bursts, each burst increments round count by 1, since it only
1820 // generates small, app-limited samples, the max_bandwidth_filter_ will not be
1821 // updated.
1822 SendBursts(params, 20, 512, QuicTime::Delta::FromSeconds(3));
1823
1824 // Run until we have something in flight.
1825 sender_endpoint_.AddBytesToTransfer(50 * 1024 * 1024);
1826 bool simulator_result = simulator_.RunUntilOrTimeout(
1827 [&]() { return sender_unacked_map()->bytes_in_flight() > 0; },
1828 QuicTime::Delta::FromSeconds(5));
1829 ASSERT_TRUE(simulator_result);
1830
1831 const QuicBandwidth prior_bandwidth_estimate = sender_->BandwidthEstimate();
1832 EXPECT_APPROX_EQ(params.BottleneckBandwidth(), prior_bandwidth_estimate,
1833 0.01f);
1834
1835 // Lose the least unacked packet.
1836 LostPacketVector lost_packets;
1837 lost_packets.emplace_back(
1838 sender_connection()->sent_packet_manager().GetLeastUnacked(),
1839 kDefaultMaxPacketSize);
1840
1841 QuicTime now = simulator_.GetClock()->Now() + params.RTT() * 0.25;
1842 sender_->OnCongestionEvent(false, sender_unacked_map()->bytes_in_flight(),
1843 now, {}, lost_packets, 0, 0);
1844
1845 // Bandwidth estimate should not change for the loss only event.
1846 EXPECT_EQ(prior_bandwidth_estimate, sender_->BandwidthEstimate());
1847 }
1848
1849 // Simulate the case where a packet is considered lost but then acked.
TEST_F(Bbr2DefaultTopologyTest,SpuriousLossEvent)1850 TEST_F(Bbr2DefaultTopologyTest, SpuriousLossEvent) {
1851 DefaultTopologyParams params;
1852 CreateNetwork(params);
1853
1854 DriveOutOfStartup(params);
1855
1856 // Make sure we have something in flight.
1857 if (sender_unacked_map()->bytes_in_flight() == 0) {
1858 sender_endpoint_.AddBytesToTransfer(50 * 1024 * 1024);
1859 bool simulator_result = simulator_.RunUntilOrTimeout(
1860 [&]() { return sender_unacked_map()->bytes_in_flight() > 0; },
1861 QuicTime::Delta::FromSeconds(5));
1862 ASSERT_TRUE(simulator_result);
1863 }
1864
1865 // Lose all in flight packets.
1866 QuicTime now = simulator_.GetClock()->Now() + params.RTT() * 0.25;
1867 const QuicByteCount prior_inflight = sender_unacked_map()->bytes_in_flight();
1868 LostPacketVector lost_packets;
1869 for (QuicPacketNumber packet_number = sender_unacked_map()->GetLeastUnacked();
1870 sender_unacked_map()->HasInFlightPackets(); packet_number++) {
1871 const auto& info = sender_unacked_map()->GetTransmissionInfo(packet_number);
1872 if (!info.in_flight) {
1873 continue;
1874 }
1875 lost_packets.emplace_back(packet_number, info.bytes_sent);
1876 sender_unacked_map()->RemoveFromInFlight(packet_number);
1877 }
1878 ASSERT_FALSE(lost_packets.empty());
1879 sender_->OnCongestionEvent(false, prior_inflight, now, {}, lost_packets, 0,
1880 0);
1881
1882 // Pretend the first lost packet number is acked.
1883 now = now + params.RTT() * 0.5;
1884 AckedPacketVector acked_packets;
1885 acked_packets.emplace_back(lost_packets[0].packet_number, 0, now);
1886 acked_packets.back().spurious_loss = true;
1887 EXPECT_EQ(sender_unacked_map()->bytes_in_flight(), 0);
1888 sender_->OnCongestionEvent(false, sender_unacked_map()->bytes_in_flight(),
1889 now, acked_packets, {}, 0, 0);
1890
1891 EXPECT_EQ(sender_->GetNetworkModel().total_bytes_sent(),
1892 sender_->GetNetworkModel().total_bytes_acked() +
1893 sender_->GetNetworkModel().total_bytes_lost());
1894 }
1895
1896 // After quiescence, if the sender is in PROBE_RTT, it should transition to
1897 // PROBE_BW immediately on the first sent packet after quiescence.
TEST_F(Bbr2DefaultTopologyTest,ProbeRttAfterQuiescenceImmediatelyExits)1898 TEST_F(Bbr2DefaultTopologyTest, ProbeRttAfterQuiescenceImmediatelyExits) {
1899 DefaultTopologyParams params;
1900 CreateNetwork(params);
1901
1902 DriveOutOfStartup(params);
1903
1904 const QuicTime::Delta timeout = QuicTime::Delta::FromSeconds(15);
1905 bool simulator_result;
1906
1907 // Keep sending until reach PROBE_RTT.
1908 simulator_result = SendUntilOrTimeout(
1909 [this]() {
1910 return sender_->ExportDebugState().mode == Bbr2Mode::PROBE_RTT;
1911 },
1912 timeout);
1913 ASSERT_TRUE(simulator_result);
1914
1915 // Wait for entering a quiescence of 5 seconds.
1916 ASSERT_TRUE(simulator_.RunUntilOrTimeout(
1917 [this]() {
1918 return sender_unacked_map()->bytes_in_flight() == 0 &&
1919 sender_->ExportDebugState().mode == Bbr2Mode::PROBE_RTT;
1920 },
1921 timeout));
1922
1923 simulator_.RunFor(QuicTime::Delta::FromSeconds(5));
1924
1925 // Send one packet to exit quiescence.
1926 EXPECT_EQ(sender_->ExportDebugState().mode, Bbr2Mode::PROBE_RTT);
1927 sender_->OnPacketSent(SimulatedNow(), /*bytes_in_flight=*/0,
1928 sender_unacked_map()->largest_sent_packet() + 1,
1929 kDefaultMaxPacketSize, HAS_RETRANSMITTABLE_DATA);
1930
1931 EXPECT_EQ(sender_->ExportDebugState().mode, Bbr2Mode::PROBE_BW);
1932 }
1933
TEST_F(Bbr2DefaultTopologyTest,ProbeBwAfterQuiescencePostponeMinRttTimestamp)1934 TEST_F(Bbr2DefaultTopologyTest, ProbeBwAfterQuiescencePostponeMinRttTimestamp) {
1935 DefaultTopologyParams params;
1936 CreateNetwork(params);
1937
1938 DriveOutOfStartup(params);
1939
1940 const QuicTime::Delta timeout = QuicTime::Delta::FromSeconds(5);
1941 bool simulator_result;
1942
1943 // Keep sending until reach PROBE_REFILL.
1944 simulator_result = SendUntilOrTimeout(
1945 [this]() {
1946 return sender_->ExportDebugState().probe_bw.phase ==
1947 CyclePhase::PROBE_REFILL;
1948 },
1949 timeout);
1950 ASSERT_TRUE(simulator_result);
1951
1952 const QuicTime min_rtt_timestamp_before_idle =
1953 sender_->ExportDebugState().min_rtt_timestamp;
1954
1955 // Wait for entering a quiescence of 15 seconds.
1956 ASSERT_TRUE(simulator_.RunUntilOrTimeout(
1957 [this]() { return sender_unacked_map()->bytes_in_flight() == 0; },
1958 params.RTT() + timeout));
1959
1960 simulator_.RunFor(QuicTime::Delta::FromSeconds(15));
1961
1962 // Send some data to exit quiescence.
1963 SendBursts(params, 1, kDefaultTCPMSS, QuicTime::Delta::Zero());
1964 const QuicTime min_rtt_timestamp_after_idle =
1965 sender_->ExportDebugState().min_rtt_timestamp;
1966
1967 EXPECT_LT(min_rtt_timestamp_before_idle + QuicTime::Delta::FromSeconds(14),
1968 min_rtt_timestamp_after_idle);
1969 }
1970
TEST_F(Bbr2DefaultTopologyTest,SwitchToBbr2MidConnection)1971 TEST_F(Bbr2DefaultTopologyTest, SwitchToBbr2MidConnection) {
1972 QuicTime now = QuicTime::Zero();
1973 BbrSender old_sender(sender_connection()->clock()->Now(),
1974 sender_connection()->sent_packet_manager().GetRttStats(),
1975 GetUnackedMap(sender_connection()),
1976 kDefaultInitialCwndPackets + 1,
1977 GetQuicFlag(quic_max_congestion_window), &random_,
1978 QuicConnectionPeer::GetStats(sender_connection()));
1979
1980 QuicPacketNumber next_packet_number(1);
1981
1982 // Send packets 1-4.
1983 while (next_packet_number < QuicPacketNumber(5)) {
1984 now = now + QuicTime::Delta::FromMilliseconds(10);
1985
1986 old_sender.OnPacketSent(now, /*bytes_in_flight=*/0, next_packet_number++,
1987 /*bytes=*/1350, HAS_RETRANSMITTABLE_DATA);
1988 }
1989
1990 // Switch from |old_sender| to |sender_|.
1991 const QuicByteCount old_sender_cwnd = old_sender.GetCongestionWindow();
1992 sender_ = SetupBbr2Sender(&sender_endpoint_, &old_sender);
1993 EXPECT_EQ(old_sender_cwnd, sender_->GetCongestionWindow());
1994
1995 // Send packets 5-7.
1996 now = now + QuicTime::Delta::FromMilliseconds(10);
1997 sender_->OnPacketSent(now, /*bytes_in_flight=*/1350, next_packet_number++,
1998 /*bytes=*/23, NO_RETRANSMITTABLE_DATA);
1999
2000 now = now + QuicTime::Delta::FromMilliseconds(10);
2001 sender_->OnPacketSent(now, /*bytes_in_flight=*/1350, next_packet_number++,
2002 /*bytes=*/767, HAS_RETRANSMITTABLE_DATA);
2003
2004 QuicByteCount bytes_in_flight = 767;
2005 while (next_packet_number < QuicPacketNumber(30)) {
2006 now = now + QuicTime::Delta::FromMilliseconds(10);
2007 bytes_in_flight += 1350;
2008 sender_->OnPacketSent(now, bytes_in_flight, next_packet_number++,
2009 /*bytes=*/1350, HAS_RETRANSMITTABLE_DATA);
2010 }
2011
2012 // Ack 1 & 2.
2013 AckedPacketVector acked = {
2014 AckedPacket(QuicPacketNumber(1), /*bytes_acked=*/0, QuicTime::Zero()),
2015 AckedPacket(QuicPacketNumber(2), /*bytes_acked=*/0, QuicTime::Zero()),
2016 };
2017 now = now + QuicTime::Delta::FromMilliseconds(2000);
2018 sender_->OnCongestionEvent(true, bytes_in_flight, now, acked, {}, 0, 0);
2019
2020 // Send 30-41.
2021 while (next_packet_number < QuicPacketNumber(42)) {
2022 now = now + QuicTime::Delta::FromMilliseconds(10);
2023 bytes_in_flight += 1350;
2024 sender_->OnPacketSent(now, bytes_in_flight, next_packet_number++,
2025 /*bytes=*/1350, HAS_RETRANSMITTABLE_DATA);
2026 }
2027
2028 // Ack 3.
2029 acked = {
2030 AckedPacket(QuicPacketNumber(3), /*bytes_acked=*/0, QuicTime::Zero()),
2031 };
2032 now = now + QuicTime::Delta::FromMilliseconds(2000);
2033 sender_->OnCongestionEvent(true, bytes_in_flight, now, acked, {}, 0, 0);
2034
2035 // Send 42.
2036 now = now + QuicTime::Delta::FromMilliseconds(10);
2037 bytes_in_flight += 1350;
2038 sender_->OnPacketSent(now, bytes_in_flight, next_packet_number++,
2039 /*bytes=*/1350, HAS_RETRANSMITTABLE_DATA);
2040
2041 // Ack 4-7.
2042 acked = {
2043 AckedPacket(QuicPacketNumber(4), /*bytes_acked=*/0, QuicTime::Zero()),
2044 AckedPacket(QuicPacketNumber(5), /*bytes_acked=*/0, QuicTime::Zero()),
2045 AckedPacket(QuicPacketNumber(6), /*bytes_acked=*/767, QuicTime::Zero()),
2046 AckedPacket(QuicPacketNumber(7), /*bytes_acked=*/1350, QuicTime::Zero()),
2047 };
2048 now = now + QuicTime::Delta::FromMilliseconds(2000);
2049 sender_->OnCongestionEvent(true, bytes_in_flight, now, acked, {}, 0, 0);
2050 EXPECT_FALSE(sender_->BandwidthEstimate().IsZero());
2051 }
2052
TEST_F(Bbr2DefaultTopologyTest,AdjustNetworkParameters)2053 TEST_F(Bbr2DefaultTopologyTest, AdjustNetworkParameters) {
2054 DefaultTopologyParams params;
2055 CreateNetwork(params);
2056
2057 QUIC_LOG(INFO) << "Initial cwnd: " << sender_debug_state().congestion_window
2058 << "\nInitial pacing rate: " << sender_->PacingRate(0)
2059 << "\nInitial bandwidth estimate: "
2060 << sender_->BandwidthEstimate()
2061 << "\nInitial rtt: " << sender_debug_state().min_rtt;
2062
2063 sender_connection()->AdjustNetworkParameters(
2064 SendAlgorithmInterface::NetworkParams(params.BottleneckBandwidth(),
2065 params.RTT(),
2066 /*allow_cwnd_to_decrease=*/false));
2067
2068 EXPECT_EQ(params.BDP(), sender_->ExportDebugState().congestion_window);
2069
2070 EXPECT_EQ(params.BottleneckBandwidth(),
2071 sender_->PacingRate(/*bytes_in_flight=*/0));
2072 EXPECT_NE(params.BottleneckBandwidth(), sender_->BandwidthEstimate());
2073
2074 EXPECT_APPROX_EQ(params.RTT(), sender_->ExportDebugState().min_rtt, 0.01f);
2075
2076 DriveOutOfStartup(params);
2077 }
2078
2079 TEST_F(Bbr2DefaultTopologyTest,
2080 200InitialCongestionWindowWithNetworkParameterAdjusted) {
2081 DefaultTopologyParams params;
2082 CreateNetwork(params);
2083
2084 sender_endpoint_.AddBytesToTransfer(1 * 1024 * 1024);
2085
2086 // Wait until an ACK comes back.
2087 const QuicTime::Delta timeout = QuicTime::Delta::FromSeconds(5);
2088 bool simulator_result = simulator_.RunUntilOrTimeout(
__anond29b03de2702() 2089 [this]() { return !sender_->ExportDebugState().min_rtt.IsZero(); },
2090 timeout);
2091 ASSERT_TRUE(simulator_result);
2092
2093 // Bootstrap cwnd by a overly large bandwidth sample.
2094 sender_connection()->AdjustNetworkParameters(
2095 SendAlgorithmInterface::NetworkParams(1024 * params.BottleneckBandwidth(),
2096 QuicTime::Delta::Zero(), false));
2097
2098 // Verify cwnd is capped at 200.
2099 EXPECT_EQ(200 * kDefaultTCPMSS,
2100 sender_->ExportDebugState().congestion_window);
2101 EXPECT_GT(1024 * params.BottleneckBandwidth(), sender_->PacingRate(0));
2102 }
2103
2104 TEST_F(Bbr2DefaultTopologyTest,
2105 100InitialCongestionWindowFromNetworkParameter) {
2106 DefaultTopologyParams params;
2107 CreateNetwork(params);
2108
2109 sender_endpoint_.AddBytesToTransfer(1 * 1024 * 1024);
2110 // Wait until an ACK comes back.
2111 const QuicTime::Delta timeout = QuicTime::Delta::FromSeconds(5);
2112 bool simulator_result = simulator_.RunUntilOrTimeout(
__anond29b03de2802() 2113 [this]() { return !sender_->ExportDebugState().min_rtt.IsZero(); },
2114 timeout);
2115 ASSERT_TRUE(simulator_result);
2116
2117 // Bootstrap cwnd by a overly large bandwidth sample.
2118 SendAlgorithmInterface::NetworkParams network_params(
2119 1024 * params.BottleneckBandwidth(), QuicTime::Delta::Zero(), false);
2120 network_params.max_initial_congestion_window = 100;
2121 sender_connection()->AdjustNetworkParameters(network_params);
2122
2123 // Verify cwnd is capped at 100.
2124 EXPECT_EQ(100 * kDefaultTCPMSS,
2125 sender_->ExportDebugState().congestion_window);
2126 EXPECT_GT(1024 * params.BottleneckBandwidth(), sender_->PacingRate(0));
2127 }
2128
2129 TEST_F(Bbr2DefaultTopologyTest,
2130 100InitialCongestionWindowWithNetworkParameterAdjusted) {
2131 SetConnectionOption(kICW1);
2132 DefaultTopologyParams params;
2133 CreateNetwork(params);
2134
2135 sender_endpoint_.AddBytesToTransfer(1 * 1024 * 1024);
2136 // Wait until an ACK comes back.
2137 const QuicTime::Delta timeout = QuicTime::Delta::FromSeconds(5);
2138 bool simulator_result = simulator_.RunUntilOrTimeout(
__anond29b03de2902() 2139 [this]() { return !sender_->ExportDebugState().min_rtt.IsZero(); },
2140 timeout);
2141 ASSERT_TRUE(simulator_result);
2142
2143 // Bootstrap cwnd by a overly large bandwidth sample.
2144 sender_connection()->AdjustNetworkParameters(
2145 SendAlgorithmInterface::NetworkParams(1024 * params.BottleneckBandwidth(),
2146 QuicTime::Delta::Zero(), false));
2147
2148 // Verify cwnd is capped at 100.
2149 EXPECT_EQ(100 * kDefaultTCPMSS,
2150 sender_->ExportDebugState().congestion_window);
2151 EXPECT_GT(1024 * params.BottleneckBandwidth(), sender_->PacingRate(0));
2152 }
2153
2154 // All Bbr2MultiSenderTests uses the following network topology:
2155 //
2156 // Sender 0 (A Bbr2Sender)
2157 // |
2158 // | <-- local_links[0]
2159 // |
2160 // | Sender N (1 <= N < kNumLocalLinks) (May or may not be a Bbr2Sender)
2161 // | |
2162 // | | <-- local_links[N]
2163 // | |
2164 // Network switch
2165 // * <-- the bottleneck queue in the direction
2166 // | of the receiver
2167 // |
2168 // | <-- test_link
2169 // |
2170 // |
2171 // Receiver
2172 class MultiSenderTopologyParams {
2173 public:
2174 static constexpr size_t kNumLocalLinks = 8;
2175 std::array<LinkParams, kNumLocalLinks> local_links = {
2176 LinkParams(10000, 1987), LinkParams(10000, 1993), LinkParams(10000, 1997),
2177 LinkParams(10000, 1999), LinkParams(10000, 2003), LinkParams(10000, 2011),
2178 LinkParams(10000, 2017), LinkParams(10000, 2027),
2179 };
2180
2181 LinkParams test_link = LinkParams(4000, 30000);
2182
2183 const simulator::SwitchPortNumber switch_port_count = kNumLocalLinks + 1;
2184
2185 // Network switch queue capacity, in number of BDPs.
2186 float switch_queue_capacity_in_bdp = 2;
2187
BottleneckBandwidth() const2188 QuicBandwidth BottleneckBandwidth() const {
2189 // Make sure all local links have a higher bandwidth than the test link.
2190 for (size_t i = 0; i < local_links.size(); ++i) {
2191 QUICHE_CHECK_GT(local_links[i].bandwidth, test_link.bandwidth);
2192 }
2193 return test_link.bandwidth;
2194 }
2195
2196 // Sender n's round trip time of a single full size packet.
Rtt(size_t n) const2197 QuicTime::Delta Rtt(size_t n) const {
2198 return 2 * (local_links[n].delay + test_link.delay +
2199 local_links[n].bandwidth.TransferTime(kMaxOutgoingPacketSize) +
2200 test_link.bandwidth.TransferTime(kMaxOutgoingPacketSize));
2201 }
2202
Bdp(size_t n) const2203 QuicByteCount Bdp(size_t n) const { return BottleneckBandwidth() * Rtt(n); }
2204
SwitchQueueCapacity() const2205 QuicByteCount SwitchQueueCapacity() const {
2206 return switch_queue_capacity_in_bdp * Bdp(1);
2207 }
2208
ToString() const2209 std::string ToString() const {
2210 std::ostringstream os;
2211 os << "{ BottleneckBandwidth: " << BottleneckBandwidth();
2212 for (size_t i = 0; i < local_links.size(); ++i) {
2213 os << " RTT_" << i << ": " << Rtt(i) << " BDP_" << i << ": " << Bdp(i);
2214 }
2215 os << " BottleneckQueueSize: " << SwitchQueueCapacity() << "}";
2216 return os.str();
2217 }
2218 };
2219
2220 class Bbr2MultiSenderTest : public Bbr2SimulatorTest {
2221 protected:
Bbr2MultiSenderTest()2222 Bbr2MultiSenderTest() {
2223 uint64_t first_connection_id = 42;
2224 std::vector<simulator::QuicEndpointBase*> receiver_endpoint_pointers;
2225 for (size_t i = 0; i < MultiSenderTopologyParams::kNumLocalLinks; ++i) {
2226 std::string sender_name = absl::StrCat("Sender", i + 1);
2227 std::string receiver_name = absl::StrCat("Receiver", i + 1);
2228 sender_endpoints_.push_back(std::make_unique<simulator::QuicEndpoint>(
2229 &simulator_, sender_name, receiver_name, Perspective::IS_CLIENT,
2230 TestConnectionId(first_connection_id + i)));
2231 receiver_endpoints_.push_back(std::make_unique<simulator::QuicEndpoint>(
2232 &simulator_, receiver_name, sender_name, Perspective::IS_SERVER,
2233 TestConnectionId(first_connection_id + i)));
2234 receiver_endpoint_pointers.push_back(receiver_endpoints_.back().get());
2235 }
2236 receiver_multiplexer_ =
2237 std::make_unique<simulator::QuicEndpointMultiplexer>(
2238 "Receiver multiplexer", receiver_endpoint_pointers);
2239 sender_0_ = SetupBbr2Sender(sender_endpoints_[0].get());
2240 }
2241
~Bbr2MultiSenderTest()2242 ~Bbr2MultiSenderTest() {
2243 const auto* test_info =
2244 ::testing::UnitTest::GetInstance()->current_test_info();
2245 QUIC_LOG(INFO) << "Bbr2MultiSenderTest." << test_info->name()
2246 << " completed at simulated time: "
2247 << SimulatedNow().ToDebuggingValue() / 1e6
2248 << " sec. Per sender stats:";
2249 for (size_t i = 0; i < sender_endpoints_.size(); ++i) {
2250 QUIC_LOG(INFO) << "sender[" << i << "]: "
2251 << sender_connection(i)
2252 ->sent_packet_manager()
2253 .GetSendAlgorithm()
2254 ->GetCongestionControlType()
2255 << ", packet_loss:"
2256 << 100.0 * sender_loss_rate_in_packets(i) << "%";
2257 }
2258 }
2259
SetupBbr2Sender(simulator::QuicEndpoint * endpoint)2260 Bbr2Sender* SetupBbr2Sender(simulator::QuicEndpoint* endpoint) {
2261 // Ownership of the sender will be overtaken by the endpoint.
2262 Bbr2Sender* sender = new Bbr2Sender(
2263 endpoint->connection()->clock()->Now(),
2264 endpoint->connection()->sent_packet_manager().GetRttStats(),
2265 QuicSentPacketManagerPeer::GetUnackedPacketMap(
2266 QuicConnectionPeer::GetSentPacketManager(endpoint->connection())),
2267 kDefaultInitialCwndPackets, GetQuicFlag(quic_max_congestion_window),
2268 &random_, QuicConnectionPeer::GetStats(endpoint->connection()),
2269 nullptr);
2270 // TODO(ianswett): Add dedicated tests for this option until it becomes
2271 // the default behavior.
2272 SetConnectionOption(sender, kBBRA);
2273
2274 QuicConnectionPeer::SetSendAlgorithm(endpoint->connection(), sender);
2275 endpoint->RecordTrace();
2276 return sender;
2277 }
2278
SetupBbrSender(simulator::QuicEndpoint * endpoint)2279 BbrSender* SetupBbrSender(simulator::QuicEndpoint* endpoint) {
2280 // Ownership of the sender will be overtaken by the endpoint.
2281 BbrSender* sender = new BbrSender(
2282 endpoint->connection()->clock()->Now(),
2283 endpoint->connection()->sent_packet_manager().GetRttStats(),
2284 QuicSentPacketManagerPeer::GetUnackedPacketMap(
2285 QuicConnectionPeer::GetSentPacketManager(endpoint->connection())),
2286 kDefaultInitialCwndPackets, GetQuicFlag(quic_max_congestion_window),
2287 &random_, QuicConnectionPeer::GetStats(endpoint->connection()));
2288 QuicConnectionPeer::SetSendAlgorithm(endpoint->connection(), sender);
2289 endpoint->RecordTrace();
2290 return sender;
2291 }
2292
2293 // reno => Reno. !reno => Cubic.
SetupTcpSender(simulator::QuicEndpoint * endpoint,bool reno)2294 TcpCubicSenderBytes* SetupTcpSender(simulator::QuicEndpoint* endpoint,
2295 bool reno) {
2296 // Ownership of the sender will be overtaken by the endpoint.
2297 TcpCubicSenderBytes* sender = new TcpCubicSenderBytes(
2298 endpoint->connection()->clock(),
2299 endpoint->connection()->sent_packet_manager().GetRttStats(), reno,
2300 kDefaultInitialCwndPackets, GetQuicFlag(quic_max_congestion_window),
2301 QuicConnectionPeer::GetStats(endpoint->connection()));
2302 QuicConnectionPeer::SetSendAlgorithm(endpoint->connection(), sender);
2303 endpoint->RecordTrace();
2304 return sender;
2305 }
2306
SetConnectionOption(SendAlgorithmInterface * sender,QuicTag option)2307 void SetConnectionOption(SendAlgorithmInterface* sender, QuicTag option) {
2308 QuicConfig config;
2309 QuicTagVector options;
2310 options.push_back(option);
2311 QuicConfigPeer::SetReceivedConnectionOptions(&config, options);
2312 sender->SetFromConfig(config, Perspective::IS_SERVER);
2313 }
2314
CreateNetwork(const MultiSenderTopologyParams & params)2315 void CreateNetwork(const MultiSenderTopologyParams& params) {
2316 QUIC_LOG(INFO) << "CreateNetwork with parameters: " << params.ToString();
2317 switch_ = std::make_unique<simulator::Switch>(&simulator_, "Switch",
2318 params.switch_port_count,
2319 params.SwitchQueueCapacity());
2320
2321 network_links_.push_back(std::make_unique<simulator::SymmetricLink>(
2322 receiver_multiplexer_.get(), switch_->port(1),
2323 params.test_link.bandwidth, params.test_link.delay));
2324 for (size_t i = 0; i < MultiSenderTopologyParams::kNumLocalLinks; ++i) {
2325 simulator::SwitchPortNumber port_number = i + 2;
2326 network_links_.push_back(std::make_unique<simulator::SymmetricLink>(
2327 sender_endpoints_[i].get(), switch_->port(port_number),
2328 params.local_links[i].bandwidth, params.local_links[i].delay));
2329 }
2330 }
2331
sender_connection(size_t which)2332 QuicConnection* sender_connection(size_t which) {
2333 return sender_endpoints_[which]->connection();
2334 }
2335
sender_connection_stats(size_t which)2336 const QuicConnectionStats& sender_connection_stats(size_t which) {
2337 return sender_connection(which)->GetStats();
2338 }
2339
sender_loss_rate_in_packets(size_t which)2340 float sender_loss_rate_in_packets(size_t which) {
2341 return static_cast<float>(sender_connection_stats(which).packets_lost) /
2342 sender_connection_stats(which).packets_sent;
2343 }
2344
2345 std::vector<std::unique_ptr<simulator::QuicEndpoint>> sender_endpoints_;
2346 std::vector<std::unique_ptr<simulator::QuicEndpoint>> receiver_endpoints_;
2347 std::unique_ptr<simulator::QuicEndpointMultiplexer> receiver_multiplexer_;
2348 Bbr2Sender* sender_0_;
2349
2350 std::unique_ptr<simulator::Switch> switch_;
2351 std::vector<std::unique_ptr<simulator::SymmetricLink>> network_links_;
2352 };
2353
TEST_F(Bbr2MultiSenderTest,Bbr2VsBbr2)2354 TEST_F(Bbr2MultiSenderTest, Bbr2VsBbr2) {
2355 SetupBbr2Sender(sender_endpoints_[1].get());
2356
2357 MultiSenderTopologyParams params;
2358 CreateNetwork(params);
2359
2360 const QuicByteCount transfer_size = 10 * 1024 * 1024;
2361 const QuicTime::Delta transfer_time =
2362 params.BottleneckBandwidth().TransferTime(transfer_size);
2363 QUIC_LOG(INFO) << "Single flow transfer time: " << transfer_time;
2364
2365 // Transfer 10% of data in first transfer.
2366 sender_endpoints_[0]->AddBytesToTransfer(transfer_size);
2367 bool simulator_result = simulator_.RunUntilOrTimeout(
2368 [this]() {
2369 return receiver_endpoints_[0]->bytes_received() >= 0.1 * transfer_size;
2370 },
2371 transfer_time);
2372 ASSERT_TRUE(simulator_result);
2373
2374 // Start the second transfer and wait until both finish.
2375 sender_endpoints_[1]->AddBytesToTransfer(transfer_size);
2376 simulator_result = simulator_.RunUntilOrTimeout(
2377 [this]() {
2378 return receiver_endpoints_[0]->bytes_received() == transfer_size &&
2379 receiver_endpoints_[1]->bytes_received() == transfer_size;
2380 },
2381 3 * transfer_time);
2382 ASSERT_TRUE(simulator_result);
2383 }
2384
TEST_F(Bbr2MultiSenderTest,Bbr2VsBbr2BBPD)2385 TEST_F(Bbr2MultiSenderTest, Bbr2VsBbr2BBPD) {
2386 SetConnectionOption(sender_0_, kBBPD);
2387 Bbr2Sender* sender_1 = SetupBbr2Sender(sender_endpoints_[1].get());
2388 SetConnectionOption(sender_1, kBBPD);
2389
2390 MultiSenderTopologyParams params;
2391 CreateNetwork(params);
2392
2393 const QuicByteCount transfer_size = 10 * 1024 * 1024;
2394 const QuicTime::Delta transfer_time =
2395 params.BottleneckBandwidth().TransferTime(transfer_size);
2396 QUIC_LOG(INFO) << "Single flow transfer time: " << transfer_time;
2397
2398 // Transfer 10% of data in first transfer.
2399 sender_endpoints_[0]->AddBytesToTransfer(transfer_size);
2400 bool simulator_result = simulator_.RunUntilOrTimeout(
2401 [this]() {
2402 return receiver_endpoints_[0]->bytes_received() >= 0.1 * transfer_size;
2403 },
2404 transfer_time);
2405 ASSERT_TRUE(simulator_result);
2406
2407 // Start the second transfer and wait until both finish.
2408 sender_endpoints_[1]->AddBytesToTransfer(transfer_size);
2409 simulator_result = simulator_.RunUntilOrTimeout(
2410 [this]() {
2411 return receiver_endpoints_[0]->bytes_received() == transfer_size &&
2412 receiver_endpoints_[1]->bytes_received() == transfer_size;
2413 },
2414 3 * transfer_time);
2415 ASSERT_TRUE(simulator_result);
2416 }
2417
TEST_F(Bbr2MultiSenderTest,QUIC_SLOW_TEST (MultipleBbr2s))2418 TEST_F(Bbr2MultiSenderTest, QUIC_SLOW_TEST(MultipleBbr2s)) {
2419 const int kTotalNumSenders = 6;
2420 for (int i = 1; i < kTotalNumSenders; ++i) {
2421 SetupBbr2Sender(sender_endpoints_[i].get());
2422 }
2423
2424 MultiSenderTopologyParams params;
2425 CreateNetwork(params);
2426
2427 const QuicByteCount transfer_size = 10 * 1024 * 1024;
2428 const QuicTime::Delta transfer_time =
2429 params.BottleneckBandwidth().TransferTime(transfer_size);
2430 QUIC_LOG(INFO) << "Single flow transfer time: " << transfer_time
2431 << ". Now: " << SimulatedNow();
2432
2433 // Start all transfers.
2434 for (int i = 0; i < kTotalNumSenders; ++i) {
2435 if (i != 0) {
2436 const QuicTime sender_start_time =
2437 SimulatedNow() + QuicTime::Delta::FromSeconds(2);
2438 bool simulator_result = simulator_.RunUntilOrTimeout(
2439 [&]() { return SimulatedNow() >= sender_start_time; }, transfer_time);
2440 ASSERT_TRUE(simulator_result);
2441 }
2442
2443 sender_endpoints_[i]->AddBytesToTransfer(transfer_size);
2444 }
2445
2446 // Wait for all transfers to finish.
2447 QuicTime::Delta expected_total_transfer_time_upper_bound =
2448 QuicTime::Delta::FromMicroseconds(kTotalNumSenders *
2449 transfer_time.ToMicroseconds() * 1.1);
2450 bool simulator_result = simulator_.RunUntilOrTimeout(
2451 [this]() {
2452 for (int i = 0; i < kTotalNumSenders; ++i) {
2453 if (receiver_endpoints_[i]->bytes_received() < transfer_size) {
2454 return false;
2455 }
2456 }
2457 return true;
2458 },
2459 expected_total_transfer_time_upper_bound);
2460 ASSERT_TRUE(simulator_result)
2461 << "Expected upper bound: " << expected_total_transfer_time_upper_bound;
2462 }
2463
2464 /* The first 11 packets are sent at the same time, but the duration between the
2465 * acks of the 1st and the 11th packet is 49 milliseconds, causing very low bw
2466 * samples. This happens for both large and small buffers.
2467 */
2468 /*
2469 TEST_F(Bbr2MultiSenderTest, Bbr2VsBbr2LargeRttTinyBuffer) {
2470 SetupBbr2Sender(sender_endpoints_[1].get());
2471
2472 MultiSenderTopologyParams params;
2473 params.switch_queue_capacity_in_bdp = 0.05;
2474 params.test_link.delay = QuicTime::Delta::FromSeconds(1);
2475 CreateNetwork(params);
2476
2477 const QuicByteCount transfer_size = 10 * 1024 * 1024;
2478 const QuicTime::Delta transfer_time =
2479 params.BottleneckBandwidth().TransferTime(transfer_size);
2480 QUIC_LOG(INFO) << "Single flow transfer time: " << transfer_time;
2481
2482 // Transfer 10% of data in first transfer.
2483 sender_endpoints_[0]->AddBytesToTransfer(transfer_size);
2484 bool simulator_result = simulator_.RunUntilOrTimeout(
2485 [this]() {
2486 return receiver_endpoints_[0]->bytes_received() >= 0.1 * transfer_size;
2487 },
2488 transfer_time);
2489 ASSERT_TRUE(simulator_result);
2490
2491 // Start the second transfer and wait until both finish.
2492 sender_endpoints_[1]->AddBytesToTransfer(transfer_size);
2493 simulator_result = simulator_.RunUntilOrTimeout(
2494 [this]() {
2495 return receiver_endpoints_[0]->bytes_received() == transfer_size &&
2496 receiver_endpoints_[1]->bytes_received() == transfer_size;
2497 },
2498 3 * transfer_time);
2499 ASSERT_TRUE(simulator_result);
2500 }
2501 */
2502
TEST_F(Bbr2MultiSenderTest,Bbr2VsBbr1)2503 TEST_F(Bbr2MultiSenderTest, Bbr2VsBbr1) {
2504 SetupBbrSender(sender_endpoints_[1].get());
2505
2506 MultiSenderTopologyParams params;
2507 CreateNetwork(params);
2508
2509 const QuicByteCount transfer_size = 10 * 1024 * 1024;
2510 const QuicTime::Delta transfer_time =
2511 params.BottleneckBandwidth().TransferTime(transfer_size);
2512 QUIC_LOG(INFO) << "Single flow transfer time: " << transfer_time;
2513
2514 // Transfer 10% of data in first transfer.
2515 sender_endpoints_[0]->AddBytesToTransfer(transfer_size);
2516 bool simulator_result = simulator_.RunUntilOrTimeout(
2517 [this]() {
2518 return receiver_endpoints_[0]->bytes_received() >= 0.1 * transfer_size;
2519 },
2520 transfer_time);
2521 ASSERT_TRUE(simulator_result);
2522
2523 // Start the second transfer and wait until both finish.
2524 sender_endpoints_[1]->AddBytesToTransfer(transfer_size);
2525 simulator_result = simulator_.RunUntilOrTimeout(
2526 [this]() {
2527 return receiver_endpoints_[0]->bytes_received() == transfer_size &&
2528 receiver_endpoints_[1]->bytes_received() == transfer_size;
2529 },
2530 3 * transfer_time);
2531 ASSERT_TRUE(simulator_result);
2532 }
2533
TEST_F(Bbr2MultiSenderTest,QUIC_SLOW_TEST (Bbr2VsReno))2534 TEST_F(Bbr2MultiSenderTest, QUIC_SLOW_TEST(Bbr2VsReno)) {
2535 SetupTcpSender(sender_endpoints_[1].get(), /*reno=*/true);
2536
2537 MultiSenderTopologyParams params;
2538 CreateNetwork(params);
2539
2540 const QuicByteCount transfer_size = 10 * 1024 * 1024;
2541 const QuicTime::Delta transfer_time =
2542 params.BottleneckBandwidth().TransferTime(transfer_size);
2543 QUIC_LOG(INFO) << "Single flow transfer time: " << transfer_time;
2544
2545 // Transfer 10% of data in first transfer.
2546 sender_endpoints_[0]->AddBytesToTransfer(transfer_size);
2547 bool simulator_result = simulator_.RunUntilOrTimeout(
2548 [this]() {
2549 return receiver_endpoints_[0]->bytes_received() >= 0.1 * transfer_size;
2550 },
2551 transfer_time);
2552 ASSERT_TRUE(simulator_result);
2553
2554 // Start the second transfer and wait until both finish.
2555 sender_endpoints_[1]->AddBytesToTransfer(transfer_size);
2556 simulator_result = simulator_.RunUntilOrTimeout(
2557 [this]() {
2558 return receiver_endpoints_[0]->bytes_received() == transfer_size &&
2559 receiver_endpoints_[1]->bytes_received() == transfer_size;
2560 },
2561 3 * transfer_time);
2562 ASSERT_TRUE(simulator_result);
2563 }
2564
TEST_F(Bbr2MultiSenderTest,QUIC_SLOW_TEST (Bbr2VsRenoB2RC))2565 TEST_F(Bbr2MultiSenderTest, QUIC_SLOW_TEST(Bbr2VsRenoB2RC)) {
2566 SetConnectionOption(sender_0_, kB2RC);
2567 SetupTcpSender(sender_endpoints_[1].get(), /*reno=*/true);
2568
2569 MultiSenderTopologyParams params;
2570 CreateNetwork(params);
2571
2572 const QuicByteCount transfer_size = 10 * 1024 * 1024;
2573 const QuicTime::Delta transfer_time =
2574 params.BottleneckBandwidth().TransferTime(transfer_size);
2575 QUIC_LOG(INFO) << "Single flow transfer time: " << transfer_time;
2576
2577 // Transfer 10% of data in first transfer.
2578 sender_endpoints_[0]->AddBytesToTransfer(transfer_size);
2579 bool simulator_result = simulator_.RunUntilOrTimeout(
2580 [this]() {
2581 return receiver_endpoints_[0]->bytes_received() >= 0.1 * transfer_size;
2582 },
2583 transfer_time);
2584 ASSERT_TRUE(simulator_result);
2585
2586 // Start the second transfer and wait until both finish.
2587 sender_endpoints_[1]->AddBytesToTransfer(transfer_size);
2588 simulator_result = simulator_.RunUntilOrTimeout(
2589 [this]() {
2590 return receiver_endpoints_[0]->bytes_received() == transfer_size &&
2591 receiver_endpoints_[1]->bytes_received() == transfer_size;
2592 },
2593 3 * transfer_time);
2594 ASSERT_TRUE(simulator_result);
2595 }
2596
TEST_F(Bbr2MultiSenderTest,QUIC_SLOW_TEST (Bbr2VsCubic))2597 TEST_F(Bbr2MultiSenderTest, QUIC_SLOW_TEST(Bbr2VsCubic)) {
2598 SetupTcpSender(sender_endpoints_[1].get(), /*reno=*/false);
2599
2600 MultiSenderTopologyParams params;
2601 CreateNetwork(params);
2602
2603 const QuicByteCount transfer_size = 50 * 1024 * 1024;
2604 const QuicTime::Delta transfer_time =
2605 params.BottleneckBandwidth().TransferTime(transfer_size);
2606 QUIC_LOG(INFO) << "Single flow transfer time: " << transfer_time;
2607
2608 // Transfer 10% of data in first transfer.
2609 sender_endpoints_[0]->AddBytesToTransfer(transfer_size);
2610 bool simulator_result = simulator_.RunUntilOrTimeout(
2611 [this]() {
2612 return receiver_endpoints_[0]->bytes_received() >= 0.1 * transfer_size;
2613 },
2614 transfer_time);
2615 ASSERT_TRUE(simulator_result);
2616
2617 // Start the second transfer and wait until both finish.
2618 sender_endpoints_[1]->AddBytesToTransfer(transfer_size);
2619 simulator_result = simulator_.RunUntilOrTimeout(
2620 [this]() {
2621 return receiver_endpoints_[0]->bytes_received() == transfer_size &&
2622 receiver_endpoints_[1]->bytes_received() == transfer_size;
2623 },
2624 3 * transfer_time);
2625 ASSERT_TRUE(simulator_result);
2626 }
2627
TEST(MinRttFilter,BadRttSample)2628 TEST(MinRttFilter, BadRttSample) {
2629 auto time_in_seconds = [](int64_t seconds) {
2630 return QuicTime::Zero() + QuicTime::Delta::FromSeconds(seconds);
2631 };
2632
2633 MinRttFilter filter(QuicTime::Delta::FromMilliseconds(10),
2634 time_in_seconds(100));
2635 ASSERT_EQ(filter.Get(), QuicTime::Delta::FromMilliseconds(10));
2636
2637 filter.Update(QuicTime::Delta::FromMilliseconds(-1), time_in_seconds(150));
2638
2639 EXPECT_EQ(filter.Get(), QuicTime::Delta::FromMilliseconds(10));
2640 EXPECT_EQ(filter.GetTimestamp(), time_in_seconds(100));
2641
2642 filter.ForceUpdate(QuicTime::Delta::FromMilliseconds(-2),
2643 time_in_seconds(200));
2644
2645 EXPECT_EQ(filter.Get(), QuicTime::Delta::FromMilliseconds(10));
2646 EXPECT_EQ(filter.GetTimestamp(), time_in_seconds(100));
2647 }
2648
2649 } // namespace test
2650 } // namespace quic
2651