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_sent_packet_manager.h" | 11 #include "net/quic/quic_sent_packet_manager.h" |
12 #include "net/quic/quic_time.h" | 12 #include "net/quic/quic_time.h" |
13 #include "net/quic/quic_utils.h" | 13 #include "net/quic/quic_utils.h" |
14 #include "net/quic/test_tools/quic_test_utils.h" | 14 #include "net/quic/test_tools/quic_test_utils.h" |
| 15 #include "net/test/gtest_util.h" |
15 #include "testing/gtest/include/gtest/gtest.h" | 16 #include "testing/gtest/include/gtest/gtest.h" |
16 | 17 |
17 using std::string; | 18 using std::string; |
18 | 19 |
19 namespace net { | 20 namespace net { |
20 namespace test { | 21 namespace test { |
21 namespace { | 22 namespace { |
22 | 23 |
23 class QuicConfigTest : public ::testing::Test { | 24 class QuicConfigTest : public ::testing::Test { |
24 protected: | 25 protected: |
25 QuicConfigTest() { | 26 QuicConfigTest() { |
26 config_.SetDefaults(); | 27 config_.SetDefaults(); |
27 } | 28 } |
28 | 29 |
29 QuicConfig config_; | 30 QuicConfig config_; |
30 }; | 31 }; |
31 | 32 |
32 TEST_F(QuicConfigTest, ToHandshakeMessage) { | 33 TEST_F(QuicConfigTest, ToHandshakeMessage) { |
33 ValueRestore<bool> old_flag(&FLAGS_enable_quic_pacing, false); | 34 ValueRestore<bool> old_flag(&FLAGS_enable_quic_pacing, false); |
34 config_.SetDefaults(); | 35 config_.SetDefaults(); |
| 36 config_.SetInitialFlowControlWindowToSend(kInitialFlowControlWindowForTest); |
35 config_.set_idle_connection_state_lifetime(QuicTime::Delta::FromSeconds(5), | 37 config_.set_idle_connection_state_lifetime(QuicTime::Delta::FromSeconds(5), |
36 QuicTime::Delta::FromSeconds(2)); | 38 QuicTime::Delta::FromSeconds(2)); |
37 config_.set_max_streams_per_connection(4, 2); | 39 config_.set_max_streams_per_connection(4, 2); |
38 CryptoHandshakeMessage msg; | 40 CryptoHandshakeMessage msg; |
39 config_.ToHandshakeMessage(&msg); | 41 config_.ToHandshakeMessage(&msg); |
40 | 42 |
41 uint32 value; | 43 uint32 value; |
42 QuicErrorCode error = msg.GetUint32(kICSL, &value); | 44 QuicErrorCode error = msg.GetUint32(kICSL, &value); |
43 EXPECT_EQ(QUIC_NO_ERROR, error); | 45 EXPECT_EQ(QUIC_NO_ERROR, error); |
44 EXPECT_EQ(5u, value); | 46 EXPECT_EQ(5u, value); |
45 | 47 |
46 error = msg.GetUint32(kMSPC, &value); | 48 error = msg.GetUint32(kMSPC, &value); |
47 EXPECT_EQ(QUIC_NO_ERROR, error); | 49 EXPECT_EQ(QUIC_NO_ERROR, error); |
48 EXPECT_EQ(4u, value); | 50 EXPECT_EQ(4u, value); |
49 | 51 |
| 52 error = msg.GetUint32(kIFCW, &value); |
| 53 EXPECT_EQ(QUIC_NO_ERROR, error); |
| 54 EXPECT_EQ(kInitialFlowControlWindowForTest, value); |
| 55 |
50 const QuicTag* out; | 56 const QuicTag* out; |
51 size_t out_len; | 57 size_t out_len; |
52 error = msg.GetTaglist(kCGST, &out, &out_len); | 58 error = msg.GetTaglist(kCGST, &out, &out_len); |
53 EXPECT_EQ(1u, out_len); | 59 EXPECT_EQ(1u, out_len); |
54 EXPECT_EQ(kQBIC, *out); | 60 EXPECT_EQ(kQBIC, *out); |
55 } | 61 } |
56 | 62 |
57 TEST_F(QuicConfigTest, ToHandshakeMessageWithPacing) { | 63 TEST_F(QuicConfigTest, ToHandshakeMessageWithPacing) { |
58 ValueRestore<bool> old_flag(&FLAGS_enable_quic_pacing, true); | 64 ValueRestore<bool> old_flag(&FLAGS_enable_quic_pacing, true); |
59 | 65 |
(...skipping 15 matching lines...) Expand all Loading... |
75 cgst.push_back(kINAR); | 81 cgst.push_back(kINAR); |
76 cgst.push_back(kQBIC); | 82 cgst.push_back(kQBIC); |
77 client_config.set_congestion_feedback(cgst, kQBIC); | 83 client_config.set_congestion_feedback(cgst, kQBIC); |
78 client_config.set_idle_connection_state_lifetime( | 84 client_config.set_idle_connection_state_lifetime( |
79 QuicTime::Delta::FromSeconds(2 * kDefaultTimeoutSecs), | 85 QuicTime::Delta::FromSeconds(2 * kDefaultTimeoutSecs), |
80 QuicTime::Delta::FromSeconds(kDefaultTimeoutSecs)); | 86 QuicTime::Delta::FromSeconds(kDefaultTimeoutSecs)); |
81 client_config.set_max_streams_per_connection( | 87 client_config.set_max_streams_per_connection( |
82 2 * kDefaultMaxStreamsPerConnection, kDefaultMaxStreamsPerConnection); | 88 2 * kDefaultMaxStreamsPerConnection, kDefaultMaxStreamsPerConnection); |
83 client_config.SetInitialRoundTripTimeUsToSend( | 89 client_config.SetInitialRoundTripTimeUsToSend( |
84 10 * base::Time::kMicrosecondsPerMillisecond); | 90 10 * base::Time::kMicrosecondsPerMillisecond); |
| 91 client_config.SetInitialFlowControlWindowToSend( |
| 92 2 * kInitialFlowControlWindowForTest); |
85 QuicTagVector copt; | 93 QuicTagVector copt; |
86 copt.push_back(kTBBR); | 94 copt.push_back(kTBBR); |
87 client_config.SetCongestionOptionsToSend(copt); | 95 client_config.SetCongestionOptionsToSend(copt); |
88 CryptoHandshakeMessage msg; | 96 CryptoHandshakeMessage msg; |
89 client_config.ToHandshakeMessage(&msg); | 97 client_config.ToHandshakeMessage(&msg); |
90 string error_details; | 98 string error_details; |
91 const QuicErrorCode error = | 99 const QuicErrorCode error = |
92 config_.ProcessPeerHello(msg, CLIENT, &error_details); | 100 config_.ProcessPeerHello(msg, CLIENT, &error_details); |
93 EXPECT_EQ(QUIC_NO_ERROR, error); | 101 EXPECT_EQ(QUIC_NO_ERROR, error); |
94 EXPECT_TRUE(config_.negotiated()); | 102 EXPECT_TRUE(config_.negotiated()); |
95 EXPECT_EQ(kQBIC, config_.congestion_feedback()); | 103 EXPECT_EQ(kQBIC, config_.congestion_feedback()); |
96 EXPECT_EQ(QuicTime::Delta::FromSeconds(kDefaultTimeoutSecs), | 104 EXPECT_EQ(QuicTime::Delta::FromSeconds(kDefaultTimeoutSecs), |
97 config_.idle_connection_state_lifetime()); | 105 config_.idle_connection_state_lifetime()); |
98 EXPECT_EQ(kDefaultMaxStreamsPerConnection, | 106 EXPECT_EQ(kDefaultMaxStreamsPerConnection, |
99 config_.max_streams_per_connection()); | 107 config_.max_streams_per_connection()); |
100 EXPECT_EQ(QuicTime::Delta::FromSeconds(0), config_.keepalive_timeout()); | 108 EXPECT_EQ(QuicTime::Delta::FromSeconds(0), config_.keepalive_timeout()); |
101 EXPECT_EQ(10 * base::Time::kMicrosecondsPerMillisecond, | 109 EXPECT_EQ(10 * base::Time::kMicrosecondsPerMillisecond, |
102 config_.ReceivedInitialRoundTripTimeUs()); | 110 config_.ReceivedInitialRoundTripTimeUs()); |
103 EXPECT_FALSE(config_.HasReceivedLossDetection()); | 111 EXPECT_FALSE(config_.HasReceivedLossDetection()); |
104 EXPECT_TRUE(config_.HasReceivedCongestionOptions()); | 112 EXPECT_TRUE(config_.HasReceivedCongestionOptions()); |
105 EXPECT_EQ(1u, config_.ReceivedCongestionOptions().size()); | 113 EXPECT_EQ(1u, config_.ReceivedCongestionOptions().size()); |
106 EXPECT_EQ(config_.ReceivedCongestionOptions()[0], kTBBR); | 114 EXPECT_EQ(config_.ReceivedCongestionOptions()[0], kTBBR); |
| 115 EXPECT_EQ(config_.ReceivedInitialFlowControlWindowBytes(), |
| 116 2 * kInitialFlowControlWindowForTest); |
107 } | 117 } |
108 | 118 |
109 TEST_F(QuicConfigTest, ProcessServerHello) { | 119 TEST_F(QuicConfigTest, ProcessServerHello) { |
110 QuicConfig server_config; | 120 QuicConfig server_config; |
111 QuicTagVector cgst; | 121 QuicTagVector cgst; |
112 cgst.push_back(kQBIC); | 122 cgst.push_back(kQBIC); |
113 server_config.set_congestion_feedback(cgst, kQBIC); | 123 server_config.set_congestion_feedback(cgst, kQBIC); |
114 server_config.set_idle_connection_state_lifetime( | 124 server_config.set_idle_connection_state_lifetime( |
115 QuicTime::Delta::FromSeconds(kDefaultTimeoutSecs / 2), | 125 QuicTime::Delta::FromSeconds(kDefaultTimeoutSecs / 2), |
116 QuicTime::Delta::FromSeconds(kDefaultTimeoutSecs / 2)); | 126 QuicTime::Delta::FromSeconds(kDefaultTimeoutSecs / 2)); |
117 server_config.set_max_streams_per_connection( | 127 server_config.set_max_streams_per_connection( |
118 kDefaultMaxStreamsPerConnection / 2, | 128 kDefaultMaxStreamsPerConnection / 2, |
119 kDefaultMaxStreamsPerConnection / 2); | 129 kDefaultMaxStreamsPerConnection / 2); |
120 server_config.SetInitialCongestionWindowToSend(kDefaultInitialWindow / 2); | 130 server_config.SetInitialCongestionWindowToSend(kDefaultInitialWindow / 2); |
121 server_config.SetInitialRoundTripTimeUsToSend( | 131 server_config.SetInitialRoundTripTimeUsToSend( |
122 10 * base::Time::kMicrosecondsPerMillisecond); | 132 10 * base::Time::kMicrosecondsPerMillisecond); |
| 133 server_config.SetInitialFlowControlWindowToSend( |
| 134 2 * kInitialFlowControlWindowForTest); |
123 CryptoHandshakeMessage msg; | 135 CryptoHandshakeMessage msg; |
124 server_config.ToHandshakeMessage(&msg); | 136 server_config.ToHandshakeMessage(&msg); |
125 string error_details; | 137 string error_details; |
126 const QuicErrorCode error = | 138 const QuicErrorCode error = |
127 config_.ProcessPeerHello(msg, SERVER, &error_details); | 139 config_.ProcessPeerHello(msg, SERVER, &error_details); |
128 EXPECT_EQ(QUIC_NO_ERROR, error); | 140 EXPECT_EQ(QUIC_NO_ERROR, error); |
129 EXPECT_TRUE(config_.negotiated()); | 141 EXPECT_TRUE(config_.negotiated()); |
130 EXPECT_EQ(kQBIC, config_.congestion_feedback()); | 142 EXPECT_EQ(kQBIC, config_.congestion_feedback()); |
131 EXPECT_EQ(QuicTime::Delta::FromSeconds(kDefaultTimeoutSecs / 2), | 143 EXPECT_EQ(QuicTime::Delta::FromSeconds(kDefaultTimeoutSecs / 2), |
132 config_.idle_connection_state_lifetime()); | 144 config_.idle_connection_state_lifetime()); |
133 EXPECT_EQ(kDefaultMaxStreamsPerConnection / 2, | 145 EXPECT_EQ(kDefaultMaxStreamsPerConnection / 2, |
134 config_.max_streams_per_connection()); | 146 config_.max_streams_per_connection()); |
135 EXPECT_EQ(kDefaultInitialWindow / 2, | 147 EXPECT_EQ(kDefaultInitialWindow / 2, |
136 config_.ReceivedInitialCongestionWindow()); | 148 config_.ReceivedInitialCongestionWindow()); |
137 EXPECT_EQ(QuicTime::Delta::FromSeconds(0), config_.keepalive_timeout()); | 149 EXPECT_EQ(QuicTime::Delta::FromSeconds(0), config_.keepalive_timeout()); |
138 EXPECT_EQ(10 * base::Time::kMicrosecondsPerMillisecond, | 150 EXPECT_EQ(10 * base::Time::kMicrosecondsPerMillisecond, |
139 config_.ReceivedInitialRoundTripTimeUs()); | 151 config_.ReceivedInitialRoundTripTimeUs()); |
140 EXPECT_FALSE(config_.HasReceivedLossDetection()); | 152 EXPECT_FALSE(config_.HasReceivedLossDetection()); |
| 153 EXPECT_EQ(config_.ReceivedInitialFlowControlWindowBytes(), |
| 154 2 * kInitialFlowControlWindowForTest); |
141 } | 155 } |
142 | 156 |
143 TEST_F(QuicConfigTest, MissingOptionalValuesInCHLO) { | 157 TEST_F(QuicConfigTest, MissingOptionalValuesInCHLO) { |
144 CryptoHandshakeMessage msg; | 158 CryptoHandshakeMessage msg; |
145 msg.SetValue(kICSL, 1); | 159 msg.SetValue(kICSL, 1); |
146 msg.SetVector(kCGST, QuicTagVector(1, kQBIC)); | 160 msg.SetVector(kCGST, QuicTagVector(1, kQBIC)); |
147 | 161 |
148 // Set all REQUIRED tags. | 162 // Set all REQUIRED tags. |
149 msg.SetValue(kICSL, 1); | 163 msg.SetValue(kICSL, 1); |
150 msg.SetVector(kCGST, QuicTagVector(1, kQBIC)); | 164 msg.SetVector(kCGST, QuicTagVector(1, kQBIC)); |
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
236 | 250 |
237 CryptoHandshakeMessage msg; | 251 CryptoHandshakeMessage msg; |
238 string error_details; | 252 string error_details; |
239 server_config.ToHandshakeMessage(&msg); | 253 server_config.ToHandshakeMessage(&msg); |
240 const QuicErrorCode error = | 254 const QuicErrorCode error = |
241 config_.ProcessPeerHello(msg, CLIENT, &error_details); | 255 config_.ProcessPeerHello(msg, CLIENT, &error_details); |
242 DVLOG(1) << QuicUtils::ErrorToString(error); | 256 DVLOG(1) << QuicUtils::ErrorToString(error); |
243 EXPECT_EQ(QUIC_CRYPTO_MESSAGE_PARAMETER_NO_OVERLAP, error); | 257 EXPECT_EQ(QUIC_CRYPTO_MESSAGE_PARAMETER_NO_OVERLAP, error); |
244 } | 258 } |
245 | 259 |
| 260 TEST_F(QuicConfigTest, InvalidFlowControlWindow) { |
| 261 // QuicConfig should not accept an invalid flow control window to send to the |
| 262 // peer: the receive window must be at least the default of 16 Kb. |
| 263 QuicConfig config; |
| 264 const uint64 kInvalidWindow = kDefaultFlowControlSendWindow - 1; |
| 265 EXPECT_DFATAL(config.SetInitialFlowControlWindowToSend(kInvalidWindow), |
| 266 "Initial flow control receive window"); |
| 267 |
| 268 EXPECT_EQ(kDefaultFlowControlSendWindow, |
| 269 config.GetInitialFlowControlWindowToSend()); |
| 270 } |
| 271 |
246 } // namespace | 272 } // namespace |
247 } // namespace test | 273 } // namespace test |
248 } // namespace net | 274 } // namespace net |
OLD | NEW |