| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "base/logging.h" | 5 #include "base/logging.h" |
| 6 #include "base/memory/scoped_ptr.h" | 6 #include "base/memory/scoped_ptr.h" |
| 7 #include "net/quic/congestion_control/tcp_cubic_sender.h" | 7 #include "net/quic/congestion_control/tcp_cubic_sender.h" |
| 8 #include "net/quic/congestion_control/tcp_receiver.h" | 8 #include "net/quic/congestion_control/tcp_receiver.h" |
| 9 #include "net/quic/test_tools/mock_clock.h" | 9 #include "net/quic/test_tools/mock_clock.h" |
| 10 #include "testing/gtest/include/gtest/gtest.h" | 10 #include "testing/gtest/include/gtest/gtest.h" |
| 11 | 11 |
| 12 namespace net { | 12 namespace net { |
| 13 namespace test { | 13 namespace test { |
| 14 | 14 |
| 15 const uint32 kDefaultWindowTCP = 10 * kMaxPacketSize; | 15 const uint32 kDefaultWindowTCP = 10 * kMaxPacketSize; |
| 16 const QuicByteCount kNoNBytesInFlight = 0; | 16 const QuicByteCount kNoNBytesInFlight = 0; |
| 17 | 17 |
| 18 class TcpCubicSenderPeer : public TcpCubicSender { | 18 class TcpCubicSenderPeer : public TcpCubicSender { |
| 19 public: | 19 public: |
| 20 explicit TcpCubicSenderPeer(const QuicClock* clock, bool reno) | 20 TcpCubicSenderPeer(const QuicClock* clock, bool reno) |
| 21 : TcpCubicSender(clock, reno) { | 21 : TcpCubicSender(clock, reno) { |
| 22 } | 22 } |
| 23 using TcpCubicSender::AvailableCongestionWindow; | 23 using TcpCubicSender::AvailableCongestionWindow; |
| 24 using TcpCubicSender::CongestionWindow; | 24 using TcpCubicSender::CongestionWindow; |
| 25 using TcpCubicSender::AckAccounting; |
| 25 }; | 26 }; |
| 26 | 27 |
| 27 class TcpCubicSenderTest : public ::testing::Test { | 28 class TcpCubicSenderTest : public ::testing::Test { |
| 28 protected: | 29 protected: |
| 29 TcpCubicSenderTest() | 30 TcpCubicSenderTest() |
| 30 : rtt_(QuicTime::Delta::FromMilliseconds(60)), | 31 : rtt_(QuicTime::Delta::FromMilliseconds(60)), |
| 31 one_ms_(QuicTime::Delta::FromMilliseconds(1)), | 32 one_ms_(QuicTime::Delta::FromMilliseconds(1)), |
| 32 sender_(new TcpCubicSenderPeer(&clock_, true)), | 33 sender_(new TcpCubicSenderPeer(&clock_, true)), |
| 33 receiver_(new TcpReceiver()), | 34 receiver_(new TcpReceiver()), |
| 34 sequence_number_(1), | 35 sequence_number_(1), |
| (...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 214 SendAvailableCongestionWindow(); | 215 SendAvailableCongestionWindow(); |
| 215 AckNPackets(1); | 216 AckNPackets(1); |
| 216 EXPECT_EQ(expected_congestion_window, sender_->CongestionWindow()); | 217 EXPECT_EQ(expected_congestion_window, sender_->CongestionWindow()); |
| 217 } | 218 } |
| 218 SendAvailableCongestionWindow(); | 219 SendAvailableCongestionWindow(); |
| 219 AckNPackets(1); | 220 AckNPackets(1); |
| 220 expected_congestion_window += kMaxPacketSize; | 221 expected_congestion_window += kMaxPacketSize; |
| 221 EXPECT_EQ(expected_congestion_window, sender_->CongestionWindow()); | 222 EXPECT_EQ(expected_congestion_window, sender_->CongestionWindow()); |
| 222 } | 223 } |
| 223 | 224 |
| 225 TEST_F(TcpCubicSenderTest, RetransmissionDelay) { |
| 226 const int64 kRttMs = 10; |
| 227 const int64 kDeviationMs = 3; |
| 228 EXPECT_EQ(QuicTime::Delta::Zero(), sender_->RetransmissionDelay()); |
| 229 |
| 230 sender_->AckAccounting(QuicTime::Delta::FromMilliseconds(kRttMs)); |
| 231 |
| 232 // Initial value is to set the median deviation to half of the initial |
| 233 // rtt, the median in then multiplied by a factor of 4 and finaly the |
| 234 // smoothed rtt is added which is the inital rtt. |
| 235 QuicTime::Delta expected_delay = |
| 236 QuicTime::Delta::FromMilliseconds(kRttMs + kRttMs / 2 * 4); |
| 237 EXPECT_EQ(expected_delay, sender_->RetransmissionDelay()); |
| 238 |
| 239 for (int i = 0; i < 100; ++i) { |
| 240 // Run to make sure that we converge. |
| 241 sender_->AckAccounting( |
| 242 QuicTime::Delta::FromMilliseconds(kRttMs + kDeviationMs)); |
| 243 sender_->AckAccounting( |
| 244 QuicTime::Delta::FromMilliseconds(kRttMs - kDeviationMs)); |
| 245 } |
| 246 expected_delay = QuicTime::Delta::FromMilliseconds(kRttMs + kDeviationMs * 4); |
| 247 |
| 248 EXPECT_NEAR(kRttMs, sender_->SmoothedRtt().ToMilliseconds(), 1); |
| 249 EXPECT_NEAR(expected_delay.ToMilliseconds(), |
| 250 sender_->RetransmissionDelay().ToMilliseconds(), |
| 251 1); |
| 252 } |
| 224 } // namespace test | 253 } // namespace test |
| 225 } // namespace net | 254 } // namespace net |
| OLD | NEW |