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 "base/basictypes.h" | 7 #include "base/basictypes.h" |
8 #include "base/bind.h" | 8 #include "base/bind.h" |
9 #include "base/memory/scoped_ptr.h" | 9 #include "base/memory/scoped_ptr.h" |
10 #include "base/stl_util.h" | 10 #include "base/stl_util.h" |
(...skipping 1559 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1570 | 1570 |
1571 // First send without any pause and check the result. | 1571 // First send without any pause and check the result. |
1572 QuicTime expected_recorded_send_time = clock_.Now(); | 1572 QuicTime expected_recorded_send_time = clock_.Now(); |
1573 connection_.SendStreamDataWithString(1, "foo", 0, !kFin, nullptr); | 1573 connection_.SendStreamDataWithString(1, "foo", 0, !kFin, nullptr); |
1574 EXPECT_EQ(expected_recorded_send_time, actual_recorded_send_time) | 1574 EXPECT_EQ(expected_recorded_send_time, actual_recorded_send_time) |
1575 << "Expected time = " << expected_recorded_send_time.ToDebuggingValue() | 1575 << "Expected time = " << expected_recorded_send_time.ToDebuggingValue() |
1576 << ". Actual time = " << actual_recorded_send_time.ToDebuggingValue(); | 1576 << ". Actual time = " << actual_recorded_send_time.ToDebuggingValue(); |
1577 | 1577 |
1578 // Now pause during the write, and check the results. | 1578 // Now pause during the write, and check the results. |
1579 actual_recorded_send_time = QuicTime::Zero(); | 1579 actual_recorded_send_time = QuicTime::Zero(); |
1580 const QuicTime::Delta kWritePauseTimeDelta = | 1580 const QuicTime::Delta write_pause_time_delta = |
1581 QuicTime::Delta::FromMilliseconds(5000); | 1581 QuicTime::Delta::FromMilliseconds(5000); |
1582 SetWritePauseTimeDelta(kWritePauseTimeDelta); | 1582 SetWritePauseTimeDelta(write_pause_time_delta); |
1583 expected_recorded_send_time = clock_.Now(); | 1583 expected_recorded_send_time = clock_.Now(); |
1584 | 1584 |
1585 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)) | 1585 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)) |
1586 .WillOnce(DoAll(SaveArg<0>(&actual_recorded_send_time), Return(true))); | 1586 .WillOnce(DoAll(SaveArg<0>(&actual_recorded_send_time), Return(true))); |
1587 connection_.SendStreamDataWithString(2, "baz", 0, !kFin, nullptr); | 1587 connection_.SendStreamDataWithString(2, "baz", 0, !kFin, nullptr); |
1588 EXPECT_EQ(expected_recorded_send_time, actual_recorded_send_time) | 1588 EXPECT_EQ(expected_recorded_send_time, actual_recorded_send_time) |
1589 << "Expected time = " << expected_recorded_send_time.ToDebuggingValue() | 1589 << "Expected time = " << expected_recorded_send_time.ToDebuggingValue() |
1590 << ". Actual time = " << actual_recorded_send_time.ToDebuggingValue(); | 1590 << ". Actual time = " << actual_recorded_send_time.ToDebuggingValue(); |
1591 } | 1591 } |
1592 | 1592 |
1593 TEST_P(QuicConnectionTest, FECSending) { | 1593 TEST_P(QuicConnectionTest, FECSending) { |
1594 // All packets carry version info till version is negotiated. | 1594 // All packets carry version info till version is negotiated. |
1595 size_t payload_length; | 1595 size_t payload_length; |
1596 // GetPacketLengthForOneStream() assumes a stream offset of 0 in determining | 1596 // GetPacketLengthForOneStream() assumes a stream offset of 0 in determining |
1597 // packet length. The size of the offset field in a stream frame is 0 for | 1597 // packet length. The size of the offset field in a stream frame is 0 for |
1598 // offset 0, and 2 for non-zero offsets up through 64K. Increase | 1598 // offset 0, and 2 for non-zero offsets up through 64K. Increase |
1599 // max_packet_length by 2 so that subsequent packets containing subsequent | 1599 // max_packet_length by 2 so that subsequent packets containing subsequent |
1600 // stream frames with non-zero offets will fit within the packet length. | 1600 // stream frames with non-zero offets will fit within the packet length. |
1601 size_t length = 2 + GetPacketLengthForOneStream( | 1601 size_t length = 2 + GetPacketLengthForOneStream( |
1602 connection_.version(), kIncludeVersion, | 1602 connection_.version(), kIncludeVersion, |
1603 PACKET_8BYTE_CONNECTION_ID, PACKET_1BYTE_SEQUENCE_NUMBER, | 1603 PACKET_8BYTE_CONNECTION_ID, PACKET_1BYTE_SEQUENCE_NUMBER, |
1604 IN_FEC_GROUP, &payload_length); | 1604 IN_FEC_GROUP, &payload_length); |
1605 creator_->set_max_packet_length(length); | 1605 creator_->SetMaxPacketLength(length); |
1606 | 1606 |
1607 // Send 4 protected data packets, which should also trigger 1 FEC packet. | 1607 // Send 4 protected data packets, which should also trigger 1 FEC packet. |
1608 EXPECT_CALL(*send_algorithm_, | 1608 EXPECT_CALL(*send_algorithm_, |
1609 OnPacketSent(_, _, _, _, HAS_RETRANSMITTABLE_DATA)).Times(5); | 1609 OnPacketSent(_, _, _, _, HAS_RETRANSMITTABLE_DATA)).Times(5); |
1610 // The first stream frame will have 2 fewer overhead bytes than the other 3. | 1610 // The first stream frame will have 2 fewer overhead bytes than the other 3. |
1611 const string payload(payload_length * 4 + 2, 'a'); | 1611 const string payload(payload_length * 4 + 2, 'a'); |
1612 connection_.SendStreamDataWithStringWithFec(1, payload, 0, !kFin, nullptr); | 1612 connection_.SendStreamDataWithStringWithFec(1, payload, 0, !kFin, nullptr); |
1613 // Expect the FEC group to be closed after SendStreamDataWithString. | 1613 // Expect the FEC group to be closed after SendStreamDataWithString. |
1614 EXPECT_FALSE(creator_->IsFecGroupOpen()); | 1614 EXPECT_FALSE(creator_->IsFecGroupOpen()); |
1615 EXPECT_FALSE(creator_->IsFecProtected()); | 1615 EXPECT_FALSE(creator_->IsFecProtected()); |
1616 } | 1616 } |
1617 | 1617 |
1618 TEST_P(QuicConnectionTest, FECQueueing) { | 1618 TEST_P(QuicConnectionTest, FECQueueing) { |
1619 // All packets carry version info till version is negotiated. | 1619 // All packets carry version info till version is negotiated. |
1620 size_t payload_length; | 1620 size_t payload_length; |
1621 size_t length = GetPacketLengthForOneStream( | 1621 size_t length = GetPacketLengthForOneStream( |
1622 connection_.version(), kIncludeVersion, | 1622 connection_.version(), kIncludeVersion, |
1623 PACKET_8BYTE_CONNECTION_ID, PACKET_1BYTE_SEQUENCE_NUMBER, | 1623 PACKET_8BYTE_CONNECTION_ID, PACKET_1BYTE_SEQUENCE_NUMBER, |
1624 IN_FEC_GROUP, &payload_length); | 1624 IN_FEC_GROUP, &payload_length); |
1625 creator_->set_max_packet_length(length); | 1625 creator_->SetMaxPacketLength(length); |
1626 EXPECT_TRUE(creator_->IsFecEnabled()); | 1626 EXPECT_TRUE(creator_->IsFecEnabled()); |
1627 | 1627 |
1628 EXPECT_EQ(0u, connection_.NumQueuedPackets()); | 1628 EXPECT_EQ(0u, connection_.NumQueuedPackets()); |
1629 BlockOnNextWrite(); | 1629 BlockOnNextWrite(); |
1630 const string payload(payload_length, 'a'); | 1630 const string payload(payload_length, 'a'); |
1631 connection_.SendStreamDataWithStringWithFec(1, payload, 0, !kFin, nullptr); | 1631 connection_.SendStreamDataWithStringWithFec(1, payload, 0, !kFin, nullptr); |
1632 EXPECT_FALSE(creator_->IsFecGroupOpen()); | 1632 EXPECT_FALSE(creator_->IsFecGroupOpen()); |
1633 EXPECT_FALSE(creator_->IsFecProtected()); | 1633 EXPECT_FALSE(creator_->IsFecProtected()); |
1634 // Expect the first data packet and the fec packet to be queued. | 1634 // Expect the first data packet and the fec packet to be queued. |
1635 EXPECT_EQ(2u, connection_.NumQueuedPackets()); | 1635 EXPECT_EQ(2u, connection_.NumQueuedPackets()); |
(...skipping 1230 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2866 // the forward-secure encrypter is now used. | 2866 // the forward-secure encrypter is now used. |
2867 for (uint64 i = 0; i < 3 * congestion_window - 1; ++i) { | 2867 for (uint64 i = 0; i < 3 * congestion_window - 1; ++i) { |
2868 EXPECT_EQ(0x02020202u, writer_->final_bytes_of_last_packet()); | 2868 EXPECT_EQ(0x02020202u, writer_->final_bytes_of_last_packet()); |
2869 SendAckPacketToPeer(); | 2869 SendAckPacketToPeer(); |
2870 } | 2870 } |
2871 EXPECT_EQ(0x03030303u, writer_->final_bytes_of_last_packet()); | 2871 EXPECT_EQ(0x03030303u, writer_->final_bytes_of_last_packet()); |
2872 } | 2872 } |
2873 | 2873 |
2874 TEST_P(QuicConnectionTest, BufferNonDecryptablePackets) { | 2874 TEST_P(QuicConnectionTest, BufferNonDecryptablePackets) { |
2875 // SetFromConfig is always called after construction from InitializeSession. | 2875 // SetFromConfig is always called after construction from InitializeSession. |
2876 EXPECT_CALL(*send_algorithm_, SetFromConfig(_, _, _)); | 2876 EXPECT_CALL(*send_algorithm_, SetFromConfig(_, _)); |
2877 QuicConfig config; | 2877 QuicConfig config; |
2878 connection_.SetFromConfig(config); | 2878 connection_.SetFromConfig(config); |
2879 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); | 2879 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); |
2880 use_tagging_decrypter(); | 2880 use_tagging_decrypter(); |
2881 | 2881 |
2882 const uint8 tag = 0x07; | 2882 const uint8 tag = 0x07; |
2883 framer_.SetEncrypter(ENCRYPTION_INITIAL, new TaggingEncrypter(tag)); | 2883 framer_.SetEncrypter(ENCRYPTION_INITIAL, new TaggingEncrypter(tag)); |
2884 | 2884 |
2885 // Process an encrypted packet which can not yet be decrypted which should | 2885 // Process an encrypted packet which can not yet be decrypted which should |
2886 // result in the packet being buffered. | 2886 // result in the packet being buffered. |
2887 ProcessDataPacketAtLevel(1, 0, kEntropyFlag, ENCRYPTION_INITIAL); | 2887 ProcessDataPacketAtLevel(1, 0, kEntropyFlag, ENCRYPTION_INITIAL); |
2888 | 2888 |
2889 // Transition to the new encryption state and process another encrypted packet | 2889 // Transition to the new encryption state and process another encrypted packet |
2890 // which should result in the original packet being processed. | 2890 // which should result in the original packet being processed. |
2891 connection_.SetDecrypter(new StrictTaggingDecrypter(tag), | 2891 connection_.SetDecrypter(new StrictTaggingDecrypter(tag), |
2892 ENCRYPTION_INITIAL); | 2892 ENCRYPTION_INITIAL); |
2893 connection_.SetDefaultEncryptionLevel(ENCRYPTION_INITIAL); | 2893 connection_.SetDefaultEncryptionLevel(ENCRYPTION_INITIAL); |
2894 connection_.SetEncrypter(ENCRYPTION_INITIAL, new TaggingEncrypter(tag)); | 2894 connection_.SetEncrypter(ENCRYPTION_INITIAL, new TaggingEncrypter(tag)); |
2895 EXPECT_CALL(visitor_, OnStreamFrames(_)).Times(2); | 2895 EXPECT_CALL(visitor_, OnStreamFrames(_)).Times(2); |
2896 ProcessDataPacketAtLevel(2, 0, kEntropyFlag, ENCRYPTION_INITIAL); | 2896 ProcessDataPacketAtLevel(2, 0, kEntropyFlag, ENCRYPTION_INITIAL); |
2897 | 2897 |
2898 // Finally, process a third packet and note that we do not reprocess the | 2898 // Finally, process a third packet and note that we do not reprocess the |
2899 // buffered packet. | 2899 // buffered packet. |
2900 EXPECT_CALL(visitor_, OnStreamFrames(_)).Times(1); | 2900 EXPECT_CALL(visitor_, OnStreamFrames(_)).Times(1); |
2901 ProcessDataPacketAtLevel(3, 0, kEntropyFlag, ENCRYPTION_INITIAL); | 2901 ProcessDataPacketAtLevel(3, 0, kEntropyFlag, ENCRYPTION_INITIAL); |
2902 } | 2902 } |
2903 | 2903 |
2904 TEST_P(QuicConnectionTest, Buffer100NonDecryptablePackets) { | 2904 TEST_P(QuicConnectionTest, Buffer100NonDecryptablePackets) { |
2905 // SetFromConfig is always called after construction from InitializeSession. | 2905 // SetFromConfig is always called after construction from InitializeSession. |
2906 EXPECT_CALL(*send_algorithm_, SetFromConfig(_, _, _)); | 2906 EXPECT_CALL(*send_algorithm_, SetFromConfig(_, _)); |
2907 QuicConfig config; | 2907 QuicConfig config; |
2908 config.set_max_undecryptable_packets(100); | 2908 config.set_max_undecryptable_packets(100); |
2909 connection_.SetFromConfig(config); | 2909 connection_.SetFromConfig(config); |
2910 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); | 2910 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); |
2911 use_tagging_decrypter(); | 2911 use_tagging_decrypter(); |
2912 | 2912 |
2913 const uint8 tag = 0x07; | 2913 const uint8 tag = 0x07; |
2914 framer_.SetEncrypter(ENCRYPTION_INITIAL, new TaggingEncrypter(tag)); | 2914 framer_.SetEncrypter(ENCRYPTION_INITIAL, new TaggingEncrypter(tag)); |
2915 | 2915 |
2916 // Process an encrypted packet which can not yet be decrypted which should | 2916 // Process an encrypted packet which can not yet be decrypted which should |
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3044 ProcessStopWaitingPacket(&frame); | 3044 ProcessStopWaitingPacket(&frame); |
3045 ASSERT_EQ(0u, connection_.NumFecGroups()); | 3045 ASSERT_EQ(0u, connection_.NumFecGroups()); |
3046 } | 3046 } |
3047 | 3047 |
3048 TEST_P(QuicConnectionTest, InitialTimeout) { | 3048 TEST_P(QuicConnectionTest, InitialTimeout) { |
3049 EXPECT_TRUE(connection_.connected()); | 3049 EXPECT_TRUE(connection_.connected()); |
3050 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(AnyNumber()); | 3050 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(AnyNumber()); |
3051 EXPECT_FALSE(connection_.GetTimeoutAlarm()->IsSet()); | 3051 EXPECT_FALSE(connection_.GetTimeoutAlarm()->IsSet()); |
3052 | 3052 |
3053 // SetFromConfig sets the initial timeouts before negotiation. | 3053 // SetFromConfig sets the initial timeouts before negotiation. |
3054 EXPECT_CALL(*send_algorithm_, SetFromConfig(_, _, _)); | 3054 EXPECT_CALL(*send_algorithm_, SetFromConfig(_, _)); |
3055 QuicConfig config; | 3055 QuicConfig config; |
3056 connection_.SetFromConfig(config); | 3056 connection_.SetFromConfig(config); |
3057 // Subtract a second from the idle timeout on the client side. | 3057 // Subtract a second from the idle timeout on the client side. |
3058 QuicTime default_timeout = clock_.ApproximateNow().Add( | 3058 QuicTime default_timeout = clock_.ApproximateNow().Add( |
3059 QuicTime::Delta::FromSeconds(kInitialIdleTimeoutSecs - 1)); | 3059 QuicTime::Delta::FromSeconds(kInitialIdleTimeoutSecs - 1)); |
3060 EXPECT_EQ(default_timeout, connection_.GetTimeoutAlarm()->deadline()); | 3060 EXPECT_EQ(default_timeout, connection_.GetTimeoutAlarm()->deadline()); |
3061 | 3061 |
3062 EXPECT_CALL(visitor_, OnConnectionClosed(QUIC_CONNECTION_TIMED_OUT, false)); | 3062 EXPECT_CALL(visitor_, OnConnectionClosed(QUIC_CONNECTION_TIMED_OUT, false)); |
3063 // Simulate the timeout alarm firing. | 3063 // Simulate the timeout alarm firing. |
3064 clock_.AdvanceTime( | 3064 clock_.AdvanceTime( |
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3156 | 3156 |
3157 EXPECT_CALL(visitor_, HasOpenDataStreams()).WillRepeatedly(Return(false)); | 3157 EXPECT_CALL(visitor_, HasOpenDataStreams()).WillRepeatedly(Return(false)); |
3158 clock_.AdvanceTime(QuicTime::Delta::FromMilliseconds(5)); | 3158 clock_.AdvanceTime(QuicTime::Delta::FromMilliseconds(5)); |
3159 SendAckPacketToPeer(); | 3159 SendAckPacketToPeer(); |
3160 | 3160 |
3161 EXPECT_FALSE(connection_.GetPingAlarm()->IsSet()); | 3161 EXPECT_FALSE(connection_.GetPingAlarm()->IsSet()); |
3162 } | 3162 } |
3163 | 3163 |
3164 TEST_P(QuicConnectionTest, TimeoutAfterSend) { | 3164 TEST_P(QuicConnectionTest, TimeoutAfterSend) { |
3165 EXPECT_TRUE(connection_.connected()); | 3165 EXPECT_TRUE(connection_.connected()); |
3166 EXPECT_CALL(*send_algorithm_, SetFromConfig(_, _, _)); | 3166 EXPECT_CALL(*send_algorithm_, SetFromConfig(_, _)); |
3167 QuicConfig config; | 3167 QuicConfig config; |
3168 connection_.SetFromConfig(config); | 3168 connection_.SetFromConfig(config); |
3169 EXPECT_FALSE(QuicConnectionPeer::IsSilentCloseEnabled(&connection_)); | 3169 EXPECT_FALSE(QuicConnectionPeer::IsSilentCloseEnabled(&connection_)); |
3170 | 3170 |
3171 const QuicTime::Delta initial_idle_timeout = | 3171 const QuicTime::Delta initial_idle_timeout = |
3172 QuicTime::Delta::FromSeconds(kInitialIdleTimeoutSecs - 1); | 3172 QuicTime::Delta::FromSeconds(kInitialIdleTimeoutSecs - 1); |
3173 const QuicTime::Delta five_ms = QuicTime::Delta::FromMilliseconds(5); | 3173 const QuicTime::Delta five_ms = QuicTime::Delta::FromMilliseconds(5); |
3174 QuicTime default_timeout = clock_.ApproximateNow().Add(initial_idle_timeout); | 3174 QuicTime default_timeout = clock_.ApproximateNow().Add(initial_idle_timeout); |
3175 | 3175 |
3176 // When we send a packet, the timeout will change to 5ms + | 3176 // When we send a packet, the timeout will change to 5ms + |
(...skipping 21 matching lines...) Expand all Loading... |
3198 EXPECT_EQ(default_timeout.Add(five_ms), clock_.ApproximateNow()); | 3198 EXPECT_EQ(default_timeout.Add(five_ms), clock_.ApproximateNow()); |
3199 connection_.GetTimeoutAlarm()->Fire(); | 3199 connection_.GetTimeoutAlarm()->Fire(); |
3200 EXPECT_FALSE(connection_.GetTimeoutAlarm()->IsSet()); | 3200 EXPECT_FALSE(connection_.GetTimeoutAlarm()->IsSet()); |
3201 EXPECT_FALSE(connection_.connected()); | 3201 EXPECT_FALSE(connection_.connected()); |
3202 } | 3202 } |
3203 | 3203 |
3204 TEST_P(QuicConnectionTest, TimeoutAfterSendSilentClose) { | 3204 TEST_P(QuicConnectionTest, TimeoutAfterSendSilentClose) { |
3205 // Same test as above, but complete a handshake which enables silent close, | 3205 // Same test as above, but complete a handshake which enables silent close, |
3206 // causing no connection close packet to be sent. | 3206 // causing no connection close packet to be sent. |
3207 EXPECT_TRUE(connection_.connected()); | 3207 EXPECT_TRUE(connection_.connected()); |
3208 EXPECT_CALL(*send_algorithm_, SetFromConfig(_, _, _)); | 3208 EXPECT_CALL(*send_algorithm_, SetFromConfig(_, _)); |
3209 QuicConfig config; | 3209 QuicConfig config; |
3210 | 3210 |
3211 // Create a handshake message that also enables silent close. | 3211 // Create a handshake message that also enables silent close. |
3212 CryptoHandshakeMessage msg; | 3212 CryptoHandshakeMessage msg; |
3213 string error_details; | 3213 string error_details; |
3214 QuicConfig client_config; | 3214 QuicConfig client_config; |
3215 client_config.SetInitialStreamFlowControlWindowToSend( | 3215 client_config.SetInitialStreamFlowControlWindowToSend( |
3216 kInitialStreamFlowControlWindowForTest); | 3216 kInitialStreamFlowControlWindowForTest); |
3217 client_config.SetInitialSessionFlowControlWindowToSend( | 3217 client_config.SetInitialSessionFlowControlWindowToSend( |
3218 kInitialSessionFlowControlWindowForTest); | 3218 kInitialSessionFlowControlWindowForTest); |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3277 EXPECT_EQ(1u, connection_.NumQueuedPackets()); | 3277 EXPECT_EQ(1u, connection_.NumQueuedPackets()); |
3278 } | 3278 } |
3279 | 3279 |
3280 TEST_P(QuicConnectionTest, TestQueueLimitsOnSendStreamData) { | 3280 TEST_P(QuicConnectionTest, TestQueueLimitsOnSendStreamData) { |
3281 // All packets carry version info till version is negotiated. | 3281 // All packets carry version info till version is negotiated. |
3282 size_t payload_length; | 3282 size_t payload_length; |
3283 size_t length = GetPacketLengthForOneStream( | 3283 size_t length = GetPacketLengthForOneStream( |
3284 connection_.version(), kIncludeVersion, | 3284 connection_.version(), kIncludeVersion, |
3285 PACKET_8BYTE_CONNECTION_ID, PACKET_1BYTE_SEQUENCE_NUMBER, | 3285 PACKET_8BYTE_CONNECTION_ID, PACKET_1BYTE_SEQUENCE_NUMBER, |
3286 NOT_IN_FEC_GROUP, &payload_length); | 3286 NOT_IN_FEC_GROUP, &payload_length); |
3287 creator_->set_max_packet_length(length); | 3287 creator_->SetMaxPacketLength(length); |
3288 | 3288 |
3289 // Queue the first packet. | 3289 // Queue the first packet. |
3290 EXPECT_CALL(*send_algorithm_, | 3290 EXPECT_CALL(*send_algorithm_, |
3291 TimeUntilSend(_, _, _)).WillOnce( | 3291 TimeUntilSend(_, _, _)).WillOnce( |
3292 testing::Return(QuicTime::Delta::FromMicroseconds(10))); | 3292 testing::Return(QuicTime::Delta::FromMicroseconds(10))); |
3293 const string payload(payload_length, 'a'); | 3293 const string payload(payload_length, 'a'); |
3294 EXPECT_EQ(0u, connection_.SendStreamDataWithString(3, payload, 0, !kFin, | 3294 EXPECT_EQ(0u, connection_.SendStreamDataWithString(3, payload, 0, !kFin, |
3295 nullptr).bytes_consumed); | 3295 nullptr).bytes_consumed); |
3296 EXPECT_EQ(0u, connection_.NumQueuedPackets()); | 3296 EXPECT_EQ(0u, connection_.NumQueuedPackets()); |
3297 } | 3297 } |
3298 | 3298 |
3299 TEST_P(QuicConnectionTest, LoopThroughSendingPackets) { | 3299 TEST_P(QuicConnectionTest, LoopThroughSendingPackets) { |
3300 // All packets carry version info till version is negotiated. | 3300 // All packets carry version info till version is negotiated. |
3301 size_t payload_length; | 3301 size_t payload_length; |
3302 // GetPacketLengthForOneStream() assumes a stream offset of 0 in determining | 3302 // GetPacketLengthForOneStream() assumes a stream offset of 0 in determining |
3303 // packet length. The size of the offset field in a stream frame is 0 for | 3303 // packet length. The size of the offset field in a stream frame is 0 for |
3304 // offset 0, and 2 for non-zero offsets up through 16K. Increase | 3304 // offset 0, and 2 for non-zero offsets up through 16K. Increase |
3305 // max_packet_length by 2 so that subsequent packets containing subsequent | 3305 // max_packet_length by 2 so that subsequent packets containing subsequent |
3306 // stream frames with non-zero offets will fit within the packet length. | 3306 // stream frames with non-zero offets will fit within the packet length. |
3307 size_t length = 2 + GetPacketLengthForOneStream( | 3307 size_t length = 2 + GetPacketLengthForOneStream( |
3308 connection_.version(), kIncludeVersion, | 3308 connection_.version(), kIncludeVersion, |
3309 PACKET_8BYTE_CONNECTION_ID, PACKET_1BYTE_SEQUENCE_NUMBER, | 3309 PACKET_8BYTE_CONNECTION_ID, PACKET_1BYTE_SEQUENCE_NUMBER, |
3310 NOT_IN_FEC_GROUP, &payload_length); | 3310 NOT_IN_FEC_GROUP, &payload_length); |
3311 creator_->set_max_packet_length(length); | 3311 creator_->SetMaxPacketLength(length); |
3312 | 3312 |
3313 // Queue the first packet. | 3313 // Queue the first packet. |
3314 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(7); | 3314 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(7); |
3315 // The first stream frame will have 2 fewer overhead bytes than the other six. | 3315 // The first stream frame will have 2 fewer overhead bytes than the other six. |
3316 const string payload(payload_length * 7 + 2, 'a'); | 3316 const string payload(payload_length * 7 + 2, 'a'); |
3317 EXPECT_EQ(payload.size(), | 3317 EXPECT_EQ(payload.size(), |
3318 connection_.SendStreamDataWithString(1, payload, 0, !kFin, nullptr) | 3318 connection_.SendStreamDataWithString(1, payload, 0, !kFin, nullptr) |
3319 .bytes_consumed); | 3319 .bytes_consumed); |
3320 } | 3320 } |
3321 | 3321 |
3322 TEST_P(QuicConnectionTest, LoopThroughSendingPacketsWithTruncation) { | 3322 TEST_P(QuicConnectionTest, LoopThroughSendingPacketsWithTruncation) { |
3323 // Set up a larger payload than will fit in one packet. | 3323 // Set up a larger payload than will fit in one packet. |
3324 const string payload(connection_.max_packet_length(), 'a'); | 3324 const string payload(connection_.max_packet_length(), 'a'); |
3325 EXPECT_CALL(*send_algorithm_, SetFromConfig(_, _, _)).Times(AnyNumber()); | 3325 EXPECT_CALL(*send_algorithm_, SetFromConfig(_, _)).Times(AnyNumber()); |
3326 | 3326 |
3327 // Now send some packets with no truncation. | 3327 // Now send some packets with no truncation. |
3328 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(2); | 3328 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(2); |
3329 EXPECT_EQ(payload.size(), | 3329 EXPECT_EQ(payload.size(), |
3330 connection_.SendStreamDataWithString( | 3330 connection_.SendStreamDataWithString( |
3331 3, payload, 0, !kFin, nullptr).bytes_consumed); | 3331 3, payload, 0, !kFin, nullptr).bytes_consumed); |
3332 // Track the size of the second packet here. The overhead will be the largest | 3332 // Track the size of the second packet here. The overhead will be the largest |
3333 // we see in this test, due to the non-truncated connection id. | 3333 // we see in this test, due to the non-truncated connection id. |
3334 size_t non_truncated_packet_size = writer_->last_packet_size(); | 3334 size_t non_truncated_packet_size = writer_->last_packet_size(); |
3335 | 3335 |
(...skipping 329 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3665 TEST_P(QuicConnectionTest, UpdateEntropyForReceivedPackets) { | 3665 TEST_P(QuicConnectionTest, UpdateEntropyForReceivedPackets) { |
3666 EXPECT_CALL(visitor_, OnStreamFrames(_)).Times(AtLeast(1)); | 3666 EXPECT_CALL(visitor_, OnStreamFrames(_)).Times(AtLeast(1)); |
3667 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); | 3667 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); |
3668 ProcessDataPacket(1, 1, kEntropyFlag); | 3668 ProcessDataPacket(1, 1, kEntropyFlag); |
3669 ProcessDataPacket(5, 1, kEntropyFlag); | 3669 ProcessDataPacket(5, 1, kEntropyFlag); |
3670 ProcessDataPacket(4, 1, !kEntropyFlag); | 3670 ProcessDataPacket(4, 1, !kEntropyFlag); |
3671 EXPECT_EQ(34u, outgoing_ack()->entropy_hash); | 3671 EXPECT_EQ(34u, outgoing_ack()->entropy_hash); |
3672 // Make 4th packet my least unacked, and update entropy for 2, 3 packets. | 3672 // Make 4th packet my least unacked, and update entropy for 2, 3 packets. |
3673 QuicPacketCreatorPeer::SetSequenceNumber(&peer_creator_, 5); | 3673 QuicPacketCreatorPeer::SetSequenceNumber(&peer_creator_, 5); |
3674 QuicPacketEntropyHash six_packet_entropy_hash = 0; | 3674 QuicPacketEntropyHash six_packet_entropy_hash = 0; |
3675 QuicPacketEntropyHash kRandomEntropyHash = 129u; | 3675 QuicPacketEntropyHash random_entropy_hash = 129u; |
3676 QuicStopWaitingFrame frame = InitStopWaitingFrame(4); | 3676 QuicStopWaitingFrame frame = InitStopWaitingFrame(4); |
3677 frame.entropy_hash = kRandomEntropyHash; | 3677 frame.entropy_hash = random_entropy_hash; |
3678 if (ProcessStopWaitingPacket(&frame)) { | 3678 if (ProcessStopWaitingPacket(&frame)) { |
3679 six_packet_entropy_hash = 1 << 6; | 3679 six_packet_entropy_hash = 1 << 6; |
3680 } | 3680 } |
3681 | 3681 |
3682 EXPECT_EQ((kRandomEntropyHash + (1 << 5) + six_packet_entropy_hash), | 3682 EXPECT_EQ((random_entropy_hash + (1 << 5) + six_packet_entropy_hash), |
3683 outgoing_ack()->entropy_hash); | 3683 outgoing_ack()->entropy_hash); |
3684 } | 3684 } |
3685 | 3685 |
3686 TEST_P(QuicConnectionTest, UpdateEntropyHashUptoCurrentPacket) { | 3686 TEST_P(QuicConnectionTest, UpdateEntropyHashUptoCurrentPacket) { |
3687 EXPECT_CALL(visitor_, OnStreamFrames(_)).Times(AtLeast(1)); | 3687 EXPECT_CALL(visitor_, OnStreamFrames(_)).Times(AtLeast(1)); |
3688 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); | 3688 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); |
3689 ProcessDataPacket(1, 1, kEntropyFlag); | 3689 ProcessDataPacket(1, 1, kEntropyFlag); |
3690 ProcessDataPacket(5, 1, !kEntropyFlag); | 3690 ProcessDataPacket(5, 1, !kEntropyFlag); |
3691 ProcessDataPacket(22, 1, kEntropyFlag); | 3691 ProcessDataPacket(22, 1, kEntropyFlag); |
3692 EXPECT_EQ(66u, outgoing_ack()->entropy_hash); | 3692 EXPECT_EQ(66u, outgoing_ack()->entropy_hash); |
3693 QuicPacketCreatorPeer::SetSequenceNumber(&peer_creator_, 22); | 3693 QuicPacketCreatorPeer::SetSequenceNumber(&peer_creator_, 22); |
3694 QuicPacketEntropyHash kRandomEntropyHash = 85u; | 3694 QuicPacketEntropyHash random_entropy_hash = 85u; |
3695 // Current packet is the least unacked packet. | 3695 // Current packet is the least unacked packet. |
3696 QuicPacketEntropyHash ack_entropy_hash; | 3696 QuicPacketEntropyHash ack_entropy_hash; |
3697 QuicStopWaitingFrame frame = InitStopWaitingFrame(23); | 3697 QuicStopWaitingFrame frame = InitStopWaitingFrame(23); |
3698 frame.entropy_hash = kRandomEntropyHash; | 3698 frame.entropy_hash = random_entropy_hash; |
3699 ack_entropy_hash = ProcessStopWaitingPacket(&frame); | 3699 ack_entropy_hash = ProcessStopWaitingPacket(&frame); |
3700 EXPECT_EQ((kRandomEntropyHash + ack_entropy_hash), | 3700 EXPECT_EQ((random_entropy_hash + ack_entropy_hash), |
3701 outgoing_ack()->entropy_hash); | 3701 outgoing_ack()->entropy_hash); |
3702 ProcessDataPacket(25, 1, kEntropyFlag); | 3702 ProcessDataPacket(25, 1, kEntropyFlag); |
3703 EXPECT_EQ((kRandomEntropyHash + ack_entropy_hash + (1 << (25 % 8))), | 3703 EXPECT_EQ((random_entropy_hash + ack_entropy_hash + (1 << (25 % 8))), |
3704 outgoing_ack()->entropy_hash); | 3704 outgoing_ack()->entropy_hash); |
3705 } | 3705 } |
3706 | 3706 |
3707 TEST_P(QuicConnectionTest, EntropyCalculationForTruncatedAck) { | 3707 TEST_P(QuicConnectionTest, EntropyCalculationForTruncatedAck) { |
3708 EXPECT_CALL(visitor_, OnStreamFrames(_)).Times(AtLeast(1)); | 3708 EXPECT_CALL(visitor_, OnStreamFrames(_)).Times(AtLeast(1)); |
3709 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); | 3709 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); |
3710 QuicPacketEntropyHash entropy[51]; | 3710 QuicPacketEntropyHash entropy[51]; |
3711 entropy[0] = 0; | 3711 entropy[0] = 0; |
3712 for (int i = 1; i < 51; ++i) { | 3712 for (int i = 1; i < 51; ++i) { |
3713 bool should_send = i % 10 != 1; | 3713 bool should_send = i % 10 != 1; |
(...skipping 613 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4327 | 4327 |
4328 TEST_P(QuicConnectionTest, NetworkChangeVisitorConfigCallbackChangesFecState) { | 4328 TEST_P(QuicConnectionTest, NetworkChangeVisitorConfigCallbackChangesFecState) { |
4329 QuicSentPacketManager::NetworkChangeVisitor* visitor = | 4329 QuicSentPacketManager::NetworkChangeVisitor* visitor = |
4330 QuicSentPacketManagerPeer::GetNetworkChangeVisitor(manager_); | 4330 QuicSentPacketManagerPeer::GetNetworkChangeVisitor(manager_); |
4331 EXPECT_TRUE(visitor); | 4331 EXPECT_TRUE(visitor); |
4332 EXPECT_EQ(QuicTime::Delta::Zero(), | 4332 EXPECT_EQ(QuicTime::Delta::Zero(), |
4333 QuicPacketGeneratorPeer::GetFecTimeout(generator_)); | 4333 QuicPacketGeneratorPeer::GetFecTimeout(generator_)); |
4334 | 4334 |
4335 // Verify that sending a config with a new initial rtt changes fec timeout. | 4335 // Verify that sending a config with a new initial rtt changes fec timeout. |
4336 // Create and process a config with a non-zero initial RTT. | 4336 // Create and process a config with a non-zero initial RTT. |
4337 EXPECT_CALL(*send_algorithm_, SetFromConfig(_, _, _)); | 4337 EXPECT_CALL(*send_algorithm_, SetFromConfig(_, _)); |
4338 QuicConfig config; | 4338 QuicConfig config; |
4339 config.SetInitialRoundTripTimeUsToSend(300000); | 4339 config.SetInitialRoundTripTimeUsToSend(300000); |
4340 connection_.SetFromConfig(config); | 4340 connection_.SetFromConfig(config); |
4341 EXPECT_LT(QuicTime::Delta::Zero(), | 4341 EXPECT_LT(QuicTime::Delta::Zero(), |
4342 QuicPacketGeneratorPeer::GetFecTimeout(generator_)); | 4342 QuicPacketGeneratorPeer::GetFecTimeout(generator_)); |
4343 } | 4343 } |
4344 | 4344 |
4345 TEST_P(QuicConnectionTest, NetworkChangeVisitorRttCallbackChangesFecState) { | 4345 TEST_P(QuicConnectionTest, NetworkChangeVisitorRttCallbackChangesFecState) { |
4346 // Verify that sending a config with a new initial rtt changes fec timeout. | 4346 // Verify that sending a config with a new initial rtt changes fec timeout. |
4347 QuicSentPacketManager::NetworkChangeVisitor* visitor = | 4347 QuicSentPacketManager::NetworkChangeVisitor* visitor = |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4407 // Regression test for b/18594622 | 4407 // Regression test for b/18594622 |
4408 scoped_refptr<MockAckNotifierDelegate> delegate(new MockAckNotifierDelegate); | 4408 scoped_refptr<MockAckNotifierDelegate> delegate(new MockAckNotifierDelegate); |
4409 EXPECT_DFATAL( | 4409 EXPECT_DFATAL( |
4410 connection_.SendStreamDataWithString(3, "", 0, !kFin, delegate.get()), | 4410 connection_.SendStreamDataWithString(3, "", 0, !kFin, delegate.get()), |
4411 "Attempt to send empty stream frame"); | 4411 "Attempt to send empty stream frame"); |
4412 } | 4412 } |
4413 | 4413 |
4414 } // namespace | 4414 } // namespace |
4415 } // namespace test | 4415 } // namespace test |
4416 } // namespace net | 4416 } // namespace net |
OLD | NEW |