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

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

Issue 2828543002: Let QUIC be able to add random padding of [1,256] bytes after fin is consumed for a stream. Random … (Closed)
Patch Set: Created 3 years, 8 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
« no previous file with comments | « net/quic/core/quic_packet_creator.cc ('k') | net/quic/core/quic_packet_generator.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/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 <ostream> 9 #include <ostream>
10 #include <string> 10 #include <string>
(...skipping 341 matching lines...) Expand 10 before | Expand all | Expand 10 after
352 frames, true /* has_crypto_handshake */, -1 /* needs full padding */, 352 frames, true /* has_crypto_handshake */, -1 /* needs full padding */,
353 ENCRYPTION_NONE, 353 ENCRYPTION_NONE,
354 QuicPacketCreatorPeer::GetPacketNumberLength(&creator_))); 354 QuicPacketCreatorPeer::GetPacketNumberLength(&creator_)));
355 EXPECT_CALL(delegate_, OnSerializedPacket(_)) 355 EXPECT_CALL(delegate_, OnSerializedPacket(_))
356 .WillOnce(Invoke(this, &QuicPacketCreatorTest::SaveSerializedPacket)); 356 .WillOnce(Invoke(this, &QuicPacketCreatorTest::SaveSerializedPacket));
357 creator_.ReserializeAllFrames(retransmission, buffer, kMaxPacketSize); 357 creator_.ReserializeAllFrames(retransmission, buffer, kMaxPacketSize);
358 EXPECT_EQ(kDefaultMaxPacketSize, serialized_packet_.encrypted_length); 358 EXPECT_EQ(kDefaultMaxPacketSize, serialized_packet_.encrypted_length);
359 delete frame.stream_frame; 359 delete frame.stream_frame;
360 } 360 }
361 361
362 TEST_P(QuicPacketCreatorTest, ReserializeFramesWithSpecifiedPadding) { 362 TEST_P(QuicPacketCreatorTest, DoNotRetransmitPendingPadding) {
363 QuicFrame frame; 363 QuicFrame frame;
364 QuicIOVector io_vector(MakeIOVectorFromStringPiece("fake message data")); 364 QuicIOVector io_vector(MakeIOVectorFromStringPiece("fake message data"));
365 QuicPacketCreatorPeer::CreateStreamFrame(&creator_, kCryptoStreamId, 365 QuicPacketCreatorPeer::CreateStreamFrame(&creator_, kCryptoStreamId,
366 io_vector, 0u, 0u, false, &frame); 366 io_vector, 0u, 0u, false, &frame);
367 367
368 const int kNumPaddingBytes1 = 4; 368 const int kNumPaddingBytes1 = 4;
369 int packet_size = 0; 369 int packet_size = 0;
370 { 370 {
371 QuicFrames frames; 371 QuicFrames frames;
372 frames.push_back(frame); 372 frames.push_back(frame);
373 char buffer[kMaxPacketSize]; 373 char buffer[kMaxPacketSize];
374 QuicPendingRetransmission retransmission(CreateRetransmission( 374 QuicPendingRetransmission retransmission(CreateRetransmission(
375 frames, false /* has_crypto_handshake */, 375 frames, false /* has_crypto_handshake */,
376 kNumPaddingBytes1 /* padding bytes */, ENCRYPTION_NONE, 376 kNumPaddingBytes1 /* padding bytes */, ENCRYPTION_NONE,
377 QuicPacketCreatorPeer::GetPacketNumberLength(&creator_))); 377 QuicPacketCreatorPeer::GetPacketNumberLength(&creator_)));
378 EXPECT_CALL(delegate_, OnSerializedPacket(_)) 378 EXPECT_CALL(delegate_, OnSerializedPacket(_))
379 .WillOnce(Invoke(this, &QuicPacketCreatorTest::SaveSerializedPacket)); 379 .WillOnce(Invoke(this, &QuicPacketCreatorTest::SaveSerializedPacket));
380 creator_.ReserializeAllFrames(retransmission, buffer, kMaxPacketSize); 380 creator_.ReserializeAllFrames(retransmission, buffer, kMaxPacketSize);
381 packet_size = serialized_packet_.encrypted_length; 381 packet_size = serialized_packet_.encrypted_length;
382 } 382 }
383 383
384 {
385 InSequence s;
386 EXPECT_CALL(framer_visitor_, OnPacket());
387 EXPECT_CALL(framer_visitor_, OnUnauthenticatedPublicHeader(_));
388 EXPECT_CALL(framer_visitor_, OnUnauthenticatedHeader(_));
389 EXPECT_CALL(framer_visitor_, OnDecryptedPacket(_));
390 EXPECT_CALL(framer_visitor_, OnPacketHeader(_));
391 EXPECT_CALL(framer_visitor_, OnStreamFrame(_));
392 // Pending paddings are not retransmitted.
393 EXPECT_CALL(framer_visitor_, OnPaddingFrame(_)).Times(0);
394 EXPECT_CALL(framer_visitor_, OnPacketComplete());
395 }
396 ProcessPacket(serialized_packet_);
397
384 const int kNumPaddingBytes2 = 44; 398 const int kNumPaddingBytes2 = 44;
385 QuicFrames frames; 399 QuicFrames frames;
386 frames.push_back(frame); 400 frames.push_back(frame);
387 char buffer[kMaxPacketSize]; 401 char buffer[kMaxPacketSize];
388 QuicPendingRetransmission retransmission(CreateRetransmission( 402 QuicPendingRetransmission retransmission(CreateRetransmission(
389 frames, false /* has_crypto_handshake */, 403 frames, false /* has_crypto_handshake */,
390 kNumPaddingBytes2 /* padding bytes */, ENCRYPTION_NONE, 404 kNumPaddingBytes2 /* padding bytes */, ENCRYPTION_NONE,
391 QuicPacketCreatorPeer::GetPacketNumberLength(&creator_))); 405 QuicPacketCreatorPeer::GetPacketNumberLength(&creator_)));
392 EXPECT_CALL(delegate_, OnSerializedPacket(_)) 406 EXPECT_CALL(delegate_, OnSerializedPacket(_))
393 .WillOnce(Invoke(this, &QuicPacketCreatorTest::SaveSerializedPacket)); 407 .WillOnce(Invoke(this, &QuicPacketCreatorTest::SaveSerializedPacket));
394 creator_.ReserializeAllFrames(retransmission, buffer, kMaxPacketSize); 408 creator_.ReserializeAllFrames(retransmission, buffer, kMaxPacketSize);
395 409
396 EXPECT_EQ(packet_size + kNumPaddingBytes2 - kNumPaddingBytes1, 410 EXPECT_EQ(packet_size, serialized_packet_.encrypted_length);
397 serialized_packet_.encrypted_length);
398 delete frame.stream_frame; 411 delete frame.stream_frame;
399 } 412 }
400 413
401 TEST_P(QuicPacketCreatorTest, ReserializeFramesWithFullPacketAndPadding) { 414 TEST_P(QuicPacketCreatorTest, ReserializeFramesWithFullPacketAndPadding) {
402 const size_t overhead = GetPacketHeaderOverhead(client_framer_.version()) + 415 const size_t overhead = GetPacketHeaderOverhead(client_framer_.version()) +
403 GetEncryptionOverhead() + GetStreamFrameOverhead(); 416 GetEncryptionOverhead() + GetStreamFrameOverhead();
404 size_t capacity = kDefaultMaxPacketSize - overhead; 417 size_t capacity = kDefaultMaxPacketSize - overhead;
405 for (int delta = -5; delta <= 0; ++delta) { 418 for (int delta = -5; delta <= 0; ++delta) {
406 string data(capacity + delta, 'A'); 419 string data(capacity + delta, 'A');
407 size_t bytes_free = 0 - delta; 420 size_t bytes_free = 0 - delta;
(...skipping 438 matching lines...) Expand 10 before | Expand all | Expand 10 after
846 QuicIOVector data_iovec(MakeIOVector( 859 QuicIOVector data_iovec(MakeIOVector(
847 QuicStringPiece(message_data->data(), message_data->length()), &iov)); 860 QuicStringPiece(message_data->data(), message_data->length()), &iov));
848 QuicFrame frame; 861 QuicFrame frame;
849 EXPECT_CALL(delegate_, 862 EXPECT_CALL(delegate_,
850 OnUnrecoverableError(QUIC_CRYPTO_CHLO_TOO_LARGE, _, _)); 863 OnUnrecoverableError(QUIC_CRYPTO_CHLO_TOO_LARGE, _, _));
851 EXPECT_QUIC_BUG(creator_.ConsumeData(kCryptoStreamId, data_iovec, 0u, 0u, 864 EXPECT_QUIC_BUG(creator_.ConsumeData(kCryptoStreamId, data_iovec, 0u, 0u,
852 false, false, &frame), 865 false, false, &frame),
853 "Client hello won't fit in a single packet."); 866 "Client hello won't fit in a single packet.");
854 } 867 }
855 868
869 TEST_P(QuicPacketCreatorTest, PendingPadding) {
870 EXPECT_EQ(0u, creator_.pending_padding_bytes());
871 creator_.AddPendingPadding(kMaxNumRandomPaddingBytes * 10);
872 EXPECT_EQ(kMaxNumRandomPaddingBytes * 10, creator_.pending_padding_bytes());
873
874 EXPECT_CALL(delegate_, OnSerializedPacket(_))
875 .WillRepeatedly(
876 Invoke(this, &QuicPacketCreatorTest::SaveSerializedPacket));
877 // Flush all paddings.
878 while (creator_.pending_padding_bytes() > 0) {
879 creator_.Flush();
880 {
881 InSequence s;
882 EXPECT_CALL(framer_visitor_, OnPacket());
883 EXPECT_CALL(framer_visitor_, OnUnauthenticatedPublicHeader(_));
884 EXPECT_CALL(framer_visitor_, OnUnauthenticatedHeader(_));
885 EXPECT_CALL(framer_visitor_, OnDecryptedPacket(_));
886 EXPECT_CALL(framer_visitor_, OnPacketHeader(_));
887 EXPECT_CALL(framer_visitor_, OnPaddingFrame(_));
888 EXPECT_CALL(framer_visitor_, OnPacketComplete());
889 }
890 // Packet only contains padding.
891 ProcessPacket(serialized_packet_);
892 }
893 EXPECT_EQ(0u, creator_.pending_padding_bytes());
894 }
895
896 TEST_P(QuicPacketCreatorTest, FullPaddingDoesNotConsumePendingPadding) {
897 creator_.AddPendingPadding(kMaxNumRandomPaddingBytes);
898 QuicFrame frame;
899 QuicIOVector io_vector(MakeIOVectorFromStringPiece("test"));
900 ASSERT_TRUE(creator_.ConsumeData(kCryptoStreamId, io_vector, 0u, 0u, false,
901 /*needs_full_padding=*/true, &frame));
902 EXPECT_CALL(delegate_, OnSerializedPacket(_))
903 .WillOnce(Invoke(this, &QuicPacketCreatorTest::SaveSerializedPacket));
904 creator_.Flush();
905 EXPECT_EQ(kMaxNumRandomPaddingBytes, creator_.pending_padding_bytes());
906 }
907
908 TEST_P(QuicPacketCreatorTest, SendPendingPaddingInRetransmission) {
909 QuicStreamFrame* stream_frame = new QuicStreamFrame(
910 kCryptoStreamId, /*fin=*/false, 0u, QuicStringPiece());
911 QuicFrames frames;
912 frames.push_back(QuicFrame(stream_frame));
913 char buffer[kMaxPacketSize];
914 QuicPendingRetransmission retransmission(
915 CreateRetransmission(frames, true, /*num_padding_bytes=*/0,
916 ENCRYPTION_NONE, PACKET_1BYTE_PACKET_NUMBER));
917 EXPECT_CALL(delegate_, OnSerializedPacket(_))
918 .WillOnce(Invoke(this, &QuicPacketCreatorTest::SaveSerializedPacket));
919 creator_.AddPendingPadding(kMaxNumRandomPaddingBytes);
920 creator_.ReserializeAllFrames(retransmission, buffer, kMaxPacketSize);
921 EXPECT_EQ(0u, creator_.pending_padding_bytes());
922 {
923 InSequence s;
924 EXPECT_CALL(framer_visitor_, OnPacket());
925 EXPECT_CALL(framer_visitor_, OnUnauthenticatedPublicHeader(_));
926 EXPECT_CALL(framer_visitor_, OnUnauthenticatedHeader(_));
927 EXPECT_CALL(framer_visitor_, OnDecryptedPacket(_));
928 EXPECT_CALL(framer_visitor_, OnPacketHeader(_));
929 EXPECT_CALL(framer_visitor_, OnStreamFrame(_));
930 EXPECT_CALL(framer_visitor_, OnPaddingFrame(_));
931 EXPECT_CALL(framer_visitor_, OnPacketComplete());
932 }
933 ProcessPacket(serialized_packet_);
934 delete stream_frame;
935 }
936
937 TEST_P(QuicPacketCreatorTest, SendPacketAfterFullPaddingRetransmission) {
938 // Making sure needs_full_padding gets reset after a full padding
939 // retransmission.
940 EXPECT_EQ(0u, creator_.pending_padding_bytes());
941 QuicFrame frame;
942 QuicIOVector io_vector(
943 MakeIOVectorFromStringPiece("fake handshake message data"));
944 QuicPacketCreatorPeer::CreateStreamFrame(&creator_, kCryptoStreamId,
945 io_vector, 0u, 0u, false, &frame);
946 QuicFrames frames;
947 frames.push_back(frame);
948 char buffer[kMaxPacketSize];
949 QuicPendingRetransmission retransmission(CreateRetransmission(
950 frames, true, /*num_padding_bytes=*/-1, ENCRYPTION_NONE,
951 QuicPacketCreatorPeer::GetPacketNumberLength(&creator_)));
952 EXPECT_CALL(delegate_, OnSerializedPacket(_))
953 .WillRepeatedly(
954 Invoke(this, &QuicPacketCreatorTest::SaveSerializedPacket));
955 creator_.ReserializeAllFrames(retransmission, buffer, kMaxPacketSize);
956 EXPECT_EQ(kDefaultMaxPacketSize, serialized_packet_.encrypted_length);
957 {
958 InSequence s;
959 EXPECT_CALL(framer_visitor_, OnPacket());
960 EXPECT_CALL(framer_visitor_, OnUnauthenticatedPublicHeader(_));
961 EXPECT_CALL(framer_visitor_, OnUnauthenticatedHeader(_));
962 EXPECT_CALL(framer_visitor_, OnDecryptedPacket(_));
963 EXPECT_CALL(framer_visitor_, OnPacketHeader(_));
964 EXPECT_CALL(framer_visitor_, OnStreamFrame(_));
965 // Full padding.
966 EXPECT_CALL(framer_visitor_, OnPaddingFrame(_));
967 EXPECT_CALL(framer_visitor_, OnPacketComplete());
968 }
969 ProcessPacket(serialized_packet_);
970 delete frame.stream_frame;
971
972 creator_.ConsumeData(kCryptoStreamId, io_vector, 0u, 0u, false, false,
973 &frame);
974 creator_.Flush();
975 {
976 InSequence s;
977 EXPECT_CALL(framer_visitor_, OnPacket());
978 EXPECT_CALL(framer_visitor_, OnUnauthenticatedPublicHeader(_));
979 EXPECT_CALL(framer_visitor_, OnUnauthenticatedHeader(_));
980 EXPECT_CALL(framer_visitor_, OnDecryptedPacket(_));
981 EXPECT_CALL(framer_visitor_, OnPacketHeader(_));
982 EXPECT_CALL(framer_visitor_, OnStreamFrame(_));
983 // needs_full_padding gets reset.
984 EXPECT_CALL(framer_visitor_, OnPaddingFrame(_)).Times(0);
985 EXPECT_CALL(framer_visitor_, OnPacketComplete());
986 }
987 ProcessPacket(serialized_packet_);
988 }
989
990 TEST_P(QuicPacketCreatorTest, ConsumeDataAndRandomPadding) {
991 const QuicByteCount kStreamFramePayloadSize = 100u;
992 // Set the packet size be enough for one stream frame with 0 stream offset +
993 // 1.
994 size_t length = GetPacketHeaderOverhead(client_framer_.version()) +
995 GetEncryptionOverhead() +
996 QuicFramer::GetMinStreamFrameSize(
997 kCryptoStreamId, 0, /*last_frame_in_packet=*/false) +
998 kStreamFramePayloadSize + 1;
999 creator_.SetMaxPacketLength(length);
1000 creator_.AddPendingPadding(kMaxNumRandomPaddingBytes);
1001 QuicByteCount pending_padding_bytes = creator_.pending_padding_bytes();
1002 QuicFrame frame;
1003 char buf[kStreamFramePayloadSize + 1] = {};
1004 EXPECT_CALL(delegate_, OnSerializedPacket(_))
1005 .WillRepeatedly(
1006 Invoke(this, &QuicPacketCreatorTest::SaveSerializedPacket));
1007 // Send stream frame of size kStreamFramePayloadSize.
1008 creator_.ConsumeData(kCryptoStreamId,
1009 MakeIOVectorFromStringPiece(
1010 QuicStringPiece(buf, kStreamFramePayloadSize)),
1011 0u, 0u, false, false, &frame);
1012 creator_.Flush();
1013 delete frame.stream_frame;
1014 // 1 byte padding is sent.
1015 EXPECT_EQ(pending_padding_bytes - 1, creator_.pending_padding_bytes());
1016 // Send stream frame of size kStreamFramePayloadSize + 1.
1017 creator_.ConsumeData(kCryptoStreamId,
1018 MakeIOVectorFromStringPiece(
1019 QuicStringPiece(buf, kStreamFramePayloadSize + 1)),
1020 0u, 0u, false, false, &frame);
1021 // No padding is sent.
1022 creator_.Flush();
1023 delete frame.stream_frame;
1024 EXPECT_EQ(pending_padding_bytes - 1, creator_.pending_padding_bytes());
1025 // Flush all paddings.
1026 while (creator_.pending_padding_bytes() > 0) {
1027 creator_.Flush();
1028 }
1029 EXPECT_EQ(0u, creator_.pending_padding_bytes());
1030 }
1031
856 } // namespace 1032 } // namespace
857 } // namespace test 1033 } // namespace test
858 } // namespace net 1034 } // namespace net
OLDNEW
« no previous file with comments | « net/quic/core/quic_packet_creator.cc ('k') | net/quic/core/quic_packet_generator.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698