blob: bde3b04b19d7a281b13bdd768a2fd92baad29b53 [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>
minyue939df962017-04-19 01:58:38 -070016#include <array>
minyue939df962017-04-19 01:58:38 -070017#include <memory>
18#include <string>
minyue939df962017-04-19 01:58:38 -070019
Yves Gerey3e707812018-11-28 16:47:49 +010020#include "absl/types/optional.h"
Steve Anton10542f22019-01-11 09:11:00 -080021#include "p2p/base/basic_packet_socket_factory.h"
22#include "rtc_base/async_packet_socket.h"
23#include "rtc_base/constructor_magic.h"
24#include "rtc_base/critical_section.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020025#include "rtc_base/ignore_wundef.h"
Yves Gerey3e707812018-11-28 16:47:49 +010026#include "rtc_base/sequenced_task_checker.h"
Steve Anton10542f22019-01-11 09:11:00 -080027#include "rtc_base/socket_address.h"
Yves Gerey3e707812018-11-28 16:47:49 +010028#include "rtc_base/third_party/sigslot/sigslot.h"
29#include "rtc_base/thread_annotations.h"
30#include "rtc_base/thread_checker.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"
Yves Gerey3e707812018-11-28 16:47:49 +010037
minyue939df962017-04-19 01:58:38 -070038RTC_POP_IGNORING_WUNDEF()
39using webrtc::network_tester::packet::NetworkTesterPacket;
40#else
41class NetworkTesterPacket;
42#endif // WEBRTC_NETWORK_TESTER_PROTO
43
44namespace webrtc {
45
46constexpr size_t kEthernetMtu = 1500;
47
48class TestController : public sigslot::has_slots<> {
49 public:
50 TestController(int min_port,
51 int max_port,
michaeltfcea39d2017-04-20 05:39:30 -070052 const std::string& config_file_path,
53 const std::string& log_file_path);
minyue939df962017-04-19 01:58:38 -070054
55 void Run();
56
57 void SendConnectTo(const std::string& hostname, int port);
58
59 void SendData(const NetworkTesterPacket& packet,
Danil Chapovalov431abd92018-06-18 12:54:17 +020060 absl::optional<size_t> data_size);
minyue939df962017-04-19 01:58:38 -070061
62 void OnTestDone();
63
64 bool IsTestDone();
65
66 private:
67 void OnReadPacket(rtc::AsyncPacketSocket* socket,
68 const char* data,
69 size_t len,
70 const rtc::SocketAddress& remote_addr,
Niels Möllere6933812018-11-05 13:01:41 +010071 const int64_t& packet_time_us);
minyue939df962017-04-19 01:58:38 -070072 rtc::ThreadChecker test_controller_thread_checker_;
73 rtc::SequencedTaskChecker packet_sender_checker_;
74 rtc::BasicPacketSocketFactory socket_factory_;
75 const std::string config_file_path_;
michaeltfcea39d2017-04-20 05:39:30 -070076 PacketLogger packet_logger_;
minyue939df962017-04-19 01:58:38 -070077 rtc::CriticalSection local_test_done_lock_;
danilchapa37de392017-09-09 04:17:22 -070078 bool local_test_done_ RTC_GUARDED_BY(local_test_done_lock_);
minyue939df962017-04-19 01:58:38 -070079 bool remote_test_done_;
80 std::array<char, kEthernetMtu> send_data_;
Jonas Olssoncfe3b6a2018-11-12 10:12:47 +010081 std::unique_ptr<rtc::AsyncPacketSocket> udp_socket_;
82 rtc::SocketAddress remote_address_;
minyue939df962017-04-19 01:58:38 -070083 std::unique_ptr<PacketSender> packet_sender_;
michaeltfcea39d2017-04-20 05:39:30 -070084
85 RTC_DISALLOW_COPY_AND_ASSIGN(TestController);
minyue939df962017-04-19 01:58:38 -070086};
87
88} // namespace webrtc
89
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020090#endif // RTC_TOOLS_NETWORK_TESTER_TEST_CONTROLLER_H_