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 <string> | 7 #include <string> |
8 | 8 |
9 #include "base/strings/string_piece.h" | 9 #include "base/strings/string_piece.h" |
10 #include "net/quic/crypto/crypto_handshake.h" | 10 #include "net/quic/crypto/crypto_handshake.h" |
(...skipping 184 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
195 | 195 |
196 EXPECT_CALL(*reinterpret_cast<MockConnection*>(session1_->connection()), | 196 EXPECT_CALL(*reinterpret_cast<MockConnection*>(session1_->connection()), |
197 SendConnectionClose(QUIC_PEER_GOING_AWAY)); | 197 SendConnectionClose(QUIC_PEER_GOING_AWAY)); |
198 | 198 |
199 dispatcher_.Shutdown(); | 199 dispatcher_.Shutdown(); |
200 } | 200 } |
201 | 201 |
202 class MockTimeWaitListManager : public QuicTimeWaitListManager { | 202 class MockTimeWaitListManager : public QuicTimeWaitListManager { |
203 public: | 203 public: |
204 MockTimeWaitListManager(QuicPacketWriter* writer, | 204 MockTimeWaitListManager(QuicPacketWriter* writer, |
| 205 QuicServerSessionVisitor* visitor, |
205 EpollServer* eps) | 206 EpollServer* eps) |
206 : QuicTimeWaitListManager(writer, eps, QuicSupportedVersions()) { | 207 : QuicTimeWaitListManager(writer, visitor, eps, QuicSupportedVersions()) { |
207 } | 208 } |
208 | 209 |
209 MOCK_METHOD4(ProcessPacket, void(const IPEndPoint& server_address, | 210 MOCK_METHOD4(ProcessPacket, void(const IPEndPoint& server_address, |
210 const IPEndPoint& client_address, | 211 const IPEndPoint& client_address, |
211 QuicGuid guid, | 212 QuicGuid guid, |
212 QuicPacketSequenceNumber sequence_number)); | 213 QuicPacketSequenceNumber sequence_number)); |
213 }; | 214 }; |
214 | 215 |
215 TEST_F(QuicDispatcherTest, TimeWaitListManager) { | 216 TEST_F(QuicDispatcherTest, TimeWaitListManager) { |
216 MockTimeWaitListManager* time_wait_list_manager = | 217 MockTimeWaitListManager* time_wait_list_manager = |
217 new MockTimeWaitListManager( | 218 new MockTimeWaitListManager( |
218 QuicDispatcherPeer::GetWriter(&dispatcher_), &eps_); | 219 QuicDispatcherPeer::GetWriter(&dispatcher_), &dispatcher_, &eps_); |
219 // dispatcher takes the ownership of time_wait_list_manager. | 220 // dispatcher takes the ownership of time_wait_list_manager. |
220 QuicDispatcherPeer::SetTimeWaitListManager(&dispatcher_, | 221 QuicDispatcherPeer::SetTimeWaitListManager(&dispatcher_, |
221 time_wait_list_manager); | 222 time_wait_list_manager); |
222 // Create a new session. | 223 // Create a new session. |
223 IPEndPoint addr(net::test::Loopback4(), 1); | 224 IPEndPoint addr(net::test::Loopback4(), 1); |
224 QuicGuid guid = 1; | 225 QuicGuid guid = 1; |
225 EXPECT_CALL(dispatcher_, CreateQuicSession(guid, _, addr)) | 226 EXPECT_CALL(dispatcher_, CreateQuicSession(guid, _, addr)) |
226 .WillOnce(testing::Return(CreateSession( | 227 .WillOnce(testing::Return(CreateSession( |
227 &dispatcher_, guid, addr, &session1_))); | 228 &dispatcher_, guid, addr, &session1_))); |
228 ProcessPacket(addr, guid, true, "foo"); | 229 ProcessPacket(addr, guid, true, "foo"); |
(...skipping 21 matching lines...) Expand all Loading... |
250 | 251 |
251 // Dispatcher forwards subsequent packets for this guid to the time wait list | 252 // Dispatcher forwards subsequent packets for this guid to the time wait list |
252 // manager. | 253 // manager. |
253 EXPECT_CALL(*time_wait_list_manager, ProcessPacket(_, _, guid, _)).Times(1); | 254 EXPECT_CALL(*time_wait_list_manager, ProcessPacket(_, _, guid, _)).Times(1); |
254 ProcessPacket(addr, guid, true, "foo"); | 255 ProcessPacket(addr, guid, true, "foo"); |
255 } | 256 } |
256 | 257 |
257 TEST_F(QuicDispatcherTest, StrayPacketToTimeWaitListManager) { | 258 TEST_F(QuicDispatcherTest, StrayPacketToTimeWaitListManager) { |
258 MockTimeWaitListManager* time_wait_list_manager = | 259 MockTimeWaitListManager* time_wait_list_manager = |
259 new MockTimeWaitListManager( | 260 new MockTimeWaitListManager( |
260 QuicDispatcherPeer::GetWriter(&dispatcher_), &eps_); | 261 QuicDispatcherPeer::GetWriter(&dispatcher_), &dispatcher_, &eps_); |
261 // dispatcher takes the ownership of time_wait_list_manager. | 262 // dispatcher takes the ownership of time_wait_list_manager. |
262 QuicDispatcherPeer::SetTimeWaitListManager(&dispatcher_, | 263 QuicDispatcherPeer::SetTimeWaitListManager(&dispatcher_, |
263 time_wait_list_manager); | 264 time_wait_list_manager); |
264 | 265 |
265 IPEndPoint addr(net::test::Loopback4(), 1); | 266 IPEndPoint addr(net::test::Loopback4(), 1); |
266 QuicGuid guid = 1; | 267 QuicGuid guid = 1; |
267 // Dispatcher forwards all packets for this guid to the time wait list | 268 // Dispatcher forwards all packets for this guid to the time wait list |
268 // manager. | 269 // manager. |
269 EXPECT_CALL(dispatcher_, CreateQuicSession(_, _, _)).Times(0); | 270 EXPECT_CALL(dispatcher_, CreateQuicSession(_, _, _)).Times(0); |
270 EXPECT_CALL(*time_wait_list_manager, ProcessPacket(_, _, guid, _)).Times(1); | 271 EXPECT_CALL(*time_wait_list_manager, ProcessPacket(_, _, guid, _)).Times(1); |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
317 blocked_list_ = dispatcher_.write_blocked_list(); | 318 blocked_list_ = dispatcher_.write_blocked_list(); |
318 } | 319 } |
319 | 320 |
320 virtual void TearDown() { | 321 virtual void TearDown() { |
321 EXPECT_CALL(*connection1(), SendConnectionClose(QUIC_PEER_GOING_AWAY)); | 322 EXPECT_CALL(*connection1(), SendConnectionClose(QUIC_PEER_GOING_AWAY)); |
322 EXPECT_CALL(*connection2(), SendConnectionClose(QUIC_PEER_GOING_AWAY)); | 323 EXPECT_CALL(*connection2(), SendConnectionClose(QUIC_PEER_GOING_AWAY)); |
323 dispatcher_.Shutdown(); | 324 dispatcher_.Shutdown(); |
324 } | 325 } |
325 | 326 |
326 bool SetBlocked() { | 327 bool SetBlocked() { |
327 writer_->write_blocked_ = true;; | 328 writer_->write_blocked_ = true; |
328 return true; | 329 return true; |
329 } | 330 } |
330 | 331 |
331 protected: | 332 protected: |
332 BlockingWriter* writer_; | 333 BlockingWriter* writer_; |
333 QuicDispatcher::WriteBlockedList* blocked_list_; | 334 QuicDispatcher::WriteBlockedList* blocked_list_; |
334 }; | 335 }; |
335 | 336 |
336 TEST_F(QuicWriteBlockedListTest, BasicOnCanWrite) { | 337 TEST_F(QuicWriteBlockedListTest, BasicOnCanWrite) { |
337 // No OnCanWrite calls because no connections are blocked. | 338 // No OnCanWrite calls because no connections are blocked. |
338 dispatcher_.OnCanWrite(); | 339 dispatcher_.OnCanWrite(); |
339 | 340 |
340 // Register connection 1 for events, and make sure it's nofitied. | 341 // Register connection 1 for events, and make sure it's notified. |
341 blocked_list_->insert(make_pair(connection1(), true)); | 342 SetBlocked(); |
| 343 dispatcher_.OnWriteBlocked(connection1()); |
342 EXPECT_CALL(*connection1(), OnCanWrite()); | 344 EXPECT_CALL(*connection1(), OnCanWrite()); |
343 dispatcher_.OnCanWrite(); | 345 dispatcher_.OnCanWrite(); |
344 | 346 |
345 // It should get only one notification. | 347 // It should get only one notification. |
346 EXPECT_CALL(*connection1(), OnCanWrite()).Times(0); | 348 EXPECT_CALL(*connection1(), OnCanWrite()).Times(0); |
347 EXPECT_FALSE(dispatcher_.OnCanWrite()); | 349 EXPECT_FALSE(dispatcher_.OnCanWrite()); |
348 } | 350 } |
349 | 351 |
350 TEST_F(QuicWriteBlockedListTest, OnCanWriteOrder) { | 352 TEST_F(QuicWriteBlockedListTest, OnCanWriteOrder) { |
351 // Make sure we handle events in order. | 353 // Make sure we handle events in order. |
352 InSequence s; | 354 InSequence s; |
353 blocked_list_->insert(make_pair(connection1(), true)); | 355 SetBlocked(); |
354 blocked_list_->insert(make_pair(connection2(), true)); | 356 dispatcher_.OnWriteBlocked(connection1()); |
| 357 dispatcher_.OnWriteBlocked(connection2()); |
355 EXPECT_CALL(*connection1(), OnCanWrite()); | 358 EXPECT_CALL(*connection1(), OnCanWrite()); |
356 EXPECT_CALL(*connection2(), OnCanWrite()); | 359 EXPECT_CALL(*connection2(), OnCanWrite()); |
357 dispatcher_.OnCanWrite(); | 360 dispatcher_.OnCanWrite(); |
358 | 361 |
359 // Check the other ordering. | 362 // Check the other ordering. |
360 blocked_list_->insert(make_pair(connection2(), true)); | 363 SetBlocked(); |
361 blocked_list_->insert(make_pair(connection1(), true)); | 364 dispatcher_.OnWriteBlocked(connection2()); |
| 365 dispatcher_.OnWriteBlocked(connection1()); |
362 EXPECT_CALL(*connection2(), OnCanWrite()); | 366 EXPECT_CALL(*connection2(), OnCanWrite()); |
363 EXPECT_CALL(*connection1(), OnCanWrite()); | 367 EXPECT_CALL(*connection1(), OnCanWrite()); |
364 dispatcher_.OnCanWrite(); | 368 dispatcher_.OnCanWrite(); |
365 } | 369 } |
366 | 370 |
367 TEST_F(QuicWriteBlockedListTest, OnCanWriteRemove) { | 371 TEST_F(QuicWriteBlockedListTest, OnCanWriteRemove) { |
368 // Add and remove one connction. | 372 // Add and remove one connction. |
369 blocked_list_->insert(make_pair(connection1(), true)); | 373 SetBlocked(); |
| 374 dispatcher_.OnWriteBlocked(connection1()); |
370 blocked_list_->erase(connection1()); | 375 blocked_list_->erase(connection1()); |
371 EXPECT_CALL(*connection1(), OnCanWrite()).Times(0); | 376 EXPECT_CALL(*connection1(), OnCanWrite()).Times(0); |
372 dispatcher_.OnCanWrite(); | 377 dispatcher_.OnCanWrite(); |
373 | 378 |
374 // Add and remove one connction and make sure it doesn't affect others. | 379 // Add and remove one connction and make sure it doesn't affect others. |
375 blocked_list_->insert(make_pair(connection1(), true)); | 380 SetBlocked(); |
376 blocked_list_->insert(make_pair(connection2(), true)); | 381 dispatcher_.OnWriteBlocked(connection1()); |
| 382 dispatcher_.OnWriteBlocked(connection2()); |
377 blocked_list_->erase(connection1()); | 383 blocked_list_->erase(connection1()); |
378 EXPECT_CALL(*connection2(), OnCanWrite()); | 384 EXPECT_CALL(*connection2(), OnCanWrite()); |
379 dispatcher_.OnCanWrite(); | 385 dispatcher_.OnCanWrite(); |
380 | 386 |
381 // Add it, remove it, and add it back and make sure things are OK. | 387 // Add it, remove it, and add it back and make sure things are OK. |
382 blocked_list_->insert(make_pair(connection1(), true)); | 388 SetBlocked(); |
| 389 dispatcher_.OnWriteBlocked(connection1()); |
383 blocked_list_->erase(connection1()); | 390 blocked_list_->erase(connection1()); |
384 blocked_list_->insert(make_pair(connection1(), true)); | 391 dispatcher_.OnWriteBlocked(connection1()); |
385 EXPECT_CALL(*connection1(), OnCanWrite()).Times(1); | 392 EXPECT_CALL(*connection1(), OnCanWrite()).Times(1); |
386 dispatcher_.OnCanWrite(); | 393 dispatcher_.OnCanWrite(); |
387 } | 394 } |
388 | 395 |
389 TEST_F(QuicWriteBlockedListTest, DoubleAdd) { | 396 TEST_F(QuicWriteBlockedListTest, DoubleAdd) { |
390 // Make sure a double add does not necessitate a double remove. | 397 // Make sure a double add does not necessitate a double remove. |
391 blocked_list_->insert(make_pair(connection1(), true)); | 398 SetBlocked(); |
392 blocked_list_->insert(make_pair(connection1(), true)); | 399 dispatcher_.OnWriteBlocked(connection1()); |
| 400 dispatcher_.OnWriteBlocked(connection1()); |
393 blocked_list_->erase(connection1()); | 401 blocked_list_->erase(connection1()); |
394 EXPECT_CALL(*connection1(), OnCanWrite()).Times(0); | 402 EXPECT_CALL(*connection1(), OnCanWrite()).Times(0); |
395 dispatcher_.OnCanWrite(); | 403 dispatcher_.OnCanWrite(); |
396 | 404 |
397 // Make sure a double add does not result in two OnCanWrite calls. | 405 // Make sure a double add does not result in two OnCanWrite calls. |
398 blocked_list_->insert(make_pair(connection1(), true)); | 406 SetBlocked(); |
399 blocked_list_->insert(make_pair(connection1(), true)); | 407 dispatcher_.OnWriteBlocked(connection1()); |
| 408 dispatcher_.OnWriteBlocked(connection1()); |
400 EXPECT_CALL(*connection1(), OnCanWrite()).Times(1); | 409 EXPECT_CALL(*connection1(), OnCanWrite()).Times(1); |
401 dispatcher_.OnCanWrite(); | 410 dispatcher_.OnCanWrite(); |
402 } | 411 } |
403 | 412 |
404 TEST_F(QuicWriteBlockedListTest, OnCanWriteHandleBlock) { | 413 TEST_F(QuicWriteBlockedListTest, OnCanWriteHandleBlock) { |
405 // Finally make sure if we write block on a write call, we stop calling. | 414 // Finally make sure if we write block on a write call, we stop calling. |
406 InSequence s; | 415 InSequence s; |
407 blocked_list_->insert(make_pair(connection1(), true)); | 416 SetBlocked(); |
408 blocked_list_->insert(make_pair(connection2(), true)); | 417 dispatcher_.OnWriteBlocked(connection1()); |
| 418 dispatcher_.OnWriteBlocked(connection2()); |
409 EXPECT_CALL(*connection1(), OnCanWrite()).WillOnce( | 419 EXPECT_CALL(*connection1(), OnCanWrite()).WillOnce( |
410 Invoke(this, &QuicWriteBlockedListTest::SetBlocked)); | 420 Invoke(this, &QuicWriteBlockedListTest::SetBlocked)); |
411 EXPECT_CALL(*connection2(), OnCanWrite()).Times(0); | 421 EXPECT_CALL(*connection2(), OnCanWrite()).Times(0); |
412 dispatcher_.OnCanWrite(); | 422 dispatcher_.OnCanWrite(); |
413 | 423 |
414 // And we'll resume where we left off when we get another call. | 424 // And we'll resume where we left off when we get another call. |
415 EXPECT_CALL(*connection2(), OnCanWrite()); | 425 EXPECT_CALL(*connection2(), OnCanWrite()); |
416 dispatcher_.OnCanWrite(); | 426 dispatcher_.OnCanWrite(); |
417 } | 427 } |
418 | 428 |
419 TEST_F(QuicWriteBlockedListTest, LimitedWrites) { | 429 TEST_F(QuicWriteBlockedListTest, LimitedWrites) { |
420 // Make sure we call both writers. The first will register for more writing | 430 // Make sure we call both writers. The first will register for more writing |
421 // but should not be immediately called due to limits. | 431 // but should not be immediately called due to limits. |
422 InSequence s; | 432 InSequence s; |
423 blocked_list_->insert(make_pair(connection1(), true)); | 433 SetBlocked(); |
424 blocked_list_->insert(make_pair(connection2(), true)); | 434 dispatcher_.OnWriteBlocked(connection1()); |
| 435 dispatcher_.OnWriteBlocked(connection2()); |
425 EXPECT_CALL(*connection1(), OnCanWrite()).WillOnce(Return(true)); | 436 EXPECT_CALL(*connection1(), OnCanWrite()).WillOnce(Return(true)); |
426 EXPECT_CALL(*connection2(), OnCanWrite()).WillOnce(Return(false)); | 437 EXPECT_CALL(*connection2(), OnCanWrite()).WillOnce(Return(false)); |
427 dispatcher_.OnCanWrite(); | 438 dispatcher_.OnCanWrite(); |
428 | 439 |
429 // Now call OnCanWrite again, and connection1 should get its second chance | 440 // Now call OnCanWrite again, and connection1 should get its second chance |
430 EXPECT_CALL(*connection1(), OnCanWrite()); | 441 EXPECT_CALL(*connection1(), OnCanWrite()); |
431 dispatcher_.OnCanWrite(); | 442 dispatcher_.OnCanWrite(); |
432 } | 443 } |
433 | 444 |
434 TEST_F(QuicWriteBlockedListTest, TestWriteLimits) { | 445 TEST_F(QuicWriteBlockedListTest, TestWriteLimits) { |
435 // Finally make sure if we write block on a write call, we stop calling. | 446 // Finally make sure if we write block on a write call, we stop calling. |
436 InSequence s; | 447 InSequence s; |
437 blocked_list_->insert(make_pair(connection1(), true)); | 448 SetBlocked(); |
438 blocked_list_->insert(make_pair(connection2(), true)); | 449 dispatcher_.OnWriteBlocked(connection1()); |
| 450 dispatcher_.OnWriteBlocked(connection2()); |
439 EXPECT_CALL(*connection1(), OnCanWrite()).WillOnce( | 451 EXPECT_CALL(*connection1(), OnCanWrite()).WillOnce( |
440 Invoke(this, &QuicWriteBlockedListTest::SetBlocked)); | 452 Invoke(this, &QuicWriteBlockedListTest::SetBlocked)); |
441 EXPECT_CALL(*connection2(), OnCanWrite()).Times(0); | 453 EXPECT_CALL(*connection2(), OnCanWrite()).Times(0); |
442 dispatcher_.OnCanWrite(); | 454 dispatcher_.OnCanWrite(); |
443 | 455 |
444 // And we'll resume where we left off when we get another call. | 456 // And we'll resume where we left off when we get another call. |
445 EXPECT_CALL(*connection2(), OnCanWrite()); | 457 EXPECT_CALL(*connection2(), OnCanWrite()); |
446 dispatcher_.OnCanWrite(); | 458 dispatcher_.OnCanWrite(); |
447 } | 459 } |
448 | 460 |
449 } // namespace | 461 } // namespace |
450 } // namespace test | 462 } // namespace test |
451 } // namespace tools | 463 } // namespace tools |
452 } // namespace net | 464 } // namespace net |
OLD | NEW |