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

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

Issue 1668073002: Add network cost as part of the connection comparison. (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Created 4 years, 10 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
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 350 matching lines...) Expand 10 before | Expand all | Expand 10 after
361 } else { 361 } else {
362 return NULL; 362 return NULL;
363 } 363 }
364 } 364 }
365 cricket::PortAllocator* GetAllocator(int endpoint) { 365 cricket::PortAllocator* GetAllocator(int endpoint) {
366 return GetEndpoint(endpoint)->allocator_.get(); 366 return GetEndpoint(endpoint)->allocator_.get();
367 } 367 }
368 void AddAddress(int endpoint, const SocketAddress& addr) { 368 void AddAddress(int endpoint, const SocketAddress& addr) {
369 GetEndpoint(endpoint)->network_manager_.AddInterface(addr); 369 GetEndpoint(endpoint)->network_manager_.AddInterface(addr);
370 } 370 }
371 void AddAddress(int endpoint,
372 const SocketAddress& addr,
373 const std::string& ifname,
374 rtc::AdapterType adapter_type) {
375 GetEndpoint(endpoint)->network_manager_.AddInterface(addr, ifname,
376 adapter_type);
377 }
371 void RemoveAddress(int endpoint, const SocketAddress& addr) { 378 void RemoveAddress(int endpoint, const SocketAddress& addr) {
372 GetEndpoint(endpoint)->network_manager_.RemoveInterface(addr); 379 GetEndpoint(endpoint)->network_manager_.RemoveInterface(addr);
373 } 380 }
374 void SetProxy(int endpoint, rtc::ProxyType type) { 381 void SetProxy(int endpoint, rtc::ProxyType type) {
375 rtc::ProxyInfo info; 382 rtc::ProxyInfo info;
376 info.type = type; 383 info.type = type;
377 info.address = (type == rtc::PROXY_HTTPS) ? 384 info.address = (type == rtc::PROXY_HTTPS) ?
378 kHttpsProxyAddrs[endpoint] : kSocksProxyAddrs[endpoint]; 385 kHttpsProxyAddrs[endpoint] : kSocksProxyAddrs[endpoint];
379 GetAllocator(endpoint)->set_proxy("unittest/1.0", info); 386 GetAllocator(endpoint)->set_proxy("unittest/1.0", info);
380 } 387 }
(...skipping 1262 matching lines...) Expand 10 before | Expand all | Expand 10 after
1643 ep2_ch1()->best_connection()->receiving(), 1000); 1650 ep2_ch1()->best_connection()->receiving(), 1000);
1644 EXPECT_TRUE( 1651 EXPECT_TRUE(
1645 LocalCandidate(ep1_ch1())->address().EqualIPs(kAlternateAddrs[0])); 1652 LocalCandidate(ep1_ch1())->address().EqualIPs(kAlternateAddrs[0]));
1646 EXPECT_TRUE(RemoteCandidate(ep1_ch1())->address().EqualIPs(kPublicAddrs[1])); 1653 EXPECT_TRUE(RemoteCandidate(ep1_ch1())->address().EqualIPs(kPublicAddrs[1]));
1647 EXPECT_TRUE( 1654 EXPECT_TRUE(
1648 RemoteCandidate(ep2_ch1())->address().EqualIPs(kAlternateAddrs[0])); 1655 RemoteCandidate(ep2_ch1())->address().EqualIPs(kAlternateAddrs[0]));
1649 1656
1650 DestroyChannels(); 1657 DestroyChannels();
1651 } 1658 }
1652 1659
1660 TEST_F(P2PTransportChannelMultihomedTest, TestPreferWifiOverCellularNetwork) {
1661 // The interface names are chosen so that |kPublicAddrs| would have higher
1662 // candidate priority if it is not for the network type.
1663 AddAddress(0, kAlternateAddrs[0], "test0", rtc::ADAPTER_TYPE_WIFI);
1664 AddAddress(0, kPublicAddrs[0], "test1", rtc::ADAPTER_TYPE_CELLULAR);
1665 AddAddress(1, kAlternateAddrs[1], "test0", rtc::ADAPTER_TYPE_WIFI);
1666 AddAddress(1, kPublicAddrs[1], "test1", rtc::ADAPTER_TYPE_CELLULAR);
1667
1668 // Use only local ports for simplicity.
1669 SetAllocatorFlags(0, kOnlyLocalPorts);
1670 SetAllocatorFlags(1, kOnlyLocalPorts);
1671
1672 // Create channels and let them go writable, as usual.
1673 CreateChannels(1);
1674
1675 EXPECT_TRUE_WAIT_MARGIN(ep1_ch1()->receiving() && ep1_ch1()->writable() &&
1676 ep2_ch1()->receiving() && ep2_ch1()->writable(),
1677 1000, 1000);
1678 // Need to wait to make sure the connections on both networks are writable.
1679 EXPECT_TRUE_WAIT(
1680 ep1_ch1()->best_connection() &&
1681 LocalCandidate(ep1_ch1())->address().EqualIPs(kAlternateAddrs[0]) &&
1682 RemoteCandidate(ep1_ch1())->address().EqualIPs(kAlternateAddrs[1]),
1683 1000);
1684 EXPECT_TRUE_WAIT(
1685 ep2_ch1()->best_connection() &&
1686 LocalCandidate(ep2_ch1())->address().EqualIPs(kAlternateAddrs[1]) &&
1687 RemoteCandidate(ep2_ch1())->address().EqualIPs(kAlternateAddrs[0]),
1688 1000);
pthatcher1 2016/02/12 00:07:12 This would be more readable if you did something l
honghaiz3 2016/02/12 19:28:43 Done. We really just need wifi and cellular.
1689 }
pthatcher1 2016/02/12 00:07:12 Should we have a test case that WiFi -> Cell is pr
honghaiz3 2016/02/12 19:28:43 I think the above test has covered Wifi-Wifi is pr
1690
1653 // Test that the backup connection is pinged at a rate no faster than 1691 // Test that the backup connection is pinged at a rate no faster than
1654 // what was configured. 1692 // what was configured.
1655 TEST_F(P2PTransportChannelMultihomedTest, TestPingBackupConnectionRate) { 1693 TEST_F(P2PTransportChannelMultihomedTest, TestPingBackupConnectionRate) {
1656 AddAddress(0, kPublicAddrs[0]); 1694 AddAddress(0, kPublicAddrs[0]);
1657 // Adding alternate address will make sure |kPublicAddrs| has the higher 1695 // Adding alternate address will make sure |kPublicAddrs| has the higher
1658 // priority than others. This is due to FakeNetwork::AddInterface method. 1696 // priority than others. This is due to FakeNetwork::AddInterface method.
1659 AddAddress(1, kAlternateAddrs[1]); 1697 AddAddress(1, kAlternateAddrs[1]);
1660 AddAddress(1, kPublicAddrs[1]); 1698 AddAddress(1, kPublicAddrs[1]);
1661 1699
1662 // Use only local ports for simplicity. 1700 // Use only local ports for simplicity.
(...skipping 686 matching lines...) Expand 10 before | Expand all | Expand 10 after
2349 // It should stop getting ports after a new connection becomes strongly 2387 // It should stop getting ports after a new connection becomes strongly
2350 // connected. 2388 // connected.
2351 ch.SetIceCredentials(kIceUfrag[1], kIcePwd[1]); 2389 ch.SetIceCredentials(kIceUfrag[1], kIcePwd[1]);
2352 ch.MaybeStartGathering(); 2390 ch.MaybeStartGathering();
2353 ch.AddRemoteCandidate(CreateCandidate("2.2.2.2", 2, 100)); 2391 ch.AddRemoteCandidate(CreateCandidate("2.2.2.2", 2, 100));
2354 cricket::Connection* conn2 = WaitForConnectionTo(&ch, "2.2.2.2", 2); 2392 cricket::Connection* conn2 = WaitForConnectionTo(&ch, "2.2.2.2", 2);
2355 ASSERT_TRUE(conn2 != nullptr); 2393 ASSERT_TRUE(conn2 != nullptr);
2356 conn2->ReceivedPingResponse(); // Becomes writable and receiving 2394 conn2->ReceivedPingResponse(); // Becomes writable and receiving
2357 EXPECT_TRUE(!ch.allocator_session()->IsGettingPorts()); 2395 EXPECT_TRUE(!ch.allocator_session()->IsGettingPorts());
2358 } 2396 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698