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

Side by Side Diff: net/tools/quic/quic_time_wait_list_manager_test.cc

Issue 1660533002: Landing Recent QUIC changes until 01/26/2016 18:14 UTC (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 10 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
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/tools/quic/quic_time_wait_list_manager.h" 5 #include "net/tools/quic/quic_time_wait_list_manager.h"
6 6
7 #include <errno.h> 7 #include <errno.h>
8 8
9 #include "net/quic/crypto/crypto_protocol.h" 9 #include "net/quic/crypto/crypto_protocol.h"
10 #include "net/quic/crypto/null_encrypter.h" 10 #include "net/quic/crypto/null_encrypter.h"
(...skipping 211 matching lines...) Expand 10 before | Expand all | Expand 10 after
222 TEST_F(QuicTimeWaitListManagerTest, SendConnectionClose) { 222 TEST_F(QuicTimeWaitListManagerTest, SendConnectionClose) {
223 const size_t kConnectionCloseLength = 100; 223 const size_t kConnectionCloseLength = 100;
224 EXPECT_CALL(visitor_, OnConnectionAddedToTimeWaitList(connection_id_)); 224 EXPECT_CALL(visitor_, OnConnectionAddedToTimeWaitList(connection_id_));
225 std::vector<QuicEncryptedPacket*> termination_packets; 225 std::vector<QuicEncryptedPacket*> termination_packets;
226 termination_packets.push_back(new QuicEncryptedPacket( 226 termination_packets.push_back(new QuicEncryptedPacket(
227 new char[kConnectionCloseLength], kConnectionCloseLength, true)); 227 new char[kConnectionCloseLength], kConnectionCloseLength, true));
228 AddConnectionId(connection_id_, QuicVersionMax(), 228 AddConnectionId(connection_id_, QuicVersionMax(),
229 /*connection_rejected_statelessly=*/false, 229 /*connection_rejected_statelessly=*/false,
230 &termination_packets); 230 &termination_packets);
231 const int kRandomSequenceNumber = 1; 231 const int kRandomSequenceNumber = 1;
232 EXPECT_CALL(writer_, 232 EXPECT_CALL(writer_, WritePacket(_, kConnectionCloseLength,
233 WritePacket(_, kConnectionCloseLength, 233 server_address_.address().bytes(),
234 server_address_.address().bytes(), client_address_)) 234 client_address_, _))
235 .WillOnce(Return(WriteResult(WRITE_STATUS_OK, 1))); 235 .WillOnce(Return(WriteResult(WRITE_STATUS_OK, 1)));
236 236
237 ProcessPacket(connection_id_, kRandomSequenceNumber); 237 ProcessPacket(connection_id_, kRandomSequenceNumber);
238 } 238 }
239 239
240 TEST_F(QuicTimeWaitListManagerTest, SendTwoConnectionCloses) { 240 TEST_F(QuicTimeWaitListManagerTest, SendTwoConnectionCloses) {
241 const size_t kConnectionCloseLength = 100; 241 const size_t kConnectionCloseLength = 100;
242 EXPECT_CALL(visitor_, OnConnectionAddedToTimeWaitList(connection_id_)); 242 EXPECT_CALL(visitor_, OnConnectionAddedToTimeWaitList(connection_id_));
243 std::vector<QuicEncryptedPacket*> termination_packets; 243 std::vector<QuicEncryptedPacket*> termination_packets;
244 termination_packets.push_back(new QuicEncryptedPacket( 244 termination_packets.push_back(new QuicEncryptedPacket(
245 new char[kConnectionCloseLength], kConnectionCloseLength, true)); 245 new char[kConnectionCloseLength], kConnectionCloseLength, true));
246 termination_packets.push_back(new QuicEncryptedPacket( 246 termination_packets.push_back(new QuicEncryptedPacket(
247 new char[kConnectionCloseLength], kConnectionCloseLength, true)); 247 new char[kConnectionCloseLength], kConnectionCloseLength, true));
248 AddConnectionId(connection_id_, QuicVersionMax(), 248 AddConnectionId(connection_id_, QuicVersionMax(),
249 /*connection_rejected_statelessly=*/false, 249 /*connection_rejected_statelessly=*/false,
250 &termination_packets); 250 &termination_packets);
251 const int kRandomSequenceNumber = 1; 251 const int kRandomSequenceNumber = 1;
252 EXPECT_CALL(writer_, 252 EXPECT_CALL(writer_, WritePacket(_, kConnectionCloseLength,
253 WritePacket(_, kConnectionCloseLength, 253 server_address_.address().bytes(),
254 server_address_.address().bytes(), client_address_)) 254 client_address_, _))
255 .Times(2) 255 .Times(2)
256 .WillRepeatedly(Return(WriteResult(WRITE_STATUS_OK, 1))); 256 .WillRepeatedly(Return(WriteResult(WRITE_STATUS_OK, 1)));
257 257
258 ProcessPacket(connection_id_, kRandomSequenceNumber); 258 ProcessPacket(connection_id_, kRandomSequenceNumber);
259 } 259 }
260 260
261 TEST_F(QuicTimeWaitListManagerTest, SendPublicReset) { 261 TEST_F(QuicTimeWaitListManagerTest, SendPublicReset) {
262 EXPECT_CALL(visitor_, OnConnectionAddedToTimeWaitList(connection_id_)); 262 EXPECT_CALL(visitor_, OnConnectionAddedToTimeWaitList(connection_id_));
263 AddConnectionId(connection_id_); 263 AddConnectionId(connection_id_);
264 const int kRandomSequenceNumber = 1; 264 const int kRandomSequenceNumber = 1;
265 EXPECT_CALL(writer_, WritePacket(_, _, server_address_.address().bytes(), 265 EXPECT_CALL(writer_, WritePacket(_, _, server_address_.address().bytes(),
266 client_address_)) 266 client_address_, _))
267 .With(Args<0, 1>( 267 .With(Args<0, 1>(
268 PublicResetPacketEq(connection_id_, kRandomSequenceNumber))) 268 PublicResetPacketEq(connection_id_, kRandomSequenceNumber)))
269 .WillOnce(Return(WriteResult(WRITE_STATUS_OK, 0))); 269 .WillOnce(Return(WriteResult(WRITE_STATUS_OK, 0)));
270 270
271 ProcessPacket(connection_id_, kRandomSequenceNumber); 271 ProcessPacket(connection_id_, kRandomSequenceNumber);
272 } 272 }
273 273
274 TEST_F(QuicTimeWaitListManagerTest, SendPublicResetWithExponentialBackOff) { 274 TEST_F(QuicTimeWaitListManagerTest, SendPublicResetWithExponentialBackOff) {
275 EXPECT_CALL(visitor_, OnConnectionAddedToTimeWaitList(connection_id_)); 275 EXPECT_CALL(visitor_, OnConnectionAddedToTimeWaitList(connection_id_));
276 AddConnectionId(connection_id_); 276 AddConnectionId(connection_id_);
277 EXPECT_EQ(1u, time_wait_list_manager_.num_connections()); 277 EXPECT_EQ(1u, time_wait_list_manager_.num_connections());
278 for (int packet_number = 1; packet_number < 101; ++packet_number) { 278 for (int packet_number = 1; packet_number < 101; ++packet_number) {
279 if ((packet_number & (packet_number - 1)) == 0) { 279 if ((packet_number & (packet_number - 1)) == 0) {
280 EXPECT_CALL(writer_, WritePacket(_, _, _, _)) 280 EXPECT_CALL(writer_, WritePacket(_, _, _, _, _))
281 .WillOnce(Return(WriteResult(WRITE_STATUS_OK, 1))); 281 .WillOnce(Return(WriteResult(WRITE_STATUS_OK, 1)));
282 } 282 }
283 ProcessPacket(connection_id_, packet_number); 283 ProcessPacket(connection_id_, packet_number);
284 // Send public reset with exponential back off. 284 // Send public reset with exponential back off.
285 if ((packet_number & (packet_number - 1)) == 0) { 285 if ((packet_number & (packet_number - 1)) == 0) {
286 EXPECT_TRUE(QuicTimeWaitListManagerPeer::ShouldSendResponse( 286 EXPECT_TRUE(QuicTimeWaitListManagerPeer::ShouldSendResponse(
287 &time_wait_list_manager_, packet_number)); 287 &time_wait_list_manager_, packet_number));
288 } else { 288 } else {
289 EXPECT_FALSE(QuicTimeWaitListManagerPeer::ShouldSendResponse( 289 EXPECT_FALSE(QuicTimeWaitListManagerPeer::ShouldSendResponse(
290 &time_wait_list_manager_, packet_number)); 290 &time_wait_list_manager_, packet_number));
291 } 291 }
292 } 292 }
293 } 293 }
294 294
295 TEST_F(QuicTimeWaitListManagerTest, NoPublicResetForStatelessConnections) { 295 TEST_F(QuicTimeWaitListManagerTest, NoPublicResetForStatelessConnections) {
296 EXPECT_CALL(visitor_, OnConnectionAddedToTimeWaitList(connection_id_)); 296 EXPECT_CALL(visitor_, OnConnectionAddedToTimeWaitList(connection_id_));
297 AddStatelessConnectionId(connection_id_); 297 AddStatelessConnectionId(connection_id_);
298 const int kRandomSequenceNumber = 1; 298 const int kRandomSequenceNumber = 1;
299 299
300 EXPECT_CALL(writer_, WritePacket(_, _, server_address_.address().bytes(), 300 EXPECT_CALL(writer_, WritePacket(_, _, server_address_.address().bytes(),
301 client_address_)) 301 client_address_, _))
302 .WillOnce(Return(WriteResult(WRITE_STATUS_OK, 1))); 302 .WillOnce(Return(WriteResult(WRITE_STATUS_OK, 1)));
303 303
304 ProcessPacket(connection_id_, kRandomSequenceNumber); 304 ProcessPacket(connection_id_, kRandomSequenceNumber);
305 } 305 }
306 306
307 TEST_F(QuicTimeWaitListManagerTest, CleanUpOldConnectionIds) { 307 TEST_F(QuicTimeWaitListManagerTest, CleanUpOldConnectionIds) {
308 const size_t kConnectionIdCount = 100; 308 const size_t kConnectionIdCount = 100;
309 const size_t kOldConnectionIdCount = 31; 309 const size_t kOldConnectionIdCount = 31;
310 310
311 // Add connection_ids such that their expiry time is time_wait_period_. 311 // Add connection_ids such that their expiry time is time_wait_period_.
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
358 358
359 TEST_F(QuicTimeWaitListManagerTest, SendQueuedPackets) { 359 TEST_F(QuicTimeWaitListManagerTest, SendQueuedPackets) {
360 QuicConnectionId connection_id = 1; 360 QuicConnectionId connection_id = 1;
361 EXPECT_CALL(visitor_, OnConnectionAddedToTimeWaitList(connection_id)); 361 EXPECT_CALL(visitor_, OnConnectionAddedToTimeWaitList(connection_id));
362 AddConnectionId(connection_id); 362 AddConnectionId(connection_id);
363 QuicPacketNumber packet_number = 234; 363 QuicPacketNumber packet_number = 234;
364 scoped_ptr<QuicEncryptedPacket> packet( 364 scoped_ptr<QuicEncryptedPacket> packet(
365 ConstructEncryptedPacket(connection_id, packet_number)); 365 ConstructEncryptedPacket(connection_id, packet_number));
366 // Let first write through. 366 // Let first write through.
367 EXPECT_CALL(writer_, WritePacket(_, _, server_address_.address().bytes(), 367 EXPECT_CALL(writer_, WritePacket(_, _, server_address_.address().bytes(),
368 client_address_)) 368 client_address_, _))
369 .With(Args<0, 1>(PublicResetPacketEq(connection_id, packet_number))) 369 .With(Args<0, 1>(PublicResetPacketEq(connection_id, packet_number)))
370 .WillOnce(Return(WriteResult(WRITE_STATUS_OK, packet->length()))); 370 .WillOnce(Return(WriteResult(WRITE_STATUS_OK, packet->length())));
371 ProcessPacket(connection_id, packet_number); 371 ProcessPacket(connection_id, packet_number);
372 372
373 // write block for the next packet. 373 // write block for the next packet.
374 EXPECT_CALL(writer_, WritePacket(_, _, server_address_.address().bytes(), 374 EXPECT_CALL(writer_, WritePacket(_, _, server_address_.address().bytes(),
375 client_address_)) 375 client_address_, _))
376 .With(Args<0, 1>(PublicResetPacketEq(connection_id, packet_number))) 376 .With(Args<0, 1>(PublicResetPacketEq(connection_id, packet_number)))
377 .WillOnce(DoAll(Assign(&writer_is_blocked_, true), 377 .WillOnce(DoAll(Assign(&writer_is_blocked_, true),
378 Return(WriteResult(WRITE_STATUS_BLOCKED, EAGAIN)))); 378 Return(WriteResult(WRITE_STATUS_BLOCKED, EAGAIN))));
379 EXPECT_CALL(visitor_, OnWriteBlocked(&time_wait_list_manager_)); 379 EXPECT_CALL(visitor_, OnWriteBlocked(&time_wait_list_manager_));
380 ProcessPacket(connection_id, packet_number); 380 ProcessPacket(connection_id, packet_number);
381 // 3rd packet. No public reset should be sent; 381 // 3rd packet. No public reset should be sent;
382 ProcessPacket(connection_id, packet_number); 382 ProcessPacket(connection_id, packet_number);
383 383
384 // write packet should not be called since we are write blocked but the 384 // write packet should not be called since we are write blocked but the
385 // should be queued. 385 // should be queued.
386 QuicConnectionId other_connection_id = 2; 386 QuicConnectionId other_connection_id = 2;
387 EXPECT_CALL(visitor_, OnConnectionAddedToTimeWaitList(other_connection_id)); 387 EXPECT_CALL(visitor_, OnConnectionAddedToTimeWaitList(other_connection_id));
388 AddConnectionId(other_connection_id); 388 AddConnectionId(other_connection_id);
389 QuicPacketNumber other_packet_number = 23423; 389 QuicPacketNumber other_packet_number = 23423;
390 scoped_ptr<QuicEncryptedPacket> other_packet( 390 scoped_ptr<QuicEncryptedPacket> other_packet(
391 ConstructEncryptedPacket(other_connection_id, other_packet_number)); 391 ConstructEncryptedPacket(other_connection_id, other_packet_number));
392 EXPECT_CALL(writer_, WritePacket(_, _, _, _)).Times(0); 392 EXPECT_CALL(writer_, WritePacket(_, _, _, _, _)).Times(0);
393 EXPECT_CALL(visitor_, OnWriteBlocked(&time_wait_list_manager_)); 393 EXPECT_CALL(visitor_, OnWriteBlocked(&time_wait_list_manager_));
394 ProcessPacket(other_connection_id, other_packet_number); 394 ProcessPacket(other_connection_id, other_packet_number);
395 EXPECT_EQ(2u, time_wait_list_manager_.num_connections()); 395 EXPECT_EQ(2u, time_wait_list_manager_.num_connections());
396 396
397 // Now expect all the write blocked public reset packets to be sent again. 397 // Now expect all the write blocked public reset packets to be sent again.
398 writer_is_blocked_ = false; 398 writer_is_blocked_ = false;
399 EXPECT_CALL(writer_, WritePacket(_, _, server_address_.address().bytes(), 399 EXPECT_CALL(writer_, WritePacket(_, _, server_address_.address().bytes(),
400 client_address_)) 400 client_address_, _))
401 .With(Args<0, 1>(PublicResetPacketEq(connection_id, packet_number))) 401 .With(Args<0, 1>(PublicResetPacketEq(connection_id, packet_number)))
402 .WillOnce(Return(WriteResult(WRITE_STATUS_OK, packet->length()))); 402 .WillOnce(Return(WriteResult(WRITE_STATUS_OK, packet->length())));
403 EXPECT_CALL(writer_, WritePacket(_, _, server_address_.address().bytes(), 403 EXPECT_CALL(writer_, WritePacket(_, _, server_address_.address().bytes(),
404 client_address_)) 404 client_address_, _))
405 .With(Args<0, 1>( 405 .With(Args<0, 1>(
406 PublicResetPacketEq(other_connection_id, other_packet_number))) 406 PublicResetPacketEq(other_connection_id, other_packet_number)))
407 .WillOnce(Return(WriteResult(WRITE_STATUS_OK, other_packet->length()))); 407 .WillOnce(Return(WriteResult(WRITE_STATUS_OK, other_packet->length())));
408 time_wait_list_manager_.OnCanWrite(); 408 time_wait_list_manager_.OnCanWrite();
409 } 409 }
410 410
411 TEST_F(QuicTimeWaitListManagerTest, GetQuicVersionFromMap) { 411 TEST_F(QuicTimeWaitListManagerTest, GetQuicVersionFromMap) {
412 const int kConnectionId1 = 123; 412 const int kConnectionId1 = 123;
413 const int kConnectionId2 = 456; 413 const int kConnectionId2 = 456;
414 const int kConnectionId3 = 789; 414 const int kConnectionId3 = 789;
(...skipping 28 matching lines...) Expand all
443 const size_t kConnectionCloseLength = 100; 443 const size_t kConnectionCloseLength = 100;
444 std::vector<QuicEncryptedPacket*> termination_packets; 444 std::vector<QuicEncryptedPacket*> termination_packets;
445 termination_packets.push_back(new QuicEncryptedPacket( 445 termination_packets.push_back(new QuicEncryptedPacket(
446 new char[kConnectionCloseLength], kConnectionCloseLength, true)); 446 new char[kConnectionCloseLength], kConnectionCloseLength, true));
447 AddConnectionId(connection_id_, QuicVersionMax(), 447 AddConnectionId(connection_id_, QuicVersionMax(),
448 /*connection_rejected_statelessly=*/false, 448 /*connection_rejected_statelessly=*/false,
449 &termination_packets); 449 &termination_packets);
450 EXPECT_TRUE(IsConnectionIdInTimeWait(connection_id_)); 450 EXPECT_TRUE(IsConnectionIdInTimeWait(connection_id_));
451 EXPECT_EQ(1u, time_wait_list_manager_.num_connections()); 451 EXPECT_EQ(1u, time_wait_list_manager_.num_connections());
452 452
453 EXPECT_CALL(writer_, 453 EXPECT_CALL(writer_, WritePacket(_, kConnectionCloseLength,
454 WritePacket(_, kConnectionCloseLength, 454 server_address_.address().bytes(),
455 server_address_.address().bytes(), client_address_)) 455 client_address_, _))
456 .WillOnce(Return(WriteResult(WRITE_STATUS_OK, 1))); 456 .WillOnce(Return(WriteResult(WRITE_STATUS_OK, 1)));
457 457
458 const int kRandomSequenceNumber = 1; 458 const int kRandomSequenceNumber = 1;
459 ProcessPacket(connection_id_, kRandomSequenceNumber); 459 ProcessPacket(connection_id_, kRandomSequenceNumber);
460 460
461 const QuicTime::Delta time_wait_period = 461 const QuicTime::Delta time_wait_period =
462 QuicTimeWaitListManagerPeer::time_wait_period(&time_wait_list_manager_); 462 QuicTimeWaitListManagerPeer::time_wait_period(&time_wait_list_manager_);
463 463
464 QuicTime::Delta offset = QuicTime::Delta::FromMicroseconds(39); 464 QuicTime::Delta offset = QuicTime::Delta::FromMicroseconds(39);
465 // Now set the current time as time_wait_period + offset usecs. 465 // Now set the current time as time_wait_period + offset usecs.
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
539 EXPECT_EQ(static_cast<size_t>(FLAGS_quic_time_wait_list_max_connections), 539 EXPECT_EQ(static_cast<size_t>(FLAGS_quic_time_wait_list_max_connections),
540 time_wait_list_manager_.num_connections()); 540 time_wait_list_manager_.num_connections());
541 EXPECT_FALSE(IsConnectionIdInTimeWait(id_to_evict)); 541 EXPECT_FALSE(IsConnectionIdInTimeWait(id_to_evict));
542 EXPECT_TRUE(IsConnectionIdInTimeWait(current_connection_id)); 542 EXPECT_TRUE(IsConnectionIdInTimeWait(current_connection_id));
543 } 543 }
544 } 544 }
545 545
546 } // namespace 546 } // namespace
547 } // namespace test 547 } // namespace test
548 } // namespace net 548 } // namespace net
OLDNEW
« no previous file with comments | « net/tools/quic/quic_time_wait_list_manager.cc ('k') | net/tools/quic/test_tools/limited_mtu_test_writer.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698