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_packet_creator.h" | 5 #include "net/quic/quic_packet_creator.h" |
6 | 6 |
7 #include <stdint.h> | 7 #include <stdint.h> |
8 | 8 |
9 #include "base/macros.h" | 9 #include "base/macros.h" |
10 #include "base/stl_util.h" | 10 #include "base/stl_util.h" |
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
95 if (serialized_packet == nullptr) { | 95 if (serialized_packet == nullptr) { |
96 return; | 96 return; |
97 } | 97 } |
98 QuicUtils::ClearSerializedPacket(serialized_packet); | 98 QuicUtils::ClearSerializedPacket(serialized_packet); |
99 } | 99 } |
100 | 100 |
101 void SaveSerializedPacket(SerializedPacket* serialized_packet) { | 101 void SaveSerializedPacket(SerializedPacket* serialized_packet) { |
102 if (serialized_packet == nullptr) { | 102 if (serialized_packet == nullptr) { |
103 return; | 103 return; |
104 } | 104 } |
105 | 105 delete[] serialized_packet_.encrypted_buffer; |
106 serialized_packet_ = *serialized_packet; | 106 serialized_packet_ = *serialized_packet; |
107 serialized_packet_.packet = serialized_packet->packet->Clone(); | 107 serialized_packet_.encrypted_buffer = |
108 delete serialized_packet->packet; | 108 QuicUtils::CopyBuffer(*serialized_packet); |
109 serialized_packet->retransmittable_frames.clear(); | 109 serialized_packet->retransmittable_frames.clear(); |
110 } | 110 } |
111 | 111 |
112 void DeleteSerializedPacket() { ClearSerializedPacket(&serialized_packet_); } | 112 void DeleteSerializedPacket() { |
| 113 delete[] serialized_packet_.encrypted_buffer; |
| 114 serialized_packet_.encrypted_buffer = nullptr; |
| 115 ClearSerializedPacket(&serialized_packet_); |
| 116 } |
113 | 117 |
114 protected: | 118 protected: |
115 QuicPacketCreatorTest() | 119 QuicPacketCreatorTest() |
116 : server_framer_(SupportedVersions(GetParam().version), | 120 : server_framer_(SupportedVersions(GetParam().version), |
117 QuicTime::Zero(), | 121 QuicTime::Zero(), |
118 Perspective::IS_SERVER), | 122 Perspective::IS_SERVER), |
119 client_framer_(SupportedVersions(GetParam().version), | 123 client_framer_(SupportedVersions(GetParam().version), |
120 QuicTime::Zero(), | 124 QuicTime::Zero(), |
121 Perspective::IS_CLIENT), | 125 Perspective::IS_CLIENT), |
122 connection_id_(2), | 126 connection_id_(2), |
(...skipping 10 matching lines...) Expand all Loading... |
133 creator_.SetEncrypter(ENCRYPTION_INITIAL, new NullEncrypter()); | 137 creator_.SetEncrypter(ENCRYPTION_INITIAL, new NullEncrypter()); |
134 creator_.SetEncrypter(ENCRYPTION_FORWARD_SECURE, new NullEncrypter()); | 138 creator_.SetEncrypter(ENCRYPTION_FORWARD_SECURE, new NullEncrypter()); |
135 client_framer_.set_visitor(&framer_visitor_); | 139 client_framer_.set_visitor(&framer_visitor_); |
136 client_framer_.set_received_entropy_calculator(&entropy_calculator_); | 140 client_framer_.set_received_entropy_calculator(&entropy_calculator_); |
137 server_framer_.set_visitor(&framer_visitor_); | 141 server_framer_.set_visitor(&framer_visitor_); |
138 // TODO(ianswett): Fix this test so it uses a non-null encrypter. | 142 // TODO(ianswett): Fix this test so it uses a non-null encrypter. |
139 FLAGS_quic_never_write_unencrypted_data = false; | 143 FLAGS_quic_never_write_unencrypted_data = false; |
140 FLAGS_quic_no_unencrypted_fec = false; | 144 FLAGS_quic_no_unencrypted_fec = false; |
141 } | 145 } |
142 | 146 |
143 ~QuicPacketCreatorTest() override {} | 147 ~QuicPacketCreatorTest() override { |
| 148 delete[] serialized_packet_.encrypted_buffer; |
| 149 ClearSerializedPacket(&serialized_packet_); |
| 150 } |
144 | 151 |
145 SerializedPacket SerializeAllFrames(const QuicFrames& frames) { | 152 SerializedPacket SerializeAllFrames(const QuicFrames& frames) { |
146 SerializedPacket packet = QuicPacketCreatorPeer::SerializeAllFrames( | 153 SerializedPacket packet = QuicPacketCreatorPeer::SerializeAllFrames( |
147 &creator_, frames, buffer_, kMaxPacketSize); | 154 &creator_, frames, buffer_, kMaxPacketSize); |
148 EXPECT_EQ(QuicPacketCreatorPeer::GetEncryptionLevel(&creator_), | 155 EXPECT_EQ(QuicPacketCreatorPeer::GetEncryptionLevel(&creator_), |
149 packet.encryption_level); | 156 packet.encryption_level); |
150 return packet; | 157 return packet; |
151 } | 158 } |
152 | 159 |
153 void ProcessPacket(const SerializedPacket& packet) { | 160 void ProcessPacket(const SerializedPacket& packet) { |
154 server_framer_.ProcessPacket(*packet.packet); | 161 QuicEncryptedPacket encrypted_packet(packet.encrypted_buffer, |
| 162 packet.encrypted_length); |
| 163 server_framer_.ProcessPacket(encrypted_packet); |
155 } | 164 } |
156 | 165 |
157 void CheckStreamFrame(const QuicFrame& frame, | 166 void CheckStreamFrame(const QuicFrame& frame, |
158 QuicStreamId stream_id, | 167 QuicStreamId stream_id, |
159 const string& data, | 168 const string& data, |
160 QuicStreamOffset offset, | 169 QuicStreamOffset offset, |
161 bool fin) { | 170 bool fin) { |
162 EXPECT_EQ(STREAM_FRAME, frame.type); | 171 EXPECT_EQ(STREAM_FRAME, frame.type); |
163 ASSERT_TRUE(frame.stream_frame); | 172 ASSERT_TRUE(frame.stream_frame); |
164 EXPECT_EQ(stream_id, frame.stream_frame->stream_id); | 173 EXPECT_EQ(stream_id, frame.stream_frame->stream_id); |
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
254 EXPECT_CALL(framer_visitor_, OnUnauthenticatedPublicHeader(_)); | 263 EXPECT_CALL(framer_visitor_, OnUnauthenticatedPublicHeader(_)); |
255 EXPECT_CALL(framer_visitor_, OnUnauthenticatedHeader(_)); | 264 EXPECT_CALL(framer_visitor_, OnUnauthenticatedHeader(_)); |
256 EXPECT_CALL(framer_visitor_, OnDecryptedPacket(_)); | 265 EXPECT_CALL(framer_visitor_, OnDecryptedPacket(_)); |
257 EXPECT_CALL(framer_visitor_, OnPacketHeader(_)); | 266 EXPECT_CALL(framer_visitor_, OnPacketHeader(_)); |
258 EXPECT_CALL(framer_visitor_, OnAckFrame(_)); | 267 EXPECT_CALL(framer_visitor_, OnAckFrame(_)); |
259 EXPECT_CALL(framer_visitor_, OnStreamFrame(_)); | 268 EXPECT_CALL(framer_visitor_, OnStreamFrame(_)); |
260 EXPECT_CALL(framer_visitor_, OnStreamFrame(_)); | 269 EXPECT_CALL(framer_visitor_, OnStreamFrame(_)); |
261 EXPECT_CALL(framer_visitor_, OnPacketComplete()); | 270 EXPECT_CALL(framer_visitor_, OnPacketComplete()); |
262 } | 271 } |
263 ProcessPacket(serialized); | 272 ProcessPacket(serialized); |
264 delete serialized.packet; | |
265 } | 273 } |
266 } | 274 } |
267 | 275 |
268 TEST_P(QuicPacketCreatorTest, SerializeWithFEC) { | 276 TEST_P(QuicPacketCreatorTest, SerializeWithFEC) { |
269 // Send FEC packet every 6 packets. | 277 // Send FEC packet every 6 packets. |
270 creator_.set_max_packets_per_fec_group(6); | 278 creator_.set_max_packets_per_fec_group(6); |
271 // Should return false since we do not have enough packets in the FEC group to | 279 // Should return false since we do not have enough packets in the FEC group to |
272 // trigger an FEC packet. | 280 // trigger an FEC packet. |
273 ASSERT_FALSE(creator_.ShouldSendFec(/*force_close=*/false)); | 281 ASSERT_FALSE(creator_.ShouldSendFec(/*force_close=*/false)); |
274 // Turn on FEC protection. | 282 // Turn on FEC protection. |
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
388 // whose length should be 1. | 396 // whose length should be 1. |
389 QuicStopWaitingFrame stop_waiting_frame; | 397 QuicStopWaitingFrame stop_waiting_frame; |
390 EXPECT_TRUE(creator_.AddSavedFrame(QuicFrame(&stop_waiting_frame))); | 398 EXPECT_TRUE(creator_.AddSavedFrame(QuicFrame(&stop_waiting_frame))); |
391 EXPECT_TRUE(creator_.HasPendingFrames()); | 399 EXPECT_TRUE(creator_.HasPendingFrames()); |
392 | 400 |
393 // Ensure the packet is successfully created. | 401 // Ensure the packet is successfully created. |
394 EXPECT_CALL(delegate_, OnSerializedPacket(_)) | 402 EXPECT_CALL(delegate_, OnSerializedPacket(_)) |
395 .WillRepeatedly( | 403 .WillRepeatedly( |
396 Invoke(this, &QuicPacketCreatorTest::SaveSerializedPacket)); | 404 Invoke(this, &QuicPacketCreatorTest::SaveSerializedPacket)); |
397 creator_.Flush(); | 405 creator_.Flush(); |
398 ASSERT_TRUE(serialized_packet_.packet); | 406 ASSERT_TRUE(serialized_packet_.encrypted_buffer); |
399 EXPECT_EQ(PACKET_1BYTE_PACKET_NUMBER, | 407 EXPECT_EQ(PACKET_1BYTE_PACKET_NUMBER, |
400 serialized_packet_.packet_number_length); | 408 serialized_packet_.packet_number_length); |
401 | 409 |
402 // Verify that header in transmitted packet has 1 byte sequence length. | 410 // Verify that header in transmitted packet has 1 byte sequence length. |
403 QuicPacketHeader header; | 411 QuicPacketHeader header; |
404 { | 412 { |
405 InSequence s; | 413 InSequence s; |
406 EXPECT_CALL(framer_visitor_, OnPacket()); | 414 EXPECT_CALL(framer_visitor_, OnPacket()); |
407 EXPECT_CALL(framer_visitor_, OnUnauthenticatedPublicHeader(_)); | 415 EXPECT_CALL(framer_visitor_, OnUnauthenticatedPublicHeader(_)); |
408 EXPECT_CALL(framer_visitor_, OnUnauthenticatedHeader(_)); | 416 EXPECT_CALL(framer_visitor_, OnUnauthenticatedHeader(_)); |
(...skipping 11 matching lines...) Expand all Loading... |
420 | 428 |
421 // Packet 2. | 429 // Packet 2. |
422 EXPECT_FALSE(creator_.HasPendingFrames()); | 430 EXPECT_FALSE(creator_.HasPendingFrames()); |
423 // Generate Packet 2 with one frame -- packet number length should now | 431 // Generate Packet 2 with one frame -- packet number length should now |
424 // change to 4 bytes. | 432 // change to 4 bytes. |
425 EXPECT_TRUE(creator_.AddSavedFrame(QuicFrame(&stop_waiting_frame))); | 433 EXPECT_TRUE(creator_.AddSavedFrame(QuicFrame(&stop_waiting_frame))); |
426 EXPECT_TRUE(creator_.HasPendingFrames()); | 434 EXPECT_TRUE(creator_.HasPendingFrames()); |
427 | 435 |
428 // Ensure the packet is successfully created. | 436 // Ensure the packet is successfully created. |
429 creator_.Flush(); | 437 creator_.Flush(); |
430 ASSERT_TRUE(serialized_packet_.packet); | 438 ASSERT_TRUE(serialized_packet_.encrypted_buffer); |
431 EXPECT_EQ(PACKET_4BYTE_PACKET_NUMBER, | 439 EXPECT_EQ(PACKET_4BYTE_PACKET_NUMBER, |
432 serialized_packet_.packet_number_length); | 440 serialized_packet_.packet_number_length); |
433 | 441 |
434 // Verify that header in transmitted packet has 4 byte sequence length. | 442 // Verify that header in transmitted packet has 4 byte sequence length. |
435 { | 443 { |
436 InSequence s; | 444 InSequence s; |
437 EXPECT_CALL(framer_visitor_, OnPacket()); | 445 EXPECT_CALL(framer_visitor_, OnPacket()); |
438 EXPECT_CALL(framer_visitor_, OnUnauthenticatedPublicHeader(_)); | 446 EXPECT_CALL(framer_visitor_, OnUnauthenticatedPublicHeader(_)); |
439 EXPECT_CALL(framer_visitor_, OnUnauthenticatedHeader(_)); | 447 EXPECT_CALL(framer_visitor_, OnUnauthenticatedHeader(_)); |
440 EXPECT_CALL(framer_visitor_, OnDecryptedPacket(_)); | 448 EXPECT_CALL(framer_visitor_, OnDecryptedPacket(_)); |
(...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
589 InSequence s; | 597 InSequence s; |
590 EXPECT_CALL(framer_visitor_, OnPacket()); | 598 EXPECT_CALL(framer_visitor_, OnPacket()); |
591 EXPECT_CALL(framer_visitor_, OnUnauthenticatedPublicHeader(_)); | 599 EXPECT_CALL(framer_visitor_, OnUnauthenticatedPublicHeader(_)); |
592 EXPECT_CALL(framer_visitor_, OnUnauthenticatedHeader(_)); | 600 EXPECT_CALL(framer_visitor_, OnUnauthenticatedHeader(_)); |
593 EXPECT_CALL(framer_visitor_, OnDecryptedPacket(_)); | 601 EXPECT_CALL(framer_visitor_, OnDecryptedPacket(_)); |
594 EXPECT_CALL(framer_visitor_, OnPacketHeader(_)); | 602 EXPECT_CALL(framer_visitor_, OnPacketHeader(_)); |
595 EXPECT_CALL(framer_visitor_, OnStreamFrame(_)); | 603 EXPECT_CALL(framer_visitor_, OnStreamFrame(_)); |
596 EXPECT_CALL(framer_visitor_, OnPacketComplete()); | 604 EXPECT_CALL(framer_visitor_, OnPacketComplete()); |
597 } | 605 } |
598 ProcessPacket(serialized); | 606 ProcessPacket(serialized); |
599 delete serialized.packet; | |
600 delete stream_frame; | 607 delete stream_frame; |
601 } | 608 } |
602 | 609 |
603 TEST_P(QuicPacketCreatorTest, ReserializeCryptoFrameWithForwardSecurity) { | 610 TEST_P(QuicPacketCreatorTest, ReserializeCryptoFrameWithForwardSecurity) { |
604 QuicStreamFrame* stream_frame = | 611 QuicStreamFrame* stream_frame = |
605 new QuicStreamFrame(kCryptoStreamId, /*fin=*/false, 0u, StringPiece()); | 612 new QuicStreamFrame(kCryptoStreamId, /*fin=*/false, 0u, StringPiece()); |
606 QuicFrames frames; | 613 QuicFrames frames; |
607 frames.push_back(QuicFrame(stream_frame)); | 614 frames.push_back(QuicFrame(stream_frame)); |
608 creator_.set_encryption_level(ENCRYPTION_FORWARD_SECURE); | 615 creator_.set_encryption_level(ENCRYPTION_FORWARD_SECURE); |
609 char buffer[kMaxPacketSize]; | 616 char buffer[kMaxPacketSize]; |
610 PendingRetransmission retransmission(CreateRetransmission( | 617 PendingRetransmission retransmission(CreateRetransmission( |
611 frames, true /* has_crypto_handshake */, true /* needs padding */, | 618 frames, true /* has_crypto_handshake */, true /* needs padding */, |
612 ENCRYPTION_NONE, | 619 ENCRYPTION_NONE, |
613 QuicPacketCreatorPeer::NextPacketNumberLength(&creator_))); | 620 QuicPacketCreatorPeer::NextPacketNumberLength(&creator_))); |
614 if (FLAGS_quic_retransmit_via_onserializedpacket) { | 621 if (FLAGS_quic_retransmit_via_onserializedpacket) { |
615 EXPECT_CALL(delegate_, OnSerializedPacket(_)) | 622 EXPECT_CALL(delegate_, OnSerializedPacket(_)) |
616 .WillOnce(Invoke(this, &QuicPacketCreatorTest::SaveSerializedPacket)); | 623 .WillOnce(Invoke(this, &QuicPacketCreatorTest::SaveSerializedPacket)); |
617 } | 624 } |
618 SerializedPacket serialized = | 625 SerializedPacket serialized = |
619 creator_.ReserializeAllFrames(retransmission, buffer, kMaxPacketSize); | 626 creator_.ReserializeAllFrames(retransmission, buffer, kMaxPacketSize); |
620 if (FLAGS_quic_retransmit_via_onserializedpacket) { | 627 if (FLAGS_quic_retransmit_via_onserializedpacket) { |
621 serialized = serialized_packet_; | 628 serialized = serialized_packet_; |
622 } | 629 } |
623 EXPECT_EQ(ENCRYPTION_NONE, serialized.encryption_level); | 630 EXPECT_EQ(ENCRYPTION_NONE, serialized.encryption_level); |
624 delete serialized.packet; | |
625 delete stream_frame; | 631 delete stream_frame; |
626 } | 632 } |
627 | 633 |
628 TEST_P(QuicPacketCreatorTest, ReserializeFrameWithForwardSecurity) { | 634 TEST_P(QuicPacketCreatorTest, ReserializeFrameWithForwardSecurity) { |
629 QuicStreamFrame* stream_frame = | 635 QuicStreamFrame* stream_frame = |
630 new QuicStreamFrame(0u, /*fin=*/false, 0u, StringPiece()); | 636 new QuicStreamFrame(0u, /*fin=*/false, 0u, StringPiece()); |
631 QuicFrames frames; | 637 QuicFrames frames; |
632 frames.push_back(QuicFrame(stream_frame)); | 638 frames.push_back(QuicFrame(stream_frame)); |
633 creator_.set_encryption_level(ENCRYPTION_FORWARD_SECURE); | 639 creator_.set_encryption_level(ENCRYPTION_FORWARD_SECURE); |
634 char buffer[kMaxPacketSize]; | 640 char buffer[kMaxPacketSize]; |
635 PendingRetransmission retransmission(CreateRetransmission( | 641 PendingRetransmission retransmission(CreateRetransmission( |
636 frames, false /* has_crypto_handshake */, false /* needs padding */, | 642 frames, false /* has_crypto_handshake */, false /* needs padding */, |
637 ENCRYPTION_NONE, | 643 ENCRYPTION_NONE, |
638 QuicPacketCreatorPeer::NextPacketNumberLength(&creator_))); | 644 QuicPacketCreatorPeer::NextPacketNumberLength(&creator_))); |
639 if (FLAGS_quic_retransmit_via_onserializedpacket) { | 645 if (FLAGS_quic_retransmit_via_onserializedpacket) { |
640 EXPECT_CALL(delegate_, OnSerializedPacket(_)) | 646 EXPECT_CALL(delegate_, OnSerializedPacket(_)) |
641 .WillOnce(Invoke(this, &QuicPacketCreatorTest::SaveSerializedPacket)); | 647 .WillOnce(Invoke(this, &QuicPacketCreatorTest::SaveSerializedPacket)); |
642 } | 648 } |
643 SerializedPacket serialized = | 649 SerializedPacket serialized = |
644 creator_.ReserializeAllFrames(retransmission, buffer, kMaxPacketSize); | 650 creator_.ReserializeAllFrames(retransmission, buffer, kMaxPacketSize); |
645 if (FLAGS_quic_retransmit_via_onserializedpacket) { | 651 if (FLAGS_quic_retransmit_via_onserializedpacket) { |
646 serialized = serialized_packet_; | 652 serialized = serialized_packet_; |
647 } | 653 } |
648 EXPECT_EQ(ENCRYPTION_FORWARD_SECURE, serialized.encryption_level); | 654 EXPECT_EQ(ENCRYPTION_FORWARD_SECURE, serialized.encryption_level); |
649 delete serialized.packet; | |
650 delete stream_frame; | 655 delete stream_frame; |
651 } | 656 } |
652 | 657 |
653 TEST_P(QuicPacketCreatorTest, ReserializeFramesWithPadding) { | 658 TEST_P(QuicPacketCreatorTest, ReserializeFramesWithPadding) { |
654 QuicFrame frame; | 659 QuicFrame frame; |
655 QuicIOVector io_vector(MakeIOVector("fake handshake message data")); | 660 QuicIOVector io_vector(MakeIOVector("fake handshake message data")); |
656 QuicPacketCreatorPeer::CreateStreamFrame(&creator_, kCryptoStreamId, | 661 QuicPacketCreatorPeer::CreateStreamFrame(&creator_, kCryptoStreamId, |
657 io_vector, 0u, 0u, false, &frame); | 662 io_vector, 0u, 0u, false, &frame); |
658 QuicFrames frames; | 663 QuicFrames frames; |
659 frames.push_back(frame); | 664 frames.push_back(frame); |
660 char buffer[kMaxPacketSize]; | 665 char buffer[kMaxPacketSize]; |
661 PendingRetransmission retransmission(CreateRetransmission( | 666 PendingRetransmission retransmission(CreateRetransmission( |
662 frames, true /* has_crypto_handshake */, true /* needs padding */, | 667 frames, true /* has_crypto_handshake */, true /* needs padding */, |
663 ENCRYPTION_NONE, | 668 ENCRYPTION_NONE, |
664 QuicPacketCreatorPeer::NextPacketNumberLength(&creator_))); | 669 QuicPacketCreatorPeer::NextPacketNumberLength(&creator_))); |
665 if (FLAGS_quic_retransmit_via_onserializedpacket) { | 670 if (FLAGS_quic_retransmit_via_onserializedpacket) { |
666 EXPECT_CALL(delegate_, OnSerializedPacket(_)) | 671 EXPECT_CALL(delegate_, OnSerializedPacket(_)) |
667 .WillOnce(Invoke(this, &QuicPacketCreatorTest::SaveSerializedPacket)); | 672 .WillOnce(Invoke(this, &QuicPacketCreatorTest::SaveSerializedPacket)); |
668 } | 673 } |
669 SerializedPacket serialized = | 674 SerializedPacket serialized = |
670 creator_.ReserializeAllFrames(retransmission, buffer, kMaxPacketSize); | 675 creator_.ReserializeAllFrames(retransmission, buffer, kMaxPacketSize); |
671 if (FLAGS_quic_retransmit_via_onserializedpacket) { | 676 if (FLAGS_quic_retransmit_via_onserializedpacket) { |
672 serialized = serialized_packet_; | 677 serialized = serialized_packet_; |
673 } | 678 } |
674 EXPECT_EQ(kDefaultMaxPacketSize, serialized.packet->length()); | 679 EXPECT_EQ(kDefaultMaxPacketSize, serialized.encrypted_length); |
675 delete serialized.packet; | |
676 delete frame.stream_frame; | 680 delete frame.stream_frame; |
677 } | 681 } |
678 | 682 |
679 TEST_P(QuicPacketCreatorTest, ReserializeFramesWithFullPacketAndPadding) { | 683 TEST_P(QuicPacketCreatorTest, ReserializeFramesWithFullPacketAndPadding) { |
680 const size_t overhead = GetPacketHeaderOverhead(NOT_IN_FEC_GROUP) + | 684 const size_t overhead = GetPacketHeaderOverhead(NOT_IN_FEC_GROUP) + |
681 GetEncryptionOverhead() + | 685 GetEncryptionOverhead() + |
682 GetStreamFrameOverhead(NOT_IN_FEC_GROUP); | 686 GetStreamFrameOverhead(NOT_IN_FEC_GROUP); |
683 size_t capacity = kDefaultMaxPacketSize - overhead; | 687 size_t capacity = kDefaultMaxPacketSize - overhead; |
684 for (int delta = -5; delta <= 0; ++delta) { | 688 for (int delta = -5; delta <= 0; ++delta) { |
685 string data(capacity + delta, 'A'); | 689 string data(capacity + delta, 'A'); |
(...skipping 19 matching lines...) Expand all Loading... |
705 creator_.ReserializeAllFrames(retransmission, buffer, kMaxPacketSize); | 709 creator_.ReserializeAllFrames(retransmission, buffer, kMaxPacketSize); |
706 if (FLAGS_quic_retransmit_via_onserializedpacket) { | 710 if (FLAGS_quic_retransmit_via_onserializedpacket) { |
707 serialized = serialized_packet_; | 711 serialized = serialized_packet_; |
708 } | 712 } |
709 | 713 |
710 // If there is not enough space in the packet to fit a padding frame | 714 // If there is not enough space in the packet to fit a padding frame |
711 // (1 byte) and to expand the stream frame (another 2 bytes) the packet | 715 // (1 byte) and to expand the stream frame (another 2 bytes) the packet |
712 // will not be padded. | 716 // will not be padded. |
713 if (bytes_free < 3) { | 717 if (bytes_free < 3) { |
714 EXPECT_EQ(kDefaultMaxPacketSize - bytes_free, | 718 EXPECT_EQ(kDefaultMaxPacketSize - bytes_free, |
715 serialized.packet->length()); | 719 serialized.encrypted_length); |
716 } else { | 720 } else { |
717 EXPECT_EQ(kDefaultMaxPacketSize, serialized.packet->length()); | 721 EXPECT_EQ(kDefaultMaxPacketSize, serialized.encrypted_length); |
718 } | 722 } |
719 | 723 |
720 delete serialized.packet; | |
721 delete frame.stream_frame; | 724 delete frame.stream_frame; |
722 frames_.clear(); | 725 frames_.clear(); |
723 } | 726 } |
724 } | 727 } |
725 | 728 |
726 TEST_P(QuicPacketCreatorTest, SerializeConnectionClose) { | 729 TEST_P(QuicPacketCreatorTest, SerializeConnectionClose) { |
727 QuicConnectionCloseFrame frame; | 730 QuicConnectionCloseFrame frame; |
728 frame.error_code = QUIC_NO_ERROR; | 731 frame.error_code = QUIC_NO_ERROR; |
729 frame.error_details = "error"; | 732 frame.error_details = "error"; |
730 | 733 |
731 QuicFrames frames; | 734 QuicFrames frames; |
732 frames.push_back(QuicFrame(&frame)); | 735 frames.push_back(QuicFrame(&frame)); |
733 SerializedPacket serialized = SerializeAllFrames(frames); | 736 SerializedPacket serialized = SerializeAllFrames(frames); |
734 EXPECT_EQ(ENCRYPTION_NONE, serialized.encryption_level); | 737 EXPECT_EQ(ENCRYPTION_NONE, serialized.encryption_level); |
735 ASSERT_EQ(1u, serialized.packet_number); | 738 ASSERT_EQ(1u, serialized.packet_number); |
736 ASSERT_EQ(1u, creator_.packet_number()); | 739 ASSERT_EQ(1u, creator_.packet_number()); |
737 | 740 |
738 InSequence s; | 741 InSequence s; |
739 EXPECT_CALL(framer_visitor_, OnPacket()); | 742 EXPECT_CALL(framer_visitor_, OnPacket()); |
740 EXPECT_CALL(framer_visitor_, OnUnauthenticatedPublicHeader(_)); | 743 EXPECT_CALL(framer_visitor_, OnUnauthenticatedPublicHeader(_)); |
741 EXPECT_CALL(framer_visitor_, OnUnauthenticatedHeader(_)); | 744 EXPECT_CALL(framer_visitor_, OnUnauthenticatedHeader(_)); |
742 EXPECT_CALL(framer_visitor_, OnDecryptedPacket(_)); | 745 EXPECT_CALL(framer_visitor_, OnDecryptedPacket(_)); |
743 EXPECT_CALL(framer_visitor_, OnPacketHeader(_)); | 746 EXPECT_CALL(framer_visitor_, OnPacketHeader(_)); |
744 EXPECT_CALL(framer_visitor_, OnConnectionCloseFrame(_)); | 747 EXPECT_CALL(framer_visitor_, OnConnectionCloseFrame(_)); |
745 EXPECT_CALL(framer_visitor_, OnPacketComplete()); | 748 EXPECT_CALL(framer_visitor_, OnPacketComplete()); |
746 | 749 |
747 ProcessPacket(serialized); | 750 ProcessPacket(serialized); |
748 delete serialized.packet; | |
749 } | 751 } |
750 | 752 |
751 TEST_P(QuicPacketCreatorTest, SwitchFecOnOffWithGroupInProgress) { | 753 TEST_P(QuicPacketCreatorTest, SwitchFecOnOffWithGroupInProgress) { |
752 // Send FEC packet every 6 packets. | 754 // Send FEC packet every 6 packets. |
753 creator_.set_max_packets_per_fec_group(6); | 755 creator_.set_max_packets_per_fec_group(6); |
754 // Turn on FEC protection. | 756 // Turn on FEC protection. |
755 QuicFrame frame; | 757 QuicFrame frame; |
756 QuicIOVector io_vector(MakeIOVector("test")); | 758 QuicIOVector io_vector(MakeIOVector("test")); |
757 ASSERT_TRUE(creator_.ConsumeData(1u, io_vector, 0u, 0u, false, false, &frame, | 759 ASSERT_TRUE(creator_.ConsumeData(1u, io_vector, 0u, 0u, false, false, &frame, |
758 MUST_FEC_PROTECT)); | 760 MUST_FEC_PROTECT)); |
(...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
907 ASSERT_TRUE(frame.stream_frame); | 909 ASSERT_TRUE(frame.stream_frame); |
908 | 910 |
909 // BytesFree() returns bytes available for the next frame, which will | 911 // BytesFree() returns bytes available for the next frame, which will |
910 // be two bytes smaller since the stream frame would need to be grown. | 912 // be two bytes smaller since the stream frame would need to be grown. |
911 EXPECT_EQ(2u, creator_.ExpansionOnNewFrame()); | 913 EXPECT_EQ(2u, creator_.ExpansionOnNewFrame()); |
912 size_t expected_bytes_free = bytes_free < 3 ? 0 : bytes_free - 2; | 914 size_t expected_bytes_free = bytes_free < 3 ? 0 : bytes_free - 2; |
913 EXPECT_EQ(expected_bytes_free, creator_.BytesFree()) << "delta: " << delta; | 915 EXPECT_EQ(expected_bytes_free, creator_.BytesFree()) << "delta: " << delta; |
914 EXPECT_CALL(delegate_, OnSerializedPacket(_)) | 916 EXPECT_CALL(delegate_, OnSerializedPacket(_)) |
915 .WillOnce(Invoke(this, &QuicPacketCreatorTest::SaveSerializedPacket)); | 917 .WillOnce(Invoke(this, &QuicPacketCreatorTest::SaveSerializedPacket)); |
916 creator_.Flush(); | 918 creator_.Flush(); |
917 ASSERT_TRUE(serialized_packet_.packet); | 919 ASSERT_TRUE(serialized_packet_.encrypted_buffer); |
918 DeleteSerializedPacket(); | 920 DeleteSerializedPacket(); |
919 } | 921 } |
920 } | 922 } |
921 | 923 |
922 TEST_P(QuicPacketCreatorTest, StreamFrameConsumptionWithFec) { | 924 TEST_P(QuicPacketCreatorTest, StreamFrameConsumptionWithFec) { |
923 // Send FEC packet every 6 packets. | 925 // Send FEC packet every 6 packets. |
924 creator_.set_max_packets_per_fec_group(6); | 926 creator_.set_max_packets_per_fec_group(6); |
925 // Turn on FEC protection. | 927 // Turn on FEC protection. |
926 QuicFrame frame; | 928 QuicFrame frame; |
927 QuicIOVector io_vector(MakeIOVector("test")); | 929 QuicIOVector io_vector(MakeIOVector("test")); |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
959 EXPECT_CALL(delegate_, OnSerializedPacket(_)) | 961 EXPECT_CALL(delegate_, OnSerializedPacket(_)) |
960 .WillOnce(Invoke(this, &QuicPacketCreatorTest::SaveSerializedPacket)); | 962 .WillOnce(Invoke(this, &QuicPacketCreatorTest::SaveSerializedPacket)); |
961 // Every 6th packet will generate an extra FEC packet. | 963 // Every 6th packet will generate an extra FEC packet. |
962 if (delta == -1 || delta == 5) { | 964 if (delta == -1 || delta == 5) { |
963 EXPECT_CALL(delegate_, OnSerializedPacket(_)) | 965 EXPECT_CALL(delegate_, OnSerializedPacket(_)) |
964 .WillOnce( | 966 .WillOnce( |
965 Invoke(this, &QuicPacketCreatorTest::ClearSerializedPacket)); | 967 Invoke(this, &QuicPacketCreatorTest::ClearSerializedPacket)); |
966 } | 968 } |
967 } | 969 } |
968 creator_.Flush(); | 970 creator_.Flush(); |
969 ASSERT_TRUE(serialized_packet_.packet); | 971 ASSERT_TRUE(serialized_packet_.encrypted_buffer); |
970 DeleteSerializedPacket(); | 972 DeleteSerializedPacket(); |
971 } | 973 } |
972 } | 974 } |
973 | 975 |
974 TEST_P(QuicPacketCreatorTest, CryptoStreamFramePacketPadding) { | 976 TEST_P(QuicPacketCreatorTest, CryptoStreamFramePacketPadding) { |
975 // Compute the total overhead for a single frame in packet. | 977 // Compute the total overhead for a single frame in packet. |
976 const size_t overhead = GetPacketHeaderOverhead(NOT_IN_FEC_GROUP) + | 978 const size_t overhead = GetPacketHeaderOverhead(NOT_IN_FEC_GROUP) + |
977 GetEncryptionOverhead() + | 979 GetEncryptionOverhead() + |
978 GetStreamFrameOverhead(NOT_IN_FEC_GROUP); | 980 GetStreamFrameOverhead(NOT_IN_FEC_GROUP); |
979 ASSERT_GT(kMaxPacketSize, overhead); | 981 ASSERT_GT(kMaxPacketSize, overhead); |
980 size_t capacity = kDefaultMaxPacketSize - overhead; | 982 size_t capacity = kDefaultMaxPacketSize - overhead; |
981 // Now, test various sizes around this size. | 983 // Now, test various sizes around this size. |
982 for (int delta = -5; delta <= 5; ++delta) { | 984 for (int delta = -5; delta <= 5; ++delta) { |
983 string data(capacity + delta, 'A'); | 985 string data(capacity + delta, 'A'); |
984 size_t bytes_free = delta > 0 ? 0 : 0 - delta; | 986 size_t bytes_free = delta > 0 ? 0 : 0 - delta; |
985 | 987 |
986 QuicFrame frame; | 988 QuicFrame frame; |
987 QuicIOVector io_vector(MakeIOVector(data)); | 989 QuicIOVector io_vector(MakeIOVector(data)); |
988 EXPECT_CALL(delegate_, OnSerializedPacket(_)) | 990 EXPECT_CALL(delegate_, OnSerializedPacket(_)) |
989 .WillRepeatedly( | 991 .WillRepeatedly( |
990 Invoke(this, &QuicPacketCreatorTest::SaveSerializedPacket)); | 992 Invoke(this, &QuicPacketCreatorTest::SaveSerializedPacket)); |
991 ASSERT_TRUE(creator_.ConsumeData(kCryptoStreamId, io_vector, 0u, kOffset, | 993 ASSERT_TRUE(creator_.ConsumeData(kCryptoStreamId, io_vector, 0u, kOffset, |
992 false, true, &frame, MAY_FEC_PROTECT)); | 994 false, true, &frame, MAY_FEC_PROTECT)); |
993 ASSERT_TRUE(frame.stream_frame); | 995 ASSERT_TRUE(frame.stream_frame); |
994 size_t bytes_consumed = frame.stream_frame->frame_length; | 996 size_t bytes_consumed = frame.stream_frame->frame_length; |
995 EXPECT_LT(0u, bytes_consumed); | 997 EXPECT_LT(0u, bytes_consumed); |
996 creator_.Flush(); | 998 creator_.Flush(); |
997 ASSERT_TRUE(serialized_packet_.packet); | 999 ASSERT_TRUE(serialized_packet_.encrypted_buffer); |
998 // If there is not enough space in the packet to fit a padding frame | 1000 // If there is not enough space in the packet to fit a padding frame |
999 // (1 byte) and to expand the stream frame (another 2 bytes) the packet | 1001 // (1 byte) and to expand the stream frame (another 2 bytes) the packet |
1000 // will not be padded. | 1002 // will not be padded. |
1001 if (bytes_free < 3) { | 1003 if (bytes_free < 3) { |
1002 EXPECT_EQ(kDefaultMaxPacketSize - bytes_free, | 1004 EXPECT_EQ(kDefaultMaxPacketSize - bytes_free, |
1003 serialized_packet_.packet->length()); | 1005 serialized_packet_.encrypted_length); |
1004 } else { | 1006 } else { |
1005 EXPECT_EQ(kDefaultMaxPacketSize, serialized_packet_.packet->length()); | 1007 EXPECT_EQ(kDefaultMaxPacketSize, serialized_packet_.encrypted_length); |
1006 } | 1008 } |
1007 DeleteSerializedPacket(); | 1009 DeleteSerializedPacket(); |
1008 } | 1010 } |
1009 } | 1011 } |
1010 | 1012 |
1011 TEST_P(QuicPacketCreatorTest, NonCryptoStreamFramePacketNonPadding) { | 1013 TEST_P(QuicPacketCreatorTest, NonCryptoStreamFramePacketNonPadding) { |
1012 // Compute the total overhead for a single frame in packet. | 1014 // Compute the total overhead for a single frame in packet. |
1013 const size_t overhead = GetPacketHeaderOverhead(NOT_IN_FEC_GROUP) + | 1015 const size_t overhead = GetPacketHeaderOverhead(NOT_IN_FEC_GROUP) + |
1014 GetEncryptionOverhead() + | 1016 GetEncryptionOverhead() + |
1015 GetStreamFrameOverhead(NOT_IN_FEC_GROUP); | 1017 GetStreamFrameOverhead(NOT_IN_FEC_GROUP); |
1016 ASSERT_GT(kDefaultMaxPacketSize, overhead); | 1018 ASSERT_GT(kDefaultMaxPacketSize, overhead); |
1017 size_t capacity = kDefaultMaxPacketSize - overhead; | 1019 size_t capacity = kDefaultMaxPacketSize - overhead; |
1018 // Now, test various sizes around this size. | 1020 // Now, test various sizes around this size. |
1019 for (int delta = -5; delta <= 5; ++delta) { | 1021 for (int delta = -5; delta <= 5; ++delta) { |
1020 string data(capacity + delta, 'A'); | 1022 string data(capacity + delta, 'A'); |
1021 size_t bytes_free = delta > 0 ? 0 : 0 - delta; | 1023 size_t bytes_free = delta > 0 ? 0 : 0 - delta; |
1022 | 1024 |
1023 QuicFrame frame; | 1025 QuicFrame frame; |
1024 QuicIOVector io_vector(MakeIOVector(data)); | 1026 QuicIOVector io_vector(MakeIOVector(data)); |
1025 EXPECT_CALL(delegate_, OnSerializedPacket(_)) | 1027 EXPECT_CALL(delegate_, OnSerializedPacket(_)) |
1026 .WillOnce(Invoke(this, &QuicPacketCreatorTest::SaveSerializedPacket)); | 1028 .WillOnce(Invoke(this, &QuicPacketCreatorTest::SaveSerializedPacket)); |
1027 ASSERT_TRUE(creator_.ConsumeData(kClientDataStreamId1, io_vector, 0u, | 1029 ASSERT_TRUE(creator_.ConsumeData(kClientDataStreamId1, io_vector, 0u, |
1028 kOffset, false, false, &frame, | 1030 kOffset, false, false, &frame, |
1029 MAY_FEC_PROTECT)); | 1031 MAY_FEC_PROTECT)); |
1030 ASSERT_TRUE(frame.stream_frame); | 1032 ASSERT_TRUE(frame.stream_frame); |
1031 size_t bytes_consumed = frame.stream_frame->frame_length; | 1033 size_t bytes_consumed = frame.stream_frame->frame_length; |
1032 EXPECT_LT(0u, bytes_consumed); | 1034 EXPECT_LT(0u, bytes_consumed); |
1033 creator_.Flush(); | 1035 creator_.Flush(); |
1034 ASSERT_TRUE(serialized_packet_.packet); | 1036 ASSERT_TRUE(serialized_packet_.encrypted_buffer); |
1035 if (bytes_free > 0) { | 1037 if (bytes_free > 0) { |
1036 EXPECT_EQ(kDefaultMaxPacketSize - bytes_free, | 1038 EXPECT_EQ(kDefaultMaxPacketSize - bytes_free, |
1037 serialized_packet_.packet->length()); | 1039 serialized_packet_.encrypted_length); |
1038 } else { | 1040 } else { |
1039 EXPECT_EQ(kDefaultMaxPacketSize, serialized_packet_.packet->length()); | 1041 EXPECT_EQ(kDefaultMaxPacketSize, serialized_packet_.encrypted_length); |
1040 } | 1042 } |
1041 DeleteSerializedPacket(); | 1043 DeleteSerializedPacket(); |
1042 } | 1044 } |
1043 } | 1045 } |
1044 | 1046 |
1045 TEST_P(QuicPacketCreatorTest, SerializeVersionNegotiationPacket) { | 1047 TEST_P(QuicPacketCreatorTest, SerializeVersionNegotiationPacket) { |
1046 QuicFramerPeer::SetPerspective(&client_framer_, Perspective::IS_SERVER); | 1048 QuicFramerPeer::SetPerspective(&client_framer_, Perspective::IS_SERVER); |
1047 QuicVersionVector versions; | 1049 QuicVersionVector versions; |
1048 versions.push_back(test::QuicVersionMax()); | 1050 versions.push_back(test::QuicVersionMax()); |
1049 scoped_ptr<QuicEncryptedPacket> encrypted( | 1051 scoped_ptr<QuicEncryptedPacket> encrypted( |
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1131 EXPECT_CALL(framer_visitor_, OnUnauthenticatedHeader(_)); | 1133 EXPECT_CALL(framer_visitor_, OnUnauthenticatedHeader(_)); |
1132 EXPECT_CALL(framer_visitor_, OnDecryptedPacket(_)); | 1134 EXPECT_CALL(framer_visitor_, OnDecryptedPacket(_)); |
1133 EXPECT_CALL(framer_visitor_, OnPacketHeader(_)) | 1135 EXPECT_CALL(framer_visitor_, OnPacketHeader(_)) |
1134 .WillOnce(DoAll(SaveArg<0>(&header), Return(true))); | 1136 .WillOnce(DoAll(SaveArg<0>(&header), Return(true))); |
1135 EXPECT_CALL(framer_visitor_, OnStreamFrame(_)); | 1137 EXPECT_CALL(framer_visitor_, OnStreamFrame(_)); |
1136 EXPECT_CALL(framer_visitor_, OnPacketComplete()); | 1138 EXPECT_CALL(framer_visitor_, OnPacketComplete()); |
1137 } | 1139 } |
1138 ProcessPacket(serialized); | 1140 ProcessPacket(serialized); |
1139 EXPECT_EQ(GetParam().version_serialization, | 1141 EXPECT_EQ(GetParam().version_serialization, |
1140 header.public_header.version_flag); | 1142 header.public_header.version_flag); |
1141 delete serialized.packet; | |
1142 } | 1143 } |
1143 | 1144 |
1144 TEST_P(QuicPacketCreatorTest, ConsumeDataLargerThanOneStreamFrame) { | 1145 TEST_P(QuicPacketCreatorTest, ConsumeDataLargerThanOneStreamFrame) { |
1145 if (!GetParam().version_serialization) { | 1146 if (!GetParam().version_serialization) { |
1146 creator_.StopSendingVersion(); | 1147 creator_.StopSendingVersion(); |
1147 } | 1148 } |
1148 // A string larger than fits into a frame. | 1149 // A string larger than fits into a frame. |
1149 size_t payload_length; | 1150 size_t payload_length; |
1150 creator_.SetMaxPacketLength(GetPacketLengthForOneStream( | 1151 creator_.SetMaxPacketLength(GetPacketLengthForOneStream( |
1151 client_framer_.version(), | 1152 client_framer_.version(), |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1202 EXPECT_TRUE(creator_.AddSavedFrame(QuicFrame(padding_frame))); | 1203 EXPECT_TRUE(creator_.AddSavedFrame(QuicFrame(padding_frame))); |
1203 EXPECT_TRUE(creator_.HasPendingFrames()); | 1204 EXPECT_TRUE(creator_.HasPendingFrames()); |
1204 EXPECT_EQ(0u, creator_.BytesFree()); | 1205 EXPECT_EQ(0u, creator_.BytesFree()); |
1205 | 1206 |
1206 // Packet is full. Creator will flush. | 1207 // Packet is full. Creator will flush. |
1207 EXPECT_CALL(delegate_, OnSerializedPacket(_)) | 1208 EXPECT_CALL(delegate_, OnSerializedPacket(_)) |
1208 .WillOnce(Invoke(this, &QuicPacketCreatorTest::SaveSerializedPacket)); | 1209 .WillOnce(Invoke(this, &QuicPacketCreatorTest::SaveSerializedPacket)); |
1209 EXPECT_FALSE(creator_.AddSavedFrame(QuicFrame(&ack_frame))); | 1210 EXPECT_FALSE(creator_.AddSavedFrame(QuicFrame(&ack_frame))); |
1210 | 1211 |
1211 // Ensure the packet is successfully created. | 1212 // Ensure the packet is successfully created. |
1212 ASSERT_TRUE(serialized_packet_.packet); | 1213 ASSERT_TRUE(serialized_packet_.encrypted_buffer); |
1213 ASSERT_FALSE(serialized_packet_.retransmittable_frames.empty()); | 1214 ASSERT_FALSE(serialized_packet_.retransmittable_frames.empty()); |
1214 const QuicFrames& retransmittable = serialized_packet_.retransmittable_frames; | 1215 const QuicFrames& retransmittable = serialized_packet_.retransmittable_frames; |
1215 ASSERT_EQ(1u, retransmittable.size()); | 1216 ASSERT_EQ(1u, retransmittable.size()); |
1216 EXPECT_EQ(STREAM_FRAME, retransmittable[0].type); | 1217 EXPECT_EQ(STREAM_FRAME, retransmittable[0].type); |
1217 ASSERT_TRUE(retransmittable[0].stream_frame); | 1218 ASSERT_TRUE(retransmittable[0].stream_frame); |
1218 DeleteSerializedPacket(); | 1219 DeleteSerializedPacket(); |
1219 | 1220 |
1220 EXPECT_FALSE(creator_.HasPendingFrames()); | 1221 EXPECT_FALSE(creator_.HasPendingFrames()); |
1221 EXPECT_EQ(max_plaintext_size - | 1222 EXPECT_EQ(max_plaintext_size - |
1222 GetPacketHeaderSize( | 1223 GetPacketHeaderSize( |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1258 EXPECT_EQ(4u, consumed); | 1259 EXPECT_EQ(4u, consumed); |
1259 EXPECT_TRUE(creator_.HasPendingFrames()); | 1260 EXPECT_TRUE(creator_.HasPendingFrames()); |
1260 | 1261 |
1261 // Ensure the packet is successfully created, and the packet size estimate | 1262 // Ensure the packet is successfully created, and the packet size estimate |
1262 // matches the serialized packet length. | 1263 // matches the serialized packet length. |
1263 EXPECT_CALL(entropy_calculator_, EntropyHash(_)).WillOnce(testing::Return(0)); | 1264 EXPECT_CALL(entropy_calculator_, EntropyHash(_)).WillOnce(testing::Return(0)); |
1264 EXPECT_CALL(delegate_, OnSerializedPacket(_)) | 1265 EXPECT_CALL(delegate_, OnSerializedPacket(_)) |
1265 .WillOnce(Invoke(this, &QuicPacketCreatorTest::SaveSerializedPacket)); | 1266 .WillOnce(Invoke(this, &QuicPacketCreatorTest::SaveSerializedPacket)); |
1266 size_t est_packet_size = creator_.PacketSize(); | 1267 size_t est_packet_size = creator_.PacketSize(); |
1267 creator_.Flush(); | 1268 creator_.Flush(); |
1268 ASSERT_TRUE(serialized_packet_.packet); | 1269 ASSERT_TRUE(serialized_packet_.encrypted_buffer); |
1269 EXPECT_EQ(est_packet_size, client_framer_.GetMaxPlaintextSize( | 1270 EXPECT_EQ(est_packet_size, client_framer_.GetMaxPlaintextSize( |
1270 serialized_packet_.packet->length())); | 1271 serialized_packet_.encrypted_length)); |
1271 DeleteSerializedPacket(); | 1272 DeleteSerializedPacket(); |
1272 } | 1273 } |
1273 | 1274 |
1274 TEST_P(QuicPacketCreatorTest, SerializeTruncatedAckFrameWithSmallPacketSize) { | 1275 TEST_P(QuicPacketCreatorTest, SerializeTruncatedAckFrameWithSmallPacketSize) { |
1275 if (!GetParam().version_serialization) { | 1276 if (!GetParam().version_serialization) { |
1276 creator_.StopSendingVersion(); | 1277 creator_.StopSendingVersion(); |
1277 } | 1278 } |
1278 creator_.SetMaxPacketLength(500u); | 1279 creator_.SetMaxPacketLength(500u); |
1279 | 1280 |
1280 const size_t max_plaintext_size = | 1281 const size_t max_plaintext_size = |
(...skipping 15 matching lines...) Expand all Loading... |
1296 creator_.PacketSize()); | 1297 creator_.PacketSize()); |
1297 EXPECT_EQ(0u, creator_.BytesFree()); | 1298 EXPECT_EQ(0u, creator_.BytesFree()); |
1298 | 1299 |
1299 // Ensure the packet is successfully created, and the packet size estimate | 1300 // Ensure the packet is successfully created, and the packet size estimate |
1300 // may not match the serialized packet length. | 1301 // may not match the serialized packet length. |
1301 EXPECT_CALL(entropy_calculator_, EntropyHash(_)).WillOnce(Return(0)); | 1302 EXPECT_CALL(entropy_calculator_, EntropyHash(_)).WillOnce(Return(0)); |
1302 size_t est_packet_size = creator_.PacketSize(); | 1303 size_t est_packet_size = creator_.PacketSize(); |
1303 EXPECT_CALL(delegate_, OnSerializedPacket(_)) | 1304 EXPECT_CALL(delegate_, OnSerializedPacket(_)) |
1304 .WillOnce(Invoke(this, &QuicPacketCreatorTest::SaveSerializedPacket)); | 1305 .WillOnce(Invoke(this, &QuicPacketCreatorTest::SaveSerializedPacket)); |
1305 creator_.Flush(); | 1306 creator_.Flush(); |
1306 ASSERT_TRUE(serialized_packet_.packet); | 1307 ASSERT_TRUE(serialized_packet_.encrypted_buffer); |
1307 EXPECT_GE(est_packet_size, client_framer_.GetMaxPlaintextSize( | 1308 EXPECT_GE(est_packet_size, client_framer_.GetMaxPlaintextSize( |
1308 serialized_packet_.packet->length())); | 1309 serialized_packet_.encrypted_length)); |
1309 DeleteSerializedPacket(); | 1310 DeleteSerializedPacket(); |
1310 } | 1311 } |
1311 | 1312 |
1312 TEST_P(QuicPacketCreatorTest, EntropyFlag) { | 1313 TEST_P(QuicPacketCreatorTest, EntropyFlag) { |
1313 frames_.push_back( | 1314 frames_.push_back( |
1314 QuicFrame(new QuicStreamFrame(0u, false, 0u, StringPiece()))); | 1315 QuicFrame(new QuicStreamFrame(0u, false, 0u, StringPiece()))); |
1315 | 1316 |
1316 for (int i = 0; i < 2; ++i) { | 1317 for (int i = 0; i < 2; ++i) { |
1317 for (int j = 0; j < 64; ++j) { | 1318 for (int j = 0; j < 64; ++j) { |
1318 SerializedPacket serialized = SerializeAllFrames(frames_); | 1319 SerializedPacket serialized = SerializeAllFrames(frames_); |
1319 // Verify both BoolSource and hash algorithm. | 1320 // Verify both BoolSource and hash algorithm. |
1320 bool expected_rand_bool = | 1321 bool expected_rand_bool = |
1321 (mock_random_.RandUint64() & (UINT64_C(1) << j)) != 0; | 1322 (mock_random_.RandUint64() & (UINT64_C(1) << j)) != 0; |
1322 bool observed_rand_bool = | 1323 bool observed_rand_bool = |
1323 (serialized.entropy_hash & (1 << ((j + 1) % 8))) != 0; | 1324 (serialized.entropy_hash & (1 << ((j + 1) % 8))) != 0; |
1324 uint8_t rest_of_hash = serialized.entropy_hash & ~(1 << ((j + 1) % 8)); | 1325 uint8_t rest_of_hash = serialized.entropy_hash & ~(1 << ((j + 1) % 8)); |
1325 EXPECT_EQ(expected_rand_bool, observed_rand_bool); | 1326 EXPECT_EQ(expected_rand_bool, observed_rand_bool); |
1326 EXPECT_EQ(0, rest_of_hash); | 1327 EXPECT_EQ(0, rest_of_hash); |
1327 delete serialized.packet; | |
1328 } | 1328 } |
1329 // After 64 calls, BoolSource will refresh the bucket - make sure it does. | 1329 // After 64 calls, BoolSource will refresh the bucket - make sure it does. |
1330 mock_random_.ChangeValue(); | 1330 mock_random_.ChangeValue(); |
1331 } | 1331 } |
1332 | 1332 |
1333 delete frames_[0].stream_frame; | 1333 delete frames_[0].stream_frame; |
1334 } | 1334 } |
1335 | 1335 |
1336 TEST_P(QuicPacketCreatorTest, ResetFecGroup) { | 1336 TEST_P(QuicPacketCreatorTest, ResetFecGroup) { |
1337 // Send FEC packet every 6 packets. | 1337 // Send FEC packet every 6 packets. |
(...skipping 358 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1696 EXPECT_CALL(delegate_, CloseConnection(QUIC_UNENCRYPTED_FEC_DATA, _)); | 1696 EXPECT_CALL(delegate_, CloseConnection(QUIC_UNENCRYPTED_FEC_DATA, _)); |
1697 char seralized_fec_buffer[kMaxPacketSize]; | 1697 char seralized_fec_buffer[kMaxPacketSize]; |
1698 EXPECT_DFATAL(QuicPacketCreatorPeer::SerializeFec( | 1698 EXPECT_DFATAL(QuicPacketCreatorPeer::SerializeFec( |
1699 &creator_, seralized_fec_buffer, kMaxPacketSize), | 1699 &creator_, seralized_fec_buffer, kMaxPacketSize), |
1700 "SerializeFEC must be called with encryption."); | 1700 "SerializeFEC must be called with encryption."); |
1701 } | 1701 } |
1702 | 1702 |
1703 } // namespace | 1703 } // namespace |
1704 } // namespace test | 1704 } // namespace test |
1705 } // namespace net | 1705 } // namespace net |
OLD | NEW |