Artem Titov | d3666b2 | 2019-02-11 14:40:17 +0100 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2019 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 | |
Artem Titov | 386802e | 2019-07-05 10:48:17 +0200 | [diff] [blame] | 11 | #ifndef TEST_NETWORK_CROSS_TRAFFIC_H_ |
| 12 | #define TEST_NETWORK_CROSS_TRAFFIC_H_ |
Artem Titov | d3666b2 | 2019-02-11 14:40:17 +0100 | [diff] [blame] | 13 | |
Artem Titov | 386802e | 2019-07-05 10:48:17 +0200 | [diff] [blame] | 14 | #include <algorithm> |
| 15 | #include <map> |
Artem Titov | d3666b2 | 2019-02-11 14:40:17 +0100 | [diff] [blame] | 16 | #include <memory> |
| 17 | |
| 18 | #include "api/units/data_rate.h" |
| 19 | #include "api/units/data_size.h" |
| 20 | #include "api/units/time_delta.h" |
| 21 | #include "api/units/timestamp.h" |
| 22 | #include "rtc_base/random.h" |
Sebastian Jansson | f6e6435 | 2019-04-17 18:02:34 +0200 | [diff] [blame] | 23 | #include "rtc_base/synchronization/sequence_checker.h" |
Artem Titov | 386802e | 2019-07-05 10:48:17 +0200 | [diff] [blame] | 24 | #include "test/network/traffic_route.h" |
Artem Titov | d3666b2 | 2019-02-11 14:40:17 +0100 | [diff] [blame] | 25 | #include "test/scenario/column_printer.h" |
Artem Titov | d3666b2 | 2019-02-11 14:40:17 +0100 | [diff] [blame] | 26 | |
| 27 | namespace webrtc { |
| 28 | namespace test { |
| 29 | |
| 30 | struct RandomWalkConfig { |
| 31 | int random_seed = 1; |
| 32 | DataRate peak_rate = DataRate::kbps(100); |
| 33 | DataSize min_packet_size = DataSize::bytes(200); |
| 34 | TimeDelta min_packet_interval = TimeDelta::ms(1); |
| 35 | TimeDelta update_interval = TimeDelta::ms(200); |
| 36 | double variance = 0.6; |
| 37 | double bias = -0.1; |
| 38 | }; |
| 39 | |
| 40 | class RandomWalkCrossTraffic { |
| 41 | public: |
| 42 | RandomWalkCrossTraffic(RandomWalkConfig config, TrafficRoute* traffic_route); |
| 43 | ~RandomWalkCrossTraffic(); |
| 44 | |
| 45 | void Process(Timestamp at_time); |
| 46 | DataRate TrafficRate() const; |
| 47 | ColumnPrinter StatsPrinter(); |
| 48 | |
| 49 | private: |
Sebastian Jansson | f6e6435 | 2019-04-17 18:02:34 +0200 | [diff] [blame] | 50 | SequenceChecker sequence_checker_; |
| 51 | const RandomWalkConfig config_; |
| 52 | TrafficRoute* const traffic_route_ RTC_PT_GUARDED_BY(sequence_checker_); |
| 53 | webrtc::Random random_ RTC_GUARDED_BY(sequence_checker_); |
Artem Titov | d3666b2 | 2019-02-11 14:40:17 +0100 | [diff] [blame] | 54 | |
Sebastian Jansson | f6e6435 | 2019-04-17 18:02:34 +0200 | [diff] [blame] | 55 | Timestamp last_process_time_ RTC_GUARDED_BY(sequence_checker_) = |
| 56 | Timestamp::MinusInfinity(); |
| 57 | Timestamp last_update_time_ RTC_GUARDED_BY(sequence_checker_) = |
| 58 | Timestamp::MinusInfinity(); |
| 59 | Timestamp last_send_time_ RTC_GUARDED_BY(sequence_checker_) = |
| 60 | Timestamp::MinusInfinity(); |
| 61 | double intensity_ RTC_GUARDED_BY(sequence_checker_) = 0; |
| 62 | DataSize pending_size_ RTC_GUARDED_BY(sequence_checker_) = DataSize::Zero(); |
Artem Titov | d3666b2 | 2019-02-11 14:40:17 +0100 | [diff] [blame] | 63 | }; |
| 64 | |
| 65 | struct PulsedPeaksConfig { |
| 66 | DataRate peak_rate = DataRate::kbps(100); |
| 67 | DataSize min_packet_size = DataSize::bytes(200); |
| 68 | TimeDelta min_packet_interval = TimeDelta::ms(1); |
| 69 | TimeDelta send_duration = TimeDelta::ms(100); |
| 70 | TimeDelta hold_duration = TimeDelta::ms(2000); |
| 71 | }; |
| 72 | |
| 73 | class PulsedPeaksCrossTraffic { |
| 74 | public: |
| 75 | PulsedPeaksCrossTraffic(PulsedPeaksConfig config, |
| 76 | TrafficRoute* traffic_route); |
| 77 | ~PulsedPeaksCrossTraffic(); |
| 78 | |
| 79 | void Process(Timestamp at_time); |
| 80 | DataRate TrafficRate() const; |
| 81 | ColumnPrinter StatsPrinter(); |
| 82 | |
| 83 | private: |
Sebastian Jansson | f6e6435 | 2019-04-17 18:02:34 +0200 | [diff] [blame] | 84 | SequenceChecker sequence_checker_; |
| 85 | const PulsedPeaksConfig config_; |
| 86 | TrafficRoute* const traffic_route_ RTC_PT_GUARDED_BY(sequence_checker_); |
Artem Titov | d3666b2 | 2019-02-11 14:40:17 +0100 | [diff] [blame] | 87 | |
Sebastian Jansson | f6e6435 | 2019-04-17 18:02:34 +0200 | [diff] [blame] | 88 | Timestamp last_update_time_ RTC_GUARDED_BY(sequence_checker_) = |
| 89 | Timestamp::MinusInfinity(); |
| 90 | Timestamp last_send_time_ RTC_GUARDED_BY(sequence_checker_) = |
| 91 | Timestamp::MinusInfinity(); |
| 92 | bool sending_ RTC_GUARDED_BY(sequence_checker_) = false; |
Artem Titov | d3666b2 | 2019-02-11 14:40:17 +0100 | [diff] [blame] | 93 | }; |
| 94 | |
Sebastian Jansson | b13ccc5 | 2019-06-07 13:06:00 +0200 | [diff] [blame] | 95 | struct FakeTcpConfig { |
| 96 | DataSize packet_size = DataSize::bytes(1200); |
| 97 | DataSize send_limit = DataSize::PlusInfinity(); |
| 98 | int packet_window; |
| 99 | TimeDelta process_interval = TimeDelta::ms(200); |
| 100 | TimeDelta packet_timeout = TimeDelta::seconds(1); |
| 101 | }; |
| 102 | |
| 103 | class FakeTcpCrossTraffic |
| 104 | : public TwoWayFakeTrafficRoute<int, int>::TrafficHandlerInterface { |
| 105 | public: |
| 106 | FakeTcpCrossTraffic(FakeTcpConfig config, |
| 107 | EmulatedRoute* send_route, |
| 108 | EmulatedRoute* ret_route); |
| 109 | void Process(Timestamp at_time); |
| 110 | void OnRequest(int sequence_number, Timestamp at_time) override; |
| 111 | void OnResponse(int sequence_number, Timestamp at_time) override; |
| 112 | |
| 113 | void HandleLoss(Timestamp at_time); |
| 114 | |
| 115 | void SendPackets(Timestamp at_time); |
| 116 | |
| 117 | private: |
| 118 | const FakeTcpConfig conf_; |
| 119 | TwoWayFakeTrafficRoute<int, int> route_; |
| 120 | |
| 121 | std::map<int, Timestamp> in_flight_; |
| 122 | double cwnd_ = 10; |
| 123 | double ssthresh_ = INFINITY; |
| 124 | bool ack_received_ = false; |
| 125 | int last_acked_seq_num_ = 0; |
| 126 | int next_sequence_number_ = 0; |
| 127 | Timestamp last_reduction_time_ = Timestamp::MinusInfinity(); |
| 128 | TimeDelta last_rtt_ = TimeDelta::Zero(); |
| 129 | DataSize total_sent_ = DataSize::Zero(); |
| 130 | }; |
| 131 | |
Artem Titov | d3666b2 | 2019-02-11 14:40:17 +0100 | [diff] [blame] | 132 | } // namespace test |
| 133 | } // namespace webrtc |
| 134 | |
Artem Titov | 386802e | 2019-07-05 10:48:17 +0200 | [diff] [blame] | 135 | #endif // TEST_NETWORK_CROSS_TRAFFIC_H_ |