blob: e23c09b6acfec4a5d7b85305d935b3ae4f57e30d [file] [log] [blame]
Sebastian Janssoncec24332019-12-04 14:26:50 +01001/*
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
15namespace webrtc {
16
17NetworkEmulationManager::SimulatedNetworkNode::Builder&
18NetworkEmulationManager::SimulatedNetworkNode::Builder::config(
19 BuiltInNetworkBehaviorConfig config) {
20 config_ = config;
21 return *this;
22}
23
24NetworkEmulationManager::SimulatedNetworkNode::Builder&
25NetworkEmulationManager::SimulatedNetworkNode::Builder::delay_ms(
26 int queue_delay_ms) {
27 config_.queue_delay_ms = queue_delay_ms;
28 return *this;
29}
30
31NetworkEmulationManager::SimulatedNetworkNode::Builder&
32NetworkEmulationManager::SimulatedNetworkNode::Builder::capacity_kbps(
33 int link_capacity_kbps) {
34 config_.link_capacity_kbps = link_capacity_kbps;
35 return *this;
36}
37
38NetworkEmulationManager::SimulatedNetworkNode::Builder&
39NetworkEmulationManager::SimulatedNetworkNode::Builder::capacity_Mbps(
40 int link_capacity_Mbps) {
41 config_.link_capacity_kbps = link_capacity_Mbps * 1000;
42 return *this;
43}
44
45NetworkEmulationManager::SimulatedNetworkNode::Builder&
46NetworkEmulationManager::SimulatedNetworkNode::Builder::loss(double loss_rate) {
47 config_.loss_percent = std::round(loss_rate * 100);
48 return *this;
49}
50
51NetworkEmulationManager::SimulatedNetworkNode
52NetworkEmulationManager::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