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 227 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
559 } | 557 } |
560 // Try sending some data to other end. | 558 // Try sending some data to other end. |
561 TestSendRecv(1); | 559 TestSendRecv(1); |
562 | 560 |
563 // Destroy the channels, and wait for them to be fully cleaned up. | 561 // Destroy the channels, and wait for them to be fully cleaned up. |
564 DestroyChannels(); | 562 DestroyChannels(); |
565 } | 563 } |
566 | 564 |
567 void TestSendRecv(int channels) { | 565 void TestSendRecv(int channels) { |
568 for (int i = 0; i < 10; ++i) { | 566 for (int i = 0; i < 10; ++i) { |
569 const char* data = "ABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890"; | 567 const char* data = "ABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890"; |
570 int len = static_cast<int>(strlen(data)); | 568 int len = static_cast<int>(strlen(data)); |
571 // local_channel1 <==> remote_channel1 | 569 // local_channel1 <==> remote_channel1 |
572 EXPECT_EQ_WAIT(len, SendData(ep1_ch1(), data, len), 1000); | 570 EXPECT_EQ_WAIT(len, SendData(ep1_ch1(), data, len), 1000); |
573 EXPECT_TRUE_WAIT(CheckDataOnChannel(ep2_ch1(), data, len), 1000); | 571 EXPECT_TRUE_WAIT(CheckDataOnChannel(ep2_ch1(), data, len), 1000); |
574 EXPECT_EQ_WAIT(len, SendData(ep2_ch1(), data, len), 1000); | 572 EXPECT_EQ_WAIT(len, SendData(ep2_ch1(), data, len), 1000); |
575 EXPECT_TRUE_WAIT(CheckDataOnChannel(ep1_ch1(), data, len), 1000); | 573 EXPECT_TRUE_WAIT(CheckDataOnChannel(ep1_ch1(), data, len), 1000); |
576 if (channels == 2 && ep1_ch2() && ep2_ch2()) { | 574 if (channels == 2 && ep1_ch2() && ep2_ch2()) { |
577 // local_channel2 <==> remote_channel2 | 575 // local_channel2 <==> remote_channel2 |
578 EXPECT_EQ_WAIT(len, SendData(ep1_ch2(), data, len), 1000); | 576 EXPECT_EQ_WAIT(len, SendData(ep1_ch2(), data, len), 1000); |
579 EXPECT_TRUE_WAIT(CheckDataOnChannel(ep2_ch2(), data, len), 1000); | 577 EXPECT_TRUE_WAIT(CheckDataOnChannel(ep2_ch2(), data, len), 1000); |
(...skipping 157 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()); | |
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 int SendData(cricket::TransportChannel& channel, |
| 1954 const char* data, |
| 1955 size_t len, |
| 1956 int packet_id) { |
| 1957 rtc::PacketOptions options; |
| 1958 options.packet_id = packet_id; |
| 1959 return channel.SendPacket(data, len, options, 0); |
| 1960 } |
| 1961 |
| 1962 void OnSelectedCandidatePairChanged( |
| 1963 cricket::TransportChannel* transport_channel, |
| 1964 cricket::CandidatePairInterface* selected_candidate_pair, |
| 1965 int last_sent_packet_id) { |
| 1966 last_selected_candidate_pair_ = selected_candidate_pair; |
| 1967 last_sent_packet_id_ = last_sent_packet_id; |
| 1968 } |
| 1969 |
1974 void OnReadyToSend(cricket::TransportChannel* channel) { | 1970 void OnReadyToSend(cricket::TransportChannel* channel) { |
1975 channel_ready_to_send_ = true; | 1971 channel_ready_to_send_ = true; |
1976 } | 1972 } |
1977 | 1973 |
| 1974 cricket::CandidatePairInterface* last_selected_candidate_pair() { |
| 1975 return last_selected_candidate_pair_; |
| 1976 } |
| 1977 int last_sent_packet_id() { return last_sent_packet_id_; } |
1978 bool channel_ready_to_send() { return channel_ready_to_send_; } | 1978 bool channel_ready_to_send() { return channel_ready_to_send_; } |
1979 void reset_channel_ready_to_send() { channel_ready_to_send_ = false; } | 1979 void reset_channel_ready_to_send() { channel_ready_to_send_ = false; } |
1980 | 1980 |
1981 private: | 1981 private: |
1982 rtc::scoped_ptr<rtc::PhysicalSocketServer> pss_; | 1982 rtc::scoped_ptr<rtc::PhysicalSocketServer> pss_; |
1983 rtc::scoped_ptr<rtc::VirtualSocketServer> vss_; | 1983 rtc::scoped_ptr<rtc::VirtualSocketServer> vss_; |
1984 rtc::SocketServerScope ss_scope_; | 1984 rtc::SocketServerScope ss_scope_; |
| 1985 cricket::CandidatePairInterface* last_selected_candidate_pair_ = nullptr; |
| 1986 int last_sent_packet_id_ = -1; |
1985 bool channel_ready_to_send_ = false; | 1987 bool channel_ready_to_send_ = false; |
1986 }; | 1988 }; |
1987 | 1989 |
1988 TEST_F(P2PTransportChannelPingTest, TestTriggeredChecks) { | 1990 TEST_F(P2PTransportChannelPingTest, TestTriggeredChecks) { |
1989 cricket::FakePortAllocator pa(rtc::Thread::Current(), nullptr); | 1991 cricket::FakePortAllocator pa(rtc::Thread::Current(), nullptr); |
1990 cricket::P2PTransportChannel ch("trigger checks", 1, &pa); | 1992 cricket::P2PTransportChannel ch("trigger checks", 1, &pa); |
1991 PrepareChannel(&ch); | 1993 PrepareChannel(&ch); |
1992 ch.Connect(); | 1994 ch.Connect(); |
1993 ch.MaybeStartGathering(); | 1995 ch.MaybeStartGathering(); |
1994 ch.AddRemoteCandidate(CreateHostCandidate("1.1.1.1", 1, 1)); | 1996 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(); | 2167 conn1->ReceivedPing(); |
2166 conn1->OnReadPacket("ABC", 3, rtc::CreatePacketTime(0)); | 2168 conn1->OnReadPacket("ABC", 3, rtc::CreatePacketTime(0)); |
2167 EXPECT_TRUE_WAIT(ch.best_connection() != nullptr, 1000); | 2169 EXPECT_TRUE_WAIT(ch.best_connection() != nullptr, 1000); |
2168 EXPECT_TRUE_WAIT(ch.receiving(), 1000); | 2170 EXPECT_TRUE_WAIT(ch.receiving(), 1000); |
2169 EXPECT_TRUE_WAIT(!ch.receiving(), 1000); | 2171 EXPECT_TRUE_WAIT(!ch.receiving(), 1000); |
2170 } | 2172 } |
2171 | 2173 |
2172 // The controlled side will select a connection as the "best connection" based | 2174 // The controlled side will select a connection as the "best connection" based |
2173 // on priority until the controlling side nominates a connection, at which | 2175 // on priority until the controlling side nominates a connection, at which |
2174 // point the controlled side will select that connection as the | 2176 // point the controlled side will select that connection as the |
2175 // "best connection". Plus, the channel will fire SignalReadyToSend if the new | 2177 // "best connection". Plus, SignalSelectedCandidatePair will be fired if the |
2176 // best connection is writable. | 2178 // best connection changes and SignalReadyToSend will be fired if the new best |
| 2179 // connection is writable. |
2177 TEST_F(P2PTransportChannelPingTest, TestSelectConnectionBeforeNomination) { | 2180 TEST_F(P2PTransportChannelPingTest, TestSelectConnectionBeforeNomination) { |
2178 cricket::FakePortAllocator pa(rtc::Thread::Current(), nullptr); | 2181 cricket::FakePortAllocator pa(rtc::Thread::Current(), nullptr); |
2179 cricket::P2PTransportChannel ch("receiving state change", 1, &pa); | 2182 cricket::P2PTransportChannel ch("receiving state change", 1, &pa); |
2180 PrepareChannel(&ch); | 2183 PrepareChannel(&ch); |
2181 ch.SetIceRole(cricket::ICEROLE_CONTROLLED); | 2184 ch.SetIceRole(cricket::ICEROLE_CONTROLLED); |
2182 ch.Connect(); | 2185 ch.Connect(); |
2183 ch.MaybeStartGathering(); | 2186 ch.MaybeStartGathering(); |
2184 ch.AddRemoteCandidate(CreateHostCandidate("1.1.1.1", 1, 1)); | 2187 ch.AddRemoteCandidate(CreateHostCandidate("1.1.1.1", 1, 1)); |
2185 cricket::Connection* conn1 = WaitForConnectionTo(&ch, "1.1.1.1", 1); | 2188 cricket::Connection* conn1 = WaitForConnectionTo(&ch, "1.1.1.1", 1); |
2186 ASSERT_TRUE(conn1 != nullptr); | 2189 ASSERT_TRUE(conn1 != nullptr); |
2187 EXPECT_EQ(conn1, ch.best_connection()); | 2190 EXPECT_EQ(conn1, ch.best_connection()); |
2188 // Channel is not ready because it is not writable. | 2191 EXPECT_EQ(conn1, last_selected_candidate_pair()); |
| 2192 EXPECT_EQ(-1, last_sent_packet_id()); |
| 2193 // Channel is not ready to send because it is not writable. |
2189 EXPECT_FALSE(channel_ready_to_send()); | 2194 EXPECT_FALSE(channel_ready_to_send()); |
2190 | 2195 |
| 2196 int last_packet_id = 0; |
| 2197 const char* data = "ABCDEFGH"; |
| 2198 int len = static_cast<int>(strlen(data)); |
| 2199 SendData(ch, data, len, ++last_packet_id); |
2191 // When a higher priority candidate comes in, the new connection is chosen | 2200 // When a higher priority candidate comes in, the new connection is chosen |
2192 // as the best connection. | 2201 // as the best connection. |
2193 ch.AddRemoteCandidate(CreateHostCandidate("2.2.2.2", 2, 10)); | 2202 ch.AddRemoteCandidate(CreateHostCandidate("2.2.2.2", 2, 10)); |
2194 cricket::Connection* conn2 = WaitForConnectionTo(&ch, "2.2.2.2", 2); | 2203 cricket::Connection* conn2 = WaitForConnectionTo(&ch, "2.2.2.2", 2); |
2195 ASSERT_TRUE(conn2 != nullptr); | 2204 ASSERT_TRUE(conn2 != nullptr); |
2196 EXPECT_EQ(conn2, ch.best_connection()); | 2205 EXPECT_EQ(conn2, ch.best_connection()); |
| 2206 EXPECT_EQ(conn2, last_selected_candidate_pair()); |
| 2207 EXPECT_EQ(last_packet_id, last_sent_packet_id()); |
2197 EXPECT_FALSE(channel_ready_to_send()); | 2208 EXPECT_FALSE(channel_ready_to_send()); |
2198 | 2209 |
2199 // If a stun request with use-candidate attribute arrives, the receiving | 2210 // If a stun request with use-candidate attribute arrives, the receiving |
2200 // connection will be set as the best connection, even though | 2211 // connection will be set as the best connection, even though |
2201 // its priority is lower. | 2212 // its priority is lower. |
| 2213 SendData(ch, data, len, ++last_packet_id); |
2202 ch.AddRemoteCandidate(CreateHostCandidate("3.3.3.3", 3, 1)); | 2214 ch.AddRemoteCandidate(CreateHostCandidate("3.3.3.3", 3, 1)); |
2203 cricket::Connection* conn3 = WaitForConnectionTo(&ch, "3.3.3.3", 3); | 2215 cricket::Connection* conn3 = WaitForConnectionTo(&ch, "3.3.3.3", 3); |
2204 ASSERT_TRUE(conn3 != nullptr); | 2216 ASSERT_TRUE(conn3 != nullptr); |
2205 // Because it has a lower priority, the best connection is still conn2. | 2217 // Because it has a lower priority, the best connection is still conn2. |
2206 EXPECT_EQ(conn2, ch.best_connection()); | 2218 EXPECT_EQ(conn2, ch.best_connection()); |
2207 conn3->ReceivedPingResponse(); // Become writable. | 2219 conn3->ReceivedPingResponse(); // Become writable. |
2208 // But if it is nominated via use_candidate, it is chosen as the best | 2220 // But if it is nominated via use_candidate, it is chosen as the best |
2209 // connection. | 2221 // connection. |
2210 conn3->set_nominated(true); | 2222 conn3->set_nominated(true); |
2211 conn3->SignalNominated(conn3); | 2223 conn3->SignalNominated(conn3); |
2212 EXPECT_EQ(conn3, ch.best_connection()); | 2224 EXPECT_EQ(conn3, ch.best_connection()); |
| 2225 EXPECT_EQ(conn3, last_selected_candidate_pair()); |
| 2226 EXPECT_EQ(last_packet_id, last_sent_packet_id()); |
2213 EXPECT_TRUE(channel_ready_to_send()); | 2227 EXPECT_TRUE(channel_ready_to_send()); |
2214 | 2228 |
2215 // Even if another higher priority candidate arrives, | 2229 // Even if another higher priority candidate arrives, |
2216 // it will not be set as the best connection because the best connection | 2230 // it will not be set as the best connection because the best connection |
2217 // is nominated by the controlling side. | 2231 // is nominated by the controlling side. |
| 2232 SendData(ch, data, len, ++last_packet_id); |
2218 ch.AddRemoteCandidate(CreateHostCandidate("4.4.4.4", 4, 100)); | 2233 ch.AddRemoteCandidate(CreateHostCandidate("4.4.4.4", 4, 100)); |
2219 cricket::Connection* conn4 = WaitForConnectionTo(&ch, "4.4.4.4", 4); | 2234 cricket::Connection* conn4 = WaitForConnectionTo(&ch, "4.4.4.4", 4); |
2220 ASSERT_TRUE(conn4 != nullptr); | 2235 ASSERT_TRUE(conn4 != nullptr); |
2221 EXPECT_EQ(conn3, ch.best_connection()); | 2236 EXPECT_EQ(conn3, ch.best_connection()); |
2222 // But if it is nominated via use_candidate and writable, it will be set as | 2237 // But if it is nominated via use_candidate and writable, it will be set as |
2223 // the best connection. | 2238 // the best connection. |
2224 conn4->set_nominated(true); | 2239 conn4->set_nominated(true); |
2225 conn4->SignalNominated(conn4); | 2240 conn4->SignalNominated(conn4); |
2226 // Not switched yet because conn4 is not writable. | 2241 // Not switched yet because conn4 is not writable. |
2227 EXPECT_EQ(conn3, ch.best_connection()); | 2242 EXPECT_EQ(conn3, ch.best_connection()); |
2228 reset_channel_ready_to_send(); | 2243 reset_channel_ready_to_send(); |
2229 // The best connection switches after conn4 becomes writable. | 2244 // The best connection switches after conn4 becomes writable. |
2230 conn4->ReceivedPingResponse(); | 2245 conn4->ReceivedPingResponse(); |
2231 EXPECT_EQ(conn4, ch.best_connection()); | 2246 EXPECT_EQ(conn4, ch.best_connection()); |
| 2247 EXPECT_EQ(conn4, last_selected_candidate_pair()); |
| 2248 EXPECT_EQ(last_packet_id, last_sent_packet_id()); |
2232 // SignalReadyToSend is fired again because conn4 is writable. | 2249 // SignalReadyToSend is fired again because conn4 is writable. |
2233 EXPECT_TRUE(channel_ready_to_send()); | 2250 EXPECT_TRUE(channel_ready_to_send()); |
2234 } | 2251 } |
2235 | 2252 |
2236 // The controlled side will select a connection as the "best connection" based | 2253 // The controlled side will select a connection as the "best connection" based |
2237 // on requests from an unknown address before the controlling side nominates | 2254 // 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 | 2255 // 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 | 2256 // 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. | 2257 // a ping response and set the ICE pwd in the remote candidate appropriately. |
2241 TEST_F(P2PTransportChannelPingTest, TestSelectConnectionFromUnknownAddress) { | 2258 TEST_F(P2PTransportChannelPingTest, TestSelectConnectionFromUnknownAddress) { |
(...skipping 521 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2763 | 2780 |
2764 // TCP Relay/Relay is the next. | 2781 // TCP Relay/Relay is the next. |
2765 VerifyNextPingableConnection(cricket::RELAY_PORT_TYPE, | 2782 VerifyNextPingableConnection(cricket::RELAY_PORT_TYPE, |
2766 cricket::RELAY_PORT_TYPE, | 2783 cricket::RELAY_PORT_TYPE, |
2767 cricket::TCP_PROTOCOL_NAME); | 2784 cricket::TCP_PROTOCOL_NAME); |
2768 | 2785 |
2769 // Finally, Local/Relay will be pinged. | 2786 // Finally, Local/Relay will be pinged. |
2770 VerifyNextPingableConnection(cricket::LOCAL_PORT_TYPE, | 2787 VerifyNextPingableConnection(cricket::LOCAL_PORT_TYPE, |
2771 cricket::RELAY_PORT_TYPE); | 2788 cricket::RELAY_PORT_TYPE); |
2772 } | 2789 } |
OLD | NEW |