blob: 5bc3dc4e536152bda275fddebee1adf756572e3b [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},
Sebastian Jansson9de4ef42018-09-04 17:32:36 +020070 {kStartTime + kPacketsDelta + kDefaultDelay, Timestamp::PlusInfinity(),
71 kStartTime + kDefaultDelay + 3 * kPacketsDelta,
72 Timestamp::PlusInfinity()},
Anastasia Koloskovaddbbf462018-08-21 16:12:31 +020073 {kDefaultDataSize, kDefaultDataSize, kDefaultDataSize,
74 kDefaultDataSize}));
75 EXPECT_DOUBLE_EQ(utility_function.Compute(monitor_interval),
76 kThroughputCoefficient *
77 std::pow(kSendingBitrate.bps(), kThroughputPower));
78}
79
80TEST(PccVivaceUtilityFunctionTest,
81 LossTermIsNonZeroIfLossCoefficientIsNonZero) {
82 VivaceUtilityFunction utility_function(
83 0, kLossCoefficient, kThroughputCoefficient, kThroughputPower, 0,
84 kDelayGradientNegativeBound);
85 PccMonitorInterval monitor_interval(kSendingBitrate, kStartTime,
86 kIntervalDuration);
87 monitor_interval.OnPacketsFeedback(CreatePacketResults(
88 {kStartTime + kPacketsDelta, kStartTime + 2 * kPacketsDelta,
89 kStartTime + 5 * kPacketsDelta, kStartTime + 2 * kIntervalDuration},
Sebastian Jansson9de4ef42018-09-04 17:32:36 +020090 {kStartTime + kDefaultDelay, Timestamp::PlusInfinity(),
Anastasia Koloskovaddbbf462018-08-21 16:12:31 +020091 kStartTime + kDefaultDelay, kStartTime + 3 * kIntervalDuration},
92 {}));
93 // The second packet was lost.
94 EXPECT_DOUBLE_EQ(utility_function.Compute(monitor_interval),
95 kThroughputCoefficient *
96 std::pow(kSendingBitrate.bps(), kThroughputPower) -
97 kLossCoefficient * kSendingBitrate.bps() *
98 monitor_interval.GetLossRate());
99}
100
101} // namespace test
102} // namespace pcc
103} // namespace webrtc