Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(11)

Side by Side Diff: net/quic/quic_connection_test.cc

Issue 841603005: Change QUIC's RTO implementation. Protected by FLAGS_quic_use_new_rto. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@Remove_transmission_stats_83598791
Patch Set: Merge internal change: 83966746 Created 5 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | net/quic/quic_flags.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/quic_connection.h" 5 #include "net/quic/quic_connection.h"
6 6
7 #include "base/basictypes.h" 7 #include "base/basictypes.h"
8 #include "base/bind.h" 8 #include "base/bind.h"
9 #include "base/stl_util.h" 9 #include "base/stl_util.h"
10 #include "net/base/net_errors.h" 10 #include "net/base/net_errors.h"
(...skipping 1743 matching lines...) Expand 10 before | Expand all | Expand 10 after
1754 // packet is retransmitted, and this retransmission (but not FEC) gets added 1754 // packet is retransmitted, and this retransmission (but not FEC) gets added
1755 // back into the inflight. 1755 // back into the inflight.
1756 EXPECT_CALL(*send_algorithm_, OnRetransmissionTimeout(true)); 1756 EXPECT_CALL(*send_algorithm_, OnRetransmissionTimeout(true));
1757 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(1); 1757 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(1);
1758 connection_.GetRetransmissionAlarm()->Fire(); 1758 connection_.GetRetransmissionAlarm()->Fire();
1759 1759
1760 // The retransmission of packet 1 will be 3 bytes smaller than packet 1, since 1760 // The retransmission of packet 1 will be 3 bytes smaller than packet 1, since
1761 // the first transmission will have 1 byte for FEC group number and 2 bytes of 1761 // the first transmission will have 1 byte for FEC group number and 2 bytes of
1762 // stream frame size, which are absent in the retransmission. 1762 // stream frame size, which are absent in the retransmission.
1763 size_t retransmitted_packet = protected_packet - 3; 1763 size_t retransmitted_packet = protected_packet - 3;
1764 EXPECT_EQ(retransmitted_packet, 1764 if (FLAGS_quic_use_new_rto) {
1765 QuicSentPacketManagerPeer::GetBytesInFlight(manager_)); 1765 EXPECT_EQ(protected_packet + retransmitted_packet,
1766 QuicSentPacketManagerPeer::GetBytesInFlight(manager_));
1767 } else {
1768 EXPECT_EQ(retransmitted_packet,
1769 QuicSentPacketManagerPeer::GetBytesInFlight(manager_));
1770 }
1766 EXPECT_FALSE(connection_.GetFecAlarm()->IsSet()); 1771 EXPECT_FALSE(connection_.GetFecAlarm()->IsSet());
1767 1772
1768 // Receive ack for the retransmission. No data should be outstanding. 1773 // Receive ack for the retransmission. No data should be outstanding.
1769 QuicAckFrame ack = InitAckFrame(3); 1774 QuicAckFrame ack = InitAckFrame(3);
1770 NackPacket(1, &ack); 1775 NackPacket(1, &ack);
1771 NackPacket(2, &ack); 1776 NackPacket(2, &ack);
1772 SequenceNumberSet lost_packets; 1777 SequenceNumberSet lost_packets;
1778 if (FLAGS_quic_use_new_rto) {
1779 lost_packets.insert(1);
1780 }
1773 EXPECT_CALL(*loss_algorithm_, DetectLostPackets(_, _, _, _)) 1781 EXPECT_CALL(*loss_algorithm_, DetectLostPackets(_, _, _, _))
1774 .WillOnce(Return(lost_packets)); 1782 .WillOnce(Return(lost_packets));
1775 EXPECT_CALL(*send_algorithm_, OnCongestionEvent(true, _, _, _)); 1783 EXPECT_CALL(*send_algorithm_, OnCongestionEvent(true, _, _, _));
1776 ProcessAckPacket(&ack); 1784 ProcessAckPacket(&ack);
1777 EXPECT_EQ(0u, QuicSentPacketManagerPeer::GetBytesInFlight(manager_));
1778 1785
1779 // Ensure the alarm is not set since all packets have been acked or abandoned. 1786 // Ensure the alarm is not set since all packets have been acked or abandoned.
1780 EXPECT_FALSE(connection_.GetRetransmissionAlarm()->IsSet()); 1787 EXPECT_FALSE(connection_.GetRetransmissionAlarm()->IsSet());
1781 EXPECT_EQ(0u, QuicSentPacketManagerPeer::GetBytesInFlight(manager_)); 1788 EXPECT_EQ(0u, QuicSentPacketManagerPeer::GetBytesInFlight(manager_));
1782 } 1789 }
1783 1790
1784 TEST_P(QuicConnectionTest, RemoveFECFromInflightOnLossRetransmission) { 1791 TEST_P(QuicConnectionTest, RemoveFECFromInflightOnLossRetransmission) {
1785 EXPECT_TRUE(creator_->IsFecEnabled()); 1792 EXPECT_TRUE(creator_->IsFecEnabled());
1786 EXPECT_FALSE(connection_.GetFecAlarm()->IsSet()); 1793 EXPECT_FALSE(connection_.GetFecAlarm()->IsSet());
1787 1794
(...skipping 204 matching lines...) Expand 10 before | Expand all | Expand 10 after
1992 ProcessAckPacket(&ack); 1999 ProcessAckPacket(&ack);
1993 2000
1994 // No TLP alarm for FEC, but retransmission alarm should be set for an RTO. 2001 // No TLP alarm for FEC, but retransmission alarm should be set for an RTO.
1995 EXPECT_LT(0u, QuicSentPacketManagerPeer::GetBytesInFlight(manager_)); 2002 EXPECT_LT(0u, QuicSentPacketManagerPeer::GetBytesInFlight(manager_));
1996 EXPECT_TRUE(connection_.GetRetransmissionAlarm()->IsSet()); 2003 EXPECT_TRUE(connection_.GetRetransmissionAlarm()->IsSet());
1997 QuicTime rto_time = connection_.GetRetransmissionAlarm()->deadline(); 2004 QuicTime rto_time = connection_.GetRetransmissionAlarm()->deadline();
1998 EXPECT_NE(QuicTime::Zero(), rto_time); 2005 EXPECT_NE(QuicTime::Zero(), rto_time);
1999 2006
2000 // Simulate the retransmission alarm firing. FEC packet is no longer 2007 // Simulate the retransmission alarm firing. FEC packet is no longer
2001 // outstanding. 2008 // outstanding.
2002 EXPECT_CALL(*send_algorithm_, OnRetransmissionTimeout(false)); 2009 if (!FLAGS_quic_use_new_rto) {
2010 EXPECT_CALL(*send_algorithm_, OnRetransmissionTimeout(false));
2011 }
2003 clock_.AdvanceTime(rto_time.Subtract(clock_.Now())); 2012 clock_.AdvanceTime(rto_time.Subtract(clock_.Now()));
2004 connection_.GetRetransmissionAlarm()->Fire(); 2013 connection_.GetRetransmissionAlarm()->Fire();
2014
2005 EXPECT_FALSE(connection_.GetRetransmissionAlarm()->IsSet()); 2015 EXPECT_FALSE(connection_.GetRetransmissionAlarm()->IsSet());
2006 EXPECT_EQ(0u, QuicSentPacketManagerPeer::GetBytesInFlight(manager_)); 2016 EXPECT_EQ(0u, QuicSentPacketManagerPeer::GetBytesInFlight(manager_));
2007 } 2017 }
2008 2018
2009 TEST_P(QuicConnectionTest, FramePacking) { 2019 TEST_P(QuicConnectionTest, FramePacking) {
2010 CongestionBlockWrites(); 2020 CongestionBlockWrites();
2011 2021
2012 // Send an ack and two stream frames in 1 packet by queueing them. 2022 // Send an ack and two stream frames in 1 packet by queueing them.
2013 connection_.SendAck(); 2023 connection_.SendAck();
2014 EXPECT_CALL(visitor_, OnCanWrite()).WillOnce(DoAll( 2024 EXPECT_CALL(visitor_, OnCanWrite()).WillOnce(DoAll(
(...skipping 304 matching lines...) Expand 10 before | Expand all | Expand 10 after
2319 OnPacketSent(_, _, _, packet_size - kQuicVersionSize, _)); 2329 OnPacketSent(_, _, _, packet_size - kQuicVersionSize, _));
2320 ProcessAckPacket(&frame); 2330 ProcessAckPacket(&frame);
2321 } 2331 }
2322 2332
2323 TEST_P(QuicConnectionTest, QueueAfterTwoRTOs) { 2333 TEST_P(QuicConnectionTest, QueueAfterTwoRTOs) {
2324 for (int i = 0; i < 10; ++i) { 2334 for (int i = 0; i < 10; ++i) {
2325 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(1); 2335 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(1);
2326 connection_.SendStreamDataWithString(3, "foo", i * 3, !kFin, nullptr); 2336 connection_.SendStreamDataWithString(3, "foo", i * 3, !kFin, nullptr);
2327 } 2337 }
2328 2338
2329 // Block the congestion window and ensure they're queued. 2339 // Block the writer and ensure they're queued.
2330 BlockOnNextWrite(); 2340 BlockOnNextWrite();
2331 clock_.AdvanceTime(DefaultRetransmissionTime()); 2341 clock_.AdvanceTime(DefaultRetransmissionTime());
2332 // Only one packet should be retransmitted. 2342 // Only one packet should be retransmitted.
2333 EXPECT_CALL(*send_algorithm_, OnRetransmissionTimeout(true)); 2343 if (!FLAGS_quic_use_new_rto) {
2344 EXPECT_CALL(*send_algorithm_, OnRetransmissionTimeout(true));
2345 }
2334 connection_.GetRetransmissionAlarm()->Fire(); 2346 connection_.GetRetransmissionAlarm()->Fire();
2335 EXPECT_TRUE(connection_.HasQueuedData()); 2347 EXPECT_TRUE(connection_.HasQueuedData());
2336 2348
2337 // Unblock the congestion window. 2349 // Unblock the writer.
2338 writer_->SetWritable(); 2350 writer_->SetWritable();
2339 clock_.AdvanceTime(QuicTime::Delta::FromMicroseconds( 2351 clock_.AdvanceTime(QuicTime::Delta::FromMicroseconds(
2340 2 * DefaultRetransmissionTime().ToMicroseconds())); 2352 2 * DefaultRetransmissionTime().ToMicroseconds()));
2341 // Retransmit already retransmitted packets event though the sequence number 2353 // Retransmit already retransmitted packets event though the sequence number
2342 // greater than the largest observed. 2354 // greater than the largest observed.
2343 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(10); 2355 if (FLAGS_quic_use_new_rto) {
2356 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(2);
2357 } else {
2358 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(10);
2359 }
2344 connection_.GetRetransmissionAlarm()->Fire(); 2360 connection_.GetRetransmissionAlarm()->Fire();
2345 connection_.OnCanWrite(); 2361 connection_.OnCanWrite();
2346 } 2362 }
2347 2363
2348 TEST_P(QuicConnectionTest, WriteBlockedThenSent) { 2364 TEST_P(QuicConnectionTest, WriteBlockedThenSent) {
2349 BlockOnNextWrite(); 2365 BlockOnNextWrite();
2350 writer_->set_is_write_blocked_data_buffered(true); 2366 writer_->set_is_write_blocked_data_buffered(true);
2351 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(1); 2367 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(1);
2352 connection_.SendStreamDataWithString(1, "foo", 0, !kFin, nullptr); 2368 connection_.SendStreamDataWithString(1, "foo", 0, !kFin, nullptr);
2353 EXPECT_TRUE(connection_.GetRetransmissionAlarm()->IsSet()); 2369 EXPECT_TRUE(connection_.GetRetransmissionAlarm()->IsSet());
2354 2370
2355 writer_->SetWritable(); 2371 writer_->SetWritable();
2356 connection_.OnCanWrite(); 2372 connection_.OnCanWrite();
2357 EXPECT_TRUE(connection_.GetRetransmissionAlarm()->IsSet()); 2373 EXPECT_TRUE(connection_.GetRetransmissionAlarm()->IsSet());
2358 } 2374 }
2359 2375
2360 TEST_P(QuicConnectionTest, RetransmitWriteBlockedAckedOriginalThenSent) { 2376 TEST_P(QuicConnectionTest, RetransmitWriteBlockedAckedOriginalThenSent) {
2361 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); 2377 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_));
2362 connection_.SendStreamDataWithString(3, "foo", 0, !kFin, nullptr); 2378 connection_.SendStreamDataWithString(3, "foo", 0, !kFin, nullptr);
2363 EXPECT_TRUE(connection_.GetRetransmissionAlarm()->IsSet()); 2379 EXPECT_TRUE(connection_.GetRetransmissionAlarm()->IsSet());
2364 2380
2365 BlockOnNextWrite(); 2381 BlockOnNextWrite();
2366 writer_->set_is_write_blocked_data_buffered(true); 2382 writer_->set_is_write_blocked_data_buffered(true);
2367 // Simulate the retransmission alarm firing. 2383 // Simulate the retransmission alarm firing.
2368 EXPECT_CALL(*send_algorithm_, OnRetransmissionTimeout(_)); 2384 if (!FLAGS_quic_use_new_rto) {
2385 EXPECT_CALL(*send_algorithm_, OnRetransmissionTimeout(_));
2386 }
2369 clock_.AdvanceTime(DefaultRetransmissionTime()); 2387 clock_.AdvanceTime(DefaultRetransmissionTime());
2370 connection_.GetRetransmissionAlarm()->Fire(); 2388 connection_.GetRetransmissionAlarm()->Fire();
2371 2389
2372 // Ack the sent packet before the callback returns, which happens in 2390 // Ack the sent packet before the callback returns, which happens in
2373 // rare circumstances with write blocked sockets. 2391 // rare circumstances with write blocked sockets.
2374 QuicAckFrame ack = InitAckFrame(1); 2392 QuicAckFrame ack = InitAckFrame(1);
2375 EXPECT_CALL(*send_algorithm_, OnCongestionEvent(true, _, _, _)); 2393 EXPECT_CALL(*send_algorithm_, OnCongestionEvent(true, _, _, _));
2376 EXPECT_CALL(*send_algorithm_, RevertRetransmissionTimeout()); 2394 if (!FLAGS_quic_use_new_rto) {
2395 EXPECT_CALL(*send_algorithm_, RevertRetransmissionTimeout());
2396 }
2377 ProcessAckPacket(&ack); 2397 ProcessAckPacket(&ack);
2378 2398
2379 writer_->SetWritable(); 2399 writer_->SetWritable();
2380 connection_.OnCanWrite(); 2400 connection_.OnCanWrite();
2381 // There is now a pending packet, but with no retransmittable frames. 2401 // There is now a pending packet, but with no retransmittable frames.
2382 EXPECT_TRUE(connection_.GetRetransmissionAlarm()->IsSet()); 2402 EXPECT_TRUE(connection_.GetRetransmissionAlarm()->IsSet());
2383 EXPECT_FALSE(connection_.sent_packet_manager().HasRetransmittableFrames(2)); 2403 EXPECT_FALSE(connection_.sent_packet_manager().HasRetransmittableFrames(2));
2384 } 2404 }
2385 2405
2386 TEST_P(QuicConnectionTest, AlarmsWhenWriteBlocked) { 2406 TEST_P(QuicConnectionTest, AlarmsWhenWriteBlocked) {
(...skipping 264 matching lines...) Expand 10 before | Expand all | Expand 10 after
2651 QuicTime default_retransmission_time = clock_.ApproximateNow().Add( 2671 QuicTime default_retransmission_time = clock_.ApproximateNow().Add(
2652 DefaultRetransmissionTime()); 2672 DefaultRetransmissionTime());
2653 SendStreamDataToPeer(3, "foo", 0, !kFin, nullptr); 2673 SendStreamDataToPeer(3, "foo", 0, !kFin, nullptr);
2654 EXPECT_EQ(1u, stop_waiting()->least_unacked); 2674 EXPECT_EQ(1u, stop_waiting()->least_unacked);
2655 2675
2656 EXPECT_EQ(1u, writer_->header().packet_sequence_number); 2676 EXPECT_EQ(1u, writer_->header().packet_sequence_number);
2657 EXPECT_EQ(default_retransmission_time, 2677 EXPECT_EQ(default_retransmission_time,
2658 connection_.GetRetransmissionAlarm()->deadline()); 2678 connection_.GetRetransmissionAlarm()->deadline());
2659 // Simulate the retransmission alarm firing. 2679 // Simulate the retransmission alarm firing.
2660 clock_.AdvanceTime(DefaultRetransmissionTime()); 2680 clock_.AdvanceTime(DefaultRetransmissionTime());
2661 EXPECT_CALL(*send_algorithm_, OnRetransmissionTimeout(true)); 2681 if (!FLAGS_quic_use_new_rto) {
2682 EXPECT_CALL(*send_algorithm_, OnRetransmissionTimeout(true));
2683 }
2662 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, 2u, _, _)); 2684 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, 2u, _, _));
2663 connection_.GetRetransmissionAlarm()->Fire(); 2685 connection_.GetRetransmissionAlarm()->Fire();
2664 EXPECT_EQ(2u, writer_->header().packet_sequence_number); 2686 EXPECT_EQ(2u, writer_->header().packet_sequence_number);
2665 // We do not raise the high water mark yet. 2687 // We do not raise the high water mark yet.
2666 EXPECT_EQ(1u, stop_waiting()->least_unacked); 2688 EXPECT_EQ(1u, stop_waiting()->least_unacked);
2667 } 2689 }
2668 2690
2669 TEST_P(QuicConnectionTest, RTOWithSameEncryptionLevel) { 2691 TEST_P(QuicConnectionTest, RTOWithSameEncryptionLevel) {
2670 QuicTime default_retransmission_time = clock_.ApproximateNow().Add( 2692 QuicTime default_retransmission_time = clock_.ApproximateNow().Add(
2671 DefaultRetransmissionTime()); 2693 DefaultRetransmissionTime());
2672 use_tagging_decrypter(); 2694 use_tagging_decrypter();
2673 2695
2674 // A TaggingEncrypter puts kTagSize copies of the given byte (0x01 here) at 2696 // A TaggingEncrypter puts kTagSize copies of the given byte (0x01 here) at
2675 // the end of the packet. We can test this to check which encrypter was used. 2697 // the end of the packet. We can test this to check which encrypter was used.
2676 connection_.SetEncrypter(ENCRYPTION_NONE, new TaggingEncrypter(0x01)); 2698 connection_.SetEncrypter(ENCRYPTION_NONE, new TaggingEncrypter(0x01));
2677 SendStreamDataToPeer(3, "foo", 0, !kFin, nullptr); 2699 SendStreamDataToPeer(3, "foo", 0, !kFin, nullptr);
2678 EXPECT_EQ(0x01010101u, writer_->final_bytes_of_last_packet()); 2700 EXPECT_EQ(0x01010101u, writer_->final_bytes_of_last_packet());
2679 2701
2680 connection_.SetEncrypter(ENCRYPTION_INITIAL, new TaggingEncrypter(0x02)); 2702 connection_.SetEncrypter(ENCRYPTION_INITIAL, new TaggingEncrypter(0x02));
2681 connection_.SetDefaultEncryptionLevel(ENCRYPTION_INITIAL); 2703 connection_.SetDefaultEncryptionLevel(ENCRYPTION_INITIAL);
2682 SendStreamDataToPeer(3, "foo", 0, !kFin, nullptr); 2704 SendStreamDataToPeer(3, "foo", 0, !kFin, nullptr);
2683 EXPECT_EQ(0x02020202u, writer_->final_bytes_of_last_packet()); 2705 EXPECT_EQ(0x02020202u, writer_->final_bytes_of_last_packet());
2684 2706
2685 EXPECT_EQ(default_retransmission_time, 2707 EXPECT_EQ(default_retransmission_time,
2686 connection_.GetRetransmissionAlarm()->deadline()); 2708 connection_.GetRetransmissionAlarm()->deadline());
2687 { 2709 {
2688 InSequence s; 2710 InSequence s;
2689 EXPECT_CALL(*send_algorithm_, OnRetransmissionTimeout(true)); 2711 if (!FLAGS_quic_use_new_rto) {
2712 EXPECT_CALL(*send_algorithm_, OnRetransmissionTimeout(true));
2713 }
2690 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, 3, _, _)); 2714 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, 3, _, _));
2691 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, 4, _, _)); 2715 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, 4, _, _));
2692 } 2716 }
2693 2717
2694 // Simulate the retransmission alarm firing. 2718 // Simulate the retransmission alarm firing.
2695 clock_.AdvanceTime(DefaultRetransmissionTime()); 2719 clock_.AdvanceTime(DefaultRetransmissionTime());
2696 connection_.GetRetransmissionAlarm()->Fire(); 2720 connection_.GetRetransmissionAlarm()->Fire();
2697 2721
2698 // Packet should have been sent with ENCRYPTION_NONE. 2722 // Packet should have been sent with ENCRYPTION_NONE.
2699 EXPECT_EQ(0x01010101u, writer_->final_bytes_of_previous_packet()); 2723 EXPECT_EQ(0x01010101u, writer_->final_bytes_of_previous_packet());
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
2733 2757
2734 TEST_P(QuicConnectionTest, 2758 TEST_P(QuicConnectionTest,
2735 DropRetransmitsForNullEncryptedPacketAfterForwardSecure) { 2759 DropRetransmitsForNullEncryptedPacketAfterForwardSecure) {
2736 use_tagging_decrypter(); 2760 use_tagging_decrypter();
2737 connection_.SetEncrypter(ENCRYPTION_NONE, new TaggingEncrypter(0x01)); 2761 connection_.SetEncrypter(ENCRYPTION_NONE, new TaggingEncrypter(0x01));
2738 QuicPacketSequenceNumber sequence_number; 2762 QuicPacketSequenceNumber sequence_number;
2739 SendStreamDataToPeer(3, "foo", 0, !kFin, &sequence_number); 2763 SendStreamDataToPeer(3, "foo", 0, !kFin, &sequence_number);
2740 2764
2741 // Simulate the retransmission alarm firing and the socket blocking. 2765 // Simulate the retransmission alarm firing and the socket blocking.
2742 BlockOnNextWrite(); 2766 BlockOnNextWrite();
2743 EXPECT_CALL(*send_algorithm_, OnRetransmissionTimeout(true)); 2767 if (!FLAGS_quic_use_new_rto) {
2768 EXPECT_CALL(*send_algorithm_, OnRetransmissionTimeout(true));
2769 }
2744 clock_.AdvanceTime(DefaultRetransmissionTime()); 2770 clock_.AdvanceTime(DefaultRetransmissionTime());
2745 connection_.GetRetransmissionAlarm()->Fire(); 2771 connection_.GetRetransmissionAlarm()->Fire();
2746 2772
2747 // Go forward secure. 2773 // Go forward secure.
2748 connection_.SetEncrypter(ENCRYPTION_FORWARD_SECURE, 2774 connection_.SetEncrypter(ENCRYPTION_FORWARD_SECURE,
2749 new TaggingEncrypter(0x02)); 2775 new TaggingEncrypter(0x02));
2750 connection_.SetDefaultEncryptionLevel(ENCRYPTION_FORWARD_SECURE); 2776 connection_.SetDefaultEncryptionLevel(ENCRYPTION_FORWARD_SECURE);
2751 connection_.NeuterUnencryptedPackets(); 2777 connection_.NeuterUnencryptedPackets();
2752 2778
2753 EXPECT_EQ(QuicTime::Zero(), 2779 EXPECT_EQ(QuicTime::Zero(),
(...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after
2895 DoAll(SaveArg<3>(&first_packet_size), Return(true))); 2921 DoAll(SaveArg<3>(&first_packet_size), Return(true)));
2896 2922
2897 connection_.SendStreamDataWithString(3, "first_packet", 0, !kFin, nullptr); 2923 connection_.SendStreamDataWithString(3, "first_packet", 0, !kFin, nullptr);
2898 QuicByteCount second_packet_size; 2924 QuicByteCount second_packet_size;
2899 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).WillOnce( 2925 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).WillOnce(
2900 DoAll(SaveArg<3>(&second_packet_size), Return(true))); 2926 DoAll(SaveArg<3>(&second_packet_size), Return(true)));
2901 connection_.SendStreamDataWithString(3, "second_packet", 12, !kFin, nullptr); 2927 connection_.SendStreamDataWithString(3, "second_packet", 12, !kFin, nullptr);
2902 EXPECT_NE(first_packet_size, second_packet_size); 2928 EXPECT_NE(first_packet_size, second_packet_size);
2903 // Advance the clock by huge time to make sure packets will be retransmitted. 2929 // Advance the clock by huge time to make sure packets will be retransmitted.
2904 clock_.AdvanceTime(QuicTime::Delta::FromSeconds(10)); 2930 clock_.AdvanceTime(QuicTime::Delta::FromSeconds(10));
2905 EXPECT_CALL(*send_algorithm_, OnRetransmissionTimeout(true)); 2931 if (!FLAGS_quic_use_new_rto) {
2932 EXPECT_CALL(*send_algorithm_, OnRetransmissionTimeout(true));
2933 }
2906 { 2934 {
2907 InSequence s; 2935 InSequence s;
2908 EXPECT_CALL(*send_algorithm_, 2936 EXPECT_CALL(*send_algorithm_,
2909 OnPacketSent(_, _, _, first_packet_size, _)); 2937 OnPacketSent(_, _, _, first_packet_size, _));
2910 EXPECT_CALL(*send_algorithm_, 2938 EXPECT_CALL(*send_algorithm_,
2911 OnPacketSent(_, _, _, second_packet_size, _)); 2939 OnPacketSent(_, _, _, second_packet_size, _));
2912 } 2940 }
2913 connection_.GetRetransmissionAlarm()->Fire(); 2941 connection_.GetRetransmissionAlarm()->Fire();
2914 2942
2915 // Advance again and expect the packets to be sent again in the same order. 2943 // Advance again and expect the packets to be sent again in the same order.
2916 clock_.AdvanceTime(QuicTime::Delta::FromSeconds(20)); 2944 clock_.AdvanceTime(QuicTime::Delta::FromSeconds(20));
2917 EXPECT_CALL(*send_algorithm_, OnRetransmissionTimeout(true)); 2945 if (!FLAGS_quic_use_new_rto) {
2946 EXPECT_CALL(*send_algorithm_, OnRetransmissionTimeout(true));
2947 }
2918 { 2948 {
2919 InSequence s; 2949 InSequence s;
2920 EXPECT_CALL(*send_algorithm_, 2950 EXPECT_CALL(*send_algorithm_,
2921 OnPacketSent(_, _, _, first_packet_size, _)); 2951 OnPacketSent(_, _, _, first_packet_size, _));
2922 EXPECT_CALL(*send_algorithm_, 2952 EXPECT_CALL(*send_algorithm_,
2923 OnPacketSent(_, _, _, second_packet_size, _)); 2953 OnPacketSent(_, _, _, second_packet_size, _));
2924 } 2954 }
2925 connection_.GetRetransmissionAlarm()->Fire(); 2955 connection_.GetRetransmissionAlarm()->Fire();
2926 } 2956 }
2927 2957
2928 TEST_P(QuicConnectionTest, RetransmissionCountCalculation) {
2929 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_));
2930 QuicPacketSequenceNumber original_sequence_number;
2931 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _))
2932 .WillOnce(DoAll(SaveArg<2>(&original_sequence_number), Return(true)));
2933 connection_.SendStreamDataWithString(3, "foo", 0, !kFin, nullptr);
2934
2935 EXPECT_TRUE(QuicConnectionPeer::IsSavedForRetransmission(
2936 &connection_, original_sequence_number));
2937 EXPECT_FALSE(QuicConnectionPeer::IsRetransmission(
2938 &connection_, original_sequence_number));
2939 // Force retransmission due to RTO.
2940 clock_.AdvanceTime(QuicTime::Delta::FromSeconds(10));
2941 EXPECT_CALL(*send_algorithm_, OnRetransmissionTimeout(true));
2942 QuicPacketSequenceNumber rto_sequence_number;
2943 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _))
2944 .WillOnce(DoAll(SaveArg<2>(&rto_sequence_number), Return(true)));
2945 connection_.GetRetransmissionAlarm()->Fire();
2946 EXPECT_FALSE(QuicConnectionPeer::IsSavedForRetransmission(
2947 &connection_, original_sequence_number));
2948 ASSERT_TRUE(QuicConnectionPeer::IsSavedForRetransmission(
2949 &connection_, rto_sequence_number));
2950 EXPECT_TRUE(QuicConnectionPeer::IsRetransmission(
2951 &connection_, rto_sequence_number));
2952 // Once by explicit nack.
2953 SequenceNumberSet lost_packets;
2954 lost_packets.insert(rto_sequence_number);
2955 EXPECT_CALL(*loss_algorithm_, DetectLostPackets(_, _, _, _))
2956 .WillOnce(Return(lost_packets));
2957 EXPECT_CALL(*send_algorithm_, OnCongestionEvent(true, _, _, _));
2958 QuicPacketSequenceNumber nack_sequence_number = 0;
2959 // Ack packets might generate some other packets, which are not
2960 // retransmissions. (More ack packets).
2961 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _))
2962 .Times(AnyNumber());
2963 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _))
2964 .WillOnce(DoAll(SaveArg<2>(&nack_sequence_number), Return(true)));
2965 QuicAckFrame ack = InitAckFrame(rto_sequence_number);
2966 // Nack the retransmitted packet.
2967 NackPacket(original_sequence_number, &ack);
2968 NackPacket(rto_sequence_number, &ack);
2969 ProcessAckPacket(&ack);
2970
2971 ASSERT_NE(0u, nack_sequence_number);
2972 EXPECT_FALSE(QuicConnectionPeer::IsSavedForRetransmission(
2973 &connection_, rto_sequence_number));
2974 ASSERT_TRUE(QuicConnectionPeer::IsSavedForRetransmission(
2975 &connection_, nack_sequence_number));
2976 EXPECT_TRUE(QuicConnectionPeer::IsRetransmission(
2977 &connection_, nack_sequence_number));
2978 }
2979
2980 TEST_P(QuicConnectionTest, SetRTOAfterWritingToSocket) { 2958 TEST_P(QuicConnectionTest, SetRTOAfterWritingToSocket) {
2981 BlockOnNextWrite(); 2959 BlockOnNextWrite();
2982 connection_.SendStreamDataWithString(1, "foo", 0, !kFin, nullptr); 2960 connection_.SendStreamDataWithString(1, "foo", 0, !kFin, nullptr);
2983 // Make sure that RTO is not started when the packet is queued. 2961 // Make sure that RTO is not started when the packet is queued.
2984 EXPECT_FALSE(connection_.GetRetransmissionAlarm()->IsSet()); 2962 EXPECT_FALSE(connection_.GetRetransmissionAlarm()->IsSet());
2985 2963
2986 // Test that RTO is started once we write to the socket. 2964 // Test that RTO is started once we write to the socket.
2987 writer_->SetWritable(); 2965 writer_->SetWritable();
2988 connection_.OnCanWrite(); 2966 connection_.OnCanWrite();
2989 EXPECT_TRUE(connection_.GetRetransmissionAlarm()->IsSet()); 2967 EXPECT_TRUE(connection_.GetRetransmissionAlarm()->IsSet());
(...skipping 18 matching lines...) Expand all
3008 ProcessAckPacket(&ack); 2986 ProcessAckPacket(&ack);
3009 EXPECT_TRUE(retransmission_alarm->IsSet()); 2987 EXPECT_TRUE(retransmission_alarm->IsSet());
3010 EXPECT_GT(retransmission_alarm->deadline(), clock_.Now()); 2988 EXPECT_GT(retransmission_alarm->deadline(), clock_.Now());
3011 2989
3012 // Move forward past the original RTO and ensure the RTO is still pending. 2990 // Move forward past the original RTO and ensure the RTO is still pending.
3013 clock_.AdvanceTime(DefaultRetransmissionTime().Multiply(2)); 2991 clock_.AdvanceTime(DefaultRetransmissionTime().Multiply(2));
3014 2992
3015 // Ensure the second packet gets retransmitted when it finally fires. 2993 // Ensure the second packet gets retransmitted when it finally fires.
3016 EXPECT_TRUE(retransmission_alarm->IsSet()); 2994 EXPECT_TRUE(retransmission_alarm->IsSet());
3017 EXPECT_LT(retransmission_alarm->deadline(), clock_.ApproximateNow()); 2995 EXPECT_LT(retransmission_alarm->deadline(), clock_.ApproximateNow());
3018 EXPECT_CALL(*send_algorithm_, OnRetransmissionTimeout(true)); 2996 if (!FLAGS_quic_use_new_rto) {
2997 EXPECT_CALL(*send_algorithm_, OnRetransmissionTimeout(true));
2998 }
3019 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)); 2999 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _));
3020 // Manually cancel the alarm to simulate a real test. 3000 // Manually cancel the alarm to simulate a real test.
3021 connection_.GetRetransmissionAlarm()->Fire(); 3001 connection_.GetRetransmissionAlarm()->Fire();
3022 3002
3023 // The new retransmitted sequence number should set the RTO to a larger value 3003 // The new retransmitted sequence number should set the RTO to a larger value
3024 // than previously. 3004 // than previously.
3025 EXPECT_TRUE(retransmission_alarm->IsSet()); 3005 EXPECT_TRUE(retransmission_alarm->IsSet());
3026 QuicTime next_rto_time = retransmission_alarm->deadline(); 3006 QuicTime next_rto_time = retransmission_alarm->deadline();
3027 QuicTime expected_rto_time = 3007 QuicTime expected_rto_time =
3028 connection_.sent_packet_manager().GetRetransmissionTime(); 3008 connection_.sent_packet_manager().GetRetransmissionTime();
(...skipping 956 matching lines...) Expand 10 before | Expand all | Expand 10 after
3985 NackPacket(3, &nack_three); 3965 NackPacket(3, &nack_three);
3986 NackPacket(1, &nack_three); 3966 NackPacket(1, &nack_three);
3987 SequenceNumberSet lost_packets; 3967 SequenceNumberSet lost_packets;
3988 lost_packets.insert(1); 3968 lost_packets.insert(1);
3989 lost_packets.insert(3); 3969 lost_packets.insert(3);
3990 EXPECT_CALL(*loss_algorithm_, DetectLostPackets(_, _, _, _)) 3970 EXPECT_CALL(*loss_algorithm_, DetectLostPackets(_, _, _, _))
3991 .WillOnce(Return(lost_packets)); 3971 .WillOnce(Return(lost_packets));
3992 EXPECT_CALL(*send_algorithm_, OnCongestionEvent(true, _, _, _)); 3972 EXPECT_CALL(*send_algorithm_, OnCongestionEvent(true, _, _, _));
3993 EXPECT_CALL(visitor_, OnCanWrite()).Times(2); 3973 EXPECT_CALL(visitor_, OnCanWrite()).Times(2);
3994 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); 3974 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_));
3995 EXPECT_CALL(*send_algorithm_, RevertRetransmissionTimeout()); 3975 if (!FLAGS_quic_use_new_rto) {
3976 EXPECT_CALL(*send_algorithm_, RevertRetransmissionTimeout());
3977 }
3996 ProcessAckPacket(&nack_three); 3978 ProcessAckPacket(&nack_three);
3997 3979
3998 EXPECT_CALL(*send_algorithm_, BandwidthEstimate()).WillOnce( 3980 EXPECT_CALL(*send_algorithm_, BandwidthEstimate()).WillOnce(
3999 Return(QuicBandwidth::Zero())); 3981 Return(QuicBandwidth::Zero()));
4000 3982
4001 const QuicConnectionStats& stats = connection_.GetStats(); 3983 const QuicConnectionStats& stats = connection_.GetStats();
4002 EXPECT_EQ(3 * first_packet_size + 2 * second_packet_size - kQuicVersionSize, 3984 EXPECT_EQ(3 * first_packet_size + 2 * second_packet_size - kQuicVersionSize,
4003 stats.bytes_sent); 3985 stats.bytes_sent);
4004 EXPECT_EQ(5u, stats.packets_sent); 3986 EXPECT_EQ(5u, stats.packets_sent);
4005 EXPECT_EQ(2 * first_packet_size + second_packet_size - kQuicVersionSize, 3987 EXPECT_EQ(2 * first_packet_size + second_packet_size - kQuicVersionSize,
(...skipping 225 matching lines...) Expand 10 before | Expand all | Expand 10 after
4231 QuicTime default_retransmission_time = clock_.ApproximateNow().Add( 4213 QuicTime default_retransmission_time = clock_.ApproximateNow().Add(
4232 DefaultRetransmissionTime()); 4214 DefaultRetransmissionTime());
4233 connection_.SendStreamDataWithString(3, "foo", 0, !kFin, delegate.get()); 4215 connection_.SendStreamDataWithString(3, "foo", 0, !kFin, delegate.get());
4234 EXPECT_EQ(1u, stop_waiting()->least_unacked); 4216 EXPECT_EQ(1u, stop_waiting()->least_unacked);
4235 4217
4236 EXPECT_EQ(1u, writer_->header().packet_sequence_number); 4218 EXPECT_EQ(1u, writer_->header().packet_sequence_number);
4237 EXPECT_EQ(default_retransmission_time, 4219 EXPECT_EQ(default_retransmission_time,
4238 connection_.GetRetransmissionAlarm()->deadline()); 4220 connection_.GetRetransmissionAlarm()->deadline());
4239 // Simulate the retransmission alarm firing. 4221 // Simulate the retransmission alarm firing.
4240 clock_.AdvanceTime(DefaultRetransmissionTime()); 4222 clock_.AdvanceTime(DefaultRetransmissionTime());
4241 EXPECT_CALL(*send_algorithm_, OnRetransmissionTimeout(true)); 4223 if (!FLAGS_quic_use_new_rto) {
4224 EXPECT_CALL(*send_algorithm_, OnRetransmissionTimeout(true));
4225 }
4242 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, 2u, _, _)); 4226 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, 2u, _, _));
4243 connection_.GetRetransmissionAlarm()->Fire(); 4227 connection_.GetRetransmissionAlarm()->Fire();
4244 EXPECT_EQ(2u, writer_->header().packet_sequence_number); 4228 EXPECT_EQ(2u, writer_->header().packet_sequence_number);
4245 // We do not raise the high water mark yet. 4229 // We do not raise the high water mark yet.
4246 EXPECT_EQ(1u, stop_waiting()->least_unacked); 4230 EXPECT_EQ(1u, stop_waiting()->least_unacked);
4247 4231
4248 // Ack the original packet, which will revert the RTO. 4232 // Ack the original packet, which will revert the RTO.
4249 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); 4233 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_));
4250 EXPECT_CALL(*delegate.get(), OnAckNotification(1, _, _)); 4234 EXPECT_CALL(*delegate.get(), OnAckNotification(1, _, _));
4251 EXPECT_CALL(*send_algorithm_, RevertRetransmissionTimeout()); 4235 if (!FLAGS_quic_use_new_rto) {
4236 EXPECT_CALL(*send_algorithm_, RevertRetransmissionTimeout());
4237 }
4252 EXPECT_CALL(*send_algorithm_, OnCongestionEvent(true, _, _, _)); 4238 EXPECT_CALL(*send_algorithm_, OnCongestionEvent(true, _, _, _));
4253 QuicAckFrame ack_frame = InitAckFrame(1); 4239 QuicAckFrame ack_frame = InitAckFrame(1);
4254 ProcessAckPacket(&ack_frame); 4240 ProcessAckPacket(&ack_frame);
4255 4241
4256 // Delegate is not notified again when the retransmit is acked. 4242 // Delegate is not notified again when the retransmit is acked.
4257 EXPECT_CALL(*send_algorithm_, OnCongestionEvent(true, _, _, _)); 4243 EXPECT_CALL(*send_algorithm_, OnCongestionEvent(true, _, _, _));
4258 QuicAckFrame second_ack_frame = InitAckFrame(2); 4244 QuicAckFrame second_ack_frame = InitAckFrame(2);
4259 ProcessAckPacket(&second_ack_frame); 4245 ProcessAckPacket(&second_ack_frame);
4260 } 4246 }
4261 4247
(...skipping 257 matching lines...) Expand 10 before | Expand all | Expand 10 after
4519 // Regression test for b/18594622 4505 // Regression test for b/18594622
4520 scoped_refptr<MockAckNotifierDelegate> delegate(new MockAckNotifierDelegate); 4506 scoped_refptr<MockAckNotifierDelegate> delegate(new MockAckNotifierDelegate);
4521 EXPECT_DFATAL( 4507 EXPECT_DFATAL(
4522 connection_.SendStreamDataWithString(3, "", 0, !kFin, delegate.get()), 4508 connection_.SendStreamDataWithString(3, "", 0, !kFin, delegate.get()),
4523 "Attempt to send empty stream frame"); 4509 "Attempt to send empty stream frame");
4524 } 4510 }
4525 4511
4526 } // namespace 4512 } // namespace
4527 } // namespace test 4513 } // namespace test
4528 } // namespace net 4514 } // namespace net
OLDNEW
« no previous file with comments | « no previous file | net/quic/quic_flags.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698