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 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
109 EXPECT_CALL(writer_, IsWriteBlockedDataBuffered()) | 109 EXPECT_CALL(writer_, IsWriteBlockedDataBuffered()) |
110 .WillRepeatedly(Return(false)); | 110 .WillRepeatedly(Return(false)); |
111 } | 111 } |
112 | 112 |
113 void AddConnectionId(QuicConnectionId connection_id) { | 113 void AddConnectionId(QuicConnectionId connection_id) { |
114 AddConnectionId(connection_id, QuicVersionMax(), | 114 AddConnectionId(connection_id, QuicVersionMax(), |
115 /*connection_rejected_statelessly=*/false, nullptr); | 115 /*connection_rejected_statelessly=*/false, nullptr); |
116 } | 116 } |
117 | 117 |
118 void AddStatelessConnectionId(QuicConnectionId connection_id) { | 118 void AddStatelessConnectionId(QuicConnectionId connection_id) { |
| 119 std::vector<QuicEncryptedPacket*> termination_packets; |
| 120 termination_packets.push_back(new QuicEncryptedPacket(nullptr, 0, false)); |
119 time_wait_list_manager_.AddConnectionIdToTimeWait( | 121 time_wait_list_manager_.AddConnectionIdToTimeWait( |
120 connection_id, QuicVersionMax(), | 122 connection_id, QuicVersionMax(), |
121 /*connection_rejected_statelessly=*/true, nullptr); | 123 /*connection_rejected_statelessly=*/true, &termination_packets); |
122 } | 124 } |
123 | 125 |
124 void AddConnectionId(QuicConnectionId connection_id, | 126 void AddConnectionId(QuicConnectionId connection_id, |
125 QuicVersion version, | 127 QuicVersion version, |
126 bool connection_rejected_statelessly, | 128 bool connection_rejected_statelessly, |
127 QuicEncryptedPacket* packet) { | 129 std::vector<QuicEncryptedPacket*>* packets) { |
128 time_wait_list_manager_.AddConnectionIdToTimeWait( | 130 time_wait_list_manager_.AddConnectionIdToTimeWait( |
129 connection_id, version, connection_rejected_statelessly, packet); | 131 connection_id, version, connection_rejected_statelessly, packets); |
130 } | 132 } |
131 | 133 |
132 bool IsConnectionIdInTimeWait(QuicConnectionId connection_id) { | 134 bool IsConnectionIdInTimeWait(QuicConnectionId connection_id) { |
133 return time_wait_list_manager_.IsConnectionIdInTimeWait(connection_id); | 135 return time_wait_list_manager_.IsConnectionIdInTimeWait(connection_id); |
134 } | 136 } |
135 | 137 |
136 void ProcessPacket(QuicConnectionId connection_id, | 138 void ProcessPacket(QuicConnectionId connection_id, |
137 QuicPacketNumber packet_number) { | 139 QuicPacketNumber packet_number) { |
138 QuicEncryptedPacket packet(nullptr, 0); | 140 QuicEncryptedPacket packet(nullptr, 0); |
139 time_wait_list_manager_.ProcessPacket(server_address_, client_address_, | 141 time_wait_list_manager_.ProcessPacket(server_address_, client_address_, |
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
212 EXPECT_FALSE(IsConnectionIdInTimeWait(connection_id_)); | 214 EXPECT_FALSE(IsConnectionIdInTimeWait(connection_id_)); |
213 EXPECT_CALL(visitor_, OnConnectionAddedToTimeWaitList(connection_id_)); | 215 EXPECT_CALL(visitor_, OnConnectionAddedToTimeWaitList(connection_id_)); |
214 AddStatelessConnectionId(connection_id_); | 216 AddStatelessConnectionId(connection_id_); |
215 EXPECT_EQ(1u, time_wait_list_manager_.num_connections()); | 217 EXPECT_EQ(1u, time_wait_list_manager_.num_connections()); |
216 EXPECT_TRUE(IsConnectionIdInTimeWait(connection_id_)); | 218 EXPECT_TRUE(IsConnectionIdInTimeWait(connection_id_)); |
217 } | 219 } |
218 | 220 |
219 TEST_F(QuicTimeWaitListManagerTest, SendConnectionClose) { | 221 TEST_F(QuicTimeWaitListManagerTest, SendConnectionClose) { |
220 const size_t kConnectionCloseLength = 100; | 222 const size_t kConnectionCloseLength = 100; |
221 EXPECT_CALL(visitor_, OnConnectionAddedToTimeWaitList(connection_id_)); | 223 EXPECT_CALL(visitor_, OnConnectionAddedToTimeWaitList(connection_id_)); |
| 224 std::vector<QuicEncryptedPacket*> termination_packets; |
| 225 termination_packets.push_back( |
| 226 new QuicEncryptedPacket(new char[kConnectionCloseLength], |
| 227 kConnectionCloseLength, true)); |
222 AddConnectionId(connection_id_, QuicVersionMax(), | 228 AddConnectionId(connection_id_, QuicVersionMax(), |
223 /*connection_rejected_statelessly=*/false, | 229 /*connection_rejected_statelessly=*/false, |
224 new QuicEncryptedPacket(new char[kConnectionCloseLength], | 230 &termination_packets); |
225 kConnectionCloseLength, true)); | |
226 const int kRandomSequenceNumber = 1; | 231 const int kRandomSequenceNumber = 1; |
227 EXPECT_CALL(writer_, WritePacket(_, kConnectionCloseLength, | 232 EXPECT_CALL(writer_, WritePacket(_, kConnectionCloseLength, |
228 server_address_.address(), | 233 server_address_.address(), |
229 client_address_)) | 234 client_address_)) |
230 .WillOnce(Return(WriteResult(WRITE_STATUS_OK, 1))); | 235 .WillOnce(Return(WriteResult(WRITE_STATUS_OK, 1))); |
231 | 236 |
232 ProcessPacket(connection_id_, kRandomSequenceNumber); | 237 ProcessPacket(connection_id_, kRandomSequenceNumber); |
233 } | 238 } |
234 | 239 |
| 240 TEST_F(QuicTimeWaitListManagerTest, SendTwoConnectionCloses) { |
| 241 const size_t kConnectionCloseLength = 100; |
| 242 EXPECT_CALL(visitor_, OnConnectionAddedToTimeWaitList(connection_id_)); |
| 243 std::vector<QuicEncryptedPacket*> termination_packets; |
| 244 termination_packets.push_back( |
| 245 new QuicEncryptedPacket(new char[kConnectionCloseLength], |
| 246 kConnectionCloseLength, true)); |
| 247 termination_packets.push_back( |
| 248 new QuicEncryptedPacket(new char[kConnectionCloseLength], |
| 249 kConnectionCloseLength, true)); |
| 250 AddConnectionId(connection_id_, QuicVersionMax(), |
| 251 /*connection_rejected_statelessly=*/false, |
| 252 &termination_packets); |
| 253 const int kRandomSequenceNumber = 1; |
| 254 EXPECT_CALL(writer_, WritePacket(_, kConnectionCloseLength, |
| 255 server_address_.address(), |
| 256 client_address_)).Times(2) |
| 257 .WillRepeatedly(Return(WriteResult(WRITE_STATUS_OK, 1))); |
| 258 |
| 259 ProcessPacket(connection_id_, kRandomSequenceNumber); |
| 260 } |
| 261 |
235 TEST_F(QuicTimeWaitListManagerTest, SendPublicReset) { | 262 TEST_F(QuicTimeWaitListManagerTest, SendPublicReset) { |
236 EXPECT_CALL(visitor_, OnConnectionAddedToTimeWaitList(connection_id_)); | 263 EXPECT_CALL(visitor_, OnConnectionAddedToTimeWaitList(connection_id_)); |
237 AddConnectionId(connection_id_); | 264 AddConnectionId(connection_id_); |
238 const int kRandomSequenceNumber = 1; | 265 const int kRandomSequenceNumber = 1; |
239 EXPECT_CALL(writer_, WritePacket(_, _, | 266 EXPECT_CALL(writer_, WritePacket(_, _, |
240 server_address_.address(), | 267 server_address_.address(), |
241 client_address_)) | 268 client_address_)) |
242 .With(Args<0, 1>(PublicResetPacketEq(connection_id_, | 269 .With(Args<0, 1>(PublicResetPacketEq(connection_id_, |
243 kRandomSequenceNumber))) | 270 kRandomSequenceNumber))) |
244 .WillOnce(Return(WriteResult(WRITE_STATUS_OK, 0))); | 271 .WillOnce(Return(WriteResult(WRITE_STATUS_OK, 0))); |
(...skipping 19 matching lines...) Expand all Loading... |
264 EXPECT_FALSE(QuicTimeWaitListManagerPeer::ShouldSendResponse( | 291 EXPECT_FALSE(QuicTimeWaitListManagerPeer::ShouldSendResponse( |
265 &time_wait_list_manager_, packet_number)); | 292 &time_wait_list_manager_, packet_number)); |
266 } | 293 } |
267 } | 294 } |
268 } | 295 } |
269 | 296 |
270 TEST_F(QuicTimeWaitListManagerTest, NoPublicResetForStatelessConnections) { | 297 TEST_F(QuicTimeWaitListManagerTest, NoPublicResetForStatelessConnections) { |
271 EXPECT_CALL(visitor_, OnConnectionAddedToTimeWaitList(connection_id_)); | 298 EXPECT_CALL(visitor_, OnConnectionAddedToTimeWaitList(connection_id_)); |
272 AddStatelessConnectionId(connection_id_); | 299 AddStatelessConnectionId(connection_id_); |
273 const int kRandomSequenceNumber = 1; | 300 const int kRandomSequenceNumber = 1; |
| 301 |
| 302 EXPECT_CALL(writer_, WritePacket(_, _, |
| 303 server_address_.address(), |
| 304 client_address_)) |
| 305 .WillOnce(Return(WriteResult(WRITE_STATUS_OK, 1))); |
| 306 |
274 ProcessPacket(connection_id_, kRandomSequenceNumber); | 307 ProcessPacket(connection_id_, kRandomSequenceNumber); |
275 } | 308 } |
276 | 309 |
277 TEST_F(QuicTimeWaitListManagerTest, CleanUpOldConnectionIds) { | 310 TEST_F(QuicTimeWaitListManagerTest, CleanUpOldConnectionIds) { |
278 const size_t kConnectionIdCount = 100; | 311 const size_t kConnectionIdCount = 100; |
279 const size_t kOldConnectionIdCount = 31; | 312 const size_t kOldConnectionIdCount = 31; |
280 | 313 |
281 // Add connection_ids such that their expiry time is time_wait_period_. | 314 // Add connection_ids such that their expiry time is time_wait_period_. |
282 epoll_server_.set_now_in_usec(0); | 315 epoll_server_.set_now_in_usec(0); |
283 for (size_t connection_id = 1; connection_id <= kOldConnectionIdCount; | 316 for (size_t connection_id = 1; connection_id <= kOldConnectionIdCount; |
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
405 &time_wait_list_manager_, kConnectionId3)); | 438 &time_wait_list_manager_, kConnectionId3)); |
406 } | 439 } |
407 | 440 |
408 TEST_F(QuicTimeWaitListManagerTest, AddConnectionIdTwice) { | 441 TEST_F(QuicTimeWaitListManagerTest, AddConnectionIdTwice) { |
409 // Add connection_ids such that their expiry time is time_wait_period_. | 442 // Add connection_ids such that their expiry time is time_wait_period_. |
410 epoll_server_.set_now_in_usec(0); | 443 epoll_server_.set_now_in_usec(0); |
411 EXPECT_CALL(visitor_, OnConnectionAddedToTimeWaitList(connection_id_)); | 444 EXPECT_CALL(visitor_, OnConnectionAddedToTimeWaitList(connection_id_)); |
412 AddConnectionId(connection_id_); | 445 AddConnectionId(connection_id_); |
413 EXPECT_TRUE(IsConnectionIdInTimeWait(connection_id_)); | 446 EXPECT_TRUE(IsConnectionIdInTimeWait(connection_id_)); |
414 const size_t kConnectionCloseLength = 100; | 447 const size_t kConnectionCloseLength = 100; |
| 448 std::vector<QuicEncryptedPacket*> termination_packets; |
| 449 termination_packets.push_back( |
| 450 new QuicEncryptedPacket(new char[kConnectionCloseLength], |
| 451 kConnectionCloseLength, true)); |
415 AddConnectionId(connection_id_, QuicVersionMax(), | 452 AddConnectionId(connection_id_, QuicVersionMax(), |
416 /*connection_rejected_statelessly=*/false, | 453 /*connection_rejected_statelessly=*/false, |
417 new QuicEncryptedPacket(new char[kConnectionCloseLength], | 454 &termination_packets); |
418 kConnectionCloseLength, true)); | 455 EXPECT_TRUE(IsConnectionIdInTimeWait(connection_id_)); |
419 EXPECT_TRUE(IsConnectionIdInTimeWait(connection_id_)); | |
420 EXPECT_EQ(1u, time_wait_list_manager_.num_connections()); | 456 EXPECT_EQ(1u, time_wait_list_manager_.num_connections()); |
421 | 457 |
422 EXPECT_CALL(writer_, WritePacket(_, | 458 EXPECT_CALL(writer_, WritePacket(_, |
423 kConnectionCloseLength, | 459 kConnectionCloseLength, |
424 server_address_.address(), | 460 server_address_.address(), |
425 client_address_)) | 461 client_address_)) |
426 .WillOnce(Return(WriteResult(WRITE_STATUS_OK, 1))); | 462 .WillOnce(Return(WriteResult(WRITE_STATUS_OK, 1))); |
427 | 463 |
428 const int kRandomSequenceNumber = 1; | 464 const int kRandomSequenceNumber = 1; |
429 ProcessPacket(connection_id_, kRandomSequenceNumber); | 465 ProcessPacket(connection_id_, kRandomSequenceNumber); |
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
510 time_wait_list_manager_.num_connections()); | 546 time_wait_list_manager_.num_connections()); |
511 EXPECT_FALSE(IsConnectionIdInTimeWait(id_to_evict)); | 547 EXPECT_FALSE(IsConnectionIdInTimeWait(id_to_evict)); |
512 EXPECT_TRUE(IsConnectionIdInTimeWait(current_connection_id)); | 548 EXPECT_TRUE(IsConnectionIdInTimeWait(current_connection_id)); |
513 } | 549 } |
514 } | 550 } |
515 | 551 |
516 } // namespace | 552 } // namespace |
517 } // namespace test | 553 } // namespace test |
518 } // namespace tools | 554 } // namespace tools |
519 } // namespace net | 555 } // namespace net |
OLD | NEW |