| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/quic_connection.h" | 5 #include "net/quic/quic_connection.h" |
| 6 | 6 |
| 7 #include <errno.h> | 7 #include <errno.h> |
| 8 #include <memory> | 8 #include <memory> |
| 9 #include <ostream> | 9 #include <ostream> |
| 10 #include <utility> | 10 #include <utility> |
| (...skipping 451 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 462 writer->set_perspective(perspective); | 462 writer->set_perspective(perspective); |
| 463 } | 463 } |
| 464 | 464 |
| 465 void SendAck() { QuicConnectionPeer::SendAck(this); } | 465 void SendAck() { QuicConnectionPeer::SendAck(this); } |
| 466 | 466 |
| 467 void SetSendAlgorithm(SendAlgorithmInterface* send_algorithm) { | 467 void SetSendAlgorithm(SendAlgorithmInterface* send_algorithm) { |
| 468 QuicConnectionPeer::SetSendAlgorithm(this, send_algorithm); | 468 QuicConnectionPeer::SetSendAlgorithm(this, send_algorithm); |
| 469 } | 469 } |
| 470 | 470 |
| 471 void SetLossAlgorithm(LossDetectionInterface* loss_algorithm) { | 471 void SetLossAlgorithm(LossDetectionInterface* loss_algorithm) { |
| 472 // TODO(fayang): connection tests should use MockSentPacketManager. |
| 472 QuicSentPacketManagerPeer::SetLossAlgorithm( | 473 QuicSentPacketManagerPeer::SetLossAlgorithm( |
| 473 QuicConnectionPeer::GetSentPacketManager(this), loss_algorithm); | 474 static_cast<QuicSentPacketManager*>( |
| 475 QuicConnectionPeer::GetSentPacketManager(this)), |
| 476 loss_algorithm); |
| 474 } | 477 } |
| 475 | 478 |
| 476 void SendPacket(EncryptionLevel level, | 479 void SendPacket(EncryptionLevel level, |
| 477 QuicPathId path_id, | 480 QuicPathId path_id, |
| 478 QuicPacketNumber packet_number, | 481 QuicPacketNumber packet_number, |
| 479 QuicPacket* packet, | 482 QuicPacket* packet, |
| 480 QuicPacketEntropyHash entropy_hash, | 483 QuicPacketEntropyHash entropy_hash, |
| 481 HasRetransmittableData retransmittable, | 484 HasRetransmittableData retransmittable, |
| 482 bool has_ack, | 485 bool has_ack, |
| 483 bool has_pending_frames) { | 486 bool has_pending_frames) { |
| (...skipping 871 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1355 lost_packets.insert(i * 2); | 1358 lost_packets.insert(i * 2); |
| 1356 } | 1359 } |
| 1357 } | 1360 } |
| 1358 EXPECT_CALL(*loss_algorithm_, DetectLosses(_, _, _, _, _)); | 1361 EXPECT_CALL(*loss_algorithm_, DetectLosses(_, _, _, _, _)); |
| 1359 EXPECT_CALL(peer_entropy_calculator_, EntropyHash(511)) | 1362 EXPECT_CALL(peer_entropy_calculator_, EntropyHash(511)) |
| 1360 .WillOnce(Return(static_cast<QuicPacketEntropyHash>(0))); | 1363 .WillOnce(Return(static_cast<QuicPacketEntropyHash>(0))); |
| 1361 EXPECT_CALL(*send_algorithm_, OnCongestionEvent(true, _, _, _)); | 1364 EXPECT_CALL(*send_algorithm_, OnCongestionEvent(true, _, _, _)); |
| 1362 ProcessAckPacket(&frame); | 1365 ProcessAckPacket(&frame); |
| 1363 | 1366 |
| 1364 // A truncated ack will not have the true largest observed. | 1367 // A truncated ack will not have the true largest observed. |
| 1365 EXPECT_GT(num_packets, manager_->largest_observed()); | 1368 EXPECT_GT(num_packets, manager_->GetLargestObserved(frame.path_id)); |
| 1366 | 1369 |
| 1367 AckPacket(192, &frame); | 1370 AckPacket(192, &frame); |
| 1368 | 1371 |
| 1369 // Removing one missing packet allows us to ack 192 and one more range, but | 1372 // Removing one missing packet allows us to ack 192 and one more range, but |
| 1370 // 192 has already been declared lost, so it doesn't register as an ack. | 1373 // 192 has already been declared lost, so it doesn't register as an ack. |
| 1371 EXPECT_CALL(*loss_algorithm_, DetectLosses(_, _, _, _, _)); | 1374 EXPECT_CALL(*loss_algorithm_, DetectLosses(_, _, _, _, _)); |
| 1372 EXPECT_CALL(*send_algorithm_, OnCongestionEvent(true, _, _, _)); | 1375 EXPECT_CALL(*send_algorithm_, OnCongestionEvent(true, _, _, _)); |
| 1373 ProcessAckPacket(&frame); | 1376 ProcessAckPacket(&frame); |
| 1374 EXPECT_EQ(num_packets, manager_->largest_observed()); | 1377 EXPECT_EQ(num_packets, manager_->GetLargestObserved(frame.path_id)); |
| 1375 } | 1378 } |
| 1376 | 1379 |
| 1377 TEST_P(QuicConnectionTest, AckReceiptCausesAckSendBadEntropy) { | 1380 TEST_P(QuicConnectionTest, AckReceiptCausesAckSendBadEntropy) { |
| 1378 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); | 1381 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); |
| 1379 | 1382 |
| 1380 ProcessPacket(kDefaultPathId, 1); | 1383 ProcessPacket(kDefaultPathId, 1); |
| 1381 // Delay sending, then queue up an ack. | 1384 // Delay sending, then queue up an ack. |
| 1382 QuicConnectionPeer::SendAck(&connection_); | 1385 QuicConnectionPeer::SendAck(&connection_); |
| 1383 | 1386 |
| 1384 // Process an ack with a least unacked of the received ack. | 1387 // Process an ack with a least unacked of the received ack. |
| (...skipping 959 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2344 // Ack the sent packet before the callback returns, which happens in | 2347 // Ack the sent packet before the callback returns, which happens in |
| 2345 // rare circumstances with write blocked sockets. | 2348 // rare circumstances with write blocked sockets. |
| 2346 QuicAckFrame ack = InitAckFrame(1); | 2349 QuicAckFrame ack = InitAckFrame(1); |
| 2347 EXPECT_CALL(*send_algorithm_, OnCongestionEvent(true, _, _, _)); | 2350 EXPECT_CALL(*send_algorithm_, OnCongestionEvent(true, _, _, _)); |
| 2348 ProcessAckPacket(&ack); | 2351 ProcessAckPacket(&ack); |
| 2349 | 2352 |
| 2350 writer_->SetWritable(); | 2353 writer_->SetWritable(); |
| 2351 connection_.OnCanWrite(); | 2354 connection_.OnCanWrite(); |
| 2352 // There is now a pending packet, but with no retransmittable frames. | 2355 // There is now a pending packet, but with no retransmittable frames. |
| 2353 EXPECT_TRUE(connection_.GetRetransmissionAlarm()->IsSet()); | 2356 EXPECT_TRUE(connection_.GetRetransmissionAlarm()->IsSet()); |
| 2354 EXPECT_FALSE(connection_.sent_packet_manager().HasRetransmittableFrames(2)); | 2357 EXPECT_FALSE(connection_.sent_packet_manager().HasRetransmittableFrames( |
| 2358 ack.path_id, 2)); |
| 2355 } | 2359 } |
| 2356 | 2360 |
| 2357 TEST_P(QuicConnectionTest, AlarmsWhenWriteBlocked) { | 2361 TEST_P(QuicConnectionTest, AlarmsWhenWriteBlocked) { |
| 2358 // Block the connection. | 2362 // Block the connection. |
| 2359 BlockOnNextWrite(); | 2363 BlockOnNextWrite(); |
| 2360 connection_.SendStreamDataWithString(3, "foo", 0, !kFin, nullptr); | 2364 connection_.SendStreamDataWithString(3, "foo", 0, !kFin, nullptr); |
| 2361 EXPECT_EQ(1u, writer_->packets_write_attempts()); | 2365 EXPECT_EQ(1u, writer_->packets_write_attempts()); |
| 2362 EXPECT_TRUE(writer_->IsWriteBlocked()); | 2366 EXPECT_TRUE(writer_->IsWriteBlocked()); |
| 2363 | 2367 |
| 2364 // Set the send and resumption alarms. Fire the alarms and ensure they don't | 2368 // Set the send and resumption alarms. Fire the alarms and ensure they don't |
| (...skipping 1066 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3431 | 3435 |
| 3432 EXPECT_CALL(visitor_, OnPathDegrading()); | 3436 EXPECT_CALL(visitor_, OnPathDegrading()); |
| 3433 // Fire the retransmission alarm 6 times, twice for TLP and 4 times for RTO. | 3437 // Fire the retransmission alarm 6 times, twice for TLP and 4 times for RTO. |
| 3434 for (int i = 0; i < 6; ++i) { | 3438 for (int i = 0; i < 6; ++i) { |
| 3435 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)); | 3439 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)); |
| 3436 connection_.GetRetransmissionAlarm()->Fire(); | 3440 connection_.GetRetransmissionAlarm()->Fire(); |
| 3437 EXPECT_TRUE(connection_.GetTimeoutAlarm()->IsSet()); | 3441 EXPECT_TRUE(connection_.GetTimeoutAlarm()->IsSet()); |
| 3438 EXPECT_TRUE(connection_.connected()); | 3442 EXPECT_TRUE(connection_.connected()); |
| 3439 } | 3443 } |
| 3440 | 3444 |
| 3441 EXPECT_EQ(2u, connection_.sent_packet_manager().consecutive_tlp_count()); | 3445 EXPECT_EQ(2u, connection_.sent_packet_manager().GetConsecutiveTlpCount()); |
| 3442 EXPECT_EQ(4u, connection_.sent_packet_manager().consecutive_rto_count()); | 3446 EXPECT_EQ(4u, connection_.sent_packet_manager().GetConsecutiveRtoCount()); |
| 3443 // This time, we should time out. | 3447 // This time, we should time out. |
| 3444 EXPECT_CALL(visitor_, OnConnectionClosed(QUIC_TOO_MANY_RTOS, _, | 3448 EXPECT_CALL(visitor_, OnConnectionClosed(QUIC_TOO_MANY_RTOS, _, |
| 3445 ConnectionCloseSource::FROM_SELF)); | 3449 ConnectionCloseSource::FROM_SELF)); |
| 3446 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)); | 3450 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)); |
| 3447 connection_.GetRetransmissionAlarm()->Fire(); | 3451 connection_.GetRetransmissionAlarm()->Fire(); |
| 3448 EXPECT_FALSE(connection_.GetTimeoutAlarm()->IsSet()); | 3452 EXPECT_FALSE(connection_.GetTimeoutAlarm()->IsSet()); |
| 3449 EXPECT_FALSE(connection_.connected()); | 3453 EXPECT_FALSE(connection_.connected()); |
| 3450 } | 3454 } |
| 3451 | 3455 |
| 3452 TEST_P(QuicConnectionTest, SendScheduler) { | 3456 TEST_P(QuicConnectionTest, SendScheduler) { |
| (...skipping 1308 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4761 std::unique_ptr<MockQuicConnectionDebugVisitor> debug_visitor( | 4765 std::unique_ptr<MockQuicConnectionDebugVisitor> debug_visitor( |
| 4762 new MockQuicConnectionDebugVisitor()); | 4766 new MockQuicConnectionDebugVisitor()); |
| 4763 connection_.set_debug_visitor(debug_visitor.get()); | 4767 connection_.set_debug_visitor(debug_visitor.get()); |
| 4764 EXPECT_CALL(*debug_visitor, OnPacketHeader(Ref(header))).Times(1); | 4768 EXPECT_CALL(*debug_visitor, OnPacketHeader(Ref(header))).Times(1); |
| 4765 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)).Times(1); | 4769 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)).Times(1); |
| 4766 EXPECT_CALL(*debug_visitor, OnSuccessfulVersionNegotiation(_)).Times(1); | 4770 EXPECT_CALL(*debug_visitor, OnSuccessfulVersionNegotiation(_)).Times(1); |
| 4767 connection_.OnPacketHeader(header); | 4771 connection_.OnPacketHeader(header); |
| 4768 } | 4772 } |
| 4769 | 4773 |
| 4770 TEST_P(QuicConnectionTest, Pacing) { | 4774 TEST_P(QuicConnectionTest, Pacing) { |
| 4775 // static_cast here does not work if using multipath_sent_packet_manager. |
| 4776 FLAGS_quic_enable_multipath = false; |
| 4771 TestConnection server(connection_id_, kSelfAddress, helper_.get(), | 4777 TestConnection server(connection_id_, kSelfAddress, helper_.get(), |
| 4772 alarm_factory_.get(), writer_.get(), | 4778 alarm_factory_.get(), writer_.get(), |
| 4773 Perspective::IS_SERVER, version()); | 4779 Perspective::IS_SERVER, version()); |
| 4774 TestConnection client(connection_id_, kPeerAddress, helper_.get(), | 4780 TestConnection client(connection_id_, kPeerAddress, helper_.get(), |
| 4775 alarm_factory_.get(), writer_.get(), | 4781 alarm_factory_.get(), writer_.get(), |
| 4776 Perspective::IS_CLIENT, version()); | 4782 Perspective::IS_CLIENT, version()); |
| 4777 EXPECT_FALSE(client.sent_packet_manager().using_pacing()); | 4783 EXPECT_FALSE(QuicSentPacketManagerPeer::UsingPacing( |
| 4778 EXPECT_FALSE(server.sent_packet_manager().using_pacing()); | 4784 static_cast<const QuicSentPacketManager*>( |
| 4785 &client.sent_packet_manager()))); |
| 4786 EXPECT_FALSE(QuicSentPacketManagerPeer::UsingPacing( |
| 4787 static_cast<const QuicSentPacketManager*>( |
| 4788 &server.sent_packet_manager()))); |
| 4779 } | 4789 } |
| 4780 | 4790 |
| 4781 TEST_P(QuicConnectionTest, WindowUpdateInstigateAcks) { | 4791 TEST_P(QuicConnectionTest, WindowUpdateInstigateAcks) { |
| 4782 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); | 4792 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); |
| 4783 | 4793 |
| 4784 // Send a WINDOW_UPDATE frame. | 4794 // Send a WINDOW_UPDATE frame. |
| 4785 QuicWindowUpdateFrame window_update; | 4795 QuicWindowUpdateFrame window_update; |
| 4786 window_update.stream_id = 3; | 4796 window_update.stream_id = 3; |
| 4787 window_update.byte_offset = 1234; | 4797 window_update.byte_offset = 1234; |
| 4788 EXPECT_CALL(visitor_, OnWindowUpdateFrame(_)); | 4798 EXPECT_CALL(visitor_, OnWindowUpdateFrame(_)); |
| (...skipping 207 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4996 frame1_.data_length = data->length(); | 5006 frame1_.data_length = data->length(); |
| 4997 | 5007 |
| 4998 EXPECT_CALL(visitor_, OnConnectionClosed(QUIC_MAYBE_CORRUPTED_MEMORY, _, | 5008 EXPECT_CALL(visitor_, OnConnectionClosed(QUIC_MAYBE_CORRUPTED_MEMORY, _, |
| 4999 ConnectionCloseSource::FROM_SELF)); | 5009 ConnectionCloseSource::FROM_SELF)); |
| 5000 ProcessFramePacket(QuicFrame(&frame1_)); | 5010 ProcessFramePacket(QuicFrame(&frame1_)); |
| 5001 } | 5011 } |
| 5002 | 5012 |
| 5003 } // namespace | 5013 } // namespace |
| 5004 } // namespace test | 5014 } // namespace test |
| 5005 } // namespace net | 5015 } // namespace net |
| OLD | NEW |