| 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 15 matching lines...) Expand all Loading... |
| 26 namespace net { | 26 namespace net { |
| 27 namespace test { | 27 namespace test { |
| 28 namespace { | 28 namespace { |
| 29 | 29 |
| 30 // Default packet length. | 30 // Default packet length. |
| 31 const uint32_t kDefaultLength = 1000; | 31 const uint32_t kDefaultLength = 1000; |
| 32 | 32 |
| 33 // Stream ID for data sent in CreatePacket(). | 33 // Stream ID for data sent in CreatePacket(). |
| 34 const QuicStreamId kStreamId = 7; | 34 const QuicStreamId kStreamId = 7; |
| 35 | 35 |
| 36 // Minimum number of consecutive RTOs before path is considered to be degrading. |
| 37 const size_t kMinTimeoutsBeforePathDegrading = 2; |
| 38 |
| 36 // Matcher to check the key of the key-value pair it receives as first argument | 39 // Matcher to check the key of the key-value pair it receives as first argument |
| 37 // equals its second argument. | 40 // equals its second argument. |
| 38 MATCHER(KeyEq, "") { | 41 MATCHER(KeyEq, "") { |
| 39 return std::tr1::get<0>(arg).first == std::tr1::get<1>(arg); | 42 return std::tr1::get<0>(arg).first == std::tr1::get<1>(arg); |
| 40 } | 43 } |
| 41 | 44 |
| 42 class MockDebugDelegate : public QuicSentPacketManager::DebugDelegate { | 45 class MockDebugDelegate : public QuicSentPacketManager::DebugDelegate { |
| 43 public: | 46 public: |
| 44 MOCK_METHOD2(OnSpuriousPacketRetransmission, | 47 MOCK_METHOD2(OnSpuriousPacketRetransmission, |
| 45 void(TransmissionType transmission_type, | 48 void(TransmissionType transmission_type, |
| (...skipping 1118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1164 SendDataPacket(1); | 1167 SendDataPacket(1); |
| 1165 | 1168 |
| 1166 manager_.OnRetransmissionTimeout(); | 1169 manager_.OnRetransmissionTimeout(); |
| 1167 EXPECT_TRUE(manager_.HasPendingRetransmissions()); | 1170 EXPECT_TRUE(manager_.HasPendingRetransmissions()); |
| 1168 EXPECT_EQ(kDefaultLength, | 1171 EXPECT_EQ(kDefaultLength, |
| 1169 QuicSentPacketManagerPeer::GetBytesInFlight(&manager_)); | 1172 QuicSentPacketManagerPeer::GetBytesInFlight(&manager_)); |
| 1170 RetransmitNextPacket(2); | 1173 RetransmitNextPacket(2); |
| 1171 EXPECT_FALSE(manager_.HasPendingRetransmissions()); | 1174 EXPECT_FALSE(manager_.HasPendingRetransmissions()); |
| 1172 | 1175 |
| 1173 // Rto a second time. | 1176 // Rto a second time. |
| 1177 EXPECT_CALL(*network_change_visitor_, OnPathDegrading()); |
| 1174 manager_.OnRetransmissionTimeout(); | 1178 manager_.OnRetransmissionTimeout(); |
| 1175 EXPECT_TRUE(manager_.HasPendingRetransmissions()); | 1179 EXPECT_TRUE(manager_.HasPendingRetransmissions()); |
| 1176 EXPECT_EQ(2 * kDefaultLength, | 1180 EXPECT_EQ(2 * kDefaultLength, |
| 1177 QuicSentPacketManagerPeer::GetBytesInFlight(&manager_)); | 1181 QuicSentPacketManagerPeer::GetBytesInFlight(&manager_)); |
| 1178 RetransmitNextPacket(3); | 1182 RetransmitNextPacket(3); |
| 1179 EXPECT_FALSE(manager_.HasPendingRetransmissions()); | 1183 EXPECT_FALSE(manager_.HasPendingRetransmissions()); |
| 1180 | 1184 |
| 1181 // Ack a retransmission and ensure OnRetransmissionTimeout is called. | 1185 // Ack a retransmission and ensure OnRetransmissionTimeout is called. |
| 1182 EXPECT_CALL(*send_algorithm_, OnRetransmissionTimeout(true)); | 1186 EXPECT_CALL(*send_algorithm_, OnRetransmissionTimeout(true)); |
| 1183 QuicAckFrame ack_frame; | 1187 QuicAckFrame ack_frame; |
| (...skipping 13 matching lines...) Expand all Loading... |
| 1197 SendDataPacket(1); | 1201 SendDataPacket(1); |
| 1198 | 1202 |
| 1199 manager_.OnRetransmissionTimeout(); | 1203 manager_.OnRetransmissionTimeout(); |
| 1200 EXPECT_TRUE(manager_.HasPendingRetransmissions()); | 1204 EXPECT_TRUE(manager_.HasPendingRetransmissions()); |
| 1201 EXPECT_EQ(kDefaultLength, | 1205 EXPECT_EQ(kDefaultLength, |
| 1202 QuicSentPacketManagerPeer::GetBytesInFlight(&manager_)); | 1206 QuicSentPacketManagerPeer::GetBytesInFlight(&manager_)); |
| 1203 RetransmitNextPacket(2); | 1207 RetransmitNextPacket(2); |
| 1204 EXPECT_FALSE(manager_.HasPendingRetransmissions()); | 1208 EXPECT_FALSE(manager_.HasPendingRetransmissions()); |
| 1205 | 1209 |
| 1206 // Rto a second time. | 1210 // Rto a second time. |
| 1211 EXPECT_CALL(*network_change_visitor_, OnPathDegrading()); |
| 1207 manager_.OnRetransmissionTimeout(); | 1212 manager_.OnRetransmissionTimeout(); |
| 1208 EXPECT_TRUE(manager_.HasPendingRetransmissions()); | 1213 EXPECT_TRUE(manager_.HasPendingRetransmissions()); |
| 1209 EXPECT_EQ(2 * kDefaultLength, | 1214 EXPECT_EQ(2 * kDefaultLength, |
| 1210 QuicSentPacketManagerPeer::GetBytesInFlight(&manager_)); | 1215 QuicSentPacketManagerPeer::GetBytesInFlight(&manager_)); |
| 1211 RetransmitNextPacket(3); | 1216 RetransmitNextPacket(3); |
| 1212 EXPECT_FALSE(manager_.HasPendingRetransmissions()); | 1217 EXPECT_FALSE(manager_.HasPendingRetransmissions()); |
| 1213 | 1218 |
| 1214 // Ack a retransmission and ensure OnRetransmissionTimeout is called. | 1219 // Ack a retransmission and ensure OnRetransmissionTimeout is called. |
| 1215 EXPECT_CALL(*send_algorithm_, OnRetransmissionTimeout(true)); | 1220 EXPECT_CALL(*send_algorithm_, OnRetransmissionTimeout(true)); |
| 1216 QuicAckFrame ack_frame; | 1221 QuicAckFrame ack_frame; |
| 1217 ack_frame.ack_delay_time = QuicTime::Delta::Zero(); | 1222 ack_frame.ack_delay_time = QuicTime::Delta::Zero(); |
| 1218 ack_frame.largest_observed = 3; | 1223 ack_frame.largest_observed = 3; |
| 1219 ack_frame.missing_packets.Add(1, 3); | 1224 ack_frame.missing_packets.Add(1, 3); |
| 1220 ExpectAck(3); | 1225 ExpectAck(3); |
| 1221 manager_.OnIncomingAck(ack_frame, clock_.Now()); | 1226 manager_.OnIncomingAck(ack_frame, clock_.Now()); |
| 1222 | 1227 |
| 1223 // The first two packets should still be outstanding. | 1228 // The first two packets should still be outstanding. |
| 1224 EXPECT_EQ(2 * kDefaultLength, | 1229 EXPECT_EQ(2 * kDefaultLength, |
| 1225 QuicSentPacketManagerPeer::GetBytesInFlight(&manager_)); | 1230 QuicSentPacketManagerPeer::GetBytesInFlight(&manager_)); |
| 1226 } | 1231 } |
| 1227 | 1232 |
| 1233 TEST_F(QuicSentPacketManagerTest, OnPathDegrading) { |
| 1234 SendDataPacket(1); |
| 1235 QuicTime::Delta delay = QuicTime::Delta::FromMilliseconds(500); |
| 1236 EXPECT_CALL(*send_algorithm_, RetransmissionDelay()) |
| 1237 .WillRepeatedly(Return(delay)); |
| 1238 for (size_t i = 1; i < kMinTimeoutsBeforePathDegrading; ++i) { |
| 1239 manager_.OnRetransmissionTimeout(); |
| 1240 RetransmitNextPacket(i + 2); |
| 1241 } |
| 1242 // Next RTO should cause network_change_visitor_'s OnPathDegrading method |
| 1243 // to be called. |
| 1244 EXPECT_CALL(*network_change_visitor_, OnPathDegrading()); |
| 1245 manager_.OnRetransmissionTimeout(); |
| 1246 } |
| 1247 |
| 1228 TEST_F(QuicSentPacketManagerTest, GetTransmissionTime) { | 1248 TEST_F(QuicSentPacketManagerTest, GetTransmissionTime) { |
| 1229 EXPECT_EQ(QuicTime::Zero(), manager_.GetRetransmissionTime()); | 1249 EXPECT_EQ(QuicTime::Zero(), manager_.GetRetransmissionTime()); |
| 1230 } | 1250 } |
| 1231 | 1251 |
| 1232 TEST_F(QuicSentPacketManagerTest, GetTransmissionTimeCryptoHandshake) { | 1252 TEST_F(QuicSentPacketManagerTest, GetTransmissionTimeCryptoHandshake) { |
| 1233 SendCryptoPacket(1); | 1253 SendCryptoPacket(1); |
| 1234 | 1254 |
| 1235 // Check the min. | 1255 // Check the min. |
| 1236 RttStats* rtt_stats = QuicSentPacketManagerPeer::GetRttStats(&manager_); | 1256 RttStats* rtt_stats = QuicSentPacketManagerPeer::GetRttStats(&manager_); |
| 1237 rtt_stats->set_initial_rtt_us(1 * kNumMicrosPerMilli); | 1257 rtt_stats->set_initial_rtt_us(1 * kNumMicrosPerMilli); |
| (...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1351 } | 1371 } |
| 1352 | 1372 |
| 1353 TEST_F(QuicSentPacketManagerTest, GetTransmissionDelayMin) { | 1373 TEST_F(QuicSentPacketManagerTest, GetTransmissionDelayMin) { |
| 1354 SendDataPacket(1); | 1374 SendDataPacket(1); |
| 1355 EXPECT_CALL(*send_algorithm_, RetransmissionDelay()) | 1375 EXPECT_CALL(*send_algorithm_, RetransmissionDelay()) |
| 1356 .WillRepeatedly(Return(QuicTime::Delta::FromMilliseconds(1))); | 1376 .WillRepeatedly(Return(QuicTime::Delta::FromMilliseconds(1))); |
| 1357 QuicTime::Delta delay = QuicTime::Delta::FromMilliseconds(200); | 1377 QuicTime::Delta delay = QuicTime::Delta::FromMilliseconds(200); |
| 1358 | 1378 |
| 1359 // If the delay is smaller than the min, ensure it exponentially backs off | 1379 // If the delay is smaller than the min, ensure it exponentially backs off |
| 1360 // from the min. | 1380 // from the min. |
| 1381 EXPECT_CALL(*network_change_visitor_, OnPathDegrading()); |
| 1361 for (int i = 0; i < 5; ++i) { | 1382 for (int i = 0; i < 5; ++i) { |
| 1362 EXPECT_EQ(delay, | 1383 EXPECT_EQ(delay, |
| 1363 QuicSentPacketManagerPeer::GetRetransmissionDelay(&manager_)); | 1384 QuicSentPacketManagerPeer::GetRetransmissionDelay(&manager_)); |
| 1364 delay = delay.Add(delay); | 1385 delay = delay.Add(delay); |
| 1365 manager_.OnRetransmissionTimeout(); | 1386 manager_.OnRetransmissionTimeout(); |
| 1366 RetransmitNextPacket(i + 2); | 1387 RetransmitNextPacket(i + 2); |
| 1367 } | 1388 } |
| 1368 } | 1389 } |
| 1369 | 1390 |
| 1370 TEST_F(QuicSentPacketManagerTest, GetTransmissionDelayMax) { | 1391 TEST_F(QuicSentPacketManagerTest, GetTransmissionDelayMax) { |
| 1371 EXPECT_CALL(*send_algorithm_, RetransmissionDelay()) | 1392 EXPECT_CALL(*send_algorithm_, RetransmissionDelay()) |
| 1372 .WillOnce(Return(QuicTime::Delta::FromSeconds(500))); | 1393 .WillOnce(Return(QuicTime::Delta::FromSeconds(500))); |
| 1373 | 1394 |
| 1374 EXPECT_EQ(QuicTime::Delta::FromSeconds(60), | 1395 EXPECT_EQ(QuicTime::Delta::FromSeconds(60), |
| 1375 QuicSentPacketManagerPeer::GetRetransmissionDelay(&manager_)); | 1396 QuicSentPacketManagerPeer::GetRetransmissionDelay(&manager_)); |
| 1376 } | 1397 } |
| 1377 | 1398 |
| 1378 TEST_F(QuicSentPacketManagerTest, GetTransmissionDelay) { | 1399 TEST_F(QuicSentPacketManagerTest, GetTransmissionDelay) { |
| 1379 SendDataPacket(1); | 1400 SendDataPacket(1); |
| 1380 QuicTime::Delta delay = QuicTime::Delta::FromMilliseconds(500); | 1401 QuicTime::Delta delay = QuicTime::Delta::FromMilliseconds(500); |
| 1381 EXPECT_CALL(*send_algorithm_, RetransmissionDelay()) | 1402 EXPECT_CALL(*send_algorithm_, RetransmissionDelay()) |
| 1382 .WillRepeatedly(Return(delay)); | 1403 .WillRepeatedly(Return(delay)); |
| 1383 | 1404 |
| 1384 // Delay should back off exponentially. | 1405 // Delay should back off exponentially. |
| 1406 EXPECT_CALL(*network_change_visitor_, OnPathDegrading()); |
| 1385 for (int i = 0; i < 5; ++i) { | 1407 for (int i = 0; i < 5; ++i) { |
| 1386 EXPECT_EQ(delay, | 1408 EXPECT_EQ(delay, |
| 1387 QuicSentPacketManagerPeer::GetRetransmissionDelay(&manager_)); | 1409 QuicSentPacketManagerPeer::GetRetransmissionDelay(&manager_)); |
| 1388 delay = delay.Add(delay); | 1410 delay = delay.Add(delay); |
| 1389 manager_.OnRetransmissionTimeout(); | 1411 manager_.OnRetransmissionTimeout(); |
| 1390 RetransmitNextPacket(i + 2); | 1412 RetransmitNextPacket(i + 2); |
| 1391 } | 1413 } |
| 1392 } | 1414 } |
| 1393 | 1415 |
| 1394 TEST_F(QuicSentPacketManagerTest, GetLossDelay) { | 1416 TEST_F(QuicSentPacketManagerTest, GetLossDelay) { |
| (...skipping 301 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1696 | 1718 |
| 1697 EXPECT_CALL(*send_algorithm_, ResumeConnectionState(_, false)); | 1719 EXPECT_CALL(*send_algorithm_, ResumeConnectionState(_, false)); |
| 1698 manager_.ResumeConnectionState(cached_network_params, false); | 1720 manager_.ResumeConnectionState(cached_network_params, false); |
| 1699 EXPECT_EQ(kRttMs * kNumMicrosPerMilli, | 1721 EXPECT_EQ(kRttMs * kNumMicrosPerMilli, |
| 1700 static_cast<uint64_t>(manager_.GetRttStats()->initial_rtt_us())); | 1722 static_cast<uint64_t>(manager_.GetRttStats()->initial_rtt_us())); |
| 1701 } | 1723 } |
| 1702 | 1724 |
| 1703 } // namespace | 1725 } // namespace |
| 1704 } // namespace test | 1726 } // namespace test |
| 1705 } // namespace net | 1727 } // namespace net |
| OLD | NEW |