minyue | 939df96 | 2017-04-19 01:58:38 -0700 | [diff] [blame] | 1 | /* |
| 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 Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 11 | #ifndef RTC_TOOLS_NETWORK_TESTER_TEST_CONTROLLER_H_ |
| 12 | #define RTC_TOOLS_NETWORK_TESTER_TEST_CONTROLLER_H_ |
minyue | 939df96 | 2017-04-19 01:58:38 -0700 | [diff] [blame] | 13 | |
| 14 | #include <array> |
| 15 | #include <limits> |
| 16 | #include <memory> |
| 17 | #include <string> |
| 18 | #include <utility> |
| 19 | |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 20 | #include "p2p/base/basicpacketsocketfactory.h" |
| 21 | #include "p2p/base/udptransport.h" |
| 22 | #include "rtc_base/constructormagic.h" |
| 23 | #include "rtc_base/ignore_wundef.h" |
| 24 | #include "rtc_tools/network_tester/packet_logger.h" |
| 25 | #include "rtc_tools/network_tester/packet_sender.h" |
minyue | 939df96 | 2017-04-19 01:58:38 -0700 | [diff] [blame] | 26 | |
| 27 | #ifdef WEBRTC_NETWORK_TESTER_PROTO |
| 28 | RTC_PUSH_IGNORING_WUNDEF() |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 29 | #include "rtc_tools/network_tester/network_tester_packet.pb.h" |
minyue | 939df96 | 2017-04-19 01:58:38 -0700 | [diff] [blame] | 30 | RTC_POP_IGNORING_WUNDEF() |
| 31 | using webrtc::network_tester::packet::NetworkTesterPacket; |
| 32 | #else |
| 33 | class NetworkTesterPacket; |
| 34 | #endif // WEBRTC_NETWORK_TESTER_PROTO |
| 35 | |
| 36 | namespace webrtc { |
| 37 | |
| 38 | constexpr size_t kEthernetMtu = 1500; |
| 39 | |
| 40 | class TestController : public sigslot::has_slots<> { |
| 41 | public: |
| 42 | TestController(int min_port, |
| 43 | int max_port, |
michaelt | fcea39d | 2017-04-20 05:39:30 -0700 | [diff] [blame] | 44 | const std::string& config_file_path, |
| 45 | const std::string& log_file_path); |
minyue | 939df96 | 2017-04-19 01:58:38 -0700 | [diff] [blame] | 46 | |
| 47 | void Run(); |
| 48 | |
| 49 | void SendConnectTo(const std::string& hostname, int port); |
| 50 | |
| 51 | void SendData(const NetworkTesterPacket& packet, |
Danil Chapovalov | 431abd9 | 2018-06-18 12:54:17 +0200 | [diff] [blame] | 52 | absl::optional<size_t> data_size); |
minyue | 939df96 | 2017-04-19 01:58:38 -0700 | [diff] [blame] | 53 | |
| 54 | void OnTestDone(); |
| 55 | |
| 56 | bool IsTestDone(); |
| 57 | |
| 58 | private: |
| 59 | void OnReadPacket(rtc::AsyncPacketSocket* socket, |
| 60 | const char* data, |
| 61 | size_t len, |
| 62 | const rtc::SocketAddress& remote_addr, |
Niels Möller | e693381 | 2018-11-05 13:01:41 +0100 | [diff] [blame] | 63 | const int64_t& packet_time_us); |
minyue | 939df96 | 2017-04-19 01:58:38 -0700 | [diff] [blame] | 64 | rtc::ThreadChecker test_controller_thread_checker_; |
| 65 | rtc::SequencedTaskChecker packet_sender_checker_; |
| 66 | rtc::BasicPacketSocketFactory socket_factory_; |
| 67 | const std::string config_file_path_; |
michaelt | fcea39d | 2017-04-20 05:39:30 -0700 | [diff] [blame] | 68 | PacketLogger packet_logger_; |
minyue | 939df96 | 2017-04-19 01:58:38 -0700 | [diff] [blame] | 69 | rtc::CriticalSection local_test_done_lock_; |
danilchap | a37de39 | 2017-09-09 04:17:22 -0700 | [diff] [blame] | 70 | bool local_test_done_ RTC_GUARDED_BY(local_test_done_lock_); |
minyue | 939df96 | 2017-04-19 01:58:38 -0700 | [diff] [blame] | 71 | bool remote_test_done_; |
| 72 | std::array<char, kEthernetMtu> send_data_; |
| 73 | std::unique_ptr<cricket::UdpTransport> udp_transport_; |
| 74 | std::unique_ptr<PacketSender> packet_sender_; |
michaelt | fcea39d | 2017-04-20 05:39:30 -0700 | [diff] [blame] | 75 | |
| 76 | RTC_DISALLOW_COPY_AND_ASSIGN(TestController); |
minyue | 939df96 | 2017-04-19 01:58:38 -0700 | [diff] [blame] | 77 | }; |
| 78 | |
| 79 | } // namespace webrtc |
| 80 | |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 81 | #endif // RTC_TOOLS_NETWORK_TESTER_TEST_CONTROLLER_H_ |