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

Side by Side Diff: webrtc/p2p/client/portallocator_unittest.cc

Issue 1274013002: Bug 4865: Enable connectivity when the remote peer is on public internet. (Closed) Base URL: https://chromium.googlesource.com/external/webrtc@master
Patch Set: Created 5 years, 4 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/base/ipaddress_unittest.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 101 matching lines...) Expand 10 before | Expand all | Expand 10 after
112 } 112 }
113 void AddInterfaceAsDefaultRoute(const SocketAddress& addr) { 113 void AddInterfaceAsDefaultRoute(const SocketAddress& addr) {
114 AddInterface(addr); 114 AddInterface(addr);
115 // When a binding comes from the any address, the |addr| will be used as the 115 // When a binding comes from the any address, the |addr| will be used as the
116 // srflx address. 116 // srflx address.
117 vss_->SetDefaultRoute(addr.ipaddr()); 117 vss_->SetDefaultRoute(addr.ipaddr());
118 } 118 }
119 bool SetPortRange(int min_port, int max_port) { 119 bool SetPortRange(int min_port, int max_port) {
120 return allocator_->SetPortRange(min_port, max_port); 120 return allocator_->SetPortRange(min_port, max_port);
121 } 121 }
122 // No STUN/TURN configuration. 122 // Endpoint is on the public network. No STUN or TURN.
123 void ResetWithNoServers() { 123 void ResetWithNoServersOrNat() {
124 allocator_.reset(new cricket::BasicPortAllocator(&network_manager_)); 124 allocator_.reset(new cricket::BasicPortAllocator(&network_manager_));
125 allocator_->set_step_delay(cricket::kMinimumStepDelay); 125 allocator_->set_step_delay(cricket::kMinimumStepDelay);
126 } 126 }
127 void ResetWithNatServer(const rtc::SocketAddress& stun_server) { 127 // Endpoint is behind a NAT, with STUN specified.
128 nat_server_.reset(new rtc::NATServer( 128 void ResetWithStunServerAndNat(const rtc::SocketAddress& stun_server) {
129 rtc::NAT_OPEN_CONE, vss_.get(), kNatUdpAddr, kNatTcpAddr, vss_.get(), 129 ResetWithStunServer(stun_server, true);
130 rtc::SocketAddress(kNatUdpAddr.ipaddr(), 0)));
131
132 ServerAddresses stun_servers;
133 if (!stun_server.IsNil()) {
134 stun_servers.insert(stun_server);
135 }
136 allocator_.reset(new cricket::BasicPortAllocator(
137 &network_manager_, nat_socket_factory_.get(), stun_servers));
138 allocator().set_step_delay(cricket::kMinimumStepDelay);
139 } 130 }
140 131 // Endpoint is on the public network, with STUN specified.
141 void ResetWithStunServer(const rtc::SocketAddress& stun_server) { 132 void ResetWithStunServerNoNat(const rtc::SocketAddress& stun_server) {
142 nat_socket_factory_.reset(new rtc::BasicPacketSocketFactory()); 133 ResetWithStunServer(stun_server, false);
143
144 ServerAddresses stun_servers;
145 if (!stun_server.IsNil()) {
146 stun_servers.insert(stun_server);
147 }
148 allocator_.reset(new cricket::BasicPortAllocator(
149 &network_manager_, nat_socket_factory_.get(), stun_servers));
150 allocator().set_step_delay(cricket::kMinimumStepDelay);
151 } 134 }
152 135 // Endpoint is on the public network, with TURN specified.
153 // Create a BasicPortAllocator without GTURN and add the TURN servers. 136 void ResetWithTurnServersNoNat(const rtc::SocketAddress& udp_turn,
154 void ResetWithTurnServers(const rtc::SocketAddress& udp_turn, 137 const rtc::SocketAddress& tcp_turn) {
155 const rtc::SocketAddress& tcp_turn) { 138 ResetWithNoServersOrNat();
156 allocator_.reset(new cricket::BasicPortAllocator(&network_manager_));
157 allocator().set_step_delay(cricket::kMinimumStepDelay);
158 AddTurnServers(udp_turn, tcp_turn); 139 AddTurnServers(udp_turn, tcp_turn);
159 } 140 }
160 141
161 void AddTurnServers(const rtc::SocketAddress& udp_turn, 142 void AddTurnServers(const rtc::SocketAddress& udp_turn,
162 const rtc::SocketAddress& tcp_turn) { 143 const rtc::SocketAddress& tcp_turn) {
163 cricket::RelayServerConfig relay_server(cricket::RELAY_TURN); 144 cricket::RelayServerConfig relay_server(cricket::RELAY_TURN);
164 cricket::RelayCredentials credentials(kTurnUsername, kTurnPassword); 145 cricket::RelayCredentials credentials(kTurnUsername, kTurnPassword);
165 relay_server.credentials = credentials; 146 relay_server.credentials = credentials;
166 147
167 if (!udp_turn.IsNil()) { 148 if (!udp_turn.IsNil()) {
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after
267 const rtc::IPAddress& relay_candidate_tcp_transport_addr) { 248 const rtc::IPAddress& relay_candidate_tcp_transport_addr) {
268 EXPECT_TRUE(CreateSession(cricket::ICE_CANDIDATE_COMPONENT_RTP)); 249 EXPECT_TRUE(CreateSession(cricket::ICE_CANDIDATE_COMPONENT_RTP));
269 session_->set_flags(cricket::PORTALLOCATOR_DISABLE_ADAPTER_ENUMERATION | 250 session_->set_flags(cricket::PORTALLOCATOR_DISABLE_ADAPTER_ENUMERATION |
270 cricket::PORTALLOCATOR_ENABLE_SHARED_UFRAG | 251 cricket::PORTALLOCATOR_ENABLE_SHARED_UFRAG |
271 cricket::PORTALLOCATOR_ENABLE_SHARED_SOCKET); 252 cricket::PORTALLOCATOR_ENABLE_SHARED_SOCKET);
272 allocator().set_allow_tcp_listen(false); 253 allocator().set_allow_tcp_listen(false);
273 session_->StartGettingPorts(); 254 session_->StartGettingPorts();
274 EXPECT_TRUE_WAIT(candidate_allocation_done_, kDefaultAllocationTimeout); 255 EXPECT_TRUE_WAIT(candidate_allocation_done_, kDefaultAllocationTimeout);
275 256
276 uint32 total_candidates = 0; 257 uint32 total_candidates = 0;
277 if (!IPIsUnspec(stun_candidate_addr)) { 258 if (!stun_candidate_addr.IsNil()) {
278 ++total_candidates; 259 ++total_candidates;
279 EXPECT_PRED5(CheckCandidate, candidates_[0], 260 EXPECT_PRED5(CheckCandidate, candidates_[0],
280 cricket::ICE_CANDIDATE_COMPONENT_RTP, "stun", "udp", 261 cricket::ICE_CANDIDATE_COMPONENT_RTP, "stun", "udp",
281 rtc::SocketAddress(stun_candidate_addr, 0)); 262 rtc::SocketAddress(stun_candidate_addr, 0));
282 EXPECT_EQ( 263 EXPECT_EQ(
283 rtc::EmptySocketAddressWithFamily(candidates_[0].address().family()), 264 rtc::EmptySocketAddressWithFamily(candidates_[0].address().family()),
284 candidates_[0].related_address()); 265 candidates_[0].related_address());
285 } 266 }
286 if (!IPIsUnspec(relay_candidate_udp_transport_addr)) { 267 if (!relay_candidate_udp_transport_addr.IsNil()) {
287 ++total_candidates; 268 ++total_candidates;
288 EXPECT_PRED5(CheckCandidate, candidates_[1], 269 EXPECT_PRED5(CheckCandidate, candidates_[1],
289 cricket::ICE_CANDIDATE_COMPONENT_RTP, "relay", "udp", 270 cricket::ICE_CANDIDATE_COMPONENT_RTP, "relay", "udp",
290 rtc::SocketAddress(relay_candidate_udp_transport_addr, 0)); 271 rtc::SocketAddress(relay_candidate_udp_transport_addr, 0));
291 EXPECT_EQ(stun_candidate_addr, candidates_[1].related_address().ipaddr()); 272 EXPECT_EQ(stun_candidate_addr, candidates_[1].related_address().ipaddr());
292 } 273 }
293 if (!IPIsUnspec(relay_candidate_tcp_transport_addr)) { 274 if (!relay_candidate_tcp_transport_addr.IsNil()) {
294 ++total_candidates; 275 ++total_candidates;
295 EXPECT_PRED5(CheckCandidate, candidates_[2], 276 EXPECT_PRED5(CheckCandidate, candidates_[2],
296 cricket::ICE_CANDIDATE_COMPONENT_RTP, "relay", "udp", 277 cricket::ICE_CANDIDATE_COMPONENT_RTP, "relay", "udp",
297 rtc::SocketAddress(relay_candidate_tcp_transport_addr, 0)); 278 rtc::SocketAddress(relay_candidate_tcp_transport_addr, 0));
298 EXPECT_EQ(stun_candidate_addr, candidates_[2].related_address().ipaddr()); 279 EXPECT_EQ(stun_candidate_addr, candidates_[2].related_address().ipaddr());
299 } 280 }
300 281
301 EXPECT_EQ(total_candidates, candidates_.size()); 282 EXPECT_EQ(total_candidates, candidates_.size());
302 EXPECT_EQ(total_ports, ports_.size()); 283 EXPECT_EQ(total_ports, ports_.size());
303 } 284 }
(...skipping 23 matching lines...) Expand all
327 for (relay_port = server_config.ports.begin(); 308 for (relay_port = server_config.ports.begin();
328 relay_port != server_config.ports.end(); ++relay_port) { 309 relay_port != server_config.ports.end(); ++relay_port) {
329 if (proto_addr.address == relay_port->address && 310 if (proto_addr.address == relay_port->address &&
330 proto_addr.proto == relay_port->proto) 311 proto_addr.proto == relay_port->proto)
331 return true; 312 return true;
332 } 313 }
333 } 314 }
334 return false; 315 return false;
335 } 316 }
336 317
318 void ResetWithStunServer(const rtc::SocketAddress& stun_server,
319 bool with_nat) {
320 if (with_nat) {
321 nat_server_.reset(new rtc::NATServer(
322 rtc::NAT_OPEN_CONE, vss_.get(), kNatUdpAddr, kNatTcpAddr, vss_.get(),
323 rtc::SocketAddress(kNatUdpAddr.ipaddr(), 0)));
324 } else {
325 nat_socket_factory_.reset(new rtc::BasicPacketSocketFactory());
326 }
327
328 ServerAddresses stun_servers;
329 if (!stun_server.IsNil()) {
330 stun_servers.insert(stun_server);
331 }
332 allocator_.reset(new cricket::BasicPortAllocator(
333 &network_manager_, nat_socket_factory_.get(), stun_servers));
334 allocator().set_step_delay(cricket::kMinimumStepDelay);
335 }
336
337 rtc::scoped_ptr<rtc::PhysicalSocketServer> pss_; 337 rtc::scoped_ptr<rtc::PhysicalSocketServer> pss_;
338 rtc::scoped_ptr<rtc::VirtualSocketServer> vss_; 338 rtc::scoped_ptr<rtc::VirtualSocketServer> vss_;
339 rtc::scoped_ptr<rtc::FirewallSocketServer> fss_; 339 rtc::scoped_ptr<rtc::FirewallSocketServer> fss_;
340 rtc::SocketServerScope ss_scope_; 340 rtc::SocketServerScope ss_scope_;
341 rtc::scoped_ptr<rtc::NATServer> nat_server_; 341 rtc::scoped_ptr<rtc::NATServer> nat_server_;
342 rtc::NATSocketFactory nat_factory_; 342 rtc::NATSocketFactory nat_factory_;
343 rtc::scoped_ptr<rtc::BasicPacketSocketFactory> nat_socket_factory_; 343 rtc::scoped_ptr<rtc::BasicPacketSocketFactory> nat_socket_factory_;
344 rtc::scoped_ptr<cricket::TestStunServer> stun_server_; 344 rtc::scoped_ptr<cricket::TestStunServer> stun_server_;
345 cricket::TestRelayServer relay_server_; 345 cricket::TestRelayServer relay_server_;
346 cricket::TestTurnServer turn_server_; 346 cricket::TestTurnServer turn_server_;
(...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after
498 // Without network adapter, we should not get any candidate. 498 // Without network adapter, we should not get any candidate.
499 EXPECT_EQ(0U, candidates_.size()); 499 EXPECT_EQ(0U, candidates_.size());
500 EXPECT_TRUE(candidate_allocation_done_); 500 EXPECT_TRUE(candidate_allocation_done_);
501 } 501 }
502 502
503 // Test that we should only get STUN and TURN candidates when adapter 503 // Test that we should only get STUN and TURN candidates when adapter
504 // enumeration is disabled. 504 // enumeration is disabled.
505 TEST_F(PortAllocatorTest, TestDisableAdapterEnumerationBehindNat) { 505 TEST_F(PortAllocatorTest, TestDisableAdapterEnumerationBehindNat) {
506 AddInterface(kClientAddr); 506 AddInterface(kClientAddr);
507 // GTURN is not configured here. 507 // GTURN is not configured here.
508 ResetWithNatServer(kStunAddr); 508 ResetWithStunServerAndNat(kStunAddr);
509 AddTurnServers(kTurnUdpIntAddr, rtc::SocketAddress()); 509 AddTurnServers(kTurnUdpIntAddr, rtc::SocketAddress());
510 // Expect to see 3 ports: STUN, TURN/UDP and TCP ports, and both STUN and 510 // Expect to see 3 ports: STUN, TURN/UDP and TCP ports, and both STUN and
511 // TURN/UDP candidates. 511 // TURN/UDP candidates.
512 CheckDisableAdapterEnumeration(3U, kNatUdpAddr.ipaddr(), 512 CheckDisableAdapterEnumeration(3U, kNatUdpAddr.ipaddr(),
513 kTurnUdpExtAddr.ipaddr(), rtc::IPAddress()); 513 kTurnUdpExtAddr.ipaddr(), rtc::IPAddress());
514 } 514 }
515 515
516 // Test that even with multiple interfaces, the result should still be one STUN 516 // Test that even with multiple interfaces, the result should still be one STUN
517 // and one TURN candidate since we bind to any address (i.e. all 0s). 517 // and one TURN candidate since we bind to any address (i.e. all 0s).
518 TEST_F(PortAllocatorTest, 518 TEST_F(PortAllocatorTest,
519 TestDisableAdapterEnumerationBehindNatMultipleInterfaces) { 519 TestDisableAdapterEnumerationBehindNatMultipleInterfaces) {
520 AddInterface(kPrivateAddr); 520 AddInterface(kPrivateAddr);
521 AddInterface(kPrivateAddr2); 521 AddInterface(kPrivateAddr2);
522 ResetWithNatServer(kStunAddr); 522 ResetWithStunServerAndNat(kStunAddr);
523 AddTurnServers(kTurnUdpIntAddr, rtc::SocketAddress()); 523 AddTurnServers(kTurnUdpIntAddr, rtc::SocketAddress());
524 // Expect to see 3 ports: STUN, TURN/UDP and TCP ports, and both STUN and 524 // Expect to see 3 ports: STUN, TURN/UDP and TCP ports, and both STUN and
525 // TURN/UDP candidates. 525 // TURN/UDP candidates.
526 CheckDisableAdapterEnumeration(3U, kNatUdpAddr.ipaddr(), 526 CheckDisableAdapterEnumeration(3U, kNatUdpAddr.ipaddr(),
527 kTurnUdpExtAddr.ipaddr(), rtc::IPAddress()); 527 kTurnUdpExtAddr.ipaddr(), rtc::IPAddress());
528 } 528 }
529 529
530 // Test that we should get STUN, TURN/UDP and TURN/TCP candidates when a 530 // Test that we should get STUN, TURN/UDP and TURN/TCP candidates when a
531 // TURN/TCP server is specified. 531 // TURN/TCP server is specified.
532 TEST_F(PortAllocatorTest, TestDisableAdapterEnumerationBehindNatWithTcp) { 532 TEST_F(PortAllocatorTest, TestDisableAdapterEnumerationBehindNatWithTcp) {
533 turn_server_.AddInternalSocket(kTurnTcpIntAddr, cricket::PROTO_TCP); 533 turn_server_.AddInternalSocket(kTurnTcpIntAddr, cricket::PROTO_TCP);
534 AddInterface(kClientAddr); 534 AddInterface(kClientAddr);
535 // GTURN is not configured here. 535 // GTURN is not configured here.
536 ResetWithNatServer(kStunAddr); 536 ResetWithStunServerAndNat(kStunAddr);
537 AddTurnServers(kTurnUdpIntAddr, kTurnTcpIntAddr); 537 AddTurnServers(kTurnUdpIntAddr, kTurnTcpIntAddr);
538 // Expect to see 4 ports - STUN, TURN/UDP, TURN/TCP and TCP port. STUN, 538 // Expect to see 4 ports - STUN, TURN/UDP, TURN/TCP and TCP port. STUN,
539 // TURN/UDP, and TURN/TCP candidates. 539 // TURN/UDP, and TURN/TCP candidates.
540 CheckDisableAdapterEnumeration(4U, kNatUdpAddr.ipaddr(), 540 CheckDisableAdapterEnumeration(4U, kNatUdpAddr.ipaddr(),
541 kTurnUdpExtAddr.ipaddr(), 541 kTurnUdpExtAddr.ipaddr(),
542 kTurnUdpExtAddr.ipaddr()); 542 kTurnUdpExtAddr.ipaddr());
543 } 543 }
544 544
545 // Test that we should only get STUN and TURN candidates when adapter 545 // Test that we should only get STUN and TURN candidates when adapter
546 // enumeration is disabled. Since the endpoint is not behind NAT, the srflx 546 // enumeration is disabled. Since the endpoint is not behind NAT, the srflx
547 // address should be the public client interface. 547 // address should be the public client interface.
548 TEST_F(PortAllocatorTest, TestDisableAdapterEnumerationWithoutNat) { 548 TEST_F(PortAllocatorTest, TestDisableAdapterEnumerationWithoutNat) {
549 AddInterfaceAsDefaultRoute(kClientAddr); 549 AddInterfaceAsDefaultRoute(kClientAddr);
550 ResetWithStunServer(kStunAddr); 550 ResetWithStunServerNoNat(kStunAddr);
551 AddTurnServers(kTurnUdpIntAddr, rtc::SocketAddress()); 551 AddTurnServers(kTurnUdpIntAddr, rtc::SocketAddress());
552 // Expect to see 3 ports: STUN, TURN/UDP and TCP ports, but only both STUN and 552 // Expect to see 3 ports: STUN, TURN/UDP and TCP ports, but only both STUN and
553 // TURN candidates. The STUN candidate should have kClientAddr as srflx 553 // TURN candidates. The STUN candidate should have kClientAddr as srflx
554 // address, and TURN candidate with kClientAddr as the related address. 554 // address, and TURN candidate with kClientAddr as the related address.
555 CheckDisableAdapterEnumeration(3U, kClientAddr.ipaddr(), 555 CheckDisableAdapterEnumeration(3U, kClientAddr.ipaddr(),
556 kTurnUdpExtAddr.ipaddr(), rtc::IPAddress()); 556 kTurnUdpExtAddr.ipaddr(), rtc::IPAddress());
557 } 557 }
558 558
559 // Test that when adapter enumeration is disabled, for endpoints without 559 // Test that when adapter enumeration is disabled, for endpoints without
560 // STUN/TURN specified, no candidate is generated. 560 // STUN/TURN specified, no candidate is generated.
561 TEST_F(PortAllocatorTest, TestDisableAdapterEnumerationWithoutNatOrServers) { 561 TEST_F(PortAllocatorTest, TestDisableAdapterEnumerationWithoutNatOrServers) {
562 AddInterfaceAsDefaultRoute(kClientAddr); 562 AddInterfaceAsDefaultRoute(kClientAddr);
563 ResetWithNoServers(); 563 ResetWithNoServersOrNat();
564 // Expect to see 2 ports: STUN and TCP ports, but no candidate. 564 // Expect to see 2 ports: STUN and TCP ports, but no candidate.
565 CheckDisableAdapterEnumeration(2U, rtc::IPAddress(), rtc::IPAddress(), 565 CheckDisableAdapterEnumeration(2U, rtc::IPAddress(), rtc::IPAddress(),
566 rtc::IPAddress()); 566 rtc::IPAddress());
567 } 567 }
568 568
569 // Disable for asan, see 569 // Disable for asan, see
570 // https://code.google.com/p/webrtc/issues/detail?id=4743 for details. 570 // https://code.google.com/p/webrtc/issues/detail?id=4743 for details.
571 #if !defined(ADDRESS_SANITIZER) 571 #if !defined(ADDRESS_SANITIZER)
572 572
573 // Test that we can get OnCandidatesAllocationDone callback when all the ports 573 // Test that we can get OnCandidatesAllocationDone callback when all the ports
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after
705 } 705 }
706 706
707 // Test ICE candidate filter mechanism with options Relay/Host/Reflexive. 707 // Test ICE candidate filter mechanism with options Relay/Host/Reflexive.
708 // This test also verifies that when the allocator is only allowed to use 708 // This test also verifies that when the allocator is only allowed to use
709 // relay (i.e. IceTransportsType is relay), the raddr is an empty 709 // relay (i.e. IceTransportsType is relay), the raddr is an empty
710 // address with the correct family. This is to prevent any local 710 // address with the correct family. This is to prevent any local
711 // reflective address leakage in the sdp line. 711 // reflective address leakage in the sdp line.
712 TEST_F(PortAllocatorTest, TestCandidateFilterWithRelayOnly) { 712 TEST_F(PortAllocatorTest, TestCandidateFilterWithRelayOnly) {
713 AddInterface(kClientAddr); 713 AddInterface(kClientAddr);
714 // GTURN is not configured here. 714 // GTURN is not configured here.
715 ResetWithTurnServers(kTurnUdpIntAddr, rtc::SocketAddress()); 715 ResetWithTurnServersNoNat(kTurnUdpIntAddr, rtc::SocketAddress());
716 allocator().set_candidate_filter(cricket::CF_RELAY); 716 allocator().set_candidate_filter(cricket::CF_RELAY);
717 EXPECT_TRUE(CreateSession(cricket::ICE_CANDIDATE_COMPONENT_RTP)); 717 EXPECT_TRUE(CreateSession(cricket::ICE_CANDIDATE_COMPONENT_RTP));
718 session_->StartGettingPorts(); 718 session_->StartGettingPorts();
719 EXPECT_TRUE_WAIT(candidate_allocation_done_, kDefaultAllocationTimeout); 719 EXPECT_TRUE_WAIT(candidate_allocation_done_, kDefaultAllocationTimeout);
720 EXPECT_PRED5(CheckCandidate, 720 EXPECT_PRED5(CheckCandidate,
721 candidates_[0], 721 candidates_[0],
722 cricket::ICE_CANDIDATE_COMPONENT_RTP, 722 cricket::ICE_CANDIDATE_COMPONENT_RTP,
723 "relay", 723 "relay",
724 "udp", 724 "udp",
725 rtc::SocketAddress(kTurnUdpExtAddr.ipaddr(), 0)); 725 rtc::SocketAddress(kTurnUdpExtAddr.ipaddr(), 0));
(...skipping 19 matching lines...) Expand all
745 EXPECT_EQ(2U, candidates_.size()); // Host UDP/TCP candidates only. 745 EXPECT_EQ(2U, candidates_.size()); // Host UDP/TCP candidates only.
746 EXPECT_EQ(2U, ports_.size()); // UDP/TCP ports only. 746 EXPECT_EQ(2U, ports_.size()); // UDP/TCP ports only.
747 for (size_t i = 0; i < candidates_.size(); ++i) { 747 for (size_t i = 0; i < candidates_.size(); ++i) {
748 EXPECT_EQ(std::string(cricket::LOCAL_PORT_TYPE), candidates_[i].type()); 748 EXPECT_EQ(std::string(cricket::LOCAL_PORT_TYPE), candidates_[i].type());
749 } 749 }
750 } 750 }
751 751
752 // Host is behind the NAT. 752 // Host is behind the NAT.
753 TEST_F(PortAllocatorTest, TestCandidateFilterWithReflexiveOnly) { 753 TEST_F(PortAllocatorTest, TestCandidateFilterWithReflexiveOnly) {
754 AddInterface(kPrivateAddr); 754 AddInterface(kPrivateAddr);
755 ResetWithNatServer(kStunAddr); 755 ResetWithStunServerAndNat(kStunAddr);
756 756
757 allocator().set_flags(cricket::PORTALLOCATOR_ENABLE_SHARED_UFRAG | 757 allocator().set_flags(cricket::PORTALLOCATOR_ENABLE_SHARED_UFRAG |
758 cricket::PORTALLOCATOR_ENABLE_SHARED_SOCKET); 758 cricket::PORTALLOCATOR_ENABLE_SHARED_SOCKET);
759 allocator().set_candidate_filter(cricket::CF_REFLEXIVE); 759 allocator().set_candidate_filter(cricket::CF_REFLEXIVE);
760 EXPECT_TRUE(CreateSession(cricket::ICE_CANDIDATE_COMPONENT_RTP)); 760 EXPECT_TRUE(CreateSession(cricket::ICE_CANDIDATE_COMPONENT_RTP));
761 session_->StartGettingPorts(); 761 session_->StartGettingPorts();
762 EXPECT_TRUE_WAIT(candidate_allocation_done_, kDefaultAllocationTimeout); 762 EXPECT_TRUE_WAIT(candidate_allocation_done_, kDefaultAllocationTimeout);
763 // Host is behind NAT, no private address will be exposed. Hence only UDP 763 // Host is behind NAT, no private address will be exposed. Hence only UDP
764 // port with STUN candidate will be sent outside. 764 // port with STUN candidate will be sent outside.
765 EXPECT_EQ(1U, candidates_.size()); // Only STUN candidate. 765 EXPECT_EQ(1U, candidates_.size()); // Only STUN candidate.
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
853 EXPECT_PRED5(CheckCandidate, candidates_[0], 853 EXPECT_PRED5(CheckCandidate, candidates_[0],
854 cricket::ICE_CANDIDATE_COMPONENT_RTP, "local", "udp", kClientAddr); 854 cricket::ICE_CANDIDATE_COMPONENT_RTP, "local", "udp", kClientAddr);
855 EXPECT_TRUE_WAIT(candidate_allocation_done_, kDefaultAllocationTimeout); 855 EXPECT_TRUE_WAIT(candidate_allocation_done_, kDefaultAllocationTimeout);
856 } 856 }
857 857
858 // Test that when PORTALLOCATOR_ENABLE_SHARED_SOCKET is enabled only one port 858 // Test that when PORTALLOCATOR_ENABLE_SHARED_SOCKET is enabled only one port
859 // is allocated for udp and stun. In this test we should expect both stun and 859 // is allocated for udp and stun. In this test we should expect both stun and
860 // local candidates as client behind a nat. 860 // local candidates as client behind a nat.
861 TEST_F(PortAllocatorTest, TestSharedSocketWithNat) { 861 TEST_F(PortAllocatorTest, TestSharedSocketWithNat) {
862 AddInterface(kClientAddr); 862 AddInterface(kClientAddr);
863 ResetWithNatServer(kStunAddr); 863 ResetWithStunServerAndNat(kStunAddr);
864 864
865 allocator_->set_flags(allocator().flags() | 865 allocator_->set_flags(allocator().flags() |
866 cricket::PORTALLOCATOR_ENABLE_SHARED_UFRAG | 866 cricket::PORTALLOCATOR_ENABLE_SHARED_UFRAG |
867 cricket::PORTALLOCATOR_ENABLE_SHARED_SOCKET); 867 cricket::PORTALLOCATOR_ENABLE_SHARED_SOCKET);
868 EXPECT_TRUE(CreateSession(cricket::ICE_CANDIDATE_COMPONENT_RTP)); 868 EXPECT_TRUE(CreateSession(cricket::ICE_CANDIDATE_COMPONENT_RTP));
869 session_->StartGettingPorts(); 869 session_->StartGettingPorts();
870 ASSERT_EQ_WAIT(3U, candidates_.size(), kDefaultAllocationTimeout); 870 ASSERT_EQ_WAIT(3U, candidates_.size(), kDefaultAllocationTimeout);
871 ASSERT_EQ(2U, ports_.size()); 871 ASSERT_EQ(2U, ports_.size());
872 EXPECT_PRED5(CheckCandidate, candidates_[0], 872 EXPECT_PRED5(CheckCandidate, candidates_[0],
873 cricket::ICE_CANDIDATE_COMPONENT_RTP, "local", "udp", kClientAddr); 873 cricket::ICE_CANDIDATE_COMPONENT_RTP, "local", "udp", kClientAddr);
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
934 session_->StartGettingPorts(); 934 session_->StartGettingPorts();
935 935
936 EXPECT_EQ_WAIT(2U, ports_.size(), kDefaultAllocationTimeout); 936 EXPECT_EQ_WAIT(2U, ports_.size(), kDefaultAllocationTimeout);
937 } 937 }
938 938
939 // Test that when PORTALLOCATOR_ENABLE_SHARED_SOCKET is enabled only one port 939 // Test that when PORTALLOCATOR_ENABLE_SHARED_SOCKET is enabled only one port
940 // is allocated for udp/stun/turn. In this test we should expect all local, 940 // is allocated for udp/stun/turn. In this test we should expect all local,
941 // stun and turn candidates. 941 // stun and turn candidates.
942 TEST_F(PortAllocatorTest, TestSharedSocketWithNatUsingTurn) { 942 TEST_F(PortAllocatorTest, TestSharedSocketWithNatUsingTurn) {
943 AddInterface(kClientAddr); 943 AddInterface(kClientAddr);
944 ResetWithNatServer(kStunAddr); 944 ResetWithStunServerAndNat(kStunAddr);
945 945
946 AddTurnServers(kTurnUdpIntAddr, rtc::SocketAddress()); 946 AddTurnServers(kTurnUdpIntAddr, rtc::SocketAddress());
947 947
948 allocator_->set_flags(allocator().flags() | 948 allocator_->set_flags(allocator().flags() |
949 cricket::PORTALLOCATOR_ENABLE_SHARED_UFRAG | 949 cricket::PORTALLOCATOR_ENABLE_SHARED_UFRAG |
950 cricket::PORTALLOCATOR_ENABLE_SHARED_SOCKET | 950 cricket::PORTALLOCATOR_ENABLE_SHARED_SOCKET |
951 cricket::PORTALLOCATOR_DISABLE_TCP); 951 cricket::PORTALLOCATOR_DISABLE_TCP);
952 952
953 EXPECT_TRUE(CreateSession(cricket::ICE_CANDIDATE_COMPONENT_RTP)); 953 EXPECT_TRUE(CreateSession(cricket::ICE_CANDIDATE_COMPONENT_RTP));
954 session_->StartGettingPorts(); 954 session_->StartGettingPorts();
(...skipping 14 matching lines...) Expand all
969 EXPECT_EQ(2U, ports_[0]->Candidates().size()); 969 EXPECT_EQ(2U, ports_[0]->Candidates().size());
970 EXPECT_EQ(1U, ports_[1]->Candidates().size()); 970 EXPECT_EQ(1U, ports_[1]->Candidates().size());
971 } 971 }
972 972
973 // Test that when PORTALLOCATOR_ENABLE_SHARED_SOCKET is enabled and the TURN 973 // Test that when PORTALLOCATOR_ENABLE_SHARED_SOCKET is enabled and the TURN
974 // server is also used as the STUN server, we should get 'local', 'stun', and 974 // server is also used as the STUN server, we should get 'local', 'stun', and
975 // 'relay' candidates. 975 // 'relay' candidates.
976 TEST_F(PortAllocatorTest, TestSharedSocketWithNatUsingTurnAsStun) { 976 TEST_F(PortAllocatorTest, TestSharedSocketWithNatUsingTurnAsStun) {
977 AddInterface(kClientAddr); 977 AddInterface(kClientAddr);
978 // Use an empty SocketAddress to add a NAT without STUN server. 978 // Use an empty SocketAddress to add a NAT without STUN server.
979 ResetWithNatServer(SocketAddress()); 979 ResetWithStunServerAndNat(SocketAddress());
980 AddTurnServers(kTurnUdpIntAddr, rtc::SocketAddress()); 980 AddTurnServers(kTurnUdpIntAddr, rtc::SocketAddress());
981 981
982 // Must set the step delay to 0 to make sure the relay allocation phase is 982 // Must set the step delay to 0 to make sure the relay allocation phase is
983 // started before the STUN candidates are obtained, so that the STUN binding 983 // started before the STUN candidates are obtained, so that the STUN binding
984 // response is processed when both StunPort and TurnPort exist to reproduce 984 // response is processed when both StunPort and TurnPort exist to reproduce
985 // webrtc issue 3537. 985 // webrtc issue 3537.
986 allocator_->set_step_delay(0); 986 allocator_->set_step_delay(0);
987 allocator_->set_flags(allocator().flags() | 987 allocator_->set_flags(allocator().flags() |
988 cricket::PORTALLOCATOR_ENABLE_SHARED_UFRAG | 988 cricket::PORTALLOCATOR_ENABLE_SHARED_UFRAG |
989 cricket::PORTALLOCATOR_ENABLE_SHARED_SOCKET | 989 cricket::PORTALLOCATOR_ENABLE_SHARED_SOCKET |
(...skipping 19 matching lines...) Expand all
1009 EXPECT_EQ(2U, ports_[0]->Candidates().size()); 1009 EXPECT_EQ(2U, ports_[0]->Candidates().size());
1010 EXPECT_EQ(1U, ports_[1]->Candidates().size()); 1010 EXPECT_EQ(1U, ports_[1]->Candidates().size());
1011 } 1011 }
1012 1012
1013 // Test that when only a TCP TURN server is available, we do NOT use it as 1013 // Test that when only a TCP TURN server is available, we do NOT use it as
1014 // a UDP STUN server, as this could leak our IP address. Thus we should only 1014 // a UDP STUN server, as this could leak our IP address. Thus we should only
1015 // expect two ports, a UDPPort and TurnPort. 1015 // expect two ports, a UDPPort and TurnPort.
1016 TEST_F(PortAllocatorTest, TestSharedSocketWithNatUsingTurnTcpOnly) { 1016 TEST_F(PortAllocatorTest, TestSharedSocketWithNatUsingTurnTcpOnly) {
1017 turn_server_.AddInternalSocket(kTurnTcpIntAddr, cricket::PROTO_TCP); 1017 turn_server_.AddInternalSocket(kTurnTcpIntAddr, cricket::PROTO_TCP);
1018 AddInterface(kClientAddr); 1018 AddInterface(kClientAddr);
1019 ResetWithNatServer(rtc::SocketAddress()); 1019 ResetWithStunServerAndNat(rtc::SocketAddress());
1020 AddTurnServers(rtc::SocketAddress(), kTurnTcpIntAddr); 1020 AddTurnServers(rtc::SocketAddress(), kTurnTcpIntAddr);
1021 1021
1022 allocator_->set_flags(allocator().flags() | 1022 allocator_->set_flags(allocator().flags() |
1023 cricket::PORTALLOCATOR_ENABLE_SHARED_UFRAG | 1023 cricket::PORTALLOCATOR_ENABLE_SHARED_UFRAG |
1024 cricket::PORTALLOCATOR_ENABLE_SHARED_SOCKET | 1024 cricket::PORTALLOCATOR_ENABLE_SHARED_SOCKET |
1025 cricket::PORTALLOCATOR_DISABLE_TCP); 1025 cricket::PORTALLOCATOR_DISABLE_TCP);
1026 1026
1027 EXPECT_TRUE(CreateSession(cricket::ICE_CANDIDATE_COMPONENT_RTP)); 1027 EXPECT_TRUE(CreateSession(cricket::ICE_CANDIDATE_COMPONENT_RTP));
1028 session_->StartGettingPorts(); 1028 session_->StartGettingPorts();
1029 1029
(...skipping 12 matching lines...) Expand all
1042 } 1042 }
1043 1043
1044 // Test that even when PORTALLOCATOR_ENABLE_SHARED_SOCKET is NOT enabled, the 1044 // Test that even when PORTALLOCATOR_ENABLE_SHARED_SOCKET is NOT enabled, the
1045 // TURN server is used as the STUN server and we get 'local', 'stun', and 1045 // TURN server is used as the STUN server and we get 'local', 'stun', and
1046 // 'relay' candidates. 1046 // 'relay' candidates.
1047 // TODO(deadbeef): Remove this test when support for non-shared socket mode 1047 // TODO(deadbeef): Remove this test when support for non-shared socket mode
1048 // is removed. 1048 // is removed.
1049 TEST_F(PortAllocatorTest, TestNonSharedSocketWithNatUsingTurnAsStun) { 1049 TEST_F(PortAllocatorTest, TestNonSharedSocketWithNatUsingTurnAsStun) {
1050 AddInterface(kClientAddr); 1050 AddInterface(kClientAddr);
1051 // Use an empty SocketAddress to add a NAT without STUN server. 1051 // Use an empty SocketAddress to add a NAT without STUN server.
1052 ResetWithNatServer(SocketAddress()); 1052 ResetWithStunServerAndNat(SocketAddress());
1053 AddTurnServers(kTurnUdpIntAddr, rtc::SocketAddress()); 1053 AddTurnServers(kTurnUdpIntAddr, rtc::SocketAddress());
1054 1054
1055 allocator_->set_flags(allocator().flags() | 1055 allocator_->set_flags(allocator().flags() |
1056 cricket::PORTALLOCATOR_ENABLE_SHARED_UFRAG | 1056 cricket::PORTALLOCATOR_ENABLE_SHARED_UFRAG |
1057 cricket::PORTALLOCATOR_DISABLE_TCP); 1057 cricket::PORTALLOCATOR_DISABLE_TCP);
1058 1058
1059 EXPECT_TRUE(CreateSession(cricket::ICE_CANDIDATE_COMPONENT_RTP)); 1059 EXPECT_TRUE(CreateSession(cricket::ICE_CANDIDATE_COMPONENT_RTP));
1060 session_->StartGettingPorts(); 1060 session_->StartGettingPorts();
1061 1061
1062 ASSERT_EQ_WAIT(3U, candidates_.size(), kDefaultAllocationTimeout); 1062 ASSERT_EQ_WAIT(3U, candidates_.size(), kDefaultAllocationTimeout);
(...skipping 17 matching lines...) Expand all
1080 EXPECT_EQ(1U, ports_[1]->Candidates().size()); 1080 EXPECT_EQ(1U, ports_[1]->Candidates().size());
1081 EXPECT_EQ(1U, ports_[2]->Candidates().size()); 1081 EXPECT_EQ(1U, ports_[2]->Candidates().size());
1082 } 1082 }
1083 1083
1084 // Test that even when both a STUN and TURN server are configured, the TURN 1084 // Test that even when both a STUN and TURN server are configured, the TURN
1085 // server is used as a STUN server and we get a 'stun' candidate. 1085 // server is used as a STUN server and we get a 'stun' candidate.
1086 TEST_F(PortAllocatorTest, TestSharedSocketWithNatUsingTurnAndStun) { 1086 TEST_F(PortAllocatorTest, TestSharedSocketWithNatUsingTurnAndStun) {
1087 AddInterface(kClientAddr); 1087 AddInterface(kClientAddr);
1088 // Configure with STUN server but destroy it, so we can ensure that it's 1088 // Configure with STUN server but destroy it, so we can ensure that it's
1089 // the TURN server actually being used as a STUN server. 1089 // the TURN server actually being used as a STUN server.
1090 ResetWithNatServer(kStunAddr); 1090 ResetWithStunServerAndNat(kStunAddr);
1091 stun_server_.reset(); 1091 stun_server_.reset();
1092 AddTurnServers(kTurnUdpIntAddr, rtc::SocketAddress()); 1092 AddTurnServers(kTurnUdpIntAddr, rtc::SocketAddress());
1093 1093
1094 allocator_->set_flags(allocator().flags() | 1094 allocator_->set_flags(allocator().flags() |
1095 cricket::PORTALLOCATOR_ENABLE_SHARED_UFRAG | 1095 cricket::PORTALLOCATOR_ENABLE_SHARED_UFRAG |
1096 cricket::PORTALLOCATOR_ENABLE_SHARED_SOCKET | 1096 cricket::PORTALLOCATOR_ENABLE_SHARED_SOCKET |
1097 cricket::PORTALLOCATOR_DISABLE_TCP); 1097 cricket::PORTALLOCATOR_DISABLE_TCP);
1098 1098
1099 EXPECT_TRUE(CreateSession(cricket::ICE_CANDIDATE_COMPONENT_RTP)); 1099 EXPECT_TRUE(CreateSession(cricket::ICE_CANDIDATE_COMPONENT_RTP));
1100 session_->StartGettingPorts(); 1100 session_->StartGettingPorts();
(...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after
1275 AllocationSequenceForTest alloc_sequence( 1275 AllocationSequenceForTest alloc_sequence(
1276 static_cast<cricket::BasicPortAllocatorSession*>(session_.get()), 1276 static_cast<cricket::BasicPortAllocatorSession*>(session_.get()),
1277 &network1, &config, flag); 1277 &network1, &config, flag);
1278 // This simply tests it will not crash if udp_socket_ in the 1278 // This simply tests it will not crash if udp_socket_ in the
1279 // AllocationSequence is null, which is chosen in the constructor. 1279 // AllocationSequence is null, which is chosen in the constructor.
1280 cricket::RelayServerConfig relay_server(cricket::RELAY_TURN); 1280 cricket::RelayServerConfig relay_server(cricket::RELAY_TURN);
1281 relay_server.ports.push_back( 1281 relay_server.ports.push_back(
1282 cricket::ProtocolAddress(kTurnUdpIntAddr, cricket::PROTO_UDP, false)); 1282 cricket::ProtocolAddress(kTurnUdpIntAddr, cricket::PROTO_UDP, false));
1283 alloc_sequence.CreateTurnPort(relay_server); 1283 alloc_sequence.CreateTurnPort(relay_server);
1284 } 1284 }
OLDNEW
« no previous file with comments | « webrtc/base/ipaddress_unittest.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698