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 <stddef.h> | 5 #include <stddef.h> |
6 #include <string> | 6 #include <string> |
7 #include <sys/epoll.h> | 7 #include <sys/epoll.h> |
8 #include <vector> | 8 #include <vector> |
9 | 9 |
10 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
11 #include "base/memory/scoped_ptr.h" | 11 #include "base/memory/scoped_ptr.h" |
12 #include "base/memory/singleton.h" | 12 #include "base/memory/singleton.h" |
13 #include "base/strings/string_number_conversions.h" | 13 #include "base/strings/string_number_conversions.h" |
14 #include "base/synchronization/waitable_event.h" | 14 #include "base/synchronization/waitable_event.h" |
15 #include "net/base/ip_endpoint.h" | 15 #include "net/base/ip_endpoint.h" |
16 #include "net/quic/congestion_control/tcp_cubic_sender.h" | 16 #include "net/quic/congestion_control/tcp_cubic_sender.h" |
17 #include "net/quic/crypto/aes_128_gcm_12_encrypter.h" | 17 #include "net/quic/crypto/aes_128_gcm_12_encrypter.h" |
18 #include "net/quic/crypto/null_encrypter.h" | 18 #include "net/quic/crypto/null_encrypter.h" |
19 #include "net/quic/quic_framer.h" | 19 #include "net/quic/quic_framer.h" |
20 #include "net/quic/quic_packet_creator.h" | 20 #include "net/quic/quic_packet_creator.h" |
21 #include "net/quic/quic_protocol.h" | 21 #include "net/quic/quic_protocol.h" |
22 #include "net/quic/quic_sent_packet_manager.h" | 22 #include "net/quic/quic_sent_packet_manager.h" |
| 23 #include "net/quic/quic_session_key.h" |
23 #include "net/quic/test_tools/quic_connection_peer.h" | 24 #include "net/quic/test_tools/quic_connection_peer.h" |
24 #include "net/quic/test_tools/quic_session_peer.h" | 25 #include "net/quic/test_tools/quic_session_peer.h" |
25 #include "net/quic/test_tools/quic_test_utils.h" | 26 #include "net/quic/test_tools/quic_test_utils.h" |
26 #include "net/quic/test_tools/reliable_quic_stream_peer.h" | 27 #include "net/quic/test_tools/reliable_quic_stream_peer.h" |
27 #include "net/test/gtest_util.h" | 28 #include "net/test/gtest_util.h" |
28 #include "net/tools/quic/quic_epoll_connection_helper.h" | 29 #include "net/tools/quic/quic_epoll_connection_helper.h" |
29 #include "net/tools/quic/quic_in_memory_cache.h" | 30 #include "net/tools/quic/quic_in_memory_cache.h" |
30 #include "net/tools/quic/quic_packet_writer_wrapper.h" | 31 #include "net/tools/quic/quic_packet_writer_wrapper.h" |
31 #include "net/tools/quic/quic_server.h" | 32 #include "net/tools/quic/quic_server.h" |
32 #include "net/tools/quic/quic_socket_utils.h" | 33 #include "net/tools/quic/quic_socket_utils.h" |
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
142 EpollEvent event(EPOLLOUT, false); | 143 EpollEvent event(EPOLLOUT, false); |
143 client_->OnEvent(client_->fd(), &event); | 144 client_->OnEvent(client_->fd(), &event); |
144 } | 145 } |
145 private: | 146 private: |
146 QuicClient* client_; | 147 QuicClient* client_; |
147 }; | 148 }; |
148 | 149 |
149 class EndToEndTest : public ::testing::TestWithParam<TestParams> { | 150 class EndToEndTest : public ::testing::TestWithParam<TestParams> { |
150 protected: | 151 protected: |
151 EndToEndTest() | 152 EndToEndTest() |
152 : server_hostname_("example.com"), | 153 : server_started_(false), |
153 server_started_(false), | |
154 strike_register_no_startup_period_(false) { | 154 strike_register_no_startup_period_(false) { |
155 net::IPAddressNumber ip; | 155 net::IPAddressNumber ip; |
156 CHECK(net::ParseIPLiteralToNumber("127.0.0.1", &ip)); | 156 CHECK(net::ParseIPLiteralToNumber("127.0.0.1", &ip)); |
157 server_address_ = IPEndPoint(ip, 0); | 157 uint port = 0; |
| 158 server_address_ = IPEndPoint(ip, port); |
| 159 server_key_ = QuicSessionKey("example.com", port, false); |
158 | 160 |
159 client_supported_versions_ = GetParam().client_supported_versions; | 161 client_supported_versions_ = GetParam().client_supported_versions; |
160 server_supported_versions_ = GetParam().server_supported_versions; | 162 server_supported_versions_ = GetParam().server_supported_versions; |
161 negotiated_version_ = GetParam().negotiated_version; | 163 negotiated_version_ = GetParam().negotiated_version; |
162 FLAGS_enable_quic_pacing = GetParam().use_pacing; | 164 FLAGS_enable_quic_pacing = GetParam().use_pacing; |
163 VLOG(1) << "Using Configuration: " << GetParam(); | 165 VLOG(1) << "Using Configuration: " << GetParam(); |
164 | 166 |
165 client_config_.SetDefaults(); | 167 client_config_.SetDefaults(); |
166 server_config_.SetDefaults(); | 168 server_config_.SetDefaults(); |
167 server_config_.set_initial_round_trip_time_us(kMaxInitialRoundTripTimeUs, | 169 server_config_.set_initial_round_trip_time_us(kMaxInitialRoundTripTimeUs, |
168 0); | 170 0); |
169 | 171 |
170 QuicInMemoryCachePeer::ResetForTests(); | 172 QuicInMemoryCachePeer::ResetForTests(); |
171 AddToCache("GET", "https://www.google.com/foo", | 173 AddToCache("GET", "https://www.google.com/foo", |
172 "HTTP/1.1", "200", "OK", kFooResponseBody); | 174 "HTTP/1.1", "200", "OK", kFooResponseBody); |
173 AddToCache("GET", "https://www.google.com/bar", | 175 AddToCache("GET", "https://www.google.com/bar", |
174 "HTTP/1.1", "200", "OK", kBarResponseBody); | 176 "HTTP/1.1", "200", "OK", kBarResponseBody); |
175 } | 177 } |
176 | 178 |
177 virtual ~EndToEndTest() { | 179 virtual ~EndToEndTest() { |
178 // TODO(rtenneti): port RecycleUnusedPort if needed. | 180 // TODO(rtenneti): port RecycleUnusedPort if needed. |
179 // RecycleUnusedPort(server_address_.port()); | 181 // RecycleUnusedPort(server_address_.port()); |
180 QuicInMemoryCachePeer::ResetForTests(); | 182 QuicInMemoryCachePeer::ResetForTests(); |
181 } | 183 } |
182 | 184 |
183 QuicTestClient* CreateQuicClient(QuicPacketWriterWrapper* writer) { | 185 QuicTestClient* CreateQuicClient(QuicPacketWriterWrapper* writer) { |
184 QuicTestClient* client = new QuicTestClient(server_address_, | 186 QuicTestClient* client = new QuicTestClient(server_address_, |
185 server_hostname_, | 187 server_key_, |
186 false, // not secure | 188 false, // not secure |
187 client_config_, | 189 client_config_, |
188 client_supported_versions_); | 190 client_supported_versions_); |
189 client->UseWriter(writer); | 191 client->UseWriter(writer); |
190 client->Connect(); | 192 client->Connect(); |
191 return client; | 193 return client; |
192 } | 194 } |
193 | 195 |
194 bool Initialize() { | 196 bool Initialize() { |
195 // Start the server first, because CreateQuicClient() attempts | 197 // Start the server first, because CreateQuicClient() attempts |
(...skipping 20 matching lines...) Expand all Loading... |
216 StopServer(); | 218 StopServer(); |
217 } | 219 } |
218 | 220 |
219 void StartServer() { | 221 void StartServer() { |
220 server_thread_.reset(new ServerThread(server_address_, server_config_, | 222 server_thread_.reset(new ServerThread(server_address_, server_config_, |
221 server_supported_versions_, | 223 server_supported_versions_, |
222 strike_register_no_startup_period_)); | 224 strike_register_no_startup_period_)); |
223 server_thread_->Initialize(); | 225 server_thread_->Initialize(); |
224 server_address_ = IPEndPoint(server_address_.address(), | 226 server_address_ = IPEndPoint(server_address_.address(), |
225 server_thread_->GetPort()); | 227 server_thread_->GetPort()); |
| 228 server_key_ = QuicSessionKey(server_key_.host(), |
| 229 server_thread_->GetPort(), false); |
| 230 |
226 QuicDispatcher* dispatcher = | 231 QuicDispatcher* dispatcher = |
227 QuicServerPeer::GetDispatcher(server_thread_->server()); | 232 QuicServerPeer::GetDispatcher(server_thread_->server()); |
228 QuicDispatcherPeer::UseWriter(dispatcher, server_writer_); | 233 QuicDispatcherPeer::UseWriter(dispatcher, server_writer_); |
229 server_writer_->Initialize( | 234 server_writer_->Initialize( |
230 QuicDispatcherPeer::GetHelper(dispatcher), | 235 QuicDispatcherPeer::GetHelper(dispatcher), |
231 new ServerDelegate(dispatcher)); | 236 new ServerDelegate(dispatcher)); |
232 server_thread_->Start(); | 237 server_thread_->Start(); |
233 server_started_ = true; | 238 server_started_ = true; |
234 } | 239 } |
235 | 240 |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
269 } | 274 } |
270 | 275 |
271 void SetReorderPercentage(int32 reorder) { | 276 void SetReorderPercentage(int32 reorder) { |
272 // TODO(rtenneti): enable when we can do random packet reorder tests in | 277 // TODO(rtenneti): enable when we can do random packet reorder tests in |
273 // chrome's tree. | 278 // chrome's tree. |
274 // client_writer_->set_fake_reorder_percentage(reorder); | 279 // client_writer_->set_fake_reorder_percentage(reorder); |
275 // server_writer_->set_fake_reorder_percentage(reorder); | 280 // server_writer_->set_fake_reorder_percentage(reorder); |
276 } | 281 } |
277 | 282 |
278 IPEndPoint server_address_; | 283 IPEndPoint server_address_; |
279 string server_hostname_; | 284 QuicSessionKey server_key_; |
280 scoped_ptr<ServerThread> server_thread_; | 285 scoped_ptr<ServerThread> server_thread_; |
281 scoped_ptr<QuicTestClient> client_; | 286 scoped_ptr<QuicTestClient> client_; |
282 PacketDroppingTestWriter* client_writer_; | 287 PacketDroppingTestWriter* client_writer_; |
283 PacketDroppingTestWriter* server_writer_; | 288 PacketDroppingTestWriter* server_writer_; |
284 bool server_started_; | 289 bool server_started_; |
285 QuicConfig client_config_; | 290 QuicConfig client_config_; |
286 QuicConfig server_config_; | 291 QuicConfig server_config_; |
287 QuicVersionVector client_supported_versions_; | 292 QuicVersionVector client_supported_versions_; |
288 QuicVersionVector server_supported_versions_; | 293 QuicVersionVector server_supported_versions_; |
289 QuicVersion negotiated_version_; | 294 QuicVersion negotiated_version_; |
(...skipping 572 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
862 client_->SendSynchronousRequest("/bar"); | 867 client_->SendSynchronousRequest("/bar"); |
863 | 868 |
864 EXPECT_EQ(QUIC_STREAM_CONNECTION_ERROR, client_->stream_error()); | 869 EXPECT_EQ(QUIC_STREAM_CONNECTION_ERROR, client_->stream_error()); |
865 EXPECT_EQ(QUIC_ERROR_MIGRATING_ADDRESS, client_->connection_error()); | 870 EXPECT_EQ(QUIC_ERROR_MIGRATING_ADDRESS, client_->connection_error()); |
866 } | 871 } |
867 | 872 |
868 } // namespace | 873 } // namespace |
869 } // namespace test | 874 } // namespace test |
870 } // namespace tools | 875 } // namespace tools |
871 } // namespace net | 876 } // namespace net |
OLD | NEW |