test_controller.h 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  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. #ifndef RTC_TOOLS_NETWORK_TESTER_TEST_CONTROLLER_H_
  11. #define RTC_TOOLS_NETWORK_TESTER_TEST_CONTROLLER_H_
  12. #include <stddef.h>
  13. #include <stdint.h>
  14. #include <array>
  15. #include <memory>
  16. #include <string>
  17. #include "absl/types/optional.h"
  18. #include "p2p/base/basic_packet_socket_factory.h"
  19. #include "rtc_base/async_packet_socket.h"
  20. #include "rtc_base/constructor_magic.h"
  21. #include "rtc_base/ignore_wundef.h"
  22. #include "rtc_base/socket_address.h"
  23. #include "rtc_base/synchronization/mutex.h"
  24. #include "rtc_base/synchronization/sequence_checker.h"
  25. #include "rtc_base/third_party/sigslot/sigslot.h"
  26. #include "rtc_base/thread_annotations.h"
  27. #include "rtc_base/thread_checker.h"
  28. #include "rtc_tools/network_tester/packet_logger.h"
  29. #include "rtc_tools/network_tester/packet_sender.h"
  30. #ifdef WEBRTC_NETWORK_TESTER_PROTO
  31. RTC_PUSH_IGNORING_WUNDEF()
  32. #include "rtc_tools/network_tester/network_tester_packet.pb.h"
  33. RTC_POP_IGNORING_WUNDEF()
  34. using webrtc::network_tester::packet::NetworkTesterPacket;
  35. #else
  36. class NetworkTesterPacket;
  37. #endif // WEBRTC_NETWORK_TESTER_PROTO
  38. namespace webrtc {
  39. constexpr size_t kEthernetMtu = 1500;
  40. class TestController : public sigslot::has_slots<> {
  41. public:
  42. TestController(int min_port,
  43. int max_port,
  44. const std::string& config_file_path,
  45. const std::string& log_file_path);
  46. void Run();
  47. void SendConnectTo(const std::string& hostname, int port);
  48. void SendData(const NetworkTesterPacket& packet,
  49. absl::optional<size_t> data_size);
  50. void OnTestDone();
  51. bool IsTestDone();
  52. private:
  53. void OnReadPacket(rtc::AsyncPacketSocket* socket,
  54. const char* data,
  55. size_t len,
  56. const rtc::SocketAddress& remote_addr,
  57. const int64_t& packet_time_us);
  58. rtc::ThreadChecker test_controller_thread_checker_;
  59. SequenceChecker packet_sender_checker_;
  60. rtc::BasicPacketSocketFactory socket_factory_;
  61. const std::string config_file_path_;
  62. PacketLogger packet_logger_;
  63. Mutex local_test_done_lock_;
  64. bool local_test_done_ RTC_GUARDED_BY(local_test_done_lock_);
  65. bool remote_test_done_;
  66. std::array<char, kEthernetMtu> send_data_;
  67. std::unique_ptr<rtc::AsyncPacketSocket> udp_socket_;
  68. rtc::SocketAddress remote_address_;
  69. std::unique_ptr<PacketSender> packet_sender_;
  70. RTC_DISALLOW_COPY_AND_ASSIGN(TestController);
  71. };
  72. } // namespace webrtc
  73. #endif // RTC_TOOLS_NETWORK_TESTER_TEST_CONTROLLER_H_