| OLD | NEW |
| 1 // Copyright (c) 2015 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2015 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 "net/quic/congestion_control/tcp_cubic_sender_bytes.h" | 5 #include "net/quic/congestion_control/tcp_cubic_sender_bytes.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 | 8 |
| 9 #include "base/logging.h" | 9 #include "base/logging.h" |
| 10 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 55 TcpCubicSenderBytesTest() | 55 TcpCubicSenderBytesTest() |
| 56 : one_ms_(QuicTime::Delta::FromMilliseconds(1)), | 56 : one_ms_(QuicTime::Delta::FromMilliseconds(1)), |
| 57 sender_(new TcpCubicSenderBytesPeer(&clock_, true)), | 57 sender_(new TcpCubicSenderBytesPeer(&clock_, true)), |
| 58 packet_number_(1), | 58 packet_number_(1), |
| 59 acked_packet_number_(0), | 59 acked_packet_number_(0), |
| 60 bytes_in_flight_(0) {} | 60 bytes_in_flight_(0) {} |
| 61 | 61 |
| 62 int SendAvailableSendWindow() { | 62 int SendAvailableSendWindow() { |
| 63 // Send as long as TimeUntilSend returns Zero. | 63 // Send as long as TimeUntilSend returns Zero. |
| 64 int packets_sent = 0; | 64 int packets_sent = 0; |
| 65 bool can_send = sender_ | 65 bool can_send = |
| 66 ->TimeUntilSend(clock_.Now(), bytes_in_flight_, | 66 sender_->TimeUntilSend(clock_.Now(), bytes_in_flight_).IsZero(); |
| 67 HAS_RETRANSMITTABLE_DATA) | |
| 68 .IsZero(); | |
| 69 while (can_send) { | 67 while (can_send) { |
| 70 sender_->OnPacketSent(clock_.Now(), bytes_in_flight_, packet_number_++, | 68 sender_->OnPacketSent(clock_.Now(), bytes_in_flight_, packet_number_++, |
| 71 kDefaultTCPMSS, HAS_RETRANSMITTABLE_DATA); | 69 kDefaultTCPMSS, HAS_RETRANSMITTABLE_DATA); |
| 72 ++packets_sent; | 70 ++packets_sent; |
| 73 bytes_in_flight_ += kDefaultTCPMSS; | 71 bytes_in_flight_ += kDefaultTCPMSS; |
| 74 can_send = sender_ | 72 can_send = |
| 75 ->TimeUntilSend(clock_.Now(), bytes_in_flight_, | 73 sender_->TimeUntilSend(clock_.Now(), bytes_in_flight_).IsZero(); |
| 76 HAS_RETRANSMITTABLE_DATA) | |
| 77 .IsZero(); | |
| 78 } | 74 } |
| 79 return packets_sent; | 75 return packets_sent; |
| 80 } | 76 } |
| 81 | 77 |
| 82 // Normal is that TCP acks every other segment. | 78 // Normal is that TCP acks every other segment. |
| 83 void AckNPackets(int n) { | 79 void AckNPackets(int n) { |
| 84 sender_->rtt_stats_.UpdateRtt(QuicTime::Delta::FromMilliseconds(60), | 80 sender_->rtt_stats_.UpdateRtt(QuicTime::Delta::FromMilliseconds(60), |
| 85 QuicTime::Delta::Zero(), clock_.Now()); | 81 QuicTime::Delta::Zero(), clock_.Now()); |
| 86 SendAlgorithmInterface::CongestionVector acked_packets; | 82 SendAlgorithmInterface::CongestionVector acked_packets; |
| 87 SendAlgorithmInterface::CongestionVector lost_packets; | 83 SendAlgorithmInterface::CongestionVector lost_packets; |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 124 scoped_ptr<TcpCubicSenderBytesPeer> sender_; | 120 scoped_ptr<TcpCubicSenderBytesPeer> sender_; |
| 125 QuicPacketNumber packet_number_; | 121 QuicPacketNumber packet_number_; |
| 126 QuicPacketNumber acked_packet_number_; | 122 QuicPacketNumber acked_packet_number_; |
| 127 QuicByteCount bytes_in_flight_; | 123 QuicByteCount bytes_in_flight_; |
| 128 }; | 124 }; |
| 129 | 125 |
| 130 TEST_F(TcpCubicSenderBytesTest, SimpleSender) { | 126 TEST_F(TcpCubicSenderBytesTest, SimpleSender) { |
| 131 // At startup make sure we are at the default. | 127 // At startup make sure we are at the default. |
| 132 EXPECT_EQ(kDefaultWindowTCP, sender_->GetCongestionWindow()); | 128 EXPECT_EQ(kDefaultWindowTCP, sender_->GetCongestionWindow()); |
| 133 // At startup make sure we can send. | 129 // At startup make sure we can send. |
| 134 EXPECT_TRUE(sender_->TimeUntilSend(clock_.Now(), 0, HAS_RETRANSMITTABLE_DATA) | 130 EXPECT_TRUE(sender_->TimeUntilSend(clock_.Now(), 0).IsZero()); |
| 135 .IsZero()); | |
| 136 // Make sure we can send. | 131 // Make sure we can send. |
| 137 EXPECT_TRUE(sender_->TimeUntilSend(clock_.Now(), 0, HAS_RETRANSMITTABLE_DATA) | 132 EXPECT_TRUE(sender_->TimeUntilSend(clock_.Now(), 0).IsZero()); |
| 138 .IsZero()); | |
| 139 // And that window is un-affected. | 133 // And that window is un-affected. |
| 140 EXPECT_EQ(kDefaultWindowTCP, sender_->GetCongestionWindow()); | 134 EXPECT_EQ(kDefaultWindowTCP, sender_->GetCongestionWindow()); |
| 141 | 135 |
| 142 // Fill the send window with data, then verify that we can't send. | 136 // Fill the send window with data, then verify that we can't send. |
| 143 SendAvailableSendWindow(); | 137 SendAvailableSendWindow(); |
| 144 EXPECT_FALSE(sender_ | 138 EXPECT_FALSE( |
| 145 ->TimeUntilSend(clock_.Now(), sender_->GetCongestionWindow(), | 139 sender_->TimeUntilSend(clock_.Now(), sender_->GetCongestionWindow()) |
| 146 HAS_RETRANSMITTABLE_DATA) | 140 .IsZero()); |
| 147 .IsZero()); | |
| 148 } | 141 } |
| 149 | 142 |
| 150 TEST_F(TcpCubicSenderBytesTest, ApplicationLimitedSlowStart) { | 143 TEST_F(TcpCubicSenderBytesTest, ApplicationLimitedSlowStart) { |
| 151 // Send exactly 10 packets and ensure the CWND ends at 14 packets. | 144 // Send exactly 10 packets and ensure the CWND ends at 14 packets. |
| 152 const int kNumberOfAcks = 5; | 145 const int kNumberOfAcks = 5; |
| 153 // At startup make sure we can send. | 146 // At startup make sure we can send. |
| 154 EXPECT_TRUE(sender_->TimeUntilSend(clock_.Now(), 0, HAS_RETRANSMITTABLE_DATA) | 147 EXPECT_TRUE(sender_->TimeUntilSend(clock_.Now(), 0).IsZero()); |
| 155 .IsZero()); | |
| 156 // Make sure we can send. | 148 // Make sure we can send. |
| 157 EXPECT_TRUE(sender_->TimeUntilSend(clock_.Now(), 0, HAS_RETRANSMITTABLE_DATA) | 149 EXPECT_TRUE(sender_->TimeUntilSend(clock_.Now(), 0).IsZero()); |
| 158 .IsZero()); | |
| 159 | 150 |
| 160 SendAvailableSendWindow(); | 151 SendAvailableSendWindow(); |
| 161 for (int i = 0; i < kNumberOfAcks; ++i) { | 152 for (int i = 0; i < kNumberOfAcks; ++i) { |
| 162 AckNPackets(2); | 153 AckNPackets(2); |
| 163 } | 154 } |
| 164 QuicByteCount bytes_to_send = sender_->GetCongestionWindow(); | 155 QuicByteCount bytes_to_send = sender_->GetCongestionWindow(); |
| 165 // It's expected 2 acks will arrive when the bytes_in_flight are greater than | 156 // It's expected 2 acks will arrive when the bytes_in_flight are greater than |
| 166 // half the CWND. | 157 // half the CWND. |
| 167 EXPECT_EQ(kDefaultWindowTCP + kDefaultTCPMSS * 2 * 2, bytes_to_send); | 158 EXPECT_EQ(kDefaultWindowTCP + kDefaultTCPMSS * 2 * 2, bytes_to_send); |
| 168 } | 159 } |
| 169 | 160 |
| 170 TEST_F(TcpCubicSenderBytesTest, ExponentialSlowStart) { | 161 TEST_F(TcpCubicSenderBytesTest, ExponentialSlowStart) { |
| 171 const int kNumberOfAcks = 20; | 162 const int kNumberOfAcks = 20; |
| 172 // At startup make sure we can send. | 163 // At startup make sure we can send. |
| 173 EXPECT_TRUE(sender_->TimeUntilSend(clock_.Now(), 0, HAS_RETRANSMITTABLE_DATA) | 164 EXPECT_TRUE(sender_->TimeUntilSend(clock_.Now(), 0).IsZero()); |
| 174 .IsZero()); | |
| 175 EXPECT_EQ(QuicBandwidth::Zero(), sender_->BandwidthEstimate()); | 165 EXPECT_EQ(QuicBandwidth::Zero(), sender_->BandwidthEstimate()); |
| 176 // Make sure we can send. | 166 // Make sure we can send. |
| 177 EXPECT_TRUE(sender_->TimeUntilSend(clock_.Now(), 0, HAS_RETRANSMITTABLE_DATA) | 167 EXPECT_TRUE(sender_->TimeUntilSend(clock_.Now(), 0).IsZero()); |
| 178 .IsZero()); | |
| 179 | 168 |
| 180 for (int i = 0; i < kNumberOfAcks; ++i) { | 169 for (int i = 0; i < kNumberOfAcks; ++i) { |
| 181 // Send our full send window. | 170 // Send our full send window. |
| 182 SendAvailableSendWindow(); | 171 SendAvailableSendWindow(); |
| 183 AckNPackets(2); | 172 AckNPackets(2); |
| 184 } | 173 } |
| 185 const QuicByteCount cwnd = sender_->GetCongestionWindow(); | 174 const QuicByteCount cwnd = sender_->GetCongestionWindow(); |
| 186 EXPECT_EQ(kDefaultWindowTCP + kDefaultTCPMSS * 2 * kNumberOfAcks, cwnd); | 175 EXPECT_EQ(kDefaultWindowTCP + kDefaultTCPMSS * 2 * kNumberOfAcks, cwnd); |
| 187 EXPECT_EQ(QuicBandwidth::FromBytesAndTimeDelta( | 176 EXPECT_EQ(QuicBandwidth::FromBytesAndTimeDelta( |
| 188 cwnd, sender_->rtt_stats_.smoothed_rtt()), | 177 cwnd, sender_->rtt_stats_.smoothed_rtt()), |
| (...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 293 | 282 |
| 294 TEST_F(TcpCubicSenderBytesTest, NoPRRWhenLessThanOnePacketInFlight) { | 283 TEST_F(TcpCubicSenderBytesTest, NoPRRWhenLessThanOnePacketInFlight) { |
| 295 SendAvailableSendWindow(); | 284 SendAvailableSendWindow(); |
| 296 LoseNPackets(kInitialCongestionWindowPackets - 1); | 285 LoseNPackets(kInitialCongestionWindowPackets - 1); |
| 297 AckNPackets(1); | 286 AckNPackets(1); |
| 298 // PRR will allow 2 packets for every ack during recovery. | 287 // PRR will allow 2 packets for every ack during recovery. |
| 299 EXPECT_EQ(2, SendAvailableSendWindow()); | 288 EXPECT_EQ(2, SendAvailableSendWindow()); |
| 300 // Simulate abandoning all packets by supplying a bytes_in_flight of 0. | 289 // Simulate abandoning all packets by supplying a bytes_in_flight of 0. |
| 301 // PRR should now allow a packet to be sent, even though prr's state variables | 290 // PRR should now allow a packet to be sent, even though prr's state variables |
| 302 // believe it has sent enough packets. | 291 // believe it has sent enough packets. |
| 303 EXPECT_EQ(QuicTime::Delta::Zero(), | 292 EXPECT_EQ(QuicTime::Delta::Zero(), sender_->TimeUntilSend(clock_.Now(), 0)); |
| 304 sender_->TimeUntilSend(clock_.Now(), 0, HAS_RETRANSMITTABLE_DATA)); | |
| 305 } | 293 } |
| 306 | 294 |
| 307 TEST_F(TcpCubicSenderBytesTest, SlowStartPacketLossPRR) { | 295 TEST_F(TcpCubicSenderBytesTest, SlowStartPacketLossPRR) { |
| 308 sender_->SetNumEmulatedConnections(1); | 296 sender_->SetNumEmulatedConnections(1); |
| 309 // Test based on the first example in RFC6937. | 297 // Test based on the first example in RFC6937. |
| 310 // Ack 10 packets in 5 acks to raise the CWND to 20, as in the example. | 298 // Ack 10 packets in 5 acks to raise the CWND to 20, as in the example. |
| 311 const int kNumberOfAcks = 5; | 299 const int kNumberOfAcks = 5; |
| 312 for (int i = 0; i < kNumberOfAcks; ++i) { | 300 for (int i = 0; i < kNumberOfAcks; ++i) { |
| 313 // Send our full send window. | 301 // Send our full send window. |
| 314 SendAvailableSendWindow(); | 302 SendAvailableSendWindow(); |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 371 EXPECT_EQ(expected_send_window, sender_->GetCongestionWindow()); | 359 EXPECT_EQ(expected_send_window, sender_->GetCongestionWindow()); |
| 372 | 360 |
| 373 // Lose one more than the congestion window reduction, so that after loss, | 361 // Lose one more than the congestion window reduction, so that after loss, |
| 374 // bytes_in_flight is lesser than the congestion window. | 362 // bytes_in_flight is lesser than the congestion window. |
| 375 size_t send_window_after_loss = kRenoBeta * expected_send_window; | 363 size_t send_window_after_loss = kRenoBeta * expected_send_window; |
| 376 size_t num_packets_to_lose = | 364 size_t num_packets_to_lose = |
| 377 (expected_send_window - send_window_after_loss) / kDefaultTCPMSS + 1; | 365 (expected_send_window - send_window_after_loss) / kDefaultTCPMSS + 1; |
| 378 LoseNPackets(num_packets_to_lose); | 366 LoseNPackets(num_packets_to_lose); |
| 379 // Immediately after the loss, ensure at least one packet can be sent. | 367 // Immediately after the loss, ensure at least one packet can be sent. |
| 380 // Losses without subsequent acks can occur with timer based loss detection. | 368 // Losses without subsequent acks can occur with timer based loss detection. |
| 381 EXPECT_TRUE(sender_ | 369 EXPECT_TRUE(sender_->TimeUntilSend(clock_.Now(), bytes_in_flight_).IsZero()); |
| 382 ->TimeUntilSend(clock_.Now(), bytes_in_flight_, | |
| 383 HAS_RETRANSMITTABLE_DATA) | |
| 384 .IsZero()); | |
| 385 AckNPackets(1); | 370 AckNPackets(1); |
| 386 | 371 |
| 387 // We should now have fallen out of slow start with a reduced window. | 372 // We should now have fallen out of slow start with a reduced window. |
| 388 expected_send_window *= kRenoBeta; | 373 expected_send_window *= kRenoBeta; |
| 389 EXPECT_EQ(expected_send_window, sender_->GetCongestionWindow()); | 374 EXPECT_EQ(expected_send_window, sender_->GetCongestionWindow()); |
| 390 | 375 |
| 391 // Only 2 packets should be allowed to be sent, per PRR-SSRB. | 376 // Only 2 packets should be allowed to be sent, per PRR-SSRB. |
| 392 EXPECT_EQ(2, SendAvailableSendWindow()); | 377 EXPECT_EQ(2, SendAvailableSendWindow()); |
| 393 | 378 |
| 394 // Ack the next packet, which triggers another loss. | 379 // Ack the next packet, which triggers another loss. |
| (...skipping 295 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 690 QuicConfig config; | 675 QuicConfig config; |
| 691 | 676 |
| 692 // Verify that kCOPT: kMIN4 forces the min CWND to 1 packet, but allows up | 677 // Verify that kCOPT: kMIN4 forces the min CWND to 1 packet, but allows up |
| 693 // to 4 to be sent. | 678 // to 4 to be sent. |
| 694 QuicTagVector options; | 679 QuicTagVector options; |
| 695 options.push_back(kMIN4); | 680 options.push_back(kMIN4); |
| 696 QuicConfigPeer::SetReceivedConnectionOptions(&config, options); | 681 QuicConfigPeer::SetReceivedConnectionOptions(&config, options); |
| 697 sender_->SetFromConfig(config, Perspective::IS_SERVER); | 682 sender_->SetFromConfig(config, Perspective::IS_SERVER); |
| 698 sender_->OnRetransmissionTimeout(true); | 683 sender_->OnRetransmissionTimeout(true); |
| 699 EXPECT_EQ(kDefaultTCPMSS, sender_->GetCongestionWindow()); | 684 EXPECT_EQ(kDefaultTCPMSS, sender_->GetCongestionWindow()); |
| 700 EXPECT_TRUE(sender_ | 685 EXPECT_TRUE( |
| 701 ->TimeUntilSend(QuicTime::Zero(), kDefaultTCPMSS, | 686 sender_->TimeUntilSend(QuicTime::Zero(), kDefaultTCPMSS).IsZero()); |
| 702 HAS_RETRANSMITTABLE_DATA) | 687 EXPECT_TRUE( |
| 703 .IsZero()); | 688 sender_->TimeUntilSend(QuicTime::Zero(), 2 * kDefaultTCPMSS).IsZero()); |
| 704 EXPECT_TRUE(sender_ | 689 EXPECT_TRUE( |
| 705 ->TimeUntilSend(QuicTime::Zero(), 2 * kDefaultTCPMSS, | 690 sender_->TimeUntilSend(QuicTime::Zero(), 3 * kDefaultTCPMSS).IsZero()); |
| 706 HAS_RETRANSMITTABLE_DATA) | 691 EXPECT_FALSE( |
| 707 .IsZero()); | 692 sender_->TimeUntilSend(QuicTime::Zero(), 4 * kDefaultTCPMSS).IsZero()); |
| 708 EXPECT_TRUE(sender_ | |
| 709 ->TimeUntilSend(QuicTime::Zero(), 3 * kDefaultTCPMSS, | |
| 710 HAS_RETRANSMITTABLE_DATA) | |
| 711 .IsZero()); | |
| 712 EXPECT_FALSE(sender_ | |
| 713 ->TimeUntilSend(QuicTime::Zero(), 4 * kDefaultTCPMSS, | |
| 714 HAS_RETRANSMITTABLE_DATA) | |
| 715 .IsZero()); | |
| 716 } | 693 } |
| 717 | 694 |
| 718 TEST_F(TcpCubicSenderBytesTest, ResetAfterConnectionMigration) { | 695 TEST_F(TcpCubicSenderBytesTest, ResetAfterConnectionMigration) { |
| 719 // Starts from slow start. | 696 // Starts from slow start. |
| 720 sender_->SetNumEmulatedConnections(1); | 697 sender_->SetNumEmulatedConnections(1); |
| 721 const int kNumberOfAcks = 10; | 698 const int kNumberOfAcks = 10; |
| 722 for (int i = 0; i < kNumberOfAcks; ++i) { | 699 for (int i = 0; i < kNumberOfAcks; ++i) { |
| 723 // Send our full send window. | 700 // Send our full send window. |
| 724 SendAvailableSendWindow(); | 701 SendAvailableSendWindow(); |
| 725 AckNPackets(2); | 702 AckNPackets(2); |
| (...skipping 15 matching lines...) Expand all Loading... |
| 741 // Resets cwnd and slow start threshold on connection migrations. | 718 // Resets cwnd and slow start threshold on connection migrations. |
| 742 sender_->OnConnectionMigration(); | 719 sender_->OnConnectionMigration(); |
| 743 EXPECT_EQ(kDefaultWindowTCP, sender_->GetCongestionWindow()); | 720 EXPECT_EQ(kDefaultWindowTCP, sender_->GetCongestionWindow()); |
| 744 EXPECT_EQ(kMaxCongestionWindow * kDefaultTCPMSS, | 721 EXPECT_EQ(kMaxCongestionWindow * kDefaultTCPMSS, |
| 745 sender_->GetSlowStartThreshold()); | 722 sender_->GetSlowStartThreshold()); |
| 746 EXPECT_FALSE(sender_->hybrid_slow_start().started()); | 723 EXPECT_FALSE(sender_->hybrid_slow_start().started()); |
| 747 } | 724 } |
| 748 | 725 |
| 749 } // namespace test | 726 } // namespace test |
| 750 } // namespace net | 727 } // namespace net |
| OLD | NEW |