OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2009 The WebRTC Project Authors. All rights reserved. | 2 * Copyright 2009 The WebRTC Project Authors. All rights reserved. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license | 4 * Use of this source code is governed by a BSD-style license |
5 * that can be found in the LICENSE file in the root of the source | 5 * that can be found in the LICENSE file in the root of the source |
6 * tree. An additional intellectual property rights grant can be found | 6 * tree. An additional intellectual property rights grant can be found |
7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may |
8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. |
9 */ | 9 */ |
10 | 10 |
11 #include <algorithm> | 11 #include <algorithm> |
12 #include <memory> | 12 #include <memory> |
13 | 13 |
14 #include "webrtc/p2p/base/basicpacketsocketfactory.h" | 14 #include "webrtc/p2p/base/basicpacketsocketfactory.h" |
15 #include "webrtc/p2p/base/p2pconstants.h" | 15 #include "webrtc/p2p/base/p2pconstants.h" |
16 #include "webrtc/p2p/base/p2ptransportchannel.h" | 16 #include "webrtc/p2p/base/p2ptransportchannel.h" |
17 #include "webrtc/p2p/base/testrelayserver.h" | 17 #include "webrtc/p2p/base/testrelayserver.h" |
18 #include "webrtc/p2p/base/teststunserver.h" | 18 #include "webrtc/p2p/base/teststunserver.h" |
19 #include "webrtc/p2p/base/testturnserver.h" | 19 #include "webrtc/p2p/base/testturnserver.h" |
20 #include "webrtc/p2p/client/basicportallocator.h" | 20 #include "webrtc/p2p/client/basicportallocator.h" |
| 21 #include "webrtc/base/fakeclock.h" |
21 #include "webrtc/base/fakenetwork.h" | 22 #include "webrtc/base/fakenetwork.h" |
22 #include "webrtc/base/firewallsocketserver.h" | 23 #include "webrtc/base/firewallsocketserver.h" |
23 #include "webrtc/base/gunit.h" | 24 #include "webrtc/base/gunit.h" |
24 #include "webrtc/base/helpers.h" | 25 #include "webrtc/base/helpers.h" |
25 #include "webrtc/base/ipaddress.h" | 26 #include "webrtc/base/ipaddress.h" |
26 #include "webrtc/base/logging.h" | 27 #include "webrtc/base/logging.h" |
27 #include "webrtc/base/natserver.h" | 28 #include "webrtc/base/natserver.h" |
28 #include "webrtc/base/natsocketfactory.h" | 29 #include "webrtc/base/natsocketfactory.h" |
29 #include "webrtc/base/network.h" | 30 #include "webrtc/base/network.h" |
30 #include "webrtc/base/physicalsocketserver.h" | 31 #include "webrtc/base/physicalsocketserver.h" |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
100 if (!first) { | 101 if (!first) { |
101 os << ", "; | 102 os << ", "; |
102 } | 103 } |
103 os << c.ToString(); | 104 os << c.ToString(); |
104 first = false; | 105 first = false; |
105 }; | 106 }; |
106 os << ']'; | 107 os << ']'; |
107 return os; | 108 return os; |
108 } | 109 } |
109 | 110 |
110 class BasicPortAllocatorTest : public testing::Test, | 111 class BasicPortAllocatorTestBase : public testing::Test, |
111 public sigslot::has_slots<> { | 112 public sigslot::has_slots<> { |
112 public: | 113 public: |
113 BasicPortAllocatorTest() | 114 BasicPortAllocatorTestBase() |
114 : pss_(new rtc::PhysicalSocketServer), | 115 : pss_(new rtc::PhysicalSocketServer), |
115 vss_(new rtc::VirtualSocketServer(pss_.get())), | 116 vss_(new rtc::VirtualSocketServer(pss_.get())), |
116 fss_(new rtc::FirewallSocketServer(vss_.get())), | 117 fss_(new rtc::FirewallSocketServer(vss_.get())), |
117 ss_scope_(fss_.get()), | 118 ss_scope_(fss_.get()), |
118 // Note that the NAT is not used by default. ResetWithStunServerAndNat | 119 // Note that the NAT is not used by default. ResetWithStunServerAndNat |
119 // must be called. | 120 // must be called. |
120 nat_factory_(vss_.get(), kNatUdpAddr, kNatTcpAddr), | 121 nat_factory_(vss_.get(), kNatUdpAddr, kNatTcpAddr), |
121 nat_socket_factory_(new rtc::BasicPacketSocketFactory(&nat_factory_)), | 122 nat_socket_factory_(new rtc::BasicPacketSocketFactory(&nat_factory_)), |
122 stun_server_(TestStunServer::Create(Thread::Current(), kStunAddr)), | 123 stun_server_(TestStunServer::Create(Thread::Current(), kStunAddr)), |
123 relay_server_(Thread::Current(), | 124 relay_server_(Thread::Current(), |
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
236 | 237 |
237 std::unique_ptr<PortAllocatorSession> CreateSession( | 238 std::unique_ptr<PortAllocatorSession> CreateSession( |
238 const std::string& sid, | 239 const std::string& sid, |
239 const std::string& content_name, | 240 const std::string& content_name, |
240 int component, | 241 int component, |
241 const std::string& ice_ufrag, | 242 const std::string& ice_ufrag, |
242 const std::string& ice_pwd) { | 243 const std::string& ice_pwd) { |
243 std::unique_ptr<PortAllocatorSession> session = | 244 std::unique_ptr<PortAllocatorSession> session = |
244 allocator_->CreateSession(content_name, component, ice_ufrag, ice_pwd); | 245 allocator_->CreateSession(content_name, component, ice_ufrag, ice_pwd); |
245 session->SignalPortReady.connect(this, | 246 session->SignalPortReady.connect(this, |
246 &BasicPortAllocatorTest::OnPortReady); | 247 &BasicPortAllocatorTestBase::OnPortReady); |
247 session->SignalPortsPruned.connect(this, | 248 session->SignalPortsPruned.connect( |
248 &BasicPortAllocatorTest::OnPortsPruned); | 249 this, &BasicPortAllocatorTestBase::OnPortsPruned); |
249 session->SignalCandidatesReady.connect( | 250 session->SignalCandidatesReady.connect( |
250 this, &BasicPortAllocatorTest::OnCandidatesReady); | 251 this, &BasicPortAllocatorTestBase::OnCandidatesReady); |
251 session->SignalCandidatesRemoved.connect( | 252 session->SignalCandidatesRemoved.connect( |
252 this, &BasicPortAllocatorTest::OnCandidatesRemoved); | 253 this, &BasicPortAllocatorTestBase::OnCandidatesRemoved); |
253 session->SignalCandidatesAllocationDone.connect( | 254 session->SignalCandidatesAllocationDone.connect( |
254 this, &BasicPortAllocatorTest::OnCandidatesAllocationDone); | 255 this, &BasicPortAllocatorTestBase::OnCandidatesAllocationDone); |
255 return session; | 256 return session; |
256 } | 257 } |
257 | 258 |
258 // Return true if the addresses are the same, or the port is 0 in |pattern| | 259 // Return true if the addresses are the same, or the port is 0 in |pattern| |
259 // (acting as a wildcard) and the IPs are the same. | 260 // (acting as a wildcard) and the IPs are the same. |
260 // Even with a wildcard port, the port of the address should be nonzero if | 261 // Even with a wildcard port, the port of the address should be nonzero if |
261 // the IP is nonzero. | 262 // the IP is nonzero. |
262 static bool AddressMatch(const SocketAddress& address, | 263 static bool AddressMatch(const SocketAddress& address, |
263 const SocketAddress& pattern) { | 264 const SocketAddress& pattern) { |
264 return address.ipaddr() == pattern.ipaddr() && | 265 return address.ipaddr() == pattern.ipaddr() && |
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
360 EXPECT_EQ(SOCKET_ERROR, | 361 EXPECT_EQ(SOCKET_ERROR, |
361 (*it)->GetOption(rtc::Socket::OPT_SNDBUF, &send_buffer_size)); | 362 (*it)->GetOption(rtc::Socket::OPT_SNDBUF, &send_buffer_size)); |
362 } else { | 363 } else { |
363 EXPECT_EQ(0, | 364 EXPECT_EQ(0, |
364 (*it)->GetOption(rtc::Socket::OPT_SNDBUF, &send_buffer_size)); | 365 (*it)->GetOption(rtc::Socket::OPT_SNDBUF, &send_buffer_size)); |
365 ASSERT_EQ(expected, send_buffer_size); | 366 ASSERT_EQ(expected, send_buffer_size); |
366 } | 367 } |
367 } | 368 } |
368 } | 369 } |
369 | 370 |
370 // This function starts the port/address gathering and check the existence of | |
371 // candidates as specified. When |expect_stun_candidate| is true, | |
372 // |stun_candidate_addr| carries the expected reflective address, which is | |
373 // also the related address for TURN candidate if it is expected. Otherwise, | |
374 // it should be ignore. | |
375 void CheckDisableAdapterEnumeration( | |
376 uint32_t total_ports, | |
377 const rtc::IPAddress& host_candidate_addr, | |
378 const rtc::IPAddress& stun_candidate_addr, | |
379 const rtc::IPAddress& relay_candidate_udp_transport_addr, | |
380 const rtc::IPAddress& relay_candidate_tcp_transport_addr) { | |
381 network_manager_.set_default_local_addresses(kPrivateAddr.ipaddr(), | |
382 rtc::IPAddress()); | |
383 if (!session_) { | |
384 EXPECT_TRUE(CreateSession(ICE_CANDIDATE_COMPONENT_RTP)); | |
385 } | |
386 session_->set_flags(session_->flags() | | |
387 PORTALLOCATOR_DISABLE_ADAPTER_ENUMERATION | | |
388 PORTALLOCATOR_ENABLE_SHARED_SOCKET); | |
389 allocator().set_allow_tcp_listen(false); | |
390 session_->StartGettingPorts(); | |
391 EXPECT_TRUE_WAIT(candidate_allocation_done_, kDefaultAllocationTimeout); | |
392 | |
393 uint32_t total_candidates = 0; | |
394 if (!host_candidate_addr.IsNil()) { | |
395 EXPECT_PRED4(HasCandidate, candidates_, "local", "udp", | |
396 rtc::SocketAddress(kPrivateAddr.ipaddr(), 0)); | |
397 ++total_candidates; | |
398 } | |
399 if (!stun_candidate_addr.IsNil()) { | |
400 rtc::SocketAddress related_address(host_candidate_addr, 0); | |
401 if (host_candidate_addr.IsNil()) { | |
402 related_address.SetIP(rtc::GetAnyIP(stun_candidate_addr.family())); | |
403 } | |
404 EXPECT_PRED5(HasCandidateWithRelatedAddr, candidates_, "stun", "udp", | |
405 rtc::SocketAddress(stun_candidate_addr, 0), related_address); | |
406 ++total_candidates; | |
407 } | |
408 if (!relay_candidate_udp_transport_addr.IsNil()) { | |
409 EXPECT_PRED5(HasCandidateWithRelatedAddr, candidates_, "relay", "udp", | |
410 rtc::SocketAddress(relay_candidate_udp_transport_addr, 0), | |
411 rtc::SocketAddress(stun_candidate_addr, 0)); | |
412 ++total_candidates; | |
413 } | |
414 if (!relay_candidate_tcp_transport_addr.IsNil()) { | |
415 EXPECT_PRED5(HasCandidateWithRelatedAddr, candidates_, "relay", "udp", | |
416 rtc::SocketAddress(relay_candidate_tcp_transport_addr, 0), | |
417 rtc::SocketAddress(stun_candidate_addr, 0)); | |
418 ++total_candidates; | |
419 } | |
420 | |
421 EXPECT_EQ(total_candidates, candidates_.size()); | |
422 EXPECT_EQ(total_ports, ports_.size()); | |
423 } | |
424 | |
425 rtc::VirtualSocketServer* virtual_socket_server() { return vss_.get(); } | 371 rtc::VirtualSocketServer* virtual_socket_server() { return vss_.get(); } |
426 | 372 |
427 protected: | 373 protected: |
428 BasicPortAllocator& allocator() { return *allocator_; } | 374 BasicPortAllocator& allocator() { return *allocator_; } |
429 | 375 |
430 void OnPortReady(PortAllocatorSession* ses, PortInterface* port) { | 376 void OnPortReady(PortAllocatorSession* ses, PortInterface* port) { |
431 LOG(LS_INFO) << "OnPortReady: " << port->ToString(); | 377 LOG(LS_INFO) << "OnPortReady: " << port->ToString(); |
432 ports_.push_back(port); | 378 ports_.push_back(port); |
433 // Make sure the new port is added to ReadyPorts. | 379 // Make sure the new port is added to ReadyPorts. |
434 auto ready_ports = ses->ReadyPorts(); | 380 auto ready_ports = ses->ReadyPorts(); |
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
507 | 453 |
508 ServerAddresses stun_servers; | 454 ServerAddresses stun_servers; |
509 if (!stun_server.IsNil()) { | 455 if (!stun_server.IsNil()) { |
510 stun_servers.insert(stun_server); | 456 stun_servers.insert(stun_server); |
511 } | 457 } |
512 allocator_.reset(new BasicPortAllocator( | 458 allocator_.reset(new BasicPortAllocator( |
513 &network_manager_, nat_socket_factory_.get(), stun_servers)); | 459 &network_manager_, nat_socket_factory_.get(), stun_servers)); |
514 allocator().set_step_delay(kMinimumStepDelay); | 460 allocator().set_step_delay(kMinimumStepDelay); |
515 } | 461 } |
516 | 462 |
517 void TestUdpTurnPortPrunesTcpTurnPort() { | 463 std::unique_ptr<rtc::PhysicalSocketServer> pss_; |
518 turn_server_.AddInternalSocket(kTurnTcpIntAddr, PROTO_TCP); | 464 std::unique_ptr<rtc::VirtualSocketServer> vss_; |
519 AddInterface(kClientAddr); | 465 std::unique_ptr<rtc::FirewallSocketServer> fss_; |
520 allocator_.reset(new BasicPortAllocator(&network_manager_)); | 466 rtc::SocketServerScope ss_scope_; |
521 allocator_->SetConfiguration(allocator_->stun_servers(), | 467 std::unique_ptr<rtc::NATServer> nat_server_; |
522 allocator_->turn_servers(), 0, true); | 468 rtc::NATSocketFactory nat_factory_; |
523 AddTurnServers(kTurnUdpIntAddr, kTurnTcpIntAddr); | 469 std::unique_ptr<rtc::BasicPacketSocketFactory> nat_socket_factory_; |
524 allocator_->set_step_delay(kMinimumStepDelay); | 470 std::unique_ptr<TestStunServer> stun_server_; |
525 allocator_->set_flags(allocator().flags() | | 471 TestRelayServer relay_server_; |
526 PORTALLOCATOR_ENABLE_SHARED_SOCKET | | 472 TestTurnServer turn_server_; |
527 PORTALLOCATOR_DISABLE_TCP); | 473 rtc::FakeNetworkManager network_manager_; |
| 474 std::unique_ptr<BasicPortAllocator> allocator_; |
| 475 std::unique_ptr<PortAllocatorSession> session_; |
| 476 std::vector<PortInterface*> ports_; |
| 477 std::vector<Candidate> candidates_; |
| 478 bool candidate_allocation_done_; |
| 479 }; |
528 | 480 |
529 EXPECT_TRUE(CreateSession(ICE_CANDIDATE_COMPONENT_RTP)); | 481 class BasicPortAllocatorTestWithRealClock : public BasicPortAllocatorTestBase { |
| 482 }; |
| 483 |
| 484 class FakeClockBase { |
| 485 public: |
| 486 rtc::ScopedFakeClock fake_clock; |
| 487 }; |
| 488 |
| 489 class BasicPortAllocatorTest : public FakeClockBase, |
| 490 public BasicPortAllocatorTestBase { |
| 491 public: |
| 492 // This function starts the port/address gathering and check the existence of |
| 493 // candidates as specified. When |expect_stun_candidate| is true, |
| 494 // |stun_candidate_addr| carries the expected reflective address, which is |
| 495 // also the related address for TURN candidate if it is expected. Otherwise, |
| 496 // it should be ignore. |
| 497 void CheckDisableAdapterEnumeration( |
| 498 uint32_t total_ports, |
| 499 const rtc::IPAddress& host_candidate_addr, |
| 500 const rtc::IPAddress& stun_candidate_addr, |
| 501 const rtc::IPAddress& relay_candidate_udp_transport_addr, |
| 502 const rtc::IPAddress& relay_candidate_tcp_transport_addr) { |
| 503 network_manager_.set_default_local_addresses(kPrivateAddr.ipaddr(), |
| 504 rtc::IPAddress()); |
| 505 if (!session_) { |
| 506 EXPECT_TRUE(CreateSession(ICE_CANDIDATE_COMPONENT_RTP)); |
| 507 } |
| 508 session_->set_flags(session_->flags() | |
| 509 PORTALLOCATOR_DISABLE_ADAPTER_ENUMERATION | |
| 510 PORTALLOCATOR_ENABLE_SHARED_SOCKET); |
| 511 allocator().set_allow_tcp_listen(false); |
530 session_->StartGettingPorts(); | 512 session_->StartGettingPorts(); |
531 EXPECT_TRUE_WAIT(candidate_allocation_done_, kDefaultAllocationTimeout); | 513 EXPECT_TRUE_SIMULATED_WAIT(candidate_allocation_done_, |
532 // Only 2 ports (one STUN and one TURN) are actually being used. | 514 kDefaultAllocationTimeout, fake_clock); |
533 EXPECT_EQ(2U, session_->ReadyPorts().size()); | |
534 // We have verified that each port, when it is added to |ports_|, it is | |
535 // found in |ready_ports|, and when it is pruned, it is not found in | |
536 // |ready_ports|, so we only need to verify the content in one of them. | |
537 EXPECT_EQ(2U, ports_.size()); | |
538 EXPECT_EQ(1, CountPorts(ports_, "local", PROTO_UDP, kClientAddr)); | |
539 EXPECT_EQ(1, CountPorts(ports_, "relay", PROTO_UDP, kClientAddr)); | |
540 EXPECT_EQ(0, CountPorts(ports_, "relay", PROTO_TCP, kClientAddr)); | |
541 | 515 |
542 // Now that we remove candidates when a TURN port is pruned, |candidates_| | 516 uint32_t total_candidates = 0; |
543 // should only contains two candidates regardless whether the TCP TURN port | 517 if (!host_candidate_addr.IsNil()) { |
544 // is created before or after the UDP turn port. | 518 EXPECT_PRED4(HasCandidate, candidates_, "local", "udp", |
545 EXPECT_EQ(2U, candidates_.size()); | 519 rtc::SocketAddress(kPrivateAddr.ipaddr(), 0)); |
546 // There will only be 2 candidates in |ready_candidates| because it only | 520 ++total_candidates; |
547 // includes the candidates in the ready ports. | 521 } |
548 const std::vector<Candidate>& ready_candidates = | 522 if (!stun_candidate_addr.IsNil()) { |
549 session_->ReadyCandidates(); | 523 rtc::SocketAddress related_address(host_candidate_addr, 0); |
550 EXPECT_EQ(2U, ready_candidates.size()); | 524 if (host_candidate_addr.IsNil()) { |
551 EXPECT_PRED4(HasCandidate, ready_candidates, "local", "udp", kClientAddr); | 525 related_address.SetIP(rtc::GetAnyIP(stun_candidate_addr.family())); |
552 EXPECT_PRED4(HasCandidate, ready_candidates, "relay", "udp", | 526 } |
553 rtc::SocketAddress(kTurnUdpExtAddr.ipaddr(), 0)); | 527 EXPECT_PRED5(HasCandidateWithRelatedAddr, candidates_, "stun", "udp", |
| 528 rtc::SocketAddress(stun_candidate_addr, 0), related_address); |
| 529 ++total_candidates; |
| 530 } |
| 531 if (!relay_candidate_udp_transport_addr.IsNil()) { |
| 532 EXPECT_PRED5(HasCandidateWithRelatedAddr, candidates_, "relay", "udp", |
| 533 rtc::SocketAddress(relay_candidate_udp_transport_addr, 0), |
| 534 rtc::SocketAddress(stun_candidate_addr, 0)); |
| 535 ++total_candidates; |
| 536 } |
| 537 if (!relay_candidate_tcp_transport_addr.IsNil()) { |
| 538 EXPECT_PRED5(HasCandidateWithRelatedAddr, candidates_, "relay", "udp", |
| 539 rtc::SocketAddress(relay_candidate_tcp_transport_addr, 0), |
| 540 rtc::SocketAddress(stun_candidate_addr, 0)); |
| 541 ++total_candidates; |
| 542 } |
| 543 |
| 544 EXPECT_EQ(total_candidates, candidates_.size()); |
| 545 EXPECT_EQ(total_ports, ports_.size()); |
554 } | 546 } |
555 | 547 |
556 void TestIPv6TurnPortPrunesIPv4TurnPort() { | 548 void TestIPv6TurnPortPrunesIPv4TurnPort() { |
557 turn_server_.AddInternalSocket(kTurnUdpIntIPv6Addr, PROTO_UDP); | 549 turn_server_.AddInternalSocket(kTurnUdpIntIPv6Addr, PROTO_UDP); |
558 // Add two IP addresses on the same interface. | 550 // Add two IP addresses on the same interface. |
559 AddInterface(kClientAddr, "net1"); | 551 AddInterface(kClientAddr, "net1"); |
560 AddInterface(kClientIPv6Addr, "net1"); | 552 AddInterface(kClientIPv6Addr, "net1"); |
561 allocator_.reset(new BasicPortAllocator(&network_manager_)); | 553 allocator_.reset(new BasicPortAllocator(&network_manager_)); |
562 allocator_->SetConfiguration(allocator_->stun_servers(), | 554 allocator_->SetConfiguration(allocator_->stun_servers(), |
563 allocator_->turn_servers(), 0, true); | 555 allocator_->turn_servers(), 0, true); |
564 AddTurnServers(kTurnUdpIntIPv6Addr, rtc::SocketAddress()); | 556 AddTurnServers(kTurnUdpIntIPv6Addr, rtc::SocketAddress()); |
565 AddTurnServers(kTurnUdpIntAddr, rtc::SocketAddress()); | 557 AddTurnServers(kTurnUdpIntAddr, rtc::SocketAddress()); |
566 | 558 |
567 allocator_->set_step_delay(kMinimumStepDelay); | 559 allocator_->set_step_delay(kMinimumStepDelay); |
568 allocator_->set_flags( | 560 allocator_->set_flags( |
569 allocator().flags() | PORTALLOCATOR_ENABLE_SHARED_SOCKET | | 561 allocator().flags() | PORTALLOCATOR_ENABLE_SHARED_SOCKET | |
570 PORTALLOCATOR_ENABLE_IPV6 | PORTALLOCATOR_DISABLE_TCP); | 562 PORTALLOCATOR_ENABLE_IPV6 | PORTALLOCATOR_DISABLE_TCP); |
571 | 563 |
572 EXPECT_TRUE(CreateSession(ICE_CANDIDATE_COMPONENT_RTP)); | 564 EXPECT_TRUE(CreateSession(ICE_CANDIDATE_COMPONENT_RTP)); |
573 session_->StartGettingPorts(); | 565 session_->StartGettingPorts(); |
574 EXPECT_TRUE_WAIT(candidate_allocation_done_, kDefaultAllocationTimeout); | 566 EXPECT_TRUE_SIMULATED_WAIT(candidate_allocation_done_, |
| 567 kDefaultAllocationTimeout, fake_clock); |
575 // Three ports (one IPv4 STUN, one IPv6 STUN and one TURN) will be ready. | 568 // Three ports (one IPv4 STUN, one IPv6 STUN and one TURN) will be ready. |
576 EXPECT_EQ(3U, session_->ReadyPorts().size()); | 569 EXPECT_EQ(3U, session_->ReadyPorts().size()); |
577 EXPECT_EQ(3U, ports_.size()); | 570 EXPECT_EQ(3U, ports_.size()); |
578 EXPECT_EQ(1, CountPorts(ports_, "local", PROTO_UDP, kClientAddr)); | 571 EXPECT_EQ(1, CountPorts(ports_, "local", PROTO_UDP, kClientAddr)); |
579 EXPECT_EQ(1, CountPorts(ports_, "local", PROTO_UDP, kClientIPv6Addr)); | 572 EXPECT_EQ(1, CountPorts(ports_, "local", PROTO_UDP, kClientIPv6Addr)); |
580 EXPECT_EQ(1, CountPorts(ports_, "relay", PROTO_UDP, kClientIPv6Addr)); | 573 EXPECT_EQ(1, CountPorts(ports_, "relay", PROTO_UDP, kClientIPv6Addr)); |
581 EXPECT_EQ(0, CountPorts(ports_, "relay", PROTO_UDP, kClientAddr)); | 574 EXPECT_EQ(0, CountPorts(ports_, "relay", PROTO_UDP, kClientAddr)); |
582 | 575 |
583 // Now that we remove candidates when a TURN port is pruned, there will be | 576 // Now that we remove candidates when a TURN port is pruned, there will be |
584 // exactly 3 candidates in both |candidates_| and |ready_candidates|. | 577 // exactly 3 candidates in both |candidates_| and |ready_candidates|. |
585 EXPECT_EQ(3U, candidates_.size()); | 578 EXPECT_EQ(3U, candidates_.size()); |
586 const std::vector<Candidate>& ready_candidates = | 579 const std::vector<Candidate>& ready_candidates = |
587 session_->ReadyCandidates(); | 580 session_->ReadyCandidates(); |
588 EXPECT_EQ(3U, ready_candidates.size()); | 581 EXPECT_EQ(3U, ready_candidates.size()); |
589 EXPECT_PRED4(HasCandidate, ready_candidates, "local", "udp", kClientAddr); | 582 EXPECT_PRED4(HasCandidate, ready_candidates, "local", "udp", kClientAddr); |
590 EXPECT_PRED4(HasCandidate, ready_candidates, "relay", "udp", | 583 EXPECT_PRED4(HasCandidate, ready_candidates, "relay", "udp", |
591 rtc::SocketAddress(kTurnUdpExtAddr.ipaddr(), 0)); | 584 rtc::SocketAddress(kTurnUdpExtAddr.ipaddr(), 0)); |
592 } | 585 } |
593 | 586 |
| 587 void TestUdpTurnPortPrunesTcpTurnPort() { |
| 588 turn_server_.AddInternalSocket(kTurnTcpIntAddr, PROTO_TCP); |
| 589 AddInterface(kClientAddr); |
| 590 allocator_.reset(new BasicPortAllocator(&network_manager_)); |
| 591 allocator_->SetConfiguration(allocator_->stun_servers(), |
| 592 allocator_->turn_servers(), 0, true); |
| 593 AddTurnServers(kTurnUdpIntAddr, kTurnTcpIntAddr); |
| 594 allocator_->set_step_delay(kMinimumStepDelay); |
| 595 allocator_->set_flags(allocator().flags() | |
| 596 PORTALLOCATOR_ENABLE_SHARED_SOCKET | |
| 597 PORTALLOCATOR_DISABLE_TCP); |
| 598 |
| 599 EXPECT_TRUE(CreateSession(ICE_CANDIDATE_COMPONENT_RTP)); |
| 600 session_->StartGettingPorts(); |
| 601 EXPECT_TRUE_SIMULATED_WAIT(candidate_allocation_done_, |
| 602 kDefaultAllocationTimeout, fake_clock); |
| 603 // Only 2 ports (one STUN and one TURN) are actually being used. |
| 604 EXPECT_EQ(2U, session_->ReadyPorts().size()); |
| 605 // We have verified that each port, when it is added to |ports_|, it is |
| 606 // found in |ready_ports|, and when it is pruned, it is not found in |
| 607 // |ready_ports|, so we only need to verify the content in one of them. |
| 608 EXPECT_EQ(2U, ports_.size()); |
| 609 EXPECT_EQ(1, CountPorts(ports_, "local", PROTO_UDP, kClientAddr)); |
| 610 EXPECT_EQ(1, CountPorts(ports_, "relay", PROTO_UDP, kClientAddr)); |
| 611 EXPECT_EQ(0, CountPorts(ports_, "relay", PROTO_TCP, kClientAddr)); |
| 612 |
| 613 // Now that we remove candidates when a TURN port is pruned, |candidates_| |
| 614 // should only contains two candidates regardless whether the TCP TURN port |
| 615 // is created before or after the UDP turn port. |
| 616 EXPECT_EQ(2U, candidates_.size()); |
| 617 // There will only be 2 candidates in |ready_candidates| because it only |
| 618 // includes the candidates in the ready ports. |
| 619 const std::vector<Candidate>& ready_candidates = |
| 620 session_->ReadyCandidates(); |
| 621 EXPECT_EQ(2U, ready_candidates.size()); |
| 622 EXPECT_PRED4(HasCandidate, ready_candidates, "local", "udp", kClientAddr); |
| 623 EXPECT_PRED4(HasCandidate, ready_candidates, "relay", "udp", |
| 624 rtc::SocketAddress(kTurnUdpExtAddr.ipaddr(), 0)); |
| 625 } |
| 626 |
594 void TestEachInterfaceHasItsOwnTurnPorts() { | 627 void TestEachInterfaceHasItsOwnTurnPorts() { |
595 turn_server_.AddInternalSocket(kTurnTcpIntAddr, PROTO_TCP); | 628 turn_server_.AddInternalSocket(kTurnTcpIntAddr, PROTO_TCP); |
596 turn_server_.AddInternalSocket(kTurnUdpIntIPv6Addr, PROTO_UDP); | 629 turn_server_.AddInternalSocket(kTurnUdpIntIPv6Addr, PROTO_UDP); |
597 turn_server_.AddInternalSocket(kTurnTcpIntIPv6Addr, PROTO_TCP); | 630 turn_server_.AddInternalSocket(kTurnTcpIntIPv6Addr, PROTO_TCP); |
598 // Add two interfaces both having IPv4 and IPv6 addresses. | 631 // Add two interfaces both having IPv4 and IPv6 addresses. |
599 AddInterface(kClientAddr, "net1", rtc::ADAPTER_TYPE_WIFI); | 632 AddInterface(kClientAddr, "net1", rtc::ADAPTER_TYPE_WIFI); |
600 AddInterface(kClientIPv6Addr, "net1", rtc::ADAPTER_TYPE_WIFI); | 633 AddInterface(kClientIPv6Addr, "net1", rtc::ADAPTER_TYPE_WIFI); |
601 AddInterface(kClientAddr2, "net2", rtc::ADAPTER_TYPE_CELLULAR); | 634 AddInterface(kClientAddr2, "net2", rtc::ADAPTER_TYPE_CELLULAR); |
602 AddInterface(kClientIPv6Addr2, "net2", rtc::ADAPTER_TYPE_CELLULAR); | 635 AddInterface(kClientIPv6Addr2, "net2", rtc::ADAPTER_TYPE_CELLULAR); |
603 allocator_.reset(new BasicPortAllocator(&network_manager_)); | 636 allocator_.reset(new BasicPortAllocator(&network_manager_)); |
604 allocator_->SetConfiguration(allocator_->stun_servers(), | 637 allocator_->SetConfiguration(allocator_->stun_servers(), |
605 allocator_->turn_servers(), 0, true); | 638 allocator_->turn_servers(), 0, true); |
606 // Have both UDP/TCP and IPv4/IPv6 TURN ports. | 639 // Have both UDP/TCP and IPv4/IPv6 TURN ports. |
607 AddTurnServers(kTurnUdpIntAddr, kTurnTcpIntAddr); | 640 AddTurnServers(kTurnUdpIntAddr, kTurnTcpIntAddr); |
608 AddTurnServers(kTurnUdpIntIPv6Addr, kTurnTcpIntIPv6Addr); | 641 AddTurnServers(kTurnUdpIntIPv6Addr, kTurnTcpIntIPv6Addr); |
609 | 642 |
610 allocator_->set_step_delay(kMinimumStepDelay); | 643 allocator_->set_step_delay(kMinimumStepDelay); |
611 allocator_->set_flags(allocator().flags() | | 644 allocator_->set_flags(allocator().flags() | |
612 PORTALLOCATOR_ENABLE_SHARED_SOCKET | | 645 PORTALLOCATOR_ENABLE_SHARED_SOCKET | |
613 PORTALLOCATOR_ENABLE_IPV6); | 646 PORTALLOCATOR_ENABLE_IPV6); |
614 EXPECT_TRUE(CreateSession(ICE_CANDIDATE_COMPONENT_RTP)); | 647 EXPECT_TRUE(CreateSession(ICE_CANDIDATE_COMPONENT_RTP)); |
615 session_->StartGettingPorts(); | 648 session_->StartGettingPorts(); |
616 EXPECT_TRUE_WAIT(candidate_allocation_done_, kDefaultAllocationTimeout); | 649 EXPECT_TRUE_SIMULATED_WAIT(candidate_allocation_done_, |
| 650 kDefaultAllocationTimeout, fake_clock); |
617 // 10 ports (4 STUN and 1 TURN ports on each interface) will be ready to | 651 // 10 ports (4 STUN and 1 TURN ports on each interface) will be ready to |
618 // use. | 652 // use. |
619 EXPECT_EQ(10U, session_->ReadyPorts().size()); | 653 EXPECT_EQ(10U, session_->ReadyPorts().size()); |
620 EXPECT_EQ(10U, ports_.size()); | 654 EXPECT_EQ(10U, ports_.size()); |
621 EXPECT_EQ(1, CountPorts(ports_, "local", PROTO_UDP, kClientAddr)); | 655 EXPECT_EQ(1, CountPorts(ports_, "local", PROTO_UDP, kClientAddr)); |
622 EXPECT_EQ(1, CountPorts(ports_, "local", PROTO_UDP, kClientAddr2)); | 656 EXPECT_EQ(1, CountPorts(ports_, "local", PROTO_UDP, kClientAddr2)); |
623 EXPECT_EQ(1, CountPorts(ports_, "local", PROTO_UDP, kClientIPv6Addr)); | 657 EXPECT_EQ(1, CountPorts(ports_, "local", PROTO_UDP, kClientIPv6Addr)); |
624 EXPECT_EQ(1, CountPorts(ports_, "local", PROTO_UDP, kClientIPv6Addr2)); | 658 EXPECT_EQ(1, CountPorts(ports_, "local", PROTO_UDP, kClientIPv6Addr2)); |
625 EXPECT_EQ(1, CountPorts(ports_, "local", PROTO_TCP, kClientAddr)); | 659 EXPECT_EQ(1, CountPorts(ports_, "local", PROTO_TCP, kClientAddr)); |
626 EXPECT_EQ(1, CountPorts(ports_, "local", PROTO_TCP, kClientAddr2)); | 660 EXPECT_EQ(1, CountPorts(ports_, "local", PROTO_TCP, kClientAddr2)); |
(...skipping 16 matching lines...) Expand all Loading... |
643 kClientIPv6Addr2); | 677 kClientIPv6Addr2); |
644 EXPECT_PRED4(HasCandidate, ready_candidates, "local", "tcp", kClientAddr); | 678 EXPECT_PRED4(HasCandidate, ready_candidates, "local", "tcp", kClientAddr); |
645 EXPECT_PRED4(HasCandidate, ready_candidates, "local", "tcp", kClientAddr2); | 679 EXPECT_PRED4(HasCandidate, ready_candidates, "local", "tcp", kClientAddr2); |
646 EXPECT_PRED4(HasCandidate, ready_candidates, "local", "tcp", | 680 EXPECT_PRED4(HasCandidate, ready_candidates, "local", "tcp", |
647 kClientIPv6Addr); | 681 kClientIPv6Addr); |
648 EXPECT_PRED4(HasCandidate, ready_candidates, "local", "tcp", | 682 EXPECT_PRED4(HasCandidate, ready_candidates, "local", "tcp", |
649 kClientIPv6Addr2); | 683 kClientIPv6Addr2); |
650 EXPECT_PRED4(HasCandidate, ready_candidates, "relay", "udp", | 684 EXPECT_PRED4(HasCandidate, ready_candidates, "relay", "udp", |
651 rtc::SocketAddress(kTurnUdpExtAddr.ipaddr(), 0)); | 685 rtc::SocketAddress(kTurnUdpExtAddr.ipaddr(), 0)); |
652 } | 686 } |
653 | |
654 std::unique_ptr<rtc::PhysicalSocketServer> pss_; | |
655 std::unique_ptr<rtc::VirtualSocketServer> vss_; | |
656 std::unique_ptr<rtc::FirewallSocketServer> fss_; | |
657 rtc::SocketServerScope ss_scope_; | |
658 std::unique_ptr<rtc::NATServer> nat_server_; | |
659 rtc::NATSocketFactory nat_factory_; | |
660 std::unique_ptr<rtc::BasicPacketSocketFactory> nat_socket_factory_; | |
661 std::unique_ptr<TestStunServer> stun_server_; | |
662 TestRelayServer relay_server_; | |
663 TestTurnServer turn_server_; | |
664 rtc::FakeNetworkManager network_manager_; | |
665 std::unique_ptr<BasicPortAllocator> allocator_; | |
666 std::unique_ptr<PortAllocatorSession> session_; | |
667 std::vector<PortInterface*> ports_; | |
668 std::vector<Candidate> candidates_; | |
669 bool candidate_allocation_done_; | |
670 }; | 687 }; |
671 | 688 |
672 // Tests that we can init the port allocator and create a session. | 689 // Tests that we can init the port allocator and create a session. |
673 TEST_F(BasicPortAllocatorTest, TestBasic) { | 690 TEST_F(BasicPortAllocatorTest, TestBasic) { |
674 EXPECT_EQ(&network_manager_, allocator().network_manager()); | 691 EXPECT_EQ(&network_manager_, allocator().network_manager()); |
675 EXPECT_EQ(kStunAddr, *allocator().stun_servers().begin()); | 692 EXPECT_EQ(kStunAddr, *allocator().stun_servers().begin()); |
676 ASSERT_EQ(1u, allocator().turn_servers().size()); | 693 ASSERT_EQ(1u, allocator().turn_servers().size()); |
677 EXPECT_EQ(RELAY_GTURN, allocator().turn_servers()[0].type); | 694 EXPECT_EQ(RELAY_GTURN, allocator().turn_servers()[0].type); |
678 // Empty relay credentials are used for GTURN. | 695 // Empty relay credentials are used for GTURN. |
679 EXPECT_TRUE(allocator().turn_servers()[0].credentials.username.empty()); | 696 EXPECT_TRUE(allocator().turn_servers()[0].credentials.username.empty()); |
(...skipping 15 matching lines...) Expand all Loading... |
695 AddInterface(SocketAddress(IPAddress(0x12345602U), 0), "test_cell0", | 712 AddInterface(SocketAddress(IPAddress(0x12345602U), 0), "test_cell0", |
696 rtc::ADAPTER_TYPE_CELLULAR); | 713 rtc::ADAPTER_TYPE_CELLULAR); |
697 AddInterface(SocketAddress(IPAddress(0x12345603U), 0), "test_vpn0", | 714 AddInterface(SocketAddress(IPAddress(0x12345603U), 0), "test_vpn0", |
698 rtc::ADAPTER_TYPE_VPN); | 715 rtc::ADAPTER_TYPE_VPN); |
699 AddInterface(SocketAddress(IPAddress(0x12345604U), 0), "test_lo", | 716 AddInterface(SocketAddress(IPAddress(0x12345604U), 0), "test_lo", |
700 rtc::ADAPTER_TYPE_LOOPBACK); | 717 rtc::ADAPTER_TYPE_LOOPBACK); |
701 EXPECT_TRUE(CreateSession(ICE_CANDIDATE_COMPONENT_RTP)); | 718 EXPECT_TRUE(CreateSession(ICE_CANDIDATE_COMPONENT_RTP)); |
702 session_->set_flags(PORTALLOCATOR_DISABLE_STUN | PORTALLOCATOR_DISABLE_RELAY | | 719 session_->set_flags(PORTALLOCATOR_DISABLE_STUN | PORTALLOCATOR_DISABLE_RELAY | |
703 PORTALLOCATOR_DISABLE_TCP); | 720 PORTALLOCATOR_DISABLE_TCP); |
704 session_->StartGettingPorts(); | 721 session_->StartGettingPorts(); |
705 EXPECT_TRUE_WAIT(candidate_allocation_done_, kDefaultAllocationTimeout); | 722 EXPECT_TRUE_SIMULATED_WAIT(candidate_allocation_done_, |
| 723 kDefaultAllocationTimeout, fake_clock); |
706 EXPECT_EQ(4U, candidates_.size()); | 724 EXPECT_EQ(4U, candidates_.size()); |
707 for (Candidate candidate : candidates_) { | 725 for (Candidate candidate : candidates_) { |
708 EXPECT_LT(candidate.address().ip(), 0x12345604U); | 726 EXPECT_LT(candidate.address().ip(), 0x12345604U); |
709 } | 727 } |
710 } | 728 } |
711 | 729 |
712 TEST_F(BasicPortAllocatorTest, TestIgnoreNetworksAccordingToIgnoreMask) { | 730 TEST_F(BasicPortAllocatorTest, TestIgnoreNetworksAccordingToIgnoreMask) { |
713 AddInterface(SocketAddress(IPAddress(0x12345600U), 0), "test_eth0", | 731 AddInterface(SocketAddress(IPAddress(0x12345600U), 0), "test_eth0", |
714 rtc::ADAPTER_TYPE_ETHERNET); | 732 rtc::ADAPTER_TYPE_ETHERNET); |
715 AddInterface(SocketAddress(IPAddress(0x12345601U), 0), "test_wlan0", | 733 AddInterface(SocketAddress(IPAddress(0x12345601U), 0), "test_wlan0", |
716 rtc::ADAPTER_TYPE_WIFI); | 734 rtc::ADAPTER_TYPE_WIFI); |
717 AddInterface(SocketAddress(IPAddress(0x12345602U), 0), "test_cell0", | 735 AddInterface(SocketAddress(IPAddress(0x12345602U), 0), "test_cell0", |
718 rtc::ADAPTER_TYPE_CELLULAR); | 736 rtc::ADAPTER_TYPE_CELLULAR); |
719 allocator_->SetNetworkIgnoreMask(rtc::ADAPTER_TYPE_ETHERNET | | 737 allocator_->SetNetworkIgnoreMask(rtc::ADAPTER_TYPE_ETHERNET | |
720 rtc::ADAPTER_TYPE_LOOPBACK | | 738 rtc::ADAPTER_TYPE_LOOPBACK | |
721 rtc::ADAPTER_TYPE_WIFI); | 739 rtc::ADAPTER_TYPE_WIFI); |
722 EXPECT_TRUE(CreateSession(ICE_CANDIDATE_COMPONENT_RTP)); | 740 EXPECT_TRUE(CreateSession(ICE_CANDIDATE_COMPONENT_RTP)); |
723 session_->set_flags(PORTALLOCATOR_DISABLE_STUN | PORTALLOCATOR_DISABLE_RELAY | | 741 session_->set_flags(PORTALLOCATOR_DISABLE_STUN | PORTALLOCATOR_DISABLE_RELAY | |
724 PORTALLOCATOR_DISABLE_TCP); | 742 PORTALLOCATOR_DISABLE_TCP); |
725 session_->StartGettingPorts(); | 743 session_->StartGettingPorts(); |
726 EXPECT_TRUE_WAIT(candidate_allocation_done_, kDefaultAllocationTimeout); | 744 EXPECT_TRUE_SIMULATED_WAIT(candidate_allocation_done_, |
| 745 kDefaultAllocationTimeout, fake_clock); |
727 EXPECT_EQ(1U, candidates_.size()); | 746 EXPECT_EQ(1U, candidates_.size()); |
728 EXPECT_EQ(0x12345602U, candidates_[0].address().ip()); | 747 EXPECT_EQ(0x12345602U, candidates_[0].address().ip()); |
729 } | 748 } |
730 | 749 |
731 // Test that high cost networks are filtered if the flag | 750 // Test that high cost networks are filtered if the flag |
732 // PORTALLOCATOR_DISABLE_COSTLY_NETWORKS is set. | 751 // PORTALLOCATOR_DISABLE_COSTLY_NETWORKS is set. |
733 TEST_F(BasicPortAllocatorTest, TestGatherLowCostNetworkOnly) { | 752 TEST_F(BasicPortAllocatorTest, TestGatherLowCostNetworkOnly) { |
734 SocketAddress addr_wifi(IPAddress(0x12345600U), 0); | 753 SocketAddress addr_wifi(IPAddress(0x12345600U), 0); |
735 SocketAddress addr_cellular(IPAddress(0x12345601U), 0); | 754 SocketAddress addr_cellular(IPAddress(0x12345601U), 0); |
736 SocketAddress addr_unknown1(IPAddress(0x12345602U), 0); | 755 SocketAddress addr_unknown1(IPAddress(0x12345602U), 0); |
737 SocketAddress addr_unknown2(IPAddress(0x12345603U), 0); | 756 SocketAddress addr_unknown2(IPAddress(0x12345603U), 0); |
738 // If both Wi-Fi and cellular interfaces are present, only gather on the Wi-Fi | 757 // If both Wi-Fi and cellular interfaces are present, only gather on the Wi-Fi |
739 // interface. | 758 // interface. |
740 AddInterface(addr_wifi, "test_wlan0", rtc::ADAPTER_TYPE_WIFI); | 759 AddInterface(addr_wifi, "test_wlan0", rtc::ADAPTER_TYPE_WIFI); |
741 AddInterface(addr_cellular, "test_cell0", rtc::ADAPTER_TYPE_CELLULAR); | 760 AddInterface(addr_cellular, "test_cell0", rtc::ADAPTER_TYPE_CELLULAR); |
742 allocator().set_flags(cricket::PORTALLOCATOR_DISABLE_STUN | | 761 allocator().set_flags(cricket::PORTALLOCATOR_DISABLE_STUN | |
743 cricket::PORTALLOCATOR_DISABLE_RELAY | | 762 cricket::PORTALLOCATOR_DISABLE_RELAY | |
744 cricket::PORTALLOCATOR_DISABLE_TCP | | 763 cricket::PORTALLOCATOR_DISABLE_TCP | |
745 cricket::PORTALLOCATOR_DISABLE_COSTLY_NETWORKS); | 764 cricket::PORTALLOCATOR_DISABLE_COSTLY_NETWORKS); |
746 EXPECT_TRUE(CreateSession(cricket::ICE_CANDIDATE_COMPONENT_RTP)); | 765 EXPECT_TRUE(CreateSession(cricket::ICE_CANDIDATE_COMPONENT_RTP)); |
747 session_->StartGettingPorts(); | 766 session_->StartGettingPorts(); |
748 EXPECT_TRUE_WAIT(candidate_allocation_done_, kDefaultAllocationTimeout); | 767 EXPECT_TRUE_SIMULATED_WAIT(candidate_allocation_done_, |
| 768 kDefaultAllocationTimeout, fake_clock); |
749 EXPECT_EQ(1U, candidates_.size()); | 769 EXPECT_EQ(1U, candidates_.size()); |
750 EXPECT_TRUE(addr_wifi.EqualIPs(candidates_[0].address())); | 770 EXPECT_TRUE(addr_wifi.EqualIPs(candidates_[0].address())); |
751 | 771 |
752 // If both cellular and unknown interfaces are present, only gather on the | 772 // If both cellular and unknown interfaces are present, only gather on the |
753 // unknown interfaces. | 773 // unknown interfaces. |
754 candidates_.clear(); | 774 candidates_.clear(); |
755 candidate_allocation_done_ = false; | 775 candidate_allocation_done_ = false; |
756 RemoveInterface(addr_wifi); | 776 RemoveInterface(addr_wifi); |
757 AddInterface(addr_unknown1, "test_unknown0", rtc::ADAPTER_TYPE_UNKNOWN); | 777 AddInterface(addr_unknown1, "test_unknown0", rtc::ADAPTER_TYPE_UNKNOWN); |
758 AddInterface(addr_unknown2, "test_unknown1", rtc::ADAPTER_TYPE_UNKNOWN); | 778 AddInterface(addr_unknown2, "test_unknown1", rtc::ADAPTER_TYPE_UNKNOWN); |
759 session_->StartGettingPorts(); | 779 session_->StartGettingPorts(); |
760 EXPECT_TRUE_WAIT(candidate_allocation_done_, kDefaultAllocationTimeout); | 780 EXPECT_TRUE_SIMULATED_WAIT(candidate_allocation_done_, |
| 781 kDefaultAllocationTimeout, fake_clock); |
761 EXPECT_EQ(2U, candidates_.size()); | 782 EXPECT_EQ(2U, candidates_.size()); |
762 EXPECT_TRUE((addr_unknown1.EqualIPs(candidates_[0].address()) && | 783 EXPECT_TRUE((addr_unknown1.EqualIPs(candidates_[0].address()) && |
763 addr_unknown2.EqualIPs(candidates_[1].address())) || | 784 addr_unknown2.EqualIPs(candidates_[1].address())) || |
764 (addr_unknown1.EqualIPs(candidates_[1].address()) && | 785 (addr_unknown1.EqualIPs(candidates_[1].address()) && |
765 addr_unknown2.EqualIPs(candidates_[0].address()))); | 786 addr_unknown2.EqualIPs(candidates_[0].address()))); |
766 | 787 |
767 // If Wi-Fi, cellular, unknown interfaces are all present, only gather on the | 788 // If Wi-Fi, cellular, unknown interfaces are all present, only gather on the |
768 // Wi-Fi interface. | 789 // Wi-Fi interface. |
769 candidates_.clear(); | 790 candidates_.clear(); |
770 candidate_allocation_done_ = false; | 791 candidate_allocation_done_ = false; |
771 AddInterface(addr_wifi, "test_wlan0", rtc::ADAPTER_TYPE_WIFI); | 792 AddInterface(addr_wifi, "test_wlan0", rtc::ADAPTER_TYPE_WIFI); |
772 session_->StartGettingPorts(); | 793 session_->StartGettingPorts(); |
773 EXPECT_TRUE_WAIT(candidate_allocation_done_, kDefaultAllocationTimeout); | 794 EXPECT_TRUE_SIMULATED_WAIT(candidate_allocation_done_, |
| 795 kDefaultAllocationTimeout, fake_clock); |
774 EXPECT_EQ(1U, candidates_.size()); | 796 EXPECT_EQ(1U, candidates_.size()); |
775 EXPECT_TRUE(addr_wifi.EqualIPs(candidates_[0].address())); | 797 EXPECT_TRUE(addr_wifi.EqualIPs(candidates_[0].address())); |
776 } | 798 } |
777 | 799 |
778 // Test that we could use loopback interface as host candidate. | 800 // Test that we could use loopback interface as host candidate. |
779 TEST_F(BasicPortAllocatorTest, TestLoopbackNetworkInterface) { | 801 TEST_F(BasicPortAllocatorTest, TestLoopbackNetworkInterface) { |
780 AddInterface(kLoopbackAddr, "test_loopback", rtc::ADAPTER_TYPE_LOOPBACK); | 802 AddInterface(kLoopbackAddr, "test_loopback", rtc::ADAPTER_TYPE_LOOPBACK); |
781 allocator_->SetNetworkIgnoreMask(0); | 803 allocator_->SetNetworkIgnoreMask(0); |
782 EXPECT_TRUE(CreateSession(ICE_CANDIDATE_COMPONENT_RTP)); | 804 EXPECT_TRUE(CreateSession(ICE_CANDIDATE_COMPONENT_RTP)); |
783 session_->set_flags(PORTALLOCATOR_DISABLE_STUN | PORTALLOCATOR_DISABLE_RELAY | | 805 session_->set_flags(PORTALLOCATOR_DISABLE_STUN | PORTALLOCATOR_DISABLE_RELAY | |
784 PORTALLOCATOR_DISABLE_TCP); | 806 PORTALLOCATOR_DISABLE_TCP); |
785 session_->StartGettingPorts(); | 807 session_->StartGettingPorts(); |
786 EXPECT_TRUE_WAIT(candidate_allocation_done_, kDefaultAllocationTimeout); | 808 EXPECT_TRUE_SIMULATED_WAIT(candidate_allocation_done_, |
| 809 kDefaultAllocationTimeout, fake_clock); |
787 EXPECT_EQ(1U, candidates_.size()); | 810 EXPECT_EQ(1U, candidates_.size()); |
788 } | 811 } |
789 | 812 |
790 // Tests that we can get all the desired addresses successfully. | 813 // Tests that we can get all the desired addresses successfully. |
791 TEST_F(BasicPortAllocatorTest, TestGetAllPortsWithMinimumStepDelay) { | 814 TEST_F(BasicPortAllocatorTest, TestGetAllPortsWithMinimumStepDelay) { |
792 AddInterface(kClientAddr); | 815 AddInterface(kClientAddr); |
793 EXPECT_TRUE(CreateSession(ICE_CANDIDATE_COMPONENT_RTP)); | 816 EXPECT_TRUE(CreateSession(ICE_CANDIDATE_COMPONENT_RTP)); |
794 session_->StartGettingPorts(); | 817 session_->StartGettingPorts(); |
795 ASSERT_EQ_WAIT(7U, candidates_.size(), kDefaultAllocationTimeout); | 818 ASSERT_EQ_SIMULATED_WAIT(7U, candidates_.size(), kDefaultAllocationTimeout, |
| 819 fake_clock); |
796 EXPECT_EQ(4U, ports_.size()); | 820 EXPECT_EQ(4U, ports_.size()); |
797 EXPECT_PRED4(HasCandidate, candidates_, "local", "udp", kClientAddr); | 821 EXPECT_PRED4(HasCandidate, candidates_, "local", "udp", kClientAddr); |
798 EXPECT_PRED4(HasCandidate, candidates_, "stun", "udp", kClientAddr); | 822 EXPECT_PRED4(HasCandidate, candidates_, "stun", "udp", kClientAddr); |
799 EXPECT_PRED4(HasCandidate, candidates_, "relay", "udp", kRelayUdpIntAddr); | 823 EXPECT_PRED4(HasCandidate, candidates_, "relay", "udp", kRelayUdpIntAddr); |
800 EXPECT_PRED4(HasCandidate, candidates_, "relay", "udp", kRelayUdpExtAddr); | 824 EXPECT_PRED4(HasCandidate, candidates_, "relay", "udp", kRelayUdpExtAddr); |
801 EXPECT_PRED4(HasCandidate, candidates_, "relay", "tcp", kRelayTcpIntAddr); | 825 EXPECT_PRED4(HasCandidate, candidates_, "relay", "tcp", kRelayTcpIntAddr); |
802 EXPECT_PRED4(HasCandidate, candidates_, "local", "tcp", kClientAddr); | 826 EXPECT_PRED4(HasCandidate, candidates_, "local", "tcp", kClientAddr); |
803 EXPECT_PRED4(HasCandidate, candidates_, "relay", "ssltcp", | 827 EXPECT_PRED4(HasCandidate, candidates_, "relay", "ssltcp", |
804 kRelaySslTcpIntAddr); | 828 kRelaySslTcpIntAddr); |
805 EXPECT_TRUE(candidate_allocation_done_); | 829 EXPECT_TRUE(candidate_allocation_done_); |
806 } | 830 } |
807 | 831 |
808 // Test that when the same network interface is brought down and up, the | 832 // Test that when the same network interface is brought down and up, the |
809 // port allocator session will restart a new allocation sequence if | 833 // port allocator session will restart a new allocation sequence if |
810 // it is not stopped. | 834 // it is not stopped. |
811 TEST_F(BasicPortAllocatorTest, TestSameNetworkDownAndUpWhenSessionNotStopped) { | 835 TEST_F(BasicPortAllocatorTest, TestSameNetworkDownAndUpWhenSessionNotStopped) { |
812 std::string if_name("test_net0"); | 836 std::string if_name("test_net0"); |
813 AddInterface(kClientAddr, if_name); | 837 AddInterface(kClientAddr, if_name); |
814 EXPECT_TRUE(CreateSession(ICE_CANDIDATE_COMPONENT_RTP)); | 838 EXPECT_TRUE(CreateSession(ICE_CANDIDATE_COMPONENT_RTP)); |
815 session_->StartGettingPorts(); | 839 session_->StartGettingPorts(); |
816 ASSERT_EQ_WAIT(7U, candidates_.size(), kDefaultAllocationTimeout); | 840 ASSERT_EQ_SIMULATED_WAIT(7U, candidates_.size(), kDefaultAllocationTimeout, |
| 841 fake_clock); |
817 EXPECT_EQ(4U, ports_.size()); | 842 EXPECT_EQ(4U, ports_.size()); |
818 EXPECT_TRUE(candidate_allocation_done_); | 843 EXPECT_TRUE(candidate_allocation_done_); |
819 candidate_allocation_done_ = false; | 844 candidate_allocation_done_ = false; |
820 candidates_.clear(); | 845 candidates_.clear(); |
821 ports_.clear(); | 846 ports_.clear(); |
822 | 847 |
823 RemoveInterface(kClientAddr); | 848 RemoveInterface(kClientAddr); |
824 ASSERT_EQ_WAIT(0U, candidates_.size(), kDefaultAllocationTimeout); | 849 ASSERT_EQ_SIMULATED_WAIT(0U, candidates_.size(), kDefaultAllocationTimeout, |
| 850 fake_clock); |
825 EXPECT_EQ(0U, ports_.size()); | 851 EXPECT_EQ(0U, ports_.size()); |
826 EXPECT_FALSE(candidate_allocation_done_); | 852 EXPECT_FALSE(candidate_allocation_done_); |
827 | 853 |
828 // When the same interfaces are added again, new candidates/ports should be | 854 // When the same interfaces are added again, new candidates/ports should be |
829 // generated. | 855 // generated. |
830 AddInterface(kClientAddr, if_name); | 856 AddInterface(kClientAddr, if_name); |
831 ASSERT_EQ_WAIT(7U, candidates_.size(), kDefaultAllocationTimeout); | 857 ASSERT_EQ_SIMULATED_WAIT(7U, candidates_.size(), kDefaultAllocationTimeout, |
| 858 fake_clock); |
832 EXPECT_EQ(4U, ports_.size()); | 859 EXPECT_EQ(4U, ports_.size()); |
833 EXPECT_TRUE(candidate_allocation_done_); | 860 EXPECT_TRUE(candidate_allocation_done_); |
834 } | 861 } |
835 | 862 |
836 // Test that when the same network interface is brought down and up, the | 863 // Test that when the same network interface is brought down and up, the |
837 // port allocator session will not restart a new allocation sequence if | 864 // port allocator session will not restart a new allocation sequence if |
838 // it is stopped. | 865 // it is stopped. |
839 TEST_F(BasicPortAllocatorTest, TestSameNetworkDownAndUpWhenSessionStopped) { | 866 TEST_F(BasicPortAllocatorTest, TestSameNetworkDownAndUpWhenSessionStopped) { |
840 std::string if_name("test_net0"); | 867 std::string if_name("test_net0"); |
841 AddInterface(kClientAddr, if_name); | 868 AddInterface(kClientAddr, if_name); |
842 EXPECT_TRUE(CreateSession(ICE_CANDIDATE_COMPONENT_RTP)); | 869 EXPECT_TRUE(CreateSession(ICE_CANDIDATE_COMPONENT_RTP)); |
843 session_->StartGettingPorts(); | 870 session_->StartGettingPorts(); |
844 ASSERT_EQ_WAIT(7U, candidates_.size(), kDefaultAllocationTimeout); | 871 ASSERT_EQ_SIMULATED_WAIT(7U, candidates_.size(), kDefaultAllocationTimeout, |
| 872 fake_clock); |
845 EXPECT_EQ(4U, ports_.size()); | 873 EXPECT_EQ(4U, ports_.size()); |
846 EXPECT_TRUE(candidate_allocation_done_); | 874 EXPECT_TRUE(candidate_allocation_done_); |
847 session_->StopGettingPorts(); | 875 session_->StopGettingPorts(); |
848 candidates_.clear(); | 876 candidates_.clear(); |
849 ports_.clear(); | 877 ports_.clear(); |
850 | 878 |
851 RemoveInterface(kClientAddr); | 879 RemoveInterface(kClientAddr); |
852 ASSERT_EQ_WAIT(0U, candidates_.size(), kDefaultAllocationTimeout); | 880 ASSERT_EQ_SIMULATED_WAIT(0U, candidates_.size(), kDefaultAllocationTimeout, |
| 881 fake_clock); |
853 EXPECT_EQ(0U, ports_.size()); | 882 EXPECT_EQ(0U, ports_.size()); |
854 | 883 |
855 // When the same interfaces are added again, new candidates/ports should not | 884 // When the same interfaces are added again, new candidates/ports should not |
856 // be generated because the session has stopped. | 885 // be generated because the session has stopped. |
857 AddInterface(kClientAddr, if_name); | 886 AddInterface(kClientAddr, if_name); |
858 ASSERT_EQ_WAIT(0U, candidates_.size(), kDefaultAllocationTimeout); | 887 ASSERT_EQ_SIMULATED_WAIT(0U, candidates_.size(), kDefaultAllocationTimeout, |
| 888 fake_clock); |
859 EXPECT_EQ(0U, ports_.size()); | 889 EXPECT_EQ(0U, ports_.size()); |
860 EXPECT_TRUE(candidate_allocation_done_); | 890 EXPECT_TRUE(candidate_allocation_done_); |
861 } | 891 } |
862 | 892 |
863 // Verify candidates with default step delay of 1sec. | 893 // Verify candidates with default step delay of 1sec. |
864 TEST_F(BasicPortAllocatorTest, TestGetAllPortsWithOneSecondStepDelay) { | 894 TEST_F(BasicPortAllocatorTest, TestGetAllPortsWithOneSecondStepDelay) { |
865 AddInterface(kClientAddr); | 895 AddInterface(kClientAddr); |
866 allocator_->set_step_delay(kDefaultStepDelay); | 896 allocator_->set_step_delay(kDefaultStepDelay); |
867 EXPECT_TRUE(CreateSession(ICE_CANDIDATE_COMPONENT_RTP)); | 897 EXPECT_TRUE(CreateSession(ICE_CANDIDATE_COMPONENT_RTP)); |
868 session_->StartGettingPorts(); | 898 session_->StartGettingPorts(); |
869 ASSERT_EQ_WAIT(2U, candidates_.size(), 1000); | 899 ASSERT_EQ_SIMULATED_WAIT(2U, candidates_.size(), 1000, fake_clock); |
870 EXPECT_EQ(2U, ports_.size()); | 900 EXPECT_EQ(2U, ports_.size()); |
871 ASSERT_EQ_WAIT(4U, candidates_.size(), 2000); | 901 ASSERT_EQ_SIMULATED_WAIT(4U, candidates_.size(), 2000, fake_clock); |
872 EXPECT_EQ(3U, ports_.size()); | 902 EXPECT_EQ(3U, ports_.size()); |
873 EXPECT_PRED4(HasCandidate, candidates_, "relay", "udp", kRelayUdpIntAddr); | 903 EXPECT_PRED4(HasCandidate, candidates_, "relay", "udp", kRelayUdpIntAddr); |
874 EXPECT_PRED4(HasCandidate, candidates_, "relay", "udp", kRelayUdpExtAddr); | 904 EXPECT_PRED4(HasCandidate, candidates_, "relay", "udp", kRelayUdpExtAddr); |
875 ASSERT_EQ_WAIT(6U, candidates_.size(), 1500); | 905 ASSERT_EQ_SIMULATED_WAIT(6U, candidates_.size(), 1500, fake_clock); |
876 EXPECT_PRED4(HasCandidate, candidates_, "relay", "tcp", kRelayTcpIntAddr); | 906 EXPECT_PRED4(HasCandidate, candidates_, "relay", "tcp", kRelayTcpIntAddr); |
877 EXPECT_PRED4(HasCandidate, candidates_, "local", "tcp", kClientAddr); | 907 EXPECT_PRED4(HasCandidate, candidates_, "local", "tcp", kClientAddr); |
878 EXPECT_EQ(4U, ports_.size()); | 908 EXPECT_EQ(4U, ports_.size()); |
879 ASSERT_EQ_WAIT(7U, candidates_.size(), 2000); | 909 ASSERT_EQ_SIMULATED_WAIT(7U, candidates_.size(), 2000, fake_clock); |
880 EXPECT_PRED4(HasCandidate, candidates_, "relay", "ssltcp", | 910 EXPECT_PRED4(HasCandidate, candidates_, "relay", "ssltcp", |
881 kRelaySslTcpIntAddr); | 911 kRelaySslTcpIntAddr); |
882 EXPECT_EQ(4U, ports_.size()); | 912 EXPECT_EQ(4U, ports_.size()); |
883 EXPECT_TRUE(candidate_allocation_done_); | 913 EXPECT_TRUE(candidate_allocation_done_); |
884 // If we Stop gathering now, we shouldn't get a second "done" callback. | 914 // If we Stop gathering now, we shouldn't get a second "done" callback. |
885 session_->StopGettingPorts(); | 915 session_->StopGettingPorts(); |
886 } | 916 } |
887 | 917 |
888 TEST_F(BasicPortAllocatorTest, TestSetupVideoRtpPortsWithNormalSendBuffers) { | 918 TEST_F(BasicPortAllocatorTest, TestSetupVideoRtpPortsWithNormalSendBuffers) { |
889 AddInterface(kClientAddr); | 919 AddInterface(kClientAddr); |
890 EXPECT_TRUE(CreateSession(ICE_CANDIDATE_COMPONENT_RTP, CN_VIDEO)); | 920 EXPECT_TRUE(CreateSession(ICE_CANDIDATE_COMPONENT_RTP, CN_VIDEO)); |
891 session_->StartGettingPorts(); | 921 session_->StartGettingPorts(); |
892 ASSERT_EQ_WAIT(7U, candidates_.size(), kDefaultAllocationTimeout); | 922 ASSERT_EQ_SIMULATED_WAIT(7U, candidates_.size(), kDefaultAllocationTimeout, |
| 923 fake_clock); |
893 EXPECT_TRUE(candidate_allocation_done_); | 924 EXPECT_TRUE(candidate_allocation_done_); |
894 // If we Stop gathering now, we shouldn't get a second "done" callback. | 925 // If we Stop gathering now, we shouldn't get a second "done" callback. |
895 session_->StopGettingPorts(); | 926 session_->StopGettingPorts(); |
896 | 927 |
897 // All ports should have unset send-buffer sizes. | 928 // All ports should have unset send-buffer sizes. |
898 CheckSendBufferSizesOfAllPorts(-1); | 929 CheckSendBufferSizesOfAllPorts(-1); |
899 } | 930 } |
900 | 931 |
901 // Tests that we can get callback after StopGetAllPorts. | 932 // Tests that we can get callback after StopGetAllPorts. |
902 TEST_F(BasicPortAllocatorTest, TestStopGetAllPorts) { | 933 TEST_F(BasicPortAllocatorTest, TestStopGetAllPorts) { |
(...skipping 12 matching lines...) Expand all Loading... |
915 TEST_F(BasicPortAllocatorTest, TestGetAllPortsPortRange) { | 946 TEST_F(BasicPortAllocatorTest, TestGetAllPortsPortRange) { |
916 AddInterface(kClientAddr); | 947 AddInterface(kClientAddr); |
917 // Check that an invalid port range fails. | 948 // Check that an invalid port range fails. |
918 EXPECT_FALSE(SetPortRange(kMaxPort, kMinPort)); | 949 EXPECT_FALSE(SetPortRange(kMaxPort, kMinPort)); |
919 // Check that a null port range succeeds. | 950 // Check that a null port range succeeds. |
920 EXPECT_TRUE(SetPortRange(0, 0)); | 951 EXPECT_TRUE(SetPortRange(0, 0)); |
921 // Check that a valid port range succeeds. | 952 // Check that a valid port range succeeds. |
922 EXPECT_TRUE(SetPortRange(kMinPort, kMaxPort)); | 953 EXPECT_TRUE(SetPortRange(kMinPort, kMaxPort)); |
923 EXPECT_TRUE(CreateSession(ICE_CANDIDATE_COMPONENT_RTP)); | 954 EXPECT_TRUE(CreateSession(ICE_CANDIDATE_COMPONENT_RTP)); |
924 session_->StartGettingPorts(); | 955 session_->StartGettingPorts(); |
925 ASSERT_EQ_WAIT(7U, candidates_.size(), kDefaultAllocationTimeout); | 956 ASSERT_EQ_SIMULATED_WAIT(7U, candidates_.size(), kDefaultAllocationTimeout, |
| 957 fake_clock); |
926 EXPECT_EQ(4U, ports_.size()); | 958 EXPECT_EQ(4U, ports_.size()); |
927 | 959 |
928 int num_nonrelay_candidates = 0; | 960 int num_nonrelay_candidates = 0; |
929 for (const Candidate& candidate : candidates_) { | 961 for (const Candidate& candidate : candidates_) { |
930 // Check the port number for the UDP/STUN/TCP port objects. | 962 // Check the port number for the UDP/STUN/TCP port objects. |
931 if (candidate.type() != RELAY_PORT_TYPE) { | 963 if (candidate.type() != RELAY_PORT_TYPE) { |
932 EXPECT_PRED3(CheckPort, candidate.address(), kMinPort, kMaxPort); | 964 EXPECT_PRED3(CheckPort, candidate.address(), kMinPort, kMaxPort); |
933 ++num_nonrelay_candidates; | 965 ++num_nonrelay_candidates; |
934 } | 966 } |
935 } | 967 } |
(...skipping 12 matching lines...) Expand all Loading... |
948 ResetWithStunServerAndNat(kStunAddr); | 980 ResetWithStunServerAndNat(kStunAddr); |
949 turn_server_.AddInternalSocket(kTurnTcpIntAddr, PROTO_TCP); | 981 turn_server_.AddInternalSocket(kTurnTcpIntAddr, PROTO_TCP); |
950 AddTurnServers(kTurnUdpIntAddr, kTurnTcpIntAddr); | 982 AddTurnServers(kTurnUdpIntAddr, kTurnTcpIntAddr); |
951 AddTurnServers(kTurnUdpIntIPv6Addr, kTurnTcpIntIPv6Addr); | 983 AddTurnServers(kTurnUdpIntIPv6Addr, kTurnTcpIntIPv6Addr); |
952 // Disable IPv6, because our test infrastructure doesn't support having IPv4 | 984 // Disable IPv6, because our test infrastructure doesn't support having IPv4 |
953 // behind a NAT but IPv6 not, or having an IPv6 NAT. | 985 // behind a NAT but IPv6 not, or having an IPv6 NAT. |
954 // TODO(deadbeef): Fix this. | 986 // TODO(deadbeef): Fix this. |
955 network_manager_.set_ipv6_enabled(false); | 987 network_manager_.set_ipv6_enabled(false); |
956 EXPECT_TRUE(CreateSession(ICE_CANDIDATE_COMPONENT_RTP)); | 988 EXPECT_TRUE(CreateSession(ICE_CANDIDATE_COMPONENT_RTP)); |
957 session_->StartGettingPorts(); | 989 session_->StartGettingPorts(); |
958 EXPECT_TRUE_WAIT(candidate_allocation_done_, kDefaultAllocationTimeout); | 990 EXPECT_TRUE_SIMULATED_WAIT(candidate_allocation_done_, |
| 991 kDefaultAllocationTimeout, fake_clock); |
959 EXPECT_EQ(4U, ports_.size()); | 992 EXPECT_EQ(4U, ports_.size()); |
960 EXPECT_EQ(1, CountPorts(ports_, "stun", PROTO_UDP, kAnyAddr)); | 993 EXPECT_EQ(1, CountPorts(ports_, "stun", PROTO_UDP, kAnyAddr)); |
961 EXPECT_EQ(1, CountPorts(ports_, "local", PROTO_TCP, kAnyAddr)); | 994 EXPECT_EQ(1, CountPorts(ports_, "local", PROTO_TCP, kAnyAddr)); |
962 // Two TURN ports, using UDP/TCP for the first hop to the TURN server. | 995 // Two TURN ports, using UDP/TCP for the first hop to the TURN server. |
963 EXPECT_EQ(1, CountPorts(ports_, "relay", PROTO_UDP, kAnyAddr)); | 996 EXPECT_EQ(1, CountPorts(ports_, "relay", PROTO_UDP, kAnyAddr)); |
964 EXPECT_EQ(1, CountPorts(ports_, "relay", PROTO_TCP, kAnyAddr)); | 997 EXPECT_EQ(1, CountPorts(ports_, "relay", PROTO_TCP, kAnyAddr)); |
965 // The "any" address port should be in the signaled ready ports, but the host | 998 // The "any" address port should be in the signaled ready ports, but the host |
966 // candidate for it is useless and shouldn't be signaled. So we only have | 999 // candidate for it is useless and shouldn't be signaled. So we only have |
967 // STUN/TURN candidates. | 1000 // STUN/TURN candidates. |
968 EXPECT_EQ(3U, candidates_.size()); | 1001 EXPECT_EQ(3U, candidates_.size()); |
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1085 turn_server_.AddInternalSocket(kTurnTcpIntAddr, PROTO_TCP); | 1118 turn_server_.AddInternalSocket(kTurnTcpIntAddr, PROTO_TCP); |
1086 AddInterface(kClientAddr); | 1119 AddInterface(kClientAddr); |
1087 ResetWithStunServerAndNat(kStunAddr); | 1120 ResetWithStunServerAndNat(kStunAddr); |
1088 AddTurnServers(kTurnUdpIntAddr, kTurnTcpIntAddr); | 1121 AddTurnServers(kTurnUdpIntAddr, kTurnTcpIntAddr); |
1089 EXPECT_TRUE(CreateSession(ICE_CANDIDATE_COMPONENT_RTP)); | 1122 EXPECT_TRUE(CreateSession(ICE_CANDIDATE_COMPONENT_RTP)); |
1090 session_->set_flags(PORTALLOCATOR_DISABLE_UDP_RELAY | | 1123 session_->set_flags(PORTALLOCATOR_DISABLE_UDP_RELAY | |
1091 PORTALLOCATOR_DISABLE_UDP | PORTALLOCATOR_DISABLE_STUN | | 1124 PORTALLOCATOR_DISABLE_UDP | PORTALLOCATOR_DISABLE_STUN | |
1092 PORTALLOCATOR_ENABLE_SHARED_SOCKET); | 1125 PORTALLOCATOR_ENABLE_SHARED_SOCKET); |
1093 | 1126 |
1094 session_->StartGettingPorts(); | 1127 session_->StartGettingPorts(); |
1095 EXPECT_TRUE_WAIT(candidate_allocation_done_, kDefaultAllocationTimeout); | 1128 EXPECT_TRUE_SIMULATED_WAIT(candidate_allocation_done_, |
| 1129 kDefaultAllocationTimeout, fake_clock); |
1096 | 1130 |
1097 // Expect to see 2 ports and 2 candidates - TURN/TCP and TCP ports, TCP and | 1131 // Expect to see 2 ports and 2 candidates - TURN/TCP and TCP ports, TCP and |
1098 // TURN/TCP candidates. | 1132 // TURN/TCP candidates. |
1099 EXPECT_EQ(2U, ports_.size()); | 1133 EXPECT_EQ(2U, ports_.size()); |
1100 EXPECT_EQ(2U, candidates_.size()); | 1134 EXPECT_EQ(2U, candidates_.size()); |
1101 Candidate turn_candidate; | 1135 Candidate turn_candidate; |
1102 EXPECT_PRED5(FindCandidate, candidates_, "relay", "udp", kTurnUdpExtAddr, | 1136 EXPECT_PRED5(FindCandidate, candidates_, "relay", "udp", kTurnUdpExtAddr, |
1103 &turn_candidate); | 1137 &turn_candidate); |
1104 // The TURN candidate should use TCP to contact the TURN server. | 1138 // The TURN candidate should use TCP to contact the TURN server. |
1105 EXPECT_EQ(TCP_PROTOCOL_NAME, turn_candidate.relay_protocol()); | 1139 EXPECT_EQ(TCP_PROTOCOL_NAME, turn_candidate.relay_protocol()); |
1106 EXPECT_PRED4(HasCandidate, candidates_, "local", "tcp", kClientAddr); | 1140 EXPECT_PRED4(HasCandidate, candidates_, "local", "tcp", kClientAddr); |
1107 } | 1141 } |
1108 | 1142 |
1109 // Disable for asan, see | 1143 // Disable for asan, see |
1110 // https://code.google.com/p/webrtc/issues/detail?id=4743 for details. | 1144 // https://code.google.com/p/webrtc/issues/detail?id=4743 for details. |
1111 #if !defined(ADDRESS_SANITIZER) | 1145 #if !defined(ADDRESS_SANITIZER) |
1112 | 1146 |
1113 // Test that we can get OnCandidatesAllocationDone callback when all the ports | 1147 // Test that we can get OnCandidatesAllocationDone callback when all the ports |
1114 // are disabled. | 1148 // are disabled. |
1115 TEST_F(BasicPortAllocatorTest, TestDisableAllPorts) { | 1149 TEST_F(BasicPortAllocatorTest, TestDisableAllPorts) { |
1116 AddInterface(kClientAddr); | 1150 AddInterface(kClientAddr); |
1117 EXPECT_TRUE(CreateSession(ICE_CANDIDATE_COMPONENT_RTP)); | 1151 EXPECT_TRUE(CreateSession(ICE_CANDIDATE_COMPONENT_RTP)); |
1118 session_->set_flags(PORTALLOCATOR_DISABLE_UDP | PORTALLOCATOR_DISABLE_STUN | | 1152 session_->set_flags(PORTALLOCATOR_DISABLE_UDP | PORTALLOCATOR_DISABLE_STUN | |
1119 PORTALLOCATOR_DISABLE_RELAY | PORTALLOCATOR_DISABLE_TCP); | 1153 PORTALLOCATOR_DISABLE_RELAY | PORTALLOCATOR_DISABLE_TCP); |
1120 session_->StartGettingPorts(); | 1154 session_->StartGettingPorts(); |
1121 rtc::Thread::Current()->ProcessMessages(100); | 1155 EXPECT_TRUE_SIMULATED_WAIT(candidate_allocation_done_, 1000, fake_clock); |
1122 EXPECT_EQ(0U, candidates_.size()); | 1156 EXPECT_EQ(0U, candidates_.size()); |
1123 EXPECT_TRUE(candidate_allocation_done_); | |
1124 } | 1157 } |
1125 | 1158 |
1126 // Test that we don't crash or malfunction if we can't create UDP sockets. | 1159 // Test that we don't crash or malfunction if we can't create UDP sockets. |
1127 TEST_F(BasicPortAllocatorTest, TestGetAllPortsNoUdpSockets) { | 1160 TEST_F(BasicPortAllocatorTest, TestGetAllPortsNoUdpSockets) { |
1128 AddInterface(kClientAddr); | 1161 AddInterface(kClientAddr); |
1129 fss_->set_udp_sockets_enabled(false); | 1162 fss_->set_udp_sockets_enabled(false); |
1130 EXPECT_TRUE(CreateSession(1)); | 1163 EXPECT_TRUE(CreateSession(1)); |
1131 session_->StartGettingPorts(); | 1164 session_->StartGettingPorts(); |
1132 ASSERT_EQ_WAIT(5U, candidates_.size(), kDefaultAllocationTimeout); | 1165 ASSERT_EQ_SIMULATED_WAIT(5U, candidates_.size(), kDefaultAllocationTimeout, |
| 1166 fake_clock); |
1133 EXPECT_EQ(2U, ports_.size()); | 1167 EXPECT_EQ(2U, ports_.size()); |
1134 EXPECT_PRED4(HasCandidate, candidates_, "relay", "udp", kRelayUdpIntAddr); | 1168 EXPECT_PRED4(HasCandidate, candidates_, "relay", "udp", kRelayUdpIntAddr); |
1135 EXPECT_PRED4(HasCandidate, candidates_, "relay", "udp", kRelayUdpExtAddr); | 1169 EXPECT_PRED4(HasCandidate, candidates_, "relay", "udp", kRelayUdpExtAddr); |
1136 EXPECT_PRED4(HasCandidate, candidates_, "relay", "tcp", kRelayTcpIntAddr); | 1170 EXPECT_PRED4(HasCandidate, candidates_, "relay", "tcp", kRelayTcpIntAddr); |
1137 EXPECT_PRED4(HasCandidate, candidates_, "local", "tcp", kClientAddr); | 1171 EXPECT_PRED4(HasCandidate, candidates_, "local", "tcp", kClientAddr); |
1138 EXPECT_PRED4(HasCandidate, candidates_, "relay", "ssltcp", | 1172 EXPECT_PRED4(HasCandidate, candidates_, "relay", "ssltcp", |
1139 kRelaySslTcpIntAddr); | 1173 kRelaySslTcpIntAddr); |
1140 EXPECT_TRUE(candidate_allocation_done_); | 1174 EXPECT_TRUE(candidate_allocation_done_); |
1141 } | 1175 } |
1142 | 1176 |
1143 #endif // if !defined(ADDRESS_SANITIZER) | 1177 #endif // if !defined(ADDRESS_SANITIZER) |
1144 | 1178 |
1145 // Test that we don't crash or malfunction if we can't create UDP sockets or | 1179 // Test that we don't crash or malfunction if we can't create UDP sockets or |
1146 // listen on TCP sockets. We still give out a local TCP address, since | 1180 // listen on TCP sockets. We still give out a local TCP address, since |
1147 // apparently this is needed for the remote side to accept our connection. | 1181 // apparently this is needed for the remote side to accept our connection. |
1148 TEST_F(BasicPortAllocatorTest, TestGetAllPortsNoUdpSocketsNoTcpListen) { | 1182 TEST_F(BasicPortAllocatorTest, TestGetAllPortsNoUdpSocketsNoTcpListen) { |
1149 AddInterface(kClientAddr); | 1183 AddInterface(kClientAddr); |
1150 fss_->set_udp_sockets_enabled(false); | 1184 fss_->set_udp_sockets_enabled(false); |
1151 fss_->set_tcp_listen_enabled(false); | 1185 fss_->set_tcp_listen_enabled(false); |
1152 EXPECT_TRUE(CreateSession(1)); | 1186 EXPECT_TRUE(CreateSession(1)); |
1153 session_->StartGettingPorts(); | 1187 session_->StartGettingPorts(); |
1154 ASSERT_EQ_WAIT(5U, candidates_.size(), kDefaultAllocationTimeout); | 1188 ASSERT_EQ_SIMULATED_WAIT(5U, candidates_.size(), kDefaultAllocationTimeout, |
| 1189 fake_clock); |
1155 EXPECT_EQ(2U, ports_.size()); | 1190 EXPECT_EQ(2U, ports_.size()); |
1156 EXPECT_PRED4(HasCandidate, candidates_, "relay", "udp", kRelayUdpIntAddr); | 1191 EXPECT_PRED4(HasCandidate, candidates_, "relay", "udp", kRelayUdpIntAddr); |
1157 EXPECT_PRED4(HasCandidate, candidates_, "relay", "udp", kRelayUdpExtAddr); | 1192 EXPECT_PRED4(HasCandidate, candidates_, "relay", "udp", kRelayUdpExtAddr); |
1158 EXPECT_PRED4(HasCandidate, candidates_, "relay", "tcp", kRelayTcpIntAddr); | 1193 EXPECT_PRED4(HasCandidate, candidates_, "relay", "tcp", kRelayTcpIntAddr); |
1159 EXPECT_PRED4(HasCandidate, candidates_, "local", "tcp", kClientAddr); | 1194 EXPECT_PRED4(HasCandidate, candidates_, "local", "tcp", kClientAddr); |
1160 EXPECT_PRED4(HasCandidate, candidates_, "relay", "ssltcp", | 1195 EXPECT_PRED4(HasCandidate, candidates_, "relay", "ssltcp", |
1161 kRelaySslTcpIntAddr); | 1196 kRelaySslTcpIntAddr); |
1162 EXPECT_TRUE(candidate_allocation_done_); | 1197 EXPECT_TRUE(candidate_allocation_done_); |
1163 } | 1198 } |
1164 | 1199 |
(...skipping 10 matching lines...) Expand all Loading... |
1175 // In case of Relay, ports creation will succeed but sockets will fail. | 1210 // In case of Relay, ports creation will succeed but sockets will fail. |
1176 // There is no error reporting from RelayEntry to handle this failure. | 1211 // There is no error reporting from RelayEntry to handle this failure. |
1177 } | 1212 } |
1178 | 1213 |
1179 // Testing STUN timeout. | 1214 // Testing STUN timeout. |
1180 TEST_F(BasicPortAllocatorTest, TestGetAllPortsNoUdpAllowed) { | 1215 TEST_F(BasicPortAllocatorTest, TestGetAllPortsNoUdpAllowed) { |
1181 fss_->AddRule(false, rtc::FP_UDP, rtc::FD_ANY, kClientAddr); | 1216 fss_->AddRule(false, rtc::FP_UDP, rtc::FD_ANY, kClientAddr); |
1182 AddInterface(kClientAddr); | 1217 AddInterface(kClientAddr); |
1183 EXPECT_TRUE(CreateSession(ICE_CANDIDATE_COMPONENT_RTP)); | 1218 EXPECT_TRUE(CreateSession(ICE_CANDIDATE_COMPONENT_RTP)); |
1184 session_->StartGettingPorts(); | 1219 session_->StartGettingPorts(); |
1185 EXPECT_EQ_WAIT(2U, candidates_.size(), kDefaultAllocationTimeout); | 1220 EXPECT_EQ_SIMULATED_WAIT(2U, candidates_.size(), kDefaultAllocationTimeout, |
| 1221 fake_clock); |
1186 EXPECT_EQ(2U, ports_.size()); | 1222 EXPECT_EQ(2U, ports_.size()); |
1187 EXPECT_PRED4(HasCandidate, candidates_, "local", "udp", kClientAddr); | 1223 EXPECT_PRED4(HasCandidate, candidates_, "local", "udp", kClientAddr); |
1188 EXPECT_PRED4(HasCandidate, candidates_, "local", "tcp", kClientAddr); | 1224 EXPECT_PRED4(HasCandidate, candidates_, "local", "tcp", kClientAddr); |
1189 // RelayPort connection timeout is 3sec. TCP connection with RelayServer | 1225 // RelayPort connection timeout is 3sec. TCP connection with RelayServer |
1190 // will be tried after 3 seconds. | 1226 // will be tried after about 3 seconds. |
1191 // TODO(deadbeef): Use simulated clock here, waiting for exactly 3 seconds. | 1227 EXPECT_EQ_SIMULATED_WAIT(6U, candidates_.size(), 3500, fake_clock); |
1192 EXPECT_EQ_WAIT(6U, candidates_.size(), kStunTimeoutMs); | |
1193 EXPECT_EQ(3U, ports_.size()); | 1228 EXPECT_EQ(3U, ports_.size()); |
1194 EXPECT_PRED4(HasCandidate, candidates_, "relay", "udp", kRelayUdpIntAddr); | 1229 EXPECT_PRED4(HasCandidate, candidates_, "relay", "udp", kRelayUdpIntAddr); |
1195 EXPECT_PRED4(HasCandidate, candidates_, "relay", "tcp", kRelayTcpIntAddr); | 1230 EXPECT_PRED4(HasCandidate, candidates_, "relay", "tcp", kRelayTcpIntAddr); |
1196 EXPECT_PRED4(HasCandidate, candidates_, "relay", "ssltcp", | 1231 EXPECT_PRED4(HasCandidate, candidates_, "relay", "ssltcp", |
1197 kRelaySslTcpIntAddr); | 1232 kRelaySslTcpIntAddr); |
1198 EXPECT_PRED4(HasCandidate, candidates_, "relay", "udp", kRelayUdpExtAddr); | 1233 EXPECT_PRED4(HasCandidate, candidates_, "relay", "udp", kRelayUdpExtAddr); |
1199 // Stun Timeout is 9.5sec. | 1234 // We wait at least for a full STUN timeout, which is currently 9.5 |
1200 // TODO(deadbeef): Use simulated clock here, waiting exactly 6.5 seconds. | 1235 // seconds. But since 3-3.5 seconds already passed (see above), we |
1201 EXPECT_TRUE_WAIT(candidate_allocation_done_, kStunTimeoutMs); | 1236 // only need 6.5 more seconds. |
| 1237 EXPECT_TRUE_SIMULATED_WAIT(candidate_allocation_done_, 6500, fake_clock); |
1202 } | 1238 } |
1203 | 1239 |
1204 TEST_F(BasicPortAllocatorTest, TestCandidatePriorityOfMultipleInterfaces) { | 1240 TEST_F(BasicPortAllocatorTest, TestCandidatePriorityOfMultipleInterfaces) { |
1205 AddInterface(kClientAddr); | 1241 AddInterface(kClientAddr); |
1206 AddInterface(kClientAddr2); | 1242 AddInterface(kClientAddr2); |
1207 // Allocating only host UDP ports. This is done purely for testing | 1243 // Allocating only host UDP ports. This is done purely for testing |
1208 // convenience. | 1244 // convenience. |
1209 allocator().set_flags(PORTALLOCATOR_DISABLE_TCP | PORTALLOCATOR_DISABLE_STUN | | 1245 allocator().set_flags(PORTALLOCATOR_DISABLE_TCP | PORTALLOCATOR_DISABLE_STUN | |
1210 PORTALLOCATOR_DISABLE_RELAY); | 1246 PORTALLOCATOR_DISABLE_RELAY); |
1211 EXPECT_TRUE(CreateSession(ICE_CANDIDATE_COMPONENT_RTP)); | 1247 EXPECT_TRUE(CreateSession(ICE_CANDIDATE_COMPONENT_RTP)); |
1212 session_->StartGettingPorts(); | 1248 session_->StartGettingPorts(); |
1213 EXPECT_TRUE_WAIT(candidate_allocation_done_, kDefaultAllocationTimeout); | 1249 EXPECT_TRUE_SIMULATED_WAIT(candidate_allocation_done_, |
| 1250 kDefaultAllocationTimeout, fake_clock); |
1214 ASSERT_EQ(2U, candidates_.size()); | 1251 ASSERT_EQ(2U, candidates_.size()); |
1215 EXPECT_EQ(2U, ports_.size()); | 1252 EXPECT_EQ(2U, ports_.size()); |
1216 // Candidates priorities should be different. | 1253 // Candidates priorities should be different. |
1217 EXPECT_NE(candidates_[0].priority(), candidates_[1].priority()); | 1254 EXPECT_NE(candidates_[0].priority(), candidates_[1].priority()); |
1218 } | 1255 } |
1219 | 1256 |
1220 // Test to verify ICE restart process. | 1257 // Test to verify ICE restart process. |
1221 TEST_F(BasicPortAllocatorTest, TestGetAllPortsRestarts) { | 1258 TEST_F(BasicPortAllocatorTest, TestGetAllPortsRestarts) { |
1222 AddInterface(kClientAddr); | 1259 AddInterface(kClientAddr); |
1223 EXPECT_TRUE(CreateSession(ICE_CANDIDATE_COMPONENT_RTP)); | 1260 EXPECT_TRUE(CreateSession(ICE_CANDIDATE_COMPONENT_RTP)); |
1224 session_->StartGettingPorts(); | 1261 session_->StartGettingPorts(); |
1225 EXPECT_EQ_WAIT(7U, candidates_.size(), kDefaultAllocationTimeout); | 1262 EXPECT_EQ_SIMULATED_WAIT(7U, candidates_.size(), kDefaultAllocationTimeout, |
| 1263 fake_clock); |
1226 EXPECT_EQ(4U, ports_.size()); | 1264 EXPECT_EQ(4U, ports_.size()); |
1227 EXPECT_TRUE(candidate_allocation_done_); | 1265 EXPECT_TRUE(candidate_allocation_done_); |
1228 // TODO(deadbeef): Extend this to verify ICE restart. | 1266 // TODO(deadbeef): Extend this to verify ICE restart. |
1229 } | 1267 } |
1230 | 1268 |
1231 // Test that the allocator session uses the candidate filter it's created with, | 1269 // Test that the allocator session uses the candidate filter it's created with, |
1232 // rather than the filter of its parent allocator. | 1270 // rather than the filter of its parent allocator. |
1233 // The filter of the allocator should only affect the next gathering phase, | 1271 // The filter of the allocator should only affect the next gathering phase, |
1234 // according to JSEP, which means the *next* allocator session returned. | 1272 // according to JSEP, which means the *next* allocator session returned. |
1235 TEST_F(BasicPortAllocatorTest, TestSessionUsesOwnCandidateFilter) { | 1273 TEST_F(BasicPortAllocatorTest, TestSessionUsesOwnCandidateFilter) { |
1236 AddInterface(kClientAddr); | 1274 AddInterface(kClientAddr); |
1237 EXPECT_TRUE(CreateSession(ICE_CANDIDATE_COMPONENT_RTP)); | 1275 EXPECT_TRUE(CreateSession(ICE_CANDIDATE_COMPONENT_RTP)); |
1238 // Set candidate filter *after* creating the session. Should have no effect. | 1276 // Set candidate filter *after* creating the session. Should have no effect. |
1239 allocator().set_candidate_filter(CF_RELAY); | 1277 allocator().set_candidate_filter(CF_RELAY); |
1240 session_->StartGettingPorts(); | 1278 session_->StartGettingPorts(); |
1241 // 7 candidates and 4 ports is what we would normally get (see the | 1279 // 7 candidates and 4 ports is what we would normally get (see the |
1242 // TestGetAllPorts* tests). | 1280 // TestGetAllPorts* tests). |
1243 EXPECT_EQ_WAIT(7U, candidates_.size(), kDefaultAllocationTimeout); | 1281 EXPECT_EQ_SIMULATED_WAIT(7U, candidates_.size(), kDefaultAllocationTimeout, |
| 1282 fake_clock); |
1244 EXPECT_EQ(4U, ports_.size()); | 1283 EXPECT_EQ(4U, ports_.size()); |
1245 EXPECT_TRUE(candidate_allocation_done_); | 1284 EXPECT_TRUE(candidate_allocation_done_); |
1246 } | 1285 } |
1247 | 1286 |
1248 // Test ICE candidate filter mechanism with options Relay/Host/Reflexive. | 1287 // Test ICE candidate filter mechanism with options Relay/Host/Reflexive. |
1249 // This test also verifies that when the allocator is only allowed to use | 1288 // This test also verifies that when the allocator is only allowed to use |
1250 // relay (i.e. IceTransportsType is relay), the raddr is an empty | 1289 // relay (i.e. IceTransportsType is relay), the raddr is an empty |
1251 // address with the correct family. This is to prevent any local | 1290 // address with the correct family. This is to prevent any local |
1252 // reflective address leakage in the sdp line. | 1291 // reflective address leakage in the sdp line. |
1253 TEST_F(BasicPortAllocatorTest, TestCandidateFilterWithRelayOnly) { | 1292 TEST_F(BasicPortAllocatorTest, TestCandidateFilterWithRelayOnly) { |
1254 AddInterface(kClientAddr); | 1293 AddInterface(kClientAddr); |
1255 // GTURN is not configured here. | 1294 // GTURN is not configured here. |
1256 ResetWithTurnServersNoNat(kTurnUdpIntAddr, rtc::SocketAddress()); | 1295 ResetWithTurnServersNoNat(kTurnUdpIntAddr, rtc::SocketAddress()); |
1257 allocator().set_candidate_filter(CF_RELAY); | 1296 allocator().set_candidate_filter(CF_RELAY); |
1258 EXPECT_TRUE(CreateSession(ICE_CANDIDATE_COMPONENT_RTP)); | 1297 EXPECT_TRUE(CreateSession(ICE_CANDIDATE_COMPONENT_RTP)); |
1259 session_->StartGettingPorts(); | 1298 session_->StartGettingPorts(); |
1260 EXPECT_TRUE_WAIT(candidate_allocation_done_, kDefaultAllocationTimeout); | 1299 EXPECT_TRUE_SIMULATED_WAIT(candidate_allocation_done_, |
| 1300 kDefaultAllocationTimeout, fake_clock); |
1261 EXPECT_PRED4(HasCandidate, candidates_, "relay", "udp", | 1301 EXPECT_PRED4(HasCandidate, candidates_, "relay", "udp", |
1262 rtc::SocketAddress(kTurnUdpExtAddr.ipaddr(), 0)); | 1302 rtc::SocketAddress(kTurnUdpExtAddr.ipaddr(), 0)); |
1263 | 1303 |
1264 EXPECT_EQ(1U, candidates_.size()); | 1304 EXPECT_EQ(1U, candidates_.size()); |
1265 EXPECT_EQ(1U, ports_.size()); // Only Relay port will be in ready state. | 1305 EXPECT_EQ(1U, ports_.size()); // Only Relay port will be in ready state. |
1266 EXPECT_EQ(std::string(RELAY_PORT_TYPE), candidates_[0].type()); | 1306 EXPECT_EQ(std::string(RELAY_PORT_TYPE), candidates_[0].type()); |
1267 EXPECT_EQ( | 1307 EXPECT_EQ( |
1268 candidates_[0].related_address(), | 1308 candidates_[0].related_address(), |
1269 rtc::EmptySocketAddressWithFamily(candidates_[0].address().family())); | 1309 rtc::EmptySocketAddressWithFamily(candidates_[0].address().family())); |
1270 } | 1310 } |
1271 | 1311 |
1272 TEST_F(BasicPortAllocatorTest, TestCandidateFilterWithHostOnly) { | 1312 TEST_F(BasicPortAllocatorTest, TestCandidateFilterWithHostOnly) { |
1273 AddInterface(kClientAddr); | 1313 AddInterface(kClientAddr); |
1274 allocator().set_flags(PORTALLOCATOR_ENABLE_SHARED_SOCKET); | 1314 allocator().set_flags(PORTALLOCATOR_ENABLE_SHARED_SOCKET); |
1275 allocator().set_candidate_filter(CF_HOST); | 1315 allocator().set_candidate_filter(CF_HOST); |
1276 EXPECT_TRUE(CreateSession(ICE_CANDIDATE_COMPONENT_RTP)); | 1316 EXPECT_TRUE(CreateSession(ICE_CANDIDATE_COMPONENT_RTP)); |
1277 session_->StartGettingPorts(); | 1317 session_->StartGettingPorts(); |
1278 EXPECT_TRUE_WAIT(candidate_allocation_done_, kDefaultAllocationTimeout); | 1318 EXPECT_TRUE_SIMULATED_WAIT(candidate_allocation_done_, |
| 1319 kDefaultAllocationTimeout, fake_clock); |
1279 EXPECT_EQ(2U, candidates_.size()); // Host UDP/TCP candidates only. | 1320 EXPECT_EQ(2U, candidates_.size()); // Host UDP/TCP candidates only. |
1280 EXPECT_EQ(2U, ports_.size()); // UDP/TCP ports only. | 1321 EXPECT_EQ(2U, ports_.size()); // UDP/TCP ports only. |
1281 for (const Candidate& candidate : candidates_) { | 1322 for (const Candidate& candidate : candidates_) { |
1282 EXPECT_EQ(std::string(LOCAL_PORT_TYPE), candidate.type()); | 1323 EXPECT_EQ(std::string(LOCAL_PORT_TYPE), candidate.type()); |
1283 } | 1324 } |
1284 } | 1325 } |
1285 | 1326 |
1286 // Host is behind the NAT. | 1327 // Host is behind the NAT. |
1287 TEST_F(BasicPortAllocatorTest, TestCandidateFilterWithReflexiveOnly) { | 1328 TEST_F(BasicPortAllocatorTest, TestCandidateFilterWithReflexiveOnly) { |
1288 AddInterface(kPrivateAddr); | 1329 AddInterface(kPrivateAddr); |
1289 ResetWithStunServerAndNat(kStunAddr); | 1330 ResetWithStunServerAndNat(kStunAddr); |
1290 | 1331 |
1291 allocator().set_flags(PORTALLOCATOR_ENABLE_SHARED_SOCKET); | 1332 allocator().set_flags(PORTALLOCATOR_ENABLE_SHARED_SOCKET); |
1292 allocator().set_candidate_filter(CF_REFLEXIVE); | 1333 allocator().set_candidate_filter(CF_REFLEXIVE); |
1293 EXPECT_TRUE(CreateSession(ICE_CANDIDATE_COMPONENT_RTP)); | 1334 EXPECT_TRUE(CreateSession(ICE_CANDIDATE_COMPONENT_RTP)); |
1294 session_->StartGettingPorts(); | 1335 session_->StartGettingPorts(); |
1295 EXPECT_TRUE_WAIT(candidate_allocation_done_, kDefaultAllocationTimeout); | 1336 EXPECT_TRUE_SIMULATED_WAIT(candidate_allocation_done_, |
| 1337 kDefaultAllocationTimeout, fake_clock); |
1296 // Host is behind NAT, no private address will be exposed. Hence only UDP | 1338 // Host is behind NAT, no private address will be exposed. Hence only UDP |
1297 // port with STUN candidate will be sent outside. | 1339 // port with STUN candidate will be sent outside. |
1298 EXPECT_EQ(1U, candidates_.size()); // Only STUN candidate. | 1340 EXPECT_EQ(1U, candidates_.size()); // Only STUN candidate. |
1299 EXPECT_EQ(1U, ports_.size()); // Only UDP port will be in ready state. | 1341 EXPECT_EQ(1U, ports_.size()); // Only UDP port will be in ready state. |
1300 EXPECT_EQ(std::string(STUN_PORT_TYPE), candidates_[0].type()); | 1342 EXPECT_EQ(std::string(STUN_PORT_TYPE), candidates_[0].type()); |
1301 EXPECT_EQ( | 1343 EXPECT_EQ( |
1302 candidates_[0].related_address(), | 1344 candidates_[0].related_address(), |
1303 rtc::EmptySocketAddressWithFamily(candidates_[0].address().family())); | 1345 rtc::EmptySocketAddressWithFamily(candidates_[0].address().family())); |
1304 } | 1346 } |
1305 | 1347 |
1306 // Host is not behind the NAT. | 1348 // Host is not behind the NAT. |
1307 TEST_F(BasicPortAllocatorTest, TestCandidateFilterWithReflexiveOnlyAndNoNAT) { | 1349 TEST_F(BasicPortAllocatorTest, TestCandidateFilterWithReflexiveOnlyAndNoNAT) { |
1308 AddInterface(kClientAddr); | 1350 AddInterface(kClientAddr); |
1309 allocator().set_flags(PORTALLOCATOR_ENABLE_SHARED_SOCKET); | 1351 allocator().set_flags(PORTALLOCATOR_ENABLE_SHARED_SOCKET); |
1310 allocator().set_candidate_filter(CF_REFLEXIVE); | 1352 allocator().set_candidate_filter(CF_REFLEXIVE); |
1311 EXPECT_TRUE(CreateSession(ICE_CANDIDATE_COMPONENT_RTP)); | 1353 EXPECT_TRUE(CreateSession(ICE_CANDIDATE_COMPONENT_RTP)); |
1312 session_->StartGettingPorts(); | 1354 session_->StartGettingPorts(); |
1313 EXPECT_TRUE_WAIT(candidate_allocation_done_, kDefaultAllocationTimeout); | 1355 EXPECT_TRUE_SIMULATED_WAIT(candidate_allocation_done_, |
| 1356 kDefaultAllocationTimeout, fake_clock); |
1314 // Host has a public address, both UDP and TCP candidates will be exposed. | 1357 // Host has a public address, both UDP and TCP candidates will be exposed. |
1315 EXPECT_EQ(2U, candidates_.size()); // Local UDP + TCP candidate. | 1358 EXPECT_EQ(2U, candidates_.size()); // Local UDP + TCP candidate. |
1316 EXPECT_EQ(2U, ports_.size()); // UDP and TCP ports will be in ready state. | 1359 EXPECT_EQ(2U, ports_.size()); // UDP and TCP ports will be in ready state. |
1317 for (const Candidate& candidate : candidates_) { | 1360 for (const Candidate& candidate : candidates_) { |
1318 EXPECT_EQ(std::string(LOCAL_PORT_TYPE), candidate.type()); | 1361 EXPECT_EQ(std::string(LOCAL_PORT_TYPE), candidate.type()); |
1319 } | 1362 } |
1320 } | 1363 } |
1321 | 1364 |
1322 // Test that we get the same ufrag and pwd for all candidates. | 1365 // Test that we get the same ufrag and pwd for all candidates. |
1323 TEST_F(BasicPortAllocatorTest, TestEnableSharedUfrag) { | 1366 TEST_F(BasicPortAllocatorTest, TestEnableSharedUfrag) { |
1324 AddInterface(kClientAddr); | 1367 AddInterface(kClientAddr); |
1325 EXPECT_TRUE(CreateSession(ICE_CANDIDATE_COMPONENT_RTP)); | 1368 EXPECT_TRUE(CreateSession(ICE_CANDIDATE_COMPONENT_RTP)); |
1326 session_->StartGettingPorts(); | 1369 session_->StartGettingPorts(); |
1327 ASSERT_EQ_WAIT(7U, candidates_.size(), kDefaultAllocationTimeout); | 1370 ASSERT_EQ_SIMULATED_WAIT(7U, candidates_.size(), kDefaultAllocationTimeout, |
| 1371 fake_clock); |
1328 EXPECT_PRED4(HasCandidate, candidates_, "local", "udp", kClientAddr); | 1372 EXPECT_PRED4(HasCandidate, candidates_, "local", "udp", kClientAddr); |
1329 EXPECT_PRED4(HasCandidate, candidates_, "stun", "udp", kClientAddr); | 1373 EXPECT_PRED4(HasCandidate, candidates_, "stun", "udp", kClientAddr); |
1330 EXPECT_PRED4(HasCandidate, candidates_, "local", "tcp", kClientAddr); | 1374 EXPECT_PRED4(HasCandidate, candidates_, "local", "tcp", kClientAddr); |
1331 EXPECT_EQ(4U, ports_.size()); | 1375 EXPECT_EQ(4U, ports_.size()); |
1332 for (const Candidate& candidate : candidates_) { | 1376 for (const Candidate& candidate : candidates_) { |
1333 EXPECT_EQ(kIceUfrag0, candidate.username()); | 1377 EXPECT_EQ(kIceUfrag0, candidate.username()); |
1334 EXPECT_EQ(kIcePwd0, candidate.password()); | 1378 EXPECT_EQ(kIcePwd0, candidate.password()); |
1335 } | 1379 } |
1336 EXPECT_TRUE(candidate_allocation_done_); | 1380 EXPECT_TRUE(candidate_allocation_done_); |
1337 } | 1381 } |
1338 | 1382 |
1339 // Test that when PORTALLOCATOR_ENABLE_SHARED_SOCKET is enabled only one port | 1383 // Test that when PORTALLOCATOR_ENABLE_SHARED_SOCKET is enabled only one port |
1340 // is allocated for udp and stun. Also verify there is only one candidate | 1384 // is allocated for udp and stun. Also verify there is only one candidate |
1341 // (local) if stun candidate is same as local candidate, which will be the case | 1385 // (local) if stun candidate is same as local candidate, which will be the case |
1342 // in a public network like the below test. | 1386 // in a public network like the below test. |
1343 TEST_F(BasicPortAllocatorTest, TestSharedSocketWithoutNat) { | 1387 TEST_F(BasicPortAllocatorTest, TestSharedSocketWithoutNat) { |
1344 AddInterface(kClientAddr); | 1388 AddInterface(kClientAddr); |
1345 allocator_->set_flags(allocator().flags() | | 1389 allocator_->set_flags(allocator().flags() | |
1346 PORTALLOCATOR_ENABLE_SHARED_SOCKET); | 1390 PORTALLOCATOR_ENABLE_SHARED_SOCKET); |
1347 EXPECT_TRUE(CreateSession(ICE_CANDIDATE_COMPONENT_RTP)); | 1391 EXPECT_TRUE(CreateSession(ICE_CANDIDATE_COMPONENT_RTP)); |
1348 session_->StartGettingPorts(); | 1392 session_->StartGettingPorts(); |
1349 ASSERT_EQ_WAIT(6U, candidates_.size(), kDefaultAllocationTimeout); | 1393 ASSERT_EQ_SIMULATED_WAIT(6U, candidates_.size(), kDefaultAllocationTimeout, |
| 1394 fake_clock); |
1350 EXPECT_EQ(3U, ports_.size()); | 1395 EXPECT_EQ(3U, ports_.size()); |
1351 EXPECT_PRED4(HasCandidate, candidates_, "local", "udp", kClientAddr); | 1396 EXPECT_PRED4(HasCandidate, candidates_, "local", "udp", kClientAddr); |
1352 EXPECT_TRUE_WAIT(candidate_allocation_done_, kDefaultAllocationTimeout); | 1397 EXPECT_TRUE_SIMULATED_WAIT(candidate_allocation_done_, |
| 1398 kDefaultAllocationTimeout, fake_clock); |
1353 } | 1399 } |
1354 | 1400 |
1355 // Test that when PORTALLOCATOR_ENABLE_SHARED_SOCKET is enabled only one port | 1401 // Test that when PORTALLOCATOR_ENABLE_SHARED_SOCKET is enabled only one port |
1356 // is allocated for udp and stun. In this test we should expect both stun and | 1402 // is allocated for udp and stun. In this test we should expect both stun and |
1357 // local candidates as client behind a nat. | 1403 // local candidates as client behind a nat. |
1358 TEST_F(BasicPortAllocatorTest, TestSharedSocketWithNat) { | 1404 TEST_F(BasicPortAllocatorTest, TestSharedSocketWithNat) { |
1359 AddInterface(kClientAddr); | 1405 AddInterface(kClientAddr); |
1360 ResetWithStunServerAndNat(kStunAddr); | 1406 ResetWithStunServerAndNat(kStunAddr); |
1361 | 1407 |
1362 allocator_->set_flags(allocator().flags() | | 1408 allocator_->set_flags(allocator().flags() | |
1363 PORTALLOCATOR_ENABLE_SHARED_SOCKET); | 1409 PORTALLOCATOR_ENABLE_SHARED_SOCKET); |
1364 EXPECT_TRUE(CreateSession(ICE_CANDIDATE_COMPONENT_RTP)); | 1410 EXPECT_TRUE(CreateSession(ICE_CANDIDATE_COMPONENT_RTP)); |
1365 session_->StartGettingPorts(); | 1411 session_->StartGettingPorts(); |
1366 ASSERT_EQ_WAIT(3U, candidates_.size(), kDefaultAllocationTimeout); | 1412 ASSERT_EQ_SIMULATED_WAIT(3U, candidates_.size(), kDefaultAllocationTimeout, |
| 1413 fake_clock); |
1367 ASSERT_EQ(2U, ports_.size()); | 1414 ASSERT_EQ(2U, ports_.size()); |
1368 EXPECT_PRED4(HasCandidate, candidates_, "local", "udp", kClientAddr); | 1415 EXPECT_PRED4(HasCandidate, candidates_, "local", "udp", kClientAddr); |
1369 EXPECT_PRED4(HasCandidate, candidates_, "stun", "udp", | 1416 EXPECT_PRED4(HasCandidate, candidates_, "stun", "udp", |
1370 rtc::SocketAddress(kNatUdpAddr.ipaddr(), 0)); | 1417 rtc::SocketAddress(kNatUdpAddr.ipaddr(), 0)); |
1371 EXPECT_TRUE_WAIT(candidate_allocation_done_, kDefaultAllocationTimeout); | 1418 EXPECT_TRUE_SIMULATED_WAIT(candidate_allocation_done_, |
| 1419 kDefaultAllocationTimeout, fake_clock); |
1372 EXPECT_EQ(3U, candidates_.size()); | 1420 EXPECT_EQ(3U, candidates_.size()); |
1373 } | 1421 } |
1374 | 1422 |
1375 // Test TURN port in shared socket mode with UDP and TCP TURN server addresses. | 1423 // Test TURN port in shared socket mode with UDP and TCP TURN server addresses. |
1376 TEST_F(BasicPortAllocatorTest, TestSharedSocketWithoutNatUsingTurn) { | 1424 TEST_F(BasicPortAllocatorTest, TestSharedSocketWithoutNatUsingTurn) { |
1377 turn_server_.AddInternalSocket(kTurnTcpIntAddr, PROTO_TCP); | 1425 turn_server_.AddInternalSocket(kTurnTcpIntAddr, PROTO_TCP); |
1378 AddInterface(kClientAddr); | 1426 AddInterface(kClientAddr); |
1379 allocator_.reset(new BasicPortAllocator(&network_manager_)); | 1427 allocator_.reset(new BasicPortAllocator(&network_manager_)); |
1380 | 1428 |
1381 AddTurnServers(kTurnUdpIntAddr, kTurnTcpIntAddr); | 1429 AddTurnServers(kTurnUdpIntAddr, kTurnTcpIntAddr); |
1382 | 1430 |
1383 allocator_->set_step_delay(kMinimumStepDelay); | 1431 allocator_->set_step_delay(kMinimumStepDelay); |
1384 allocator_->set_flags(allocator().flags() | | 1432 allocator_->set_flags(allocator().flags() | |
1385 PORTALLOCATOR_ENABLE_SHARED_SOCKET | | 1433 PORTALLOCATOR_ENABLE_SHARED_SOCKET | |
1386 PORTALLOCATOR_DISABLE_TCP); | 1434 PORTALLOCATOR_DISABLE_TCP); |
1387 | 1435 |
1388 EXPECT_TRUE(CreateSession(ICE_CANDIDATE_COMPONENT_RTP)); | 1436 EXPECT_TRUE(CreateSession(ICE_CANDIDATE_COMPONENT_RTP)); |
1389 session_->StartGettingPorts(); | 1437 session_->StartGettingPorts(); |
1390 | 1438 |
1391 ASSERT_EQ_WAIT(3U, candidates_.size(), kDefaultAllocationTimeout); | 1439 ASSERT_EQ_SIMULATED_WAIT(3U, candidates_.size(), kDefaultAllocationTimeout, |
| 1440 fake_clock); |
1392 ASSERT_EQ(3U, ports_.size()); | 1441 ASSERT_EQ(3U, ports_.size()); |
1393 EXPECT_PRED4(HasCandidate, candidates_, "local", "udp", kClientAddr); | 1442 EXPECT_PRED4(HasCandidate, candidates_, "local", "udp", kClientAddr); |
1394 EXPECT_PRED4(HasCandidate, candidates_, "relay", "udp", | 1443 EXPECT_PRED4(HasCandidate, candidates_, "relay", "udp", |
1395 rtc::SocketAddress(kTurnUdpExtAddr.ipaddr(), 0)); | 1444 rtc::SocketAddress(kTurnUdpExtAddr.ipaddr(), 0)); |
1396 EXPECT_PRED4(HasCandidate, candidates_, "relay", "udp", | 1445 EXPECT_PRED4(HasCandidate, candidates_, "relay", "udp", |
1397 rtc::SocketAddress(kTurnUdpExtAddr.ipaddr(), 0)); | 1446 rtc::SocketAddress(kTurnUdpExtAddr.ipaddr(), 0)); |
1398 EXPECT_TRUE_WAIT(candidate_allocation_done_, kDefaultAllocationTimeout); | 1447 EXPECT_TRUE_SIMULATED_WAIT(candidate_allocation_done_, |
| 1448 kDefaultAllocationTimeout, fake_clock); |
1399 EXPECT_EQ(3U, candidates_.size()); | 1449 EXPECT_EQ(3U, candidates_.size()); |
1400 } | 1450 } |
1401 | 1451 |
1402 // Test that if prune_turn_ports is set, TCP TURN port will not be used | 1452 // Test that if prune_turn_ports is set, TCP TURN port will not be used |
1403 // if UDP TurnPort is used, given that TCP TURN port becomes ready first. | 1453 // if UDP TurnPort is used, given that TCP TURN port becomes ready first. |
1404 TEST_F(BasicPortAllocatorTest, | 1454 TEST_F(BasicPortAllocatorTest, |
1405 TestUdpTurnPortPrunesTcpTurnPortWithTcpPortReadyFirst) { | 1455 TestUdpTurnPortPrunesTcpTurnPortWithTcpPortReadyFirst) { |
1406 // UDP has longer delay than TCP so that TCP TURN port becomes ready first. | 1456 // UDP has longer delay than TCP so that TCP TURN port becomes ready first. |
1407 virtual_socket_server()->SetDelayOnAddress(kTurnUdpIntAddr, 200); | 1457 virtual_socket_server()->SetDelayOnAddress(kTurnUdpIntAddr, 200); |
1408 virtual_socket_server()->SetDelayOnAddress(kTurnTcpIntAddr, 100); | 1458 virtual_socket_server()->SetDelayOnAddress(kTurnTcpIntAddr, 100); |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1462 virtual_socket_server()->SetDelayOnAddress(kTurnTcpIntAddr, 10); | 1512 virtual_socket_server()->SetDelayOnAddress(kTurnTcpIntAddr, 10); |
1463 virtual_socket_server()->SetDelayOnAddress(kTurnUdpIntAddr, 100); | 1513 virtual_socket_server()->SetDelayOnAddress(kTurnUdpIntAddr, 100); |
1464 virtual_socket_server()->SetDelayOnAddress(kTurnTcpIntIPv6Addr, 20); | 1514 virtual_socket_server()->SetDelayOnAddress(kTurnTcpIntIPv6Addr, 20); |
1465 virtual_socket_server()->SetDelayOnAddress(kTurnUdpIntIPv6Addr, 300); | 1515 virtual_socket_server()->SetDelayOnAddress(kTurnUdpIntIPv6Addr, 300); |
1466 | 1516 |
1467 TestEachInterfaceHasItsOwnTurnPorts(); | 1517 TestEachInterfaceHasItsOwnTurnPorts(); |
1468 } | 1518 } |
1469 | 1519 |
1470 // Testing DNS resolve for the TURN server, this will test AllocationSequence | 1520 // Testing DNS resolve for the TURN server, this will test AllocationSequence |
1471 // handling the unresolved address signal from TurnPort. | 1521 // handling the unresolved address signal from TurnPort. |
1472 TEST_F(BasicPortAllocatorTest, TestSharedSocketWithServerAddressResolve) { | 1522 // TODO(pthatcher): Make this test work with SIMULATED_WAIT. It |
| 1523 // appears that it doesn't currently because of the DNS look up not |
| 1524 // using the fake clock. |
| 1525 TEST_F(BasicPortAllocatorTestWithRealClock, |
| 1526 TestSharedSocketWithServerAddressResolve) { |
1473 turn_server_.AddInternalSocket(rtc::SocketAddress("127.0.0.1", 3478), | 1527 turn_server_.AddInternalSocket(rtc::SocketAddress("127.0.0.1", 3478), |
1474 PROTO_UDP); | 1528 PROTO_UDP); |
1475 AddInterface(kClientAddr); | 1529 AddInterface(kClientAddr); |
1476 allocator_.reset(new BasicPortAllocator(&network_manager_)); | 1530 allocator_.reset(new BasicPortAllocator(&network_manager_)); |
1477 RelayServerConfig turn_server(RELAY_TURN); | 1531 RelayServerConfig turn_server(RELAY_TURN); |
1478 RelayCredentials credentials(kTurnUsername, kTurnPassword); | 1532 RelayCredentials credentials(kTurnUsername, kTurnPassword); |
1479 turn_server.credentials = credentials; | 1533 turn_server.credentials = credentials; |
1480 turn_server.ports.push_back( | 1534 turn_server.ports.push_back( |
1481 ProtocolAddress(rtc::SocketAddress("localhost", 3478), PROTO_UDP)); | 1535 ProtocolAddress(rtc::SocketAddress("localhost", 3478), PROTO_UDP)); |
1482 allocator_->AddTurnServer(turn_server); | 1536 allocator_->AddTurnServer(turn_server); |
(...skipping 18 matching lines...) Expand all Loading... |
1501 | 1555 |
1502 AddTurnServers(kTurnUdpIntAddr, rtc::SocketAddress()); | 1556 AddTurnServers(kTurnUdpIntAddr, rtc::SocketAddress()); |
1503 | 1557 |
1504 allocator_->set_flags(allocator().flags() | | 1558 allocator_->set_flags(allocator().flags() | |
1505 PORTALLOCATOR_ENABLE_SHARED_SOCKET | | 1559 PORTALLOCATOR_ENABLE_SHARED_SOCKET | |
1506 PORTALLOCATOR_DISABLE_TCP); | 1560 PORTALLOCATOR_DISABLE_TCP); |
1507 | 1561 |
1508 EXPECT_TRUE(CreateSession(ICE_CANDIDATE_COMPONENT_RTP)); | 1562 EXPECT_TRUE(CreateSession(ICE_CANDIDATE_COMPONENT_RTP)); |
1509 session_->StartGettingPorts(); | 1563 session_->StartGettingPorts(); |
1510 | 1564 |
1511 ASSERT_EQ_WAIT(3U, candidates_.size(), kDefaultAllocationTimeout); | 1565 ASSERT_EQ_SIMULATED_WAIT(3U, candidates_.size(), kDefaultAllocationTimeout, |
| 1566 fake_clock); |
1512 ASSERT_EQ(2U, ports_.size()); | 1567 ASSERT_EQ(2U, ports_.size()); |
1513 EXPECT_PRED4(HasCandidate, candidates_, "local", "udp", kClientAddr); | 1568 EXPECT_PRED4(HasCandidate, candidates_, "local", "udp", kClientAddr); |
1514 EXPECT_PRED4(HasCandidate, candidates_, "stun", "udp", | 1569 EXPECT_PRED4(HasCandidate, candidates_, "stun", "udp", |
1515 rtc::SocketAddress(kNatUdpAddr.ipaddr(), 0)); | 1570 rtc::SocketAddress(kNatUdpAddr.ipaddr(), 0)); |
1516 EXPECT_PRED4(HasCandidate, candidates_, "relay", "udp", | 1571 EXPECT_PRED4(HasCandidate, candidates_, "relay", "udp", |
1517 rtc::SocketAddress(kTurnUdpExtAddr.ipaddr(), 0)); | 1572 rtc::SocketAddress(kTurnUdpExtAddr.ipaddr(), 0)); |
1518 EXPECT_TRUE_WAIT(candidate_allocation_done_, kDefaultAllocationTimeout); | 1573 EXPECT_TRUE_SIMULATED_WAIT(candidate_allocation_done_, |
| 1574 kDefaultAllocationTimeout, fake_clock); |
1519 EXPECT_EQ(3U, candidates_.size()); | 1575 EXPECT_EQ(3U, candidates_.size()); |
1520 // Local port will be created first and then TURN port. | 1576 // Local port will be created first and then TURN port. |
1521 EXPECT_EQ(2U, ports_[0]->Candidates().size()); | 1577 EXPECT_EQ(2U, ports_[0]->Candidates().size()); |
1522 EXPECT_EQ(1U, ports_[1]->Candidates().size()); | 1578 EXPECT_EQ(1U, ports_[1]->Candidates().size()); |
1523 } | 1579 } |
1524 | 1580 |
1525 // Test that when PORTALLOCATOR_ENABLE_SHARED_SOCKET is enabled and the TURN | 1581 // Test that when PORTALLOCATOR_ENABLE_SHARED_SOCKET is enabled and the TURN |
1526 // server is also used as the STUN server, we should get 'local', 'stun', and | 1582 // server is also used as the STUN server, we should get 'local', 'stun', and |
1527 // 'relay' candidates. | 1583 // 'relay' candidates. |
1528 TEST_F(BasicPortAllocatorTest, TestSharedSocketWithNatUsingTurnAsStun) { | 1584 TEST_F(BasicPortAllocatorTest, TestSharedSocketWithNatUsingTurnAsStun) { |
1529 AddInterface(kClientAddr); | 1585 AddInterface(kClientAddr); |
1530 // Use an empty SocketAddress to add a NAT without STUN server. | 1586 // Use an empty SocketAddress to add a NAT without STUN server. |
1531 ResetWithStunServerAndNat(SocketAddress()); | 1587 ResetWithStunServerAndNat(SocketAddress()); |
1532 AddTurnServers(kTurnUdpIntAddr, rtc::SocketAddress()); | 1588 AddTurnServers(kTurnUdpIntAddr, rtc::SocketAddress()); |
1533 | 1589 |
1534 // Must set the step delay to 0 to make sure the relay allocation phase is | 1590 // Must set the step delay to 0 to make sure the relay allocation phase is |
1535 // started before the STUN candidates are obtained, so that the STUN binding | 1591 // started before the STUN candidates are obtained, so that the STUN binding |
1536 // response is processed when both StunPort and TurnPort exist to reproduce | 1592 // response is processed when both StunPort and TurnPort exist to reproduce |
1537 // webrtc issue 3537. | 1593 // webrtc issue 3537. |
1538 allocator_->set_step_delay(0); | 1594 allocator_->set_step_delay(0); |
1539 allocator_->set_flags(allocator().flags() | | 1595 allocator_->set_flags(allocator().flags() | |
1540 PORTALLOCATOR_ENABLE_SHARED_SOCKET | | 1596 PORTALLOCATOR_ENABLE_SHARED_SOCKET | |
1541 PORTALLOCATOR_DISABLE_TCP); | 1597 PORTALLOCATOR_DISABLE_TCP); |
1542 | 1598 |
1543 EXPECT_TRUE(CreateSession(ICE_CANDIDATE_COMPONENT_RTP)); | 1599 EXPECT_TRUE(CreateSession(ICE_CANDIDATE_COMPONENT_RTP)); |
1544 session_->StartGettingPorts(); | 1600 session_->StartGettingPorts(); |
1545 | 1601 |
1546 ASSERT_EQ_WAIT(3U, candidates_.size(), kDefaultAllocationTimeout); | 1602 ASSERT_EQ_SIMULATED_WAIT(3U, candidates_.size(), kDefaultAllocationTimeout, |
| 1603 fake_clock); |
1547 EXPECT_PRED4(HasCandidate, candidates_, "local", "udp", kClientAddr); | 1604 EXPECT_PRED4(HasCandidate, candidates_, "local", "udp", kClientAddr); |
1548 Candidate stun_candidate; | 1605 Candidate stun_candidate; |
1549 EXPECT_PRED5(FindCandidate, candidates_, "stun", "udp", | 1606 EXPECT_PRED5(FindCandidate, candidates_, "stun", "udp", |
1550 rtc::SocketAddress(kNatUdpAddr.ipaddr(), 0), &stun_candidate); | 1607 rtc::SocketAddress(kNatUdpAddr.ipaddr(), 0), &stun_candidate); |
1551 EXPECT_PRED5(HasCandidateWithRelatedAddr, candidates_, "relay", "udp", | 1608 EXPECT_PRED5(HasCandidateWithRelatedAddr, candidates_, "relay", "udp", |
1552 rtc::SocketAddress(kTurnUdpExtAddr.ipaddr(), 0), | 1609 rtc::SocketAddress(kTurnUdpExtAddr.ipaddr(), 0), |
1553 stun_candidate.address()); | 1610 stun_candidate.address()); |
1554 | 1611 |
1555 EXPECT_TRUE_WAIT(candidate_allocation_done_, kDefaultAllocationTimeout); | 1612 EXPECT_TRUE_SIMULATED_WAIT(candidate_allocation_done_, |
| 1613 kDefaultAllocationTimeout, fake_clock); |
1556 EXPECT_EQ(3U, candidates_.size()); | 1614 EXPECT_EQ(3U, candidates_.size()); |
1557 // Local port will be created first and then TURN port. | 1615 // Local port will be created first and then TURN port. |
1558 EXPECT_EQ(2U, ports_[0]->Candidates().size()); | 1616 EXPECT_EQ(2U, ports_[0]->Candidates().size()); |
1559 EXPECT_EQ(1U, ports_[1]->Candidates().size()); | 1617 EXPECT_EQ(1U, ports_[1]->Candidates().size()); |
1560 } | 1618 } |
1561 | 1619 |
1562 // Test that when only a TCP TURN server is available, we do NOT use it as | 1620 // Test that when only a TCP TURN server is available, we do NOT use it as |
1563 // a UDP STUN server, as this could leak our IP address. Thus we should only | 1621 // a UDP STUN server, as this could leak our IP address. Thus we should only |
1564 // expect two ports, a UDPPort and TurnPort. | 1622 // expect two ports, a UDPPort and TurnPort. |
1565 TEST_F(BasicPortAllocatorTest, TestSharedSocketWithNatUsingTurnTcpOnly) { | 1623 TEST_F(BasicPortAllocatorTest, TestSharedSocketWithNatUsingTurnTcpOnly) { |
1566 turn_server_.AddInternalSocket(kTurnTcpIntAddr, PROTO_TCP); | 1624 turn_server_.AddInternalSocket(kTurnTcpIntAddr, PROTO_TCP); |
1567 AddInterface(kClientAddr); | 1625 AddInterface(kClientAddr); |
1568 ResetWithStunServerAndNat(rtc::SocketAddress()); | 1626 ResetWithStunServerAndNat(rtc::SocketAddress()); |
1569 AddTurnServers(rtc::SocketAddress(), kTurnTcpIntAddr); | 1627 AddTurnServers(rtc::SocketAddress(), kTurnTcpIntAddr); |
1570 | 1628 |
1571 allocator_->set_flags(allocator().flags() | | 1629 allocator_->set_flags(allocator().flags() | |
1572 PORTALLOCATOR_ENABLE_SHARED_SOCKET | | 1630 PORTALLOCATOR_ENABLE_SHARED_SOCKET | |
1573 PORTALLOCATOR_DISABLE_TCP); | 1631 PORTALLOCATOR_DISABLE_TCP); |
1574 | 1632 |
1575 EXPECT_TRUE(CreateSession(ICE_CANDIDATE_COMPONENT_RTP)); | 1633 EXPECT_TRUE(CreateSession(ICE_CANDIDATE_COMPONENT_RTP)); |
1576 session_->StartGettingPorts(); | 1634 session_->StartGettingPorts(); |
1577 | 1635 |
1578 ASSERT_EQ_WAIT(2U, candidates_.size(), kDefaultAllocationTimeout); | 1636 ASSERT_EQ_SIMULATED_WAIT(2U, candidates_.size(), kDefaultAllocationTimeout, |
| 1637 fake_clock); |
1579 ASSERT_EQ(2U, ports_.size()); | 1638 ASSERT_EQ(2U, ports_.size()); |
1580 EXPECT_PRED4(HasCandidate, candidates_, "local", "udp", kClientAddr); | 1639 EXPECT_PRED4(HasCandidate, candidates_, "local", "udp", kClientAddr); |
1581 EXPECT_PRED4(HasCandidate, candidates_, "relay", "udp", | 1640 EXPECT_PRED4(HasCandidate, candidates_, "relay", "udp", |
1582 rtc::SocketAddress(kTurnUdpExtAddr.ipaddr(), 0)); | 1641 rtc::SocketAddress(kTurnUdpExtAddr.ipaddr(), 0)); |
1583 EXPECT_TRUE_WAIT(candidate_allocation_done_, kDefaultAllocationTimeout); | 1642 EXPECT_TRUE_SIMULATED_WAIT(candidate_allocation_done_, |
| 1643 kDefaultAllocationTimeout, fake_clock); |
1584 EXPECT_EQ(2U, candidates_.size()); | 1644 EXPECT_EQ(2U, candidates_.size()); |
1585 EXPECT_EQ(1U, ports_[0]->Candidates().size()); | 1645 EXPECT_EQ(1U, ports_[0]->Candidates().size()); |
1586 EXPECT_EQ(1U, ports_[1]->Candidates().size()); | 1646 EXPECT_EQ(1U, ports_[1]->Candidates().size()); |
1587 } | 1647 } |
1588 | 1648 |
1589 // Test that even when PORTALLOCATOR_ENABLE_SHARED_SOCKET is NOT enabled, the | 1649 // Test that even when PORTALLOCATOR_ENABLE_SHARED_SOCKET is NOT enabled, the |
1590 // TURN server is used as the STUN server and we get 'local', 'stun', and | 1650 // TURN server is used as the STUN server and we get 'local', 'stun', and |
1591 // 'relay' candidates. | 1651 // 'relay' candidates. |
1592 // TODO(deadbeef): Remove this test when support for non-shared socket mode | 1652 // TODO(deadbeef): Remove this test when support for non-shared socket mode |
1593 // is removed. | 1653 // is removed. |
1594 TEST_F(BasicPortAllocatorTest, TestNonSharedSocketWithNatUsingTurnAsStun) { | 1654 TEST_F(BasicPortAllocatorTest, TestNonSharedSocketWithNatUsingTurnAsStun) { |
1595 AddInterface(kClientAddr); | 1655 AddInterface(kClientAddr); |
1596 // Use an empty SocketAddress to add a NAT without STUN server. | 1656 // Use an empty SocketAddress to add a NAT without STUN server. |
1597 ResetWithStunServerAndNat(SocketAddress()); | 1657 ResetWithStunServerAndNat(SocketAddress()); |
1598 AddTurnServers(kTurnUdpIntAddr, rtc::SocketAddress()); | 1658 AddTurnServers(kTurnUdpIntAddr, rtc::SocketAddress()); |
1599 | 1659 |
1600 allocator_->set_flags(allocator().flags() | PORTALLOCATOR_DISABLE_TCP); | 1660 allocator_->set_flags(allocator().flags() | PORTALLOCATOR_DISABLE_TCP); |
1601 | 1661 |
1602 EXPECT_TRUE(CreateSession(ICE_CANDIDATE_COMPONENT_RTP)); | 1662 EXPECT_TRUE(CreateSession(ICE_CANDIDATE_COMPONENT_RTP)); |
1603 session_->StartGettingPorts(); | 1663 session_->StartGettingPorts(); |
1604 | 1664 |
1605 ASSERT_EQ_WAIT(3U, candidates_.size(), kDefaultAllocationTimeout); | 1665 ASSERT_EQ_SIMULATED_WAIT(3U, candidates_.size(), kDefaultAllocationTimeout, |
| 1666 fake_clock); |
1606 ASSERT_EQ(3U, ports_.size()); | 1667 ASSERT_EQ(3U, ports_.size()); |
1607 EXPECT_PRED4(HasCandidate, candidates_, "local", "udp", kClientAddr); | 1668 EXPECT_PRED4(HasCandidate, candidates_, "local", "udp", kClientAddr); |
1608 Candidate stun_candidate; | 1669 Candidate stun_candidate; |
1609 EXPECT_PRED5(FindCandidate, candidates_, "stun", "udp", | 1670 EXPECT_PRED5(FindCandidate, candidates_, "stun", "udp", |
1610 rtc::SocketAddress(kNatUdpAddr.ipaddr(), 0), &stun_candidate); | 1671 rtc::SocketAddress(kNatUdpAddr.ipaddr(), 0), &stun_candidate); |
1611 Candidate turn_candidate; | 1672 Candidate turn_candidate; |
1612 EXPECT_PRED5(FindCandidate, candidates_, "relay", "udp", | 1673 EXPECT_PRED5(FindCandidate, candidates_, "relay", "udp", |
1613 rtc::SocketAddress(kTurnUdpExtAddr.ipaddr(), 0), | 1674 rtc::SocketAddress(kTurnUdpExtAddr.ipaddr(), 0), |
1614 &turn_candidate); | 1675 &turn_candidate); |
1615 // Not using shared socket, so the STUN request's server reflexive address | 1676 // Not using shared socket, so the STUN request's server reflexive address |
1616 // should be different than the TURN request's server reflexive address. | 1677 // should be different than the TURN request's server reflexive address. |
1617 EXPECT_NE(turn_candidate.related_address(), stun_candidate.address()); | 1678 EXPECT_NE(turn_candidate.related_address(), stun_candidate.address()); |
1618 | 1679 |
1619 EXPECT_TRUE_WAIT(candidate_allocation_done_, kDefaultAllocationTimeout); | 1680 EXPECT_TRUE_SIMULATED_WAIT(candidate_allocation_done_, |
| 1681 kDefaultAllocationTimeout, fake_clock); |
1620 EXPECT_EQ(3U, candidates_.size()); | 1682 EXPECT_EQ(3U, candidates_.size()); |
1621 EXPECT_EQ(1U, ports_[0]->Candidates().size()); | 1683 EXPECT_EQ(1U, ports_[0]->Candidates().size()); |
1622 EXPECT_EQ(1U, ports_[1]->Candidates().size()); | 1684 EXPECT_EQ(1U, ports_[1]->Candidates().size()); |
1623 EXPECT_EQ(1U, ports_[2]->Candidates().size()); | 1685 EXPECT_EQ(1U, ports_[2]->Candidates().size()); |
1624 } | 1686 } |
1625 | 1687 |
1626 // Test that even when both a STUN and TURN server are configured, the TURN | 1688 // Test that even when both a STUN and TURN server are configured, the TURN |
1627 // server is used as a STUN server and we get a 'stun' candidate. | 1689 // server is used as a STUN server and we get a 'stun' candidate. |
1628 TEST_F(BasicPortAllocatorTest, TestSharedSocketWithNatUsingTurnAndStun) { | 1690 TEST_F(BasicPortAllocatorTest, TestSharedSocketWithNatUsingTurnAndStun) { |
1629 AddInterface(kClientAddr); | 1691 AddInterface(kClientAddr); |
1630 // Configure with STUN server but destroy it, so we can ensure that it's | 1692 // Configure with STUN server but destroy it, so we can ensure that it's |
1631 // the TURN server actually being used as a STUN server. | 1693 // the TURN server actually being used as a STUN server. |
1632 ResetWithStunServerAndNat(kStunAddr); | 1694 ResetWithStunServerAndNat(kStunAddr); |
1633 stun_server_.reset(); | 1695 stun_server_.reset(); |
1634 AddTurnServers(kTurnUdpIntAddr, rtc::SocketAddress()); | 1696 AddTurnServers(kTurnUdpIntAddr, rtc::SocketAddress()); |
1635 | 1697 |
1636 allocator_->set_flags(allocator().flags() | | 1698 allocator_->set_flags(allocator().flags() | |
1637 PORTALLOCATOR_ENABLE_SHARED_SOCKET | | 1699 PORTALLOCATOR_ENABLE_SHARED_SOCKET | |
1638 PORTALLOCATOR_DISABLE_TCP); | 1700 PORTALLOCATOR_DISABLE_TCP); |
1639 | 1701 |
1640 EXPECT_TRUE(CreateSession(ICE_CANDIDATE_COMPONENT_RTP)); | 1702 EXPECT_TRUE(CreateSession(ICE_CANDIDATE_COMPONENT_RTP)); |
1641 session_->StartGettingPorts(); | 1703 session_->StartGettingPorts(); |
1642 | 1704 |
1643 ASSERT_EQ_WAIT(3U, candidates_.size(), kDefaultAllocationTimeout); | 1705 ASSERT_EQ_SIMULATED_WAIT(3U, candidates_.size(), kDefaultAllocationTimeout, |
| 1706 fake_clock); |
1644 EXPECT_PRED4(HasCandidate, candidates_, "local", "udp", kClientAddr); | 1707 EXPECT_PRED4(HasCandidate, candidates_, "local", "udp", kClientAddr); |
1645 Candidate stun_candidate; | 1708 Candidate stun_candidate; |
1646 EXPECT_PRED5(FindCandidate, candidates_, "stun", "udp", | 1709 EXPECT_PRED5(FindCandidate, candidates_, "stun", "udp", |
1647 rtc::SocketAddress(kNatUdpAddr.ipaddr(), 0), &stun_candidate); | 1710 rtc::SocketAddress(kNatUdpAddr.ipaddr(), 0), &stun_candidate); |
1648 EXPECT_PRED5(HasCandidateWithRelatedAddr, candidates_, "relay", "udp", | 1711 EXPECT_PRED5(HasCandidateWithRelatedAddr, candidates_, "relay", "udp", |
1649 rtc::SocketAddress(kTurnUdpExtAddr.ipaddr(), 0), | 1712 rtc::SocketAddress(kTurnUdpExtAddr.ipaddr(), 0), |
1650 stun_candidate.address()); | 1713 stun_candidate.address()); |
1651 | 1714 |
1652 // Don't bother waiting for STUN timeout, since we already verified | 1715 // Don't bother waiting for STUN timeout, since we already verified |
1653 // that we got a STUN candidate from the TURN server. | 1716 // that we got a STUN candidate from the TURN server. |
1654 } | 1717 } |
1655 | 1718 |
1656 // This test verifies when PORTALLOCATOR_ENABLE_SHARED_SOCKET flag is enabled | 1719 // This test verifies when PORTALLOCATOR_ENABLE_SHARED_SOCKET flag is enabled |
1657 // and fail to generate STUN candidate, local UDP candidate is generated | 1720 // and fail to generate STUN candidate, local UDP candidate is generated |
1658 // properly. | 1721 // properly. |
1659 TEST_F(BasicPortAllocatorTest, TestSharedSocketNoUdpAllowed) { | 1722 TEST_F(BasicPortAllocatorTest, TestSharedSocketNoUdpAllowed) { |
1660 allocator().set_flags(allocator().flags() | PORTALLOCATOR_DISABLE_RELAY | | 1723 allocator().set_flags(allocator().flags() | PORTALLOCATOR_DISABLE_RELAY | |
1661 PORTALLOCATOR_DISABLE_TCP | | 1724 PORTALLOCATOR_DISABLE_TCP | |
1662 PORTALLOCATOR_ENABLE_SHARED_SOCKET); | 1725 PORTALLOCATOR_ENABLE_SHARED_SOCKET); |
1663 fss_->AddRule(false, rtc::FP_UDP, rtc::FD_ANY, kClientAddr); | 1726 fss_->AddRule(false, rtc::FP_UDP, rtc::FD_ANY, kClientAddr); |
1664 AddInterface(kClientAddr); | 1727 AddInterface(kClientAddr); |
1665 EXPECT_TRUE(CreateSession(ICE_CANDIDATE_COMPONENT_RTP)); | 1728 EXPECT_TRUE(CreateSession(ICE_CANDIDATE_COMPONENT_RTP)); |
1666 session_->StartGettingPorts(); | 1729 session_->StartGettingPorts(); |
1667 ASSERT_EQ_WAIT(1U, ports_.size(), kDefaultAllocationTimeout); | 1730 ASSERT_EQ_SIMULATED_WAIT(1U, ports_.size(), kDefaultAllocationTimeout, |
| 1731 fake_clock); |
1668 EXPECT_EQ(1U, candidates_.size()); | 1732 EXPECT_EQ(1U, candidates_.size()); |
1669 EXPECT_PRED4(HasCandidate, candidates_, "local", "udp", kClientAddr); | 1733 EXPECT_PRED4(HasCandidate, candidates_, "local", "udp", kClientAddr); |
1670 // STUN timeout is 9.5sec. We need to wait to get candidate done signal. | 1734 // STUN timeout is 9.5sec. We need to wait to get candidate done signal. |
1671 EXPECT_TRUE_WAIT(candidate_allocation_done_, kStunTimeoutMs); | 1735 EXPECT_TRUE_SIMULATED_WAIT(candidate_allocation_done_, kStunTimeoutMs, |
| 1736 fake_clock); |
1672 EXPECT_EQ(1U, candidates_.size()); | 1737 EXPECT_EQ(1U, candidates_.size()); |
1673 } | 1738 } |
1674 | 1739 |
1675 // Test that when the NetworkManager doesn't have permission to enumerate | 1740 // Test that when the NetworkManager doesn't have permission to enumerate |
1676 // adapters, the PORTALLOCATOR_DISABLE_ADAPTER_ENUMERATION is specified | 1741 // adapters, the PORTALLOCATOR_DISABLE_ADAPTER_ENUMERATION is specified |
1677 // automatically. | 1742 // automatically. |
1678 TEST_F(BasicPortAllocatorTest, TestNetworkPermissionBlocked) { | 1743 TEST_F(BasicPortAllocatorTest, TestNetworkPermissionBlocked) { |
1679 network_manager_.set_default_local_addresses(kPrivateAddr.ipaddr(), | 1744 network_manager_.set_default_local_addresses(kPrivateAddr.ipaddr(), |
1680 rtc::IPAddress()); | 1745 rtc::IPAddress()); |
1681 network_manager_.set_enumeration_permission( | 1746 network_manager_.set_enumeration_permission( |
1682 rtc::NetworkManager::ENUMERATION_BLOCKED); | 1747 rtc::NetworkManager::ENUMERATION_BLOCKED); |
1683 allocator().set_flags(allocator().flags() | PORTALLOCATOR_DISABLE_RELAY | | 1748 allocator().set_flags(allocator().flags() | PORTALLOCATOR_DISABLE_RELAY | |
1684 PORTALLOCATOR_DISABLE_TCP | | 1749 PORTALLOCATOR_DISABLE_TCP | |
1685 PORTALLOCATOR_ENABLE_SHARED_SOCKET); | 1750 PORTALLOCATOR_ENABLE_SHARED_SOCKET); |
1686 EXPECT_EQ(0U, | 1751 EXPECT_EQ(0U, |
1687 allocator_->flags() & PORTALLOCATOR_DISABLE_ADAPTER_ENUMERATION); | 1752 allocator_->flags() & PORTALLOCATOR_DISABLE_ADAPTER_ENUMERATION); |
1688 EXPECT_TRUE(CreateSession(ICE_CANDIDATE_COMPONENT_RTP)); | 1753 EXPECT_TRUE(CreateSession(ICE_CANDIDATE_COMPONENT_RTP)); |
1689 EXPECT_EQ(0U, session_->flags() & PORTALLOCATOR_DISABLE_ADAPTER_ENUMERATION); | 1754 EXPECT_EQ(0U, session_->flags() & PORTALLOCATOR_DISABLE_ADAPTER_ENUMERATION); |
1690 session_->StartGettingPorts(); | 1755 session_->StartGettingPorts(); |
1691 EXPECT_EQ_WAIT(1U, ports_.size(), kDefaultAllocationTimeout); | 1756 EXPECT_EQ_SIMULATED_WAIT(1U, ports_.size(), kDefaultAllocationTimeout, |
| 1757 fake_clock); |
1692 EXPECT_EQ(1U, candidates_.size()); | 1758 EXPECT_EQ(1U, candidates_.size()); |
1693 EXPECT_PRED4(HasCandidate, candidates_, "local", "udp", kPrivateAddr); | 1759 EXPECT_PRED4(HasCandidate, candidates_, "local", "udp", kPrivateAddr); |
1694 EXPECT_NE(0U, session_->flags() & PORTALLOCATOR_DISABLE_ADAPTER_ENUMERATION); | 1760 EXPECT_NE(0U, session_->flags() & PORTALLOCATOR_DISABLE_ADAPTER_ENUMERATION); |
1695 } | 1761 } |
1696 | 1762 |
1697 // This test verifies allocator can use IPv6 addresses along with IPv4. | 1763 // This test verifies allocator can use IPv6 addresses along with IPv4. |
1698 TEST_F(BasicPortAllocatorTest, TestEnableIPv6Addresses) { | 1764 TEST_F(BasicPortAllocatorTest, TestEnableIPv6Addresses) { |
1699 allocator().set_flags(allocator().flags() | PORTALLOCATOR_DISABLE_RELAY | | 1765 allocator().set_flags(allocator().flags() | PORTALLOCATOR_DISABLE_RELAY | |
1700 PORTALLOCATOR_ENABLE_IPV6 | | 1766 PORTALLOCATOR_ENABLE_IPV6 | |
1701 PORTALLOCATOR_ENABLE_SHARED_SOCKET); | 1767 PORTALLOCATOR_ENABLE_SHARED_SOCKET); |
1702 AddInterface(kClientIPv6Addr); | 1768 AddInterface(kClientIPv6Addr); |
1703 AddInterface(kClientAddr); | 1769 AddInterface(kClientAddr); |
1704 allocator_->set_step_delay(kMinimumStepDelay); | 1770 allocator_->set_step_delay(kMinimumStepDelay); |
1705 EXPECT_TRUE(CreateSession(ICE_CANDIDATE_COMPONENT_RTP)); | 1771 EXPECT_TRUE(CreateSession(ICE_CANDIDATE_COMPONENT_RTP)); |
1706 session_->StartGettingPorts(); | 1772 session_->StartGettingPorts(); |
1707 ASSERT_EQ_WAIT(4U, ports_.size(), kDefaultAllocationTimeout); | 1773 ASSERT_EQ_SIMULATED_WAIT(4U, ports_.size(), kDefaultAllocationTimeout, |
| 1774 fake_clock); |
1708 EXPECT_EQ(4U, candidates_.size()); | 1775 EXPECT_EQ(4U, candidates_.size()); |
1709 EXPECT_TRUE_WAIT(candidate_allocation_done_, kDefaultAllocationTimeout); | 1776 EXPECT_TRUE_SIMULATED_WAIT(candidate_allocation_done_, |
| 1777 kDefaultAllocationTimeout, fake_clock); |
1710 EXPECT_PRED4(HasCandidate, candidates_, "local", "udp", kClientIPv6Addr); | 1778 EXPECT_PRED4(HasCandidate, candidates_, "local", "udp", kClientIPv6Addr); |
1711 EXPECT_PRED4(HasCandidate, candidates_, "local", "udp", kClientAddr); | 1779 EXPECT_PRED4(HasCandidate, candidates_, "local", "udp", kClientAddr); |
1712 EXPECT_PRED4(HasCandidate, candidates_, "local", "tcp", kClientIPv6Addr); | 1780 EXPECT_PRED4(HasCandidate, candidates_, "local", "tcp", kClientIPv6Addr); |
1713 EXPECT_PRED4(HasCandidate, candidates_, "local", "tcp", kClientAddr); | 1781 EXPECT_PRED4(HasCandidate, candidates_, "local", "tcp", kClientAddr); |
1714 EXPECT_EQ(4U, candidates_.size()); | 1782 EXPECT_EQ(4U, candidates_.size()); |
1715 } | 1783 } |
1716 | 1784 |
1717 TEST_F(BasicPortAllocatorTest, TestStopGettingPorts) { | 1785 TEST_F(BasicPortAllocatorTest, TestStopGettingPorts) { |
1718 AddInterface(kClientAddr); | 1786 AddInterface(kClientAddr); |
1719 allocator_->set_step_delay(kDefaultStepDelay); | 1787 allocator_->set_step_delay(kDefaultStepDelay); |
1720 EXPECT_TRUE(CreateSession(ICE_CANDIDATE_COMPONENT_RTP)); | 1788 EXPECT_TRUE(CreateSession(ICE_CANDIDATE_COMPONENT_RTP)); |
1721 session_->StartGettingPorts(); | 1789 session_->StartGettingPorts(); |
1722 ASSERT_EQ_WAIT(2U, candidates_.size(), 1000); | 1790 ASSERT_EQ_SIMULATED_WAIT(2U, candidates_.size(), 1000, fake_clock); |
1723 EXPECT_EQ(2U, ports_.size()); | 1791 EXPECT_EQ(2U, ports_.size()); |
1724 session_->StopGettingPorts(); | 1792 session_->StopGettingPorts(); |
1725 EXPECT_TRUE_WAIT(candidate_allocation_done_, 1000); | 1793 EXPECT_TRUE_SIMULATED_WAIT(candidate_allocation_done_, 1000, fake_clock); |
1726 | 1794 |
1727 // After stopping getting ports, adding a new interface will not start | 1795 // After stopping getting ports, adding a new interface will not start |
1728 // getting ports again. | 1796 // getting ports again. |
1729 allocator_->set_step_delay(kMinimumStepDelay); | 1797 allocator_->set_step_delay(kMinimumStepDelay); |
1730 candidates_.clear(); | 1798 candidates_.clear(); |
1731 ports_.clear(); | 1799 ports_.clear(); |
1732 candidate_allocation_done_ = false; | 1800 candidate_allocation_done_ = false; |
1733 network_manager_.AddInterface(kClientAddr2); | 1801 network_manager_.AddInterface(kClientAddr2); |
1734 rtc::Thread::Current()->ProcessMessages(1000); | 1802 SIMULATED_WAIT(false, 1000, fake_clock); |
1735 EXPECT_EQ(0U, candidates_.size()); | 1803 EXPECT_EQ(0U, candidates_.size()); |
1736 EXPECT_EQ(0U, ports_.size()); | 1804 EXPECT_EQ(0U, ports_.size()); |
1737 } | 1805 } |
1738 | 1806 |
1739 TEST_F(BasicPortAllocatorTest, TestClearGettingPorts) { | 1807 TEST_F(BasicPortAllocatorTest, TestClearGettingPorts) { |
1740 AddInterface(kClientAddr); | 1808 AddInterface(kClientAddr); |
1741 allocator_->set_step_delay(kDefaultStepDelay); | 1809 allocator_->set_step_delay(kDefaultStepDelay); |
1742 EXPECT_TRUE(CreateSession(ICE_CANDIDATE_COMPONENT_RTP)); | 1810 EXPECT_TRUE(CreateSession(ICE_CANDIDATE_COMPONENT_RTP)); |
1743 session_->StartGettingPorts(); | 1811 session_->StartGettingPorts(); |
1744 ASSERT_EQ_WAIT(2U, candidates_.size(), 1000); | 1812 ASSERT_EQ_SIMULATED_WAIT(2U, candidates_.size(), 1000, fake_clock); |
1745 EXPECT_EQ(2U, ports_.size()); | 1813 EXPECT_EQ(2U, ports_.size()); |
1746 session_->ClearGettingPorts(); | 1814 session_->ClearGettingPorts(); |
1747 EXPECT_TRUE_WAIT(candidate_allocation_done_, 1000); | 1815 EXPECT_TRUE_SIMULATED_WAIT(candidate_allocation_done_, 1000, fake_clock); |
1748 | 1816 |
1749 // After clearing getting ports, adding a new interface will start getting | 1817 // After clearing getting ports, adding a new interface will start getting |
1750 // ports again. | 1818 // ports again. |
1751 allocator_->set_step_delay(kMinimumStepDelay); | 1819 allocator_->set_step_delay(kMinimumStepDelay); |
1752 candidates_.clear(); | 1820 candidates_.clear(); |
1753 ports_.clear(); | 1821 ports_.clear(); |
1754 candidate_allocation_done_ = false; | 1822 candidate_allocation_done_ = false; |
1755 network_manager_.AddInterface(kClientAddr2); | 1823 network_manager_.AddInterface(kClientAddr2); |
1756 ASSERT_EQ_WAIT(2U, candidates_.size(), 1000); | 1824 ASSERT_EQ_SIMULATED_WAIT(2U, candidates_.size(), 1000, fake_clock); |
1757 EXPECT_EQ(2U, ports_.size()); | 1825 EXPECT_EQ(2U, ports_.size()); |
1758 EXPECT_TRUE_WAIT(candidate_allocation_done_, kDefaultAllocationTimeout); | 1826 EXPECT_TRUE_SIMULATED_WAIT(candidate_allocation_done_, |
| 1827 kDefaultAllocationTimeout, fake_clock); |
1759 } | 1828 } |
1760 | 1829 |
1761 // Test that the ports and candidates are updated with new ufrag/pwd/etc. when | 1830 // Test that the ports and candidates are updated with new ufrag/pwd/etc. when |
1762 // a pooled session is taken out of the pool. | 1831 // a pooled session is taken out of the pool. |
1763 TEST_F(BasicPortAllocatorTest, TestTransportInformationUpdated) { | 1832 TEST_F(BasicPortAllocatorTest, TestTransportInformationUpdated) { |
1764 AddInterface(kClientAddr); | 1833 AddInterface(kClientAddr); |
1765 int pool_size = 1; | 1834 int pool_size = 1; |
1766 allocator_->SetConfiguration(allocator_->stun_servers(), | 1835 allocator_->SetConfiguration(allocator_->stun_servers(), |
1767 allocator_->turn_servers(), pool_size, false); | 1836 allocator_->turn_servers(), pool_size, false); |
1768 const PortAllocatorSession* peeked_session = allocator_->GetPooledSession(); | 1837 const PortAllocatorSession* peeked_session = allocator_->GetPooledSession(); |
1769 ASSERT_NE(nullptr, peeked_session); | 1838 ASSERT_NE(nullptr, peeked_session); |
1770 EXPECT_EQ_WAIT(true, peeked_session->CandidatesAllocationDone(), | 1839 EXPECT_EQ_SIMULATED_WAIT(true, peeked_session->CandidatesAllocationDone(), |
1771 kDefaultAllocationTimeout); | 1840 kDefaultAllocationTimeout, fake_clock); |
1772 // Expect that when TakePooledSession is called, | 1841 // Expect that when TakePooledSession is called, |
1773 // UpdateTransportInformationInternal will be called and the | 1842 // UpdateTransportInformationInternal will be called and the |
1774 // BasicPortAllocatorSession will update the ufrag/pwd of ports and | 1843 // BasicPortAllocatorSession will update the ufrag/pwd of ports and |
1775 // candidates. | 1844 // candidates. |
1776 session_ = | 1845 session_ = |
1777 allocator_->TakePooledSession(kContentName, 1, kIceUfrag0, kIcePwd0); | 1846 allocator_->TakePooledSession(kContentName, 1, kIceUfrag0, kIcePwd0); |
1778 ASSERT_NE(nullptr, session_.get()); | 1847 ASSERT_NE(nullptr, session_.get()); |
1779 auto ready_ports = session_->ReadyPorts(); | 1848 auto ready_ports = session_->ReadyPorts(); |
1780 auto candidates = session_->ReadyCandidates(); | 1849 auto candidates = session_->ReadyCandidates(); |
1781 EXPECT_FALSE(ready_ports.empty()); | 1850 EXPECT_FALSE(ready_ports.empty()); |
(...skipping 14 matching lines...) Expand all Loading... |
1796 | 1865 |
1797 // Test that a new candidate filter takes effect even on already-gathered | 1866 // Test that a new candidate filter takes effect even on already-gathered |
1798 // candidates. | 1867 // candidates. |
1799 TEST_F(BasicPortAllocatorTest, TestSetCandidateFilterAfterCandidatesGathered) { | 1868 TEST_F(BasicPortAllocatorTest, TestSetCandidateFilterAfterCandidatesGathered) { |
1800 AddInterface(kClientAddr); | 1869 AddInterface(kClientAddr); |
1801 int pool_size = 1; | 1870 int pool_size = 1; |
1802 allocator_->SetConfiguration(allocator_->stun_servers(), | 1871 allocator_->SetConfiguration(allocator_->stun_servers(), |
1803 allocator_->turn_servers(), pool_size, false); | 1872 allocator_->turn_servers(), pool_size, false); |
1804 const PortAllocatorSession* peeked_session = allocator_->GetPooledSession(); | 1873 const PortAllocatorSession* peeked_session = allocator_->GetPooledSession(); |
1805 ASSERT_NE(nullptr, peeked_session); | 1874 ASSERT_NE(nullptr, peeked_session); |
1806 EXPECT_EQ_WAIT(true, peeked_session->CandidatesAllocationDone(), | 1875 EXPECT_EQ_SIMULATED_WAIT(true, peeked_session->CandidatesAllocationDone(), |
1807 kDefaultAllocationTimeout); | 1876 kDefaultAllocationTimeout, fake_clock); |
1808 size_t initial_candidates_size = peeked_session->ReadyCandidates().size(); | 1877 size_t initial_candidates_size = peeked_session->ReadyCandidates().size(); |
1809 size_t initial_ports_size = peeked_session->ReadyPorts().size(); | 1878 size_t initial_ports_size = peeked_session->ReadyPorts().size(); |
1810 allocator_->set_candidate_filter(CF_RELAY); | 1879 allocator_->set_candidate_filter(CF_RELAY); |
1811 // Assume that when TakePooledSession is called, the candidate filter will be | 1880 // Assume that when TakePooledSession is called, the candidate filter will be |
1812 // applied to the pooled session. This is tested by PortAllocatorTest. | 1881 // applied to the pooled session. This is tested by PortAllocatorTest. |
1813 session_ = | 1882 session_ = |
1814 allocator_->TakePooledSession(kContentName, 1, kIceUfrag0, kIcePwd0); | 1883 allocator_->TakePooledSession(kContentName, 1, kIceUfrag0, kIcePwd0); |
1815 ASSERT_NE(nullptr, session_.get()); | 1884 ASSERT_NE(nullptr, session_.get()); |
1816 auto candidates = session_->ReadyCandidates(); | 1885 auto candidates = session_->ReadyCandidates(); |
1817 auto ports = session_->ReadyPorts(); | 1886 auto ports = session_->ReadyPorts(); |
1818 // Sanity check that the number of candidates and ports decreased. | 1887 // Sanity check that the number of candidates and ports decreased. |
1819 EXPECT_GT(initial_candidates_size, candidates.size()); | 1888 EXPECT_GT(initial_candidates_size, candidates.size()); |
1820 EXPECT_GT(initial_ports_size, ports.size()); | 1889 EXPECT_GT(initial_ports_size, ports.size()); |
1821 for (const PortInterface* port : ports) { | 1890 for (const PortInterface* port : ports) { |
1822 // Expect only relay ports. | 1891 // Expect only relay ports. |
1823 EXPECT_EQ(RELAY_PORT_TYPE, port->Type()); | 1892 EXPECT_EQ(RELAY_PORT_TYPE, port->Type()); |
1824 } | 1893 } |
1825 for (const Candidate& candidate : candidates) { | 1894 for (const Candidate& candidate : candidates) { |
1826 // Expect only relay candidates now that the filter is applied. | 1895 // Expect only relay candidates now that the filter is applied. |
1827 EXPECT_EQ(std::string(RELAY_PORT_TYPE), candidate.type()); | 1896 EXPECT_EQ(std::string(RELAY_PORT_TYPE), candidate.type()); |
1828 // Expect that the raddr is emptied due to the CF_RELAY filter. | 1897 // Expect that the raddr is emptied due to the CF_RELAY filter. |
1829 EXPECT_EQ(candidate.related_address(), | 1898 EXPECT_EQ(candidate.related_address(), |
1830 rtc::EmptySocketAddressWithFamily(candidate.address().family())); | 1899 rtc::EmptySocketAddressWithFamily(candidate.address().family())); |
1831 } | 1900 } |
1832 } | 1901 } |
1833 | 1902 |
1834 } // namespace cricket | 1903 } // namespace cricket |
OLD | NEW |