network_node.h 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. /*
  2. * Copyright 2018 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_SCENARIO_NETWORK_NODE_H_
  11. #define TEST_SCENARIO_NETWORK_NODE_H_
  12. #include <deque>
  13. #include <map>
  14. #include <memory>
  15. #include <utility>
  16. #include <vector>
  17. #include "api/call/transport.h"
  18. #include "api/units/timestamp.h"
  19. #include "call/call.h"
  20. #include "call/simulated_network.h"
  21. #include "rtc_base/constructor_magic.h"
  22. #include "rtc_base/copy_on_write_buffer.h"
  23. #include "rtc_base/task_queue.h"
  24. #include "test/network/network_emulation.h"
  25. #include "test/scenario/column_printer.h"
  26. #include "test/scenario/scenario_config.h"
  27. namespace webrtc {
  28. namespace test {
  29. class SimulationNode {
  30. public:
  31. SimulationNode(NetworkSimulationConfig config,
  32. SimulatedNetwork* behavior,
  33. EmulatedNetworkNode* network_node);
  34. static std::unique_ptr<SimulatedNetwork> CreateBehavior(
  35. NetworkSimulationConfig config);
  36. void UpdateConfig(std::function<void(NetworkSimulationConfig*)> modifier);
  37. void PauseTransmissionUntil(Timestamp until);
  38. ColumnPrinter ConfigPrinter() const;
  39. EmulatedNetworkNode* node() { return network_node_; }
  40. private:
  41. NetworkSimulationConfig config_;
  42. SimulatedNetwork* const simulation_;
  43. EmulatedNetworkNode* const network_node_;
  44. };
  45. class NetworkNodeTransport : public Transport {
  46. public:
  47. NetworkNodeTransport(Clock* sender_clock, Call* sender_call);
  48. ~NetworkNodeTransport() override;
  49. bool SendRtp(const uint8_t* packet,
  50. size_t length,
  51. const PacketOptions& options) override;
  52. bool SendRtcp(const uint8_t* packet, size_t length) override;
  53. void Connect(EmulatedEndpoint* endpoint,
  54. const rtc::SocketAddress& receiver_address,
  55. DataSize packet_overhead);
  56. void Disconnect();
  57. DataSize packet_overhead() {
  58. rtc::CritScope crit(&crit_sect_);
  59. return packet_overhead_;
  60. }
  61. private:
  62. rtc::CriticalSection crit_sect_;
  63. Clock* const sender_clock_;
  64. Call* const sender_call_;
  65. EmulatedEndpoint* endpoint_ RTC_GUARDED_BY(crit_sect_) = nullptr;
  66. rtc::SocketAddress local_address_ RTC_GUARDED_BY(crit_sect_);
  67. rtc::SocketAddress remote_address_ RTC_GUARDED_BY(crit_sect_);
  68. DataSize packet_overhead_ RTC_GUARDED_BY(crit_sect_) = DataSize::Zero();
  69. rtc::NetworkRoute current_network_route_ RTC_GUARDED_BY(crit_sect_);
  70. };
  71. } // namespace test
  72. } // namespace webrtc
  73. #endif // TEST_SCENARIO_NETWORK_NODE_H_