1 /*
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 "modules/congestion_controller/goog_cc/congestion_window_pushback_controller.h"
12 
13 #include <memory>
14 
15 #include "api/transport/field_trial_based_config.h"
16 #include "test/field_trial.h"
17 #include "test/gmock.h"
18 #include "test/gtest.h"
19 
20 using ::testing::_;
21 
22 namespace webrtc {
23 namespace test {
24 
25 class CongestionWindowPushbackControllerTest : public ::testing::Test {
26  public:
CongestionWindowPushbackControllerTest()27   CongestionWindowPushbackControllerTest() {
28     cwnd_controller_.reset(
29         new CongestionWindowPushbackController(&field_trial_config_));
30   }
31 
32  protected:
33   FieldTrialBasedConfig field_trial_config_;
34 
35   std::unique_ptr<CongestionWindowPushbackController> cwnd_controller_;
36 };
37 
TEST_F(CongestionWindowPushbackControllerTest,FullCongestionWindow)38 TEST_F(CongestionWindowPushbackControllerTest, FullCongestionWindow) {
39   cwnd_controller_->UpdateOutstandingData(100000);
40   cwnd_controller_->SetDataWindow(DataSize::Bytes(50000));
41 
42   uint32_t bitrate_bps = 80000;
43   bitrate_bps = cwnd_controller_->UpdateTargetBitrate(bitrate_bps);
44   EXPECT_EQ(72000u, bitrate_bps);
45 
46   cwnd_controller_->SetDataWindow(DataSize::Bytes(50000));
47   bitrate_bps = cwnd_controller_->UpdateTargetBitrate(bitrate_bps);
48   EXPECT_EQ(static_cast<uint32_t>(72000 * 0.9 * 0.9), bitrate_bps);
49 }
50 
TEST_F(CongestionWindowPushbackControllerTest,NormalCongestionWindow)51 TEST_F(CongestionWindowPushbackControllerTest, NormalCongestionWindow) {
52   cwnd_controller_->UpdateOutstandingData(199999);
53   cwnd_controller_->SetDataWindow(DataSize::Bytes(200000));
54 
55   uint32_t bitrate_bps = 80000;
56   bitrate_bps = cwnd_controller_->UpdateTargetBitrate(bitrate_bps);
57   EXPECT_EQ(80000u, bitrate_bps);
58 }
59 
TEST_F(CongestionWindowPushbackControllerTest,LowBitrate)60 TEST_F(CongestionWindowPushbackControllerTest, LowBitrate) {
61   cwnd_controller_->UpdateOutstandingData(100000);
62   cwnd_controller_->SetDataWindow(DataSize::Bytes(50000));
63 
64   uint32_t bitrate_bps = 35000;
65   bitrate_bps = cwnd_controller_->UpdateTargetBitrate(bitrate_bps);
66   EXPECT_EQ(static_cast<uint32_t>(35000 * 0.9), bitrate_bps);
67 
68   cwnd_controller_->SetDataWindow(DataSize::Bytes(20000));
69   bitrate_bps = cwnd_controller_->UpdateTargetBitrate(bitrate_bps);
70   EXPECT_EQ(30000u, bitrate_bps);
71 }
72 
TEST_F(CongestionWindowPushbackControllerTest,NoPushbackOnDataWindowUnset)73 TEST_F(CongestionWindowPushbackControllerTest, NoPushbackOnDataWindowUnset) {
74   cwnd_controller_->UpdateOutstandingData(1e8);  // Large number
75 
76   uint32_t bitrate_bps = 80000;
77   bitrate_bps = cwnd_controller_->UpdateTargetBitrate(bitrate_bps);
78   EXPECT_EQ(80000u, bitrate_bps);
79 }
80 
TEST_F(CongestionWindowPushbackControllerTest,PushbackOnInititialDataWindow)81 TEST_F(CongestionWindowPushbackControllerTest, PushbackOnInititialDataWindow) {
82   test::ScopedFieldTrials trials("WebRTC-CongestionWindow/InitWin:100000/");
83   cwnd_controller_.reset(
84       new CongestionWindowPushbackController(&field_trial_config_));
85   cwnd_controller_->UpdateOutstandingData(1e8);  // Large number
86 
87   uint32_t bitrate_bps = 80000;
88   bitrate_bps = cwnd_controller_->UpdateTargetBitrate(bitrate_bps);
89   EXPECT_GT(80000u, bitrate_bps);
90 }
91 
TEST_F(CongestionWindowPushbackControllerTest,PushbackDropFrame)92 TEST_F(CongestionWindowPushbackControllerTest, PushbackDropFrame) {
93   test::ScopedFieldTrials trials("WebRTC-CongestionWindow/DropFrame:true/");
94   cwnd_controller_.reset(
95       new CongestionWindowPushbackController(&field_trial_config_));
96   cwnd_controller_->UpdateOutstandingData(1e8);  // Large number
97   cwnd_controller_->SetDataWindow(DataSize::Bytes(50000));
98 
99   uint32_t bitrate_bps = 80000;
100   bitrate_bps = cwnd_controller_->UpdateTargetBitrate(bitrate_bps);
101   EXPECT_GT(80000u, bitrate_bps);
102 }
103 
104 }  // namespace test
105 }  // namespace webrtc
106