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() { | |
pthatcher1
2016/07/13 21:17:22
Just call this reset_selected_candidate_pair_switc
honghaiz3
2016/07/14 04:54:20
Done.
| |
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 an interface failed temporarily, connection will not switch. | |
1995 TEST_F(P2PTransportChannelMultihomedTest, | |
1996 TestConnectionSwitchDampeningControlledSide) { | |
1997 rtc::ScopedFakeClock clock; | |
1998 AddAddress(0, kPublicAddrs[0]); | |
1999 // Adding alternate address will make sure |kPublicAddrs| has the higher | |
2000 // priority than others. This is due to FakeNetwork::AddInterface method. | |
2001 AddAddress(1, kAlternateAddrs[1]); | |
2002 AddAddress(1, kPublicAddrs[1]); | |
2003 | |
2004 // Use only local ports for simplicity. | |
2005 SetAllocatorFlags(0, kOnlyLocalPorts); | |
2006 SetAllocatorFlags(1, kOnlyLocalPorts); | |
2007 | |
2008 // Create channels and let them go writable, as usual. | |
2009 CreateChannels(1); | |
2010 | |
2011 EXPECT_TRUE_SIMULATED_WAIT(ep1_ch1()->receiving() && ep1_ch1()->writable() && | |
2012 ep2_ch1()->receiving() && | |
2013 ep2_ch1()->writable(), | |
2014 3000, clock); | |
2015 EXPECT_TRUE(ep1_ch1()->selected_connection() && | |
2016 ep2_ch1()->selected_connection() && | |
2017 LocalCandidate(ep1_ch1())->address().EqualIPs(kPublicAddrs[0]) && | |
2018 RemoteCandidate(ep1_ch1())->address().EqualIPs(kPublicAddrs[1])); | |
2019 | |
2020 // Make the receiving timeout shorter for testing. | |
2021 IceConfig config = CreateIceConfig(1000, GATHER_ONCE); | |
2022 ep1_ch1()->SetIceConfig(config); | |
2023 ep2_ch1()->SetIceConfig(config); | |
2024 get_and_reset_selected_candidate_pair_switches(); | |
2025 | |
2026 // Blackhole any traffic to or from the public addrs. | |
2027 LOG(LS_INFO) << "Failing over..."; | |
2028 fw()->AddRule(false, rtc::FP_ANY, rtc::FD_ANY, kPublicAddrs[1]); | |
2029 | |
2030 // The selected connections may switch, so keep references to them. | |
2031 const Connection* selected_connection1 = ep1_ch1()->selected_connection(); | |
2032 const Connection* selected_connection2 = ep2_ch1()->selected_connection(); | |
2033 // We should detect loss of receiving within 1 second or so. | |
2034 EXPECT_TRUE_SIMULATED_WAIT( | |
2035 !selected_connection1->receiving() && !selected_connection2->receiving(), | |
2036 3000, clock); | |
2037 // After a short while, the link recovers itself. | |
2038 SIMULATED_WAIT(false, 10, clock); | |
2039 fw()->ClearRules(); | |
2040 | |
2041 // We should remain on the public address on both sides and no connection | |
2042 // switches should have happened. | |
2043 EXPECT_TRUE_SIMULATED_WAIT(ep1_ch1()->selected_connection()->receiving() && | |
2044 ep2_ch1()->selected_connection()->receiving(), | |
2045 3000, clock); | |
2046 EXPECT_TRUE(LocalCandidate(ep1_ch1())->address().EqualIPs(kPublicAddrs[0])); | |
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()); | |
pthatcher1
2016/07/13 21:17:22
Do we need to add to the test that after the expec
honghaiz3
2016/07/14 04:54:20
There is a test above, TestFailoverControllingSide
pthatcher1
2016/07/14 18:01:43
As long as that case is covered. Perhaps make a n
honghaiz3
2016/07/14 23:15:01
Done. Notes at the top of the test.
| |
2050 | |
2051 DestroyChannels(); | |
2052 } | |
2053 | |
2054 TEST_F(P2PTransportChannelMultihomedTest, | |
2055 TestConnectionSwitchDampeningControllingSide) { | |
2056 rtc::ScopedFakeClock clock; | |
2057 // Adding alternate address will make sure |kPublicAddrs| has the higher | |
2058 // priority than others. This is due to FakeNetwork::AddInterface method. | |
2059 AddAddress(0, kAlternateAddrs[0]); | |
2060 AddAddress(0, kPublicAddrs[0]); | |
2061 AddAddress(1, kPublicAddrs[1]); | |
2062 | |
2063 // Use only local ports for simplicity. | |
2064 SetAllocatorFlags(0, kOnlyLocalPorts); | |
2065 SetAllocatorFlags(1, kOnlyLocalPorts); | |
2066 | |
2067 // Create channels and let them go writable, as usual. | |
2068 CreateChannels(1); | |
2069 EXPECT_TRUE_SIMULATED_WAIT(ep1_ch1()->receiving() && ep1_ch1()->writable() && | |
2070 ep2_ch1()->receiving() && | |
2071 ep2_ch1()->writable(), | |
2072 3000, clock); | |
2073 EXPECT_TRUE(ep1_ch1()->selected_connection() && | |
2074 ep2_ch1()->selected_connection() && | |
2075 LocalCandidate(ep1_ch1())->address().EqualIPs(kPublicAddrs[0]) && | |
2076 RemoteCandidate(ep1_ch1())->address().EqualIPs(kPublicAddrs[1])); | |
2077 | |
2078 // Make the receiving timeout shorter for testing. | |
2079 IceConfig config = CreateIceConfig(1000, GATHER_ONCE); | |
2080 ep1_ch1()->SetIceConfig(config); | |
2081 ep2_ch1()->SetIceConfig(config); | |
2082 get_and_reset_selected_candidate_pair_switches(); | |
2083 | |
2084 // Blackhole any traffic to or from the public addrs. | |
2085 LOG(LS_INFO) << "Failing over..."; | |
2086 fw()->AddRule(false, rtc::FP_ANY, rtc::FD_ANY, kPublicAddrs[0]); | |
2087 // The selected connections will switch, so keep references to them. | |
2088 const Connection* selected_connection1 = ep1_ch1()->selected_connection(); | |
2089 const Connection* selected_connection2 = ep2_ch1()->selected_connection(); | |
2090 // We should detect loss of receiving within 1 second or so. | |
2091 EXPECT_TRUE_SIMULATED_WAIT( | |
2092 !selected_connection1->receiving() && !selected_connection2->receiving(), | |
2093 3000, clock); | |
2094 // The link recovers after a short while. | |
2095 SIMULATED_WAIT(false, 10, clock); | |
2096 fw()->ClearRules(); | |
2097 | |
2098 // We should not switch to the alternate addr on both sides because of the | |
2099 // dampening. | |
2100 EXPECT_TRUE_SIMULATED_WAIT(ep1_ch1()->selected_connection()->receiving() && | |
2101 ep2_ch1()->selected_connection()->receiving(), | |
2102 3000, clock); | |
2103 EXPECT_TRUE(LocalCandidate(ep1_ch1())->address().EqualIPs(kPublicAddrs[0])); | |
2104 EXPECT_TRUE(RemoteCandidate(ep2_ch1())->address().EqualIPs(kPublicAddrs[0])); | |
2105 EXPECT_EQ(0, get_and_reset_selected_candidate_pair_switches()); | |
2106 DestroyChannels(); | |
2107 } | |
2108 | |
1974 // Tests that a Wifi-Wifi connection has the highest precedence. | 2109 // Tests that a Wifi-Wifi connection has the highest precedence. |
1975 TEST_F(P2PTransportChannelMultihomedTest, TestPreferWifiToWifiConnection) { | 2110 TEST_F(P2PTransportChannelMultihomedTest, TestPreferWifiToWifiConnection) { |
1976 // The interface names are chosen so that |cellular| would have higher | 2111 // The interface names are chosen so that |cellular| would have higher |
1977 // candidate priority if it is not for the network type. | 2112 // candidate priority if it is not for the network type. |
1978 auto& wifi = kAlternateAddrs; | 2113 auto& wifi = kAlternateAddrs; |
1979 auto& cellular = kPublicAddrs; | 2114 auto& cellular = kPublicAddrs; |
1980 AddAddress(0, wifi[0], "test0", rtc::ADAPTER_TYPE_WIFI); | 2115 AddAddress(0, wifi[0], "test0", rtc::ADAPTER_TYPE_WIFI); |
1981 AddAddress(0, cellular[0], "test1", rtc::ADAPTER_TYPE_CELLULAR); | 2116 AddAddress(0, cellular[0], "test1", rtc::ADAPTER_TYPE_CELLULAR); |
1982 AddAddress(1, wifi[1], "test0", rtc::ADAPTER_TYPE_WIFI); | 2117 AddAddress(1, wifi[1], "test0", rtc::ADAPTER_TYPE_WIFI); |
1983 AddAddress(1, cellular[1], "test1", rtc::ADAPTER_TYPE_CELLULAR); | 2118 AddAddress(1, cellular[1], "test1", rtc::ADAPTER_TYPE_CELLULAR); |
(...skipping 1682 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
3666 | 3801 |
3667 // TCP Relay/Relay is the next. | 3802 // TCP Relay/Relay is the next. |
3668 VerifyNextPingableConnection(RELAY_PORT_TYPE, RELAY_PORT_TYPE, | 3803 VerifyNextPingableConnection(RELAY_PORT_TYPE, RELAY_PORT_TYPE, |
3669 TCP_PROTOCOL_NAME); | 3804 TCP_PROTOCOL_NAME); |
3670 | 3805 |
3671 // Finally, Local/Relay will be pinged. | 3806 // Finally, Local/Relay will be pinged. |
3672 VerifyNextPingableConnection(LOCAL_PORT_TYPE, RELAY_PORT_TYPE); | 3807 VerifyNextPingableConnection(LOCAL_PORT_TYPE, RELAY_PORT_TYPE); |
3673 } | 3808 } |
3674 | 3809 |
3675 } // namespace cricket { | 3810 } // namespace cricket { |
OLD | NEW |