| 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_protocol.h" | 9 #include "net/quic/quic_protocol.h" |
| 10 #include "net/quic/quic_sent_packet_manager.h" | 10 #include "net/quic/quic_sent_packet_manager.h" |
| (...skipping 17 matching lines...) Expand all Loading... |
| 28 | 28 |
| 29 QuicConfig config_; | 29 QuicConfig config_; |
| 30 }; | 30 }; |
| 31 | 31 |
| 32 TEST_F(QuicConfigTest, ToHandshakeMessage) { | 32 TEST_F(QuicConfigTest, ToHandshakeMessage) { |
| 33 FLAGS_enable_quic_pacing = false; | 33 FLAGS_enable_quic_pacing = false; |
| 34 config_.SetDefaults(); | 34 config_.SetDefaults(); |
| 35 config_.set_idle_connection_state_lifetime(QuicTime::Delta::FromSeconds(5), | 35 config_.set_idle_connection_state_lifetime(QuicTime::Delta::FromSeconds(5), |
| 36 QuicTime::Delta::FromSeconds(2)); | 36 QuicTime::Delta::FromSeconds(2)); |
| 37 config_.set_max_streams_per_connection(4, 2); | 37 config_.set_max_streams_per_connection(4, 2); |
| 38 config_.set_peer_initial_flow_control_window_bytes(6); |
| 38 CryptoHandshakeMessage msg; | 39 CryptoHandshakeMessage msg; |
| 39 config_.ToHandshakeMessage(&msg); | 40 config_.ToHandshakeMessage(&msg); |
| 40 | 41 |
| 41 uint32 value; | 42 uint32 value; |
| 42 QuicErrorCode error = msg.GetUint32(kICSL, &value); | 43 QuicErrorCode error = msg.GetUint32(kICSL, &value); |
| 43 EXPECT_EQ(QUIC_NO_ERROR, error); | 44 EXPECT_EQ(QUIC_NO_ERROR, error); |
| 44 EXPECT_EQ(5u, value); | 45 EXPECT_EQ(5u, value); |
| 45 | 46 |
| 46 error = msg.GetUint32(kMSPC, &value); | 47 error = msg.GetUint32(kMSPC, &value); |
| 47 EXPECT_EQ(QUIC_NO_ERROR, error); | 48 EXPECT_EQ(QUIC_NO_ERROR, error); |
| 48 EXPECT_EQ(4u, value); | 49 EXPECT_EQ(4u, value); |
| 49 | 50 |
| 51 error = msg.GetUint32(kIFCW, &value); |
| 52 EXPECT_EQ(QUIC_NO_ERROR, error); |
| 53 EXPECT_EQ(6u, value); |
| 54 |
| 50 const QuicTag* out; | 55 const QuicTag* out; |
| 51 size_t out_len; | 56 size_t out_len; |
| 52 error = msg.GetTaglist(kCGST, &out, &out_len); | 57 error = msg.GetTaglist(kCGST, &out, &out_len); |
| 53 EXPECT_EQ(1u, out_len); | 58 EXPECT_EQ(1u, out_len); |
| 54 EXPECT_EQ(kQBIC, *out); | 59 EXPECT_EQ(kQBIC, *out); |
| 55 } | 60 } |
| 56 | 61 |
| 57 TEST_F(QuicConfigTest, ToHandshakeMessageWithPacing) { | 62 TEST_F(QuicConfigTest, ToHandshakeMessageWithPacing) { |
| 58 ValueRestore<bool> old_flag(&FLAGS_enable_quic_pacing, true); | 63 ValueRestore<bool> old_flag(&FLAGS_enable_quic_pacing, true); |
| 59 | 64 |
| (...skipping 16 matching lines...) Expand all Loading... |
| 76 cgst.push_back(kQBIC); | 81 cgst.push_back(kQBIC); |
| 77 client_config.set_congestion_control(cgst, kQBIC); | 82 client_config.set_congestion_control(cgst, kQBIC); |
| 78 client_config.set_idle_connection_state_lifetime( | 83 client_config.set_idle_connection_state_lifetime( |
| 79 QuicTime::Delta::FromSeconds(2 * kDefaultTimeoutSecs), | 84 QuicTime::Delta::FromSeconds(2 * kDefaultTimeoutSecs), |
| 80 QuicTime::Delta::FromSeconds(kDefaultTimeoutSecs)); | 85 QuicTime::Delta::FromSeconds(kDefaultTimeoutSecs)); |
| 81 client_config.set_max_streams_per_connection( | 86 client_config.set_max_streams_per_connection( |
| 82 2 * kDefaultMaxStreamsPerConnection, kDefaultMaxStreamsPerConnection); | 87 2 * kDefaultMaxStreamsPerConnection, kDefaultMaxStreamsPerConnection); |
| 83 client_config.set_initial_round_trip_time_us( | 88 client_config.set_initial_round_trip_time_us( |
| 84 10 * base::Time::kMicrosecondsPerMillisecond, | 89 10 * base::Time::kMicrosecondsPerMillisecond, |
| 85 10 * base::Time::kMicrosecondsPerMillisecond); | 90 10 * base::Time::kMicrosecondsPerMillisecond); |
| 91 const uint32 kFlowControlWindow = 1234; |
| 92 client_config.set_peer_initial_flow_control_window_bytes(kFlowControlWindow); |
| 86 | 93 |
| 87 CryptoHandshakeMessage msg; | 94 CryptoHandshakeMessage msg; |
| 88 client_config.ToHandshakeMessage(&msg); | 95 client_config.ToHandshakeMessage(&msg); |
| 89 string error_details; | 96 string error_details; |
| 90 const QuicErrorCode error = config_.ProcessClientHello(msg, &error_details); | 97 const QuicErrorCode error = config_.ProcessClientHello(msg, &error_details); |
| 91 EXPECT_EQ(QUIC_NO_ERROR, error); | 98 EXPECT_EQ(QUIC_NO_ERROR, error); |
| 92 EXPECT_TRUE(config_.negotiated()); | 99 EXPECT_TRUE(config_.negotiated()); |
| 93 EXPECT_EQ(kQBIC, config_.congestion_control()); | 100 EXPECT_EQ(kQBIC, config_.congestion_control()); |
| 94 EXPECT_EQ(QuicTime::Delta::FromSeconds(kDefaultTimeoutSecs), | 101 EXPECT_EQ(QuicTime::Delta::FromSeconds(kDefaultTimeoutSecs), |
| 95 config_.idle_connection_state_lifetime()); | 102 config_.idle_connection_state_lifetime()); |
| 96 EXPECT_EQ(kDefaultMaxStreamsPerConnection, | 103 EXPECT_EQ(kDefaultMaxStreamsPerConnection, |
| 97 config_.max_streams_per_connection()); | 104 config_.max_streams_per_connection()); |
| 98 EXPECT_EQ(QuicTime::Delta::FromSeconds(0), config_.keepalive_timeout()); | 105 EXPECT_EQ(QuicTime::Delta::FromSeconds(0), config_.keepalive_timeout()); |
| 99 EXPECT_EQ(10 * base::Time::kMicrosecondsPerMillisecond, | 106 EXPECT_EQ(10 * base::Time::kMicrosecondsPerMillisecond, |
| 100 config_.initial_round_trip_time_us()); | 107 config_.initial_round_trip_time_us()); |
| 108 EXPECT_EQ(kFlowControlWindow, |
| 109 config_.peer_initial_flow_control_window_bytes()); |
| 101 } | 110 } |
| 102 | 111 |
| 103 TEST_F(QuicConfigTest, ProcessServerHello) { | 112 TEST_F(QuicConfigTest, ProcessServerHello) { |
| 104 QuicConfig server_config; | 113 QuicConfig server_config; |
| 105 QuicTagVector cgst; | 114 QuicTagVector cgst; |
| 106 cgst.push_back(kQBIC); | 115 cgst.push_back(kQBIC); |
| 107 server_config.set_congestion_control(cgst, kQBIC); | 116 server_config.set_congestion_control(cgst, kQBIC); |
| 108 server_config.set_idle_connection_state_lifetime( | 117 server_config.set_idle_connection_state_lifetime( |
| 109 QuicTime::Delta::FromSeconds(kDefaultTimeoutSecs / 2), | 118 QuicTime::Delta::FromSeconds(kDefaultTimeoutSecs / 2), |
| 110 QuicTime::Delta::FromSeconds(kDefaultTimeoutSecs / 2)); | 119 QuicTime::Delta::FromSeconds(kDefaultTimeoutSecs / 2)); |
| 111 server_config.set_max_streams_per_connection( | 120 server_config.set_max_streams_per_connection( |
| 112 kDefaultMaxStreamsPerConnection / 2, | 121 kDefaultMaxStreamsPerConnection / 2, |
| 113 kDefaultMaxStreamsPerConnection / 2); | 122 kDefaultMaxStreamsPerConnection / 2); |
| 114 server_config.set_server_initial_congestion_window(kDefaultInitialWindow / 2, | 123 server_config.set_server_initial_congestion_window(kDefaultInitialWindow / 2, |
| 115 kDefaultInitialWindow / 2); | 124 kDefaultInitialWindow / 2); |
| 116 server_config.set_initial_round_trip_time_us( | 125 server_config.set_initial_round_trip_time_us( |
| 117 10 * base::Time::kMicrosecondsPerMillisecond, | 126 10 * base::Time::kMicrosecondsPerMillisecond, |
| 118 10 * base::Time::kMicrosecondsPerMillisecond); | 127 10 * base::Time::kMicrosecondsPerMillisecond); |
| 128 const uint32 kFlowControlWindow = 1234; |
| 129 server_config.set_peer_initial_flow_control_window_bytes(kFlowControlWindow); |
| 119 | 130 |
| 120 CryptoHandshakeMessage msg; | 131 CryptoHandshakeMessage msg; |
| 121 server_config.ToHandshakeMessage(&msg); | 132 server_config.ToHandshakeMessage(&msg); |
| 122 string error_details; | 133 string error_details; |
| 123 const QuicErrorCode error = config_.ProcessServerHello(msg, &error_details); | 134 const QuicErrorCode error = config_.ProcessServerHello(msg, &error_details); |
| 124 EXPECT_EQ(QUIC_NO_ERROR, error); | 135 EXPECT_EQ(QUIC_NO_ERROR, error); |
| 125 EXPECT_TRUE(config_.negotiated()); | 136 EXPECT_TRUE(config_.negotiated()); |
| 126 EXPECT_EQ(kQBIC, config_.congestion_control()); | 137 EXPECT_EQ(kQBIC, config_.congestion_control()); |
| 127 EXPECT_EQ(QuicTime::Delta::FromSeconds(kDefaultTimeoutSecs / 2), | 138 EXPECT_EQ(QuicTime::Delta::FromSeconds(kDefaultTimeoutSecs / 2), |
| 128 config_.idle_connection_state_lifetime()); | 139 config_.idle_connection_state_lifetime()); |
| 129 EXPECT_EQ(kDefaultMaxStreamsPerConnection / 2, | 140 EXPECT_EQ(kDefaultMaxStreamsPerConnection / 2, |
| 130 config_.max_streams_per_connection()); | 141 config_.max_streams_per_connection()); |
| 131 EXPECT_EQ(kDefaultInitialWindow / 2, | 142 EXPECT_EQ(kDefaultInitialWindow / 2, |
| 132 config_.server_initial_congestion_window()); | 143 config_.server_initial_congestion_window()); |
| 133 EXPECT_EQ(QuicTime::Delta::FromSeconds(0), config_.keepalive_timeout()); | 144 EXPECT_EQ(QuicTime::Delta::FromSeconds(0), config_.keepalive_timeout()); |
| 134 EXPECT_EQ(10 * base::Time::kMicrosecondsPerMillisecond, | 145 EXPECT_EQ(10 * base::Time::kMicrosecondsPerMillisecond, |
| 135 config_.initial_round_trip_time_us()); | 146 config_.initial_round_trip_time_us()); |
| 147 EXPECT_EQ(kFlowControlWindow, |
| 148 config_.peer_initial_flow_control_window_bytes()); |
| 149 } |
| 150 |
| 151 TEST_F(QuicConfigTest, MissingOptionalValuesInCHLO) { |
| 152 CryptoHandshakeMessage msg; |
| 153 msg.SetValue(kICSL, 1); |
| 154 msg.SetVector(kCGST, QuicTagVector(1, kQBIC)); |
| 155 |
| 156 // Set all REQUIRED tags. |
| 157 msg.SetValue(kICSL, 1); |
| 158 msg.SetVector(kCGST, QuicTagVector(1, kQBIC)); |
| 159 msg.SetValue(kMSPC, 1); |
| 160 |
| 161 // No error, as rest are optional. |
| 162 string error_details; |
| 163 const QuicErrorCode error = config_.ProcessClientHello(msg, &error_details); |
| 164 EXPECT_EQ(QUIC_NO_ERROR, error); |
| 165 |
| 166 EXPECT_EQ(0u, config_.peer_initial_flow_control_window_bytes()); |
| 167 } |
| 168 |
| 169 TEST_F(QuicConfigTest, MissingOptionalValuesInSHLO) { |
| 170 CryptoHandshakeMessage msg; |
| 171 |
| 172 // Set all REQUIRED tags. |
| 173 msg.SetValue(kICSL, 1); |
| 174 msg.SetVector(kCGST, QuicTagVector(1, kQBIC)); |
| 175 msg.SetValue(kMSPC, 1); |
| 176 |
| 177 // No error, as rest are optional. |
| 178 string error_details; |
| 179 const QuicErrorCode error = config_.ProcessServerHello(msg, &error_details); |
| 180 EXPECT_EQ(QUIC_NO_ERROR, error); |
| 181 |
| 182 EXPECT_EQ(0u, config_.peer_initial_flow_control_window_bytes()); |
| 136 } | 183 } |
| 137 | 184 |
| 138 TEST_F(QuicConfigTest, MissingValueInCHLO) { | 185 TEST_F(QuicConfigTest, MissingValueInCHLO) { |
| 139 CryptoHandshakeMessage msg; | 186 CryptoHandshakeMessage msg; |
| 140 msg.SetValue(kICSL, 1); | 187 msg.SetValue(kICSL, 1); |
| 141 msg.SetVector(kCGST, QuicTagVector(1, kQBIC)); | 188 msg.SetVector(kCGST, QuicTagVector(1, kQBIC)); |
| 142 // Missing kMSPC. KATO is optional. | 189 // Missing kMSPC. KATO is optional. |
| 143 string error_details; | 190 string error_details; |
| 144 const QuicErrorCode error = config_.ProcessClientHello(msg, &error_details); | 191 const QuicErrorCode error = config_.ProcessClientHello(msg, &error_details); |
| 145 EXPECT_EQ(QUIC_CRYPTO_MESSAGE_PARAMETER_NOT_FOUND, error); | 192 EXPECT_EQ(QUIC_CRYPTO_MESSAGE_PARAMETER_NOT_FOUND, error); |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 193 string error_details; | 240 string error_details; |
| 194 server_config.ToHandshakeMessage(&msg); | 241 server_config.ToHandshakeMessage(&msg); |
| 195 const QuicErrorCode error = config_.ProcessClientHello(msg, &error_details); | 242 const QuicErrorCode error = config_.ProcessClientHello(msg, &error_details); |
| 196 LOG(INFO) << QuicUtils::ErrorToString(error); | 243 LOG(INFO) << QuicUtils::ErrorToString(error); |
| 197 EXPECT_EQ(QUIC_CRYPTO_MESSAGE_PARAMETER_NO_OVERLAP, error); | 244 EXPECT_EQ(QUIC_CRYPTO_MESSAGE_PARAMETER_NO_OVERLAP, error); |
| 198 } | 245 } |
| 199 | 246 |
| 200 } // namespace | 247 } // namespace |
| 201 } // namespace test | 248 } // namespace test |
| 202 } // namespace net | 249 } // namespace net |
| OLD | NEW |