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:
parent
6c5f787741
commit
cf781282f1
@ -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",
|
||||
|
||||
@ -15,6 +15,7 @@
|
||||
#include <memory>
|
||||
#include <vector>
|
||||
|
||||
#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<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(
|
||||
std::function<void(std::unique_ptr<EmulatedNetworkStats>)> stats_callback)
|
||||
const = 0;
|
||||
@ -182,6 +193,13 @@ class NetworkEmulationManager {
|
||||
virtual EmulatedNetworkManagerInterface*
|
||||
CreateEmulatedNetworkManagerInterface(
|
||||
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
|
||||
|
||||
@ -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<EmulatedEndpoint*> endpoints() const override {
|
||||
return endpoints_container_->endpoints();
|
||||
}
|
||||
void GetStats(std::function<void(std::unique_ptr<EmulatedNetworkStats>)>
|
||||
stats_callback) const override;
|
||||
|
||||
|
||||
@ -469,6 +469,10 @@ EndpointsContainer::GetEnabledNetworks() const {
|
||||
return networks;
|
||||
}
|
||||
|
||||
std::vector<EmulatedEndpoint*> EndpointsContainer::endpoints() const {
|
||||
return std::vector<EmulatedEndpoint*>(endpoints_.begin(), endpoints_.end());
|
||||
}
|
||||
|
||||
std::unique_ptr<EmulatedNetworkStats> EndpointsContainer::GetStats() const {
|
||||
EmulatedNetworkStatsBuilder stats_builder;
|
||||
for (auto* endpoint : endpoints_) {
|
||||
|
||||
@ -349,6 +349,7 @@ class EndpointsContainer {
|
||||
// Returns list of networks for enabled endpoints. Caller takes ownership of
|
||||
// returned rtc::Network objects.
|
||||
std::vector<std::unique_ptr<rtc::Network>> GetEnabledNetworks() const;
|
||||
std::vector<EmulatedEndpoint*> endpoints() const;
|
||||
std::unique_ptr<EmulatedNetworkStats> GetStats() const;
|
||||
|
||||
private:
|
||||
|
||||
@ -295,6 +295,18 @@ NetworkEmulationManagerImpl::CreateEmulatedNetworkManagerInterface(
|
||||
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>
|
||||
NetworkEmulationManagerImpl::GetNextIPv4Address() {
|
||||
uint32_t addresses_count = kMaxIPv4Address - kMinIPv4Address;
|
||||
|
||||
@ -17,6 +17,7 @@
|
||||
#include <utility>
|
||||
#include <vector>
|
||||
|
||||
#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<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(); }
|
||||
|
||||
Timestamp Now() const;
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user