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" 21 #include "call/call.h" 22 #include "call/simulated_network.h" 23 #include "rtc_base/constructor_magic.h" 24 #include "rtc_base/copy_on_write_buffer.h" 25 #include "rtc_base/synchronization/mutex.h" 26 #include "rtc_base/task_queue.h" 27 #include "test/network/network_emulation.h" 28 #include "test/scenario/column_printer.h" 29 #include "test/scenario/scenario_config.h" 30 31 namespace webrtc { 32 namespace test { 33 34 class SimulationNode { 35 public: 36 SimulationNode(NetworkSimulationConfig config, 37 SimulatedNetwork* behavior, 38 EmulatedNetworkNode* network_node); 39 static std::unique_ptr<SimulatedNetwork> CreateBehavior( 40 NetworkSimulationConfig config); 41 42 void UpdateConfig(std::function<void(NetworkSimulationConfig*)> modifier); 43 void PauseTransmissionUntil(Timestamp until); 44 ColumnPrinter ConfigPrinter() const; node()45 EmulatedNetworkNode* node() { return network_node_; } 46 47 private: 48 NetworkSimulationConfig config_; 49 SimulatedNetwork* const simulation_; 50 EmulatedNetworkNode* const network_node_; 51 }; 52 53 class NetworkNodeTransport : public Transport { 54 public: 55 NetworkNodeTransport(Clock* sender_clock, Call* sender_call); 56 ~NetworkNodeTransport() override; 57 58 bool SendRtp(const uint8_t* packet, 59 size_t length, 60 const PacketOptions& options) override; 61 bool SendRtcp(const uint8_t* packet, size_t length) override; 62 63 void Connect(EmulatedEndpoint* endpoint, 64 const rtc::SocketAddress& receiver_address, 65 DataSize packet_overhead); 66 void Disconnect(); 67 packet_overhead()68 DataSize packet_overhead() { 69 MutexLock lock(&mutex_); 70 return packet_overhead_; 71 } 72 73 private: 74 Mutex mutex_; 75 Clock* const sender_clock_; 76 Call* const sender_call_; 77 EmulatedEndpoint* endpoint_ RTC_GUARDED_BY(mutex_) = nullptr; 78 rtc::SocketAddress local_address_ RTC_GUARDED_BY(mutex_); 79 rtc::SocketAddress remote_address_ RTC_GUARDED_BY(mutex_); 80 DataSize packet_overhead_ RTC_GUARDED_BY(mutex_) = DataSize::Zero(); 81 rtc::NetworkRoute current_network_route_ RTC_GUARDED_BY(mutex_); 82 }; 83 } // namespace test 84 } // namespace webrtc 85 #endif // TEST_SCENARIO_NETWORK_NODE_H_ 86