Removes NetworkControllerTester

Replacing NetworkControllerTester usages with SimulatedTimeClient since
they have corresponding functionality.

Bug: webrtc:9510
Change-Id: I4a6a78142a9922e53b862eb8cb71ba9091236346
Reviewed-on: https://webrtc-review.googlesource.com/c/114660
Commit-Queue: Sebastian Jansson <srte@webrtc.org>
Reviewed-by: Christoffer Rodbro <crodbro@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#26048}
This commit is contained in:
Sebastian Jansson 2018-12-18 15:54:01 +01:00 committed by Commit Bot
parent 1c931c4f00
commit 358fba1f9d
8 changed files with 98 additions and 328 deletions

View File

@ -61,18 +61,12 @@ if (rtc_include_tests) {
testonly = true
sources = [
"test/mock_network_control.h",
"test/network_control_tester.cc",
"test/network_control_tester.h",
]
deps = [
":network_control",
"../../rtc_base:checks",
"../../rtc_base:rtc_base_approved",
"../../test:test_support",
"../units:data_rate",
"../units:data_size",
"../units:time_delta",
"../units:timestamp",
"//third_party/abseil-cpp/absl/types:optional",
]
}

View File

@ -1,152 +0,0 @@
/*
* Copyright (c) 2018 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 "api/transport/test/network_control_tester.h"
#include <algorithm>
#include <string>
#include <vector>
#include "absl/types/optional.h"
#include "api/transport/network_control.h"
#include "api/units/data_size.h"
#include "rtc_base/checks.h"
#include "rtc_base/logging.h"
namespace webrtc {
namespace test {
namespace {
void Update(NetworkControlUpdate* target, const NetworkControlUpdate& update) {
if (update.congestion_window) {
RTC_LOG(LS_INFO) << "Received window="
<< ToString(*update.congestion_window);
target->congestion_window = update.congestion_window;
}
if (update.pacer_config) {
RTC_LOG(LS_INFO) << "Received pacing at:"
<< ToString(update.pacer_config->at_time)
<< ": rate=" << ToString(update.pacer_config->data_rate())
<< ", pad=" << ToString(update.pacer_config->pad_rate());
target->pacer_config = update.pacer_config;
}
if (update.target_rate) {
RTC_LOG(LS_INFO)
<< "Received target at:" << ToString(update.target_rate->at_time)
<< ": rate=" << ToString(update.target_rate->target_rate) << ", rtt="
<< ToString(update.target_rate->network_estimate.round_trip_time);
target->target_rate = update.target_rate;
}
for (const auto& probe : update.probe_cluster_configs) {
target->probe_cluster_configs.push_back(probe);
RTC_LOG(LS_INFO) << "Received probe at:" << ToString(probe.at_time)
<< ": target=" << ToString(probe.target_data_rate);
}
}
} // namespace
SentPacket SimpleTargetRateProducer::ProduceNext(
const NetworkControlUpdate& cache,
Timestamp current_time,
TimeDelta time_delta) {
DataRate actual_send_rate =
std::max(cache.target_rate->target_rate, cache.pacer_config->pad_rate());
SentPacket packet;
packet.send_time = current_time;
packet.size = time_delta * actual_send_rate;
return packet;
}
NetworkControllerTester::NetworkControllerTester(
NetworkControllerFactoryInterface* factory,
NetworkControllerConfig initial_config)
: current_time_(Timestamp::seconds(100000)),
packet_sequence_number_(1),
accumulated_buffer_(TimeDelta::Zero()) {
initial_config.constraints.at_time = current_time_;
controller_ = factory->Create(initial_config);
process_interval_ = factory->GetProcessInterval();
ProcessInterval interval_msg;
interval_msg.at_time = current_time_;
Update(&state_, controller_->OnProcessInterval(interval_msg));
}
NetworkControllerTester::~NetworkControllerTester() = default;
void NetworkControllerTester::RunSimulation(TimeDelta duration,
TimeDelta packet_interval,
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) {
bool send_packet = true;
if (state_.congestion_window && state_.congestion_window->IsFinite()) {
DataSize data_in_flight = DataSize::Zero();
for (PacketResult& packet : outstanding_packets_)
data_in_flight += packet.sent_packet.size;
if (data_in_flight > *state_.congestion_window)
send_packet = false;
}
if (send_packet) {
SentPacket sent_packet;
sent_packet = next_packet(state_, current_time_, packet_interval);
sent_packet.sequence_number = packet_sequence_number_++;
sent_packet.data_in_flight = sent_packet.size;
for (PacketResult& packet : outstanding_packets_)
sent_packet.data_in_flight += packet.sent_packet.size;
Update(&state_, controller_->OnSentPacket(sent_packet));
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;
outstanding_packets_.push_back(result);
}
TimeDelta buffer_consumed = std::min(accumulated_buffer_, packet_interval);
accumulated_buffer_ -= buffer_consumed;
if (outstanding_packets_.size() >= 2 &&
current_time_ >=
outstanding_packets_[1].receive_time + propagation_delay) {
TransportPacketsFeedback feedback;
feedback.prior_in_flight = DataSize::Zero();
for (PacketResult& packet : outstanding_packets_)
feedback.prior_in_flight += packet.sent_packet.size;
while (!outstanding_packets_.empty() &&
current_time_ >= outstanding_packets_.front().receive_time +
propagation_delay) {
feedback.packet_feedbacks.push_back(outstanding_packets_.front());
outstanding_packets_.pop_front();
}
feedback.feedback_time =
feedback.packet_feedbacks.back().receive_time + propagation_delay;
feedback.data_in_flight = DataSize::Zero();
for (PacketResult& packet : outstanding_packets_)
feedback.data_in_flight += packet.sent_packet.size;
Update(&state_, controller_->OnTransportPacketsFeedback(feedback));
}
current_time_ += packet_interval;
if (current_time_ - last_process_time > process_interval_) {
ProcessInterval interval_msg;
interval_msg.at_time = current_time_;
Update(&state_, controller_->OnProcessInterval(interval_msg));
}
}
}
} // namespace test
} // namespace webrtc

View File

@ -1,77 +0,0 @@
/*
* Copyright (c) 2018 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 API_TRANSPORT_TEST_NETWORK_CONTROL_TESTER_H_
#define API_TRANSPORT_TEST_NETWORK_CONTROL_TESTER_H_
#include <stdint.h>
#include <deque>
#include <functional>
#include <memory>
#include "api/transport/network_control.h"
#include "api/transport/network_types.h"
#include "api/units/data_rate.h"
#include "api/units/time_delta.h"
#include "api/units/timestamp.h"
namespace webrtc {
namespace test {
// Produces one packet per time delta
class SimpleTargetRateProducer {
public:
static SentPacket ProduceNext(const NetworkControlUpdate& state,
Timestamp current_time,
TimeDelta time_delta);
};
class NetworkControllerTester {
public:
// A PacketProducer is a function that takes a network control state, a
// timestamp representing the expected send time and a time delta of the send
// times (This allows the PacketProducer to be stateless). It returns a
// SentPacket struct with actual send time and packet size.
using PacketProducer = std::function<
SentPacket(const NetworkControlUpdate&, Timestamp, TimeDelta)>;
NetworkControllerTester(NetworkControllerFactoryInterface* factory,
NetworkControllerConfig initial_config);
~NetworkControllerTester();
// Runs the simulations for the given duration, the PacketProducer will be
// called repeatedly based on the given packet interval and the network will
// be simulated using given bandwidth and propagation delay. The simulation
// will call the controller under test with OnSentPacket and
// OnTransportPacketsFeedback.
// Note that OnTransportPacketsFeedback will only be called for
// packets with resulting feedback time within the simulated duration. Packets
// with later feedback time are saved and used in the next call to
// RunSimulation where enough simulated time has passed.
void RunSimulation(TimeDelta duration,
TimeDelta packet_interval,
DataRate actual_bandwidth,
TimeDelta propagation_delay,
PacketProducer next_packet);
NetworkControlUpdate GetState() { return state_; }
private:
std::unique_ptr<NetworkControllerInterface> controller_;
TimeDelta process_interval_ = TimeDelta::PlusInfinity();
Timestamp current_time_;
int64_t packet_sequence_number_;
TimeDelta accumulated_buffer_;
std::deque<PacketResult> outstanding_packets_;
NetworkControlUpdate state_;
};
} // namespace test
} // namespace webrtc
#endif // API_TRANSPORT_TEST_NETWORK_CONTROL_TESTER_H_

View File

@ -157,6 +157,7 @@ if (rtc_include_tests) {
"../../../api/units:timestamp",
"../../../rtc_base:logging",
"../../../test:test_support",
"../../../test/scenario",
]
if (!build_with_chromium && is_clang) {
# Suppress warnings from the Chromium Clang plugin (bugs.webrtc.org/163).

View File

@ -11,11 +11,11 @@
#include <algorithm>
#include <memory>
#include "api/transport/test/network_control_tester.h"
#include "modules/congestion_controller/bbr/bbr_factory.h"
#include "modules/congestion_controller/bbr/bbr_network_controller.h"
#include "test/gmock.h"
#include "test/gtest.h"
#include "test/scenario/scenario.h"
using testing::Field;
using testing::Matcher;
@ -28,7 +28,6 @@ using testing::StrictMock;
using testing::_;
namespace webrtc {
namespace bbr {
namespace test {
namespace {
@ -85,7 +84,7 @@ class BbrNetworkControllerTest : public ::testing::Test {
TEST_F(BbrNetworkControllerTest, SendsConfigurationOnFirstProcess) {
std::unique_ptr<NetworkControllerInterface> controller_;
controller_.reset(new BbrNetworkController(InitialConfig()));
controller_.reset(new bbr::BbrNetworkController(InitialConfig()));
NetworkControlUpdate update =
controller_->OnProcessInterval(InitialProcessInterval());
@ -97,7 +96,7 @@ TEST_F(BbrNetworkControllerTest, SendsConfigurationOnFirstProcess) {
TEST_F(BbrNetworkControllerTest, SendsConfigurationOnNetworkRouteChanged) {
std::unique_ptr<NetworkControllerInterface> controller_;
controller_.reset(new BbrNetworkController(InitialConfig()));
controller_.reset(new bbr::BbrNetworkController(InitialConfig()));
NetworkControlUpdate update =
controller_->OnProcessInterval(InitialProcessInterval());
@ -118,35 +117,49 @@ TEST_F(BbrNetworkControllerTest, SendsConfigurationOnNetworkRouteChanged) {
// Feedbacks which show an increasing delay cause the estimation to be reduced.
TEST_F(BbrNetworkControllerTest, UpdatesTargetSendRate) {
BbrNetworkControllerFactory factory;
webrtc::test::NetworkControllerTester tester(&factory,
InitialConfig(60, 0, 600));
auto packet_producer = &webrtc::test::SimpleTargetRateProducer::ProduceNext;
Scenario s("bbr_unit/updates_rate", false);
SimulatedTimeClientConfig config;
config.transport.cc =
TransportControllerConfig::CongestionController::kInjected;
config.transport.cc_factory = &factory;
config.transport.rates.min_rate = DataRate::kbps(10);
config.transport.rates.max_rate = DataRate::kbps(1500);
config.transport.rates.start_rate = DataRate::kbps(300);
NetworkNodeConfig net_conf;
auto send_net = s.CreateSimulationNode([](NetworkNodeConfig* c) {
c->simulation.bandwidth = DataRate::kbps(500);
c->simulation.delay = TimeDelta::ms(100);
c->simulation.loss_rate = 0.0;
c->update_frequency = TimeDelta::ms(5);
});
auto ret_net = s.CreateSimulationNode([](NetworkNodeConfig* c) {
c->simulation.delay = TimeDelta::ms(100);
c->update_frequency = TimeDelta::ms(5);
});
SimulatedTimeClient* client = s.CreateSimulatedTimeClient(
"send", config, {PacketStreamConfig()}, {send_net}, {ret_net});
tester.RunSimulation(TimeDelta::seconds(5), TimeDelta::ms(10),
DataRate::kbps(300), TimeDelta::ms(100),
packet_producer);
EXPECT_GE(tester.GetState().target_rate->target_rate,
DataRate::kbps(300) * kMinDataRateFactor);
EXPECT_LE(tester.GetState().target_rate->target_rate,
DataRate::kbps(300) * kMaxDataRateFactor);
s.RunFor(TimeDelta::seconds(25));
EXPECT_NEAR(client->target_rate_kbps(), 450, 100);
tester.RunSimulation(TimeDelta::seconds(30), TimeDelta::ms(10),
DataRate::kbps(500), TimeDelta::ms(100),
packet_producer);
EXPECT_GE(tester.GetState().target_rate->target_rate,
DataRate::kbps(500) * kMinDataRateFactor);
EXPECT_LE(tester.GetState().target_rate->target_rate,
DataRate::kbps(500) * kMaxDataRateFactor);
send_net->UpdateConfig([](NetworkNodeConfig* c) {
c->simulation.bandwidth = DataRate::kbps(800);
c->simulation.delay = TimeDelta::ms(100);
});
tester.RunSimulation(TimeDelta::seconds(30), TimeDelta::ms(10),
DataRate::kbps(100), TimeDelta::ms(200),
packet_producer);
EXPECT_GE(tester.GetState().target_rate->target_rate,
DataRate::kbps(100) * kMinDataRateFactor);
EXPECT_LE(tester.GetState().target_rate->target_rate,
DataRate::kbps(100) * kMaxDataRateFactor);
s.RunFor(TimeDelta::seconds(20));
EXPECT_NEAR(client->target_rate_kbps(), 750, 150);
send_net->UpdateConfig([](NetworkNodeConfig* c) {
c->simulation.bandwidth = DataRate::kbps(200);
c->simulation.delay = TimeDelta::ms(200);
});
ret_net->UpdateConfig(
[](NetworkNodeConfig* c) { c->simulation.delay = TimeDelta::ms(200); });
s.RunFor(TimeDelta::seconds(40));
EXPECT_NEAR(client->target_rate_kbps(), 200, 40);
}
} // namespace test
} // namespace bbr
} // namespace webrtc

View File

@ -9,7 +9,6 @@
*/
#include "api/transport/goog_cc_factory.h"
#include "api/transport/test/network_control_tester.h"
#include "logging/rtc_event_log/mock/mock_rtc_event_log.h"
#include "test/field_trial.h"
#include "test/gtest.h"
@ -29,8 +28,8 @@ const uint32_t kInitialBitrateKbps = 60;
const DataRate kInitialBitrate = DataRate::kbps(kInitialBitrateKbps);
const float kDefaultPacingRate = 2.5f;
void UpdatesTargetRateBasedOnLinkCapacity(double loss_rate = 0.0) {
Scenario s("googcc_unit/target_capacity", false);
void UpdatesTargetRateBasedOnLinkCapacity(std::string test_name = "") {
Scenario s("googcc_unit/target_capacity" + test_name, false);
SimulatedTimeClientConfig config;
config.transport.cc =
TransportControllerConfig::CongestionController::kGoogCcFeedback;
@ -38,10 +37,10 @@ void UpdatesTargetRateBasedOnLinkCapacity(double loss_rate = 0.0) {
config.transport.rates.max_rate = DataRate::kbps(1500);
config.transport.rates.start_rate = DataRate::kbps(300);
NetworkNodeConfig net_conf;
auto send_net = s.CreateSimulationNode([loss_rate](NetworkNodeConfig* c) {
auto send_net = s.CreateSimulationNode([](NetworkNodeConfig* c) {
c->simulation.bandwidth = DataRate::kbps(500);
c->simulation.delay = TimeDelta::ms(100);
c->simulation.loss_rate = loss_rate;
c->simulation.loss_rate = 0.0;
c->update_frequency = TimeDelta::ms(5);
});
auto ret_net = s.CreateSimulationNode([](NetworkNodeConfig* c) {
@ -264,31 +263,6 @@ TEST_F(GoogCcNetworkControllerTest, UpdatesDelayBasedEstimate) {
EXPECT_LT(*target_bitrate_, bitrate_before_delay);
}
TEST_F(GoogCcNetworkControllerTest,
FeedbackVersionUpdatesTargetSendRateBasedOnFeedback) {
GoogCcFeedbackNetworkControllerFactory factory(&event_log_);
NetworkControllerTester tester(&factory, InitialConfig(60, 0, 600));
auto packet_producer = &SimpleTargetRateProducer::ProduceNext;
tester.RunSimulation(TimeDelta::seconds(10), TimeDelta::ms(10),
DataRate::kbps(300), TimeDelta::ms(100),
packet_producer);
EXPECT_NEAR(tester.GetState().target_rate->target_rate.kbps<double>(), 300,
50);
tester.RunSimulation(TimeDelta::seconds(10), TimeDelta::ms(10),
DataRate::kbps(500), TimeDelta::ms(100),
packet_producer);
EXPECT_NEAR(tester.GetState().target_rate->target_rate.kbps<double>(), 500,
100);
tester.RunSimulation(TimeDelta::seconds(30), TimeDelta::ms(10),
DataRate::kbps(100), TimeDelta::ms(200),
packet_producer);
EXPECT_NEAR(tester.GetState().target_rate->target_rate.kbps<double>(), 100,
20);
}
TEST_F(GoogCcNetworkControllerTest,
PaddingRateLimitedByCongestionWindowInTrial) {
ScopedFieldTrials trial(
@ -433,7 +407,12 @@ TEST_F(GoogCcNetworkControllerTest,
LossBasedControlUpdatesTargetRateBasedOnLinkCapacity) {
ScopedFieldTrials trial("WebRTC-Bwe-LossBasedControl/Enabled/");
// TODO(srte): Should the behavior be unaffected at low loss rates?
UpdatesTargetRateBasedOnLinkCapacity(/*loss_rate*/ 0.0);
UpdatesTargetRateBasedOnLinkCapacity("_loss_based");
}
TEST_F(GoogCcNetworkControllerTest, DelayBasedRateControlRegressionTest) {
ScopedFieldTrials trial("WebRTC-Bwe-DelayBasedRateController/Enabled/");
UpdatesTargetRateBasedOnLinkCapacity("_delay_based");
}
TEST_F(GoogCcNetworkControllerTest,

View File

@ -126,7 +126,12 @@ if (rtc_include_tests) {
"../../../api/units:timestamp",
"../../../rtc_base:rtc_base_approved",
"../../../test:test_support",
"../../../test/scenario",
"//third_party/abseil-cpp/absl/memory",
]
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" ]
}
}
}

View File

@ -10,9 +10,9 @@
#include <memory>
#include "api/transport/test/network_control_tester.h"
#include "modules/congestion_controller/pcc/pcc_factory.h"
#include "modules/congestion_controller/pcc/pcc_network_controller.h"
#include "test/scenario/scenario.h"
#include "test/gmock.h"
#include "test/gtest.h"
@ -25,7 +25,6 @@ using testing::Le;
using testing::Property;
namespace webrtc {
namespace pcc {
namespace test {
namespace {
@ -64,7 +63,7 @@ ProcessInterval InitialProcessInterval() {
TEST(PccNetworkControllerTest, SendsConfigurationOnFirstProcess) {
std::unique_ptr<NetworkControllerInterface> controller_;
controller_.reset(new PccNetworkController(InitialConfig()));
controller_.reset(new pcc::PccNetworkController(InitialConfig()));
NetworkControlUpdate update =
controller_->OnProcessInterval(InitialProcessInterval());
@ -75,41 +74,49 @@ TEST(PccNetworkControllerTest, SendsConfigurationOnFirstProcess) {
TEST(PccNetworkControllerTest, UpdatesTargetSendRate) {
PccNetworkControllerFactory factory;
webrtc::test::NetworkControllerTester tester(&factory,
InitialConfig(60, 0, 600));
auto packet_producer = &webrtc::test::SimpleTargetRateProducer::ProduceNext;
Scenario s("pcc_unit/updates_rate", false);
SimulatedTimeClientConfig config;
config.transport.cc =
TransportControllerConfig::CongestionController::kInjected;
config.transport.cc_factory = &factory;
config.transport.rates.min_rate = DataRate::kbps(10);
config.transport.rates.max_rate = DataRate::kbps(1500);
config.transport.rates.start_rate = DataRate::kbps(300);
NetworkNodeConfig net_conf;
auto send_net = s.CreateSimulationNode([](NetworkNodeConfig* c) {
c->simulation.bandwidth = DataRate::kbps(500);
c->simulation.delay = TimeDelta::ms(100);
c->simulation.loss_rate = 0.0;
c->update_frequency = TimeDelta::ms(5);
});
auto ret_net = s.CreateSimulationNode([](NetworkNodeConfig* c) {
c->simulation.delay = TimeDelta::ms(100);
c->update_frequency = TimeDelta::ms(5);
});
SimulatedTimeClient* client = s.CreateSimulatedTimeClient(
"send", config, {PacketStreamConfig()}, {send_net}, {ret_net});
tester.RunSimulation(TimeDelta::seconds(10), TimeDelta::ms(10),
DataRate::kbps(300), TimeDelta::ms(100),
packet_producer);
EXPECT_GE(tester.GetState().target_rate->target_rate.kbps(),
300 * kMinDataRateFactor);
EXPECT_LE(tester.GetState().target_rate->target_rate.kbps(),
300 * kMaxDataRateFactor);
s.RunFor(TimeDelta::seconds(25));
EXPECT_NEAR(client->target_rate_kbps(), 450, 100);
tester.RunSimulation(TimeDelta::seconds(30), TimeDelta::ms(10),
DataRate::kbps(500), TimeDelta::ms(100),
packet_producer);
EXPECT_GE(tester.GetState().target_rate->target_rate.kbps(),
500 * kMinDataRateFactor);
EXPECT_LE(tester.GetState().target_rate->target_rate.kbps(),
500 * kMaxDataRateFactor);
send_net->UpdateConfig([](NetworkNodeConfig* c) {
c->simulation.bandwidth = DataRate::kbps(800);
c->simulation.delay = TimeDelta::ms(100);
});
tester.RunSimulation(TimeDelta::seconds(2), TimeDelta::ms(10),
DataRate::kbps(200), TimeDelta::ms(200),
packet_producer);
EXPECT_LE(tester.GetState().target_rate->target_rate.kbps(),
200 * kMaxDataRateFactor);
s.RunFor(TimeDelta::seconds(20));
EXPECT_NEAR(client->target_rate_kbps(), 750, 150);
tester.RunSimulation(TimeDelta::seconds(18), TimeDelta::ms(10),
DataRate::kbps(200), TimeDelta::ms(200),
packet_producer);
EXPECT_GE(tester.GetState().target_rate->target_rate.kbps(),
200 * kMinDataRateFactor);
EXPECT_LE(tester.GetState().target_rate->target_rate.kbps(),
200 * kMaxDataRateFactor);
send_net->UpdateConfig([](NetworkNodeConfig* c) {
c->simulation.bandwidth = DataRate::kbps(200);
c->simulation.delay = TimeDelta::ms(200);
});
ret_net->UpdateConfig(
[](NetworkNodeConfig* c) { c->simulation.delay = TimeDelta::ms(200); });
s.RunFor(TimeDelta::seconds(10));
EXPECT_NEAR(client->target_rate_kbps(), 200, 40);
}
} // namespace test
} // namespace pcc
} // namespace webrtc