| 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 <string> |
| 8 |
| 7 #include "base/basictypes.h" | 9 #include "base/basictypes.h" |
| 8 #include "base/bind.h" | 10 #include "base/bind.h" |
| 9 #include "base/stl_util.h" | 11 #include "base/stl_util.h" |
| 10 #include "net/base/net_errors.h" | 12 #include "net/base/net_errors.h" |
| 11 #include "net/quic/congestion_control/loss_detection_interface.h" | 13 #include "net/quic/congestion_control/loss_detection_interface.h" |
| 12 #include "net/quic/congestion_control/receive_algorithm_interface.h" | 14 #include "net/quic/congestion_control/receive_algorithm_interface.h" |
| 13 #include "net/quic/congestion_control/send_algorithm_interface.h" | 15 #include "net/quic/congestion_control/send_algorithm_interface.h" |
| 14 #include "net/quic/crypto/null_encrypter.h" | 16 #include "net/quic/crypto/null_encrypter.h" |
| 15 #include "net/quic/crypto/quic_decrypter.h" | 17 #include "net/quic/crypto/quic_decrypter.h" |
| 16 #include "net/quic/crypto/quic_encrypter.h" | 18 #include "net/quic/crypto/quic_encrypter.h" |
| (...skipping 1633 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1650 size_t length = 2 + GetPacketLengthForOneStream( | 1652 size_t length = 2 + GetPacketLengthForOneStream( |
| 1651 connection_.version(), kIncludeVersion, | 1653 connection_.version(), kIncludeVersion, |
| 1652 PACKET_8BYTE_CONNECTION_ID, PACKET_1BYTE_SEQUENCE_NUMBER, | 1654 PACKET_8BYTE_CONNECTION_ID, PACKET_1BYTE_SEQUENCE_NUMBER, |
| 1653 IN_FEC_GROUP, &payload_length); | 1655 IN_FEC_GROUP, &payload_length); |
| 1654 creator->set_max_packet_length(length); | 1656 creator->set_max_packet_length(length); |
| 1655 | 1657 |
| 1656 // Send 4 protected data packets, which should also trigger 1 FEC packet. | 1658 // Send 4 protected data packets, which should also trigger 1 FEC packet. |
| 1657 EXPECT_CALL(*send_algorithm_, | 1659 EXPECT_CALL(*send_algorithm_, |
| 1658 OnPacketSent(_, _, _, _, HAS_RETRANSMITTABLE_DATA)).Times(5); | 1660 OnPacketSent(_, _, _, _, HAS_RETRANSMITTABLE_DATA)).Times(5); |
| 1659 // The first stream frame will have 2 fewer overhead bytes than the other 3. | 1661 // The first stream frame will have 2 fewer overhead bytes than the other 3. |
| 1660 const string payload(payload_length * 4 + 2, 'a'); | 1662 const std::string payload(payload_length * 4 + 2, 'a'); |
| 1661 connection_.SendStreamDataWithStringWithFec(1, payload, 0, !kFin, nullptr); | 1663 connection_.SendStreamDataWithStringWithFec(1, payload, 0, !kFin, nullptr); |
| 1662 // Expect the FEC group to be closed after SendStreamDataWithString. | 1664 // Expect the FEC group to be closed after SendStreamDataWithString. |
| 1663 EXPECT_FALSE(creator->IsFecGroupOpen()); | 1665 EXPECT_FALSE(creator->IsFecGroupOpen()); |
| 1664 EXPECT_FALSE(creator->IsFecProtected()); | 1666 EXPECT_FALSE(creator->IsFecProtected()); |
| 1665 } | 1667 } |
| 1666 | 1668 |
| 1667 TEST_P(QuicConnectionTest, FECQueueing) { | 1669 TEST_P(QuicConnectionTest, FECQueueing) { |
| 1668 // All packets carry version info till version is negotiated. | 1670 // All packets carry version info till version is negotiated. |
| 1669 size_t payload_length; | 1671 size_t payload_length; |
| 1670 QuicPacketCreator* creator = | 1672 QuicPacketCreator* creator = |
| 1671 QuicConnectionPeer::GetPacketCreator(&connection_); | 1673 QuicConnectionPeer::GetPacketCreator(&connection_); |
| 1672 size_t length = GetPacketLengthForOneStream( | 1674 size_t length = GetPacketLengthForOneStream( |
| 1673 connection_.version(), kIncludeVersion, | 1675 connection_.version(), kIncludeVersion, |
| 1674 PACKET_8BYTE_CONNECTION_ID, PACKET_1BYTE_SEQUENCE_NUMBER, | 1676 PACKET_8BYTE_CONNECTION_ID, PACKET_1BYTE_SEQUENCE_NUMBER, |
| 1675 IN_FEC_GROUP, &payload_length); | 1677 IN_FEC_GROUP, &payload_length); |
| 1676 creator->set_max_packet_length(length); | 1678 creator->set_max_packet_length(length); |
| 1677 EXPECT_TRUE(creator->IsFecEnabled()); | 1679 EXPECT_TRUE(creator->IsFecEnabled()); |
| 1678 | 1680 |
| 1679 EXPECT_EQ(0u, connection_.NumQueuedPackets()); | 1681 EXPECT_EQ(0u, connection_.NumQueuedPackets()); |
| 1680 BlockOnNextWrite(); | 1682 BlockOnNextWrite(); |
| 1681 const string payload(payload_length, 'a'); | 1683 const std::string payload(payload_length, 'a'); |
| 1682 connection_.SendStreamDataWithStringWithFec(1, payload, 0, !kFin, nullptr); | 1684 connection_.SendStreamDataWithStringWithFec(1, payload, 0, !kFin, nullptr); |
| 1683 EXPECT_FALSE(creator->IsFecGroupOpen()); | 1685 EXPECT_FALSE(creator->IsFecGroupOpen()); |
| 1684 EXPECT_FALSE(creator->IsFecProtected()); | 1686 EXPECT_FALSE(creator->IsFecProtected()); |
| 1685 // Expect the first data packet and the fec packet to be queued. | 1687 // Expect the first data packet and the fec packet to be queued. |
| 1686 EXPECT_EQ(2u, connection_.NumQueuedPackets()); | 1688 EXPECT_EQ(2u, connection_.NumQueuedPackets()); |
| 1687 } | 1689 } |
| 1688 | 1690 |
| 1689 TEST_P(QuicConnectionTest, AbandonFECFromCongestionWindow) { | 1691 TEST_P(QuicConnectionTest, AbandonFECFromCongestionWindow) { |
| 1690 EXPECT_TRUE(QuicConnectionPeer::GetPacketCreator( | 1692 EXPECT_TRUE(QuicConnectionPeer::GetPacketCreator( |
| 1691 &connection_)->IsFecEnabled()); | 1693 &connection_)->IsFecEnabled()); |
| (...skipping 228 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1920 | 1922 |
| 1921 EXPECT_EQ(0u, connection_.NumQueuedPackets()); | 1923 EXPECT_EQ(0u, connection_.NumQueuedPackets()); |
| 1922 EXPECT_FALSE(connection_.HasQueuedData()); | 1924 EXPECT_FALSE(connection_.HasQueuedData()); |
| 1923 | 1925 |
| 1924 // Parse the last packet and ensure multiple iovector blocks have | 1926 // Parse the last packet and ensure multiple iovector blocks have |
| 1925 // been packed into a single stream frame from one stream. | 1927 // been packed into a single stream frame from one stream. |
| 1926 EXPECT_EQ(1u, writer_->frame_count()); | 1928 EXPECT_EQ(1u, writer_->frame_count()); |
| 1927 EXPECT_EQ(1u, writer_->stream_frames().size()); | 1929 EXPECT_EQ(1u, writer_->stream_frames().size()); |
| 1928 QuicStreamFrame frame = writer_->stream_frames()[0]; | 1930 QuicStreamFrame frame = writer_->stream_frames()[0]; |
| 1929 EXPECT_EQ(1u, frame.stream_id); | 1931 EXPECT_EQ(1u, frame.stream_id); |
| 1930 EXPECT_EQ("ABCD", string(static_cast<char*> | 1932 EXPECT_EQ("ABCD", std::string(static_cast<char*> |
| 1931 (frame.data.iovec()[0].iov_base), | 1933 (frame.data.iovec()[0].iov_base), |
| 1932 (frame.data.iovec()[0].iov_len))); | 1934 (frame.data.iovec()[0].iov_len))); |
| 1933 } | 1935 } |
| 1934 | 1936 |
| 1935 TEST_P(QuicConnectionTest, FramePackingSendvQueued) { | 1937 TEST_P(QuicConnectionTest, FramePackingSendvQueued) { |
| 1936 // Try to send two stream frames in 1 packet by using writev. | 1938 // Try to send two stream frames in 1 packet by using writev. |
| 1937 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)); | 1939 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)); |
| 1938 | 1940 |
| 1939 BlockOnNextWrite(); | 1941 BlockOnNextWrite(); |
| 1940 char data[] = "ABCD"; | 1942 char data[] = "ABCD"; |
| (...skipping 1105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3046 connection_.version(), kIncludeVersion, | 3048 connection_.version(), kIncludeVersion, |
| 3047 PACKET_8BYTE_CONNECTION_ID, PACKET_1BYTE_SEQUENCE_NUMBER, | 3049 PACKET_8BYTE_CONNECTION_ID, PACKET_1BYTE_SEQUENCE_NUMBER, |
| 3048 NOT_IN_FEC_GROUP, &payload_length); | 3050 NOT_IN_FEC_GROUP, &payload_length); |
| 3049 QuicConnectionPeer::GetPacketCreator(&connection_)->set_max_packet_length( | 3051 QuicConnectionPeer::GetPacketCreator(&connection_)->set_max_packet_length( |
| 3050 length); | 3052 length); |
| 3051 | 3053 |
| 3052 // Queue the first packet. | 3054 // Queue the first packet. |
| 3053 EXPECT_CALL(*send_algorithm_, | 3055 EXPECT_CALL(*send_algorithm_, |
| 3054 TimeUntilSend(_, _, _)).WillOnce( | 3056 TimeUntilSend(_, _, _)).WillOnce( |
| 3055 testing::Return(QuicTime::Delta::FromMicroseconds(10))); | 3057 testing::Return(QuicTime::Delta::FromMicroseconds(10))); |
| 3056 const string payload(payload_length, 'a'); | 3058 const std::string payload(payload_length, 'a'); |
| 3057 EXPECT_EQ(0u, connection_.SendStreamDataWithString(3, payload, 0, !kFin, | 3059 EXPECT_EQ(0u, connection_.SendStreamDataWithString(3, payload, 0, !kFin, |
| 3058 nullptr).bytes_consumed); | 3060 nullptr).bytes_consumed); |
| 3059 EXPECT_EQ(0u, connection_.NumQueuedPackets()); | 3061 EXPECT_EQ(0u, connection_.NumQueuedPackets()); |
| 3060 } | 3062 } |
| 3061 | 3063 |
| 3062 TEST_P(QuicConnectionTest, LoopThroughSendingPackets) { | 3064 TEST_P(QuicConnectionTest, LoopThroughSendingPackets) { |
| 3063 // All packets carry version info till version is negotiated. | 3065 // All packets carry version info till version is negotiated. |
| 3064 size_t payload_length; | 3066 size_t payload_length; |
| 3065 // GetPacketLengthForOneStream() assumes a stream offset of 0 in determining | 3067 // GetPacketLengthForOneStream() assumes a stream offset of 0 in determining |
| 3066 // packet length. The size of the offset field in a stream frame is 0 for | 3068 // packet length. The size of the offset field in a stream frame is 0 for |
| 3067 // offset 0, and 2 for non-zero offsets up through 16K. Increase | 3069 // offset 0, and 2 for non-zero offsets up through 16K. Increase |
| 3068 // max_packet_length by 2 so that subsequent packets containing subsequent | 3070 // max_packet_length by 2 so that subsequent packets containing subsequent |
| 3069 // stream frames with non-zero offets will fit within the packet length. | 3071 // stream frames with non-zero offets will fit within the packet length. |
| 3070 size_t length = 2 + GetPacketLengthForOneStream( | 3072 size_t length = 2 + GetPacketLengthForOneStream( |
| 3071 connection_.version(), kIncludeVersion, | 3073 connection_.version(), kIncludeVersion, |
| 3072 PACKET_8BYTE_CONNECTION_ID, PACKET_1BYTE_SEQUENCE_NUMBER, | 3074 PACKET_8BYTE_CONNECTION_ID, PACKET_1BYTE_SEQUENCE_NUMBER, |
| 3073 NOT_IN_FEC_GROUP, &payload_length); | 3075 NOT_IN_FEC_GROUP, &payload_length); |
| 3074 QuicConnectionPeer::GetPacketCreator(&connection_)->set_max_packet_length( | 3076 QuicConnectionPeer::GetPacketCreator(&connection_)->set_max_packet_length( |
| 3075 length); | 3077 length); |
| 3076 | 3078 |
| 3077 // Queue the first packet. | 3079 // Queue the first packet. |
| 3078 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(7); | 3080 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(7); |
| 3079 // The first stream frame will have 2 fewer overhead bytes than the other six. | 3081 // The first stream frame will have 2 fewer overhead bytes than the other six. |
| 3080 const string payload(payload_length * 7 + 2, 'a'); | 3082 const std::string payload(payload_length * 7 + 2, 'a'); |
| 3081 EXPECT_EQ(payload.size(), | 3083 EXPECT_EQ(payload.size(), |
| 3082 connection_.SendStreamDataWithString(1, payload, 0, !kFin, nullptr) | 3084 connection_.SendStreamDataWithString(1, payload, 0, !kFin, nullptr) |
| 3083 .bytes_consumed); | 3085 .bytes_consumed); |
| 3084 } | 3086 } |
| 3085 | 3087 |
| 3086 TEST_P(QuicConnectionTest, LoopThroughSendingPacketsWithTruncation) { | 3088 TEST_P(QuicConnectionTest, LoopThroughSendingPacketsWithTruncation) { |
| 3087 ValueRestore<bool> old_flag(&FLAGS_allow_truncated_connection_ids_for_quic, | 3089 ValueRestore<bool> old_flag(&FLAGS_allow_truncated_connection_ids_for_quic, |
| 3088 true); | 3090 true); |
| 3089 | 3091 |
| 3090 // Set up a larger payload than will fit in one packet. | 3092 // Set up a larger payload than will fit in one packet. |
| 3091 const string payload(connection_.max_packet_length(), 'a'); | 3093 const std::string payload(connection_.max_packet_length(), 'a'); |
| 3092 EXPECT_CALL(*send_algorithm_, SetFromConfig(_, _, _)).Times(AnyNumber()); | 3094 EXPECT_CALL(*send_algorithm_, SetFromConfig(_, _, _)).Times(AnyNumber()); |
| 3093 | 3095 |
| 3094 // Now send some packets with no truncation. | 3096 // Now send some packets with no truncation. |
| 3095 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(2); | 3097 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(2); |
| 3096 EXPECT_EQ(payload.size(), | 3098 EXPECT_EQ(payload.size(), |
| 3097 connection_.SendStreamDataWithString( | 3099 connection_.SendStreamDataWithString( |
| 3098 3, payload, 0, !kFin, nullptr).bytes_consumed); | 3100 3, payload, 0, !kFin, nullptr).bytes_consumed); |
| 3099 // Track the size of the second packet here. The overhead will be the largest | 3101 // Track the size of the second packet here. The overhead will be the largest |
| 3100 // we see in this test, due to the non-truncated CID. | 3102 // we see in this test, due to the non-truncated CID. |
| 3101 size_t non_truncated_packet_size = writer_->last_packet_size(); | 3103 size_t non_truncated_packet_size = writer_->last_packet_size(); |
| (...skipping 1090 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4192 QuicBlockedFrame blocked; | 4194 QuicBlockedFrame blocked; |
| 4193 blocked.stream_id = 3; | 4195 blocked.stream_id = 3; |
| 4194 EXPECT_CALL(visitor_, OnBlockedFrames(_)); | 4196 EXPECT_CALL(visitor_, OnBlockedFrames(_)); |
| 4195 ProcessFramePacket(QuicFrame(&blocked)); | 4197 ProcessFramePacket(QuicFrame(&blocked)); |
| 4196 EXPECT_TRUE(ack_alarm->IsSet()); | 4198 EXPECT_TRUE(ack_alarm->IsSet()); |
| 4197 } | 4199 } |
| 4198 | 4200 |
| 4199 } // namespace | 4201 } // namespace |
| 4200 } // namespace test | 4202 } // namespace test |
| 4201 } // namespace net | 4203 } // namespace net |
| OLD | NEW |