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 1105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1116 EXPECT_TRUE(infos[0].writable); | 1116 EXPECT_TRUE(infos[0].writable); |
1117 EXPECT_FALSE(infos[0].timeout); | 1117 EXPECT_FALSE(infos[0].timeout); |
1118 EXPECT_EQ(10U, infos[0].sent_total_packets); | 1118 EXPECT_EQ(10U, infos[0].sent_total_packets); |
1119 EXPECT_EQ(0U, infos[0].sent_discarded_packets); | 1119 EXPECT_EQ(0U, infos[0].sent_discarded_packets); |
1120 EXPECT_EQ(10 * 36U, infos[0].sent_total_bytes); | 1120 EXPECT_EQ(10 * 36U, infos[0].sent_total_bytes); |
1121 EXPECT_EQ(10 * 36U, infos[0].recv_total_bytes); | 1121 EXPECT_EQ(10 * 36U, infos[0].recv_total_bytes); |
1122 EXPECT_GT(infos[0].rtt, 0U); | 1122 EXPECT_GT(infos[0].rtt, 0U); |
1123 DestroyChannels(); | 1123 DestroyChannels(); |
1124 } | 1124 } |
1125 | 1125 |
| 1126 |
| 1127 // Test that p2ptransportchannel returns the state correctly. |
| 1128 TEST_F(P2PTransportChannelTest, TestGetState) { |
| 1129 ConfigureEndpoints(OPEN, OPEN, |
| 1130 kDefaultPortAllocatorFlags, |
| 1131 kDefaultPortAllocatorFlags); |
| 1132 CreateChannels(1); |
| 1133 EXPECT_TRUE_WAIT(ep1_ch1()->writable() && ep2_ch1()->writable(), 1000); |
| 1134 EXPECT_EQ_WAIT(cricket::TransportChannelState::STATE_COMPLETED, |
| 1135 ep1_ch1()->GetState(), 1000); |
| 1136 const std::vector<cricket::Connection*>& connections = |
| 1137 ep1_ch1()->connections(); |
| 1138 |
| 1139 ASSERT_TRUE(connections.size() >= 2); |
| 1140 connections[0]->Unprune(); |
| 1141 connections[1]->Unprune(); |
| 1142 EXPECT_EQ(cricket::TransportChannelState::STATE_CONNECTING, |
| 1143 ep1_ch1()->GetState()); |
| 1144 |
| 1145 for (cricket::Connection* conn : connections) { |
| 1146 conn->Prune(); |
| 1147 } |
| 1148 EXPECT_EQ(cricket::TransportChannelState::STATE_FAILED, |
| 1149 ep1_ch1()->GetState()); |
| 1150 } |
| 1151 |
1126 // Test that we properly create a connection on a STUN ping from unknown address | 1152 // Test that we properly create a connection on a STUN ping from unknown address |
1127 // when the signaling is slow. | 1153 // when the signaling is slow. |
1128 TEST_F(P2PTransportChannelTest, PeerReflexiveCandidateBeforeSignaling) { | 1154 TEST_F(P2PTransportChannelTest, PeerReflexiveCandidateBeforeSignaling) { |
1129 ConfigureEndpoints(OPEN, OPEN, | 1155 ConfigureEndpoints(OPEN, OPEN, |
1130 kDefaultPortAllocatorFlags, | 1156 kDefaultPortAllocatorFlags, |
1131 kDefaultPortAllocatorFlags); | 1157 kDefaultPortAllocatorFlags); |
1132 // Emulate no remote credentials coming in. | 1158 // Emulate no remote credentials coming in. |
1133 set_clear_remote_candidates_ufrag_pwd(false); | 1159 set_clear_remote_candidates_ufrag_pwd(false); |
1134 CreateChannels(1); | 1160 CreateChannels(1); |
1135 // Only have remote credentials come in for ep2, not ep1. | 1161 // Only have remote credentials come in for ep2, not ep1. |
(...skipping 283 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1419 cricket::PORTALLOCATOR_ENABLE_SHARED_SOCKET, | 1445 cricket::PORTALLOCATOR_ENABLE_SHARED_SOCKET, |
1420 kDefaultPortAllocatorFlags | | 1446 kDefaultPortAllocatorFlags | |
1421 cricket::PORTALLOCATOR_ENABLE_SHARED_SOCKET); | 1447 cricket::PORTALLOCATOR_ENABLE_SHARED_SOCKET); |
1422 set_force_relay(true); | 1448 set_force_relay(true); |
1423 | 1449 |
1424 SetAllocationStepDelay(0, kMinimumStepDelay); | 1450 SetAllocationStepDelay(0, kMinimumStepDelay); |
1425 SetAllocationStepDelay(1, kMinimumStepDelay); | 1451 SetAllocationStepDelay(1, kMinimumStepDelay); |
1426 | 1452 |
1427 CreateChannels(1); | 1453 CreateChannels(1); |
1428 | 1454 |
1429 EXPECT_TRUE_WAIT(ep1_ch1()->receiving() && ep1_ch1()->writable() && | 1455 EXPECT_TRUE_WAIT(ep1_ch1()->receiving() && |
1430 ep2_ch1()->receiving() && ep2_ch1()->writable(), | 1456 ep1_ch1()->writable() && |
| 1457 ep2_ch1()->receiving() && |
| 1458 ep2_ch1()->writable(), |
1431 2000); | 1459 2000); |
1432 | 1460 |
1433 EXPECT_TRUE(ep1_ch1()->best_connection() && | 1461 EXPECT_TRUE(ep1_ch1()->best_connection() && |
1434 ep2_ch1()->best_connection()); | 1462 ep2_ch1()->best_connection()); |
1435 | 1463 |
1436 EXPECT_EQ("relay", RemoteCandidate(ep1_ch1())->type()); | 1464 EXPECT_EQ("relay", RemoteCandidate(ep1_ch1())->type()); |
1437 EXPECT_EQ("relay", LocalCandidate(ep1_ch1())->type()); | 1465 EXPECT_EQ("relay", LocalCandidate(ep1_ch1())->type()); |
1438 EXPECT_EQ("relay", RemoteCandidate(ep2_ch1())->type()); | 1466 EXPECT_EQ("relay", RemoteCandidate(ep2_ch1())->type()); |
1439 EXPECT_EQ("relay", LocalCandidate(ep2_ch1())->type()); | 1467 EXPECT_EQ("relay", LocalCandidate(ep2_ch1())->type()); |
1440 | 1468 |
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1512 EXPECT_TRUE( | 1540 EXPECT_TRUE( |
1513 ep1_ch1()->best_connection() && ep2_ch1()->best_connection() && | 1541 ep1_ch1()->best_connection() && ep2_ch1()->best_connection() && |
1514 LocalCandidate(ep1_ch1())->address().EqualIPs(kPublicAddrs[0]) && | 1542 LocalCandidate(ep1_ch1())->address().EqualIPs(kPublicAddrs[0]) && |
1515 RemoteCandidate(ep1_ch1())->address().EqualIPs(kPublicAddrs[1])); | 1543 RemoteCandidate(ep1_ch1())->address().EqualIPs(kPublicAddrs[1])); |
1516 | 1544 |
1517 // Blackhole any traffic to or from the public addrs. | 1545 // Blackhole any traffic to or from the public addrs. |
1518 LOG(LS_INFO) << "Failing over..."; | 1546 LOG(LS_INFO) << "Failing over..."; |
1519 fw()->AddRule(false, rtc::FP_ANY, rtc::FD_ANY, | 1547 fw()->AddRule(false, rtc::FP_ANY, rtc::FD_ANY, |
1520 kPublicAddrs[1]); | 1548 kPublicAddrs[1]); |
1521 | 1549 |
1522 // We should detect loss of connectivity within 5 seconds or so. | 1550 // We should detect loss of connectivity within 2.5 seconds or so. |
1523 EXPECT_TRUE_WAIT(!ep1_ch1()->writable(), 7000); | 1551 // The best connection will be switched. So keep a reference to the |
| 1552 // current best connection. |
| 1553 const cricket::Connection* best_connection = ep1_ch1()->best_connection(); |
| 1554 EXPECT_TRUE_WAIT(!best_connection->receiving(), 3000); |
| 1555 // The channel is still receiving because the backup connection is receiving. |
| 1556 EXPECT_TRUE(ep1_ch1()->receiving()); |
1524 | 1557 |
1525 // We should switch over to use the alternate addr immediately | 1558 // We should switch over to use the alternate addr immediately |
1526 // when we lose writability. | 1559 // when we lose receiving. |
1527 EXPECT_TRUE_WAIT( | 1560 EXPECT_TRUE_WAIT( |
1528 ep1_ch1()->best_connection() && ep2_ch1()->best_connection() && | 1561 ep1_ch1()->best_connection() && ep2_ch1()->best_connection() && |
1529 LocalCandidate(ep1_ch1())->address().EqualIPs(kPublicAddrs[0]) && | 1562 LocalCandidate(ep1_ch1())->address().EqualIPs(kPublicAddrs[0]) && |
1530 RemoteCandidate(ep1_ch1())->address().EqualIPs(kAlternateAddrs[1]), | 1563 RemoteCandidate(ep1_ch1())->address().EqualIPs(kAlternateAddrs[1]), |
1531 3000); | 1564 1000); |
1532 | 1565 |
1533 DestroyChannels(); | 1566 DestroyChannels(); |
1534 } | 1567 } |
1535 | 1568 |
1536 /* | 1569 /* |
1537 | 1570 |
1538 TODO(pthatcher): Once have a way to handle network interfaces changes | 1571 TODO(pthatcher): Once have a way to handle network interfaces changes |
1539 without signalling an ICE restart, put a test like this back. In the | 1572 without signalling an ICE restart, put a test like this back. In the |
1540 mean time, this test only worked for GICE. With ICE, it's currently | 1573 mean time, this test only worked for GICE. With ICE, it's currently |
1541 not possible without an ICE restart. | 1574 not possible without an ICE restart. |
(...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1702 cricket::Connection* conn1 = WaitForConnectionTo(&ch, "1.1.1.1", 1); | 1735 cricket::Connection* conn1 = WaitForConnectionTo(&ch, "1.1.1.1", 1); |
1703 ASSERT_TRUE(conn1 != nullptr); | 1736 ASSERT_TRUE(conn1 != nullptr); |
1704 uint32 remote_priority = conn1->remote_candidate().priority(); | 1737 uint32 remote_priority = conn1->remote_candidate().priority(); |
1705 | 1738 |
1706 // Create a higher priority candidate and make the connection | 1739 // Create a higher priority candidate and make the connection |
1707 // receiving/writable. This will prune conn1. | 1740 // receiving/writable. This will prune conn1. |
1708 ch.OnCandidate(CreateCandidate("2.2.2.2", 2, 2)); | 1741 ch.OnCandidate(CreateCandidate("2.2.2.2", 2, 2)); |
1709 cricket::Connection* conn2 = WaitForConnectionTo(&ch, "2.2.2.2", 2); | 1742 cricket::Connection* conn2 = WaitForConnectionTo(&ch, "2.2.2.2", 2); |
1710 ASSERT_TRUE(conn2 != nullptr); | 1743 ASSERT_TRUE(conn2 != nullptr); |
1711 conn2->ReceivedPing(); | 1744 conn2->ReceivedPing(); |
| 1745 // Need Ping to set the last_ping_sent so that the write state will not |
| 1746 // become stale. |
| 1747 conn2->Ping(rtc::Time()); |
1712 conn2->ReceivedPingResponse(); | 1748 conn2->ReceivedPingResponse(); |
1713 | 1749 |
1714 // Wait for conn1 to be destroyed. | 1750 // Wait for conn1 being pruned. |
| 1751 ASSERT_EQ(conn1, GetConnectionTo(&ch, "1.1.1.1", 1)); |
| 1752 EXPECT_TRUE_WAIT( |
| 1753 conn1 == GetConnectionTo(&ch, "1.1.1.1", 1) && conn1->pruned(), 3000); |
| 1754 // conn1 won't be deleted right away. Destroy it. |
| 1755 conn1->Destroy(); |
1715 EXPECT_TRUE_WAIT(GetConnectionTo(&ch, "1.1.1.1", 1) == nullptr, 3000); | 1756 EXPECT_TRUE_WAIT(GetConnectionTo(&ch, "1.1.1.1", 1) == nullptr, 3000); |
1716 cricket::Port* port = GetPort(&ch); | |
1717 | 1757 |
1718 // Create a minimal STUN message with prflx priority. | 1758 // Create a minimal STUN message with prflx priority. |
1719 cricket::IceMessage request; | 1759 cricket::IceMessage request; |
1720 request.SetType(cricket::STUN_BINDING_REQUEST); | 1760 request.SetType(cricket::STUN_BINDING_REQUEST); |
1721 request.AddAttribute(new cricket::StunByteStringAttribute( | 1761 request.AddAttribute(new cricket::StunByteStringAttribute( |
1722 cricket::STUN_ATTR_USERNAME, kIceUfrag[1])); | 1762 cricket::STUN_ATTR_USERNAME, kIceUfrag[1])); |
1723 uint32 prflx_priority = cricket::ICE_TYPE_PREFERENCE_PRFLX << 24; | 1763 uint32 prflx_priority = cricket::ICE_TYPE_PREFERENCE_PRFLX << 24; |
1724 request.AddAttribute(new cricket::StunUInt32Attribute( | 1764 request.AddAttribute(new cricket::StunUInt32Attribute( |
1725 cricket::STUN_ATTR_PRIORITY, prflx_priority)); | 1765 cricket::STUN_ATTR_PRIORITY, prflx_priority)); |
1726 EXPECT_NE(prflx_priority, remote_priority); | 1766 EXPECT_NE(prflx_priority, remote_priority); |
1727 | 1767 |
| 1768 cricket::Port* port = GetPort(&ch); |
1728 // conn1 should be resurrected with original priority. | 1769 // conn1 should be resurrected with original priority. |
1729 port->SignalUnknownAddress(port, rtc::SocketAddress("1.1.1.1", 1), | 1770 port->SignalUnknownAddress(port, rtc::SocketAddress("1.1.1.1", 1), |
1730 cricket::PROTO_UDP, &request, kIceUfrag[1], false); | 1771 cricket::PROTO_UDP, &request, kIceUfrag[1], false); |
1731 conn1 = WaitForConnectionTo(&ch, "1.1.1.1", 1); | 1772 conn1 = WaitForConnectionTo(&ch, "1.1.1.1", 1); |
1732 ASSERT_TRUE(conn1 != nullptr); | 1773 ASSERT_TRUE(conn1 != nullptr); |
1733 EXPECT_EQ(conn1->remote_candidate().priority(), remote_priority); | 1774 EXPECT_EQ(conn1->remote_candidate().priority(), remote_priority); |
1734 | 1775 |
1735 // conn3, a real prflx connection, should have prflx priority. | 1776 // conn3, a real prflx connection, should have prflx priority. |
1736 port->SignalUnknownAddress(port, rtc::SocketAddress("3.3.3.3", 1), | 1777 port->SignalUnknownAddress(port, rtc::SocketAddress("3.3.3.3", 1), |
1737 cricket::PROTO_UDP, &request, kIceUfrag[1], false); | 1778 cricket::PROTO_UDP, &request, kIceUfrag[1], false); |
(...skipping 195 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1933 conn3->ReceivedPingResponse(); // Become writable. | 1974 conn3->ReceivedPingResponse(); // Become writable. |
1934 EXPECT_EQ(conn3, ch.best_connection()); | 1975 EXPECT_EQ(conn3, ch.best_connection()); |
1935 | 1976 |
1936 // Now another data packet will not switch the best connection because the | 1977 // Now another data packet will not switch the best connection because the |
1937 // best connection was nominated by the controlling side. | 1978 // best connection was nominated by the controlling side. |
1938 conn2->ReceivedPing(); | 1979 conn2->ReceivedPing(); |
1939 conn2->ReceivedPingResponse(); | 1980 conn2->ReceivedPingResponse(); |
1940 conn2->OnReadPacket("XYZ", 3, rtc::CreatePacketTime(0)); | 1981 conn2->OnReadPacket("XYZ", 3, rtc::CreatePacketTime(0)); |
1941 EXPECT_EQ(conn3, ch.best_connection()); | 1982 EXPECT_EQ(conn3, ch.best_connection()); |
1942 } | 1983 } |
OLD | NEW |