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

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

Issue 2825083003: Landing Recent QUIC changes until Mon Apr 17 2017 (Closed)
Patch Set: Format Created 3 years, 8 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_reader.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
11 #include "base/macros.h" 11 #include "base/macros.h"
12 #include "net/quic/core/crypto/crypto_handshake.h" 12 #include "net/quic/core/crypto/crypto_handshake.h"
13 #include "net/quic/core/crypto/quic_crypto_server_config.h" 13 #include "net/quic/core/crypto/quic_crypto_server_config.h"
14 #include "net/quic/core/crypto/quic_random.h" 14 #include "net/quic/core/crypto/quic_random.h"
15 #include "net/quic/core/quic_crypto_stream.h" 15 #include "net/quic/core/quic_crypto_stream.h"
16 #include "net/quic/core/quic_flags.h"
17 #include "net/quic/core/quic_utils.h" 16 #include "net/quic/core/quic_utils.h"
17 #include "net/quic/platform/api/quic_flags.h"
18 #include "net/quic/platform/api/quic_logging.h" 18 #include "net/quic/platform/api/quic_logging.h"
19 #include "net/quic/platform/api/quic_str_cat.h" 19 #include "net/quic/platform/api/quic_str_cat.h"
20 #include "net/quic/test_tools/crypto_test_utils.h" 20 #include "net/quic/test_tools/crypto_test_utils.h"
21 #include "net/quic/test_tools/fake_proof_source.h" 21 #include "net/quic/test_tools/fake_proof_source.h"
22 #include "net/quic/test_tools/quic_buffered_packet_store_peer.h" 22 #include "net/quic/test_tools/quic_buffered_packet_store_peer.h"
23 #include "net/quic/test_tools/quic_crypto_server_config_peer.h" 23 #include "net/quic/test_tools/quic_crypto_server_config_peer.h"
24 #include "net/quic/test_tools/quic_test_utils.h" 24 #include "net/quic/test_tools/quic_test_utils.h"
25 #include "net/quic/test_tools/quic_time_wait_list_manager_peer.h" 25 #include "net/quic/test_tools/quic_time_wait_list_manager_peer.h"
26 #include "net/test/gtest_util.h" 26 #include "net/test/gtest_util.h"
27 #include "net/tools/epoll_server/epoll_server.h" 27 #include "net/tools/epoll_server/epoll_server.h"
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
61 TestQuicSpdyServerSession(const QuicConfig& config, 61 TestQuicSpdyServerSession(const QuicConfig& config,
62 QuicConnection* connection, 62 QuicConnection* connection,
63 const QuicCryptoServerConfig* crypto_config, 63 const QuicCryptoServerConfig* crypto_config,
64 QuicCompressedCertsCache* compressed_certs_cache) 64 QuicCompressedCertsCache* compressed_certs_cache)
65 : QuicServerSessionBase(config, 65 : QuicServerSessionBase(config,
66 connection, 66 connection,
67 nullptr, 67 nullptr,
68 nullptr, 68 nullptr,
69 crypto_config, 69 crypto_config,
70 compressed_certs_cache), 70 compressed_certs_cache),
71 crypto_stream_(QuicServerSessionBase::GetCryptoStream()) {} 71 crypto_stream_(QuicServerSessionBase::GetMutableCryptoStream()) {}
72 72
73 ~TestQuicSpdyServerSession() override { delete connection(); }; 73 ~TestQuicSpdyServerSession() override { delete connection(); };
74 74
75 MOCK_METHOD3(OnConnectionClosed, 75 MOCK_METHOD3(OnConnectionClosed,
76 void(QuicErrorCode error, 76 void(QuicErrorCode error,
77 const string& error_details, 77 const string& error_details,
78 ConnectionCloseSource source)); 78 ConnectionCloseSource source));
79 MOCK_METHOD1(CreateIncomingDynamicStream, QuicSpdyStream*(QuicStreamId id)); 79 MOCK_METHOD1(CreateIncomingDynamicStream, QuicSpdyStream*(QuicStreamId id));
80 MOCK_METHOD1(CreateOutgoingDynamicStream, 80 MOCK_METHOD1(CreateOutgoingDynamicStream,
81 QuicSpdyStream*(SpdyPriority priority)); 81 QuicSpdyStream*(SpdyPriority priority));
82 82
83 QuicCryptoServerStreamBase* CreateQuicCryptoServerStream( 83 QuicCryptoServerStreamBase* CreateQuicCryptoServerStream(
84 const QuicCryptoServerConfig* crypto_config, 84 const QuicCryptoServerConfig* crypto_config,
85 QuicCompressedCertsCache* compressed_certs_cache) override { 85 QuicCompressedCertsCache* compressed_certs_cache) override {
86 return new QuicCryptoServerStream( 86 return new QuicCryptoServerStream(
87 crypto_config, compressed_certs_cache, 87 crypto_config, compressed_certs_cache,
88 FLAGS_quic_reloadable_flag_enable_quic_stateless_reject_support, this, 88 FLAGS_quic_reloadable_flag_enable_quic_stateless_reject_support, this,
89 stream_helper()); 89 stream_helper());
90 } 90 }
91 91
92 void SetCryptoStream(QuicCryptoServerStream* crypto_stream) { 92 void SetCryptoStream(QuicCryptoServerStream* crypto_stream) {
93 crypto_stream_ = crypto_stream; 93 crypto_stream_ = crypto_stream;
94 } 94 }
95 95
96 QuicCryptoServerStreamBase* GetCryptoStream() override { 96 QuicCryptoServerStreamBase* GetMutableCryptoStream() override {
97 return crypto_stream_; 97 return crypto_stream_;
98 } 98 }
99 99
100 const QuicCryptoServerStreamBase* GetCryptoStream() const override {
101 return crypto_stream_;
102 }
103
100 QuicCryptoServerStream::Helper* stream_helper() { 104 QuicCryptoServerStream::Helper* stream_helper() {
101 return QuicServerSessionBase::stream_helper(); 105 return QuicServerSessionBase::stream_helper();
102 } 106 }
103 107
104 private: 108 private:
105 QuicCryptoServerStreamBase* crypto_stream_; 109 QuicCryptoServerStreamBase* crypto_stream_;
106 110
107 DISALLOW_COPY_AND_ASSIGN(TestQuicSpdyServerSession); 111 DISALLOW_COPY_AND_ASSIGN(TestQuicSpdyServerSession);
108 }; 112 };
109 113
(...skipping 411 matching lines...) Expand 10 before | Expand all | Expand 10 after
521 EXPECT_CALL(*time_wait_list_manager_, AddConnectionIdToTimeWait(_, _, _, _)) 525 EXPECT_CALL(*time_wait_list_manager_, AddConnectionIdToTimeWait(_, _, _, _))
522 .Times(1); 526 .Times(1);
523 // A packet whose packet number is one to large to be allowed to start a 527 // A packet whose packet number is one to large to be allowed to start a
524 // connection. 528 // connection.
525 ProcessPacket(client_address, connection_id, true, SerializeCHLO(), 529 ProcessPacket(client_address, connection_id, true, SerializeCHLO(),
526 PACKET_8BYTE_CONNECTION_ID, PACKET_6BYTE_PACKET_NUMBER, 530 PACKET_8BYTE_CONNECTION_ID, PACKET_6BYTE_PACKET_NUMBER,
527 QuicDispatcher::kMaxReasonableInitialPacketNumber + 1); 531 QuicDispatcher::kMaxReasonableInitialPacketNumber + 1);
528 } 532 }
529 533
530 TEST_F(QuicDispatcherTest, SupportedVersionsChangeInFlight) { 534 TEST_F(QuicDispatcherTest, SupportedVersionsChangeInFlight) {
531 static_assert(arraysize(kSupportedQuicVersions) == 6u, 535 static_assert(arraysize(kSupportedQuicVersions) == 5u,
532 "Supported versions out of sync"); 536 "Supported versions out of sync");
533 FLAGS_quic_reloadable_flag_quic_disable_version_34 = false;
534 FLAGS_quic_reloadable_flag_quic_enable_version_36_v3 = true;
535 FLAGS_quic_reloadable_flag_quic_enable_version_37 = true;
536 FLAGS_quic_reloadable_flag_quic_enable_version_38 = true; 537 FLAGS_quic_reloadable_flag_quic_enable_version_38 = true;
537 base::SetFlag(&FLAGS_quic_enable_version_39, true); 538 SetQuicFlag(&FLAGS_quic_enable_version_39, true);
538 QuicSocketAddress client_address(QuicIpAddress::Loopback4(), 1); 539 QuicSocketAddress client_address(QuicIpAddress::Loopback4(), 1);
539 server_address_ = QuicSocketAddress(QuicIpAddress::Any4(), 5); 540 server_address_ = QuicSocketAddress(QuicIpAddress::Any4(), 5);
540 QuicConnectionId connection_id = 1; 541 QuicConnectionId connection_id = 1;
541 542
542 EXPECT_CALL(*dispatcher_, CreateQuicSession(connection_id, client_address)) 543 EXPECT_CALL(*dispatcher_, CreateQuicSession(connection_id, client_address))
543 .Times(0); 544 .Times(0);
544 ProcessPacket(client_address, connection_id, true, 545 ProcessPacket(client_address, connection_id, true,
545 static_cast<QuicVersion>(QuicVersionMin() - 1), SerializeCHLO(), 546 static_cast<QuicVersion>(QuicVersionMin() - 1), SerializeCHLO(),
546 PACKET_8BYTE_CONNECTION_ID, PACKET_6BYTE_PACKET_NUMBER, 1); 547 PACKET_8BYTE_CONNECTION_ID, PACKET_6BYTE_PACKET_NUMBER, 1);
547 ++connection_id; 548 ++connection_id;
(...skipping 19 matching lines...) Expand all
567 EXPECT_CALL(*reinterpret_cast<MockQuicConnection*>(session1_->connection()), 568 EXPECT_CALL(*reinterpret_cast<MockQuicConnection*>(session1_->connection()),
568 ProcessUdpPacket(_, _, _)) 569 ProcessUdpPacket(_, _, _))
569 .WillOnce(testing::WithArgs<2>( 570 .WillOnce(testing::WithArgs<2>(
570 Invoke(CreateFunctor(&QuicDispatcherTest::ValidatePacket, 571 Invoke(CreateFunctor(&QuicDispatcherTest::ValidatePacket,
571 base::Unretained(this), connection_id)))); 572 base::Unretained(this), connection_id))));
572 ProcessPacket(client_address, connection_id, true, QuicVersionMax(), 573 ProcessPacket(client_address, connection_id, true, QuicVersionMax(),
573 SerializeCHLO(), PACKET_8BYTE_CONNECTION_ID, 574 SerializeCHLO(), PACKET_8BYTE_CONNECTION_ID,
574 PACKET_6BYTE_PACKET_NUMBER, 1); 575 PACKET_6BYTE_PACKET_NUMBER, 1);
575 576
576 // Turn off version 39. 577 // Turn off version 39.
577 base::SetFlag(&FLAGS_quic_enable_version_39, false); 578 SetQuicFlag(&FLAGS_quic_enable_version_39, false);
578 ++connection_id; 579 ++connection_id;
579 EXPECT_CALL(*dispatcher_, CreateQuicSession(connection_id, client_address)) 580 EXPECT_CALL(*dispatcher_, CreateQuicSession(connection_id, client_address))
580 .Times(0); 581 .Times(0);
581 ProcessPacket(client_address, connection_id, true, QUIC_VERSION_39, 582 ProcessPacket(client_address, connection_id, true, QUIC_VERSION_39,
582 SerializeCHLO(), PACKET_8BYTE_CONNECTION_ID, 583 SerializeCHLO(), PACKET_8BYTE_CONNECTION_ID,
583 PACKET_6BYTE_PACKET_NUMBER, 1); 584 PACKET_6BYTE_PACKET_NUMBER, 1);
584 585
585 // Turn on version 39. 586 // Turn on version 39.
586 base::SetFlag(&FLAGS_quic_enable_version_39, true); 587 SetQuicFlag(&FLAGS_quic_enable_version_39, true);
587 ++connection_id; 588 ++connection_id;
588 EXPECT_CALL(*dispatcher_, CreateQuicSession(connection_id, client_address)) 589 EXPECT_CALL(*dispatcher_, CreateQuicSession(connection_id, client_address))
589 .WillOnce(testing::Return(CreateSession( 590 .WillOnce(testing::Return(CreateSession(
590 dispatcher_.get(), config_, connection_id, client_address, 591 dispatcher_.get(), config_, connection_id, client_address,
591 &mock_helper_, &mock_alarm_factory_, &crypto_config_, 592 &mock_helper_, &mock_alarm_factory_, &crypto_config_,
592 QuicDispatcherPeer::GetCache(dispatcher_.get()), &session1_))); 593 QuicDispatcherPeer::GetCache(dispatcher_.get()), &session1_)));
593 EXPECT_CALL(*reinterpret_cast<MockQuicConnection*>(session1_->connection()), 594 EXPECT_CALL(*reinterpret_cast<MockQuicConnection*>(session1_->connection()),
594 ProcessUdpPacket(_, _, _)) 595 ProcessUdpPacket(_, _, _))
595 .WillOnce(testing::WithArgs<2>( 596 .WillOnce(testing::WithArgs<2>(
596 Invoke(CreateFunctor(&QuicDispatcherTest::ValidatePacket, 597 Invoke(CreateFunctor(&QuicDispatcherTest::ValidatePacket,
597 base::Unretained(this), connection_id)))); 598 base::Unretained(this), connection_id))));
598 ProcessPacket(client_address, connection_id, true, QUIC_VERSION_39, 599 ProcessPacket(client_address, connection_id, true, QUIC_VERSION_39,
599 SerializeCHLO(), PACKET_8BYTE_CONNECTION_ID, 600 SerializeCHLO(), PACKET_8BYTE_CONNECTION_ID,
600 PACKET_6BYTE_PACKET_NUMBER, 1); 601 PACKET_6BYTE_PACKET_NUMBER, 1);
601
602 // Turn off version 36.
603 FLAGS_quic_reloadable_flag_quic_enable_version_36_v3 = false;
604 ++connection_id;
605 EXPECT_CALL(*dispatcher_, CreateQuicSession(connection_id, client_address))
606 .Times(0);
607 ProcessPacket(client_address, connection_id, true, QUIC_VERSION_36,
608 SerializeCHLO(), PACKET_8BYTE_CONNECTION_ID,
609 PACKET_6BYTE_PACKET_NUMBER, 1);
610
611 // Turn on version 36.
612 FLAGS_quic_reloadable_flag_quic_enable_version_36_v3 = true;
613 ++connection_id;
614 EXPECT_CALL(*dispatcher_, CreateQuicSession(connection_id, client_address))
615 .WillOnce(testing::Return(CreateSession(
616 dispatcher_.get(), config_, connection_id, client_address,
617 &mock_helper_, &mock_alarm_factory_, &crypto_config_,
618 QuicDispatcherPeer::GetCache(dispatcher_.get()), &session1_)));
619 EXPECT_CALL(*reinterpret_cast<MockQuicConnection*>(session1_->connection()),
620 ProcessUdpPacket(_, _, _))
621 .WillOnce(testing::WithArgs<2>(
622 Invoke(CreateFunctor(&QuicDispatcherTest::ValidatePacket,
623 base::Unretained(this), connection_id))));
624 ProcessPacket(client_address, connection_id, true, QUIC_VERSION_35,
625 SerializeCHLO(), PACKET_8BYTE_CONNECTION_ID,
626 PACKET_6BYTE_PACKET_NUMBER, 1);
627
628 // Turn off version 34.
629 FLAGS_quic_reloadable_flag_quic_disable_version_34 = true;
630 ++connection_id;
631 EXPECT_CALL(*dispatcher_, CreateQuicSession(connection_id, client_address))
632 .Times(0);
633 ProcessPacket(client_address, connection_id, true, QUIC_VERSION_34,
634 SerializeCHLO(), PACKET_8BYTE_CONNECTION_ID,
635 PACKET_6BYTE_PACKET_NUMBER, 1);
636
637 // Turn on version 34.
638 FLAGS_quic_reloadable_flag_quic_disable_version_34 = false;
639 ++connection_id;
640 EXPECT_CALL(*dispatcher_, CreateQuicSession(connection_id, client_address))
641 .WillOnce(testing::Return(CreateSession(
642 dispatcher_.get(), config_, connection_id, client_address,
643 &mock_helper_, &mock_alarm_factory_, &crypto_config_,
644 QuicDispatcherPeer::GetCache(dispatcher_.get()), &session1_)));
645 EXPECT_CALL(*reinterpret_cast<MockQuicConnection*>(session1_->connection()),
646 ProcessUdpPacket(_, _, _))
647 .WillOnce(testing::WithArgs<2>(
648 Invoke(CreateFunctor(&QuicDispatcherTest::ValidatePacket,
649 base::Unretained(this), connection_id))));
650 ProcessPacket(client_address, connection_id, true, QUIC_VERSION_34,
651 SerializeCHLO(), PACKET_8BYTE_CONNECTION_ID,
652 PACKET_6BYTE_PACKET_NUMBER, 1);
653 } 602 }
654 603
655 // Enables mocking of the handshake-confirmation for stateless rejects. 604 // Enables mocking of the handshake-confirmation for stateless rejects.
656 class MockQuicCryptoServerStream : public QuicCryptoServerStream { 605 class MockQuicCryptoServerStream : public QuicCryptoServerStream {
657 public: 606 public:
658 MockQuicCryptoServerStream(const QuicCryptoServerConfig& crypto_config, 607 MockQuicCryptoServerStream(const QuicCryptoServerConfig& crypto_config,
659 QuicCompressedCertsCache* compressed_certs_cache, 608 QuicCompressedCertsCache* compressed_certs_cache,
660 QuicServerSessionBase* session, 609 QuicServerSessionBase* session,
661 QuicCryptoServerStream::Helper* helper) 610 QuicCryptoServerStream::Helper* helper)
662 : QuicCryptoServerStream( 611 : QuicCryptoServerStream(
(...skipping 1431 matching lines...) Expand 10 before | Expand all | Expand 10 after
2094 check.Call(2); 2043 check.Call(2);
2095 GetFakeProofSource()->InvokePendingCallback(0); 2044 GetFakeProofSource()->InvokePendingCallback(0);
2096 ASSERT_EQ(GetFakeProofSource()->NumPendingCallbacks(), 0); 2045 ASSERT_EQ(GetFakeProofSource()->NumPendingCallbacks(), 0);
2097 EXPECT_FALSE(store->HasBufferedPackets(conn_id)); 2046 EXPECT_FALSE(store->HasBufferedPackets(conn_id));
2098 EXPECT_FALSE(time_wait_list_manager_->IsConnectionIdInTimeWait(conn_id)); 2047 EXPECT_FALSE(time_wait_list_manager_->IsConnectionIdInTimeWait(conn_id));
2099 } 2048 }
2100 2049
2101 } // namespace 2050 } // namespace
2102 } // namespace test 2051 } // namespace test
2103 } // namespace net 2052 } // namespace net
OLDNEW
« no previous file with comments | « net/tools/quic/quic_dispatcher.cc ('k') | net/tools/quic/quic_packet_reader.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698