X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=src%2Fnet%2Ftools%2Fquic%2Fquic_dispatcher_test.cc;h=db8b76a9710781047befc36efdc7bcc9769290bd;hb=004985e17e624662a4c85c76a7654039dc83f028;hp=fa63c2f047f62cec7d502f2d37e0f86ac3842d1d;hpb=2f108dbacb161091e42a3479f4e171339b7e7623;p=platform%2Fframework%2Fweb%2Fcrosswalk.git diff --git a/src/net/tools/quic/quic_dispatcher_test.cc b/src/net/tools/quic/quic_dispatcher_test.cc index fa63c2f..db8b76a 100644 --- a/src/net/tools/quic/quic_dispatcher_test.cc +++ b/src/net/tools/quic/quic_dispatcher_test.cc @@ -11,6 +11,7 @@ #include "net/quic/crypto/quic_crypto_server_config.h" #include "net/quic/crypto/quic_random.h" #include "net/quic/quic_crypto_stream.h" +#include "net/quic/quic_flags.h" #include "net/quic/quic_utils.h" #include "net/quic/test_tools/quic_test_utils.h" #include "net/tools/epoll_server/epoll_server.h" @@ -43,7 +44,11 @@ class TestDispatcher : public QuicDispatcher { explicit TestDispatcher(const QuicConfig& config, const QuicCryptoServerConfig& crypto_config, EpollServer* eps) - : QuicDispatcher(config, crypto_config, QuicSupportedVersions(), eps) { + : QuicDispatcher(config, + crypto_config, + QuicSupportedVersions(), + eps, + kInitialFlowControlWindowForTest) { } MOCK_METHOD3(CreateQuicSession, QuicSession*( @@ -51,6 +56,9 @@ class TestDispatcher : public QuicDispatcher { const IPEndPoint& server_address, const IPEndPoint& client_address)); using QuicDispatcher::write_blocked_list; + + using QuicDispatcher::current_server_address; + using QuicDispatcher::current_client_address; }; // A Connection class which unregisters the session from the dispatcher @@ -74,7 +82,7 @@ class MockServerConnection : public MockConnection { QuicSession* CreateSession(QuicDispatcher* dispatcher, QuicConnectionId connection_id, - const IPEndPoint& addr, + const IPEndPoint& client_address, MockSession** session) { MockServerConnection* connection = new MockServerConnection(connection_id, dispatcher); @@ -83,7 +91,7 @@ QuicSession* CreateSession(QuicDispatcher* dispatcher, WithoutArgs(Invoke( connection, &MockServerConnection::UnregisterOnConnectionClosed))); EXPECT_CALL(*reinterpret_cast((*session)->connection()), - ProcessUdpPacket(_, addr, _)); + ProcessUdpPacket(_, client_address, _)); return *session; } @@ -109,14 +117,14 @@ class QuicDispatcherTest : public ::testing::Test { return reinterpret_cast(session2_->connection()); } - void ProcessPacket(IPEndPoint addr, + void ProcessPacket(IPEndPoint client_address, QuicConnectionId connection_id, bool has_version_flag, const string& data) { scoped_ptr packet(ConstructEncryptedPacket( connection_id, has_version_flag, false, 1, data)); data_ = string(packet->data(), packet->length()); - dispatcher_.ProcessPacket(IPEndPoint(), addr, *packet.get()); + dispatcher_.ProcessPacket(server_address_, client_address, *packet.get()); } void ValidatePacket(const QuicEncryptedPacket& packet) { @@ -127,6 +135,7 @@ class QuicDispatcherTest : public ::testing::Test { EpollServer eps_; QuicConfig config_; QuicCryptoServerConfig crypto_config_; + IPEndPoint server_address_; TestDispatcher dispatcher_; MockSession* session1_; MockSession* session2_; @@ -134,33 +143,39 @@ class QuicDispatcherTest : public ::testing::Test { }; TEST_F(QuicDispatcherTest, ProcessPackets) { - IPEndPoint addr(net::test::Loopback4(), 1); + IPEndPoint client_address(net::test::Loopback4(), 1); + IPAddressNumber any4; + CHECK(net::ParseIPLiteralToNumber("0.0.0.0", &any4)); + server_address_ = IPEndPoint(any4, 5); - EXPECT_CALL(dispatcher_, CreateQuicSession(1, _, addr)) + EXPECT_CALL(dispatcher_, CreateQuicSession(1, _, client_address)) .WillOnce(testing::Return(CreateSession( - &dispatcher_, 1, addr, &session1_))); - ProcessPacket(addr, 1, true, "foo"); + &dispatcher_, 1, client_address, &session1_))); + ProcessPacket(client_address, 1, true, "foo"); + EXPECT_EQ(client_address, dispatcher_.current_client_address()); + EXPECT_EQ(server_address_, dispatcher_.current_server_address()); + - EXPECT_CALL(dispatcher_, CreateQuicSession(2, _, addr)) + EXPECT_CALL(dispatcher_, CreateQuicSession(2, _, client_address)) .WillOnce(testing::Return(CreateSession( - &dispatcher_, 2, addr, &session2_))); - ProcessPacket(addr, 2, true, "bar"); + &dispatcher_, 2, client_address, &session2_))); + ProcessPacket(client_address, 2, true, "bar"); EXPECT_CALL(*reinterpret_cast(session1_->connection()), ProcessUdpPacket(_, _, _)).Times(1). WillOnce(testing::WithArgs<2>(Invoke( this, &QuicDispatcherTest::ValidatePacket))); - ProcessPacket(addr, 1, false, "eep"); + ProcessPacket(client_address, 1, false, "eep"); } TEST_F(QuicDispatcherTest, Shutdown) { - IPEndPoint addr(net::test::Loopback4(), 1); + IPEndPoint client_address(net::test::Loopback4(), 1); - EXPECT_CALL(dispatcher_, CreateQuicSession(_, _, addr)) + EXPECT_CALL(dispatcher_, CreateQuicSession(_, _, client_address)) .WillOnce(testing::Return(CreateSession( - &dispatcher_, 1, addr, &session1_))); + &dispatcher_, 1, client_address, &session1_))); - ProcessPacket(addr, 1, true, "foo"); + ProcessPacket(client_address, 1, true, "foo"); EXPECT_CALL(*reinterpret_cast(session1_->connection()), SendConnectionClose(QUIC_PEER_GOING_AWAY)); @@ -176,10 +191,11 @@ class MockTimeWaitListManager : public QuicTimeWaitListManager { : QuicTimeWaitListManager(writer, visitor, eps, QuicSupportedVersions()) { } - MOCK_METHOD4(ProcessPacket, void(const IPEndPoint& server_address, + MOCK_METHOD5(ProcessPacket, void(const IPEndPoint& server_address, const IPEndPoint& client_address, QuicConnectionId connection_id, - QuicPacketSequenceNumber sequence_number)); + QuicPacketSequenceNumber sequence_number, + const QuicEncryptedPacket& packet)); }; TEST_F(QuicDispatcherTest, TimeWaitListManager) { @@ -190,12 +206,12 @@ TEST_F(QuicDispatcherTest, TimeWaitListManager) { QuicDispatcherPeer::SetTimeWaitListManager(&dispatcher_, time_wait_list_manager); // Create a new session. - IPEndPoint addr(net::test::Loopback4(), 1); + IPEndPoint client_address(net::test::Loopback4(), 1); QuicConnectionId connection_id = 1; - EXPECT_CALL(dispatcher_, CreateQuicSession(connection_id, _, addr)) + EXPECT_CALL(dispatcher_, CreateQuicSession(connection_id, _, client_address)) .WillOnce(testing::Return(CreateSession( - &dispatcher_, connection_id, addr, &session1_))); - ProcessPacket(addr, connection_id, true, "foo"); + &dispatcher_, connection_id, client_address, &session1_))); + ProcessPacket(client_address, connection_id, true, "foo"); // Close the connection by sending public reset packet. QuicPublicResetPacket packet; @@ -215,14 +231,14 @@ TEST_F(QuicDispatcherTest, TimeWaitListManager) { .WillOnce(Invoke( reinterpret_cast(session1_->connection()), &MockConnection::ReallyProcessUdpPacket)); - dispatcher_.ProcessPacket(IPEndPoint(), addr, *encrypted); + dispatcher_.ProcessPacket(IPEndPoint(), client_address, *encrypted); EXPECT_TRUE(time_wait_list_manager->IsConnectionIdInTimeWait(connection_id)); // Dispatcher forwards subsequent packets for this connection_id to the time // wait list manager. EXPECT_CALL(*time_wait_list_manager, - ProcessPacket(_, _, connection_id, _)).Times(1); - ProcessPacket(addr, connection_id, true, "foo"); + ProcessPacket(_, _, connection_id, _, _)).Times(1); + ProcessPacket(client_address, connection_id, true, "foo"); } TEST_F(QuicDispatcherTest, StrayPacketToTimeWaitListManager) { @@ -233,15 +249,58 @@ TEST_F(QuicDispatcherTest, StrayPacketToTimeWaitListManager) { QuicDispatcherPeer::SetTimeWaitListManager(&dispatcher_, time_wait_list_manager); - IPEndPoint addr(net::test::Loopback4(), 1); + IPEndPoint client_address(net::test::Loopback4(), 1); QuicConnectionId connection_id = 1; // Dispatcher forwards all packets for this connection_id to the time wait // list manager. EXPECT_CALL(dispatcher_, CreateQuicSession(_, _, _)).Times(0); EXPECT_CALL(*time_wait_list_manager, - ProcessPacket(_, _, connection_id, _)).Times(1); + ProcessPacket(_, _, connection_id, _, _)).Times(1); string data = "foo"; - ProcessPacket(addr, connection_id, false, "foo"); + ProcessPacket(client_address, connection_id, false, "foo"); +} + +TEST(QuicDispatcherFlowControlTest, NoNewVersion17ConnectionsIfFlagDisabled) { + // If FLAGS_enable_quic_stream_flow_control_2 is disabled + // then the dispatcher should stop creating connections that support + // QUIC_VERSION_17 (existing connections will stay alive). + // TODO(rjshade): Remove once + // FLAGS_enable_quic_stream_flow_control_2 is removed. + + EpollServer eps; + QuicConfig config; + QuicCryptoServerConfig server_config(QuicCryptoServerConfig::TESTING, + QuicRandom::GetInstance()); + IPEndPoint client(net::test::Loopback4(), 1); + IPEndPoint server(net::test::Loopback4(), 1); + QuicConnectionId kCID = 1234; + + QuicVersion kTestQuicVersions[] = {QUIC_VERSION_17, + QUIC_VERSION_16, + QUIC_VERSION_15}; + QuicVersionVector kTestVersions; + for (size_t i = 0; i < arraysize(kTestQuicVersions); ++i) { + kTestVersions.push_back(kTestQuicVersions[i]); + } + + QuicDispatcher dispatcher(config, server_config, kTestVersions, &eps, + kInitialFlowControlWindowForTest); + dispatcher.Initialize(0); + + // When flag is enabled, new connections should support QUIC_VERSION_17. + FLAGS_enable_quic_stream_flow_control_2 = true; + scoped_ptr connection_1( + QuicDispatcherPeer::CreateQuicConnection( + &dispatcher, kCID, client, server, kInitialFlowControlWindowForTest)); + EXPECT_EQ(QUIC_VERSION_17, connection_1->version()); + + + // When flag is disabled, new connections should not support QUIC_VERSION_17. + FLAGS_enable_quic_stream_flow_control_2 = false; + scoped_ptr connection_2( + QuicDispatcherPeer::CreateQuicConnection( + &dispatcher, kCID, client, server, kInitialFlowControlWindowForTest)); + EXPECT_EQ(QUIC_VERSION_16, connection_2->version()); } class BlockingWriter : public QuicPacketWriterWrapper { @@ -254,13 +313,13 @@ class BlockingWriter : public QuicPacketWriterWrapper { virtual WriteResult WritePacket( const char* buffer, size_t buf_len, - const IPAddressNumber& self_address, - const IPEndPoint& peer_address) OVERRIDE { + const IPAddressNumber& self_client_address, + const IPEndPoint& peer_client_address) OVERRIDE { if (write_blocked_) { return WriteResult(WRITE_STATUS_BLOCKED, EAGAIN); } else { return QuicPacketWriterWrapper::WritePacket( - buffer, buf_len, self_address, peer_address); + buffer, buf_len, self_client_address, peer_client_address); } } @@ -273,17 +332,17 @@ class QuicDispatcherWriteBlockedListTest : public QuicDispatcherTest { writer_ = new BlockingWriter; QuicDispatcherPeer::UseWriter(&dispatcher_, writer_); - IPEndPoint addr(net::test::Loopback4(), 1); + IPEndPoint client_address(net::test::Loopback4(), 1); - EXPECT_CALL(dispatcher_, CreateQuicSession(_, _, addr)) + EXPECT_CALL(dispatcher_, CreateQuicSession(_, _, client_address)) .WillOnce(testing::Return(CreateSession( - &dispatcher_, 1, addr, &session1_))); - ProcessPacket(addr, 1, true, "foo"); + &dispatcher_, 1, client_address, &session1_))); + ProcessPacket(client_address, 1, true, "foo"); - EXPECT_CALL(dispatcher_, CreateQuicSession(_, _, addr)) + EXPECT_CALL(dispatcher_, CreateQuicSession(_, _, client_address)) .WillOnce(testing::Return(CreateSession( - &dispatcher_, 2, addr, &session2_))); - ProcessPacket(addr, 2, true, "bar"); + &dispatcher_, 2, client_address, &session2_))); + ProcessPacket(client_address, 2, true, "bar"); blocked_list_ = dispatcher_.write_blocked_list(); }