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

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

Issue 326403006: Enables PacketGenerator's use of PacketCreator's FEC primitives. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 6 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 | Annotate | Revision Log
« no previous file with comments | « net/quic/quic_packet_creator.cc ('k') | net/quic/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/quic_packet_creator.h" 5 #include "net/quic/quic_packet_creator.h"
6 6
7 #include "base/stl_util.h" 7 #include "base/stl_util.h"
8 #include "net/quic/crypto/null_encrypter.h" 8 #include "net/quic/crypto/null_encrypter.h"
9 #include "net/quic/crypto/quic_decrypter.h" 9 #include "net/quic/crypto/quic_decrypter.h"
10 #include "net/quic/crypto/quic_encrypter.h" 10 #include "net/quic/crypto/quic_encrypter.h"
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after
113 creator_.max_packet_length()); 113 creator_.max_packet_length());
114 } 114 }
115 115
116 // Returns the number of bytes consumed by the non-data fields of a stream 116 // Returns the number of bytes consumed by the non-data fields of a stream
117 // frame, assuming it is the last frame in the packet 117 // frame, assuming it is the last frame in the packet
118 size_t GetStreamFrameOverhead(InFecGroup is_in_fec_group) { 118 size_t GetStreamFrameOverhead(InFecGroup is_in_fec_group) {
119 return QuicFramer::GetMinStreamFrameSize(client_framer_.version(), 119 return QuicFramer::GetMinStreamFrameSize(client_framer_.version(),
120 kClientDataStreamId1, kOffset, 120 kClientDataStreamId1, kOffset,
121 true, is_in_fec_group); 121 true, is_in_fec_group);
122 } 122 }
123
124 // Enables and turns on FEC protection. Returns true if FEC protection is on.
125 bool SwitchFecProtectionOn(size_t max_packets_per_fec_group) {
126 creator_.set_max_packets_per_fec_group(max_packets_per_fec_group);
127 creator_.StartFecProtectingPackets();
128 return creator_.IsFecProtected();
129 }
130
123 static const QuicStreamOffset kOffset = 1u; 131 static const QuicStreamOffset kOffset = 1u;
124 132
125 QuicFrames frames_; 133 QuicFrames frames_;
126 QuicFramer server_framer_; 134 QuicFramer server_framer_;
127 QuicFramer client_framer_; 135 QuicFramer client_framer_;
128 testing::StrictMock<MockFramerVisitor> framer_visitor_; 136 testing::StrictMock<MockFramerVisitor> framer_visitor_;
129 QuicPacketSequenceNumber sequence_number_; 137 QuicPacketSequenceNumber sequence_number_;
130 QuicConnectionId connection_id_; 138 QuicConnectionId connection_id_;
131 string data_; 139 string data_;
132 MockRandom mock_random_; 140 MockRandom mock_random_;
(...skipping 27 matching lines...) Expand all
160 EXPECT_CALL(framer_visitor_, OnStreamFrame(_)); 168 EXPECT_CALL(framer_visitor_, OnStreamFrame(_));
161 EXPECT_CALL(framer_visitor_, OnStreamFrame(_)); 169 EXPECT_CALL(framer_visitor_, OnStreamFrame(_));
162 EXPECT_CALL(framer_visitor_, OnPacketComplete()); 170 EXPECT_CALL(framer_visitor_, OnPacketComplete());
163 } 171 }
164 ProcessPacket(serialized.packet); 172 ProcessPacket(serialized.packet);
165 delete serialized.packet; 173 delete serialized.packet;
166 } 174 }
167 175
168 TEST_P(QuicPacketCreatorTest, SerializeWithFEC) { 176 TEST_P(QuicPacketCreatorTest, SerializeWithFEC) {
169 // Enable FEC protection, and send FEC packet every 6 packets. 177 // Enable FEC protection, and send FEC packet every 6 packets.
170 EXPECT_TRUE(QuicPacketCreatorPeer::SwitchFecProtectionOn(&creator_, 6)); 178 EXPECT_TRUE(SwitchFecProtectionOn(6));
171 // Should return false since we do not have enough packets in the FEC group to 179 // Should return false since we do not have enough packets in the FEC group to
172 // trigger an FEC packet. 180 // trigger an FEC packet.
173 ASSERT_FALSE(creator_.ShouldSendFec(/*force_close=*/false)); 181 ASSERT_FALSE(creator_.ShouldSendFec(/*force_close=*/false));
174 182
175 frames_.push_back(QuicFrame(new QuicStreamFrame(0u, false, 0u, IOVector()))); 183 frames_.push_back(QuicFrame(new QuicStreamFrame(0u, false, 0u, IOVector())));
176 SerializedPacket serialized = creator_.SerializeAllFrames(frames_); 184 SerializedPacket serialized = creator_.SerializeAllFrames(frames_);
177 delete frames_[0].stream_frame; 185 delete frames_[0].stream_frame;
178 186
179 { 187 {
180 InSequence s; 188 InSequence s;
(...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after
332 delete ack_frame.ack_frame; 340 delete ack_frame.ack_frame;
333 } 341 }
334 342
335 TEST_P(QuicPacketCreatorTest, SerializeWithFECChangingSequenceNumberLength) { 343 TEST_P(QuicPacketCreatorTest, SerializeWithFECChangingSequenceNumberLength) {
336 // Test goal is to test the following sequence (P1 => generate Packet 1): 344 // Test goal is to test the following sequence (P1 => generate Packet 1):
337 // P1 <change seq num length> P2 FEC, 345 // P1 <change seq num length> P2 FEC,
338 // and we expect that sequence number length should not change until the end 346 // and we expect that sequence number length should not change until the end
339 // of the open FEC group. 347 // of the open FEC group.
340 348
341 // Enable FEC protection, and send FEC packet every 6 packets. 349 // Enable FEC protection, and send FEC packet every 6 packets.
342 EXPECT_TRUE(QuicPacketCreatorPeer::SwitchFecProtectionOn(&creator_, 6)); 350 EXPECT_TRUE(SwitchFecProtectionOn(6));
343 // Should return false since we do not have enough packets in the FEC group to 351 // Should return false since we do not have enough packets in the FEC group to
344 // trigger an FEC packet. 352 // trigger an FEC packet.
345 ASSERT_FALSE(creator_.ShouldSendFec(/*force_close=*/false)); 353 ASSERT_FALSE(creator_.ShouldSendFec(/*force_close=*/false));
346 frames_.push_back(QuicFrame(new QuicAckFrame(MakeAckFrame(0u, 0u)))); 354 frames_.push_back(QuicFrame(new QuicAckFrame(MakeAckFrame(0u, 0u))));
347 355
348 // Generate Packet 1. 356 // Generate Packet 1.
349 creator_.AddSavedFrame(frames_[0]); 357 creator_.AddSavedFrame(frames_[0]);
350 // Change the sequence number length mid-FEC group and it should not change. 358 // Change the sequence number length mid-FEC group and it should not change.
351 creator_.set_next_sequence_number_length(PACKET_4BYTE_SEQUENCE_NUMBER); 359 creator_.set_next_sequence_number_length(PACKET_4BYTE_SEQUENCE_NUMBER);
352 SerializedPacket serialized = creator_.SerializePacket(); 360 SerializedPacket serialized = creator_.SerializePacket();
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after
481 // We have no packets in the FEC group, so no FEC packet can be created. 489 // We have no packets in the FEC group, so no FEC packet can be created.
482 EXPECT_FALSE(creator_.ShouldSendFec(/*force_close=*/true)); 490 EXPECT_FALSE(creator_.ShouldSendFec(/*force_close=*/true));
483 // Since no packets are in FEC group yet, we should be able to turn FEC 491 // Since no packets are in FEC group yet, we should be able to turn FEC
484 // off with no trouble. 492 // off with no trouble.
485 creator_.StopFecProtectingPackets(); 493 creator_.StopFecProtectingPackets();
486 EXPECT_FALSE(creator_.IsFecProtected()); 494 EXPECT_FALSE(creator_.IsFecProtected());
487 } 495 }
488 496
489 TEST_P(QuicPacketCreatorTest, SwitchFecOnOffWithGroupInProgress) { 497 TEST_P(QuicPacketCreatorTest, SwitchFecOnOffWithGroupInProgress) {
490 // Enable FEC protection, and send FEC packet every 6 packets. 498 // Enable FEC protection, and send FEC packet every 6 packets.
491 EXPECT_TRUE(QuicPacketCreatorPeer::SwitchFecProtectionOn(&creator_, 6)); 499 EXPECT_TRUE(SwitchFecProtectionOn(6));
492 frames_.push_back(QuicFrame(new QuicStreamFrame(0u, false, 0u, IOVector()))); 500 frames_.push_back(QuicFrame(new QuicStreamFrame(0u, false, 0u, IOVector())));
493 SerializedPacket serialized = creator_.SerializeAllFrames(frames_); 501 SerializedPacket serialized = creator_.SerializeAllFrames(frames_);
494 delete frames_[0].stream_frame; 502 delete frames_[0].stream_frame;
495 delete serialized.packet; 503 delete serialized.packet;
496 504
497 EXPECT_TRUE(creator_.IsFecProtected()); 505 EXPECT_TRUE(creator_.IsFecProtected());
498 // We do not have enough packets in the FEC group to trigger an FEC packet. 506 // We do not have enough packets in the FEC group to trigger an FEC packet.
499 EXPECT_FALSE(creator_.ShouldSendFec(/*force_close=*/false)); 507 EXPECT_FALSE(creator_.ShouldSendFec(/*force_close=*/false));
500 // Should return true since there are packets in the FEC group. 508 // Should return true since there are packets in the FEC group.
501 EXPECT_TRUE(creator_.ShouldSendFec(/*force_close=*/true)); 509 EXPECT_TRUE(creator_.ShouldSendFec(/*force_close=*/true));
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after
619 EXPECT_EQ(expected_bytes_free, creator_.BytesFree()) << "delta: " << delta; 627 EXPECT_EQ(expected_bytes_free, creator_.BytesFree()) << "delta: " << delta;
620 SerializedPacket serialized_packet = creator_.SerializePacket(); 628 SerializedPacket serialized_packet = creator_.SerializePacket();
621 ASSERT_TRUE(serialized_packet.packet); 629 ASSERT_TRUE(serialized_packet.packet);
622 delete serialized_packet.packet; 630 delete serialized_packet.packet;
623 delete serialized_packet.retransmittable_frames; 631 delete serialized_packet.retransmittable_frames;
624 } 632 }
625 } 633 }
626 634
627 TEST_P(QuicPacketCreatorTest, StreamFrameConsumptionWithFec) { 635 TEST_P(QuicPacketCreatorTest, StreamFrameConsumptionWithFec) {
628 // Enable FEC protection, and send FEC packet every 6 packets. 636 // Enable FEC protection, and send FEC packet every 6 packets.
629 EXPECT_TRUE(QuicPacketCreatorPeer::SwitchFecProtectionOn(&creator_, 6)); 637 EXPECT_TRUE(SwitchFecProtectionOn(6));
630 // Compute the total overhead for a single frame in packet. 638 // Compute the total overhead for a single frame in packet.
631 const size_t overhead = GetPacketHeaderOverhead(IN_FEC_GROUP) 639 const size_t overhead = GetPacketHeaderOverhead(IN_FEC_GROUP)
632 + GetEncryptionOverhead() + GetStreamFrameOverhead(IN_FEC_GROUP); 640 + GetEncryptionOverhead() + GetStreamFrameOverhead(IN_FEC_GROUP);
633 size_t capacity = kDefaultMaxPacketSize - overhead; 641 size_t capacity = kDefaultMaxPacketSize - overhead;
634 // Now, test various sizes around this size. 642 // Now, test various sizes around this size.
635 for (int delta = -5; delta <= 5; ++delta) { 643 for (int delta = -5; delta <= 5; ++delta) {
636 string data(capacity + delta, 'A'); 644 string data(capacity + delta, 'A');
637 size_t bytes_free = delta > 0 ? 0 : 0 - delta; 645 size_t bytes_free = delta > 0 ? 0 : 0 - delta;
638 QuicFrame frame; 646 QuicFrame frame;
639 size_t bytes_consumed = creator_.CreateStreamFrame( 647 size_t bytes_consumed = creator_.CreateStreamFrame(
(...skipping 361 matching lines...) Expand 10 before | Expand all | Expand 10 after
1001 // After 64 calls, BoolSource will refresh the bucket - make sure it does. 1009 // After 64 calls, BoolSource will refresh the bucket - make sure it does.
1002 mock_random_.ChangeValue(); 1010 mock_random_.ChangeValue();
1003 } 1011 }
1004 1012
1005 delete frames_[0].stream_frame; 1013 delete frames_[0].stream_frame;
1006 } 1014 }
1007 1015
1008 } // namespace 1016 } // namespace
1009 } // namespace test 1017 } // namespace test
1010 } // namespace net 1018 } // namespace net
OLDNEW
« no previous file with comments | « net/quic/quic_packet_creator.cc ('k') | net/quic/quic_packet_generator.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698