This source file includes following definitions.
- SetUp
- TEST_F
- TEST_F
- TEST_F
- TEST_F
- TEST_F
#include "base/logging.h"
#include "net/quic/congestion_control/channel_estimator.h"
#include "net/quic/test_tools/mock_clock.h"
#include "testing/gtest/include/gtest/gtest.h"
namespace net {
namespace test {
class ChannelEstimatorTest : public ::testing::Test {
protected:
virtual void SetUp() {
srand(1234);
packet_size_ = 1200;
sequence_number_ = 1;
}
QuicPacketSequenceNumber sequence_number_;
QuicByteCount packet_size_;
MockClock send_clock_;
MockClock receive_clock_;
ChannelEstimator channel_estimator_;
};
TEST_F(ChannelEstimatorTest, SimpleNonDetect) {
QuicTime::Delta delta = QuicTime::Delta::FromMilliseconds(10);
for (int i = 0; i < 1000; ++i) {
QuicTime send_time = send_clock_.ApproximateNow();
QuicTime receive_time = receive_clock_.ApproximateNow();
channel_estimator_.OnAcknowledgedPacket(sequence_number_++,
packet_size_,
send_time,
receive_time);
send_clock_.AdvanceTime(delta);
receive_clock_.AdvanceTime(delta);
}
QuicBandwidth estimate = QuicBandwidth::Zero();
EXPECT_EQ(kChannelEstimateUnknown,
channel_estimator_.GetChannelEstimate(&estimate));
EXPECT_TRUE(estimate.IsZero());
}
TEST_F(ChannelEstimatorTest, SimplePacketPairDetect) {
QuicTime::Delta received_delta = QuicTime::Delta::FromMilliseconds(5);
QuicTime::Delta send_delta = QuicTime::Delta::FromMilliseconds(10);
for (int i = 0; i < 100; ++i) {
receive_clock_.AdvanceTime(received_delta);
QuicTime receive_time = receive_clock_.ApproximateNow();
QuicTime send_time = send_clock_.ApproximateNow();
channel_estimator_.OnAcknowledgedPacket(sequence_number_++,
packet_size_,
send_time,
receive_time);
receive_clock_.AdvanceTime(received_delta);
receive_time = receive_clock_.ApproximateNow();
channel_estimator_.OnAcknowledgedPacket(sequence_number_++,
packet_size_,
send_time,
receive_time);
send_clock_.AdvanceTime(send_delta);
}
QuicBandwidth estimate = QuicBandwidth::Zero();
EXPECT_EQ(kChannelEstimateGood,
channel_estimator_.GetChannelEstimate(&estimate));
EXPECT_EQ(QuicBandwidth::FromBytesAndTimeDelta(packet_size_, received_delta),
estimate);
received_delta = QuicTime::Delta::FromMilliseconds(1);
for (int i = 0; i < 100; ++i) {
receive_clock_.AdvanceTime(received_delta);
QuicTime receive_time = receive_clock_.ApproximateNow();
QuicTime send_time = send_clock_.ApproximateNow();
channel_estimator_.OnAcknowledgedPacket(sequence_number_++,
packet_size_,
send_time,
receive_time);
receive_clock_.AdvanceTime(received_delta);
receive_time = receive_clock_.ApproximateNow();
channel_estimator_.OnAcknowledgedPacket(sequence_number_++,
packet_size_,
send_time,
receive_time);
send_clock_.AdvanceTime(send_delta);
}
EXPECT_EQ(kChannelEstimateGood,
channel_estimator_.GetChannelEstimate(&estimate));
EXPECT_EQ(QuicBandwidth::FromBytesAndTimeDelta(packet_size_, received_delta),
estimate);
}
TEST_F(ChannelEstimatorTest, SimpleFlatSlope) {
QuicTime::Delta initial_received_delta = QuicTime::Delta::FromMilliseconds(5);
QuicTime::Delta received_delta = initial_received_delta;
QuicTime::Delta send_delta = QuicTime::Delta::FromMilliseconds(10);
for (int i = 0; i < 100; ++i) {
receive_clock_.AdvanceTime(received_delta);
QuicTime receive_time = receive_clock_.ApproximateNow();
QuicTime send_time = send_clock_.ApproximateNow();
channel_estimator_.OnAcknowledgedPacket(sequence_number_++,
packet_size_,
send_time,
receive_time);
receive_clock_.AdvanceTime(received_delta);
receive_time = receive_clock_.ApproximateNow();
channel_estimator_.OnAcknowledgedPacket(sequence_number_++,
packet_size_,
send_time,
receive_time);
send_clock_.AdvanceTime(send_delta);
received_delta = received_delta.Add(QuicTime::Delta::FromMicroseconds(10));
}
QuicBandwidth estimate = QuicBandwidth::Zero();
EXPECT_EQ(kChannelEstimateGood,
channel_estimator_.GetChannelEstimate(&estimate));
QuicTime::Delta increased_received_delta =
received_delta.Subtract(initial_received_delta);
QuicTime::Delta mean_received_delta = initial_received_delta.Add(
QuicTime::Delta::FromMicroseconds(
increased_received_delta.ToMicroseconds() / 2));
EXPECT_EQ(QuicBandwidth::FromBytesAndTimeDelta(packet_size_,
mean_received_delta), estimate);
}
TEST_F(ChannelEstimatorTest, SimpleMediumSlope) {
QuicTime::Delta initial_received_delta = QuicTime::Delta::FromMilliseconds(5);
QuicTime::Delta received_delta = initial_received_delta;
QuicTime::Delta send_delta = QuicTime::Delta::FromMilliseconds(10);
for (int i = 0; i < 100; ++i) {
receive_clock_.AdvanceTime(received_delta);
QuicTime receive_time = receive_clock_.ApproximateNow();
QuicTime send_time = send_clock_.ApproximateNow();
channel_estimator_.OnAcknowledgedPacket(sequence_number_++,
packet_size_,
send_time,
receive_time);
receive_clock_.AdvanceTime(received_delta);
receive_time = receive_clock_.ApproximateNow();
channel_estimator_.OnAcknowledgedPacket(sequence_number_++,
packet_size_,
send_time,
receive_time);
send_clock_.AdvanceTime(send_delta);
received_delta = received_delta.Add(QuicTime::Delta::FromMicroseconds(50));
}
QuicBandwidth estimate = QuicBandwidth::Zero();
EXPECT_EQ(kChannelEstimateUncertain,
channel_estimator_.GetChannelEstimate(&estimate));
QuicTime::Delta increased_received_delta =
received_delta.Subtract(initial_received_delta);
QuicTime::Delta mean_received_delta = initial_received_delta.Add(
QuicTime::Delta::FromMicroseconds(
increased_received_delta.ToMicroseconds() / 2));
EXPECT_EQ(QuicBandwidth::FromBytesAndTimeDelta(packet_size_,
mean_received_delta), estimate);
}
TEST_F(ChannelEstimatorTest, SimpleSteepSlope) {
QuicTime::Delta initial_received_delta = QuicTime::Delta::FromMilliseconds(5);
QuicTime::Delta received_delta = initial_received_delta;
QuicTime::Delta send_delta = QuicTime::Delta::FromMilliseconds(10);
for (int i = 0; i < 100; ++i) {
receive_clock_.AdvanceTime(received_delta);
QuicTime receive_time = receive_clock_.ApproximateNow();
QuicTime send_time = send_clock_.ApproximateNow();
channel_estimator_.OnAcknowledgedPacket(sequence_number_++,
packet_size_,
send_time,
receive_time);
receive_clock_.AdvanceTime(received_delta);
receive_time = receive_clock_.ApproximateNow();
channel_estimator_.OnAcknowledgedPacket(sequence_number_++,
packet_size_,
send_time,
receive_time);
send_clock_.AdvanceTime(send_delta);
received_delta = received_delta.Add(QuicTime::Delta::FromMicroseconds(100));
}
QuicBandwidth estimate = QuicBandwidth::Zero();
EXPECT_EQ(kChannelEstimateUncertain,
channel_estimator_.GetChannelEstimate(&estimate));
QuicTime::Delta increased_received_delta =
received_delta.Subtract(initial_received_delta);
QuicTime::Delta mean_received_delta = initial_received_delta.Add(
QuicTime::Delta::FromMicroseconds(
increased_received_delta.ToMicroseconds() / 2));
EXPECT_EQ(QuicBandwidth::FromBytesAndTimeDelta(packet_size_,
mean_received_delta), estimate);
}
}
}