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_session.h" | 5 #include "net/quic/quic_session.h" |
6 | 6 |
7 #include <set> | 7 #include <set> |
8 #include <vector> | 8 #include <vector> |
9 | 9 |
10 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
(...skipping 503 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
514 EXPECT_CALL(*stream4, OnCanWrite()); | 514 EXPECT_CALL(*stream4, OnCanWrite()); |
515 session_.OnCanWrite(); | 515 session_.OnCanWrite(); |
516 EXPECT_FALSE(session_.WillingAndAbleToWrite()); | 516 EXPECT_FALSE(session_.WillingAndAbleToWrite()); |
517 } | 517 } |
518 | 518 |
519 TEST_P(QuicSessionTest, OnCanWriteLimitsNumWritesIfFlowControlBlocked) { | 519 TEST_P(QuicSessionTest, OnCanWriteLimitsNumWritesIfFlowControlBlocked) { |
520 if (version() < QUIC_VERSION_19) { | 520 if (version() < QUIC_VERSION_19) { |
521 return; | 521 return; |
522 } | 522 } |
523 | 523 |
524 ValueRestore<bool> old_flag(&FLAGS_enable_quic_connection_flow_control, true); | 524 ValueRestore<bool> old_flag(&FLAGS_enable_quic_connection_flow_control_2, |
| 525 true); |
525 // Ensure connection level flow control blockage. | 526 // Ensure connection level flow control blockage. |
526 QuicFlowControllerPeer::SetSendWindowOffset(session_.flow_controller(), 0); | 527 QuicFlowControllerPeer::SetSendWindowOffset(session_.flow_controller(), 0); |
527 EXPECT_TRUE(session_.flow_controller()->IsBlocked()); | 528 EXPECT_TRUE(session_.flow_controller()->IsBlocked()); |
528 | 529 |
529 // Mark the crypto and headers streams as write blocked, we expect them to be | 530 // Mark the crypto and headers streams as write blocked, we expect them to be |
530 // allowed to write later. | 531 // allowed to write later. |
531 session_.MarkWriteBlocked(kCryptoStreamId, kHighestPriority); | 532 session_.MarkWriteBlocked(kCryptoStreamId, kHighestPriority); |
532 session_.MarkWriteBlocked(kHeadersStreamId, kHighestPriority); | 533 session_.MarkWriteBlocked(kHeadersStreamId, kHighestPriority); |
533 | 534 |
534 // Create a data stream, and although it is write blocked we never expect it | 535 // Create a data stream, and although it is write blocked we never expect it |
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
663 SendConnectionClose(QUIC_FLOW_CONTROL_INVALID_WINDOW)).Times(2); | 664 SendConnectionClose(QUIC_FLOW_CONTROL_INVALID_WINDOW)).Times(2); |
664 session_.OnConfigNegotiated(); | 665 session_.OnConfigNegotiated(); |
665 } | 666 } |
666 | 667 |
667 TEST_P(QuicSessionTest, ConnectionFlowControlAccountingRstOutOfOrder) { | 668 TEST_P(QuicSessionTest, ConnectionFlowControlAccountingRstOutOfOrder) { |
668 if (version() < QUIC_VERSION_19) { | 669 if (version() < QUIC_VERSION_19) { |
669 return; | 670 return; |
670 } | 671 } |
671 | 672 |
672 ValueRestore<bool> old_flag2(&FLAGS_enable_quic_stream_flow_control_2, true); | 673 ValueRestore<bool> old_flag2(&FLAGS_enable_quic_stream_flow_control_2, true); |
673 ValueRestore<bool> old_flag(&FLAGS_enable_quic_connection_flow_control, true); | 674 ValueRestore<bool> old_flag(&FLAGS_enable_quic_connection_flow_control_2, |
| 675 true); |
674 // Test that when we receive an out of order stream RST we correctly adjust | 676 // Test that when we receive an out of order stream RST we correctly adjust |
675 // our connection level flow control receive window. | 677 // our connection level flow control receive window. |
676 // On close, the stream should mark as consumed all bytes between the highest | 678 // On close, the stream should mark as consumed all bytes between the highest |
677 // byte consumed so far and the final byte offset from the RST frame. | 679 // byte consumed so far and the final byte offset from the RST frame. |
678 TestStream* stream = session_.CreateOutgoingDataStream(); | 680 TestStream* stream = session_.CreateOutgoingDataStream(); |
679 | 681 |
680 const QuicStreamOffset kByteOffset = 1 + kInitialFlowControlWindowForTest / 2; | 682 const QuicStreamOffset kByteOffset = 1 + kInitialFlowControlWindowForTest / 2; |
681 // Expect no stream WINDOW_UPDATE frames, as stream read side closed. | 683 // Expect no stream WINDOW_UPDATE frames, as stream read side closed. |
682 EXPECT_CALL(*connection_, SendWindowUpdate(stream->id(), _)).Times(0); | 684 EXPECT_CALL(*connection_, SendWindowUpdate(stream->id(), _)).Times(0); |
683 // We do expect a connection level WINDOW_UPDATE when the stream is reset. | 685 // We do expect a connection level WINDOW_UPDATE when the stream is reset. |
684 EXPECT_CALL(*connection_, | 686 EXPECT_CALL(*connection_, |
685 SendWindowUpdate( | 687 SendWindowUpdate( |
686 0, kInitialFlowControlWindowForTest + kByteOffset)).Times(1); | 688 0, kInitialFlowControlWindowForTest + kByteOffset)).Times(1); |
687 | 689 |
688 QuicRstStreamFrame rst_frame(stream->id(), QUIC_STREAM_CANCELLED, | 690 QuicRstStreamFrame rst_frame(stream->id(), QUIC_STREAM_CANCELLED, |
689 kByteOffset); | 691 kByteOffset); |
690 session_.OnRstStream(rst_frame); | 692 session_.OnRstStream(rst_frame); |
691 session_.PostProcessAfterData(); | 693 session_.PostProcessAfterData(); |
692 EXPECT_EQ(kByteOffset, session_.flow_controller()->bytes_consumed()); | 694 EXPECT_EQ(kByteOffset, session_.flow_controller()->bytes_consumed()); |
693 } | 695 } |
694 | 696 |
695 TEST_P(QuicSessionTest, ConnectionFlowControlAccountingFinAndLocalReset) { | 697 TEST_P(QuicSessionTest, ConnectionFlowControlAccountingFinAndLocalReset) { |
696 if (version() < QUIC_VERSION_19) { | 698 if (version() < QUIC_VERSION_19) { |
697 return; | 699 return; |
698 } | 700 } |
699 | 701 |
700 ValueRestore<bool> old_flag2(&FLAGS_enable_quic_stream_flow_control_2, true); | 702 ValueRestore<bool> old_flag2(&FLAGS_enable_quic_stream_flow_control_2, true); |
701 ValueRestore<bool> old_flag(&FLAGS_enable_quic_connection_flow_control, true); | 703 ValueRestore<bool> old_flag(&FLAGS_enable_quic_connection_flow_control_2, |
| 704 true); |
702 // Test the situation where we receive a FIN on a stream, and before we fully | 705 // Test the situation where we receive a FIN on a stream, and before we fully |
703 // consume all the data from the sequencer buffer we locally RST the stream. | 706 // consume all the data from the sequencer buffer we locally RST the stream. |
704 // The bytes between highest consumed byte, and the final byte offset that we | 707 // The bytes between highest consumed byte, and the final byte offset that we |
705 // determined when the FIN arrived, should be marked as consumed at the | 708 // determined when the FIN arrived, should be marked as consumed at the |
706 // connection level flow controller when the stream is reset. | 709 // connection level flow controller when the stream is reset. |
707 TestStream* stream = session_.CreateOutgoingDataStream(); | 710 TestStream* stream = session_.CreateOutgoingDataStream(); |
708 | 711 |
709 const QuicStreamOffset kByteOffset = 1 + kInitialFlowControlWindowForTest / 2; | 712 const QuicStreamOffset kByteOffset = 1 + kInitialFlowControlWindowForTest / 2; |
710 QuicStreamFrame frame(stream->id(), true, kByteOffset, IOVector()); | 713 QuicStreamFrame frame(stream->id(), true, kByteOffset, IOVector()); |
711 vector<QuicStreamFrame> frames; | 714 vector<QuicStreamFrame> frames; |
(...skipping 20 matching lines...) Expand all Loading... |
732 | 735 |
733 TEST_P(QuicSessionTest, ConnectionFlowControlAccountingFinAfterRst) { | 736 TEST_P(QuicSessionTest, ConnectionFlowControlAccountingFinAfterRst) { |
734 // Test that when we RST the stream (and tear down stream state), and then | 737 // Test that when we RST the stream (and tear down stream state), and then |
735 // receive a FIN from the peer, we correctly adjust our connection level flow | 738 // receive a FIN from the peer, we correctly adjust our connection level flow |
736 // control receive window. | 739 // control receive window. |
737 if (version() < QUIC_VERSION_19) { | 740 if (version() < QUIC_VERSION_19) { |
738 return; | 741 return; |
739 } | 742 } |
740 | 743 |
741 ValueRestore<bool> old_flag2(&FLAGS_enable_quic_stream_flow_control_2, true); | 744 ValueRestore<bool> old_flag2(&FLAGS_enable_quic_stream_flow_control_2, true); |
742 ValueRestore<bool> old_flag(&FLAGS_enable_quic_connection_flow_control, true); | 745 ValueRestore<bool> old_flag(&FLAGS_enable_quic_connection_flow_control_2, |
| 746 true); |
743 // Connection starts with some non-zero highest received byte offset, | 747 // Connection starts with some non-zero highest received byte offset, |
744 // due to other active streams. | 748 // due to other active streams. |
745 const uint64 kInitialConnectionBytesConsumed = 567; | 749 const uint64 kInitialConnectionBytesConsumed = 567; |
746 const uint64 kInitialConnectionHighestReceivedOffset = 1234; | 750 const uint64 kInitialConnectionHighestReceivedOffset = 1234; |
747 EXPECT_LT(kInitialConnectionBytesConsumed, | 751 EXPECT_LT(kInitialConnectionBytesConsumed, |
748 kInitialConnectionHighestReceivedOffset); | 752 kInitialConnectionHighestReceivedOffset); |
749 session_.flow_controller()->UpdateHighestReceivedOffset( | 753 session_.flow_controller()->UpdateHighestReceivedOffset( |
750 kInitialConnectionHighestReceivedOffset); | 754 kInitialConnectionHighestReceivedOffset); |
751 session_.flow_controller()->AddBytesConsumed(kInitialConnectionBytesConsumed); | 755 session_.flow_controller()->AddBytesConsumed(kInitialConnectionBytesConsumed); |
752 | 756 |
(...skipping 23 matching lines...) Expand all Loading... |
776 | 780 |
777 TEST_P(QuicSessionTest, ConnectionFlowControlAccountingRstAfterRst) { | 781 TEST_P(QuicSessionTest, ConnectionFlowControlAccountingRstAfterRst) { |
778 // Test that when we RST the stream (and tear down stream state), and then | 782 // Test that when we RST the stream (and tear down stream state), and then |
779 // receive a RST from the peer, we correctly adjust our connection level flow | 783 // receive a RST from the peer, we correctly adjust our connection level flow |
780 // control receive window. | 784 // control receive window. |
781 if (version() < QUIC_VERSION_19) { | 785 if (version() < QUIC_VERSION_19) { |
782 return; | 786 return; |
783 } | 787 } |
784 | 788 |
785 ValueRestore<bool> old_flag2(&FLAGS_enable_quic_stream_flow_control_2, true); | 789 ValueRestore<bool> old_flag2(&FLAGS_enable_quic_stream_flow_control_2, true); |
786 ValueRestore<bool> old_flag(&FLAGS_enable_quic_connection_flow_control, true); | 790 ValueRestore<bool> old_flag(&FLAGS_enable_quic_connection_flow_control_2, |
| 791 true); |
787 // Connection starts with some non-zero highest received byte offset, | 792 // Connection starts with some non-zero highest received byte offset, |
788 // due to other active streams. | 793 // due to other active streams. |
789 const uint64 kInitialConnectionBytesConsumed = 567; | 794 const uint64 kInitialConnectionBytesConsumed = 567; |
790 const uint64 kInitialConnectionHighestReceivedOffset = 1234; | 795 const uint64 kInitialConnectionHighestReceivedOffset = 1234; |
791 EXPECT_LT(kInitialConnectionBytesConsumed, | 796 EXPECT_LT(kInitialConnectionBytesConsumed, |
792 kInitialConnectionHighestReceivedOffset); | 797 kInitialConnectionHighestReceivedOffset); |
793 session_.flow_controller()->UpdateHighestReceivedOffset( | 798 session_.flow_controller()->UpdateHighestReceivedOffset( |
794 kInitialConnectionHighestReceivedOffset); | 799 kInitialConnectionHighestReceivedOffset); |
795 session_.flow_controller()->AddBytesConsumed(kInitialConnectionBytesConsumed); | 800 session_.flow_controller()->AddBytesConsumed(kInitialConnectionBytesConsumed); |
796 | 801 |
(...skipping 15 matching lines...) Expand all Loading... |
812 session_.flow_controller()->highest_received_byte_offset()); | 817 session_.flow_controller()->highest_received_byte_offset()); |
813 } | 818 } |
814 | 819 |
815 TEST_P(QuicSessionTest, FlowControlWithInvalidFinalOffset) { | 820 TEST_P(QuicSessionTest, FlowControlWithInvalidFinalOffset) { |
816 // Test that if we receive a stream RST with a highest byte offset that | 821 // Test that if we receive a stream RST with a highest byte offset that |
817 // violates flow control, that we close the connection. | 822 // violates flow control, that we close the connection. |
818 if (version() < QUIC_VERSION_17) { | 823 if (version() < QUIC_VERSION_17) { |
819 return; | 824 return; |
820 } | 825 } |
821 ValueRestore<bool> old_flag2(&FLAGS_enable_quic_stream_flow_control_2, true); | 826 ValueRestore<bool> old_flag2(&FLAGS_enable_quic_stream_flow_control_2, true); |
822 ValueRestore<bool> old_flag(&FLAGS_enable_quic_connection_flow_control, true); | 827 ValueRestore<bool> old_flag(&FLAGS_enable_quic_connection_flow_control_2, |
| 828 true); |
823 | 829 |
824 const uint64 kLargeOffset = kInitialFlowControlWindowForTest + 1; | 830 const uint64 kLargeOffset = kInitialFlowControlWindowForTest + 1; |
825 EXPECT_CALL(*connection_, | 831 EXPECT_CALL(*connection_, |
826 SendConnectionClose(QUIC_FLOW_CONTROL_RECEIVED_TOO_MUCH_DATA)) | 832 SendConnectionClose(QUIC_FLOW_CONTROL_RECEIVED_TOO_MUCH_DATA)) |
827 .Times(2); | 833 .Times(2); |
828 | 834 |
829 // Check that stream frame + FIN results in connection close. | 835 // Check that stream frame + FIN results in connection close. |
830 TestStream* stream = session_.CreateOutgoingDataStream(); | 836 TestStream* stream = session_.CreateOutgoingDataStream(); |
831 stream->Reset(QUIC_STREAM_CANCELLED); | 837 stream->Reset(QUIC_STREAM_CANCELLED); |
832 QuicStreamFrame frame(stream->id(), true, kLargeOffset, IOVector()); | 838 QuicStreamFrame frame(stream->id(), true, kLargeOffset, IOVector()); |
833 vector<QuicStreamFrame> frames; | 839 vector<QuicStreamFrame> frames; |
834 frames.push_back(frame); | 840 frames.push_back(frame); |
835 session_.OnStreamFrames(frames); | 841 session_.OnStreamFrames(frames); |
836 | 842 |
837 // Check that RST results in connection close. | 843 // Check that RST results in connection close. |
838 QuicRstStreamFrame rst_frame(stream->id(), QUIC_STREAM_CANCELLED, | 844 QuicRstStreamFrame rst_frame(stream->id(), QUIC_STREAM_CANCELLED, |
839 kLargeOffset); | 845 kLargeOffset); |
840 session_.OnRstStream(rst_frame); | 846 session_.OnRstStream(rst_frame); |
841 } | 847 } |
842 | 848 |
843 TEST_P(QuicSessionTest, VersionNegotiationDisablesFlowControl) { | 849 TEST_P(QuicSessionTest, VersionNegotiationDisablesFlowControl) { |
844 if (version() < QUIC_VERSION_19) { | 850 if (version() < QUIC_VERSION_19) { |
845 return; | 851 return; |
846 } | 852 } |
847 | 853 |
848 ValueRestore<bool> old_flag2(&FLAGS_enable_quic_stream_flow_control_2, true); | 854 ValueRestore<bool> old_flag2(&FLAGS_enable_quic_stream_flow_control_2, true); |
849 ValueRestore<bool> old_flag(&FLAGS_enable_quic_connection_flow_control, true); | 855 ValueRestore<bool> old_flag(&FLAGS_enable_quic_connection_flow_control_2, |
| 856 true); |
850 // Test that after successful version negotiation, flow control is disabled | 857 // Test that after successful version negotiation, flow control is disabled |
851 // appropriately at both the connection and stream level. | 858 // appropriately at both the connection and stream level. |
852 | 859 |
853 // Initially both stream and connection flow control are enabled. | 860 // Initially both stream and connection flow control are enabled. |
854 TestStream* stream = session_.CreateOutgoingDataStream(); | 861 TestStream* stream = session_.CreateOutgoingDataStream(); |
855 EXPECT_TRUE(stream->flow_controller()->IsEnabled()); | 862 EXPECT_TRUE(stream->flow_controller()->IsEnabled()); |
856 EXPECT_TRUE(session_.flow_controller()->IsEnabled()); | 863 EXPECT_TRUE(session_.flow_controller()->IsEnabled()); |
857 | 864 |
858 // Version 17 implies that stream flow control is enabled, but connection | 865 // Version 17 implies that stream flow control is enabled, but connection |
859 // level is disabled. | 866 // level is disabled. |
860 session_.OnSuccessfulVersionNegotiation(QUIC_VERSION_17); | 867 session_.OnSuccessfulVersionNegotiation(QUIC_VERSION_17); |
861 EXPECT_FALSE(session_.flow_controller()->IsEnabled()); | 868 EXPECT_FALSE(session_.flow_controller()->IsEnabled()); |
862 EXPECT_TRUE(stream->flow_controller()->IsEnabled()); | 869 EXPECT_TRUE(stream->flow_controller()->IsEnabled()); |
863 | 870 |
864 // Version 16 means all flow control is disabled. | 871 // Version 16 means all flow control is disabled. |
865 session_.OnSuccessfulVersionNegotiation(QUIC_VERSION_16); | 872 session_.OnSuccessfulVersionNegotiation(QUIC_VERSION_16); |
866 EXPECT_FALSE(session_.flow_controller()->IsEnabled()); | 873 EXPECT_FALSE(session_.flow_controller()->IsEnabled()); |
867 EXPECT_FALSE(stream->flow_controller()->IsEnabled()); | 874 EXPECT_FALSE(stream->flow_controller()->IsEnabled()); |
868 } | 875 } |
869 | 876 |
870 } // namespace | 877 } // namespace |
871 } // namespace test | 878 } // namespace test |
872 } // namespace net | 879 } // namespace net |
OLD | NEW |