blob: 737a93c2fd0493aa9f27014a3980f3a24bc1b8ef [file] [log] [blame]
Andrey Logvinf9ee0e02021-01-14 09:50:32 +00001/*
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
20namespace 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.
26class CrossTrafficRoute {
27 public:
28 virtual ~CrossTrafficRoute() = default;
29
Artem Titov0e61fdd2021-07-25 21:50:14 +020030 // Triggers sending of dummy packets with size `packet_size` bytes.
Andrey Logvinf9ee0e02021-01-14 09:50:32 +000031 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 Titov0e61fdd2021-07-25 21:50:14 +020035 // Sends a packet over the nodes and runs `action` when it has been delivered.
Andrey Logvinf9ee0e02021-01-14 09:50:32 +000036 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.
42class 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.
56struct 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.
68struct 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
76struct 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_