From 8c8feb9d2b10c701e56aa21e1cdaa6c204b1cf2d Mon Sep 17 00:00:00 2001 From: Sebastian Jansson Date: Tue, 29 Jan 2019 15:59:17 +0100 Subject: [PATCH] Moves packet overhead from network nodes to simulation. This simplifies the design by making simulated network more self sufficient. It also prepares for removing network node specific configuration (The behavior implementation should be responsible for handling any configuration.) Bug: webrtc:9510 Change-Id: I218d70c0359774d9891178fbd8b1bbc729cbad92 Reviewed-on: https://webrtc-review.googlesource.com/c/120346 Reviewed-by: Karl Wiberg Commit-Queue: Sebastian Jansson Cr-Commit-Position: refs/heads/master@{#26450} --- api/test/simulated_network.h | 2 ++ call/simulated_network.cc | 1 + test/scenario/network/network_emulation.cc | 10 ++++------ test/scenario/network/network_emulation.h | 6 ++---- test/scenario/network_node.cc | 4 ++-- test/scenario/scenario.cc | 3 +-- 6 files changed, 12 insertions(+), 14 deletions(-) diff --git a/api/test/simulated_network.h b/api/test/simulated_network.h index 404f016550..5961724371 100644 --- a/api/test/simulated_network.h +++ b/api/test/simulated_network.h @@ -61,6 +61,8 @@ struct BuiltInNetworkBehaviorConfig { bool allow_reordering = false; // The average length of a burst of lost packets. int avg_burst_loss_length = -1; + // Additional bytes to add to packet size. + int packet_overhead = 0; }; class NetworkBehaviorInterface { diff --git a/call/simulated_network.cc b/call/simulated_network.cc index 62889a74db..01a74e51f1 100644 --- a/call/simulated_network.cc +++ b/call/simulated_network.cc @@ -66,6 +66,7 @@ bool SimulatedNetwork::EnqueuePacket(PacketInFlightInfo packet) { rtc::CritScope crit(&config_lock_); config = config_; } + packet.size += config.packet_overhead; rtc::CritScope crit(&process_lock_); if (config.queue_length_packets > 0 && capacity_link_.size() >= config.queue_length_packets) { diff --git a/test/scenario/network/network_emulation.cc b/test/scenario/network/network_emulation.cc index 08b8abc801..9ff24e76ea 100644 --- a/test/scenario/network/network_emulation.cc +++ b/test/scenario/network/network_emulation.cc @@ -50,10 +50,8 @@ void EmulatedNetworkNode::ClearRoute(uint64_t receiver_id, } EmulatedNetworkNode::EmulatedNetworkNode( - std::unique_ptr network_behavior, - size_t packet_overhead) - : network_behavior_(std::move(network_behavior)), - packet_overhead_(packet_overhead) {} + std::unique_ptr network_behavior) + : network_behavior_(std::move(network_behavior)) {} EmulatedNetworkNode::~EmulatedNetworkNode() = default; @@ -62,8 +60,8 @@ void EmulatedNetworkNode::OnPacketReceived(EmulatedIpPacket packet) { if (routing_.find(packet.dest_endpoint_id) == routing_.end()) return; uint64_t packet_id = next_packet_id_++; - bool sent = network_behavior_->EnqueuePacket(PacketInFlightInfo( - packet.size() + packet_overhead_, packet.arrival_time.us(), packet_id)); + bool sent = network_behavior_->EnqueuePacket( + PacketInFlightInfo(packet.size(), packet.arrival_time.us(), packet_id)); if (sent) { packets_.emplace_back(StoredPacket{packet_id, std::move(packet), false}); } diff --git a/test/scenario/network/network_emulation.h b/test/scenario/network/network_emulation.h index ec179b0ea6..ba8798484e 100644 --- a/test/scenario/network/network_emulation.h +++ b/test/scenario/network/network_emulation.h @@ -71,9 +71,8 @@ class EmulatedNetworkNode : public EmulatedNetworkReceiverInterface { // Creates node based on |network_behavior|. The specified |packet_overhead| // is added to the size of each packet in the information provided to // |network_behavior|. - EmulatedNetworkNode( - std::unique_ptr network_behavior, - size_t packet_overhead = 0); + explicit EmulatedNetworkNode( + std::unique_ptr network_behavior); ~EmulatedNetworkNode() override; RTC_DISALLOW_COPY_AND_ASSIGN(EmulatedNetworkNode); @@ -103,7 +102,6 @@ class EmulatedNetworkNode : public EmulatedNetworkReceiverInterface { RTC_GUARDED_BY(lock_); const std::unique_ptr network_behavior_ RTC_GUARDED_BY(lock_); - const size_t packet_overhead_ RTC_GUARDED_BY(lock_); std::deque packets_ RTC_GUARDED_BY(lock_); uint64_t next_packet_id_ RTC_GUARDED_BY(lock_) = 1; diff --git a/test/scenario/network_node.cc b/test/scenario/network_node.cc index 2df5ce204d..316a46bff6 100644 --- a/test/scenario/network_node.cc +++ b/test/scenario/network_node.cc @@ -24,6 +24,7 @@ SimulatedNetwork::Config CreateSimulationConfig(NetworkNodeConfig config) { sim_config.loss_percent = config.simulation.loss_rate * 100; sim_config.queue_delay_ms = config.simulation.delay.ms(); sim_config.delay_standard_deviation_ms = config.simulation.delay_std_dev.ms(); + sim_config.packet_overhead = config.packet_overhead.bytes(); return sim_config; } } // namespace @@ -73,8 +74,7 @@ SimulationNode::SimulationNode( NetworkNodeConfig config, std::unique_ptr behavior, SimulatedNetwork* simulation) - : EmulatedNetworkNode(std::move(behavior), - config.packet_overhead.bytes_or(0)), + : EmulatedNetworkNode(std::move(behavior)), simulated_network_(simulation), config_(config) {} diff --git a/test/scenario/scenario.cc b/test/scenario/scenario.cc index 3bce243787..aade8c6a38 100644 --- a/test/scenario/scenario.cc +++ b/test/scenario/scenario.cc @@ -227,8 +227,7 @@ EmulatedNetworkNode* Scenario::CreateNetworkNode( NetworkNodeConfig config, std::unique_ptr behavior) { RTC_DCHECK(config.mode == NetworkNodeConfig::TrafficMode::kCustom); - network_nodes_.emplace_back(new EmulatedNetworkNode( - std::move(behavior), config.packet_overhead.bytes_or(0))); + network_nodes_.emplace_back(new EmulatedNetworkNode(std::move(behavior))); EmulatedNetworkNode* network_node = network_nodes_.back().get(); Every(config.update_frequency, [this, network_node] { network_node->Process(Now()); });