2016-09-12 12:28:54 -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 <memory>
|
|
|
|
|
|
2017-09-15 06:47:31 +02:00
|
|
|
#include "modules/congestion_controller/probe_controller.h"
|
|
|
|
|
#include "modules/pacing/mock/mock_paced_sender.h"
|
|
|
|
|
#include "rtc_base/logging.h"
|
|
|
|
|
#include "system_wrappers/include/clock.h"
|
|
|
|
|
#include "test/gmock.h"
|
|
|
|
|
#include "test/gtest.h"
|
2016-09-12 12:28:54 -07:00
|
|
|
|
|
|
|
|
using testing::_;
|
|
|
|
|
using testing::AtLeast;
|
|
|
|
|
using testing::NiceMock;
|
2016-11-28 13:11:13 -08:00
|
|
|
using testing::Return;
|
2016-09-12 12:28:54 -07:00
|
|
|
|
|
|
|
|
namespace webrtc {
|
|
|
|
|
namespace test {
|
|
|
|
|
|
|
|
|
|
namespace {
|
|
|
|
|
|
|
|
|
|
constexpr int kMinBitrateBps = 100;
|
|
|
|
|
constexpr int kStartBitrateBps = 300;
|
2016-11-03 11:59:50 -07:00
|
|
|
constexpr int kMaxBitrateBps = 10000;
|
2016-09-12 12:28:54 -07:00
|
|
|
|
2016-09-16 11:30:44 -07:00
|
|
|
constexpr int kExponentialProbingTimeoutMs = 5000;
|
|
|
|
|
|
2016-11-28 13:11:13 -08:00
|
|
|
constexpr int kAlrProbeInterval = 5000;
|
2017-07-31 04:23:25 -07:00
|
|
|
constexpr int kAlrEndedTimeoutMs = 3000;
|
|
|
|
|
constexpr int kBitrateDropTimeoutMs = 5000;
|
2016-11-28 13:11:13 -08:00
|
|
|
|
2016-09-12 12:28:54 -07:00
|
|
|
} // namespace
|
|
|
|
|
|
|
|
|
|
class ProbeControllerTest : public ::testing::Test {
|
|
|
|
|
protected:
|
2016-11-28 13:11:13 -08:00
|
|
|
ProbeControllerTest() : clock_(100000000L) {
|
2016-09-12 12:28:54 -07:00
|
|
|
probe_controller_.reset(new ProbeController(&pacer_, &clock_));
|
|
|
|
|
}
|
|
|
|
|
~ProbeControllerTest() override {}
|
|
|
|
|
|
|
|
|
|
SimulatedClock clock_;
|
|
|
|
|
NiceMock<MockPacedSender> pacer_;
|
|
|
|
|
std::unique_ptr<ProbeController> probe_controller_;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
TEST_F(ProbeControllerTest, InitiatesProbingAtStart) {
|
2017-01-04 07:05:25 -08:00
|
|
|
EXPECT_CALL(pacer_, CreateProbeCluster(_)).Times(AtLeast(2));
|
2016-09-12 12:28:54 -07:00
|
|
|
probe_controller_->SetBitrates(kMinBitrateBps, kStartBitrateBps,
|
|
|
|
|
kMaxBitrateBps);
|
|
|
|
|
}
|
|
|
|
|
|
2016-11-22 16:08:30 -08:00
|
|
|
TEST_F(ProbeControllerTest, ProbeOnlyWhenNetworkIsUp) {
|
|
|
|
|
probe_controller_->OnNetworkStateChanged(kNetworkDown);
|
2017-01-04 07:05:25 -08:00
|
|
|
EXPECT_CALL(pacer_, CreateProbeCluster(_)).Times(0);
|
2016-11-22 16:08:30 -08:00
|
|
|
probe_controller_->SetBitrates(kMinBitrateBps, kStartBitrateBps,
|
|
|
|
|
kMaxBitrateBps);
|
|
|
|
|
|
|
|
|
|
testing::Mock::VerifyAndClearExpectations(&pacer_);
|
2017-01-04 07:05:25 -08:00
|
|
|
EXPECT_CALL(pacer_, CreateProbeCluster(_)).Times(AtLeast(2));
|
2016-11-22 16:08:30 -08:00
|
|
|
probe_controller_->OnNetworkStateChanged(kNetworkUp);
|
|
|
|
|
}
|
|
|
|
|
|
2016-09-12 12:28:54 -07:00
|
|
|
TEST_F(ProbeControllerTest, InitiatesProbingOnMaxBitrateIncrease) {
|
2017-01-04 07:05:25 -08:00
|
|
|
EXPECT_CALL(pacer_, CreateProbeCluster(_)).Times(AtLeast(2));
|
2016-09-12 12:28:54 -07:00
|
|
|
probe_controller_->SetBitrates(kMinBitrateBps, kStartBitrateBps,
|
|
|
|
|
kMaxBitrateBps);
|
2016-09-16 11:30:44 -07:00
|
|
|
// Long enough to time out exponential probing.
|
|
|
|
|
clock_.AdvanceTimeMilliseconds(kExponentialProbingTimeoutMs);
|
2016-09-12 12:28:54 -07:00
|
|
|
probe_controller_->SetEstimatedBitrate(kStartBitrateBps);
|
2016-12-02 11:03:01 -08:00
|
|
|
probe_controller_->Process();
|
2016-09-16 11:30:44 -07:00
|
|
|
|
2017-01-04 07:05:25 -08:00
|
|
|
EXPECT_CALL(pacer_, CreateProbeCluster(kMaxBitrateBps + 100));
|
2016-09-12 12:28:54 -07:00
|
|
|
probe_controller_->SetBitrates(kMinBitrateBps, kStartBitrateBps,
|
|
|
|
|
kMaxBitrateBps + 100);
|
|
|
|
|
}
|
|
|
|
|
|
2017-01-17 02:08:28 -08:00
|
|
|
TEST_F(ProbeControllerTest, InitiatesProbingOnMaxBitrateIncreaseAtMaxBitrate) {
|
|
|
|
|
EXPECT_CALL(pacer_, CreateProbeCluster(_)).Times(AtLeast(2));
|
|
|
|
|
probe_controller_->SetBitrates(kMinBitrateBps, kStartBitrateBps,
|
|
|
|
|
kMaxBitrateBps);
|
|
|
|
|
// Long enough to time out exponential probing.
|
|
|
|
|
clock_.AdvanceTimeMilliseconds(kExponentialProbingTimeoutMs);
|
|
|
|
|
probe_controller_->SetEstimatedBitrate(kStartBitrateBps);
|
|
|
|
|
probe_controller_->Process();
|
|
|
|
|
|
|
|
|
|
probe_controller_->SetEstimatedBitrate(kMaxBitrateBps);
|
|
|
|
|
EXPECT_CALL(pacer_, CreateProbeCluster(kMaxBitrateBps + 100));
|
|
|
|
|
probe_controller_->SetBitrates(kMinBitrateBps, kStartBitrateBps,
|
|
|
|
|
kMaxBitrateBps + 100);
|
|
|
|
|
}
|
|
|
|
|
|
2016-09-12 12:28:54 -07:00
|
|
|
TEST_F(ProbeControllerTest, TestExponentialProbing) {
|
|
|
|
|
probe_controller_->SetBitrates(kMinBitrateBps, kStartBitrateBps,
|
|
|
|
|
kMaxBitrateBps);
|
2016-11-03 11:59:50 -07:00
|
|
|
|
2016-12-15 10:42:09 -08:00
|
|
|
// Repeated probe should only be sent when estimated bitrate climbs above
|
|
|
|
|
// 0.7 * 6 * kStartBitrateBps = 1260.
|
2017-01-04 07:05:25 -08:00
|
|
|
EXPECT_CALL(pacer_, CreateProbeCluster(_)).Times(0);
|
2016-12-02 11:03:01 -08:00
|
|
|
probe_controller_->SetEstimatedBitrate(1000);
|
|
|
|
|
testing::Mock::VerifyAndClearExpectations(&pacer_);
|
|
|
|
|
|
2017-01-04 07:05:25 -08:00
|
|
|
EXPECT_CALL(pacer_, CreateProbeCluster(2 * 1800));
|
2016-09-12 12:28:54 -07:00
|
|
|
probe_controller_->SetEstimatedBitrate(1800);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TEST_F(ProbeControllerTest, TestExponentialProbingTimeout) {
|
|
|
|
|
probe_controller_->SetBitrates(kMinBitrateBps, kStartBitrateBps,
|
|
|
|
|
kMaxBitrateBps);
|
|
|
|
|
|
|
|
|
|
// Advance far enough to cause a time out in waiting for probing result.
|
2016-09-16 11:30:44 -07:00
|
|
|
clock_.AdvanceTimeMilliseconds(kExponentialProbingTimeoutMs);
|
2016-12-02 11:03:01 -08:00
|
|
|
probe_controller_->Process();
|
|
|
|
|
|
2017-01-04 07:05:25 -08:00
|
|
|
EXPECT_CALL(pacer_, CreateProbeCluster(_)).Times(0);
|
2016-09-12 12:28:54 -07:00
|
|
|
probe_controller_->SetEstimatedBitrate(1800);
|
|
|
|
|
}
|
|
|
|
|
|
2017-07-31 04:23:25 -07:00
|
|
|
TEST_F(ProbeControllerTest, RequestProbeInAlr) {
|
2017-01-04 07:05:25 -08:00
|
|
|
EXPECT_CALL(pacer_, CreateProbeCluster(_)).Times(2);
|
2016-11-28 13:11:13 -08:00
|
|
|
probe_controller_->SetBitrates(kMinBitrateBps, kStartBitrateBps,
|
|
|
|
|
kMaxBitrateBps);
|
|
|
|
|
probe_controller_->SetEstimatedBitrate(500);
|
|
|
|
|
testing::Mock::VerifyAndClearExpectations(&pacer_);
|
2017-07-31 04:23:25 -07:00
|
|
|
EXPECT_CALL(pacer_, CreateProbeCluster(0.85 * 500)).Times(1);
|
|
|
|
|
EXPECT_CALL(pacer_, GetApplicationLimitedRegionStartTime())
|
2017-11-16 10:56:55 +01:00
|
|
|
.WillRepeatedly(Return(clock_.TimeInMilliseconds()));
|
2017-07-31 04:23:25 -07:00
|
|
|
clock_.AdvanceTimeMilliseconds(kAlrProbeInterval + 1);
|
|
|
|
|
probe_controller_->Process();
|
|
|
|
|
probe_controller_->SetEstimatedBitrate(250);
|
|
|
|
|
probe_controller_->RequestProbe();
|
|
|
|
|
}
|
2016-11-28 13:11:13 -08:00
|
|
|
|
2017-07-31 04:23:25 -07:00
|
|
|
TEST_F(ProbeControllerTest, RequestProbeWhenAlrEndedRecently) {
|
|
|
|
|
EXPECT_CALL(pacer_, CreateProbeCluster(_)).Times(2);
|
|
|
|
|
probe_controller_->SetBitrates(kMinBitrateBps, kStartBitrateBps,
|
|
|
|
|
kMaxBitrateBps);
|
|
|
|
|
probe_controller_->SetEstimatedBitrate(500);
|
|
|
|
|
testing::Mock::VerifyAndClearExpectations(&pacer_);
|
|
|
|
|
EXPECT_CALL(pacer_, CreateProbeCluster(0.85 * 500)).Times(1);
|
|
|
|
|
EXPECT_CALL(pacer_, GetApplicationLimitedRegionStartTime())
|
2017-11-16 10:56:55 +01:00
|
|
|
.WillRepeatedly(Return(rtc::nullopt));
|
2017-07-31 04:23:25 -07:00
|
|
|
clock_.AdvanceTimeMilliseconds(kAlrProbeInterval + 1);
|
|
|
|
|
probe_controller_->Process();
|
|
|
|
|
probe_controller_->SetEstimatedBitrate(250);
|
|
|
|
|
probe_controller_->SetAlrEndedTimeMs(clock_.TimeInMilliseconds());
|
|
|
|
|
clock_.AdvanceTimeMilliseconds(kAlrEndedTimeoutMs - 1);
|
|
|
|
|
probe_controller_->RequestProbe();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TEST_F(ProbeControllerTest, RequestProbeWhenAlrNotEndedRecently) {
|
|
|
|
|
EXPECT_CALL(pacer_, CreateProbeCluster(_)).Times(2);
|
|
|
|
|
probe_controller_->SetBitrates(kMinBitrateBps, kStartBitrateBps,
|
|
|
|
|
kMaxBitrateBps);
|
|
|
|
|
probe_controller_->SetEstimatedBitrate(500);
|
|
|
|
|
testing::Mock::VerifyAndClearExpectations(&pacer_);
|
|
|
|
|
EXPECT_CALL(pacer_, CreateProbeCluster(_)).Times(0);
|
|
|
|
|
EXPECT_CALL(pacer_, GetApplicationLimitedRegionStartTime())
|
2017-11-16 10:56:55 +01:00
|
|
|
.WillRepeatedly(Return(rtc::nullopt));
|
2017-07-31 04:23:25 -07:00
|
|
|
clock_.AdvanceTimeMilliseconds(kAlrProbeInterval + 1);
|
|
|
|
|
probe_controller_->Process();
|
|
|
|
|
probe_controller_->SetEstimatedBitrate(250);
|
|
|
|
|
probe_controller_->SetAlrEndedTimeMs(clock_.TimeInMilliseconds());
|
|
|
|
|
clock_.AdvanceTimeMilliseconds(kAlrEndedTimeoutMs + 1);
|
|
|
|
|
probe_controller_->RequestProbe();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TEST_F(ProbeControllerTest, RequestProbeWhenBweDropNotRecent) {
|
|
|
|
|
EXPECT_CALL(pacer_, CreateProbeCluster(_)).Times(2);
|
|
|
|
|
probe_controller_->SetBitrates(kMinBitrateBps, kStartBitrateBps,
|
|
|
|
|
kMaxBitrateBps);
|
|
|
|
|
probe_controller_->SetEstimatedBitrate(500);
|
|
|
|
|
testing::Mock::VerifyAndClearExpectations(&pacer_);
|
|
|
|
|
EXPECT_CALL(pacer_, CreateProbeCluster(_)).Times(0);
|
2016-11-28 13:11:13 -08:00
|
|
|
EXPECT_CALL(pacer_, GetApplicationLimitedRegionStartTime())
|
2017-11-16 10:56:55 +01:00
|
|
|
.WillRepeatedly(Return(clock_.TimeInMilliseconds()));
|
2016-11-28 13:11:13 -08:00
|
|
|
clock_.AdvanceTimeMilliseconds(kAlrProbeInterval + 1);
|
2016-12-02 11:03:01 -08:00
|
|
|
probe_controller_->Process();
|
2017-07-31 04:23:25 -07:00
|
|
|
probe_controller_->SetEstimatedBitrate(250);
|
|
|
|
|
clock_.AdvanceTimeMilliseconds(kBitrateDropTimeoutMs + 1);
|
|
|
|
|
probe_controller_->RequestProbe();
|
2016-11-28 13:11:13 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TEST_F(ProbeControllerTest, PeriodicProbing) {
|
2017-01-04 07:05:25 -08:00
|
|
|
EXPECT_CALL(pacer_, CreateProbeCluster(_)).Times(2);
|
2016-11-28 13:11:13 -08:00
|
|
|
probe_controller_->EnablePeriodicAlrProbing(true);
|
|
|
|
|
probe_controller_->SetBitrates(kMinBitrateBps, kStartBitrateBps,
|
|
|
|
|
kMaxBitrateBps);
|
|
|
|
|
probe_controller_->SetEstimatedBitrate(500);
|
|
|
|
|
testing::Mock::VerifyAndClearExpectations(&pacer_);
|
|
|
|
|
|
|
|
|
|
int64_t start_time = clock_.TimeInMilliseconds();
|
|
|
|
|
|
|
|
|
|
// Expect the controller to send a new probe after 5s has passed.
|
2017-01-04 07:05:25 -08:00
|
|
|
EXPECT_CALL(pacer_, CreateProbeCluster(1000)).Times(1);
|
2016-11-28 13:11:13 -08:00
|
|
|
EXPECT_CALL(pacer_, GetApplicationLimitedRegionStartTime())
|
2017-11-16 10:56:55 +01:00
|
|
|
.WillRepeatedly(Return(start_time));
|
2016-11-28 13:11:13 -08:00
|
|
|
clock_.AdvanceTimeMilliseconds(5000);
|
|
|
|
|
probe_controller_->Process();
|
|
|
|
|
probe_controller_->SetEstimatedBitrate(500);
|
|
|
|
|
testing::Mock::VerifyAndClearExpectations(&pacer_);
|
|
|
|
|
|
|
|
|
|
// The following probe should be sent at 10s into ALR.
|
2017-01-04 07:05:25 -08:00
|
|
|
EXPECT_CALL(pacer_, CreateProbeCluster(_)).Times(0);
|
2016-11-28 13:11:13 -08:00
|
|
|
EXPECT_CALL(pacer_, GetApplicationLimitedRegionStartTime())
|
2017-11-16 10:56:55 +01:00
|
|
|
.WillRepeatedly(Return(start_time));
|
2016-11-28 13:11:13 -08:00
|
|
|
clock_.AdvanceTimeMilliseconds(4000);
|
|
|
|
|
probe_controller_->Process();
|
|
|
|
|
probe_controller_->SetEstimatedBitrate(500);
|
|
|
|
|
testing::Mock::VerifyAndClearExpectations(&pacer_);
|
|
|
|
|
|
2017-01-04 07:05:25 -08:00
|
|
|
EXPECT_CALL(pacer_, CreateProbeCluster(_)).Times(1);
|
2016-11-28 13:11:13 -08:00
|
|
|
EXPECT_CALL(pacer_, GetApplicationLimitedRegionStartTime())
|
2017-11-16 10:56:55 +01:00
|
|
|
.WillRepeatedly(Return(start_time));
|
2016-11-28 13:11:13 -08:00
|
|
|
clock_.AdvanceTimeMilliseconds(1000);
|
|
|
|
|
probe_controller_->Process();
|
|
|
|
|
probe_controller_->SetEstimatedBitrate(500);
|
|
|
|
|
testing::Mock::VerifyAndClearExpectations(&pacer_);
|
|
|
|
|
}
|
|
|
|
|
|
2017-05-04 08:35:52 -07:00
|
|
|
TEST_F(ProbeControllerTest, PeriodicProbingAfterReset) {
|
|
|
|
|
testing::StrictMock<MockPacedSender> local_pacer;
|
|
|
|
|
probe_controller_.reset(new ProbeController(&local_pacer, &clock_));
|
|
|
|
|
int64_t alr_start_time = clock_.TimeInMilliseconds();
|
|
|
|
|
EXPECT_CALL(local_pacer, GetApplicationLimitedRegionStartTime())
|
2017-11-16 10:56:55 +01:00
|
|
|
.WillRepeatedly(Return(alr_start_time));
|
2017-05-04 08:35:52 -07:00
|
|
|
|
|
|
|
|
EXPECT_CALL(local_pacer, CreateProbeCluster(_)).Times(2);
|
|
|
|
|
probe_controller_->EnablePeriodicAlrProbing(true);
|
|
|
|
|
probe_controller_->SetBitrates(kMinBitrateBps, kStartBitrateBps,
|
|
|
|
|
kMaxBitrateBps);
|
|
|
|
|
probe_controller_->Reset();
|
|
|
|
|
|
|
|
|
|
clock_.AdvanceTimeMilliseconds(10000);
|
|
|
|
|
probe_controller_->Process();
|
|
|
|
|
|
|
|
|
|
EXPECT_CALL(local_pacer, CreateProbeCluster(_)).Times(2);
|
|
|
|
|
probe_controller_->SetBitrates(kMinBitrateBps, kStartBitrateBps,
|
|
|
|
|
kMaxBitrateBps);
|
|
|
|
|
|
|
|
|
|
// Make sure we use |kStartBitrateBps| as the estimated bitrate
|
|
|
|
|
// until SetEstimatedBitrate is called with an updated estimate.
|
|
|
|
|
clock_.AdvanceTimeMilliseconds(10000);
|
|
|
|
|
EXPECT_CALL(local_pacer, CreateProbeCluster(kStartBitrateBps*2));
|
|
|
|
|
probe_controller_->Process();
|
|
|
|
|
}
|
|
|
|
|
|
2016-12-15 10:42:09 -08:00
|
|
|
TEST_F(ProbeControllerTest, TestExponentialProbingOverflow) {
|
|
|
|
|
const int64_t kMbpsMultiplier = 1000000;
|
|
|
|
|
probe_controller_->SetBitrates(kMinBitrateBps, 10 * kMbpsMultiplier,
|
|
|
|
|
100 * kMbpsMultiplier);
|
|
|
|
|
|
|
|
|
|
// Verify that probe bitrate is capped at the specified max bitrate
|
2017-01-04 07:05:25 -08:00
|
|
|
EXPECT_CALL(pacer_, CreateProbeCluster(100 * kMbpsMultiplier));
|
2016-12-15 10:42:09 -08:00
|
|
|
probe_controller_->SetEstimatedBitrate(60 * kMbpsMultiplier);
|
|
|
|
|
testing::Mock::VerifyAndClearExpectations(&pacer_);
|
|
|
|
|
|
|
|
|
|
// Verify that repeated probes aren't sent.
|
2017-01-04 07:05:25 -08:00
|
|
|
EXPECT_CALL(pacer_, CreateProbeCluster(_)).Times(0);
|
2016-12-15 10:42:09 -08:00
|
|
|
probe_controller_->SetEstimatedBitrate(100 * kMbpsMultiplier);
|
|
|
|
|
}
|
|
|
|
|
|
2016-09-12 12:28:54 -07:00
|
|
|
} // namespace test
|
|
|
|
|
} // namespace webrtc
|