| 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/basictypes.h" | 9 #include "base/basictypes.h" |
| 10 #include "base/bind.h" | 10 #include "base/bind.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 730 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 804 framer_.EncryptPayload(level, number, *packet, buffer, kMaxPacketSize); | 805 framer_.EncryptPayload(level, number, *packet, buffer, kMaxPacketSize); |
| 805 connection_.ProcessUdpPacket( | 806 connection_.ProcessUdpPacket( |
| 806 kSelfAddress, kPeerAddress, | 807 kSelfAddress, kPeerAddress, |
| 807 QuicEncryptedPacket(buffer, encrypted_length, false)); | 808 QuicEncryptedPacket(buffer, encrypted_length, false)); |
| 808 return base::checked_cast<QuicPacketEntropyHash>(encrypted_length); | 809 return base::checked_cast<QuicPacketEntropyHash>(encrypted_length); |
| 809 } | 810 } |
| 810 | 811 |
| 811 size_t ProcessDataPacket(QuicPacketNumber number, | 812 size_t ProcessDataPacket(QuicPacketNumber number, |
| 812 QuicFecGroupNumber fec_group, | 813 QuicFecGroupNumber fec_group, |
| 813 bool entropy_flag) { | 814 bool entropy_flag) { |
| 814 return ProcessDataPacketAtLevel(number, fec_group, entropy_flag, | 815 return ProcessDataPacketAtLevel(number, fec_group, entropy_flag, false, |
| 815 ENCRYPTION_NONE); | 816 ENCRYPTION_NONE); |
| 816 } | 817 } |
| 817 | 818 |
| 818 size_t ProcessDataPacketAtLevel(QuicPacketNumber number, | 819 size_t ProcessDataPacketAtLevel(QuicPacketNumber number, |
| 819 QuicFecGroupNumber fec_group, | 820 QuicFecGroupNumber fec_group, |
| 820 bool entropy_flag, | 821 bool entropy_flag, |
| 822 bool has_stop_waiting, |
| 821 EncryptionLevel level) { | 823 EncryptionLevel level) { |
| 822 scoped_ptr<QuicPacket> packet(ConstructDataPacket(number, fec_group, | 824 scoped_ptr<QuicPacket> packet( |
| 823 entropy_flag)); | 825 ConstructDataPacket(number, fec_group, entropy_flag, has_stop_waiting)); |
| 824 char buffer[kMaxPacketSize]; | 826 char buffer[kMaxPacketSize]; |
| 825 size_t encrypted_length = | 827 size_t encrypted_length = |
| 826 framer_.EncryptPayload(level, number, *packet, buffer, kMaxPacketSize); | 828 framer_.EncryptPayload(level, number, *packet, buffer, kMaxPacketSize); |
| 827 connection_.ProcessUdpPacket( | 829 connection_.ProcessUdpPacket( |
| 828 kSelfAddress, kPeerAddress, | 830 kSelfAddress, kPeerAddress, |
| 829 QuicEncryptedPacket(buffer, encrypted_length, false)); | 831 QuicEncryptedPacket(buffer, encrypted_length, false)); |
| 830 return encrypted_length; | 832 return encrypted_length; |
| 831 } | 833 } |
| 832 | 834 |
| 833 void ProcessClosePacket(QuicPacketNumber number, | 835 void ProcessClosePacket(QuicPacketNumber number, |
| 834 QuicFecGroupNumber fec_group) { | 836 QuicFecGroupNumber fec_group) { |
| 835 scoped_ptr<QuicPacket> packet(ConstructClosePacket(number, fec_group)); | 837 scoped_ptr<QuicPacket> packet(ConstructClosePacket(number, fec_group)); |
| 836 char buffer[kMaxPacketSize]; | 838 char buffer[kMaxPacketSize]; |
| 837 size_t encrypted_length = framer_.EncryptPayload( | 839 size_t encrypted_length = framer_.EncryptPayload( |
| 838 ENCRYPTION_NONE, number, *packet, buffer, kMaxPacketSize); | 840 ENCRYPTION_NONE, number, *packet, buffer, kMaxPacketSize); |
| 839 connection_.ProcessUdpPacket( | 841 connection_.ProcessUdpPacket( |
| 840 kSelfAddress, kPeerAddress, | 842 kSelfAddress, kPeerAddress, |
| 841 QuicEncryptedPacket(buffer, encrypted_length, false)); | 843 QuicEncryptedPacket(buffer, encrypted_length, false)); |
| 842 } | 844 } |
| 843 | 845 |
| 844 size_t ProcessFecProtectedPacket(QuicPacketNumber number, | 846 size_t ProcessFecProtectedPacket(QuicPacketNumber number, |
| 845 bool expect_revival, | 847 bool expect_revival, |
| 846 bool entropy_flag) { | 848 bool entropy_flag, |
| 849 bool has_stop_waiting) { |
| 847 return ProcessFecProtectedPacketAtLevel(number, 1, expect_revival, | 850 return ProcessFecProtectedPacketAtLevel(number, 1, expect_revival, |
| 848 entropy_flag, ENCRYPTION_NONE); | 851 entropy_flag, has_stop_waiting, |
| 852 ENCRYPTION_NONE); |
| 849 } | 853 } |
| 850 | 854 |
| 851 size_t ProcessFecProtectedPacketAtLevel(QuicPacketNumber number, | 855 size_t ProcessFecProtectedPacketAtLevel(QuicPacketNumber number, |
| 852 QuicFecGroupNumber fec_group, | 856 QuicFecGroupNumber fec_group, |
| 853 bool expect_revival, | 857 bool expect_revival, |
| 854 bool entropy_flag, | 858 bool entropy_flag, |
| 859 bool has_stop_waiting, |
| 855 EncryptionLevel level) { | 860 EncryptionLevel level) { |
| 856 if (expect_revival) { | 861 if (expect_revival) { |
| 857 EXPECT_CALL(visitor_, OnStreamFrame(_)).Times(1); | 862 EXPECT_CALL(visitor_, OnStreamFrame(_)).Times(1); |
| 858 } | 863 } |
| 859 EXPECT_CALL(visitor_, OnStreamFrame(_)).Times(1).RetiresOnSaturation(); | 864 EXPECT_CALL(visitor_, OnStreamFrame(_)).Times(1).RetiresOnSaturation(); |
| 860 return ProcessDataPacketAtLevel(number, fec_group, entropy_flag, level); | 865 return ProcessDataPacketAtLevel(number, fec_group, entropy_flag, |
| 866 has_stop_waiting, level); |
| 861 } | 867 } |
| 862 | 868 |
| 863 // Processes an FEC packet that covers the packets that would have been | 869 // Processes an FEC packet that covers the packets that would have been |
| 864 // received. | 870 // received. |
| 865 size_t ProcessFecPacket(QuicPacketNumber number, | 871 size_t ProcessFecPacket(QuicPacketNumber number, |
| 866 QuicPacketNumber min_protected_packet, | 872 QuicPacketNumber min_protected_packet, |
| 867 bool expect_revival, | 873 bool expect_revival, |
| 868 bool entropy_flag, | 874 bool entropy_flag, |
| 869 QuicPacket* packet) { | 875 QuicPacket* packet) { |
| 870 return ProcessFecPacketAtLevel(number, min_protected_packet, expect_revival, | 876 return ProcessFecPacketAtLevel(number, min_protected_packet, expect_revival, |
| (...skipping 12 matching lines...) Expand all Loading... |
| 883 EXPECT_CALL(visitor_, OnStreamFrame(_)).Times(1); | 889 EXPECT_CALL(visitor_, OnStreamFrame(_)).Times(1); |
| 884 } | 890 } |
| 885 | 891 |
| 886 // Construct the decrypted data packet so we can compute the correct | 892 // Construct the decrypted data packet so we can compute the correct |
| 887 // redundancy. If |packet| has been provided then use that, otherwise | 893 // redundancy. If |packet| has been provided then use that, otherwise |
| 888 // construct a default data packet. | 894 // construct a default data packet. |
| 889 scoped_ptr<QuicPacket> data_packet; | 895 scoped_ptr<QuicPacket> data_packet; |
| 890 if (packet) { | 896 if (packet) { |
| 891 data_packet.reset(packet); | 897 data_packet.reset(packet); |
| 892 } else { | 898 } else { |
| 893 data_packet.reset(ConstructDataPacket(number, 1, !kEntropyFlag)); | 899 data_packet.reset( |
| 900 ConstructDataPacket(number, 1, !kEntropyFlag, !kHasStopWaiting)); |
| 894 } | 901 } |
| 895 | 902 |
| 896 QuicPacketHeader header; | 903 QuicPacketHeader header; |
| 897 header.public_header.connection_id = connection_id_; | 904 header.public_header.connection_id = connection_id_; |
| 898 header.public_header.packet_number_length = packet_number_length_; | 905 header.public_header.packet_number_length = packet_number_length_; |
| 899 header.public_header.connection_id_length = connection_id_length_; | 906 header.public_header.connection_id_length = connection_id_length_; |
| 900 header.packet_number = number; | 907 header.packet_number = number; |
| 901 header.entropy_flag = entropy_flag; | 908 header.entropy_flag = entropy_flag; |
| 902 header.fec_flag = true; | 909 header.fec_flag = true; |
| 903 header.is_in_fec_group = IN_FEC_GROUP; | 910 header.is_in_fec_group = IN_FEC_GROUP; |
| (...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 982 } | 989 } |
| 983 | 990 |
| 984 QuicPacket* ConstructPacket(QuicPacketHeader header, QuicFrames frames) { | 991 QuicPacket* ConstructPacket(QuicPacketHeader header, QuicFrames frames) { |
| 985 QuicPacket* packet = BuildUnsizedDataPacket(&framer_, header, frames); | 992 QuicPacket* packet = BuildUnsizedDataPacket(&framer_, header, frames); |
| 986 EXPECT_NE(nullptr, packet); | 993 EXPECT_NE(nullptr, packet); |
| 987 return packet; | 994 return packet; |
| 988 } | 995 } |
| 989 | 996 |
| 990 QuicPacket* ConstructDataPacket(QuicPacketNumber number, | 997 QuicPacket* ConstructDataPacket(QuicPacketNumber number, |
| 991 QuicFecGroupNumber fec_group, | 998 QuicFecGroupNumber fec_group, |
| 992 bool entropy_flag) { | 999 bool entropy_flag, |
| 1000 bool has_stop_waiting) { |
| 993 QuicPacketHeader header; | 1001 QuicPacketHeader header; |
| 994 header.public_header.connection_id = connection_id_; | 1002 header.public_header.connection_id = connection_id_; |
| 995 header.public_header.packet_number_length = packet_number_length_; | 1003 header.public_header.packet_number_length = packet_number_length_; |
| 996 header.public_header.connection_id_length = connection_id_length_; | 1004 header.public_header.connection_id_length = connection_id_length_; |
| 997 header.entropy_flag = entropy_flag; | 1005 header.entropy_flag = entropy_flag; |
| 998 header.packet_number = number; | 1006 header.packet_number = number; |
| 999 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; |
| 1000 header.fec_group = fec_group; | 1008 header.fec_group = fec_group; |
| 1001 | 1009 |
| 1002 QuicFrames frames; | 1010 QuicFrames frames; |
| 1003 frames.push_back(QuicFrame(&frame1_)); | 1011 frames.push_back(QuicFrame(&frame1_)); |
| 1012 if (has_stop_waiting) { |
| 1013 frames.push_back(QuicFrame(&stop_waiting_)); |
| 1014 } |
| 1004 return ConstructPacket(header, frames); | 1015 return ConstructPacket(header, frames); |
| 1005 } | 1016 } |
| 1006 | 1017 |
| 1007 QuicPacket* ConstructClosePacket(QuicPacketNumber number, | 1018 QuicPacket* ConstructClosePacket(QuicPacketNumber number, |
| 1008 QuicFecGroupNumber fec_group) { | 1019 QuicFecGroupNumber fec_group) { |
| 1009 QuicPacketHeader header; | 1020 QuicPacketHeader header; |
| 1010 header.public_header.connection_id = connection_id_; | 1021 header.public_header.connection_id = connection_id_; |
| 1011 header.packet_number = number; | 1022 header.packet_number = number; |
| 1012 header.is_in_fec_group = fec_group == 0u ? NOT_IN_FEC_GROUP : IN_FEC_GROUP; | 1023 header.is_in_fec_group = fec_group == 0u ? NOT_IN_FEC_GROUP : IN_FEC_GROUP; |
| 1013 header.fec_group = fec_group; | 1024 header.fec_group = fec_group; |
| (...skipping 2043 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3057 // Connection id length in the revived header should be the same as | 3068 // Connection id length in the revived header should be the same as |
| 3058 // in the original data/fec packet headers. | 3069 // in the original data/fec packet headers. |
| 3059 EXPECT_EQ(connection_id_length_, | 3070 EXPECT_EQ(connection_id_length_, |
| 3060 fec_visitor->revived_header().public_header.connection_id_length); | 3071 fec_visitor->revived_header().public_header.connection_id_length); |
| 3061 } | 3072 } |
| 3062 } | 3073 } |
| 3063 | 3074 |
| 3064 TEST_P(QuicConnectionTest, ReviveMissingPacketAfterDataPacketThenFecPacket) { | 3075 TEST_P(QuicConnectionTest, ReviveMissingPacketAfterDataPacketThenFecPacket) { |
| 3065 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); | 3076 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); |
| 3066 | 3077 |
| 3067 ProcessFecProtectedPacket(1, false, kEntropyFlag); | 3078 ProcessFecProtectedPacket(1, false, kEntropyFlag, !kHasStopWaiting); |
| 3068 // Don't send missing packet 2. | 3079 // Don't send missing packet 2. |
| 3069 ProcessFecPacket(3, 1, true, !kEntropyFlag, nullptr); | 3080 ProcessFecPacket(3, 1, true, !kEntropyFlag, nullptr); |
| 3070 // Entropy flag should be true, so entropy should not be 0. | 3081 // Entropy flag should be true, so entropy should not be 0. |
| 3071 EXPECT_NE(0u, QuicConnectionPeer::ReceivedEntropyHash(&connection_, 2)); | 3082 EXPECT_NE(0u, QuicConnectionPeer::ReceivedEntropyHash(&connection_, 2)); |
| 3072 } | 3083 } |
| 3073 | 3084 |
| 3074 TEST_P(QuicConnectionTest, ReviveMissingPacketAfterDataPacketsThenFecPacket) { | 3085 TEST_P(QuicConnectionTest, ReviveMissingPacketAfterDataPacketsThenFecPacket) { |
| 3075 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); | 3086 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); |
| 3076 | 3087 |
| 3077 ProcessFecProtectedPacket(1, false, !kEntropyFlag); | 3088 ProcessFecProtectedPacket(1, false, !kEntropyFlag, !kHasStopWaiting); |
| 3078 // Don't send missing packet 2. | 3089 // Don't send missing packet 2. |
| 3079 ProcessFecProtectedPacket(3, false, !kEntropyFlag); | 3090 ProcessFecProtectedPacket(3, false, !kEntropyFlag, !kHasStopWaiting); |
| 3080 ProcessFecPacket(4, 1, true, kEntropyFlag, nullptr); | 3091 ProcessFecPacket(4, 1, true, kEntropyFlag, nullptr); |
| 3081 // Ensure QUIC no longer revives entropy for lost packets. | 3092 // Ensure QUIC no longer revives entropy for lost packets. |
| 3082 EXPECT_EQ(0u, QuicConnectionPeer::ReceivedEntropyHash(&connection_, 2)); | 3093 EXPECT_EQ(0u, QuicConnectionPeer::ReceivedEntropyHash(&connection_, 2)); |
| 3083 EXPECT_NE(0u, QuicConnectionPeer::ReceivedEntropyHash(&connection_, 4)); | 3094 EXPECT_NE(0u, QuicConnectionPeer::ReceivedEntropyHash(&connection_, 4)); |
| 3084 } | 3095 } |
| 3085 | 3096 |
| 3086 TEST_P(QuicConnectionTest, ReviveMissingPacketAfterDataPacket) { | 3097 TEST_P(QuicConnectionTest, ReviveMissingPacketAfterDataPacket) { |
| 3087 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); | 3098 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); |
| 3088 | 3099 |
| 3089 // Don't send missing packet 1. | 3100 // Don't send missing packet 1. |
| 3090 ProcessFecPacket(3, 1, false, !kEntropyFlag, nullptr); | 3101 ProcessFecPacket(3, 1, false, !kEntropyFlag, nullptr); |
| 3091 // Out of order. | 3102 // Out of order. |
| 3092 ProcessFecProtectedPacket(2, true, !kEntropyFlag); | 3103 ProcessFecProtectedPacket(2, true, !kEntropyFlag, !kHasStopWaiting); |
| 3093 // Entropy flag should be false, so entropy should be 0. | 3104 // Entropy flag should be false, so entropy should be 0. |
| 3094 EXPECT_EQ(0u, QuicConnectionPeer::ReceivedEntropyHash(&connection_, 2)); | 3105 EXPECT_EQ(0u, QuicConnectionPeer::ReceivedEntropyHash(&connection_, 2)); |
| 3095 } | 3106 } |
| 3096 | 3107 |
| 3097 TEST_P(QuicConnectionTest, ReviveMissingPacketAfterDataPackets) { | 3108 TEST_P(QuicConnectionTest, ReviveMissingPacketAfterDataPackets) { |
| 3098 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); | 3109 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); |
| 3099 | 3110 |
| 3100 ProcessFecProtectedPacket(1, false, !kEntropyFlag); | 3111 ProcessFecProtectedPacket(1, false, !kEntropyFlag, !kHasStopWaiting); |
| 3101 // Don't send missing packet 2. | 3112 // Don't send missing packet 2. |
| 3102 ProcessFecPacket(6, 1, false, kEntropyFlag, nullptr); | 3113 ProcessFecPacket(6, 1, false, kEntropyFlag, nullptr); |
| 3103 ProcessFecProtectedPacket(3, false, kEntropyFlag); | 3114 ProcessFecProtectedPacket(3, false, kEntropyFlag, !kHasStopWaiting); |
| 3104 ProcessFecProtectedPacket(4, false, kEntropyFlag); | 3115 ProcessFecProtectedPacket(4, false, kEntropyFlag, !kHasStopWaiting); |
| 3105 ProcessFecProtectedPacket(5, true, !kEntropyFlag); | 3116 ProcessFecProtectedPacket(5, true, !kEntropyFlag, !kHasStopWaiting); |
| 3106 // Ensure entropy is not revived for the missing packet. | 3117 // Ensure entropy is not revived for the missing packet. |
| 3107 EXPECT_EQ(0u, QuicConnectionPeer::ReceivedEntropyHash(&connection_, 2)); | 3118 EXPECT_EQ(0u, QuicConnectionPeer::ReceivedEntropyHash(&connection_, 2)); |
| 3108 EXPECT_NE(0u, QuicConnectionPeer::ReceivedEntropyHash(&connection_, 3)); | 3119 EXPECT_NE(0u, QuicConnectionPeer::ReceivedEntropyHash(&connection_, 3)); |
| 3109 } | 3120 } |
| 3110 | 3121 |
| 3111 TEST_P(QuicConnectionTest, TLP) { | 3122 TEST_P(QuicConnectionTest, TLP) { |
| 3112 QuicSentPacketManagerPeer::SetMaxTailLossProbes(manager_, 1); | 3123 QuicSentPacketManagerPeer::SetMaxTailLossProbes(manager_, 1); |
| 3113 | 3124 |
| 3114 SendStreamDataToPeer(3, "foo", 0, !kFin, nullptr); | 3125 SendStreamDataToPeer(3, "foo", 0, !kFin, nullptr); |
| 3115 EXPECT_EQ(1u, stop_waiting()->least_unacked); | 3126 EXPECT_EQ(1u, stop_waiting()->least_unacked); |
| (...skipping 195 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3311 QuicConfig config; | 3322 QuicConfig config; |
| 3312 connection_.SetFromConfig(config); | 3323 connection_.SetFromConfig(config); |
| 3313 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); | 3324 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); |
| 3314 use_tagging_decrypter(); | 3325 use_tagging_decrypter(); |
| 3315 | 3326 |
| 3316 const uint8 tag = 0x07; | 3327 const uint8 tag = 0x07; |
| 3317 framer_.SetEncrypter(ENCRYPTION_INITIAL, new TaggingEncrypter(tag)); | 3328 framer_.SetEncrypter(ENCRYPTION_INITIAL, new TaggingEncrypter(tag)); |
| 3318 | 3329 |
| 3319 // Process an encrypted packet which can not yet be decrypted which should | 3330 // Process an encrypted packet which can not yet be decrypted which should |
| 3320 // result in the packet being buffered. | 3331 // result in the packet being buffered. |
| 3321 ProcessDataPacketAtLevel(1, 0, kEntropyFlag, ENCRYPTION_INITIAL); | 3332 ProcessDataPacketAtLevel(1, 0, kEntropyFlag, !kHasStopWaiting, |
| 3333 ENCRYPTION_INITIAL); |
| 3322 | 3334 |
| 3323 // Transition to the new encryption state and process another encrypted packet | 3335 // Transition to the new encryption state and process another encrypted packet |
| 3324 // which should result in the original packet being processed. | 3336 // which should result in the original packet being processed. |
| 3325 connection_.SetDecrypter(ENCRYPTION_INITIAL, new StrictTaggingDecrypter(tag)); | 3337 connection_.SetDecrypter(ENCRYPTION_INITIAL, new StrictTaggingDecrypter(tag)); |
| 3326 connection_.SetDefaultEncryptionLevel(ENCRYPTION_INITIAL); | 3338 connection_.SetDefaultEncryptionLevel(ENCRYPTION_INITIAL); |
| 3327 connection_.SetEncrypter(ENCRYPTION_INITIAL, new TaggingEncrypter(tag)); | 3339 connection_.SetEncrypter(ENCRYPTION_INITIAL, new TaggingEncrypter(tag)); |
| 3328 EXPECT_CALL(visitor_, OnStreamFrame(_)).Times(2); | 3340 EXPECT_CALL(visitor_, OnStreamFrame(_)).Times(2); |
| 3329 ProcessDataPacketAtLevel(2, 0, kEntropyFlag, ENCRYPTION_INITIAL); | 3341 ProcessDataPacketAtLevel(2, 0, kEntropyFlag, !kHasStopWaiting, |
| 3342 ENCRYPTION_INITIAL); |
| 3330 | 3343 |
| 3331 // Finally, process a third packet and note that we do not reprocess the | 3344 // Finally, process a third packet and note that we do not reprocess the |
| 3332 // buffered packet. | 3345 // buffered packet. |
| 3333 EXPECT_CALL(visitor_, OnStreamFrame(_)).Times(1); | 3346 EXPECT_CALL(visitor_, OnStreamFrame(_)).Times(1); |
| 3334 ProcessDataPacketAtLevel(3, 0, kEntropyFlag, ENCRYPTION_INITIAL); | 3347 ProcessDataPacketAtLevel(3, 0, kEntropyFlag, !kHasStopWaiting, |
| 3348 ENCRYPTION_INITIAL); |
| 3335 } | 3349 } |
| 3336 | 3350 |
| 3337 TEST_P(QuicConnectionTest, ProcessBufferedFECGroup) { | 3351 TEST_P(QuicConnectionTest, ProcessBufferedFECGroup) { |
| 3338 // SetFromConfig is always called after construction from InitializeSession. | 3352 // SetFromConfig is always called after construction from InitializeSession. |
| 3339 EXPECT_CALL(*send_algorithm_, SetFromConfig(_, _)); | 3353 EXPECT_CALL(*send_algorithm_, SetFromConfig(_, _)); |
| 3340 QuicConfig config; | 3354 QuicConfig config; |
| 3341 config.set_max_undecryptable_packets(100); | 3355 config.set_max_undecryptable_packets(100); |
| 3342 connection_.SetFromConfig(config); | 3356 connection_.SetFromConfig(config); |
| 3343 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); | 3357 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); |
| 3344 use_tagging_decrypter(); | 3358 use_tagging_decrypter(); |
| 3345 | 3359 |
| 3346 const uint8 tag = 0x07; | 3360 const uint8 tag = 0x07; |
| 3347 framer_.SetEncrypter(ENCRYPTION_INITIAL, new TaggingEncrypter(tag)); | 3361 framer_.SetEncrypter(ENCRYPTION_INITIAL, new TaggingEncrypter(tag)); |
| 3348 | 3362 |
| 3349 // Don't send packet 1 and buffer initially encrypted packets. | 3363 // Don't send packet 1 and buffer initially encrypted packets. |
| 3350 ProcessFecProtectedPacketAtLevel(2, 1, false, !kEntropyFlag, | 3364 ProcessFecProtectedPacketAtLevel(2, 1, false, !kEntropyFlag, !kHasStopWaiting, |
| 3351 ENCRYPTION_INITIAL); | 3365 ENCRYPTION_INITIAL); |
| 3352 ProcessFecPacketAtLevel(3, 1, false, kEntropyFlag, nullptr, | 3366 ProcessFecPacketAtLevel(3, 1, false, kEntropyFlag, nullptr, |
| 3353 ENCRYPTION_INITIAL); | 3367 ENCRYPTION_INITIAL); |
| 3354 // Since the packets were buffered, no FEC group should be open. | 3368 // Since the packets were buffered, no FEC group should be open. |
| 3355 ASSERT_EQ(0u, connection_.NumFecGroups()); | 3369 ASSERT_EQ(0u, connection_.NumFecGroups()); |
| 3356 | 3370 |
| 3357 // Now send non-fec protected ack packet and close the group. | 3371 // Now send non-fec protected ack packet and close the group. |
| 3358 QuicStopWaitingFrame frame = InitStopWaitingFrame(4); | 3372 QuicStopWaitingFrame frame = InitStopWaitingFrame(4); |
| 3359 ProcessStopWaitingPacketAtLevel(4, &frame, ENCRYPTION_INITIAL); | 3373 ProcessStopWaitingPacketAtLevel(4, &frame, ENCRYPTION_INITIAL); |
| 3360 | 3374 |
| 3361 // Transition to the new encryption state and process another encrypted packet | 3375 // Transition to the new encryption state and process another encrypted packet |
| 3362 // which should result in the original packets being processed. The missing | 3376 // which should result in the original packets being processed. The missing |
| 3363 // packet should be revived before the STOP_WAITING packet is processed. | 3377 // packet should be revived before the STOP_WAITING packet is processed. |
| 3364 connection_.SetDecrypter(ENCRYPTION_INITIAL, new StrictTaggingDecrypter(tag)); | 3378 connection_.SetDecrypter(ENCRYPTION_INITIAL, new StrictTaggingDecrypter(tag)); |
| 3365 connection_.SetDefaultEncryptionLevel(ENCRYPTION_INITIAL); | 3379 connection_.SetDefaultEncryptionLevel(ENCRYPTION_INITIAL); |
| 3366 connection_.SetEncrypter(ENCRYPTION_INITIAL, new TaggingEncrypter(tag)); | 3380 connection_.SetEncrypter(ENCRYPTION_INITIAL, new TaggingEncrypter(tag)); |
| 3367 | 3381 |
| 3368 EXPECT_CALL(visitor_, OnStreamFrame(_)).Times(2).RetiresOnSaturation(); | 3382 EXPECT_CALL(visitor_, OnStreamFrame(_)).Times(2).RetiresOnSaturation(); |
| 3369 ProcessDataPacketAtLevel(5, 0, kEntropyFlag, ENCRYPTION_INITIAL); | 3383 ProcessDataPacketAtLevel(5, 0, kEntropyFlag, !kHasStopWaiting, |
| 3384 ENCRYPTION_INITIAL); |
| 3370 const QuicConnectionStats& stats = connection_.GetStats(); | 3385 const QuicConnectionStats& stats = connection_.GetStats(); |
| 3371 EXPECT_EQ(1u, stats.packets_revived); | 3386 EXPECT_EQ(1u, stats.packets_revived); |
| 3372 } | 3387 } |
| 3373 | 3388 |
| 3374 TEST_P(QuicConnectionTest, Buffer100NonDecryptablePackets) { | 3389 TEST_P(QuicConnectionTest, Buffer100NonDecryptablePackets) { |
| 3375 // SetFromConfig is always called after construction from InitializeSession. | 3390 // SetFromConfig is always called after construction from InitializeSession. |
| 3376 EXPECT_CALL(*send_algorithm_, SetFromConfig(_, _)); | 3391 EXPECT_CALL(*send_algorithm_, SetFromConfig(_, _)); |
| 3377 QuicConfig config; | 3392 QuicConfig config; |
| 3378 config.set_max_undecryptable_packets(100); | 3393 config.set_max_undecryptable_packets(100); |
| 3379 connection_.SetFromConfig(config); | 3394 connection_.SetFromConfig(config); |
| 3380 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); | 3395 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); |
| 3381 use_tagging_decrypter(); | 3396 use_tagging_decrypter(); |
| 3382 | 3397 |
| 3383 const uint8 tag = 0x07; | 3398 const uint8 tag = 0x07; |
| 3384 framer_.SetEncrypter(ENCRYPTION_INITIAL, new TaggingEncrypter(tag)); | 3399 framer_.SetEncrypter(ENCRYPTION_INITIAL, new TaggingEncrypter(tag)); |
| 3385 | 3400 |
| 3386 // Process an encrypted packet which can not yet be decrypted which should | 3401 // Process an encrypted packet which can not yet be decrypted which should |
| 3387 // result in the packet being buffered. | 3402 // result in the packet being buffered. |
| 3388 for (QuicPacketNumber i = 1; i <= 100; ++i) { | 3403 for (QuicPacketNumber i = 1; i <= 100; ++i) { |
| 3389 ProcessDataPacketAtLevel(i, 0, kEntropyFlag, ENCRYPTION_INITIAL); | 3404 ProcessDataPacketAtLevel(i, 0, kEntropyFlag, !kHasStopWaiting, |
| 3405 ENCRYPTION_INITIAL); |
| 3390 } | 3406 } |
| 3391 | 3407 |
| 3392 // Transition to the new encryption state and process another encrypted packet | 3408 // Transition to the new encryption state and process another encrypted packet |
| 3393 // which should result in the original packets being processed. | 3409 // which should result in the original packets being processed. |
| 3394 connection_.SetDecrypter(ENCRYPTION_INITIAL, new StrictTaggingDecrypter(tag)); | 3410 connection_.SetDecrypter(ENCRYPTION_INITIAL, new StrictTaggingDecrypter(tag)); |
| 3395 connection_.SetDefaultEncryptionLevel(ENCRYPTION_INITIAL); | 3411 connection_.SetDefaultEncryptionLevel(ENCRYPTION_INITIAL); |
| 3396 connection_.SetEncrypter(ENCRYPTION_INITIAL, new TaggingEncrypter(tag)); | 3412 connection_.SetEncrypter(ENCRYPTION_INITIAL, new TaggingEncrypter(tag)); |
| 3397 EXPECT_CALL(visitor_, OnStreamFrame(_)).Times(101); | 3413 EXPECT_CALL(visitor_, OnStreamFrame(_)).Times(101); |
| 3398 ProcessDataPacketAtLevel(101, 0, kEntropyFlag, ENCRYPTION_INITIAL); | 3414 ProcessDataPacketAtLevel(101, 0, kEntropyFlag, !kHasStopWaiting, |
| 3415 ENCRYPTION_INITIAL); |
| 3399 | 3416 |
| 3400 // Finally, process a third packet and note that we do not reprocess the | 3417 // Finally, process a third packet and note that we do not reprocess the |
| 3401 // buffered packet. | 3418 // buffered packet. |
| 3402 EXPECT_CALL(visitor_, OnStreamFrame(_)).Times(1); | 3419 EXPECT_CALL(visitor_, OnStreamFrame(_)).Times(1); |
| 3403 ProcessDataPacketAtLevel(102, 0, kEntropyFlag, ENCRYPTION_INITIAL); | 3420 ProcessDataPacketAtLevel(102, 0, kEntropyFlag, !kHasStopWaiting, |
| 3421 ENCRYPTION_INITIAL); |
| 3404 } | 3422 } |
| 3405 | 3423 |
| 3406 TEST_P(QuicConnectionTest, TestRetransmitOrder) { | 3424 TEST_P(QuicConnectionTest, TestRetransmitOrder) { |
| 3407 QuicByteCount first_packet_size; | 3425 QuicByteCount first_packet_size; |
| 3408 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).WillOnce( | 3426 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).WillOnce( |
| 3409 DoAll(SaveArg<3>(&first_packet_size), Return(true))); | 3427 DoAll(SaveArg<3>(&first_packet_size), Return(true))); |
| 3410 | 3428 |
| 3411 connection_.SendStreamDataWithString(3, "first_packet", 0, !kFin, nullptr); | 3429 connection_.SendStreamDataWithString(3, "first_packet", 0, !kFin, nullptr); |
| 3412 QuicByteCount second_packet_size; | 3430 QuicByteCount second_packet_size; |
| 3413 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).WillOnce( | 3431 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).WillOnce( |
| (...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3497 // Unblock the writes and actually send. | 3515 // Unblock the writes and actually send. |
| 3498 writer_->SetWritable(); | 3516 writer_->SetWritable(); |
| 3499 connection_.OnCanWrite(); | 3517 connection_.OnCanWrite(); |
| 3500 EXPECT_EQ(0u, connection_.NumQueuedPackets()); | 3518 EXPECT_EQ(0u, connection_.NumQueuedPackets()); |
| 3501 } | 3519 } |
| 3502 | 3520 |
| 3503 TEST_P(QuicConnectionTest, CloseFecGroup) { | 3521 TEST_P(QuicConnectionTest, CloseFecGroup) { |
| 3504 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); | 3522 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); |
| 3505 // Don't send missing packet 1. | 3523 // Don't send missing packet 1. |
| 3506 // Don't send missing packet 2. | 3524 // Don't send missing packet 2. |
| 3507 ProcessFecProtectedPacket(3, false, !kEntropyFlag); | 3525 ProcessFecProtectedPacket(3, false, !kEntropyFlag, !kHasStopWaiting); |
| 3508 // Don't send missing FEC packet 3. | 3526 // Don't send missing FEC packet 3. |
| 3509 ASSERT_EQ(1u, connection_.NumFecGroups()); | 3527 ASSERT_EQ(1u, connection_.NumFecGroups()); |
| 3510 | 3528 |
| 3511 // Now send non-fec protected ack packet and close the group. | 3529 // Now send non-fec protected ack packet and close the group. |
| 3512 QuicPacketCreatorPeer::SetPacketNumber(&peer_creator_, 4); | 3530 QuicPacketCreatorPeer::SetPacketNumber(&peer_creator_, 4); |
| 3513 QuicStopWaitingFrame frame = InitStopWaitingFrame(5); | 3531 QuicStopWaitingFrame frame = InitStopWaitingFrame(5); |
| 3514 ProcessStopWaitingPacket(&frame); | 3532 ProcessStopWaitingPacket(&frame); |
| 3515 ASSERT_EQ(0u, connection_.NumFecGroups()); | 3533 ASSERT_EQ(0u, connection_.NumFecGroups()); |
| 3516 } | 3534 } |
| 3517 | 3535 |
| 3536 TEST_P(QuicConnectionTest, FailedToCloseFecGroupWithFecProtectedStopWaiting) { |
| 3537 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); |
| 3538 ValueRestore<bool> old_flag(&FLAGS_quic_drop_non_awaited_packets, false); |
| 3539 // Don't send missing packet 1. |
| 3540 ProcessFecProtectedPacket(2, false, !kEntropyFlag, !kHasStopWaiting); |
| 3541 EXPECT_EQ(1u, connection_.NumFecGroups()); |
| 3542 stop_waiting_ = InitStopWaitingFrame(3); |
| 3543 ProcessFecProtectedPacket(3, false, !kEntropyFlag, kHasStopWaiting); |
| 3544 // This Fec group would be closed but created again. |
| 3545 EXPECT_EQ(1u, connection_.NumFecGroups()); |
| 3546 } |
| 3547 |
| 3548 TEST_P(QuicConnectionTest, |
| 3549 CloseFecGroupUnderStopWaitingAndWaitingForPacketsBelowStopWaiting) { |
| 3550 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); |
| 3551 ValueRestore<bool> old_flag(&FLAGS_quic_drop_non_awaited_packets, true); |
| 3552 // Don't send missing packet 1. |
| 3553 ProcessFecProtectedPacket(2, false, !kEntropyFlag, !kHasStopWaiting); |
| 3554 EXPECT_EQ(1u, connection_.NumFecGroups()); |
| 3555 stop_waiting_ = InitStopWaitingFrame(2); |
| 3556 ProcessFecProtectedPacket(3, false, !kEntropyFlag, kHasStopWaiting); |
| 3557 // This Fec group would be closed. |
| 3558 EXPECT_EQ(0u, connection_.NumFecGroups()); |
| 3559 } |
| 3560 |
| 3561 TEST_P(QuicConnectionTest, |
| 3562 DoNotCloseFecGroupUnderStopWaitingButNotWaitingForPacketsBelow) { |
| 3563 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); |
| 3564 ValueRestore<bool> old_flag(&FLAGS_quic_drop_non_awaited_packets, true); |
| 3565 ProcessFecProtectedPacket(1, false, !kEntropyFlag, !kHasStopWaiting); |
| 3566 ProcessFecProtectedPacket(2, false, !kEntropyFlag, !kHasStopWaiting); |
| 3567 // Don't send missing packet 3. |
| 3568 EXPECT_EQ(1u, connection_.NumFecGroups()); |
| 3569 stop_waiting_ = InitStopWaitingFrame(2); |
| 3570 ProcessFecProtectedPacket(3, false, !kEntropyFlag, kHasStopWaiting); |
| 3571 // This group will not be closed because this group is not waiting for packets |
| 3572 // below stop waiting. |
| 3573 EXPECT_EQ(1u, connection_.NumFecGroups()); |
| 3574 } |
| 3575 |
| 3518 TEST_P(QuicConnectionTest, InitialTimeout) { | 3576 TEST_P(QuicConnectionTest, InitialTimeout) { |
| 3519 EXPECT_TRUE(connection_.connected()); | 3577 EXPECT_TRUE(connection_.connected()); |
| 3520 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(AnyNumber()); | 3578 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(AnyNumber()); |
| 3521 EXPECT_FALSE(connection_.GetTimeoutAlarm()->IsSet()); | 3579 EXPECT_FALSE(connection_.GetTimeoutAlarm()->IsSet()); |
| 3522 | 3580 |
| 3523 // SetFromConfig sets the initial timeouts before negotiation. | 3581 // SetFromConfig sets the initial timeouts before negotiation. |
| 3524 EXPECT_CALL(*send_algorithm_, SetFromConfig(_, _)); | 3582 EXPECT_CALL(*send_algorithm_, SetFromConfig(_, _)); |
| 3525 QuicConfig config; | 3583 QuicConfig config; |
| 3526 connection_.SetFromConfig(config); | 3584 connection_.SetFromConfig(config); |
| 3527 // Subtract a second from the idle timeout on the client side. | 3585 // Subtract a second from the idle timeout on the client side. |
| (...skipping 644 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4172 nullptr); | 4230 nullptr); |
| 4173 connection_.GetTimeoutAlarm()->Fire(); | 4231 connection_.GetTimeoutAlarm()->Fire(); |
| 4174 clock_.AdvanceTime(QuicTime::Delta::FromSeconds(1)); | 4232 clock_.AdvanceTime(QuicTime::Delta::FromSeconds(1)); |
| 4175 } | 4233 } |
| 4176 EXPECT_FALSE(connection_.connected()); | 4234 EXPECT_FALSE(connection_.connected()); |
| 4177 EXPECT_FALSE(connection_.GetTimeoutAlarm()->IsSet()); | 4235 EXPECT_FALSE(connection_.GetTimeoutAlarm()->IsSet()); |
| 4178 } | 4236 } |
| 4179 | 4237 |
| 4180 TEST_P(QuicConnectionTest, SendScheduler) { | 4238 TEST_P(QuicConnectionTest, SendScheduler) { |
| 4181 // Test that if we send a packet without delay, it is not queued. | 4239 // Test that if we send a packet without delay, it is not queued. |
| 4182 QuicPacket* packet = ConstructDataPacket(1, 0, !kEntropyFlag); | 4240 QuicPacket* packet = |
| 4241 ConstructDataPacket(1, 0, !kEntropyFlag, !kHasStopWaiting); |
| 4183 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)); | 4242 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)); |
| 4184 connection_.SendPacket(ENCRYPTION_NONE, 1, packet, kTestEntropyHash, | 4243 connection_.SendPacket(ENCRYPTION_NONE, 1, packet, kTestEntropyHash, |
| 4185 HAS_RETRANSMITTABLE_DATA, false, false); | 4244 HAS_RETRANSMITTABLE_DATA, false, false); |
| 4186 EXPECT_EQ(0u, connection_.NumQueuedPackets()); | 4245 EXPECT_EQ(0u, connection_.NumQueuedPackets()); |
| 4187 } | 4246 } |
| 4188 | 4247 |
| 4189 TEST_P(QuicConnectionTest, FailToSendFirstPacket) { | 4248 TEST_P(QuicConnectionTest, FailToSendFirstPacket) { |
| 4190 // Test that the connection does not crash when it fails to send the first | 4249 // Test that the connection does not crash when it fails to send the first |
| 4191 // packet at which point self_address_ might be uninitialized. | 4250 // packet at which point self_address_ might be uninitialized. |
| 4192 EXPECT_CALL(visitor_, OnConnectionClosed(_, _)).Times(1); | 4251 EXPECT_CALL(visitor_, OnConnectionClosed(_, _)).Times(1); |
| 4193 QuicPacket* packet = ConstructDataPacket(1, 0, !kEntropyFlag); | 4252 QuicPacket* packet = |
| 4253 ConstructDataPacket(1, 0, !kEntropyFlag, !kHasStopWaiting); |
| 4194 writer_->SetShouldWriteFail(); | 4254 writer_->SetShouldWriteFail(); |
| 4195 connection_.SendPacket(ENCRYPTION_NONE, 1, packet, kTestEntropyHash, | 4255 connection_.SendPacket(ENCRYPTION_NONE, 1, packet, kTestEntropyHash, |
| 4196 HAS_RETRANSMITTABLE_DATA, false, false); | 4256 HAS_RETRANSMITTABLE_DATA, false, false); |
| 4197 } | 4257 } |
| 4198 | 4258 |
| 4199 TEST_P(QuicConnectionTest, SendSchedulerEAGAIN) { | 4259 TEST_P(QuicConnectionTest, SendSchedulerEAGAIN) { |
| 4200 QuicPacket* packet = ConstructDataPacket(1, 0, !kEntropyFlag); | 4260 QuicPacket* packet = |
| 4261 ConstructDataPacket(1, 0, !kEntropyFlag, !kHasStopWaiting); |
| 4201 BlockOnNextWrite(); | 4262 BlockOnNextWrite(); |
| 4202 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, 1, _, _)).Times(0); | 4263 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, 1, _, _)).Times(0); |
| 4203 connection_.SendPacket(ENCRYPTION_NONE, 1, packet, kTestEntropyHash, | 4264 connection_.SendPacket(ENCRYPTION_NONE, 1, packet, kTestEntropyHash, |
| 4204 HAS_RETRANSMITTABLE_DATA, false, false); | 4265 HAS_RETRANSMITTABLE_DATA, false, false); |
| 4205 EXPECT_EQ(1u, connection_.NumQueuedPackets()); | 4266 EXPECT_EQ(1u, connection_.NumQueuedPackets()); |
| 4206 } | 4267 } |
| 4207 | 4268 |
| 4208 TEST_P(QuicConnectionTest, TestQueueLimitsOnSendStreamData) { | 4269 TEST_P(QuicConnectionTest, TestQueueLimitsOnSendStreamData) { |
| 4209 // All packets carry version info till version is negotiated. | 4270 // All packets carry version info till version is negotiated. |
| 4210 size_t payload_length; | 4271 size_t payload_length; |
| (...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4301 EXPECT_FALSE(connection_.GetAckAlarm()->IsSet()); | 4362 EXPECT_FALSE(connection_.GetAckAlarm()->IsSet()); |
| 4302 const uint8 tag = 0x07; | 4363 const uint8 tag = 0x07; |
| 4303 connection_.SetDecrypter(ENCRYPTION_INITIAL, new StrictTaggingDecrypter(tag)); | 4364 connection_.SetDecrypter(ENCRYPTION_INITIAL, new StrictTaggingDecrypter(tag)); |
| 4304 framer_.SetEncrypter(ENCRYPTION_INITIAL, new TaggingEncrypter(tag)); | 4365 framer_.SetEncrypter(ENCRYPTION_INITIAL, new TaggingEncrypter(tag)); |
| 4305 // Process a packet from the non-crypto stream. | 4366 // Process a packet from the non-crypto stream. |
| 4306 frame1_.stream_id = 3; | 4367 frame1_.stream_id = 3; |
| 4307 | 4368 |
| 4308 // The same as ProcessPacket(1) except that ENCRYPTION_INITIAL is used | 4369 // The same as ProcessPacket(1) except that ENCRYPTION_INITIAL is used |
| 4309 // instead of ENCRYPTION_NONE. | 4370 // instead of ENCRYPTION_NONE. |
| 4310 EXPECT_CALL(visitor_, OnStreamFrame(_)).Times(1); | 4371 EXPECT_CALL(visitor_, OnStreamFrame(_)).Times(1); |
| 4311 ProcessDataPacketAtLevel(1, 0, !kEntropyFlag, ENCRYPTION_INITIAL); | 4372 ProcessDataPacketAtLevel(1, 0, !kEntropyFlag, !kHasStopWaiting, |
| 4373 ENCRYPTION_INITIAL); |
| 4312 | 4374 |
| 4313 // Check if delayed ack timer is running for the expected interval. | 4375 // Check if delayed ack timer is running for the expected interval. |
| 4314 EXPECT_TRUE(connection_.GetAckAlarm()->IsSet()); | 4376 EXPECT_TRUE(connection_.GetAckAlarm()->IsSet()); |
| 4315 EXPECT_EQ(ack_time, connection_.GetAckAlarm()->deadline()); | 4377 EXPECT_EQ(ack_time, connection_.GetAckAlarm()->deadline()); |
| 4316 // Simulate delayed ack alarm firing. | 4378 // Simulate delayed ack alarm firing. |
| 4317 connection_.GetAckAlarm()->Fire(); | 4379 connection_.GetAckAlarm()->Fire(); |
| 4318 // Check that ack is sent and that delayed ack alarm is reset. | 4380 // Check that ack is sent and that delayed ack alarm is reset. |
| 4319 EXPECT_EQ(2u, writer_->frame_count()); | 4381 EXPECT_EQ(2u, writer_->frame_count()); |
| 4320 EXPECT_FALSE(writer_->stop_waiting_frames().empty()); | 4382 EXPECT_FALSE(writer_->stop_waiting_frames().empty()); |
| 4321 EXPECT_FALSE(writer_->ack_frames().empty()); | 4383 EXPECT_FALSE(writer_->ack_frames().empty()); |
| (...skipping 16 matching lines...) Expand all Loading... |
| 4338 const uint8 tag = 0x07; | 4400 const uint8 tag = 0x07; |
| 4339 connection_.SetDecrypter(ENCRYPTION_INITIAL, new StrictTaggingDecrypter(tag)); | 4401 connection_.SetDecrypter(ENCRYPTION_INITIAL, new StrictTaggingDecrypter(tag)); |
| 4340 framer_.SetEncrypter(ENCRYPTION_INITIAL, new TaggingEncrypter(tag)); | 4402 framer_.SetEncrypter(ENCRYPTION_INITIAL, new TaggingEncrypter(tag)); |
| 4341 // Process a packet from the non-crypto stream. | 4403 // Process a packet from the non-crypto stream. |
| 4342 frame1_.stream_id = 3; | 4404 frame1_.stream_id = 3; |
| 4343 | 4405 |
| 4344 // Process all the initial packets in order so there aren't missing packets. | 4406 // Process all the initial packets in order so there aren't missing packets. |
| 4345 QuicPacketNumber kFirstDecimatedPacket = 101; | 4407 QuicPacketNumber kFirstDecimatedPacket = 101; |
| 4346 for (unsigned int i = 0; i < kFirstDecimatedPacket - 1; ++i) { | 4408 for (unsigned int i = 0; i < kFirstDecimatedPacket - 1; ++i) { |
| 4347 EXPECT_CALL(visitor_, OnStreamFrame(_)).Times(1); | 4409 EXPECT_CALL(visitor_, OnStreamFrame(_)).Times(1); |
| 4348 ProcessDataPacketAtLevel(1 + i, 0, !kEntropyFlag, ENCRYPTION_INITIAL); | 4410 ProcessDataPacketAtLevel(1 + i, 0, !kEntropyFlag, !kHasStopWaiting, |
| 4411 ENCRYPTION_INITIAL); |
| 4349 } | 4412 } |
| 4350 EXPECT_FALSE(connection_.GetAckAlarm()->IsSet()); | 4413 EXPECT_FALSE(connection_.GetAckAlarm()->IsSet()); |
| 4351 // The same as ProcessPacket(1) except that ENCRYPTION_INITIAL is used | 4414 // The same as ProcessPacket(1) except that ENCRYPTION_INITIAL is used |
| 4352 // instead of ENCRYPTION_NONE. | 4415 // instead of ENCRYPTION_NONE. |
| 4353 EXPECT_CALL(visitor_, OnStreamFrame(_)).Times(1); | 4416 EXPECT_CALL(visitor_, OnStreamFrame(_)).Times(1); |
| 4354 ProcessDataPacketAtLevel(kFirstDecimatedPacket, 0, !kEntropyFlag, | 4417 ProcessDataPacketAtLevel(kFirstDecimatedPacket, 0, !kEntropyFlag, |
| 4355 ENCRYPTION_INITIAL); | 4418 !kHasStopWaiting, ENCRYPTION_INITIAL); |
| 4356 | 4419 |
| 4357 // Check if delayed ack timer is running for the expected interval. | 4420 // Check if delayed ack timer is running for the expected interval. |
| 4358 EXPECT_TRUE(connection_.GetAckAlarm()->IsSet()); | 4421 EXPECT_TRUE(connection_.GetAckAlarm()->IsSet()); |
| 4359 EXPECT_EQ(ack_time, connection_.GetAckAlarm()->deadline()); | 4422 EXPECT_EQ(ack_time, connection_.GetAckAlarm()->deadline()); |
| 4360 | 4423 |
| 4361 // The 10th received packet causes an ack to be sent. | 4424 // The 10th received packet causes an ack to be sent. |
| 4362 for (int i = 0; i < 9; ++i) { | 4425 for (int i = 0; i < 9; ++i) { |
| 4363 EXPECT_TRUE(connection_.GetAckAlarm()->IsSet()); | 4426 EXPECT_TRUE(connection_.GetAckAlarm()->IsSet()); |
| 4364 EXPECT_CALL(visitor_, OnStreamFrame(_)).Times(1); | 4427 EXPECT_CALL(visitor_, OnStreamFrame(_)).Times(1); |
| 4365 ProcessDataPacketAtLevel(kFirstDecimatedPacket + 1 + i, 0, !kEntropyFlag, | 4428 ProcessDataPacketAtLevel(kFirstDecimatedPacket + 1 + i, 0, !kEntropyFlag, |
| 4366 ENCRYPTION_INITIAL); | 4429 !kHasStopWaiting, ENCRYPTION_INITIAL); |
| 4367 } | 4430 } |
| 4368 // Check that ack is sent and that delayed ack alarm is reset. | 4431 // Check that ack is sent and that delayed ack alarm is reset. |
| 4369 EXPECT_EQ(2u, writer_->frame_count()); | 4432 EXPECT_EQ(2u, writer_->frame_count()); |
| 4370 EXPECT_FALSE(writer_->stop_waiting_frames().empty()); | 4433 EXPECT_FALSE(writer_->stop_waiting_frames().empty()); |
| 4371 EXPECT_FALSE(writer_->ack_frames().empty()); | 4434 EXPECT_FALSE(writer_->ack_frames().empty()); |
| 4372 EXPECT_FALSE(connection_.GetAckAlarm()->IsSet()); | 4435 EXPECT_FALSE(connection_.GetAckAlarm()->IsSet()); |
| 4373 } | 4436 } |
| 4374 | 4437 |
| 4375 TEST_P(QuicConnectionTest, SendDelayedAckOnHandshakeConfirmed) { | 4438 TEST_P(QuicConnectionTest, SendDelayedAckOnHandshakeConfirmed) { |
| 4376 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); | 4439 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); |
| (...skipping 185 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4562 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(0); | 4625 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(0); |
| 4563 ProcessClosePacket(2, 0); | 4626 ProcessClosePacket(2, 0); |
| 4564 } | 4627 } |
| 4565 | 4628 |
| 4566 TEST_P(QuicConnectionTest, SendWhenDisconnected) { | 4629 TEST_P(QuicConnectionTest, SendWhenDisconnected) { |
| 4567 EXPECT_TRUE(connection_.connected()); | 4630 EXPECT_TRUE(connection_.connected()); |
| 4568 EXPECT_CALL(visitor_, OnConnectionClosed(QUIC_PEER_GOING_AWAY, false)); | 4631 EXPECT_CALL(visitor_, OnConnectionClosed(QUIC_PEER_GOING_AWAY, false)); |
| 4569 connection_.CloseConnection(QUIC_PEER_GOING_AWAY, false); | 4632 connection_.CloseConnection(QUIC_PEER_GOING_AWAY, false); |
| 4570 EXPECT_FALSE(connection_.connected()); | 4633 EXPECT_FALSE(connection_.connected()); |
| 4571 EXPECT_FALSE(connection_.CanWriteStreamData()); | 4634 EXPECT_FALSE(connection_.CanWriteStreamData()); |
| 4572 QuicPacket* packet = ConstructDataPacket(1, 0, !kEntropyFlag); | 4635 QuicPacket* packet = |
| 4636 ConstructDataPacket(1, 0, !kEntropyFlag, !kHasStopWaiting); |
| 4573 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, 1, _, _)).Times(0); | 4637 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, 1, _, _)).Times(0); |
| 4574 connection_.SendPacket(ENCRYPTION_NONE, 1, packet, kTestEntropyHash, | 4638 connection_.SendPacket(ENCRYPTION_NONE, 1, packet, kTestEntropyHash, |
| 4575 HAS_RETRANSMITTABLE_DATA, false, false); | 4639 HAS_RETRANSMITTABLE_DATA, false, false); |
| 4576 } | 4640 } |
| 4577 | 4641 |
| 4578 TEST_P(QuicConnectionTest, PublicReset) { | 4642 TEST_P(QuicConnectionTest, PublicReset) { |
| 4579 QuicPublicResetPacket header; | 4643 QuicPublicResetPacket header; |
| 4580 header.public_header.connection_id = connection_id_; | 4644 header.public_header.connection_id = connection_id_; |
| 4581 header.public_header.reset_flag = true; | 4645 header.public_header.reset_flag = true; |
| 4582 header.public_header.version_flag = false; | 4646 header.public_header.version_flag = false; |
| (...skipping 337 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4920 stats.bytes_retransmitted); | 4984 stats.bytes_retransmitted); |
| 4921 EXPECT_EQ(3u, stats.packets_retransmitted); | 4985 EXPECT_EQ(3u, stats.packets_retransmitted); |
| 4922 EXPECT_EQ(1u, stats.rto_count); | 4986 EXPECT_EQ(1u, stats.rto_count); |
| 4923 EXPECT_EQ(kDefaultMaxPacketSize, stats.max_packet_size); | 4987 EXPECT_EQ(kDefaultMaxPacketSize, stats.max_packet_size); |
| 4924 } | 4988 } |
| 4925 | 4989 |
| 4926 TEST_P(QuicConnectionTest, CheckReceiveStats) { | 4990 TEST_P(QuicConnectionTest, CheckReceiveStats) { |
| 4927 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); | 4991 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); |
| 4928 | 4992 |
| 4929 size_t received_bytes = 0; | 4993 size_t received_bytes = 0; |
| 4930 received_bytes += ProcessFecProtectedPacket(1, false, !kEntropyFlag); | 4994 received_bytes += |
| 4931 received_bytes += ProcessFecProtectedPacket(3, false, !kEntropyFlag); | 4995 ProcessFecProtectedPacket(1, false, !kEntropyFlag, !kHasStopWaiting); |
| 4996 received_bytes += |
| 4997 ProcessFecProtectedPacket(3, false, !kEntropyFlag, !kHasStopWaiting); |
| 4932 // Should be counted against dropped packets. | 4998 // Should be counted against dropped packets. |
| 4933 received_bytes += ProcessDataPacket(3, 1, !kEntropyFlag); | 4999 received_bytes += ProcessDataPacket(3, 1, !kEntropyFlag); |
| 4934 received_bytes += ProcessFecPacket(4, 1, true, !kEntropyFlag, nullptr); | 5000 received_bytes += ProcessFecPacket(4, 1, true, !kEntropyFlag, nullptr); |
| 4935 | 5001 |
| 4936 EXPECT_CALL(*send_algorithm_, BandwidthEstimate()).WillOnce( | 5002 EXPECT_CALL(*send_algorithm_, BandwidthEstimate()).WillOnce( |
| 4937 Return(QuicBandwidth::Zero())); | 5003 Return(QuicBandwidth::Zero())); |
| 4938 | 5004 |
| 4939 const QuicConnectionStats& stats = connection_.GetStats(); | 5005 const QuicConnectionStats& stats = connection_.GetStats(); |
| 4940 EXPECT_EQ(received_bytes, stats.bytes_received); | 5006 EXPECT_EQ(received_bytes, stats.bytes_received); |
| 4941 EXPECT_EQ(4u, stats.packets_received); | 5007 EXPECT_EQ(4u, stats.packets_received); |
| (...skipping 410 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5352 QuicPacketCreatorPeer::GetFecTimeout(creator_)); | 5418 QuicPacketCreatorPeer::GetFecTimeout(creator_)); |
| 5353 } | 5419 } |
| 5354 | 5420 |
| 5355 TEST_P(QuicConnectionTest, OnPacketHeaderDebugVisitor) { | 5421 TEST_P(QuicConnectionTest, OnPacketHeaderDebugVisitor) { |
| 5356 QuicPacketHeader header; | 5422 QuicPacketHeader header; |
| 5357 | 5423 |
| 5358 scoped_ptr<MockQuicConnectionDebugVisitor> debug_visitor( | 5424 scoped_ptr<MockQuicConnectionDebugVisitor> debug_visitor( |
| 5359 new MockQuicConnectionDebugVisitor()); | 5425 new MockQuicConnectionDebugVisitor()); |
| 5360 connection_.set_debug_visitor(debug_visitor.get()); | 5426 connection_.set_debug_visitor(debug_visitor.get()); |
| 5361 EXPECT_CALL(*debug_visitor, OnPacketHeader(Ref(header))).Times(1); | 5427 EXPECT_CALL(*debug_visitor, OnPacketHeader(Ref(header))).Times(1); |
| 5362 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)).Times(1); | 5428 if (FLAGS_quic_drop_non_awaited_packets) { |
| 5363 EXPECT_CALL(*debug_visitor, OnSuccessfulVersionNegotiation(_)).Times(1); | 5429 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)).Times(1); |
| 5430 EXPECT_CALL(*debug_visitor, OnSuccessfulVersionNegotiation(_)).Times(1); |
| 5431 } |
| 5364 connection_.OnPacketHeader(header); | 5432 connection_.OnPacketHeader(header); |
| 5365 } | 5433 } |
| 5366 | 5434 |
| 5367 TEST_P(QuicConnectionTest, Pacing) { | 5435 TEST_P(QuicConnectionTest, Pacing) { |
| 5368 TestConnection server(connection_id_, kSelfAddress, helper_.get(), factory_, | 5436 TestConnection server(connection_id_, kSelfAddress, helper_.get(), factory_, |
| 5369 Perspective::IS_SERVER, version()); | 5437 Perspective::IS_SERVER, version()); |
| 5370 TestConnection client(connection_id_, kPeerAddress, helper_.get(), factory_, | 5438 TestConnection client(connection_id_, kPeerAddress, helper_.get(), factory_, |
| 5371 Perspective::IS_CLIENT, version()); | 5439 Perspective::IS_CLIENT, version()); |
| 5372 EXPECT_FALSE(client.sent_packet_manager().using_pacing()); | 5440 EXPECT_FALSE(client.sent_packet_manager().using_pacing()); |
| 5373 EXPECT_FALSE(server.sent_packet_manager().using_pacing()); | 5441 EXPECT_FALSE(server.sent_packet_manager().using_pacing()); |
| (...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5503 EXPECT_CALL(visitor_, | 5571 EXPECT_CALL(visitor_, |
| 5504 OnConnectionClosed(QUIC_UNENCRYPTED_STREAM_DATA, false)); | 5572 OnConnectionClosed(QUIC_UNENCRYPTED_STREAM_DATA, false)); |
| 5505 EXPECT_DFATAL(connection_.SendStreamDataWithString(3, "", 0, kFin, nullptr), | 5573 EXPECT_DFATAL(connection_.SendStreamDataWithString(3, "", 0, kFin, nullptr), |
| 5506 "Cannot send stream data without encryption."); | 5574 "Cannot send stream data without encryption."); |
| 5507 EXPECT_FALSE(connection_.connected()); | 5575 EXPECT_FALSE(connection_.connected()); |
| 5508 } | 5576 } |
| 5509 | 5577 |
| 5510 } // namespace | 5578 } // namespace |
| 5511 } // namespace test | 5579 } // namespace test |
| 5512 } // namespace net | 5580 } // namespace net |
| OLD | NEW |