diff --git a/api/test/network_emulation_manager.h b/api/test/network_emulation_manager.h index 4857c872e2..dd4c83549b 100644 --- a/api/test/network_emulation_manager.h +++ b/api/test/network_emulation_manager.h @@ -56,6 +56,8 @@ struct EmulatedEndpointConfig { kDebug }; + // If specified will be used to name endpoint for logging purposes. + absl::optional name = absl::nullopt; IpAddressFamily generated_ip_family = IpAddressFamily::kIpv4; // If specified will be used as IP address for endpoint node. Must be unique // among all created nodes. diff --git a/test/network/BUILD.gn b/test/network/BUILD.gn index 66c178f25f..7fd499236e 100644 --- a/test/network/BUILD.gn +++ b/test/network/BUILD.gn @@ -138,7 +138,10 @@ rtc_library("cross_traffic_unittest") { "../../rtc_base:rtc_event", "../time_controller", ] - absl_deps = [ "//third_party/abseil-cpp/absl/memory" ] + absl_deps = [ + "//third_party/abseil-cpp/absl/memory", + "//third_party/abseil-cpp/absl/types:optional", + ] } if (rtc_include_tests) { diff --git a/test/network/cross_traffic_unittest.cc b/test/network/cross_traffic_unittest.cc index c8191a3d27..ac45e11d5b 100644 --- a/test/network/cross_traffic_unittest.cc +++ b/test/network/cross_traffic_unittest.cc @@ -16,6 +16,7 @@ #include #include "absl/memory/memory.h" +#include "absl/types/optional.h" #include "api/test/network_emulation_manager.h" #include "api/test/simulated_network.h" #include "call/simulated_network.h" @@ -50,6 +51,7 @@ struct TrafficCounterFixture { TaskQueueForTest task_queue_; EmulatedEndpointImpl endpoint{ /*id=*/1, + absl::nullopt, rtc::IPAddress(kTestIpAddress), EmulatedEndpointConfig::StatsGatheringMode::kDefault, /*is_enabled=*/true, diff --git a/test/network/network_emulation.cc b/test/network/network_emulation.cc index bf6c0683d4..ab1c0c448c 100644 --- a/test/network/network_emulation.cc +++ b/test/network/network_emulation.cc @@ -14,6 +14,7 @@ #include #include +#include "absl/types/optional.h" #include "api/numerics/samples_stats_counter.h" #include "api/units/data_size.h" #include "rtc_base/bind.h" @@ -417,6 +418,7 @@ EmulatedNetworkNode::~EmulatedNetworkNode() = default; EmulatedEndpointImpl::EmulatedEndpointImpl( uint64_t id, + absl::optional name, const rtc::IPAddress& ip, EmulatedEndpointConfig::StatsGatheringMode stats_gathering_mode, bool is_enabled, @@ -424,6 +426,7 @@ EmulatedEndpointImpl::EmulatedEndpointImpl( rtc::TaskQueue* task_queue, Clock* clock) : id_(id), + log_name_(ip.ToString() + " (" + name.value_or("") + ")"), peer_local_addr_(ip), stats_gathering_mode_(stats_gathering_mode), is_enabled_(is_enabled), @@ -449,6 +452,7 @@ EmulatedEndpointImpl::EmulatedEndpointImpl( network_->AddIP(ip); enabled_state_checker_.Detach(); + RTC_LOG(INFO) << "Created emulated endpoint " << log_name_ << "; id=" << id_; } EmulatedEndpointImpl::~EmulatedEndpointImpl() = default; @@ -496,15 +500,15 @@ absl::optional EmulatedEndpointImpl::BindReceiver( } } RTC_CHECK(port != 0) << "Can't find free port for receiver in endpoint " - << id_; + << log_name_ << "; id=" << id_; bool result = port_to_receiver_.insert({port, receiver}).second; if (!result) { RTC_LOG(INFO) << "Can't bind receiver to used port " << desired_port - << " in endpoint " << id_; + << " in endpoint " << log_name_ << "; id=" << id_; return absl::nullopt; } - RTC_LOG(INFO) << "New receiver is binded to endpoint " << id_ << " on port " - << port; + RTC_LOG(INFO) << "New receiver is binded to endpoint " << log_name_ + << "; id=" << id_ << " on port " << port; return port; } @@ -542,8 +546,8 @@ void EmulatedEndpointImpl::OnPacketReceived(EmulatedIpPacket packet) { // It can happen, that remote peer closed connection, but there still some // packets, that are going to it. It can happen during peer connection close // process: one peer closed connection, second still sending data. - RTC_LOG(INFO) << "Drop packet: no receiver registered in " << id_ - << " on port " << packet.to.port(); + RTC_LOG(INFO) << "Drop packet: no receiver registered in " << log_name_ + << "; id=" << id_ << " on port " << packet.to.port(); stats_builder_.OnPacketDropped(packet.from.ipaddr(), DataSize::Bytes(packet.ip_packet_size()), stats_gathering_mode_); diff --git a/test/network/network_emulation.h b/test/network/network_emulation.h index c4d79661aa..84872cb017 100644 --- a/test/network/network_emulation.h +++ b/test/network/network_emulation.h @@ -484,6 +484,7 @@ class EmulatedEndpointImpl : public EmulatedEndpoint { public: EmulatedEndpointImpl( uint64_t id, + absl::optional name, const rtc::IPAddress& ip, EmulatedEndpointConfig::StatsGatheringMode stats_gathering_mode, bool is_enabled, @@ -527,6 +528,7 @@ class EmulatedEndpointImpl : public EmulatedEndpoint { rtc::ThreadChecker enabled_state_checker_; const uint64_t id_; + const std::string log_name_; // Peer's local IP address for this endpoint network interface. const rtc::IPAddress peer_local_addr_; const EmulatedEndpointConfig::StatsGatheringMode stats_gathering_mode_; diff --git a/test/network/network_emulation_manager.cc b/test/network/network_emulation_manager.cc index 9ffe9e3aa7..93bcda133e 100644 --- a/test/network/network_emulation_manager.cc +++ b/test/network/network_emulation_manager.cc @@ -106,7 +106,7 @@ 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( - next_node_id_++, *ip, config.stats_gathering_mode, + next_node_id_++, config.name, *ip, config.stats_gathering_mode, config.start_as_enabled, config.type, &task_queue_, clock_); EmulatedEndpoint* out = node.get(); endpoints_.push_back(std::move(node));