Chromium Code Reviews| 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 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 47 static const int LOW_RTT = 20; | 47 static const int LOW_RTT = 20; |
| 48 // Addresses on the public internet. | 48 // Addresses on the public internet. |
| 49 static const SocketAddress kPublicAddrs[2] = | 49 static const SocketAddress kPublicAddrs[2] = |
| 50 { SocketAddress("11.11.11.11", 0), SocketAddress("22.22.22.22", 0) }; | 50 { SocketAddress("11.11.11.11", 0), SocketAddress("22.22.22.22", 0) }; |
| 51 // IPv6 Addresses on the public internet. | 51 // IPv6 Addresses on the public internet. |
| 52 static const SocketAddress kIPv6PublicAddrs[2] = { | 52 static const SocketAddress kIPv6PublicAddrs[2] = { |
| 53 SocketAddress("2400:4030:1:2c00:be30:abcd:efab:cdef", 0), | 53 SocketAddress("2400:4030:1:2c00:be30:abcd:efab:cdef", 0), |
| 54 SocketAddress("2620:0:1000:1b03:2e41:38ff:fea6:f2a4", 0) | 54 SocketAddress("2620:0:1000:1b03:2e41:38ff:fea6:f2a4", 0) |
| 55 }; | 55 }; |
| 56 // For configuring multihomed clients. | 56 // For configuring multihomed clients. |
| 57 static const SocketAddress kAlternateAddrs[2] = | 57 static const SocketAddress kAlternateAddrs[2] = { |
| 58 { SocketAddress("11.11.11.101", 0), SocketAddress("22.22.22.202", 0) }; | 58 SocketAddress("101.101.101.101", 0), SocketAddress("202.202.202.202", 0)}; |
| 59 // Addresses for HTTP proxy servers. | 59 // Addresses for HTTP proxy servers. |
| 60 static const SocketAddress kHttpsProxyAddrs[2] = | 60 static const SocketAddress kHttpsProxyAddrs[2] = |
| 61 { SocketAddress("11.11.11.1", 443), SocketAddress("22.22.22.1", 443) }; | 61 { SocketAddress("11.11.11.1", 443), SocketAddress("22.22.22.1", 443) }; |
| 62 // Addresses for SOCKS proxy servers. | 62 // Addresses for SOCKS proxy servers. |
| 63 static const SocketAddress kSocksProxyAddrs[2] = | 63 static const SocketAddress kSocksProxyAddrs[2] = |
| 64 { SocketAddress("11.11.11.1", 1080), SocketAddress("22.22.22.1", 1080) }; | 64 { SocketAddress("11.11.11.1", 1080), SocketAddress("22.22.22.1", 1080) }; |
| 65 // Internal addresses for NAT boxes. | 65 // Internal addresses for NAT boxes. |
| 66 static const SocketAddress kNatAddrs[2] = | 66 static const SocketAddress kNatAddrs[2] = |
| 67 { SocketAddress("192.168.1.1", 0), SocketAddress("192.168.2.1", 0) }; | 67 { SocketAddress("192.168.1.1", 0), SocketAddress("192.168.2.1", 0) }; |
| 68 // Private addresses inside the NAT private networks. | 68 // Private addresses inside the NAT private networks. |
| (...skipping 619 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 688 } else { | 688 } else { |
| 689 main_->Post(RTC_FROM_HERE, this, MSG_ADD_CANDIDATES, | 689 main_->Post(RTC_FROM_HERE, this, MSG_ADD_CANDIDATES, |
| 690 new CandidatesData(ch, c)); | 690 new CandidatesData(ch, c)); |
| 691 } | 691 } |
| 692 } | 692 } |
| 693 void OnSelectedCandidatePairChanged( | 693 void OnSelectedCandidatePairChanged( |
| 694 TransportChannel* transport_channel, | 694 TransportChannel* transport_channel, |
| 695 CandidatePairInterface* selected_candidate_pair, | 695 CandidatePairInterface* selected_candidate_pair, |
| 696 int last_sent_packet_id, | 696 int last_sent_packet_id, |
| 697 bool ready_to_send) { | 697 bool ready_to_send) { |
| 698 ++selected_candidate_pair_switches_; | 698 // Do not count if it switches to nullptr. This may happen if all |
| 699 // connections timed out. | |
| 700 if (selected_candidate_pair != nullptr) { | |
| 701 ++selected_candidate_pair_switches_; | |
| 702 } | |
| 699 } | 703 } |
| 700 | 704 |
| 701 int reset_selected_candidate_pair_switches() { | 705 int reset_selected_candidate_pair_switches() { |
| 702 int switches = selected_candidate_pair_switches_; | 706 int switches = selected_candidate_pair_switches_; |
| 703 selected_candidate_pair_switches_ = 0; | 707 selected_candidate_pair_switches_ = 0; |
| 704 return switches; | 708 return switches; |
| 705 } | 709 } |
| 706 | 710 |
| 707 void PauseCandidates(int endpoint) { | 711 void PauseCandidates(int endpoint) { |
| 708 GetEndpoint(endpoint)->save_candidates_ = true; | 712 GetEndpoint(endpoint)->save_candidates_ = true; |
| (...skipping 1144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1853 cricket::P2PTransportChannel* channel, | 1857 cricket::P2PTransportChannel* channel, |
| 1854 const SocketAddress& address) { | 1858 const SocketAddress& address) { |
| 1855 for (cricket::Connection* conn : channel->connections()) { | 1859 for (cricket::Connection* conn : channel->connections()) { |
| 1856 if (conn->remote_candidate().address().EqualIPs(address)) { | 1860 if (conn->remote_candidate().address().EqualIPs(address)) { |
| 1857 return conn; | 1861 return conn; |
| 1858 } | 1862 } |
| 1859 } | 1863 } |
| 1860 return nullptr; | 1864 return nullptr; |
| 1861 } | 1865 } |
| 1862 | 1866 |
| 1863 const cricket::Connection* GetConnectionWithLocalAddress( | 1867 cricket::Connection* GetConnectionWithLocalAddress( |
| 1864 cricket::P2PTransportChannel* channel, | 1868 cricket::P2PTransportChannel* channel, |
| 1865 const SocketAddress& address) { | 1869 const SocketAddress& address) { |
| 1866 for (cricket::Connection* conn : channel->connections()) { | 1870 for (cricket::Connection* conn : channel->connections()) { |
| 1867 if (conn->local_candidate().address().EqualIPs(address)) { | 1871 if (conn->local_candidate().address().EqualIPs(address)) { |
| 1868 return conn; | 1872 return conn; |
| 1869 } | 1873 } |
| 1870 } | 1874 } |
| 1871 return nullptr; | 1875 return nullptr; |
| 1872 } | 1876 } |
| 1873 | 1877 |
| (...skipping 299 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2173 // dampening. | 2177 // dampening. |
| 2174 EXPECT_TRUE_SIMULATED_WAIT(ep1_ch1()->selected_connection()->receiving() && | 2178 EXPECT_TRUE_SIMULATED_WAIT(ep1_ch1()->selected_connection()->receiving() && |
| 2175 ep2_ch1()->selected_connection()->receiving(), | 2179 ep2_ch1()->selected_connection()->receiving(), |
| 2176 3000, clock); | 2180 3000, clock); |
| 2177 EXPECT_TRUE(LocalCandidate(ep1_ch1())->address().EqualIPs(kPublicAddrs[0])); | 2181 EXPECT_TRUE(LocalCandidate(ep1_ch1())->address().EqualIPs(kPublicAddrs[0])); |
| 2178 EXPECT_TRUE(RemoteCandidate(ep2_ch1())->address().EqualIPs(kPublicAddrs[0])); | 2182 EXPECT_TRUE(RemoteCandidate(ep2_ch1())->address().EqualIPs(kPublicAddrs[0])); |
| 2179 EXPECT_EQ(0, reset_selected_candidate_pair_switches()); | 2183 EXPECT_EQ(0, reset_selected_candidate_pair_switches()); |
| 2180 DestroyChannels(); | 2184 DestroyChannels(); |
| 2181 } | 2185 } |
| 2182 | 2186 |
| 2187 // Tests that if the remote side's network failed, it won't cause the local | |
| 2188 // side to switch connections and networks. | |
| 2189 TEST_F(P2PTransportChannelMultihomedTest, TestRemoteFailover) { | |
| 2190 rtc::ScopedFakeClock clock; | |
| 2191 // Start the clock at 100 seconds. P2PTransportChannel::IsPingable assumes | |
| 2192 // that the clock time is sufficently large. | |
| 2193 clock.AdvanceTime(rtc::TimeDelta::FromSeconds(100u)); | |
|
Taylor Brandstetter
2016/08/11 22:54:40
Can you explain why this is necessary? Can IsPinga
honghaiz3
2016/08/12 17:04:26
A backup connection is pinged at a slower rate (wh
Taylor Brandstetter
2016/08/15 17:37:32
So then the issue is that 0 is treated as a specia
honghaiz3
2016/08/16 00:43:07
Added checking on the "no ping response is receive
| |
| 2194 // The interface names are chosen so that |cellular| would have higher | |
| 2195 // candidate priority and higher cost. | |
| 2196 auto& wifi = kPublicAddrs; | |
| 2197 auto& cellular = kAlternateAddrs; | |
| 2198 AddAddress(0, wifi[0], "wifi0", rtc::ADAPTER_TYPE_WIFI); | |
| 2199 AddAddress(0, cellular[0], "cellular0", rtc::ADAPTER_TYPE_CELLULAR); | |
| 2200 AddAddress(1, wifi[1], "wifi0", rtc::ADAPTER_TYPE_WIFI); | |
| 2201 | |
| 2202 // Use only local ports for simplicity. | |
| 2203 SetAllocatorFlags(0, kOnlyLocalPorts); | |
| 2204 SetAllocatorFlags(1, kOnlyLocalPorts); | |
| 2205 // Create channels and let them go writable, as usual. | |
| 2206 CreateChannels(1); | |
| 2207 // Make the receiving timeout shorter for testing. | |
| 2208 // Set the backup connection ping interval to 25s. | |
| 2209 IceConfig config = CreateIceConfig(1000, GATHER_ONCE, 25000); | |
| 2210 // Ping the best connection more frequently since we don't have traffic. | |
| 2211 config.stable_writable_connection_ping_interval = 900; | |
| 2212 ep1_ch1()->SetIceConfig(config); | |
| 2213 ep2_ch1()->SetIceConfig(config); | |
| 2214 // Need to wait to make sure the connections on both networks are writable. | |
| 2215 EXPECT_TRUE_SIMULATED_WAIT(ep1_ch1()->receiving() && ep1_ch1()->writable() && | |
| 2216 ep2_ch1()->receiving() && | |
| 2217 ep2_ch1()->writable(), | |
| 2218 3000, clock); | |
| 2219 EXPECT_TRUE_SIMULATED_WAIT( | |
| 2220 ep1_ch1()->selected_connection() && | |
| 2221 LocalCandidate(ep1_ch1())->address().EqualIPs(wifi[0]) && | |
| 2222 RemoteCandidate(ep1_ch1())->address().EqualIPs(wifi[1]), | |
| 2223 kDefaultTimeout, clock); | |
| 2224 Connection* backup_conn = | |
| 2225 GetConnectionWithLocalAddress(ep1_ch1(), cellular[0]); | |
| 2226 ASSERT_NE(nullptr, backup_conn); | |
| 2227 // After a short while, the backup connection will be writable but not | |
| 2228 // receiving because backup connection is pinged at a slower rate. | |
| 2229 EXPECT_TRUE_SIMULATED_WAIT( | |
| 2230 backup_conn->writable() && !backup_conn->receiving(), 5000, clock); | |
| 2231 reset_selected_candidate_pair_switches(); | |
| 2232 // Blackhole any traffic to or from the remote WiFi networks. | |
| 2233 LOG(LS_INFO) << "Failing over..."; | |
| 2234 fw()->AddRule(false, rtc::FP_ANY, rtc::FD_ANY, wifi[1]); | |
| 2235 | |
| 2236 int num_switches = 0; | |
| 2237 SIMULATED_WAIT((num_switches = reset_selected_candidate_pair_switches()) > 0, | |
| 2238 20000, clock); | |
| 2239 EXPECT_EQ(0, num_switches); | |
| 2240 DestroyChannels(); | |
| 2241 } | |
| 2242 | |
| 2183 // Tests that a Wifi-Wifi connection has the highest precedence. | 2243 // Tests that a Wifi-Wifi connection has the highest precedence. |
| 2184 TEST_F(P2PTransportChannelMultihomedTest, TestPreferWifiToWifiConnection) { | 2244 TEST_F(P2PTransportChannelMultihomedTest, TestPreferWifiToWifiConnection) { |
| 2185 // The interface names are chosen so that |cellular| would have higher | 2245 // The interface names are chosen so that |cellular| would have higher |
| 2186 // candidate priority if it is not for the network type. | 2246 // candidate priority if it is not for the network type. |
| 2187 auto& wifi = kAlternateAddrs; | 2247 auto& wifi = kAlternateAddrs; |
| 2188 auto& cellular = kPublicAddrs; | 2248 auto& cellular = kPublicAddrs; |
| 2189 AddAddress(0, wifi[0], "test0", rtc::ADAPTER_TYPE_WIFI); | 2249 AddAddress(0, wifi[0], "test0", rtc::ADAPTER_TYPE_WIFI); |
| 2190 AddAddress(0, cellular[0], "test1", rtc::ADAPTER_TYPE_CELLULAR); | 2250 AddAddress(0, cellular[0], "test1", rtc::ADAPTER_TYPE_CELLULAR); |
| 2191 AddAddress(1, wifi[1], "test0", rtc::ADAPTER_TYPE_WIFI); | 2251 AddAddress(1, wifi[1], "test0", rtc::ADAPTER_TYPE_WIFI); |
| 2192 AddAddress(1, cellular[1], "test1", rtc::ADAPTER_TYPE_CELLULAR); | 2252 AddAddress(1, cellular[1], "test1", rtc::ADAPTER_TYPE_CELLULAR); |
| (...skipping 1761 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 3954 | 4014 |
| 3955 // TCP Relay/Relay is the next. | 4015 // TCP Relay/Relay is the next. |
| 3956 VerifyNextPingableConnection(RELAY_PORT_TYPE, RELAY_PORT_TYPE, | 4016 VerifyNextPingableConnection(RELAY_PORT_TYPE, RELAY_PORT_TYPE, |
| 3957 TCP_PROTOCOL_NAME); | 4017 TCP_PROTOCOL_NAME); |
| 3958 | 4018 |
| 3959 // Finally, Local/Relay will be pinged. | 4019 // Finally, Local/Relay will be pinged. |
| 3960 VerifyNextPingableConnection(LOCAL_PORT_TYPE, RELAY_PORT_TYPE); | 4020 VerifyNextPingableConnection(LOCAL_PORT_TYPE, RELAY_PORT_TYPE); |
| 3961 } | 4021 } |
| 3962 | 4022 |
| 3963 } // namespace cricket { | 4023 } // namespace cricket { |
| OLD | NEW |