webrtc/api/transport/test/network_control_tester.h
Danil Chapovalov 0bc58cf876 Replace rtc::Optional with absl::optional in api
This is a no-op change because rtc::Optional is an alias to absl::optional

This CL generated by running script with parameter 'api'
Then undo changes to optional target itself and optional_unittests

find $@ -type f \( -name \*.h -o -name \*.cc \) \
-exec sed -i 's|rtc::Optional|absl::optional|g' {} \+ \
-exec sed -i 's|rtc::nullopt|absl::nullopt|g' {} \+ \
-exec sed -i 's|#include "api/optional.h"|#include "absl/types/optional.h"|' {} \+

find $@ -type f -name BUILD.gn \
-exec sed -r -i 's|"[\./api]*:optional"|"//third_party/abseil-cpp/absl/types:optional"|' {} \+;

git cl format

Bug: webrtc:9078
Change-Id: I44093da213369d6a502e33792c694f620f53b779
Reviewed-on: https://webrtc-review.googlesource.com/84621
Reviewed-by: Karl Wiberg <kwiberg@webrtc.org>
Commit-Queue: Danil Chapovalov <danilchap@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#23707}
2018-06-21 12:50:03 +00:00

73 lines
2.8 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 <deque>
#include <functional>
#include <memory>
#include "absl/types/optional.h"
#include "api/transport/network_control.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_