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.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#ifndef TEST_SCENARIO_NETWORK_NETWORK_EMULATION_MANAGER_H_
|
|
|
|
|
#define TEST_SCENARIO_NETWORK_NETWORK_EMULATION_MANAGER_H_
|
|
|
|
|
|
|
|
|
|
#include <memory>
|
|
|
|
|
#include <utility>
|
|
|
|
|
#include <vector>
|
|
|
|
|
|
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"
|
|
|
|
|
#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-01-30 15:26:05 +01:00
|
|
|
#include "rtc_base/task_queue.h"
|
|
|
|
|
#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-02-11 14:40:17 +01:00
|
|
|
#include "test/scenario/network/cross_traffic.h"
|
2019-01-30 15:26:05 +01:00
|
|
|
#include "test/scenario/network/fake_network_socket_server.h"
|
|
|
|
|
#include "test/scenario/network/network_emulation.h"
|
2019-02-11 14:40:17 +01:00
|
|
|
#include "test/scenario/network/traffic_route.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:
|
2019-03-15 15:00:37 +01:00
|
|
|
NetworkEmulationManagerImpl();
|
|
|
|
|
~NetworkEmulationManagerImpl();
|
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-03-15 15:00:37 +01:00
|
|
|
EmulatedEndpoint* CreateEndpoint(EmulatedEndpointConfig config) 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;
|
|
|
|
|
void ClearRoute(EmulatedRoute* route) override;
|
2019-01-30 15:26:05 +01:00
|
|
|
|
2019-03-15 15:00:37 +01:00
|
|
|
TrafficRoute* CreateTrafficRoute(
|
|
|
|
|
const std::vector<EmulatedNetworkNode*>& via_nodes);
|
2019-02-11 14:40:17 +01:00
|
|
|
RandomWalkCrossTraffic* CreateRandomWalkCrossTraffic(
|
|
|
|
|
TrafficRoute* traffic_route,
|
|
|
|
|
RandomWalkConfig config);
|
|
|
|
|
PulsedPeaksCrossTraffic* CreatePulsedPeaksCrossTraffic(
|
|
|
|
|
TrafficRoute* traffic_route,
|
|
|
|
|
PulsedPeaksConfig config);
|
|
|
|
|
|
2019-03-15 15:00:37 +01:00
|
|
|
rtc::Thread* CreateNetworkThread(
|
|
|
|
|
const std::vector<EmulatedEndpoint*>& endpoints) override;
|
2019-03-13 10:30:51 +01:00
|
|
|
rtc::NetworkManager* CreateNetworkManager(
|
2019-03-15 15:00:37 +01:00
|
|
|
const std::vector<EmulatedEndpoint*>& endpoints) override;
|
2019-01-30 15:26:05 +01:00
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
FakeNetworkSocketServer* CreateSocketServer(
|
2019-03-15 15:00:37 +01:00
|
|
|
const std::vector<EmulatedEndpoint*>& endpoints);
|
2019-02-26 10:00:07 +01:00
|
|
|
absl::optional<rtc::IPAddress> GetNextIPv4Address();
|
2019-01-30 15:26:05 +01:00
|
|
|
void ProcessNetworkPackets();
|
|
|
|
|
Timestamp Now() const;
|
|
|
|
|
|
|
|
|
|
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_;
|
2019-02-11 14:40:17 +01:00
|
|
|
std::vector<std::unique_ptr<TrafficRoute>> traffic_routes_;
|
|
|
|
|
std::vector<std::unique_ptr<RandomWalkCrossTraffic>> random_cross_traffics_;
|
|
|
|
|
std::vector<std::unique_ptr<PulsedPeaksCrossTraffic>> pulsed_cross_traffics_;
|
2019-01-30 15:26:05 +01:00
|
|
|
std::vector<std::unique_ptr<FakeNetworkSocketServer>> socket_servers_;
|
|
|
|
|
std::vector<std::unique_ptr<rtc::Thread>> threads_;
|
2019-03-13 10:30:51 +01:00
|
|
|
std::vector<std::unique_ptr<rtc::NetworkManager>> managers_;
|
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.
|
|
|
|
|
rtc::TaskQueue task_queue_;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
} // namespace test
|
|
|
|
|
} // namespace webrtc
|
|
|
|
|
|
|
|
|
|
#endif // TEST_SCENARIO_NETWORK_NETWORK_EMULATION_MANAGER_H_
|