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 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
103 allocator_.reset(new cricket::BasicPortAllocator( | 103 allocator_.reset(new cricket::BasicPortAllocator( |
104 &network_manager_, | 104 &network_manager_, |
105 stun_servers, | 105 stun_servers, |
106 kRelayUdpIntAddr, kRelayTcpIntAddr, kRelaySslTcpIntAddr)); | 106 kRelayUdpIntAddr, kRelayTcpIntAddr, kRelaySslTcpIntAddr)); |
107 allocator_->set_step_delay(cricket::kMinimumStepDelay); | 107 allocator_->set_step_delay(cricket::kMinimumStepDelay); |
108 } | 108 } |
109 | 109 |
110 void AddInterface(const SocketAddress& addr) { | 110 void AddInterface(const SocketAddress& addr) { |
111 network_manager_.AddInterface(addr); | 111 network_manager_.AddInterface(addr); |
112 } | 112 } |
113 void AddInterfaceAsDefaultRoute(const SocketAddress& addr) { | |
114 AddInterface(addr); | |
115 // When a binding comes from the any address, the |addr| will be used as the | |
116 // srflx address. | |
117 vss_->SetDefaultRoute(addr.ipaddr()); | |
118 } | |
113 bool SetPortRange(int min_port, int max_port) { | 119 bool SetPortRange(int min_port, int max_port) { |
114 return allocator_->SetPortRange(min_port, max_port); | 120 return allocator_->SetPortRange(min_port, max_port); |
115 } | 121 } |
122 // No STUN/TURN configuration. | |
123 void ResetWithNoServers() { | |
124 allocator_.reset(new cricket::BasicPortAllocator(&network_manager_)); | |
125 allocator_->set_step_delay(cricket::kMinimumStepDelay); | |
126 } | |
116 void ResetWithNatServer(const rtc::SocketAddress& stun_server) { | 127 void ResetWithNatServer(const rtc::SocketAddress& stun_server) { |
117 nat_server_.reset(new rtc::NATServer( | 128 nat_server_.reset(new rtc::NATServer( |
118 rtc::NAT_OPEN_CONE, vss_.get(), kNatUdpAddr, kNatTcpAddr, vss_.get(), | 129 rtc::NAT_OPEN_CONE, vss_.get(), kNatUdpAddr, kNatTcpAddr, vss_.get(), |
119 rtc::SocketAddress(kNatUdpAddr.ipaddr(), 0))); | 130 rtc::SocketAddress(kNatUdpAddr.ipaddr(), 0))); |
120 | 131 |
121 ServerAddresses stun_servers; | 132 ServerAddresses stun_servers; |
122 if (!stun_server.IsNil()) { | 133 if (!stun_server.IsNil()) { |
123 stun_servers.insert(stun_server); | 134 stun_servers.insert(stun_server); |
124 } | 135 } |
125 allocator_.reset(new cricket::BasicPortAllocator( | 136 allocator_.reset(new cricket::BasicPortAllocator( |
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
227 } else { | 238 } else { |
228 EXPECT_EQ(0, (*it)->GetOption(rtc::Socket::OPT_SNDBUF, | 239 EXPECT_EQ(0, (*it)->GetOption(rtc::Socket::OPT_SNDBUF, |
229 &send_buffer_size)); | 240 &send_buffer_size)); |
230 ASSERT_EQ(expected, send_buffer_size); | 241 ASSERT_EQ(expected, send_buffer_size); |
231 } | 242 } |
232 } | 243 } |
233 } | 244 } |
234 | 245 |
235 void CheckDisableAdapterEnumeration() { | 246 void CheckDisableAdapterEnumeration() { |
236 EXPECT_TRUE(CreateSession(cricket::ICE_CANDIDATE_COMPONENT_RTP)); | 247 EXPECT_TRUE(CreateSession(cricket::ICE_CANDIDATE_COMPONENT_RTP)); |
237 session_->set_flags(cricket::PORTALLOCATOR_DISABLE_ADAPTER_ENUMERATION); | 248 session_->set_flags(cricket::PORTALLOCATOR_DISABLE_ADAPTER_ENUMERATION | |
249 cricket::PORTALLOCATOR_ENABLE_SHARED_UFRAG | | |
250 cricket::PORTALLOCATOR_ENABLE_SHARED_SOCKET); | |
238 session_->StartGettingPorts(); | 251 session_->StartGettingPorts(); |
239 EXPECT_TRUE_WAIT(candidate_allocation_done_, kDefaultAllocationTimeout); | 252 EXPECT_TRUE_WAIT(candidate_allocation_done_, kDefaultAllocationTimeout); |
240 | 253 |
241 // Only 2 candidates as local UDP/TCP are all 0s and get trimmed out. | 254 // Only 2 candidates as local UDP/TCP are all 0s and get trimmed out. |
242 EXPECT_EQ(2U, candidates_.size()); | 255 EXPECT_EQ(2U, candidates_.size()); |
243 EXPECT_EQ(2U, ports_.size()); // One stunport and one turnport. | 256 EXPECT_EQ(2U, ports_.size()); // One stunport and one turnport. |
244 | 257 |
245 EXPECT_PRED5(CheckCandidate, candidates_[0], | 258 EXPECT_PRED5(CheckCandidate, candidates_[0], |
246 cricket::ICE_CANDIDATE_COMPONENT_RTP, "stun", "udp", | 259 cricket::ICE_CANDIDATE_COMPONENT_RTP, "stun", "udp", |
247 rtc::SocketAddress(kNatUdpAddr.ipaddr(), 0)); | 260 rtc::SocketAddress(kNatUdpAddr.ipaddr(), 0)); |
(...skipping 200 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
448 EXPECT_TRUE(CreateSession(cricket::ICE_CANDIDATE_COMPONENT_RTP)); | 461 EXPECT_TRUE(CreateSession(cricket::ICE_CANDIDATE_COMPONENT_RTP)); |
449 session_->StartGettingPorts(); | 462 session_->StartGettingPorts(); |
450 rtc::Thread::Current()->ProcessMessages(100); | 463 rtc::Thread::Current()->ProcessMessages(100); |
451 // Without network adapter, we should not get any candidate. | 464 // Without network adapter, we should not get any candidate. |
452 EXPECT_EQ(0U, candidates_.size()); | 465 EXPECT_EQ(0U, candidates_.size()); |
453 EXPECT_TRUE(candidate_allocation_done_); | 466 EXPECT_TRUE(candidate_allocation_done_); |
454 } | 467 } |
455 | 468 |
456 // Test that we should only get STUN and TURN candidates when adapter | 469 // Test that we should only get STUN and TURN candidates when adapter |
457 // enumeration is disabled. | 470 // enumeration is disabled. |
458 TEST_F(PortAllocatorTest, TestDisableAdapterEnumeration) { | 471 TEST_F(PortAllocatorTest, TestDisableAdapterEnumerationBehindNat) { |
459 AddInterface(kClientAddr); | 472 AddInterface(kClientAddr); |
460 // GTURN is not configured here. | 473 // GTURN is not configured here. |
461 ResetWithNatServer(kStunAddr); | 474 ResetWithNatServer(kStunAddr); |
462 AddTurnServers(kTurnUdpIntAddr, rtc::SocketAddress()); | 475 AddTurnServers(kTurnUdpIntAddr, rtc::SocketAddress()); |
463 | 476 |
464 CheckDisableAdapterEnumeration(); | 477 CheckDisableAdapterEnumeration(); |
465 } | 478 } |
466 | 479 |
467 // Test that even with multiple interfaces, the result should be only 1 Stun | 480 // Test that even with multiple interfaces, the result should be only 1 Stun |
468 // candidate since we bind to any address (i.e. all 0s). | 481 // candidate since we bind to any address (i.e. all 0s). |
469 TEST_F(PortAllocatorTest, TestDisableAdapterEnumerationMultipleInterfaces) { | 482 TEST_F(PortAllocatorTest, TestDisableAdapterEnumerationMultipleInterfaces) { |
juberti1
2015/08/06 23:43:21
TestDisableAdapterEnumerationBehindNatMultipleInte
guoweis_webrtc
2015/08/07 18:03:43
Done.
| |
470 AddInterface(kPrivateAddr); | 483 AddInterface(kPrivateAddr); |
471 AddInterface(kPrivateAddr2); | 484 AddInterface(kPrivateAddr2); |
472 ResetWithNatServer(kStunAddr); | 485 ResetWithNatServer(kStunAddr); |
473 AddTurnServers(kTurnUdpIntAddr, rtc::SocketAddress()); | 486 AddTurnServers(kTurnUdpIntAddr, rtc::SocketAddress()); |
474 | 487 |
475 CheckDisableAdapterEnumeration(); | 488 CheckDisableAdapterEnumeration(); |
476 } | 489 } |
477 | 490 |
491 // Test that when adapter enumeration is disabled, STUN is the only candidate | |
492 // for endpoints not behind a NAT. | |
493 TEST_F(PortAllocatorTest, TestDisableAdapterEnumerationWithoutNat) { | |
juberti1
2015/08/06 23:43:21
can we just parameterize CheckDisableAdapterEnumer
| |
494 AddInterfaceAsDefaultRoute(kClientAddr); | |
495 allocator_->set_flags(allocator().flags() | | |
496 cricket::PORTALLOCATOR_ENABLE_SHARED_UFRAG | | |
497 cricket::PORTALLOCATOR_DISABLE_ADAPTER_ENUMERATION | | |
juberti1
2015/08/06 23:43:21
since we have no turn servers, why do we need to d
| |
498 cricket::PORTALLOCATOR_DISABLE_RELAY | | |
499 cricket::PORTALLOCATOR_DISABLE_TCP | | |
500 cricket::PORTALLOCATOR_ENABLE_SHARED_SOCKET); | |
501 EXPECT_TRUE(CreateSession(cricket::ICE_CANDIDATE_COMPONENT_RTP)); | |
502 session_->StartGettingPorts(); | |
503 EXPECT_TRUE_WAIT(1U == ports_.size(), kDefaultAllocationTimeout); | |
504 ASSERT_EQ_WAIT(1U, candidates_.size(), kDefaultAllocationTimeout); | |
505 EXPECT_PRED5(CheckCandidate, candidates_[0], | |
506 cricket::ICE_CANDIDATE_COMPONENT_RTP, "stun", "udp", | |
507 kClientAddr); | |
508 EXPECT_TRUE_WAIT(candidate_allocation_done_, kDefaultAllocationTimeout); | |
509 } | |
510 | |
511 // Test that when adapter enumeration is disabled, for endpoints without | |
512 // STUN/TURN specified, no candidate is generated. | |
513 TEST_F(PortAllocatorTest, TestDisableAdapterEnumerationWithoutNat_NoCandidate) { | |
juberti1
2015/08/06 23:43:21
see above
| |
514 AddInterfaceAsDefaultRoute(kClientAddr); | |
515 ResetWithNoServers(); | |
516 allocator_->set_flags(allocator().flags() | | |
517 cricket::PORTALLOCATOR_ENABLE_SHARED_UFRAG | | |
518 cricket::PORTALLOCATOR_DISABLE_ADAPTER_ENUMERATION | | |
519 cricket::PORTALLOCATOR_DISABLE_RELAY | | |
520 cricket::PORTALLOCATOR_DISABLE_TCP | | |
521 cricket::PORTALLOCATOR_ENABLE_SHARED_SOCKET); | |
522 EXPECT_TRUE(CreateSession(cricket::ICE_CANDIDATE_COMPONENT_RTP)); | |
523 session_->StartGettingPorts(); | |
524 EXPECT_TRUE_WAIT(1U == ports_.size(), kDefaultAllocationTimeout); | |
525 EXPECT_EQ(candidates_.size(), 0u); | |
526 EXPECT_TRUE_WAIT(candidate_allocation_done_, kDefaultAllocationTimeout); | |
527 } | |
528 | |
478 // Disable for asan, see | 529 // Disable for asan, see |
479 // https://code.google.com/p/webrtc/issues/detail?id=4743 for details. | 530 // https://code.google.com/p/webrtc/issues/detail?id=4743 for details. |
480 #if !defined(ADDRESS_SANITIZER) | 531 #if !defined(ADDRESS_SANITIZER) |
481 | 532 |
482 // Test that we can get OnCandidatesAllocationDone callback when all the ports | 533 // Test that we can get OnCandidatesAllocationDone callback when all the ports |
483 // are disabled. | 534 // are disabled. |
484 TEST_F(PortAllocatorTest, TestDisableAllPorts) { | 535 TEST_F(PortAllocatorTest, TestDisableAllPorts) { |
485 AddInterface(kClientAddr); | 536 AddInterface(kClientAddr); |
486 EXPECT_TRUE(CreateSession(cricket::ICE_CANDIDATE_COMPONENT_RTP)); | 537 EXPECT_TRUE(CreateSession(cricket::ICE_CANDIDATE_COMPONENT_RTP)); |
487 session_->set_flags(cricket::PORTALLOCATOR_DISABLE_UDP | | 538 session_->set_flags(cricket::PORTALLOCATOR_DISABLE_UDP | |
(...skipping 696 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1184 AllocationSequenceForTest alloc_sequence( | 1235 AllocationSequenceForTest alloc_sequence( |
1185 static_cast<cricket::BasicPortAllocatorSession*>(session_.get()), | 1236 static_cast<cricket::BasicPortAllocatorSession*>(session_.get()), |
1186 &network1, &config, flag); | 1237 &network1, &config, flag); |
1187 // This simply tests it will not crash if udp_socket_ in the | 1238 // This simply tests it will not crash if udp_socket_ in the |
1188 // AllocationSequence is null, which is chosen in the constructor. | 1239 // AllocationSequence is null, which is chosen in the constructor. |
1189 cricket::RelayServerConfig relay_server(cricket::RELAY_TURN); | 1240 cricket::RelayServerConfig relay_server(cricket::RELAY_TURN); |
1190 relay_server.ports.push_back( | 1241 relay_server.ports.push_back( |
1191 cricket::ProtocolAddress(kTurnUdpIntAddr, cricket::PROTO_UDP, false)); | 1242 cricket::ProtocolAddress(kTurnUdpIntAddr, cricket::PROTO_UDP, false)); |
1192 alloc_sequence.CreateTurnPort(relay_server); | 1243 alloc_sequence.CreateTurnPort(relay_server); |
1193 } | 1244 } |
OLD | NEW |