blob: d04158d934f2dd31cbe575e66698679f27b5c028 [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"
Steve Anton10542f22019-01-11 09:11:00 -080022#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/critical_section.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"
Sebastian Janssonb55015e2019-04-09 13:44:04 +020028#include "rtc_base/synchronization/sequence_checker.h"
Yves Gerey3e707812018-11-28 16:47:49 +010029#include "rtc_base/third_party/sigslot/sigslot.h"
30#include "rtc_base/thread_annotations.h"
31#include "rtc_base/thread_checker.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020032#include "rtc_tools/network_tester/packet_logger.h"
33#include "rtc_tools/network_tester/packet_sender.h"
minyue939df962017-04-19 01:58:38 -070034
35#ifdef WEBRTC_NETWORK_TESTER_PROTO
36RTC_PUSH_IGNORING_WUNDEF()
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020037#include "rtc_tools/network_tester/network_tester_packet.pb.h"
Yves Gerey3e707812018-11-28 16:47:49 +010038
minyue939df962017-04-19 01:58:38 -070039RTC_POP_IGNORING_WUNDEF()
40using webrtc::network_tester::packet::NetworkTesterPacket;
41#else
42class NetworkTesterPacket;
43#endif // WEBRTC_NETWORK_TESTER_PROTO
44
45namespace webrtc {
46
47constexpr size_t kEthernetMtu = 1500;
48
49class TestController : public sigslot::has_slots<> {
50 public:
51 TestController(int min_port,
52 int max_port,
michaeltfcea39d2017-04-20 05:39:30 -070053 const std::string& config_file_path,
54 const std::string& log_file_path);
minyue939df962017-04-19 01:58:38 -070055
56 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);
minyue939df962017-04-19 01:58:38 -070073 rtc::ThreadChecker 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_;
minyue939df962017-04-19 01:58:38 -070078 rtc::CriticalSection 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_;
michaeltfcea39d2017-04-20 05:39:30 -070085
86 RTC_DISALLOW_COPY_AND_ASSIGN(TestController);
minyue939df962017-04-19 01:58:38 -070087};
88
89} // namespace webrtc
90
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020091#endif // RTC_TOOLS_NETWORK_TESTER_TEST_CONTROLLER_H_