Chromium Code Reviews

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

Issue 1270613006: First step of passive aggressive nomination. (Closed) Base URL: https://chromium.googlesource.com/external/webrtc@master
Patch Set: Created 5 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff |
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 1866 matching lines...)
1877 ch.OnCandidate(CreateCandidate("1.1.1.1", 1, 1)); 1877 ch.OnCandidate(CreateCandidate("1.1.1.1", 1, 1));
1878 cricket::Connection* conn1 = WaitForConnectionTo(&ch, "1.1.1.1", 1); 1878 cricket::Connection* conn1 = WaitForConnectionTo(&ch, "1.1.1.1", 1);
1879 ASSERT_TRUE(conn1 != nullptr); 1879 ASSERT_TRUE(conn1 != nullptr);
1880 1880
1881 conn1->ReceivedPing(); 1881 conn1->ReceivedPing();
1882 conn1->OnReadPacket("ABC", 3, rtc::CreatePacketTime(0)); 1882 conn1->OnReadPacket("ABC", 3, rtc::CreatePacketTime(0));
1883 EXPECT_TRUE_WAIT(ch.best_connection() != nullptr, 1000) 1883 EXPECT_TRUE_WAIT(ch.best_connection() != nullptr, 1000)
1884 EXPECT_TRUE_WAIT(ch.receiving(), 1000); 1884 EXPECT_TRUE_WAIT(ch.receiving(), 1000);
1885 EXPECT_TRUE_WAIT(!ch.receiving(), 1000); 1885 EXPECT_TRUE_WAIT(!ch.receiving(), 1000);
1886 } 1886 }
1887
1888 // When the p2p transport channel with a controlled role received a candidate,
pthatcher1 2015/08/07 22:50:22 You could just shorten this to 'The controlled sid
honghaiz3 2015/08/10 20:15:43 Done.
1889 // it should set up the best connection if the best connection was not nominated
1890 // by the controlling side (via use_candidate attribute). If the best connection
1891 // was nominated by the controlling side, the connection receiving a new
1892 // candidate will not be set as the best connection.
1893 TEST_F(P2PTransportChannelPingTest, TestPassiveAggressiveNomination) {
pthatcher1 2015/08/07 22:50:22 It's not yet passive aggressive nomination. It's
honghaiz3 2015/08/10 20:15:43 Done. Shortened the name a little bit.
1894 cricket::FakePortAllocator pa(rtc::Thread::Current(), nullptr);
1895 cricket::P2PTransportChannel ch("receiving state change", 1, nullptr, &pa);
1896 PrepareChannel(&ch);
1897 ch.SetIceRole(cricket::ICEROLE_CONTROLLED);
1898 ch.Connect();
1899 ch.OnCandidate(CreateCandidate("1.1.1.1", 1, 1));
1900 cricket::Connection* conn1 = WaitForConnectionTo(&ch, "1.1.1.1", 1);
1901 ASSERT_TRUE(conn1 != nullptr);
1902 EXPECT_EQ(conn1, ch.best_connection());
1903
1904 // When a higher priority candidate comes in, the new connection is chosen
1905 // as the best connection.
1906 ch.OnCandidate(CreateCandidate("2.2.2.2", 2, 10));
1907 cricket::Connection* conn2 = WaitForConnectionTo(&ch, "2.2.2.2", 2);
1908 ASSERT_TRUE(conn1 != nullptr);
1909 EXPECT_EQ(conn2, ch.best_connection());
1910
1911 // If a stun request with use-candidate attribute arrives, the receiving
1912 // connection will be set as the best connection, even though
1913 // its priority is lower.
1914 ch.OnCandidate(CreateCandidate("3.3.3.3", 3, 1));
1915 cricket::Connection* conn3 = WaitForConnectionTo(&ch, "3.3.3.3", 3);
1916 ASSERT_TRUE(conn3 != nullptr);
1917 // Because it has a lower priority, the best connection is still conn2.
1918 EXPECT_EQ(conn2, ch.best_connection());
1919 conn3->ReceivedPingResponse(); // Become writable.
1920 // But if it is nominated via use_candidate, it is chosen as the best
1921 // connection.
1922 conn3->set_nominated(true);
1923 conn3->SignalUseCandidate(conn3);
pthatcher1 2015/08/07 22:50:22 Maybe we should just fire SignalNominated within s
honghaiz3 2015/08/10 20:15:43 That's what I did in a previous patch. But Justin
1924 EXPECT_EQ(conn3, ch.best_connection());
1925
1926 // Even if another higher priority candidate arrives,
1927 // it will not be set as the best connection because the best connection
1928 // is nominated by the controlling side.
1929 ch.OnCandidate(CreateCandidate("4.4.4.4", 4, 100));
1930 cricket::Connection* conn4 = WaitForConnectionTo(&ch, "4.4.4.4", 4);
1931 ASSERT_TRUE(conn4 != nullptr);
1932 EXPECT_EQ(conn3, ch.best_connection());
1933 // But if it is nominated via use_candidate and writable, it will be set as
1934 // the best connection.
1935 conn4->set_nominated(true);
1936 conn4->SignalUseCandidate(conn4);
1937 // Not switched yet because conn4 is not writable.
1938 EXPECT_EQ(conn3, ch.best_connection());
1939 // The best connection switches after conn4 becomes writable.
1940 conn4->ReceivedPingResponse();
1941 EXPECT_EQ(conn4, ch.best_connection());
1942 }
1943
1944 // For the controlled side, when a stun request with an unknown address is
1945 // received, it will be selected as the best connection if the best connection
1946 // is not nominated by the controlling side and vice versa. If the received
1947 // stun request with an unknown address contains a use_candidate attribute, it
1948 // will be treated as a nomination from the controlling side.
pthatcher1 2015/08/07 22:50:22 I think you could shorten this to "The controlled
honghaiz3 2015/08/10 20:15:43 Done. Thanks!
1949 TEST_F(P2PTransportChannelPingTest, TestReceivingUnknownAddress) {
pthatcher1 2015/08/07 22:50:22 This is kind of two tests in one: SelectConnectio
honghaiz3 2015/08/10 20:15:43 I think this is more on nominations from Unknown A
1950 cricket::FakePortAllocator pa(rtc::Thread::Current(), nullptr);
1951 cricket::P2PTransportChannel ch("receiving state change", 1, nullptr, &pa);
1952 PrepareChannel(&ch);
1953 ch.SetIceRole(cricket::ICEROLE_CONTROLLED);
1954 ch.Connect();
1955 // A minimal STUN message with prflx priority.
1956 cricket::IceMessage request;
1957 request.SetType(cricket::STUN_BINDING_REQUEST);
1958 request.AddAttribute(new cricket::StunByteStringAttribute(
1959 cricket::STUN_ATTR_USERNAME, kIceUfrag[1]));
1960 uint32 prflx_priority = cricket::ICE_TYPE_PREFERENCE_PRFLX << 24;
1961 request.AddAttribute(new cricket::StunUInt32Attribute(
1962 cricket::STUN_ATTR_PRIORITY, prflx_priority));
1963 cricket::Port* port = GetPort(&ch);
1964 port->SignalUnknownAddress(port, rtc::SocketAddress("1.1.1.1", 1),
1965 cricket::PROTO_UDP, &request, kIceUfrag[1], false);
1966 cricket::Connection* conn1 = WaitForConnectionTo(&ch, "1.1.1.1", 1);
1967 ASSERT_TRUE(conn1 != nullptr);
1968 EXPECT_EQ(conn1, ch.best_connection());
1969 conn1->ReceivedPingResponse();
1970 EXPECT_EQ(conn1, ch.best_connection());
1971
1972 // Another connection is nominated via use_candidate.
1973 ch.OnCandidate(CreateCandidate("2.2.2.2", 2, 1));
1974 cricket::Connection* conn2 = WaitForConnectionTo(&ch, "2.2.2.2", 2);
1975 ASSERT_TRUE(conn2 != nullptr);
1976 // Because it has a lower priority, the best connection is still conn1.
1977 EXPECT_EQ(conn1, ch.best_connection());
1978 // When it is nominated via use_candidate and writable, it is chosen as the
1979 // best connection.
1980 conn2->ReceivedPingResponse(); // Become writable.
1981 conn2->set_nominated(true);
1982 conn2->SignalUseCandidate(conn2);
1983 EXPECT_EQ(conn2, ch.best_connection());
1984
1985 // Another request with unknown address, it will not be set as the best
1986 // connection because the best connection was nominated by the controlling
1987 // side.
1988 port->SignalUnknownAddress(port, rtc::SocketAddress("3.3.3.3", 3),
1989 cricket::PROTO_UDP, &request, kIceUfrag[1], false);
1990 cricket::Connection* conn3 = WaitForConnectionTo(&ch, "3.3.3.3", 3);
1991 ASSERT_TRUE(conn3 != nullptr);
1992 conn3->ReceivedPingResponse(); // Become writable.
1993 EXPECT_EQ(conn2, ch.best_connection());
1994
1995 // However if the request contains use_candidate attribute, it will be
1996 // selected as the best connection.
1997 request.AddAttribute(
1998 new cricket::StunByteStringAttribute(cricket::STUN_ATTR_USE_CANDIDATE));
1999 port->SignalUnknownAddress(port, rtc::SocketAddress("4.4.4.4", 4),
2000 cricket::PROTO_UDP, &request, kIceUfrag[1], false);
2001 cricket::Connection* conn4 = WaitForConnectionTo(&ch, "4.4.4.4", 4);
2002 ASSERT_TRUE(conn4 != nullptr);
2003 // conn4 is not the best connection yet because it is not writable.
2004 EXPECT_EQ(conn2, ch.best_connection());
2005 conn4->ReceivedPingResponse(); // Become writable.
2006 EXPECT_EQ(conn4, ch.best_connection());
2007 }
2008
2009 // For the controlled side, if a data packet is received on a connection,
2010 // the sending path will mirror the receiving path if it is writable and
2011 // the current best connection is not nominated by the controlling side.
2012 // If the current best connection is already nominated by the controlling side,
2013 // it will not switch the best connection (the sending path).
pthatcher1 2015/08/07 22:50:22 This could be shortened to 'The controlled side wi
honghaiz3 2015/08/10 20:15:43 Done.
2014 TEST_F(P2PTransportChannelPingTest, TestSendingPathMirrorReceivingPath) {
pthatcher1 2015/08/07 22:50:22 This might be called SelectConnectionBeforeNominat
honghaiz3 2015/08/10 20:15:43 Shortened a little bit. Since the comments have de
2015 cricket::FakePortAllocator pa(rtc::Thread::Current(), nullptr);
2016 cricket::P2PTransportChannel ch("receiving state change", 1, nullptr, &pa);
2017 PrepareChannel(&ch);
2018 ch.SetIceRole(cricket::ICEROLE_CONTROLLED);
2019 ch.Connect();
2020 ch.OnCandidate(CreateCandidate("1.1.1.1", 1, 10));
2021 cricket::Connection* conn1 = WaitForConnectionTo(&ch, "1.1.1.1", 1);
2022 ASSERT_TRUE(conn1 != nullptr);
2023 EXPECT_EQ(conn1, ch.best_connection());
2024
2025 // If a data packet is received on conn2, the best connection should
2026 // switch to conn2 because the controlled side must mirror the media path
2027 // chosen by the controlling side.
2028 ch.OnCandidate(CreateCandidate("2.2.2.2", 2, 1));
2029 cricket::Connection* conn2 = WaitForConnectionTo(&ch, "2.2.2.2", 2);
2030 ASSERT_TRUE(conn2 != nullptr);
2031 conn2->ReceivedPing(); // Become readable.
2032 // Do not switch because it is not writable.
2033 conn2->OnReadPacket("ABC", 3, rtc::CreatePacketTime(0));
2034 EXPECT_EQ(conn1, ch.best_connection());
2035
2036 conn2->ReceivedPingResponse(); // Become writable.
2037 // Switch because it is writable.
2038 conn2->OnReadPacket("DEF", 3, rtc::CreatePacketTime(0));
2039 EXPECT_EQ(conn2, ch.best_connection());
2040
2041 // Now another STUN message with an unknown address and use_candidate will
2042 // nominate the best connection.
2043 cricket::IceMessage request;
2044 request.SetType(cricket::STUN_BINDING_REQUEST);
2045 request.AddAttribute(new cricket::StunByteStringAttribute(
2046 cricket::STUN_ATTR_USERNAME, kIceUfrag[1]));
2047 uint32 prflx_priority = cricket::ICE_TYPE_PREFERENCE_PRFLX << 24;
2048 request.AddAttribute(new cricket::StunUInt32Attribute(
2049 cricket::STUN_ATTR_PRIORITY, prflx_priority));
2050 request.AddAttribute(
2051 new cricket::StunByteStringAttribute(cricket::STUN_ATTR_USE_CANDIDATE));
2052 cricket::Port* port = GetPort(&ch);
2053 port->SignalUnknownAddress(port, rtc::SocketAddress("3.3.3.3", 3),
2054 cricket::PROTO_UDP, &request, kIceUfrag[1], false);
2055 cricket::Connection* conn3 = WaitForConnectionTo(&ch, "3.3.3.3", 3);
2056 ASSERT_TRUE(conn3 != nullptr);
2057 EXPECT_EQ(conn2, ch.best_connection()); // Not writable yet.
2058 conn3->ReceivedPingResponse(); // Become writable.
2059 EXPECT_EQ(conn3, ch.best_connection());
2060
2061 // Now another data packet will not switch the best connection because the
2062 // best connection was nominated by the controlling side.
2063 conn2->ReceivedPing();
2064 conn2->ReceivedPingResponse();
2065 conn2->OnReadPacket("XYZ", 3, rtc::CreatePacketTime(0));
2066 EXPECT_EQ(conn3, ch.best_connection());
2067 }
OLDNEW

Powered by Google App Engine