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

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

Issue 1842093002: Add the last_sent_packet_id to the candidate pair change signal (Closed) Base URL: https://chromium.googlesource.com/external/webrtc@master
Patch Set: Created 4 years, 8 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 299 matching lines...) Expand 10 before | Expand all | Expand 10 after
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
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
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
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
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 } 1902 }
1924 1903
1925 cricket::Candidate CreateHostCandidate(const std::string& ip, 1904 cricket::Candidate CreateHostCandidate(const std::string& ip,
1926 int port, 1905 int port,
1927 int priority, 1906 int priority,
1928 const std::string& ufrag = "") { 1907 const std::string& ufrag = "") {
1929 cricket::Candidate c; 1908 cricket::Candidate c;
1930 c.set_address(rtc::SocketAddress(ip, port)); 1909 c.set_address(rtc::SocketAddress(ip, port));
1931 c.set_component(1); 1910 c.set_component(1);
1932 c.set_protocol(cricket::UDP_PROTOCOL_NAME); 1911 c.set_protocol(cricket::UDP_PROTOCOL_NAME);
(...skipping 29 matching lines...) Expand all
1962 1941
1963 cricket::Connection* FindNextPingableConnectionAndPingIt( 1942 cricket::Connection* FindNextPingableConnectionAndPingIt(
1964 cricket::P2PTransportChannel* ch) { 1943 cricket::P2PTransportChannel* ch) {
1965 cricket::Connection* conn = ch->FindNextPingableConnection(); 1944 cricket::Connection* conn = ch->FindNextPingableConnection();
1966 if (conn) { 1945 if (conn) {
1967 ch->MarkConnectionPinged(conn); 1946 ch->MarkConnectionPinged(conn);
1968 } 1947 }
1969 return conn; 1948 return conn;
1970 } 1949 }
1971 1950
1951 void OnSelectedCandidatePairChanged(
1952 cricket::TransportChannel* transport_channel,
1953 cricket::CandidatePairInterface* selected_candidate_pair,
1954 int last_sent_packet_id) {
1955 last_selected_candidate_pair_ = selected_candidate_pair;
1956 last_sent_packet_id_ = last_sent_packet_id;
1957 }
1958
1959 cricket::CandidatePairInterface* last_selected_candidate_pair() {
1960 return last_selected_candidate_pair_;
1961 }
1962 int last_sent_packet_id() { return last_sent_packet_id_; }
1963
1972 private: 1964 private:
1973 rtc::scoped_ptr<rtc::PhysicalSocketServer> pss_; 1965 rtc::scoped_ptr<rtc::PhysicalSocketServer> pss_;
1974 rtc::scoped_ptr<rtc::VirtualSocketServer> vss_; 1966 rtc::scoped_ptr<rtc::VirtualSocketServer> vss_;
1975 rtc::SocketServerScope ss_scope_; 1967 rtc::SocketServerScope ss_scope_;
1968 cricket::CandidatePairInterface* last_selected_candidate_pair_ = nullptr;
1969 int last_sent_packet_id_ = -1;
1976 }; 1970 };
1977 1971
1978 TEST_F(P2PTransportChannelPingTest, TestTriggeredChecks) { 1972 TEST_F(P2PTransportChannelPingTest, TestTriggeredChecks) {
1979 cricket::FakePortAllocator pa(rtc::Thread::Current(), nullptr); 1973 cricket::FakePortAllocator pa(rtc::Thread::Current(), nullptr);
1980 cricket::P2PTransportChannel ch("trigger checks", 1, &pa); 1974 cricket::P2PTransportChannel ch("trigger checks", 1, &pa);
1981 PrepareChannel(&ch); 1975 PrepareChannel(&ch);
1982 ch.Connect(); 1976 ch.Connect();
1983 ch.MaybeStartGathering(); 1977 ch.MaybeStartGathering();
1984 ch.AddRemoteCandidate(CreateHostCandidate("1.1.1.1", 1, 1)); 1978 ch.AddRemoteCandidate(CreateHostCandidate("1.1.1.1", 1, 1));
1985 ch.AddRemoteCandidate(CreateHostCandidate("2.2.2.2", 2, 2)); 1979 ch.AddRemoteCandidate(CreateHostCandidate("2.2.2.2", 2, 2));
(...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after
2155 conn1->ReceivedPing(); 2149 conn1->ReceivedPing();
2156 conn1->OnReadPacket("ABC", 3, rtc::CreatePacketTime(0)); 2150 conn1->OnReadPacket("ABC", 3, rtc::CreatePacketTime(0));
2157 EXPECT_TRUE_WAIT(ch.best_connection() != nullptr, 1000); 2151 EXPECT_TRUE_WAIT(ch.best_connection() != nullptr, 1000);
2158 EXPECT_TRUE_WAIT(ch.receiving(), 1000); 2152 EXPECT_TRUE_WAIT(ch.receiving(), 1000);
2159 EXPECT_TRUE_WAIT(!ch.receiving(), 1000); 2153 EXPECT_TRUE_WAIT(!ch.receiving(), 1000);
2160 } 2154 }
2161 2155
2162 // The controlled side will select a connection as the "best connection" based 2156 // The controlled side will select a connection as the "best connection" based
2163 // on priority until the controlling side nominates a connection, at which 2157 // on priority until the controlling side nominates a connection, at which
2164 // point the controlled side will select that connection as the 2158 // point the controlled side will select that connection as the
2165 // "best connection". 2159 // "best connection". Plus, SignalCandidatePair will be fired if the best
2160 // connection changes.
2166 TEST_F(P2PTransportChannelPingTest, TestSelectConnectionBeforeNomination) { 2161 TEST_F(P2PTransportChannelPingTest, TestSelectConnectionBeforeNomination) {
2167 cricket::FakePortAllocator pa(rtc::Thread::Current(), nullptr); 2162 cricket::FakePortAllocator pa(rtc::Thread::Current(), nullptr);
2168 cricket::P2PTransportChannel ch("receiving state change", 1, &pa); 2163 cricket::P2PTransportChannel ch("receiving state change", 1, &pa);
2169 PrepareChannel(&ch); 2164 PrepareChannel(&ch);
2170 ch.SetIceRole(cricket::ICEROLE_CONTROLLED); 2165 ch.SetIceRole(cricket::ICEROLE_CONTROLLED);
2171 ch.Connect(); 2166 ch.Connect();
2172 ch.MaybeStartGathering(); 2167 ch.MaybeStartGathering();
2173 ch.AddRemoteCandidate(CreateHostCandidate("1.1.1.1", 1, 1)); 2168 ch.AddRemoteCandidate(CreateHostCandidate("1.1.1.1", 1, 1));
2174 cricket::Connection* conn1 = WaitForConnectionTo(&ch, "1.1.1.1", 1); 2169 cricket::Connection* conn1 = WaitForConnectionTo(&ch, "1.1.1.1", 1);
2175 ASSERT_TRUE(conn1 != nullptr); 2170 ASSERT_TRUE(conn1 != nullptr);
2176 EXPECT_EQ(conn1, ch.best_connection()); 2171 EXPECT_EQ(conn1, ch.best_connection());
2172 EXPECT_EQ(conn1, last_selected_candidate_pair());
2173 EXPECT_EQ(-1, last_sent_packet_id());
2177 2174
2175 int last_packet_id = 0;
2176 ch.set_last_sent_packet_id(++last_packet_id);
2178 // When a higher priority candidate comes in, the new connection is chosen 2177 // When a higher priority candidate comes in, the new connection is chosen
2179 // as the best connection. 2178 // as the best connection.
2180 ch.AddRemoteCandidate(CreateHostCandidate("2.2.2.2", 2, 10)); 2179 ch.AddRemoteCandidate(CreateHostCandidate("2.2.2.2", 2, 10));
2181 cricket::Connection* conn2 = WaitForConnectionTo(&ch, "2.2.2.2", 2); 2180 cricket::Connection* conn2 = WaitForConnectionTo(&ch, "2.2.2.2", 2);
2182 ASSERT_TRUE(conn2 != nullptr); 2181 ASSERT_TRUE(conn2 != nullptr);
2183 EXPECT_EQ(conn2, ch.best_connection()); 2182 EXPECT_EQ(conn2, ch.best_connection());
2183 EXPECT_EQ(conn2, last_selected_candidate_pair());
2184 EXPECT_EQ(last_packet_id, last_sent_packet_id());
2184 2185
2185 // If a stun request with use-candidate attribute arrives, the receiving 2186 // If a stun request with use-candidate attribute arrives, the receiving
2186 // connection will be set as the best connection, even though 2187 // connection will be set as the best connection, even though
2187 // its priority is lower. 2188 // its priority is lower.
2189 ch.set_last_sent_packet_id(++last_packet_id);
2188 ch.AddRemoteCandidate(CreateHostCandidate("3.3.3.3", 3, 1)); 2190 ch.AddRemoteCandidate(CreateHostCandidate("3.3.3.3", 3, 1));
2189 cricket::Connection* conn3 = WaitForConnectionTo(&ch, "3.3.3.3", 3); 2191 cricket::Connection* conn3 = WaitForConnectionTo(&ch, "3.3.3.3", 3);
2190 ASSERT_TRUE(conn3 != nullptr); 2192 ASSERT_TRUE(conn3 != nullptr);
2191 // Because it has a lower priority, the best connection is still conn2. 2193 // Because it has a lower priority, the best connection is still conn2.
2192 EXPECT_EQ(conn2, ch.best_connection()); 2194 EXPECT_EQ(conn2, ch.best_connection());
2193 conn3->ReceivedPingResponse(); // Become writable. 2195 conn3->ReceivedPingResponse(); // Become writable.
2194 // But if it is nominated via use_candidate, it is chosen as the best 2196 // But if it is nominated via use_candidate, it is chosen as the best
2195 // connection. 2197 // connection.
2196 conn3->set_nominated(true); 2198 conn3->set_nominated(true);
2197 conn3->SignalNominated(conn3); 2199 conn3->SignalNominated(conn3);
2198 EXPECT_EQ(conn3, ch.best_connection()); 2200 EXPECT_EQ(conn3, ch.best_connection());
2201 EXPECT_EQ(conn3, last_selected_candidate_pair());
2202 EXPECT_EQ(last_packet_id, last_sent_packet_id());
2199 2203
2200 // Even if another higher priority candidate arrives, 2204 // Even if another higher priority candidate arrives,
2201 // it will not be set as the best connection because the best connection 2205 // it will not be set as the best connection because the best connection
2202 // is nominated by the controlling side. 2206 // is nominated by the controlling side.
2207 ch.set_last_sent_packet_id(++last_packet_id);
2203 ch.AddRemoteCandidate(CreateHostCandidate("4.4.4.4", 4, 100)); 2208 ch.AddRemoteCandidate(CreateHostCandidate("4.4.4.4", 4, 100));
2204 cricket::Connection* conn4 = WaitForConnectionTo(&ch, "4.4.4.4", 4); 2209 cricket::Connection* conn4 = WaitForConnectionTo(&ch, "4.4.4.4", 4);
2205 ASSERT_TRUE(conn4 != nullptr); 2210 ASSERT_TRUE(conn4 != nullptr);
2206 EXPECT_EQ(conn3, ch.best_connection()); 2211 EXPECT_EQ(conn3, ch.best_connection());
2207 // But if it is nominated via use_candidate and writable, it will be set as 2212 // But if it is nominated via use_candidate and writable, it will be set as
2208 // the best connection. 2213 // the best connection.
2209 conn4->set_nominated(true); 2214 conn4->set_nominated(true);
2210 conn4->SignalNominated(conn4); 2215 conn4->SignalNominated(conn4);
2211 // Not switched yet because conn4 is not writable. 2216 // Not switched yet because conn4 is not writable.
2212 EXPECT_EQ(conn3, ch.best_connection()); 2217 EXPECT_EQ(conn3, ch.best_connection());
2213 // The best connection switches after conn4 becomes writable. 2218 // The best connection switches after conn4 becomes writable.
2214 conn4->ReceivedPingResponse(); 2219 conn4->ReceivedPingResponse();
2215 EXPECT_EQ(conn4, ch.best_connection()); 2220 EXPECT_EQ(conn4, ch.best_connection());
2221 EXPECT_EQ(conn4, last_selected_candidate_pair());
2222 EXPECT_EQ(last_packet_id, last_sent_packet_id());
2216 } 2223 }
2217 2224
2218 // The controlled side will select a connection as the "best connection" based 2225 // The controlled side will select a connection as the "best connection" based
2219 // on requests from an unknown address before the controlling side nominates 2226 // on requests from an unknown address before the controlling side nominates
2220 // a connection, and will nominate a connection from an unknown address if the 2227 // a connection, and will nominate a connection from an unknown address if the
2221 // request contains the use_candidate attribute. Plus, it will also sends back 2228 // request contains the use_candidate attribute. Plus, it will also sends back
2222 // a ping response and set the ICE pwd in the remote candidate appropriately. 2229 // a ping response and set the ICE pwd in the remote candidate appropriately.
2223 TEST_F(P2PTransportChannelPingTest, TestSelectConnectionFromUnknownAddress) { 2230 TEST_F(P2PTransportChannelPingTest, TestSelectConnectionFromUnknownAddress) {
2224 cricket::FakePortAllocator pa(rtc::Thread::Current(), nullptr); 2231 cricket::FakePortAllocator pa(rtc::Thread::Current(), nullptr);
2225 cricket::P2PTransportChannel ch("receiving state change", 1, &pa); 2232 cricket::P2PTransportChannel ch("receiving state change", 1, &pa);
(...skipping 519 matching lines...) Expand 10 before | Expand all | Expand 10 after
2745 2752
2746 // TCP Relay/Relay is the next. 2753 // TCP Relay/Relay is the next.
2747 VerifyNextPingableConnection(cricket::RELAY_PORT_TYPE, 2754 VerifyNextPingableConnection(cricket::RELAY_PORT_TYPE,
2748 cricket::RELAY_PORT_TYPE, 2755 cricket::RELAY_PORT_TYPE,
2749 cricket::TCP_PROTOCOL_NAME); 2756 cricket::TCP_PROTOCOL_NAME);
2750 2757
2751 // Finally, Local/Relay will be pinged. 2758 // Finally, Local/Relay will be pinged.
2752 VerifyNextPingableConnection(cricket::LOCAL_PORT_TYPE, 2759 VerifyNextPingableConnection(cricket::LOCAL_PORT_TYPE,
2753 cricket::RELAY_PORT_TYPE); 2760 cricket::RELAY_PORT_TYPE);
2754 } 2761 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698