| 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 "base/basictypes.h" | 7 #include "base/basictypes.h" |
| 8 #include "base/bind.h" | 8 #include "base/bind.h" |
| 9 #include "base/stl_util.h" | 9 #include "base/stl_util.h" |
| 10 #include "net/base/net_errors.h" | 10 #include "net/base/net_errors.h" |
| 11 #include "net/quic/congestion_control/loss_detection_interface.h" | 11 #include "net/quic/congestion_control/loss_detection_interface.h" |
| 12 #include "net/quic/congestion_control/receive_algorithm_interface.h" | |
| 13 #include "net/quic/congestion_control/send_algorithm_interface.h" | 12 #include "net/quic/congestion_control/send_algorithm_interface.h" |
| 14 #include "net/quic/crypto/null_encrypter.h" | 13 #include "net/quic/crypto/null_encrypter.h" |
| 15 #include "net/quic/crypto/quic_decrypter.h" | 14 #include "net/quic/crypto/quic_decrypter.h" |
| 16 #include "net/quic/crypto/quic_encrypter.h" | 15 #include "net/quic/crypto/quic_encrypter.h" |
| 17 #include "net/quic/quic_ack_notifier.h" | 16 #include "net/quic/quic_ack_notifier.h" |
| 18 #include "net/quic/quic_flags.h" | 17 #include "net/quic/quic_flags.h" |
| 19 #include "net/quic/quic_protocol.h" | 18 #include "net/quic/quic_protocol.h" |
| 20 #include "net/quic/quic_utils.h" | 19 #include "net/quic/quic_utils.h" |
| 21 #include "net/quic/test_tools/mock_clock.h" | 20 #include "net/quic/test_tools/mock_clock.h" |
| 22 #include "net/quic/test_tools/mock_random.h" | 21 #include "net/quic/test_tools/mock_random.h" |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 57 const char data1[] = "foo"; | 56 const char data1[] = "foo"; |
| 58 const char data2[] = "bar"; | 57 const char data2[] = "bar"; |
| 59 | 58 |
| 60 const bool kFin = true; | 59 const bool kFin = true; |
| 61 const bool kEntropyFlag = true; | 60 const bool kEntropyFlag = true; |
| 62 | 61 |
| 63 const QuicPacketEntropyHash kTestEntropyHash = 76; | 62 const QuicPacketEntropyHash kTestEntropyHash = 76; |
| 64 | 63 |
| 65 const int kDefaultRetransmissionTimeMs = 500; | 64 const int kDefaultRetransmissionTimeMs = 500; |
| 66 | 65 |
| 67 class TestReceiveAlgorithm : public ReceiveAlgorithmInterface { | |
| 68 public: | |
| 69 TestReceiveAlgorithm() {} | |
| 70 | |
| 71 MOCK_METHOD3(RecordIncomingPacket, | |
| 72 void(QuicByteCount, QuicPacketSequenceNumber, QuicTime)); | |
| 73 | |
| 74 private: | |
| 75 DISALLOW_COPY_AND_ASSIGN(TestReceiveAlgorithm); | |
| 76 }; | |
| 77 | |
| 78 // TaggingEncrypter appends kTagSize bytes of |tag| to the end of each message. | 66 // TaggingEncrypter appends kTagSize bytes of |tag| to the end of each message. |
| 79 class TaggingEncrypter : public QuicEncrypter { | 67 class TaggingEncrypter : public QuicEncrypter { |
| 80 public: | 68 public: |
| 81 explicit TaggingEncrypter(uint8 tag) | 69 explicit TaggingEncrypter(uint8 tag) |
| 82 : tag_(tag) { | 70 : tag_(tag) { |
| 83 } | 71 } |
| 84 | 72 |
| 85 ~TaggingEncrypter() override {} | 73 ~TaggingEncrypter() override {} |
| 86 | 74 |
| 87 // QuicEncrypter interface. | 75 // QuicEncrypter interface. |
| (...skipping 313 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 401 // Disable tail loss probes for most tests. | 389 // Disable tail loss probes for most tests. |
| 402 QuicSentPacketManagerPeer::SetMaxTailLossProbes( | 390 QuicSentPacketManagerPeer::SetMaxTailLossProbes( |
| 403 QuicConnectionPeer::GetSentPacketManager(this), 0); | 391 QuicConnectionPeer::GetSentPacketManager(this), 0); |
| 404 writer()->set_is_server(is_server); | 392 writer()->set_is_server(is_server); |
| 405 } | 393 } |
| 406 | 394 |
| 407 void SendAck() { | 395 void SendAck() { |
| 408 QuicConnectionPeer::SendAck(this); | 396 QuicConnectionPeer::SendAck(this); |
| 409 } | 397 } |
| 410 | 398 |
| 411 void SetReceiveAlgorithm(TestReceiveAlgorithm* receive_algorithm) { | |
| 412 QuicConnectionPeer::SetReceiveAlgorithm(this, receive_algorithm); | |
| 413 } | |
| 414 | |
| 415 void SetSendAlgorithm(SendAlgorithmInterface* send_algorithm) { | 399 void SetSendAlgorithm(SendAlgorithmInterface* send_algorithm) { |
| 416 QuicConnectionPeer::SetSendAlgorithm(this, send_algorithm); | 400 QuicConnectionPeer::SetSendAlgorithm(this, send_algorithm); |
| 417 } | 401 } |
| 418 | 402 |
| 419 void SetLossAlgorithm(LossDetectionInterface* loss_algorithm) { | 403 void SetLossAlgorithm(LossDetectionInterface* loss_algorithm) { |
| 420 QuicSentPacketManagerPeer::SetLossAlgorithm( | 404 QuicSentPacketManagerPeer::SetLossAlgorithm( |
| 421 QuicConnectionPeer::GetSentPacketManager(this), loss_algorithm); | 405 QuicConnectionPeer::GetSentPacketManager(this), loss_algorithm); |
| 422 } | 406 } |
| 423 | 407 |
| 424 void SendPacket(EncryptionLevel level, | 408 void SendPacket(EncryptionLevel level, |
| (...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 596 }; | 580 }; |
| 597 | 581 |
| 598 class QuicConnectionTest : public ::testing::TestWithParam<QuicVersion> { | 582 class QuicConnectionTest : public ::testing::TestWithParam<QuicVersion> { |
| 599 protected: | 583 protected: |
| 600 QuicConnectionTest() | 584 QuicConnectionTest() |
| 601 : connection_id_(42), | 585 : connection_id_(42), |
| 602 framer_(SupportedVersions(version()), QuicTime::Zero(), false), | 586 framer_(SupportedVersions(version()), QuicTime::Zero(), false), |
| 603 peer_creator_(connection_id_, &framer_, &random_generator_), | 587 peer_creator_(connection_id_, &framer_, &random_generator_), |
| 604 send_algorithm_(new StrictMock<MockSendAlgorithm>), | 588 send_algorithm_(new StrictMock<MockSendAlgorithm>), |
| 605 loss_algorithm_(new MockLossAlgorithm()), | 589 loss_algorithm_(new MockLossAlgorithm()), |
| 606 receive_algorithm_(new TestReceiveAlgorithm), | |
| 607 helper_(new TestConnectionHelper(&clock_, &random_generator_)), | 590 helper_(new TestConnectionHelper(&clock_, &random_generator_)), |
| 608 writer_(new TestPacketWriter(version(), &clock_)), | 591 writer_(new TestPacketWriter(version(), &clock_)), |
| 609 factory_(writer_.get()), | 592 factory_(writer_.get()), |
| 610 connection_(connection_id_, | 593 connection_(connection_id_, |
| 611 IPEndPoint(), | 594 IPEndPoint(), |
| 612 helper_.get(), | 595 helper_.get(), |
| 613 factory_, | 596 factory_, |
| 614 false, | 597 false, |
| 615 version()), | 598 version()), |
| 616 creator_(QuicConnectionPeer::GetPacketCreator(&connection_)), | 599 creator_(QuicConnectionPeer::GetPacketCreator(&connection_)), |
| 617 generator_(QuicConnectionPeer::GetPacketGenerator(&connection_)), | 600 generator_(QuicConnectionPeer::GetPacketGenerator(&connection_)), |
| 618 manager_(QuicConnectionPeer::GetSentPacketManager(&connection_)), | 601 manager_(QuicConnectionPeer::GetSentPacketManager(&connection_)), |
| 619 frame1_(1, false, 0, MakeIOVector(data1)), | 602 frame1_(1, false, 0, MakeIOVector(data1)), |
| 620 frame2_(1, false, 3, MakeIOVector(data2)), | 603 frame2_(1, false, 3, MakeIOVector(data2)), |
| 621 sequence_number_length_(PACKET_6BYTE_SEQUENCE_NUMBER), | 604 sequence_number_length_(PACKET_6BYTE_SEQUENCE_NUMBER), |
| 622 connection_id_length_(PACKET_8BYTE_CONNECTION_ID) { | 605 connection_id_length_(PACKET_8BYTE_CONNECTION_ID) { |
| 623 connection_.set_visitor(&visitor_); | 606 connection_.set_visitor(&visitor_); |
| 624 connection_.SetSendAlgorithm(send_algorithm_); | 607 connection_.SetSendAlgorithm(send_algorithm_); |
| 625 connection_.SetLossAlgorithm(loss_algorithm_); | 608 connection_.SetLossAlgorithm(loss_algorithm_); |
| 626 framer_.set_received_entropy_calculator(&entropy_calculator_); | 609 framer_.set_received_entropy_calculator(&entropy_calculator_); |
| 627 connection_.SetReceiveAlgorithm(receive_algorithm_); | |
| 628 EXPECT_CALL( | 610 EXPECT_CALL( |
| 629 *send_algorithm_, TimeUntilSend(_, _, _)).WillRepeatedly(Return( | 611 *send_algorithm_, TimeUntilSend(_, _, _)).WillRepeatedly(Return( |
| 630 QuicTime::Delta::Zero())); | 612 QuicTime::Delta::Zero())); |
| 631 EXPECT_CALL(*receive_algorithm_, | |
| 632 RecordIncomingPacket(_, _, _)).Times(AnyNumber()); | |
| 633 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)) | 613 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)) |
| 634 .Times(AnyNumber()); | 614 .Times(AnyNumber()); |
| 635 EXPECT_CALL(*send_algorithm_, RetransmissionDelay()).WillRepeatedly( | 615 EXPECT_CALL(*send_algorithm_, RetransmissionDelay()).WillRepeatedly( |
| 636 Return(QuicTime::Delta::Zero())); | 616 Return(QuicTime::Delta::Zero())); |
| 637 EXPECT_CALL(*send_algorithm_, GetCongestionWindow()).WillRepeatedly( | 617 EXPECT_CALL(*send_algorithm_, GetCongestionWindow()).WillRepeatedly( |
| 638 Return(kMaxPacketSize)); | 618 Return(kMaxPacketSize)); |
| 639 ON_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)) | 619 ON_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)) |
| 640 .WillByDefault(Return(true)); | 620 .WillByDefault(Return(true)); |
| 641 EXPECT_CALL(*send_algorithm_, HasReliableBandwidthEstimate()) | 621 EXPECT_CALL(*send_algorithm_, HasReliableBandwidthEstimate()) |
| 642 .Times(AnyNumber()); | 622 .Times(AnyNumber()); |
| (...skipping 12 matching lines...) Expand all Loading... |
| 655 .WillRepeatedly(Return(QuicTime::Zero())); | 635 .WillRepeatedly(Return(QuicTime::Zero())); |
| 656 EXPECT_CALL(*loss_algorithm_, DetectLostPackets(_, _, _, _)) | 636 EXPECT_CALL(*loss_algorithm_, DetectLostPackets(_, _, _, _)) |
| 657 .WillRepeatedly(Return(SequenceNumberSet())); | 637 .WillRepeatedly(Return(SequenceNumberSet())); |
| 658 } | 638 } |
| 659 | 639 |
| 660 QuicVersion version() { | 640 QuicVersion version() { |
| 661 return GetParam(); | 641 return GetParam(); |
| 662 } | 642 } |
| 663 | 643 |
| 664 QuicAckFrame* outgoing_ack() { | 644 QuicAckFrame* outgoing_ack() { |
| 665 outgoing_ack_.reset(QuicConnectionPeer::CreateAckFrame(&connection_)); | 645 QuicConnectionPeer::PopulateAckFrame(&connection_, &ack_); |
| 666 return outgoing_ack_.get(); | 646 return &ack_; |
| 667 } | 647 } |
| 668 | 648 |
| 669 QuicStopWaitingFrame* stop_waiting() { | 649 QuicStopWaitingFrame* stop_waiting() { |
| 670 stop_waiting_.reset( | 650 QuicConnectionPeer::PopulateStopWaitingFrame(&connection_, &stop_waiting_); |
| 671 QuicConnectionPeer::CreateStopWaitingFrame(&connection_)); | 651 return &stop_waiting_; |
| 672 return stop_waiting_.get(); | |
| 673 } | 652 } |
| 674 | 653 |
| 675 QuicPacketSequenceNumber least_unacked() { | 654 QuicPacketSequenceNumber least_unacked() { |
| 676 if (writer_->stop_waiting_frames().empty()) { | 655 if (writer_->stop_waiting_frames().empty()) { |
| 677 return 0; | 656 return 0; |
| 678 } | 657 } |
| 679 return writer_->stop_waiting_frames()[0].least_unacked; | 658 return writer_->stop_waiting_frames()[0].least_unacked; |
| 680 } | 659 } |
| 681 | 660 |
| 682 void use_tagging_decrypter() { | 661 void use_tagging_decrypter() { |
| (...skipping 301 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 984 testing::Return(QuicTime::Delta::Zero())); | 963 testing::Return(QuicTime::Delta::Zero())); |
| 985 } | 964 } |
| 986 | 965 |
| 987 QuicConnectionId connection_id_; | 966 QuicConnectionId connection_id_; |
| 988 QuicFramer framer_; | 967 QuicFramer framer_; |
| 989 QuicPacketCreator peer_creator_; | 968 QuicPacketCreator peer_creator_; |
| 990 MockEntropyCalculator entropy_calculator_; | 969 MockEntropyCalculator entropy_calculator_; |
| 991 | 970 |
| 992 MockSendAlgorithm* send_algorithm_; | 971 MockSendAlgorithm* send_algorithm_; |
| 993 MockLossAlgorithm* loss_algorithm_; | 972 MockLossAlgorithm* loss_algorithm_; |
| 994 TestReceiveAlgorithm* receive_algorithm_; | |
| 995 MockClock clock_; | 973 MockClock clock_; |
| 996 MockRandom random_generator_; | 974 MockRandom random_generator_; |
| 997 scoped_ptr<TestConnectionHelper> helper_; | 975 scoped_ptr<TestConnectionHelper> helper_; |
| 998 scoped_ptr<TestPacketWriter> writer_; | 976 scoped_ptr<TestPacketWriter> writer_; |
| 999 NiceMock<MockPacketWriterFactory> factory_; | 977 NiceMock<MockPacketWriterFactory> factory_; |
| 1000 TestConnection connection_; | 978 TestConnection connection_; |
| 1001 QuicPacketCreator* creator_; | 979 QuicPacketCreator* creator_; |
| 1002 QuicPacketGenerator* generator_; | 980 QuicPacketGenerator* generator_; |
| 1003 QuicSentPacketManager* manager_; | 981 QuicSentPacketManager* manager_; |
| 1004 StrictMock<MockConnectionVisitor> visitor_; | 982 StrictMock<MockConnectionVisitor> visitor_; |
| 1005 | 983 |
| 1006 QuicPacketHeader header_; | 984 QuicPacketHeader header_; |
| 1007 QuicStreamFrame frame1_; | 985 QuicStreamFrame frame1_; |
| 1008 QuicStreamFrame frame2_; | 986 QuicStreamFrame frame2_; |
| 1009 scoped_ptr<QuicAckFrame> outgoing_ack_; | 987 QuicAckFrame ack_; |
| 1010 scoped_ptr<QuicStopWaitingFrame> stop_waiting_; | 988 QuicStopWaitingFrame stop_waiting_; |
| 1011 QuicSequenceNumberLength sequence_number_length_; | 989 QuicSequenceNumberLength sequence_number_length_; |
| 1012 QuicConnectionIdLength connection_id_length_; | 990 QuicConnectionIdLength connection_id_length_; |
| 1013 | 991 |
| 1014 private: | 992 private: |
| 1015 DISALLOW_COPY_AND_ASSIGN(QuicConnectionTest); | 993 DISALLOW_COPY_AND_ASSIGN(QuicConnectionTest); |
| 1016 }; | 994 }; |
| 1017 | 995 |
| 1018 // Run all end to end tests with all supported versions. | 996 // Run all end to end tests with all supported versions. |
| 1019 INSTANTIATE_TEST_CASE_P(SupportedVersion, | 997 INSTANTIATE_TEST_CASE_P(SupportedVersion, |
| 1020 QuicConnectionTest, | 998 QuicConnectionTest, |
| (...skipping 2129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3150 clock_.AdvanceTime(five_ms); | 3128 clock_.AdvanceTime(five_ms); |
| 3151 EXPECT_EQ(default_timeout.Add(five_ms), clock_.ApproximateNow()); | 3129 EXPECT_EQ(default_timeout.Add(five_ms), clock_.ApproximateNow()); |
| 3152 connection_.GetTimeoutAlarm()->Fire(); | 3130 connection_.GetTimeoutAlarm()->Fire(); |
| 3153 EXPECT_FALSE(connection_.GetTimeoutAlarm()->IsSet()); | 3131 EXPECT_FALSE(connection_.GetTimeoutAlarm()->IsSet()); |
| 3154 EXPECT_FALSE(connection_.connected()); | 3132 EXPECT_FALSE(connection_.connected()); |
| 3155 } | 3133 } |
| 3156 | 3134 |
| 3157 TEST_P(QuicConnectionTest, TimeoutAfterSendSilentClose) { | 3135 TEST_P(QuicConnectionTest, TimeoutAfterSendSilentClose) { |
| 3158 // Same test as above, but complete a handshake which enables silent close, | 3136 // Same test as above, but complete a handshake which enables silent close, |
| 3159 // causing no connection close packet to be sent. | 3137 // causing no connection close packet to be sent. |
| 3160 ValueRestore<bool> old_flag(&FLAGS_quic_allow_silent_close, true); | |
| 3161 EXPECT_TRUE(connection_.connected()); | 3138 EXPECT_TRUE(connection_.connected()); |
| 3162 EXPECT_CALL(*send_algorithm_, SetFromConfig(_, _, _)); | 3139 EXPECT_CALL(*send_algorithm_, SetFromConfig(_, _, _)); |
| 3163 QuicConfig config; | 3140 QuicConfig config; |
| 3164 | 3141 |
| 3165 // Create a handshake message that also enables silent close. | 3142 // Create a handshake message that also enables silent close. |
| 3166 CryptoHandshakeMessage msg; | 3143 CryptoHandshakeMessage msg; |
| 3167 string error_details; | 3144 string error_details; |
| 3168 QuicConfig client_config; | 3145 QuicConfig client_config; |
| 3169 client_config.SetInitialStreamFlowControlWindowToSend( | 3146 client_config.SetInitialStreamFlowControlWindowToSend( |
| 3170 kInitialStreamFlowControlWindowForTest); | 3147 kInitialStreamFlowControlWindowForTest); |
| (...skipping 1251 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4422 // Regression test for b/18594622 | 4399 // Regression test for b/18594622 |
| 4423 scoped_refptr<MockAckNotifierDelegate> delegate(new MockAckNotifierDelegate); | 4400 scoped_refptr<MockAckNotifierDelegate> delegate(new MockAckNotifierDelegate); |
| 4424 EXPECT_DFATAL( | 4401 EXPECT_DFATAL( |
| 4425 connection_.SendStreamDataWithString(3, "", 0, !kFin, delegate.get()), | 4402 connection_.SendStreamDataWithString(3, "", 0, !kFin, delegate.get()), |
| 4426 "Attempt to send empty stream frame"); | 4403 "Attempt to send empty stream frame"); |
| 4427 } | 4404 } |
| 4428 | 4405 |
| 4429 } // namespace | 4406 } // namespace |
| 4430 } // namespace test | 4407 } // namespace test |
| 4431 } // namespace net | 4408 } // namespace net |
| OLD | NEW |