| 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/memory/scoped_ptr.h" |
| 9 #include "base/stl_util.h" | 10 #include "base/stl_util.h" |
| 10 #include "net/base/net_errors.h" | 11 #include "net/base/net_errors.h" |
| 11 #include "net/quic/congestion_control/loss_detection_interface.h" | 12 #include "net/quic/congestion_control/loss_detection_interface.h" |
| 12 #include "net/quic/congestion_control/send_algorithm_interface.h" | 13 #include "net/quic/congestion_control/send_algorithm_interface.h" |
| 13 #include "net/quic/crypto/null_encrypter.h" | 14 #include "net/quic/crypto/null_encrypter.h" |
| 14 #include "net/quic/crypto/quic_decrypter.h" | 15 #include "net/quic/crypto/quic_decrypter.h" |
| 15 #include "net/quic/crypto/quic_encrypter.h" | 16 #include "net/quic/crypto/quic_encrypter.h" |
| 16 #include "net/quic/quic_ack_notifier.h" | 17 #include "net/quic/quic_ack_notifier.h" |
| 17 #include "net/quic/quic_flags.h" | 18 #include "net/quic/quic_flags.h" |
| 18 #include "net/quic/quic_protocol.h" | 19 #include "net/quic/quic_protocol.h" |
| (...skipping 2504 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2523 // Don't send missing packet 1. | 2524 // Don't send missing packet 1. |
| 2524 ProcessFecPacket(2, 1, true, !kEntropyFlag, nullptr); | 2525 ProcessFecPacket(2, 1, true, !kEntropyFlag, nullptr); |
| 2525 // Entropy flag should be false, so entropy should be 0. | 2526 // Entropy flag should be false, so entropy should be 0. |
| 2526 EXPECT_EQ(0u, QuicConnectionPeer::ReceivedEntropyHash(&connection_, 2)); | 2527 EXPECT_EQ(0u, QuicConnectionPeer::ReceivedEntropyHash(&connection_, 2)); |
| 2527 } | 2528 } |
| 2528 | 2529 |
| 2529 TEST_P(QuicConnectionTest, ReviveMissingPacketWithVaryingSeqNumLengths) { | 2530 TEST_P(QuicConnectionTest, ReviveMissingPacketWithVaryingSeqNumLengths) { |
| 2530 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); | 2531 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); |
| 2531 | 2532 |
| 2532 // Set up a debug visitor to the connection. | 2533 // Set up a debug visitor to the connection. |
| 2533 FecQuicConnectionDebugVisitor* fec_visitor = | 2534 scoped_ptr<FecQuicConnectionDebugVisitor> fec_visitor( |
| 2534 new FecQuicConnectionDebugVisitor(); | 2535 new FecQuicConnectionDebugVisitor()); |
| 2535 connection_.set_debug_visitor(fec_visitor); | 2536 connection_.set_debug_visitor(fec_visitor.get()); |
| 2536 | 2537 |
| 2537 QuicPacketSequenceNumber fec_packet = 0; | 2538 QuicPacketSequenceNumber fec_packet = 0; |
| 2538 QuicSequenceNumberLength lengths[] = {PACKET_6BYTE_SEQUENCE_NUMBER, | 2539 QuicSequenceNumberLength lengths[] = {PACKET_6BYTE_SEQUENCE_NUMBER, |
| 2539 PACKET_4BYTE_SEQUENCE_NUMBER, | 2540 PACKET_4BYTE_SEQUENCE_NUMBER, |
| 2540 PACKET_2BYTE_SEQUENCE_NUMBER, | 2541 PACKET_2BYTE_SEQUENCE_NUMBER, |
| 2541 PACKET_1BYTE_SEQUENCE_NUMBER}; | 2542 PACKET_1BYTE_SEQUENCE_NUMBER}; |
| 2542 // For each sequence number length size, revive a packet and check sequence | 2543 // For each sequence number length size, revive a packet and check sequence |
| 2543 // number length in the revived packet. | 2544 // number length in the revived packet. |
| 2544 for (size_t i = 0; i < arraysize(lengths); ++i) { | 2545 for (size_t i = 0; i < arraysize(lengths); ++i) { |
| 2545 // Set sequence_number_length_ (for data and FEC packets). | 2546 // Set sequence_number_length_ (for data and FEC packets). |
| 2546 sequence_number_length_ = lengths[i]; | 2547 sequence_number_length_ = lengths[i]; |
| 2547 fec_packet += 2; | 2548 fec_packet += 2; |
| 2548 // Don't send missing packet, but send fec packet right after it. | 2549 // Don't send missing packet, but send fec packet right after it. |
| 2549 ProcessFecPacket(fec_packet, fec_packet - 1, true, !kEntropyFlag, nullptr); | 2550 ProcessFecPacket(fec_packet, fec_packet - 1, true, !kEntropyFlag, nullptr); |
| 2550 // Sequence number length in the revived header should be the same as | 2551 // Sequence number length in the revived header should be the same as |
| 2551 // in the original data/fec packet headers. | 2552 // in the original data/fec packet headers. |
| 2552 EXPECT_EQ(sequence_number_length_, fec_visitor->revived_header(). | 2553 EXPECT_EQ(sequence_number_length_, fec_visitor->revived_header(). |
| 2553 public_header.sequence_number_length); | 2554 public_header.sequence_number_length); |
| 2554 } | 2555 } |
| 2555 } | 2556 } |
| 2556 | 2557 |
| 2557 TEST_P(QuicConnectionTest, ReviveMissingPacketWithVaryingConnectionIdLengths) { | 2558 TEST_P(QuicConnectionTest, ReviveMissingPacketWithVaryingConnectionIdLengths) { |
| 2558 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); | 2559 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); |
| 2559 | 2560 |
| 2560 // Set up a debug visitor to the connection. | 2561 // Set up a debug visitor to the connection. |
| 2561 FecQuicConnectionDebugVisitor* fec_visitor = | 2562 scoped_ptr<FecQuicConnectionDebugVisitor> fec_visitor( |
| 2562 new FecQuicConnectionDebugVisitor(); | 2563 new FecQuicConnectionDebugVisitor()); |
| 2563 connection_.set_debug_visitor(fec_visitor); | 2564 connection_.set_debug_visitor(fec_visitor.get()); |
| 2564 | 2565 |
| 2565 QuicPacketSequenceNumber fec_packet = 0; | 2566 QuicPacketSequenceNumber fec_packet = 0; |
| 2566 QuicConnectionIdLength lengths[] = {PACKET_8BYTE_CONNECTION_ID, | 2567 QuicConnectionIdLength lengths[] = {PACKET_8BYTE_CONNECTION_ID, |
| 2567 PACKET_4BYTE_CONNECTION_ID, | 2568 PACKET_4BYTE_CONNECTION_ID, |
| 2568 PACKET_1BYTE_CONNECTION_ID, | 2569 PACKET_1BYTE_CONNECTION_ID, |
| 2569 PACKET_0BYTE_CONNECTION_ID}; | 2570 PACKET_0BYTE_CONNECTION_ID}; |
| 2570 // For each connection id length size, revive a packet and check connection | 2571 // For each connection id length size, revive a packet and check connection |
| 2571 // id length in the revived packet. | 2572 // id length in the revived packet. |
| 2572 for (size_t i = 0; i < arraysize(lengths); ++i) { | 2573 for (size_t i = 0; i < arraysize(lengths); ++i) { |
| 2573 // Set connection id length (for data and FEC packets). | 2574 // Set connection id length (for data and FEC packets). |
| (...skipping 1787 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4361 MOCK_METHOD1(OnVersionNegotiationPacket, | 4362 MOCK_METHOD1(OnVersionNegotiationPacket, |
| 4362 void(const QuicVersionNegotiationPacket&)); | 4363 void(const QuicVersionNegotiationPacket&)); |
| 4363 | 4364 |
| 4364 MOCK_METHOD2(OnRevivedPacket, | 4365 MOCK_METHOD2(OnRevivedPacket, |
| 4365 void(const QuicPacketHeader&, StringPiece payload)); | 4366 void(const QuicPacketHeader&, StringPiece payload)); |
| 4366 }; | 4367 }; |
| 4367 | 4368 |
| 4368 TEST_P(QuicConnectionTest, OnPacketHeaderDebugVisitor) { | 4369 TEST_P(QuicConnectionTest, OnPacketHeaderDebugVisitor) { |
| 4369 QuicPacketHeader header; | 4370 QuicPacketHeader header; |
| 4370 | 4371 |
| 4371 MockQuicConnectionDebugVisitor* debug_visitor = | 4372 scoped_ptr<MockQuicConnectionDebugVisitor> debug_visitor( |
| 4372 new MockQuicConnectionDebugVisitor(); | 4373 new MockQuicConnectionDebugVisitor()); |
| 4373 connection_.set_debug_visitor(debug_visitor); | 4374 connection_.set_debug_visitor(debug_visitor.get()); |
| 4374 EXPECT_CALL(*debug_visitor, OnPacketHeader(Ref(header))).Times(1); | 4375 EXPECT_CALL(*debug_visitor, OnPacketHeader(Ref(header))).Times(1); |
| 4375 connection_.OnPacketHeader(header); | 4376 connection_.OnPacketHeader(header); |
| 4376 } | 4377 } |
| 4377 | 4378 |
| 4378 TEST_P(QuicConnectionTest, Pacing) { | 4379 TEST_P(QuicConnectionTest, Pacing) { |
| 4379 TestConnection server(connection_id_, IPEndPoint(), helper_.get(), | 4380 TestConnection server(connection_id_, IPEndPoint(), helper_.get(), |
| 4380 factory_, /* is_server= */ true, version()); | 4381 factory_, /* is_server= */ true, version()); |
| 4381 TestConnection client(connection_id_, IPEndPoint(), helper_.get(), | 4382 TestConnection client(connection_id_, IPEndPoint(), helper_.get(), |
| 4382 factory_, /* is_server= */ false, version()); | 4383 factory_, /* is_server= */ false, version()); |
| 4383 EXPECT_FALSE(client.sent_packet_manager().using_pacing()); | 4384 EXPECT_FALSE(client.sent_packet_manager().using_pacing()); |
| (...skipping 29 matching lines...) Expand all Loading... |
| 4413 // Regression test for b/18594622 | 4414 // Regression test for b/18594622 |
| 4414 scoped_refptr<MockAckNotifierDelegate> delegate(new MockAckNotifierDelegate); | 4415 scoped_refptr<MockAckNotifierDelegate> delegate(new MockAckNotifierDelegate); |
| 4415 EXPECT_DFATAL( | 4416 EXPECT_DFATAL( |
| 4416 connection_.SendStreamDataWithString(3, "", 0, !kFin, delegate.get()), | 4417 connection_.SendStreamDataWithString(3, "", 0, !kFin, delegate.get()), |
| 4417 "Attempt to send empty stream frame"); | 4418 "Attempt to send empty stream frame"); |
| 4418 } | 4419 } |
| 4419 | 4420 |
| 4420 } // namespace | 4421 } // namespace |
| 4421 } // namespace test | 4422 } // namespace test |
| 4422 } // namespace net | 4423 } // namespace net |
| OLD | NEW |