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

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

Issue 420313005: Land Recent QUIC Changes. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@Final_0723
Patch Set: change QUIC packet size to 1350 Created 6 years, 4 months 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
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_packet_creator.h" 5 #include "net/quic/quic_packet_creator.h"
6 6
7 #include "base/stl_util.h" 7 #include "base/stl_util.h"
8 #include "net/quic/crypto/null_encrypter.h" 8 #include "net/quic/crypto/null_encrypter.h"
9 #include "net/quic/crypto/quic_decrypter.h" 9 #include "net/quic/crypto/quic_decrypter.h"
10 #include "net/quic/crypto/quic_encrypter.h" 10 #include "net/quic/crypto/quic_encrypter.h"
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after
111 // Returns the number of bytes of overhead that will be added to a packet 111 // Returns the number of bytes of overhead that will be added to a packet
112 // of maximum length. 112 // of maximum length.
113 size_t GetEncryptionOverhead() { 113 size_t GetEncryptionOverhead() {
114 return creator_.max_packet_length() - client_framer_.GetMaxPlaintextSize( 114 return creator_.max_packet_length() - client_framer_.GetMaxPlaintextSize(
115 creator_.max_packet_length()); 115 creator_.max_packet_length());
116 } 116 }
117 117
118 // Returns the number of bytes consumed by the non-data fields of a stream 118 // Returns the number of bytes consumed by the non-data fields of a stream
119 // frame, assuming it is the last frame in the packet 119 // frame, assuming it is the last frame in the packet
120 size_t GetStreamFrameOverhead(InFecGroup is_in_fec_group) { 120 size_t GetStreamFrameOverhead(InFecGroup is_in_fec_group) {
121 return QuicFramer::GetMinStreamFrameSize(client_framer_.version(), 121 return QuicFramer::GetMinStreamFrameSize(kClientDataStreamId1, kOffset,
122 kClientDataStreamId1, kOffset,
123 true, is_in_fec_group); 122 true, is_in_fec_group);
124 } 123 }
125 124
126 // Enables and turns on FEC protection. Returns true if FEC protection is on. 125 // Enables and turns on FEC protection. Returns true if FEC protection is on.
127 bool SwitchFecProtectionOn(size_t max_packets_per_fec_group) { 126 bool SwitchFecProtectionOn(size_t max_packets_per_fec_group) {
128 creator_.set_max_packets_per_fec_group(max_packets_per_fec_group); 127 creator_.set_max_packets_per_fec_group(max_packets_per_fec_group);
129 creator_.StartFecProtectingPackets(); 128 creator_.StartFecProtectingPackets();
130 return creator_.IsFecProtected(); 129 return creator_.IsFecProtected();
131 } 130 }
132 131
(...skipping 11 matching lines...) Expand all
144 MockEntropyCalculator entropy_calculator_; 143 MockEntropyCalculator entropy_calculator_;
145 }; 144 };
146 145
147 // Run all packet creator tests with all supported versions of QUIC, and with 146 // Run all packet creator tests with all supported versions of QUIC, and with
148 // and without version in the packet header. 147 // and without version in the packet header.
149 INSTANTIATE_TEST_CASE_P(QuicPacketCreatorTests, 148 INSTANTIATE_TEST_CASE_P(QuicPacketCreatorTests,
150 QuicPacketCreatorTest, 149 QuicPacketCreatorTest,
151 ::testing::ValuesIn(GetTestParams())); 150 ::testing::ValuesIn(GetTestParams()));
152 151
153 TEST_P(QuicPacketCreatorTest, SerializeFrames) { 152 TEST_P(QuicPacketCreatorTest, SerializeFrames) {
154 frames_.push_back(QuicFrame(new QuicAckFrame(MakeAckFrame(0u, 0u)))); 153 frames_.push_back(QuicFrame(new QuicAckFrame(MakeAckFrame(0u))));
155 frames_.push_back(QuicFrame(new QuicStreamFrame(0u, false, 0u, IOVector()))); 154 frames_.push_back(QuicFrame(new QuicStreamFrame(0u, false, 0u, IOVector())));
156 frames_.push_back(QuicFrame(new QuicStreamFrame(0u, true, 0u, IOVector()))); 155 frames_.push_back(QuicFrame(new QuicStreamFrame(0u, true, 0u, IOVector())));
157 SerializedPacket serialized = creator_.SerializeAllFrames(frames_); 156 SerializedPacket serialized = creator_.SerializeAllFrames(frames_);
158 delete frames_[0].ack_frame; 157 delete frames_[0].ack_frame;
159 delete frames_[1].stream_frame; 158 delete frames_[1].stream_frame;
160 delete frames_[2].stream_frame; 159 delete frames_[2].stream_frame;
161 160
162 { 161 {
163 InSequence s; 162 InSequence s;
164 EXPECT_CALL(framer_visitor_, OnPacket()); 163 EXPECT_CALL(framer_visitor_, OnPacket());
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
216 EXPECT_CALL(framer_visitor_, OnDecryptedPacket(_)); 215 EXPECT_CALL(framer_visitor_, OnDecryptedPacket(_));
217 EXPECT_CALL(framer_visitor_, OnPacketHeader(_)); 216 EXPECT_CALL(framer_visitor_, OnPacketHeader(_));
218 EXPECT_CALL(framer_visitor_, OnFecData(_)); 217 EXPECT_CALL(framer_visitor_, OnFecData(_));
219 EXPECT_CALL(framer_visitor_, OnPacketComplete()); 218 EXPECT_CALL(framer_visitor_, OnPacketComplete());
220 } 219 }
221 ProcessPacket(serialized.packet); 220 ProcessPacket(serialized.packet);
222 delete serialized.packet; 221 delete serialized.packet;
223 } 222 }
224 223
225 TEST_P(QuicPacketCreatorTest, SerializeChangingSequenceNumberLength) { 224 TEST_P(QuicPacketCreatorTest, SerializeChangingSequenceNumberLength) {
226 frames_.push_back(QuicFrame(new QuicAckFrame(MakeAckFrame(0u, 0u)))); 225 frames_.push_back(QuicFrame(new QuicAckFrame(MakeAckFrame(0u))));
227 creator_.AddSavedFrame(frames_[0]); 226 creator_.AddSavedFrame(frames_[0]);
228 creator_.set_next_sequence_number_length(PACKET_4BYTE_SEQUENCE_NUMBER); 227 creator_.set_next_sequence_number_length(PACKET_4BYTE_SEQUENCE_NUMBER);
229 SerializedPacket serialized = creator_.SerializePacket(); 228 SerializedPacket serialized = creator_.SerializePacket();
230 // The sequence number length will not change mid-packet. 229 // The sequence number length will not change mid-packet.
231 EXPECT_EQ(PACKET_1BYTE_SEQUENCE_NUMBER, serialized.sequence_number_length); 230 EXPECT_EQ(PACKET_1BYTE_SEQUENCE_NUMBER, serialized.sequence_number_length);
232 231
233 { 232 {
234 InSequence s; 233 InSequence s;
235 EXPECT_CALL(framer_visitor_, OnPacket()); 234 EXPECT_CALL(framer_visitor_, OnPacket());
236 EXPECT_CALL(framer_visitor_, OnUnauthenticatedPublicHeader(_)); 235 EXPECT_CALL(framer_visitor_, OnUnauthenticatedPublicHeader(_));
(...skipping 20 matching lines...) Expand all
257 EXPECT_CALL(framer_visitor_, OnDecryptedPacket(_)); 256 EXPECT_CALL(framer_visitor_, OnDecryptedPacket(_));
258 EXPECT_CALL(framer_visitor_, OnPacketHeader(_)); 257 EXPECT_CALL(framer_visitor_, OnPacketHeader(_));
259 EXPECT_CALL(framer_visitor_, OnAckFrame(_)); 258 EXPECT_CALL(framer_visitor_, OnAckFrame(_));
260 EXPECT_CALL(framer_visitor_, OnPacketComplete()); 259 EXPECT_CALL(framer_visitor_, OnPacketComplete());
261 } 260 }
262 ProcessPacket(serialized.packet); 261 ProcessPacket(serialized.packet);
263 delete serialized.packet; 262 delete serialized.packet;
264 } 263 }
265 264
266 TEST_P(QuicPacketCreatorTest, ChangeSequenceNumberLengthMidPacket) { 265 TEST_P(QuicPacketCreatorTest, ChangeSequenceNumberLengthMidPacket) {
267 if (GetParam().version <= QUIC_VERSION_15) {
268 return;
269 }
270 // Changing the sequence number length with queued frames in the creator 266 // Changing the sequence number length with queued frames in the creator
271 // should hold the change until after any currently queued frames are 267 // should hold the change until after any currently queued frames are
272 // serialized. 268 // serialized.
273 269
274 // Packet 1. 270 // Packet 1.
275 // Queue a frame in the creator. 271 // Queue a frame in the creator.
276 EXPECT_FALSE(creator_.HasPendingFrames()); 272 EXPECT_FALSE(creator_.HasPendingFrames());
277 QuicFrame ack_frame = QuicFrame(new QuicAckFrame(MakeAckFrame(0u, 0u))); 273 QuicFrame ack_frame = QuicFrame(new QuicAckFrame(MakeAckFrame(0u)));
278 creator_.AddSavedFrame(ack_frame); 274 creator_.AddSavedFrame(ack_frame);
279 275
280 // Now change sequence number length. 276 // Now change sequence number length.
281 creator_.set_next_sequence_number_length(PACKET_4BYTE_SEQUENCE_NUMBER); 277 creator_.set_next_sequence_number_length(PACKET_4BYTE_SEQUENCE_NUMBER);
282 278
283 // Add a STOP_WAITING frame since it contains a packet sequence number, 279 // Add a STOP_WAITING frame since it contains a packet sequence number,
284 // whose length should be 1. 280 // whose length should be 1.
285 QuicStopWaitingFrame stop_waiting_frame; 281 QuicStopWaitingFrame stop_waiting_frame;
286 EXPECT_TRUE(creator_.AddSavedFrame(QuicFrame(&stop_waiting_frame))); 282 EXPECT_TRUE(creator_.AddSavedFrame(QuicFrame(&stop_waiting_frame)));
287 EXPECT_TRUE(creator_.HasPendingFrames()); 283 EXPECT_TRUE(creator_.HasPendingFrames());
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
346 // Test goal is to test the following sequence (P1 => generate Packet 1): 342 // Test goal is to test the following sequence (P1 => generate Packet 1):
347 // P1 <change seq num length> P2 FEC, 343 // P1 <change seq num length> P2 FEC,
348 // and we expect that sequence number length should not change until the end 344 // and we expect that sequence number length should not change until the end
349 // of the open FEC group. 345 // of the open FEC group.
350 346
351 // Enable FEC protection, and send FEC packet every 6 packets. 347 // Enable FEC protection, and send FEC packet every 6 packets.
352 EXPECT_TRUE(SwitchFecProtectionOn(6)); 348 EXPECT_TRUE(SwitchFecProtectionOn(6));
353 // Should return false since we do not have enough packets in the FEC group to 349 // Should return false since we do not have enough packets in the FEC group to
354 // trigger an FEC packet. 350 // trigger an FEC packet.
355 ASSERT_FALSE(creator_.ShouldSendFec(/*force_close=*/false)); 351 ASSERT_FALSE(creator_.ShouldSendFec(/*force_close=*/false));
356 frames_.push_back(QuicFrame(new QuicAckFrame(MakeAckFrame(0u, 0u)))); 352 frames_.push_back(QuicFrame(new QuicAckFrame(MakeAckFrame(0u))));
357 353
358 // Generate Packet 1. 354 // Generate Packet 1.
359 creator_.AddSavedFrame(frames_[0]); 355 creator_.AddSavedFrame(frames_[0]);
360 // Change the sequence number length mid-FEC group and it should not change. 356 // Change the sequence number length mid-FEC group and it should not change.
361 creator_.set_next_sequence_number_length(PACKET_4BYTE_SEQUENCE_NUMBER); 357 creator_.set_next_sequence_number_length(PACKET_4BYTE_SEQUENCE_NUMBER);
362 SerializedPacket serialized = creator_.SerializePacket(); 358 SerializedPacket serialized = creator_.SerializePacket();
363 EXPECT_EQ(PACKET_1BYTE_SEQUENCE_NUMBER, serialized.sequence_number_length); 359 EXPECT_EQ(PACKET_1BYTE_SEQUENCE_NUMBER, serialized.sequence_number_length);
364 360
365 { 361 {
366 InSequence s; 362 InSequence s;
(...skipping 497 matching lines...) Expand 10 before | Expand all | Expand 10 after
864 client_framer_.GetMaxPlaintextSize(creator_.max_packet_length()); 860 client_framer_.GetMaxPlaintextSize(creator_.max_packet_length());
865 EXPECT_FALSE(creator_.HasPendingFrames()); 861 EXPECT_FALSE(creator_.HasPendingFrames());
866 EXPECT_EQ(max_plaintext_size - 862 EXPECT_EQ(max_plaintext_size -
867 GetPacketHeaderSize( 863 GetPacketHeaderSize(
868 creator_.connection_id_length(), 864 creator_.connection_id_length(),
869 QuicPacketCreatorPeer::SendVersionInPacket(&creator_), 865 QuicPacketCreatorPeer::SendVersionInPacket(&creator_),
870 PACKET_1BYTE_SEQUENCE_NUMBER, NOT_IN_FEC_GROUP), 866 PACKET_1BYTE_SEQUENCE_NUMBER, NOT_IN_FEC_GROUP),
871 creator_.BytesFree()); 867 creator_.BytesFree());
872 868
873 // Add a variety of frame types and then a padding frame. 869 // Add a variety of frame types and then a padding frame.
874 QuicAckFrame ack_frame(MakeAckFrame(0u, 0u)); 870 QuicAckFrame ack_frame(MakeAckFrame(0u));
875 EXPECT_TRUE(creator_.AddSavedFrame(QuicFrame(&ack_frame))); 871 EXPECT_TRUE(creator_.AddSavedFrame(QuicFrame(&ack_frame)));
876 EXPECT_TRUE(creator_.HasPendingFrames()); 872 EXPECT_TRUE(creator_.HasPendingFrames());
877 873
878 QuicCongestionFeedbackFrame congestion_feedback; 874 QuicCongestionFeedbackFrame congestion_feedback;
879 congestion_feedback.type = kFixRate; 875 congestion_feedback.type = kTCP;
876 congestion_feedback.tcp.receive_window = 0x4030;
880 EXPECT_TRUE(creator_.AddSavedFrame(QuicFrame(&congestion_feedback))); 877 EXPECT_TRUE(creator_.AddSavedFrame(QuicFrame(&congestion_feedback)));
881 EXPECT_TRUE(creator_.HasPendingFrames()); 878 EXPECT_TRUE(creator_.HasPendingFrames());
882 879
883 QuicFrame frame; 880 QuicFrame frame;
884 size_t consumed = creator_.CreateStreamFrame( 881 size_t consumed = creator_.CreateStreamFrame(
885 1u, MakeIOVector("test"), 0u, false, &frame); 882 1u, MakeIOVector("test"), 0u, false, &frame);
886 EXPECT_EQ(4u, consumed); 883 EXPECT_EQ(4u, consumed);
887 ASSERT_TRUE(frame.stream_frame); 884 ASSERT_TRUE(frame.stream_frame);
888 EXPECT_TRUE(creator_.AddSavedFrame(frame)); 885 EXPECT_TRUE(creator_.AddSavedFrame(frame));
889 EXPECT_TRUE(creator_.HasPendingFrames()); 886 EXPECT_TRUE(creator_.HasPendingFrames());
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after
1015 // After 64 calls, BoolSource will refresh the bucket - make sure it does. 1012 // After 64 calls, BoolSource will refresh the bucket - make sure it does.
1016 mock_random_.ChangeValue(); 1013 mock_random_.ChangeValue();
1017 } 1014 }
1018 1015
1019 delete frames_[0].stream_frame; 1016 delete frames_[0].stream_frame;
1020 } 1017 }
1021 1018
1022 } // namespace 1019 } // namespace
1023 } // namespace test 1020 } // namespace test
1024 } // namespace net 1021 } // namespace net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698