Add ability to specify random seed when creating built it network emulation
Bug: webrtc:12340 Change-Id: Iffd054928249099866ef4527b911b1e358e26f5a Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/200805 Reviewed-by: Mirko Bonadei <mbonadei@webrtc.org> Commit-Queue: Artem Titov <titovartem@webrtc.org> Cr-Commit-Position: refs/heads/master@{#32920}
This commit is contained in:
parent
82e1875c7d
commit
ec9b281bbc
@ -56,18 +56,20 @@ NetworkEmulationManager::SimulatedNetworkNode::Builder::packet_queue_length(
|
|||||||
}
|
}
|
||||||
|
|
||||||
NetworkEmulationManager::SimulatedNetworkNode
|
NetworkEmulationManager::SimulatedNetworkNode
|
||||||
NetworkEmulationManager::SimulatedNetworkNode::Builder::Build() const {
|
NetworkEmulationManager::SimulatedNetworkNode::Builder::Build(
|
||||||
|
uint64_t random_seed) const {
|
||||||
RTC_CHECK(net_);
|
RTC_CHECK(net_);
|
||||||
return Build(net_);
|
return Build(net_, random_seed);
|
||||||
}
|
}
|
||||||
|
|
||||||
NetworkEmulationManager::SimulatedNetworkNode
|
NetworkEmulationManager::SimulatedNetworkNode
|
||||||
NetworkEmulationManager::SimulatedNetworkNode::Builder::Build(
|
NetworkEmulationManager::SimulatedNetworkNode::Builder::Build(
|
||||||
NetworkEmulationManager* net) const {
|
NetworkEmulationManager* net,
|
||||||
|
uint64_t random_seed) const {
|
||||||
RTC_CHECK(net);
|
RTC_CHECK(net);
|
||||||
RTC_CHECK(net_ == nullptr || net_ == net);
|
RTC_CHECK(net_ == nullptr || net_ == net);
|
||||||
SimulatedNetworkNode res;
|
SimulatedNetworkNode res;
|
||||||
auto behavior = std::make_unique<SimulatedNetwork>(config_);
|
auto behavior = std::make_unique<SimulatedNetwork>(config_, random_seed);
|
||||||
res.simulation = behavior.get();
|
res.simulation = behavior.get();
|
||||||
res.node = net->CreateEmulatedNode(std::move(behavior));
|
res.node = net->CreateEmulatedNode(std::move(behavior));
|
||||||
return res;
|
return res;
|
||||||
|
|||||||
@ -152,8 +152,9 @@ class NetworkEmulationManager {
|
|||||||
Builder& capacity_Mbps(int link_capacity_Mbps);
|
Builder& capacity_Mbps(int link_capacity_Mbps);
|
||||||
Builder& loss(double loss_rate);
|
Builder& loss(double loss_rate);
|
||||||
Builder& packet_queue_length(int max_queue_length_in_packets);
|
Builder& packet_queue_length(int max_queue_length_in_packets);
|
||||||
SimulatedNetworkNode Build() const;
|
SimulatedNetworkNode Build(uint64_t random_seed = 1) const;
|
||||||
SimulatedNetworkNode Build(NetworkEmulationManager* net) const;
|
SimulatedNetworkNode Build(NetworkEmulationManager* net,
|
||||||
|
uint64_t random_seed = 1) const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
NetworkEmulationManager* const net_;
|
NetworkEmulationManager* const net_;
|
||||||
@ -165,9 +166,15 @@ class NetworkEmulationManager {
|
|||||||
virtual TimeController* time_controller() = 0;
|
virtual TimeController* time_controller() = 0;
|
||||||
|
|
||||||
// Creates an emulated network node, which represents single network in
|
// Creates an emulated network node, which represents single network in
|
||||||
// the emulated network layer.
|
// the emulated network layer. Uses default implementation on network behavior
|
||||||
|
// which can be configured with |config|. |random_seed| can be provided to
|
||||||
|
// alter randomization behavior.
|
||||||
virtual EmulatedNetworkNode* CreateEmulatedNode(
|
virtual EmulatedNetworkNode* CreateEmulatedNode(
|
||||||
BuiltInNetworkBehaviorConfig config) = 0;
|
BuiltInNetworkBehaviorConfig config,
|
||||||
|
uint64_t random_seed = 1) = 0;
|
||||||
|
// Creates an emulated network node, which represents single network in
|
||||||
|
// the emulated network layer. |network_behavior| determines how created node
|
||||||
|
// will forward incoming packets to the next receiver.
|
||||||
virtual EmulatedNetworkNode* CreateEmulatedNode(
|
virtual EmulatedNetworkNode* CreateEmulatedNode(
|
||||||
std::unique_ptr<NetworkBehaviorInterface> network_behavior) = 0;
|
std::unique_ptr<NetworkBehaviorInterface> network_behavior) = 0;
|
||||||
|
|
||||||
|
|||||||
@ -66,7 +66,8 @@ class Random {
|
|||||||
double Exponential(double lambda);
|
double Exponential(double lambda);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
// Outputs a nonzero 64-bit random number.
|
// Outputs a nonzero 64-bit random number using Xorshift algorithm.
|
||||||
|
// https://en.wikipedia.org/wiki/Xorshift
|
||||||
uint64_t NextOutput() {
|
uint64_t NextOutput() {
|
||||||
state_ ^= state_ >> 12;
|
state_ ^= state_ >> 12;
|
||||||
state_ ^= state_ << 25;
|
state_ ^= state_ << 25;
|
||||||
|
|||||||
@ -63,8 +63,10 @@ NetworkEmulationManagerImpl::~NetworkEmulationManagerImpl() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
EmulatedNetworkNode* NetworkEmulationManagerImpl::CreateEmulatedNode(
|
EmulatedNetworkNode* NetworkEmulationManagerImpl::CreateEmulatedNode(
|
||||||
BuiltInNetworkBehaviorConfig config) {
|
BuiltInNetworkBehaviorConfig config,
|
||||||
return CreateEmulatedNode(std::make_unique<SimulatedNetwork>(config));
|
uint64_t random_seed) {
|
||||||
|
return CreateEmulatedNode(
|
||||||
|
std::make_unique<SimulatedNetwork>(config, random_seed));
|
||||||
}
|
}
|
||||||
|
|
||||||
EmulatedNetworkNode* NetworkEmulationManagerImpl::CreateEmulatedNode(
|
EmulatedNetworkNode* NetworkEmulationManagerImpl::CreateEmulatedNode(
|
||||||
|
|||||||
@ -44,8 +44,8 @@ class NetworkEmulationManagerImpl : public NetworkEmulationManager {
|
|||||||
explicit NetworkEmulationManagerImpl(TimeMode mode);
|
explicit NetworkEmulationManagerImpl(TimeMode mode);
|
||||||
~NetworkEmulationManagerImpl();
|
~NetworkEmulationManagerImpl();
|
||||||
|
|
||||||
EmulatedNetworkNode* CreateEmulatedNode(
|
EmulatedNetworkNode* CreateEmulatedNode(BuiltInNetworkBehaviorConfig config,
|
||||||
BuiltInNetworkBehaviorConfig config) override;
|
uint64_t random_seed = 1) override;
|
||||||
EmulatedNetworkNode* CreateEmulatedNode(
|
EmulatedNetworkNode* CreateEmulatedNode(
|
||||||
std::unique_ptr<NetworkBehaviorInterface> network_behavior) override;
|
std::unique_ptr<NetworkBehaviorInterface> network_behavior) override;
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user