OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2004 The WebRTC Project Authors. All rights reserved. | 2 * Copyright 2004 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 541 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
552 } else { | 552 } else { |
553 switch (proto) { | 553 switch (proto) { |
554 case PROTO_UDP: return "gturn(udp)"; | 554 case PROTO_UDP: return "gturn(udp)"; |
555 case PROTO_TCP: return "gturn(tcp)"; | 555 case PROTO_TCP: return "gturn(tcp)"; |
556 case PROTO_SSLTCP: return "gturn(ssltcp)"; | 556 case PROTO_SSLTCP: return "gturn(ssltcp)"; |
557 default: return "gturn(?)"; | 557 default: return "gturn(?)"; |
558 } | 558 } |
559 } | 559 } |
560 } | 560 } |
561 | 561 |
| 562 void SetNetworkType(rtc::AdapterType adapter_type) { |
| 563 network_.set_type(adapter_type); |
| 564 } |
| 565 |
562 void TestCrossFamilyPorts(int type); | 566 void TestCrossFamilyPorts(int type); |
563 | 567 |
564 void ExpectPortsCanConnect(bool can_connect, Port* p1, Port* p2); | 568 void ExpectPortsCanConnect(bool can_connect, Port* p1, Port* p2); |
565 | 569 |
566 // This does all the work and then deletes |port1| and |port2|. | 570 // This does all the work and then deletes |port1| and |port2|. |
567 void TestConnectivity(const char* name1, Port* port1, | 571 void TestConnectivity(const char* name1, Port* port1, |
568 const char* name2, Port* port2, | 572 const char* name2, Port* port2, |
569 bool accept, bool same_addr1, | 573 bool accept, bool same_addr1, |
570 bool same_addr2, bool possible); | 574 bool same_addr2, bool possible); |
571 | 575 |
(...skipping 1178 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1750 ASSERT_TRUE_WAIT(lport->last_stun_msg() != NULL, 1000); | 1754 ASSERT_TRUE_WAIT(lport->last_stun_msg() != NULL, 1000); |
1751 IceMessage* msg = lport->last_stun_msg(); | 1755 IceMessage* msg = lport->last_stun_msg(); |
1752 const StunUInt64Attribute* ice_controlling_attr = | 1756 const StunUInt64Attribute* ice_controlling_attr = |
1753 msg->GetUInt64(STUN_ATTR_ICE_CONTROLLING); | 1757 msg->GetUInt64(STUN_ATTR_ICE_CONTROLLING); |
1754 ASSERT_TRUE(ice_controlling_attr != NULL); | 1758 ASSERT_TRUE(ice_controlling_attr != NULL); |
1755 const StunByteStringAttribute* use_candidate_attr = msg->GetByteString( | 1759 const StunByteStringAttribute* use_candidate_attr = msg->GetByteString( |
1756 STUN_ATTR_USE_CANDIDATE); | 1760 STUN_ATTR_USE_CANDIDATE); |
1757 ASSERT_TRUE(use_candidate_attr != NULL); | 1761 ASSERT_TRUE(use_candidate_attr != NULL); |
1758 } | 1762 } |
1759 | 1763 |
| 1764 TEST_F(PortTest, TestNetworkInfoAttribute) { |
| 1765 rtc::scoped_ptr<TestPort> lport( |
| 1766 CreateTestPort(kLocalAddr1, "lfrag", "lpass")); |
| 1767 // Set the network type for rport to be cellular so its cost will be 999. |
| 1768 SetNetworkType(rtc::ADAPTER_TYPE_CELLULAR); |
| 1769 rtc::scoped_ptr<TestPort> rport( |
| 1770 CreateTestPort(kLocalAddr2, "rfrag", "rpass")); |
| 1771 lport->SetIceRole(cricket::ICEROLE_CONTROLLING); |
| 1772 lport->SetIceTiebreaker(kTiebreaker1); |
| 1773 rport->SetIceRole(cricket::ICEROLE_CONTROLLED); |
| 1774 rport->SetIceTiebreaker(kTiebreaker2); |
| 1775 |
| 1776 uint16_t lnetwork_id = 9; |
| 1777 lport->Network()->set_id(lnetwork_id); |
| 1778 // Send a fake ping from lport to rport. |
| 1779 lport->PrepareAddress(); |
| 1780 rport->PrepareAddress(); |
| 1781 Connection* lconn = |
| 1782 lport->CreateConnection(rport->Candidates()[0], Port::ORIGIN_MESSAGE); |
| 1783 lconn->Ping(0); |
| 1784 ASSERT_TRUE_WAIT(lport->last_stun_msg() != NULL, 1000); |
| 1785 IceMessage* msg = lport->last_stun_msg(); |
| 1786 const StunUInt32Attribute* network_info_attr = |
| 1787 msg->GetUInt32(STUN_ATTR_NETWORK_INFO); |
| 1788 ASSERT_TRUE(network_info_attr != NULL); |
| 1789 uint32_t network_info = network_info_attr->value(); |
| 1790 EXPECT_EQ(lnetwork_id, network_info >> 16); |
| 1791 // Default network cost is 0. |
| 1792 EXPECT_EQ(0U, network_info & 0xFFFF); |
| 1793 |
| 1794 // Send a fake ping from rport to lport. |
| 1795 uint16_t rnetwork_id = 8; |
| 1796 rport->Network()->set_id(rnetwork_id); |
| 1797 Connection* rconn = |
| 1798 rport->CreateConnection(lport->Candidates()[0], Port::ORIGIN_MESSAGE); |
| 1799 rconn->Ping(0); |
| 1800 ASSERT_TRUE_WAIT(rport->last_stun_msg() != NULL, 1000); |
| 1801 msg = rport->last_stun_msg(); |
| 1802 network_info_attr = msg->GetUInt32(STUN_ATTR_NETWORK_INFO); |
| 1803 ASSERT_TRUE(network_info_attr != NULL); |
| 1804 network_info = network_info_attr->value(); |
| 1805 EXPECT_EQ(rnetwork_id, network_info >> 16); |
| 1806 EXPECT_EQ(cricket::kMaxNetworkCost, network_info & 0xFFFF); |
| 1807 } |
| 1808 |
1760 // Test handling STUN messages. | 1809 // Test handling STUN messages. |
1761 TEST_F(PortTest, TestHandleStunMessage) { | 1810 TEST_F(PortTest, TestHandleStunMessage) { |
1762 // Our port will act as the "remote" port. | 1811 // Our port will act as the "remote" port. |
1763 rtc::scoped_ptr<TestPort> port( | 1812 rtc::scoped_ptr<TestPort> port( |
1764 CreateTestPort(kLocalAddr2, "rfrag", "rpass")); | 1813 CreateTestPort(kLocalAddr2, "rfrag", "rpass")); |
1765 | 1814 |
1766 rtc::scoped_ptr<IceMessage> in_msg, out_msg; | 1815 rtc::scoped_ptr<IceMessage> in_msg, out_msg; |
1767 rtc::scoped_ptr<ByteBuffer> buf(new ByteBuffer()); | 1816 rtc::scoped_ptr<ByteBuffer> buf(new ByteBuffer()); |
1768 rtc::SocketAddress addr(kLocalAddr1); | 1817 rtc::SocketAddress addr(kLocalAddr1); |
1769 std::string username; | 1818 std::string username; |
(...skipping 766 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2536 rtc::scoped_ptr<Port> tcp_port(CreateTcpPort(kLocalAddr1)); | 2585 rtc::scoped_ptr<Port> tcp_port(CreateTcpPort(kLocalAddr1)); |
2537 EXPECT_TRUE(tcp_port->SupportsProtocol(TCP_PROTOCOL_NAME)); | 2586 EXPECT_TRUE(tcp_port->SupportsProtocol(TCP_PROTOCOL_NAME)); |
2538 EXPECT_TRUE(tcp_port->SupportsProtocol(SSLTCP_PROTOCOL_NAME)); | 2587 EXPECT_TRUE(tcp_port->SupportsProtocol(SSLTCP_PROTOCOL_NAME)); |
2539 EXPECT_FALSE(tcp_port->SupportsProtocol(UDP_PROTOCOL_NAME)); | 2588 EXPECT_FALSE(tcp_port->SupportsProtocol(UDP_PROTOCOL_NAME)); |
2540 | 2589 |
2541 rtc::scoped_ptr<Port> turn_port( | 2590 rtc::scoped_ptr<Port> turn_port( |
2542 CreateTurnPort(kLocalAddr1, nat_socket_factory1(), PROTO_UDP, PROTO_UDP)); | 2591 CreateTurnPort(kLocalAddr1, nat_socket_factory1(), PROTO_UDP, PROTO_UDP)); |
2543 EXPECT_TRUE(turn_port->SupportsProtocol(UDP_PROTOCOL_NAME)); | 2592 EXPECT_TRUE(turn_port->SupportsProtocol(UDP_PROTOCOL_NAME)); |
2544 EXPECT_FALSE(turn_port->SupportsProtocol(TCP_PROTOCOL_NAME)); | 2593 EXPECT_FALSE(turn_port->SupportsProtocol(TCP_PROTOCOL_NAME)); |
2545 } | 2594 } |
OLD | NEW |