| 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 <algorithm> | 5 #include <algorithm> |
| 6 | 6 |
| 7 #include "base/logging.h" | 7 #include "base/logging.h" |
| 8 #include "base/memory/scoped_ptr.h" | 8 #include "base/memory/scoped_ptr.h" |
| 9 #include "net/quic/congestion_control/rtt_stats.h" | 9 #include "net/quic/congestion_control/rtt_stats.h" |
| 10 #include "net/quic/congestion_control/tcp_cubic_sender.h" | 10 #include "net/quic/congestion_control/tcp_cubic_sender.h" |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 43 QuicPacketCount slowstart_threshold() { | 43 QuicPacketCount slowstart_threshold() { |
| 44 return slowstart_threshold_; | 44 return slowstart_threshold_; |
| 45 } | 45 } |
| 46 | 46 |
| 47 const HybridSlowStart& hybrid_slow_start() const { | 47 const HybridSlowStart& hybrid_slow_start() const { |
| 48 return hybrid_slow_start_; | 48 return hybrid_slow_start_; |
| 49 } | 49 } |
| 50 | 50 |
| 51 RttStats rtt_stats_; | 51 RttStats rtt_stats_; |
| 52 QuicConnectionStats stats_; | 52 QuicConnectionStats stats_; |
| 53 | |
| 54 using TcpCubicSender::SendWindow; | |
| 55 }; | 53 }; |
| 56 | 54 |
| 57 class TcpCubicSenderTest : public ::testing::Test { | 55 class TcpCubicSenderTest : public ::testing::Test { |
| 58 protected: | 56 protected: |
| 59 TcpCubicSenderTest() | 57 TcpCubicSenderTest() |
| 60 : one_ms_(QuicTime::Delta::FromMilliseconds(1)), | 58 : one_ms_(QuicTime::Delta::FromMilliseconds(1)), |
| 61 sender_(new TcpCubicSenderPeer(&clock_, true, | 59 sender_(new TcpCubicSenderPeer(&clock_, true, |
| 62 kDefaultMaxCongestionWindowTCP)), | 60 kDefaultMaxCongestionWindowTCP)), |
| 63 receiver_(new TcpReceiver()), | 61 receiver_(new TcpReceiver()), |
| 64 sequence_number_(1), | 62 sequence_number_(1), |
| (...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 165 HAS_RETRANSMITTABLE_DATA).IsZero()); | 163 HAS_RETRANSMITTABLE_DATA).IsZero()); |
| 166 // Make sure we can send. | 164 // Make sure we can send. |
| 167 EXPECT_TRUE(sender_->TimeUntilSend(clock_.Now(), | 165 EXPECT_TRUE(sender_->TimeUntilSend(clock_.Now(), |
| 168 0, | 166 0, |
| 169 HAS_RETRANSMITTABLE_DATA).IsZero()); | 167 HAS_RETRANSMITTABLE_DATA).IsZero()); |
| 170 | 168 |
| 171 SendAvailableSendWindow(); | 169 SendAvailableSendWindow(); |
| 172 for (int i = 0; i < kNumberOfAcks; ++i) { | 170 for (int i = 0; i < kNumberOfAcks; ++i) { |
| 173 AckNPackets(2); | 171 AckNPackets(2); |
| 174 } | 172 } |
| 175 QuicByteCount bytes_to_send = sender_->SendWindow(); | 173 QuicByteCount bytes_to_send = sender_->GetCongestionWindow(); |
| 176 // It's expected 2 acks will arrive when the bytes_in_flight are greater than | 174 // It's expected 2 acks will arrive when the bytes_in_flight are greater than |
| 177 // half the CWND. | 175 // half the CWND. |
| 178 EXPECT_EQ(kDefaultWindowTCP + kDefaultTCPMSS * 2 * 2, | 176 EXPECT_EQ(kDefaultWindowTCP + kDefaultTCPMSS * 2 * 2, |
| 179 bytes_to_send); | 177 bytes_to_send); |
| 180 } | 178 } |
| 181 | 179 |
| 182 TEST_F(TcpCubicSenderTest, ExponentialSlowStart) { | 180 TEST_F(TcpCubicSenderTest, ExponentialSlowStart) { |
| 183 const int kNumberOfAcks = 20; | 181 const int kNumberOfAcks = 20; |
| 184 // At startup make sure we can send. | 182 // At startup make sure we can send. |
| 185 EXPECT_TRUE(sender_->TimeUntilSend(clock_.Now(), | 183 EXPECT_TRUE(sender_->TimeUntilSend(clock_.Now(), |
| 186 0, | 184 0, |
| 187 HAS_RETRANSMITTABLE_DATA).IsZero()); | 185 HAS_RETRANSMITTABLE_DATA).IsZero()); |
| 188 // Make sure we can send. | 186 // Make sure we can send. |
| 189 EXPECT_TRUE(sender_->TimeUntilSend(clock_.Now(), | 187 EXPECT_TRUE(sender_->TimeUntilSend(clock_.Now(), |
| 190 0, | 188 0, |
| 191 HAS_RETRANSMITTABLE_DATA).IsZero()); | 189 HAS_RETRANSMITTABLE_DATA).IsZero()); |
| 192 | 190 |
| 193 for (int i = 0; i < kNumberOfAcks; ++i) { | 191 for (int i = 0; i < kNumberOfAcks; ++i) { |
| 194 // Send our full send window. | 192 // Send our full send window. |
| 195 SendAvailableSendWindow(); | 193 SendAvailableSendWindow(); |
| 196 AckNPackets(2); | 194 AckNPackets(2); |
| 197 } | 195 } |
| 198 QuicByteCount bytes_to_send = sender_->SendWindow(); | 196 QuicByteCount bytes_to_send = sender_->GetCongestionWindow(); |
| 199 EXPECT_EQ(kDefaultWindowTCP + kDefaultTCPMSS * 2 * kNumberOfAcks, | 197 EXPECT_EQ(kDefaultWindowTCP + kDefaultTCPMSS * 2 * kNumberOfAcks, |
| 200 bytes_to_send); | 198 bytes_to_send); |
| 201 } | 199 } |
| 202 | 200 |
| 203 TEST_F(TcpCubicSenderTest, SlowStartAckTrain) { | 201 TEST_F(TcpCubicSenderTest, SlowStartAckTrain) { |
| 204 sender_->SetNumEmulatedConnections(1); | 202 sender_->SetNumEmulatedConnections(1); |
| 205 EXPECT_EQ(kDefaultMaxCongestionWindowTCP * kDefaultTCPMSS, | 203 EXPECT_EQ(kDefaultMaxCongestionWindowTCP * kDefaultTCPMSS, |
| 206 sender_->GetSlowStartThreshold()); | 204 sender_->GetSlowStartThreshold()); |
| 207 | 205 |
| 208 // Make sure that we fall out of slow start when we send ACK train longer | 206 // Make sure that we fall out of slow start when we send ACK train longer |
| (...skipping 212 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 421 EXPECT_EQ(expected_send_window, sender_->GetCongestionWindow()); | 419 EXPECT_EQ(expected_send_window, sender_->GetCongestionWindow()); |
| 422 | 420 |
| 423 // Exit recovery and return to sending at the new rate. | 421 // Exit recovery and return to sending at the new rate. |
| 424 for (int i = 0; i < kNumberOfAcks; ++i) { | 422 for (int i = 0; i < kNumberOfAcks; ++i) { |
| 425 AckNPackets(1); | 423 AckNPackets(1); |
| 426 EXPECT_EQ(1, SendAvailableSendWindow()); | 424 EXPECT_EQ(1, SendAvailableSendWindow()); |
| 427 } | 425 } |
| 428 } | 426 } |
| 429 | 427 |
| 430 TEST_F(TcpCubicSenderTest, RTOCongestionWindowAndRevert) { | 428 TEST_F(TcpCubicSenderTest, RTOCongestionWindowAndRevert) { |
| 431 EXPECT_EQ(kDefaultWindowTCP, sender_->SendWindow()); | 429 EXPECT_EQ(kDefaultWindowTCP, sender_->GetCongestionWindow()); |
| 432 EXPECT_EQ(10000u, sender_->slowstart_threshold()); | 430 EXPECT_EQ(10000u, sender_->slowstart_threshold()); |
| 433 | 431 |
| 434 // Expect the window to decrease to the minimum once the RTO fires | 432 // Expect the window to decrease to the minimum once the RTO fires |
| 435 // and slow start threshold to be set to 1/2 of the CWND. | 433 // and slow start threshold to be set to 1/2 of the CWND. |
| 436 sender_->OnRetransmissionTimeout(true); | 434 sender_->OnRetransmissionTimeout(true); |
| 437 EXPECT_EQ(2 * kDefaultTCPMSS, sender_->SendWindow()); | 435 EXPECT_EQ(2 * kDefaultTCPMSS, sender_->GetCongestionWindow()); |
| 438 EXPECT_EQ(5u, sender_->slowstart_threshold()); | 436 EXPECT_EQ(5u, sender_->slowstart_threshold()); |
| 439 | 437 |
| 440 // Now repair the RTO and ensure the slowstart threshold reverts. | 438 // Now repair the RTO and ensure the slowstart threshold reverts. |
| 441 sender_->RevertRetransmissionTimeout(); | 439 sender_->RevertRetransmissionTimeout(); |
| 442 EXPECT_EQ(kDefaultWindowTCP, sender_->SendWindow()); | 440 EXPECT_EQ(kDefaultWindowTCP, sender_->GetCongestionWindow()); |
| 443 EXPECT_EQ(10000u, sender_->slowstart_threshold()); | 441 EXPECT_EQ(10000u, sender_->slowstart_threshold()); |
| 444 } | 442 } |
| 445 | 443 |
| 446 TEST_F(TcpCubicSenderTest, RTOCongestionWindowNoRetransmission) { | 444 TEST_F(TcpCubicSenderTest, RTOCongestionWindowNoRetransmission) { |
| 447 EXPECT_EQ(kDefaultWindowTCP, sender_->SendWindow()); | 445 EXPECT_EQ(kDefaultWindowTCP, sender_->GetCongestionWindow()); |
| 448 | 446 |
| 449 // Expect the window to remain unchanged if the RTO fires but no | 447 // Expect the window to remain unchanged if the RTO fires but no |
| 450 // packets are retransmitted. | 448 // packets are retransmitted. |
| 451 sender_->OnRetransmissionTimeout(false); | 449 sender_->OnRetransmissionTimeout(false); |
| 452 EXPECT_EQ(kDefaultWindowTCP, sender_->SendWindow()); | 450 EXPECT_EQ(kDefaultWindowTCP, sender_->GetCongestionWindow()); |
| 453 } | 451 } |
| 454 | 452 |
| 455 TEST_F(TcpCubicSenderTest, RetransmissionDelay) { | 453 TEST_F(TcpCubicSenderTest, RetransmissionDelay) { |
| 456 const int64 kRttMs = 10; | 454 const int64 kRttMs = 10; |
| 457 const int64 kDeviationMs = 3; | 455 const int64 kDeviationMs = 3; |
| 458 EXPECT_EQ(QuicTime::Delta::Zero(), sender_->RetransmissionDelay()); | 456 EXPECT_EQ(QuicTime::Delta::Zero(), sender_->RetransmissionDelay()); |
| 459 | 457 |
| 460 sender_->rtt_stats_.UpdateRtt(QuicTime::Delta::FromMilliseconds(kRttMs), | 458 sender_->rtt_stats_.UpdateRtt(QuicTime::Delta::FromMilliseconds(kRttMs), |
| 461 QuicTime::Delta::Zero(), clock_.Now()); | 459 QuicTime::Delta::Zero(), clock_.Now()); |
| 462 | 460 |
| (...skipping 227 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 690 } | 688 } |
| 691 | 689 |
| 692 // Next ack should cause congestion window to grow by 1MSS. | 690 // Next ack should cause congestion window to grow by 1MSS. |
| 693 AckNPackets(2); | 691 AckNPackets(2); |
| 694 expected_send_window += kDefaultTCPMSS; | 692 expected_send_window += kDefaultTCPMSS; |
| 695 EXPECT_EQ(expected_send_window, sender_->GetCongestionWindow()); | 693 EXPECT_EQ(expected_send_window, sender_->GetCongestionWindow()); |
| 696 } | 694 } |
| 697 | 695 |
| 698 } // namespace test | 696 } // namespace test |
| 699 } // namespace net | 697 } // namespace net |
| OLD | NEW |