Pass random seed to SchedulableNetworkBehavior.
Change-Id: Icd2b2e638773243df26de3e163b18c9bd42c9245 Bug: None Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/354721 Commit-Queue: Jeremy Leconte <jleconte@google.com> Reviewed-by: Per Kjellander <perkj@webrtc.org> Reviewed-by: Björn Terelius <terelius@webrtc.org> Cr-Commit-Position: refs/heads/main@{#42514}
This commit is contained in:
parent
d5238b0998
commit
defafcb86e
@ -10,6 +10,7 @@
|
||||
#include "api/test/network_emulation/schedulable_network_node_builder.h"
|
||||
|
||||
#include <memory>
|
||||
#include <optional>
|
||||
#include <utility>
|
||||
|
||||
#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<uint64_t> random_seed) {
|
||||
uint64_t seed = random_seed.has_value()
|
||||
? *random_seed
|
||||
: static_cast<uint64_t>(rtc::TimeNanos());
|
||||
return net_.CreateEmulatedNode(std::make_unique<SchedulableNetworkBehavior>(
|
||||
std::move(schedule_), *net_.time_controller()->GetClock(),
|
||||
std::move(schedule_), seed, *net_.time_controller()->GetClock(),
|
||||
std::move(start_condition_)));
|
||||
}
|
||||
} // namespace webrtc
|
||||
|
||||
@ -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 <cstdint>
|
||||
#include <optional>
|
||||
|
||||
#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<bool(webrtc::Timestamp)> 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<uint64_t> random_seed = std::nullopt);
|
||||
|
||||
private:
|
||||
webrtc::NetworkEmulationManager& net_;
|
||||
|
||||
@ -9,6 +9,7 @@
|
||||
*/
|
||||
#include "test/network/schedulable_network_behavior.h"
|
||||
|
||||
#include <cstdint>
|
||||
#include <utility>
|
||||
|
||||
#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<bool(webrtc::Timestamp)> start_callback)
|
||||
: SimulatedNetwork(GetInitialConfig(schedule)),
|
||||
: SimulatedNetwork(GetInitialConfig(schedule), random_seed),
|
||||
schedule_(std::move(schedule)),
|
||||
start_condition_(std::move(start_callback)),
|
||||
clock_(clock),
|
||||
|
||||
@ -11,6 +11,8 @@
|
||||
#ifndef TEST_NETWORK_SCHEDULABLE_NETWORK_BEHAVIOR_H_
|
||||
#define TEST_NETWORK_SCHEDULABLE_NETWORK_BEHAVIOR_H_
|
||||
|
||||
#include <cstdint>
|
||||
|
||||
#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<bool(webrtc::Timestamp)> start_condition =
|
||||
[](webrtc::Timestamp) { return true; });
|
||||
|
||||
@ -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<void()> 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(
|
||||
|
||||
@ -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());
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user