traffic_route.h 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  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. #ifndef TEST_NETWORK_TRAFFIC_ROUTE_H_
  11. #define TEST_NETWORK_TRAFFIC_ROUTE_H_
  12. #include <memory>
  13. #include <vector>
  14. #include "rtc_base/copy_on_write_buffer.h"
  15. #include "system_wrappers/include/clock.h"
  16. #include "test/network/network_emulation.h"
  17. namespace webrtc {
  18. namespace test {
  19. // Represents the endpoint for cross traffic that is going through the network.
  20. // It can be used to emulate unexpected network load.
  21. class TrafficRoute {
  22. public:
  23. TrafficRoute(Clock* clock,
  24. EmulatedNetworkReceiverInterface* receiver,
  25. EmulatedEndpoint* endpoint);
  26. ~TrafficRoute();
  27. // Triggers sending of dummy packets with size |packet_size| bytes.
  28. void TriggerPacketBurst(size_t num_packets, size_t packet_size);
  29. // Sends a packet over the nodes and runs |action| when it has been delivered.
  30. void NetworkDelayedAction(size_t packet_size, std::function<void()> action);
  31. void SendPacket(size_t packet_size);
  32. private:
  33. void SendPacket(size_t packet_size, uint16_t dest_port);
  34. Clock* const clock_;
  35. EmulatedNetworkReceiverInterface* const receiver_;
  36. EmulatedEndpoint* const endpoint_;
  37. uint16_t null_receiver_port_;
  38. std::unique_ptr<EmulatedNetworkReceiverInterface> null_receiver_;
  39. std::vector<std::unique_ptr<EmulatedNetworkReceiverInterface>> actions_;
  40. };
  41. } // namespace test
  42. } // namespace webrtc
  43. #endif // TEST_NETWORK_TRAFFIC_ROUTE_H_