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 350 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
381 network_manager_.set_default_local_addresses(kPrivateAddr.ipaddr(), | 382 network_manager_.set_default_local_addresses(kPrivateAddr.ipaddr(), |
382 rtc::IPAddress()); | 383 rtc::IPAddress()); |
383 if (!session_) { | 384 if (!session_) { |
384 EXPECT_TRUE(CreateSession(ICE_CANDIDATE_COMPONENT_RTP)); | 385 EXPECT_TRUE(CreateSession(ICE_CANDIDATE_COMPONENT_RTP)); |
385 } | 386 } |
386 session_->set_flags(session_->flags() | | 387 session_->set_flags(session_->flags() | |
387 PORTALLOCATOR_DISABLE_ADAPTER_ENUMERATION | | 388 PORTALLOCATOR_DISABLE_ADAPTER_ENUMERATION | |
388 PORTALLOCATOR_ENABLE_SHARED_SOCKET); | 389 PORTALLOCATOR_ENABLE_SHARED_SOCKET); |
389 allocator().set_allow_tcp_listen(false); | 390 allocator().set_allow_tcp_listen(false); |
390 session_->StartGettingPorts(); | 391 session_->StartGettingPorts(); |
391 EXPECT_TRUE_WAIT(candidate_allocation_done_, kDefaultAllocationTimeout); | 392 EXPECT_TRUE_SIMULATED_WAIT(candidate_allocation_done_, |
393 kDefaultAllocationTimeout, fake_clock); | |
392 | 394 |
393 uint32_t total_candidates = 0; | 395 uint32_t total_candidates = 0; |
394 if (!host_candidate_addr.IsNil()) { | 396 if (!host_candidate_addr.IsNil()) { |
395 EXPECT_PRED4(HasCandidate, candidates_, "local", "udp", | 397 EXPECT_PRED4(HasCandidate, candidates_, "local", "udp", |
396 rtc::SocketAddress(kPrivateAddr.ipaddr(), 0)); | 398 rtc::SocketAddress(kPrivateAddr.ipaddr(), 0)); |
397 ++total_candidates; | 399 ++total_candidates; |
398 } | 400 } |
399 if (!stun_candidate_addr.IsNil()) { | 401 if (!stun_candidate_addr.IsNil()) { |
400 rtc::SocketAddress related_address(host_candidate_addr, 0); | 402 rtc::SocketAddress related_address(host_candidate_addr, 0); |
401 if (host_candidate_addr.IsNil()) { | 403 if (host_candidate_addr.IsNil()) { |
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
521 allocator_->SetConfiguration(allocator_->stun_servers(), | 523 allocator_->SetConfiguration(allocator_->stun_servers(), |
522 allocator_->turn_servers(), 0, true); | 524 allocator_->turn_servers(), 0, true); |
523 AddTurnServers(kTurnUdpIntAddr, kTurnTcpIntAddr); | 525 AddTurnServers(kTurnUdpIntAddr, kTurnTcpIntAddr); |
524 allocator_->set_step_delay(kMinimumStepDelay); | 526 allocator_->set_step_delay(kMinimumStepDelay); |
525 allocator_->set_flags(allocator().flags() | | 527 allocator_->set_flags(allocator().flags() | |
526 PORTALLOCATOR_ENABLE_SHARED_SOCKET | | 528 PORTALLOCATOR_ENABLE_SHARED_SOCKET | |
527 PORTALLOCATOR_DISABLE_TCP); | 529 PORTALLOCATOR_DISABLE_TCP); |
528 | 530 |
529 EXPECT_TRUE(CreateSession(ICE_CANDIDATE_COMPONENT_RTP)); | 531 EXPECT_TRUE(CreateSession(ICE_CANDIDATE_COMPONENT_RTP)); |
530 session_->StartGettingPorts(); | 532 session_->StartGettingPorts(); |
531 EXPECT_TRUE_WAIT(candidate_allocation_done_, kDefaultAllocationTimeout); | 533 EXPECT_TRUE_SIMULATED_WAIT(candidate_allocation_done_, |
534 kDefaultAllocationTimeout, fake_clock); | |
532 // Only 2 ports (one STUN and one TURN) are actually being used. | 535 // Only 2 ports (one STUN and one TURN) are actually being used. |
533 EXPECT_EQ(2U, session_->ReadyPorts().size()); | 536 EXPECT_EQ(2U, session_->ReadyPorts().size()); |
534 // We have verified that each port, when it is added to |ports_|, it is | 537 // 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 | 538 // 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. | 539 // |ready_ports|, so we only need to verify the content in one of them. |
537 EXPECT_EQ(2U, ports_.size()); | 540 EXPECT_EQ(2U, ports_.size()); |
538 EXPECT_EQ(1, CountPorts(ports_, "local", PROTO_UDP, kClientAddr)); | 541 EXPECT_EQ(1, CountPorts(ports_, "local", PROTO_UDP, kClientAddr)); |
539 EXPECT_EQ(1, CountPorts(ports_, "relay", PROTO_UDP, kClientAddr)); | 542 EXPECT_EQ(1, CountPorts(ports_, "relay", PROTO_UDP, kClientAddr)); |
540 EXPECT_EQ(0, CountPorts(ports_, "relay", PROTO_TCP, kClientAddr)); | 543 EXPECT_EQ(0, CountPorts(ports_, "relay", PROTO_TCP, kClientAddr)); |
541 | 544 |
(...skipping 22 matching lines...) Expand all Loading... | |
564 AddTurnServers(kTurnUdpIntIPv6Addr, rtc::SocketAddress()); | 567 AddTurnServers(kTurnUdpIntIPv6Addr, rtc::SocketAddress()); |
565 AddTurnServers(kTurnUdpIntAddr, rtc::SocketAddress()); | 568 AddTurnServers(kTurnUdpIntAddr, rtc::SocketAddress()); |
566 | 569 |
567 allocator_->set_step_delay(kMinimumStepDelay); | 570 allocator_->set_step_delay(kMinimumStepDelay); |
568 allocator_->set_flags( | 571 allocator_->set_flags( |
569 allocator().flags() | PORTALLOCATOR_ENABLE_SHARED_SOCKET | | 572 allocator().flags() | PORTALLOCATOR_ENABLE_SHARED_SOCKET | |
570 PORTALLOCATOR_ENABLE_IPV6 | PORTALLOCATOR_DISABLE_TCP); | 573 PORTALLOCATOR_ENABLE_IPV6 | PORTALLOCATOR_DISABLE_TCP); |
571 | 574 |
572 EXPECT_TRUE(CreateSession(ICE_CANDIDATE_COMPONENT_RTP)); | 575 EXPECT_TRUE(CreateSession(ICE_CANDIDATE_COMPONENT_RTP)); |
573 session_->StartGettingPorts(); | 576 session_->StartGettingPorts(); |
574 EXPECT_TRUE_WAIT(candidate_allocation_done_, kDefaultAllocationTimeout); | 577 EXPECT_TRUE_SIMULATED_WAIT(candidate_allocation_done_, |
578 kDefaultAllocationTimeout, fake_clock); | |
575 // Three ports (one IPv4 STUN, one IPv6 STUN and one TURN) will be ready. | 579 // Three ports (one IPv4 STUN, one IPv6 STUN and one TURN) will be ready. |
576 EXPECT_EQ(3U, session_->ReadyPorts().size()); | 580 EXPECT_EQ(3U, session_->ReadyPorts().size()); |
577 EXPECT_EQ(3U, ports_.size()); | 581 EXPECT_EQ(3U, ports_.size()); |
578 EXPECT_EQ(1, CountPorts(ports_, "local", PROTO_UDP, kClientAddr)); | 582 EXPECT_EQ(1, CountPorts(ports_, "local", PROTO_UDP, kClientAddr)); |
579 EXPECT_EQ(1, CountPorts(ports_, "local", PROTO_UDP, kClientIPv6Addr)); | 583 EXPECT_EQ(1, CountPorts(ports_, "local", PROTO_UDP, kClientIPv6Addr)); |
580 EXPECT_EQ(1, CountPorts(ports_, "relay", PROTO_UDP, kClientIPv6Addr)); | 584 EXPECT_EQ(1, CountPorts(ports_, "relay", PROTO_UDP, kClientIPv6Addr)); |
581 EXPECT_EQ(0, CountPorts(ports_, "relay", PROTO_UDP, kClientAddr)); | 585 EXPECT_EQ(0, CountPorts(ports_, "relay", PROTO_UDP, kClientAddr)); |
582 | 586 |
583 // Now that we remove candidates when a TURN port is pruned, there will be | 587 // Now that we remove candidates when a TURN port is pruned, there will be |
584 // exactly 3 candidates in both |candidates_| and |ready_candidates|. | 588 // exactly 3 candidates in both |candidates_| and |ready_candidates|. |
(...skipping 21 matching lines...) Expand all Loading... | |
606 // Have both UDP/TCP and IPv4/IPv6 TURN ports. | 610 // Have both UDP/TCP and IPv4/IPv6 TURN ports. |
607 AddTurnServers(kTurnUdpIntAddr, kTurnTcpIntAddr); | 611 AddTurnServers(kTurnUdpIntAddr, kTurnTcpIntAddr); |
608 AddTurnServers(kTurnUdpIntIPv6Addr, kTurnTcpIntIPv6Addr); | 612 AddTurnServers(kTurnUdpIntIPv6Addr, kTurnTcpIntIPv6Addr); |
609 | 613 |
610 allocator_->set_step_delay(kMinimumStepDelay); | 614 allocator_->set_step_delay(kMinimumStepDelay); |
611 allocator_->set_flags(allocator().flags() | | 615 allocator_->set_flags(allocator().flags() | |
612 PORTALLOCATOR_ENABLE_SHARED_SOCKET | | 616 PORTALLOCATOR_ENABLE_SHARED_SOCKET | |
613 PORTALLOCATOR_ENABLE_IPV6); | 617 PORTALLOCATOR_ENABLE_IPV6); |
614 EXPECT_TRUE(CreateSession(ICE_CANDIDATE_COMPONENT_RTP)); | 618 EXPECT_TRUE(CreateSession(ICE_CANDIDATE_COMPONENT_RTP)); |
615 session_->StartGettingPorts(); | 619 session_->StartGettingPorts(); |
616 EXPECT_TRUE_WAIT(candidate_allocation_done_, kDefaultAllocationTimeout); | 620 EXPECT_TRUE_SIMULATED_WAIT(candidate_allocation_done_, |
621 kDefaultAllocationTimeout, fake_clock); | |
617 // 10 ports (4 STUN and 1 TURN ports on each interface) will be ready to | 622 // 10 ports (4 STUN and 1 TURN ports on each interface) will be ready to |
618 // use. | 623 // use. |
619 EXPECT_EQ(10U, session_->ReadyPorts().size()); | 624 EXPECT_EQ(10U, session_->ReadyPorts().size()); |
620 EXPECT_EQ(10U, ports_.size()); | 625 EXPECT_EQ(10U, ports_.size()); |
621 EXPECT_EQ(1, CountPorts(ports_, "local", PROTO_UDP, kClientAddr)); | 626 EXPECT_EQ(1, CountPorts(ports_, "local", PROTO_UDP, kClientAddr)); |
622 EXPECT_EQ(1, CountPorts(ports_, "local", PROTO_UDP, kClientAddr2)); | 627 EXPECT_EQ(1, CountPorts(ports_, "local", PROTO_UDP, kClientAddr2)); |
623 EXPECT_EQ(1, CountPorts(ports_, "local", PROTO_UDP, kClientIPv6Addr)); | 628 EXPECT_EQ(1, CountPorts(ports_, "local", PROTO_UDP, kClientIPv6Addr)); |
624 EXPECT_EQ(1, CountPorts(ports_, "local", PROTO_UDP, kClientIPv6Addr2)); | 629 EXPECT_EQ(1, CountPorts(ports_, "local", PROTO_UDP, kClientIPv6Addr2)); |
625 EXPECT_EQ(1, CountPorts(ports_, "local", PROTO_TCP, kClientAddr)); | 630 EXPECT_EQ(1, CountPorts(ports_, "local", PROTO_TCP, kClientAddr)); |
626 EXPECT_EQ(1, CountPorts(ports_, "local", PROTO_TCP, kClientAddr2)); | 631 EXPECT_EQ(1, CountPorts(ports_, "local", PROTO_TCP, kClientAddr2)); |
(...skipping 17 matching lines...) Expand all Loading... | |
644 EXPECT_PRED4(HasCandidate, ready_candidates, "local", "tcp", kClientAddr); | 649 EXPECT_PRED4(HasCandidate, ready_candidates, "local", "tcp", kClientAddr); |
645 EXPECT_PRED4(HasCandidate, ready_candidates, "local", "tcp", kClientAddr2); | 650 EXPECT_PRED4(HasCandidate, ready_candidates, "local", "tcp", kClientAddr2); |
646 EXPECT_PRED4(HasCandidate, ready_candidates, "local", "tcp", | 651 EXPECT_PRED4(HasCandidate, ready_candidates, "local", "tcp", |
647 kClientIPv6Addr); | 652 kClientIPv6Addr); |
648 EXPECT_PRED4(HasCandidate, ready_candidates, "local", "tcp", | 653 EXPECT_PRED4(HasCandidate, ready_candidates, "local", "tcp", |
649 kClientIPv6Addr2); | 654 kClientIPv6Addr2); |
650 EXPECT_PRED4(HasCandidate, ready_candidates, "relay", "udp", | 655 EXPECT_PRED4(HasCandidate, ready_candidates, "relay", "udp", |
651 rtc::SocketAddress(kTurnUdpExtAddr.ipaddr(), 0)); | 656 rtc::SocketAddress(kTurnUdpExtAddr.ipaddr(), 0)); |
652 } | 657 } |
653 | 658 |
659 rtc::ScopedFakeClock fake_clock; | |
654 std::unique_ptr<rtc::PhysicalSocketServer> pss_; | 660 std::unique_ptr<rtc::PhysicalSocketServer> pss_; |
655 std::unique_ptr<rtc::VirtualSocketServer> vss_; | 661 std::unique_ptr<rtc::VirtualSocketServer> vss_; |
656 std::unique_ptr<rtc::FirewallSocketServer> fss_; | 662 std::unique_ptr<rtc::FirewallSocketServer> fss_; |
657 rtc::SocketServerScope ss_scope_; | 663 rtc::SocketServerScope ss_scope_; |
658 std::unique_ptr<rtc::NATServer> nat_server_; | 664 std::unique_ptr<rtc::NATServer> nat_server_; |
659 rtc::NATSocketFactory nat_factory_; | 665 rtc::NATSocketFactory nat_factory_; |
660 std::unique_ptr<rtc::BasicPacketSocketFactory> nat_socket_factory_; | 666 std::unique_ptr<rtc::BasicPacketSocketFactory> nat_socket_factory_; |
661 std::unique_ptr<TestStunServer> stun_server_; | 667 std::unique_ptr<TestStunServer> stun_server_; |
662 TestRelayServer relay_server_; | 668 TestRelayServer relay_server_; |
663 TestTurnServer turn_server_; | 669 TestTurnServer turn_server_; |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
695 AddInterface(SocketAddress(IPAddress(0x12345602U), 0), "test_cell0", | 701 AddInterface(SocketAddress(IPAddress(0x12345602U), 0), "test_cell0", |
696 rtc::ADAPTER_TYPE_CELLULAR); | 702 rtc::ADAPTER_TYPE_CELLULAR); |
697 AddInterface(SocketAddress(IPAddress(0x12345603U), 0), "test_vpn0", | 703 AddInterface(SocketAddress(IPAddress(0x12345603U), 0), "test_vpn0", |
698 rtc::ADAPTER_TYPE_VPN); | 704 rtc::ADAPTER_TYPE_VPN); |
699 AddInterface(SocketAddress(IPAddress(0x12345604U), 0), "test_lo", | 705 AddInterface(SocketAddress(IPAddress(0x12345604U), 0), "test_lo", |
700 rtc::ADAPTER_TYPE_LOOPBACK); | 706 rtc::ADAPTER_TYPE_LOOPBACK); |
701 EXPECT_TRUE(CreateSession(ICE_CANDIDATE_COMPONENT_RTP)); | 707 EXPECT_TRUE(CreateSession(ICE_CANDIDATE_COMPONENT_RTP)); |
702 session_->set_flags(PORTALLOCATOR_DISABLE_STUN | PORTALLOCATOR_DISABLE_RELAY | | 708 session_->set_flags(PORTALLOCATOR_DISABLE_STUN | PORTALLOCATOR_DISABLE_RELAY | |
703 PORTALLOCATOR_DISABLE_TCP); | 709 PORTALLOCATOR_DISABLE_TCP); |
704 session_->StartGettingPorts(); | 710 session_->StartGettingPorts(); |
705 EXPECT_TRUE_WAIT(candidate_allocation_done_, kDefaultAllocationTimeout); | 711 EXPECT_TRUE_SIMULATED_WAIT(candidate_allocation_done_, |
712 kDefaultAllocationTimeout, fake_clock); | |
706 EXPECT_EQ(4U, candidates_.size()); | 713 EXPECT_EQ(4U, candidates_.size()); |
707 for (Candidate candidate : candidates_) { | 714 for (Candidate candidate : candidates_) { |
708 EXPECT_LT(candidate.address().ip(), 0x12345604U); | 715 EXPECT_LT(candidate.address().ip(), 0x12345604U); |
709 } | 716 } |
710 } | 717 } |
711 | 718 |
712 TEST_F(BasicPortAllocatorTest, TestIgnoreNetworksAccordingToIgnoreMask) { | 719 TEST_F(BasicPortAllocatorTest, TestIgnoreNetworksAccordingToIgnoreMask) { |
713 AddInterface(SocketAddress(IPAddress(0x12345600U), 0), "test_eth0", | 720 AddInterface(SocketAddress(IPAddress(0x12345600U), 0), "test_eth0", |
714 rtc::ADAPTER_TYPE_ETHERNET); | 721 rtc::ADAPTER_TYPE_ETHERNET); |
715 AddInterface(SocketAddress(IPAddress(0x12345601U), 0), "test_wlan0", | 722 AddInterface(SocketAddress(IPAddress(0x12345601U), 0), "test_wlan0", |
716 rtc::ADAPTER_TYPE_WIFI); | 723 rtc::ADAPTER_TYPE_WIFI); |
717 AddInterface(SocketAddress(IPAddress(0x12345602U), 0), "test_cell0", | 724 AddInterface(SocketAddress(IPAddress(0x12345602U), 0), "test_cell0", |
718 rtc::ADAPTER_TYPE_CELLULAR); | 725 rtc::ADAPTER_TYPE_CELLULAR); |
719 allocator_->SetNetworkIgnoreMask(rtc::ADAPTER_TYPE_ETHERNET | | 726 allocator_->SetNetworkIgnoreMask(rtc::ADAPTER_TYPE_ETHERNET | |
720 rtc::ADAPTER_TYPE_LOOPBACK | | 727 rtc::ADAPTER_TYPE_LOOPBACK | |
721 rtc::ADAPTER_TYPE_WIFI); | 728 rtc::ADAPTER_TYPE_WIFI); |
722 EXPECT_TRUE(CreateSession(ICE_CANDIDATE_COMPONENT_RTP)); | 729 EXPECT_TRUE(CreateSession(ICE_CANDIDATE_COMPONENT_RTP)); |
723 session_->set_flags(PORTALLOCATOR_DISABLE_STUN | PORTALLOCATOR_DISABLE_RELAY | | 730 session_->set_flags(PORTALLOCATOR_DISABLE_STUN | PORTALLOCATOR_DISABLE_RELAY | |
724 PORTALLOCATOR_DISABLE_TCP); | 731 PORTALLOCATOR_DISABLE_TCP); |
725 session_->StartGettingPorts(); | 732 session_->StartGettingPorts(); |
726 EXPECT_TRUE_WAIT(candidate_allocation_done_, kDefaultAllocationTimeout); | 733 EXPECT_TRUE_SIMULATED_WAIT(candidate_allocation_done_, |
734 kDefaultAllocationTimeout, fake_clock); | |
727 EXPECT_EQ(1U, candidates_.size()); | 735 EXPECT_EQ(1U, candidates_.size()); |
728 EXPECT_EQ(0x12345602U, candidates_[0].address().ip()); | 736 EXPECT_EQ(0x12345602U, candidates_[0].address().ip()); |
729 } | 737 } |
730 | 738 |
731 // Test that high cost networks are filtered if the flag | 739 // Test that high cost networks are filtered if the flag |
732 // PORTALLOCATOR_DISABLE_COSTLY_NETWORKS is set. | 740 // PORTALLOCATOR_DISABLE_COSTLY_NETWORKS is set. |
733 TEST_F(BasicPortAllocatorTest, TestGatherLowCostNetworkOnly) { | 741 TEST_F(BasicPortAllocatorTest, TestGatherLowCostNetworkOnly) { |
734 SocketAddress addr_wifi(IPAddress(0x12345600U), 0); | 742 SocketAddress addr_wifi(IPAddress(0x12345600U), 0); |
735 SocketAddress addr_cellular(IPAddress(0x12345601U), 0); | 743 SocketAddress addr_cellular(IPAddress(0x12345601U), 0); |
736 SocketAddress addr_unknown1(IPAddress(0x12345602U), 0); | 744 SocketAddress addr_unknown1(IPAddress(0x12345602U), 0); |
737 SocketAddress addr_unknown2(IPAddress(0x12345603U), 0); | 745 SocketAddress addr_unknown2(IPAddress(0x12345603U), 0); |
738 // If both Wi-Fi and cellular interfaces are present, only gather on the Wi-Fi | 746 // If both Wi-Fi and cellular interfaces are present, only gather on the Wi-Fi |
739 // interface. | 747 // interface. |
740 AddInterface(addr_wifi, "test_wlan0", rtc::ADAPTER_TYPE_WIFI); | 748 AddInterface(addr_wifi, "test_wlan0", rtc::ADAPTER_TYPE_WIFI); |
741 AddInterface(addr_cellular, "test_cell0", rtc::ADAPTER_TYPE_CELLULAR); | 749 AddInterface(addr_cellular, "test_cell0", rtc::ADAPTER_TYPE_CELLULAR); |
742 allocator().set_flags(cricket::PORTALLOCATOR_DISABLE_STUN | | 750 allocator().set_flags(cricket::PORTALLOCATOR_DISABLE_STUN | |
743 cricket::PORTALLOCATOR_DISABLE_RELAY | | 751 cricket::PORTALLOCATOR_DISABLE_RELAY | |
744 cricket::PORTALLOCATOR_DISABLE_TCP | | 752 cricket::PORTALLOCATOR_DISABLE_TCP | |
745 cricket::PORTALLOCATOR_DISABLE_COSTLY_NETWORKS); | 753 cricket::PORTALLOCATOR_DISABLE_COSTLY_NETWORKS); |
746 EXPECT_TRUE(CreateSession(cricket::ICE_CANDIDATE_COMPONENT_RTP)); | 754 EXPECT_TRUE(CreateSession(cricket::ICE_CANDIDATE_COMPONENT_RTP)); |
747 session_->StartGettingPorts(); | 755 session_->StartGettingPorts(); |
748 EXPECT_TRUE_WAIT(candidate_allocation_done_, kDefaultAllocationTimeout); | 756 EXPECT_TRUE_SIMULATED_WAIT(candidate_allocation_done_, |
757 kDefaultAllocationTimeout, fake_clock); | |
749 EXPECT_EQ(1U, candidates_.size()); | 758 EXPECT_EQ(1U, candidates_.size()); |
750 EXPECT_TRUE(addr_wifi.EqualIPs(candidates_[0].address())); | 759 EXPECT_TRUE(addr_wifi.EqualIPs(candidates_[0].address())); |
751 | 760 |
752 // If both cellular and unknown interfaces are present, only gather on the | 761 // If both cellular and unknown interfaces are present, only gather on the |
753 // unknown interfaces. | 762 // unknown interfaces. |
754 candidates_.clear(); | 763 candidates_.clear(); |
755 candidate_allocation_done_ = false; | 764 candidate_allocation_done_ = false; |
756 RemoveInterface(addr_wifi); | 765 RemoveInterface(addr_wifi); |
757 AddInterface(addr_unknown1, "test_unknown0", rtc::ADAPTER_TYPE_UNKNOWN); | 766 AddInterface(addr_unknown1, "test_unknown0", rtc::ADAPTER_TYPE_UNKNOWN); |
758 AddInterface(addr_unknown2, "test_unknown1", rtc::ADAPTER_TYPE_UNKNOWN); | 767 AddInterface(addr_unknown2, "test_unknown1", rtc::ADAPTER_TYPE_UNKNOWN); |
759 session_->StartGettingPorts(); | 768 session_->StartGettingPorts(); |
760 EXPECT_TRUE_WAIT(candidate_allocation_done_, kDefaultAllocationTimeout); | 769 EXPECT_TRUE_SIMULATED_WAIT(candidate_allocation_done_, |
770 kDefaultAllocationTimeout, fake_clock); | |
761 EXPECT_EQ(2U, candidates_.size()); | 771 EXPECT_EQ(2U, candidates_.size()); |
762 EXPECT_TRUE((addr_unknown1.EqualIPs(candidates_[0].address()) && | 772 EXPECT_TRUE((addr_unknown1.EqualIPs(candidates_[0].address()) && |
763 addr_unknown2.EqualIPs(candidates_[1].address())) || | 773 addr_unknown2.EqualIPs(candidates_[1].address())) || |
764 (addr_unknown1.EqualIPs(candidates_[1].address()) && | 774 (addr_unknown1.EqualIPs(candidates_[1].address()) && |
765 addr_unknown2.EqualIPs(candidates_[0].address()))); | 775 addr_unknown2.EqualIPs(candidates_[0].address()))); |
766 | 776 |
767 // If Wi-Fi, cellular, unknown interfaces are all present, only gather on the | 777 // If Wi-Fi, cellular, unknown interfaces are all present, only gather on the |
768 // Wi-Fi interface. | 778 // Wi-Fi interface. |
769 candidates_.clear(); | 779 candidates_.clear(); |
770 candidate_allocation_done_ = false; | 780 candidate_allocation_done_ = false; |
771 AddInterface(addr_wifi, "test_wlan0", rtc::ADAPTER_TYPE_WIFI); | 781 AddInterface(addr_wifi, "test_wlan0", rtc::ADAPTER_TYPE_WIFI); |
772 session_->StartGettingPorts(); | 782 session_->StartGettingPorts(); |
773 EXPECT_TRUE_WAIT(candidate_allocation_done_, kDefaultAllocationTimeout); | 783 EXPECT_TRUE_SIMULATED_WAIT(candidate_allocation_done_, |
784 kDefaultAllocationTimeout, fake_clock); | |
774 EXPECT_EQ(1U, candidates_.size()); | 785 EXPECT_EQ(1U, candidates_.size()); |
775 EXPECT_TRUE(addr_wifi.EqualIPs(candidates_[0].address())); | 786 EXPECT_TRUE(addr_wifi.EqualIPs(candidates_[0].address())); |
776 } | 787 } |
777 | 788 |
778 // Test that we could use loopback interface as host candidate. | 789 // Test that we could use loopback interface as host candidate. |
779 TEST_F(BasicPortAllocatorTest, TestLoopbackNetworkInterface) { | 790 TEST_F(BasicPortAllocatorTest, TestLoopbackNetworkInterface) { |
780 AddInterface(kLoopbackAddr, "test_loopback", rtc::ADAPTER_TYPE_LOOPBACK); | 791 AddInterface(kLoopbackAddr, "test_loopback", rtc::ADAPTER_TYPE_LOOPBACK); |
781 allocator_->SetNetworkIgnoreMask(0); | 792 allocator_->SetNetworkIgnoreMask(0); |
782 EXPECT_TRUE(CreateSession(ICE_CANDIDATE_COMPONENT_RTP)); | 793 EXPECT_TRUE(CreateSession(ICE_CANDIDATE_COMPONENT_RTP)); |
783 session_->set_flags(PORTALLOCATOR_DISABLE_STUN | PORTALLOCATOR_DISABLE_RELAY | | 794 session_->set_flags(PORTALLOCATOR_DISABLE_STUN | PORTALLOCATOR_DISABLE_RELAY | |
784 PORTALLOCATOR_DISABLE_TCP); | 795 PORTALLOCATOR_DISABLE_TCP); |
785 session_->StartGettingPorts(); | 796 session_->StartGettingPorts(); |
786 EXPECT_TRUE_WAIT(candidate_allocation_done_, kDefaultAllocationTimeout); | 797 EXPECT_TRUE_SIMULATED_WAIT(candidate_allocation_done_, |
798 kDefaultAllocationTimeout, fake_clock); | |
787 EXPECT_EQ(1U, candidates_.size()); | 799 EXPECT_EQ(1U, candidates_.size()); |
788 } | 800 } |
789 | 801 |
790 // Tests that we can get all the desired addresses successfully. | 802 // Tests that we can get all the desired addresses successfully. |
791 TEST_F(BasicPortAllocatorTest, TestGetAllPortsWithMinimumStepDelay) { | 803 TEST_F(BasicPortAllocatorTest, TestGetAllPortsWithMinimumStepDelay) { |
792 AddInterface(kClientAddr); | 804 AddInterface(kClientAddr); |
793 EXPECT_TRUE(CreateSession(ICE_CANDIDATE_COMPONENT_RTP)); | 805 EXPECT_TRUE(CreateSession(ICE_CANDIDATE_COMPONENT_RTP)); |
794 session_->StartGettingPorts(); | 806 session_->StartGettingPorts(); |
795 ASSERT_EQ_WAIT(7U, candidates_.size(), kDefaultAllocationTimeout); | 807 ASSERT_EQ_SIMULATED_WAIT(7U, candidates_.size(), kDefaultAllocationTimeout, |
808 fake_clock); | |
796 EXPECT_EQ(4U, ports_.size()); | 809 EXPECT_EQ(4U, ports_.size()); |
797 EXPECT_PRED4(HasCandidate, candidates_, "local", "udp", kClientAddr); | 810 EXPECT_PRED4(HasCandidate, candidates_, "local", "udp", kClientAddr); |
798 EXPECT_PRED4(HasCandidate, candidates_, "stun", "udp", kClientAddr); | 811 EXPECT_PRED4(HasCandidate, candidates_, "stun", "udp", kClientAddr); |
799 EXPECT_PRED4(HasCandidate, candidates_, "relay", "udp", kRelayUdpIntAddr); | 812 EXPECT_PRED4(HasCandidate, candidates_, "relay", "udp", kRelayUdpIntAddr); |
800 EXPECT_PRED4(HasCandidate, candidates_, "relay", "udp", kRelayUdpExtAddr); | 813 EXPECT_PRED4(HasCandidate, candidates_, "relay", "udp", kRelayUdpExtAddr); |
801 EXPECT_PRED4(HasCandidate, candidates_, "relay", "tcp", kRelayTcpIntAddr); | 814 EXPECT_PRED4(HasCandidate, candidates_, "relay", "tcp", kRelayTcpIntAddr); |
802 EXPECT_PRED4(HasCandidate, candidates_, "local", "tcp", kClientAddr); | 815 EXPECT_PRED4(HasCandidate, candidates_, "local", "tcp", kClientAddr); |
803 EXPECT_PRED4(HasCandidate, candidates_, "relay", "ssltcp", | 816 EXPECT_PRED4(HasCandidate, candidates_, "relay", "ssltcp", |
804 kRelaySslTcpIntAddr); | 817 kRelaySslTcpIntAddr); |
805 EXPECT_TRUE(candidate_allocation_done_); | 818 EXPECT_TRUE(candidate_allocation_done_); |
806 } | 819 } |
807 | 820 |
808 // Test that when the same network interface is brought down and up, the | 821 // Test that when the same network interface is brought down and up, the |
809 // port allocator session will restart a new allocation sequence if | 822 // port allocator session will restart a new allocation sequence if |
810 // it is not stopped. | 823 // it is not stopped. |
811 TEST_F(BasicPortAllocatorTest, TestSameNetworkDownAndUpWhenSessionNotStopped) { | 824 TEST_F(BasicPortAllocatorTest, TestSameNetworkDownAndUpWhenSessionNotStopped) { |
812 std::string if_name("test_net0"); | 825 std::string if_name("test_net0"); |
813 AddInterface(kClientAddr, if_name); | 826 AddInterface(kClientAddr, if_name); |
814 EXPECT_TRUE(CreateSession(ICE_CANDIDATE_COMPONENT_RTP)); | 827 EXPECT_TRUE(CreateSession(ICE_CANDIDATE_COMPONENT_RTP)); |
815 session_->StartGettingPorts(); | 828 session_->StartGettingPorts(); |
816 ASSERT_EQ_WAIT(7U, candidates_.size(), kDefaultAllocationTimeout); | 829 ASSERT_EQ_SIMULATED_WAIT(7U, candidates_.size(), kDefaultAllocationTimeout, |
830 fake_clock); | |
817 EXPECT_EQ(4U, ports_.size()); | 831 EXPECT_EQ(4U, ports_.size()); |
818 EXPECT_TRUE(candidate_allocation_done_); | 832 EXPECT_TRUE(candidate_allocation_done_); |
819 candidate_allocation_done_ = false; | 833 candidate_allocation_done_ = false; |
820 candidates_.clear(); | 834 candidates_.clear(); |
821 ports_.clear(); | 835 ports_.clear(); |
822 | 836 |
823 RemoveInterface(kClientAddr); | 837 RemoveInterface(kClientAddr); |
824 ASSERT_EQ_WAIT(0U, candidates_.size(), kDefaultAllocationTimeout); | 838 ASSERT_EQ_SIMULATED_WAIT(0U, candidates_.size(), kDefaultAllocationTimeout, |
839 fake_clock); | |
825 EXPECT_EQ(0U, ports_.size()); | 840 EXPECT_EQ(0U, ports_.size()); |
826 EXPECT_FALSE(candidate_allocation_done_); | 841 EXPECT_FALSE(candidate_allocation_done_); |
827 | 842 |
828 // When the same interfaces are added again, new candidates/ports should be | 843 // When the same interfaces are added again, new candidates/ports should be |
829 // generated. | 844 // generated. |
830 AddInterface(kClientAddr, if_name); | 845 AddInterface(kClientAddr, if_name); |
831 ASSERT_EQ_WAIT(7U, candidates_.size(), kDefaultAllocationTimeout); | 846 ASSERT_EQ_SIMULATED_WAIT(7U, candidates_.size(), kDefaultAllocationTimeout, |
847 fake_clock); | |
832 EXPECT_EQ(4U, ports_.size()); | 848 EXPECT_EQ(4U, ports_.size()); |
833 EXPECT_TRUE(candidate_allocation_done_); | 849 EXPECT_TRUE(candidate_allocation_done_); |
834 } | 850 } |
835 | 851 |
836 // Test that when the same network interface is brought down and up, the | 852 // 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 | 853 // port allocator session will not restart a new allocation sequence if |
838 // it is stopped. | 854 // it is stopped. |
839 TEST_F(BasicPortAllocatorTest, TestSameNetworkDownAndUpWhenSessionStopped) { | 855 TEST_F(BasicPortAllocatorTest, TestSameNetworkDownAndUpWhenSessionStopped) { |
840 std::string if_name("test_net0"); | 856 std::string if_name("test_net0"); |
841 AddInterface(kClientAddr, if_name); | 857 AddInterface(kClientAddr, if_name); |
842 EXPECT_TRUE(CreateSession(ICE_CANDIDATE_COMPONENT_RTP)); | 858 EXPECT_TRUE(CreateSession(ICE_CANDIDATE_COMPONENT_RTP)); |
843 session_->StartGettingPorts(); | 859 session_->StartGettingPorts(); |
844 ASSERT_EQ_WAIT(7U, candidates_.size(), kDefaultAllocationTimeout); | 860 ASSERT_EQ_SIMULATED_WAIT(7U, candidates_.size(), kDefaultAllocationTimeout, |
861 fake_clock); | |
845 EXPECT_EQ(4U, ports_.size()); | 862 EXPECT_EQ(4U, ports_.size()); |
846 EXPECT_TRUE(candidate_allocation_done_); | 863 EXPECT_TRUE(candidate_allocation_done_); |
847 session_->StopGettingPorts(); | 864 session_->StopGettingPorts(); |
848 candidates_.clear(); | 865 candidates_.clear(); |
849 ports_.clear(); | 866 ports_.clear(); |
850 | 867 |
851 RemoveInterface(kClientAddr); | 868 RemoveInterface(kClientAddr); |
852 ASSERT_EQ_WAIT(0U, candidates_.size(), kDefaultAllocationTimeout); | 869 ASSERT_EQ_SIMULATED_WAIT(0U, candidates_.size(), kDefaultAllocationTimeout, |
870 fake_clock); | |
853 EXPECT_EQ(0U, ports_.size()); | 871 EXPECT_EQ(0U, ports_.size()); |
854 | 872 |
855 // When the same interfaces are added again, new candidates/ports should not | 873 // When the same interfaces are added again, new candidates/ports should not |
856 // be generated because the session has stopped. | 874 // be generated because the session has stopped. |
857 AddInterface(kClientAddr, if_name); | 875 AddInterface(kClientAddr, if_name); |
858 ASSERT_EQ_WAIT(0U, candidates_.size(), kDefaultAllocationTimeout); | 876 ASSERT_EQ_SIMULATED_WAIT(0U, candidates_.size(), kDefaultAllocationTimeout, |
877 fake_clock); | |
859 EXPECT_EQ(0U, ports_.size()); | 878 EXPECT_EQ(0U, ports_.size()); |
860 EXPECT_TRUE(candidate_allocation_done_); | 879 EXPECT_TRUE(candidate_allocation_done_); |
861 } | 880 } |
862 | 881 |
863 // Verify candidates with default step delay of 1sec. | 882 // Verify candidates with default step delay of 1sec. |
864 TEST_F(BasicPortAllocatorTest, TestGetAllPortsWithOneSecondStepDelay) { | 883 TEST_F(BasicPortAllocatorTest, TestGetAllPortsWithOneSecondStepDelay) { |
865 AddInterface(kClientAddr); | 884 AddInterface(kClientAddr); |
866 allocator_->set_step_delay(kDefaultStepDelay); | 885 allocator_->set_step_delay(kDefaultStepDelay); |
867 EXPECT_TRUE(CreateSession(ICE_CANDIDATE_COMPONENT_RTP)); | 886 EXPECT_TRUE(CreateSession(ICE_CANDIDATE_COMPONENT_RTP)); |
868 session_->StartGettingPorts(); | 887 session_->StartGettingPorts(); |
869 ASSERT_EQ_WAIT(2U, candidates_.size(), 1000); | 888 ASSERT_EQ_SIMULATED_WAIT(2U, candidates_.size(), 1000, fake_clock); |
870 EXPECT_EQ(2U, ports_.size()); | 889 EXPECT_EQ(2U, ports_.size()); |
871 ASSERT_EQ_WAIT(4U, candidates_.size(), 2000); | 890 ASSERT_EQ_SIMULATED_WAIT(4U, candidates_.size(), 2000, fake_clock); |
872 EXPECT_EQ(3U, ports_.size()); | 891 EXPECT_EQ(3U, ports_.size()); |
873 EXPECT_PRED4(HasCandidate, candidates_, "relay", "udp", kRelayUdpIntAddr); | 892 EXPECT_PRED4(HasCandidate, candidates_, "relay", "udp", kRelayUdpIntAddr); |
874 EXPECT_PRED4(HasCandidate, candidates_, "relay", "udp", kRelayUdpExtAddr); | 893 EXPECT_PRED4(HasCandidate, candidates_, "relay", "udp", kRelayUdpExtAddr); |
875 ASSERT_EQ_WAIT(6U, candidates_.size(), 1500); | 894 ASSERT_EQ_SIMULATED_WAIT(6U, candidates_.size(), 1500, fake_clock); |
876 EXPECT_PRED4(HasCandidate, candidates_, "relay", "tcp", kRelayTcpIntAddr); | 895 EXPECT_PRED4(HasCandidate, candidates_, "relay", "tcp", kRelayTcpIntAddr); |
877 EXPECT_PRED4(HasCandidate, candidates_, "local", "tcp", kClientAddr); | 896 EXPECT_PRED4(HasCandidate, candidates_, "local", "tcp", kClientAddr); |
878 EXPECT_EQ(4U, ports_.size()); | 897 EXPECT_EQ(4U, ports_.size()); |
879 ASSERT_EQ_WAIT(7U, candidates_.size(), 2000); | 898 ASSERT_EQ_SIMULATED_WAIT(7U, candidates_.size(), 2000, fake_clock); |
880 EXPECT_PRED4(HasCandidate, candidates_, "relay", "ssltcp", | 899 EXPECT_PRED4(HasCandidate, candidates_, "relay", "ssltcp", |
881 kRelaySslTcpIntAddr); | 900 kRelaySslTcpIntAddr); |
882 EXPECT_EQ(4U, ports_.size()); | 901 EXPECT_EQ(4U, ports_.size()); |
883 EXPECT_TRUE(candidate_allocation_done_); | 902 EXPECT_TRUE(candidate_allocation_done_); |
884 // If we Stop gathering now, we shouldn't get a second "done" callback. | 903 // If we Stop gathering now, we shouldn't get a second "done" callback. |
885 session_->StopGettingPorts(); | 904 session_->StopGettingPorts(); |
886 } | 905 } |
887 | 906 |
888 TEST_F(BasicPortAllocatorTest, TestSetupVideoRtpPortsWithNormalSendBuffers) { | 907 TEST_F(BasicPortAllocatorTest, TestSetupVideoRtpPortsWithNormalSendBuffers) { |
889 AddInterface(kClientAddr); | 908 AddInterface(kClientAddr); |
890 EXPECT_TRUE(CreateSession(ICE_CANDIDATE_COMPONENT_RTP, CN_VIDEO)); | 909 EXPECT_TRUE(CreateSession(ICE_CANDIDATE_COMPONENT_RTP, CN_VIDEO)); |
891 session_->StartGettingPorts(); | 910 session_->StartGettingPorts(); |
892 ASSERT_EQ_WAIT(7U, candidates_.size(), kDefaultAllocationTimeout); | 911 ASSERT_EQ_SIMULATED_WAIT(7U, candidates_.size(), kDefaultAllocationTimeout, |
912 fake_clock); | |
893 EXPECT_TRUE(candidate_allocation_done_); | 913 EXPECT_TRUE(candidate_allocation_done_); |
894 // 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. |
895 session_->StopGettingPorts(); | 915 session_->StopGettingPorts(); |
896 | 916 |
897 // All ports should have unset send-buffer sizes. | 917 // All ports should have unset send-buffer sizes. |
898 CheckSendBufferSizesOfAllPorts(-1); | 918 CheckSendBufferSizesOfAllPorts(-1); |
899 } | 919 } |
900 | 920 |
901 // Tests that we can get callback after StopGetAllPorts. | 921 // Tests that we can get callback after StopGetAllPorts. |
902 TEST_F(BasicPortAllocatorTest, TestStopGetAllPorts) { | 922 TEST_F(BasicPortAllocatorTest, TestStopGetAllPorts) { |
(...skipping 12 matching lines...) Expand all Loading... | |
915 TEST_F(BasicPortAllocatorTest, TestGetAllPortsPortRange) { | 935 TEST_F(BasicPortAllocatorTest, TestGetAllPortsPortRange) { |
916 AddInterface(kClientAddr); | 936 AddInterface(kClientAddr); |
917 // Check that an invalid port range fails. | 937 // Check that an invalid port range fails. |
918 EXPECT_FALSE(SetPortRange(kMaxPort, kMinPort)); | 938 EXPECT_FALSE(SetPortRange(kMaxPort, kMinPort)); |
919 // Check that a null port range succeeds. | 939 // Check that a null port range succeeds. |
920 EXPECT_TRUE(SetPortRange(0, 0)); | 940 EXPECT_TRUE(SetPortRange(0, 0)); |
921 // Check that a valid port range succeeds. | 941 // Check that a valid port range succeeds. |
922 EXPECT_TRUE(SetPortRange(kMinPort, kMaxPort)); | 942 EXPECT_TRUE(SetPortRange(kMinPort, kMaxPort)); |
923 EXPECT_TRUE(CreateSession(ICE_CANDIDATE_COMPONENT_RTP)); | 943 EXPECT_TRUE(CreateSession(ICE_CANDIDATE_COMPONENT_RTP)); |
924 session_->StartGettingPorts(); | 944 session_->StartGettingPorts(); |
925 ASSERT_EQ_WAIT(7U, candidates_.size(), kDefaultAllocationTimeout); | 945 ASSERT_EQ_SIMULATED_WAIT(7U, candidates_.size(), kDefaultAllocationTimeout, |
946 fake_clock); | |
926 EXPECT_EQ(4U, ports_.size()); | 947 EXPECT_EQ(4U, ports_.size()); |
927 | 948 |
928 int num_nonrelay_candidates = 0; | 949 int num_nonrelay_candidates = 0; |
929 for (const Candidate& candidate : candidates_) { | 950 for (const Candidate& candidate : candidates_) { |
930 // Check the port number for the UDP/STUN/TCP port objects. | 951 // Check the port number for the UDP/STUN/TCP port objects. |
931 if (candidate.type() != RELAY_PORT_TYPE) { | 952 if (candidate.type() != RELAY_PORT_TYPE) { |
932 EXPECT_PRED3(CheckPort, candidate.address(), kMinPort, kMaxPort); | 953 EXPECT_PRED3(CheckPort, candidate.address(), kMinPort, kMaxPort); |
933 ++num_nonrelay_candidates; | 954 ++num_nonrelay_candidates; |
934 } | 955 } |
935 } | 956 } |
(...skipping 12 matching lines...) Expand all Loading... | |
948 ResetWithStunServerAndNat(kStunAddr); | 969 ResetWithStunServerAndNat(kStunAddr); |
949 turn_server_.AddInternalSocket(kTurnTcpIntAddr, PROTO_TCP); | 970 turn_server_.AddInternalSocket(kTurnTcpIntAddr, PROTO_TCP); |
950 AddTurnServers(kTurnUdpIntAddr, kTurnTcpIntAddr); | 971 AddTurnServers(kTurnUdpIntAddr, kTurnTcpIntAddr); |
951 AddTurnServers(kTurnUdpIntIPv6Addr, kTurnTcpIntIPv6Addr); | 972 AddTurnServers(kTurnUdpIntIPv6Addr, kTurnTcpIntIPv6Addr); |
952 // Disable IPv6, because our test infrastructure doesn't support having IPv4 | 973 // Disable IPv6, because our test infrastructure doesn't support having IPv4 |
953 // behind a NAT but IPv6 not, or having an IPv6 NAT. | 974 // behind a NAT but IPv6 not, or having an IPv6 NAT. |
954 // TODO(deadbeef): Fix this. | 975 // TODO(deadbeef): Fix this. |
955 network_manager_.set_ipv6_enabled(false); | 976 network_manager_.set_ipv6_enabled(false); |
956 EXPECT_TRUE(CreateSession(ICE_CANDIDATE_COMPONENT_RTP)); | 977 EXPECT_TRUE(CreateSession(ICE_CANDIDATE_COMPONENT_RTP)); |
957 session_->StartGettingPorts(); | 978 session_->StartGettingPorts(); |
958 EXPECT_TRUE_WAIT(candidate_allocation_done_, kDefaultAllocationTimeout); | 979 EXPECT_TRUE_SIMULATED_WAIT(candidate_allocation_done_, |
980 kDefaultAllocationTimeout, fake_clock); | |
959 EXPECT_EQ(4U, ports_.size()); | 981 EXPECT_EQ(4U, ports_.size()); |
960 EXPECT_EQ(1, CountPorts(ports_, "stun", PROTO_UDP, kAnyAddr)); | 982 EXPECT_EQ(1, CountPorts(ports_, "stun", PROTO_UDP, kAnyAddr)); |
961 EXPECT_EQ(1, CountPorts(ports_, "local", PROTO_TCP, kAnyAddr)); | 983 EXPECT_EQ(1, CountPorts(ports_, "local", PROTO_TCP, kAnyAddr)); |
962 // Two TURN ports, using UDP/TCP for the first hop to the TURN server. | 984 // Two TURN ports, using UDP/TCP for the first hop to the TURN server. |
963 EXPECT_EQ(1, CountPorts(ports_, "relay", PROTO_UDP, kAnyAddr)); | 985 EXPECT_EQ(1, CountPorts(ports_, "relay", PROTO_UDP, kAnyAddr)); |
964 EXPECT_EQ(1, CountPorts(ports_, "relay", PROTO_TCP, kAnyAddr)); | 986 EXPECT_EQ(1, CountPorts(ports_, "relay", PROTO_TCP, kAnyAddr)); |
965 // The "any" address port should be in the signaled ready ports, but the host | 987 // 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 | 988 // candidate for it is useless and shouldn't be signaled. So we only have |
967 // STUN/TURN candidates. | 989 // STUN/TURN candidates. |
968 EXPECT_EQ(3U, candidates_.size()); | 990 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); | 1107 turn_server_.AddInternalSocket(kTurnTcpIntAddr, PROTO_TCP); |
1086 AddInterface(kClientAddr); | 1108 AddInterface(kClientAddr); |
1087 ResetWithStunServerAndNat(kStunAddr); | 1109 ResetWithStunServerAndNat(kStunAddr); |
1088 AddTurnServers(kTurnUdpIntAddr, kTurnTcpIntAddr); | 1110 AddTurnServers(kTurnUdpIntAddr, kTurnTcpIntAddr); |
1089 EXPECT_TRUE(CreateSession(ICE_CANDIDATE_COMPONENT_RTP)); | 1111 EXPECT_TRUE(CreateSession(ICE_CANDIDATE_COMPONENT_RTP)); |
1090 session_->set_flags(PORTALLOCATOR_DISABLE_UDP_RELAY | | 1112 session_->set_flags(PORTALLOCATOR_DISABLE_UDP_RELAY | |
1091 PORTALLOCATOR_DISABLE_UDP | PORTALLOCATOR_DISABLE_STUN | | 1113 PORTALLOCATOR_DISABLE_UDP | PORTALLOCATOR_DISABLE_STUN | |
1092 PORTALLOCATOR_ENABLE_SHARED_SOCKET); | 1114 PORTALLOCATOR_ENABLE_SHARED_SOCKET); |
1093 | 1115 |
1094 session_->StartGettingPorts(); | 1116 session_->StartGettingPorts(); |
1095 EXPECT_TRUE_WAIT(candidate_allocation_done_, kDefaultAllocationTimeout); | 1117 EXPECT_TRUE_SIMULATED_WAIT(candidate_allocation_done_, |
1118 kDefaultAllocationTimeout, fake_clock); | |
1096 | 1119 |
1097 // Expect to see 2 ports and 2 candidates - TURN/TCP and TCP ports, TCP and | 1120 // Expect to see 2 ports and 2 candidates - TURN/TCP and TCP ports, TCP and |
1098 // TURN/TCP candidates. | 1121 // TURN/TCP candidates. |
1099 EXPECT_EQ(2U, ports_.size()); | 1122 EXPECT_EQ(2U, ports_.size()); |
1100 EXPECT_EQ(2U, candidates_.size()); | 1123 EXPECT_EQ(2U, candidates_.size()); |
1101 Candidate turn_candidate; | 1124 Candidate turn_candidate; |
1102 EXPECT_PRED5(FindCandidate, candidates_, "relay", "udp", kTurnUdpExtAddr, | 1125 EXPECT_PRED5(FindCandidate, candidates_, "relay", "udp", kTurnUdpExtAddr, |
1103 &turn_candidate); | 1126 &turn_candidate); |
1104 // The TURN candidate should use TCP to contact the TURN server. | 1127 // The TURN candidate should use TCP to contact the TURN server. |
1105 EXPECT_EQ(TCP_PROTOCOL_NAME, turn_candidate.relay_protocol()); | 1128 EXPECT_EQ(TCP_PROTOCOL_NAME, turn_candidate.relay_protocol()); |
1106 EXPECT_PRED4(HasCandidate, candidates_, "local", "tcp", kClientAddr); | 1129 EXPECT_PRED4(HasCandidate, candidates_, "local", "tcp", kClientAddr); |
1107 } | 1130 } |
1108 | 1131 |
1109 // Disable for asan, see | 1132 // Disable for asan, see |
1110 // https://code.google.com/p/webrtc/issues/detail?id=4743 for details. | 1133 // https://code.google.com/p/webrtc/issues/detail?id=4743 for details. |
1111 #if !defined(ADDRESS_SANITIZER) | 1134 #if !defined(ADDRESS_SANITIZER) |
1112 | 1135 |
1113 // Test that we can get OnCandidatesAllocationDone callback when all the ports | 1136 // Test that we can get OnCandidatesAllocationDone callback when all the ports |
1114 // are disabled. | 1137 // are disabled. |
1115 TEST_F(BasicPortAllocatorTest, TestDisableAllPorts) { | 1138 TEST_F(BasicPortAllocatorTest, TestDisableAllPorts) { |
1116 AddInterface(kClientAddr); | 1139 AddInterface(kClientAddr); |
1117 EXPECT_TRUE(CreateSession(ICE_CANDIDATE_COMPONENT_RTP)); | 1140 EXPECT_TRUE(CreateSession(ICE_CANDIDATE_COMPONENT_RTP)); |
1118 session_->set_flags(PORTALLOCATOR_DISABLE_UDP | PORTALLOCATOR_DISABLE_STUN | | 1141 session_->set_flags(PORTALLOCATOR_DISABLE_UDP | PORTALLOCATOR_DISABLE_STUN | |
1119 PORTALLOCATOR_DISABLE_RELAY | PORTALLOCATOR_DISABLE_TCP); | 1142 PORTALLOCATOR_DISABLE_RELAY | PORTALLOCATOR_DISABLE_TCP); |
1120 session_->StartGettingPorts(); | 1143 session_->StartGettingPorts(); |
1121 rtc::Thread::Current()->ProcessMessages(100); | 1144 EXPECT_TRUE_SIMULATED_WAIT(candidate_allocation_done_, 1000, fake_clock); |
1122 EXPECT_EQ(0U, candidates_.size()); | 1145 EXPECT_EQ(0U, candidates_.size()); |
1123 EXPECT_TRUE(candidate_allocation_done_); | |
1124 } | 1146 } |
1125 | 1147 |
1126 // Test that we don't crash or malfunction if we can't create UDP sockets. | 1148 // Test that we don't crash or malfunction if we can't create UDP sockets. |
1127 TEST_F(BasicPortAllocatorTest, TestGetAllPortsNoUdpSockets) { | 1149 TEST_F(BasicPortAllocatorTest, TestGetAllPortsNoUdpSockets) { |
1128 AddInterface(kClientAddr); | 1150 AddInterface(kClientAddr); |
1129 fss_->set_udp_sockets_enabled(false); | 1151 fss_->set_udp_sockets_enabled(false); |
1130 EXPECT_TRUE(CreateSession(1)); | 1152 EXPECT_TRUE(CreateSession(1)); |
1131 session_->StartGettingPorts(); | 1153 session_->StartGettingPorts(); |
1132 ASSERT_EQ_WAIT(5U, candidates_.size(), kDefaultAllocationTimeout); | 1154 ASSERT_EQ_SIMULATED_WAIT(5U, candidates_.size(), kDefaultAllocationTimeout, |
1155 fake_clock); | |
1133 EXPECT_EQ(2U, ports_.size()); | 1156 EXPECT_EQ(2U, ports_.size()); |
1134 EXPECT_PRED4(HasCandidate, candidates_, "relay", "udp", kRelayUdpIntAddr); | 1157 EXPECT_PRED4(HasCandidate, candidates_, "relay", "udp", kRelayUdpIntAddr); |
1135 EXPECT_PRED4(HasCandidate, candidates_, "relay", "udp", kRelayUdpExtAddr); | 1158 EXPECT_PRED4(HasCandidate, candidates_, "relay", "udp", kRelayUdpExtAddr); |
1136 EXPECT_PRED4(HasCandidate, candidates_, "relay", "tcp", kRelayTcpIntAddr); | 1159 EXPECT_PRED4(HasCandidate, candidates_, "relay", "tcp", kRelayTcpIntAddr); |
1137 EXPECT_PRED4(HasCandidate, candidates_, "local", "tcp", kClientAddr); | 1160 EXPECT_PRED4(HasCandidate, candidates_, "local", "tcp", kClientAddr); |
1138 EXPECT_PRED4(HasCandidate, candidates_, "relay", "ssltcp", | 1161 EXPECT_PRED4(HasCandidate, candidates_, "relay", "ssltcp", |
1139 kRelaySslTcpIntAddr); | 1162 kRelaySslTcpIntAddr); |
1140 EXPECT_TRUE(candidate_allocation_done_); | 1163 EXPECT_TRUE(candidate_allocation_done_); |
1141 } | 1164 } |
1142 | 1165 |
1143 #endif // if !defined(ADDRESS_SANITIZER) | 1166 #endif // if !defined(ADDRESS_SANITIZER) |
1144 | 1167 |
1145 // Test that we don't crash or malfunction if we can't create UDP sockets or | 1168 // 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 | 1169 // 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. | 1170 // apparently this is needed for the remote side to accept our connection. |
1148 TEST_F(BasicPortAllocatorTest, TestGetAllPortsNoUdpSocketsNoTcpListen) { | 1171 TEST_F(BasicPortAllocatorTest, TestGetAllPortsNoUdpSocketsNoTcpListen) { |
1149 AddInterface(kClientAddr); | 1172 AddInterface(kClientAddr); |
1150 fss_->set_udp_sockets_enabled(false); | 1173 fss_->set_udp_sockets_enabled(false); |
1151 fss_->set_tcp_listen_enabled(false); | 1174 fss_->set_tcp_listen_enabled(false); |
1152 EXPECT_TRUE(CreateSession(1)); | 1175 EXPECT_TRUE(CreateSession(1)); |
1153 session_->StartGettingPorts(); | 1176 session_->StartGettingPorts(); |
1154 ASSERT_EQ_WAIT(5U, candidates_.size(), kDefaultAllocationTimeout); | 1177 ASSERT_EQ_SIMULATED_WAIT(5U, candidates_.size(), kDefaultAllocationTimeout, |
1178 fake_clock); | |
1155 EXPECT_EQ(2U, ports_.size()); | 1179 EXPECT_EQ(2U, ports_.size()); |
1156 EXPECT_PRED4(HasCandidate, candidates_, "relay", "udp", kRelayUdpIntAddr); | 1180 EXPECT_PRED4(HasCandidate, candidates_, "relay", "udp", kRelayUdpIntAddr); |
1157 EXPECT_PRED4(HasCandidate, candidates_, "relay", "udp", kRelayUdpExtAddr); | 1181 EXPECT_PRED4(HasCandidate, candidates_, "relay", "udp", kRelayUdpExtAddr); |
1158 EXPECT_PRED4(HasCandidate, candidates_, "relay", "tcp", kRelayTcpIntAddr); | 1182 EXPECT_PRED4(HasCandidate, candidates_, "relay", "tcp", kRelayTcpIntAddr); |
1159 EXPECT_PRED4(HasCandidate, candidates_, "local", "tcp", kClientAddr); | 1183 EXPECT_PRED4(HasCandidate, candidates_, "local", "tcp", kClientAddr); |
1160 EXPECT_PRED4(HasCandidate, candidates_, "relay", "ssltcp", | 1184 EXPECT_PRED4(HasCandidate, candidates_, "relay", "ssltcp", |
1161 kRelaySslTcpIntAddr); | 1185 kRelaySslTcpIntAddr); |
1162 EXPECT_TRUE(candidate_allocation_done_); | 1186 EXPECT_TRUE(candidate_allocation_done_); |
1163 } | 1187 } |
1164 | 1188 |
(...skipping 10 matching lines...) Expand all Loading... | |
1175 // In case of Relay, ports creation will succeed but sockets will fail. | 1199 // In case of Relay, ports creation will succeed but sockets will fail. |
1176 // There is no error reporting from RelayEntry to handle this failure. | 1200 // There is no error reporting from RelayEntry to handle this failure. |
1177 } | 1201 } |
1178 | 1202 |
1179 // Testing STUN timeout. | 1203 // Testing STUN timeout. |
1180 TEST_F(BasicPortAllocatorTest, TestGetAllPortsNoUdpAllowed) { | 1204 TEST_F(BasicPortAllocatorTest, TestGetAllPortsNoUdpAllowed) { |
1181 fss_->AddRule(false, rtc::FP_UDP, rtc::FD_ANY, kClientAddr); | 1205 fss_->AddRule(false, rtc::FP_UDP, rtc::FD_ANY, kClientAddr); |
1182 AddInterface(kClientAddr); | 1206 AddInterface(kClientAddr); |
1183 EXPECT_TRUE(CreateSession(ICE_CANDIDATE_COMPONENT_RTP)); | 1207 EXPECT_TRUE(CreateSession(ICE_CANDIDATE_COMPONENT_RTP)); |
1184 session_->StartGettingPorts(); | 1208 session_->StartGettingPorts(); |
1185 EXPECT_EQ_WAIT(2U, candidates_.size(), kDefaultAllocationTimeout); | 1209 EXPECT_EQ_SIMULATED_WAIT(2U, candidates_.size(), kDefaultAllocationTimeout, |
1210 fake_clock); | |
1186 EXPECT_EQ(2U, ports_.size()); | 1211 EXPECT_EQ(2U, ports_.size()); |
1187 EXPECT_PRED4(HasCandidate, candidates_, "local", "udp", kClientAddr); | 1212 EXPECT_PRED4(HasCandidate, candidates_, "local", "udp", kClientAddr); |
1188 EXPECT_PRED4(HasCandidate, candidates_, "local", "tcp", kClientAddr); | 1213 EXPECT_PRED4(HasCandidate, candidates_, "local", "tcp", kClientAddr); |
1189 // RelayPort connection timeout is 3sec. TCP connection with RelayServer | 1214 // RelayPort connection timeout is 3sec. TCP connection with RelayServer |
1190 // will be tried after 3 seconds. | 1215 // will be tried after about 3 seconds. |
1191 // TODO(deadbeef): Use simulated clock here, waiting for exactly 3 seconds. | 1216 EXPECT_EQ_SIMULATED_WAIT(6U, candidates_.size(), 3500, fake_clock); |
1192 EXPECT_EQ_WAIT(6U, candidates_.size(), kStunTimeoutMs); | |
1193 EXPECT_EQ(3U, ports_.size()); | 1217 EXPECT_EQ(3U, ports_.size()); |
1194 EXPECT_PRED4(HasCandidate, candidates_, "relay", "udp", kRelayUdpIntAddr); | 1218 EXPECT_PRED4(HasCandidate, candidates_, "relay", "udp", kRelayUdpIntAddr); |
1195 EXPECT_PRED4(HasCandidate, candidates_, "relay", "tcp", kRelayTcpIntAddr); | 1219 EXPECT_PRED4(HasCandidate, candidates_, "relay", "tcp", kRelayTcpIntAddr); |
1196 EXPECT_PRED4(HasCandidate, candidates_, "relay", "ssltcp", | 1220 EXPECT_PRED4(HasCandidate, candidates_, "relay", "ssltcp", |
1197 kRelaySslTcpIntAddr); | 1221 kRelaySslTcpIntAddr); |
1198 EXPECT_PRED4(HasCandidate, candidates_, "relay", "udp", kRelayUdpExtAddr); | 1222 EXPECT_PRED4(HasCandidate, candidates_, "relay", "udp", kRelayUdpExtAddr); |
1199 // Stun Timeout is 9.5sec. | 1223 // 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. | 1224 // seconds. But since 3-3.5 seconds already passed (see above), we |
1201 EXPECT_TRUE_WAIT(candidate_allocation_done_, kStunTimeoutMs); | 1225 // only need 6.5 more seconds. |
Taylor Brandstetter
2017/02/08 09:21:26
Well now I feel dumb
| |
1226 EXPECT_TRUE_SIMULATED_WAIT(candidate_allocation_done_, 6500, fake_clock); | |
1202 } | 1227 } |
1203 | 1228 |
1204 TEST_F(BasicPortAllocatorTest, TestCandidatePriorityOfMultipleInterfaces) { | 1229 TEST_F(BasicPortAllocatorTest, TestCandidatePriorityOfMultipleInterfaces) { |
1205 AddInterface(kClientAddr); | 1230 AddInterface(kClientAddr); |
1206 AddInterface(kClientAddr2); | 1231 AddInterface(kClientAddr2); |
1207 // Allocating only host UDP ports. This is done purely for testing | 1232 // Allocating only host UDP ports. This is done purely for testing |
1208 // convenience. | 1233 // convenience. |
1209 allocator().set_flags(PORTALLOCATOR_DISABLE_TCP | PORTALLOCATOR_DISABLE_STUN | | 1234 allocator().set_flags(PORTALLOCATOR_DISABLE_TCP | PORTALLOCATOR_DISABLE_STUN | |
1210 PORTALLOCATOR_DISABLE_RELAY); | 1235 PORTALLOCATOR_DISABLE_RELAY); |
1211 EXPECT_TRUE(CreateSession(ICE_CANDIDATE_COMPONENT_RTP)); | 1236 EXPECT_TRUE(CreateSession(ICE_CANDIDATE_COMPONENT_RTP)); |
1212 session_->StartGettingPorts(); | 1237 session_->StartGettingPorts(); |
1213 EXPECT_TRUE_WAIT(candidate_allocation_done_, kDefaultAllocationTimeout); | 1238 EXPECT_TRUE_SIMULATED_WAIT(candidate_allocation_done_, |
1239 kDefaultAllocationTimeout, fake_clock); | |
1214 ASSERT_EQ(2U, candidates_.size()); | 1240 ASSERT_EQ(2U, candidates_.size()); |
1215 EXPECT_EQ(2U, ports_.size()); | 1241 EXPECT_EQ(2U, ports_.size()); |
1216 // Candidates priorities should be different. | 1242 // Candidates priorities should be different. |
1217 EXPECT_NE(candidates_[0].priority(), candidates_[1].priority()); | 1243 EXPECT_NE(candidates_[0].priority(), candidates_[1].priority()); |
1218 } | 1244 } |
1219 | 1245 |
1220 // Test to verify ICE restart process. | 1246 // Test to verify ICE restart process. |
1221 TEST_F(BasicPortAllocatorTest, TestGetAllPortsRestarts) { | 1247 TEST_F(BasicPortAllocatorTest, TestGetAllPortsRestarts) { |
1222 AddInterface(kClientAddr); | 1248 AddInterface(kClientAddr); |
1223 EXPECT_TRUE(CreateSession(ICE_CANDIDATE_COMPONENT_RTP)); | 1249 EXPECT_TRUE(CreateSession(ICE_CANDIDATE_COMPONENT_RTP)); |
1224 session_->StartGettingPorts(); | 1250 session_->StartGettingPorts(); |
1225 EXPECT_EQ_WAIT(7U, candidates_.size(), kDefaultAllocationTimeout); | 1251 EXPECT_EQ_SIMULATED_WAIT(7U, candidates_.size(), kDefaultAllocationTimeout, |
1252 fake_clock); | |
1226 EXPECT_EQ(4U, ports_.size()); | 1253 EXPECT_EQ(4U, ports_.size()); |
1227 EXPECT_TRUE(candidate_allocation_done_); | 1254 EXPECT_TRUE(candidate_allocation_done_); |
1228 // TODO(deadbeef): Extend this to verify ICE restart. | 1255 // TODO(deadbeef): Extend this to verify ICE restart. |
1229 } | 1256 } |
1230 | 1257 |
1231 // Test that the allocator session uses the candidate filter it's created with, | 1258 // Test that the allocator session uses the candidate filter it's created with, |
1232 // rather than the filter of its parent allocator. | 1259 // rather than the filter of its parent allocator. |
1233 // The filter of the allocator should only affect the next gathering phase, | 1260 // The filter of the allocator should only affect the next gathering phase, |
1234 // according to JSEP, which means the *next* allocator session returned. | 1261 // according to JSEP, which means the *next* allocator session returned. |
1235 TEST_F(BasicPortAllocatorTest, TestSessionUsesOwnCandidateFilter) { | 1262 TEST_F(BasicPortAllocatorTest, TestSessionUsesOwnCandidateFilter) { |
1236 AddInterface(kClientAddr); | 1263 AddInterface(kClientAddr); |
1237 EXPECT_TRUE(CreateSession(ICE_CANDIDATE_COMPONENT_RTP)); | 1264 EXPECT_TRUE(CreateSession(ICE_CANDIDATE_COMPONENT_RTP)); |
1238 // Set candidate filter *after* creating the session. Should have no effect. | 1265 // Set candidate filter *after* creating the session. Should have no effect. |
1239 allocator().set_candidate_filter(CF_RELAY); | 1266 allocator().set_candidate_filter(CF_RELAY); |
1240 session_->StartGettingPorts(); | 1267 session_->StartGettingPorts(); |
1241 // 7 candidates and 4 ports is what we would normally get (see the | 1268 // 7 candidates and 4 ports is what we would normally get (see the |
1242 // TestGetAllPorts* tests). | 1269 // TestGetAllPorts* tests). |
1243 EXPECT_EQ_WAIT(7U, candidates_.size(), kDefaultAllocationTimeout); | 1270 EXPECT_EQ_SIMULATED_WAIT(7U, candidates_.size(), kDefaultAllocationTimeout, |
1271 fake_clock); | |
1244 EXPECT_EQ(4U, ports_.size()); | 1272 EXPECT_EQ(4U, ports_.size()); |
1245 EXPECT_TRUE(candidate_allocation_done_); | 1273 EXPECT_TRUE(candidate_allocation_done_); |
1246 } | 1274 } |
1247 | 1275 |
1248 // Test ICE candidate filter mechanism with options Relay/Host/Reflexive. | 1276 // Test ICE candidate filter mechanism with options Relay/Host/Reflexive. |
1249 // This test also verifies that when the allocator is only allowed to use | 1277 // 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 | 1278 // relay (i.e. IceTransportsType is relay), the raddr is an empty |
1251 // address with the correct family. This is to prevent any local | 1279 // address with the correct family. This is to prevent any local |
1252 // reflective address leakage in the sdp line. | 1280 // reflective address leakage in the sdp line. |
1253 TEST_F(BasicPortAllocatorTest, TestCandidateFilterWithRelayOnly) { | 1281 TEST_F(BasicPortAllocatorTest, TestCandidateFilterWithRelayOnly) { |
1254 AddInterface(kClientAddr); | 1282 AddInterface(kClientAddr); |
1255 // GTURN is not configured here. | 1283 // GTURN is not configured here. |
1256 ResetWithTurnServersNoNat(kTurnUdpIntAddr, rtc::SocketAddress()); | 1284 ResetWithTurnServersNoNat(kTurnUdpIntAddr, rtc::SocketAddress()); |
1257 allocator().set_candidate_filter(CF_RELAY); | 1285 allocator().set_candidate_filter(CF_RELAY); |
1258 EXPECT_TRUE(CreateSession(ICE_CANDIDATE_COMPONENT_RTP)); | 1286 EXPECT_TRUE(CreateSession(ICE_CANDIDATE_COMPONENT_RTP)); |
1259 session_->StartGettingPorts(); | 1287 session_->StartGettingPorts(); |
1260 EXPECT_TRUE_WAIT(candidate_allocation_done_, kDefaultAllocationTimeout); | 1288 EXPECT_TRUE_SIMULATED_WAIT(candidate_allocation_done_, |
1289 kDefaultAllocationTimeout, fake_clock); | |
1261 EXPECT_PRED4(HasCandidate, candidates_, "relay", "udp", | 1290 EXPECT_PRED4(HasCandidate, candidates_, "relay", "udp", |
1262 rtc::SocketAddress(kTurnUdpExtAddr.ipaddr(), 0)); | 1291 rtc::SocketAddress(kTurnUdpExtAddr.ipaddr(), 0)); |
1263 | 1292 |
1264 EXPECT_EQ(1U, candidates_.size()); | 1293 EXPECT_EQ(1U, candidates_.size()); |
1265 EXPECT_EQ(1U, ports_.size()); // Only Relay port will be in ready state. | 1294 EXPECT_EQ(1U, ports_.size()); // Only Relay port will be in ready state. |
1266 EXPECT_EQ(std::string(RELAY_PORT_TYPE), candidates_[0].type()); | 1295 EXPECT_EQ(std::string(RELAY_PORT_TYPE), candidates_[0].type()); |
1267 EXPECT_EQ( | 1296 EXPECT_EQ( |
1268 candidates_[0].related_address(), | 1297 candidates_[0].related_address(), |
1269 rtc::EmptySocketAddressWithFamily(candidates_[0].address().family())); | 1298 rtc::EmptySocketAddressWithFamily(candidates_[0].address().family())); |
1270 } | 1299 } |
1271 | 1300 |
1272 TEST_F(BasicPortAllocatorTest, TestCandidateFilterWithHostOnly) { | 1301 TEST_F(BasicPortAllocatorTest, TestCandidateFilterWithHostOnly) { |
1273 AddInterface(kClientAddr); | 1302 AddInterface(kClientAddr); |
1274 allocator().set_flags(PORTALLOCATOR_ENABLE_SHARED_SOCKET); | 1303 allocator().set_flags(PORTALLOCATOR_ENABLE_SHARED_SOCKET); |
1275 allocator().set_candidate_filter(CF_HOST); | 1304 allocator().set_candidate_filter(CF_HOST); |
1276 EXPECT_TRUE(CreateSession(ICE_CANDIDATE_COMPONENT_RTP)); | 1305 EXPECT_TRUE(CreateSession(ICE_CANDIDATE_COMPONENT_RTP)); |
1277 session_->StartGettingPorts(); | 1306 session_->StartGettingPorts(); |
1278 EXPECT_TRUE_WAIT(candidate_allocation_done_, kDefaultAllocationTimeout); | 1307 EXPECT_TRUE_SIMULATED_WAIT(candidate_allocation_done_, |
1308 kDefaultAllocationTimeout, fake_clock); | |
1279 EXPECT_EQ(2U, candidates_.size()); // Host UDP/TCP candidates only. | 1309 EXPECT_EQ(2U, candidates_.size()); // Host UDP/TCP candidates only. |
1280 EXPECT_EQ(2U, ports_.size()); // UDP/TCP ports only. | 1310 EXPECT_EQ(2U, ports_.size()); // UDP/TCP ports only. |
1281 for (const Candidate& candidate : candidates_) { | 1311 for (const Candidate& candidate : candidates_) { |
1282 EXPECT_EQ(std::string(LOCAL_PORT_TYPE), candidate.type()); | 1312 EXPECT_EQ(std::string(LOCAL_PORT_TYPE), candidate.type()); |
1283 } | 1313 } |
1284 } | 1314 } |
1285 | 1315 |
1286 // Host is behind the NAT. | 1316 // Host is behind the NAT. |
1287 TEST_F(BasicPortAllocatorTest, TestCandidateFilterWithReflexiveOnly) { | 1317 TEST_F(BasicPortAllocatorTest, TestCandidateFilterWithReflexiveOnly) { |
1288 AddInterface(kPrivateAddr); | 1318 AddInterface(kPrivateAddr); |
1289 ResetWithStunServerAndNat(kStunAddr); | 1319 ResetWithStunServerAndNat(kStunAddr); |
1290 | 1320 |
1291 allocator().set_flags(PORTALLOCATOR_ENABLE_SHARED_SOCKET); | 1321 allocator().set_flags(PORTALLOCATOR_ENABLE_SHARED_SOCKET); |
1292 allocator().set_candidate_filter(CF_REFLEXIVE); | 1322 allocator().set_candidate_filter(CF_REFLEXIVE); |
1293 EXPECT_TRUE(CreateSession(ICE_CANDIDATE_COMPONENT_RTP)); | 1323 EXPECT_TRUE(CreateSession(ICE_CANDIDATE_COMPONENT_RTP)); |
1294 session_->StartGettingPorts(); | 1324 session_->StartGettingPorts(); |
1295 EXPECT_TRUE_WAIT(candidate_allocation_done_, kDefaultAllocationTimeout); | 1325 EXPECT_TRUE_SIMULATED_WAIT(candidate_allocation_done_, |
1326 kDefaultAllocationTimeout, fake_clock); | |
1296 // Host is behind NAT, no private address will be exposed. Hence only UDP | 1327 // Host is behind NAT, no private address will be exposed. Hence only UDP |
1297 // port with STUN candidate will be sent outside. | 1328 // port with STUN candidate will be sent outside. |
1298 EXPECT_EQ(1U, candidates_.size()); // Only STUN candidate. | 1329 EXPECT_EQ(1U, candidates_.size()); // Only STUN candidate. |
1299 EXPECT_EQ(1U, ports_.size()); // Only UDP port will be in ready state. | 1330 EXPECT_EQ(1U, ports_.size()); // Only UDP port will be in ready state. |
1300 EXPECT_EQ(std::string(STUN_PORT_TYPE), candidates_[0].type()); | 1331 EXPECT_EQ(std::string(STUN_PORT_TYPE), candidates_[0].type()); |
1301 EXPECT_EQ( | 1332 EXPECT_EQ( |
1302 candidates_[0].related_address(), | 1333 candidates_[0].related_address(), |
1303 rtc::EmptySocketAddressWithFamily(candidates_[0].address().family())); | 1334 rtc::EmptySocketAddressWithFamily(candidates_[0].address().family())); |
1304 } | 1335 } |
1305 | 1336 |
1306 // Host is not behind the NAT. | 1337 // Host is not behind the NAT. |
1307 TEST_F(BasicPortAllocatorTest, TestCandidateFilterWithReflexiveOnlyAndNoNAT) { | 1338 TEST_F(BasicPortAllocatorTest, TestCandidateFilterWithReflexiveOnlyAndNoNAT) { |
1308 AddInterface(kClientAddr); | 1339 AddInterface(kClientAddr); |
1309 allocator().set_flags(PORTALLOCATOR_ENABLE_SHARED_SOCKET); | 1340 allocator().set_flags(PORTALLOCATOR_ENABLE_SHARED_SOCKET); |
1310 allocator().set_candidate_filter(CF_REFLEXIVE); | 1341 allocator().set_candidate_filter(CF_REFLEXIVE); |
1311 EXPECT_TRUE(CreateSession(ICE_CANDIDATE_COMPONENT_RTP)); | 1342 EXPECT_TRUE(CreateSession(ICE_CANDIDATE_COMPONENT_RTP)); |
1312 session_->StartGettingPorts(); | 1343 session_->StartGettingPorts(); |
1313 EXPECT_TRUE_WAIT(candidate_allocation_done_, kDefaultAllocationTimeout); | 1344 EXPECT_TRUE_SIMULATED_WAIT(candidate_allocation_done_, |
1345 kDefaultAllocationTimeout, fake_clock); | |
1314 // Host has a public address, both UDP and TCP candidates will be exposed. | 1346 // Host has a public address, both UDP and TCP candidates will be exposed. |
1315 EXPECT_EQ(2U, candidates_.size()); // Local UDP + TCP candidate. | 1347 EXPECT_EQ(2U, candidates_.size()); // Local UDP + TCP candidate. |
1316 EXPECT_EQ(2U, ports_.size()); // UDP and TCP ports will be in ready state. | 1348 EXPECT_EQ(2U, ports_.size()); // UDP and TCP ports will be in ready state. |
1317 for (const Candidate& candidate : candidates_) { | 1349 for (const Candidate& candidate : candidates_) { |
1318 EXPECT_EQ(std::string(LOCAL_PORT_TYPE), candidate.type()); | 1350 EXPECT_EQ(std::string(LOCAL_PORT_TYPE), candidate.type()); |
1319 } | 1351 } |
1320 } | 1352 } |
1321 | 1353 |
1322 // Test that we get the same ufrag and pwd for all candidates. | 1354 // Test that we get the same ufrag and pwd for all candidates. |
1323 TEST_F(BasicPortAllocatorTest, TestEnableSharedUfrag) { | 1355 TEST_F(BasicPortAllocatorTest, TestEnableSharedUfrag) { |
1324 AddInterface(kClientAddr); | 1356 AddInterface(kClientAddr); |
1325 EXPECT_TRUE(CreateSession(ICE_CANDIDATE_COMPONENT_RTP)); | 1357 EXPECT_TRUE(CreateSession(ICE_CANDIDATE_COMPONENT_RTP)); |
1326 session_->StartGettingPorts(); | 1358 session_->StartGettingPorts(); |
1327 ASSERT_EQ_WAIT(7U, candidates_.size(), kDefaultAllocationTimeout); | 1359 ASSERT_EQ_SIMULATED_WAIT(7U, candidates_.size(), kDefaultAllocationTimeout, |
1360 fake_clock); | |
1328 EXPECT_PRED4(HasCandidate, candidates_, "local", "udp", kClientAddr); | 1361 EXPECT_PRED4(HasCandidate, candidates_, "local", "udp", kClientAddr); |
1329 EXPECT_PRED4(HasCandidate, candidates_, "stun", "udp", kClientAddr); | 1362 EXPECT_PRED4(HasCandidate, candidates_, "stun", "udp", kClientAddr); |
1330 EXPECT_PRED4(HasCandidate, candidates_, "local", "tcp", kClientAddr); | 1363 EXPECT_PRED4(HasCandidate, candidates_, "local", "tcp", kClientAddr); |
1331 EXPECT_EQ(4U, ports_.size()); | 1364 EXPECT_EQ(4U, ports_.size()); |
1332 for (const Candidate& candidate : candidates_) { | 1365 for (const Candidate& candidate : candidates_) { |
1333 EXPECT_EQ(kIceUfrag0, candidate.username()); | 1366 EXPECT_EQ(kIceUfrag0, candidate.username()); |
1334 EXPECT_EQ(kIcePwd0, candidate.password()); | 1367 EXPECT_EQ(kIcePwd0, candidate.password()); |
1335 } | 1368 } |
1336 EXPECT_TRUE(candidate_allocation_done_); | 1369 EXPECT_TRUE(candidate_allocation_done_); |
1337 } | 1370 } |
1338 | 1371 |
1339 // Test that when PORTALLOCATOR_ENABLE_SHARED_SOCKET is enabled only one port | 1372 // 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 | 1373 // 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 | 1374 // (local) if stun candidate is same as local candidate, which will be the case |
1342 // in a public network like the below test. | 1375 // in a public network like the below test. |
1343 TEST_F(BasicPortAllocatorTest, TestSharedSocketWithoutNat) { | 1376 TEST_F(BasicPortAllocatorTest, TestSharedSocketWithoutNat) { |
1344 AddInterface(kClientAddr); | 1377 AddInterface(kClientAddr); |
1345 allocator_->set_flags(allocator().flags() | | 1378 allocator_->set_flags(allocator().flags() | |
1346 PORTALLOCATOR_ENABLE_SHARED_SOCKET); | 1379 PORTALLOCATOR_ENABLE_SHARED_SOCKET); |
1347 EXPECT_TRUE(CreateSession(ICE_CANDIDATE_COMPONENT_RTP)); | 1380 EXPECT_TRUE(CreateSession(ICE_CANDIDATE_COMPONENT_RTP)); |
1348 session_->StartGettingPorts(); | 1381 session_->StartGettingPorts(); |
1349 ASSERT_EQ_WAIT(6U, candidates_.size(), kDefaultAllocationTimeout); | 1382 ASSERT_EQ_SIMULATED_WAIT(6U, candidates_.size(), kDefaultAllocationTimeout, |
1383 fake_clock); | |
1350 EXPECT_EQ(3U, ports_.size()); | 1384 EXPECT_EQ(3U, ports_.size()); |
1351 EXPECT_PRED4(HasCandidate, candidates_, "local", "udp", kClientAddr); | 1385 EXPECT_PRED4(HasCandidate, candidates_, "local", "udp", kClientAddr); |
1352 EXPECT_TRUE_WAIT(candidate_allocation_done_, kDefaultAllocationTimeout); | 1386 EXPECT_TRUE_SIMULATED_WAIT(candidate_allocation_done_, |
1387 kDefaultAllocationTimeout, fake_clock); | |
1353 } | 1388 } |
1354 | 1389 |
1355 // Test that when PORTALLOCATOR_ENABLE_SHARED_SOCKET is enabled only one port | 1390 // 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 | 1391 // is allocated for udp and stun. In this test we should expect both stun and |
1357 // local candidates as client behind a nat. | 1392 // local candidates as client behind a nat. |
1358 TEST_F(BasicPortAllocatorTest, TestSharedSocketWithNat) { | 1393 TEST_F(BasicPortAllocatorTest, TestSharedSocketWithNat) { |
1359 AddInterface(kClientAddr); | 1394 AddInterface(kClientAddr); |
1360 ResetWithStunServerAndNat(kStunAddr); | 1395 ResetWithStunServerAndNat(kStunAddr); |
1361 | 1396 |
1362 allocator_->set_flags(allocator().flags() | | 1397 allocator_->set_flags(allocator().flags() | |
1363 PORTALLOCATOR_ENABLE_SHARED_SOCKET); | 1398 PORTALLOCATOR_ENABLE_SHARED_SOCKET); |
1364 EXPECT_TRUE(CreateSession(ICE_CANDIDATE_COMPONENT_RTP)); | 1399 EXPECT_TRUE(CreateSession(ICE_CANDIDATE_COMPONENT_RTP)); |
1365 session_->StartGettingPorts(); | 1400 session_->StartGettingPorts(); |
1366 ASSERT_EQ_WAIT(3U, candidates_.size(), kDefaultAllocationTimeout); | 1401 ASSERT_EQ_SIMULATED_WAIT(3U, candidates_.size(), kDefaultAllocationTimeout, |
1402 fake_clock); | |
1367 ASSERT_EQ(2U, ports_.size()); | 1403 ASSERT_EQ(2U, ports_.size()); |
1368 EXPECT_PRED4(HasCandidate, candidates_, "local", "udp", kClientAddr); | 1404 EXPECT_PRED4(HasCandidate, candidates_, "local", "udp", kClientAddr); |
1369 EXPECT_PRED4(HasCandidate, candidates_, "stun", "udp", | 1405 EXPECT_PRED4(HasCandidate, candidates_, "stun", "udp", |
1370 rtc::SocketAddress(kNatUdpAddr.ipaddr(), 0)); | 1406 rtc::SocketAddress(kNatUdpAddr.ipaddr(), 0)); |
1371 EXPECT_TRUE_WAIT(candidate_allocation_done_, kDefaultAllocationTimeout); | 1407 EXPECT_TRUE_SIMULATED_WAIT(candidate_allocation_done_, |
1408 kDefaultAllocationTimeout, fake_clock); | |
1372 EXPECT_EQ(3U, candidates_.size()); | 1409 EXPECT_EQ(3U, candidates_.size()); |
1373 } | 1410 } |
1374 | 1411 |
1375 // Test TURN port in shared socket mode with UDP and TCP TURN server addresses. | 1412 // Test TURN port in shared socket mode with UDP and TCP TURN server addresses. |
1376 TEST_F(BasicPortAllocatorTest, TestSharedSocketWithoutNatUsingTurn) { | 1413 TEST_F(BasicPortAllocatorTest, TestSharedSocketWithoutNatUsingTurn) { |
1377 turn_server_.AddInternalSocket(kTurnTcpIntAddr, PROTO_TCP); | 1414 turn_server_.AddInternalSocket(kTurnTcpIntAddr, PROTO_TCP); |
1378 AddInterface(kClientAddr); | 1415 AddInterface(kClientAddr); |
1379 allocator_.reset(new BasicPortAllocator(&network_manager_)); | 1416 allocator_.reset(new BasicPortAllocator(&network_manager_)); |
1380 | 1417 |
1381 AddTurnServers(kTurnUdpIntAddr, kTurnTcpIntAddr); | 1418 AddTurnServers(kTurnUdpIntAddr, kTurnTcpIntAddr); |
1382 | 1419 |
1383 allocator_->set_step_delay(kMinimumStepDelay); | 1420 allocator_->set_step_delay(kMinimumStepDelay); |
1384 allocator_->set_flags(allocator().flags() | | 1421 allocator_->set_flags(allocator().flags() | |
1385 PORTALLOCATOR_ENABLE_SHARED_SOCKET | | 1422 PORTALLOCATOR_ENABLE_SHARED_SOCKET | |
1386 PORTALLOCATOR_DISABLE_TCP); | 1423 PORTALLOCATOR_DISABLE_TCP); |
1387 | 1424 |
1388 EXPECT_TRUE(CreateSession(ICE_CANDIDATE_COMPONENT_RTP)); | 1425 EXPECT_TRUE(CreateSession(ICE_CANDIDATE_COMPONENT_RTP)); |
1389 session_->StartGettingPorts(); | 1426 session_->StartGettingPorts(); |
1390 | 1427 |
1391 ASSERT_EQ_WAIT(3U, candidates_.size(), kDefaultAllocationTimeout); | 1428 ASSERT_EQ_SIMULATED_WAIT(3U, candidates_.size(), kDefaultAllocationTimeout, |
1429 fake_clock); | |
1392 ASSERT_EQ(3U, ports_.size()); | 1430 ASSERT_EQ(3U, ports_.size()); |
1393 EXPECT_PRED4(HasCandidate, candidates_, "local", "udp", kClientAddr); | 1431 EXPECT_PRED4(HasCandidate, candidates_, "local", "udp", kClientAddr); |
1394 EXPECT_PRED4(HasCandidate, candidates_, "relay", "udp", | 1432 EXPECT_PRED4(HasCandidate, candidates_, "relay", "udp", |
1395 rtc::SocketAddress(kTurnUdpExtAddr.ipaddr(), 0)); | 1433 rtc::SocketAddress(kTurnUdpExtAddr.ipaddr(), 0)); |
1396 EXPECT_PRED4(HasCandidate, candidates_, "relay", "udp", | 1434 EXPECT_PRED4(HasCandidate, candidates_, "relay", "udp", |
1397 rtc::SocketAddress(kTurnUdpExtAddr.ipaddr(), 0)); | 1435 rtc::SocketAddress(kTurnUdpExtAddr.ipaddr(), 0)); |
1398 EXPECT_TRUE_WAIT(candidate_allocation_done_, kDefaultAllocationTimeout); | 1436 EXPECT_TRUE_SIMULATED_WAIT(candidate_allocation_done_, |
1437 kDefaultAllocationTimeout, fake_clock); | |
1399 EXPECT_EQ(3U, candidates_.size()); | 1438 EXPECT_EQ(3U, candidates_.size()); |
1400 } | 1439 } |
1401 | 1440 |
1402 // Test that if prune_turn_ports is set, TCP TURN port will not be used | 1441 // 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. | 1442 // if UDP TurnPort is used, given that TCP TURN port becomes ready first. |
1404 TEST_F(BasicPortAllocatorTest, | 1443 TEST_F(BasicPortAllocatorTest, |
1405 TestUdpTurnPortPrunesTcpTurnPortWithTcpPortReadyFirst) { | 1444 TestUdpTurnPortPrunesTcpTurnPortWithTcpPortReadyFirst) { |
1406 // UDP has longer delay than TCP so that TCP TURN port becomes ready first. | 1445 // UDP has longer delay than TCP so that TCP TURN port becomes ready first. |
1407 virtual_socket_server()->SetDelayOnAddress(kTurnUdpIntAddr, 200); | 1446 virtual_socket_server()->SetDelayOnAddress(kTurnUdpIntAddr, 200); |
1408 virtual_socket_server()->SetDelayOnAddress(kTurnTcpIntAddr, 100); | 1447 virtual_socket_server()->SetDelayOnAddress(kTurnTcpIntAddr, 100); |
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1482 allocator_->AddTurnServer(turn_server); | 1521 allocator_->AddTurnServer(turn_server); |
1483 | 1522 |
1484 allocator_->set_step_delay(kMinimumStepDelay); | 1523 allocator_->set_step_delay(kMinimumStepDelay); |
1485 allocator_->set_flags(allocator().flags() | | 1524 allocator_->set_flags(allocator().flags() | |
1486 PORTALLOCATOR_ENABLE_SHARED_SOCKET | | 1525 PORTALLOCATOR_ENABLE_SHARED_SOCKET | |
1487 PORTALLOCATOR_DISABLE_TCP); | 1526 PORTALLOCATOR_DISABLE_TCP); |
1488 | 1527 |
1489 EXPECT_TRUE(CreateSession(ICE_CANDIDATE_COMPONENT_RTP)); | 1528 EXPECT_TRUE(CreateSession(ICE_CANDIDATE_COMPONENT_RTP)); |
1490 session_->StartGettingPorts(); | 1529 session_->StartGettingPorts(); |
1491 | 1530 |
1492 EXPECT_EQ_WAIT(2U, ports_.size(), kDefaultAllocationTimeout); | 1531 EXPECT_EQ_SIMULATED_WAIT(2U, ports_.size(), kDefaultAllocationTimeout, |
1532 fake_clock); | |
1493 } | 1533 } |
1494 | 1534 |
1495 // Test that when PORTALLOCATOR_ENABLE_SHARED_SOCKET is enabled only one port | 1535 // Test that when PORTALLOCATOR_ENABLE_SHARED_SOCKET is enabled only one port |
1496 // is allocated for udp/stun/turn. In this test we should expect all local, | 1536 // is allocated for udp/stun/turn. In this test we should expect all local, |
1497 // stun and turn candidates. | 1537 // stun and turn candidates. |
1498 TEST_F(BasicPortAllocatorTest, TestSharedSocketWithNatUsingTurn) { | 1538 TEST_F(BasicPortAllocatorTest, TestSharedSocketWithNatUsingTurn) { |
1499 AddInterface(kClientAddr); | 1539 AddInterface(kClientAddr); |
1500 ResetWithStunServerAndNat(kStunAddr); | 1540 ResetWithStunServerAndNat(kStunAddr); |
1501 | 1541 |
1502 AddTurnServers(kTurnUdpIntAddr, rtc::SocketAddress()); | 1542 AddTurnServers(kTurnUdpIntAddr, rtc::SocketAddress()); |
1503 | 1543 |
1504 allocator_->set_flags(allocator().flags() | | 1544 allocator_->set_flags(allocator().flags() | |
1505 PORTALLOCATOR_ENABLE_SHARED_SOCKET | | 1545 PORTALLOCATOR_ENABLE_SHARED_SOCKET | |
1506 PORTALLOCATOR_DISABLE_TCP); | 1546 PORTALLOCATOR_DISABLE_TCP); |
1507 | 1547 |
1508 EXPECT_TRUE(CreateSession(ICE_CANDIDATE_COMPONENT_RTP)); | 1548 EXPECT_TRUE(CreateSession(ICE_CANDIDATE_COMPONENT_RTP)); |
1509 session_->StartGettingPorts(); | 1549 session_->StartGettingPorts(); |
1510 | 1550 |
1511 ASSERT_EQ_WAIT(3U, candidates_.size(), kDefaultAllocationTimeout); | 1551 ASSERT_EQ_SIMULATED_WAIT(3U, candidates_.size(), kDefaultAllocationTimeout, |
1552 fake_clock); | |
1512 ASSERT_EQ(2U, ports_.size()); | 1553 ASSERT_EQ(2U, ports_.size()); |
1513 EXPECT_PRED4(HasCandidate, candidates_, "local", "udp", kClientAddr); | 1554 EXPECT_PRED4(HasCandidate, candidates_, "local", "udp", kClientAddr); |
1514 EXPECT_PRED4(HasCandidate, candidates_, "stun", "udp", | 1555 EXPECT_PRED4(HasCandidate, candidates_, "stun", "udp", |
1515 rtc::SocketAddress(kNatUdpAddr.ipaddr(), 0)); | 1556 rtc::SocketAddress(kNatUdpAddr.ipaddr(), 0)); |
1516 EXPECT_PRED4(HasCandidate, candidates_, "relay", "udp", | 1557 EXPECT_PRED4(HasCandidate, candidates_, "relay", "udp", |
1517 rtc::SocketAddress(kTurnUdpExtAddr.ipaddr(), 0)); | 1558 rtc::SocketAddress(kTurnUdpExtAddr.ipaddr(), 0)); |
1518 EXPECT_TRUE_WAIT(candidate_allocation_done_, kDefaultAllocationTimeout); | 1559 EXPECT_TRUE_SIMULATED_WAIT(candidate_allocation_done_, |
1560 kDefaultAllocationTimeout, fake_clock); | |
1519 EXPECT_EQ(3U, candidates_.size()); | 1561 EXPECT_EQ(3U, candidates_.size()); |
1520 // Local port will be created first and then TURN port. | 1562 // Local port will be created first and then TURN port. |
1521 EXPECT_EQ(2U, ports_[0]->Candidates().size()); | 1563 EXPECT_EQ(2U, ports_[0]->Candidates().size()); |
1522 EXPECT_EQ(1U, ports_[1]->Candidates().size()); | 1564 EXPECT_EQ(1U, ports_[1]->Candidates().size()); |
1523 } | 1565 } |
1524 | 1566 |
1525 // Test that when PORTALLOCATOR_ENABLE_SHARED_SOCKET is enabled and the TURN | 1567 // 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 | 1568 // server is also used as the STUN server, we should get 'local', 'stun', and |
1527 // 'relay' candidates. | 1569 // 'relay' candidates. |
1528 TEST_F(BasicPortAllocatorTest, TestSharedSocketWithNatUsingTurnAsStun) { | 1570 TEST_F(BasicPortAllocatorTest, TestSharedSocketWithNatUsingTurnAsStun) { |
1529 AddInterface(kClientAddr); | 1571 AddInterface(kClientAddr); |
1530 // Use an empty SocketAddress to add a NAT without STUN server. | 1572 // Use an empty SocketAddress to add a NAT without STUN server. |
1531 ResetWithStunServerAndNat(SocketAddress()); | 1573 ResetWithStunServerAndNat(SocketAddress()); |
1532 AddTurnServers(kTurnUdpIntAddr, rtc::SocketAddress()); | 1574 AddTurnServers(kTurnUdpIntAddr, rtc::SocketAddress()); |
1533 | 1575 |
1534 // Must set the step delay to 0 to make sure the relay allocation phase is | 1576 // 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 | 1577 // started before the STUN candidates are obtained, so that the STUN binding |
1536 // response is processed when both StunPort and TurnPort exist to reproduce | 1578 // response is processed when both StunPort and TurnPort exist to reproduce |
1537 // webrtc issue 3537. | 1579 // webrtc issue 3537. |
1538 allocator_->set_step_delay(0); | 1580 allocator_->set_step_delay(0); |
1539 allocator_->set_flags(allocator().flags() | | 1581 allocator_->set_flags(allocator().flags() | |
1540 PORTALLOCATOR_ENABLE_SHARED_SOCKET | | 1582 PORTALLOCATOR_ENABLE_SHARED_SOCKET | |
1541 PORTALLOCATOR_DISABLE_TCP); | 1583 PORTALLOCATOR_DISABLE_TCP); |
1542 | 1584 |
1543 EXPECT_TRUE(CreateSession(ICE_CANDIDATE_COMPONENT_RTP)); | 1585 EXPECT_TRUE(CreateSession(ICE_CANDIDATE_COMPONENT_RTP)); |
1544 session_->StartGettingPorts(); | 1586 session_->StartGettingPorts(); |
1545 | 1587 |
1546 ASSERT_EQ_WAIT(3U, candidates_.size(), kDefaultAllocationTimeout); | 1588 ASSERT_EQ_SIMULATED_WAIT(3U, candidates_.size(), kDefaultAllocationTimeout, |
1589 fake_clock); | |
1547 EXPECT_PRED4(HasCandidate, candidates_, "local", "udp", kClientAddr); | 1590 EXPECT_PRED4(HasCandidate, candidates_, "local", "udp", kClientAddr); |
1548 Candidate stun_candidate; | 1591 Candidate stun_candidate; |
1549 EXPECT_PRED5(FindCandidate, candidates_, "stun", "udp", | 1592 EXPECT_PRED5(FindCandidate, candidates_, "stun", "udp", |
1550 rtc::SocketAddress(kNatUdpAddr.ipaddr(), 0), &stun_candidate); | 1593 rtc::SocketAddress(kNatUdpAddr.ipaddr(), 0), &stun_candidate); |
1551 EXPECT_PRED5(HasCandidateWithRelatedAddr, candidates_, "relay", "udp", | 1594 EXPECT_PRED5(HasCandidateWithRelatedAddr, candidates_, "relay", "udp", |
1552 rtc::SocketAddress(kTurnUdpExtAddr.ipaddr(), 0), | 1595 rtc::SocketAddress(kTurnUdpExtAddr.ipaddr(), 0), |
1553 stun_candidate.address()); | 1596 stun_candidate.address()); |
1554 | 1597 |
1555 EXPECT_TRUE_WAIT(candidate_allocation_done_, kDefaultAllocationTimeout); | 1598 EXPECT_TRUE_SIMULATED_WAIT(candidate_allocation_done_, |
1599 kDefaultAllocationTimeout, fake_clock); | |
1556 EXPECT_EQ(3U, candidates_.size()); | 1600 EXPECT_EQ(3U, candidates_.size()); |
1557 // Local port will be created first and then TURN port. | 1601 // Local port will be created first and then TURN port. |
1558 EXPECT_EQ(2U, ports_[0]->Candidates().size()); | 1602 EXPECT_EQ(2U, ports_[0]->Candidates().size()); |
1559 EXPECT_EQ(1U, ports_[1]->Candidates().size()); | 1603 EXPECT_EQ(1U, ports_[1]->Candidates().size()); |
1560 } | 1604 } |
1561 | 1605 |
1562 // Test that when only a TCP TURN server is available, we do NOT use it as | 1606 // 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 | 1607 // a UDP STUN server, as this could leak our IP address. Thus we should only |
1564 // expect two ports, a UDPPort and TurnPort. | 1608 // expect two ports, a UDPPort and TurnPort. |
1565 TEST_F(BasicPortAllocatorTest, TestSharedSocketWithNatUsingTurnTcpOnly) { | 1609 TEST_F(BasicPortAllocatorTest, TestSharedSocketWithNatUsingTurnTcpOnly) { |
1566 turn_server_.AddInternalSocket(kTurnTcpIntAddr, PROTO_TCP); | 1610 turn_server_.AddInternalSocket(kTurnTcpIntAddr, PROTO_TCP); |
1567 AddInterface(kClientAddr); | 1611 AddInterface(kClientAddr); |
1568 ResetWithStunServerAndNat(rtc::SocketAddress()); | 1612 ResetWithStunServerAndNat(rtc::SocketAddress()); |
1569 AddTurnServers(rtc::SocketAddress(), kTurnTcpIntAddr); | 1613 AddTurnServers(rtc::SocketAddress(), kTurnTcpIntAddr); |
1570 | 1614 |
1571 allocator_->set_flags(allocator().flags() | | 1615 allocator_->set_flags(allocator().flags() | |
1572 PORTALLOCATOR_ENABLE_SHARED_SOCKET | | 1616 PORTALLOCATOR_ENABLE_SHARED_SOCKET | |
1573 PORTALLOCATOR_DISABLE_TCP); | 1617 PORTALLOCATOR_DISABLE_TCP); |
1574 | 1618 |
1575 EXPECT_TRUE(CreateSession(ICE_CANDIDATE_COMPONENT_RTP)); | 1619 EXPECT_TRUE(CreateSession(ICE_CANDIDATE_COMPONENT_RTP)); |
1576 session_->StartGettingPorts(); | 1620 session_->StartGettingPorts(); |
1577 | 1621 |
1578 ASSERT_EQ_WAIT(2U, candidates_.size(), kDefaultAllocationTimeout); | 1622 ASSERT_EQ_SIMULATED_WAIT(2U, candidates_.size(), kDefaultAllocationTimeout, |
1623 fake_clock); | |
1579 ASSERT_EQ(2U, ports_.size()); | 1624 ASSERT_EQ(2U, ports_.size()); |
1580 EXPECT_PRED4(HasCandidate, candidates_, "local", "udp", kClientAddr); | 1625 EXPECT_PRED4(HasCandidate, candidates_, "local", "udp", kClientAddr); |
1581 EXPECT_PRED4(HasCandidate, candidates_, "relay", "udp", | 1626 EXPECT_PRED4(HasCandidate, candidates_, "relay", "udp", |
1582 rtc::SocketAddress(kTurnUdpExtAddr.ipaddr(), 0)); | 1627 rtc::SocketAddress(kTurnUdpExtAddr.ipaddr(), 0)); |
1583 EXPECT_TRUE_WAIT(candidate_allocation_done_, kDefaultAllocationTimeout); | 1628 EXPECT_TRUE_SIMULATED_WAIT(candidate_allocation_done_, |
1629 kDefaultAllocationTimeout, fake_clock); | |
1584 EXPECT_EQ(2U, candidates_.size()); | 1630 EXPECT_EQ(2U, candidates_.size()); |
1585 EXPECT_EQ(1U, ports_[0]->Candidates().size()); | 1631 EXPECT_EQ(1U, ports_[0]->Candidates().size()); |
1586 EXPECT_EQ(1U, ports_[1]->Candidates().size()); | 1632 EXPECT_EQ(1U, ports_[1]->Candidates().size()); |
1587 } | 1633 } |
1588 | 1634 |
1589 // Test that even when PORTALLOCATOR_ENABLE_SHARED_SOCKET is NOT enabled, the | 1635 // 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 | 1636 // TURN server is used as the STUN server and we get 'local', 'stun', and |
1591 // 'relay' candidates. | 1637 // 'relay' candidates. |
1592 // TODO(deadbeef): Remove this test when support for non-shared socket mode | 1638 // TODO(deadbeef): Remove this test when support for non-shared socket mode |
1593 // is removed. | 1639 // is removed. |
1594 TEST_F(BasicPortAllocatorTest, TestNonSharedSocketWithNatUsingTurnAsStun) { | 1640 TEST_F(BasicPortAllocatorTest, TestNonSharedSocketWithNatUsingTurnAsStun) { |
1595 AddInterface(kClientAddr); | 1641 AddInterface(kClientAddr); |
1596 // Use an empty SocketAddress to add a NAT without STUN server. | 1642 // Use an empty SocketAddress to add a NAT without STUN server. |
1597 ResetWithStunServerAndNat(SocketAddress()); | 1643 ResetWithStunServerAndNat(SocketAddress()); |
1598 AddTurnServers(kTurnUdpIntAddr, rtc::SocketAddress()); | 1644 AddTurnServers(kTurnUdpIntAddr, rtc::SocketAddress()); |
1599 | 1645 |
1600 allocator_->set_flags(allocator().flags() | PORTALLOCATOR_DISABLE_TCP); | 1646 allocator_->set_flags(allocator().flags() | PORTALLOCATOR_DISABLE_TCP); |
1601 | 1647 |
1602 EXPECT_TRUE(CreateSession(ICE_CANDIDATE_COMPONENT_RTP)); | 1648 EXPECT_TRUE(CreateSession(ICE_CANDIDATE_COMPONENT_RTP)); |
1603 session_->StartGettingPorts(); | 1649 session_->StartGettingPorts(); |
1604 | 1650 |
1605 ASSERT_EQ_WAIT(3U, candidates_.size(), kDefaultAllocationTimeout); | 1651 ASSERT_EQ_SIMULATED_WAIT(3U, candidates_.size(), kDefaultAllocationTimeout, |
1652 fake_clock); | |
1606 ASSERT_EQ(3U, ports_.size()); | 1653 ASSERT_EQ(3U, ports_.size()); |
1607 EXPECT_PRED4(HasCandidate, candidates_, "local", "udp", kClientAddr); | 1654 EXPECT_PRED4(HasCandidate, candidates_, "local", "udp", kClientAddr); |
1608 Candidate stun_candidate; | 1655 Candidate stun_candidate; |
1609 EXPECT_PRED5(FindCandidate, candidates_, "stun", "udp", | 1656 EXPECT_PRED5(FindCandidate, candidates_, "stun", "udp", |
1610 rtc::SocketAddress(kNatUdpAddr.ipaddr(), 0), &stun_candidate); | 1657 rtc::SocketAddress(kNatUdpAddr.ipaddr(), 0), &stun_candidate); |
1611 Candidate turn_candidate; | 1658 Candidate turn_candidate; |
1612 EXPECT_PRED5(FindCandidate, candidates_, "relay", "udp", | 1659 EXPECT_PRED5(FindCandidate, candidates_, "relay", "udp", |
1613 rtc::SocketAddress(kTurnUdpExtAddr.ipaddr(), 0), | 1660 rtc::SocketAddress(kTurnUdpExtAddr.ipaddr(), 0), |
1614 &turn_candidate); | 1661 &turn_candidate); |
1615 // Not using shared socket, so the STUN request's server reflexive address | 1662 // Not using shared socket, so the STUN request's server reflexive address |
1616 // should be different than the TURN request's server reflexive address. | 1663 // should be different than the TURN request's server reflexive address. |
1617 EXPECT_NE(turn_candidate.related_address(), stun_candidate.address()); | 1664 EXPECT_NE(turn_candidate.related_address(), stun_candidate.address()); |
1618 | 1665 |
1619 EXPECT_TRUE_WAIT(candidate_allocation_done_, kDefaultAllocationTimeout); | 1666 EXPECT_TRUE_SIMULATED_WAIT(candidate_allocation_done_, |
1667 kDefaultAllocationTimeout, fake_clock); | |
1620 EXPECT_EQ(3U, candidates_.size()); | 1668 EXPECT_EQ(3U, candidates_.size()); |
1621 EXPECT_EQ(1U, ports_[0]->Candidates().size()); | 1669 EXPECT_EQ(1U, ports_[0]->Candidates().size()); |
1622 EXPECT_EQ(1U, ports_[1]->Candidates().size()); | 1670 EXPECT_EQ(1U, ports_[1]->Candidates().size()); |
1623 EXPECT_EQ(1U, ports_[2]->Candidates().size()); | 1671 EXPECT_EQ(1U, ports_[2]->Candidates().size()); |
1624 } | 1672 } |
1625 | 1673 |
1626 // Test that even when both a STUN and TURN server are configured, the TURN | 1674 // 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. | 1675 // server is used as a STUN server and we get a 'stun' candidate. |
1628 TEST_F(BasicPortAllocatorTest, TestSharedSocketWithNatUsingTurnAndStun) { | 1676 TEST_F(BasicPortAllocatorTest, TestSharedSocketWithNatUsingTurnAndStun) { |
1629 AddInterface(kClientAddr); | 1677 AddInterface(kClientAddr); |
1630 // Configure with STUN server but destroy it, so we can ensure that it's | 1678 // 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. | 1679 // the TURN server actually being used as a STUN server. |
1632 ResetWithStunServerAndNat(kStunAddr); | 1680 ResetWithStunServerAndNat(kStunAddr); |
1633 stun_server_.reset(); | 1681 stun_server_.reset(); |
1634 AddTurnServers(kTurnUdpIntAddr, rtc::SocketAddress()); | 1682 AddTurnServers(kTurnUdpIntAddr, rtc::SocketAddress()); |
1635 | 1683 |
1636 allocator_->set_flags(allocator().flags() | | 1684 allocator_->set_flags(allocator().flags() | |
1637 PORTALLOCATOR_ENABLE_SHARED_SOCKET | | 1685 PORTALLOCATOR_ENABLE_SHARED_SOCKET | |
1638 PORTALLOCATOR_DISABLE_TCP); | 1686 PORTALLOCATOR_DISABLE_TCP); |
1639 | 1687 |
1640 EXPECT_TRUE(CreateSession(ICE_CANDIDATE_COMPONENT_RTP)); | 1688 EXPECT_TRUE(CreateSession(ICE_CANDIDATE_COMPONENT_RTP)); |
1641 session_->StartGettingPorts(); | 1689 session_->StartGettingPorts(); |
1642 | 1690 |
1643 ASSERT_EQ_WAIT(3U, candidates_.size(), kDefaultAllocationTimeout); | 1691 ASSERT_EQ_SIMULATED_WAIT(3U, candidates_.size(), kDefaultAllocationTimeout, |
1692 fake_clock); | |
1644 EXPECT_PRED4(HasCandidate, candidates_, "local", "udp", kClientAddr); | 1693 EXPECT_PRED4(HasCandidate, candidates_, "local", "udp", kClientAddr); |
1645 Candidate stun_candidate; | 1694 Candidate stun_candidate; |
1646 EXPECT_PRED5(FindCandidate, candidates_, "stun", "udp", | 1695 EXPECT_PRED5(FindCandidate, candidates_, "stun", "udp", |
1647 rtc::SocketAddress(kNatUdpAddr.ipaddr(), 0), &stun_candidate); | 1696 rtc::SocketAddress(kNatUdpAddr.ipaddr(), 0), &stun_candidate); |
1648 EXPECT_PRED5(HasCandidateWithRelatedAddr, candidates_, "relay", "udp", | 1697 EXPECT_PRED5(HasCandidateWithRelatedAddr, candidates_, "relay", "udp", |
1649 rtc::SocketAddress(kTurnUdpExtAddr.ipaddr(), 0), | 1698 rtc::SocketAddress(kTurnUdpExtAddr.ipaddr(), 0), |
1650 stun_candidate.address()); | 1699 stun_candidate.address()); |
1651 | 1700 |
1652 // Don't bother waiting for STUN timeout, since we already verified | 1701 // Don't bother waiting for STUN timeout, since we already verified |
1653 // that we got a STUN candidate from the TURN server. | 1702 // that we got a STUN candidate from the TURN server. |
1654 } | 1703 } |
1655 | 1704 |
1656 // This test verifies when PORTALLOCATOR_ENABLE_SHARED_SOCKET flag is enabled | 1705 // This test verifies when PORTALLOCATOR_ENABLE_SHARED_SOCKET flag is enabled |
1657 // and fail to generate STUN candidate, local UDP candidate is generated | 1706 // and fail to generate STUN candidate, local UDP candidate is generated |
1658 // properly. | 1707 // properly. |
1659 TEST_F(BasicPortAllocatorTest, TestSharedSocketNoUdpAllowed) { | 1708 TEST_F(BasicPortAllocatorTest, TestSharedSocketNoUdpAllowed) { |
1660 allocator().set_flags(allocator().flags() | PORTALLOCATOR_DISABLE_RELAY | | 1709 allocator().set_flags(allocator().flags() | PORTALLOCATOR_DISABLE_RELAY | |
1661 PORTALLOCATOR_DISABLE_TCP | | 1710 PORTALLOCATOR_DISABLE_TCP | |
1662 PORTALLOCATOR_ENABLE_SHARED_SOCKET); | 1711 PORTALLOCATOR_ENABLE_SHARED_SOCKET); |
1663 fss_->AddRule(false, rtc::FP_UDP, rtc::FD_ANY, kClientAddr); | 1712 fss_->AddRule(false, rtc::FP_UDP, rtc::FD_ANY, kClientAddr); |
1664 AddInterface(kClientAddr); | 1713 AddInterface(kClientAddr); |
1665 EXPECT_TRUE(CreateSession(ICE_CANDIDATE_COMPONENT_RTP)); | 1714 EXPECT_TRUE(CreateSession(ICE_CANDIDATE_COMPONENT_RTP)); |
1666 session_->StartGettingPorts(); | 1715 session_->StartGettingPorts(); |
1667 ASSERT_EQ_WAIT(1U, ports_.size(), kDefaultAllocationTimeout); | 1716 ASSERT_EQ_SIMULATED_WAIT(1U, ports_.size(), kDefaultAllocationTimeout, |
1717 fake_clock); | |
1668 EXPECT_EQ(1U, candidates_.size()); | 1718 EXPECT_EQ(1U, candidates_.size()); |
1669 EXPECT_PRED4(HasCandidate, candidates_, "local", "udp", kClientAddr); | 1719 EXPECT_PRED4(HasCandidate, candidates_, "local", "udp", kClientAddr); |
1670 // STUN timeout is 9.5sec. We need to wait to get candidate done signal. | 1720 // STUN timeout is 9.5sec. We need to wait to get candidate done signal. |
1671 EXPECT_TRUE_WAIT(candidate_allocation_done_, kStunTimeoutMs); | 1721 EXPECT_TRUE_SIMULATED_WAIT(candidate_allocation_done_, kStunTimeoutMs, |
1722 fake_clock); | |
1672 EXPECT_EQ(1U, candidates_.size()); | 1723 EXPECT_EQ(1U, candidates_.size()); |
1673 } | 1724 } |
1674 | 1725 |
1675 // Test that when the NetworkManager doesn't have permission to enumerate | 1726 // Test that when the NetworkManager doesn't have permission to enumerate |
1676 // adapters, the PORTALLOCATOR_DISABLE_ADAPTER_ENUMERATION is specified | 1727 // adapters, the PORTALLOCATOR_DISABLE_ADAPTER_ENUMERATION is specified |
1677 // automatically. | 1728 // automatically. |
1678 TEST_F(BasicPortAllocatorTest, TestNetworkPermissionBlocked) { | 1729 TEST_F(BasicPortAllocatorTest, TestNetworkPermissionBlocked) { |
1679 network_manager_.set_default_local_addresses(kPrivateAddr.ipaddr(), | 1730 network_manager_.set_default_local_addresses(kPrivateAddr.ipaddr(), |
1680 rtc::IPAddress()); | 1731 rtc::IPAddress()); |
1681 network_manager_.set_enumeration_permission( | 1732 network_manager_.set_enumeration_permission( |
1682 rtc::NetworkManager::ENUMERATION_BLOCKED); | 1733 rtc::NetworkManager::ENUMERATION_BLOCKED); |
1683 allocator().set_flags(allocator().flags() | PORTALLOCATOR_DISABLE_RELAY | | 1734 allocator().set_flags(allocator().flags() | PORTALLOCATOR_DISABLE_RELAY | |
1684 PORTALLOCATOR_DISABLE_TCP | | 1735 PORTALLOCATOR_DISABLE_TCP | |
1685 PORTALLOCATOR_ENABLE_SHARED_SOCKET); | 1736 PORTALLOCATOR_ENABLE_SHARED_SOCKET); |
1686 EXPECT_EQ(0U, | 1737 EXPECT_EQ(0U, |
1687 allocator_->flags() & PORTALLOCATOR_DISABLE_ADAPTER_ENUMERATION); | 1738 allocator_->flags() & PORTALLOCATOR_DISABLE_ADAPTER_ENUMERATION); |
1688 EXPECT_TRUE(CreateSession(ICE_CANDIDATE_COMPONENT_RTP)); | 1739 EXPECT_TRUE(CreateSession(ICE_CANDIDATE_COMPONENT_RTP)); |
1689 EXPECT_EQ(0U, session_->flags() & PORTALLOCATOR_DISABLE_ADAPTER_ENUMERATION); | 1740 EXPECT_EQ(0U, session_->flags() & PORTALLOCATOR_DISABLE_ADAPTER_ENUMERATION); |
1690 session_->StartGettingPorts(); | 1741 session_->StartGettingPorts(); |
1691 EXPECT_EQ_WAIT(1U, ports_.size(), kDefaultAllocationTimeout); | 1742 EXPECT_EQ_SIMULATED_WAIT(1U, ports_.size(), kDefaultAllocationTimeout, |
1743 fake_clock); | |
1692 EXPECT_EQ(1U, candidates_.size()); | 1744 EXPECT_EQ(1U, candidates_.size()); |
1693 EXPECT_PRED4(HasCandidate, candidates_, "local", "udp", kPrivateAddr); | 1745 EXPECT_PRED4(HasCandidate, candidates_, "local", "udp", kPrivateAddr); |
1694 EXPECT_NE(0U, session_->flags() & PORTALLOCATOR_DISABLE_ADAPTER_ENUMERATION); | 1746 EXPECT_NE(0U, session_->flags() & PORTALLOCATOR_DISABLE_ADAPTER_ENUMERATION); |
1695 } | 1747 } |
1696 | 1748 |
1697 // This test verifies allocator can use IPv6 addresses along with IPv4. | 1749 // This test verifies allocator can use IPv6 addresses along with IPv4. |
1698 TEST_F(BasicPortAllocatorTest, TestEnableIPv6Addresses) { | 1750 TEST_F(BasicPortAllocatorTest, TestEnableIPv6Addresses) { |
1699 allocator().set_flags(allocator().flags() | PORTALLOCATOR_DISABLE_RELAY | | 1751 allocator().set_flags(allocator().flags() | PORTALLOCATOR_DISABLE_RELAY | |
1700 PORTALLOCATOR_ENABLE_IPV6 | | 1752 PORTALLOCATOR_ENABLE_IPV6 | |
1701 PORTALLOCATOR_ENABLE_SHARED_SOCKET); | 1753 PORTALLOCATOR_ENABLE_SHARED_SOCKET); |
1702 AddInterface(kClientIPv6Addr); | 1754 AddInterface(kClientIPv6Addr); |
1703 AddInterface(kClientAddr); | 1755 AddInterface(kClientAddr); |
1704 allocator_->set_step_delay(kMinimumStepDelay); | 1756 allocator_->set_step_delay(kMinimumStepDelay); |
1705 EXPECT_TRUE(CreateSession(ICE_CANDIDATE_COMPONENT_RTP)); | 1757 EXPECT_TRUE(CreateSession(ICE_CANDIDATE_COMPONENT_RTP)); |
1706 session_->StartGettingPorts(); | 1758 session_->StartGettingPorts(); |
1707 ASSERT_EQ_WAIT(4U, ports_.size(), kDefaultAllocationTimeout); | 1759 ASSERT_EQ_SIMULATED_WAIT(4U, ports_.size(), kDefaultAllocationTimeout, |
1760 fake_clock); | |
1708 EXPECT_EQ(4U, candidates_.size()); | 1761 EXPECT_EQ(4U, candidates_.size()); |
1709 EXPECT_TRUE_WAIT(candidate_allocation_done_, kDefaultAllocationTimeout); | 1762 EXPECT_TRUE_SIMULATED_WAIT(candidate_allocation_done_, |
1763 kDefaultAllocationTimeout, fake_clock); | |
1710 EXPECT_PRED4(HasCandidate, candidates_, "local", "udp", kClientIPv6Addr); | 1764 EXPECT_PRED4(HasCandidate, candidates_, "local", "udp", kClientIPv6Addr); |
1711 EXPECT_PRED4(HasCandidate, candidates_, "local", "udp", kClientAddr); | 1765 EXPECT_PRED4(HasCandidate, candidates_, "local", "udp", kClientAddr); |
1712 EXPECT_PRED4(HasCandidate, candidates_, "local", "tcp", kClientIPv6Addr); | 1766 EXPECT_PRED4(HasCandidate, candidates_, "local", "tcp", kClientIPv6Addr); |
1713 EXPECT_PRED4(HasCandidate, candidates_, "local", "tcp", kClientAddr); | 1767 EXPECT_PRED4(HasCandidate, candidates_, "local", "tcp", kClientAddr); |
1714 EXPECT_EQ(4U, candidates_.size()); | 1768 EXPECT_EQ(4U, candidates_.size()); |
1715 } | 1769 } |
1716 | 1770 |
1717 TEST_F(BasicPortAllocatorTest, TestStopGettingPorts) { | 1771 TEST_F(BasicPortAllocatorTest, TestStopGettingPorts) { |
1718 AddInterface(kClientAddr); | 1772 AddInterface(kClientAddr); |
1719 allocator_->set_step_delay(kDefaultStepDelay); | 1773 allocator_->set_step_delay(kDefaultStepDelay); |
1720 EXPECT_TRUE(CreateSession(ICE_CANDIDATE_COMPONENT_RTP)); | 1774 EXPECT_TRUE(CreateSession(ICE_CANDIDATE_COMPONENT_RTP)); |
1721 session_->StartGettingPorts(); | 1775 session_->StartGettingPorts(); |
1722 ASSERT_EQ_WAIT(2U, candidates_.size(), 1000); | 1776 ASSERT_EQ_SIMULATED_WAIT(2U, candidates_.size(), 1000, fake_clock); |
1723 EXPECT_EQ(2U, ports_.size()); | 1777 EXPECT_EQ(2U, ports_.size()); |
1724 session_->StopGettingPorts(); | 1778 session_->StopGettingPorts(); |
1725 EXPECT_TRUE_WAIT(candidate_allocation_done_, 1000); | 1779 EXPECT_TRUE_SIMULATED_WAIT(candidate_allocation_done_, 1000, fake_clock); |
1726 | 1780 |
1727 // After stopping getting ports, adding a new interface will not start | 1781 // After stopping getting ports, adding a new interface will not start |
1728 // getting ports again. | 1782 // getting ports again. |
1729 allocator_->set_step_delay(kMinimumStepDelay); | 1783 allocator_->set_step_delay(kMinimumStepDelay); |
1730 candidates_.clear(); | 1784 candidates_.clear(); |
1731 ports_.clear(); | 1785 ports_.clear(); |
1732 candidate_allocation_done_ = false; | 1786 candidate_allocation_done_ = false; |
1733 network_manager_.AddInterface(kClientAddr2); | 1787 network_manager_.AddInterface(kClientAddr2); |
1734 rtc::Thread::Current()->ProcessMessages(1000); | 1788 SIMULATED_WAIT(false, 1000, fake_clock); |
1735 EXPECT_EQ(0U, candidates_.size()); | 1789 EXPECT_EQ(0U, candidates_.size()); |
1736 EXPECT_EQ(0U, ports_.size()); | 1790 EXPECT_EQ(0U, ports_.size()); |
1737 } | 1791 } |
1738 | 1792 |
1739 TEST_F(BasicPortAllocatorTest, TestClearGettingPorts) { | 1793 TEST_F(BasicPortAllocatorTest, TestClearGettingPorts) { |
1740 AddInterface(kClientAddr); | 1794 AddInterface(kClientAddr); |
1741 allocator_->set_step_delay(kDefaultStepDelay); | 1795 allocator_->set_step_delay(kDefaultStepDelay); |
1742 EXPECT_TRUE(CreateSession(ICE_CANDIDATE_COMPONENT_RTP)); | 1796 EXPECT_TRUE(CreateSession(ICE_CANDIDATE_COMPONENT_RTP)); |
1743 session_->StartGettingPorts(); | 1797 session_->StartGettingPorts(); |
1744 ASSERT_EQ_WAIT(2U, candidates_.size(), 1000); | 1798 ASSERT_EQ_SIMULATED_WAIT(2U, candidates_.size(), 1000, fake_clock); |
1745 EXPECT_EQ(2U, ports_.size()); | 1799 EXPECT_EQ(2U, ports_.size()); |
1746 session_->ClearGettingPorts(); | 1800 session_->ClearGettingPorts(); |
1747 EXPECT_TRUE_WAIT(candidate_allocation_done_, 1000); | 1801 EXPECT_TRUE_SIMULATED_WAIT(candidate_allocation_done_, 1000, fake_clock); |
1748 | 1802 |
1749 // After clearing getting ports, adding a new interface will start getting | 1803 // After clearing getting ports, adding a new interface will start getting |
1750 // ports again. | 1804 // ports again. |
1751 allocator_->set_step_delay(kMinimumStepDelay); | 1805 allocator_->set_step_delay(kMinimumStepDelay); |
1752 candidates_.clear(); | 1806 candidates_.clear(); |
1753 ports_.clear(); | 1807 ports_.clear(); |
1754 candidate_allocation_done_ = false; | 1808 candidate_allocation_done_ = false; |
1755 network_manager_.AddInterface(kClientAddr2); | 1809 network_manager_.AddInterface(kClientAddr2); |
1756 ASSERT_EQ_WAIT(2U, candidates_.size(), 1000); | 1810 ASSERT_EQ_SIMULATED_WAIT(2U, candidates_.size(), 1000, fake_clock); |
1757 EXPECT_EQ(2U, ports_.size()); | 1811 EXPECT_EQ(2U, ports_.size()); |
1758 EXPECT_TRUE_WAIT(candidate_allocation_done_, kDefaultAllocationTimeout); | 1812 EXPECT_TRUE_SIMULATED_WAIT(candidate_allocation_done_, |
1813 kDefaultAllocationTimeout, fake_clock); | |
1759 } | 1814 } |
1760 | 1815 |
1761 // Test that the ports and candidates are updated with new ufrag/pwd/etc. when | 1816 // Test that the ports and candidates are updated with new ufrag/pwd/etc. when |
1762 // a pooled session is taken out of the pool. | 1817 // a pooled session is taken out of the pool. |
1763 TEST_F(BasicPortAllocatorTest, TestTransportInformationUpdated) { | 1818 TEST_F(BasicPortAllocatorTest, TestTransportInformationUpdated) { |
1764 AddInterface(kClientAddr); | 1819 AddInterface(kClientAddr); |
1765 int pool_size = 1; | 1820 int pool_size = 1; |
1766 allocator_->SetConfiguration(allocator_->stun_servers(), | 1821 allocator_->SetConfiguration(allocator_->stun_servers(), |
1767 allocator_->turn_servers(), pool_size, false); | 1822 allocator_->turn_servers(), pool_size, false); |
1768 const PortAllocatorSession* peeked_session = allocator_->GetPooledSession(); | 1823 const PortAllocatorSession* peeked_session = allocator_->GetPooledSession(); |
1769 ASSERT_NE(nullptr, peeked_session); | 1824 ASSERT_NE(nullptr, peeked_session); |
1770 EXPECT_EQ_WAIT(true, peeked_session->CandidatesAllocationDone(), | 1825 EXPECT_EQ_SIMULATED_WAIT(true, peeked_session->CandidatesAllocationDone(), |
1771 kDefaultAllocationTimeout); | 1826 kDefaultAllocationTimeout, fake_clock); |
1772 // Expect that when TakePooledSession is called, | 1827 // Expect that when TakePooledSession is called, |
1773 // UpdateTransportInformationInternal will be called and the | 1828 // UpdateTransportInformationInternal will be called and the |
1774 // BasicPortAllocatorSession will update the ufrag/pwd of ports and | 1829 // BasicPortAllocatorSession will update the ufrag/pwd of ports and |
1775 // candidates. | 1830 // candidates. |
1776 session_ = | 1831 session_ = |
1777 allocator_->TakePooledSession(kContentName, 1, kIceUfrag0, kIcePwd0); | 1832 allocator_->TakePooledSession(kContentName, 1, kIceUfrag0, kIcePwd0); |
1778 ASSERT_NE(nullptr, session_.get()); | 1833 ASSERT_NE(nullptr, session_.get()); |
1779 auto ready_ports = session_->ReadyPorts(); | 1834 auto ready_ports = session_->ReadyPorts(); |
1780 auto candidates = session_->ReadyCandidates(); | 1835 auto candidates = session_->ReadyCandidates(); |
1781 EXPECT_FALSE(ready_ports.empty()); | 1836 EXPECT_FALSE(ready_ports.empty()); |
(...skipping 14 matching lines...) Expand all Loading... | |
1796 | 1851 |
1797 // Test that a new candidate filter takes effect even on already-gathered | 1852 // Test that a new candidate filter takes effect even on already-gathered |
1798 // candidates. | 1853 // candidates. |
1799 TEST_F(BasicPortAllocatorTest, TestSetCandidateFilterAfterCandidatesGathered) { | 1854 TEST_F(BasicPortAllocatorTest, TestSetCandidateFilterAfterCandidatesGathered) { |
1800 AddInterface(kClientAddr); | 1855 AddInterface(kClientAddr); |
1801 int pool_size = 1; | 1856 int pool_size = 1; |
1802 allocator_->SetConfiguration(allocator_->stun_servers(), | 1857 allocator_->SetConfiguration(allocator_->stun_servers(), |
1803 allocator_->turn_servers(), pool_size, false); | 1858 allocator_->turn_servers(), pool_size, false); |
1804 const PortAllocatorSession* peeked_session = allocator_->GetPooledSession(); | 1859 const PortAllocatorSession* peeked_session = allocator_->GetPooledSession(); |
1805 ASSERT_NE(nullptr, peeked_session); | 1860 ASSERT_NE(nullptr, peeked_session); |
1806 EXPECT_EQ_WAIT(true, peeked_session->CandidatesAllocationDone(), | 1861 EXPECT_EQ_SIMULATED_WAIT(true, peeked_session->CandidatesAllocationDone(), |
1807 kDefaultAllocationTimeout); | 1862 kDefaultAllocationTimeout, fake_clock); |
1808 size_t initial_candidates_size = peeked_session->ReadyCandidates().size(); | 1863 size_t initial_candidates_size = peeked_session->ReadyCandidates().size(); |
1809 size_t initial_ports_size = peeked_session->ReadyPorts().size(); | 1864 size_t initial_ports_size = peeked_session->ReadyPorts().size(); |
1810 allocator_->set_candidate_filter(CF_RELAY); | 1865 allocator_->set_candidate_filter(CF_RELAY); |
1811 // Assume that when TakePooledSession is called, the candidate filter will be | 1866 // Assume that when TakePooledSession is called, the candidate filter will be |
1812 // applied to the pooled session. This is tested by PortAllocatorTest. | 1867 // applied to the pooled session. This is tested by PortAllocatorTest. |
1813 session_ = | 1868 session_ = |
1814 allocator_->TakePooledSession(kContentName, 1, kIceUfrag0, kIcePwd0); | 1869 allocator_->TakePooledSession(kContentName, 1, kIceUfrag0, kIcePwd0); |
1815 ASSERT_NE(nullptr, session_.get()); | 1870 ASSERT_NE(nullptr, session_.get()); |
1816 auto candidates = session_->ReadyCandidates(); | 1871 auto candidates = session_->ReadyCandidates(); |
1817 auto ports = session_->ReadyPorts(); | 1872 auto ports = session_->ReadyPorts(); |
1818 // Sanity check that the number of candidates and ports decreased. | 1873 // Sanity check that the number of candidates and ports decreased. |
1819 EXPECT_GT(initial_candidates_size, candidates.size()); | 1874 EXPECT_GT(initial_candidates_size, candidates.size()); |
1820 EXPECT_GT(initial_ports_size, ports.size()); | 1875 EXPECT_GT(initial_ports_size, ports.size()); |
1821 for (const PortInterface* port : ports) { | 1876 for (const PortInterface* port : ports) { |
1822 // Expect only relay ports. | 1877 // Expect only relay ports. |
1823 EXPECT_EQ(RELAY_PORT_TYPE, port->Type()); | 1878 EXPECT_EQ(RELAY_PORT_TYPE, port->Type()); |
1824 } | 1879 } |
1825 for (const Candidate& candidate : candidates) { | 1880 for (const Candidate& candidate : candidates) { |
1826 // Expect only relay candidates now that the filter is applied. | 1881 // Expect only relay candidates now that the filter is applied. |
1827 EXPECT_EQ(std::string(RELAY_PORT_TYPE), candidate.type()); | 1882 EXPECT_EQ(std::string(RELAY_PORT_TYPE), candidate.type()); |
1828 // Expect that the raddr is emptied due to the CF_RELAY filter. | 1883 // Expect that the raddr is emptied due to the CF_RELAY filter. |
1829 EXPECT_EQ(candidate.related_address(), | 1884 EXPECT_EQ(candidate.related_address(), |
1830 rtc::EmptySocketAddressWithFamily(candidate.address().family())); | 1885 rtc::EmptySocketAddressWithFamily(candidate.address().family())); |
1831 } | 1886 } |
1832 } | 1887 } |
1833 | 1888 |
1834 } // namespace cricket | 1889 } // namespace cricket |
OLD | NEW |