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 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
57 QuicCongestionFeedbackFrame* feedback_; | 57 QuicCongestionFeedbackFrame* feedback_; |
58 | 58 |
59 DISALLOW_COPY_AND_ASSIGN(TestCollector); | 59 DISALLOW_COPY_AND_ASSIGN(TestCollector); |
60 }; | 60 }; |
61 | 61 |
62 class TestConnectionHelper : public QuicConnectionHelperInterface { | 62 class TestConnectionHelper : public QuicConnectionHelperInterface { |
63 public: | 63 public: |
64 TestConnectionHelper(MockClock* clock, MockRandom* random_generator) | 64 TestConnectionHelper(MockClock* clock, MockRandom* random_generator) |
65 : clock_(clock), | 65 : clock_(clock), |
66 random_generator_(random_generator), | 66 random_generator_(random_generator), |
| 67 retransmission_alarm_(QuicTime::Zero()), |
| 68 send_alarm_(QuicTime::Zero()), |
| 69 timeout_alarm_(QuicTime::Zero()), |
67 blocked_(false) { | 70 blocked_(false) { |
68 } | 71 } |
69 | 72 |
70 // QuicConnectionHelperInterface | 73 // QuicConnectionHelperInterface |
71 virtual void SetConnection(QuicConnection* connection) {} | 74 virtual void SetConnection(QuicConnection* connection) {} |
72 | 75 |
73 virtual const QuicClock* GetClock() const { | 76 virtual const QuicClock* GetClock() const { |
74 return clock_; | 77 return clock_; |
75 } | 78 } |
76 | 79 |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
110 | 113 |
111 virtual void SetTimeoutAlarm(QuicTime::Delta delay) { | 114 virtual void SetTimeoutAlarm(QuicTime::Delta delay) { |
112 timeout_alarm_ = clock_->Now().Add(delay); | 115 timeout_alarm_ = clock_->Now().Add(delay); |
113 } | 116 } |
114 | 117 |
115 virtual bool IsSendAlarmSet() { | 118 virtual bool IsSendAlarmSet() { |
116 return send_alarm_ > clock_->Now(); | 119 return send_alarm_ > clock_->Now(); |
117 } | 120 } |
118 | 121 |
119 virtual void UnregisterSendAlarmIfRegistered() { | 122 virtual void UnregisterSendAlarmIfRegistered() { |
120 send_alarm_ = QuicTime(); | 123 send_alarm_ = QuicTime::Zero(); |
121 } | 124 } |
122 | 125 |
123 virtual void SetAckAlarm(QuicTime::Delta delay) {} | 126 virtual void SetAckAlarm(QuicTime::Delta delay) {} |
124 virtual void ClearAckAlarm() {} | 127 virtual void ClearAckAlarm() {} |
125 | 128 |
126 QuicTime retransmission_alarm() const { | 129 QuicTime retransmission_alarm() const { |
127 return retransmission_alarm_; | 130 return retransmission_alarm_; |
128 } | 131 } |
129 | 132 |
130 QuicTime timeout_alarm() const { return timeout_alarm_; } | 133 QuicTime timeout_alarm() const { return timeout_alarm_; } |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
194 helper_(new TestConnectionHelper(&clock_, &random_generator_)), | 197 helper_(new TestConnectionHelper(&clock_, &random_generator_)), |
195 connection_(guid_, IPEndPoint(), helper_.get()), | 198 connection_(guid_, IPEndPoint(), helper_.get()), |
196 frame1_(1, false, 0, data1), | 199 frame1_(1, false, 0, data1), |
197 frame2_(1, false, 3, data2), | 200 frame2_(1, false, 3, data2), |
198 accept_packet_(true) { | 201 accept_packet_(true) { |
199 connection_.set_visitor(&visitor_); | 202 connection_.set_visitor(&visitor_); |
200 connection_.SetScheduler(scheduler_); | 203 connection_.SetScheduler(scheduler_); |
201 // Simplify tests by not sending feedback unless specifically configured. | 204 // Simplify tests by not sending feedback unless specifically configured. |
202 SetFeedback(NULL); | 205 SetFeedback(NULL); |
203 EXPECT_CALL(*scheduler_, TimeUntilSend(_)).WillRepeatedly(Return( | 206 EXPECT_CALL(*scheduler_, TimeUntilSend(_)).WillRepeatedly(Return( |
204 QuicTime::Delta())); | 207 QuicTime::Delta::Zero())); |
205 EXPECT_CALL(*collector_, | 208 EXPECT_CALL(*collector_, |
206 RecordIncomingPacket(_, _, _, _)).Times(AnyNumber()); | 209 RecordIncomingPacket(_, _, _, _)).Times(AnyNumber()); |
207 EXPECT_CALL(*scheduler_, SentPacket(_, _, _)).Times(AnyNumber()); | 210 EXPECT_CALL(*scheduler_, SentPacket(_, _, _)).Times(AnyNumber()); |
208 } | 211 } |
209 | 212 |
210 QuicAckFrame* outgoing_ack() { | 213 QuicAckFrame* outgoing_ack() { |
211 return QuicConnectionPeer::GetOutgoingAck(&connection_); | 214 return QuicConnectionPeer::GetOutgoingAck(&connection_); |
212 } | 215 } |
213 | 216 |
214 QuicAckFrame* last_ack() { | 217 QuicAckFrame* last_ack() { |
(...skipping 680 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
895 clock_.Now()); | 898 clock_.Now()); |
896 EXPECT_TRUE(connection_.CheckForTimeout()); | 899 EXPECT_TRUE(connection_.CheckForTimeout()); |
897 EXPECT_FALSE(connection_.connected()); | 900 EXPECT_FALSE(connection_.connected()); |
898 } | 901 } |
899 | 902 |
900 // TODO(ianswett): Add scheduler tests when should_retransmit is false. | 903 // TODO(ianswett): Add scheduler tests when should_retransmit is false. |
901 TEST_F(QuicConnectionTest, SendScheduler) { | 904 TEST_F(QuicConnectionTest, SendScheduler) { |
902 // 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. |
903 QuicPacket* packet = ConstructDataPacket(1, 0); | 906 QuicPacket* packet = ConstructDataPacket(1, 0); |
904 EXPECT_CALL(*scheduler_, TimeUntilSend(false)).WillOnce(testing::Return( | 907 EXPECT_CALL(*scheduler_, TimeUntilSend(false)).WillOnce(testing::Return( |
905 QuicTime::Delta())); | 908 QuicTime::Delta::Zero())); |
906 EXPECT_CALL(*scheduler_, SentPacket(_, _, _)); | 909 EXPECT_CALL(*scheduler_, SentPacket(_, _, _)); |
907 connection_.SendPacket(1, packet, true, false, false); | 910 connection_.SendPacket(1, packet, true, false, false); |
908 EXPECT_EQ(0u, connection_.NumQueuedPackets()); | 911 EXPECT_EQ(0u, connection_.NumQueuedPackets()); |
909 } | 912 } |
910 | 913 |
911 TEST_F(QuicConnectionTest, SendSchedulerDelay) { | 914 TEST_F(QuicConnectionTest, SendSchedulerDelay) { |
912 // 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. |
913 QuicPacket* packet = ConstructDataPacket(1, 0); | 916 QuicPacket* packet = ConstructDataPacket(1, 0); |
914 EXPECT_CALL(*scheduler_, TimeUntilSend(false)).WillOnce(testing::Return( | 917 EXPECT_CALL(*scheduler_, TimeUntilSend(false)).WillOnce(testing::Return( |
915 QuicTime::Delta::FromMicroseconds(1))); | 918 QuicTime::Delta::FromMicroseconds(1))); |
916 EXPECT_CALL(*scheduler_, SentPacket(1, _, _)).Times(0); | 919 EXPECT_CALL(*scheduler_, SentPacket(1, _, _)).Times(0); |
917 connection_.SendPacket(1, packet, true, false, false); | 920 connection_.SendPacket(1, packet, true, false, false); |
918 EXPECT_EQ(1u, connection_.NumQueuedPackets()); | 921 EXPECT_EQ(1u, connection_.NumQueuedPackets()); |
919 } | 922 } |
920 | 923 |
921 TEST_F(QuicConnectionTest, SendSchedulerForce) { | 924 TEST_F(QuicConnectionTest, SendSchedulerForce) { |
922 // 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. |
923 QuicPacket* packet = ConstructDataPacket(1, 0); | 926 QuicPacket* packet = ConstructDataPacket(1, 0); |
924 EXPECT_CALL(*scheduler_, TimeUntilSend(true)).Times(0); | 927 EXPECT_CALL(*scheduler_, TimeUntilSend(true)).Times(0); |
925 EXPECT_CALL(*scheduler_, SentPacket(_, _, _)); | 928 EXPECT_CALL(*scheduler_, SentPacket(_, _, _)); |
926 connection_.SendPacket(1, packet, true, true, false); | 929 connection_.SendPacket(1, packet, true, true, false); |
927 EXPECT_EQ(0u, connection_.NumQueuedPackets()); | 930 EXPECT_EQ(0u, connection_.NumQueuedPackets()); |
928 } | 931 } |
929 | 932 |
930 // TODO(rch): Enable after we get non-blocking sockets. | 933 // TODO(rch): Enable after we get non-blocking sockets. |
931 TEST_F(QuicConnectionTest, DISABLED_SendSchedulerEAGAIN) { | 934 TEST_F(QuicConnectionTest, DISABLED_SendSchedulerEAGAIN) { |
932 QuicPacket* packet = ConstructDataPacket(1, 0); | 935 QuicPacket* packet = ConstructDataPacket(1, 0); |
933 helper_->set_blocked(true); | 936 helper_->set_blocked(true); |
934 EXPECT_CALL(*scheduler_, TimeUntilSend(false)).WillOnce(testing::Return( | 937 EXPECT_CALL(*scheduler_, TimeUntilSend(false)).WillOnce(testing::Return( |
935 QuicTime::Delta())); | 938 QuicTime::Delta::Zero())); |
936 EXPECT_CALL(*scheduler_, SentPacket(1, _, _)).Times(0); | 939 EXPECT_CALL(*scheduler_, SentPacket(1, _, _)).Times(0); |
937 connection_.SendPacket(1, packet, true, false, false); | 940 connection_.SendPacket(1, packet, true, false, false); |
938 EXPECT_EQ(1u, connection_.NumQueuedPackets()); | 941 EXPECT_EQ(1u, connection_.NumQueuedPackets()); |
939 } | 942 } |
940 | 943 |
941 TEST_F(QuicConnectionTest, SendSchedulerDelayThenSend) { | 944 TEST_F(QuicConnectionTest, SendSchedulerDelayThenSend) { |
942 // 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. |
943 QuicPacket* packet = ConstructDataPacket(1, 0); | 946 QuicPacket* packet = ConstructDataPacket(1, 0); |
944 EXPECT_CALL(*scheduler_, TimeUntilSend(false)).WillOnce(testing::Return( | 947 EXPECT_CALL(*scheduler_, TimeUntilSend(false)).WillOnce(testing::Return( |
945 QuicTime::Delta::FromMicroseconds(1))); | 948 QuicTime::Delta::FromMicroseconds(1))); |
946 connection_.SendPacket(1, packet, true, false, false); | 949 connection_.SendPacket(1, packet, true, false, false); |
947 EXPECT_EQ(1u, connection_.NumQueuedPackets()); | 950 EXPECT_EQ(1u, connection_.NumQueuedPackets()); |
948 | 951 |
949 // Advance the clock to fire the alarm, and configure the scheduler | 952 // Advance the clock to fire the alarm, and configure the scheduler |
950 // to permit the packet to be sent. | 953 // to permit the packet to be sent. |
951 EXPECT_CALL(*scheduler_, TimeUntilSend(false)).WillOnce(testing::Return( | 954 EXPECT_CALL(*scheduler_, TimeUntilSend(false)).WillOnce(testing::Return( |
952 QuicTime::Delta())); | 955 QuicTime::Delta::Zero())); |
953 clock_.AdvanceTime(QuicTime::Delta::FromMicroseconds(1)); | 956 clock_.AdvanceTime(QuicTime::Delta::FromMicroseconds(1)); |
954 EXPECT_CALL(*scheduler_, SentPacket(_, _, _)); | 957 EXPECT_CALL(*scheduler_, SentPacket(_, _, _)); |
955 EXPECT_CALL(visitor_, OnCanWrite()); | 958 EXPECT_CALL(visitor_, OnCanWrite()); |
956 connection_.OnCanWrite(); | 959 connection_.OnCanWrite(); |
957 EXPECT_EQ(0u, connection_.NumQueuedPackets()); | 960 EXPECT_EQ(0u, connection_.NumQueuedPackets()); |
958 } | 961 } |
959 | 962 |
960 TEST_F(QuicConnectionTest, SendSchedulerDelayThenRetransmit) { | 963 TEST_F(QuicConnectionTest, SendSchedulerDelayThenRetransmit) { |
961 // 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. |
962 QuicPacket* packet = ConstructDataPacket(1, 0); | 965 QuicPacket* packet = ConstructDataPacket(1, 0); |
963 EXPECT_CALL(*scheduler_, TimeUntilSend(true)).WillOnce(testing::Return( | 966 EXPECT_CALL(*scheduler_, TimeUntilSend(true)).WillOnce(testing::Return( |
964 QuicTime::Delta::FromMicroseconds(1))); | 967 QuicTime::Delta::FromMicroseconds(1))); |
965 connection_.SendPacket(1, packet, true, false, true); | 968 connection_.SendPacket(1, packet, true, false, true); |
966 EXPECT_EQ(1u, connection_.NumQueuedPackets()); | 969 EXPECT_EQ(1u, connection_.NumQueuedPackets()); |
967 | 970 |
968 // Advance the clock to fire the alarm, and configure the scheduler | 971 // Advance the clock to fire the alarm, and configure the scheduler |
969 // to permit the packet to be sent. | 972 // to permit the packet to be sent. |
970 EXPECT_CALL(*scheduler_, TimeUntilSend(true)).WillOnce(testing::Return( | 973 EXPECT_CALL(*scheduler_, TimeUntilSend(true)).WillOnce(testing::Return( |
971 QuicTime::Delta())); | 974 QuicTime::Delta::Zero())); |
972 | 975 |
973 // Ensure the scheduler is notified this is a retransmit. | 976 // Ensure the scheduler is notified this is a retransmit. |
974 EXPECT_CALL(*scheduler_, SentPacket(1, _, true)); | 977 EXPECT_CALL(*scheduler_, SentPacket(1, _, true)); |
975 clock_.AdvanceTime(QuicTime::Delta::FromMicroseconds(1)); | 978 clock_.AdvanceTime(QuicTime::Delta::FromMicroseconds(1)); |
976 EXPECT_CALL(visitor_, OnCanWrite()); | 979 EXPECT_CALL(visitor_, OnCanWrite()); |
977 connection_.OnCanWrite(); | 980 connection_.OnCanWrite(); |
978 EXPECT_EQ(0u, connection_.NumQueuedPackets()); | 981 EXPECT_EQ(0u, connection_.NumQueuedPackets()); |
979 } | 982 } |
980 | 983 |
981 TEST_F(QuicConnectionTest, SendSchedulerDelayAndQueue) { | 984 TEST_F(QuicConnectionTest, SendSchedulerDelayAndQueue) { |
(...skipping 13 matching lines...) Expand all Loading... |
995 QuicPacket* packet = ConstructDataPacket(1, 0); | 998 QuicPacket* packet = ConstructDataPacket(1, 0); |
996 EXPECT_CALL(*scheduler_, TimeUntilSend(false)).WillOnce(testing::Return( | 999 EXPECT_CALL(*scheduler_, TimeUntilSend(false)).WillOnce(testing::Return( |
997 QuicTime::Delta::FromMicroseconds(10))); | 1000 QuicTime::Delta::FromMicroseconds(10))); |
998 connection_.SendPacket(1, packet, true, false, false); | 1001 connection_.SendPacket(1, packet, true, false, false); |
999 EXPECT_EQ(1u, connection_.NumQueuedPackets()); | 1002 EXPECT_EQ(1u, connection_.NumQueuedPackets()); |
1000 | 1003 |
1001 // Now send non-retransmitting information, that we're not going to | 1004 // Now send non-retransmitting information, that we're not going to |
1002 // retransmit 3. The far end should stop waiting for it. | 1005 // retransmit 3. The far end should stop waiting for it. |
1003 QuicAckFrame frame(0, 1); | 1006 QuicAckFrame frame(0, 1); |
1004 EXPECT_CALL(*scheduler_, TimeUntilSend(false)).WillRepeatedly(testing::Return( | 1007 EXPECT_CALL(*scheduler_, TimeUntilSend(false)).WillRepeatedly(testing::Return( |
1005 QuicTime::Delta())); | 1008 QuicTime::Delta::Zero())); |
1006 EXPECT_CALL(*scheduler_, SentPacket(_, _, _)); | 1009 EXPECT_CALL(*scheduler_, SentPacket(_, _, _)); |
1007 EXPECT_CALL(visitor_, OnCanWrite()); | 1010 EXPECT_CALL(visitor_, OnCanWrite()); |
1008 ProcessAckPacket(&frame); | 1011 ProcessAckPacket(&frame); |
1009 | 1012 |
1010 EXPECT_EQ(0u, connection_.NumQueuedPackets()); | 1013 EXPECT_EQ(0u, connection_.NumQueuedPackets()); |
1011 // Ensure alarm is not set | 1014 // Ensure alarm is not set |
1012 EXPECT_FALSE(helper_->IsSendAlarmSet()); | 1015 EXPECT_FALSE(helper_->IsSendAlarmSet()); |
1013 } | 1016 } |
1014 | 1017 |
1015 TEST_F(QuicConnectionTest, SendSchedulerDelayThenAckAndHold) { | 1018 TEST_F(QuicConnectionTest, SendSchedulerDelayThenAckAndHold) { |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1065 | 1068 |
1066 // Queue the first packet. | 1069 // Queue the first packet. |
1067 EXPECT_CALL(*scheduler_, SentPacket(_, _, _)).Times(17); | 1070 EXPECT_CALL(*scheduler_, SentPacket(_, _, _)).Times(17); |
1068 EXPECT_EQ(17u, connection_.SendStreamData( | 1071 EXPECT_EQ(17u, connection_.SendStreamData( |
1069 1, "EnoughDataToQueue", 0, false, NULL).bytes_consumed); | 1072 1, "EnoughDataToQueue", 0, false, NULL).bytes_consumed); |
1070 } | 1073 } |
1071 | 1074 |
1072 } // namespace | 1075 } // namespace |
1073 } // namespace test | 1076 } // namespace test |
1074 } // namespace net | 1077 } // namespace net |
OLD | NEW |