OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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_sent_packet_manager.h" | 5 #include "net/quic/quic_sent_packet_manager.h" |
6 | 6 |
7 #include "base/stl_util.h" | 7 #include "base/stl_util.h" |
8 #include "net/quic/quic_flags.h" | 8 #include "net/quic/quic_flags.h" |
9 #include "net/quic/test_tools/quic_config_peer.h" | 9 #include "net/quic/test_tools/quic_config_peer.h" |
10 #include "net/quic/test_tools/quic_sent_packet_manager_peer.h" | 10 #include "net/quic/test_tools/quic_sent_packet_manager_peer.h" |
(...skipping 19 matching lines...) Expand all Loading... |
30 const uint32 kDefaultLength = 1000; | 30 const uint32 kDefaultLength = 1000; |
31 | 31 |
32 // Matcher to check the key of the key-value pair it receives as first argument | 32 // Matcher to check the key of the key-value pair it receives as first argument |
33 // equals its second argument. | 33 // equals its second argument. |
34 MATCHER(KeyEq, "") { | 34 MATCHER(KeyEq, "") { |
35 return std::tr1::get<0>(arg).first == std::tr1::get<1>(arg); | 35 return std::tr1::get<0>(arg).first == std::tr1::get<1>(arg); |
36 } | 36 } |
37 | 37 |
38 class MockDebugDelegate : public QuicSentPacketManager::DebugDelegate { | 38 class MockDebugDelegate : public QuicSentPacketManager::DebugDelegate { |
39 public: | 39 public: |
40 MOCK_METHOD2(OnSpuriousPacketRetransmition, | 40 MOCK_METHOD2(OnSpuriousPacketRetransmission, |
41 void(TransmissionType transmission_type, | 41 void(TransmissionType transmission_type, |
42 QuicByteCount byte_size)); | 42 QuicByteCount byte_size)); |
43 }; | 43 }; |
44 | 44 |
45 class QuicSentPacketManagerTest : public ::testing::TestWithParam<bool> { | 45 class QuicSentPacketManagerTest : public ::testing::TestWithParam<bool> { |
46 protected: | 46 protected: |
47 QuicSentPacketManagerTest() | 47 QuicSentPacketManagerTest() |
48 : manager_(true, &clock_, &stats_, kCubic, kNack, false), | 48 : manager_(true, &clock_, &stats_, kCubic, kNack, false), |
49 send_algorithm_(new StrictMock<MockSendAlgorithm>), | 49 send_algorithm_(new StrictMock<MockSendAlgorithm>), |
50 network_change_visitor_(new StrictMock<MockNetworkChangeVisitor>) { | 50 network_change_visitor_(new StrictMock<MockNetworkChangeVisitor>) { |
(...skipping 326 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
377 // No packets remain unacked. | 377 // No packets remain unacked. |
378 VerifyUnackedPackets(nullptr, 0); | 378 VerifyUnackedPackets(nullptr, 0); |
379 EXPECT_FALSE(QuicSentPacketManagerPeer::HasPendingPackets(&manager_)); | 379 EXPECT_FALSE(QuicSentPacketManagerPeer::HasPendingPackets(&manager_)); |
380 VerifyRetransmittablePackets(nullptr, 0); | 380 VerifyRetransmittablePackets(nullptr, 0); |
381 | 381 |
382 // Verify that the retransmission alarm would not fire, | 382 // Verify that the retransmission alarm would not fire, |
383 // since there is no retransmittable data outstanding. | 383 // since there is no retransmittable data outstanding. |
384 EXPECT_EQ(QuicTime::Zero(), manager_.GetRetransmissionTime()); | 384 EXPECT_EQ(QuicTime::Zero(), manager_.GetRetransmissionTime()); |
385 } | 385 } |
386 | 386 |
387 TEST_F(QuicSentPacketManagerTest, RetransmitTwiceThenAckPreviousBeforeSend) { | 387 TEST_F(QuicSentPacketManagerTest, |
| 388 DISABLED_RetransmitTwiceThenAckPreviousBeforeSend) { |
388 SendDataPacket(1); | 389 SendDataPacket(1); |
389 RetransmitAndSendPacket(1, 2); | 390 RetransmitAndSendPacket(1, 2); |
390 | 391 |
391 // Fire the RTO, which will mark 2 for retransmission (but will not send it). | 392 // Fire the RTO, which will mark 2 for retransmission (but will not send it). |
392 EXPECT_CALL(*send_algorithm_, OnRetransmissionTimeout(true)); | 393 EXPECT_CALL(*send_algorithm_, OnRetransmissionTimeout(true)); |
393 EXPECT_CALL(*network_change_visitor_, OnCongestionWindowChange()); | 394 EXPECT_CALL(*network_change_visitor_, OnCongestionWindowChange()); |
394 manager_.OnRetransmissionTimeout(); | 395 manager_.OnRetransmissionTimeout(); |
395 EXPECT_TRUE(manager_.HasPendingRetransmissions()); | 396 EXPECT_TRUE(manager_.HasPendingRetransmissions()); |
396 | 397 |
397 // Ack 1 but not 2, before 2 is able to be sent. | 398 // Ack 1 but not 2, before 2 is able to be sent. |
(...skipping 11 matching lines...) Expand all Loading... |
409 EXPECT_FALSE(QuicSentPacketManagerPeer::HasPendingPackets(&manager_)); | 410 EXPECT_FALSE(QuicSentPacketManagerPeer::HasPendingPackets(&manager_)); |
410 VerifyRetransmittablePackets(nullptr, 0); | 411 VerifyRetransmittablePackets(nullptr, 0); |
411 | 412 |
412 // Verify that the retransmission alarm would not fire, | 413 // Verify that the retransmission alarm would not fire, |
413 // since there is no retransmittable data outstanding. | 414 // since there is no retransmittable data outstanding. |
414 EXPECT_EQ(QuicTime::Zero(), manager_.GetRetransmissionTime()); | 415 EXPECT_EQ(QuicTime::Zero(), manager_.GetRetransmissionTime()); |
415 } | 416 } |
416 | 417 |
417 TEST_F(QuicSentPacketManagerTest, RetransmitTwiceThenAckFirst) { | 418 TEST_F(QuicSentPacketManagerTest, RetransmitTwiceThenAckFirst) { |
418 StrictMock<MockDebugDelegate> debug_delegate; | 419 StrictMock<MockDebugDelegate> debug_delegate; |
419 EXPECT_CALL(debug_delegate, OnSpuriousPacketRetransmition( | 420 EXPECT_CALL(debug_delegate, OnSpuriousPacketRetransmission( |
420 TLP_RETRANSMISSION, kDefaultLength)).Times(2); | 421 TLP_RETRANSMISSION, kDefaultLength)).Times(2); |
421 manager_.set_debug_delegate(&debug_delegate); | 422 manager_.set_debug_delegate(&debug_delegate); |
422 | 423 |
423 SendDataPacket(1); | 424 SendDataPacket(1); |
424 RetransmitAndSendPacket(1, 2); | 425 RetransmitAndSendPacket(1, 2); |
425 RetransmitAndSendPacket(2, 3); | 426 RetransmitAndSendPacket(2, 3); |
426 QuicTime::Delta rtt = QuicTime::Delta::FromMilliseconds(15); | 427 QuicTime::Delta rtt = QuicTime::Delta::FromMilliseconds(15); |
427 clock_.AdvanceTime(rtt); | 428 clock_.AdvanceTime(rtt); |
428 | 429 |
429 // Ack 1 but not 2 or 3. | 430 // Ack 1 but not 2 or 3. |
430 ExpectAck(1); | 431 ExpectAck(1); |
(...skipping 405 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
836 rto_packet_time = clock_.Now(); | 837 rto_packet_time = clock_.Now(); |
837 } | 838 } |
838 EXPECT_CALL(*send_algorithm_, RetransmissionDelay()) | 839 EXPECT_CALL(*send_algorithm_, RetransmissionDelay()) |
839 .WillOnce(Return(QuicTime::Delta::FromSeconds(1))); | 840 .WillOnce(Return(QuicTime::Delta::FromSeconds(1))); |
840 EXPECT_EQ(rto_packet_time.Add(QuicTime::Delta::FromSeconds(1)), | 841 EXPECT_EQ(rto_packet_time.Add(QuicTime::Delta::FromSeconds(1)), |
841 manager_.GetRetransmissionTime()); | 842 manager_.GetRetransmissionTime()); |
842 | 843 |
843 // Advance the time enough to ensure all packets are RTO'd. | 844 // Advance the time enough to ensure all packets are RTO'd. |
844 clock_.AdvanceTime(QuicTime::Delta::FromMilliseconds(1000)); | 845 clock_.AdvanceTime(QuicTime::Delta::FromMilliseconds(1000)); |
845 | 846 |
846 // The final RTO abandons all of them. | 847 if (!FLAGS_quic_use_new_rto) { |
847 EXPECT_CALL(*send_algorithm_, OnRetransmissionTimeout(true)); | 848 // The final RTO abandons all of them. |
848 EXPECT_CALL(*network_change_visitor_, OnCongestionWindowChange()); | 849 EXPECT_CALL(*send_algorithm_, OnRetransmissionTimeout(true)); |
| 850 EXPECT_CALL(*network_change_visitor_, OnCongestionWindowChange()); |
| 851 } |
849 manager_.OnRetransmissionTimeout(); | 852 manager_.OnRetransmissionTimeout(); |
850 EXPECT_TRUE(manager_.HasPendingRetransmissions()); | 853 EXPECT_TRUE(manager_.HasPendingRetransmissions()); |
851 EXPECT_EQ(2u, stats_.tlp_count); | 854 EXPECT_EQ(2u, stats_.tlp_count); |
852 EXPECT_EQ(1u, stats_.rto_count); | 855 EXPECT_EQ(1u, stats_.rto_count); |
| 856 |
| 857 // Send and Ack the RTO and ensure OnRetransmissionTimeout is called. |
| 858 if (FLAGS_quic_use_new_rto) { |
| 859 EXPECT_EQ(102 * kDefaultLength, |
| 860 QuicSentPacketManagerPeer::GetBytesInFlight(&manager_)); |
| 861 |
| 862 RetransmitNextPacket(103); |
| 863 QuicAckFrame ack_frame; |
| 864 ack_frame.largest_observed = 103; |
| 865 for (int i = 0; i < 103; ++i) { |
| 866 ack_frame.missing_packets.insert(i); |
| 867 } |
| 868 EXPECT_CALL(*send_algorithm_, OnRetransmissionTimeout(true)); |
| 869 EXPECT_CALL(*send_algorithm_, |
| 870 OnCongestionEvent(true, _, ElementsAre(Pair(103, _)), _)); |
| 871 EXPECT_CALL(*network_change_visitor_, OnCongestionWindowChange()); |
| 872 EXPECT_CALL(*network_change_visitor_, OnRttChange()); |
| 873 manager_.OnIncomingAck(ack_frame, clock_.ApproximateNow()); |
| 874 // All packets before 103 should be lost. |
| 875 EXPECT_EQ(0u, QuicSentPacketManagerPeer::GetBytesInFlight(&manager_)); |
| 876 } |
853 } | 877 } |
854 | 878 |
855 TEST_F(QuicSentPacketManagerTest, CryptoHandshakeTimeout) { | 879 TEST_F(QuicSentPacketManagerTest, CryptoHandshakeTimeout) { |
856 // Send 2 crypto packets and 3 data packets. | 880 // Send 2 crypto packets and 3 data packets. |
857 const size_t kNumSentCryptoPackets = 2; | 881 const size_t kNumSentCryptoPackets = 2; |
858 for (size_t i = 1; i <= kNumSentCryptoPackets; ++i) { | 882 for (size_t i = 1; i <= kNumSentCryptoPackets; ++i) { |
859 SendCryptoPacket(i); | 883 SendCryptoPacket(i); |
860 } | 884 } |
861 const size_t kNumSentDataPackets = 3; | 885 const size_t kNumSentDataPackets = 3; |
862 for (size_t i = 1; i <= kNumSentDataPackets; ++i) { | 886 for (size_t i = 1; i <= kNumSentDataPackets; ++i) { |
(...skipping 204 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1067 manager_.OnIncomingAck(ack_frame, clock_.Now()); | 1091 manager_.OnIncomingAck(ack_frame, clock_.Now()); |
1068 | 1092 |
1069 EXPECT_EQ(min_rtt, | 1093 EXPECT_EQ(min_rtt, |
1070 QuicSentPacketManagerPeer::GetRttStats(&manager_)->min_rtt()); | 1094 QuicSentPacketManagerPeer::GetRttStats(&manager_)->min_rtt()); |
1071 EXPECT_EQ(QuicTime::Delta::FromMilliseconds(100), | 1095 EXPECT_EQ(QuicTime::Delta::FromMilliseconds(100), |
1072 QuicSentPacketManagerPeer::GetRttStats( | 1096 QuicSentPacketManagerPeer::GetRttStats( |
1073 &manager_)->recent_min_rtt()); | 1097 &manager_)->recent_min_rtt()); |
1074 } | 1098 } |
1075 | 1099 |
1076 TEST_F(QuicSentPacketManagerTest, RetransmissionTimeout) { | 1100 TEST_F(QuicSentPacketManagerTest, RetransmissionTimeout) { |
1077 // Send 100 packets and then ensure all are abandoned when the RTO fires. | 1101 // Send 100 packets. |
1078 const size_t kNumSentPackets = 100; | 1102 const size_t kNumSentPackets = 100; |
1079 for (size_t i = 1; i <= kNumSentPackets; ++i) { | 1103 for (size_t i = 1; i <= kNumSentPackets; ++i) { |
1080 SendDataPacket(i); | 1104 SendDataPacket(i); |
1081 } | 1105 } |
1082 | 1106 |
1083 EXPECT_CALL(*send_algorithm_, OnRetransmissionTimeout(true)); | 1107 if (!FLAGS_quic_use_new_rto) { |
1084 EXPECT_CALL(*network_change_visitor_, OnCongestionWindowChange()); | 1108 EXPECT_CALL(*send_algorithm_, OnRetransmissionTimeout(true)); |
| 1109 EXPECT_CALL(*network_change_visitor_, OnCongestionWindowChange()); |
| 1110 } |
1085 EXPECT_FALSE(manager_.MaybeRetransmitTailLossProbe()); | 1111 EXPECT_FALSE(manager_.MaybeRetransmitTailLossProbe()); |
1086 manager_.OnRetransmissionTimeout(); | 1112 manager_.OnRetransmissionTimeout(); |
| 1113 EXPECT_TRUE(manager_.HasPendingRetransmissions()); |
| 1114 if (FLAGS_quic_use_new_rto) { |
| 1115 EXPECT_EQ(100 * kDefaultLength, |
| 1116 QuicSentPacketManagerPeer::GetBytesInFlight(&manager_)); |
| 1117 } else { |
| 1118 // Ensure all are abandoned when the RTO fires. |
| 1119 EXPECT_EQ(0u, QuicSentPacketManagerPeer::GetBytesInFlight(&manager_)); |
| 1120 } |
| 1121 RetransmitNextPacket(101); |
| 1122 RetransmitNextPacket(102); |
| 1123 if (FLAGS_quic_use_new_rto) { |
| 1124 EXPECT_FALSE(manager_.HasPendingRetransmissions()); |
| 1125 } else { |
| 1126 EXPECT_TRUE(manager_.HasPendingRetransmissions()); |
| 1127 } |
| 1128 |
| 1129 // Ack a retransmission. |
| 1130 if (FLAGS_quic_use_new_rto) { |
| 1131 EXPECT_CALL(*send_algorithm_, OnRetransmissionTimeout(true)); |
| 1132 } |
| 1133 QuicAckFrame ack_frame; |
| 1134 ack_frame.delta_time_largest_observed = QuicTime::Delta::Zero(); |
| 1135 ack_frame.largest_observed = 102; |
| 1136 for (int i = 0; i < 102; ++i) { |
| 1137 ack_frame.missing_packets.insert(i); |
| 1138 } |
| 1139 EXPECT_CALL(*send_algorithm_, |
| 1140 OnCongestionEvent(true, _, ElementsAre(Pair(102, _)), _)); |
| 1141 EXPECT_CALL(*network_change_visitor_, OnCongestionWindowChange()); |
| 1142 EXPECT_CALL(*network_change_visitor_, OnRttChange()); |
| 1143 manager_.OnIncomingAck(ack_frame, clock_.Now()); |
| 1144 } |
| 1145 |
| 1146 TEST_F(QuicSentPacketManagerTest, TwoRetransmissionTimeoutsAckSecond) { |
| 1147 // Send 1 packet. |
| 1148 SendDataPacket(1); |
| 1149 |
| 1150 if (!FLAGS_quic_use_new_rto) { |
| 1151 EXPECT_CALL(*send_algorithm_, OnRetransmissionTimeout(true)); |
| 1152 EXPECT_CALL(*network_change_visitor_, OnCongestionWindowChange()); |
| 1153 } |
| 1154 manager_.OnRetransmissionTimeout(); |
| 1155 EXPECT_TRUE(manager_.HasPendingRetransmissions()); |
| 1156 if (FLAGS_quic_use_new_rto) { |
| 1157 EXPECT_EQ(kDefaultLength, |
| 1158 QuicSentPacketManagerPeer::GetBytesInFlight(&manager_)); |
| 1159 } else { |
| 1160 // Ensure all are abandoned when the RTO fires. |
| 1161 EXPECT_EQ(0u, QuicSentPacketManagerPeer::GetBytesInFlight(&manager_)); |
| 1162 } |
| 1163 RetransmitNextPacket(2); |
| 1164 EXPECT_FALSE(manager_.HasPendingRetransmissions()); |
| 1165 |
| 1166 // Rto a second time. |
| 1167 if (!FLAGS_quic_use_new_rto) { |
| 1168 EXPECT_CALL(*send_algorithm_, OnRetransmissionTimeout(true)); |
| 1169 EXPECT_CALL(*network_change_visitor_, OnCongestionWindowChange()); |
| 1170 } |
| 1171 manager_.OnRetransmissionTimeout(); |
| 1172 EXPECT_TRUE(manager_.HasPendingRetransmissions()); |
| 1173 if (FLAGS_quic_use_new_rto) { |
| 1174 EXPECT_EQ(2 * kDefaultLength, |
| 1175 QuicSentPacketManagerPeer::GetBytesInFlight(&manager_)); |
| 1176 } else { |
| 1177 // Ensure all are abandoned when the RTO fires. |
| 1178 EXPECT_EQ(0u, QuicSentPacketManagerPeer::GetBytesInFlight(&manager_)); |
| 1179 } |
| 1180 RetransmitNextPacket(3); |
| 1181 EXPECT_FALSE(manager_.HasPendingRetransmissions()); |
| 1182 |
| 1183 // Ack a retransmission and ensure OnRetransmissionTimeout is called. |
| 1184 if (FLAGS_quic_use_new_rto) { |
| 1185 EXPECT_CALL(*send_algorithm_, OnRetransmissionTimeout(true)); |
| 1186 } |
| 1187 QuicAckFrame ack_frame; |
| 1188 ack_frame.delta_time_largest_observed = QuicTime::Delta::Zero(); |
| 1189 ack_frame.largest_observed = 2; |
| 1190 ack_frame.missing_packets.insert(1); |
| 1191 if (FLAGS_quic_use_new_rto) { |
| 1192 ExpectAck(2); |
| 1193 } else { |
| 1194 ExpectUpdatedRtt(2); |
| 1195 } |
| 1196 manager_.OnIncomingAck(ack_frame, clock_.Now()); |
| 1197 |
| 1198 if (FLAGS_quic_use_new_rto) { |
| 1199 // The original packet and newest should be outstanding. |
| 1200 EXPECT_EQ(2 * kDefaultLength, |
| 1201 QuicSentPacketManagerPeer::GetBytesInFlight(&manager_)); |
| 1202 } else { |
| 1203 EXPECT_EQ(kDefaultLength, |
| 1204 QuicSentPacketManagerPeer::GetBytesInFlight(&manager_)); |
| 1205 } |
| 1206 } |
| 1207 |
| 1208 TEST_F(QuicSentPacketManagerTest, TwoRetransmissionTimeoutsAckFirst) { |
| 1209 // Send 1 packet. |
| 1210 SendDataPacket(1); |
| 1211 |
| 1212 if (!FLAGS_quic_use_new_rto) { |
| 1213 EXPECT_CALL(*send_algorithm_, OnRetransmissionTimeout(true)); |
| 1214 EXPECT_CALL(*network_change_visitor_, OnCongestionWindowChange()); |
| 1215 } |
| 1216 manager_.OnRetransmissionTimeout(); |
| 1217 EXPECT_TRUE(manager_.HasPendingRetransmissions()); |
| 1218 if (FLAGS_quic_use_new_rto) { |
| 1219 EXPECT_EQ(kDefaultLength, |
| 1220 QuicSentPacketManagerPeer::GetBytesInFlight(&manager_)); |
| 1221 } else { |
| 1222 // Ensure all are abandoned when the RTO fires. |
| 1223 EXPECT_EQ(0u, QuicSentPacketManagerPeer::GetBytesInFlight(&manager_)); |
| 1224 } |
| 1225 RetransmitNextPacket(2); |
| 1226 EXPECT_FALSE(manager_.HasPendingRetransmissions()); |
| 1227 |
| 1228 // Rto a second time. |
| 1229 if (!FLAGS_quic_use_new_rto) { |
| 1230 EXPECT_CALL(*send_algorithm_, OnRetransmissionTimeout(true)); |
| 1231 EXPECT_CALL(*network_change_visitor_, OnCongestionWindowChange()); |
| 1232 } |
| 1233 manager_.OnRetransmissionTimeout(); |
| 1234 EXPECT_TRUE(manager_.HasPendingRetransmissions()); |
| 1235 if (FLAGS_quic_use_new_rto) { |
| 1236 EXPECT_EQ(2 * kDefaultLength, |
| 1237 QuicSentPacketManagerPeer::GetBytesInFlight(&manager_)); |
| 1238 } else { |
| 1239 // Ensure all are abandoned when the RTO fires. |
| 1240 EXPECT_EQ(0u, QuicSentPacketManagerPeer::GetBytesInFlight(&manager_)); |
| 1241 } |
| 1242 RetransmitNextPacket(3); |
| 1243 EXPECT_FALSE(manager_.HasPendingRetransmissions()); |
| 1244 |
| 1245 // Ack a retransmission and ensure OnRetransmissionTimeout is called. |
| 1246 if (FLAGS_quic_use_new_rto) { |
| 1247 EXPECT_CALL(*send_algorithm_, OnRetransmissionTimeout(true)); |
| 1248 } |
| 1249 QuicAckFrame ack_frame; |
| 1250 ack_frame.delta_time_largest_observed = QuicTime::Delta::Zero(); |
| 1251 ack_frame.largest_observed = 3; |
| 1252 ack_frame.missing_packets.insert(1); |
| 1253 ack_frame.missing_packets.insert(2); |
| 1254 ExpectAck(3); |
| 1255 manager_.OnIncomingAck(ack_frame, clock_.Now()); |
| 1256 |
| 1257 if (FLAGS_quic_use_new_rto) { |
| 1258 // The first two packets should still be outstanding. |
| 1259 EXPECT_EQ(2 * kDefaultLength, |
| 1260 QuicSentPacketManagerPeer::GetBytesInFlight(&manager_)); |
| 1261 } else { |
| 1262 EXPECT_EQ(0u, QuicSentPacketManagerPeer::GetBytesInFlight(&manager_)); |
| 1263 } |
1087 } | 1264 } |
1088 | 1265 |
1089 TEST_F(QuicSentPacketManagerTest, GetTransmissionTime) { | 1266 TEST_F(QuicSentPacketManagerTest, GetTransmissionTime) { |
1090 EXPECT_EQ(QuicTime::Zero(), manager_.GetRetransmissionTime()); | 1267 EXPECT_EQ(QuicTime::Zero(), manager_.GetRetransmissionTime()); |
1091 } | 1268 } |
1092 | 1269 |
1093 TEST_F(QuicSentPacketManagerTest, GetTransmissionTimeCryptoHandshake) { | 1270 TEST_F(QuicSentPacketManagerTest, GetTransmissionTimeCryptoHandshake) { |
1094 SendCryptoPacket(1); | 1271 SendCryptoPacket(1); |
1095 | 1272 |
1096 // Check the min. | 1273 // Check the min. |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1148 EXPECT_CALL(*send_algorithm_, TimeUntilSend(_, _, _)).WillOnce(Return( | 1325 EXPECT_CALL(*send_algorithm_, TimeUntilSend(_, _, _)).WillOnce(Return( |
1149 QuicTime::Delta::Infinite())); | 1326 QuicTime::Delta::Infinite())); |
1150 EXPECT_EQ(QuicTime::Delta::Infinite(), | 1327 EXPECT_EQ(QuicTime::Delta::Infinite(), |
1151 manager_.TimeUntilSend(clock_.Now(), HAS_RETRANSMITTABLE_DATA)); | 1328 manager_.TimeUntilSend(clock_.Now(), HAS_RETRANSMITTABLE_DATA)); |
1152 EXPECT_FALSE(manager_.HasPendingRetransmissions()); | 1329 EXPECT_FALSE(manager_.HasPendingRetransmissions()); |
1153 | 1330 |
1154 expected_time = clock_.Now().Add(expected_tlp_delay); | 1331 expected_time = clock_.Now().Add(expected_tlp_delay); |
1155 EXPECT_EQ(expected_time, manager_.GetRetransmissionTime()); | 1332 EXPECT_EQ(expected_time, manager_.GetRetransmissionTime()); |
1156 } | 1333 } |
1157 | 1334 |
1158 TEST_F(QuicSentPacketManagerTest, GetTransmissionTimeRTO) { | 1335 TEST_F(QuicSentPacketManagerTest, GetTransmissionTimeSpuriousRTO) { |
1159 QuicSentPacketManagerPeer::GetRttStats(&manager_)->UpdateRtt( | 1336 QuicSentPacketManagerPeer::GetRttStats(&manager_)->UpdateRtt( |
1160 QuicTime::Delta::FromMilliseconds(100), | 1337 QuicTime::Delta::FromMilliseconds(100), |
1161 QuicTime::Delta::Zero(), | 1338 QuicTime::Delta::Zero(), |
1162 QuicTime::Zero()); | 1339 QuicTime::Zero()); |
1163 | 1340 |
1164 SendDataPacket(1); | 1341 SendDataPacket(1); |
1165 SendDataPacket(2); | 1342 SendDataPacket(2); |
1166 SendDataPacket(3); | 1343 SendDataPacket(3); |
1167 SendDataPacket(4); | 1344 SendDataPacket(4); |
1168 | 1345 |
1169 QuicTime::Delta expected_rto_delay = QuicTime::Delta::FromMilliseconds(500); | 1346 QuicTime::Delta expected_rto_delay = QuicTime::Delta::FromMilliseconds(500); |
1170 EXPECT_CALL(*send_algorithm_, RetransmissionDelay()) | 1347 EXPECT_CALL(*send_algorithm_, RetransmissionDelay()) |
1171 .WillRepeatedly(Return(expected_rto_delay)); | 1348 .WillRepeatedly(Return(expected_rto_delay)); |
1172 QuicTime expected_time = clock_.Now().Add(expected_rto_delay); | 1349 QuicTime expected_time = clock_.Now().Add(expected_rto_delay); |
1173 EXPECT_EQ(expected_time, manager_.GetRetransmissionTime()); | 1350 EXPECT_EQ(expected_time, manager_.GetRetransmissionTime()); |
1174 | 1351 |
1175 // Retransmit the packet by invoking the retransmission timeout. | 1352 // Retransmit the packet by invoking the retransmission timeout. |
1176 EXPECT_CALL(*network_change_visitor_, OnCongestionWindowChange()); | 1353 if (!FLAGS_quic_use_new_rto) { |
1177 EXPECT_CALL(*send_algorithm_, OnRetransmissionTimeout(true)); | 1354 EXPECT_CALL(*network_change_visitor_, OnCongestionWindowChange()); |
| 1355 EXPECT_CALL(*send_algorithm_, OnRetransmissionTimeout(true)); |
| 1356 } |
1178 clock_.AdvanceTime(expected_rto_delay); | 1357 clock_.AdvanceTime(expected_rto_delay); |
1179 manager_.OnRetransmissionTimeout(); | 1358 manager_.OnRetransmissionTimeout(); |
1180 EXPECT_EQ(0u, QuicSentPacketManagerPeer::GetBytesInFlight(&manager_)); | 1359 if (FLAGS_quic_use_new_rto) { |
| 1360 // All packets are still considered inflight. |
| 1361 EXPECT_EQ(4 * kDefaultLength, |
| 1362 QuicSentPacketManagerPeer::GetBytesInFlight(&manager_)); |
| 1363 } else { |
| 1364 EXPECT_EQ(0u, QuicSentPacketManagerPeer::GetBytesInFlight(&manager_)); |
| 1365 } |
1181 RetransmitNextPacket(5); | 1366 RetransmitNextPacket(5); |
1182 RetransmitNextPacket(6); | 1367 RetransmitNextPacket(6); |
1183 EXPECT_EQ(2 * kDefaultLength, | 1368 if (FLAGS_quic_use_new_rto) { |
1184 QuicSentPacketManagerPeer::GetBytesInFlight(&manager_)); | 1369 // All previous packets are inflight, plus two rto retransmissions. |
1185 EXPECT_TRUE(manager_.HasPendingRetransmissions()); | 1370 EXPECT_EQ(6 * kDefaultLength, |
| 1371 QuicSentPacketManagerPeer::GetBytesInFlight(&manager_)); |
| 1372 EXPECT_FALSE(manager_.HasPendingRetransmissions()); |
| 1373 } else { |
| 1374 EXPECT_EQ(2 * kDefaultLength, |
| 1375 QuicSentPacketManagerPeer::GetBytesInFlight(&manager_)); |
| 1376 EXPECT_TRUE(manager_.HasPendingRetransmissions()); |
| 1377 } |
1186 | 1378 |
1187 // The delay should double the second time. | 1379 // The delay should double the second time. |
1188 expected_time = clock_.Now().Add(expected_rto_delay).Add(expected_rto_delay); | 1380 expected_time = clock_.Now().Add(expected_rto_delay).Add(expected_rto_delay); |
1189 EXPECT_EQ(expected_time, manager_.GetRetransmissionTime()); | 1381 // Once we always base the timer on the right edge, leaving the older packets |
| 1382 // in flight doesn't change the timeout. |
| 1383 if (!FLAGS_quic_use_new_rto || FLAGS_quic_rto_uses_last_sent) { |
| 1384 EXPECT_EQ(expected_time, manager_.GetRetransmissionTime()); |
| 1385 } |
1190 | 1386 |
1191 // Ack a packet and ensure the RTO goes back to the original value. | 1387 // Ack a packet before the first RTO and ensure the RTO timeout returns to the |
| 1388 // original value and OnRetransmissionTimeout is not called or reverted. |
1192 QuicAckFrame ack_frame; | 1389 QuicAckFrame ack_frame; |
1193 ack_frame.largest_observed = 2; | 1390 ack_frame.largest_observed = 2; |
1194 ack_frame.missing_packets.insert(1); | 1391 ack_frame.missing_packets.insert(1); |
1195 ExpectUpdatedRtt(2); | 1392 if (FLAGS_quic_use_new_rto) { |
1196 EXPECT_CALL(*send_algorithm_, RevertRetransmissionTimeout()); | 1393 ExpectAck(2); |
| 1394 } else { |
| 1395 ExpectUpdatedRtt(2); |
| 1396 EXPECT_CALL(*send_algorithm_, RevertRetransmissionTimeout()); |
| 1397 } |
1197 manager_.OnIncomingAck(ack_frame, clock_.ApproximateNow()); | 1398 manager_.OnIncomingAck(ack_frame, clock_.ApproximateNow()); |
1198 EXPECT_FALSE(manager_.HasPendingRetransmissions()); | 1399 EXPECT_FALSE(manager_.HasPendingRetransmissions()); |
1199 EXPECT_EQ(4 * kDefaultLength, | 1400 if (FLAGS_quic_use_new_rto) { |
1200 QuicSentPacketManagerPeer::GetBytesInFlight(&manager_)); | 1401 EXPECT_EQ(5 * kDefaultLength, |
| 1402 QuicSentPacketManagerPeer::GetBytesInFlight(&manager_)); |
| 1403 } else { |
| 1404 EXPECT_EQ(4 * kDefaultLength, |
| 1405 QuicSentPacketManagerPeer::GetBytesInFlight(&manager_)); |
| 1406 } |
1201 | 1407 |
1202 // Wait 2RTTs from now for the RTO, since it's the max of the RTO time | 1408 // Wait 2RTTs from now for the RTO, since it's the max of the RTO time |
1203 // and the TLP time. In production, there would always be two TLP's first. | 1409 // and the TLP time. In production, there would always be two TLP's first. |
1204 // Since retransmission was spurious, smoothed_rtt_ is expired, and replaced | 1410 // Since retransmission was spurious, smoothed_rtt_ is expired, and replaced |
1205 // by the latest RTT sample of 500ms. | 1411 // by the latest RTT sample of 500ms. |
1206 expected_time = clock_.Now().Add(QuicTime::Delta::FromMilliseconds(1000)); | 1412 expected_time = clock_.Now().Add(QuicTime::Delta::FromMilliseconds(1000)); |
1207 EXPECT_EQ(expected_time, manager_.GetRetransmissionTime()); | 1413 // Once we always base the timer on the right edge, leaving the older packets |
| 1414 // in flight doesn't change the timeout. |
| 1415 if (!FLAGS_quic_use_new_rto || FLAGS_quic_rto_uses_last_sent) { |
| 1416 EXPECT_EQ(expected_time, manager_.GetRetransmissionTime()); |
| 1417 } |
1208 } | 1418 } |
1209 | 1419 |
1210 TEST_F(QuicSentPacketManagerTest, GetTransmissionDelayMin) { | 1420 TEST_F(QuicSentPacketManagerTest, GetTransmissionDelayMin) { |
1211 SendDataPacket(1); | 1421 SendDataPacket(1); |
1212 EXPECT_CALL(*send_algorithm_, RetransmissionDelay()) | 1422 EXPECT_CALL(*send_algorithm_, RetransmissionDelay()) |
1213 .WillRepeatedly(Return(QuicTime::Delta::FromMilliseconds(1))); | 1423 .WillRepeatedly(Return(QuicTime::Delta::FromMilliseconds(1))); |
1214 QuicTime::Delta delay = QuicTime::Delta::FromMilliseconds(200); | 1424 QuicTime::Delta delay = QuicTime::Delta::FromMilliseconds(200); |
1215 | 1425 |
1216 // If the delay is smaller than the min, ensure it exponentially backs off | 1426 // If the delay is smaller than the min, ensure it exponentially backs off |
1217 // from the min. | 1427 // from the min. |
1218 for (int i = 0; i < 5; ++i) { | 1428 for (int i = 0; i < 5; ++i) { |
1219 EXPECT_EQ(delay, | 1429 EXPECT_EQ(delay, |
1220 QuicSentPacketManagerPeer::GetRetransmissionDelay(&manager_)); | 1430 QuicSentPacketManagerPeer::GetRetransmissionDelay(&manager_)); |
1221 delay = delay.Add(delay); | 1431 delay = delay.Add(delay); |
1222 EXPECT_CALL(*network_change_visitor_, OnCongestionWindowChange()); | 1432 if (!FLAGS_quic_use_new_rto) { |
1223 EXPECT_CALL(*send_algorithm_, OnRetransmissionTimeout(true)); | 1433 EXPECT_CALL(*network_change_visitor_, OnCongestionWindowChange()); |
| 1434 EXPECT_CALL(*send_algorithm_, OnRetransmissionTimeout(true)); |
| 1435 } |
1224 manager_.OnRetransmissionTimeout(); | 1436 manager_.OnRetransmissionTimeout(); |
1225 RetransmitNextPacket(i + 2); | 1437 RetransmitNextPacket(i + 2); |
1226 } | 1438 } |
1227 } | 1439 } |
1228 | 1440 |
1229 TEST_F(QuicSentPacketManagerTest, GetTransmissionDelayMax) { | 1441 TEST_F(QuicSentPacketManagerTest, GetTransmissionDelayMax) { |
1230 EXPECT_CALL(*send_algorithm_, RetransmissionDelay()) | 1442 EXPECT_CALL(*send_algorithm_, RetransmissionDelay()) |
1231 .WillOnce(Return(QuicTime::Delta::FromSeconds(500))); | 1443 .WillOnce(Return(QuicTime::Delta::FromSeconds(500))); |
1232 | 1444 |
1233 EXPECT_EQ(QuicTime::Delta::FromSeconds(60), | 1445 EXPECT_EQ(QuicTime::Delta::FromSeconds(60), |
1234 QuicSentPacketManagerPeer::GetRetransmissionDelay(&manager_)); | 1446 QuicSentPacketManagerPeer::GetRetransmissionDelay(&manager_)); |
1235 } | 1447 } |
1236 | 1448 |
1237 TEST_F(QuicSentPacketManagerTest, GetTransmissionDelay) { | 1449 TEST_F(QuicSentPacketManagerTest, GetTransmissionDelay) { |
1238 SendDataPacket(1); | 1450 SendDataPacket(1); |
1239 QuicTime::Delta delay = QuicTime::Delta::FromMilliseconds(500); | 1451 QuicTime::Delta delay = QuicTime::Delta::FromMilliseconds(500); |
1240 EXPECT_CALL(*send_algorithm_, RetransmissionDelay()) | 1452 EXPECT_CALL(*send_algorithm_, RetransmissionDelay()) |
1241 .WillRepeatedly(Return(delay)); | 1453 .WillRepeatedly(Return(delay)); |
1242 | 1454 |
1243 // Delay should back off exponentially. | 1455 // Delay should back off exponentially. |
1244 for (int i = 0; i < 5; ++i) { | 1456 for (int i = 0; i < 5; ++i) { |
1245 EXPECT_EQ(delay, | 1457 EXPECT_EQ(delay, |
1246 QuicSentPacketManagerPeer::GetRetransmissionDelay(&manager_)); | 1458 QuicSentPacketManagerPeer::GetRetransmissionDelay(&manager_)); |
1247 delay = delay.Add(delay); | 1459 delay = delay.Add(delay); |
1248 EXPECT_CALL(*network_change_visitor_, OnCongestionWindowChange()); | 1460 if (!FLAGS_quic_use_new_rto) { |
1249 EXPECT_CALL(*send_algorithm_, OnRetransmissionTimeout(true)); | 1461 EXPECT_CALL(*network_change_visitor_, OnCongestionWindowChange()); |
| 1462 EXPECT_CALL(*send_algorithm_, OnRetransmissionTimeout(true)); |
| 1463 } |
1250 manager_.OnRetransmissionTimeout(); | 1464 manager_.OnRetransmissionTimeout(); |
1251 RetransmitNextPacket(i + 2); | 1465 RetransmitNextPacket(i + 2); |
1252 } | 1466 } |
1253 } | 1467 } |
1254 | 1468 |
1255 TEST_F(QuicSentPacketManagerTest, GetLossDelay) { | 1469 TEST_F(QuicSentPacketManagerTest, GetLossDelay) { |
1256 MockLossAlgorithm* loss_algorithm = new MockLossAlgorithm(); | 1470 MockLossAlgorithm* loss_algorithm = new MockLossAlgorithm(); |
1257 QuicSentPacketManagerPeer::SetLossAlgorithm(&manager_, loss_algorithm); | 1471 QuicSentPacketManagerPeer::SetLossAlgorithm(&manager_, loss_algorithm); |
1258 | 1472 |
1259 EXPECT_CALL(*loss_algorithm, GetLossTimeout()) | 1473 EXPECT_CALL(*loss_algorithm, GetLossTimeout()) |
(...skipping 243 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1503 | 1717 |
1504 EXPECT_CALL(*send_algorithm_, ResumeConnectionState(_)); | 1718 EXPECT_CALL(*send_algorithm_, ResumeConnectionState(_)); |
1505 manager_.ResumeConnectionState(cached_network_params); | 1719 manager_.ResumeConnectionState(cached_network_params); |
1506 EXPECT_EQ(kRttMs * kNumMicrosPerMilli, | 1720 EXPECT_EQ(kRttMs * kNumMicrosPerMilli, |
1507 static_cast<uint64>(manager_.GetRttStats()->initial_rtt_us())); | 1721 static_cast<uint64>(manager_.GetRttStats()->initial_rtt_us())); |
1508 } | 1722 } |
1509 | 1723 |
1510 } // namespace | 1724 } // namespace |
1511 } // namespace test | 1725 } // namespace test |
1512 } // namespace net | 1726 } // namespace net |
OLD | NEW |