network_node.h 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  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/synchronization/mutex.h"
  24. #include "rtc_base/task_queue.h"
  25. #include "test/network/network_emulation.h"
  26. #include "test/scenario/column_printer.h"
  27. #include "test/scenario/scenario_config.h"
  28. namespace webrtc {
  29. namespace test {
  30. class SimulationNode {
  31. public:
  32. SimulationNode(NetworkSimulationConfig config,
  33. SimulatedNetwork* behavior,
  34. EmulatedNetworkNode* network_node);
  35. static std::unique_ptr<SimulatedNetwork> CreateBehavior(
  36. NetworkSimulationConfig config);
  37. void UpdateConfig(std::function<void(NetworkSimulationConfig*)> modifier);
  38. void PauseTransmissionUntil(Timestamp until);
  39. ColumnPrinter ConfigPrinter() const;
  40. EmulatedNetworkNode* node() { return network_node_; }
  41. private:
  42. NetworkSimulationConfig config_;
  43. SimulatedNetwork* const simulation_;
  44. EmulatedNetworkNode* const network_node_;
  45. };
  46. class NetworkNodeTransport : public Transport {
  47. public:
  48. NetworkNodeTransport(Clock* sender_clock, Call* sender_call);
  49. ~NetworkNodeTransport() override;
  50. bool SendRtp(const uint8_t* packet,
  51. size_t length,
  52. const PacketOptions& options) override;
  53. bool SendRtcp(const uint8_t* packet, size_t length) override;
  54. void Connect(EmulatedEndpoint* endpoint,
  55. const rtc::SocketAddress& receiver_address,
  56. DataSize packet_overhead);
  57. void Disconnect();
  58. DataSize packet_overhead() {
  59. MutexLock lock(&mutex_);
  60. return packet_overhead_;
  61. }
  62. private:
  63. Mutex mutex_;
  64. Clock* const sender_clock_;
  65. Call* const sender_call_;
  66. EmulatedEndpoint* endpoint_ RTC_GUARDED_BY(mutex_) = nullptr;
  67. rtc::SocketAddress local_address_ RTC_GUARDED_BY(mutex_);
  68. rtc::SocketAddress remote_address_ RTC_GUARDED_BY(mutex_);
  69. DataSize packet_overhead_ RTC_GUARDED_BY(mutex_) = DataSize::Zero();
  70. rtc::NetworkRoute current_network_route_ RTC_GUARDED_BY(mutex_);
  71. };
  72. } // namespace test
  73. } // namespace webrtc
  74. #endif // TEST_SCENARIO_NETWORK_NODE_H_