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 164 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
175 Perspective::IS_CLIENT); | 175 Perspective::IS_CLIENT); |
176 framer.set_visitor(&visitor); | 176 framer.set_visitor(&visitor); |
177 QuicEncryptedPacket encrypted(std::tr1::get<0>(packet_buffer), | 177 QuicEncryptedPacket encrypted(std::tr1::get<0>(packet_buffer), |
178 std::tr1::get<1>(packet_buffer)); | 178 std::tr1::get<1>(packet_buffer)); |
179 framer.ProcessPacket(encrypted); | 179 framer.ProcessPacket(encrypted); |
180 QuicPublicResetPacket packet = visitor.public_reset_packet(); | 180 QuicPublicResetPacket packet = visitor.public_reset_packet(); |
181 return connection_id_ == packet.public_header.connection_id && | 181 return connection_id_ == packet.public_header.connection_id && |
182 packet.public_header.reset_flag && | 182 packet.public_header.reset_flag && |
183 !packet.public_header.version_flag && | 183 !packet.public_header.version_flag && |
184 packet_number_ == packet.rejected_packet_number && | 184 packet_number_ == packet.rejected_packet_number && |
185 net::test::TestPeerIPAddress() == packet.client_address.address() && | 185 net::test::TestPeerIPAddress() == |
| 186 packet.client_address.address().bytes() && |
186 kTestPort == packet.client_address.port(); | 187 kTestPort == packet.client_address.port(); |
187 } | 188 } |
188 | 189 |
189 void DescribeTo(::std::ostream* os) const override {} | 190 void DescribeTo(::std::ostream* os) const override {} |
190 | 191 |
191 void DescribeNegationTo(::std::ostream* os) const override {} | 192 void DescribeNegationTo(::std::ostream* os) const override {} |
192 | 193 |
193 private: | 194 private: |
194 QuicConnectionId connection_id_; | 195 QuicConnectionId connection_id_; |
195 QuicPacketNumber packet_number_; | 196 QuicPacketNumber packet_number_; |
(...skipping 25 matching lines...) Expand all Loading... |
221 TEST_F(QuicTimeWaitListManagerTest, SendConnectionClose) { | 222 TEST_F(QuicTimeWaitListManagerTest, SendConnectionClose) { |
222 const size_t kConnectionCloseLength = 100; | 223 const size_t kConnectionCloseLength = 100; |
223 EXPECT_CALL(visitor_, OnConnectionAddedToTimeWaitList(connection_id_)); | 224 EXPECT_CALL(visitor_, OnConnectionAddedToTimeWaitList(connection_id_)); |
224 std::vector<QuicEncryptedPacket*> termination_packets; | 225 std::vector<QuicEncryptedPacket*> termination_packets; |
225 termination_packets.push_back(new QuicEncryptedPacket( | 226 termination_packets.push_back(new QuicEncryptedPacket( |
226 new char[kConnectionCloseLength], kConnectionCloseLength, true)); | 227 new char[kConnectionCloseLength], kConnectionCloseLength, true)); |
227 AddConnectionId(connection_id_, QuicVersionMax(), | 228 AddConnectionId(connection_id_, QuicVersionMax(), |
228 /*connection_rejected_statelessly=*/false, | 229 /*connection_rejected_statelessly=*/false, |
229 &termination_packets); | 230 &termination_packets); |
230 const int kRandomSequenceNumber = 1; | 231 const int kRandomSequenceNumber = 1; |
231 EXPECT_CALL(writer_, WritePacket(_, kConnectionCloseLength, | 232 EXPECT_CALL(writer_, |
232 server_address_.address(), client_address_)) | 233 WritePacket(_, kConnectionCloseLength, |
| 234 server_address_.address().bytes(), client_address_)) |
233 .WillOnce(Return(WriteResult(WRITE_STATUS_OK, 1))); | 235 .WillOnce(Return(WriteResult(WRITE_STATUS_OK, 1))); |
234 | 236 |
235 ProcessPacket(connection_id_, kRandomSequenceNumber); | 237 ProcessPacket(connection_id_, kRandomSequenceNumber); |
236 } | 238 } |
237 | 239 |
238 TEST_F(QuicTimeWaitListManagerTest, SendTwoConnectionCloses) { | 240 TEST_F(QuicTimeWaitListManagerTest, SendTwoConnectionCloses) { |
239 const size_t kConnectionCloseLength = 100; | 241 const size_t kConnectionCloseLength = 100; |
240 EXPECT_CALL(visitor_, OnConnectionAddedToTimeWaitList(connection_id_)); | 242 EXPECT_CALL(visitor_, OnConnectionAddedToTimeWaitList(connection_id_)); |
241 std::vector<QuicEncryptedPacket*> termination_packets; | 243 std::vector<QuicEncryptedPacket*> termination_packets; |
242 termination_packets.push_back(new QuicEncryptedPacket( | 244 termination_packets.push_back(new QuicEncryptedPacket( |
243 new char[kConnectionCloseLength], kConnectionCloseLength, true)); | 245 new char[kConnectionCloseLength], kConnectionCloseLength, true)); |
244 termination_packets.push_back(new QuicEncryptedPacket( | 246 termination_packets.push_back(new QuicEncryptedPacket( |
245 new char[kConnectionCloseLength], kConnectionCloseLength, true)); | 247 new char[kConnectionCloseLength], kConnectionCloseLength, true)); |
246 AddConnectionId(connection_id_, QuicVersionMax(), | 248 AddConnectionId(connection_id_, QuicVersionMax(), |
247 /*connection_rejected_statelessly=*/false, | 249 /*connection_rejected_statelessly=*/false, |
248 &termination_packets); | 250 &termination_packets); |
249 const int kRandomSequenceNumber = 1; | 251 const int kRandomSequenceNumber = 1; |
250 EXPECT_CALL(writer_, WritePacket(_, kConnectionCloseLength, | 252 EXPECT_CALL(writer_, |
251 server_address_.address(), client_address_)) | 253 WritePacket(_, kConnectionCloseLength, |
| 254 server_address_.address().bytes(), client_address_)) |
252 .Times(2) | 255 .Times(2) |
253 .WillRepeatedly(Return(WriteResult(WRITE_STATUS_OK, 1))); | 256 .WillRepeatedly(Return(WriteResult(WRITE_STATUS_OK, 1))); |
254 | 257 |
255 ProcessPacket(connection_id_, kRandomSequenceNumber); | 258 ProcessPacket(connection_id_, kRandomSequenceNumber); |
256 } | 259 } |
257 | 260 |
258 TEST_F(QuicTimeWaitListManagerTest, SendPublicReset) { | 261 TEST_F(QuicTimeWaitListManagerTest, SendPublicReset) { |
259 EXPECT_CALL(visitor_, OnConnectionAddedToTimeWaitList(connection_id_)); | 262 EXPECT_CALL(visitor_, OnConnectionAddedToTimeWaitList(connection_id_)); |
260 AddConnectionId(connection_id_); | 263 AddConnectionId(connection_id_); |
261 const int kRandomSequenceNumber = 1; | 264 const int kRandomSequenceNumber = 1; |
262 EXPECT_CALL(writer_, | 265 EXPECT_CALL(writer_, WritePacket(_, _, server_address_.address().bytes(), |
263 WritePacket(_, _, server_address_.address(), client_address_)) | 266 client_address_)) |
264 .With(Args<0, 1>( | 267 .With(Args<0, 1>( |
265 PublicResetPacketEq(connection_id_, kRandomSequenceNumber))) | 268 PublicResetPacketEq(connection_id_, kRandomSequenceNumber))) |
266 .WillOnce(Return(WriteResult(WRITE_STATUS_OK, 0))); | 269 .WillOnce(Return(WriteResult(WRITE_STATUS_OK, 0))); |
267 | 270 |
268 ProcessPacket(connection_id_, kRandomSequenceNumber); | 271 ProcessPacket(connection_id_, kRandomSequenceNumber); |
269 } | 272 } |
270 | 273 |
271 TEST_F(QuicTimeWaitListManagerTest, SendPublicResetWithExponentialBackOff) { | 274 TEST_F(QuicTimeWaitListManagerTest, SendPublicResetWithExponentialBackOff) { |
272 EXPECT_CALL(visitor_, OnConnectionAddedToTimeWaitList(connection_id_)); | 275 EXPECT_CALL(visitor_, OnConnectionAddedToTimeWaitList(connection_id_)); |
273 AddConnectionId(connection_id_); | 276 AddConnectionId(connection_id_); |
(...skipping 13 matching lines...) Expand all Loading... |
287 &time_wait_list_manager_, packet_number)); | 290 &time_wait_list_manager_, packet_number)); |
288 } | 291 } |
289 } | 292 } |
290 } | 293 } |
291 | 294 |
292 TEST_F(QuicTimeWaitListManagerTest, NoPublicResetForStatelessConnections) { | 295 TEST_F(QuicTimeWaitListManagerTest, NoPublicResetForStatelessConnections) { |
293 EXPECT_CALL(visitor_, OnConnectionAddedToTimeWaitList(connection_id_)); | 296 EXPECT_CALL(visitor_, OnConnectionAddedToTimeWaitList(connection_id_)); |
294 AddStatelessConnectionId(connection_id_); | 297 AddStatelessConnectionId(connection_id_); |
295 const int kRandomSequenceNumber = 1; | 298 const int kRandomSequenceNumber = 1; |
296 | 299 |
297 EXPECT_CALL(writer_, | 300 EXPECT_CALL(writer_, WritePacket(_, _, server_address_.address().bytes(), |
298 WritePacket(_, _, server_address_.address(), client_address_)) | 301 client_address_)) |
299 .WillOnce(Return(WriteResult(WRITE_STATUS_OK, 1))); | 302 .WillOnce(Return(WriteResult(WRITE_STATUS_OK, 1))); |
300 | 303 |
301 ProcessPacket(connection_id_, kRandomSequenceNumber); | 304 ProcessPacket(connection_id_, kRandomSequenceNumber); |
302 } | 305 } |
303 | 306 |
304 TEST_F(QuicTimeWaitListManagerTest, CleanUpOldConnectionIds) { | 307 TEST_F(QuicTimeWaitListManagerTest, CleanUpOldConnectionIds) { |
305 const size_t kConnectionIdCount = 100; | 308 const size_t kConnectionIdCount = 100; |
306 const size_t kOldConnectionIdCount = 31; | 309 const size_t kOldConnectionIdCount = 31; |
307 | 310 |
308 // 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 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
354 } | 357 } |
355 | 358 |
356 TEST_F(QuicTimeWaitListManagerTest, SendQueuedPackets) { | 359 TEST_F(QuicTimeWaitListManagerTest, SendQueuedPackets) { |
357 QuicConnectionId connection_id = 1; | 360 QuicConnectionId connection_id = 1; |
358 EXPECT_CALL(visitor_, OnConnectionAddedToTimeWaitList(connection_id)); | 361 EXPECT_CALL(visitor_, OnConnectionAddedToTimeWaitList(connection_id)); |
359 AddConnectionId(connection_id); | 362 AddConnectionId(connection_id); |
360 QuicPacketNumber packet_number = 234; | 363 QuicPacketNumber packet_number = 234; |
361 scoped_ptr<QuicEncryptedPacket> packet( | 364 scoped_ptr<QuicEncryptedPacket> packet( |
362 ConstructEncryptedPacket(connection_id, packet_number)); | 365 ConstructEncryptedPacket(connection_id, packet_number)); |
363 // Let first write through. | 366 // Let first write through. |
364 EXPECT_CALL(writer_, | 367 EXPECT_CALL(writer_, WritePacket(_, _, server_address_.address().bytes(), |
365 WritePacket(_, _, server_address_.address(), client_address_)) | 368 client_address_)) |
366 .With(Args<0, 1>(PublicResetPacketEq(connection_id, packet_number))) | 369 .With(Args<0, 1>(PublicResetPacketEq(connection_id, packet_number))) |
367 .WillOnce(Return(WriteResult(WRITE_STATUS_OK, packet->length()))); | 370 .WillOnce(Return(WriteResult(WRITE_STATUS_OK, packet->length()))); |
368 ProcessPacket(connection_id, packet_number); | 371 ProcessPacket(connection_id, packet_number); |
369 | 372 |
370 // write block for the next packet. | 373 // write block for the next packet. |
371 EXPECT_CALL(writer_, | 374 EXPECT_CALL(writer_, WritePacket(_, _, server_address_.address().bytes(), |
372 WritePacket(_, _, server_address_.address(), client_address_)) | 375 client_address_)) |
373 .With(Args<0, 1>(PublicResetPacketEq(connection_id, packet_number))) | 376 .With(Args<0, 1>(PublicResetPacketEq(connection_id, packet_number))) |
374 .WillOnce(DoAll(Assign(&writer_is_blocked_, true), | 377 .WillOnce(DoAll(Assign(&writer_is_blocked_, true), |
375 Return(WriteResult(WRITE_STATUS_BLOCKED, EAGAIN)))); | 378 Return(WriteResult(WRITE_STATUS_BLOCKED, EAGAIN)))); |
376 EXPECT_CALL(visitor_, OnWriteBlocked(&time_wait_list_manager_)); | 379 EXPECT_CALL(visitor_, OnWriteBlocked(&time_wait_list_manager_)); |
377 ProcessPacket(connection_id, packet_number); | 380 ProcessPacket(connection_id, packet_number); |
378 // 3rd packet. No public reset should be sent; | 381 // 3rd packet. No public reset should be sent; |
379 ProcessPacket(connection_id, packet_number); | 382 ProcessPacket(connection_id, packet_number); |
380 | 383 |
381 // 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 |
382 // should be queued. | 385 // should be queued. |
383 QuicConnectionId other_connection_id = 2; | 386 QuicConnectionId other_connection_id = 2; |
384 EXPECT_CALL(visitor_, OnConnectionAddedToTimeWaitList(other_connection_id)); | 387 EXPECT_CALL(visitor_, OnConnectionAddedToTimeWaitList(other_connection_id)); |
385 AddConnectionId(other_connection_id); | 388 AddConnectionId(other_connection_id); |
386 QuicPacketNumber other_packet_number = 23423; | 389 QuicPacketNumber other_packet_number = 23423; |
387 scoped_ptr<QuicEncryptedPacket> other_packet( | 390 scoped_ptr<QuicEncryptedPacket> other_packet( |
388 ConstructEncryptedPacket(other_connection_id, other_packet_number)); | 391 ConstructEncryptedPacket(other_connection_id, other_packet_number)); |
389 EXPECT_CALL(writer_, WritePacket(_, _, _, _)).Times(0); | 392 EXPECT_CALL(writer_, WritePacket(_, _, _, _)).Times(0); |
390 EXPECT_CALL(visitor_, OnWriteBlocked(&time_wait_list_manager_)); | 393 EXPECT_CALL(visitor_, OnWriteBlocked(&time_wait_list_manager_)); |
391 ProcessPacket(other_connection_id, other_packet_number); | 394 ProcessPacket(other_connection_id, other_packet_number); |
392 EXPECT_EQ(2u, time_wait_list_manager_.num_connections()); | 395 EXPECT_EQ(2u, time_wait_list_manager_.num_connections()); |
393 | 396 |
394 // 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. |
395 writer_is_blocked_ = false; | 398 writer_is_blocked_ = false; |
396 EXPECT_CALL(writer_, | 399 EXPECT_CALL(writer_, WritePacket(_, _, server_address_.address().bytes(), |
397 WritePacket(_, _, server_address_.address(), client_address_)) | 400 client_address_)) |
398 .With(Args<0, 1>(PublicResetPacketEq(connection_id, packet_number))) | 401 .With(Args<0, 1>(PublicResetPacketEq(connection_id, packet_number))) |
399 .WillOnce(Return(WriteResult(WRITE_STATUS_OK, packet->length()))); | 402 .WillOnce(Return(WriteResult(WRITE_STATUS_OK, packet->length()))); |
400 EXPECT_CALL(writer_, | 403 EXPECT_CALL(writer_, WritePacket(_, _, server_address_.address().bytes(), |
401 WritePacket(_, _, server_address_.address(), client_address_)) | 404 client_address_)) |
402 .With(Args<0, 1>( | 405 .With(Args<0, 1>( |
403 PublicResetPacketEq(other_connection_id, other_packet_number))) | 406 PublicResetPacketEq(other_connection_id, other_packet_number))) |
404 .WillOnce(Return(WriteResult(WRITE_STATUS_OK, other_packet->length()))); | 407 .WillOnce(Return(WriteResult(WRITE_STATUS_OK, other_packet->length()))); |
405 time_wait_list_manager_.OnCanWrite(); | 408 time_wait_list_manager_.OnCanWrite(); |
406 } | 409 } |
407 | 410 |
408 TEST_F(QuicTimeWaitListManagerTest, GetQuicVersionFromMap) { | 411 TEST_F(QuicTimeWaitListManagerTest, GetQuicVersionFromMap) { |
409 const int kConnectionId1 = 123; | 412 const int kConnectionId1 = 123; |
410 const int kConnectionId2 = 456; | 413 const int kConnectionId2 = 456; |
411 const int kConnectionId3 = 789; | 414 const int kConnectionId3 = 789; |
(...skipping 28 matching lines...) Expand all Loading... |
440 const size_t kConnectionCloseLength = 100; | 443 const size_t kConnectionCloseLength = 100; |
441 std::vector<QuicEncryptedPacket*> termination_packets; | 444 std::vector<QuicEncryptedPacket*> termination_packets; |
442 termination_packets.push_back(new QuicEncryptedPacket( | 445 termination_packets.push_back(new QuicEncryptedPacket( |
443 new char[kConnectionCloseLength], kConnectionCloseLength, true)); | 446 new char[kConnectionCloseLength], kConnectionCloseLength, true)); |
444 AddConnectionId(connection_id_, QuicVersionMax(), | 447 AddConnectionId(connection_id_, QuicVersionMax(), |
445 /*connection_rejected_statelessly=*/false, | 448 /*connection_rejected_statelessly=*/false, |
446 &termination_packets); | 449 &termination_packets); |
447 EXPECT_TRUE(IsConnectionIdInTimeWait(connection_id_)); | 450 EXPECT_TRUE(IsConnectionIdInTimeWait(connection_id_)); |
448 EXPECT_EQ(1u, time_wait_list_manager_.num_connections()); | 451 EXPECT_EQ(1u, time_wait_list_manager_.num_connections()); |
449 | 452 |
450 EXPECT_CALL(writer_, WritePacket(_, kConnectionCloseLength, | 453 EXPECT_CALL(writer_, |
451 server_address_.address(), client_address_)) | 454 WritePacket(_, kConnectionCloseLength, |
| 455 server_address_.address().bytes(), client_address_)) |
452 .WillOnce(Return(WriteResult(WRITE_STATUS_OK, 1))); | 456 .WillOnce(Return(WriteResult(WRITE_STATUS_OK, 1))); |
453 | 457 |
454 const int kRandomSequenceNumber = 1; | 458 const int kRandomSequenceNumber = 1; |
455 ProcessPacket(connection_id_, kRandomSequenceNumber); | 459 ProcessPacket(connection_id_, kRandomSequenceNumber); |
456 | 460 |
457 const QuicTime::Delta time_wait_period = | 461 const QuicTime::Delta time_wait_period = |
458 QuicTimeWaitListManagerPeer::time_wait_period(&time_wait_list_manager_); | 462 QuicTimeWaitListManagerPeer::time_wait_period(&time_wait_list_manager_); |
459 | 463 |
460 QuicTime::Delta offset = QuicTime::Delta::FromMicroseconds(39); | 464 QuicTime::Delta offset = QuicTime::Delta::FromMicroseconds(39); |
461 // Now set the current time as time_wait_period + offset usecs. | 465 // Now set the current time as time_wait_period + offset usecs. |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
536 time_wait_list_manager_.num_connections()); | 540 time_wait_list_manager_.num_connections()); |
537 EXPECT_FALSE(IsConnectionIdInTimeWait(id_to_evict)); | 541 EXPECT_FALSE(IsConnectionIdInTimeWait(id_to_evict)); |
538 EXPECT_TRUE(IsConnectionIdInTimeWait(current_connection_id)); | 542 EXPECT_TRUE(IsConnectionIdInTimeWait(current_connection_id)); |
539 } | 543 } |
540 } | 544 } |
541 | 545 |
542 } // namespace | 546 } // namespace |
543 } // namespace test | 547 } // namespace test |
544 } // namespace tools | 548 } // namespace tools |
545 } // namespace net | 549 } // namespace net |
OLD | NEW |