diff --git a/api/BUILD.gn b/api/BUILD.gn index d8681b154c..fd5df66fdf 100644 --- a/api/BUILD.gn +++ b/api/BUILD.gn @@ -219,6 +219,20 @@ if (rtc_include_tests) { "//third_party/abseil-cpp/absl/memory", ] } + + rtc_source_set("create_network_emulation_manager_api") { + visibility = [ "*" ] + testonly = true + sources = [ + "test/create_network_emulation_manager.cc", + "test/create_network_emulation_manager.h", + ] + deps = [ + ":network_emulation_manager_api", + "../test/scenario/network:emulated_network", + "//third_party/abseil-cpp/absl/memory:memory", + ] + } } rtc_source_set("libjingle_logging_api") { @@ -305,6 +319,17 @@ rtc_source_set("simulated_network_api") { ] } +rtc_source_set("network_emulation_manager_api") { + visibility = [ "*" ] + sources = [ + "test/network_emulation_manager.h", + ] + deps = [ + ":simulated_network_api", + "../rtc_base:rtc_base", + ] +} + rtc_source_set("fec_controller_api") { visibility = [ "*" ] sources = [ diff --git a/api/test/DEPS b/api/test/DEPS index ed944b4d2d..c15d58d2a6 100644 --- a/api/test/DEPS +++ b/api/test/DEPS @@ -14,4 +14,8 @@ specific_include_rules = { "+rtc_base/thread.h", "+rtc_base/thread_checker.h", ], + "network_emulation_manager\.h": [ + "+rtc_base/thread.h", + "+rtc_base/network.h", + ], } diff --git a/api/test/create_network_emulation_manager.cc b/api/test/create_network_emulation_manager.cc new file mode 100644 index 0000000000..677f19ceca --- /dev/null +++ b/api/test/create_network_emulation_manager.cc @@ -0,0 +1,23 @@ + +/* + * 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 "api/test/create_network_emulation_manager.h" + +#include "absl/memory/memory.h" +#include "test/scenario/network/network_emulation_manager.h" + +namespace webrtc { + +std::unique_ptr CreateNetworkEmulationManager() { + return absl::make_unique(); +} + +} // namespace webrtc diff --git a/api/test/create_network_emulation_manager.h b/api/test/create_network_emulation_manager.h new file mode 100644 index 0000000000..747da1cb54 --- /dev/null +++ b/api/test/create_network_emulation_manager.h @@ -0,0 +1,25 @@ + +/* + * 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 API_TEST_CREATE_NETWORK_EMULATION_MANAGER_H_ +#define API_TEST_CREATE_NETWORK_EMULATION_MANAGER_H_ + +#include + +#include "api/test/network_emulation_manager.h" + +namespace webrtc { + +std::unique_ptr CreateNetworkEmulationManager(); + +} // namespace webrtc + +#endif // API_TEST_CREATE_NETWORK_EMULATION_MANAGER_H_ diff --git a/api/test/network_emulation_manager.h b/api/test/network_emulation_manager.h new file mode 100644 index 0000000000..3cb329ca49 --- /dev/null +++ b/api/test/network_emulation_manager.h @@ -0,0 +1,106 @@ +/* + * 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 API_TEST_NETWORK_EMULATION_MANAGER_H_ +#define API_TEST_NETWORK_EMULATION_MANAGER_H_ + +#include +#include + +#include "api/test/simulated_network.h" +#include "rtc_base/network.h" +#include "rtc_base/thread.h" + +namespace webrtc { + +// This API is still in development and can be changed without prior notice. + +// These classes are forward declared here, because they used as handles, to +// make it possible for client code to operate with these abstractions and build +// required network configuration. With forward declaration here implementation +// is more readable, than with interfaces approach and cause user needn't any +// API methods on these abstractions it is acceptable here. + +// EmulatedNetworkNode is an abstraction for some network in the real world, +// like 3G network between peers, or Wi-Fi for one peer and LTE for another. +// Multiple networks can be joined into chain emulating a network path from +// one peer to another. +class EmulatedNetworkNode; +// EmulatedEndpoint is and abstraction for network interface on device. +class EmulatedEndpoint; +// EmulatedRoute is handle for single route from one network interface on one +// peer device to another network interface on another peer device. +class EmulatedRoute; + +struct EmulatedEndpointConfig { + enum class IpAddressFamily { kIpv4, kIpv6 }; + + IpAddressFamily generated_ip_family = IpAddressFamily::kIpv4; + // If specified will be used as IP address for endpoint node. Must be unique + // among all created nodes. + absl::optional ip; +}; + +// Provides an API for creating and configuring emulated network layer. +// All objects returned by this API are owned by NetworkEmulationManager itself +// and will be deleted when manager will be deleted. +class NetworkEmulationManager { + public: + virtual ~NetworkEmulationManager() = default; + + // Creates an emulated network node, which represents single network in + // the emulated network layer. + virtual EmulatedNetworkNode* CreateEmulatedNode( + std::unique_ptr network_behavior) = 0; + + // Creates an emulated endpoint, which represents single network interface on + // the peer's device. + virtual EmulatedEndpoint* CreateEndpoint(EmulatedEndpointConfig config) = 0; + + // Creates a route between endpoints going through specified network nodes. + // This route is single direction only and describe how traffic that was + // sent by network interface |from| have to be delivered to the network + // interface |to|. Return object can be used to remove created route. + // + // Assume there are endpoints E1, E2 and E3 and network nodes A, B, C and D. + // Also assume, that there is a route constructed via A, B and C like this: + // E1 -> A -> B -> C -> E2. In such case: + // * Caller mustn't use A, B and C in any route, that is leading to E2. + // * If caller will then create a new route E1 -> D -> E3, then first + // route will be corrupted, so if caller want to do this, first route + // should be deleted by ClearRoute(...) and then a new one should be + // created. + // * Caller can use A, B or C for any other routes. + // * Caller can create other routes leading to E2. + virtual EmulatedRoute* CreateRoute( + EmulatedEndpoint* from, + const std::vector& via_nodes, + EmulatedEndpoint* to) = 0; + // Removes route previously created by CreateRoute(...). + // Caller mustn't call this function with route, that have been already + // removed earlier. + virtual void ClearRoute(EmulatedRoute* route) = 0; + + // Creates rtc::Thread that should be used as network thread for peer + // connection. Created thread contains special rtc::SocketServer inside it + // to enable correct integration between peer connection and emulated network + // layer. + virtual rtc::Thread* CreateNetworkThread( + const std::vector& endpoints) = 0; + // Creates rtc::NetworkManager that should be used inside + // cricket::PortAllocator for peer connection to provide correct list of + // network interfaces, that exists in emulated network later. + virtual rtc::NetworkManager* CreateNetworkManager( + const std::vector& endpoints) = 0; +}; + +} // namespace webrtc + +#endif // API_TEST_NETWORK_EMULATION_MANAGER_H_ diff --git a/test/pc/e2e/BUILD.gn b/test/pc/e2e/BUILD.gn index 8c85fdd865..b61e4734f5 100644 --- a/test/pc/e2e/BUILD.gn +++ b/test/pc/e2e/BUILD.gn @@ -264,7 +264,9 @@ if (rtc_include_tests) { ":default_audio_quality_analyzer", ":default_video_quality_analyzer", "../../../api:callfactory_api", + "../../../api:create_network_emulation_manager_api", "../../../api:libjingle_peerconnection_api", + "../../../api:network_emulation_manager_api", "../../../api:scoped_refptr", "../../../api:simulated_network_api", "../../../api/audio_codecs:builtin_audio_decoder_factory", @@ -284,7 +286,6 @@ if (rtc_include_tests) { "../../../rtc_base:rtc_event", "../../../test:fileutils", "../../../test:test_support", - "../../../test/scenario/network:emulated_network", "api:create_peerconnection_quality_test_fixture", "api:peer_connection_quality_test_fixture_api", "//third_party/abseil-cpp/absl/memory:memory", diff --git a/test/pc/e2e/peer_connection_e2e_smoke_test.cc b/test/pc/e2e/peer_connection_e2e_smoke_test.cc index f4f2015833..61f5feab41 100644 --- a/test/pc/e2e/peer_connection_e2e_smoke_test.cc +++ b/test/pc/e2e/peer_connection_e2e_smoke_test.cc @@ -12,14 +12,14 @@ #include #include "absl/memory/memory.h" +#include "api/test/create_network_emulation_manager.h" +#include "api/test/network_emulation_manager.h" #include "call/simulated_network.h" #include "test/gtest.h" #include "test/pc/e2e/analyzer/audio/default_audio_quality_analyzer.h" #include "test/pc/e2e/analyzer/video/default_video_quality_analyzer.h" #include "test/pc/e2e/api/create_peerconnection_quality_test_fixture.h" #include "test/pc/e2e/api/peerconnection_quality_test_fixture.h" -#include "test/scenario/network/network_emulation.h" -#include "test/scenario/network/network_emulation_manager.h" #include "test/testsupport/file_utils.h" namespace webrtc { @@ -61,35 +61,36 @@ TEST(PeerConnectionE2EQualityTestSmokeTest, RunWithEmulatedNetwork) { bob_params->audio_config = AudioConfig(); // Setup emulated network - NetworkEmulationManager network_emulation_manager; + std::unique_ptr network_emulation_manager = + CreateNetworkEmulationManager(); EmulatedNetworkNode* alice_node = - network_emulation_manager.CreateEmulatedNode( + network_emulation_manager->CreateEmulatedNode( absl::make_unique(BuiltInNetworkBehaviorConfig())); - EmulatedNetworkNode* bob_node = network_emulation_manager.CreateEmulatedNode( + EmulatedNetworkNode* bob_node = network_emulation_manager->CreateEmulatedNode( absl::make_unique(BuiltInNetworkBehaviorConfig())); EmulatedEndpoint* alice_endpoint = - network_emulation_manager.CreateEndpoint(EmulatedEndpointConfig()); + network_emulation_manager->CreateEndpoint(EmulatedEndpointConfig()); EmulatedEndpoint* bob_endpoint = - network_emulation_manager.CreateEndpoint(EmulatedEndpointConfig()); - network_emulation_manager.CreateRoute(alice_endpoint, {alice_node}, - bob_endpoint); - network_emulation_manager.CreateRoute(bob_endpoint, {bob_node}, - alice_endpoint); + network_emulation_manager->CreateEndpoint(EmulatedEndpointConfig()); + network_emulation_manager->CreateRoute(alice_endpoint, {alice_node}, + bob_endpoint); + network_emulation_manager->CreateRoute(bob_endpoint, {bob_node}, + alice_endpoint); rtc::Thread* alice_network_thread = - network_emulation_manager.CreateNetworkThread({alice_endpoint}); + network_emulation_manager->CreateNetworkThread({alice_endpoint}); rtc::Thread* bob_network_thread = - network_emulation_manager.CreateNetworkThread({bob_endpoint}); + network_emulation_manager->CreateNetworkThread({bob_endpoint}); // Setup components. We need to provide rtc::NetworkManager compatible with // emulated network layer. rtc::NetworkManager* alice_network_manager = - network_emulation_manager.CreateNetworkManager({alice_endpoint}); + network_emulation_manager->CreateNetworkManager({alice_endpoint}); auto alice_components = absl::make_unique( alice_network_thread, alice_network_manager); rtc::NetworkManager* bob_network_manager = - network_emulation_manager.CreateNetworkManager({bob_endpoint}); + network_emulation_manager->CreateNetworkManager({bob_endpoint}); auto bob_components = absl::make_unique( bob_network_thread, bob_network_manager); diff --git a/test/scenario/network/BUILD.gn b/test/scenario/network/BUILD.gn index 25a3ec06be..7b03a9b51f 100644 --- a/test/scenario/network/BUILD.gn +++ b/test/scenario/network/BUILD.gn @@ -26,6 +26,7 @@ rtc_source_set("emulated_network") { ] deps = [ "../:column_printer", + "../../../api:network_emulation_manager_api", "../../../api:simulated_network_api", "../../../api/units:data_rate", "../../../api/units:data_size", diff --git a/test/scenario/network/cross_traffic_unittest.cc b/test/scenario/network/cross_traffic_unittest.cc index 98f2d3cf86..01ea3376fd 100644 --- a/test/scenario/network/cross_traffic_unittest.cc +++ b/test/scenario/network/cross_traffic_unittest.cc @@ -63,7 +63,7 @@ class CountingBehavior : public NetworkBehaviorInterface { } // namespace TEST(CrossTrafficTest, TriggerPacketBurst) { - NetworkEmulationManager network_manager; + NetworkEmulationManagerImpl network_manager; std::unique_ptr behavior = absl::make_unique(); @@ -86,7 +86,7 @@ TEST(CrossTrafficTest, TriggerPacketBurst) { } TEST(CrossTrafficTest, PulsedPeaksCrossTraffic) { - NetworkEmulationManager network_manager; + NetworkEmulationManagerImpl network_manager; std::unique_ptr behavior = absl::make_unique(); @@ -119,7 +119,7 @@ TEST(CrossTrafficTest, PulsedPeaksCrossTraffic) { } TEST(CrossTrafficTest, RandomWalkCrossTraffic) { - NetworkEmulationManager network_manager; + NetworkEmulationManagerImpl network_manager; std::unique_ptr behavior = absl::make_unique(); diff --git a/test/scenario/network/network_emulation.cc b/test/scenario/network/network_emulation.cc index 7fb4fd595f..98f5a068eb 100644 --- a/test/scenario/network/network_emulation.cc +++ b/test/scenario/network/network_emulation.cc @@ -18,7 +18,6 @@ #include "rtc_base/logging.h" namespace webrtc { -namespace test { EmulatedIpPacket::EmulatedIpPacket(const rtc::SocketAddress& from, const rtc::SocketAddress& to, @@ -235,5 +234,4 @@ void EmulatedEndpoint::SetConnectedEndpointId(uint64_t endpoint_id) { connected_endpoint_id_ = endpoint_id; } -} // namespace test } // namespace webrtc diff --git a/test/scenario/network/network_emulation.h b/test/scenario/network/network_emulation.h index cc1aec4af5..837ff38081 100644 --- a/test/scenario/network/network_emulation.h +++ b/test/scenario/network/network_emulation.h @@ -31,6 +31,12 @@ namespace webrtc { namespace test { +// Forward declare NetworkEmulationManagerImpl for friend access from +// EmulatedEndpoint. +class NetworkEmulationManagerImpl; + +} // namespace test + struct EmulatedIpPacket { public: EmulatedIpPacket(const rtc::SocketAddress& from, @@ -150,7 +156,7 @@ class EmulatedEndpoint : public EmulatedNetworkReceiverInterface { void OnPacketReceived(EmulatedIpPacket packet) override; protected: - friend class NetworkEmulationManager; + friend class test::NetworkEmulationManagerImpl; EmulatedNetworkNode* GetSendNode() const; void SetConnectedEndpointId(uint64_t endpoint_id); @@ -187,7 +193,6 @@ class EmulatedRoute { bool active; }; -} // namespace test } // namespace webrtc #endif // TEST_SCENARIO_NETWORK_NETWORK_EMULATION_H_ diff --git a/test/scenario/network/network_emulation_manager.cc b/test/scenario/network/network_emulation_manager.cc index 851c29f83e..577d96840a 100644 --- a/test/scenario/network/network_emulation_manager.cc +++ b/test/scenario/network/network_emulation_manager.cc @@ -30,18 +30,7 @@ constexpr uint32_t kMaxIPv4Address = 0xC0A8FFFF; } // namespace -EmulatedEndpointConfig::EmulatedEndpointConfig() = default; -EmulatedEndpointConfig::~EmulatedEndpointConfig() = default; -EmulatedEndpointConfig::EmulatedEndpointConfig(EmulatedEndpointConfig&) = - default; -EmulatedEndpointConfig& EmulatedEndpointConfig::operator=( - EmulatedEndpointConfig&) = default; -EmulatedEndpointConfig::EmulatedEndpointConfig(EmulatedEndpointConfig&&) = - default; -EmulatedEndpointConfig& EmulatedEndpointConfig::operator=( - EmulatedEndpointConfig&&) = default; - -NetworkEmulationManager::NetworkEmulationManager() +NetworkEmulationManagerImpl::NetworkEmulationManagerImpl() : clock_(Clock::GetRealTimeClock()), next_node_id_(1), next_ip4_address_(kMinIPv4Address), @@ -55,9 +44,9 @@ NetworkEmulationManager::NetworkEmulationManager() // TODO(srte): Ensure that any pending task that must be run for consistency // (such as stats collection tasks) are not cancelled when the task queue is // destroyed. -NetworkEmulationManager::~NetworkEmulationManager() = default; +NetworkEmulationManagerImpl::~NetworkEmulationManagerImpl() = default; -EmulatedNetworkNode* NetworkEmulationManager::CreateEmulatedNode( +EmulatedNetworkNode* NetworkEmulationManagerImpl::CreateEmulatedNode( std::unique_ptr network_behavior) { auto node = absl::make_unique(std::move(network_behavior)); @@ -65,14 +54,14 @@ EmulatedNetworkNode* NetworkEmulationManager::CreateEmulatedNode( struct Closure { void operator()() { manager->network_nodes_.push_back(std::move(node)); } - NetworkEmulationManager* manager; + NetworkEmulationManagerImpl* manager; std::unique_ptr node; }; task_queue_.PostTask(Closure{this, std::move(node)}); return out; } -EmulatedEndpoint* NetworkEmulationManager::CreateEndpoint( +EmulatedEndpoint* NetworkEmulationManagerImpl::CreateEndpoint( EmulatedEndpointConfig config) { absl::optional ip = config.ip; if (!ip) { @@ -97,9 +86,9 @@ EmulatedEndpoint* NetworkEmulationManager::CreateEndpoint( return out; } -EmulatedRoute* NetworkEmulationManager::CreateRoute( +EmulatedRoute* NetworkEmulationManagerImpl::CreateRoute( EmulatedEndpoint* from, - std::vector via_nodes, + const std::vector& via_nodes, EmulatedEndpoint* to) { // Because endpoint has no send node by default at least one should be // provided here. @@ -121,7 +110,7 @@ EmulatedRoute* NetworkEmulationManager::CreateRoute( return out; } -void NetworkEmulationManager::ClearRoute(EmulatedRoute* route) { +void NetworkEmulationManagerImpl::ClearRoute(EmulatedRoute* route) { RTC_CHECK(route->active) << "Route already cleared"; // Remove receiver from intermediate nodes. @@ -137,8 +126,8 @@ void NetworkEmulationManager::ClearRoute(EmulatedRoute* route) { route->active = false; } -TrafficRoute* NetworkEmulationManager::CreateTrafficRoute( - std::vector via_nodes) { +TrafficRoute* NetworkEmulationManagerImpl::CreateTrafficRoute( + const std::vector& via_nodes) { RTC_CHECK(!via_nodes.empty()); EmulatedEndpoint* endpoint = CreateEndpoint(EmulatedEndpointConfig()); @@ -157,7 +146,8 @@ TrafficRoute* NetworkEmulationManager::CreateTrafficRoute( return out; } -RandomWalkCrossTraffic* NetworkEmulationManager::CreateRandomWalkCrossTraffic( +RandomWalkCrossTraffic* +NetworkEmulationManagerImpl::CreateRandomWalkCrossTraffic( TrafficRoute* traffic_route, RandomWalkConfig config) { auto traffic = absl::make_unique(std::move(config), @@ -167,14 +157,15 @@ RandomWalkCrossTraffic* NetworkEmulationManager::CreateRandomWalkCrossTraffic( void operator()() { manager->random_cross_traffics_.push_back(std::move(traffic)); } - NetworkEmulationManager* manager; + NetworkEmulationManagerImpl* manager; std::unique_ptr traffic; }; task_queue_.PostTask(Closure{this, std::move(traffic)}); return out; } -PulsedPeaksCrossTraffic* NetworkEmulationManager::CreatePulsedPeaksCrossTraffic( +PulsedPeaksCrossTraffic* +NetworkEmulationManagerImpl::CreatePulsedPeaksCrossTraffic( TrafficRoute* traffic_route, PulsedPeaksConfig config) { auto traffic = absl::make_unique(std::move(config), @@ -184,15 +175,15 @@ PulsedPeaksCrossTraffic* NetworkEmulationManager::CreatePulsedPeaksCrossTraffic( void operator()() { manager->pulsed_cross_traffics_.push_back(std::move(traffic)); } - NetworkEmulationManager* manager; + NetworkEmulationManagerImpl* manager; std::unique_ptr traffic; }; task_queue_.PostTask(Closure{this, std::move(traffic)}); return out; } -rtc::Thread* NetworkEmulationManager::CreateNetworkThread( - std::vector endpoints) { +rtc::Thread* NetworkEmulationManagerImpl::CreateNetworkThread( + const std::vector& endpoints) { FakeNetworkSocketServer* socket_server = CreateSocketServer(endpoints); std::unique_ptr network_thread = absl::make_unique(socket_server); @@ -204,8 +195,8 @@ rtc::Thread* NetworkEmulationManager::CreateNetworkThread( return out; } -rtc::NetworkManager* NetworkEmulationManager::CreateNetworkManager( - std::vector endpoints) { +rtc::NetworkManager* NetworkEmulationManagerImpl::CreateNetworkManager( + const std::vector& endpoints) { auto network_manager = absl::make_unique(); for (auto* endpoint : endpoints) { network_manager->AddInterface( @@ -216,8 +207,8 @@ rtc::NetworkManager* NetworkEmulationManager::CreateNetworkManager( return out; } -FakeNetworkSocketServer* NetworkEmulationManager::CreateSocketServer( - std::vector endpoints) { +FakeNetworkSocketServer* NetworkEmulationManagerImpl::CreateSocketServer( + const std::vector& endpoints) { auto socket_server = absl::make_unique(clock_, endpoints); FakeNetworkSocketServer* out = socket_server.get(); @@ -225,7 +216,8 @@ FakeNetworkSocketServer* NetworkEmulationManager::CreateSocketServer( return out; } -absl::optional NetworkEmulationManager::GetNextIPv4Address() { +absl::optional +NetworkEmulationManagerImpl::GetNextIPv4Address() { uint32_t addresses_count = kMaxIPv4Address - kMinIPv4Address; for (uint32_t i = 0; i < addresses_count; i++) { rtc::IPAddress ip(next_ip4_address_); @@ -241,7 +233,7 @@ absl::optional NetworkEmulationManager::GetNextIPv4Address() { return absl::nullopt; } -void NetworkEmulationManager::ProcessNetworkPackets() { +void NetworkEmulationManagerImpl::ProcessNetworkPackets() { Timestamp current_time = Now(); for (auto& traffic : random_cross_traffics_) { traffic->Process(current_time); @@ -254,7 +246,7 @@ void NetworkEmulationManager::ProcessNetworkPackets() { } } -Timestamp NetworkEmulationManager::Now() const { +Timestamp NetworkEmulationManagerImpl::Now() const { return Timestamp::us(clock_->TimeInMicroseconds()); } diff --git a/test/scenario/network/network_emulation_manager.h b/test/scenario/network/network_emulation_manager.h index 6923d655bf..8290ec30f1 100644 --- a/test/scenario/network/network_emulation_manager.h +++ b/test/scenario/network/network_emulation_manager.h @@ -15,6 +15,7 @@ #include #include +#include "api/test/network_emulation_manager.h" #include "api/test/simulated_network.h" #include "api/units/time_delta.h" #include "api/units/timestamp.h" @@ -32,38 +33,23 @@ namespace webrtc { namespace test { -struct EmulatedEndpointConfig { - enum class IpAddressFamily { kIpv4, kIpv6 }; - - EmulatedEndpointConfig(); - ~EmulatedEndpointConfig(); - EmulatedEndpointConfig(EmulatedEndpointConfig&); - EmulatedEndpointConfig& operator=(EmulatedEndpointConfig&); - EmulatedEndpointConfig(EmulatedEndpointConfig&&); - EmulatedEndpointConfig& operator=(EmulatedEndpointConfig&&); - - IpAddressFamily generated_ip_family = IpAddressFamily::kIpv4; - // If specified will be used as IP address for endpoint node. Must be unique - // among all created nodes. - absl::optional ip; -}; - -class NetworkEmulationManager { +class NetworkEmulationManagerImpl : public NetworkEmulationManager { public: - NetworkEmulationManager(); - ~NetworkEmulationManager(); + NetworkEmulationManagerImpl(); + ~NetworkEmulationManagerImpl(); EmulatedNetworkNode* CreateEmulatedNode( - std::unique_ptr network_behavior); + std::unique_ptr network_behavior) override; - EmulatedEndpoint* CreateEndpoint(EmulatedEndpointConfig config); + EmulatedEndpoint* CreateEndpoint(EmulatedEndpointConfig config) override; EmulatedRoute* CreateRoute(EmulatedEndpoint* from, - std::vector via_nodes, - EmulatedEndpoint* to); - void ClearRoute(EmulatedRoute* route); + const std::vector& via_nodes, + EmulatedEndpoint* to) override; + void ClearRoute(EmulatedRoute* route) override; - TrafficRoute* CreateTrafficRoute(std::vector via_nodes); + TrafficRoute* CreateTrafficRoute( + const std::vector& via_nodes); RandomWalkCrossTraffic* CreateRandomWalkCrossTraffic( TrafficRoute* traffic_route, RandomWalkConfig config); @@ -71,13 +57,14 @@ class NetworkEmulationManager { TrafficRoute* traffic_route, PulsedPeaksConfig config); - rtc::Thread* CreateNetworkThread(std::vector endpoints); + rtc::Thread* CreateNetworkThread( + const std::vector& endpoints) override; rtc::NetworkManager* CreateNetworkManager( - std::vector endpoints); + const std::vector& endpoints) override; private: FakeNetworkSocketServer* CreateSocketServer( - std::vector endpoints); + const std::vector& endpoints); absl::optional GetNextIPv4Address(); void ProcessNetworkPackets(); Timestamp Now() const; diff --git a/test/scenario/network/network_emulation_pc_unittest.cc b/test/scenario/network/network_emulation_pc_unittest.cc index 37039390aa..d197fc56ec 100644 --- a/test/scenario/network/network_emulation_pc_unittest.cc +++ b/test/scenario/network/network_emulation_pc_unittest.cc @@ -100,7 +100,7 @@ TEST(NetworkEmulationManagerPCTest, Run) { signaling_thread->Start(); // Setup emulated network - NetworkEmulationManager emulation; + NetworkEmulationManagerImpl emulation; EmulatedNetworkNode* alice_node = emulation.CreateEmulatedNode( absl::make_unique(BuiltInNetworkBehaviorConfig())); diff --git a/test/scenario/network/network_emulation_unittest.cc b/test/scenario/network/network_emulation_unittest.cc index 24fe089ab9..13c388cc79 100644 --- a/test/scenario/network/network_emulation_unittest.cc +++ b/test/scenario/network/network_emulation_unittest.cc @@ -58,7 +58,7 @@ class SocketReader : public sigslot::has_slots<> { }; TEST(NetworkEmulationManagerTest, GeneratedIpv4AddressDoesNotCollide) { - NetworkEmulationManager network_manager; + NetworkEmulationManagerImpl network_manager; std::set ips; EmulatedEndpointConfig config; config.generated_ip_family = EmulatedEndpointConfig::IpAddressFamily::kIpv4; @@ -71,7 +71,7 @@ TEST(NetworkEmulationManagerTest, GeneratedIpv4AddressDoesNotCollide) { } TEST(NetworkEmulationManagerTest, GeneratedIpv6AddressDoesNotCollide) { - NetworkEmulationManager network_manager; + NetworkEmulationManagerImpl network_manager; std::set ips; EmulatedEndpointConfig config; config.generated_ip_family = EmulatedEndpointConfig::IpAddressFamily::kIpv6; @@ -84,7 +84,7 @@ TEST(NetworkEmulationManagerTest, GeneratedIpv6AddressDoesNotCollide) { } TEST(NetworkEmulationManagerTest, Run) { - NetworkEmulationManager network_manager; + NetworkEmulationManagerImpl network_manager; EmulatedNetworkNode* alice_node = network_manager.CreateEmulatedNode( absl::make_unique(BuiltInNetworkBehaviorConfig()));