OLD | NEW |
---|---|
1 /* | 1 /* |
2 * Copyright 2006 The WebRTC Project Authors. All rights reserved. | 2 * Copyright 2006 The WebRTC Project Authors. All rights reserved. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license | 4 * Use of this source code is governed by a BSD-style license |
5 * that can be found in the LICENSE file in the root of the source | 5 * that can be found in the LICENSE file in the root of the source |
6 * tree. An additional intellectual property rights grant can be found | 6 * tree. An additional intellectual property rights grant can be found |
7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may |
8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. |
9 */ | 9 */ |
10 | 10 |
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
142 EXPECT_EQ(post_ipv4.s_addr, pre_ipv4.s_addr); | 142 EXPECT_EQ(post_ipv4.s_addr, pre_ipv4.s_addr); |
143 } else if (post_ip.family() == AF_INET6) { | 143 } else if (post_ip.family() == AF_INET6) { |
144 in6_addr post_ip6 = post_ip.ipv6_address(); | 144 in6_addr post_ip6 = post_ip.ipv6_address(); |
145 in6_addr pre_ip6 = pre_ip.ipv6_address(); | 145 in6_addr pre_ip6 = pre_ip.ipv6_address(); |
146 uint32* post_as_ints = reinterpret_cast<uint32*>(&post_ip6.s6_addr); | 146 uint32* post_as_ints = reinterpret_cast<uint32*>(&post_ip6.s6_addr); |
147 uint32* pre_as_ints = reinterpret_cast<uint32*>(&pre_ip6.s6_addr); | 147 uint32* pre_as_ints = reinterpret_cast<uint32*>(&pre_ip6.s6_addr); |
148 EXPECT_EQ(post_as_ints[3], pre_as_ints[3]); | 148 EXPECT_EQ(post_as_ints[3], pre_as_ints[3]); |
149 } | 149 } |
150 } | 150 } |
151 | 151 |
152 // Test a client can bind to the any address, and all sent packets will have | |
153 // the default route as the source address. Also, it can receive packets sent | |
154 // to the default route. | |
155 void TestDefaultRoute(const IPAddress& default_route) { | |
156 ss_->SetDefaultRoute(default_route); | |
157 | |
158 // Create client1 bound to the any address. | |
159 AsyncSocket* socket = | |
160 ss_->CreateAsyncSocket(default_route.family(), SOCK_DGRAM); | |
161 socket->Bind(EmptySocketAddressWithFamily(default_route.family())); | |
162 SocketAddress client1_any_addr = socket->GetLocalAddress(); | |
163 EXPECT_TRUE(client1_any_addr.IsAnyIP()); | |
164 TestClient* client1 = new TestClient(new AsyncUDPSocket(socket)); | |
165 | |
166 // Create client2 bound to the default route. | |
167 AsyncSocket* socket2 = | |
168 ss_->CreateAsyncSocket(default_route.family(), SOCK_DGRAM); | |
169 socket2->Bind(SocketAddress(default_route, 0)); | |
170 SocketAddress client2_addr = socket2->GetLocalAddress(); | |
171 EXPECT_FALSE(client2_addr.IsAnyIP()); | |
172 TestClient* client2 = new TestClient(new AsyncUDPSocket(socket2)); | |
173 | |
174 // Client1 sends to client2, client2 should see the default route as | |
175 // client1's address. | |
176 SocketAddress client1_addr; | |
177 EXPECT_EQ(6, client1->SendTo("bizbaz", 6, client2_addr)); | |
178 EXPECT_TRUE(client2->CheckNextPacket("bizbaz", 6, &client1_addr)); | |
179 EXPECT_EQ(client1_addr, | |
180 SocketAddress(default_route, client1_any_addr.port())); | |
181 | |
182 // Client2 can send back to client1's default route address. | |
183 EXPECT_EQ(3, client2->SendTo("foo", 3, client1_addr)); | |
184 EXPECT_TRUE(client1->CheckNextPacket("foo", 3, &client2_addr)); | |
185 | |
186 // Client2 also can send to client1's any address. This is to document the | |
187 // current behavior. In reality, this should fail as the any address | |
188 // shouldn't be the destination. | |
pthatcher1
2015/08/07 21:28:19
Can we just remove the current behavior, or do we
guoweis_webrtc
2015/08/13 14:17:28
Done.
| |
189 SocketAddress client2_addr_new; | |
190 EXPECT_EQ(3, client2->SendTo("foo", 3, client1_any_addr)); | |
191 EXPECT_TRUE(client1->CheckNextPacket("foo", 3, &client2_addr_new)); | |
192 EXPECT_EQ(client2_addr_new, client2_addr); | |
193 } | |
194 | |
152 void BasicTest(const SocketAddress& initial_addr) { | 195 void BasicTest(const SocketAddress& initial_addr) { |
153 AsyncSocket* socket = ss_->CreateAsyncSocket(initial_addr.family(), | 196 AsyncSocket* socket = ss_->CreateAsyncSocket(initial_addr.family(), |
154 SOCK_DGRAM); | 197 SOCK_DGRAM); |
155 socket->Bind(initial_addr); | 198 socket->Bind(initial_addr); |
156 SocketAddress server_addr = socket->GetLocalAddress(); | 199 SocketAddress server_addr = socket->GetLocalAddress(); |
157 // Make sure VSS didn't switch families on us. | 200 // Make sure VSS didn't switch families on us. |
158 EXPECT_EQ(server_addr.family(), initial_addr.family()); | 201 EXPECT_EQ(server_addr.family(), initial_addr.family()); |
159 | 202 |
160 TestClient* client1 = new TestClient(new AsyncUDPSocket(socket)); | 203 TestClient* client1 = new TestClient(new AsyncUDPSocket(socket)); |
161 AsyncSocket* socket2 = | 204 AsyncSocket* socket2 = |
(...skipping 622 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
784 TEST_F(VirtualSocketServerTest, basic_v4) { | 827 TEST_F(VirtualSocketServerTest, basic_v4) { |
785 SocketAddress ipv4_test_addr(IPAddress(INADDR_ANY), 5000); | 828 SocketAddress ipv4_test_addr(IPAddress(INADDR_ANY), 5000); |
786 BasicTest(ipv4_test_addr); | 829 BasicTest(ipv4_test_addr); |
787 } | 830 } |
788 | 831 |
789 TEST_F(VirtualSocketServerTest, basic_v6) { | 832 TEST_F(VirtualSocketServerTest, basic_v6) { |
790 SocketAddress ipv6_test_addr(IPAddress(in6addr_any), 5000); | 833 SocketAddress ipv6_test_addr(IPAddress(in6addr_any), 5000); |
791 BasicTest(ipv6_test_addr); | 834 BasicTest(ipv6_test_addr); |
792 } | 835 } |
793 | 836 |
837 TEST_F(VirtualSocketServerTest, TestDefaultRoute_v4) { | |
838 IPAddress ipv4_default_addr(0x01020304); | |
839 TestDefaultRoute(ipv4_default_addr); | |
840 } | |
841 | |
842 TEST_F(VirtualSocketServerTest, TestDefaultRoute_v6) { | |
843 IPAddress ipv6_default_addr; | |
844 EXPECT_TRUE( | |
845 IPFromString("2401:fa00:4:1000:be30:5bff:fee5:c3", &ipv6_default_addr)); | |
846 TestDefaultRoute(ipv6_default_addr); | |
847 } | |
848 | |
794 TEST_F(VirtualSocketServerTest, connect_v4) { | 849 TEST_F(VirtualSocketServerTest, connect_v4) { |
795 ConnectTest(kIPv4AnyAddress); | 850 ConnectTest(kIPv4AnyAddress); |
796 } | 851 } |
797 | 852 |
798 TEST_F(VirtualSocketServerTest, connect_v6) { | 853 TEST_F(VirtualSocketServerTest, connect_v6) { |
799 ConnectTest(kIPv6AnyAddress); | 854 ConnectTest(kIPv6AnyAddress); |
800 } | 855 } |
801 | 856 |
802 TEST_F(VirtualSocketServerTest, connect_to_non_listener_v4) { | 857 TEST_F(VirtualSocketServerTest, connect_to_non_listener_v4) { |
803 ConnectToNonListenerTest(kIPv4AnyAddress); | 858 ConnectToNonListenerTest(kIPv4AnyAddress); |
(...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
994 << " N=" << kTestSamples[sidx]; | 1049 << " N=" << kTestSamples[sidx]; |
995 EXPECT_NEAR(kStdDev, stddev, 0.1 * kStdDev) | 1050 EXPECT_NEAR(kStdDev, stddev, 0.1 * kStdDev) |
996 << "M=" << kTestMean[midx] | 1051 << "M=" << kTestMean[midx] |
997 << " SD=" << kStdDev | 1052 << " SD=" << kStdDev |
998 << " N=" << kTestSamples[sidx]; | 1053 << " N=" << kTestSamples[sidx]; |
999 delete f; | 1054 delete f; |
1000 } | 1055 } |
1001 } | 1056 } |
1002 } | 1057 } |
1003 } | 1058 } |
OLD | NEW |