Home | History | Annotate | Download | only in congestion_control
      1 // Copyright (c) 2013 The Chromium Authors. All rights reserved.
      2 // Use of this source code is governed by a BSD-style license that can be
      3 // found in the LICENSE file.
      4 
      5 #include "base/basictypes.h"
      6 #include "base/logging.h"
      7 #include "base/memory/scoped_ptr.h"
      8 #include "net/quic/congestion_control/inter_arrival_probe.h"
      9 #include "testing/gtest/include/gtest/gtest.h"
     10 
     11 namespace net {
     12 namespace test {
     13 
     14 class InterArrivalProbeTest : public ::testing::Test {
     15  protected:
     16   InterArrivalProbeTest() : start_(QuicTime::Zero()) {
     17   }
     18 
     19   InterArrivalProbe probe_;
     20   QuicTime start_;
     21 };
     22 
     23 TEST_F(InterArrivalProbeTest, CongestionWindow) {
     24   for (size_t i = 0; i < 10; i++) {
     25     probe_.OnSentPacket(kMaxPacketSize);
     26     EXPECT_EQ((9 - i) * kMaxPacketSize, probe_.GetAvailableCongestionWindow());
     27   }
     28   probe_.OnAcknowledgedPacket(kMaxPacketSize);
     29   EXPECT_EQ(kMaxPacketSize, probe_.GetAvailableCongestionWindow());
     30 
     31   probe_.OnSentPacket(kMaxPacketSize);
     32   EXPECT_EQ(0u, probe_.GetAvailableCongestionWindow());
     33 }
     34 
     35 TEST_F(InterArrivalProbeTest, Estimate) {
     36   QuicPacketSequenceNumber sequence_number = 1;
     37   QuicByteCount bytes_sent = kMaxPacketSize;
     38   QuicTime time_received = start_.Add(QuicTime::Delta::FromMilliseconds(10));
     39   QuicTime time_sent = start_.Add(QuicTime::Delta::FromMilliseconds(1));
     40   QuicBandwidth available_channel_estimate = QuicBandwidth::Zero();
     41 
     42   for (size_t i = 0; i < 10; ++i) {
     43     EXPECT_FALSE(probe_.GetEstimate(&available_channel_estimate));
     44 
     45     probe_.OnIncomingFeedback(sequence_number++,
     46                               bytes_sent,
     47                               time_sent,
     48                               time_received);
     49     time_sent = time_sent.Add(QuicTime::Delta::FromMilliseconds(1));
     50     time_received = time_received.Add(QuicTime::Delta::FromMilliseconds(10));
     51   }
     52   EXPECT_TRUE(probe_.GetEstimate(&available_channel_estimate));
     53   EXPECT_EQ(kMaxPacketSize * 100,
     54             static_cast<uint64>(available_channel_estimate.ToBytesPerSecond()));
     55 }
     56 
     57 TEST_F(InterArrivalProbeTest, EstimateWithLoss) {
     58   QuicPacketSequenceNumber sequence_number = 1;
     59   QuicByteCount bytes_sent = kMaxPacketSize;
     60   QuicTime time_received = start_.Add(QuicTime::Delta::FromMilliseconds(10));
     61   QuicTime time_sent = start_.Add(QuicTime::Delta::FromMilliseconds(1));
     62   QuicBandwidth available_channel_estimate = QuicBandwidth::Zero();
     63 
     64   for (size_t i = 0; i < 6; ++i) {
     65     EXPECT_FALSE(probe_.GetEstimate(&available_channel_estimate));
     66 
     67     probe_.OnIncomingFeedback(sequence_number,
     68                               bytes_sent,
     69                               time_sent,
     70                               time_received);
     71     sequence_number += 2;
     72     time_sent = time_sent.Add(QuicTime::Delta::FromMilliseconds(1));
     73     time_received = time_received.Add(QuicTime::Delta::FromMilliseconds(10));
     74   }
     75   EXPECT_TRUE(probe_.GetEstimate(&available_channel_estimate));
     76   EXPECT_EQ(kMaxPacketSize * 50,
     77             static_cast<uint64>(available_channel_estimate.ToBytesPerSecond()));
     78 }
     79 
     80 }  // namespace test
     81 }  // namespace net
     82