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 
11 #ifndef TEST_NETWORK_TRAFFIC_ROUTE_H_
12 #define TEST_NETWORK_TRAFFIC_ROUTE_H_
13 
14 #include <memory>
15 #include <vector>
16 
17 #include "rtc_base/copy_on_write_buffer.h"
18 #include "system_wrappers/include/clock.h"
19 #include "test/network/network_emulation.h"
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,
30                EmulatedEndpoint* endpoint);
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_;
45   EmulatedEndpoint* const endpoint_;
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 
55 #endif  // TEST_NETWORK_TRAFFIC_ROUTE_H_
56