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

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: Add tests Created 4 years, 6 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 370 matching lines...) Expand 10 before | Expand all | Expand 10 after
381 } 381 }
382 void AddAddress(int endpoint, 382 void AddAddress(int endpoint,
383 const SocketAddress& addr, 383 const SocketAddress& addr,
384 const std::string& ifname, 384 const std::string& ifname,
385 rtc::AdapterType adapter_type) { 385 rtc::AdapterType adapter_type) {
386 GetEndpoint(endpoint)->network_manager_.AddInterface(addr, ifname, 386 GetEndpoint(endpoint)->network_manager_.AddInterface(addr, ifname,
387 adapter_type); 387 adapter_type);
388 } 388 }
389 void RemoveAddress(int endpoint, const SocketAddress& addr) { 389 void RemoveAddress(int endpoint, const SocketAddress& addr) {
390 GetEndpoint(endpoint)->network_manager_.RemoveInterface(addr); 390 GetEndpoint(endpoint)->network_manager_.RemoveInterface(addr);
391 fw()->AddRule(false, rtc::FP_ANY, rtc::FD_ANY, addr);
391 } 392 }
392 void SetProxy(int endpoint, rtc::ProxyType type) { 393 void SetProxy(int endpoint, rtc::ProxyType type) {
393 rtc::ProxyInfo info; 394 rtc::ProxyInfo info;
394 info.type = type; 395 info.type = type;
395 info.address = (type == rtc::PROXY_HTTPS) ? 396 info.address = (type == rtc::PROXY_HTTPS) ?
396 kHttpsProxyAddrs[endpoint] : kSocksProxyAddrs[endpoint]; 397 kHttpsProxyAddrs[endpoint] : kSocksProxyAddrs[endpoint];
397 GetAllocator(endpoint)->set_proxy("unittest/1.0", info); 398 GetAllocator(endpoint)->set_proxy("unittest/1.0", info);
398 } 399 }
399 void SetAllocatorFlags(int endpoint, int flags) { 400 void SetAllocatorFlags(int endpoint, int flags) {
400 GetAllocator(endpoint)->set_flags(flags); 401 GetAllocator(endpoint)->set_flags(flags);
(...skipping 1175 matching lines...) Expand 10 before | Expand all | Expand 10 after
1576 TEST_F(P2PTransportChannelSameNatTest, TestConesBehindSameCone) { 1577 TEST_F(P2PTransportChannelSameNatTest, TestConesBehindSameCone) {
1577 ConfigureEndpoints(NAT_FULL_CONE, NAT_FULL_CONE, NAT_FULL_CONE); 1578 ConfigureEndpoints(NAT_FULL_CONE, NAT_FULL_CONE, NAT_FULL_CONE);
1578 Test(P2PTransportChannelTestBase::Result( 1579 Test(P2PTransportChannelTestBase::Result(
1579 "prflx", "udp", "stun", "udp", "stun", "udp", "prflx", "udp", 1000)); 1580 "prflx", "udp", "stun", "udp", "stun", "udp", "prflx", "udp", 1000));
1580 } 1581 }
1581 1582
1582 // Test what happens when we have multiple available pathways. 1583 // Test what happens when we have multiple available pathways.
1583 // In the future we will try different RTTs and configs for the different 1584 // In the future we will try different RTTs and configs for the different
1584 // interfaces, so that we can simulate a user with Ethernet and VPN networks. 1585 // interfaces, so that we can simulate a user with Ethernet and VPN networks.
1585 class P2PTransportChannelMultihomedTest : public P2PTransportChannelTestBase { 1586 class P2PTransportChannelMultihomedTest : public P2PTransportChannelTestBase {
1587 public:
1588 const cricket::Connection* GetConnectionWithRemoteAddress(
1589 cricket::P2PTransportChannel* channel,
1590 const SocketAddress& address) {
1591 for (cricket::Connection* conn : channel->connections()) {
1592 if (conn->remote_candidate().address().EqualIPs(address)) {
1593 return conn;
1594 }
1595 }
1596 return nullptr;
1597 }
1598
1599 const cricket::Connection* GetConnectionWithLocalAddress(
1600 cricket::P2PTransportChannel* channel,
1601 const SocketAddress& address) {
1602 for (cricket::Connection* conn : channel->connections()) {
1603 if (conn->local_candidate().address().EqualIPs(address)) {
1604 return conn;
1605 }
1606 }
1607 return nullptr;
1608 }
1609
1610 void DestroyAllButBestConnection(cricket::P2PTransportChannel* channel) {
1611 const cricket::Connection* best_connection = channel->best_connection();
1612 for (cricket::Connection* conn : channel->connections()) {
1613 if (conn != best_connection) {
1614 conn->Destroy();
1615 }
1616 }
1617 }
1586 }; 1618 };
1587 1619
1588 // Test that we can establish connectivity when both peers are multihomed. 1620 // Test that we can establish connectivity when both peers are multihomed.
1589 TEST_F(P2PTransportChannelMultihomedTest, DISABLED_TestBasic) { 1621 TEST_F(P2PTransportChannelMultihomedTest, DISABLED_TestBasic) {
1590 AddAddress(0, kPublicAddrs[0]); 1622 AddAddress(0, kPublicAddrs[0]);
1591 AddAddress(0, kAlternateAddrs[0]); 1623 AddAddress(0, kAlternateAddrs[0]);
1592 AddAddress(1, kPublicAddrs[1]); 1624 AddAddress(1, kPublicAddrs[1]);
1593 AddAddress(1, kAlternateAddrs[1]); 1625 AddAddress(1, kAlternateAddrs[1]);
1594 Test(kLocalUdpToLocalUdp); 1626 Test(kLocalUdpToLocalUdp);
1595 } 1627 }
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after
1722 1000, 1000); 1754 1000, 1000);
1723 // Need to wait to make sure the connections on both networks are writable. 1755 // Need to wait to make sure the connections on both networks are writable.
1724 EXPECT_TRUE_WAIT(ep1_ch1()->best_connection() && 1756 EXPECT_TRUE_WAIT(ep1_ch1()->best_connection() &&
1725 LocalCandidate(ep1_ch1())->address().EqualIPs(wifi[0]) && 1757 LocalCandidate(ep1_ch1())->address().EqualIPs(wifi[0]) &&
1726 RemoteCandidate(ep1_ch1())->address().EqualIPs(wifi[1]), 1758 RemoteCandidate(ep1_ch1())->address().EqualIPs(wifi[1]),
1727 1000); 1759 1000);
1728 EXPECT_TRUE_WAIT(ep2_ch1()->best_connection() && 1760 EXPECT_TRUE_WAIT(ep2_ch1()->best_connection() &&
1729 LocalCandidate(ep2_ch1())->address().EqualIPs(wifi[1]) && 1761 LocalCandidate(ep2_ch1())->address().EqualIPs(wifi[1]) &&
1730 RemoteCandidate(ep2_ch1())->address().EqualIPs(wifi[0]), 1762 RemoteCandidate(ep2_ch1())->address().EqualIPs(wifi[0]),
1731 1000); 1763 1000);
1764 DestroyChannels();
1732 } 1765 }
1733 1766
1734 // Tests that a Wifi-Cellular connection has higher precedence than 1767 // Tests that a Wifi-Cellular connection has higher precedence than
1735 // a Cellular-Cellular connection. 1768 // a Cellular-Cellular connection.
1736 TEST_F(P2PTransportChannelMultihomedTest, TestPreferWifiOverCellularNetwork) { 1769 TEST_F(P2PTransportChannelMultihomedTest, TestPreferWifiOverCellularNetwork) {
1737 // The interface names are chosen so that |cellular| would have higher 1770 // The interface names are chosen so that |cellular| would have higher
1738 // candidate priority if it is not for the network type. 1771 // candidate priority if it is not for the network type.
1739 auto& wifi = kAlternateAddrs; 1772 auto& wifi = kAlternateAddrs;
1740 auto& cellular = kPublicAddrs; 1773 auto& cellular = kPublicAddrs;
1741 AddAddress(0, cellular[0], "test1", rtc::ADAPTER_TYPE_CELLULAR); 1774 AddAddress(0, cellular[0], "test1", rtc::ADAPTER_TYPE_CELLULAR);
(...skipping 10 matching lines...) Expand all
1752 EXPECT_TRUE_WAIT_MARGIN(ep1_ch1()->receiving() && ep1_ch1()->writable() && 1785 EXPECT_TRUE_WAIT_MARGIN(ep1_ch1()->receiving() && ep1_ch1()->writable() &&
1753 ep2_ch1()->receiving() && ep2_ch1()->writable(), 1786 ep2_ch1()->receiving() && ep2_ch1()->writable(),
1754 1000, 1000); 1787 1000, 1000);
1755 // Need to wait to make sure the connections on both networks are writable. 1788 // Need to wait to make sure the connections on both networks are writable.
1756 EXPECT_TRUE_WAIT(ep1_ch1()->best_connection() && 1789 EXPECT_TRUE_WAIT(ep1_ch1()->best_connection() &&
1757 RemoteCandidate(ep1_ch1())->address().EqualIPs(wifi[1]), 1790 RemoteCandidate(ep1_ch1())->address().EqualIPs(wifi[1]),
1758 1000); 1791 1000);
1759 EXPECT_TRUE_WAIT(ep2_ch1()->best_connection() && 1792 EXPECT_TRUE_WAIT(ep2_ch1()->best_connection() &&
1760 LocalCandidate(ep2_ch1())->address().EqualIPs(wifi[1]), 1793 LocalCandidate(ep2_ch1())->address().EqualIPs(wifi[1]),
1761 1000); 1794 1000);
1795 DestroyChannels();
1762 } 1796 }
1763 1797
1764 // Test that the backup connection is pinged at a rate no faster than 1798 // Test that the backup connection is pinged at a rate no faster than
1765 // what was configured. 1799 // what was configured.
1766 TEST_F(P2PTransportChannelMultihomedTest, TestPingBackupConnectionRate) { 1800 TEST_F(P2PTransportChannelMultihomedTest, TestPingBackupConnectionRate) {
1767 AddAddress(0, kPublicAddrs[0]); 1801 AddAddress(0, kPublicAddrs[0]);
1768 // Adding alternate address will make sure |kPublicAddrs| has the higher 1802 // Adding alternate address will make sure |kPublicAddrs| has the higher
1769 // priority than others. This is due to FakeNetwork::AddInterface method. 1803 // priority than others. This is due to FakeNetwork::AddInterface method.
1770 AddAddress(1, kAlternateAddrs[1]); 1804 AddAddress(1, kAlternateAddrs[1]);
1771 AddAddress(1, kPublicAddrs[1]); 1805 AddAddress(1, kPublicAddrs[1]);
(...skipping 17 matching lines...) Expand all
1789 ASSERT_EQ(2U, connections.size()); 1823 ASSERT_EQ(2U, connections.size());
1790 cricket::Connection* backup_conn = connections[1]; 1824 cricket::Connection* backup_conn = connections[1];
1791 EXPECT_TRUE_WAIT(backup_conn->writable(), 3000); 1825 EXPECT_TRUE_WAIT(backup_conn->writable(), 3000);
1792 int64_t last_ping_response_ms = backup_conn->last_ping_response_received(); 1826 int64_t last_ping_response_ms = backup_conn->last_ping_response_received();
1793 EXPECT_TRUE_WAIT( 1827 EXPECT_TRUE_WAIT(
1794 last_ping_response_ms < backup_conn->last_ping_response_received(), 5000); 1828 last_ping_response_ms < backup_conn->last_ping_response_received(), 5000);
1795 int time_elapsed = 1829 int time_elapsed =
1796 backup_conn->last_ping_response_received() - last_ping_response_ms; 1830 backup_conn->last_ping_response_received() - last_ping_response_ms;
1797 LOG(LS_INFO) << "Time elapsed: " << time_elapsed; 1831 LOG(LS_INFO) << "Time elapsed: " << time_elapsed;
1798 EXPECT_GE(time_elapsed, backup_ping_interval); 1832 EXPECT_GE(time_elapsed, backup_ping_interval);
1833
1834 DestroyChannels();
1799 } 1835 }
1800 1836
1801 TEST_F(P2PTransportChannelMultihomedTest, TestGetState) { 1837 TEST_F(P2PTransportChannelMultihomedTest, TestGetState) {
1802 AddAddress(0, kAlternateAddrs[0]); 1838 AddAddress(0, kAlternateAddrs[0]);
1803 AddAddress(0, kPublicAddrs[0]); 1839 AddAddress(0, kPublicAddrs[0]);
1804 AddAddress(1, kPublicAddrs[1]); 1840 AddAddress(1, kPublicAddrs[1]);
1805 // Create channels and let them go writable, as usual. 1841 // Create channels and let them go writable, as usual.
1806 CreateChannels(1); 1842 CreateChannels(1);
1807 1843
1808 // Both transport channels will reach STATE_COMPLETED quickly. 1844 // Both transport channels will reach STATE_COMPLETED quickly.
1809 EXPECT_EQ_WAIT(cricket::TransportChannelState::STATE_COMPLETED, 1845 EXPECT_EQ_WAIT(cricket::TransportChannelState::STATE_COMPLETED,
1810 ep1_ch1()->GetState(), 1000); 1846 ep1_ch1()->GetState(), 1000);
1811 EXPECT_EQ_WAIT(cricket::TransportChannelState::STATE_COMPLETED, 1847 EXPECT_EQ_WAIT(cricket::TransportChannelState::STATE_COMPLETED,
1812 ep2_ch1()->GetState(), 1000); 1848 ep2_ch1()->GetState(), 1000);
1849
1850 DestroyChannels();
1813 } 1851 }
1814 1852
1815 // Tests that when a network interface becomes inactive, if and only if 1853 // Tests that when a network interface becomes inactive, if and only if
1816 // Continual Gathering is enabled, the ports associated with that network 1854 // Continual Gathering is enabled, the ports associated with that network
1817 // will be removed from the port list of the channel, and the respective 1855 // will be removed from the port list of the channel, and the respective
1818 // remote candidates on the other participant will be removed eventually. 1856 // remote candidates on the other participant will be removed eventually.
1819 TEST_F(P2PTransportChannelMultihomedTest, TestNetworkBecomesInactive) { 1857 TEST_F(P2PTransportChannelMultihomedTest, TestNetworkBecomesInactive) {
1820 AddAddress(0, kPublicAddrs[0]); 1858 AddAddress(0, kPublicAddrs[0]);
1821 AddAddress(1, kPublicAddrs[1]); 1859 AddAddress(1, kPublicAddrs[1]);
1822 // Create channels and let them go writable, as usual. 1860 // Create channels and let them go writable, as usual.
(...skipping 18 matching lines...) Expand all
1841 size_t num_ports = ep2_ch1()->ports().size(); 1879 size_t num_ports = ep2_ch1()->ports().size();
1842 EXPECT_LE(1U, num_ports); 1880 EXPECT_LE(1U, num_ports);
1843 size_t num_remote_candidates = ep1_ch1()->remote_candidates().size(); 1881 size_t num_remote_candidates = ep1_ch1()->remote_candidates().size();
1844 // Endpoint 2 did not enable continual gathering; the port will not be removed 1882 // Endpoint 2 did not enable continual gathering; the port will not be removed
1845 // when the interface is removed and neither the remote candidates on the 1883 // when the interface is removed and neither the remote candidates on the
1846 // other participant. 1884 // other participant.
1847 RemoveAddress(1, kPublicAddrs[1]); 1885 RemoveAddress(1, kPublicAddrs[1]);
1848 rtc::Thread::Current()->ProcessMessages(500); 1886 rtc::Thread::Current()->ProcessMessages(500);
1849 EXPECT_EQ(num_ports, ep2_ch1()->ports().size()); 1887 EXPECT_EQ(num_ports, ep2_ch1()->ports().size());
1850 EXPECT_EQ(num_remote_candidates, ep1_ch1()->remote_candidates().size()); 1888 EXPECT_EQ(num_remote_candidates, ep1_ch1()->remote_candidates().size());
1889
1890 DestroyChannels();
1851 } 1891 }
1852 1892
1853 /* 1893 // Tests that continual gathering will create new connections when a new
1894 // interface is added.
1895 TEST_F(P2PTransportChannelMultihomedTest,
1896 TestContinualGatheringOnNewInterface) {
1897 auto& wifi = kAlternateAddrs;
1898 auto& cellular = kPublicAddrs;
1899 AddAddress(0, wifi[0], "test_wifi0", rtc::ADAPTER_TYPE_WIFI);
1900 AddAddress(1, cellular[1], "test_cell1", rtc::ADAPTER_TYPE_CELLULAR);
1901 CreateChannels(1);
1902 // Enable continual gathering.
1903 ep1_ch1()->SetIceConfig(CreateIceConfig(1000, true));
1904 ep2_ch1()->SetIceConfig(CreateIceConfig(1000, true));
1905 SetAllocatorFlags(0, kOnlyLocalPorts);
1906 SetAllocatorFlags(1, kOnlyLocalPorts);
1907 EXPECT_TRUE_WAIT_MARGIN(ep1_ch1()->receiving() && ep1_ch1()->writable() &&
1908 ep2_ch1()->receiving() && ep2_ch1()->writable(),
1909 kDefaultTimeout, kDefaultTimeout);
1854 1910
1855 TODO(pthatcher): Once have a way to handle network interfaces changes 1911 // Add a new wifi interface on end point 2. We should expect a new connection
1856 without signalling an ICE restart, put a test like this back. In the 1912 // to be created and the new one will be the best connection.
1857 mean time, this test only worked for GICE. With ICE, it's currently 1913 AddAddress(1, wifi[1], "test_wifi1", rtc::ADAPTER_TYPE_WIFI);
1858 not possible without an ICE restart. 1914 const cricket::Connection* conn;
1915 EXPECT_TRUE_WAIT((conn = ep1_ch1()->best_connection()) != nullptr &&
1916 conn->remote_candidate().address().EqualIPs(wifi[1]),
1917 kDefaultTimeout);
1918 EXPECT_TRUE_WAIT((conn = ep2_ch1()->best_connection()) != nullptr &&
1919 conn->local_candidate().address().EqualIPs(wifi[1]),
1920 kDefaultTimeout);
1859 1921
1860 // Test that we can switch links in a coordinated fashion. 1922 // Add a new cellular interface on end point 1, we should expect a new
1861 TEST_F(P2PTransportChannelMultihomedTest, TestDrain) { 1923 // backup connection created using this new interface.
1924 AddAddress(0, cellular[0], "test_cellular0", rtc::ADAPTER_TYPE_CELLULAR);
1925 EXPECT_TRUE_WAIT(
1926 ep1_ch1()->GetState() == cricket::STATE_COMPLETED &&
1927 (conn = GetConnectionWithLocalAddress(ep1_ch1(), cellular[0])) &&
1928 conn != ep1_ch1()->best_connection() && conn->writable(),
1929 kDefaultTimeout);
1930 EXPECT_TRUE_WAIT(
1931 ep2_ch1()->GetState() == cricket::STATE_COMPLETED &&
1932 (conn = GetConnectionWithRemoteAddress(ep2_ch1(), cellular[0])) &&
1933 conn != ep2_ch1()->best_connection() && conn->receiving(),
1934 kDefaultTimeout);
1935
1936 DestroyChannels();
1937 }
1938
1939 // Tests that we can switch links via continual gathering.
1940 TEST_F(P2PTransportChannelMultihomedTest, TestContinualGatheringSwitchLinks) {
1862 AddAddress(0, kPublicAddrs[0]); 1941 AddAddress(0, kPublicAddrs[0]);
1863 AddAddress(1, kPublicAddrs[1]); 1942 AddAddress(1, kPublicAddrs[1]);
1864 // Use only local ports for simplicity. 1943 // Use only local ports for simplicity.
1865 SetAllocatorFlags(0, kOnlyLocalPorts); 1944 SetAllocatorFlags(0, kOnlyLocalPorts);
1866 SetAllocatorFlags(1, kOnlyLocalPorts); 1945 SetAllocatorFlags(1, kOnlyLocalPorts);
1867 1946
1868 // Create channels and let them go writable, as usual. 1947 // Create channels and let them go writable, as usual.
1869 CreateChannels(1); 1948 CreateChannels(1);
1870 EXPECT_TRUE_WAIT(ep1_ch1()->receiving() && ep1_ch1()->writable() && 1949 // Enable continual gathering.
1871 ep2_ch1()->receiving() && ep2_ch1()->writable(), 1950 ep1_ch1()->SetIceConfig(CreateIceConfig(1000, true));
1872 1000); 1951 ep2_ch1()->SetIceConfig(CreateIceConfig(1000, true));
1952 EXPECT_TRUE_WAIT_MARGIN(ep1_ch1()->receiving() && ep1_ch1()->writable() &&
1953 ep2_ch1()->receiving() && ep2_ch1()->writable(),
1954 kDefaultTimeout, kDefaultTimeout);
1873 EXPECT_TRUE( 1955 EXPECT_TRUE(
1874 ep1_ch1()->best_connection() && ep2_ch1()->best_connection() && 1956 ep1_ch1()->best_connection() && ep2_ch1()->best_connection() &&
1875 LocalCandidate(ep1_ch1())->address().EqualIPs(kPublicAddrs[0]) && 1957 LocalCandidate(ep1_ch1())->address().EqualIPs(kPublicAddrs[0]) &&
1876 RemoteCandidate(ep1_ch1())->address().EqualIPs(kPublicAddrs[1])); 1958 RemoteCandidate(ep1_ch1())->address().EqualIPs(kPublicAddrs[1]));
1877 1959
1878 1960 // Add the new address first and then remove the other one.
1879 // Remove the public interface, add the alternate interface, and allocate
1880 // a new generation of candidates for the new interface (via
1881 // MaybeStartGathering()).
1882 LOG(LS_INFO) << "Draining..."; 1961 LOG(LS_INFO) << "Draining...";
1883 AddAddress(1, kAlternateAddrs[1]); 1962 AddAddress(1, kAlternateAddrs[1]);
1884 RemoveAddress(1, kPublicAddrs[1]); 1963 RemoveAddress(1, kPublicAddrs[1]);
1885 ep2_ch1()->MaybeStartGathering(); 1964 // We should switch to use the alternate address after an exchange of pings.
1886
1887 // We should switch over to use the alternate address after
1888 // an exchange of pings.
1889 EXPECT_TRUE_WAIT( 1965 EXPECT_TRUE_WAIT(
1890 ep1_ch1()->best_connection() && ep2_ch1()->best_connection() && 1966 ep1_ch1()->best_connection() && ep2_ch1()->best_connection() &&
1891 LocalCandidate(ep1_ch1())->address().EqualIPs(kPublicAddrs[0]) && 1967 LocalCandidate(ep1_ch1())->address().EqualIPs(kPublicAddrs[0]) &&
1892 RemoteCandidate(ep1_ch1())->address().EqualIPs(kAlternateAddrs[1]), 1968 RemoteCandidate(ep1_ch1())->address().EqualIPs(kAlternateAddrs[1]),
1893 3000); 1969 3000);
1894 1970
1971 // Remove one address first and then add another address.
1972 LOG(LS_INFO) << "Draining again...";
1973 RemoveAddress(1, kAlternateAddrs[1]);
1974 AddAddress(1, kAlternateAddrs[0]);
1975 EXPECT_TRUE_WAIT(
1976 ep1_ch1()->best_connection() && ep2_ch1()->best_connection() &&
1977 LocalCandidate(ep1_ch1())->address().EqualIPs(kPublicAddrs[0]) &&
1978 RemoteCandidate(ep1_ch1())->address().EqualIPs(kAlternateAddrs[0]),
1979 3000);
1980
1895 DestroyChannels(); 1981 DestroyChannels();
1896 } 1982 }
1897 1983
1898 */ 1984 // Tests that if the backup connections are lost and then the interface with the
1985 // selected connection is gone, continual gathering will restore the
1986 // connectivity.
1987 TEST_F(P2PTransportChannelMultihomedTest,
1988 TestBackupConnectionLostThenContinualGathering) {
1989 auto& wifi = kAlternateAddrs;
1990 auto& cellular = kPublicAddrs;
1991 AddAddress(0, wifi[0], "test_wifi0", rtc::ADAPTER_TYPE_WIFI);
1992 AddAddress(0, cellular[0], "test_cell0", rtc::ADAPTER_TYPE_CELLULAR);
1993 AddAddress(1, wifi[1], "test_wifi1", rtc::ADAPTER_TYPE_WIFI);
1994 AddAddress(1, cellular[1], "test_cell1", rtc::ADAPTER_TYPE_CELLULAR);
1995 // Use only local ports for simplicity.
1996 SetAllocatorFlags(0, kOnlyLocalPorts);
1997 SetAllocatorFlags(1, kOnlyLocalPorts);
1998
1999 // Create channels and let them go writable, as usual.
2000 CreateChannels(1);
2001 // Enable continual gathering.
2002 ep1_ch1()->SetIceConfig(CreateIceConfig(1000, true));
2003 ep2_ch1()->SetIceConfig(CreateIceConfig(1000, true));
2004 EXPECT_TRUE_WAIT_MARGIN(ep1_ch1()->receiving() && ep1_ch1()->writable() &&
2005 ep2_ch1()->receiving() && ep2_ch1()->writable(),
2006 kDefaultTimeout, kDefaultTimeout);
2007 EXPECT_TRUE(ep1_ch1()->best_connection() && ep2_ch1()->best_connection() &&
2008 LocalCandidate(ep1_ch1())->address().EqualIPs(wifi[0]) &&
2009 RemoteCandidate(ep1_ch1())->address().EqualIPs(wifi[1]));
2010
2011 // First destroy all backup connection.
2012 DestroyAllButBestConnection(ep1_ch1());
2013 // Then the interface of the best connection goes away.
2014 RemoveAddress(0, wifi[0]);
2015 EXPECT_TRUE_WAIT(
2016 ep1_ch1()->best_connection() && ep2_ch1()->best_connection() &&
2017 LocalCandidate(ep1_ch1())->address().EqualIPs(cellular[0]) &&
2018 RemoteCandidate(ep1_ch1())->address().EqualIPs(wifi[1]),
2019 kDefaultTimeout);
2020
2021 DestroyChannels();
2022 }
2023
2024 // Tests that the backup connection will be restored after it is destroyed.
2025 TEST_F(P2PTransportChannelMultihomedTest, TestRestoreBackupConnection) {
2026 auto& wifi = kAlternateAddrs;
2027 auto& cellular = kPublicAddrs;
2028 AddAddress(0, wifi[0], "test_wifi0", rtc::ADAPTER_TYPE_WIFI);
2029 AddAddress(0, cellular[0], "test_cell0", rtc::ADAPTER_TYPE_CELLULAR);
2030 AddAddress(1, wifi[1], "test_wifi1", rtc::ADAPTER_TYPE_WIFI);
2031 AddAddress(1, cellular[1], "test_cell1", rtc::ADAPTER_TYPE_CELLULAR);
2032 // Use only local ports for simplicity.
2033 SetAllocatorFlags(0, kOnlyLocalPorts);
2034 SetAllocatorFlags(1, kOnlyLocalPorts);
2035
2036 // Create channels and let them go writable, as usual.
2037 CreateChannels(1);
2038 ep1_ch1()->SetIceConfig(CreateIceConfig(1000, true));
2039 ep2_ch1()->SetIceConfig(CreateIceConfig(1000, true));
2040 EXPECT_TRUE_WAIT_MARGIN(ep1_ch1()->receiving() && ep1_ch1()->writable() &&
2041 ep2_ch1()->receiving() && ep2_ch1()->writable(),
2042 kDefaultTimeout, kDefaultTimeout);
2043 EXPECT_TRUE(ep1_ch1()->best_connection() && ep2_ch1()->best_connection() &&
2044 LocalCandidate(ep1_ch1())->address().EqualIPs(wifi[0]) &&
2045 RemoteCandidate(ep1_ch1())->address().EqualIPs(wifi[1]));
2046
2047 // Destroy all backup connections.
2048 ep1_ch1()->set_check_restore_backup_connection_interval(2000);
2049 DestroyAllButBestConnection(ep1_ch1());
2050 // Ensure the backup connection is removed first.
2051 EXPECT_TRUE_WAIT(
2052 GetConnectionWithLocalAddress(ep1_ch1(), cellular[0]) == nullptr,
2053 kDefaultTimeout);
2054 const cricket::Connection* conn;
2055 EXPECT_TRUE_WAIT(
2056 (conn = GetConnectionWithLocalAddress(ep1_ch1(), cellular[0])) &&
2057 conn != ep1_ch1()->best_connection() && conn->writable(),
2058 5000);
2059
2060 DestroyChannels();
2061 }
1899 2062
1900 // A collection of tests which tests a single P2PTransportChannel by sending 2063 // A collection of tests which tests a single P2PTransportChannel by sending
1901 // pings. 2064 // pings.
1902 class P2PTransportChannelPingTest : public testing::Test, 2065 class P2PTransportChannelPingTest : public testing::Test,
1903 public sigslot::has_slots<> { 2066 public sigslot::has_slots<> {
1904 public: 2067 public:
1905 P2PTransportChannelPingTest() 2068 P2PTransportChannelPingTest()
1906 : pss_(new rtc::PhysicalSocketServer), 2069 : pss_(new rtc::PhysicalSocketServer),
1907 vss_(new rtc::VirtualSocketServer(pss_.get())), 2070 vss_(new rtc::VirtualSocketServer(pss_.get())),
1908 ss_scope_(vss_.get()) {} 2071 ss_scope_(vss_.get()) {}
(...skipping 1006 matching lines...) Expand 10 before | Expand all | Expand 10 after
2915 3078
2916 // TCP Relay/Relay is the next. 3079 // TCP Relay/Relay is the next.
2917 VerifyNextPingableConnection(cricket::RELAY_PORT_TYPE, 3080 VerifyNextPingableConnection(cricket::RELAY_PORT_TYPE,
2918 cricket::RELAY_PORT_TYPE, 3081 cricket::RELAY_PORT_TYPE,
2919 cricket::TCP_PROTOCOL_NAME); 3082 cricket::TCP_PROTOCOL_NAME);
2920 3083
2921 // Finally, Local/Relay will be pinged. 3084 // Finally, Local/Relay will be pinged.
2922 VerifyNextPingableConnection(cricket::LOCAL_PORT_TYPE, 3085 VerifyNextPingableConnection(cricket::LOCAL_PORT_TYPE,
2923 cricket::RELAY_PORT_TYPE); 3086 cricket::RELAY_PORT_TYPE);
2924 } 3087 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698