| 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 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 98 static const char* kIcePwd[4] = {"TESTICEPWD00000000000000", | 98 static const char* kIcePwd[4] = {"TESTICEPWD00000000000000", |
| 99 "TESTICEPWD00000000000001", | 99 "TESTICEPWD00000000000001", |
| 100 "TESTICEPWD00000000000002", | 100 "TESTICEPWD00000000000002", |
| 101 "TESTICEPWD00000000000003"}; | 101 "TESTICEPWD00000000000003"}; |
| 102 | 102 |
| 103 static const uint64_t kLowTiebreaker = 11111; | 103 static const uint64_t kLowTiebreaker = 11111; |
| 104 static const uint64_t kHighTiebreaker = 22222; | 104 static const uint64_t kHighTiebreaker = 22222; |
| 105 | 105 |
| 106 enum { MSG_ADD_CANDIDATES, MSG_REMOVE_CANDIDATES }; | 106 enum { MSG_ADD_CANDIDATES, MSG_REMOVE_CANDIDATES }; |
| 107 | 107 |
| 108 cricket::IceConfig CreateIceConfig(int receiving_timeout, | 108 cricket::IceConfig CreateIceConfig( |
| 109 bool gather_continually, | 109 int receiving_timeout, |
| 110 int backup_ping_interval = -1) { | 110 cricket::ContinualGatheringPolicy continual_gathering_policy, |
| 111 int backup_ping_interval = -1) { |
| 111 cricket::IceConfig config; | 112 cricket::IceConfig config; |
| 112 config.receiving_timeout = receiving_timeout; | 113 config.receiving_timeout = receiving_timeout; |
| 113 config.gather_continually = gather_continually; | 114 config.continual_gathering_policy = continual_gathering_policy; |
| 114 config.backup_connection_ping_interval = backup_ping_interval; | 115 config.backup_connection_ping_interval = backup_ping_interval; |
| 115 return config; | 116 return config; |
| 116 } | 117 } |
| 117 | 118 |
| 118 cricket::Candidate CreateUdpCandidate(const std::string& type, | 119 cricket::Candidate CreateUdpCandidate(const std::string& type, |
| 119 const std::string& ip, | 120 const std::string& ip, |
| 120 int port, | 121 int port, |
| 121 int priority, | 122 int priority, |
| 122 const std::string& ufrag = "") { | 123 const std::string& ufrag = "") { |
| 123 cricket::Candidate c; | 124 cricket::Candidate c; |
| (...skipping 281 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 405 } | 406 } |
| 406 void AddAddress(int endpoint, | 407 void AddAddress(int endpoint, |
| 407 const SocketAddress& addr, | 408 const SocketAddress& addr, |
| 408 const std::string& ifname, | 409 const std::string& ifname, |
| 409 rtc::AdapterType adapter_type) { | 410 rtc::AdapterType adapter_type) { |
| 410 GetEndpoint(endpoint)->network_manager_.AddInterface(addr, ifname, | 411 GetEndpoint(endpoint)->network_manager_.AddInterface(addr, ifname, |
| 411 adapter_type); | 412 adapter_type); |
| 412 } | 413 } |
| 413 void RemoveAddress(int endpoint, const SocketAddress& addr) { | 414 void RemoveAddress(int endpoint, const SocketAddress& addr) { |
| 414 GetEndpoint(endpoint)->network_manager_.RemoveInterface(addr); | 415 GetEndpoint(endpoint)->network_manager_.RemoveInterface(addr); |
| 416 fw()->AddRule(false, rtc::FP_ANY, rtc::FD_ANY, addr); |
| 415 } | 417 } |
| 416 void SetProxy(int endpoint, rtc::ProxyType type) { | 418 void SetProxy(int endpoint, rtc::ProxyType type) { |
| 417 rtc::ProxyInfo info; | 419 rtc::ProxyInfo info; |
| 418 info.type = type; | 420 info.type = type; |
| 419 info.address = (type == rtc::PROXY_HTTPS) ? | 421 info.address = (type == rtc::PROXY_HTTPS) ? |
| 420 kHttpsProxyAddrs[endpoint] : kSocksProxyAddrs[endpoint]; | 422 kHttpsProxyAddrs[endpoint] : kSocksProxyAddrs[endpoint]; |
| 421 GetAllocator(endpoint)->set_proxy("unittest/1.0", info); | 423 GetAllocator(endpoint)->set_proxy("unittest/1.0", info); |
| 422 } | 424 } |
| 423 void SetAllocatorFlags(int endpoint, int flags) { | 425 void SetAllocatorFlags(int endpoint, int flags) { |
| 424 GetAllocator(endpoint)->set_flags(flags); | 426 GetAllocator(endpoint)->set_flags(flags); |
| (...skipping 1111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1536 } | 1538 } |
| 1537 | 1539 |
| 1538 // Test that if continual gathering is set to true, ICE gathering state will | 1540 // Test that if continual gathering is set to true, ICE gathering state will |
| 1539 // not change to "Complete", and vice versa. | 1541 // not change to "Complete", and vice versa. |
| 1540 TEST_F(P2PTransportChannelTest, TestContinualGathering) { | 1542 TEST_F(P2PTransportChannelTest, TestContinualGathering) { |
| 1541 ConfigureEndpoints(OPEN, OPEN, kDefaultPortAllocatorFlags, | 1543 ConfigureEndpoints(OPEN, OPEN, kDefaultPortAllocatorFlags, |
| 1542 kDefaultPortAllocatorFlags); | 1544 kDefaultPortAllocatorFlags); |
| 1543 SetAllocationStepDelay(0, kDefaultStepDelay); | 1545 SetAllocationStepDelay(0, kDefaultStepDelay); |
| 1544 SetAllocationStepDelay(1, kDefaultStepDelay); | 1546 SetAllocationStepDelay(1, kDefaultStepDelay); |
| 1545 CreateChannels(1); | 1547 CreateChannels(1); |
| 1546 IceConfig config = CreateIceConfig(1000, true); | 1548 IceConfig config = CreateIceConfig(1000, GATHER_CONTINUALLY); |
| 1547 ep1_ch1()->SetIceConfig(config); | 1549 ep1_ch1()->SetIceConfig(config); |
| 1548 // By default, ep2 does not gather continually. | 1550 // By default, ep2 does not gather continually. |
| 1549 | 1551 |
| 1550 EXPECT_TRUE_WAIT_MARGIN(ep1_ch1() != NULL && ep2_ch1() != NULL && | 1552 EXPECT_TRUE_WAIT_MARGIN(ep1_ch1() != NULL && ep2_ch1() != NULL && |
| 1551 ep1_ch1()->receiving() && ep1_ch1()->writable() && | 1553 ep1_ch1()->receiving() && ep1_ch1()->writable() && |
| 1552 ep2_ch1()->receiving() && ep2_ch1()->writable(), | 1554 ep2_ch1()->receiving() && ep2_ch1()->writable(), |
| 1553 1000, 1000); | 1555 1000, 1000); |
| 1554 WAIT(IceGatheringState::kIceGatheringComplete == ep1_ch1()->gathering_state(), | 1556 WAIT(IceGatheringState::kIceGatheringComplete == ep1_ch1()->gathering_state(), |
| 1555 1000); | 1557 1000); |
| 1556 EXPECT_EQ(IceGatheringState::kIceGatheringGathering, | 1558 EXPECT_EQ(IceGatheringState::kIceGatheringGathering, |
| (...skipping 256 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1813 TEST_F(P2PTransportChannelSameNatTest, TestConesBehindSameCone) { | 1815 TEST_F(P2PTransportChannelSameNatTest, TestConesBehindSameCone) { |
| 1814 ConfigureEndpoints(NAT_FULL_CONE, NAT_FULL_CONE, NAT_FULL_CONE); | 1816 ConfigureEndpoints(NAT_FULL_CONE, NAT_FULL_CONE, NAT_FULL_CONE); |
| 1815 Test(P2PTransportChannelTestBase::Result( | 1817 Test(P2PTransportChannelTestBase::Result( |
| 1816 "prflx", "udp", "stun", "udp", "stun", "udp", "prflx", "udp", 1000)); | 1818 "prflx", "udp", "stun", "udp", "stun", "udp", "prflx", "udp", 1000)); |
| 1817 } | 1819 } |
| 1818 | 1820 |
| 1819 // Test what happens when we have multiple available pathways. | 1821 // Test what happens when we have multiple available pathways. |
| 1820 // In the future we will try different RTTs and configs for the different | 1822 // In the future we will try different RTTs and configs for the different |
| 1821 // interfaces, so that we can simulate a user with Ethernet and VPN networks. | 1823 // interfaces, so that we can simulate a user with Ethernet and VPN networks. |
| 1822 class P2PTransportChannelMultihomedTest : public P2PTransportChannelTestBase { | 1824 class P2PTransportChannelMultihomedTest : public P2PTransportChannelTestBase { |
| 1825 public: |
| 1826 const cricket::Connection* GetConnectionWithRemoteAddress( |
| 1827 cricket::P2PTransportChannel* channel, |
| 1828 const SocketAddress& address) { |
| 1829 for (cricket::Connection* conn : channel->connections()) { |
| 1830 if (conn->remote_candidate().address().EqualIPs(address)) { |
| 1831 return conn; |
| 1832 } |
| 1833 } |
| 1834 return nullptr; |
| 1835 } |
| 1836 |
| 1837 const cricket::Connection* GetConnectionWithLocalAddress( |
| 1838 cricket::P2PTransportChannel* channel, |
| 1839 const SocketAddress& address) { |
| 1840 for (cricket::Connection* conn : channel->connections()) { |
| 1841 if (conn->local_candidate().address().EqualIPs(address)) { |
| 1842 return conn; |
| 1843 } |
| 1844 } |
| 1845 return nullptr; |
| 1846 } |
| 1847 |
| 1848 void DestroyAllButBestConnection(cricket::P2PTransportChannel* channel) { |
| 1849 const cricket::Connection* best_connection = channel->best_connection(); |
| 1850 for (cricket::Connection* conn : channel->connections()) { |
| 1851 if (conn != best_connection) { |
| 1852 conn->Destroy(); |
| 1853 } |
| 1854 } |
| 1855 } |
| 1823 }; | 1856 }; |
| 1824 | 1857 |
| 1825 // Test that we can establish connectivity when both peers are multihomed. | 1858 // Test that we can establish connectivity when both peers are multihomed. |
| 1826 TEST_F(P2PTransportChannelMultihomedTest, DISABLED_TestBasic) { | 1859 TEST_F(P2PTransportChannelMultihomedTest, DISABLED_TestBasic) { |
| 1827 AddAddress(0, kPublicAddrs[0]); | 1860 AddAddress(0, kPublicAddrs[0]); |
| 1828 AddAddress(0, kAlternateAddrs[0]); | 1861 AddAddress(0, kAlternateAddrs[0]); |
| 1829 AddAddress(1, kPublicAddrs[1]); | 1862 AddAddress(1, kPublicAddrs[1]); |
| 1830 AddAddress(1, kAlternateAddrs[1]); | 1863 AddAddress(1, kAlternateAddrs[1]); |
| 1831 Test(kLocalUdpToLocalUdp); | 1864 Test(kLocalUdpToLocalUdp); |
| 1832 } | 1865 } |
| (...skipping 16 matching lines...) Expand all Loading... |
| 1849 | 1882 |
| 1850 EXPECT_TRUE_WAIT_MARGIN(ep1_ch1()->receiving() && ep1_ch1()->writable() && | 1883 EXPECT_TRUE_WAIT_MARGIN(ep1_ch1()->receiving() && ep1_ch1()->writable() && |
| 1851 ep2_ch1()->receiving() && ep2_ch1()->writable(), | 1884 ep2_ch1()->receiving() && ep2_ch1()->writable(), |
| 1852 1000, 1000); | 1885 1000, 1000); |
| 1853 EXPECT_TRUE(ep1_ch1()->selected_connection() && | 1886 EXPECT_TRUE(ep1_ch1()->selected_connection() && |
| 1854 ep2_ch1()->selected_connection() && | 1887 ep2_ch1()->selected_connection() && |
| 1855 LocalCandidate(ep1_ch1())->address().EqualIPs(kPublicAddrs[0]) && | 1888 LocalCandidate(ep1_ch1())->address().EqualIPs(kPublicAddrs[0]) && |
| 1856 RemoteCandidate(ep1_ch1())->address().EqualIPs(kPublicAddrs[1])); | 1889 RemoteCandidate(ep1_ch1())->address().EqualIPs(kPublicAddrs[1])); |
| 1857 | 1890 |
| 1858 // Make the receiving timeout shorter for testing. | 1891 // Make the receiving timeout shorter for testing. |
| 1859 IceConfig config = CreateIceConfig(1000, false); | 1892 IceConfig config = CreateIceConfig(1000, GATHER_ONCE); |
| 1860 ep1_ch1()->SetIceConfig(config); | 1893 ep1_ch1()->SetIceConfig(config); |
| 1861 ep2_ch1()->SetIceConfig(config); | 1894 ep2_ch1()->SetIceConfig(config); |
| 1862 | 1895 |
| 1863 // Blackhole any traffic to or from the public addrs. | 1896 // Blackhole any traffic to or from the public addrs. |
| 1864 LOG(LS_INFO) << "Failing over..."; | 1897 LOG(LS_INFO) << "Failing over..."; |
| 1865 fw()->AddRule(false, rtc::FP_ANY, rtc::FD_ANY, kPublicAddrs[1]); | 1898 fw()->AddRule(false, rtc::FP_ANY, rtc::FD_ANY, kPublicAddrs[1]); |
| 1866 // The selected connections will switch, so keep references to them. | 1899 // The selected connections will switch, so keep references to them. |
| 1867 const Connection* selected_connection1 = ep1_ch1()->selected_connection(); | 1900 const Connection* selected_connection1 = ep1_ch1()->selected_connection(); |
| 1868 const Connection* selected_connection2 = ep2_ch1()->selected_connection(); | 1901 const Connection* selected_connection2 = ep2_ch1()->selected_connection(); |
| 1869 // We should detect loss of receiving within 1 second or so. | 1902 // We should detect loss of receiving within 1 second or so. |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1902 CreateChannels(1); | 1935 CreateChannels(1); |
| 1903 EXPECT_TRUE_WAIT_MARGIN(ep1_ch1()->receiving() && ep1_ch1()->writable() && | 1936 EXPECT_TRUE_WAIT_MARGIN(ep1_ch1()->receiving() && ep1_ch1()->writable() && |
| 1904 ep2_ch1()->receiving() && ep2_ch1()->writable(), | 1937 ep2_ch1()->receiving() && ep2_ch1()->writable(), |
| 1905 1000, 1000); | 1938 1000, 1000); |
| 1906 EXPECT_TRUE(ep1_ch1()->selected_connection() && | 1939 EXPECT_TRUE(ep1_ch1()->selected_connection() && |
| 1907 ep2_ch1()->selected_connection() && | 1940 ep2_ch1()->selected_connection() && |
| 1908 LocalCandidate(ep1_ch1())->address().EqualIPs(kPublicAddrs[0]) && | 1941 LocalCandidate(ep1_ch1())->address().EqualIPs(kPublicAddrs[0]) && |
| 1909 RemoteCandidate(ep1_ch1())->address().EqualIPs(kPublicAddrs[1])); | 1942 RemoteCandidate(ep1_ch1())->address().EqualIPs(kPublicAddrs[1])); |
| 1910 | 1943 |
| 1911 // Make the receiving timeout shorter for testing. | 1944 // Make the receiving timeout shorter for testing. |
| 1912 IceConfig config = CreateIceConfig(1000, false); | 1945 IceConfig config = CreateIceConfig(1000, GATHER_ONCE); |
| 1913 ep1_ch1()->SetIceConfig(config); | 1946 ep1_ch1()->SetIceConfig(config); |
| 1914 ep2_ch1()->SetIceConfig(config); | 1947 ep2_ch1()->SetIceConfig(config); |
| 1915 | 1948 |
| 1916 // Blackhole any traffic to or from the public addrs. | 1949 // Blackhole any traffic to or from the public addrs. |
| 1917 LOG(LS_INFO) << "Failing over..."; | 1950 LOG(LS_INFO) << "Failing over..."; |
| 1918 fw()->AddRule(false, rtc::FP_ANY, rtc::FD_ANY, kPublicAddrs[0]); | 1951 fw()->AddRule(false, rtc::FP_ANY, rtc::FD_ANY, kPublicAddrs[0]); |
| 1919 // The selected connections will switch, so keep references to them. | 1952 // The selected connections will switch, so keep references to them. |
| 1920 const Connection* selected_connection1 = ep1_ch1()->selected_connection(); | 1953 const Connection* selected_connection1 = ep1_ch1()->selected_connection(); |
| 1921 const Connection* selected_connection2 = ep2_ch1()->selected_connection(); | 1954 const Connection* selected_connection2 = ep2_ch1()->selected_connection(); |
| 1922 // We should detect loss of receiving within 1 second or so. | 1955 // We should detect loss of receiving within 1 second or so. |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1961 1000, 1000); | 1994 1000, 1000); |
| 1962 // Need to wait to make sure the connections on both networks are writable. | 1995 // Need to wait to make sure the connections on both networks are writable. |
| 1963 EXPECT_TRUE_WAIT(ep1_ch1()->selected_connection() && | 1996 EXPECT_TRUE_WAIT(ep1_ch1()->selected_connection() && |
| 1964 LocalCandidate(ep1_ch1())->address().EqualIPs(wifi[0]) && | 1997 LocalCandidate(ep1_ch1())->address().EqualIPs(wifi[0]) && |
| 1965 RemoteCandidate(ep1_ch1())->address().EqualIPs(wifi[1]), | 1998 RemoteCandidate(ep1_ch1())->address().EqualIPs(wifi[1]), |
| 1966 1000); | 1999 1000); |
| 1967 EXPECT_TRUE_WAIT(ep2_ch1()->selected_connection() && | 2000 EXPECT_TRUE_WAIT(ep2_ch1()->selected_connection() && |
| 1968 LocalCandidate(ep2_ch1())->address().EqualIPs(wifi[1]) && | 2001 LocalCandidate(ep2_ch1())->address().EqualIPs(wifi[1]) && |
| 1969 RemoteCandidate(ep2_ch1())->address().EqualIPs(wifi[0]), | 2002 RemoteCandidate(ep2_ch1())->address().EqualIPs(wifi[0]), |
| 1970 1000); | 2003 1000); |
| 2004 DestroyChannels(); |
| 1971 } | 2005 } |
| 1972 | 2006 |
| 1973 // Tests that a Wifi-Cellular connection has higher precedence than | 2007 // Tests that a Wifi-Cellular connection has higher precedence than |
| 1974 // a Cellular-Cellular connection. | 2008 // a Cellular-Cellular connection. |
| 1975 TEST_F(P2PTransportChannelMultihomedTest, TestPreferWifiOverCellularNetwork) { | 2009 TEST_F(P2PTransportChannelMultihomedTest, TestPreferWifiOverCellularNetwork) { |
| 1976 // The interface names are chosen so that |cellular| would have higher | 2010 // The interface names are chosen so that |cellular| would have higher |
| 1977 // candidate priority if it is not for the network type. | 2011 // candidate priority if it is not for the network type. |
| 1978 auto& wifi = kAlternateAddrs; | 2012 auto& wifi = kAlternateAddrs; |
| 1979 auto& cellular = kPublicAddrs; | 2013 auto& cellular = kPublicAddrs; |
| 1980 AddAddress(0, cellular[0], "test1", rtc::ADAPTER_TYPE_CELLULAR); | 2014 AddAddress(0, cellular[0], "test1", rtc::ADAPTER_TYPE_CELLULAR); |
| (...skipping 10 matching lines...) Expand all Loading... |
| 1991 EXPECT_TRUE_WAIT_MARGIN(ep1_ch1()->receiving() && ep1_ch1()->writable() && | 2025 EXPECT_TRUE_WAIT_MARGIN(ep1_ch1()->receiving() && ep1_ch1()->writable() && |
| 1992 ep2_ch1()->receiving() && ep2_ch1()->writable(), | 2026 ep2_ch1()->receiving() && ep2_ch1()->writable(), |
| 1993 1000, 1000); | 2027 1000, 1000); |
| 1994 // Need to wait to make sure the connections on both networks are writable. | 2028 // Need to wait to make sure the connections on both networks are writable. |
| 1995 EXPECT_TRUE_WAIT(ep1_ch1()->selected_connection() && | 2029 EXPECT_TRUE_WAIT(ep1_ch1()->selected_connection() && |
| 1996 RemoteCandidate(ep1_ch1())->address().EqualIPs(wifi[1]), | 2030 RemoteCandidate(ep1_ch1())->address().EqualIPs(wifi[1]), |
| 1997 1000); | 2031 1000); |
| 1998 EXPECT_TRUE_WAIT(ep2_ch1()->selected_connection() && | 2032 EXPECT_TRUE_WAIT(ep2_ch1()->selected_connection() && |
| 1999 LocalCandidate(ep2_ch1())->address().EqualIPs(wifi[1]), | 2033 LocalCandidate(ep2_ch1())->address().EqualIPs(wifi[1]), |
| 2000 1000); | 2034 1000); |
| 2035 DestroyChannels(); |
| 2001 } | 2036 } |
| 2002 | 2037 |
| 2003 // Test that the backup connection is pinged at a rate no faster than | 2038 // Test that the backup connection is pinged at a rate no faster than |
| 2004 // what was configured. | 2039 // what was configured. |
| 2005 TEST_F(P2PTransportChannelMultihomedTest, TestPingBackupConnectionRate) { | 2040 TEST_F(P2PTransportChannelMultihomedTest, TestPingBackupConnectionRate) { |
| 2006 AddAddress(0, kPublicAddrs[0]); | 2041 AddAddress(0, kPublicAddrs[0]); |
| 2007 // Adding alternate address will make sure |kPublicAddrs| has the higher | 2042 // Adding alternate address will make sure |kPublicAddrs| has the higher |
| 2008 // priority than others. This is due to FakeNetwork::AddInterface method. | 2043 // priority than others. This is due to FakeNetwork::AddInterface method. |
| 2009 AddAddress(1, kAlternateAddrs[1]); | 2044 AddAddress(1, kAlternateAddrs[1]); |
| 2010 AddAddress(1, kPublicAddrs[1]); | 2045 AddAddress(1, kPublicAddrs[1]); |
| 2011 | 2046 |
| 2012 // Use only local ports for simplicity. | 2047 // Use only local ports for simplicity. |
| 2013 SetAllocatorFlags(0, kOnlyLocalPorts); | 2048 SetAllocatorFlags(0, kOnlyLocalPorts); |
| 2014 SetAllocatorFlags(1, kOnlyLocalPorts); | 2049 SetAllocatorFlags(1, kOnlyLocalPorts); |
| 2015 | 2050 |
| 2016 // Create channels and let them go writable, as usual. | 2051 // Create channels and let them go writable, as usual. |
| 2017 CreateChannels(1); | 2052 CreateChannels(1); |
| 2018 EXPECT_TRUE_WAIT_MARGIN(ep1_ch1()->receiving() && ep1_ch1()->writable() && | 2053 EXPECT_TRUE_WAIT_MARGIN(ep1_ch1()->receiving() && ep1_ch1()->writable() && |
| 2019 ep2_ch1()->receiving() && ep2_ch1()->writable(), | 2054 ep2_ch1()->receiving() && ep2_ch1()->writable(), |
| 2020 1000, 1000); | 2055 1000, 1000); |
| 2021 int backup_ping_interval = 2000; | 2056 int backup_ping_interval = 2000; |
| 2022 ep2_ch1()->SetIceConfig(CreateIceConfig(2000, false, backup_ping_interval)); | 2057 ep2_ch1()->SetIceConfig( |
| 2058 CreateIceConfig(2000, GATHER_ONCE, backup_ping_interval)); |
| 2023 // After the state becomes COMPLETED, the backup connection will be pinged | 2059 // After the state becomes COMPLETED, the backup connection will be pinged |
| 2024 // once every |backup_ping_interval| milliseconds. | 2060 // once every |backup_ping_interval| milliseconds. |
| 2025 ASSERT_TRUE_WAIT(ep2_ch1()->GetState() == STATE_COMPLETED, 1000); | 2061 ASSERT_TRUE_WAIT(ep2_ch1()->GetState() == STATE_COMPLETED, 1000); |
| 2026 const std::vector<Connection*>& connections = ep2_ch1()->connections(); | 2062 const std::vector<Connection*>& connections = ep2_ch1()->connections(); |
| 2027 ASSERT_EQ(2U, connections.size()); | 2063 ASSERT_EQ(2U, connections.size()); |
| 2028 Connection* backup_conn = connections[1]; | 2064 Connection* backup_conn = connections[1]; |
| 2029 EXPECT_TRUE_WAIT(backup_conn->writable(), 3000); | 2065 EXPECT_TRUE_WAIT(backup_conn->writable(), 3000); |
| 2030 int64_t last_ping_response_ms = backup_conn->last_ping_response_received(); | 2066 int64_t last_ping_response_ms = backup_conn->last_ping_response_received(); |
| 2031 EXPECT_TRUE_WAIT( | 2067 EXPECT_TRUE_WAIT( |
| 2032 last_ping_response_ms < backup_conn->last_ping_response_received(), 5000); | 2068 last_ping_response_ms < backup_conn->last_ping_response_received(), 5000); |
| 2033 int time_elapsed = | 2069 int time_elapsed = |
| 2034 backup_conn->last_ping_response_received() - last_ping_response_ms; | 2070 backup_conn->last_ping_response_received() - last_ping_response_ms; |
| 2035 LOG(LS_INFO) << "Time elapsed: " << time_elapsed; | 2071 LOG(LS_INFO) << "Time elapsed: " << time_elapsed; |
| 2036 EXPECT_GE(time_elapsed, backup_ping_interval); | 2072 EXPECT_GE(time_elapsed, backup_ping_interval); |
| 2073 |
| 2074 DestroyChannels(); |
| 2037 } | 2075 } |
| 2038 | 2076 |
| 2039 TEST_F(P2PTransportChannelMultihomedTest, TestGetState) { | 2077 TEST_F(P2PTransportChannelMultihomedTest, TestGetState) { |
| 2040 AddAddress(0, kAlternateAddrs[0]); | 2078 AddAddress(0, kAlternateAddrs[0]); |
| 2041 AddAddress(0, kPublicAddrs[0]); | 2079 AddAddress(0, kPublicAddrs[0]); |
| 2042 AddAddress(1, kPublicAddrs[1]); | 2080 AddAddress(1, kPublicAddrs[1]); |
| 2043 // Create channels and let them go writable, as usual. | 2081 // Create channels and let them go writable, as usual. |
| 2044 CreateChannels(1); | 2082 CreateChannels(1); |
| 2045 | 2083 |
| 2046 // Both transport channels will reach STATE_COMPLETED quickly. | 2084 // Both transport channels will reach STATE_COMPLETED quickly. |
| 2047 EXPECT_EQ_WAIT(TransportChannelState::STATE_COMPLETED, ep1_ch1()->GetState(), | 2085 EXPECT_EQ_WAIT(TransportChannelState::STATE_COMPLETED, ep1_ch1()->GetState(), |
| 2048 1000); | 2086 1000); |
| 2049 EXPECT_EQ_WAIT(TransportChannelState::STATE_COMPLETED, ep2_ch1()->GetState(), | 2087 EXPECT_EQ_WAIT(TransportChannelState::STATE_COMPLETED, ep2_ch1()->GetState(), |
| 2050 1000); | 2088 1000); |
| 2051 } | 2089 } |
| 2052 | 2090 |
| 2053 // Tests that when a network interface becomes inactive, if and only if | 2091 // Tests that when a network interface becomes inactive, if Continual Gathering |
| 2054 // Continual Gathering is enabled, the ports associated with that network | 2092 // policy is GATHER_CONTINUALLY, the ports associated with that network |
| 2055 // will be removed from the port list of the channel, and the respective | 2093 // will be removed from the port list of the channel, and the respective |
| 2056 // remote candidates on the other participant will be removed eventually. | 2094 // remote candidates on the other participant will be removed eventually. |
| 2057 TEST_F(P2PTransportChannelMultihomedTest, TestNetworkBecomesInactive) { | 2095 TEST_F(P2PTransportChannelMultihomedTest, TestNetworkBecomesInactive) { |
| 2096 rtc::ScopedFakeClock clock; |
| 2058 AddAddress(0, kPublicAddrs[0]); | 2097 AddAddress(0, kPublicAddrs[0]); |
| 2059 AddAddress(1, kPublicAddrs[1]); | 2098 AddAddress(1, kPublicAddrs[1]); |
| 2060 // Create channels and let them go writable, as usual. | 2099 // Create channels and let them go writable, as usual. |
| 2061 CreateChannels(1); | 2100 CreateChannels(1); |
| 2062 ep1_ch1()->SetIceConfig(CreateIceConfig(2000, true)); | 2101 ep1_ch1()->SetIceConfig(CreateIceConfig(2000, GATHER_CONTINUALLY)); |
| 2063 ep2_ch1()->SetIceConfig(CreateIceConfig(2000, false)); | 2102 ep2_ch1()->SetIceConfig(CreateIceConfig(2000, GATHER_ONCE)); |
| 2064 | 2103 |
| 2065 SetAllocatorFlags(0, kOnlyLocalPorts); | 2104 SetAllocatorFlags(0, kOnlyLocalPorts); |
| 2066 SetAllocatorFlags(1, kOnlyLocalPorts); | 2105 SetAllocatorFlags(1, kOnlyLocalPorts); |
| 2067 EXPECT_TRUE_WAIT_MARGIN(ep1_ch1()->receiving() && ep1_ch1()->writable() && | 2106 EXPECT_TRUE_SIMULATED_WAIT(ep1_ch1()->receiving() && ep1_ch1()->writable() && |
| 2068 ep2_ch1()->receiving() && ep2_ch1()->writable(), | 2107 ep2_ch1()->receiving() && |
| 2069 1000, 1000); | 2108 ep2_ch1()->writable(), |
| 2109 kDefaultTimeout, clock); |
| 2070 // More than one port has been created. | 2110 // More than one port has been created. |
| 2071 EXPECT_LE(1U, ep1_ch1()->ports().size()); | 2111 EXPECT_LE(1U, ep1_ch1()->ports().size()); |
| 2072 // Endpoint 1 enabled continual gathering; the port will be removed | 2112 // Endpoint 1 enabled continual gathering; the port will be removed |
| 2073 // when the interface is removed. | 2113 // when the interface is removed. |
| 2074 RemoveAddress(0, kPublicAddrs[0]); | 2114 RemoveAddress(0, kPublicAddrs[0]); |
| 2075 EXPECT_TRUE(ep1_ch1()->ports().empty()); | 2115 EXPECT_TRUE(ep1_ch1()->ports().empty()); |
| 2076 // The remote candidates will be removed eventually. | 2116 // The remote candidates will be removed eventually. |
| 2077 EXPECT_TRUE_WAIT(ep2_ch1()->remote_candidates().empty(), 1000); | 2117 EXPECT_TRUE_SIMULATED_WAIT(ep2_ch1()->remote_candidates().empty(), 1000, |
| 2118 clock); |
| 2078 | 2119 |
| 2079 size_t num_ports = ep2_ch1()->ports().size(); | 2120 size_t num_ports = ep2_ch1()->ports().size(); |
| 2080 EXPECT_LE(1U, num_ports); | 2121 EXPECT_LE(1U, num_ports); |
| 2081 size_t num_remote_candidates = ep1_ch1()->remote_candidates().size(); | 2122 size_t num_remote_candidates = ep1_ch1()->remote_candidates().size(); |
| 2082 // Endpoint 2 did not enable continual gathering; the port will not be removed | 2123 // Endpoint 2 did not enable continual gathering; the local port will still be |
| 2083 // when the interface is removed and neither the remote candidates on the | 2124 // removed when the interface is removed but the remote candidates on the |
| 2084 // other participant. | 2125 // other participant will not be removed. |
| 2085 RemoveAddress(1, kPublicAddrs[1]); | 2126 RemoveAddress(1, kPublicAddrs[1]); |
| 2086 rtc::Thread::Current()->ProcessMessages(500); | 2127 |
| 2087 EXPECT_EQ(num_ports, ep2_ch1()->ports().size()); | 2128 EXPECT_EQ_SIMULATED_WAIT(0U, ep2_ch1()->ports().size(), kDefaultTimeout, |
| 2129 clock); |
| 2130 SIMULATED_WAIT(0U == ep1_ch1()->remote_candidates().size(), 500, clock); |
| 2088 EXPECT_EQ(num_remote_candidates, ep1_ch1()->remote_candidates().size()); | 2131 EXPECT_EQ(num_remote_candidates, ep1_ch1()->remote_candidates().size()); |
| 2132 |
| 2133 DestroyChannels(); |
| 2089 } | 2134 } |
| 2090 | 2135 |
| 2091 /* | 2136 // Tests that continual gathering will create new connections when a new |
| 2137 // interface is added. |
| 2138 TEST_F(P2PTransportChannelMultihomedTest, |
| 2139 TestContinualGatheringOnNewInterface) { |
| 2140 auto& wifi = kAlternateAddrs; |
| 2141 auto& cellular = kPublicAddrs; |
| 2142 AddAddress(0, wifi[0], "test_wifi0", rtc::ADAPTER_TYPE_WIFI); |
| 2143 AddAddress(1, cellular[1], "test_cell1", rtc::ADAPTER_TYPE_CELLULAR); |
| 2144 CreateChannels(1); |
| 2145 // Set continual gathering policy. |
| 2146 ep1_ch1()->SetIceConfig(CreateIceConfig(1000, GATHER_CONTINUALLY)); |
| 2147 ep2_ch1()->SetIceConfig(CreateIceConfig(1000, GATHER_CONTINUALLY)); |
| 2148 SetAllocatorFlags(0, kOnlyLocalPorts); |
| 2149 SetAllocatorFlags(1, kOnlyLocalPorts); |
| 2150 EXPECT_TRUE_WAIT_MARGIN(ep1_ch1()->receiving() && ep1_ch1()->writable() && |
| 2151 ep2_ch1()->receiving() && ep2_ch1()->writable(), |
| 2152 kDefaultTimeout, kDefaultTimeout); |
| 2092 | 2153 |
| 2093 TODO(pthatcher): Once have a way to handle network interfaces changes | 2154 // Add a new wifi interface on end point 2. We should expect a new connection |
| 2094 without signalling an ICE restart, put a test like this back. In the | 2155 // to be created and the new one will be the best connection. |
| 2095 mean time, this test only worked for GICE. With ICE, it's currently | 2156 AddAddress(1, wifi[1], "test_wifi1", rtc::ADAPTER_TYPE_WIFI); |
| 2096 not possible without an ICE restart. | 2157 const cricket::Connection* conn; |
| 2158 EXPECT_TRUE_WAIT((conn = ep1_ch1()->best_connection()) != nullptr && |
| 2159 conn->remote_candidate().address().EqualIPs(wifi[1]), |
| 2160 kDefaultTimeout); |
| 2161 EXPECT_TRUE_WAIT((conn = ep2_ch1()->best_connection()) != nullptr && |
| 2162 conn->local_candidate().address().EqualIPs(wifi[1]), |
| 2163 kDefaultTimeout); |
| 2097 | 2164 |
| 2098 // Test that we can switch links in a coordinated fashion. | 2165 // Add a new cellular interface on end point 1, we should expect a new |
| 2099 TEST_F(P2PTransportChannelMultihomedTest, TestDrain) { | 2166 // backup connection created using this new interface. |
| 2167 AddAddress(0, cellular[0], "test_cellular0", rtc::ADAPTER_TYPE_CELLULAR); |
| 2168 EXPECT_TRUE_WAIT(ep1_ch1()->GetState() == cricket::STATE_COMPLETED && |
| 2169 (conn = GetConnectionWithLocalAddress( |
| 2170 ep1_ch1(), cellular[0])) != nullptr && |
| 2171 conn != ep1_ch1()->best_connection() && conn->writable(), |
| 2172 kDefaultTimeout); |
| 2173 EXPECT_TRUE_WAIT( |
| 2174 ep2_ch1()->GetState() == cricket::STATE_COMPLETED && |
| 2175 (conn = GetConnectionWithRemoteAddress(ep2_ch1(), cellular[0])) != |
| 2176 nullptr && |
| 2177 conn != ep2_ch1()->best_connection() && conn->receiving(), |
| 2178 kDefaultTimeout); |
| 2179 |
| 2180 DestroyChannels(); |
| 2181 } |
| 2182 |
| 2183 // Tests that we can switch links via continual gathering. |
| 2184 TEST_F(P2PTransportChannelMultihomedTest, |
| 2185 TestSwitchLinksViaContinualGathering) { |
| 2186 rtc::ScopedFakeClock clock; |
| 2100 AddAddress(0, kPublicAddrs[0]); | 2187 AddAddress(0, kPublicAddrs[0]); |
| 2101 AddAddress(1, kPublicAddrs[1]); | 2188 AddAddress(1, kPublicAddrs[1]); |
| 2102 // Use only local ports for simplicity. | 2189 // Use only local ports for simplicity. |
| 2103 SetAllocatorFlags(0, kOnlyLocalPorts); | 2190 SetAllocatorFlags(0, kOnlyLocalPorts); |
| 2104 SetAllocatorFlags(1, kOnlyLocalPorts); | 2191 SetAllocatorFlags(1, kOnlyLocalPorts); |
| 2105 | 2192 |
| 2106 // Create channels and let them go writable, as usual. | 2193 // Create channels and let them go writable, as usual. |
| 2107 CreateChannels(1); | 2194 CreateChannels(1); |
| 2108 EXPECT_TRUE_WAIT(ep1_ch1()->receiving() && ep1_ch1()->writable() && | 2195 // Set continual gathering policy. |
| 2109 ep2_ch1()->receiving() && ep2_ch1()->writable(), | 2196 ep1_ch1()->SetIceConfig(CreateIceConfig(1000, GATHER_CONTINUALLY)); |
| 2110 1000); | 2197 ep2_ch1()->SetIceConfig(CreateIceConfig(1000, GATHER_CONTINUALLY)); |
| 2198 EXPECT_TRUE_SIMULATED_WAIT(ep1_ch1()->receiving() && ep1_ch1()->writable() && |
| 2199 ep2_ch1()->receiving() && |
| 2200 ep2_ch1()->writable(), |
| 2201 3000, clock); |
| 2111 EXPECT_TRUE( | 2202 EXPECT_TRUE( |
| 2112 ep1_ch1()->selected_connection() && ep2_ch1()->selected_connection() && | 2203 ep1_ch1()->selected_connection() && ep2_ch1()->selected_connection() && |
| 2113 LocalCandidate(ep1_ch1())->address().EqualIPs(kPublicAddrs[0]) && | 2204 LocalCandidate(ep1_ch1())->address().EqualIPs(kPublicAddrs[0]) && |
| 2114 RemoteCandidate(ep1_ch1())->address().EqualIPs(kPublicAddrs[1])); | 2205 RemoteCandidate(ep1_ch1())->address().EqualIPs(kPublicAddrs[1])); |
| 2115 | 2206 |
| 2116 | 2207 // Add the new address first and then remove the other one. |
| 2117 // Remove the public interface, add the alternate interface, and allocate | |
| 2118 // a new generation of candidates for the new interface (via | |
| 2119 // MaybeStartGathering()). | |
| 2120 LOG(LS_INFO) << "Draining..."; | 2208 LOG(LS_INFO) << "Draining..."; |
| 2121 AddAddress(1, kAlternateAddrs[1]); | 2209 AddAddress(1, kAlternateAddrs[1]); |
| 2122 RemoveAddress(1, kPublicAddrs[1]); | 2210 RemoveAddress(1, kPublicAddrs[1]); |
| 2123 ep2_ch1()->MaybeStartGathering(); | 2211 // We should switch to use the alternate address after an exchange of pings. |
| 2212 EXPECT_TRUE_SIMULATED_WAIT( |
| 2213 ep1_ch1()->selected_connection() && ep2_ch1()->selected_connection() && |
| 2214 LocalCandidate(ep1_ch1())->address().EqualIPs(kPublicAddrs[0]) && |
| 2215 RemoteCandidate(ep1_ch1())->address().EqualIPs(kAlternateAddrs[1]), |
| 2216 3000, clock); |
| 2124 | 2217 |
| 2125 // We should switch over to use the alternate address after | 2218 // Remove one address first and then add another address. |
| 2126 // an exchange of pings. | 2219 LOG(LS_INFO) << "Draining again..."; |
| 2127 EXPECT_TRUE_WAIT( | 2220 RemoveAddress(1, kAlternateAddrs[1]); |
| 2128 ep1_ch1()->selected_connection() && ep2_ch1()->selected_connection() && | 2221 AddAddress(1, kAlternateAddrs[0]); |
| 2129 LocalCandidate(ep1_ch1())->address().EqualIPs(kPublicAddrs[0]) && | 2222 EXPECT_TRUE_SIMULATED_WAIT( |
| 2130 RemoteCandidate(ep1_ch1())->address().EqualIPs(kAlternateAddrs[1]), | 2223 ep1_ch1()->best_connection() && ep2_ch1()->best_connection() && |
| 2131 3000); | 2224 LocalCandidate(ep1_ch1())->address().EqualIPs(kPublicAddrs[0]) && |
| 2225 RemoteCandidate(ep1_ch1())->address().EqualIPs(kAlternateAddrs[0]), |
| 2226 3000, clock); |
| 2132 | 2227 |
| 2133 DestroyChannels(); | 2228 DestroyChannels(); |
| 2134 } | 2229 } |
| 2135 | 2230 |
| 2231 /* |
| 2232 TODO(honghaiz) Once continual gathering fully supports |
| 2233 GATHER_CONTINUALLY_AND_RECOVER, put this test back. |
| 2234 |
| 2235 // Tests that if the backup connections are lost and then the interface with the |
| 2236 // selected connection is gone, continual gathering will restore the |
| 2237 // connectivity. |
| 2238 TEST_F(P2PTransportChannelMultihomedTest, |
| 2239 TestBackupConnectionLostThenInterfaceGone) { |
| 2240 rtc::ScopedFakeClock clock; |
| 2241 auto& wifi = kAlternateAddrs; |
| 2242 auto& cellular = kPublicAddrs; |
| 2243 AddAddress(0, wifi[0], "test_wifi0", rtc::ADAPTER_TYPE_WIFI); |
| 2244 AddAddress(0, cellular[0], "test_cell0", rtc::ADAPTER_TYPE_CELLULAR); |
| 2245 AddAddress(1, wifi[1], "test_wifi1", rtc::ADAPTER_TYPE_WIFI); |
| 2246 AddAddress(1, cellular[1], "test_cell1", rtc::ADAPTER_TYPE_CELLULAR); |
| 2247 // Use only local ports for simplicity. |
| 2248 SetAllocatorFlags(0, kOnlyLocalPorts); |
| 2249 SetAllocatorFlags(1, kOnlyLocalPorts); |
| 2250 |
| 2251 // Create channels and let them go writable, as usual. |
| 2252 CreateChannels(1); |
| 2253 // Set continual gathering policy. |
| 2254 IceConfig config = CreateIceConfig(1000, GATHER_CONTINUALLY_AND_RECOVER); |
| 2255 ep1_ch1()->SetIceConfig(config); |
| 2256 ep2_ch1()->SetIceConfig(config); |
| 2257 EXPECT_TRUE_SIMULATED_WAIT(ep1_ch1()->receiving() && ep1_ch1()->writable() && |
| 2258 ep2_ch1()->receiving() && ep2_ch1()->writable(), |
| 2259 3000, clock); |
| 2260 EXPECT_TRUE(ep1_ch1()->best_connection() && ep2_ch1()->best_connection() && |
| 2261 LocalCandidate(ep1_ch1())->address().EqualIPs(wifi[0]) && |
| 2262 RemoteCandidate(ep1_ch1())->address().EqualIPs(wifi[1])); |
| 2263 |
| 2264 // First destroy all backup connection. |
| 2265 DestroyAllButBestConnection(ep1_ch1()); |
| 2266 |
| 2267 SIMULATED_WAIT(false, 10, clock); |
| 2268 // Then the interface of the best connection goes away. |
| 2269 RemoveAddress(0, wifi[0]); |
| 2270 EXPECT_TRUE_SIMULATED_WAIT( |
| 2271 ep1_ch1()->best_connection() && ep2_ch1()->best_connection() && |
| 2272 LocalCandidate(ep1_ch1())->address().EqualIPs(cellular[0]) && |
| 2273 RemoteCandidate(ep1_ch1())->address().EqualIPs(wifi[1]), |
| 2274 3000, clock); |
| 2275 |
| 2276 DestroyChannels(); |
| 2277 } |
| 2136 */ | 2278 */ |
| 2137 | 2279 |
| 2280 // Tests that the backup connection will be restored after it is destroyed. |
| 2281 TEST_F(P2PTransportChannelMultihomedTest, TestRestoreBackupConnection) { |
| 2282 rtc::ScopedFakeClock clock; |
| 2283 auto& wifi = kAlternateAddrs; |
| 2284 auto& cellular = kPublicAddrs; |
| 2285 AddAddress(0, wifi[0], "test_wifi0", rtc::ADAPTER_TYPE_WIFI); |
| 2286 AddAddress(0, cellular[0], "test_cell0", rtc::ADAPTER_TYPE_CELLULAR); |
| 2287 AddAddress(1, wifi[1], "test_wifi1", rtc::ADAPTER_TYPE_WIFI); |
| 2288 AddAddress(1, cellular[1], "test_cell1", rtc::ADAPTER_TYPE_CELLULAR); |
| 2289 // Use only local ports for simplicity. |
| 2290 SetAllocatorFlags(0, kOnlyLocalPorts); |
| 2291 SetAllocatorFlags(1, kOnlyLocalPorts); |
| 2292 |
| 2293 // Create channels and let them go writable, as usual. |
| 2294 CreateChannels(1); |
| 2295 IceConfig config = CreateIceConfig(1000, GATHER_CONTINUALLY); |
| 2296 config.regather_on_failed_networks_interval = rtc::Optional<int>(2000); |
| 2297 ep1_ch1()->SetIceConfig(config); |
| 2298 ep2_ch1()->SetIceConfig(config); |
| 2299 EXPECT_TRUE_SIMULATED_WAIT(ep1_ch1()->receiving() && ep1_ch1()->writable() && |
| 2300 ep2_ch1()->receiving() && |
| 2301 ep2_ch1()->writable(), |
| 2302 3000, clock); |
| 2303 EXPECT_TRUE(ep1_ch1()->best_connection() && ep2_ch1()->best_connection() && |
| 2304 LocalCandidate(ep1_ch1())->address().EqualIPs(wifi[0]) && |
| 2305 RemoteCandidate(ep1_ch1())->address().EqualIPs(wifi[1])); |
| 2306 |
| 2307 // Destroy all backup connections. |
| 2308 DestroyAllButBestConnection(ep1_ch1()); |
| 2309 // Ensure the backup connection is removed first. |
| 2310 EXPECT_TRUE_SIMULATED_WAIT( |
| 2311 GetConnectionWithLocalAddress(ep1_ch1(), cellular[0]) == nullptr, |
| 2312 kDefaultTimeout, clock); |
| 2313 const cricket::Connection* conn; |
| 2314 EXPECT_TRUE_SIMULATED_WAIT( |
| 2315 (conn = GetConnectionWithLocalAddress(ep1_ch1(), cellular[0])) != |
| 2316 nullptr && |
| 2317 conn != ep1_ch1()->best_connection() && conn->writable(), |
| 2318 5000, clock); |
| 2319 |
| 2320 DestroyChannels(); |
| 2321 } |
| 2322 |
| 2138 // A collection of tests which tests a single P2PTransportChannel by sending | 2323 // A collection of tests which tests a single P2PTransportChannel by sending |
| 2139 // pings. | 2324 // pings. |
| 2140 class P2PTransportChannelPingTest : public testing::Test, | 2325 class P2PTransportChannelPingTest : public testing::Test, |
| 2141 public sigslot::has_slots<> { | 2326 public sigslot::has_slots<> { |
| 2142 public: | 2327 public: |
| 2143 P2PTransportChannelPingTest() | 2328 P2PTransportChannelPingTest() |
| 2144 : pss_(new rtc::PhysicalSocketServer), | 2329 : pss_(new rtc::PhysicalSocketServer), |
| 2145 vss_(new rtc::VirtualSocketServer(pss_.get())), | 2330 vss_(new rtc::VirtualSocketServer(pss_.get())), |
| 2146 ss_scope_(vss_.get()) {} | 2331 ss_scope_(vss_.get()) {} |
| 2147 | 2332 |
| (...skipping 469 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2617 } | 2802 } |
| 2618 | 2803 |
| 2619 TEST_F(P2PTransportChannelPingTest, TestReceivingStateChange) { | 2804 TEST_F(P2PTransportChannelPingTest, TestReceivingStateChange) { |
| 2620 FakePortAllocator pa(rtc::Thread::Current(), nullptr); | 2805 FakePortAllocator pa(rtc::Thread::Current(), nullptr); |
| 2621 P2PTransportChannel ch("receiving state change", 1, &pa); | 2806 P2PTransportChannel ch("receiving state change", 1, &pa); |
| 2622 PrepareChannel(&ch); | 2807 PrepareChannel(&ch); |
| 2623 // Default receiving timeout and checking receiving interval should not be too | 2808 // Default receiving timeout and checking receiving interval should not be too |
| 2624 // small. | 2809 // small. |
| 2625 EXPECT_LE(1000, ch.receiving_timeout()); | 2810 EXPECT_LE(1000, ch.receiving_timeout()); |
| 2626 EXPECT_LE(200, ch.check_receiving_interval()); | 2811 EXPECT_LE(200, ch.check_receiving_interval()); |
| 2627 ch.SetIceConfig(CreateIceConfig(500, false)); | 2812 ch.SetIceConfig(CreateIceConfig(500, GATHER_ONCE)); |
| 2628 EXPECT_EQ(500, ch.receiving_timeout()); | 2813 EXPECT_EQ(500, ch.receiving_timeout()); |
| 2629 EXPECT_EQ(50, ch.check_receiving_interval()); | 2814 EXPECT_EQ(50, ch.check_receiving_interval()); |
| 2630 ch.MaybeStartGathering(); | 2815 ch.MaybeStartGathering(); |
| 2631 ch.AddRemoteCandidate(CreateUdpCandidate(LOCAL_PORT_TYPE, "1.1.1.1", 1, 1)); | 2816 ch.AddRemoteCandidate(CreateUdpCandidate(LOCAL_PORT_TYPE, "1.1.1.1", 1, 1)); |
| 2632 Connection* conn1 = WaitForConnectionTo(&ch, "1.1.1.1", 1); | 2817 Connection* conn1 = WaitForConnectionTo(&ch, "1.1.1.1", 1); |
| 2633 ASSERT_TRUE(conn1 != nullptr); | 2818 ASSERT_TRUE(conn1 != nullptr); |
| 2634 | 2819 |
| 2635 conn1->ReceivedPing(); | 2820 conn1->ReceivedPing(); |
| 2636 conn1->OnReadPacket("ABC", 3, rtc::CreatePacketTime(0)); | 2821 conn1->OnReadPacket("ABC", 3, rtc::CreatePacketTime(0)); |
| 2637 EXPECT_TRUE_WAIT(ch.selected_connection() != nullptr, 1000); | 2822 EXPECT_TRUE_WAIT(ch.selected_connection() != nullptr, 1000); |
| (...skipping 393 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3031 // When a higher-priority, nominated candidate comes in, the connections with | 3216 // When a higher-priority, nominated candidate comes in, the connections with |
| 3032 // lower-priority are pruned. | 3217 // lower-priority are pruned. |
| 3033 ch.AddRemoteCandidate(CreateUdpCandidate(LOCAL_PORT_TYPE, "2.2.2.2", 2, 10)); | 3218 ch.AddRemoteCandidate(CreateUdpCandidate(LOCAL_PORT_TYPE, "2.2.2.2", 2, 10)); |
| 3034 Connection* conn2 = WaitForConnectionTo(&ch, "2.2.2.2", 2); | 3219 Connection* conn2 = WaitForConnectionTo(&ch, "2.2.2.2", 2); |
| 3035 ASSERT_TRUE(conn2 != nullptr); | 3220 ASSERT_TRUE(conn2 != nullptr); |
| 3036 conn2->ReceivedPingResponse(LOW_RTT); // Becomes writable and receiving | 3221 conn2->ReceivedPingResponse(LOW_RTT); // Becomes writable and receiving |
| 3037 conn2->set_nominated(true); | 3222 conn2->set_nominated(true); |
| 3038 conn2->SignalNominated(conn2); | 3223 conn2->SignalNominated(conn2); |
| 3039 EXPECT_TRUE_WAIT(conn1->pruned(), 3000); | 3224 EXPECT_TRUE_WAIT(conn1->pruned(), 3000); |
| 3040 | 3225 |
| 3041 ch.SetIceConfig(CreateIceConfig(500, false)); | 3226 ch.SetIceConfig(CreateIceConfig(500, GATHER_ONCE)); |
| 3042 // Wait until conn2 becomes not receiving. | 3227 // Wait until conn2 becomes not receiving. |
| 3043 EXPECT_TRUE_WAIT(!conn2->receiving(), 3000); | 3228 EXPECT_TRUE_WAIT(!conn2->receiving(), 3000); |
| 3044 | 3229 |
| 3045 ch.AddRemoteCandidate(CreateUdpCandidate(LOCAL_PORT_TYPE, "3.3.3.3", 3, 1)); | 3230 ch.AddRemoteCandidate(CreateUdpCandidate(LOCAL_PORT_TYPE, "3.3.3.3", 3, 1)); |
| 3046 Connection* conn3 = WaitForConnectionTo(&ch, "3.3.3.3", 3); | 3231 Connection* conn3 = WaitForConnectionTo(&ch, "3.3.3.3", 3); |
| 3047 ASSERT_TRUE(conn3 != nullptr); | 3232 ASSERT_TRUE(conn3 != nullptr); |
| 3048 // The selected connection should still be conn2. Even through conn3 has lower | 3233 // The selected connection should still be conn2. Even through conn3 has lower |
| 3049 // priority and is not receiving/writable, it is not pruned because the | 3234 // priority and is not receiving/writable, it is not pruned because the |
| 3050 // selected connection is not receiving. | 3235 // selected connection is not receiving. |
| 3051 WAIT(conn3->pruned(), 1000); | 3236 WAIT(conn3->pruned(), 1000); |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3097 // Need to wait until the channel state is updated. | 3282 // Need to wait until the channel state is updated. |
| 3098 EXPECT_EQ_WAIT(TransportChannelState::STATE_FAILED, ch.GetState(), 1000); | 3283 EXPECT_EQ_WAIT(TransportChannelState::STATE_FAILED, ch.GetState(), 1000); |
| 3099 } | 3284 } |
| 3100 | 3285 |
| 3101 // Test that when a low-priority connection is pruned, it is not deleted | 3286 // Test that when a low-priority connection is pruned, it is not deleted |
| 3102 // right away, and it can become active and be pruned again. | 3287 // right away, and it can become active and be pruned again. |
| 3103 TEST_F(P2PTransportChannelPingTest, TestConnectionPrunedAgain) { | 3288 TEST_F(P2PTransportChannelPingTest, TestConnectionPrunedAgain) { |
| 3104 FakePortAllocator pa(rtc::Thread::Current(), nullptr); | 3289 FakePortAllocator pa(rtc::Thread::Current(), nullptr); |
| 3105 P2PTransportChannel ch("test channel", 1, &pa); | 3290 P2PTransportChannel ch("test channel", 1, &pa); |
| 3106 PrepareChannel(&ch); | 3291 PrepareChannel(&ch); |
| 3107 ch.SetIceConfig(CreateIceConfig(1000, false)); | 3292 ch.SetIceConfig(CreateIceConfig(1000, GATHER_ONCE)); |
| 3108 ch.MaybeStartGathering(); | 3293 ch.MaybeStartGathering(); |
| 3109 ch.AddRemoteCandidate(CreateUdpCandidate(LOCAL_PORT_TYPE, "1.1.1.1", 1, 100)); | 3294 ch.AddRemoteCandidate(CreateUdpCandidate(LOCAL_PORT_TYPE, "1.1.1.1", 1, 100)); |
| 3110 Connection* conn1 = WaitForConnectionTo(&ch, "1.1.1.1", 1); | 3295 Connection* conn1 = WaitForConnectionTo(&ch, "1.1.1.1", 1); |
| 3111 ASSERT_TRUE(conn1 != nullptr); | 3296 ASSERT_TRUE(conn1 != nullptr); |
| 3112 EXPECT_EQ(conn1, ch.selected_connection()); | 3297 EXPECT_EQ(conn1, ch.selected_connection()); |
| 3113 conn1->ReceivedPingResponse(LOW_RTT); // Becomes writable and receiving | 3298 conn1->ReceivedPingResponse(LOW_RTT); // Becomes writable and receiving |
| 3114 | 3299 |
| 3115 // Add a low-priority connection |conn2|, which will be pruned, but it will | 3300 // Add a low-priority connection |conn2|, which will be pruned, but it will |
| 3116 // not be deleted right away. Once the current selected connection becomes not | 3301 // not be deleted right away. Once the current selected connection becomes not |
| 3117 // receiving, |conn2| will start to ping and upon receiving the ping response, | 3302 // receiving, |conn2| will start to ping and upon receiving the ping response, |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3171 } | 3356 } |
| 3172 | 3357 |
| 3173 // Tests that after a port allocator session is started, it will be stopped | 3358 // Tests that after a port allocator session is started, it will be stopped |
| 3174 // when a new connection becomes writable and receiving. Also tests that if a | 3359 // when a new connection becomes writable and receiving. Also tests that if a |
| 3175 // connection belonging to an old session becomes writable, it won't stop | 3360 // connection belonging to an old session becomes writable, it won't stop |
| 3176 // the current port allocator session. | 3361 // the current port allocator session. |
| 3177 TEST_F(P2PTransportChannelPingTest, TestStopPortAllocatorSessions) { | 3362 TEST_F(P2PTransportChannelPingTest, TestStopPortAllocatorSessions) { |
| 3178 FakePortAllocator pa(rtc::Thread::Current(), nullptr); | 3363 FakePortAllocator pa(rtc::Thread::Current(), nullptr); |
| 3179 P2PTransportChannel ch("test channel", 1, &pa); | 3364 P2PTransportChannel ch("test channel", 1, &pa); |
| 3180 PrepareChannel(&ch); | 3365 PrepareChannel(&ch); |
| 3181 ch.SetIceConfig(CreateIceConfig(2000, false)); | 3366 ch.SetIceConfig(CreateIceConfig(2000, GATHER_ONCE)); |
| 3182 ch.MaybeStartGathering(); | 3367 ch.MaybeStartGathering(); |
| 3183 ch.AddRemoteCandidate(CreateUdpCandidate(LOCAL_PORT_TYPE, "1.1.1.1", 1, 100)); | 3368 ch.AddRemoteCandidate(CreateUdpCandidate(LOCAL_PORT_TYPE, "1.1.1.1", 1, 100)); |
| 3184 Connection* conn1 = WaitForConnectionTo(&ch, "1.1.1.1", 1); | 3369 Connection* conn1 = WaitForConnectionTo(&ch, "1.1.1.1", 1); |
| 3185 ASSERT_TRUE(conn1 != nullptr); | 3370 ASSERT_TRUE(conn1 != nullptr); |
| 3186 conn1->ReceivedPingResponse(LOW_RTT); // Becomes writable and receiving | 3371 conn1->ReceivedPingResponse(LOW_RTT); // Becomes writable and receiving |
| 3187 EXPECT_TRUE(!ch.allocator_session()->IsGettingPorts()); | 3372 EXPECT_TRUE(!ch.allocator_session()->IsGettingPorts()); |
| 3188 | 3373 |
| 3189 // Start a new session. Even though conn1, which belongs to an older | 3374 // Start a new session. Even though conn1, which belongs to an older |
| 3190 // session, becomes unwritable and writable again, it should not stop the | 3375 // session, becomes unwritable and writable again, it should not stop the |
| 3191 // current session. | 3376 // current session. |
| 3192 ch.SetIceCredentials(kIceUfrag[1], kIcePwd[1]); | 3377 ch.SetIceCredentials(kIceUfrag[1], kIcePwd[1]); |
| 3193 ch.MaybeStartGathering(); | 3378 ch.MaybeStartGathering(); |
| 3194 conn1->Prune(); | 3379 conn1->Prune(); |
| 3195 conn1->ReceivedPingResponse(LOW_RTT); | 3380 conn1->ReceivedPingResponse(LOW_RTT); |
| 3196 EXPECT_TRUE(ch.allocator_session()->IsGettingPorts()); | 3381 EXPECT_TRUE(ch.allocator_session()->IsGettingPorts()); |
| 3197 | 3382 |
| 3198 // But if a new connection created from the new session becomes writable, | 3383 // But if a new connection created from the new session becomes writable, |
| 3199 // it will stop the current session. | 3384 // it will stop the current session. |
| 3200 ch.AddRemoteCandidate(CreateUdpCandidate(LOCAL_PORT_TYPE, "2.2.2.2", 2, 100)); | 3385 ch.AddRemoteCandidate(CreateUdpCandidate(LOCAL_PORT_TYPE, "2.2.2.2", 2, 100)); |
| 3201 Connection* conn2 = WaitForConnectionTo(&ch, "2.2.2.2", 2); | 3386 Connection* conn2 = WaitForConnectionTo(&ch, "2.2.2.2", 2); |
| 3202 ASSERT_TRUE(conn2 != nullptr); | 3387 ASSERT_TRUE(conn2 != nullptr); |
| 3203 conn2->ReceivedPingResponse(LOW_RTT); // Becomes writable and receiving | 3388 conn2->ReceivedPingResponse(LOW_RTT); // Becomes writable and receiving |
| 3204 EXPECT_TRUE(!ch.allocator_session()->IsGettingPorts()); | 3389 EXPECT_TRUE(!ch.allocator_session()->IsGettingPorts()); |
| 3205 } | 3390 } |
| 3206 | 3391 |
| 3207 // Test that the ICE role is updated even on ports with inactive networks when | 3392 // Test that the ICE role is updated even on ports that has been removed. |
| 3208 // doing continual gathering. These ports may still have connections that need | 3393 // These ports may still have connections that need a correct role, in case that |
| 3209 // a correct role, in case the network becomes active before the connection is | 3394 // the connections on it may still receive stun pings. |
| 3210 // destroyed. | 3395 TEST_F(P2PTransportChannelPingTest, TestIceRoleUpdatedOnRemovedPort) { |
| 3211 TEST_F(P2PTransportChannelPingTest, | |
| 3212 TestIceRoleUpdatedOnPortAfterSignalNetworkInactive) { | |
| 3213 FakePortAllocator pa(rtc::Thread::Current(), nullptr); | 3396 FakePortAllocator pa(rtc::Thread::Current(), nullptr); |
| 3214 P2PTransportChannel ch("test channel", ICE_CANDIDATE_COMPONENT_DEFAULT, &pa); | 3397 P2PTransportChannel ch("test channel", ICE_CANDIDATE_COMPONENT_DEFAULT, &pa); |
| 3215 // Starts with ICEROLE_CONTROLLING. | 3398 // Starts with ICEROLE_CONTROLLING. |
| 3216 PrepareChannel(&ch); | 3399 PrepareChannel(&ch); |
| 3217 IceConfig config = CreateIceConfig(1000, true); | 3400 IceConfig config = CreateIceConfig(1000, GATHER_CONTINUALLY); |
| 3218 ch.SetIceConfig(config); | 3401 ch.SetIceConfig(config); |
| 3219 ch.MaybeStartGathering(); | 3402 ch.MaybeStartGathering(); |
| 3220 ch.AddRemoteCandidate(CreateUdpCandidate(LOCAL_PORT_TYPE, "1.1.1.1", 1, 1)); | 3403 ch.AddRemoteCandidate(CreateUdpCandidate(LOCAL_PORT_TYPE, "1.1.1.1", 1, 1)); |
| 3221 | 3404 |
| 3222 Connection* conn = WaitForConnectionTo(&ch, "1.1.1.1", 1); | 3405 Connection* conn = WaitForConnectionTo(&ch, "1.1.1.1", 1); |
| 3223 ASSERT_TRUE(conn != nullptr); | 3406 ASSERT_TRUE(conn != nullptr); |
| 3224 | 3407 |
| 3225 // Make the fake port signal that its network is inactive, then change the | 3408 // Make a fake signal to remove the ports in the p2ptransportchannel. then |
| 3226 // ICE role and expect it to be updated. | 3409 // change the ICE role and expect it to be updated. |
| 3227 conn->port()->SignalNetworkInactive(conn->port()); | 3410 std::vector<PortInterface*> ports(1, conn->port()); |
| 3411 ch.allocator_session()->SignalPortsRemoved(ch.allocator_session(), ports); |
| 3228 ch.SetIceRole(ICEROLE_CONTROLLED); | 3412 ch.SetIceRole(ICEROLE_CONTROLLED); |
| 3229 EXPECT_EQ(ICEROLE_CONTROLLED, conn->port()->GetIceRole()); | 3413 EXPECT_EQ(ICEROLE_CONTROLLED, conn->port()->GetIceRole()); |
| 3230 } | 3414 } |
| 3231 | 3415 |
| 3232 // Test that the ICE role is updated even on ports with inactive networks. | 3416 // Test that the ICE role is updated even on ports with inactive networks. |
| 3233 // These ports may still have connections that need a correct role, for the | 3417 // These ports may still have connections that need a correct role, for the |
| 3234 // pings sent by those connections until they're replaced by newer-generation | 3418 // pings sent by those connections until they're replaced by newer-generation |
| 3235 // connections. | 3419 // connections. |
| 3236 TEST_F(P2PTransportChannelPingTest, TestIceRoleUpdatedOnPortAfterIceRestart) { | 3420 TEST_F(P2PTransportChannelPingTest, TestIceRoleUpdatedOnPortAfterIceRestart) { |
| 3237 FakePortAllocator pa(rtc::Thread::Current(), nullptr); | 3421 FakePortAllocator pa(rtc::Thread::Current(), nullptr); |
| (...skipping 244 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3482 | 3666 |
| 3483 // TCP Relay/Relay is the next. | 3667 // TCP Relay/Relay is the next. |
| 3484 VerifyNextPingableConnection(RELAY_PORT_TYPE, RELAY_PORT_TYPE, | 3668 VerifyNextPingableConnection(RELAY_PORT_TYPE, RELAY_PORT_TYPE, |
| 3485 TCP_PROTOCOL_NAME); | 3669 TCP_PROTOCOL_NAME); |
| 3486 | 3670 |
| 3487 // Finally, Local/Relay will be pinged. | 3671 // Finally, Local/Relay will be pinged. |
| 3488 VerifyNextPingableConnection(LOCAL_PORT_TYPE, RELAY_PORT_TYPE); | 3672 VerifyNextPingableConnection(LOCAL_PORT_TYPE, RELAY_PORT_TYPE); |
| 3489 } | 3673 } |
| 3490 | 3674 |
| 3491 } // namespace cricket { | 3675 } // namespace cricket { |
| OLD | NEW |