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

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

Issue 2391103003: Landing Recent QUIC changes until 3:24 PM, Oct 01, 2016 UTC-4 (Closed)
Patch Set: Add new error code to quic_error_mapping.cc 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/core/quic_spdy_stream.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 21 matching lines...) Expand all
1158 // Retransmit the packet by invoking the retransmission timeout. 1153 // Retransmit the packet by invoking the retransmission timeout.
1159 clock_.AdvanceTime(1.5 * srtt); 1154 clock_.AdvanceTime(1.5 * srtt);
1160 manager_.OnRetransmissionTimeout(); 1155 manager_.OnRetransmissionTimeout();
1161 RetransmitNextPacket(2); 1156 RetransmitNextPacket(2);
1162 1157
1163 // The retransmission time should now be twice as far in the future. 1158 // The retransmission time should now be twice as far in the future.
1164 expected_time = clock_.Now() + srtt * 2 * 1.5; 1159 expected_time = clock_.Now() + srtt * 2 * 1.5;
1165 EXPECT_EQ(expected_time, manager_.GetRetransmissionTime()); 1160 EXPECT_EQ(expected_time, manager_.GetRetransmissionTime());
1166 } 1161 }
1167 1162
1163 TEST_P(QuicSentPacketManagerTest,
1164 GetConservativeTransmissionTimeCryptoHandshake) {
1165 FLAGS_quic_conservative_handshake_retransmits = true;
1166 QuicConfig config;
1167 QuicTagVector options;
1168 options.push_back(kCONH);
1169 QuicConfigPeer::SetReceivedConnectionOptions(&config, options);
1170 EXPECT_CALL(*send_algorithm_, SetFromConfig(_, _));
1171 EXPECT_CALL(*network_change_visitor_, OnCongestionChange());
1172 manager_.SetFromConfig(config);
1173 // Calling SetFromConfig requires mocking out some send algorithm methods.
1174 EXPECT_CALL(*send_algorithm_, PacingRate(_))
1175 .WillRepeatedly(Return(QuicBandwidth::Zero()));
1176 EXPECT_CALL(*send_algorithm_, GetCongestionWindow())
1177 .WillRepeatedly(Return(10 * kDefaultTCPMSS));
1178
1179 SendCryptoPacket(1);
1180
1181 // Check the min.
1182 RttStats* rtt_stats = const_cast<RttStats*>(manager_.GetRttStats());
1183 rtt_stats->set_initial_rtt_us(1 * kNumMicrosPerMilli);
1184 EXPECT_EQ(clock_.Now() + QuicTime::Delta::FromMilliseconds(25),
1185 manager_.GetRetransmissionTime());
1186
1187 // Test with a standard smoothed RTT.
1188 rtt_stats->set_initial_rtt_us(100 * kNumMicrosPerMilli);
1189
1190 QuicTime::Delta srtt =
1191 QuicTime::Delta::FromMicroseconds(rtt_stats->initial_rtt_us());
1192 QuicTime expected_time = clock_.Now() + 2 * srtt;
1193 EXPECT_EQ(expected_time, manager_.GetRetransmissionTime());
1194
1195 // Retransmit the packet by invoking the retransmission timeout.
1196 clock_.AdvanceTime(2 * srtt);
1197 manager_.OnRetransmissionTimeout();
1198 RetransmitNextPacket(2);
1199
1200 // The retransmission time should now be twice as far in the future.
1201 expected_time = clock_.Now() + srtt * 2 * 2;
1202 EXPECT_EQ(expected_time, manager_.GetRetransmissionTime());
1203 }
1204
1168 TEST_P(QuicSentPacketManagerTest, GetTransmissionTimeTailLossProbe) { 1205 TEST_P(QuicSentPacketManagerTest, GetTransmissionTimeTailLossProbe) {
1169 QuicSentPacketManagerPeer::SetMaxTailLossProbes(&manager_, 2); 1206 QuicSentPacketManagerPeer::SetMaxTailLossProbes(&manager_, 2);
1170 SendDataPacket(1); 1207 SendDataPacket(1);
1171 SendDataPacket(2); 1208 SendDataPacket(2);
1172 1209
1173 // Check the min. 1210 // Check the min.
1174 RttStats* rtt_stats = const_cast<RttStats*>(manager_.GetRttStats()); 1211 RttStats* rtt_stats = const_cast<RttStats*>(manager_.GetRttStats());
1175 rtt_stats->set_initial_rtt_us(1 * kNumMicrosPerMilli); 1212 rtt_stats->set_initial_rtt_us(1 * kNumMicrosPerMilli);
1176 EXPECT_EQ(clock_.Now() + QuicTime::Delta::FromMilliseconds(10), 1213 EXPECT_EQ(clock_.Now() + QuicTime::Delta::FromMilliseconds(10),
1177 manager_.GetRetransmissionTime()); 1214 manager_.GetRetransmissionTime());
(...skipping 20 matching lines...) Expand all
1198 .WillOnce(Return(QuicTime::Delta::Infinite())); 1235 .WillOnce(Return(QuicTime::Delta::Infinite()));
1199 EXPECT_EQ(QuicTime::Delta::Infinite(), 1236 EXPECT_EQ(QuicTime::Delta::Infinite(),
1200 manager_.TimeUntilSend(clock_.Now(), &path_id)); 1237 manager_.TimeUntilSend(clock_.Now(), &path_id));
1201 EXPECT_FALSE(manager_.HasPendingRetransmissions()); 1238 EXPECT_FALSE(manager_.HasPendingRetransmissions());
1202 1239
1203 expected_time = clock_.Now() + expected_tlp_delay; 1240 expected_time = clock_.Now() + expected_tlp_delay;
1204 EXPECT_EQ(expected_time, manager_.GetRetransmissionTime()); 1241 EXPECT_EQ(expected_time, manager_.GetRetransmissionTime());
1205 } 1242 }
1206 1243
1207 TEST_P(QuicSentPacketManagerTest, GetTransmissionTimeSpuriousRTO) { 1244 TEST_P(QuicSentPacketManagerTest, GetTransmissionTimeSpuriousRTO) {
1208 const_cast<RttStats*>(manager_.GetRttStats()) 1245 RttStats* rtt_stats = const_cast<RttStats*>(manager_.GetRttStats());
1209 ->UpdateRtt(QuicTime::Delta::FromMilliseconds(100), 1246 rtt_stats->UpdateRtt(QuicTime::Delta::FromMilliseconds(100),
1210 QuicTime::Delta::Zero(), QuicTime::Zero()); 1247 QuicTime::Delta::Zero(), QuicTime::Zero());
1248
1211 SendDataPacket(1); 1249 SendDataPacket(1);
1212 SendDataPacket(2); 1250 SendDataPacket(2);
1213 SendDataPacket(3); 1251 SendDataPacket(3);
1214 SendDataPacket(4); 1252 SendDataPacket(4);
1215 1253
1216 QuicTime::Delta expected_rto_delay = QuicTime::Delta::FromMilliseconds(500); 1254 QuicTime::Delta expected_rto_delay =
1217 EXPECT_CALL(*send_algorithm_, RetransmissionDelay()) 1255 rtt_stats->smoothed_rtt() + 4 * rtt_stats->mean_deviation();
1218 .WillRepeatedly(Return(expected_rto_delay));
1219 QuicTime expected_time = clock_.Now() + expected_rto_delay; 1256 QuicTime expected_time = clock_.Now() + expected_rto_delay;
1220 EXPECT_EQ(expected_time, manager_.GetRetransmissionTime()); 1257 EXPECT_EQ(expected_time, manager_.GetRetransmissionTime());
1221 1258
1222 // Retransmit the packet by invoking the retransmission timeout. 1259 // Retransmit the packet by invoking the retransmission timeout.
1223 clock_.AdvanceTime(expected_rto_delay); 1260 clock_.AdvanceTime(expected_rto_delay);
1224 manager_.OnRetransmissionTimeout(); 1261 manager_.OnRetransmissionTimeout();
1225 // All packets are still considered inflight. 1262 // All packets are still considered inflight.
1226 EXPECT_EQ(4 * kDefaultLength, 1263 EXPECT_EQ(4 * kDefaultLength,
1227 QuicSentPacketManagerPeer::GetBytesInFlight(&manager_)); 1264 QuicSentPacketManagerPeer::GetBytesInFlight(&manager_));
1228 RetransmitNextPacket(5); 1265 RetransmitNextPacket(5);
(...skipping 24 matching lines...) Expand all
1253 // Since retransmission was spurious, smoothed_rtt_ is expired, and replaced 1290 // Since retransmission was spurious, smoothed_rtt_ is expired, and replaced
1254 // by the latest RTT sample of 500ms. 1291 // by the latest RTT sample of 500ms.
1255 expected_time = clock_.Now() + QuicTime::Delta::FromMilliseconds(1000); 1292 expected_time = clock_.Now() + QuicTime::Delta::FromMilliseconds(1000);
1256 // 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
1257 // in flight doesn't change the timeout. 1294 // in flight doesn't change the timeout.
1258 EXPECT_EQ(expected_time, manager_.GetRetransmissionTime()); 1295 EXPECT_EQ(expected_time, manager_.GetRetransmissionTime());
1259 } 1296 }
1260 1297
1261 TEST_P(QuicSentPacketManagerTest, GetTransmissionDelayMin) { 1298 TEST_P(QuicSentPacketManagerTest, GetTransmissionDelayMin) {
1262 SendDataPacket(1); 1299 SendDataPacket(1);
1263 EXPECT_CALL(*send_algorithm_, RetransmissionDelay()) 1300 // Provide a 1ms RTT sample.
1264 .WillRepeatedly(Return(QuicTime::Delta::FromMilliseconds(1))); 1301 const_cast<RttStats*>(manager_.GetRttStats())
1302 ->UpdateRtt(QuicTime::Delta::FromMilliseconds(1), QuicTime::Delta::Zero(),
1303 QuicTime::Zero());
1265 QuicTime::Delta delay = QuicTime::Delta::FromMilliseconds(200); 1304 QuicTime::Delta delay = QuicTime::Delta::FromMilliseconds(200);
1266 1305
1267 // 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
1268 // from the min. 1307 // from the min.
1269 EXPECT_CALL(*network_change_visitor_, OnPathDegrading()); 1308 EXPECT_CALL(*network_change_visitor_, OnPathDegrading());
1270 for (int i = 0; i < 5; ++i) { 1309 for (int i = 0; i < 5; ++i) {
1271 EXPECT_EQ(delay, 1310 EXPECT_EQ(delay,
1272 QuicSentPacketManagerPeer::GetRetransmissionDelay(&manager_)); 1311 QuicSentPacketManagerPeer::GetRetransmissionDelay(&manager_));
1273 delay = delay + delay; 1312 delay = delay + delay;
1274 manager_.OnRetransmissionTimeout(); 1313 manager_.OnRetransmissionTimeout();
1275 RetransmitNextPacket(i + 2); 1314 RetransmitNextPacket(i + 2);
1276 } 1315 }
1277 } 1316 }
1278 1317
1279 TEST_P(QuicSentPacketManagerTest, GetTransmissionDelayMax) { 1318 TEST_P(QuicSentPacketManagerTest, GetTransmissionDelayMax) {
1280 EXPECT_CALL(*send_algorithm_, RetransmissionDelay()) 1319 SendDataPacket(1);
1281 .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());
1282 1324
1283 EXPECT_EQ(QuicTime::Delta::FromSeconds(60), 1325 EXPECT_EQ(QuicTime::Delta::FromSeconds(60),
1284 QuicSentPacketManagerPeer::GetRetransmissionDelay(&manager_)); 1326 QuicSentPacketManagerPeer::GetRetransmissionDelay(&manager_));
1285 } 1327 }
1286 1328
1287 TEST_P(QuicSentPacketManagerTest, GetTransmissionDelay) { 1329 TEST_P(QuicSentPacketManagerTest, GetTransmissionDelayExponentialBackoff) {
1288 SendDataPacket(1); 1330 SendDataPacket(1);
1289 QuicTime::Delta delay = QuicTime::Delta::FromMilliseconds(500); 1331 QuicTime::Delta delay = QuicTime::Delta::FromMilliseconds(500);
1290 EXPECT_CALL(*send_algorithm_, RetransmissionDelay())
1291 .WillRepeatedly(Return(delay));
1292 1332
1293 // Delay should back off exponentially. 1333 // Delay should back off exponentially.
1294 EXPECT_CALL(*network_change_visitor_, OnPathDegrading()); 1334 EXPECT_CALL(*network_change_visitor_, OnPathDegrading());
1295 for (int i = 0; i < 5; ++i) { 1335 for (int i = 0; i < 5; ++i) {
1296 EXPECT_EQ(delay, 1336 EXPECT_EQ(delay,
1297 QuicSentPacketManagerPeer::GetRetransmissionDelay(&manager_)); 1337 QuicSentPacketManagerPeer::GetRetransmissionDelay(&manager_));
1298 delay = delay + delay; 1338 delay = delay + delay;
1299 manager_.OnRetransmissionTimeout(); 1339 manager_.OnRetransmissionTimeout();
1300 RetransmitNextPacket(i + 2); 1340 RetransmitNextPacket(i + 2);
1301 } 1341 }
1302 } 1342 }
1303 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
1304 TEST_P(QuicSentPacketManagerTest, GetLossDelay) { 1378 TEST_P(QuicSentPacketManagerTest, GetLossDelay) {
1305 auto loss_algorithm = base::MakeUnique<MockLossAlgorithm>(); 1379 auto loss_algorithm = base::MakeUnique<MockLossAlgorithm>();
1306 QuicSentPacketManagerPeer::SetLossAlgorithm(&manager_, loss_algorithm.get()); 1380 QuicSentPacketManagerPeer::SetLossAlgorithm(&manager_, loss_algorithm.get());
1307 1381
1308 EXPECT_CALL(*loss_algorithm, GetLossTimeout()) 1382 EXPECT_CALL(*loss_algorithm, GetLossTimeout())
1309 .WillRepeatedly(Return(QuicTime::Zero())); 1383 .WillRepeatedly(Return(QuicTime::Zero()));
1310 SendDataPacket(1); 1384 SendDataPacket(1);
1311 SendDataPacket(2); 1385 SendDataPacket(2);
1312 1386
1313 // 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
1661 ExpectAck(1); 1735 ExpectAck(1);
1662 EXPECT_CALL(*network_change_visitor_, 1736 EXPECT_CALL(*network_change_visitor_,
1663 OnPathMtuIncreased(kDefaultLength + 100)); 1737 OnPathMtuIncreased(kDefaultLength + 100));
1664 QuicAckFrame ack_frame = InitAckFrame(1); 1738 QuicAckFrame ack_frame = InitAckFrame(1);
1665 manager_.OnIncomingAck(ack_frame, clock_.Now()); 1739 manager_.OnIncomingAck(ack_frame, clock_.Now());
1666 } 1740 }
1667 1741
1668 } // namespace 1742 } // namespace
1669 } // namespace test 1743 } // namespace test
1670 } // namespace net 1744 } // namespace net
OLDNEW
« no previous file with comments | « net/quic/core/quic_sent_packet_manager.cc ('k') | net/quic/core/quic_spdy_stream.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698