QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 1 | // Copyright (c) 2018 The Chromium Authors. All rights reserved. |
| 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | #include "net/third_party/quiche/src/quic/core/quic_stream_id_manager.h" |
| 5 | |
| 6 | #include <cstdint> |
vasilvv | 872e7a3 | 2019-03-12 16:42:44 -0700 | [diff] [blame] | 7 | #include <string> |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 8 | #include <utility> |
| 9 | |
renjietang | 315428e | 2020-01-27 10:18:12 -0800 | [diff] [blame] | 10 | #include "net/third_party/quiche/src/quic/core/quic_constants.h" |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 11 | #include "net/third_party/quiche/src/quic/core/quic_utils.h" |
dschinazi | 38cc1ee | 2020-02-28 14:33:58 -0800 | [diff] [blame] | 12 | #include "net/third_party/quiche/src/quic/core/quic_versions.h" |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 13 | #include "net/third_party/quiche/src/quic/platform/api/quic_expect_bug.h" |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 14 | #include "net/third_party/quiche/src/quic/platform/api/quic_test.h" |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 15 | #include "net/third_party/quiche/src/quic/test_tools/quic_stream_id_manager_peer.h" |
dmcardle | cf0bfcf | 2019-12-13 08:08:21 -0800 | [diff] [blame] | 16 | #include "net/third_party/quiche/src/common/platform/api/quiche_str_cat.h" |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 17 | |
| 18 | using testing::_; |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 19 | using testing::StrictMock; |
| 20 | |
| 21 | namespace quic { |
| 22 | namespace test { |
| 23 | namespace { |
| 24 | |
rch | a8b56e4 | 2019-09-20 10:41:48 -0700 | [diff] [blame] | 25 | class MockDelegate : public QuicStreamIdManager::DelegateInterface { |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 26 | public: |
rch | a8b56e4 | 2019-09-20 10:41:48 -0700 | [diff] [blame] | 27 | MOCK_METHOD1(OnCanCreateNewOutgoingStream, void(bool unidirectional)); |
renjietang | ff4b2b6 | 2020-02-12 16:52:32 -0800 | [diff] [blame] | 28 | MOCK_METHOD2(OnStreamIdManagerError, |
rch | a8b56e4 | 2019-09-20 10:41:48 -0700 | [diff] [blame] | 29 | void(QuicErrorCode error_code, std::string error_details)); |
| 30 | MOCK_METHOD2(SendMaxStreams, |
| 31 | void(QuicStreamCount stream_count, bool unidirectional)); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 32 | }; |
| 33 | |
rch | 9301d3c | 2019-09-20 14:30:48 -0700 | [diff] [blame] | 34 | struct TestParams { |
dschinazi | 38cc1ee | 2020-02-28 14:33:58 -0800 | [diff] [blame] | 35 | TestParams(ParsedQuicVersion version, |
| 36 | Perspective perspective, |
| 37 | bool is_unidirectional) |
| 38 | : version(version), |
| 39 | perspective(perspective), |
| 40 | is_unidirectional(is_unidirectional) {} |
rch | 9301d3c | 2019-09-20 14:30:48 -0700 | [diff] [blame] | 41 | |
dschinazi | 38cc1ee | 2020-02-28 14:33:58 -0800 | [diff] [blame] | 42 | ParsedQuicVersion version; |
rch | 9301d3c | 2019-09-20 14:30:48 -0700 | [diff] [blame] | 43 | Perspective perspective; |
| 44 | bool is_unidirectional; |
| 45 | }; |
| 46 | |
| 47 | // Used by ::testing::PrintToStringParamName(). |
| 48 | std::string PrintToString(const TestParams& p) { |
dmcardle | cf0bfcf | 2019-12-13 08:08:21 -0800 | [diff] [blame] | 49 | return quiche::QuicheStrCat( |
dschinazi | 38cc1ee | 2020-02-28 14:33:58 -0800 | [diff] [blame] | 50 | ParsedQuicVersionToString(p.version), "_", |
rch | 9301d3c | 2019-09-20 14:30:48 -0700 | [diff] [blame] | 51 | (p.perspective == Perspective::IS_CLIENT ? "Client" : "Server"), |
| 52 | (p.is_unidirectional ? "Unidirectional" : "Bidirectional")); |
| 53 | } |
| 54 | |
| 55 | std::vector<TestParams> GetTestParams() { |
| 56 | std::vector<TestParams> params; |
dschinazi | 38cc1ee | 2020-02-28 14:33:58 -0800 | [diff] [blame] | 57 | for (const ParsedQuicVersion& version : AllSupportedVersions()) { |
| 58 | if (!version.HasIetfQuicFrames()) { |
| 59 | continue; |
| 60 | } |
| 61 | for (Perspective perspective : |
| 62 | {Perspective::IS_CLIENT, Perspective::IS_SERVER}) { |
| 63 | for (bool is_unidirectional : {true, false}) { |
| 64 | params.push_back(TestParams(version, perspective, is_unidirectional)); |
| 65 | } |
rch | 9301d3c | 2019-09-20 14:30:48 -0700 | [diff] [blame] | 66 | } |
| 67 | } |
| 68 | return params; |
| 69 | } |
| 70 | |
| 71 | class QuicStreamIdManagerTest : public QuicTestWithParam<TestParams> { |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 72 | protected: |
rch | 9301d3c | 2019-09-20 14:30:48 -0700 | [diff] [blame] | 73 | QuicStreamIdManagerTest() |
rch | a8b56e4 | 2019-09-20 10:41:48 -0700 | [diff] [blame] | 74 | : stream_id_manager_(&delegate_, |
rch | 9301d3c | 2019-09-20 14:30:48 -0700 | [diff] [blame] | 75 | IsUnidirectional(), |
| 76 | perspective(), |
| 77 | transport_version(), |
renjietang | 315428e | 2020-01-27 10:18:12 -0800 | [diff] [blame] | 78 | 0, |
rch | 9301d3c | 2019-09-20 14:30:48 -0700 | [diff] [blame] | 79 | kDefaultMaxStreamsPerConnection) { |
| 80 | DCHECK(VersionHasIetfQuicFrames(transport_version())); |
| 81 | } |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 82 | |
dschinazi | 38cc1ee | 2020-02-28 14:33:58 -0800 | [diff] [blame] | 83 | QuicTransportVersion transport_version() const { |
| 84 | return GetParam().version.transport_version; |
| 85 | } |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 86 | |
rch | 9301d3c | 2019-09-20 14:30:48 -0700 | [diff] [blame] | 87 | // Returns the stream ID for the Nth incoming stream (created by the peer) |
| 88 | // of the corresponding directionality of this manager. |
| 89 | QuicStreamId GetNthIncomingStreamId(int n) { |
| 90 | return kV99StreamIdIncrement * n + |
| 91 | (IsUnidirectional() |
| 92 | ? QuicUtils::GetFirstUnidirectionalStreamId( |
| 93 | transport_version(), |
| 94 | QuicUtils::InvertPerspective(perspective())) |
| 95 | : QuicUtils::GetFirstBidirectionalStreamId( |
| 96 | transport_version(), |
| 97 | QuicUtils::InvertPerspective(perspective()))); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 98 | } |
| 99 | |
rch | 9301d3c | 2019-09-20 14:30:48 -0700 | [diff] [blame] | 100 | bool IsUnidirectional() { return GetParam().is_unidirectional; } |
| 101 | Perspective perspective() { return GetParam().perspective; } |
fkastenholz | 3c4eabf | 2019-04-22 07:49:59 -0700 | [diff] [blame] | 102 | |
rch | a8b56e4 | 2019-09-20 10:41:48 -0700 | [diff] [blame] | 103 | StrictMock<MockDelegate> delegate_; |
| 104 | QuicStreamIdManager stream_id_manager_; |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 105 | }; |
| 106 | |
dschinazi | 142051a | 2019-09-18 18:17:29 -0700 | [diff] [blame] | 107 | INSTANTIATE_TEST_SUITE_P(Tests, |
rch | 9301d3c | 2019-09-20 14:30:48 -0700 | [diff] [blame] | 108 | QuicStreamIdManagerTest, |
| 109 | ::testing::ValuesIn(GetTestParams()), |
dschinazi | 142051a | 2019-09-18 18:17:29 -0700 | [diff] [blame] | 110 | ::testing::PrintToStringParamName()); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 111 | |
rch | 9301d3c | 2019-09-20 14:30:48 -0700 | [diff] [blame] | 112 | TEST_P(QuicStreamIdManagerTest, Initialization) { |
renjietang | 315428e | 2020-01-27 10:18:12 -0800 | [diff] [blame] | 113 | EXPECT_EQ(0u, stream_id_manager_.outgoing_max_streams()); |
fkastenholz | 3c4eabf | 2019-04-22 07:49:59 -0700 | [diff] [blame] | 114 | |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 115 | EXPECT_EQ(kDefaultMaxStreamsPerConnection, |
rch | a8b56e4 | 2019-09-20 10:41:48 -0700 | [diff] [blame] | 116 | stream_id_manager_.incoming_actual_max_streams()); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 117 | EXPECT_EQ(kDefaultMaxStreamsPerConnection, |
rch | a8b56e4 | 2019-09-20 10:41:48 -0700 | [diff] [blame] | 118 | stream_id_manager_.incoming_advertised_max_streams()); |
fkastenholz | 3c4eabf | 2019-04-22 07:49:59 -0700 | [diff] [blame] | 119 | EXPECT_EQ(kDefaultMaxStreamsPerConnection, |
rch | a8b56e4 | 2019-09-20 10:41:48 -0700 | [diff] [blame] | 120 | stream_id_manager_.incoming_initial_max_open_streams()); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 121 | |
| 122 | // The window for advertising updates to the MAX STREAM ID is half the number |
| 123 | // of streams allowed. |
rch | 9301d3c | 2019-09-20 14:30:48 -0700 | [diff] [blame] | 124 | EXPECT_EQ(kDefaultMaxStreamsPerConnection / 2, |
rch | a8b56e4 | 2019-09-20 10:41:48 -0700 | [diff] [blame] | 125 | stream_id_manager_.max_streams_window()); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 126 | } |
| 127 | |
| 128 | // This test checks that the stream advertisement window is set to 1 |
| 129 | // if the number of stream ids is 1. This is a special case in the code. |
rch | 9301d3c | 2019-09-20 14:30:48 -0700 | [diff] [blame] | 130 | TEST_P(QuicStreamIdManagerTest, CheckMaxStreamsWindowForSingleStream) { |
rch | a8b56e4 | 2019-09-20 10:41:48 -0700 | [diff] [blame] | 131 | stream_id_manager_.SetMaxOpenIncomingStreams(1); |
| 132 | EXPECT_EQ(1u, stream_id_manager_.incoming_initial_max_open_streams()); |
| 133 | EXPECT_EQ(1u, stream_id_manager_.incoming_actual_max_streams()); |
rch | a8b56e4 | 2019-09-20 10:41:48 -0700 | [diff] [blame] | 134 | EXPECT_EQ(1u, stream_id_manager_.max_streams_window()); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 135 | } |
| 136 | |
rch | 9301d3c | 2019-09-20 14:30:48 -0700 | [diff] [blame] | 137 | TEST_P(QuicStreamIdManagerTest, CheckMaxStreamsBadValuesOverMaxFailsOutgoing) { |
renjietang | b885a12 | 2020-03-20 08:24:16 -0700 | [diff] [blame^] | 138 | QuicStreamCount implementation_max = QuicUtils::GetMaxStreamCount(); |
fkastenholz | 3c4eabf | 2019-04-22 07:49:59 -0700 | [diff] [blame] | 139 | // Ensure that the limit is less than the implementation maximum. |
rch | a8b56e4 | 2019-09-20 10:41:48 -0700 | [diff] [blame] | 140 | EXPECT_LT(stream_id_manager_.outgoing_max_streams(), implementation_max); |
fkastenholz | 3c4eabf | 2019-04-22 07:49:59 -0700 | [diff] [blame] | 141 | |
rch | 9301d3c | 2019-09-20 14:30:48 -0700 | [diff] [blame] | 142 | EXPECT_CALL(delegate_, OnCanCreateNewOutgoingStream(IsUnidirectional())); |
rch | a8b56e4 | 2019-09-20 10:41:48 -0700 | [diff] [blame] | 143 | stream_id_manager_.SetMaxOpenOutgoingStreams(implementation_max + 1); |
fkastenholz | 3c4eabf | 2019-04-22 07:49:59 -0700 | [diff] [blame] | 144 | // Should be pegged at the max. |
rch | a8b56e4 | 2019-09-20 10:41:48 -0700 | [diff] [blame] | 145 | EXPECT_EQ(implementation_max, stream_id_manager_.outgoing_max_streams()); |
fkastenholz | 3c4eabf | 2019-04-22 07:49:59 -0700 | [diff] [blame] | 146 | } |
| 147 | |
fkastenholz | 3c4eabf | 2019-04-22 07:49:59 -0700 | [diff] [blame] | 148 | // Check the case of the stream count in a STREAMS_BLOCKED frame is less than |
| 149 | // the count most recently advertised in a MAX_STREAMS frame. This should cause |
| 150 | // a MAX_STREAMS frame with the most recently advertised count to be sent. |
rch | 9301d3c | 2019-09-20 14:30:48 -0700 | [diff] [blame] | 151 | TEST_P(QuicStreamIdManagerTest, ProcessStreamsBlockedOk) { |
fkastenholz | 3c4eabf | 2019-04-22 07:49:59 -0700 | [diff] [blame] | 152 | QuicStreamCount stream_count = |
rch | a8b56e4 | 2019-09-20 10:41:48 -0700 | [diff] [blame] | 153 | stream_id_manager_.incoming_initial_max_open_streams(); |
rch | 9301d3c | 2019-09-20 14:30:48 -0700 | [diff] [blame] | 154 | QuicStreamsBlockedFrame frame(0, stream_count - 1, IsUnidirectional()); |
| 155 | EXPECT_CALL(delegate_, SendMaxStreams(stream_count, IsUnidirectional())); |
rch | a8b56e4 | 2019-09-20 10:41:48 -0700 | [diff] [blame] | 156 | stream_id_manager_.OnStreamsBlockedFrame(frame); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 157 | } |
| 158 | |
fkastenholz | 3c4eabf | 2019-04-22 07:49:59 -0700 | [diff] [blame] | 159 | // Check the case of the stream count in a STREAMS_BLOCKED frame is equal to the |
| 160 | // count most recently advertised in a MAX_STREAMS frame. No MAX_STREAMS |
| 161 | // should be generated. |
rch | 9301d3c | 2019-09-20 14:30:48 -0700 | [diff] [blame] | 162 | TEST_P(QuicStreamIdManagerTest, ProcessStreamsBlockedNoOp) { |
fkastenholz | 3c4eabf | 2019-04-22 07:49:59 -0700 | [diff] [blame] | 163 | QuicStreamCount stream_count = |
rch | a8b56e4 | 2019-09-20 10:41:48 -0700 | [diff] [blame] | 164 | stream_id_manager_.incoming_initial_max_open_streams(); |
rch | 9301d3c | 2019-09-20 14:30:48 -0700 | [diff] [blame] | 165 | QuicStreamsBlockedFrame frame(0, stream_count, IsUnidirectional()); |
rch | a8b56e4 | 2019-09-20 10:41:48 -0700 | [diff] [blame] | 166 | EXPECT_CALL(delegate_, SendMaxStreams(_, _)).Times(0); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 167 | } |
| 168 | |
fkastenholz | 3c4eabf | 2019-04-22 07:49:59 -0700 | [diff] [blame] | 169 | // Check the case of the stream count in a STREAMS_BLOCKED frame is greater than |
| 170 | // the count most recently advertised in a MAX_STREAMS frame. Expect a |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 171 | // connection close with an error. |
rch | 9301d3c | 2019-09-20 14:30:48 -0700 | [diff] [blame] | 172 | TEST_P(QuicStreamIdManagerTest, ProcessStreamsBlockedTooBig) { |
renjietang | ff4b2b6 | 2020-02-12 16:52:32 -0800 | [diff] [blame] | 173 | EXPECT_CALL(delegate_, OnStreamIdManagerError(QUIC_STREAMS_BLOCKED_ERROR, _)); |
rch | a8b56e4 | 2019-09-20 10:41:48 -0700 | [diff] [blame] | 174 | EXPECT_CALL(delegate_, SendMaxStreams(_, _)).Times(0); |
fkastenholz | 3c4eabf | 2019-04-22 07:49:59 -0700 | [diff] [blame] | 175 | QuicStreamCount stream_count = |
rch | a8b56e4 | 2019-09-20 10:41:48 -0700 | [diff] [blame] | 176 | stream_id_manager_.incoming_initial_max_open_streams() + 1; |
rch | 9301d3c | 2019-09-20 14:30:48 -0700 | [diff] [blame] | 177 | QuicStreamsBlockedFrame frame(0, stream_count, IsUnidirectional()); |
rch | a8b56e4 | 2019-09-20 10:41:48 -0700 | [diff] [blame] | 178 | stream_id_manager_.OnStreamsBlockedFrame(frame); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 179 | } |
| 180 | |
| 181 | // Same basic tests as above, but calls |
| 182 | // QuicStreamIdManager::MaybeIncreaseLargestPeerStreamId directly, avoiding the |
| 183 | // call chain. The intent is that if there is a problem, the following tests |
| 184 | // will point to either the stream ID manager or the call chain. They also |
| 185 | // provide specific, small scale, tests of a public QuicStreamIdManager method. |
| 186 | // First test make sure that streams with ids below the limit are accepted. |
rch | 9301d3c | 2019-09-20 14:30:48 -0700 | [diff] [blame] | 187 | TEST_P(QuicStreamIdManagerTest, IsIncomingStreamIdValidBelowLimit) { |
| 188 | QuicStreamId stream_id = GetNthIncomingStreamId( |
| 189 | stream_id_manager_.incoming_actual_max_streams() - 2); |
renjietang | ff4b2b6 | 2020-02-12 16:52:32 -0800 | [diff] [blame] | 190 | EXPECT_CALL(delegate_, OnStreamIdManagerError(_, _)).Times(0); |
rch | a8b56e4 | 2019-09-20 10:41:48 -0700 | [diff] [blame] | 191 | EXPECT_TRUE(stream_id_manager_.MaybeIncreaseLargestPeerStreamId(stream_id)); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 192 | } |
| 193 | |
| 194 | // Accept a stream with an ID that equals the limit. |
rch | 9301d3c | 2019-09-20 14:30:48 -0700 | [diff] [blame] | 195 | TEST_P(QuicStreamIdManagerTest, IsIncomingStreamIdValidAtLimit) { |
| 196 | QuicStreamId stream_id = GetNthIncomingStreamId( |
| 197 | stream_id_manager_.incoming_actual_max_streams() - 1); |
renjietang | ff4b2b6 | 2020-02-12 16:52:32 -0800 | [diff] [blame] | 198 | EXPECT_CALL(delegate_, OnStreamIdManagerError(_, _)).Times(0); |
rch | a8b56e4 | 2019-09-20 10:41:48 -0700 | [diff] [blame] | 199 | EXPECT_TRUE(stream_id_manager_.MaybeIncreaseLargestPeerStreamId(stream_id)); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 200 | } |
| 201 | |
| 202 | // Close the connection if the id exceeds the limit. |
rch | 9301d3c | 2019-09-20 14:30:48 -0700 | [diff] [blame] | 203 | TEST_P(QuicStreamIdManagerTest, IsIncomingStreamIdInValidAboveLimit) { |
| 204 | QuicStreamId stream_id = |
| 205 | GetNthIncomingStreamId(stream_id_manager_.incoming_actual_max_streams()); |
dmcardle | cf0bfcf | 2019-12-13 08:08:21 -0800 | [diff] [blame] | 206 | std::string error_details = quiche::QuicheStrCat( |
rch | 9301d3c | 2019-09-20 14:30:48 -0700 | [diff] [blame] | 207 | "Stream id ", stream_id, " would exceed stream count limit 100"); |
renjietang | ff4b2b6 | 2020-02-12 16:52:32 -0800 | [diff] [blame] | 208 | EXPECT_CALL(delegate_, |
| 209 | OnStreamIdManagerError(QUIC_INVALID_STREAM_ID, error_details)); |
rch | a8b56e4 | 2019-09-20 10:41:48 -0700 | [diff] [blame] | 210 | EXPECT_FALSE(stream_id_manager_.MaybeIncreaseLargestPeerStreamId(stream_id)); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 211 | } |
| 212 | |
rch | 9301d3c | 2019-09-20 14:30:48 -0700 | [diff] [blame] | 213 | TEST_P(QuicStreamIdManagerTest, OnMaxStreamsFrame) { |
fkastenholz | 3c4eabf | 2019-04-22 07:49:59 -0700 | [diff] [blame] | 214 | QuicMaxStreamsFrame frame; |
renjietang | 315428e | 2020-01-27 10:18:12 -0800 | [diff] [blame] | 215 | frame.stream_count = 10; |
fkastenholz | 3c4eabf | 2019-04-22 07:49:59 -0700 | [diff] [blame] | 216 | |
rch | 9301d3c | 2019-09-20 14:30:48 -0700 | [diff] [blame] | 217 | frame.unidirectional = IsUnidirectional(); |
| 218 | EXPECT_CALL(delegate_, OnCanCreateNewOutgoingStream(IsUnidirectional())); |
rch | a8b56e4 | 2019-09-20 10:41:48 -0700 | [diff] [blame] | 219 | EXPECT_TRUE(stream_id_manager_.OnMaxStreamsFrame(frame)); |
renjietang | 315428e | 2020-01-27 10:18:12 -0800 | [diff] [blame] | 220 | EXPECT_EQ(10u, stream_id_manager_.outgoing_max_streams()); |
fkastenholz | 3c4eabf | 2019-04-22 07:49:59 -0700 | [diff] [blame] | 221 | |
| 222 | QuicStreamCount save_outgoing_max_streams = |
rch | a8b56e4 | 2019-09-20 10:41:48 -0700 | [diff] [blame] | 223 | stream_id_manager_.outgoing_max_streams(); |
fkastenholz | 3c4eabf | 2019-04-22 07:49:59 -0700 | [diff] [blame] | 224 | // Now that there has been one MAX STREAMS frame, we should not |
| 225 | // accept a MAX_STREAMS that reduces the limit... |
renjietang | 315428e | 2020-01-27 10:18:12 -0800 | [diff] [blame] | 226 | frame.stream_count = 8; |
rch | 9301d3c | 2019-09-20 14:30:48 -0700 | [diff] [blame] | 227 | frame.unidirectional = IsUnidirectional(); |
rch | a8b56e4 | 2019-09-20 10:41:48 -0700 | [diff] [blame] | 228 | EXPECT_TRUE(stream_id_manager_.OnMaxStreamsFrame(frame)); |
fkastenholz | 3c4eabf | 2019-04-22 07:49:59 -0700 | [diff] [blame] | 229 | // should not change from previous setting. |
| 230 | EXPECT_EQ(save_outgoing_max_streams, |
rch | a8b56e4 | 2019-09-20 10:41:48 -0700 | [diff] [blame] | 231 | stream_id_manager_.outgoing_max_streams()); |
fkastenholz | 3c4eabf | 2019-04-22 07:49:59 -0700 | [diff] [blame] | 232 | |
| 233 | // A stream count greater than the current limit should increase the limit. |
renjietang | 315428e | 2020-01-27 10:18:12 -0800 | [diff] [blame] | 234 | frame.stream_count = 12; |
rch | 9301d3c | 2019-09-20 14:30:48 -0700 | [diff] [blame] | 235 | EXPECT_CALL(delegate_, OnCanCreateNewOutgoingStream(IsUnidirectional())); |
rch | a8b56e4 | 2019-09-20 10:41:48 -0700 | [diff] [blame] | 236 | EXPECT_TRUE(stream_id_manager_.OnMaxStreamsFrame(frame)); |
fkastenholz | 3c4eabf | 2019-04-22 07:49:59 -0700 | [diff] [blame] | 237 | |
renjietang | 315428e | 2020-01-27 10:18:12 -0800 | [diff] [blame] | 238 | EXPECT_EQ(12u, stream_id_manager_.outgoing_max_streams()); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 239 | } |
| 240 | |
rch | 9301d3c | 2019-09-20 14:30:48 -0700 | [diff] [blame] | 241 | TEST_P(QuicStreamIdManagerTest, OnStreamsBlockedFrame) { |
fkastenholz | 3c4eabf | 2019-04-22 07:49:59 -0700 | [diff] [blame] | 242 | // Get the current maximum allowed incoming stream count. |
| 243 | QuicStreamCount advertised_stream_count = |
rch | a8b56e4 | 2019-09-20 10:41:48 -0700 | [diff] [blame] | 244 | stream_id_manager_.incoming_advertised_max_streams(); |
| 245 | |
fkastenholz | 3c4eabf | 2019-04-22 07:49:59 -0700 | [diff] [blame] | 246 | QuicStreamsBlockedFrame frame; |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 247 | |
rch | 9301d3c | 2019-09-20 14:30:48 -0700 | [diff] [blame] | 248 | frame.unidirectional = IsUnidirectional(); |
fkastenholz | 3c4eabf | 2019-04-22 07:49:59 -0700 | [diff] [blame] | 249 | |
| 250 | // If the peer is saying it's blocked on the stream count that |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 251 | // we've advertised, it's a noop since the peer has the correct information. |
fkastenholz | 3c4eabf | 2019-04-22 07:49:59 -0700 | [diff] [blame] | 252 | frame.stream_count = advertised_stream_count; |
rch | a8b56e4 | 2019-09-20 10:41:48 -0700 | [diff] [blame] | 253 | EXPECT_TRUE(stream_id_manager_.OnStreamsBlockedFrame(frame)); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 254 | |
fkastenholz | 3c4eabf | 2019-04-22 07:49:59 -0700 | [diff] [blame] | 255 | // If the peer is saying it's blocked on a stream count that is larger |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 256 | // than what we've advertised, the connection should get closed. |
fkastenholz | 3c4eabf | 2019-04-22 07:49:59 -0700 | [diff] [blame] | 257 | frame.stream_count = advertised_stream_count + 1; |
renjietang | ff4b2b6 | 2020-02-12 16:52:32 -0800 | [diff] [blame] | 258 | EXPECT_CALL(delegate_, OnStreamIdManagerError(QUIC_STREAMS_BLOCKED_ERROR, _)); |
rch | a8b56e4 | 2019-09-20 10:41:48 -0700 | [diff] [blame] | 259 | EXPECT_FALSE(stream_id_manager_.OnStreamsBlockedFrame(frame)); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 260 | |
fkastenholz | 3c4eabf | 2019-04-22 07:49:59 -0700 | [diff] [blame] | 261 | // If the peer is saying it's blocked on a count that is less than |
| 262 | // our actual count, we send a MAX_STREAMS frame and update |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 263 | // the advertised value. |
| 264 | // First, need to bump up the actual max so there is room for the MAX |
fkastenholz | 3c4eabf | 2019-04-22 07:49:59 -0700 | [diff] [blame] | 265 | // STREAMS frame to send a larger ID. |
| 266 | QuicStreamCount actual_stream_count = |
rch | a8b56e4 | 2019-09-20 10:41:48 -0700 | [diff] [blame] | 267 | stream_id_manager_.incoming_actual_max_streams(); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 268 | |
fkastenholz | 3c4eabf | 2019-04-22 07:49:59 -0700 | [diff] [blame] | 269 | // Closing a stream will result in the ability to initiate one more |
| 270 | // stream |
rch | a8b56e4 | 2019-09-20 10:41:48 -0700 | [diff] [blame] | 271 | stream_id_manager_.OnStreamClosed( |
| 272 | QuicStreamIdManagerPeer::GetFirstIncomingStreamId(&stream_id_manager_)); |
fkastenholz | d035fc3 | 2019-04-23 12:24:02 -0700 | [diff] [blame] | 273 | EXPECT_EQ(actual_stream_count + 1u, |
rch | a8b56e4 | 2019-09-20 10:41:48 -0700 | [diff] [blame] | 274 | stream_id_manager_.incoming_actual_max_streams()); |
| 275 | EXPECT_EQ(stream_id_manager_.incoming_actual_max_streams(), |
| 276 | stream_id_manager_.incoming_advertised_max_streams() + 1u); |
fkastenholz | 3c4eabf | 2019-04-22 07:49:59 -0700 | [diff] [blame] | 277 | |
| 278 | // Now simulate receiving a STREAMS_BLOCKED frame... |
| 279 | // Changing the actual maximum, above, forces a MAX_STREAMS frame to be |
| 280 | // sent, so the logic for that (SendMaxStreamsFrame(), etc) is tested. |
| 281 | |
| 282 | // The STREAMS_BLOCKED frame contains the previous advertised count, |
| 283 | // not the one that the peer would have received as a result of the |
| 284 | // MAX_STREAMS sent earler. |
| 285 | frame.stream_count = advertised_stream_count; |
| 286 | |
rch | a8b56e4 | 2019-09-20 10:41:48 -0700 | [diff] [blame] | 287 | EXPECT_CALL(delegate_, |
| 288 | SendMaxStreams(stream_id_manager_.incoming_actual_max_streams(), |
rch | 9301d3c | 2019-09-20 14:30:48 -0700 | [diff] [blame] | 289 | IsUnidirectional())); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 290 | |
rch | a8b56e4 | 2019-09-20 10:41:48 -0700 | [diff] [blame] | 291 | EXPECT_TRUE(stream_id_manager_.OnStreamsBlockedFrame(frame)); |
fkastenholz | 3c4eabf | 2019-04-22 07:49:59 -0700 | [diff] [blame] | 292 | // Check that the saved frame is correct. |
rch | a8b56e4 | 2019-09-20 10:41:48 -0700 | [diff] [blame] | 293 | EXPECT_EQ(stream_id_manager_.incoming_actual_max_streams(), |
| 294 | stream_id_manager_.incoming_advertised_max_streams()); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 295 | } |
| 296 | |
rch | 9301d3c | 2019-09-20 14:30:48 -0700 | [diff] [blame] | 297 | TEST_P(QuicStreamIdManagerTest, GetNextOutgoingStream) { |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 298 | // Number of streams we can open and the first one we should get when |
| 299 | // opening... |
renjietang | 7fc869e | 2019-08-14 11:02:42 -0700 | [diff] [blame] | 300 | size_t number_of_streams = kDefaultMaxStreamsPerConnection; |
fkastenholz | 56055be | 2019-09-17 11:17:37 -0700 | [diff] [blame] | 301 | |
rch | 9301d3c | 2019-09-20 14:30:48 -0700 | [diff] [blame] | 302 | EXPECT_CALL(delegate_, OnCanCreateNewOutgoingStream(IsUnidirectional())); |
renjietang | 315428e | 2020-01-27 10:18:12 -0800 | [diff] [blame] | 303 | stream_id_manager_.SetMaxOpenOutgoingStreams(kDefaultMaxStreamsPerConnection); |
rch | a8b56e4 | 2019-09-20 10:41:48 -0700 | [diff] [blame] | 304 | |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 305 | QuicStreamId stream_id = |
rch | 9301d3c | 2019-09-20 14:30:48 -0700 | [diff] [blame] | 306 | IsUnidirectional() |
| 307 | ? QuicUtils::GetFirstUnidirectionalStreamId( |
| 308 | transport_version(), stream_id_manager_.perspective()) |
| 309 | : QuicUtils::GetFirstBidirectionalStreamId( |
| 310 | transport_version(), stream_id_manager_.perspective()); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 311 | |
rch | a8b56e4 | 2019-09-20 10:41:48 -0700 | [diff] [blame] | 312 | EXPECT_EQ(number_of_streams, stream_id_manager_.outgoing_max_streams()); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 313 | while (number_of_streams) { |
rch | a8b56e4 | 2019-09-20 10:41:48 -0700 | [diff] [blame] | 314 | EXPECT_TRUE(stream_id_manager_.CanOpenNextOutgoingStream()); |
| 315 | EXPECT_EQ(stream_id, stream_id_manager_.GetNextOutgoingStreamId()); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 316 | stream_id += kV99StreamIdIncrement; |
| 317 | number_of_streams--; |
| 318 | } |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 319 | |
| 320 | // If we try to check that the next outgoing stream id is available it should |
fayang | 769172b | 2020-03-19 14:27:39 -0700 | [diff] [blame] | 321 | // fail. |
rch | a8b56e4 | 2019-09-20 10:41:48 -0700 | [diff] [blame] | 322 | EXPECT_FALSE(stream_id_manager_.CanOpenNextOutgoingStream()); |
| 323 | |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 324 | // If we try to get the next id (above the limit), it should cause a quic-bug. |
| 325 | EXPECT_QUIC_BUG( |
rch | a8b56e4 | 2019-09-20 10:41:48 -0700 | [diff] [blame] | 326 | stream_id_manager_.GetNextOutgoingStreamId(), |
fkastenholz | 3c4eabf | 2019-04-22 07:49:59 -0700 | [diff] [blame] | 327 | "Attempt to allocate a new outgoing stream that would exceed the limit"); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 328 | } |
| 329 | |
rch | 9301d3c | 2019-09-20 14:30:48 -0700 | [diff] [blame] | 330 | TEST_P(QuicStreamIdManagerTest, MaybeIncreaseLargestPeerStreamId) { |
| 331 | QuicStreamId max_stream_id = GetNthIncomingStreamId( |
| 332 | stream_id_manager_.incoming_actual_max_streams() - 1); |
fkastenholz | 3c4eabf | 2019-04-22 07:49:59 -0700 | [diff] [blame] | 333 | EXPECT_TRUE( |
rch | a8b56e4 | 2019-09-20 10:41:48 -0700 | [diff] [blame] | 334 | stream_id_manager_.MaybeIncreaseLargestPeerStreamId(max_stream_id)); |
fkastenholz | 3c4eabf | 2019-04-22 07:49:59 -0700 | [diff] [blame] | 335 | |
rch | 9301d3c | 2019-09-20 14:30:48 -0700 | [diff] [blame] | 336 | QuicStreamId first_stream_id = GetNthIncomingStreamId(0); |
| 337 | EXPECT_TRUE( |
| 338 | stream_id_manager_.MaybeIncreaseLargestPeerStreamId(first_stream_id)); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 339 | // A bad stream ID results in a closed connection. |
renjietang | ff4b2b6 | 2020-02-12 16:52:32 -0800 | [diff] [blame] | 340 | EXPECT_CALL(delegate_, OnStreamIdManagerError(QUIC_INVALID_STREAM_ID, _)); |
rch | a8b56e4 | 2019-09-20 10:41:48 -0700 | [diff] [blame] | 341 | EXPECT_FALSE(stream_id_manager_.MaybeIncreaseLargestPeerStreamId( |
fkastenholz | 3c4eabf | 2019-04-22 07:49:59 -0700 | [diff] [blame] | 342 | max_stream_id + kV99StreamIdIncrement)); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 343 | } |
| 344 | |
rch | 9301d3c | 2019-09-20 14:30:48 -0700 | [diff] [blame] | 345 | TEST_P(QuicStreamIdManagerTest, MaxStreamsWindow) { |
fkastenholz | 3c4eabf | 2019-04-22 07:49:59 -0700 | [diff] [blame] | 346 | // Test that a MAX_STREAMS frame is generated when the peer has less than |
| 347 | // |max_streams_window_| streams left that it can initiate. |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 348 | |
fkastenholz | 3c4eabf | 2019-04-22 07:49:59 -0700 | [diff] [blame] | 349 | // First, open, and then close, max_streams_window_ streams. This will |
| 350 | // max_streams_window_ streams available for the peer -- no MAX_STREAMS |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 351 | // should be sent. The -1 is because the check in |
fkastenholz | 3c4eabf | 2019-04-22 07:49:59 -0700 | [diff] [blame] | 352 | // QuicStreamIdManager::MaybeSendMaxStreamsFrame sends a MAX_STREAMS if the |
| 353 | // number of available streams at the peer is <= |max_streams_window_| |
rch | a8b56e4 | 2019-09-20 10:41:48 -0700 | [diff] [blame] | 354 | int stream_count = stream_id_manager_.max_streams_window() - 1; |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 355 | |
| 356 | // Should not get a control-frame transmission since the peer should have |
| 357 | // "plenty" of stream IDs to use. |
rch | a8b56e4 | 2019-09-20 10:41:48 -0700 | [diff] [blame] | 358 | EXPECT_CALL(delegate_, SendMaxStreams(_, _)).Times(0); |
fkastenholz | 3c4eabf | 2019-04-22 07:49:59 -0700 | [diff] [blame] | 359 | |
| 360 | // Get the first incoming stream ID to try and allocate. |
rch | 9301d3c | 2019-09-20 14:30:48 -0700 | [diff] [blame] | 361 | QuicStreamId stream_id = GetNthIncomingStreamId(0); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 362 | size_t old_available_incoming_streams = |
rch | a8b56e4 | 2019-09-20 10:41:48 -0700 | [diff] [blame] | 363 | stream_id_manager_.available_incoming_streams(); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 364 | while (stream_count) { |
rch | a8b56e4 | 2019-09-20 10:41:48 -0700 | [diff] [blame] | 365 | EXPECT_TRUE(stream_id_manager_.MaybeIncreaseLargestPeerStreamId(stream_id)); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 366 | |
fkastenholz | 3c4eabf | 2019-04-22 07:49:59 -0700 | [diff] [blame] | 367 | // This node should think that the peer believes it has one fewer |
| 368 | // stream it can create. |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 369 | old_available_incoming_streams--; |
| 370 | EXPECT_EQ(old_available_incoming_streams, |
rch | a8b56e4 | 2019-09-20 10:41:48 -0700 | [diff] [blame] | 371 | stream_id_manager_.available_incoming_streams()); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 372 | |
| 373 | stream_count--; |
| 374 | stream_id += kV99StreamIdIncrement; |
| 375 | } |
| 376 | |
fkastenholz | 3c4eabf | 2019-04-22 07:49:59 -0700 | [diff] [blame] | 377 | // Now close them, still should get no MAX_STREAMS |
rch | a8b56e4 | 2019-09-20 10:41:48 -0700 | [diff] [blame] | 378 | stream_count = stream_id_manager_.max_streams_window(); |
rch | 9301d3c | 2019-09-20 14:30:48 -0700 | [diff] [blame] | 379 | stream_id = GetNthIncomingStreamId(0); |
fkastenholz | 3c4eabf | 2019-04-22 07:49:59 -0700 | [diff] [blame] | 380 | QuicStreamCount expected_actual_max = |
rch | a8b56e4 | 2019-09-20 10:41:48 -0700 | [diff] [blame] | 381 | stream_id_manager_.incoming_actual_max_streams(); |
fkastenholz | 3c4eabf | 2019-04-22 07:49:59 -0700 | [diff] [blame] | 382 | QuicStreamCount expected_advertised_max_streams = |
rch | a8b56e4 | 2019-09-20 10:41:48 -0700 | [diff] [blame] | 383 | stream_id_manager_.incoming_advertised_max_streams(); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 384 | while (stream_count) { |
rch | a8b56e4 | 2019-09-20 10:41:48 -0700 | [diff] [blame] | 385 | stream_id_manager_.OnStreamClosed(stream_id); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 386 | stream_count--; |
| 387 | stream_id += kV99StreamIdIncrement; |
fkastenholz | 3c4eabf | 2019-04-22 07:49:59 -0700 | [diff] [blame] | 388 | expected_actual_max++; |
| 389 | EXPECT_EQ(expected_actual_max, |
rch | a8b56e4 | 2019-09-20 10:41:48 -0700 | [diff] [blame] | 390 | stream_id_manager_.incoming_actual_max_streams()); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 391 | // Advertised maximum should remain the same. |
fkastenholz | 3c4eabf | 2019-04-22 07:49:59 -0700 | [diff] [blame] | 392 | EXPECT_EQ(expected_advertised_max_streams, |
rch | a8b56e4 | 2019-09-20 10:41:48 -0700 | [diff] [blame] | 393 | stream_id_manager_.incoming_advertised_max_streams()); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 394 | } |
| 395 | |
| 396 | // This should not change. |
| 397 | EXPECT_EQ(old_available_incoming_streams, |
rch | a8b56e4 | 2019-09-20 10:41:48 -0700 | [diff] [blame] | 398 | stream_id_manager_.available_incoming_streams()); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 399 | |
fkastenholz | 3c4eabf | 2019-04-22 07:49:59 -0700 | [diff] [blame] | 400 | // Now whenever we close a stream we should get a MAX_STREAMS frame. |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 401 | // Above code closed all the open streams, so we have to open/close |
rch | a8b56e4 | 2019-09-20 10:41:48 -0700 | [diff] [blame] | 402 | // EXPECT_CALL(delegate_, |
| 403 | // SendMaxStreams(stream_id_manager_.incoming_actual_max_streams(), |
rch | 9301d3c | 2019-09-20 14:30:48 -0700 | [diff] [blame] | 404 | // IsUnidirectional())); |
| 405 | EXPECT_CALL(delegate_, SendMaxStreams(_, IsUnidirectional())); |
rch | a8b56e4 | 2019-09-20 10:41:48 -0700 | [diff] [blame] | 406 | EXPECT_TRUE(stream_id_manager_.MaybeIncreaseLargestPeerStreamId(stream_id)); |
| 407 | stream_id_manager_.OnStreamClosed(stream_id); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 408 | } |
| 409 | |
rch | 9301d3c | 2019-09-20 14:30:48 -0700 | [diff] [blame] | 410 | TEST_P(QuicStreamIdManagerTest, StreamsBlockedEdgeConditions) { |
fkastenholz | 3c4eabf | 2019-04-22 07:49:59 -0700 | [diff] [blame] | 411 | QuicStreamsBlockedFrame frame; |
rch | 9301d3c | 2019-09-20 14:30:48 -0700 | [diff] [blame] | 412 | frame.unidirectional = IsUnidirectional(); |
fkastenholz | 3c4eabf | 2019-04-22 07:49:59 -0700 | [diff] [blame] | 413 | |
| 414 | // Check that receipt of a STREAMS BLOCKED with stream-count = 0 does nothing |
| 415 | // when max_allowed_incoming_streams is 0. |
rch | a8b56e4 | 2019-09-20 10:41:48 -0700 | [diff] [blame] | 416 | EXPECT_CALL(delegate_, SendMaxStreams(_, _)).Times(0); |
rch | a8b56e4 | 2019-09-20 10:41:48 -0700 | [diff] [blame] | 417 | stream_id_manager_.SetMaxOpenIncomingStreams(0); |
fkastenholz | 3c4eabf | 2019-04-22 07:49:59 -0700 | [diff] [blame] | 418 | frame.stream_count = 0; |
rch | a8b56e4 | 2019-09-20 10:41:48 -0700 | [diff] [blame] | 419 | stream_id_manager_.OnStreamsBlockedFrame(frame); |
fkastenholz | 3c4eabf | 2019-04-22 07:49:59 -0700 | [diff] [blame] | 420 | |
| 421 | // Check that receipt of a STREAMS BLOCKED with stream-count = 0 invokes a |
| 422 | // MAX STREAMS, count = 123, when the MaxOpen... is set to 123. |
rch | 9301d3c | 2019-09-20 14:30:48 -0700 | [diff] [blame] | 423 | EXPECT_CALL(delegate_, SendMaxStreams(123u, IsUnidirectional())); |
rch | a8b56e4 | 2019-09-20 10:41:48 -0700 | [diff] [blame] | 424 | stream_id_manager_.SetMaxOpenIncomingStreams(123); |
fkastenholz | 3c4eabf | 2019-04-22 07:49:59 -0700 | [diff] [blame] | 425 | frame.stream_count = 0; |
rch | a8b56e4 | 2019-09-20 10:41:48 -0700 | [diff] [blame] | 426 | stream_id_manager_.OnStreamsBlockedFrame(frame); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 427 | } |
| 428 | |
rch | 9301d3c | 2019-09-20 14:30:48 -0700 | [diff] [blame] | 429 | TEST_P(QuicStreamIdManagerTest, CheckMaxAllowedOutgoingInitialization) { |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 430 | const size_t kIncomingStreamCount = 123; |
rch | 9301d3c | 2019-09-20 14:30:48 -0700 | [diff] [blame] | 431 | EXPECT_CALL(delegate_, OnCanCreateNewOutgoingStream(IsUnidirectional())); |
rch | a8b56e4 | 2019-09-20 10:41:48 -0700 | [diff] [blame] | 432 | stream_id_manager_.SetMaxOpenOutgoingStreams(kIncomingStreamCount); |
| 433 | EXPECT_EQ(kIncomingStreamCount, stream_id_manager_.outgoing_max_streams()); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 434 | } |
| 435 | |
fkastenholz | 3c4eabf | 2019-04-22 07:49:59 -0700 | [diff] [blame] | 436 | // Test that a MAX_STREAMS frame is generated when half the stream ids become |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 437 | // available. This has a useful side effect of testing that when streams are |
| 438 | // closed, the number of available stream ids increases. |
rch | 9301d3c | 2019-09-20 14:30:48 -0700 | [diff] [blame] | 439 | TEST_P(QuicStreamIdManagerTest, MaxStreamsSlidingWindow) { |
fkastenholz | 3c4eabf | 2019-04-22 07:49:59 -0700 | [diff] [blame] | 440 | QuicStreamCount first_advert = |
rch | a8b56e4 | 2019-09-20 10:41:48 -0700 | [diff] [blame] | 441 | stream_id_manager_.incoming_advertised_max_streams(); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 442 | |
fkastenholz | 3c4eabf | 2019-04-22 07:49:59 -0700 | [diff] [blame] | 443 | // Open/close enough streams to shrink the window without causing a MAX |
| 444 | // STREAMS to be generated. The window will open (and a MAX STREAMS generated) |
| 445 | // when max_streams_window() stream IDs have been made available. The loop |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 446 | // will make that many stream IDs available, so the last CloseStream should |
rch | a8b56e4 | 2019-09-20 10:41:48 -0700 | [diff] [blame] | 447 | |
fkastenholz | 3c4eabf | 2019-04-22 07:49:59 -0700 | [diff] [blame] | 448 | // cause a MAX STREAMS frame to be generated. |
rch | a8b56e4 | 2019-09-20 10:41:48 -0700 | [diff] [blame] | 449 | int i = static_cast<int>(stream_id_manager_.max_streams_window()); |
fkastenholz | 3c4eabf | 2019-04-22 07:49:59 -0700 | [diff] [blame] | 450 | QuicStreamId id = |
rch | a8b56e4 | 2019-09-20 10:41:48 -0700 | [diff] [blame] | 451 | QuicStreamIdManagerPeer::GetFirstIncomingStreamId(&stream_id_manager_); |
| 452 | EXPECT_CALL( |
| 453 | delegate_, |
| 454 | SendMaxStreams(first_advert + stream_id_manager_.max_streams_window(), |
rch | 9301d3c | 2019-09-20 14:30:48 -0700 | [diff] [blame] | 455 | IsUnidirectional())); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 456 | while (i) { |
rch | a8b56e4 | 2019-09-20 10:41:48 -0700 | [diff] [blame] | 457 | EXPECT_TRUE(stream_id_manager_.MaybeIncreaseLargestPeerStreamId(id)); |
| 458 | stream_id_manager_.OnStreamClosed(id); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 459 | i--; |
| 460 | id += kV99StreamIdIncrement; |
| 461 | } |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 462 | } |
| 463 | |
rch | 9301d3c | 2019-09-20 14:30:48 -0700 | [diff] [blame] | 464 | TEST_P(QuicStreamIdManagerTest, NewStreamDoesNotExceedLimit) { |
| 465 | EXPECT_CALL(delegate_, OnCanCreateNewOutgoingStream(IsUnidirectional())); |
rch | a8b56e4 | 2019-09-20 10:41:48 -0700 | [diff] [blame] | 466 | stream_id_manager_.SetMaxOpenOutgoingStreams(100); |
fkastenholz | 56055be | 2019-09-17 11:17:37 -0700 | [diff] [blame] | 467 | |
rch | a8b56e4 | 2019-09-20 10:41:48 -0700 | [diff] [blame] | 468 | size_t stream_count = stream_id_manager_.outgoing_max_streams(); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 469 | EXPECT_NE(0u, stream_count); |
rch | a8b56e4 | 2019-09-20 10:41:48 -0700 | [diff] [blame] | 470 | |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 471 | while (stream_count) { |
rch | a8b56e4 | 2019-09-20 10:41:48 -0700 | [diff] [blame] | 472 | EXPECT_TRUE(stream_id_manager_.CanOpenNextOutgoingStream()); |
| 473 | stream_id_manager_.GetNextOutgoingStreamId(); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 474 | stream_count--; |
| 475 | } |
fkastenholz | 3c4eabf | 2019-04-22 07:49:59 -0700 | [diff] [blame] | 476 | |
rch | a8b56e4 | 2019-09-20 10:41:48 -0700 | [diff] [blame] | 477 | EXPECT_EQ(stream_id_manager_.outgoing_stream_count(), |
| 478 | stream_id_manager_.outgoing_max_streams()); |
fayang | 769172b | 2020-03-19 14:27:39 -0700 | [diff] [blame] | 479 | // Create another, it should fail. |
rch | a8b56e4 | 2019-09-20 10:41:48 -0700 | [diff] [blame] | 480 | EXPECT_FALSE(stream_id_manager_.CanOpenNextOutgoingStream()); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 481 | } |
| 482 | |
rch | 9301d3c | 2019-09-20 14:30:48 -0700 | [diff] [blame] | 483 | TEST_P(QuicStreamIdManagerTest, AvailableStreams) { |
rch | a8b56e4 | 2019-09-20 10:41:48 -0700 | [diff] [blame] | 484 | stream_id_manager_.MaybeIncreaseLargestPeerStreamId( |
rch | 9301d3c | 2019-09-20 14:30:48 -0700 | [diff] [blame] | 485 | GetNthIncomingStreamId(3)); |
| 486 | |
| 487 | EXPECT_TRUE(stream_id_manager_.IsAvailableStream(GetNthIncomingStreamId(1))); |
| 488 | EXPECT_TRUE(stream_id_manager_.IsAvailableStream(GetNthIncomingStreamId(2))); |
| 489 | EXPECT_FALSE(stream_id_manager_.IsAvailableStream(GetNthIncomingStreamId(3))); |
| 490 | EXPECT_TRUE(stream_id_manager_.IsAvailableStream(GetNthIncomingStreamId(4))); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 491 | } |
| 492 | |
| 493 | // Tests that if MaybeIncreaseLargestPeerStreamId is given an extremely |
| 494 | // large stream ID (larger than the limit) it is rejected. |
| 495 | // This is a regression for Chromium bugs 909987 and 910040 |
rch | 9301d3c | 2019-09-20 14:30:48 -0700 | [diff] [blame] | 496 | TEST_P(QuicStreamIdManagerTest, ExtremeMaybeIncreaseLargestPeerStreamId) { |
| 497 | QuicStreamId too_big_stream_id = GetNthIncomingStreamId( |
| 498 | stream_id_manager_.incoming_actual_max_streams() + 20); |
dmcardle | cf0bfcf | 2019-12-13 08:08:21 -0800 | [diff] [blame] | 499 | std::string error_details = quiche::QuicheStrCat( |
rch | 9301d3c | 2019-09-20 14:30:48 -0700 | [diff] [blame] | 500 | "Stream id ", too_big_stream_id, " would exceed stream count limit 100"); |
nharper | 46833c3 | 2019-05-15 21:33:05 -0700 | [diff] [blame] | 501 | |
renjietang | ff4b2b6 | 2020-02-12 16:52:32 -0800 | [diff] [blame] | 502 | EXPECT_CALL(delegate_, |
| 503 | OnStreamIdManagerError(QUIC_INVALID_STREAM_ID, error_details)); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 504 | EXPECT_FALSE( |
rch | a8b56e4 | 2019-09-20 10:41:48 -0700 | [diff] [blame] | 505 | stream_id_manager_.MaybeIncreaseLargestPeerStreamId(too_big_stream_id)); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 506 | } |
| 507 | |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 508 | } // namespace |
| 509 | } // namespace test |
| 510 | } // namespace quic |