From b005087a8cac6afda03b0b100f7a9f5b26ebeac4 Mon Sep 17 00:00:00 2001 From: Artem Titov Date: Thu, 16 Aug 2018 17:02:20 +0200 Subject: [PATCH] Add replacements for all FakeNetworkPipe ctors. Add replacements for all FakeNetworkPipe constructos, that will accept instance of NetworkSimulationInterface instead of config to be able to use any implmentation of network simulation. Bug: webrtc:9630 Change-Id: Ifceb2f0d028faf255648891ce695b3742f866044 Reviewed-on: https://webrtc-review.googlesource.com/94541 Commit-Queue: Artem Titov Reviewed-by: Sebastian Jansson Cr-Commit-Position: refs/heads/master@{#24320} --- call/fake_network_pipe.cc | 56 ++++++++++++++++++------- call/fake_network_pipe.h | 27 +++++++++++- call/test/fake_network_pipe_unittest.cc | 9 ++-- 3 files changed, 70 insertions(+), 22 deletions(-) diff --git a/call/fake_network_pipe.cc b/call/fake_network_pipe.cc index dd8d5d7552..55af767cb2 100644 --- a/call/fake_network_pipe.cc +++ b/call/fake_network_pipe.cc @@ -88,20 +88,6 @@ FakeNetworkPipe::FakeNetworkPipe(Clock* clock, const FakeNetworkPipe::Config& config) : FakeNetworkPipe(clock, config, nullptr, 1) {} -FakeNetworkPipe::FakeNetworkPipe( - Clock* clock, - std::unique_ptr network_simulation) - : clock_(clock), - network_simulation_(std::move(network_simulation)), - receiver_(nullptr), - transport_(nullptr), - clock_offset_ms_(0), - dropped_packets_(0), - sent_packets_(0), - total_packet_delay_us_(0), - next_process_time_us_(clock_->TimeInMicroseconds()), - last_log_time_us_(clock_->TimeInMicroseconds()) {} - FakeNetworkPipe::FakeNetworkPipe(Clock* clock, const FakeNetworkPipe::Config& config, PacketReceiver* receiver) @@ -136,6 +122,48 @@ FakeNetworkPipe::FakeNetworkPipe(Clock* clock, next_process_time_us_(clock_->TimeInMicroseconds()), last_log_time_us_(clock_->TimeInMicroseconds()) {} +FakeNetworkPipe::FakeNetworkPipe( + Clock* clock, + std::unique_ptr network_simulation) + : FakeNetworkPipe(clock, std::move(network_simulation), nullptr, 1) {} + +FakeNetworkPipe::FakeNetworkPipe( + Clock* clock, + std::unique_ptr network_simulation, + PacketReceiver* receiver) + : FakeNetworkPipe(clock, std::move(network_simulation), receiver, 1) {} + +FakeNetworkPipe::FakeNetworkPipe( + Clock* clock, + std::unique_ptr network_simulation, + PacketReceiver* receiver, + uint64_t seed) + : clock_(clock), + network_simulation_(std::move(network_simulation)), + receiver_(receiver), + transport_(nullptr), + clock_offset_ms_(0), + dropped_packets_(0), + sent_packets_(0), + total_packet_delay_us_(0), + next_process_time_us_(clock_->TimeInMicroseconds()), + last_log_time_us_(clock_->TimeInMicroseconds()) {} + +FakeNetworkPipe::FakeNetworkPipe( + Clock* clock, + std::unique_ptr network_simulation, + Transport* transport) + : clock_(clock), + network_simulation_(std::move(network_simulation)), + receiver_(nullptr), + transport_(transport), + clock_offset_ms_(0), + dropped_packets_(0), + sent_packets_(0), + total_packet_delay_us_(0), + next_process_time_us_(clock_->TimeInMicroseconds()), + last_log_time_us_(clock_->TimeInMicroseconds()) {} + FakeNetworkPipe::~FakeNetworkPipe() = default; void FakeNetworkPipe::SetReceiver(PacketReceiver* receiver) { diff --git a/call/fake_network_pipe.h b/call/fake_network_pipe.h index ea8da42640..1f660b8063 100644 --- a/call/fake_network_pipe.h +++ b/call/fake_network_pipe.h @@ -103,31 +103,54 @@ class FakeNetworkPipe : public Transport, public PacketReceiver, public Module { public: using Config = NetworkSimulationInterface::SimulatedNetworkConfig; + // Deprecated. DO NOT USE. To be removed. Use corresponding version with + // NetworkSimulationInterface instance instead. // Use these constructors if you plan to insert packets using DeliverPacket(). FakeNetworkPipe(Clock* clock, const FakeNetworkPipe::Config& config); // Will keep |network_simulation| alive while pipe is alive itself. + // Use these constructors if you plan to insert packets using DeliverPacket(). FakeNetworkPipe( Clock* clock, std::unique_ptr network_simulation); + // Deprecated. DO NOT USE. To be removed. Use corresponding version with + // NetworkSimulationInterface instance instead. FakeNetworkPipe(Clock* clock, const FakeNetworkPipe::Config& config, PacketReceiver* receiver); + FakeNetworkPipe( + Clock* clock, + std::unique_ptr network_simulation, + PacketReceiver* receiver); + // Deprecated. DO NOT USE. To be removed. Use corresponding version with + // NetworkSimulationInterface instance instead. FakeNetworkPipe(Clock* clock, const FakeNetworkPipe::Config& config, PacketReceiver* receiver, uint64_t seed); + FakeNetworkPipe( + Clock* clock, + std::unique_ptr network_simulation, + PacketReceiver* receiver, + uint64_t seed); + // Deprecated. DO NOT USE. To be removed. Use corresponding version with + // NetworkSimulationInterface instance instead. // Use this constructor if you plan to insert packets using SendRt[c?]p(). FakeNetworkPipe(Clock* clock, const FakeNetworkPipe::Config& config, Transport* transport); + // Use this constructor if you plan to insert packets using SendRt[c?]p(). + FakeNetworkPipe( + Clock* clock, + std::unique_ptr network_simulation, + Transport* transport); ~FakeNetworkPipe() override; void SetClockOffset(int64_t offset_ms); - // DO NOT USE. Hold direct reference on NetworkSimulationInterface instead - // and call SetConfig on that object directly. Will be removed soon. + // Deprecated. DO NOT USE. Hold direct reference on NetworkSimulationInterface + // instead and call SetConfig on that object directly. Will be removed soon. // Sets a new configuration. This won't affect packets already in the pipe. void SetConfig(const FakeNetworkPipe::Config& config); diff --git a/call/test/fake_network_pipe_unittest.cc b/call/test/fake_network_pipe_unittest.cc index 284d18c9cd..0578f33191 100644 --- a/call/test/fake_network_pipe_unittest.cc +++ b/call/test/fake_network_pipe_unittest.cc @@ -208,8 +208,7 @@ TEST_F(FakeNetworkPipeTest, ChangingCapacityWithEmptyPipeTest) { std::unique_ptr network(new SimulatedNetwork(config)); SimulatedNetwork* simulated_network = network.get(); std::unique_ptr pipe( - new FakeNetworkPipe(&fake_clock_, std::move(network))); - pipe->SetReceiver(&receiver); + new FakeNetworkPipe(&fake_clock_, std::move(network), &receiver)); // Add 10 packets of 1000 bytes, = 80 kb, and verify it takes one second to // get through the pipe. @@ -270,8 +269,7 @@ TEST_F(FakeNetworkPipeTest, ChangingCapacityWithPacketsInPipeTest) { std::unique_ptr network(new SimulatedNetwork(config)); SimulatedNetwork* simulated_network = network.get(); std::unique_ptr pipe( - new FakeNetworkPipe(&fake_clock_, std::move(network))); - pipe->SetReceiver(&receiver); + new FakeNetworkPipe(&fake_clock_, std::move(network), &receiver)); // Add 10 packets of 1000 bytes, = 80 kb. const int kNumPackets = 10; @@ -328,8 +326,7 @@ TEST_F(FakeNetworkPipeTest, DisallowReorderingThenAllowReordering) { std::unique_ptr network(new SimulatedNetwork(config)); SimulatedNetwork* simulated_network = network.get(); std::unique_ptr pipe( - new FakeNetworkPipe(&fake_clock_, std::move(network))); - pipe->SetReceiver(&receiver); + new FakeNetworkPipe(&fake_clock_, std::move(network), &receiver)); const uint32_t kNumPackets = 100; const int kPacketSize = 10;