Patrik Höglund | b6b29e0 | 2018-06-21 16:58:01 +0200 | [diff] [blame] | 1 | /* |
| 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> |
| 16 | #include <deque> |
| 17 | #include <queue> |
| 18 | #include <vector> |
| 19 | |
Danil Chapovalov | 065a52a | 2018-07-09 10:58:54 +0200 | [diff] [blame] | 20 | #include "absl/types/optional.h" |
Patrik Höglund | b6b29e0 | 2018-06-21 16:58:01 +0200 | [diff] [blame] | 21 | #include "rtc_base/criticalsection.h" |
| 22 | #include "rtc_base/random.h" |
| 23 | #include "rtc_base/thread_annotations.h" |
| 24 | |
| 25 | namespace webrtc { |
| 26 | |
| 27 | struct PacketInFlightInfo { |
| 28 | PacketInFlightInfo(size_t size, int64_t send_time_us, uint64_t packet_id) |
| 29 | : size(size), send_time_us(send_time_us), packet_id(packet_id) {} |
| 30 | |
| 31 | size_t size; |
| 32 | int64_t send_time_us; |
| 33 | // Unique identifier for the packet in relation to other packets in flight. |
| 34 | uint64_t packet_id; |
| 35 | }; |
| 36 | |
| 37 | struct PacketDeliveryInfo { |
| 38 | static constexpr int kNotReceived = -1; |
| 39 | PacketDeliveryInfo(PacketInFlightInfo source, int64_t receive_time_us) |
| 40 | : receive_time_us(receive_time_us), packet_id(source.packet_id) {} |
| 41 | int64_t receive_time_us; |
| 42 | uint64_t packet_id; |
| 43 | }; |
| 44 | |
Artem Titov | e9721f2 | 2018-08-16 11:41:44 +0200 | [diff] [blame^] | 45 | // DefaultNetworkSimulationConfig is a default network simulation configuration |
| 46 | // for default network simulation that will be used by WebRTC if no custom |
| 47 | // NetworkSimulationInterface is provided. |
| 48 | struct DefaultNetworkSimulationConfig { |
| 49 | DefaultNetworkSimulationConfig() {} |
| 50 | // Queue length in number of packets. |
| 51 | size_t queue_length_packets = 0; |
| 52 | // Delay in addition to capacity induced delay. |
| 53 | int queue_delay_ms = 0; |
| 54 | // Standard deviation of the extra delay. |
| 55 | int delay_standard_deviation_ms = 0; |
| 56 | // Link capacity in kbps. |
| 57 | int link_capacity_kbps = 0; |
| 58 | // Random packet loss. |
| 59 | int loss_percent = 0; |
| 60 | // If packets are allowed to be reordered. |
| 61 | bool allow_reordering = false; |
| 62 | // The average length of a burst of lost packets. |
| 63 | int avg_burst_loss_length = -1; |
| 64 | }; |
| 65 | |
Patrik Höglund | b6b29e0 | 2018-06-21 16:58:01 +0200 | [diff] [blame] | 66 | class NetworkSimulationInterface { |
| 67 | public: |
Artem Titov | e9721f2 | 2018-08-16 11:41:44 +0200 | [diff] [blame^] | 68 | // DO NOT USE. Use DefaultNetworkSimulationConfig directly. This reference |
| 69 | // should be removed when all users will be switched on direct usage. |
| 70 | using SimulatedNetworkConfig = DefaultNetworkSimulationConfig; |
Patrik Höglund | b6b29e0 | 2018-06-21 16:58:01 +0200 | [diff] [blame] | 71 | |
Artem Titov | 847a9c7 | 2018-08-14 15:44:31 +0200 | [diff] [blame] | 72 | // DO NOT USE. Method added temporary for further refactoring and will be |
| 73 | // removed soon. |
| 74 | // Sets a new configuration. This won't affect packets already in the pipe. |
| 75 | virtual void SetConfig(const SimulatedNetworkConfig& config) = 0; |
| 76 | |
Patrik Höglund | b6b29e0 | 2018-06-21 16:58:01 +0200 | [diff] [blame] | 77 | virtual bool EnqueuePacket(PacketInFlightInfo packet_info) = 0; |
| 78 | // Retrieves all packets that should be delivered by the given receive time. |
| 79 | virtual std::vector<PacketDeliveryInfo> DequeueDeliverablePackets( |
| 80 | int64_t receive_time_us) = 0; |
| 81 | virtual absl::optional<int64_t> NextDeliveryTimeUs() const = 0; |
| 82 | virtual ~NetworkSimulationInterface() = default; |
| 83 | }; |
| 84 | |
| 85 | } // namespace webrtc |
| 86 | |
| 87 | #endif // API_TEST_SIMULATED_NETWORK_H_ |