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

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

Issue 1231343004: relnote: Change QuicConnectionVisitorInterface::OnStreamFrames to (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@Fix_flag_quic_delay_retransmission_alarm_97271704
Patch Set: Created 5 years, 5 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_session.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 <ostream> 7 #include <ostream>
8 8
9 #include "base/basictypes.h" 9 #include "base/basictypes.h"
10 #include "base/bind.h" 10 #include "base/bind.h"
(...skipping 715 matching lines...) Expand 10 before | Expand all | Expand 10 after
726 return 0; 726 return 0;
727 } 727 }
728 return writer_->stop_waiting_frames()[0].least_unacked; 728 return writer_->stop_waiting_frames()[0].least_unacked;
729 } 729 }
730 730
731 void use_tagging_decrypter() { 731 void use_tagging_decrypter() {
732 writer_->use_tagging_decrypter(); 732 writer_->use_tagging_decrypter();
733 } 733 }
734 734
735 void ProcessPacket(QuicPacketSequenceNumber number) { 735 void ProcessPacket(QuicPacketSequenceNumber number) {
736 EXPECT_CALL(visitor_, OnStreamFrames(_)).Times(1); 736 EXPECT_CALL(visitor_, OnStreamFrame(_)).Times(1);
737 ProcessDataPacket(number, 0, !kEntropyFlag); 737 ProcessDataPacket(number, 0, !kEntropyFlag);
738 } 738 }
739 739
740 QuicPacketEntropyHash ProcessFramePacket(QuicFrame frame) { 740 QuicPacketEntropyHash ProcessFramePacket(QuicFrame frame) {
741 QuicFrames frames; 741 QuicFrames frames;
742 frames.push_back(QuicFrame(frame)); 742 frames.push_back(QuicFrame(frame));
743 QuicPacketCreatorPeer::SetSendVersionInPacket( 743 QuicPacketCreatorPeer::SetSendVersionInPacket(
744 &peer_creator_, connection_.perspective() == Perspective::IS_SERVER); 744 &peer_creator_, connection_.perspective() == Perspective::IS_SERVER);
745 745
746 char buffer[kMaxPacketSize]; 746 char buffer[kMaxPacketSize];
(...skipping 29 matching lines...) Expand all
776 scoped_ptr<QuicPacket> packet(ConstructClosePacket(number, fec_group)); 776 scoped_ptr<QuicPacket> packet(ConstructClosePacket(number, fec_group));
777 char buffer[kMaxPacketSize]; 777 char buffer[kMaxPacketSize];
778 scoped_ptr<QuicEncryptedPacket> encrypted(framer_.EncryptPayload( 778 scoped_ptr<QuicEncryptedPacket> encrypted(framer_.EncryptPayload(
779 ENCRYPTION_NONE, number, *packet, buffer, kMaxPacketSize)); 779 ENCRYPTION_NONE, number, *packet, buffer, kMaxPacketSize));
780 connection_.ProcessUdpPacket(IPEndPoint(), IPEndPoint(), *encrypted); 780 connection_.ProcessUdpPacket(IPEndPoint(), IPEndPoint(), *encrypted);
781 } 781 }
782 782
783 size_t ProcessFecProtectedPacket(QuicPacketSequenceNumber number, 783 size_t ProcessFecProtectedPacket(QuicPacketSequenceNumber number,
784 bool expect_revival, bool entropy_flag) { 784 bool expect_revival, bool entropy_flag) {
785 if (expect_revival) { 785 if (expect_revival) {
786 EXPECT_CALL(visitor_, OnStreamFrames(_)).Times(1); 786 EXPECT_CALL(visitor_, OnStreamFrame(_)).Times(1);
787 } 787 }
788 EXPECT_CALL(visitor_, OnStreamFrames(_)).Times(1). 788 EXPECT_CALL(visitor_, OnStreamFrame(_)).Times(1).RetiresOnSaturation();
789 RetiresOnSaturation();
790 return ProcessDataPacket(number, 1, entropy_flag); 789 return ProcessDataPacket(number, 1, entropy_flag);
791 } 790 }
792 791
793 // Processes an FEC packet that covers the packets that would have been 792 // Processes an FEC packet that covers the packets that would have been
794 // received. 793 // received.
795 size_t ProcessFecPacket(QuicPacketSequenceNumber number, 794 size_t ProcessFecPacket(QuicPacketSequenceNumber number,
796 QuicPacketSequenceNumber min_protected_packet, 795 QuicPacketSequenceNumber min_protected_packet,
797 bool expect_revival, 796 bool expect_revival,
798 bool entropy_flag, 797 bool entropy_flag,
799 QuicPacket* packet) { 798 QuicPacket* packet) {
800 if (expect_revival) { 799 if (expect_revival) {
801 EXPECT_CALL(visitor_, OnStreamFrames(_)).Times(1); 800 EXPECT_CALL(visitor_, OnStreamFrame(_)).Times(1);
802 } 801 }
803 802
804 // Construct the decrypted data packet so we can compute the correct 803 // Construct the decrypted data packet so we can compute the correct
805 // redundancy. If |packet| has been provided then use that, otherwise 804 // redundancy. If |packet| has been provided then use that, otherwise
806 // construct a default data packet. 805 // construct a default data packet.
807 scoped_ptr<QuicPacket> data_packet; 806 scoped_ptr<QuicPacket> data_packet;
808 if (packet) { 807 if (packet) {
809 data_packet.reset(packet); 808 data_packet.reset(packet);
810 } else { 809 } else {
811 data_packet.reset(ConstructDataPacket(number, 1, !kEntropyFlag)); 810 data_packet.reset(ConstructDataPacket(number, 1, !kEntropyFlag));
(...skipping 254 matching lines...) Expand 10 before | Expand all | Expand 10 after
1066 QuicPaddingFrame padding; 1065 QuicPaddingFrame padding;
1067 frames.push_back(QuicFrame(&frame1_)); 1066 frames.push_back(QuicFrame(&frame1_));
1068 frames.push_back(QuicFrame(&padding)); 1067 frames.push_back(QuicFrame(&padding));
1069 scoped_ptr<QuicPacket> packet(ConstructPacket(header, frames)); 1068 scoped_ptr<QuicPacket> packet(ConstructPacket(header, frames));
1070 char buffer[kMaxPacketSize]; 1069 char buffer[kMaxPacketSize];
1071 scoped_ptr<QuicEncryptedPacket> encrypted(framer_.EncryptPayload( 1070 scoped_ptr<QuicEncryptedPacket> encrypted(framer_.EncryptPayload(
1072 ENCRYPTION_NONE, 12, *packet, buffer, kMaxPacketSize)); 1071 ENCRYPTION_NONE, 12, *packet, buffer, kMaxPacketSize));
1073 EXPECT_EQ(kMaxPacketSize, encrypted->length()); 1072 EXPECT_EQ(kMaxPacketSize, encrypted->length());
1074 1073
1075 framer_.set_version(version()); 1074 framer_.set_version(version());
1076 EXPECT_CALL(visitor_, OnStreamFrames(_)).Times(1); 1075 EXPECT_CALL(visitor_, OnStreamFrame(_)).Times(1);
1077 connection_.ProcessUdpPacket(IPEndPoint(), IPEndPoint(), *encrypted); 1076 connection_.ProcessUdpPacket(IPEndPoint(), IPEndPoint(), *encrypted);
1078 1077
1079 EXPECT_EQ(kMaxPacketSize, connection_.max_packet_length()); 1078 EXPECT_EQ(kMaxPacketSize, connection_.max_packet_length());
1080 } 1079 }
1081 1080
1082 TEST_P(QuicConnectionTest, PacketsInOrder) { 1081 TEST_P(QuicConnectionTest, PacketsInOrder) {
1083 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); 1082 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_));
1084 1083
1085 ProcessPacket(1); 1084 ProcessPacket(1);
1086 EXPECT_EQ(1u, outgoing_ack()->largest_observed); 1085 EXPECT_EQ(1u, outgoing_ack()->largest_observed);
(...skipping 29 matching lines...) Expand all
1116 1115
1117 TEST_P(QuicConnectionTest, DuplicatePacket) { 1116 TEST_P(QuicConnectionTest, DuplicatePacket) {
1118 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); 1117 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_));
1119 1118
1120 ProcessPacket(3); 1119 ProcessPacket(3);
1121 EXPECT_EQ(3u, outgoing_ack()->largest_observed); 1120 EXPECT_EQ(3u, outgoing_ack()->largest_observed);
1122 EXPECT_TRUE(IsMissing(2)); 1121 EXPECT_TRUE(IsMissing(2));
1123 EXPECT_TRUE(IsMissing(1)); 1122 EXPECT_TRUE(IsMissing(1));
1124 1123
1125 // Send packet 3 again, but do not set the expectation that 1124 // Send packet 3 again, but do not set the expectation that
1126 // the visitor OnStreamFrames() will be called. 1125 // the visitor OnStreamFrame() will be called.
1127 ProcessDataPacket(3, 0, !kEntropyFlag); 1126 ProcessDataPacket(3, 0, !kEntropyFlag);
1128 EXPECT_EQ(3u, outgoing_ack()->largest_observed); 1127 EXPECT_EQ(3u, outgoing_ack()->largest_observed);
1129 EXPECT_TRUE(IsMissing(2)); 1128 EXPECT_TRUE(IsMissing(2));
1130 EXPECT_TRUE(IsMissing(1)); 1129 EXPECT_TRUE(IsMissing(1));
1131 } 1130 }
1132 1131
1133 TEST_P(QuicConnectionTest, PacketsOutOfOrderWithAdditionsAndLeastAwaiting) { 1132 TEST_P(QuicConnectionTest, PacketsOutOfOrderWithAdditionsAndLeastAwaiting) {
1134 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); 1133 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_));
1135 1134
1136 ProcessPacket(3); 1135 ProcessPacket(3);
(...skipping 992 matching lines...) Expand 10 before | Expand all | Expand 10 after
2129 EXPECT_EQ(2u, writer_->header().fec_group); 2128 EXPECT_EQ(2u, writer_->header().fec_group);
2130 EXPECT_EQ(2u, writer_->frame_count()); 2129 EXPECT_EQ(2u, writer_->frame_count());
2131 2130
2132 // FEC alarm should be set. 2131 // FEC alarm should be set.
2133 EXPECT_TRUE(connection_.GetFecAlarm()->IsSet()); 2132 EXPECT_TRUE(connection_.GetFecAlarm()->IsSet());
2134 } 2133 }
2135 2134
2136 TEST_P(QuicConnectionTest, FramePackingAckResponse) { 2135 TEST_P(QuicConnectionTest, FramePackingAckResponse) {
2137 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); 2136 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_));
2138 // Process a data packet to queue up a pending ack. 2137 // Process a data packet to queue up a pending ack.
2139 EXPECT_CALL(visitor_, OnStreamFrames(_)).Times(1); 2138 EXPECT_CALL(visitor_, OnStreamFrame(_)).Times(1);
2140 ProcessDataPacket(1, 1, kEntropyFlag); 2139 ProcessDataPacket(1, 1, kEntropyFlag);
2141 2140
2142 EXPECT_CALL(visitor_, OnCanWrite()).WillOnce(DoAll( 2141 EXPECT_CALL(visitor_, OnCanWrite()).WillOnce(DoAll(
2143 IgnoreResult(InvokeWithoutArgs(&connection_, 2142 IgnoreResult(InvokeWithoutArgs(&connection_,
2144 &TestConnection::SendStreamData3)), 2143 &TestConnection::SendStreamData3)),
2145 IgnoreResult(InvokeWithoutArgs(&connection_, 2144 IgnoreResult(InvokeWithoutArgs(&connection_,
2146 &TestConnection::SendStreamData5)))); 2145 &TestConnection::SendStreamData5))));
2147 2146
2148 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(1); 2147 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(1);
2149 2148
(...skipping 801 matching lines...) Expand 10 before | Expand all | Expand 10 after
2951 2950
2952 // Process an encrypted packet which can not yet be decrypted which should 2951 // Process an encrypted packet which can not yet be decrypted which should
2953 // result in the packet being buffered. 2952 // result in the packet being buffered.
2954 ProcessDataPacketAtLevel(1, 0, kEntropyFlag, ENCRYPTION_INITIAL); 2953 ProcessDataPacketAtLevel(1, 0, kEntropyFlag, ENCRYPTION_INITIAL);
2955 2954
2956 // Transition to the new encryption state and process another encrypted packet 2955 // Transition to the new encryption state and process another encrypted packet
2957 // which should result in the original packet being processed. 2956 // which should result in the original packet being processed.
2958 connection_.SetDecrypter(ENCRYPTION_INITIAL, new StrictTaggingDecrypter(tag)); 2957 connection_.SetDecrypter(ENCRYPTION_INITIAL, new StrictTaggingDecrypter(tag));
2959 connection_.SetDefaultEncryptionLevel(ENCRYPTION_INITIAL); 2958 connection_.SetDefaultEncryptionLevel(ENCRYPTION_INITIAL);
2960 connection_.SetEncrypter(ENCRYPTION_INITIAL, new TaggingEncrypter(tag)); 2959 connection_.SetEncrypter(ENCRYPTION_INITIAL, new TaggingEncrypter(tag));
2961 EXPECT_CALL(visitor_, OnStreamFrames(_)).Times(2); 2960 EXPECT_CALL(visitor_, OnStreamFrame(_)).Times(2);
2962 ProcessDataPacketAtLevel(2, 0, kEntropyFlag, ENCRYPTION_INITIAL); 2961 ProcessDataPacketAtLevel(2, 0, kEntropyFlag, ENCRYPTION_INITIAL);
2963 2962
2964 // Finally, process a third packet and note that we do not reprocess the 2963 // Finally, process a third packet and note that we do not reprocess the
2965 // buffered packet. 2964 // buffered packet.
2966 EXPECT_CALL(visitor_, OnStreamFrames(_)).Times(1); 2965 EXPECT_CALL(visitor_, OnStreamFrame(_)).Times(1);
2967 ProcessDataPacketAtLevel(3, 0, kEntropyFlag, ENCRYPTION_INITIAL); 2966 ProcessDataPacketAtLevel(3, 0, kEntropyFlag, ENCRYPTION_INITIAL);
2968 } 2967 }
2969 2968
2970 TEST_P(QuicConnectionTest, Buffer100NonDecryptablePackets) { 2969 TEST_P(QuicConnectionTest, Buffer100NonDecryptablePackets) {
2971 // SetFromConfig is always called after construction from InitializeSession. 2970 // SetFromConfig is always called after construction from InitializeSession.
2972 EXPECT_CALL(*send_algorithm_, SetFromConfig(_, _)); 2971 EXPECT_CALL(*send_algorithm_, SetFromConfig(_, _));
2973 QuicConfig config; 2972 QuicConfig config;
2974 config.set_max_undecryptable_packets(100); 2973 config.set_max_undecryptable_packets(100);
2975 connection_.SetFromConfig(config); 2974 connection_.SetFromConfig(config);
2976 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); 2975 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_));
2977 use_tagging_decrypter(); 2976 use_tagging_decrypter();
2978 2977
2979 const uint8 tag = 0x07; 2978 const uint8 tag = 0x07;
2980 framer_.SetEncrypter(ENCRYPTION_INITIAL, new TaggingEncrypter(tag)); 2979 framer_.SetEncrypter(ENCRYPTION_INITIAL, new TaggingEncrypter(tag));
2981 2980
2982 // Process an encrypted packet which can not yet be decrypted which should 2981 // Process an encrypted packet which can not yet be decrypted which should
2983 // result in the packet being buffered. 2982 // result in the packet being buffered.
2984 for (QuicPacketSequenceNumber i = 1; i <= 100; ++i) { 2983 for (QuicPacketSequenceNumber i = 1; i <= 100; ++i) {
2985 ProcessDataPacketAtLevel(i, 0, kEntropyFlag, ENCRYPTION_INITIAL); 2984 ProcessDataPacketAtLevel(i, 0, kEntropyFlag, ENCRYPTION_INITIAL);
2986 } 2985 }
2987 2986
2988 // Transition to the new encryption state and process another encrypted packet 2987 // Transition to the new encryption state and process another encrypted packet
2989 // which should result in the original packets being processed. 2988 // which should result in the original packets being processed.
2990 connection_.SetDecrypter(ENCRYPTION_INITIAL, new StrictTaggingDecrypter(tag)); 2989 connection_.SetDecrypter(ENCRYPTION_INITIAL, new StrictTaggingDecrypter(tag));
2991 connection_.SetDefaultEncryptionLevel(ENCRYPTION_INITIAL); 2990 connection_.SetDefaultEncryptionLevel(ENCRYPTION_INITIAL);
2992 connection_.SetEncrypter(ENCRYPTION_INITIAL, new TaggingEncrypter(tag)); 2991 connection_.SetEncrypter(ENCRYPTION_INITIAL, new TaggingEncrypter(tag));
2993 EXPECT_CALL(visitor_, OnStreamFrames(_)).Times(101); 2992 EXPECT_CALL(visitor_, OnStreamFrame(_)).Times(101);
2994 ProcessDataPacketAtLevel(101, 0, kEntropyFlag, ENCRYPTION_INITIAL); 2993 ProcessDataPacketAtLevel(101, 0, kEntropyFlag, ENCRYPTION_INITIAL);
2995 2994
2996 // Finally, process a third packet and note that we do not reprocess the 2995 // Finally, process a third packet and note that we do not reprocess the
2997 // buffered packet. 2996 // buffered packet.
2998 EXPECT_CALL(visitor_, OnStreamFrames(_)).Times(1); 2997 EXPECT_CALL(visitor_, OnStreamFrame(_)).Times(1);
2999 ProcessDataPacketAtLevel(102, 0, kEntropyFlag, ENCRYPTION_INITIAL); 2998 ProcessDataPacketAtLevel(102, 0, kEntropyFlag, ENCRYPTION_INITIAL);
3000 } 2999 }
3001 3000
3002 TEST_P(QuicConnectionTest, TestRetransmitOrder) { 3001 TEST_P(QuicConnectionTest, TestRetransmitOrder) {
3003 QuicByteCount first_packet_size; 3002 QuicByteCount first_packet_size;
3004 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).WillOnce( 3003 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).WillOnce(
3005 DoAll(SaveArg<3>(&first_packet_size), Return(true))); 3004 DoAll(SaveArg<3>(&first_packet_size), Return(true)));
3006 3005
3007 connection_.SendStreamDataWithString(3, "first_packet", 0, !kFin, nullptr); 3006 connection_.SendStreamDataWithString(3, "first_packet", 0, !kFin, nullptr);
3008 QuicByteCount second_packet_size; 3007 QuicByteCount second_packet_size;
(...skipping 609 matching lines...) Expand 10 before | Expand all | Expand 10 after
3618 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); 3617 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_));
3619 EXPECT_FALSE(connection_.GetAckAlarm()->IsSet()); 3618 EXPECT_FALSE(connection_.GetAckAlarm()->IsSet());
3620 const uint8 tag = 0x07; 3619 const uint8 tag = 0x07;
3621 connection_.SetDecrypter(ENCRYPTION_INITIAL, new StrictTaggingDecrypter(tag)); 3620 connection_.SetDecrypter(ENCRYPTION_INITIAL, new StrictTaggingDecrypter(tag));
3622 framer_.SetEncrypter(ENCRYPTION_INITIAL, new TaggingEncrypter(tag)); 3621 framer_.SetEncrypter(ENCRYPTION_INITIAL, new TaggingEncrypter(tag));
3623 // Process a packet from the non-crypto stream. 3622 // Process a packet from the non-crypto stream.
3624 frame1_.stream_id = 3; 3623 frame1_.stream_id = 3;
3625 3624
3626 // The same as ProcessPacket(1) except that ENCRYPTION_INITIAL is used 3625 // The same as ProcessPacket(1) except that ENCRYPTION_INITIAL is used
3627 // instead of ENCRYPTION_NONE. 3626 // instead of ENCRYPTION_NONE.
3628 EXPECT_CALL(visitor_, OnStreamFrames(_)).Times(1); 3627 EXPECT_CALL(visitor_, OnStreamFrame(_)).Times(1);
3629 ProcessDataPacketAtLevel(1, 0, !kEntropyFlag, ENCRYPTION_INITIAL); 3628 ProcessDataPacketAtLevel(1, 0, !kEntropyFlag, ENCRYPTION_INITIAL);
3630 3629
3631 // Check if delayed ack timer is running for the expected interval. 3630 // Check if delayed ack timer is running for the expected interval.
3632 EXPECT_TRUE(connection_.GetAckAlarm()->IsSet()); 3631 EXPECT_TRUE(connection_.GetAckAlarm()->IsSet());
3633 EXPECT_EQ(ack_time, connection_.GetAckAlarm()->deadline()); 3632 EXPECT_EQ(ack_time, connection_.GetAckAlarm()->deadline());
3634 // Simulate delayed ack alarm firing. 3633 // Simulate delayed ack alarm firing.
3635 connection_.GetAckAlarm()->Fire(); 3634 connection_.GetAckAlarm()->Fire();
3636 // Check that ack is sent and that delayed ack alarm is reset. 3635 // Check that ack is sent and that delayed ack alarm is reset.
3637 EXPECT_EQ(2u, writer_->frame_count()); 3636 EXPECT_EQ(2u, writer_->frame_count());
3638 EXPECT_FALSE(writer_->stop_waiting_frames().empty()); 3637 EXPECT_FALSE(writer_->stop_waiting_frames().empty());
(...skipping 211 matching lines...) Expand 10 before | Expand all | Expand 10 after
3850 EXPECT_CALL(visitor_, OnGoAway(_)); 3849 EXPECT_CALL(visitor_, OnGoAway(_));
3851 ProcessGoAwayPacket(&goaway); 3850 ProcessGoAwayPacket(&goaway);
3852 } 3851 }
3853 3852
3854 TEST_P(QuicConnectionTest, WindowUpdate) { 3853 TEST_P(QuicConnectionTest, WindowUpdate) {
3855 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); 3854 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_));
3856 3855
3857 QuicWindowUpdateFrame window_update; 3856 QuicWindowUpdateFrame window_update;
3858 window_update.stream_id = 3; 3857 window_update.stream_id = 3;
3859 window_update.byte_offset = 1234; 3858 window_update.byte_offset = 1234;
3860 EXPECT_CALL(visitor_, OnWindowUpdateFrames(_)); 3859 EXPECT_CALL(visitor_, OnWindowUpdateFrame(_));
3861 ProcessFramePacket(QuicFrame(&window_update)); 3860 ProcessFramePacket(QuicFrame(&window_update));
3862 } 3861 }
3863 3862
3864 TEST_P(QuicConnectionTest, Blocked) { 3863 TEST_P(QuicConnectionTest, Blocked) {
3865 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); 3864 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_));
3866 3865
3867 QuicBlockedFrame blocked; 3866 QuicBlockedFrame blocked;
3868 blocked.stream_id = 3; 3867 blocked.stream_id = 3;
3869 EXPECT_CALL(visitor_, OnBlockedFrames(_)); 3868 EXPECT_CALL(visitor_, OnBlockedFrame(_));
3870 ProcessFramePacket(QuicFrame(&blocked)); 3869 ProcessFramePacket(QuicFrame(&blocked));
3871 } 3870 }
3872 3871
3873 TEST_P(QuicConnectionTest, ZeroBytePacket) { 3872 TEST_P(QuicConnectionTest, ZeroBytePacket) {
3874 // Don't close the connection for zero byte packets. 3873 // Don't close the connection for zero byte packets.
3875 EXPECT_CALL(visitor_, OnConnectionClosed(_, _)).Times(0); 3874 EXPECT_CALL(visitor_, OnConnectionClosed(_, _)).Times(0);
3876 QuicEncryptedPacket encrypted(nullptr, 0); 3875 QuicEncryptedPacket encrypted(nullptr, 0);
3877 connection_.ProcessUdpPacket(IPEndPoint(), IPEndPoint(), encrypted); 3876 connection_.ProcessUdpPacket(IPEndPoint(), IPEndPoint(), encrypted);
3878 } 3877 }
3879 3878
3880 TEST_P(QuicConnectionTest, MissingPacketsBeforeLeastUnacked) { 3879 TEST_P(QuicConnectionTest, MissingPacketsBeforeLeastUnacked) {
3881 // Set the sequence number of the ack packet to be least unacked (4). 3880 // Set the sequence number of the ack packet to be least unacked (4).
3882 QuicPacketCreatorPeer::SetSequenceNumber(&peer_creator_, 3); 3881 QuicPacketCreatorPeer::SetSequenceNumber(&peer_creator_, 3);
3883 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); 3882 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_));
3884 QuicStopWaitingFrame frame = InitStopWaitingFrame(4); 3883 QuicStopWaitingFrame frame = InitStopWaitingFrame(4);
3885 ProcessStopWaitingPacket(&frame); 3884 ProcessStopWaitingPacket(&frame);
3886 EXPECT_TRUE(outgoing_ack()->missing_packets.empty()); 3885 EXPECT_TRUE(outgoing_ack()->missing_packets.empty());
3887 } 3886 }
3888 3887
3889 TEST_P(QuicConnectionTest, ReceivedEntropyHashCalculation) { 3888 TEST_P(QuicConnectionTest, ReceivedEntropyHashCalculation) {
3890 EXPECT_CALL(visitor_, OnStreamFrames(_)).Times(AtLeast(1)); 3889 EXPECT_CALL(visitor_, OnStreamFrame(_)).Times(AtLeast(1));
3891 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); 3890 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_));
3892 ProcessDataPacket(1, 1, kEntropyFlag); 3891 ProcessDataPacket(1, 1, kEntropyFlag);
3893 ProcessDataPacket(4, 1, kEntropyFlag); 3892 ProcessDataPacket(4, 1, kEntropyFlag);
3894 ProcessDataPacket(3, 1, !kEntropyFlag); 3893 ProcessDataPacket(3, 1, !kEntropyFlag);
3895 ProcessDataPacket(7, 1, kEntropyFlag); 3894 ProcessDataPacket(7, 1, kEntropyFlag);
3896 EXPECT_EQ(146u, outgoing_ack()->entropy_hash); 3895 EXPECT_EQ(146u, outgoing_ack()->entropy_hash);
3897 } 3896 }
3898 3897
3899 TEST_P(QuicConnectionTest, ReceivedEntropyHashCalculationHalfFEC) { 3898 TEST_P(QuicConnectionTest, ReceivedEntropyHashCalculationHalfFEC) {
3900 // FEC packets should not change the entropy hash calculation. 3899 // FEC packets should not change the entropy hash calculation.
3901 EXPECT_CALL(visitor_, OnStreamFrames(_)).Times(AtLeast(1)); 3900 EXPECT_CALL(visitor_, OnStreamFrame(_)).Times(AtLeast(1));
3902 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); 3901 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_));
3903 ProcessDataPacket(1, 1, kEntropyFlag); 3902 ProcessDataPacket(1, 1, kEntropyFlag);
3904 ProcessFecPacket(4, 1, false, kEntropyFlag, nullptr); 3903 ProcessFecPacket(4, 1, false, kEntropyFlag, nullptr);
3905 ProcessDataPacket(3, 3, !kEntropyFlag); 3904 ProcessDataPacket(3, 3, !kEntropyFlag);
3906 ProcessFecPacket(7, 3, false, kEntropyFlag, nullptr); 3905 ProcessFecPacket(7, 3, false, kEntropyFlag, nullptr);
3907 EXPECT_EQ(146u, outgoing_ack()->entropy_hash); 3906 EXPECT_EQ(146u, outgoing_ack()->entropy_hash);
3908 } 3907 }
3909 3908
3910 TEST_P(QuicConnectionTest, UpdateEntropyForReceivedPackets) { 3909 TEST_P(QuicConnectionTest, UpdateEntropyForReceivedPackets) {
3911 EXPECT_CALL(visitor_, OnStreamFrames(_)).Times(AtLeast(1)); 3910 EXPECT_CALL(visitor_, OnStreamFrame(_)).Times(AtLeast(1));
3912 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); 3911 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_));
3913 ProcessDataPacket(1, 1, kEntropyFlag); 3912 ProcessDataPacket(1, 1, kEntropyFlag);
3914 ProcessDataPacket(5, 1, kEntropyFlag); 3913 ProcessDataPacket(5, 1, kEntropyFlag);
3915 ProcessDataPacket(4, 1, !kEntropyFlag); 3914 ProcessDataPacket(4, 1, !kEntropyFlag);
3916 EXPECT_EQ(34u, outgoing_ack()->entropy_hash); 3915 EXPECT_EQ(34u, outgoing_ack()->entropy_hash);
3917 // Make 4th packet my least unacked, and update entropy for 2, 3 packets. 3916 // Make 4th packet my least unacked, and update entropy for 2, 3 packets.
3918 QuicPacketCreatorPeer::SetSequenceNumber(&peer_creator_, 5); 3917 QuicPacketCreatorPeer::SetSequenceNumber(&peer_creator_, 5);
3919 QuicPacketEntropyHash six_packet_entropy_hash = 0; 3918 QuicPacketEntropyHash six_packet_entropy_hash = 0;
3920 QuicPacketEntropyHash random_entropy_hash = 129u; 3919 QuicPacketEntropyHash random_entropy_hash = 129u;
3921 QuicStopWaitingFrame frame = InitStopWaitingFrame(4); 3920 QuicStopWaitingFrame frame = InitStopWaitingFrame(4);
3922 frame.entropy_hash = random_entropy_hash; 3921 frame.entropy_hash = random_entropy_hash;
3923 if (ProcessStopWaitingPacket(&frame)) { 3922 if (ProcessStopWaitingPacket(&frame)) {
3924 six_packet_entropy_hash = 1 << 6; 3923 six_packet_entropy_hash = 1 << 6;
3925 } 3924 }
3926 3925
3927 EXPECT_EQ((random_entropy_hash + (1 << 5) + six_packet_entropy_hash), 3926 EXPECT_EQ((random_entropy_hash + (1 << 5) + six_packet_entropy_hash),
3928 outgoing_ack()->entropy_hash); 3927 outgoing_ack()->entropy_hash);
3929 } 3928 }
3930 3929
3931 TEST_P(QuicConnectionTest, UpdateEntropyHashUptoCurrentPacket) { 3930 TEST_P(QuicConnectionTest, UpdateEntropyHashUptoCurrentPacket) {
3932 EXPECT_CALL(visitor_, OnStreamFrames(_)).Times(AtLeast(1)); 3931 EXPECT_CALL(visitor_, OnStreamFrame(_)).Times(AtLeast(1));
3933 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); 3932 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_));
3934 ProcessDataPacket(1, 1, kEntropyFlag); 3933 ProcessDataPacket(1, 1, kEntropyFlag);
3935 ProcessDataPacket(5, 1, !kEntropyFlag); 3934 ProcessDataPacket(5, 1, !kEntropyFlag);
3936 ProcessDataPacket(22, 1, kEntropyFlag); 3935 ProcessDataPacket(22, 1, kEntropyFlag);
3937 EXPECT_EQ(66u, outgoing_ack()->entropy_hash); 3936 EXPECT_EQ(66u, outgoing_ack()->entropy_hash);
3938 QuicPacketCreatorPeer::SetSequenceNumber(&peer_creator_, 22); 3937 QuicPacketCreatorPeer::SetSequenceNumber(&peer_creator_, 22);
3939 QuicPacketEntropyHash random_entropy_hash = 85u; 3938 QuicPacketEntropyHash random_entropy_hash = 85u;
3940 // Current packet is the least unacked packet. 3939 // Current packet is the least unacked packet.
3941 QuicPacketEntropyHash ack_entropy_hash; 3940 QuicPacketEntropyHash ack_entropy_hash;
3942 QuicStopWaitingFrame frame = InitStopWaitingFrame(23); 3941 QuicStopWaitingFrame frame = InitStopWaitingFrame(23);
3943 frame.entropy_hash = random_entropy_hash; 3942 frame.entropy_hash = random_entropy_hash;
3944 ack_entropy_hash = ProcessStopWaitingPacket(&frame); 3943 ack_entropy_hash = ProcessStopWaitingPacket(&frame);
3945 EXPECT_EQ((random_entropy_hash + ack_entropy_hash), 3944 EXPECT_EQ((random_entropy_hash + ack_entropy_hash),
3946 outgoing_ack()->entropy_hash); 3945 outgoing_ack()->entropy_hash);
3947 ProcessDataPacket(25, 1, kEntropyFlag); 3946 ProcessDataPacket(25, 1, kEntropyFlag);
3948 EXPECT_EQ((random_entropy_hash + ack_entropy_hash + (1 << (25 % 8))), 3947 EXPECT_EQ((random_entropy_hash + ack_entropy_hash + (1 << (25 % 8))),
3949 outgoing_ack()->entropy_hash); 3948 outgoing_ack()->entropy_hash);
3950 } 3949 }
3951 3950
3952 TEST_P(QuicConnectionTest, EntropyCalculationForTruncatedAck) { 3951 TEST_P(QuicConnectionTest, EntropyCalculationForTruncatedAck) {
3953 EXPECT_CALL(visitor_, OnStreamFrames(_)).Times(AtLeast(1)); 3952 EXPECT_CALL(visitor_, OnStreamFrame(_)).Times(AtLeast(1));
3954 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); 3953 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_));
3955 QuicPacketEntropyHash entropy[51]; 3954 QuicPacketEntropyHash entropy[51];
3956 entropy[0] = 0; 3955 entropy[0] = 0;
3957 for (int i = 1; i < 51; ++i) { 3956 for (int i = 1; i < 51; ++i) {
3958 bool should_send = i % 10 != 1; 3957 bool should_send = i % 10 != 1;
3959 bool entropy_flag = (i & (i - 1)) != 0; 3958 bool entropy_flag = (i & (i - 1)) != 0;
3960 if (!should_send) { 3959 if (!should_send) {
3961 entropy[i] = entropy[i - 1]; 3960 entropy[i] = entropy[i - 1];
3962 continue; 3961 continue;
3963 } 3962 }
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after
4095 4094
4096 // Now force another packet. The connection should transition into 4095 // Now force another packet. The connection should transition into
4097 // NEGOTIATED_VERSION state and tell the packet creator to StopSendingVersion. 4096 // NEGOTIATED_VERSION state and tell the packet creator to StopSendingVersion.
4098 header.public_header.version_flag = false; 4097 header.public_header.version_flag = false;
4099 QuicFrames frames; 4098 QuicFrames frames;
4100 frames.push_back(QuicFrame(&frame1_)); 4099 frames.push_back(QuicFrame(&frame1_));
4101 scoped_ptr<QuicPacket> packet(ConstructPacket(header, frames)); 4100 scoped_ptr<QuicPacket> packet(ConstructPacket(header, frames));
4102 char buffer[kMaxPacketSize]; 4101 char buffer[kMaxPacketSize];
4103 encrypted.reset(framer_.EncryptPayload(ENCRYPTION_NONE, 12, *packet, buffer, 4102 encrypted.reset(framer_.EncryptPayload(ENCRYPTION_NONE, 12, *packet, buffer,
4104 kMaxPacketSize)); 4103 kMaxPacketSize));
4105 EXPECT_CALL(visitor_, OnStreamFrames(_)).Times(1); 4104 EXPECT_CALL(visitor_, OnStreamFrame(_)).Times(1);
4106 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); 4105 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_));
4107 connection_.ProcessUdpPacket(IPEndPoint(), IPEndPoint(), *encrypted); 4106 connection_.ProcessUdpPacket(IPEndPoint(), IPEndPoint(), *encrypted);
4108 4107
4109 ASSERT_FALSE(QuicPacketCreatorPeer::SendVersionInPacket(creator_)); 4108 ASSERT_FALSE(QuicPacketCreatorPeer::SendVersionInPacket(creator_));
4110 } 4109 }
4111 4110
4112 TEST_P(QuicConnectionTest, BadVersionNegotiation) { 4111 TEST_P(QuicConnectionTest, BadVersionNegotiation) {
4113 QuicPacketHeader header; 4112 QuicPacketHeader header;
4114 header.public_header.connection_id = connection_id_; 4113 header.public_header.connection_id = connection_id_;
4115 header.public_header.version_flag = true; 4114 header.public_header.version_flag = true;
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after
4232 QuicFrames frames; 4231 QuicFrames frames;
4233 frames.push_back(QuicFrame(&frame1_)); 4232 frames.push_back(QuicFrame(&frame1_));
4234 frames.push_back(QuicFrame(&qccf)); 4233 frames.push_back(QuicFrame(&qccf));
4235 scoped_ptr<QuicPacket> packet(ConstructPacket(header, frames)); 4234 scoped_ptr<QuicPacket> packet(ConstructPacket(header, frames));
4236 EXPECT_TRUE(nullptr != packet.get()); 4235 EXPECT_TRUE(nullptr != packet.get());
4237 char buffer[kMaxPacketSize]; 4236 char buffer[kMaxPacketSize];
4238 scoped_ptr<QuicEncryptedPacket> encrypted(framer_.EncryptPayload( 4237 scoped_ptr<QuicEncryptedPacket> encrypted(framer_.EncryptPayload(
4239 ENCRYPTION_NONE, 1, *packet, buffer, kMaxPacketSize)); 4238 ENCRYPTION_NONE, 1, *packet, buffer, kMaxPacketSize));
4240 4239
4241 EXPECT_CALL(visitor_, OnConnectionClosed(QUIC_PEER_GOING_AWAY, true)); 4240 EXPECT_CALL(visitor_, OnConnectionClosed(QUIC_PEER_GOING_AWAY, true));
4242 EXPECT_CALL(visitor_, OnStreamFrames(_)).Times(1); 4241 EXPECT_CALL(visitor_, OnStreamFrame(_)).Times(1);
4243 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); 4242 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_));
4244 4243
4245 connection_.ProcessUdpPacket(IPEndPoint(), IPEndPoint(), *encrypted); 4244 connection_.ProcessUdpPacket(IPEndPoint(), IPEndPoint(), *encrypted);
4246 } 4245 }
4247 4246
4248 TEST_P(QuicConnectionTest, SelectMutualVersion) { 4247 TEST_P(QuicConnectionTest, SelectMutualVersion) {
4249 connection_.SetSupportedVersions(QuicSupportedVersions()); 4248 connection_.SetSupportedVersions(QuicSupportedVersions());
4250 // Set the connection to speak the lowest quic version. 4249 // Set the connection to speak the lowest quic version.
4251 connection_.set_version(QuicVersionMin()); 4250 connection_.set_version(QuicVersionMin());
4252 EXPECT_EQ(QuicVersionMin(), connection_.version()); 4251 EXPECT_EQ(QuicVersionMin(), connection_.version());
(...skipping 342 matching lines...) Expand 10 before | Expand all | Expand 10 after
4595 EXPECT_FALSE(server.sent_packet_manager().using_pacing()); 4594 EXPECT_FALSE(server.sent_packet_manager().using_pacing());
4596 } 4595 }
4597 4596
4598 TEST_P(QuicConnectionTest, ControlFramesInstigateAcks) { 4597 TEST_P(QuicConnectionTest, ControlFramesInstigateAcks) {
4599 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); 4598 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_));
4600 4599
4601 // Send a WINDOW_UPDATE frame. 4600 // Send a WINDOW_UPDATE frame.
4602 QuicWindowUpdateFrame window_update; 4601 QuicWindowUpdateFrame window_update;
4603 window_update.stream_id = 3; 4602 window_update.stream_id = 3;
4604 window_update.byte_offset = 1234; 4603 window_update.byte_offset = 1234;
4605 EXPECT_CALL(visitor_, OnWindowUpdateFrames(_)); 4604 EXPECT_CALL(visitor_, OnWindowUpdateFrame(_));
4606 ProcessFramePacket(QuicFrame(&window_update)); 4605 ProcessFramePacket(QuicFrame(&window_update));
4607 4606
4608 // Ensure that this has caused the ACK alarm to be set. 4607 // Ensure that this has caused the ACK alarm to be set.
4609 QuicAlarm* ack_alarm = QuicConnectionPeer::GetAckAlarm(&connection_); 4608 QuicAlarm* ack_alarm = QuicConnectionPeer::GetAckAlarm(&connection_);
4610 EXPECT_TRUE(ack_alarm->IsSet()); 4609 EXPECT_TRUE(ack_alarm->IsSet());
4611 4610
4612 // Cancel alarm, and try again with BLOCKED frame. 4611 // Cancel alarm, and try again with BLOCKED frame.
4613 ack_alarm->Cancel(); 4612 ack_alarm->Cancel();
4614 QuicBlockedFrame blocked; 4613 QuicBlockedFrame blocked;
4615 blocked.stream_id = 3; 4614 blocked.stream_id = 3;
4616 EXPECT_CALL(visitor_, OnBlockedFrames(_)); 4615 EXPECT_CALL(visitor_, OnBlockedFrame(_));
4617 ProcessFramePacket(QuicFrame(&blocked)); 4616 ProcessFramePacket(QuicFrame(&blocked));
4618 EXPECT_TRUE(ack_alarm->IsSet()); 4617 EXPECT_TRUE(ack_alarm->IsSet());
4619 } 4618 }
4620 4619
4621 TEST_P(QuicConnectionTest, NoDataNoFin) { 4620 TEST_P(QuicConnectionTest, NoDataNoFin) {
4622 // Make sure that a call to SendStreamWithData, with no data and no FIN, does 4621 // Make sure that a call to SendStreamWithData, with no data and no FIN, does
4623 // not result in a QuicAckNotifier being used-after-free (fail under ASAN). 4622 // not result in a QuicAckNotifier being used-after-free (fail under ASAN).
4624 // Regression test for b/18594622 4623 // Regression test for b/18594622
4625 scoped_refptr<MockAckNotifierDelegate> delegate(new MockAckNotifierDelegate); 4624 scoped_refptr<MockAckNotifierDelegate> delegate(new MockAckNotifierDelegate);
4626 EXPECT_DFATAL( 4625 EXPECT_DFATAL(
(...skipping 18 matching lines...) Expand all
4645 copt.push_back(kFSPA); 4644 copt.push_back(kFSPA);
4646 QuicConfigPeer::SetReceivedConnectionOptions(&config, copt); 4645 QuicConfigPeer::SetReceivedConnectionOptions(&config, copt);
4647 EXPECT_EQ(FEC_ANY_TRIGGER, generator_->fec_send_policy()); 4646 EXPECT_EQ(FEC_ANY_TRIGGER, generator_->fec_send_policy());
4648 connection_.SetFromConfig(config); 4647 connection_.SetFromConfig(config);
4649 EXPECT_EQ(FEC_ALARM_TRIGGER, generator_->fec_send_policy()); 4648 EXPECT_EQ(FEC_ALARM_TRIGGER, generator_->fec_send_policy());
4650 } 4649 }
4651 4650
4652 } // namespace 4651 } // namespace
4653 } // namespace test 4652 } // namespace test
4654 } // namespace net 4653 } // namespace net
OLDNEW
« no previous file with comments | « net/quic/quic_connection.cc ('k') | net/quic/quic_session.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698