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 |
(...skipping 734 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
745 EXPECT_TRUE(CreateSession(ICE_CANDIDATE_COMPONENT_RTP)); | 745 EXPECT_TRUE(CreateSession(ICE_CANDIDATE_COMPONENT_RTP)); |
746 session_->set_flags(PORTALLOCATOR_DISABLE_STUN | PORTALLOCATOR_DISABLE_RELAY | | 746 session_->set_flags(PORTALLOCATOR_DISABLE_STUN | PORTALLOCATOR_DISABLE_RELAY | |
747 PORTALLOCATOR_DISABLE_TCP); | 747 PORTALLOCATOR_DISABLE_TCP); |
748 session_->StartGettingPorts(); | 748 session_->StartGettingPorts(); |
749 EXPECT_TRUE_SIMULATED_WAIT(candidate_allocation_done_, | 749 EXPECT_TRUE_SIMULATED_WAIT(candidate_allocation_done_, |
750 kDefaultAllocationTimeout, fake_clock); | 750 kDefaultAllocationTimeout, fake_clock); |
751 EXPECT_EQ(1U, candidates_.size()); | 751 EXPECT_EQ(1U, candidates_.size()); |
752 EXPECT_EQ(0x12345602U, candidates_[0].address().ip()); | 752 EXPECT_EQ(0x12345602U, candidates_[0].address().ip()); |
753 } | 753 } |
754 | 754 |
755 // Test that high cost networks are filtered if the flag | 755 // Test that when the PORTALLOCATOR_DISABLE_COSTLY_NETWORKS flag is set and |
756 // PORTALLOCATOR_DISABLE_COSTLY_NETWORKS is set. | 756 // both Wi-Fi and cell interfaces are available, only Wi-Fi is used. |
757 TEST_F(BasicPortAllocatorTest, TestGatherLowCostNetworkOnly) { | 757 TEST_F(BasicPortAllocatorTest, |
758 SocketAddress addr_wifi(IPAddress(0x12345600U), 0); | 758 WifiUsedInsteadOfCellWhenCostlyNetworksDisabled) { |
759 SocketAddress addr_cellular(IPAddress(0x12345601U), 0); | 759 SocketAddress wifi(IPAddress(0x12345600U), 0); |
760 SocketAddress addr_unknown1(IPAddress(0x12345602U), 0); | 760 SocketAddress cell(IPAddress(0x12345601U), 0); |
761 SocketAddress addr_unknown2(IPAddress(0x12345603U), 0); | 761 AddInterface(wifi, "test_wlan0", rtc::ADAPTER_TYPE_WIFI); |
762 // If both Wi-Fi and cellular interfaces are present, only gather on the Wi-Fi | 762 AddInterface(cell, "test_cell0", rtc::ADAPTER_TYPE_CELLULAR); |
763 // interface. | 763 // Disable all but UDP candidates to make the test simpler. |
764 AddInterface(addr_wifi, "test_wlan0", rtc::ADAPTER_TYPE_WIFI); | |
765 AddInterface(addr_cellular, "test_cell0", rtc::ADAPTER_TYPE_CELLULAR); | |
766 allocator().set_flags(cricket::PORTALLOCATOR_DISABLE_STUN | | 764 allocator().set_flags(cricket::PORTALLOCATOR_DISABLE_STUN | |
767 cricket::PORTALLOCATOR_DISABLE_RELAY | | 765 cricket::PORTALLOCATOR_DISABLE_RELAY | |
768 cricket::PORTALLOCATOR_DISABLE_TCP | | 766 cricket::PORTALLOCATOR_DISABLE_TCP | |
769 cricket::PORTALLOCATOR_DISABLE_COSTLY_NETWORKS); | 767 cricket::PORTALLOCATOR_DISABLE_COSTLY_NETWORKS); |
770 EXPECT_TRUE(CreateSession(cricket::ICE_CANDIDATE_COMPONENT_RTP)); | 768 EXPECT_TRUE(CreateSession(cricket::ICE_CANDIDATE_COMPONENT_RTP)); |
771 session_->StartGettingPorts(); | 769 session_->StartGettingPorts(); |
772 EXPECT_TRUE_SIMULATED_WAIT(candidate_allocation_done_, | 770 EXPECT_TRUE_SIMULATED_WAIT(candidate_allocation_done_, |
773 kDefaultAllocationTimeout, fake_clock); | 771 kDefaultAllocationTimeout, fake_clock); |
| 772 // Should only get one Wi-Fi candidate. |
774 EXPECT_EQ(1U, candidates_.size()); | 773 EXPECT_EQ(1U, candidates_.size()); |
775 EXPECT_TRUE(addr_wifi.EqualIPs(candidates_[0].address())); | 774 EXPECT_PRED4(HasCandidate, candidates_, "local", "udp", wifi); |
| 775 } |
776 | 776 |
777 // If both cellular and unknown interfaces are present, only gather on the | 777 // Test that when the PORTALLOCATOR_DISABLE_COSTLY_NETWORKS flag is set and |
778 // unknown interfaces. | 778 // both "unknown" and cell interfaces are available, only the unknown are used. |
779 candidates_.clear(); | 779 // The unknown interface may be something that ultimately uses Wi-Fi, so we do |
780 candidate_allocation_done_ = false; | 780 // this to be on the safe side. |
781 RemoveInterface(addr_wifi); | 781 TEST_F(BasicPortAllocatorTest, |
782 AddInterface(addr_unknown1, "test_unknown0", rtc::ADAPTER_TYPE_UNKNOWN); | 782 UnknownInterfaceUsedInsteadOfCellWhenCostlyNetworksDisabled) { |
783 AddInterface(addr_unknown2, "test_unknown1", rtc::ADAPTER_TYPE_UNKNOWN); | 783 SocketAddress cell(IPAddress(0x12345601U), 0); |
| 784 SocketAddress unknown1(IPAddress(0x12345602U), 0); |
| 785 SocketAddress unknown2(IPAddress(0x12345603U), 0); |
| 786 AddInterface(cell, "test_cell0", rtc::ADAPTER_TYPE_CELLULAR); |
| 787 AddInterface(unknown1, "test_unknown0", rtc::ADAPTER_TYPE_UNKNOWN); |
| 788 AddInterface(unknown2, "test_unknown1", rtc::ADAPTER_TYPE_UNKNOWN); |
| 789 // Disable all but UDP candidates to make the test simpler. |
| 790 allocator().set_flags(cricket::PORTALLOCATOR_DISABLE_STUN | |
| 791 cricket::PORTALLOCATOR_DISABLE_RELAY | |
| 792 cricket::PORTALLOCATOR_DISABLE_TCP | |
| 793 cricket::PORTALLOCATOR_DISABLE_COSTLY_NETWORKS); |
| 794 EXPECT_TRUE(CreateSession(cricket::ICE_CANDIDATE_COMPONENT_RTP)); |
784 session_->StartGettingPorts(); | 795 session_->StartGettingPorts(); |
785 EXPECT_TRUE_SIMULATED_WAIT(candidate_allocation_done_, | 796 EXPECT_TRUE_SIMULATED_WAIT(candidate_allocation_done_, |
786 kDefaultAllocationTimeout, fake_clock); | 797 kDefaultAllocationTimeout, fake_clock); |
| 798 // Should only get two candidates, none of which is cell. |
787 EXPECT_EQ(2U, candidates_.size()); | 799 EXPECT_EQ(2U, candidates_.size()); |
788 EXPECT_TRUE((addr_unknown1.EqualIPs(candidates_[0].address()) && | 800 EXPECT_PRED4(HasCandidate, candidates_, "local", "udp", unknown1); |
789 addr_unknown2.EqualIPs(candidates_[1].address())) || | 801 EXPECT_PRED4(HasCandidate, candidates_, "local", "udp", unknown2); |
790 (addr_unknown1.EqualIPs(candidates_[1].address()) && | 802 } |
791 addr_unknown2.EqualIPs(candidates_[0].address()))); | |
792 | 803 |
793 // If Wi-Fi, cellular, unknown interfaces are all present, only gather on the | 804 // Test that when the PORTALLOCATOR_DISABLE_COSTLY_NETWORKS flag is set and |
794 // Wi-Fi interface. | 805 // there are a mix of Wi-Fi, "unknown" and cell interfaces, only the Wi-Fi |
795 candidates_.clear(); | 806 // interface is used. |
796 candidate_allocation_done_ = false; | 807 TEST_F(BasicPortAllocatorTest, |
797 AddInterface(addr_wifi, "test_wlan0", rtc::ADAPTER_TYPE_WIFI); | 808 WifiUsedInsteadOfUnknownOrCellWhenCostlyNetworksDisabled) { |
| 809 SocketAddress wifi(IPAddress(0x12345600U), 0); |
| 810 SocketAddress cellular(IPAddress(0x12345601U), 0); |
| 811 SocketAddress unknown1(IPAddress(0x12345602U), 0); |
| 812 SocketAddress unknown2(IPAddress(0x12345603U), 0); |
| 813 AddInterface(wifi, "test_wlan0", rtc::ADAPTER_TYPE_WIFI); |
| 814 AddInterface(cellular, "test_cell0", rtc::ADAPTER_TYPE_CELLULAR); |
| 815 AddInterface(unknown1, "test_unknown0", rtc::ADAPTER_TYPE_UNKNOWN); |
| 816 AddInterface(unknown2, "test_unknown1", rtc::ADAPTER_TYPE_UNKNOWN); |
| 817 // Disable all but UDP candidates to make the test simpler. |
| 818 allocator().set_flags(cricket::PORTALLOCATOR_DISABLE_STUN | |
| 819 cricket::PORTALLOCATOR_DISABLE_RELAY | |
| 820 cricket::PORTALLOCATOR_DISABLE_TCP | |
| 821 cricket::PORTALLOCATOR_DISABLE_COSTLY_NETWORKS); |
| 822 EXPECT_TRUE(CreateSession(cricket::ICE_CANDIDATE_COMPONENT_RTP)); |
798 session_->StartGettingPorts(); | 823 session_->StartGettingPorts(); |
799 EXPECT_TRUE_SIMULATED_WAIT(candidate_allocation_done_, | 824 EXPECT_TRUE_SIMULATED_WAIT(candidate_allocation_done_, |
800 kDefaultAllocationTimeout, fake_clock); | 825 kDefaultAllocationTimeout, fake_clock); |
| 826 // Should only get one Wi-Fi candidate. |
801 EXPECT_EQ(1U, candidates_.size()); | 827 EXPECT_EQ(1U, candidates_.size()); |
802 EXPECT_TRUE(addr_wifi.EqualIPs(candidates_[0].address())); | 828 EXPECT_PRED4(HasCandidate, candidates_, "local", "udp", wifi); |
| 829 } |
| 830 |
| 831 // Test that if the PORTALLOCATOR_DISABLE_COSTLY_NETWORKS flag is set, but the |
| 832 // only interface available is cellular, it ends up used anyway. A costly |
| 833 // connection is always better than no connection. |
| 834 TEST_F(BasicPortAllocatorTest, |
| 835 CellUsedWhenCostlyNetworksDisabledButThereAreNoOtherInterfaces) { |
| 836 SocketAddress cellular(IPAddress(0x12345601U), 0); |
| 837 AddInterface(cellular, "test_cell0", rtc::ADAPTER_TYPE_CELLULAR); |
| 838 // Disable all but UDP candidates to make the test simpler. |
| 839 allocator().set_flags(cricket::PORTALLOCATOR_DISABLE_STUN | |
| 840 cricket::PORTALLOCATOR_DISABLE_RELAY | |
| 841 cricket::PORTALLOCATOR_DISABLE_TCP | |
| 842 cricket::PORTALLOCATOR_DISABLE_COSTLY_NETWORKS); |
| 843 EXPECT_TRUE(CreateSession(cricket::ICE_CANDIDATE_COMPONENT_RTP)); |
| 844 session_->StartGettingPorts(); |
| 845 EXPECT_TRUE_SIMULATED_WAIT(candidate_allocation_done_, |
| 846 kDefaultAllocationTimeout, fake_clock); |
| 847 // Make sure we got the cell candidate. |
| 848 EXPECT_EQ(1U, candidates_.size()); |
| 849 EXPECT_PRED4(HasCandidate, candidates_, "local", "udp", cellular); |
803 } | 850 } |
804 | 851 |
805 // Test that no more than allocator.max_ipv6_networks() IPv6 networks are used | 852 // Test that no more than allocator.max_ipv6_networks() IPv6 networks are used |
806 // to gather candidates. | 853 // to gather candidates. |
807 TEST_F(BasicPortAllocatorTest, MaxIpv6NetworksLimitEnforced) { | 854 TEST_F(BasicPortAllocatorTest, MaxIpv6NetworksLimitEnforced) { |
808 // Add three IPv6 network interfaces, but tell the allocator to only use two. | 855 // Add three IPv6 network interfaces, but tell the allocator to only use two. |
809 allocator().set_max_ipv6_networks(2); | 856 allocator().set_max_ipv6_networks(2); |
810 AddInterface(kClientIPv6Addr, "eth0", rtc::ADAPTER_TYPE_ETHERNET); | 857 AddInterface(kClientIPv6Addr, "eth0", rtc::ADAPTER_TYPE_ETHERNET); |
811 AddInterface(kClientIPv6Addr2, "eth1", rtc::ADAPTER_TYPE_ETHERNET); | 858 AddInterface(kClientIPv6Addr2, "eth1", rtc::ADAPTER_TYPE_ETHERNET); |
812 AddInterface(kClientIPv6Addr3, "eth2", rtc::ADAPTER_TYPE_ETHERNET); | 859 AddInterface(kClientIPv6Addr3, "eth2", rtc::ADAPTER_TYPE_ETHERNET); |
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
946 EXPECT_EQ(0U, ports_.size()); | 993 EXPECT_EQ(0U, ports_.size()); |
947 | 994 |
948 // When the same interfaces are added again, new candidates/ports should not | 995 // When the same interfaces are added again, new candidates/ports should not |
949 // be generated because the session has stopped. | 996 // be generated because the session has stopped. |
950 AddInterface(kClientAddr, if_name); | 997 AddInterface(kClientAddr, if_name); |
951 SIMULATED_WAIT(false, 1000, fake_clock); | 998 SIMULATED_WAIT(false, 1000, fake_clock); |
952 EXPECT_EQ(0U, candidates_.size()); | 999 EXPECT_EQ(0U, candidates_.size()); |
953 EXPECT_EQ(0U, ports_.size()); | 1000 EXPECT_EQ(0U, ports_.size()); |
954 } | 1001 } |
955 | 1002 |
| 1003 // Similar to the above tests, but tests a situation when sockets can't be |
| 1004 // bound to a network interface, then after a network change event can be. |
| 1005 // Related bug: https://bugs.chromium.org/p/webrtc/issues/detail?id=8256 |
| 1006 TEST_F(BasicPortAllocatorTest, CandidatesRegatheredAfterBindingFails) { |
| 1007 // Only test local ports to simplify test. |
| 1008 ResetWithNoServersOrNat(); |
| 1009 // Provide a situation where the interface appears to be available, but |
| 1010 // binding the sockets fails. See bug for description of when this can |
| 1011 // happen. |
| 1012 std::string if_name("test_net0"); |
| 1013 AddInterface(kClientAddr, if_name); |
| 1014 fss_->set_tcp_sockets_enabled(false); |
| 1015 fss_->set_udp_sockets_enabled(false); |
| 1016 EXPECT_TRUE(CreateSession(ICE_CANDIDATE_COMPONENT_RTP)); |
| 1017 session_->StartGettingPorts(); |
| 1018 ASSERT_TRUE_SIMULATED_WAIT(candidate_allocation_done_, |
| 1019 kDefaultAllocationTimeout, fake_clock); |
| 1020 // Make sure we actually prevented candidates from being gathered (other than |
| 1021 // a single TCP active candidate, since that doesn't require creating a |
| 1022 // socket). |
| 1023 ASSERT_EQ(1U, candidates_.size()); |
| 1024 EXPECT_PRED4(HasCandidate, candidates_, "local", "tcp", kClientAddr); |
| 1025 candidate_allocation_done_ = false; |
| 1026 |
| 1027 // Now simulate the interface coming up, with the newfound ability to bind |
| 1028 // sockets. |
| 1029 fss_->set_tcp_sockets_enabled(true); |
| 1030 fss_->set_udp_sockets_enabled(true); |
| 1031 AddInterface(kClientAddr, if_name); |
| 1032 ASSERT_TRUE_SIMULATED_WAIT(candidate_allocation_done_, |
| 1033 kDefaultAllocationTimeout, fake_clock); |
| 1034 // Should get UDP and TCP candidate. |
| 1035 ASSERT_EQ(2U, candidates_.size()); |
| 1036 EXPECT_PRED4(HasCandidate, candidates_, "local", "udp", kClientAddr); |
| 1037 // TODO(deadbeef): This is actually the same active TCP candidate as before. |
| 1038 // We should extend this test to also verify that a server candidate is |
| 1039 // gathered. |
| 1040 EXPECT_PRED4(HasCandidate, candidates_, "local", "tcp", kClientAddr); |
| 1041 } |
| 1042 |
956 // Verify candidates with default step delay of 1sec. | 1043 // Verify candidates with default step delay of 1sec. |
957 TEST_F(BasicPortAllocatorTest, TestGetAllPortsWithOneSecondStepDelay) { | 1044 TEST_F(BasicPortAllocatorTest, TestGetAllPortsWithOneSecondStepDelay) { |
958 AddInterface(kClientAddr); | 1045 AddInterface(kClientAddr); |
959 allocator_->set_step_delay(kDefaultStepDelay); | 1046 allocator_->set_step_delay(kDefaultStepDelay); |
960 EXPECT_TRUE(CreateSession(ICE_CANDIDATE_COMPONENT_RTP)); | 1047 EXPECT_TRUE(CreateSession(ICE_CANDIDATE_COMPONENT_RTP)); |
961 session_->StartGettingPorts(); | 1048 session_->StartGettingPorts(); |
962 ASSERT_EQ_SIMULATED_WAIT(2U, candidates_.size(), 1000, fake_clock); | 1049 ASSERT_EQ_SIMULATED_WAIT(2U, candidates_.size(), 1000, fake_clock); |
963 EXPECT_EQ(2U, ports_.size()); | 1050 EXPECT_EQ(2U, ports_.size()); |
964 ASSERT_EQ_SIMULATED_WAIT(6U, candidates_.size(), 2000, fake_clock); | 1051 ASSERT_EQ_SIMULATED_WAIT(6U, candidates_.size(), 2000, fake_clock); |
965 EXPECT_EQ(3U, ports_.size()); | 1052 EXPECT_EQ(3U, ports_.size()); |
(...skipping 990 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1956 for (const Candidate& candidate : candidates) { | 2043 for (const Candidate& candidate : candidates) { |
1957 // Expect only relay candidates now that the filter is applied. | 2044 // Expect only relay candidates now that the filter is applied. |
1958 EXPECT_EQ(std::string(RELAY_PORT_TYPE), candidate.type()); | 2045 EXPECT_EQ(std::string(RELAY_PORT_TYPE), candidate.type()); |
1959 // Expect that the raddr is emptied due to the CF_RELAY filter. | 2046 // Expect that the raddr is emptied due to the CF_RELAY filter. |
1960 EXPECT_EQ(candidate.related_address(), | 2047 EXPECT_EQ(candidate.related_address(), |
1961 rtc::EmptySocketAddressWithFamily(candidate.address().family())); | 2048 rtc::EmptySocketAddressWithFamily(candidate.address().family())); |
1962 } | 2049 } |
1963 } | 2050 } |
1964 | 2051 |
1965 } // namespace cricket | 2052 } // namespace cricket |
OLD | NEW |