blob: d85f2e6f3c3a1d3bb637949ab664efc026d82fa5 [file] [log] [blame]
Sebastian Jansson8d3e4bd2019-07-31 18:33:17 +02001/*
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 "test/network/simulated_network_node.h"
11
Mirko Bonadei317a1f02019-09-17 17:06:18 +020012#include <memory>
Sebastian Jansson8d3e4bd2019-07-31 18:33:17 +020013#include <utility>
14
Sebastian Jansson8d3e4bd2019-07-31 18:33:17 +020015namespace webrtc {
16namespace test {
17
18SimulatedNetworkNode::Builder::Builder() {}
19
20SimulatedNetworkNode::Builder::Builder(NetworkEmulationManager* net)
21 : net_(net) {}
22
23SimulatedNetworkNode::Builder& SimulatedNetworkNode::Builder::config(
24 SimulatedNetwork::Config config) {
25 config_ = config;
26 return *this;
27}
28
29SimulatedNetworkNode::Builder& SimulatedNetworkNode::Builder::delay_ms(
30 int queue_delay_ms) {
31 config_.queue_delay_ms = queue_delay_ms;
32 return *this;
33}
34
35SimulatedNetworkNode::Builder& SimulatedNetworkNode::Builder::capacity_kbps(
36 int link_capacity_kbps) {
37 config_.link_capacity_kbps = link_capacity_kbps;
38 return *this;
39}
40
41SimulatedNetworkNode::Builder& SimulatedNetworkNode::Builder::capacity_Mbps(
42 int link_capacity_Mbps) {
43 config_.link_capacity_kbps = link_capacity_Mbps * 1000;
44 return *this;
45}
46
47SimulatedNetworkNode::Builder& SimulatedNetworkNode::Builder::loss(
48 double loss_rate) {
49 config_.loss_percent = std::round(loss_rate * 100);
50 return *this;
51}
52
53SimulatedNetworkNode SimulatedNetworkNode::Builder::Build() const {
54 RTC_DCHECK(net_);
55 return Build(net_);
56}
57
58SimulatedNetworkNode SimulatedNetworkNode::Builder::Build(
59 NetworkEmulationManager* net) const {
60 SimulatedNetworkNode res;
Mirko Bonadei317a1f02019-09-17 17:06:18 +020061 auto behavior = std::make_unique<SimulatedNetwork>(config_);
Sebastian Jansson8d3e4bd2019-07-31 18:33:17 +020062 res.simulation = behavior.get();
63 res.node = net->CreateEmulatedNode(std::move(behavior));
64 return res;
65}
66
67} // namespace test
68} // namespace webrtc