Rename EndpointNode into EmulatedEndpoint
This CL is preparation for extraction of public API for network emulation layer. Bug: webrtc:10138 Change-Id: Id59204ea20a103dafce4122c59e51a354836c374 Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/126624 Commit-Queue: Artem Titov <titovartem@webrtc.org> Reviewed-by: Sebastian Jansson <srte@webrtc.org> Cr-Commit-Position: refs/heads/master@{#27050}
This commit is contained in:
parent
2057673c11
commit
aba8dc2a00
@ -29,7 +29,7 @@ namespace test {
|
||||
namespace {
|
||||
|
||||
std::unique_ptr<rtc::NetworkManager> CreateFakeNetworkManager(
|
||||
std::vector<EndpointNode*> endpoints) {
|
||||
std::vector<EmulatedEndpoint*> endpoints) {
|
||||
auto network_manager = absl::make_unique<rtc::FakeNetworkManager>();
|
||||
for (auto* endpoint : endpoints) {
|
||||
network_manager->AddInterface(
|
||||
@ -80,9 +80,9 @@ TEST(PeerConnectionE2EQualityTestSmokeTest, RunWithEmulatedNetwork) {
|
||||
absl::make_unique<SimulatedNetwork>(BuiltInNetworkBehaviorConfig()));
|
||||
EmulatedNetworkNode* bob_node = network_emulation_manager.CreateEmulatedNode(
|
||||
absl::make_unique<SimulatedNetwork>(BuiltInNetworkBehaviorConfig()));
|
||||
EndpointNode* alice_endpoint =
|
||||
EmulatedEndpoint* alice_endpoint =
|
||||
network_emulation_manager.CreateEndpoint(EndpointConfig());
|
||||
EndpointNode* bob_endpoint =
|
||||
EmulatedEndpoint* bob_endpoint =
|
||||
network_emulation_manager.CreateEndpoint(EndpointConfig());
|
||||
network_emulation_manager.CreateRoute(alice_endpoint, {alice_node},
|
||||
bob_endpoint);
|
||||
|
||||
@ -39,7 +39,7 @@ class SocketManager {
|
||||
virtual void WakeUp() = 0;
|
||||
virtual void Unregister(SocketIoProcessor* io_processor) = 0;
|
||||
// Provides endpoints by IP address.
|
||||
virtual EndpointNode* GetEndpointNode(const rtc::IPAddress& ip) = 0;
|
||||
virtual EmulatedEndpoint* GetEndpointNode(const rtc::IPAddress& ip) = 0;
|
||||
};
|
||||
|
||||
// Represents a socket, which will operate with emulated network.
|
||||
@ -50,7 +50,7 @@ class FakeNetworkSocket : public rtc::AsyncSocket,
|
||||
explicit FakeNetworkSocket(SocketManager* scoket_manager);
|
||||
~FakeNetworkSocket() override;
|
||||
|
||||
// Will be invoked by EndpointNode to deliver packets into this socket.
|
||||
// Will be invoked by EmulatedEndpoint to deliver packets into this socket.
|
||||
void OnPacketReceived(EmulatedIpPacket packet) override;
|
||||
// Will fire read event for incoming packets.
|
||||
bool ProcessIo() override;
|
||||
@ -82,7 +82,7 @@ class FakeNetworkSocket : public rtc::AsyncSocket,
|
||||
absl::optional<EmulatedIpPacket> PopFrontPacket();
|
||||
|
||||
SocketManager* const socket_manager_;
|
||||
EndpointNode* endpoint_;
|
||||
EmulatedEndpoint* endpoint_;
|
||||
|
||||
rtc::SocketAddress local_addr_;
|
||||
rtc::SocketAddress remote_addr_;
|
||||
|
||||
@ -17,7 +17,7 @@ namespace test {
|
||||
|
||||
FakeNetworkSocketServer::FakeNetworkSocketServer(
|
||||
Clock* clock,
|
||||
std::vector<EndpointNode*> endpoints)
|
||||
std::vector<EmulatedEndpoint*> endpoints)
|
||||
: clock_(clock),
|
||||
endpoints_(std::move(endpoints)),
|
||||
wakeup_(/*manual_reset=*/false, /*initially_signaled=*/false) {}
|
||||
@ -27,7 +27,7 @@ void FakeNetworkSocketServer::OnMessageQueueDestroyed() {
|
||||
msg_queue_ = nullptr;
|
||||
}
|
||||
|
||||
EndpointNode* FakeNetworkSocketServer::GetEndpointNode(
|
||||
EmulatedEndpoint* FakeNetworkSocketServer::GetEndpointNode(
|
||||
const rtc::IPAddress& ip) {
|
||||
for (auto* endpoint : endpoints_) {
|
||||
rtc::IPAddress peerLocalAddress = endpoint->GetPeerLocalAddress();
|
||||
|
||||
@ -34,10 +34,11 @@ class FakeNetworkSocketServer : public rtc::SocketServer,
|
||||
public sigslot::has_slots<>,
|
||||
public SocketManager {
|
||||
public:
|
||||
FakeNetworkSocketServer(Clock* clock, std::vector<EndpointNode*> endpoints);
|
||||
FakeNetworkSocketServer(Clock* clock,
|
||||
std::vector<EmulatedEndpoint*> endpoints);
|
||||
~FakeNetworkSocketServer() override;
|
||||
|
||||
EndpointNode* GetEndpointNode(const rtc::IPAddress& ip) override;
|
||||
EmulatedEndpoint* GetEndpointNode(const rtc::IPAddress& ip) override;
|
||||
void Unregister(SocketIoProcessor* io_processor) override;
|
||||
void OnMessageQueueDestroyed();
|
||||
|
||||
@ -56,7 +57,7 @@ class FakeNetworkSocketServer : public rtc::SocketServer,
|
||||
Timestamp Now() const;
|
||||
|
||||
Clock* const clock_;
|
||||
const std::vector<EndpointNode*> endpoints_;
|
||||
const std::vector<EmulatedEndpoint*> endpoints_;
|
||||
rtc::Event wakeup_;
|
||||
rtc::MessageQueue* msg_queue_;
|
||||
|
||||
|
||||
@ -129,26 +129,26 @@ void EmulatedNetworkNode::RemoveReceiver(uint64_t dest_endpoint_id) {
|
||||
routing_.erase(dest_endpoint_id);
|
||||
}
|
||||
|
||||
EndpointNode::EndpointNode(uint64_t id, rtc::IPAddress ip, Clock* clock)
|
||||
EmulatedEndpoint::EmulatedEndpoint(uint64_t id, rtc::IPAddress ip, Clock* clock)
|
||||
: id_(id),
|
||||
peer_local_addr_(ip),
|
||||
send_node_(nullptr),
|
||||
clock_(clock),
|
||||
next_port_(kFirstEphemeralPort),
|
||||
connected_endpoint_id_(absl::nullopt) {}
|
||||
EndpointNode::~EndpointNode() = default;
|
||||
EmulatedEndpoint::~EmulatedEndpoint() = default;
|
||||
|
||||
uint64_t EndpointNode::GetId() const {
|
||||
uint64_t EmulatedEndpoint::GetId() const {
|
||||
return id_;
|
||||
}
|
||||
|
||||
void EndpointNode::SetSendNode(EmulatedNetworkNode* send_node) {
|
||||
void EmulatedEndpoint::SetSendNode(EmulatedNetworkNode* send_node) {
|
||||
send_node_ = send_node;
|
||||
}
|
||||
|
||||
void EndpointNode::SendPacket(const rtc::SocketAddress& from,
|
||||
const rtc::SocketAddress& to,
|
||||
rtc::CopyOnWriteBuffer packet) {
|
||||
void EmulatedEndpoint::SendPacket(const rtc::SocketAddress& from,
|
||||
const rtc::SocketAddress& to,
|
||||
rtc::CopyOnWriteBuffer packet) {
|
||||
RTC_CHECK(from.ipaddr() == peer_local_addr_);
|
||||
RTC_CHECK(connected_endpoint_id_);
|
||||
RTC_CHECK(send_node_);
|
||||
@ -157,7 +157,7 @@ void EndpointNode::SendPacket(const rtc::SocketAddress& from,
|
||||
Timestamp::us(clock_->TimeInMicroseconds())));
|
||||
}
|
||||
|
||||
absl::optional<uint16_t> EndpointNode::BindReceiver(
|
||||
absl::optional<uint16_t> EmulatedEndpoint::BindReceiver(
|
||||
uint16_t desired_port,
|
||||
EmulatedNetworkReceiverInterface* receiver) {
|
||||
rtc::CritScope crit(&receiver_lock_);
|
||||
@ -188,7 +188,7 @@ absl::optional<uint16_t> EndpointNode::BindReceiver(
|
||||
return port;
|
||||
}
|
||||
|
||||
uint16_t EndpointNode::NextPort() {
|
||||
uint16_t EmulatedEndpoint::NextPort() {
|
||||
uint16_t out = next_port_;
|
||||
if (next_port_ == std::numeric_limits<uint16_t>::max()) {
|
||||
next_port_ = kFirstEphemeralPort;
|
||||
@ -198,16 +198,16 @@ uint16_t EndpointNode::NextPort() {
|
||||
return out;
|
||||
}
|
||||
|
||||
void EndpointNode::UnbindReceiver(uint16_t port) {
|
||||
void EmulatedEndpoint::UnbindReceiver(uint16_t port) {
|
||||
rtc::CritScope crit(&receiver_lock_);
|
||||
port_to_receiver_.erase(port);
|
||||
}
|
||||
|
||||
rtc::IPAddress EndpointNode::GetPeerLocalAddress() const {
|
||||
rtc::IPAddress EmulatedEndpoint::GetPeerLocalAddress() const {
|
||||
return peer_local_addr_;
|
||||
}
|
||||
|
||||
void EndpointNode::OnPacketReceived(EmulatedIpPacket packet) {
|
||||
void EmulatedEndpoint::OnPacketReceived(EmulatedIpPacket packet) {
|
||||
RTC_CHECK(packet.dest_endpoint_id == id_)
|
||||
<< "Routing error: wrong destination endpoint. Destination id: "
|
||||
<< packet.dest_endpoint_id << "; Receiver id: " << id_;
|
||||
@ -227,11 +227,11 @@ void EndpointNode::OnPacketReceived(EmulatedIpPacket packet) {
|
||||
it->second->OnPacketReceived(std::move(packet));
|
||||
}
|
||||
|
||||
EmulatedNetworkNode* EndpointNode::GetSendNode() const {
|
||||
EmulatedNetworkNode* EmulatedEndpoint::GetSendNode() const {
|
||||
return send_node_;
|
||||
}
|
||||
|
||||
void EndpointNode::SetConnectedEndpointId(uint64_t endpoint_id) {
|
||||
void EmulatedEndpoint::SetConnectedEndpointId(uint64_t endpoint_id) {
|
||||
connected_endpoint_id_ = endpoint_id;
|
||||
}
|
||||
|
||||
|
||||
@ -112,10 +112,10 @@ class EmulatedNetworkNode : public EmulatedNetworkReceiverInterface {
|
||||
// It will be used as sender from socket side to send data to the network and
|
||||
// will act as packet receiver from emulated network side to receive packets
|
||||
// from other EmulatedNetworkNodes.
|
||||
class EndpointNode : public EmulatedNetworkReceiverInterface {
|
||||
class EmulatedEndpoint : public EmulatedNetworkReceiverInterface {
|
||||
public:
|
||||
EndpointNode(uint64_t id, rtc::IPAddress, Clock* clock);
|
||||
~EndpointNode() override;
|
||||
EmulatedEndpoint(uint64_t id, rtc::IPAddress, Clock* clock);
|
||||
~EmulatedEndpoint() override;
|
||||
|
||||
uint64_t GetId() const;
|
||||
|
||||
|
||||
@ -67,7 +67,8 @@ EmulatedNetworkNode* NetworkEmulationManager::CreateEmulatedNode(
|
||||
return out;
|
||||
}
|
||||
|
||||
EndpointNode* NetworkEmulationManager::CreateEndpoint(EndpointConfig config) {
|
||||
EmulatedEndpoint* NetworkEmulationManager::CreateEndpoint(
|
||||
EndpointConfig config) {
|
||||
absl::optional<rtc::IPAddress> ip = config.ip;
|
||||
if (!ip) {
|
||||
switch (config.generated_ip_family) {
|
||||
@ -85,16 +86,16 @@ EndpointNode* NetworkEmulationManager::CreateEndpoint(EndpointConfig config) {
|
||||
|
||||
bool res = used_ip_addresses_.insert(*ip).second;
|
||||
RTC_CHECK(res) << "IP=" << ip->ToString() << " already in use";
|
||||
auto node = absl::make_unique<EndpointNode>(next_node_id_++, *ip, clock_);
|
||||
EndpointNode* out = node.get();
|
||||
auto node = absl::make_unique<EmulatedEndpoint>(next_node_id_++, *ip, clock_);
|
||||
EmulatedEndpoint* out = node.get();
|
||||
endpoints_.push_back(std::move(node));
|
||||
return out;
|
||||
}
|
||||
|
||||
void NetworkEmulationManager::CreateRoute(
|
||||
EndpointNode* from,
|
||||
EmulatedEndpoint* from,
|
||||
std::vector<EmulatedNetworkNode*> via_nodes,
|
||||
EndpointNode* to) {
|
||||
EmulatedEndpoint* to) {
|
||||
// Because endpoint has no send node by default at least one should be
|
||||
// provided here.
|
||||
RTC_CHECK(!via_nodes.empty());
|
||||
@ -110,9 +111,9 @@ void NetworkEmulationManager::CreateRoute(
|
||||
}
|
||||
|
||||
void NetworkEmulationManager::ClearRoute(
|
||||
EndpointNode* from,
|
||||
EmulatedEndpoint* from,
|
||||
std::vector<EmulatedNetworkNode*> via_nodes,
|
||||
EndpointNode* to) {
|
||||
EmulatedEndpoint* to) {
|
||||
// Remove receiver from intermediate nodes.
|
||||
for (auto* node : via_nodes) {
|
||||
node->RemoveReceiver(to->GetId());
|
||||
@ -127,7 +128,7 @@ void NetworkEmulationManager::ClearRoute(
|
||||
TrafficRoute* NetworkEmulationManager::CreateTrafficRoute(
|
||||
std::vector<EmulatedNetworkNode*> via_nodes) {
|
||||
RTC_CHECK(!via_nodes.empty());
|
||||
EndpointNode* endpoint = CreateEndpoint(EndpointConfig());
|
||||
EmulatedEndpoint* endpoint = CreateEndpoint(EndpointConfig());
|
||||
|
||||
// Setup a route via specified nodes.
|
||||
EmulatedNetworkNode* cur_node = via_nodes[0];
|
||||
@ -179,7 +180,7 @@ PulsedPeaksCrossTraffic* NetworkEmulationManager::CreatePulsedPeaksCrossTraffic(
|
||||
}
|
||||
|
||||
rtc::Thread* NetworkEmulationManager::CreateNetworkThread(
|
||||
std::vector<EndpointNode*> endpoints) {
|
||||
std::vector<EmulatedEndpoint*> endpoints) {
|
||||
FakeNetworkSocketServer* socket_server = CreateSocketServer(endpoints);
|
||||
std::unique_ptr<rtc::Thread> network_thread =
|
||||
absl::make_unique<rtc::Thread>(socket_server);
|
||||
@ -192,7 +193,7 @@ rtc::Thread* NetworkEmulationManager::CreateNetworkThread(
|
||||
}
|
||||
|
||||
FakeNetworkSocketServer* NetworkEmulationManager::CreateSocketServer(
|
||||
std::vector<EndpointNode*> endpoints) {
|
||||
std::vector<EmulatedEndpoint*> endpoints) {
|
||||
auto socket_server =
|
||||
absl::make_unique<FakeNetworkSocketServer>(clock_, endpoints);
|
||||
FakeNetworkSocketServer* out = socket_server.get();
|
||||
|
||||
@ -55,14 +55,14 @@ class NetworkEmulationManager {
|
||||
EmulatedNetworkNode* CreateEmulatedNode(
|
||||
std::unique_ptr<NetworkBehaviorInterface> network_behavior);
|
||||
|
||||
EndpointNode* CreateEndpoint(EndpointConfig config);
|
||||
EmulatedEndpoint* CreateEndpoint(EndpointConfig config);
|
||||
|
||||
void CreateRoute(EndpointNode* from,
|
||||
void CreateRoute(EmulatedEndpoint* from,
|
||||
std::vector<EmulatedNetworkNode*> via_nodes,
|
||||
EndpointNode* to);
|
||||
void ClearRoute(EndpointNode* from,
|
||||
EmulatedEndpoint* to);
|
||||
void ClearRoute(EmulatedEndpoint* from,
|
||||
std::vector<EmulatedNetworkNode*> via_nodes,
|
||||
EndpointNode* to);
|
||||
EmulatedEndpoint* to);
|
||||
|
||||
TrafficRoute* CreateTrafficRoute(std::vector<EmulatedNetworkNode*> via_nodes);
|
||||
RandomWalkCrossTraffic* CreateRandomWalkCrossTraffic(
|
||||
@ -72,11 +72,11 @@ class NetworkEmulationManager {
|
||||
TrafficRoute* traffic_route,
|
||||
PulsedPeaksConfig config);
|
||||
|
||||
rtc::Thread* CreateNetworkThread(std::vector<EndpointNode*> endpoints);
|
||||
rtc::Thread* CreateNetworkThread(std::vector<EmulatedEndpoint*> endpoints);
|
||||
|
||||
private:
|
||||
FakeNetworkSocketServer* CreateSocketServer(
|
||||
std::vector<EndpointNode*> endpoints);
|
||||
std::vector<EmulatedEndpoint*> endpoints);
|
||||
absl::optional<rtc::IPAddress> GetNextIPv4Address();
|
||||
void ProcessNetworkPackets();
|
||||
Timestamp Now() const;
|
||||
@ -90,7 +90,7 @@ class NetworkEmulationManager {
|
||||
std::set<rtc::IPAddress> used_ip_addresses_;
|
||||
|
||||
// All objects can be added to the manager only when it is idle.
|
||||
std::vector<std::unique_ptr<EndpointNode>> endpoints_;
|
||||
std::vector<std::unique_ptr<EmulatedEndpoint>> endpoints_;
|
||||
std::vector<std::unique_ptr<EmulatedNetworkNode>> network_nodes_;
|
||||
std::vector<std::unique_ptr<TrafficRoute>> traffic_routes_;
|
||||
std::vector<std::unique_ptr<RandomWalkCrossTraffic>> random_cross_traffics_;
|
||||
|
||||
@ -108,9 +108,10 @@ TEST(NetworkEmulationManagerPCTest, Run) {
|
||||
absl::make_unique<SimulatedNetwork>(BuiltInNetworkBehaviorConfig()));
|
||||
EmulatedNetworkNode* bob_node = network_manager.CreateEmulatedNode(
|
||||
absl::make_unique<SimulatedNetwork>(BuiltInNetworkBehaviorConfig()));
|
||||
EndpointNode* alice_endpoint =
|
||||
EmulatedEndpoint* alice_endpoint =
|
||||
network_manager.CreateEndpoint(EndpointConfig());
|
||||
EmulatedEndpoint* bob_endpoint =
|
||||
network_manager.CreateEndpoint(EndpointConfig());
|
||||
EndpointNode* bob_endpoint = network_manager.CreateEndpoint(EndpointConfig());
|
||||
network_manager.CreateRoute(alice_endpoint, {alice_node}, bob_endpoint);
|
||||
network_manager.CreateRoute(bob_endpoint, {bob_node}, alice_endpoint);
|
||||
|
||||
|
||||
@ -63,7 +63,7 @@ TEST(NetworkEmulationManagerTest, GeneratedIpv4AddressDoesNotCollide) {
|
||||
EndpointConfig config;
|
||||
config.generated_ip_family = EndpointConfig::IpAddressFamily::kIpv4;
|
||||
for (int i = 0; i < 1000; i++) {
|
||||
EndpointNode* endpoint = network_manager.CreateEndpoint(config);
|
||||
EmulatedEndpoint* endpoint = network_manager.CreateEndpoint(config);
|
||||
ASSERT_EQ(endpoint->GetPeerLocalAddress().family(), AF_INET);
|
||||
bool result = ips.insert(endpoint->GetPeerLocalAddress()).second;
|
||||
ASSERT_TRUE(result);
|
||||
@ -76,7 +76,7 @@ TEST(NetworkEmulationManagerTest, GeneratedIpv6AddressDoesNotCollide) {
|
||||
EndpointConfig config;
|
||||
config.generated_ip_family = EndpointConfig::IpAddressFamily::kIpv6;
|
||||
for (int i = 0; i < 1000; i++) {
|
||||
EndpointNode* endpoint = network_manager.CreateEndpoint(config);
|
||||
EmulatedEndpoint* endpoint = network_manager.CreateEndpoint(config);
|
||||
ASSERT_EQ(endpoint->GetPeerLocalAddress().family(), AF_INET6);
|
||||
bool result = ips.insert(endpoint->GetPeerLocalAddress()).second;
|
||||
ASSERT_TRUE(result);
|
||||
@ -90,9 +90,10 @@ TEST(NetworkEmulationManagerTest, Run) {
|
||||
absl::make_unique<SimulatedNetwork>(BuiltInNetworkBehaviorConfig()));
|
||||
EmulatedNetworkNode* bob_node = network_manager.CreateEmulatedNode(
|
||||
absl::make_unique<SimulatedNetwork>(BuiltInNetworkBehaviorConfig()));
|
||||
EndpointNode* alice_endpoint =
|
||||
EmulatedEndpoint* alice_endpoint =
|
||||
network_manager.CreateEndpoint(EndpointConfig());
|
||||
EmulatedEndpoint* bob_endpoint =
|
||||
network_manager.CreateEndpoint(EndpointConfig());
|
||||
EndpointNode* bob_endpoint = network_manager.CreateEndpoint(EndpointConfig());
|
||||
network_manager.CreateRoute(alice_endpoint, {alice_node}, bob_endpoint);
|
||||
network_manager.CreateRoute(bob_endpoint, {bob_node}, alice_endpoint);
|
||||
|
||||
|
||||
@ -28,7 +28,7 @@ class NullReceiver : public EmulatedNetworkReceiverInterface {
|
||||
|
||||
class ActionReceiver : public EmulatedNetworkReceiverInterface {
|
||||
public:
|
||||
ActionReceiver(std::function<void()> action, EndpointNode* endpoint)
|
||||
ActionReceiver(std::function<void()> action, EmulatedEndpoint* endpoint)
|
||||
: action_(action), endpoint_(endpoint) {}
|
||||
~ActionReceiver() override = default;
|
||||
|
||||
@ -46,7 +46,7 @@ class ActionReceiver : public EmulatedNetworkReceiverInterface {
|
||||
std::function<void()> action_;
|
||||
// Endpoint and port will be used to free port in the endpoint after action
|
||||
// will be done.
|
||||
EndpointNode* endpoint_;
|
||||
EmulatedEndpoint* endpoint_;
|
||||
absl::optional<uint16_t> port_ = absl::nullopt;
|
||||
};
|
||||
|
||||
@ -54,7 +54,7 @@ class ActionReceiver : public EmulatedNetworkReceiverInterface {
|
||||
|
||||
TrafficRoute::TrafficRoute(Clock* clock,
|
||||
EmulatedNetworkReceiverInterface* receiver,
|
||||
EndpointNode* endpoint)
|
||||
EmulatedEndpoint* endpoint)
|
||||
: clock_(clock), receiver_(receiver), endpoint_(endpoint) {
|
||||
null_receiver_ = absl::make_unique<NullReceiver>();
|
||||
absl::optional<uint16_t> port =
|
||||
|
||||
@ -27,7 +27,7 @@ class TrafficRoute {
|
||||
public:
|
||||
TrafficRoute(Clock* clock,
|
||||
EmulatedNetworkReceiverInterface* receiver,
|
||||
EndpointNode* endpoint);
|
||||
EmulatedEndpoint* endpoint);
|
||||
~TrafficRoute();
|
||||
|
||||
// Triggers sending of dummy packets with size |packet_size| bytes.
|
||||
@ -42,7 +42,7 @@ class TrafficRoute {
|
||||
|
||||
Clock* const clock_;
|
||||
EmulatedNetworkReceiverInterface* const receiver_;
|
||||
EndpointNode* const endpoint_;
|
||||
EmulatedEndpoint* const endpoint_;
|
||||
|
||||
uint16_t null_receiver_port_;
|
||||
std::unique_ptr<EmulatedNetworkReceiverInterface> null_receiver_;
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user