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