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

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

Issue 2395243005: Prune connections based on network name. (Closed)
Patch Set: Override system-provided HasIPv6Enabled method Created 4 years, 2 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/p2ptransportchannel.cc ('k') | no next file » | 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 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 2795 matching lines...) Expand 10 before | Expand all | Expand 10 after
2806 rtc::FakeClock* clock = nullptr) { 2806 rtc::FakeClock* clock = nullptr) {
2807 if (clock == nullptr) { 2807 if (clock == nullptr) {
2808 EXPECT_TRUE_WAIT(GetConnectionTo(ch, ip, port_num) != nullptr, 3000); 2808 EXPECT_TRUE_WAIT(GetConnectionTo(ch, ip, port_num) != nullptr, 3000);
2809 } else { 2809 } else {
2810 EXPECT_TRUE_SIMULATED_WAIT(GetConnectionTo(ch, ip, port_num) != nullptr, 2810 EXPECT_TRUE_SIMULATED_WAIT(GetConnectionTo(ch, ip, port_num) != nullptr,
2811 3000, *clock); 2811 3000, *clock);
2812 } 2812 }
2813 return GetConnectionTo(ch, ip, port_num); 2813 return GetConnectionTo(ch, ip, port_num);
2814 } 2814 }
2815 2815
2816 Port* GetPort(P2PTransportChannel* ch) { 2816 Port* GetFirstPort(P2PTransportChannel* ch) {
2817 if (ch->ports().empty()) { 2817 if (ch->ports().empty()) {
2818 return nullptr; 2818 return nullptr;
2819 } 2819 }
2820 return static_cast<Port*>(ch->ports()[0]); 2820 return static_cast<Port*>(ch->ports()[0]);
2821 } 2821 }
2822 2822
2823 Port* GetPrunedPort(P2PTransportChannel* ch) { 2823 Port* GetPrunedPort(P2PTransportChannel* ch) {
2824 if (ch->pruned_ports().empty()) { 2824 if (ch->pruned_ports().empty()) {
2825 return nullptr; 2825 return nullptr;
2826 } 2826 }
2827 return static_cast<Port*>(ch->pruned_ports()[0]); 2827 return static_cast<Port*>(ch->pruned_ports()[0]);
2828 } 2828 }
2829 2829
2830 Connection* GetConnectionTo(P2PTransportChannel* ch, 2830 Connection* GetConnectionTo(P2PTransportChannel* ch,
2831 const std::string& ip, 2831 const std::string& ip,
2832 int port_num) { 2832 int port_num) {
2833 Port* port = GetPort(ch); 2833 for (PortInterface* port : ch->ports()) {
2834 if (!port) { 2834 Connection* conn = port->GetConnection(rtc::SocketAddress(ip, port_num));
2835 return nullptr; 2835 if (conn != nullptr) {
2836 return conn;
2837 }
2836 } 2838 }
2837 return port->GetConnection(rtc::SocketAddress(ip, port_num)); 2839 return nullptr;
2838 } 2840 }
2839 2841
2840 Connection* FindNextPingableConnectionAndPingIt(P2PTransportChannel* ch) { 2842 Connection* FindNextPingableConnectionAndPingIt(P2PTransportChannel* ch) {
2841 Connection* conn = ch->FindNextPingableConnection(); 2843 Connection* conn = ch->FindNextPingableConnection();
2842 if (conn) { 2844 if (conn) {
2843 ch->MarkConnectionPinged(conn); 2845 ch->MarkConnectionPinged(conn);
2844 } 2846 }
2845 return conn; 2847 return conn;
2846 } 2848 }
2847 2849
(...skipping 236 matching lines...) Expand 10 before | Expand all | Expand 10 after
3084 3086
3085 // Simulate a binding request being received, creating a peer reflexive 3087 // Simulate a binding request being received, creating a peer reflexive
3086 // candidate pair while we still don't have remote ICE parameters. 3088 // candidate pair while we still don't have remote ICE parameters.
3087 IceMessage request; 3089 IceMessage request;
3088 request.SetType(STUN_BINDING_REQUEST); 3090 request.SetType(STUN_BINDING_REQUEST);
3089 request.AddAttribute( 3091 request.AddAttribute(
3090 new StunByteStringAttribute(STUN_ATTR_USERNAME, kIceUfrag[1])); 3092 new StunByteStringAttribute(STUN_ATTR_USERNAME, kIceUfrag[1]));
3091 uint32_t prflx_priority = ICE_TYPE_PREFERENCE_PRFLX << 24; 3093 uint32_t prflx_priority = ICE_TYPE_PREFERENCE_PRFLX << 24;
3092 request.AddAttribute( 3094 request.AddAttribute(
3093 new StunUInt32Attribute(STUN_ATTR_PRIORITY, prflx_priority)); 3095 new StunUInt32Attribute(STUN_ATTR_PRIORITY, prflx_priority));
3094 Port* port = GetPort(&ch); 3096 Port* port = GetFirstPort(&ch);
3095 ASSERT_NE(nullptr, port); 3097 ASSERT_NE(nullptr, port);
3096 port->SignalUnknownAddress(port, rtc::SocketAddress("1.1.1.1", 1), PROTO_UDP, 3098 port->SignalUnknownAddress(port, rtc::SocketAddress("1.1.1.1", 1), PROTO_UDP,
3097 &request, kIceUfrag[1], false); 3099 &request, kIceUfrag[1], false);
3098 Connection* conn = GetConnectionTo(&ch, "1.1.1.1", 1); 3100 Connection* conn = GetConnectionTo(&ch, "1.1.1.1", 1);
3099 ASSERT_NE(nullptr, conn); 3101 ASSERT_NE(nullptr, conn);
3100 3102
3101 // Simulate waiting for a second (and change) and verify that no pings were 3103 // Simulate waiting for a second (and change) and verify that no pings were
3102 // sent, since we don't yet have remote ICE parameters. 3104 // sent, since we don't yet have remote ICE parameters.
3103 SIMULATED_WAIT(conn->num_pings_sent() > 0, 1025, clock); 3105 SIMULATED_WAIT(conn->num_pings_sent() > 0, 1025, clock);
3104 EXPECT_EQ(0, conn->num_pings_sent()); 3106 EXPECT_EQ(0, conn->num_pings_sent());
(...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after
3253 // Create a minimal STUN message with prflx priority. 3255 // Create a minimal STUN message with prflx priority.
3254 IceMessage request; 3256 IceMessage request;
3255 request.SetType(STUN_BINDING_REQUEST); 3257 request.SetType(STUN_BINDING_REQUEST);
3256 request.AddAttribute( 3258 request.AddAttribute(
3257 new StunByteStringAttribute(STUN_ATTR_USERNAME, kIceUfrag[1])); 3259 new StunByteStringAttribute(STUN_ATTR_USERNAME, kIceUfrag[1]));
3258 uint32_t prflx_priority = ICE_TYPE_PREFERENCE_PRFLX << 24; 3260 uint32_t prflx_priority = ICE_TYPE_PREFERENCE_PRFLX << 24;
3259 request.AddAttribute( 3261 request.AddAttribute(
3260 new StunUInt32Attribute(STUN_ATTR_PRIORITY, prflx_priority)); 3262 new StunUInt32Attribute(STUN_ATTR_PRIORITY, prflx_priority));
3261 EXPECT_NE(prflx_priority, remote_priority); 3263 EXPECT_NE(prflx_priority, remote_priority);
3262 3264
3263 Port* port = GetPort(&ch); 3265 Port* port = GetFirstPort(&ch);
3264 // conn1 should be resurrected with original priority. 3266 // conn1 should be resurrected with original priority.
3265 port->SignalUnknownAddress(port, rtc::SocketAddress("1.1.1.1", 1), PROTO_UDP, 3267 port->SignalUnknownAddress(port, rtc::SocketAddress("1.1.1.1", 1), PROTO_UDP,
3266 &request, kIceUfrag[1], false); 3268 &request, kIceUfrag[1], false);
3267 conn1 = WaitForConnectionTo(&ch, "1.1.1.1", 1); 3269 conn1 = WaitForConnectionTo(&ch, "1.1.1.1", 1);
3268 ASSERT_TRUE(conn1 != nullptr); 3270 ASSERT_TRUE(conn1 != nullptr);
3269 EXPECT_EQ(conn1->remote_candidate().priority(), remote_priority); 3271 EXPECT_EQ(conn1->remote_candidate().priority(), remote_priority);
3270 3272
3271 // conn3, a real prflx connection, should have prflx priority. 3273 // conn3, a real prflx connection, should have prflx priority.
3272 port->SignalUnknownAddress(port, rtc::SocketAddress("3.3.3.3", 1), PROTO_UDP, 3274 port->SignalUnknownAddress(port, rtc::SocketAddress("3.3.3.3", 1), PROTO_UDP,
3273 &request, kIceUfrag[1], false); 3275 &request, kIceUfrag[1], false);
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after
3392 ch.SetIceRole(ICEROLE_CONTROLLED); 3394 ch.SetIceRole(ICEROLE_CONTROLLED);
3393 ch.MaybeStartGathering(); 3395 ch.MaybeStartGathering();
3394 // A minimal STUN message with prflx priority. 3396 // A minimal STUN message with prflx priority.
3395 IceMessage request; 3397 IceMessage request;
3396 request.SetType(STUN_BINDING_REQUEST); 3398 request.SetType(STUN_BINDING_REQUEST);
3397 request.AddAttribute( 3399 request.AddAttribute(
3398 new StunByteStringAttribute(STUN_ATTR_USERNAME, kIceUfrag[1])); 3400 new StunByteStringAttribute(STUN_ATTR_USERNAME, kIceUfrag[1]));
3399 uint32_t prflx_priority = ICE_TYPE_PREFERENCE_PRFLX << 24; 3401 uint32_t prflx_priority = ICE_TYPE_PREFERENCE_PRFLX << 24;
3400 request.AddAttribute( 3402 request.AddAttribute(
3401 new StunUInt32Attribute(STUN_ATTR_PRIORITY, prflx_priority)); 3403 new StunUInt32Attribute(STUN_ATTR_PRIORITY, prflx_priority));
3402 TestUDPPort* port = static_cast<TestUDPPort*>(GetPort(&ch)); 3404 TestUDPPort* port = static_cast<TestUDPPort*>(GetFirstPort(&ch));
3403 port->SignalUnknownAddress(port, rtc::SocketAddress("1.1.1.1", 1), PROTO_UDP, 3405 port->SignalUnknownAddress(port, rtc::SocketAddress("1.1.1.1", 1), PROTO_UDP,
3404 &request, kIceUfrag[1], false); 3406 &request, kIceUfrag[1], false);
3405 Connection* conn1 = WaitForConnectionTo(&ch, "1.1.1.1", 1); 3407 Connection* conn1 = WaitForConnectionTo(&ch, "1.1.1.1", 1);
3406 ASSERT_TRUE(conn1 != nullptr); 3408 ASSERT_TRUE(conn1 != nullptr);
3407 EXPECT_TRUE(port->sent_binding_response()); 3409 EXPECT_TRUE(port->sent_binding_response());
3408 EXPECT_NE(conn1, ch.selected_connection()); 3410 EXPECT_NE(conn1, ch.selected_connection());
3409 conn1->ReceivedPingResponse(LOW_RTT, "id"); 3411 conn1->ReceivedPingResponse(LOW_RTT, "id");
3410 EXPECT_EQ_WAIT(conn1, ch.selected_connection(), kDefaultTimeout); 3412 EXPECT_EQ_WAIT(conn1, ch.selected_connection(), kDefaultTimeout);
3411 port->set_sent_binding_response(false); 3413 port->set_sent_binding_response(false);
3412 3414
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
3490 // Now another STUN message with an unknown address and use_candidate will 3492 // Now another STUN message with an unknown address and use_candidate will
3491 // nominate the selected connection. 3493 // nominate the selected connection.
3492 IceMessage request; 3494 IceMessage request;
3493 request.SetType(STUN_BINDING_REQUEST); 3495 request.SetType(STUN_BINDING_REQUEST);
3494 request.AddAttribute( 3496 request.AddAttribute(
3495 new StunByteStringAttribute(STUN_ATTR_USERNAME, kIceUfrag[1])); 3497 new StunByteStringAttribute(STUN_ATTR_USERNAME, kIceUfrag[1]));
3496 uint32_t prflx_priority = ICE_TYPE_PREFERENCE_PRFLX << 24; 3498 uint32_t prflx_priority = ICE_TYPE_PREFERENCE_PRFLX << 24;
3497 request.AddAttribute( 3499 request.AddAttribute(
3498 new StunUInt32Attribute(STUN_ATTR_PRIORITY, prflx_priority)); 3500 new StunUInt32Attribute(STUN_ATTR_PRIORITY, prflx_priority));
3499 request.AddAttribute(new StunByteStringAttribute(STUN_ATTR_USE_CANDIDATE)); 3501 request.AddAttribute(new StunByteStringAttribute(STUN_ATTR_USE_CANDIDATE));
3500 Port* port = GetPort(&ch); 3502 Port* port = GetFirstPort(&ch);
3501 port->SignalUnknownAddress(port, rtc::SocketAddress("3.3.3.3", 3), PROTO_UDP, 3503 port->SignalUnknownAddress(port, rtc::SocketAddress("3.3.3.3", 3), PROTO_UDP,
3502 &request, kIceUfrag[1], false); 3504 &request, kIceUfrag[1], false);
3503 Connection* conn3 = WaitForConnectionTo(&ch, "3.3.3.3", 3); 3505 Connection* conn3 = WaitForConnectionTo(&ch, "3.3.3.3", 3);
3504 ASSERT_TRUE(conn3 != nullptr); 3506 ASSERT_TRUE(conn3 != nullptr);
3505 EXPECT_EQ(conn2, ch.selected_connection()); // Not writable yet. 3507 EXPECT_EQ(conn2, ch.selected_connection()); // Not writable yet.
3506 conn3->ReceivedPingResponse(LOW_RTT, "id"); // Become writable. 3508 conn3->ReceivedPingResponse(LOW_RTT, "id"); // Become writable.
3507 EXPECT_EQ_WAIT(conn3, ch.selected_connection(), kDefaultTimeout); 3509 EXPECT_EQ_WAIT(conn3, ch.selected_connection(), kDefaultTimeout);
3508 3510
3509 // Now another data packet will not switch the selected connection because the 3511 // Now another data packet will not switch the selected connection because the
3510 // selected connection was nominated by the controlling side. 3512 // selected connection was nominated by the controlling side.
(...skipping 354 matching lines...) Expand 10 before | Expand all | Expand 10 after
3865 EXPECT_EQ(TransportChannelState::STATE_CONNECTING, ch.GetState()); 3867 EXPECT_EQ(TransportChannelState::STATE_CONNECTING, ch.GetState());
3866 3868
3867 // When |conn1| comes back again, |conn2| will be pruned again. 3869 // When |conn1| comes back again, |conn2| will be pruned again.
3868 conn1->ReceivedPingResponse(LOW_RTT, "id"); 3870 conn1->ReceivedPingResponse(LOW_RTT, "id");
3869 EXPECT_EQ_SIMULATED_WAIT(conn1, ch.selected_connection(), kDefaultTimeout, 3871 EXPECT_EQ_SIMULATED_WAIT(conn1, ch.selected_connection(), kDefaultTimeout,
3870 clock); 3872 clock);
3871 EXPECT_TRUE_SIMULATED_WAIT(!conn2->active(), kDefaultTimeout, clock); 3873 EXPECT_TRUE_SIMULATED_WAIT(!conn2->active(), kDefaultTimeout, clock);
3872 EXPECT_EQ(TransportChannelState::STATE_COMPLETED, ch.GetState()); 3874 EXPECT_EQ(TransportChannelState::STATE_COMPLETED, ch.GetState());
3873 } 3875 }
3874 3876
3877 TEST_F(P2PTransportChannelPingTest, TestPruneConnectionsByNetworkName) {
3878 std::string ipv4_addr("1.1.1.1");
3879 std::string ipv6_addr("2400:1:2:3:4:5:6:7");
3880 FakePortAllocator pa(rtc::Thread::Current(), nullptr);
3881 pa.set_ipv6_enabled(true);
3882 pa.set_flags(PORTALLOCATOR_ENABLE_IPV6);
3883 P2PTransportChannel ch("test channel", 1, &pa);
3884 PrepareChannel(&ch);
3885 ch.MaybeStartGathering();
3886 ch.AddRemoteCandidate(CreateUdpCandidate(LOCAL_PORT_TYPE, ipv4_addr, 1, 100));
3887 ch.AddRemoteCandidate(CreateUdpCandidate(LOCAL_PORT_TYPE, ipv6_addr, 1, 100));
3888 Connection* conn1 = WaitForConnectionTo(&ch, ipv4_addr, 1);
3889 ASSERT_TRUE(conn1 != nullptr);
3890 Connection* conn2 = WaitForConnectionTo(&ch, ipv6_addr, 1);
3891 ASSERT_TRUE(conn2 != nullptr);
3892 conn1->ReceivedPingResponse(LOW_RTT, "id");
3893 EXPECT_EQ_WAIT(conn1, ch.selected_connection(), kDefaultTimeout);
3894 conn2->ReceivedPingResponse(LOW_RTT, "id");
3895 // IPv6 connection has higher priority.
3896 EXPECT_EQ_WAIT(conn2, ch.selected_connection(), kDefaultTimeout);
3897 // Since conn1 and conn2 are on networks with the same network name,
3898 // conn1 will be pruned when conn2 becomes writable and receiving.
3899 EXPECT_FALSE(conn1->writable());
3900 }
3901
3875 // Test that if all connections in a channel has timed out on writing, they 3902 // Test that if all connections in a channel has timed out on writing, they
3876 // will all be deleted. We use Prune to simulate write_time_out. 3903 // will all be deleted. We use Prune to simulate write_time_out.
3877 TEST_F(P2PTransportChannelPingTest, TestDeleteConnectionsIfAllWriteTimedout) { 3904 TEST_F(P2PTransportChannelPingTest, TestDeleteConnectionsIfAllWriteTimedout) {
3878 FakePortAllocator pa(rtc::Thread::Current(), nullptr); 3905 FakePortAllocator pa(rtc::Thread::Current(), nullptr);
3879 P2PTransportChannel ch("test channel", 1, &pa); 3906 P2PTransportChannel ch("test channel", 1, &pa);
3880 PrepareChannel(&ch); 3907 PrepareChannel(&ch);
3881 ch.MaybeStartGathering(); 3908 ch.MaybeStartGathering();
3882 // Have one connection only but later becomes write-time-out. 3909 // Have one connection only but later becomes write-time-out.
3883 ch.AddRemoteCandidate(CreateUdpCandidate(LOCAL_PORT_TYPE, "1.1.1.1", 1, 100)); 3910 ch.AddRemoteCandidate(CreateUdpCandidate(LOCAL_PORT_TYPE, "1.1.1.1", 1, 100));
3884 Connection* conn1 = WaitForConnectionTo(&ch, "1.1.1.1", 1); 3911 Connection* conn1 = WaitForConnectionTo(&ch, "1.1.1.1", 1);
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after
3999 Connection* conn = WaitForConnectionTo(&ch, "1.1.1.1", 1); 4026 Connection* conn = WaitForConnectionTo(&ch, "1.1.1.1", 1);
4000 ASSERT_TRUE(conn != nullptr); 4027 ASSERT_TRUE(conn != nullptr);
4001 4028
4002 // Simulate 2 minutes going by. This should be enough time for the port to 4029 // Simulate 2 minutes going by. This should be enough time for the port to
4003 // time out. 4030 // time out.
4004 for (int second = 0; second < 120; ++second) { 4031 for (int second = 0; second < 120; ++second) {
4005 fake_clock.AdvanceTime(rtc::TimeDelta::FromSeconds(1)); 4032 fake_clock.AdvanceTime(rtc::TimeDelta::FromSeconds(1));
4006 } 4033 }
4007 EXPECT_EQ(nullptr, GetConnectionTo(&ch, "1.1.1.1", 1)); 4034 EXPECT_EQ(nullptr, GetConnectionTo(&ch, "1.1.1.1", 1));
4008 // Port will not be removed because it is not pruned yet. 4035 // Port will not be removed because it is not pruned yet.
4009 PortInterface* port = GetPort(&ch); 4036 PortInterface* port = GetFirstPort(&ch);
4010 ASSERT_NE(nullptr, port); 4037 ASSERT_NE(nullptr, port);
4011 4038
4012 // If the session prunes all ports, the port will be destroyed. 4039 // If the session prunes all ports, the port will be destroyed.
4013 ch.allocator_session()->PruneAllPorts(); 4040 ch.allocator_session()->PruneAllPorts();
4014 EXPECT_EQ_SIMULATED_WAIT(nullptr, GetPort(&ch), 1, fake_clock); 4041 EXPECT_EQ_SIMULATED_WAIT(nullptr, GetFirstPort(&ch), 1, fake_clock);
4015 EXPECT_EQ_SIMULATED_WAIT(nullptr, GetPrunedPort(&ch), 1, fake_clock); 4042 EXPECT_EQ_SIMULATED_WAIT(nullptr, GetPrunedPort(&ch), 1, fake_clock);
4016 } 4043 }
4017 4044
4018 class P2PTransportChannelMostLikelyToWorkFirstTest 4045 class P2PTransportChannelMostLikelyToWorkFirstTest
4019 : public P2PTransportChannelPingTest { 4046 : public P2PTransportChannelPingTest {
4020 public: 4047 public:
4021 P2PTransportChannelMostLikelyToWorkFirstTest() 4048 P2PTransportChannelMostLikelyToWorkFirstTest()
4022 : turn_server_(rtc::Thread::Current(), kTurnUdpIntAddr, kTurnUdpExtAddr) { 4049 : turn_server_(rtc::Thread::Current(), kTurnUdpIntAddr, kTurnUdpExtAddr) {
4023 network_manager_.AddInterface(kPublicAddrs[0]); 4050 network_manager_.AddInterface(kPublicAddrs[0]);
4024 allocator_.reset( 4051 allocator_.reset(
(...skipping 191 matching lines...) Expand 10 before | Expand all | Expand 10 after
4216 4243
4217 // TCP Relay/Relay is the next. 4244 // TCP Relay/Relay is the next.
4218 VerifyNextPingableConnection(RELAY_PORT_TYPE, RELAY_PORT_TYPE, 4245 VerifyNextPingableConnection(RELAY_PORT_TYPE, RELAY_PORT_TYPE,
4219 TCP_PROTOCOL_NAME); 4246 TCP_PROTOCOL_NAME);
4220 4247
4221 // Finally, Local/Relay will be pinged. 4248 // Finally, Local/Relay will be pinged.
4222 VerifyNextPingableConnection(LOCAL_PORT_TYPE, RELAY_PORT_TYPE); 4249 VerifyNextPingableConnection(LOCAL_PORT_TYPE, RELAY_PORT_TYPE);
4223 } 4250 }
4224 4251
4225 } // namespace cricket { 4252 } // namespace cricket {
OLDNEW
« no previous file with comments | « webrtc/p2p/base/p2ptransportchannel.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698