blob: 50055fcf4c5f8d07cbae2c5e76e88daabd598382 [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"
Artem Titov3f872502022-01-26 14:51:53 +000025#include "rtc_base/constructor_magic.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020026#include "rtc_base/ignore_wundef.h"
Steve Anton10542f22019-01-11 09:11:00 -080027#include "rtc_base/socket_address.h"
Markus Handell85585f42020-07-08 23:04:37 +020028#include "rtc_base/synchronization/mutex.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);
minyue939df962017-04-19 01:58:38 -070053
54 void Run();
55
56 void SendConnectTo(const std::string& hostname, int port);
57
58 void SendData(const NetworkTesterPacket& packet,
Danil Chapovalov431abd92018-06-18 12:54:17 +020059 absl::optional<size_t> data_size);
minyue939df962017-04-19 01:58:38 -070060
61 void OnTestDone();
62
63 bool IsTestDone();
64
65 private:
66 void OnReadPacket(rtc::AsyncPacketSocket* socket,
67 const char* data,
68 size_t len,
69 const rtc::SocketAddress& remote_addr,
Niels Möllere6933812018-11-05 13:01:41 +010070 const int64_t& packet_time_us);
Artem Titovc8421c42021-02-02 10:57:19 +010071 SequenceChecker test_controller_thread_checker_;
Sebastian Janssonb55015e2019-04-09 13:44:04 +020072 SequenceChecker packet_sender_checker_;
minyue939df962017-04-19 01:58:38 -070073 rtc::BasicPacketSocketFactory socket_factory_;
74 const std::string config_file_path_;
michaeltfcea39d2017-04-20 05:39:30 -070075 PacketLogger packet_logger_;
Markus Handell85585f42020-07-08 23:04:37 +020076 Mutex local_test_done_lock_;
danilchapa37de392017-09-09 04:17:22 -070077 bool local_test_done_ RTC_GUARDED_BY(local_test_done_lock_);
minyue939df962017-04-19 01:58:38 -070078 bool remote_test_done_;
79 std::array<char, kEthernetMtu> send_data_;
Jonas Olssoncfe3b6a2018-11-12 10:12:47 +010080 std::unique_ptr<rtc::AsyncPacketSocket> udp_socket_;
81 rtc::SocketAddress remote_address_;
minyue939df962017-04-19 01:58:38 -070082 std::unique_ptr<PacketSender> packet_sender_;
Artem Titov3f872502022-01-26 14:51:53 +000083
84 RTC_DISALLOW_COPY_AND_ASSIGN(TestController);
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_