| 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/core/quic_connection.h" | 5 #include "net/quic/core/quic_connection.h" |
| 6 | 6 |
| 7 #include <errno.h> | 7 #include <errno.h> |
| 8 #include <memory> | 8 #include <memory> |
| 9 #include <ostream> | 9 #include <ostream> |
| 10 #include <utility> | 10 #include <utility> |
| (...skipping 565 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 576 | 576 |
| 577 // Enable path MTU discovery. Assumes that the test is performed from the | 577 // Enable path MTU discovery. Assumes that the test is performed from the |
| 578 // client perspective and the higher value of MTU target is used. | 578 // client perspective and the higher value of MTU target is used. |
| 579 void EnablePathMtuDiscovery(MockSendAlgorithm* send_algorithm) { | 579 void EnablePathMtuDiscovery(MockSendAlgorithm* send_algorithm) { |
| 580 ASSERT_EQ(Perspective::IS_CLIENT, perspective()); | 580 ASSERT_EQ(Perspective::IS_CLIENT, perspective()); |
| 581 | 581 |
| 582 QuicConfig config; | 582 QuicConfig config; |
| 583 QuicTagVector connection_options; | 583 QuicTagVector connection_options; |
| 584 connection_options.push_back(kMTUH); | 584 connection_options.push_back(kMTUH); |
| 585 config.SetConnectionOptionsToSend(connection_options); | 585 config.SetConnectionOptionsToSend(connection_options); |
| 586 EXPECT_CALL(*send_algorithm, GetCongestionControlType()); |
| 586 EXPECT_CALL(*send_algorithm, SetFromConfig(_, _)); | 587 EXPECT_CALL(*send_algorithm, SetFromConfig(_, _)); |
| 587 SetFromConfig(config); | 588 SetFromConfig(config); |
| 588 | 589 |
| 589 // Normally, the pacing would be disabled in the test, but calling | 590 // Normally, the pacing would be disabled in the test, but calling |
| 590 // SetFromConfig enables it. Set nearly-infinite bandwidth to make the | 591 // SetFromConfig enables it. Set nearly-infinite bandwidth to make the |
| 591 // pacing algorithm work. | 592 // pacing algorithm work. |
| 592 EXPECT_CALL(*send_algorithm, PacingRate(_)) | 593 EXPECT_CALL(*send_algorithm, PacingRate(_)) |
| 593 .WillRepeatedly(Return(QuicBandwidth::Infinite())); | 594 .WillRepeatedly(Return(QuicBandwidth::Infinite())); |
| 594 } | 595 } |
| 595 | 596 |
| (...skipping 2092 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2688 connection_.SetDefaultEncryptionLevel(ENCRYPTION_INITIAL); | 2689 connection_.SetDefaultEncryptionLevel(ENCRYPTION_INITIAL); |
| 2689 | 2690 |
| 2690 SendStreamDataToPeer(2, "bar", 0, NO_FIN, nullptr); | 2691 SendStreamDataToPeer(2, "bar", 0, NO_FIN, nullptr); |
| 2691 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(1); | 2692 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(1); |
| 2692 | 2693 |
| 2693 connection_.RetransmitUnackedPackets(ALL_INITIAL_RETRANSMISSION); | 2694 connection_.RetransmitUnackedPackets(ALL_INITIAL_RETRANSMISSION); |
| 2694 } | 2695 } |
| 2695 | 2696 |
| 2696 TEST_P(QuicConnectionTest, BufferNonDecryptablePackets) { | 2697 TEST_P(QuicConnectionTest, BufferNonDecryptablePackets) { |
| 2697 // SetFromConfig is always called after construction from InitializeSession. | 2698 // SetFromConfig is always called after construction from InitializeSession. |
| 2699 EXPECT_CALL(*send_algorithm_, GetCongestionControlType()); |
| 2698 EXPECT_CALL(*send_algorithm_, SetFromConfig(_, _)); | 2700 EXPECT_CALL(*send_algorithm_, SetFromConfig(_, _)); |
| 2699 QuicConfig config; | 2701 QuicConfig config; |
| 2700 connection_.SetFromConfig(config); | 2702 connection_.SetFromConfig(config); |
| 2701 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); | 2703 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); |
| 2702 use_tagging_decrypter(); | 2704 use_tagging_decrypter(); |
| 2703 | 2705 |
| 2704 const uint8_t tag = 0x07; | 2706 const uint8_t tag = 0x07; |
| 2705 peer_framer_.SetEncrypter(ENCRYPTION_INITIAL, new TaggingEncrypter(tag)); | 2707 peer_framer_.SetEncrypter(ENCRYPTION_INITIAL, new TaggingEncrypter(tag)); |
| 2706 | 2708 |
| 2707 // Process an encrypted packet which can not yet be decrypted which should | 2709 // Process an encrypted packet which can not yet be decrypted which should |
| 2708 // result in the packet being buffered. | 2710 // result in the packet being buffered. |
| 2709 ProcessDataPacketAtLevel(1, !kHasStopWaiting, ENCRYPTION_INITIAL); | 2711 ProcessDataPacketAtLevel(1, !kHasStopWaiting, ENCRYPTION_INITIAL); |
| 2710 | 2712 |
| 2711 // Transition to the new encryption state and process another encrypted packet | 2713 // Transition to the new encryption state and process another encrypted packet |
| 2712 // which should result in the original packet being processed. | 2714 // which should result in the original packet being processed. |
| 2713 connection_.SetDecrypter(ENCRYPTION_INITIAL, new StrictTaggingDecrypter(tag)); | 2715 connection_.SetDecrypter(ENCRYPTION_INITIAL, new StrictTaggingDecrypter(tag)); |
| 2714 connection_.SetDefaultEncryptionLevel(ENCRYPTION_INITIAL); | 2716 connection_.SetDefaultEncryptionLevel(ENCRYPTION_INITIAL); |
| 2715 connection_.SetEncrypter(ENCRYPTION_INITIAL, new TaggingEncrypter(tag)); | 2717 connection_.SetEncrypter(ENCRYPTION_INITIAL, new TaggingEncrypter(tag)); |
| 2716 EXPECT_CALL(visitor_, OnStreamFrame(_)).Times(2); | 2718 EXPECT_CALL(visitor_, OnStreamFrame(_)).Times(2); |
| 2717 ProcessDataPacketAtLevel(2, !kHasStopWaiting, ENCRYPTION_INITIAL); | 2719 ProcessDataPacketAtLevel(2, !kHasStopWaiting, ENCRYPTION_INITIAL); |
| 2718 | 2720 |
| 2719 // Finally, process a third packet and note that we do not reprocess the | 2721 // Finally, process a third packet and note that we do not reprocess the |
| 2720 // buffered packet. | 2722 // buffered packet. |
| 2721 EXPECT_CALL(visitor_, OnStreamFrame(_)).Times(1); | 2723 EXPECT_CALL(visitor_, OnStreamFrame(_)).Times(1); |
| 2722 ProcessDataPacketAtLevel(3, !kHasStopWaiting, ENCRYPTION_INITIAL); | 2724 ProcessDataPacketAtLevel(3, !kHasStopWaiting, ENCRYPTION_INITIAL); |
| 2723 } | 2725 } |
| 2724 | 2726 |
| 2725 TEST_P(QuicConnectionTest, Buffer100NonDecryptablePackets) { | 2727 TEST_P(QuicConnectionTest, Buffer100NonDecryptablePackets) { |
| 2726 // SetFromConfig is always called after construction from InitializeSession. | 2728 // SetFromConfig is always called after construction from InitializeSession. |
| 2729 EXPECT_CALL(*send_algorithm_, GetCongestionControlType()); |
| 2727 EXPECT_CALL(*send_algorithm_, SetFromConfig(_, _)); | 2730 EXPECT_CALL(*send_algorithm_, SetFromConfig(_, _)); |
| 2728 QuicConfig config; | 2731 QuicConfig config; |
| 2729 config.set_max_undecryptable_packets(100); | 2732 config.set_max_undecryptable_packets(100); |
| 2730 connection_.SetFromConfig(config); | 2733 connection_.SetFromConfig(config); |
| 2731 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); | 2734 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); |
| 2732 use_tagging_decrypter(); | 2735 use_tagging_decrypter(); |
| 2733 | 2736 |
| 2734 const uint8_t tag = 0x07; | 2737 const uint8_t tag = 0x07; |
| 2735 peer_framer_.SetEncrypter(ENCRYPTION_INITIAL, new TaggingEncrypter(tag)); | 2738 peer_framer_.SetEncrypter(ENCRYPTION_INITIAL, new TaggingEncrypter(tag)); |
| 2736 | 2739 |
| (...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2855 connection_.OnCanWrite(); | 2858 connection_.OnCanWrite(); |
| 2856 EXPECT_EQ(0u, connection_.NumQueuedPackets()); | 2859 EXPECT_EQ(0u, connection_.NumQueuedPackets()); |
| 2857 } | 2860 } |
| 2858 | 2861 |
| 2859 TEST_P(QuicConnectionTest, InitialTimeout) { | 2862 TEST_P(QuicConnectionTest, InitialTimeout) { |
| 2860 EXPECT_TRUE(connection_.connected()); | 2863 EXPECT_TRUE(connection_.connected()); |
| 2861 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(AnyNumber()); | 2864 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(AnyNumber()); |
| 2862 EXPECT_FALSE(connection_.GetTimeoutAlarm()->IsSet()); | 2865 EXPECT_FALSE(connection_.GetTimeoutAlarm()->IsSet()); |
| 2863 | 2866 |
| 2864 // SetFromConfig sets the initial timeouts before negotiation. | 2867 // SetFromConfig sets the initial timeouts before negotiation. |
| 2868 EXPECT_CALL(*send_algorithm_, GetCongestionControlType()); |
| 2865 EXPECT_CALL(*send_algorithm_, SetFromConfig(_, _)); | 2869 EXPECT_CALL(*send_algorithm_, SetFromConfig(_, _)); |
| 2866 QuicConfig config; | 2870 QuicConfig config; |
| 2867 connection_.SetFromConfig(config); | 2871 connection_.SetFromConfig(config); |
| 2868 // Subtract a second from the idle timeout on the client side. | 2872 // Subtract a second from the idle timeout on the client side. |
| 2869 QuicTime default_timeout = | 2873 QuicTime default_timeout = |
| 2870 clock_.ApproximateNow() + | 2874 clock_.ApproximateNow() + |
| 2871 QuicTime::Delta::FromSeconds(kInitialIdleTimeoutSecs - 1); | 2875 QuicTime::Delta::FromSeconds(kInitialIdleTimeoutSecs - 1); |
| 2872 EXPECT_EQ(default_timeout, connection_.GetTimeoutAlarm()->deadline()); | 2876 EXPECT_EQ(default_timeout, connection_.GetTimeoutAlarm()->deadline()); |
| 2873 | 2877 |
| 2874 EXPECT_CALL(visitor_, OnConnectionClosed(QUIC_NETWORK_IDLE_TIMEOUT, _, | 2878 EXPECT_CALL(visitor_, OnConnectionClosed(QUIC_NETWORK_IDLE_TIMEOUT, _, |
| (...skipping 416 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3291 EXPECT_TRUE(connection_.GetMtuDiscoveryAlarm()->IsSet()); | 3295 EXPECT_TRUE(connection_.GetMtuDiscoveryAlarm()->IsSet()); |
| 3292 | 3296 |
| 3293 EXPECT_CALL(visitor_, OnConnectionClosed(_, _, _)); | 3297 EXPECT_CALL(visitor_, OnConnectionClosed(_, _, _)); |
| 3294 connection_.CloseConnection(QUIC_PEER_GOING_AWAY, "no reason", | 3298 connection_.CloseConnection(QUIC_PEER_GOING_AWAY, "no reason", |
| 3295 ConnectionCloseBehavior::SILENT_CLOSE); | 3299 ConnectionCloseBehavior::SILENT_CLOSE); |
| 3296 EXPECT_FALSE(connection_.GetMtuDiscoveryAlarm()->IsSet()); | 3300 EXPECT_FALSE(connection_.GetMtuDiscoveryAlarm()->IsSet()); |
| 3297 } | 3301 } |
| 3298 | 3302 |
| 3299 TEST_P(QuicConnectionTest, TimeoutAfterSend) { | 3303 TEST_P(QuicConnectionTest, TimeoutAfterSend) { |
| 3300 EXPECT_TRUE(connection_.connected()); | 3304 EXPECT_TRUE(connection_.connected()); |
| 3305 EXPECT_CALL(*send_algorithm_, GetCongestionControlType()); |
| 3301 EXPECT_CALL(*send_algorithm_, SetFromConfig(_, _)); | 3306 EXPECT_CALL(*send_algorithm_, SetFromConfig(_, _)); |
| 3302 QuicConfig config; | 3307 QuicConfig config; |
| 3303 connection_.SetFromConfig(config); | 3308 connection_.SetFromConfig(config); |
| 3304 EXPECT_FALSE(QuicConnectionPeer::IsSilentCloseEnabled(&connection_)); | 3309 EXPECT_FALSE(QuicConnectionPeer::IsSilentCloseEnabled(&connection_)); |
| 3305 | 3310 |
| 3306 const QuicTime::Delta initial_idle_timeout = | 3311 const QuicTime::Delta initial_idle_timeout = |
| 3307 QuicTime::Delta::FromSeconds(kInitialIdleTimeoutSecs - 1); | 3312 QuicTime::Delta::FromSeconds(kInitialIdleTimeoutSecs - 1); |
| 3308 const QuicTime::Delta five_ms = QuicTime::Delta::FromMilliseconds(5); | 3313 const QuicTime::Delta five_ms = QuicTime::Delta::FromMilliseconds(5); |
| 3309 QuicTime default_timeout = clock_.ApproximateNow() + initial_idle_timeout; | 3314 QuicTime default_timeout = clock_.ApproximateNow() + initial_idle_timeout; |
| 3310 | 3315 |
| (...skipping 26 matching lines...) Expand all Loading... |
| 3337 clock_.AdvanceTime(five_ms); | 3342 clock_.AdvanceTime(five_ms); |
| 3338 EXPECT_EQ(default_timeout + five_ms, clock_.ApproximateNow()); | 3343 EXPECT_EQ(default_timeout + five_ms, clock_.ApproximateNow()); |
| 3339 connection_.GetTimeoutAlarm()->Fire(); | 3344 connection_.GetTimeoutAlarm()->Fire(); |
| 3340 EXPECT_FALSE(connection_.GetTimeoutAlarm()->IsSet()); | 3345 EXPECT_FALSE(connection_.GetTimeoutAlarm()->IsSet()); |
| 3341 EXPECT_FALSE(connection_.connected()); | 3346 EXPECT_FALSE(connection_.connected()); |
| 3342 } | 3347 } |
| 3343 | 3348 |
| 3344 TEST_P(QuicConnectionTest, TimeoutAfterRetransmission) { | 3349 TEST_P(QuicConnectionTest, TimeoutAfterRetransmission) { |
| 3345 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); | 3350 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); |
| 3346 EXPECT_TRUE(connection_.connected()); | 3351 EXPECT_TRUE(connection_.connected()); |
| 3352 EXPECT_CALL(*send_algorithm_, GetCongestionControlType()); |
| 3347 EXPECT_CALL(*send_algorithm_, SetFromConfig(_, _)); | 3353 EXPECT_CALL(*send_algorithm_, SetFromConfig(_, _)); |
| 3348 QuicConfig config; | 3354 QuicConfig config; |
| 3349 connection_.SetFromConfig(config); | 3355 connection_.SetFromConfig(config); |
| 3350 EXPECT_FALSE(QuicConnectionPeer::IsSilentCloseEnabled(&connection_)); | 3356 EXPECT_FALSE(QuicConnectionPeer::IsSilentCloseEnabled(&connection_)); |
| 3351 | 3357 |
| 3352 const QuicTime start_time = clock_.Now(); | 3358 const QuicTime start_time = clock_.Now(); |
| 3353 const QuicTime::Delta initial_idle_timeout = | 3359 const QuicTime::Delta initial_idle_timeout = |
| 3354 QuicTime::Delta::FromSeconds(kInitialIdleTimeoutSecs - 1); | 3360 QuicTime::Delta::FromSeconds(kInitialIdleTimeoutSecs - 1); |
| 3355 QuicTime default_timeout = clock_.Now() + initial_idle_timeout; | 3361 QuicTime default_timeout = clock_.Now() + initial_idle_timeout; |
| 3356 | 3362 |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3411 EXPECT_EQ(final_timeout, clock_.Now()); | 3417 EXPECT_EQ(final_timeout, clock_.Now()); |
| 3412 connection_.GetTimeoutAlarm()->Fire(); | 3418 connection_.GetTimeoutAlarm()->Fire(); |
| 3413 EXPECT_FALSE(connection_.GetTimeoutAlarm()->IsSet()); | 3419 EXPECT_FALSE(connection_.GetTimeoutAlarm()->IsSet()); |
| 3414 EXPECT_FALSE(connection_.connected()); | 3420 EXPECT_FALSE(connection_.connected()); |
| 3415 } | 3421 } |
| 3416 | 3422 |
| 3417 TEST_P(QuicConnectionTest, NewTimeoutAfterSendSilentClose) { | 3423 TEST_P(QuicConnectionTest, NewTimeoutAfterSendSilentClose) { |
| 3418 // Same test as above, but complete a handshake which enables silent close, | 3424 // Same test as above, but complete a handshake which enables silent close, |
| 3419 // causing no connection close packet to be sent. | 3425 // causing no connection close packet to be sent. |
| 3420 EXPECT_TRUE(connection_.connected()); | 3426 EXPECT_TRUE(connection_.connected()); |
| 3427 EXPECT_CALL(*send_algorithm_, GetCongestionControlType()); |
| 3421 EXPECT_CALL(*send_algorithm_, SetFromConfig(_, _)); | 3428 EXPECT_CALL(*send_algorithm_, SetFromConfig(_, _)); |
| 3422 QuicConfig config; | 3429 QuicConfig config; |
| 3423 | 3430 |
| 3424 // Create a handshake message that also enables silent close. | 3431 // Create a handshake message that also enables silent close. |
| 3425 CryptoHandshakeMessage msg; | 3432 CryptoHandshakeMessage msg; |
| 3426 string error_details; | 3433 string error_details; |
| 3427 QuicConfig client_config; | 3434 QuicConfig client_config; |
| 3428 client_config.SetInitialStreamFlowControlWindowToSend( | 3435 client_config.SetInitialStreamFlowControlWindowToSend( |
| 3429 kInitialStreamFlowControlWindowForTest); | 3436 kInitialStreamFlowControlWindowForTest); |
| 3430 client_config.SetInitialSessionFlowControlWindowToSend( | 3437 client_config.SetInitialSessionFlowControlWindowToSend( |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3473 clock_.AdvanceTime(five_ms); | 3480 clock_.AdvanceTime(five_ms); |
| 3474 EXPECT_EQ(default_timeout + five_ms, clock_.ApproximateNow()); | 3481 EXPECT_EQ(default_timeout + five_ms, clock_.ApproximateNow()); |
| 3475 connection_.GetTimeoutAlarm()->Fire(); | 3482 connection_.GetTimeoutAlarm()->Fire(); |
| 3476 EXPECT_FALSE(connection_.GetTimeoutAlarm()->IsSet()); | 3483 EXPECT_FALSE(connection_.GetTimeoutAlarm()->IsSet()); |
| 3477 EXPECT_FALSE(connection_.connected()); | 3484 EXPECT_FALSE(connection_.connected()); |
| 3478 } | 3485 } |
| 3479 | 3486 |
| 3480 TEST_P(QuicConnectionTest, TimeoutAfterReceive) { | 3487 TEST_P(QuicConnectionTest, TimeoutAfterReceive) { |
| 3481 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); | 3488 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); |
| 3482 EXPECT_TRUE(connection_.connected()); | 3489 EXPECT_TRUE(connection_.connected()); |
| 3490 EXPECT_CALL(*send_algorithm_, GetCongestionControlType()); |
| 3483 EXPECT_CALL(*send_algorithm_, SetFromConfig(_, _)); | 3491 EXPECT_CALL(*send_algorithm_, SetFromConfig(_, _)); |
| 3484 QuicConfig config; | 3492 QuicConfig config; |
| 3485 connection_.SetFromConfig(config); | 3493 connection_.SetFromConfig(config); |
| 3486 EXPECT_FALSE(QuicConnectionPeer::IsSilentCloseEnabled(&connection_)); | 3494 EXPECT_FALSE(QuicConnectionPeer::IsSilentCloseEnabled(&connection_)); |
| 3487 | 3495 |
| 3488 const QuicTime::Delta initial_idle_timeout = | 3496 const QuicTime::Delta initial_idle_timeout = |
| 3489 QuicTime::Delta::FromSeconds(kInitialIdleTimeoutSecs - 1); | 3497 QuicTime::Delta::FromSeconds(kInitialIdleTimeoutSecs - 1); |
| 3490 const QuicTime::Delta five_ms = QuicTime::Delta::FromMilliseconds(5); | 3498 const QuicTime::Delta five_ms = QuicTime::Delta::FromMilliseconds(5); |
| 3491 QuicTime default_timeout = clock_.ApproximateNow() + initial_idle_timeout; | 3499 QuicTime default_timeout = clock_.ApproximateNow() + initial_idle_timeout; |
| 3492 | 3500 |
| (...skipping 28 matching lines...) Expand all Loading... |
| 3521 clock_.AdvanceTime(five_ms); | 3529 clock_.AdvanceTime(five_ms); |
| 3522 EXPECT_EQ(default_timeout + five_ms, clock_.ApproximateNow()); | 3530 EXPECT_EQ(default_timeout + five_ms, clock_.ApproximateNow()); |
| 3523 connection_.GetTimeoutAlarm()->Fire(); | 3531 connection_.GetTimeoutAlarm()->Fire(); |
| 3524 EXPECT_FALSE(connection_.GetTimeoutAlarm()->IsSet()); | 3532 EXPECT_FALSE(connection_.GetTimeoutAlarm()->IsSet()); |
| 3525 EXPECT_FALSE(connection_.connected()); | 3533 EXPECT_FALSE(connection_.connected()); |
| 3526 } | 3534 } |
| 3527 | 3535 |
| 3528 TEST_P(QuicConnectionTest, TimeoutAfterReceiveNotSendWhenUnacked) { | 3536 TEST_P(QuicConnectionTest, TimeoutAfterReceiveNotSendWhenUnacked) { |
| 3529 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); | 3537 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); |
| 3530 EXPECT_TRUE(connection_.connected()); | 3538 EXPECT_TRUE(connection_.connected()); |
| 3539 EXPECT_CALL(*send_algorithm_, GetCongestionControlType()); |
| 3531 EXPECT_CALL(*send_algorithm_, SetFromConfig(_, _)); | 3540 EXPECT_CALL(*send_algorithm_, SetFromConfig(_, _)); |
| 3532 QuicConfig config; | 3541 QuicConfig config; |
| 3533 connection_.SetFromConfig(config); | 3542 connection_.SetFromConfig(config); |
| 3534 EXPECT_FALSE(QuicConnectionPeer::IsSilentCloseEnabled(&connection_)); | 3543 EXPECT_FALSE(QuicConnectionPeer::IsSilentCloseEnabled(&connection_)); |
| 3535 | 3544 |
| 3536 const QuicTime::Delta initial_idle_timeout = | 3545 const QuicTime::Delta initial_idle_timeout = |
| 3537 QuicTime::Delta::FromSeconds(kInitialIdleTimeoutSecs - 1); | 3546 QuicTime::Delta::FromSeconds(kInitialIdleTimeoutSecs - 1); |
| 3538 connection_.SetNetworkTimeouts( | 3547 connection_.SetNetworkTimeouts( |
| 3539 QuicTime::Delta::Infinite(), | 3548 QuicTime::Delta::Infinite(), |
| 3540 initial_idle_timeout + QuicTime::Delta::FromSeconds(1)); | 3549 initial_idle_timeout + QuicTime::Delta::FromSeconds(1)); |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3580 connection_.GetTimeoutAlarm()->Fire(); | 3589 connection_.GetTimeoutAlarm()->Fire(); |
| 3581 clock_.AdvanceTime(QuicTime::Delta::FromSeconds(1)); | 3590 clock_.AdvanceTime(QuicTime::Delta::FromSeconds(1)); |
| 3582 } | 3591 } |
| 3583 EXPECT_FALSE(connection_.connected()); | 3592 EXPECT_FALSE(connection_.connected()); |
| 3584 EXPECT_FALSE(connection_.GetTimeoutAlarm()->IsSet()); | 3593 EXPECT_FALSE(connection_.GetTimeoutAlarm()->IsSet()); |
| 3585 } | 3594 } |
| 3586 | 3595 |
| 3587 TEST_P(QuicConnectionTest, TimeoutAfter5ClientRTOs) { | 3596 TEST_P(QuicConnectionTest, TimeoutAfter5ClientRTOs) { |
| 3588 connection_.SetMaxTailLossProbes(2); | 3597 connection_.SetMaxTailLossProbes(2); |
| 3589 EXPECT_TRUE(connection_.connected()); | 3598 EXPECT_TRUE(connection_.connected()); |
| 3599 EXPECT_CALL(*send_algorithm_, GetCongestionControlType()); |
| 3590 EXPECT_CALL(*send_algorithm_, SetFromConfig(_, _)); | 3600 EXPECT_CALL(*send_algorithm_, SetFromConfig(_, _)); |
| 3591 QuicConfig config; | 3601 QuicConfig config; |
| 3592 QuicTagVector connection_options; | 3602 QuicTagVector connection_options; |
| 3593 connection_options.push_back(k5RTO); | 3603 connection_options.push_back(k5RTO); |
| 3594 config.SetConnectionOptionsToSend(connection_options); | 3604 config.SetConnectionOptionsToSend(connection_options); |
| 3595 connection_.SetFromConfig(config); | 3605 connection_.SetFromConfig(config); |
| 3596 | 3606 |
| 3597 // Send stream data. | 3607 // Send stream data. |
| 3598 SendStreamDataToPeer(kClientDataStreamId1, "foo", 0, FIN, nullptr); | 3608 SendStreamDataToPeer(kClientDataStreamId1, "foo", 0, FIN, nullptr); |
| 3599 | 3609 |
| (...skipping 10 matching lines...) Expand all Loading... |
| 3610 EXPECT_EQ(4u, connection_.sent_packet_manager().GetConsecutiveRtoCount()); | 3620 EXPECT_EQ(4u, connection_.sent_packet_manager().GetConsecutiveRtoCount()); |
| 3611 // This time, we should time out. | 3621 // This time, we should time out. |
| 3612 EXPECT_CALL(visitor_, OnConnectionClosed(QUIC_TOO_MANY_RTOS, _, | 3622 EXPECT_CALL(visitor_, OnConnectionClosed(QUIC_TOO_MANY_RTOS, _, |
| 3613 ConnectionCloseSource::FROM_SELF)); | 3623 ConnectionCloseSource::FROM_SELF)); |
| 3614 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)); | 3624 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)); |
| 3615 connection_.GetRetransmissionAlarm()->Fire(); | 3625 connection_.GetRetransmissionAlarm()->Fire(); |
| 3616 EXPECT_FALSE(connection_.GetTimeoutAlarm()->IsSet()); | 3626 EXPECT_FALSE(connection_.GetTimeoutAlarm()->IsSet()); |
| 3617 EXPECT_FALSE(connection_.connected()); | 3627 EXPECT_FALSE(connection_.connected()); |
| 3618 } | 3628 } |
| 3619 | 3629 |
| 3630 TEST_P(QuicConnectionTest, TimeoutAfter3ClientRTOs) { |
| 3631 FLAGS_quic_reloadable_flag_quic_enable_3rtos = true; |
| 3632 connection_.SetMaxTailLossProbes(2); |
| 3633 EXPECT_TRUE(connection_.connected()); |
| 3634 EXPECT_CALL(*send_algorithm_, GetCongestionControlType()); |
| 3635 EXPECT_CALL(*send_algorithm_, SetFromConfig(_, _)); |
| 3636 QuicConfig config; |
| 3637 QuicTagVector connection_options; |
| 3638 connection_options.push_back(k3RTO); |
| 3639 config.SetConnectionOptionsToSend(connection_options); |
| 3640 connection_.SetFromConfig(config); |
| 3641 |
| 3642 // Send stream data. |
| 3643 SendStreamDataToPeer(kClientDataStreamId1, "foo", 0, FIN, nullptr); |
| 3644 |
| 3645 EXPECT_CALL(visitor_, OnPathDegrading()); |
| 3646 // Fire the retransmission alarm 4 times, twice for TLP and 2 times for RTO. |
| 3647 for (int i = 0; i < 4; ++i) { |
| 3648 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)); |
| 3649 connection_.GetRetransmissionAlarm()->Fire(); |
| 3650 EXPECT_TRUE(connection_.GetTimeoutAlarm()->IsSet()); |
| 3651 EXPECT_TRUE(connection_.connected()); |
| 3652 } |
| 3653 |
| 3654 EXPECT_EQ(2u, connection_.sent_packet_manager().GetConsecutiveTlpCount()); |
| 3655 EXPECT_EQ(2u, connection_.sent_packet_manager().GetConsecutiveRtoCount()); |
| 3656 // This time, we should time out. |
| 3657 EXPECT_CALL(visitor_, OnConnectionClosed(QUIC_TOO_MANY_RTOS, _, |
| 3658 ConnectionCloseSource::FROM_SELF)); |
| 3659 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)); |
| 3660 connection_.GetRetransmissionAlarm()->Fire(); |
| 3661 EXPECT_FALSE(connection_.GetTimeoutAlarm()->IsSet()); |
| 3662 EXPECT_FALSE(connection_.connected()); |
| 3663 } |
| 3664 |
| 3620 TEST_P(QuicConnectionTest, SendScheduler) { | 3665 TEST_P(QuicConnectionTest, SendScheduler) { |
| 3621 // Test that if we send a packet without delay, it is not queued. | 3666 // Test that if we send a packet without delay, it is not queued. |
| 3622 QuicPacket* packet = ConstructDataPacket(1, !kHasStopWaiting); | 3667 QuicPacket* packet = ConstructDataPacket(1, !kHasStopWaiting); |
| 3623 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)); | 3668 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)); |
| 3624 connection_.SendPacket(ENCRYPTION_NONE, 1, packet, HAS_RETRANSMITTABLE_DATA, | 3669 connection_.SendPacket(ENCRYPTION_NONE, 1, packet, HAS_RETRANSMITTABLE_DATA, |
| 3625 false, false); | 3670 false, false); |
| 3626 EXPECT_EQ(0u, connection_.NumQueuedPackets()); | 3671 EXPECT_EQ(0u, connection_.NumQueuedPackets()); |
| 3627 } | 3672 } |
| 3628 | 3673 |
| 3629 TEST_P(QuicConnectionTest, FailToSendFirstPacket) { | 3674 TEST_P(QuicConnectionTest, FailToSendFirstPacket) { |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3683 // The first stream frame will have 2 fewer overhead bytes than the other six. | 3728 // The first stream frame will have 2 fewer overhead bytes than the other six. |
| 3684 const string payload(payload_length * 7 + 2, 'a'); | 3729 const string payload(payload_length * 7 + 2, 'a'); |
| 3685 EXPECT_EQ(payload.size(), | 3730 EXPECT_EQ(payload.size(), |
| 3686 connection_.SendStreamDataWithString(1, payload, 0, NO_FIN, nullptr) | 3731 connection_.SendStreamDataWithString(1, payload, 0, NO_FIN, nullptr) |
| 3687 .bytes_consumed); | 3732 .bytes_consumed); |
| 3688 } | 3733 } |
| 3689 | 3734 |
| 3690 TEST_P(QuicConnectionTest, LoopThroughSendingPacketsWithTruncation) { | 3735 TEST_P(QuicConnectionTest, LoopThroughSendingPacketsWithTruncation) { |
| 3691 // Set up a larger payload than will fit in one packet. | 3736 // Set up a larger payload than will fit in one packet. |
| 3692 const string payload(connection_.max_packet_length(), 'a'); | 3737 const string payload(connection_.max_packet_length(), 'a'); |
| 3738 EXPECT_CALL(*send_algorithm_, GetCongestionControlType()).Times(AnyNumber()); |
| 3693 EXPECT_CALL(*send_algorithm_, SetFromConfig(_, _)).Times(AnyNumber()); | 3739 EXPECT_CALL(*send_algorithm_, SetFromConfig(_, _)).Times(AnyNumber()); |
| 3694 | 3740 |
| 3695 // Now send some packets with no truncation. | 3741 // Now send some packets with no truncation. |
| 3696 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(2); | 3742 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(2); |
| 3697 EXPECT_EQ(payload.size(), | 3743 EXPECT_EQ(payload.size(), |
| 3698 connection_.SendStreamDataWithString(3, payload, 0, NO_FIN, nullptr) | 3744 connection_.SendStreamDataWithString(3, payload, 0, NO_FIN, nullptr) |
| 3699 .bytes_consumed); | 3745 .bytes_consumed); |
| 3700 // Track the size of the second packet here. The overhead will be the largest | 3746 // Track the size of the second packet here. The overhead will be the largest |
| 3701 // we see in this test, due to the non-truncated connection id. | 3747 // we see in this test, due to the non-truncated connection id. |
| 3702 size_t non_truncated_packet_size = writer_->last_packet_size(); | 3748 size_t non_truncated_packet_size = writer_->last_packet_size(); |
| (...skipping 1514 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5217 error_details, ConnectionCloseSource::FROM_PEER)); | 5263 error_details, ConnectionCloseSource::FROM_PEER)); |
| 5218 connection_.set_perspective(Perspective::IS_CLIENT); | 5264 connection_.set_perspective(Perspective::IS_CLIENT); |
| 5219 connection_.CloseConnection(QUIC_CRYPTO_HANDSHAKE_STATELESS_REJECT, | 5265 connection_.CloseConnection(QUIC_CRYPTO_HANDSHAKE_STATELESS_REJECT, |
| 5220 error_details, | 5266 error_details, |
| 5221 ConnectionCloseBehavior::SILENT_CLOSE); | 5267 ConnectionCloseBehavior::SILENT_CLOSE); |
| 5222 } | 5268 } |
| 5223 | 5269 |
| 5224 } // namespace | 5270 } // namespace |
| 5225 } // namespace test | 5271 } // namespace test |
| 5226 } // namespace net | 5272 } // namespace net |
| OLD | NEW |