You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

85 lines
2.7 KiB

​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
  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(EmulatedNetworkNode* send_node,
  54. rtc::IPAddress receiver_ip,
  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. // Store local address here for consistency with receiver address.
  66. const rtc::SocketAddress local_address_;
  67. EmulatedNetworkNode* send_net_ RTC_GUARDED_BY(crit_sect_) = nullptr;
  68. rtc::SocketAddress receiver_address_ RTC_GUARDED_BY(crit_sect_);
  69. DataSize packet_overhead_ RTC_GUARDED_BY(crit_sect_) = DataSize::Zero();
  70. rtc::NetworkRoute current_network_route_ RTC_GUARDED_BY(crit_sect_);
  71. };
  72. } // namespace test
  73. } // namespace webrtc
  74. #endif // TEST_SCENARIO_NETWORK_NODE_H_