2016-10-04 08:43:09 -07:00
|
|
|
/*
|
|
|
|
|
* Copyright (c) 2016 The WebRTC project authors. All Rights Reserved.
|
|
|
|
|
*
|
|
|
|
|
* Use of this source code is governed by a BSD-style license
|
|
|
|
|
* that can be found in the LICENSE file in the root of the source
|
|
|
|
|
* tree. An additional intellectual property rights grant can be found
|
|
|
|
|
* in the file PATENTS. All contributing project authors may
|
|
|
|
|
* be found in the AUTHORS file in the root of the source tree.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#include "webrtc/modules/pacing/alr_detector.h"
|
|
|
|
|
|
2016-11-16 15:42:11 -08:00
|
|
|
#include "webrtc/test/gtest.h"
|
|
|
|
|
|
2016-10-04 08:43:09 -07:00
|
|
|
namespace {
|
|
|
|
|
|
|
|
|
|
constexpr int kEstimatedBitrateBps = 300000;
|
|
|
|
|
|
|
|
|
|
} // namespace
|
|
|
|
|
|
|
|
|
|
namespace webrtc {
|
|
|
|
|
|
2016-11-16 15:42:11 -08:00
|
|
|
class AlrDetectorTest : public testing::Test {
|
|
|
|
|
public:
|
|
|
|
|
void SetUp() override {
|
|
|
|
|
alr_detector_.SetEstimatedBitrate(kEstimatedBitrateBps);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void SimulateOutgoingTraffic(int interval_ms, int usage_percentage) {
|
|
|
|
|
const int kTimeStepMs = 10;
|
|
|
|
|
for (int t = 0; t < interval_ms; t += kTimeStepMs) {
|
|
|
|
|
now_ms += kTimeStepMs;
|
|
|
|
|
alr_detector_.OnBytesSent(kEstimatedBitrateBps * usage_percentage *
|
|
|
|
|
kTimeStepMs / (8 * 100 * 1000),
|
|
|
|
|
now_ms);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int remainder_ms = interval_ms % kTimeStepMs;
|
|
|
|
|
now_ms += remainder_ms;
|
|
|
|
|
if (remainder_ms > 0) {
|
|
|
|
|
alr_detector_.OnBytesSent(kEstimatedBitrateBps * usage_percentage *
|
|
|
|
|
remainder_ms / (8 * 100 * 1000),
|
|
|
|
|
remainder_ms);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected:
|
|
|
|
|
AlrDetector alr_detector_;
|
|
|
|
|
int64_t now_ms = 1;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
TEST_F(AlrDetectorTest, AlrDetection) {
|
|
|
|
|
// Start in non-ALR state.
|
2016-11-28 13:11:13 -08:00
|
|
|
EXPECT_FALSE(alr_detector_.GetApplicationLimitedRegionStartTime());
|
2016-11-16 15:42:11 -08:00
|
|
|
|
|
|
|
|
// Stay in non-ALR state when usage is close to 100%.
|
|
|
|
|
SimulateOutgoingTraffic(500, 90);
|
2016-11-28 13:11:13 -08:00
|
|
|
EXPECT_FALSE(alr_detector_.GetApplicationLimitedRegionStartTime());
|
2016-10-04 08:43:09 -07:00
|
|
|
|
2016-11-16 15:42:11 -08:00
|
|
|
// Verify that we ALR starts when bitrate drops below 20%.
|
|
|
|
|
SimulateOutgoingTraffic(500, 20);
|
2016-11-28 13:11:13 -08:00
|
|
|
EXPECT_TRUE(alr_detector_.GetApplicationLimitedRegionStartTime());
|
2016-10-04 08:43:09 -07:00
|
|
|
|
2017-01-27 02:27:33 -08:00
|
|
|
// Verify that we remain in ALR state while usage is still below 70%.
|
|
|
|
|
SimulateOutgoingTraffic(500, 69);
|
2016-11-28 13:11:13 -08:00
|
|
|
EXPECT_TRUE(alr_detector_.GetApplicationLimitedRegionStartTime());
|
2016-11-16 15:42:11 -08:00
|
|
|
|
2017-01-27 02:27:33 -08:00
|
|
|
// Verify that ALR ends when usage is above 70%.
|
|
|
|
|
SimulateOutgoingTraffic(500, 75);
|
2016-11-28 13:11:13 -08:00
|
|
|
EXPECT_FALSE(alr_detector_.GetApplicationLimitedRegionStartTime());
|
2016-11-16 15:42:11 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TEST_F(AlrDetectorTest, ShortSpike) {
|
|
|
|
|
// Start in non-ALR state.
|
2016-11-28 13:11:13 -08:00
|
|
|
EXPECT_FALSE(alr_detector_.GetApplicationLimitedRegionStartTime());
|
2016-11-16 15:42:11 -08:00
|
|
|
|
|
|
|
|
// Verify that we ALR starts when bitrate drops below 20%.
|
|
|
|
|
SimulateOutgoingTraffic(500, 20);
|
2016-11-28 13:11:13 -08:00
|
|
|
EXPECT_TRUE(alr_detector_.GetApplicationLimitedRegionStartTime());
|
2016-11-16 15:42:11 -08:00
|
|
|
|
|
|
|
|
// Verify that we stay in ALR region even after a short bitrate spike.
|
|
|
|
|
SimulateOutgoingTraffic(100, 150);
|
2016-11-28 13:11:13 -08:00
|
|
|
EXPECT_TRUE(alr_detector_.GetApplicationLimitedRegionStartTime());
|
2016-11-16 15:42:11 -08:00
|
|
|
|
|
|
|
|
SimulateOutgoingTraffic(200, 20);
|
2016-11-28 13:11:13 -08:00
|
|
|
EXPECT_TRUE(alr_detector_.GetApplicationLimitedRegionStartTime());
|
2016-11-16 15:42:11 -08:00
|
|
|
|
2017-01-27 02:27:33 -08:00
|
|
|
// ALR ends when usage is above 70%.
|
|
|
|
|
SimulateOutgoingTraffic(500, 75);
|
2016-11-28 13:11:13 -08:00
|
|
|
EXPECT_FALSE(alr_detector_.GetApplicationLimitedRegionStartTime());
|
2016-10-04 08:43:09 -07:00
|
|
|
}
|
|
|
|
|
|
2016-11-16 15:42:11 -08:00
|
|
|
TEST_F(AlrDetectorTest, BandwidthEstimateChanges) {
|
|
|
|
|
// Start in non-ALR state.
|
2016-11-28 13:11:13 -08:00
|
|
|
EXPECT_FALSE(alr_detector_.GetApplicationLimitedRegionStartTime());
|
2016-11-16 15:42:11 -08:00
|
|
|
|
|
|
|
|
// ALR starts when bitrate drops below 20%.
|
|
|
|
|
SimulateOutgoingTraffic(500, 20);
|
2016-11-28 13:11:13 -08:00
|
|
|
EXPECT_TRUE(alr_detector_.GetApplicationLimitedRegionStartTime());
|
2016-10-04 08:43:09 -07:00
|
|
|
|
2016-11-16 15:42:11 -08:00
|
|
|
// When bandwidth estimate drops the detector should stay in ALR mode and quit
|
|
|
|
|
// it shortly afterwards as the sender continues sending the same amount of
|
|
|
|
|
// traffic. This is necessary to ensure that ProbeController can still react
|
|
|
|
|
// to the BWE drop by initiating a new probe.
|
|
|
|
|
alr_detector_.SetEstimatedBitrate(kEstimatedBitrateBps / 5);
|
2016-11-28 13:11:13 -08:00
|
|
|
EXPECT_TRUE(alr_detector_.GetApplicationLimitedRegionStartTime());
|
2016-11-16 15:42:11 -08:00
|
|
|
SimulateOutgoingTraffic(10, 20);
|
2016-11-28 13:11:13 -08:00
|
|
|
EXPECT_FALSE(alr_detector_.GetApplicationLimitedRegionStartTime());
|
2016-10-04 08:43:09 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
} // namespace webrtc
|