Add ability to get network stats from endpoint instance

Bug: webrtc:11756
Change-Id: Ic232304d037a8f8bc9dc293af23c9a89d4b8cb37
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/180360
Reviewed-by: Christoffer Rodbro <crodbro@webrtc.org>
Reviewed-by: Andrey Logvin <landrey@webrtc.org>
Commit-Queue: Artem Titov <titovartem@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#31801}
This commit is contained in:
Artem Titov 2020-07-28 13:45:16 +02:00 committed by Commit Bot
parent 6c5f787741
commit cf781282f1
7 changed files with 45 additions and 1 deletions

View File

@ -592,6 +592,7 @@ rtc_source_set("network_emulation_manager_api") {
"test/network_emulation_manager.h", "test/network_emulation_manager.h",
] ]
deps = [ deps = [
":array_view",
":simulated_network_api", ":simulated_network_api",
":time_controller", ":time_controller",
"../call:simulated_network", "../call:simulated_network",

View File

@ -15,6 +15,7 @@
#include <memory> #include <memory>
#include <vector> #include <vector>
#include "api/array_view.h"
#include "api/test/network_emulation/network_emulation_interfaces.h" #include "api/test/network_emulation/network_emulation_interfaces.h"
#include "api/test/simulated_network.h" #include "api/test/simulated_network.h"
#include "api/test/time_controller.h" #include "api/test/time_controller.h"
@ -65,10 +66,20 @@ class EmulatedNetworkManagerInterface {
public: public:
virtual ~EmulatedNetworkManagerInterface() = default; 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; 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; 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<EmulatedEndpoint*> 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( virtual void GetStats(
std::function<void(std::unique_ptr<EmulatedNetworkStats>)> stats_callback) std::function<void(std::unique_ptr<EmulatedNetworkStats>)> stats_callback)
const = 0; const = 0;
@ -182,6 +193,13 @@ class NetworkEmulationManager {
virtual EmulatedNetworkManagerInterface* virtual EmulatedNetworkManagerInterface*
CreateEmulatedNetworkManagerInterface( CreateEmulatedNetworkManagerInterface(
const std::vector<EmulatedEndpoint*>& endpoints) = 0; const std::vector<EmulatedEndpoint*>& endpoints) = 0;
// Passes summarized network stats for specified |endpoints| into specifield
// |stats_callback|.
virtual void GetStats(
rtc::ArrayView<EmulatedEndpoint*> endpoints,
std::function<void(std::unique_ptr<EmulatedNetworkStats>)>
stats_callback) = 0;
}; };
} // namespace webrtc } // namespace webrtc

View File

@ -50,6 +50,9 @@ class EmulatedNetworkManager : public rtc::NetworkManagerBase,
// EmulatedNetworkManagerInterface API // EmulatedNetworkManagerInterface API
rtc::Thread* network_thread() override { return network_thread_.get(); } rtc::Thread* network_thread() override { return network_thread_.get(); }
rtc::NetworkManager* network_manager() override { return this; } rtc::NetworkManager* network_manager() override { return this; }
std::vector<EmulatedEndpoint*> endpoints() const override {
return endpoints_container_->endpoints();
}
void GetStats(std::function<void(std::unique_ptr<EmulatedNetworkStats>)> void GetStats(std::function<void(std::unique_ptr<EmulatedNetworkStats>)>
stats_callback) const override; stats_callback) const override;

View File

@ -469,6 +469,10 @@ EndpointsContainer::GetEnabledNetworks() const {
return networks; return networks;
} }
std::vector<EmulatedEndpoint*> EndpointsContainer::endpoints() const {
return std::vector<EmulatedEndpoint*>(endpoints_.begin(), endpoints_.end());
}
std::unique_ptr<EmulatedNetworkStats> EndpointsContainer::GetStats() const { std::unique_ptr<EmulatedNetworkStats> EndpointsContainer::GetStats() const {
EmulatedNetworkStatsBuilder stats_builder; EmulatedNetworkStatsBuilder stats_builder;
for (auto* endpoint : endpoints_) { for (auto* endpoint : endpoints_) {

View File

@ -349,6 +349,7 @@ class EndpointsContainer {
// Returns list of networks for enabled endpoints. Caller takes ownership of // Returns list of networks for enabled endpoints. Caller takes ownership of
// returned rtc::Network objects. // returned rtc::Network objects.
std::vector<std::unique_ptr<rtc::Network>> GetEnabledNetworks() const; std::vector<std::unique_ptr<rtc::Network>> GetEnabledNetworks() const;
std::vector<EmulatedEndpoint*> endpoints() const;
std::unique_ptr<EmulatedNetworkStats> GetStats() const; std::unique_ptr<EmulatedNetworkStats> GetStats() const;
private: private:

View File

@ -295,6 +295,18 @@ NetworkEmulationManagerImpl::CreateEmulatedNetworkManagerInterface(
return out; return out;
} }
void NetworkEmulationManagerImpl::GetStats(
rtc::ArrayView<EmulatedEndpoint*> endpoints,
std::function<void(std::unique_ptr<EmulatedNetworkStats>)> 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<rtc::IPAddress> absl::optional<rtc::IPAddress>
NetworkEmulationManagerImpl::GetNextIPv4Address() { NetworkEmulationManagerImpl::GetNextIPv4Address() {
uint32_t addresses_count = kMaxIPv4Address - kMinIPv4Address; uint32_t addresses_count = kMaxIPv4Address - kMinIPv4Address;

View File

@ -17,6 +17,7 @@
#include <utility> #include <utility>
#include <vector> #include <vector>
#include "api/array_view.h"
#include "api/test/network_emulation_manager.h" #include "api/test/network_emulation_manager.h"
#include "api/test/simulated_network.h" #include "api/test/simulated_network.h"
#include "api/test/time_controller.h" #include "api/test/time_controller.h"
@ -83,6 +84,10 @@ class NetworkEmulationManagerImpl : public NetworkEmulationManager {
EmulatedNetworkManagerInterface* CreateEmulatedNetworkManagerInterface( EmulatedNetworkManagerInterface* CreateEmulatedNetworkManagerInterface(
const std::vector<EmulatedEndpoint*>& endpoints) override; const std::vector<EmulatedEndpoint*>& endpoints) override;
void GetStats(rtc::ArrayView<EmulatedEndpoint*> endpoints,
std::function<void(std::unique_ptr<EmulatedNetworkStats>)>
stats_callback) override;
TimeController* time_controller() override { return time_controller_.get(); } TimeController* time_controller() override { return time_controller_.get(); }
Timestamp Now() const; Timestamp Now() const;