Sebastian Jansson | cec2433 | 2019-12-04 14:26:50 +0100 | [diff] [blame] | 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& |
| 18 | NetworkEmulationManager::SimulatedNetworkNode::Builder::config( |
| 19 | BuiltInNetworkBehaviorConfig config) { |
| 20 | config_ = config; |
| 21 | return *this; |
| 22 | } |
| 23 | |
| 24 | NetworkEmulationManager::SimulatedNetworkNode::Builder& |
| 25 | NetworkEmulationManager::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& |
| 32 | NetworkEmulationManager::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& |
| 39 | NetworkEmulationManager::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& |
| 46 | NetworkEmulationManager::SimulatedNetworkNode::Builder::loss(double loss_rate) { |
| 47 | config_.loss_percent = std::round(loss_rate * 100); |
| 48 | return *this; |
| 49 | } |
| 50 | |
| 51 | NetworkEmulationManager::SimulatedNetworkNode |
| 52 | NetworkEmulationManager::SimulatedNetworkNode::Builder::Build() const { |
| 53 | SimulatedNetworkNode res; |
| 54 | auto behavior = std::make_unique<SimulatedNetwork>(config_); |
| 55 | res.simulation = behavior.get(); |
| 56 | res.node = net_->CreateEmulatedNode(std::move(behavior)); |
| 57 | return res; |
| 58 | } |
| 59 | } // namespace webrtc |