2018-03-27 11:19:29 +02:00
|
|
|
/*
|
|
|
|
|
* 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.
|
|
|
|
|
*/
|
|
|
|
|
|
2018-05-09 10:33:39 +02:00
|
|
|
#ifndef API_TRANSPORT_TEST_NETWORK_CONTROL_TESTER_H_
|
|
|
|
|
#define API_TRANSPORT_TEST_NETWORK_CONTROL_TESTER_H_
|
2018-03-27 11:19:29 +02:00
|
|
|
|
|
|
|
|
#include <deque>
|
|
|
|
|
#include <functional>
|
|
|
|
|
#include <memory>
|
|
|
|
|
|
2018-06-21 13:32:56 +02:00
|
|
|
#include "absl/types/optional.h"
|
2018-05-09 10:33:39 +02:00
|
|
|
#include "api/transport/network_control.h"
|
2018-03-27 11:19:29 +02:00
|
|
|
|
|
|
|
|
namespace webrtc {
|
|
|
|
|
namespace test {
|
|
|
|
|
|
|
|
|
|
// Produces one packet per time delta
|
|
|
|
|
class SimpleTargetRateProducer {
|
|
|
|
|
public:
|
2018-04-09 13:21:35 +02:00
|
|
|
static SentPacket ProduceNext(const NetworkControlUpdate& state,
|
2018-03-27 11:19:29 +02:00
|
|
|
Timestamp current_time,
|
|
|
|
|
TimeDelta time_delta);
|
|
|
|
|
};
|
|
|
|
|
|
2018-04-06 11:19:50 +02:00
|
|
|
class NetworkControllerTester {
|
2018-03-27 11:19:29 +02:00
|
|
|
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<
|
2018-04-09 13:21:35 +02:00
|
|
|
SentPacket(const NetworkControlUpdate&, Timestamp, TimeDelta)>;
|
2018-04-06 11:19:50 +02:00
|
|
|
NetworkControllerTester(NetworkControllerFactoryInterface* factory,
|
|
|
|
|
NetworkControllerConfig initial_config);
|
|
|
|
|
~NetworkControllerTester();
|
2018-03-27 11:19:29 +02:00
|
|
|
|
|
|
|
|
// 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);
|
2018-04-09 13:21:35 +02:00
|
|
|
NetworkControlUpdate GetState() { return state_; }
|
2018-03-27 11:19:29 +02:00
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
std::unique_ptr<NetworkControllerInterface> controller_;
|
2018-05-04 17:07:16 +02:00
|
|
|
TimeDelta process_interval_ = TimeDelta::PlusInfinity();
|
2018-03-27 11:19:29 +02:00
|
|
|
Timestamp current_time_;
|
2018-05-22 11:03:12 +02:00
|
|
|
int64_t packet_sequence_number_;
|
2018-06-15 14:16:44 +02:00
|
|
|
TimeDelta accumulated_buffer_;
|
2018-03-27 14:01:24 +02:00
|
|
|
std::deque<PacketResult> outstanding_packets_;
|
2018-04-09 13:21:35 +02:00
|
|
|
NetworkControlUpdate state_;
|
2018-03-27 11:19:29 +02:00
|
|
|
};
|
|
|
|
|
} // namespace test
|
|
|
|
|
} // namespace webrtc
|
|
|
|
|
|
2018-05-09 10:33:39 +02:00
|
|
|
#endif // API_TRANSPORT_TEST_NETWORK_CONTROL_TESTER_H_
|