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 delete[] serialized_packet_.encrypted_buffer; |
| 106 serialized_packet_ = *serialized_packet; |
| 107 serialized_packet_.encrypted_buffer = |
| 108 QuicUtils::CopyBuffer(*serialized_packet); |
| 109 serialized_packet->retransmittable_frames.clear(); |
| 110 } |
105 | 111 |
106 serialized_packet_ = *serialized_packet; | 112 void DeleteSerializedPacket() { |
107 serialized_packet_.packet = serialized_packet->packet->Clone(); | 113 delete[] serialized_packet_.encrypted_buffer; |
108 delete serialized_packet->packet; | 114 serialized_packet_.encrypted_buffer = nullptr; |
109 serialized_packet->retransmittable_frames.clear(); | 115 ClearSerializedPacket(&serialized_packet_); |
110 } | 116 } |
111 | 117 |
112 protected: | 118 protected: |
113 QuicPacketCreatorTest() | 119 QuicPacketCreatorTest() |
114 : server_framer_(SupportedVersions(GetParam().version), | 120 : server_framer_(SupportedVersions(GetParam().version), |
115 QuicTime::Zero(), | 121 QuicTime::Zero(), |
116 Perspective::IS_SERVER), | 122 Perspective::IS_SERVER), |
117 client_framer_(SupportedVersions(GetParam().version), | 123 client_framer_(SupportedVersions(GetParam().version), |
118 QuicTime::Zero(), | 124 QuicTime::Zero(), |
119 Perspective::IS_CLIENT), | 125 Perspective::IS_CLIENT), |
(...skipping 11 matching lines...) Expand all Loading... |
131 creator_.SetEncrypter(ENCRYPTION_INITIAL, new NullEncrypter()); | 137 creator_.SetEncrypter(ENCRYPTION_INITIAL, new NullEncrypter()); |
132 creator_.SetEncrypter(ENCRYPTION_FORWARD_SECURE, new NullEncrypter()); | 138 creator_.SetEncrypter(ENCRYPTION_FORWARD_SECURE, new NullEncrypter()); |
133 client_framer_.set_visitor(&framer_visitor_); | 139 client_framer_.set_visitor(&framer_visitor_); |
134 client_framer_.set_received_entropy_calculator(&entropy_calculator_); | 140 client_framer_.set_received_entropy_calculator(&entropy_calculator_); |
135 server_framer_.set_visitor(&framer_visitor_); | 141 server_framer_.set_visitor(&framer_visitor_); |
136 // 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. |
137 FLAGS_quic_never_write_unencrypted_data = false; | 143 FLAGS_quic_never_write_unencrypted_data = false; |
138 FLAGS_quic_no_unencrypted_fec = false; | 144 FLAGS_quic_no_unencrypted_fec = false; |
139 } | 145 } |
140 | 146 |
141 ~QuicPacketCreatorTest() override {} | 147 ~QuicPacketCreatorTest() override { |
| 148 delete[] serialized_packet_.encrypted_buffer; |
| 149 ClearSerializedPacket(&serialized_packet_); |
| 150 } |
142 | 151 |
143 SerializedPacket SerializeAllFrames(const QuicFrames& frames) { | 152 SerializedPacket SerializeAllFrames(const QuicFrames& frames) { |
144 SerializedPacket packet = QuicPacketCreatorPeer::SerializeAllFrames( | 153 SerializedPacket packet = QuicPacketCreatorPeer::SerializeAllFrames( |
145 &creator_, frames, buffer_, kMaxPacketSize); | 154 &creator_, frames, buffer_, kMaxPacketSize); |
146 EXPECT_EQ(QuicPacketCreatorPeer::GetEncryptionLevel(&creator_), | 155 EXPECT_EQ(QuicPacketCreatorPeer::GetEncryptionLevel(&creator_), |
147 packet.encryption_level); | 156 packet.encryption_level); |
148 return packet; | 157 return packet; |
149 } | 158 } |
150 | 159 |
151 void ProcessPacket(QuicEncryptedPacket* encrypted) { | 160 void ProcessPacket(const SerializedPacket& packet) { |
152 server_framer_.ProcessPacket(*encrypted); | 161 QuicEncryptedPacket encrypted_packet(packet.encrypted_buffer, |
| 162 packet.encrypted_length); |
| 163 server_framer_.ProcessPacket(encrypted_packet); |
153 } | 164 } |
154 | 165 |
155 void CheckStreamFrame(const QuicFrame& frame, | 166 void CheckStreamFrame(const QuicFrame& frame, |
156 QuicStreamId stream_id, | 167 QuicStreamId stream_id, |
157 const string& data, | 168 const string& data, |
158 QuicStreamOffset offset, | 169 QuicStreamOffset offset, |
159 bool fin) { | 170 bool fin) { |
160 EXPECT_EQ(STREAM_FRAME, frame.type); | 171 EXPECT_EQ(STREAM_FRAME, frame.type); |
161 ASSERT_TRUE(frame.stream_frame); | 172 ASSERT_TRUE(frame.stream_frame); |
162 EXPECT_EQ(stream_id, frame.stream_frame->stream_id); | 173 EXPECT_EQ(stream_id, frame.stream_frame->stream_id); |
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
251 EXPECT_CALL(framer_visitor_, OnPacket()); | 262 EXPECT_CALL(framer_visitor_, OnPacket()); |
252 EXPECT_CALL(framer_visitor_, OnUnauthenticatedPublicHeader(_)); | 263 EXPECT_CALL(framer_visitor_, OnUnauthenticatedPublicHeader(_)); |
253 EXPECT_CALL(framer_visitor_, OnUnauthenticatedHeader(_)); | 264 EXPECT_CALL(framer_visitor_, OnUnauthenticatedHeader(_)); |
254 EXPECT_CALL(framer_visitor_, OnDecryptedPacket(_)); | 265 EXPECT_CALL(framer_visitor_, OnDecryptedPacket(_)); |
255 EXPECT_CALL(framer_visitor_, OnPacketHeader(_)); | 266 EXPECT_CALL(framer_visitor_, OnPacketHeader(_)); |
256 EXPECT_CALL(framer_visitor_, OnAckFrame(_)); | 267 EXPECT_CALL(framer_visitor_, OnAckFrame(_)); |
257 EXPECT_CALL(framer_visitor_, OnStreamFrame(_)); | 268 EXPECT_CALL(framer_visitor_, OnStreamFrame(_)); |
258 EXPECT_CALL(framer_visitor_, OnStreamFrame(_)); | 269 EXPECT_CALL(framer_visitor_, OnStreamFrame(_)); |
259 EXPECT_CALL(framer_visitor_, OnPacketComplete()); | 270 EXPECT_CALL(framer_visitor_, OnPacketComplete()); |
260 } | 271 } |
261 ProcessPacket(serialized.packet); | 272 ProcessPacket(serialized); |
262 delete serialized.packet; | |
263 } | 273 } |
264 } | 274 } |
265 | 275 |
266 TEST_P(QuicPacketCreatorTest, SerializeWithFEC) { | 276 TEST_P(QuicPacketCreatorTest, SerializeWithFEC) { |
267 // Send FEC packet every 6 packets. | 277 // Send FEC packet every 6 packets. |
268 creator_.set_max_packets_per_fec_group(6); | 278 creator_.set_max_packets_per_fec_group(6); |
269 // 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 |
270 // trigger an FEC packet. | 280 // trigger an FEC packet. |
271 ASSERT_FALSE(creator_.ShouldSendFec(/*force_close=*/false)); | 281 ASSERT_FALSE(creator_.ShouldSendFec(/*force_close=*/false)); |
272 // Turn on FEC protection. | 282 // Turn on FEC protection. |
(...skipping 11 matching lines...) Expand all Loading... |
284 InSequence s; | 294 InSequence s; |
285 EXPECT_CALL(framer_visitor_, OnPacket()); | 295 EXPECT_CALL(framer_visitor_, OnPacket()); |
286 EXPECT_CALL(framer_visitor_, OnUnauthenticatedPublicHeader(_)); | 296 EXPECT_CALL(framer_visitor_, OnUnauthenticatedPublicHeader(_)); |
287 EXPECT_CALL(framer_visitor_, OnUnauthenticatedHeader(_)); | 297 EXPECT_CALL(framer_visitor_, OnUnauthenticatedHeader(_)); |
288 EXPECT_CALL(framer_visitor_, OnDecryptedPacket(_)); | 298 EXPECT_CALL(framer_visitor_, OnDecryptedPacket(_)); |
289 EXPECT_CALL(framer_visitor_, OnPacketHeader(_)); | 299 EXPECT_CALL(framer_visitor_, OnPacketHeader(_)); |
290 EXPECT_CALL(framer_visitor_, OnFecProtectedPayload(_)); | 300 EXPECT_CALL(framer_visitor_, OnFecProtectedPayload(_)); |
291 EXPECT_CALL(framer_visitor_, OnStreamFrame(_)); | 301 EXPECT_CALL(framer_visitor_, OnStreamFrame(_)); |
292 EXPECT_CALL(framer_visitor_, OnPacketComplete()); | 302 EXPECT_CALL(framer_visitor_, OnPacketComplete()); |
293 } | 303 } |
294 ProcessPacket(serialized_packet_.packet); | 304 ProcessPacket(serialized_packet_); |
295 ClearSerializedPacket(&serialized_packet_); | 305 DeleteSerializedPacket(); |
296 | 306 |
297 // Should return false since we do not have enough packets in the FEC group to | 307 // Should return false since we do not have enough packets in the FEC group to |
298 // trigger an FEC packet. | 308 // trigger an FEC packet. |
299 ASSERT_FALSE(creator_.ShouldSendFec(/*force_close=*/false)); | 309 ASSERT_FALSE(creator_.ShouldSendFec(/*force_close=*/false)); |
300 // Should return true since there are packets in the FEC group. | 310 // Should return true since there are packets in the FEC group. |
301 ASSERT_TRUE(creator_.ShouldSendFec(/*force_close=*/true)); | 311 ASSERT_TRUE(creator_.ShouldSendFec(/*force_close=*/true)); |
302 | 312 |
303 EXPECT_CALL(delegate_, OnSerializedPacket(_)) | 313 EXPECT_CALL(delegate_, OnSerializedPacket(_)) |
304 .WillOnce(Invoke(this, &QuicPacketCreatorTest::SaveSerializedPacket)); | 314 .WillOnce(Invoke(this, &QuicPacketCreatorTest::SaveSerializedPacket)); |
305 creator_.MaybeSendFecPacketAndCloseGroup(/*force_send_fec=*/true, | 315 creator_.MaybeSendFecPacketAndCloseGroup(/*force_send_fec=*/true, |
306 /*is_fec_timeout=*/false); | 316 /*is_fec_timeout=*/false); |
307 ASSERT_EQ(2u, serialized_packet_.packet_number); | 317 ASSERT_EQ(2u, serialized_packet_.packet_number); |
308 { | 318 { |
309 InSequence s; | 319 InSequence s; |
310 EXPECT_CALL(framer_visitor_, OnPacket()); | 320 EXPECT_CALL(framer_visitor_, OnPacket()); |
311 EXPECT_CALL(framer_visitor_, OnUnauthenticatedPublicHeader(_)); | 321 EXPECT_CALL(framer_visitor_, OnUnauthenticatedPublicHeader(_)); |
312 EXPECT_CALL(framer_visitor_, OnUnauthenticatedHeader(_)); | 322 EXPECT_CALL(framer_visitor_, OnUnauthenticatedHeader(_)); |
313 EXPECT_CALL(framer_visitor_, OnDecryptedPacket(_)); | 323 EXPECT_CALL(framer_visitor_, OnDecryptedPacket(_)); |
314 EXPECT_CALL(framer_visitor_, OnPacketHeader(_)); | 324 EXPECT_CALL(framer_visitor_, OnPacketHeader(_)); |
315 EXPECT_CALL(framer_visitor_, OnFecData(_)); | 325 EXPECT_CALL(framer_visitor_, OnFecData(_)); |
316 EXPECT_CALL(framer_visitor_, OnPacketComplete()); | 326 EXPECT_CALL(framer_visitor_, OnPacketComplete()); |
317 } | 327 } |
318 ProcessPacket(serialized_packet_.packet); | 328 ProcessPacket(serialized_packet_); |
319 ClearSerializedPacket(&serialized_packet_); | 329 DeleteSerializedPacket(); |
320 } | 330 } |
321 | 331 |
322 TEST_P(QuicPacketCreatorTest, SerializeChangingSequenceNumberLength) { | 332 TEST_P(QuicPacketCreatorTest, SerializeChangingSequenceNumberLength) { |
323 frames_.push_back(QuicFrame(new QuicAckFrame(MakeAckFrame(0u)))); | 333 frames_.push_back(QuicFrame(new QuicAckFrame(MakeAckFrame(0u)))); |
324 creator_.AddSavedFrame(frames_[0]); | 334 creator_.AddSavedFrame(frames_[0]); |
325 QuicPacketCreatorPeer::SetNextPacketNumberLength(&creator_, | 335 QuicPacketCreatorPeer::SetNextPacketNumberLength(&creator_, |
326 PACKET_4BYTE_PACKET_NUMBER); | 336 PACKET_4BYTE_PACKET_NUMBER); |
327 | 337 |
328 EXPECT_CALL(delegate_, OnSerializedPacket(_)) | 338 EXPECT_CALL(delegate_, OnSerializedPacket(_)) |
329 .WillRepeatedly( | 339 .WillRepeatedly( |
330 Invoke(this, &QuicPacketCreatorTest::SaveSerializedPacket)); | 340 Invoke(this, &QuicPacketCreatorTest::SaveSerializedPacket)); |
331 creator_.Flush(); | 341 creator_.Flush(); |
332 // The packet number length will not change mid-packet. | 342 // The packet number length will not change mid-packet. |
333 EXPECT_EQ(PACKET_1BYTE_PACKET_NUMBER, | 343 EXPECT_EQ(PACKET_1BYTE_PACKET_NUMBER, |
334 serialized_packet_.packet_number_length); | 344 serialized_packet_.packet_number_length); |
335 | 345 |
336 { | 346 { |
337 InSequence s; | 347 InSequence s; |
338 EXPECT_CALL(framer_visitor_, OnPacket()); | 348 EXPECT_CALL(framer_visitor_, OnPacket()); |
339 EXPECT_CALL(framer_visitor_, OnUnauthenticatedPublicHeader(_)); | 349 EXPECT_CALL(framer_visitor_, OnUnauthenticatedPublicHeader(_)); |
340 EXPECT_CALL(framer_visitor_, OnUnauthenticatedHeader(_)); | 350 EXPECT_CALL(framer_visitor_, OnUnauthenticatedHeader(_)); |
341 EXPECT_CALL(framer_visitor_, OnDecryptedPacket(_)); | 351 EXPECT_CALL(framer_visitor_, OnDecryptedPacket(_)); |
342 EXPECT_CALL(framer_visitor_, OnPacketHeader(_)); | 352 EXPECT_CALL(framer_visitor_, OnPacketHeader(_)); |
343 EXPECT_CALL(framer_visitor_, OnAckFrame(_)); | 353 EXPECT_CALL(framer_visitor_, OnAckFrame(_)); |
344 EXPECT_CALL(framer_visitor_, OnPacketComplete()); | 354 EXPECT_CALL(framer_visitor_, OnPacketComplete()); |
345 } | 355 } |
346 ProcessPacket(serialized_packet_.packet); | 356 ProcessPacket(serialized_packet_); |
347 ClearSerializedPacket(&serialized_packet_); | 357 DeleteSerializedPacket(); |
348 | 358 |
349 creator_.AddSavedFrame(frames_[0]); | 359 creator_.AddSavedFrame(frames_[0]); |
350 creator_.Flush(); | 360 creator_.Flush(); |
351 // Now the actual packet number length should have changed. | 361 // Now the actual packet number length should have changed. |
352 EXPECT_EQ(PACKET_4BYTE_PACKET_NUMBER, | 362 EXPECT_EQ(PACKET_4BYTE_PACKET_NUMBER, |
353 serialized_packet_.packet_number_length); | 363 serialized_packet_.packet_number_length); |
354 delete frames_[0].ack_frame; | 364 delete frames_[0].ack_frame; |
355 | 365 |
356 { | 366 { |
357 InSequence s; | 367 InSequence s; |
358 EXPECT_CALL(framer_visitor_, OnPacket()); | 368 EXPECT_CALL(framer_visitor_, OnPacket()); |
359 EXPECT_CALL(framer_visitor_, OnUnauthenticatedPublicHeader(_)); | 369 EXPECT_CALL(framer_visitor_, OnUnauthenticatedPublicHeader(_)); |
360 EXPECT_CALL(framer_visitor_, OnUnauthenticatedHeader(_)); | 370 EXPECT_CALL(framer_visitor_, OnUnauthenticatedHeader(_)); |
361 EXPECT_CALL(framer_visitor_, OnDecryptedPacket(_)); | 371 EXPECT_CALL(framer_visitor_, OnDecryptedPacket(_)); |
362 EXPECT_CALL(framer_visitor_, OnPacketHeader(_)); | 372 EXPECT_CALL(framer_visitor_, OnPacketHeader(_)); |
363 EXPECT_CALL(framer_visitor_, OnAckFrame(_)); | 373 EXPECT_CALL(framer_visitor_, OnAckFrame(_)); |
364 EXPECT_CALL(framer_visitor_, OnPacketComplete()); | 374 EXPECT_CALL(framer_visitor_, OnPacketComplete()); |
365 } | 375 } |
366 ProcessPacket(serialized_packet_.packet); | 376 ProcessPacket(serialized_packet_); |
367 ClearSerializedPacket(&serialized_packet_); | 377 DeleteSerializedPacket(); |
368 } | 378 } |
369 | 379 |
370 TEST_P(QuicPacketCreatorTest, ChangeSequenceNumberLengthMidPacket) { | 380 TEST_P(QuicPacketCreatorTest, ChangeSequenceNumberLengthMidPacket) { |
371 // Changing the packet number length with queued frames in the creator | 381 // Changing the packet number length with queued frames in the creator |
372 // should hold the change until after any currently queued frames are | 382 // should hold the change until after any currently queued frames are |
373 // serialized. | 383 // serialized. |
374 | 384 |
375 // Packet 1. | 385 // Packet 1. |
376 // Queue a frame in the creator. | 386 // Queue a frame in the creator. |
377 EXPECT_FALSE(creator_.HasPendingFrames()); | 387 EXPECT_FALSE(creator_.HasPendingFrames()); |
378 QuicFrame ack_frame = QuicFrame(new QuicAckFrame(MakeAckFrame(0u))); | 388 QuicFrame ack_frame = QuicFrame(new QuicAckFrame(MakeAckFrame(0u))); |
379 creator_.AddSavedFrame(ack_frame); | 389 creator_.AddSavedFrame(ack_frame); |
380 | 390 |
381 // Now change packet number length. | 391 // Now change packet number length. |
382 QuicPacketCreatorPeer::SetNextPacketNumberLength(&creator_, | 392 QuicPacketCreatorPeer::SetNextPacketNumberLength(&creator_, |
383 PACKET_4BYTE_PACKET_NUMBER); | 393 PACKET_4BYTE_PACKET_NUMBER); |
384 | 394 |
385 // Add a STOP_WAITING frame since it contains a packet number, | 395 // Add a STOP_WAITING frame since it contains a packet number, |
386 // whose length should be 1. | 396 // whose length should be 1. |
387 QuicStopWaitingFrame stop_waiting_frame; | 397 QuicStopWaitingFrame stop_waiting_frame; |
388 EXPECT_TRUE(creator_.AddSavedFrame(QuicFrame(&stop_waiting_frame))); | 398 EXPECT_TRUE(creator_.AddSavedFrame(QuicFrame(&stop_waiting_frame))); |
389 EXPECT_TRUE(creator_.HasPendingFrames()); | 399 EXPECT_TRUE(creator_.HasPendingFrames()); |
390 | 400 |
391 // Ensure the packet is successfully created. | 401 // Ensure the packet is successfully created. |
392 EXPECT_CALL(delegate_, OnSerializedPacket(_)) | 402 EXPECT_CALL(delegate_, OnSerializedPacket(_)) |
393 .WillRepeatedly( | 403 .WillRepeatedly( |
394 Invoke(this, &QuicPacketCreatorTest::SaveSerializedPacket)); | 404 Invoke(this, &QuicPacketCreatorTest::SaveSerializedPacket)); |
395 creator_.Flush(); | 405 creator_.Flush(); |
396 ASSERT_TRUE(serialized_packet_.packet); | 406 ASSERT_TRUE(serialized_packet_.encrypted_buffer); |
397 EXPECT_EQ(PACKET_1BYTE_PACKET_NUMBER, | 407 EXPECT_EQ(PACKET_1BYTE_PACKET_NUMBER, |
398 serialized_packet_.packet_number_length); | 408 serialized_packet_.packet_number_length); |
399 | 409 |
400 // Verify that header in transmitted packet has 1 byte sequence length. | 410 // Verify that header in transmitted packet has 1 byte sequence length. |
401 QuicPacketHeader header; | 411 QuicPacketHeader header; |
402 { | 412 { |
403 InSequence s; | 413 InSequence s; |
404 EXPECT_CALL(framer_visitor_, OnPacket()); | 414 EXPECT_CALL(framer_visitor_, OnPacket()); |
405 EXPECT_CALL(framer_visitor_, OnUnauthenticatedPublicHeader(_)); | 415 EXPECT_CALL(framer_visitor_, OnUnauthenticatedPublicHeader(_)); |
406 EXPECT_CALL(framer_visitor_, OnUnauthenticatedHeader(_)); | 416 EXPECT_CALL(framer_visitor_, OnUnauthenticatedHeader(_)); |
407 EXPECT_CALL(framer_visitor_, OnDecryptedPacket(_)); | 417 EXPECT_CALL(framer_visitor_, OnDecryptedPacket(_)); |
408 EXPECT_CALL(framer_visitor_, OnPacketHeader(_)) | 418 EXPECT_CALL(framer_visitor_, OnPacketHeader(_)) |
409 .WillOnce(DoAll(SaveArg<0>(&header), Return(true))); | 419 .WillOnce(DoAll(SaveArg<0>(&header), Return(true))); |
410 EXPECT_CALL(framer_visitor_, OnAckFrame(_)); | 420 EXPECT_CALL(framer_visitor_, OnAckFrame(_)); |
411 EXPECT_CALL(framer_visitor_, OnStopWaitingFrame(_)); | 421 EXPECT_CALL(framer_visitor_, OnStopWaitingFrame(_)); |
412 EXPECT_CALL(framer_visitor_, OnPacketComplete()); | 422 EXPECT_CALL(framer_visitor_, OnPacketComplete()); |
413 } | 423 } |
414 ProcessPacket(serialized_packet_.packet); | 424 ProcessPacket(serialized_packet_); |
415 EXPECT_EQ(PACKET_1BYTE_PACKET_NUMBER, | 425 EXPECT_EQ(PACKET_1BYTE_PACKET_NUMBER, |
416 header.public_header.packet_number_length); | 426 header.public_header.packet_number_length); |
417 ClearSerializedPacket(&serialized_packet_); | 427 DeleteSerializedPacket(); |
418 | 428 |
419 // Packet 2. | 429 // Packet 2. |
420 EXPECT_FALSE(creator_.HasPendingFrames()); | 430 EXPECT_FALSE(creator_.HasPendingFrames()); |
421 // Generate Packet 2 with one frame -- packet number length should now | 431 // Generate Packet 2 with one frame -- packet number length should now |
422 // change to 4 bytes. | 432 // change to 4 bytes. |
423 EXPECT_TRUE(creator_.AddSavedFrame(QuicFrame(&stop_waiting_frame))); | 433 EXPECT_TRUE(creator_.AddSavedFrame(QuicFrame(&stop_waiting_frame))); |
424 EXPECT_TRUE(creator_.HasPendingFrames()); | 434 EXPECT_TRUE(creator_.HasPendingFrames()); |
425 | 435 |
426 // Ensure the packet is successfully created. | 436 // Ensure the packet is successfully created. |
427 creator_.Flush(); | 437 creator_.Flush(); |
428 ASSERT_TRUE(serialized_packet_.packet); | 438 ASSERT_TRUE(serialized_packet_.encrypted_buffer); |
429 EXPECT_EQ(PACKET_4BYTE_PACKET_NUMBER, | 439 EXPECT_EQ(PACKET_4BYTE_PACKET_NUMBER, |
430 serialized_packet_.packet_number_length); | 440 serialized_packet_.packet_number_length); |
431 | 441 |
432 // Verify that header in transmitted packet has 4 byte sequence length. | 442 // Verify that header in transmitted packet has 4 byte sequence length. |
433 { | 443 { |
434 InSequence s; | 444 InSequence s; |
435 EXPECT_CALL(framer_visitor_, OnPacket()); | 445 EXPECT_CALL(framer_visitor_, OnPacket()); |
436 EXPECT_CALL(framer_visitor_, OnUnauthenticatedPublicHeader(_)); | 446 EXPECT_CALL(framer_visitor_, OnUnauthenticatedPublicHeader(_)); |
437 EXPECT_CALL(framer_visitor_, OnUnauthenticatedHeader(_)); | 447 EXPECT_CALL(framer_visitor_, OnUnauthenticatedHeader(_)); |
438 EXPECT_CALL(framer_visitor_, OnDecryptedPacket(_)); | 448 EXPECT_CALL(framer_visitor_, OnDecryptedPacket(_)); |
439 EXPECT_CALL(framer_visitor_, OnPacketHeader(_)) | 449 EXPECT_CALL(framer_visitor_, OnPacketHeader(_)) |
440 .WillOnce(DoAll(SaveArg<0>(&header), Return(true))); | 450 .WillOnce(DoAll(SaveArg<0>(&header), Return(true))); |
441 EXPECT_CALL(framer_visitor_, OnStopWaitingFrame(_)); | 451 EXPECT_CALL(framer_visitor_, OnStopWaitingFrame(_)); |
442 EXPECT_CALL(framer_visitor_, OnPacketComplete()); | 452 EXPECT_CALL(framer_visitor_, OnPacketComplete()); |
443 } | 453 } |
444 ProcessPacket(serialized_packet_.packet); | 454 ProcessPacket(serialized_packet_); |
445 EXPECT_EQ(PACKET_4BYTE_PACKET_NUMBER, | 455 EXPECT_EQ(PACKET_4BYTE_PACKET_NUMBER, |
446 header.public_header.packet_number_length); | 456 header.public_header.packet_number_length); |
447 | 457 |
448 ClearSerializedPacket(&serialized_packet_); | 458 DeleteSerializedPacket(); |
449 delete ack_frame.ack_frame; | 459 delete ack_frame.ack_frame; |
450 } | 460 } |
451 | 461 |
452 TEST_P(QuicPacketCreatorTest, SerializeWithFECChangingSequenceNumberLength) { | 462 TEST_P(QuicPacketCreatorTest, SerializeWithFECChangingSequenceNumberLength) { |
453 // Test goal is to test the following sequence (P1 => generate Packet 1): | 463 // Test goal is to test the following sequence (P1 => generate Packet 1): |
454 // P1 <change seq num length> P2 FEC, | 464 // P1 <change seq num length> P2 FEC, |
455 // and we expect that packet number length should not change until the end | 465 // and we expect that packet number length should not change until the end |
456 // of the open FEC group. | 466 // of the open FEC group. |
457 | 467 |
458 // Send FEC packet every 6 packets. | 468 // Send FEC packet every 6 packets. |
(...skipping 21 matching lines...) Expand all Loading... |
480 InSequence s; | 490 InSequence s; |
481 EXPECT_CALL(framer_visitor_, OnPacket()); | 491 EXPECT_CALL(framer_visitor_, OnPacket()); |
482 EXPECT_CALL(framer_visitor_, OnUnauthenticatedPublicHeader(_)); | 492 EXPECT_CALL(framer_visitor_, OnUnauthenticatedPublicHeader(_)); |
483 EXPECT_CALL(framer_visitor_, OnUnauthenticatedHeader(_)); | 493 EXPECT_CALL(framer_visitor_, OnUnauthenticatedHeader(_)); |
484 EXPECT_CALL(framer_visitor_, OnDecryptedPacket(_)); | 494 EXPECT_CALL(framer_visitor_, OnDecryptedPacket(_)); |
485 EXPECT_CALL(framer_visitor_, OnPacketHeader(_)); | 495 EXPECT_CALL(framer_visitor_, OnPacketHeader(_)); |
486 EXPECT_CALL(framer_visitor_, OnFecProtectedPayload(_)); | 496 EXPECT_CALL(framer_visitor_, OnFecProtectedPayload(_)); |
487 EXPECT_CALL(framer_visitor_, OnStreamFrame(_)); | 497 EXPECT_CALL(framer_visitor_, OnStreamFrame(_)); |
488 EXPECT_CALL(framer_visitor_, OnPacketComplete()); | 498 EXPECT_CALL(framer_visitor_, OnPacketComplete()); |
489 } | 499 } |
490 ProcessPacket(serialized_packet_.packet); | 500 ProcessPacket(serialized_packet_); |
491 ClearSerializedPacket(&serialized_packet_); | 501 DeleteSerializedPacket(); |
492 | 502 |
493 // Generate Packet 2. | 503 // Generate Packet 2. |
494 ASSERT_TRUE(creator_.ConsumeData(2u, io_vector, 0u, 0u, false, false, &frame, | 504 ASSERT_TRUE(creator_.ConsumeData(2u, io_vector, 0u, 0u, false, false, &frame, |
495 MUST_FEC_PROTECT)); | 505 MUST_FEC_PROTECT)); |
496 creator_.Flush(); | 506 creator_.Flush(); |
497 EXPECT_EQ(PACKET_1BYTE_PACKET_NUMBER, | 507 EXPECT_EQ(PACKET_1BYTE_PACKET_NUMBER, |
498 serialized_packet_.packet_number_length); | 508 serialized_packet_.packet_number_length); |
499 | 509 |
500 { | 510 { |
501 InSequence s; | 511 InSequence s; |
502 EXPECT_CALL(framer_visitor_, OnPacket()); | 512 EXPECT_CALL(framer_visitor_, OnPacket()); |
503 EXPECT_CALL(framer_visitor_, OnUnauthenticatedPublicHeader(_)); | 513 EXPECT_CALL(framer_visitor_, OnUnauthenticatedPublicHeader(_)); |
504 EXPECT_CALL(framer_visitor_, OnUnauthenticatedHeader(_)); | 514 EXPECT_CALL(framer_visitor_, OnUnauthenticatedHeader(_)); |
505 EXPECT_CALL(framer_visitor_, OnDecryptedPacket(_)); | 515 EXPECT_CALL(framer_visitor_, OnDecryptedPacket(_)); |
506 EXPECT_CALL(framer_visitor_, OnPacketHeader(_)); | 516 EXPECT_CALL(framer_visitor_, OnPacketHeader(_)); |
507 EXPECT_CALL(framer_visitor_, OnFecProtectedPayload(_)); | 517 EXPECT_CALL(framer_visitor_, OnFecProtectedPayload(_)); |
508 EXPECT_CALL(framer_visitor_, OnStreamFrame(_)); | 518 EXPECT_CALL(framer_visitor_, OnStreamFrame(_)); |
509 EXPECT_CALL(framer_visitor_, OnPacketComplete()); | 519 EXPECT_CALL(framer_visitor_, OnPacketComplete()); |
510 } | 520 } |
511 ProcessPacket(serialized_packet_.packet); | 521 ProcessPacket(serialized_packet_); |
512 ClearSerializedPacket(&serialized_packet_); | 522 DeleteSerializedPacket(); |
513 | 523 |
514 // Should return false since we do not have enough packets in the FEC group to | 524 // Should return false since we do not have enough packets in the FEC group to |
515 // trigger an FEC packet. | 525 // trigger an FEC packet. |
516 ASSERT_FALSE(creator_.ShouldSendFec(/*force_close=*/false)); | 526 ASSERT_FALSE(creator_.ShouldSendFec(/*force_close=*/false)); |
517 // Should return true since there are packets in the FEC group. | 527 // Should return true since there are packets in the FEC group. |
518 ASSERT_TRUE(creator_.ShouldSendFec(/*force_close=*/true)); | 528 ASSERT_TRUE(creator_.ShouldSendFec(/*force_close=*/true)); |
519 | 529 |
520 // Force generation of FEC packet. | 530 // Force generation of FEC packet. |
521 EXPECT_CALL(delegate_, OnSerializedPacket(_)) | 531 EXPECT_CALL(delegate_, OnSerializedPacket(_)) |
522 .WillOnce(Invoke(this, &QuicPacketCreatorTest::SaveSerializedPacket)); | 532 .WillOnce(Invoke(this, &QuicPacketCreatorTest::SaveSerializedPacket)); |
523 // Turn off FEC protection. | 533 // Turn off FEC protection. |
524 creator_.MaybeSendFecPacketAndCloseGroup(/*force_send_fec=*/true, | 534 creator_.MaybeSendFecPacketAndCloseGroup(/*force_send_fec=*/true, |
525 /*is_fec_timeout=*/false); | 535 /*is_fec_timeout=*/false); |
526 EXPECT_EQ(PACKET_1BYTE_PACKET_NUMBER, | 536 EXPECT_EQ(PACKET_1BYTE_PACKET_NUMBER, |
527 serialized_packet_.packet_number_length); | 537 serialized_packet_.packet_number_length); |
528 ASSERT_EQ(3u, serialized_packet_.packet_number); | 538 ASSERT_EQ(3u, serialized_packet_.packet_number); |
529 | 539 |
530 { | 540 { |
531 InSequence s; | 541 InSequence s; |
532 EXPECT_CALL(framer_visitor_, OnPacket()); | 542 EXPECT_CALL(framer_visitor_, OnPacket()); |
533 EXPECT_CALL(framer_visitor_, OnUnauthenticatedPublicHeader(_)); | 543 EXPECT_CALL(framer_visitor_, OnUnauthenticatedPublicHeader(_)); |
534 EXPECT_CALL(framer_visitor_, OnUnauthenticatedHeader(_)); | 544 EXPECT_CALL(framer_visitor_, OnUnauthenticatedHeader(_)); |
535 EXPECT_CALL(framer_visitor_, OnDecryptedPacket(_)); | 545 EXPECT_CALL(framer_visitor_, OnDecryptedPacket(_)); |
536 EXPECT_CALL(framer_visitor_, OnPacketHeader(_)); | 546 EXPECT_CALL(framer_visitor_, OnPacketHeader(_)); |
537 EXPECT_CALL(framer_visitor_, OnFecData(_)); | 547 EXPECT_CALL(framer_visitor_, OnFecData(_)); |
538 EXPECT_CALL(framer_visitor_, OnPacketComplete()); | 548 EXPECT_CALL(framer_visitor_, OnPacketComplete()); |
539 } | 549 } |
540 ProcessPacket(serialized_packet_.packet); | 550 ProcessPacket(serialized_packet_); |
541 ClearSerializedPacket(&serialized_packet_); | 551 DeleteSerializedPacket(); |
542 | 552 |
543 // Ensure the next FEC group starts using the new packet number length. | 553 // Ensure the next FEC group starts using the new packet number length. |
544 ASSERT_TRUE(creator_.ConsumeData(3u, io_vector, 0u, 0u, false, false, &frame, | 554 ASSERT_TRUE(creator_.ConsumeData(3u, io_vector, 0u, 0u, false, false, &frame, |
545 MUST_FEC_PROTECT)); | 555 MUST_FEC_PROTECT)); |
546 EXPECT_TRUE(QuicPacketCreatorPeer::IsFecProtected(&creator_)); | 556 EXPECT_TRUE(QuicPacketCreatorPeer::IsFecProtected(&creator_)); |
547 EXPECT_CALL(delegate_, OnSerializedPacket(_)) | 557 EXPECT_CALL(delegate_, OnSerializedPacket(_)) |
548 .WillOnce(Invoke(this, &QuicPacketCreatorTest::SaveSerializedPacket)); | 558 .WillOnce(Invoke(this, &QuicPacketCreatorTest::SaveSerializedPacket)); |
549 creator_.Flush(); | 559 creator_.Flush(); |
550 EXPECT_EQ(PACKET_4BYTE_PACKET_NUMBER, | 560 EXPECT_EQ(PACKET_4BYTE_PACKET_NUMBER, |
551 serialized_packet_.packet_number_length); | 561 serialized_packet_.packet_number_length); |
552 ClearSerializedPacket(&serialized_packet_); | 562 DeleteSerializedPacket(); |
553 } | 563 } |
554 | 564 |
555 TEST_P(QuicPacketCreatorTest, ReserializeFramesWithSequenceNumberLength) { | 565 TEST_P(QuicPacketCreatorTest, ReserializeFramesWithSequenceNumberLength) { |
556 // If the original packet number length, the current packet number | 566 // If the original packet number length, the current packet number |
557 // length, and the configured send packet number length are different, the | 567 // length, and the configured send packet number length are different, the |
558 // retransmit must sent with the original length and the others do not change. | 568 // retransmit must sent with the original length and the others do not change. |
559 QuicPacketCreatorPeer::SetNextPacketNumberLength(&creator_, | 569 QuicPacketCreatorPeer::SetNextPacketNumberLength(&creator_, |
560 PACKET_4BYTE_PACKET_NUMBER); | 570 PACKET_4BYTE_PACKET_NUMBER); |
561 QuicPacketCreatorPeer::SetPacketNumberLength(&creator_, | 571 QuicPacketCreatorPeer::SetPacketNumberLength(&creator_, |
562 PACKET_2BYTE_PACKET_NUMBER); | 572 PACKET_2BYTE_PACKET_NUMBER); |
(...skipping 23 matching lines...) Expand all Loading... |
586 { | 596 { |
587 InSequence s; | 597 InSequence s; |
588 EXPECT_CALL(framer_visitor_, OnPacket()); | 598 EXPECT_CALL(framer_visitor_, OnPacket()); |
589 EXPECT_CALL(framer_visitor_, OnUnauthenticatedPublicHeader(_)); | 599 EXPECT_CALL(framer_visitor_, OnUnauthenticatedPublicHeader(_)); |
590 EXPECT_CALL(framer_visitor_, OnUnauthenticatedHeader(_)); | 600 EXPECT_CALL(framer_visitor_, OnUnauthenticatedHeader(_)); |
591 EXPECT_CALL(framer_visitor_, OnDecryptedPacket(_)); | 601 EXPECT_CALL(framer_visitor_, OnDecryptedPacket(_)); |
592 EXPECT_CALL(framer_visitor_, OnPacketHeader(_)); | 602 EXPECT_CALL(framer_visitor_, OnPacketHeader(_)); |
593 EXPECT_CALL(framer_visitor_, OnStreamFrame(_)); | 603 EXPECT_CALL(framer_visitor_, OnStreamFrame(_)); |
594 EXPECT_CALL(framer_visitor_, OnPacketComplete()); | 604 EXPECT_CALL(framer_visitor_, OnPacketComplete()); |
595 } | 605 } |
596 ProcessPacket(serialized.packet); | 606 ProcessPacket(serialized); |
597 delete serialized.packet; | |
598 delete stream_frame; | 607 delete stream_frame; |
599 } | 608 } |
600 | 609 |
601 TEST_P(QuicPacketCreatorTest, ReserializeCryptoFrameWithForwardSecurity) { | 610 TEST_P(QuicPacketCreatorTest, ReserializeCryptoFrameWithForwardSecurity) { |
602 QuicStreamFrame* stream_frame = | 611 QuicStreamFrame* stream_frame = |
603 new QuicStreamFrame(kCryptoStreamId, /*fin=*/false, 0u, StringPiece()); | 612 new QuicStreamFrame(kCryptoStreamId, /*fin=*/false, 0u, StringPiece()); |
604 QuicFrames frames; | 613 QuicFrames frames; |
605 frames.push_back(QuicFrame(stream_frame)); | 614 frames.push_back(QuicFrame(stream_frame)); |
606 creator_.set_encryption_level(ENCRYPTION_FORWARD_SECURE); | 615 creator_.set_encryption_level(ENCRYPTION_FORWARD_SECURE); |
607 char buffer[kMaxPacketSize]; | 616 char buffer[kMaxPacketSize]; |
608 PendingRetransmission retransmission(CreateRetransmission( | 617 PendingRetransmission retransmission(CreateRetransmission( |
609 frames, true /* has_crypto_handshake */, true /* needs padding */, | 618 frames, true /* has_crypto_handshake */, true /* needs padding */, |
610 ENCRYPTION_NONE, | 619 ENCRYPTION_NONE, |
611 QuicPacketCreatorPeer::NextPacketNumberLength(&creator_))); | 620 QuicPacketCreatorPeer::NextPacketNumberLength(&creator_))); |
612 if (FLAGS_quic_retransmit_via_onserializedpacket) { | 621 if (FLAGS_quic_retransmit_via_onserializedpacket) { |
613 EXPECT_CALL(delegate_, OnSerializedPacket(_)) | 622 EXPECT_CALL(delegate_, OnSerializedPacket(_)) |
614 .WillOnce(Invoke(this, &QuicPacketCreatorTest::SaveSerializedPacket)); | 623 .WillOnce(Invoke(this, &QuicPacketCreatorTest::SaveSerializedPacket)); |
615 } | 624 } |
616 SerializedPacket serialized = | 625 SerializedPacket serialized = |
617 creator_.ReserializeAllFrames(retransmission, buffer, kMaxPacketSize); | 626 creator_.ReserializeAllFrames(retransmission, buffer, kMaxPacketSize); |
618 if (FLAGS_quic_retransmit_via_onserializedpacket) { | 627 if (FLAGS_quic_retransmit_via_onserializedpacket) { |
619 serialized = serialized_packet_; | 628 serialized = serialized_packet_; |
620 } | 629 } |
621 EXPECT_EQ(ENCRYPTION_NONE, serialized.encryption_level); | 630 EXPECT_EQ(ENCRYPTION_NONE, serialized.encryption_level); |
622 delete serialized.packet; | |
623 delete stream_frame; | 631 delete stream_frame; |
624 } | 632 } |
625 | 633 |
626 TEST_P(QuicPacketCreatorTest, ReserializeFrameWithForwardSecurity) { | 634 TEST_P(QuicPacketCreatorTest, ReserializeFrameWithForwardSecurity) { |
627 QuicStreamFrame* stream_frame = | 635 QuicStreamFrame* stream_frame = |
628 new QuicStreamFrame(0u, /*fin=*/false, 0u, StringPiece()); | 636 new QuicStreamFrame(0u, /*fin=*/false, 0u, StringPiece()); |
629 QuicFrames frames; | 637 QuicFrames frames; |
630 frames.push_back(QuicFrame(stream_frame)); | 638 frames.push_back(QuicFrame(stream_frame)); |
631 creator_.set_encryption_level(ENCRYPTION_FORWARD_SECURE); | 639 creator_.set_encryption_level(ENCRYPTION_FORWARD_SECURE); |
632 char buffer[kMaxPacketSize]; | 640 char buffer[kMaxPacketSize]; |
633 PendingRetransmission retransmission(CreateRetransmission( | 641 PendingRetransmission retransmission(CreateRetransmission( |
634 frames, false /* has_crypto_handshake */, false /* needs padding */, | 642 frames, false /* has_crypto_handshake */, false /* needs padding */, |
635 ENCRYPTION_NONE, | 643 ENCRYPTION_NONE, |
636 QuicPacketCreatorPeer::NextPacketNumberLength(&creator_))); | 644 QuicPacketCreatorPeer::NextPacketNumberLength(&creator_))); |
637 if (FLAGS_quic_retransmit_via_onserializedpacket) { | 645 if (FLAGS_quic_retransmit_via_onserializedpacket) { |
638 EXPECT_CALL(delegate_, OnSerializedPacket(_)) | 646 EXPECT_CALL(delegate_, OnSerializedPacket(_)) |
639 .WillOnce(Invoke(this, &QuicPacketCreatorTest::SaveSerializedPacket)); | 647 .WillOnce(Invoke(this, &QuicPacketCreatorTest::SaveSerializedPacket)); |
640 } | 648 } |
641 SerializedPacket serialized = | 649 SerializedPacket serialized = |
642 creator_.ReserializeAllFrames(retransmission, buffer, kMaxPacketSize); | 650 creator_.ReserializeAllFrames(retransmission, buffer, kMaxPacketSize); |
643 if (FLAGS_quic_retransmit_via_onserializedpacket) { | 651 if (FLAGS_quic_retransmit_via_onserializedpacket) { |
644 serialized = serialized_packet_; | 652 serialized = serialized_packet_; |
645 } | 653 } |
646 EXPECT_EQ(ENCRYPTION_FORWARD_SECURE, serialized.encryption_level); | 654 EXPECT_EQ(ENCRYPTION_FORWARD_SECURE, serialized.encryption_level); |
647 delete serialized.packet; | |
648 delete stream_frame; | 655 delete stream_frame; |
649 } | 656 } |
650 | 657 |
651 TEST_P(QuicPacketCreatorTest, ReserializeFramesWithPadding) { | 658 TEST_P(QuicPacketCreatorTest, ReserializeFramesWithPadding) { |
652 QuicFrame frame; | 659 QuicFrame frame; |
653 QuicIOVector io_vector(MakeIOVector("fake handshake message data")); | 660 QuicIOVector io_vector(MakeIOVector("fake handshake message data")); |
654 QuicPacketCreatorPeer::CreateStreamFrame(&creator_, kCryptoStreamId, | 661 QuicPacketCreatorPeer::CreateStreamFrame(&creator_, kCryptoStreamId, |
655 io_vector, 0u, 0u, false, &frame); | 662 io_vector, 0u, 0u, false, &frame); |
656 QuicFrames frames; | 663 QuicFrames frames; |
657 frames.push_back(frame); | 664 frames.push_back(frame); |
658 char buffer[kMaxPacketSize]; | 665 char buffer[kMaxPacketSize]; |
659 PendingRetransmission retransmission(CreateRetransmission( | 666 PendingRetransmission retransmission(CreateRetransmission( |
660 frames, true /* has_crypto_handshake */, true /* needs padding */, | 667 frames, true /* has_crypto_handshake */, true /* needs padding */, |
661 ENCRYPTION_NONE, | 668 ENCRYPTION_NONE, |
662 QuicPacketCreatorPeer::NextPacketNumberLength(&creator_))); | 669 QuicPacketCreatorPeer::NextPacketNumberLength(&creator_))); |
663 if (FLAGS_quic_retransmit_via_onserializedpacket) { | 670 if (FLAGS_quic_retransmit_via_onserializedpacket) { |
664 EXPECT_CALL(delegate_, OnSerializedPacket(_)) | 671 EXPECT_CALL(delegate_, OnSerializedPacket(_)) |
665 .WillOnce(Invoke(this, &QuicPacketCreatorTest::SaveSerializedPacket)); | 672 .WillOnce(Invoke(this, &QuicPacketCreatorTest::SaveSerializedPacket)); |
666 } | 673 } |
667 SerializedPacket serialized = | 674 SerializedPacket serialized = |
668 creator_.ReserializeAllFrames(retransmission, buffer, kMaxPacketSize); | 675 creator_.ReserializeAllFrames(retransmission, buffer, kMaxPacketSize); |
669 if (FLAGS_quic_retransmit_via_onserializedpacket) { | 676 if (FLAGS_quic_retransmit_via_onserializedpacket) { |
670 serialized = serialized_packet_; | 677 serialized = serialized_packet_; |
671 } | 678 } |
672 EXPECT_EQ(kDefaultMaxPacketSize, serialized.packet->length()); | 679 EXPECT_EQ(kDefaultMaxPacketSize, serialized.encrypted_length); |
673 delete serialized.packet; | |
674 delete frame.stream_frame; | 680 delete frame.stream_frame; |
675 } | 681 } |
676 | 682 |
677 TEST_P(QuicPacketCreatorTest, ReserializeFramesWithFullPacketAndPadding) { | 683 TEST_P(QuicPacketCreatorTest, ReserializeFramesWithFullPacketAndPadding) { |
678 const size_t overhead = GetPacketHeaderOverhead(NOT_IN_FEC_GROUP) + | 684 const size_t overhead = GetPacketHeaderOverhead(NOT_IN_FEC_GROUP) + |
679 GetEncryptionOverhead() + | 685 GetEncryptionOverhead() + |
680 GetStreamFrameOverhead(NOT_IN_FEC_GROUP); | 686 GetStreamFrameOverhead(NOT_IN_FEC_GROUP); |
681 size_t capacity = kDefaultMaxPacketSize - overhead; | 687 size_t capacity = kDefaultMaxPacketSize - overhead; |
682 for (int delta = -5; delta <= 0; ++delta) { | 688 for (int delta = -5; delta <= 0; ++delta) { |
683 string data(capacity + delta, 'A'); | 689 string data(capacity + delta, 'A'); |
(...skipping 19 matching lines...) Expand all Loading... |
703 creator_.ReserializeAllFrames(retransmission, buffer, kMaxPacketSize); | 709 creator_.ReserializeAllFrames(retransmission, buffer, kMaxPacketSize); |
704 if (FLAGS_quic_retransmit_via_onserializedpacket) { | 710 if (FLAGS_quic_retransmit_via_onserializedpacket) { |
705 serialized = serialized_packet_; | 711 serialized = serialized_packet_; |
706 } | 712 } |
707 | 713 |
708 // 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 |
709 // (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 |
710 // will not be padded. | 716 // will not be padded. |
711 if (bytes_free < 3) { | 717 if (bytes_free < 3) { |
712 EXPECT_EQ(kDefaultMaxPacketSize - bytes_free, | 718 EXPECT_EQ(kDefaultMaxPacketSize - bytes_free, |
713 serialized.packet->length()); | 719 serialized.encrypted_length); |
714 } else { | 720 } else { |
715 EXPECT_EQ(kDefaultMaxPacketSize, serialized.packet->length()); | 721 EXPECT_EQ(kDefaultMaxPacketSize, serialized.encrypted_length); |
716 } | 722 } |
717 | 723 |
718 delete serialized.packet; | |
719 delete frame.stream_frame; | 724 delete frame.stream_frame; |
720 frames_.clear(); | 725 frames_.clear(); |
721 } | 726 } |
722 } | 727 } |
723 | 728 |
724 TEST_P(QuicPacketCreatorTest, SerializeConnectionClose) { | 729 TEST_P(QuicPacketCreatorTest, SerializeConnectionClose) { |
725 QuicConnectionCloseFrame frame; | 730 QuicConnectionCloseFrame frame; |
726 frame.error_code = QUIC_NO_ERROR; | 731 frame.error_code = QUIC_NO_ERROR; |
727 frame.error_details = "error"; | 732 frame.error_details = "error"; |
728 | 733 |
729 QuicFrames frames; | 734 QuicFrames frames; |
730 frames.push_back(QuicFrame(&frame)); | 735 frames.push_back(QuicFrame(&frame)); |
731 SerializedPacket serialized = SerializeAllFrames(frames); | 736 SerializedPacket serialized = SerializeAllFrames(frames); |
732 EXPECT_EQ(ENCRYPTION_NONE, serialized.encryption_level); | 737 EXPECT_EQ(ENCRYPTION_NONE, serialized.encryption_level); |
733 ASSERT_EQ(1u, serialized.packet_number); | 738 ASSERT_EQ(1u, serialized.packet_number); |
734 ASSERT_EQ(1u, creator_.packet_number()); | 739 ASSERT_EQ(1u, creator_.packet_number()); |
735 | 740 |
736 InSequence s; | 741 InSequence s; |
737 EXPECT_CALL(framer_visitor_, OnPacket()); | 742 EXPECT_CALL(framer_visitor_, OnPacket()); |
738 EXPECT_CALL(framer_visitor_, OnUnauthenticatedPublicHeader(_)); | 743 EXPECT_CALL(framer_visitor_, OnUnauthenticatedPublicHeader(_)); |
739 EXPECT_CALL(framer_visitor_, OnUnauthenticatedHeader(_)); | 744 EXPECT_CALL(framer_visitor_, OnUnauthenticatedHeader(_)); |
740 EXPECT_CALL(framer_visitor_, OnDecryptedPacket(_)); | 745 EXPECT_CALL(framer_visitor_, OnDecryptedPacket(_)); |
741 EXPECT_CALL(framer_visitor_, OnPacketHeader(_)); | 746 EXPECT_CALL(framer_visitor_, OnPacketHeader(_)); |
742 EXPECT_CALL(framer_visitor_, OnConnectionCloseFrame(_)); | 747 EXPECT_CALL(framer_visitor_, OnConnectionCloseFrame(_)); |
743 EXPECT_CALL(framer_visitor_, OnPacketComplete()); | 748 EXPECT_CALL(framer_visitor_, OnPacketComplete()); |
744 | 749 |
745 ProcessPacket(serialized.packet); | 750 ProcessPacket(serialized); |
746 delete serialized.packet; | |
747 } | 751 } |
748 | 752 |
749 TEST_P(QuicPacketCreatorTest, SwitchFecOnOffWithGroupInProgress) { | 753 TEST_P(QuicPacketCreatorTest, SwitchFecOnOffWithGroupInProgress) { |
750 // Send FEC packet every 6 packets. | 754 // Send FEC packet every 6 packets. |
751 creator_.set_max_packets_per_fec_group(6); | 755 creator_.set_max_packets_per_fec_group(6); |
752 // Turn on FEC protection. | 756 // Turn on FEC protection. |
753 QuicFrame frame; | 757 QuicFrame frame; |
754 QuicIOVector io_vector(MakeIOVector("test")); | 758 QuicIOVector io_vector(MakeIOVector("test")); |
755 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, |
756 MUST_FEC_PROTECT)); | 760 MUST_FEC_PROTECT)); |
(...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
905 ASSERT_TRUE(frame.stream_frame); | 909 ASSERT_TRUE(frame.stream_frame); |
906 | 910 |
907 // BytesFree() returns bytes available for the next frame, which will | 911 // BytesFree() returns bytes available for the next frame, which will |
908 // 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. |
909 EXPECT_EQ(2u, creator_.ExpansionOnNewFrame()); | 913 EXPECT_EQ(2u, creator_.ExpansionOnNewFrame()); |
910 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; |
911 EXPECT_EQ(expected_bytes_free, creator_.BytesFree()) << "delta: " << delta; | 915 EXPECT_EQ(expected_bytes_free, creator_.BytesFree()) << "delta: " << delta; |
912 EXPECT_CALL(delegate_, OnSerializedPacket(_)) | 916 EXPECT_CALL(delegate_, OnSerializedPacket(_)) |
913 .WillOnce(Invoke(this, &QuicPacketCreatorTest::SaveSerializedPacket)); | 917 .WillOnce(Invoke(this, &QuicPacketCreatorTest::SaveSerializedPacket)); |
914 creator_.Flush(); | 918 creator_.Flush(); |
915 ASSERT_TRUE(serialized_packet_.packet); | 919 ASSERT_TRUE(serialized_packet_.encrypted_buffer); |
916 ClearSerializedPacket(&serialized_packet_); | 920 DeleteSerializedPacket(); |
917 } | 921 } |
918 } | 922 } |
919 | 923 |
920 TEST_P(QuicPacketCreatorTest, StreamFrameConsumptionWithFec) { | 924 TEST_P(QuicPacketCreatorTest, StreamFrameConsumptionWithFec) { |
921 // Send FEC packet every 6 packets. | 925 // Send FEC packet every 6 packets. |
922 creator_.set_max_packets_per_fec_group(6); | 926 creator_.set_max_packets_per_fec_group(6); |
923 // Turn on FEC protection. | 927 // Turn on FEC protection. |
924 QuicFrame frame; | 928 QuicFrame frame; |
925 QuicIOVector io_vector(MakeIOVector("test")); | 929 QuicIOVector io_vector(MakeIOVector("test")); |
926 ASSERT_TRUE(creator_.ConsumeData(1u, io_vector, 0u, 0u, false, false, &frame, | 930 ASSERT_TRUE(creator_.ConsumeData(1u, io_vector, 0u, 0u, false, false, &frame, |
(...skipping 30 matching lines...) Expand all Loading... |
957 EXPECT_CALL(delegate_, OnSerializedPacket(_)) | 961 EXPECT_CALL(delegate_, OnSerializedPacket(_)) |
958 .WillOnce(Invoke(this, &QuicPacketCreatorTest::SaveSerializedPacket)); | 962 .WillOnce(Invoke(this, &QuicPacketCreatorTest::SaveSerializedPacket)); |
959 // Every 6th packet will generate an extra FEC packet. | 963 // Every 6th packet will generate an extra FEC packet. |
960 if (delta == -1 || delta == 5) { | 964 if (delta == -1 || delta == 5) { |
961 EXPECT_CALL(delegate_, OnSerializedPacket(_)) | 965 EXPECT_CALL(delegate_, OnSerializedPacket(_)) |
962 .WillOnce( | 966 .WillOnce( |
963 Invoke(this, &QuicPacketCreatorTest::ClearSerializedPacket)); | 967 Invoke(this, &QuicPacketCreatorTest::ClearSerializedPacket)); |
964 } | 968 } |
965 } | 969 } |
966 creator_.Flush(); | 970 creator_.Flush(); |
967 ASSERT_TRUE(serialized_packet_.packet); | 971 ASSERT_TRUE(serialized_packet_.encrypted_buffer); |
968 ClearSerializedPacket(&serialized_packet_); | 972 DeleteSerializedPacket(); |
969 } | 973 } |
970 } | 974 } |
971 | 975 |
972 TEST_P(QuicPacketCreatorTest, CryptoStreamFramePacketPadding) { | 976 TEST_P(QuicPacketCreatorTest, CryptoStreamFramePacketPadding) { |
973 // Compute the total overhead for a single frame in packet. | 977 // Compute the total overhead for a single frame in packet. |
974 const size_t overhead = GetPacketHeaderOverhead(NOT_IN_FEC_GROUP) + | 978 const size_t overhead = GetPacketHeaderOverhead(NOT_IN_FEC_GROUP) + |
975 GetEncryptionOverhead() + | 979 GetEncryptionOverhead() + |
976 GetStreamFrameOverhead(NOT_IN_FEC_GROUP); | 980 GetStreamFrameOverhead(NOT_IN_FEC_GROUP); |
977 ASSERT_GT(kMaxPacketSize, overhead); | 981 ASSERT_GT(kMaxPacketSize, overhead); |
978 size_t capacity = kDefaultMaxPacketSize - overhead; | 982 size_t capacity = kDefaultMaxPacketSize - overhead; |
979 // Now, test various sizes around this size. | 983 // Now, test various sizes around this size. |
980 for (int delta = -5; delta <= 5; ++delta) { | 984 for (int delta = -5; delta <= 5; ++delta) { |
981 string data(capacity + delta, 'A'); | 985 string data(capacity + delta, 'A'); |
982 size_t bytes_free = delta > 0 ? 0 : 0 - delta; | 986 size_t bytes_free = delta > 0 ? 0 : 0 - delta; |
983 | 987 |
984 QuicFrame frame; | 988 QuicFrame frame; |
985 QuicIOVector io_vector(MakeIOVector(data)); | 989 QuicIOVector io_vector(MakeIOVector(data)); |
986 EXPECT_CALL(delegate_, OnSerializedPacket(_)) | 990 EXPECT_CALL(delegate_, OnSerializedPacket(_)) |
987 .WillRepeatedly( | 991 .WillRepeatedly( |
988 Invoke(this, &QuicPacketCreatorTest::SaveSerializedPacket)); | 992 Invoke(this, &QuicPacketCreatorTest::SaveSerializedPacket)); |
989 ASSERT_TRUE(creator_.ConsumeData(kCryptoStreamId, io_vector, 0u, kOffset, | 993 ASSERT_TRUE(creator_.ConsumeData(kCryptoStreamId, io_vector, 0u, kOffset, |
990 false, true, &frame, MAY_FEC_PROTECT)); | 994 false, true, &frame, MAY_FEC_PROTECT)); |
991 ASSERT_TRUE(frame.stream_frame); | 995 ASSERT_TRUE(frame.stream_frame); |
992 size_t bytes_consumed = frame.stream_frame->frame_length; | 996 size_t bytes_consumed = frame.stream_frame->frame_length; |
993 EXPECT_LT(0u, bytes_consumed); | 997 EXPECT_LT(0u, bytes_consumed); |
994 creator_.Flush(); | 998 creator_.Flush(); |
995 ASSERT_TRUE(serialized_packet_.packet); | 999 ASSERT_TRUE(serialized_packet_.encrypted_buffer); |
996 // 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 |
997 // (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 |
998 // will not be padded. | 1002 // will not be padded. |
999 if (bytes_free < 3) { | 1003 if (bytes_free < 3) { |
1000 EXPECT_EQ(kDefaultMaxPacketSize - bytes_free, | 1004 EXPECT_EQ(kDefaultMaxPacketSize - bytes_free, |
1001 serialized_packet_.packet->length()); | 1005 serialized_packet_.encrypted_length); |
1002 } else { | 1006 } else { |
1003 EXPECT_EQ(kDefaultMaxPacketSize, serialized_packet_.packet->length()); | 1007 EXPECT_EQ(kDefaultMaxPacketSize, serialized_packet_.encrypted_length); |
1004 } | 1008 } |
1005 ClearSerializedPacket(&serialized_packet_); | 1009 DeleteSerializedPacket(); |
1006 } | 1010 } |
1007 } | 1011 } |
1008 | 1012 |
1009 TEST_P(QuicPacketCreatorTest, NonCryptoStreamFramePacketNonPadding) { | 1013 TEST_P(QuicPacketCreatorTest, NonCryptoStreamFramePacketNonPadding) { |
1010 // Compute the total overhead for a single frame in packet. | 1014 // Compute the total overhead for a single frame in packet. |
1011 const size_t overhead = GetPacketHeaderOverhead(NOT_IN_FEC_GROUP) + | 1015 const size_t overhead = GetPacketHeaderOverhead(NOT_IN_FEC_GROUP) + |
1012 GetEncryptionOverhead() + | 1016 GetEncryptionOverhead() + |
1013 GetStreamFrameOverhead(NOT_IN_FEC_GROUP); | 1017 GetStreamFrameOverhead(NOT_IN_FEC_GROUP); |
1014 ASSERT_GT(kDefaultMaxPacketSize, overhead); | 1018 ASSERT_GT(kDefaultMaxPacketSize, overhead); |
1015 size_t capacity = kDefaultMaxPacketSize - overhead; | 1019 size_t capacity = kDefaultMaxPacketSize - overhead; |
1016 // Now, test various sizes around this size. | 1020 // Now, test various sizes around this size. |
1017 for (int delta = -5; delta <= 5; ++delta) { | 1021 for (int delta = -5; delta <= 5; ++delta) { |
1018 string data(capacity + delta, 'A'); | 1022 string data(capacity + delta, 'A'); |
1019 size_t bytes_free = delta > 0 ? 0 : 0 - delta; | 1023 size_t bytes_free = delta > 0 ? 0 : 0 - delta; |
1020 | 1024 |
1021 QuicFrame frame; | 1025 QuicFrame frame; |
1022 QuicIOVector io_vector(MakeIOVector(data)); | 1026 QuicIOVector io_vector(MakeIOVector(data)); |
1023 EXPECT_CALL(delegate_, OnSerializedPacket(_)) | 1027 EXPECT_CALL(delegate_, OnSerializedPacket(_)) |
1024 .WillOnce(Invoke(this, &QuicPacketCreatorTest::SaveSerializedPacket)); | 1028 .WillOnce(Invoke(this, &QuicPacketCreatorTest::SaveSerializedPacket)); |
1025 ASSERT_TRUE(creator_.ConsumeData(kClientDataStreamId1, io_vector, 0u, | 1029 ASSERT_TRUE(creator_.ConsumeData(kClientDataStreamId1, io_vector, 0u, |
1026 kOffset, false, false, &frame, | 1030 kOffset, false, false, &frame, |
1027 MAY_FEC_PROTECT)); | 1031 MAY_FEC_PROTECT)); |
1028 ASSERT_TRUE(frame.stream_frame); | 1032 ASSERT_TRUE(frame.stream_frame); |
1029 size_t bytes_consumed = frame.stream_frame->frame_length; | 1033 size_t bytes_consumed = frame.stream_frame->frame_length; |
1030 EXPECT_LT(0u, bytes_consumed); | 1034 EXPECT_LT(0u, bytes_consumed); |
1031 creator_.Flush(); | 1035 creator_.Flush(); |
1032 ASSERT_TRUE(serialized_packet_.packet); | 1036 ASSERT_TRUE(serialized_packet_.encrypted_buffer); |
1033 if (bytes_free > 0) { | 1037 if (bytes_free > 0) { |
1034 EXPECT_EQ(kDefaultMaxPacketSize - bytes_free, | 1038 EXPECT_EQ(kDefaultMaxPacketSize - bytes_free, |
1035 serialized_packet_.packet->length()); | 1039 serialized_packet_.encrypted_length); |
1036 } else { | 1040 } else { |
1037 EXPECT_EQ(kDefaultMaxPacketSize, serialized_packet_.packet->length()); | 1041 EXPECT_EQ(kDefaultMaxPacketSize, serialized_packet_.encrypted_length); |
1038 } | 1042 } |
1039 ClearSerializedPacket(&serialized_packet_); | 1043 DeleteSerializedPacket(); |
1040 } | 1044 } |
1041 } | 1045 } |
1042 | 1046 |
1043 TEST_P(QuicPacketCreatorTest, SerializeVersionNegotiationPacket) { | 1047 TEST_P(QuicPacketCreatorTest, SerializeVersionNegotiationPacket) { |
1044 QuicFramerPeer::SetPerspective(&client_framer_, Perspective::IS_SERVER); | 1048 QuicFramerPeer::SetPerspective(&client_framer_, Perspective::IS_SERVER); |
1045 QuicVersionVector versions; | 1049 QuicVersionVector versions; |
1046 versions.push_back(test::QuicVersionMax()); | 1050 versions.push_back(test::QuicVersionMax()); |
1047 scoped_ptr<QuicEncryptedPacket> encrypted( | 1051 scoped_ptr<QuicEncryptedPacket> encrypted( |
1048 creator_.SerializeVersionNegotiationPacket(versions)); | 1052 creator_.SerializeVersionNegotiationPacket(versions)); |
1049 | 1053 |
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1126 InSequence s; | 1130 InSequence s; |
1127 EXPECT_CALL(framer_visitor_, OnPacket()); | 1131 EXPECT_CALL(framer_visitor_, OnPacket()); |
1128 EXPECT_CALL(framer_visitor_, OnUnauthenticatedPublicHeader(_)); | 1132 EXPECT_CALL(framer_visitor_, OnUnauthenticatedPublicHeader(_)); |
1129 EXPECT_CALL(framer_visitor_, OnUnauthenticatedHeader(_)); | 1133 EXPECT_CALL(framer_visitor_, OnUnauthenticatedHeader(_)); |
1130 EXPECT_CALL(framer_visitor_, OnDecryptedPacket(_)); | 1134 EXPECT_CALL(framer_visitor_, OnDecryptedPacket(_)); |
1131 EXPECT_CALL(framer_visitor_, OnPacketHeader(_)) | 1135 EXPECT_CALL(framer_visitor_, OnPacketHeader(_)) |
1132 .WillOnce(DoAll(SaveArg<0>(&header), Return(true))); | 1136 .WillOnce(DoAll(SaveArg<0>(&header), Return(true))); |
1133 EXPECT_CALL(framer_visitor_, OnStreamFrame(_)); | 1137 EXPECT_CALL(framer_visitor_, OnStreamFrame(_)); |
1134 EXPECT_CALL(framer_visitor_, OnPacketComplete()); | 1138 EXPECT_CALL(framer_visitor_, OnPacketComplete()); |
1135 } | 1139 } |
1136 ProcessPacket(serialized.packet); | 1140 ProcessPacket(serialized); |
1137 EXPECT_EQ(GetParam().version_serialization, | 1141 EXPECT_EQ(GetParam().version_serialization, |
1138 header.public_header.version_flag); | 1142 header.public_header.version_flag); |
1139 delete serialized.packet; | |
1140 } | 1143 } |
1141 | 1144 |
1142 TEST_P(QuicPacketCreatorTest, ConsumeDataLargerThanOneStreamFrame) { | 1145 TEST_P(QuicPacketCreatorTest, ConsumeDataLargerThanOneStreamFrame) { |
1143 if (!GetParam().version_serialization) { | 1146 if (!GetParam().version_serialization) { |
1144 creator_.StopSendingVersion(); | 1147 creator_.StopSendingVersion(); |
1145 } | 1148 } |
1146 // A string larger than fits into a frame. | 1149 // A string larger than fits into a frame. |
1147 size_t payload_length; | 1150 size_t payload_length; |
1148 creator_.SetMaxPacketLength(GetPacketLengthForOneStream( | 1151 creator_.SetMaxPacketLength(GetPacketLengthForOneStream( |
1149 client_framer_.version(), | 1152 client_framer_.version(), |
1150 QuicPacketCreatorPeer::SendVersionInPacket(&creator_), | 1153 QuicPacketCreatorPeer::SendVersionInPacket(&creator_), |
1151 QuicPacketCreatorPeer::SendPathIdInPacket(&creator_), | 1154 QuicPacketCreatorPeer::SendPathIdInPacket(&creator_), |
1152 creator_.connection_id_length(), PACKET_1BYTE_PACKET_NUMBER, | 1155 creator_.connection_id_length(), PACKET_1BYTE_PACKET_NUMBER, |
1153 NOT_IN_FEC_GROUP, &payload_length)); | 1156 NOT_IN_FEC_GROUP, &payload_length)); |
1154 QuicFrame frame; | 1157 QuicFrame frame; |
1155 const string too_long_payload(payload_length * 2, 'a'); | 1158 const string too_long_payload(payload_length * 2, 'a'); |
1156 QuicIOVector io_vector(MakeIOVector(too_long_payload)); | 1159 QuicIOVector io_vector(MakeIOVector(too_long_payload)); |
1157 EXPECT_CALL(delegate_, OnSerializedPacket(_)) | 1160 EXPECT_CALL(delegate_, OnSerializedPacket(_)) |
1158 .WillOnce(Invoke(this, &QuicPacketCreatorTest::SaveSerializedPacket)); | 1161 .WillOnce(Invoke(this, &QuicPacketCreatorTest::SaveSerializedPacket)); |
1159 ASSERT_TRUE(creator_.ConsumeData(1u, io_vector, 0u, 0u, true, false, &frame, | 1162 ASSERT_TRUE(creator_.ConsumeData(1u, io_vector, 0u, 0u, true, false, &frame, |
1160 MAY_FEC_PROTECT)); | 1163 MAY_FEC_PROTECT)); |
1161 ASSERT_TRUE(frame.stream_frame); | 1164 ASSERT_TRUE(frame.stream_frame); |
1162 size_t consumed = frame.stream_frame->frame_length; | 1165 size_t consumed = frame.stream_frame->frame_length; |
1163 EXPECT_EQ(payload_length, consumed); | 1166 EXPECT_EQ(payload_length, consumed); |
1164 const string payload(payload_length, 'a'); | 1167 const string payload(payload_length, 'a'); |
1165 CheckStreamFrame(frame, 1u, payload, 0u, false); | 1168 CheckStreamFrame(frame, 1u, payload, 0u, false); |
1166 creator_.Flush(); | 1169 creator_.Flush(); |
1167 ClearSerializedPacket(&serialized_packet_); | 1170 DeleteSerializedPacket(); |
1168 } | 1171 } |
1169 | 1172 |
1170 TEST_P(QuicPacketCreatorTest, AddFrameAndFlush) { | 1173 TEST_P(QuicPacketCreatorTest, AddFrameAndFlush) { |
1171 if (!GetParam().version_serialization) { | 1174 if (!GetParam().version_serialization) { |
1172 creator_.StopSendingVersion(); | 1175 creator_.StopSendingVersion(); |
1173 } | 1176 } |
1174 const size_t max_plaintext_size = | 1177 const size_t max_plaintext_size = |
1175 client_framer_.GetMaxPlaintextSize(creator_.max_packet_length()); | 1178 client_framer_.GetMaxPlaintextSize(creator_.max_packet_length()); |
1176 EXPECT_FALSE(creator_.HasPendingFrames()); | 1179 EXPECT_FALSE(creator_.HasPendingFrames()); |
1177 EXPECT_EQ(max_plaintext_size - | 1180 EXPECT_EQ(max_plaintext_size - |
(...skipping 22 matching lines...) Expand all Loading... |
1200 EXPECT_TRUE(creator_.AddSavedFrame(QuicFrame(padding_frame))); | 1203 EXPECT_TRUE(creator_.AddSavedFrame(QuicFrame(padding_frame))); |
1201 EXPECT_TRUE(creator_.HasPendingFrames()); | 1204 EXPECT_TRUE(creator_.HasPendingFrames()); |
1202 EXPECT_EQ(0u, creator_.BytesFree()); | 1205 EXPECT_EQ(0u, creator_.BytesFree()); |
1203 | 1206 |
1204 // Packet is full. Creator will flush. | 1207 // Packet is full. Creator will flush. |
1205 EXPECT_CALL(delegate_, OnSerializedPacket(_)) | 1208 EXPECT_CALL(delegate_, OnSerializedPacket(_)) |
1206 .WillOnce(Invoke(this, &QuicPacketCreatorTest::SaveSerializedPacket)); | 1209 .WillOnce(Invoke(this, &QuicPacketCreatorTest::SaveSerializedPacket)); |
1207 EXPECT_FALSE(creator_.AddSavedFrame(QuicFrame(&ack_frame))); | 1210 EXPECT_FALSE(creator_.AddSavedFrame(QuicFrame(&ack_frame))); |
1208 | 1211 |
1209 // Ensure the packet is successfully created. | 1212 // Ensure the packet is successfully created. |
1210 ASSERT_TRUE(serialized_packet_.packet); | 1213 ASSERT_TRUE(serialized_packet_.encrypted_buffer); |
1211 ASSERT_FALSE(serialized_packet_.retransmittable_frames.empty()); | 1214 ASSERT_FALSE(serialized_packet_.retransmittable_frames.empty()); |
1212 const QuicFrames& retransmittable = serialized_packet_.retransmittable_frames; | 1215 const QuicFrames& retransmittable = serialized_packet_.retransmittable_frames; |
1213 ASSERT_EQ(1u, retransmittable.size()); | 1216 ASSERT_EQ(1u, retransmittable.size()); |
1214 EXPECT_EQ(STREAM_FRAME, retransmittable[0].type); | 1217 EXPECT_EQ(STREAM_FRAME, retransmittable[0].type); |
1215 ASSERT_TRUE(retransmittable[0].stream_frame); | 1218 ASSERT_TRUE(retransmittable[0].stream_frame); |
1216 ClearSerializedPacket(&serialized_packet_); | 1219 DeleteSerializedPacket(); |
1217 | 1220 |
1218 EXPECT_FALSE(creator_.HasPendingFrames()); | 1221 EXPECT_FALSE(creator_.HasPendingFrames()); |
1219 EXPECT_EQ(max_plaintext_size - | 1222 EXPECT_EQ(max_plaintext_size - |
1220 GetPacketHeaderSize( | 1223 GetPacketHeaderSize( |
1221 creator_.connection_id_length(), | 1224 creator_.connection_id_length(), |
1222 QuicPacketCreatorPeer::SendVersionInPacket(&creator_), | 1225 QuicPacketCreatorPeer::SendVersionInPacket(&creator_), |
1223 /*include_path_id=*/false, PACKET_1BYTE_PACKET_NUMBER, | 1226 /*include_path_id=*/false, PACKET_1BYTE_PACKET_NUMBER, |
1224 NOT_IN_FEC_GROUP), | 1227 NOT_IN_FEC_GROUP), |
1225 creator_.BytesFree()); | 1228 creator_.BytesFree()); |
1226 } | 1229 } |
(...skipping 29 matching lines...) Expand all Loading... |
1256 EXPECT_EQ(4u, consumed); | 1259 EXPECT_EQ(4u, consumed); |
1257 EXPECT_TRUE(creator_.HasPendingFrames()); | 1260 EXPECT_TRUE(creator_.HasPendingFrames()); |
1258 | 1261 |
1259 // Ensure the packet is successfully created, and the packet size estimate | 1262 // Ensure the packet is successfully created, and the packet size estimate |
1260 // matches the serialized packet length. | 1263 // matches the serialized packet length. |
1261 EXPECT_CALL(entropy_calculator_, EntropyHash(_)).WillOnce(testing::Return(0)); | 1264 EXPECT_CALL(entropy_calculator_, EntropyHash(_)).WillOnce(testing::Return(0)); |
1262 EXPECT_CALL(delegate_, OnSerializedPacket(_)) | 1265 EXPECT_CALL(delegate_, OnSerializedPacket(_)) |
1263 .WillOnce(Invoke(this, &QuicPacketCreatorTest::SaveSerializedPacket)); | 1266 .WillOnce(Invoke(this, &QuicPacketCreatorTest::SaveSerializedPacket)); |
1264 size_t est_packet_size = creator_.PacketSize(); | 1267 size_t est_packet_size = creator_.PacketSize(); |
1265 creator_.Flush(); | 1268 creator_.Flush(); |
1266 ASSERT_TRUE(serialized_packet_.packet); | 1269 ASSERT_TRUE(serialized_packet_.encrypted_buffer); |
1267 EXPECT_EQ(est_packet_size, client_framer_.GetMaxPlaintextSize( | 1270 EXPECT_EQ(est_packet_size, client_framer_.GetMaxPlaintextSize( |
1268 serialized_packet_.packet->length())); | 1271 serialized_packet_.encrypted_length)); |
1269 ClearSerializedPacket(&serialized_packet_); | 1272 DeleteSerializedPacket(); |
1270 } | 1273 } |
1271 | 1274 |
1272 TEST_P(QuicPacketCreatorTest, SerializeTruncatedAckFrameWithSmallPacketSize) { | 1275 TEST_P(QuicPacketCreatorTest, SerializeTruncatedAckFrameWithSmallPacketSize) { |
1273 if (!GetParam().version_serialization) { | 1276 if (!GetParam().version_serialization) { |
1274 creator_.StopSendingVersion(); | 1277 creator_.StopSendingVersion(); |
1275 } | 1278 } |
1276 creator_.SetMaxPacketLength(500u); | 1279 creator_.SetMaxPacketLength(500u); |
1277 | 1280 |
1278 const size_t max_plaintext_size = | 1281 const size_t max_plaintext_size = |
1279 client_framer_.GetMaxPlaintextSize(creator_.max_packet_length()); | 1282 client_framer_.GetMaxPlaintextSize(creator_.max_packet_length()); |
(...skipping 14 matching lines...) Expand all Loading... |
1294 creator_.PacketSize()); | 1297 creator_.PacketSize()); |
1295 EXPECT_EQ(0u, creator_.BytesFree()); | 1298 EXPECT_EQ(0u, creator_.BytesFree()); |
1296 | 1299 |
1297 // Ensure the packet is successfully created, and the packet size estimate | 1300 // Ensure the packet is successfully created, and the packet size estimate |
1298 // may not match the serialized packet length. | 1301 // may not match the serialized packet length. |
1299 EXPECT_CALL(entropy_calculator_, EntropyHash(_)).WillOnce(Return(0)); | 1302 EXPECT_CALL(entropy_calculator_, EntropyHash(_)).WillOnce(Return(0)); |
1300 size_t est_packet_size = creator_.PacketSize(); | 1303 size_t est_packet_size = creator_.PacketSize(); |
1301 EXPECT_CALL(delegate_, OnSerializedPacket(_)) | 1304 EXPECT_CALL(delegate_, OnSerializedPacket(_)) |
1302 .WillOnce(Invoke(this, &QuicPacketCreatorTest::SaveSerializedPacket)); | 1305 .WillOnce(Invoke(this, &QuicPacketCreatorTest::SaveSerializedPacket)); |
1303 creator_.Flush(); | 1306 creator_.Flush(); |
1304 ASSERT_TRUE(serialized_packet_.packet); | 1307 ASSERT_TRUE(serialized_packet_.encrypted_buffer); |
1305 EXPECT_GE(est_packet_size, client_framer_.GetMaxPlaintextSize( | 1308 EXPECT_GE(est_packet_size, client_framer_.GetMaxPlaintextSize( |
1306 serialized_packet_.packet->length())); | 1309 serialized_packet_.encrypted_length)); |
1307 ClearSerializedPacket(&serialized_packet_); | 1310 DeleteSerializedPacket(); |
1308 } | 1311 } |
1309 | 1312 |
1310 TEST_P(QuicPacketCreatorTest, EntropyFlag) { | 1313 TEST_P(QuicPacketCreatorTest, EntropyFlag) { |
1311 frames_.push_back( | 1314 frames_.push_back( |
1312 QuicFrame(new QuicStreamFrame(0u, false, 0u, StringPiece()))); | 1315 QuicFrame(new QuicStreamFrame(0u, false, 0u, StringPiece()))); |
1313 | 1316 |
1314 for (int i = 0; i < 2; ++i) { | 1317 for (int i = 0; i < 2; ++i) { |
1315 for (int j = 0; j < 64; ++j) { | 1318 for (int j = 0; j < 64; ++j) { |
1316 SerializedPacket serialized = SerializeAllFrames(frames_); | 1319 SerializedPacket serialized = SerializeAllFrames(frames_); |
1317 // Verify both BoolSource and hash algorithm. | 1320 // Verify both BoolSource and hash algorithm. |
1318 bool expected_rand_bool = | 1321 bool expected_rand_bool = |
1319 (mock_random_.RandUint64() & (UINT64_C(1) << j)) != 0; | 1322 (mock_random_.RandUint64() & (UINT64_C(1) << j)) != 0; |
1320 bool observed_rand_bool = | 1323 bool observed_rand_bool = |
1321 (serialized.entropy_hash & (1 << ((j + 1) % 8))) != 0; | 1324 (serialized.entropy_hash & (1 << ((j + 1) % 8))) != 0; |
1322 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)); |
1323 EXPECT_EQ(expected_rand_bool, observed_rand_bool); | 1326 EXPECT_EQ(expected_rand_bool, observed_rand_bool); |
1324 EXPECT_EQ(0, rest_of_hash); | 1327 EXPECT_EQ(0, rest_of_hash); |
1325 delete serialized.packet; | |
1326 } | 1328 } |
1327 // 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. |
1328 mock_random_.ChangeValue(); | 1330 mock_random_.ChangeValue(); |
1329 } | 1331 } |
1330 | 1332 |
1331 delete frames_[0].stream_frame; | 1333 delete frames_[0].stream_frame; |
1332 } | 1334 } |
1333 | 1335 |
1334 TEST_P(QuicPacketCreatorTest, ResetFecGroup) { | 1336 TEST_P(QuicPacketCreatorTest, ResetFecGroup) { |
1335 // Send FEC packet every 6 packets. | 1337 // Send FEC packet every 6 packets. |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1389 // Should return true since there are packets in the FEC group. | 1391 // Should return true since there are packets in the FEC group. |
1390 ASSERT_TRUE(creator_.ShouldSendFec(/*force_close=*/true)); | 1392 ASSERT_TRUE(creator_.ShouldSendFec(/*force_close=*/true)); |
1391 | 1393 |
1392 // Change FEC policy, send FEC packet and close FEC group. | 1394 // Change FEC policy, send FEC packet and close FEC group. |
1393 creator_.set_fec_send_policy(FEC_ANY_TRIGGER); | 1395 creator_.set_fec_send_policy(FEC_ANY_TRIGGER); |
1394 EXPECT_CALL(delegate_, OnSerializedPacket(_)) | 1396 EXPECT_CALL(delegate_, OnSerializedPacket(_)) |
1395 .WillOnce(Invoke(this, &QuicPacketCreatorTest::SaveSerializedPacket)); | 1397 .WillOnce(Invoke(this, &QuicPacketCreatorTest::SaveSerializedPacket)); |
1396 creator_.MaybeSendFecPacketAndCloseGroup(/*force_send_fec=*/true, | 1398 creator_.MaybeSendFecPacketAndCloseGroup(/*force_send_fec=*/true, |
1397 /*is_fec_timeout=*/false); | 1399 /*is_fec_timeout=*/false); |
1398 ASSERT_EQ(3u, serialized_packet_.packet_number); | 1400 ASSERT_EQ(3u, serialized_packet_.packet_number); |
1399 ClearSerializedPacket(&serialized_packet_); | 1401 DeleteSerializedPacket(); |
1400 } | 1402 } |
1401 | 1403 |
1402 TEST_P(QuicPacketCreatorTest, ResetFecGroupWithQueuedFrames) { | 1404 TEST_P(QuicPacketCreatorTest, ResetFecGroupWithQueuedFrames) { |
1403 // Send FEC packet every 6 packets. | 1405 // Send FEC packet every 6 packets. |
1404 creator_.set_max_packets_per_fec_group(6); | 1406 creator_.set_max_packets_per_fec_group(6); |
1405 // Add a stream frame to the creator and turn on FEC protection. | 1407 // Add a stream frame to the creator and turn on FEC protection. |
1406 QuicFrame frame; | 1408 QuicFrame frame; |
1407 QuicIOVector io_vector(MakeIOVector("test")); | 1409 QuicIOVector io_vector(MakeIOVector("test")); |
1408 ASSERT_TRUE(creator_.ConsumeData(1u, io_vector, 0u, 0u, false, false, &frame, | 1410 ASSERT_TRUE(creator_.ConsumeData(1u, io_vector, 0u, 0u, false, false, &frame, |
1409 MUST_FEC_PROTECT)); | 1411 MUST_FEC_PROTECT)); |
(...skipping 198 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1608 EXPECT_TRUE(creator_.HasPendingFrames()); | 1610 EXPECT_TRUE(creator_.HasPendingFrames()); |
1609 EXPECT_EQ(0u, creator_.packet_number()); | 1611 EXPECT_EQ(0u, creator_.packet_number()); |
1610 EXPECT_CALL(delegate_, OnSerializedPacket(_)) | 1612 EXPECT_CALL(delegate_, OnSerializedPacket(_)) |
1611 .WillRepeatedly( | 1613 .WillRepeatedly( |
1612 Invoke(this, &QuicPacketCreatorTest::SaveSerializedPacket)); | 1614 Invoke(this, &QuicPacketCreatorTest::SaveSerializedPacket)); |
1613 creator_.Flush(); | 1615 creator_.Flush(); |
1614 EXPECT_FALSE(creator_.HasPendingFrames()); | 1616 EXPECT_FALSE(creator_.HasPendingFrames()); |
1615 EXPECT_EQ(1u, creator_.packet_number()); | 1617 EXPECT_EQ(1u, creator_.packet_number()); |
1616 // Verify serialized data packet's path id. | 1618 // Verify serialized data packet's path id. |
1617 EXPECT_EQ(kDefaultPathId, serialized_packet_.path_id); | 1619 EXPECT_EQ(kDefaultPathId, serialized_packet_.path_id); |
1618 ClearSerializedPacket(&serialized_packet_); | 1620 DeleteSerializedPacket(); |
1619 | 1621 |
1620 // Change to path 1. | 1622 // Change to path 1. |
1621 QuicPathId kPathId1 = 1; | 1623 QuicPathId kPathId1 = 1; |
1622 creator_.SetCurrentPath(kPathId1, 1, 0); | 1624 creator_.SetCurrentPath(kPathId1, 1, 0); |
1623 EXPECT_EQ(kPathId1, QuicPacketCreatorPeer::GetCurrentPath(&creator_)); | 1625 EXPECT_EQ(kPathId1, QuicPacketCreatorPeer::GetCurrentPath(&creator_)); |
1624 EXPECT_FALSE(creator_.HasPendingFrames()); | 1626 EXPECT_FALSE(creator_.HasPendingFrames()); |
1625 EXPECT_EQ(0u, creator_.packet_number()); | 1627 EXPECT_EQ(0u, creator_.packet_number()); |
1626 EXPECT_EQ(PACKET_1BYTE_PACKET_NUMBER, | 1628 EXPECT_EQ(PACKET_1BYTE_PACKET_NUMBER, |
1627 QuicPacketCreatorPeer::NextPacketNumberLength(&creator_)); | 1629 QuicPacketCreatorPeer::NextPacketNumberLength(&creator_)); |
1628 | 1630 |
1629 // Add a stream frame to the creator and flush the packet. | 1631 // Add a stream frame to the creator and flush the packet. |
1630 ASSERT_TRUE(creator_.ConsumeData(1u, io_vector, 0u, 0u, false, false, &frame, | 1632 ASSERT_TRUE(creator_.ConsumeData(1u, io_vector, 0u, 0u, false, false, &frame, |
1631 MAY_FEC_PROTECT)); | 1633 MAY_FEC_PROTECT)); |
1632 ASSERT_TRUE(frame.stream_frame); | 1634 ASSERT_TRUE(frame.stream_frame); |
1633 consumed = frame.stream_frame->frame_length; | 1635 consumed = frame.stream_frame->frame_length; |
1634 EXPECT_EQ(4u, consumed); | 1636 EXPECT_EQ(4u, consumed); |
1635 EXPECT_TRUE(creator_.HasPendingFrames()); | 1637 EXPECT_TRUE(creator_.HasPendingFrames()); |
1636 creator_.Flush(); | 1638 creator_.Flush(); |
1637 // Verify serialized data packet's path id. | 1639 // Verify serialized data packet's path id. |
1638 EXPECT_EQ(kPathId1, serialized_packet_.path_id); | 1640 EXPECT_EQ(kPathId1, serialized_packet_.path_id); |
1639 ClearSerializedPacket(&serialized_packet_); | 1641 DeleteSerializedPacket(); |
1640 } | 1642 } |
1641 | 1643 |
1642 TEST_P(QuicPacketCreatorTest, AddUnencryptedStreamDataClosesConnection) { | 1644 TEST_P(QuicPacketCreatorTest, AddUnencryptedStreamDataClosesConnection) { |
1643 FLAGS_quic_never_write_unencrypted_data = true; | 1645 FLAGS_quic_never_write_unencrypted_data = true; |
1644 EXPECT_CALL(delegate_, CloseConnection(_, _)); | 1646 EXPECT_CALL(delegate_, CloseConnection(_, _)); |
1645 QuicStreamFrame stream_frame(kHeadersStreamId, /*fin=*/false, 0u, | 1647 QuicStreamFrame stream_frame(kHeadersStreamId, /*fin=*/false, 0u, |
1646 StringPiece()); | 1648 StringPiece()); |
1647 EXPECT_DFATAL(creator_.AddSavedFrame(QuicFrame(&stream_frame)), | 1649 EXPECT_DFATAL(creator_.AddSavedFrame(QuicFrame(&stream_frame)), |
1648 "Cannot send stream data without encryption."); | 1650 "Cannot send stream data without encryption."); |
1649 } | 1651 } |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1694 EXPECT_CALL(delegate_, CloseConnection(QUIC_UNENCRYPTED_FEC_DATA, _)); | 1696 EXPECT_CALL(delegate_, CloseConnection(QUIC_UNENCRYPTED_FEC_DATA, _)); |
1695 char seralized_fec_buffer[kMaxPacketSize]; | 1697 char seralized_fec_buffer[kMaxPacketSize]; |
1696 EXPECT_DFATAL(QuicPacketCreatorPeer::SerializeFec( | 1698 EXPECT_DFATAL(QuicPacketCreatorPeer::SerializeFec( |
1697 &creator_, seralized_fec_buffer, kMaxPacketSize), | 1699 &creator_, seralized_fec_buffer, kMaxPacketSize), |
1698 "SerializeFEC must be called with encryption."); | 1700 "SerializeFEC must be called with encryption."); |
1699 } | 1701 } |
1700 | 1702 |
1701 } // namespace | 1703 } // namespace |
1702 } // namespace test | 1704 } // namespace test |
1703 } // namespace net | 1705 } // namespace net |
OLD | NEW |