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 350 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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 Loading... |
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 // Tests that a Wifi-Wifi connection has the highest precedence. |
| 1661 TEST_F(P2PTransportChannelMultihomedTest, TestPreferWifiToWifiConnection) { |
| 1662 // The interface names are chosen so that |cellular| would have higher |
| 1663 // candidate priority if it is not for the network type. |
| 1664 auto& wifi = kAlternateAddrs; |
| 1665 auto& cellular = kPublicAddrs; |
| 1666 AddAddress(0, wifi[0], "test0", rtc::ADAPTER_TYPE_WIFI); |
| 1667 AddAddress(0, cellular[0], "test1", rtc::ADAPTER_TYPE_CELLULAR); |
| 1668 AddAddress(1, wifi[1], "test0", rtc::ADAPTER_TYPE_WIFI); |
| 1669 AddAddress(1, cellular[1], "test1", rtc::ADAPTER_TYPE_CELLULAR); |
| 1670 |
| 1671 // Use only local ports for simplicity. |
| 1672 SetAllocatorFlags(0, kOnlyLocalPorts); |
| 1673 SetAllocatorFlags(1, kOnlyLocalPorts); |
| 1674 |
| 1675 // Create channels and let them go writable, as usual. |
| 1676 CreateChannels(1); |
| 1677 |
| 1678 EXPECT_TRUE_WAIT_MARGIN(ep1_ch1()->receiving() && ep1_ch1()->writable() && |
| 1679 ep2_ch1()->receiving() && ep2_ch1()->writable(), |
| 1680 1000, 1000); |
| 1681 // Need to wait to make sure the connections on both networks are writable. |
| 1682 EXPECT_TRUE_WAIT(ep1_ch1()->best_connection() && |
| 1683 LocalCandidate(ep1_ch1())->address().EqualIPs(wifi[0]) && |
| 1684 RemoteCandidate(ep1_ch1())->address().EqualIPs(wifi[1]), |
| 1685 1000); |
| 1686 EXPECT_TRUE_WAIT(ep2_ch1()->best_connection() && |
| 1687 LocalCandidate(ep2_ch1())->address().EqualIPs(wifi[1]) && |
| 1688 RemoteCandidate(ep2_ch1())->address().EqualIPs(wifi[0]), |
| 1689 1000); |
| 1690 } |
| 1691 |
| 1692 // Tests that a Wifi-Cellular connection has higher precedence than |
| 1693 // a Cellular-Cellular connection. |
| 1694 TEST_F(P2PTransportChannelMultihomedTest, TestPreferWifiOverCellularNetwork) { |
| 1695 // The interface names are chosen so that |cellular| would have higher |
| 1696 // candidate priority if it is not for the network type. |
| 1697 auto& wifi = kAlternateAddrs; |
| 1698 auto& cellular = kPublicAddrs; |
| 1699 AddAddress(0, cellular[0], "test1", rtc::ADAPTER_TYPE_CELLULAR); |
| 1700 AddAddress(1, wifi[1], "test0", rtc::ADAPTER_TYPE_WIFI); |
| 1701 AddAddress(1, cellular[1], "test1", rtc::ADAPTER_TYPE_CELLULAR); |
| 1702 |
| 1703 // Use only local ports for simplicity. |
| 1704 SetAllocatorFlags(0, kOnlyLocalPorts); |
| 1705 SetAllocatorFlags(1, kOnlyLocalPorts); |
| 1706 |
| 1707 // Create channels and let them go writable, as usual. |
| 1708 CreateChannels(1); |
| 1709 |
| 1710 EXPECT_TRUE_WAIT_MARGIN(ep1_ch1()->receiving() && ep1_ch1()->writable() && |
| 1711 ep2_ch1()->receiving() && ep2_ch1()->writable(), |
| 1712 1000, 1000); |
| 1713 // Need to wait to make sure the connections on both networks are writable. |
| 1714 EXPECT_TRUE_WAIT(ep1_ch1()->best_connection() && |
| 1715 RemoteCandidate(ep1_ch1())->address().EqualIPs(wifi[1]), |
| 1716 1000); |
| 1717 EXPECT_TRUE_WAIT(ep2_ch1()->best_connection() && |
| 1718 LocalCandidate(ep2_ch1())->address().EqualIPs(wifi[1]), |
| 1719 1000); |
| 1720 } |
| 1721 |
1653 // Test that the backup connection is pinged at a rate no faster than | 1722 // Test that the backup connection is pinged at a rate no faster than |
1654 // what was configured. | 1723 // what was configured. |
1655 TEST_F(P2PTransportChannelMultihomedTest, TestPingBackupConnectionRate) { | 1724 TEST_F(P2PTransportChannelMultihomedTest, TestPingBackupConnectionRate) { |
1656 AddAddress(0, kPublicAddrs[0]); | 1725 AddAddress(0, kPublicAddrs[0]); |
1657 // Adding alternate address will make sure |kPublicAddrs| has the higher | 1726 // Adding alternate address will make sure |kPublicAddrs| has the higher |
1658 // priority than others. This is due to FakeNetwork::AddInterface method. | 1727 // priority than others. This is due to FakeNetwork::AddInterface method. |
1659 AddAddress(1, kAlternateAddrs[1]); | 1728 AddAddress(1, kAlternateAddrs[1]); |
1660 AddAddress(1, kPublicAddrs[1]); | 1729 AddAddress(1, kPublicAddrs[1]); |
1661 | 1730 |
1662 // Use only local ports for simplicity. | 1731 // Use only local ports for simplicity. |
(...skipping 686 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2349 // It should stop getting ports after a new connection becomes strongly | 2418 // It should stop getting ports after a new connection becomes strongly |
2350 // connected. | 2419 // connected. |
2351 ch.SetIceCredentials(kIceUfrag[1], kIcePwd[1]); | 2420 ch.SetIceCredentials(kIceUfrag[1], kIcePwd[1]); |
2352 ch.MaybeStartGathering(); | 2421 ch.MaybeStartGathering(); |
2353 ch.AddRemoteCandidate(CreateCandidate("2.2.2.2", 2, 100)); | 2422 ch.AddRemoteCandidate(CreateCandidate("2.2.2.2", 2, 100)); |
2354 cricket::Connection* conn2 = WaitForConnectionTo(&ch, "2.2.2.2", 2); | 2423 cricket::Connection* conn2 = WaitForConnectionTo(&ch, "2.2.2.2", 2); |
2355 ASSERT_TRUE(conn2 != nullptr); | 2424 ASSERT_TRUE(conn2 != nullptr); |
2356 conn2->ReceivedPingResponse(); // Becomes writable and receiving | 2425 conn2->ReceivedPingResponse(); // Becomes writable and receiving |
2357 EXPECT_TRUE(!ch.allocator_session()->IsGettingPorts()); | 2426 EXPECT_TRUE(!ch.allocator_session()->IsGettingPorts()); |
2358 } | 2427 } |
OLD | NEW |