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_TRAFFIC_ROUTE_H_ |
| 12 | #define TEST_NETWORK_TRAFFIC_ROUTE_H_ |
Artem Titov | d3666b2 | 2019-02-11 14:40:17 +0100 | [diff] [blame] | 13 | |
| 14 | #include <memory> |
| 15 | #include <vector> |
| 16 | |
Andrey Logvin | f9ee0e0 | 2021-01-14 09:50:32 +0000 | [diff] [blame] | 17 | #include "api/test/network_emulation_manager.h" |
Artem Titov | d3666b2 | 2019-02-11 14:40:17 +0100 | [diff] [blame] | 18 | #include "rtc_base/copy_on_write_buffer.h" |
| 19 | #include "system_wrappers/include/clock.h" |
Artem Titov | 386802e | 2019-07-05 10:48:17 +0200 | [diff] [blame] | 20 | #include "test/network/network_emulation.h" |
Artem Titov | d3666b2 | 2019-02-11 14:40:17 +0100 | [diff] [blame] | 21 | |
| 22 | namespace webrtc { |
| 23 | namespace test { |
| 24 | |
| 25 | // Represents the endpoint for cross traffic that is going through the network. |
| 26 | // It can be used to emulate unexpected network load. |
Andrey Logvin | f9ee0e0 | 2021-01-14 09:50:32 +0000 | [diff] [blame] | 27 | class CrossTrafficRouteImpl final : public CrossTrafficRoute { |
Artem Titov | d3666b2 | 2019-02-11 14:40:17 +0100 | [diff] [blame] | 28 | public: |
Andrey Logvin | f9ee0e0 | 2021-01-14 09:50:32 +0000 | [diff] [blame] | 29 | CrossTrafficRouteImpl(Clock* clock, |
| 30 | EmulatedNetworkReceiverInterface* receiver, |
Niels Möller | 376cf38 | 2021-02-26 09:24:51 +0100 | [diff] [blame] | 31 | EmulatedEndpointImpl* endpoint); |
Andrey Logvin | f9ee0e0 | 2021-01-14 09:50:32 +0000 | [diff] [blame] | 32 | ~CrossTrafficRouteImpl(); |
Artem Titov | d3666b2 | 2019-02-11 14:40:17 +0100 | [diff] [blame] | 33 | |
Artem Titov | 1ee563d | 2021-07-27 12:46:29 +0200 | [diff] [blame] | 34 | // Triggers sending of dummy packets with size `packet_size` bytes. |
Andrey Logvin | f9ee0e0 | 2021-01-14 09:50:32 +0000 | [diff] [blame] | 35 | void TriggerPacketBurst(size_t num_packets, size_t packet_size) override; |
Artem Titov | 1ee563d | 2021-07-27 12:46:29 +0200 | [diff] [blame] | 36 | // 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] | 37 | void NetworkDelayedAction(size_t packet_size, |
| 38 | std::function<void()> action) override; |
Artem Titov | d3666b2 | 2019-02-11 14:40:17 +0100 | [diff] [blame] | 39 | |
Andrey Logvin | f9ee0e0 | 2021-01-14 09:50:32 +0000 | [diff] [blame] | 40 | void SendPacket(size_t packet_size) override; |
Artem Titov | d3666b2 | 2019-02-11 14:40:17 +0100 | [diff] [blame] | 41 | |
| 42 | private: |
| 43 | void SendPacket(size_t packet_size, uint16_t dest_port); |
| 44 | |
| 45 | Clock* const clock_; |
| 46 | EmulatedNetworkReceiverInterface* const receiver_; |
Niels Möller | 376cf38 | 2021-02-26 09:24:51 +0100 | [diff] [blame] | 47 | EmulatedEndpointImpl* const endpoint_; |
Artem Titov | d3666b2 | 2019-02-11 14:40:17 +0100 | [diff] [blame] | 48 | |
| 49 | uint16_t null_receiver_port_; |
| 50 | std::unique_ptr<EmulatedNetworkReceiverInterface> null_receiver_; |
| 51 | std::vector<std::unique_ptr<EmulatedNetworkReceiverInterface>> actions_; |
| 52 | }; |
| 53 | |
| 54 | } // namespace test |
| 55 | } // namespace webrtc |
| 56 | |
Artem Titov | 386802e | 2019-07-05 10:48:17 +0200 | [diff] [blame] | 57 | #endif // TEST_NETWORK_TRAFFIC_ROUTE_H_ |