Skip to content

Commit

Permalink
Introduce network emulated endpoint optional name for better logging
Browse files Browse the repository at this point in the history
Change-Id: Iedce88400c6f1e91c30249fb49c7914723da2a8d
Bug: None
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/203141
Commit-Queue: Artem Titov <[email protected]>
Reviewed-by: Andrey Logvin <[email protected]>
Cr-Commit-Position: refs/heads/master@{#33054}
  • Loading branch information
Artem Titov authored and Commit Bot committed Jan 21, 2021
1 parent e4fd1ba commit d2dd732
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 8 deletions.
2 changes: 2 additions & 0 deletions api/test/network_emulation_manager.h
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
5 changes: 4 additions & 1 deletion test/network/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
2 changes: 2 additions & 0 deletions test/network/cross_traffic_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -50,6 +51,7 @@ struct TrafficCounterFixture {
TaskQueueForTest task_queue_;
EmulatedEndpointImpl endpoint{
/*id=*/1,
absl::nullopt,
rtc::IPAddress(kTestIpAddress),
EmulatedEndpointConfig::StatsGatheringMode::kDefault,
/*is_enabled=*/true,
Expand Down
16 changes: 10 additions & 6 deletions test/network/network_emulation.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -417,13 +418,15 @@ 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,
rtc::AdapterType type,
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),
Expand All @@ -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;

Expand Down Expand Up @@ -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;
}

Expand Down Expand Up @@ -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_);
Expand Down
2 changes: 2 additions & 0 deletions test/network/network_emulation.h
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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_;
Expand Down
2 changes: 1 addition & 1 deletion test/network/network_emulation_manager.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down

0 comments on commit d2dd732

Please sign in to comment.