OLD | NEW |
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 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_config.h" | 5 #include "net/quic/quic_config.h" |
6 | 6 |
7 #include "net/quic/crypto/crypto_handshake_message.h" | 7 #include "net/quic/crypto/crypto_handshake_message.h" |
8 #include "net/quic/crypto/crypto_protocol.h" | 8 #include "net/quic/crypto/crypto_protocol.h" |
9 #include "net/quic/quic_flags.h" | 9 #include "net/quic/quic_flags.h" |
10 #include "net/quic/quic_protocol.h" | 10 #include "net/quic/quic_protocol.h" |
11 #include "net/quic/quic_time.h" | 11 #include "net/quic/quic_time.h" |
12 #include "net/quic/quic_utils.h" | 12 #include "net/quic/quic_utils.h" |
13 #include "net/quic/test_tools/quic_test_utils.h" | 13 #include "net/quic/test_tools/quic_test_utils.h" |
14 #include "net/test/gtest_util.h" | 14 #include "net/test/gtest_util.h" |
15 #include "testing/gtest/include/gtest/gtest.h" | 15 #include "testing/gtest/include/gtest/gtest.h" |
16 | 16 |
17 using std::string; | 17 using std::string; |
18 | 18 |
19 namespace net { | 19 namespace net { |
20 namespace test { | 20 namespace test { |
21 namespace { | 21 namespace { |
22 | 22 |
23 class QuicConfigTest : public ::testing::Test { | 23 class QuicConfigTest : public ::testing::Test { |
24 protected: | 24 protected: |
25 QuicConfig config_; | 25 QuicConfig config_; |
26 }; | 26 }; |
27 | 27 |
28 TEST_F(QuicConfigTest, ToHandshakeMessage) { | 28 TEST_F(QuicConfigTest, ToHandshakeMessage) { |
29 config_.SetInitialFlowControlWindowToSend( | |
30 kInitialSessionFlowControlWindowForTest); | |
31 config_.SetInitialStreamFlowControlWindowToSend( | 29 config_.SetInitialStreamFlowControlWindowToSend( |
32 kInitialStreamFlowControlWindowForTest); | 30 kInitialStreamFlowControlWindowForTest); |
33 config_.SetInitialSessionFlowControlWindowToSend( | 31 config_.SetInitialSessionFlowControlWindowToSend( |
34 kInitialSessionFlowControlWindowForTest); | 32 kInitialSessionFlowControlWindowForTest); |
35 config_.SetIdleConnectionStateLifetime(QuicTime::Delta::FromSeconds(5), | 33 config_.SetIdleConnectionStateLifetime(QuicTime::Delta::FromSeconds(5), |
36 QuicTime::Delta::FromSeconds(2)); | 34 QuicTime::Delta::FromSeconds(2)); |
37 config_.SetMaxStreamsPerConnection(4, 2); | 35 config_.SetMaxStreamsPerConnection(4, 2); |
38 config_.SetSocketReceiveBufferToSend(kDefaultSocketReceiveBuffer); | 36 config_.SetSocketReceiveBufferToSend(kDefaultSocketReceiveBuffer); |
39 CryptoHandshakeMessage msg; | 37 CryptoHandshakeMessage msg; |
40 config_.ToHandshakeMessage(&msg); | 38 config_.ToHandshakeMessage(&msg); |
41 | 39 |
42 uint32 value; | 40 uint32 value; |
43 QuicErrorCode error = msg.GetUint32(kICSL, &value); | 41 QuicErrorCode error = msg.GetUint32(kICSL, &value); |
44 EXPECT_EQ(QUIC_NO_ERROR, error); | 42 EXPECT_EQ(QUIC_NO_ERROR, error); |
45 EXPECT_EQ(5u, value); | 43 EXPECT_EQ(5u, value); |
46 | 44 |
47 error = msg.GetUint32(kMSPC, &value); | 45 error = msg.GetUint32(kMSPC, &value); |
48 EXPECT_EQ(QUIC_NO_ERROR, error); | 46 EXPECT_EQ(QUIC_NO_ERROR, error); |
49 EXPECT_EQ(4u, value); | 47 EXPECT_EQ(4u, value); |
50 | 48 |
51 error = msg.GetUint32(kIFCW, &value); | |
52 EXPECT_EQ(QUIC_NO_ERROR, error); | |
53 EXPECT_EQ(kInitialSessionFlowControlWindowForTest, value); | |
54 | |
55 error = msg.GetUint32(kSFCW, &value); | 49 error = msg.GetUint32(kSFCW, &value); |
56 EXPECT_EQ(QUIC_NO_ERROR, error); | 50 EXPECT_EQ(QUIC_NO_ERROR, error); |
57 EXPECT_EQ(kInitialStreamFlowControlWindowForTest, value); | 51 EXPECT_EQ(kInitialStreamFlowControlWindowForTest, value); |
58 | 52 |
59 error = msg.GetUint32(kCFCW, &value); | 53 error = msg.GetUint32(kCFCW, &value); |
60 EXPECT_EQ(QUIC_NO_ERROR, error); | 54 EXPECT_EQ(QUIC_NO_ERROR, error); |
61 EXPECT_EQ(kInitialSessionFlowControlWindowForTest, value); | 55 EXPECT_EQ(kInitialSessionFlowControlWindowForTest, value); |
62 | 56 |
63 error = msg.GetUint32(kSRBF, &value); | 57 error = msg.GetUint32(kSRBF, &value); |
64 EXPECT_EQ(QUIC_NO_ERROR, error); | 58 EXPECT_EQ(QUIC_NO_ERROR, error); |
(...skipping 10 matching lines...) Expand all Loading... |
75 QuicConfig client_config; | 69 QuicConfig client_config; |
76 QuicTagVector cgst; | 70 QuicTagVector cgst; |
77 cgst.push_back(kQBIC); | 71 cgst.push_back(kQBIC); |
78 client_config.SetCongestionFeedback(cgst, kQBIC); | 72 client_config.SetCongestionFeedback(cgst, kQBIC); |
79 client_config.SetIdleConnectionStateLifetime( | 73 client_config.SetIdleConnectionStateLifetime( |
80 QuicTime::Delta::FromSeconds(2 * kMaximumIdleTimeoutSecs), | 74 QuicTime::Delta::FromSeconds(2 * kMaximumIdleTimeoutSecs), |
81 QuicTime::Delta::FromSeconds(kMaximumIdleTimeoutSecs)); | 75 QuicTime::Delta::FromSeconds(kMaximumIdleTimeoutSecs)); |
82 client_config.SetMaxStreamsPerConnection( | 76 client_config.SetMaxStreamsPerConnection( |
83 2 * kDefaultMaxStreamsPerConnection, kDefaultMaxStreamsPerConnection); | 77 2 * kDefaultMaxStreamsPerConnection, kDefaultMaxStreamsPerConnection); |
84 client_config.SetInitialRoundTripTimeUsToSend(10 * kNumMicrosPerMilli); | 78 client_config.SetInitialRoundTripTimeUsToSend(10 * kNumMicrosPerMilli); |
85 client_config.SetInitialFlowControlWindowToSend( | |
86 2 * kInitialSessionFlowControlWindowForTest); | |
87 client_config.SetInitialStreamFlowControlWindowToSend( | 79 client_config.SetInitialStreamFlowControlWindowToSend( |
88 2 * kInitialStreamFlowControlWindowForTest); | 80 2 * kInitialStreamFlowControlWindowForTest); |
89 client_config.SetInitialSessionFlowControlWindowToSend( | 81 client_config.SetInitialSessionFlowControlWindowToSend( |
90 2 * kInitialSessionFlowControlWindowForTest); | 82 2 * kInitialSessionFlowControlWindowForTest); |
91 client_config.SetSocketReceiveBufferToSend(kDefaultSocketReceiveBuffer); | 83 client_config.SetSocketReceiveBufferToSend(kDefaultSocketReceiveBuffer); |
92 QuicTagVector copt; | 84 QuicTagVector copt; |
93 copt.push_back(kTBBR); | 85 copt.push_back(kTBBR); |
94 copt.push_back(kFHDR); | 86 copt.push_back(kFHDR); |
95 client_config.SetConnectionOptionsToSend(copt); | 87 client_config.SetConnectionOptionsToSend(copt); |
96 CryptoHandshakeMessage msg; | 88 CryptoHandshakeMessage msg; |
97 client_config.ToHandshakeMessage(&msg); | 89 client_config.ToHandshakeMessage(&msg); |
98 | 90 |
99 string error_details; | 91 string error_details; |
100 const QuicErrorCode error = | 92 const QuicErrorCode error = |
101 config_.ProcessPeerHello(msg, CLIENT, &error_details); | 93 config_.ProcessPeerHello(msg, CLIENT, &error_details); |
102 EXPECT_EQ(QUIC_NO_ERROR, error); | 94 EXPECT_EQ(QUIC_NO_ERROR, error); |
103 EXPECT_TRUE(config_.negotiated()); | 95 EXPECT_TRUE(config_.negotiated()); |
104 EXPECT_EQ(kQBIC, config_.CongestionFeedback()); | 96 EXPECT_EQ(kQBIC, config_.CongestionFeedback()); |
105 EXPECT_EQ(QuicTime::Delta::FromSeconds(kMaximumIdleTimeoutSecs), | 97 EXPECT_EQ(QuicTime::Delta::FromSeconds(kMaximumIdleTimeoutSecs), |
106 config_.IdleConnectionStateLifetime()); | 98 config_.IdleConnectionStateLifetime()); |
107 EXPECT_EQ(kDefaultMaxStreamsPerConnection, | 99 EXPECT_EQ(kDefaultMaxStreamsPerConnection, |
108 config_.MaxStreamsPerConnection()); | 100 config_.MaxStreamsPerConnection()); |
109 EXPECT_EQ(10 * kNumMicrosPerMilli, config_.ReceivedInitialRoundTripTimeUs()); | 101 EXPECT_EQ(10 * kNumMicrosPerMilli, config_.ReceivedInitialRoundTripTimeUs()); |
110 EXPECT_TRUE(config_.HasReceivedConnectionOptions()); | 102 EXPECT_TRUE(config_.HasReceivedConnectionOptions()); |
111 EXPECT_EQ(2u, config_.ReceivedConnectionOptions().size()); | 103 EXPECT_EQ(2u, config_.ReceivedConnectionOptions().size()); |
112 EXPECT_EQ(config_.ReceivedConnectionOptions()[0], kTBBR); | 104 EXPECT_EQ(config_.ReceivedConnectionOptions()[0], kTBBR); |
113 EXPECT_EQ(config_.ReceivedConnectionOptions()[1], kFHDR); | 105 EXPECT_EQ(config_.ReceivedConnectionOptions()[1], kFHDR); |
114 EXPECT_EQ(config_.ReceivedInitialFlowControlWindowBytes(), | |
115 2 * kInitialSessionFlowControlWindowForTest); | |
116 EXPECT_EQ(config_.ReceivedInitialStreamFlowControlWindowBytes(), | 106 EXPECT_EQ(config_.ReceivedInitialStreamFlowControlWindowBytes(), |
117 2 * kInitialStreamFlowControlWindowForTest); | 107 2 * kInitialStreamFlowControlWindowForTest); |
118 EXPECT_EQ(config_.ReceivedInitialSessionFlowControlWindowBytes(), | 108 EXPECT_EQ(config_.ReceivedInitialSessionFlowControlWindowBytes(), |
119 2 * kInitialSessionFlowControlWindowForTest); | 109 2 * kInitialSessionFlowControlWindowForTest); |
120 EXPECT_EQ(config_.ReceivedSocketReceiveBuffer(), | 110 EXPECT_EQ(config_.ReceivedSocketReceiveBuffer(), |
121 kDefaultSocketReceiveBuffer); | 111 kDefaultSocketReceiveBuffer); |
122 } | 112 } |
123 | 113 |
124 TEST_F(QuicConfigTest, ProcessServerHello) { | 114 TEST_F(QuicConfigTest, ProcessServerHello) { |
125 QuicConfig server_config; | 115 QuicConfig server_config; |
126 QuicTagVector cgst; | 116 QuicTagVector cgst; |
127 cgst.push_back(kQBIC); | 117 cgst.push_back(kQBIC); |
128 server_config.SetCongestionFeedback(cgst, kQBIC); | 118 server_config.SetCongestionFeedback(cgst, kQBIC); |
129 server_config.SetIdleConnectionStateLifetime( | 119 server_config.SetIdleConnectionStateLifetime( |
130 QuicTime::Delta::FromSeconds(kMaximumIdleTimeoutSecs / 2), | 120 QuicTime::Delta::FromSeconds(kMaximumIdleTimeoutSecs / 2), |
131 QuicTime::Delta::FromSeconds(kMaximumIdleTimeoutSecs / 2)); | 121 QuicTime::Delta::FromSeconds(kMaximumIdleTimeoutSecs / 2)); |
132 server_config.SetMaxStreamsPerConnection( | 122 server_config.SetMaxStreamsPerConnection( |
133 kDefaultMaxStreamsPerConnection / 2, | 123 kDefaultMaxStreamsPerConnection / 2, |
134 kDefaultMaxStreamsPerConnection / 2); | 124 kDefaultMaxStreamsPerConnection / 2); |
135 server_config.SetInitialRoundTripTimeUsToSend(10 * kNumMicrosPerMilli); | 125 server_config.SetInitialRoundTripTimeUsToSend(10 * kNumMicrosPerMilli); |
136 server_config.SetInitialFlowControlWindowToSend( | |
137 2 * kInitialSessionFlowControlWindowForTest); | |
138 server_config.SetInitialStreamFlowControlWindowToSend( | 126 server_config.SetInitialStreamFlowControlWindowToSend( |
139 2 * kInitialStreamFlowControlWindowForTest); | 127 2 * kInitialStreamFlowControlWindowForTest); |
140 server_config.SetInitialSessionFlowControlWindowToSend( | 128 server_config.SetInitialSessionFlowControlWindowToSend( |
141 2 * kInitialSessionFlowControlWindowForTest); | 129 2 * kInitialSessionFlowControlWindowForTest); |
142 server_config.SetSocketReceiveBufferToSend(kDefaultSocketReceiveBuffer); | 130 server_config.SetSocketReceiveBufferToSend(kDefaultSocketReceiveBuffer); |
143 CryptoHandshakeMessage msg; | 131 CryptoHandshakeMessage msg; |
144 server_config.ToHandshakeMessage(&msg); | 132 server_config.ToHandshakeMessage(&msg); |
145 string error_details; | 133 string error_details; |
146 const QuicErrorCode error = | 134 const QuicErrorCode error = |
147 config_.ProcessPeerHello(msg, SERVER, &error_details); | 135 config_.ProcessPeerHello(msg, SERVER, &error_details); |
148 EXPECT_EQ(QUIC_NO_ERROR, error); | 136 EXPECT_EQ(QUIC_NO_ERROR, error); |
149 EXPECT_TRUE(config_.negotiated()); | 137 EXPECT_TRUE(config_.negotiated()); |
150 EXPECT_EQ(kQBIC, config_.CongestionFeedback()); | 138 EXPECT_EQ(kQBIC, config_.CongestionFeedback()); |
151 EXPECT_EQ(QuicTime::Delta::FromSeconds(kMaximumIdleTimeoutSecs / 2), | 139 EXPECT_EQ(QuicTime::Delta::FromSeconds(kMaximumIdleTimeoutSecs / 2), |
152 config_.IdleConnectionStateLifetime()); | 140 config_.IdleConnectionStateLifetime()); |
153 EXPECT_EQ(kDefaultMaxStreamsPerConnection / 2, | 141 EXPECT_EQ(kDefaultMaxStreamsPerConnection / 2, |
154 config_.MaxStreamsPerConnection()); | 142 config_.MaxStreamsPerConnection()); |
155 EXPECT_EQ(10 * kNumMicrosPerMilli, config_.ReceivedInitialRoundTripTimeUs()); | 143 EXPECT_EQ(10 * kNumMicrosPerMilli, config_.ReceivedInitialRoundTripTimeUs()); |
156 EXPECT_EQ(config_.ReceivedInitialFlowControlWindowBytes(), | |
157 2 * kInitialSessionFlowControlWindowForTest); | |
158 EXPECT_EQ(config_.ReceivedInitialStreamFlowControlWindowBytes(), | 144 EXPECT_EQ(config_.ReceivedInitialStreamFlowControlWindowBytes(), |
159 2 * kInitialStreamFlowControlWindowForTest); | 145 2 * kInitialStreamFlowControlWindowForTest); |
160 EXPECT_EQ(config_.ReceivedInitialSessionFlowControlWindowBytes(), | 146 EXPECT_EQ(config_.ReceivedInitialSessionFlowControlWindowBytes(), |
161 2 * kInitialSessionFlowControlWindowForTest); | 147 2 * kInitialSessionFlowControlWindowForTest); |
162 EXPECT_EQ(config_.ReceivedSocketReceiveBuffer(), | 148 EXPECT_EQ(config_.ReceivedSocketReceiveBuffer(), |
163 kDefaultSocketReceiveBuffer); | 149 kDefaultSocketReceiveBuffer); |
164 } | 150 } |
165 | 151 |
166 TEST_F(QuicConfigTest, MissingOptionalValuesInCHLO) { | 152 TEST_F(QuicConfigTest, MissingOptionalValuesInCHLO) { |
167 CryptoHandshakeMessage msg; | 153 CryptoHandshakeMessage msg; |
168 msg.SetValue(kICSL, 1); | 154 msg.SetValue(kICSL, 1); |
169 msg.SetVector(kCGST, QuicTagVector(1, kQBIC)); | 155 msg.SetVector(kCGST, QuicTagVector(1, kQBIC)); |
170 | 156 |
171 // Set all REQUIRED tags. | 157 // Set all REQUIRED tags. |
172 msg.SetValue(kICSL, 1); | 158 msg.SetValue(kICSL, 1); |
173 msg.SetVector(kCGST, QuicTagVector(1, kQBIC)); | 159 msg.SetVector(kCGST, QuicTagVector(1, kQBIC)); |
174 msg.SetValue(kMSPC, 1); | 160 msg.SetValue(kMSPC, 1); |
175 | 161 |
176 // No error, as rest are optional. | 162 // No error, as rest are optional. |
177 string error_details; | 163 string error_details; |
178 const QuicErrorCode error = | 164 const QuicErrorCode error = |
179 config_.ProcessPeerHello(msg, CLIENT, &error_details); | 165 config_.ProcessPeerHello(msg, CLIENT, &error_details); |
180 EXPECT_EQ(QUIC_NO_ERROR, error); | 166 EXPECT_EQ(QUIC_NO_ERROR, error); |
181 EXPECT_TRUE(config_.negotiated()); | 167 EXPECT_TRUE(config_.negotiated()); |
182 | |
183 EXPECT_FALSE(config_.HasReceivedInitialFlowControlWindowBytes()); | |
184 } | 168 } |
185 | 169 |
186 TEST_F(QuicConfigTest, MissingOptionalValuesInSHLO) { | 170 TEST_F(QuicConfigTest, MissingOptionalValuesInSHLO) { |
187 CryptoHandshakeMessage msg; | 171 CryptoHandshakeMessage msg; |
188 | 172 |
189 // Set all REQUIRED tags. | 173 // Set all REQUIRED tags. |
190 msg.SetValue(kICSL, 1); | 174 msg.SetValue(kICSL, 1); |
191 msg.SetVector(kCGST, QuicTagVector(1, kQBIC)); | 175 msg.SetVector(kCGST, QuicTagVector(1, kQBIC)); |
192 msg.SetValue(kMSPC, 1); | 176 msg.SetValue(kMSPC, 1); |
193 | 177 |
194 // No error, as rest are optional. | 178 // No error, as rest are optional. |
195 string error_details; | 179 string error_details; |
196 const QuicErrorCode error = | 180 const QuicErrorCode error = |
197 config_.ProcessPeerHello(msg, SERVER, &error_details); | 181 config_.ProcessPeerHello(msg, SERVER, &error_details); |
198 EXPECT_EQ(QUIC_NO_ERROR, error); | 182 EXPECT_EQ(QUIC_NO_ERROR, error); |
199 EXPECT_TRUE(config_.negotiated()); | 183 EXPECT_TRUE(config_.negotiated()); |
200 | |
201 EXPECT_FALSE(config_.HasReceivedInitialFlowControlWindowBytes()); | |
202 } | 184 } |
203 | 185 |
204 TEST_F(QuicConfigTest, MissingValueInCHLO) { | 186 TEST_F(QuicConfigTest, MissingValueInCHLO) { |
205 CryptoHandshakeMessage msg; | 187 CryptoHandshakeMessage msg; |
206 msg.SetValue(kICSL, 1); | 188 msg.SetValue(kICSL, 1); |
207 msg.SetVector(kCGST, QuicTagVector(1, kQBIC)); | 189 msg.SetVector(kCGST, QuicTagVector(1, kQBIC)); |
208 // Missing kMSPC. KATO is optional. | 190 // Missing kMSPC. KATO is optional. |
209 string error_details; | 191 string error_details; |
210 const QuicErrorCode error = | 192 const QuicErrorCode error = |
211 config_.ProcessPeerHello(msg, CLIENT, &error_details); | 193 config_.ProcessPeerHello(msg, CLIENT, &error_details); |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
265 config_.ProcessPeerHello(msg, CLIENT, &error_details); | 247 config_.ProcessPeerHello(msg, CLIENT, &error_details); |
266 DVLOG(1) << QuicUtils::ErrorToString(error); | 248 DVLOG(1) << QuicUtils::ErrorToString(error); |
267 EXPECT_EQ(QUIC_CRYPTO_MESSAGE_PARAMETER_NO_OVERLAP, error); | 249 EXPECT_EQ(QUIC_CRYPTO_MESSAGE_PARAMETER_NO_OVERLAP, error); |
268 } | 250 } |
269 | 251 |
270 TEST_F(QuicConfigTest, InvalidFlowControlWindow) { | 252 TEST_F(QuicConfigTest, InvalidFlowControlWindow) { |
271 // QuicConfig should not accept an invalid flow control window to send to the | 253 // QuicConfig should not accept an invalid flow control window to send to the |
272 // peer: the receive window must be at least the default of 16 Kb. | 254 // peer: the receive window must be at least the default of 16 Kb. |
273 QuicConfig config; | 255 QuicConfig config; |
274 const uint64 kInvalidWindow = kMinimumFlowControlSendWindow - 1; | 256 const uint64 kInvalidWindow = kMinimumFlowControlSendWindow - 1; |
275 EXPECT_DFATAL(config.SetInitialFlowControlWindowToSend(kInvalidWindow), | 257 EXPECT_DFATAL(config.SetInitialStreamFlowControlWindowToSend(kInvalidWindow), |
276 "Initial flow control receive window"); | 258 "Initial stream flow control receive window"); |
277 | 259 |
278 EXPECT_EQ(kMinimumFlowControlSendWindow, | 260 EXPECT_EQ(kMinimumFlowControlSendWindow, |
279 config.GetInitialFlowControlWindowToSend()); | 261 config.GetInitialStreamFlowControlWindowToSend()); |
280 } | 262 } |
281 | 263 |
282 } // namespace | 264 } // namespace |
283 } // namespace test | 265 } // namespace test |
284 } // namespace net | 266 } // namespace net |
OLD | NEW |