2019-01-30 15:26:05 +01:00
|
|
|
/*
|
|
|
|
|
* 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.
|
|
|
|
|
*/
|
|
|
|
|
|
2019-07-05 10:48:17 +02:00
|
|
|
#ifndef TEST_NETWORK_NETWORK_EMULATION_MANAGER_H_
|
|
|
|
|
#define TEST_NETWORK_NETWORK_EMULATION_MANAGER_H_
|
2019-01-30 15:26:05 +01:00
|
|
|
|
2019-07-05 10:48:17 +02:00
|
|
|
#include <map>
|
2019-01-30 15:26:05 +01:00
|
|
|
#include <memory>
|
2019-07-05 10:48:17 +02:00
|
|
|
#include <set>
|
2019-01-30 15:26:05 +01:00
|
|
|
#include <utility>
|
|
|
|
|
#include <vector>
|
|
|
|
|
|
2020-07-28 13:45:16 +02:00
|
|
|
#include "api/array_view.h"
|
2019-03-15 15:00:37 +01:00
|
|
|
#include "api/test/network_emulation_manager.h"
|
2019-01-30 15:26:05 +01:00
|
|
|
#include "api/test/simulated_network.h"
|
2019-11-21 10:37:18 -08:00
|
|
|
#include "api/test/time_controller.h"
|
2019-01-30 15:26:05 +01:00
|
|
|
#include "api/units/time_delta.h"
|
|
|
|
|
#include "api/units/timestamp.h"
|
|
|
|
|
#include "rtc_base/logging.h"
|
2019-03-13 10:30:51 +01:00
|
|
|
#include "rtc_base/network.h"
|
2019-03-21 09:58:30 +01:00
|
|
|
#include "rtc_base/task_queue_for_test.h"
|
2019-01-30 15:26:05 +01:00
|
|
|
#include "rtc_base/task_utils/repeating_task.h"
|
|
|
|
|
#include "rtc_base/thread.h"
|
2019-02-11 09:13:01 +01:00
|
|
|
#include "system_wrappers/include/clock.h"
|
2019-07-05 10:48:17 +02:00
|
|
|
#include "test/network/cross_traffic.h"
|
|
|
|
|
#include "test/network/emulated_network_manager.h"
|
2020-11-17 21:30:33 +01:00
|
|
|
#include "test/network/emulated_turn_server.h"
|
2019-07-05 10:48:17 +02:00
|
|
|
#include "test/network/fake_network_socket_server.h"
|
|
|
|
|
#include "test/network/network_emulation.h"
|
2019-01-30 15:26:05 +01:00
|
|
|
|
|
|
|
|
namespace webrtc {
|
|
|
|
|
namespace test {
|
|
|
|
|
|
2019-03-15 15:00:37 +01:00
|
|
|
class NetworkEmulationManagerImpl : public NetworkEmulationManager {
|
2019-01-30 15:26:05 +01:00
|
|
|
public:
|
2020-01-22 10:12:56 +01:00
|
|
|
explicit NetworkEmulationManagerImpl(TimeMode mode);
|
2019-03-15 15:00:37 +01:00
|
|
|
~NetworkEmulationManagerImpl();
|
2019-01-30 15:26:05 +01:00
|
|
|
|
2021-01-07 15:49:31 +01:00
|
|
|
EmulatedNetworkNode* CreateEmulatedNode(BuiltInNetworkBehaviorConfig config,
|
|
|
|
|
uint64_t random_seed = 1) override;
|
2019-01-30 15:26:05 +01:00
|
|
|
EmulatedNetworkNode* CreateEmulatedNode(
|
2019-03-15 15:00:37 +01:00
|
|
|
std::unique_ptr<NetworkBehaviorInterface> network_behavior) override;
|
2019-01-30 15:26:05 +01:00
|
|
|
|
2019-12-04 14:26:50 +01:00
|
|
|
SimulatedNetworkNode::Builder NodeBuilder() override;
|
2019-07-31 18:33:17 +02:00
|
|
|
|
2021-02-26 09:24:51 +01:00
|
|
|
EmulatedEndpointImpl* CreateEndpoint(EmulatedEndpointConfig config) override;
|
2019-03-28 12:11:09 +01:00
|
|
|
void EnableEndpoint(EmulatedEndpoint* endpoint) override;
|
|
|
|
|
void DisableEndpoint(EmulatedEndpoint* endpoint) override;
|
2019-01-30 15:26:05 +01:00
|
|
|
|
2019-03-12 13:48:32 +01:00
|
|
|
EmulatedRoute* CreateRoute(EmulatedEndpoint* from,
|
2019-03-15 15:00:37 +01:00
|
|
|
const std::vector<EmulatedNetworkNode*>& via_nodes,
|
|
|
|
|
EmulatedEndpoint* to) override;
|
2019-06-07 13:06:00 +02:00
|
|
|
|
|
|
|
|
EmulatedRoute* CreateRoute(
|
2019-12-04 14:26:50 +01:00
|
|
|
const std::vector<EmulatedNetworkNode*>& via_nodes) override;
|
2019-06-07 13:06:00 +02:00
|
|
|
|
2021-02-19 20:26:32 +01:00
|
|
|
EmulatedRoute* CreateDefaultRoute(
|
|
|
|
|
EmulatedEndpoint* from,
|
|
|
|
|
const std::vector<EmulatedNetworkNode*>& via_nodes,
|
|
|
|
|
EmulatedEndpoint* to) override;
|
|
|
|
|
|
2019-03-15 15:00:37 +01:00
|
|
|
void ClearRoute(EmulatedRoute* route) override;
|
2019-01-30 15:26:05 +01:00
|
|
|
|
2019-11-13 14:10:07 +01:00
|
|
|
TcpMessageRoute* CreateTcpRoute(EmulatedRoute* send_route,
|
2019-12-04 14:26:50 +01:00
|
|
|
EmulatedRoute* ret_route) override;
|
2019-11-12 16:36:34 +01:00
|
|
|
|
2021-01-14 09:50:32 +00:00
|
|
|
CrossTrafficRoute* CreateCrossTrafficRoute(
|
|
|
|
|
const std::vector<EmulatedNetworkNode*>& via_nodes) override;
|
|
|
|
|
|
|
|
|
|
CrossTrafficGenerator* StartCrossTraffic(
|
|
|
|
|
std::unique_ptr<CrossTrafficGenerator> generator) override;
|
|
|
|
|
void StopCrossTraffic(CrossTrafficGenerator* generator) override;
|
2019-02-11 14:40:17 +01:00
|
|
|
|
2019-03-28 12:11:09 +01:00
|
|
|
EmulatedNetworkManagerInterface* CreateEmulatedNetworkManagerInterface(
|
2019-03-15 15:00:37 +01:00
|
|
|
const std::vector<EmulatedEndpoint*>& endpoints) override;
|
2019-01-30 15:26:05 +01:00
|
|
|
|
2021-02-15 11:24:37 +01:00
|
|
|
void GetStats(rtc::ArrayView<EmulatedEndpoint* const> endpoints,
|
2020-07-28 13:45:16 +02:00
|
|
|
std::function<void(std::unique_ptr<EmulatedNetworkStats>)>
|
|
|
|
|
stats_callback) override;
|
|
|
|
|
|
2020-01-22 10:12:56 +01:00
|
|
|
TimeController* time_controller() override { return time_controller_.get(); }
|
|
|
|
|
|
2021-01-26 13:58:23 +01:00
|
|
|
TimeMode time_mode() const override { return time_mode_; }
|
|
|
|
|
|
2019-01-30 15:26:05 +01:00
|
|
|
Timestamp Now() const;
|
|
|
|
|
|
2020-11-17 21:30:33 +01:00
|
|
|
EmulatedTURNServerInterface* CreateTURNServer(
|
|
|
|
|
EmulatedTURNServerConfig config) override;
|
|
|
|
|
|
2020-01-22 10:12:56 +01:00
|
|
|
private:
|
2021-01-14 09:50:32 +00:00
|
|
|
using CrossTrafficSource =
|
|
|
|
|
std::pair<std::unique_ptr<CrossTrafficGenerator>, RepeatingTaskHandle>;
|
|
|
|
|
|
2020-01-22 10:12:56 +01:00
|
|
|
absl::optional<rtc::IPAddress> GetNextIPv4Address();
|
2021-01-26 13:58:23 +01:00
|
|
|
|
|
|
|
|
const TimeMode time_mode_;
|
2020-01-22 10:12:56 +01:00
|
|
|
const std::unique_ptr<TimeController> time_controller_;
|
2019-01-30 15:26:05 +01:00
|
|
|
Clock* const clock_;
|
|
|
|
|
int next_node_id_;
|
|
|
|
|
|
|
|
|
|
RepeatingTaskHandle process_task_handle_;
|
|
|
|
|
|
2019-02-26 10:00:07 +01:00
|
|
|
uint32_t next_ip4_address_;
|
|
|
|
|
std::set<rtc::IPAddress> used_ip_addresses_;
|
|
|
|
|
|
2019-01-30 15:26:05 +01:00
|
|
|
// All objects can be added to the manager only when it is idle.
|
2019-03-11 10:08:40 +01:00
|
|
|
std::vector<std::unique_ptr<EmulatedEndpoint>> endpoints_;
|
2019-01-30 15:26:05 +01:00
|
|
|
std::vector<std::unique_ptr<EmulatedNetworkNode>> network_nodes_;
|
2019-03-12 13:48:32 +01:00
|
|
|
std::vector<std::unique_ptr<EmulatedRoute>> routes_;
|
2021-01-14 09:50:32 +00:00
|
|
|
std::vector<std::unique_ptr<CrossTrafficRoute>> traffic_routes_;
|
|
|
|
|
std::vector<CrossTrafficSource> cross_traffics_;
|
2019-12-04 14:26:50 +01:00
|
|
|
std::list<std::unique_ptr<TcpMessageRouteImpl>> tcp_message_routes_;
|
2019-04-05 14:49:59 +02:00
|
|
|
std::vector<std::unique_ptr<EndpointsContainer>> endpoints_containers_;
|
2019-03-28 12:11:09 +01:00
|
|
|
std::vector<std::unique_ptr<EmulatedNetworkManager>> network_managers_;
|
2020-11-17 21:30:33 +01:00
|
|
|
std::vector<std::unique_ptr<EmulatedTURNServer>> turn_servers_;
|
2019-03-28 12:11:09 +01:00
|
|
|
|
|
|
|
|
std::map<EmulatedEndpoint*, EmulatedNetworkManager*>
|
|
|
|
|
endpoint_to_network_manager_;
|
2019-01-30 15:26:05 +01:00
|
|
|
|
|
|
|
|
// Must be the last field, so it will be deleted first, because tasks
|
|
|
|
|
// in the TaskQueue can access other fields of the instance of this class.
|
2019-03-21 09:58:30 +01:00
|
|
|
TaskQueueForTest task_queue_;
|
2019-01-30 15:26:05 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
} // namespace test
|
|
|
|
|
} // namespace webrtc
|
|
|
|
|
|
2019-07-05 10:48:17 +02:00
|
|
|
#endif // TEST_NETWORK_NETWORK_EMULATION_MANAGER_H_
|