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

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

Issue 1565303002: Change IPEndpoint::address() to return a net::IPAddress (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebase for ChromeOS Created 4 years, 10 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/socket/tcp_client_socket_unittest.cc ('k') | net/tools/quic/quic_client_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 <stddef.h> 5 #include <stddef.h>
6 #include <sys/epoll.h> 6 #include <sys/epoll.h>
7 #include <string> 7 #include <string>
8 #include <vector> 8 #include <vector>
9 9
10 #include "base/memory/scoped_ptr.h" 10 #include "base/memory/scoped_ptr.h"
(...skipping 390 matching lines...) Expand 10 before | Expand all | Expand 10 after
401 401
402 void StartServer() { 402 void StartServer() {
403 server_thread_.reset(new ServerThread( 403 server_thread_.reset(new ServerThread(
404 new QuicTestServer(CryptoTestUtils::ProofSourceForTesting(), 404 new QuicTestServer(CryptoTestUtils::ProofSourceForTesting(),
405 server_config_, server_supported_versions_), 405 server_config_, server_supported_versions_),
406 server_address_, strike_register_no_startup_period_)); 406 server_address_, strike_register_no_startup_period_));
407 if (chlo_multiplier_ != 0) { 407 if (chlo_multiplier_ != 0) {
408 server_thread_->server()->SetChloMultiplier(chlo_multiplier_); 408 server_thread_->server()->SetChloMultiplier(chlo_multiplier_);
409 } 409 }
410 server_thread_->Initialize(); 410 server_thread_->Initialize();
411 server_address_ = 411 server_address_ = IPEndPoint(server_address_.address().bytes(),
412 IPEndPoint(server_address_.address(), server_thread_->GetPort()); 412 server_thread_->GetPort());
413 QuicDispatcher* dispatcher = 413 QuicDispatcher* dispatcher =
414 QuicServerPeer::GetDispatcher(server_thread_->server()); 414 QuicServerPeer::GetDispatcher(server_thread_->server());
415 QuicDispatcherPeer::UseWriter(dispatcher, server_writer_); 415 QuicDispatcherPeer::UseWriter(dispatcher, server_writer_);
416 416
417 FLAGS_enable_quic_stateless_reject_support = 417 FLAGS_enable_quic_stateless_reject_support =
418 GetParam().server_uses_stateless_rejects_if_peer_supported; 418 GetParam().server_uses_stateless_rejects_if_peer_supported;
419 419
420 server_writer_->Initialize(QuicDispatcherPeer::GetHelper(dispatcher), 420 server_writer_->Initialize(QuicDispatcherPeer::GetHelper(dispatcher),
421 new ServerDelegate(dispatcher)); 421 new ServerDelegate(dispatcher));
422 if (stream_factory_ != nullptr) { 422 if (stream_factory_ != nullptr) {
(...skipping 1035 matching lines...) Expand 10 before | Expand all | Expand 10 after
1458 CHECK(net::ParseIPLiteralToNumber("127.0.0.2", &ip)); 1458 CHECK(net::ParseIPLiteralToNumber("127.0.0.2", &ip));
1459 self_address_ = IPEndPoint(ip, 0); 1459 self_address_ = IPEndPoint(ip, 0);
1460 } 1460 }
1461 1461
1462 WriteResult WritePacket(const char* buffer, 1462 WriteResult WritePacket(const char* buffer,
1463 size_t buf_len, 1463 size_t buf_len,
1464 const IPAddressNumber& /*real_self_address*/, 1464 const IPAddressNumber& /*real_self_address*/,
1465 const IPEndPoint& peer_address) override { 1465 const IPEndPoint& peer_address) override {
1466 // Use wrong address! 1466 // Use wrong address!
1467 return QuicPacketWriterWrapper::WritePacket( 1467 return QuicPacketWriterWrapper::WritePacket(
1468 buffer, buf_len, self_address_.address(), peer_address); 1468 buffer, buf_len, self_address_.address().bytes(), peer_address);
1469 } 1469 }
1470 1470
1471 bool IsWriteBlockedDataBuffered() const override { return false; } 1471 bool IsWriteBlockedDataBuffered() const override { return false; }
1472 1472
1473 IPEndPoint self_address_; 1473 IPEndPoint self_address_;
1474 }; 1474 };
1475 1475
1476 TEST_P(EndToEndTest, ConnectionMigrationClientIPChanged) { 1476 TEST_P(EndToEndTest, ConnectionMigrationClientIPChanged) {
1477 ASSERT_TRUE(Initialize()); 1477 ASSERT_TRUE(Initialize());
1478 1478
1479 EXPECT_EQ(kFooResponseBody, client_->SendSynchronousRequest("/foo")); 1479 EXPECT_EQ(kFooResponseBody, client_->SendSynchronousRequest("/foo"));
1480 EXPECT_EQ(200u, client_->response_headers()->parsed_response_code()); 1480 EXPECT_EQ(200u, client_->response_headers()->parsed_response_code());
1481 1481
1482 // Store the client IP address which was used to send the first request. 1482 // Store the client IP address which was used to send the first request.
1483 IPAddressNumber old_host = 1483 IPAddressNumber old_host =
1484 client_->client()->GetLatestClientAddress().address(); 1484 client_->client()->GetLatestClientAddress().address().bytes();
1485 1485
1486 // Migrate socket to the new IP address. 1486 // Migrate socket to the new IP address.
1487 IPAddressNumber new_host; 1487 IPAddressNumber new_host;
1488 CHECK(net::ParseIPLiteralToNumber("127.0.0.2", &new_host)); 1488 CHECK(net::ParseIPLiteralToNumber("127.0.0.2", &new_host));
1489 EXPECT_NE(old_host, new_host); 1489 EXPECT_NE(old_host, new_host);
1490 ASSERT_TRUE(client_->client()->MigrateSocket(new_host)); 1490 ASSERT_TRUE(client_->client()->MigrateSocket(new_host));
1491 1491
1492 // Send a request using the new socket. 1492 // Send a request using the new socket.
1493 EXPECT_EQ(kBarResponseBody, client_->SendSynchronousRequest("/bar")); 1493 EXPECT_EQ(kBarResponseBody, client_->SendSynchronousRequest("/bar"));
1494 EXPECT_EQ(200u, client_->response_headers()->parsed_response_code()); 1494 EXPECT_EQ(200u, client_->response_headers()->parsed_response_code());
(...skipping 303 matching lines...) Expand 10 before | Expand all | Expand 10 after
1798 Perspective::IS_SERVER); 1798 Perspective::IS_SERVER);
1799 scoped_ptr<QuicEncryptedPacket> packet(framer.BuildPublicResetPacket(header)); 1799 scoped_ptr<QuicEncryptedPacket> packet(framer.BuildPublicResetPacket(header));
1800 testing::NiceMock<MockQuicConnectionDebugVisitor> visitor; 1800 testing::NiceMock<MockQuicConnectionDebugVisitor> visitor;
1801 client_->client()->session()->connection()->set_debug_visitor(&visitor); 1801 client_->client()->session()->connection()->set_debug_visitor(&visitor);
1802 EXPECT_CALL(visitor, OnIncorrectConnectionId(incorrect_connection_id)) 1802 EXPECT_CALL(visitor, OnIncorrectConnectionId(incorrect_connection_id))
1803 .Times(1); 1803 .Times(1);
1804 // We must pause the server's thread in order to call WritePacket without 1804 // We must pause the server's thread in order to call WritePacket without
1805 // race conditions. 1805 // race conditions.
1806 server_thread_->Pause(); 1806 server_thread_->Pause();
1807 server_writer_->WritePacket(packet->data(), packet->length(), 1807 server_writer_->WritePacket(packet->data(), packet->length(),
1808 server_address_.address(), 1808 server_address_.address().bytes(),
1809 client_->client()->GetLatestClientAddress()); 1809 client_->client()->GetLatestClientAddress());
1810 server_thread_->Resume(); 1810 server_thread_->Resume();
1811 1811
1812 // The connection should be unaffected. 1812 // The connection should be unaffected.
1813 EXPECT_EQ(kFooResponseBody, client_->SendSynchronousRequest("/foo")); 1813 EXPECT_EQ(kFooResponseBody, client_->SendSynchronousRequest("/foo"));
1814 EXPECT_EQ(200u, client_->response_headers()->parsed_response_code()); 1814 EXPECT_EQ(200u, client_->response_headers()->parsed_response_code());
1815 1815
1816 client_->client()->session()->connection()->set_debug_visitor(nullptr); 1816 client_->client()->session()->connection()->set_debug_visitor(nullptr);
1817 } 1817 }
1818 1818
1819 // Send a public reset from the client for a different connection ID. 1819 // Send a public reset from the client for a different connection ID.
1820 // It should be ignored. 1820 // It should be ignored.
1821 TEST_P(EndToEndTest, ClientSendPublicResetWithDifferentConnectionId) { 1821 TEST_P(EndToEndTest, ClientSendPublicResetWithDifferentConnectionId) {
1822 ASSERT_TRUE(Initialize()); 1822 ASSERT_TRUE(Initialize());
1823 1823
1824 // Send the public reset. 1824 // Send the public reset.
1825 QuicConnectionId incorrect_connection_id = 1825 QuicConnectionId incorrect_connection_id =
1826 client_->client()->session()->connection()->connection_id() + 1; 1826 client_->client()->session()->connection()->connection_id() + 1;
1827 QuicPublicResetPacket header; 1827 QuicPublicResetPacket header;
1828 header.public_header.connection_id = incorrect_connection_id; 1828 header.public_header.connection_id = incorrect_connection_id;
1829 header.public_header.reset_flag = true; 1829 header.public_header.reset_flag = true;
1830 header.public_header.version_flag = false; 1830 header.public_header.version_flag = false;
1831 header.rejected_packet_number = 10101; 1831 header.rejected_packet_number = 10101;
1832 QuicFramer framer(server_supported_versions_, QuicTime::Zero(), 1832 QuicFramer framer(server_supported_versions_, QuicTime::Zero(),
1833 Perspective::IS_CLIENT); 1833 Perspective::IS_CLIENT);
1834 scoped_ptr<QuicEncryptedPacket> packet(framer.BuildPublicResetPacket(header)); 1834 scoped_ptr<QuicEncryptedPacket> packet(framer.BuildPublicResetPacket(header));
1835 client_writer_->WritePacket( 1835 client_writer_->WritePacket(
1836 packet->data(), packet->length(), 1836 packet->data(), packet->length(),
1837 client_->client()->GetLatestClientAddress().address(), server_address_); 1837 client_->client()->GetLatestClientAddress().address().bytes(),
1838 server_address_);
1838 1839
1839 // The connection should be unaffected. 1840 // The connection should be unaffected.
1840 EXPECT_EQ(kFooResponseBody, client_->SendSynchronousRequest("/foo")); 1841 EXPECT_EQ(kFooResponseBody, client_->SendSynchronousRequest("/foo"));
1841 EXPECT_EQ(200u, client_->response_headers()->parsed_response_code()); 1842 EXPECT_EQ(200u, client_->response_headers()->parsed_response_code());
1842 } 1843 }
1843 1844
1844 // Send a version negotiation packet from the server for a different 1845 // Send a version negotiation packet from the server for a different
1845 // connection ID. It should be ignored. 1846 // connection ID. It should be ignored.
1846 TEST_P(EndToEndTest, ServerSendVersionNegotiationWithDifferentConnectionId) { 1847 TEST_P(EndToEndTest, ServerSendVersionNegotiationWithDifferentConnectionId) {
1847 ASSERT_TRUE(Initialize()); 1848 ASSERT_TRUE(Initialize());
1848 1849
1849 // Send the version negotiation packet. 1850 // Send the version negotiation packet.
1850 QuicConnectionId incorrect_connection_id = 1851 QuicConnectionId incorrect_connection_id =
1851 client_->client()->session()->connection()->connection_id() + 1; 1852 client_->client()->session()->connection()->connection_id() + 1;
1852 scoped_ptr<QuicEncryptedPacket> packet( 1853 scoped_ptr<QuicEncryptedPacket> packet(
1853 QuicFramer::BuildVersionNegotiationPacket(incorrect_connection_id, 1854 QuicFramer::BuildVersionNegotiationPacket(incorrect_connection_id,
1854 server_supported_versions_)); 1855 server_supported_versions_));
1855 testing::NiceMock<MockQuicConnectionDebugVisitor> visitor; 1856 testing::NiceMock<MockQuicConnectionDebugVisitor> visitor;
1856 client_->client()->session()->connection()->set_debug_visitor(&visitor); 1857 client_->client()->session()->connection()->set_debug_visitor(&visitor);
1857 EXPECT_CALL(visitor, OnIncorrectConnectionId(incorrect_connection_id)) 1858 EXPECT_CALL(visitor, OnIncorrectConnectionId(incorrect_connection_id))
1858 .Times(1); 1859 .Times(1);
1859 // We must pause the server's thread in order to call WritePacket without 1860 // We must pause the server's thread in order to call WritePacket without
1860 // race conditions. 1861 // race conditions.
1861 server_thread_->Pause(); 1862 server_thread_->Pause();
1862 server_writer_->WritePacket(packet->data(), packet->length(), 1863 server_writer_->WritePacket(packet->data(), packet->length(),
1863 server_address_.address(), 1864 server_address_.address().bytes(),
1864 client_->client()->GetLatestClientAddress()); 1865 client_->client()->GetLatestClientAddress());
1865 server_thread_->Resume(); 1866 server_thread_->Resume();
1866 1867
1867 // The connection should be unaffected. 1868 // The connection should be unaffected.
1868 EXPECT_EQ(kFooResponseBody, client_->SendSynchronousRequest("/foo")); 1869 EXPECT_EQ(kFooResponseBody, client_->SendSynchronousRequest("/foo"));
1869 EXPECT_EQ(200u, client_->response_headers()->parsed_response_code()); 1870 EXPECT_EQ(200u, client_->response_headers()->parsed_response_code());
1870 1871
1871 client_->client()->session()->connection()->set_debug_visitor(nullptr); 1872 client_->client()->session()->connection()->set_debug_visitor(nullptr);
1872 } 1873 }
1873 1874
1874 // A bad header shouldn't tear down the connection, because the receiver can't 1875 // A bad header shouldn't tear down the connection, because the receiver can't
1875 // tell the connection ID. 1876 // tell the connection ID.
1876 TEST_P(EndToEndTest, BadPacketHeaderTruncated) { 1877 TEST_P(EndToEndTest, BadPacketHeaderTruncated) {
1877 ASSERT_TRUE(Initialize()); 1878 ASSERT_TRUE(Initialize());
1878 1879
1879 // Start the connection. 1880 // Start the connection.
1880 EXPECT_EQ(kFooResponseBody, client_->SendSynchronousRequest("/foo")); 1881 EXPECT_EQ(kFooResponseBody, client_->SendSynchronousRequest("/foo"));
1881 EXPECT_EQ(200u, client_->response_headers()->parsed_response_code()); 1882 EXPECT_EQ(200u, client_->response_headers()->parsed_response_code());
1882 1883
1883 // Packet with invalid public flags. 1884 // Packet with invalid public flags.
1884 char packet[] = {// public flags (8 byte connection_id) 1885 char packet[] = {// public flags (8 byte connection_id)
1885 0x3C, 1886 0x3C,
1886 // truncated connection ID 1887 // truncated connection ID
1887 0x11}; 1888 0x11};
1888 client_writer_->WritePacket( 1889 client_writer_->WritePacket(
1889 &packet[0], sizeof(packet), 1890 &packet[0], sizeof(packet),
1890 client_->client()->GetLatestClientAddress().address(), server_address_); 1891 client_->client()->GetLatestClientAddress().address().bytes(),
1892 server_address_);
1891 // Give the server time to process the packet. 1893 // Give the server time to process the packet.
1892 base::PlatformThread::Sleep(base::TimeDelta::FromMilliseconds(100)); 1894 base::PlatformThread::Sleep(base::TimeDelta::FromMilliseconds(100));
1893 // Pause the server so we can access the server's internals without races. 1895 // Pause the server so we can access the server's internals without races.
1894 server_thread_->Pause(); 1896 server_thread_->Pause();
1895 QuicDispatcher* dispatcher = 1897 QuicDispatcher* dispatcher =
1896 QuicServerPeer::GetDispatcher(server_thread_->server()); 1898 QuicServerPeer::GetDispatcher(server_thread_->server());
1897 EXPECT_EQ(QUIC_INVALID_PACKET_HEADER, 1899 EXPECT_EQ(QUIC_INVALID_PACKET_HEADER,
1898 QuicDispatcherPeer::GetAndClearLastError(dispatcher)); 1900 QuicDispatcherPeer::GetAndClearLastError(dispatcher));
1899 server_thread_->Resume(); 1901 server_thread_->Resume();
1900 1902
(...skipping 17 matching lines...) Expand all
1918 0xFF, 1920 0xFF,
1919 // connection_id 1921 // connection_id
1920 0x10, 0x32, 0x54, 0x76, 0x98, 0xBA, 0xDC, 0xFE, 1922 0x10, 0x32, 0x54, 0x76, 0x98, 0xBA, 0xDC, 0xFE,
1921 // packet sequence number 1923 // packet sequence number
1922 0xBC, 0x9A, 0x78, 0x56, 0x34, 0x12, 1924 0xBC, 0x9A, 0x78, 0x56, 0x34, 0x12,
1923 // private flags 1925 // private flags
1924 0x00, 1926 0x00,
1925 }; 1927 };
1926 client_writer_->WritePacket( 1928 client_writer_->WritePacket(
1927 &packet[0], sizeof(packet), 1929 &packet[0], sizeof(packet),
1928 client_->client()->GetLatestClientAddress().address(), server_address_); 1930 client_->client()->GetLatestClientAddress().address().bytes(),
1931 server_address_);
1929 // Give the server time to process the packet. 1932 // Give the server time to process the packet.
1930 base::PlatformThread::Sleep(base::TimeDelta::FromMilliseconds(100)); 1933 base::PlatformThread::Sleep(base::TimeDelta::FromMilliseconds(100));
1931 // Pause the server so we can access the server's internals without races. 1934 // Pause the server so we can access the server's internals without races.
1932 server_thread_->Pause(); 1935 server_thread_->Pause();
1933 QuicDispatcher* dispatcher = 1936 QuicDispatcher* dispatcher =
1934 QuicServerPeer::GetDispatcher(server_thread_->server()); 1937 QuicServerPeer::GetDispatcher(server_thread_->server());
1935 EXPECT_EQ(QUIC_INVALID_PACKET_HEADER, 1938 EXPECT_EQ(QUIC_INVALID_PACKET_HEADER,
1936 QuicDispatcherPeer::GetAndClearLastError(dispatcher)); 1939 QuicDispatcherPeer::GetAndClearLastError(dispatcher));
1937 server_thread_->Resume(); 1940 server_thread_->Resume();
1938 1941
(...skipping 14 matching lines...) Expand all
1953 scoped_ptr<QuicEncryptedPacket> packet(ConstructEncryptedPacket( 1956 scoped_ptr<QuicEncryptedPacket> packet(ConstructEncryptedPacket(
1954 client_->client()->session()->connection()->connection_id(), false, false, 1957 client_->client()->session()->connection()->connection_id(), false, false,
1955 1, "At least 20 characters.", PACKET_8BYTE_CONNECTION_ID, 1958 1, "At least 20 characters.", PACKET_8BYTE_CONNECTION_ID,
1956 PACKET_6BYTE_PACKET_NUMBER)); 1959 PACKET_6BYTE_PACKET_NUMBER));
1957 // Damage the encrypted data. 1960 // Damage the encrypted data.
1958 string damaged_packet(packet->data(), packet->length()); 1961 string damaged_packet(packet->data(), packet->length());
1959 damaged_packet[30] ^= 0x01; 1962 damaged_packet[30] ^= 0x01;
1960 DVLOG(1) << "Sending bad packet."; 1963 DVLOG(1) << "Sending bad packet.";
1961 client_writer_->WritePacket( 1964 client_writer_->WritePacket(
1962 damaged_packet.data(), damaged_packet.length(), 1965 damaged_packet.data(), damaged_packet.length(),
1963 client_->client()->GetLatestClientAddress().address(), server_address_); 1966 client_->client()->GetLatestClientAddress().address().bytes(),
1967 server_address_);
1964 // Give the server time to process the packet. 1968 // Give the server time to process the packet.
1965 base::PlatformThread::Sleep(base::TimeDelta::FromMilliseconds(100)); 1969 base::PlatformThread::Sleep(base::TimeDelta::FromMilliseconds(100));
1966 // This error is sent to the connection's OnError (which ignores it), so the 1970 // This error is sent to the connection's OnError (which ignores it), so the
1967 // dispatcher doesn't see it. 1971 // dispatcher doesn't see it.
1968 // Pause the server so we can access the server's internals without races. 1972 // Pause the server so we can access the server's internals without races.
1969 server_thread_->Pause(); 1973 server_thread_->Pause();
1970 QuicDispatcher* dispatcher = 1974 QuicDispatcher* dispatcher =
1971 QuicServerPeer::GetDispatcher(server_thread_->server()); 1975 QuicServerPeer::GetDispatcher(server_thread_->server());
1972 EXPECT_EQ(QUIC_NO_ERROR, 1976 EXPECT_EQ(QUIC_NO_ERROR,
1973 QuicDispatcherPeer::GetAndClearLastError(dispatcher)); 1977 QuicDispatcherPeer::GetAndClearLastError(dispatcher));
(...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after
2164 2168
2165 EXPECT_EQ(kBody, client_->SendSynchronousRequest("/trailer_url")); 2169 EXPECT_EQ(kBody, client_->SendSynchronousRequest("/trailer_url"));
2166 EXPECT_EQ(200u, client_->response_headers()->parsed_response_code()); 2170 EXPECT_EQ(200u, client_->response_headers()->parsed_response_code());
2167 EXPECT_EQ(trailers, client_->response_trailers()); 2171 EXPECT_EQ(trailers, client_->response_trailers());
2168 } 2172 }
2169 2173
2170 } // namespace 2174 } // namespace
2171 } // namespace test 2175 } // namespace test
2172 } // namespace tools 2176 } // namespace tools
2173 } // namespace net 2177 } // namespace net
OLDNEW
« no previous file with comments | « net/socket/tcp_client_socket_unittest.cc ('k') | net/tools/quic/quic_client_bin.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698