Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "net/quic/test_tools/simulator/simulator.h" | 5 #include "net/quic/test_tools/simulator/simulator.h" |
| 6 | 6 |
| 7 #include "net/quic/platform/api/quic_logging.h" | 7 #include "net/quic/platform/api/quic_logging.h" |
| 8 #include "net/quic/platform/api/quic_ptr_util.h" | 8 #include "net/quic/platform/api/quic_ptr_util.h" |
| 9 #include "net/quic/test_tools/quic_test_utils.h" | 9 #include "net/quic/test_tools/quic_test_utils.h" |
| 10 #include "net/quic/test_tools/simulator/alarm_factory.h" | 10 #include "net/quic/test_tools/simulator/alarm_factory.h" |
| (...skipping 291 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 302 CounterPort counter; | 302 CounterPort counter; |
| 303 | 303 |
| 304 OneWayLink local_link(&simulator, "Local link", &queue, local_bandwidth, | 304 OneWayLink local_link(&simulator, "Local link", &queue, local_bandwidth, |
| 305 local_propagation_delay); | 305 local_propagation_delay); |
| 306 OneWayLink bottleneck_link(&simulator, "Bottleneck link", &counter, | 306 OneWayLink bottleneck_link(&simulator, "Bottleneck link", &counter, |
| 307 bottleneck_bandwidth, | 307 bottleneck_bandwidth, |
| 308 bottleneck_propagation_delay); | 308 bottleneck_propagation_delay); |
| 309 saturator.SetTxPort(&local_link); | 309 saturator.SetTxPort(&local_link); |
| 310 queue.set_tx_port(&bottleneck_link); | 310 queue.set_tx_port(&bottleneck_link); |
| 311 | 311 |
| 312 const QuicPacketCount packets_received = 1000; | 312 static const QuicPacketCount packets_received = 1000; |
|
eroman
2017/01/20 17:49:25
[optional] These should probably be renamed to kPa
krasin1
2017/01/20 18:02:20
Let's leave it as is. Yesterday, in a similar case
| |
| 313 simulator.RunUntil([&counter, packets_received]() { | 313 simulator.RunUntil( |
| 314 return counter.packets() == packets_received; | 314 [&counter]() { return counter.packets() == packets_received; }); |
| 315 }); | |
| 316 const double loss_ratio = | 315 const double loss_ratio = |
| 317 1 - | 316 1 - |
| 318 static_cast<double>(packets_received) / saturator.packets_transmitted(); | 317 static_cast<double>(packets_received) / saturator.packets_transmitted(); |
| 319 EXPECT_NEAR(loss_ratio, 0.9, 0.001); | 318 EXPECT_NEAR(loss_ratio, 0.9, 0.001); |
| 320 } | 319 } |
| 321 | 320 |
| 322 // Verify that the queue of exactly one packet allows the transmission to | 321 // Verify that the queue of exactly one packet allows the transmission to |
| 323 // actually go through. | 322 // actually go through. |
| 324 TEST(SimulatorTest, OnePacketQueue) { | 323 TEST(SimulatorTest, OnePacketQueue) { |
| 325 const QuicBandwidth local_bandwidth = | 324 const QuicBandwidth local_bandwidth = |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 336 CounterPort counter; | 335 CounterPort counter; |
| 337 | 336 |
| 338 OneWayLink local_link(&simulator, "Local link", &queue, local_bandwidth, | 337 OneWayLink local_link(&simulator, "Local link", &queue, local_bandwidth, |
| 339 local_propagation_delay); | 338 local_propagation_delay); |
| 340 OneWayLink bottleneck_link(&simulator, "Bottleneck link", &counter, | 339 OneWayLink bottleneck_link(&simulator, "Bottleneck link", &counter, |
| 341 bottleneck_bandwidth, | 340 bottleneck_bandwidth, |
| 342 bottleneck_propagation_delay); | 341 bottleneck_propagation_delay); |
| 343 saturator.SetTxPort(&local_link); | 342 saturator.SetTxPort(&local_link); |
| 344 queue.set_tx_port(&bottleneck_link); | 343 queue.set_tx_port(&bottleneck_link); |
| 345 | 344 |
| 346 const QuicPacketCount packets_received = 10; | 345 static const QuicPacketCount packets_received = 10; |
| 347 // The deadline here is to prevent this tests from looping infinitely in case | 346 // The deadline here is to prevent this tests from looping infinitely in case |
| 348 // the packets never reach the receiver. | 347 // the packets never reach the receiver. |
| 349 const QuicTime deadline = | 348 const QuicTime deadline = |
| 350 simulator.GetClock()->Now() + QuicTime::Delta::FromSeconds(10); | 349 simulator.GetClock()->Now() + QuicTime::Delta::FromSeconds(10); |
| 351 simulator.RunUntil([&simulator, &counter, packets_received, deadline]() { | 350 simulator.RunUntil([&simulator, &counter, deadline]() { |
| 352 return counter.packets() == packets_received || | 351 return counter.packets() == packets_received || |
| 353 simulator.GetClock()->Now() > deadline; | 352 simulator.GetClock()->Now() > deadline; |
| 354 }); | 353 }); |
| 355 ASSERT_EQ(packets_received, counter.packets()); | 354 ASSERT_EQ(packets_received, counter.packets()); |
| 356 } | 355 } |
| 357 | 356 |
| 358 // Simulate a network where three endpoints are connected to a switch and they | 357 // Simulate a network where three endpoints are connected to a switch and they |
| 359 // are sending traffic in circle (1 -> 2, 2 -> 3, 3 -> 1). | 358 // are sending traffic in circle (1 -> 2, 2 -> 3, 3 -> 1). |
| 360 TEST(SimulatorTest, SwitchedNetwork) { | 359 TEST(SimulatorTest, SwitchedNetwork) { |
| 361 const QuicBandwidth bandwidth = QuicBandwidth::FromBytesPerSecond(10000); | 360 const QuicBandwidth bandwidth = QuicBandwidth::FromBytesPerSecond(10000); |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 372 // For determinicity, make it so that the first packet will arrive from | 371 // For determinicity, make it so that the first packet will arrive from |
| 373 // Saturator 1, then from Saturator 2, and then from Saturator 3. | 372 // Saturator 1, then from Saturator 2, and then from Saturator 3. |
| 374 SymmetricLink link1(&saturator1, network_switch.port(1), bandwidth, | 373 SymmetricLink link1(&saturator1, network_switch.port(1), bandwidth, |
| 375 base_propagation_delay); | 374 base_propagation_delay); |
| 376 SymmetricLink link2(&saturator2, network_switch.port(2), bandwidth, | 375 SymmetricLink link2(&saturator2, network_switch.port(2), bandwidth, |
| 377 base_propagation_delay * 2); | 376 base_propagation_delay * 2); |
| 378 SymmetricLink link3(&saturator3, network_switch.port(3), bandwidth, | 377 SymmetricLink link3(&saturator3, network_switch.port(3), bandwidth, |
| 379 base_propagation_delay * 3); | 378 base_propagation_delay * 3); |
| 380 | 379 |
| 381 const QuicTime start_time = simulator.GetClock()->Now(); | 380 const QuicTime start_time = simulator.GetClock()->Now(); |
| 382 const QuicPacketCount bytes_received = 64 * 1000; | 381 static const QuicPacketCount bytes_received = 64 * 1000; |
| 383 simulator.RunUntil([&saturator1, bytes_received]() { | 382 simulator.RunUntil([&saturator1]() { |
| 384 return saturator1.counter()->bytes() >= bytes_received; | 383 return saturator1.counter()->bytes() >= bytes_received; |
| 385 }); | 384 }); |
| 386 const QuicTime end_time = simulator.GetClock()->Now(); | 385 const QuicTime end_time = simulator.GetClock()->Now(); |
| 387 | 386 |
| 388 const QuicBandwidth observed_bandwidth = QuicBandwidth::FromBytesAndTimeDelta( | 387 const QuicBandwidth observed_bandwidth = QuicBandwidth::FromBytesAndTimeDelta( |
| 389 bytes_received, end_time - start_time); | 388 bytes_received, end_time - start_time); |
| 390 const double bandwidth_ratio = | 389 const double bandwidth_ratio = |
| 391 static_cast<double>(observed_bandwidth.ToBitsPerSecond()) / | 390 static_cast<double>(observed_bandwidth.ToBitsPerSecond()) / |
| 392 bandwidth.ToBitsPerSecond(); | 391 bandwidth.ToBitsPerSecond(); |
| 393 EXPECT_NEAR(1, bandwidth_ratio, 0.1); | 392 EXPECT_NEAR(1, bandwidth_ratio, 0.1); |
| (...skipping 229 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 623 const QuicTime::Delta base_propagation_delay = | 622 const QuicTime::Delta base_propagation_delay = |
| 624 QuicTime::Delta::FromMilliseconds(5); | 623 QuicTime::Delta::FromMilliseconds(5); |
| 625 const QuicTime::Delta timeout = QuicTime::Delta::FromSeconds(10); | 624 const QuicTime::Delta timeout = QuicTime::Delta::FromSeconds(10); |
| 626 | 625 |
| 627 Simulator simulator; | 626 Simulator simulator; |
| 628 LinkSaturator saturator1(&simulator, "Saturator 1", 1000, "Saturator 2"); | 627 LinkSaturator saturator1(&simulator, "Saturator 1", 1000, "Saturator 2"); |
| 629 LinkSaturator saturator2(&simulator, "Saturator 2", 1000, "Saturator 1"); | 628 LinkSaturator saturator2(&simulator, "Saturator 2", 1000, "Saturator 1"); |
| 630 Switch network_switch(&simulator, "Switch", 8, | 629 Switch network_switch(&simulator, "Switch", 8, |
| 631 bandwidth * base_propagation_delay * 10); | 630 bandwidth * base_propagation_delay * 10); |
| 632 | 631 |
| 633 const QuicByteCount initial_burst = 1000 * 10; | 632 static const QuicByteCount initial_burst = 1000 * 10; |
| 634 const QuicByteCount max_bucket_size = 1000 * 100; | 633 static const QuicByteCount max_bucket_size = 1000 * 100; |
| 635 const QuicBandwidth target_bandwidth = bandwidth * 0.25; | 634 static const QuicBandwidth target_bandwidth = bandwidth * 0.25; |
| 636 TrafficPolicer policer(&simulator, "Policer", initial_burst, max_bucket_size, | 635 TrafficPolicer policer(&simulator, "Policer", initial_burst, max_bucket_size, |
| 637 target_bandwidth, network_switch.port(2)); | 636 target_bandwidth, network_switch.port(2)); |
| 638 | 637 |
| 639 SymmetricLink link1(&saturator1, network_switch.port(1), bandwidth, | 638 SymmetricLink link1(&saturator1, network_switch.port(1), bandwidth, |
| 640 base_propagation_delay); | 639 base_propagation_delay); |
| 641 SymmetricLink link2(&saturator2, &policer, bandwidth, base_propagation_delay); | 640 SymmetricLink link2(&saturator2, &policer, bandwidth, base_propagation_delay); |
| 642 | 641 |
| 643 // Ensure the initial burst passes without being dropped at all. | 642 // Ensure the initial burst passes without being dropped at all. |
| 644 bool simulator_result = simulator.RunUntilOrTimeout( | 643 bool simulator_result = simulator.RunUntilOrTimeout( |
| 645 [&saturator1, initial_burst]() { | 644 [&saturator1]() { |
| 646 return saturator1.bytes_transmitted() == initial_burst; | 645 return saturator1.bytes_transmitted() == initial_burst; |
| 647 }, | 646 }, |
| 648 timeout); | 647 timeout); |
| 649 ASSERT_TRUE(simulator_result); | 648 ASSERT_TRUE(simulator_result); |
| 650 saturator1.Pause(); | 649 saturator1.Pause(); |
| 651 simulator_result = simulator.RunUntilOrTimeout( | 650 simulator_result = simulator.RunUntilOrTimeout( |
| 652 [&saturator2, initial_burst]() { | 651 [&saturator2]() { |
| 653 return saturator2.counter()->bytes() == initial_burst; | 652 return saturator2.counter()->bytes() == initial_burst; |
| 654 }, | 653 }, |
| 655 timeout); | 654 timeout); |
| 656 ASSERT_TRUE(simulator_result); | 655 ASSERT_TRUE(simulator_result); |
| 657 saturator1.Resume(); | 656 saturator1.Resume(); |
| 658 | 657 |
| 659 // Run for some time so that the initial burst is not visible. | 658 // Run for some time so that the initial burst is not visible. |
| 660 const QuicTime::Delta simulation_time = QuicTime::Delta::FromSeconds(10); | 659 const QuicTime::Delta simulation_time = QuicTime::Delta::FromSeconds(10); |
| 661 simulator.RunFor(simulation_time); | 660 simulator.RunFor(simulation_time); |
| 662 | 661 |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 724 | 723 |
| 725 // Expect subsequent traffic to be policed. | 724 // Expect subsequent traffic to be policed. |
| 726 saturator1.Resume(); | 725 saturator1.Resume(); |
| 727 simulator.RunFor(QuicTime::Delta::FromSeconds(10)); | 726 simulator.RunFor(QuicTime::Delta::FromSeconds(10)); |
| 728 test::ExpectApproxEq(saturator1.bytes_transmitted() / 4, | 727 test::ExpectApproxEq(saturator1.bytes_transmitted() / 4, |
| 729 saturator2.counter()->bytes(), 0.1f); | 728 saturator2.counter()->bytes(), 0.1f); |
| 730 } | 729 } |
| 731 | 730 |
| 732 } // namespace simulator | 731 } // namespace simulator |
| 733 } // namespace net | 732 } // namespace net |
| OLD | NEW |