| 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 "net/tools/quic/quic_dispatcher.h" | 5 #include "net/tools/quic/quic_dispatcher.h" |
| 6 | 6 |
| 7 #include <ostream> | 7 #include <ostream> |
| 8 #include <string> | 8 #include <string> |
| 9 | 9 |
| 10 #include "base/macros.h" | 10 #include "base/macros.h" |
| (...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 157 ~QuicDispatcherTest() override {} | 157 ~QuicDispatcherTest() override {} |
| 158 | 158 |
| 159 MockConnection* connection1() { | 159 MockConnection* connection1() { |
| 160 return reinterpret_cast<MockConnection*>(session1_->connection()); | 160 return reinterpret_cast<MockConnection*>(session1_->connection()); |
| 161 } | 161 } |
| 162 | 162 |
| 163 MockConnection* connection2() { | 163 MockConnection* connection2() { |
| 164 return reinterpret_cast<MockConnection*>(session2_->connection()); | 164 return reinterpret_cast<MockConnection*>(session2_->connection()); |
| 165 } | 165 } |
| 166 | 166 |
| 167 // Process a packet with an 8 byte connection id, |
| 168 // 6 byte packet number, default path id, and packet number 1, |
| 169 // using the first supported version. |
| 167 void ProcessPacket(IPEndPoint client_address, | 170 void ProcessPacket(IPEndPoint client_address, |
| 168 QuicConnectionId connection_id, | 171 QuicConnectionId connection_id, |
| 169 bool has_version_flag, | 172 bool has_version_flag, |
| 170 bool has_multipath_flag, | 173 bool has_multipath_flag, |
| 171 const string& data) { | 174 const string& data) { |
| 172 ProcessPacket(client_address, connection_id, has_version_flag, | 175 ProcessPacket(client_address, connection_id, has_version_flag, |
| 173 has_multipath_flag, data, PACKET_8BYTE_CONNECTION_ID, | 176 has_multipath_flag, data, PACKET_8BYTE_CONNECTION_ID, |
| 174 PACKET_6BYTE_PACKET_NUMBER); | 177 PACKET_6BYTE_PACKET_NUMBER); |
| 175 } | 178 } |
| 176 | 179 |
| 180 // Process a packet with a default path id, and packet number 1, |
| 181 // using the first supported version. |
| 177 void ProcessPacket(IPEndPoint client_address, | 182 void ProcessPacket(IPEndPoint client_address, |
| 178 QuicConnectionId connection_id, | 183 QuicConnectionId connection_id, |
| 179 bool has_version_flag, | 184 bool has_version_flag, |
| 180 bool has_multipath_flag, | 185 bool has_multipath_flag, |
| 181 const string& data, | 186 const string& data, |
| 182 QuicConnectionIdLength connection_id_length, | 187 QuicConnectionIdLength connection_id_length, |
| 183 QuicPacketNumberLength packet_number_length) { | 188 QuicPacketNumberLength packet_number_length) { |
| 184 ProcessPacket(client_address, connection_id, has_version_flag, | 189 ProcessPacket(client_address, connection_id, has_version_flag, |
| 185 has_multipath_flag, data, connection_id_length, | 190 has_multipath_flag, data, connection_id_length, |
| 186 packet_number_length, kDefaultPathId, 1); | 191 packet_number_length, kDefaultPathId, 1); |
| 187 } | 192 } |
| 188 | 193 |
| 194 // Process a packet using the first supported version. |
| 189 void ProcessPacket(IPEndPoint client_address, | 195 void ProcessPacket(IPEndPoint client_address, |
| 190 QuicConnectionId connection_id, | 196 QuicConnectionId connection_id, |
| 191 bool has_version_flag, | 197 bool has_version_flag, |
| 192 bool has_multipath_flag, | 198 bool has_multipath_flag, |
| 193 const string& data, | 199 const string& data, |
| 194 QuicConnectionIdLength connection_id_length, | 200 QuicConnectionIdLength connection_id_length, |
| 195 QuicPacketNumberLength packet_number_length, | 201 QuicPacketNumberLength packet_number_length, |
| 196 QuicPathId path_id, | 202 QuicPathId path_id, |
| 197 QuicPacketNumber packet_number) { | 203 QuicPacketNumber packet_number) { |
| 204 ProcessPacket(client_address, connection_id, has_version_flag, |
| 205 QuicSupportedVersions().front(), data, connection_id_length, |
| 206 packet_number_length, packet_number); |
| 207 } |
| 208 |
| 209 // Processes a packet. |
| 210 void ProcessPacket(IPEndPoint client_address, |
| 211 QuicConnectionId connection_id, |
| 212 bool has_version_flag, |
| 213 QuicVersion version, |
| 214 const string& data, |
| 215 QuicConnectionIdLength connection_id_length, |
| 216 QuicPacketNumberLength packet_number_length, |
| 217 QuicPacketNumber packet_number) { |
| 218 QuicVersionVector versions(SupportedVersions(version)); |
| 198 scoped_ptr<QuicEncryptedPacket> packet(ConstructEncryptedPacket( | 219 scoped_ptr<QuicEncryptedPacket> packet(ConstructEncryptedPacket( |
| 199 connection_id, has_version_flag, has_multipath_flag, false, path_id, | 220 connection_id, has_version_flag, false, false, 0, packet_number, data, |
| 200 packet_number, data, connection_id_length, packet_number_length)); | 221 connection_id_length, packet_number_length, &versions)); |
| 222 |
| 201 data_ = string(packet->data(), packet->length()); | 223 data_ = string(packet->data(), packet->length()); |
| 202 dispatcher_.ProcessPacket(server_address_, client_address, *packet); | 224 dispatcher_.ProcessPacket(server_address_, client_address, *packet); |
| 203 } | 225 } |
| 204 | 226 |
| 205 void ValidatePacket(const QuicEncryptedPacket& packet) { | 227 void ValidatePacket(const QuicEncryptedPacket& packet) { |
| 206 EXPECT_EQ(data_.length(), packet.AsStringPiece().length()); | 228 EXPECT_EQ(data_.length(), packet.AsStringPiece().length()); |
| 207 EXPECT_EQ(data_, packet.AsStringPiece()); | 229 EXPECT_EQ(data_, packet.AsStringPiece()); |
| 208 } | 230 } |
| 209 | 231 |
| 210 void CreateTimeWaitListManager() { | 232 void CreateTimeWaitListManager() { |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 247 ProcessPacket(client_address, 2, true, false, "bar"); | 269 ProcessPacket(client_address, 2, true, false, "bar"); |
| 248 | 270 |
| 249 EXPECT_CALL(*reinterpret_cast<MockConnection*>(session1_->connection()), | 271 EXPECT_CALL(*reinterpret_cast<MockConnection*>(session1_->connection()), |
| 250 ProcessUdpPacket(_, _, _)) | 272 ProcessUdpPacket(_, _, _)) |
| 251 .Times(1) | 273 .Times(1) |
| 252 .WillOnce(testing::WithArgs<2>( | 274 .WillOnce(testing::WithArgs<2>( |
| 253 Invoke(this, &QuicDispatcherTest::ValidatePacket))); | 275 Invoke(this, &QuicDispatcherTest::ValidatePacket))); |
| 254 ProcessPacket(client_address, 1, false, false, "eep"); | 276 ProcessPacket(client_address, 1, false, false, "eep"); |
| 255 } | 277 } |
| 256 | 278 |
| 279 TEST_F(QuicDispatcherTest, StatelessVersionNegotiation) { |
| 280 ValueRestore<bool> old_flag(&FLAGS_quic_stateless_version_negotiation, true); |
| 281 IPEndPoint client_address(net::test::Loopback4(), 1); |
| 282 server_address_ = IPEndPoint(net::test::Any4(), 5); |
| 283 |
| 284 EXPECT_CALL(dispatcher_, CreateQuicSession(1, client_address)).Times(0); |
| 285 QuicVersion version = static_cast<QuicVersion>(QuicVersionMin() - 1); |
| 286 ProcessPacket(client_address, 1, true, version, "foo", |
| 287 PACKET_8BYTE_CONNECTION_ID, PACKET_6BYTE_PACKET_NUMBER, 1); |
| 288 } |
| 289 |
| 290 TEST_F(QuicDispatcherTest, StatefulVersionNegotiation) { |
| 291 ValueRestore<bool> old_flag(&FLAGS_quic_stateless_version_negotiation, false); |
| 292 IPEndPoint client_address(net::test::Loopback4(), 1); |
| 293 server_address_ = IPEndPoint(net::test::Any4(), 5); |
| 294 |
| 295 EXPECT_CALL(dispatcher_, CreateQuicSession(1, client_address)) |
| 296 .WillOnce(testing::Return(CreateSession(&dispatcher_, config_, 1, |
| 297 client_address, &mock_helper_, |
| 298 &crypto_config_, &session1_))); |
| 299 QuicVersion version = static_cast<QuicVersion>(QuicVersionMin() - 1); |
| 300 ProcessPacket(client_address, 1, true, version, "foo", |
| 301 PACKET_8BYTE_CONNECTION_ID, PACKET_6BYTE_PACKET_NUMBER, 1); |
| 302 } |
| 303 |
| 257 TEST_F(QuicDispatcherTest, Shutdown) { | 304 TEST_F(QuicDispatcherTest, Shutdown) { |
| 258 IPEndPoint client_address(net::test::Loopback4(), 1); | 305 IPEndPoint client_address(net::test::Loopback4(), 1); |
| 259 | 306 |
| 260 EXPECT_CALL(dispatcher_, CreateQuicSession(_, client_address)) | 307 EXPECT_CALL(dispatcher_, CreateQuicSession(_, client_address)) |
| 261 .WillOnce(testing::Return(CreateSession(&dispatcher_, config_, 1, | 308 .WillOnce(testing::Return(CreateSession(&dispatcher_, config_, 1, |
| 262 client_address, &mock_helper_, | 309 client_address, &mock_helper_, |
| 263 &crypto_config_, &session1_))); | 310 &crypto_config_, &session1_))); |
| 264 | 311 |
| 265 ProcessPacket(client_address, 1, true, false, "foo"); | 312 ProcessPacket(client_address, 1, true, false, "foo"); |
| 266 | 313 |
| (...skipping 498 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 765 | 812 |
| 766 // And we'll resume where we left off when we get another call. | 813 // And we'll resume where we left off when we get another call. |
| 767 EXPECT_CALL(*connection2(), OnCanWrite()); | 814 EXPECT_CALL(*connection2(), OnCanWrite()); |
| 768 dispatcher_.OnCanWrite(); | 815 dispatcher_.OnCanWrite(); |
| 769 EXPECT_FALSE(dispatcher_.HasPendingWrites()); | 816 EXPECT_FALSE(dispatcher_.HasPendingWrites()); |
| 770 } | 817 } |
| 771 | 818 |
| 772 } // namespace | 819 } // namespace |
| 773 } // namespace test | 820 } // namespace test |
| 774 } // namespace net | 821 } // namespace net |
| OLD | NEW |