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 "net/quic/congestion_control/tcp_cubic_sender_packets.h" | 5 #include "net/quic/congestion_control/tcp_cubic_sender_packets.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 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
62 protected: | 62 protected: |
63 TcpCubicSenderPacketsTest() | 63 TcpCubicSenderPacketsTest() |
64 : one_ms_(QuicTime::Delta::FromMilliseconds(1)), | 64 : one_ms_(QuicTime::Delta::FromMilliseconds(1)), |
65 sender_( | 65 sender_( |
66 new TcpCubicSenderPacketsPeer(&clock_, true, kMaxCongestionWindow)), | 66 new TcpCubicSenderPacketsPeer(&clock_, true, kMaxCongestionWindow)), |
67 packet_number_(1), | 67 packet_number_(1), |
68 acked_packet_number_(0), | 68 acked_packet_number_(0), |
69 bytes_in_flight_(0) {} | 69 bytes_in_flight_(0) {} |
70 | 70 |
71 int SendAvailableSendWindow() { | 71 int SendAvailableSendWindow() { |
| 72 return SendAvailableSendWindow(kDefaultTCPMSS); |
| 73 } |
| 74 |
| 75 int SendAvailableSendWindow(QuicPacketLength packet_length) { |
72 // Send as long as TimeUntilSend returns Zero. | 76 // Send as long as TimeUntilSend returns Zero. |
73 int packets_sent = 0; | 77 int packets_sent = 0; |
74 bool can_send = | 78 bool can_send = |
75 sender_->TimeUntilSend(clock_.Now(), bytes_in_flight_).IsZero(); | 79 sender_->TimeUntilSend(clock_.Now(), bytes_in_flight_).IsZero(); |
76 while (can_send) { | 80 while (can_send) { |
77 sender_->OnPacketSent(clock_.Now(), bytes_in_flight_, packet_number_++, | 81 sender_->OnPacketSent(clock_.Now(), bytes_in_flight_, packet_number_++, |
78 kDefaultTCPMSS, HAS_RETRANSMITTABLE_DATA); | 82 kDefaultTCPMSS, HAS_RETRANSMITTABLE_DATA); |
79 ++packets_sent; | 83 ++packets_sent; |
80 bytes_in_flight_ += kDefaultTCPMSS; | 84 bytes_in_flight_ += kDefaultTCPMSS; |
81 can_send = | 85 can_send = |
(...skipping 12 matching lines...) Expand all Loading... |
94 ++acked_packet_number_; | 98 ++acked_packet_number_; |
95 acked_packets.push_back( | 99 acked_packets.push_back( |
96 std::make_pair(acked_packet_number_, kDefaultTCPMSS)); | 100 std::make_pair(acked_packet_number_, kDefaultTCPMSS)); |
97 } | 101 } |
98 sender_->OnCongestionEvent(true, bytes_in_flight_, acked_packets, | 102 sender_->OnCongestionEvent(true, bytes_in_flight_, acked_packets, |
99 lost_packets); | 103 lost_packets); |
100 bytes_in_flight_ -= n * kDefaultTCPMSS; | 104 bytes_in_flight_ -= n * kDefaultTCPMSS; |
101 clock_.AdvanceTime(one_ms_); | 105 clock_.AdvanceTime(one_ms_); |
102 } | 106 } |
103 | 107 |
104 void LoseNPackets(int n) { | 108 void LoseNPackets(int n) { LoseNPackets(n, kDefaultTCPMSS); } |
| 109 |
| 110 void LoseNPackets(int n, QuicPacketLength packet_length) { |
105 SendAlgorithmInterface::CongestionVector acked_packets; | 111 SendAlgorithmInterface::CongestionVector acked_packets; |
106 SendAlgorithmInterface::CongestionVector lost_packets; | 112 SendAlgorithmInterface::CongestionVector lost_packets; |
107 for (int i = 0; i < n; ++i) { | 113 for (int i = 0; i < n; ++i) { |
108 ++acked_packet_number_; | 114 ++acked_packet_number_; |
109 lost_packets.push_back( | 115 lost_packets.push_back( |
110 std::make_pair(acked_packet_number_, kDefaultTCPMSS)); | 116 std::make_pair(acked_packet_number_, packet_length)); |
111 } | 117 } |
112 sender_->OnCongestionEvent(false, bytes_in_flight_, acked_packets, | 118 sender_->OnCongestionEvent(false, bytes_in_flight_, acked_packets, |
113 lost_packets); | 119 lost_packets); |
114 bytes_in_flight_ -= n * kDefaultTCPMSS; | 120 bytes_in_flight_ -= n * packet_length; |
115 } | 121 } |
116 | 122 |
117 // Does not increment acked_packet_number_. | 123 // Does not increment acked_packet_number_. |
118 void LosePacket(QuicPacketNumber packet_number) { | 124 void LosePacket(QuicPacketNumber packet_number) { |
119 SendAlgorithmInterface::CongestionVector acked_packets; | 125 SendAlgorithmInterface::CongestionVector acked_packets; |
120 SendAlgorithmInterface::CongestionVector lost_packets; | 126 SendAlgorithmInterface::CongestionVector lost_packets; |
121 lost_packets.push_back(std::make_pair(packet_number, kDefaultTCPMSS)); | 127 lost_packets.push_back(std::make_pair(packet_number, kDefaultTCPMSS)); |
122 sender_->OnCongestionEvent(false, bytes_in_flight_, acked_packets, | 128 sender_->OnCongestionEvent(false, bytes_in_flight_, acked_packets, |
123 lost_packets); | 129 lost_packets); |
124 bytes_in_flight_ -= kDefaultTCPMSS; | 130 bytes_in_flight_ -= kDefaultTCPMSS; |
(...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
282 AckNPackets(1); | 288 AckNPackets(1); |
283 expected_send_window += kDefaultTCPMSS; | 289 expected_send_window += kDefaultTCPMSS; |
284 EXPECT_EQ(expected_send_window, sender_->GetCongestionWindow()); | 290 EXPECT_EQ(expected_send_window, sender_->GetCongestionWindow()); |
285 | 291 |
286 // Now RTO and ensure slow start gets reset. | 292 // Now RTO and ensure slow start gets reset. |
287 EXPECT_TRUE(sender_->hybrid_slow_start().started()); | 293 EXPECT_TRUE(sender_->hybrid_slow_start().started()); |
288 sender_->OnRetransmissionTimeout(true); | 294 sender_->OnRetransmissionTimeout(true); |
289 EXPECT_FALSE(sender_->hybrid_slow_start().started()); | 295 EXPECT_FALSE(sender_->hybrid_slow_start().started()); |
290 } | 296 } |
291 | 297 |
| 298 TEST_F(TcpCubicSenderPacketsTest, SlowStartHalfPacketLossWithLargeReduction) { |
| 299 FLAGS_quic_sslr_byte_conservation = true; |
| 300 QuicConfig config; |
| 301 QuicTagVector options; |
| 302 options.push_back(kSSLR); |
| 303 QuicConfigPeer::SetReceivedConnectionOptions(&config, options); |
| 304 sender_->SetFromConfig(config, Perspective::IS_SERVER); |
| 305 |
| 306 sender_->SetNumEmulatedConnections(1); |
| 307 const int kNumberOfAcks = 10; |
| 308 for (int i = 0; i < kNumberOfAcks; ++i) { |
| 309 // Send our full send window in half sized packets. |
| 310 SendAvailableSendWindow(kDefaultTCPMSS / 2); |
| 311 AckNPackets(2); |
| 312 } |
| 313 SendAvailableSendWindow(kDefaultTCPMSS / 2); |
| 314 QuicByteCount expected_send_window = |
| 315 kDefaultWindowTCP + (kDefaultTCPMSS * 2 * kNumberOfAcks); |
| 316 EXPECT_EQ(expected_send_window, sender_->GetCongestionWindow()); |
| 317 |
| 318 // Lose a packet to exit slow start. We should now have fallen out of |
| 319 // slow start with a window reduced by 1. |
| 320 LoseNPackets(1); |
| 321 expected_send_window -= kDefaultTCPMSS; |
| 322 EXPECT_EQ(expected_send_window, sender_->GetCongestionWindow()); |
| 323 |
| 324 // Lose 10 packets in recovery and verify that congestion window is reduced |
| 325 // by 5 packets. |
| 326 LoseNPackets(10, kDefaultTCPMSS / 2); |
| 327 expected_send_window -= 5 * kDefaultTCPMSS; |
| 328 EXPECT_EQ(expected_send_window, sender_->GetCongestionWindow()); |
| 329 } |
| 330 |
292 TEST_F(TcpCubicSenderPacketsTest, NoPRRWhenLessThanOnePacketInFlight) { | 331 TEST_F(TcpCubicSenderPacketsTest, NoPRRWhenLessThanOnePacketInFlight) { |
293 SendAvailableSendWindow(); | 332 SendAvailableSendWindow(); |
294 LoseNPackets(kInitialCongestionWindowPackets - 1); | 333 LoseNPackets(kInitialCongestionWindowPackets - 1); |
295 AckNPackets(1); | 334 AckNPackets(1); |
296 // PRR will allow 2 packets for every ack during recovery. | 335 // PRR will allow 2 packets for every ack during recovery. |
297 EXPECT_EQ(2, SendAvailableSendWindow()); | 336 EXPECT_EQ(2, SendAvailableSendWindow()); |
298 // Simulate abandoning all packets by supplying a bytes_in_flight of 0. | 337 // Simulate abandoning all packets by supplying a bytes_in_flight of 0. |
299 // PRR should now allow a packet to be sent, even though prr's state | 338 // PRR should now allow a packet to be sent, even though prr's state |
300 // variables believe it has sent enough packets. | 339 // variables believe it has sent enough packets. |
301 EXPECT_EQ(QuicTime::Delta::Zero(), sender_->TimeUntilSend(clock_.Now(), 0)); | 340 EXPECT_EQ(QuicTime::Delta::Zero(), sender_->TimeUntilSend(clock_.Now(), 0)); |
(...skipping 566 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
868 | 907 |
869 // Resets cwnd and slow start threshold on connection migrations. | 908 // Resets cwnd and slow start threshold on connection migrations. |
870 sender_->OnConnectionMigration(); | 909 sender_->OnConnectionMigration(); |
871 EXPECT_EQ(kDefaultWindowTCP, sender_->GetCongestionWindow()); | 910 EXPECT_EQ(kDefaultWindowTCP, sender_->GetCongestionWindow()); |
872 EXPECT_EQ(kMaxCongestionWindow, sender_->slowstart_threshold()); | 911 EXPECT_EQ(kMaxCongestionWindow, sender_->slowstart_threshold()); |
873 EXPECT_FALSE(sender_->hybrid_slow_start().started()); | 912 EXPECT_FALSE(sender_->hybrid_slow_start().started()); |
874 } | 913 } |
875 | 914 |
876 } // namespace test | 915 } // namespace test |
877 } // namespace net | 916 } // namespace net |
OLD | NEW |