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