Add packet logger and server
BUG=webrtc:7426 Review-Url: https://codereview.webrtc.org/2790513002 Cr-Commit-Position: refs/heads/master@{#17788}
This commit is contained in:
@ -28,6 +28,8 @@ if (rtc_enable_protobuf) {
|
||||
sources = [
|
||||
"config_reader.cc",
|
||||
"config_reader.h",
|
||||
"packet_logger.cc",
|
||||
"packet_logger.h",
|
||||
"packet_sender.cc",
|
||||
"packet_sender.h",
|
||||
"test_controller.cc",
|
||||
@ -39,6 +41,7 @@ if (rtc_enable_protobuf) {
|
||||
deps = [
|
||||
":network_tester_config_proto",
|
||||
":network_tester_packet_proto",
|
||||
"../../base:protobuf_utils",
|
||||
"../../base:rtc_task_queue",
|
||||
"../../p2p",
|
||||
]
|
||||
@ -93,4 +96,19 @@ if (rtc_enable_protobuf) {
|
||||
suppressed_configs += [ "//build/config/clang:find_bad_constructs" ]
|
||||
}
|
||||
}
|
||||
|
||||
rtc_executable("network_tester_server") {
|
||||
sources = [
|
||||
"server.cc",
|
||||
]
|
||||
|
||||
deps = [
|
||||
":network_tester",
|
||||
]
|
||||
|
||||
if (!build_with_chromium && is_clang) {
|
||||
# Suppress warnings from the Chromium Clang plugin (bugs.webrtc.org/163).
|
||||
suppressed_configs += [ "//build/config/clang:find_bad_constructs" ]
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -21,10 +21,12 @@ namespace webrtc {
|
||||
|
||||
TEST(NetworkTesterTest, ServerClient) {
|
||||
TestController client(
|
||||
0, 0, webrtc::test::ResourcePath("network_tester/client_config", "dat"));
|
||||
0, 0, webrtc::test::ResourcePath("network_tester/client_config", "dat"),
|
||||
webrtc::test::OutputPath() + "client_packet_log.dat");
|
||||
TestController server(
|
||||
9090, 9090,
|
||||
webrtc::test::ResourcePath("network_tester/server_config", "dat"));
|
||||
webrtc::test::ResourcePath("network_tester/server_config", "dat"),
|
||||
webrtc::test::OutputPath() + "server_packet_log.dat");
|
||||
client.SendConnectTo("127.0.0.1", 9090);
|
||||
EXPECT_TRUE_WAIT(server.IsTestDone() && client.IsTestDone(), 2000);
|
||||
}
|
||||
|
||||
43
webrtc/tools/network_tester/packet_logger.cc
Normal file
43
webrtc/tools/network_tester/packet_logger.cc
Normal file
@ -0,0 +1,43 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
#include "webrtc/tools/network_tester/packet_logger.h"
|
||||
|
||||
#include "webrtc/base/checks.h"
|
||||
#include "webrtc/base/protobuf_utils.h"
|
||||
|
||||
namespace webrtc {
|
||||
|
||||
PacketLogger::PacketLogger(const std::string& log_file_path)
|
||||
: packet_logger_stream_(log_file_path,
|
||||
std::ios_base::out | std::ios_base::binary) {
|
||||
RTC_DCHECK(packet_logger_stream_.is_open());
|
||||
RTC_DCHECK(packet_logger_stream_.good());
|
||||
}
|
||||
|
||||
PacketLogger::~PacketLogger() = default;
|
||||
|
||||
void PacketLogger::LogPacket(const NetworkTesterPacket& packet) {
|
||||
// The protobuffer message will be saved in the following format to the file:
|
||||
// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
||||
// | 1 byte | X byte | 1 byte | ... | X byte |
|
||||
// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
||||
// | Size of the next | proto | Size of the next | ... | proto |
|
||||
// | proto message | message | proto message | | message |
|
||||
// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
||||
ProtoString packet_data;
|
||||
packet.SerializeToString(&packet_data);
|
||||
RTC_DCHECK_LE(packet_data.length(), 255);
|
||||
RTC_DCHECK_GE(packet_data.length(), 0);
|
||||
char proto_size = packet_data.length();
|
||||
packet_logger_stream_.write(&proto_size, sizeof(proto_size));
|
||||
packet_logger_stream_.write(packet_data.data(), packet_data.length());
|
||||
}
|
||||
|
||||
} // namespace webrtc
|
||||
46
webrtc/tools/network_tester/packet_logger.h
Normal file
46
webrtc/tools/network_tester/packet_logger.h
Normal file
@ -0,0 +1,46 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#ifndef WEBRTC_TOOLS_NETWORK_TESTER_PACKET_LOGGER_H_
|
||||
#define WEBRTC_TOOLS_NETWORK_TESTER_PACKET_LOGGER_H_
|
||||
|
||||
#include <fstream>
|
||||
#include <string>
|
||||
|
||||
#include "webrtc/base/constructormagic.h"
|
||||
#include "webrtc/base/ignore_wundef.h"
|
||||
|
||||
#ifdef WEBRTC_NETWORK_TESTER_PROTO
|
||||
RTC_PUSH_IGNORING_WUNDEF()
|
||||
#include "webrtc/tools/network_tester/network_tester_packet.pb.h"
|
||||
RTC_POP_IGNORING_WUNDEF()
|
||||
using webrtc::network_tester::packet::NetworkTesterPacket;
|
||||
#else
|
||||
class NetworkTesterPacket;
|
||||
#endif // WEBRTC_NETWORK_TESTER_PROTO
|
||||
|
||||
namespace webrtc {
|
||||
|
||||
class PacketLogger {
|
||||
public:
|
||||
explicit PacketLogger(const std::string& log_file_path);
|
||||
~PacketLogger();
|
||||
|
||||
void LogPacket(const NetworkTesterPacket& packet);
|
||||
|
||||
private:
|
||||
std::ofstream packet_logger_stream_;
|
||||
|
||||
RTC_DISALLOW_COPY_AND_ASSIGN(PacketLogger);
|
||||
};
|
||||
|
||||
} // namespace webrtc
|
||||
|
||||
#endif // WEBRTC_TOOLS_NETWORK_TESTER_PACKET_LOGGER_H_
|
||||
@ -14,6 +14,7 @@
|
||||
#include <memory>
|
||||
#include <string>
|
||||
|
||||
#include "webrtc/base/constructormagic.h"
|
||||
#include "webrtc/base/ignore_wundef.h"
|
||||
#include "webrtc/base/sequenced_task_checker.h"
|
||||
#include "webrtc/base/task_queue.h"
|
||||
|
||||
19
webrtc/tools/network_tester/server.cc
Normal file
19
webrtc/tools/network_tester/server.cc
Normal file
@ -0,0 +1,19 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#include "webrtc/tools/network_tester/test_controller.h"
|
||||
|
||||
int main() {
|
||||
webrtc::TestController server(9090, 9090, "server_config.dat",
|
||||
"server_packet_log.dat");
|
||||
while (!server.IsTestDone()) {
|
||||
server.Run();
|
||||
}
|
||||
}
|
||||
@ -14,8 +14,10 @@ namespace webrtc {
|
||||
|
||||
TestController::TestController(int min_port,
|
||||
int max_port,
|
||||
const std::string& config_file_path)
|
||||
const std::string& config_file_path,
|
||||
const std::string& log_file_path)
|
||||
: config_file_path_(config_file_path),
|
||||
packet_logger_(log_file_path),
|
||||
local_test_done_(false),
|
||||
remote_test_done_(false) {
|
||||
RTC_DCHECK_RUN_ON(&test_controller_thread_checker_);
|
||||
@ -104,7 +106,7 @@ void TestController::OnReadPacket(rtc::AsyncPacketSocket* socket,
|
||||
case NetworkTesterPacket::TEST_DATA: {
|
||||
packet.set_arrival_timestamp(packet_time.timestamp);
|
||||
packet.set_packet_size(len);
|
||||
// log packet
|
||||
packet_logger_.LogPacket(packet);
|
||||
break;
|
||||
}
|
||||
case NetworkTesterPacket::TEST_DONE: {
|
||||
|
||||
@ -17,9 +17,11 @@
|
||||
#include <string>
|
||||
#include <utility>
|
||||
|
||||
#include "webrtc/base/constructormagic.h"
|
||||
#include "webrtc/base/ignore_wundef.h"
|
||||
#include "webrtc/p2p/base/basicpacketsocketfactory.h"
|
||||
#include "webrtc/p2p/base/udptransport.h"
|
||||
#include "webrtc/tools/network_tester/packet_logger.h"
|
||||
#include "webrtc/tools/network_tester/packet_sender.h"
|
||||
|
||||
#ifdef WEBRTC_NETWORK_TESTER_PROTO
|
||||
@ -39,7 +41,8 @@ class TestController : public sigslot::has_slots<> {
|
||||
public:
|
||||
TestController(int min_port,
|
||||
int max_port,
|
||||
const std::string& config_file_path);
|
||||
const std::string& config_file_path,
|
||||
const std::string& log_file_path);
|
||||
|
||||
void Run();
|
||||
|
||||
@ -62,12 +65,15 @@ class TestController : public sigslot::has_slots<> {
|
||||
rtc::SequencedTaskChecker packet_sender_checker_;
|
||||
rtc::BasicPacketSocketFactory socket_factory_;
|
||||
const std::string config_file_path_;
|
||||
PacketLogger packet_logger_;
|
||||
rtc::CriticalSection local_test_done_lock_;
|
||||
bool local_test_done_ GUARDED_BY(local_test_done_lock_);
|
||||
bool remote_test_done_;
|
||||
std::array<char, kEthernetMtu> send_data_;
|
||||
std::unique_ptr<cricket::UdpTransport> udp_transport_;
|
||||
std::unique_ptr<PacketSender> packet_sender_;
|
||||
|
||||
RTC_DISALLOW_COPY_AND_ASSIGN(TestController);
|
||||
};
|
||||
|
||||
} // namespace webrtc
|
||||
|
||||
Reference in New Issue
Block a user