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/core/quic_packet_creator.h" | 5 #include "net/quic/core/quic_packet_creator.h" |
6 | 6 |
7 #include <cstdint> | 7 #include <cstdint> |
8 #include <memory> | 8 #include <memory> |
9 #include <string> | 9 #include <string> |
10 | 10 |
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
124 QuicTime::Zero(), | 124 QuicTime::Zero(), |
125 Perspective::IS_CLIENT), | 125 Perspective::IS_CLIENT), |
126 connection_id_(2), | 126 connection_id_(2), |
127 data_("foo"), | 127 data_("foo"), |
128 creator_(connection_id_, | 128 creator_(connection_id_, |
129 &client_framer_, | 129 &client_framer_, |
130 &mock_random_, | 130 &mock_random_, |
131 &buffer_allocator_, | 131 &buffer_allocator_, |
132 &delegate_), | 132 &delegate_), |
133 serialized_packet_(creator_.NoPacket()) { | 133 serialized_packet_(creator_.NoPacket()) { |
134 FLAGS_quic_always_log_bugs_for_tests = true; | |
135 creator_.set_connection_id_length(GetParam().connection_id_length); | 134 creator_.set_connection_id_length(GetParam().connection_id_length); |
136 | 135 |
137 creator_.SetEncrypter(ENCRYPTION_INITIAL, new NullEncrypter()); | 136 creator_.SetEncrypter(ENCRYPTION_INITIAL, new NullEncrypter()); |
138 creator_.SetEncrypter(ENCRYPTION_FORWARD_SECURE, new NullEncrypter()); | 137 creator_.SetEncrypter(ENCRYPTION_FORWARD_SECURE, new NullEncrypter()); |
139 client_framer_.set_visitor(&framer_visitor_); | 138 client_framer_.set_visitor(&framer_visitor_); |
140 client_framer_.set_received_entropy_calculator(&entropy_calculator_); | 139 client_framer_.set_received_entropy_calculator(&entropy_calculator_); |
141 server_framer_.set_visitor(&framer_visitor_); | 140 server_framer_.set_visitor(&framer_visitor_); |
142 // TODO(ianswett): Fix this test so it uses a non-null encrypter. | 141 // TODO(ianswett): Fix this test so it uses a non-null encrypter. |
143 FLAGS_quic_never_write_unencrypted_data = false; | 142 FLAGS_quic_never_write_unencrypted_data = false; |
144 } | 143 } |
(...skipping 27 matching lines...) Expand all Loading... |
172 EXPECT_EQ(stream_id, frame.stream_frame->stream_id); | 171 EXPECT_EQ(stream_id, frame.stream_frame->stream_id); |
173 EXPECT_EQ(data, StringPiece(frame.stream_frame->data_buffer, | 172 EXPECT_EQ(data, StringPiece(frame.stream_frame->data_buffer, |
174 frame.stream_frame->data_length)); | 173 frame.stream_frame->data_length)); |
175 EXPECT_EQ(offset, frame.stream_frame->offset); | 174 EXPECT_EQ(offset, frame.stream_frame->offset); |
176 EXPECT_EQ(fin, frame.stream_frame->fin); | 175 EXPECT_EQ(fin, frame.stream_frame->fin); |
177 } | 176 } |
178 | 177 |
179 // Returns the number of bytes consumed by the header of packet, including | 178 // Returns the number of bytes consumed by the header of packet, including |
180 // the version. | 179 // the version. |
181 size_t GetPacketHeaderOverhead(QuicVersion version) { | 180 size_t GetPacketHeaderOverhead(QuicVersion version) { |
182 if (FLAGS_quic_simple_packet_number_length) { | 181 if (FLAGS_quic_simple_packet_number_length_2) { |
183 return GetPacketHeaderSize( | 182 return GetPacketHeaderSize( |
184 version, creator_.connection_id_length(), kIncludeVersion, | 183 version, creator_.connection_id_length(), kIncludeVersion, |
185 !kIncludePathId, !kIncludeDiversificationNonce, | 184 !kIncludePathId, !kIncludeDiversificationNonce, |
186 QuicPacketCreatorPeer::GetPacketNumberLength(&creator_)); | 185 QuicPacketCreatorPeer::GetPacketNumberLength(&creator_)); |
187 } else { | 186 } else { |
188 return GetPacketHeaderSize( | 187 return GetPacketHeaderSize( |
189 version, creator_.connection_id_length(), kIncludeVersion, | 188 version, creator_.connection_id_length(), kIncludeVersion, |
190 !kIncludePathId, !kIncludeDiversificationNonce, | 189 !kIncludePathId, !kIncludeDiversificationNonce, |
191 QuicPacketCreatorPeer::NextPacketNumberLength(&creator_)); | 190 QuicPacketCreatorPeer::NextPacketNumberLength(&creator_)); |
192 } | 191 } |
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
273 EXPECT_CALL(framer_visitor_, OnAckFrame(_)); | 272 EXPECT_CALL(framer_visitor_, OnAckFrame(_)); |
274 EXPECT_CALL(framer_visitor_, OnStreamFrame(_)); | 273 EXPECT_CALL(framer_visitor_, OnStreamFrame(_)); |
275 EXPECT_CALL(framer_visitor_, OnStreamFrame(_)); | 274 EXPECT_CALL(framer_visitor_, OnStreamFrame(_)); |
276 EXPECT_CALL(framer_visitor_, OnPacketComplete()); | 275 EXPECT_CALL(framer_visitor_, OnPacketComplete()); |
277 } | 276 } |
278 ProcessPacket(serialized); | 277 ProcessPacket(serialized); |
279 } | 278 } |
280 } | 279 } |
281 | 280 |
282 TEST_P(QuicPacketCreatorTest, SerializeChangingSequenceNumberLength) { | 281 TEST_P(QuicPacketCreatorTest, SerializeChangingSequenceNumberLength) { |
283 FLAGS_quic_simple_packet_number_length = false; | 282 FLAGS_quic_simple_packet_number_length_2 = false; |
284 frames_.push_back(QuicFrame(new QuicAckFrame(MakeAckFrame(0u)))); | 283 frames_.push_back(QuicFrame(new QuicAckFrame(MakeAckFrame(0u)))); |
285 creator_.AddSavedFrame(frames_[0]); | 284 creator_.AddSavedFrame(frames_[0]); |
286 QuicPacketCreatorPeer::SetNextPacketNumberLength(&creator_, | 285 QuicPacketCreatorPeer::SetNextPacketNumberLength(&creator_, |
287 PACKET_4BYTE_PACKET_NUMBER); | 286 PACKET_4BYTE_PACKET_NUMBER); |
288 | 287 |
289 EXPECT_CALL(delegate_, OnSerializedPacket(_)) | 288 EXPECT_CALL(delegate_, OnSerializedPacket(_)) |
290 .WillRepeatedly( | 289 .WillRepeatedly( |
291 Invoke(this, &QuicPacketCreatorTest::SaveSerializedPacket)); | 290 Invoke(this, &QuicPacketCreatorTest::SaveSerializedPacket)); |
292 creator_.Flush(); | 291 creator_.Flush(); |
293 // The packet number length will not change mid-packet. | 292 // The packet number length will not change mid-packet. |
(...skipping 28 matching lines...) Expand all Loading... |
322 EXPECT_CALL(framer_visitor_, OnDecryptedPacket(_)); | 321 EXPECT_CALL(framer_visitor_, OnDecryptedPacket(_)); |
323 EXPECT_CALL(framer_visitor_, OnPacketHeader(_)); | 322 EXPECT_CALL(framer_visitor_, OnPacketHeader(_)); |
324 EXPECT_CALL(framer_visitor_, OnAckFrame(_)); | 323 EXPECT_CALL(framer_visitor_, OnAckFrame(_)); |
325 EXPECT_CALL(framer_visitor_, OnPacketComplete()); | 324 EXPECT_CALL(framer_visitor_, OnPacketComplete()); |
326 } | 325 } |
327 ProcessPacket(serialized_packet_); | 326 ProcessPacket(serialized_packet_); |
328 DeleteSerializedPacket(); | 327 DeleteSerializedPacket(); |
329 } | 328 } |
330 | 329 |
331 TEST_P(QuicPacketCreatorTest, ChangeSequenceNumberLengthMidPacket) { | 330 TEST_P(QuicPacketCreatorTest, ChangeSequenceNumberLengthMidPacket) { |
332 FLAGS_quic_simple_packet_number_length = false; | 331 FLAGS_quic_simple_packet_number_length_2 = false; |
333 // Changing the packet number length with queued frames in the creator | 332 // Changing the packet number length with queued frames in the creator |
334 // should hold the change until after any currently queued frames are | 333 // should hold the change until after any currently queued frames are |
335 // serialized. | 334 // serialized. |
336 | 335 |
337 // Packet 1. | 336 // Packet 1. |
338 // Queue a frame in the creator. | 337 // Queue a frame in the creator. |
339 EXPECT_FALSE(creator_.HasPendingFrames()); | 338 EXPECT_FALSE(creator_.HasPendingFrames()); |
340 QuicFrame ack_frame = QuicFrame(new QuicAckFrame(MakeAckFrame(0u))); | 339 QuicFrame ack_frame = QuicFrame(new QuicAckFrame(MakeAckFrame(0u))); |
341 creator_.AddSavedFrame(ack_frame); | 340 creator_.AddSavedFrame(ack_frame); |
342 | 341 |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
405 } | 404 } |
406 ProcessPacket(serialized_packet_); | 405 ProcessPacket(serialized_packet_); |
407 EXPECT_EQ(PACKET_4BYTE_PACKET_NUMBER, | 406 EXPECT_EQ(PACKET_4BYTE_PACKET_NUMBER, |
408 header.public_header.packet_number_length); | 407 header.public_header.packet_number_length); |
409 | 408 |
410 DeleteSerializedPacket(); | 409 DeleteSerializedPacket(); |
411 delete ack_frame.ack_frame; | 410 delete ack_frame.ack_frame; |
412 } | 411 } |
413 | 412 |
414 TEST_P(QuicPacketCreatorTest, ChangeSequenceNumberLengthMidPacketDoesNothing) { | 413 TEST_P(QuicPacketCreatorTest, ChangeSequenceNumberLengthMidPacketDoesNothing) { |
415 FLAGS_quic_simple_packet_number_length = true; | 414 FLAGS_quic_simple_packet_number_length_2 = true; |
416 EXPECT_EQ(PACKET_1BYTE_PACKET_NUMBER, | 415 EXPECT_EQ(PACKET_1BYTE_PACKET_NUMBER, |
417 QuicPacketCreatorPeer::GetPacketNumberLength(&creator_)); | 416 QuicPacketCreatorPeer::GetPacketNumberLength(&creator_)); |
418 // Changing the packet number length with queued frames in the creator | 417 // Changing the packet number length with queued frames in the creator |
419 // should do nothing. | 418 // should do nothing. |
420 EXPECT_FALSE(creator_.HasPendingFrames()); | 419 EXPECT_FALSE(creator_.HasPendingFrames()); |
421 QuicFrame ack_frame = QuicFrame(new QuicAckFrame(MakeAckFrame(0u))); | 420 QuicFrame ack_frame = QuicFrame(new QuicAckFrame(MakeAckFrame(0u))); |
422 creator_.AddSavedFrame(ack_frame); | 421 creator_.AddSavedFrame(ack_frame); |
423 | 422 |
424 // Now change packet number length and expect a QUIC_BUG and no change in | 423 // Now change packet number length and expect a QUIC_BUG and no change in |
425 // packet number length. | 424 // packet number length. |
426 EXPECT_DFATAL(creator_.UpdatePacketNumberLength(0, 256), | 425 EXPECT_QUIC_BUG(creator_.UpdatePacketNumberLength(0, 256), |
427 "Called UpdatePacketNumberLength with 1 queued_frames."); | 426 "Called UpdatePacketNumberLength with 1 queued_frames."); |
428 EXPECT_EQ(PACKET_1BYTE_PACKET_NUMBER, | 427 EXPECT_EQ(PACKET_1BYTE_PACKET_NUMBER, |
429 QuicPacketCreatorPeer::GetPacketNumberLength(&creator_)); | 428 QuicPacketCreatorPeer::GetPacketNumberLength(&creator_)); |
430 delete ack_frame.ack_frame; | 429 delete ack_frame.ack_frame; |
431 } | 430 } |
432 | 431 |
433 TEST_P(QuicPacketCreatorTest, ReserializeFramesWithSequenceNumberLength) { | 432 TEST_P(QuicPacketCreatorTest, ReserializeFramesWithSequenceNumberLength) { |
434 // If the original packet number length, the current packet number | 433 // If the original packet number length, the current packet number |
435 // length, and the configured send packet number length are different, the | 434 // length, and the configured send packet number length are different, the |
436 // retransmit must sent with the original length and the others do not change. | 435 // retransmit must sent with the original length and the others do not change. |
437 if (!FLAGS_quic_simple_packet_number_length) { | 436 if (!FLAGS_quic_simple_packet_number_length_2) { |
438 QuicPacketCreatorPeer::SetNextPacketNumberLength( | 437 QuicPacketCreatorPeer::SetNextPacketNumberLength( |
439 &creator_, PACKET_4BYTE_PACKET_NUMBER); | 438 &creator_, PACKET_4BYTE_PACKET_NUMBER); |
440 } | 439 } |
441 QuicPacketCreatorPeer::SetPacketNumberLength(&creator_, | 440 QuicPacketCreatorPeer::SetPacketNumberLength(&creator_, |
442 PACKET_2BYTE_PACKET_NUMBER); | 441 PACKET_2BYTE_PACKET_NUMBER); |
443 QuicStreamFrame* stream_frame = | 442 QuicStreamFrame* stream_frame = |
444 new QuicStreamFrame(kCryptoStreamId, /*fin=*/false, 0u, StringPiece()); | 443 new QuicStreamFrame(kCryptoStreamId, /*fin=*/false, 0u, StringPiece()); |
445 QuicFrames frames; | 444 QuicFrames frames; |
446 frames.push_back(QuicFrame(stream_frame)); | 445 frames.push_back(QuicFrame(stream_frame)); |
447 char buffer[kMaxPacketSize]; | 446 char buffer[kMaxPacketSize]; |
448 PendingRetransmission retransmission(CreateRetransmission( | 447 PendingRetransmission retransmission(CreateRetransmission( |
449 frames, true /* has_crypto_handshake */, -1 /* needs full padding */, | 448 frames, true /* has_crypto_handshake */, -1 /* needs full padding */, |
450 ENCRYPTION_NONE, PACKET_1BYTE_PACKET_NUMBER)); | 449 ENCRYPTION_NONE, PACKET_1BYTE_PACKET_NUMBER)); |
451 EXPECT_CALL(delegate_, OnSerializedPacket(_)) | 450 EXPECT_CALL(delegate_, OnSerializedPacket(_)) |
452 .WillOnce(Invoke(this, &QuicPacketCreatorTest::SaveSerializedPacket)); | 451 .WillOnce(Invoke(this, &QuicPacketCreatorTest::SaveSerializedPacket)); |
453 creator_.ReserializeAllFrames(retransmission, buffer, kMaxPacketSize); | 452 creator_.ReserializeAllFrames(retransmission, buffer, kMaxPacketSize); |
454 if (FLAGS_quic_simple_packet_number_length) { | 453 if (FLAGS_quic_simple_packet_number_length_2) { |
455 // The packet number length is updated after every packet is sent, | 454 // The packet number length is updated after every packet is sent, |
456 // so there is no need to restore the old length after sending. | 455 // so there is no need to restore the old length after sending. |
457 EXPECT_EQ(PACKET_1BYTE_PACKET_NUMBER, | 456 EXPECT_EQ(PACKET_1BYTE_PACKET_NUMBER, |
458 QuicPacketCreatorPeer::GetPacketNumberLength(&creator_)); | 457 QuicPacketCreatorPeer::GetPacketNumberLength(&creator_)); |
459 } else { | 458 } else { |
460 EXPECT_EQ(PACKET_4BYTE_PACKET_NUMBER, | 459 EXPECT_EQ(PACKET_4BYTE_PACKET_NUMBER, |
461 QuicPacketCreatorPeer::NextPacketNumberLength(&creator_)); | 460 QuicPacketCreatorPeer::NextPacketNumberLength(&creator_)); |
462 EXPECT_EQ(PACKET_2BYTE_PACKET_NUMBER, | 461 EXPECT_EQ(PACKET_2BYTE_PACKET_NUMBER, |
463 QuicPacketCreatorPeer::GetPacketNumberLength(&creator_)); | 462 QuicPacketCreatorPeer::GetPacketNumberLength(&creator_)); |
464 } | 463 } |
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
543 | 542 |
544 const int kNumPaddingBytes1 = 4; | 543 const int kNumPaddingBytes1 = 4; |
545 int packet_size = 0; | 544 int packet_size = 0; |
546 { | 545 { |
547 QuicFrames frames; | 546 QuicFrames frames; |
548 frames.push_back(frame); | 547 frames.push_back(frame); |
549 char buffer[kMaxPacketSize]; | 548 char buffer[kMaxPacketSize]; |
550 PendingRetransmission retransmission(CreateRetransmission( | 549 PendingRetransmission retransmission(CreateRetransmission( |
551 frames, false /* has_crypto_handshake */, | 550 frames, false /* has_crypto_handshake */, |
552 kNumPaddingBytes1 /* padding bytes */, ENCRYPTION_NONE, | 551 kNumPaddingBytes1 /* padding bytes */, ENCRYPTION_NONE, |
553 FLAGS_quic_simple_packet_number_length | 552 FLAGS_quic_simple_packet_number_length_2 |
554 ? QuicPacketCreatorPeer::GetPacketNumberLength(&creator_) | 553 ? QuicPacketCreatorPeer::GetPacketNumberLength(&creator_) |
555 : QuicPacketCreatorPeer::NextPacketNumberLength(&creator_))); | 554 : QuicPacketCreatorPeer::NextPacketNumberLength(&creator_))); |
556 EXPECT_CALL(delegate_, OnSerializedPacket(_)) | 555 EXPECT_CALL(delegate_, OnSerializedPacket(_)) |
557 .WillOnce(Invoke(this, &QuicPacketCreatorTest::SaveSerializedPacket)); | 556 .WillOnce(Invoke(this, &QuicPacketCreatorTest::SaveSerializedPacket)); |
558 creator_.ReserializeAllFrames(retransmission, buffer, kMaxPacketSize); | 557 creator_.ReserializeAllFrames(retransmission, buffer, kMaxPacketSize); |
559 packet_size = serialized_packet_.encrypted_length; | 558 packet_size = serialized_packet_.encrypted_length; |
560 } | 559 } |
561 | 560 |
562 const int kNumPaddingBytes2 = 44; | 561 const int kNumPaddingBytes2 = 44; |
563 QuicFrames frames; | 562 QuicFrames frames; |
(...skipping 241 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
805 InSequence s; | 804 InSequence s; |
806 EXPECT_CALL(framer_visitor_, OnPacket()); | 805 EXPECT_CALL(framer_visitor_, OnPacket()); |
807 EXPECT_CALL(framer_visitor_, OnUnauthenticatedPublicHeader(_)); | 806 EXPECT_CALL(framer_visitor_, OnUnauthenticatedPublicHeader(_)); |
808 EXPECT_CALL(framer_visitor_, OnVersionNegotiationPacket(_)); | 807 EXPECT_CALL(framer_visitor_, OnVersionNegotiationPacket(_)); |
809 } | 808 } |
810 QuicFramerPeer::SetPerspective(&client_framer_, Perspective::IS_CLIENT); | 809 QuicFramerPeer::SetPerspective(&client_framer_, Perspective::IS_CLIENT); |
811 client_framer_.ProcessPacket(*encrypted); | 810 client_framer_.ProcessPacket(*encrypted); |
812 } | 811 } |
813 | 812 |
814 TEST_P(QuicPacketCreatorTest, UpdatePacketNumberLengthLeastAwaiting_Old) { | 813 TEST_P(QuicPacketCreatorTest, UpdatePacketNumberLengthLeastAwaiting_Old) { |
815 FLAGS_quic_simple_packet_number_length = false; | 814 FLAGS_quic_simple_packet_number_length_2 = false; |
816 EXPECT_EQ(PACKET_1BYTE_PACKET_NUMBER, | 815 EXPECT_EQ(PACKET_1BYTE_PACKET_NUMBER, |
817 QuicPacketCreatorPeer::NextPacketNumberLength(&creator_)); | 816 QuicPacketCreatorPeer::NextPacketNumberLength(&creator_)); |
818 | 817 |
819 QuicPacketCreatorPeer::SetPacketNumber(&creator_, 64); | 818 QuicPacketCreatorPeer::SetPacketNumber(&creator_, 64); |
820 creator_.UpdatePacketNumberLength(2, 10000 / kDefaultMaxPacketSize); | 819 creator_.UpdatePacketNumberLength(2, 10000 / kDefaultMaxPacketSize); |
821 EXPECT_EQ(PACKET_1BYTE_PACKET_NUMBER, | 820 EXPECT_EQ(PACKET_1BYTE_PACKET_NUMBER, |
822 QuicPacketCreatorPeer::NextPacketNumberLength(&creator_)); | 821 QuicPacketCreatorPeer::NextPacketNumberLength(&creator_)); |
823 | 822 |
824 QuicPacketCreatorPeer::SetPacketNumber(&creator_, 64 * 256); | 823 QuicPacketCreatorPeer::SetPacketNumber(&creator_, 64 * 256); |
825 creator_.UpdatePacketNumberLength(2, 10000 / kDefaultMaxPacketSize); | 824 creator_.UpdatePacketNumberLength(2, 10000 / kDefaultMaxPacketSize); |
826 EXPECT_EQ(PACKET_2BYTE_PACKET_NUMBER, | 825 EXPECT_EQ(PACKET_2BYTE_PACKET_NUMBER, |
827 QuicPacketCreatorPeer::NextPacketNumberLength(&creator_)); | 826 QuicPacketCreatorPeer::NextPacketNumberLength(&creator_)); |
828 | 827 |
829 QuicPacketCreatorPeer::SetPacketNumber(&creator_, 64 * 256 * 256); | 828 QuicPacketCreatorPeer::SetPacketNumber(&creator_, 64 * 256 * 256); |
830 creator_.UpdatePacketNumberLength(2, 10000 / kDefaultMaxPacketSize); | 829 creator_.UpdatePacketNumberLength(2, 10000 / kDefaultMaxPacketSize); |
831 EXPECT_EQ(PACKET_4BYTE_PACKET_NUMBER, | 830 EXPECT_EQ(PACKET_4BYTE_PACKET_NUMBER, |
832 QuicPacketCreatorPeer::NextPacketNumberLength(&creator_)); | 831 QuicPacketCreatorPeer::NextPacketNumberLength(&creator_)); |
833 | 832 |
834 QuicPacketCreatorPeer::SetPacketNumber(&creator_, | 833 QuicPacketCreatorPeer::SetPacketNumber(&creator_, |
835 UINT64_C(64) * 256 * 256 * 256 * 256); | 834 UINT64_C(64) * 256 * 256 * 256 * 256); |
836 creator_.UpdatePacketNumberLength(2, 10000 / kDefaultMaxPacketSize); | 835 creator_.UpdatePacketNumberLength(2, 10000 / kDefaultMaxPacketSize); |
837 EXPECT_EQ(PACKET_6BYTE_PACKET_NUMBER, | 836 EXPECT_EQ(PACKET_6BYTE_PACKET_NUMBER, |
838 QuicPacketCreatorPeer::NextPacketNumberLength(&creator_)); | 837 QuicPacketCreatorPeer::NextPacketNumberLength(&creator_)); |
839 } | 838 } |
840 | 839 |
841 TEST_P(QuicPacketCreatorTest, UpdatePacketSequenceNumberLengthBandwidth_old) { | 840 TEST_P(QuicPacketCreatorTest, UpdatePacketSequenceNumberLengthBandwidth_old) { |
842 FLAGS_quic_simple_packet_number_length = false; | 841 FLAGS_quic_simple_packet_number_length_2 = false; |
843 EXPECT_EQ(PACKET_1BYTE_PACKET_NUMBER, | 842 EXPECT_EQ(PACKET_1BYTE_PACKET_NUMBER, |
844 QuicPacketCreatorPeer::NextPacketNumberLength(&creator_)); | 843 QuicPacketCreatorPeer::NextPacketNumberLength(&creator_)); |
845 | 844 |
846 creator_.UpdatePacketNumberLength(1, 10000 / kDefaultMaxPacketSize); | 845 creator_.UpdatePacketNumberLength(1, 10000 / kDefaultMaxPacketSize); |
847 EXPECT_EQ(PACKET_1BYTE_PACKET_NUMBER, | 846 EXPECT_EQ(PACKET_1BYTE_PACKET_NUMBER, |
848 QuicPacketCreatorPeer::NextPacketNumberLength(&creator_)); | 847 QuicPacketCreatorPeer::NextPacketNumberLength(&creator_)); |
849 | 848 |
850 creator_.UpdatePacketNumberLength(1, 10000 * 256 / kDefaultMaxPacketSize); | 849 creator_.UpdatePacketNumberLength(1, 10000 * 256 / kDefaultMaxPacketSize); |
851 EXPECT_EQ(PACKET_2BYTE_PACKET_NUMBER, | 850 EXPECT_EQ(PACKET_2BYTE_PACKET_NUMBER, |
852 QuicPacketCreatorPeer::NextPacketNumberLength(&creator_)); | 851 QuicPacketCreatorPeer::NextPacketNumberLength(&creator_)); |
853 | 852 |
854 creator_.UpdatePacketNumberLength(1, | 853 creator_.UpdatePacketNumberLength(1, |
855 10000 * 256 * 256 / kDefaultMaxPacketSize); | 854 10000 * 256 * 256 / kDefaultMaxPacketSize); |
856 EXPECT_EQ(PACKET_4BYTE_PACKET_NUMBER, | 855 EXPECT_EQ(PACKET_4BYTE_PACKET_NUMBER, |
857 QuicPacketCreatorPeer::NextPacketNumberLength(&creator_)); | 856 QuicPacketCreatorPeer::NextPacketNumberLength(&creator_)); |
858 | 857 |
859 creator_.UpdatePacketNumberLength( | 858 creator_.UpdatePacketNumberLength( |
860 1, UINT64_C(1000) * 256 * 256 * 256 * 256 / kDefaultMaxPacketSize); | 859 1, UINT64_C(1000) * 256 * 256 * 256 * 256 / kDefaultMaxPacketSize); |
861 EXPECT_EQ(PACKET_6BYTE_PACKET_NUMBER, | 860 EXPECT_EQ(PACKET_6BYTE_PACKET_NUMBER, |
862 QuicPacketCreatorPeer::NextPacketNumberLength(&creator_)); | 861 QuicPacketCreatorPeer::NextPacketNumberLength(&creator_)); |
863 } | 862 } |
864 | 863 |
865 TEST_P(QuicPacketCreatorTest, UpdatePacketSequenceNumberLengthLeastAwaiting) { | 864 TEST_P(QuicPacketCreatorTest, UpdatePacketSequenceNumberLengthLeastAwaiting) { |
866 FLAGS_quic_simple_packet_number_length = true; | 865 FLAGS_quic_simple_packet_number_length_2 = true; |
867 EXPECT_EQ(PACKET_1BYTE_PACKET_NUMBER, | 866 EXPECT_EQ(PACKET_1BYTE_PACKET_NUMBER, |
868 QuicPacketCreatorPeer::GetPacketNumberLength(&creator_)); | 867 QuicPacketCreatorPeer::GetPacketNumberLength(&creator_)); |
869 | 868 |
870 QuicPacketCreatorPeer::SetPacketNumber(&creator_, 64); | 869 QuicPacketCreatorPeer::SetPacketNumber(&creator_, 64); |
871 creator_.UpdatePacketNumberLength(2, 10000 / kDefaultMaxPacketSize); | 870 creator_.UpdatePacketNumberLength(2, 10000 / kDefaultMaxPacketSize); |
872 EXPECT_EQ(PACKET_1BYTE_PACKET_NUMBER, | 871 EXPECT_EQ(PACKET_1BYTE_PACKET_NUMBER, |
873 QuicPacketCreatorPeer::GetPacketNumberLength(&creator_)); | 872 QuicPacketCreatorPeer::GetPacketNumberLength(&creator_)); |
874 | 873 |
875 QuicPacketCreatorPeer::SetPacketNumber(&creator_, 64 * 256); | 874 QuicPacketCreatorPeer::SetPacketNumber(&creator_, 64 * 256); |
876 creator_.UpdatePacketNumberLength(2, 10000 / kDefaultMaxPacketSize); | 875 creator_.UpdatePacketNumberLength(2, 10000 / kDefaultMaxPacketSize); |
877 EXPECT_EQ(PACKET_2BYTE_PACKET_NUMBER, | 876 EXPECT_EQ(PACKET_2BYTE_PACKET_NUMBER, |
878 QuicPacketCreatorPeer::GetPacketNumberLength(&creator_)); | 877 QuicPacketCreatorPeer::GetPacketNumberLength(&creator_)); |
879 | 878 |
880 QuicPacketCreatorPeer::SetPacketNumber(&creator_, 64 * 256 * 256); | 879 QuicPacketCreatorPeer::SetPacketNumber(&creator_, 64 * 256 * 256); |
881 creator_.UpdatePacketNumberLength(2, 10000 / kDefaultMaxPacketSize); | 880 creator_.UpdatePacketNumberLength(2, 10000 / kDefaultMaxPacketSize); |
882 EXPECT_EQ(PACKET_4BYTE_PACKET_NUMBER, | 881 EXPECT_EQ(PACKET_4BYTE_PACKET_NUMBER, |
883 QuicPacketCreatorPeer::GetPacketNumberLength(&creator_)); | 882 QuicPacketCreatorPeer::GetPacketNumberLength(&creator_)); |
884 | 883 |
885 QuicPacketCreatorPeer::SetPacketNumber(&creator_, | 884 QuicPacketCreatorPeer::SetPacketNumber(&creator_, |
886 UINT64_C(64) * 256 * 256 * 256 * 256); | 885 UINT64_C(64) * 256 * 256 * 256 * 256); |
887 creator_.UpdatePacketNumberLength(2, 10000 / kDefaultMaxPacketSize); | 886 creator_.UpdatePacketNumberLength(2, 10000 / kDefaultMaxPacketSize); |
888 EXPECT_EQ(PACKET_6BYTE_PACKET_NUMBER, | 887 EXPECT_EQ(PACKET_6BYTE_PACKET_NUMBER, |
889 QuicPacketCreatorPeer::GetPacketNumberLength(&creator_)); | 888 QuicPacketCreatorPeer::GetPacketNumberLength(&creator_)); |
890 } | 889 } |
891 | 890 |
892 TEST_P(QuicPacketCreatorTest, UpdatePacketSequenceNumberLengthCwnd) { | 891 TEST_P(QuicPacketCreatorTest, UpdatePacketSequenceNumberLengthCwnd) { |
893 FLAGS_quic_simple_packet_number_length = true; | 892 FLAGS_quic_simple_packet_number_length_2 = true; |
894 EXPECT_EQ(PACKET_1BYTE_PACKET_NUMBER, | 893 EXPECT_EQ(PACKET_1BYTE_PACKET_NUMBER, |
895 QuicPacketCreatorPeer::GetPacketNumberLength(&creator_)); | 894 QuicPacketCreatorPeer::GetPacketNumberLength(&creator_)); |
896 | 895 |
897 creator_.UpdatePacketNumberLength(1, 10000 / kDefaultMaxPacketSize); | 896 creator_.UpdatePacketNumberLength(1, 10000 / kDefaultMaxPacketSize); |
898 EXPECT_EQ(PACKET_1BYTE_PACKET_NUMBER, | 897 EXPECT_EQ(PACKET_1BYTE_PACKET_NUMBER, |
899 QuicPacketCreatorPeer::GetPacketNumberLength(&creator_)); | 898 QuicPacketCreatorPeer::GetPacketNumberLength(&creator_)); |
900 | 899 |
901 creator_.UpdatePacketNumberLength(1, 10000 * 256 / kDefaultMaxPacketSize); | 900 creator_.UpdatePacketNumberLength(1, 10000 * 256 / kDefaultMaxPacketSize); |
902 EXPECT_EQ(PACKET_2BYTE_PACKET_NUMBER, | 901 EXPECT_EQ(PACKET_2BYTE_PACKET_NUMBER, |
903 QuicPacketCreatorPeer::GetPacketNumberLength(&creator_)); | 902 QuicPacketCreatorPeer::GetPacketNumberLength(&creator_)); |
(...skipping 270 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1174 ASSERT_TRUE( | 1173 ASSERT_TRUE( |
1175 creator_.ConsumeData(1u, io_vector, 0u, 0u, false, false, &frame)); | 1174 creator_.ConsumeData(1u, io_vector, 0u, 0u, false, false, &frame)); |
1176 ASSERT_TRUE(frame.stream_frame); | 1175 ASSERT_TRUE(frame.stream_frame); |
1177 size_t consumed = frame.stream_frame->data_length; | 1176 size_t consumed = frame.stream_frame->data_length; |
1178 EXPECT_EQ(4u, consumed); | 1177 EXPECT_EQ(4u, consumed); |
1179 EXPECT_TRUE(creator_.HasPendingFrames()); | 1178 EXPECT_TRUE(creator_.HasPendingFrames()); |
1180 EXPECT_EQ(0u, creator_.packet_number()); | 1179 EXPECT_EQ(0u, creator_.packet_number()); |
1181 | 1180 |
1182 // Change current path. | 1181 // Change current path. |
1183 QuicPathId kPathId1 = 1; | 1182 QuicPathId kPathId1 = 1; |
1184 EXPECT_DFATAL(creator_.SetCurrentPath(kPathId1, 1, 0), | 1183 EXPECT_QUIC_BUG(creator_.SetCurrentPath(kPathId1, 1, 0), |
1185 "Unable to change paths when a packet is under construction"); | 1184 "Unable to change paths when a packet is under construction"); |
1186 EXPECT_CALL(delegate_, OnSerializedPacket(_)) | 1185 EXPECT_CALL(delegate_, OnSerializedPacket(_)) |
1187 .Times(1) | 1186 .Times(1) |
1188 .WillRepeatedly( | 1187 .WillRepeatedly( |
1189 Invoke(this, &QuicPacketCreatorTest::ClearSerializedPacket)); | 1188 Invoke(this, &QuicPacketCreatorTest::ClearSerializedPacket)); |
1190 creator_.Flush(); | 1189 creator_.Flush(); |
1191 EXPECT_FALSE(creator_.HasPendingFrames()); | 1190 EXPECT_FALSE(creator_.HasPendingFrames()); |
1192 creator_.SetCurrentPath(kPathId1, 1, 0); | 1191 creator_.SetCurrentPath(kPathId1, 1, 0); |
1193 EXPECT_EQ(kPathId1, QuicPacketCreatorPeer::GetCurrentPath(&creator_)); | 1192 EXPECT_EQ(kPathId1, QuicPacketCreatorPeer::GetCurrentPath(&creator_)); |
1194 EXPECT_FALSE(creator_.HasPendingFrames()); | 1193 EXPECT_FALSE(creator_.HasPendingFrames()); |
1195 EXPECT_EQ(0u, creator_.packet_number()); | 1194 EXPECT_EQ(0u, creator_.packet_number()); |
(...skipping 18 matching lines...) Expand all Loading... |
1214 creator_.SetCurrentPath(kDefaultPathId, 2, 0); | 1213 creator_.SetCurrentPath(kDefaultPathId, 2, 0); |
1215 EXPECT_EQ(kDefaultPathId, QuicPacketCreatorPeer::GetCurrentPath(&creator_)); | 1214 EXPECT_EQ(kDefaultPathId, QuicPacketCreatorPeer::GetCurrentPath(&creator_)); |
1216 EXPECT_TRUE(creator_.HasPendingFrames()); | 1215 EXPECT_TRUE(creator_.HasPendingFrames()); |
1217 EXPECT_EQ(1u, creator_.packet_number()); | 1216 EXPECT_EQ(1u, creator_.packet_number()); |
1218 EXPECT_EQ(PACKET_1BYTE_PACKET_NUMBER, | 1217 EXPECT_EQ(PACKET_1BYTE_PACKET_NUMBER, |
1219 QuicPacketCreatorPeer::GetPacketNumberLength(&creator_)); | 1218 QuicPacketCreatorPeer::GetPacketNumberLength(&creator_)); |
1220 } | 1219 } |
1221 | 1220 |
1222 TEST_P(QuicPacketCreatorTest, | 1221 TEST_P(QuicPacketCreatorTest, |
1223 SetCurrentPathAndUpdatePacketSequenceNumberLength) { | 1222 SetCurrentPathAndUpdatePacketSequenceNumberLength) { |
1224 FLAGS_quic_simple_packet_number_length = false; | 1223 FLAGS_quic_simple_packet_number_length_2 = false; |
1225 // Current path is the default path. | 1224 // Current path is the default path. |
1226 EXPECT_EQ(kDefaultPathId, QuicPacketCreatorPeer::GetCurrentPath(&creator_)); | 1225 EXPECT_EQ(kDefaultPathId, QuicPacketCreatorPeer::GetCurrentPath(&creator_)); |
1227 EXPECT_EQ(PACKET_1BYTE_PACKET_NUMBER, | 1226 EXPECT_EQ(PACKET_1BYTE_PACKET_NUMBER, |
1228 QuicPacketCreatorPeer::GetPacketNumberLength(&creator_)); | 1227 QuicPacketCreatorPeer::GetPacketNumberLength(&creator_)); |
1229 EXPECT_EQ(PACKET_1BYTE_PACKET_NUMBER, | 1228 EXPECT_EQ(PACKET_1BYTE_PACKET_NUMBER, |
1230 QuicPacketCreatorPeer::NextPacketNumberLength(&creator_)); | 1229 QuicPacketCreatorPeer::NextPacketNumberLength(&creator_)); |
1231 QuicPacketCreatorPeer::SetPacketNumber(&creator_, 64 * 256 - 2); | 1230 QuicPacketCreatorPeer::SetPacketNumber(&creator_, 64 * 256 - 2); |
1232 // Add a stream frame to the creator and send the packet. | 1231 // Add a stream frame to the creator and send the packet. |
1233 QuicFrame frame; | 1232 QuicFrame frame; |
1234 QuicIOVector io_vector(MakeIOVector("test")); | 1233 QuicIOVector io_vector(MakeIOVector("test")); |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1302 // Verify serialized data packet's path id. | 1301 // Verify serialized data packet's path id. |
1303 EXPECT_EQ(kPathId1, serialized_packet_.path_id); | 1302 EXPECT_EQ(kPathId1, serialized_packet_.path_id); |
1304 DeleteSerializedPacket(); | 1303 DeleteSerializedPacket(); |
1305 } | 1304 } |
1306 | 1305 |
1307 TEST_P(QuicPacketCreatorTest, AddUnencryptedStreamDataClosesConnection) { | 1306 TEST_P(QuicPacketCreatorTest, AddUnencryptedStreamDataClosesConnection) { |
1308 FLAGS_quic_never_write_unencrypted_data = true; | 1307 FLAGS_quic_never_write_unencrypted_data = true; |
1309 EXPECT_CALL(delegate_, OnUnrecoverableError(_, _, _)); | 1308 EXPECT_CALL(delegate_, OnUnrecoverableError(_, _, _)); |
1310 QuicStreamFrame stream_frame(kHeadersStreamId, /*fin=*/false, 0u, | 1309 QuicStreamFrame stream_frame(kHeadersStreamId, /*fin=*/false, 0u, |
1311 StringPiece()); | 1310 StringPiece()); |
1312 EXPECT_DFATAL(creator_.AddSavedFrame(QuicFrame(&stream_frame)), | 1311 EXPECT_QUIC_BUG(creator_.AddSavedFrame(QuicFrame(&stream_frame)), |
1313 "Cannot send stream data without encryption."); | 1312 "Cannot send stream data without encryption."); |
1314 } | 1313 } |
1315 | 1314 |
1316 TEST_P(QuicPacketCreatorTest, ChloTooLarge) { | 1315 TEST_P(QuicPacketCreatorTest, ChloTooLarge) { |
1317 CryptoHandshakeMessage message; | 1316 CryptoHandshakeMessage message; |
1318 message.set_tag(kCHLO); | 1317 message.set_tag(kCHLO); |
1319 message.set_minimum_size(kMaxPacketSize); | 1318 message.set_minimum_size(kMaxPacketSize); |
1320 CryptoFramer framer; | 1319 CryptoFramer framer; |
1321 std::unique_ptr<QuicData> message_data; | 1320 std::unique_ptr<QuicData> message_data; |
1322 message_data.reset(framer.ConstructHandshakeMessage(message)); | 1321 message_data.reset(framer.ConstructHandshakeMessage(message)); |
1323 | 1322 |
1324 struct iovec iov; | 1323 struct iovec iov; |
1325 QuicIOVector data_iovec(::net::MakeIOVector( | 1324 QuicIOVector data_iovec(::net::MakeIOVector( |
1326 StringPiece(message_data->data(), message_data->length()), &iov)); | 1325 StringPiece(message_data->data(), message_data->length()), &iov)); |
1327 QuicFrame frame; | 1326 QuicFrame frame; |
1328 EXPECT_CALL(delegate_, | 1327 EXPECT_CALL(delegate_, |
1329 OnUnrecoverableError(QUIC_CRYPTO_CHLO_TOO_LARGE, _, _)); | 1328 OnUnrecoverableError(QUIC_CRYPTO_CHLO_TOO_LARGE, _, _)); |
1330 EXPECT_DFATAL( | 1329 EXPECT_QUIC_BUG( |
1331 creator_.ConsumeData(1u, data_iovec, 0u, 0u, false, false, &frame), | 1330 creator_.ConsumeData(1u, data_iovec, 0u, 0u, false, false, &frame), |
1332 "Client hello won't fit in a single packet."); | 1331 "Client hello won't fit in a single packet."); |
1333 } | 1332 } |
1334 | 1333 |
1335 } // namespace | 1334 } // namespace |
1336 } // namespace test | 1335 } // namespace test |
1337 } // namespace net | 1336 } // namespace net |
OLD | NEW |