| 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 1117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1163 SendDataPacket(1); | 1166 SendDataPacket(1); |
| 1164 | 1167 |
| 1165 manager_.OnRetransmissionTimeout(); | 1168 manager_.OnRetransmissionTimeout(); |
| 1166 EXPECT_TRUE(manager_.HasPendingRetransmissions()); | 1169 EXPECT_TRUE(manager_.HasPendingRetransmissions()); |
| 1167 EXPECT_EQ(kDefaultLength, | 1170 EXPECT_EQ(kDefaultLength, |
| 1168 QuicSentPacketManagerPeer::GetBytesInFlight(&manager_)); | 1171 QuicSentPacketManagerPeer::GetBytesInFlight(&manager_)); |
| 1169 RetransmitNextPacket(2); | 1172 RetransmitNextPacket(2); |
| 1170 EXPECT_FALSE(manager_.HasPendingRetransmissions()); | 1173 EXPECT_FALSE(manager_.HasPendingRetransmissions()); |
| 1171 | 1174 |
| 1172 // Rto a second time. | 1175 // Rto a second time. |
| 1176 EXPECT_CALL(*network_change_visitor_, OnPathDegrading()); |
| 1173 manager_.OnRetransmissionTimeout(); | 1177 manager_.OnRetransmissionTimeout(); |
| 1174 EXPECT_TRUE(manager_.HasPendingRetransmissions()); | 1178 EXPECT_TRUE(manager_.HasPendingRetransmissions()); |
| 1175 EXPECT_EQ(2 * kDefaultLength, | 1179 EXPECT_EQ(2 * kDefaultLength, |
| 1176 QuicSentPacketManagerPeer::GetBytesInFlight(&manager_)); | 1180 QuicSentPacketManagerPeer::GetBytesInFlight(&manager_)); |
| 1177 RetransmitNextPacket(3); | 1181 RetransmitNextPacket(3); |
| 1178 EXPECT_FALSE(manager_.HasPendingRetransmissions()); | 1182 EXPECT_FALSE(manager_.HasPendingRetransmissions()); |
| 1179 | 1183 |
| 1180 // Ack a retransmission and ensure OnRetransmissionTimeout is called. | 1184 // Ack a retransmission and ensure OnRetransmissionTimeout is called. |
| 1181 EXPECT_CALL(*send_algorithm_, OnRetransmissionTimeout(true)); | 1185 EXPECT_CALL(*send_algorithm_, OnRetransmissionTimeout(true)); |
| 1182 QuicAckFrame ack_frame; | 1186 QuicAckFrame ack_frame; |
| (...skipping 13 matching lines...) Expand all Loading... |
| 1196 SendDataPacket(1); | 1200 SendDataPacket(1); |
| 1197 | 1201 |
| 1198 manager_.OnRetransmissionTimeout(); | 1202 manager_.OnRetransmissionTimeout(); |
| 1199 EXPECT_TRUE(manager_.HasPendingRetransmissions()); | 1203 EXPECT_TRUE(manager_.HasPendingRetransmissions()); |
| 1200 EXPECT_EQ(kDefaultLength, | 1204 EXPECT_EQ(kDefaultLength, |
| 1201 QuicSentPacketManagerPeer::GetBytesInFlight(&manager_)); | 1205 QuicSentPacketManagerPeer::GetBytesInFlight(&manager_)); |
| 1202 RetransmitNextPacket(2); | 1206 RetransmitNextPacket(2); |
| 1203 EXPECT_FALSE(manager_.HasPendingRetransmissions()); | 1207 EXPECT_FALSE(manager_.HasPendingRetransmissions()); |
| 1204 | 1208 |
| 1205 // Rto a second time. | 1209 // Rto a second time. |
| 1210 EXPECT_CALL(*network_change_visitor_, OnPathDegrading()); |
| 1206 manager_.OnRetransmissionTimeout(); | 1211 manager_.OnRetransmissionTimeout(); |
| 1207 EXPECT_TRUE(manager_.HasPendingRetransmissions()); | 1212 EXPECT_TRUE(manager_.HasPendingRetransmissions()); |
| 1208 EXPECT_EQ(2 * kDefaultLength, | 1213 EXPECT_EQ(2 * kDefaultLength, |
| 1209 QuicSentPacketManagerPeer::GetBytesInFlight(&manager_)); | 1214 QuicSentPacketManagerPeer::GetBytesInFlight(&manager_)); |
| 1210 RetransmitNextPacket(3); | 1215 RetransmitNextPacket(3); |
| 1211 EXPECT_FALSE(manager_.HasPendingRetransmissions()); | 1216 EXPECT_FALSE(manager_.HasPendingRetransmissions()); |
| 1212 | 1217 |
| 1213 // Ack a retransmission and ensure OnRetransmissionTimeout is called. | 1218 // Ack a retransmission and ensure OnRetransmissionTimeout is called. |
| 1214 EXPECT_CALL(*send_algorithm_, OnRetransmissionTimeout(true)); | 1219 EXPECT_CALL(*send_algorithm_, OnRetransmissionTimeout(true)); |
| 1215 QuicAckFrame ack_frame; | 1220 QuicAckFrame ack_frame; |
| 1216 ack_frame.ack_delay_time = QuicTime::Delta::Zero(); | 1221 ack_frame.ack_delay_time = QuicTime::Delta::Zero(); |
| 1217 ack_frame.largest_observed = 3; | 1222 ack_frame.largest_observed = 3; |
| 1218 ack_frame.missing_packets.Add(1, 3); | 1223 ack_frame.missing_packets.Add(1, 3); |
| 1219 ExpectAck(3); | 1224 ExpectAck(3); |
| 1220 manager_.OnIncomingAck(ack_frame, clock_.Now()); | 1225 manager_.OnIncomingAck(ack_frame, clock_.Now()); |
| 1221 | 1226 |
| 1222 // The first two packets should still be outstanding. | 1227 // The first two packets should still be outstanding. |
| 1223 EXPECT_EQ(2 * kDefaultLength, | 1228 EXPECT_EQ(2 * kDefaultLength, |
| 1224 QuicSentPacketManagerPeer::GetBytesInFlight(&manager_)); | 1229 QuicSentPacketManagerPeer::GetBytesInFlight(&manager_)); |
| 1225 } | 1230 } |
| 1226 | 1231 |
| 1232 TEST_F(QuicSentPacketManagerTest, OnPathDegrading) { |
| 1233 SendDataPacket(1); |
| 1234 QuicTime::Delta delay = QuicTime::Delta::FromMilliseconds(500); |
| 1235 EXPECT_CALL(*send_algorithm_, RetransmissionDelay()) |
| 1236 .WillRepeatedly(Return(delay)); |
| 1237 for (size_t i = 1; i < kMinTimeoutsBeforePathDegrading; ++i) { |
| 1238 manager_.OnRetransmissionTimeout(); |
| 1239 RetransmitNextPacket(i + 2); |
| 1240 } |
| 1241 // Next RTO should cause network_change_visitor_'s OnPathDegrading method |
| 1242 // to be called. |
| 1243 EXPECT_CALL(*network_change_visitor_, OnPathDegrading()); |
| 1244 manager_.OnRetransmissionTimeout(); |
| 1245 } |
| 1246 |
| 1227 TEST_F(QuicSentPacketManagerTest, GetTransmissionTime) { | 1247 TEST_F(QuicSentPacketManagerTest, GetTransmissionTime) { |
| 1228 EXPECT_EQ(QuicTime::Zero(), manager_.GetRetransmissionTime()); | 1248 EXPECT_EQ(QuicTime::Zero(), manager_.GetRetransmissionTime()); |
| 1229 } | 1249 } |
| 1230 | 1250 |
| 1231 TEST_F(QuicSentPacketManagerTest, GetTransmissionTimeCryptoHandshake) { | 1251 TEST_F(QuicSentPacketManagerTest, GetTransmissionTimeCryptoHandshake) { |
| 1232 SendCryptoPacket(1); | 1252 SendCryptoPacket(1); |
| 1233 | 1253 |
| 1234 // Check the min. | 1254 // Check the min. |
| 1235 RttStats* rtt_stats = QuicSentPacketManagerPeer::GetRttStats(&manager_); | 1255 RttStats* rtt_stats = QuicSentPacketManagerPeer::GetRttStats(&manager_); |
| 1236 rtt_stats->set_initial_rtt_us(1 * kNumMicrosPerMilli); | 1256 rtt_stats->set_initial_rtt_us(1 * kNumMicrosPerMilli); |
| (...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1350 } | 1370 } |
| 1351 | 1371 |
| 1352 TEST_F(QuicSentPacketManagerTest, GetTransmissionDelayMin) { | 1372 TEST_F(QuicSentPacketManagerTest, GetTransmissionDelayMin) { |
| 1353 SendDataPacket(1); | 1373 SendDataPacket(1); |
| 1354 EXPECT_CALL(*send_algorithm_, RetransmissionDelay()) | 1374 EXPECT_CALL(*send_algorithm_, RetransmissionDelay()) |
| 1355 .WillRepeatedly(Return(QuicTime::Delta::FromMilliseconds(1))); | 1375 .WillRepeatedly(Return(QuicTime::Delta::FromMilliseconds(1))); |
| 1356 QuicTime::Delta delay = QuicTime::Delta::FromMilliseconds(200); | 1376 QuicTime::Delta delay = QuicTime::Delta::FromMilliseconds(200); |
| 1357 | 1377 |
| 1358 // If the delay is smaller than the min, ensure it exponentially backs off | 1378 // If the delay is smaller than the min, ensure it exponentially backs off |
| 1359 // from the min. | 1379 // from the min. |
| 1380 EXPECT_CALL(*network_change_visitor_, OnPathDegrading()); |
| 1360 for (int i = 0; i < 5; ++i) { | 1381 for (int i = 0; i < 5; ++i) { |
| 1361 EXPECT_EQ(delay, | 1382 EXPECT_EQ(delay, |
| 1362 QuicSentPacketManagerPeer::GetRetransmissionDelay(&manager_)); | 1383 QuicSentPacketManagerPeer::GetRetransmissionDelay(&manager_)); |
| 1363 delay = delay.Add(delay); | 1384 delay = delay.Add(delay); |
| 1364 manager_.OnRetransmissionTimeout(); | 1385 manager_.OnRetransmissionTimeout(); |
| 1365 RetransmitNextPacket(i + 2); | 1386 RetransmitNextPacket(i + 2); |
| 1366 } | 1387 } |
| 1367 } | 1388 } |
| 1368 | 1389 |
| 1369 TEST_F(QuicSentPacketManagerTest, GetTransmissionDelayMax) { | 1390 TEST_F(QuicSentPacketManagerTest, GetTransmissionDelayMax) { |
| 1370 EXPECT_CALL(*send_algorithm_, RetransmissionDelay()) | 1391 EXPECT_CALL(*send_algorithm_, RetransmissionDelay()) |
| 1371 .WillOnce(Return(QuicTime::Delta::FromSeconds(500))); | 1392 .WillOnce(Return(QuicTime::Delta::FromSeconds(500))); |
| 1372 | 1393 |
| 1373 EXPECT_EQ(QuicTime::Delta::FromSeconds(60), | 1394 EXPECT_EQ(QuicTime::Delta::FromSeconds(60), |
| 1374 QuicSentPacketManagerPeer::GetRetransmissionDelay(&manager_)); | 1395 QuicSentPacketManagerPeer::GetRetransmissionDelay(&manager_)); |
| 1375 } | 1396 } |
| 1376 | 1397 |
| 1377 TEST_F(QuicSentPacketManagerTest, GetTransmissionDelay) { | 1398 TEST_F(QuicSentPacketManagerTest, GetTransmissionDelay) { |
| 1378 SendDataPacket(1); | 1399 SendDataPacket(1); |
| 1379 QuicTime::Delta delay = QuicTime::Delta::FromMilliseconds(500); | 1400 QuicTime::Delta delay = QuicTime::Delta::FromMilliseconds(500); |
| 1380 EXPECT_CALL(*send_algorithm_, RetransmissionDelay()) | 1401 EXPECT_CALL(*send_algorithm_, RetransmissionDelay()) |
| 1381 .WillRepeatedly(Return(delay)); | 1402 .WillRepeatedly(Return(delay)); |
| 1382 | 1403 |
| 1383 // Delay should back off exponentially. | 1404 // Delay should back off exponentially. |
| 1405 EXPECT_CALL(*network_change_visitor_, OnPathDegrading()); |
| 1384 for (int i = 0; i < 5; ++i) { | 1406 for (int i = 0; i < 5; ++i) { |
| 1385 EXPECT_EQ(delay, | 1407 EXPECT_EQ(delay, |
| 1386 QuicSentPacketManagerPeer::GetRetransmissionDelay(&manager_)); | 1408 QuicSentPacketManagerPeer::GetRetransmissionDelay(&manager_)); |
| 1387 delay = delay.Add(delay); | 1409 delay = delay.Add(delay); |
| 1388 manager_.OnRetransmissionTimeout(); | 1410 manager_.OnRetransmissionTimeout(); |
| 1389 RetransmitNextPacket(i + 2); | 1411 RetransmitNextPacket(i + 2); |
| 1390 } | 1412 } |
| 1391 } | 1413 } |
| 1392 | 1414 |
| 1393 TEST_F(QuicSentPacketManagerTest, GetLossDelay) { | 1415 TEST_F(QuicSentPacketManagerTest, GetLossDelay) { |
| (...skipping 301 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1695 | 1717 |
| 1696 EXPECT_CALL(*send_algorithm_, ResumeConnectionState(_, false)); | 1718 EXPECT_CALL(*send_algorithm_, ResumeConnectionState(_, false)); |
| 1697 manager_.ResumeConnectionState(cached_network_params, false); | 1719 manager_.ResumeConnectionState(cached_network_params, false); |
| 1698 EXPECT_EQ(kRttMs * kNumMicrosPerMilli, | 1720 EXPECT_EQ(kRttMs * kNumMicrosPerMilli, |
| 1699 static_cast<uint64_t>(manager_.GetRttStats()->initial_rtt_us())); | 1721 static_cast<uint64_t>(manager_.GetRttStats()->initial_rtt_us())); |
| 1700 } | 1722 } |
| 1701 | 1723 |
| 1702 } // namespace | 1724 } // namespace |
| 1703 } // namespace test | 1725 } // namespace test |
| 1704 } // namespace net | 1726 } // namespace net |
| OLD | NEW |