Andrey Logvin | f9ee0e0 | 2021-01-14 09:50:32 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2021 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 | #ifndef API_TEST_NETWORK_EMULATION_CROSS_TRAFFIC_H_ |
| 11 | #define API_TEST_NETWORK_EMULATION_CROSS_TRAFFIC_H_ |
| 12 | |
| 13 | #include "api/task_queue/task_queue_base.h" |
| 14 | #include "api/test/network_emulation/network_emulation_interfaces.h" |
| 15 | #include "api/units/data_rate.h" |
| 16 | #include "api/units/data_size.h" |
| 17 | #include "api/units/time_delta.h" |
| 18 | #include "api/units/timestamp.h" |
| 19 | |
| 20 | namespace webrtc { |
| 21 | |
| 22 | // This API is still in development and can be changed without prior notice. |
| 23 | |
| 24 | // Represents the endpoint for cross traffic that is going through the network. |
| 25 | // It can be used to emulate unexpected network load. |
| 26 | class CrossTrafficRoute { |
| 27 | public: |
| 28 | virtual ~CrossTrafficRoute() = default; |
| 29 | |
Artem Titov | 0e61fdd | 2021-07-25 21:50:14 +0200 | [diff] [blame^] | 30 | // Triggers sending of dummy packets with size `packet_size` bytes. |
Andrey Logvin | f9ee0e0 | 2021-01-14 09:50:32 +0000 | [diff] [blame] | 31 | virtual void TriggerPacketBurst(size_t num_packets, size_t packet_size) = 0; |
| 32 | // Sends a packet over the nodes. The content of the packet is unspecified; |
| 33 | // only the size metter for the emulation purposes. |
| 34 | virtual void SendPacket(size_t packet_size) = 0; |
Artem Titov | 0e61fdd | 2021-07-25 21:50:14 +0200 | [diff] [blame^] | 35 | // Sends a packet over the nodes and runs `action` when it has been delivered. |
Andrey Logvin | f9ee0e0 | 2021-01-14 09:50:32 +0000 | [diff] [blame] | 36 | virtual void NetworkDelayedAction(size_t packet_size, |
| 37 | std::function<void()> action) = 0; |
| 38 | }; |
| 39 | |
| 40 | // Describes a way of generating cross traffic on some route. Used by |
| 41 | // NetworkEmulationManager to produce cross traffic during some period of time. |
| 42 | class CrossTrafficGenerator { |
| 43 | public: |
| 44 | virtual ~CrossTrafficGenerator() = default; |
| 45 | |
| 46 | // Time between Process calls. |
| 47 | virtual TimeDelta GetProcessInterval() const = 0; |
| 48 | |
| 49 | // Called periodically by NetworkEmulationManager. Generates traffic on the |
| 50 | // route. |
| 51 | virtual void Process(Timestamp at_time) = 0; |
| 52 | }; |
| 53 | |
| 54 | // Config of a cross traffic generator. Generated traffic rises and falls |
| 55 | // randomly. |
| 56 | struct RandomWalkConfig { |
| 57 | int random_seed = 1; |
| 58 | DataRate peak_rate = DataRate::KilobitsPerSec(100); |
| 59 | DataSize min_packet_size = DataSize::Bytes(200); |
| 60 | TimeDelta min_packet_interval = TimeDelta::Millis(1); |
| 61 | TimeDelta update_interval = TimeDelta::Millis(200); |
| 62 | double variance = 0.6; |
| 63 | double bias = -0.1; |
| 64 | }; |
| 65 | |
| 66 | // Config of a cross traffic generator. Generated traffic has form of periodic |
| 67 | // peaks alternating with periods of silence. |
| 68 | struct PulsedPeaksConfig { |
| 69 | DataRate peak_rate = DataRate::KilobitsPerSec(100); |
| 70 | DataSize min_packet_size = DataSize::Bytes(200); |
| 71 | TimeDelta min_packet_interval = TimeDelta::Millis(1); |
| 72 | TimeDelta send_duration = TimeDelta::Millis(100); |
| 73 | TimeDelta hold_duration = TimeDelta::Millis(2000); |
| 74 | }; |
| 75 | |
| 76 | struct FakeTcpConfig { |
| 77 | DataSize packet_size = DataSize::Bytes(1200); |
| 78 | DataSize send_limit = DataSize::PlusInfinity(); |
| 79 | TimeDelta process_interval = TimeDelta::Millis(200); |
| 80 | TimeDelta packet_timeout = TimeDelta::Seconds(1); |
| 81 | }; |
| 82 | |
| 83 | } // namespace webrtc |
| 84 | |
| 85 | #endif // API_TEST_NETWORK_EMULATION_CROSS_TRAFFIC_H_ |