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 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 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 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, 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 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, 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 457 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2441 channel_state_ = channel->GetState(); | 2578 channel_state_ = channel->GetState(); |
2442 } | 2579 } |
2443 | 2580 |
2444 CandidatePairInterface* last_selected_candidate_pair() { | 2581 CandidatePairInterface* last_selected_candidate_pair() { |
2445 return last_selected_candidate_pair_; | 2582 return last_selected_candidate_pair_; |
2446 } | 2583 } |
2447 int last_sent_packet_id() { return last_sent_packet_id_; } | 2584 int last_sent_packet_id() { return last_sent_packet_id_; } |
2448 bool channel_ready_to_send() { return channel_ready_to_send_; } | 2585 bool channel_ready_to_send() { return channel_ready_to_send_; } |
2449 void reset_channel_ready_to_send() { channel_ready_to_send_ = false; } | 2586 void reset_channel_ready_to_send() { channel_ready_to_send_ = false; } |
2450 TransportChannelState channel_state() { return channel_state_; } | 2587 TransportChannelState channel_state() { return channel_state_; } |
2451 int get_and_reset_selected_candidate_pair_switches() { | 2588 int reset_selected_candidate_pair_switches() { |
2452 int switches = selected_candidate_pair_switches_; | 2589 int switches = selected_candidate_pair_switches_; |
2453 selected_candidate_pair_switches_ = 0; | 2590 selected_candidate_pair_switches_ = 0; |
2454 return switches; | 2591 return switches; |
2455 } | 2592 } |
2456 | 2593 |
2457 private: | 2594 private: |
2458 std::unique_ptr<rtc::PhysicalSocketServer> pss_; | 2595 std::unique_ptr<rtc::PhysicalSocketServer> pss_; |
2459 std::unique_ptr<rtc::VirtualSocketServer> vss_; | 2596 std::unique_ptr<rtc::VirtualSocketServer> vss_; |
2460 rtc::SocketServerScope ss_scope_; | 2597 rtc::SocketServerScope ss_scope_; |
2461 CandidatePairInterface* last_selected_candidate_pair_ = nullptr; | 2598 CandidatePairInterface* last_selected_candidate_pair_ = nullptr; |
(...skipping 586 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3048 ch.MaybeStartGathering(); | 3185 ch.MaybeStartGathering(); |
3049 // The connections have decreasing priority. | 3186 // The connections have decreasing priority. |
3050 Connection* conn1 = | 3187 Connection* conn1 = |
3051 CreateConnectionWithCandidate(ch, clock, "1.1.1.1", 1, 10, true); | 3188 CreateConnectionWithCandidate(ch, clock, "1.1.1.1", 1, 10, true); |
3052 ASSERT_TRUE(conn1 != nullptr); | 3189 ASSERT_TRUE(conn1 != nullptr); |
3053 Connection* conn2 = | 3190 Connection* conn2 = |
3054 CreateConnectionWithCandidate(ch, clock, "2.2.2.2", 2, 9, true); | 3191 CreateConnectionWithCandidate(ch, clock, "2.2.2.2", 2, 9, true); |
3055 ASSERT_TRUE(conn2 != nullptr); | 3192 ASSERT_TRUE(conn2 != nullptr); |
3056 | 3193 |
3057 // Initially, connections are selected based on priority. | 3194 // Initially, connections are selected based on priority. |
3058 EXPECT_EQ(1, get_and_reset_selected_candidate_pair_switches()); | 3195 EXPECT_EQ(1, reset_selected_candidate_pair_switches()); |
3059 EXPECT_EQ(conn1, last_selected_candidate_pair()); | 3196 EXPECT_EQ(conn1, last_selected_candidate_pair()); |
3060 | 3197 |
3061 // conn2 receives data; it becomes selected. | 3198 // conn2 receives data; it becomes selected. |
3062 // Advance the clock by 1ms so that the last data receiving timestamp of | 3199 // Advance the clock by 1ms so that the last data receiving timestamp of |
3063 // conn2 is larger. | 3200 // conn2 is larger. |
3064 SIMULATED_WAIT(false, 1, clock); | 3201 SIMULATED_WAIT(false, 1, clock); |
3065 conn2->OnReadPacket("XYZ", 3, rtc::CreatePacketTime(0)); | 3202 conn2->OnReadPacket("XYZ", 3, rtc::CreatePacketTime(0)); |
3066 EXPECT_EQ(1, get_and_reset_selected_candidate_pair_switches()); | 3203 EXPECT_EQ(1, reset_selected_candidate_pair_switches()); |
3067 EXPECT_EQ(conn2, last_selected_candidate_pair()); | 3204 EXPECT_EQ(conn2, last_selected_candidate_pair()); |
3068 | 3205 |
3069 // conn1 also receives data; it becomes selected due to priority again. | 3206 // conn1 also receives data; it becomes selected due to priority again. |
3070 conn1->OnReadPacket("XYZ", 3, rtc::CreatePacketTime(0)); | 3207 conn1->OnReadPacket("XYZ", 3, rtc::CreatePacketTime(0)); |
3071 EXPECT_EQ(1, get_and_reset_selected_candidate_pair_switches()); | 3208 EXPECT_EQ(1, reset_selected_candidate_pair_switches()); |
3072 EXPECT_EQ(conn1, last_selected_candidate_pair()); | 3209 EXPECT_EQ(conn1, last_selected_candidate_pair()); |
3073 | 3210 |
3074 // Make sure sorting won't reselect candidate pair. | 3211 // Make sure sorting won't reselect candidate pair. |
3075 SIMULATED_WAIT(false, 10, clock); | 3212 SIMULATED_WAIT(false, 10, clock); |
3076 EXPECT_EQ(0, get_and_reset_selected_candidate_pair_switches()); | 3213 EXPECT_EQ(0, reset_selected_candidate_pair_switches()); |
3077 } | 3214 } |
3078 | 3215 |
3079 TEST_F(P2PTransportChannelPingTest, | 3216 TEST_F(P2PTransportChannelPingTest, |
3080 TestControlledAgentNominationTakesHigherPrecedenceThanDataReceiving) { | 3217 TestControlledAgentNominationTakesHigherPrecedenceThanDataReceiving) { |
3081 rtc::ScopedFakeClock clock; | 3218 rtc::ScopedFakeClock clock; |
3082 | 3219 |
3083 FakePortAllocator pa(rtc::Thread::Current(), nullptr); | 3220 FakePortAllocator pa(rtc::Thread::Current(), nullptr); |
3084 P2PTransportChannel ch("SwitchSelectedConnection", 1, &pa); | 3221 P2PTransportChannel ch("SwitchSelectedConnection", 1, &pa); |
3085 PrepareChannel(&ch); | 3222 PrepareChannel(&ch); |
3086 ch.SetIceRole(ICEROLE_CONTROLLED); | 3223 ch.SetIceRole(ICEROLE_CONTROLLED); |
3087 ch.MaybeStartGathering(); | 3224 ch.MaybeStartGathering(); |
3088 // The connections have decreasing priority. | 3225 // The connections have decreasing priority. |
3089 Connection* conn1 = | 3226 Connection* conn1 = |
3090 CreateConnectionWithCandidate(ch, clock, "1.1.1.1", 1, 10, false); | 3227 CreateConnectionWithCandidate(ch, clock, "1.1.1.1", 1, 10, false); |
3091 ASSERT_TRUE(conn1 != nullptr); | 3228 ASSERT_TRUE(conn1 != nullptr); |
3092 Connection* conn2 = | 3229 Connection* conn2 = |
3093 CreateConnectionWithCandidate(ch, clock, "2.2.2.2", 2, 9, false); | 3230 CreateConnectionWithCandidate(ch, clock, "2.2.2.2", 2, 9, false); |
3094 ASSERT_TRUE(conn2 != nullptr); | 3231 ASSERT_TRUE(conn2 != nullptr); |
3095 | 3232 |
3096 // conn1 received data; it is the selected connection. | 3233 // conn1 received data; it is the selected connection. |
3097 // Advance the clock to have a non-zero last-data-receiving time. | 3234 // Advance the clock to have a non-zero last-data-receiving time. |
3098 SIMULATED_WAIT(false, 1, clock); | 3235 SIMULATED_WAIT(false, 1, clock); |
3099 conn1->OnReadPacket("XYZ", 3, rtc::CreatePacketTime(0)); | 3236 conn1->OnReadPacket("XYZ", 3, rtc::CreatePacketTime(0)); |
3100 EXPECT_EQ(1, get_and_reset_selected_candidate_pair_switches()); | 3237 EXPECT_EQ(1, reset_selected_candidate_pair_switches()); |
3101 EXPECT_EQ(conn1, last_selected_candidate_pair()); | 3238 EXPECT_EQ(conn1, last_selected_candidate_pair()); |
3102 | 3239 |
3103 // conn2 is nominated; it becomes the selected connection. | 3240 // conn2 is nominated; it becomes the selected connection. |
3104 NominateConnection(conn2); | 3241 NominateConnection(conn2); |
3105 EXPECT_EQ(1, get_and_reset_selected_candidate_pair_switches()); | 3242 EXPECT_EQ(1, reset_selected_candidate_pair_switches()); |
3106 EXPECT_EQ(conn2, last_selected_candidate_pair()); | 3243 EXPECT_EQ(conn2, last_selected_candidate_pair()); |
3107 | 3244 |
3108 NominateConnection(conn1); | 3245 NominateConnection(conn1); |
3109 EXPECT_EQ(1, get_and_reset_selected_candidate_pair_switches()); | 3246 EXPECT_EQ(1, reset_selected_candidate_pair_switches()); |
3110 EXPECT_EQ(conn1, last_selected_candidate_pair()); | 3247 EXPECT_EQ(conn1, last_selected_candidate_pair()); |
3111 | 3248 |
3112 // conn2 received data more recently; it is selected now because it | 3249 // conn2 received data more recently; it is selected now because it |
3113 // received data more recently. | 3250 // received data more recently. |
3114 SIMULATED_WAIT(false, 1, clock); | 3251 SIMULATED_WAIT(false, 1, clock); |
3115 conn2->OnReadPacket("XYZ", 3, rtc::CreatePacketTime(0)); | 3252 conn2->OnReadPacket("XYZ", 3, rtc::CreatePacketTime(0)); |
3116 EXPECT_EQ(1, get_and_reset_selected_candidate_pair_switches()); | 3253 EXPECT_EQ(1, reset_selected_candidate_pair_switches()); |
3117 EXPECT_EQ(conn2, last_selected_candidate_pair()); | 3254 EXPECT_EQ(conn2, last_selected_candidate_pair()); |
3118 | 3255 |
3119 // Make sure sorting won't reselect candidate pair. | 3256 // Make sure sorting won't reselect candidate pair. |
3120 SIMULATED_WAIT(false, 10, clock); | 3257 SIMULATED_WAIT(false, 10, clock); |
3121 EXPECT_EQ(0, get_and_reset_selected_candidate_pair_switches()); | 3258 EXPECT_EQ(0, reset_selected_candidate_pair_switches()); |
3122 } | 3259 } |
3123 | 3260 |
3124 TEST_F(P2PTransportChannelPingTest, | 3261 TEST_F(P2PTransportChannelPingTest, |
3125 TestControlledAgentWriteStateTakesHigherPrecedenceThanNomination) { | 3262 TestControlledAgentWriteStateTakesHigherPrecedenceThanNomination) { |
3126 rtc::ScopedFakeClock clock; | 3263 rtc::ScopedFakeClock clock; |
3127 | 3264 |
3128 FakePortAllocator pa(rtc::Thread::Current(), nullptr); | 3265 FakePortAllocator pa(rtc::Thread::Current(), nullptr); |
3129 P2PTransportChannel ch("SwitchSelectedConnection", 1, &pa); | 3266 P2PTransportChannel ch("SwitchSelectedConnection", 1, &pa); |
3130 PrepareChannel(&ch); | 3267 PrepareChannel(&ch); |
3131 ch.SetIceRole(ICEROLE_CONTROLLED); | 3268 ch.SetIceRole(ICEROLE_CONTROLLED); |
3132 ch.MaybeStartGathering(); | 3269 ch.MaybeStartGathering(); |
3133 // The connections have decreasing priority. | 3270 // The connections have decreasing priority. |
3134 Connection* conn1 = | 3271 Connection* conn1 = |
3135 CreateConnectionWithCandidate(ch, clock, "1.1.1.1", 1, 10, false); | 3272 CreateConnectionWithCandidate(ch, clock, "1.1.1.1", 1, 10, false); |
3136 ASSERT_TRUE(conn1 != nullptr); | 3273 ASSERT_TRUE(conn1 != nullptr); |
3137 Connection* conn2 = | 3274 Connection* conn2 = |
3138 CreateConnectionWithCandidate(ch, clock, "2.2.2.2", 2, 9, false); | 3275 CreateConnectionWithCandidate(ch, clock, "2.2.2.2", 2, 9, false); |
3139 ASSERT_TRUE(conn2 != nullptr); | 3276 ASSERT_TRUE(conn2 != nullptr); |
3140 | 3277 |
3141 NominateConnection(conn1); | 3278 NominateConnection(conn1); |
3142 EXPECT_EQ(1, get_and_reset_selected_candidate_pair_switches()); | 3279 EXPECT_EQ(1, reset_selected_candidate_pair_switches()); |
3143 | 3280 |
3144 // conn2 becomes writable; it is selected even though it is not nominated. | 3281 // conn2 becomes writable; it is selected even though it is not nominated. |
3145 conn2->ReceivedPingResponse(LOW_RTT); | 3282 conn2->ReceivedPingResponse(LOW_RTT); |
3146 | 3283 |
3147 EXPECT_EQ_SIMULATED_WAIT(1, get_and_reset_selected_candidate_pair_switches(), | 3284 EXPECT_EQ_SIMULATED_WAIT(1, reset_selected_candidate_pair_switches(), |
3148 kDefaultTimeout, clock); | 3285 kDefaultTimeout, clock); |
3149 EXPECT_EQ_SIMULATED_WAIT(conn2, last_selected_candidate_pair(), | 3286 EXPECT_EQ_SIMULATED_WAIT(conn2, last_selected_candidate_pair(), |
3150 kDefaultTimeout, clock); | 3287 kDefaultTimeout, clock); |
3151 | 3288 |
3152 // If conn1 is also writable, it will become selected. | 3289 // If conn1 is also writable, it will become selected. |
3153 conn1->ReceivedPingResponse(LOW_RTT); | 3290 conn1->ReceivedPingResponse(LOW_RTT); |
3154 EXPECT_EQ_SIMULATED_WAIT(1, get_and_reset_selected_candidate_pair_switches(), | 3291 EXPECT_EQ_SIMULATED_WAIT(1, reset_selected_candidate_pair_switches(), |
3155 kDefaultTimeout, clock); | 3292 kDefaultTimeout, clock); |
3156 EXPECT_EQ_SIMULATED_WAIT(conn1, last_selected_candidate_pair(), | 3293 EXPECT_EQ_SIMULATED_WAIT(conn1, last_selected_candidate_pair(), |
3157 kDefaultTimeout, clock); | 3294 kDefaultTimeout, clock); |
3158 | 3295 |
3159 // Make sure sorting won't reselect candidate pair. | 3296 // Make sure sorting won't reselect candidate pair. |
3160 SIMULATED_WAIT(false, 10, clock); | 3297 SIMULATED_WAIT(false, 10, clock); |
3161 EXPECT_EQ(0, get_and_reset_selected_candidate_pair_switches()); | 3298 EXPECT_EQ(0, reset_selected_candidate_pair_switches()); |
3162 } | 3299 } |
3163 | 3300 |
3164 // Test that if a new remote candidate has the same address and port with | 3301 // Test that if a new remote candidate has the same address and port with |
3165 // an old one, it will be used to create a new connection. | 3302 // an old one, it will be used to create a new connection. |
3166 TEST_F(P2PTransportChannelPingTest, TestAddRemoteCandidateWithAddressReuse) { | 3303 TEST_F(P2PTransportChannelPingTest, TestAddRemoteCandidateWithAddressReuse) { |
3167 FakePortAllocator pa(rtc::Thread::Current(), nullptr); | 3304 FakePortAllocator pa(rtc::Thread::Current(), nullptr); |
3168 P2PTransportChannel ch("candidate reuse", 1, &pa); | 3305 P2PTransportChannel ch("candidate reuse", 1, &pa); |
3169 PrepareChannel(&ch); | 3306 PrepareChannel(&ch); |
3170 ch.MaybeStartGathering(); | 3307 ch.MaybeStartGathering(); |
3171 const std::string host_address = "1.1.1.1"; | 3308 const std::string host_address = "1.1.1.1"; |
(...skipping 494 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 |