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

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
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 92 matching lines...) Expand 10 before | Expand all | Expand 10 after
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 AddInterfaceAsDefault(const SocketAddress& addr) {
pthatcher1 2015/08/06 01:06:19 Would SetDefaultRoute make more sense?
guoweis_webrtc 2015/08/06 08:50:07 I renamed it as AddInterfaceAsDefaultRoute, since
114 AddInterface(addr);
115 // When a binding comes from the any address, the |addr| will be used as the
116 // srflx address.
117 vss_->set_default_interface(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 99 matching lines...) Expand 10 before | Expand all | Expand 10 after
225 (*it)->GetOption(rtc::Socket::OPT_SNDBUF, 236 (*it)->GetOption(rtc::Socket::OPT_SNDBUF,
226 &send_buffer_size)); 237 &send_buffer_size));
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 CheckDisableAdapterEnumerationNonSharedSocket() {
juberti1 2015/08/06 00:35:26 can we just fix this to use shared socket? non-sha
guoweis_webrtc 2015/08/06 08:50:07 Done.
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);
238 session_->StartGettingPorts(); 249 session_->StartGettingPorts();
239 EXPECT_TRUE_WAIT(candidate_allocation_done_, kDefaultAllocationTimeout); 250 EXPECT_TRUE_WAIT(candidate_allocation_done_, kDefaultAllocationTimeout);
240 251
241 // Only 2 candidates as local UDP/TCP are all 0s and get trimmed out. 252 // Only 2 candidates as local UDP/TCP are all 0s and get trimmed out.
242 EXPECT_EQ(2U, candidates_.size()); 253 EXPECT_EQ(2U, candidates_.size());
243 EXPECT_EQ(2U, ports_.size()); // One stunport and one turnport. 254 EXPECT_EQ(2U, ports_.size()); // One stunport and one turnport.
244 255
245 EXPECT_PRED5(CheckCandidate, candidates_[0], 256 EXPECT_PRED5(CheckCandidate, candidates_[0],
(...skipping 208 matching lines...) Expand 10 before | Expand all | Expand 10 after
454 } 465 }
455 466
456 // Test that we should only get STUN and TURN candidates when adapter 467 // Test that we should only get STUN and TURN candidates when adapter
457 // enumeration is disabled. 468 // enumeration is disabled.
458 TEST_F(PortAllocatorTest, TestDisableAdapterEnumeration) { 469 TEST_F(PortAllocatorTest, TestDisableAdapterEnumeration) {
459 AddInterface(kClientAddr); 470 AddInterface(kClientAddr);
460 // GTURN is not configured here. 471 // GTURN is not configured here.
461 ResetWithNatServer(kStunAddr); 472 ResetWithNatServer(kStunAddr);
462 AddTurnServers(kTurnUdpIntAddr, rtc::SocketAddress()); 473 AddTurnServers(kTurnUdpIntAddr, rtc::SocketAddress());
463 474
464 CheckDisableAdapterEnumeration(); 475 CheckDisableAdapterEnumerationNonSharedSocket();
465 } 476 }
466 477
467 // Test that even with multiple interfaces, the result should be only 1 Stun 478 // 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). 479 // candidate since we bind to any address (i.e. all 0s).
469 TEST_F(PortAllocatorTest, TestDisableAdapterEnumerationMultipleInterfaces) { 480 TEST_F(PortAllocatorTest, TestDisableAdapterEnumerationMultipleInterfaces) {
470 AddInterface(kPrivateAddr); 481 AddInterface(kPrivateAddr);
471 AddInterface(kPrivateAddr2); 482 AddInterface(kPrivateAddr2);
472 ResetWithNatServer(kStunAddr); 483 ResetWithNatServer(kStunAddr);
473 AddTurnServers(kTurnUdpIntAddr, rtc::SocketAddress()); 484 AddTurnServers(kTurnUdpIntAddr, rtc::SocketAddress());
474 485
475 CheckDisableAdapterEnumeration(); 486 CheckDisableAdapterEnumerationNonSharedSocket();
476 } 487 }
477 488
478 // Disable for asan, see 489 // Disable for asan, see
479 // https://code.google.com/p/webrtc/issues/detail?id=4743 for details. 490 // https://code.google.com/p/webrtc/issues/detail?id=4743 for details.
480 #if !defined(ADDRESS_SANITIZER) 491 #if !defined(ADDRESS_SANITIZER)
481 492
482 // Test that we can get OnCandidatesAllocationDone callback when all the ports 493 // Test that we can get OnCandidatesAllocationDone callback when all the ports
483 // are disabled. 494 // are disabled.
484 TEST_F(PortAllocatorTest, TestDisableAllPorts) { 495 TEST_F(PortAllocatorTest, TestDisableAllPorts) {
485 AddInterface(kClientAddr); 496 AddInterface(kClientAddr);
(...skipping 668 matching lines...) Expand 10 before | Expand all | Expand 10 after
1154 session_->StartGettingPorts(); 1165 session_->StartGettingPorts();
1155 ASSERT_EQ_WAIT(7U, candidates_.size(), kDefaultAllocationTimeout); 1166 ASSERT_EQ_WAIT(7U, candidates_.size(), kDefaultAllocationTimeout);
1156 EXPECT_EQ(4U, ports_.size()); 1167 EXPECT_EQ(4U, ports_.size());
1157 1168
1158 auto it = ports_.begin(); 1169 auto it = ports_.begin();
1159 for (; it != ports_.end(); ++it) { 1170 for (; it != ports_.end(); ++it) {
1160 (reinterpret_cast<cricket::Port*>(*it))->Destroy(); 1171 (reinterpret_cast<cricket::Port*>(*it))->Destroy();
1161 } 1172 }
1162 } 1173 }
1163 1174
1175 // Test that when adapter enumeration is disabled, STUN is the only candidate
juberti1 2015/08/06 00:35:26 Isn't this already tested by the tests above?
pthatcher1 2015/08/06 01:06:19 I think this one is different because it is shared
guoweis_webrtc 2015/08/06 08:50:07 this one is different because it doesn't have a NA
1176 // for endpoints not behind a NAT.
1177 TEST_F(PortAllocatorTest, TestAdapterEnumerationDisabledWithoutNat) {
juberti1 2015/08/06 00:35:26 move this next to other adapter-enum disabled test
guoweis_webrtc 2015/08/06 08:50:07 Done.
1178 AddInterfaceAsDefault(kClientAddr);
1179 allocator_->set_flags(allocator().flags() |
1180 cricket::PORTALLOCATOR_ENABLE_SHARED_UFRAG |
1181 cricket::PORTALLOCATOR_DISABLE_ADAPTER_ENUMERATION |
1182 cricket::PORTALLOCATOR_DISABLE_RELAY |
1183 cricket::PORTALLOCATOR_DISABLE_TCP |
1184 cricket::PORTALLOCATOR_ENABLE_SHARED_SOCKET);
1185 EXPECT_TRUE(CreateSession(cricket::ICE_CANDIDATE_COMPONENT_RTP));
1186 session_->StartGettingPorts();
1187 EXPECT_TRUE_WAIT(1U == ports_.size(), kDefaultAllocationTimeout);
1188 ASSERT_EQ_WAIT(1U, candidates_.size(), kDefaultAllocationTimeout);
1189 EXPECT_PRED5(CheckCandidate, candidates_[0],
1190 cricket::ICE_CANDIDATE_COMPONENT_RTP, "stun", "udp",
1191 kClientAddr);
1192 EXPECT_TRUE_WAIT(candidate_allocation_done_, kDefaultAllocationTimeout);
1193 }
1194
1195 // Test that when adapter enumeration is disabled, for endpoints without
1196 // STUN/TURN specified, no candidate is generated.
1197 TEST_F(PortAllocatorTest,
1198 TestAdapterEnumerationDisabledWithoutNat_NoCandidate) {
1199 AddInterfaceAsDefault(kClientAddr);
1200 ResetWithNoServers();
1201 allocator_->set_flags(allocator().flags() |
1202 cricket::PORTALLOCATOR_ENABLE_SHARED_UFRAG |
1203 cricket::PORTALLOCATOR_DISABLE_ADAPTER_ENUMERATION |
1204 cricket::PORTALLOCATOR_DISABLE_RELAY |
1205 cricket::PORTALLOCATOR_DISABLE_TCP |
1206 cricket::PORTALLOCATOR_ENABLE_SHARED_SOCKET);
1207 EXPECT_TRUE(CreateSession(cricket::ICE_CANDIDATE_COMPONENT_RTP));
1208 session_->StartGettingPorts();
1209 EXPECT_TRUE_WAIT(1U == ports_.size(), kDefaultAllocationTimeout);
1210 EXPECT_EQ(candidates_.size(), 0u);
1211 EXPECT_TRUE_WAIT(candidate_allocation_done_, kDefaultAllocationTimeout);
1212 }
1213
1164 class AllocationSequenceForTest : public cricket::AllocationSequence { 1214 class AllocationSequenceForTest : public cricket::AllocationSequence {
1165 public: 1215 public:
1166 AllocationSequenceForTest(cricket::BasicPortAllocatorSession* session, 1216 AllocationSequenceForTest(cricket::BasicPortAllocatorSession* session,
1167 rtc::Network* network, 1217 rtc::Network* network,
1168 cricket::PortConfiguration* config, 1218 cricket::PortConfiguration* config,
1169 uint32 flags) 1219 uint32 flags)
1170 : cricket::AllocationSequence(session, network, config, flags) {} 1220 : cricket::AllocationSequence(session, network, config, flags) {}
1171 using cricket::AllocationSequence::CreateTurnPort; 1221 using cricket::AllocationSequence::CreateTurnPort;
1172 }; 1222 };
1173 1223
(...skipping 10 matching lines...) Expand all
1184 AllocationSequenceForTest alloc_sequence( 1234 AllocationSequenceForTest alloc_sequence(
1185 static_cast<cricket::BasicPortAllocatorSession*>(session_.get()), 1235 static_cast<cricket::BasicPortAllocatorSession*>(session_.get()),
1186 &network1, &config, flag); 1236 &network1, &config, flag);
1187 // This simply tests it will not crash if udp_socket_ in the 1237 // This simply tests it will not crash if udp_socket_ in the
1188 // AllocationSequence is null, which is chosen in the constructor. 1238 // AllocationSequence is null, which is chosen in the constructor.
1189 cricket::RelayServerConfig relay_server(cricket::RELAY_TURN); 1239 cricket::RelayServerConfig relay_server(cricket::RELAY_TURN);
1190 relay_server.ports.push_back( 1240 relay_server.ports.push_back(
1191 cricket::ProtocolAddress(kTurnUdpIntAddr, cricket::PROTO_UDP, false)); 1241 cricket::ProtocolAddress(kTurnUdpIntAddr, cricket::PROTO_UDP, false));
1192 alloc_sequence.CreateTurnPort(relay_server); 1242 alloc_sequence.CreateTurnPort(relay_server);
1193 } 1243 }
OLDNEW
« webrtc/p2p/client/basicportallocator.cc ('K') | « webrtc/p2p/client/basicportallocator.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698