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

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

Issue 2006263004: In BasicPortAllocator test, don't require a specific candidate order. (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Re-enable the main flaky test that was disabled. Created 4 years, 7 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 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
76 76
77 // STUN timeout (with all retries) is 9500ms. 77 // STUN timeout (with all retries) is 9500ms.
78 // Add some margin of error for slow bots. 78 // Add some margin of error for slow bots.
79 // TODO(deadbeef): Use simulated clock instead of just increasing timeouts to 79 // TODO(deadbeef): Use simulated clock instead of just increasing timeouts to
80 // fix flaky tests. 80 // fix flaky tests.
81 static const int kStunTimeoutMs = 15000; 81 static const int kStunTimeoutMs = 15000;
82 82
83 namespace cricket { 83 namespace cricket {
84 84
85 // Helper for dumping candidates 85 // Helper for dumping candidates
86 std::ostream& operator<<(std::ostream& os, const Candidate& c) { 86 std::ostream& operator<<(std::ostream& os,
87 os << c.ToString(); 87 const std::vector<Candidate>& candidates) {
88 os << '[';
89 bool first = true;
90 for (const Candidate& c : candidates) {
91 if (!first) {
92 os << ", ";
93 }
94 os << c.ToString();
95 first = false;
96 };
97 os << ']';
88 return os; 98 return os;
89 } 99 }
90 100
91 class BasicPortAllocatorTest : public testing::Test, 101 class BasicPortAllocatorTest : public testing::Test,
92 public sigslot::has_slots<> { 102 public sigslot::has_slots<> {
93 public: 103 public:
94 BasicPortAllocatorTest() 104 BasicPortAllocatorTest()
95 : pss_(new rtc::PhysicalSocketServer), 105 : pss_(new rtc::PhysicalSocketServer),
96 vss_(new rtc::VirtualSocketServer(pss_.get())), 106 vss_(new rtc::VirtualSocketServer(pss_.get())),
97 fss_(new rtc::FirewallSocketServer(vss_.get())), 107 fss_(new rtc::FirewallSocketServer(vss_.get())),
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after
222 sid, content_name, component, ice_ufrag, ice_pwd); 232 sid, content_name, component, ice_ufrag, ice_pwd);
223 session->SignalPortReady.connect(this, 233 session->SignalPortReady.connect(this,
224 &BasicPortAllocatorTest::OnPortReady); 234 &BasicPortAllocatorTest::OnPortReady);
225 session->SignalCandidatesReady.connect( 235 session->SignalCandidatesReady.connect(
226 this, &BasicPortAllocatorTest::OnCandidatesReady); 236 this, &BasicPortAllocatorTest::OnCandidatesReady);
227 session->SignalCandidatesAllocationDone.connect( 237 session->SignalCandidatesAllocationDone.connect(
228 this, &BasicPortAllocatorTest::OnCandidatesAllocationDone); 238 this, &BasicPortAllocatorTest::OnCandidatesAllocationDone);
229 return session; 239 return session;
230 } 240 }
231 241
232 static bool CheckCandidate(const Candidate& c, 242 // Return true if the addresses are the same, or the port is 0 in |pattern|
233 int component, 243 // (acting as a wildcard) and the IPs are the same.
234 const std::string& type, 244 // Even with a wildcard port, the port of the address should be nonzero.
235 const std::string& proto, 245 static bool AddressMatch(const SocketAddress& address,
236 const SocketAddress& addr) { 246 const SocketAddress& pattern) {
237 return (c.component() == component && c.type() == type && 247 return address.ipaddr() == pattern.ipaddr() &&
238 c.protocol() == proto && c.address().ipaddr() == addr.ipaddr() && 248 ((pattern.port() == 0 && address.port() != 0) ||
239 ((addr.port() == 0 && (c.address().port() != 0)) || 249 (pattern.port() != 0 && address.port() == pattern.port()));
240 (c.address().port() == addr.port())));
241 } 250 }
251
252 static bool FindCandidate(const std::vector<Candidate>& candidates,
253 const std::string& type,
254 const std::string& proto,
255 const SocketAddress& addr) {
256 auto it = std::find_if(candidates.begin(), candidates.end(),
257 [type, proto, addr](const Candidate& c) {
258 return c.type() == type && c.protocol() == proto &&
259 AddressMatch(c.address(), addr);
260 });
261 return it != candidates.end();
pthatcher1 2016/05/25 20:49:05 Can't this just be the following? Candidate c; re
Taylor Brandstetter 2016/05/25 21:48:42 Done.
262 }
263
264 // Find a candidate and return it.
265 static bool FindAndReturnCandidate(const std::vector<Candidate>& candidates,
pthatcher1 2016/05/25 20:49:05 I think it would be more clear if you renamed it a
Taylor Brandstetter 2016/05/25 21:48:43 Done.
266 const std::string& type,
267 const std::string& proto,
268 const SocketAddress& addr,
269 Candidate* found) {
270 auto it = std::find_if(candidates.begin(), candidates.end(),
271 [type, proto, addr](const Candidate& c) {
272 return c.type() == type && c.protocol() == proto &&
273 AddressMatch(c.address(), addr);
274 });
275 if (it != candidates.end()) {
276 *found = *it;
277 }
278 return it != candidates.end();
279 }
280
281 // Version of FindCandidate that also takes a related addr.
282 static bool FindCandidateWithRelatedAddr(
283 const std::vector<Candidate>& candidates,
284 const std::string& type,
285 const std::string& proto,
286 const SocketAddress& addr,
287 const SocketAddress& related_addr) {
288 auto it =
289 std::find_if(candidates.begin(), candidates.end(),
290 [type, proto, addr, related_addr](const Candidate& c) {
291 return c.type() == type && c.protocol() == proto &&
292 AddressMatch(c.address(), addr) &&
293 AddressMatch(c.related_address(), related_addr);
294 });
295 return it != candidates.end();
296 }
297
242 static bool CheckPort(const rtc::SocketAddress& addr, 298 static bool CheckPort(const rtc::SocketAddress& addr,
243 int min_port, 299 int min_port,
244 int max_port) { 300 int max_port) {
245 return (addr.port() >= min_port && addr.port() <= max_port); 301 return (addr.port() >= min_port && addr.port() <= max_port);
246 } 302 }
247 303
248 void OnCandidatesAllocationDone(PortAllocatorSession* session) { 304 void OnCandidatesAllocationDone(PortAllocatorSession* session) {
249 // We should only get this callback once, except in the mux test where 305 // We should only get this callback once, except in the mux test where
250 // we have multiple port allocation sessions. 306 // we have multiple port allocation sessions.
251 if (session == session_.get()) { 307 if (session == session_.get()) {
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
290 } 346 }
291 session_->set_flags(session_->flags() | 347 session_->set_flags(session_->flags() |
292 PORTALLOCATOR_DISABLE_ADAPTER_ENUMERATION | 348 PORTALLOCATOR_DISABLE_ADAPTER_ENUMERATION |
293 PORTALLOCATOR_ENABLE_SHARED_SOCKET); 349 PORTALLOCATOR_ENABLE_SHARED_SOCKET);
294 allocator().set_allow_tcp_listen(false); 350 allocator().set_allow_tcp_listen(false);
295 session_->StartGettingPorts(); 351 session_->StartGettingPorts();
296 EXPECT_TRUE_WAIT(candidate_allocation_done_, kDefaultAllocationTimeout); 352 EXPECT_TRUE_WAIT(candidate_allocation_done_, kDefaultAllocationTimeout);
297 353
298 uint32_t total_candidates = 0; 354 uint32_t total_candidates = 0;
299 if (!host_candidate_addr.IsNil()) { 355 if (!host_candidate_addr.IsNil()) {
300 EXPECT_PRED5(CheckCandidate, candidates_[total_candidates], 356 EXPECT_PRED4(FindCandidate, candidates_, "local", "udp",
301 ICE_CANDIDATE_COMPONENT_RTP, "local", "udp",
302 rtc::SocketAddress(kPrivateAddr.ipaddr(), 0)); 357 rtc::SocketAddress(kPrivateAddr.ipaddr(), 0));
303 ++total_candidates; 358 ++total_candidates;
304 } 359 }
305 if (!stun_candidate_addr.IsNil()) { 360 if (!stun_candidate_addr.IsNil()) {
306 EXPECT_PRED5(CheckCandidate, candidates_[total_candidates], 361 rtc::SocketAddress related_address(host_candidate_addr, 0);
307 ICE_CANDIDATE_COMPONENT_RTP, "stun", "udp",
308 rtc::SocketAddress(stun_candidate_addr, 0));
309 rtc::IPAddress related_address = host_candidate_addr;
310 if (host_candidate_addr.IsNil()) { 362 if (host_candidate_addr.IsNil()) {
311 related_address = 363 related_address.SetIP(rtc::GetAnyIP(stun_candidate_addr.family()));
312 rtc::GetAnyIP(candidates_[total_candidates].address().family());
313 } 364 }
314 EXPECT_EQ(related_address, 365 EXPECT_PRED5(FindCandidateWithRelatedAddr, candidates_, "stun", "udp",
315 candidates_[total_candidates].related_address().ipaddr()); 366 rtc::SocketAddress(stun_candidate_addr, 0), related_address);
316 ++total_candidates; 367 ++total_candidates;
317 } 368 }
318 if (!relay_candidate_udp_transport_addr.IsNil()) { 369 if (!relay_candidate_udp_transport_addr.IsNil()) {
319 EXPECT_PRED5(CheckCandidate, candidates_[total_candidates], 370 EXPECT_PRED5(FindCandidateWithRelatedAddr, candidates_, "relay", "udp",
320 ICE_CANDIDATE_COMPONENT_RTP, "relay", "udp", 371 rtc::SocketAddress(relay_candidate_udp_transport_addr, 0),
321 rtc::SocketAddress(relay_candidate_udp_transport_addr, 0)); 372 rtc::SocketAddress(stun_candidate_addr, 0));
322 EXPECT_EQ(stun_candidate_addr,
323 candidates_[total_candidates].related_address().ipaddr());
324 ++total_candidates; 373 ++total_candidates;
325 } 374 }
326 if (!relay_candidate_tcp_transport_addr.IsNil()) { 375 if (!relay_candidate_tcp_transport_addr.IsNil()) {
327 EXPECT_PRED5(CheckCandidate, candidates_[total_candidates], 376 EXPECT_PRED5(FindCandidateWithRelatedAddr, candidates_, "relay", "udp",
328 ICE_CANDIDATE_COMPONENT_RTP, "relay", "udp", 377 rtc::SocketAddress(relay_candidate_tcp_transport_addr, 0),
329 rtc::SocketAddress(relay_candidate_tcp_transport_addr, 0)); 378 rtc::SocketAddress(stun_candidate_addr, 0));
330 EXPECT_EQ(stun_candidate_addr,
331 candidates_[total_candidates].related_address().ipaddr());
332 ++total_candidates; 379 ++total_candidates;
333 } 380 }
334 381
335 EXPECT_EQ(total_candidates, candidates_.size()); 382 EXPECT_EQ(total_candidates, candidates_.size());
336 EXPECT_EQ(total_ports, ports_.size()); 383 EXPECT_EQ(total_ports, ports_.size());
337 } 384 }
338 385
339 protected: 386 protected:
340 BasicPortAllocator& allocator() { return *allocator_; } 387 BasicPortAllocator& allocator() { return *allocator_; }
341 388
342 void OnPortReady(PortAllocatorSession* ses, PortInterface* port) { 389 void OnPortReady(PortAllocatorSession* ses, PortInterface* port) {
343 LOG(LS_INFO) << "OnPortReady: " << port->ToString(); 390 LOG(LS_INFO) << "OnPortReady: " << port->ToString();
344 ports_.push_back(port); 391 ports_.push_back(port);
345 // Make sure the new port is added to ReadyPorts. 392 // Make sure the new port is added to ReadyPorts.
346 auto ready_ports = ses->ReadyPorts(); 393 auto ready_ports = ses->ReadyPorts();
347 EXPECT_NE(ready_ports.end(), 394 EXPECT_NE(ready_ports.end(),
348 std::find(ready_ports.begin(), ready_ports.end(), port)); 395 std::find(ready_ports.begin(), ready_ports.end(), port));
349 } 396 }
350 void OnCandidatesReady(PortAllocatorSession* ses, 397 void OnCandidatesReady(PortAllocatorSession* ses,
351 const std::vector<Candidate>& candidates) { 398 const std::vector<Candidate>& candidates) {
352 for (size_t i = 0; i < candidates.size(); ++i) { 399 for (const Candidate& candidate : candidates) {
353 LOG(LS_INFO) << "OnCandidatesReady: " << candidates[i].ToString(); 400 LOG(LS_INFO) << "OnCandidatesReady: " << candidate.ToString();
354 candidates_.push_back(candidates[i]); 401 // Sanity check that the ICE component is set.
402 EXPECT_EQ(ICE_CANDIDATE_COMPONENT_RTP, candidate.component());
403 candidates_.push_back(candidate);
355 } 404 }
356 // Make sure the new candidates are added to Candidates. 405 // Make sure the new candidates are added to Candidates.
357 auto ses_candidates = ses->ReadyCandidates(); 406 auto ses_candidates = ses->ReadyCandidates();
358 for (const Candidate& candidate : candidates) { 407 for (const Candidate& candidate : candidates) {
359 EXPECT_NE( 408 EXPECT_NE(
360 ses_candidates.end(), 409 ses_candidates.end(),
361 std::find(ses_candidates.begin(), ses_candidates.end(), candidate)); 410 std::find(ses_candidates.begin(), ses_candidates.end(), candidate));
362 } 411 }
363 } 412 }
364 413
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after
497 EXPECT_EQ(1U, candidates_.size()); 546 EXPECT_EQ(1U, candidates_.size());
498 } 547 }
499 548
500 // Tests that we can get all the desired addresses successfully. 549 // Tests that we can get all the desired addresses successfully.
501 TEST_F(BasicPortAllocatorTest, TestGetAllPortsWithMinimumStepDelay) { 550 TEST_F(BasicPortAllocatorTest, TestGetAllPortsWithMinimumStepDelay) {
502 AddInterface(kClientAddr); 551 AddInterface(kClientAddr);
503 EXPECT_TRUE(CreateSession(ICE_CANDIDATE_COMPONENT_RTP)); 552 EXPECT_TRUE(CreateSession(ICE_CANDIDATE_COMPONENT_RTP));
504 session_->StartGettingPorts(); 553 session_->StartGettingPorts();
505 ASSERT_EQ_WAIT(7U, candidates_.size(), kDefaultAllocationTimeout); 554 ASSERT_EQ_WAIT(7U, candidates_.size(), kDefaultAllocationTimeout);
506 EXPECT_EQ(4U, ports_.size()); 555 EXPECT_EQ(4U, ports_.size());
507 EXPECT_PRED5(CheckCandidate, candidates_[0], ICE_CANDIDATE_COMPONENT_RTP, 556 EXPECT_PRED4(FindCandidate, candidates_, "local", "udp", kClientAddr);
508 "local", "udp", kClientAddr); 557 EXPECT_PRED4(FindCandidate, candidates_, "stun", "udp", kClientAddr);
509 EXPECT_PRED5(CheckCandidate, candidates_[1], ICE_CANDIDATE_COMPONENT_RTP, 558 EXPECT_PRED4(FindCandidate, candidates_, "relay", "udp", kRelayUdpIntAddr);
510 "stun", "udp", kClientAddr); 559 EXPECT_PRED4(FindCandidate, candidates_, "relay", "udp", kRelayUdpExtAddr);
511 EXPECT_PRED5(CheckCandidate, candidates_[2], ICE_CANDIDATE_COMPONENT_RTP, 560 EXPECT_PRED4(FindCandidate, candidates_, "relay", "tcp", kRelayTcpIntAddr);
512 "relay", "udp", kRelayUdpIntAddr); 561 EXPECT_PRED4(FindCandidate, candidates_, "local", "tcp", kClientAddr);
513 EXPECT_PRED5(CheckCandidate, candidates_[3], ICE_CANDIDATE_COMPONENT_RTP, 562 EXPECT_PRED4(FindCandidate, candidates_, "relay", "ssltcp",
514 "relay", "udp", kRelayUdpExtAddr); 563 kRelaySslTcpIntAddr);
515 EXPECT_PRED5(CheckCandidate, candidates_[4], ICE_CANDIDATE_COMPONENT_RTP,
516 "relay", "tcp", kRelayTcpIntAddr);
517 EXPECT_PRED5(CheckCandidate, candidates_[5], ICE_CANDIDATE_COMPONENT_RTP,
518 "local", "tcp", kClientAddr);
519 EXPECT_PRED5(CheckCandidate, candidates_[6], ICE_CANDIDATE_COMPONENT_RTP,
520 "relay", "ssltcp", kRelaySslTcpIntAddr);
521 EXPECT_TRUE(candidate_allocation_done_); 564 EXPECT_TRUE(candidate_allocation_done_);
522 } 565 }
523 566
524 // Test that when the same network interface is brought down and up, the 567 // Test that when the same network interface is brought down and up, the
525 // port allocator session will restart a new allocation sequence if 568 // port allocator session will restart a new allocation sequence if
526 // it is not stopped. 569 // it is not stopped.
527 TEST_F(BasicPortAllocatorTest, TestSameNetworkDownAndUpWhenSessionNotStopped) { 570 TEST_F(BasicPortAllocatorTest, TestSameNetworkDownAndUpWhenSessionNotStopped) {
528 std::string if_name("test_net0"); 571 std::string if_name("test_net0");
529 AddInterface(kClientAddr, if_name); 572 AddInterface(kClientAddr, if_name);
530 EXPECT_TRUE(CreateSession(ICE_CANDIDATE_COMPONENT_RTP)); 573 EXPECT_TRUE(CreateSession(ICE_CANDIDATE_COMPONENT_RTP));
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
579 // Verify candidates with default step delay of 1sec. 622 // Verify candidates with default step delay of 1sec.
580 TEST_F(BasicPortAllocatorTest, TestGetAllPortsWithOneSecondStepDelay) { 623 TEST_F(BasicPortAllocatorTest, TestGetAllPortsWithOneSecondStepDelay) {
581 AddInterface(kClientAddr); 624 AddInterface(kClientAddr);
582 allocator_->set_step_delay(kDefaultStepDelay); 625 allocator_->set_step_delay(kDefaultStepDelay);
583 EXPECT_TRUE(CreateSession(ICE_CANDIDATE_COMPONENT_RTP)); 626 EXPECT_TRUE(CreateSession(ICE_CANDIDATE_COMPONENT_RTP));
584 session_->StartGettingPorts(); 627 session_->StartGettingPorts();
585 ASSERT_EQ_WAIT(2U, candidates_.size(), 1000); 628 ASSERT_EQ_WAIT(2U, candidates_.size(), 1000);
586 EXPECT_EQ(2U, ports_.size()); 629 EXPECT_EQ(2U, ports_.size());
587 ASSERT_EQ_WAIT(4U, candidates_.size(), 2000); 630 ASSERT_EQ_WAIT(4U, candidates_.size(), 2000);
588 EXPECT_EQ(3U, ports_.size()); 631 EXPECT_EQ(3U, ports_.size());
589 EXPECT_PRED5(CheckCandidate, candidates_[2], ICE_CANDIDATE_COMPONENT_RTP, 632 EXPECT_PRED4(FindCandidate, candidates_, "relay", "udp", kRelayUdpIntAddr);
590 "relay", "udp", kRelayUdpIntAddr); 633 EXPECT_PRED4(FindCandidate, candidates_, "relay", "udp", kRelayUdpExtAddr);
591 EXPECT_PRED5(CheckCandidate, candidates_[3], ICE_CANDIDATE_COMPONENT_RTP,
592 "relay", "udp", kRelayUdpExtAddr);
593 ASSERT_EQ_WAIT(6U, candidates_.size(), 1500); 634 ASSERT_EQ_WAIT(6U, candidates_.size(), 1500);
594 EXPECT_PRED5(CheckCandidate, candidates_[4], ICE_CANDIDATE_COMPONENT_RTP, 635 EXPECT_PRED4(FindCandidate, candidates_, "relay", "tcp", kRelayTcpIntAddr);
595 "relay", "tcp", kRelayTcpIntAddr); 636 EXPECT_PRED4(FindCandidate, candidates_, "local", "tcp", kClientAddr);
596 EXPECT_PRED5(CheckCandidate, candidates_[5], ICE_CANDIDATE_COMPONENT_RTP,
597 "local", "tcp", kClientAddr);
598 EXPECT_EQ(4U, ports_.size()); 637 EXPECT_EQ(4U, ports_.size());
599 ASSERT_EQ_WAIT(7U, candidates_.size(), 2000); 638 ASSERT_EQ_WAIT(7U, candidates_.size(), 2000);
600 EXPECT_PRED5(CheckCandidate, candidates_[6], ICE_CANDIDATE_COMPONENT_RTP, 639 EXPECT_PRED4(FindCandidate, candidates_, "relay", "ssltcp",
601 "relay", "ssltcp", kRelaySslTcpIntAddr); 640 kRelaySslTcpIntAddr);
602 EXPECT_EQ(4U, ports_.size()); 641 EXPECT_EQ(4U, ports_.size());
603 EXPECT_TRUE(candidate_allocation_done_); 642 EXPECT_TRUE(candidate_allocation_done_);
604 // If we Stop gathering now, we shouldn't get a second "done" callback. 643 // If we Stop gathering now, we shouldn't get a second "done" callback.
605 session_->StopGettingPorts(); 644 session_->StopGettingPorts();
606 } 645 }
607 646
608 TEST_F(BasicPortAllocatorTest, TestSetupVideoRtpPortsWithNormalSendBuffers) { 647 TEST_F(BasicPortAllocatorTest, TestSetupVideoRtpPortsWithNormalSendBuffers) {
609 AddInterface(kClientAddr); 648 AddInterface(kClientAddr);
610 EXPECT_TRUE(CreateSession(ICE_CANDIDATE_COMPONENT_RTP, CN_VIDEO)); 649 EXPECT_TRUE(CreateSession(ICE_CANDIDATE_COMPONENT_RTP, CN_VIDEO));
611 session_->StartGettingPorts(); 650 session_->StartGettingPorts();
(...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after
765 ResetWithStunServerAndNat(kStunAddr); 804 ResetWithStunServerAndNat(kStunAddr);
766 EXPECT_TRUE(CreateSession(ICE_CANDIDATE_COMPONENT_RTP)); 805 EXPECT_TRUE(CreateSession(ICE_CANDIDATE_COMPONENT_RTP));
767 session_->set_flags(PORTALLOCATOR_DISABLE_DEFAULT_LOCAL_CANDIDATE); 806 session_->set_flags(PORTALLOCATOR_DISABLE_DEFAULT_LOCAL_CANDIDATE);
768 // Expect to see 2 ports: STUN and TCP ports, and single STUN candidate. 807 // Expect to see 2 ports: STUN and TCP ports, and single STUN candidate.
769 CheckDisableAdapterEnumeration(2U, rtc::IPAddress(), kNatUdpAddr.ipaddr(), 808 CheckDisableAdapterEnumeration(2U, rtc::IPAddress(), kNatUdpAddr.ipaddr(),
770 rtc::IPAddress(), rtc::IPAddress()); 809 rtc::IPAddress(), rtc::IPAddress());
771 } 810 }
772 811
773 // Test that we disable relay over UDP, and only TCP is used when connecting to 812 // Test that we disable relay over UDP, and only TCP is used when connecting to
774 // the relay server. 813 // the relay server.
775 TEST_F(BasicPortAllocatorTest, DISABLED_TestDisableUdpTurn) { 814 TEST_F(BasicPortAllocatorTest, TestDisableUdpTurn) {
776 turn_server_.AddInternalSocket(kTurnTcpIntAddr, PROTO_TCP); 815 turn_server_.AddInternalSocket(kTurnTcpIntAddr, PROTO_TCP);
777 AddInterface(kClientAddr); 816 AddInterface(kClientAddr);
778 ResetWithStunServerAndNat(kStunAddr); 817 ResetWithStunServerAndNat(kStunAddr);
779 AddTurnServers(kTurnUdpIntAddr, kTurnTcpIntAddr); 818 AddTurnServers(kTurnUdpIntAddr, kTurnTcpIntAddr);
780 EXPECT_TRUE(CreateSession(ICE_CANDIDATE_COMPONENT_RTP)); 819 EXPECT_TRUE(CreateSession(ICE_CANDIDATE_COMPONENT_RTP));
781 session_->set_flags(PORTALLOCATOR_DISABLE_UDP_RELAY | 820 session_->set_flags(PORTALLOCATOR_DISABLE_UDP_RELAY |
782 PORTALLOCATOR_DISABLE_UDP | PORTALLOCATOR_DISABLE_STUN | 821 PORTALLOCATOR_DISABLE_UDP | PORTALLOCATOR_DISABLE_STUN |
783 PORTALLOCATOR_ENABLE_SHARED_SOCKET); 822 PORTALLOCATOR_ENABLE_SHARED_SOCKET);
784 823
785 session_->StartGettingPorts(); 824 session_->StartGettingPorts();
786 EXPECT_TRUE_WAIT(candidate_allocation_done_, kDefaultAllocationTimeout); 825 EXPECT_TRUE_WAIT(candidate_allocation_done_, kDefaultAllocationTimeout);
787 826
788 // Expect to see 2 ports and 2 candidates - TURN/TCP and TCP ports, TCP and 827 // Expect to see 2 ports and 2 candidates - TURN/TCP and TCP ports, TCP and
789 // TURN/TCP candidates. 828 // TURN/TCP candidates.
790 EXPECT_EQ(2U, ports_.size()); 829 EXPECT_EQ(2U, ports_.size());
791 EXPECT_EQ(2U, candidates_.size()); 830 EXPECT_EQ(2U, candidates_.size());
792 EXPECT_PRED5(CheckCandidate, candidates_[0], ICE_CANDIDATE_COMPONENT_RTP, 831 Candidate turn_candidate;
793 "relay", "udp", kTurnUdpExtAddr); 832 EXPECT_PRED5(FindAndReturnCandidate, candidates_, "relay", "udp",
833 kTurnUdpExtAddr, &turn_candidate);
794 // The TURN candidate should use TCP to contact the TURN server. 834 // The TURN candidate should use TCP to contact the TURN server.
795 EXPECT_EQ(TCP_PROTOCOL_NAME, candidates_[0].relay_protocol()); 835 EXPECT_EQ(TCP_PROTOCOL_NAME, turn_candidate.relay_protocol());
796 EXPECT_PRED5(CheckCandidate, candidates_[1], ICE_CANDIDATE_COMPONENT_RTP, 836 EXPECT_PRED4(FindCandidate, candidates_, "local", "tcp", kClientAddr);
797 "local", "tcp", kClientAddr);
798 } 837 }
799 838
800 // Disable for asan, see 839 // Disable for asan, see
801 // https://code.google.com/p/webrtc/issues/detail?id=4743 for details. 840 // https://code.google.com/p/webrtc/issues/detail?id=4743 for details.
802 #if !defined(ADDRESS_SANITIZER) 841 #if !defined(ADDRESS_SANITIZER)
803 842
804 // Test that we can get OnCandidatesAllocationDone callback when all the ports 843 // Test that we can get OnCandidatesAllocationDone callback when all the ports
805 // are disabled. 844 // are disabled.
806 TEST_F(BasicPortAllocatorTest, TestDisableAllPorts) { 845 TEST_F(BasicPortAllocatorTest, TestDisableAllPorts) {
807 AddInterface(kClientAddr); 846 AddInterface(kClientAddr);
808 EXPECT_TRUE(CreateSession(ICE_CANDIDATE_COMPONENT_RTP)); 847 EXPECT_TRUE(CreateSession(ICE_CANDIDATE_COMPONENT_RTP));
809 session_->set_flags(PORTALLOCATOR_DISABLE_UDP | PORTALLOCATOR_DISABLE_STUN | 848 session_->set_flags(PORTALLOCATOR_DISABLE_UDP | PORTALLOCATOR_DISABLE_STUN |
810 PORTALLOCATOR_DISABLE_RELAY | PORTALLOCATOR_DISABLE_TCP); 849 PORTALLOCATOR_DISABLE_RELAY | PORTALLOCATOR_DISABLE_TCP);
811 session_->StartGettingPorts(); 850 session_->StartGettingPorts();
812 rtc::Thread::Current()->ProcessMessages(100); 851 rtc::Thread::Current()->ProcessMessages(100);
813 EXPECT_EQ(0U, candidates_.size()); 852 EXPECT_EQ(0U, candidates_.size());
814 EXPECT_TRUE(candidate_allocation_done_); 853 EXPECT_TRUE(candidate_allocation_done_);
815 } 854 }
816 855
817 // Test that we don't crash or malfunction if we can't create UDP sockets. 856 // Test that we don't crash or malfunction if we can't create UDP sockets.
818 TEST_F(BasicPortAllocatorTest, TestGetAllPortsNoUdpSockets) { 857 TEST_F(BasicPortAllocatorTest, TestGetAllPortsNoUdpSockets) {
819 AddInterface(kClientAddr); 858 AddInterface(kClientAddr);
820 fss_->set_udp_sockets_enabled(false); 859 fss_->set_udp_sockets_enabled(false);
821 EXPECT_TRUE(CreateSession(1)); 860 EXPECT_TRUE(CreateSession(1));
822 session_->StartGettingPorts(); 861 session_->StartGettingPorts();
823 ASSERT_EQ_WAIT(5U, candidates_.size(), kDefaultAllocationTimeout); 862 ASSERT_EQ_WAIT(5U, candidates_.size(), kDefaultAllocationTimeout);
824 EXPECT_EQ(2U, ports_.size()); 863 EXPECT_EQ(2U, ports_.size());
825 EXPECT_PRED5(CheckCandidate, candidates_[0], ICE_CANDIDATE_COMPONENT_RTP, 864 EXPECT_PRED4(FindCandidate, candidates_, "relay", "udp", kRelayUdpIntAddr);
826 "relay", "udp", kRelayUdpIntAddr); 865 EXPECT_PRED4(FindCandidate, candidates_, "relay", "udp", kRelayUdpExtAddr);
827 EXPECT_PRED5(CheckCandidate, candidates_[1], ICE_CANDIDATE_COMPONENT_RTP, 866 EXPECT_PRED4(FindCandidate, candidates_, "relay", "tcp", kRelayTcpIntAddr);
828 "relay", "udp", kRelayUdpExtAddr); 867 EXPECT_PRED4(FindCandidate, candidates_, "local", "tcp", kClientAddr);
829 EXPECT_PRED5(CheckCandidate, candidates_[2], ICE_CANDIDATE_COMPONENT_RTP, 868 EXPECT_PRED4(FindCandidate, candidates_, "relay", "ssltcp",
830 "relay", "tcp", kRelayTcpIntAddr); 869 kRelaySslTcpIntAddr);
831 EXPECT_PRED5(CheckCandidate, candidates_[3], ICE_CANDIDATE_COMPONENT_RTP,
832 "local", "tcp", kClientAddr);
833 EXPECT_PRED5(CheckCandidate, candidates_[4], ICE_CANDIDATE_COMPONENT_RTP,
834 "relay", "ssltcp", kRelaySslTcpIntAddr);
835 EXPECT_TRUE(candidate_allocation_done_); 870 EXPECT_TRUE(candidate_allocation_done_);
836 } 871 }
837 872
838 #endif // if !defined(ADDRESS_SANITIZER) 873 #endif // if !defined(ADDRESS_SANITIZER)
839 874
840 // Test that we don't crash or malfunction if we can't create UDP sockets or 875 // Test that we don't crash or malfunction if we can't create UDP sockets or
841 // listen on TCP sockets. We still give out a local TCP address, since 876 // listen on TCP sockets. We still give out a local TCP address, since
842 // apparently this is needed for the remote side to accept our connection. 877 // apparently this is needed for the remote side to accept our connection.
843 TEST_F(BasicPortAllocatorTest, TestGetAllPortsNoUdpSocketsNoTcpListen) { 878 TEST_F(BasicPortAllocatorTest, TestGetAllPortsNoUdpSocketsNoTcpListen) {
844 AddInterface(kClientAddr); 879 AddInterface(kClientAddr);
845 fss_->set_udp_sockets_enabled(false); 880 fss_->set_udp_sockets_enabled(false);
846 fss_->set_tcp_listen_enabled(false); 881 fss_->set_tcp_listen_enabled(false);
847 EXPECT_TRUE(CreateSession(1)); 882 EXPECT_TRUE(CreateSession(1));
848 session_->StartGettingPorts(); 883 session_->StartGettingPorts();
849 ASSERT_EQ_WAIT(5U, candidates_.size(), kDefaultAllocationTimeout); 884 ASSERT_EQ_WAIT(5U, candidates_.size(), kDefaultAllocationTimeout);
850 EXPECT_EQ(2U, ports_.size()); 885 EXPECT_EQ(2U, ports_.size());
851 EXPECT_PRED5(CheckCandidate, candidates_[0], 1, "relay", "udp", 886 EXPECT_PRED4(FindCandidate, candidates_, "relay", "udp", kRelayUdpIntAddr);
852 kRelayUdpIntAddr); 887 EXPECT_PRED4(FindCandidate, candidates_, "relay", "udp", kRelayUdpExtAddr);
853 EXPECT_PRED5(CheckCandidate, candidates_[1], 1, "relay", "udp", 888 EXPECT_PRED4(FindCandidate, candidates_, "relay", "tcp", kRelayTcpIntAddr);
854 kRelayUdpExtAddr); 889 EXPECT_PRED4(FindCandidate, candidates_, "local", "tcp", kClientAddr);
855 EXPECT_PRED5(CheckCandidate, candidates_[2], 1, "relay", "tcp", 890 EXPECT_PRED4(FindCandidate, candidates_, "relay", "ssltcp",
856 kRelayTcpIntAddr);
857 EXPECT_PRED5(CheckCandidate, candidates_[3], 1, "local", "tcp", kClientAddr);
858 EXPECT_PRED5(CheckCandidate, candidates_[4], 1, "relay", "ssltcp",
859 kRelaySslTcpIntAddr); 891 kRelaySslTcpIntAddr);
860 EXPECT_TRUE(candidate_allocation_done_); 892 EXPECT_TRUE(candidate_allocation_done_);
861 } 893 }
862 894
863 // Test that we don't crash or malfunction if we can't create any sockets. 895 // Test that we don't crash or malfunction if we can't create any sockets.
864 // TODO(deadbeef): Find a way to exit early here. 896 // TODO(deadbeef): Find a way to exit early here.
865 TEST_F(BasicPortAllocatorTest, TestGetAllPortsNoSockets) { 897 TEST_F(BasicPortAllocatorTest, TestGetAllPortsNoSockets) {
866 AddInterface(kClientAddr); 898 AddInterface(kClientAddr);
867 fss_->set_tcp_sockets_enabled(false); 899 fss_->set_tcp_sockets_enabled(false);
868 fss_->set_udp_sockets_enabled(false); 900 fss_->set_udp_sockets_enabled(false);
869 EXPECT_TRUE(CreateSession(ICE_CANDIDATE_COMPONENT_RTP)); 901 EXPECT_TRUE(CreateSession(ICE_CANDIDATE_COMPONENT_RTP));
870 session_->StartGettingPorts(); 902 session_->StartGettingPorts();
871 WAIT(candidates_.size() > 0, 2000); 903 WAIT(candidates_.size() > 0, 2000);
872 // TODO(deadbeef): Check candidate_allocation_done signal. 904 // TODO(deadbeef): Check candidate_allocation_done signal.
873 // In case of Relay, ports creation will succeed but sockets will fail. 905 // In case of Relay, ports creation will succeed but sockets will fail.
874 // There is no error reporting from RelayEntry to handle this failure. 906 // There is no error reporting from RelayEntry to handle this failure.
875 } 907 }
876 908
877 // Testing STUN timeout. 909 // Testing STUN timeout.
878 TEST_F(BasicPortAllocatorTest, TestGetAllPortsNoUdpAllowed) { 910 TEST_F(BasicPortAllocatorTest, TestGetAllPortsNoUdpAllowed) {
879 fss_->AddRule(false, rtc::FP_UDP, rtc::FD_ANY, kClientAddr); 911 fss_->AddRule(false, rtc::FP_UDP, rtc::FD_ANY, kClientAddr);
880 AddInterface(kClientAddr); 912 AddInterface(kClientAddr);
881 EXPECT_TRUE(CreateSession(ICE_CANDIDATE_COMPONENT_RTP)); 913 EXPECT_TRUE(CreateSession(ICE_CANDIDATE_COMPONENT_RTP));
882 session_->StartGettingPorts(); 914 session_->StartGettingPorts();
883 EXPECT_EQ_WAIT(2U, candidates_.size(), kDefaultAllocationTimeout); 915 EXPECT_EQ_WAIT(2U, candidates_.size(), kDefaultAllocationTimeout);
884 EXPECT_EQ(2U, ports_.size()); 916 EXPECT_EQ(2U, ports_.size());
885 EXPECT_PRED5(CheckCandidate, candidates_[0], ICE_CANDIDATE_COMPONENT_RTP, 917 EXPECT_PRED4(FindCandidate, candidates_, "local", "udp", kClientAddr);
886 "local", "udp", kClientAddr); 918 EXPECT_PRED4(FindCandidate, candidates_, "local", "tcp", kClientAddr);
887 EXPECT_PRED5(CheckCandidate, candidates_[1], ICE_CANDIDATE_COMPONENT_RTP,
888 "local", "tcp", kClientAddr);
889 // RelayPort connection timeout is 3sec. TCP connection with RelayServer 919 // RelayPort connection timeout is 3sec. TCP connection with RelayServer
890 // will be tried after 3 seconds. 920 // will be tried after 3 seconds.
891 EXPECT_EQ_WAIT(6U, candidates_.size(), 4000); 921 EXPECT_EQ_WAIT(6U, candidates_.size(), 4000);
892 EXPECT_EQ(3U, ports_.size()); 922 EXPECT_EQ(3U, ports_.size());
893 EXPECT_PRED5(CheckCandidate, candidates_[2], ICE_CANDIDATE_COMPONENT_RTP, 923 EXPECT_PRED4(FindCandidate, candidates_, "relay", "udp", kRelayUdpIntAddr);
894 "relay", "udp", kRelayUdpIntAddr); 924 EXPECT_PRED4(FindCandidate, candidates_, "relay", "tcp", kRelayTcpIntAddr);
895 EXPECT_PRED5(CheckCandidate, candidates_[3], ICE_CANDIDATE_COMPONENT_RTP, 925 EXPECT_PRED4(FindCandidate, candidates_, "relay", "ssltcp",
896 "relay", "tcp", kRelayTcpIntAddr); 926 kRelaySslTcpIntAddr);
897 EXPECT_PRED5(CheckCandidate, candidates_[4], ICE_CANDIDATE_COMPONENT_RTP, 927 EXPECT_PRED4(FindCandidate, candidates_, "relay", "udp", kRelayUdpExtAddr);
898 "relay", "ssltcp", kRelaySslTcpIntAddr);
899 EXPECT_PRED5(CheckCandidate, candidates_[5], ICE_CANDIDATE_COMPONENT_RTP,
900 "relay", "udp", kRelayUdpExtAddr);
901 // Stun Timeout is 9sec. 928 // Stun Timeout is 9sec.
902 EXPECT_TRUE_WAIT(candidate_allocation_done_, 9000); 929 EXPECT_TRUE_WAIT(candidate_allocation_done_, 9000);
903 } 930 }
904 931
905 TEST_F(BasicPortAllocatorTest, TestCandidatePriorityOfMultipleInterfaces) { 932 TEST_F(BasicPortAllocatorTest, TestCandidatePriorityOfMultipleInterfaces) {
906 AddInterface(kClientAddr); 933 AddInterface(kClientAddr);
907 AddInterface(kClientAddr2); 934 AddInterface(kClientAddr2);
908 // Allocating only host UDP ports. This is done purely for testing 935 // Allocating only host UDP ports. This is done purely for testing
909 // convenience. 936 // convenience.
910 allocator().set_flags(PORTALLOCATOR_DISABLE_TCP | PORTALLOCATOR_DISABLE_STUN | 937 allocator().set_flags(PORTALLOCATOR_DISABLE_TCP | PORTALLOCATOR_DISABLE_STUN |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
952 // address with the correct family. This is to prevent any local 979 // address with the correct family. This is to prevent any local
953 // reflective address leakage in the sdp line. 980 // reflective address leakage in the sdp line.
954 TEST_F(BasicPortAllocatorTest, TestCandidateFilterWithRelayOnly) { 981 TEST_F(BasicPortAllocatorTest, TestCandidateFilterWithRelayOnly) {
955 AddInterface(kClientAddr); 982 AddInterface(kClientAddr);
956 // GTURN is not configured here. 983 // GTURN is not configured here.
957 ResetWithTurnServersNoNat(kTurnUdpIntAddr, rtc::SocketAddress()); 984 ResetWithTurnServersNoNat(kTurnUdpIntAddr, rtc::SocketAddress());
958 allocator().set_candidate_filter(CF_RELAY); 985 allocator().set_candidate_filter(CF_RELAY);
959 EXPECT_TRUE(CreateSession(ICE_CANDIDATE_COMPONENT_RTP)); 986 EXPECT_TRUE(CreateSession(ICE_CANDIDATE_COMPONENT_RTP));
960 session_->StartGettingPorts(); 987 session_->StartGettingPorts();
961 EXPECT_TRUE_WAIT(candidate_allocation_done_, kDefaultAllocationTimeout); 988 EXPECT_TRUE_WAIT(candidate_allocation_done_, kDefaultAllocationTimeout);
962 EXPECT_PRED5(CheckCandidate, candidates_[0], ICE_CANDIDATE_COMPONENT_RTP, 989 EXPECT_PRED4(FindCandidate, candidates_, "relay", "udp",
963 "relay", "udp", rtc::SocketAddress(kTurnUdpExtAddr.ipaddr(), 0)); 990 rtc::SocketAddress(kTurnUdpExtAddr.ipaddr(), 0));
964 991
965 EXPECT_EQ(1U, candidates_.size()); 992 EXPECT_EQ(1U, candidates_.size());
966 EXPECT_EQ(1U, ports_.size()); // Only Relay port will be in ready state. 993 EXPECT_EQ(1U, ports_.size()); // Only Relay port will be in ready state.
967 for (size_t i = 0; i < candidates_.size(); ++i) { 994 EXPECT_EQ(std::string(RELAY_PORT_TYPE), candidates_[0].type());
968 EXPECT_EQ(std::string(RELAY_PORT_TYPE), candidates_[i].type()); 995 EXPECT_EQ(
969 EXPECT_EQ( 996 candidates_[0].related_address(),
970 candidates_[0].related_address(), 997 rtc::EmptySocketAddressWithFamily(candidates_[0].address().family()));
971 rtc::EmptySocketAddressWithFamily(candidates_[0].address().family()));
972 }
973 } 998 }
974 999
975 TEST_F(BasicPortAllocatorTest, TestCandidateFilterWithHostOnly) { 1000 TEST_F(BasicPortAllocatorTest, TestCandidateFilterWithHostOnly) {
976 AddInterface(kClientAddr); 1001 AddInterface(kClientAddr);
977 allocator().set_flags(PORTALLOCATOR_ENABLE_SHARED_SOCKET); 1002 allocator().set_flags(PORTALLOCATOR_ENABLE_SHARED_SOCKET);
978 allocator().set_candidate_filter(CF_HOST); 1003 allocator().set_candidate_filter(CF_HOST);
979 EXPECT_TRUE(CreateSession(ICE_CANDIDATE_COMPONENT_RTP)); 1004 EXPECT_TRUE(CreateSession(ICE_CANDIDATE_COMPONENT_RTP));
980 session_->StartGettingPorts(); 1005 session_->StartGettingPorts();
981 EXPECT_TRUE_WAIT(candidate_allocation_done_, kDefaultAllocationTimeout); 1006 EXPECT_TRUE_WAIT(candidate_allocation_done_, kDefaultAllocationTimeout);
982 EXPECT_EQ(2U, candidates_.size()); // Host UDP/TCP candidates only. 1007 EXPECT_EQ(2U, candidates_.size()); // Host UDP/TCP candidates only.
983 EXPECT_EQ(2U, ports_.size()); // UDP/TCP ports only. 1008 EXPECT_EQ(2U, ports_.size()); // UDP/TCP ports only.
984 for (size_t i = 0; i < candidates_.size(); ++i) { 1009 for (const Candidate& candidate : candidates_) {
985 EXPECT_EQ(std::string(LOCAL_PORT_TYPE), candidates_[i].type()); 1010 EXPECT_EQ(std::string(LOCAL_PORT_TYPE), candidate.type());
986 } 1011 }
987 } 1012 }
988 1013
989 // Host is behind the NAT. 1014 // Host is behind the NAT.
990 TEST_F(BasicPortAllocatorTest, TestCandidateFilterWithReflexiveOnly) { 1015 TEST_F(BasicPortAllocatorTest, TestCandidateFilterWithReflexiveOnly) {
991 AddInterface(kPrivateAddr); 1016 AddInterface(kPrivateAddr);
992 ResetWithStunServerAndNat(kStunAddr); 1017 ResetWithStunServerAndNat(kStunAddr);
993 1018
994 allocator().set_flags(PORTALLOCATOR_ENABLE_SHARED_SOCKET); 1019 allocator().set_flags(PORTALLOCATOR_ENABLE_SHARED_SOCKET);
995 allocator().set_candidate_filter(CF_REFLEXIVE); 1020 allocator().set_candidate_filter(CF_REFLEXIVE);
996 EXPECT_TRUE(CreateSession(ICE_CANDIDATE_COMPONENT_RTP)); 1021 EXPECT_TRUE(CreateSession(ICE_CANDIDATE_COMPONENT_RTP));
997 session_->StartGettingPorts(); 1022 session_->StartGettingPorts();
998 EXPECT_TRUE_WAIT(candidate_allocation_done_, kDefaultAllocationTimeout); 1023 EXPECT_TRUE_WAIT(candidate_allocation_done_, kDefaultAllocationTimeout);
999 // Host is behind NAT, no private address will be exposed. Hence only UDP 1024 // Host is behind NAT, no private address will be exposed. Hence only UDP
1000 // port with STUN candidate will be sent outside. 1025 // port with STUN candidate will be sent outside.
1001 EXPECT_EQ(1U, candidates_.size()); // Only STUN candidate. 1026 EXPECT_EQ(1U, candidates_.size()); // Only STUN candidate.
1002 EXPECT_EQ(1U, ports_.size()); // Only UDP port will be in ready state. 1027 EXPECT_EQ(1U, ports_.size()); // Only UDP port will be in ready state.
1003 for (size_t i = 0; i < candidates_.size(); ++i) { 1028 EXPECT_EQ(std::string(STUN_PORT_TYPE), candidates_[0].type());
1004 EXPECT_EQ(std::string(STUN_PORT_TYPE), candidates_[i].type()); 1029 EXPECT_EQ(
1005 EXPECT_EQ( 1030 candidates_[0].related_address(),
1006 candidates_[0].related_address(), 1031 rtc::EmptySocketAddressWithFamily(candidates_[0].address().family()));
1007 rtc::EmptySocketAddressWithFamily(candidates_[0].address().family()));
1008 }
1009 } 1032 }
1010 1033
1011 // Host is not behind the NAT. 1034 // Host is not behind the NAT.
1012 TEST_F(BasicPortAllocatorTest, TestCandidateFilterWithReflexiveOnlyAndNoNAT) { 1035 TEST_F(BasicPortAllocatorTest, TestCandidateFilterWithReflexiveOnlyAndNoNAT) {
1013 AddInterface(kClientAddr); 1036 AddInterface(kClientAddr);
1014 allocator().set_flags(PORTALLOCATOR_ENABLE_SHARED_SOCKET); 1037 allocator().set_flags(PORTALLOCATOR_ENABLE_SHARED_SOCKET);
1015 allocator().set_candidate_filter(CF_REFLEXIVE); 1038 allocator().set_candidate_filter(CF_REFLEXIVE);
1016 EXPECT_TRUE(CreateSession(ICE_CANDIDATE_COMPONENT_RTP)); 1039 EXPECT_TRUE(CreateSession(ICE_CANDIDATE_COMPONENT_RTP));
1017 session_->StartGettingPorts(); 1040 session_->StartGettingPorts();
1018 EXPECT_TRUE_WAIT(candidate_allocation_done_, kDefaultAllocationTimeout); 1041 EXPECT_TRUE_WAIT(candidate_allocation_done_, kDefaultAllocationTimeout);
1019 // Host has a public address, both UDP and TCP candidates will be exposed. 1042 // Host has a public address, both UDP and TCP candidates will be exposed.
1020 EXPECT_EQ(2U, candidates_.size()); // Local UDP + TCP candidate. 1043 EXPECT_EQ(2U, candidates_.size()); // Local UDP + TCP candidate.
1021 EXPECT_EQ(2U, ports_.size()); // UDP and TCP ports will be in ready state. 1044 EXPECT_EQ(2U, ports_.size()); // UDP and TCP ports will be in ready state.
1022 for (size_t i = 0; i < candidates_.size(); ++i) { 1045 for (const Candidate& candidate : candidates_) {
1023 EXPECT_EQ(std::string(LOCAL_PORT_TYPE), candidates_[i].type()); 1046 EXPECT_EQ(std::string(LOCAL_PORT_TYPE), candidate.type());
1024 } 1047 }
1025 } 1048 }
1026 1049
1027 // Test that we get the same ufrag and pwd for all candidates. 1050 // Test that we get the same ufrag and pwd for all candidates.
1028 TEST_F(BasicPortAllocatorTest, TestEnableSharedUfrag) { 1051 TEST_F(BasicPortAllocatorTest, TestEnableSharedUfrag) {
1029 AddInterface(kClientAddr); 1052 AddInterface(kClientAddr);
1030 EXPECT_TRUE(CreateSession(ICE_CANDIDATE_COMPONENT_RTP)); 1053 EXPECT_TRUE(CreateSession(ICE_CANDIDATE_COMPONENT_RTP));
1031 session_->StartGettingPorts(); 1054 session_->StartGettingPorts();
1032 ASSERT_EQ_WAIT(7U, candidates_.size(), kDefaultAllocationTimeout); 1055 ASSERT_EQ_WAIT(7U, candidates_.size(), kDefaultAllocationTimeout);
1033 EXPECT_PRED5(CheckCandidate, candidates_[0], ICE_CANDIDATE_COMPONENT_RTP, 1056 EXPECT_PRED4(FindCandidate, candidates_, "local", "udp", kClientAddr);
1034 "local", "udp", kClientAddr); 1057 EXPECT_PRED4(FindCandidate, candidates_, "stun", "udp", kClientAddr);
1035 EXPECT_PRED5(CheckCandidate, candidates_[1], ICE_CANDIDATE_COMPONENT_RTP, 1058 EXPECT_PRED4(FindCandidate, candidates_, "local", "tcp", kClientAddr);
1036 "stun", "udp", kClientAddr);
1037 EXPECT_PRED5(CheckCandidate, candidates_[5], ICE_CANDIDATE_COMPONENT_RTP,
1038 "local", "tcp", kClientAddr);
1039 EXPECT_EQ(4U, ports_.size()); 1059 EXPECT_EQ(4U, ports_.size());
1040 EXPECT_EQ(kIceUfrag0, candidates_[0].username()); 1060 for (const Candidate& candidate : candidates_) {
1041 EXPECT_EQ(kIceUfrag0, candidates_[1].username()); 1061 EXPECT_EQ(kIceUfrag0, candidate.username());
1042 EXPECT_EQ(kIceUfrag0, candidates_[2].username()); 1062 EXPECT_EQ(kIcePwd0, candidate.password());
1043 EXPECT_EQ(kIcePwd0, candidates_[0].password()); 1063 }
1044 EXPECT_EQ(kIcePwd0, candidates_[1].password());
1045 EXPECT_TRUE(candidate_allocation_done_); 1064 EXPECT_TRUE(candidate_allocation_done_);
1046 } 1065 }
1047 1066
1048 // Test that when PORTALLOCATOR_ENABLE_SHARED_SOCKET is enabled only one port 1067 // Test that when PORTALLOCATOR_ENABLE_SHARED_SOCKET is enabled only one port
1049 // is allocated for udp and stun. Also verify there is only one candidate 1068 // is allocated for udp and stun. Also verify there is only one candidate
1050 // (local) if stun candidate is same as local candidate, which will be the case 1069 // (local) if stun candidate is same as local candidate, which will be the case
1051 // in a public network like the below test. 1070 // in a public network like the below test.
1052 TEST_F(BasicPortAllocatorTest, TestSharedSocketWithoutNat) { 1071 TEST_F(BasicPortAllocatorTest, TestSharedSocketWithoutNat) {
1053 AddInterface(kClientAddr); 1072 AddInterface(kClientAddr);
1054 allocator_->set_flags(allocator().flags() | 1073 allocator_->set_flags(allocator().flags() |
1055 PORTALLOCATOR_ENABLE_SHARED_SOCKET); 1074 PORTALLOCATOR_ENABLE_SHARED_SOCKET);
1056 EXPECT_TRUE(CreateSession(ICE_CANDIDATE_COMPONENT_RTP)); 1075 EXPECT_TRUE(CreateSession(ICE_CANDIDATE_COMPONENT_RTP));
1057 session_->StartGettingPorts(); 1076 session_->StartGettingPorts();
1058 ASSERT_EQ_WAIT(6U, candidates_.size(), kDefaultAllocationTimeout); 1077 ASSERT_EQ_WAIT(6U, candidates_.size(), kDefaultAllocationTimeout);
1059 EXPECT_EQ(3U, ports_.size()); 1078 EXPECT_EQ(3U, ports_.size());
1060 EXPECT_PRED5(CheckCandidate, candidates_[0], ICE_CANDIDATE_COMPONENT_RTP, 1079 EXPECT_PRED4(FindCandidate, candidates_, "local", "udp", kClientAddr);
1061 "local", "udp", kClientAddr);
1062 EXPECT_TRUE_WAIT(candidate_allocation_done_, kDefaultAllocationTimeout); 1080 EXPECT_TRUE_WAIT(candidate_allocation_done_, kDefaultAllocationTimeout);
1063 } 1081 }
1064 1082
1065 // Test that when PORTALLOCATOR_ENABLE_SHARED_SOCKET is enabled only one port 1083 // Test that when PORTALLOCATOR_ENABLE_SHARED_SOCKET is enabled only one port
1066 // is allocated for udp and stun. In this test we should expect both stun and 1084 // is allocated for udp and stun. In this test we should expect both stun and
1067 // local candidates as client behind a nat. 1085 // local candidates as client behind a nat.
1068 TEST_F(BasicPortAllocatorTest, TestSharedSocketWithNat) { 1086 TEST_F(BasicPortAllocatorTest, TestSharedSocketWithNat) {
1069 AddInterface(kClientAddr); 1087 AddInterface(kClientAddr);
1070 ResetWithStunServerAndNat(kStunAddr); 1088 ResetWithStunServerAndNat(kStunAddr);
1071 1089
1072 allocator_->set_flags(allocator().flags() | 1090 allocator_->set_flags(allocator().flags() |
1073 PORTALLOCATOR_ENABLE_SHARED_SOCKET); 1091 PORTALLOCATOR_ENABLE_SHARED_SOCKET);
1074 EXPECT_TRUE(CreateSession(ICE_CANDIDATE_COMPONENT_RTP)); 1092 EXPECT_TRUE(CreateSession(ICE_CANDIDATE_COMPONENT_RTP));
1075 session_->StartGettingPorts(); 1093 session_->StartGettingPorts();
1076 ASSERT_EQ_WAIT(3U, candidates_.size(), kDefaultAllocationTimeout); 1094 ASSERT_EQ_WAIT(3U, candidates_.size(), kDefaultAllocationTimeout);
1077 ASSERT_EQ(2U, ports_.size()); 1095 ASSERT_EQ(2U, ports_.size());
1078 EXPECT_PRED5(CheckCandidate, candidates_[0], ICE_CANDIDATE_COMPONENT_RTP, 1096 EXPECT_PRED4(FindCandidate, candidates_, "local", "udp", kClientAddr);
1079 "local", "udp", kClientAddr); 1097 EXPECT_PRED4(FindCandidate, candidates_, "stun", "udp",
1080 EXPECT_PRED5(CheckCandidate, candidates_[1], ICE_CANDIDATE_COMPONENT_RTP, 1098 rtc::SocketAddress(kNatUdpAddr.ipaddr(), 0));
1081 "stun", "udp", rtc::SocketAddress(kNatUdpAddr.ipaddr(), 0));
1082 EXPECT_TRUE_WAIT(candidate_allocation_done_, kDefaultAllocationTimeout); 1099 EXPECT_TRUE_WAIT(candidate_allocation_done_, kDefaultAllocationTimeout);
1083 EXPECT_EQ(3U, candidates_.size()); 1100 EXPECT_EQ(3U, candidates_.size());
1084 } 1101 }
1085 1102
1086 // Test TURN port in shared socket mode with UDP and TCP TURN server addresses. 1103 // Test TURN port in shared socket mode with UDP and TCP TURN server addresses.
1087 TEST_F(BasicPortAllocatorTest, TestSharedSocketWithoutNatUsingTurn) { 1104 TEST_F(BasicPortAllocatorTest, TestSharedSocketWithoutNatUsingTurn) {
1088 turn_server_.AddInternalSocket(kTurnTcpIntAddr, PROTO_TCP); 1105 turn_server_.AddInternalSocket(kTurnTcpIntAddr, PROTO_TCP);
1089 AddInterface(kClientAddr); 1106 AddInterface(kClientAddr);
1090 allocator_.reset(new BasicPortAllocator(&network_manager_)); 1107 allocator_.reset(new BasicPortAllocator(&network_manager_));
1091 1108
1092 AddTurnServers(kTurnUdpIntAddr, kTurnTcpIntAddr); 1109 AddTurnServers(kTurnUdpIntAddr, kTurnTcpIntAddr);
1093 1110
1094 allocator_->set_step_delay(kMinimumStepDelay); 1111 allocator_->set_step_delay(kMinimumStepDelay);
1095 allocator_->set_flags(allocator().flags() | 1112 allocator_->set_flags(allocator().flags() |
1096 PORTALLOCATOR_ENABLE_SHARED_SOCKET | 1113 PORTALLOCATOR_ENABLE_SHARED_SOCKET |
1097 PORTALLOCATOR_DISABLE_TCP); 1114 PORTALLOCATOR_DISABLE_TCP);
1098 1115
1099 EXPECT_TRUE(CreateSession(ICE_CANDIDATE_COMPONENT_RTP)); 1116 EXPECT_TRUE(CreateSession(ICE_CANDIDATE_COMPONENT_RTP));
1100 session_->StartGettingPorts(); 1117 session_->StartGettingPorts();
1101 1118
1102 ASSERT_EQ_WAIT(3U, candidates_.size(), kDefaultAllocationTimeout); 1119 ASSERT_EQ_WAIT(3U, candidates_.size(), kDefaultAllocationTimeout);
1103 ASSERT_EQ(3U, ports_.size()); 1120 ASSERT_EQ(3U, ports_.size());
1104 EXPECT_PRED5(CheckCandidate, candidates_[0], ICE_CANDIDATE_COMPONENT_RTP, 1121 EXPECT_PRED4(FindCandidate, candidates_, "local", "udp", kClientAddr);
1105 "local", "udp", kClientAddr); 1122 EXPECT_PRED4(FindCandidate, candidates_, "relay", "udp",
1106 EXPECT_PRED5(CheckCandidate, candidates_[1], ICE_CANDIDATE_COMPONENT_RTP, 1123 rtc::SocketAddress(kTurnUdpExtAddr.ipaddr(), 0));
1107 "relay", "udp", rtc::SocketAddress(kTurnUdpExtAddr.ipaddr(), 0)); 1124 EXPECT_PRED4(FindCandidate, candidates_, "relay", "udp",
1108 EXPECT_PRED5(CheckCandidate, candidates_[2], ICE_CANDIDATE_COMPONENT_RTP, 1125 rtc::SocketAddress(kTurnUdpExtAddr.ipaddr(), 0));
1109 "relay", "udp", rtc::SocketAddress(kTurnUdpExtAddr.ipaddr(), 0));
1110 EXPECT_TRUE_WAIT(candidate_allocation_done_, kDefaultAllocationTimeout); 1126 EXPECT_TRUE_WAIT(candidate_allocation_done_, kDefaultAllocationTimeout);
1111 EXPECT_EQ(3U, candidates_.size()); 1127 EXPECT_EQ(3U, candidates_.size());
1112 } 1128 }
1113 1129
1114 // Testing DNS resolve for the TURN server, this will test AllocationSequence 1130 // Testing DNS resolve for the TURN server, this will test AllocationSequence
1115 // handling the unresolved address signal from TurnPort. 1131 // handling the unresolved address signal from TurnPort.
1116 TEST_F(BasicPortAllocatorTest, TestSharedSocketWithServerAddressResolve) { 1132 TEST_F(BasicPortAllocatorTest, TestSharedSocketWithServerAddressResolve) {
1117 turn_server_.AddInternalSocket(rtc::SocketAddress("127.0.0.1", 3478), 1133 turn_server_.AddInternalSocket(rtc::SocketAddress("127.0.0.1", 3478),
1118 PROTO_UDP); 1134 PROTO_UDP);
1119 AddInterface(kClientAddr); 1135 AddInterface(kClientAddr);
(...skipping 27 matching lines...) Expand all
1147 1163
1148 allocator_->set_flags(allocator().flags() | 1164 allocator_->set_flags(allocator().flags() |
1149 PORTALLOCATOR_ENABLE_SHARED_SOCKET | 1165 PORTALLOCATOR_ENABLE_SHARED_SOCKET |
1150 PORTALLOCATOR_DISABLE_TCP); 1166 PORTALLOCATOR_DISABLE_TCP);
1151 1167
1152 EXPECT_TRUE(CreateSession(ICE_CANDIDATE_COMPONENT_RTP)); 1168 EXPECT_TRUE(CreateSession(ICE_CANDIDATE_COMPONENT_RTP));
1153 session_->StartGettingPorts(); 1169 session_->StartGettingPorts();
1154 1170
1155 ASSERT_EQ_WAIT(3U, candidates_.size(), kDefaultAllocationTimeout); 1171 ASSERT_EQ_WAIT(3U, candidates_.size(), kDefaultAllocationTimeout);
1156 ASSERT_EQ(2U, ports_.size()); 1172 ASSERT_EQ(2U, ports_.size());
1157 EXPECT_PRED5(CheckCandidate, candidates_[0], ICE_CANDIDATE_COMPONENT_RTP, 1173 EXPECT_PRED4(FindCandidate, candidates_, "local", "udp", kClientAddr);
1158 "local", "udp", kClientAddr); 1174 EXPECT_PRED4(FindCandidate, candidates_, "stun", "udp",
1159 EXPECT_PRED5(CheckCandidate, candidates_[1], ICE_CANDIDATE_COMPONENT_RTP, 1175 rtc::SocketAddress(kNatUdpAddr.ipaddr(), 0));
1160 "stun", "udp", rtc::SocketAddress(kNatUdpAddr.ipaddr(), 0)); 1176 EXPECT_PRED4(FindCandidate, candidates_, "relay", "udp",
1161 EXPECT_PRED5(CheckCandidate, candidates_[2], ICE_CANDIDATE_COMPONENT_RTP, 1177 rtc::SocketAddress(kTurnUdpExtAddr.ipaddr(), 0));
1162 "relay", "udp", rtc::SocketAddress(kTurnUdpExtAddr.ipaddr(), 0));
1163 EXPECT_TRUE_WAIT(candidate_allocation_done_, kDefaultAllocationTimeout); 1178 EXPECT_TRUE_WAIT(candidate_allocation_done_, kDefaultAllocationTimeout);
1164 EXPECT_EQ(3U, candidates_.size()); 1179 EXPECT_EQ(3U, candidates_.size());
1165 // Local port will be created first and then TURN port. 1180 // Local port will be created first and then TURN port.
1166 EXPECT_EQ(2U, ports_[0]->Candidates().size()); 1181 EXPECT_EQ(2U, ports_[0]->Candidates().size());
1167 EXPECT_EQ(1U, ports_[1]->Candidates().size()); 1182 EXPECT_EQ(1U, ports_[1]->Candidates().size());
1168 } 1183 }
1169 1184
1170 // Test that when PORTALLOCATOR_ENABLE_SHARED_SOCKET is enabled and the TURN 1185 // Test that when PORTALLOCATOR_ENABLE_SHARED_SOCKET is enabled and the TURN
1171 // server is also used as the STUN server, we should get 'local', 'stun', and 1186 // server is also used as the STUN server, we should get 'local', 'stun', and
1172 // 'relay' candidates. 1187 // 'relay' candidates.
1173 TEST_F(BasicPortAllocatorTest, TestSharedSocketWithNatUsingTurnAsStun) { 1188 TEST_F(BasicPortAllocatorTest, TestSharedSocketWithNatUsingTurnAsStun) {
1174 AddInterface(kClientAddr); 1189 AddInterface(kClientAddr);
1175 // Use an empty SocketAddress to add a NAT without STUN server. 1190 // Use an empty SocketAddress to add a NAT without STUN server.
1176 ResetWithStunServerAndNat(SocketAddress()); 1191 ResetWithStunServerAndNat(SocketAddress());
1177 AddTurnServers(kTurnUdpIntAddr, rtc::SocketAddress()); 1192 AddTurnServers(kTurnUdpIntAddr, rtc::SocketAddress());
1178 1193
1179 // Must set the step delay to 0 to make sure the relay allocation phase is 1194 // Must set the step delay to 0 to make sure the relay allocation phase is
1180 // started before the STUN candidates are obtained, so that the STUN binding 1195 // started before the STUN candidates are obtained, so that the STUN binding
1181 // response is processed when both StunPort and TurnPort exist to reproduce 1196 // response is processed when both StunPort and TurnPort exist to reproduce
1182 // webrtc issue 3537. 1197 // webrtc issue 3537.
1183 allocator_->set_step_delay(0); 1198 allocator_->set_step_delay(0);
1184 allocator_->set_flags(allocator().flags() | 1199 allocator_->set_flags(allocator().flags() |
1185 PORTALLOCATOR_ENABLE_SHARED_SOCKET | 1200 PORTALLOCATOR_ENABLE_SHARED_SOCKET |
1186 PORTALLOCATOR_DISABLE_TCP); 1201 PORTALLOCATOR_DISABLE_TCP);
1187 1202
1188 EXPECT_TRUE(CreateSession(ICE_CANDIDATE_COMPONENT_RTP)); 1203 EXPECT_TRUE(CreateSession(ICE_CANDIDATE_COMPONENT_RTP));
1189 session_->StartGettingPorts(); 1204 session_->StartGettingPorts();
1190 1205
1191 ASSERT_EQ_WAIT(3U, candidates_.size(), kDefaultAllocationTimeout); 1206 ASSERT_EQ_WAIT(3U, candidates_.size(), kDefaultAllocationTimeout);
1192 EXPECT_PRED5(CheckCandidate, candidates_[0], ICE_CANDIDATE_COMPONENT_RTP, 1207 EXPECT_PRED4(FindCandidate, candidates_, "local", "udp", kClientAddr);
1193 "local", "udp", kClientAddr); 1208 Candidate stun_candidate;
1194 EXPECT_PRED5(CheckCandidate, candidates_[1], ICE_CANDIDATE_COMPONENT_RTP, 1209 EXPECT_PRED5(FindAndReturnCandidate, candidates_, "stun", "udp",
1195 "stun", "udp", rtc::SocketAddress(kNatUdpAddr.ipaddr(), 0)); 1210 rtc::SocketAddress(kNatUdpAddr.ipaddr(), 0), &stun_candidate);
1196 EXPECT_PRED5(CheckCandidate, candidates_[2], ICE_CANDIDATE_COMPONENT_RTP, 1211 EXPECT_PRED5(FindCandidateWithRelatedAddr, candidates_, "relay", "udp",
1197 "relay", "udp", rtc::SocketAddress(kTurnUdpExtAddr.ipaddr(), 0)); 1212 rtc::SocketAddress(kTurnUdpExtAddr.ipaddr(), 0),
1198 EXPECT_EQ(candidates_[2].related_address(), candidates_[1].address()); 1213 stun_candidate.address());
1199 1214
1200 EXPECT_TRUE_WAIT(candidate_allocation_done_, kDefaultAllocationTimeout); 1215 EXPECT_TRUE_WAIT(candidate_allocation_done_, kDefaultAllocationTimeout);
1201 EXPECT_EQ(3U, candidates_.size()); 1216 EXPECT_EQ(3U, candidates_.size());
1202 // Local port will be created first and then TURN port. 1217 // Local port will be created first and then TURN port.
1203 EXPECT_EQ(2U, ports_[0]->Candidates().size()); 1218 EXPECT_EQ(2U, ports_[0]->Candidates().size());
1204 EXPECT_EQ(1U, ports_[1]->Candidates().size()); 1219 EXPECT_EQ(1U, ports_[1]->Candidates().size());
1205 } 1220 }
1206 1221
1207 // Test that when only a TCP TURN server is available, we do NOT use it as 1222 // Test that when only a TCP TURN server is available, we do NOT use it as
1208 // a UDP STUN server, as this could leak our IP address. Thus we should only 1223 // a UDP STUN server, as this could leak our IP address. Thus we should only
1209 // expect two ports, a UDPPort and TurnPort. 1224 // expect two ports, a UDPPort and TurnPort.
1210 TEST_F(BasicPortAllocatorTest, TestSharedSocketWithNatUsingTurnTcpOnly) { 1225 TEST_F(BasicPortAllocatorTest, TestSharedSocketWithNatUsingTurnTcpOnly) {
1211 turn_server_.AddInternalSocket(kTurnTcpIntAddr, PROTO_TCP); 1226 turn_server_.AddInternalSocket(kTurnTcpIntAddr, PROTO_TCP);
1212 AddInterface(kClientAddr); 1227 AddInterface(kClientAddr);
1213 ResetWithStunServerAndNat(rtc::SocketAddress()); 1228 ResetWithStunServerAndNat(rtc::SocketAddress());
1214 AddTurnServers(rtc::SocketAddress(), kTurnTcpIntAddr); 1229 AddTurnServers(rtc::SocketAddress(), kTurnTcpIntAddr);
1215 1230
1216 allocator_->set_flags(allocator().flags() | 1231 allocator_->set_flags(allocator().flags() |
1217 PORTALLOCATOR_ENABLE_SHARED_SOCKET | 1232 PORTALLOCATOR_ENABLE_SHARED_SOCKET |
1218 PORTALLOCATOR_DISABLE_TCP); 1233 PORTALLOCATOR_DISABLE_TCP);
1219 1234
1220 EXPECT_TRUE(CreateSession(ICE_CANDIDATE_COMPONENT_RTP)); 1235 EXPECT_TRUE(CreateSession(ICE_CANDIDATE_COMPONENT_RTP));
1221 session_->StartGettingPorts(); 1236 session_->StartGettingPorts();
1222 1237
1223 ASSERT_EQ_WAIT(2U, candidates_.size(), kDefaultAllocationTimeout); 1238 ASSERT_EQ_WAIT(2U, candidates_.size(), kDefaultAllocationTimeout);
1224 ASSERT_EQ(2U, ports_.size()); 1239 ASSERT_EQ(2U, ports_.size());
1225 EXPECT_PRED5(CheckCandidate, candidates_[0], ICE_CANDIDATE_COMPONENT_RTP, 1240 EXPECT_PRED4(FindCandidate, candidates_, "local", "udp", kClientAddr);
1226 "local", "udp", kClientAddr); 1241 EXPECT_PRED4(FindCandidate, candidates_, "relay", "udp",
1227 EXPECT_PRED5(CheckCandidate, candidates_[1], ICE_CANDIDATE_COMPONENT_RTP, 1242 rtc::SocketAddress(kTurnUdpExtAddr.ipaddr(), 0));
1228 "relay", "udp", rtc::SocketAddress(kTurnUdpExtAddr.ipaddr(), 0));
1229 EXPECT_TRUE_WAIT(candidate_allocation_done_, kDefaultAllocationTimeout); 1243 EXPECT_TRUE_WAIT(candidate_allocation_done_, kDefaultAllocationTimeout);
1230 EXPECT_EQ(2U, candidates_.size()); 1244 EXPECT_EQ(2U, candidates_.size());
1231 EXPECT_EQ(1U, ports_[0]->Candidates().size()); 1245 EXPECT_EQ(1U, ports_[0]->Candidates().size());
1232 EXPECT_EQ(1U, ports_[1]->Candidates().size()); 1246 EXPECT_EQ(1U, ports_[1]->Candidates().size());
1233 } 1247 }
1234 1248
1235 // Test that even when PORTALLOCATOR_ENABLE_SHARED_SOCKET is NOT enabled, the 1249 // Test that even when PORTALLOCATOR_ENABLE_SHARED_SOCKET is NOT enabled, the
1236 // TURN server is used as the STUN server and we get 'local', 'stun', and 1250 // TURN server is used as the STUN server and we get 'local', 'stun', and
1237 // 'relay' candidates. 1251 // 'relay' candidates.
1238 // TODO(deadbeef): Remove this test when support for non-shared socket mode 1252 // TODO(deadbeef): Remove this test when support for non-shared socket mode
1239 // is removed. 1253 // is removed.
1240 TEST_F(BasicPortAllocatorTest, TestNonSharedSocketWithNatUsingTurnAsStun) { 1254 TEST_F(BasicPortAllocatorTest, TestNonSharedSocketWithNatUsingTurnAsStun) {
1241 AddInterface(kClientAddr); 1255 AddInterface(kClientAddr);
1242 // Use an empty SocketAddress to add a NAT without STUN server. 1256 // Use an empty SocketAddress to add a NAT without STUN server.
1243 ResetWithStunServerAndNat(SocketAddress()); 1257 ResetWithStunServerAndNat(SocketAddress());
1244 AddTurnServers(kTurnUdpIntAddr, rtc::SocketAddress()); 1258 AddTurnServers(kTurnUdpIntAddr, rtc::SocketAddress());
1245 1259
1246 allocator_->set_flags(allocator().flags() | PORTALLOCATOR_DISABLE_TCP); 1260 allocator_->set_flags(allocator().flags() | PORTALLOCATOR_DISABLE_TCP);
1247 1261
1248 EXPECT_TRUE(CreateSession(ICE_CANDIDATE_COMPONENT_RTP)); 1262 EXPECT_TRUE(CreateSession(ICE_CANDIDATE_COMPONENT_RTP));
1249 session_->StartGettingPorts(); 1263 session_->StartGettingPorts();
1250 1264
1251 ASSERT_EQ_WAIT(3U, candidates_.size(), kDefaultAllocationTimeout); 1265 ASSERT_EQ_WAIT(3U, candidates_.size(), kDefaultAllocationTimeout);
1252 ASSERT_EQ(3U, ports_.size()); 1266 ASSERT_EQ(3U, ports_.size());
1253 EXPECT_PRED5(CheckCandidate, candidates_[0], ICE_CANDIDATE_COMPONENT_RTP, 1267 EXPECT_PRED4(FindCandidate, candidates_, "local", "udp", kClientAddr);
1254 "local", "udp", kClientAddr); 1268 Candidate stun_candidate;
1255 EXPECT_PRED5(CheckCandidate, candidates_[1], ICE_CANDIDATE_COMPONENT_RTP, 1269 EXPECT_PRED5(FindAndReturnCandidate, candidates_, "stun", "udp",
1256 "stun", "udp", rtc::SocketAddress(kNatUdpAddr.ipaddr(), 0)); 1270 rtc::SocketAddress(kNatUdpAddr.ipaddr(), 0), &stun_candidate);
1257 EXPECT_PRED5(CheckCandidate, candidates_[2], ICE_CANDIDATE_COMPONENT_RTP, 1271 Candidate turn_candidate;
1258 "relay", "udp", rtc::SocketAddress(kTurnUdpExtAddr.ipaddr(), 0)); 1272 EXPECT_PRED5(FindAndReturnCandidate, candidates_, "relay", "udp",
1273 rtc::SocketAddress(kTurnUdpExtAddr.ipaddr(), 0),
1274 &turn_candidate);
1259 // Not using shared socket, so the STUN request's server reflexive address 1275 // Not using shared socket, so the STUN request's server reflexive address
1260 // should be different than the TURN request's server reflexive address. 1276 // should be different than the TURN request's server reflexive address.
1261 EXPECT_NE(candidates_[2].related_address(), candidates_[1].address()); 1277 EXPECT_NE(turn_candidate.related_address(), stun_candidate.address());
1262 1278
1263 EXPECT_TRUE_WAIT(candidate_allocation_done_, kDefaultAllocationTimeout); 1279 EXPECT_TRUE_WAIT(candidate_allocation_done_, kDefaultAllocationTimeout);
1264 EXPECT_EQ(3U, candidates_.size()); 1280 EXPECT_EQ(3U, candidates_.size());
1265 EXPECT_EQ(1U, ports_[0]->Candidates().size()); 1281 EXPECT_EQ(1U, ports_[0]->Candidates().size());
1266 EXPECT_EQ(1U, ports_[1]->Candidates().size()); 1282 EXPECT_EQ(1U, ports_[1]->Candidates().size());
1267 EXPECT_EQ(1U, ports_[2]->Candidates().size()); 1283 EXPECT_EQ(1U, ports_[2]->Candidates().size());
1268 } 1284 }
1269 1285
1270 // Test that even when both a STUN and TURN server are configured, the TURN 1286 // Test that even when both a STUN and TURN server are configured, the TURN
1271 // server is used as a STUN server and we get a 'stun' candidate. 1287 // server is used as a STUN server and we get a 'stun' candidate.
1272 TEST_F(BasicPortAllocatorTest, TestSharedSocketWithNatUsingTurnAndStun) { 1288 TEST_F(BasicPortAllocatorTest, TestSharedSocketWithNatUsingTurnAndStun) {
1273 AddInterface(kClientAddr); 1289 AddInterface(kClientAddr);
1274 // Configure with STUN server but destroy it, so we can ensure that it's 1290 // Configure with STUN server but destroy it, so we can ensure that it's
1275 // the TURN server actually being used as a STUN server. 1291 // the TURN server actually being used as a STUN server.
1276 ResetWithStunServerAndNat(kStunAddr); 1292 ResetWithStunServerAndNat(kStunAddr);
1277 stun_server_.reset(); 1293 stun_server_.reset();
1278 AddTurnServers(kTurnUdpIntAddr, rtc::SocketAddress()); 1294 AddTurnServers(kTurnUdpIntAddr, rtc::SocketAddress());
1279 1295
1280 allocator_->set_flags(allocator().flags() | 1296 allocator_->set_flags(allocator().flags() |
1281 PORTALLOCATOR_ENABLE_SHARED_SOCKET | 1297 PORTALLOCATOR_ENABLE_SHARED_SOCKET |
1282 PORTALLOCATOR_DISABLE_TCP); 1298 PORTALLOCATOR_DISABLE_TCP);
1283 1299
1284 EXPECT_TRUE(CreateSession(ICE_CANDIDATE_COMPONENT_RTP)); 1300 EXPECT_TRUE(CreateSession(ICE_CANDIDATE_COMPONENT_RTP));
1285 session_->StartGettingPorts(); 1301 session_->StartGettingPorts();
1286 1302
1287 ASSERT_EQ_WAIT(3U, candidates_.size(), kDefaultAllocationTimeout); 1303 ASSERT_EQ_WAIT(3U, candidates_.size(), kDefaultAllocationTimeout);
1288 EXPECT_PRED5(CheckCandidate, candidates_[0], ICE_CANDIDATE_COMPONENT_RTP, 1304 EXPECT_PRED4(FindCandidate, candidates_, "local", "udp", kClientAddr);
1289 "local", "udp", kClientAddr); 1305 Candidate stun_candidate;
1290 EXPECT_PRED5(CheckCandidate, candidates_[1], ICE_CANDIDATE_COMPONENT_RTP, 1306 EXPECT_PRED5(FindAndReturnCandidate, candidates_, "stun", "udp",
1291 "stun", "udp", rtc::SocketAddress(kNatUdpAddr.ipaddr(), 0)); 1307 rtc::SocketAddress(kNatUdpAddr.ipaddr(), 0), &stun_candidate);
1292 EXPECT_PRED5(CheckCandidate, candidates_[2], ICE_CANDIDATE_COMPONENT_RTP, 1308 EXPECT_PRED5(FindCandidateWithRelatedAddr, candidates_, "relay", "udp",
1293 "relay", "udp", rtc::SocketAddress(kTurnUdpExtAddr.ipaddr(), 0)); 1309 rtc::SocketAddress(kTurnUdpExtAddr.ipaddr(), 0),
1294 EXPECT_EQ(candidates_[2].related_address(), candidates_[1].address()); 1310 stun_candidate.address());
1295 1311
1296 // Don't bother waiting for STUN timeout, since we already verified 1312 // Don't bother waiting for STUN timeout, since we already verified
1297 // that we got a STUN candidate from the TURN server. 1313 // that we got a STUN candidate from the TURN server.
1298 } 1314 }
1299 1315
1300 // This test verifies when PORTALLOCATOR_ENABLE_SHARED_SOCKET flag is enabled 1316 // This test verifies when PORTALLOCATOR_ENABLE_SHARED_SOCKET flag is enabled
1301 // and fail to generate STUN candidate, local UDP candidate is generated 1317 // and fail to generate STUN candidate, local UDP candidate is generated
1302 // properly. 1318 // properly.
1303 TEST_F(BasicPortAllocatorTest, TestSharedSocketNoUdpAllowed) { 1319 TEST_F(BasicPortAllocatorTest, TestSharedSocketNoUdpAllowed) {
1304 allocator().set_flags(allocator().flags() | PORTALLOCATOR_DISABLE_RELAY | 1320 allocator().set_flags(allocator().flags() | PORTALLOCATOR_DISABLE_RELAY |
1305 PORTALLOCATOR_DISABLE_TCP | 1321 PORTALLOCATOR_DISABLE_TCP |
1306 PORTALLOCATOR_ENABLE_SHARED_SOCKET); 1322 PORTALLOCATOR_ENABLE_SHARED_SOCKET);
1307 fss_->AddRule(false, rtc::FP_UDP, rtc::FD_ANY, kClientAddr); 1323 fss_->AddRule(false, rtc::FP_UDP, rtc::FD_ANY, kClientAddr);
1308 AddInterface(kClientAddr); 1324 AddInterface(kClientAddr);
1309 EXPECT_TRUE(CreateSession(ICE_CANDIDATE_COMPONENT_RTP)); 1325 EXPECT_TRUE(CreateSession(ICE_CANDIDATE_COMPONENT_RTP));
1310 session_->StartGettingPorts(); 1326 session_->StartGettingPorts();
1311 ASSERT_EQ_WAIT(1U, ports_.size(), kDefaultAllocationTimeout); 1327 ASSERT_EQ_WAIT(1U, ports_.size(), kDefaultAllocationTimeout);
1312 EXPECT_EQ(1U, candidates_.size()); 1328 EXPECT_EQ(1U, candidates_.size());
1313 EXPECT_PRED5(CheckCandidate, candidates_[0], ICE_CANDIDATE_COMPONENT_RTP, 1329 EXPECT_PRED4(FindCandidate, candidates_, "local", "udp", kClientAddr);
1314 "local", "udp", kClientAddr);
1315 // STUN timeout is 9.5sec. We need to wait to get candidate done signal. 1330 // STUN timeout is 9.5sec. We need to wait to get candidate done signal.
1316 EXPECT_TRUE_WAIT(candidate_allocation_done_, kStunTimeoutMs); 1331 EXPECT_TRUE_WAIT(candidate_allocation_done_, kStunTimeoutMs);
1317 EXPECT_EQ(1U, candidates_.size()); 1332 EXPECT_EQ(1U, candidates_.size());
1318 } 1333 }
1319 1334
1320 // Test that when the NetworkManager doesn't have permission to enumerate 1335 // Test that when the NetworkManager doesn't have permission to enumerate
1321 // adapters, the PORTALLOCATOR_DISABLE_ADAPTER_ENUMERATION is specified 1336 // adapters, the PORTALLOCATOR_DISABLE_ADAPTER_ENUMERATION is specified
1322 // automatically. 1337 // automatically.
1323 TEST_F(BasicPortAllocatorTest, TestNetworkPermissionBlocked) { 1338 TEST_F(BasicPortAllocatorTest, TestNetworkPermissionBlocked) {
1324 network_manager_.set_default_local_addresses(kPrivateAddr.ipaddr(), 1339 network_manager_.set_default_local_addresses(kPrivateAddr.ipaddr(),
1325 rtc::IPAddress()); 1340 rtc::IPAddress());
1326 network_manager_.set_enumeration_permission( 1341 network_manager_.set_enumeration_permission(
1327 rtc::NetworkManager::ENUMERATION_BLOCKED); 1342 rtc::NetworkManager::ENUMERATION_BLOCKED);
1328 allocator().set_flags(allocator().flags() | PORTALLOCATOR_DISABLE_RELAY | 1343 allocator().set_flags(allocator().flags() | PORTALLOCATOR_DISABLE_RELAY |
1329 PORTALLOCATOR_DISABLE_TCP | 1344 PORTALLOCATOR_DISABLE_TCP |
1330 PORTALLOCATOR_ENABLE_SHARED_SOCKET); 1345 PORTALLOCATOR_ENABLE_SHARED_SOCKET);
1331 EXPECT_EQ(0U, 1346 EXPECT_EQ(0U,
1332 allocator_->flags() & PORTALLOCATOR_DISABLE_ADAPTER_ENUMERATION); 1347 allocator_->flags() & PORTALLOCATOR_DISABLE_ADAPTER_ENUMERATION);
1333 EXPECT_TRUE(CreateSession(ICE_CANDIDATE_COMPONENT_RTP)); 1348 EXPECT_TRUE(CreateSession(ICE_CANDIDATE_COMPONENT_RTP));
1334 EXPECT_EQ(0U, session_->flags() & PORTALLOCATOR_DISABLE_ADAPTER_ENUMERATION); 1349 EXPECT_EQ(0U, session_->flags() & PORTALLOCATOR_DISABLE_ADAPTER_ENUMERATION);
1335 session_->StartGettingPorts(); 1350 session_->StartGettingPorts();
1336 EXPECT_EQ_WAIT(1U, ports_.size(), kDefaultAllocationTimeout); 1351 EXPECT_EQ_WAIT(1U, ports_.size(), kDefaultAllocationTimeout);
1337 EXPECT_EQ(1U, candidates_.size()); 1352 EXPECT_EQ(1U, candidates_.size());
1338 EXPECT_PRED5(CheckCandidate, candidates_[0], ICE_CANDIDATE_COMPONENT_RTP, 1353 EXPECT_PRED4(FindCandidate, candidates_, "local", "udp", kPrivateAddr);
1339 "local", "udp", kPrivateAddr);
1340 EXPECT_NE(0U, session_->flags() & PORTALLOCATOR_DISABLE_ADAPTER_ENUMERATION); 1354 EXPECT_NE(0U, session_->flags() & PORTALLOCATOR_DISABLE_ADAPTER_ENUMERATION);
1341 } 1355 }
1342 1356
1343 // This test verifies allocator can use IPv6 addresses along with IPv4. 1357 // This test verifies allocator can use IPv6 addresses along with IPv4.
1344 TEST_F(BasicPortAllocatorTest, TestEnableIPv6Addresses) { 1358 TEST_F(BasicPortAllocatorTest, TestEnableIPv6Addresses) {
1345 allocator().set_flags(allocator().flags() | PORTALLOCATOR_DISABLE_RELAY | 1359 allocator().set_flags(allocator().flags() | PORTALLOCATOR_DISABLE_RELAY |
1346 PORTALLOCATOR_ENABLE_IPV6 | 1360 PORTALLOCATOR_ENABLE_IPV6 |
1347 PORTALLOCATOR_ENABLE_SHARED_SOCKET); 1361 PORTALLOCATOR_ENABLE_SHARED_SOCKET);
1348 AddInterface(kClientIPv6Addr); 1362 AddInterface(kClientIPv6Addr);
1349 AddInterface(kClientAddr); 1363 AddInterface(kClientAddr);
1350 allocator_->set_step_delay(kMinimumStepDelay); 1364 allocator_->set_step_delay(kMinimumStepDelay);
1351 EXPECT_TRUE(CreateSession(ICE_CANDIDATE_COMPONENT_RTP)); 1365 EXPECT_TRUE(CreateSession(ICE_CANDIDATE_COMPONENT_RTP));
1352 session_->StartGettingPorts(); 1366 session_->StartGettingPorts();
1353 ASSERT_EQ_WAIT(4U, ports_.size(), kDefaultAllocationTimeout); 1367 ASSERT_EQ_WAIT(4U, ports_.size(), kDefaultAllocationTimeout);
1354 EXPECT_EQ(4U, candidates_.size()); 1368 EXPECT_EQ(4U, candidates_.size());
1355 EXPECT_TRUE_WAIT(candidate_allocation_done_, kDefaultAllocationTimeout); 1369 EXPECT_TRUE_WAIT(candidate_allocation_done_, kDefaultAllocationTimeout);
1356 EXPECT_PRED5(CheckCandidate, candidates_[0], ICE_CANDIDATE_COMPONENT_RTP, 1370 EXPECT_PRED4(FindCandidate, candidates_, "local", "udp", kClientIPv6Addr);
1357 "local", "udp", kClientIPv6Addr); 1371 EXPECT_PRED4(FindCandidate, candidates_, "local", "udp", kClientAddr);
1358 EXPECT_PRED5(CheckCandidate, candidates_[1], ICE_CANDIDATE_COMPONENT_RTP, 1372 EXPECT_PRED4(FindCandidate, candidates_, "local", "tcp", kClientIPv6Addr);
1359 "local", "udp", kClientAddr); 1373 EXPECT_PRED4(FindCandidate, candidates_, "local", "tcp", kClientAddr);
1360 EXPECT_PRED5(CheckCandidate, candidates_[2], ICE_CANDIDATE_COMPONENT_RTP,
1361 "local", "tcp", kClientIPv6Addr);
1362 EXPECT_PRED5(CheckCandidate, candidates_[3], ICE_CANDIDATE_COMPONENT_RTP,
1363 "local", "tcp", kClientAddr);
1364 EXPECT_EQ(4U, candidates_.size()); 1374 EXPECT_EQ(4U, candidates_.size());
1365 } 1375 }
1366 1376
1367 TEST_F(BasicPortAllocatorTest, TestStopGettingPorts) { 1377 TEST_F(BasicPortAllocatorTest, TestStopGettingPorts) {
1368 AddInterface(kClientAddr); 1378 AddInterface(kClientAddr);
1369 allocator_->set_step_delay(kDefaultStepDelay); 1379 allocator_->set_step_delay(kDefaultStepDelay);
1370 EXPECT_TRUE(CreateSession(ICE_CANDIDATE_COMPONENT_RTP)); 1380 EXPECT_TRUE(CreateSession(ICE_CANDIDATE_COMPONENT_RTP));
1371 session_->StartGettingPorts(); 1381 session_->StartGettingPorts();
1372 ASSERT_EQ_WAIT(2U, candidates_.size(), 1000); 1382 ASSERT_EQ_WAIT(2U, candidates_.size(), 1000);
1373 EXPECT_EQ(2U, ports_.size()); 1383 EXPECT_EQ(2U, ports_.size());
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after
1473 for (const Candidate& candidate : candidates) { 1483 for (const Candidate& candidate : candidates) {
1474 // Expect only relay candidates now that the filter is applied. 1484 // Expect only relay candidates now that the filter is applied.
1475 EXPECT_EQ(std::string(RELAY_PORT_TYPE), candidate.type()); 1485 EXPECT_EQ(std::string(RELAY_PORT_TYPE), candidate.type());
1476 // Expect that the raddr is emptied due to the CF_RELAY filter. 1486 // Expect that the raddr is emptied due to the CF_RELAY filter.
1477 EXPECT_EQ(candidate.related_address(), 1487 EXPECT_EQ(candidate.related_address(),
1478 rtc::EmptySocketAddressWithFamily(candidate.address().family())); 1488 rtc::EmptySocketAddressWithFamily(candidate.address().family()));
1479 } 1489 }
1480 } 1490 }
1481 1491
1482 } // namespace cricket 1492 } // 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