| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "net/quic/quic_connection.h" | 5 #include "net/quic/quic_connection.h" |
| 6 | 6 |
| 7 #include <ostream> | 7 #include <ostream> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/macros.h" | 10 #include "base/macros.h" |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 54 | 54 |
| 55 namespace net { | 55 namespace net { |
| 56 namespace test { | 56 namespace test { |
| 57 namespace { | 57 namespace { |
| 58 | 58 |
| 59 const char data1[] = "foo"; | 59 const char data1[] = "foo"; |
| 60 const char data2[] = "bar"; | 60 const char data2[] = "bar"; |
| 61 | 61 |
| 62 const bool kFin = true; | 62 const bool kFin = true; |
| 63 const bool kEntropyFlag = true; | 63 const bool kEntropyFlag = true; |
| 64 const bool kHasStopWaiting = true; |
| 64 | 65 |
| 65 const QuicPacketEntropyHash kTestEntropyHash = 76; | 66 const QuicPacketEntropyHash kTestEntropyHash = 76; |
| 66 | 67 |
| 67 const int kDefaultRetransmissionTimeMs = 500; | 68 const int kDefaultRetransmissionTimeMs = 500; |
| 68 | 69 |
| 69 const IPEndPoint kPeerAddress = IPEndPoint(Loopback6(), /*port=*/12345); | 70 const IPEndPoint kPeerAddress = IPEndPoint(Loopback6(), /*port=*/12345); |
| 70 const IPEndPoint kSelfAddress = IPEndPoint(Loopback6(), /*port=*/443); | 71 const IPEndPoint kSelfAddress = IPEndPoint(Loopback6(), /*port=*/443); |
| 71 | 72 |
| 72 // TaggingEncrypter appends kTagSize bytes of |tag| to the end of each message. | 73 // TaggingEncrypter appends kTagSize bytes of |tag| to the end of each message. |
| 73 class TaggingEncrypter : public QuicEncrypter { | 74 class TaggingEncrypter : public QuicEncrypter { |
| (...skipping 369 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 443 RetransmittableFrames* retransmittable_frames = | 444 RetransmittableFrames* retransmittable_frames = |
| 444 retransmittable == HAS_RETRANSMITTABLE_DATA | 445 retransmittable == HAS_RETRANSMITTABLE_DATA |
| 445 ? new RetransmittableFrames() | 446 ? new RetransmittableFrames() |
| 446 : nullptr; | 447 : nullptr; |
| 447 char buffer[kMaxPacketSize]; | 448 char buffer[kMaxPacketSize]; |
| 448 size_t encrypted_length = | 449 size_t encrypted_length = |
| 449 QuicConnectionPeer::GetFramer(this)->EncryptPayload( | 450 QuicConnectionPeer::GetFramer(this)->EncryptPayload( |
| 450 ENCRYPTION_NONE, packet_number, *packet, buffer, kMaxPacketSize); | 451 ENCRYPTION_NONE, packet_number, *packet, buffer, kMaxPacketSize); |
| 451 delete packet; | 452 delete packet; |
| 452 SerializedPacket serialized_packet( | 453 SerializedPacket serialized_packet( |
| 453 packet_number, PACKET_6BYTE_PACKET_NUMBER, buffer, encrypted_length, | 454 kDefaultPathId, packet_number, PACKET_6BYTE_PACKET_NUMBER, buffer, |
| 454 false, entropy_hash, retransmittable_frames, has_ack, | 455 encrypted_length, false, entropy_hash, retransmittable_frames, has_ack, |
| 455 has_pending_frames, ENCRYPTION_NONE); | 456 has_pending_frames, ENCRYPTION_NONE); |
| 456 OnSerializedPacket(&serialized_packet); | 457 OnSerializedPacket(&serialized_packet); |
| 457 } | 458 } |
| 458 | 459 |
| 459 QuicConsumedData SendStreamDataWithString( | 460 QuicConsumedData SendStreamDataWithString( |
| 460 QuicStreamId id, | 461 QuicStreamId id, |
| 461 StringPiece data, | 462 StringPiece data, |
| 462 QuicStreamOffset offset, | 463 QuicStreamOffset offset, |
| 463 bool fin, | 464 bool fin, |
| 464 QuicAckListenerInterface* listener) { | 465 QuicAckListenerInterface* listener) { |
| (...skipping 323 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 788 framer_.EncryptPayload(level, number, *packet, buffer, kMaxPacketSize); | 789 framer_.EncryptPayload(level, number, *packet, buffer, kMaxPacketSize); |
| 789 connection_.ProcessUdpPacket( | 790 connection_.ProcessUdpPacket( |
| 790 kSelfAddress, kPeerAddress, | 791 kSelfAddress, kPeerAddress, |
| 791 QuicEncryptedPacket(buffer, encrypted_length, false)); | 792 QuicEncryptedPacket(buffer, encrypted_length, false)); |
| 792 return base::checked_cast<QuicPacketEntropyHash>(encrypted_length); | 793 return base::checked_cast<QuicPacketEntropyHash>(encrypted_length); |
| 793 } | 794 } |
| 794 | 795 |
| 795 size_t ProcessDataPacket(QuicPacketNumber number, | 796 size_t ProcessDataPacket(QuicPacketNumber number, |
| 796 QuicFecGroupNumber fec_group, | 797 QuicFecGroupNumber fec_group, |
| 797 bool entropy_flag) { | 798 bool entropy_flag) { |
| 798 return ProcessDataPacketAtLevel(number, fec_group, entropy_flag, | 799 return ProcessDataPacketAtLevel(number, fec_group, entropy_flag, false, |
| 799 ENCRYPTION_NONE); | 800 ENCRYPTION_NONE); |
| 800 } | 801 } |
| 801 | 802 |
| 802 size_t ProcessDataPacketAtLevel(QuicPacketNumber number, | 803 size_t ProcessDataPacketAtLevel(QuicPacketNumber number, |
| 803 QuicFecGroupNumber fec_group, | 804 QuicFecGroupNumber fec_group, |
| 804 bool entropy_flag, | 805 bool entropy_flag, |
| 806 bool has_stop_waiting, |
| 805 EncryptionLevel level) { | 807 EncryptionLevel level) { |
| 806 scoped_ptr<QuicPacket> packet( | 808 scoped_ptr<QuicPacket> packet( |
| 807 ConstructDataPacket(number, fec_group, entropy_flag)); | 809 ConstructDataPacket(number, fec_group, entropy_flag, has_stop_waiting)); |
| 808 char buffer[kMaxPacketSize]; | 810 char buffer[kMaxPacketSize]; |
| 809 size_t encrypted_length = | 811 size_t encrypted_length = |
| 810 framer_.EncryptPayload(level, number, *packet, buffer, kMaxPacketSize); | 812 framer_.EncryptPayload(level, number, *packet, buffer, kMaxPacketSize); |
| 811 connection_.ProcessUdpPacket( | 813 connection_.ProcessUdpPacket( |
| 812 kSelfAddress, kPeerAddress, | 814 kSelfAddress, kPeerAddress, |
| 813 QuicEncryptedPacket(buffer, encrypted_length, false)); | 815 QuicEncryptedPacket(buffer, encrypted_length, false)); |
| 814 return encrypted_length; | 816 return encrypted_length; |
| 815 } | 817 } |
| 816 | 818 |
| 817 void ProcessClosePacket(QuicPacketNumber number, | 819 void ProcessClosePacket(QuicPacketNumber number, |
| 818 QuicFecGroupNumber fec_group) { | 820 QuicFecGroupNumber fec_group) { |
| 819 scoped_ptr<QuicPacket> packet(ConstructClosePacket(number, fec_group)); | 821 scoped_ptr<QuicPacket> packet(ConstructClosePacket(number, fec_group)); |
| 820 char buffer[kMaxPacketSize]; | 822 char buffer[kMaxPacketSize]; |
| 821 size_t encrypted_length = framer_.EncryptPayload( | 823 size_t encrypted_length = framer_.EncryptPayload( |
| 822 ENCRYPTION_NONE, number, *packet, buffer, kMaxPacketSize); | 824 ENCRYPTION_NONE, number, *packet, buffer, kMaxPacketSize); |
| 823 connection_.ProcessUdpPacket( | 825 connection_.ProcessUdpPacket( |
| 824 kSelfAddress, kPeerAddress, | 826 kSelfAddress, kPeerAddress, |
| 825 QuicEncryptedPacket(buffer, encrypted_length, false)); | 827 QuicEncryptedPacket(buffer, encrypted_length, false)); |
| 826 } | 828 } |
| 827 | 829 |
| 828 size_t ProcessFecProtectedPacket(QuicPacketNumber number, | 830 size_t ProcessFecProtectedPacket(QuicPacketNumber number, |
| 829 bool expect_revival, | 831 bool expect_revival, |
| 830 bool entropy_flag) { | 832 bool entropy_flag, |
| 833 bool has_stop_waiting) { |
| 831 return ProcessFecProtectedPacketAtLevel(number, 1, expect_revival, | 834 return ProcessFecProtectedPacketAtLevel(number, 1, expect_revival, |
| 832 entropy_flag, ENCRYPTION_NONE); | 835 entropy_flag, has_stop_waiting, |
| 836 ENCRYPTION_NONE); |
| 833 } | 837 } |
| 834 | 838 |
| 835 size_t ProcessFecProtectedPacketAtLevel(QuicPacketNumber number, | 839 size_t ProcessFecProtectedPacketAtLevel(QuicPacketNumber number, |
| 836 QuicFecGroupNumber fec_group, | 840 QuicFecGroupNumber fec_group, |
| 837 bool expect_revival, | 841 bool expect_revival, |
| 838 bool entropy_flag, | 842 bool entropy_flag, |
| 843 bool has_stop_waiting, |
| 839 EncryptionLevel level) { | 844 EncryptionLevel level) { |
| 840 if (expect_revival) { | 845 if (expect_revival) { |
| 841 EXPECT_CALL(visitor_, OnStreamFrame(_)).Times(1); | 846 EXPECT_CALL(visitor_, OnStreamFrame(_)).Times(1); |
| 842 } | 847 } |
| 843 EXPECT_CALL(visitor_, OnStreamFrame(_)).Times(1).RetiresOnSaturation(); | 848 EXPECT_CALL(visitor_, OnStreamFrame(_)).Times(1).RetiresOnSaturation(); |
| 844 return ProcessDataPacketAtLevel(number, fec_group, entropy_flag, level); | 849 return ProcessDataPacketAtLevel(number, fec_group, entropy_flag, |
| 850 has_stop_waiting, level); |
| 845 } | 851 } |
| 846 | 852 |
| 847 // Processes an FEC packet that covers the packets that would have been | 853 // Processes an FEC packet that covers the packets that would have been |
| 848 // received. | 854 // received. |
| 849 size_t ProcessFecPacket(QuicPacketNumber number, | 855 size_t ProcessFecPacket(QuicPacketNumber number, |
| 850 QuicPacketNumber min_protected_packet, | 856 QuicPacketNumber min_protected_packet, |
| 851 bool expect_revival, | 857 bool expect_revival, |
| 852 bool entropy_flag, | 858 bool entropy_flag, |
| 853 QuicPacket* packet) { | 859 QuicPacket* packet) { |
| 854 return ProcessFecPacketAtLevel(number, min_protected_packet, expect_revival, | 860 return ProcessFecPacketAtLevel(number, min_protected_packet, expect_revival, |
| (...skipping 12 matching lines...) Expand all Loading... |
| 867 EXPECT_CALL(visitor_, OnStreamFrame(_)).Times(1); | 873 EXPECT_CALL(visitor_, OnStreamFrame(_)).Times(1); |
| 868 } | 874 } |
| 869 | 875 |
| 870 // Construct the decrypted data packet so we can compute the correct | 876 // Construct the decrypted data packet so we can compute the correct |
| 871 // redundancy. If |packet| has been provided then use that, otherwise | 877 // redundancy. If |packet| has been provided then use that, otherwise |
| 872 // construct a default data packet. | 878 // construct a default data packet. |
| 873 scoped_ptr<QuicPacket> data_packet; | 879 scoped_ptr<QuicPacket> data_packet; |
| 874 if (packet) { | 880 if (packet) { |
| 875 data_packet.reset(packet); | 881 data_packet.reset(packet); |
| 876 } else { | 882 } else { |
| 877 data_packet.reset(ConstructDataPacket(number, 1, !kEntropyFlag)); | 883 data_packet.reset( |
| 884 ConstructDataPacket(number, 1, !kEntropyFlag, !kHasStopWaiting)); |
| 878 } | 885 } |
| 879 | 886 |
| 880 QuicPacketHeader header; | 887 QuicPacketHeader header; |
| 881 header.public_header.connection_id = connection_id_; | 888 header.public_header.connection_id = connection_id_; |
| 882 header.public_header.packet_number_length = packet_number_length_; | 889 header.public_header.packet_number_length = packet_number_length_; |
| 883 header.public_header.connection_id_length = connection_id_length_; | 890 header.public_header.connection_id_length = connection_id_length_; |
| 884 header.packet_number = number; | 891 header.packet_number = number; |
| 885 header.entropy_flag = entropy_flag; | 892 header.entropy_flag = entropy_flag; |
| 886 header.fec_flag = true; | 893 header.fec_flag = true; |
| 887 header.is_in_fec_group = IN_FEC_GROUP; | 894 header.is_in_fec_group = IN_FEC_GROUP; |
| (...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 966 } | 973 } |
| 967 | 974 |
| 968 QuicPacket* ConstructPacket(QuicPacketHeader header, QuicFrames frames) { | 975 QuicPacket* ConstructPacket(QuicPacketHeader header, QuicFrames frames) { |
| 969 QuicPacket* packet = BuildUnsizedDataPacket(&framer_, header, frames); | 976 QuicPacket* packet = BuildUnsizedDataPacket(&framer_, header, frames); |
| 970 EXPECT_NE(nullptr, packet); | 977 EXPECT_NE(nullptr, packet); |
| 971 return packet; | 978 return packet; |
| 972 } | 979 } |
| 973 | 980 |
| 974 QuicPacket* ConstructDataPacket(QuicPacketNumber number, | 981 QuicPacket* ConstructDataPacket(QuicPacketNumber number, |
| 975 QuicFecGroupNumber fec_group, | 982 QuicFecGroupNumber fec_group, |
| 976 bool entropy_flag) { | 983 bool entropy_flag, |
| 984 bool has_stop_waiting) { |
| 977 QuicPacketHeader header; | 985 QuicPacketHeader header; |
| 978 header.public_header.connection_id = connection_id_; | 986 header.public_header.connection_id = connection_id_; |
| 979 header.public_header.packet_number_length = packet_number_length_; | 987 header.public_header.packet_number_length = packet_number_length_; |
| 980 header.public_header.connection_id_length = connection_id_length_; | 988 header.public_header.connection_id_length = connection_id_length_; |
| 981 header.entropy_flag = entropy_flag; | 989 header.entropy_flag = entropy_flag; |
| 982 header.packet_number = number; | 990 header.packet_number = number; |
| 983 header.is_in_fec_group = fec_group == 0u ? NOT_IN_FEC_GROUP : IN_FEC_GROUP; | 991 header.is_in_fec_group = fec_group == 0u ? NOT_IN_FEC_GROUP : IN_FEC_GROUP; |
| 984 header.fec_group = fec_group; | 992 header.fec_group = fec_group; |
| 985 | 993 |
| 986 QuicFrames frames; | 994 QuicFrames frames; |
| 987 frames.push_back(QuicFrame(&frame1_)); | 995 frames.push_back(QuicFrame(&frame1_)); |
| 996 if (has_stop_waiting) { |
| 997 frames.push_back(QuicFrame(&stop_waiting_)); |
| 998 } |
| 988 return ConstructPacket(header, frames); | 999 return ConstructPacket(header, frames); |
| 989 } | 1000 } |
| 990 | 1001 |
| 991 QuicPacket* ConstructClosePacket(QuicPacketNumber number, | 1002 QuicPacket* ConstructClosePacket(QuicPacketNumber number, |
| 992 QuicFecGroupNumber fec_group) { | 1003 QuicFecGroupNumber fec_group) { |
| 993 QuicPacketHeader header; | 1004 QuicPacketHeader header; |
| 994 header.public_header.connection_id = connection_id_; | 1005 header.public_header.connection_id = connection_id_; |
| 995 header.packet_number = number; | 1006 header.packet_number = number; |
| 996 header.is_in_fec_group = fec_group == 0u ? NOT_IN_FEC_GROUP : IN_FEC_GROUP; | 1007 header.is_in_fec_group = fec_group == 0u ? NOT_IN_FEC_GROUP : IN_FEC_GROUP; |
| 997 header.fec_group = fec_group; | 1008 header.fec_group = fec_group; |
| (...skipping 2055 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3053 // Connection id length in the revived header should be the same as | 3064 // Connection id length in the revived header should be the same as |
| 3054 // in the original data/fec packet headers. | 3065 // in the original data/fec packet headers. |
| 3055 EXPECT_EQ(connection_id_length_, | 3066 EXPECT_EQ(connection_id_length_, |
| 3056 fec_visitor->revived_header().public_header.connection_id_length); | 3067 fec_visitor->revived_header().public_header.connection_id_length); |
| 3057 } | 3068 } |
| 3058 } | 3069 } |
| 3059 | 3070 |
| 3060 TEST_P(QuicConnectionTest, ReviveMissingPacketAfterDataPacketThenFecPacket) { | 3071 TEST_P(QuicConnectionTest, ReviveMissingPacketAfterDataPacketThenFecPacket) { |
| 3061 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); | 3072 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); |
| 3062 | 3073 |
| 3063 ProcessFecProtectedPacket(1, false, kEntropyFlag); | 3074 ProcessFecProtectedPacket(1, false, kEntropyFlag, !kHasStopWaiting); |
| 3064 // Don't send missing packet 2. | 3075 // Don't send missing packet 2. |
| 3065 ProcessFecPacket(3, 1, true, !kEntropyFlag, nullptr); | 3076 ProcessFecPacket(3, 1, true, !kEntropyFlag, nullptr); |
| 3066 // Entropy flag should be true, so entropy should not be 0. | 3077 // Entropy flag should be true, so entropy should not be 0. |
| 3067 EXPECT_NE(0u, QuicConnectionPeer::ReceivedEntropyHash(&connection_, 2)); | 3078 EXPECT_NE(0u, QuicConnectionPeer::ReceivedEntropyHash(&connection_, 2)); |
| 3068 } | 3079 } |
| 3069 | 3080 |
| 3070 TEST_P(QuicConnectionTest, ReviveMissingPacketAfterDataPacketsThenFecPacket) { | 3081 TEST_P(QuicConnectionTest, ReviveMissingPacketAfterDataPacketsThenFecPacket) { |
| 3071 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); | 3082 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); |
| 3072 | 3083 |
| 3073 ProcessFecProtectedPacket(1, false, !kEntropyFlag); | 3084 ProcessFecProtectedPacket(1, false, !kEntropyFlag, !kHasStopWaiting); |
| 3074 // Don't send missing packet 2. | 3085 // Don't send missing packet 2. |
| 3075 ProcessFecProtectedPacket(3, false, !kEntropyFlag); | 3086 ProcessFecProtectedPacket(3, false, !kEntropyFlag, !kHasStopWaiting); |
| 3076 ProcessFecPacket(4, 1, true, kEntropyFlag, nullptr); | 3087 ProcessFecPacket(4, 1, true, kEntropyFlag, nullptr); |
| 3077 // Ensure QUIC no longer revives entropy for lost packets. | 3088 // Ensure QUIC no longer revives entropy for lost packets. |
| 3078 EXPECT_EQ(0u, QuicConnectionPeer::ReceivedEntropyHash(&connection_, 2)); | 3089 EXPECT_EQ(0u, QuicConnectionPeer::ReceivedEntropyHash(&connection_, 2)); |
| 3079 EXPECT_NE(0u, QuicConnectionPeer::ReceivedEntropyHash(&connection_, 4)); | 3090 EXPECT_NE(0u, QuicConnectionPeer::ReceivedEntropyHash(&connection_, 4)); |
| 3080 } | 3091 } |
| 3081 | 3092 |
| 3082 TEST_P(QuicConnectionTest, ReviveMissingPacketAfterDataPacket) { | 3093 TEST_P(QuicConnectionTest, ReviveMissingPacketAfterDataPacket) { |
| 3083 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); | 3094 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); |
| 3084 | 3095 |
| 3085 // Don't send missing packet 1. | 3096 // Don't send missing packet 1. |
| 3086 ProcessFecPacket(3, 1, false, !kEntropyFlag, nullptr); | 3097 ProcessFecPacket(3, 1, false, !kEntropyFlag, nullptr); |
| 3087 // Out of order. | 3098 // Out of order. |
| 3088 ProcessFecProtectedPacket(2, true, !kEntropyFlag); | 3099 ProcessFecProtectedPacket(2, true, !kEntropyFlag, !kHasStopWaiting); |
| 3089 // Entropy flag should be false, so entropy should be 0. | 3100 // Entropy flag should be false, so entropy should be 0. |
| 3090 EXPECT_EQ(0u, QuicConnectionPeer::ReceivedEntropyHash(&connection_, 2)); | 3101 EXPECT_EQ(0u, QuicConnectionPeer::ReceivedEntropyHash(&connection_, 2)); |
| 3091 } | 3102 } |
| 3092 | 3103 |
| 3093 TEST_P(QuicConnectionTest, ReviveMissingPacketAfterDataPackets) { | 3104 TEST_P(QuicConnectionTest, ReviveMissingPacketAfterDataPackets) { |
| 3094 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); | 3105 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); |
| 3095 | 3106 |
| 3096 ProcessFecProtectedPacket(1, false, !kEntropyFlag); | 3107 ProcessFecProtectedPacket(1, false, !kEntropyFlag, !kHasStopWaiting); |
| 3097 // Don't send missing packet 2. | 3108 // Don't send missing packet 2. |
| 3098 ProcessFecPacket(6, 1, false, kEntropyFlag, nullptr); | 3109 ProcessFecPacket(6, 1, false, kEntropyFlag, nullptr); |
| 3099 ProcessFecProtectedPacket(3, false, kEntropyFlag); | 3110 ProcessFecProtectedPacket(3, false, kEntropyFlag, !kHasStopWaiting); |
| 3100 ProcessFecProtectedPacket(4, false, kEntropyFlag); | 3111 ProcessFecProtectedPacket(4, false, kEntropyFlag, !kHasStopWaiting); |
| 3101 ProcessFecProtectedPacket(5, true, !kEntropyFlag); | 3112 ProcessFecProtectedPacket(5, true, !kEntropyFlag, !kHasStopWaiting); |
| 3102 // Ensure entropy is not revived for the missing packet. | 3113 // Ensure entropy is not revived for the missing packet. |
| 3103 EXPECT_EQ(0u, QuicConnectionPeer::ReceivedEntropyHash(&connection_, 2)); | 3114 EXPECT_EQ(0u, QuicConnectionPeer::ReceivedEntropyHash(&connection_, 2)); |
| 3104 EXPECT_NE(0u, QuicConnectionPeer::ReceivedEntropyHash(&connection_, 3)); | 3115 EXPECT_NE(0u, QuicConnectionPeer::ReceivedEntropyHash(&connection_, 3)); |
| 3105 } | 3116 } |
| 3106 | 3117 |
| 3107 TEST_P(QuicConnectionTest, TLP) { | 3118 TEST_P(QuicConnectionTest, TLP) { |
| 3108 QuicSentPacketManagerPeer::SetMaxTailLossProbes(manager_, 1); | 3119 QuicSentPacketManagerPeer::SetMaxTailLossProbes(manager_, 1); |
| 3109 | 3120 |
| 3110 SendStreamDataToPeer(3, "foo", 0, !kFin, nullptr); | 3121 SendStreamDataToPeer(3, "foo", 0, !kFin, nullptr); |
| 3111 EXPECT_EQ(1u, stop_waiting()->least_unacked); | 3122 EXPECT_EQ(1u, stop_waiting()->least_unacked); |
| (...skipping 193 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3305 QuicConfig config; | 3316 QuicConfig config; |
| 3306 connection_.SetFromConfig(config); | 3317 connection_.SetFromConfig(config); |
| 3307 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); | 3318 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); |
| 3308 use_tagging_decrypter(); | 3319 use_tagging_decrypter(); |
| 3309 | 3320 |
| 3310 const uint8_t tag = 0x07; | 3321 const uint8_t tag = 0x07; |
| 3311 framer_.SetEncrypter(ENCRYPTION_INITIAL, new TaggingEncrypter(tag)); | 3322 framer_.SetEncrypter(ENCRYPTION_INITIAL, new TaggingEncrypter(tag)); |
| 3312 | 3323 |
| 3313 // Process an encrypted packet which can not yet be decrypted which should | 3324 // Process an encrypted packet which can not yet be decrypted which should |
| 3314 // result in the packet being buffered. | 3325 // result in the packet being buffered. |
| 3315 ProcessDataPacketAtLevel(1, 0, kEntropyFlag, ENCRYPTION_INITIAL); | 3326 ProcessDataPacketAtLevel(1, 0, kEntropyFlag, !kHasStopWaiting, |
| 3327 ENCRYPTION_INITIAL); |
| 3316 | 3328 |
| 3317 // Transition to the new encryption state and process another encrypted packet | 3329 // Transition to the new encryption state and process another encrypted packet |
| 3318 // which should result in the original packet being processed. | 3330 // which should result in the original packet being processed. |
| 3319 connection_.SetDecrypter(ENCRYPTION_INITIAL, new StrictTaggingDecrypter(tag)); | 3331 connection_.SetDecrypter(ENCRYPTION_INITIAL, new StrictTaggingDecrypter(tag)); |
| 3320 connection_.SetDefaultEncryptionLevel(ENCRYPTION_INITIAL); | 3332 connection_.SetDefaultEncryptionLevel(ENCRYPTION_INITIAL); |
| 3321 connection_.SetEncrypter(ENCRYPTION_INITIAL, new TaggingEncrypter(tag)); | 3333 connection_.SetEncrypter(ENCRYPTION_INITIAL, new TaggingEncrypter(tag)); |
| 3322 EXPECT_CALL(visitor_, OnStreamFrame(_)).Times(2); | 3334 EXPECT_CALL(visitor_, OnStreamFrame(_)).Times(2); |
| 3323 ProcessDataPacketAtLevel(2, 0, kEntropyFlag, ENCRYPTION_INITIAL); | 3335 ProcessDataPacketAtLevel(2, 0, kEntropyFlag, !kHasStopWaiting, |
| 3336 ENCRYPTION_INITIAL); |
| 3324 | 3337 |
| 3325 // Finally, process a third packet and note that we do not reprocess the | 3338 // Finally, process a third packet and note that we do not reprocess the |
| 3326 // buffered packet. | 3339 // buffered packet. |
| 3327 EXPECT_CALL(visitor_, OnStreamFrame(_)).Times(1); | 3340 EXPECT_CALL(visitor_, OnStreamFrame(_)).Times(1); |
| 3328 ProcessDataPacketAtLevel(3, 0, kEntropyFlag, ENCRYPTION_INITIAL); | 3341 ProcessDataPacketAtLevel(3, 0, kEntropyFlag, !kHasStopWaiting, |
| 3342 ENCRYPTION_INITIAL); |
| 3329 } | 3343 } |
| 3330 | 3344 |
| 3331 TEST_P(QuicConnectionTest, ProcessBufferedFECGroup) { | 3345 TEST_P(QuicConnectionTest, ProcessBufferedFECGroup) { |
| 3332 // SetFromConfig is always called after construction from InitializeSession. | 3346 // SetFromConfig is always called after construction from InitializeSession. |
| 3333 EXPECT_CALL(*send_algorithm_, SetFromConfig(_, _)); | 3347 EXPECT_CALL(*send_algorithm_, SetFromConfig(_, _)); |
| 3334 QuicConfig config; | 3348 QuicConfig config; |
| 3335 config.set_max_undecryptable_packets(100); | 3349 config.set_max_undecryptable_packets(100); |
| 3336 connection_.SetFromConfig(config); | 3350 connection_.SetFromConfig(config); |
| 3337 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); | 3351 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); |
| 3338 use_tagging_decrypter(); | 3352 use_tagging_decrypter(); |
| 3339 | 3353 |
| 3340 const uint8_t tag = 0x07; | 3354 const uint8_t tag = 0x07; |
| 3341 framer_.SetEncrypter(ENCRYPTION_INITIAL, new TaggingEncrypter(tag)); | 3355 framer_.SetEncrypter(ENCRYPTION_INITIAL, new TaggingEncrypter(tag)); |
| 3342 | 3356 |
| 3343 // Don't send packet 1 and buffer initially encrypted packets. | 3357 // Don't send packet 1 and buffer initially encrypted packets. |
| 3344 ProcessFecProtectedPacketAtLevel(2, 1, false, !kEntropyFlag, | 3358 ProcessFecProtectedPacketAtLevel(2, 1, false, !kEntropyFlag, !kHasStopWaiting, |
| 3345 ENCRYPTION_INITIAL); | 3359 ENCRYPTION_INITIAL); |
| 3346 ProcessFecPacketAtLevel(3, 1, false, kEntropyFlag, nullptr, | 3360 ProcessFecPacketAtLevel(3, 1, false, kEntropyFlag, nullptr, |
| 3347 ENCRYPTION_INITIAL); | 3361 ENCRYPTION_INITIAL); |
| 3348 // Since the packets were buffered, no FEC group should be open. | 3362 // Since the packets were buffered, no FEC group should be open. |
| 3349 ASSERT_EQ(0u, connection_.NumFecGroups()); | 3363 ASSERT_EQ(0u, connection_.NumFecGroups()); |
| 3350 | 3364 |
| 3351 // Now send non-fec protected ack packet and close the group. | 3365 // Now send non-fec protected ack packet and close the group. |
| 3352 QuicStopWaitingFrame frame = InitStopWaitingFrame(4); | 3366 QuicStopWaitingFrame frame = InitStopWaitingFrame(4); |
| 3353 ProcessStopWaitingPacketAtLevel(4, &frame, ENCRYPTION_INITIAL); | 3367 ProcessStopWaitingPacketAtLevel(4, &frame, ENCRYPTION_INITIAL); |
| 3354 | 3368 |
| 3355 // Transition to the new encryption state and process another encrypted packet | 3369 // Transition to the new encryption state and process another encrypted packet |
| 3356 // which should result in the original packets being processed. The missing | 3370 // which should result in the original packets being processed. The missing |
| 3357 // packet should be revived before the STOP_WAITING packet is processed. | 3371 // packet should be revived before the STOP_WAITING packet is processed. |
| 3358 connection_.SetDecrypter(ENCRYPTION_INITIAL, new StrictTaggingDecrypter(tag)); | 3372 connection_.SetDecrypter(ENCRYPTION_INITIAL, new StrictTaggingDecrypter(tag)); |
| 3359 connection_.SetDefaultEncryptionLevel(ENCRYPTION_INITIAL); | 3373 connection_.SetDefaultEncryptionLevel(ENCRYPTION_INITIAL); |
| 3360 connection_.SetEncrypter(ENCRYPTION_INITIAL, new TaggingEncrypter(tag)); | 3374 connection_.SetEncrypter(ENCRYPTION_INITIAL, new TaggingEncrypter(tag)); |
| 3361 | 3375 |
| 3362 EXPECT_CALL(visitor_, OnStreamFrame(_)).Times(2).RetiresOnSaturation(); | 3376 EXPECT_CALL(visitor_, OnStreamFrame(_)).Times(2).RetiresOnSaturation(); |
| 3363 ProcessDataPacketAtLevel(5, 0, kEntropyFlag, ENCRYPTION_INITIAL); | 3377 ProcessDataPacketAtLevel(5, 0, kEntropyFlag, !kHasStopWaiting, |
| 3378 ENCRYPTION_INITIAL); |
| 3364 const QuicConnectionStats& stats = connection_.GetStats(); | 3379 const QuicConnectionStats& stats = connection_.GetStats(); |
| 3365 EXPECT_EQ(1u, stats.packets_revived); | 3380 EXPECT_EQ(1u, stats.packets_revived); |
| 3366 } | 3381 } |
| 3367 | 3382 |
| 3368 TEST_P(QuicConnectionTest, Buffer100NonDecryptablePackets) { | 3383 TEST_P(QuicConnectionTest, Buffer100NonDecryptablePackets) { |
| 3369 // SetFromConfig is always called after construction from InitializeSession. | 3384 // SetFromConfig is always called after construction from InitializeSession. |
| 3370 EXPECT_CALL(*send_algorithm_, SetFromConfig(_, _)); | 3385 EXPECT_CALL(*send_algorithm_, SetFromConfig(_, _)); |
| 3371 QuicConfig config; | 3386 QuicConfig config; |
| 3372 config.set_max_undecryptable_packets(100); | 3387 config.set_max_undecryptable_packets(100); |
| 3373 connection_.SetFromConfig(config); | 3388 connection_.SetFromConfig(config); |
| 3374 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); | 3389 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); |
| 3375 use_tagging_decrypter(); | 3390 use_tagging_decrypter(); |
| 3376 | 3391 |
| 3377 const uint8_t tag = 0x07; | 3392 const uint8_t tag = 0x07; |
| 3378 framer_.SetEncrypter(ENCRYPTION_INITIAL, new TaggingEncrypter(tag)); | 3393 framer_.SetEncrypter(ENCRYPTION_INITIAL, new TaggingEncrypter(tag)); |
| 3379 | 3394 |
| 3380 // Process an encrypted packet which can not yet be decrypted which should | 3395 // Process an encrypted packet which can not yet be decrypted which should |
| 3381 // result in the packet being buffered. | 3396 // result in the packet being buffered. |
| 3382 for (QuicPacketNumber i = 1; i <= 100; ++i) { | 3397 for (QuicPacketNumber i = 1; i <= 100; ++i) { |
| 3383 ProcessDataPacketAtLevel(i, 0, kEntropyFlag, ENCRYPTION_INITIAL); | 3398 ProcessDataPacketAtLevel(i, 0, kEntropyFlag, !kHasStopWaiting, |
| 3399 ENCRYPTION_INITIAL); |
| 3384 } | 3400 } |
| 3385 | 3401 |
| 3386 // Transition to the new encryption state and process another encrypted packet | 3402 // Transition to the new encryption state and process another encrypted packet |
| 3387 // which should result in the original packets being processed. | 3403 // which should result in the original packets being processed. |
| 3388 connection_.SetDecrypter(ENCRYPTION_INITIAL, new StrictTaggingDecrypter(tag)); | 3404 connection_.SetDecrypter(ENCRYPTION_INITIAL, new StrictTaggingDecrypter(tag)); |
| 3389 connection_.SetDefaultEncryptionLevel(ENCRYPTION_INITIAL); | 3405 connection_.SetDefaultEncryptionLevel(ENCRYPTION_INITIAL); |
| 3390 connection_.SetEncrypter(ENCRYPTION_INITIAL, new TaggingEncrypter(tag)); | 3406 connection_.SetEncrypter(ENCRYPTION_INITIAL, new TaggingEncrypter(tag)); |
| 3391 EXPECT_CALL(visitor_, OnStreamFrame(_)).Times(101); | 3407 EXPECT_CALL(visitor_, OnStreamFrame(_)).Times(101); |
| 3392 ProcessDataPacketAtLevel(101, 0, kEntropyFlag, ENCRYPTION_INITIAL); | 3408 ProcessDataPacketAtLevel(101, 0, kEntropyFlag, !kHasStopWaiting, |
| 3409 ENCRYPTION_INITIAL); |
| 3393 | 3410 |
| 3394 // Finally, process a third packet and note that we do not reprocess the | 3411 // Finally, process a third packet and note that we do not reprocess the |
| 3395 // buffered packet. | 3412 // buffered packet. |
| 3396 EXPECT_CALL(visitor_, OnStreamFrame(_)).Times(1); | 3413 EXPECT_CALL(visitor_, OnStreamFrame(_)).Times(1); |
| 3397 ProcessDataPacketAtLevel(102, 0, kEntropyFlag, ENCRYPTION_INITIAL); | 3414 ProcessDataPacketAtLevel(102, 0, kEntropyFlag, !kHasStopWaiting, |
| 3415 ENCRYPTION_INITIAL); |
| 3398 } | 3416 } |
| 3399 | 3417 |
| 3400 TEST_P(QuicConnectionTest, TestRetransmitOrder) { | 3418 TEST_P(QuicConnectionTest, TestRetransmitOrder) { |
| 3401 QuicByteCount first_packet_size; | 3419 QuicByteCount first_packet_size; |
| 3402 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)) | 3420 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)) |
| 3403 .WillOnce(DoAll(SaveArg<3>(&first_packet_size), Return(true))); | 3421 .WillOnce(DoAll(SaveArg<3>(&first_packet_size), Return(true))); |
| 3404 | 3422 |
| 3405 connection_.SendStreamDataWithString(3, "first_packet", 0, !kFin, nullptr); | 3423 connection_.SendStreamDataWithString(3, "first_packet", 0, !kFin, nullptr); |
| 3406 QuicByteCount second_packet_size; | 3424 QuicByteCount second_packet_size; |
| 3407 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)) | 3425 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)) |
| (...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3486 // Unblock the writes and actually send. | 3504 // Unblock the writes and actually send. |
| 3487 writer_->SetWritable(); | 3505 writer_->SetWritable(); |
| 3488 connection_.OnCanWrite(); | 3506 connection_.OnCanWrite(); |
| 3489 EXPECT_EQ(0u, connection_.NumQueuedPackets()); | 3507 EXPECT_EQ(0u, connection_.NumQueuedPackets()); |
| 3490 } | 3508 } |
| 3491 | 3509 |
| 3492 TEST_P(QuicConnectionTest, CloseFecGroup) { | 3510 TEST_P(QuicConnectionTest, CloseFecGroup) { |
| 3493 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); | 3511 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); |
| 3494 // Don't send missing packet 1. | 3512 // Don't send missing packet 1. |
| 3495 // Don't send missing packet 2. | 3513 // Don't send missing packet 2. |
| 3496 ProcessFecProtectedPacket(3, false, !kEntropyFlag); | 3514 ProcessFecProtectedPacket(3, false, !kEntropyFlag, !kHasStopWaiting); |
| 3497 // Don't send missing FEC packet 3. | 3515 // Don't send missing FEC packet 3. |
| 3498 ASSERT_EQ(1u, connection_.NumFecGroups()); | 3516 ASSERT_EQ(1u, connection_.NumFecGroups()); |
| 3499 | 3517 |
| 3500 // Now send non-fec protected ack packet and close the group. | 3518 // Now send non-fec protected ack packet and close the group. |
| 3501 QuicPacketCreatorPeer::SetPacketNumber(&peer_creator_, 4); | 3519 QuicPacketCreatorPeer::SetPacketNumber(&peer_creator_, 4); |
| 3502 QuicStopWaitingFrame frame = InitStopWaitingFrame(5); | 3520 QuicStopWaitingFrame frame = InitStopWaitingFrame(5); |
| 3503 ProcessStopWaitingPacket(&frame); | 3521 ProcessStopWaitingPacket(&frame); |
| 3504 ASSERT_EQ(0u, connection_.NumFecGroups()); | 3522 ASSERT_EQ(0u, connection_.NumFecGroups()); |
| 3505 } | 3523 } |
| 3506 | 3524 |
| 3525 TEST_P(QuicConnectionTest, FailedToCloseFecGroupWithFecProtectedStopWaiting) { |
| 3526 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); |
| 3527 ValueRestore<bool> old_flag(&FLAGS_quic_drop_non_awaited_packets, false); |
| 3528 // Don't send missing packet 1. |
| 3529 ProcessFecProtectedPacket(2, false, !kEntropyFlag, !kHasStopWaiting); |
| 3530 EXPECT_EQ(1u, connection_.NumFecGroups()); |
| 3531 stop_waiting_ = InitStopWaitingFrame(3); |
| 3532 ProcessFecProtectedPacket(3, false, !kEntropyFlag, kHasStopWaiting); |
| 3533 // This Fec group would be closed but created again. |
| 3534 EXPECT_EQ(1u, connection_.NumFecGroups()); |
| 3535 } |
| 3536 |
| 3537 TEST_P(QuicConnectionTest, |
| 3538 CloseFecGroupUnderStopWaitingAndWaitingForPacketsBelowStopWaiting) { |
| 3539 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); |
| 3540 ValueRestore<bool> old_flag(&FLAGS_quic_drop_non_awaited_packets, true); |
| 3541 // Don't send missing packet 1. |
| 3542 ProcessFecProtectedPacket(2, false, !kEntropyFlag, !kHasStopWaiting); |
| 3543 EXPECT_EQ(1u, connection_.NumFecGroups()); |
| 3544 stop_waiting_ = InitStopWaitingFrame(2); |
| 3545 ProcessFecProtectedPacket(3, false, !kEntropyFlag, kHasStopWaiting); |
| 3546 // This Fec group would be closed. |
| 3547 EXPECT_EQ(0u, connection_.NumFecGroups()); |
| 3548 } |
| 3549 |
| 3550 TEST_P(QuicConnectionTest, |
| 3551 DoNotCloseFecGroupUnderStopWaitingButNotWaitingForPacketsBelow) { |
| 3552 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); |
| 3553 ValueRestore<bool> old_flag(&FLAGS_quic_drop_non_awaited_packets, true); |
| 3554 ProcessFecProtectedPacket(1, false, !kEntropyFlag, !kHasStopWaiting); |
| 3555 ProcessFecProtectedPacket(2, false, !kEntropyFlag, !kHasStopWaiting); |
| 3556 // Don't send missing packet 3. |
| 3557 EXPECT_EQ(1u, connection_.NumFecGroups()); |
| 3558 stop_waiting_ = InitStopWaitingFrame(2); |
| 3559 ProcessFecProtectedPacket(3, false, !kEntropyFlag, kHasStopWaiting); |
| 3560 // This group will not be closed because this group is not waiting for packets |
| 3561 // below stop waiting. |
| 3562 EXPECT_EQ(1u, connection_.NumFecGroups()); |
| 3563 } |
| 3564 |
| 3507 TEST_P(QuicConnectionTest, InitialTimeout) { | 3565 TEST_P(QuicConnectionTest, InitialTimeout) { |
| 3508 EXPECT_TRUE(connection_.connected()); | 3566 EXPECT_TRUE(connection_.connected()); |
| 3509 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(AnyNumber()); | 3567 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(AnyNumber()); |
| 3510 EXPECT_FALSE(connection_.GetTimeoutAlarm()->IsSet()); | 3568 EXPECT_FALSE(connection_.GetTimeoutAlarm()->IsSet()); |
| 3511 | 3569 |
| 3512 // SetFromConfig sets the initial timeouts before negotiation. | 3570 // SetFromConfig sets the initial timeouts before negotiation. |
| 3513 EXPECT_CALL(*send_algorithm_, SetFromConfig(_, _)); | 3571 EXPECT_CALL(*send_algorithm_, SetFromConfig(_, _)); |
| 3514 QuicConfig config; | 3572 QuicConfig config; |
| 3515 connection_.SetFromConfig(config); | 3573 connection_.SetFromConfig(config); |
| 3516 // Subtract a second from the idle timeout on the client side. | 3574 // Subtract a second from the idle timeout on the client side. |
| (...skipping 644 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4161 nullptr); | 4219 nullptr); |
| 4162 connection_.GetTimeoutAlarm()->Fire(); | 4220 connection_.GetTimeoutAlarm()->Fire(); |
| 4163 clock_.AdvanceTime(QuicTime::Delta::FromSeconds(1)); | 4221 clock_.AdvanceTime(QuicTime::Delta::FromSeconds(1)); |
| 4164 } | 4222 } |
| 4165 EXPECT_FALSE(connection_.connected()); | 4223 EXPECT_FALSE(connection_.connected()); |
| 4166 EXPECT_FALSE(connection_.GetTimeoutAlarm()->IsSet()); | 4224 EXPECT_FALSE(connection_.GetTimeoutAlarm()->IsSet()); |
| 4167 } | 4225 } |
| 4168 | 4226 |
| 4169 TEST_P(QuicConnectionTest, SendScheduler) { | 4227 TEST_P(QuicConnectionTest, SendScheduler) { |
| 4170 // Test that if we send a packet without delay, it is not queued. | 4228 // Test that if we send a packet without delay, it is not queued. |
| 4171 QuicPacket* packet = ConstructDataPacket(1, 0, !kEntropyFlag); | 4229 QuicPacket* packet = |
| 4230 ConstructDataPacket(1, 0, !kEntropyFlag, !kHasStopWaiting); |
| 4172 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)); | 4231 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)); |
| 4173 connection_.SendPacket(ENCRYPTION_NONE, 1, packet, kTestEntropyHash, | 4232 connection_.SendPacket(ENCRYPTION_NONE, 1, packet, kTestEntropyHash, |
| 4174 HAS_RETRANSMITTABLE_DATA, false, false); | 4233 HAS_RETRANSMITTABLE_DATA, false, false); |
| 4175 EXPECT_EQ(0u, connection_.NumQueuedPackets()); | 4234 EXPECT_EQ(0u, connection_.NumQueuedPackets()); |
| 4176 } | 4235 } |
| 4177 | 4236 |
| 4178 TEST_P(QuicConnectionTest, FailToSendFirstPacket) { | 4237 TEST_P(QuicConnectionTest, FailToSendFirstPacket) { |
| 4179 // Test that the connection does not crash when it fails to send the first | 4238 // Test that the connection does not crash when it fails to send the first |
| 4180 // packet at which point self_address_ might be uninitialized. | 4239 // packet at which point self_address_ might be uninitialized. |
| 4181 EXPECT_CALL(visitor_, OnConnectionClosed(_, _)).Times(1); | 4240 EXPECT_CALL(visitor_, OnConnectionClosed(_, _)).Times(1); |
| 4182 QuicPacket* packet = ConstructDataPacket(1, 0, !kEntropyFlag); | 4241 QuicPacket* packet = |
| 4242 ConstructDataPacket(1, 0, !kEntropyFlag, !kHasStopWaiting); |
| 4183 writer_->SetShouldWriteFail(); | 4243 writer_->SetShouldWriteFail(); |
| 4184 connection_.SendPacket(ENCRYPTION_NONE, 1, packet, kTestEntropyHash, | 4244 connection_.SendPacket(ENCRYPTION_NONE, 1, packet, kTestEntropyHash, |
| 4185 HAS_RETRANSMITTABLE_DATA, false, false); | 4245 HAS_RETRANSMITTABLE_DATA, false, false); |
| 4186 } | 4246 } |
| 4187 | 4247 |
| 4188 TEST_P(QuicConnectionTest, SendSchedulerEAGAIN) { | 4248 TEST_P(QuicConnectionTest, SendSchedulerEAGAIN) { |
| 4189 QuicPacket* packet = ConstructDataPacket(1, 0, !kEntropyFlag); | 4249 QuicPacket* packet = |
| 4250 ConstructDataPacket(1, 0, !kEntropyFlag, !kHasStopWaiting); |
| 4190 BlockOnNextWrite(); | 4251 BlockOnNextWrite(); |
| 4191 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, 1, _, _)).Times(0); | 4252 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, 1, _, _)).Times(0); |
| 4192 connection_.SendPacket(ENCRYPTION_NONE, 1, packet, kTestEntropyHash, | 4253 connection_.SendPacket(ENCRYPTION_NONE, 1, packet, kTestEntropyHash, |
| 4193 HAS_RETRANSMITTABLE_DATA, false, false); | 4254 HAS_RETRANSMITTABLE_DATA, false, false); |
| 4194 EXPECT_EQ(1u, connection_.NumQueuedPackets()); | 4255 EXPECT_EQ(1u, connection_.NumQueuedPackets()); |
| 4195 } | 4256 } |
| 4196 | 4257 |
| 4197 TEST_P(QuicConnectionTest, TestQueueLimitsOnSendStreamData) { | 4258 TEST_P(QuicConnectionTest, TestQueueLimitsOnSendStreamData) { |
| 4198 // All packets carry version info till version is negotiated. | 4259 // All packets carry version info till version is negotiated. |
| 4199 size_t payload_length; | 4260 size_t payload_length; |
| (...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4290 EXPECT_FALSE(connection_.GetAckAlarm()->IsSet()); | 4351 EXPECT_FALSE(connection_.GetAckAlarm()->IsSet()); |
| 4291 const uint8_t tag = 0x07; | 4352 const uint8_t tag = 0x07; |
| 4292 connection_.SetDecrypter(ENCRYPTION_INITIAL, new StrictTaggingDecrypter(tag)); | 4353 connection_.SetDecrypter(ENCRYPTION_INITIAL, new StrictTaggingDecrypter(tag)); |
| 4293 framer_.SetEncrypter(ENCRYPTION_INITIAL, new TaggingEncrypter(tag)); | 4354 framer_.SetEncrypter(ENCRYPTION_INITIAL, new TaggingEncrypter(tag)); |
| 4294 // Process a packet from the non-crypto stream. | 4355 // Process a packet from the non-crypto stream. |
| 4295 frame1_.stream_id = 3; | 4356 frame1_.stream_id = 3; |
| 4296 | 4357 |
| 4297 // The same as ProcessPacket(1) except that ENCRYPTION_INITIAL is used | 4358 // The same as ProcessPacket(1) except that ENCRYPTION_INITIAL is used |
| 4298 // instead of ENCRYPTION_NONE. | 4359 // instead of ENCRYPTION_NONE. |
| 4299 EXPECT_CALL(visitor_, OnStreamFrame(_)).Times(1); | 4360 EXPECT_CALL(visitor_, OnStreamFrame(_)).Times(1); |
| 4300 ProcessDataPacketAtLevel(1, 0, !kEntropyFlag, ENCRYPTION_INITIAL); | 4361 ProcessDataPacketAtLevel(1, 0, !kEntropyFlag, !kHasStopWaiting, |
| 4362 ENCRYPTION_INITIAL); |
| 4301 | 4363 |
| 4302 // Check if delayed ack timer is running for the expected interval. | 4364 // Check if delayed ack timer is running for the expected interval. |
| 4303 EXPECT_TRUE(connection_.GetAckAlarm()->IsSet()); | 4365 EXPECT_TRUE(connection_.GetAckAlarm()->IsSet()); |
| 4304 EXPECT_EQ(ack_time, connection_.GetAckAlarm()->deadline()); | 4366 EXPECT_EQ(ack_time, connection_.GetAckAlarm()->deadline()); |
| 4305 // Simulate delayed ack alarm firing. | 4367 // Simulate delayed ack alarm firing. |
| 4306 connection_.GetAckAlarm()->Fire(); | 4368 connection_.GetAckAlarm()->Fire(); |
| 4307 // Check that ack is sent and that delayed ack alarm is reset. | 4369 // Check that ack is sent and that delayed ack alarm is reset. |
| 4308 EXPECT_EQ(2u, writer_->frame_count()); | 4370 EXPECT_EQ(2u, writer_->frame_count()); |
| 4309 EXPECT_FALSE(writer_->stop_waiting_frames().empty()); | 4371 EXPECT_FALSE(writer_->stop_waiting_frames().empty()); |
| 4310 EXPECT_FALSE(writer_->ack_frames().empty()); | 4372 EXPECT_FALSE(writer_->ack_frames().empty()); |
| (...skipping 16 matching lines...) Expand all Loading... |
| 4327 const uint8_t tag = 0x07; | 4389 const uint8_t tag = 0x07; |
| 4328 connection_.SetDecrypter(ENCRYPTION_INITIAL, new StrictTaggingDecrypter(tag)); | 4390 connection_.SetDecrypter(ENCRYPTION_INITIAL, new StrictTaggingDecrypter(tag)); |
| 4329 framer_.SetEncrypter(ENCRYPTION_INITIAL, new TaggingEncrypter(tag)); | 4391 framer_.SetEncrypter(ENCRYPTION_INITIAL, new TaggingEncrypter(tag)); |
| 4330 // Process a packet from the non-crypto stream. | 4392 // Process a packet from the non-crypto stream. |
| 4331 frame1_.stream_id = 3; | 4393 frame1_.stream_id = 3; |
| 4332 | 4394 |
| 4333 // Process all the initial packets in order so there aren't missing packets. | 4395 // Process all the initial packets in order so there aren't missing packets. |
| 4334 QuicPacketNumber kFirstDecimatedPacket = 101; | 4396 QuicPacketNumber kFirstDecimatedPacket = 101; |
| 4335 for (unsigned int i = 0; i < kFirstDecimatedPacket - 1; ++i) { | 4397 for (unsigned int i = 0; i < kFirstDecimatedPacket - 1; ++i) { |
| 4336 EXPECT_CALL(visitor_, OnStreamFrame(_)).Times(1); | 4398 EXPECT_CALL(visitor_, OnStreamFrame(_)).Times(1); |
| 4337 ProcessDataPacketAtLevel(1 + i, 0, !kEntropyFlag, ENCRYPTION_INITIAL); | 4399 ProcessDataPacketAtLevel(1 + i, 0, !kEntropyFlag, !kHasStopWaiting, |
| 4400 ENCRYPTION_INITIAL); |
| 4338 } | 4401 } |
| 4339 EXPECT_FALSE(connection_.GetAckAlarm()->IsSet()); | 4402 EXPECT_FALSE(connection_.GetAckAlarm()->IsSet()); |
| 4340 // The same as ProcessPacket(1) except that ENCRYPTION_INITIAL is used | 4403 // The same as ProcessPacket(1) except that ENCRYPTION_INITIAL is used |
| 4341 // instead of ENCRYPTION_NONE. | 4404 // instead of ENCRYPTION_NONE. |
| 4342 EXPECT_CALL(visitor_, OnStreamFrame(_)).Times(1); | 4405 EXPECT_CALL(visitor_, OnStreamFrame(_)).Times(1); |
| 4343 ProcessDataPacketAtLevel(kFirstDecimatedPacket, 0, !kEntropyFlag, | 4406 ProcessDataPacketAtLevel(kFirstDecimatedPacket, 0, !kEntropyFlag, |
| 4344 ENCRYPTION_INITIAL); | 4407 !kHasStopWaiting, ENCRYPTION_INITIAL); |
| 4345 | 4408 |
| 4346 // Check if delayed ack timer is running for the expected interval. | 4409 // Check if delayed ack timer is running for the expected interval. |
| 4347 EXPECT_TRUE(connection_.GetAckAlarm()->IsSet()); | 4410 EXPECT_TRUE(connection_.GetAckAlarm()->IsSet()); |
| 4348 EXPECT_EQ(ack_time, connection_.GetAckAlarm()->deadline()); | 4411 EXPECT_EQ(ack_time, connection_.GetAckAlarm()->deadline()); |
| 4349 | 4412 |
| 4350 // The 10th received packet causes an ack to be sent. | 4413 // The 10th received packet causes an ack to be sent. |
| 4351 for (int i = 0; i < 9; ++i) { | 4414 for (int i = 0; i < 9; ++i) { |
| 4352 EXPECT_TRUE(connection_.GetAckAlarm()->IsSet()); | 4415 EXPECT_TRUE(connection_.GetAckAlarm()->IsSet()); |
| 4353 EXPECT_CALL(visitor_, OnStreamFrame(_)).Times(1); | 4416 EXPECT_CALL(visitor_, OnStreamFrame(_)).Times(1); |
| 4354 ProcessDataPacketAtLevel(kFirstDecimatedPacket + 1 + i, 0, !kEntropyFlag, | 4417 ProcessDataPacketAtLevel(kFirstDecimatedPacket + 1 + i, 0, !kEntropyFlag, |
| 4355 ENCRYPTION_INITIAL); | 4418 !kHasStopWaiting, ENCRYPTION_INITIAL); |
| 4356 } | 4419 } |
| 4357 // Check that ack is sent and that delayed ack alarm is reset. | 4420 // Check that ack is sent and that delayed ack alarm is reset. |
| 4358 EXPECT_EQ(2u, writer_->frame_count()); | 4421 EXPECT_EQ(2u, writer_->frame_count()); |
| 4359 EXPECT_FALSE(writer_->stop_waiting_frames().empty()); | 4422 EXPECT_FALSE(writer_->stop_waiting_frames().empty()); |
| 4360 EXPECT_FALSE(writer_->ack_frames().empty()); | 4423 EXPECT_FALSE(writer_->ack_frames().empty()); |
| 4361 EXPECT_FALSE(connection_.GetAckAlarm()->IsSet()); | 4424 EXPECT_FALSE(connection_.GetAckAlarm()->IsSet()); |
| 4362 } | 4425 } |
| 4363 | 4426 |
| 4364 TEST_P(QuicConnectionTest, SendDelayedAckOnHandshakeConfirmed) { | 4427 TEST_P(QuicConnectionTest, SendDelayedAckOnHandshakeConfirmed) { |
| 4365 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); | 4428 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); |
| (...skipping 184 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4550 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(0); | 4613 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(0); |
| 4551 ProcessClosePacket(2, 0); | 4614 ProcessClosePacket(2, 0); |
| 4552 } | 4615 } |
| 4553 | 4616 |
| 4554 TEST_P(QuicConnectionTest, SendWhenDisconnected) { | 4617 TEST_P(QuicConnectionTest, SendWhenDisconnected) { |
| 4555 EXPECT_TRUE(connection_.connected()); | 4618 EXPECT_TRUE(connection_.connected()); |
| 4556 EXPECT_CALL(visitor_, OnConnectionClosed(QUIC_PEER_GOING_AWAY, false)); | 4619 EXPECT_CALL(visitor_, OnConnectionClosed(QUIC_PEER_GOING_AWAY, false)); |
| 4557 connection_.CloseConnection(QUIC_PEER_GOING_AWAY, false); | 4620 connection_.CloseConnection(QUIC_PEER_GOING_AWAY, false); |
| 4558 EXPECT_FALSE(connection_.connected()); | 4621 EXPECT_FALSE(connection_.connected()); |
| 4559 EXPECT_FALSE(connection_.CanWriteStreamData()); | 4622 EXPECT_FALSE(connection_.CanWriteStreamData()); |
| 4560 QuicPacket* packet = ConstructDataPacket(1, 0, !kEntropyFlag); | 4623 QuicPacket* packet = |
| 4624 ConstructDataPacket(1, 0, !kEntropyFlag, !kHasStopWaiting); |
| 4561 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, 1, _, _)).Times(0); | 4625 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, 1, _, _)).Times(0); |
| 4562 connection_.SendPacket(ENCRYPTION_NONE, 1, packet, kTestEntropyHash, | 4626 connection_.SendPacket(ENCRYPTION_NONE, 1, packet, kTestEntropyHash, |
| 4563 HAS_RETRANSMITTABLE_DATA, false, false); | 4627 HAS_RETRANSMITTABLE_DATA, false, false); |
| 4564 } | 4628 } |
| 4565 | 4629 |
| 4566 TEST_P(QuicConnectionTest, PublicReset) { | 4630 TEST_P(QuicConnectionTest, PublicReset) { |
| 4567 QuicPublicResetPacket header; | 4631 QuicPublicResetPacket header; |
| 4568 header.public_header.connection_id = connection_id_; | 4632 header.public_header.connection_id = connection_id_; |
| 4569 header.public_header.reset_flag = true; | 4633 header.public_header.reset_flag = true; |
| 4570 header.public_header.version_flag = false; | 4634 header.public_header.version_flag = false; |
| (...skipping 336 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4907 stats.bytes_retransmitted); | 4971 stats.bytes_retransmitted); |
| 4908 EXPECT_EQ(3u, stats.packets_retransmitted); | 4972 EXPECT_EQ(3u, stats.packets_retransmitted); |
| 4909 EXPECT_EQ(1u, stats.rto_count); | 4973 EXPECT_EQ(1u, stats.rto_count); |
| 4910 EXPECT_EQ(kDefaultMaxPacketSize, stats.max_packet_size); | 4974 EXPECT_EQ(kDefaultMaxPacketSize, stats.max_packet_size); |
| 4911 } | 4975 } |
| 4912 | 4976 |
| 4913 TEST_P(QuicConnectionTest, CheckReceiveStats) { | 4977 TEST_P(QuicConnectionTest, CheckReceiveStats) { |
| 4914 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); | 4978 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); |
| 4915 | 4979 |
| 4916 size_t received_bytes = 0; | 4980 size_t received_bytes = 0; |
| 4917 received_bytes += ProcessFecProtectedPacket(1, false, !kEntropyFlag); | 4981 received_bytes += |
| 4918 received_bytes += ProcessFecProtectedPacket(3, false, !kEntropyFlag); | 4982 ProcessFecProtectedPacket(1, false, !kEntropyFlag, !kHasStopWaiting); |
| 4983 received_bytes += |
| 4984 ProcessFecProtectedPacket(3, false, !kEntropyFlag, !kHasStopWaiting); |
| 4919 // Should be counted against dropped packets. | 4985 // Should be counted against dropped packets. |
| 4920 received_bytes += ProcessDataPacket(3, 1, !kEntropyFlag); | 4986 received_bytes += ProcessDataPacket(3, 1, !kEntropyFlag); |
| 4921 received_bytes += ProcessFecPacket(4, 1, true, !kEntropyFlag, nullptr); | 4987 received_bytes += ProcessFecPacket(4, 1, true, !kEntropyFlag, nullptr); |
| 4922 | 4988 |
| 4923 EXPECT_CALL(*send_algorithm_, BandwidthEstimate()) | 4989 EXPECT_CALL(*send_algorithm_, BandwidthEstimate()) |
| 4924 .WillOnce(Return(QuicBandwidth::Zero())); | 4990 .WillOnce(Return(QuicBandwidth::Zero())); |
| 4925 | 4991 |
| 4926 const QuicConnectionStats& stats = connection_.GetStats(); | 4992 const QuicConnectionStats& stats = connection_.GetStats(); |
| 4927 EXPECT_EQ(received_bytes, stats.bytes_received); | 4993 EXPECT_EQ(received_bytes, stats.bytes_received); |
| 4928 EXPECT_EQ(4u, stats.packets_received); | 4994 EXPECT_EQ(4u, stats.packets_received); |
| (...skipping 410 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5339 QuicPacketCreatorPeer::GetFecTimeout(creator_)); | 5405 QuicPacketCreatorPeer::GetFecTimeout(creator_)); |
| 5340 } | 5406 } |
| 5341 | 5407 |
| 5342 TEST_P(QuicConnectionTest, OnPacketHeaderDebugVisitor) { | 5408 TEST_P(QuicConnectionTest, OnPacketHeaderDebugVisitor) { |
| 5343 QuicPacketHeader header; | 5409 QuicPacketHeader header; |
| 5344 | 5410 |
| 5345 scoped_ptr<MockQuicConnectionDebugVisitor> debug_visitor( | 5411 scoped_ptr<MockQuicConnectionDebugVisitor> debug_visitor( |
| 5346 new MockQuicConnectionDebugVisitor()); | 5412 new MockQuicConnectionDebugVisitor()); |
| 5347 connection_.set_debug_visitor(debug_visitor.get()); | 5413 connection_.set_debug_visitor(debug_visitor.get()); |
| 5348 EXPECT_CALL(*debug_visitor, OnPacketHeader(Ref(header))).Times(1); | 5414 EXPECT_CALL(*debug_visitor, OnPacketHeader(Ref(header))).Times(1); |
| 5349 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)).Times(1); | 5415 if (FLAGS_quic_drop_non_awaited_packets) { |
| 5350 EXPECT_CALL(*debug_visitor, OnSuccessfulVersionNegotiation(_)).Times(1); | 5416 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)).Times(1); |
| 5417 EXPECT_CALL(*debug_visitor, OnSuccessfulVersionNegotiation(_)).Times(1); |
| 5418 } |
| 5351 connection_.OnPacketHeader(header); | 5419 connection_.OnPacketHeader(header); |
| 5352 } | 5420 } |
| 5353 | 5421 |
| 5354 TEST_P(QuicConnectionTest, Pacing) { | 5422 TEST_P(QuicConnectionTest, Pacing) { |
| 5355 TestConnection server(connection_id_, kSelfAddress, helper_.get(), factory_, | 5423 TestConnection server(connection_id_, kSelfAddress, helper_.get(), factory_, |
| 5356 Perspective::IS_SERVER, version()); | 5424 Perspective::IS_SERVER, version()); |
| 5357 TestConnection client(connection_id_, kPeerAddress, helper_.get(), factory_, | 5425 TestConnection client(connection_id_, kPeerAddress, helper_.get(), factory_, |
| 5358 Perspective::IS_CLIENT, version()); | 5426 Perspective::IS_CLIENT, version()); |
| 5359 EXPECT_FALSE(client.sent_packet_manager().using_pacing()); | 5427 EXPECT_FALSE(client.sent_packet_manager().using_pacing()); |
| 5360 EXPECT_FALSE(server.sent_packet_manager().using_pacing()); | 5428 EXPECT_FALSE(server.sent_packet_manager().using_pacing()); |
| (...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5490 EXPECT_CALL(visitor_, | 5558 EXPECT_CALL(visitor_, |
| 5491 OnConnectionClosed(QUIC_UNENCRYPTED_STREAM_DATA, false)); | 5559 OnConnectionClosed(QUIC_UNENCRYPTED_STREAM_DATA, false)); |
| 5492 EXPECT_DFATAL(connection_.SendStreamDataWithString(3, "", 0, kFin, nullptr), | 5560 EXPECT_DFATAL(connection_.SendStreamDataWithString(3, "", 0, kFin, nullptr), |
| 5493 "Cannot send stream data without encryption."); | 5561 "Cannot send stream data without encryption."); |
| 5494 EXPECT_FALSE(connection_.connected()); | 5562 EXPECT_FALSE(connection_.connected()); |
| 5495 } | 5563 } |
| 5496 | 5564 |
| 5497 } // namespace | 5565 } // namespace |
| 5498 } // namespace test | 5566 } // namespace test |
| 5499 } // namespace net | 5567 } // namespace net |
| OLD | NEW |