| 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/core/quic_connection.h" | 5 #include "net/quic/core/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 644 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 655 return os; | 655 return os; |
| 656 } | 656 } |
| 657 | 657 |
| 658 QuicVersion version; | 658 QuicVersion version; |
| 659 AckResponse ack_response; | 659 AckResponse ack_response; |
| 660 }; | 660 }; |
| 661 | 661 |
| 662 // Constructs various test permutations. | 662 // Constructs various test permutations. |
| 663 vector<TestParams> GetTestParams() { | 663 vector<TestParams> GetTestParams() { |
| 664 vector<TestParams> params; | 664 vector<TestParams> params; |
| 665 QuicVersionVector all_supported_versions = QuicSupportedVersions(); | 665 QuicVersionVector all_supported_versions = AllSupportedVersions(); |
| 666 for (size_t i = 0; i < all_supported_versions.size(); ++i) { | 666 for (size_t i = 0; i < all_supported_versions.size(); ++i) { |
| 667 for (AckResponse ack_response : | 667 for (AckResponse ack_response : |
| 668 {AckResponse::kDefer, AckResponse::kImmediate}) { | 668 {AckResponse::kDefer, AckResponse::kImmediate}) { |
| 669 params.push_back(TestParams(all_supported_versions[i], ack_response)); | 669 params.push_back(TestParams(all_supported_versions[i], ack_response)); |
| 670 } | 670 } |
| 671 } | 671 } |
| 672 return params; | 672 return params; |
| 673 } | 673 } |
| 674 | 674 |
| 675 class QuicConnectionTest : public ::testing::TestWithParam<TestParams> { | 675 class QuicConnectionTest : public ::testing::TestWithParam<TestParams> { |
| (...skipping 3591 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4267 } | 4267 } |
| 4268 ProcessDataPacket(kDefaultPathId, i, entropy_flag); | 4268 ProcessDataPacket(kDefaultPathId, i, entropy_flag); |
| 4269 } | 4269 } |
| 4270 for (int i = 1; i < 50; ++i) { | 4270 for (int i = 1; i < 50; ++i) { |
| 4271 EXPECT_EQ(entropy[i], | 4271 EXPECT_EQ(entropy[i], |
| 4272 QuicConnectionPeer::ReceivedEntropyHash(&connection_, i)); | 4272 QuicConnectionPeer::ReceivedEntropyHash(&connection_, i)); |
| 4273 } | 4273 } |
| 4274 } | 4274 } |
| 4275 | 4275 |
| 4276 TEST_P(QuicConnectionTest, ServerSendsVersionNegotiationPacket) { | 4276 TEST_P(QuicConnectionTest, ServerSendsVersionNegotiationPacket) { |
| 4277 connection_.SetSupportedVersions(QuicSupportedVersions()); | 4277 connection_.SetSupportedVersions(AllSupportedVersions()); |
| 4278 set_perspective(Perspective::IS_SERVER); | 4278 set_perspective(Perspective::IS_SERVER); |
| 4279 peer_framer_.set_version_for_tests(QUIC_VERSION_UNSUPPORTED); | 4279 peer_framer_.set_version_for_tests(QUIC_VERSION_UNSUPPORTED); |
| 4280 | 4280 |
| 4281 QuicPacketHeader header; | 4281 QuicPacketHeader header; |
| 4282 header.public_header.connection_id = connection_id_; | 4282 header.public_header.connection_id = connection_id_; |
| 4283 header.public_header.version_flag = true; | 4283 header.public_header.version_flag = true; |
| 4284 header.path_id = kDefaultPathId; | 4284 header.path_id = kDefaultPathId; |
| 4285 header.packet_number = 12; | 4285 header.packet_number = 12; |
| 4286 | 4286 |
| 4287 QuicFrames frames; | 4287 QuicFrames frames; |
| (...skipping 15 matching lines...) Expand all Loading... |
| 4303 | 4303 |
| 4304 // We expect all versions in kSupportedQuicVersions to be | 4304 // We expect all versions in kSupportedQuicVersions to be |
| 4305 // included in the packet. | 4305 // included in the packet. |
| 4306 for (size_t i = 0; i < num_versions; ++i) { | 4306 for (size_t i = 0; i < num_versions; ++i) { |
| 4307 EXPECT_EQ(kSupportedQuicVersions[i], | 4307 EXPECT_EQ(kSupportedQuicVersions[i], |
| 4308 writer_->version_negotiation_packet()->versions[i]); | 4308 writer_->version_negotiation_packet()->versions[i]); |
| 4309 } | 4309 } |
| 4310 } | 4310 } |
| 4311 | 4311 |
| 4312 TEST_P(QuicConnectionTest, ServerSendsVersionNegotiationPacketSocketBlocked) { | 4312 TEST_P(QuicConnectionTest, ServerSendsVersionNegotiationPacketSocketBlocked) { |
| 4313 connection_.SetSupportedVersions(QuicSupportedVersions()); | 4313 connection_.SetSupportedVersions(AllSupportedVersions()); |
| 4314 set_perspective(Perspective::IS_SERVER); | 4314 set_perspective(Perspective::IS_SERVER); |
| 4315 peer_framer_.set_version_for_tests(QUIC_VERSION_UNSUPPORTED); | 4315 peer_framer_.set_version_for_tests(QUIC_VERSION_UNSUPPORTED); |
| 4316 | 4316 |
| 4317 QuicPacketHeader header; | 4317 QuicPacketHeader header; |
| 4318 header.public_header.connection_id = connection_id_; | 4318 header.public_header.connection_id = connection_id_; |
| 4319 header.public_header.version_flag = true; | 4319 header.public_header.version_flag = true; |
| 4320 header.packet_number = 12; | 4320 header.packet_number = 12; |
| 4321 | 4321 |
| 4322 QuicFrames frames; | 4322 QuicFrames frames; |
| 4323 frames.push_back(QuicFrame(&frame1_)); | 4323 frames.push_back(QuicFrame(&frame1_)); |
| (...skipping 21 matching lines...) Expand all Loading... |
| 4345 // We expect all versions in kSupportedQuicVersions to be | 4345 // We expect all versions in kSupportedQuicVersions to be |
| 4346 // included in the packet. | 4346 // included in the packet. |
| 4347 for (size_t i = 0; i < num_versions; ++i) { | 4347 for (size_t i = 0; i < num_versions; ++i) { |
| 4348 EXPECT_EQ(kSupportedQuicVersions[i], | 4348 EXPECT_EQ(kSupportedQuicVersions[i], |
| 4349 writer_->version_negotiation_packet()->versions[i]); | 4349 writer_->version_negotiation_packet()->versions[i]); |
| 4350 } | 4350 } |
| 4351 } | 4351 } |
| 4352 | 4352 |
| 4353 TEST_P(QuicConnectionTest, | 4353 TEST_P(QuicConnectionTest, |
| 4354 ServerSendsVersionNegotiationPacketSocketBlockedDataBuffered) { | 4354 ServerSendsVersionNegotiationPacketSocketBlockedDataBuffered) { |
| 4355 connection_.SetSupportedVersions(QuicSupportedVersions()); | 4355 connection_.SetSupportedVersions(AllSupportedVersions()); |
| 4356 set_perspective(Perspective::IS_SERVER); | 4356 set_perspective(Perspective::IS_SERVER); |
| 4357 peer_framer_.set_version_for_tests(QUIC_VERSION_UNSUPPORTED); | 4357 peer_framer_.set_version_for_tests(QUIC_VERSION_UNSUPPORTED); |
| 4358 | 4358 |
| 4359 QuicPacketHeader header; | 4359 QuicPacketHeader header; |
| 4360 header.public_header.connection_id = connection_id_; | 4360 header.public_header.connection_id = connection_id_; |
| 4361 header.public_header.version_flag = true; | 4361 header.public_header.version_flag = true; |
| 4362 header.packet_number = 12; | 4362 header.packet_number = 12; |
| 4363 | 4363 |
| 4364 QuicFrames frames; | 4364 QuicFrames frames; |
| 4365 frames.push_back(QuicFrame(&frame1_)); | 4365 frames.push_back(QuicFrame(&frame1_)); |
| (...skipping 14 matching lines...) Expand all Loading... |
| 4380 } | 4380 } |
| 4381 | 4381 |
| 4382 TEST_P(QuicConnectionTest, ClientHandlesVersionNegotiation) { | 4382 TEST_P(QuicConnectionTest, ClientHandlesVersionNegotiation) { |
| 4383 // Start out with some unsupported version. | 4383 // Start out with some unsupported version. |
| 4384 QuicConnectionPeer::GetFramer(&connection_) | 4384 QuicConnectionPeer::GetFramer(&connection_) |
| 4385 ->set_version_for_tests(QUIC_VERSION_UNSUPPORTED); | 4385 ->set_version_for_tests(QUIC_VERSION_UNSUPPORTED); |
| 4386 | 4386 |
| 4387 // Send a version negotiation packet. | 4387 // Send a version negotiation packet. |
| 4388 std::unique_ptr<QuicEncryptedPacket> encrypted( | 4388 std::unique_ptr<QuicEncryptedPacket> encrypted( |
| 4389 framer_.BuildVersionNegotiationPacket(connection_id_, | 4389 framer_.BuildVersionNegotiationPacket(connection_id_, |
| 4390 QuicSupportedVersions())); | 4390 AllSupportedVersions())); |
| 4391 std::unique_ptr<QuicReceivedPacket> received( | 4391 std::unique_ptr<QuicReceivedPacket> received( |
| 4392 ConstructReceivedPacket(*encrypted, QuicTime::Zero())); | 4392 ConstructReceivedPacket(*encrypted, QuicTime::Zero())); |
| 4393 connection_.ProcessUdpPacket(kSelfAddress, kPeerAddress, *received); | 4393 connection_.ProcessUdpPacket(kSelfAddress, kPeerAddress, *received); |
| 4394 | 4394 |
| 4395 // Now force another packet. The connection should transition into | 4395 // Now force another packet. The connection should transition into |
| 4396 // NEGOTIATED_VERSION state and tell the packet creator to StopSendingVersion. | 4396 // NEGOTIATED_VERSION state and tell the packet creator to StopSendingVersion. |
| 4397 QuicPacketHeader header; | 4397 QuicPacketHeader header; |
| 4398 header.public_header.connection_id = connection_id_; | 4398 header.public_header.connection_id = connection_id_; |
| 4399 header.path_id = kDefaultPathId; | 4399 header.path_id = kDefaultPathId; |
| 4400 header.packet_number = 12; | 4400 header.packet_number = 12; |
| (...skipping 15 matching lines...) Expand all Loading... |
| 4416 } | 4416 } |
| 4417 | 4417 |
| 4418 TEST_P(QuicConnectionTest, BadVersionNegotiation) { | 4418 TEST_P(QuicConnectionTest, BadVersionNegotiation) { |
| 4419 // Send a version negotiation packet with the version the client started with. | 4419 // Send a version negotiation packet with the version the client started with. |
| 4420 // It should be rejected. | 4420 // It should be rejected. |
| 4421 EXPECT_CALL(visitor_, | 4421 EXPECT_CALL(visitor_, |
| 4422 OnConnectionClosed(QUIC_INVALID_VERSION_NEGOTIATION_PACKET, _, | 4422 OnConnectionClosed(QUIC_INVALID_VERSION_NEGOTIATION_PACKET, _, |
| 4423 ConnectionCloseSource::FROM_SELF)); | 4423 ConnectionCloseSource::FROM_SELF)); |
| 4424 std::unique_ptr<QuicEncryptedPacket> encrypted( | 4424 std::unique_ptr<QuicEncryptedPacket> encrypted( |
| 4425 framer_.BuildVersionNegotiationPacket(connection_id_, | 4425 framer_.BuildVersionNegotiationPacket(connection_id_, |
| 4426 QuicSupportedVersions())); | 4426 AllSupportedVersions())); |
| 4427 std::unique_ptr<QuicReceivedPacket> received( | 4427 std::unique_ptr<QuicReceivedPacket> received( |
| 4428 ConstructReceivedPacket(*encrypted, QuicTime::Zero())); | 4428 ConstructReceivedPacket(*encrypted, QuicTime::Zero())); |
| 4429 connection_.ProcessUdpPacket(kSelfAddress, kPeerAddress, *received); | 4429 connection_.ProcessUdpPacket(kSelfAddress, kPeerAddress, *received); |
| 4430 } | 4430 } |
| 4431 | 4431 |
| 4432 TEST_P(QuicConnectionTest, CheckSendStats) { | 4432 TEST_P(QuicConnectionTest, CheckSendStats) { |
| 4433 connection_.SetMaxTailLossProbes(kDefaultPathId, 0); | 4433 connection_.SetMaxTailLossProbes(kDefaultPathId, 0); |
| 4434 | 4434 |
| 4435 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)); | 4435 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)); |
| 4436 connection_.SendStreamDataWithString(3, "first", 0, !kFin, nullptr); | 4436 connection_.SendStreamDataWithString(3, "first", 0, !kFin, nullptr); |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4499 ConnectionCloseSource::FROM_PEER)); | 4499 ConnectionCloseSource::FROM_PEER)); |
| 4500 EXPECT_CALL(visitor_, OnStreamFrame(_)).Times(1); | 4500 EXPECT_CALL(visitor_, OnStreamFrame(_)).Times(1); |
| 4501 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); | 4501 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); |
| 4502 | 4502 |
| 4503 connection_.ProcessUdpPacket( | 4503 connection_.ProcessUdpPacket( |
| 4504 kSelfAddress, kPeerAddress, | 4504 kSelfAddress, kPeerAddress, |
| 4505 QuicReceivedPacket(buffer, encrypted_length, QuicTime::Zero(), false)); | 4505 QuicReceivedPacket(buffer, encrypted_length, QuicTime::Zero(), false)); |
| 4506 } | 4506 } |
| 4507 | 4507 |
| 4508 TEST_P(QuicConnectionTest, SelectMutualVersion) { | 4508 TEST_P(QuicConnectionTest, SelectMutualVersion) { |
| 4509 connection_.SetSupportedVersions(QuicSupportedVersions()); | 4509 connection_.SetSupportedVersions(AllSupportedVersions()); |
| 4510 // Set the connection to speak the lowest quic version. | 4510 // Set the connection to speak the lowest quic version. |
| 4511 connection_.set_version(QuicVersionMin()); | 4511 connection_.set_version(QuicVersionMin()); |
| 4512 EXPECT_EQ(QuicVersionMin(), connection_.version()); | 4512 EXPECT_EQ(QuicVersionMin(), connection_.version()); |
| 4513 | 4513 |
| 4514 // Pass in available versions which includes a higher mutually supported | 4514 // Pass in available versions which includes a higher mutually supported |
| 4515 // version. The higher mutually supported version should be selected. | 4515 // version. The higher mutually supported version should be selected. |
| 4516 QuicVersionVector supported_versions; | 4516 QuicVersionVector supported_versions; |
| 4517 for (size_t i = 0; i < arraysize(kSupportedQuicVersions); ++i) { | 4517 for (size_t i = 0; i < arraysize(kSupportedQuicVersions); ++i) { |
| 4518 supported_versions.push_back(kSupportedQuicVersions[i]); | 4518 supported_versions.push_back(kSupportedQuicVersions[i]); |
| 4519 } | 4519 } |
| (...skipping 514 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5034 EXPECT_CALL(*send_algorithm_, OnApplicationLimited(_)).Times(0); | 5034 EXPECT_CALL(*send_algorithm_, OnApplicationLimited(_)).Times(0); |
| 5035 EXPECT_CALL(visitor_, WillingAndAbleToWrite()).WillRepeatedly(Return(true)); | 5035 EXPECT_CALL(visitor_, WillingAndAbleToWrite()).WillRepeatedly(Return(true)); |
| 5036 BlockOnNextWrite(); | 5036 BlockOnNextWrite(); |
| 5037 | 5037 |
| 5038 connection_.SendStreamData3(); | 5038 connection_.SendStreamData3(); |
| 5039 } | 5039 } |
| 5040 | 5040 |
| 5041 } // namespace | 5041 } // namespace |
| 5042 } // namespace test | 5042 } // namespace test |
| 5043 } // namespace net | 5043 } // namespace net |
| OLD | NEW |