blob: ea8eb35dafd296edc4cf8af43856e0e19168a116 [file] [log] [blame]
Sebastian Jansson98b07e912018-09-27 11:47:011/*
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 09:49:0321#include "call/call.h"
Sebastian Jansson98b07e912018-09-27 11:47:0122#include "call/simulated_network.h"
Steve Anton10542f22019-01-11 17:11:0023#include "rtc_base/constructor_magic.h"
24#include "rtc_base/copy_on_write_buffer.h"
Markus Handella5a4be12020-07-08 14:09:2125#include "rtc_base/synchronization/mutex.h"
Sebastian Jansson4124dab2019-04-01 12:33:5326#include "rtc_base/task_queue.h"
Artem Titov386802e2019-07-05 08:48:1727#include "test/network/network_emulation.h"
Sebastian Jansson98b07e912018-09-27 11:47:0128#include "test/scenario/column_printer.h"
29#include "test/scenario/scenario_config.h"
30
31namespace webrtc {
32namespace test {
33
Sebastian Janssona4c22b92019-04-15 19:10:0034class SimulationNode {
Sebastian Jansson98b07e912018-09-27 11:47:0135 public:
Sebastian Janssona4c22b92019-04-15 19:10:0036 SimulationNode(NetworkSimulationConfig config,
37 SimulatedNetwork* behavior,
38 EmulatedNetworkNode* network_node);
39 static std::unique_ptr<SimulatedNetwork> CreateBehavior(
40 NetworkSimulationConfig config);
Artem Titov40f51152019-01-04 14:45:0141
Sebastian Janssonef86d142019-04-15 12:42:4242 void UpdateConfig(std::function<void(NetworkSimulationConfig*)> modifier);
Sebastian Jansson98b07e912018-09-27 11:47:0143 void PauseTransmissionUntil(Timestamp until);
44 ColumnPrinter ConfigPrinter() const;
Sebastian Janssona4c22b92019-04-15 19:10:0045 EmulatedNetworkNode* node() { return network_node_; }
Sebastian Jansson98b07e912018-09-27 11:47:0146
47 private:
Sebastian Janssonef86d142019-04-15 12:42:4248 NetworkSimulationConfig config_;
Sebastian Janssona4c22b92019-04-15 19:10:0049 SimulatedNetwork* const simulation_;
50 EmulatedNetworkNode* const network_node_;
Sebastian Jansson98b07e912018-09-27 11:47:0151};
52
53class NetworkNodeTransport : public Transport {
54 public:
Sebastian Janssonaa01f272019-01-30 10:28:5955 NetworkNodeTransport(Clock* sender_clock, Call* sender_call);
Sebastian Jansson98b07e912018-09-27 11:47:0156 ~NetworkNodeTransport() override;
57
58 bool SendRtp(const uint8_t* packet,
59 size_t length,
60 const PacketOptions& options) override;
61 bool SendRtcp(const uint8_t* packet, size_t length) override;
Sebastian Jansson800e1212018-10-22 09:49:0362
Sebastian Jansson77bd3852020-01-17 12:05:5463 void Connect(EmulatedEndpoint* endpoint,
64 const rtc::SocketAddress& receiver_address,
Sebastian Jansson800e1212018-10-22 09:49:0365 DataSize packet_overhead);
Sebastian Jansson4124dab2019-04-01 12:33:5366 void Disconnect();
Sebastian Jansson800e1212018-10-22 09:49:0367
68 DataSize packet_overhead() {
Markus Handella5a4be12020-07-08 14:09:2169 MutexLock lock(&mutex_);
Sebastian Jansson800e1212018-10-22 09:49:0370 return packet_overhead_;
71 }
Sebastian Jansson98b07e912018-09-27 11:47:0172
73 private:
Markus Handella5a4be12020-07-08 14:09:2174 Mutex mutex_;
Sebastian Janssonaa01f272019-01-30 10:28:5975 Clock* const sender_clock_;
Sebastian Jansson800e1212018-10-22 09:49:0376 Call* const sender_call_;
Markus Handella5a4be12020-07-08 14:09:2177 EmulatedEndpoint* endpoint_ RTC_GUARDED_BY(mutex_) = nullptr;
78 rtc::SocketAddress local_address_ RTC_GUARDED_BY(mutex_);
79 rtc::SocketAddress remote_address_ RTC_GUARDED_BY(mutex_);
80 DataSize packet_overhead_ RTC_GUARDED_BY(mutex_) = DataSize::Zero();
81 rtc::NetworkRoute current_network_route_ RTC_GUARDED_BY(mutex_);
Sebastian Jansson98b07e912018-09-27 11:47:0182};
Sebastian Jansson98b07e912018-09-27 11:47:0183} // namespace test
84} // namespace webrtc
85#endif // TEST_SCENARIO_NETWORK_NODE_H_