blob: 1bb34c6b6ccf9a373b05c583705eb68272d87354 [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
17#include "rtc_base/copy_on_write_buffer.h"
18#include "system_wrappers/include/clock.h"
Artem Titov386802e2019-07-05 10:48:17 +020019#include "test/network/network_emulation.h"
Artem Titovd3666b22019-02-11 14:40:17 +010020
21namespace webrtc {
22namespace 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.
26class TrafficRoute {
27 public:
28 TrafficRoute(Clock* clock,
29 EmulatedNetworkReceiverInterface* receiver,
Artem Titovaba8dc22019-03-11 10:08:40 +010030 EmulatedEndpoint* endpoint);
Artem Titovd3666b22019-02-11 14:40:17 +010031 ~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 Titovaba8dc22019-03-11 10:08:40 +010045 EmulatedEndpoint* const endpoint_;
Artem Titovd3666b22019-02-11 14:40:17 +010046
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 Titov386802e2019-07-05 10:48:17 +020055#endif // TEST_NETWORK_TRAFFIC_ROUTE_H_