1 /* 2 * Copyright (c) 2019 The WebRTC project authors. All Rights Reserved. 3 * 4 * Use of this source code is governed by a BSD-style license 5 * that can be found in the LICENSE file in the root of the source 6 * tree. An additional intellectual property rights grant can be found 7 * in the file PATENTS. All contributing project authors may 8 * be found in the AUTHORS file in the root of the source tree. 9 */ 10 #include <utility> 11 12 #include "api/test/network_emulation_manager.h" 13 #include "call/simulated_network.h" 14 15 namespace webrtc { 16 17 NetworkEmulationManager::SimulatedNetworkNode::Builder& config(BuiltInNetworkBehaviorConfig config)18NetworkEmulationManager::SimulatedNetworkNode::Builder::config( 19 BuiltInNetworkBehaviorConfig config) { 20 config_ = config; 21 return *this; 22 } 23 24 NetworkEmulationManager::SimulatedNetworkNode::Builder& delay_ms(int queue_delay_ms)25NetworkEmulationManager::SimulatedNetworkNode::Builder::delay_ms( 26 int queue_delay_ms) { 27 config_.queue_delay_ms = queue_delay_ms; 28 return *this; 29 } 30 31 NetworkEmulationManager::SimulatedNetworkNode::Builder& capacity_kbps(int link_capacity_kbps)32NetworkEmulationManager::SimulatedNetworkNode::Builder::capacity_kbps( 33 int link_capacity_kbps) { 34 config_.link_capacity_kbps = link_capacity_kbps; 35 return *this; 36 } 37 38 NetworkEmulationManager::SimulatedNetworkNode::Builder& capacity_Mbps(int link_capacity_Mbps)39NetworkEmulationManager::SimulatedNetworkNode::Builder::capacity_Mbps( 40 int link_capacity_Mbps) { 41 config_.link_capacity_kbps = link_capacity_Mbps * 1000; 42 return *this; 43 } 44 45 NetworkEmulationManager::SimulatedNetworkNode::Builder& loss(double loss_rate)46NetworkEmulationManager::SimulatedNetworkNode::Builder::loss(double loss_rate) { 47 config_.loss_percent = std::round(loss_rate * 100); 48 return *this; 49 } 50 51 NetworkEmulationManager::SimulatedNetworkNode::Builder& packet_queue_length(int max_queue_length_in_packets)52NetworkEmulationManager::SimulatedNetworkNode::Builder::packet_queue_length( 53 int max_queue_length_in_packets) { 54 config_.queue_length_packets = max_queue_length_in_packets; 55 return *this; 56 } 57 58 NetworkEmulationManager::SimulatedNetworkNode Build() const59NetworkEmulationManager::SimulatedNetworkNode::Builder::Build() const { 60 RTC_CHECK(net_); 61 return Build(net_); 62 } 63 64 NetworkEmulationManager::SimulatedNetworkNode Build(NetworkEmulationManager * net) const65NetworkEmulationManager::SimulatedNetworkNode::Builder::Build( 66 NetworkEmulationManager* net) const { 67 RTC_CHECK(net); 68 RTC_CHECK(net_ == nullptr || net_ == net); 69 SimulatedNetworkNode res; 70 auto behavior = std::make_unique<SimulatedNetwork>(config_); 71 res.simulation = behavior.get(); 72 res.node = net->CreateEmulatedNode(std::move(behavior)); 73 return res; 74 } 75 } // namespace webrtc 76