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

Side by Side Diff: webrtc/p2p/client/basicportallocator_unittest.cc

Issue 2093623004: Add config to prune TURN ports (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Partially disable the test TestEachInterfaceHasItsOwnTurnPorts Created 4 years, 5 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 | « webrtc/p2p/client/basicportallocator.cc ('k') | 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 21 matching lines...) Expand all
32 #include "webrtc/base/socketaddress.h" 32 #include "webrtc/base/socketaddress.h"
33 #include "webrtc/base/ssladapter.h" 33 #include "webrtc/base/ssladapter.h"
34 #include "webrtc/base/thread.h" 34 #include "webrtc/base/thread.h"
35 #include "webrtc/base/virtualsocketserver.h" 35 #include "webrtc/base/virtualsocketserver.h"
36 36
37 using rtc::IPAddress; 37 using rtc::IPAddress;
38 using rtc::SocketAddress; 38 using rtc::SocketAddress;
39 using rtc::Thread; 39 using rtc::Thread;
40 40
41 static const SocketAddress kClientAddr("11.11.11.11", 0); 41 static const SocketAddress kClientAddr("11.11.11.11", 0);
42 static const SocketAddress kClientAddr2("22.22.22.22", 0);
42 static const SocketAddress kLoopbackAddr("127.0.0.1", 0); 43 static const SocketAddress kLoopbackAddr("127.0.0.1", 0);
43 static const SocketAddress kPrivateAddr("192.168.1.11", 0); 44 static const SocketAddress kPrivateAddr("192.168.1.11", 0);
44 static const SocketAddress kPrivateAddr2("192.168.1.12", 0); 45 static const SocketAddress kPrivateAddr2("192.168.1.12", 0);
45 static const SocketAddress kClientIPv6Addr("2401:fa00:4:1000:be30:5bff:fee5:c3", 46 static const SocketAddress kClientIPv6Addr("2401:fa00:4:1000:be30:5bff:fee5:c3",
46 0); 47 0);
47 static const SocketAddress kClientAddr2("22.22.22.22", 0); 48 static const SocketAddress kClientIPv6Addr2(
49 "2401:fa00:4:2000:be30:5bff:fee5:c3",
50 0);
48 static const SocketAddress kNatUdpAddr("77.77.77.77", rtc::NAT_SERVER_UDP_PORT); 51 static const SocketAddress kNatUdpAddr("77.77.77.77", rtc::NAT_SERVER_UDP_PORT);
49 static const SocketAddress kNatTcpAddr("77.77.77.77", rtc::NAT_SERVER_TCP_PORT); 52 static const SocketAddress kNatTcpAddr("77.77.77.77", rtc::NAT_SERVER_TCP_PORT);
50 static const SocketAddress kRemoteClientAddr("22.22.22.22", 0); 53 static const SocketAddress kRemoteClientAddr("22.22.22.22", 0);
51 static const SocketAddress kStunAddr("99.99.99.1", cricket::STUN_SERVER_PORT); 54 static const SocketAddress kStunAddr("99.99.99.1", cricket::STUN_SERVER_PORT);
52 static const SocketAddress kRelayUdpIntAddr("99.99.99.2", 5000); 55 static const SocketAddress kRelayUdpIntAddr("99.99.99.2", 5000);
53 static const SocketAddress kRelayUdpExtAddr("99.99.99.3", 5001); 56 static const SocketAddress kRelayUdpExtAddr("99.99.99.3", 5001);
54 static const SocketAddress kRelayTcpIntAddr("99.99.99.2", 5002); 57 static const SocketAddress kRelayTcpIntAddr("99.99.99.2", 5002);
55 static const SocketAddress kRelayTcpExtAddr("99.99.99.3", 5003); 58 static const SocketAddress kRelayTcpExtAddr("99.99.99.3", 5003);
56 static const SocketAddress kRelaySslTcpIntAddr("99.99.99.2", 5004); 59 static const SocketAddress kRelaySslTcpIntAddr("99.99.99.2", 5004);
57 static const SocketAddress kRelaySslTcpExtAddr("99.99.99.3", 5005); 60 static const SocketAddress kRelaySslTcpExtAddr("99.99.99.3", 5005);
58 static const SocketAddress kTurnUdpIntAddr("99.99.99.4", 3478); 61 static const SocketAddress kTurnUdpIntAddr("99.99.99.4", 3478);
62 static const SocketAddress kTurnUdpIntIPv6Addr(
63 "2402:fb00:4:1000:be30:5bff:fee5:c3",
64 3479);
59 static const SocketAddress kTurnTcpIntAddr("99.99.99.5", 3478); 65 static const SocketAddress kTurnTcpIntAddr("99.99.99.5", 3478);
66 static const SocketAddress kTurnTcpIntIPv6Addr(
67 "2402:fb00:4:2000:be30:5bff:fee5:c3",
68 3479);
60 static const SocketAddress kTurnUdpExtAddr("99.99.99.6", 0); 69 static const SocketAddress kTurnUdpExtAddr("99.99.99.6", 0);
61 70
62 // Minimum and maximum port for port range tests. 71 // Minimum and maximum port for port range tests.
63 static const int kMinPort = 10000; 72 static const int kMinPort = 10000;
64 static const int kMaxPort = 10099; 73 static const int kMaxPort = 10099;
65 74
66 // Based on ICE_UFRAG_LENGTH 75 // Based on ICE_UFRAG_LENGTH
67 static const char kIceUfrag0[] = "UF00"; 76 static const char kIceUfrag0[] = "UF00";
68 // Based on ICE_PWD_LENGTH 77 // Based on ICE_PWD_LENGTH
69 static const char kIcePwd0[] = "TESTICEPWD00000000000000"; 78 static const char kIcePwd0[] = "TESTICEPWD00000000000000";
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after
177 AddTurnServers(udp_turn, tcp_turn); 186 AddTurnServers(udp_turn, tcp_turn);
178 } 187 }
179 188
180 void AddTurnServers(const rtc::SocketAddress& udp_turn, 189 void AddTurnServers(const rtc::SocketAddress& udp_turn,
181 const rtc::SocketAddress& tcp_turn) { 190 const rtc::SocketAddress& tcp_turn) {
182 RelayServerConfig turn_server(RELAY_TURN); 191 RelayServerConfig turn_server(RELAY_TURN);
183 RelayCredentials credentials(kTurnUsername, kTurnPassword); 192 RelayCredentials credentials(kTurnUsername, kTurnPassword);
184 turn_server.credentials = credentials; 193 turn_server.credentials = credentials;
185 194
186 if (!udp_turn.IsNil()) { 195 if (!udp_turn.IsNil()) {
187 turn_server.ports.push_back( 196 turn_server.ports.push_back(ProtocolAddress(udp_turn, PROTO_UDP, false));
188 ProtocolAddress(kTurnUdpIntAddr, PROTO_UDP, false));
189 } 197 }
190 if (!tcp_turn.IsNil()) { 198 if (!tcp_turn.IsNil()) {
191 turn_server.ports.push_back( 199 turn_server.ports.push_back(ProtocolAddress(tcp_turn, PROTO_TCP, false));
192 ProtocolAddress(kTurnTcpIntAddr, PROTO_TCP, false));
193 } 200 }
194 allocator_->AddTurnServer(turn_server); 201 allocator_->AddTurnServer(turn_server);
195 } 202 }
196 203
197 bool CreateSession(int component) { 204 bool CreateSession(int component) {
198 session_ = CreateSession("session", component); 205 session_ = CreateSession("session", component);
199 if (!session_) { 206 if (!session_) {
200 return false; 207 return false;
201 } 208 }
202 return true; 209 return true;
(...skipping 22 matching lines...) Expand all
225 std::unique_ptr<PortAllocatorSession> CreateSession( 232 std::unique_ptr<PortAllocatorSession> CreateSession(
226 const std::string& sid, 233 const std::string& sid,
227 const std::string& content_name, 234 const std::string& content_name,
228 int component, 235 int component,
229 const std::string& ice_ufrag, 236 const std::string& ice_ufrag,
230 const std::string& ice_pwd) { 237 const std::string& ice_pwd) {
231 std::unique_ptr<PortAllocatorSession> session = allocator_->CreateSession( 238 std::unique_ptr<PortAllocatorSession> session = allocator_->CreateSession(
232 sid, content_name, component, ice_ufrag, ice_pwd); 239 sid, content_name, component, ice_ufrag, ice_pwd);
233 session->SignalPortReady.connect(this, 240 session->SignalPortReady.connect(this,
234 &BasicPortAllocatorTest::OnPortReady); 241 &BasicPortAllocatorTest::OnPortReady);
242 session->SignalPortPruned.connect(this,
243 &BasicPortAllocatorTest::OnPortPruned);
235 session->SignalCandidatesReady.connect( 244 session->SignalCandidatesReady.connect(
236 this, &BasicPortAllocatorTest::OnCandidatesReady); 245 this, &BasicPortAllocatorTest::OnCandidatesReady);
237 session->SignalCandidatesAllocationDone.connect( 246 session->SignalCandidatesAllocationDone.connect(
238 this, &BasicPortAllocatorTest::OnCandidatesAllocationDone); 247 this, &BasicPortAllocatorTest::OnCandidatesAllocationDone);
239 return session; 248 return session;
240 } 249 }
241 250
242 // Return true if the addresses are the same, or the port is 0 in |pattern| 251 // Return true if the addresses are the same, or the port is 0 in |pattern|
243 // (acting as a wildcard) and the IPs are the same. 252 // (acting as a wildcard) and the IPs are the same.
244 // Even with a wildcard port, the port of the address should be nonzero if 253 // Even with a wildcard port, the port of the address should be nonzero if
245 // the IP is nonzero. 254 // the IP is nonzero.
246 static bool AddressMatch(const SocketAddress& address, 255 static bool AddressMatch(const SocketAddress& address,
247 const SocketAddress& pattern) { 256 const SocketAddress& pattern) {
248 return address.ipaddr() == pattern.ipaddr() && 257 return address.ipaddr() == pattern.ipaddr() &&
249 ((pattern.port() == 0 && 258 ((pattern.port() == 0 &&
250 (address.port() != 0 || IPIsAny(address.ipaddr()))) || 259 (address.port() != 0 || IPIsAny(address.ipaddr()))) ||
251 (pattern.port() != 0 && address.port() == pattern.port())); 260 (pattern.port() != 0 && address.port() == pattern.port()));
252 } 261 }
253 262
263 // Returns the number of ports that have matching type, protocol and
264 // address.
265 static int CountPorts(const std::vector<PortInterface*>& ports,
266 const std::string& type,
267 ProtocolType protocol,
268 const SocketAddress& client_addr) {
269 return std::count_if(
270 ports.begin(), ports.end(),
271 [type, protocol, client_addr](PortInterface* port) {
272 return port->Type() == type && port->GetProtocol() == protocol &&
273 port->Network()->GetBestIP() == client_addr.ipaddr();
274 });
275 }
276
254 // Find a candidate and return it. 277 // Find a candidate and return it.
255 static bool FindCandidate(const std::vector<Candidate>& candidates, 278 static bool FindCandidate(const std::vector<Candidate>& candidates,
256 const std::string& type, 279 const std::string& type,
257 const std::string& proto, 280 const std::string& proto,
258 const SocketAddress& addr, 281 const SocketAddress& addr,
259 Candidate* found) { 282 Candidate* found) {
260 auto it = std::find_if(candidates.begin(), candidates.end(), 283 auto it = std::find_if(candidates.begin(), candidates.end(),
261 [type, proto, addr](const Candidate& c) { 284 [type, proto, addr](const Candidate& c) {
262 return c.type() == type && c.protocol() == proto && 285 return c.type() == type && c.protocol() == proto &&
263 AddressMatch(c.address(), addr); 286 AddressMatch(c.address(), addr);
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after
385 BasicPortAllocator& allocator() { return *allocator_; } 408 BasicPortAllocator& allocator() { return *allocator_; }
386 409
387 void OnPortReady(PortAllocatorSession* ses, PortInterface* port) { 410 void OnPortReady(PortAllocatorSession* ses, PortInterface* port) {
388 LOG(LS_INFO) << "OnPortReady: " << port->ToString(); 411 LOG(LS_INFO) << "OnPortReady: " << port->ToString();
389 ports_.push_back(port); 412 ports_.push_back(port);
390 // Make sure the new port is added to ReadyPorts. 413 // Make sure the new port is added to ReadyPorts.
391 auto ready_ports = ses->ReadyPorts(); 414 auto ready_ports = ses->ReadyPorts();
392 EXPECT_NE(ready_ports.end(), 415 EXPECT_NE(ready_ports.end(),
393 std::find(ready_ports.begin(), ready_ports.end(), port)); 416 std::find(ready_ports.begin(), ready_ports.end(), port));
394 } 417 }
418 void OnPortPruned(PortAllocatorSession* ses, PortInterface* port) {
419 LOG(LS_INFO) << "OnPortPruned: " << port->ToString();
420 ports_.erase(std::remove(ports_.begin(), ports_.end(), port), ports_.end());
421 // Make sure the pruned port is not in ReadyPorts.
422 auto ready_ports = ses->ReadyPorts();
423 EXPECT_EQ(ready_ports.end(),
424 std::find(ready_ports.begin(), ready_ports.end(), port));
425 }
426
395 void OnCandidatesReady(PortAllocatorSession* ses, 427 void OnCandidatesReady(PortAllocatorSession* ses,
396 const std::vector<Candidate>& candidates) { 428 const std::vector<Candidate>& candidates) {
397 for (const Candidate& candidate : candidates) { 429 for (const Candidate& candidate : candidates) {
398 LOG(LS_INFO) << "OnCandidatesReady: " << candidate.ToString(); 430 LOG(LS_INFO) << "OnCandidatesReady: " << candidate.ToString();
399 // Sanity check that the ICE component is set. 431 // Sanity check that the ICE component is set.
400 EXPECT_EQ(ICE_CANDIDATE_COMPONENT_RTP, candidate.component()); 432 EXPECT_EQ(ICE_CANDIDATE_COMPONENT_RTP, candidate.component());
401 candidates_.push_back(candidate); 433 candidates_.push_back(candidate);
402 } 434 }
403 // Make sure the new candidates are added to Candidates. 435 // Make sure the new candidates are added to Candidates.
404 auto ses_candidates = ses->ReadyCandidates(); 436 auto ses_candidates = ses->ReadyCandidates();
(...skipping 762 matching lines...) Expand 10 before | Expand all | Expand 10 after
1167 ASSERT_EQ(3U, ports_.size()); 1199 ASSERT_EQ(3U, ports_.size());
1168 EXPECT_PRED4(HasCandidate, candidates_, "local", "udp", kClientAddr); 1200 EXPECT_PRED4(HasCandidate, candidates_, "local", "udp", kClientAddr);
1169 EXPECT_PRED4(HasCandidate, candidates_, "relay", "udp", 1201 EXPECT_PRED4(HasCandidate, candidates_, "relay", "udp",
1170 rtc::SocketAddress(kTurnUdpExtAddr.ipaddr(), 0)); 1202 rtc::SocketAddress(kTurnUdpExtAddr.ipaddr(), 0));
1171 EXPECT_PRED4(HasCandidate, candidates_, "relay", "udp", 1203 EXPECT_PRED4(HasCandidate, candidates_, "relay", "udp",
1172 rtc::SocketAddress(kTurnUdpExtAddr.ipaddr(), 0)); 1204 rtc::SocketAddress(kTurnUdpExtAddr.ipaddr(), 0));
1173 EXPECT_TRUE_WAIT(candidate_allocation_done_, kDefaultAllocationTimeout); 1205 EXPECT_TRUE_WAIT(candidate_allocation_done_, kDefaultAllocationTimeout);
1174 EXPECT_EQ(3U, candidates_.size()); 1206 EXPECT_EQ(3U, candidates_.size());
1175 } 1207 }
1176 1208
1209 // Test that if prune_turn_ports is set, TCP TurnPort will not
1210 // be used if UDP TurnPort is used.
1211 TEST_F(BasicPortAllocatorTest, TestUdpTurnPortPrunesTcpTurnPorts) {
1212 turn_server_.AddInternalSocket(kTurnTcpIntAddr, PROTO_TCP);
1213 AddInterface(kClientAddr);
1214 allocator_.reset(new BasicPortAllocator(&network_manager_));
1215 allocator_->SetConfiguration(allocator_->stun_servers(),
1216 allocator_->turn_servers(), 0, true);
1217 AddTurnServers(kTurnUdpIntAddr, kTurnTcpIntAddr);
1218 allocator_->set_step_delay(kMinimumStepDelay);
1219 allocator_->set_flags(allocator().flags() |
1220 PORTALLOCATOR_ENABLE_SHARED_SOCKET |
1221 PORTALLOCATOR_DISABLE_TCP);
1222
1223 EXPECT_TRUE(CreateSession(ICE_CANDIDATE_COMPONENT_RTP));
1224 session_->StartGettingPorts();
1225 EXPECT_TRUE_WAIT(candidate_allocation_done_, kDefaultAllocationTimeout);
1226 // Only 2 ports (one STUN and one TURN) are actually being used.
1227 EXPECT_EQ(2U, session_->ReadyPorts().size());
1228 // We have verified that each port, when it is added to |ports_|, it is found
1229 // in |ready_ports|, and when it is pruned, it is not found in |ready_ports|,
1230 // so we only need to verify the content in one of them.
1231 EXPECT_EQ(2U, ports_.size());
1232 EXPECT_EQ(1, CountPorts(ports_, "local", PROTO_UDP, kClientAddr));
1233 EXPECT_EQ(1, CountPorts(ports_, "relay", PROTO_UDP, kClientAddr));
1234 EXPECT_EQ(0, CountPorts(ports_, "relay", PROTO_TCP, kClientAddr));
1235
1236 // We don't remove candidates, so the size of |candidates_| will depend on
1237 // when the TCP TURN port becomes ready. If it is ready after the UDP TURN
1238 // port becomes ready, its candidates will be used there will be 3 candidates.
1239 // Otherwise there will be only 2 candidates.
1240 EXPECT_LE(2U, candidates_.size());
1241 // There will only be 2 candidates in |ready_candidates| because it only
1242 // includes the candidates in the ready ports.
1243 const std::vector<Candidate>& ready_candidates = session_->ReadyCandidates();
1244 EXPECT_EQ(2U, ready_candidates.size());
1245 EXPECT_PRED4(HasCandidate, ready_candidates, "local", "udp", kClientAddr);
1246 EXPECT_PRED4(HasCandidate, ready_candidates, "relay", "udp",
1247 rtc::SocketAddress(kTurnUdpExtAddr.ipaddr(), 0));
1248 }
1249
1250 // Tests that if prune_turn_ports is set, IPv4 TurnPort will not
1251 // be used if IPv6 TurnPort is used.
1252 TEST_F(BasicPortAllocatorTest, TestIPv6TurnPortPrunesIPv4TurnPorts) {
1253 turn_server_.AddInternalSocket(kTurnUdpIntIPv6Addr, PROTO_UDP);
1254 // Add two IP addresses on the same interface.
1255 AddInterface(kClientAddr, "net1");
1256 AddInterface(kClientIPv6Addr, "net1");
1257 allocator_.reset(new BasicPortAllocator(&network_manager_));
1258 allocator_->SetConfiguration(allocator_->stun_servers(),
1259 allocator_->turn_servers(), 0, true);
1260 AddTurnServers(kTurnUdpIntIPv6Addr, rtc::SocketAddress());
1261
1262 allocator_->set_step_delay(kMinimumStepDelay);
1263 allocator_->set_flags(allocator().flags() |
1264 PORTALLOCATOR_ENABLE_SHARED_SOCKET |
1265 PORTALLOCATOR_ENABLE_IPV6 | PORTALLOCATOR_DISABLE_TCP);
1266
1267 EXPECT_TRUE(CreateSession(ICE_CANDIDATE_COMPONENT_RTP));
1268 session_->StartGettingPorts();
1269 EXPECT_TRUE_WAIT(candidate_allocation_done_, kDefaultAllocationTimeout);
1270 // Three ports (one IPv4 STUN, one IPv6 STUN and one TURN) will be ready.
1271 EXPECT_EQ(3U, session_->ReadyPorts().size());
1272 EXPECT_EQ(3U, ports_.size());
1273 EXPECT_EQ(1, CountPorts(ports_, "local", PROTO_UDP, kClientAddr));
1274 EXPECT_EQ(1, CountPorts(ports_, "local", PROTO_UDP, kClientIPv6Addr));
1275 EXPECT_EQ(1, CountPorts(ports_, "relay", PROTO_UDP, kClientIPv6Addr));
1276 EXPECT_EQ(0, CountPorts(ports_, "relay", PROTO_UDP, kClientAddr));
1277
1278 // We don't remove candidates, so there may be more than 3 elemenets in
1279 // |candidates_|, although |ready_candidates| only includes the candidates
1280 // in |ready_ports|.
1281 EXPECT_LE(3U, candidates_.size());
1282 const std::vector<Candidate>& ready_candidates = session_->ReadyCandidates();
1283 EXPECT_EQ(3U, ready_candidates.size());
1284 EXPECT_PRED4(HasCandidate, ready_candidates, "local", "udp", kClientAddr);
1285 EXPECT_PRED4(HasCandidate, ready_candidates, "relay", "udp",
1286 rtc::SocketAddress(kTurnUdpExtAddr.ipaddr(), 0));
1287 }
1288
1289 // Test has an assert error on win_x64_dbg and win_dbg. See: webrtc:6068
1290 #if defined(WEBRTC_WIN)
1291 #define MAYBE_TestEachInterfaceHasItsOwnTurnPorts \
1292 DISABLED_TestEachInterfaceHasItsOwnTurnPort
1293 #else
1294 #define MAYBE_TestEachInterfaceHasItsOwnTurnPorts \
1295 TestEachInterfaceHasItsOwnTurnPorts
1296 #endif
1297 // Tests that if prune_turn_ports is set, each network interface
1298 // will has its own set of TurnPorts based on their priorities.
1299 TEST_F(BasicPortAllocatorTest, MAYBE_TestEachInterfaceHasItsOwnTurnPorts) {
1300 turn_server_.AddInternalSocket(kTurnTcpIntAddr, PROTO_TCP);
1301 turn_server_.AddInternalSocket(kTurnUdpIntIPv6Addr, PROTO_UDP);
1302 turn_server_.AddInternalSocket(kTurnTcpIntIPv6Addr, PROTO_TCP);
1303 // Add two interfaces both having IPv4 and IPv6 addresses.
1304 AddInterface(kClientAddr, "net1", rtc::ADAPTER_TYPE_WIFI);
1305 AddInterface(kClientIPv6Addr, "net1", rtc::ADAPTER_TYPE_WIFI);
1306 AddInterface(kClientAddr2, "net2", rtc::ADAPTER_TYPE_CELLULAR);
1307 AddInterface(kClientIPv6Addr2, "net2", rtc::ADAPTER_TYPE_CELLULAR);
1308 allocator_.reset(new BasicPortAllocator(&network_manager_));
1309 allocator_->SetConfiguration(allocator_->stun_servers(),
1310 allocator_->turn_servers(), 0, true);
1311 // Have both UDP/TCP and IPv4/IPv6 TURN ports.
1312 AddTurnServers(kTurnUdpIntAddr, kTurnTcpIntAddr);
1313 AddTurnServers(kTurnUdpIntIPv6Addr, kTurnTcpIntIPv6Addr);
1314
1315 allocator_->set_step_delay(kMinimumStepDelay);
1316 allocator_->set_flags(allocator().flags() |
1317 PORTALLOCATOR_ENABLE_SHARED_SOCKET |
1318 PORTALLOCATOR_ENABLE_IPV6);
1319 EXPECT_TRUE(CreateSession(ICE_CANDIDATE_COMPONENT_RTP));
1320 session_->StartGettingPorts();
1321 EXPECT_TRUE_WAIT(candidate_allocation_done_, kDefaultAllocationTimeout);
1322 // 10 ports (4 STUN and 1 TURN ports on each interface) will be ready to use.
1323 EXPECT_EQ(10U, session_->ReadyPorts().size());
1324 EXPECT_EQ(10U, ports_.size());
1325 EXPECT_EQ(1, CountPorts(ports_, "local", PROTO_UDP, kClientAddr));
1326 EXPECT_EQ(1, CountPorts(ports_, "local", PROTO_UDP, kClientAddr2));
1327 EXPECT_EQ(1, CountPorts(ports_, "local", PROTO_UDP, kClientIPv6Addr));
1328 EXPECT_EQ(1, CountPorts(ports_, "local", PROTO_UDP, kClientIPv6Addr2));
1329 EXPECT_EQ(1, CountPorts(ports_, "local", PROTO_TCP, kClientAddr));
1330 EXPECT_EQ(1, CountPorts(ports_, "local", PROTO_TCP, kClientAddr2));
1331 EXPECT_EQ(1, CountPorts(ports_, "local", PROTO_TCP, kClientIPv6Addr));
1332 EXPECT_EQ(1, CountPorts(ports_, "local", PROTO_TCP, kClientIPv6Addr2));
1333 EXPECT_EQ(1, CountPorts(ports_, "relay", PROTO_UDP, kClientIPv6Addr));
1334 EXPECT_EQ(1, CountPorts(ports_, "relay", PROTO_UDP, kClientIPv6Addr2));
1335
1336 // We don't remove candidates, so there may be more than 10 candidates
1337 // in |candidates_|.
1338 EXPECT_LE(10U, candidates_.size());
1339 const std::vector<Candidate>& ready_candidates = session_->ReadyCandidates();
1340 EXPECT_EQ(10U, ready_candidates.size());
1341 EXPECT_PRED4(HasCandidate, ready_candidates, "local", "udp", kClientAddr);
1342 EXPECT_PRED4(HasCandidate, ready_candidates, "local", "udp", kClientAddr2);
1343 EXPECT_PRED4(HasCandidate, ready_candidates, "local", "udp", kClientIPv6Addr);
1344 EXPECT_PRED4(HasCandidate, ready_candidates, "local", "udp",
1345 kClientIPv6Addr2);
1346 EXPECT_PRED4(HasCandidate, ready_candidates, "local", "tcp", kClientAddr);
1347 EXPECT_PRED4(HasCandidate, ready_candidates, "local", "tcp", kClientAddr2);
1348 EXPECT_PRED4(HasCandidate, ready_candidates, "local", "tcp", kClientIPv6Addr);
1349 EXPECT_PRED4(HasCandidate, ready_candidates, "local", "tcp",
1350 kClientIPv6Addr2);
1351 EXPECT_PRED4(HasCandidate, ready_candidates, "relay", "udp",
1352 rtc::SocketAddress(kTurnUdpExtAddr.ipaddr(), 0));
1353 }
1354
1177 // Testing DNS resolve for the TURN server, this will test AllocationSequence 1355 // Testing DNS resolve for the TURN server, this will test AllocationSequence
1178 // handling the unresolved address signal from TurnPort. 1356 // handling the unresolved address signal from TurnPort.
1179 TEST_F(BasicPortAllocatorTest, TestSharedSocketWithServerAddressResolve) { 1357 TEST_F(BasicPortAllocatorTest, TestSharedSocketWithServerAddressResolve) {
1180 turn_server_.AddInternalSocket(rtc::SocketAddress("127.0.0.1", 3478), 1358 turn_server_.AddInternalSocket(rtc::SocketAddress("127.0.0.1", 3478),
1181 PROTO_UDP); 1359 PROTO_UDP);
1182 AddInterface(kClientAddr); 1360 AddInterface(kClientAddr);
1183 allocator_.reset(new BasicPortAllocator(&network_manager_)); 1361 allocator_.reset(new BasicPortAllocator(&network_manager_));
1184 RelayServerConfig turn_server(RELAY_TURN); 1362 RelayServerConfig turn_server(RELAY_TURN);
1185 RelayCredentials credentials(kTurnUsername, kTurnPassword); 1363 RelayCredentials credentials(kTurnUsername, kTurnPassword);
1186 turn_server.credentials = credentials; 1364 turn_server.credentials = credentials;
(...skipping 275 matching lines...) Expand 10 before | Expand all | Expand 10 after
1462 ASSERT_EQ_WAIT(2U, candidates_.size(), 1000); 1640 ASSERT_EQ_WAIT(2U, candidates_.size(), 1000);
1463 EXPECT_EQ(2U, ports_.size()); 1641 EXPECT_EQ(2U, ports_.size());
1464 } 1642 }
1465 1643
1466 // Test that the ports and candidates are updated with new ufrag/pwd/etc. when 1644 // Test that the ports and candidates are updated with new ufrag/pwd/etc. when
1467 // a pooled session is taken out of the pool. 1645 // a pooled session is taken out of the pool.
1468 TEST_F(BasicPortAllocatorTest, TestTransportInformationUpdated) { 1646 TEST_F(BasicPortAllocatorTest, TestTransportInformationUpdated) {
1469 AddInterface(kClientAddr); 1647 AddInterface(kClientAddr);
1470 int pool_size = 1; 1648 int pool_size = 1;
1471 allocator_->SetConfiguration(allocator_->stun_servers(), 1649 allocator_->SetConfiguration(allocator_->stun_servers(),
1472 allocator_->turn_servers(), pool_size); 1650 allocator_->turn_servers(), pool_size, false);
1473 const PortAllocatorSession* peeked_session = allocator_->GetPooledSession(); 1651 const PortAllocatorSession* peeked_session = allocator_->GetPooledSession();
1474 ASSERT_NE(nullptr, peeked_session); 1652 ASSERT_NE(nullptr, peeked_session);
1475 EXPECT_EQ_WAIT(true, peeked_session->CandidatesAllocationDone(), 1653 EXPECT_EQ_WAIT(true, peeked_session->CandidatesAllocationDone(),
1476 kDefaultAllocationTimeout); 1654 kDefaultAllocationTimeout);
1477 // Expect that when TakePooledSession is called, 1655 // Expect that when TakePooledSession is called,
1478 // UpdateTransportInformationInternal will be called and the 1656 // UpdateTransportInformationInternal will be called and the
1479 // BasicPortAllocatorSession will update the ufrag/pwd of ports and 1657 // BasicPortAllocatorSession will update the ufrag/pwd of ports and
1480 // candidates. 1658 // candidates.
1481 session_ = 1659 session_ =
1482 allocator_->TakePooledSession(kContentName, 1, kIceUfrag0, kIcePwd0); 1660 allocator_->TakePooledSession(kContentName, 1, kIceUfrag0, kIcePwd0);
(...skipping 15 matching lines...) Expand all
1498 EXPECT_EQ(kIcePwd0, candidate.password()); 1676 EXPECT_EQ(kIcePwd0, candidate.password());
1499 } 1677 }
1500 } 1678 }
1501 1679
1502 // Test that a new candidate filter takes effect even on already-gathered 1680 // Test that a new candidate filter takes effect even on already-gathered
1503 // candidates. 1681 // candidates.
1504 TEST_F(BasicPortAllocatorTest, TestSetCandidateFilterAfterCandidatesGathered) { 1682 TEST_F(BasicPortAllocatorTest, TestSetCandidateFilterAfterCandidatesGathered) {
1505 AddInterface(kClientAddr); 1683 AddInterface(kClientAddr);
1506 int pool_size = 1; 1684 int pool_size = 1;
1507 allocator_->SetConfiguration(allocator_->stun_servers(), 1685 allocator_->SetConfiguration(allocator_->stun_servers(),
1508 allocator_->turn_servers(), pool_size); 1686 allocator_->turn_servers(), pool_size, false);
1509 const PortAllocatorSession* peeked_session = allocator_->GetPooledSession(); 1687 const PortAllocatorSession* peeked_session = allocator_->GetPooledSession();
1510 ASSERT_NE(nullptr, peeked_session); 1688 ASSERT_NE(nullptr, peeked_session);
1511 EXPECT_EQ_WAIT(true, peeked_session->CandidatesAllocationDone(), 1689 EXPECT_EQ_WAIT(true, peeked_session->CandidatesAllocationDone(),
1512 kDefaultAllocationTimeout); 1690 kDefaultAllocationTimeout);
1513 size_t initial_candidates_size = peeked_session->ReadyCandidates().size(); 1691 size_t initial_candidates_size = peeked_session->ReadyCandidates().size();
1514 size_t initial_ports_size = peeked_session->ReadyPorts().size(); 1692 size_t initial_ports_size = peeked_session->ReadyPorts().size();
1515 allocator_->set_candidate_filter(CF_RELAY); 1693 allocator_->set_candidate_filter(CF_RELAY);
1516 // Assume that when TakePooledSession is called, the candidate filter will be 1694 // Assume that when TakePooledSession is called, the candidate filter will be
1517 // applied to the pooled session. This is tested by PortAllocatorTest. 1695 // applied to the pooled session. This is tested by PortAllocatorTest.
1518 session_ = 1696 session_ =
(...skipping 11 matching lines...) Expand all
1530 for (const Candidate& candidate : candidates) { 1708 for (const Candidate& candidate : candidates) {
1531 // Expect only relay candidates now that the filter is applied. 1709 // Expect only relay candidates now that the filter is applied.
1532 EXPECT_EQ(std::string(RELAY_PORT_TYPE), candidate.type()); 1710 EXPECT_EQ(std::string(RELAY_PORT_TYPE), candidate.type());
1533 // Expect that the raddr is emptied due to the CF_RELAY filter. 1711 // Expect that the raddr is emptied due to the CF_RELAY filter.
1534 EXPECT_EQ(candidate.related_address(), 1712 EXPECT_EQ(candidate.related_address(),
1535 rtc::EmptySocketAddressWithFamily(candidate.address().family())); 1713 rtc::EmptySocketAddressWithFamily(candidate.address().family()));
1536 } 1714 }
1537 } 1715 }
1538 1716
1539 } // namespace cricket 1717 } // namespace cricket
OLDNEW
« no previous file with comments | « webrtc/p2p/client/basicportallocator.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698