2017-04-19 01:58:38 -07:00
|
|
|
/*
|
|
|
|
|
* Copyright 2017 The WebRTC project authors. All Rights Reserved.
|
|
|
|
|
*
|
|
|
|
|
* Use of this source code is governed by a BSD-style license
|
|
|
|
|
* that can be found in the LICENSE file in the root of the source
|
|
|
|
|
* tree. An additional intellectual property rights grant can be found
|
|
|
|
|
* in the file PATENTS. All contributing project authors may
|
|
|
|
|
* be found in the AUTHORS file in the root of the source tree.
|
|
|
|
|
*/
|
|
|
|
|
|
2017-09-15 06:47:31 +02:00
|
|
|
#ifndef RTC_TOOLS_NETWORK_TESTER_TEST_CONTROLLER_H_
|
|
|
|
|
#define RTC_TOOLS_NETWORK_TESTER_TEST_CONTROLLER_H_
|
2017-04-19 01:58:38 -07:00
|
|
|
|
2018-11-28 16:47:49 +01:00
|
|
|
#include <stddef.h>
|
|
|
|
|
#include <stdint.h>
|
2019-07-05 19:08:33 +02:00
|
|
|
|
2017-04-19 01:58:38 -07:00
|
|
|
#include <array>
|
|
|
|
|
#include <memory>
|
|
|
|
|
#include <string>
|
|
|
|
|
|
2018-11-28 16:47:49 +01:00
|
|
|
#include "absl/types/optional.h"
|
2021-02-10 14:31:24 +01:00
|
|
|
#include "api/sequence_checker.h"
|
2019-01-11 09:11:00 -08:00
|
|
|
#include "p2p/base/basic_packet_socket_factory.h"
|
|
|
|
|
#include "rtc_base/async_packet_socket.h"
|
|
|
|
|
#include "rtc_base/socket_address.h"
|
2020-07-08 23:04:37 +02:00
|
|
|
#include "rtc_base/synchronization/mutex.h"
|
2022-07-03 17:20:17 +09:00
|
|
|
#include "rtc_base/system/no_unique_address.h"
|
2018-11-28 16:47:49 +01:00
|
|
|
#include "rtc_base/third_party/sigslot/sigslot.h"
|
|
|
|
|
#include "rtc_base/thread_annotations.h"
|
2017-09-15 06:47:31 +02:00
|
|
|
#include "rtc_tools/network_tester/packet_logger.h"
|
|
|
|
|
#include "rtc_tools/network_tester/packet_sender.h"
|
2017-04-19 01:58:38 -07:00
|
|
|
|
|
|
|
|
#ifdef WEBRTC_NETWORK_TESTER_PROTO
|
2017-09-15 06:47:31 +02:00
|
|
|
#include "rtc_tools/network_tester/network_tester_packet.pb.h"
|
2017-04-19 01:58:38 -07:00
|
|
|
using webrtc::network_tester::packet::NetworkTesterPacket;
|
|
|
|
|
#else
|
|
|
|
|
class NetworkTesterPacket;
|
|
|
|
|
#endif // WEBRTC_NETWORK_TESTER_PROTO
|
|
|
|
|
|
|
|
|
|
namespace webrtc {
|
|
|
|
|
|
|
|
|
|
constexpr size_t kEthernetMtu = 1500;
|
|
|
|
|
|
|
|
|
|
class TestController : public sigslot::has_slots<> {
|
|
|
|
|
public:
|
|
|
|
|
TestController(int min_port,
|
|
|
|
|
int max_port,
|
2017-04-20 05:39:30 -07:00
|
|
|
const std::string& config_file_path,
|
|
|
|
|
const std::string& log_file_path);
|
2022-07-03 17:20:17 +09:00
|
|
|
~TestController() override;
|
2017-04-19 01:58:38 -07:00
|
|
|
|
2022-01-26 15:01:10 +00:00
|
|
|
TestController(const TestController&) = delete;
|
|
|
|
|
TestController& operator=(const TestController&) = delete;
|
|
|
|
|
|
2017-04-19 01:58:38 -07:00
|
|
|
void SendConnectTo(const std::string& hostname, int port);
|
|
|
|
|
|
|
|
|
|
void SendData(const NetworkTesterPacket& packet,
|
2018-06-18 12:54:17 +02:00
|
|
|
absl::optional<size_t> data_size);
|
2017-04-19 01:58:38 -07:00
|
|
|
|
|
|
|
|
void OnTestDone();
|
|
|
|
|
|
|
|
|
|
bool IsTestDone();
|
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
void OnReadPacket(rtc::AsyncPacketSocket* socket,
|
|
|
|
|
const char* data,
|
|
|
|
|
size_t len,
|
|
|
|
|
const rtc::SocketAddress& remote_addr,
|
2018-11-05 13:01:41 +01:00
|
|
|
const int64_t& packet_time_us);
|
2022-07-03 17:20:17 +09:00
|
|
|
RTC_NO_UNIQUE_ADDRESS SequenceChecker test_controller_thread_checker_;
|
|
|
|
|
std::unique_ptr<rtc::SocketServer> socket_server_;
|
|
|
|
|
std::unique_ptr<rtc::Thread> packet_sender_thread_;
|
|
|
|
|
rtc::BasicPacketSocketFactory socket_factory_
|
|
|
|
|
RTC_GUARDED_BY(packet_sender_thread_);
|
2017-04-19 01:58:38 -07:00
|
|
|
const std::string config_file_path_;
|
2022-07-03 17:20:17 +09:00
|
|
|
PacketLogger packet_logger_ RTC_GUARDED_BY(packet_sender_thread_);
|
|
|
|
|
Mutex test_done_lock_ RTC_GUARDED_BY(test_controller_thread_checker_);
|
|
|
|
|
bool local_test_done_ RTC_GUARDED_BY(test_done_lock_);
|
|
|
|
|
bool remote_test_done_ RTC_GUARDED_BY(test_done_lock_);
|
|
|
|
|
std::array<char, kEthernetMtu> send_data_
|
|
|
|
|
RTC_GUARDED_BY(packet_sender_thread_);
|
|
|
|
|
std::unique_ptr<rtc::AsyncPacketSocket> udp_socket_
|
|
|
|
|
RTC_GUARDED_BY(packet_sender_thread_);
|
2018-11-12 10:12:47 +01:00
|
|
|
rtc::SocketAddress remote_address_;
|
2022-07-03 17:20:17 +09:00
|
|
|
std::unique_ptr<PacketSender> packet_sender_
|
|
|
|
|
RTC_GUARDED_BY(packet_sender_thread_);
|
|
|
|
|
rtc::scoped_refptr<webrtc::PendingTaskSafetyFlag> task_safety_flag_;
|
2017-04-19 01:58:38 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
} // namespace webrtc
|
|
|
|
|
|
2017-09-15 06:47:31 +02:00
|
|
|
#endif // RTC_TOOLS_NETWORK_TESTER_TEST_CONTROLLER_H_
|