Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(28)

Side by Side Diff: webrtc/p2p/base/p2ptransportchannel_unittest.cc

Issue 2025573002: Use continual gathering to restore backup connections (Closed) Base URL: https://chromium.googlesource.com/external/webrtc@master
Patch Set: Merge branch 'master' into enhanced_cg Created 4 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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
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
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
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
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
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
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
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 // Enable continual gathering.
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, TestContinualGatheringSwitchLinks) {
2112 AddAddress(0, kPublicAddrs[0]); 2196 AddAddress(0, kPublicAddrs[0]);
2113 AddAddress(1, kPublicAddrs[1]); 2197 AddAddress(1, kPublicAddrs[1]);
2114 // Use only local ports for simplicity. 2198 // Use only local ports for simplicity.
2115 SetAllocatorFlags(0, kOnlyLocalPorts); 2199 SetAllocatorFlags(0, kOnlyLocalPorts);
2116 SetAllocatorFlags(1, kOnlyLocalPorts); 2200 SetAllocatorFlags(1, kOnlyLocalPorts);
2117 2201
2118 // Create channels and let them go writable, as usual. 2202 // Create channels and let them go writable, as usual.
2119 CreateChannels(1); 2203 CreateChannels(1);
2120 EXPECT_TRUE_WAIT(ep1_ch1()->receiving() && ep1_ch1()->writable() && 2204 // Enable continual gathering.
2121 ep2_ch1()->receiving() && ep2_ch1()->writable(), 2205 ep1_ch1()->SetIceConfig(CreateIceConfig(1000, GATHER_CONTINUALLY));
2122 1000); 2206 ep2_ch1()->SetIceConfig(CreateIceConfig(1000, GATHER_CONTINUALLY));
2207 EXPECT_TRUE_WAIT_MARGIN(ep1_ch1()->receiving() && ep1_ch1()->writable() &&
2208 ep2_ch1()->receiving() && ep2_ch1()->writable(),
2209 kDefaultTimeout, kDefaultTimeout);
2123 EXPECT_TRUE( 2210 EXPECT_TRUE(
2124 ep1_ch1()->selected_connection() && ep2_ch1()->selected_connection() && 2211 ep1_ch1()->selected_connection() && ep2_ch1()->selected_connection() &&
2125 LocalCandidate(ep1_ch1())->address().EqualIPs(kPublicAddrs[0]) && 2212 LocalCandidate(ep1_ch1())->address().EqualIPs(kPublicAddrs[0]) &&
2126 RemoteCandidate(ep1_ch1())->address().EqualIPs(kPublicAddrs[1])); 2213 RemoteCandidate(ep1_ch1())->address().EqualIPs(kPublicAddrs[1]));
2127 2214
2128 2215 // 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..."; 2216 LOG(LS_INFO) << "Draining...";
2133 AddAddress(1, kAlternateAddrs[1]); 2217 AddAddress(1, kAlternateAddrs[1]);
2134 RemoveAddress(1, kPublicAddrs[1]); 2218 RemoveAddress(1, kPublicAddrs[1]);
2135 ep2_ch1()->MaybeStartGathering(); 2219 // We should switch to use the alternate address after an exchange of pings.
2136
2137 // We should switch over to use the alternate address after
2138 // an exchange of pings.
2139 EXPECT_TRUE_WAIT( 2220 EXPECT_TRUE_WAIT(
2140 ep1_ch1()->selected_connection() && ep2_ch1()->selected_connection() && 2221 ep1_ch1()->selected_connection() && ep2_ch1()->selected_connection() &&
2141 LocalCandidate(ep1_ch1())->address().EqualIPs(kPublicAddrs[0]) && 2222 LocalCandidate(ep1_ch1())->address().EqualIPs(kPublicAddrs[0]) &&
2142 RemoteCandidate(ep1_ch1())->address().EqualIPs(kAlternateAddrs[1]), 2223 RemoteCandidate(ep1_ch1())->address().EqualIPs(kAlternateAddrs[1]),
2143 3000); 2224 3000);
2144 2225
2226 // Remove one address first and then add another address.
2227 LOG(LS_INFO) << "Draining again...";
2228 RemoveAddress(1, kAlternateAddrs[1]);
2229 AddAddress(1, kAlternateAddrs[0]);
2230 EXPECT_TRUE_WAIT(
2231 ep1_ch1()->best_connection() && ep2_ch1()->best_connection() &&
2232 LocalCandidate(ep1_ch1())->address().EqualIPs(kPublicAddrs[0]) &&
2233 RemoteCandidate(ep1_ch1())->address().EqualIPs(kAlternateAddrs[0]),
2234 3000);
2235
2145 DestroyChannels(); 2236 DestroyChannels();
2146 } 2237 }
2147 2238
2148 */ 2239 // Tests that if the backup connections are lost and then the interface with the
2240 // selected connection is gone, continual gathering will restore the
2241 // connectivity.
2242 TEST_F(P2PTransportChannelMultihomedTest,
2243 TestBackupConnectionLostThenContinualGathering) {
2244 auto& wifi = kAlternateAddrs;
2245 auto& cellular = kPublicAddrs;
2246 AddAddress(0, wifi[0], "test_wifi0", rtc::ADAPTER_TYPE_WIFI);
2247 AddAddress(0, cellular[0], "test_cell0", rtc::ADAPTER_TYPE_CELLULAR);
2248 AddAddress(1, wifi[1], "test_wifi1", rtc::ADAPTER_TYPE_WIFI);
2249 AddAddress(1, cellular[1], "test_cell1", rtc::ADAPTER_TYPE_CELLULAR);
2250 // Use only local ports for simplicity.
2251 SetAllocatorFlags(0, kOnlyLocalPorts);
2252 SetAllocatorFlags(1, kOnlyLocalPorts);
2253
2254 // Create channels and let them go writable, as usual.
2255 CreateChannels(1);
2256 // Enable continual gathering.
2257 ep1_ch1()->SetIceConfig(CreateIceConfig(1000, GATHER_CONTINUALLY));
2258 ep2_ch1()->SetIceConfig(CreateIceConfig(1000, GATHER_CONTINUALLY));
2259 EXPECT_TRUE_WAIT_MARGIN(ep1_ch1()->receiving() && ep1_ch1()->writable() &&
2260 ep2_ch1()->receiving() && ep2_ch1()->writable(),
2261 kDefaultTimeout, kDefaultTimeout);
2262 EXPECT_TRUE(ep1_ch1()->best_connection() && ep2_ch1()->best_connection() &&
2263 LocalCandidate(ep1_ch1())->address().EqualIPs(wifi[0]) &&
2264 RemoteCandidate(ep1_ch1())->address().EqualIPs(wifi[1]));
2265
2266 // First destroy all backup connection.
2267 DestroyAllButBestConnection(ep1_ch1());
2268 // Then the interface of the best connection goes away.
2269 RemoveAddress(0, wifi[0]);
2270 EXPECT_TRUE_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 kDefaultTimeout);
2275
2276 DestroyChannels();
2277 }
2278
2279 // Tests that the backup connection will be restored after it is destroyed.
2280 TEST_F(P2PTransportChannelMultihomedTest, TestRestoreBackupConnection) {
2281 auto& wifi = kAlternateAddrs;
2282 auto& cellular = kPublicAddrs;
2283 AddAddress(0, wifi[0], "test_wifi0", rtc::ADAPTER_TYPE_WIFI);
2284 AddAddress(0, cellular[0], "test_cell0", rtc::ADAPTER_TYPE_CELLULAR);
2285 AddAddress(1, wifi[1], "test_wifi1", rtc::ADAPTER_TYPE_WIFI);
2286 AddAddress(1, cellular[1], "test_cell1", rtc::ADAPTER_TYPE_CELLULAR);
2287 // Use only local ports for simplicity.
2288 SetAllocatorFlags(0, kOnlyLocalPorts);
2289 SetAllocatorFlags(1, kOnlyLocalPorts);
2290
2291 // Create channels and let them go writable, as usual.
2292 CreateChannels(1);
2293 IceConfig config = CreateIceConfig(1000, GATHER_CONTINUALLY);
2294 config.regather_on_failed_networks_interval = 2000;
2295 ep1_ch1()->SetIceConfig(config);
2296 ep2_ch1()->SetIceConfig(config);
2297 EXPECT_TRUE_WAIT_MARGIN(ep1_ch1()->receiving() && ep1_ch1()->writable() &&
2298 ep2_ch1()->receiving() && ep2_ch1()->writable(),
2299 kDefaultTimeout, kDefaultTimeout);
2300 EXPECT_TRUE(ep1_ch1()->best_connection() && ep2_ch1()->best_connection() &&
2301 LocalCandidate(ep1_ch1())->address().EqualIPs(wifi[0]) &&
2302 RemoteCandidate(ep1_ch1())->address().EqualIPs(wifi[1]));
2303
2304 // Destroy all backup connections.
2305 DestroyAllButBestConnection(ep1_ch1());
2306 // Ensure the backup connection is removed first.
2307 EXPECT_TRUE_WAIT(
2308 GetConnectionWithLocalAddress(ep1_ch1(), cellular[0]) == nullptr,
2309 kDefaultTimeout);
2310 const cricket::Connection* conn;
2311 EXPECT_TRUE_WAIT(
2312 (conn = GetConnectionWithLocalAddress(ep1_ch1(), cellular[0])) &&
2313 conn != ep1_ch1()->best_connection() && conn->writable(),
2314 5000);
2315
2316 DestroyChannels();
2317 }
2149 2318
2150 // A collection of tests which tests a single P2PTransportChannel by sending 2319 // A collection of tests which tests a single P2PTransportChannel by sending
2151 // pings. 2320 // pings.
2152 class P2PTransportChannelPingTest : public testing::Test, 2321 class P2PTransportChannelPingTest : public testing::Test,
2153 public sigslot::has_slots<> { 2322 public sigslot::has_slots<> {
2154 public: 2323 public:
2155 P2PTransportChannelPingTest() 2324 P2PTransportChannelPingTest()
2156 : pss_(new rtc::PhysicalSocketServer), 2325 : pss_(new rtc::PhysicalSocketServer),
2157 vss_(new rtc::VirtualSocketServer(pss_.get())), 2326 vss_(new rtc::VirtualSocketServer(pss_.get())),
2158 ss_scope_(vss_.get()) {} 2327 ss_scope_(vss_.get()) {}
(...skipping 437 matching lines...) Expand 10 before | Expand all | Expand 10 after
2596 } 2765 }
2597 2766
2598 TEST_F(P2PTransportChannelPingTest, TestReceivingStateChange) { 2767 TEST_F(P2PTransportChannelPingTest, TestReceivingStateChange) {
2599 FakePortAllocator pa(rtc::Thread::Current(), nullptr); 2768 FakePortAllocator pa(rtc::Thread::Current(), nullptr);
2600 P2PTransportChannel ch("receiving state change", 1, &pa); 2769 P2PTransportChannel ch("receiving state change", 1, &pa);
2601 PrepareChannel(&ch); 2770 PrepareChannel(&ch);
2602 // Default receiving timeout and checking receiving interval should not be too 2771 // Default receiving timeout and checking receiving interval should not be too
2603 // small. 2772 // small.
2604 EXPECT_LE(1000, ch.receiving_timeout()); 2773 EXPECT_LE(1000, ch.receiving_timeout());
2605 EXPECT_LE(200, ch.check_receiving_interval()); 2774 EXPECT_LE(200, ch.check_receiving_interval());
2606 ch.SetIceConfig(CreateIceConfig(500, false)); 2775 ch.SetIceConfig(CreateIceConfig(500, GATHER_ONCE));
2607 EXPECT_EQ(500, ch.receiving_timeout()); 2776 EXPECT_EQ(500, ch.receiving_timeout());
2608 EXPECT_EQ(50, ch.check_receiving_interval()); 2777 EXPECT_EQ(50, ch.check_receiving_interval());
2609 ch.Connect(); 2778 ch.Connect();
2610 ch.MaybeStartGathering(); 2779 ch.MaybeStartGathering();
2611 ch.AddRemoteCandidate(CreateUdpCandidate(LOCAL_PORT_TYPE, "1.1.1.1", 1, 1)); 2780 ch.AddRemoteCandidate(CreateUdpCandidate(LOCAL_PORT_TYPE, "1.1.1.1", 1, 1));
2612 Connection* conn1 = WaitForConnectionTo(&ch, "1.1.1.1", 1); 2781 Connection* conn1 = WaitForConnectionTo(&ch, "1.1.1.1", 1);
2613 ASSERT_TRUE(conn1 != nullptr); 2782 ASSERT_TRUE(conn1 != nullptr);
2614 2783
2615 conn1->ReceivedPing(); 2784 conn1->ReceivedPing();
2616 conn1->OnReadPacket("ABC", 3, rtc::CreatePacketTime(0)); 2785 conn1->OnReadPacket("ABC", 3, rtc::CreatePacketTime(0));
(...skipping 402 matching lines...) Expand 10 before | Expand all | Expand 10 after
3019 // When a higher-priority, nominated candidate comes in, the connections with 3188 // When a higher-priority, nominated candidate comes in, the connections with
3020 // lower-priority are pruned. 3189 // lower-priority are pruned.
3021 ch.AddRemoteCandidate(CreateUdpCandidate(LOCAL_PORT_TYPE, "2.2.2.2", 2, 10)); 3190 ch.AddRemoteCandidate(CreateUdpCandidate(LOCAL_PORT_TYPE, "2.2.2.2", 2, 10));
3022 Connection* conn2 = WaitForConnectionTo(&ch, "2.2.2.2", 2); 3191 Connection* conn2 = WaitForConnectionTo(&ch, "2.2.2.2", 2);
3023 ASSERT_TRUE(conn2 != nullptr); 3192 ASSERT_TRUE(conn2 != nullptr);
3024 conn2->ReceivedPingResponse(LOW_RTT); // Becomes writable and receiving 3193 conn2->ReceivedPingResponse(LOW_RTT); // Becomes writable and receiving
3025 conn2->set_nominated(true); 3194 conn2->set_nominated(true);
3026 conn2->SignalNominated(conn2); 3195 conn2->SignalNominated(conn2);
3027 EXPECT_TRUE_WAIT(conn1->pruned(), 3000); 3196 EXPECT_TRUE_WAIT(conn1->pruned(), 3000);
3028 3197
3029 ch.SetIceConfig(CreateIceConfig(500, false)); 3198 ch.SetIceConfig(CreateIceConfig(500, GATHER_ONCE));
3030 // Wait until conn2 becomes not receiving. 3199 // Wait until conn2 becomes not receiving.
3031 EXPECT_TRUE_WAIT(!conn2->receiving(), 3000); 3200 EXPECT_TRUE_WAIT(!conn2->receiving(), 3000);
3032 3201
3033 ch.AddRemoteCandidate(CreateUdpCandidate(LOCAL_PORT_TYPE, "3.3.3.3", 3, 1)); 3202 ch.AddRemoteCandidate(CreateUdpCandidate(LOCAL_PORT_TYPE, "3.3.3.3", 3, 1));
3034 Connection* conn3 = WaitForConnectionTo(&ch, "3.3.3.3", 3); 3203 Connection* conn3 = WaitForConnectionTo(&ch, "3.3.3.3", 3);
3035 ASSERT_TRUE(conn3 != nullptr); 3204 ASSERT_TRUE(conn3 != nullptr);
3036 // The selected connection should still be conn2. Even through conn3 has lower 3205 // 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 3206 // priority and is not receiving/writable, it is not pruned because the
3038 // selected connection is not receiving. 3207 // selected connection is not receiving.
3039 WAIT(conn3->pruned(), 1000); 3208 WAIT(conn3->pruned(), 1000);
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
3087 // Need to wait until the channel state is updated. 3256 // Need to wait until the channel state is updated.
3088 EXPECT_EQ_WAIT(TransportChannelState::STATE_FAILED, ch.GetState(), 1000); 3257 EXPECT_EQ_WAIT(TransportChannelState::STATE_FAILED, ch.GetState(), 1000);
3089 } 3258 }
3090 3259
3091 // Test that when a low-priority connection is pruned, it is not deleted 3260 // 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. 3261 // right away, and it can become active and be pruned again.
3093 TEST_F(P2PTransportChannelPingTest, TestConnectionPrunedAgain) { 3262 TEST_F(P2PTransportChannelPingTest, TestConnectionPrunedAgain) {
3094 FakePortAllocator pa(rtc::Thread::Current(), nullptr); 3263 FakePortAllocator pa(rtc::Thread::Current(), nullptr);
3095 P2PTransportChannel ch("test channel", 1, &pa); 3264 P2PTransportChannel ch("test channel", 1, &pa);
3096 PrepareChannel(&ch); 3265 PrepareChannel(&ch);
3097 ch.SetIceConfig(CreateIceConfig(1000, false)); 3266 ch.SetIceConfig(CreateIceConfig(1000, GATHER_ONCE));
3098 ch.Connect(); 3267 ch.Connect();
3099 ch.MaybeStartGathering(); 3268 ch.MaybeStartGathering();
3100 ch.AddRemoteCandidate(CreateUdpCandidate(LOCAL_PORT_TYPE, "1.1.1.1", 1, 100)); 3269 ch.AddRemoteCandidate(CreateUdpCandidate(LOCAL_PORT_TYPE, "1.1.1.1", 1, 100));
3101 Connection* conn1 = WaitForConnectionTo(&ch, "1.1.1.1", 1); 3270 Connection* conn1 = WaitForConnectionTo(&ch, "1.1.1.1", 1);
3102 ASSERT_TRUE(conn1 != nullptr); 3271 ASSERT_TRUE(conn1 != nullptr);
3103 EXPECT_EQ(conn1, ch.selected_connection()); 3272 EXPECT_EQ(conn1, ch.selected_connection());
3104 conn1->ReceivedPingResponse(LOW_RTT); // Becomes writable and receiving 3273 conn1->ReceivedPingResponse(LOW_RTT); // Becomes writable and receiving
3105 3274
3106 // Add a low-priority connection |conn2|, which will be pruned, but it will 3275 // 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 3276 // not be deleted right away. Once the current selected connection becomes not
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
3163 } 3332 }
3164 3333
3165 // Tests that after a port allocator session is started, it will be stopped 3334 // 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 3335 // 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 3336 // connection belonging to an old session becomes writable, it won't stop
3168 // the current port allocator session. 3337 // the current port allocator session.
3169 TEST_F(P2PTransportChannelPingTest, TestStopPortAllocatorSessions) { 3338 TEST_F(P2PTransportChannelPingTest, TestStopPortAllocatorSessions) {
3170 FakePortAllocator pa(rtc::Thread::Current(), nullptr); 3339 FakePortAllocator pa(rtc::Thread::Current(), nullptr);
3171 P2PTransportChannel ch("test channel", 1, &pa); 3340 P2PTransportChannel ch("test channel", 1, &pa);
3172 PrepareChannel(&ch); 3341 PrepareChannel(&ch);
3173 ch.SetIceConfig(CreateIceConfig(2000, false)); 3342 ch.SetIceConfig(CreateIceConfig(2000, GATHER_ONCE));
3174 ch.Connect(); 3343 ch.Connect();
3175 ch.MaybeStartGathering(); 3344 ch.MaybeStartGathering();
3176 ch.AddRemoteCandidate(CreateUdpCandidate(LOCAL_PORT_TYPE, "1.1.1.1", 1, 100)); 3345 ch.AddRemoteCandidate(CreateUdpCandidate(LOCAL_PORT_TYPE, "1.1.1.1", 1, 100));
3177 Connection* conn1 = WaitForConnectionTo(&ch, "1.1.1.1", 1); 3346 Connection* conn1 = WaitForConnectionTo(&ch, "1.1.1.1", 1);
3178 ASSERT_TRUE(conn1 != nullptr); 3347 ASSERT_TRUE(conn1 != nullptr);
3179 conn1->ReceivedPingResponse(LOW_RTT); // Becomes writable and receiving 3348 conn1->ReceivedPingResponse(LOW_RTT); // Becomes writable and receiving
3180 EXPECT_TRUE(!ch.allocator_session()->IsGettingPorts()); 3349 EXPECT_TRUE(!ch.allocator_session()->IsGettingPorts());
3181 3350
3182 // Start a new session. Even though conn1, which belongs to an older 3351 // Start a new session. Even though conn1, which belongs to an older
3183 // session, becomes unwritable and writable again, it should not stop the 3352 // session, becomes unwritable and writable again, it should not stop the
3184 // current session. 3353 // current session.
3185 ch.SetIceCredentials(kIceUfrag[1], kIcePwd[1]); 3354 ch.SetIceCredentials(kIceUfrag[1], kIcePwd[1]);
3186 ch.MaybeStartGathering(); 3355 ch.MaybeStartGathering();
3187 conn1->Prune(); 3356 conn1->Prune();
3188 conn1->ReceivedPingResponse(LOW_RTT); 3357 conn1->ReceivedPingResponse(LOW_RTT);
3189 EXPECT_TRUE(ch.allocator_session()->IsGettingPorts()); 3358 EXPECT_TRUE(ch.allocator_session()->IsGettingPorts());
3190 3359
3191 // But if a new connection created from the new session becomes writable, 3360 // But if a new connection created from the new session becomes writable,
3192 // it will stop the current session. 3361 // it will stop the current session.
3193 ch.AddRemoteCandidate(CreateUdpCandidate(LOCAL_PORT_TYPE, "2.2.2.2", 2, 100)); 3362 ch.AddRemoteCandidate(CreateUdpCandidate(LOCAL_PORT_TYPE, "2.2.2.2", 2, 100));
3194 Connection* conn2 = WaitForConnectionTo(&ch, "2.2.2.2", 2); 3363 Connection* conn2 = WaitForConnectionTo(&ch, "2.2.2.2", 2);
3195 ASSERT_TRUE(conn2 != nullptr); 3364 ASSERT_TRUE(conn2 != nullptr);
3196 conn2->ReceivedPingResponse(LOW_RTT); // Becomes writable and receiving 3365 conn2->ReceivedPingResponse(LOW_RTT); // Becomes writable and receiving
3197 EXPECT_TRUE(!ch.allocator_session()->IsGettingPorts()); 3366 EXPECT_TRUE(!ch.allocator_session()->IsGettingPorts());
3198 } 3367 }
3199 3368
3200 // Test that the ICE role is updated even on ports with inactive networks when 3369 // 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 3370 // 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 3371 // the connections on it may still receive stun pings.
3203 // destroyed. 3372 TEST_F(P2PTransportChannelPingTest, TestIceRoleUpdatedOnRemovedPort) {
3204 TEST_F(P2PTransportChannelPingTest,
3205 TestIceRoleUpdatedOnPortAfterSignalNetworkInactive) {
3206 FakePortAllocator pa(rtc::Thread::Current(), nullptr); 3373 FakePortAllocator pa(rtc::Thread::Current(), nullptr);
3207 P2PTransportChannel ch("test channel", ICE_CANDIDATE_COMPONENT_DEFAULT, &pa); 3374 P2PTransportChannel ch("test channel", ICE_CANDIDATE_COMPONENT_DEFAULT, &pa);
3208 // Starts with ICEROLE_CONTROLLING. 3375 // Starts with ICEROLE_CONTROLLING.
3209 PrepareChannel(&ch); 3376 PrepareChannel(&ch);
3210 IceConfig config = CreateIceConfig(1000, true); 3377 IceConfig config = CreateIceConfig(1000, GATHER_CONTINUALLY);
3211 ch.SetIceConfig(config); 3378 ch.SetIceConfig(config);
3212 ch.Connect(); 3379 ch.Connect();
3213 ch.MaybeStartGathering(); 3380 ch.MaybeStartGathering();
3214 ch.AddRemoteCandidate(CreateUdpCandidate(LOCAL_PORT_TYPE, "1.1.1.1", 1, 1)); 3381 ch.AddRemoteCandidate(CreateUdpCandidate(LOCAL_PORT_TYPE, "1.1.1.1", 1, 1));
3215 3382
3216 Connection* conn = WaitForConnectionTo(&ch, "1.1.1.1", 1); 3383 Connection* conn = WaitForConnectionTo(&ch, "1.1.1.1", 1);
3217 ASSERT_TRUE(conn != nullptr); 3384 ASSERT_TRUE(conn != nullptr);
3218 3385
3219 // Make the fake port signal that its network is inactive, then change the 3386 // Make a fake signal to remove the ports in the p2ptransportchannel. then
3220 // ICE role and expect it to be updated. 3387 // change the ICE role and expect it to be updated.
3221 conn->port()->SignalNetworkInactive(conn->port()); 3388 std::vector<PortInterface*> ports(1, conn->port());
3389 ch.allocator_session()->SignalPortsRemoved(ch.allocator_session(), ports);
3222 ch.SetIceRole(ICEROLE_CONTROLLED); 3390 ch.SetIceRole(ICEROLE_CONTROLLED);
3223 EXPECT_EQ(ICEROLE_CONTROLLED, conn->port()->GetIceRole()); 3391 EXPECT_EQ(ICEROLE_CONTROLLED, conn->port()->GetIceRole());
3224 } 3392 }
3225 3393
3226 // Test that the ICE role is updated even on ports with inactive networks. 3394 // 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 3395 // 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 3396 // pings sent by those connections until they're replaced by newer-generation
3229 // connections. 3397 // connections.
3230 TEST_F(P2PTransportChannelPingTest, TestIceRoleUpdatedOnPortAfterIceRestart) { 3398 TEST_F(P2PTransportChannelPingTest, TestIceRoleUpdatedOnPortAfterIceRestart) {
3231 FakePortAllocator pa(rtc::Thread::Current(), nullptr); 3399 FakePortAllocator pa(rtc::Thread::Current(), nullptr);
(...skipping 247 matching lines...) Expand 10 before | Expand all | Expand 10 after
3479 3647
3480 // TCP Relay/Relay is the next. 3648 // TCP Relay/Relay is the next.
3481 VerifyNextPingableConnection(RELAY_PORT_TYPE, RELAY_PORT_TYPE, 3649 VerifyNextPingableConnection(RELAY_PORT_TYPE, RELAY_PORT_TYPE,
3482 TCP_PROTOCOL_NAME); 3650 TCP_PROTOCOL_NAME);
3483 3651
3484 // Finally, Local/Relay will be pinged. 3652 // Finally, Local/Relay will be pinged.
3485 VerifyNextPingableConnection(LOCAL_PORT_TYPE, RELAY_PORT_TYPE); 3653 VerifyNextPingableConnection(LOCAL_PORT_TYPE, RELAY_PORT_TYPE);
3486 } 3654 }
3487 3655
3488 } // namespace cricket { 3656 } // namespace cricket {
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698