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 332 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
343 channel->SignalReadyToSend.connect( | 343 channel->SignalReadyToSend.connect( |
344 this, &P2PTransportChannelTestBase::OnReadyToSend); | 344 this, &P2PTransportChannelTestBase::OnReadyToSend); |
345 channel->SignalCandidateGathered.connect( | 345 channel->SignalCandidateGathered.connect( |
346 this, &P2PTransportChannelTestBase::OnCandidateGathered); | 346 this, &P2PTransportChannelTestBase::OnCandidateGathered); |
347 channel->SignalCandidatesRemoved.connect( | 347 channel->SignalCandidatesRemoved.connect( |
348 this, &P2PTransportChannelTestBase::OnCandidatesRemoved); | 348 this, &P2PTransportChannelTestBase::OnCandidatesRemoved); |
349 channel->SignalReadPacket.connect( | 349 channel->SignalReadPacket.connect( |
350 this, &P2PTransportChannelTestBase::OnReadPacket); | 350 this, &P2PTransportChannelTestBase::OnReadPacket); |
351 channel->SignalRoleConflict.connect( | 351 channel->SignalRoleConflict.connect( |
352 this, &P2PTransportChannelTestBase::OnRoleConflict); | 352 this, &P2PTransportChannelTestBase::OnRoleConflict); |
| 353 channel->SignalSelectedCandidatePairChanged.connect( |
| 354 this, &P2PTransportChannelTestBase::OnSelectedCandidatePairChanged); |
353 channel->SetIceCredentials(local_ice_ufrag, local_ice_pwd); | 355 channel->SetIceCredentials(local_ice_ufrag, local_ice_pwd); |
354 if (remote_ice_credential_source_ == FROM_SETICECREDENTIALS) { | 356 if (remote_ice_credential_source_ == FROM_SETICECREDENTIALS) { |
355 channel->SetRemoteIceCredentials(remote_ice_ufrag, remote_ice_pwd); | 357 channel->SetRemoteIceCredentials(remote_ice_ufrag, remote_ice_pwd); |
356 } | 358 } |
357 channel->SetIceRole(GetEndpoint(endpoint)->ice_role()); | 359 channel->SetIceRole(GetEndpoint(endpoint)->ice_role()); |
358 channel->SetIceTiebreaker(GetEndpoint(endpoint)->GetIceTiebreaker()); | 360 channel->SetIceTiebreaker(GetEndpoint(endpoint)->GetIceTiebreaker()); |
359 return channel; | 361 return channel; |
360 } | 362 } |
361 void DestroyChannels() { | 363 void DestroyChannels() { |
362 ep1_.cd1_.ch_.reset(); | 364 ep1_.cd1_.ch_.reset(); |
(...skipping 318 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
681 return; | 683 return; |
682 | 684 |
683 if (GetEndpoint(ch)->save_candidates_) { | 685 if (GetEndpoint(ch)->save_candidates_) { |
684 GetEndpoint(ch)->saved_candidates_.push_back( | 686 GetEndpoint(ch)->saved_candidates_.push_back( |
685 std::unique_ptr<CandidatesData>(new CandidatesData(ch, c))); | 687 std::unique_ptr<CandidatesData>(new CandidatesData(ch, c))); |
686 } else { | 688 } else { |
687 main_->Post(RTC_FROM_HERE, this, MSG_ADD_CANDIDATES, | 689 main_->Post(RTC_FROM_HERE, this, MSG_ADD_CANDIDATES, |
688 new CandidatesData(ch, c)); | 690 new CandidatesData(ch, c)); |
689 } | 691 } |
690 } | 692 } |
| 693 void OnSelectedCandidatePairChanged( |
| 694 TransportChannel* transport_channel, |
| 695 CandidatePairInterface* selected_candidate_pair, |
| 696 int last_sent_packet_id, |
| 697 bool ready_to_send) { |
| 698 ++selected_candidate_pair_switches_; |
| 699 } |
| 700 |
| 701 int get_and_reset_selected_candidate_pair_switches() { |
| 702 int switches = selected_candidate_pair_switches_; |
| 703 selected_candidate_pair_switches_ = 0; |
| 704 return switches; |
| 705 } |
691 | 706 |
692 void PauseCandidates(int endpoint) { | 707 void PauseCandidates(int endpoint) { |
693 GetEndpoint(endpoint)->save_candidates_ = true; | 708 GetEndpoint(endpoint)->save_candidates_ = true; |
694 } | 709 } |
695 | 710 |
696 void OnCandidatesRemoved(TransportChannelImpl* ch, | 711 void OnCandidatesRemoved(TransportChannelImpl* ch, |
697 const std::vector<Candidate>& candidates) { | 712 const std::vector<Candidate>& candidates) { |
698 // Candidate removals are not paused. | 713 // Candidate removals are not paused. |
699 CandidatesData* candidates_data = new CandidatesData(ch, candidates); | 714 CandidatesData* candidates_data = new CandidatesData(ch, candidates); |
700 main_->Post(RTC_FROM_HERE, this, MSG_REMOVE_CANDIDATES, candidates_data); | 715 main_->Post(RTC_FROM_HERE, this, MSG_REMOVE_CANDIDATES, candidates_data); |
(...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
843 rtc::SocketServerScope ss_scope_; | 858 rtc::SocketServerScope ss_scope_; |
844 std::unique_ptr<TestStunServer> stun_server_; | 859 std::unique_ptr<TestStunServer> stun_server_; |
845 TestTurnServer turn_server_; | 860 TestTurnServer turn_server_; |
846 TestRelayServer relay_server_; | 861 TestRelayServer relay_server_; |
847 rtc::SocksProxyServer socks_server1_; | 862 rtc::SocksProxyServer socks_server1_; |
848 rtc::SocksProxyServer socks_server2_; | 863 rtc::SocksProxyServer socks_server2_; |
849 Endpoint ep1_; | 864 Endpoint ep1_; |
850 Endpoint ep2_; | 865 Endpoint ep2_; |
851 RemoteIceCredentialSource remote_ice_credential_source_ = FROM_CANDIDATE; | 866 RemoteIceCredentialSource remote_ice_credential_source_ = FROM_CANDIDATE; |
852 bool force_relay_; | 867 bool force_relay_; |
| 868 int selected_candidate_pair_switches_ = 0; |
853 }; | 869 }; |
854 | 870 |
855 // The tests have only a few outcomes, which we predefine. | 871 // The tests have only a few outcomes, which we predefine. |
856 const P2PTransportChannelTestBase::Result P2PTransportChannelTestBase:: | 872 const P2PTransportChannelTestBase::Result P2PTransportChannelTestBase:: |
857 kLocalUdpToLocalUdp("local", "udp", "local", "udp", | 873 kLocalUdpToLocalUdp("local", "udp", "local", "udp", |
858 "local", "udp", "local", "udp", 1000); | 874 "local", "udp", "local", "udp", 1000); |
859 const P2PTransportChannelTestBase::Result P2PTransportChannelTestBase:: | 875 const P2PTransportChannelTestBase::Result P2PTransportChannelTestBase:: |
860 kLocalUdpToStunUdp("local", "udp", "stun", "udp", | 876 kLocalUdpToStunUdp("local", "udp", "stun", "udp", |
861 "local", "udp", "stun", "udp", 1000); | 877 "local", "udp", "stun", "udp", 1000); |
862 const P2PTransportChannelTestBase::Result P2PTransportChannelTestBase:: | 878 const P2PTransportChannelTestBase::Result P2PTransportChannelTestBase:: |
(...skipping 997 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1860 AddAddress(0, kPublicAddrs[0]); | 1876 AddAddress(0, kPublicAddrs[0]); |
1861 AddAddress(0, kAlternateAddrs[0]); | 1877 AddAddress(0, kAlternateAddrs[0]); |
1862 AddAddress(1, kPublicAddrs[1]); | 1878 AddAddress(1, kPublicAddrs[1]); |
1863 AddAddress(1, kAlternateAddrs[1]); | 1879 AddAddress(1, kAlternateAddrs[1]); |
1864 Test(kLocalUdpToLocalUdp); | 1880 Test(kLocalUdpToLocalUdp); |
1865 } | 1881 } |
1866 | 1882 |
1867 // Test that we can quickly switch links if an interface goes down. | 1883 // Test that we can quickly switch links if an interface goes down. |
1868 // The controlled side has two interfaces and one will die. | 1884 // The controlled side has two interfaces and one will die. |
1869 TEST_F(P2PTransportChannelMultihomedTest, TestFailoverControlledSide) { | 1885 TEST_F(P2PTransportChannelMultihomedTest, TestFailoverControlledSide) { |
| 1886 rtc::ScopedFakeClock clock; |
1870 AddAddress(0, kPublicAddrs[0]); | 1887 AddAddress(0, kPublicAddrs[0]); |
1871 // Adding alternate address will make sure |kPublicAddrs| has the higher | 1888 // Adding alternate address will make sure |kPublicAddrs| has the higher |
1872 // priority than others. This is due to FakeNetwork::AddInterface method. | 1889 // priority than others. This is due to FakeNetwork::AddInterface method. |
1873 AddAddress(1, kAlternateAddrs[1]); | 1890 AddAddress(1, kAlternateAddrs[1]); |
1874 AddAddress(1, kPublicAddrs[1]); | 1891 AddAddress(1, kPublicAddrs[1]); |
1875 | 1892 |
1876 // Use only local ports for simplicity. | 1893 // Use only local ports for simplicity. |
1877 SetAllocatorFlags(0, kOnlyLocalPorts); | 1894 SetAllocatorFlags(0, kOnlyLocalPorts); |
1878 SetAllocatorFlags(1, kOnlyLocalPorts); | 1895 SetAllocatorFlags(1, kOnlyLocalPorts); |
1879 | 1896 |
1880 // Create channels and let them go writable, as usual. | 1897 // Create channels and let them go writable, as usual. |
1881 CreateChannels(1); | 1898 CreateChannels(1); |
1882 | 1899 |
1883 EXPECT_TRUE_WAIT_MARGIN(ep1_ch1()->receiving() && ep1_ch1()->writable() && | 1900 EXPECT_TRUE_SIMULATED_WAIT(ep1_ch1()->receiving() && ep1_ch1()->writable() && |
1884 ep2_ch1()->receiving() && ep2_ch1()->writable(), | 1901 ep2_ch1()->receiving() && |
1885 1000, 1000); | 1902 ep2_ch1()->writable(), |
| 1903 3000, clock); |
1886 EXPECT_TRUE(ep1_ch1()->selected_connection() && | 1904 EXPECT_TRUE(ep1_ch1()->selected_connection() && |
1887 ep2_ch1()->selected_connection() && | 1905 ep2_ch1()->selected_connection() && |
1888 LocalCandidate(ep1_ch1())->address().EqualIPs(kPublicAddrs[0]) && | 1906 LocalCandidate(ep1_ch1())->address().EqualIPs(kPublicAddrs[0]) && |
1889 RemoteCandidate(ep1_ch1())->address().EqualIPs(kPublicAddrs[1])); | 1907 RemoteCandidate(ep1_ch1())->address().EqualIPs(kPublicAddrs[1])); |
1890 | 1908 |
1891 // Make the receiving timeout shorter for testing. | 1909 // Make the receiving timeout shorter for testing. |
1892 IceConfig config = CreateIceConfig(1000, GATHER_ONCE); | 1910 IceConfig config = CreateIceConfig(1000, GATHER_ONCE); |
1893 ep1_ch1()->SetIceConfig(config); | 1911 ep1_ch1()->SetIceConfig(config); |
1894 ep2_ch1()->SetIceConfig(config); | 1912 ep2_ch1()->SetIceConfig(config); |
1895 | 1913 |
1896 // Blackhole any traffic to or from the public addrs. | 1914 // Blackhole any traffic to or from the public addrs. |
1897 LOG(LS_INFO) << "Failing over..."; | 1915 LOG(LS_INFO) << "Failing over..."; |
1898 fw()->AddRule(false, rtc::FP_ANY, rtc::FD_ANY, kPublicAddrs[1]); | 1916 fw()->AddRule(false, rtc::FP_ANY, rtc::FD_ANY, kPublicAddrs[1]); |
1899 // The selected connections will switch, so keep references to them. | 1917 // The selected connections may switch, so keep references to them. |
1900 const Connection* selected_connection1 = ep1_ch1()->selected_connection(); | 1918 const Connection* selected_connection1 = ep1_ch1()->selected_connection(); |
1901 const Connection* selected_connection2 = ep2_ch1()->selected_connection(); | 1919 const Connection* selected_connection2 = ep2_ch1()->selected_connection(); |
1902 // We should detect loss of receiving within 1 second or so. | 1920 // We should detect loss of receiving within 1 second or so. |
1903 EXPECT_TRUE_WAIT( | 1921 EXPECT_TRUE_SIMULATED_WAIT( |
1904 !selected_connection1->receiving() && !selected_connection2->receiving(), | 1922 !selected_connection1->receiving() && !selected_connection2->receiving(), |
1905 3000); | 1923 3000, clock); |
1906 | 1924 |
1907 // We should switch over to use the alternate addr immediately on both sides | 1925 // We should switch over to use the alternate addr immediately on both sides |
1908 // when we are not receiving. | 1926 // when we are not receiving. |
1909 EXPECT_TRUE_WAIT(ep1_ch1()->selected_connection()->receiving() && | 1927 EXPECT_TRUE_SIMULATED_WAIT(ep1_ch1()->selected_connection()->receiving() && |
1910 ep2_ch1()->selected_connection()->receiving(), | 1928 ep2_ch1()->selected_connection()->receiving(), |
1911 1000); | 1929 3000, clock); |
1912 EXPECT_TRUE(LocalCandidate(ep1_ch1())->address().EqualIPs(kPublicAddrs[0])); | 1930 EXPECT_TRUE(LocalCandidate(ep1_ch1())->address().EqualIPs(kPublicAddrs[0])); |
1913 EXPECT_TRUE( | 1931 EXPECT_TRUE( |
1914 RemoteCandidate(ep1_ch1())->address().EqualIPs(kAlternateAddrs[1])); | 1932 RemoteCandidate(ep1_ch1())->address().EqualIPs(kAlternateAddrs[1])); |
1915 EXPECT_TRUE( | 1933 EXPECT_TRUE( |
1916 LocalCandidate(ep2_ch1())->address().EqualIPs(kAlternateAddrs[1])); | 1934 LocalCandidate(ep2_ch1())->address().EqualIPs(kAlternateAddrs[1])); |
1917 | 1935 |
1918 DestroyChannels(); | 1936 DestroyChannels(); |
1919 } | 1937 } |
1920 | 1938 |
1921 // Test that we can quickly switch links if an interface goes down. | 1939 // Test that we can quickly switch links if an interface goes down. |
1922 // The controlling side has two interfaces and one will die. | 1940 // The controlling side has two interfaces and one will die. |
1923 TEST_F(P2PTransportChannelMultihomedTest, TestFailoverControllingSide) { | 1941 TEST_F(P2PTransportChannelMultihomedTest, TestFailoverControllingSide) { |
| 1942 rtc::ScopedFakeClock clock; |
1924 // Adding alternate address will make sure |kPublicAddrs| has the higher | 1943 // Adding alternate address will make sure |kPublicAddrs| has the higher |
1925 // priority than others. This is due to FakeNetwork::AddInterface method. | 1944 // priority than others. This is due to FakeNetwork::AddInterface method. |
1926 AddAddress(0, kAlternateAddrs[0]); | 1945 AddAddress(0, kAlternateAddrs[0]); |
1927 AddAddress(0, kPublicAddrs[0]); | 1946 AddAddress(0, kPublicAddrs[0]); |
1928 AddAddress(1, kPublicAddrs[1]); | 1947 AddAddress(1, kPublicAddrs[1]); |
1929 | 1948 |
1930 // Use only local ports for simplicity. | 1949 // Use only local ports for simplicity. |
1931 SetAllocatorFlags(0, kOnlyLocalPorts); | 1950 SetAllocatorFlags(0, kOnlyLocalPorts); |
1932 SetAllocatorFlags(1, kOnlyLocalPorts); | 1951 SetAllocatorFlags(1, kOnlyLocalPorts); |
1933 | 1952 |
1934 // Create channels and let them go writable, as usual. | 1953 // Create channels and let them go writable, as usual. |
1935 CreateChannels(1); | 1954 CreateChannels(1); |
1936 EXPECT_TRUE_WAIT_MARGIN(ep1_ch1()->receiving() && ep1_ch1()->writable() && | 1955 EXPECT_TRUE_SIMULATED_WAIT(ep1_ch1()->receiving() && ep1_ch1()->writable() && |
1937 ep2_ch1()->receiving() && ep2_ch1()->writable(), | 1956 ep2_ch1()->receiving() && |
1938 1000, 1000); | 1957 ep2_ch1()->writable(), |
| 1958 3000, clock); |
1939 EXPECT_TRUE(ep1_ch1()->selected_connection() && | 1959 EXPECT_TRUE(ep1_ch1()->selected_connection() && |
1940 ep2_ch1()->selected_connection() && | 1960 ep2_ch1()->selected_connection() && |
1941 LocalCandidate(ep1_ch1())->address().EqualIPs(kPublicAddrs[0]) && | 1961 LocalCandidate(ep1_ch1())->address().EqualIPs(kPublicAddrs[0]) && |
1942 RemoteCandidate(ep1_ch1())->address().EqualIPs(kPublicAddrs[1])); | 1962 RemoteCandidate(ep1_ch1())->address().EqualIPs(kPublicAddrs[1])); |
1943 | 1963 |
1944 // Make the receiving timeout shorter for testing. | 1964 // Make the receiving timeout shorter for testing. |
1945 IceConfig config = CreateIceConfig(1000, GATHER_ONCE); | 1965 IceConfig config = CreateIceConfig(1000, GATHER_ONCE); |
1946 ep1_ch1()->SetIceConfig(config); | 1966 ep1_ch1()->SetIceConfig(config); |
1947 ep2_ch1()->SetIceConfig(config); | 1967 ep2_ch1()->SetIceConfig(config); |
1948 | 1968 |
1949 // Blackhole any traffic to or from the public addrs. | 1969 // Blackhole any traffic to or from the public addrs. |
1950 LOG(LS_INFO) << "Failing over..."; | 1970 LOG(LS_INFO) << "Failing over..."; |
1951 fw()->AddRule(false, rtc::FP_ANY, rtc::FD_ANY, kPublicAddrs[0]); | 1971 fw()->AddRule(false, rtc::FP_ANY, rtc::FD_ANY, kPublicAddrs[0]); |
1952 // The selected connections will switch, so keep references to them. | 1972 // The selected connections will switch, so keep references to them. |
1953 const Connection* selected_connection1 = ep1_ch1()->selected_connection(); | 1973 const Connection* selected_connection1 = ep1_ch1()->selected_connection(); |
1954 const Connection* selected_connection2 = ep2_ch1()->selected_connection(); | 1974 const Connection* selected_connection2 = ep2_ch1()->selected_connection(); |
1955 // We should detect loss of receiving within 1 second or so. | 1975 // We should detect loss of receiving within 1 second or so. |
1956 EXPECT_TRUE_WAIT( | 1976 EXPECT_TRUE_SIMULATED_WAIT( |
1957 !selected_connection1->receiving() && !selected_connection2->receiving(), | 1977 !selected_connection1->receiving() && !selected_connection2->receiving(), |
1958 3000); | 1978 3000, clock); |
1959 | 1979 |
1960 // We should switch over to use the alternate addr immediately on both sides | 1980 // We should switch over to use the alternate addr on both sides |
1961 // when we are not receiving. | 1981 // when we are not receiving. |
1962 EXPECT_TRUE_WAIT(ep1_ch1()->selected_connection()->receiving() && | 1982 EXPECT_TRUE_SIMULATED_WAIT(ep1_ch1()->selected_connection()->receiving() && |
1963 ep2_ch1()->selected_connection()->receiving(), | 1983 ep2_ch1()->selected_connection()->receiving(), |
1964 1000); | 1984 3000, clock); |
1965 EXPECT_TRUE( | 1985 EXPECT_TRUE( |
1966 LocalCandidate(ep1_ch1())->address().EqualIPs(kAlternateAddrs[0])); | 1986 LocalCandidate(ep1_ch1())->address().EqualIPs(kAlternateAddrs[0])); |
1967 EXPECT_TRUE(RemoteCandidate(ep1_ch1())->address().EqualIPs(kPublicAddrs[1])); | 1987 EXPECT_TRUE(RemoteCandidate(ep1_ch1())->address().EqualIPs(kPublicAddrs[1])); |
1968 EXPECT_TRUE( | 1988 EXPECT_TRUE( |
1969 RemoteCandidate(ep2_ch1())->address().EqualIPs(kAlternateAddrs[0])); | 1989 RemoteCandidate(ep2_ch1())->address().EqualIPs(kAlternateAddrs[0])); |
1970 | 1990 |
1971 DestroyChannels(); | 1991 DestroyChannels(); |
1972 } | 1992 } |
1973 | 1993 |
| 1994 // Test that if an interface fails temporarily and then recovers quickly, |
| 1995 // the selected connection will not switch. |
| 1996 TEST_F(P2PTransportChannelMultihomedTest, |
| 1997 TestConnectionSwitchDampeningControlledSide) { |
| 1998 rtc::ScopedFakeClock clock; |
| 1999 AddAddress(0, kPublicAddrs[0]); |
| 2000 // Adding alternate address will make sure |kPublicAddrs| has the higher |
| 2001 // priority than others. This is due to FakeNetwork::AddInterface method. |
| 2002 AddAddress(1, kAlternateAddrs[1]); |
| 2003 AddAddress(1, kPublicAddrs[1]); |
| 2004 |
| 2005 // Use only local ports for simplicity. |
| 2006 SetAllocatorFlags(0, kOnlyLocalPorts); |
| 2007 SetAllocatorFlags(1, kOnlyLocalPorts); |
| 2008 |
| 2009 // Create channels and let them go writable, as usual. |
| 2010 CreateChannels(1); |
| 2011 |
| 2012 EXPECT_TRUE_SIMULATED_WAIT(ep1_ch1()->receiving() && ep1_ch1()->writable() && |
| 2013 ep2_ch1()->receiving() && |
| 2014 ep2_ch1()->writable(), |
| 2015 3000, clock); |
| 2016 EXPECT_TRUE(ep1_ch1()->selected_connection() && |
| 2017 ep2_ch1()->selected_connection() && |
| 2018 LocalCandidate(ep1_ch1())->address().EqualIPs(kPublicAddrs[0]) && |
| 2019 RemoteCandidate(ep1_ch1())->address().EqualIPs(kPublicAddrs[1])); |
| 2020 |
| 2021 // Make the receiving timeout shorter for testing. |
| 2022 IceConfig config = CreateIceConfig(1000, GATHER_ONCE); |
| 2023 ep1_ch1()->SetIceConfig(config); |
| 2024 ep2_ch1()->SetIceConfig(config); |
| 2025 get_and_reset_selected_candidate_pair_switches(); |
| 2026 |
| 2027 // Blackhole any traffic to or from the public addrs. |
| 2028 LOG(LS_INFO) << "Failing over..."; |
| 2029 fw()->AddRule(false, rtc::FP_ANY, rtc::FD_ANY, kPublicAddrs[1]); |
| 2030 |
| 2031 // The selected connections may switch, so keep references to them. |
| 2032 const Connection* selected_connection1 = ep1_ch1()->selected_connection(); |
| 2033 const Connection* selected_connection2 = ep2_ch1()->selected_connection(); |
| 2034 // We should detect loss of receiving within 1 second or so. |
| 2035 EXPECT_TRUE_SIMULATED_WAIT( |
| 2036 !selected_connection1->receiving() && !selected_connection2->receiving(), |
| 2037 3000, clock); |
| 2038 // After a short while, the link recovers itself. |
| 2039 SIMULATED_WAIT(false, 10, clock); |
| 2040 fw()->ClearRules(); |
| 2041 |
| 2042 // We should remain on the public address on both sides and no connection |
| 2043 // switches should have happened. |
| 2044 EXPECT_TRUE_SIMULATED_WAIT(ep1_ch1()->selected_connection()->receiving() && |
| 2045 ep2_ch1()->selected_connection()->receiving(), |
| 2046 3000, clock); |
| 2047 EXPECT_TRUE(RemoteCandidate(ep1_ch1())->address().EqualIPs(kPublicAddrs[1])); |
| 2048 EXPECT_TRUE(LocalCandidate(ep2_ch1())->address().EqualIPs(kPublicAddrs[1])); |
| 2049 EXPECT_EQ(0, get_and_reset_selected_candidate_pair_switches()); |
| 2050 |
| 2051 DestroyChannels(); |
| 2052 } |
| 2053 |
| 2054 // Test that if an interface fails temporarily and then recovers quickly, |
| 2055 // the selected connection will not switch. |
| 2056 TEST_F(P2PTransportChannelMultihomedTest, |
| 2057 TestConnectionSwitchDampeningControllingSide) { |
| 2058 rtc::ScopedFakeClock clock; |
| 2059 // Adding alternate address will make sure |kPublicAddrs| has the higher |
| 2060 // priority than others. This is due to FakeNetwork::AddInterface method. |
| 2061 AddAddress(0, kAlternateAddrs[0]); |
| 2062 AddAddress(0, kPublicAddrs[0]); |
| 2063 AddAddress(1, kPublicAddrs[1]); |
| 2064 |
| 2065 // Use only local ports for simplicity. |
| 2066 SetAllocatorFlags(0, kOnlyLocalPorts); |
| 2067 SetAllocatorFlags(1, kOnlyLocalPorts); |
| 2068 |
| 2069 // Create channels and let them go writable, as usual. |
| 2070 CreateChannels(1); |
| 2071 EXPECT_TRUE_SIMULATED_WAIT(ep1_ch1()->receiving() && ep1_ch1()->writable() && |
| 2072 ep2_ch1()->receiving() && |
| 2073 ep2_ch1()->writable(), |
| 2074 3000, clock); |
| 2075 EXPECT_TRUE(ep1_ch1()->selected_connection() && |
| 2076 ep2_ch1()->selected_connection() && |
| 2077 LocalCandidate(ep1_ch1())->address().EqualIPs(kPublicAddrs[0]) && |
| 2078 RemoteCandidate(ep1_ch1())->address().EqualIPs(kPublicAddrs[1])); |
| 2079 |
| 2080 // Make the receiving timeout shorter for testing. |
| 2081 IceConfig config = CreateIceConfig(1000, GATHER_ONCE); |
| 2082 ep1_ch1()->SetIceConfig(config); |
| 2083 ep2_ch1()->SetIceConfig(config); |
| 2084 get_and_reset_selected_candidate_pair_switches(); |
| 2085 |
| 2086 // Blackhole any traffic to or from the public addrs. |
| 2087 LOG(LS_INFO) << "Failing over..."; |
| 2088 fw()->AddRule(false, rtc::FP_ANY, rtc::FD_ANY, kPublicAddrs[0]); |
| 2089 // The selected connections may switch, so keep references to them. |
| 2090 const Connection* selected_connection1 = ep1_ch1()->selected_connection(); |
| 2091 const Connection* selected_connection2 = ep2_ch1()->selected_connection(); |
| 2092 // We should detect loss of receiving within 1 second or so. |
| 2093 EXPECT_TRUE_SIMULATED_WAIT( |
| 2094 !selected_connection1->receiving() && !selected_connection2->receiving(), |
| 2095 3000, clock); |
| 2096 // The link recovers after a short while. |
| 2097 SIMULATED_WAIT(false, 10, clock); |
| 2098 fw()->ClearRules(); |
| 2099 |
| 2100 // We should not switch to the alternate addr on both sides because of the |
| 2101 // dampening. |
| 2102 EXPECT_TRUE_SIMULATED_WAIT(ep1_ch1()->selected_connection()->receiving() && |
| 2103 ep2_ch1()->selected_connection()->receiving(), |
| 2104 3000, clock); |
| 2105 EXPECT_TRUE(LocalCandidate(ep1_ch1())->address().EqualIPs(kPublicAddrs[0])); |
| 2106 EXPECT_TRUE(RemoteCandidate(ep2_ch1())->address().EqualIPs(kPublicAddrs[0])); |
| 2107 EXPECT_EQ(0, get_and_reset_selected_candidate_pair_switches()); |
| 2108 DestroyChannels(); |
| 2109 } |
| 2110 |
1974 // Tests that a Wifi-Wifi connection has the highest precedence. | 2111 // Tests that a Wifi-Wifi connection has the highest precedence. |
1975 TEST_F(P2PTransportChannelMultihomedTest, TestPreferWifiToWifiConnection) { | 2112 TEST_F(P2PTransportChannelMultihomedTest, TestPreferWifiToWifiConnection) { |
1976 // The interface names are chosen so that |cellular| would have higher | 2113 // The interface names are chosen so that |cellular| would have higher |
1977 // candidate priority if it is not for the network type. | 2114 // candidate priority if it is not for the network type. |
1978 auto& wifi = kAlternateAddrs; | 2115 auto& wifi = kAlternateAddrs; |
1979 auto& cellular = kPublicAddrs; | 2116 auto& cellular = kPublicAddrs; |
1980 AddAddress(0, wifi[0], "test0", rtc::ADAPTER_TYPE_WIFI); | 2117 AddAddress(0, wifi[0], "test0", rtc::ADAPTER_TYPE_WIFI); |
1981 AddAddress(0, cellular[0], "test1", rtc::ADAPTER_TYPE_CELLULAR); | 2118 AddAddress(0, cellular[0], "test1", rtc::ADAPTER_TYPE_CELLULAR); |
1982 AddAddress(1, wifi[1], "test0", rtc::ADAPTER_TYPE_WIFI); | 2119 AddAddress(1, wifi[1], "test0", rtc::ADAPTER_TYPE_WIFI); |
1983 AddAddress(1, cellular[1], "test1", rtc::ADAPTER_TYPE_CELLULAR); | 2120 AddAddress(1, cellular[1], "test1", rtc::ADAPTER_TYPE_CELLULAR); |
(...skipping 1682 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3666 | 3803 |
3667 // TCP Relay/Relay is the next. | 3804 // TCP Relay/Relay is the next. |
3668 VerifyNextPingableConnection(RELAY_PORT_TYPE, RELAY_PORT_TYPE, | 3805 VerifyNextPingableConnection(RELAY_PORT_TYPE, RELAY_PORT_TYPE, |
3669 TCP_PROTOCOL_NAME); | 3806 TCP_PROTOCOL_NAME); |
3670 | 3807 |
3671 // Finally, Local/Relay will be pinged. | 3808 // Finally, Local/Relay will be pinged. |
3672 VerifyNextPingableConnection(LOCAL_PORT_TYPE, RELAY_PORT_TYPE); | 3809 VerifyNextPingableConnection(LOCAL_PORT_TYPE, RELAY_PORT_TYPE); |
3673 } | 3810 } |
3674 | 3811 |
3675 } // namespace cricket { | 3812 } // namespace cricket { |
OLD | NEW |