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

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

Issue 2093623004: Add config to prune TURN ports (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: . Created 4 years, 5 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 21 matching lines...) Expand all
32 #include "webrtc/base/socketaddress.h" 32 #include "webrtc/base/socketaddress.h"
33 #include "webrtc/base/ssladapter.h" 33 #include "webrtc/base/ssladapter.h"
34 #include "webrtc/base/thread.h" 34 #include "webrtc/base/thread.h"
35 #include "webrtc/base/virtualsocketserver.h" 35 #include "webrtc/base/virtualsocketserver.h"
36 36
37 using rtc::IPAddress; 37 using rtc::IPAddress;
38 using rtc::SocketAddress; 38 using rtc::SocketAddress;
39 using rtc::Thread; 39 using rtc::Thread;
40 40
41 static const SocketAddress kClientAddr("11.11.11.11", 0); 41 static const SocketAddress kClientAddr("11.11.11.11", 0);
42 static const SocketAddress kClientAddr2("22.22.22.22", 0);
42 static const SocketAddress kLoopbackAddr("127.0.0.1", 0); 43 static const SocketAddress kLoopbackAddr("127.0.0.1", 0);
43 static const SocketAddress kPrivateAddr("192.168.1.11", 0); 44 static const SocketAddress kPrivateAddr("192.168.1.11", 0);
44 static const SocketAddress kPrivateAddr2("192.168.1.12", 0); 45 static const SocketAddress kPrivateAddr2("192.168.1.12", 0);
45 static const SocketAddress kClientIPv6Addr("2401:fa00:4:1000:be30:5bff:fee5:c3", 46 static const SocketAddress kClientIPv6Addr("2401:fa00:4:1000:be30:5bff:fee5:c3",
46 0); 47 0);
47 static const SocketAddress kClientAddr2("22.22.22.22", 0); 48 static const SocketAddress kClientIPv6Addr2(
49 "2401:fa00:4:2000:be30:5bff:fee5:c3",
50 0);
48 static const SocketAddress kNatUdpAddr("77.77.77.77", rtc::NAT_SERVER_UDP_PORT); 51 static const SocketAddress kNatUdpAddr("77.77.77.77", rtc::NAT_SERVER_UDP_PORT);
49 static const SocketAddress kNatTcpAddr("77.77.77.77", rtc::NAT_SERVER_TCP_PORT); 52 static const SocketAddress kNatTcpAddr("77.77.77.77", rtc::NAT_SERVER_TCP_PORT);
50 static const SocketAddress kRemoteClientAddr("22.22.22.22", 0); 53 static const SocketAddress kRemoteClientAddr("22.22.22.22", 0);
51 static const SocketAddress kStunAddr("99.99.99.1", cricket::STUN_SERVER_PORT); 54 static const SocketAddress kStunAddr("99.99.99.1", cricket::STUN_SERVER_PORT);
52 static const SocketAddress kRelayUdpIntAddr("99.99.99.2", 5000); 55 static const SocketAddress kRelayUdpIntAddr("99.99.99.2", 5000);
53 static const SocketAddress kRelayUdpExtAddr("99.99.99.3", 5001); 56 static const SocketAddress kRelayUdpExtAddr("99.99.99.3", 5001);
54 static const SocketAddress kRelayTcpIntAddr("99.99.99.2", 5002); 57 static const SocketAddress kRelayTcpIntAddr("99.99.99.2", 5002);
55 static const SocketAddress kRelayTcpExtAddr("99.99.99.3", 5003); 58 static const SocketAddress kRelayTcpExtAddr("99.99.99.3", 5003);
56 static const SocketAddress kRelaySslTcpIntAddr("99.99.99.2", 5004); 59 static const SocketAddress kRelaySslTcpIntAddr("99.99.99.2", 5004);
57 static const SocketAddress kRelaySslTcpExtAddr("99.99.99.3", 5005); 60 static const SocketAddress kRelaySslTcpExtAddr("99.99.99.3", 5005);
58 static const SocketAddress kTurnUdpIntAddr("99.99.99.4", 3478); 61 static const SocketAddress kTurnUdpIntAddr("99.99.99.4", 3478);
62 static const SocketAddress kTurnUdpIntIPv6Addr(
63 "2402:fb00:4:1000:be30:5bff:fee5:c3",
64 3479);
59 static const SocketAddress kTurnTcpIntAddr("99.99.99.5", 3478); 65 static const SocketAddress kTurnTcpIntAddr("99.99.99.5", 3478);
66 static const SocketAddress kTurnTcpIntIPv6Addr(
67 "2402:fb00:4:2000:be30:5bff:fee5:c3",
68 3479);
60 static const SocketAddress kTurnUdpExtAddr("99.99.99.6", 0); 69 static const SocketAddress kTurnUdpExtAddr("99.99.99.6", 0);
61 70
62 // Minimum and maximum port for port range tests. 71 // Minimum and maximum port for port range tests.
63 static const int kMinPort = 10000; 72 static const int kMinPort = 10000;
64 static const int kMaxPort = 10099; 73 static const int kMaxPort = 10099;
65 74
66 // Based on ICE_UFRAG_LENGTH 75 // Based on ICE_UFRAG_LENGTH
67 static const char kIceUfrag0[] = "UF00"; 76 static const char kIceUfrag0[] = "UF00";
68 // Based on ICE_PWD_LENGTH 77 // Based on ICE_PWD_LENGTH
69 static const char kIcePwd0[] = "TESTICEPWD00000000000000"; 78 static const char kIcePwd0[] = "TESTICEPWD00000000000000";
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after
177 AddTurnServers(udp_turn, tcp_turn); 186 AddTurnServers(udp_turn, tcp_turn);
178 } 187 }
179 188
180 void AddTurnServers(const rtc::SocketAddress& udp_turn, 189 void AddTurnServers(const rtc::SocketAddress& udp_turn,
181 const rtc::SocketAddress& tcp_turn) { 190 const rtc::SocketAddress& tcp_turn) {
182 RelayServerConfig turn_server(RELAY_TURN); 191 RelayServerConfig turn_server(RELAY_TURN);
183 RelayCredentials credentials(kTurnUsername, kTurnPassword); 192 RelayCredentials credentials(kTurnUsername, kTurnPassword);
184 turn_server.credentials = credentials; 193 turn_server.credentials = credentials;
185 194
186 if (!udp_turn.IsNil()) { 195 if (!udp_turn.IsNil()) {
187 turn_server.ports.push_back( 196 turn_server.ports.push_back(ProtocolAddress(udp_turn, PROTO_UDP, false));
188 ProtocolAddress(kTurnUdpIntAddr, PROTO_UDP, false));
189 } 197 }
190 if (!tcp_turn.IsNil()) { 198 if (!tcp_turn.IsNil()) {
191 turn_server.ports.push_back( 199 turn_server.ports.push_back(ProtocolAddress(tcp_turn, PROTO_TCP, false));
192 ProtocolAddress(kTurnTcpIntAddr, PROTO_TCP, false));
193 } 200 }
194 allocator_->AddTurnServer(turn_server); 201 allocator_->AddTurnServer(turn_server);
195 } 202 }
196 203
197 bool CreateSession(int component) { 204 bool CreateSession(int component) {
198 session_ = CreateSession("session", component); 205 session_ = CreateSession("session", component);
199 if (!session_) { 206 if (!session_) {
200 return false; 207 return false;
201 } 208 }
202 return true; 209 return true;
(...skipping 22 matching lines...) Expand all
225 std::unique_ptr<PortAllocatorSession> CreateSession( 232 std::unique_ptr<PortAllocatorSession> CreateSession(
226 const std::string& sid, 233 const std::string& sid,
227 const std::string& content_name, 234 const std::string& content_name,
228 int component, 235 int component,
229 const std::string& ice_ufrag, 236 const std::string& ice_ufrag,
230 const std::string& ice_pwd) { 237 const std::string& ice_pwd) {
231 std::unique_ptr<PortAllocatorSession> session = allocator_->CreateSession( 238 std::unique_ptr<PortAllocatorSession> session = allocator_->CreateSession(
232 sid, content_name, component, ice_ufrag, ice_pwd); 239 sid, content_name, component, ice_ufrag, ice_pwd);
233 session->SignalPortReady.connect(this, 240 session->SignalPortReady.connect(this,
234 &BasicPortAllocatorTest::OnPortReady); 241 &BasicPortAllocatorTest::OnPortReady);
242 session->SignalPortPruned.connect(this,
243 &BasicPortAllocatorTest::OnPortPruned);
235 session->SignalCandidatesReady.connect( 244 session->SignalCandidatesReady.connect(
236 this, &BasicPortAllocatorTest::OnCandidatesReady); 245 this, &BasicPortAllocatorTest::OnCandidatesReady);
237 session->SignalCandidatesAllocationDone.connect( 246 session->SignalCandidatesAllocationDone.connect(
238 this, &BasicPortAllocatorTest::OnCandidatesAllocationDone); 247 this, &BasicPortAllocatorTest::OnCandidatesAllocationDone);
239 return session; 248 return session;
240 } 249 }
241 250
242 // Return true if the addresses are the same, or the port is 0 in |pattern| 251 // Return true if the addresses are the same, or the port is 0 in |pattern|
243 // (acting as a wildcard) and the IPs are the same. 252 // (acting as a wildcard) and the IPs are the same.
244 // Even with a wildcard port, the port of the address should be nonzero if 253 // Even with a wildcard port, the port of the address should be nonzero if
245 // the IP is nonzero. 254 // the IP is nonzero.
246 static bool AddressMatch(const SocketAddress& address, 255 static bool AddressMatch(const SocketAddress& address,
247 const SocketAddress& pattern) { 256 const SocketAddress& pattern) {
248 return address.ipaddr() == pattern.ipaddr() && 257 return address.ipaddr() == pattern.ipaddr() &&
249 ((pattern.port() == 0 && 258 ((pattern.port() == 0 &&
250 (address.port() != 0 || IPIsAny(address.ipaddr()))) || 259 (address.port() != 0 || IPIsAny(address.ipaddr()))) ||
251 (pattern.port() != 0 && address.port() == pattern.port())); 260 (pattern.port() != 0 && address.port() == pattern.port()));
252 } 261 }
253 262
263 static int CountPorts(const std::vector<PortInterface*>& ports,
Taylor Brandstetter 2016/06/29 20:57:36 nit: CountPortsWithAddress?
honghaiz3 2016/06/29 22:53:30 Ideally we may want CountPortsWithTypeProtocolAndA
264 const std::string& type,
265 ProtocolType protocol,
266 const SocketAddress& client_addr) {
267 return std::count_if(
268 ports.begin(), ports.end(),
269 [type, protocol, client_addr](PortInterface* port) {
270 return port->Type() == type && port->GetProtocol() == protocol &&
271 port->Network()->GetBestIP() == client_addr.ipaddr();
272 });
273 }
274
254 // Find a candidate and return it. 275 // Find a candidate and return it.
255 static bool FindCandidate(const std::vector<Candidate>& candidates, 276 static bool FindCandidate(const std::vector<Candidate>& candidates,
256 const std::string& type, 277 const std::string& type,
257 const std::string& proto, 278 const std::string& proto,
258 const SocketAddress& addr, 279 const SocketAddress& addr,
259 Candidate* found) { 280 Candidate* found) {
260 auto it = std::find_if(candidates.begin(), candidates.end(), 281 auto it = std::find_if(candidates.begin(), candidates.end(),
261 [type, proto, addr](const Candidate& c) { 282 [type, proto, addr](const Candidate& c) {
262 return c.type() == type && c.protocol() == proto && 283 return c.type() == type && c.protocol() == proto &&
263 AddressMatch(c.address(), addr); 284 AddressMatch(c.address(), addr);
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after
385 BasicPortAllocator& allocator() { return *allocator_; } 406 BasicPortAllocator& allocator() { return *allocator_; }
386 407
387 void OnPortReady(PortAllocatorSession* ses, PortInterface* port) { 408 void OnPortReady(PortAllocatorSession* ses, PortInterface* port) {
388 LOG(LS_INFO) << "OnPortReady: " << port->ToString(); 409 LOG(LS_INFO) << "OnPortReady: " << port->ToString();
389 ports_.push_back(port); 410 ports_.push_back(port);
390 // Make sure the new port is added to ReadyPorts. 411 // Make sure the new port is added to ReadyPorts.
391 auto ready_ports = ses->ReadyPorts(); 412 auto ready_ports = ses->ReadyPorts();
392 EXPECT_NE(ready_ports.end(), 413 EXPECT_NE(ready_ports.end(),
393 std::find(ready_ports.begin(), ready_ports.end(), port)); 414 std::find(ready_ports.begin(), ready_ports.end(), port));
394 } 415 }
416 void OnPortPruned(PortAllocatorSession* ses, PortInterface* port) {
417 LOG(LS_INFO) << "OnPortPruned: " << port->ToString();
418 ports_.erase(std::remove(ports_.begin(), ports_.end(), port), ports_.end());
419 // Make sure the pruned port is not in ReadyPorts.
420 auto ready_ports = ses->ReadyPorts();
421 EXPECT_EQ(ready_ports.end(),
422 std::find(ready_ports.begin(), ready_ports.end(), port));
423 }
424
395 void OnCandidatesReady(PortAllocatorSession* ses, 425 void OnCandidatesReady(PortAllocatorSession* ses,
396 const std::vector<Candidate>& candidates) { 426 const std::vector<Candidate>& candidates) {
397 for (const Candidate& candidate : candidates) { 427 for (const Candidate& candidate : candidates) {
398 LOG(LS_INFO) << "OnCandidatesReady: " << candidate.ToString(); 428 LOG(LS_INFO) << "OnCandidatesReady: " << candidate.ToString();
399 // Sanity check that the ICE component is set. 429 // Sanity check that the ICE component is set.
400 EXPECT_EQ(ICE_CANDIDATE_COMPONENT_RTP, candidate.component()); 430 EXPECT_EQ(ICE_CANDIDATE_COMPONENT_RTP, candidate.component());
401 candidates_.push_back(candidate); 431 candidates_.push_back(candidate);
402 } 432 }
403 // Make sure the new candidates are added to Candidates. 433 // Make sure the new candidates are added to Candidates.
404 auto ses_candidates = ses->ReadyCandidates(); 434 auto ses_candidates = ses->ReadyCandidates();
(...skipping 762 matching lines...) Expand 10 before | Expand all | Expand 10 after
1167 ASSERT_EQ(3U, ports_.size()); 1197 ASSERT_EQ(3U, ports_.size());
1168 EXPECT_PRED4(HasCandidate, candidates_, "local", "udp", kClientAddr); 1198 EXPECT_PRED4(HasCandidate, candidates_, "local", "udp", kClientAddr);
1169 EXPECT_PRED4(HasCandidate, candidates_, "relay", "udp", 1199 EXPECT_PRED4(HasCandidate, candidates_, "relay", "udp",
1170 rtc::SocketAddress(kTurnUdpExtAddr.ipaddr(), 0)); 1200 rtc::SocketAddress(kTurnUdpExtAddr.ipaddr(), 0));
1171 EXPECT_PRED4(HasCandidate, candidates_, "relay", "udp", 1201 EXPECT_PRED4(HasCandidate, candidates_, "relay", "udp",
1172 rtc::SocketAddress(kTurnUdpExtAddr.ipaddr(), 0)); 1202 rtc::SocketAddress(kTurnUdpExtAddr.ipaddr(), 0));
1173 EXPECT_TRUE_WAIT(candidate_allocation_done_, kDefaultAllocationTimeout); 1203 EXPECT_TRUE_WAIT(candidate_allocation_done_, kDefaultAllocationTimeout);
1174 EXPECT_EQ(3U, candidates_.size()); 1204 EXPECT_EQ(3U, candidates_.size());
1175 } 1205 }
1176 1206
1207 // Test that if prune_turn_ports is set, TCP TurnPort will not
1208 // be used if UDP TurnPort is used.
1209 TEST_F(BasicPortAllocatorTest, TestUdpTurnPortDisablesTcpTurnPorts) {
1210 turn_server_.AddInternalSocket(kTurnTcpIntAddr, PROTO_TCP);
1211 AddInterface(kClientAddr);
1212 allocator_.reset(new BasicPortAllocator(&network_manager_));
1213 allocator_->SetConfiguration(allocator_->stun_servers(),
1214 allocator_->turn_servers(), 0, true);
1215 AddTurnServers(kTurnUdpIntAddr, kTurnTcpIntAddr);
1216 allocator_->set_step_delay(kMinimumStepDelay);
1217 allocator_->set_flags(allocator().flags() |
1218 PORTALLOCATOR_ENABLE_SHARED_SOCKET |
1219 PORTALLOCATOR_DISABLE_TCP);
1220
1221 EXPECT_TRUE(CreateSession(ICE_CANDIDATE_COMPONENT_RTP));
1222 session_->StartGettingPorts();
1223 EXPECT_TRUE_WAIT(candidate_allocation_done_, kDefaultAllocationTimeout);
1224 // Only 2 ports (one STUN and one TURN) are actually being used.
1225 EXPECT_EQ(2U, session_->ReadyPorts().size());
1226 // We have verified that each port, when it is added to |ports_|, it is found
1227 // in |ready_ports|, and when it is pruned, it is not found in |ready_ports|,
1228 // so we only need to verify the content in one of them.
1229 EXPECT_EQ(2U, ports_.size());
1230 EXPECT_EQ(1, CountPorts(ports_, "local", PROTO_UDP, kClientAddr));
1231 EXPECT_EQ(1, CountPorts(ports_, "relay", PROTO_UDP, kClientAddr));
1232 EXPECT_EQ(0, CountPorts(ports_, "relay", PROTO_TCP, kClientAddr));
1233
1234 // We don't remove candidates, so the size of |candidates_| will depend on
1235 // when the TCP TURN port becomes ready. If it is ready after the UDP TURN
1236 // port becomes ready, its candidates will be used there will be 3 candidates.
1237 // Otherwise there will be only 2 candidates.
Taylor Brandstetter 2016/06/29 20:57:36 This seems less than optimal. I understand keeping
honghaiz3 2016/06/29 22:53:30 We do have a plan to remove candidates for v1.1 as
Taylor Brandstetter 2016/06/29 23:04:57 Well in theory, if a connection has not been nomin
1238 EXPECT_LE(2U, candidates_.size());
1239 // There will only be 2 candidates in |ready_candidates| because it only
1240 // includes the candidates in the ready ports.
1241 const std::vector<Candidate>& ready_candidates = session_->ReadyCandidates();
1242 EXPECT_EQ(2U, ready_candidates.size());
1243 EXPECT_PRED4(HasCandidate, ready_candidates, "local", "udp", kClientAddr);
1244 EXPECT_PRED4(HasCandidate, ready_candidates, "relay", "udp",
1245 rtc::SocketAddress(kTurnUdpExtAddr.ipaddr(), 0));
1246 }
1247
1248 // Tests that if prune_turn_ports is set, IPv4 TurnPort will not
1249 // be used if IPv6 TurnPort is used.
1250 TEST_F(BasicPortAllocatorTest, TestIPv6TurnPortDisablesIPv4TurnPorts) {
1251 turn_server_.AddInternalSocket(kTurnUdpIntIPv6Addr, PROTO_UDP);
1252 // Add two IP addresses on the same interface.
1253 AddInterface(kClientAddr, "net1");
1254 AddInterface(kClientIPv6Addr, "net1");
1255 allocator_.reset(new BasicPortAllocator(&network_manager_));
1256 allocator_->SetConfiguration(allocator_->stun_servers(),
1257 allocator_->turn_servers(), 0, true);
1258 AddTurnServers(kTurnUdpIntIPv6Addr, rtc::SocketAddress());
1259
1260 allocator_->set_step_delay(kMinimumStepDelay);
1261 allocator_->set_flags(allocator().flags() |
1262 PORTALLOCATOR_ENABLE_SHARED_SOCKET |
1263 PORTALLOCATOR_ENABLE_IPV6 | PORTALLOCATOR_DISABLE_TCP);
1264
1265 EXPECT_TRUE(CreateSession(ICE_CANDIDATE_COMPONENT_RTP));
1266 session_->StartGettingPorts();
1267 EXPECT_TRUE_WAIT(candidate_allocation_done_, kDefaultAllocationTimeout);
1268 rtc::Thread::Current()->ProcessMessages(1000);
1269 // Three ports (one IPv4 STUN, one IPv6 STUN and one TURN) will be ready.
1270 EXPECT_EQ(3U, session_->ReadyPorts().size());
1271 EXPECT_EQ(3U, ports_.size());
1272 EXPECT_EQ(1, CountPorts(ports_, "local", PROTO_UDP, kClientAddr));
1273 EXPECT_EQ(1, CountPorts(ports_, "local", PROTO_UDP, kClientIPv6Addr));
1274 EXPECT_EQ(1, CountPorts(ports_, "relay", PROTO_UDP, kClientIPv6Addr));
1275 EXPECT_EQ(0, CountPorts(ports_, "relay", PROTO_UDP, kClientAddr));
1276
1277 // We don't remove candidates, so there may be more than 3 elemenets in
1278 // |candidates_|, although |ready_candidates| only includes the candidates
1279 // in |ready_ports|.
1280 EXPECT_LE(3U, candidates_.size());
1281 const std::vector<Candidate>& ready_candidates = session_->ReadyCandidates();
1282 EXPECT_EQ(3U, ready_candidates.size());
1283 EXPECT_PRED4(HasCandidate, ready_candidates, "local", "udp", kClientAddr);
1284 EXPECT_PRED4(HasCandidate, ready_candidates, "relay", "udp",
1285 rtc::SocketAddress(kTurnUdpExtAddr.ipaddr(), 0));
1286 }
1287
1288 // Tests that if prune_turn_ports is set, each network interface
1289 // will has its own set of TurnPorts based on their priorities.
1290 TEST_F(BasicPortAllocatorTest, TestEachInterfaceHasItsOwnTurnPorts) {
1291 turn_server_.AddInternalSocket(kTurnTcpIntAddr, PROTO_TCP);
1292 turn_server_.AddInternalSocket(kTurnUdpIntIPv6Addr, PROTO_UDP);
1293 turn_server_.AddInternalSocket(kTurnTcpIntIPv6Addr, PROTO_TCP);
1294 // Add two interfaces both having IPv4 and IPv6 addresses.
1295 AddInterface(kClientAddr, "net1");
1296 AddInterface(kClientIPv6Addr, "net1");
1297 AddInterface(kClientAddr2, "net2");
1298 AddInterface(kClientIPv6Addr2, "net2");
1299 allocator_.reset(new BasicPortAllocator(&network_manager_));
1300 allocator_->SetConfiguration(allocator_->stun_servers(),
1301 allocator_->turn_servers(), 0, true);
1302 // Have both UDP/TCP and IPv4/IPv6 TURN ports.
1303 AddTurnServers(kTurnUdpIntAddr, kTurnTcpIntAddr);
1304 AddTurnServers(kTurnUdpIntIPv6Addr, kTurnTcpIntIPv6Addr);
1305
1306 allocator_->set_step_delay(kMinimumStepDelay);
1307 allocator_->set_flags(allocator().flags() |
1308 PORTALLOCATOR_ENABLE_SHARED_SOCKET |
1309 PORTALLOCATOR_ENABLE_IPV6);
1310 EXPECT_TRUE(CreateSession(ICE_CANDIDATE_COMPONENT_RTP));
1311 session_->StartGettingPorts();
1312 EXPECT_TRUE_WAIT(candidate_allocation_done_, kDefaultAllocationTimeout);
1313 // 10 ports (4 STUN and 1 TURN ports on each interface) will be ready to use.
1314 EXPECT_EQ(10U, session_->ReadyPorts().size());
1315 EXPECT_EQ(10U, ports_.size());
1316 EXPECT_EQ(1, CountPorts(ports_, "local", PROTO_UDP, kClientAddr));
1317 EXPECT_EQ(1, CountPorts(ports_, "local", PROTO_UDP, kClientAddr2));
1318 EXPECT_EQ(1, CountPorts(ports_, "local", PROTO_UDP, kClientIPv6Addr));
1319 EXPECT_EQ(1, CountPorts(ports_, "local", PROTO_UDP, kClientIPv6Addr2));
1320 EXPECT_EQ(1, CountPorts(ports_, "local", PROTO_TCP, kClientAddr));
1321 EXPECT_EQ(1, CountPorts(ports_, "local", PROTO_TCP, kClientAddr2));
1322 EXPECT_EQ(1, CountPorts(ports_, "local", PROTO_TCP, kClientIPv6Addr));
1323 EXPECT_EQ(1, CountPorts(ports_, "local", PROTO_TCP, kClientIPv6Addr2));
1324 EXPECT_EQ(1, CountPorts(ports_, "relay", PROTO_UDP, kClientIPv6Addr));
1325 EXPECT_EQ(1, CountPorts(ports_, "relay", PROTO_UDP, kClientIPv6Addr2));
1326
1327 // We don't remove candidates, so there may be more than 10 candidates
1328 // in |candidates_|.
1329 EXPECT_LE(10U, candidates_.size());
1330 const std::vector<Candidate>& ready_candidates = session_->ReadyCandidates();
1331 EXPECT_EQ(10U, ready_candidates.size());
1332 EXPECT_PRED4(HasCandidate, ready_candidates, "local", "udp", kClientAddr);
1333 EXPECT_PRED4(HasCandidate, ready_candidates, "local", "udp", kClientAddr2);
1334 EXPECT_PRED4(HasCandidate, ready_candidates, "local", "udp", kClientIPv6Addr);
1335 EXPECT_PRED4(HasCandidate, ready_candidates, "local", "udp",
1336 kClientIPv6Addr2);
1337 EXPECT_PRED4(HasCandidate, ready_candidates, "local", "tcp", kClientAddr);
1338 EXPECT_PRED4(HasCandidate, ready_candidates, "local", "tcp", kClientAddr2);
1339 EXPECT_PRED4(HasCandidate, ready_candidates, "local", "tcp", kClientIPv6Addr);
1340 EXPECT_PRED4(HasCandidate, ready_candidates, "local", "tcp",
1341 kClientIPv6Addr2);
1342 EXPECT_PRED4(HasCandidate, ready_candidates, "relay", "udp",
1343 rtc::SocketAddress(kTurnUdpExtAddr.ipaddr(), 0));
1344 }
1345
1177 // Testing DNS resolve for the TURN server, this will test AllocationSequence 1346 // Testing DNS resolve for the TURN server, this will test AllocationSequence
1178 // handling the unresolved address signal from TurnPort. 1347 // handling the unresolved address signal from TurnPort.
1179 TEST_F(BasicPortAllocatorTest, TestSharedSocketWithServerAddressResolve) { 1348 TEST_F(BasicPortAllocatorTest, TestSharedSocketWithServerAddressResolve) {
1180 turn_server_.AddInternalSocket(rtc::SocketAddress("127.0.0.1", 3478), 1349 turn_server_.AddInternalSocket(rtc::SocketAddress("127.0.0.1", 3478),
1181 PROTO_UDP); 1350 PROTO_UDP);
1182 AddInterface(kClientAddr); 1351 AddInterface(kClientAddr);
1183 allocator_.reset(new BasicPortAllocator(&network_manager_)); 1352 allocator_.reset(new BasicPortAllocator(&network_manager_));
1184 RelayServerConfig turn_server(RELAY_TURN); 1353 RelayServerConfig turn_server(RELAY_TURN);
1185 RelayCredentials credentials(kTurnUsername, kTurnPassword); 1354 RelayCredentials credentials(kTurnUsername, kTurnPassword);
1186 turn_server.credentials = credentials; 1355 turn_server.credentials = credentials;
(...skipping 275 matching lines...) Expand 10 before | Expand all | Expand 10 after
1462 ASSERT_EQ_WAIT(2U, candidates_.size(), 1000); 1631 ASSERT_EQ_WAIT(2U, candidates_.size(), 1000);
1463 EXPECT_EQ(2U, ports_.size()); 1632 EXPECT_EQ(2U, ports_.size());
1464 } 1633 }
1465 1634
1466 // Test that the ports and candidates are updated with new ufrag/pwd/etc. when 1635 // Test that the ports and candidates are updated with new ufrag/pwd/etc. when
1467 // a pooled session is taken out of the pool. 1636 // a pooled session is taken out of the pool.
1468 TEST_F(BasicPortAllocatorTest, TestTransportInformationUpdated) { 1637 TEST_F(BasicPortAllocatorTest, TestTransportInformationUpdated) {
1469 AddInterface(kClientAddr); 1638 AddInterface(kClientAddr);
1470 int pool_size = 1; 1639 int pool_size = 1;
1471 allocator_->SetConfiguration(allocator_->stun_servers(), 1640 allocator_->SetConfiguration(allocator_->stun_servers(),
1472 allocator_->turn_servers(), pool_size); 1641 allocator_->turn_servers(), pool_size, false);
1473 const PortAllocatorSession* peeked_session = allocator_->GetPooledSession(); 1642 const PortAllocatorSession* peeked_session = allocator_->GetPooledSession();
1474 ASSERT_NE(nullptr, peeked_session); 1643 ASSERT_NE(nullptr, peeked_session);
1475 EXPECT_EQ_WAIT(true, peeked_session->CandidatesAllocationDone(), 1644 EXPECT_EQ_WAIT(true, peeked_session->CandidatesAllocationDone(),
1476 kDefaultAllocationTimeout); 1645 kDefaultAllocationTimeout);
1477 // Expect that when TakePooledSession is called, 1646 // Expect that when TakePooledSession is called,
1478 // UpdateTransportInformationInternal will be called and the 1647 // UpdateTransportInformationInternal will be called and the
1479 // BasicPortAllocatorSession will update the ufrag/pwd of ports and 1648 // BasicPortAllocatorSession will update the ufrag/pwd of ports and
1480 // candidates. 1649 // candidates.
1481 session_ = 1650 session_ =
1482 allocator_->TakePooledSession(kContentName, 1, kIceUfrag0, kIcePwd0); 1651 allocator_->TakePooledSession(kContentName, 1, kIceUfrag0, kIcePwd0);
(...skipping 15 matching lines...) Expand all
1498 EXPECT_EQ(kIcePwd0, candidate.password()); 1667 EXPECT_EQ(kIcePwd0, candidate.password());
1499 } 1668 }
1500 } 1669 }
1501 1670
1502 // Test that a new candidate filter takes effect even on already-gathered 1671 // Test that a new candidate filter takes effect even on already-gathered
1503 // candidates. 1672 // candidates.
1504 TEST_F(BasicPortAllocatorTest, TestSetCandidateFilterAfterCandidatesGathered) { 1673 TEST_F(BasicPortAllocatorTest, TestSetCandidateFilterAfterCandidatesGathered) {
1505 AddInterface(kClientAddr); 1674 AddInterface(kClientAddr);
1506 int pool_size = 1; 1675 int pool_size = 1;
1507 allocator_->SetConfiguration(allocator_->stun_servers(), 1676 allocator_->SetConfiguration(allocator_->stun_servers(),
1508 allocator_->turn_servers(), pool_size); 1677 allocator_->turn_servers(), pool_size, false);
1509 const PortAllocatorSession* peeked_session = allocator_->GetPooledSession(); 1678 const PortAllocatorSession* peeked_session = allocator_->GetPooledSession();
1510 ASSERT_NE(nullptr, peeked_session); 1679 ASSERT_NE(nullptr, peeked_session);
1511 EXPECT_EQ_WAIT(true, peeked_session->CandidatesAllocationDone(), 1680 EXPECT_EQ_WAIT(true, peeked_session->CandidatesAllocationDone(),
1512 kDefaultAllocationTimeout); 1681 kDefaultAllocationTimeout);
1513 size_t initial_candidates_size = peeked_session->ReadyCandidates().size(); 1682 size_t initial_candidates_size = peeked_session->ReadyCandidates().size();
1514 size_t initial_ports_size = peeked_session->ReadyPorts().size(); 1683 size_t initial_ports_size = peeked_session->ReadyPorts().size();
1515 allocator_->set_candidate_filter(CF_RELAY); 1684 allocator_->set_candidate_filter(CF_RELAY);
1516 // Assume that when TakePooledSession is called, the candidate filter will be 1685 // Assume that when TakePooledSession is called, the candidate filter will be
1517 // applied to the pooled session. This is tested by PortAllocatorTest. 1686 // applied to the pooled session. This is tested by PortAllocatorTest.
1518 session_ = 1687 session_ =
(...skipping 11 matching lines...) Expand all
1530 for (const Candidate& candidate : candidates) { 1699 for (const Candidate& candidate : candidates) {
1531 // Expect only relay candidates now that the filter is applied. 1700 // Expect only relay candidates now that the filter is applied.
1532 EXPECT_EQ(std::string(RELAY_PORT_TYPE), candidate.type()); 1701 EXPECT_EQ(std::string(RELAY_PORT_TYPE), candidate.type());
1533 // Expect that the raddr is emptied due to the CF_RELAY filter. 1702 // Expect that the raddr is emptied due to the CF_RELAY filter.
1534 EXPECT_EQ(candidate.related_address(), 1703 EXPECT_EQ(candidate.related_address(),
1535 rtc::EmptySocketAddressWithFamily(candidate.address().family())); 1704 rtc::EmptySocketAddressWithFamily(candidate.address().family()));
1536 } 1705 }
1537 } 1706 }
1538 1707
1539 } // namespace cricket 1708 } // namespace cricket
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