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

Side by Side Diff: webrtc/p2p/base/p2ptransportchannel_unittest.cc

Issue 2232563002: Do not switch to a high-cost connection that is not receiving (Closed) Base URL: https://chromium.googlesource.com/external/webrtc@master
Patch Set: . Created 4 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « webrtc/p2p/base/p2ptransportchannel.cc ('k') | webrtc/p2p/base/port.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright 2009 The WebRTC Project Authors. All rights reserved. 2 * Copyright 2009 The WebRTC Project Authors. All rights reserved.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license 4 * Use of this source code is governed by a BSD-style license
5 * that can be found in the LICENSE file in the root of the source 5 * that can be found in the LICENSE file in the root of the source
6 * tree. An additional intellectual property rights grant can be found 6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may 7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree. 8 * be found in the AUTHORS file in the root of the source tree.
9 */ 9 */
10 10
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
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 597 matching lines...) Expand 10 before | Expand all | Expand 10 after
666 } else { 666 } else {
667 main_->Post(RTC_FROM_HERE, this, MSG_ADD_CANDIDATES, 667 main_->Post(RTC_FROM_HERE, this, MSG_ADD_CANDIDATES,
668 new CandidatesData(ch, c)); 668 new CandidatesData(ch, c));
669 } 669 }
670 } 670 }
671 void OnSelectedCandidatePairChanged( 671 void OnSelectedCandidatePairChanged(
672 TransportChannel* transport_channel, 672 TransportChannel* transport_channel,
673 CandidatePairInterface* selected_candidate_pair, 673 CandidatePairInterface* selected_candidate_pair,
674 int last_sent_packet_id, 674 int last_sent_packet_id,
675 bool ready_to_send) { 675 bool ready_to_send) {
676 ++selected_candidate_pair_switches_; 676 // Do not count if it switches to nullptr. This may happen if all
677 // connections timed out.
678 if (selected_candidate_pair != nullptr) {
679 ++selected_candidate_pair_switches_;
680 }
677 } 681 }
678 682
679 int reset_selected_candidate_pair_switches() { 683 int reset_selected_candidate_pair_switches() {
680 int switches = selected_candidate_pair_switches_; 684 int switches = selected_candidate_pair_switches_;
681 selected_candidate_pair_switches_ = 0; 685 selected_candidate_pair_switches_ = 0;
682 return switches; 686 return switches;
683 } 687 }
684 688
685 void PauseCandidates(int endpoint) { 689 void PauseCandidates(int endpoint) {
686 GetEndpoint(endpoint)->save_candidates_ = true; 690 GetEndpoint(endpoint)->save_candidates_ = true;
(...skipping 1190 matching lines...) Expand 10 before | Expand all | Expand 10 after
1877 cricket::P2PTransportChannel* channel, 1881 cricket::P2PTransportChannel* channel,
1878 const SocketAddress& address) { 1882 const SocketAddress& address) {
1879 for (cricket::Connection* conn : channel->connections()) { 1883 for (cricket::Connection* conn : channel->connections()) {
1880 if (conn->remote_candidate().address().EqualIPs(address)) { 1884 if (conn->remote_candidate().address().EqualIPs(address)) {
1881 return conn; 1885 return conn;
1882 } 1886 }
1883 } 1887 }
1884 return nullptr; 1888 return nullptr;
1885 } 1889 }
1886 1890
1887 const cricket::Connection* GetConnectionWithLocalAddress( 1891 cricket::Connection* GetConnectionWithLocalAddress(
1888 cricket::P2PTransportChannel* channel, 1892 cricket::P2PTransportChannel* channel,
1889 const SocketAddress& address) { 1893 const SocketAddress& address) {
1890 for (cricket::Connection* conn : channel->connections()) { 1894 for (cricket::Connection* conn : channel->connections()) {
1891 if (conn->local_candidate().address().EqualIPs(address)) { 1895 if (conn->local_candidate().address().EqualIPs(address)) {
1892 return conn; 1896 return conn;
1893 } 1897 }
1894 } 1898 }
1895 return nullptr; 1899 return nullptr;
1896 } 1900 }
1897 1901
(...skipping 299 matching lines...) Expand 10 before | Expand all | Expand 10 after
2197 // dampening. 2201 // dampening.
2198 EXPECT_TRUE_SIMULATED_WAIT(ep1_ch1()->selected_connection()->receiving() && 2202 EXPECT_TRUE_SIMULATED_WAIT(ep1_ch1()->selected_connection()->receiving() &&
2199 ep2_ch1()->selected_connection()->receiving(), 2203 ep2_ch1()->selected_connection()->receiving(),
2200 3000, clock); 2204 3000, clock);
2201 EXPECT_TRUE(LocalCandidate(ep1_ch1())->address().EqualIPs(kPublicAddrs[0])); 2205 EXPECT_TRUE(LocalCandidate(ep1_ch1())->address().EqualIPs(kPublicAddrs[0]));
2202 EXPECT_TRUE(RemoteCandidate(ep2_ch1())->address().EqualIPs(kPublicAddrs[0])); 2206 EXPECT_TRUE(RemoteCandidate(ep2_ch1())->address().EqualIPs(kPublicAddrs[0]));
2203 EXPECT_EQ(0, reset_selected_candidate_pair_switches()); 2207 EXPECT_EQ(0, reset_selected_candidate_pair_switches());
2204 DestroyChannels(); 2208 DestroyChannels();
2205 } 2209 }
2206 2210
2211 // Tests that if the remote side's network failed, it won't cause the local
2212 // side to switch connections and networks.
2213 TEST_F(P2PTransportChannelMultihomedTest, TestRemoteFailover) {
2214 rtc::ScopedFakeClock clock;
2215 // The interface names are chosen so that |cellular| would have higher
2216 // candidate priority and higher cost.
2217 auto& wifi = kPublicAddrs;
2218 auto& cellular = kAlternateAddrs;
2219 AddAddress(0, wifi[0], "wifi0", rtc::ADAPTER_TYPE_WIFI);
2220 AddAddress(0, cellular[0], "cellular0", rtc::ADAPTER_TYPE_CELLULAR);
2221 AddAddress(1, wifi[1], "wifi0", rtc::ADAPTER_TYPE_WIFI);
2222
2223 // Use only local ports for simplicity.
2224 SetAllocatorFlags(0, kOnlyLocalPorts);
2225 SetAllocatorFlags(1, kOnlyLocalPorts);
2226 // Create channels and let them go writable, as usual.
2227 CreateChannels(1);
2228 // Make the receiving timeout shorter for testing.
2229 // Set the backup connection ping interval to 25s.
2230 IceConfig config = CreateIceConfig(1000, GATHER_ONCE, 25000);
2231 // Ping the best connection more frequently since we don't have traffic.
2232 config.stable_writable_connection_ping_interval = 900;
2233 ep1_ch1()->SetIceConfig(config);
2234 ep2_ch1()->SetIceConfig(config);
2235 // Need to wait to make sure the connections on both networks are writable.
2236 EXPECT_TRUE_SIMULATED_WAIT(ep1_ch1()->receiving() && ep1_ch1()->writable() &&
2237 ep2_ch1()->receiving() &&
2238 ep2_ch1()->writable(),
2239 3000, clock);
2240 EXPECT_TRUE_SIMULATED_WAIT(
2241 ep1_ch1()->selected_connection() &&
2242 LocalCandidate(ep1_ch1())->address().EqualIPs(wifi[0]) &&
2243 RemoteCandidate(ep1_ch1())->address().EqualIPs(wifi[1]),
2244 kDefaultTimeout, clock);
2245 Connection* backup_conn =
2246 GetConnectionWithLocalAddress(ep1_ch1(), cellular[0]);
2247 ASSERT_NE(nullptr, backup_conn);
2248 // After a short while, the backup connection will be writable but not
2249 // receiving because backup connection is pinged at a slower rate.
2250 EXPECT_TRUE_SIMULATED_WAIT(
2251 backup_conn->writable() && !backup_conn->receiving(), 5000, clock);
2252 reset_selected_candidate_pair_switches();
2253 // Blackhole any traffic to or from the remote WiFi networks.
2254 LOG(LS_INFO) << "Failing over...";
2255 fw()->AddRule(false, rtc::FP_ANY, rtc::FD_ANY, wifi[1]);
2256
2257 int num_switches = 0;
2258 SIMULATED_WAIT((num_switches = reset_selected_candidate_pair_switches()) > 0,
2259 20000, clock);
2260 EXPECT_EQ(0, num_switches);
2261 DestroyChannels();
2262 }
2263
2207 // Tests that a Wifi-Wifi connection has the highest precedence. 2264 // Tests that a Wifi-Wifi connection has the highest precedence.
2208 TEST_F(P2PTransportChannelMultihomedTest, TestPreferWifiToWifiConnection) { 2265 TEST_F(P2PTransportChannelMultihomedTest, TestPreferWifiToWifiConnection) {
2209 // The interface names are chosen so that |cellular| would have higher 2266 // The interface names are chosen so that |cellular| would have higher
2210 // candidate priority if it is not for the network type. 2267 // candidate priority if it is not for the network type.
2211 auto& wifi = kAlternateAddrs; 2268 auto& wifi = kAlternateAddrs;
2212 auto& cellular = kPublicAddrs; 2269 auto& cellular = kPublicAddrs;
2213 AddAddress(0, wifi[0], "test0", rtc::ADAPTER_TYPE_WIFI); 2270 AddAddress(0, wifi[0], "test0", rtc::ADAPTER_TYPE_WIFI);
2214 AddAddress(0, cellular[0], "test1", rtc::ADAPTER_TYPE_CELLULAR); 2271 AddAddress(0, cellular[0], "test1", rtc::ADAPTER_TYPE_CELLULAR);
2215 AddAddress(1, wifi[1], "test0", rtc::ADAPTER_TYPE_WIFI); 2272 AddAddress(1, wifi[1], "test0", rtc::ADAPTER_TYPE_WIFI);
2216 AddAddress(1, cellular[1], "test1", rtc::ADAPTER_TYPE_CELLULAR); 2273 AddAddress(1, cellular[1], "test1", rtc::ADAPTER_TYPE_CELLULAR);
(...skipping 1761 matching lines...) Expand 10 before | Expand all | Expand 10 after
3978 4035
3979 // TCP Relay/Relay is the next. 4036 // TCP Relay/Relay is the next.
3980 VerifyNextPingableConnection(RELAY_PORT_TYPE, RELAY_PORT_TYPE, 4037 VerifyNextPingableConnection(RELAY_PORT_TYPE, RELAY_PORT_TYPE,
3981 TCP_PROTOCOL_NAME); 4038 TCP_PROTOCOL_NAME);
3982 4039
3983 // Finally, Local/Relay will be pinged. 4040 // Finally, Local/Relay will be pinged.
3984 VerifyNextPingableConnection(LOCAL_PORT_TYPE, RELAY_PORT_TYPE); 4041 VerifyNextPingableConnection(LOCAL_PORT_TYPE, RELAY_PORT_TYPE);
3985 } 4042 }
3986 4043
3987 } // namespace cricket { 4044 } // namespace cricket {
OLDNEW
« no previous file with comments | « webrtc/p2p/base/p2ptransportchannel.cc ('k') | webrtc/p2p/base/port.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698