Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(47)

Side by Side Diff: net/quic/core/quic_sent_packet_manager_test.cc

Issue 2393933002: Move the logic from SendAlgorithmInterface::RetransmissionDelay() into QuicSentPacketManager, becau… (Closed)
Patch Set: Created 4 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « net/quic/core/quic_sent_packet_manager.cc ('k') | net/quic/test_tools/quic_test_utils.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/core/quic_sent_packet_manager.h" 5 #include "net/quic/core/quic_sent_packet_manager.h"
6 6
7 #include <memory> 7 #include <memory>
8 #include "base/memory/ptr_util.h" 8 #include "base/memory/ptr_util.h"
9 #include "base/stl_util.h" 9 #include "base/stl_util.h"
10 #include "net/quic/core/quic_flags.h" 10 #include "net/quic/core/quic_flags.h"
(...skipping 736 matching lines...) Expand 10 before | Expand all | Expand 10 after
747 EXPECT_TRUE(manager_.MaybeRetransmitTailLossProbe()); 747 EXPECT_TRUE(manager_.MaybeRetransmitTailLossProbe());
748 EXPECT_TRUE(manager_.HasPendingRetransmissions()); 748 EXPECT_TRUE(manager_.HasPendingRetransmissions());
749 RetransmitNextPacket(102); 749 RetransmitNextPacket(102);
750 EXPECT_CALL(*send_algorithm_, TimeUntilSend(_, _)) 750 EXPECT_CALL(*send_algorithm_, TimeUntilSend(_, _))
751 .WillOnce(Return(QuicTime::Delta::Infinite())); 751 .WillOnce(Return(QuicTime::Delta::Infinite()));
752 EXPECT_EQ(QuicTime::Delta::Infinite(), 752 EXPECT_EQ(QuicTime::Delta::Infinite(),
753 manager_.TimeUntilSend(clock_.Now(), &path_id)); 753 manager_.TimeUntilSend(clock_.Now(), &path_id));
754 754
755 // Ensure the RTO is set based on the correct packet. 755 // Ensure the RTO is set based on the correct packet.
756 rto_packet_time = clock_.Now(); 756 rto_packet_time = clock_.Now();
757 EXPECT_CALL(*send_algorithm_, RetransmissionDelay()) 757 EXPECT_EQ(rto_packet_time + QuicTime::Delta::FromMilliseconds(500),
758 .WillOnce(Return(QuicTime::Delta::FromSeconds(1)));
759 EXPECT_EQ(rto_packet_time + QuicTime::Delta::FromSeconds(1),
760 manager_.GetRetransmissionTime()); 758 manager_.GetRetransmissionTime());
761 759
762 // Advance the time enough to ensure all packets are RTO'd. 760 // Advance the time enough to ensure all packets are RTO'd.
763 clock_.AdvanceTime(QuicTime::Delta::FromMilliseconds(1000)); 761 clock_.AdvanceTime(QuicTime::Delta::FromMilliseconds(1000));
764 762
765 manager_.OnRetransmissionTimeout(); 763 manager_.OnRetransmissionTimeout();
766 EXPECT_TRUE(manager_.HasPendingRetransmissions()); 764 EXPECT_TRUE(manager_.HasPendingRetransmissions());
767 EXPECT_EQ(2u, stats_.tlp_count); 765 EXPECT_EQ(2u, stats_.tlp_count);
768 EXPECT_EQ(1u, stats_.rto_count); 766 EXPECT_EQ(1u, stats_.rto_count);
769 767
(...skipping 344 matching lines...) Expand 10 before | Expand all | Expand 10 after
1114 ExpectAck(3); 1112 ExpectAck(3);
1115 manager_.OnIncomingAck(ack_frame, clock_.Now()); 1113 manager_.OnIncomingAck(ack_frame, clock_.Now());
1116 1114
1117 // The first two packets should still be outstanding. 1115 // The first two packets should still be outstanding.
1118 EXPECT_EQ(2 * kDefaultLength, 1116 EXPECT_EQ(2 * kDefaultLength,
1119 QuicSentPacketManagerPeer::GetBytesInFlight(&manager_)); 1117 QuicSentPacketManagerPeer::GetBytesInFlight(&manager_));
1120 } 1118 }
1121 1119
1122 TEST_P(QuicSentPacketManagerTest, OnPathDegrading) { 1120 TEST_P(QuicSentPacketManagerTest, OnPathDegrading) {
1123 SendDataPacket(1); 1121 SendDataPacket(1);
1124 QuicTime::Delta delay = QuicTime::Delta::FromMilliseconds(500);
1125 EXPECT_CALL(*send_algorithm_, RetransmissionDelay())
1126 .WillRepeatedly(Return(delay));
1127 for (size_t i = 1; i < kMinTimeoutsBeforePathDegrading; ++i) { 1122 for (size_t i = 1; i < kMinTimeoutsBeforePathDegrading; ++i) {
1128 manager_.OnRetransmissionTimeout(); 1123 manager_.OnRetransmissionTimeout();
1129 RetransmitNextPacket(i + 2); 1124 RetransmitNextPacket(i + 2);
1130 } 1125 }
1131 // Next RTO should cause network_change_visitor_'s OnPathDegrading method 1126 // Next RTO should cause network_change_visitor_'s OnPathDegrading method
1132 // to be called. 1127 // to be called.
1133 EXPECT_CALL(*network_change_visitor_, OnPathDegrading()); 1128 EXPECT_CALL(*network_change_visitor_, OnPathDegrading());
1134 manager_.OnRetransmissionTimeout(); 1129 manager_.OnRetransmissionTimeout();
1135 } 1130 }
1136 1131
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after
1240 .WillOnce(Return(QuicTime::Delta::Infinite())); 1235 .WillOnce(Return(QuicTime::Delta::Infinite()));
1241 EXPECT_EQ(QuicTime::Delta::Infinite(), 1236 EXPECT_EQ(QuicTime::Delta::Infinite(),
1242 manager_.TimeUntilSend(clock_.Now(), &path_id)); 1237 manager_.TimeUntilSend(clock_.Now(), &path_id));
1243 EXPECT_FALSE(manager_.HasPendingRetransmissions()); 1238 EXPECT_FALSE(manager_.HasPendingRetransmissions());
1244 1239
1245 expected_time = clock_.Now() + expected_tlp_delay; 1240 expected_time = clock_.Now() + expected_tlp_delay;
1246 EXPECT_EQ(expected_time, manager_.GetRetransmissionTime()); 1241 EXPECT_EQ(expected_time, manager_.GetRetransmissionTime());
1247 } 1242 }
1248 1243
1249 TEST_P(QuicSentPacketManagerTest, GetTransmissionTimeSpuriousRTO) { 1244 TEST_P(QuicSentPacketManagerTest, GetTransmissionTimeSpuriousRTO) {
1250 const_cast<RttStats*>(manager_.GetRttStats()) 1245 RttStats* rtt_stats = const_cast<RttStats*>(manager_.GetRttStats());
1251 ->UpdateRtt(QuicTime::Delta::FromMilliseconds(100), 1246 rtt_stats->UpdateRtt(QuicTime::Delta::FromMilliseconds(100),
1252 QuicTime::Delta::Zero(), QuicTime::Zero()); 1247 QuicTime::Delta::Zero(), QuicTime::Zero());
1248
1253 SendDataPacket(1); 1249 SendDataPacket(1);
1254 SendDataPacket(2); 1250 SendDataPacket(2);
1255 SendDataPacket(3); 1251 SendDataPacket(3);
1256 SendDataPacket(4); 1252 SendDataPacket(4);
1257 1253
1258 QuicTime::Delta expected_rto_delay = QuicTime::Delta::FromMilliseconds(500); 1254 QuicTime::Delta expected_rto_delay =
1259 EXPECT_CALL(*send_algorithm_, RetransmissionDelay()) 1255 rtt_stats->smoothed_rtt() + 4 * rtt_stats->mean_deviation();
1260 .WillRepeatedly(Return(expected_rto_delay));
1261 QuicTime expected_time = clock_.Now() + expected_rto_delay; 1256 QuicTime expected_time = clock_.Now() + expected_rto_delay;
1262 EXPECT_EQ(expected_time, manager_.GetRetransmissionTime()); 1257 EXPECT_EQ(expected_time, manager_.GetRetransmissionTime());
1263 1258
1264 // Retransmit the packet by invoking the retransmission timeout. 1259 // Retransmit the packet by invoking the retransmission timeout.
1265 clock_.AdvanceTime(expected_rto_delay); 1260 clock_.AdvanceTime(expected_rto_delay);
1266 manager_.OnRetransmissionTimeout(); 1261 manager_.OnRetransmissionTimeout();
1267 // All packets are still considered inflight. 1262 // All packets are still considered inflight.
1268 EXPECT_EQ(4 * kDefaultLength, 1263 EXPECT_EQ(4 * kDefaultLength,
1269 QuicSentPacketManagerPeer::GetBytesInFlight(&manager_)); 1264 QuicSentPacketManagerPeer::GetBytesInFlight(&manager_));
1270 RetransmitNextPacket(5); 1265 RetransmitNextPacket(5);
(...skipping 24 matching lines...) Expand all
1295 // Since retransmission was spurious, smoothed_rtt_ is expired, and replaced 1290 // Since retransmission was spurious, smoothed_rtt_ is expired, and replaced
1296 // by the latest RTT sample of 500ms. 1291 // by the latest RTT sample of 500ms.
1297 expected_time = clock_.Now() + QuicTime::Delta::FromMilliseconds(1000); 1292 expected_time = clock_.Now() + QuicTime::Delta::FromMilliseconds(1000);
1298 // Once we always base the timer on the right edge, leaving the older packets 1293 // Once we always base the timer on the right edge, leaving the older packets
1299 // in flight doesn't change the timeout. 1294 // in flight doesn't change the timeout.
1300 EXPECT_EQ(expected_time, manager_.GetRetransmissionTime()); 1295 EXPECT_EQ(expected_time, manager_.GetRetransmissionTime());
1301 } 1296 }
1302 1297
1303 TEST_P(QuicSentPacketManagerTest, GetTransmissionDelayMin) { 1298 TEST_P(QuicSentPacketManagerTest, GetTransmissionDelayMin) {
1304 SendDataPacket(1); 1299 SendDataPacket(1);
1305 EXPECT_CALL(*send_algorithm_, RetransmissionDelay()) 1300 // Provide a 1ms RTT sample.
1306 .WillRepeatedly(Return(QuicTime::Delta::FromMilliseconds(1))); 1301 const_cast<RttStats*>(manager_.GetRttStats())
1302 ->UpdateRtt(QuicTime::Delta::FromMilliseconds(1), QuicTime::Delta::Zero(),
1303 QuicTime::Zero());
1307 QuicTime::Delta delay = QuicTime::Delta::FromMilliseconds(200); 1304 QuicTime::Delta delay = QuicTime::Delta::FromMilliseconds(200);
1308 1305
1309 // If the delay is smaller than the min, ensure it exponentially backs off 1306 // If the delay is smaller than the min, ensure it exponentially backs off
1310 // from the min. 1307 // from the min.
1311 EXPECT_CALL(*network_change_visitor_, OnPathDegrading()); 1308 EXPECT_CALL(*network_change_visitor_, OnPathDegrading());
1312 for (int i = 0; i < 5; ++i) { 1309 for (int i = 0; i < 5; ++i) {
1313 EXPECT_EQ(delay, 1310 EXPECT_EQ(delay,
1314 QuicSentPacketManagerPeer::GetRetransmissionDelay(&manager_)); 1311 QuicSentPacketManagerPeer::GetRetransmissionDelay(&manager_));
1315 delay = delay + delay; 1312 delay = delay + delay;
1316 manager_.OnRetransmissionTimeout(); 1313 manager_.OnRetransmissionTimeout();
1317 RetransmitNextPacket(i + 2); 1314 RetransmitNextPacket(i + 2);
1318 } 1315 }
1319 } 1316 }
1320 1317
1321 TEST_P(QuicSentPacketManagerTest, GetTransmissionDelayMax) { 1318 TEST_P(QuicSentPacketManagerTest, GetTransmissionDelayMax) {
1322 EXPECT_CALL(*send_algorithm_, RetransmissionDelay()) 1319 SendDataPacket(1);
1323 .WillOnce(Return(QuicTime::Delta::FromSeconds(500))); 1320 // Provide a 60s RTT sample.
1321 const_cast<RttStats*>(manager_.GetRttStats())
1322 ->UpdateRtt(QuicTime::Delta::FromSeconds(60), QuicTime::Delta::Zero(),
1323 QuicTime::Zero());
1324 1324
1325 EXPECT_EQ(QuicTime::Delta::FromSeconds(60), 1325 EXPECT_EQ(QuicTime::Delta::FromSeconds(60),
1326 QuicSentPacketManagerPeer::GetRetransmissionDelay(&manager_)); 1326 QuicSentPacketManagerPeer::GetRetransmissionDelay(&manager_));
1327 } 1327 }
1328 1328
1329 TEST_P(QuicSentPacketManagerTest, GetTransmissionDelay) { 1329 TEST_P(QuicSentPacketManagerTest, GetTransmissionDelayExponentialBackoff) {
1330 SendDataPacket(1); 1330 SendDataPacket(1);
1331 QuicTime::Delta delay = QuicTime::Delta::FromMilliseconds(500); 1331 QuicTime::Delta delay = QuicTime::Delta::FromMilliseconds(500);
1332 EXPECT_CALL(*send_algorithm_, RetransmissionDelay())
1333 .WillRepeatedly(Return(delay));
1334 1332
1335 // Delay should back off exponentially. 1333 // Delay should back off exponentially.
1336 EXPECT_CALL(*network_change_visitor_, OnPathDegrading()); 1334 EXPECT_CALL(*network_change_visitor_, OnPathDegrading());
1337 for (int i = 0; i < 5; ++i) { 1335 for (int i = 0; i < 5; ++i) {
1338 EXPECT_EQ(delay, 1336 EXPECT_EQ(delay,
1339 QuicSentPacketManagerPeer::GetRetransmissionDelay(&manager_)); 1337 QuicSentPacketManagerPeer::GetRetransmissionDelay(&manager_));
1340 delay = delay + delay; 1338 delay = delay + delay;
1341 manager_.OnRetransmissionTimeout(); 1339 manager_.OnRetransmissionTimeout();
1342 RetransmitNextPacket(i + 2); 1340 RetransmitNextPacket(i + 2);
1343 } 1341 }
1344 } 1342 }
1345 1343
1344 TEST_F(QuicSentPacketManagerTest, RetransmissionDelay) {
1345 RttStats* rtt_stats = const_cast<RttStats*>(manager_.GetRttStats());
1346 const int64_t kRttMs = 250;
1347 const int64_t kDeviationMs = 5;
1348
1349 rtt_stats->UpdateRtt(QuicTime::Delta::FromMilliseconds(kRttMs),
1350 QuicTime::Delta::Zero(), clock_.Now());
1351
1352 // Initial value is to set the median deviation to half of the initial rtt,
1353 // the median in then multiplied by a factor of 4 and finally the smoothed rtt
1354 // is added which is the initial rtt.
1355 QuicTime::Delta expected_delay =
1356 QuicTime::Delta::FromMilliseconds(kRttMs + kRttMs / 2 * 4);
1357 EXPECT_EQ(expected_delay,
1358 QuicSentPacketManagerPeer::GetRetransmissionDelay(&manager_));
1359
1360 for (int i = 0; i < 100; ++i) {
1361 // Run to make sure that we converge.
1362 rtt_stats->UpdateRtt(
1363 QuicTime::Delta::FromMilliseconds(kRttMs + kDeviationMs),
1364 QuicTime::Delta::Zero(), clock_.Now());
1365 rtt_stats->UpdateRtt(
1366 QuicTime::Delta::FromMilliseconds(kRttMs - kDeviationMs),
1367 QuicTime::Delta::Zero(), clock_.Now());
1368 }
1369 expected_delay = QuicTime::Delta::FromMilliseconds(kRttMs + kDeviationMs * 4);
1370
1371 EXPECT_NEAR(kRttMs, rtt_stats->smoothed_rtt().ToMilliseconds(), 1);
1372 EXPECT_NEAR(expected_delay.ToMilliseconds(),
1373 QuicSentPacketManagerPeer::GetRetransmissionDelay(&manager_)
1374 .ToMilliseconds(),
1375 1);
1376 }
1377
1346 TEST_P(QuicSentPacketManagerTest, GetLossDelay) { 1378 TEST_P(QuicSentPacketManagerTest, GetLossDelay) {
1347 auto loss_algorithm = base::MakeUnique<MockLossAlgorithm>(); 1379 auto loss_algorithm = base::MakeUnique<MockLossAlgorithm>();
1348 QuicSentPacketManagerPeer::SetLossAlgorithm(&manager_, loss_algorithm.get()); 1380 QuicSentPacketManagerPeer::SetLossAlgorithm(&manager_, loss_algorithm.get());
1349 1381
1350 EXPECT_CALL(*loss_algorithm, GetLossTimeout()) 1382 EXPECT_CALL(*loss_algorithm, GetLossTimeout())
1351 .WillRepeatedly(Return(QuicTime::Zero())); 1383 .WillRepeatedly(Return(QuicTime::Zero()));
1352 SendDataPacket(1); 1384 SendDataPacket(1);
1353 SendDataPacket(2); 1385 SendDataPacket(2);
1354 1386
1355 // Handle an ack which causes the loss algorithm to be evaluated and 1387 // Handle an ack which causes the loss algorithm to be evaluated and
(...skipping 347 matching lines...) Expand 10 before | Expand all | Expand 10 after
1703 ExpectAck(1); 1735 ExpectAck(1);
1704 EXPECT_CALL(*network_change_visitor_, 1736 EXPECT_CALL(*network_change_visitor_,
1705 OnPathMtuIncreased(kDefaultLength + 100)); 1737 OnPathMtuIncreased(kDefaultLength + 100));
1706 QuicAckFrame ack_frame = InitAckFrame(1); 1738 QuicAckFrame ack_frame = InitAckFrame(1);
1707 manager_.OnIncomingAck(ack_frame, clock_.Now()); 1739 manager_.OnIncomingAck(ack_frame, clock_.Now());
1708 } 1740 }
1709 1741
1710 } // namespace 1742 } // namespace
1711 } // namespace test 1743 } // namespace test
1712 } // namespace net 1744 } // namespace net
OLDNEW
« no previous file with comments | « net/quic/core/quic_sent_packet_manager.cc ('k') | net/quic/test_tools/quic_test_utils.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698