From defafcb86ed2b4a9601d9d367ea48bc2b77c6125 Mon Sep 17 00:00:00 2001 From: Jeremy Leconte Date: Tue, 18 Jun 2024 15:06:49 +0200 Subject: [PATCH] Pass random seed to SchedulableNetworkBehavior. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Change-Id: Icd2b2e638773243df26de3e163b18c9bd42c9245 Bug: None Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/354721 Commit-Queue: Jeremy Leconte Reviewed-by: Per Kjellander Reviewed-by: Björn Terelius Cr-Commit-Position: refs/heads/main@{#42514} --- .../schedulable_network_node_builder.cc | 9 ++++++-- .../schedulable_network_node_builder.h | 8 ++++++- test/network/schedulable_network_behavior.cc | 4 +++- test/network/schedulable_network_behavior.h | 3 +++ .../schedulable_network_behavior_test.cc | 21 ++++++++++++------- test/peer_scenario/tests/bwe_ramp_up_test.cc | 2 +- 6 files changed, 35 insertions(+), 12 deletions(-) diff --git a/api/test/network_emulation/schedulable_network_node_builder.cc b/api/test/network_emulation/schedulable_network_node_builder.cc index b4ca1eb6af..41c66d8581 100644 --- a/api/test/network_emulation/schedulable_network_node_builder.cc +++ b/api/test/network_emulation/schedulable_network_node_builder.cc @@ -10,6 +10,7 @@ #include "api/test/network_emulation/schedulable_network_node_builder.h" #include +#include #include #include "absl/functional/any_invocable.h" @@ -32,9 +33,13 @@ void SchedulableNetworkNodeBuilder::set_start_condition( start_condition_ = std::move(start_condition); } -webrtc::EmulatedNetworkNode* SchedulableNetworkNodeBuilder::Build() { +webrtc::EmulatedNetworkNode* SchedulableNetworkNodeBuilder::Build( + std::optional random_seed) { + uint64_t seed = random_seed.has_value() + ? *random_seed + : static_cast(rtc::TimeNanos()); return net_.CreateEmulatedNode(std::make_unique( - std::move(schedule_), *net_.time_controller()->GetClock(), + std::move(schedule_), seed, *net_.time_controller()->GetClock(), std::move(start_condition_))); } } // namespace webrtc diff --git a/api/test/network_emulation/schedulable_network_node_builder.h b/api/test/network_emulation/schedulable_network_node_builder.h index 928d1e6947..9ac6547a32 100644 --- a/api/test/network_emulation/schedulable_network_node_builder.h +++ b/api/test/network_emulation/schedulable_network_node_builder.h @@ -10,6 +10,9 @@ #ifndef API_TEST_NETWORK_EMULATION_SCHEDULABLE_NETWORK_NODE_BUILDER_H_ #define API_TEST_NETWORK_EMULATION_SCHEDULABLE_NETWORK_NODE_BUILDER_H_ +#include +#include + #include "absl/functional/any_invocable.h" #include "api/test/network_emulation/network_config_schedule.pb.h" #include "api/test/network_emulation_manager.h" @@ -30,7 +33,10 @@ class SchedulableNetworkNodeBuilder { void set_start_condition( absl::AnyInvocable start_condition); - webrtc::EmulatedNetworkNode* Build(); + // If no random seed is provided, one will be created. + // The random seed is required for loss rate and to delay standard deviation. + webrtc::EmulatedNetworkNode* Build( + std::optional random_seed = std::nullopt); private: webrtc::NetworkEmulationManager& net_; diff --git a/test/network/schedulable_network_behavior.cc b/test/network/schedulable_network_behavior.cc index a3291d0886..67c738c04c 100644 --- a/test/network/schedulable_network_behavior.cc +++ b/test/network/schedulable_network_behavior.cc @@ -9,6 +9,7 @@ */ #include "test/network/schedulable_network_behavior.h" +#include #include #include "absl/functional/any_invocable.h" @@ -72,9 +73,10 @@ BuiltInNetworkBehaviorConfig GetInitialConfig( SchedulableNetworkBehavior::SchedulableNetworkBehavior( network_behaviour::NetworkConfigSchedule schedule, + uint64_t random_seed, webrtc::Clock& clock, absl::AnyInvocable start_callback) - : SimulatedNetwork(GetInitialConfig(schedule)), + : SimulatedNetwork(GetInitialConfig(schedule), random_seed), schedule_(std::move(schedule)), start_condition_(std::move(start_callback)), clock_(clock), diff --git a/test/network/schedulable_network_behavior.h b/test/network/schedulable_network_behavior.h index c5300d64a2..53cf05de94 100644 --- a/test/network/schedulable_network_behavior.h +++ b/test/network/schedulable_network_behavior.h @@ -11,6 +11,8 @@ #ifndef TEST_NETWORK_SCHEDULABLE_NETWORK_BEHAVIOR_H_ #define TEST_NETWORK_SCHEDULABLE_NETWORK_BEHAVIOR_H_ +#include + #include "absl/functional/any_invocable.h" #include "api/sequence_checker.h" #include "api/test/network_emulation/network_config_schedule.pb.h" @@ -30,6 +32,7 @@ class SchedulableNetworkBehavior : public SimulatedNetwork { public: SchedulableNetworkBehavior( network_behaviour::NetworkConfigSchedule schedule, + uint64_t random_seed, Clock& clock, absl::AnyInvocable start_condition = [](webrtc::Timestamp) { return true; }); diff --git a/test/network/schedulable_network_behavior_test.cc b/test/network/schedulable_network_behavior_test.cc index e76f224b0f..5ab77f3d45 100644 --- a/test/network/schedulable_network_behavior_test.cc +++ b/test/network/schedulable_network_behavior_test.cc @@ -31,6 +31,8 @@ using ::testing::Return; using ::testing::Sequence; using ::testing::SizeIs; +constexpr uint64_t kRandomSeed = 1; + class SchedulableNetworkBehaviorTestFixture { public: SchedulableNetworkBehaviorTestFixture() @@ -61,7 +63,8 @@ TEST(SchedulableNetworkBehaviorTest, NoSchedule) { SchedulableNetworkBehaviorTestFixture fixture; network_behaviour::NetworkConfigSchedule schedule; - SchedulableNetworkBehavior network_behaviour(schedule, fixture.clock()); + SchedulableNetworkBehavior network_behaviour(schedule, kRandomSeed, + fixture.clock()); webrtc::Timestamp send_time = fixture.TimeNow(); EXPECT_TRUE(network_behaviour.EnqueuePacket({/*size=*/1000 / 8, /*send_time_us=*/send_time.us(), @@ -81,7 +84,8 @@ TEST(SchedulableNetworkBehaviorTest, ScheduleWithoutUpdates) { initial_config->set_link_capacity_kbps(10); initial_config->set_queue_delay_ms(70); - SchedulableNetworkBehavior network_behaviour(schedule, fixture.clock()); + SchedulableNetworkBehavior network_behaviour(schedule, kRandomSeed, + fixture.clock()); webrtc::Timestamp send_time = fixture.TimeNow(); EXPECT_TRUE(network_behaviour.EnqueuePacket({/*size=*/1000 / 8, /*send_time_us=*/send_time.us(), @@ -119,7 +123,8 @@ TEST(SchedulableNetworkBehaviorTest, // 55ms. updated_capacity->set_link_capacity_kbps(100); - SchedulableNetworkBehavior network_behaviour(schedule, fixture.clock()); + SchedulableNetworkBehavior network_behaviour(schedule, kRandomSeed, + fixture.clock()); MockFunction delivery_time_changed_callback; network_behaviour.RegisterDeliveryTimeChangedCallback( delivery_time_changed_callback.AsStdFunction()); @@ -170,8 +175,8 @@ TEST(SchedulableNetworkBehaviorTest, ScheduleStartedWhenStartConditionTrue) { EXPECT_CALL(start_condition, Call(second_packet_send_time)) .InSequence(s) .WillOnce(Return(true)); - SchedulableNetworkBehavior network_behaviour(schedule, fixture.clock(), - start_condition.AsStdFunction()); + SchedulableNetworkBehavior network_behaviour( + schedule, kRandomSeed, fixture.clock(), start_condition.AsStdFunction()); EXPECT_TRUE(network_behaviour.EnqueuePacket( {/*size=*/1000 / 8, @@ -207,7 +212,8 @@ TEST(SchedulableNetworkBehaviorTest, ScheduleWithRepeat) { // config should again take 100ms to send. schedule.set_repeat_schedule_after_last_ms(200); - SchedulableNetworkBehavior network_behaviour(schedule, fixture.clock()); + SchedulableNetworkBehavior network_behaviour(schedule, kRandomSeed, + fixture.clock()); webrtc::Timestamp first_packet_send_time = fixture.TimeNow(); EXPECT_TRUE(network_behaviour.EnqueuePacket( @@ -247,7 +253,8 @@ TEST(SchedulableNetworkBehaviorTest, ScheduleWithoutRepeat) { // A packet of size 1000 bits should take 10ms to send. updated_capacity->set_link_capacity_kbps(100); - SchedulableNetworkBehavior network_behaviour(schedule, fixture.clock()); + SchedulableNetworkBehavior network_behaviour(schedule, kRandomSeed, + fixture.clock()); webrtc::Timestamp first_packet_send_time = fixture.TimeNow(); EXPECT_TRUE(network_behaviour.EnqueuePacket( diff --git a/test/peer_scenario/tests/bwe_ramp_up_test.cc b/test/peer_scenario/tests/bwe_ramp_up_test.cc index 9879ed5336..36e643ad0b 100644 --- a/test/peer_scenario/tests/bwe_ramp_up_test.cc +++ b/test/peer_scenario/tests/bwe_ramp_up_test.cc @@ -73,7 +73,7 @@ TEST(BweRampupTest, BweRampUpWhenCapacityIncrease) { SchedulableNetworkNodeBuilder schedulable_builder(*s.net(), std::move(schedule)); - auto caller_node = schedulable_builder.Build(); + auto caller_node = schedulable_builder.Build(/*random_seed=*/1); auto callee_node = s.net()->NodeBuilder().capacity_kbps(5000).Build().node; s.net()->CreateRoute(caller->endpoint(), {caller_node}, callee->endpoint()); s.net()->CreateRoute(callee->endpoint(), {callee_node}, caller->endpoint());