blob: bab045db92927f0491f11c3225556561b28b96fe [file] [log] [blame]
Sebastian Jansson98b07e92018-09-27 13:47:01 +02001/*
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
13#include <deque>
14#include <map>
15#include <memory>
16#include <utility>
17#include <vector>
18
19#include "api/call/transport.h"
20#include "api/units/timestamp.h"
Sebastian Jansson800e1212018-10-22 11:49:03 +020021#include "call/call.h"
Sebastian Jansson98b07e92018-09-27 13:47:01 +020022#include "call/simulated_network.h"
Steve Anton10542f22019-01-11 09:11:00 -080023#include "rtc_base/constructor_magic.h"
24#include "rtc_base/copy_on_write_buffer.h"
Sebastian Jansson4124dab2019-04-01 14:33:53 +020025#include "rtc_base/task_queue.h"
Artem Titov386802e2019-07-05 10:48:17 +020026#include "test/network/network_emulation.h"
Sebastian Jansson98b07e92018-09-27 13:47:01 +020027#include "test/scenario/column_printer.h"
28#include "test/scenario/scenario_config.h"
29
30namespace webrtc {
31namespace test {
32
Sebastian Janssona4c22b92019-04-15 21:10:00 +020033class SimulationNode {
Sebastian Jansson98b07e92018-09-27 13:47:01 +020034 public:
Sebastian Janssona4c22b92019-04-15 21:10:00 +020035 SimulationNode(NetworkSimulationConfig config,
36 SimulatedNetwork* behavior,
37 EmulatedNetworkNode* network_node);
38 static std::unique_ptr<SimulatedNetwork> CreateBehavior(
39 NetworkSimulationConfig config);
Artem Titov40f51152019-01-04 15:45:01 +010040
Sebastian Janssonef86d142019-04-15 14:42:42 +020041 void UpdateConfig(std::function<void(NetworkSimulationConfig*)> modifier);
Sebastian Jansson98b07e92018-09-27 13:47:01 +020042 void PauseTransmissionUntil(Timestamp until);
43 ColumnPrinter ConfigPrinter() const;
Sebastian Janssona4c22b92019-04-15 21:10:00 +020044 EmulatedNetworkNode* node() { return network_node_; }
Sebastian Jansson98b07e92018-09-27 13:47:01 +020045
46 private:
Sebastian Janssonef86d142019-04-15 14:42:42 +020047 NetworkSimulationConfig config_;
Sebastian Janssona4c22b92019-04-15 21:10:00 +020048 SimulatedNetwork* const simulation_;
49 EmulatedNetworkNode* const network_node_;
Sebastian Jansson98b07e92018-09-27 13:47:01 +020050};
51
52class NetworkNodeTransport : public Transport {
53 public:
Sebastian Janssonaa01f272019-01-30 11:28:59 +010054 NetworkNodeTransport(Clock* sender_clock, Call* sender_call);
Sebastian Jansson98b07e92018-09-27 13:47:01 +020055 ~NetworkNodeTransport() override;
56
57 bool SendRtp(const uint8_t* packet,
58 size_t length,
59 const PacketOptions& options) override;
60 bool SendRtcp(const uint8_t* packet, size_t length) override;
Sebastian Jansson800e1212018-10-22 11:49:03 +020061
Artem Titov37d18482019-01-08 15:41:45 +010062 void Connect(EmulatedNetworkNode* send_node,
Artem Titov4cd433e2019-04-01 11:01:16 +020063 rtc::IPAddress receiver_ip,
Sebastian Jansson800e1212018-10-22 11:49:03 +020064 DataSize packet_overhead);
Sebastian Jansson4124dab2019-04-01 14:33:53 +020065 void Disconnect();
Sebastian Jansson800e1212018-10-22 11:49:03 +020066
67 DataSize packet_overhead() {
68 rtc::CritScope crit(&crit_sect_);
69 return packet_overhead_;
70 }
Sebastian Jansson98b07e92018-09-27 13:47:01 +020071
72 private:
Sebastian Jansson800e1212018-10-22 11:49:03 +020073 rtc::CriticalSection crit_sect_;
Sebastian Janssonaa01f272019-01-30 11:28:59 +010074 Clock* const sender_clock_;
Sebastian Jansson800e1212018-10-22 11:49:03 +020075 Call* const sender_call_;
Artem Titov4cd433e2019-04-01 11:01:16 +020076 // Store local address here for consistency with receiver address.
77 const rtc::SocketAddress local_address_;
Artem Titov37d18482019-01-08 15:41:45 +010078 EmulatedNetworkNode* send_net_ RTC_GUARDED_BY(crit_sect_) = nullptr;
Artem Titov4cd433e2019-04-01 11:01:16 +020079 rtc::SocketAddress receiver_address_ RTC_GUARDED_BY(crit_sect_);
Sebastian Jansson800e1212018-10-22 11:49:03 +020080 DataSize packet_overhead_ RTC_GUARDED_BY(crit_sect_) = DataSize::Zero();
Sebastian Jansson4124dab2019-04-01 14:33:53 +020081 rtc::NetworkRoute current_network_route_ RTC_GUARDED_BY(crit_sect_);
Sebastian Jansson98b07e92018-09-27 13:47:01 +020082};
Sebastian Jansson98b07e92018-09-27 13:47:01 +020083} // namespace test
84} // namespace webrtc
85#endif // TEST_SCENARIO_NETWORK_NODE_H_