Artem Titov | 7bf8c7f | 2019-03-15 14:00:37 | [diff] [blame] | 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 API_TEST_NETWORK_EMULATION_MANAGER_H_ |
| 12 | #define API_TEST_NETWORK_EMULATION_MANAGER_H_ |
| 13 | |
Artem Titov | 3e0b65d | 2020-07-23 00:19:02 | [diff] [blame] | 14 | #include <functional> |
Artem Titov | 7bf8c7f | 2019-03-15 14:00:37 | [diff] [blame] | 15 | #include <memory> |
Jonas Oreland | 9705011 | 2020-11-17 20:30:33 | [diff] [blame] | 16 | #include <string> |
Byoungchan Lee | e2f2cae | 2022-09-26 14:44:44 | [diff] [blame] | 17 | #include <utility> |
Artem Titov | 7bf8c7f | 2019-03-15 14:00:37 | [diff] [blame] | 18 | #include <vector> |
| 19 | |
Artem Titov | cf78128 | 2020-07-28 11:45:16 | [diff] [blame] | 20 | #include "api/array_view.h" |
Niels Möller | 5e7a3ae | 2021-09-09 13:54:42 | [diff] [blame] | 21 | #include "api/packet_socket_factory.h" |
Andrey Logvin | f9ee0e0 | 2021-01-14 09:50:32 | [diff] [blame] | 22 | #include "api/test/network_emulation/cross_traffic.h" |
Sebastian Jansson | cec2433 | 2019-12-04 13:26:50 | [diff] [blame] | 23 | #include "api/test/network_emulation/network_emulation_interfaces.h" |
Niels Möller | f47a724 | 2021-11-22 15:07:35 | [diff] [blame] | 24 | #include "api/test/peer_network_dependencies.h" |
Artem Titov | 7bf8c7f | 2019-03-15 14:00:37 | [diff] [blame] | 25 | #include "api/test/simulated_network.h" |
Sebastian Jansson | 6ce033a | 2020-01-22 09:12:56 | [diff] [blame] | 26 | #include "api/test/time_controller.h" |
Artem Titov | 806299e | 2019-04-12 10:17:19 | [diff] [blame] | 27 | #include "api/units/timestamp.h" |
Artem Titov | 7bf8c7f | 2019-03-15 14:00:37 | [diff] [blame] | 28 | #include "rtc_base/network.h" |
Artem Titov | 1e02339 | 2020-01-23 14:46:45 | [diff] [blame] | 29 | #include "rtc_base/network_constants.h" |
Artem Titov | 7bf8c7f | 2019-03-15 14:00:37 | [diff] [blame] | 30 | #include "rtc_base/thread.h" |
| 31 | |
| 32 | namespace webrtc { |
| 33 | |
| 34 | // This API is still in development and can be changed without prior notice. |
| 35 | |
| 36 | // These classes are forward declared here, because they used as handles, to |
| 37 | // make it possible for client code to operate with these abstractions and build |
| 38 | // required network configuration. With forward declaration here implementation |
| 39 | // is more readable, than with interfaces approach and cause user needn't any |
| 40 | // API methods on these abstractions it is acceptable here. |
| 41 | |
| 42 | // EmulatedNetworkNode is an abstraction for some network in the real world, |
| 43 | // like 3G network between peers, or Wi-Fi for one peer and LTE for another. |
| 44 | // Multiple networks can be joined into chain emulating a network path from |
| 45 | // one peer to another. |
| 46 | class EmulatedNetworkNode; |
Sebastian Jansson | cec2433 | 2019-12-04 13:26:50 | [diff] [blame] | 47 | |
Artem Titov | 7bf8c7f | 2019-03-15 14:00:37 | [diff] [blame] | 48 | // EmulatedRoute is handle for single route from one network interface on one |
| 49 | // peer device to another network interface on another peer device. |
| 50 | class EmulatedRoute; |
| 51 | |
Artem Titov | b41568b | 2022-11-11 22:14:30 | [diff] [blame] | 52 | enum class EmulatedNetworkStatsGatheringMode { |
| 53 | // Gather main network stats counters. See more details on which particular |
| 54 | // metrics are collected in the `EmulatedNetworkStats` and |
| 55 | // `EmulatedNetworkNodeStats` documentation. |
| 56 | kDefault, |
| 57 | // kDefault + also gather per packet statistics. In this mode more memory |
| 58 | // will be used. |
| 59 | kDebug |
| 60 | }; |
| 61 | |
Artem Titov | 7bf8c7f | 2019-03-15 14:00:37 | [diff] [blame] | 62 | struct EmulatedEndpointConfig { |
| 63 | enum class IpAddressFamily { kIpv4, kIpv6 }; |
| 64 | |
Artem Titov | d2dd732 | 2021-01-21 16:28:17 | [diff] [blame] | 65 | // If specified will be used to name endpoint for logging purposes. |
| 66 | absl::optional<std::string> name = absl::nullopt; |
Artem Titov | 7bf8c7f | 2019-03-15 14:00:37 | [diff] [blame] | 67 | IpAddressFamily generated_ip_family = IpAddressFamily::kIpv4; |
| 68 | // If specified will be used as IP address for endpoint node. Must be unique |
| 69 | // among all created nodes. |
| 70 | absl::optional<rtc::IPAddress> ip; |
Artem Titov | e5cc85b | 2019-03-28 11:11:09 | [diff] [blame] | 71 | // Should endpoint be enabled or not, when it will be created. |
| 72 | // Enabled endpoints will be available for webrtc to send packets. |
| 73 | bool start_as_enabled = true; |
Artem Titov | 1e02339 | 2020-01-23 14:46:45 | [diff] [blame] | 74 | // Network type which will be used to represent endpoint to WebRTC. |
| 75 | rtc::AdapterType type = rtc::AdapterType::ADAPTER_TYPE_UNKNOWN; |
Artem Titov | 3d37e06 | 2021-02-19 19:26:32 | [diff] [blame] | 76 | // Allow endpoint to send packets specifying source IP address different to |
| 77 | // the current endpoint IP address. If false endpoint will crash if attempt |
| 78 | // to send such packet will be done. |
| 79 | bool allow_send_packet_with_different_source_ip = false; |
| 80 | // Allow endpoint to receive packet with destination IP address different to |
| 81 | // the current endpoint IP address. If false endpoint will crash if such |
| 82 | // packet will arrive. |
| 83 | bool allow_receive_packets_with_different_dest_ip = false; |
Artem Titov | e5cc85b | 2019-03-28 11:11:09 | [diff] [blame] | 84 | }; |
| 85 | |
Jonas Oreland | 9705011 | 2020-11-17 20:30:33 | [diff] [blame] | 86 | struct EmulatedTURNServerConfig { |
| 87 | EmulatedEndpointConfig client_config; |
| 88 | EmulatedEndpointConfig peer_config; |
| 89 | }; |
| 90 | |
| 91 | // EmulatedTURNServer is an abstraction for a TURN server. |
| 92 | class EmulatedTURNServerInterface { |
| 93 | public: |
| 94 | struct IceServerConfig { |
| 95 | std::string username; |
| 96 | std::string password; |
| 97 | std::string url; |
| 98 | }; |
| 99 | |
| 100 | virtual ~EmulatedTURNServerInterface() {} |
| 101 | |
| 102 | // Get an IceServer configuration suitable to add to a PeerConnection. |
| 103 | virtual IceServerConfig GetIceServerConfig() const = 0; |
| 104 | |
| 105 | // Get non-null client endpoint, an endpoint that accepts TURN allocations. |
| 106 | // This shall typically be connected to one or more webrtc endpoint. |
| 107 | virtual EmulatedEndpoint* GetClientEndpoint() const = 0; |
| 108 | |
| 109 | // Returns socket address, which client should use to connect to TURN server |
| 110 | // and do TURN allocation. |
| 111 | virtual rtc::SocketAddress GetClientEndpointAddress() const = 0; |
| 112 | |
| 113 | // Get non-null peer endpoint, that is "connected to the internet". |
| 114 | // This shall typically be connected to another TURN server. |
| 115 | virtual EmulatedEndpoint* GetPeerEndpoint() const = 0; |
| 116 | }; |
Artem Titov | 806299e | 2019-04-12 10:17:19 | [diff] [blame] | 117 | |
Artem Titov | e5cc85b | 2019-03-28 11:11:09 | [diff] [blame] | 118 | // Provide interface to obtain all required objects to inject network emulation |
Artem Titov | 806299e | 2019-04-12 10:17:19 | [diff] [blame] | 119 | // layer into PeerConnection. Also contains information about network interfaces |
| 120 | // accessible by PeerConnection. |
Artem Titov | e5cc85b | 2019-03-28 11:11:09 | [diff] [blame] | 121 | class EmulatedNetworkManagerInterface { |
| 122 | public: |
| 123 | virtual ~EmulatedNetworkManagerInterface() = default; |
| 124 | |
Artem Titov | cf78128 | 2020-07-28 11:45:16 | [diff] [blame] | 125 | // Returns non-null pointer to thread that have to be used as network thread |
| 126 | // for WebRTC to properly setup network emulation. Returned thread is owned |
| 127 | // by EmulatedNetworkManagerInterface implementation. |
Artem Titov | e5cc85b | 2019-03-28 11:11:09 | [diff] [blame] | 128 | virtual rtc::Thread* network_thread() = 0; |
Artem Titov | cf78128 | 2020-07-28 11:45:16 | [diff] [blame] | 129 | // Returns non-null pointer to network manager that have to be injected into |
| 130 | // WebRTC to properly setup network emulation. Returned manager is owned by |
| 131 | // EmulatedNetworkManagerInterface implementation. |
Artem Titov | e5cc85b | 2019-03-28 11:11:09 | [diff] [blame] | 132 | virtual rtc::NetworkManager* network_manager() = 0; |
Niels Möller | 5e7a3ae | 2021-09-09 13:54:42 | [diff] [blame] | 133 | // Returns non-null pointer to packet socket factory that have to be injected |
| 134 | // into WebRTC to properly setup network emulation. Returned factory is owned |
| 135 | // by EmulatedNetworkManagerInterface implementation. |
| 136 | virtual rtc::PacketSocketFactory* packet_socket_factory() = 0; |
Niels Möller | f47a724 | 2021-11-22 15:07:35 | [diff] [blame] | 137 | webrtc::webrtc_pc_e2e::PeerNetworkDependencies network_dependencies() { |
| 138 | return {network_thread(), network_manager(), packet_socket_factory()}; |
| 139 | } |
Artem Titov | cf78128 | 2020-07-28 11:45:16 | [diff] [blame] | 140 | // Returns list of endpoints that are associated with this instance. Pointers |
| 141 | // are guaranteed to be non-null and are owned by NetworkEmulationManager. |
| 142 | virtual std::vector<EmulatedEndpoint*> endpoints() const = 0; |
Artem Titov | 806299e | 2019-04-12 10:17:19 | [diff] [blame] | 143 | |
Artem Titov | cf78128 | 2020-07-28 11:45:16 | [diff] [blame] | 144 | // Passes summarized network stats for endpoints for this manager into |
Artem Titov | 0e61fdd | 2021-07-25 19:50:14 | [diff] [blame] | 145 | // specified `stats_callback`. Callback will be executed on network emulation |
Artem Titov | 5501cef | 2020-08-04 09:49:19 | [diff] [blame] | 146 | // internal task queue. |
Artem Titov | e4c1b1c | 2022-11-09 10:54:12 | [diff] [blame] | 147 | virtual void GetStats( |
| 148 | std::function<void(EmulatedNetworkStats)> stats_callback) const = 0; |
Artem Titov | 7bf8c7f | 2019-03-15 14:00:37 | [diff] [blame] | 149 | }; |
| 150 | |
Sebastian Jansson | 6ce033a | 2020-01-22 09:12:56 | [diff] [blame] | 151 | enum class TimeMode { kRealTime, kSimulated }; |
| 152 | |
Björn Terelius | b22cabc | 2022-06-02 08:51:59 | [diff] [blame] | 153 | // Called implicitly when parsing an ABSL_FLAG of type TimeMode. |
| 154 | // from the command line flag value `text`. |
| 155 | // Returns `true` and sets `*mode` on success; |
| 156 | // returns `false` and sets `*error` on failure. |
| 157 | bool AbslParseFlag(absl::string_view text, TimeMode* mode, std::string* error); |
| 158 | |
| 159 | // AbslUnparseFlag returns a textual flag value corresponding to the TimeMode |
| 160 | // `mode`. |
| 161 | std::string AbslUnparseFlag(TimeMode mode); |
| 162 | |
Artem Titov | 7bf8c7f | 2019-03-15 14:00:37 | [diff] [blame] | 163 | // Provides an API for creating and configuring emulated network layer. |
| 164 | // All objects returned by this API are owned by NetworkEmulationManager itself |
| 165 | // and will be deleted when manager will be deleted. |
| 166 | class NetworkEmulationManager { |
| 167 | public: |
Sebastian Jansson | cec2433 | 2019-12-04 13:26:50 | [diff] [blame] | 168 | // Helper struct to simplify creation of simulated network behaviors. Contains |
| 169 | // non-owning pointers as the underlying instances are owned by the manager. |
| 170 | struct SimulatedNetworkNode { |
| 171 | SimulatedNetworkInterface* simulation; |
| 172 | EmulatedNetworkNode* node; |
| 173 | |
| 174 | class Builder { |
| 175 | public: |
| 176 | explicit Builder(NetworkEmulationManager* net) : net_(net) {} |
Sebastian Jansson | ce91126 | 2019-12-11 18:08:40 | [diff] [blame] | 177 | Builder() : net_(nullptr) {} |
Sebastian Jansson | cec2433 | 2019-12-04 13:26:50 | [diff] [blame] | 178 | Builder(const Builder&) = default; |
| 179 | // Sets the config state, note that this will replace any previously set |
| 180 | // values. |
| 181 | Builder& config(BuiltInNetworkBehaviorConfig config); |
| 182 | Builder& delay_ms(int queue_delay_ms); |
| 183 | Builder& capacity_kbps(int link_capacity_kbps); |
| 184 | Builder& capacity_Mbps(int link_capacity_Mbps); |
| 185 | Builder& loss(double loss_rate); |
Sebastian Jansson | 3927298 | 2019-12-11 18:29:57 | [diff] [blame] | 186 | Builder& packet_queue_length(int max_queue_length_in_packets); |
Mirko Bonadei | cad3aed | 2023-08-04 09:00:24 | [diff] [blame] | 187 | Builder& delay_standard_deviation_ms(int delay_standard_deviation_ms); |
| 188 | Builder& allow_reordering(); |
| 189 | Builder& avg_burst_loss_length(int avg_burst_loss_length); |
| 190 | Builder& packet_overhead(int packet_overhead); |
Artem Titov | ec9b281 | 2021-01-07 14:49:31 | [diff] [blame] | 191 | SimulatedNetworkNode Build(uint64_t random_seed = 1) const; |
| 192 | SimulatedNetworkNode Build(NetworkEmulationManager* net, |
| 193 | uint64_t random_seed = 1) const; |
Sebastian Jansson | cec2433 | 2019-12-04 13:26:50 | [diff] [blame] | 194 | |
| 195 | private: |
| 196 | NetworkEmulationManager* const net_; |
| 197 | BuiltInNetworkBehaviorConfig config_; |
| 198 | }; |
| 199 | }; |
Artem Titov | 7bf8c7f | 2019-03-15 14:00:37 | [diff] [blame] | 200 | virtual ~NetworkEmulationManager() = default; |
| 201 | |
Sebastian Jansson | 6ce033a | 2020-01-22 09:12:56 | [diff] [blame] | 202 | virtual TimeController* time_controller() = 0; |
Artem Titov | cc8a1f8 | 2021-01-26 12:58:23 | [diff] [blame] | 203 | // Returns a mode in which underlying time controller operates. |
| 204 | virtual TimeMode time_mode() const = 0; |
Sebastian Jansson | 6ce033a | 2020-01-22 09:12:56 | [diff] [blame] | 205 | |
Artem Titov | 1031a4f | 2022-07-21 14:04:45 | [diff] [blame] | 206 | // Creates an emulated network node, which represents ideal network with |
| 207 | // unlimited capacity, no delay and no packet loss. |
| 208 | EmulatedNetworkNode* CreateUnconstrainedEmulatedNode() { |
| 209 | return CreateEmulatedNode(BuiltInNetworkBehaviorConfig()); |
| 210 | } |
Artem Titov | 7bf8c7f | 2019-03-15 14:00:37 | [diff] [blame] | 211 | // Creates an emulated network node, which represents single network in |
Artem Titov | ec9b281 | 2021-01-07 14:49:31 | [diff] [blame] | 212 | // the emulated network layer. Uses default implementation on network behavior |
Artem Titov | 0e61fdd | 2021-07-25 19:50:14 | [diff] [blame] | 213 | // which can be configured with `config`. `random_seed` can be provided to |
Artem Titov | ec9b281 | 2021-01-07 14:49:31 | [diff] [blame] | 214 | // alter randomization behavior. |
Artem Titov | 7bf8c7f | 2019-03-15 14:00:37 | [diff] [blame] | 215 | virtual EmulatedNetworkNode* CreateEmulatedNode( |
Artem Titov | ec9b281 | 2021-01-07 14:49:31 | [diff] [blame] | 216 | BuiltInNetworkBehaviorConfig config, |
| 217 | uint64_t random_seed = 1) = 0; |
| 218 | // Creates an emulated network node, which represents single network in |
Artem Titov | 0e61fdd | 2021-07-25 19:50:14 | [diff] [blame] | 219 | // the emulated network layer. `network_behavior` determines how created node |
Artem Titov | ec9b281 | 2021-01-07 14:49:31 | [diff] [blame] | 220 | // will forward incoming packets to the next receiver. |
Artem Titov | 48b1b18 | 2019-07-05 11:09:48 | [diff] [blame] | 221 | virtual EmulatedNetworkNode* CreateEmulatedNode( |
Artem Titov | 7bf8c7f | 2019-03-15 14:00:37 | [diff] [blame] | 222 | std::unique_ptr<NetworkBehaviorInterface> network_behavior) = 0; |
| 223 | |
Sebastian Jansson | cec2433 | 2019-12-04 13:26:50 | [diff] [blame] | 224 | virtual SimulatedNetworkNode::Builder NodeBuilder() = 0; |
| 225 | |
Artem Titov | 7bf8c7f | 2019-03-15 14:00:37 | [diff] [blame] | 226 | // Creates an emulated endpoint, which represents single network interface on |
| 227 | // the peer's device. |
| 228 | virtual EmulatedEndpoint* CreateEndpoint(EmulatedEndpointConfig config) = 0; |
Artem Titov | e5cc85b | 2019-03-28 11:11:09 | [diff] [blame] | 229 | // Enable emulated endpoint to make it available for webrtc. |
| 230 | // Caller mustn't enable currently enabled endpoint. |
| 231 | virtual void EnableEndpoint(EmulatedEndpoint* endpoint) = 0; |
| 232 | // Disable emulated endpoint to make it unavailable for webrtc. |
| 233 | // Caller mustn't disable currently disabled endpoint. |
| 234 | virtual void DisableEndpoint(EmulatedEndpoint* endpoint) = 0; |
Artem Titov | 7bf8c7f | 2019-03-15 14:00:37 | [diff] [blame] | 235 | |
| 236 | // Creates a route between endpoints going through specified network nodes. |
| 237 | // This route is single direction only and describe how traffic that was |
Artem Titov | 0e61fdd | 2021-07-25 19:50:14 | [diff] [blame] | 238 | // sent by network interface `from` have to be delivered to the network |
| 239 | // interface `to`. Return object can be used to remove created route. The |
Artem Titov | ff39312 | 2019-04-05 09:19:52 | [diff] [blame] | 240 | // route must contains at least one network node inside it. |
Artem Titov | 7bf8c7f | 2019-03-15 14:00:37 | [diff] [blame] | 241 | // |
Artem Titov | ff39312 | 2019-04-05 09:19:52 | [diff] [blame] | 242 | // Assume that E{0-9} are endpoints and N{0-9} are network nodes, then |
| 243 | // creation of the route have to follow these rules: |
| 244 | // 1. A route consists of a source endpoint, an ordered list of one or |
| 245 | // more network nodes, and a destination endpoint. |
| 246 | // 2. If (E1, ..., E2) is a route, then E1 != E2. |
| 247 | // In other words, the source and the destination may not be the same. |
| 248 | // 3. Given two simultaneously existing routes (E1, ..., E2) and |
| 249 | // (E3, ..., E4), either E1 != E3 or E2 != E4. |
| 250 | // In other words, there may be at most one route from any given source |
| 251 | // endpoint to any given destination endpoint. |
| 252 | // 4. Given two simultaneously existing routes (E1, ..., N1, ..., E2) |
| 253 | // and (E3, ..., N2, ..., E4), either N1 != N2 or E2 != E4. |
| 254 | // In other words, a network node may not belong to two routes that lead |
| 255 | // to the same destination endpoint. |
Artem Titov | 7bf8c7f | 2019-03-15 14:00:37 | [diff] [blame] | 256 | virtual EmulatedRoute* CreateRoute( |
| 257 | EmulatedEndpoint* from, |
| 258 | const std::vector<EmulatedNetworkNode*>& via_nodes, |
| 259 | EmulatedEndpoint* to) = 0; |
Sebastian Jansson | cec2433 | 2019-12-04 13:26:50 | [diff] [blame] | 260 | |
Artem Titov | 0e61fdd | 2021-07-25 19:50:14 | [diff] [blame] | 261 | // Creates a route over the given `via_nodes` creating the required endpoints |
Sebastian Jansson | cec2433 | 2019-12-04 13:26:50 | [diff] [blame] | 262 | // in the process. The returned EmulatedRoute pointer can be used in other |
| 263 | // calls as a transport route for message or cross traffic. |
| 264 | virtual EmulatedRoute* CreateRoute( |
| 265 | const std::vector<EmulatedNetworkNode*>& via_nodes) = 0; |
| 266 | |
Artem Titov | 3d37e06 | 2021-02-19 19:26:32 | [diff] [blame] | 267 | // Creates a default route between endpoints going through specified network |
| 268 | // nodes. Default route is used for packet when there is no known route for |
| 269 | // packet's destination IP. |
| 270 | // |
| 271 | // This route is single direction only and describe how traffic that was |
Artem Titov | 0e61fdd | 2021-07-25 19:50:14 | [diff] [blame] | 272 | // sent by network interface `from` have to be delivered in case if routing |
Artem Titov | 3d37e06 | 2021-02-19 19:26:32 | [diff] [blame] | 273 | // was unspecified. Return object can be used to remove created route. The |
| 274 | // route must contains at least one network node inside it. |
| 275 | // |
| 276 | // Assume that E{0-9} are endpoints and N{0-9} are network nodes, then |
| 277 | // creation of the route have to follow these rules: |
| 278 | // 1. A route consists of a source endpoint, an ordered list of one or |
| 279 | // more network nodes, and a destination endpoint. |
| 280 | // 2. If (E1, ..., E2) is a route, then E1 != E2. |
| 281 | // In other words, the source and the destination may not be the same. |
| 282 | // 3. Given two simultaneously existing routes (E1, ..., E2) and |
| 283 | // (E3, ..., E4), either E1 != E3 or E2 != E4. |
| 284 | // In other words, there may be at most one route from any given source |
| 285 | // endpoint to any given destination endpoint. |
| 286 | // 4. Given two simultaneously existing routes (E1, ..., N1, ..., E2) |
| 287 | // and (E3, ..., N2, ..., E4), either N1 != N2 or E2 != E4. |
| 288 | // In other words, a network node may not belong to two routes that lead |
| 289 | // to the same destination endpoint. |
| 290 | // 5. Any node N can belong to only one default route. |
| 291 | virtual EmulatedRoute* CreateDefaultRoute( |
| 292 | EmulatedEndpoint* from, |
| 293 | const std::vector<EmulatedNetworkNode*>& via_nodes, |
| 294 | EmulatedEndpoint* to) = 0; |
| 295 | |
Artem Titov | 7bf8c7f | 2019-03-15 14:00:37 | [diff] [blame] | 296 | // Removes route previously created by CreateRoute(...). |
| 297 | // Caller mustn't call this function with route, that have been already |
Andrey Logvin | f9ee0e0 | 2021-01-14 09:50:32 | [diff] [blame] | 298 | // removed earlier. Removing a route that is currently in use will lead to |
| 299 | // packets being dropped. |
Artem Titov | 7bf8c7f | 2019-03-15 14:00:37 | [diff] [blame] | 300 | virtual void ClearRoute(EmulatedRoute* route) = 0; |
| 301 | |
Artem Titov | 0e61fdd | 2021-07-25 19:50:14 | [diff] [blame] | 302 | // Creates a simulated TCP connection using `send_route` for traffic and |
| 303 | // `ret_route` for feedback. This can be used to emulate HTTP cross traffic |
Sebastian Jansson | cec2433 | 2019-12-04 13:26:50 | [diff] [blame] | 304 | // and to implement realistic reliable signaling over lossy networks. |
| 305 | // TODO(srte): Handle clearing of the routes involved. |
| 306 | virtual TcpMessageRoute* CreateTcpRoute(EmulatedRoute* send_route, |
| 307 | EmulatedRoute* ret_route) = 0; |
| 308 | |
Artem Titov | 0e61fdd | 2021-07-25 19:50:14 | [diff] [blame] | 309 | // Creates a route over the given `via_nodes`. Returns an object that can be |
Andrey Logvin | f9ee0e0 | 2021-01-14 09:50:32 | [diff] [blame] | 310 | // used to emulate network load with cross traffic over the created route. |
| 311 | virtual CrossTrafficRoute* CreateCrossTrafficRoute( |
| 312 | const std::vector<EmulatedNetworkNode*>& via_nodes) = 0; |
| 313 | |
Artem Titov | 0e61fdd | 2021-07-25 19:50:14 | [diff] [blame] | 314 | // Starts generating cross traffic using given `generator`. Takes ownership |
Andrey Logvin | f9ee0e0 | 2021-01-14 09:50:32 | [diff] [blame] | 315 | // over the generator. |
| 316 | virtual CrossTrafficGenerator* StartCrossTraffic( |
| 317 | std::unique_ptr<CrossTrafficGenerator> generator) = 0; |
| 318 | |
Artem Titov | 0e61fdd | 2021-07-25 19:50:14 | [diff] [blame] | 319 | // Stops generating cross traffic that was started using given `generator`. |
| 320 | // The `generator` shouldn't be used after and the reference may be invalid. |
Andrey Logvin | f9ee0e0 | 2021-01-14 09:50:32 | [diff] [blame] | 321 | virtual void StopCrossTraffic(CrossTrafficGenerator* generator) = 0; |
| 322 | |
Artem Titov | e5cc85b | 2019-03-28 11:11:09 | [diff] [blame] | 323 | // Creates EmulatedNetworkManagerInterface which can be used then to inject |
Artem Titov | 0e61fdd | 2021-07-25 19:50:14 | [diff] [blame] | 324 | // network emulation layer into PeerConnection. `endpoints` - are available |
Artem Titov | e5cc85b | 2019-03-28 11:11:09 | [diff] [blame] | 325 | // network interfaces for PeerConnection. If endpoint is enabled, it will be |
| 326 | // immediately available for PeerConnection, otherwise user will be able to |
| 327 | // enable endpoint later to make it available for PeerConnection. |
| 328 | virtual EmulatedNetworkManagerInterface* |
| 329 | CreateEmulatedNetworkManagerInterface( |
Artem Titov | 7bf8c7f | 2019-03-15 14:00:37 | [diff] [blame] | 330 | const std::vector<EmulatedEndpoint*>& endpoints) = 0; |
Artem Titov | cf78128 | 2020-07-28 11:45:16 | [diff] [blame] | 331 | |
Artem Titov | b41568b | 2022-11-11 22:14:30 | [diff] [blame] | 332 | // Passes combined network stats for all specified `endpoints` into specified |
Artem Titov | 0e61fdd | 2021-07-25 19:50:14 | [diff] [blame] | 333 | // `stats_callback`. Callback will be executed on network emulation |
Artem Titov | 5501cef | 2020-08-04 09:49:19 | [diff] [blame] | 334 | // internal task queue. |
Artem Titov | e4c1b1c | 2022-11-09 10:54:12 | [diff] [blame] | 335 | virtual void GetStats( |
| 336 | rtc::ArrayView<EmulatedEndpoint* const> endpoints, |
| 337 | std::function<void(EmulatedNetworkStats)> stats_callback) = 0; |
Jonas Oreland | 9705011 | 2020-11-17 20:30:33 | [diff] [blame] | 338 | |
Artem Titov | b41568b | 2022-11-11 22:14:30 | [diff] [blame] | 339 | // Passes combined network stats for all specified `nodes` into specified |
| 340 | // `stats_callback`. Callback will be executed on network emulation |
| 341 | // internal task queue. |
| 342 | virtual void GetStats( |
| 343 | rtc::ArrayView<EmulatedNetworkNode* const> nodes, |
| 344 | std::function<void(EmulatedNetworkNodeStats)> stats_callback) = 0; |
| 345 | |
Jonas Oreland | 9705011 | 2020-11-17 20:30:33 | [diff] [blame] | 346 | // Create a EmulatedTURNServer. |
| 347 | // The TURN server has 2 endpoints that need to be connected with routes, |
| 348 | // - GetClientEndpoint() - the endpoint that accepts TURN allocations. |
| 349 | // - GetPeerEndpoint() - the endpoint that is "connected to the internet". |
| 350 | virtual EmulatedTURNServerInterface* CreateTURNServer( |
| 351 | EmulatedTURNServerConfig config) = 0; |
Byoungchan Lee | e2f2cae | 2022-09-26 14:44:44 | [diff] [blame] | 352 | |
| 353 | // Create a pair of EmulatedNetworkManagerInterfaces connected to each other. |
| 354 | std::pair<EmulatedNetworkManagerInterface*, EmulatedNetworkManagerInterface*> |
| 355 | CreateEndpointPairWithTwoWayRoutes( |
| 356 | const BuiltInNetworkBehaviorConfig& config); |
Artem Titov | 7bf8c7f | 2019-03-15 14:00:37 | [diff] [blame] | 357 | }; |
| 358 | |
| 359 | } // namespace webrtc |
| 360 | |
| 361 | #endif // API_TEST_NETWORK_EMULATION_MANAGER_H_ |