Adds simulated network node builder.
Bug: webrtc:10839 Change-Id: I8fd7efc928e418bee3871c3870adb6d9061348fe Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/147274 Commit-Queue: Sebastian Jansson <srte@webrtc.org> Reviewed-by: Erik Språng <sprang@webrtc.org> Cr-Commit-Position: refs/heads/master@{#28724}
This commit is contained in:

committed by
Commit Bot

parent
e05ae5bbbb
commit
8d3e4bd9a6
@ -30,6 +30,8 @@ rtc_source_set("emulated_network") {
|
||||
"network_emulation.h",
|
||||
"network_emulation_manager.cc",
|
||||
"network_emulation_manager.h",
|
||||
"simulated_network_node.cc",
|
||||
"simulated_network_node.h",
|
||||
"traffic_route.cc",
|
||||
"traffic_route.h",
|
||||
]
|
||||
|
@ -87,6 +87,10 @@ EmulatedNetworkNode* NetworkEmulationManagerImpl::CreateEmulatedNode(
|
||||
return out;
|
||||
}
|
||||
|
||||
SimulatedNetworkNode::Builder NetworkEmulationManagerImpl::NodeBuilder() {
|
||||
return SimulatedNetworkNode::Builder(this);
|
||||
}
|
||||
|
||||
EmulatedEndpoint* NetworkEmulationManagerImpl::CreateEndpoint(
|
||||
EmulatedEndpointConfig config) {
|
||||
absl::optional<rtc::IPAddress> ip = config.ip;
|
||||
|
@ -31,6 +31,7 @@
|
||||
#include "test/network/emulated_network_manager.h"
|
||||
#include "test/network/fake_network_socket_server.h"
|
||||
#include "test/network/network_emulation.h"
|
||||
#include "test/network/simulated_network_node.h"
|
||||
#include "test/network/traffic_route.h"
|
||||
#include "test/time_controller/time_controller.h"
|
||||
|
||||
@ -48,6 +49,8 @@ class NetworkEmulationManagerImpl : public NetworkEmulationManager {
|
||||
EmulatedNetworkNode* CreateEmulatedNode(
|
||||
std::unique_ptr<NetworkBehaviorInterface> network_behavior) override;
|
||||
|
||||
SimulatedNetworkNode::Builder NodeBuilder();
|
||||
|
||||
EmulatedEndpoint* CreateEndpoint(EmulatedEndpointConfig config) override;
|
||||
void EnableEndpoint(EmulatedEndpoint* endpoint) override;
|
||||
void DisableEndpoint(EmulatedEndpoint* endpoint) override;
|
||||
|
69
test/network/simulated_network_node.cc
Normal file
69
test/network/simulated_network_node.cc
Normal file
@ -0,0 +1,69 @@
|
||||
/*
|
||||
* Copyright (c) 2019 The WebRTC project authors. All Rights Reserved.
|
||||
*
|
||||
* Use of this source code is governed by a BSD-style license
|
||||
* that can be found in the LICENSE file in the root of the source
|
||||
* tree. An additional intellectual property rights grant can be found
|
||||
* in the file PATENTS. All contributing project authors may
|
||||
* be found in the AUTHORS file in the root of the source tree.
|
||||
*/
|
||||
#include "test/network/simulated_network_node.h"
|
||||
|
||||
#include <utility>
|
||||
|
||||
#include "absl/memory/memory.h"
|
||||
|
||||
namespace webrtc {
|
||||
namespace test {
|
||||
|
||||
SimulatedNetworkNode::Builder::Builder() {}
|
||||
|
||||
SimulatedNetworkNode::Builder::Builder(NetworkEmulationManager* net)
|
||||
: net_(net) {}
|
||||
|
||||
SimulatedNetworkNode::Builder& SimulatedNetworkNode::Builder::config(
|
||||
SimulatedNetwork::Config config) {
|
||||
config_ = config;
|
||||
return *this;
|
||||
}
|
||||
|
||||
SimulatedNetworkNode::Builder& SimulatedNetworkNode::Builder::delay_ms(
|
||||
int queue_delay_ms) {
|
||||
config_.queue_delay_ms = queue_delay_ms;
|
||||
return *this;
|
||||
}
|
||||
|
||||
SimulatedNetworkNode::Builder& SimulatedNetworkNode::Builder::capacity_kbps(
|
||||
int link_capacity_kbps) {
|
||||
config_.link_capacity_kbps = link_capacity_kbps;
|
||||
return *this;
|
||||
}
|
||||
|
||||
SimulatedNetworkNode::Builder& SimulatedNetworkNode::Builder::capacity_Mbps(
|
||||
int link_capacity_Mbps) {
|
||||
config_.link_capacity_kbps = link_capacity_Mbps * 1000;
|
||||
return *this;
|
||||
}
|
||||
|
||||
SimulatedNetworkNode::Builder& SimulatedNetworkNode::Builder::loss(
|
||||
double loss_rate) {
|
||||
config_.loss_percent = std::round(loss_rate * 100);
|
||||
return *this;
|
||||
}
|
||||
|
||||
SimulatedNetworkNode SimulatedNetworkNode::Builder::Build() const {
|
||||
RTC_DCHECK(net_);
|
||||
return Build(net_);
|
||||
}
|
||||
|
||||
SimulatedNetworkNode SimulatedNetworkNode::Builder::Build(
|
||||
NetworkEmulationManager* net) const {
|
||||
SimulatedNetworkNode res;
|
||||
auto behavior = absl::make_unique<SimulatedNetwork>(config_);
|
||||
res.simulation = behavior.get();
|
||||
res.node = net->CreateEmulatedNode(std::move(behavior));
|
||||
return res;
|
||||
}
|
||||
|
||||
} // namespace test
|
||||
} // namespace webrtc
|
42
test/network/simulated_network_node.h
Normal file
42
test/network/simulated_network_node.h
Normal file
@ -0,0 +1,42 @@
|
||||
/*
|
||||
* Copyright (c) 2019 The WebRTC project authors. All Rights Reserved.
|
||||
*
|
||||
* Use of this source code is governed by a BSD-style license
|
||||
* that can be found in the LICENSE file in the root of the source
|
||||
* tree. An additional intellectual property rights grant can be found
|
||||
* in the file PATENTS. All contributing project authors may
|
||||
* be found in the AUTHORS file in the root of the source tree.
|
||||
*/
|
||||
#ifndef TEST_NETWORK_SIMULATED_NETWORK_NODE_H_
|
||||
#define TEST_NETWORK_SIMULATED_NETWORK_NODE_H_
|
||||
|
||||
#include "api/test/network_emulation_manager.h"
|
||||
#include "call/simulated_network.h"
|
||||
|
||||
namespace webrtc {
|
||||
namespace test {
|
||||
// Helper struct to simplify creation of simulated network behaviors.
|
||||
struct SimulatedNetworkNode {
|
||||
SimulatedNetwork* simulation;
|
||||
EmulatedNetworkNode* node;
|
||||
class Builder {
|
||||
public:
|
||||
Builder();
|
||||
explicit Builder(NetworkEmulationManager* net);
|
||||
Builder& config(SimulatedNetwork::Config config);
|
||||
Builder& delay_ms(int queue_delay_ms);
|
||||
Builder& capacity_kbps(int link_capacity_kbps);
|
||||
Builder& capacity_Mbps(int link_capacity_Mbps);
|
||||
Builder& loss(double loss_rate);
|
||||
SimulatedNetworkNode Build() const;
|
||||
SimulatedNetworkNode Build(NetworkEmulationManager* net) const;
|
||||
|
||||
private:
|
||||
NetworkEmulationManager* const net_ = nullptr;
|
||||
SimulatedNetwork::Config config_;
|
||||
};
|
||||
};
|
||||
} // namespace test
|
||||
} // namespace webrtc
|
||||
|
||||
#endif // TEST_NETWORK_SIMULATED_NETWORK_NODE_H_
|
Reference in New Issue
Block a user