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 | |
| 17 | #include "rtc_base/copy_on_write_buffer.h" |
| 18 | #include "system_wrappers/include/clock.h" |
Artem Titov | 386802e | 2019-07-05 10:48:17 +0200 | [diff] [blame] | 19 | #include "test/network/network_emulation.h" |
Artem Titov | d3666b2 | 2019-02-11 14:40:17 +0100 | [diff] [blame] | 20 | |
| 21 | namespace webrtc { |
| 22 | namespace test { |
| 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 TrafficRoute { |
| 27 | public: |
| 28 | TrafficRoute(Clock* clock, |
| 29 | EmulatedNetworkReceiverInterface* receiver, |
Artem Titov | aba8dc2 | 2019-03-11 10:08:40 +0100 | [diff] [blame] | 30 | EmulatedEndpoint* endpoint); |
Artem Titov | d3666b2 | 2019-02-11 14:40:17 +0100 | [diff] [blame] | 31 | ~TrafficRoute(); |
| 32 | |
| 33 | // Triggers sending of dummy packets with size |packet_size| bytes. |
| 34 | void TriggerPacketBurst(size_t num_packets, size_t packet_size); |
| 35 | // Sends a packet over the nodes and runs |action| when it has been delivered. |
| 36 | void NetworkDelayedAction(size_t packet_size, std::function<void()> action); |
| 37 | |
| 38 | void SendPacket(size_t packet_size); |
| 39 | |
| 40 | private: |
| 41 | void SendPacket(size_t packet_size, uint16_t dest_port); |
| 42 | |
| 43 | Clock* const clock_; |
| 44 | EmulatedNetworkReceiverInterface* const receiver_; |
Artem Titov | aba8dc2 | 2019-03-11 10:08:40 +0100 | [diff] [blame] | 45 | EmulatedEndpoint* const endpoint_; |
Artem Titov | d3666b2 | 2019-02-11 14:40:17 +0100 | [diff] [blame] | 46 | |
| 47 | uint16_t null_receiver_port_; |
| 48 | std::unique_ptr<EmulatedNetworkReceiverInterface> null_receiver_; |
| 49 | std::vector<std::unique_ptr<EmulatedNetworkReceiverInterface>> actions_; |
| 50 | }; |
| 51 | |
| 52 | } // namespace test |
| 53 | } // namespace webrtc |
| 54 | |
Artem Titov | 386802e | 2019-07-05 10:48:17 +0200 | [diff] [blame] | 55 | #endif // TEST_NETWORK_TRAFFIC_ROUTE_H_ |