2018-09-27 13:47:01 +02:00
|
|
|
/*
|
|
|
|
|
* Copyright 2018 The WebRTC project authors. All Rights Reserved.
|
|
|
|
|
*
|
|
|
|
|
* Use of this source code is governed by a BSD-style license
|
|
|
|
|
* that can be found in the LICENSE file in the root of the source
|
|
|
|
|
* tree. An additional intellectual property rights grant can be found
|
|
|
|
|
* in the file PATENTS. All contributing project authors may
|
|
|
|
|
* be found in the AUTHORS file in the root of the source tree.
|
|
|
|
|
*/
|
|
|
|
|
#ifndef TEST_SCENARIO_NETWORK_NODE_H_
|
|
|
|
|
#define TEST_SCENARIO_NETWORK_NODE_H_
|
|
|
|
|
|
|
|
|
|
#include <deque>
|
|
|
|
|
#include <map>
|
|
|
|
|
#include <memory>
|
|
|
|
|
#include <utility>
|
|
|
|
|
#include <vector>
|
|
|
|
|
|
|
|
|
|
#include "api/call/transport.h"
|
|
|
|
|
#include "api/units/timestamp.h"
|
2018-10-22 11:49:03 +02:00
|
|
|
#include "call/call.h"
|
2018-09-27 13:47:01 +02:00
|
|
|
#include "call/simulated_network.h"
|
2019-01-11 09:11:00 -08:00
|
|
|
#include "rtc_base/constructor_magic.h"
|
|
|
|
|
#include "rtc_base/copy_on_write_buffer.h"
|
2019-04-01 14:33:53 +02:00
|
|
|
#include "rtc_base/task_queue.h"
|
2018-09-27 13:47:01 +02:00
|
|
|
#include "test/scenario/column_printer.h"
|
2019-01-04 15:45:01 +01:00
|
|
|
#include "test/scenario/network/network_emulation.h"
|
2018-09-27 13:47:01 +02:00
|
|
|
#include "test/scenario/scenario_config.h"
|
|
|
|
|
|
|
|
|
|
namespace webrtc {
|
|
|
|
|
namespace test {
|
|
|
|
|
|
2019-01-04 15:45:01 +01:00
|
|
|
class NullReceiver : public EmulatedNetworkReceiverInterface {
|
2018-09-27 13:47:01 +02:00
|
|
|
public:
|
2019-01-04 15:45:01 +01:00
|
|
|
void OnPacketReceived(EmulatedIpPacket packet) override;
|
2018-09-27 13:47:01 +02:00
|
|
|
};
|
2019-01-04 15:45:01 +01:00
|
|
|
class ActionReceiver : public EmulatedNetworkReceiverInterface {
|
2018-09-27 13:47:01 +02:00
|
|
|
public:
|
|
|
|
|
explicit ActionReceiver(std::function<void()> action);
|
|
|
|
|
virtual ~ActionReceiver() = default;
|
2019-01-04 15:45:01 +01:00
|
|
|
|
|
|
|
|
void OnPacketReceived(EmulatedIpPacket packet) override;
|
2018-09-27 13:47:01 +02:00
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
std::function<void()> action_;
|
|
|
|
|
};
|
|
|
|
|
|
2019-01-08 15:41:45 +01:00
|
|
|
class SimulationNode : public EmulatedNetworkNode {
|
2018-09-27 13:47:01 +02:00
|
|
|
public:
|
2019-04-15 14:42:42 +02:00
|
|
|
void UpdateConfig(std::function<void(NetworkSimulationConfig*)> modifier);
|
2018-09-27 13:47:01 +02:00
|
|
|
void PauseTransmissionUntil(Timestamp until);
|
|
|
|
|
ColumnPrinter ConfigPrinter() const;
|
2019-04-15 14:42:42 +02:00
|
|
|
EmulatedNetworkNode* node() { return this; }
|
2018-09-27 13:47:01 +02:00
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
friend class Scenario;
|
|
|
|
|
|
2019-04-01 14:33:53 +02:00
|
|
|
SimulationNode(Clock* clock,
|
|
|
|
|
rtc::TaskQueue* task_queue,
|
2019-04-15 14:42:42 +02:00
|
|
|
NetworkSimulationConfig config,
|
2018-10-04 14:46:31 +02:00
|
|
|
std::unique_ptr<NetworkBehaviorInterface> behavior,
|
2018-09-27 13:47:01 +02:00
|
|
|
SimulatedNetwork* simulation);
|
2019-04-01 14:33:53 +02:00
|
|
|
static std::unique_ptr<SimulationNode> Create(Clock* clock,
|
|
|
|
|
rtc::TaskQueue* task_queue,
|
2019-04-15 14:42:42 +02:00
|
|
|
NetworkSimulationConfig config);
|
2019-01-08 15:41:45 +01:00
|
|
|
|
2018-09-27 13:47:01 +02:00
|
|
|
SimulatedNetwork* const simulated_network_;
|
2019-04-15 14:42:42 +02:00
|
|
|
NetworkSimulationConfig config_;
|
2018-09-27 13:47:01 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
class NetworkNodeTransport : public Transport {
|
|
|
|
|
public:
|
2019-01-30 11:28:59 +01:00
|
|
|
NetworkNodeTransport(Clock* sender_clock, Call* sender_call);
|
2018-09-27 13:47:01 +02:00
|
|
|
~NetworkNodeTransport() override;
|
|
|
|
|
|
|
|
|
|
bool SendRtp(const uint8_t* packet,
|
|
|
|
|
size_t length,
|
|
|
|
|
const PacketOptions& options) override;
|
|
|
|
|
bool SendRtcp(const uint8_t* packet, size_t length) override;
|
2018-10-22 11:49:03 +02:00
|
|
|
|
2019-01-08 15:41:45 +01:00
|
|
|
void Connect(EmulatedNetworkNode* send_node,
|
2019-04-01 11:01:16 +02:00
|
|
|
rtc::IPAddress receiver_ip,
|
2018-10-22 11:49:03 +02:00
|
|
|
DataSize packet_overhead);
|
2019-04-01 14:33:53 +02:00
|
|
|
void Disconnect();
|
2018-10-22 11:49:03 +02:00
|
|
|
|
|
|
|
|
DataSize packet_overhead() {
|
|
|
|
|
rtc::CritScope crit(&crit_sect_);
|
|
|
|
|
return packet_overhead_;
|
|
|
|
|
}
|
2018-09-27 13:47:01 +02:00
|
|
|
|
|
|
|
|
private:
|
2018-10-22 11:49:03 +02:00
|
|
|
rtc::CriticalSection crit_sect_;
|
2019-01-30 11:28:59 +01:00
|
|
|
Clock* const sender_clock_;
|
2018-10-22 11:49:03 +02:00
|
|
|
Call* const sender_call_;
|
2019-04-01 11:01:16 +02:00
|
|
|
// Store local address here for consistency with receiver address.
|
|
|
|
|
const rtc::SocketAddress local_address_;
|
2019-01-08 15:41:45 +01:00
|
|
|
EmulatedNetworkNode* send_net_ RTC_GUARDED_BY(crit_sect_) = nullptr;
|
2019-04-01 11:01:16 +02:00
|
|
|
rtc::SocketAddress receiver_address_ RTC_GUARDED_BY(crit_sect_);
|
2018-10-22 11:49:03 +02:00
|
|
|
DataSize packet_overhead_ RTC_GUARDED_BY(crit_sect_) = DataSize::Zero();
|
2019-04-01 14:33:53 +02:00
|
|
|
rtc::NetworkRoute current_network_route_ RTC_GUARDED_BY(crit_sect_);
|
2018-09-27 13:47:01 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
// CrossTrafficSource is created by a Scenario and generates cross traffic. It
|
|
|
|
|
// provides methods to access and print internal state.
|
|
|
|
|
class CrossTrafficSource {
|
|
|
|
|
public:
|
|
|
|
|
DataRate TrafficRate() const;
|
|
|
|
|
ColumnPrinter StatsPrinter();
|
|
|
|
|
~CrossTrafficSource();
|
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
friend class Scenario;
|
2019-01-04 15:45:01 +01:00
|
|
|
CrossTrafficSource(EmulatedNetworkReceiverInterface* target,
|
2019-04-01 11:01:16 +02:00
|
|
|
rtc::IPAddress receiver_ip,
|
2018-09-27 13:47:01 +02:00
|
|
|
CrossTrafficConfig config);
|
|
|
|
|
void Process(Timestamp at_time, TimeDelta delta);
|
|
|
|
|
|
2019-01-04 15:45:01 +01:00
|
|
|
EmulatedNetworkReceiverInterface* const target_;
|
2019-04-01 11:01:16 +02:00
|
|
|
const rtc::SocketAddress receiver_address_;
|
2018-09-27 13:47:01 +02:00
|
|
|
CrossTrafficConfig config_;
|
|
|
|
|
webrtc::Random random_;
|
|
|
|
|
|
|
|
|
|
TimeDelta time_since_update_ = TimeDelta::Zero();
|
|
|
|
|
double intensity_ = 0;
|
|
|
|
|
DataSize pending_size_ = DataSize::Zero();
|
|
|
|
|
};
|
|
|
|
|
} // namespace test
|
|
|
|
|
} // namespace webrtc
|
|
|
|
|
#endif // TEST_SCENARIO_NETWORK_NODE_H_
|