blob: 9b20c9cbd91c1b1adb05dc3e9a440ab38974d59b [file] [log] [blame]
Patrik Höglundb6b29e02018-06-21 16:58:01 +02001/*
2 * Copyright (c) 2018 The WebRTC project authors. All Rights Reserved.
3 *
4 * Use of this source code is governed by a BSD-style license
5 * that can be found in the LICENSE file in the root of the source
6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree.
9 */
10
11#ifndef API_TEST_SIMULATED_NETWORK_H_
12#define API_TEST_SIMULATED_NETWORK_H_
13
14#include <stddef.h>
15#include <stdint.h>
Jonas Olssona4d87372019-07-05 19:08:33 +020016
Patrik Höglundb6b29e02018-06-21 16:58:01 +020017#include <deque>
18#include <queue>
19#include <vector>
20
Danil Chapovalov065a52a2018-07-09 10:58:54 +020021#include "absl/types/optional.h"
Steve Anton10542f22019-01-11 09:11:00 -080022#include "rtc_base/critical_section.h"
Patrik Höglundb6b29e02018-06-21 16:58:01 +020023#include "rtc_base/random.h"
24#include "rtc_base/thread_annotations.h"
25
26namespace webrtc {
27
28struct PacketInFlightInfo {
29 PacketInFlightInfo(size_t size, int64_t send_time_us, uint64_t packet_id)
30 : size(size), send_time_us(send_time_us), packet_id(packet_id) {}
31
32 size_t size;
33 int64_t send_time_us;
34 // Unique identifier for the packet in relation to other packets in flight.
35 uint64_t packet_id;
36};
37
38struct PacketDeliveryInfo {
39 static constexpr int kNotReceived = -1;
40 PacketDeliveryInfo(PacketInFlightInfo source, int64_t receive_time_us)
41 : receive_time_us(receive_time_us), packet_id(source.packet_id) {}
42 int64_t receive_time_us;
43 uint64_t packet_id;
44};
45
Artem Titov666fb322018-10-08 11:31:09 +020046// BuiltInNetworkBehaviorConfig is a built-in network behavior configuration
47// for built-in network behavior that will be used by WebRTC if no custom
Artem Titov24ee1672018-10-04 13:48:48 +020048// NetworkBehaviorInterface is provided.
Artem Titov666fb322018-10-08 11:31:09 +020049struct BuiltInNetworkBehaviorConfig {
50 BuiltInNetworkBehaviorConfig() {}
Artem Titove9721f22018-08-16 11:41:44 +020051 // Queue length in number of packets.
52 size_t queue_length_packets = 0;
53 // Delay in addition to capacity induced delay.
54 int queue_delay_ms = 0;
55 // Standard deviation of the extra delay.
56 int delay_standard_deviation_ms = 0;
57 // Link capacity in kbps.
58 int link_capacity_kbps = 0;
59 // Random packet loss.
60 int loss_percent = 0;
61 // If packets are allowed to be reordered.
62 bool allow_reordering = false;
63 // The average length of a burst of lost packets.
64 int avg_burst_loss_length = -1;
Sebastian Jansson8c8feb92019-01-29 15:59:17 +010065 // Additional bytes to add to packet size.
66 int packet_overhead = 0;
Sebastian Jansson2b08e312019-02-25 10:24:46 +010067 // Enable CoDel active queue management.
68 bool codel_active_queue_management = false;
Artem Titove9721f22018-08-16 11:41:44 +020069};
70
Artem Titov24ee1672018-10-04 13:48:48 +020071class NetworkBehaviorInterface {
Patrik Höglundb6b29e02018-06-21 16:58:01 +020072 public:
Patrik Höglundb6b29e02018-06-21 16:58:01 +020073 virtual bool EnqueuePacket(PacketInFlightInfo packet_info) = 0;
74 // Retrieves all packets that should be delivered by the given receive time.
75 virtual std::vector<PacketDeliveryInfo> DequeueDeliverablePackets(
76 int64_t receive_time_us) = 0;
Artem Titovc8e202f2018-08-27 14:59:29 +020077 // Returns time in microseconds when caller should call
78 // DequeueDeliverablePackets to get next set of packets to deliver.
Patrik Höglundb6b29e02018-06-21 16:58:01 +020079 virtual absl::optional<int64_t> NextDeliveryTimeUs() const = 0;
Artem Titov24ee1672018-10-04 13:48:48 +020080 virtual ~NetworkBehaviorInterface() = default;
Patrik Höglundb6b29e02018-06-21 16:58:01 +020081};
82
Patrik Höglundb6b29e02018-06-21 16:58:01 +020083} // namespace webrtc
84
85#endif // API_TEST_SIMULATED_NETWORK_H_