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 <kwiberg@webrtc.org> Commit-Queue: Sebastian Jansson <srte@webrtc.org> Cr-Commit-Position: refs/heads/master@{#26450}
This commit is contained in:

committed by
Commit Bot

parent
c1a0bcbe89
commit
8c8feb9d2b
@ -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 {
|
||||
|
@ -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) {
|
||||
|
@ -50,10 +50,8 @@ void EmulatedNetworkNode::ClearRoute(uint64_t receiver_id,
|
||||
}
|
||||
|
||||
EmulatedNetworkNode::EmulatedNetworkNode(
|
||||
std::unique_ptr<NetworkBehaviorInterface> network_behavior,
|
||||
size_t packet_overhead)
|
||||
: network_behavior_(std::move(network_behavior)),
|
||||
packet_overhead_(packet_overhead) {}
|
||||
std::unique_ptr<NetworkBehaviorInterface> 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});
|
||||
}
|
||||
|
@ -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<NetworkBehaviorInterface> network_behavior,
|
||||
size_t packet_overhead = 0);
|
||||
explicit EmulatedNetworkNode(
|
||||
std::unique_ptr<NetworkBehaviorInterface> 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<NetworkBehaviorInterface> network_behavior_
|
||||
RTC_GUARDED_BY(lock_);
|
||||
const size_t packet_overhead_ RTC_GUARDED_BY(lock_);
|
||||
std::deque<StoredPacket> packets_ RTC_GUARDED_BY(lock_);
|
||||
|
||||
uint64_t next_packet_id_ RTC_GUARDED_BY(lock_) = 1;
|
||||
|
@ -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<int>();
|
||||
return sim_config;
|
||||
}
|
||||
} // namespace
|
||||
@ -73,8 +74,7 @@ SimulationNode::SimulationNode(
|
||||
NetworkNodeConfig config,
|
||||
std::unique_ptr<NetworkBehaviorInterface> behavior,
|
||||
SimulatedNetwork* simulation)
|
||||
: EmulatedNetworkNode(std::move(behavior),
|
||||
config.packet_overhead.bytes_or(0)),
|
||||
: EmulatedNetworkNode(std::move(behavior)),
|
||||
simulated_network_(simulation),
|
||||
config_(config) {}
|
||||
|
||||
|
@ -227,8 +227,7 @@ EmulatedNetworkNode* Scenario::CreateNetworkNode(
|
||||
NetworkNodeConfig config,
|
||||
std::unique_ptr<NetworkBehaviorInterface> 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()); });
|
||||
|
Reference in New Issue
Block a user