blob: 3933b46b5b6e3eecb948fd3d9b825a639f31484c [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"
Yves Gerey3e707812018-11-28 16:47:49 +010028#include "rtc_base/third_party/sigslot/sigslot.h"
29#include "rtc_base/thread_annotations.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020030#include "rtc_tools/network_tester/packet_logger.h"
31#include "rtc_tools/network_tester/packet_sender.h"
minyue939df962017-04-19 01:58:38 -070032
33#ifdef WEBRTC_NETWORK_TESTER_PROTO
34RTC_PUSH_IGNORING_WUNDEF()
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020035#include "rtc_tools/network_tester/network_tester_packet.pb.h"
minyue939df962017-04-19 01:58:38 -070036RTC_POP_IGNORING_WUNDEF()
37using webrtc::network_tester::packet::NetworkTesterPacket;
38#else
39class NetworkTesterPacket;
40#endif // WEBRTC_NETWORK_TESTER_PROTO
41
42namespace webrtc {
43
44constexpr size_t kEthernetMtu = 1500;
45
46class TestController : public sigslot::has_slots<> {
47 public:
48 TestController(int min_port,
49 int max_port,
michaeltfcea39d2017-04-20 05:39:30 -070050 const std::string& config_file_path,
51 const std::string& log_file_path);
minyue939df962017-04-19 01:58:38 -070052
Artem Titov6cae2d52022-01-26 15:01:10 +000053 TestController(const TestController&) = delete;
54 TestController& operator=(const TestController&) = delete;
55
minyue939df962017-04-19 01:58:38 -070056 void Run();
57
58 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);
Artem Titovc8421c42021-02-02 10:57:19 +010073 SequenceChecker test_controller_thread_checker_;
Sebastian Janssonb55015e2019-04-09 13:44:04 +020074 SequenceChecker packet_sender_checker_;
minyue939df962017-04-19 01:58:38 -070075 rtc::BasicPacketSocketFactory socket_factory_;
76 const std::string config_file_path_;
michaeltfcea39d2017-04-20 05:39:30 -070077 PacketLogger packet_logger_;
Markus Handell85585f42020-07-08 23:04:37 +020078 Mutex local_test_done_lock_;
danilchapa37de392017-09-09 04:17:22 -070079 bool local_test_done_ RTC_GUARDED_BY(local_test_done_lock_);
minyue939df962017-04-19 01:58:38 -070080 bool remote_test_done_;
81 std::array<char, kEthernetMtu> send_data_;
Jonas Olssoncfe3b6a2018-11-12 10:12:47 +010082 std::unique_ptr<rtc::AsyncPacketSocket> udp_socket_;
83 rtc::SocketAddress remote_address_;
minyue939df962017-04-19 01:58:38 -070084 std::unique_ptr<PacketSender> packet_sender_;
minyue939df962017-04-19 01:58:38 -070085};
86
87} // namespace webrtc
88
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020089#endif // RTC_TOOLS_NETWORK_TESTER_TEST_CONTROLLER_H_