| 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_generator.h" | 5 #include "net/quic/quic_packet_generator.h" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 | 8 |
| 9 #include "net/quic/crypto/crypto_protocol.h" | 9 #include "net/quic/crypto/crypto_protocol.h" |
| 10 #include "net/quic/crypto/null_encrypter.h" | 10 #include "net/quic/crypto/null_encrypter.h" |
| (...skipping 545 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 556 EXPECT_EQ(3u, consumed.bytes_consumed); | 556 EXPECT_EQ(3u, consumed.bytes_consumed); |
| 557 EXPECT_TRUE(consumed.fin_consumed); | 557 EXPECT_TRUE(consumed.fin_consumed); |
| 558 EXPECT_FALSE(generator_.HasQueuedFrames()); | 558 EXPECT_FALSE(generator_.HasQueuedFrames()); |
| 559 | 559 |
| 560 PacketContents contents; | 560 PacketContents contents; |
| 561 contents.num_stream_frames = 1; | 561 contents.num_stream_frames = 1; |
| 562 CheckPacketContains(contents, packet_); | 562 CheckPacketContains(contents, packet_); |
| 563 CheckPacketContains(contents, packet2_); | 563 CheckPacketContains(contents, packet2_); |
| 564 } | 564 } |
| 565 | 565 |
| 566 TEST_F(QuicPacketGeneratorTest, FecGroupSizeOnCongestionWindowChange) { |
| 567 delegate_.SetCanWriteAnything(); |
| 568 creator_->set_max_packets_per_fec_group(50); |
| 569 EXPECT_EQ(50u, creator_->max_packets_per_fec_group()); |
| 570 EXPECT_FALSE(creator_->IsFecGroupOpen()); |
| 571 |
| 572 // On reduced cwnd. |
| 573 generator_.OnCongestionWindowChange(7 * kDefaultTCPMSS); |
| 574 EXPECT_EQ(3u, creator_->max_packets_per_fec_group()); |
| 575 |
| 576 // On increased cwnd. |
| 577 generator_.OnCongestionWindowChange(100 * kDefaultTCPMSS); |
| 578 EXPECT_EQ(50u, creator_->max_packets_per_fec_group()); |
| 579 |
| 580 // On collapsed cwnd. |
| 581 generator_.OnCongestionWindowChange(1 * kDefaultTCPMSS); |
| 582 EXPECT_EQ(2u, creator_->max_packets_per_fec_group()); |
| 583 } |
| 584 |
| 585 TEST_F(QuicPacketGeneratorTest, FecGroupSizeChangeWithOpenGroup) { |
| 586 delegate_.SetCanWriteAnything(); |
| 587 // TODO(jri): This starting of batch mode should not be required when |
| 588 // FEC sending is separated from batching operations. |
| 589 generator_.StartBatchOperations(); |
| 590 creator_->set_max_packets_per_fec_group(50); |
| 591 EXPECT_EQ(50u, creator_->max_packets_per_fec_group()); |
| 592 EXPECT_FALSE(creator_->IsFecGroupOpen()); |
| 593 |
| 594 // Send enough data to create 4 packets with MUST_FEC_PROTECT flag. |
| 595 // 3 packets are sent, one is queued in the creator. |
| 596 { |
| 597 InSequence dummy; |
| 598 EXPECT_CALL(delegate_, OnSerializedPacket(_)).WillOnce( |
| 599 DoAll(SaveArg<0>(&packet_), Return(true))); |
| 600 EXPECT_CALL(delegate_, OnSerializedPacket(_)).WillOnce( |
| 601 DoAll(SaveArg<0>(&packet2_), Return(true))); |
| 602 EXPECT_CALL(delegate_, OnSerializedPacket(_)).WillOnce( |
| 603 DoAll(SaveArg<0>(&packet3_), Return(true))); |
| 604 } |
| 605 size_t data_len = 3 * kDefaultMaxPacketSize + 1; |
| 606 QuicConsumedData consumed = generator_.ConsumeData( |
| 607 7, CreateData(data_len), 0, true, MUST_FEC_PROTECT, NULL); |
| 608 EXPECT_EQ(data_len, consumed.bytes_consumed); |
| 609 EXPECT_TRUE(creator_->IsFecGroupOpen()); |
| 610 |
| 611 // Change FEC groupsize. |
| 612 generator_.OnCongestionWindowChange(2 * kDefaultTCPMSS); |
| 613 EXPECT_EQ(2u, creator_->max_packets_per_fec_group()); |
| 614 |
| 615 // Send enough data to trigger one unprotected data packet, |
| 616 // causing the FEC packet to also be sent. |
| 617 { |
| 618 InSequence dummy; |
| 619 EXPECT_CALL(delegate_, OnSerializedPacket(_)).WillOnce( |
| 620 DoAll(SaveArg<0>(&packet4_), Return(true))); |
| 621 EXPECT_CALL(delegate_, OnSerializedPacket(_)).WillOnce( |
| 622 DoAll(SaveArg<0>(&packet5_), Return(true))); |
| 623 } |
| 624 consumed = generator_.ConsumeData(7, CreateData(kDefaultMaxPacketSize), 0, |
| 625 true, MAY_FEC_PROTECT, NULL); |
| 626 EXPECT_EQ(kDefaultMaxPacketSize, consumed.bytes_consumed); |
| 627 // Verify that one FEC packet was sent. |
| 628 CheckPacketIsFec(packet5_, /*fec_group=*/1u); |
| 629 EXPECT_FALSE(creator_->IsFecGroupOpen()); |
| 630 EXPECT_FALSE(creator_->IsFecProtected()); |
| 631 } |
| 632 |
| 566 TEST_F(QuicPacketGeneratorTest, SwitchFecOnOff) { | 633 TEST_F(QuicPacketGeneratorTest, SwitchFecOnOff) { |
| 567 delegate_.SetCanWriteAnything(); | 634 delegate_.SetCanWriteAnything(); |
| 568 // Enable FEC. | |
| 569 creator_->set_max_packets_per_fec_group(2); | 635 creator_->set_max_packets_per_fec_group(2); |
| 570 EXPECT_FALSE(creator_->IsFecProtected()); | 636 EXPECT_FALSE(creator_->IsFecProtected()); |
| 571 | 637 |
| 572 // Send one unprotected data packet. | 638 // Send one unprotected data packet. |
| 573 EXPECT_CALL(delegate_, OnSerializedPacket(_)).WillOnce( | 639 EXPECT_CALL(delegate_, OnSerializedPacket(_)).WillOnce( |
| 574 DoAll(SaveArg<0>(&packet_), Return(true))); | 640 DoAll(SaveArg<0>(&packet_), Return(true))); |
| 575 QuicConsumedData consumed = | 641 QuicConsumedData consumed = |
| 576 generator_.ConsumeData(5, CreateData(1u), 0, true, MAY_FEC_PROTECT, | 642 generator_.ConsumeData(5, CreateData(1u), 0, true, MAY_FEC_PROTECT, |
| 577 NULL); | 643 NULL); |
| 578 EXPECT_EQ(1u, consumed.bytes_consumed); | 644 EXPECT_EQ(1u, consumed.bytes_consumed); |
| (...skipping 318 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 897 | 963 |
| 898 // The second should have the remainder of the stream data. | 964 // The second should have the remainder of the stream data. |
| 899 PacketContents contents2; | 965 PacketContents contents2; |
| 900 contents2.num_goaway_frames = 1; | 966 contents2.num_goaway_frames = 1; |
| 901 contents2.num_stream_frames = 1; | 967 contents2.num_stream_frames = 1; |
| 902 CheckPacketContains(contents2, packet2_); | 968 CheckPacketContains(contents2, packet2_); |
| 903 } | 969 } |
| 904 | 970 |
| 905 } // namespace test | 971 } // namespace test |
| 906 } // namespace net | 972 } // namespace net |
| OLD | NEW |