| OLD | NEW |
| (Empty) |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "net/quic/congestion_control/tcp_cubic_sender_bytes.h" | |
| 6 | |
| 7 #include <algorithm> | |
| 8 #include <cstdint> | |
| 9 #include <memory> | |
| 10 | |
| 11 #include "base/logging.h" | |
| 12 #include "net/quic/congestion_control/rtt_stats.h" | |
| 13 #include "net/quic/crypto/crypto_protocol.h" | |
| 14 #include "net/quic/proto/cached_network_parameters.pb.h" | |
| 15 #include "net/quic/quic_flags.h" | |
| 16 #include "net/quic/quic_protocol.h" | |
| 17 #include "net/quic/quic_utils.h" | |
| 18 #include "net/quic/test_tools/mock_clock.h" | |
| 19 #include "net/quic/test_tools/quic_config_peer.h" | |
| 20 #include "net/quic/test_tools/quic_test_utils.h" | |
| 21 #include "testing/gtest/include/gtest/gtest.h" | |
| 22 | |
| 23 namespace net { | |
| 24 namespace test { | |
| 25 | |
| 26 // TODO(ianswett): A number of theses tests were written with the assumption of | |
| 27 // an initial CWND of 10. They have carefully calculated values which should be | |
| 28 // updated to be based on kInitialCongestionWindow. | |
| 29 const uint32_t kInitialCongestionWindowPackets = 10; | |
| 30 const uint32_t kMaxCongestionWindowPackets = 200; | |
| 31 const uint32_t kDefaultWindowTCP = | |
| 32 kInitialCongestionWindowPackets * kDefaultTCPMSS; | |
| 33 const float kRenoBeta = 0.7f; // Reno backoff factor. | |
| 34 | |
| 35 class TcpCubicSenderBytesPeer : public TcpCubicSenderBytes { | |
| 36 public: | |
| 37 TcpCubicSenderBytesPeer(const QuicClock* clock, bool reno) | |
| 38 : TcpCubicSenderBytes(clock, | |
| 39 &rtt_stats_, | |
| 40 reno, | |
| 41 kInitialCongestionWindowPackets, | |
| 42 kMaxCongestionWindowPackets, | |
| 43 &stats_) {} | |
| 44 | |
| 45 const HybridSlowStart& hybrid_slow_start() const { | |
| 46 return hybrid_slow_start_; | |
| 47 } | |
| 48 | |
| 49 float GetRenoBeta() const { return RenoBeta(); } | |
| 50 | |
| 51 RttStats rtt_stats_; | |
| 52 QuicConnectionStats stats_; | |
| 53 }; | |
| 54 | |
| 55 class TcpCubicSenderBytesTest : public ::testing::Test { | |
| 56 protected: | |
| 57 TcpCubicSenderBytesTest() | |
| 58 : one_ms_(QuicTime::Delta::FromMilliseconds(1)), | |
| 59 sender_(new TcpCubicSenderBytesPeer(&clock_, true)), | |
| 60 packet_number_(1), | |
| 61 acked_packet_number_(0), | |
| 62 bytes_in_flight_(0) {} | |
| 63 | |
| 64 int SendAvailableSendWindow() { | |
| 65 return SendAvailableSendWindow(kDefaultTCPMSS); | |
| 66 } | |
| 67 | |
| 68 int SendAvailableSendWindow(QuicPacketLength packet_length) { | |
| 69 // Send as long as TimeUntilSend returns Zero. | |
| 70 int packets_sent = 0; | |
| 71 bool can_send = | |
| 72 sender_->TimeUntilSend(clock_.Now(), bytes_in_flight_).IsZero(); | |
| 73 while (can_send) { | |
| 74 sender_->OnPacketSent(clock_.Now(), bytes_in_flight_, packet_number_++, | |
| 75 kDefaultTCPMSS, HAS_RETRANSMITTABLE_DATA); | |
| 76 ++packets_sent; | |
| 77 bytes_in_flight_ += kDefaultTCPMSS; | |
| 78 can_send = | |
| 79 sender_->TimeUntilSend(clock_.Now(), bytes_in_flight_).IsZero(); | |
| 80 } | |
| 81 return packets_sent; | |
| 82 } | |
| 83 | |
| 84 // Normal is that TCP acks every other segment. | |
| 85 void AckNPackets(int n) { | |
| 86 sender_->rtt_stats_.UpdateRtt(QuicTime::Delta::FromMilliseconds(60), | |
| 87 QuicTime::Delta::Zero(), clock_.Now()); | |
| 88 SendAlgorithmInterface::CongestionVector acked_packets; | |
| 89 SendAlgorithmInterface::CongestionVector lost_packets; | |
| 90 for (int i = 0; i < n; ++i) { | |
| 91 ++acked_packet_number_; | |
| 92 acked_packets.push_back( | |
| 93 std::make_pair(acked_packet_number_, kDefaultTCPMSS)); | |
| 94 } | |
| 95 sender_->OnCongestionEvent(true, bytes_in_flight_, acked_packets, | |
| 96 lost_packets); | |
| 97 bytes_in_flight_ -= n * kDefaultTCPMSS; | |
| 98 clock_.AdvanceTime(one_ms_); | |
| 99 } | |
| 100 | |
| 101 void LoseNPackets(int n) { LoseNPackets(n, kDefaultTCPMSS); } | |
| 102 | |
| 103 void LoseNPackets(int n, QuicPacketLength packet_length) { | |
| 104 SendAlgorithmInterface::CongestionVector acked_packets; | |
| 105 SendAlgorithmInterface::CongestionVector lost_packets; | |
| 106 for (int i = 0; i < n; ++i) { | |
| 107 ++acked_packet_number_; | |
| 108 lost_packets.push_back( | |
| 109 std::make_pair(acked_packet_number_, packet_length)); | |
| 110 } | |
| 111 sender_->OnCongestionEvent(false, bytes_in_flight_, acked_packets, | |
| 112 lost_packets); | |
| 113 bytes_in_flight_ -= n * packet_length; | |
| 114 } | |
| 115 | |
| 116 // Does not increment acked_packet_number_. | |
| 117 void LosePacket(QuicPacketNumber packet_number) { | |
| 118 SendAlgorithmInterface::CongestionVector acked_packets; | |
| 119 SendAlgorithmInterface::CongestionVector lost_packets; | |
| 120 lost_packets.push_back(std::make_pair(packet_number, kDefaultTCPMSS)); | |
| 121 sender_->OnCongestionEvent(false, bytes_in_flight_, acked_packets, | |
| 122 lost_packets); | |
| 123 bytes_in_flight_ -= kDefaultTCPMSS; | |
| 124 } | |
| 125 | |
| 126 const QuicTime::Delta one_ms_; | |
| 127 MockClock clock_; | |
| 128 std::unique_ptr<TcpCubicSenderBytesPeer> sender_; | |
| 129 QuicPacketNumber packet_number_; | |
| 130 QuicPacketNumber acked_packet_number_; | |
| 131 QuicByteCount bytes_in_flight_; | |
| 132 }; | |
| 133 | |
| 134 TEST_F(TcpCubicSenderBytesTest, SimpleSender) { | |
| 135 // At startup make sure we are at the default. | |
| 136 EXPECT_EQ(kDefaultWindowTCP, sender_->GetCongestionWindow()); | |
| 137 // At startup make sure we can send. | |
| 138 EXPECT_TRUE(sender_->TimeUntilSend(clock_.Now(), 0).IsZero()); | |
| 139 // Make sure we can send. | |
| 140 EXPECT_TRUE(sender_->TimeUntilSend(clock_.Now(), 0).IsZero()); | |
| 141 // And that window is un-affected. | |
| 142 EXPECT_EQ(kDefaultWindowTCP, sender_->GetCongestionWindow()); | |
| 143 | |
| 144 // Fill the send window with data, then verify that we can't send. | |
| 145 SendAvailableSendWindow(); | |
| 146 EXPECT_FALSE( | |
| 147 sender_->TimeUntilSend(clock_.Now(), sender_->GetCongestionWindow()) | |
| 148 .IsZero()); | |
| 149 } | |
| 150 | |
| 151 TEST_F(TcpCubicSenderBytesTest, ApplicationLimitedSlowStart) { | |
| 152 // Send exactly 10 packets and ensure the CWND ends at 14 packets. | |
| 153 const int kNumberOfAcks = 5; | |
| 154 // At startup make sure we can send. | |
| 155 EXPECT_TRUE(sender_->TimeUntilSend(clock_.Now(), 0).IsZero()); | |
| 156 // Make sure we can send. | |
| 157 EXPECT_TRUE(sender_->TimeUntilSend(clock_.Now(), 0).IsZero()); | |
| 158 | |
| 159 SendAvailableSendWindow(); | |
| 160 for (int i = 0; i < kNumberOfAcks; ++i) { | |
| 161 AckNPackets(2); | |
| 162 } | |
| 163 QuicByteCount bytes_to_send = sender_->GetCongestionWindow(); | |
| 164 // It's expected 2 acks will arrive when the bytes_in_flight are greater than | |
| 165 // half the CWND. | |
| 166 EXPECT_EQ(kDefaultWindowTCP + kDefaultTCPMSS * 2 * 2, bytes_to_send); | |
| 167 } | |
| 168 | |
| 169 TEST_F(TcpCubicSenderBytesTest, ExponentialSlowStart) { | |
| 170 const int kNumberOfAcks = 20; | |
| 171 // At startup make sure we can send. | |
| 172 EXPECT_TRUE(sender_->TimeUntilSend(clock_.Now(), 0).IsZero()); | |
| 173 EXPECT_EQ(QuicBandwidth::Zero(), sender_->BandwidthEstimate()); | |
| 174 // Make sure we can send. | |
| 175 EXPECT_TRUE(sender_->TimeUntilSend(clock_.Now(), 0).IsZero()); | |
| 176 | |
| 177 for (int i = 0; i < kNumberOfAcks; ++i) { | |
| 178 // Send our full send window. | |
| 179 SendAvailableSendWindow(); | |
| 180 AckNPackets(2); | |
| 181 } | |
| 182 const QuicByteCount cwnd = sender_->GetCongestionWindow(); | |
| 183 EXPECT_EQ(kDefaultWindowTCP + kDefaultTCPMSS * 2 * kNumberOfAcks, cwnd); | |
| 184 EXPECT_EQ(QuicBandwidth::FromBytesAndTimeDelta( | |
| 185 cwnd, sender_->rtt_stats_.smoothed_rtt()), | |
| 186 sender_->BandwidthEstimate()); | |
| 187 } | |
| 188 | |
| 189 TEST_F(TcpCubicSenderBytesTest, SlowStartPacketLoss) { | |
| 190 sender_->SetNumEmulatedConnections(1); | |
| 191 const int kNumberOfAcks = 10; | |
| 192 for (int i = 0; i < kNumberOfAcks; ++i) { | |
| 193 // Send our full send window. | |
| 194 SendAvailableSendWindow(); | |
| 195 AckNPackets(2); | |
| 196 } | |
| 197 SendAvailableSendWindow(); | |
| 198 QuicByteCount expected_send_window = | |
| 199 kDefaultWindowTCP + (kDefaultTCPMSS * 2 * kNumberOfAcks); | |
| 200 EXPECT_EQ(expected_send_window, sender_->GetCongestionWindow()); | |
| 201 | |
| 202 // Lose a packet to exit slow start. | |
| 203 LoseNPackets(1); | |
| 204 size_t packets_in_recovery_window = expected_send_window / kDefaultTCPMSS; | |
| 205 | |
| 206 // We should now have fallen out of slow start with a reduced window. | |
| 207 expected_send_window *= kRenoBeta; | |
| 208 EXPECT_EQ(expected_send_window, sender_->GetCongestionWindow()); | |
| 209 | |
| 210 // Recovery phase. We need to ack every packet in the recovery window before | |
| 211 // we exit recovery. | |
| 212 size_t number_of_packets_in_window = expected_send_window / kDefaultTCPMSS; | |
| 213 DVLOG(1) << "number_packets: " << number_of_packets_in_window; | |
| 214 AckNPackets(packets_in_recovery_window); | |
| 215 SendAvailableSendWindow(); | |
| 216 EXPECT_EQ(expected_send_window, sender_->GetCongestionWindow()); | |
| 217 | |
| 218 // We need to ack an entire window before we increase CWND by 1. | |
| 219 AckNPackets(number_of_packets_in_window - 2); | |
| 220 SendAvailableSendWindow(); | |
| 221 EXPECT_EQ(expected_send_window, sender_->GetCongestionWindow()); | |
| 222 | |
| 223 // Next ack should increase cwnd by 1. | |
| 224 AckNPackets(1); | |
| 225 expected_send_window += kDefaultTCPMSS; | |
| 226 EXPECT_EQ(expected_send_window, sender_->GetCongestionWindow()); | |
| 227 | |
| 228 // Now RTO and ensure slow start gets reset. | |
| 229 EXPECT_TRUE(sender_->hybrid_slow_start().started()); | |
| 230 sender_->OnRetransmissionTimeout(true); | |
| 231 EXPECT_FALSE(sender_->hybrid_slow_start().started()); | |
| 232 } | |
| 233 | |
| 234 TEST_F(TcpCubicSenderBytesTest, SlowStartPacketLossWithLargeReduction) { | |
| 235 QuicConfig config; | |
| 236 QuicTagVector options; | |
| 237 options.push_back(kSSLR); | |
| 238 QuicConfigPeer::SetReceivedConnectionOptions(&config, options); | |
| 239 sender_->SetFromConfig(config, Perspective::IS_SERVER); | |
| 240 | |
| 241 sender_->SetNumEmulatedConnections(1); | |
| 242 const int kNumberOfAcks = (kDefaultWindowTCP / (2 * kDefaultTCPMSS)) - 1; | |
| 243 for (int i = 0; i < kNumberOfAcks; ++i) { | |
| 244 // Send our full send window. | |
| 245 SendAvailableSendWindow(); | |
| 246 AckNPackets(2); | |
| 247 } | |
| 248 SendAvailableSendWindow(); | |
| 249 QuicByteCount expected_send_window = | |
| 250 kDefaultWindowTCP + (kDefaultTCPMSS * 2 * kNumberOfAcks); | |
| 251 EXPECT_EQ(expected_send_window, sender_->GetCongestionWindow()); | |
| 252 | |
| 253 // Lose a packet to exit slow start. We should now have fallen out of | |
| 254 // slow start with a window reduced by 1. | |
| 255 LoseNPackets(1); | |
| 256 expected_send_window -= kDefaultTCPMSS; | |
| 257 EXPECT_EQ(expected_send_window, sender_->GetCongestionWindow()); | |
| 258 | |
| 259 // Lose 5 packets in recovery and verify that congestion window is reduced | |
| 260 // further. | |
| 261 LoseNPackets(5); | |
| 262 expected_send_window -= 5 * kDefaultTCPMSS; | |
| 263 EXPECT_EQ(expected_send_window, sender_->GetCongestionWindow()); | |
| 264 // Lose another 10 packets and ensure it reduces below half the peak CWND, | |
| 265 // because we never acked the full IW. | |
| 266 LoseNPackets(10); | |
| 267 expected_send_window -= 10 * kDefaultTCPMSS; | |
| 268 EXPECT_EQ(expected_send_window, sender_->GetCongestionWindow()); | |
| 269 | |
| 270 size_t packets_in_recovery_window = expected_send_window / kDefaultTCPMSS; | |
| 271 | |
| 272 // Recovery phase. We need to ack every packet in the recovery window before | |
| 273 // we exit recovery. | |
| 274 size_t number_of_packets_in_window = expected_send_window / kDefaultTCPMSS; | |
| 275 DVLOG(1) << "number_packets: " << number_of_packets_in_window; | |
| 276 AckNPackets(packets_in_recovery_window); | |
| 277 SendAvailableSendWindow(); | |
| 278 EXPECT_EQ(expected_send_window, sender_->GetCongestionWindow()); | |
| 279 | |
| 280 // We need to ack an entire window before we increase CWND by 1. | |
| 281 AckNPackets(number_of_packets_in_window - 1); | |
| 282 SendAvailableSendWindow(); | |
| 283 EXPECT_EQ(expected_send_window, sender_->GetCongestionWindow()); | |
| 284 | |
| 285 // Next ack should increase cwnd by 1. | |
| 286 AckNPackets(1); | |
| 287 expected_send_window += kDefaultTCPMSS; | |
| 288 EXPECT_EQ(expected_send_window, sender_->GetCongestionWindow()); | |
| 289 | |
| 290 // Now RTO and ensure slow start gets reset. | |
| 291 EXPECT_TRUE(sender_->hybrid_slow_start().started()); | |
| 292 sender_->OnRetransmissionTimeout(true); | |
| 293 EXPECT_FALSE(sender_->hybrid_slow_start().started()); | |
| 294 } | |
| 295 | |
| 296 TEST_F(TcpCubicSenderBytesTest, SlowStartHalfPacketLossWithLargeReduction) { | |
| 297 QuicConfig config; | |
| 298 QuicTagVector options; | |
| 299 options.push_back(kSSLR); | |
| 300 QuicConfigPeer::SetReceivedConnectionOptions(&config, options); | |
| 301 sender_->SetFromConfig(config, Perspective::IS_SERVER); | |
| 302 | |
| 303 sender_->SetNumEmulatedConnections(1); | |
| 304 const int kNumberOfAcks = 10; | |
| 305 for (int i = 0; i < kNumberOfAcks; ++i) { | |
| 306 // Send our full send window in half sized packets. | |
| 307 SendAvailableSendWindow(kDefaultTCPMSS / 2); | |
| 308 AckNPackets(2); | |
| 309 } | |
| 310 SendAvailableSendWindow(kDefaultTCPMSS / 2); | |
| 311 QuicByteCount expected_send_window = | |
| 312 kDefaultWindowTCP + (kDefaultTCPMSS * 2 * kNumberOfAcks); | |
| 313 EXPECT_EQ(expected_send_window, sender_->GetCongestionWindow()); | |
| 314 | |
| 315 // Lose a packet to exit slow start. We should now have fallen out of | |
| 316 // slow start with a window reduced by 1. | |
| 317 LoseNPackets(1); | |
| 318 expected_send_window -= kDefaultTCPMSS; | |
| 319 EXPECT_EQ(expected_send_window, sender_->GetCongestionWindow()); | |
| 320 | |
| 321 // Lose 10 packets in recovery and verify that congestion window is reduced | |
| 322 // by 5 packets. | |
| 323 LoseNPackets(10, kDefaultTCPMSS / 2); | |
| 324 expected_send_window -= 5 * kDefaultTCPMSS; | |
| 325 EXPECT_EQ(expected_send_window, sender_->GetCongestionWindow()); | |
| 326 } | |
| 327 | |
| 328 TEST_F(TcpCubicSenderBytesTest, SlowStartPacketLossWithMaxHalfReduction) { | |
| 329 QuicConfig config; | |
| 330 QuicTagVector options; | |
| 331 options.push_back(kSSLR); | |
| 332 QuicConfigPeer::SetReceivedConnectionOptions(&config, options); | |
| 333 sender_->SetFromConfig(config, Perspective::IS_SERVER); | |
| 334 | |
| 335 sender_->SetNumEmulatedConnections(1); | |
| 336 const int kNumberOfAcks = kInitialCongestionWindowPackets / 2; | |
| 337 for (int i = 0; i < kNumberOfAcks; ++i) { | |
| 338 // Send our full send window. | |
| 339 SendAvailableSendWindow(); | |
| 340 AckNPackets(2); | |
| 341 } | |
| 342 SendAvailableSendWindow(); | |
| 343 QuicByteCount expected_send_window = | |
| 344 kDefaultWindowTCP + (kDefaultTCPMSS * 2 * kNumberOfAcks); | |
| 345 EXPECT_EQ(expected_send_window, sender_->GetCongestionWindow()); | |
| 346 | |
| 347 // Lose a packet to exit slow start. We should now have fallen out of | |
| 348 // slow start with a window reduced by 1. | |
| 349 LoseNPackets(1); | |
| 350 expected_send_window -= kDefaultTCPMSS; | |
| 351 EXPECT_EQ(expected_send_window, sender_->GetCongestionWindow()); | |
| 352 | |
| 353 // Lose half the outstanding packets in recovery and verify the congestion | |
| 354 // window is only reduced by a max of half. | |
| 355 LoseNPackets(kNumberOfAcks * 2); | |
| 356 expected_send_window -= (kNumberOfAcks * 2 - 1) * kDefaultTCPMSS; | |
| 357 EXPECT_EQ(expected_send_window, sender_->GetCongestionWindow()); | |
| 358 LoseNPackets(5); | |
| 359 EXPECT_EQ(expected_send_window, sender_->GetCongestionWindow()); | |
| 360 } | |
| 361 | |
| 362 TEST_F(TcpCubicSenderBytesTest, NoPRRWhenLessThanOnePacketInFlight) { | |
| 363 SendAvailableSendWindow(); | |
| 364 LoseNPackets(kInitialCongestionWindowPackets - 1); | |
| 365 AckNPackets(1); | |
| 366 // PRR will allow 2 packets for every ack during recovery. | |
| 367 EXPECT_EQ(2, SendAvailableSendWindow()); | |
| 368 // Simulate abandoning all packets by supplying a bytes_in_flight of 0. | |
| 369 // PRR should now allow a packet to be sent, even though prr's state variables | |
| 370 // believe it has sent enough packets. | |
| 371 EXPECT_EQ(QuicTime::Delta::Zero(), sender_->TimeUntilSend(clock_.Now(), 0)); | |
| 372 } | |
| 373 | |
| 374 TEST_F(TcpCubicSenderBytesTest, SlowStartPacketLossPRR) { | |
| 375 sender_->SetNumEmulatedConnections(1); | |
| 376 // Test based on the first example in RFC6937. | |
| 377 // Ack 10 packets in 5 acks to raise the CWND to 20, as in the example. | |
| 378 const int kNumberOfAcks = 5; | |
| 379 for (int i = 0; i < kNumberOfAcks; ++i) { | |
| 380 // Send our full send window. | |
| 381 SendAvailableSendWindow(); | |
| 382 AckNPackets(2); | |
| 383 } | |
| 384 SendAvailableSendWindow(); | |
| 385 QuicByteCount expected_send_window = | |
| 386 kDefaultWindowTCP + (kDefaultTCPMSS * 2 * kNumberOfAcks); | |
| 387 EXPECT_EQ(expected_send_window, sender_->GetCongestionWindow()); | |
| 388 | |
| 389 LoseNPackets(1); | |
| 390 | |
| 391 // We should now have fallen out of slow start with a reduced window. | |
| 392 size_t send_window_before_loss = expected_send_window; | |
| 393 expected_send_window *= kRenoBeta; | |
| 394 EXPECT_EQ(expected_send_window, sender_->GetCongestionWindow()); | |
| 395 | |
| 396 // Testing TCP proportional rate reduction. | |
| 397 // We should send packets paced over the received acks for the remaining | |
| 398 // outstanding packets. The number of packets before we exit recovery is the | |
| 399 // original CWND minus the packet that has been lost and the one which | |
| 400 // triggered the loss. | |
| 401 size_t remaining_packets_in_recovery = | |
| 402 send_window_before_loss / kDefaultTCPMSS - 2; | |
| 403 | |
| 404 for (size_t i = 0; i < remaining_packets_in_recovery; ++i) { | |
| 405 AckNPackets(1); | |
| 406 SendAvailableSendWindow(); | |
| 407 EXPECT_EQ(expected_send_window, sender_->GetCongestionWindow()); | |
| 408 } | |
| 409 | |
| 410 // We need to ack another window before we increase CWND by 1. | |
| 411 size_t number_of_packets_in_window = expected_send_window / kDefaultTCPMSS; | |
| 412 for (size_t i = 0; i < number_of_packets_in_window; ++i) { | |
| 413 AckNPackets(1); | |
| 414 EXPECT_EQ(1, SendAvailableSendWindow()); | |
| 415 EXPECT_EQ(expected_send_window, sender_->GetCongestionWindow()); | |
| 416 } | |
| 417 | |
| 418 AckNPackets(1); | |
| 419 expected_send_window += kDefaultTCPMSS; | |
| 420 EXPECT_EQ(expected_send_window, sender_->GetCongestionWindow()); | |
| 421 } | |
| 422 | |
| 423 TEST_F(TcpCubicSenderBytesTest, SlowStartBurstPacketLossPRR) { | |
| 424 sender_->SetNumEmulatedConnections(1); | |
| 425 // Test based on the second example in RFC6937, though we also implement | |
| 426 // forward acknowledgements, so the first two incoming acks will trigger | |
| 427 // PRR immediately. | |
| 428 // Ack 20 packets in 10 acks to raise the CWND to 30. | |
| 429 const int kNumberOfAcks = 10; | |
| 430 for (int i = 0; i < kNumberOfAcks; ++i) { | |
| 431 // Send our full send window. | |
| 432 SendAvailableSendWindow(); | |
| 433 AckNPackets(2); | |
| 434 } | |
| 435 SendAvailableSendWindow(); | |
| 436 QuicByteCount expected_send_window = | |
| 437 kDefaultWindowTCP + (kDefaultTCPMSS * 2 * kNumberOfAcks); | |
| 438 EXPECT_EQ(expected_send_window, sender_->GetCongestionWindow()); | |
| 439 | |
| 440 // Lose one more than the congestion window reduction, so that after loss, | |
| 441 // bytes_in_flight is lesser than the congestion window. | |
| 442 size_t send_window_after_loss = kRenoBeta * expected_send_window; | |
| 443 size_t num_packets_to_lose = | |
| 444 (expected_send_window - send_window_after_loss) / kDefaultTCPMSS + 1; | |
| 445 LoseNPackets(num_packets_to_lose); | |
| 446 // Immediately after the loss, ensure at least one packet can be sent. | |
| 447 // Losses without subsequent acks can occur with timer based loss detection. | |
| 448 EXPECT_TRUE(sender_->TimeUntilSend(clock_.Now(), bytes_in_flight_).IsZero()); | |
| 449 AckNPackets(1); | |
| 450 | |
| 451 // We should now have fallen out of slow start with a reduced window. | |
| 452 expected_send_window *= kRenoBeta; | |
| 453 EXPECT_EQ(expected_send_window, sender_->GetCongestionWindow()); | |
| 454 | |
| 455 // Only 2 packets should be allowed to be sent, per PRR-SSRB. | |
| 456 EXPECT_EQ(2, SendAvailableSendWindow()); | |
| 457 | |
| 458 // Ack the next packet, which triggers another loss. | |
| 459 LoseNPackets(1); | |
| 460 AckNPackets(1); | |
| 461 | |
| 462 // Send 2 packets to simulate PRR-SSRB. | |
| 463 EXPECT_EQ(2, SendAvailableSendWindow()); | |
| 464 | |
| 465 // Ack the next packet, which triggers another loss. | |
| 466 LoseNPackets(1); | |
| 467 AckNPackets(1); | |
| 468 | |
| 469 // Send 2 packets to simulate PRR-SSRB. | |
| 470 EXPECT_EQ(2, SendAvailableSendWindow()); | |
| 471 | |
| 472 // Exit recovery and return to sending at the new rate. | |
| 473 for (int i = 0; i < kNumberOfAcks; ++i) { | |
| 474 AckNPackets(1); | |
| 475 EXPECT_EQ(1, SendAvailableSendWindow()); | |
| 476 } | |
| 477 } | |
| 478 | |
| 479 TEST_F(TcpCubicSenderBytesTest, RTOCongestionWindow) { | |
| 480 EXPECT_EQ(kDefaultWindowTCP, sender_->GetCongestionWindow()); | |
| 481 // Expect the window to decrease to the minimum once the RTO fires and slow | |
| 482 // start threshold to be set to 1/2 of the CWND. | |
| 483 sender_->OnRetransmissionTimeout(true); | |
| 484 EXPECT_EQ(2 * kDefaultTCPMSS, sender_->GetCongestionWindow()); | |
| 485 EXPECT_EQ(5u * kDefaultTCPMSS, sender_->GetSlowStartThreshold()); | |
| 486 } | |
| 487 | |
| 488 TEST_F(TcpCubicSenderBytesTest, RTOCongestionWindowNoRetransmission) { | |
| 489 EXPECT_EQ(kDefaultWindowTCP, sender_->GetCongestionWindow()); | |
| 490 | |
| 491 // Expect the window to remain unchanged if the RTO fires but no packets are | |
| 492 // retransmitted. | |
| 493 sender_->OnRetransmissionTimeout(false); | |
| 494 EXPECT_EQ(kDefaultWindowTCP, sender_->GetCongestionWindow()); | |
| 495 } | |
| 496 | |
| 497 TEST_F(TcpCubicSenderBytesTest, RetransmissionDelay) { | |
| 498 const int64_t kRttMs = 10; | |
| 499 const int64_t kDeviationMs = 3; | |
| 500 EXPECT_EQ(QuicTime::Delta::Zero(), sender_->RetransmissionDelay()); | |
| 501 | |
| 502 sender_->rtt_stats_.UpdateRtt(QuicTime::Delta::FromMilliseconds(kRttMs), | |
| 503 QuicTime::Delta::Zero(), clock_.Now()); | |
| 504 | |
| 505 // Initial value is to set the median deviation to half of the initial rtt, | |
| 506 // the median in then multiplied by a factor of 4 and finally the smoothed rtt | |
| 507 // is added which is the initial rtt. | |
| 508 QuicTime::Delta expected_delay = | |
| 509 QuicTime::Delta::FromMilliseconds(kRttMs + kRttMs / 2 * 4); | |
| 510 EXPECT_EQ(expected_delay, sender_->RetransmissionDelay()); | |
| 511 | |
| 512 for (int i = 0; i < 100; ++i) { | |
| 513 // Run to make sure that we converge. | |
| 514 sender_->rtt_stats_.UpdateRtt( | |
| 515 QuicTime::Delta::FromMilliseconds(kRttMs + kDeviationMs), | |
| 516 QuicTime::Delta::Zero(), clock_.Now()); | |
| 517 sender_->rtt_stats_.UpdateRtt( | |
| 518 QuicTime::Delta::FromMilliseconds(kRttMs - kDeviationMs), | |
| 519 QuicTime::Delta::Zero(), clock_.Now()); | |
| 520 } | |
| 521 expected_delay = QuicTime::Delta::FromMilliseconds(kRttMs + kDeviationMs * 4); | |
| 522 | |
| 523 EXPECT_NEAR(kRttMs, sender_->rtt_stats_.smoothed_rtt().ToMilliseconds(), 1); | |
| 524 EXPECT_NEAR(expected_delay.ToMilliseconds(), | |
| 525 sender_->RetransmissionDelay().ToMilliseconds(), 1); | |
| 526 EXPECT_EQ(static_cast<int64_t>( | |
| 527 sender_->GetCongestionWindow() * kNumMicrosPerSecond / | |
| 528 sender_->rtt_stats_.smoothed_rtt().ToMicroseconds()), | |
| 529 sender_->BandwidthEstimate().ToBytesPerSecond()); | |
| 530 } | |
| 531 | |
| 532 TEST_F(TcpCubicSenderBytesTest, TcpCubicResetEpochOnQuiescence) { | |
| 533 const int kMaxCongestionWindow = 50; | |
| 534 const QuicByteCount kMaxCongestionWindowBytes = | |
| 535 kMaxCongestionWindow * kDefaultTCPMSS; | |
| 536 int num_sent = SendAvailableSendWindow(); | |
| 537 | |
| 538 // Make sure we fall out of slow start. | |
| 539 QuicByteCount saved_cwnd = sender_->GetCongestionWindow(); | |
| 540 LoseNPackets(1); | |
| 541 EXPECT_GT(saved_cwnd, sender_->GetCongestionWindow()); | |
| 542 | |
| 543 // Ack the rest of the outstanding packets to get out of recovery. | |
| 544 for (int i = 1; i < num_sent; ++i) { | |
| 545 AckNPackets(1); | |
| 546 } | |
| 547 EXPECT_EQ(0u, bytes_in_flight_); | |
| 548 | |
| 549 // Send a new window of data and ack all; cubic growth should occur. | |
| 550 saved_cwnd = sender_->GetCongestionWindow(); | |
| 551 num_sent = SendAvailableSendWindow(); | |
| 552 for (int i = 0; i < num_sent; ++i) { | |
| 553 AckNPackets(1); | |
| 554 } | |
| 555 EXPECT_LT(saved_cwnd, sender_->GetCongestionWindow()); | |
| 556 EXPECT_GT(kMaxCongestionWindowBytes, sender_->GetCongestionWindow()); | |
| 557 EXPECT_EQ(0u, bytes_in_flight_); | |
| 558 | |
| 559 // Quiescent time of 100 seconds | |
| 560 clock_.AdvanceTime(QuicTime::Delta::FromMilliseconds(100000)); | |
| 561 | |
| 562 // Send new window of data and ack one packet. Cubic epoch should have | |
| 563 // been reset; ensure cwnd increase is not dramatic. | |
| 564 saved_cwnd = sender_->GetCongestionWindow(); | |
| 565 SendAvailableSendWindow(); | |
| 566 AckNPackets(1); | |
| 567 EXPECT_NEAR(saved_cwnd, sender_->GetCongestionWindow(), kDefaultTCPMSS); | |
| 568 EXPECT_GT(kMaxCongestionWindowBytes, sender_->GetCongestionWindow()); | |
| 569 } | |
| 570 | |
| 571 TEST_F(TcpCubicSenderBytesTest, MultipleLossesInOneWindow) { | |
| 572 SendAvailableSendWindow(); | |
| 573 const QuicByteCount initial_window = sender_->GetCongestionWindow(); | |
| 574 LosePacket(acked_packet_number_ + 1); | |
| 575 const QuicByteCount post_loss_window = sender_->GetCongestionWindow(); | |
| 576 EXPECT_GT(initial_window, post_loss_window); | |
| 577 LosePacket(acked_packet_number_ + 3); | |
| 578 EXPECT_EQ(post_loss_window, sender_->GetCongestionWindow()); | |
| 579 LosePacket(packet_number_ - 1); | |
| 580 EXPECT_EQ(post_loss_window, sender_->GetCongestionWindow()); | |
| 581 | |
| 582 // Lose a later packet and ensure the window decreases. | |
| 583 LosePacket(packet_number_); | |
| 584 EXPECT_GT(post_loss_window, sender_->GetCongestionWindow()); | |
| 585 } | |
| 586 | |
| 587 TEST_F(TcpCubicSenderBytesTest, DontTrackAckPackets) { | |
| 588 // Send a packet with no retransmittable data, and ensure it's not tracked. | |
| 589 EXPECT_FALSE(sender_->OnPacketSent(clock_.Now(), bytes_in_flight_, | |
| 590 packet_number_++, kDefaultTCPMSS, | |
| 591 NO_RETRANSMITTABLE_DATA)); | |
| 592 | |
| 593 // Send a data packet with retransmittable data, and ensure it is tracked. | |
| 594 EXPECT_TRUE(sender_->OnPacketSent(clock_.Now(), bytes_in_flight_, | |
| 595 packet_number_++, kDefaultTCPMSS, | |
| 596 HAS_RETRANSMITTABLE_DATA)); | |
| 597 } | |
| 598 | |
| 599 TEST_F(TcpCubicSenderBytesTest, ConfigureMaxInitialWindow) { | |
| 600 QuicConfig config; | |
| 601 | |
| 602 // Verify that kCOPT: kIW10 forces the congestion window to the default of 10. | |
| 603 QuicTagVector options; | |
| 604 options.push_back(kIW10); | |
| 605 QuicConfigPeer::SetReceivedConnectionOptions(&config, options); | |
| 606 sender_->SetFromConfig(config, Perspective::IS_SERVER); | |
| 607 EXPECT_EQ(10u * kDefaultTCPMSS, sender_->GetCongestionWindow()); | |
| 608 } | |
| 609 | |
| 610 TEST_F(TcpCubicSenderBytesTest, 2ConnectionCongestionAvoidanceAtEndOfRecovery) { | |
| 611 sender_->SetNumEmulatedConnections(2); | |
| 612 // Ack 10 packets in 5 acks to raise the CWND to 20. | |
| 613 const int kNumberOfAcks = 5; | |
| 614 for (int i = 0; i < kNumberOfAcks; ++i) { | |
| 615 // Send our full send window. | |
| 616 SendAvailableSendWindow(); | |
| 617 AckNPackets(2); | |
| 618 } | |
| 619 SendAvailableSendWindow(); | |
| 620 QuicByteCount expected_send_window = | |
| 621 kDefaultWindowTCP + (kDefaultTCPMSS * 2 * kNumberOfAcks); | |
| 622 EXPECT_EQ(expected_send_window, sender_->GetCongestionWindow()); | |
| 623 | |
| 624 LoseNPackets(1); | |
| 625 | |
| 626 // We should now have fallen out of slow start with a reduced window. | |
| 627 expected_send_window = expected_send_window * sender_->GetRenoBeta(); | |
| 628 EXPECT_EQ(expected_send_window, sender_->GetCongestionWindow()); | |
| 629 | |
| 630 // No congestion window growth should occur in recovery phase, i.e., until the | |
| 631 // currently outstanding 20 packets are acked. | |
| 632 for (int i = 0; i < 10; ++i) { | |
| 633 // Send our full send window. | |
| 634 SendAvailableSendWindow(); | |
| 635 EXPECT_TRUE(sender_->InRecovery()); | |
| 636 AckNPackets(2); | |
| 637 EXPECT_EQ(expected_send_window, sender_->GetCongestionWindow()); | |
| 638 } | |
| 639 EXPECT_FALSE(sender_->InRecovery()); | |
| 640 | |
| 641 // Out of recovery now. Congestion window should not grow for half an RTT. | |
| 642 size_t packets_in_send_window = expected_send_window / kDefaultTCPMSS; | |
| 643 SendAvailableSendWindow(); | |
| 644 AckNPackets(packets_in_send_window / 2 - 2); | |
| 645 EXPECT_EQ(expected_send_window, sender_->GetCongestionWindow()); | |
| 646 | |
| 647 // Next ack should increase congestion window by 1MSS. | |
| 648 SendAvailableSendWindow(); | |
| 649 AckNPackets(2); | |
| 650 expected_send_window += kDefaultTCPMSS; | |
| 651 packets_in_send_window += 1; | |
| 652 EXPECT_EQ(expected_send_window, sender_->GetCongestionWindow()); | |
| 653 | |
| 654 // Congestion window should remain steady again for half an RTT. | |
| 655 SendAvailableSendWindow(); | |
| 656 AckNPackets(packets_in_send_window / 2 - 1); | |
| 657 EXPECT_EQ(expected_send_window, sender_->GetCongestionWindow()); | |
| 658 | |
| 659 // Next ack should cause congestion window to grow by 1MSS. | |
| 660 SendAvailableSendWindow(); | |
| 661 AckNPackets(2); | |
| 662 expected_send_window += kDefaultTCPMSS; | |
| 663 EXPECT_EQ(expected_send_window, sender_->GetCongestionWindow()); | |
| 664 } | |
| 665 | |
| 666 TEST_F(TcpCubicSenderBytesTest, 1ConnectionCongestionAvoidanceAtEndOfRecovery) { | |
| 667 sender_->SetNumEmulatedConnections(1); | |
| 668 // Ack 10 packets in 5 acks to raise the CWND to 20. | |
| 669 const int kNumberOfAcks = 5; | |
| 670 for (int i = 0; i < kNumberOfAcks; ++i) { | |
| 671 // Send our full send window. | |
| 672 SendAvailableSendWindow(); | |
| 673 AckNPackets(2); | |
| 674 } | |
| 675 SendAvailableSendWindow(); | |
| 676 QuicByteCount expected_send_window = | |
| 677 kDefaultWindowTCP + (kDefaultTCPMSS * 2 * kNumberOfAcks); | |
| 678 EXPECT_EQ(expected_send_window, sender_->GetCongestionWindow()); | |
| 679 | |
| 680 LoseNPackets(1); | |
| 681 | |
| 682 // We should now have fallen out of slow start with a reduced window. | |
| 683 expected_send_window *= kRenoBeta; | |
| 684 EXPECT_EQ(expected_send_window, sender_->GetCongestionWindow()); | |
| 685 | |
| 686 // No congestion window growth should occur in recovery phase, i.e., until the | |
| 687 // currently outstanding 20 packets are acked. | |
| 688 for (int i = 0; i < 10; ++i) { | |
| 689 // Send our full send window. | |
| 690 SendAvailableSendWindow(); | |
| 691 EXPECT_TRUE(sender_->InRecovery()); | |
| 692 AckNPackets(2); | |
| 693 EXPECT_EQ(expected_send_window, sender_->GetCongestionWindow()); | |
| 694 } | |
| 695 EXPECT_FALSE(sender_->InRecovery()); | |
| 696 | |
| 697 // Out of recovery now. Congestion window should not grow during RTT. | |
| 698 for (uint64_t i = 0; i < expected_send_window / kDefaultTCPMSS - 2; i += 2) { | |
| 699 // Send our full send window. | |
| 700 SendAvailableSendWindow(); | |
| 701 AckNPackets(2); | |
| 702 EXPECT_EQ(expected_send_window, sender_->GetCongestionWindow()); | |
| 703 } | |
| 704 | |
| 705 // Next ack should cause congestion window to grow by 1MSS. | |
| 706 SendAvailableSendWindow(); | |
| 707 AckNPackets(2); | |
| 708 expected_send_window += kDefaultTCPMSS; | |
| 709 EXPECT_EQ(expected_send_window, sender_->GetCongestionWindow()); | |
| 710 } | |
| 711 | |
| 712 TEST_F(TcpCubicSenderBytesTest, BandwidthResumption) { | |
| 713 // Test that when provided with CachedNetworkParameters and opted in to the | |
| 714 // bandwidth resumption experiment, that the TcpCubicSender sets initial CWND | |
| 715 // appropriately. | |
| 716 | |
| 717 // Set some common values. | |
| 718 CachedNetworkParameters cached_network_params; | |
| 719 const QuicPacketCount kNumberOfPackets = 123; | |
| 720 const int kBandwidthEstimateBytesPerSecond = | |
| 721 kNumberOfPackets * kDefaultTCPMSS; | |
| 722 cached_network_params.set_bandwidth_estimate_bytes_per_second( | |
| 723 kBandwidthEstimateBytesPerSecond); | |
| 724 cached_network_params.set_min_rtt_ms(1000); | |
| 725 | |
| 726 // Make sure that a bandwidth estimate results in a changed CWND. | |
| 727 cached_network_params.set_timestamp(clock_.WallNow().ToUNIXSeconds() - | |
| 728 (kNumSecondsPerHour - 1)); | |
| 729 sender_->ResumeConnectionState(cached_network_params, false); | |
| 730 EXPECT_EQ(kNumberOfPackets * kDefaultTCPMSS, sender_->GetCongestionWindow()); | |
| 731 | |
| 732 // Resumed CWND is limited to be in a sensible range. | |
| 733 cached_network_params.set_bandwidth_estimate_bytes_per_second( | |
| 734 (kMaxCongestionWindowPackets + 1) * kDefaultTCPMSS); | |
| 735 sender_->ResumeConnectionState(cached_network_params, false); | |
| 736 EXPECT_EQ(kMaxCongestionWindowPackets * kDefaultTCPMSS, | |
| 737 sender_->GetCongestionWindow()); | |
| 738 | |
| 739 if (FLAGS_quic_no_lower_bw_resumption_limit) { | |
| 740 // Resume with an illegal value of 0 and verify the server uses 1 instead. | |
| 741 cached_network_params.set_bandwidth_estimate_bytes_per_second(0); | |
| 742 sender_->ResumeConnectionState(cached_network_params, false); | |
| 743 EXPECT_EQ(sender_->min_congestion_window(), sender_->GetCongestionWindow()); | |
| 744 } else { | |
| 745 cached_network_params.set_bandwidth_estimate_bytes_per_second( | |
| 746 (kMinCongestionWindowForBandwidthResumption - 1) * kDefaultTCPMSS); | |
| 747 sender_->ResumeConnectionState(cached_network_params, false); | |
| 748 EXPECT_EQ(kMinCongestionWindowForBandwidthResumption * kDefaultTCPMSS, | |
| 749 sender_->GetCongestionWindow()); | |
| 750 } | |
| 751 | |
| 752 // Resume to the max value. | |
| 753 cached_network_params.set_max_bandwidth_estimate_bytes_per_second( | |
| 754 kMaxCongestionWindowPackets * kDefaultTCPMSS); | |
| 755 sender_->ResumeConnectionState(cached_network_params, true); | |
| 756 EXPECT_EQ(kMaxCongestionWindowPackets * kDefaultTCPMSS, | |
| 757 sender_->GetCongestionWindow()); | |
| 758 } | |
| 759 | |
| 760 TEST_F(TcpCubicSenderBytesTest, PaceBelowCWND) { | |
| 761 QuicConfig config; | |
| 762 | |
| 763 // Verify that kCOPT: kMIN4 forces the min CWND to 1 packet, but allows up | |
| 764 // to 4 to be sent. | |
| 765 QuicTagVector options; | |
| 766 options.push_back(kMIN4); | |
| 767 QuicConfigPeer::SetReceivedConnectionOptions(&config, options); | |
| 768 sender_->SetFromConfig(config, Perspective::IS_SERVER); | |
| 769 sender_->OnRetransmissionTimeout(true); | |
| 770 EXPECT_EQ(kDefaultTCPMSS, sender_->GetCongestionWindow()); | |
| 771 EXPECT_TRUE( | |
| 772 sender_->TimeUntilSend(QuicTime::Zero(), kDefaultTCPMSS).IsZero()); | |
| 773 EXPECT_TRUE( | |
| 774 sender_->TimeUntilSend(QuicTime::Zero(), 2 * kDefaultTCPMSS).IsZero()); | |
| 775 EXPECT_TRUE( | |
| 776 sender_->TimeUntilSend(QuicTime::Zero(), 3 * kDefaultTCPMSS).IsZero()); | |
| 777 EXPECT_FALSE( | |
| 778 sender_->TimeUntilSend(QuicTime::Zero(), 4 * kDefaultTCPMSS).IsZero()); | |
| 779 } | |
| 780 | |
| 781 TEST_F(TcpCubicSenderBytesTest, NoPRR) { | |
| 782 QuicTime::Delta rtt = QuicTime::Delta::FromMilliseconds(100); | |
| 783 sender_->rtt_stats_.UpdateRtt(rtt, QuicTime::Delta::Zero(), QuicTime::Zero()); | |
| 784 | |
| 785 sender_->SetNumEmulatedConnections(1); | |
| 786 // Verify that kCOPT: kNPRR allows all packets to be sent, even if only one | |
| 787 // ack has been received. | |
| 788 QuicTagVector options; | |
| 789 options.push_back(kNPRR); | |
| 790 QuicConfig config; | |
| 791 QuicConfigPeer::SetReceivedConnectionOptions(&config, options); | |
| 792 sender_->SetFromConfig(config, Perspective::IS_SERVER); | |
| 793 SendAvailableSendWindow(); | |
| 794 LoseNPackets(9); | |
| 795 AckNPackets(1); | |
| 796 | |
| 797 // We should now have fallen out of slow start with a reduced window. | |
| 798 EXPECT_EQ(kRenoBeta * kDefaultWindowTCP, sender_->GetCongestionWindow()); | |
| 799 const QuicPacketCount window_in_packets = | |
| 800 kRenoBeta * kDefaultWindowTCP / kDefaultTCPMSS; | |
| 801 const QuicBandwidth expected_pacing_rate = | |
| 802 QuicBandwidth::FromBytesAndTimeDelta(kRenoBeta * kDefaultWindowTCP, | |
| 803 sender_->rtt_stats_.smoothed_rtt()); | |
| 804 EXPECT_EQ(expected_pacing_rate, sender_->PacingRate(0)); | |
| 805 EXPECT_EQ(window_in_packets, | |
| 806 static_cast<uint64_t>(SendAvailableSendWindow())); | |
| 807 EXPECT_EQ(expected_pacing_rate, | |
| 808 sender_->PacingRate(kRenoBeta * kDefaultWindowTCP)); | |
| 809 } | |
| 810 | |
| 811 TEST_F(TcpCubicSenderBytesTest, PaceSlowerAboveCwnd) { | |
| 812 ValueRestore<bool> old_flag(&FLAGS_quic_rate_based_sending, true); | |
| 813 QuicTime::Delta rtt(QuicTime::Delta::FromMilliseconds(60)); | |
| 814 sender_->rtt_stats_.UpdateRtt(rtt, QuicTime::Delta::Zero(), clock_.Now()); | |
| 815 | |
| 816 QuicConfig config; | |
| 817 QuicTagVector options; | |
| 818 options.push_back(kRATE); | |
| 819 QuicConfigPeer::SetReceivedConnectionOptions(&config, options); | |
| 820 sender_->SetFromConfig(config, Perspective::IS_SERVER); | |
| 821 EXPECT_EQ(10 * kDefaultTCPMSS, sender_->GetCongestionWindow()); | |
| 822 sender_->SetNumEmulatedConnections(1); | |
| 823 // Lose a packet to exit slow start. | |
| 824 LoseNPackets(1); | |
| 825 const QuicPacketCount cwnd = 7; | |
| 826 EXPECT_EQ(cwnd * kDefaultTCPMSS, sender_->GetCongestionWindow()); | |
| 827 | |
| 828 EXPECT_TRUE( | |
| 829 sender_->TimeUntilSend(QuicTime::Zero(), kDefaultTCPMSS).IsZero()); | |
| 830 EXPECT_EQ( | |
| 831 sender_->PacingRate(kDefaultTCPMSS), | |
| 832 QuicBandwidth::FromBytesAndTimeDelta(7 * kDefaultTCPMSS, rtt) * 1.25); | |
| 833 for (QuicPacketCount i = cwnd + 1; i < 1.5 * cwnd; ++i) { | |
| 834 EXPECT_TRUE( | |
| 835 sender_->TimeUntilSend(QuicTime::Zero(), i * kDefaultTCPMSS).IsZero()); | |
| 836 EXPECT_EQ(sender_->PacingRate(i * kDefaultTCPMSS), | |
| 837 QuicBandwidth::FromBytesAndTimeDelta(cwnd * kDefaultTCPMSS, rtt) * | |
| 838 0.75); | |
| 839 } | |
| 840 EXPECT_FALSE( | |
| 841 sender_->TimeUntilSend(QuicTime::Zero(), 11 * kDefaultTCPMSS).IsZero()); | |
| 842 } | |
| 843 | |
| 844 TEST_F(TcpCubicSenderBytesTest, ResetAfterConnectionMigration) { | |
| 845 // Starts from slow start. | |
| 846 sender_->SetNumEmulatedConnections(1); | |
| 847 const int kNumberOfAcks = 10; | |
| 848 for (int i = 0; i < kNumberOfAcks; ++i) { | |
| 849 // Send our full send window. | |
| 850 SendAvailableSendWindow(); | |
| 851 AckNPackets(2); | |
| 852 } | |
| 853 SendAvailableSendWindow(); | |
| 854 QuicByteCount expected_send_window = | |
| 855 kDefaultWindowTCP + (kDefaultTCPMSS * 2 * kNumberOfAcks); | |
| 856 EXPECT_EQ(expected_send_window, sender_->GetCongestionWindow()); | |
| 857 | |
| 858 // Loses a packet to exit slow start. | |
| 859 LoseNPackets(1); | |
| 860 | |
| 861 // We should now have fallen out of slow start with a reduced window. Slow | |
| 862 // start threshold is also updated. | |
| 863 expected_send_window *= kRenoBeta; | |
| 864 EXPECT_EQ(expected_send_window, sender_->GetCongestionWindow()); | |
| 865 EXPECT_EQ(expected_send_window, sender_->GetSlowStartThreshold()); | |
| 866 | |
| 867 // Resets cwnd and slow start threshold on connection migrations. | |
| 868 sender_->OnConnectionMigration(); | |
| 869 EXPECT_EQ(kDefaultWindowTCP, sender_->GetCongestionWindow()); | |
| 870 EXPECT_EQ(kMaxCongestionWindowPackets * kDefaultTCPMSS, | |
| 871 sender_->GetSlowStartThreshold()); | |
| 872 EXPECT_FALSE(sender_->hybrid_slow_start().started()); | |
| 873 } | |
| 874 | |
| 875 TEST_F(TcpCubicSenderBytesTest, DefaultMaxCwnd) { | |
| 876 RttStats rtt_stats; | |
| 877 QuicConnectionStats stats; | |
| 878 std::unique_ptr<SendAlgorithmInterface> sender(SendAlgorithmInterface::Create( | |
| 879 &clock_, &rtt_stats, kCubicBytes, &stats, kInitialCongestionWindow)); | |
| 880 | |
| 881 SendAlgorithmInterface::CongestionVector acked_packets; | |
| 882 SendAlgorithmInterface::CongestionVector missing_packets; | |
| 883 for (uint64_t i = 1; i < kDefaultMaxCongestionWindowPackets; ++i) { | |
| 884 acked_packets.clear(); | |
| 885 acked_packets.push_back(std::make_pair(i, 1350)); | |
| 886 sender->OnCongestionEvent(true, sender->GetCongestionWindow(), | |
| 887 acked_packets, missing_packets); | |
| 888 } | |
| 889 EXPECT_EQ(kDefaultMaxCongestionWindowPackets, | |
| 890 sender->GetCongestionWindow() / kDefaultTCPMSS); | |
| 891 } | |
| 892 | |
| 893 } // namespace test | |
| 894 } // namespace net | |
| OLD | NEW |