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/stl_util.h" | 9 #include "base/stl_util.h" |
10 #include "net/base/net_errors.h" | 10 #include "net/base/net_errors.h" |
(...skipping 2993 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3004 | 3004 |
3005 QuicGoAwayFrame goaway; | 3005 QuicGoAwayFrame goaway; |
3006 goaway.last_good_stream_id = 1; | 3006 goaway.last_good_stream_id = 1; |
3007 goaway.error_code = QUIC_PEER_GOING_AWAY; | 3007 goaway.error_code = QUIC_PEER_GOING_AWAY; |
3008 goaway.reason_phrase = "Going away."; | 3008 goaway.reason_phrase = "Going away."; |
3009 EXPECT_CALL(visitor_, OnGoAway(_)); | 3009 EXPECT_CALL(visitor_, OnGoAway(_)); |
3010 ProcessGoAwayPacket(&goaway); | 3010 ProcessGoAwayPacket(&goaway); |
3011 } | 3011 } |
3012 | 3012 |
3013 TEST_P(QuicConnectionTest, WindowUpdate) { | 3013 TEST_P(QuicConnectionTest, WindowUpdate) { |
3014 if (version() < QUIC_VERSION_14) { | 3014 if (version() == QUIC_VERSION_13) { |
3015 return; | 3015 return; |
3016 } | 3016 } |
3017 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); | 3017 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); |
3018 | 3018 |
3019 QuicWindowUpdateFrame window_update; | 3019 QuicWindowUpdateFrame window_update; |
3020 window_update.stream_id = 3; | 3020 window_update.stream_id = 3; |
3021 window_update.byte_offset = 1234; | 3021 window_update.byte_offset = 1234; |
3022 EXPECT_CALL(visitor_, OnWindowUpdateFrames(_)); | 3022 EXPECT_CALL(visitor_, OnWindowUpdateFrames(_)); |
3023 ProcessFramePacket(QuicFrame(&window_update)); | 3023 ProcessFramePacket(QuicFrame(&window_update)); |
3024 } | 3024 } |
3025 | 3025 |
3026 TEST_P(QuicConnectionTest, Blocked) { | 3026 TEST_P(QuicConnectionTest, Blocked) { |
3027 if (version() < QUIC_VERSION_14) { | 3027 if (version() == QUIC_VERSION_13) { |
3028 return; | 3028 return; |
3029 } | 3029 } |
3030 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); | 3030 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); |
3031 | 3031 |
3032 QuicBlockedFrame blocked; | 3032 QuicBlockedFrame blocked; |
3033 blocked.stream_id = 3; | 3033 blocked.stream_id = 3; |
3034 EXPECT_CALL(visitor_, OnBlockedFrames(_)); | 3034 EXPECT_CALL(visitor_, OnBlockedFrames(_)); |
3035 ProcessFramePacket(QuicFrame(&blocked)); | 3035 ProcessFramePacket(QuicFrame(&blocked)); |
3036 } | 3036 } |
3037 | 3037 |
(...skipping 554 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3592 EXPECT_TRUE(writer_->IsWriteBlocked()); | 3592 EXPECT_TRUE(writer_->IsWriteBlocked()); |
3593 TriggerConnectionClose(); | 3593 TriggerConnectionClose(); |
3594 EXPECT_EQ(1u, writer_->packets_write_attempts()); | 3594 EXPECT_EQ(1u, writer_->packets_write_attempts()); |
3595 } | 3595 } |
3596 | 3596 |
3597 TEST_P(QuicConnectionTest, AckNotifierTriggerCallback) { | 3597 TEST_P(QuicConnectionTest, AckNotifierTriggerCallback) { |
3598 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); | 3598 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); |
3599 | 3599 |
3600 // Create a delegate which we expect to be called. | 3600 // Create a delegate which we expect to be called. |
3601 scoped_refptr<MockAckNotifierDelegate> delegate(new MockAckNotifierDelegate); | 3601 scoped_refptr<MockAckNotifierDelegate> delegate(new MockAckNotifierDelegate); |
3602 EXPECT_CALL(*delegate, OnAckNotification()).Times(1); | 3602 EXPECT_CALL(*delegate, OnAckNotification(_, _, _, _)).Times(1); |
3603 | 3603 |
3604 // Send some data, which will register the delegate to be notified. | 3604 // Send some data, which will register the delegate to be notified. |
3605 connection_.SendStreamDataWithString(1, "foo", 0, !kFin, delegate.get()); | 3605 connection_.SendStreamDataWithString(1, "foo", 0, !kFin, delegate.get()); |
3606 | 3606 |
3607 // Process an ACK from the server which should trigger the callback. | 3607 // Process an ACK from the server which should trigger the callback. |
3608 EXPECT_CALL(*send_algorithm_, UpdateRtt(_)); | 3608 EXPECT_CALL(*send_algorithm_, UpdateRtt(_)); |
3609 EXPECT_CALL(*send_algorithm_, OnPacketAcked(_, _)).Times(1); | 3609 EXPECT_CALL(*send_algorithm_, OnPacketAcked(_, _)).Times(1); |
3610 QuicAckFrame frame = InitAckFrame(1, 0); | 3610 QuicAckFrame frame = InitAckFrame(1, 0); |
3611 ProcessAckPacket(&frame); | 3611 ProcessAckPacket(&frame); |
3612 } | 3612 } |
3613 | 3613 |
3614 TEST_P(QuicConnectionTest, AckNotifierFailToTriggerCallback) { | 3614 TEST_P(QuicConnectionTest, AckNotifierFailToTriggerCallback) { |
3615 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); | 3615 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); |
3616 | 3616 |
3617 // Create a delegate which we don't expect to be called. | 3617 // Create a delegate which we don't expect to be called. |
3618 scoped_refptr<MockAckNotifierDelegate> delegate(new MockAckNotifierDelegate); | 3618 scoped_refptr<MockAckNotifierDelegate> delegate(new MockAckNotifierDelegate); |
3619 EXPECT_CALL(*delegate, OnAckNotification()).Times(0); | 3619 EXPECT_CALL(*delegate, OnAckNotification(_, _, _, _)).Times(0); |
3620 | 3620 |
3621 EXPECT_CALL(*send_algorithm_, UpdateRtt(_)); | 3621 EXPECT_CALL(*send_algorithm_, UpdateRtt(_)); |
3622 EXPECT_CALL(*send_algorithm_, OnPacketAcked(_, _)).Times(2); | 3622 EXPECT_CALL(*send_algorithm_, OnPacketAcked(_, _)).Times(2); |
3623 | 3623 |
3624 // Send some data, which will register the delegate to be notified. This will | 3624 // Send some data, which will register the delegate to be notified. This will |
3625 // not be ACKed and so the delegate should never be called. | 3625 // not be ACKed and so the delegate should never be called. |
3626 connection_.SendStreamDataWithString(1, "foo", 0, !kFin, delegate.get()); | 3626 connection_.SendStreamDataWithString(1, "foo", 0, !kFin, delegate.get()); |
3627 | 3627 |
3628 // Send some other data which we will ACK. | 3628 // Send some other data which we will ACK. |
3629 connection_.SendStreamDataWithString(1, "foo", 0, !kFin, NULL); | 3629 connection_.SendStreamDataWithString(1, "foo", 0, !kFin, NULL); |
(...skipping 10 matching lines...) Expand all Loading... |
3640 EXPECT_CALL(*send_algorithm_, OnPacketLost(1, _)); | 3640 EXPECT_CALL(*send_algorithm_, OnPacketLost(1, _)); |
3641 EXPECT_CALL(*send_algorithm_, OnPacketAbandoned(1, _)); | 3641 EXPECT_CALL(*send_algorithm_, OnPacketAbandoned(1, _)); |
3642 ProcessAckPacket(&frame); | 3642 ProcessAckPacket(&frame); |
3643 } | 3643 } |
3644 | 3644 |
3645 TEST_P(QuicConnectionTest, AckNotifierCallbackAfterRetransmission) { | 3645 TEST_P(QuicConnectionTest, AckNotifierCallbackAfterRetransmission) { |
3646 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); | 3646 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); |
3647 | 3647 |
3648 // Create a delegate which we expect to be called. | 3648 // Create a delegate which we expect to be called. |
3649 scoped_refptr<MockAckNotifierDelegate> delegate(new MockAckNotifierDelegate); | 3649 scoped_refptr<MockAckNotifierDelegate> delegate(new MockAckNotifierDelegate); |
3650 EXPECT_CALL(*delegate, OnAckNotification()).Times(1); | 3650 EXPECT_CALL(*delegate, OnAckNotification(_, _, _, _)).Times(1); |
3651 | 3651 |
3652 // Send four packets, and register to be notified on ACK of packet 2. | 3652 // Send four packets, and register to be notified on ACK of packet 2. |
3653 connection_.SendStreamDataWithString(3, "foo", 0, !kFin, NULL); | 3653 connection_.SendStreamDataWithString(3, "foo", 0, !kFin, NULL); |
3654 connection_.SendStreamDataWithString(3, "bar", 0, !kFin, delegate.get()); | 3654 connection_.SendStreamDataWithString(3, "bar", 0, !kFin, delegate.get()); |
3655 connection_.SendStreamDataWithString(3, "baz", 0, !kFin, NULL); | 3655 connection_.SendStreamDataWithString(3, "baz", 0, !kFin, NULL); |
3656 connection_.SendStreamDataWithString(3, "qux", 0, !kFin, NULL); | 3656 connection_.SendStreamDataWithString(3, "qux", 0, !kFin, NULL); |
3657 | 3657 |
3658 // Now we receive ACK for packets 1, 3, and 4 and lose 2. | 3658 // Now we receive ACK for packets 1, 3, and 4 and lose 2. |
3659 QuicAckFrame frame = InitAckFrame(4, 0); | 3659 QuicAckFrame frame = InitAckFrame(4, 0); |
3660 NackPacket(2, &frame); | 3660 NackPacket(2, &frame); |
(...skipping 22 matching lines...) Expand all Loading... |
3683 // ACK) triggers notification on our end. | 3683 // ACK) triggers notification on our end. |
3684 TEST_P(QuicConnectionTest, AckNotifierCallbackAfterFECRecovery) { | 3684 TEST_P(QuicConnectionTest, AckNotifierCallbackAfterFECRecovery) { |
3685 if (version() < QUIC_VERSION_15) { | 3685 if (version() < QUIC_VERSION_15) { |
3686 return; | 3686 return; |
3687 } | 3687 } |
3688 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); | 3688 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); |
3689 EXPECT_CALL(visitor_, OnCanWrite()); | 3689 EXPECT_CALL(visitor_, OnCanWrite()); |
3690 | 3690 |
3691 // Create a delegate which we expect to be called. | 3691 // Create a delegate which we expect to be called. |
3692 scoped_refptr<MockAckNotifierDelegate> delegate(new MockAckNotifierDelegate); | 3692 scoped_refptr<MockAckNotifierDelegate> delegate(new MockAckNotifierDelegate); |
3693 EXPECT_CALL(*delegate, OnAckNotification()).Times(1); | 3693 EXPECT_CALL(*delegate, OnAckNotification(_, _, _, _)).Times(1); |
3694 | 3694 |
3695 // Expect ACKs for 1 packet. | 3695 // Expect ACKs for 1 packet. |
3696 EXPECT_CALL(*send_algorithm_, UpdateRtt(_)); | 3696 EXPECT_CALL(*send_algorithm_, UpdateRtt(_)); |
3697 EXPECT_CALL(*send_algorithm_, OnPacketAcked(_, _)).Times(1); | 3697 EXPECT_CALL(*send_algorithm_, OnPacketAcked(_, _)).Times(1); |
3698 | 3698 |
3699 // Send one packet, and register to be notified on ACK. | 3699 // Send one packet, and register to be notified on ACK. |
3700 connection_.SendStreamDataWithString(1, "foo", 0, !kFin, delegate.get()); | 3700 connection_.SendStreamDataWithString(1, "foo", 0, !kFin, delegate.get()); |
3701 | 3701 |
3702 // Ack packet gets dropped, but we receive an FEC packet that covers it. | 3702 // Ack packet gets dropped, but we receive an FEC packet that covers it. |
3703 // Should recover the Ack packet and trigger the notification callback. | 3703 // Should recover the Ack packet and trigger the notification callback. |
(...skipping 22 matching lines...) Expand all Loading... |
3726 // FEC packet which allows the ACK packet to be recovered. | 3726 // FEC packet which allows the ACK packet to be recovered. |
3727 ProcessFecPacket(2, 1, true, !kEntropyFlag, packet); | 3727 ProcessFecPacket(2, 1, true, !kEntropyFlag, packet); |
3728 } | 3728 } |
3729 | 3729 |
3730 class MockQuicConnectionDebugVisitor | 3730 class MockQuicConnectionDebugVisitor |
3731 : public QuicConnectionDebugVisitorInterface { | 3731 : public QuicConnectionDebugVisitorInterface { |
3732 public: | 3732 public: |
3733 MOCK_METHOD1(OnFrameAddedToPacket, | 3733 MOCK_METHOD1(OnFrameAddedToPacket, |
3734 void(const QuicFrame&)); | 3734 void(const QuicFrame&)); |
3735 | 3735 |
3736 MOCK_METHOD4(OnPacketSent, | 3736 MOCK_METHOD5(OnPacketSent, |
3737 void(QuicPacketSequenceNumber, | 3737 void(QuicPacketSequenceNumber, |
3738 EncryptionLevel, | 3738 EncryptionLevel, |
| 3739 TransmissionType, |
3739 const QuicEncryptedPacket&, | 3740 const QuicEncryptedPacket&, |
3740 WriteResult)); | 3741 WriteResult)); |
3741 | 3742 |
3742 MOCK_METHOD2(OnPacketRetransmitted, | 3743 MOCK_METHOD2(OnPacketRetransmitted, |
3743 void(QuicPacketSequenceNumber, | 3744 void(QuicPacketSequenceNumber, |
3744 QuicPacketSequenceNumber)); | 3745 QuicPacketSequenceNumber)); |
3745 | 3746 |
3746 MOCK_METHOD3(OnPacketReceived, | 3747 MOCK_METHOD3(OnPacketReceived, |
3747 void(const IPEndPoint&, | 3748 void(const IPEndPoint&, |
3748 const IPEndPoint&, | 3749 const IPEndPoint&, |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3797 | 3798 |
3798 TestConnection server(connection_id_, IPEndPoint(), helper_.get(), | 3799 TestConnection server(connection_id_, IPEndPoint(), helper_.get(), |
3799 writer_.get(), true, version()); | 3800 writer_.get(), true, version()); |
3800 TestConnection client(connection_id_, IPEndPoint(), helper_.get(), | 3801 TestConnection client(connection_id_, IPEndPoint(), helper_.get(), |
3801 writer_.get(), false, version()); | 3802 writer_.get(), false, version()); |
3802 EXPECT_TRUE(client.sent_packet_manager().using_pacing()); | 3803 EXPECT_TRUE(client.sent_packet_manager().using_pacing()); |
3803 EXPECT_FALSE(server.sent_packet_manager().using_pacing()); | 3804 EXPECT_FALSE(server.sent_packet_manager().using_pacing()); |
3804 } | 3805 } |
3805 | 3806 |
3806 TEST_P(QuicConnectionTest, ControlFramesInstigateAcks) { | 3807 TEST_P(QuicConnectionTest, ControlFramesInstigateAcks) { |
3807 if (version() < QUIC_VERSION_14) { | 3808 if (version() == QUIC_VERSION_13) { |
3808 return; | 3809 return; |
3809 } | 3810 } |
3810 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); | 3811 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); |
3811 | 3812 |
3812 // Send a WINDOW_UPDATE frame. | 3813 // Send a WINDOW_UPDATE frame. |
3813 QuicWindowUpdateFrame window_update; | 3814 QuicWindowUpdateFrame window_update; |
3814 window_update.stream_id = 3; | 3815 window_update.stream_id = 3; |
3815 window_update.byte_offset = 1234; | 3816 window_update.byte_offset = 1234; |
3816 EXPECT_CALL(visitor_, OnWindowUpdateFrames(_)); | 3817 EXPECT_CALL(visitor_, OnWindowUpdateFrames(_)); |
3817 ProcessFramePacket(QuicFrame(&window_update)); | 3818 ProcessFramePacket(QuicFrame(&window_update)); |
3818 | 3819 |
3819 // Ensure that this has caused the ACK alarm to be set. | 3820 // Ensure that this has caused the ACK alarm to be set. |
3820 QuicAlarm* ack_alarm = QuicConnectionPeer::GetAckAlarm(&connection_); | 3821 QuicAlarm* ack_alarm = QuicConnectionPeer::GetAckAlarm(&connection_); |
3821 EXPECT_TRUE(ack_alarm->IsSet()); | 3822 EXPECT_TRUE(ack_alarm->IsSet()); |
3822 | 3823 |
3823 // Cancel alarm, and try again with BLOCKED frame. | 3824 // Cancel alarm, and try again with BLOCKED frame. |
3824 ack_alarm->Cancel(); | 3825 ack_alarm->Cancel(); |
3825 QuicBlockedFrame blocked; | 3826 QuicBlockedFrame blocked; |
3826 blocked.stream_id = 3; | 3827 blocked.stream_id = 3; |
3827 EXPECT_CALL(visitor_, OnBlockedFrames(_)); | 3828 EXPECT_CALL(visitor_, OnBlockedFrames(_)); |
3828 ProcessFramePacket(QuicFrame(&blocked)); | 3829 ProcessFramePacket(QuicFrame(&blocked)); |
3829 EXPECT_TRUE(ack_alarm->IsSet()); | 3830 EXPECT_TRUE(ack_alarm->IsSet()); |
3830 } | 3831 } |
3831 | 3832 |
3832 } // namespace | 3833 } // namespace |
3833 } // namespace test | 3834 } // namespace test |
3834 } // namespace net | 3835 } // namespace net |
OLD | NEW |