Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(20)

Side by Side Diff: net/quic/quic_connection_test.cc

Issue 687033002: Adding an option for peers to negotiate the length of the QUIC (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@Final_1028
Patch Set: Created 6 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « net/quic/quic_connection.cc ('k') | net/quic/quic_flags.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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" 12 #include "net/quic/congestion_control/receive_algorithm_interface.h"
13 #include "net/quic/congestion_control/send_algorithm_interface.h" 13 #include "net/quic/congestion_control/send_algorithm_interface.h"
14 #include "net/quic/crypto/null_encrypter.h" 14 #include "net/quic/crypto/null_encrypter.h"
15 #include "net/quic/crypto/quic_decrypter.h" 15 #include "net/quic/crypto/quic_decrypter.h"
16 #include "net/quic/crypto/quic_encrypter.h" 16 #include "net/quic/crypto/quic_encrypter.h"
17 #include "net/quic/quic_flags.h" 17 #include "net/quic/quic_flags.h"
18 #include "net/quic/quic_protocol.h" 18 #include "net/quic/quic_protocol.h"
19 #include "net/quic/quic_utils.h" 19 #include "net/quic/quic_utils.h"
20 #include "net/quic/test_tools/mock_clock.h" 20 #include "net/quic/test_tools/mock_clock.h"
21 #include "net/quic/test_tools/mock_random.h" 21 #include "net/quic/test_tools/mock_random.h"
22 #include "net/quic/test_tools/quic_config_peer.h"
22 #include "net/quic/test_tools/quic_connection_peer.h" 23 #include "net/quic/test_tools/quic_connection_peer.h"
23 #include "net/quic/test_tools/quic_framer_peer.h" 24 #include "net/quic/test_tools/quic_framer_peer.h"
24 #include "net/quic/test_tools/quic_packet_creator_peer.h" 25 #include "net/quic/test_tools/quic_packet_creator_peer.h"
25 #include "net/quic/test_tools/quic_sent_packet_manager_peer.h" 26 #include "net/quic/test_tools/quic_sent_packet_manager_peer.h"
26 #include "net/quic/test_tools/quic_test_utils.h" 27 #include "net/quic/test_tools/quic_test_utils.h"
27 #include "net/quic/test_tools/simple_quic_framer.h" 28 #include "net/quic/test_tools/simple_quic_framer.h"
28 #include "testing/gmock/include/gmock/gmock.h" 29 #include "testing/gmock/include/gmock/gmock.h"
29 #include "testing/gtest/include/gtest/gtest.h" 30 #include "testing/gtest/include/gtest/gtest.h"
30 31
31 using base::StringPiece; 32 using base::StringPiece;
(...skipping 1475 matching lines...) Expand 10 before | Expand all | Expand 10 after
1507 // All packets carry version info till version is negotiated. 1508 // All packets carry version info till version is negotiated.
1508 QuicPacketCreator* creator = 1509 QuicPacketCreator* creator =
1509 QuicConnectionPeer::GetPacketCreator(&connection_); 1510 QuicConnectionPeer::GetPacketCreator(&connection_);
1510 size_t payload_length; 1511 size_t payload_length;
1511 // GetPacketLengthForOneStream() assumes a stream offset of 0 in determining 1512 // GetPacketLengthForOneStream() assumes a stream offset of 0 in determining
1512 // packet length. The size of the offset field in a stream frame is 0 for 1513 // packet length. The size of the offset field in a stream frame is 0 for
1513 // offset 0, and 2 for non-zero offsets up through 64K. Increase 1514 // offset 0, and 2 for non-zero offsets up through 64K. Increase
1514 // max_packet_length by 2 so that subsequent packets containing subsequent 1515 // max_packet_length by 2 so that subsequent packets containing subsequent
1515 // stream frames with non-zero offets will fit within the packet length. 1516 // stream frames with non-zero offets will fit within the packet length.
1516 size_t length = 2 + GetPacketLengthForOneStream( 1517 size_t length = 2 + GetPacketLengthForOneStream(
1517 connection_.version(), kIncludeVersion, PACKET_1BYTE_SEQUENCE_NUMBER, 1518 connection_.version(), kIncludeVersion,
1519 PACKET_8BYTE_CONNECTION_ID, PACKET_1BYTE_SEQUENCE_NUMBER,
1518 IN_FEC_GROUP, &payload_length); 1520 IN_FEC_GROUP, &payload_length);
1519 creator->set_max_packet_length(length); 1521 creator->set_max_packet_length(length);
1520 1522
1521 // Send 4 protected data packets, which should also trigger 1 FEC packet. 1523 // Send 4 protected data packets, which should also trigger 1 FEC packet.
1522 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(5); 1524 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(5);
1523 // The first stream frame will have 2 fewer overhead bytes than the other 3. 1525 // The first stream frame will have 2 fewer overhead bytes than the other 3.
1524 const string payload(payload_length * 4 + 2, 'a'); 1526 const string payload(payload_length * 4 + 2, 'a');
1525 connection_.SendStreamDataWithStringWithFec(1, payload, 0, !kFin, nullptr); 1527 connection_.SendStreamDataWithStringWithFec(1, payload, 0, !kFin, nullptr);
1526 // Expect the FEC group to be closed after SendStreamDataWithString. 1528 // Expect the FEC group to be closed after SendStreamDataWithString.
1527 EXPECT_FALSE(creator->IsFecGroupOpen()); 1529 EXPECT_FALSE(creator->IsFecGroupOpen());
1528 EXPECT_FALSE(creator->IsFecProtected()); 1530 EXPECT_FALSE(creator->IsFecProtected());
1529 } 1531 }
1530 1532
1531 TEST_P(QuicConnectionTest, FECQueueing) { 1533 TEST_P(QuicConnectionTest, FECQueueing) {
1532 // All packets carry version info till version is negotiated. 1534 // All packets carry version info till version is negotiated.
1533 size_t payload_length; 1535 size_t payload_length;
1534 QuicPacketCreator* creator = 1536 QuicPacketCreator* creator =
1535 QuicConnectionPeer::GetPacketCreator(&connection_); 1537 QuicConnectionPeer::GetPacketCreator(&connection_);
1536 size_t length = GetPacketLengthForOneStream( 1538 size_t length = GetPacketLengthForOneStream(
1537 connection_.version(), kIncludeVersion, PACKET_1BYTE_SEQUENCE_NUMBER, 1539 connection_.version(), kIncludeVersion,
1540 PACKET_8BYTE_CONNECTION_ID, PACKET_1BYTE_SEQUENCE_NUMBER,
1538 IN_FEC_GROUP, &payload_length); 1541 IN_FEC_GROUP, &payload_length);
1539 creator->set_max_packet_length(length); 1542 creator->set_max_packet_length(length);
1540 EXPECT_TRUE(creator->IsFecEnabled()); 1543 EXPECT_TRUE(creator->IsFecEnabled());
1541 1544
1542 EXPECT_EQ(0u, connection_.NumQueuedPackets()); 1545 EXPECT_EQ(0u, connection_.NumQueuedPackets());
1543 BlockOnNextWrite(); 1546 BlockOnNextWrite();
1544 const string payload(payload_length, 'a'); 1547 const string payload(payload_length, 'a');
1545 connection_.SendStreamDataWithStringWithFec(1, payload, 0, !kFin, nullptr); 1548 connection_.SendStreamDataWithStringWithFec(1, payload, 0, !kFin, nullptr);
1546 EXPECT_FALSE(creator->IsFecGroupOpen()); 1549 EXPECT_FALSE(creator->IsFecGroupOpen());
1547 EXPECT_FALSE(creator->IsFecProtected()); 1550 EXPECT_FALSE(creator->IsFecProtected());
(...skipping 1351 matching lines...) Expand 10 before | Expand all | Expand 10 after
2899 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, 1, _, _)).Times(0); 2902 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, 1, _, _)).Times(0);
2900 connection_.SendPacket( 2903 connection_.SendPacket(
2901 ENCRYPTION_NONE, 1, packet, kTestEntropyHash, HAS_RETRANSMITTABLE_DATA); 2904 ENCRYPTION_NONE, 1, packet, kTestEntropyHash, HAS_RETRANSMITTABLE_DATA);
2902 EXPECT_EQ(1u, connection_.NumQueuedPackets()); 2905 EXPECT_EQ(1u, connection_.NumQueuedPackets());
2903 } 2906 }
2904 2907
2905 TEST_P(QuicConnectionTest, TestQueueLimitsOnSendStreamData) { 2908 TEST_P(QuicConnectionTest, TestQueueLimitsOnSendStreamData) {
2906 // All packets carry version info till version is negotiated. 2909 // All packets carry version info till version is negotiated.
2907 size_t payload_length; 2910 size_t payload_length;
2908 size_t length = GetPacketLengthForOneStream( 2911 size_t length = GetPacketLengthForOneStream(
2909 connection_.version(), kIncludeVersion, PACKET_1BYTE_SEQUENCE_NUMBER, 2912 connection_.version(), kIncludeVersion,
2913 PACKET_8BYTE_CONNECTION_ID, PACKET_1BYTE_SEQUENCE_NUMBER,
2910 NOT_IN_FEC_GROUP, &payload_length); 2914 NOT_IN_FEC_GROUP, &payload_length);
2911 QuicConnectionPeer::GetPacketCreator(&connection_)->set_max_packet_length( 2915 QuicConnectionPeer::GetPacketCreator(&connection_)->set_max_packet_length(
2912 length); 2916 length);
2913 2917
2914 // Queue the first packet. 2918 // Queue the first packet.
2915 EXPECT_CALL(*send_algorithm_, 2919 EXPECT_CALL(*send_algorithm_,
2916 TimeUntilSend(_, _, _)).WillOnce( 2920 TimeUntilSend(_, _, _)).WillOnce(
2917 testing::Return(QuicTime::Delta::FromMicroseconds(10))); 2921 testing::Return(QuicTime::Delta::FromMicroseconds(10)));
2918 const string payload(payload_length, 'a'); 2922 const string payload(payload_length, 'a');
2919 EXPECT_EQ(0u, connection_.SendStreamDataWithString(3, payload, 0, !kFin, 2923 EXPECT_EQ(0u, connection_.SendStreamDataWithString(3, payload, 0, !kFin,
2920 nullptr).bytes_consumed); 2924 nullptr).bytes_consumed);
2921 EXPECT_EQ(0u, connection_.NumQueuedPackets()); 2925 EXPECT_EQ(0u, connection_.NumQueuedPackets());
2922 } 2926 }
2923 2927
2924 TEST_P(QuicConnectionTest, LoopThroughSendingPackets) { 2928 TEST_P(QuicConnectionTest, LoopThroughSendingPackets) {
2925 // All packets carry version info till version is negotiated. 2929 // All packets carry version info till version is negotiated.
2926 size_t payload_length; 2930 size_t payload_length;
2927 // GetPacketLengthForOneStream() assumes a stream offset of 0 in determining 2931 // GetPacketLengthForOneStream() assumes a stream offset of 0 in determining
2928 // packet length. The size of the offset field in a stream frame is 0 for 2932 // packet length. The size of the offset field in a stream frame is 0 for
2929 // offset 0, and 2 for non-zero offsets up through 16K. Increase 2933 // offset 0, and 2 for non-zero offsets up through 16K. Increase
2930 // max_packet_length by 2 so that subsequent packets containing subsequent 2934 // max_packet_length by 2 so that subsequent packets containing subsequent
2931 // stream frames with non-zero offets will fit within the packet length. 2935 // stream frames with non-zero offets will fit within the packet length.
2932 size_t length = 2 + GetPacketLengthForOneStream( 2936 size_t length = 2 + GetPacketLengthForOneStream(
2933 connection_.version(), kIncludeVersion, PACKET_1BYTE_SEQUENCE_NUMBER, 2937 connection_.version(), kIncludeVersion,
2938 PACKET_8BYTE_CONNECTION_ID, PACKET_1BYTE_SEQUENCE_NUMBER,
2934 NOT_IN_FEC_GROUP, &payload_length); 2939 NOT_IN_FEC_GROUP, &payload_length);
2935 QuicConnectionPeer::GetPacketCreator(&connection_)->set_max_packet_length( 2940 QuicConnectionPeer::GetPacketCreator(&connection_)->set_max_packet_length(
2936 length); 2941 length);
2937 2942
2938 // Queue the first packet. 2943 // Queue the first packet.
2939 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(7); 2944 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(7);
2940 // The first stream frame will have 2 fewer overhead bytes than the other six. 2945 // The first stream frame will have 2 fewer overhead bytes than the other six.
2941 const string payload(payload_length * 7 + 2, 'a'); 2946 const string payload(payload_length * 7 + 2, 'a');
2942 EXPECT_EQ(payload.size(), 2947 EXPECT_EQ(payload.size(),
2943 connection_.SendStreamDataWithString(1, payload, 0, !kFin, nullptr) 2948 connection_.SendStreamDataWithString(1, payload, 0, !kFin, nullptr)
2944 .bytes_consumed); 2949 .bytes_consumed);
2945 } 2950 }
2946 2951
2952 TEST_P(QuicConnectionTest, LoopThroughSendingPacketsWithTruncation) {
2953 ValueRestore<bool> old_flag(&FLAGS_allow_truncated_connection_ids_for_quic,
2954 true);
2955
2956 // Set up a larger payload than will fit in one packet.
2957 const string payload(connection_.max_packet_length(), 'a');
2958 EXPECT_CALL(*send_algorithm_, SetFromConfig(_, _)).Times(AnyNumber());
2959
2960 // Now send some packets with no truncation.
2961 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(2);
2962 EXPECT_EQ(payload.size(),
2963 connection_.SendStreamDataWithString(
2964 3, payload, 0, !kFin, nullptr).bytes_consumed);
2965 // Track the size of the second packet here. The overhead will be the largest
2966 // we see in this test, due to the non-truncated CID.
2967 size_t non_truncated_packet_size = writer_->last_packet_size();
2968
2969 // Change to a 4 byte CID.
2970 QuicConfig config;
2971 QuicConfigPeer::SetReceivedBytesForConnectionId(&config, 4);
2972 connection_.SetFromConfig(config);
2973 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(2);
2974 EXPECT_EQ(payload.size(),
2975 connection_.SendStreamDataWithString(
2976 3, payload, 0, !kFin, nullptr).bytes_consumed);
2977 // Verify that we have 8 fewer bytes than in the non-truncated case. The
2978 // first packet got 4 bytes of extra payload due to the truncation, and the
2979 // headers here are also 4 byte smaller.
2980 EXPECT_EQ(non_truncated_packet_size, writer_->last_packet_size() + 8);
2981
2982
2983 // Change to a 1 byte CID.
2984 QuicConfigPeer::SetReceivedBytesForConnectionId(&config, 1);
2985 connection_.SetFromConfig(config);
2986 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(2);
2987 EXPECT_EQ(payload.size(),
2988 connection_.SendStreamDataWithString(
2989 3, payload, 0, !kFin, nullptr).bytes_consumed);
2990 // Just like above, we save 7 bytes on payload, and 7 on truncation.
2991 EXPECT_EQ(non_truncated_packet_size, writer_->last_packet_size() + 7 * 2);
2992
2993 // Change to a 0 byte CID.
2994 QuicConfigPeer::SetReceivedBytesForConnectionId(&config, 0);
2995 connection_.SetFromConfig(config);
2996 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(2);
2997 EXPECT_EQ(payload.size(),
2998 connection_.SendStreamDataWithString(
2999 3, payload, 0, !kFin, nullptr).bytes_consumed);
3000 // Just like above, we save 8 bytes on payload, and 8 on truncation.
3001 EXPECT_EQ(non_truncated_packet_size, writer_->last_packet_size() + 8 * 2);
3002 }
3003
2947 TEST_P(QuicConnectionTest, SendDelayedAck) { 3004 TEST_P(QuicConnectionTest, SendDelayedAck) {
2948 QuicTime ack_time = clock_.ApproximateNow().Add(DefaultDelayedAckTime()); 3005 QuicTime ack_time = clock_.ApproximateNow().Add(DefaultDelayedAckTime());
2949 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); 3006 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_));
2950 EXPECT_FALSE(connection_.GetAckAlarm()->IsSet()); 3007 EXPECT_FALSE(connection_.GetAckAlarm()->IsSet());
2951 const uint8 tag = 0x07; 3008 const uint8 tag = 0x07;
2952 connection_.SetDecrypter(new StrictTaggingDecrypter(tag), 3009 connection_.SetDecrypter(new StrictTaggingDecrypter(tag),
2953 ENCRYPTION_INITIAL); 3010 ENCRYPTION_INITIAL);
2954 framer_.SetEncrypter(ENCRYPTION_INITIAL, new TaggingEncrypter(tag)); 3011 framer_.SetEncrypter(ENCRYPTION_INITIAL, new TaggingEncrypter(tag));
2955 // Process a packet from the non-crypto stream. 3012 // Process a packet from the non-crypto stream.
2956 frame1_.stream_id = 3; 3013 frame1_.stream_id = 3;
(...skipping 1050 matching lines...) Expand 10 before | Expand all | Expand 10 after
4007 QuicBlockedFrame blocked; 4064 QuicBlockedFrame blocked;
4008 blocked.stream_id = 3; 4065 blocked.stream_id = 3;
4009 EXPECT_CALL(visitor_, OnBlockedFrames(_)); 4066 EXPECT_CALL(visitor_, OnBlockedFrames(_));
4010 ProcessFramePacket(QuicFrame(&blocked)); 4067 ProcessFramePacket(QuicFrame(&blocked));
4011 EXPECT_TRUE(ack_alarm->IsSet()); 4068 EXPECT_TRUE(ack_alarm->IsSet());
4012 } 4069 }
4013 4070
4014 } // namespace 4071 } // namespace
4015 } // namespace test 4072 } // namespace test
4016 } // namespace net 4073 } // namespace net
OLDNEW
« no previous file with comments | « net/quic/quic_connection.cc ('k') | net/quic/quic_flags.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698