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;