blob: 76927a1582475c228c40aa044a5f5d6bda9dc940 [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
Yves Gerey3e707812018-11-28 16:47:49 +010011#include <stddef.h>
12#include <cmath>
13#include <type_traits>
Anastasia Koloskovaddbbf462018-08-21 16:12:31 +020014#include <vector>
15
Yves Gerey3e707812018-11-28 16:47:49 +010016#include "api/transport/network_types.h"
17#include "api/units/data_rate.h"
18#include "api/units/data_size.h"
19#include "api/units/time_delta.h"
20#include "api/units/timestamp.h"
Anastasia Koloskovaddbbf462018-08-21 16:12:31 +020021#include "modules/congestion_controller/pcc/utility_function.h"
22#include "test/gtest.h"
23
24namespace webrtc {
25namespace pcc {
26namespace test {
27namespace {
28constexpr double kLossCoefficient = 11.35;
29constexpr double kThroughputPower = 0.9;
30constexpr double kThroughputCoefficient = 1;
31constexpr double kDelayGradientNegativeBound = 10;
32
33const Timestamp kStartTime = Timestamp::us(0);
34const TimeDelta kPacketsDelta = TimeDelta::ms(1);
35const TimeDelta kIntervalDuration = TimeDelta::ms(100);
36const DataRate kSendingBitrate = DataRate::bps(1000);
37
38const DataSize kDefaultDataSize = DataSize::bytes(100);
39const TimeDelta kDefaultDelay = TimeDelta::ms(100);
40
41std::vector<PacketResult> CreatePacketResults(
42 const std::vector<Timestamp>& packets_send_times,
43 const std::vector<Timestamp>& packets_received_times = {},
44 const std::vector<DataSize>& packets_sizes = {}) {
45 std::vector<PacketResult> packet_results;
46 PacketResult packet_result;
47 SentPacket sent_packet;
48 for (size_t i = 0; i < packets_send_times.size(); ++i) {
49 sent_packet.send_time = packets_send_times[i];
50 if (packets_sizes.empty()) {
51 sent_packet.size = kDefaultDataSize;
52 } else {
53 sent_packet.size = packets_sizes[i];
54 }
55 packet_result.sent_packet = sent_packet;
56 if (packets_received_times.empty()) {
57 packet_result.receive_time = packets_send_times[i] + kDefaultDelay;
58 } else {
59 packet_result.receive_time = packets_received_times[i];
60 }
61 packet_results.push_back(packet_result);
62 }
63 return packet_results;
64}
65
66} // namespace
67
68TEST(PccVivaceUtilityFunctionTest,
69 UtilityIsThroughputTermIfAllRestCoefficientsAreZero) {
70 VivaceUtilityFunction utility_function(0, 0, kThroughputCoefficient,
71 kThroughputPower, 0,
72 kDelayGradientNegativeBound);
73 PccMonitorInterval monitor_interval(kSendingBitrate, kStartTime,
74 kIntervalDuration);
75 monitor_interval.OnPacketsFeedback(CreatePacketResults(
76 {kStartTime + kPacketsDelta, kStartTime + 2 * kPacketsDelta,
77 kStartTime + 3 * kPacketsDelta, kStartTime + 2 * kIntervalDuration},
Sebastian Jansson9de4ef42018-09-04 17:32:36 +020078 {kStartTime + kPacketsDelta + kDefaultDelay, Timestamp::PlusInfinity(),
79 kStartTime + kDefaultDelay + 3 * kPacketsDelta,
80 Timestamp::PlusInfinity()},
Anastasia Koloskovaddbbf462018-08-21 16:12:31 +020081 {kDefaultDataSize, kDefaultDataSize, kDefaultDataSize,
82 kDefaultDataSize}));
83 EXPECT_DOUBLE_EQ(utility_function.Compute(monitor_interval),
84 kThroughputCoefficient *
85 std::pow(kSendingBitrate.bps(), kThroughputPower));
86}
87
88TEST(PccVivaceUtilityFunctionTest,
89 LossTermIsNonZeroIfLossCoefficientIsNonZero) {
90 VivaceUtilityFunction utility_function(
91 0, kLossCoefficient, kThroughputCoefficient, kThroughputPower, 0,
92 kDelayGradientNegativeBound);
93 PccMonitorInterval monitor_interval(kSendingBitrate, kStartTime,
94 kIntervalDuration);
95 monitor_interval.OnPacketsFeedback(CreatePacketResults(
96 {kStartTime + kPacketsDelta, kStartTime + 2 * kPacketsDelta,
97 kStartTime + 5 * kPacketsDelta, kStartTime + 2 * kIntervalDuration},
Sebastian Jansson9de4ef42018-09-04 17:32:36 +020098 {kStartTime + kDefaultDelay, Timestamp::PlusInfinity(),
Anastasia Koloskovaddbbf462018-08-21 16:12:31 +020099 kStartTime + kDefaultDelay, kStartTime + 3 * kIntervalDuration},
100 {}));
101 // The second packet was lost.
102 EXPECT_DOUBLE_EQ(utility_function.Compute(monitor_interval),
103 kThroughputCoefficient *
104 std::pow(kSendingBitrate.bps(), kThroughputPower) -
105 kLossCoefficient * kSendingBitrate.bps() *
106 monitor_interval.GetLossRate());
107}
108
109} // namespace test
110} // namespace pcc
111} // namespace webrtc