From fb4d66be9726b849f8af61cafb09ed96bb993604 Mon Sep 17 00:00:00 2001 From: Sebastian Jansson Date: Fri, 15 Jun 2018 14:16:44 +0200 Subject: [PATCH] Improves buffer time calculation in network control tester. The previous solution caused packet reordering if the bandwidth changed with large buffers. To avoid this, the buffer time is tracked instead. This means the the bandwidth is applied per packet and can't be retroactively changed for packets already handled. Bug: webrtc:8415 Change-Id: Ib6c97ba9b948220e88c79776aa8d96de289dcfb5 Reviewed-on: https://webrtc-review.googlesource.com/83723 Commit-Queue: Sebastian Jansson Reviewed-by: Stefan Holmer Cr-Commit-Position: refs/heads/master@{#23629} --- api/transport/test/network_control_tester.cc | 12 ++++++------ api/transport/test/network_control_tester.h | 2 +- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/api/transport/test/network_control_tester.cc b/api/transport/test/network_control_tester.cc index 0ba53028ef..2edabd0717 100644 --- a/api/transport/test/network_control_tester.cc +++ b/api/transport/test/network_control_tester.cc @@ -63,7 +63,7 @@ NetworkControllerTester::NetworkControllerTester( NetworkControllerConfig initial_config) : current_time_(Timestamp::seconds(100000)), packet_sequence_number_(1), - accumulated_buffer_(DataSize::Zero()) { + accumulated_buffer_(TimeDelta::Zero()) { initial_config.constraints.at_time = current_time_; controller_ = factory->Create(initial_config); process_interval_ = factory->GetProcessInterval(); @@ -79,6 +79,7 @@ void NetworkControllerTester::RunSimulation(TimeDelta duration, DataRate actual_bandwidth, TimeDelta propagation_delay, PacketProducer next_packet) { + RTC_CHECK(actual_bandwidth.bps() > 0); Timestamp start_time = current_time_; Timestamp last_process_time = current_time_; while (current_time_ - start_time < duration) { @@ -100,9 +101,9 @@ void NetworkControllerTester::RunSimulation(TimeDelta duration, sent_packet.data_in_flight += packet.sent_packet->size; Update(&state_, controller_->OnSentPacket(sent_packet)); - accumulated_buffer_ += sent_packet.size; - TimeDelta buffer_delay = accumulated_buffer_ / actual_bandwidth; - TimeDelta total_delay = propagation_delay + buffer_delay; + TimeDelta time_in_flight = sent_packet.size / actual_bandwidth; + accumulated_buffer_ += time_in_flight; + TimeDelta total_delay = propagation_delay + accumulated_buffer_; PacketResult result; result.sent_packet = sent_packet; result.receive_time = sent_packet.send_time + total_delay; @@ -110,8 +111,7 @@ void NetworkControllerTester::RunSimulation(TimeDelta duration, outstanding_packets_.push_back(result); } - DataSize buffer_consumed = - std::min(accumulated_buffer_, packet_interval * actual_bandwidth); + TimeDelta buffer_consumed = std::min(accumulated_buffer_, packet_interval); accumulated_buffer_ -= buffer_consumed; if (outstanding_packets_.size() >= 2 && diff --git a/api/transport/test/network_control_tester.h b/api/transport/test/network_control_tester.h index bb6837a79e..2e9fc02468 100644 --- a/api/transport/test/network_control_tester.h +++ b/api/transport/test/network_control_tester.h @@ -63,7 +63,7 @@ class NetworkControllerTester { TimeDelta process_interval_ = TimeDelta::PlusInfinity(); Timestamp current_time_; int64_t packet_sequence_number_; - DataSize accumulated_buffer_; + TimeDelta accumulated_buffer_; std::deque outstanding_packets_; NetworkControlUpdate state_; };