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

Side by Side Diff: webrtc/p2p/base/p2ptransportchannel_unittest.cc

Issue 2380923002: Replace RelayPort with TurnPort in p2ptransportchannel tests.
Patch Set: Do not have TURN TCP port, which caused some tests flaky Created 4 years, 2 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 | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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.3",
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"};
96 // Based on ICE_PWD_LENGTH 89 // Based on ICE_PWD_LENGTH
97 const char* kIcePwd[4] = { 90 const char* kIcePwd[4] = {
(...skipping 29 matching lines...) Expand all
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::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 }
137 } // namespace 152 } // namespace
138 153
139 namespace cricket { 154 namespace cricket {
140 155
141 // This test simulates 2 P2P endpoints that want to establish connectivity 156 // This test simulates 2 P2P endpoints that want to establish connectivity
142 // with each other over various network topologies and conditions, which can be 157 // with each other over various network topologies and conditions, which can be
143 // specified in each individial test. 158 // specified in each individial test.
144 // A virtual network (via VirtualSocketServer) along with virtual firewalls and 159 // A virtual network (via VirtualSocketServer) along with virtual firewalls and
145 // NATs (via Firewall/NATSocketServer) are used to simulate the various network 160 // NATs (via Firewall/NATSocketServer) are used to simulate the various network
146 // conditions. We can configure the IP addresses of the endpoints, 161 // conditions. We can configure the IP addresses of the endpoints,
(...skipping 12 matching lines...) Expand all
159 public: 174 public:
160 P2PTransportChannelTestBase() 175 P2PTransportChannelTestBase()
161 : main_(rtc::Thread::Current()), 176 : main_(rtc::Thread::Current()),
162 pss_(new rtc::PhysicalSocketServer), 177 pss_(new rtc::PhysicalSocketServer),
163 vss_(new rtc::VirtualSocketServer(pss_.get())), 178 vss_(new rtc::VirtualSocketServer(pss_.get())),
164 nss_(new rtc::NATSocketServer(vss_.get())), 179 nss_(new rtc::NATSocketServer(vss_.get())),
165 ss_(new rtc::FirewallSocketServer(nss_.get())), 180 ss_(new rtc::FirewallSocketServer(nss_.get())),
166 ss_scope_(ss_.get()), 181 ss_scope_(ss_.get()),
167 stun_server_(TestStunServer::Create(main_, kStunAddr)), 182 stun_server_(TestStunServer::Create(main_, kStunAddr)),
168 turn_server_(main_, kTurnUdpIntAddr, kTurnUdpExtAddr), 183 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(), 184 socks_server1_(ss_.get(),
177 kSocksProxyAddrs[0], 185 kSocksProxyAddrs[0],
178 ss_.get(), 186 ss_.get(),
179 kSocksProxyAddrs[0]), 187 kSocksProxyAddrs[0]),
180 socks_server2_(ss_.get(), 188 socks_server2_(ss_.get(),
181 kSocksProxyAddrs[1], 189 kSocksProxyAddrs[1],
182 ss_.get(), 190 ss_.get(),
183 kSocksProxyAddrs[1]), 191 kSocksProxyAddrs[1]),
184 force_relay_(false) { 192 force_relay_(false) {
185 ep1_.role_ = ICEROLE_CONTROLLING; 193 ep1_.role_ = ICEROLE_CONTROLLING;
186 ep2_.role_ = ICEROLE_CONTROLLED; 194 ep2_.role_ = ICEROLE_CONTROLLED;
187 195
188 ServerAddresses stun_servers; 196 ServerAddresses stun_servers;
189 stun_servers.insert(kStunAddr); 197 stun_servers.insert(kStunAddr);
190 ep1_.allocator_.reset(new BasicPortAllocator( 198 ep1_.allocator_.reset(
191 &ep1_.network_manager_, stun_servers, kRelayUdpIntAddr, 199 CreateBasicPortAllocator(&ep1_.network_manager_, stun_servers,
192 kRelayTcpIntAddr, kRelaySslTcpIntAddr)); 200 kTurnUdpIntAddr, rtc::SocketAddress()));
193 ep2_.allocator_.reset(new BasicPortAllocator( 201 ep2_.allocator_.reset(
194 &ep2_.network_manager_, stun_servers, kRelayUdpIntAddr, 202 CreateBasicPortAllocator(&ep2_.network_manager_, stun_servers,
195 kRelayTcpIntAddr, kRelaySslTcpIntAddr)); 203 kTurnUdpIntAddr, rtc::SocketAddress()));
196 } 204 }
197 205
198 protected: 206 protected:
199 enum Config { 207 enum Config {
200 OPEN, // Open to the Internet 208 OPEN, // Open to the Internet
201 NAT_FULL_CONE, // NAT, no filtering 209 NAT_FULL_CONE, // NAT, no filtering
202 NAT_ADDR_RESTRICTED, // NAT, must send to an addr to recv 210 NAT_ADDR_RESTRICTED, // NAT, must send to an addr to recv
203 NAT_PORT_RESTRICTED, // NAT, must send to an addr+port to recv 211 NAT_PORT_RESTRICTED, // NAT, must send to an addr+port to recv
204 NAT_SYMMETRIC, // NAT, endpoint-dependent bindings 212 NAT_SYMMETRIC, // NAT, endpoint-dependent bindings
205 NAT_DOUBLE_CONE, // Double NAT, both cone 213 NAT_DOUBLE_CONE, // Double NAT, both cone
(...skipping 631 matching lines...) Expand 10 before | Expand all | Expand 10 after
837 845
838 private: 846 private:
839 rtc::Thread* main_; 847 rtc::Thread* main_;
840 std::unique_ptr<rtc::PhysicalSocketServer> pss_; 848 std::unique_ptr<rtc::PhysicalSocketServer> pss_;
841 std::unique_ptr<rtc::VirtualSocketServer> vss_; 849 std::unique_ptr<rtc::VirtualSocketServer> vss_;
842 std::unique_ptr<rtc::NATSocketServer> nss_; 850 std::unique_ptr<rtc::NATSocketServer> nss_;
843 std::unique_ptr<rtc::FirewallSocketServer> ss_; 851 std::unique_ptr<rtc::FirewallSocketServer> ss_;
844 rtc::SocketServerScope ss_scope_; 852 rtc::SocketServerScope ss_scope_;
845 std::unique_ptr<TestStunServer> stun_server_; 853 std::unique_ptr<TestStunServer> stun_server_;
846 TestTurnServer turn_server_; 854 TestTurnServer turn_server_;
847 TestRelayServer relay_server_;
848 rtc::SocksProxyServer socks_server1_; 855 rtc::SocksProxyServer socks_server1_;
849 rtc::SocksProxyServer socks_server2_; 856 rtc::SocksProxyServer socks_server2_;
850 Endpoint ep1_; 857 Endpoint ep1_;
851 Endpoint ep2_; 858 Endpoint ep2_;
852 RemoteIceParameterSource remote_ice_parameter_source_ = FROM_CANDIDATE; 859 RemoteIceParameterSource remote_ice_parameter_source_ = FROM_CANDIDATE;
853 bool force_relay_; 860 bool force_relay_;
854 int selected_candidate_pair_switches_ = 0; 861 int selected_candidate_pair_switches_ = 0;
855 862
856 bool nominated_ = false; 863 bool nominated_ = false;
857 }; 864 };
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after
944 951
945 // Test the matrix of all the connectivity types we expect to see in the wild. 952 // 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. 953 // Just test every combination of the configs in the Config enum.
947 class P2PTransportChannelTest : public P2PTransportChannelTestBase { 954 class P2PTransportChannelTest : public P2PTransportChannelTestBase {
948 protected: 955 protected:
949 static const Result* kMatrix[NUM_CONFIGS][NUM_CONFIGS]; 956 static const Result* kMatrix[NUM_CONFIGS][NUM_CONFIGS];
950 void ConfigureEndpoints(Config config1, 957 void ConfigureEndpoints(Config config1,
951 Config config2, 958 Config config2,
952 int allocator_flags1, 959 int allocator_flags1,
953 int allocator_flags2) { 960 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; 961 int delay = kMinimumStepDelay;
971 ConfigureEndpoint(0, config1); 962 ConfigureEndpoint(0, config1);
972 SetAllocatorFlags(0, allocator_flags1); 963 SetAllocatorFlags(0, allocator_flags1);
973 SetAllocationStepDelay(0, delay); 964 SetAllocationStepDelay(0, delay);
974 ConfigureEndpoint(1, config2); 965 ConfigureEndpoint(1, config2);
975 SetAllocatorFlags(1, allocator_flags2); 966 SetAllocatorFlags(1, allocator_flags2);
976 SetAllocationStepDelay(1, delay); 967 SetAllocationStepDelay(1, delay);
977 968
978 set_remote_ice_parameter_source(FROM_SETICEPARAMETERS); 969 set_remote_ice_parameter_source(FROM_SETICEPARAMETERS);
979 } 970 }
(...skipping 2827 matching lines...) Expand 10 before | Expand all | Expand 10 after
3807 EXPECT_EQ_SIMULATED_WAIT(nullptr, GetPort(&ch), 1, fake_clock); 3798 EXPECT_EQ_SIMULATED_WAIT(nullptr, GetPort(&ch), 1, fake_clock);
3808 EXPECT_EQ_SIMULATED_WAIT(nullptr, GetPrunedPort(&ch), 1, fake_clock); 3799 EXPECT_EQ_SIMULATED_WAIT(nullptr, GetPrunedPort(&ch), 1, fake_clock);
3809 } 3800 }
3810 3801
3811 class P2PTransportChannelMostLikelyToWorkFirstTest 3802 class P2PTransportChannelMostLikelyToWorkFirstTest
3812 : public P2PTransportChannelPingTest { 3803 : public P2PTransportChannelPingTest {
3813 public: 3804 public:
3814 P2PTransportChannelMostLikelyToWorkFirstTest() 3805 P2PTransportChannelMostLikelyToWorkFirstTest()
3815 : turn_server_(rtc::Thread::Current(), kTurnUdpIntAddr, kTurnUdpExtAddr) { 3806 : turn_server_(rtc::Thread::Current(), kTurnUdpIntAddr, kTurnUdpExtAddr) {
3816 network_manager_.AddInterface(kPublicAddrs[0]); 3807 network_manager_.AddInterface(kPublicAddrs[0]);
3817 allocator_.reset(new BasicPortAllocator( 3808 allocator_.reset(
3818 &network_manager_, ServerAddresses(), rtc::SocketAddress(), 3809 CreateBasicPortAllocator(&network_manager_, ServerAddresses(),
3819 rtc::SocketAddress(), rtc::SocketAddress())); 3810 kTurnUdpIntAddr, rtc::SocketAddress()));
3820 allocator_->set_flags(allocator_->flags() | PORTALLOCATOR_DISABLE_STUN | 3811 allocator_->set_flags(allocator_->flags() | PORTALLOCATOR_DISABLE_STUN |
3821 PORTALLOCATOR_DISABLE_TCP); 3812 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); 3813 allocator_->set_step_delay(kMinimumStepDelay);
3827 } 3814 }
3828 3815
3829 P2PTransportChannel& StartTransportChannel( 3816 P2PTransportChannel& StartTransportChannel(
3830 bool prioritize_most_likely_to_work, 3817 bool prioritize_most_likely_to_work,
3831 int stable_writable_connection_ping_interval) { 3818 int stable_writable_connection_ping_interval) {
3832 channel_.reset(new P2PTransportChannel("checks", 1, nullptr, allocator())); 3819 channel_.reset(new P2PTransportChannel("checks", 1, nullptr, allocator()));
3833 IceConfig config = channel_->config(); 3820 IceConfig config = channel_->config();
3834 config.prioritize_most_likely_candidate_pairs = 3821 config.prioritize_most_likely_candidate_pairs =
3835 prioritize_most_likely_to_work; 3822 prioritize_most_likely_to_work;
(...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after
4013 4000
4014 // TCP Relay/Relay is the next. 4001 // TCP Relay/Relay is the next.
4015 VerifyNextPingableConnection(RELAY_PORT_TYPE, RELAY_PORT_TYPE, 4002 VerifyNextPingableConnection(RELAY_PORT_TYPE, RELAY_PORT_TYPE,
4016 TCP_PROTOCOL_NAME); 4003 TCP_PROTOCOL_NAME);
4017 4004
4018 // Finally, Local/Relay will be pinged. 4005 // Finally, Local/Relay will be pinged.
4019 VerifyNextPingableConnection(LOCAL_PORT_TYPE, RELAY_PORT_TYPE); 4006 VerifyNextPingableConnection(LOCAL_PORT_TYPE, RELAY_PORT_TYPE);
4020 } 4007 }
4021 4008
4022 } // namespace cricket { 4009 } // namespace cricket {
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698