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

Unified Diff: webrtc/p2p/base/p2ptransportchannel_unittest.cc

Issue 1577233006: Implement Turn/Turn first logic for connection selection. (Closed) Base URL: https://chromium.googlesource.com/external/webrtc@master
Patch Set: Fix test issues Created 4 years, 11 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 side-by-side diff with in-line comments
Download patch
Index: webrtc/p2p/base/p2ptransportchannel_unittest.cc
diff --git a/webrtc/p2p/base/p2ptransportchannel_unittest.cc b/webrtc/p2p/base/p2ptransportchannel_unittest.cc
index 90ddd43714daa8c55bdaa45139caf5f2b7812dbf..9810a6d45c0b45401c7897465ad172814dca0d62 100644
--- a/webrtc/p2p/base/p2ptransportchannel_unittest.cc
+++ b/webrtc/p2p/base/p2ptransportchannel_unittest.cc
@@ -81,6 +81,8 @@ static const SocketAddress kRelaySslTcpExtAddr("99.99.99.3", 5005);
// The addresses for the public turn server.
static const SocketAddress kTurnUdpIntAddr("99.99.99.4",
cricket::STUN_SERVER_PORT);
+static const SocketAddress kTurnTcpIntAddr("99.99.99.4",
+ cricket::STUN_SERVER_PORT + 1);
static const SocketAddress kTurnUdpExtAddr("99.99.99.5", 0);
static const cricket::RelayCredentials kRelayCredentials("test", "test");
@@ -1765,16 +1767,17 @@ class P2PTransportChannelPingTest : public testing::Test,
ch->SetRemoteIceCredentials(kIceUfrag[1], kIcePwd[1]);
}
- cricket::Candidate CreateCandidate(const std::string& ip,
- int port,
- int priority,
- const std::string& ufrag = "") {
+ cricket::Candidate CreateLocalCandidate(const std::string& ip,
pthatcher1 2016/01/27 19:59:59 We ought to call this CreateHostCandidate. LOCAL_
guoweis_webrtc 2016/02/29 18:03:01 Done.
+ int port,
+ int priority,
+ const std::string& ufrag = "") {
cricket::Candidate c;
c.set_address(rtc::SocketAddress(ip, port));
c.set_component(1);
c.set_protocol(cricket::UDP_PROTOCOL_NAME);
c.set_priority(priority);
c.set_username(ufrag);
+ c.set_type(cricket::LOCAL_PORT_TYPE);
return c;
}
@@ -1814,8 +1817,8 @@ TEST_F(P2PTransportChannelPingTest, TestTriggeredChecks) {
PrepareChannel(&ch);
ch.Connect();
ch.MaybeStartGathering();
- ch.AddRemoteCandidate(CreateCandidate("1.1.1.1", 1, 1));
- ch.AddRemoteCandidate(CreateCandidate("2.2.2.2", 2, 2));
+ ch.AddRemoteCandidate(CreateLocalCandidate("1.1.1.1", 1, 1));
+ ch.AddRemoteCandidate(CreateLocalCandidate("2.2.2.2", 2, 2));
cricket::Connection* conn1 = WaitForConnectionTo(&ch, "1.1.1.1", 1);
cricket::Connection* conn2 = WaitForConnectionTo(&ch, "2.2.2.2", 2);
@@ -1839,8 +1842,8 @@ TEST_F(P2PTransportChannelPingTest, TestNoTriggeredChecksWhenWritable) {
PrepareChannel(&ch);
ch.Connect();
ch.MaybeStartGathering();
- ch.AddRemoteCandidate(CreateCandidate("1.1.1.1", 1, 1));
- ch.AddRemoteCandidate(CreateCandidate("2.2.2.2", 2, 2));
+ ch.AddRemoteCandidate(CreateLocalCandidate("1.1.1.1", 1, 1));
+ ch.AddRemoteCandidate(CreateLocalCandidate("2.2.2.2", 2, 2));
cricket::Connection* conn1 = WaitForConnectionTo(&ch, "1.1.1.1", 1);
cricket::Connection* conn2 = WaitForConnectionTo(&ch, "2.2.2.2", 2);
@@ -1848,6 +1851,7 @@ TEST_F(P2PTransportChannelPingTest, TestNoTriggeredChecksWhenWritable) {
ASSERT_TRUE(conn2 != nullptr);
EXPECT_EQ(conn2, ch.FindNextPingableConnection());
+ EXPECT_EQ(conn1, ch.FindNextPingableConnection());
conn1->ReceivedPingResponse();
ASSERT_TRUE(conn1->writable());
conn1->ReceivedPing();
@@ -1871,7 +1875,7 @@ TEST_F(P2PTransportChannelPingTest, TestAddRemoteCandidateWithVariousUfrags) {
ch.Connect();
ch.MaybeStartGathering();
// Add a candidate with a future ufrag.
- ch.AddRemoteCandidate(CreateCandidate("1.1.1.1", 1, 1, kIceUfrag[2]));
+ ch.AddRemoteCandidate(CreateLocalCandidate("1.1.1.1", 1, 1, kIceUfrag[2]));
cricket::Connection* conn1 = WaitForConnectionTo(&ch, "1.1.1.1", 1);
ASSERT_TRUE(conn1 != nullptr);
const cricket::Candidate& candidate = conn1->remote_candidate();
@@ -1888,13 +1892,13 @@ TEST_F(P2PTransportChannelPingTest, TestAddRemoteCandidateWithVariousUfrags) {
EXPECT_EQ(conn1, ch.FindNextPingableConnection());
// Add a candidate with an old ufrag. No connection will be created.
- ch.AddRemoteCandidate(CreateCandidate("2.2.2.2", 2, 2, kIceUfrag[1]));
+ ch.AddRemoteCandidate(CreateLocalCandidate("2.2.2.2", 2, 2, kIceUfrag[1]));
rtc::Thread::Current()->ProcessMessages(500);
EXPECT_TRUE(GetConnectionTo(&ch, "2.2.2.2", 2) == nullptr);
// Add a candidate with the current ufrag, its pwd and generation will be
// assigned, even if the generation is not set.
- ch.AddRemoteCandidate(CreateCandidate("3.3.3.3", 3, 0, kIceUfrag[2]));
+ ch.AddRemoteCandidate(CreateLocalCandidate("3.3.3.3", 3, 0, kIceUfrag[2]));
cricket::Connection* conn3 = nullptr;
ASSERT_TRUE_WAIT((conn3 = GetConnectionTo(&ch, "3.3.3.3", 3)) != nullptr,
3000);
@@ -1922,14 +1926,14 @@ TEST_F(P2PTransportChannelPingTest, ConnectionResurrection) {
ch.MaybeStartGathering();
// Create conn1 and keep track of original candidate priority.
- ch.AddRemoteCandidate(CreateCandidate("1.1.1.1", 1, 1));
+ ch.AddRemoteCandidate(CreateLocalCandidate("1.1.1.1", 1, 1));
cricket::Connection* conn1 = WaitForConnectionTo(&ch, "1.1.1.1", 1);
ASSERT_TRUE(conn1 != nullptr);
uint32_t remote_priority = conn1->remote_candidate().priority();
// Create a higher priority candidate and make the connection
// receiving/writable. This will prune conn1.
- ch.AddRemoteCandidate(CreateCandidate("2.2.2.2", 2, 2));
+ ch.AddRemoteCandidate(CreateLocalCandidate("2.2.2.2", 2, 2));
cricket::Connection* conn2 = WaitForConnectionTo(&ch, "2.2.2.2", 2);
ASSERT_TRUE(conn2 != nullptr);
conn2->ReceivedPing();
@@ -1980,7 +1984,7 @@ TEST_F(P2PTransportChannelPingTest, TestReceivingStateChange) {
EXPECT_EQ(50, ch.check_receiving_delay());
ch.Connect();
ch.MaybeStartGathering();
- ch.AddRemoteCandidate(CreateCandidate("1.1.1.1", 1, 1));
+ ch.AddRemoteCandidate(CreateLocalCandidate("1.1.1.1", 1, 1));
cricket::Connection* conn1 = WaitForConnectionTo(&ch, "1.1.1.1", 1);
ASSERT_TRUE(conn1 != nullptr);
@@ -2002,14 +2006,14 @@ TEST_F(P2PTransportChannelPingTest, TestSelectConnectionBeforeNomination) {
ch.SetIceRole(cricket::ICEROLE_CONTROLLED);
ch.Connect();
ch.MaybeStartGathering();
- ch.AddRemoteCandidate(CreateCandidate("1.1.1.1", 1, 1));
+ ch.AddRemoteCandidate(CreateLocalCandidate("1.1.1.1", 1, 1));
cricket::Connection* conn1 = WaitForConnectionTo(&ch, "1.1.1.1", 1);
ASSERT_TRUE(conn1 != nullptr);
EXPECT_EQ(conn1, ch.best_connection());
// When a higher priority candidate comes in, the new connection is chosen
// as the best connection.
- ch.AddRemoteCandidate(CreateCandidate("2.2.2.2", 2, 10));
+ ch.AddRemoteCandidate(CreateLocalCandidate("2.2.2.2", 2, 10));
cricket::Connection* conn2 = WaitForConnectionTo(&ch, "2.2.2.2", 2);
ASSERT_TRUE(conn2 != nullptr);
EXPECT_EQ(conn2, ch.best_connection());
@@ -2017,7 +2021,7 @@ TEST_F(P2PTransportChannelPingTest, TestSelectConnectionBeforeNomination) {
// If a stun request with use-candidate attribute arrives, the receiving
// connection will be set as the best connection, even though
// its priority is lower.
- ch.AddRemoteCandidate(CreateCandidate("3.3.3.3", 3, 1));
+ ch.AddRemoteCandidate(CreateLocalCandidate("3.3.3.3", 3, 1));
cricket::Connection* conn3 = WaitForConnectionTo(&ch, "3.3.3.3", 3);
ASSERT_TRUE(conn3 != nullptr);
// Because it has a lower priority, the best connection is still conn2.
@@ -2032,7 +2036,7 @@ TEST_F(P2PTransportChannelPingTest, TestSelectConnectionBeforeNomination) {
// Even if another higher priority candidate arrives,
// it will not be set as the best connection because the best connection
// is nominated by the controlling side.
- ch.AddRemoteCandidate(CreateCandidate("4.4.4.4", 4, 100));
+ ch.AddRemoteCandidate(CreateLocalCandidate("4.4.4.4", 4, 100));
cricket::Connection* conn4 = WaitForConnectionTo(&ch, "4.4.4.4", 4);
ASSERT_TRUE(conn4 != nullptr);
EXPECT_EQ(conn3, ch.best_connection());
@@ -2079,7 +2083,7 @@ TEST_F(P2PTransportChannelPingTest, TestSelectConnectionFromUnknownAddress) {
port->set_sent_binding_response(false);
// Another connection is nominated via use_candidate.
- ch.AddRemoteCandidate(CreateCandidate("2.2.2.2", 2, 1));
+ ch.AddRemoteCandidate(CreateLocalCandidate("2.2.2.2", 2, 1));
cricket::Connection* conn2 = WaitForConnectionTo(&ch, "2.2.2.2", 2);
ASSERT_TRUE(conn2 != nullptr);
// Because it has a lower priority, the best connection is still conn1.
@@ -2141,7 +2145,7 @@ TEST_F(P2PTransportChannelPingTest, TestSelectConnectionBasedOnMediaReceived) {
ch.SetIceRole(cricket::ICEROLE_CONTROLLED);
ch.Connect();
ch.MaybeStartGathering();
- ch.AddRemoteCandidate(CreateCandidate("1.1.1.1", 1, 10));
+ ch.AddRemoteCandidate(CreateLocalCandidate("1.1.1.1", 1, 10));
cricket::Connection* conn1 = WaitForConnectionTo(&ch, "1.1.1.1", 1);
ASSERT_TRUE(conn1 != nullptr);
EXPECT_EQ(conn1, ch.best_connection());
@@ -2149,7 +2153,7 @@ TEST_F(P2PTransportChannelPingTest, TestSelectConnectionBasedOnMediaReceived) {
// If a data packet is received on conn2, the best connection should
// switch to conn2 because the controlled side must mirror the media path
// chosen by the controlling side.
- ch.AddRemoteCandidate(CreateCandidate("2.2.2.2", 2, 1));
+ ch.AddRemoteCandidate(CreateLocalCandidate("2.2.2.2", 2, 1));
cricket::Connection* conn2 = WaitForConnectionTo(&ch, "2.2.2.2", 2);
ASSERT_TRUE(conn2 != nullptr);
conn2->ReceivedPing(); // Start receiving.
@@ -2199,7 +2203,7 @@ TEST_F(P2PTransportChannelPingTest, TestDontPruneWhenWeak) {
ch.SetIceRole(cricket::ICEROLE_CONTROLLED);
ch.Connect();
ch.MaybeStartGathering();
- ch.AddRemoteCandidate(CreateCandidate("1.1.1.1", 1, 1));
+ ch.AddRemoteCandidate(CreateLocalCandidate("1.1.1.1", 1, 1));
cricket::Connection* conn1 = WaitForConnectionTo(&ch, "1.1.1.1", 1);
ASSERT_TRUE(conn1 != nullptr);
EXPECT_EQ(conn1, ch.best_connection());
@@ -2207,7 +2211,7 @@ TEST_F(P2PTransportChannelPingTest, TestDontPruneWhenWeak) {
// When a higher-priority, nominated candidate comes in, the connections with
// lower-priority are pruned.
- ch.AddRemoteCandidate(CreateCandidate("2.2.2.2", 2, 10));
+ ch.AddRemoteCandidate(CreateLocalCandidate("2.2.2.2", 2, 10));
cricket::Connection* conn2 = WaitForConnectionTo(&ch, "2.2.2.2", 2);
ASSERT_TRUE(conn2 != nullptr);
conn2->ReceivedPingResponse(); // Becomes writable and receiving
@@ -2219,7 +2223,7 @@ TEST_F(P2PTransportChannelPingTest, TestDontPruneWhenWeak) {
// Wait until conn2 becomes not receiving.
EXPECT_TRUE_WAIT(!conn2->receiving(), 3000);
- ch.AddRemoteCandidate(CreateCandidate("3.3.3.3", 3, 1));
+ ch.AddRemoteCandidate(CreateLocalCandidate("3.3.3.3", 3, 1));
cricket::Connection* conn3 = WaitForConnectionTo(&ch, "3.3.3.3", 3);
ASSERT_TRUE(conn3 != nullptr);
// The best connection should still be conn2. Even through conn3 has lower
@@ -2237,8 +2241,8 @@ TEST_F(P2PTransportChannelPingTest, TestGetState) {
ch.Connect();
ch.MaybeStartGathering();
EXPECT_EQ(cricket::TransportChannelState::STATE_INIT, ch.GetState());
- ch.AddRemoteCandidate(CreateCandidate("1.1.1.1", 1, 100));
- ch.AddRemoteCandidate(CreateCandidate("2.2.2.2", 2, 1));
+ ch.AddRemoteCandidate(CreateLocalCandidate("1.1.1.1", 1, 100));
+ ch.AddRemoteCandidate(CreateLocalCandidate("2.2.2.2", 2, 1));
cricket::Connection* conn1 = WaitForConnectionTo(&ch, "1.1.1.1", 1);
cricket::Connection* conn2 = WaitForConnectionTo(&ch, "2.2.2.2", 2);
ASSERT_TRUE(conn1 != nullptr);
@@ -2264,7 +2268,7 @@ TEST_F(P2PTransportChannelPingTest, TestConnectionPrunedAgain) {
ch.SetIceConfig(CreateIceConfig(1000, false));
ch.Connect();
ch.MaybeStartGathering();
- ch.AddRemoteCandidate(CreateCandidate("1.1.1.1", 1, 100));
+ ch.AddRemoteCandidate(CreateLocalCandidate("1.1.1.1", 1, 100));
cricket::Connection* conn1 = WaitForConnectionTo(&ch, "1.1.1.1", 1);
ASSERT_TRUE(conn1 != nullptr);
EXPECT_EQ(conn1, ch.best_connection());
@@ -2274,7 +2278,7 @@ TEST_F(P2PTransportChannelPingTest, TestConnectionPrunedAgain) {
// not be deleted right away. Once the current best connection becomes not
// receiving, |conn2| will start to ping and upon receiving the ping response,
// it will become the best connection.
- ch.AddRemoteCandidate(CreateCandidate("2.2.2.2", 2, 1));
+ ch.AddRemoteCandidate(CreateLocalCandidate("2.2.2.2", 2, 1));
cricket::Connection* conn2 = WaitForConnectionTo(&ch, "2.2.2.2", 2);
ASSERT_TRUE(conn2 != nullptr);
EXPECT_TRUE_WAIT(!conn2->active(), 1000);
@@ -2307,7 +2311,7 @@ TEST_F(P2PTransportChannelPingTest, TestDeleteConnectionsIfAllWriteTimedout) {
ch.Connect();
ch.MaybeStartGathering();
// Have one connection only but later becomes write-time-out.
- ch.AddRemoteCandidate(CreateCandidate("1.1.1.1", 1, 100));
+ ch.AddRemoteCandidate(CreateLocalCandidate("1.1.1.1", 1, 100));
cricket::Connection* conn1 = WaitForConnectionTo(&ch, "1.1.1.1", 1);
ASSERT_TRUE(conn1 != nullptr);
conn1->ReceivedPing(); // Becomes receiving
@@ -2315,11 +2319,11 @@ TEST_F(P2PTransportChannelPingTest, TestDeleteConnectionsIfAllWriteTimedout) {
EXPECT_TRUE_WAIT(ch.connections().empty(), 1000);
// Have two connections but both become write-time-out later.
- ch.AddRemoteCandidate(CreateCandidate("2.2.2.2", 2, 1));
+ ch.AddRemoteCandidate(CreateLocalCandidate("2.2.2.2", 2, 1));
cricket::Connection* conn2 = WaitForConnectionTo(&ch, "2.2.2.2", 2);
ASSERT_TRUE(conn2 != nullptr);
conn2->ReceivedPing(); // Becomes receiving
- ch.AddRemoteCandidate(CreateCandidate("3.3.3.3", 3, 2));
+ ch.AddRemoteCandidate(CreateLocalCandidate("3.3.3.3", 3, 2));
cricket::Connection* conn3 = WaitForConnectionTo(&ch, "3.3.3.3", 3);
ASSERT_TRUE(conn3 != nullptr);
conn3->ReceivedPing(); // Becomes receiving
@@ -2339,7 +2343,7 @@ TEST_F(P2PTransportChannelPingTest, TestStopPortAllocatorSessions) {
ch.SetIceConfig(CreateIceConfig(2000, false));
ch.Connect();
ch.MaybeStartGathering();
- ch.AddRemoteCandidate(CreateCandidate("1.1.1.1", 1, 100));
+ ch.AddRemoteCandidate(CreateLocalCandidate("1.1.1.1", 1, 100));
cricket::Connection* conn1 = WaitForConnectionTo(&ch, "1.1.1.1", 1);
ASSERT_TRUE(conn1 != nullptr);
conn1->ReceivedPingResponse(); // Becomes writable and receiving
@@ -2350,9 +2354,230 @@ TEST_F(P2PTransportChannelPingTest, TestStopPortAllocatorSessions) {
// connected.
ch.SetIceCredentials(kIceUfrag[1], kIcePwd[1]);
ch.MaybeStartGathering();
- ch.AddRemoteCandidate(CreateCandidate("2.2.2.2", 2, 100));
+ ch.AddRemoteCandidate(CreateLocalCandidate("2.2.2.2", 2, 100));
cricket::Connection* conn2 = WaitForConnectionTo(&ch, "2.2.2.2", 2);
ASSERT_TRUE(conn2 != nullptr);
conn2->ReceivedPingResponse(); // Becomes writable and receiving
EXPECT_TRUE(!ch.allocator_session()->IsGettingPorts());
}
+
+class P2PTransportChannelTurnTurnFirstTest
pthatcher1 2016/01/27 19:59:59 Can you call this P2PTransportChannelMostLikelyToW
guoweis_webrtc 2016/02/29 18:03:00 Done.
+ : public P2PTransportChannelPingTest {
+ public:
+ P2PTransportChannelTurnTurnFirstTest()
+ : turn_server_(rtc::Thread::Current(), kTurnUdpIntAddr, kTurnUdpExtAddr) {
+ network_manager_.AddInterface(kPublicAddrs[0]);
+ allocator_.reset(new cricket::BasicPortAllocator(
+ &network_manager_, ServerAddresses(), rtc::SocketAddress(),
+ rtc::SocketAddress(), rtc::SocketAddress()));
+ allocator_->set_flags(allocator_->flags() |
+ cricket::PORTALLOCATOR_DISABLE_STUN |
+ cricket::PORTALLOCATOR_DISABLE_TCP);
+ cricket::RelayServerConfig config(cricket::RELAY_TURN);
+ config.credentials = kRelayCredentials;
+ config.ports.push_back(
+ cricket::ProtocolAddress(kTurnUdpIntAddr, cricket::PROTO_UDP, false));
+ allocator_->AddTurnServer(config);
+ allocator_->set_step_delay(kMinimumStepDelay);
+ }
+
+ cricket::P2PTransportChannel& StartChannel() {
pthatcher1 2016/01/27 19:59:59 Can we call this StartTransportChannel()? And it'
guoweis_webrtc 2016/02/29 18:03:01 Done.
+ channel_.reset(
+ new cricket::P2PTransportChannel("checks", 1, nullptr, allocator()));
+ cricket::IceConfig config = channel_->GetIceConfig();
+ config.ping_most_likely_candidate_pair_first = true;
+ channel_->SetIceConfig(config);
+ PrepareChannel(channel_.get());
+ channel_->Connect();
+ channel_->MaybeStartGathering();
+ return *channel_.get();
+ }
+
+ cricket::BasicPortAllocator* allocator() { return allocator_.get(); }
+ cricket::TestTurnServer* turn_server() { return &turn_server_; }
+
+ // This verifies the next pingable connection has the expected candidates'
+ // types and, for relay local candidate, the expected relay protocol and ping
+ // it.
+ void VerifyNextPingableConnection(
+ const std::string& local_candidate_type,
+ const std::string& remote_candidate_type,
+ const std::string& relay_protocol_type = cricket::UDP_PROTOCOL_NAME) {
+ cricket::Connection* conn = channel_->FindNextPingableConnection();
+ EXPECT_EQ(conn->local_candidate().type(), local_candidate_type);
+ if (conn->local_candidate().type() == cricket::RELAY_PORT_TYPE) {
+ EXPECT_EQ(conn->local_candidate().relay_protocol(), relay_protocol_type);
+ }
+ EXPECT_EQ(conn->remote_candidate().type(), remote_candidate_type);
+ }
+
+ cricket::Candidate CreateRelayCandidate(const std::string& ip,
+ int port,
+ int priority,
+ const std::string& ufrag = "") {
+ cricket::Candidate c = CreateLocalCandidate(ip, port, priority, ufrag);
+ c.set_type(cricket::RELAY_PORT_TYPE);
+ return c;
+ }
+
+ private:
+ rtc::scoped_ptr<cricket::BasicPortAllocator> allocator_;
+ rtc::FakeNetworkManager network_manager_;
+ cricket::TestTurnServer turn_server_;
+ rtc::scoped_ptr<cricket::P2PTransportChannel> channel_;
+};
+
+// Test that Relay/Relay connection will be pinged when no other connections
pthatcher1 2016/01/27 19:59:59 Relay/Relay connection => Relay/Relay connections
pthatcher1 2016/01/27 19:59:59 Can you say "pinged first" instead of just "pinged
guoweis_webrtc 2016/02/29 18:03:01 Done.
guoweis_webrtc 2016/02/29 18:03:01 Done.
+// have been pinged yet, unless we need to ping a trigger check or we have a
+// best connection.
+TEST_F(P2PTransportChannelTurnTurnFirstTest,
+ TestTurnTurnFirstWhenNothingPingedYet) {
pthatcher1 2016/01/27 19:59:59 The comment says Relay/Relay, but the variable nam
guoweis_webrtc 2016/02/29 18:03:01 Done.
+ cricket::P2PTransportChannel& ch = StartChannel();
+ EXPECT_TRUE_WAIT(ch.ports().size() == 2, 5000);
+ EXPECT_EQ(ch.ports()[0]->Type(), cricket::LOCAL_PORT_TYPE);
+ EXPECT_EQ(ch.ports()[1]->Type(), cricket::RELAY_PORT_TYPE);
+
+ ch.AddRemoteCandidate(CreateRelayCandidate("1.1.1.1", 1, 1));
+ ch.AddRemoteCandidate(CreateLocalCandidate("2.2.2.2", 2, 2));
+
+ EXPECT_TRUE_WAIT(ch.connections().size() == 4, 5000);
+
+ // Relay/Relay should be the first pingable connection.
+ cricket::Connection* conn = ch.FindNextPingableConnection();
+ EXPECT_EQ(conn->local_candidate().type(), cricket::RELAY_PORT_TYPE);
+ EXPECT_EQ(conn->remote_candidate().type(), cricket::RELAY_PORT_TYPE);
+
+ // Unless that we have a trigger check waiting to be pinged.
+ cricket::Connection* conn2 = WaitForConnectionTo(&ch, "2.2.2.2", 2);
+ EXPECT_EQ(conn2->local_candidate().type(), cricket::LOCAL_PORT_TYPE);
+ EXPECT_EQ(conn2->remote_candidate().type(), cricket::LOCAL_PORT_TYPE);
+ conn2->ReceivedPing();
+ EXPECT_EQ(conn2, ch.FindNextPingableConnection());
+
+ // Make conn3 the best connection.
+ cricket::Connection* conn3 = WaitForConnectionTo(&ch, "1.1.1.1", 1);
+ EXPECT_EQ(conn3->local_candidate().type(), cricket::LOCAL_PORT_TYPE);
+ EXPECT_EQ(conn3->remote_candidate().type(), cricket::RELAY_PORT_TYPE);
+ conn3->ReceivedPingResponse();
+ ASSERT_TRUE(conn3->writable());
+ conn3->ReceivedPing();
+
+ // Verify that conn3 will be the "best connection" since it is readable and
+ // writable. After |MAX_CURRENT_STRONG_DELAY|, it should be the next pingable
+ // connection.
+ EXPECT_TRUE_WAIT(conn3 == ch.best_connection(), 5000);
+ WAIT(false, cricket::MAX_CURRENT_STRONG_DELAY + 100);
pthatcher1 2016/01/27 19:59:59 We have to wait 1 second for each of these tests?
guoweis_webrtc 2016/02/29 18:03:01 Done.
+ conn3->ReceivedPingResponse();
+ ASSERT_TRUE(conn3->writable());
+ EXPECT_EQ(conn3, ch.FindNextPingableConnection());
+}
+
+// Test that Relay/Relay connection will be pinged first when everything has
+// been pinged even if the Relay/Relay connection wasn't the first to be pinged
+// in the first round.
+TEST_F(P2PTransportChannelTurnTurnFirstTest,
+ TestTurnTurnFirstWhenEverythingPinged) {
+ cricket::P2PTransportChannel& ch = StartChannel();
+ EXPECT_TRUE_WAIT(ch.ports().size() == 2, 5000);
+ EXPECT_EQ(ch.ports()[0]->Type(), cricket::LOCAL_PORT_TYPE);
+ EXPECT_EQ(ch.ports()[1]->Type(), cricket::RELAY_PORT_TYPE);
+
+ ch.AddRemoteCandidate(CreateLocalCandidate("1.1.1.1", 1, 1));
+ EXPECT_TRUE_WAIT(ch.connections().size() == 2, 5000);
+
+ // Initially, only have Local/Local and Local/Relay.
+ VerifyNextPingableConnection(cricket::LOCAL_PORT_TYPE,
+ cricket::LOCAL_PORT_TYPE);
+ VerifyNextPingableConnection(cricket::RELAY_PORT_TYPE,
+ cricket::LOCAL_PORT_TYPE);
+
+ // Remote Relay candidate arrives.
+ ch.AddRemoteCandidate(CreateRelayCandidate("2.2.2.2", 2, 2));
+ EXPECT_TRUE_WAIT(ch.connections().size() == 4, 5000);
+
+ // Relay/Relay should be the first since it hasn't been pinged before.
+ VerifyNextPingableConnection(cricket::RELAY_PORT_TYPE,
+ cricket::RELAY_PORT_TYPE);
+
+ // Local/Relay is the final one.
+ VerifyNextPingableConnection(cricket::LOCAL_PORT_TYPE,
+ cricket::RELAY_PORT_TYPE);
+
+ // Now, every connection has been pinged once. The next one should be
+ // Relay/Relay.
+ VerifyNextPingableConnection(cricket::RELAY_PORT_TYPE,
+ cricket::RELAY_PORT_TYPE);
+}
+
+// Test that when we receive a new remote candidate, they will be tried first
+// before we re-ping Relay/Relay connection.
pthatcher1 2016/01/27 19:59:59 connection => connections again
guoweis_webrtc 2016/02/29 18:03:01 Done.
+TEST_F(P2PTransportChannelTurnTurnFirstTest,
+ TestNoStarvationOnNonRelayConnection) {
+ cricket::P2PTransportChannel& ch = StartChannel();
+ EXPECT_TRUE_WAIT(ch.ports().size() == 2, 5000);
+ EXPECT_EQ(ch.ports()[0]->Type(), cricket::LOCAL_PORT_TYPE);
+ EXPECT_EQ(ch.ports()[1]->Type(), cricket::RELAY_PORT_TYPE);
+
+ ch.AddRemoteCandidate(CreateRelayCandidate("1.1.1.1", 1, 1));
+ EXPECT_TRUE_WAIT(ch.connections().size() == 2, 5000);
+
+ // Initially, only have Relay/Relay and Local/Relay. Ping Relay/Relay first.
+ VerifyNextPingableConnection(cricket::RELAY_PORT_TYPE,
+ cricket::RELAY_PORT_TYPE);
+
+ // Next, ping Local/Relay.
+ VerifyNextPingableConnection(cricket::LOCAL_PORT_TYPE,
+ cricket::RELAY_PORT_TYPE);
+
+ // Remote Local candidate arrives.
+ ch.AddRemoteCandidate(CreateLocalCandidate("2.2.2.2", 2, 2));
+ EXPECT_TRUE_WAIT(ch.connections().size() == 4, 5000);
+
+ // Local/Local should be the first since it hasn't been pinged before.
+ VerifyNextPingableConnection(cricket::LOCAL_PORT_TYPE,
+ cricket::LOCAL_PORT_TYPE);
+
+ // Relay/Local is the final one.
+ VerifyNextPingableConnection(cricket::RELAY_PORT_TYPE,
+ cricket::LOCAL_PORT_TYPE);
+
+ // Now, every connection has been pinged once. The next one should be
+ // Relay/Relay.
+ VerifyNextPingableConnection(cricket::RELAY_PORT_TYPE,
+ cricket::RELAY_PORT_TYPE);
+}
+
+// Test the ping sequence is UDP Relay/Relay followed by TCP Relay/Relay,
+// followed by the rest.
+TEST_F(P2PTransportChannelTurnTurnFirstTest, TestTcpTurn) {
+ // Add a Tcp Turn server.
+ turn_server()->AddInternalSocket(kTurnTcpIntAddr, cricket::PROTO_TCP);
+ cricket::RelayServerConfig config(cricket::RELAY_TURN);
+ config.credentials = kRelayCredentials;
+ config.ports.push_back(
+ cricket::ProtocolAddress(kTurnTcpIntAddr, cricket::PROTO_TCP, false));
+ allocator()->AddTurnServer(config);
+
+ cricket::P2PTransportChannel& ch = StartChannel();
+ EXPECT_TRUE_WAIT(ch.ports().size() == 3, 5000);
+ EXPECT_EQ(ch.ports()[0]->Type(), cricket::LOCAL_PORT_TYPE);
+ EXPECT_EQ(ch.ports()[1]->Type(), cricket::RELAY_PORT_TYPE);
+ EXPECT_EQ(ch.ports()[2]->Type(), cricket::RELAY_PORT_TYPE);
+
+ // Remote Relay candidate arrives.
+ ch.AddRemoteCandidate(CreateRelayCandidate("1.1.1.1", 1, 1));
+ EXPECT_TRUE_WAIT(ch.connections().size() == 3, 5000);
+
+ // UDP Relay/Relay should be pinged first.
+ VerifyNextPingableConnection(cricket::RELAY_PORT_TYPE,
+ cricket::RELAY_PORT_TYPE);
+
+ // TCP Relay/Relay is the next.
+ VerifyNextPingableConnection(cricket::RELAY_PORT_TYPE,
+ cricket::RELAY_PORT_TYPE,
+ cricket::TCP_PROTOCOL_NAME);
+
+ // Finally, Local/Relay will be pinged.
+ VerifyNextPingableConnection(cricket::LOCAL_PORT_TYPE,
+ cricket::RELAY_PORT_TYPE);
+}

Powered by Google App Engine
This is Rietveld 408576698