Introduce network emulated endpoint optional name for better logging
Change-Id: Iedce88400c6f1e91c30249fb49c7914723da2a8d Bug: None Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/203141 Commit-Queue: Artem Titov <titovartem@webrtc.org> Reviewed-by: Andrey Logvin <landrey@webrtc.org> Cr-Commit-Position: refs/heads/master@{#33054}
This commit is contained in:
parent
e4fd1ba319
commit
d2dd732d83
@ -56,6 +56,8 @@ struct EmulatedEndpointConfig {
|
||||
kDebug
|
||||
};
|
||||
|
||||
// If specified will be used to name endpoint for logging purposes.
|
||||
absl::optional<std::string> 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.
|
||||
|
||||
@ -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) {
|
||||
|
||||
@ -16,6 +16,7 @@
|
||||
#include <vector>
|
||||
|
||||
#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,
|
||||
|
||||
@ -14,6 +14,7 @@
|
||||
#include <limits>
|
||||
#include <memory>
|
||||
|
||||
#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<std::string> 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<uint16_t> 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_);
|
||||
|
||||
@ -484,6 +484,7 @@ class EmulatedEndpointImpl : public EmulatedEndpoint {
|
||||
public:
|
||||
EmulatedEndpointImpl(
|
||||
uint64_t id,
|
||||
absl::optional<std::string> 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_;
|
||||
|
||||
@ -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<EmulatedEndpointImpl>(
|
||||
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));
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user