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 kTiebreaker1 = 11111; | 103 static const uint64_t kTiebreaker1 = 11111; |
104 static const uint64_t kTiebreaker2 = 22222; | 104 static const uint64_t kTiebreaker2 = 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 1129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1554 } | 1556 } |
1555 | 1557 |
1556 // Test that if continual gathering is set to true, ICE gathering state will | 1558 // Test that if continual gathering is set to true, ICE gathering state will |
1557 // not change to "Complete", and vice versa. | 1559 // not change to "Complete", and vice versa. |
1558 TEST_F(P2PTransportChannelTest, TestContinualGathering) { | 1560 TEST_F(P2PTransportChannelTest, TestContinualGathering) { |
1559 ConfigureEndpoints(OPEN, OPEN, kDefaultPortAllocatorFlags, | 1561 ConfigureEndpoints(OPEN, OPEN, kDefaultPortAllocatorFlags, |
1560 kDefaultPortAllocatorFlags); | 1562 kDefaultPortAllocatorFlags); |
1561 SetAllocationStepDelay(0, kDefaultStepDelay); | 1563 SetAllocationStepDelay(0, kDefaultStepDelay); |
1562 SetAllocationStepDelay(1, kDefaultStepDelay); | 1564 SetAllocationStepDelay(1, kDefaultStepDelay); |
1563 CreateChannels(1); | 1565 CreateChannels(1); |
1564 IceConfig config = CreateIceConfig(1000, true); | 1566 IceConfig config = CreateIceConfig(1000, GATHER_CONTINUALLY); |
1565 ep1_ch1()->SetIceConfig(config); | 1567 ep1_ch1()->SetIceConfig(config); |
1566 // By default, ep2 does not gather continually. | 1568 // By default, ep2 does not gather continually. |
1567 | 1569 |
1568 EXPECT_TRUE_WAIT_MARGIN(ep1_ch1() != NULL && ep2_ch1() != NULL && | 1570 EXPECT_TRUE_WAIT_MARGIN(ep1_ch1() != NULL && ep2_ch1() != NULL && |
1569 ep1_ch1()->receiving() && ep1_ch1()->writable() && | 1571 ep1_ch1()->receiving() && ep1_ch1()->writable() && |
1570 ep2_ch1()->receiving() && ep2_ch1()->writable(), | 1572 ep2_ch1()->receiving() && ep2_ch1()->writable(), |
1571 1000, 1000); | 1573 1000, 1000); |
1572 WAIT(IceGatheringState::kIceGatheringComplete == ep1_ch1()->gathering_state(), | 1574 WAIT(IceGatheringState::kIceGatheringComplete == ep1_ch1()->gathering_state(), |
1573 1000); | 1575 1000); |
1574 EXPECT_EQ(IceGatheringState::kIceGatheringGathering, | 1576 EXPECT_EQ(IceGatheringState::kIceGatheringGathering, |
(...skipping 250 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1825 TEST_F(P2PTransportChannelSameNatTest, TestConesBehindSameCone) { | 1827 TEST_F(P2PTransportChannelSameNatTest, TestConesBehindSameCone) { |
1826 ConfigureEndpoints(NAT_FULL_CONE, NAT_FULL_CONE, NAT_FULL_CONE); | 1828 ConfigureEndpoints(NAT_FULL_CONE, NAT_FULL_CONE, NAT_FULL_CONE); |
1827 Test(P2PTransportChannelTestBase::Result( | 1829 Test(P2PTransportChannelTestBase::Result( |
1828 "prflx", "udp", "stun", "udp", "stun", "udp", "prflx", "udp", 1000)); | 1830 "prflx", "udp", "stun", "udp", "stun", "udp", "prflx", "udp", 1000)); |
1829 } | 1831 } |
1830 | 1832 |
1831 // Test what happens when we have multiple available pathways. | 1833 // Test what happens when we have multiple available pathways. |
1832 // In the future we will try different RTTs and configs for the different | 1834 // In the future we will try different RTTs and configs for the different |
1833 // interfaces, so that we can simulate a user with Ethernet and VPN networks. | 1835 // interfaces, so that we can simulate a user with Ethernet and VPN networks. |
1834 class P2PTransportChannelMultihomedTest : public P2PTransportChannelTestBase { | 1836 class P2PTransportChannelMultihomedTest : public P2PTransportChannelTestBase { |
| 1837 public: |
| 1838 const cricket::Connection* GetConnectionWithRemoteAddress( |
| 1839 cricket::P2PTransportChannel* channel, |
| 1840 const SocketAddress& address) { |
| 1841 for (cricket::Connection* conn : channel->connections()) { |
| 1842 if (conn->remote_candidate().address().EqualIPs(address)) { |
| 1843 return conn; |
| 1844 } |
| 1845 } |
| 1846 return nullptr; |
| 1847 } |
| 1848 |
| 1849 const cricket::Connection* GetConnectionWithLocalAddress( |
| 1850 cricket::P2PTransportChannel* channel, |
| 1851 const SocketAddress& address) { |
| 1852 for (cricket::Connection* conn : channel->connections()) { |
| 1853 if (conn->local_candidate().address().EqualIPs(address)) { |
| 1854 return conn; |
| 1855 } |
| 1856 } |
| 1857 return nullptr; |
| 1858 } |
| 1859 |
| 1860 void DestroyAllButBestConnection(cricket::P2PTransportChannel* channel) { |
| 1861 const cricket::Connection* best_connection = channel->best_connection(); |
| 1862 for (cricket::Connection* conn : channel->connections()) { |
| 1863 if (conn != best_connection) { |
| 1864 conn->Destroy(); |
| 1865 } |
| 1866 } |
| 1867 } |
1835 }; | 1868 }; |
1836 | 1869 |
1837 // Test that we can establish connectivity when both peers are multihomed. | 1870 // Test that we can establish connectivity when both peers are multihomed. |
1838 TEST_F(P2PTransportChannelMultihomedTest, DISABLED_TestBasic) { | 1871 TEST_F(P2PTransportChannelMultihomedTest, DISABLED_TestBasic) { |
1839 AddAddress(0, kPublicAddrs[0]); | 1872 AddAddress(0, kPublicAddrs[0]); |
1840 AddAddress(0, kAlternateAddrs[0]); | 1873 AddAddress(0, kAlternateAddrs[0]); |
1841 AddAddress(1, kPublicAddrs[1]); | 1874 AddAddress(1, kPublicAddrs[1]); |
1842 AddAddress(1, kAlternateAddrs[1]); | 1875 AddAddress(1, kAlternateAddrs[1]); |
1843 Test(kLocalUdpToLocalUdp); | 1876 Test(kLocalUdpToLocalUdp); |
1844 } | 1877 } |
(...skipping 16 matching lines...) Expand all Loading... |
1861 | 1894 |
1862 EXPECT_TRUE_WAIT_MARGIN(ep1_ch1()->receiving() && ep1_ch1()->writable() && | 1895 EXPECT_TRUE_WAIT_MARGIN(ep1_ch1()->receiving() && ep1_ch1()->writable() && |
1863 ep2_ch1()->receiving() && ep2_ch1()->writable(), | 1896 ep2_ch1()->receiving() && ep2_ch1()->writable(), |
1864 1000, 1000); | 1897 1000, 1000); |
1865 EXPECT_TRUE(ep1_ch1()->selected_connection() && | 1898 EXPECT_TRUE(ep1_ch1()->selected_connection() && |
1866 ep2_ch1()->selected_connection() && | 1899 ep2_ch1()->selected_connection() && |
1867 LocalCandidate(ep1_ch1())->address().EqualIPs(kPublicAddrs[0]) && | 1900 LocalCandidate(ep1_ch1())->address().EqualIPs(kPublicAddrs[0]) && |
1868 RemoteCandidate(ep1_ch1())->address().EqualIPs(kPublicAddrs[1])); | 1901 RemoteCandidate(ep1_ch1())->address().EqualIPs(kPublicAddrs[1])); |
1869 | 1902 |
1870 // Make the receiving timeout shorter for testing. | 1903 // Make the receiving timeout shorter for testing. |
1871 IceConfig config = CreateIceConfig(1000, false); | 1904 IceConfig config = CreateIceConfig(1000, GATHER_ONCE); |
1872 ep1_ch1()->SetIceConfig(config); | 1905 ep1_ch1()->SetIceConfig(config); |
1873 ep2_ch1()->SetIceConfig(config); | 1906 ep2_ch1()->SetIceConfig(config); |
1874 | 1907 |
1875 // Blackhole any traffic to or from the public addrs. | 1908 // Blackhole any traffic to or from the public addrs. |
1876 LOG(LS_INFO) << "Failing over..."; | 1909 LOG(LS_INFO) << "Failing over..."; |
1877 fw()->AddRule(false, rtc::FP_ANY, rtc::FD_ANY, kPublicAddrs[1]); | 1910 fw()->AddRule(false, rtc::FP_ANY, rtc::FD_ANY, kPublicAddrs[1]); |
1878 // The selected connections will switch, so keep references to them. | 1911 // The selected connections will switch, so keep references to them. |
1879 const Connection* selected_connection1 = ep1_ch1()->selected_connection(); | 1912 const Connection* selected_connection1 = ep1_ch1()->selected_connection(); |
1880 const Connection* selected_connection2 = ep2_ch1()->selected_connection(); | 1913 const Connection* selected_connection2 = ep2_ch1()->selected_connection(); |
1881 // We should detect loss of receiving within 1 second or so. | 1914 // We should detect loss of receiving within 1 second or so. |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1914 CreateChannels(1); | 1947 CreateChannels(1); |
1915 EXPECT_TRUE_WAIT_MARGIN(ep1_ch1()->receiving() && ep1_ch1()->writable() && | 1948 EXPECT_TRUE_WAIT_MARGIN(ep1_ch1()->receiving() && ep1_ch1()->writable() && |
1916 ep2_ch1()->receiving() && ep2_ch1()->writable(), | 1949 ep2_ch1()->receiving() && ep2_ch1()->writable(), |
1917 1000, 1000); | 1950 1000, 1000); |
1918 EXPECT_TRUE(ep1_ch1()->selected_connection() && | 1951 EXPECT_TRUE(ep1_ch1()->selected_connection() && |
1919 ep2_ch1()->selected_connection() && | 1952 ep2_ch1()->selected_connection() && |
1920 LocalCandidate(ep1_ch1())->address().EqualIPs(kPublicAddrs[0]) && | 1953 LocalCandidate(ep1_ch1())->address().EqualIPs(kPublicAddrs[0]) && |
1921 RemoteCandidate(ep1_ch1())->address().EqualIPs(kPublicAddrs[1])); | 1954 RemoteCandidate(ep1_ch1())->address().EqualIPs(kPublicAddrs[1])); |
1922 | 1955 |
1923 // Make the receiving timeout shorter for testing. | 1956 // Make the receiving timeout shorter for testing. |
1924 IceConfig config = CreateIceConfig(1000, false); | 1957 IceConfig config = CreateIceConfig(1000, GATHER_ONCE); |
1925 ep1_ch1()->SetIceConfig(config); | 1958 ep1_ch1()->SetIceConfig(config); |
1926 ep2_ch1()->SetIceConfig(config); | 1959 ep2_ch1()->SetIceConfig(config); |
1927 | 1960 |
1928 // Blackhole any traffic to or from the public addrs. | 1961 // Blackhole any traffic to or from the public addrs. |
1929 LOG(LS_INFO) << "Failing over..."; | 1962 LOG(LS_INFO) << "Failing over..."; |
1930 fw()->AddRule(false, rtc::FP_ANY, rtc::FD_ANY, kPublicAddrs[0]); | 1963 fw()->AddRule(false, rtc::FP_ANY, rtc::FD_ANY, kPublicAddrs[0]); |
1931 // The selected connections will switch, so keep references to them. | 1964 // The selected connections will switch, so keep references to them. |
1932 const Connection* selected_connection1 = ep1_ch1()->selected_connection(); | 1965 const Connection* selected_connection1 = ep1_ch1()->selected_connection(); |
1933 const Connection* selected_connection2 = ep2_ch1()->selected_connection(); | 1966 const Connection* selected_connection2 = ep2_ch1()->selected_connection(); |
1934 // We should detect loss of receiving within 1 second or so. | 1967 // We should detect loss of receiving within 1 second or so. |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1973 1000, 1000); | 2006 1000, 1000); |
1974 // Need to wait to make sure the connections on both networks are writable. | 2007 // Need to wait to make sure the connections on both networks are writable. |
1975 EXPECT_TRUE_WAIT(ep1_ch1()->selected_connection() && | 2008 EXPECT_TRUE_WAIT(ep1_ch1()->selected_connection() && |
1976 LocalCandidate(ep1_ch1())->address().EqualIPs(wifi[0]) && | 2009 LocalCandidate(ep1_ch1())->address().EqualIPs(wifi[0]) && |
1977 RemoteCandidate(ep1_ch1())->address().EqualIPs(wifi[1]), | 2010 RemoteCandidate(ep1_ch1())->address().EqualIPs(wifi[1]), |
1978 1000); | 2011 1000); |
1979 EXPECT_TRUE_WAIT(ep2_ch1()->selected_connection() && | 2012 EXPECT_TRUE_WAIT(ep2_ch1()->selected_connection() && |
1980 LocalCandidate(ep2_ch1())->address().EqualIPs(wifi[1]) && | 2013 LocalCandidate(ep2_ch1())->address().EqualIPs(wifi[1]) && |
1981 RemoteCandidate(ep2_ch1())->address().EqualIPs(wifi[0]), | 2014 RemoteCandidate(ep2_ch1())->address().EqualIPs(wifi[0]), |
1982 1000); | 2015 1000); |
| 2016 DestroyChannels(); |
1983 } | 2017 } |
1984 | 2018 |
1985 // Tests that a Wifi-Cellular connection has higher precedence than | 2019 // Tests that a Wifi-Cellular connection has higher precedence than |
1986 // a Cellular-Cellular connection. | 2020 // a Cellular-Cellular connection. |
1987 TEST_F(P2PTransportChannelMultihomedTest, TestPreferWifiOverCellularNetwork) { | 2021 TEST_F(P2PTransportChannelMultihomedTest, TestPreferWifiOverCellularNetwork) { |
1988 // The interface names are chosen so that |cellular| would have higher | 2022 // The interface names are chosen so that |cellular| would have higher |
1989 // candidate priority if it is not for the network type. | 2023 // candidate priority if it is not for the network type. |
1990 auto& wifi = kAlternateAddrs; | 2024 auto& wifi = kAlternateAddrs; |
1991 auto& cellular = kPublicAddrs; | 2025 auto& cellular = kPublicAddrs; |
1992 AddAddress(0, cellular[0], "test1", rtc::ADAPTER_TYPE_CELLULAR); | 2026 AddAddress(0, cellular[0], "test1", rtc::ADAPTER_TYPE_CELLULAR); |
(...skipping 10 matching lines...) Expand all Loading... |
2003 EXPECT_TRUE_WAIT_MARGIN(ep1_ch1()->receiving() && ep1_ch1()->writable() && | 2037 EXPECT_TRUE_WAIT_MARGIN(ep1_ch1()->receiving() && ep1_ch1()->writable() && |
2004 ep2_ch1()->receiving() && ep2_ch1()->writable(), | 2038 ep2_ch1()->receiving() && ep2_ch1()->writable(), |
2005 1000, 1000); | 2039 1000, 1000); |
2006 // Need to wait to make sure the connections on both networks are writable. | 2040 // Need to wait to make sure the connections on both networks are writable. |
2007 EXPECT_TRUE_WAIT(ep1_ch1()->selected_connection() && | 2041 EXPECT_TRUE_WAIT(ep1_ch1()->selected_connection() && |
2008 RemoteCandidate(ep1_ch1())->address().EqualIPs(wifi[1]), | 2042 RemoteCandidate(ep1_ch1())->address().EqualIPs(wifi[1]), |
2009 1000); | 2043 1000); |
2010 EXPECT_TRUE_WAIT(ep2_ch1()->selected_connection() && | 2044 EXPECT_TRUE_WAIT(ep2_ch1()->selected_connection() && |
2011 LocalCandidate(ep2_ch1())->address().EqualIPs(wifi[1]), | 2045 LocalCandidate(ep2_ch1())->address().EqualIPs(wifi[1]), |
2012 1000); | 2046 1000); |
| 2047 DestroyChannels(); |
2013 } | 2048 } |
2014 | 2049 |
2015 // Test that the backup connection is pinged at a rate no faster than | 2050 // Test that the backup connection is pinged at a rate no faster than |
2016 // what was configured. | 2051 // what was configured. |
2017 TEST_F(P2PTransportChannelMultihomedTest, TestPingBackupConnectionRate) { | 2052 TEST_F(P2PTransportChannelMultihomedTest, TestPingBackupConnectionRate) { |
2018 AddAddress(0, kPublicAddrs[0]); | 2053 AddAddress(0, kPublicAddrs[0]); |
2019 // Adding alternate address will make sure |kPublicAddrs| has the higher | 2054 // Adding alternate address will make sure |kPublicAddrs| has the higher |
2020 // priority than others. This is due to FakeNetwork::AddInterface method. | 2055 // priority than others. This is due to FakeNetwork::AddInterface method. |
2021 AddAddress(1, kAlternateAddrs[1]); | 2056 AddAddress(1, kAlternateAddrs[1]); |
2022 AddAddress(1, kPublicAddrs[1]); | 2057 AddAddress(1, kPublicAddrs[1]); |
2023 | 2058 |
2024 // Use only local ports for simplicity. | 2059 // Use only local ports for simplicity. |
2025 SetAllocatorFlags(0, kOnlyLocalPorts); | 2060 SetAllocatorFlags(0, kOnlyLocalPorts); |
2026 SetAllocatorFlags(1, kOnlyLocalPorts); | 2061 SetAllocatorFlags(1, kOnlyLocalPorts); |
2027 | 2062 |
2028 // Create channels and let them go writable, as usual. | 2063 // Create channels and let them go writable, as usual. |
2029 CreateChannels(1); | 2064 CreateChannels(1); |
2030 EXPECT_TRUE_WAIT_MARGIN(ep1_ch1()->receiving() && ep1_ch1()->writable() && | 2065 EXPECT_TRUE_WAIT_MARGIN(ep1_ch1()->receiving() && ep1_ch1()->writable() && |
2031 ep2_ch1()->receiving() && ep2_ch1()->writable(), | 2066 ep2_ch1()->receiving() && ep2_ch1()->writable(), |
2032 1000, 1000); | 2067 1000, 1000); |
2033 int backup_ping_interval = 2000; | 2068 int backup_ping_interval = 2000; |
2034 ep2_ch1()->SetIceConfig(CreateIceConfig(2000, false, backup_ping_interval)); | 2069 ep2_ch1()->SetIceConfig( |
| 2070 CreateIceConfig(2000, GATHER_ONCE, backup_ping_interval)); |
2035 // After the state becomes COMPLETED, the backup connection will be pinged | 2071 // After the state becomes COMPLETED, the backup connection will be pinged |
2036 // once every |backup_ping_interval| milliseconds. | 2072 // once every |backup_ping_interval| milliseconds. |
2037 ASSERT_TRUE_WAIT(ep2_ch1()->GetState() == STATE_COMPLETED, 1000); | 2073 ASSERT_TRUE_WAIT(ep2_ch1()->GetState() == STATE_COMPLETED, 1000); |
2038 const std::vector<Connection*>& connections = ep2_ch1()->connections(); | 2074 const std::vector<Connection*>& connections = ep2_ch1()->connections(); |
2039 ASSERT_EQ(2U, connections.size()); | 2075 ASSERT_EQ(2U, connections.size()); |
2040 Connection* backup_conn = connections[1]; | 2076 Connection* backup_conn = connections[1]; |
2041 EXPECT_TRUE_WAIT(backup_conn->writable(), 3000); | 2077 EXPECT_TRUE_WAIT(backup_conn->writable(), 3000); |
2042 int64_t last_ping_response_ms = backup_conn->last_ping_response_received(); | 2078 int64_t last_ping_response_ms = backup_conn->last_ping_response_received(); |
2043 EXPECT_TRUE_WAIT( | 2079 EXPECT_TRUE_WAIT( |
2044 last_ping_response_ms < backup_conn->last_ping_response_received(), 5000); | 2080 last_ping_response_ms < backup_conn->last_ping_response_received(), 5000); |
2045 int time_elapsed = | 2081 int time_elapsed = |
2046 backup_conn->last_ping_response_received() - last_ping_response_ms; | 2082 backup_conn->last_ping_response_received() - last_ping_response_ms; |
2047 LOG(LS_INFO) << "Time elapsed: " << time_elapsed; | 2083 LOG(LS_INFO) << "Time elapsed: " << time_elapsed; |
2048 EXPECT_GE(time_elapsed, backup_ping_interval); | 2084 EXPECT_GE(time_elapsed, backup_ping_interval); |
| 2085 |
| 2086 DestroyChannels(); |
2049 } | 2087 } |
2050 | 2088 |
2051 TEST_F(P2PTransportChannelMultihomedTest, TestGetState) { | 2089 TEST_F(P2PTransportChannelMultihomedTest, TestGetState) { |
2052 AddAddress(0, kAlternateAddrs[0]); | 2090 AddAddress(0, kAlternateAddrs[0]); |
2053 AddAddress(0, kPublicAddrs[0]); | 2091 AddAddress(0, kPublicAddrs[0]); |
2054 AddAddress(1, kPublicAddrs[1]); | 2092 AddAddress(1, kPublicAddrs[1]); |
2055 // Create channels and let them go writable, as usual. | 2093 // Create channels and let them go writable, as usual. |
2056 CreateChannels(1); | 2094 CreateChannels(1); |
2057 | 2095 |
2058 // Both transport channels will reach STATE_COMPLETED quickly. | 2096 // Both transport channels will reach STATE_COMPLETED quickly. |
2059 EXPECT_EQ_WAIT(TransportChannelState::STATE_COMPLETED, ep1_ch1()->GetState(), | 2097 EXPECT_EQ_WAIT(TransportChannelState::STATE_COMPLETED, ep1_ch1()->GetState(), |
2060 1000); | 2098 1000); |
2061 EXPECT_EQ_WAIT(TransportChannelState::STATE_COMPLETED, ep2_ch1()->GetState(), | 2099 EXPECT_EQ_WAIT(TransportChannelState::STATE_COMPLETED, ep2_ch1()->GetState(), |
2062 1000); | 2100 1000); |
2063 } | 2101 } |
2064 | 2102 |
2065 // Tests that when a network interface becomes inactive, if and only if | 2103 // Tests that when a network interface becomes inactive, if Continual Gathering |
2066 // Continual Gathering is enabled, the ports associated with that network | 2104 // policy is GATHER_CONTINUALLY, the ports associated with that network |
2067 // will be removed from the port list of the channel, and the respective | 2105 // will be removed from the port list of the channel, and the respective |
2068 // remote candidates on the other participant will be removed eventually. | 2106 // remote candidates on the other participant will be removed eventually. |
2069 TEST_F(P2PTransportChannelMultihomedTest, TestNetworkBecomesInactive) { | 2107 TEST_F(P2PTransportChannelMultihomedTest, TestNetworkBecomesInactive) { |
| 2108 rtc::ScopedFakeClock clock; |
2070 AddAddress(0, kPublicAddrs[0]); | 2109 AddAddress(0, kPublicAddrs[0]); |
2071 AddAddress(1, kPublicAddrs[1]); | 2110 AddAddress(1, kPublicAddrs[1]); |
2072 // Create channels and let them go writable, as usual. | 2111 // Create channels and let them go writable, as usual. |
2073 CreateChannels(1); | 2112 CreateChannels(1); |
2074 ep1_ch1()->SetIceConfig(CreateIceConfig(2000, true)); | 2113 ep1_ch1()->SetIceConfig(CreateIceConfig(2000, GATHER_CONTINUALLY)); |
2075 ep2_ch1()->SetIceConfig(CreateIceConfig(2000, false)); | 2114 ep2_ch1()->SetIceConfig(CreateIceConfig(2000, GATHER_ONCE)); |
2076 | 2115 |
2077 SetAllocatorFlags(0, kOnlyLocalPorts); | 2116 SetAllocatorFlags(0, kOnlyLocalPorts); |
2078 SetAllocatorFlags(1, kOnlyLocalPorts); | 2117 SetAllocatorFlags(1, kOnlyLocalPorts); |
2079 EXPECT_TRUE_WAIT_MARGIN(ep1_ch1()->receiving() && ep1_ch1()->writable() && | 2118 EXPECT_TRUE_SIMULATED_WAIT(ep1_ch1()->receiving() && ep1_ch1()->writable() && |
2080 ep2_ch1()->receiving() && ep2_ch1()->writable(), | 2119 ep2_ch1()->receiving() && |
2081 1000, 1000); | 2120 ep2_ch1()->writable(), |
| 2121 kDefaultTimeout, clock); |
2082 // More than one port has been created. | 2122 // More than one port has been created. |
2083 EXPECT_LE(1U, ep1_ch1()->ports().size()); | 2123 EXPECT_LE(1U, ep1_ch1()->ports().size()); |
2084 // Endpoint 1 enabled continual gathering; the port will be removed | 2124 // Endpoint 1 enabled continual gathering; the port will be removed |
2085 // when the interface is removed. | 2125 // when the interface is removed. |
2086 RemoveAddress(0, kPublicAddrs[0]); | 2126 RemoveAddress(0, kPublicAddrs[0]); |
2087 EXPECT_TRUE(ep1_ch1()->ports().empty()); | 2127 EXPECT_TRUE(ep1_ch1()->ports().empty()); |
2088 // The remote candidates will be removed eventually. | 2128 // The remote candidates will be removed eventually. |
2089 EXPECT_TRUE_WAIT(ep2_ch1()->remote_candidates().empty(), 1000); | 2129 EXPECT_TRUE_SIMULATED_WAIT(ep2_ch1()->remote_candidates().empty(), 1000, |
| 2130 clock); |
2090 | 2131 |
2091 size_t num_ports = ep2_ch1()->ports().size(); | 2132 size_t num_ports = ep2_ch1()->ports().size(); |
2092 EXPECT_LE(1U, num_ports); | 2133 EXPECT_LE(1U, num_ports); |
2093 size_t num_remote_candidates = ep1_ch1()->remote_candidates().size(); | 2134 size_t num_remote_candidates = ep1_ch1()->remote_candidates().size(); |
2094 // Endpoint 2 did not enable continual gathering; the port will not be removed | 2135 // Endpoint 2 did not enable continual gathering; the local port will still be |
2095 // when the interface is removed and neither the remote candidates on the | 2136 // removed when the interface is removed but the remote candidates on the |
2096 // other participant. | 2137 // other participant will not be removed. |
2097 RemoveAddress(1, kPublicAddrs[1]); | 2138 RemoveAddress(1, kPublicAddrs[1]); |
2098 rtc::Thread::Current()->ProcessMessages(500); | 2139 |
2099 EXPECT_EQ(num_ports, ep2_ch1()->ports().size()); | 2140 EXPECT_EQ_SIMULATED_WAIT(0U, ep2_ch1()->ports().size(), kDefaultTimeout, |
| 2141 clock); |
| 2142 SIMULATED_WAIT(0U == ep1_ch1()->remote_candidates().size(), 500, clock); |
2100 EXPECT_EQ(num_remote_candidates, ep1_ch1()->remote_candidates().size()); | 2143 EXPECT_EQ(num_remote_candidates, ep1_ch1()->remote_candidates().size()); |
| 2144 |
| 2145 DestroyChannels(); |
2101 } | 2146 } |
2102 | 2147 |
2103 /* | 2148 // Tests that continual gathering will create new connections when a new |
| 2149 // interface is added. |
| 2150 TEST_F(P2PTransportChannelMultihomedTest, |
| 2151 TestContinualGatheringOnNewInterface) { |
| 2152 auto& wifi = kAlternateAddrs; |
| 2153 auto& cellular = kPublicAddrs; |
| 2154 AddAddress(0, wifi[0], "test_wifi0", rtc::ADAPTER_TYPE_WIFI); |
| 2155 AddAddress(1, cellular[1], "test_cell1", rtc::ADAPTER_TYPE_CELLULAR); |
| 2156 CreateChannels(1); |
| 2157 // Set continual gathering policy. |
| 2158 ep1_ch1()->SetIceConfig(CreateIceConfig(1000, GATHER_CONTINUALLY)); |
| 2159 ep2_ch1()->SetIceConfig(CreateIceConfig(1000, GATHER_CONTINUALLY)); |
| 2160 SetAllocatorFlags(0, kOnlyLocalPorts); |
| 2161 SetAllocatorFlags(1, kOnlyLocalPorts); |
| 2162 EXPECT_TRUE_WAIT_MARGIN(ep1_ch1()->receiving() && ep1_ch1()->writable() && |
| 2163 ep2_ch1()->receiving() && ep2_ch1()->writable(), |
| 2164 kDefaultTimeout, kDefaultTimeout); |
2104 | 2165 |
2105 TODO(pthatcher): Once have a way to handle network interfaces changes | 2166 // Add a new wifi interface on end point 2. We should expect a new connection |
2106 without signalling an ICE restart, put a test like this back. In the | 2167 // to be created and the new one will be the best connection. |
2107 mean time, this test only worked for GICE. With ICE, it's currently | 2168 AddAddress(1, wifi[1], "test_wifi1", rtc::ADAPTER_TYPE_WIFI); |
2108 not possible without an ICE restart. | 2169 const cricket::Connection* conn; |
| 2170 EXPECT_TRUE_WAIT((conn = ep1_ch1()->best_connection()) != nullptr && |
| 2171 conn->remote_candidate().address().EqualIPs(wifi[1]), |
| 2172 kDefaultTimeout); |
| 2173 EXPECT_TRUE_WAIT((conn = ep2_ch1()->best_connection()) != nullptr && |
| 2174 conn->local_candidate().address().EqualIPs(wifi[1]), |
| 2175 kDefaultTimeout); |
2109 | 2176 |
2110 // Test that we can switch links in a coordinated fashion. | 2177 // Add a new cellular interface on end point 1, we should expect a new |
2111 TEST_F(P2PTransportChannelMultihomedTest, TestDrain) { | 2178 // backup connection created using this new interface. |
| 2179 AddAddress(0, cellular[0], "test_cellular0", rtc::ADAPTER_TYPE_CELLULAR); |
| 2180 EXPECT_TRUE_WAIT( |
| 2181 ep1_ch1()->GetState() == cricket::STATE_COMPLETED && |
| 2182 (conn = GetConnectionWithLocalAddress(ep1_ch1(), cellular[0])) && |
| 2183 conn != ep1_ch1()->best_connection() && conn->writable(), |
| 2184 kDefaultTimeout); |
| 2185 EXPECT_TRUE_WAIT( |
| 2186 ep2_ch1()->GetState() == cricket::STATE_COMPLETED && |
| 2187 (conn = GetConnectionWithRemoteAddress(ep2_ch1(), cellular[0])) && |
| 2188 conn != ep2_ch1()->best_connection() && conn->receiving(), |
| 2189 kDefaultTimeout); |
| 2190 |
| 2191 DestroyChannels(); |
| 2192 } |
| 2193 |
| 2194 // Tests that we can switch links via continual gathering. |
| 2195 TEST_F(P2PTransportChannelMultihomedTest, |
| 2196 TestSwitchLinksViaContinualGathering) { |
| 2197 rtc::ScopedFakeClock clock; |
2112 AddAddress(0, kPublicAddrs[0]); | 2198 AddAddress(0, kPublicAddrs[0]); |
2113 AddAddress(1, kPublicAddrs[1]); | 2199 AddAddress(1, kPublicAddrs[1]); |
2114 // Use only local ports for simplicity. | 2200 // Use only local ports for simplicity. |
2115 SetAllocatorFlags(0, kOnlyLocalPorts); | 2201 SetAllocatorFlags(0, kOnlyLocalPorts); |
2116 SetAllocatorFlags(1, kOnlyLocalPorts); | 2202 SetAllocatorFlags(1, kOnlyLocalPorts); |
2117 | 2203 |
2118 // Create channels and let them go writable, as usual. | 2204 // Create channels and let them go writable, as usual. |
2119 CreateChannels(1); | 2205 CreateChannels(1); |
2120 EXPECT_TRUE_WAIT(ep1_ch1()->receiving() && ep1_ch1()->writable() && | 2206 // Set continual gathering policy. |
2121 ep2_ch1()->receiving() && ep2_ch1()->writable(), | 2207 ep1_ch1()->SetIceConfig(CreateIceConfig(1000, GATHER_CONTINUALLY)); |
2122 1000); | 2208 ep2_ch1()->SetIceConfig(CreateIceConfig(1000, GATHER_CONTINUALLY)); |
| 2209 EXPECT_TRUE_SIMULATED_WAIT(ep1_ch1()->receiving() && ep1_ch1()->writable() && |
| 2210 ep2_ch1()->receiving() && |
| 2211 ep2_ch1()->writable(), |
| 2212 3000, clock); |
2123 EXPECT_TRUE( | 2213 EXPECT_TRUE( |
2124 ep1_ch1()->selected_connection() && ep2_ch1()->selected_connection() && | 2214 ep1_ch1()->selected_connection() && ep2_ch1()->selected_connection() && |
2125 LocalCandidate(ep1_ch1())->address().EqualIPs(kPublicAddrs[0]) && | 2215 LocalCandidate(ep1_ch1())->address().EqualIPs(kPublicAddrs[0]) && |
2126 RemoteCandidate(ep1_ch1())->address().EqualIPs(kPublicAddrs[1])); | 2216 RemoteCandidate(ep1_ch1())->address().EqualIPs(kPublicAddrs[1])); |
2127 | 2217 |
2128 | 2218 // Add the new address first and then remove the other one. |
2129 // Remove the public interface, add the alternate interface, and allocate | |
2130 // a new generation of candidates for the new interface (via | |
2131 // MaybeStartGathering()). | |
2132 LOG(LS_INFO) << "Draining..."; | 2219 LOG(LS_INFO) << "Draining..."; |
2133 AddAddress(1, kAlternateAddrs[1]); | 2220 AddAddress(1, kAlternateAddrs[1]); |
2134 RemoveAddress(1, kPublicAddrs[1]); | 2221 RemoveAddress(1, kPublicAddrs[1]); |
2135 ep2_ch1()->MaybeStartGathering(); | 2222 // We should switch to use the alternate address after an exchange of pings. |
| 2223 EXPECT_TRUE_SIMULATED_WAIT( |
| 2224 ep1_ch1()->selected_connection() && ep2_ch1()->selected_connection() && |
| 2225 LocalCandidate(ep1_ch1())->address().EqualIPs(kPublicAddrs[0]) && |
| 2226 RemoteCandidate(ep1_ch1())->address().EqualIPs(kAlternateAddrs[1]), |
| 2227 3000, clock); |
2136 | 2228 |
2137 // We should switch over to use the alternate address after | 2229 // Remove one address first and then add another address. |
2138 // an exchange of pings. | 2230 LOG(LS_INFO) << "Draining again..."; |
2139 EXPECT_TRUE_WAIT( | 2231 RemoveAddress(1, kAlternateAddrs[1]); |
2140 ep1_ch1()->selected_connection() && ep2_ch1()->selected_connection() && | 2232 AddAddress(1, kAlternateAddrs[0]); |
2141 LocalCandidate(ep1_ch1())->address().EqualIPs(kPublicAddrs[0]) && | 2233 EXPECT_TRUE_SIMULATED_WAIT( |
2142 RemoteCandidate(ep1_ch1())->address().EqualIPs(kAlternateAddrs[1]), | 2234 ep1_ch1()->best_connection() && ep2_ch1()->best_connection() && |
2143 3000); | 2235 LocalCandidate(ep1_ch1())->address().EqualIPs(kPublicAddrs[0]) && |
| 2236 RemoteCandidate(ep1_ch1())->address().EqualIPs(kAlternateAddrs[0]), |
| 2237 3000, clock); |
2144 | 2238 |
2145 DestroyChannels(); | 2239 DestroyChannels(); |
2146 } | 2240 } |
2147 | 2241 |
| 2242 /* |
| 2243 TODO(honghaiz) Once continual gathering fully supports |
| 2244 GATHER_CONTINUALLY_AND_RECOVER, put this test back. |
| 2245 |
| 2246 // Tests that if the backup connections are lost and then the interface with the |
| 2247 // selected connection is gone, continual gathering will restore the |
| 2248 // connectivity. |
| 2249 TEST_F(P2PTransportChannelMultihomedTest, |
| 2250 TestBackupConnectionLostThenInterfaceGone) { |
| 2251 rtc::ScopedFakeClock clock; |
| 2252 auto& wifi = kAlternateAddrs; |
| 2253 auto& cellular = kPublicAddrs; |
| 2254 AddAddress(0, wifi[0], "test_wifi0", rtc::ADAPTER_TYPE_WIFI); |
| 2255 AddAddress(0, cellular[0], "test_cell0", rtc::ADAPTER_TYPE_CELLULAR); |
| 2256 AddAddress(1, wifi[1], "test_wifi1", rtc::ADAPTER_TYPE_WIFI); |
| 2257 AddAddress(1, cellular[1], "test_cell1", rtc::ADAPTER_TYPE_CELLULAR); |
| 2258 // Use only local ports for simplicity. |
| 2259 SetAllocatorFlags(0, kOnlyLocalPorts); |
| 2260 SetAllocatorFlags(1, kOnlyLocalPorts); |
| 2261 |
| 2262 // Create channels and let them go writable, as usual. |
| 2263 CreateChannels(1); |
| 2264 // Set continual gathering policy. |
| 2265 IceConfig config = CreateIceConfig(1000, GATHER_CONTINUALLY_AND_RECOVER); |
| 2266 ep1_ch1()->SetIceConfig(config); |
| 2267 ep2_ch1()->SetIceConfig(config); |
| 2268 EXPECT_TRUE_SIMULATED_WAIT(ep1_ch1()->receiving() && ep1_ch1()->writable() && |
| 2269 ep2_ch1()->receiving() && ep2_ch1()->writable(), |
| 2270 3000, clock); |
| 2271 EXPECT_TRUE(ep1_ch1()->best_connection() && ep2_ch1()->best_connection() && |
| 2272 LocalCandidate(ep1_ch1())->address().EqualIPs(wifi[0]) && |
| 2273 RemoteCandidate(ep1_ch1())->address().EqualIPs(wifi[1])); |
| 2274 |
| 2275 // First destroy all backup connection. |
| 2276 DestroyAllButBestConnection(ep1_ch1()); |
| 2277 |
| 2278 SIMULATED_WAIT(false, 10, clock); |
| 2279 // Then the interface of the best connection goes away. |
| 2280 RemoveAddress(0, wifi[0]); |
| 2281 EXPECT_TRUE_SIMULATED_WAIT( |
| 2282 ep1_ch1()->best_connection() && ep2_ch1()->best_connection() && |
| 2283 LocalCandidate(ep1_ch1())->address().EqualIPs(cellular[0]) && |
| 2284 RemoteCandidate(ep1_ch1())->address().EqualIPs(wifi[1]), |
| 2285 3000, clock); |
| 2286 |
| 2287 DestroyChannels(); |
| 2288 } |
2148 */ | 2289 */ |
2149 | 2290 |
| 2291 // Tests that the backup connection will be restored after it is destroyed. |
| 2292 TEST_F(P2PTransportChannelMultihomedTest, TestRestoreBackupConnection) { |
| 2293 rtc::ScopedFakeClock clock; |
| 2294 auto& wifi = kAlternateAddrs; |
| 2295 auto& cellular = kPublicAddrs; |
| 2296 AddAddress(0, wifi[0], "test_wifi0", rtc::ADAPTER_TYPE_WIFI); |
| 2297 AddAddress(0, cellular[0], "test_cell0", rtc::ADAPTER_TYPE_CELLULAR); |
| 2298 AddAddress(1, wifi[1], "test_wifi1", rtc::ADAPTER_TYPE_WIFI); |
| 2299 AddAddress(1, cellular[1], "test_cell1", rtc::ADAPTER_TYPE_CELLULAR); |
| 2300 // Use only local ports for simplicity. |
| 2301 SetAllocatorFlags(0, kOnlyLocalPorts); |
| 2302 SetAllocatorFlags(1, kOnlyLocalPorts); |
| 2303 |
| 2304 // Create channels and let them go writable, as usual. |
| 2305 CreateChannels(1); |
| 2306 IceConfig config = CreateIceConfig(1000, GATHER_CONTINUALLY); |
| 2307 config.regather_on_failed_networks_interval = rtc::Optional<int>(2000); |
| 2308 ep1_ch1()->SetIceConfig(config); |
| 2309 ep2_ch1()->SetIceConfig(config); |
| 2310 EXPECT_TRUE_SIMULATED_WAIT(ep1_ch1()->receiving() && ep1_ch1()->writable() && |
| 2311 ep2_ch1()->receiving() && |
| 2312 ep2_ch1()->writable(), |
| 2313 3000, clock); |
| 2314 EXPECT_TRUE(ep1_ch1()->best_connection() && ep2_ch1()->best_connection() && |
| 2315 LocalCandidate(ep1_ch1())->address().EqualIPs(wifi[0]) && |
| 2316 RemoteCandidate(ep1_ch1())->address().EqualIPs(wifi[1])); |
| 2317 |
| 2318 // Destroy all backup connections. |
| 2319 DestroyAllButBestConnection(ep1_ch1()); |
| 2320 // Ensure the backup connection is removed first. |
| 2321 EXPECT_TRUE_SIMULATED_WAIT( |
| 2322 GetConnectionWithLocalAddress(ep1_ch1(), cellular[0]) == nullptr, |
| 2323 kDefaultTimeout, clock); |
| 2324 const cricket::Connection* conn; |
| 2325 EXPECT_TRUE_SIMULATED_WAIT( |
| 2326 (conn = GetConnectionWithLocalAddress(ep1_ch1(), cellular[0])) && |
| 2327 conn != ep1_ch1()->best_connection() && conn->writable(), |
| 2328 5000, clock); |
| 2329 |
| 2330 DestroyChannels(); |
| 2331 } |
| 2332 |
2150 // A collection of tests which tests a single P2PTransportChannel by sending | 2333 // A collection of tests which tests a single P2PTransportChannel by sending |
2151 // pings. | 2334 // pings. |
2152 class P2PTransportChannelPingTest : public testing::Test, | 2335 class P2PTransportChannelPingTest : public testing::Test, |
2153 public sigslot::has_slots<> { | 2336 public sigslot::has_slots<> { |
2154 public: | 2337 public: |
2155 P2PTransportChannelPingTest() | 2338 P2PTransportChannelPingTest() |
2156 : pss_(new rtc::PhysicalSocketServer), | 2339 : pss_(new rtc::PhysicalSocketServer), |
2157 vss_(new rtc::VirtualSocketServer(pss_.get())), | 2340 vss_(new rtc::VirtualSocketServer(pss_.get())), |
2158 ss_scope_(vss_.get()) {} | 2341 ss_scope_(vss_.get()) {} |
2159 | 2342 |
(...skipping 436 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2596 } | 2779 } |
2597 | 2780 |
2598 TEST_F(P2PTransportChannelPingTest, TestReceivingStateChange) { | 2781 TEST_F(P2PTransportChannelPingTest, TestReceivingStateChange) { |
2599 FakePortAllocator pa(rtc::Thread::Current(), nullptr); | 2782 FakePortAllocator pa(rtc::Thread::Current(), nullptr); |
2600 P2PTransportChannel ch("receiving state change", 1, &pa); | 2783 P2PTransportChannel ch("receiving state change", 1, &pa); |
2601 PrepareChannel(&ch); | 2784 PrepareChannel(&ch); |
2602 // Default receiving timeout and checking receiving interval should not be too | 2785 // Default receiving timeout and checking receiving interval should not be too |
2603 // small. | 2786 // small. |
2604 EXPECT_LE(1000, ch.receiving_timeout()); | 2787 EXPECT_LE(1000, ch.receiving_timeout()); |
2605 EXPECT_LE(200, ch.check_receiving_interval()); | 2788 EXPECT_LE(200, ch.check_receiving_interval()); |
2606 ch.SetIceConfig(CreateIceConfig(500, false)); | 2789 ch.SetIceConfig(CreateIceConfig(500, GATHER_ONCE)); |
2607 EXPECT_EQ(500, ch.receiving_timeout()); | 2790 EXPECT_EQ(500, ch.receiving_timeout()); |
2608 EXPECT_EQ(50, ch.check_receiving_interval()); | 2791 EXPECT_EQ(50, ch.check_receiving_interval()); |
2609 ch.Connect(); | 2792 ch.Connect(); |
2610 ch.MaybeStartGathering(); | 2793 ch.MaybeStartGathering(); |
2611 ch.AddRemoteCandidate(CreateUdpCandidate(LOCAL_PORT_TYPE, "1.1.1.1", 1, 1)); | 2794 ch.AddRemoteCandidate(CreateUdpCandidate(LOCAL_PORT_TYPE, "1.1.1.1", 1, 1)); |
2612 Connection* conn1 = WaitForConnectionTo(&ch, "1.1.1.1", 1); | 2795 Connection* conn1 = WaitForConnectionTo(&ch, "1.1.1.1", 1); |
2613 ASSERT_TRUE(conn1 != nullptr); | 2796 ASSERT_TRUE(conn1 != nullptr); |
2614 | 2797 |
2615 conn1->ReceivedPing(); | 2798 conn1->ReceivedPing(); |
2616 conn1->OnReadPacket("ABC", 3, rtc::CreatePacketTime(0)); | 2799 conn1->OnReadPacket("ABC", 3, rtc::CreatePacketTime(0)); |
(...skipping 402 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3019 // When a higher-priority, nominated candidate comes in, the connections with | 3202 // When a higher-priority, nominated candidate comes in, the connections with |
3020 // lower-priority are pruned. | 3203 // lower-priority are pruned. |
3021 ch.AddRemoteCandidate(CreateUdpCandidate(LOCAL_PORT_TYPE, "2.2.2.2", 2, 10)); | 3204 ch.AddRemoteCandidate(CreateUdpCandidate(LOCAL_PORT_TYPE, "2.2.2.2", 2, 10)); |
3022 Connection* conn2 = WaitForConnectionTo(&ch, "2.2.2.2", 2); | 3205 Connection* conn2 = WaitForConnectionTo(&ch, "2.2.2.2", 2); |
3023 ASSERT_TRUE(conn2 != nullptr); | 3206 ASSERT_TRUE(conn2 != nullptr); |
3024 conn2->ReceivedPingResponse(LOW_RTT); // Becomes writable and receiving | 3207 conn2->ReceivedPingResponse(LOW_RTT); // Becomes writable and receiving |
3025 conn2->set_nominated(true); | 3208 conn2->set_nominated(true); |
3026 conn2->SignalNominated(conn2); | 3209 conn2->SignalNominated(conn2); |
3027 EXPECT_TRUE_WAIT(conn1->pruned(), 3000); | 3210 EXPECT_TRUE_WAIT(conn1->pruned(), 3000); |
3028 | 3211 |
3029 ch.SetIceConfig(CreateIceConfig(500, false)); | 3212 ch.SetIceConfig(CreateIceConfig(500, GATHER_ONCE)); |
3030 // Wait until conn2 becomes not receiving. | 3213 // Wait until conn2 becomes not receiving. |
3031 EXPECT_TRUE_WAIT(!conn2->receiving(), 3000); | 3214 EXPECT_TRUE_WAIT(!conn2->receiving(), 3000); |
3032 | 3215 |
3033 ch.AddRemoteCandidate(CreateUdpCandidate(LOCAL_PORT_TYPE, "3.3.3.3", 3, 1)); | 3216 ch.AddRemoteCandidate(CreateUdpCandidate(LOCAL_PORT_TYPE, "3.3.3.3", 3, 1)); |
3034 Connection* conn3 = WaitForConnectionTo(&ch, "3.3.3.3", 3); | 3217 Connection* conn3 = WaitForConnectionTo(&ch, "3.3.3.3", 3); |
3035 ASSERT_TRUE(conn3 != nullptr); | 3218 ASSERT_TRUE(conn3 != nullptr); |
3036 // The selected connection should still be conn2. Even through conn3 has lower | 3219 // The selected connection should still be conn2. Even through conn3 has lower |
3037 // priority and is not receiving/writable, it is not pruned because the | 3220 // priority and is not receiving/writable, it is not pruned because the |
3038 // selected connection is not receiving. | 3221 // selected connection is not receiving. |
3039 WAIT(conn3->pruned(), 1000); | 3222 WAIT(conn3->pruned(), 1000); |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3087 // Need to wait until the channel state is updated. | 3270 // Need to wait until the channel state is updated. |
3088 EXPECT_EQ_WAIT(TransportChannelState::STATE_FAILED, ch.GetState(), 1000); | 3271 EXPECT_EQ_WAIT(TransportChannelState::STATE_FAILED, ch.GetState(), 1000); |
3089 } | 3272 } |
3090 | 3273 |
3091 // Test that when a low-priority connection is pruned, it is not deleted | 3274 // Test that when a low-priority connection is pruned, it is not deleted |
3092 // right away, and it can become active and be pruned again. | 3275 // right away, and it can become active and be pruned again. |
3093 TEST_F(P2PTransportChannelPingTest, TestConnectionPrunedAgain) { | 3276 TEST_F(P2PTransportChannelPingTest, TestConnectionPrunedAgain) { |
3094 FakePortAllocator pa(rtc::Thread::Current(), nullptr); | 3277 FakePortAllocator pa(rtc::Thread::Current(), nullptr); |
3095 P2PTransportChannel ch("test channel", 1, &pa); | 3278 P2PTransportChannel ch("test channel", 1, &pa); |
3096 PrepareChannel(&ch); | 3279 PrepareChannel(&ch); |
3097 ch.SetIceConfig(CreateIceConfig(1000, false)); | 3280 ch.SetIceConfig(CreateIceConfig(1000, GATHER_ONCE)); |
3098 ch.Connect(); | 3281 ch.Connect(); |
3099 ch.MaybeStartGathering(); | 3282 ch.MaybeStartGathering(); |
3100 ch.AddRemoteCandidate(CreateUdpCandidate(LOCAL_PORT_TYPE, "1.1.1.1", 1, 100)); | 3283 ch.AddRemoteCandidate(CreateUdpCandidate(LOCAL_PORT_TYPE, "1.1.1.1", 1, 100)); |
3101 Connection* conn1 = WaitForConnectionTo(&ch, "1.1.1.1", 1); | 3284 Connection* conn1 = WaitForConnectionTo(&ch, "1.1.1.1", 1); |
3102 ASSERT_TRUE(conn1 != nullptr); | 3285 ASSERT_TRUE(conn1 != nullptr); |
3103 EXPECT_EQ(conn1, ch.selected_connection()); | 3286 EXPECT_EQ(conn1, ch.selected_connection()); |
3104 conn1->ReceivedPingResponse(LOW_RTT); // Becomes writable and receiving | 3287 conn1->ReceivedPingResponse(LOW_RTT); // Becomes writable and receiving |
3105 | 3288 |
3106 // Add a low-priority connection |conn2|, which will be pruned, but it will | 3289 // Add a low-priority connection |conn2|, which will be pruned, but it will |
3107 // not be deleted right away. Once the current selected connection becomes not | 3290 // not be deleted right away. Once the current selected connection becomes not |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3163 } | 3346 } |
3164 | 3347 |
3165 // Tests that after a port allocator session is started, it will be stopped | 3348 // Tests that after a port allocator session is started, it will be stopped |
3166 // when a new connection becomes writable and receiving. Also tests that if a | 3349 // when a new connection becomes writable and receiving. Also tests that if a |
3167 // connection belonging to an old session becomes writable, it won't stop | 3350 // connection belonging to an old session becomes writable, it won't stop |
3168 // the current port allocator session. | 3351 // the current port allocator session. |
3169 TEST_F(P2PTransportChannelPingTest, TestStopPortAllocatorSessions) { | 3352 TEST_F(P2PTransportChannelPingTest, TestStopPortAllocatorSessions) { |
3170 FakePortAllocator pa(rtc::Thread::Current(), nullptr); | 3353 FakePortAllocator pa(rtc::Thread::Current(), nullptr); |
3171 P2PTransportChannel ch("test channel", 1, &pa); | 3354 P2PTransportChannel ch("test channel", 1, &pa); |
3172 PrepareChannel(&ch); | 3355 PrepareChannel(&ch); |
3173 ch.SetIceConfig(CreateIceConfig(2000, false)); | 3356 ch.SetIceConfig(CreateIceConfig(2000, GATHER_ONCE)); |
3174 ch.Connect(); | 3357 ch.Connect(); |
3175 ch.MaybeStartGathering(); | 3358 ch.MaybeStartGathering(); |
3176 ch.AddRemoteCandidate(CreateUdpCandidate(LOCAL_PORT_TYPE, "1.1.1.1", 1, 100)); | 3359 ch.AddRemoteCandidate(CreateUdpCandidate(LOCAL_PORT_TYPE, "1.1.1.1", 1, 100)); |
3177 Connection* conn1 = WaitForConnectionTo(&ch, "1.1.1.1", 1); | 3360 Connection* conn1 = WaitForConnectionTo(&ch, "1.1.1.1", 1); |
3178 ASSERT_TRUE(conn1 != nullptr); | 3361 ASSERT_TRUE(conn1 != nullptr); |
3179 conn1->ReceivedPingResponse(LOW_RTT); // Becomes writable and receiving | 3362 conn1->ReceivedPingResponse(LOW_RTT); // Becomes writable and receiving |
3180 EXPECT_TRUE(!ch.allocator_session()->IsGettingPorts()); | 3363 EXPECT_TRUE(!ch.allocator_session()->IsGettingPorts()); |
3181 | 3364 |
3182 // Start a new session. Even though conn1, which belongs to an older | 3365 // Start a new session. Even though conn1, which belongs to an older |
3183 // session, becomes unwritable and writable again, it should not stop the | 3366 // session, becomes unwritable and writable again, it should not stop the |
3184 // current session. | 3367 // current session. |
3185 ch.SetIceCredentials(kIceUfrag[1], kIcePwd[1]); | 3368 ch.SetIceCredentials(kIceUfrag[1], kIcePwd[1]); |
3186 ch.MaybeStartGathering(); | 3369 ch.MaybeStartGathering(); |
3187 conn1->Prune(); | 3370 conn1->Prune(); |
3188 conn1->ReceivedPingResponse(LOW_RTT); | 3371 conn1->ReceivedPingResponse(LOW_RTT); |
3189 EXPECT_TRUE(ch.allocator_session()->IsGettingPorts()); | 3372 EXPECT_TRUE(ch.allocator_session()->IsGettingPorts()); |
3190 | 3373 |
3191 // But if a new connection created from the new session becomes writable, | 3374 // But if a new connection created from the new session becomes writable, |
3192 // it will stop the current session. | 3375 // it will stop the current session. |
3193 ch.AddRemoteCandidate(CreateUdpCandidate(LOCAL_PORT_TYPE, "2.2.2.2", 2, 100)); | 3376 ch.AddRemoteCandidate(CreateUdpCandidate(LOCAL_PORT_TYPE, "2.2.2.2", 2, 100)); |
3194 Connection* conn2 = WaitForConnectionTo(&ch, "2.2.2.2", 2); | 3377 Connection* conn2 = WaitForConnectionTo(&ch, "2.2.2.2", 2); |
3195 ASSERT_TRUE(conn2 != nullptr); | 3378 ASSERT_TRUE(conn2 != nullptr); |
3196 conn2->ReceivedPingResponse(LOW_RTT); // Becomes writable and receiving | 3379 conn2->ReceivedPingResponse(LOW_RTT); // Becomes writable and receiving |
3197 EXPECT_TRUE(!ch.allocator_session()->IsGettingPorts()); | 3380 EXPECT_TRUE(!ch.allocator_session()->IsGettingPorts()); |
3198 } | 3381 } |
3199 | 3382 |
3200 // Test that the ICE role is updated even on ports with inactive networks when | 3383 // Test that the ICE role is updated even on ports that has been removed. |
3201 // doing continual gathering. These ports may still have connections that need | 3384 // These ports may still have connections that need a correct role, in case that |
3202 // a correct role, in case the network becomes active before the connection is | 3385 // the connections on it may still receive stun pings. |
3203 // destroyed. | 3386 TEST_F(P2PTransportChannelPingTest, TestIceRoleUpdatedOnRemovedPort) { |
3204 TEST_F(P2PTransportChannelPingTest, | |
3205 TestIceRoleUpdatedOnPortAfterSignalNetworkInactive) { | |
3206 FakePortAllocator pa(rtc::Thread::Current(), nullptr); | 3387 FakePortAllocator pa(rtc::Thread::Current(), nullptr); |
3207 P2PTransportChannel ch("test channel", ICE_CANDIDATE_COMPONENT_DEFAULT, &pa); | 3388 P2PTransportChannel ch("test channel", ICE_CANDIDATE_COMPONENT_DEFAULT, &pa); |
3208 // Starts with ICEROLE_CONTROLLING. | 3389 // Starts with ICEROLE_CONTROLLING. |
3209 PrepareChannel(&ch); | 3390 PrepareChannel(&ch); |
3210 IceConfig config = CreateIceConfig(1000, true); | 3391 IceConfig config = CreateIceConfig(1000, GATHER_CONTINUALLY); |
3211 ch.SetIceConfig(config); | 3392 ch.SetIceConfig(config); |
3212 ch.Connect(); | 3393 ch.Connect(); |
3213 ch.MaybeStartGathering(); | 3394 ch.MaybeStartGathering(); |
3214 ch.AddRemoteCandidate(CreateUdpCandidate(LOCAL_PORT_TYPE, "1.1.1.1", 1, 1)); | 3395 ch.AddRemoteCandidate(CreateUdpCandidate(LOCAL_PORT_TYPE, "1.1.1.1", 1, 1)); |
3215 | 3396 |
3216 Connection* conn = WaitForConnectionTo(&ch, "1.1.1.1", 1); | 3397 Connection* conn = WaitForConnectionTo(&ch, "1.1.1.1", 1); |
3217 ASSERT_TRUE(conn != nullptr); | 3398 ASSERT_TRUE(conn != nullptr); |
3218 | 3399 |
3219 // Make the fake port signal that its network is inactive, then change the | 3400 // Make a fake signal to remove the ports in the p2ptransportchannel. then |
3220 // ICE role and expect it to be updated. | 3401 // change the ICE role and expect it to be updated. |
3221 conn->port()->SignalNetworkInactive(conn->port()); | 3402 std::vector<PortInterface*> ports(1, conn->port()); |
| 3403 ch.allocator_session()->SignalPortsRemoved(ch.allocator_session(), ports); |
3222 ch.SetIceRole(ICEROLE_CONTROLLED); | 3404 ch.SetIceRole(ICEROLE_CONTROLLED); |
3223 EXPECT_EQ(ICEROLE_CONTROLLED, conn->port()->GetIceRole()); | 3405 EXPECT_EQ(ICEROLE_CONTROLLED, conn->port()->GetIceRole()); |
3224 } | 3406 } |
3225 | 3407 |
3226 // Test that the ICE role is updated even on ports with inactive networks. | 3408 // Test that the ICE role is updated even on ports with inactive networks. |
3227 // These ports may still have connections that need a correct role, for the | 3409 // These ports may still have connections that need a correct role, for the |
3228 // pings sent by those connections until they're replaced by newer-generation | 3410 // pings sent by those connections until they're replaced by newer-generation |
3229 // connections. | 3411 // connections. |
3230 TEST_F(P2PTransportChannelPingTest, TestIceRoleUpdatedOnPortAfterIceRestart) { | 3412 TEST_F(P2PTransportChannelPingTest, TestIceRoleUpdatedOnPortAfterIceRestart) { |
3231 FakePortAllocator pa(rtc::Thread::Current(), nullptr); | 3413 FakePortAllocator pa(rtc::Thread::Current(), nullptr); |
(...skipping 247 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3479 | 3661 |
3480 // TCP Relay/Relay is the next. | 3662 // TCP Relay/Relay is the next. |
3481 VerifyNextPingableConnection(RELAY_PORT_TYPE, RELAY_PORT_TYPE, | 3663 VerifyNextPingableConnection(RELAY_PORT_TYPE, RELAY_PORT_TYPE, |
3482 TCP_PROTOCOL_NAME); | 3664 TCP_PROTOCOL_NAME); |
3483 | 3665 |
3484 // Finally, Local/Relay will be pinged. | 3666 // Finally, Local/Relay will be pinged. |
3485 VerifyNextPingableConnection(LOCAL_PORT_TYPE, RELAY_PORT_TYPE); | 3667 VerifyNextPingableConnection(LOCAL_PORT_TYPE, RELAY_PORT_TYPE); |
3486 } | 3668 } |
3487 | 3669 |
3488 } // namespace cricket { | 3670 } // namespace cricket { |
OLD | NEW |