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

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

Issue 1918953003: Landing Recent QUIC changes until 4/22/2016 14:55 UTC (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Deleted SpdyFramerTests missed while mergeing 120451808 Created 4 years, 8 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 | « net/quic/quic_connection.cc ('k') | net/quic/quic_crypto_server_stream.cc » ('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 <errno.h> 7 #include <errno.h>
8 #include <memory> 8 #include <memory>
9 #include <ostream> 9 #include <ostream>
10 #include <utility> 10 #include <utility>
(...skipping 3565 matching lines...) Expand 10 before | Expand all | Expand 10 after
3576 !kEntropyFlag, !kHasStopWaiting, 3576 !kEntropyFlag, !kHasStopWaiting,
3577 ENCRYPTION_INITIAL); 3577 ENCRYPTION_INITIAL);
3578 } 3578 }
3579 // Check that ack is sent and that delayed ack alarm is reset. 3579 // Check that ack is sent and that delayed ack alarm is reset.
3580 EXPECT_EQ(2u, writer_->frame_count()); 3580 EXPECT_EQ(2u, writer_->frame_count());
3581 EXPECT_FALSE(writer_->stop_waiting_frames().empty()); 3581 EXPECT_FALSE(writer_->stop_waiting_frames().empty());
3582 EXPECT_FALSE(writer_->ack_frames().empty()); 3582 EXPECT_FALSE(writer_->ack_frames().empty());
3583 EXPECT_FALSE(connection_.GetAckAlarm()->IsSet()); 3583 EXPECT_FALSE(connection_.GetAckAlarm()->IsSet());
3584 } 3584 }
3585 3585
3586 TEST_P(QuicConnectionTest, SendDelayedAckDecimationEighthRtt) {
3587 QuicConnectionPeer::SetAckMode(&connection_, QuicConnection::ACK_DECIMATION);
3588 QuicConnectionPeer::SetAckDecimationDelay(&connection_, 0.125);
3589
3590 const size_t kMinRttMs = 40;
3591 RttStats* rtt_stats = QuicSentPacketManagerPeer::GetRttStats(manager_);
3592 rtt_stats->UpdateRtt(QuicTime::Delta::FromMilliseconds(kMinRttMs),
3593 QuicTime::Delta::Zero(), QuicTime::Zero());
3594 // The ack time should be based on min_rtt/8, since it's less than the
3595 // default delayed ack time.
3596 QuicTime ack_time = clock_.ApproximateNow().Add(
3597 QuicTime::Delta::FromMilliseconds(kMinRttMs / 8));
3598 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_));
3599 EXPECT_FALSE(connection_.GetAckAlarm()->IsSet());
3600 const uint8_t tag = 0x07;
3601 connection_.SetDecrypter(ENCRYPTION_INITIAL, new StrictTaggingDecrypter(tag));
3602 framer_.SetEncrypter(ENCRYPTION_INITIAL, new TaggingEncrypter(tag));
3603 // Process a packet from the non-crypto stream.
3604 frame1_.stream_id = 3;
3605
3606 // Process all the initial packets in order so there aren't missing packets.
3607 QuicPacketNumber kFirstDecimatedPacket = 101;
3608 for (unsigned int i = 0; i < kFirstDecimatedPacket - 1; ++i) {
3609 EXPECT_CALL(visitor_, OnStreamFrame(_)).Times(1);
3610 ProcessDataPacketAtLevel(kDefaultPathId, 1 + i, !kEntropyFlag,
3611 !kHasStopWaiting, ENCRYPTION_INITIAL);
3612 }
3613 EXPECT_FALSE(connection_.GetAckAlarm()->IsSet());
3614 // The same as ProcessPacket(1) except that ENCRYPTION_INITIAL is used
3615 // instead of ENCRYPTION_NONE.
3616 EXPECT_CALL(visitor_, OnStreamFrame(_)).Times(1);
3617 ProcessDataPacketAtLevel(kDefaultPathId, kFirstDecimatedPacket, !kEntropyFlag,
3618 !kHasStopWaiting, ENCRYPTION_INITIAL);
3619
3620 // Check if delayed ack timer is running for the expected interval.
3621 EXPECT_TRUE(connection_.GetAckAlarm()->IsSet());
3622 EXPECT_EQ(ack_time, connection_.GetAckAlarm()->deadline());
3623
3624 // The 10th received packet causes an ack to be sent.
3625 for (int i = 0; i < 9; ++i) {
3626 EXPECT_TRUE(connection_.GetAckAlarm()->IsSet());
3627 EXPECT_CALL(visitor_, OnStreamFrame(_)).Times(1);
3628 ProcessDataPacketAtLevel(kDefaultPathId, kFirstDecimatedPacket + 1 + i,
3629 !kEntropyFlag, !kHasStopWaiting,
3630 ENCRYPTION_INITIAL);
3631 }
3632 // Check that ack is sent and that delayed ack alarm is reset.
3633 EXPECT_EQ(2u, writer_->frame_count());
3634 EXPECT_FALSE(writer_->stop_waiting_frames().empty());
3635 EXPECT_FALSE(writer_->ack_frames().empty());
3636 EXPECT_FALSE(connection_.GetAckAlarm()->IsSet());
3637 }
3638
3586 TEST_P(QuicConnectionTest, SendDelayedAckDecimationWithReordering) { 3639 TEST_P(QuicConnectionTest, SendDelayedAckDecimationWithReordering) {
3587 FLAGS_quic_ack_decimation2 = true;
3588 QuicConnectionPeer::SetAckMode( 3640 QuicConnectionPeer::SetAckMode(
3589 &connection_, QuicConnection::ACK_DECIMATION_WITH_REORDERING); 3641 &connection_, QuicConnection::ACK_DECIMATION_WITH_REORDERING);
3590 3642
3591 const size_t kMinRttMs = 40; 3643 const size_t kMinRttMs = 40;
3592 RttStats* rtt_stats = QuicSentPacketManagerPeer::GetRttStats(manager_); 3644 RttStats* rtt_stats = QuicSentPacketManagerPeer::GetRttStats(manager_);
3593 rtt_stats->UpdateRtt(QuicTime::Delta::FromMilliseconds(kMinRttMs), 3645 rtt_stats->UpdateRtt(QuicTime::Delta::FromMilliseconds(kMinRttMs),
3594 QuicTime::Delta::Zero(), QuicTime::Zero()); 3646 QuicTime::Delta::Zero(), QuicTime::Zero());
3595 // The ack time should be based on min_rtt/4, since it's less than the 3647 // The ack time should be based on min_rtt/4, since it's less than the
3596 // default delayed ack time. 3648 // default delayed ack time.
3597 QuicTime ack_time = clock_.ApproximateNow().Add( 3649 QuicTime ack_time = clock_.ApproximateNow().Add(
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
3639 ENCRYPTION_INITIAL); 3691 ENCRYPTION_INITIAL);
3640 } 3692 }
3641 // Check that ack is sent and that delayed ack alarm is reset. 3693 // Check that ack is sent and that delayed ack alarm is reset.
3642 EXPECT_EQ(2u, writer_->frame_count()); 3694 EXPECT_EQ(2u, writer_->frame_count());
3643 EXPECT_FALSE(writer_->stop_waiting_frames().empty()); 3695 EXPECT_FALSE(writer_->stop_waiting_frames().empty());
3644 EXPECT_FALSE(writer_->ack_frames().empty()); 3696 EXPECT_FALSE(writer_->ack_frames().empty());
3645 EXPECT_FALSE(connection_.GetAckAlarm()->IsSet()); 3697 EXPECT_FALSE(connection_.GetAckAlarm()->IsSet());
3646 } 3698 }
3647 3699
3648 TEST_P(QuicConnectionTest, SendDelayedAckDecimationWithLargeReordering) { 3700 TEST_P(QuicConnectionTest, SendDelayedAckDecimationWithLargeReordering) {
3649 FLAGS_quic_ack_decimation2 = true;
3650 QuicConnectionPeer::SetAckMode( 3701 QuicConnectionPeer::SetAckMode(
3651 &connection_, QuicConnection::ACK_DECIMATION_WITH_REORDERING); 3702 &connection_, QuicConnection::ACK_DECIMATION_WITH_REORDERING);
3652 3703
3653 const size_t kMinRttMs = 40; 3704 const size_t kMinRttMs = 40;
3654 RttStats* rtt_stats = QuicSentPacketManagerPeer::GetRttStats(manager_); 3705 RttStats* rtt_stats = QuicSentPacketManagerPeer::GetRttStats(manager_);
3655 rtt_stats->UpdateRtt(QuicTime::Delta::FromMilliseconds(kMinRttMs), 3706 rtt_stats->UpdateRtt(QuicTime::Delta::FromMilliseconds(kMinRttMs),
3656 QuicTime::Delta::Zero(), QuicTime::Zero()); 3707 QuicTime::Delta::Zero(), QuicTime::Zero());
3657 // The ack time should be based on min_rtt/4, since it's less than the 3708 // The ack time should be based on min_rtt/4, since it's less than the
3658 // default delayed ack time. 3709 // default delayed ack time.
3659 QuicTime ack_time = clock_.ApproximateNow().Add( 3710 QuicTime ack_time = clock_.ApproximateNow().Add(
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
3712 EXPECT_CALL(visitor_, OnStreamFrame(_)).Times(1); 3763 EXPECT_CALL(visitor_, OnStreamFrame(_)).Times(1);
3713 ProcessDataPacketAtLevel(kDefaultPathId, kFirstDecimatedPacket + 10, 3764 ProcessDataPacketAtLevel(kDefaultPathId, kFirstDecimatedPacket + 10,
3714 !kEntropyFlag, !kHasStopWaiting, ENCRYPTION_INITIAL); 3765 !kEntropyFlag, !kHasStopWaiting, ENCRYPTION_INITIAL);
3715 // Check that ack is sent and that delayed ack alarm is reset. 3766 // Check that ack is sent and that delayed ack alarm is reset.
3716 EXPECT_EQ(2u, writer_->frame_count()); 3767 EXPECT_EQ(2u, writer_->frame_count());
3717 EXPECT_FALSE(writer_->stop_waiting_frames().empty()); 3768 EXPECT_FALSE(writer_->stop_waiting_frames().empty());
3718 EXPECT_FALSE(writer_->ack_frames().empty()); 3769 EXPECT_FALSE(writer_->ack_frames().empty());
3719 EXPECT_FALSE(connection_.GetAckAlarm()->IsSet()); 3770 EXPECT_FALSE(connection_.GetAckAlarm()->IsSet());
3720 } 3771 }
3721 3772
3773 TEST_P(QuicConnectionTest, SendDelayedAckDecimationWithReorderingEighthRtt) {
3774 QuicConnectionPeer::SetAckMode(
3775 &connection_, QuicConnection::ACK_DECIMATION_WITH_REORDERING);
3776 QuicConnectionPeer::SetAckDecimationDelay(&connection_, 0.125);
3777
3778 const size_t kMinRttMs = 40;
3779 RttStats* rtt_stats = QuicSentPacketManagerPeer::GetRttStats(manager_);
3780 rtt_stats->UpdateRtt(QuicTime::Delta::FromMilliseconds(kMinRttMs),
3781 QuicTime::Delta::Zero(), QuicTime::Zero());
3782 // The ack time should be based on min_rtt/8, since it's less than the
3783 // default delayed ack time.
3784 QuicTime ack_time = clock_.ApproximateNow().Add(
3785 QuicTime::Delta::FromMilliseconds(kMinRttMs / 8));
3786 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_));
3787 EXPECT_FALSE(connection_.GetAckAlarm()->IsSet());
3788 const uint8_t tag = 0x07;
3789 connection_.SetDecrypter(ENCRYPTION_INITIAL, new StrictTaggingDecrypter(tag));
3790 framer_.SetEncrypter(ENCRYPTION_INITIAL, new TaggingEncrypter(tag));
3791 // Process a packet from the non-crypto stream.
3792 frame1_.stream_id = 3;
3793
3794 // Process all the initial packets in order so there aren't missing packets.
3795 QuicPacketNumber kFirstDecimatedPacket = 101;
3796 for (unsigned int i = 0; i < kFirstDecimatedPacket - 1; ++i) {
3797 EXPECT_CALL(visitor_, OnStreamFrame(_)).Times(1);
3798 ProcessDataPacketAtLevel(kDefaultPathId, 1 + i, !kEntropyFlag,
3799 !kHasStopWaiting, ENCRYPTION_INITIAL);
3800 }
3801 EXPECT_FALSE(connection_.GetAckAlarm()->IsSet());
3802 // The same as ProcessPacket(1) except that ENCRYPTION_INITIAL is used
3803 // instead of ENCRYPTION_NONE.
3804 EXPECT_CALL(visitor_, OnStreamFrame(_)).Times(1);
3805 ProcessDataPacketAtLevel(kDefaultPathId, kFirstDecimatedPacket, !kEntropyFlag,
3806 !kHasStopWaiting, ENCRYPTION_INITIAL);
3807
3808 // Check if delayed ack timer is running for the expected interval.
3809 EXPECT_TRUE(connection_.GetAckAlarm()->IsSet());
3810 EXPECT_EQ(ack_time, connection_.GetAckAlarm()->deadline());
3811
3812 // Process packet 10 first and ensure the alarm is one eighth min_rtt.
3813 EXPECT_CALL(visitor_, OnStreamFrame(_)).Times(1);
3814 ProcessDataPacketAtLevel(kDefaultPathId, kFirstDecimatedPacket + 9,
3815 !kEntropyFlag, !kHasStopWaiting, ENCRYPTION_INITIAL);
3816 ack_time = clock_.ApproximateNow().Add(QuicTime::Delta::FromMilliseconds(5));
3817 EXPECT_TRUE(connection_.GetAckAlarm()->IsSet());
3818 EXPECT_EQ(ack_time, connection_.GetAckAlarm()->deadline());
3819
3820 // The 10th received packet causes an ack to be sent.
3821 for (int i = 0; i < 8; ++i) {
3822 EXPECT_TRUE(connection_.GetAckAlarm()->IsSet());
3823 EXPECT_CALL(visitor_, OnStreamFrame(_)).Times(1);
3824 ProcessDataPacketAtLevel(kDefaultPathId, kFirstDecimatedPacket + 1 + i,
3825 !kEntropyFlag, !kHasStopWaiting,
3826 ENCRYPTION_INITIAL);
3827 }
3828 // Check that ack is sent and that delayed ack alarm is reset.
3829 EXPECT_EQ(2u, writer_->frame_count());
3830 EXPECT_FALSE(writer_->stop_waiting_frames().empty());
3831 EXPECT_FALSE(writer_->ack_frames().empty());
3832 EXPECT_FALSE(connection_.GetAckAlarm()->IsSet());
3833 }
3834
3835 TEST_P(QuicConnectionTest,
3836 SendDelayedAckDecimationWithLargeReorderingEighthRtt) {
3837 QuicConnectionPeer::SetAckMode(
3838 &connection_, QuicConnection::ACK_DECIMATION_WITH_REORDERING);
3839 QuicConnectionPeer::SetAckDecimationDelay(&connection_, 0.125);
3840
3841 const size_t kMinRttMs = 40;
3842 RttStats* rtt_stats = QuicSentPacketManagerPeer::GetRttStats(manager_);
3843 rtt_stats->UpdateRtt(QuicTime::Delta::FromMilliseconds(kMinRttMs),
3844 QuicTime::Delta::Zero(), QuicTime::Zero());
3845 // The ack time should be based on min_rtt/8, since it's less than the
3846 // default delayed ack time.
3847 QuicTime ack_time = clock_.ApproximateNow().Add(
3848 QuicTime::Delta::FromMilliseconds(kMinRttMs / 8));
3849 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_));
3850 EXPECT_FALSE(connection_.GetAckAlarm()->IsSet());
3851 const uint8_t tag = 0x07;
3852 connection_.SetDecrypter(ENCRYPTION_INITIAL, new StrictTaggingDecrypter(tag));
3853 framer_.SetEncrypter(ENCRYPTION_INITIAL, new TaggingEncrypter(tag));
3854 // Process a packet from the non-crypto stream.
3855 frame1_.stream_id = 3;
3856
3857 // Process all the initial packets in order so there aren't missing packets.
3858 QuicPacketNumber kFirstDecimatedPacket = 101;
3859 for (unsigned int i = 0; i < kFirstDecimatedPacket - 1; ++i) {
3860 EXPECT_CALL(visitor_, OnStreamFrame(_)).Times(1);
3861 ProcessDataPacketAtLevel(kDefaultPathId, 1 + i, !kEntropyFlag,
3862 !kHasStopWaiting, ENCRYPTION_INITIAL);
3863 }
3864 EXPECT_FALSE(connection_.GetAckAlarm()->IsSet());
3865 // The same as ProcessPacket(1) except that ENCRYPTION_INITIAL is used
3866 // instead of ENCRYPTION_NONE.
3867 EXPECT_CALL(visitor_, OnStreamFrame(_)).Times(1);
3868 ProcessDataPacketAtLevel(kDefaultPathId, kFirstDecimatedPacket, !kEntropyFlag,
3869 !kHasStopWaiting, ENCRYPTION_INITIAL);
3870
3871 // Check if delayed ack timer is running for the expected interval.
3872 EXPECT_TRUE(connection_.GetAckAlarm()->IsSet());
3873 EXPECT_EQ(ack_time, connection_.GetAckAlarm()->deadline());
3874
3875 // Process packet 10 first and ensure the alarm is one eighth min_rtt.
3876 EXPECT_CALL(visitor_, OnStreamFrame(_)).Times(1);
3877 ProcessDataPacketAtLevel(kDefaultPathId, kFirstDecimatedPacket + 19,
3878 !kEntropyFlag, !kHasStopWaiting, ENCRYPTION_INITIAL);
3879 ack_time = clock_.ApproximateNow().Add(QuicTime::Delta::FromMilliseconds(5));
3880 EXPECT_TRUE(connection_.GetAckAlarm()->IsSet());
3881 EXPECT_EQ(ack_time, connection_.GetAckAlarm()->deadline());
3882
3883 // The 10th received packet causes an ack to be sent.
3884 for (int i = 0; i < 8; ++i) {
3885 EXPECT_TRUE(connection_.GetAckAlarm()->IsSet());
3886 EXPECT_CALL(visitor_, OnStreamFrame(_)).Times(1);
3887 ProcessDataPacketAtLevel(kDefaultPathId, kFirstDecimatedPacket + 1 + i,
3888 !kEntropyFlag, !kHasStopWaiting,
3889 ENCRYPTION_INITIAL);
3890 }
3891 // Check that ack is sent and that delayed ack alarm is reset.
3892 EXPECT_EQ(2u, writer_->frame_count());
3893 EXPECT_FALSE(writer_->stop_waiting_frames().empty());
3894 EXPECT_FALSE(writer_->ack_frames().empty());
3895 EXPECT_FALSE(connection_.GetAckAlarm()->IsSet());
3896
3897 // The next packet received in order will cause an immediate ack,
3898 // because it fills a hole.
3899 EXPECT_FALSE(connection_.GetAckAlarm()->IsSet());
3900 EXPECT_CALL(visitor_, OnStreamFrame(_)).Times(1);
3901 ProcessDataPacketAtLevel(kDefaultPathId, kFirstDecimatedPacket + 10,
3902 !kEntropyFlag, !kHasStopWaiting, ENCRYPTION_INITIAL);
3903 // Check that ack is sent and that delayed ack alarm is reset.
3904 EXPECT_EQ(2u, writer_->frame_count());
3905 EXPECT_FALSE(writer_->stop_waiting_frames().empty());
3906 EXPECT_FALSE(writer_->ack_frames().empty());
3907 EXPECT_FALSE(connection_.GetAckAlarm()->IsSet());
3908 }
3909
3722 TEST_P(QuicConnectionTest, SendDelayedAckOnHandshakeConfirmed) { 3910 TEST_P(QuicConnectionTest, SendDelayedAckOnHandshakeConfirmed) {
3723 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); 3911 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_));
3724 ProcessPacket(kDefaultPathId, 1); 3912 ProcessPacket(kDefaultPathId, 1);
3725 // Check that ack is sent and that delayed ack alarm is set. 3913 // Check that ack is sent and that delayed ack alarm is set.
3726 EXPECT_TRUE(connection_.GetAckAlarm()->IsSet()); 3914 EXPECT_TRUE(connection_.GetAckAlarm()->IsSet());
3727 QuicTime ack_time = clock_.ApproximateNow().Add(DefaultDelayedAckTime()); 3915 QuicTime ack_time = clock_.ApproximateNow().Add(DefaultDelayedAckTime());
3728 EXPECT_EQ(ack_time, connection_.GetAckAlarm()->deadline()); 3916 EXPECT_EQ(ack_time, connection_.GetAckAlarm()->deadline());
3729 3917
3730 // Completing the handshake as the server does nothing. 3918 // Completing the handshake as the server does nothing.
3731 QuicConnectionPeer::SetPerspective(&connection_, Perspective::IS_SERVER); 3919 QuicConnectionPeer::SetPerspective(&connection_, Perspective::IS_SERVER);
(...skipping 973 matching lines...) Expand 10 before | Expand all | Expand 10 after
4705 EXPECT_CALL(visitor_, OnConnectionClosed(_, _, _)).Times(1); 4893 EXPECT_CALL(visitor_, OnConnectionClosed(_, _, _)).Times(1);
4706 connection_.CloseConnection(QUIC_NO_ERROR, "no reason", 4894 connection_.CloseConnection(QUIC_NO_ERROR, "no reason",
4707 ConnectionCloseBehavior::SILENT_CLOSE); 4895 ConnectionCloseBehavior::SILENT_CLOSE);
4708 connection_.CloseConnection(QUIC_NO_ERROR, "no reason", 4896 connection_.CloseConnection(QUIC_NO_ERROR, "no reason",
4709 ConnectionCloseBehavior::SILENT_CLOSE); 4897 ConnectionCloseBehavior::SILENT_CLOSE);
4710 } 4898 }
4711 4899
4712 } // namespace 4900 } // namespace
4713 } // namespace test 4901 } // namespace test
4714 } // namespace net 4902 } // namespace net
OLDNEW
« no previous file with comments | « net/quic/quic_connection.cc ('k') | net/quic/quic_crypto_server_stream.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698