diff --git a/api/BUILD.gn b/api/BUILD.gn index 4ca6c9b0e6..728cc4fbb3 100644 --- a/api/BUILD.gn +++ b/api/BUILD.gn @@ -592,6 +592,7 @@ rtc_source_set("network_emulation_manager_api") { "test/network_emulation_manager.h", ] deps = [ + ":array_view", ":simulated_network_api", ":time_controller", "../call:simulated_network", diff --git a/api/test/network_emulation_manager.h b/api/test/network_emulation_manager.h index bdbc50138b..90441e4f27 100644 --- a/api/test/network_emulation_manager.h +++ b/api/test/network_emulation_manager.h @@ -15,6 +15,7 @@ #include #include +#include "api/array_view.h" #include "api/test/network_emulation/network_emulation_interfaces.h" #include "api/test/simulated_network.h" #include "api/test/time_controller.h" @@ -65,10 +66,20 @@ class EmulatedNetworkManagerInterface { public: virtual ~EmulatedNetworkManagerInterface() = default; + // Returns non-null pointer to thread that have to be used as network thread + // for WebRTC to properly setup network emulation. Returned thread is owned + // by EmulatedNetworkManagerInterface implementation. virtual rtc::Thread* network_thread() = 0; + // Returns non-null pointer to network manager that have to be injected into + // WebRTC to properly setup network emulation. Returned manager is owned by + // EmulatedNetworkManagerInterface implementation. virtual rtc::NetworkManager* network_manager() = 0; + // Returns list of endpoints that are associated with this instance. Pointers + // are guaranteed to be non-null and are owned by NetworkEmulationManager. + virtual std::vector endpoints() const = 0; - // Returns summarized network stats for endpoints for this manager. + // Passes summarized network stats for endpoints for this manager into + // specified |stats_callback|. virtual void GetStats( std::function)> stats_callback) const = 0; @@ -182,6 +193,13 @@ class NetworkEmulationManager { virtual EmulatedNetworkManagerInterface* CreateEmulatedNetworkManagerInterface( const std::vector& endpoints) = 0; + + // Passes summarized network stats for specified |endpoints| into specifield + // |stats_callback|. + virtual void GetStats( + rtc::ArrayView endpoints, + std::function)> + stats_callback) = 0; }; } // namespace webrtc diff --git a/test/network/emulated_network_manager.h b/test/network/emulated_network_manager.h index db884157c5..98927d7911 100644 --- a/test/network/emulated_network_manager.h +++ b/test/network/emulated_network_manager.h @@ -50,6 +50,9 @@ class EmulatedNetworkManager : public rtc::NetworkManagerBase, // EmulatedNetworkManagerInterface API rtc::Thread* network_thread() override { return network_thread_.get(); } rtc::NetworkManager* network_manager() override { return this; } + std::vector endpoints() const override { + return endpoints_container_->endpoints(); + } void GetStats(std::function)> stats_callback) const override; diff --git a/test/network/network_emulation.cc b/test/network/network_emulation.cc index c71f6bb4a1..2a76725247 100644 --- a/test/network/network_emulation.cc +++ b/test/network/network_emulation.cc @@ -469,6 +469,10 @@ EndpointsContainer::GetEnabledNetworks() const { return networks; } +std::vector EndpointsContainer::endpoints() const { + return std::vector(endpoints_.begin(), endpoints_.end()); +} + std::unique_ptr EndpointsContainer::GetStats() const { EmulatedNetworkStatsBuilder stats_builder; for (auto* endpoint : endpoints_) { diff --git a/test/network/network_emulation.h b/test/network/network_emulation.h index d2bb121a62..1525d881d8 100644 --- a/test/network/network_emulation.h +++ b/test/network/network_emulation.h @@ -349,6 +349,7 @@ class EndpointsContainer { // Returns list of networks for enabled endpoints. Caller takes ownership of // returned rtc::Network objects. std::vector> GetEnabledNetworks() const; + std::vector endpoints() const; std::unique_ptr GetStats() const; private: diff --git a/test/network/network_emulation_manager.cc b/test/network/network_emulation_manager.cc index adc4bb646c..afe5033e30 100644 --- a/test/network/network_emulation_manager.cc +++ b/test/network/network_emulation_manager.cc @@ -295,6 +295,18 @@ NetworkEmulationManagerImpl::CreateEmulatedNetworkManagerInterface( return out; } +void NetworkEmulationManagerImpl::GetStats( + rtc::ArrayView endpoints, + std::function)> stats_callback) { + task_queue_.PostTask([endpoints, stats_callback]() { + EmulatedNetworkStatsBuilder stats_builder; + for (auto* endpoint : endpoints) { + stats_builder.AppendEmulatedNetworkStats(endpoint->stats()); + } + stats_callback(stats_builder.Build()); + }); +} + absl::optional NetworkEmulationManagerImpl::GetNextIPv4Address() { uint32_t addresses_count = kMaxIPv4Address - kMinIPv4Address; diff --git a/test/network/network_emulation_manager.h b/test/network/network_emulation_manager.h index 2b33fa1575..7532b0a88f 100644 --- a/test/network/network_emulation_manager.h +++ b/test/network/network_emulation_manager.h @@ -17,6 +17,7 @@ #include #include +#include "api/array_view.h" #include "api/test/network_emulation_manager.h" #include "api/test/simulated_network.h" #include "api/test/time_controller.h" @@ -83,6 +84,10 @@ class NetworkEmulationManagerImpl : public NetworkEmulationManager { EmulatedNetworkManagerInterface* CreateEmulatedNetworkManagerInterface( const std::vector& endpoints) override; + void GetStats(rtc::ArrayView endpoints, + std::function)> + stats_callback) override; + TimeController* time_controller() override { return time_controller_.get(); } Timestamp Now() const;