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

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

Issue 1940493002: Add Stats to Stun ping. (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Rename. Created 4 years, 6 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 unified diff | Download patch
« no previous file with comments | « webrtc/p2p/base/port.cc ('k') | webrtc/p2p/base/tcpport.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 1631 matching lines...) Expand 10 before | Expand all | Expand 10 after
1642 EXPECT_TRUE(msg->GetUInt32(STUN_ATTR_FINGERPRINT) != NULL); 1642 EXPECT_TRUE(msg->GetUInt32(STUN_ATTR_FINGERPRINT) != NULL);
1643 EXPECT_TRUE(StunMessage::ValidateFingerprint( 1643 EXPECT_TRUE(StunMessage::ValidateFingerprint(
1644 lport->last_stun_buf()->data<char>(), lport->last_stun_buf()->size())); 1644 lport->last_stun_buf()->data<char>(), lport->last_stun_buf()->size()));
1645 1645
1646 // Request should not include ping count. 1646 // Request should not include ping count.
1647 ASSERT_TRUE(msg->GetUInt32(STUN_ATTR_RETRANSMIT_COUNT) == NULL); 1647 ASSERT_TRUE(msg->GetUInt32(STUN_ATTR_RETRANSMIT_COUNT) == NULL);
1648 1648
1649 // Save a copy of the BINDING-REQUEST for use below. 1649 // Save a copy of the BINDING-REQUEST for use below.
1650 std::unique_ptr<IceMessage> request(CopyStunMessage(msg)); 1650 std::unique_ptr<IceMessage> request(CopyStunMessage(msg));
1651 1651
1652 // Respond with a BINDING-RESPONSE. 1652 // Receive the BINDING-REQUEST and respond with BINDING-RESPONSE.
1653 rport->SendBindingResponse(request.get(), lport->Candidates()[0].address()); 1653 rconn->OnReadPacket(lport->last_stun_buf()->data<char>(),
1654 lport->last_stun_buf()->size(), rtc::PacketTime());
1654 msg = rport->last_stun_msg(); 1655 msg = rport->last_stun_msg();
1655 ASSERT_TRUE(msg != NULL); 1656 ASSERT_TRUE(msg != NULL);
1656 EXPECT_EQ(STUN_BINDING_RESPONSE, msg->type()); 1657 EXPECT_EQ(STUN_BINDING_RESPONSE, msg->type());
1657 1658 // Received a BINDING-RESPONSE.
1659 lconn->OnReadPacket(rport->last_stun_buf()->data<char>(),
1660 rport->last_stun_buf()->size(), rtc::PacketTime());
1661 // Verify the STUN Stats.
1662 EXPECT_EQ(1U, lconn->stats().sent_ping_requests_total);
1663 EXPECT_EQ(1U, lconn->stats().sent_ping_requests_before_first_response);
1664 EXPECT_EQ(1U, lconn->stats().recv_ping_responses);
1665 EXPECT_EQ(1U, rconn->stats().recv_ping_requests);
1666 EXPECT_EQ(1U, rconn->stats().sent_ping_responses);
1658 1667
1659 EXPECT_FALSE(msg->IsLegacy()); 1668 EXPECT_FALSE(msg->IsLegacy());
1660 const StunAddressAttribute* addr_attr = msg->GetAddress( 1669 const StunAddressAttribute* addr_attr = msg->GetAddress(
1661 STUN_ATTR_XOR_MAPPED_ADDRESS); 1670 STUN_ATTR_XOR_MAPPED_ADDRESS);
1662 ASSERT_TRUE(addr_attr != NULL); 1671 ASSERT_TRUE(addr_attr != NULL);
1663 EXPECT_EQ(lport->Candidates()[0].address(), addr_attr->GetAddress()); 1672 EXPECT_EQ(lport->Candidates()[0].address(), addr_attr->GetAddress());
1664 EXPECT_TRUE(msg->GetByteString(STUN_ATTR_MESSAGE_INTEGRITY) != NULL); 1673 EXPECT_TRUE(msg->GetByteString(STUN_ATTR_MESSAGE_INTEGRITY) != NULL);
1665 EXPECT_TRUE(StunMessage::ValidateMessageIntegrity( 1674 EXPECT_TRUE(StunMessage::ValidateMessageIntegrity(
1666 rport->last_stun_buf()->data<char>(), rport->last_stun_buf()->size(), 1675 rport->last_stun_buf()->data<char>(), rport->last_stun_buf()->size(),
1667 "rpass")); 1676 "rpass"));
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
1721 EXPECT_TRUE(msg->GetByteString(STUN_ATTR_USE_CANDIDATE) == NULL); 1730 EXPECT_TRUE(msg->GetByteString(STUN_ATTR_USE_CANDIDATE) == NULL);
1722 1731
1723 // Request should include ping count. 1732 // Request should include ping count.
1724 const StunUInt32Attribute* retransmit_attr = 1733 const StunUInt32Attribute* retransmit_attr =
1725 msg->GetUInt32(STUN_ATTR_RETRANSMIT_COUNT); 1734 msg->GetUInt32(STUN_ATTR_RETRANSMIT_COUNT);
1726 ASSERT_TRUE(retransmit_attr != NULL); 1735 ASSERT_TRUE(retransmit_attr != NULL);
1727 EXPECT_EQ(2U, retransmit_attr->value()); 1736 EXPECT_EQ(2U, retransmit_attr->value());
1728 1737
1729 // Respond with a BINDING-RESPONSE. 1738 // Respond with a BINDING-RESPONSE.
1730 request.reset(CopyStunMessage(msg)); 1739 request.reset(CopyStunMessage(msg));
1731 lport->SendBindingResponse(request.get(), rport->Candidates()[0].address()); 1740 lconn->OnReadPacket(rport->last_stun_buf()->data<char>(),
1741 rport->last_stun_buf()->size(), rtc::PacketTime());
1732 msg = lport->last_stun_msg(); 1742 msg = lport->last_stun_msg();
1743 // Receive the BINDING-RESPONSE.
1744 rconn->OnReadPacket(lport->last_stun_buf()->data<char>(),
1745 lport->last_stun_buf()->size(), rtc::PacketTime());
1746
1747 // Verify the Stun ping stats.
1748 EXPECT_EQ(3U, rconn->stats().sent_ping_requests_total);
1749 EXPECT_EQ(3U, rconn->stats().sent_ping_requests_before_first_response);
1750 EXPECT_EQ(1U, rconn->stats().recv_ping_responses);
1751 EXPECT_EQ(1U, lconn->stats().sent_ping_responses);
1752 EXPECT_EQ(1U, lconn->stats().recv_ping_requests);
1753 // Ping after receiver the first response
1754 rconn->Ping(0);
1755 rconn->Ping(0);
1756 EXPECT_EQ(5U, rconn->stats().sent_ping_requests_total);
1757 EXPECT_EQ(3U, rconn->stats().sent_ping_requests_before_first_response);
1733 1758
1734 // Response should include same ping count. 1759 // Response should include same ping count.
1735 retransmit_attr = msg->GetUInt32(STUN_ATTR_RETRANSMIT_COUNT); 1760 retransmit_attr = msg->GetUInt32(STUN_ATTR_RETRANSMIT_COUNT);
1736 ASSERT_TRUE(retransmit_attr != NULL); 1761 ASSERT_TRUE(retransmit_attr != NULL);
1737 EXPECT_EQ(2U, retransmit_attr->value()); 1762 EXPECT_EQ(2U, retransmit_attr->value());
1738 } 1763 }
1739 1764
1740 TEST_F(PortTest, TestUseCandidateAttribute) { 1765 TEST_F(PortTest, TestUseCandidateAttribute) {
1741 std::unique_ptr<TestPort> lport( 1766 std::unique_ptr<TestPort> lport(
1742 CreateTestPort(kLocalAddr1, "lfrag", "lpass")); 1767 CreateTestPort(kLocalAddr1, "lfrag", "lpass"));
(...skipping 915 matching lines...) Expand 10 before | Expand all | Expand 10 after
2658 EXPECT_EQ(1UL, port->Candidates().size()); 2683 EXPECT_EQ(1UL, port->Candidates().size());
2659 port->SetIceParameters(1, "ufrag2", "password2"); 2684 port->SetIceParameters(1, "ufrag2", "password2");
2660 EXPECT_EQ(1, port->component()); 2685 EXPECT_EQ(1, port->component());
2661 EXPECT_EQ("ufrag2", port->username_fragment()); 2686 EXPECT_EQ("ufrag2", port->username_fragment());
2662 EXPECT_EQ("password2", port->password()); 2687 EXPECT_EQ("password2", port->password());
2663 const Candidate& candidate = port->Candidates()[0]; 2688 const Candidate& candidate = port->Candidates()[0];
2664 EXPECT_EQ(1, candidate.component()); 2689 EXPECT_EQ(1, candidate.component());
2665 EXPECT_EQ("ufrag2", candidate.username()); 2690 EXPECT_EQ("ufrag2", candidate.username());
2666 EXPECT_EQ("password2", candidate.password()); 2691 EXPECT_EQ("password2", candidate.password());
2667 } 2692 }
OLDNEW
« no previous file with comments | « webrtc/p2p/base/port.cc ('k') | webrtc/p2p/base/tcpport.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698