blob: c3139eda05d54f66c88d9084ad05c914ef2ed5e1 [file] [log] [blame]
Anastasia Koloskovaddbbf462018-08-21 16:12:31 +02001/*
2 * Copyright (c) 2018 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
11#include <vector>
12
13#include "modules/congestion_controller/pcc/utility_function.h"
14#include "test/gtest.h"
15
16namespace webrtc {
17namespace pcc {
18namespace test {
19namespace {
20constexpr double kLossCoefficient = 11.35;
21constexpr double kThroughputPower = 0.9;
22constexpr double kThroughputCoefficient = 1;
23constexpr double kDelayGradientNegativeBound = 10;
24
25const Timestamp kStartTime = Timestamp::us(0);
26const TimeDelta kPacketsDelta = TimeDelta::ms(1);
27const TimeDelta kIntervalDuration = TimeDelta::ms(100);
28const DataRate kSendingBitrate = DataRate::bps(1000);
29
30const DataSize kDefaultDataSize = DataSize::bytes(100);
31const TimeDelta kDefaultDelay = TimeDelta::ms(100);
32
33std::vector<PacketResult> CreatePacketResults(
34 const std::vector<Timestamp>& packets_send_times,
35 const std::vector<Timestamp>& packets_received_times = {},
36 const std::vector<DataSize>& packets_sizes = {}) {
37 std::vector<PacketResult> packet_results;
38 PacketResult packet_result;
39 SentPacket sent_packet;
40 for (size_t i = 0; i < packets_send_times.size(); ++i) {
41 sent_packet.send_time = packets_send_times[i];
42 if (packets_sizes.empty()) {
43 sent_packet.size = kDefaultDataSize;
44 } else {
45 sent_packet.size = packets_sizes[i];
46 }
47 packet_result.sent_packet = sent_packet;
48 if (packets_received_times.empty()) {
49 packet_result.receive_time = packets_send_times[i] + kDefaultDelay;
50 } else {
51 packet_result.receive_time = packets_received_times[i];
52 }
53 packet_results.push_back(packet_result);
54 }
55 return packet_results;
56}
57
58} // namespace
59
60TEST(PccVivaceUtilityFunctionTest,
61 UtilityIsThroughputTermIfAllRestCoefficientsAreZero) {
62 VivaceUtilityFunction utility_function(0, 0, kThroughputCoefficient,
63 kThroughputPower, 0,
64 kDelayGradientNegativeBound);
65 PccMonitorInterval monitor_interval(kSendingBitrate, kStartTime,
66 kIntervalDuration);
67 monitor_interval.OnPacketsFeedback(CreatePacketResults(
68 {kStartTime + kPacketsDelta, kStartTime + 2 * kPacketsDelta,
69 kStartTime + 3 * kPacketsDelta, kStartTime + 2 * kIntervalDuration},
70 {kStartTime + kPacketsDelta + kDefaultDelay, Timestamp::Infinity(),
71 kStartTime + kDefaultDelay + 3 * kPacketsDelta, Timestamp::Infinity()},
72 {kDefaultDataSize, kDefaultDataSize, kDefaultDataSize,
73 kDefaultDataSize}));
74 EXPECT_DOUBLE_EQ(utility_function.Compute(monitor_interval),
75 kThroughputCoefficient *
76 std::pow(kSendingBitrate.bps(), kThroughputPower));
77}
78
79TEST(PccVivaceUtilityFunctionTest,
80 LossTermIsNonZeroIfLossCoefficientIsNonZero) {
81 VivaceUtilityFunction utility_function(
82 0, kLossCoefficient, kThroughputCoefficient, kThroughputPower, 0,
83 kDelayGradientNegativeBound);
84 PccMonitorInterval monitor_interval(kSendingBitrate, kStartTime,
85 kIntervalDuration);
86 monitor_interval.OnPacketsFeedback(CreatePacketResults(
87 {kStartTime + kPacketsDelta, kStartTime + 2 * kPacketsDelta,
88 kStartTime + 5 * kPacketsDelta, kStartTime + 2 * kIntervalDuration},
89 {kStartTime + kDefaultDelay, Timestamp::Infinity(),
90 kStartTime + kDefaultDelay, kStartTime + 3 * kIntervalDuration},
91 {}));
92 // The second packet was lost.
93 EXPECT_DOUBLE_EQ(utility_function.Compute(monitor_interval),
94 kThroughputCoefficient *
95 std::pow(kSendingBitrate.bps(), kThroughputPower) -
96 kLossCoefficient * kSendingBitrate.bps() *
97 monitor_interval.GetLossRate());
98}
99
100} // namespace test
101} // namespace pcc
102} // namespace webrtc