| 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 "net/base/net_errors.h" | 7 #include "net/base/net_errors.h" |
| 8 #include "net/quic/congestion_control/quic_receipt_metrics_collector.h" | 8 #include "net/quic/congestion_control/quic_receipt_metrics_collector.h" |
| 9 #include "net/quic/congestion_control/quic_send_scheduler.h" | 9 #include "net/quic/congestion_control/quic_send_scheduler.h" |
| 10 #include "net/quic/crypto/null_encrypter.h" | 10 #include "net/quic/crypto/null_encrypter.h" |
| (...skipping 885 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 896 clock_.AdvanceTime(QuicTime::Delta::FromMilliseconds(5)); | 896 clock_.AdvanceTime(QuicTime::Delta::FromMilliseconds(5)); |
| 897 EXPECT_EQ(default_timeout.Add(QuicTime::Delta::FromMilliseconds(5)), | 897 EXPECT_EQ(default_timeout.Add(QuicTime::Delta::FromMilliseconds(5)), |
| 898 clock_.Now()); | 898 clock_.Now()); |
| 899 EXPECT_TRUE(connection_.CheckForTimeout()); | 899 EXPECT_TRUE(connection_.CheckForTimeout()); |
| 900 EXPECT_FALSE(connection_.connected()); | 900 EXPECT_FALSE(connection_.connected()); |
| 901 } | 901 } |
| 902 | 902 |
| 903 // TODO(ianswett): Add scheduler tests when resend is false. | 903 // TODO(ianswett): Add scheduler tests when resend is false. |
| 904 TEST_F(QuicConnectionTest, SendScheduler) { | 904 TEST_F(QuicConnectionTest, SendScheduler) { |
| 905 // Test that if we send a packet without delay, it is not queued. | 905 // Test that if we send a packet without delay, it is not queued. |
| 906 scoped_ptr<QuicPacket> packet(ConstructDataPacket(1, 0)); | 906 QuicPacket* packet = ConstructDataPacket(1, 0); |
| 907 EXPECT_CALL(*scheduler_, TimeUntilSend(false)).WillOnce(testing::Return( | 907 EXPECT_CALL(*scheduler_, TimeUntilSend(false)).WillOnce(testing::Return( |
| 908 QuicTime::Delta())); | 908 QuicTime::Delta())); |
| 909 EXPECT_CALL(*scheduler_, SentPacket(_, _, _)); | 909 EXPECT_CALL(*scheduler_, SentPacket(_, _, _)); |
| 910 connection_.SendPacket(1, packet.get(), true, false, false); | 910 connection_.SendPacket(1, packet, true, false, false); |
| 911 EXPECT_EQ(0u, connection_.NumQueuedPackets()); | 911 EXPECT_EQ(0u, connection_.NumQueuedPackets()); |
| 912 } | 912 } |
| 913 | 913 |
| 914 TEST_F(QuicConnectionTest, SendSchedulerDelay) { | 914 TEST_F(QuicConnectionTest, SendSchedulerDelay) { |
| 915 // Test that if we send a packet with a delay, it ends up queued. | 915 // Test that if we send a packet with a delay, it ends up queued. |
| 916 scoped_ptr<QuicPacket> packet(ConstructDataPacket(1, 0)); | 916 QuicPacket* packet = ConstructDataPacket(1, 0); |
| 917 EXPECT_CALL(*scheduler_, TimeUntilSend(false)).WillOnce(testing::Return( | 917 EXPECT_CALL(*scheduler_, TimeUntilSend(false)).WillOnce(testing::Return( |
| 918 QuicTime::Delta::FromMicroseconds(1))); | 918 QuicTime::Delta::FromMicroseconds(1))); |
| 919 EXPECT_CALL(*scheduler_, SentPacket(1, _, _)).Times(0); | 919 EXPECT_CALL(*scheduler_, SentPacket(1, _, _)).Times(0); |
| 920 connection_.SendPacket(1, packet.get(), true, false, false); | 920 connection_.SendPacket(1, packet, true, false, false); |
| 921 EXPECT_EQ(1u, connection_.NumQueuedPackets()); | 921 EXPECT_EQ(1u, connection_.NumQueuedPackets()); |
| 922 } | 922 } |
| 923 | 923 |
| 924 TEST_F(QuicConnectionTest, SendSchedulerForce) { | 924 TEST_F(QuicConnectionTest, SendSchedulerForce) { |
| 925 // Test that if we force send a packet, it is not queued. | 925 // Test that if we force send a packet, it is not queued. |
| 926 scoped_ptr<QuicPacket> packet(ConstructDataPacket(1, 0)); | 926 QuicPacket* packet = ConstructDataPacket(1, 0); |
| 927 EXPECT_CALL(*scheduler_, TimeUntilSend(true)).Times(0); | 927 EXPECT_CALL(*scheduler_, TimeUntilSend(true)).Times(0); |
| 928 EXPECT_CALL(*scheduler_, SentPacket(_, _, _)); | 928 EXPECT_CALL(*scheduler_, SentPacket(_, _, _)); |
| 929 connection_.SendPacket(1, packet.get(), true, true, false); | 929 connection_.SendPacket(1, packet, true, true, false); |
| 930 EXPECT_EQ(0u, connection_.NumQueuedPackets()); | 930 EXPECT_EQ(0u, connection_.NumQueuedPackets()); |
| 931 } | 931 } |
| 932 | 932 |
| 933 // TODO(rch): Enable after we get non-blocking sockets. | 933 // TODO(rch): Enable after we get non-blocking sockets. |
| 934 TEST_F(QuicConnectionTest, DISABLED_SendSchedulerEAGAIN) { | 934 TEST_F(QuicConnectionTest, DISABLED_SendSchedulerEAGAIN) { |
| 935 scoped_ptr<QuicPacket> packet(ConstructDataPacket(1, 0)); | 935 QuicPacket* packet = ConstructDataPacket(1, 0); |
| 936 helper_->set_blocked(true); | 936 helper_->set_blocked(true); |
| 937 EXPECT_CALL(*scheduler_, TimeUntilSend(false)).WillOnce(testing::Return( | 937 EXPECT_CALL(*scheduler_, TimeUntilSend(false)).WillOnce(testing::Return( |
| 938 QuicTime::Delta())); | 938 QuicTime::Delta())); |
| 939 EXPECT_CALL(*scheduler_, SentPacket(1, _, _)).Times(0); | 939 EXPECT_CALL(*scheduler_, SentPacket(1, _, _)).Times(0); |
| 940 connection_.SendPacket(1, packet.get(), true, false, false); | 940 connection_.SendPacket(1, packet, true, false, false); |
| 941 EXPECT_EQ(1u, connection_.NumQueuedPackets()); | 941 EXPECT_EQ(1u, connection_.NumQueuedPackets()); |
| 942 } | 942 } |
| 943 | 943 |
| 944 TEST_F(QuicConnectionTest, SendSchedulerDelayThenSend) { | 944 TEST_F(QuicConnectionTest, SendSchedulerDelayThenSend) { |
| 945 // Test that if we send a packet with a delay, it ends up queued. | 945 // Test that if we send a packet with a delay, it ends up queued. |
| 946 scoped_ptr<QuicPacket> packet(ConstructDataPacket(1, 0)); | 946 QuicPacket* packet = ConstructDataPacket(1, 0); |
| 947 EXPECT_CALL(*scheduler_, TimeUntilSend(false)).WillOnce(testing::Return( | 947 EXPECT_CALL(*scheduler_, TimeUntilSend(false)).WillOnce(testing::Return( |
| 948 QuicTime::Delta::FromMicroseconds(1))); | 948 QuicTime::Delta::FromMicroseconds(1))); |
| 949 connection_.SendPacket(1, packet.get(), true, false, false); | 949 connection_.SendPacket(1, packet, true, false, false); |
| 950 EXPECT_EQ(1u, connection_.NumQueuedPackets()); | 950 EXPECT_EQ(1u, connection_.NumQueuedPackets()); |
| 951 | 951 |
| 952 // Advance the clock to fire the alarm, and configure the scheduler | 952 // Advance the clock to fire the alarm, and configure the scheduler |
| 953 // to permit the packet to be sent. | 953 // to permit the packet to be sent. |
| 954 EXPECT_CALL(*scheduler_, TimeUntilSend(false)).WillOnce(testing::Return( | 954 EXPECT_CALL(*scheduler_, TimeUntilSend(false)).WillOnce(testing::Return( |
| 955 QuicTime::Delta())); | 955 QuicTime::Delta())); |
| 956 clock_.AdvanceTime(QuicTime::Delta::FromMicroseconds(1)); | 956 clock_.AdvanceTime(QuicTime::Delta::FromMicroseconds(1)); |
| 957 EXPECT_CALL(*scheduler_, SentPacket(_, _, _)); | 957 EXPECT_CALL(*scheduler_, SentPacket(_, _, _)); |
| 958 EXPECT_CALL(visitor_, OnCanWrite()); | 958 EXPECT_CALL(visitor_, OnCanWrite()); |
| 959 connection_.OnCanWrite(); | 959 connection_.OnCanWrite(); |
| 960 EXPECT_EQ(0u, connection_.NumQueuedPackets()); | 960 EXPECT_EQ(0u, connection_.NumQueuedPackets()); |
| 961 } | 961 } |
| 962 | 962 |
| 963 TEST_F(QuicConnectionTest, SendSchedulerDelayThenRetransmit) { | 963 TEST_F(QuicConnectionTest, SendSchedulerDelayThenRetransmit) { |
| 964 // Test that if we send a retransmit with a delay, it ends up queued. | 964 // Test that if we send a retransmit with a delay, it ends up queued. |
| 965 scoped_ptr<QuicPacket> packet(ConstructDataPacket(1, 0)); | 965 QuicPacket* packet = ConstructDataPacket(1, 0); |
| 966 EXPECT_CALL(*scheduler_, TimeUntilSend(true)).WillOnce(testing::Return( | 966 EXPECT_CALL(*scheduler_, TimeUntilSend(true)).WillOnce(testing::Return( |
| 967 QuicTime::Delta::FromMicroseconds(1))); | 967 QuicTime::Delta::FromMicroseconds(1))); |
| 968 connection_.SendPacket(1, packet.get(), true, false, true); | 968 connection_.SendPacket(1, packet, true, false, true); |
| 969 EXPECT_EQ(1u, connection_.NumQueuedPackets()); | 969 EXPECT_EQ(1u, connection_.NumQueuedPackets()); |
| 970 | 970 |
| 971 // Advance the clock to fire the alarm, and configure the scheduler | 971 // Advance the clock to fire the alarm, and configure the scheduler |
| 972 // to permit the packet to be sent. | 972 // to permit the packet to be sent. |
| 973 EXPECT_CALL(*scheduler_, TimeUntilSend(true)).WillOnce(testing::Return( | 973 EXPECT_CALL(*scheduler_, TimeUntilSend(true)).WillOnce(testing::Return( |
| 974 QuicTime::Delta())); | 974 QuicTime::Delta())); |
| 975 | 975 |
| 976 // Ensure the scheduler is notified this is a retransmit. | 976 // Ensure the scheduler is notified this is a retransmit. |
| 977 EXPECT_CALL(*scheduler_, SentPacket(1, _, true)); | 977 EXPECT_CALL(*scheduler_, SentPacket(1, _, true)); |
| 978 clock_.AdvanceTime(QuicTime::Delta::FromMicroseconds(1)); | 978 clock_.AdvanceTime(QuicTime::Delta::FromMicroseconds(1)); |
| 979 EXPECT_CALL(visitor_, OnCanWrite()); | 979 EXPECT_CALL(visitor_, OnCanWrite()); |
| 980 connection_.OnCanWrite(); | 980 connection_.OnCanWrite(); |
| 981 EXPECT_EQ(0u, connection_.NumQueuedPackets()); | 981 EXPECT_EQ(0u, connection_.NumQueuedPackets()); |
| 982 } | 982 } |
| 983 | 983 |
| 984 TEST_F(QuicConnectionTest, SendSchedulerDelayAndQueue) { | 984 TEST_F(QuicConnectionTest, SendSchedulerDelayAndQueue) { |
| 985 scoped_ptr<QuicPacket> packet(ConstructDataPacket(1, 0)); | 985 QuicPacket* packet = ConstructDataPacket(1, 0); |
| 986 EXPECT_CALL(*scheduler_, TimeUntilSend(false)).WillOnce(testing::Return( | 986 EXPECT_CALL(*scheduler_, TimeUntilSend(false)).WillOnce(testing::Return( |
| 987 QuicTime::Delta::FromMicroseconds(1))); | 987 QuicTime::Delta::FromMicroseconds(1))); |
| 988 connection_.SendPacket(1, packet.get(), true, false, false); | 988 connection_.SendPacket(1, packet, true, false, false); |
| 989 EXPECT_EQ(1u, connection_.NumQueuedPackets()); | 989 EXPECT_EQ(1u, connection_.NumQueuedPackets()); |
| 990 | 990 |
| 991 // Attempt to send another packet and make sure that it gets queued. | 991 // Attempt to send another packet and make sure that it gets queued. |
| 992 connection_.SendPacket(2, packet.get(), true, false, false); | 992 packet = ConstructDataPacket(2, 0); |
| 993 connection_.SendPacket(2, packet, true, false, false); |
| 993 EXPECT_EQ(2u, connection_.NumQueuedPackets()); | 994 EXPECT_EQ(2u, connection_.NumQueuedPackets()); |
| 994 } | 995 } |
| 995 | 996 |
| 996 TEST_F(QuicConnectionTest, SendSchedulerDelayThenAckAndSend) { | 997 TEST_F(QuicConnectionTest, SendSchedulerDelayThenAckAndSend) { |
| 997 scoped_ptr<QuicPacket> packet(ConstructDataPacket(1, 0)); | 998 QuicPacket* packet = ConstructDataPacket(1, 0); |
| 998 EXPECT_CALL(*scheduler_, TimeUntilSend(false)).WillOnce(testing::Return( | 999 EXPECT_CALL(*scheduler_, TimeUntilSend(false)).WillOnce(testing::Return( |
| 999 QuicTime::Delta::FromMicroseconds(10))); | 1000 QuicTime::Delta::FromMicroseconds(10))); |
| 1000 connection_.SendPacket(1, packet.get(), true, false, false); | 1001 connection_.SendPacket(1, packet, true, false, false); |
| 1001 EXPECT_EQ(1u, connection_.NumQueuedPackets()); | 1002 EXPECT_EQ(1u, connection_.NumQueuedPackets()); |
| 1002 | 1003 |
| 1003 // Now send non-retransmitting information, that we're not going to resend 3. | 1004 // Now send non-retransmitting information, that we're not going to resend 3. |
| 1004 // The far end should stop waiting for it. | 1005 // The far end should stop waiting for it. |
| 1005 QuicAckFrame frame(0, 1); | 1006 QuicAckFrame frame(0, 1); |
| 1006 EXPECT_CALL(*scheduler_, TimeUntilSend(false)).WillRepeatedly(testing::Return( | 1007 EXPECT_CALL(*scheduler_, TimeUntilSend(false)).WillRepeatedly(testing::Return( |
| 1007 QuicTime::Delta())); | 1008 QuicTime::Delta())); |
| 1008 EXPECT_CALL(*scheduler_, SentPacket(_, _, _)); | 1009 EXPECT_CALL(*scheduler_, SentPacket(_, _, _)); |
| 1009 EXPECT_CALL(visitor_, OnCanWrite()); | 1010 EXPECT_CALL(visitor_, OnCanWrite()); |
| 1010 ProcessAckPacket(&frame); | 1011 ProcessAckPacket(&frame); |
| 1011 | 1012 |
| 1012 EXPECT_EQ(0u, connection_.NumQueuedPackets()); | 1013 EXPECT_EQ(0u, connection_.NumQueuedPackets()); |
| 1013 // Ensure alarm is not set | 1014 // Ensure alarm is not set |
| 1014 EXPECT_FALSE(helper_->IsSendAlarmSet()); | 1015 EXPECT_FALSE(helper_->IsSendAlarmSet()); |
| 1015 } | 1016 } |
| 1016 | 1017 |
| 1017 TEST_F(QuicConnectionTest, SendSchedulerDelayThenAckAndHold) { | 1018 TEST_F(QuicConnectionTest, SendSchedulerDelayThenAckAndHold) { |
| 1018 scoped_ptr<QuicPacket> packet(ConstructDataPacket(1, 0)); | 1019 QuicPacket* packet = ConstructDataPacket(1, 0); |
| 1019 EXPECT_CALL(*scheduler_, TimeUntilSend(false)).WillOnce(testing::Return( | 1020 EXPECT_CALL(*scheduler_, TimeUntilSend(false)).WillOnce(testing::Return( |
| 1020 QuicTime::Delta::FromMicroseconds(10))); | 1021 QuicTime::Delta::FromMicroseconds(10))); |
| 1021 connection_.SendPacket(1, packet.get(), true, false, false); | 1022 connection_.SendPacket(1, packet, true, false, false); |
| 1022 EXPECT_EQ(1u, connection_.NumQueuedPackets()); | 1023 EXPECT_EQ(1u, connection_.NumQueuedPackets()); |
| 1023 | 1024 |
| 1024 // Now send non-resending information, that we're not going to resend 3. | 1025 // Now send non-resending information, that we're not going to resend 3. |
| 1025 // The far end should stop waiting for it. | 1026 // The far end should stop waiting for it. |
| 1026 QuicAckFrame frame(0, 1); | 1027 QuicAckFrame frame(0, 1); |
| 1027 EXPECT_CALL(*scheduler_, TimeUntilSend(false)).WillOnce(testing::Return( | 1028 EXPECT_CALL(*scheduler_, TimeUntilSend(false)).WillOnce(testing::Return( |
| 1028 QuicTime::Delta::FromMicroseconds(1))); | 1029 QuicTime::Delta::FromMicroseconds(1))); |
| 1029 ProcessAckPacket(&frame); | 1030 ProcessAckPacket(&frame); |
| 1030 | 1031 |
| 1031 EXPECT_EQ(1u, connection_.NumQueuedPackets()); | 1032 EXPECT_EQ(1u, connection_.NumQueuedPackets()); |
| 1032 } | 1033 } |
| 1033 | 1034 |
| 1034 TEST_F(QuicConnectionTest, SendSchedulerDelayThenOnCanWrite) { | 1035 TEST_F(QuicConnectionTest, SendSchedulerDelayThenOnCanWrite) { |
| 1035 scoped_ptr<QuicPacket> packet(ConstructDataPacket(1, 0)); | 1036 QuicPacket* packet = ConstructDataPacket(1, 0); |
| 1036 EXPECT_CALL(*scheduler_, TimeUntilSend(false)).WillOnce(testing::Return( | 1037 EXPECT_CALL(*scheduler_, TimeUntilSend(false)).WillOnce(testing::Return( |
| 1037 QuicTime::Delta::FromMicroseconds(10))); | 1038 QuicTime::Delta::FromMicroseconds(10))); |
| 1038 connection_.SendPacket(1, packet.get(), true, false, false); | 1039 connection_.SendPacket(1, packet, true, false, false); |
| 1039 EXPECT_EQ(1u, connection_.NumQueuedPackets()); | 1040 EXPECT_EQ(1u, connection_.NumQueuedPackets()); |
| 1040 | 1041 |
| 1041 // OnCanWrite should not send the packet (because of the delay) | 1042 // OnCanWrite should not send the packet (because of the delay) |
| 1042 // but should still return true. | 1043 // but should still return true. |
| 1043 EXPECT_CALL(visitor_, OnCanWrite()); | 1044 EXPECT_CALL(visitor_, OnCanWrite()); |
| 1044 EXPECT_TRUE(connection_.OnCanWrite()); | 1045 EXPECT_TRUE(connection_.OnCanWrite()); |
| 1045 EXPECT_EQ(1u, connection_.NumQueuedPackets()); | 1046 EXPECT_EQ(1u, connection_.NumQueuedPackets()); |
| 1046 } | 1047 } |
| 1047 | 1048 |
| 1048 TEST_F(QuicConnectionTest, TestQueueLimitsOnSendStreamData) { | 1049 TEST_F(QuicConnectionTest, TestQueueLimitsOnSendStreamData) { |
| (...skipping 18 matching lines...) Expand all Loading... |
| 1067 | 1068 |
| 1068 // Queue the first packet. | 1069 // Queue the first packet. |
| 1069 EXPECT_CALL(*scheduler_, SentPacket(_, _, _)).Times(17); | 1070 EXPECT_CALL(*scheduler_, SentPacket(_, _, _)).Times(17); |
| 1070 EXPECT_EQ(17u, connection_.SendStreamData( | 1071 EXPECT_EQ(17u, connection_.SendStreamData( |
| 1071 1, "EnoughDataToQueue", 0, false, NULL).bytes_consumed); | 1072 1, "EnoughDataToQueue", 0, false, NULL).bytes_consumed); |
| 1072 } | 1073 } |
| 1073 | 1074 |
| 1074 } // namespace | 1075 } // namespace |
| 1075 } // namespace test | 1076 } // namespace test |
| 1076 } // namespace net | 1077 } // namespace net |
| OLD | NEW |