minyue | 939df96 | 2017-04-19 01:58:38 -0700 | [diff] [blame] | 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 | |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 11 | #ifndef RTC_TOOLS_NETWORK_TESTER_TEST_CONTROLLER_H_ |
| 12 | #define RTC_TOOLS_NETWORK_TESTER_TEST_CONTROLLER_H_ |
minyue | 939df96 | 2017-04-19 01:58:38 -0700 | [diff] [blame] | 13 | |
Yves Gerey | 3e70781 | 2018-11-28 16:47:49 +0100 | [diff] [blame] | 14 | #include <stddef.h> |
| 15 | #include <stdint.h> |
Jonas Olsson | a4d8737 | 2019-07-05 19:08:33 +0200 | [diff] [blame] | 16 | |
minyue | 939df96 | 2017-04-19 01:58:38 -0700 | [diff] [blame] | 17 | #include <array> |
minyue | 939df96 | 2017-04-19 01:58:38 -0700 | [diff] [blame] | 18 | #include <memory> |
| 19 | #include <string> |
minyue | 939df96 | 2017-04-19 01:58:38 -0700 | [diff] [blame] | 20 | |
Yves Gerey | 3e70781 | 2018-11-28 16:47:49 +0100 | [diff] [blame] | 21 | #include "absl/types/optional.h" |
Artem Titov | d15a575 | 2021-02-10 14:31:24 +0100 | [diff] [blame] | 22 | #include "api/sequence_checker.h" |
Steve Anton | 10542f2 | 2019-01-11 09:11:00 -0800 | [diff] [blame] | 23 | #include "p2p/base/basic_packet_socket_factory.h" |
| 24 | #include "rtc_base/async_packet_socket.h" |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 25 | #include "rtc_base/ignore_wundef.h" |
Steve Anton | 10542f2 | 2019-01-11 09:11:00 -0800 | [diff] [blame] | 26 | #include "rtc_base/socket_address.h" |
Markus Handell | 85585f4 | 2020-07-08 23:04:37 +0200 | [diff] [blame] | 27 | #include "rtc_base/synchronization/mutex.h" |
Byoungchan Lee | c931f70 | 2022-07-03 17:20:17 +0900 | [diff] [blame] | 28 | #include "rtc_base/system/no_unique_address.h" |
Yves Gerey | 3e70781 | 2018-11-28 16:47:49 +0100 | [diff] [blame] | 29 | #include "rtc_base/third_party/sigslot/sigslot.h" |
| 30 | #include "rtc_base/thread_annotations.h" |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 31 | #include "rtc_tools/network_tester/packet_logger.h" |
| 32 | #include "rtc_tools/network_tester/packet_sender.h" |
minyue | 939df96 | 2017-04-19 01:58:38 -0700 | [diff] [blame] | 33 | |
| 34 | #ifdef WEBRTC_NETWORK_TESTER_PROTO |
| 35 | RTC_PUSH_IGNORING_WUNDEF() |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 36 | #include "rtc_tools/network_tester/network_tester_packet.pb.h" |
minyue | 939df96 | 2017-04-19 01:58:38 -0700 | [diff] [blame] | 37 | RTC_POP_IGNORING_WUNDEF() |
| 38 | using webrtc::network_tester::packet::NetworkTesterPacket; |
| 39 | #else |
| 40 | class NetworkTesterPacket; |
| 41 | #endif // WEBRTC_NETWORK_TESTER_PROTO |
| 42 | |
| 43 | namespace webrtc { |
| 44 | |
| 45 | constexpr size_t kEthernetMtu = 1500; |
| 46 | |
| 47 | class TestController : public sigslot::has_slots<> { |
| 48 | public: |
| 49 | TestController(int min_port, |
| 50 | int max_port, |
michaelt | fcea39d | 2017-04-20 05:39:30 -0700 | [diff] [blame] | 51 | const std::string& config_file_path, |
| 52 | const std::string& log_file_path); |
Byoungchan Lee | c931f70 | 2022-07-03 17:20:17 +0900 | [diff] [blame] | 53 | ~TestController() override; |
minyue | 939df96 | 2017-04-19 01:58:38 -0700 | [diff] [blame] | 54 | |
Artem Titov | 6cae2d5 | 2022-01-26 15:01:10 +0000 | [diff] [blame] | 55 | TestController(const TestController&) = delete; |
| 56 | TestController& operator=(const TestController&) = delete; |
| 57 | |
minyue | 939df96 | 2017-04-19 01:58:38 -0700 | [diff] [blame] | 58 | void SendConnectTo(const std::string& hostname, int port); |
| 59 | |
| 60 | void SendData(const NetworkTesterPacket& packet, |
Danil Chapovalov | 431abd9 | 2018-06-18 12:54:17 +0200 | [diff] [blame] | 61 | absl::optional<size_t> data_size); |
minyue | 939df96 | 2017-04-19 01:58:38 -0700 | [diff] [blame] | 62 | |
| 63 | void OnTestDone(); |
| 64 | |
| 65 | bool IsTestDone(); |
| 66 | |
| 67 | private: |
| 68 | void OnReadPacket(rtc::AsyncPacketSocket* socket, |
| 69 | const char* data, |
| 70 | size_t len, |
| 71 | const rtc::SocketAddress& remote_addr, |
Niels Möller | e693381 | 2018-11-05 13:01:41 +0100 | [diff] [blame] | 72 | const int64_t& packet_time_us); |
Byoungchan Lee | c931f70 | 2022-07-03 17:20:17 +0900 | [diff] [blame] | 73 | RTC_NO_UNIQUE_ADDRESS SequenceChecker test_controller_thread_checker_; |
| 74 | std::unique_ptr<rtc::SocketServer> socket_server_; |
| 75 | std::unique_ptr<rtc::Thread> packet_sender_thread_; |
| 76 | rtc::BasicPacketSocketFactory socket_factory_ |
| 77 | RTC_GUARDED_BY(packet_sender_thread_); |
minyue | 939df96 | 2017-04-19 01:58:38 -0700 | [diff] [blame] | 78 | const std::string config_file_path_; |
Byoungchan Lee | c931f70 | 2022-07-03 17:20:17 +0900 | [diff] [blame] | 79 | PacketLogger packet_logger_ RTC_GUARDED_BY(packet_sender_thread_); |
| 80 | Mutex test_done_lock_ RTC_GUARDED_BY(test_controller_thread_checker_); |
| 81 | bool local_test_done_ RTC_GUARDED_BY(test_done_lock_); |
| 82 | bool remote_test_done_ RTC_GUARDED_BY(test_done_lock_); |
| 83 | std::array<char, kEthernetMtu> send_data_ |
| 84 | RTC_GUARDED_BY(packet_sender_thread_); |
| 85 | std::unique_ptr<rtc::AsyncPacketSocket> udp_socket_ |
| 86 | RTC_GUARDED_BY(packet_sender_thread_); |
Jonas Olsson | cfe3b6a | 2018-11-12 10:12:47 +0100 | [diff] [blame] | 87 | rtc::SocketAddress remote_address_; |
Byoungchan Lee | c931f70 | 2022-07-03 17:20:17 +0900 | [diff] [blame] | 88 | std::unique_ptr<PacketSender> packet_sender_ |
| 89 | RTC_GUARDED_BY(packet_sender_thread_); |
| 90 | rtc::scoped_refptr<webrtc::PendingTaskSafetyFlag> task_safety_flag_; |
minyue | 939df96 | 2017-04-19 01:58:38 -0700 | [diff] [blame] | 91 | }; |
| 92 | |
| 93 | } // namespace webrtc |
| 94 | |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 95 | #endif // RTC_TOOLS_NETWORK_TESTER_TEST_CONTROLLER_H_ |