2018-06-21 16:58:01 +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.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#ifndef API_TEST_SIMULATED_NETWORK_H_
|
|
|
|
|
#define API_TEST_SIMULATED_NETWORK_H_
|
|
|
|
|
|
|
|
|
|
#include <stddef.h>
|
|
|
|
|
#include <stdint.h>
|
|
|
|
|
#include <deque>
|
|
|
|
|
#include <queue>
|
|
|
|
|
#include <vector>
|
|
|
|
|
|
2018-07-09 10:58:54 +02:00
|
|
|
#include "absl/types/optional.h"
|
2019-01-11 09:11:00 -08:00
|
|
|
#include "rtc_base/critical_section.h"
|
2018-06-21 16:58:01 +02:00
|
|
|
#include "rtc_base/random.h"
|
|
|
|
|
#include "rtc_base/thread_annotations.h"
|
|
|
|
|
|
|
|
|
|
namespace webrtc {
|
|
|
|
|
|
|
|
|
|
struct PacketInFlightInfo {
|
|
|
|
|
PacketInFlightInfo(size_t size, int64_t send_time_us, uint64_t packet_id)
|
|
|
|
|
: size(size), send_time_us(send_time_us), packet_id(packet_id) {}
|
|
|
|
|
|
|
|
|
|
size_t size;
|
|
|
|
|
int64_t send_time_us;
|
|
|
|
|
// Unique identifier for the packet in relation to other packets in flight.
|
|
|
|
|
uint64_t packet_id;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
struct PacketDeliveryInfo {
|
|
|
|
|
static constexpr int kNotReceived = -1;
|
|
|
|
|
PacketDeliveryInfo(PacketInFlightInfo source, int64_t receive_time_us)
|
|
|
|
|
: receive_time_us(receive_time_us), packet_id(source.packet_id) {}
|
|
|
|
|
int64_t receive_time_us;
|
|
|
|
|
uint64_t packet_id;
|
|
|
|
|
};
|
|
|
|
|
|
2018-10-08 11:31:09 +02:00
|
|
|
// BuiltInNetworkBehaviorConfig is a built-in network behavior configuration
|
|
|
|
|
// for built-in network behavior that will be used by WebRTC if no custom
|
2018-10-04 13:48:48 +02:00
|
|
|
// NetworkBehaviorInterface is provided.
|
2018-10-08 11:31:09 +02:00
|
|
|
struct BuiltInNetworkBehaviorConfig {
|
|
|
|
|
BuiltInNetworkBehaviorConfig() {}
|
2018-08-16 11:41:44 +02:00
|
|
|
// Queue length in number of packets.
|
|
|
|
|
size_t queue_length_packets = 0;
|
|
|
|
|
// Delay in addition to capacity induced delay.
|
|
|
|
|
int queue_delay_ms = 0;
|
|
|
|
|
// Standard deviation of the extra delay.
|
|
|
|
|
int delay_standard_deviation_ms = 0;
|
|
|
|
|
// Link capacity in kbps.
|
|
|
|
|
int link_capacity_kbps = 0;
|
|
|
|
|
// Random packet loss.
|
|
|
|
|
int loss_percent = 0;
|
|
|
|
|
// If packets are allowed to be reordered.
|
|
|
|
|
bool allow_reordering = false;
|
|
|
|
|
// The average length of a burst of lost packets.
|
|
|
|
|
int avg_burst_loss_length = -1;
|
2019-01-29 15:59:17 +01:00
|
|
|
// Additional bytes to add to packet size.
|
|
|
|
|
int packet_overhead = 0;
|
2019-02-25 10:24:46 +01:00
|
|
|
// Enable CoDel active queue management.
|
|
|
|
|
bool codel_active_queue_management = false;
|
2018-08-16 11:41:44 +02:00
|
|
|
};
|
|
|
|
|
|
2018-10-04 13:48:48 +02:00
|
|
|
class NetworkBehaviorInterface {
|
2018-06-21 16:58:01 +02:00
|
|
|
public:
|
|
|
|
|
virtual bool EnqueuePacket(PacketInFlightInfo packet_info) = 0;
|
|
|
|
|
// Retrieves all packets that should be delivered by the given receive time.
|
|
|
|
|
virtual std::vector<PacketDeliveryInfo> DequeueDeliverablePackets(
|
|
|
|
|
int64_t receive_time_us) = 0;
|
2018-08-27 14:59:29 +02:00
|
|
|
// Returns time in microseconds when caller should call
|
|
|
|
|
// DequeueDeliverablePackets to get next set of packets to deliver.
|
2018-06-21 16:58:01 +02:00
|
|
|
virtual absl::optional<int64_t> NextDeliveryTimeUs() const = 0;
|
2018-10-04 13:48:48 +02:00
|
|
|
virtual ~NetworkBehaviorInterface() = default;
|
2018-06-21 16:58:01 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
} // namespace webrtc
|
|
|
|
|
|
|
|
|
|
#endif // API_TEST_SIMULATED_NETWORK_H_
|