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