blob: b08fbd5dd832f705f1e11abfaf045afe35847548 [file] [log] [blame]
minyue939df962017-04-19 01:58:38 -07001/*
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 Bonadei92ea95e2017-09-15 06:47:31 +020011#ifndef RTC_TOOLS_NETWORK_TESTER_TEST_CONTROLLER_H_
12#define RTC_TOOLS_NETWORK_TESTER_TEST_CONTROLLER_H_
minyue939df962017-04-19 01:58:38 -070013
Yves Gerey3e707812018-11-28 16:47:49 +010014#include <stddef.h>
15#include <stdint.h>
Jonas Olssona4d87372019-07-05 19:08:33 +020016
minyue939df962017-04-19 01:58:38 -070017#include <array>
minyue939df962017-04-19 01:58:38 -070018#include <memory>
19#include <string>
minyue939df962017-04-19 01:58:38 -070020
Yves Gerey3e707812018-11-28 16:47:49 +010021#include "absl/types/optional.h"
Artem Titovd15a5752021-02-10 14:31:24 +010022#include "api/sequence_checker.h"
Steve Anton10542f22019-01-11 09:11:00 -080023#include "p2p/base/basic_packet_socket_factory.h"
24#include "rtc_base/async_packet_socket.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020025#include "rtc_base/ignore_wundef.h"
Steve Anton10542f22019-01-11 09:11:00 -080026#include "rtc_base/socket_address.h"
Markus Handell85585f42020-07-08 23:04:37 +020027#include "rtc_base/synchronization/mutex.h"
Byoungchan Leec931f702022-07-03 17:20:17 +090028#include "rtc_base/system/no_unique_address.h"
Yves Gerey3e707812018-11-28 16:47:49 +010029#include "rtc_base/third_party/sigslot/sigslot.h"
30#include "rtc_base/thread_annotations.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020031#include "rtc_tools/network_tester/packet_logger.h"
32#include "rtc_tools/network_tester/packet_sender.h"
minyue939df962017-04-19 01:58:38 -070033
34#ifdef WEBRTC_NETWORK_TESTER_PROTO
35RTC_PUSH_IGNORING_WUNDEF()
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020036#include "rtc_tools/network_tester/network_tester_packet.pb.h"
minyue939df962017-04-19 01:58:38 -070037RTC_POP_IGNORING_WUNDEF()
38using webrtc::network_tester::packet::NetworkTesterPacket;
39#else
40class NetworkTesterPacket;
41#endif // WEBRTC_NETWORK_TESTER_PROTO
42
43namespace webrtc {
44
45constexpr size_t kEthernetMtu = 1500;
46
47class TestController : public sigslot::has_slots<> {
48 public:
49 TestController(int min_port,
50 int max_port,
michaeltfcea39d2017-04-20 05:39:30 -070051 const std::string& config_file_path,
52 const std::string& log_file_path);
Byoungchan Leec931f702022-07-03 17:20:17 +090053 ~TestController() override;
minyue939df962017-04-19 01:58:38 -070054
Artem Titov6cae2d52022-01-26 15:01:10 +000055 TestController(const TestController&) = delete;
56 TestController& operator=(const TestController&) = delete;
57
minyue939df962017-04-19 01:58:38 -070058 void SendConnectTo(const std::string& hostname, int port);
59
60 void SendData(const NetworkTesterPacket& packet,
Danil Chapovalov431abd92018-06-18 12:54:17 +020061 absl::optional<size_t> data_size);
minyue939df962017-04-19 01:58:38 -070062
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öllere6933812018-11-05 13:01:41 +010072 const int64_t& packet_time_us);
Byoungchan Leec931f702022-07-03 17:20:17 +090073 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_);
minyue939df962017-04-19 01:58:38 -070078 const std::string config_file_path_;
Byoungchan Leec931f702022-07-03 17:20:17 +090079 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 Olssoncfe3b6a2018-11-12 10:12:47 +010087 rtc::SocketAddress remote_address_;
Byoungchan Leec931f702022-07-03 17:20:17 +090088 std::unique_ptr<PacketSender> packet_sender_
89 RTC_GUARDED_BY(packet_sender_thread_);
90 rtc::scoped_refptr<webrtc::PendingTaskSafetyFlag> task_safety_flag_;
minyue939df962017-04-19 01:58:38 -070091};
92
93} // namespace webrtc
94
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020095#endif // RTC_TOOLS_NETWORK_TESTER_TEST_CONTROLLER_H_