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

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

Issue 1502503002: Move encryption_level from QueuedPacket into SerializedPacket. No functional change. Not flag pro… (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@108718393
Patch Set: Created 5 years 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/quic_packet_creator.cc ('k') | net/quic/quic_protocol.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 <stdint.h> 7 #include <stdint.h>
8 8
9 #include "base/stl_util.h" 9 #include "base/stl_util.h"
10 #include "net/quic/crypto/null_encrypter.h" 10 #include "net/quic/crypto/null_encrypter.h"
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after
117 QuicTime::Zero(), 117 QuicTime::Zero(),
118 Perspective::IS_SERVER), 118 Perspective::IS_SERVER),
119 client_framer_(SupportedVersions(GetParam().version), 119 client_framer_(SupportedVersions(GetParam().version),
120 QuicTime::Zero(), 120 QuicTime::Zero(),
121 Perspective::IS_CLIENT), 121 Perspective::IS_CLIENT),
122 connection_id_(2), 122 connection_id_(2),
123 data_("foo"), 123 data_("foo"),
124 creator_(connection_id_, &client_framer_, &mock_random_, &delegate_), 124 creator_(connection_id_, &client_framer_, &mock_random_, &delegate_),
125 serialized_packet_(creator_.NoPacket()) { 125 serialized_packet_(creator_.NoPacket()) {
126 creator_.set_connection_id_length(GetParam().connection_id_length); 126 creator_.set_connection_id_length(GetParam().connection_id_length);
127
128 creator_.SetEncrypter(ENCRYPTION_INITIAL, new NullEncrypter());
129 creator_.SetEncrypter(ENCRYPTION_FORWARD_SECURE, new NullEncrypter());
127 client_framer_.set_visitor(&framer_visitor_); 130 client_framer_.set_visitor(&framer_visitor_);
128 client_framer_.set_received_entropy_calculator(&entropy_calculator_); 131 client_framer_.set_received_entropy_calculator(&entropy_calculator_);
129 server_framer_.set_visitor(&framer_visitor_); 132 server_framer_.set_visitor(&framer_visitor_);
130 FLAGS_quic_packet_creator_prefetch = GetParam().copy_use_prefetch; 133 FLAGS_quic_packet_creator_prefetch = GetParam().copy_use_prefetch;
131 } 134 }
132 135
133 ~QuicPacketCreatorTest() override {} 136 ~QuicPacketCreatorTest() override {}
134 137
138 SerializedPacket SerializeAllFrames(const QuicFrames& frames) {
139 SerializedPacket packet =
140 creator_.SerializeAllFrames(frames, buffer_, kMaxPacketSize);
141 EXPECT_EQ(QuicPacketCreatorPeer::GetEncryptionLevel(&creator_),
142 packet.encryption_level);
143 return packet;
144 }
145
135 void ProcessPacket(QuicEncryptedPacket* encrypted) { 146 void ProcessPacket(QuicEncryptedPacket* encrypted) {
136 server_framer_.ProcessPacket(*encrypted); 147 server_framer_.ProcessPacket(*encrypted);
137 } 148 }
138 149
139 void CheckStreamFrame(const QuicFrame& frame, 150 void CheckStreamFrame(const QuicFrame& frame,
140 QuicStreamId stream_id, 151 QuicStreamId stream_id,
141 const string& data, 152 const string& data,
142 QuicStreamOffset offset, 153 QuicStreamOffset offset,
143 bool fin) { 154 bool fin) {
144 EXPECT_EQ(STREAM_FRAME, frame.type); 155 EXPECT_EQ(STREAM_FRAME, frame.type);
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
179 creator_.MaybeStartFecProtection(); 190 creator_.MaybeStartFecProtection();
180 return QuicPacketCreatorPeer::IsFecProtected(&creator_); 191 return QuicPacketCreatorPeer::IsFecProtected(&creator_);
181 } 192 }
182 193
183 QuicIOVector MakeIOVector(StringPiece s) { 194 QuicIOVector MakeIOVector(StringPiece s) {
184 return ::net::MakeIOVector(s, &iov_); 195 return ::net::MakeIOVector(s, &iov_);
185 } 196 }
186 197
187 static const QuicStreamOffset kOffset = 1u; 198 static const QuicStreamOffset kOffset = 1u;
188 199
200 char buffer_[kMaxPacketSize];
189 QuicFrames frames_; 201 QuicFrames frames_;
190 QuicFramer server_framer_; 202 QuicFramer server_framer_;
191 QuicFramer client_framer_; 203 QuicFramer client_framer_;
192 StrictMock<MockFramerVisitor> framer_visitor_; 204 StrictMock<MockFramerVisitor> framer_visitor_;
193 StrictMock<MockDelegate> delegate_; 205 StrictMock<MockDelegate> delegate_;
194 QuicConnectionId connection_id_; 206 QuicConnectionId connection_id_;
195 string data_; 207 string data_;
196 struct iovec iov_; 208 struct iovec iov_;
197 MockRandom mock_random_; 209 MockRandom mock_random_;
198 QuicPacketCreator creator_; 210 QuicPacketCreator creator_;
199 MockEntropyCalculator entropy_calculator_; 211 MockEntropyCalculator entropy_calculator_;
200 SerializedPacket serialized_packet_; 212 SerializedPacket serialized_packet_;
201 }; 213 };
202 214
203 // Run all packet creator tests with all supported versions of QUIC, and with 215 // Run all packet creator tests with all supported versions of QUIC, and with
204 // and without version in the packet header, as well as doing a run for each 216 // and without version in the packet header, as well as doing a run for each
205 // length of truncated connection id. 217 // length of truncated connection id.
206 INSTANTIATE_TEST_CASE_P(QuicPacketCreatorTests, 218 INSTANTIATE_TEST_CASE_P(QuicPacketCreatorTests,
207 QuicPacketCreatorTest, 219 QuicPacketCreatorTest,
208 ::testing::ValuesIn(GetTestParams())); 220 ::testing::ValuesIn(GetTestParams()));
209 221
210 TEST_P(QuicPacketCreatorTest, SerializeFrames) { 222 TEST_P(QuicPacketCreatorTest, SerializeFrames) {
211 frames_.push_back(QuicFrame(new QuicAckFrame(MakeAckFrame(0u)))); 223 for (int i = ENCRYPTION_NONE; i < NUM_ENCRYPTION_LEVELS; ++i) {
212 frames_.push_back( 224 EncryptionLevel level = static_cast<EncryptionLevel>(i);
213 QuicFrame(new QuicStreamFrame(0u, false, 0u, StringPiece()))); 225 creator_.set_encryption_level(level);
214 frames_.push_back( 226 frames_.push_back(QuicFrame(new QuicAckFrame(MakeAckFrame(0u))));
215 QuicFrame(new QuicStreamFrame(0u, true, 0u, StringPiece()))); 227 frames_.push_back(
216 char buffer[kMaxPacketSize]; 228 QuicFrame(new QuicStreamFrame(0u, false, 0u, StringPiece())));
217 SerializedPacket serialized = 229 frames_.push_back(
218 creator_.SerializeAllFrames(frames_, buffer, kMaxPacketSize); 230 QuicFrame(new QuicStreamFrame(0u, true, 0u, StringPiece())));
219 delete frames_[0].ack_frame; 231 SerializedPacket serialized = SerializeAllFrames(frames_);
220 delete frames_[1].stream_frame; 232 EXPECT_EQ(level, serialized.encryption_level);
221 delete frames_[2].stream_frame; 233 delete frames_[0].ack_frame;
234 delete frames_[1].stream_frame;
235 delete frames_[2].stream_frame;
236 frames_.clear();
222 237
223 { 238 {
224 InSequence s; 239 InSequence s;
225 EXPECT_CALL(framer_visitor_, OnPacket()); 240 EXPECT_CALL(framer_visitor_, OnPacket());
226 EXPECT_CALL(framer_visitor_, OnUnauthenticatedPublicHeader(_)); 241 EXPECT_CALL(framer_visitor_, OnUnauthenticatedPublicHeader(_));
227 EXPECT_CALL(framer_visitor_, OnUnauthenticatedHeader(_)); 242 EXPECT_CALL(framer_visitor_, OnUnauthenticatedHeader(_));
228 EXPECT_CALL(framer_visitor_, OnDecryptedPacket(_)); 243 EXPECT_CALL(framer_visitor_, OnDecryptedPacket(_));
229 EXPECT_CALL(framer_visitor_, OnPacketHeader(_)); 244 EXPECT_CALL(framer_visitor_, OnPacketHeader(_));
230 EXPECT_CALL(framer_visitor_, OnAckFrame(_)); 245 EXPECT_CALL(framer_visitor_, OnAckFrame(_));
231 EXPECT_CALL(framer_visitor_, OnStreamFrame(_)); 246 EXPECT_CALL(framer_visitor_, OnStreamFrame(_));
232 EXPECT_CALL(framer_visitor_, OnStreamFrame(_)); 247 EXPECT_CALL(framer_visitor_, OnStreamFrame(_));
233 EXPECT_CALL(framer_visitor_, OnPacketComplete()); 248 EXPECT_CALL(framer_visitor_, OnPacketComplete());
249 }
250 ProcessPacket(serialized.packet);
251 delete serialized.packet;
234 } 252 }
235 ProcessPacket(serialized.packet);
236 delete serialized.packet;
237 } 253 }
238 254
239 TEST_P(QuicPacketCreatorTest, SerializeWithFEC) { 255 TEST_P(QuicPacketCreatorTest, SerializeWithFEC) {
240 // Enable FEC protection, and send FEC packet every 6 packets. 256 // Enable FEC protection, and send FEC packet every 6 packets.
241 EXPECT_TRUE(SwitchFecProtectionOn(6)); 257 EXPECT_TRUE(SwitchFecProtectionOn(6));
242 // Should return false since we do not have enough packets in the FEC group to 258 // Should return false since we do not have enough packets in the FEC group to
243 // trigger an FEC packet. 259 // trigger an FEC packet.
244 ASSERT_FALSE(creator_.ShouldSendFec(/*force_close=*/false)); 260 ASSERT_FALSE(creator_.ShouldSendFec(/*force_close=*/false));
245 261
246 frames_.push_back( 262 frames_.push_back(
247 QuicFrame(new QuicStreamFrame(0u, false, 0u, StringPiece()))); 263 QuicFrame(new QuicStreamFrame(0u, false, 0u, StringPiece())));
248 char buffer[kMaxPacketSize]; 264 SerializedPacket serialized = SerializeAllFrames(frames_);
249 SerializedPacket serialized =
250 creator_.SerializeAllFrames(frames_, buffer, kMaxPacketSize);
251 delete frames_[0].stream_frame; 265 delete frames_[0].stream_frame;
252 266
253 { 267 {
254 InSequence s; 268 InSequence s;
255 EXPECT_CALL(framer_visitor_, OnPacket()); 269 EXPECT_CALL(framer_visitor_, OnPacket());
256 EXPECT_CALL(framer_visitor_, OnUnauthenticatedPublicHeader(_)); 270 EXPECT_CALL(framer_visitor_, OnUnauthenticatedPublicHeader(_));
257 EXPECT_CALL(framer_visitor_, OnUnauthenticatedHeader(_)); 271 EXPECT_CALL(framer_visitor_, OnUnauthenticatedHeader(_));
258 EXPECT_CALL(framer_visitor_, OnDecryptedPacket(_)); 272 EXPECT_CALL(framer_visitor_, OnDecryptedPacket(_));
259 EXPECT_CALL(framer_visitor_, OnPacketHeader(_)); 273 EXPECT_CALL(framer_visitor_, OnPacketHeader(_));
260 EXPECT_CALL(framer_visitor_, OnFecProtectedPayload(_)); 274 EXPECT_CALL(framer_visitor_, OnFecProtectedPayload(_));
(...skipping 241 matching lines...) Expand 10 before | Expand all | Expand 10 after
502 EXPECT_CALL(framer_visitor_, OnUnauthenticatedHeader(_)); 516 EXPECT_CALL(framer_visitor_, OnUnauthenticatedHeader(_));
503 EXPECT_CALL(framer_visitor_, OnDecryptedPacket(_)); 517 EXPECT_CALL(framer_visitor_, OnDecryptedPacket(_));
504 EXPECT_CALL(framer_visitor_, OnPacketHeader(_)); 518 EXPECT_CALL(framer_visitor_, OnPacketHeader(_));
505 EXPECT_CALL(framer_visitor_, OnFecData(_)); 519 EXPECT_CALL(framer_visitor_, OnFecData(_));
506 EXPECT_CALL(framer_visitor_, OnPacketComplete()); 520 EXPECT_CALL(framer_visitor_, OnPacketComplete());
507 } 521 }
508 ProcessPacket(serialized_packet_.packet); 522 ProcessPacket(serialized_packet_.packet);
509 ClearSerializedPacket(&serialized_packet_); 523 ClearSerializedPacket(&serialized_packet_);
510 524
511 // Ensure the next FEC group starts using the new packet number length. 525 // Ensure the next FEC group starts using the new packet number length.
512 char buffer[kMaxPacketSize]; 526 SerializedPacket serialized = SerializeAllFrames(frames_);
513 SerializedPacket serialized =
514 creator_.SerializeAllFrames(frames_, buffer, kMaxPacketSize);
515 EXPECT_EQ(PACKET_4BYTE_PACKET_NUMBER, serialized.packet_number_length); 527 EXPECT_EQ(PACKET_4BYTE_PACKET_NUMBER, serialized.packet_number_length);
516 delete frames_[0].ack_frame; 528 delete frames_[0].ack_frame;
517 ClearSerializedPacket(&serialized); 529 ClearSerializedPacket(&serialized);
518 } 530 }
519 531
520 TEST_P(QuicPacketCreatorTest, ReserializeFramesWithSequenceNumberLength) { 532 TEST_P(QuicPacketCreatorTest, ReserializeFramesWithSequenceNumberLength) {
521 // If the original packet number length, the current packet number 533 // If the original packet number length, the current packet number
522 // length, and the configured send packet number length are different, the 534 // length, and the configured send packet number length are different, the
523 // retransmit must sent with the original length and the others do not change. 535 // retransmit must sent with the original length and the others do not change.
524 QuicPacketCreatorPeer::SetNextPacketNumberLength(&creator_, 536 QuicPacketCreatorPeer::SetNextPacketNumberLength(&creator_,
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
607 } 619 }
608 } 620 }
609 621
610 TEST_P(QuicPacketCreatorTest, SerializeConnectionClose) { 622 TEST_P(QuicPacketCreatorTest, SerializeConnectionClose) {
611 QuicConnectionCloseFrame frame; 623 QuicConnectionCloseFrame frame;
612 frame.error_code = QUIC_NO_ERROR; 624 frame.error_code = QUIC_NO_ERROR;
613 frame.error_details = "error"; 625 frame.error_details = "error";
614 626
615 QuicFrames frames; 627 QuicFrames frames;
616 frames.push_back(QuicFrame(&frame)); 628 frames.push_back(QuicFrame(&frame));
617 char buffer[kMaxPacketSize]; 629 SerializedPacket serialized = SerializeAllFrames(frames);
618 SerializedPacket serialized = 630 EXPECT_EQ(ENCRYPTION_NONE, serialized.encryption_level);
619 creator_.SerializeAllFrames(frames, buffer, kMaxPacketSize);
620 ASSERT_EQ(1u, serialized.packet_number); 631 ASSERT_EQ(1u, serialized.packet_number);
621 ASSERT_EQ(1u, creator_.packet_number()); 632 ASSERT_EQ(1u, creator_.packet_number());
622 633
623 InSequence s; 634 InSequence s;
624 EXPECT_CALL(framer_visitor_, OnPacket()); 635 EXPECT_CALL(framer_visitor_, OnPacket());
625 EXPECT_CALL(framer_visitor_, OnUnauthenticatedPublicHeader(_)); 636 EXPECT_CALL(framer_visitor_, OnUnauthenticatedPublicHeader(_));
626 EXPECT_CALL(framer_visitor_, OnUnauthenticatedHeader(_)); 637 EXPECT_CALL(framer_visitor_, OnUnauthenticatedHeader(_));
627 EXPECT_CALL(framer_visitor_, OnDecryptedPacket(_)); 638 EXPECT_CALL(framer_visitor_, OnDecryptedPacket(_));
628 EXPECT_CALL(framer_visitor_, OnPacketHeader(_)); 639 EXPECT_CALL(framer_visitor_, OnPacketHeader(_));
629 EXPECT_CALL(framer_visitor_, OnConnectionCloseFrame(_)); 640 EXPECT_CALL(framer_visitor_, OnConnectionCloseFrame(_));
(...skipping 19 matching lines...) Expand all
649 creator_.MaybeSendFecPacketAndCloseGroup(/*force_send_fec=*/true, 660 creator_.MaybeSendFecPacketAndCloseGroup(/*force_send_fec=*/true,
650 /*is_fec_timeout=*/false); 661 /*is_fec_timeout=*/false);
651 EXPECT_FALSE(QuicPacketCreatorPeer::IsFecProtected(&creator_)); 662 EXPECT_FALSE(QuicPacketCreatorPeer::IsFecProtected(&creator_));
652 } 663 }
653 664
654 TEST_P(QuicPacketCreatorTest, SwitchFecOnOffWithGroupInProgress) { 665 TEST_P(QuicPacketCreatorTest, SwitchFecOnOffWithGroupInProgress) {
655 // Enable FEC protection, and send FEC packet every 6 packets. 666 // Enable FEC protection, and send FEC packet every 6 packets.
656 EXPECT_TRUE(SwitchFecProtectionOn(6)); 667 EXPECT_TRUE(SwitchFecProtectionOn(6));
657 frames_.push_back( 668 frames_.push_back(
658 QuicFrame(new QuicStreamFrame(0u, false, 0u, StringPiece()))); 669 QuicFrame(new QuicStreamFrame(0u, false, 0u, StringPiece())));
659 char buffer[kMaxPacketSize]; 670 SerializedPacket serialized = SerializeAllFrames(frames_);
660 SerializedPacket serialized =
661 creator_.SerializeAllFrames(frames_, buffer, kMaxPacketSize);
662 delete frames_[0].stream_frame; 671 delete frames_[0].stream_frame;
663 delete serialized.packet; 672 delete serialized.packet;
664 673
665 EXPECT_TRUE(QuicPacketCreatorPeer::IsFecProtected(&creator_)); 674 EXPECT_TRUE(QuicPacketCreatorPeer::IsFecProtected(&creator_));
666 // We do not have enough packets in the FEC group to trigger an FEC packet. 675 // We do not have enough packets in the FEC group to trigger an FEC packet.
667 EXPECT_FALSE(creator_.ShouldSendFec(/*force_close=*/false)); 676 EXPECT_FALSE(creator_.ShouldSendFec(/*force_close=*/false));
668 // Should return true since there are packets in the FEC group. 677 // Should return true since there are packets in the FEC group.
669 EXPECT_TRUE(creator_.ShouldSendFec(/*force_close=*/true)); 678 EXPECT_TRUE(creator_.ShouldSendFec(/*force_close=*/true));
670 679
671 // Switching FEC off should not change creator state, since there is an 680 // Switching FEC off should not change creator state, since there is an
(...skipping 306 matching lines...) Expand 10 before | Expand all | Expand 10 after
978 EXPECT_EQ(PACKET_6BYTE_PACKET_NUMBER, 987 EXPECT_EQ(PACKET_6BYTE_PACKET_NUMBER,
979 QuicPacketCreatorPeer::NextPacketNumberLength(&creator_)); 988 QuicPacketCreatorPeer::NextPacketNumberLength(&creator_));
980 } 989 }
981 990
982 TEST_P(QuicPacketCreatorTest, SerializeFrame) { 991 TEST_P(QuicPacketCreatorTest, SerializeFrame) {
983 if (!GetParam().version_serialization) { 992 if (!GetParam().version_serialization) {
984 creator_.StopSendingVersion(); 993 creator_.StopSendingVersion();
985 } 994 }
986 frames_.push_back( 995 frames_.push_back(
987 QuicFrame(new QuicStreamFrame(0u, false, 0u, StringPiece()))); 996 QuicFrame(new QuicStreamFrame(0u, false, 0u, StringPiece())));
988 char buffer[kMaxPacketSize]; 997 SerializedPacket serialized = SerializeAllFrames(frames_);
989 SerializedPacket serialized =
990 creator_.SerializeAllFrames(frames_, buffer, kMaxPacketSize);
991 delete frames_[0].stream_frame; 998 delete frames_[0].stream_frame;
992 999
993 QuicPacketHeader header; 1000 QuicPacketHeader header;
994 { 1001 {
995 InSequence s; 1002 InSequence s;
996 EXPECT_CALL(framer_visitor_, OnPacket()); 1003 EXPECT_CALL(framer_visitor_, OnPacket());
997 EXPECT_CALL(framer_visitor_, OnUnauthenticatedPublicHeader(_)); 1004 EXPECT_CALL(framer_visitor_, OnUnauthenticatedPublicHeader(_));
998 EXPECT_CALL(framer_visitor_, OnUnauthenticatedHeader(_)); 1005 EXPECT_CALL(framer_visitor_, OnUnauthenticatedHeader(_));
999 EXPECT_CALL(framer_visitor_, OnDecryptedPacket(_)); 1006 EXPECT_CALL(framer_visitor_, OnDecryptedPacket(_));
1000 EXPECT_CALL(framer_visitor_, OnPacketHeader(_)).WillOnce( 1007 EXPECT_CALL(framer_visitor_, OnPacketHeader(_)).WillOnce(
(...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after
1173 EXPECT_GE(est_packet_size, client_framer_.GetMaxPlaintextSize( 1180 EXPECT_GE(est_packet_size, client_framer_.GetMaxPlaintextSize(
1174 serialized_packet_.packet->length())); 1181 serialized_packet_.packet->length()));
1175 ClearSerializedPacket(&serialized_packet_); 1182 ClearSerializedPacket(&serialized_packet_);
1176 } 1183 }
1177 1184
1178 1185
1179 TEST_P(QuicPacketCreatorTest, EntropyFlag) { 1186 TEST_P(QuicPacketCreatorTest, EntropyFlag) {
1180 frames_.push_back( 1187 frames_.push_back(
1181 QuicFrame(new QuicStreamFrame(0u, false, 0u, StringPiece()))); 1188 QuicFrame(new QuicStreamFrame(0u, false, 0u, StringPiece())));
1182 1189
1183 char buffer[kMaxPacketSize];
1184 for (int i = 0; i < 2; ++i) { 1190 for (int i = 0; i < 2; ++i) {
1185 for (int j = 0; j < 64; ++j) { 1191 for (int j = 0; j < 64; ++j) {
1186 SerializedPacket serialized = 1192 SerializedPacket serialized = SerializeAllFrames(frames_);
1187 creator_.SerializeAllFrames(frames_, buffer, kMaxPacketSize);
1188 // Verify both BoolSource and hash algorithm. 1193 // Verify both BoolSource and hash algorithm.
1189 bool expected_rand_bool = 1194 bool expected_rand_bool =
1190 (mock_random_.RandUint64() & (UINT64_C(1) << j)) != 0; 1195 (mock_random_.RandUint64() & (UINT64_C(1) << j)) != 0;
1191 bool observed_rand_bool = 1196 bool observed_rand_bool =
1192 (serialized.entropy_hash & (1 << ((j+1) % 8))) != 0; 1197 (serialized.entropy_hash & (1 << ((j+1) % 8))) != 0;
1193 uint8 rest_of_hash = serialized.entropy_hash & ~(1 << ((j+1) % 8)); 1198 uint8 rest_of_hash = serialized.entropy_hash & ~(1 << ((j+1) % 8));
1194 EXPECT_EQ(expected_rand_bool, observed_rand_bool); 1199 EXPECT_EQ(expected_rand_bool, observed_rand_bool);
1195 EXPECT_EQ(0, rest_of_hash); 1200 EXPECT_EQ(0, rest_of_hash);
1196 delete serialized.packet; 1201 delete serialized.packet;
1197 } 1202 }
1198 // After 64 calls, BoolSource will refresh the bucket - make sure it does. 1203 // After 64 calls, BoolSource will refresh the bucket - make sure it does.
1199 mock_random_.ChangeValue(); 1204 mock_random_.ChangeValue();
1200 } 1205 }
1201 1206
1202 delete frames_[0].stream_frame; 1207 delete frames_[0].stream_frame;
1203 } 1208 }
1204 1209
1205 TEST_P(QuicPacketCreatorTest, ResetFecGroup) { 1210 TEST_P(QuicPacketCreatorTest, ResetFecGroup) {
1206 // Enable FEC protection, and send FEC packet every 6 packets. 1211 // Enable FEC protection, and send FEC packet every 6 packets.
1207 EXPECT_TRUE(SwitchFecProtectionOn(6)); 1212 EXPECT_TRUE(SwitchFecProtectionOn(6));
1208 frames_.push_back( 1213 frames_.push_back(
1209 QuicFrame(new QuicStreamFrame(0u, false, 0u, StringPiece()))); 1214 QuicFrame(new QuicStreamFrame(0u, false, 0u, StringPiece())));
1210 char buffer[kMaxPacketSize]; 1215 SerializedPacket serialized = SerializeAllFrames(frames_);
1211 SerializedPacket serialized =
1212 creator_.SerializeAllFrames(frames_, buffer, kMaxPacketSize);
1213 delete serialized.packet; 1216 delete serialized.packet;
1214 1217
1215 EXPECT_TRUE(QuicPacketCreatorPeer::IsFecProtected(&creator_)); 1218 EXPECT_TRUE(QuicPacketCreatorPeer::IsFecProtected(&creator_));
1216 EXPECT_TRUE(creator_.IsFecGroupOpen()); 1219 EXPECT_TRUE(creator_.IsFecGroupOpen());
1217 // We do not have enough packets in the FEC group to trigger an FEC packet. 1220 // We do not have enough packets in the FEC group to trigger an FEC packet.
1218 EXPECT_FALSE(creator_.ShouldSendFec(/*force_close=*/false)); 1221 EXPECT_FALSE(creator_.ShouldSendFec(/*force_close=*/false));
1219 // Should return true since there are packets in the FEC group. 1222 // Should return true since there are packets in the FEC group.
1220 EXPECT_TRUE(creator_.ShouldSendFec(/*force_close=*/true)); 1223 EXPECT_TRUE(creator_.ShouldSendFec(/*force_close=*/true));
1221 1224
1222 // FEC group will be reset if FEC police is alarm trigger but FEC alarm does 1225 // FEC group will be reset if FEC police is alarm trigger but FEC alarm does
1223 // not fire. 1226 // not fire.
1224 EXPECT_CALL(delegate_, OnResetFecGroup()).Times(1); 1227 EXPECT_CALL(delegate_, OnResetFecGroup()).Times(1);
1225 creator_.set_fec_send_policy(FEC_ALARM_TRIGGER); 1228 creator_.set_fec_send_policy(FEC_ALARM_TRIGGER);
1226 creator_.set_should_fec_protect(true); 1229 creator_.set_should_fec_protect(true);
1227 creator_.MaybeSendFecPacketAndCloseGroup(/*force_send_fec=*/true, 1230 creator_.MaybeSendFecPacketAndCloseGroup(/*force_send_fec=*/true,
1228 /*is_fec_timeout=*/false); 1231 /*is_fec_timeout=*/false);
1229 EXPECT_TRUE(QuicPacketCreatorPeer::IsFecProtected(&creator_)); 1232 EXPECT_TRUE(QuicPacketCreatorPeer::IsFecProtected(&creator_));
1230 EXPECT_FALSE(creator_.IsFecGroupOpen()); 1233 EXPECT_FALSE(creator_.IsFecGroupOpen());
1231 // We do not have enough packets in the FEC group to trigger an FEC packet. 1234 // We do not have enough packets in the FEC group to trigger an FEC packet.
1232 EXPECT_FALSE(creator_.ShouldSendFec(/*force_close=*/false)); 1235 EXPECT_FALSE(creator_.ShouldSendFec(/*force_close=*/false));
1233 // Confirm that there is no FEC packet under construction. 1236 // Confirm that there is no FEC packet under construction.
1234 EXPECT_FALSE(creator_.ShouldSendFec(/*force_close=*/true)); 1237 EXPECT_FALSE(creator_.ShouldSendFec(/*force_close=*/true));
1235 1238
1236 EXPECT_DFATAL(serialized = QuicPacketCreatorPeer::SerializeFec( 1239 EXPECT_DFATAL(serialized = QuicPacketCreatorPeer::SerializeFec(
1237 &creator_, buffer, kMaxPacketSize), 1240 &creator_, buffer_, kMaxPacketSize),
1238 "SerializeFEC called but no group or zero packets in group."); 1241 "SerializeFEC called but no group or zero packets in group.");
1239 delete serialized.packet; 1242 delete serialized.packet;
1240 1243
1241 // Start a new FEC packet. 1244 // Start a new FEC packet.
1242 serialized = creator_.SerializeAllFrames(frames_, buffer, kMaxPacketSize); 1245 serialized = SerializeAllFrames(frames_);
1243 delete frames_[0].stream_frame; 1246 delete frames_[0].stream_frame;
1244 delete serialized.packet; 1247 delete serialized.packet;
1245 1248
1246 EXPECT_TRUE(QuicPacketCreatorPeer::IsFecProtected(&creator_)); 1249 EXPECT_TRUE(QuicPacketCreatorPeer::IsFecProtected(&creator_));
1247 EXPECT_TRUE(creator_.IsFecGroupOpen()); 1250 EXPECT_TRUE(creator_.IsFecGroupOpen());
1248 // We do not have enough packets in the FEC group to trigger an FEC packet. 1251 // We do not have enough packets in the FEC group to trigger an FEC packet.
1249 EXPECT_FALSE(creator_.ShouldSendFec(/*force_close=*/false)); 1252 EXPECT_FALSE(creator_.ShouldSendFec(/*force_close=*/false));
1250 // Should return true since there are packets in the FEC group. 1253 // Should return true since there are packets in the FEC group.
1251 EXPECT_TRUE(creator_.ShouldSendFec(/*force_close=*/true)); 1254 EXPECT_TRUE(creator_.ShouldSendFec(/*force_close=*/true));
1252 1255
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
1292 creator_.set_fec_send_policy(FEC_ALARM_TRIGGER); 1295 creator_.set_fec_send_policy(FEC_ALARM_TRIGGER);
1293 creator_.set_should_fec_protect(true); 1296 creator_.set_should_fec_protect(true);
1294 creator_.MaybeSendFecPacketAndCloseGroup(/*force_send_fec=*/true, 1297 creator_.MaybeSendFecPacketAndCloseGroup(/*force_send_fec=*/true,
1295 /*is_fec_timeout=*/false); 1298 /*is_fec_timeout=*/false);
1296 EXPECT_FALSE(creator_.IsFecGroupOpen()); 1299 EXPECT_FALSE(creator_.IsFecGroupOpen());
1297 } 1300 }
1298 1301
1299 } // namespace 1302 } // namespace
1300 } // namespace test 1303 } // namespace test
1301 } // namespace net 1304 } // namespace net
OLDNEW
« no previous file with comments | « net/quic/quic_packet_creator.cc ('k') | net/quic/quic_protocol.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698