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