| 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" |
| (...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 175 if (negotiated_version_ >= QUIC_VERSION_19) { | 175 if (negotiated_version_ >= QUIC_VERSION_19) { |
| 176 FLAGS_enable_quic_connection_flow_control_2 = true; | 176 FLAGS_enable_quic_connection_flow_control_2 = true; |
| 177 } | 177 } |
| 178 VLOG(1) << "Using Configuration: " << GetParam(); | 178 VLOG(1) << "Using Configuration: " << GetParam(); |
| 179 | 179 |
| 180 client_config_.SetDefaults(); | 180 client_config_.SetDefaults(); |
| 181 server_config_.SetDefaults(); | 181 server_config_.SetDefaults(); |
| 182 | 182 |
| 183 // Use different flow control windows for client/server. | 183 // Use different flow control windows for client/server. |
| 184 client_config_.SetInitialFlowControlWindowToSend( | 184 client_config_.SetInitialFlowControlWindowToSend( |
| 185 2 * kInitialFlowControlWindowForTest); | 185 2 * kInitialSessionFlowControlWindowForTest); |
| 186 client_config_.SetInitialStreamFlowControlWindowToSend( |
| 187 2 * kInitialStreamFlowControlWindowForTest); |
| 188 client_config_.SetInitialSessionFlowControlWindowToSend( |
| 189 2 * kInitialSessionFlowControlWindowForTest); |
| 186 server_config_.SetInitialFlowControlWindowToSend( | 190 server_config_.SetInitialFlowControlWindowToSend( |
| 187 3 * kInitialFlowControlWindowForTest); | 191 3 * kInitialSessionFlowControlWindowForTest); |
| 192 server_config_.SetInitialStreamFlowControlWindowToSend( |
| 193 3 * kInitialStreamFlowControlWindowForTest); |
| 194 server_config_.SetInitialSessionFlowControlWindowToSend( |
| 195 3 * kInitialSessionFlowControlWindowForTest); |
| 188 | 196 |
| 189 QuicInMemoryCachePeer::ResetForTests(); | 197 QuicInMemoryCachePeer::ResetForTests(); |
| 190 AddToCache("GET", "https://www.google.com/foo", | 198 AddToCache("GET", "https://www.google.com/foo", |
| 191 "HTTP/1.1", "200", "OK", kFooResponseBody); | 199 "HTTP/1.1", "200", "OK", kFooResponseBody); |
| 192 AddToCache("GET", "https://www.google.com/bar", | 200 AddToCache("GET", "https://www.google.com/bar", |
| 193 "HTTP/1.1", "200", "OK", kBarResponseBody); | 201 "HTTP/1.1", "200", "OK", kBarResponseBody); |
| 194 } | 202 } |
| 195 | 203 |
| 196 virtual ~EndToEndTest() { | 204 virtual ~EndToEndTest() { |
| 197 // TODO(rtenneti): port RecycleUnusedPort if needed. | 205 // TODO(rtenneti): port RecycleUnusedPort if needed. |
| (...skipping 12 matching lines...) Expand all Loading... |
| 210 client->Connect(); | 218 client->Connect(); |
| 211 return client; | 219 return client; |
| 212 } | 220 } |
| 213 | 221 |
| 214 void set_client_initial_flow_control_receive_window(uint32 window) { | 222 void set_client_initial_flow_control_receive_window(uint32 window) { |
| 215 CHECK(client_.get() == NULL); | 223 CHECK(client_.get() == NULL); |
| 216 DVLOG(1) << "Setting client initial flow control window: " << window; | 224 DVLOG(1) << "Setting client initial flow control window: " << window; |
| 217 client_config_.SetInitialFlowControlWindowToSend(window); | 225 client_config_.SetInitialFlowControlWindowToSend(window); |
| 218 } | 226 } |
| 219 | 227 |
| 228 void set_client_initial_stream_flow_control_receive_window(uint32 window) { |
| 229 CHECK(client_.get() == NULL); |
| 230 DLOG(INFO) << "Setting client initial stream flow control window: " |
| 231 << window; |
| 232 client_config_.SetInitialStreamFlowControlWindowToSend(window); |
| 233 } |
| 234 |
| 235 void set_client_initial_session_flow_control_receive_window(uint32 window) { |
| 236 CHECK(client_.get() == NULL); |
| 237 DLOG(INFO) << "Setting client initial session flow control window: " |
| 238 << window; |
| 239 client_config_.SetInitialSessionFlowControlWindowToSend(window); |
| 240 } |
| 241 |
| 220 void set_server_initial_flow_control_receive_window(uint32 window) { | 242 void set_server_initial_flow_control_receive_window(uint32 window) { |
| 221 CHECK(server_thread_.get() == NULL); | 243 CHECK(server_thread_.get() == NULL); |
| 222 DVLOG(1) << "Setting server initial flow control window: " << window; | 244 DVLOG(1) << "Setting server initial flow control window: " << window; |
| 223 server_config_.SetInitialFlowControlWindowToSend(window); | 245 server_config_.SetInitialFlowControlWindowToSend(window); |
| 224 } | 246 } |
| 225 | 247 |
| 248 void set_server_initial_stream_flow_control_receive_window(uint32 window) { |
| 249 CHECK(server_thread_.get() == NULL); |
| 250 DLOG(INFO) << "Setting server initial stream flow control window: " |
| 251 << window; |
| 252 server_config_.SetInitialStreamFlowControlWindowToSend(window); |
| 253 } |
| 254 |
| 255 void set_server_initial_session_flow_control_receive_window(uint32 window) { |
| 256 CHECK(server_thread_.get() == NULL); |
| 257 DLOG(INFO) << "Setting server initial session flow control window: " |
| 258 << window; |
| 259 server_config_.SetInitialSessionFlowControlWindowToSend(window); |
| 260 } |
| 261 |
| 226 bool Initialize() { | 262 bool Initialize() { |
| 227 // Start the server first, because CreateQuicClient() attempts | 263 // Start the server first, because CreateQuicClient() attempts |
| 228 // to connect to the server. | 264 // to connect to the server. |
| 229 StartServer(); | 265 StartServer(); |
| 230 client_.reset(CreateQuicClient(client_writer_)); | 266 client_.reset(CreateQuicClient(client_writer_)); |
| 231 static EpollEvent event(EPOLLOUT, false); | 267 static EpollEvent event(EPOLLOUT, false); |
| 232 client_writer_->Initialize( | 268 client_writer_->Initialize( |
| 233 reinterpret_cast<QuicEpollConnectionHelper*>( | 269 reinterpret_cast<QuicEpollConnectionHelper*>( |
| 234 QuicConnectionPeer::GetHelper( | 270 QuicConnectionPeer::GetHelper( |
| 235 client_->client()->session()->connection())), | 271 client_->client()->session()->connection())), |
| (...skipping 822 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1058 | 1094 |
| 1059 ASSERT_TRUE(Initialize()); | 1095 ASSERT_TRUE(Initialize()); |
| 1060 | 1096 |
| 1061 EXPECT_EQ(kFooResponseBody, client_->SendSynchronousRequest("/foo")); | 1097 EXPECT_EQ(kFooResponseBody, client_->SendSynchronousRequest("/foo")); |
| 1062 EXPECT_EQ(200u, client_->response_headers()->parsed_response_code()); | 1098 EXPECT_EQ(200u, client_->response_headers()->parsed_response_code()); |
| 1063 | 1099 |
| 1064 // Store the client address which was used to send the first request. | 1100 // Store the client address which was used to send the first request. |
| 1065 IPEndPoint old_address = client_->client()->client_address(); | 1101 IPEndPoint old_address = client_->client()->client_address(); |
| 1066 | 1102 |
| 1067 // Stop listening on the old FD. | 1103 // Stop listening on the old FD. |
| 1068 EpollServer* eps = client_->client()->epoll_server(); | 1104 EpollServer* eps = client_->epoll_server(); |
| 1069 int old_fd = client_->client()->fd(); | 1105 int old_fd = client_->client()->fd(); |
| 1070 eps->UnregisterFD(old_fd); | 1106 eps->UnregisterFD(old_fd); |
| 1071 // Create a new socket before closing the old one, which will result in a new | 1107 // Create a new socket before closing the old one, which will result in a new |
| 1072 // ephemeral port. | 1108 // ephemeral port. |
| 1073 QuicClientPeer::CreateUDPSocket(client_->client()); | 1109 QuicClientPeer::CreateUDPSocket(client_->client()); |
| 1074 close(old_fd); | 1110 close(old_fd); |
| 1075 | 1111 |
| 1076 // The packet writer needs to be updated to use the new FD. | 1112 // The packet writer needs to be updated to use the new FD. |
| 1077 client_->client()->CreateQuicPacketWriter(); | 1113 client_->client()->CreateQuicPacketWriter(); |
| 1078 | 1114 |
| (...skipping 17 matching lines...) Expand all Loading... |
| 1096 // Send a second request, using the new FD. | 1132 // Send a second request, using the new FD. |
| 1097 EXPECT_EQ(kBarResponseBody, client_->SendSynchronousRequest("/bar")); | 1133 EXPECT_EQ(kBarResponseBody, client_->SendSynchronousRequest("/bar")); |
| 1098 EXPECT_EQ(200u, client_->response_headers()->parsed_response_code()); | 1134 EXPECT_EQ(200u, client_->response_headers()->parsed_response_code()); |
| 1099 | 1135 |
| 1100 // Verify that the client's ephemeral port is different. | 1136 // Verify that the client's ephemeral port is different. |
| 1101 IPEndPoint new_address = client_->client()->client_address(); | 1137 IPEndPoint new_address = client_->client()->client_address(); |
| 1102 EXPECT_EQ(old_address.address(), new_address.address()); | 1138 EXPECT_EQ(old_address.address(), new_address.address()); |
| 1103 EXPECT_NE(old_address.port(), new_address.port()); | 1139 EXPECT_NE(old_address.port(), new_address.port()); |
| 1104 } | 1140 } |
| 1105 | 1141 |
| 1106 TEST_P(EndToEndTest, DifferentFlowControlWindows) { | 1142 |
| 1143 TEST_P(EndToEndTest, DifferentFlowControlWindowsQ019) { |
| 1144 // TODO(rjshade): Remove this test when removing QUIC_VERSION_19. |
| 1107 // Client and server can set different initial flow control receive windows. | 1145 // Client and server can set different initial flow control receive windows. |
| 1108 // These are sent in CHLO/SHLO. Tests that these values are exchanged properly | 1146 // These are sent in CHLO/SHLO. Tests that these values are exchanged properly |
| 1109 // in the crypto handshake. | 1147 // in the crypto handshake. |
| 1110 | 1148 |
| 1111 const uint32 kClientIFCW = 123456; | 1149 const uint32 kClientIFCW = 123456; |
| 1112 set_client_initial_flow_control_receive_window(kClientIFCW); | 1150 set_client_initial_flow_control_receive_window(kClientIFCW); |
| 1113 | 1151 |
| 1114 const uint32 kServerIFCW = 654321; | 1152 const uint32 kServerIFCW = 654321; |
| 1115 set_server_initial_flow_control_receive_window(kServerIFCW); | 1153 set_server_initial_flow_control_receive_window(kServerIFCW); |
| 1116 | 1154 |
| 1117 ASSERT_TRUE(Initialize()); | 1155 ASSERT_TRUE(Initialize()); |
| 1156 if (negotiated_version_ > QUIC_VERSION_19) { |
| 1157 return; |
| 1158 } |
| 1118 | 1159 |
| 1119 // Values are exchanged during crypto handshake, so wait for that to finish. | 1160 // Values are exchanged during crypto handshake, so wait for that to finish. |
| 1120 client_->client()->WaitForCryptoHandshakeConfirmed(); | 1161 client_->client()->WaitForCryptoHandshakeConfirmed(); |
| 1121 server_thread_->WaitForCryptoHandshakeConfirmed(); | 1162 server_thread_->WaitForCryptoHandshakeConfirmed(); |
| 1122 | 1163 |
| 1123 // Client should have the right value for server's receive window. | 1164 // Client should have the right value for server's receive window. |
| 1124 EXPECT_EQ(kServerIFCW, client_->client() | 1165 EXPECT_EQ(kServerIFCW, client_->client() |
| 1125 ->session() | 1166 ->session() |
| 1126 ->config() | 1167 ->config() |
| 1127 ->ReceivedInitialFlowControlWindowBytes()); | 1168 ->ReceivedInitialFlowControlWindowBytes()); |
| 1128 | 1169 |
| 1129 // Server should have the right value for client's receive window. | 1170 // Server should have the right value for client's receive window. |
| 1130 server_thread_->Pause(); | 1171 server_thread_->Pause(); |
| 1131 QuicDispatcher* dispatcher = | 1172 QuicDispatcher* dispatcher = |
| 1132 QuicServerPeer::GetDispatcher(server_thread_->server()); | 1173 QuicServerPeer::GetDispatcher(server_thread_->server()); |
| 1133 QuicSession* session = dispatcher->session_map().begin()->second; | 1174 QuicSession* session = dispatcher->session_map().begin()->second; |
| 1134 EXPECT_EQ(kClientIFCW, | 1175 EXPECT_EQ(kClientIFCW, |
| 1135 session->config()->ReceivedInitialFlowControlWindowBytes()); | 1176 session->config()->ReceivedInitialFlowControlWindowBytes()); |
| 1136 server_thread_->Resume(); | 1177 server_thread_->Resume(); |
| 1137 } | 1178 } |
| 1138 | 1179 |
| 1180 TEST_P(EndToEndTest, DifferentFlowControlWindowsQ020) { |
| 1181 // TODO(rjshade): Rename to DifferentFlowControlWindows when removing |
| 1182 // QUIC_VERSION_19. |
| 1183 // Client and server can set different initial flow control receive windows. |
| 1184 // These are sent in CHLO/SHLO. Tests that these values are exchanged properly |
| 1185 // in the crypto handshake. |
| 1186 const uint32 kClientStreamIFCW = 123456; |
| 1187 const uint32 kClientSessionIFCW = 234567; |
| 1188 set_client_initial_stream_flow_control_receive_window(kClientStreamIFCW); |
| 1189 set_client_initial_session_flow_control_receive_window(kClientSessionIFCW); |
| 1190 |
| 1191 const uint32 kServerStreamIFCW = 654321; |
| 1192 const uint32 kServerSessionIFCW = 765432; |
| 1193 set_server_initial_stream_flow_control_receive_window(kServerStreamIFCW); |
| 1194 set_server_initial_session_flow_control_receive_window(kServerSessionIFCW); |
| 1195 |
| 1196 ASSERT_TRUE(Initialize()); |
| 1197 if (negotiated_version_ <= QUIC_VERSION_19) { |
| 1198 return; |
| 1199 } |
| 1200 |
| 1201 // Values are exchanged during crypto handshake, so wait for that to finish. |
| 1202 client_->client()->WaitForCryptoHandshakeConfirmed(); |
| 1203 server_thread_->WaitForCryptoHandshakeConfirmed(); |
| 1204 |
| 1205 // Open a data stream to make sure the stream level flow control is updated. |
| 1206 QuicSpdyClientStream* stream = client_->GetOrCreateStream(); |
| 1207 stream->SendBody("hello", false); |
| 1208 |
| 1209 // Client should have the right values for server's receive window. |
| 1210 EXPECT_EQ(kServerStreamIFCW, |
| 1211 client_->client() |
| 1212 ->session() |
| 1213 ->config() |
| 1214 ->ReceivedInitialStreamFlowControlWindowBytes()); |
| 1215 EXPECT_EQ(kServerSessionIFCW, |
| 1216 client_->client() |
| 1217 ->session() |
| 1218 ->config() |
| 1219 ->ReceivedInitialSessionFlowControlWindowBytes()); |
| 1220 EXPECT_EQ(kServerStreamIFCW, QuicFlowControllerPeer::SendWindowOffset( |
| 1221 stream->flow_controller())); |
| 1222 EXPECT_EQ(kServerSessionIFCW, |
| 1223 QuicFlowControllerPeer::SendWindowOffset( |
| 1224 client_->client()->session()->flow_controller())); |
| 1225 |
| 1226 // Server should have the right values for client's receive window. |
| 1227 server_thread_->Pause(); |
| 1228 QuicDispatcher* dispatcher = |
| 1229 QuicServerPeer::GetDispatcher(server_thread_->server()); |
| 1230 QuicSession* session = dispatcher->session_map().begin()->second; |
| 1231 EXPECT_EQ(kClientStreamIFCW, |
| 1232 session->config()->ReceivedInitialStreamFlowControlWindowBytes()); |
| 1233 EXPECT_EQ(kClientSessionIFCW, |
| 1234 session->config()->ReceivedInitialSessionFlowControlWindowBytes()); |
| 1235 EXPECT_EQ(kClientSessionIFCW, QuicFlowControllerPeer::SendWindowOffset( |
| 1236 session->flow_controller())); |
| 1237 server_thread_->Resume(); |
| 1238 } |
| 1239 |
| 1139 } // namespace | 1240 } // namespace |
| 1140 } // namespace test | 1241 } // namespace test |
| 1141 } // namespace tools | 1242 } // namespace tools |
| 1142 } // namespace net | 1243 } // namespace net |
| OLD | NEW |