blob: dbc41a694f1f5a120fcaea98c2149c989151c4d6 [file] [log] [blame]
Artem Titovd3666b22019-02-11 14:40:17 +01001/*
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 Titov386802e2019-07-05 10:48:17 +020011#ifndef TEST_NETWORK_TRAFFIC_ROUTE_H_
12#define TEST_NETWORK_TRAFFIC_ROUTE_H_
Artem Titovd3666b22019-02-11 14:40:17 +010013
14#include <memory>
15#include <vector>
16
Andrey Logvinf9ee0e02021-01-14 09:50:32 +000017#include "api/test/network_emulation_manager.h"
Artem Titovd3666b22019-02-11 14:40:17 +010018#include "rtc_base/copy_on_write_buffer.h"
19#include "system_wrappers/include/clock.h"
Artem Titov386802e2019-07-05 10:48:17 +020020#include "test/network/network_emulation.h"
Artem Titovd3666b22019-02-11 14:40:17 +010021
22namespace webrtc {
23namespace 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 Logvinf9ee0e02021-01-14 09:50:32 +000027class CrossTrafficRouteImpl final : public CrossTrafficRoute {
Artem Titovd3666b22019-02-11 14:40:17 +010028 public:
Andrey Logvinf9ee0e02021-01-14 09:50:32 +000029 CrossTrafficRouteImpl(Clock* clock,
30 EmulatedNetworkReceiverInterface* receiver,
Niels Möller376cf382021-02-26 09:24:51 +010031 EmulatedEndpointImpl* endpoint);
Andrey Logvinf9ee0e02021-01-14 09:50:32 +000032 ~CrossTrafficRouteImpl();
Artem Titovd3666b22019-02-11 14:40:17 +010033
Artem Titov1ee563d2021-07-27 12:46:29 +020034 // Triggers sending of dummy packets with size `packet_size` bytes.
Andrey Logvinf9ee0e02021-01-14 09:50:32 +000035 void TriggerPacketBurst(size_t num_packets, size_t packet_size) override;
Artem Titov1ee563d2021-07-27 12:46:29 +020036 // Sends a packet over the nodes and runs `action` when it has been delivered.
Andrey Logvinf9ee0e02021-01-14 09:50:32 +000037 void NetworkDelayedAction(size_t packet_size,
38 std::function<void()> action) override;
Artem Titovd3666b22019-02-11 14:40:17 +010039
Andrey Logvinf9ee0e02021-01-14 09:50:32 +000040 void SendPacket(size_t packet_size) override;
Artem Titovd3666b22019-02-11 14:40:17 +010041
42 private:
43 void SendPacket(size_t packet_size, uint16_t dest_port);
44
45 Clock* const clock_;
46 EmulatedNetworkReceiverInterface* const receiver_;
Niels Möller376cf382021-02-26 09:24:51 +010047 EmulatedEndpointImpl* const endpoint_;
Artem Titovd3666b22019-02-11 14:40:17 +010048
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 Titov386802e2019-07-05 10:48:17 +020057#endif // TEST_NETWORK_TRAFFIC_ROUTE_H_