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 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
53 class TcpCubicSenderBytesTest : public ::testing::Test { | 53 class TcpCubicSenderBytesTest : public ::testing::Test { |
54 protected: | 54 protected: |
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 return SendAvailableSendWindow(kDefaultTCPMSS); |
| 64 } |
| 65 |
| 66 int SendAvailableSendWindow(QuicPacketLength packet_length) { |
63 // Send as long as TimeUntilSend returns Zero. | 67 // Send as long as TimeUntilSend returns Zero. |
64 int packets_sent = 0; | 68 int packets_sent = 0; |
65 bool can_send = | 69 bool can_send = |
66 sender_->TimeUntilSend(clock_.Now(), bytes_in_flight_).IsZero(); | 70 sender_->TimeUntilSend(clock_.Now(), bytes_in_flight_).IsZero(); |
67 while (can_send) { | 71 while (can_send) { |
68 sender_->OnPacketSent(clock_.Now(), bytes_in_flight_, packet_number_++, | 72 sender_->OnPacketSent(clock_.Now(), bytes_in_flight_, packet_number_++, |
69 kDefaultTCPMSS, HAS_RETRANSMITTABLE_DATA); | 73 kDefaultTCPMSS, HAS_RETRANSMITTABLE_DATA); |
70 ++packets_sent; | 74 ++packets_sent; |
71 bytes_in_flight_ += kDefaultTCPMSS; | 75 bytes_in_flight_ += kDefaultTCPMSS; |
72 can_send = | 76 can_send = |
(...skipping 12 matching lines...) Expand all Loading... |
85 ++acked_packet_number_; | 89 ++acked_packet_number_; |
86 acked_packets.push_back( | 90 acked_packets.push_back( |
87 std::make_pair(acked_packet_number_, kDefaultTCPMSS)); | 91 std::make_pair(acked_packet_number_, kDefaultTCPMSS)); |
88 } | 92 } |
89 sender_->OnCongestionEvent(true, bytes_in_flight_, acked_packets, | 93 sender_->OnCongestionEvent(true, bytes_in_flight_, acked_packets, |
90 lost_packets); | 94 lost_packets); |
91 bytes_in_flight_ -= n * kDefaultTCPMSS; | 95 bytes_in_flight_ -= n * kDefaultTCPMSS; |
92 clock_.AdvanceTime(one_ms_); | 96 clock_.AdvanceTime(one_ms_); |
93 } | 97 } |
94 | 98 |
95 void LoseNPackets(int n) { | 99 void LoseNPackets(int n) { LoseNPackets(n, kDefaultTCPMSS); } |
| 100 |
| 101 void LoseNPackets(int n, QuicPacketLength packet_length) { |
96 SendAlgorithmInterface::CongestionVector acked_packets; | 102 SendAlgorithmInterface::CongestionVector acked_packets; |
97 SendAlgorithmInterface::CongestionVector lost_packets; | 103 SendAlgorithmInterface::CongestionVector lost_packets; |
98 for (int i = 0; i < n; ++i) { | 104 for (int i = 0; i < n; ++i) { |
99 ++acked_packet_number_; | 105 ++acked_packet_number_; |
100 lost_packets.push_back( | 106 lost_packets.push_back( |
101 std::make_pair(acked_packet_number_, kDefaultTCPMSS)); | 107 std::make_pair(acked_packet_number_, packet_length)); |
102 } | 108 } |
103 sender_->OnCongestionEvent(false, bytes_in_flight_, acked_packets, | 109 sender_->OnCongestionEvent(false, bytes_in_flight_, acked_packets, |
104 lost_packets); | 110 lost_packets); |
105 bytes_in_flight_ -= n * kDefaultTCPMSS; | 111 bytes_in_flight_ -= n * packet_length; |
106 } | 112 } |
107 | 113 |
108 // Does not increment acked_packet_number_. | 114 // Does not increment acked_packet_number_. |
109 void LosePacket(QuicPacketNumber packet_number) { | 115 void LosePacket(QuicPacketNumber packet_number) { |
110 SendAlgorithmInterface::CongestionVector acked_packets; | 116 SendAlgorithmInterface::CongestionVector acked_packets; |
111 SendAlgorithmInterface::CongestionVector lost_packets; | 117 SendAlgorithmInterface::CongestionVector lost_packets; |
112 lost_packets.push_back(std::make_pair(packet_number, kDefaultTCPMSS)); | 118 lost_packets.push_back(std::make_pair(packet_number, kDefaultTCPMSS)); |
113 sender_->OnCongestionEvent(false, bytes_in_flight_, acked_packets, | 119 sender_->OnCongestionEvent(false, bytes_in_flight_, acked_packets, |
114 lost_packets); | 120 lost_packets); |
115 bytes_in_flight_ -= kDefaultTCPMSS; | 121 bytes_in_flight_ -= kDefaultTCPMSS; |
(...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
273 AckNPackets(1); | 279 AckNPackets(1); |
274 expected_send_window += kDefaultTCPMSS; | 280 expected_send_window += kDefaultTCPMSS; |
275 EXPECT_EQ(expected_send_window, sender_->GetCongestionWindow()); | 281 EXPECT_EQ(expected_send_window, sender_->GetCongestionWindow()); |
276 | 282 |
277 // Now RTO and ensure slow start gets reset. | 283 // Now RTO and ensure slow start gets reset. |
278 EXPECT_TRUE(sender_->hybrid_slow_start().started()); | 284 EXPECT_TRUE(sender_->hybrid_slow_start().started()); |
279 sender_->OnRetransmissionTimeout(true); | 285 sender_->OnRetransmissionTimeout(true); |
280 EXPECT_FALSE(sender_->hybrid_slow_start().started()); | 286 EXPECT_FALSE(sender_->hybrid_slow_start().started()); |
281 } | 287 } |
282 | 288 |
| 289 TEST_F(TcpCubicSenderBytesTest, SlowStartHalfPacketLossWithLargeReduction) { |
| 290 FLAGS_quic_sslr_byte_conservation = true; |
| 291 QuicConfig config; |
| 292 QuicTagVector options; |
| 293 options.push_back(kSSLR); |
| 294 QuicConfigPeer::SetReceivedConnectionOptions(&config, options); |
| 295 sender_->SetFromConfig(config, Perspective::IS_SERVER); |
| 296 |
| 297 sender_->SetNumEmulatedConnections(1); |
| 298 const int kNumberOfAcks = 10; |
| 299 for (int i = 0; i < kNumberOfAcks; ++i) { |
| 300 // Send our full send window in half sized packets. |
| 301 SendAvailableSendWindow(kDefaultTCPMSS / 2); |
| 302 AckNPackets(2); |
| 303 } |
| 304 SendAvailableSendWindow(kDefaultTCPMSS / 2); |
| 305 QuicByteCount expected_send_window = |
| 306 kDefaultWindowTCP + (kDefaultTCPMSS * 2 * kNumberOfAcks); |
| 307 EXPECT_EQ(expected_send_window, sender_->GetCongestionWindow()); |
| 308 |
| 309 // Lose a packet to exit slow start. We should now have fallen out of |
| 310 // slow start with a window reduced by 1. |
| 311 LoseNPackets(1); |
| 312 expected_send_window -= kDefaultTCPMSS; |
| 313 EXPECT_EQ(expected_send_window, sender_->GetCongestionWindow()); |
| 314 |
| 315 // Lose 10 packets in recovery and verify that congestion window is reduced |
| 316 // by 5 packets. |
| 317 LoseNPackets(10, kDefaultTCPMSS / 2); |
| 318 expected_send_window -= 5 * kDefaultTCPMSS; |
| 319 EXPECT_EQ(expected_send_window, sender_->GetCongestionWindow()); |
| 320 } |
| 321 |
283 TEST_F(TcpCubicSenderBytesTest, NoPRRWhenLessThanOnePacketInFlight) { | 322 TEST_F(TcpCubicSenderBytesTest, NoPRRWhenLessThanOnePacketInFlight) { |
284 SendAvailableSendWindow(); | 323 SendAvailableSendWindow(); |
285 LoseNPackets(kInitialCongestionWindowPackets - 1); | 324 LoseNPackets(kInitialCongestionWindowPackets - 1); |
286 AckNPackets(1); | 325 AckNPackets(1); |
287 // PRR will allow 2 packets for every ack during recovery. | 326 // PRR will allow 2 packets for every ack during recovery. |
288 EXPECT_EQ(2, SendAvailableSendWindow()); | 327 EXPECT_EQ(2, SendAvailableSendWindow()); |
289 // Simulate abandoning all packets by supplying a bytes_in_flight of 0. | 328 // Simulate abandoning all packets by supplying a bytes_in_flight of 0. |
290 // PRR should now allow a packet to be sent, even though prr's state variables | 329 // PRR should now allow a packet to be sent, even though prr's state variables |
291 // believe it has sent enough packets. | 330 // believe it has sent enough packets. |
292 EXPECT_EQ(QuicTime::Delta::Zero(), sender_->TimeUntilSend(clock_.Now(), 0)); | 331 EXPECT_EQ(QuicTime::Delta::Zero(), sender_->TimeUntilSend(clock_.Now(), 0)); |
(...skipping 425 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
718 // Resets cwnd and slow start threshold on connection migrations. | 757 // Resets cwnd and slow start threshold on connection migrations. |
719 sender_->OnConnectionMigration(); | 758 sender_->OnConnectionMigration(); |
720 EXPECT_EQ(kDefaultWindowTCP, sender_->GetCongestionWindow()); | 759 EXPECT_EQ(kDefaultWindowTCP, sender_->GetCongestionWindow()); |
721 EXPECT_EQ(kMaxCongestionWindow * kDefaultTCPMSS, | 760 EXPECT_EQ(kMaxCongestionWindow * kDefaultTCPMSS, |
722 sender_->GetSlowStartThreshold()); | 761 sender_->GetSlowStartThreshold()); |
723 EXPECT_FALSE(sender_->hybrid_slow_start().started()); | 762 EXPECT_FALSE(sender_->hybrid_slow_start().started()); |
724 } | 763 } |
725 | 764 |
726 } // namespace test | 765 } // namespace test |
727 } // namespace net | 766 } // namespace net |
OLD | NEW |