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 616 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
627 QuicRstStreamFrame rst2(kLargeInvalidStreamId, QUIC_STREAM_NO_ERROR, 0); | 627 QuicRstStreamFrame rst2(kLargeInvalidStreamId, QUIC_STREAM_NO_ERROR, 0); |
628 session_.OnRstStream(rst2); | 628 session_.OnRstStream(rst2); |
629 } | 629 } |
630 | 630 |
631 TEST_P(QuicSessionTest, HandshakeUnblocksFlowControlBlockedStream) { | 631 TEST_P(QuicSessionTest, HandshakeUnblocksFlowControlBlockedStream) { |
632 // Test that if a stream is flow control blocked, then on receipt of the SHLO | 632 // Test that if a stream is flow control blocked, then on receipt of the SHLO |
633 // containing a suitable send window offset, the stream becomes unblocked. | 633 // containing a suitable send window offset, the stream becomes unblocked. |
634 if (version() < QUIC_VERSION_17) { | 634 if (version() < QUIC_VERSION_17) { |
635 return; | 635 return; |
636 } | 636 } |
637 ValueRestore<bool> old_flag(&FLAGS_enable_quic_stream_flow_control_2, true); | |
638 | 637 |
639 // Ensure that Writev consumes all the data it is given (simulate no socket | 638 // Ensure that Writev consumes all the data it is given (simulate no socket |
640 // blocking). | 639 // blocking). |
641 session_.set_writev_consumes_all_data(true); | 640 session_.set_writev_consumes_all_data(true); |
642 | 641 |
643 // Create a stream, and send enough data to make it flow control blocked. | 642 // Create a stream, and send enough data to make it flow control blocked. |
644 TestStream* stream2 = session_.CreateOutgoingDataStream(); | 643 TestStream* stream2 = session_.CreateOutgoingDataStream(); |
645 string body(kDefaultFlowControlSendWindow, '.'); | 644 string body(kDefaultFlowControlSendWindow, '.'); |
646 EXPECT_FALSE(stream2->flow_controller()->IsBlocked()); | 645 EXPECT_FALSE(stream2->flow_controller()->IsBlocked()); |
647 stream2->SendBody(body, false); | 646 stream2->SendBody(body, false); |
648 EXPECT_TRUE(stream2->flow_controller()->IsBlocked()); | 647 EXPECT_TRUE(stream2->flow_controller()->IsBlocked()); |
649 | 648 |
650 // Now complete the crypto handshake, resulting in an increased flow control | 649 // Now complete the crypto handshake, resulting in an increased flow control |
651 // send window. | 650 // send window. |
652 CryptoHandshakeMessage msg; | 651 CryptoHandshakeMessage msg; |
653 session_.GetCryptoStream()->OnHandshakeMessage(msg); | 652 session_.GetCryptoStream()->OnHandshakeMessage(msg); |
654 | 653 |
655 // Stream is now unblocked. | 654 // Stream is now unblocked. |
656 EXPECT_FALSE(stream2->flow_controller()->IsBlocked()); | 655 EXPECT_FALSE(stream2->flow_controller()->IsBlocked()); |
657 } | 656 } |
658 | 657 |
659 TEST_P(QuicSessionTest, InvalidFlowControlWindowInHandshake) { | 658 TEST_P(QuicSessionTest, InvalidFlowControlWindowInHandshake) { |
660 // TODO(rjshade): Remove this test when removing QUIC_VERSION_19. | 659 // TODO(rjshade): Remove this test when removing QUIC_VERSION_19. |
661 // Test that receipt of an invalid (< default) flow control window from | 660 // Test that receipt of an invalid (< default) flow control window from |
662 // the peer results in the connection being torn down. | 661 // the peer results in the connection being torn down. |
663 if (version() <= QUIC_VERSION_16 || version() > QUIC_VERSION_19) { | 662 if (version() <= QUIC_VERSION_16 || version() > QUIC_VERSION_19) { |
664 return; | 663 return; |
665 } | 664 } |
666 ValueRestore<bool> old_flag(&FLAGS_enable_quic_stream_flow_control_2, true); | |
667 | 665 |
668 uint32 kInvalidWindow = kDefaultFlowControlSendWindow - 1; | 666 uint32 kInvalidWindow = kDefaultFlowControlSendWindow - 1; |
669 QuicConfigPeer::SetReceivedInitialFlowControlWindow(session_.config(), | 667 QuicConfigPeer::SetReceivedInitialFlowControlWindow(session_.config(), |
670 kInvalidWindow); | 668 kInvalidWindow); |
671 | 669 |
672 EXPECT_CALL(*connection_, | 670 EXPECT_CALL(*connection_, |
673 SendConnectionClose(QUIC_FLOW_CONTROL_INVALID_WINDOW)).Times(2); | 671 SendConnectionClose(QUIC_FLOW_CONTROL_INVALID_WINDOW)).Times(2); |
674 session_.OnConfigNegotiated(); | 672 session_.OnConfigNegotiated(); |
675 } | 673 } |
676 | 674 |
677 TEST_P(QuicSessionTest, InvalidStreamFlowControlWindowInHandshake) { | 675 TEST_P(QuicSessionTest, InvalidStreamFlowControlWindowInHandshake) { |
678 // Test that receipt of an invalid (< default) stream flow control window from | 676 // Test that receipt of an invalid (< default) stream flow control window from |
679 // the peer results in the connection being torn down. | 677 // the peer results in the connection being torn down. |
680 if (version() <= QUIC_VERSION_19) { | 678 if (version() <= QUIC_VERSION_19) { |
681 return; | 679 return; |
682 } | 680 } |
683 ValueRestore<bool> old_flag(&FLAGS_enable_quic_stream_flow_control_2, true); | |
684 | 681 |
685 uint32 kInvalidWindow = kDefaultFlowControlSendWindow - 1; | 682 uint32 kInvalidWindow = kDefaultFlowControlSendWindow - 1; |
686 QuicConfigPeer::SetReceivedInitialStreamFlowControlWindow(session_.config(), | 683 QuicConfigPeer::SetReceivedInitialStreamFlowControlWindow(session_.config(), |
687 kInvalidWindow); | 684 kInvalidWindow); |
688 | 685 |
689 EXPECT_CALL(*connection_, | 686 EXPECT_CALL(*connection_, |
690 SendConnectionClose(QUIC_FLOW_CONTROL_INVALID_WINDOW)); | 687 SendConnectionClose(QUIC_FLOW_CONTROL_INVALID_WINDOW)); |
691 session_.OnConfigNegotiated(); | 688 session_.OnConfigNegotiated(); |
692 } | 689 } |
693 | 690 |
694 TEST_P(QuicSessionTest, InvalidSessionFlowControlWindowInHandshake) { | 691 TEST_P(QuicSessionTest, InvalidSessionFlowControlWindowInHandshake) { |
695 // Test that receipt of an invalid (< default) session flow control window | 692 // Test that receipt of an invalid (< default) session flow control window |
696 // from the peer results in the connection being torn down. | 693 // from the peer results in the connection being torn down. |
697 if (version() <= QUIC_VERSION_19) { | 694 if (version() <= QUIC_VERSION_19) { |
698 return; | 695 return; |
699 } | 696 } |
700 ValueRestore<bool> old_flag(&FLAGS_enable_quic_stream_flow_control_2, true); | |
701 | 697 |
702 uint32 kInvalidWindow = kDefaultFlowControlSendWindow - 1; | 698 uint32 kInvalidWindow = kDefaultFlowControlSendWindow - 1; |
703 QuicConfigPeer::SetReceivedInitialSessionFlowControlWindow(session_.config(), | 699 QuicConfigPeer::SetReceivedInitialSessionFlowControlWindow(session_.config(), |
704 kInvalidWindow); | 700 kInvalidWindow); |
705 | 701 |
706 EXPECT_CALL(*connection_, | 702 EXPECT_CALL(*connection_, |
707 SendConnectionClose(QUIC_FLOW_CONTROL_INVALID_WINDOW)); | 703 SendConnectionClose(QUIC_FLOW_CONTROL_INVALID_WINDOW)); |
708 session_.OnConfigNegotiated(); | 704 session_.OnConfigNegotiated(); |
709 } | 705 } |
710 | 706 |
711 TEST_P(QuicSessionTest, ConnectionFlowControlAccountingRstOutOfOrder) { | 707 TEST_P(QuicSessionTest, ConnectionFlowControlAccountingRstOutOfOrder) { |
712 if (version() < QUIC_VERSION_19) { | 708 if (version() < QUIC_VERSION_19) { |
713 return; | 709 return; |
714 } | 710 } |
715 | 711 |
716 ValueRestore<bool> old_flag2(&FLAGS_enable_quic_stream_flow_control_2, true); | |
717 ValueRestore<bool> old_flag(&FLAGS_enable_quic_connection_flow_control_2, | 712 ValueRestore<bool> old_flag(&FLAGS_enable_quic_connection_flow_control_2, |
718 true); | 713 true); |
719 // Test that when we receive an out of order stream RST we correctly adjust | 714 // Test that when we receive an out of order stream RST we correctly adjust |
720 // our connection level flow control receive window. | 715 // our connection level flow control receive window. |
721 // On close, the stream should mark as consumed all bytes between the highest | 716 // On close, the stream should mark as consumed all bytes between the highest |
722 // byte consumed so far and the final byte offset from the RST frame. | 717 // byte consumed so far and the final byte offset from the RST frame. |
723 TestStream* stream = session_.CreateOutgoingDataStream(); | 718 TestStream* stream = session_.CreateOutgoingDataStream(); |
724 | 719 |
725 const QuicStreamOffset kByteOffset = | 720 const QuicStreamOffset kByteOffset = |
726 1 + kInitialSessionFlowControlWindowForTest / 2; | 721 1 + kInitialSessionFlowControlWindowForTest / 2; |
(...skipping 10 matching lines...) Expand all Loading... |
737 session_.OnRstStream(rst_frame); | 732 session_.OnRstStream(rst_frame); |
738 session_.PostProcessAfterData(); | 733 session_.PostProcessAfterData(); |
739 EXPECT_EQ(kByteOffset, session_.flow_controller()->bytes_consumed()); | 734 EXPECT_EQ(kByteOffset, session_.flow_controller()->bytes_consumed()); |
740 } | 735 } |
741 | 736 |
742 TEST_P(QuicSessionTest, ConnectionFlowControlAccountingFinAndLocalReset) { | 737 TEST_P(QuicSessionTest, ConnectionFlowControlAccountingFinAndLocalReset) { |
743 if (version() < QUIC_VERSION_19) { | 738 if (version() < QUIC_VERSION_19) { |
744 return; | 739 return; |
745 } | 740 } |
746 | 741 |
747 ValueRestore<bool> old_flag2(&FLAGS_enable_quic_stream_flow_control_2, true); | |
748 ValueRestore<bool> old_flag(&FLAGS_enable_quic_connection_flow_control_2, | 742 ValueRestore<bool> old_flag(&FLAGS_enable_quic_connection_flow_control_2, |
749 true); | 743 true); |
750 // Test the situation where we receive a FIN on a stream, and before we fully | 744 // Test the situation where we receive a FIN on a stream, and before we fully |
751 // consume all the data from the sequencer buffer we locally RST the stream. | 745 // consume all the data from the sequencer buffer we locally RST the stream. |
752 // The bytes between highest consumed byte, and the final byte offset that we | 746 // The bytes between highest consumed byte, and the final byte offset that we |
753 // determined when the FIN arrived, should be marked as consumed at the | 747 // determined when the FIN arrived, should be marked as consumed at the |
754 // connection level flow controller when the stream is reset. | 748 // connection level flow controller when the stream is reset. |
755 TestStream* stream = session_.CreateOutgoingDataStream(); | 749 TestStream* stream = session_.CreateOutgoingDataStream(); |
756 | 750 |
757 const QuicStreamOffset kByteOffset = | 751 const QuicStreamOffset kByteOffset = |
(...skipping 28 matching lines...) Expand all Loading... |
786 } | 780 } |
787 | 781 |
788 TEST_P(QuicSessionTest, ConnectionFlowControlAccountingFinAfterRst) { | 782 TEST_P(QuicSessionTest, ConnectionFlowControlAccountingFinAfterRst) { |
789 // Test that when we RST the stream (and tear down stream state), and then | 783 // Test that when we RST the stream (and tear down stream state), and then |
790 // receive a FIN from the peer, we correctly adjust our connection level flow | 784 // receive a FIN from the peer, we correctly adjust our connection level flow |
791 // control receive window. | 785 // control receive window. |
792 if (version() < QUIC_VERSION_19) { | 786 if (version() < QUIC_VERSION_19) { |
793 return; | 787 return; |
794 } | 788 } |
795 | 789 |
796 ValueRestore<bool> old_flag2(&FLAGS_enable_quic_stream_flow_control_2, true); | |
797 ValueRestore<bool> old_flag(&FLAGS_enable_quic_connection_flow_control_2, | 790 ValueRestore<bool> old_flag(&FLAGS_enable_quic_connection_flow_control_2, |
798 true); | 791 true); |
799 // Connection starts with some non-zero highest received byte offset, | 792 // Connection starts with some non-zero highest received byte offset, |
800 // due to other active streams. | 793 // due to other active streams. |
801 const uint64 kInitialConnectionBytesConsumed = 567; | 794 const uint64 kInitialConnectionBytesConsumed = 567; |
802 const uint64 kInitialConnectionHighestReceivedOffset = 1234; | 795 const uint64 kInitialConnectionHighestReceivedOffset = 1234; |
803 EXPECT_LT(kInitialConnectionBytesConsumed, | 796 EXPECT_LT(kInitialConnectionBytesConsumed, |
804 kInitialConnectionHighestReceivedOffset); | 797 kInitialConnectionHighestReceivedOffset); |
805 session_.flow_controller()->UpdateHighestReceivedOffset( | 798 session_.flow_controller()->UpdateHighestReceivedOffset( |
806 kInitialConnectionHighestReceivedOffset); | 799 kInitialConnectionHighestReceivedOffset); |
(...skipping 24 matching lines...) Expand all Loading... |
831 } | 824 } |
832 | 825 |
833 TEST_P(QuicSessionTest, ConnectionFlowControlAccountingRstAfterRst) { | 826 TEST_P(QuicSessionTest, ConnectionFlowControlAccountingRstAfterRst) { |
834 // Test that when we RST the stream (and tear down stream state), and then | 827 // Test that when we RST the stream (and tear down stream state), and then |
835 // receive a RST from the peer, we correctly adjust our connection level flow | 828 // receive a RST from the peer, we correctly adjust our connection level flow |
836 // control receive window. | 829 // control receive window. |
837 if (version() < QUIC_VERSION_19) { | 830 if (version() < QUIC_VERSION_19) { |
838 return; | 831 return; |
839 } | 832 } |
840 | 833 |
841 ValueRestore<bool> old_flag2(&FLAGS_enable_quic_stream_flow_control_2, true); | |
842 ValueRestore<bool> old_flag(&FLAGS_enable_quic_connection_flow_control_2, | 834 ValueRestore<bool> old_flag(&FLAGS_enable_quic_connection_flow_control_2, |
843 true); | 835 true); |
844 // Connection starts with some non-zero highest received byte offset, | 836 // Connection starts with some non-zero highest received byte offset, |
845 // due to other active streams. | 837 // due to other active streams. |
846 const uint64 kInitialConnectionBytesConsumed = 567; | 838 const uint64 kInitialConnectionBytesConsumed = 567; |
847 const uint64 kInitialConnectionHighestReceivedOffset = 1234; | 839 const uint64 kInitialConnectionHighestReceivedOffset = 1234; |
848 EXPECT_LT(kInitialConnectionBytesConsumed, | 840 EXPECT_LT(kInitialConnectionBytesConsumed, |
849 kInitialConnectionHighestReceivedOffset); | 841 kInitialConnectionHighestReceivedOffset); |
850 session_.flow_controller()->UpdateHighestReceivedOffset( | 842 session_.flow_controller()->UpdateHighestReceivedOffset( |
851 kInitialConnectionHighestReceivedOffset); | 843 kInitialConnectionHighestReceivedOffset); |
(...skipping 16 matching lines...) Expand all Loading... |
868 EXPECT_EQ(kInitialConnectionHighestReceivedOffset + kByteOffset, | 860 EXPECT_EQ(kInitialConnectionHighestReceivedOffset + kByteOffset, |
869 session_.flow_controller()->highest_received_byte_offset()); | 861 session_.flow_controller()->highest_received_byte_offset()); |
870 } | 862 } |
871 | 863 |
872 TEST_P(QuicSessionTest, FlowControlWithInvalidFinalOffset) { | 864 TEST_P(QuicSessionTest, FlowControlWithInvalidFinalOffset) { |
873 // Test that if we receive a stream RST with a highest byte offset that | 865 // Test that if we receive a stream RST with a highest byte offset that |
874 // violates flow control, that we close the connection. | 866 // violates flow control, that we close the connection. |
875 if (version() < QUIC_VERSION_17) { | 867 if (version() < QUIC_VERSION_17) { |
876 return; | 868 return; |
877 } | 869 } |
878 ValueRestore<bool> old_flag2(&FLAGS_enable_quic_stream_flow_control_2, true); | |
879 ValueRestore<bool> old_flag(&FLAGS_enable_quic_connection_flow_control_2, | 870 ValueRestore<bool> old_flag(&FLAGS_enable_quic_connection_flow_control_2, |
880 true); | 871 true); |
881 | 872 |
882 const uint64 kLargeOffset = kInitialSessionFlowControlWindowForTest + 1; | 873 const uint64 kLargeOffset = kInitialSessionFlowControlWindowForTest + 1; |
883 EXPECT_CALL(*connection_, | 874 EXPECT_CALL(*connection_, |
884 SendConnectionClose(QUIC_FLOW_CONTROL_RECEIVED_TOO_MUCH_DATA)) | 875 SendConnectionClose(QUIC_FLOW_CONTROL_RECEIVED_TOO_MUCH_DATA)) |
885 .Times(2); | 876 .Times(2); |
886 | 877 |
887 // Check that stream frame + FIN results in connection close. | 878 // Check that stream frame + FIN results in connection close. |
888 TestStream* stream = session_.CreateOutgoingDataStream(); | 879 TestStream* stream = session_.CreateOutgoingDataStream(); |
889 stream->Reset(QUIC_STREAM_CANCELLED); | 880 stream->Reset(QUIC_STREAM_CANCELLED); |
890 QuicStreamFrame frame(stream->id(), true, kLargeOffset, IOVector()); | 881 QuicStreamFrame frame(stream->id(), true, kLargeOffset, IOVector()); |
891 vector<QuicStreamFrame> frames; | 882 vector<QuicStreamFrame> frames; |
892 frames.push_back(frame); | 883 frames.push_back(frame); |
893 session_.OnStreamFrames(frames); | 884 session_.OnStreamFrames(frames); |
894 | 885 |
895 // Check that RST results in connection close. | 886 // Check that RST results in connection close. |
896 QuicRstStreamFrame rst_frame(stream->id(), QUIC_STREAM_CANCELLED, | 887 QuicRstStreamFrame rst_frame(stream->id(), QUIC_STREAM_CANCELLED, |
897 kLargeOffset); | 888 kLargeOffset); |
898 session_.OnRstStream(rst_frame); | 889 session_.OnRstStream(rst_frame); |
899 } | 890 } |
900 | 891 |
901 TEST_P(QuicSessionTest, VersionNegotiationDisablesFlowControl) { | 892 TEST_P(QuicSessionTest, VersionNegotiationDisablesFlowControl) { |
902 if (version() < QUIC_VERSION_19) { | 893 if (version() < QUIC_VERSION_19) { |
903 return; | 894 return; |
904 } | 895 } |
905 | 896 |
906 ValueRestore<bool> old_flag2(&FLAGS_enable_quic_stream_flow_control_2, true); | |
907 ValueRestore<bool> old_flag(&FLAGS_enable_quic_connection_flow_control_2, | 897 ValueRestore<bool> old_flag(&FLAGS_enable_quic_connection_flow_control_2, |
908 true); | 898 true); |
909 // Test that after successful version negotiation, flow control is disabled | 899 // Test that after successful version negotiation, flow control is disabled |
910 // appropriately at both the connection and stream level. | 900 // appropriately at both the connection and stream level. |
911 | 901 |
912 // Initially both stream and connection flow control are enabled. | 902 // Initially both stream and connection flow control are enabled. |
913 TestStream* stream = session_.CreateOutgoingDataStream(); | 903 TestStream* stream = session_.CreateOutgoingDataStream(); |
914 EXPECT_TRUE(stream->flow_controller()->IsEnabled()); | 904 EXPECT_TRUE(stream->flow_controller()->IsEnabled()); |
915 EXPECT_TRUE(session_.flow_controller()->IsEnabled()); | 905 EXPECT_TRUE(session_.flow_controller()->IsEnabled()); |
916 | 906 |
917 // Version 17 implies that stream flow control is enabled, but connection | 907 // Version 17 implies that stream flow control is enabled, but connection |
918 // level is disabled. | 908 // level is disabled. |
919 session_.OnSuccessfulVersionNegotiation(QUIC_VERSION_17); | 909 session_.OnSuccessfulVersionNegotiation(QUIC_VERSION_17); |
920 EXPECT_FALSE(session_.flow_controller()->IsEnabled()); | 910 EXPECT_FALSE(session_.flow_controller()->IsEnabled()); |
921 EXPECT_TRUE(stream->flow_controller()->IsEnabled()); | 911 EXPECT_TRUE(stream->flow_controller()->IsEnabled()); |
922 | 912 |
923 // Version 16 means all flow control is disabled. | 913 // Version 16 means all flow control is disabled. |
924 session_.OnSuccessfulVersionNegotiation(QUIC_VERSION_16); | 914 session_.OnSuccessfulVersionNegotiation(QUIC_VERSION_16); |
925 EXPECT_FALSE(session_.flow_controller()->IsEnabled()); | 915 EXPECT_FALSE(session_.flow_controller()->IsEnabled()); |
926 EXPECT_FALSE(stream->flow_controller()->IsEnabled()); | 916 EXPECT_FALSE(stream->flow_controller()->IsEnabled()); |
927 } | 917 } |
928 | 918 |
929 } // namespace | 919 } // namespace |
930 } // namespace test | 920 } // namespace test |
931 } // namespace net | 921 } // namespace net |
OLD | NEW |