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 299 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 310 cricket::P2PTransportChannel* channel = new cricket::P2PTransportChannel( | 310 cricket::P2PTransportChannel* channel = new cricket::P2PTransportChannel( |
| 311 "test content name", component, GetAllocator(endpoint)); | 311 "test content name", component, GetAllocator(endpoint)); |
| 312 channel->SignalCandidateGathered.connect( | 312 channel->SignalCandidateGathered.connect( |
| 313 this, &P2PTransportChannelTestBase::OnCandidateGathered); | 313 this, &P2PTransportChannelTestBase::OnCandidateGathered); |
| 314 channel->SignalCandidatesRemoved.connect( | 314 channel->SignalCandidatesRemoved.connect( |
| 315 this, &P2PTransportChannelTestBase::OnCandidatesRemoved); | 315 this, &P2PTransportChannelTestBase::OnCandidatesRemoved); |
| 316 channel->SignalReadPacket.connect( | 316 channel->SignalReadPacket.connect( |
| 317 this, &P2PTransportChannelTestBase::OnReadPacket); | 317 this, &P2PTransportChannelTestBase::OnReadPacket); |
| 318 channel->SignalRoleConflict.connect( | 318 channel->SignalRoleConflict.connect( |
| 319 this, &P2PTransportChannelTestBase::OnRoleConflict); | 319 this, &P2PTransportChannelTestBase::OnRoleConflict); |
| 320 channel->SignalSelectedCandidatePairChanged.connect( | |
| 321 this, &P2PTransportChannelTestBase::OnSelectedCandidatePairChanged); | |
| 322 channel->SetIceCredentials(local_ice_ufrag, local_ice_pwd); | 320 channel->SetIceCredentials(local_ice_ufrag, local_ice_pwd); |
| 323 if (clear_remote_candidates_ufrag_pwd_) { | 321 if (clear_remote_candidates_ufrag_pwd_) { |
| 324 // This only needs to be set if we're clearing them from the | 322 // This only needs to be set if we're clearing them from the |
| 325 // candidates. Some unit tests rely on this not being set. | 323 // candidates. Some unit tests rely on this not being set. |
| 326 channel->SetRemoteIceCredentials(remote_ice_ufrag, remote_ice_pwd); | 324 channel->SetRemoteIceCredentials(remote_ice_ufrag, remote_ice_pwd); |
| 327 } | 325 } |
| 328 channel->SetIceRole(GetEndpoint(endpoint)->ice_role()); | 326 channel->SetIceRole(GetEndpoint(endpoint)->ice_role()); |
| 329 channel->SetIceTiebreaker(GetEndpoint(endpoint)->GetIceTiebreaker()); | 327 channel->SetIceTiebreaker(GetEndpoint(endpoint)->GetIceTiebreaker()); |
| 330 channel->Connect(); | 328 channel->Connect(); |
| 331 channel->MaybeStartGathering(); | 329 channel->MaybeStartGathering(); |
| (...skipping 405 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 737 packets.push_front(std::string(data, len)); | 735 packets.push_front(std::string(data, len)); |
| 738 } | 736 } |
| 739 void OnRoleConflict(cricket::TransportChannelImpl* channel) { | 737 void OnRoleConflict(cricket::TransportChannelImpl* channel) { |
| 740 GetEndpoint(channel)->OnRoleConflict(true); | 738 GetEndpoint(channel)->OnRoleConflict(true); |
| 741 cricket::IceRole new_role = | 739 cricket::IceRole new_role = |
| 742 GetEndpoint(channel)->ice_role() == cricket::ICEROLE_CONTROLLING ? | 740 GetEndpoint(channel)->ice_role() == cricket::ICEROLE_CONTROLLING ? |
| 743 cricket::ICEROLE_CONTROLLED : cricket::ICEROLE_CONTROLLING; | 741 cricket::ICEROLE_CONTROLLED : cricket::ICEROLE_CONTROLLING; |
| 744 channel->SetIceRole(new_role); | 742 channel->SetIceRole(new_role); |
| 745 } | 743 } |
| 746 | 744 |
| 747 void OnSelectedCandidatePairChanged( | |
| 748 cricket::TransportChannel* channel, | |
| 749 cricket::CandidatePairInterface* candidate_pair) { | |
| 750 ++num_selected_candidate_pair_changes_; | |
| 751 } | |
| 752 | |
| 753 int SendData(cricket::TransportChannel* channel, | 745 int SendData(cricket::TransportChannel* channel, |
| 754 const char* data, size_t len) { | 746 const char* data, size_t len) { |
| 755 rtc::PacketOptions options; | 747 rtc::PacketOptions options; |
| 756 return channel->SendPacket(data, len, options, 0); | 748 return channel->SendPacket(data, len, options, 0); |
| 757 } | 749 } |
| 758 bool CheckDataOnChannel(cricket::TransportChannel* channel, | 750 bool CheckDataOnChannel(cricket::TransportChannel* channel, |
| 759 const char* data, int len) { | 751 const char* data, int len) { |
| 760 return GetChannelData(channel)->CheckData(data, len); | 752 return GetChannelData(channel)->CheckData(data, len); |
| 761 } | 753 } |
| 762 static const cricket::Candidate* LocalCandidate( | 754 static const cricket::Candidate* LocalCandidate( |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 796 } | 788 } |
| 797 | 789 |
| 798 void set_clear_remote_candidates_ufrag_pwd(bool clear) { | 790 void set_clear_remote_candidates_ufrag_pwd(bool clear) { |
| 799 clear_remote_candidates_ufrag_pwd_ = clear; | 791 clear_remote_candidates_ufrag_pwd_ = clear; |
| 800 } | 792 } |
| 801 | 793 |
| 802 void set_force_relay(bool relay) { | 794 void set_force_relay(bool relay) { |
| 803 force_relay_ = relay; | 795 force_relay_ = relay; |
| 804 } | 796 } |
| 805 | 797 |
| 806 int num_selected_candidate_pair_changes() { | |
| 807 return num_selected_candidate_pair_changes_; | |
| 808 } | |
| 809 void set_num_selected_candidate_pair_changes(int num) { | |
| 810 num_selected_candidate_pair_changes_ = num; | |
| 811 } | |
| 812 | |
| 813 private: | 798 private: |
| 814 rtc::Thread* main_; | 799 rtc::Thread* main_; |
| 815 rtc::scoped_ptr<rtc::PhysicalSocketServer> pss_; | 800 rtc::scoped_ptr<rtc::PhysicalSocketServer> pss_; |
| 816 rtc::scoped_ptr<rtc::VirtualSocketServer> vss_; | 801 rtc::scoped_ptr<rtc::VirtualSocketServer> vss_; |
| 817 rtc::scoped_ptr<rtc::NATSocketServer> nss_; | 802 rtc::scoped_ptr<rtc::NATSocketServer> nss_; |
| 818 rtc::scoped_ptr<rtc::FirewallSocketServer> ss_; | 803 rtc::scoped_ptr<rtc::FirewallSocketServer> ss_; |
| 819 rtc::SocketServerScope ss_scope_; | 804 rtc::SocketServerScope ss_scope_; |
| 820 rtc::scoped_ptr<cricket::TestStunServer> stun_server_; | 805 rtc::scoped_ptr<cricket::TestStunServer> stun_server_; |
| 821 cricket::TestTurnServer turn_server_; | 806 cricket::TestTurnServer turn_server_; |
| 822 cricket::TestRelayServer relay_server_; | 807 cricket::TestRelayServer relay_server_; |
| 823 rtc::SocksProxyServer socks_server1_; | 808 rtc::SocksProxyServer socks_server1_; |
| 824 rtc::SocksProxyServer socks_server2_; | 809 rtc::SocksProxyServer socks_server2_; |
| 825 Endpoint ep1_; | 810 Endpoint ep1_; |
| 826 Endpoint ep2_; | 811 Endpoint ep2_; |
| 827 int num_selected_candidate_pair_changes_ = 0; | |
| 828 bool clear_remote_candidates_ufrag_pwd_; | 812 bool clear_remote_candidates_ufrag_pwd_; |
| 829 bool force_relay_; | 813 bool force_relay_; |
| 830 }; | 814 }; |
| 831 | 815 |
| 832 // The tests have only a few outcomes, which we predefine. | 816 // The tests have only a few outcomes, which we predefine. |
| 833 const P2PTransportChannelTestBase::Result P2PTransportChannelTestBase:: | 817 const P2PTransportChannelTestBase::Result P2PTransportChannelTestBase:: |
| 834 kLocalUdpToLocalUdp("local", "udp", "local", "udp", | 818 kLocalUdpToLocalUdp("local", "udp", "local", "udp", |
| 835 "local", "udp", "local", "udp", 1000); | 819 "local", "udp", "local", "udp", 1000); |
| 836 const P2PTransportChannelTestBase::Result P2PTransportChannelTestBase:: | 820 const P2PTransportChannelTestBase::Result P2PTransportChannelTestBase:: |
| 837 kLocalUdpToStunUdp("local", "udp", "stun", "udp", | 821 kLocalUdpToStunUdp("local", "udp", "stun", "udp", |
| (...skipping 750 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1588 | 1572 |
| 1589 // Test that we can establish connectivity when both peers are multihomed. | 1573 // Test that we can establish connectivity when both peers are multihomed. |
| 1590 TEST_F(P2PTransportChannelMultihomedTest, DISABLED_TestBasic) { | 1574 TEST_F(P2PTransportChannelMultihomedTest, DISABLED_TestBasic) { |
| 1591 AddAddress(0, kPublicAddrs[0]); | 1575 AddAddress(0, kPublicAddrs[0]); |
| 1592 AddAddress(0, kAlternateAddrs[0]); | 1576 AddAddress(0, kAlternateAddrs[0]); |
| 1593 AddAddress(1, kPublicAddrs[1]); | 1577 AddAddress(1, kPublicAddrs[1]); |
| 1594 AddAddress(1, kAlternateAddrs[1]); | 1578 AddAddress(1, kAlternateAddrs[1]); |
| 1595 Test(kLocalUdpToLocalUdp); | 1579 Test(kLocalUdpToLocalUdp); |
| 1596 } | 1580 } |
| 1597 | 1581 |
| 1598 // Test that we can quickly switch links if an interface goes down. This also | 1582 // Test that we can quickly switch links if an interface goes down. |
| 1599 // tests that when the link switches, |SignalSelectedCandidatePairChanged| will | 1583 // The controlled side has two interfaces and one will die. |
| 1600 // be fired. The controlled side has two interfaces and one will die. | |
| 1601 TEST_F(P2PTransportChannelMultihomedTest, TestFailoverControlledSide) { | 1584 TEST_F(P2PTransportChannelMultihomedTest, TestFailoverControlledSide) { |
| 1602 AddAddress(0, kPublicAddrs[0]); | 1585 AddAddress(0, kPublicAddrs[0]); |
| 1603 // Adding alternate address will make sure |kPublicAddrs| has the higher | 1586 // Adding alternate address will make sure |kPublicAddrs| has the higher |
| 1604 // priority than others. This is due to FakeNetwork::AddInterface method. | 1587 // priority than others. This is due to FakeNetwork::AddInterface method. |
| 1605 AddAddress(1, kAlternateAddrs[1]); | 1588 AddAddress(1, kAlternateAddrs[1]); |
| 1606 AddAddress(1, kPublicAddrs[1]); | 1589 AddAddress(1, kPublicAddrs[1]); |
| 1607 | 1590 |
| 1608 // Use only local ports for simplicity. | 1591 // Use only local ports for simplicity. |
| 1609 SetAllocatorFlags(0, kOnlyLocalPorts); | 1592 SetAllocatorFlags(0, kOnlyLocalPorts); |
| 1610 SetAllocatorFlags(1, kOnlyLocalPorts); | 1593 SetAllocatorFlags(1, kOnlyLocalPorts); |
| 1611 | 1594 |
| 1612 // Create channels and let them go writable, as usual. | 1595 // Create channels and let them go writable, as usual. |
| 1613 CreateChannels(1); | 1596 CreateChannels(1); |
| 1614 | 1597 |
| 1615 EXPECT_TRUE_WAIT_MARGIN(ep1_ch1()->receiving() && ep1_ch1()->writable() && | 1598 EXPECT_TRUE_WAIT_MARGIN(ep1_ch1()->receiving() && ep1_ch1()->writable() && |
| 1616 ep2_ch1()->receiving() && ep2_ch1()->writable(), | 1599 ep2_ch1()->receiving() && ep2_ch1()->writable(), |
| 1617 1000, 1000); | 1600 1000, 1000); |
| 1618 EXPECT_TRUE( | 1601 EXPECT_TRUE( |
| 1619 ep1_ch1()->best_connection() && ep2_ch1()->best_connection() && | 1602 ep1_ch1()->best_connection() && ep2_ch1()->best_connection() && |
| 1620 LocalCandidate(ep1_ch1())->address().EqualIPs(kPublicAddrs[0]) && | 1603 LocalCandidate(ep1_ch1())->address().EqualIPs(kPublicAddrs[0]) && |
| 1621 RemoteCandidate(ep1_ch1())->address().EqualIPs(kPublicAddrs[1])); | 1604 RemoteCandidate(ep1_ch1())->address().EqualIPs(kPublicAddrs[1])); |
| 1622 | 1605 |
| 1623 // Make the receiving timeout shorter for testing. | 1606 // Make the receiving timeout shorter for testing. |
| 1624 cricket::IceConfig config = CreateIceConfig(1000, false); | 1607 cricket::IceConfig config = CreateIceConfig(1000, false); |
| 1625 ep1_ch1()->SetIceConfig(config); | 1608 ep1_ch1()->SetIceConfig(config); |
| 1626 ep2_ch1()->SetIceConfig(config); | 1609 ep2_ch1()->SetIceConfig(config); |
| 1627 | 1610 |
| 1628 set_num_selected_candidate_pair_changes(0); | |
| 1629 // Blackhole any traffic to or from the public addrs. | 1611 // Blackhole any traffic to or from the public addrs. |
| 1630 LOG(LS_INFO) << "Failing over..."; | 1612 LOG(LS_INFO) << "Failing over..."; |
| 1631 fw()->AddRule(false, rtc::FP_ANY, rtc::FD_ANY, kPublicAddrs[1]); | 1613 fw()->AddRule(false, rtc::FP_ANY, rtc::FD_ANY, kPublicAddrs[1]); |
| 1632 // The best connections will switch, so keep references to them. | 1614 // The best connections will switch, so keep references to them. |
| 1633 const cricket::Connection* best_connection1 = ep1_ch1()->best_connection(); | 1615 const cricket::Connection* best_connection1 = ep1_ch1()->best_connection(); |
| 1634 const cricket::Connection* best_connection2 = ep2_ch1()->best_connection(); | 1616 const cricket::Connection* best_connection2 = ep2_ch1()->best_connection(); |
| 1635 // We should detect loss of receiving within 1 second or so. | 1617 // We should detect loss of receiving within 1 second or so. |
| 1636 EXPECT_TRUE_WAIT( | 1618 EXPECT_TRUE_WAIT( |
| 1637 !best_connection1->receiving() && !best_connection2->receiving(), 3000); | 1619 !best_connection1->receiving() && !best_connection2->receiving(), 3000); |
| 1638 | 1620 |
| 1639 // We should switch over to use the alternate addr immediately on both sides | 1621 // We should switch over to use the alternate addr immediately on both sides |
| 1640 // when we are not receiving. | 1622 // when we are not receiving. |
| 1641 EXPECT_TRUE_WAIT( | 1623 EXPECT_TRUE_WAIT( |
| 1642 ep1_ch1()->best_connection()->receiving() && | 1624 ep1_ch1()->best_connection()->receiving() && |
| 1643 ep2_ch1()->best_connection()->receiving(), 1000); | 1625 ep2_ch1()->best_connection()->receiving(), 1000); |
| 1644 EXPECT_TRUE(LocalCandidate(ep1_ch1())->address().EqualIPs(kPublicAddrs[0])); | 1626 EXPECT_TRUE(LocalCandidate(ep1_ch1())->address().EqualIPs(kPublicAddrs[0])); |
| 1645 EXPECT_TRUE( | 1627 EXPECT_TRUE( |
| 1646 RemoteCandidate(ep1_ch1())->address().EqualIPs(kAlternateAddrs[1])); | 1628 RemoteCandidate(ep1_ch1())->address().EqualIPs(kAlternateAddrs[1])); |
| 1647 EXPECT_TRUE( | 1629 EXPECT_TRUE( |
| 1648 LocalCandidate(ep2_ch1())->address().EqualIPs(kAlternateAddrs[1])); | 1630 LocalCandidate(ep2_ch1())->address().EqualIPs(kAlternateAddrs[1])); |
| 1649 // It should have changed twice, one on each side. | |
| 1650 EXPECT_EQ(2, num_selected_candidate_pair_changes()); | |
|
Taylor Brandstetter
2016/03/30 21:17:14
Why is this being removed?
honghaiz3
2016/03/30 21:48:09
I moved the tests for selected candidate pair to
| |
| 1651 | 1631 |
| 1652 DestroyChannels(); | 1632 DestroyChannels(); |
| 1653 } | 1633 } |
| 1654 | 1634 |
| 1655 // Test that we can quickly switch links if an interface goes down. This also | 1635 // Test that we can quickly switch links if an interface goes down. |
| 1656 // tests that when the link switches, |SignalSelectedCandidatePairChanged| will | 1636 // The controlling side has two interfaces and one will die. |
| 1657 // be fired. The controlling side has two interfaces and one will die. | |
| 1658 TEST_F(P2PTransportChannelMultihomedTest, TestFailoverControllingSide) { | 1637 TEST_F(P2PTransportChannelMultihomedTest, TestFailoverControllingSide) { |
| 1659 // Adding alternate address will make sure |kPublicAddrs| has the higher | 1638 // Adding alternate address will make sure |kPublicAddrs| has the higher |
| 1660 // priority than others. This is due to FakeNetwork::AddInterface method. | 1639 // priority than others. This is due to FakeNetwork::AddInterface method. |
| 1661 AddAddress(0, kAlternateAddrs[0]); | 1640 AddAddress(0, kAlternateAddrs[0]); |
| 1662 AddAddress(0, kPublicAddrs[0]); | 1641 AddAddress(0, kPublicAddrs[0]); |
| 1663 AddAddress(1, kPublicAddrs[1]); | 1642 AddAddress(1, kPublicAddrs[1]); |
| 1664 | 1643 |
| 1665 // Use only local ports for simplicity. | 1644 // Use only local ports for simplicity. |
| 1666 SetAllocatorFlags(0, kOnlyLocalPorts); | 1645 SetAllocatorFlags(0, kOnlyLocalPorts); |
| 1667 SetAllocatorFlags(1, kOnlyLocalPorts); | 1646 SetAllocatorFlags(1, kOnlyLocalPorts); |
| 1668 | 1647 |
| 1669 // Create channels and let them go writable, as usual. | 1648 // Create channels and let them go writable, as usual. |
| 1670 CreateChannels(1); | 1649 CreateChannels(1); |
| 1671 EXPECT_TRUE_WAIT_MARGIN(ep1_ch1()->receiving() && ep1_ch1()->writable() && | 1650 EXPECT_TRUE_WAIT_MARGIN(ep1_ch1()->receiving() && ep1_ch1()->writable() && |
| 1672 ep2_ch1()->receiving() && ep2_ch1()->writable(), | 1651 ep2_ch1()->receiving() && ep2_ch1()->writable(), |
| 1673 1000, 1000); | 1652 1000, 1000); |
| 1674 EXPECT_TRUE( | 1653 EXPECT_TRUE( |
| 1675 ep1_ch1()->best_connection() && ep2_ch1()->best_connection() && | 1654 ep1_ch1()->best_connection() && ep2_ch1()->best_connection() && |
| 1676 LocalCandidate(ep1_ch1())->address().EqualIPs(kPublicAddrs[0]) && | 1655 LocalCandidate(ep1_ch1())->address().EqualIPs(kPublicAddrs[0]) && |
| 1677 RemoteCandidate(ep1_ch1())->address().EqualIPs(kPublicAddrs[1])); | 1656 RemoteCandidate(ep1_ch1())->address().EqualIPs(kPublicAddrs[1])); |
| 1678 | 1657 |
| 1679 // Make the receiving timeout shorter for testing. | 1658 // Make the receiving timeout shorter for testing. |
| 1680 cricket::IceConfig config = CreateIceConfig(1000, false); | 1659 cricket::IceConfig config = CreateIceConfig(1000, false); |
| 1681 ep1_ch1()->SetIceConfig(config); | 1660 ep1_ch1()->SetIceConfig(config); |
| 1682 ep2_ch1()->SetIceConfig(config); | 1661 ep2_ch1()->SetIceConfig(config); |
| 1683 set_num_selected_candidate_pair_changes(0); | |
| 1684 | 1662 |
| 1685 // Blackhole any traffic to or from the public addrs. | 1663 // Blackhole any traffic to or from the public addrs. |
| 1686 LOG(LS_INFO) << "Failing over..."; | 1664 LOG(LS_INFO) << "Failing over..."; |
| 1687 fw()->AddRule(false, rtc::FP_ANY, rtc::FD_ANY, kPublicAddrs[0]); | 1665 fw()->AddRule(false, rtc::FP_ANY, rtc::FD_ANY, kPublicAddrs[0]); |
| 1688 // The best connections will switch, so keep references to them. | 1666 // The best connections will switch, so keep references to them. |
| 1689 const cricket::Connection* best_connection1 = ep1_ch1()->best_connection(); | 1667 const cricket::Connection* best_connection1 = ep1_ch1()->best_connection(); |
| 1690 const cricket::Connection* best_connection2 = ep2_ch1()->best_connection(); | 1668 const cricket::Connection* best_connection2 = ep2_ch1()->best_connection(); |
| 1691 // We should detect loss of receiving within 1 second or so. | 1669 // We should detect loss of receiving within 1 second or so. |
| 1692 EXPECT_TRUE_WAIT( | 1670 EXPECT_TRUE_WAIT( |
| 1693 !best_connection1->receiving() && !best_connection2->receiving(), 3000); | 1671 !best_connection1->receiving() && !best_connection2->receiving(), 3000); |
| 1694 | 1672 |
| 1695 // We should switch over to use the alternate addr immediately on both sides | 1673 // We should switch over to use the alternate addr immediately on both sides |
| 1696 // when we are not receiving. | 1674 // when we are not receiving. |
| 1697 EXPECT_TRUE_WAIT( | 1675 EXPECT_TRUE_WAIT( |
| 1698 ep1_ch1()->best_connection()->receiving() && | 1676 ep1_ch1()->best_connection()->receiving() && |
| 1699 ep2_ch1()->best_connection()->receiving(), 1000); | 1677 ep2_ch1()->best_connection()->receiving(), 1000); |
| 1700 EXPECT_TRUE( | 1678 EXPECT_TRUE( |
| 1701 LocalCandidate(ep1_ch1())->address().EqualIPs(kAlternateAddrs[0])); | 1679 LocalCandidate(ep1_ch1())->address().EqualIPs(kAlternateAddrs[0])); |
| 1702 EXPECT_TRUE(RemoteCandidate(ep1_ch1())->address().EqualIPs(kPublicAddrs[1])); | 1680 EXPECT_TRUE(RemoteCandidate(ep1_ch1())->address().EqualIPs(kPublicAddrs[1])); |
| 1703 EXPECT_TRUE( | 1681 EXPECT_TRUE( |
| 1704 RemoteCandidate(ep2_ch1())->address().EqualIPs(kAlternateAddrs[0])); | 1682 RemoteCandidate(ep2_ch1())->address().EqualIPs(kAlternateAddrs[0])); |
| 1705 EXPECT_EQ(2, num_selected_candidate_pair_changes()); | |
| 1706 | 1683 |
| 1707 DestroyChannels(); | 1684 DestroyChannels(); |
| 1708 } | 1685 } |
| 1709 | 1686 |
| 1710 // Tests that a Wifi-Wifi connection has the highest precedence. | 1687 // Tests that a Wifi-Wifi connection has the highest precedence. |
| 1711 TEST_F(P2PTransportChannelMultihomedTest, TestPreferWifiToWifiConnection) { | 1688 TEST_F(P2PTransportChannelMultihomedTest, TestPreferWifiToWifiConnection) { |
| 1712 // The interface names are chosen so that |cellular| would have higher | 1689 // The interface names are chosen so that |cellular| would have higher |
| 1713 // candidate priority if it is not for the network type. | 1690 // candidate priority if it is not for the network type. |
| 1714 auto& wifi = kAlternateAddrs; | 1691 auto& wifi = kAlternateAddrs; |
| 1715 auto& cellular = kPublicAddrs; | 1692 auto& cellular = kPublicAddrs; |
| (...skipping 197 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1913 P2PTransportChannelPingTest() | 1890 P2PTransportChannelPingTest() |
| 1914 : pss_(new rtc::PhysicalSocketServer), | 1891 : pss_(new rtc::PhysicalSocketServer), |
| 1915 vss_(new rtc::VirtualSocketServer(pss_.get())), | 1892 vss_(new rtc::VirtualSocketServer(pss_.get())), |
| 1916 ss_scope_(vss_.get()) {} | 1893 ss_scope_(vss_.get()) {} |
| 1917 | 1894 |
| 1918 protected: | 1895 protected: |
| 1919 void PrepareChannel(cricket::P2PTransportChannel* ch) { | 1896 void PrepareChannel(cricket::P2PTransportChannel* ch) { |
| 1920 ch->SetIceRole(cricket::ICEROLE_CONTROLLING); | 1897 ch->SetIceRole(cricket::ICEROLE_CONTROLLING); |
| 1921 ch->SetIceCredentials(kIceUfrag[0], kIcePwd[0]); | 1898 ch->SetIceCredentials(kIceUfrag[0], kIcePwd[0]); |
| 1922 ch->SetRemoteIceCredentials(kIceUfrag[1], kIcePwd[1]); | 1899 ch->SetRemoteIceCredentials(kIceUfrag[1], kIcePwd[1]); |
| 1900 ch->SignalSelectedCandidatePairChanged.connect( | |
| 1901 this, &P2PTransportChannelPingTest::OnSelectedCandidatePairChanged); | |
| 1923 ch->SignalReadyToSend.connect(this, | 1902 ch->SignalReadyToSend.connect(this, |
| 1924 &P2PTransportChannelPingTest::OnReadyToSend); | 1903 &P2PTransportChannelPingTest::OnReadyToSend); |
| 1925 } | 1904 } |
| 1926 | 1905 |
| 1927 cricket::Candidate CreateHostCandidate(const std::string& ip, | 1906 cricket::Candidate CreateHostCandidate(const std::string& ip, |
| 1928 int port, | 1907 int port, |
| 1929 int priority, | 1908 int priority, |
| 1930 const std::string& ufrag = "") { | 1909 const std::string& ufrag = "") { |
| 1931 cricket::Candidate c; | 1910 cricket::Candidate c; |
| 1932 c.set_address(rtc::SocketAddress(ip, port)); | 1911 c.set_address(rtc::SocketAddress(ip, port)); |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1964 | 1943 |
| 1965 cricket::Connection* FindNextPingableConnectionAndPingIt( | 1944 cricket::Connection* FindNextPingableConnectionAndPingIt( |
| 1966 cricket::P2PTransportChannel* ch) { | 1945 cricket::P2PTransportChannel* ch) { |
| 1967 cricket::Connection* conn = ch->FindNextPingableConnection(); | 1946 cricket::Connection* conn = ch->FindNextPingableConnection(); |
| 1968 if (conn) { | 1947 if (conn) { |
| 1969 ch->MarkConnectionPinged(conn); | 1948 ch->MarkConnectionPinged(conn); |
| 1970 } | 1949 } |
| 1971 return conn; | 1950 return conn; |
| 1972 } | 1951 } |
| 1973 | 1952 |
| 1953 void OnSelectedCandidatePairChanged( | |
| 1954 cricket::TransportChannel* transport_channel, | |
| 1955 cricket::CandidatePairInterface* selected_candidate_pair, | |
| 1956 int last_sent_packet_id) { | |
| 1957 last_selected_candidate_pair_ = selected_candidate_pair; | |
| 1958 last_sent_packet_id_ = last_sent_packet_id; | |
| 1959 } | |
| 1960 | |
| 1974 void OnReadyToSend(cricket::TransportChannel* channel) { | 1961 void OnReadyToSend(cricket::TransportChannel* channel) { |
| 1975 channel_ready_to_send_ = true; | 1962 channel_ready_to_send_ = true; |
| 1976 } | 1963 } |
| 1977 | 1964 |
| 1965 cricket::CandidatePairInterface* last_selected_candidate_pair() { | |
| 1966 return last_selected_candidate_pair_; | |
| 1967 } | |
| 1968 int last_sent_packet_id() { return last_sent_packet_id_; } | |
| 1978 bool channel_ready_to_send() { return channel_ready_to_send_; } | 1969 bool channel_ready_to_send() { return channel_ready_to_send_; } |
| 1979 void reset_channel_ready_to_send() { channel_ready_to_send_ = false; } | 1970 void reset_channel_ready_to_send() { channel_ready_to_send_ = false; } |
| 1980 | 1971 |
| 1981 private: | 1972 private: |
| 1982 rtc::scoped_ptr<rtc::PhysicalSocketServer> pss_; | 1973 rtc::scoped_ptr<rtc::PhysicalSocketServer> pss_; |
| 1983 rtc::scoped_ptr<rtc::VirtualSocketServer> vss_; | 1974 rtc::scoped_ptr<rtc::VirtualSocketServer> vss_; |
| 1984 rtc::SocketServerScope ss_scope_; | 1975 rtc::SocketServerScope ss_scope_; |
| 1976 cricket::CandidatePairInterface* last_selected_candidate_pair_ = nullptr; | |
| 1977 int last_sent_packet_id_ = -1; | |
| 1985 bool channel_ready_to_send_ = false; | 1978 bool channel_ready_to_send_ = false; |
| 1986 }; | 1979 }; |
| 1987 | 1980 |
| 1988 TEST_F(P2PTransportChannelPingTest, TestTriggeredChecks) { | 1981 TEST_F(P2PTransportChannelPingTest, TestTriggeredChecks) { |
| 1989 cricket::FakePortAllocator pa(rtc::Thread::Current(), nullptr); | 1982 cricket::FakePortAllocator pa(rtc::Thread::Current(), nullptr); |
| 1990 cricket::P2PTransportChannel ch("trigger checks", 1, &pa); | 1983 cricket::P2PTransportChannel ch("trigger checks", 1, &pa); |
| 1991 PrepareChannel(&ch); | 1984 PrepareChannel(&ch); |
| 1992 ch.Connect(); | 1985 ch.Connect(); |
| 1993 ch.MaybeStartGathering(); | 1986 ch.MaybeStartGathering(); |
| 1994 ch.AddRemoteCandidate(CreateHostCandidate("1.1.1.1", 1, 1)); | 1987 ch.AddRemoteCandidate(CreateHostCandidate("1.1.1.1", 1, 1)); |
| (...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2165 conn1->ReceivedPing(); | 2158 conn1->ReceivedPing(); |
| 2166 conn1->OnReadPacket("ABC", 3, rtc::CreatePacketTime(0)); | 2159 conn1->OnReadPacket("ABC", 3, rtc::CreatePacketTime(0)); |
| 2167 EXPECT_TRUE_WAIT(ch.best_connection() != nullptr, 1000); | 2160 EXPECT_TRUE_WAIT(ch.best_connection() != nullptr, 1000); |
| 2168 EXPECT_TRUE_WAIT(ch.receiving(), 1000); | 2161 EXPECT_TRUE_WAIT(ch.receiving(), 1000); |
| 2169 EXPECT_TRUE_WAIT(!ch.receiving(), 1000); | 2162 EXPECT_TRUE_WAIT(!ch.receiving(), 1000); |
| 2170 } | 2163 } |
| 2171 | 2164 |
| 2172 // The controlled side will select a connection as the "best connection" based | 2165 // The controlled side will select a connection as the "best connection" based |
| 2173 // on priority until the controlling side nominates a connection, at which | 2166 // on priority until the controlling side nominates a connection, at which |
| 2174 // point the controlled side will select that connection as the | 2167 // point the controlled side will select that connection as the |
| 2175 // "best connection". Plus, the channel will fire SignalReadyToSend if the new | 2168 // "best connection". Plus, SignalSelectedCandidatePair will be fired if the |
| 2176 // best connection is writable. | 2169 // best connection changes and SignalReadyToSend will be fired if the new best |
| 2170 // connection is writable. | |
| 2177 TEST_F(P2PTransportChannelPingTest, TestSelectConnectionBeforeNomination) { | 2171 TEST_F(P2PTransportChannelPingTest, TestSelectConnectionBeforeNomination) { |
| 2178 cricket::FakePortAllocator pa(rtc::Thread::Current(), nullptr); | 2172 cricket::FakePortAllocator pa(rtc::Thread::Current(), nullptr); |
| 2179 cricket::P2PTransportChannel ch("receiving state change", 1, &pa); | 2173 cricket::P2PTransportChannel ch("receiving state change", 1, &pa); |
| 2180 PrepareChannel(&ch); | 2174 PrepareChannel(&ch); |
| 2181 ch.SetIceRole(cricket::ICEROLE_CONTROLLED); | 2175 ch.SetIceRole(cricket::ICEROLE_CONTROLLED); |
| 2182 ch.Connect(); | 2176 ch.Connect(); |
| 2183 ch.MaybeStartGathering(); | 2177 ch.MaybeStartGathering(); |
| 2184 ch.AddRemoteCandidate(CreateHostCandidate("1.1.1.1", 1, 1)); | 2178 ch.AddRemoteCandidate(CreateHostCandidate("1.1.1.1", 1, 1)); |
| 2185 cricket::Connection* conn1 = WaitForConnectionTo(&ch, "1.1.1.1", 1); | 2179 cricket::Connection* conn1 = WaitForConnectionTo(&ch, "1.1.1.1", 1); |
| 2186 ASSERT_TRUE(conn1 != nullptr); | 2180 ASSERT_TRUE(conn1 != nullptr); |
| 2187 EXPECT_EQ(conn1, ch.best_connection()); | 2181 EXPECT_EQ(conn1, ch.best_connection()); |
| 2188 // Channel is not ready because it is not writable. | 2182 EXPECT_EQ(conn1, last_selected_candidate_pair()); |
| 2183 EXPECT_EQ(-1, last_sent_packet_id()); | |
| 2184 // Channel is not ready to send because it is not writable. | |
| 2189 EXPECT_FALSE(channel_ready_to_send()); | 2185 EXPECT_FALSE(channel_ready_to_send()); |
| 2190 | 2186 |
| 2187 int last_packet_id = 0; | |
| 2188 ch.set_last_sent_packet_id(++last_packet_id); | |
| 2191 // When a higher priority candidate comes in, the new connection is chosen | 2189 // When a higher priority candidate comes in, the new connection is chosen |
| 2192 // as the best connection. | 2190 // as the best connection. |
| 2193 ch.AddRemoteCandidate(CreateHostCandidate("2.2.2.2", 2, 10)); | 2191 ch.AddRemoteCandidate(CreateHostCandidate("2.2.2.2", 2, 10)); |
| 2194 cricket::Connection* conn2 = WaitForConnectionTo(&ch, "2.2.2.2", 2); | 2192 cricket::Connection* conn2 = WaitForConnectionTo(&ch, "2.2.2.2", 2); |
| 2195 ASSERT_TRUE(conn2 != nullptr); | 2193 ASSERT_TRUE(conn2 != nullptr); |
| 2196 EXPECT_EQ(conn2, ch.best_connection()); | 2194 EXPECT_EQ(conn2, ch.best_connection()); |
| 2195 EXPECT_EQ(conn2, last_selected_candidate_pair()); | |
| 2196 EXPECT_EQ(last_packet_id, last_sent_packet_id()); | |
| 2197 EXPECT_FALSE(channel_ready_to_send()); | 2197 EXPECT_FALSE(channel_ready_to_send()); |
| 2198 | 2198 |
| 2199 // If a stun request with use-candidate attribute arrives, the receiving | 2199 // If a stun request with use-candidate attribute arrives, the receiving |
| 2200 // connection will be set as the best connection, even though | 2200 // connection will be set as the best connection, even though |
| 2201 // its priority is lower. | 2201 // its priority is lower. |
| 2202 ch.set_last_sent_packet_id(++last_packet_id); | |
| 2202 ch.AddRemoteCandidate(CreateHostCandidate("3.3.3.3", 3, 1)); | 2203 ch.AddRemoteCandidate(CreateHostCandidate("3.3.3.3", 3, 1)); |
| 2203 cricket::Connection* conn3 = WaitForConnectionTo(&ch, "3.3.3.3", 3); | 2204 cricket::Connection* conn3 = WaitForConnectionTo(&ch, "3.3.3.3", 3); |
| 2204 ASSERT_TRUE(conn3 != nullptr); | 2205 ASSERT_TRUE(conn3 != nullptr); |
| 2205 // Because it has a lower priority, the best connection is still conn2. | 2206 // Because it has a lower priority, the best connection is still conn2. |
| 2206 EXPECT_EQ(conn2, ch.best_connection()); | 2207 EXPECT_EQ(conn2, ch.best_connection()); |
| 2207 conn3->ReceivedPingResponse(); // Become writable. | 2208 conn3->ReceivedPingResponse(); // Become writable. |
| 2208 // But if it is nominated via use_candidate, it is chosen as the best | 2209 // But if it is nominated via use_candidate, it is chosen as the best |
| 2209 // connection. | 2210 // connection. |
| 2210 conn3->set_nominated(true); | 2211 conn3->set_nominated(true); |
| 2211 conn3->SignalNominated(conn3); | 2212 conn3->SignalNominated(conn3); |
| 2212 EXPECT_EQ(conn3, ch.best_connection()); | 2213 EXPECT_EQ(conn3, ch.best_connection()); |
| 2214 EXPECT_EQ(conn3, last_selected_candidate_pair()); | |
| 2215 EXPECT_EQ(last_packet_id, last_sent_packet_id()); | |
| 2213 EXPECT_TRUE(channel_ready_to_send()); | 2216 EXPECT_TRUE(channel_ready_to_send()); |
| 2214 | 2217 |
| 2215 // Even if another higher priority candidate arrives, | 2218 // Even if another higher priority candidate arrives, |
| 2216 // it will not be set as the best connection because the best connection | 2219 // it will not be set as the best connection because the best connection |
| 2217 // is nominated by the controlling side. | 2220 // is nominated by the controlling side. |
| 2221 ch.set_last_sent_packet_id(++last_packet_id); | |
| 2218 ch.AddRemoteCandidate(CreateHostCandidate("4.4.4.4", 4, 100)); | 2222 ch.AddRemoteCandidate(CreateHostCandidate("4.4.4.4", 4, 100)); |
| 2219 cricket::Connection* conn4 = WaitForConnectionTo(&ch, "4.4.4.4", 4); | 2223 cricket::Connection* conn4 = WaitForConnectionTo(&ch, "4.4.4.4", 4); |
| 2220 ASSERT_TRUE(conn4 != nullptr); | 2224 ASSERT_TRUE(conn4 != nullptr); |
| 2221 EXPECT_EQ(conn3, ch.best_connection()); | 2225 EXPECT_EQ(conn3, ch.best_connection()); |
| 2222 // But if it is nominated via use_candidate and writable, it will be set as | 2226 // But if it is nominated via use_candidate and writable, it will be set as |
| 2223 // the best connection. | 2227 // the best connection. |
| 2224 conn4->set_nominated(true); | 2228 conn4->set_nominated(true); |
| 2225 conn4->SignalNominated(conn4); | 2229 conn4->SignalNominated(conn4); |
| 2226 // Not switched yet because conn4 is not writable. | 2230 // Not switched yet because conn4 is not writable. |
| 2227 EXPECT_EQ(conn3, ch.best_connection()); | 2231 EXPECT_EQ(conn3, ch.best_connection()); |
| 2228 reset_channel_ready_to_send(); | 2232 reset_channel_ready_to_send(); |
| 2229 // The best connection switches after conn4 becomes writable. | 2233 // The best connection switches after conn4 becomes writable. |
| 2230 conn4->ReceivedPingResponse(); | 2234 conn4->ReceivedPingResponse(); |
| 2231 EXPECT_EQ(conn4, ch.best_connection()); | 2235 EXPECT_EQ(conn4, ch.best_connection()); |
| 2236 EXPECT_EQ(conn4, last_selected_candidate_pair()); | |
| 2237 EXPECT_EQ(last_packet_id, last_sent_packet_id()); | |
| 2232 // SignalReadyToSend is fired again because conn4 is writable. | 2238 // SignalReadyToSend is fired again because conn4 is writable. |
| 2233 EXPECT_TRUE(channel_ready_to_send()); | 2239 EXPECT_TRUE(channel_ready_to_send()); |
| 2234 } | 2240 } |
| 2235 | 2241 |
| 2236 // The controlled side will select a connection as the "best connection" based | 2242 // The controlled side will select a connection as the "best connection" based |
| 2237 // on requests from an unknown address before the controlling side nominates | 2243 // on requests from an unknown address before the controlling side nominates |
| 2238 // a connection, and will nominate a connection from an unknown address if the | 2244 // a connection, and will nominate a connection from an unknown address if the |
| 2239 // request contains the use_candidate attribute. Plus, it will also sends back | 2245 // request contains the use_candidate attribute. Plus, it will also sends back |
| 2240 // a ping response and set the ICE pwd in the remote candidate appropriately. | 2246 // a ping response and set the ICE pwd in the remote candidate appropriately. |
| 2241 TEST_F(P2PTransportChannelPingTest, TestSelectConnectionFromUnknownAddress) { | 2247 TEST_F(P2PTransportChannelPingTest, TestSelectConnectionFromUnknownAddress) { |
| (...skipping 521 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2763 | 2769 |
| 2764 // TCP Relay/Relay is the next. | 2770 // TCP Relay/Relay is the next. |
| 2765 VerifyNextPingableConnection(cricket::RELAY_PORT_TYPE, | 2771 VerifyNextPingableConnection(cricket::RELAY_PORT_TYPE, |
| 2766 cricket::RELAY_PORT_TYPE, | 2772 cricket::RELAY_PORT_TYPE, |
| 2767 cricket::TCP_PROTOCOL_NAME); | 2773 cricket::TCP_PROTOCOL_NAME); |
| 2768 | 2774 |
| 2769 // Finally, Local/Relay will be pinged. | 2775 // Finally, Local/Relay will be pinged. |
| 2770 VerifyNextPingableConnection(cricket::LOCAL_PORT_TYPE, | 2776 VerifyNextPingableConnection(cricket::LOCAL_PORT_TYPE, |
| 2771 cricket::RELAY_PORT_TYPE); | 2777 cricket::RELAY_PORT_TYPE); |
| 2772 } | 2778 } |
| OLD | NEW |