| 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/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 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 62 }; | 62 }; |
| 63 | 63 |
| 64 class QuicTimeWaitListManagerPeer { | 64 class QuicTimeWaitListManagerPeer { |
| 65 public: | 65 public: |
| 66 static bool ShouldSendResponse(QuicTimeWaitListManager* manager, | 66 static bool ShouldSendResponse(QuicTimeWaitListManager* manager, |
| 67 int received_packet_count) { | 67 int received_packet_count) { |
| 68 return manager->ShouldSendResponse(received_packet_count); | 68 return manager->ShouldSendResponse(received_packet_count); |
| 69 } | 69 } |
| 70 | 70 |
| 71 static QuicTime::Delta time_wait_period(QuicTimeWaitListManager* manager) { | 71 static QuicTime::Delta time_wait_period(QuicTimeWaitListManager* manager) { |
| 72 return manager->kTimeWaitPeriod_; | 72 return manager->time_wait_period_; |
| 73 } | 73 } |
| 74 | 74 |
| 75 static QuicVersion GetQuicVersionFromConnectionId( | 75 static QuicVersion GetQuicVersionFromConnectionId( |
| 76 QuicTimeWaitListManager* manager, | 76 QuicTimeWaitListManager* manager, |
| 77 QuicConnectionId connection_id) { | 77 QuicConnectionId connection_id) { |
| 78 return manager->GetQuicVersionFromConnectionId(connection_id); | 78 return manager->GetQuicVersionFromConnectionId(connection_id); |
| 79 } | 79 } |
| 80 }; | 80 }; |
| 81 | 81 |
| 82 namespace { | 82 namespace { |
| (...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 221 | 221 |
| 222 TEST_F(QuicTimeWaitListManagerTest, CheckConnectionIdInTimeWait) { | 222 TEST_F(QuicTimeWaitListManagerTest, CheckConnectionIdInTimeWait) { |
| 223 EXPECT_FALSE(IsConnectionIdInTimeWait(connection_id_)); | 223 EXPECT_FALSE(IsConnectionIdInTimeWait(connection_id_)); |
| 224 EXPECT_CALL(visitor_, OnConnectionAddedToTimeWaitList(connection_id_)); | 224 EXPECT_CALL(visitor_, OnConnectionAddedToTimeWaitList(connection_id_)); |
| 225 AddConnectionId(connection_id_); | 225 AddConnectionId(connection_id_); |
| 226 EXPECT_EQ(1u, time_wait_list_manager_.num_connections()); | 226 EXPECT_EQ(1u, time_wait_list_manager_.num_connections()); |
| 227 EXPECT_TRUE(IsConnectionIdInTimeWait(connection_id_)); | 227 EXPECT_TRUE(IsConnectionIdInTimeWait(connection_id_)); |
| 228 } | 228 } |
| 229 | 229 |
| 230 TEST_F(QuicTimeWaitListManagerTest, SendConnectionClose) { | 230 TEST_F(QuicTimeWaitListManagerTest, SendConnectionClose) { |
| 231 size_t kConnectionCloseLength = 100; | 231 const size_t kConnectionCloseLength = 100; |
| 232 EXPECT_CALL(visitor_, OnConnectionAddedToTimeWaitList(connection_id_)); | 232 EXPECT_CALL(visitor_, OnConnectionAddedToTimeWaitList(connection_id_)); |
| 233 AddConnectionId( | 233 AddConnectionId( |
| 234 connection_id_, | 234 connection_id_, |
| 235 QuicVersionMax(), | 235 QuicVersionMax(), |
| 236 new QuicEncryptedPacket( | 236 new QuicEncryptedPacket( |
| 237 new char[kConnectionCloseLength], kConnectionCloseLength, true)); | 237 new char[kConnectionCloseLength], kConnectionCloseLength, true)); |
| 238 const int kRandomSequenceNumber = 1; | 238 const int kRandomSequenceNumber = 1; |
| 239 EXPECT_CALL(writer_, WritePacket(_, kConnectionCloseLength, | 239 EXPECT_CALL(writer_, WritePacket(_, kConnectionCloseLength, |
| 240 server_address_.address(), | 240 server_address_.address(), |
| 241 client_address_)) | 241 client_address_)) |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 276 EXPECT_FALSE(QuicTimeWaitListManagerPeer::ShouldSendResponse( | 276 EXPECT_FALSE(QuicTimeWaitListManagerPeer::ShouldSendResponse( |
| 277 &time_wait_list_manager_, sequence_number)); | 277 &time_wait_list_manager_, sequence_number)); |
| 278 } | 278 } |
| 279 } | 279 } |
| 280 } | 280 } |
| 281 | 281 |
| 282 TEST_F(QuicTimeWaitListManagerTest, CleanUpOldConnectionIds) { | 282 TEST_F(QuicTimeWaitListManagerTest, CleanUpOldConnectionIds) { |
| 283 const size_t kConnectionIdCount = 100; | 283 const size_t kConnectionIdCount = 100; |
| 284 const size_t kOldConnectionIdCount = 31; | 284 const size_t kOldConnectionIdCount = 31; |
| 285 | 285 |
| 286 // Add connection_ids such that their expiry time is kTimeWaitPeriod_. | 286 // Add connection_ids such that their expiry time is time_wait_period_. |
| 287 epoll_server_.set_now_in_usec(0); | 287 epoll_server_.set_now_in_usec(0); |
| 288 for (size_t connection_id = 1; connection_id <= kOldConnectionIdCount; | 288 for (size_t connection_id = 1; connection_id <= kOldConnectionIdCount; |
| 289 ++connection_id) { | 289 ++connection_id) { |
| 290 EXPECT_CALL(visitor_, OnConnectionAddedToTimeWaitList(connection_id)); | 290 EXPECT_CALL(visitor_, OnConnectionAddedToTimeWaitList(connection_id)); |
| 291 AddConnectionId(connection_id); | 291 AddConnectionId(connection_id); |
| 292 } | 292 } |
| 293 EXPECT_EQ(kOldConnectionIdCount, time_wait_list_manager_.num_connections()); | 293 EXPECT_EQ(kOldConnectionIdCount, time_wait_list_manager_.num_connections()); |
| 294 | 294 |
| 295 // Add remaining connection_ids such that their add time is | 295 // Add remaining connection_ids such that their add time is |
| 296 // 2 * kTimeWaitPeriod. | 296 // 2 * time_wait_period_. |
| 297 const QuicTime::Delta time_wait_period = | 297 const QuicTime::Delta time_wait_period = |
| 298 QuicTimeWaitListManagerPeer::time_wait_period(&time_wait_list_manager_); | 298 QuicTimeWaitListManagerPeer::time_wait_period(&time_wait_list_manager_); |
| 299 epoll_server_.set_now_in_usec(time_wait_period.ToMicroseconds()); | 299 epoll_server_.set_now_in_usec(time_wait_period.ToMicroseconds()); |
| 300 for (size_t connection_id = kOldConnectionIdCount + 1; | 300 for (size_t connection_id = kOldConnectionIdCount + 1; |
| 301 connection_id <= kConnectionIdCount; ++connection_id) { | 301 connection_id <= kConnectionIdCount; ++connection_id) { |
| 302 EXPECT_CALL(visitor_, OnConnectionAddedToTimeWaitList(connection_id)); | 302 EXPECT_CALL(visitor_, OnConnectionAddedToTimeWaitList(connection_id)); |
| 303 AddConnectionId(connection_id); | 303 AddConnectionId(connection_id); |
| 304 } | 304 } |
| 305 EXPECT_EQ(kConnectionIdCount, time_wait_list_manager_.num_connections()); | 305 EXPECT_EQ(kConnectionIdCount, time_wait_list_manager_.num_connections()); |
| 306 | 306 |
| (...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 411 &time_wait_list_manager_, kConnectionId1)); | 411 &time_wait_list_manager_, kConnectionId1)); |
| 412 EXPECT_EQ(QuicVersionMax(), | 412 EXPECT_EQ(QuicVersionMax(), |
| 413 QuicTimeWaitListManagerPeer::GetQuicVersionFromConnectionId( | 413 QuicTimeWaitListManagerPeer::GetQuicVersionFromConnectionId( |
| 414 &time_wait_list_manager_, kConnectionId2)); | 414 &time_wait_list_manager_, kConnectionId2)); |
| 415 EXPECT_EQ(QuicVersionMax(), | 415 EXPECT_EQ(QuicVersionMax(), |
| 416 QuicTimeWaitListManagerPeer::GetQuicVersionFromConnectionId( | 416 QuicTimeWaitListManagerPeer::GetQuicVersionFromConnectionId( |
| 417 &time_wait_list_manager_, kConnectionId3)); | 417 &time_wait_list_manager_, kConnectionId3)); |
| 418 } | 418 } |
| 419 | 419 |
| 420 TEST_F(QuicTimeWaitListManagerTest, AddConnectionIdTwice) { | 420 TEST_F(QuicTimeWaitListManagerTest, AddConnectionIdTwice) { |
| 421 // Add connection_ids such that their expiry time is kTimeWaitPeriod_. | 421 // Add connection_ids such that their expiry time is time_wait_period_. |
| 422 epoll_server_.set_now_in_usec(0); | 422 epoll_server_.set_now_in_usec(0); |
| 423 EXPECT_CALL(visitor_, OnConnectionAddedToTimeWaitList(connection_id_)); | 423 EXPECT_CALL(visitor_, OnConnectionAddedToTimeWaitList(connection_id_)); |
| 424 AddConnectionId(connection_id_); | 424 AddConnectionId(connection_id_); |
| 425 EXPECT_TRUE(IsConnectionIdInTimeWait(connection_id_)); | 425 EXPECT_TRUE(IsConnectionIdInTimeWait(connection_id_)); |
| 426 size_t kConnectionCloseLength = 100; | 426 const size_t kConnectionCloseLength = 100; |
| 427 AddConnectionId( | 427 AddConnectionId( |
| 428 connection_id_, | 428 connection_id_, |
| 429 QuicVersionMax(), | 429 QuicVersionMax(), |
| 430 new QuicEncryptedPacket( | 430 new QuicEncryptedPacket( |
| 431 new char[kConnectionCloseLength], kConnectionCloseLength, true)); | 431 new char[kConnectionCloseLength], kConnectionCloseLength, true)); |
| 432 EXPECT_TRUE(IsConnectionIdInTimeWait(connection_id_)); | 432 EXPECT_TRUE(IsConnectionIdInTimeWait(connection_id_)); |
| 433 EXPECT_EQ(1u, time_wait_list_manager_.num_connections()); | 433 EXPECT_EQ(1u, time_wait_list_manager_.num_connections()); |
| 434 | 434 |
| 435 EXPECT_CALL(writer_, WritePacket(_, | 435 EXPECT_CALL(writer_, WritePacket(_, |
| 436 kConnectionCloseLength, | 436 kConnectionCloseLength, |
| (...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 523 time_wait_list_manager_.num_connections()); | 523 time_wait_list_manager_.num_connections()); |
| 524 EXPECT_FALSE(IsConnectionIdInTimeWait(id_to_evict)); | 524 EXPECT_FALSE(IsConnectionIdInTimeWait(id_to_evict)); |
| 525 EXPECT_TRUE(IsConnectionIdInTimeWait(current_connection_id)); | 525 EXPECT_TRUE(IsConnectionIdInTimeWait(current_connection_id)); |
| 526 } | 526 } |
| 527 } | 527 } |
| 528 | 528 |
| 529 } // namespace | 529 } // namespace |
| 530 } // namespace test | 530 } // namespace test |
| 531 } // namespace tools | 531 } // namespace tools |
| 532 } // namespace net | 532 } // namespace net |
| OLD | NEW |