| 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" |
| 11 #include "net/quic/congestion_control/tcp_receiver.h" | 11 #include "net/quic/congestion_control/tcp_receiver.h" |
| 12 #include "net/quic/crypto/crypto_protocol.h" | 12 #include "net/quic/crypto/crypto_protocol.h" |
| 13 #include "net/quic/quic_utils.h" | 13 #include "net/quic/quic_utils.h" |
| 14 #include "net/quic/test_tools/mock_clock.h" | 14 #include "net/quic/test_tools/mock_clock.h" |
| 15 #include "net/quic/test_tools/quic_config_peer.h" | 15 #include "net/quic/test_tools/quic_config_peer.h" |
| 16 #include "testing/gtest/include/gtest/gtest.h" | 16 #include "testing/gtest/include/gtest/gtest.h" |
| 17 | 17 |
| 18 using std::make_pair; | 18 using std::make_pair; |
| 19 using std::min; | 19 using std::min; |
| 20 | 20 |
| 21 namespace net { | 21 namespace net { |
| 22 namespace test { | 22 namespace test { |
| 23 | 23 |
| 24 const uint32 kDefaultWindowTCP = 10 * kDefaultTCPMSS; | 24 const int64 kInitialCongestionWindow = 10; |
| 25 const uint32 kDefaultWindowTCP = kInitialCongestionWindow * kDefaultTCPMSS; |
| 25 | 26 |
| 26 // TODO(ianswett): Remove 10000 once b/10075719 is fixed. | 27 // TODO(ianswett): Remove 10000 once b/10075719 is fixed. |
| 27 const QuicTcpCongestionWindow kDefaultMaxCongestionWindowTCP = 10000; | 28 const QuicTcpCongestionWindow kDefaultMaxCongestionWindowTCP = 10000; |
| 28 | 29 |
| 29 class TcpCubicSenderPeer : public TcpCubicSender { | 30 class TcpCubicSenderPeer : public TcpCubicSender { |
| 30 public: | 31 public: |
| 31 TcpCubicSenderPeer(const QuicClock* clock, | 32 TcpCubicSenderPeer(const QuicClock* clock, |
| 32 bool reno, | 33 bool reno, |
| 33 QuicTcpCongestionWindow max_tcp_congestion_window) | 34 QuicTcpCongestionWindow max_tcp_congestion_window) |
| 34 : TcpCubicSender( | 35 : TcpCubicSender( |
| (...skipping 257 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 292 AckNPackets(1); | 293 AckNPackets(1); |
| 293 expected_send_window += kDefaultTCPMSS; | 294 expected_send_window += kDefaultTCPMSS; |
| 294 EXPECT_EQ(expected_send_window, sender_->GetCongestionWindow()); | 295 EXPECT_EQ(expected_send_window, sender_->GetCongestionWindow()); |
| 295 | 296 |
| 296 // Now RTO and ensure slow start gets reset. | 297 // Now RTO and ensure slow start gets reset. |
| 297 EXPECT_TRUE(sender_->hybrid_slow_start().started()); | 298 EXPECT_TRUE(sender_->hybrid_slow_start().started()); |
| 298 sender_->OnRetransmissionTimeout(true); | 299 sender_->OnRetransmissionTimeout(true); |
| 299 EXPECT_FALSE(sender_->hybrid_slow_start().started()); | 300 EXPECT_FALSE(sender_->hybrid_slow_start().started()); |
| 300 } | 301 } |
| 301 | 302 |
| 303 TEST_F(TcpCubicSenderTest, NoPRRWhenLessThanOnePacketInFlight) { |
| 304 SendAvailableSendWindow(); |
| 305 LoseNPackets(kInitialCongestionWindow - 1); |
| 306 AckNPackets(1); |
| 307 // PRR will allow 2 packets for every ack during recovery. |
| 308 EXPECT_EQ(2, SendAvailableSendWindow()); |
| 309 // Simulate abandoning all packets by supplying a bytes_in_flight of 0. |
| 310 // PRR should now allow a packet to be sent, even though prr's state |
| 311 // variables believe it has sent enough packets. |
| 312 EXPECT_EQ(QuicTime::Delta::Zero(), |
| 313 sender_->TimeUntilSend(clock_.Now(), 0, HAS_RETRANSMITTABLE_DATA)); |
| 314 } |
| 315 |
| 302 TEST_F(TcpCubicSenderTest, SlowStartPacketLossPRR) { | 316 TEST_F(TcpCubicSenderTest, SlowStartPacketLossPRR) { |
| 303 // Test based on the first example in RFC6937. | 317 // Test based on the first example in RFC6937. |
| 304 // Ack 10 packets in 5 acks to raise the CWND to 20, as in the example. | 318 // Ack 10 packets in 5 acks to raise the CWND to 20, as in the example. |
| 305 const int kNumberOfAcks = 5; | 319 const int kNumberOfAcks = 5; |
| 306 for (int i = 0; i < kNumberOfAcks; ++i) { | 320 for (int i = 0; i < kNumberOfAcks; ++i) { |
| 307 // Send our full send window. | 321 // Send our full send window. |
| 308 SendAvailableSendWindow(); | 322 SendAvailableSendWindow(); |
| 309 AckNPackets(2); | 323 AckNPackets(2); |
| 310 } | 324 } |
| 311 SendAvailableSendWindow(); | 325 SendAvailableSendWindow(); |
| (...skipping 303 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 615 } | 629 } |
| 616 | 630 |
| 617 // Next ack should cause congestion window to grow by 1MSS. | 631 // Next ack should cause congestion window to grow by 1MSS. |
| 618 AckNPackets(2); | 632 AckNPackets(2); |
| 619 expected_send_window += kDefaultTCPMSS; | 633 expected_send_window += kDefaultTCPMSS; |
| 620 EXPECT_EQ(expected_send_window, sender_->GetCongestionWindow()); | 634 EXPECT_EQ(expected_send_window, sender_->GetCongestionWindow()); |
| 621 } | 635 } |
| 622 | 636 |
| 623 } // namespace test | 637 } // namespace test |
| 624 } // namespace net | 638 } // namespace net |
| OLD | NEW |