1 /* 2 * Copyright 2017 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 RTC_TOOLS_NETWORK_TESTER_TEST_CONTROLLER_H_ 12 #define RTC_TOOLS_NETWORK_TESTER_TEST_CONTROLLER_H_ 13 14 #include <stddef.h> 15 #include <stdint.h> 16 17 #include <array> 18 #include <memory> 19 #include <string> 20 21 #include "absl/types/optional.h" 22 #include "p2p/base/basic_packet_socket_factory.h" 23 #include "rtc_base/async_packet_socket.h" 24 #include "rtc_base/constructor_magic.h" 25 #include "rtc_base/ignore_wundef.h" 26 #include "rtc_base/socket_address.h" 27 #include "rtc_base/synchronization/mutex.h" 28 #include "rtc_base/synchronization/sequence_checker.h" 29 #include "rtc_base/third_party/sigslot/sigslot.h" 30 #include "rtc_base/thread_annotations.h" 31 #include "rtc_base/thread_checker.h" 32 #include "rtc_tools/network_tester/packet_logger.h" 33 #include "rtc_tools/network_tester/packet_sender.h" 34 35 #ifdef WEBRTC_NETWORK_TESTER_PROTO 36 RTC_PUSH_IGNORING_WUNDEF() 37 #include "rtc_tools/network_tester/network_tester_packet.pb.h" 38 RTC_POP_IGNORING_WUNDEF() 39 using webrtc::network_tester::packet::NetworkTesterPacket; 40 #else 41 class NetworkTesterPacket; 42 #endif // WEBRTC_NETWORK_TESTER_PROTO 43 44 namespace webrtc { 45 46 constexpr size_t kEthernetMtu = 1500; 47 48 class TestController : public sigslot::has_slots<> { 49 public: 50 TestController(int min_port, 51 int max_port, 52 const std::string& config_file_path, 53 const std::string& log_file_path); 54 55 void Run(); 56 57 void SendConnectTo(const std::string& hostname, int port); 58 59 void SendData(const NetworkTesterPacket& packet, 60 absl::optional<size_t> data_size); 61 62 void OnTestDone(); 63 64 bool IsTestDone(); 65 66 private: 67 void OnReadPacket(rtc::AsyncPacketSocket* socket, 68 const char* data, 69 size_t len, 70 const rtc::SocketAddress& remote_addr, 71 const int64_t& packet_time_us); 72 rtc::ThreadChecker test_controller_thread_checker_; 73 SequenceChecker packet_sender_checker_; 74 rtc::BasicPacketSocketFactory socket_factory_; 75 const std::string config_file_path_; 76 PacketLogger packet_logger_; 77 Mutex local_test_done_lock_; 78 bool local_test_done_ RTC_GUARDED_BY(local_test_done_lock_); 79 bool remote_test_done_; 80 std::array<char, kEthernetMtu> send_data_; 81 std::unique_ptr<rtc::AsyncPacketSocket> udp_socket_; 82 rtc::SocketAddress remote_address_; 83 std::unique_ptr<PacketSender> packet_sender_; 84 85 RTC_DISALLOW_COPY_AND_ASSIGN(TestController); 86 }; 87 88 } // namespace webrtc 89 90 #endif // RTC_TOOLS_NETWORK_TESTER_TEST_CONTROLLER_H_ 91