Sebastian Jansson | 98b07e9 | 2018-09-27 13:47:01 +0200 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2018 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 | #ifndef TEST_SCENARIO_NETWORK_NODE_H_ |
| 11 | #define TEST_SCENARIO_NETWORK_NODE_H_ |
| 12 | |
| 13 | #include <deque> |
| 14 | #include <map> |
| 15 | #include <memory> |
| 16 | #include <utility> |
| 17 | #include <vector> |
| 18 | |
| 19 | #include "api/call/transport.h" |
| 20 | #include "api/units/timestamp.h" |
Sebastian Jansson | 800e121 | 2018-10-22 11:49:03 +0200 | [diff] [blame] | 21 | #include "call/call.h" |
Sebastian Jansson | 98b07e9 | 2018-09-27 13:47:01 +0200 | [diff] [blame] | 22 | #include "call/simulated_network.h" |
Steve Anton | 10542f2 | 2019-01-11 09:11:00 -0800 | [diff] [blame] | 23 | #include "rtc_base/copy_on_write_buffer.h" |
Markus Handell | a5a4be1 | 2020-07-08 16:09:21 +0200 | [diff] [blame] | 24 | #include "rtc_base/synchronization/mutex.h" |
Sebastian Jansson | 4124dab | 2019-04-01 14:33:53 +0200 | [diff] [blame] | 25 | #include "rtc_base/task_queue.h" |
Artem Titov | 386802e | 2019-07-05 10:48:17 +0200 | [diff] [blame] | 26 | #include "test/network/network_emulation.h" |
Sebastian Jansson | 98b07e9 | 2018-09-27 13:47:01 +0200 | [diff] [blame] | 27 | #include "test/scenario/column_printer.h" |
| 28 | #include "test/scenario/scenario_config.h" |
| 29 | |
| 30 | namespace webrtc { |
| 31 | namespace test { |
| 32 | |
Sebastian Jansson | a4c22b9 | 2019-04-15 21:10:00 +0200 | [diff] [blame] | 33 | class SimulationNode { |
Sebastian Jansson | 98b07e9 | 2018-09-27 13:47:01 +0200 | [diff] [blame] | 34 | public: |
Sebastian Jansson | a4c22b9 | 2019-04-15 21:10:00 +0200 | [diff] [blame] | 35 | SimulationNode(NetworkSimulationConfig config, |
| 36 | SimulatedNetwork* behavior, |
| 37 | EmulatedNetworkNode* network_node); |
| 38 | static std::unique_ptr<SimulatedNetwork> CreateBehavior( |
| 39 | NetworkSimulationConfig config); |
Artem Titov | 40f5115 | 2019-01-04 15:45:01 +0100 | [diff] [blame] | 40 | |
Sebastian Jansson | ef86d14 | 2019-04-15 14:42:42 +0200 | [diff] [blame] | 41 | void UpdateConfig(std::function<void(NetworkSimulationConfig*)> modifier); |
Sebastian Jansson | 98b07e9 | 2018-09-27 13:47:01 +0200 | [diff] [blame] | 42 | void PauseTransmissionUntil(Timestamp until); |
| 43 | ColumnPrinter ConfigPrinter() const; |
Sebastian Jansson | a4c22b9 | 2019-04-15 21:10:00 +0200 | [diff] [blame] | 44 | EmulatedNetworkNode* node() { return network_node_; } |
Sebastian Jansson | 98b07e9 | 2018-09-27 13:47:01 +0200 | [diff] [blame] | 45 | |
| 46 | private: |
Sebastian Jansson | ef86d14 | 2019-04-15 14:42:42 +0200 | [diff] [blame] | 47 | NetworkSimulationConfig config_; |
Sebastian Jansson | a4c22b9 | 2019-04-15 21:10:00 +0200 | [diff] [blame] | 48 | SimulatedNetwork* const simulation_; |
| 49 | EmulatedNetworkNode* const network_node_; |
Sebastian Jansson | 98b07e9 | 2018-09-27 13:47:01 +0200 | [diff] [blame] | 50 | }; |
| 51 | |
| 52 | class NetworkNodeTransport : public Transport { |
| 53 | public: |
Sebastian Jansson | aa01f27 | 2019-01-30 11:28:59 +0100 | [diff] [blame] | 54 | NetworkNodeTransport(Clock* sender_clock, Call* sender_call); |
Sebastian Jansson | 98b07e9 | 2018-09-27 13:47:01 +0200 | [diff] [blame] | 55 | ~NetworkNodeTransport() override; |
| 56 | |
| 57 | bool SendRtp(const uint8_t* packet, |
| 58 | size_t length, |
| 59 | const PacketOptions& options) override; |
| 60 | bool SendRtcp(const uint8_t* packet, size_t length) override; |
Sebastian Jansson | 800e121 | 2018-10-22 11:49:03 +0200 | [diff] [blame] | 61 | |
Sebastian Jansson | 77bd385 | 2020-01-17 13:05:54 +0100 | [diff] [blame] | 62 | void Connect(EmulatedEndpoint* endpoint, |
| 63 | const rtc::SocketAddress& receiver_address, |
Sebastian Jansson | 800e121 | 2018-10-22 11:49:03 +0200 | [diff] [blame] | 64 | DataSize packet_overhead); |
Sebastian Jansson | 4124dab | 2019-04-01 14:33:53 +0200 | [diff] [blame] | 65 | void Disconnect(); |
Sebastian Jansson | 800e121 | 2018-10-22 11:49:03 +0200 | [diff] [blame] | 66 | |
| 67 | DataSize packet_overhead() { |
Markus Handell | a5a4be1 | 2020-07-08 16:09:21 +0200 | [diff] [blame] | 68 | MutexLock lock(&mutex_); |
Sebastian Jansson | 800e121 | 2018-10-22 11:49:03 +0200 | [diff] [blame] | 69 | return packet_overhead_; |
| 70 | } |
Sebastian Jansson | 98b07e9 | 2018-09-27 13:47:01 +0200 | [diff] [blame] | 71 | |
| 72 | private: |
Markus Handell | a5a4be1 | 2020-07-08 16:09:21 +0200 | [diff] [blame] | 73 | Mutex mutex_; |
Sebastian Jansson | aa01f27 | 2019-01-30 11:28:59 +0100 | [diff] [blame] | 74 | Clock* const sender_clock_; |
Sebastian Jansson | 800e121 | 2018-10-22 11:49:03 +0200 | [diff] [blame] | 75 | Call* const sender_call_; |
Markus Handell | a5a4be1 | 2020-07-08 16:09:21 +0200 | [diff] [blame] | 76 | EmulatedEndpoint* endpoint_ RTC_GUARDED_BY(mutex_) = nullptr; |
| 77 | rtc::SocketAddress local_address_ RTC_GUARDED_BY(mutex_); |
| 78 | rtc::SocketAddress remote_address_ RTC_GUARDED_BY(mutex_); |
| 79 | DataSize packet_overhead_ RTC_GUARDED_BY(mutex_) = DataSize::Zero(); |
| 80 | rtc::NetworkRoute current_network_route_ RTC_GUARDED_BY(mutex_); |
Sebastian Jansson | 98b07e9 | 2018-09-27 13:47:01 +0200 | [diff] [blame] | 81 | }; |
Sebastian Jansson | 98b07e9 | 2018-09-27 13:47:01 +0200 | [diff] [blame] | 82 | } // namespace test |
| 83 | } // namespace webrtc |
| 84 | #endif // TEST_SCENARIO_NETWORK_NODE_H_ |