OLD | NEW |
---|---|
1 /* | 1 /* |
2 * Copyright 2009 The WebRTC Project Authors. All rights reserved. | 2 * Copyright 2009 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 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
69 static const SocketAddress kPrivateAddrs[2] = | 69 static const SocketAddress kPrivateAddrs[2] = |
70 { SocketAddress("192.168.1.11", 0), SocketAddress("192.168.2.22", 0) }; | 70 { SocketAddress("192.168.1.11", 0), SocketAddress("192.168.2.22", 0) }; |
71 // For cascaded NATs, the internal addresses of the inner NAT boxes. | 71 // For cascaded NATs, the internal addresses of the inner NAT boxes. |
72 static const SocketAddress kCascadedNatAddrs[2] = | 72 static const SocketAddress kCascadedNatAddrs[2] = |
73 { SocketAddress("192.168.10.1", 0), SocketAddress("192.168.20.1", 0) }; | 73 { SocketAddress("192.168.10.1", 0), SocketAddress("192.168.20.1", 0) }; |
74 // For cascaded NATs, private addresses inside the inner private networks. | 74 // For cascaded NATs, private addresses inside the inner private networks. |
75 static const SocketAddress kCascadedPrivateAddrs[2] = | 75 static const SocketAddress kCascadedPrivateAddrs[2] = |
76 { SocketAddress("192.168.10.11", 0), SocketAddress("192.168.20.22", 0) }; | 76 { SocketAddress("192.168.10.11", 0), SocketAddress("192.168.20.22", 0) }; |
77 // The address of the public STUN server. | 77 // The address of the public STUN server. |
78 static const SocketAddress kStunAddr("99.99.99.1", cricket::STUN_SERVER_PORT); | 78 static const SocketAddress kStunAddr("99.99.99.1", cricket::STUN_SERVER_PORT); |
79 // The addresses for the public relay server. | |
80 static const SocketAddress kRelayUdpIntAddr("99.99.99.2", 5000); | |
81 static const SocketAddress kRelayUdpExtAddr("99.99.99.3", 5001); | |
82 static const SocketAddress kRelayTcpIntAddr("99.99.99.2", 5002); | |
83 static const SocketAddress kRelayTcpExtAddr("99.99.99.3", 5003); | |
84 static const SocketAddress kRelaySslTcpIntAddr("99.99.99.2", 5004); | |
85 static const SocketAddress kRelaySslTcpExtAddr("99.99.99.3", 5005); | |
86 // The addresses for the public turn server. | 79 // The addresses for the public turn server. |
87 static const SocketAddress kTurnUdpIntAddr("99.99.99.4", | 80 static const SocketAddress kTurnUdpIntAddr("99.99.99.4", |
88 cricket::STUN_SERVER_PORT); | 81 cricket::STUN_SERVER_PORT); |
89 static const SocketAddress kTurnTcpIntAddr("99.99.99.4", | 82 static const SocketAddress kTurnTcpIntAddr("99.99.99.4", |
90 cricket::STUN_SERVER_PORT + 1); | 83 cricket::STUN_SERVER_PORT + 1); |
91 static const SocketAddress kTurnUdpExtAddr("99.99.99.5", 0); | 84 static const SocketAddress kTurnUdpExtAddr("99.99.99.5", 0); |
92 static const cricket::RelayCredentials kRelayCredentials("test", "test"); | 85 static const cricket::RelayCredentials kRelayCredentials("test", "test"); |
93 | 86 |
94 // Based on ICE_UFRAG_LENGTH | 87 // Based on ICE_UFRAG_LENGTH |
95 const char* kIceUfrag[4] = {"UF00", "UF01", "UF02", "UF03"}; | 88 const char* kIceUfrag[4] = {"UF00", "UF01", "UF02", "UF03"}; |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
127 cricket::Candidate c; | 120 cricket::Candidate c; |
128 c.set_address(rtc::SocketAddress(ip, port)); | 121 c.set_address(rtc::SocketAddress(ip, port)); |
129 c.set_component(cricket::ICE_CANDIDATE_COMPONENT_DEFAULT); | 122 c.set_component(cricket::ICE_CANDIDATE_COMPONENT_DEFAULT); |
130 c.set_protocol(cricket::UDP_PROTOCOL_NAME); | 123 c.set_protocol(cricket::UDP_PROTOCOL_NAME); |
131 c.set_priority(priority); | 124 c.set_priority(priority); |
132 c.set_username(ufrag); | 125 c.set_username(ufrag); |
133 c.set_type(type); | 126 c.set_type(type); |
134 return c; | 127 return c; |
135 } | 128 } |
136 | 129 |
130 cricket::BasicPortAllocator* CreateBasicPortAllocator( | |
131 rtc::NetworkManager* network_manager, | |
132 const cricket::ServerAddresses& stun_servers, | |
133 const rtc::SocketAddress& turn_server_udp, | |
134 const rtc::SocketAddress& turn_server_tcp) { | |
135 cricket::BasicPortAllocator* allocator = | |
136 new cricket::BasicPortAllocator(network_manager); | |
137 if (!stun_servers.empty()) { | |
138 allocator->SetConfiguration( | |
139 stun_servers, std::vector<cricket::RelayServerConfig>(), 0, false); | |
140 } | |
141 | |
142 cricket::RelayServerConfig turn_server(cricket::RELAY_TURN); | |
143 turn_server.credentials = kRelayCredentials; | |
144 if (!turn_server_udp.IsNil()) { | |
145 turn_server.ports.push_back( | |
146 cricket::ProtocolAddress(turn_server_udp, cricket::PROTO_UDP, false)); | |
147 } | |
148 if (!turn_server_tcp.IsNil()) { | |
149 turn_server.ports.push_back( | |
150 cricket::ProtocolAddress(turn_server_tcp, cricket::PROTO_TCP, false)); | |
151 } | |
152 allocator->AddTurnServer(turn_server); | |
Taylor Brandstetter
2016/09/29 16:47:51
nit: Could we just call SetConfiguration once at t
honghaiz3
2016/09/29 17:18:58
Done. Good point.
| |
153 return allocator; | |
154 } | |
137 } // namespace | 155 } // namespace |
138 | 156 |
139 namespace cricket { | 157 namespace cricket { |
140 | 158 |
141 // This test simulates 2 P2P endpoints that want to establish connectivity | 159 // This test simulates 2 P2P endpoints that want to establish connectivity |
142 // with each other over various network topologies and conditions, which can be | 160 // with each other over various network topologies and conditions, which can be |
143 // specified in each individial test. | 161 // specified in each individial test. |
144 // A virtual network (via VirtualSocketServer) along with virtual firewalls and | 162 // A virtual network (via VirtualSocketServer) along with virtual firewalls and |
145 // NATs (via Firewall/NATSocketServer) are used to simulate the various network | 163 // NATs (via Firewall/NATSocketServer) are used to simulate the various network |
146 // conditions. We can configure the IP addresses of the endpoints, | 164 // conditions. We can configure the IP addresses of the endpoints, |
(...skipping 12 matching lines...) Expand all Loading... | |
159 public: | 177 public: |
160 P2PTransportChannelTestBase() | 178 P2PTransportChannelTestBase() |
161 : main_(rtc::Thread::Current()), | 179 : main_(rtc::Thread::Current()), |
162 pss_(new rtc::PhysicalSocketServer), | 180 pss_(new rtc::PhysicalSocketServer), |
163 vss_(new rtc::VirtualSocketServer(pss_.get())), | 181 vss_(new rtc::VirtualSocketServer(pss_.get())), |
164 nss_(new rtc::NATSocketServer(vss_.get())), | 182 nss_(new rtc::NATSocketServer(vss_.get())), |
165 ss_(new rtc::FirewallSocketServer(nss_.get())), | 183 ss_(new rtc::FirewallSocketServer(nss_.get())), |
166 ss_scope_(ss_.get()), | 184 ss_scope_(ss_.get()), |
167 stun_server_(TestStunServer::Create(main_, kStunAddr)), | 185 stun_server_(TestStunServer::Create(main_, kStunAddr)), |
168 turn_server_(main_, kTurnUdpIntAddr, kTurnUdpExtAddr), | 186 turn_server_(main_, kTurnUdpIntAddr, kTurnUdpExtAddr), |
169 relay_server_(main_, | |
170 kRelayUdpIntAddr, | |
171 kRelayUdpExtAddr, | |
172 kRelayTcpIntAddr, | |
173 kRelayTcpExtAddr, | |
174 kRelaySslTcpIntAddr, | |
175 kRelaySslTcpExtAddr), | |
176 socks_server1_(ss_.get(), | 187 socks_server1_(ss_.get(), |
177 kSocksProxyAddrs[0], | 188 kSocksProxyAddrs[0], |
178 ss_.get(), | 189 ss_.get(), |
179 kSocksProxyAddrs[0]), | 190 kSocksProxyAddrs[0]), |
180 socks_server2_(ss_.get(), | 191 socks_server2_(ss_.get(), |
181 kSocksProxyAddrs[1], | 192 kSocksProxyAddrs[1], |
182 ss_.get(), | 193 ss_.get(), |
183 kSocksProxyAddrs[1]), | 194 kSocksProxyAddrs[1]), |
184 force_relay_(false) { | 195 force_relay_(false) { |
185 ep1_.role_ = ICEROLE_CONTROLLING; | 196 ep1_.role_ = ICEROLE_CONTROLLING; |
186 ep2_.role_ = ICEROLE_CONTROLLED; | 197 ep2_.role_ = ICEROLE_CONTROLLED; |
187 | 198 |
199 turn_server_.AddInternalSocket(kTurnTcpIntAddr, PROTO_TCP); | |
188 ServerAddresses stun_servers; | 200 ServerAddresses stun_servers; |
189 stun_servers.insert(kStunAddr); | 201 stun_servers.insert(kStunAddr); |
190 ep1_.allocator_.reset(new BasicPortAllocator( | 202 ep1_.allocator_.reset( |
191 &ep1_.network_manager_, stun_servers, kRelayUdpIntAddr, | 203 CreateBasicPortAllocator(&ep1_.network_manager_, stun_servers, |
192 kRelayTcpIntAddr, kRelaySslTcpIntAddr)); | 204 kTurnUdpIntAddr, kTurnTcpIntAddr)); |
193 ep2_.allocator_.reset(new BasicPortAllocator( | 205 ep2_.allocator_.reset( |
194 &ep2_.network_manager_, stun_servers, kRelayUdpIntAddr, | 206 CreateBasicPortAllocator(&ep2_.network_manager_, stun_servers, |
195 kRelayTcpIntAddr, kRelaySslTcpIntAddr)); | 207 kTurnUdpIntAddr, kTurnTcpIntAddr)); |
196 } | 208 } |
197 | 209 |
198 protected: | 210 protected: |
199 enum Config { | 211 enum Config { |
200 OPEN, // Open to the Internet | 212 OPEN, // Open to the Internet |
201 NAT_FULL_CONE, // NAT, no filtering | 213 NAT_FULL_CONE, // NAT, no filtering |
202 NAT_ADDR_RESTRICTED, // NAT, must send to an addr to recv | 214 NAT_ADDR_RESTRICTED, // NAT, must send to an addr to recv |
203 NAT_PORT_RESTRICTED, // NAT, must send to an addr+port to recv | 215 NAT_PORT_RESTRICTED, // NAT, must send to an addr+port to recv |
204 NAT_SYMMETRIC, // NAT, endpoint-dependent bindings | 216 NAT_SYMMETRIC, // NAT, endpoint-dependent bindings |
205 NAT_DOUBLE_CONE, // Double NAT, both cone | 217 NAT_DOUBLE_CONE, // Double NAT, both cone |
(...skipping 631 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
837 | 849 |
838 private: | 850 private: |
839 rtc::Thread* main_; | 851 rtc::Thread* main_; |
840 std::unique_ptr<rtc::PhysicalSocketServer> pss_; | 852 std::unique_ptr<rtc::PhysicalSocketServer> pss_; |
841 std::unique_ptr<rtc::VirtualSocketServer> vss_; | 853 std::unique_ptr<rtc::VirtualSocketServer> vss_; |
842 std::unique_ptr<rtc::NATSocketServer> nss_; | 854 std::unique_ptr<rtc::NATSocketServer> nss_; |
843 std::unique_ptr<rtc::FirewallSocketServer> ss_; | 855 std::unique_ptr<rtc::FirewallSocketServer> ss_; |
844 rtc::SocketServerScope ss_scope_; | 856 rtc::SocketServerScope ss_scope_; |
845 std::unique_ptr<TestStunServer> stun_server_; | 857 std::unique_ptr<TestStunServer> stun_server_; |
846 TestTurnServer turn_server_; | 858 TestTurnServer turn_server_; |
847 TestRelayServer relay_server_; | |
848 rtc::SocksProxyServer socks_server1_; | 859 rtc::SocksProxyServer socks_server1_; |
849 rtc::SocksProxyServer socks_server2_; | 860 rtc::SocksProxyServer socks_server2_; |
850 Endpoint ep1_; | 861 Endpoint ep1_; |
851 Endpoint ep2_; | 862 Endpoint ep2_; |
852 RemoteIceParameterSource remote_ice_parameter_source_ = FROM_CANDIDATE; | 863 RemoteIceParameterSource remote_ice_parameter_source_ = FROM_CANDIDATE; |
853 bool force_relay_; | 864 bool force_relay_; |
854 int selected_candidate_pair_switches_ = 0; | 865 int selected_candidate_pair_switches_ = 0; |
855 | 866 |
856 bool nominated_ = false; | 867 bool nominated_ = false; |
857 }; | 868 }; |
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
944 | 955 |
945 // Test the matrix of all the connectivity types we expect to see in the wild. | 956 // Test the matrix of all the connectivity types we expect to see in the wild. |
946 // Just test every combination of the configs in the Config enum. | 957 // Just test every combination of the configs in the Config enum. |
947 class P2PTransportChannelTest : public P2PTransportChannelTestBase { | 958 class P2PTransportChannelTest : public P2PTransportChannelTestBase { |
948 protected: | 959 protected: |
949 static const Result* kMatrix[NUM_CONFIGS][NUM_CONFIGS]; | 960 static const Result* kMatrix[NUM_CONFIGS][NUM_CONFIGS]; |
950 void ConfigureEndpoints(Config config1, | 961 void ConfigureEndpoints(Config config1, |
951 Config config2, | 962 Config config2, |
952 int allocator_flags1, | 963 int allocator_flags1, |
953 int allocator_flags2) { | 964 int allocator_flags2) { |
954 ServerAddresses stun_servers; | |
955 stun_servers.insert(kStunAddr); | |
956 GetEndpoint(0)->allocator_.reset(new BasicPortAllocator( | |
957 &(GetEndpoint(0)->network_manager_), stun_servers, rtc::SocketAddress(), | |
958 rtc::SocketAddress(), rtc::SocketAddress())); | |
959 GetEndpoint(1)->allocator_.reset(new BasicPortAllocator( | |
960 &(GetEndpoint(1)->network_manager_), stun_servers, rtc::SocketAddress(), | |
961 rtc::SocketAddress(), rtc::SocketAddress())); | |
962 | |
963 RelayServerConfig turn_server(RELAY_TURN); | |
964 turn_server.credentials = kRelayCredentials; | |
965 turn_server.ports.push_back( | |
966 ProtocolAddress(kTurnUdpIntAddr, PROTO_UDP, false)); | |
967 GetEndpoint(0)->allocator_->AddTurnServer(turn_server); | |
968 GetEndpoint(1)->allocator_->AddTurnServer(turn_server); | |
969 | |
970 int delay = kMinimumStepDelay; | 965 int delay = kMinimumStepDelay; |
971 ConfigureEndpoint(0, config1); | 966 ConfigureEndpoint(0, config1); |
972 SetAllocatorFlags(0, allocator_flags1); | 967 SetAllocatorFlags(0, allocator_flags1); |
973 SetAllocationStepDelay(0, delay); | 968 SetAllocationStepDelay(0, delay); |
974 ConfigureEndpoint(1, config2); | 969 ConfigureEndpoint(1, config2); |
975 SetAllocatorFlags(1, allocator_flags2); | 970 SetAllocatorFlags(1, allocator_flags2); |
976 SetAllocationStepDelay(1, delay); | 971 SetAllocationStepDelay(1, delay); |
977 | 972 |
978 set_remote_ice_parameter_source(FROM_SETICEPARAMETERS); | 973 set_remote_ice_parameter_source(FROM_SETICEPARAMETERS); |
979 } | 974 } |
(...skipping 2827 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
3807 EXPECT_EQ_SIMULATED_WAIT(nullptr, GetPort(&ch), 1, fake_clock); | 3802 EXPECT_EQ_SIMULATED_WAIT(nullptr, GetPort(&ch), 1, fake_clock); |
3808 EXPECT_EQ_SIMULATED_WAIT(nullptr, GetPrunedPort(&ch), 1, fake_clock); | 3803 EXPECT_EQ_SIMULATED_WAIT(nullptr, GetPrunedPort(&ch), 1, fake_clock); |
3809 } | 3804 } |
3810 | 3805 |
3811 class P2PTransportChannelMostLikelyToWorkFirstTest | 3806 class P2PTransportChannelMostLikelyToWorkFirstTest |
3812 : public P2PTransportChannelPingTest { | 3807 : public P2PTransportChannelPingTest { |
3813 public: | 3808 public: |
3814 P2PTransportChannelMostLikelyToWorkFirstTest() | 3809 P2PTransportChannelMostLikelyToWorkFirstTest() |
3815 : turn_server_(rtc::Thread::Current(), kTurnUdpIntAddr, kTurnUdpExtAddr) { | 3810 : turn_server_(rtc::Thread::Current(), kTurnUdpIntAddr, kTurnUdpExtAddr) { |
3816 network_manager_.AddInterface(kPublicAddrs[0]); | 3811 network_manager_.AddInterface(kPublicAddrs[0]); |
3817 allocator_.reset(new BasicPortAllocator( | 3812 allocator_.reset( |
3818 &network_manager_, ServerAddresses(), rtc::SocketAddress(), | 3813 CreateBasicPortAllocator(&network_manager_, ServerAddresses(), |
3819 rtc::SocketAddress(), rtc::SocketAddress())); | 3814 kTurnUdpIntAddr, rtc::SocketAddress())); |
3820 allocator_->set_flags(allocator_->flags() | PORTALLOCATOR_DISABLE_STUN | | 3815 allocator_->set_flags(allocator_->flags() | PORTALLOCATOR_DISABLE_STUN | |
3821 PORTALLOCATOR_DISABLE_TCP); | 3816 PORTALLOCATOR_DISABLE_TCP); |
3822 RelayServerConfig config(RELAY_TURN); | |
3823 config.credentials = kRelayCredentials; | |
3824 config.ports.push_back(ProtocolAddress(kTurnUdpIntAddr, PROTO_UDP, false)); | |
3825 allocator_->AddTurnServer(config); | |
3826 allocator_->set_step_delay(kMinimumStepDelay); | 3817 allocator_->set_step_delay(kMinimumStepDelay); |
3827 } | 3818 } |
3828 | 3819 |
3829 P2PTransportChannel& StartTransportChannel( | 3820 P2PTransportChannel& StartTransportChannel( |
3830 bool prioritize_most_likely_to_work, | 3821 bool prioritize_most_likely_to_work, |
3831 int stable_writable_connection_ping_interval) { | 3822 int stable_writable_connection_ping_interval) { |
3832 channel_.reset(new P2PTransportChannel("checks", 1, nullptr, allocator())); | 3823 channel_.reset(new P2PTransportChannel("checks", 1, nullptr, allocator())); |
3833 IceConfig config = channel_->config(); | 3824 IceConfig config = channel_->config(); |
3834 config.prioritize_most_likely_candidate_pairs = | 3825 config.prioritize_most_likely_candidate_pairs = |
3835 prioritize_most_likely_to_work; | 3826 prioritize_most_likely_to_work; |
(...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
4013 | 4004 |
4014 // TCP Relay/Relay is the next. | 4005 // TCP Relay/Relay is the next. |
4015 VerifyNextPingableConnection(RELAY_PORT_TYPE, RELAY_PORT_TYPE, | 4006 VerifyNextPingableConnection(RELAY_PORT_TYPE, RELAY_PORT_TYPE, |
4016 TCP_PROTOCOL_NAME); | 4007 TCP_PROTOCOL_NAME); |
4017 | 4008 |
4018 // Finally, Local/Relay will be pinged. | 4009 // Finally, Local/Relay will be pinged. |
4019 VerifyNextPingableConnection(LOCAL_PORT_TYPE, RELAY_PORT_TYPE); | 4010 VerifyNextPingableConnection(LOCAL_PORT_TYPE, RELAY_PORT_TYPE); |
4020 } | 4011 } |
4021 | 4012 |
4022 } // namespace cricket { | 4013 } // namespace cricket { |
OLD | NEW |