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 <stddef.h> | 5 #include <stddef.h> |
6 #include <string> | 6 #include <string> |
7 #include <sys/epoll.h> | 7 #include <sys/epoll.h> |
8 #include <vector> | 8 #include <vector> |
9 | 9 |
10 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
(...skipping 10 matching lines...) Expand all Loading... |
21 #include "net/quic/quic_framer.h" | 21 #include "net/quic/quic_framer.h" |
22 #include "net/quic/quic_packet_creator.h" | 22 #include "net/quic/quic_packet_creator.h" |
23 #include "net/quic/quic_protocol.h" | 23 #include "net/quic/quic_protocol.h" |
24 #include "net/quic/quic_sent_packet_manager.h" | 24 #include "net/quic/quic_sent_packet_manager.h" |
25 #include "net/quic/quic_server_id.h" | 25 #include "net/quic/quic_server_id.h" |
26 #include "net/quic/test_tools/quic_connection_peer.h" | 26 #include "net/quic/test_tools/quic_connection_peer.h" |
27 #include "net/quic/test_tools/quic_session_peer.h" | 27 #include "net/quic/test_tools/quic_session_peer.h" |
28 #include "net/quic/test_tools/quic_test_utils.h" | 28 #include "net/quic/test_tools/quic_test_utils.h" |
29 #include "net/quic/test_tools/reliable_quic_stream_peer.h" | 29 #include "net/quic/test_tools/reliable_quic_stream_peer.h" |
30 #include "net/test/gtest_util.h" | 30 #include "net/test/gtest_util.h" |
| 31 #include "net/tools/epoll_server/epoll_server.h" |
31 #include "net/tools/quic/quic_epoll_connection_helper.h" | 32 #include "net/tools/quic/quic_epoll_connection_helper.h" |
32 #include "net/tools/quic/quic_in_memory_cache.h" | 33 #include "net/tools/quic/quic_in_memory_cache.h" |
33 #include "net/tools/quic/quic_packet_writer_wrapper.h" | 34 #include "net/tools/quic/quic_packet_writer_wrapper.h" |
34 #include "net/tools/quic/quic_server.h" | 35 #include "net/tools/quic/quic_server.h" |
35 #include "net/tools/quic/quic_socket_utils.h" | 36 #include "net/tools/quic/quic_socket_utils.h" |
36 #include "net/tools/quic/quic_spdy_client_stream.h" | 37 #include "net/tools/quic/quic_spdy_client_stream.h" |
37 #include "net/tools/quic/test_tools/http_message.h" | 38 #include "net/tools/quic/test_tools/http_message.h" |
38 #include "net/tools/quic/test_tools/packet_dropping_test_writer.h" | 39 #include "net/tools/quic/test_tools/packet_dropping_test_writer.h" |
39 #include "net/tools/quic/test_tools/quic_client_peer.h" | 40 #include "net/tools/quic/test_tools/quic_client_peer.h" |
40 #include "net/tools/quic/test_tools/quic_dispatcher_peer.h" | 41 #include "net/tools/quic/test_tools/quic_dispatcher_peer.h" |
41 #include "net/tools/quic/test_tools/quic_in_memory_cache_peer.h" | 42 #include "net/tools/quic/test_tools/quic_in_memory_cache_peer.h" |
42 #include "net/tools/quic/test_tools/quic_server_peer.h" | 43 #include "net/tools/quic/test_tools/quic_server_peer.h" |
43 #include "net/tools/quic/test_tools/quic_test_client.h" | 44 #include "net/tools/quic/test_tools/quic_test_client.h" |
44 #include "net/tools/quic/test_tools/server_thread.h" | 45 #include "net/tools/quic/test_tools/server_thread.h" |
45 #include "testing/gtest/include/gtest/gtest.h" | 46 #include "testing/gtest/include/gtest/gtest.h" |
46 | 47 |
47 using base::StringPiece; | 48 using base::StringPiece; |
48 using base::WaitableEvent; | 49 using base::WaitableEvent; |
| 50 using net::EpollServer; |
49 using net::test::GenerateBody; | 51 using net::test::GenerateBody; |
50 using net::test::QuicConnectionPeer; | 52 using net::test::QuicConnectionPeer; |
51 using net::test::QuicSessionPeer; | 53 using net::test::QuicSessionPeer; |
52 using net::test::ReliableQuicStreamPeer; | 54 using net::test::ReliableQuicStreamPeer; |
53 using net::tools::test::PacketDroppingTestWriter; | 55 using net::tools::test::PacketDroppingTestWriter; |
54 using net::tools::test::QuicDispatcherPeer; | 56 using net::tools::test::QuicDispatcherPeer; |
55 using net::tools::test::QuicServerPeer; | 57 using net::tools::test::QuicServerPeer; |
56 using std::ostream; | 58 using std::ostream; |
57 using std::string; | 59 using std::string; |
58 using std::vector; | 60 using std::vector; |
(...skipping 887 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
946 buffer, buf_len, self_address_.address(), peer_address); | 948 buffer, buf_len, self_address_.address(), peer_address); |
947 } | 949 } |
948 | 950 |
949 virtual bool IsWriteBlockedDataBuffered() const OVERRIDE { | 951 virtual bool IsWriteBlockedDataBuffered() const OVERRIDE { |
950 return false; | 952 return false; |
951 } | 953 } |
952 | 954 |
953 IPEndPoint self_address_; | 955 IPEndPoint self_address_; |
954 }; | 956 }; |
955 | 957 |
956 TEST_P(EndToEndTest, ConnectionMigration) { | 958 TEST_P(EndToEndTest, ConnectionMigrationClientIPChanged) { |
| 959 // Tests that the client's IP can not change during an established QUIC |
| 960 // connection. If it changes, the connection is closed by the server as we do |
| 961 // not yet support IP migration. |
957 ASSERT_TRUE(Initialize()); | 962 ASSERT_TRUE(Initialize()); |
958 | 963 |
959 EXPECT_EQ(kFooResponseBody, client_->SendSynchronousRequest("/foo")); | 964 EXPECT_EQ(kFooResponseBody, client_->SendSynchronousRequest("/foo")); |
960 EXPECT_EQ(200u, client_->response_headers()->parsed_response_code()); | 965 EXPECT_EQ(200u, client_->response_headers()->parsed_response_code()); |
961 | 966 |
962 scoped_ptr<WrongAddressWriter> writer(new WrongAddressWriter()); | 967 scoped_ptr<WrongAddressWriter> writer(new WrongAddressWriter()); |
963 | 968 |
964 writer->set_writer(new QuicDefaultPacketWriter(client_->client()->fd())); | 969 writer->set_writer(new QuicDefaultPacketWriter(client_->client()->fd())); |
965 QuicConnectionPeer::SetWriter(client_->client()->session()->connection(), | 970 QuicConnectionPeer::SetWriter(client_->client()->session()->connection(), |
966 writer.get()); | 971 writer.get()); |
967 | 972 |
968 client_->SendSynchronousRequest("/bar"); | 973 client_->SendSynchronousRequest("/bar"); |
969 | 974 |
970 EXPECT_EQ(QUIC_STREAM_CONNECTION_ERROR, client_->stream_error()); | 975 EXPECT_EQ(QUIC_STREAM_CONNECTION_ERROR, client_->stream_error()); |
971 EXPECT_EQ(QUIC_ERROR_MIGRATING_ADDRESS, client_->connection_error()); | 976 EXPECT_EQ(QUIC_ERROR_MIGRATING_ADDRESS, client_->connection_error()); |
972 } | 977 } |
973 | 978 |
| 979 TEST_P(EndToEndTest, ConnectionMigrationClientPortChanged) { |
| 980 // Tests that the client's port can change during an established QUIC |
| 981 // connection, and that doing so does not result in the connection being |
| 982 // closed by the server. |
| 983 FLAGS_quic_allow_port_migration = true; |
| 984 |
| 985 ASSERT_TRUE(Initialize()); |
| 986 |
| 987 EXPECT_EQ(kFooResponseBody, client_->SendSynchronousRequest("/foo")); |
| 988 EXPECT_EQ(200u, client_->response_headers()->parsed_response_code()); |
| 989 |
| 990 // Store the client address which was used to send the first request. |
| 991 IPEndPoint old_address = client_->client()->client_address(); |
| 992 |
| 993 // Stop listening on the old FD. |
| 994 EpollServer* eps = client_->client()->epoll_server(); |
| 995 int old_fd = client_->client()->fd(); |
| 996 eps->UnregisterFD(old_fd); |
| 997 close(old_fd); |
| 998 |
| 999 // Create a new socket, which will result in a new ephemeral port. |
| 1000 QuicClientPeer::CreateUDPSocket(client_->client()); |
| 1001 |
| 1002 // The packet writer needs to be updated to use the new FD. |
| 1003 client_->client()->CreateQuicPacketWriter(); |
| 1004 |
| 1005 // Change the internal state of the client and connection to use the new port, |
| 1006 // this is done because in a real NAT rebinding the client wouldn't see any |
| 1007 // port change, and so expects no change to incoming port. |
| 1008 // This is kind of ugly, but needed as we are simply swapping out the client |
| 1009 // FD rather than any more complex NAT rebinding simulation. |
| 1010 int new_port = client_->client()->client_address().port(); |
| 1011 QuicClientPeer::SetClientPort(client_->client(), new_port); |
| 1012 QuicConnectionPeer::SetSelfAddress( |
| 1013 client_->client()->session()->connection(), |
| 1014 IPEndPoint( |
| 1015 client_->client()->session()->connection()->self_address().address(), |
| 1016 new_port)); |
| 1017 |
| 1018 // Register the new FD for epoll events. |
| 1019 int new_fd = client_->client()->fd(); |
| 1020 eps->RegisterFD(new_fd, client_->client(), EPOLLIN | EPOLLOUT | EPOLLET); |
| 1021 |
| 1022 // Send a second request, using the new FD. |
| 1023 EXPECT_EQ(kBarResponseBody, client_->SendSynchronousRequest("/bar")); |
| 1024 EXPECT_EQ(200u, client_->response_headers()->parsed_response_code()); |
| 1025 |
| 1026 // Verify that the client's ephemeral port is different. |
| 1027 IPEndPoint new_address = client_->client()->client_address(); |
| 1028 EXPECT_EQ(old_address.address(), new_address.address()); |
| 1029 EXPECT_NE(old_address.port(), new_address.port()); |
| 1030 } |
| 1031 |
974 TEST_P(EndToEndTest, DifferentFlowControlWindows) { | 1032 TEST_P(EndToEndTest, DifferentFlowControlWindows) { |
975 // Client and server can set different initial flow control receive windows. | 1033 // Client and server can set different initial flow control receive windows. |
976 // These are sent in CHLO/SHLO. Tests that these values are exchanged properly | 1034 // These are sent in CHLO/SHLO. Tests that these values are exchanged properly |
977 // in the crypto handshake. | 1035 // in the crypto handshake. |
978 | 1036 |
979 const uint32 kClientIFCW = 123456; | 1037 const uint32 kClientIFCW = 123456; |
980 set_client_initial_flow_control_receive_window(kClientIFCW); | 1038 set_client_initial_flow_control_receive_window(kClientIFCW); |
981 | 1039 |
982 const uint32 kServerIFCW = 654321; | 1040 const uint32 kServerIFCW = 654321; |
983 set_server_initial_flow_control_receive_window(kServerIFCW); | 1041 set_server_initial_flow_control_receive_window(kServerIFCW); |
(...skipping 17 matching lines...) Expand all Loading... |
1001 QuicSession* session = dispatcher->session_map().begin()->second; | 1059 QuicSession* session = dispatcher->session_map().begin()->second; |
1002 EXPECT_EQ(kClientIFCW, | 1060 EXPECT_EQ(kClientIFCW, |
1003 session->config()->ReceivedInitialFlowControlWindowBytes()); | 1061 session->config()->ReceivedInitialFlowControlWindowBytes()); |
1004 server_thread_->Resume(); | 1062 server_thread_->Resume(); |
1005 } | 1063 } |
1006 | 1064 |
1007 } // namespace | 1065 } // namespace |
1008 } // namespace test | 1066 } // namespace test |
1009 } // namespace tools | 1067 } // namespace tools |
1010 } // namespace net | 1068 } // namespace net |
OLD | NEW |