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 1703 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1714 // an exchange of pings. | 1714 // an exchange of pings. |
| 1715 EXPECT_TRUE_WAIT( | 1715 EXPECT_TRUE_WAIT( |
| 1716 ep1_ch1()->best_connection() && ep2_ch1()->best_connection() && | 1716 ep1_ch1()->best_connection() && ep2_ch1()->best_connection() && |
| 1717 LocalCandidate(ep1_ch1())->address().EqualIPs(kPublicAddrs[0]) && | 1717 LocalCandidate(ep1_ch1())->address().EqualIPs(kPublicAddrs[0]) && |
| 1718 RemoteCandidate(ep1_ch1())->address().EqualIPs(kAlternateAddrs[1]), | 1718 RemoteCandidate(ep1_ch1())->address().EqualIPs(kAlternateAddrs[1]), |
| 1719 3000); | 1719 3000); |
| 1720 | 1720 |
| 1721 DestroyChannels(); | 1721 DestroyChannels(); |
| 1722 } | 1722 } |
| 1723 | 1723 |
| 1724 class P2PTransportChannelPingOrderTest : public testing::Test, | 1724 class P2PTransportChannelSingleEndpointTest : public testing::Test, |
|
pthatcher1
2015/06/09 23:58:03
Let's just call it P2PTransportChannelTest
guoweis_webrtc
2015/06/10 18:12:41
P2PTransportChannelTest exists already.
| |
| 1725 public sigslot::has_slots<> { | 1725 public sigslot::has_slots<> { |
| 1726 public: | 1726 public: |
| 1727 P2PTransportChannelPingOrderTest() : | 1727 P2PTransportChannelSingleEndpointTest() |
| 1728 pss_(new rtc::PhysicalSocketServer), | 1728 : pss_(new rtc::PhysicalSocketServer), |
| 1729 vss_(new rtc::VirtualSocketServer(pss_.get())), | 1729 vss_(new rtc::VirtualSocketServer(pss_.get())), |
| 1730 ss_scope_(vss_.get()) { | 1730 ss_scope_(vss_.get()) {} |
| 1731 } | |
| 1732 | 1731 |
| 1733 protected: | 1732 protected: |
| 1734 void PrepareChannel(cricket::P2PTransportChannel* ch) { | 1733 void PrepareChannel(cricket::P2PTransportChannel* ch) { |
| 1735 ch->SignalRequestSignaling.connect( | 1734 ch->SignalRequestSignaling.connect( |
| 1736 this, &P2PTransportChannelPingOrderTest::OnChannelRequestSignaling); | 1735 this, |
| 1736 &P2PTransportChannelSingleEndpointTest::OnChannelRequestSignaling); | |
| 1737 ch->SetIceProtocolType(cricket::ICEPROTO_RFC5245); | 1737 ch->SetIceProtocolType(cricket::ICEPROTO_RFC5245); |
| 1738 ch->SetIceRole(cricket::ICEROLE_CONTROLLING); | 1738 ch->SetIceRole(cricket::ICEROLE_CONTROLLING); |
| 1739 ch->SetIceCredentials(kIceUfrag[0], kIcePwd[0]); | 1739 ch->SetIceCredentials(kIceUfrag[0], kIcePwd[0]); |
| 1740 ch->SetRemoteIceCredentials(kIceUfrag[1], kIcePwd[1]); | 1740 ch->SetRemoteIceCredentials(kIceUfrag[1], kIcePwd[1]); |
| 1741 } | 1741 } |
| 1742 | 1742 |
| 1743 void OnChannelRequestSignaling(cricket::TransportChannelImpl* channel) { | 1743 void OnChannelRequestSignaling(cricket::TransportChannelImpl* channel) { |
| 1744 channel->OnSignalingReady(); | 1744 channel->OnSignalingReady(); |
| 1745 } | 1745 } |
| 1746 | 1746 |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1779 EXPECT_TRUE_WAIT(conn->last_ping_sent() > 0, 3000); | 1779 EXPECT_TRUE_WAIT(conn->last_ping_sent() > 0, 3000); |
| 1780 return conn->last_ping_sent(); | 1780 return conn->last_ping_sent(); |
| 1781 } | 1781 } |
| 1782 | 1782 |
| 1783 private: | 1783 private: |
| 1784 rtc::scoped_ptr<rtc::PhysicalSocketServer> pss_; | 1784 rtc::scoped_ptr<rtc::PhysicalSocketServer> pss_; |
| 1785 rtc::scoped_ptr<rtc::VirtualSocketServer> vss_; | 1785 rtc::scoped_ptr<rtc::VirtualSocketServer> vss_; |
| 1786 rtc::SocketServerScope ss_scope_; | 1786 rtc::SocketServerScope ss_scope_; |
| 1787 }; | 1787 }; |
| 1788 | 1788 |
| 1789 TEST_F(P2PTransportChannelPingOrderTest, TestTriggeredChecks) { | 1789 TEST_F(P2PTransportChannelSingleEndpointTest, TestTriggeredChecks) { |
| 1790 cricket::FakePortAllocator pa(rtc::Thread::Current(), nullptr); | 1790 cricket::FakePortAllocator pa(rtc::Thread::Current(), nullptr); |
| 1791 cricket::P2PTransportChannel ch("trigger checks", 1, nullptr, &pa); | 1791 cricket::P2PTransportChannel ch("trigger checks", 1, nullptr, &pa); |
| 1792 PrepareChannel(&ch); | 1792 PrepareChannel(&ch); |
| 1793 ch.Connect(); | 1793 ch.Connect(); |
| 1794 ch.OnCandidate(CreateCandidate("1.1.1.1", 1, 1)); | 1794 ch.OnCandidate(CreateCandidate("1.1.1.1", 1, 1)); |
| 1795 ch.OnCandidate(CreateCandidate("2.2.2.2", 2, 2)); | 1795 ch.OnCandidate(CreateCandidate("2.2.2.2", 2, 2)); |
| 1796 | 1796 |
| 1797 cricket::Connection* conn1 = WaitForConnectionTo(&ch, "1.1.1.1", 1); | 1797 cricket::Connection* conn1 = WaitForConnectionTo(&ch, "1.1.1.1", 1); |
| 1798 cricket::Connection* conn2 = WaitForConnectionTo(&ch, "2.2.2.2", 2); | 1798 cricket::Connection* conn2 = WaitForConnectionTo(&ch, "2.2.2.2", 2); |
| 1799 ASSERT_TRUE(conn1 != nullptr); | 1799 ASSERT_TRUE(conn1 != nullptr); |
| 1800 ASSERT_TRUE(conn2 != nullptr); | 1800 ASSERT_TRUE(conn2 != nullptr); |
| 1801 | 1801 |
| 1802 // Receiving a ping causes a "triggered check" which should make conn1 | 1802 // Receiving a ping causes a "triggered check" which should make conn1 |
| 1803 // be pinged first instead of conn2, even though conn2 has a higher priority. | 1803 // be pinged first instead of conn2, even though conn2 has a higher priority. |
| 1804 conn1->ReceivedPing(); | 1804 conn1->ReceivedPing(); |
| 1805 uint32 ping1 = WaitForFirstPing(conn1); | 1805 uint32 ping1 = WaitForFirstPing(conn1); |
| 1806 uint32 ping2 = WaitForFirstPing(conn2); | 1806 uint32 ping2 = WaitForFirstPing(conn2); |
| 1807 EXPECT_LT(ping1, ping2); | 1807 EXPECT_LT(ping1, ping2); |
| 1808 } | 1808 } |
| 1809 | 1809 |
| 1810 TEST_F(P2PTransportChannelPingOrderTest, | 1810 TEST_F(P2PTransportChannelSingleEndpointTest, |
| 1811 TestNoTriggeredChecksWithoutIncomingPing) { | 1811 TestNoTriggeredChecksWithoutIncomingPing) { |
| 1812 cricket::FakePortAllocator pa(rtc::Thread::Current(), nullptr); | 1812 cricket::FakePortAllocator pa(rtc::Thread::Current(), nullptr); |
| 1813 cricket::P2PTransportChannel ch("trigger checks", 1, nullptr, &pa); | 1813 cricket::P2PTransportChannel ch("trigger checks", 1, nullptr, &pa); |
| 1814 PrepareChannel(&ch); | 1814 PrepareChannel(&ch); |
| 1815 ch.Connect(); | 1815 ch.Connect(); |
| 1816 ch.OnCandidate(CreateCandidate("1.1.1.1", 1, 1)); | 1816 ch.OnCandidate(CreateCandidate("1.1.1.1", 1, 1)); |
| 1817 ch.OnCandidate(CreateCandidate("2.2.2.2", 2, 2)); | 1817 ch.OnCandidate(CreateCandidate("2.2.2.2", 2, 2)); |
| 1818 | 1818 |
| 1819 cricket::Connection* conn1 = WaitForConnectionTo(&ch, "1.1.1.1", 1); | 1819 cricket::Connection* conn1 = WaitForConnectionTo(&ch, "1.1.1.1", 1); |
| 1820 cricket::Connection* conn2 = WaitForConnectionTo(&ch, "2.2.2.2", 2); | 1820 cricket::Connection* conn2 = WaitForConnectionTo(&ch, "2.2.2.2", 2); |
| 1821 ASSERT_TRUE(conn1 != nullptr); | 1821 ASSERT_TRUE(conn1 != nullptr); |
| 1822 ASSERT_TRUE(conn2 != nullptr); | 1822 ASSERT_TRUE(conn2 != nullptr); |
| 1823 | 1823 |
| 1824 // No ping received, so no "triggered check" so conn2 is pinged | 1824 // No ping received, so no "triggered check" so conn2 is pinged |
| 1825 // before conn1 because it has a higher priority. | 1825 // before conn1 because it has a higher priority. |
| 1826 uint32 ping2 = WaitForFirstPing(conn2); | 1826 uint32 ping2 = WaitForFirstPing(conn2); |
| 1827 uint32 ping1 = WaitForFirstPing(conn1); | 1827 uint32 ping1 = WaitForFirstPing(conn1); |
| 1828 EXPECT_LT(ping2, ping1); | 1828 EXPECT_LT(ping2, ping1); |
| 1829 } | 1829 } |
| 1830 | 1830 |
| 1831 TEST_F(P2PTransportChannelPingOrderTest, TestNoTriggeredChecksWhenWritable) { | 1831 TEST_F(P2PTransportChannelSingleEndpointTest, |
| 1832 TestNoTriggeredChecksWhenWritable) { | |
| 1832 cricket::FakePortAllocator pa(rtc::Thread::Current(), nullptr); | 1833 cricket::FakePortAllocator pa(rtc::Thread::Current(), nullptr); |
| 1833 cricket::P2PTransportChannel ch("trigger checks", 1, nullptr, &pa); | 1834 cricket::P2PTransportChannel ch("trigger checks", 1, nullptr, &pa); |
| 1834 PrepareChannel(&ch); | 1835 PrepareChannel(&ch); |
| 1835 ch.Connect(); | 1836 ch.Connect(); |
| 1836 ch.OnCandidate(CreateCandidate("1.1.1.1", 1, 1)); | 1837 ch.OnCandidate(CreateCandidate("1.1.1.1", 1, 1)); |
| 1837 ch.OnCandidate(CreateCandidate("2.2.2.2", 2, 2)); | 1838 ch.OnCandidate(CreateCandidate("2.2.2.2", 2, 2)); |
| 1838 | 1839 |
| 1839 cricket::Connection* conn1 = WaitForConnectionTo(&ch, "1.1.1.1", 1); | 1840 cricket::Connection* conn1 = WaitForConnectionTo(&ch, "1.1.1.1", 1); |
| 1840 cricket::Connection* conn2 = WaitForConnectionTo(&ch, "2.2.2.2", 2); | 1841 cricket::Connection* conn2 = WaitForConnectionTo(&ch, "2.2.2.2", 2); |
| 1841 ASSERT_TRUE(conn1 != nullptr); | 1842 ASSERT_TRUE(conn1 != nullptr); |
| (...skipping 12 matching lines...) Expand all Loading... | |
| 1854 if ((ping1 - before_pings) < 900) { | 1855 if ((ping1 - before_pings) < 900) { |
| 1855 // If ping2 takes longer than 900ms to send, then there's a chance | 1856 // If ping2 takes longer than 900ms to send, then there's a chance |
| 1856 // that ping1 will go out before ping2 because of the pings that | 1857 // that ping1 will go out before ping2 because of the pings that |
| 1857 // keep a connection writable, which come before triggered checks. | 1858 // keep a connection writable, which come before triggered checks. |
| 1858 // This would only happen if the tests are running very, very | 1859 // This would only happen if the tests are running very, very |
| 1859 // slowly. But to avoid the tests being flaky on very slow bots, | 1860 // slowly. But to avoid the tests being flaky on very slow bots, |
| 1860 // we add the check. | 1861 // we add the check. |
| 1861 EXPECT_LT(ping2, ping1); | 1862 EXPECT_LT(ping2, ping1); |
| 1862 } | 1863 } |
| 1863 } | 1864 } |
| 1865 | |
| 1866 TEST_F(P2PTransportChannelSingleEndpointTest, ConnectionResurrection) { | |
| 1867 cricket::FakePortAllocator pa(rtc::Thread::Current(), nullptr); | |
| 1868 cricket::P2PTransportChannel ch("connection resurrection", 1, nullptr, &pa); | |
| 1869 PrepareChannel(&ch); | |
| 1870 ch.Connect(); | |
| 1871 | |
| 1872 // Create conn1 and keep track of original candidate priority. | |
| 1873 ch.OnCandidate(CreateCandidate("1.1.1.1", 1, 1)); | |
| 1874 cricket::Connection* conn1 = WaitForConnectionTo(&ch, "1.1.1.1", 1); | |
| 1875 ASSERT_TRUE(conn1 != nullptr); | |
| 1876 uint32 remote_priority = conn1->remote_candidate().priority(); | |
| 1877 | |
| 1878 // Create a higher priority candidate and make the connection | |
| 1879 // readable/writable. This will prune conn1. | |
| 1880 ch.OnCandidate(CreateCandidate("2.2.2.2", 2, 2)); | |
| 1881 cricket::Connection* conn2 = WaitForConnectionTo(&ch, "2.2.2.2", 2); | |
| 1882 ASSERT_TRUE(conn2 != nullptr); | |
| 1883 conn2->ReceivedPing(); | |
| 1884 conn2->ReceivedPingResponse(); | |
| 1885 | |
| 1886 // Wait for conn1 being destroyed. | |
| 1887 EXPECT_TRUE_WAIT(GetConnectionTo(&ch, "1.1.1.1", 1) == nullptr, 3000); | |
| 1888 cricket::Port* port = static_cast<cricket::Port*>(ch.ports()[0]); | |
|
pthatcher1
2015/06/09 23:58:03
Can you make this its own function?
guoweis_webrtc
2015/06/10 18:12:41
Done.
| |
| 1889 | |
| 1890 // Create a minimal STUN message with prflx priority. | |
| 1891 cricket::IceMessage request; | |
| 1892 request.SetType(cricket::STUN_BINDING_REQUEST); | |
| 1893 request.AddAttribute(new cricket::StunByteStringAttribute( | |
| 1894 cricket::STUN_ATTR_USERNAME, kIceUfrag[1])); | |
| 1895 uint32 prflx_priority = cricket::ICE_TYPE_PREFERENCE_PRFLX << 24 | | |
| 1896 (conn1->remote_candidate().priority() & 0x00FFFFFF); | |
|
pthatcher1
2015/06/09 23:58:03
Can you make this its own method?
guoweis_webrtc
2015/06/10 18:12:41
Done.
| |
| 1897 request.AddAttribute(new cricket::StunUInt32Attribute( | |
| 1898 cricket::STUN_ATTR_PRIORITY, prflx_priority)); | |
| 1899 EXPECT_NE(prflx_priority, remote_priority); | |
| 1900 | |
| 1901 // conn1 should be resurrected with original priority. | |
| 1902 port->SignalUnknownAddress(port, rtc::SocketAddress("1.1.1.1", 1), | |
| 1903 cricket::PROTO_UDP, &request, kIceUfrag[1], false); | |
| 1904 conn1 = WaitForConnectionTo(&ch, "1.1.1.1", 1); | |
| 1905 ASSERT_TRUE(conn1 != nullptr); | |
| 1906 EXPECT_EQ(conn1->remote_candidate().priority(), remote_priority); | |
| 1907 | |
| 1908 // conn3, a real prflx connection, should have prflx priority. | |
| 1909 port->SignalUnknownAddress(port, rtc::SocketAddress("3.3.3.3", 1), | |
| 1910 cricket::PROTO_UDP, &request, kIceUfrag[1], false); | |
| 1911 cricket::Connection* conn3 = WaitForConnectionTo(&ch, "3.3.3.3", 1); | |
| 1912 ASSERT_TRUE(conn3 != nullptr); | |
| 1913 EXPECT_EQ(conn3->remote_candidate().priority(), prflx_priority); | |
| 1914 } | |
| OLD | NEW |