Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(56)

Side by Side Diff: net/tools/quic/quic_dispatcher_test.cc

Issue 1979763002: Landing Recent QUIC changes until Sun May 8 00:39:29 2016 +0000 (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « net/tools/quic/quic_dispatcher.cc ('k') | net/tools/quic/quic_packet_printer_bin.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 <memory> 7 #include <memory>
8 #include <ostream> 8 #include <ostream>
9 #include <string> 9 #include <string>
10 10
(...skipping 15 matching lines...) Expand all
26 #include "net/tools/quic/quic_time_wait_list_manager.h" 26 #include "net/tools/quic/quic_time_wait_list_manager.h"
27 #include "net/tools/quic/test_tools/mock_quic_time_wait_list_manager.h" 27 #include "net/tools/quic/test_tools/mock_quic_time_wait_list_manager.h"
28 #include "net/tools/quic/test_tools/quic_dispatcher_peer.h" 28 #include "net/tools/quic/test_tools/quic_dispatcher_peer.h"
29 #include "testing/gmock/include/gmock/gmock.h" 29 #include "testing/gmock/include/gmock/gmock.h"
30 #include "testing/gtest/include/gtest/gtest.h" 30 #include "testing/gtest/include/gtest/gtest.h"
31 31
32 using base::StringPiece; 32 using base::StringPiece;
33 using net::EpollServer; 33 using net::EpollServer;
34 using net::test::ConstructEncryptedPacket; 34 using net::test::ConstructEncryptedPacket;
35 using net::test::CryptoTestUtils; 35 using net::test::CryptoTestUtils;
36 using net::test::MockConnection; 36 using net::test::MockQuicConnection;
37 using net::test::MockConnectionHelper; 37 using net::test::MockQuicConnectionHelper;
38 using net::test::ValueRestore; 38 using net::test::ValueRestore;
39 using std::string; 39 using std::string;
40 using std::vector; 40 using std::vector;
41 using testing::DoAll; 41 using testing::DoAll;
42 using testing::InSequence; 42 using testing::InSequence;
43 using testing::Invoke; 43 using testing::Invoke;
44 using testing::WithoutArgs; 44 using testing::WithoutArgs;
45 using testing::_; 45 using testing::_;
46 46
47 namespace net { 47 namespace net {
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
111 const IPEndPoint& client_address)); 111 const IPEndPoint& client_address));
112 112
113 using QuicDispatcher::current_server_address; 113 using QuicDispatcher::current_server_address;
114 using QuicDispatcher::current_client_address; 114 using QuicDispatcher::current_client_address;
115 }; 115 };
116 116
117 // A Connection class which unregisters the session from the dispatcher when 117 // A Connection class which unregisters the session from the dispatcher when
118 // sending connection close. 118 // sending connection close.
119 // It'd be slightly more realistic to do this from the Session but it would 119 // It'd be slightly more realistic to do this from the Session but it would
120 // involve a lot more mocking. 120 // involve a lot more mocking.
121 class MockServerConnection : public MockConnection { 121 class MockServerConnection : public MockQuicConnection {
122 public: 122 public:
123 MockServerConnection(QuicConnectionId connection_id, 123 MockServerConnection(QuicConnectionId connection_id,
124 MockConnectionHelper* helper, 124 MockQuicConnectionHelper* helper,
125 MockAlarmFactory* alarm_factory, 125 MockAlarmFactory* alarm_factory,
126 QuicDispatcher* dispatcher) 126 QuicDispatcher* dispatcher)
127 : MockConnection(connection_id, 127 : MockQuicConnection(connection_id,
128 helper, 128 helper,
129 alarm_factory, 129 alarm_factory,
130 Perspective::IS_SERVER), 130 Perspective::IS_SERVER),
131 dispatcher_(dispatcher) {} 131 dispatcher_(dispatcher) {}
132 132
133 void UnregisterOnConnectionClosed() { 133 void UnregisterOnConnectionClosed() {
134 LOG(ERROR) << "Unregistering " << connection_id(); 134 LOG(ERROR) << "Unregistering " << connection_id();
135 dispatcher_->OnConnectionClosed(connection_id(), QUIC_NO_ERROR, 135 dispatcher_->OnConnectionClosed(connection_id(), QUIC_NO_ERROR,
136 "Unregistering."); 136 "Unregistering.");
137 } 137 }
138 138
139 private: 139 private:
140 QuicDispatcher* dispatcher_; 140 QuicDispatcher* dispatcher_;
141 }; 141 };
142 142
143 QuicServerSessionBase* CreateSession( 143 QuicServerSessionBase* CreateSession(
144 QuicDispatcher* dispatcher, 144 QuicDispatcher* dispatcher,
145 const QuicConfig& config, 145 const QuicConfig& config,
146 QuicConnectionId connection_id, 146 QuicConnectionId connection_id,
147 const IPEndPoint& client_address, 147 const IPEndPoint& client_address,
148 MockConnectionHelper* helper, 148 MockQuicConnectionHelper* helper,
149 MockAlarmFactory* alarm_factory, 149 MockAlarmFactory* alarm_factory,
150 const QuicCryptoServerConfig* crypto_config, 150 const QuicCryptoServerConfig* crypto_config,
151 QuicCompressedCertsCache* compressed_certs_cache, 151 QuicCompressedCertsCache* compressed_certs_cache,
152 TestQuicSpdyServerSession** session) { 152 TestQuicSpdyServerSession** session) {
153 MockServerConnection* connection = new MockServerConnection( 153 MockServerConnection* connection = new MockServerConnection(
154 connection_id, helper, alarm_factory, dispatcher); 154 connection_id, helper, alarm_factory, dispatcher);
155 *session = new TestQuicSpdyServerSession(config, connection, crypto_config, 155 *session = new TestQuicSpdyServerSession(config, connection, crypto_config,
156 compressed_certs_cache); 156 compressed_certs_cache);
157 connection->set_visitor(*session); 157 connection->set_visitor(*session);
158 ON_CALL(*connection, CloseConnection(_, _, _)) 158 ON_CALL(*connection, CloseConnection(_, _, _))
159 .WillByDefault(WithoutArgs(Invoke( 159 .WillByDefault(WithoutArgs(Invoke(
160 connection, &MockServerConnection::UnregisterOnConnectionClosed))); 160 connection, &MockServerConnection::UnregisterOnConnectionClosed)));
161 EXPECT_CALL(*reinterpret_cast<MockConnection*>((*session)->connection()), 161 EXPECT_CALL(*reinterpret_cast<MockQuicConnection*>((*session)->connection()),
162 ProcessUdpPacket(_, client_address, _)); 162 ProcessUdpPacket(_, client_address, _));
163 163
164 return *session; 164 return *session;
165 } 165 }
166 166
167 class QuicDispatcherTest : public ::testing::Test { 167 class QuicDispatcherTest : public ::testing::Test {
168 public: 168 public:
169 QuicDispatcherTest() 169 QuicDispatcherTest()
170 : helper_(&eps_, QuicAllocator::BUFFER_POOL), 170 : helper_(&eps_, QuicAllocator::BUFFER_POOL),
171 alarm_factory_(&eps_), 171 alarm_factory_(&eps_),
172 crypto_config_(QuicCryptoServerConfig::TESTING, 172 crypto_config_(QuicCryptoServerConfig::TESTING,
173 QuicRandom::GetInstance(), 173 QuicRandom::GetInstance(),
174 CryptoTestUtils::ProofSourceForTesting()), 174 CryptoTestUtils::ProofSourceForTesting()),
175 dispatcher_(config_, &crypto_config_, &eps_), 175 dispatcher_(config_, &crypto_config_, &eps_),
176 time_wait_list_manager_(nullptr), 176 time_wait_list_manager_(nullptr),
177 session1_(nullptr), 177 session1_(nullptr),
178 session2_(nullptr) { 178 session2_(nullptr) {
179 dispatcher_.InitializeWithWriter(new QuicDefaultPacketWriter(1)); 179 dispatcher_.InitializeWithWriter(new QuicDefaultPacketWriter(1));
180 } 180 }
181 181
182 ~QuicDispatcherTest() override {} 182 ~QuicDispatcherTest() override {}
183 183
184 MockConnection* connection1() { 184 MockQuicConnection* connection1() {
185 return reinterpret_cast<MockConnection*>(session1_->connection()); 185 return reinterpret_cast<MockQuicConnection*>(session1_->connection());
186 } 186 }
187 187
188 MockConnection* connection2() { 188 MockQuicConnection* connection2() {
189 return reinterpret_cast<MockConnection*>(session2_->connection()); 189 return reinterpret_cast<MockQuicConnection*>(session2_->connection());
190 } 190 }
191 191
192 // Process a packet with an 8 byte connection id, 192 // Process a packet with an 8 byte connection id,
193 // 6 byte packet number, default path id, and packet number 1, 193 // 6 byte packet number, default path id, and packet number 1,
194 // using the first supported version. 194 // using the first supported version.
195 void ProcessPacket(IPEndPoint client_address, 195 void ProcessPacket(IPEndPoint client_address,
196 QuicConnectionId connection_id, 196 QuicConnectionId connection_id,
197 bool has_version_flag, 197 bool has_version_flag,
198 bool has_multipath_flag, 198 bool has_multipath_flag,
199 const string& data) { 199 const string& data) {
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
259 259
260 void CreateTimeWaitListManager() { 260 void CreateTimeWaitListManager() {
261 time_wait_list_manager_ = 261 time_wait_list_manager_ =
262 new MockTimeWaitListManager(QuicDispatcherPeer::GetWriter(&dispatcher_), 262 new MockTimeWaitListManager(QuicDispatcherPeer::GetWriter(&dispatcher_),
263 &dispatcher_, &helper_, &alarm_factory_); 263 &dispatcher_, &helper_, &alarm_factory_);
264 // dispatcher_ takes the ownership of time_wait_list_manager_. 264 // dispatcher_ takes the ownership of time_wait_list_manager_.
265 QuicDispatcherPeer::SetTimeWaitListManager(&dispatcher_, 265 QuicDispatcherPeer::SetTimeWaitListManager(&dispatcher_,
266 time_wait_list_manager_); 266 time_wait_list_manager_);
267 } 267 }
268 268
269 string SerializeCHLO() {
270 CryptoHandshakeMessage client_hello;
271 client_hello.set_tag(kCHLO);
272 return client_hello.GetSerialized().AsStringPiece().as_string();
273 }
274
269 EpollServer eps_; 275 EpollServer eps_;
270 QuicEpollConnectionHelper helper_; 276 QuicEpollConnectionHelper helper_;
271 MockConnectionHelper mock_helper_; 277 MockQuicConnectionHelper mock_helper_;
272 QuicEpollAlarmFactory alarm_factory_; 278 QuicEpollAlarmFactory alarm_factory_;
273 MockAlarmFactory mock_alarm_factory_; 279 MockAlarmFactory mock_alarm_factory_;
274 QuicConfig config_; 280 QuicConfig config_;
275 QuicCryptoServerConfig crypto_config_; 281 QuicCryptoServerConfig crypto_config_;
276 IPEndPoint server_address_; 282 IPEndPoint server_address_;
277 TestDispatcher dispatcher_; 283 TestDispatcher dispatcher_;
278 MockTimeWaitListManager* time_wait_list_manager_; 284 MockTimeWaitListManager* time_wait_list_manager_;
279 TestQuicSpdyServerSession* session1_; 285 TestQuicSpdyServerSession* session1_;
280 TestQuicSpdyServerSession* session2_; 286 TestQuicSpdyServerSession* session2_;
281 string data_; 287 string data_;
282 }; 288 };
283 289
284 TEST_F(QuicDispatcherTest, ProcessPackets) { 290 TEST_F(QuicDispatcherTest, ProcessPackets) {
285 IPEndPoint client_address(net::test::Loopback4(), 1); 291 IPEndPoint client_address(net::test::Loopback4(), 1);
286 server_address_ = IPEndPoint(net::test::Any4(), 5); 292 server_address_ = IPEndPoint(net::test::Any4(), 5);
287 293
288 EXPECT_CALL(dispatcher_, CreateQuicSession(1, client_address)) 294 EXPECT_CALL(dispatcher_, CreateQuicSession(1, client_address))
289 .WillOnce(testing::Return(CreateSession( 295 .WillOnce(testing::Return(CreateSession(
290 &dispatcher_, config_, 1, client_address, &mock_helper_, 296 &dispatcher_, config_, 1, client_address, &mock_helper_,
291 &mock_alarm_factory_, &crypto_config_, 297 &mock_alarm_factory_, &crypto_config_,
292 QuicDispatcherPeer::GetCache(&dispatcher_), &session1_))); 298 QuicDispatcherPeer::GetCache(&dispatcher_), &session1_)));
293 ProcessPacket(client_address, 1, true, false, "foo"); 299 ProcessPacket(client_address, 1, true, false, SerializeCHLO());
294 EXPECT_EQ(client_address, dispatcher_.current_client_address()); 300 EXPECT_EQ(client_address, dispatcher_.current_client_address());
295 EXPECT_EQ(server_address_, dispatcher_.current_server_address()); 301 EXPECT_EQ(server_address_, dispatcher_.current_server_address());
296 302
297 EXPECT_CALL(dispatcher_, CreateQuicSession(2, client_address)) 303 EXPECT_CALL(dispatcher_, CreateQuicSession(2, client_address))
298 .WillOnce(testing::Return(CreateSession( 304 .WillOnce(testing::Return(CreateSession(
299 &dispatcher_, config_, 2, client_address, &mock_helper_, 305 &dispatcher_, config_, 2, client_address, &mock_helper_,
300 &mock_alarm_factory_, &crypto_config_, 306 &mock_alarm_factory_, &crypto_config_,
301 QuicDispatcherPeer::GetCache(&dispatcher_), &session2_))); 307 QuicDispatcherPeer::GetCache(&dispatcher_), &session2_)));
302 ProcessPacket(client_address, 2, true, false, "bar"); 308 ProcessPacket(client_address, 2, true, false, SerializeCHLO());
303 309
304 EXPECT_CALL(*reinterpret_cast<MockConnection*>(session1_->connection()), 310 EXPECT_CALL(*reinterpret_cast<MockQuicConnection*>(session1_->connection()),
305 ProcessUdpPacket(_, _, _)) 311 ProcessUdpPacket(_, _, _))
306 .Times(1) 312 .Times(1)
307 .WillOnce(testing::WithArgs<2>( 313 .WillOnce(testing::WithArgs<2>(
308 Invoke(this, &QuicDispatcherTest::ValidatePacket))); 314 Invoke(this, &QuicDispatcherTest::ValidatePacket)));
309 ProcessPacket(client_address, 1, false, false, "eep"); 315 ProcessPacket(client_address, 1, false, false, "data");
310 } 316 }
311 317
312 TEST_F(QuicDispatcherTest, StatelessVersionNegotiation) { 318 TEST_F(QuicDispatcherTest, StatelessVersionNegotiation) {
313 ValueRestore<bool> old_flag(&FLAGS_quic_stateless_version_negotiation, true);
314 IPEndPoint client_address(net::test::Loopback4(), 1); 319 IPEndPoint client_address(net::test::Loopback4(), 1);
315 server_address_ = IPEndPoint(net::test::Any4(), 5); 320 server_address_ = IPEndPoint(net::test::Any4(), 5);
316 321
317 EXPECT_CALL(dispatcher_, CreateQuicSession(1, client_address)).Times(0); 322 EXPECT_CALL(dispatcher_, CreateQuicSession(1, client_address)).Times(0);
318 QuicVersion version = static_cast<QuicVersion>(QuicVersionMin() - 1); 323 QuicVersion version = static_cast<QuicVersion>(QuicVersionMin() - 1);
319 ProcessPacket(client_address, 1, true, version, "foo", 324 ProcessPacket(client_address, 1, true, version, SerializeCHLO(),
320 PACKET_8BYTE_CONNECTION_ID, PACKET_6BYTE_PACKET_NUMBER, 1); 325 PACKET_8BYTE_CONNECTION_ID, PACKET_6BYTE_PACKET_NUMBER, 1);
321 } 326 }
322 327
323 TEST_F(QuicDispatcherTest, StatefulVersionNegotiation) {
324 ValueRestore<bool> old_flag(&FLAGS_quic_stateless_version_negotiation, false);
325 IPEndPoint client_address(net::test::Loopback4(), 1);
326 server_address_ = IPEndPoint(net::test::Any4(), 5);
327
328 EXPECT_CALL(dispatcher_, CreateQuicSession(1, client_address))
329 .WillOnce(testing::Return(CreateSession(
330 &dispatcher_, config_, 1, client_address, &mock_helper_,
331 &mock_alarm_factory_, &crypto_config_,
332 QuicDispatcherPeer::GetCache(&dispatcher_), &session1_)));
333 QuicVersion version = static_cast<QuicVersion>(QuicVersionMin() - 1);
334 ProcessPacket(client_address, 1, true, version, "foo",
335 PACKET_8BYTE_CONNECTION_ID, PACKET_6BYTE_PACKET_NUMBER, 1);
336 }
337
338 TEST_F(QuicDispatcherTest, Shutdown) { 328 TEST_F(QuicDispatcherTest, Shutdown) {
339 IPEndPoint client_address(net::test::Loopback4(), 1); 329 IPEndPoint client_address(net::test::Loopback4(), 1);
340 330
341 EXPECT_CALL(dispatcher_, CreateQuicSession(_, client_address)) 331 EXPECT_CALL(dispatcher_, CreateQuicSession(_, client_address))
342 .WillOnce(testing::Return(CreateSession( 332 .WillOnce(testing::Return(CreateSession(
343 &dispatcher_, config_, 1, client_address, &mock_helper_, 333 &dispatcher_, config_, 1, client_address, &mock_helper_,
344 &mock_alarm_factory_, &crypto_config_, 334 &mock_alarm_factory_, &crypto_config_,
345 QuicDispatcherPeer::GetCache(&dispatcher_), &session1_))); 335 QuicDispatcherPeer::GetCache(&dispatcher_), &session1_)));
346 336
347 ProcessPacket(client_address, 1, true, false, "foo"); 337 ProcessPacket(client_address, 1, true, false, SerializeCHLO());
348 338
349 EXPECT_CALL(*reinterpret_cast<MockConnection*>(session1_->connection()), 339 EXPECT_CALL(*reinterpret_cast<MockQuicConnection*>(session1_->connection()),
350 CloseConnection(QUIC_PEER_GOING_AWAY, _, _)); 340 CloseConnection(QUIC_PEER_GOING_AWAY, _, _));
351 341
352 dispatcher_.Shutdown(); 342 dispatcher_.Shutdown();
353 } 343 }
354 344
355 TEST_F(QuicDispatcherTest, TimeWaitListManager) { 345 TEST_F(QuicDispatcherTest, TimeWaitListManager) {
356 CreateTimeWaitListManager(); 346 CreateTimeWaitListManager();
357 347
358 // Create a new session. 348 // Create a new session.
359 IPEndPoint client_address(net::test::Loopback4(), 1); 349 IPEndPoint client_address(net::test::Loopback4(), 1);
360 QuicConnectionId connection_id = 1; 350 QuicConnectionId connection_id = 1;
361 EXPECT_CALL(dispatcher_, CreateQuicSession(connection_id, client_address)) 351 EXPECT_CALL(dispatcher_, CreateQuicSession(connection_id, client_address))
362 .WillOnce(testing::Return(CreateSession( 352 .WillOnce(testing::Return(CreateSession(
363 &dispatcher_, config_, connection_id, client_address, &mock_helper_, 353 &dispatcher_, config_, connection_id, client_address, &mock_helper_,
364 &mock_alarm_factory_, &crypto_config_, 354 &mock_alarm_factory_, &crypto_config_,
365 QuicDispatcherPeer::GetCache(&dispatcher_), &session1_))); 355 QuicDispatcherPeer::GetCache(&dispatcher_), &session1_)));
366 ProcessPacket(client_address, connection_id, true, false, "foo"); 356 ProcessPacket(client_address, connection_id, true, false, SerializeCHLO());
367 357
368 // Close the connection by sending public reset packet. 358 // Close the connection by sending public reset packet.
369 QuicPublicResetPacket packet; 359 QuicPublicResetPacket packet;
370 packet.public_header.connection_id = connection_id; 360 packet.public_header.connection_id = connection_id;
371 packet.public_header.reset_flag = true; 361 packet.public_header.reset_flag = true;
372 packet.public_header.version_flag = false; 362 packet.public_header.version_flag = false;
373 packet.rejected_packet_number = 19191; 363 packet.rejected_packet_number = 19191;
374 packet.nonce_proof = 132232; 364 packet.nonce_proof = 132232;
375 std::unique_ptr<QuicEncryptedPacket> encrypted( 365 std::unique_ptr<QuicEncryptedPacket> encrypted(
376 QuicFramer::BuildPublicResetPacket(packet)); 366 QuicFramer::BuildPublicResetPacket(packet));
377 std::unique_ptr<QuicReceivedPacket> received( 367 std::unique_ptr<QuicReceivedPacket> received(
378 ConstructReceivedPacket(*encrypted, helper_.GetClock()->Now())); 368 ConstructReceivedPacket(*encrypted, helper_.GetClock()->Now()));
379 EXPECT_CALL(*session1_, OnConnectionClosed(QUIC_PUBLIC_RESET, _, 369 EXPECT_CALL(*session1_, OnConnectionClosed(QUIC_PUBLIC_RESET, _,
380 ConnectionCloseSource::FROM_PEER)) 370 ConnectionCloseSource::FROM_PEER))
381 .Times(1) 371 .Times(1)
382 .WillOnce(WithoutArgs(Invoke( 372 .WillOnce(WithoutArgs(Invoke(
383 reinterpret_cast<MockServerConnection*>(session1_->connection()), 373 reinterpret_cast<MockServerConnection*>(session1_->connection()),
384 &MockServerConnection::UnregisterOnConnectionClosed))); 374 &MockServerConnection::UnregisterOnConnectionClosed)));
385 EXPECT_CALL(*reinterpret_cast<MockConnection*>(session1_->connection()), 375 EXPECT_CALL(*reinterpret_cast<MockQuicConnection*>(session1_->connection()),
386 ProcessUdpPacket(_, _, _)) 376 ProcessUdpPacket(_, _, _))
387 .WillOnce( 377 .WillOnce(
388 Invoke(reinterpret_cast<MockConnection*>(session1_->connection()), 378 Invoke(reinterpret_cast<MockQuicConnection*>(session1_->connection()),
389 &MockConnection::ReallyProcessUdpPacket)); 379 &MockQuicConnection::ReallyProcessUdpPacket));
390 dispatcher_.ProcessPacket(IPEndPoint(), client_address, *received); 380 dispatcher_.ProcessPacket(IPEndPoint(), client_address, *received);
391 EXPECT_TRUE(time_wait_list_manager_->IsConnectionIdInTimeWait(connection_id)); 381 EXPECT_TRUE(time_wait_list_manager_->IsConnectionIdInTimeWait(connection_id));
392 382
393 // Dispatcher forwards subsequent packets for this connection_id to the time 383 // Dispatcher forwards subsequent packets for this connection_id to the time
394 // wait list manager. 384 // wait list manager.
395 EXPECT_CALL(*time_wait_list_manager_, 385 EXPECT_CALL(*time_wait_list_manager_,
396 ProcessPacket(_, _, connection_id, _, _)) 386 ProcessPacket(_, _, connection_id, _, _))
397 .Times(1); 387 .Times(1);
398 EXPECT_CALL(*time_wait_list_manager_, AddConnectionIdToTimeWait(_, _, _, _)) 388 EXPECT_CALL(*time_wait_list_manager_, AddConnectionIdToTimeWait(_, _, _, _))
399 .Times(0); 389 .Times(0);
400 ProcessPacket(client_address, connection_id, true, false, "foo"); 390 ProcessPacket(client_address, connection_id, true, false, "data");
401 } 391 }
402 392
403 TEST_F(QuicDispatcherTest, NoVersionPacketToTimeWaitListManager) { 393 TEST_F(QuicDispatcherTest, NoVersionPacketToTimeWaitListManager) {
404 CreateTimeWaitListManager(); 394 CreateTimeWaitListManager();
405 395
406 IPEndPoint client_address(net::test::Loopback4(), 1); 396 IPEndPoint client_address(net::test::Loopback4(), 1);
407 QuicConnectionId connection_id = 1; 397 QuicConnectionId connection_id = 1;
408 // Dispatcher forwards all packets for this connection_id to the time wait 398 // Dispatcher forwards all packets for this connection_id to the time wait
409 // list manager. 399 // list manager.
410 EXPECT_CALL(dispatcher_, CreateQuicSession(_, _)).Times(0); 400 EXPECT_CALL(dispatcher_, CreateQuicSession(_, _)).Times(0);
411 EXPECT_CALL(*time_wait_list_manager_, 401 EXPECT_CALL(*time_wait_list_manager_,
412 ProcessPacket(_, _, connection_id, _, _)) 402 ProcessPacket(_, _, connection_id, _, _))
413 .Times(1); 403 .Times(1);
414 EXPECT_CALL(*time_wait_list_manager_, AddConnectionIdToTimeWait(_, _, _, _)) 404 EXPECT_CALL(*time_wait_list_manager_, AddConnectionIdToTimeWait(_, _, _, _))
415 .Times(1); 405 .Times(1);
416 ProcessPacket(client_address, connection_id, false, false, "data"); 406 ProcessPacket(client_address, connection_id, false, false, SerializeCHLO());
407 }
408
409 TEST_F(QuicDispatcherTest, ProcessPacketWithZeroPort) {
410 CreateTimeWaitListManager();
411
412 IPEndPoint client_address(net::test::Loopback4(), 0);
413 server_address_ = IPEndPoint(net::test::Any4(), 5);
414
415 // dispatcher_ should drop this packet.
416 EXPECT_CALL(dispatcher_, CreateQuicSession(1, client_address)).Times(0);
417 EXPECT_CALL(*time_wait_list_manager_, ProcessPacket(_, _, _, _, _)).Times(0);
418 EXPECT_CALL(*time_wait_list_manager_, AddConnectionIdToTimeWait(_, _, _, _))
419 .Times(0);
420 ProcessPacket(client_address, 1, true, false, SerializeCHLO());
421 }
422
423 TEST_F(QuicDispatcherTest, OKSeqNoPacketProcessed) {
424 IPEndPoint client_address(net::test::Loopback4(), 1);
425 QuicConnectionId connection_id = 1;
426 server_address_ = IPEndPoint(net::test::Any4(), 5);
427
428 EXPECT_CALL(dispatcher_, CreateQuicSession(1, client_address))
429 .WillOnce(testing::Return(CreateSession(
430 &dispatcher_, config_, 1, client_address, &mock_helper_,
431 &mock_alarm_factory_, &crypto_config_,
432 QuicDispatcherPeer::GetCache(&dispatcher_), &session1_)));
433 // A packet whose packet number is the largest that is allowed to start a
434 // connection.
435 ProcessPacket(client_address, connection_id, true, false, SerializeCHLO(),
436 PACKET_8BYTE_CONNECTION_ID, PACKET_6BYTE_PACKET_NUMBER,
437 kDefaultPathId,
438 QuicDispatcher::kMaxReasonableInitialPacketNumber);
439 EXPECT_EQ(client_address, dispatcher_.current_client_address());
440 EXPECT_EQ(server_address_, dispatcher_.current_server_address());
441 }
442
443 TEST_F(QuicDispatcherTest, TooBigSeqNoPacketToTimeWaitListManager) {
444 CreateTimeWaitListManager();
445
446 IPEndPoint client_address(net::test::Loopback4(), 1);
447 QuicConnectionId connection_id = 1;
448 // Dispatcher forwards this packet for this connection_id to the time wait
449 // list manager.
450 EXPECT_CALL(dispatcher_, CreateQuicSession(_, _)).Times(0);
451 EXPECT_CALL(*time_wait_list_manager_,
452 ProcessPacket(_, _, connection_id, _, _))
453 .Times(1);
454 EXPECT_CALL(*time_wait_list_manager_, AddConnectionIdToTimeWait(_, _, _, _))
455 .Times(1);
456 // A packet whose packet number is one to large to be allowed to start a
457 // connection.
458 ProcessPacket(client_address, connection_id, true, false, SerializeCHLO(),
459 PACKET_8BYTE_CONNECTION_ID, PACKET_6BYTE_PACKET_NUMBER,
460 kDefaultPathId,
461 QuicDispatcher::kMaxReasonableInitialPacketNumber + 1);
417 } 462 }
418 463
419 // Enables mocking of the handshake-confirmation for stateless rejects. 464 // Enables mocking of the handshake-confirmation for stateless rejects.
420 class MockQuicCryptoServerStream : public QuicCryptoServerStream { 465 class MockQuicCryptoServerStream : public QuicCryptoServerStream {
421 public: 466 public:
422 MockQuicCryptoServerStream(const QuicCryptoServerConfig& crypto_config, 467 MockQuicCryptoServerStream(const QuicCryptoServerConfig& crypto_config,
423 QuicCompressedCertsCache* compressed_certs_cache, 468 QuicCompressedCertsCache* compressed_certs_cache,
424 QuicSession* session) 469 QuicSession* session)
425 : QuicCryptoServerStream(&crypto_config, 470 : QuicCryptoServerStream(&crypto_config,
426 compressed_certs_cache, 471 compressed_certs_cache,
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after
519 crypto_stream1_->set_handshake_confirmed_for_testing( 564 crypto_stream1_->set_handshake_confirmed_for_testing(
520 GetParam().crypto_handshake_successful); 565 GetParam().crypto_handshake_successful);
521 crypto_stream1_->SetPeerSupportsStatelessRejects( 566 crypto_stream1_->SetPeerSupportsStatelessRejects(
522 GetParam().client_supports_statelesss_rejects); 567 GetParam().client_supports_statelesss_rejects);
523 return session1_; 568 return session1_;
524 } 569 }
525 570
526 MockQuicCryptoServerStream* crypto_stream1_; 571 MockQuicCryptoServerStream* crypto_stream1_;
527 }; 572 };
528 573
529 TEST_F(QuicDispatcherTest, ProcessPacketWithZeroPort) {
530 CreateTimeWaitListManager();
531
532 IPEndPoint client_address(net::test::Loopback4(), 0);
533 server_address_ = IPEndPoint(net::test::Any4(), 5);
534
535 // dispatcher_ should drop this packet.
536 EXPECT_CALL(dispatcher_, CreateQuicSession(1, client_address)).Times(0);
537 EXPECT_CALL(*time_wait_list_manager_, ProcessPacket(_, _, _, _, _)).Times(0);
538 EXPECT_CALL(*time_wait_list_manager_, AddConnectionIdToTimeWait(_, _, _, _))
539 .Times(0);
540 ProcessPacket(client_address, 1, true, false, "foo");
541 }
542
543 TEST_F(QuicDispatcherTest, OKSeqNoPacketProcessed) {
544 IPEndPoint client_address(net::test::Loopback4(), 1);
545 QuicConnectionId connection_id = 1;
546 server_address_ = IPEndPoint(net::test::Any4(), 5);
547
548 EXPECT_CALL(dispatcher_, CreateQuicSession(1, client_address))
549 .WillOnce(testing::Return(CreateSession(
550 &dispatcher_, config_, 1, client_address, &mock_helper_,
551 &mock_alarm_factory_, &crypto_config_,
552 QuicDispatcherPeer::GetCache(&dispatcher_), &session1_)));
553 // A packet whose packet number is the largest that is allowed to start a
554 // connection.
555 ProcessPacket(client_address, connection_id, true, false, "data",
556 PACKET_8BYTE_CONNECTION_ID, PACKET_6BYTE_PACKET_NUMBER,
557 kDefaultPathId,
558 QuicDispatcher::kMaxReasonableInitialPacketNumber);
559 EXPECT_EQ(client_address, dispatcher_.current_client_address());
560 EXPECT_EQ(server_address_, dispatcher_.current_server_address());
561 }
562
563 TEST_F(QuicDispatcherTest, TooBigSeqNoPacketToTimeWaitListManager) {
564 CreateTimeWaitListManager();
565
566 IPEndPoint client_address(net::test::Loopback4(), 1);
567 QuicConnectionId connection_id = 1;
568 // Dispatcher forwards this packet for this connection_id to the time wait
569 // list manager.
570 EXPECT_CALL(dispatcher_, CreateQuicSession(_, _)).Times(0);
571 EXPECT_CALL(*time_wait_list_manager_,
572 ProcessPacket(_, _, connection_id, _, _))
573 .Times(1);
574 EXPECT_CALL(*time_wait_list_manager_, AddConnectionIdToTimeWait(_, _, _, _))
575 .Times(1);
576 // A packet whose packet number is one to large to be allowed to start a
577 // connection.
578 ProcessPacket(client_address, connection_id, true, false, "data",
579 PACKET_8BYTE_CONNECTION_ID, PACKET_6BYTE_PACKET_NUMBER,
580 kDefaultPathId,
581 QuicDispatcher::kMaxReasonableInitialPacketNumber + 1);
582 }
583
584 INSTANTIATE_TEST_CASE_P(QuicDispatcherStatelessRejectTests, 574 INSTANTIATE_TEST_CASE_P(QuicDispatcherStatelessRejectTests,
585 QuicDispatcherStatelessRejectTest, 575 QuicDispatcherStatelessRejectTest,
586 ::testing::ValuesIn(GetStatelessRejectTestParams())); 576 ::testing::ValuesIn(GetStatelessRejectTestParams()));
587 577
588 // Parameterized test for stateless rejects. Should test all 578 // Parameterized test for stateless rejects. Should test all
589 // combinations of enabling/disabling, reject/no-reject for stateless 579 // combinations of enabling/disabling, reject/no-reject for stateless
590 // rejects. 580 // rejects.
591 TEST_P(QuicDispatcherStatelessRejectTest, ParameterizedBasicTest) { 581 TEST_P(QuicDispatcherStatelessRejectTest, ParameterizedBasicTest) {
592 CreateTimeWaitListManager(); 582 CreateTimeWaitListManager();
593 583
594 IPEndPoint client_address(net::test::Loopback4(), 1); 584 IPEndPoint client_address(net::test::Loopback4(), 1);
595 QuicConnectionId connection_id = 1; 585 QuicConnectionId connection_id = 1;
596 EXPECT_CALL(dispatcher_, CreateQuicSession(connection_id, client_address)) 586 EXPECT_CALL(dispatcher_, CreateQuicSession(connection_id, client_address))
597 .WillOnce(testing::Return( 587 .WillOnce(testing::Return(
598 CreateSessionBasedOnTestParams(connection_id, client_address))); 588 CreateSessionBasedOnTestParams(connection_id, client_address)));
599 589
600 // Process the first packet for the connection. 590 // Process the first packet for the connection.
601 ProcessPacket(client_address, connection_id, true, false, "foo"); 591 ProcessPacket(client_address, connection_id, true, false, SerializeCHLO());
602 if (ExpectStatelessReject()) { 592 if (ExpectStatelessReject()) {
603 // If this is a stateless reject, the crypto stream will close the 593 // If this is a stateless reject, the crypto stream will close the
604 // connection. 594 // connection.
605 session1_->connection()->CloseConnection( 595 session1_->connection()->CloseConnection(
606 QUIC_CRYPTO_HANDSHAKE_STATELESS_REJECT, "stateless reject", 596 QUIC_CRYPTO_HANDSHAKE_STATELESS_REJECT, "stateless reject",
607 ConnectionCloseBehavior::SILENT_CLOSE); 597 ConnectionCloseBehavior::SILENT_CLOSE);
608 } 598 }
609 599
610 // Send a second packet and check the results. If this is a stateless reject, 600 // Send a second packet and check the results. If this is a stateless reject,
611 // the existing connection_id will go on the time-wait list. 601 // the existing connection_id will go on the time-wait list.
612 EXPECT_EQ(ExpectStatelessReject(), 602 EXPECT_EQ(ExpectStatelessReject(),
613 time_wait_list_manager_->IsConnectionIdInTimeWait(connection_id)); 603 time_wait_list_manager_->IsConnectionIdInTimeWait(connection_id));
614 if (ExpectStatelessReject()) { 604 if (ExpectStatelessReject()) {
615 // The second packet will be processed on the time-wait list. 605 // The second packet will be processed on the time-wait list.
616 EXPECT_CALL(*time_wait_list_manager_, 606 EXPECT_CALL(*time_wait_list_manager_,
617 ProcessPacket(_, _, connection_id, _, _)) 607 ProcessPacket(_, _, connection_id, _, _))
618 .Times(1); 608 .Times(1);
619 } else { 609 } else {
620 // The second packet will trigger a packet-validation 610 // The second packet will trigger a packet-validation
621 EXPECT_CALL(*reinterpret_cast<MockConnection*>(session1_->connection()), 611 EXPECT_CALL(*reinterpret_cast<MockQuicConnection*>(session1_->connection()),
622 ProcessUdpPacket(_, _, _)) 612 ProcessUdpPacket(_, _, _))
623 .Times(1) 613 .Times(1)
624 .WillOnce(testing::WithArgs<2>( 614 .WillOnce(testing::WithArgs<2>(
625 Invoke(this, &QuicDispatcherTest::ValidatePacket))); 615 Invoke(this, &QuicDispatcherTest::ValidatePacket)));
626 } 616 }
627 ProcessPacket(client_address, connection_id, true, false, "foo"); 617 ProcessPacket(client_address, connection_id, true, false, "data");
628 } 618 }
629 619
630 // Verify the stopgap test: Packets with truncated connection IDs should be 620 // Verify the stopgap test: Packets with truncated connection IDs should be
631 // dropped. 621 // dropped.
632 class QuicDispatcherTestStrayPacketConnectionId : public QuicDispatcherTest {}; 622 class QuicDispatcherTestStrayPacketConnectionId : public QuicDispatcherTest {};
633 623
634 // Packets with truncated connection IDs should be dropped. 624 // Packets with truncated connection IDs should be dropped.
635 TEST_F(QuicDispatcherTestStrayPacketConnectionId, 625 TEST_F(QuicDispatcherTestStrayPacketConnectionId,
636 StrayPacketTruncatedConnectionId) { 626 StrayPacketTruncatedConnectionId) {
637 CreateTimeWaitListManager(); 627 CreateTimeWaitListManager();
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
677 writer_ = new BlockingWriter; 667 writer_ = new BlockingWriter;
678 QuicDispatcherPeer::UseWriter(&dispatcher_, writer_); 668 QuicDispatcherPeer::UseWriter(&dispatcher_, writer_);
679 669
680 IPEndPoint client_address(net::test::Loopback4(), 1); 670 IPEndPoint client_address(net::test::Loopback4(), 1);
681 671
682 EXPECT_CALL(dispatcher_, CreateQuicSession(_, client_address)) 672 EXPECT_CALL(dispatcher_, CreateQuicSession(_, client_address))
683 .WillOnce(testing::Return(CreateSession( 673 .WillOnce(testing::Return(CreateSession(
684 &dispatcher_, config_, 1, client_address, &helper_, &alarm_factory_, 674 &dispatcher_, config_, 1, client_address, &helper_, &alarm_factory_,
685 &crypto_config_, QuicDispatcherPeer::GetCache(&dispatcher_), 675 &crypto_config_, QuicDispatcherPeer::GetCache(&dispatcher_),
686 &session1_))); 676 &session1_)));
687 ProcessPacket(client_address, 1, true, false, "foo"); 677 ProcessPacket(client_address, 1, true, false, SerializeCHLO());
688 678
689 EXPECT_CALL(dispatcher_, CreateQuicSession(_, client_address)) 679 EXPECT_CALL(dispatcher_, CreateQuicSession(_, client_address))
690 .WillOnce(testing::Return(CreateSession( 680 .WillOnce(testing::Return(CreateSession(
691 &dispatcher_, config_, 2, client_address, &helper_, &alarm_factory_, 681 &dispatcher_, config_, 2, client_address, &helper_, &alarm_factory_,
692 &crypto_config_, QuicDispatcherPeer::GetCache(&dispatcher_), 682 &crypto_config_, QuicDispatcherPeer::GetCache(&dispatcher_),
693 &session2_))); 683 &session2_)));
694 ProcessPacket(client_address, 2, true, false, "bar"); 684 ProcessPacket(client_address, 2, true, false, SerializeCHLO());
695 685
696 blocked_list_ = QuicDispatcherPeer::GetWriteBlockedList(&dispatcher_); 686 blocked_list_ = QuicDispatcherPeer::GetWriteBlockedList(&dispatcher_);
697 } 687 }
698 688
699 void TearDown() override { 689 void TearDown() override {
700 EXPECT_CALL(*connection1(), CloseConnection(QUIC_PEER_GOING_AWAY, _, _)); 690 EXPECT_CALL(*connection1(), CloseConnection(QUIC_PEER_GOING_AWAY, _, _));
701 EXPECT_CALL(*connection2(), CloseConnection(QUIC_PEER_GOING_AWAY, _, _)); 691 EXPECT_CALL(*connection2(), CloseConnection(QUIC_PEER_GOING_AWAY, _, _));
702 dispatcher_.Shutdown(); 692 dispatcher_.Shutdown();
703 } 693 }
704 694
705 void SetBlocked() { writer_->write_blocked_ = true; } 695 void SetBlocked() { writer_->write_blocked_ = true; }
706 696
707 void BlockConnection2() { 697 void BlockConnection2() {
708 writer_->write_blocked_ = true; 698 writer_->write_blocked_ = true;
709 dispatcher_.OnWriteBlocked(connection2()); 699 dispatcher_.OnWriteBlocked(connection2());
710 } 700 }
711 701
712 protected: 702 protected:
713 MockConnectionHelper helper_; 703 MockQuicConnectionHelper helper_;
714 MockAlarmFactory alarm_factory_; 704 MockAlarmFactory alarm_factory_;
715 BlockingWriter* writer_; 705 BlockingWriter* writer_;
716 QuicDispatcher::WriteBlockedList* blocked_list_; 706 QuicDispatcher::WriteBlockedList* blocked_list_;
717 }; 707 };
718 708
719 TEST_F(QuicDispatcherWriteBlockedListTest, BasicOnCanWrite) { 709 TEST_F(QuicDispatcherWriteBlockedListTest, BasicOnCanWrite) {
720 // No OnCanWrite calls because no connections are blocked. 710 // No OnCanWrite calls because no connections are blocked.
721 dispatcher_.OnCanWrite(); 711 dispatcher_.OnCanWrite();
722 712
723 // Register connection 1 for events, and make sure it's notified. 713 // Register connection 1 for events, and make sure it's notified.
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after
843 833
844 // And we'll resume where we left off when we get another call. 834 // And we'll resume where we left off when we get another call.
845 EXPECT_CALL(*connection2(), OnCanWrite()); 835 EXPECT_CALL(*connection2(), OnCanWrite());
846 dispatcher_.OnCanWrite(); 836 dispatcher_.OnCanWrite();
847 EXPECT_FALSE(dispatcher_.HasPendingWrites()); 837 EXPECT_FALSE(dispatcher_.HasPendingWrites());
848 } 838 }
849 839
850 } // namespace 840 } // namespace
851 } // namespace test 841 } // namespace test
852 } // namespace net 842 } // namespace net
OLDNEW
« no previous file with comments | « net/tools/quic/quic_dispatcher.cc ('k') | net/tools/quic/quic_packet_printer_bin.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698