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" |
(...skipping 896 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
907 ProcessDataPacket(6000, 0, !kEntropyFlag); | 907 ProcessDataPacket(6000, 0, !kEntropyFlag); |
908 EXPECT_FALSE( | 908 EXPECT_FALSE( |
909 QuicConnectionPeer::GetConnectionClosePacket(&connection_) == NULL); | 909 QuicConnectionPeer::GetConnectionClosePacket(&connection_) == NULL); |
910 } | 910 } |
911 | 911 |
912 void BlockOnNextWrite() { | 912 void BlockOnNextWrite() { |
913 writer_->BlockOnNextWrite(); | 913 writer_->BlockOnNextWrite(); |
914 EXPECT_CALL(visitor_, OnWriteBlocked()).Times(AtLeast(1)); | 914 EXPECT_CALL(visitor_, OnWriteBlocked()).Times(AtLeast(1)); |
915 } | 915 } |
916 | 916 |
| 917 void CongestionBlockWrites() { |
| 918 EXPECT_CALL(*send_algorithm_, |
| 919 TimeUntilSend(_, _, _)).WillRepeatedly( |
| 920 testing::Return(QuicTime::Delta::FromSeconds(1))); |
| 921 } |
| 922 |
| 923 void CongestionUnblockWrites() { |
| 924 EXPECT_CALL(*send_algorithm_, |
| 925 TimeUntilSend(_, _, _)).WillRepeatedly( |
| 926 testing::Return(QuicTime::Delta::Zero())); |
| 927 } |
| 928 |
917 QuicConnectionId connection_id_; | 929 QuicConnectionId connection_id_; |
918 QuicFramer framer_; | 930 QuicFramer framer_; |
919 QuicPacketCreator peer_creator_; | 931 QuicPacketCreator peer_creator_; |
920 MockEntropyCalculator entropy_calculator_; | 932 MockEntropyCalculator entropy_calculator_; |
921 | 933 |
922 MockSendAlgorithm* send_algorithm_; | 934 MockSendAlgorithm* send_algorithm_; |
923 MockLossAlgorithm* loss_algorithm_; | 935 MockLossAlgorithm* loss_algorithm_; |
924 TestReceiveAlgorithm* receive_algorithm_; | 936 TestReceiveAlgorithm* receive_algorithm_; |
925 MockClock clock_; | 937 MockClock clock_; |
926 MockRandom random_generator_; | 938 MockRandom random_generator_; |
(...skipping 634 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1561 | 1573 |
1562 // Abandon all packets | 1574 // Abandon all packets |
1563 EXPECT_CALL(*send_algorithm_, OnRetransmissionTimeout(false)); | 1575 EXPECT_CALL(*send_algorithm_, OnRetransmissionTimeout(false)); |
1564 connection_.GetRetransmissionAlarm()->Fire(); | 1576 connection_.GetRetransmissionAlarm()->Fire(); |
1565 | 1577 |
1566 // Ensure the alarm is not set since all packets have been abandoned. | 1578 // Ensure the alarm is not set since all packets have been abandoned. |
1567 EXPECT_FALSE(connection_.GetRetransmissionAlarm()->IsSet()); | 1579 EXPECT_FALSE(connection_.GetRetransmissionAlarm()->IsSet()); |
1568 } | 1580 } |
1569 | 1581 |
1570 TEST_P(QuicConnectionTest, FramePacking) { | 1582 TEST_P(QuicConnectionTest, FramePacking) { |
1571 // Block the connection. | 1583 CongestionBlockWrites(); |
1572 connection_.GetSendAlarm()->Set( | |
1573 clock_.ApproximateNow().Add(QuicTime::Delta::FromSeconds(1))); | |
1574 | 1584 |
1575 // Send an ack and two stream frames in 1 packet by queueing them. | 1585 // Send an ack and two stream frames in 1 packet by queueing them. |
1576 connection_.SendAck(); | 1586 connection_.SendAck(); |
1577 EXPECT_CALL(visitor_, OnCanWrite()).WillOnce(DoAll( | 1587 EXPECT_CALL(visitor_, OnCanWrite()).WillOnce(DoAll( |
1578 IgnoreResult(InvokeWithoutArgs(&connection_, | 1588 IgnoreResult(InvokeWithoutArgs(&connection_, |
1579 &TestConnection::SendStreamData3)), | 1589 &TestConnection::SendStreamData3)), |
1580 IgnoreResult(InvokeWithoutArgs(&connection_, | 1590 IgnoreResult(InvokeWithoutArgs(&connection_, |
1581 &TestConnection::SendStreamData5)))); | 1591 &TestConnection::SendStreamData5)))); |
1582 | 1592 |
1583 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(1); | 1593 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(1); |
1584 // Unblock the connection. | 1594 CongestionUnblockWrites(); |
1585 connection_.GetSendAlarm()->Fire(); | 1595 connection_.GetSendAlarm()->Fire(); |
1586 EXPECT_EQ(0u, connection_.NumQueuedPackets()); | 1596 EXPECT_EQ(0u, connection_.NumQueuedPackets()); |
1587 EXPECT_FALSE(connection_.HasQueuedData()); | 1597 EXPECT_FALSE(connection_.HasQueuedData()); |
1588 | 1598 |
1589 // Parse the last packet and ensure it's an ack and two stream frames from | 1599 // Parse the last packet and ensure it's an ack and two stream frames from |
1590 // two different streams. | 1600 // two different streams. |
1591 if (version() > QUIC_VERSION_15) { | 1601 if (version() > QUIC_VERSION_15) { |
1592 EXPECT_EQ(4u, writer_->frame_count()); | 1602 EXPECT_EQ(4u, writer_->frame_count()); |
1593 EXPECT_FALSE(writer_->stop_waiting_frames().empty()); | 1603 EXPECT_FALSE(writer_->stop_waiting_frames().empty()); |
1594 } else { | 1604 } else { |
1595 EXPECT_EQ(3u, writer_->frame_count()); | 1605 EXPECT_EQ(3u, writer_->frame_count()); |
1596 } | 1606 } |
1597 EXPECT_FALSE(writer_->ack_frames().empty()); | 1607 EXPECT_FALSE(writer_->ack_frames().empty()); |
1598 EXPECT_EQ(2u, writer_->stream_frames().size()); | 1608 ASSERT_EQ(2u, writer_->stream_frames().size()); |
1599 EXPECT_EQ(kClientDataStreamId1, writer_->stream_frames()[0].stream_id); | 1609 EXPECT_EQ(kClientDataStreamId1, writer_->stream_frames()[0].stream_id); |
1600 EXPECT_EQ(kClientDataStreamId2, writer_->stream_frames()[1].stream_id); | 1610 EXPECT_EQ(kClientDataStreamId2, writer_->stream_frames()[1].stream_id); |
1601 } | 1611 } |
1602 | 1612 |
1603 TEST_P(QuicConnectionTest, FramePackingNonCryptoThenCrypto) { | 1613 TEST_P(QuicConnectionTest, FramePackingNonCryptoThenCrypto) { |
1604 // Block the connection. | 1614 CongestionBlockWrites(); |
1605 connection_.GetSendAlarm()->Set( | |
1606 clock_.ApproximateNow().Add(QuicTime::Delta::FromSeconds(1))); | |
1607 | 1615 |
1608 // Send an ack and two stream frames (one non-crypto, then one crypto) in 2 | 1616 // Send an ack and two stream frames (one non-crypto, then one crypto) in 2 |
1609 // packets by queueing them. | 1617 // packets by queueing them. |
1610 connection_.SendAck(); | 1618 connection_.SendAck(); |
1611 EXPECT_CALL(visitor_, OnCanWrite()).WillOnce(DoAll( | 1619 EXPECT_CALL(visitor_, OnCanWrite()).WillOnce(DoAll( |
1612 IgnoreResult(InvokeWithoutArgs(&connection_, | 1620 IgnoreResult(InvokeWithoutArgs(&connection_, |
1613 &TestConnection::SendStreamData3)), | 1621 &TestConnection::SendStreamData3)), |
1614 IgnoreResult(InvokeWithoutArgs(&connection_, | 1622 IgnoreResult(InvokeWithoutArgs(&connection_, |
1615 &TestConnection::SendCryptoStreamData)))); | 1623 &TestConnection::SendCryptoStreamData)))); |
1616 | 1624 |
1617 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(2); | 1625 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(2); |
1618 // Unblock the connection. | 1626 CongestionUnblockWrites(); |
1619 connection_.GetSendAlarm()->Fire(); | 1627 connection_.GetSendAlarm()->Fire(); |
1620 EXPECT_EQ(0u, connection_.NumQueuedPackets()); | 1628 EXPECT_EQ(0u, connection_.NumQueuedPackets()); |
1621 EXPECT_FALSE(connection_.HasQueuedData()); | 1629 EXPECT_FALSE(connection_.HasQueuedData()); |
1622 | 1630 |
1623 // Parse the last packet and ensure it's the crypto stream frame. | 1631 // Parse the last packet and ensure it's the crypto stream frame. |
1624 EXPECT_EQ(1u, writer_->frame_count()); | 1632 EXPECT_EQ(1u, writer_->frame_count()); |
1625 EXPECT_EQ(1u, writer_->stream_frames().size()); | 1633 ASSERT_EQ(1u, writer_->stream_frames().size()); |
1626 EXPECT_EQ(kCryptoStreamId, writer_->stream_frames()[0].stream_id); | 1634 EXPECT_EQ(kCryptoStreamId, writer_->stream_frames()[0].stream_id); |
1627 } | 1635 } |
1628 | 1636 |
1629 TEST_P(QuicConnectionTest, FramePackingCryptoThenNonCrypto) { | 1637 TEST_P(QuicConnectionTest, FramePackingCryptoThenNonCrypto) { |
1630 // Block the connection. | 1638 CongestionBlockWrites(); |
1631 connection_.GetSendAlarm()->Set( | |
1632 clock_.ApproximateNow().Add(QuicTime::Delta::FromSeconds(1))); | |
1633 | 1639 |
1634 // Send an ack and two stream frames (one crypto, then one non-crypto) in 3 | 1640 // Send an ack and two stream frames (one crypto, then one non-crypto) in 3 |
1635 // packets by queueing them. | 1641 // packets by queueing them. |
1636 connection_.SendAck(); | 1642 connection_.SendAck(); |
1637 EXPECT_CALL(visitor_, OnCanWrite()).WillOnce(DoAll( | 1643 EXPECT_CALL(visitor_, OnCanWrite()).WillOnce(DoAll( |
1638 IgnoreResult(InvokeWithoutArgs(&connection_, | 1644 IgnoreResult(InvokeWithoutArgs(&connection_, |
1639 &TestConnection::SendCryptoStreamData)), | 1645 &TestConnection::SendCryptoStreamData)), |
1640 IgnoreResult(InvokeWithoutArgs(&connection_, | 1646 IgnoreResult(InvokeWithoutArgs(&connection_, |
1641 &TestConnection::SendStreamData3)))); | 1647 &TestConnection::SendStreamData3)))); |
1642 | 1648 |
1643 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(3); | 1649 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(3); |
1644 // Unblock the connection. | 1650 CongestionUnblockWrites(); |
1645 connection_.GetSendAlarm()->Fire(); | 1651 connection_.GetSendAlarm()->Fire(); |
1646 EXPECT_EQ(0u, connection_.NumQueuedPackets()); | 1652 EXPECT_EQ(0u, connection_.NumQueuedPackets()); |
1647 EXPECT_FALSE(connection_.HasQueuedData()); | 1653 EXPECT_FALSE(connection_.HasQueuedData()); |
1648 | 1654 |
1649 // Parse the last packet and ensure it's the stream frame from stream 3. | 1655 // Parse the last packet and ensure it's the stream frame from stream 3. |
1650 EXPECT_EQ(1u, writer_->frame_count()); | 1656 EXPECT_EQ(1u, writer_->frame_count()); |
1651 EXPECT_EQ(1u, writer_->stream_frames().size()); | 1657 ASSERT_EQ(1u, writer_->stream_frames().size()); |
1652 EXPECT_EQ(kClientDataStreamId1, writer_->stream_frames()[0].stream_id); | 1658 EXPECT_EQ(kClientDataStreamId1, writer_->stream_frames()[0].stream_id); |
1653 } | 1659 } |
1654 | 1660 |
1655 TEST_P(QuicConnectionTest, FramePackingFEC) { | 1661 TEST_P(QuicConnectionTest, FramePackingFEC) { |
1656 if (version() < QUIC_VERSION_15) { | |
1657 return; | |
1658 } | |
1659 // Enable fec. | 1662 // Enable fec. |
1660 EXPECT_TRUE(QuicPacketCreatorPeer::SwitchFecProtectionOn( | 1663 EXPECT_TRUE(QuicPacketCreatorPeer::SwitchFecProtectionOn( |
1661 QuicConnectionPeer::GetPacketCreator(&connection_), 6)); | 1664 QuicConnectionPeer::GetPacketCreator(&connection_), 6)); |
1662 | 1665 |
1663 // Block the connection. | 1666 CongestionBlockWrites(); |
1664 connection_.GetSendAlarm()->Set( | |
1665 clock_.ApproximateNow().Add(QuicTime::Delta::FromSeconds(1))); | |
1666 | 1667 |
1667 // Send an ack and two stream frames in 1 packet by queueing them. | 1668 // Send an ack and two stream frames in 1 packet by queueing them. |
1668 connection_.SendAck(); | 1669 connection_.SendAck(); |
1669 EXPECT_CALL(visitor_, OnCanWrite()).WillOnce(DoAll( | 1670 EXPECT_CALL(visitor_, OnCanWrite()).WillOnce(DoAll( |
1670 IgnoreResult(InvokeWithoutArgs(&connection_, | 1671 IgnoreResult(InvokeWithoutArgs(&connection_, |
1671 &TestConnection::SendStreamData3)), | 1672 &TestConnection::SendStreamData3)), |
1672 IgnoreResult(InvokeWithoutArgs(&connection_, | 1673 IgnoreResult(InvokeWithoutArgs(&connection_, |
1673 &TestConnection::SendStreamData5)))); | 1674 &TestConnection::SendStreamData5)))); |
1674 | 1675 |
1675 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(2); | 1676 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(2); |
1676 // Unblock the connection. | 1677 CongestionUnblockWrites(); |
1677 connection_.GetSendAlarm()->Fire(); | 1678 connection_.GetSendAlarm()->Fire(); |
1678 EXPECT_EQ(0u, connection_.NumQueuedPackets()); | 1679 EXPECT_EQ(0u, connection_.NumQueuedPackets()); |
1679 EXPECT_FALSE(connection_.HasQueuedData()); | 1680 EXPECT_FALSE(connection_.HasQueuedData()); |
1680 | 1681 |
1681 // Parse the last packet and ensure it's in an fec group. | 1682 // Parse the last packet and ensure it's in an fec group. |
1682 EXPECT_EQ(1u, writer_->header().fec_group); | 1683 EXPECT_EQ(1u, writer_->header().fec_group); |
1683 EXPECT_EQ(0u, writer_->frame_count()); | 1684 EXPECT_EQ(0u, writer_->frame_count()); |
1684 } | 1685 } |
1685 | 1686 |
1686 TEST_P(QuicConnectionTest, FramePackingAckResponse) { | 1687 TEST_P(QuicConnectionTest, FramePackingAckResponse) { |
(...skipping 413 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2100 EXPECT_CALL(*send_algorithm_, OnCongestionEvent(true, _, _, _)); | 2101 EXPECT_CALL(*send_algorithm_, OnCongestionEvent(true, _, _, _)); |
2101 frame = InitAckFrame(7, 0); | 2102 frame = InitAckFrame(7, 0); |
2102 NackPacket(5, &frame); | 2103 NackPacket(5, &frame); |
2103 NackPacket(6, &frame); | 2104 NackPacket(6, &frame); |
2104 ProcessAckPacket(&frame); | 2105 ProcessAckPacket(&frame); |
2105 | 2106 |
2106 EXPECT_EQ(6u, outgoing_ack()->sent_info.least_unacked); | 2107 EXPECT_EQ(6u, outgoing_ack()->sent_info.least_unacked); |
2107 } | 2108 } |
2108 | 2109 |
2109 TEST_P(QuicConnectionTest, ReviveMissingPacketAfterFecPacket) { | 2110 TEST_P(QuicConnectionTest, ReviveMissingPacketAfterFecPacket) { |
2110 if (version() < QUIC_VERSION_15) { | |
2111 return; | |
2112 } | |
2113 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); | 2111 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); |
2114 | 2112 |
2115 // Don't send missing packet 1. | 2113 // Don't send missing packet 1. |
2116 ProcessFecPacket(2, 1, true, !kEntropyFlag, NULL); | 2114 ProcessFecPacket(2, 1, true, !kEntropyFlag, NULL); |
2117 // Entropy flag should be false, so entropy should be 0. | 2115 // Entropy flag should be false, so entropy should be 0. |
2118 EXPECT_EQ(0u, QuicConnectionPeer::ReceivedEntropyHash(&connection_, 2)); | 2116 EXPECT_EQ(0u, QuicConnectionPeer::ReceivedEntropyHash(&connection_, 2)); |
2119 } | 2117 } |
2120 | 2118 |
2121 TEST_P(QuicConnectionTest, ReviveMissingPacketWithVaryingSeqNumLengths) { | 2119 TEST_P(QuicConnectionTest, ReviveMissingPacketWithVaryingSeqNumLengths) { |
2122 if (version() < QUIC_VERSION_15) { | |
2123 return; | |
2124 } | |
2125 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); | 2120 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); |
2126 | 2121 |
2127 // Set up a debug visitor to the connection. | 2122 // Set up a debug visitor to the connection. |
2128 scoped_ptr<FecQuicConnectionDebugVisitor> | 2123 scoped_ptr<FecQuicConnectionDebugVisitor> |
2129 fec_visitor(new FecQuicConnectionDebugVisitor); | 2124 fec_visitor(new FecQuicConnectionDebugVisitor); |
2130 connection_.set_debug_visitor(fec_visitor.get()); | 2125 connection_.set_debug_visitor(fec_visitor.get()); |
2131 | 2126 |
2132 QuicPacketSequenceNumber fec_packet = 0; | 2127 QuicPacketSequenceNumber fec_packet = 0; |
2133 QuicSequenceNumberLength lengths[] = {PACKET_6BYTE_SEQUENCE_NUMBER, | 2128 QuicSequenceNumberLength lengths[] = {PACKET_6BYTE_SEQUENCE_NUMBER, |
2134 PACKET_4BYTE_SEQUENCE_NUMBER, | 2129 PACKET_4BYTE_SEQUENCE_NUMBER, |
2135 PACKET_2BYTE_SEQUENCE_NUMBER, | 2130 PACKET_2BYTE_SEQUENCE_NUMBER, |
2136 PACKET_1BYTE_SEQUENCE_NUMBER}; | 2131 PACKET_1BYTE_SEQUENCE_NUMBER}; |
2137 // For each sequence number length size, revive a packet and check sequence | 2132 // For each sequence number length size, revive a packet and check sequence |
2138 // number length in the revived packet. | 2133 // number length in the revived packet. |
2139 for (size_t i = 0; i < arraysize(lengths); ++i) { | 2134 for (size_t i = 0; i < arraysize(lengths); ++i) { |
2140 // Set sequence_number_length_ (for data and FEC packets). | 2135 // Set sequence_number_length_ (for data and FEC packets). |
2141 sequence_number_length_ = lengths[i]; | 2136 sequence_number_length_ = lengths[i]; |
2142 fec_packet += 2; | 2137 fec_packet += 2; |
2143 // Don't send missing packet, but send fec packet right after it. | 2138 // Don't send missing packet, but send fec packet right after it. |
2144 ProcessFecPacket(/*seq_num=*/fec_packet, /*fec_group=*/fec_packet - 1, | 2139 ProcessFecPacket(/*seq_num=*/fec_packet, /*fec_group=*/fec_packet - 1, |
2145 true, !kEntropyFlag, NULL); | 2140 true, !kEntropyFlag, NULL); |
2146 // Sequence number length in the revived header should be the same as | 2141 // Sequence number length in the revived header should be the same as |
2147 // in the original data/fec packet headers. | 2142 // in the original data/fec packet headers. |
2148 EXPECT_EQ(sequence_number_length_, fec_visitor->revived_header(). | 2143 EXPECT_EQ(sequence_number_length_, fec_visitor->revived_header(). |
2149 public_header.sequence_number_length); | 2144 public_header.sequence_number_length); |
2150 } | 2145 } |
2151 } | 2146 } |
2152 | 2147 |
2153 TEST_P(QuicConnectionTest, ReviveMissingPacketWithVaryingConnectionIdLengths) { | 2148 TEST_P(QuicConnectionTest, ReviveMissingPacketWithVaryingConnectionIdLengths) { |
2154 if (version() < QUIC_VERSION_15) { | |
2155 return; | |
2156 } | |
2157 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); | 2149 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); |
2158 | 2150 |
2159 // Set up a debug visitor to the connection. | 2151 // Set up a debug visitor to the connection. |
2160 scoped_ptr<FecQuicConnectionDebugVisitor> | 2152 scoped_ptr<FecQuicConnectionDebugVisitor> |
2161 fec_visitor(new FecQuicConnectionDebugVisitor); | 2153 fec_visitor(new FecQuicConnectionDebugVisitor); |
2162 connection_.set_debug_visitor(fec_visitor.get()); | 2154 connection_.set_debug_visitor(fec_visitor.get()); |
2163 | 2155 |
2164 QuicPacketSequenceNumber fec_packet = 0; | 2156 QuicPacketSequenceNumber fec_packet = 0; |
2165 QuicConnectionIdLength lengths[] = {PACKET_8BYTE_CONNECTION_ID, | 2157 QuicConnectionIdLength lengths[] = {PACKET_8BYTE_CONNECTION_ID, |
2166 PACKET_4BYTE_CONNECTION_ID, | 2158 PACKET_4BYTE_CONNECTION_ID, |
2167 PACKET_1BYTE_CONNECTION_ID, | 2159 PACKET_1BYTE_CONNECTION_ID, |
2168 PACKET_0BYTE_CONNECTION_ID}; | 2160 PACKET_0BYTE_CONNECTION_ID}; |
2169 // For each connection id length size, revive a packet and check connection | 2161 // For each connection id length size, revive a packet and check connection |
2170 // id length in the revived packet. | 2162 // id length in the revived packet. |
2171 for (size_t i = 0; i < arraysize(lengths); ++i) { | 2163 for (size_t i = 0; i < arraysize(lengths); ++i) { |
2172 // Set connection id length (for data and FEC packets). | 2164 // Set connection id length (for data and FEC packets). |
2173 connection_id_length_ = lengths[i]; | 2165 connection_id_length_ = lengths[i]; |
2174 fec_packet += 2; | 2166 fec_packet += 2; |
2175 // Don't send missing packet, but send fec packet right after it. | 2167 // Don't send missing packet, but send fec packet right after it. |
2176 ProcessFecPacket(/*seq_num=*/fec_packet, /*fec_group=*/fec_packet - 1, | 2168 ProcessFecPacket(/*seq_num=*/fec_packet, /*fec_group=*/fec_packet - 1, |
2177 true, !kEntropyFlag, NULL); | 2169 true, !kEntropyFlag, NULL); |
2178 // Connection id length in the revived header should be the same as | 2170 // Connection id length in the revived header should be the same as |
2179 // in the original data/fec packet headers. | 2171 // in the original data/fec packet headers. |
2180 EXPECT_EQ(connection_id_length_, | 2172 EXPECT_EQ(connection_id_length_, |
2181 fec_visitor->revived_header().public_header.connection_id_length); | 2173 fec_visitor->revived_header().public_header.connection_id_length); |
2182 } | 2174 } |
2183 } | 2175 } |
2184 | 2176 |
2185 TEST_P(QuicConnectionTest, ReviveMissingPacketAfterDataPacketThenFecPacket) { | 2177 TEST_P(QuicConnectionTest, ReviveMissingPacketAfterDataPacketThenFecPacket) { |
2186 if (version() < QUIC_VERSION_15) { | |
2187 return; | |
2188 } | |
2189 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); | 2178 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); |
2190 | 2179 |
2191 ProcessFecProtectedPacket(1, false, kEntropyFlag); | 2180 ProcessFecProtectedPacket(1, false, kEntropyFlag); |
2192 // Don't send missing packet 2. | 2181 // Don't send missing packet 2. |
2193 ProcessFecPacket(3, 1, true, !kEntropyFlag, NULL); | 2182 ProcessFecPacket(3, 1, true, !kEntropyFlag, NULL); |
2194 // Entropy flag should be true, so entropy should not be 0. | 2183 // Entropy flag should be true, so entropy should not be 0. |
2195 EXPECT_NE(0u, QuicConnectionPeer::ReceivedEntropyHash(&connection_, 2)); | 2184 EXPECT_NE(0u, QuicConnectionPeer::ReceivedEntropyHash(&connection_, 2)); |
2196 } | 2185 } |
2197 | 2186 |
2198 TEST_P(QuicConnectionTest, ReviveMissingPacketAfterDataPacketsThenFecPacket) { | 2187 TEST_P(QuicConnectionTest, ReviveMissingPacketAfterDataPacketsThenFecPacket) { |
2199 if (version() < QUIC_VERSION_15) { | |
2200 return; | |
2201 } | |
2202 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); | 2188 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); |
2203 | 2189 |
2204 ProcessFecProtectedPacket(1, false, !kEntropyFlag); | 2190 ProcessFecProtectedPacket(1, false, !kEntropyFlag); |
2205 // Don't send missing packet 2. | 2191 // Don't send missing packet 2. |
2206 ProcessFecProtectedPacket(3, false, !kEntropyFlag); | 2192 ProcessFecProtectedPacket(3, false, !kEntropyFlag); |
2207 ProcessFecPacket(4, 1, true, kEntropyFlag, NULL); | 2193 ProcessFecPacket(4, 1, true, kEntropyFlag, NULL); |
2208 // Ensure QUIC no longer revives entropy for lost packets. | 2194 // Ensure QUIC no longer revives entropy for lost packets. |
2209 EXPECT_EQ(0u, QuicConnectionPeer::ReceivedEntropyHash(&connection_, 2)); | 2195 EXPECT_EQ(0u, QuicConnectionPeer::ReceivedEntropyHash(&connection_, 2)); |
2210 EXPECT_NE(0u, QuicConnectionPeer::ReceivedEntropyHash(&connection_, 4)); | 2196 EXPECT_NE(0u, QuicConnectionPeer::ReceivedEntropyHash(&connection_, 4)); |
2211 } | 2197 } |
2212 | 2198 |
2213 TEST_P(QuicConnectionTest, ReviveMissingPacketAfterDataPacket) { | 2199 TEST_P(QuicConnectionTest, ReviveMissingPacketAfterDataPacket) { |
2214 if (version() < QUIC_VERSION_15) { | |
2215 return; | |
2216 } | |
2217 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); | 2200 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); |
2218 | 2201 |
2219 // Don't send missing packet 1. | 2202 // Don't send missing packet 1. |
2220 ProcessFecPacket(3, 1, false, !kEntropyFlag, NULL); | 2203 ProcessFecPacket(3, 1, false, !kEntropyFlag, NULL); |
2221 // Out of order. | 2204 // Out of order. |
2222 ProcessFecProtectedPacket(2, true, !kEntropyFlag); | 2205 ProcessFecProtectedPacket(2, true, !kEntropyFlag); |
2223 // Entropy flag should be false, so entropy should be 0. | 2206 // Entropy flag should be false, so entropy should be 0. |
2224 EXPECT_EQ(0u, QuicConnectionPeer::ReceivedEntropyHash(&connection_, 2)); | 2207 EXPECT_EQ(0u, QuicConnectionPeer::ReceivedEntropyHash(&connection_, 2)); |
2225 } | 2208 } |
2226 | 2209 |
2227 TEST_P(QuicConnectionTest, ReviveMissingPacketAfterDataPackets) { | 2210 TEST_P(QuicConnectionTest, ReviveMissingPacketAfterDataPackets) { |
2228 if (version() < QUIC_VERSION_15) { | |
2229 return; | |
2230 } | |
2231 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); | 2211 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); |
2232 | 2212 |
2233 ProcessFecProtectedPacket(1, false, !kEntropyFlag); | 2213 ProcessFecProtectedPacket(1, false, !kEntropyFlag); |
2234 // Don't send missing packet 2. | 2214 // Don't send missing packet 2. |
2235 ProcessFecPacket(6, 1, false, kEntropyFlag, NULL); | 2215 ProcessFecPacket(6, 1, false, kEntropyFlag, NULL); |
2236 ProcessFecProtectedPacket(3, false, kEntropyFlag); | 2216 ProcessFecProtectedPacket(3, false, kEntropyFlag); |
2237 ProcessFecProtectedPacket(4, false, kEntropyFlag); | 2217 ProcessFecProtectedPacket(4, false, kEntropyFlag); |
2238 ProcessFecProtectedPacket(5, true, !kEntropyFlag); | 2218 ProcessFecProtectedPacket(5, true, !kEntropyFlag); |
2239 // Ensure entropy is not revived for the missing packet. | 2219 // Ensure entropy is not revived for the missing packet. |
2240 EXPECT_EQ(0u, QuicConnectionPeer::ReceivedEntropyHash(&connection_, 2)); | 2220 EXPECT_EQ(0u, QuicConnectionPeer::ReceivedEntropyHash(&connection_, 2)); |
(...skipping 345 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2586 } | 2566 } |
2587 | 2567 |
2588 TEST_P(QuicConnectionTest, UpdateQuicCongestionFeedbackFrame) { | 2568 TEST_P(QuicConnectionTest, UpdateQuicCongestionFeedbackFrame) { |
2589 SendAckPacketToPeer(); | 2569 SendAckPacketToPeer(); |
2590 EXPECT_CALL(*receive_algorithm_, RecordIncomingPacket(_, _, _)); | 2570 EXPECT_CALL(*receive_algorithm_, RecordIncomingPacket(_, _, _)); |
2591 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); | 2571 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); |
2592 ProcessPacket(1); | 2572 ProcessPacket(1); |
2593 } | 2573 } |
2594 | 2574 |
2595 TEST_P(QuicConnectionTest, DontUpdateQuicCongestionFeedbackFrameForRevived) { | 2575 TEST_P(QuicConnectionTest, DontUpdateQuicCongestionFeedbackFrameForRevived) { |
2596 if (version() < QUIC_VERSION_15) { | |
2597 return; | |
2598 } | |
2599 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); | 2576 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); |
2600 SendAckPacketToPeer(); | 2577 SendAckPacketToPeer(); |
2601 // Process an FEC packet, and revive the missing data packet | 2578 // Process an FEC packet, and revive the missing data packet |
2602 // but only contact the receive_algorithm once. | 2579 // but only contact the receive_algorithm once. |
2603 EXPECT_CALL(*receive_algorithm_, RecordIncomingPacket(_, _, _)); | 2580 EXPECT_CALL(*receive_algorithm_, RecordIncomingPacket(_, _, _)); |
2604 ProcessFecPacket(2, 1, true, !kEntropyFlag, NULL); | 2581 ProcessFecPacket(2, 1, true, !kEntropyFlag, NULL); |
2605 } | 2582 } |
2606 | 2583 |
2607 TEST_P(QuicConnectionTest, InitialTimeout) { | 2584 TEST_P(QuicConnectionTest, InitialTimeout) { |
2608 EXPECT_TRUE(connection_.connected()); | 2585 EXPECT_TRUE(connection_.connected()); |
(...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2760 EXPECT_CALL(*send_algorithm_, | 2737 EXPECT_CALL(*send_algorithm_, |
2761 TimeUntilSend(_, _, _)).WillRepeatedly( | 2738 TimeUntilSend(_, _, _)).WillRepeatedly( |
2762 testing::Return(QuicTime::Delta::Zero())); | 2739 testing::Return(QuicTime::Delta::Zero())); |
2763 clock_.AdvanceTime(QuicTime::Delta::FromMicroseconds(1)); | 2740 clock_.AdvanceTime(QuicTime::Delta::FromMicroseconds(1)); |
2764 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)); | 2741 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)); |
2765 connection_.GetSendAlarm()->Fire(); | 2742 connection_.GetSendAlarm()->Fire(); |
2766 EXPECT_EQ(0u, connection_.NumQueuedPackets()); | 2743 EXPECT_EQ(0u, connection_.NumQueuedPackets()); |
2767 } | 2744 } |
2768 | 2745 |
2769 TEST_P(QuicConnectionTest, SendSchedulerDelayThenRetransmit) { | 2746 TEST_P(QuicConnectionTest, SendSchedulerDelayThenRetransmit) { |
2770 EXPECT_CALL(*send_algorithm_, TimeUntilSend(_, _, _)) | 2747 CongestionUnblockWrites(); |
2771 .WillRepeatedly(testing::Return(QuicTime::Delta::Zero())); | |
2772 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, 1, _, _)); | 2748 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, 1, _, _)); |
2773 connection_.SendStreamDataWithString(3, "foo", 0, !kFin, NULL); | 2749 connection_.SendStreamDataWithString(3, "foo", 0, !kFin, NULL); |
2774 EXPECT_EQ(0u, connection_.NumQueuedPackets()); | 2750 EXPECT_EQ(0u, connection_.NumQueuedPackets()); |
2775 // Advance the time for retransmission of lost packet. | 2751 // Advance the time for retransmission of lost packet. |
2776 clock_.AdvanceTime(QuicTime::Delta::FromMilliseconds(501)); | 2752 clock_.AdvanceTime(QuicTime::Delta::FromMilliseconds(501)); |
2777 // Test that if we send a retransmit with a delay, it ends up queued in the | 2753 // Test that if we send a retransmit with a delay, it ends up queued in the |
2778 // sent packet manager, but not yet serialized. | 2754 // sent packet manager, but not yet serialized. |
2779 EXPECT_CALL(*send_algorithm_, OnRetransmissionTimeout(true)); | 2755 EXPECT_CALL(*send_algorithm_, OnRetransmissionTimeout(true)); |
2780 EXPECT_CALL(*send_algorithm_, | 2756 CongestionBlockWrites(); |
2781 TimeUntilSend(_, _, _)).WillOnce( | |
2782 testing::Return(QuicTime::Delta::FromMicroseconds(1))); | |
2783 connection_.GetRetransmissionAlarm()->Fire(); | 2757 connection_.GetRetransmissionAlarm()->Fire(); |
2784 EXPECT_EQ(0u, connection_.NumQueuedPackets()); | 2758 EXPECT_EQ(0u, connection_.NumQueuedPackets()); |
2785 | 2759 |
2786 // Advance the clock to fire the alarm, and configure the scheduler | 2760 // Advance the clock to fire the alarm, and configure the scheduler |
2787 // to permit the packet to be sent. | 2761 // to permit the packet to be sent. |
2788 EXPECT_CALL(*send_algorithm_, | 2762 CongestionUnblockWrites(); |
2789 TimeUntilSend(_, _, _)).Times(3). | |
2790 WillRepeatedly(testing::Return(QuicTime::Delta::Zero())); | |
2791 | 2763 |
2792 // Ensure the scheduler is notified this is a retransmit. | 2764 // Ensure the scheduler is notified this is a retransmit. |
2793 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)); | 2765 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)); |
2794 clock_.AdvanceTime(QuicTime::Delta::FromMicroseconds(1)); | 2766 clock_.AdvanceTime(QuicTime::Delta::FromMicroseconds(1)); |
2795 connection_.GetSendAlarm()->Fire(); | 2767 connection_.GetSendAlarm()->Fire(); |
2796 EXPECT_EQ(0u, connection_.NumQueuedPackets()); | 2768 EXPECT_EQ(0u, connection_.NumQueuedPackets()); |
2797 } | 2769 } |
2798 | 2770 |
2799 TEST_P(QuicConnectionTest, SendSchedulerDelayAndQueue) { | 2771 TEST_P(QuicConnectionTest, SendSchedulerDelayAndQueue) { |
2800 QuicPacket* packet = ConstructDataPacket(1, 0, !kEntropyFlag); | 2772 QuicPacket* packet = ConstructDataPacket(1, 0, !kEntropyFlag); |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2855 testing::Return(QuicTime::Delta::FromMicroseconds(1))); | 2827 testing::Return(QuicTime::Delta::FromMicroseconds(1))); |
2856 ProcessAckPacket(&frame); | 2828 ProcessAckPacket(&frame); |
2857 | 2829 |
2858 EXPECT_EQ(1u, connection_.NumQueuedPackets()); | 2830 EXPECT_EQ(1u, connection_.NumQueuedPackets()); |
2859 } | 2831 } |
2860 | 2832 |
2861 TEST_P(QuicConnectionTest, SendSchedulerDelayThenOnCanWrite) { | 2833 TEST_P(QuicConnectionTest, SendSchedulerDelayThenOnCanWrite) { |
2862 // TODO(ianswett): This test is unrealistic, because we would not serialize | 2834 // TODO(ianswett): This test is unrealistic, because we would not serialize |
2863 // new data if the send algorithm said not to. | 2835 // new data if the send algorithm said not to. |
2864 QuicPacket* packet = ConstructDataPacket(1, 0, !kEntropyFlag); | 2836 QuicPacket* packet = ConstructDataPacket(1, 0, !kEntropyFlag); |
2865 EXPECT_CALL(*send_algorithm_, | 2837 CongestionBlockWrites(); |
2866 TimeUntilSend(_, _, _)).WillOnce( | |
2867 testing::Return(QuicTime::Delta::FromMicroseconds(10))); | |
2868 connection_.SendPacket( | 2838 connection_.SendPacket( |
2869 ENCRYPTION_NONE, 1, packet, kTestEntropyHash, HAS_RETRANSMITTABLE_DATA); | 2839 ENCRYPTION_NONE, 1, packet, kTestEntropyHash, HAS_RETRANSMITTABLE_DATA); |
2870 EXPECT_EQ(1u, connection_.NumQueuedPackets()); | 2840 EXPECT_EQ(1u, connection_.NumQueuedPackets()); |
2871 | 2841 |
2872 // OnCanWrite should send the packet, because it won't consult the send | 2842 // OnCanWrite should send the packet, because it won't consult the send |
2873 // algorithm for queued packets. | 2843 // algorithm for queued packets. |
2874 connection_.OnCanWrite(); | 2844 connection_.OnCanWrite(); |
2875 EXPECT_EQ(0u, connection_.NumQueuedPackets()); | 2845 EXPECT_EQ(0u, connection_.NumQueuedPackets()); |
2876 } | 2846 } |
2877 | 2847 |
(...skipping 309 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3187 EXPECT_CALL(visitor_, OnStreamFrames(_)).Times(AtLeast(1)); | 3157 EXPECT_CALL(visitor_, OnStreamFrames(_)).Times(AtLeast(1)); |
3188 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); | 3158 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); |
3189 ProcessDataPacket(1, 1, kEntropyFlag); | 3159 ProcessDataPacket(1, 1, kEntropyFlag); |
3190 ProcessDataPacket(4, 1, kEntropyFlag); | 3160 ProcessDataPacket(4, 1, kEntropyFlag); |
3191 ProcessDataPacket(3, 1, !kEntropyFlag); | 3161 ProcessDataPacket(3, 1, !kEntropyFlag); |
3192 ProcessDataPacket(7, 1, kEntropyFlag); | 3162 ProcessDataPacket(7, 1, kEntropyFlag); |
3193 EXPECT_EQ(146u, outgoing_ack()->received_info.entropy_hash); | 3163 EXPECT_EQ(146u, outgoing_ack()->received_info.entropy_hash); |
3194 } | 3164 } |
3195 | 3165 |
3196 TEST_P(QuicConnectionTest, ReceivedEntropyHashCalculationHalfFEC) { | 3166 TEST_P(QuicConnectionTest, ReceivedEntropyHashCalculationHalfFEC) { |
3197 if (version() < QUIC_VERSION_15) { | |
3198 return; | |
3199 } | |
3200 // FEC packets should not change the entropy hash calculation. | 3167 // FEC packets should not change the entropy hash calculation. |
3201 EXPECT_CALL(visitor_, OnStreamFrames(_)).Times(AtLeast(1)); | 3168 EXPECT_CALL(visitor_, OnStreamFrames(_)).Times(AtLeast(1)); |
3202 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); | 3169 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); |
3203 ProcessDataPacket(1, 1, kEntropyFlag); | 3170 ProcessDataPacket(1, 1, kEntropyFlag); |
3204 ProcessFecPacket(4, 1, false, kEntropyFlag, NULL); | 3171 ProcessFecPacket(4, 1, false, kEntropyFlag, NULL); |
3205 ProcessDataPacket(3, 3, !kEntropyFlag); | 3172 ProcessDataPacket(3, 3, !kEntropyFlag); |
3206 ProcessFecPacket(7, 3, false, kEntropyFlag, NULL); | 3173 ProcessFecPacket(7, 3, false, kEntropyFlag, NULL); |
3207 EXPECT_EQ(146u, outgoing_ack()->received_info.entropy_hash); | 3174 EXPECT_EQ(146u, outgoing_ack()->received_info.entropy_hash); |
3208 } | 3175 } |
3209 | 3176 |
(...skipping 326 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3536 EXPECT_EQ(3 * first_packet_size + 2 * second_packet_size - kQuicVersionSize, | 3503 EXPECT_EQ(3 * first_packet_size + 2 * second_packet_size - kQuicVersionSize, |
3537 stats.bytes_sent); | 3504 stats.bytes_sent); |
3538 EXPECT_EQ(5u, stats.packets_sent); | 3505 EXPECT_EQ(5u, stats.packets_sent); |
3539 EXPECT_EQ(2 * first_packet_size + second_packet_size - kQuicVersionSize, | 3506 EXPECT_EQ(2 * first_packet_size + second_packet_size - kQuicVersionSize, |
3540 stats.bytes_retransmitted); | 3507 stats.bytes_retransmitted); |
3541 EXPECT_EQ(3u, stats.packets_retransmitted); | 3508 EXPECT_EQ(3u, stats.packets_retransmitted); |
3542 EXPECT_EQ(1u, stats.rto_count); | 3509 EXPECT_EQ(1u, stats.rto_count); |
3543 } | 3510 } |
3544 | 3511 |
3545 TEST_P(QuicConnectionTest, CheckReceiveStats) { | 3512 TEST_P(QuicConnectionTest, CheckReceiveStats) { |
3546 if (version() < QUIC_VERSION_15) { | |
3547 return; | |
3548 } | |
3549 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); | 3513 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); |
3550 | 3514 |
3551 size_t received_bytes = 0; | 3515 size_t received_bytes = 0; |
3552 received_bytes += ProcessFecProtectedPacket(1, false, !kEntropyFlag); | 3516 received_bytes += ProcessFecProtectedPacket(1, false, !kEntropyFlag); |
3553 received_bytes += ProcessFecProtectedPacket(3, false, !kEntropyFlag); | 3517 received_bytes += ProcessFecProtectedPacket(3, false, !kEntropyFlag); |
3554 // Should be counted against dropped packets. | 3518 // Should be counted against dropped packets. |
3555 received_bytes += ProcessDataPacket(3, 1, !kEntropyFlag); | 3519 received_bytes += ProcessDataPacket(3, 1, !kEntropyFlag); |
3556 received_bytes += ProcessFecPacket(4, 1, true, !kEntropyFlag, NULL); | 3520 received_bytes += ProcessFecPacket(4, 1, true, !kEntropyFlag, NULL); |
3557 | 3521 |
3558 EXPECT_CALL(*send_algorithm_, BandwidthEstimate()).WillOnce( | 3522 EXPECT_CALL(*send_algorithm_, BandwidthEstimate()).WillOnce( |
(...skipping 441 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4000 QuicBlockedFrame blocked; | 3964 QuicBlockedFrame blocked; |
4001 blocked.stream_id = 3; | 3965 blocked.stream_id = 3; |
4002 EXPECT_CALL(visitor_, OnBlockedFrames(_)); | 3966 EXPECT_CALL(visitor_, OnBlockedFrames(_)); |
4003 ProcessFramePacket(QuicFrame(&blocked)); | 3967 ProcessFramePacket(QuicFrame(&blocked)); |
4004 EXPECT_TRUE(ack_alarm->IsSet()); | 3968 EXPECT_TRUE(ack_alarm->IsSet()); |
4005 } | 3969 } |
4006 | 3970 |
4007 } // namespace | 3971 } // namespace |
4008 } // namespace test | 3972 } // namespace test |
4009 } // namespace net | 3973 } // namespace net |
OLD | NEW |