Add ability to set custom adapter type on emulated endpoint

Bug: webrtc:10138
Change-Id: I2f53b42a2c377c9c0c9d36b61eb1c6ce96da480a
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/167209
Reviewed-by: Sebastian Jansson <srte@webrtc.org>
Reviewed-by: Karl Wiberg <kwiberg@webrtc.org>
Commit-Queue: Artem Titov <titovartem@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#30371}
This commit is contained in:
Artem Titov 2020-01-23 15:46:45 +01:00 committed by Commit Bot
parent b18c4eb0a9
commit 1e02339ea6
7 changed files with 20 additions and 5 deletions

View File

@ -23,6 +23,7 @@ specific_include_rules = {
"network_emulation_manager\.h": [
"+rtc_base/thread.h",
"+rtc_base/network.h",
"+rtc_base/network_constants.h",
],
"peerconnection_quality_test_fixture\.h": [
"+logging/rtc_event_log/rtc_event_log_factory_interface.h",

View File

@ -17,9 +17,9 @@
#include "api/test/network_emulation/network_emulation_interfaces.h"
#include "api/test/simulated_network.h"
#include "api/test/time_controller.h"
#include "api/units/timestamp.h"
#include "rtc_base/network.h"
#include "rtc_base/network_constants.h"
#include "rtc_base/thread.h"
namespace webrtc {
@ -52,6 +52,8 @@ struct EmulatedEndpointConfig {
// Should endpoint be enabled or not, when it will be created.
// Enabled endpoints will be available for webrtc to send packets.
bool start_as_enabled = true;
// Network type which will be used to represent endpoint to WebRTC.
rtc::AdapterType type = rtc::AdapterType::ADAPTER_TYPE_UNKNOWN;
};

View File

@ -110,6 +110,7 @@ rtc_library("cross_traffic_unittest") {
"../:test_support",
"../../api:simulated_network_api",
"../../call:simulated_network",
"../../rtc_base",
"../../rtc_base:logging",
"../../rtc_base:rtc_event",
"//test/time_controller:time_controller",

View File

@ -20,6 +20,7 @@
#include "call/simulated_network.h"
#include "rtc_base/event.h"
#include "rtc_base/logging.h"
#include "rtc_base/network_constants.h"
#include "test/gmock.h"
#include "test/gtest.h"
#include "test/network/network_emulation_manager.h"
@ -45,8 +46,12 @@ struct TrafficCounterFixture {
SimulatedClock clock{0};
CountingReceiver counter;
TaskQueueForTest task_queue_;
EmulatedEndpointImpl endpoint{/*id=*/1, rtc::IPAddress(kTestIpAddress),
/*is_enabled=*/true, &task_queue_, &clock};
EmulatedEndpointImpl endpoint{/*id=*/1,
rtc::IPAddress(kTestIpAddress),
/*is_enabled=*/true,
/*type=*/rtc::AdapterType::ADAPTER_TYPE_UNKNOWN,
&task_queue_,
&clock};
};
} // namespace

View File

@ -169,11 +169,13 @@ EmulatedNetworkNode::~EmulatedNetworkNode() = default;
EmulatedEndpointImpl::EmulatedEndpointImpl(uint64_t id,
const rtc::IPAddress& ip,
bool is_enabled,
rtc::AdapterType type,
rtc::TaskQueue* task_queue,
Clock* clock)
: id_(id),
peer_local_addr_(ip),
is_enabled_(is_enabled),
type_(type),
clock_(clock),
task_queue_(task_queue),
router_(task_queue_),
@ -190,7 +192,7 @@ EmulatedEndpointImpl::EmulatedEndpointImpl(uint64_t id,
rtc::IPAddress prefix = TruncateIP(ip, prefix_length);
network_ = std::make_unique<rtc::Network>(
ip.ToString(), "Endpoint id=" + std::to_string(id_), prefix,
prefix_length, rtc::AdapterType::ADAPTER_TYPE_UNKNOWN);
prefix_length, type_);
network_->AddIP(ip);
enabled_state_checker_.Detach();

View File

@ -25,6 +25,7 @@
#include "api/units/timestamp.h"
#include "rtc_base/copy_on_write_buffer.h"
#include "rtc_base/network.h"
#include "rtc_base/network_constants.h"
#include "rtc_base/socket_address.h"
#include "rtc_base/task_queue_for_test.h"
#include "rtc_base/task_utils/repeating_task.h"
@ -130,6 +131,7 @@ class EmulatedEndpointImpl : public EmulatedEndpoint {
EmulatedEndpointImpl(uint64_t id,
const rtc::IPAddress& ip,
bool is_enabled,
rtc::AdapterType type,
rtc::TaskQueue* task_queue,
Clock* clock);
~EmulatedEndpointImpl() override;
@ -173,6 +175,7 @@ class EmulatedEndpointImpl : public EmulatedEndpoint {
// Peer's local IP address for this endpoint network interface.
const rtc::IPAddress peer_local_addr_;
bool is_enabled_ RTC_GUARDED_BY(enabled_state_checker_);
const rtc::AdapterType type_;
Clock* const clock_;
rtc::TaskQueue* const task_queue_;
std::unique_ptr<rtc::Network> network_;

View File

@ -98,7 +98,8 @@ EmulatedEndpoint* NetworkEmulationManagerImpl::CreateEndpoint(
bool res = used_ip_addresses_.insert(*ip).second;
RTC_CHECK(res) << "IP=" << ip->ToString() << " already in use";
auto node = std::make_unique<EmulatedEndpointImpl>(
next_node_id_++, *ip, config.start_as_enabled, &task_queue_, clock_);
next_node_id_++, *ip, config.start_as_enabled, config.type, &task_queue_,
clock_);
EmulatedEndpoint* out = node.get();
endpoints_.push_back(std::move(node));
return out;