webrtc_m130/api/transport/test/network_control_tester.h
Yves Gerey 3e70781361 [Cleanup] Add missing #include. Remove useless ones. IWYU part 2.
This is a follow-up to
https://webrtc-review.googlesource.com/c/src/+/106280.
This time the whole code base is covered.
Some files may have not been fixed though, whenever the IWYU tool
was breaking the build.

Bug: webrtc:8311
Change-Id: I2c31f552a87e887d33931d46e87b6208b1e483ef
Reviewed-on: https://webrtc-review.googlesource.com/c/111965
Commit-Queue: Yves Gerey <yvesg@google.com>
Reviewed-by: Karl Wiberg <kwiberg@webrtc.org>
Reviewed-by: Mirko Bonadei <mbonadei@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#25830}
2018-11-28 18:25:07 +00:00

78 lines
2.9 KiB
C++

/*
* 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_