1 /* 2 * Copyright (c) 2019 The WebRTC project authors. All Rights Reserved. 3 * 4 * Use of this source code is governed by a BSD-style license 5 * that can be found in the LICENSE file in the root of the source 6 * tree. An additional intellectual property rights grant can be found 7 * in the file PATENTS. All contributing project authors may 8 * be found in the AUTHORS file in the root of the source tree. 9 */ 10 11 #ifndef TEST_NETWORK_EMULATED_NETWORK_MANAGER_H_ 12 #define TEST_NETWORK_EMULATED_NETWORK_MANAGER_H_ 13 14 #include <memory> 15 #include <vector> 16 17 #include "api/test/network_emulation_manager.h" 18 #include "api/test/time_controller.h" 19 #include "rtc_base/ip_address.h" 20 #include "rtc_base/network.h" 21 #include "rtc_base/socket_server.h" 22 #include "rtc_base/thread.h" 23 #include "rtc_base/thread_checker.h" 24 #include "test/network/network_emulation.h" 25 26 namespace webrtc { 27 namespace test { 28 29 // Framework assumes that rtc::NetworkManager is called from network thread. 30 class EmulatedNetworkManager : public rtc::NetworkManagerBase, 31 public sigslot::has_slots<>, 32 public EmulatedNetworkManagerInterface { 33 public: 34 EmulatedNetworkManager(TimeController* time_controller, 35 TaskQueueForTest* task_queue, 36 EndpointsContainer* endpoints_container); 37 38 void EnableEndpoint(EmulatedEndpointImpl* endpoint); 39 void DisableEndpoint(EmulatedEndpointImpl* endpoint); 40 41 // NetworkManager interface. All these methods are supposed to be called from 42 // the same thread. 43 void StartUpdating() override; 44 void StopUpdating() override; 45 46 // We don't support any address interfaces in the network emulation framework. GetAnyAddressNetworks(NetworkList * networks)47 void GetAnyAddressNetworks(NetworkList* networks) override {} 48 49 // EmulatedNetworkManagerInterface API network_thread()50 rtc::Thread* network_thread() override { return network_thread_.get(); } network_manager()51 rtc::NetworkManager* network_manager() override { return this; } 52 void GetStats( 53 std::function<void(EmulatedNetworkStats)> stats_callback) const override; 54 55 private: 56 void UpdateNetworksOnce(); 57 void MaybeSignalNetworksChanged(); 58 59 TaskQueueForTest* const task_queue_; 60 EndpointsContainer* const endpoints_container_; 61 std::unique_ptr<rtc::Thread> network_thread_; 62 63 bool sent_first_update_ RTC_GUARDED_BY(network_thread_); 64 int start_count_ RTC_GUARDED_BY(network_thread_); 65 }; 66 67 } // namespace test 68 } // namespace webrtc 69 70 #endif // TEST_NETWORK_EMULATED_NETWORK_MANAGER_H_ 71