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 3605 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3616 EXPECT_TRUE(writer_->IsWriteBlocked()); | 3616 EXPECT_TRUE(writer_->IsWriteBlocked()); |
3617 TriggerConnectionClose(); | 3617 TriggerConnectionClose(); |
3618 EXPECT_EQ(1u, writer_->packets_write_attempts()); | 3618 EXPECT_EQ(1u, writer_->packets_write_attempts()); |
3619 } | 3619 } |
3620 | 3620 |
3621 TEST_P(QuicConnectionTest, AckNotifierTriggerCallback) { | 3621 TEST_P(QuicConnectionTest, AckNotifierTriggerCallback) { |
3622 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); | 3622 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); |
3623 | 3623 |
3624 // Create a delegate which we expect to be called. | 3624 // Create a delegate which we expect to be called. |
3625 scoped_refptr<MockAckNotifierDelegate> delegate(new MockAckNotifierDelegate); | 3625 scoped_refptr<MockAckNotifierDelegate> delegate(new MockAckNotifierDelegate); |
3626 EXPECT_CALL(*delegate, OnAckNotification(_, _, _, _, _)).Times(1); | 3626 EXPECT_CALL(*delegate.get(), OnAckNotification(_, _, _, _, _)).Times(1); |
3627 | 3627 |
3628 // Send some data, which will register the delegate to be notified. | 3628 // Send some data, which will register the delegate to be notified. |
3629 connection_.SendStreamDataWithString(1, "foo", 0, !kFin, delegate.get()); | 3629 connection_.SendStreamDataWithString(1, "foo", 0, !kFin, delegate.get()); |
3630 | 3630 |
3631 // Process an ACK from the server which should trigger the callback. | 3631 // Process an ACK from the server which should trigger the callback. |
3632 EXPECT_CALL(*send_algorithm_, OnCongestionEvent(true, _, _, _)); | 3632 EXPECT_CALL(*send_algorithm_, OnCongestionEvent(true, _, _, _)); |
3633 QuicAckFrame frame = InitAckFrame(1); | 3633 QuicAckFrame frame = InitAckFrame(1); |
3634 ProcessAckPacket(&frame); | 3634 ProcessAckPacket(&frame); |
3635 } | 3635 } |
3636 | 3636 |
3637 TEST_P(QuicConnectionTest, AckNotifierFailToTriggerCallback) { | 3637 TEST_P(QuicConnectionTest, AckNotifierFailToTriggerCallback) { |
3638 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); | 3638 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); |
3639 | 3639 |
3640 // Create a delegate which we don't expect to be called. | 3640 // Create a delegate which we don't expect to be called. |
3641 scoped_refptr<MockAckNotifierDelegate> delegate(new MockAckNotifierDelegate); | 3641 scoped_refptr<MockAckNotifierDelegate> delegate(new MockAckNotifierDelegate); |
3642 EXPECT_CALL(*delegate, OnAckNotification(_, _, _, _, _)).Times(0); | 3642 EXPECT_CALL(*delegate.get(), OnAckNotification(_, _, _, _, _)).Times(0); |
3643 | 3643 |
3644 // Send some data, which will register the delegate to be notified. This will | 3644 // Send some data, which will register the delegate to be notified. This will |
3645 // not be ACKed and so the delegate should never be called. | 3645 // not be ACKed and so the delegate should never be called. |
3646 connection_.SendStreamDataWithString(1, "foo", 0, !kFin, delegate.get()); | 3646 connection_.SendStreamDataWithString(1, "foo", 0, !kFin, delegate.get()); |
3647 | 3647 |
3648 // Send some other data which we will ACK. | 3648 // Send some other data which we will ACK. |
3649 connection_.SendStreamDataWithString(1, "foo", 0, !kFin, NULL); | 3649 connection_.SendStreamDataWithString(1, "foo", 0, !kFin, NULL); |
3650 connection_.SendStreamDataWithString(1, "bar", 0, !kFin, NULL); | 3650 connection_.SendStreamDataWithString(1, "bar", 0, !kFin, NULL); |
3651 | 3651 |
3652 // Now we receive ACK for packets 2 and 3, but importantly missing packet 1 | 3652 // Now we receive ACK for packets 2 and 3, but importantly missing packet 1 |
3653 // which we registered to be notified about. | 3653 // which we registered to be notified about. |
3654 QuicAckFrame frame = InitAckFrame(3); | 3654 QuicAckFrame frame = InitAckFrame(3); |
3655 NackPacket(1, &frame); | 3655 NackPacket(1, &frame); |
3656 SequenceNumberSet lost_packets; | 3656 SequenceNumberSet lost_packets; |
3657 lost_packets.insert(1); | 3657 lost_packets.insert(1); |
3658 EXPECT_CALL(*loss_algorithm_, DetectLostPackets(_, _, _, _)) | 3658 EXPECT_CALL(*loss_algorithm_, DetectLostPackets(_, _, _, _)) |
3659 .WillOnce(Return(lost_packets)); | 3659 .WillOnce(Return(lost_packets)); |
3660 EXPECT_CALL(*send_algorithm_, OnCongestionEvent(true, _, _, _)); | 3660 EXPECT_CALL(*send_algorithm_, OnCongestionEvent(true, _, _, _)); |
3661 ProcessAckPacket(&frame); | 3661 ProcessAckPacket(&frame); |
3662 } | 3662 } |
3663 | 3663 |
3664 TEST_P(QuicConnectionTest, AckNotifierCallbackAfterRetransmission) { | 3664 TEST_P(QuicConnectionTest, AckNotifierCallbackAfterRetransmission) { |
3665 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); | 3665 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); |
3666 | 3666 |
3667 // Create a delegate which we expect to be called. | 3667 // Create a delegate which we expect to be called. |
3668 scoped_refptr<MockAckNotifierDelegate> delegate(new MockAckNotifierDelegate); | 3668 scoped_refptr<MockAckNotifierDelegate> delegate(new MockAckNotifierDelegate); |
3669 EXPECT_CALL(*delegate, OnAckNotification(_, _, _, _, _)).Times(1); | 3669 EXPECT_CALL(*delegate.get(), OnAckNotification(_, _, _, _, _)).Times(1); |
3670 | 3670 |
3671 // Send four packets, and register to be notified on ACK of packet 2. | 3671 // Send four packets, and register to be notified on ACK of packet 2. |
3672 connection_.SendStreamDataWithString(3, "foo", 0, !kFin, NULL); | 3672 connection_.SendStreamDataWithString(3, "foo", 0, !kFin, NULL); |
3673 connection_.SendStreamDataWithString(3, "bar", 0, !kFin, delegate.get()); | 3673 connection_.SendStreamDataWithString(3, "bar", 0, !kFin, delegate.get()); |
3674 connection_.SendStreamDataWithString(3, "baz", 0, !kFin, NULL); | 3674 connection_.SendStreamDataWithString(3, "baz", 0, !kFin, NULL); |
3675 connection_.SendStreamDataWithString(3, "qux", 0, !kFin, NULL); | 3675 connection_.SendStreamDataWithString(3, "qux", 0, !kFin, NULL); |
3676 | 3676 |
3677 // Now we receive ACK for packets 1, 3, and 4 and lose 2. | 3677 // Now we receive ACK for packets 1, 3, and 4 and lose 2. |
3678 QuicAckFrame frame = InitAckFrame(4); | 3678 QuicAckFrame frame = InitAckFrame(4); |
3679 NackPacket(2, &frame); | 3679 NackPacket(2, &frame); |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3716 clock_.AdvanceTime(DefaultRetransmissionTime()); | 3716 clock_.AdvanceTime(DefaultRetransmissionTime()); |
3717 EXPECT_CALL(*send_algorithm_, OnRetransmissionTimeout(true)); | 3717 EXPECT_CALL(*send_algorithm_, OnRetransmissionTimeout(true)); |
3718 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, 2u, _, _)); | 3718 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, 2u, _, _)); |
3719 connection_.GetRetransmissionAlarm()->Fire(); | 3719 connection_.GetRetransmissionAlarm()->Fire(); |
3720 EXPECT_EQ(2u, writer_->header().packet_sequence_number); | 3720 EXPECT_EQ(2u, writer_->header().packet_sequence_number); |
3721 // We do not raise the high water mark yet. | 3721 // We do not raise the high water mark yet. |
3722 EXPECT_EQ(1u, stop_waiting()->least_unacked); | 3722 EXPECT_EQ(1u, stop_waiting()->least_unacked); |
3723 | 3723 |
3724 // Ack the original packet, which will revert the RTO. | 3724 // Ack the original packet, which will revert the RTO. |
3725 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); | 3725 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); |
3726 EXPECT_CALL(*delegate, OnAckNotification(1, _, 1, _, _)); | 3726 EXPECT_CALL(*delegate.get(), OnAckNotification(1, _, 1, _, _)); |
3727 EXPECT_CALL(*send_algorithm_, RevertRetransmissionTimeout()); | 3727 EXPECT_CALL(*send_algorithm_, RevertRetransmissionTimeout()); |
3728 EXPECT_CALL(*send_algorithm_, OnCongestionEvent(true, _, _, _)); | 3728 EXPECT_CALL(*send_algorithm_, OnCongestionEvent(true, _, _, _)); |
3729 QuicAckFrame ack_frame = InitAckFrame(1); | 3729 QuicAckFrame ack_frame = InitAckFrame(1); |
3730 ProcessAckPacket(&ack_frame); | 3730 ProcessAckPacket(&ack_frame); |
3731 | 3731 |
3732 // Delegate is not notified again when the retransmit is acked. | 3732 // Delegate is not notified again when the retransmit is acked. |
3733 EXPECT_CALL(*send_algorithm_, OnCongestionEvent(true, _, _, _)); | 3733 EXPECT_CALL(*send_algorithm_, OnCongestionEvent(true, _, _, _)); |
3734 QuicAckFrame second_ack_frame = InitAckFrame(2); | 3734 QuicAckFrame second_ack_frame = InitAckFrame(2); |
3735 ProcessAckPacket(&second_ack_frame); | 3735 ProcessAckPacket(&second_ack_frame); |
3736 } | 3736 } |
(...skipping 21 matching lines...) Expand all Loading... |
3758 lost_packets.insert(2); | 3758 lost_packets.insert(2); |
3759 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); | 3759 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); |
3760 EXPECT_CALL(*loss_algorithm_, DetectLostPackets(_, _, _, _)) | 3760 EXPECT_CALL(*loss_algorithm_, DetectLostPackets(_, _, _, _)) |
3761 .WillOnce(Return(lost_packets)); | 3761 .WillOnce(Return(lost_packets)); |
3762 EXPECT_CALL(*send_algorithm_, OnCongestionEvent(true, _, _, _)); | 3762 EXPECT_CALL(*send_algorithm_, OnCongestionEvent(true, _, _, _)); |
3763 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)); | 3763 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)); |
3764 ProcessAckPacket(&frame); | 3764 ProcessAckPacket(&frame); |
3765 | 3765 |
3766 // Now we get an ACK for packet 2, which was previously nacked. | 3766 // Now we get an ACK for packet 2, which was previously nacked. |
3767 SequenceNumberSet no_lost_packets; | 3767 SequenceNumberSet no_lost_packets; |
3768 EXPECT_CALL(*delegate, OnAckNotification(1, _, 1, _, _)); | 3768 EXPECT_CALL(*delegate.get(), OnAckNotification(1, _, 1, _, _)); |
3769 EXPECT_CALL(*loss_algorithm_, DetectLostPackets(_, _, _, _)) | 3769 EXPECT_CALL(*loss_algorithm_, DetectLostPackets(_, _, _, _)) |
3770 .WillOnce(Return(no_lost_packets)); | 3770 .WillOnce(Return(no_lost_packets)); |
3771 QuicAckFrame second_ack_frame = InitAckFrame(4); | 3771 QuicAckFrame second_ack_frame = InitAckFrame(4); |
3772 ProcessAckPacket(&second_ack_frame); | 3772 ProcessAckPacket(&second_ack_frame); |
3773 | 3773 |
3774 // Verify that the delegate is not notified again when the | 3774 // Verify that the delegate is not notified again when the |
3775 // retransmit is acked. | 3775 // retransmit is acked. |
3776 EXPECT_CALL(*loss_algorithm_, DetectLostPackets(_, _, _, _)) | 3776 EXPECT_CALL(*loss_algorithm_, DetectLostPackets(_, _, _, _)) |
3777 .WillOnce(Return(no_lost_packets)); | 3777 .WillOnce(Return(no_lost_packets)); |
3778 EXPECT_CALL(*send_algorithm_, OnCongestionEvent(true, _, _, _)); | 3778 EXPECT_CALL(*send_algorithm_, OnCongestionEvent(true, _, _, _)); |
3779 QuicAckFrame third_ack_frame = InitAckFrame(5); | 3779 QuicAckFrame third_ack_frame = InitAckFrame(5); |
3780 ProcessAckPacket(&third_ack_frame); | 3780 ProcessAckPacket(&third_ack_frame); |
3781 } | 3781 } |
3782 | 3782 |
3783 TEST_P(QuicConnectionTest, AckNotifierFECTriggerCallback) { | 3783 TEST_P(QuicConnectionTest, AckNotifierFECTriggerCallback) { |
3784 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); | 3784 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); |
3785 | 3785 |
3786 // Create a delegate which we expect to be called. | 3786 // Create a delegate which we expect to be called. |
3787 scoped_refptr<MockAckNotifierDelegate> delegate( | 3787 scoped_refptr<MockAckNotifierDelegate> delegate( |
3788 new MockAckNotifierDelegate); | 3788 new MockAckNotifierDelegate); |
3789 EXPECT_CALL(*delegate, OnAckNotification(_, _, _, _, _)).Times(1); | 3789 EXPECT_CALL(*delegate.get(), OnAckNotification(_, _, _, _, _)).Times(1); |
3790 | 3790 |
3791 // Send some data, which will register the delegate to be notified. | 3791 // Send some data, which will register the delegate to be notified. |
3792 connection_.SendStreamDataWithString(1, "foo", 0, !kFin, delegate.get()); | 3792 connection_.SendStreamDataWithString(1, "foo", 0, !kFin, delegate.get()); |
3793 connection_.SendStreamDataWithString(2, "bar", 0, !kFin, NULL); | 3793 connection_.SendStreamDataWithString(2, "bar", 0, !kFin, NULL); |
3794 | 3794 |
3795 // Process an ACK from the server with a revived packet, which should trigger | 3795 // Process an ACK from the server with a revived packet, which should trigger |
3796 // the callback. | 3796 // the callback. |
3797 EXPECT_CALL(*send_algorithm_, OnCongestionEvent(true, _, _, _)); | 3797 EXPECT_CALL(*send_algorithm_, OnCongestionEvent(true, _, _, _)); |
3798 QuicAckFrame frame = InitAckFrame(2); | 3798 QuicAckFrame frame = InitAckFrame(2); |
3799 NackPacket(1, &frame); | 3799 NackPacket(1, &frame); |
3800 frame.revived_packets.insert(1); | 3800 frame.revived_packets.insert(1); |
3801 ProcessAckPacket(&frame); | 3801 ProcessAckPacket(&frame); |
3802 // If the ack is processed again, the notifier should not be called again. | 3802 // If the ack is processed again, the notifier should not be called again. |
3803 ProcessAckPacket(&frame); | 3803 ProcessAckPacket(&frame); |
3804 } | 3804 } |
3805 | 3805 |
3806 TEST_P(QuicConnectionTest, AckNotifierCallbackAfterFECRecovery) { | 3806 TEST_P(QuicConnectionTest, AckNotifierCallbackAfterFECRecovery) { |
3807 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); | 3807 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); |
3808 EXPECT_CALL(visitor_, OnCanWrite()); | 3808 EXPECT_CALL(visitor_, OnCanWrite()); |
3809 | 3809 |
3810 // Create a delegate which we expect to be called. | 3810 // Create a delegate which we expect to be called. |
3811 scoped_refptr<MockAckNotifierDelegate> delegate(new MockAckNotifierDelegate); | 3811 scoped_refptr<MockAckNotifierDelegate> delegate(new MockAckNotifierDelegate); |
3812 EXPECT_CALL(*delegate, OnAckNotification(_, _, _, _, _)).Times(1); | 3812 EXPECT_CALL(*delegate.get(), OnAckNotification(_, _, _, _, _)).Times(1); |
3813 | 3813 |
3814 // Expect ACKs for 1 packet. | 3814 // Expect ACKs for 1 packet. |
3815 EXPECT_CALL(*send_algorithm_, OnCongestionEvent(true, _, _, _)); | 3815 EXPECT_CALL(*send_algorithm_, OnCongestionEvent(true, _, _, _)); |
3816 | 3816 |
3817 // Send one packet, and register to be notified on ACK. | 3817 // Send one packet, and register to be notified on ACK. |
3818 connection_.SendStreamDataWithString(1, "foo", 0, !kFin, delegate.get()); | 3818 connection_.SendStreamDataWithString(1, "foo", 0, !kFin, delegate.get()); |
3819 | 3819 |
3820 // Ack packet gets dropped, but we receive an FEC packet that covers it. | 3820 // Ack packet gets dropped, but we receive an FEC packet that covers it. |
3821 // Should recover the Ack packet and trigger the notification callback. | 3821 // Should recover the Ack packet and trigger the notification callback. |
3822 QuicFrames frames; | 3822 QuicFrames frames; |
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3954 QuicBlockedFrame blocked; | 3954 QuicBlockedFrame blocked; |
3955 blocked.stream_id = 3; | 3955 blocked.stream_id = 3; |
3956 EXPECT_CALL(visitor_, OnBlockedFrames(_)); | 3956 EXPECT_CALL(visitor_, OnBlockedFrames(_)); |
3957 ProcessFramePacket(QuicFrame(&blocked)); | 3957 ProcessFramePacket(QuicFrame(&blocked)); |
3958 EXPECT_TRUE(ack_alarm->IsSet()); | 3958 EXPECT_TRUE(ack_alarm->IsSet()); |
3959 } | 3959 } |
3960 | 3960 |
3961 } // namespace | 3961 } // namespace |
3962 } // namespace test | 3962 } // namespace test |
3963 } // namespace net | 3963 } // namespace net |
OLD | NEW |