| 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" |
| (...skipping 27 matching lines...) Expand all Loading... |
| 38 receiver_(new TcpReceiver()), | 38 receiver_(new TcpReceiver()), |
| 39 sequence_number_(1), | 39 sequence_number_(1), |
| 40 acked_sequence_number_(0) { | 40 acked_sequence_number_(0) { |
| 41 } | 41 } |
| 42 | 42 |
| 43 void SendAvailableCongestionWindow() { | 43 void SendAvailableCongestionWindow() { |
| 44 QuicByteCount bytes_to_send = sender_->AvailableCongestionWindow(); | 44 QuicByteCount bytes_to_send = sender_->AvailableCongestionWindow(); |
| 45 while (bytes_to_send > 0) { | 45 while (bytes_to_send > 0) { |
| 46 QuicByteCount bytes_in_packet = std::min(kMaxPacketSize, bytes_to_send); | 46 QuicByteCount bytes_in_packet = std::min(kMaxPacketSize, bytes_to_send); |
| 47 sender_->SentPacket(clock_.Now(), sequence_number_++, bytes_in_packet, | 47 sender_->SentPacket(clock_.Now(), sequence_number_++, bytes_in_packet, |
| 48 NOT_RETRANSMISSION); | 48 NOT_RETRANSMISSION, HAS_RETRANSMITTABLE_DATA); |
| 49 bytes_to_send -= bytes_in_packet; | 49 bytes_to_send -= bytes_in_packet; |
| 50 if (bytes_to_send > 0) { | 50 if (bytes_to_send > 0) { |
| 51 EXPECT_TRUE(sender_->TimeUntilSend(clock_.Now(), NOT_RETRANSMISSION, | 51 EXPECT_TRUE(sender_->TimeUntilSend(clock_.Now(), NOT_RETRANSMISSION, |
| 52 HAS_RETRANSMITTABLE_DATA, NOT_HANDSHAKE).IsZero()); | 52 HAS_RETRANSMITTABLE_DATA, NOT_HANDSHAKE).IsZero()); |
| 53 } | 53 } |
| 54 } | 54 } |
| 55 } | 55 } |
| 56 // Normal is that TCP acks every other segment. | 56 // Normal is that TCP acks every other segment. |
| 57 void AckNPackets(int n) { | 57 void AckNPackets(int n) { |
| 58 for (int i = 0; i < n; ++i) { | 58 for (int i = 0; i < n; ++i) { |
| (...skipping 286 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 345 // Send our full congestion window. | 345 // Send our full congestion window. |
| 346 SendAvailableCongestionWindow(); | 346 SendAvailableCongestionWindow(); |
| 347 AckNPackets(2); | 347 AckNPackets(2); |
| 348 } | 348 } |
| 349 | 349 |
| 350 QuicByteCount expected_congestion_window = | 350 QuicByteCount expected_congestion_window = |
| 351 kMaxCongestionWindowTCP * kMaxPacketSize; | 351 kMaxCongestionWindowTCP * kMaxPacketSize; |
| 352 EXPECT_EQ(expected_congestion_window, sender_->CongestionWindow()); | 352 EXPECT_EQ(expected_congestion_window, sender_->CongestionWindow()); |
| 353 } | 353 } |
| 354 | 354 |
| 355 TEST_F(TcpCubicSenderTest, CongestionWindowNotAffectedByAcks) { |
| 356 QuicByteCount congestion_window = sender_->AvailableCongestionWindow(); |
| 357 |
| 358 // Send a packet with no retransmittable data, and ensure that the congestion |
| 359 // window doesn't change. |
| 360 QuicByteCount bytes_in_packet = std::min(kMaxPacketSize, congestion_window); |
| 361 sender_->SentPacket(clock_.Now(), sequence_number_++, bytes_in_packet, |
| 362 NOT_RETRANSMISSION, NO_RETRANSMITTABLE_DATA); |
| 363 EXPECT_EQ(congestion_window, sender_->AvailableCongestionWindow()); |
| 364 |
| 365 // Send a data packet with retransmittable data, and ensure that the |
| 366 // congestion window has shrunk. |
| 367 sender_->SentPacket(clock_.Now(), sequence_number_++, bytes_in_packet, |
| 368 NOT_RETRANSMISSION, HAS_RETRANSMITTABLE_DATA); |
| 369 EXPECT_GT(congestion_window, sender_->AvailableCongestionWindow()); |
| 370 } |
| 371 |
| 355 } // namespace test | 372 } // namespace test |
| 356 } // namespace net | 373 } // namespace net |
| OLD | NEW |