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

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: Merge branch 'master' into turn_port_exposer 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 FindPorts(const std::vector<PortInterface*>& ports,
pthatcher1 2016/06/28 21:01:42 This should be called CountPorts.
honghaiz3 2016/06/28 23:36:01 Done.
264 const std::string& type,
265 ProtocolType protocol,
266 const SocketAddress& client_addr) {
267 int found_ports = 0;
268 for (PortInterface* port : ports) {
269 if (port->Type() == type && port->GetProtocol() == protocol &&
270 port->Network()->GetBestIP() == client_addr.ipaddr()) {
271 ++found_ports;
272 }
273 }
274 return found_ports;
pthatcher1 2016/06/28 21:01:42 This could use std::count_if.
honghaiz3 2016/06/28 23:36:01 Done.
275 }
276
254 // Find a candidate and return it. 277 // Find a candidate and return it.
255 static bool FindCandidate(const std::vector<Candidate>& candidates, 278 static bool FindCandidate(const std::vector<Candidate>& candidates,
256 const std::string& type, 279 const std::string& type,
257 const std::string& proto, 280 const std::string& proto,
258 const SocketAddress& addr, 281 const SocketAddress& addr,
259 Candidate* found) { 282 Candidate* found) {
260 auto it = std::find_if(candidates.begin(), candidates.end(), 283 auto it = std::find_if(candidates.begin(), candidates.end(),
261 [type, proto, addr](const Candidate& c) { 284 [type, proto, addr](const Candidate& c) {
262 return c.type() == type && c.protocol() == proto && 285 return c.type() == type && c.protocol() == proto &&
263 AddressMatch(c.address(), addr); 286 AddressMatch(c.address(), addr);
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after
385 BasicPortAllocator& allocator() { return *allocator_; } 408 BasicPortAllocator& allocator() { return *allocator_; }
386 409
387 void OnPortReady(PortAllocatorSession* ses, PortInterface* port) { 410 void OnPortReady(PortAllocatorSession* ses, PortInterface* port) {
388 LOG(LS_INFO) << "OnPortReady: " << port->ToString(); 411 LOG(LS_INFO) << "OnPortReady: " << port->ToString();
389 ports_.push_back(port); 412 ports_.push_back(port);
390 // Make sure the new port is added to ReadyPorts. 413 // Make sure the new port is added to ReadyPorts.
391 auto ready_ports = ses->ReadyPorts(); 414 auto ready_ports = ses->ReadyPorts();
392 EXPECT_NE(ready_ports.end(), 415 EXPECT_NE(ready_ports.end(),
393 std::find(ready_ports.begin(), ready_ports.end(), port)); 416 std::find(ready_ports.begin(), ready_ports.end(), port));
394 } 417 }
418 void OnPortPruned(PortAllocatorSession* ses, PortInterface* port) {
419 LOG(LS_INFO) << "OnPortPruned: " << port->ToString();
420 ports_.erase(std::remove(ports_.begin(), ports_.end(), port), ports_.end());
421 // Make sure the pruned port is not in ReadyPorts.
422 auto ready_ports = ses->ReadyPorts();
423 EXPECT_EQ(ready_ports.end(),
424 std::find(ready_ports.begin(), ready_ports.end(), port));
425 }
426
395 void OnCandidatesReady(PortAllocatorSession* ses, 427 void OnCandidatesReady(PortAllocatorSession* ses,
396 const std::vector<Candidate>& candidates) { 428 const std::vector<Candidate>& candidates) {
397 for (const Candidate& candidate : candidates) { 429 for (const Candidate& candidate : candidates) {
398 LOG(LS_INFO) << "OnCandidatesReady: " << candidate.ToString(); 430 LOG(LS_INFO) << "OnCandidatesReady: " << candidate.ToString();
399 // Sanity check that the ICE component is set. 431 // Sanity check that the ICE component is set.
400 EXPECT_EQ(ICE_CANDIDATE_COMPONENT_RTP, candidate.component()); 432 EXPECT_EQ(ICE_CANDIDATE_COMPONENT_RTP, candidate.component());
401 candidates_.push_back(candidate); 433 candidates_.push_back(candidate);
402 } 434 }
403 // Make sure the new candidates are added to Candidates. 435 // Make sure the new candidates are added to Candidates.
404 auto ses_candidates = ses->ReadyCandidates(); 436 auto ses_candidates = ses->ReadyCandidates();
(...skipping 762 matching lines...) Expand 10 before | Expand all | Expand 10 after
1167 ASSERT_EQ(3U, ports_.size()); 1199 ASSERT_EQ(3U, ports_.size());
1168 EXPECT_PRED4(HasCandidate, candidates_, "local", "udp", kClientAddr); 1200 EXPECT_PRED4(HasCandidate, candidates_, "local", "udp", kClientAddr);
1169 EXPECT_PRED4(HasCandidate, candidates_, "relay", "udp", 1201 EXPECT_PRED4(HasCandidate, candidates_, "relay", "udp",
1170 rtc::SocketAddress(kTurnUdpExtAddr.ipaddr(), 0)); 1202 rtc::SocketAddress(kTurnUdpExtAddr.ipaddr(), 0));
1171 EXPECT_PRED4(HasCandidate, candidates_, "relay", "udp", 1203 EXPECT_PRED4(HasCandidate, candidates_, "relay", "udp",
1172 rtc::SocketAddress(kTurnUdpExtAddr.ipaddr(), 0)); 1204 rtc::SocketAddress(kTurnUdpExtAddr.ipaddr(), 0));
1173 EXPECT_TRUE_WAIT(candidate_allocation_done_, kDefaultAllocationTimeout); 1205 EXPECT_TRUE_WAIT(candidate_allocation_done_, kDefaultAllocationTimeout);
1174 EXPECT_EQ(3U, candidates_.size()); 1206 EXPECT_EQ(3U, candidates_.size());
1175 } 1207 }
1176 1208
1209 // Test that if prune_turn_ports is set, TCP TurnPort will not
1210 // be used if UDP TurnPort is used.
1211 TEST_F(BasicPortAllocatorTest, TestUdpTurnPortDisablesTcpTurnPorts) {
1212 turn_server_.AddInternalSocket(kTurnTcpIntAddr, PROTO_TCP);
1213 AddInterface(kClientAddr);
1214 allocator_.reset(new BasicPortAllocator(&network_manager_));
1215 allocator_->SetConfiguration(allocator_->stun_servers(),
1216 allocator_->turn_servers(), 0, true);
1217 AddTurnServers(kTurnUdpIntAddr, kTurnTcpIntAddr);
1218 allocator_->set_step_delay(kMinimumStepDelay);
1219 allocator_->set_flags(allocator().flags() |
1220 PORTALLOCATOR_ENABLE_SHARED_SOCKET |
1221 PORTALLOCATOR_DISABLE_TCP);
1222
1223 EXPECT_TRUE(CreateSession(ICE_CANDIDATE_COMPONENT_RTP));
1224 session_->StartGettingPorts();
1225 EXPECT_TRUE_WAIT(candidate_allocation_done_, kDefaultAllocationTimeout);
1226 // Only 2 ports (one STUN and one TURN) are actually being used.
1227 EXPECT_EQ(2U, session_->ReadyPorts().size());
1228 // We have verified that each port, when it is added to |ports_|, it is found
1229 // in |ready_ports|, and when it is pruned, it is not found in |ready_ports|,
1230 // so we only need to verify the content in one of them.
1231 EXPECT_EQ(2U, ports_.size());
1232 EXPECT_EQ(1, FindPorts(ports_, "local", PROTO_UDP, kClientAddr));
1233 EXPECT_EQ(1, FindPorts(ports_, "relay", PROTO_UDP, kClientAddr));
1234 EXPECT_EQ(0, FindPorts(ports_, "relay", PROTO_TCP, kClientAddr));
1235
1236 // We don't remove candidates, so the size of |candidates_| will depend on
1237 // when the TCP TURN port becomes ready. If it is ready after the UDP TURN
1238 // port becomes ready, its candidates will be used there will be 3 candidates.
1239 // Otherwise there will be only 2 candidates.
1240 EXPECT_LE(2U, candidates_.size());
1241 // There will only be 2 candidates in |ready_candidates| because it only
1242 // includes the candidates in the ready ports.
1243 const std::vector<Candidate>& ready_candidates = session_->ReadyCandidates();
1244 EXPECT_EQ(2U, ready_candidates.size());
1245 EXPECT_PRED4(HasCandidate, ready_candidates, "local", "udp", kClientAddr);
1246 EXPECT_PRED4(HasCandidate, ready_candidates, "relay", "udp",
1247 rtc::SocketAddress(kTurnUdpExtAddr.ipaddr(), 0));
1248 }
1249
1250 // Tests that if prune_turn_ports is set, IPv4 TurnPort will not
1251 // be used if IPv6 TurnPort is used.
1252 TEST_F(BasicPortAllocatorTest, TestIPv6TurnPortDisablesIPv4TurnPorts) {
1253 turn_server_.AddInternalSocket(kTurnUdpIntIPv6Addr, PROTO_UDP);
1254 // Add two IP addresses on the same interface.
1255 AddInterface(kClientAddr, "net1");
1256 AddInterface(kClientIPv6Addr, "net1");
1257 allocator_.reset(new BasicPortAllocator(&network_manager_));
1258 allocator_->SetConfiguration(allocator_->stun_servers(),
1259 allocator_->turn_servers(), 0, true);
1260 AddTurnServers(kTurnUdpIntIPv6Addr, rtc::SocketAddress());
1261
1262 allocator_->set_step_delay(kMinimumStepDelay);
1263 allocator_->set_flags(allocator().flags() |
1264 PORTALLOCATOR_ENABLE_SHARED_SOCKET |
1265 PORTALLOCATOR_ENABLE_IPV6 | PORTALLOCATOR_DISABLE_TCP);
1266
1267 EXPECT_TRUE(CreateSession(ICE_CANDIDATE_COMPONENT_RTP));
1268 session_->StartGettingPorts();
1269 EXPECT_TRUE_WAIT(candidate_allocation_done_, kDefaultAllocationTimeout);
1270 rtc::Thread::Current()->ProcessMessages(1000);
1271 // Three ports (one IPv4 STUN, one IPv6 STUN and one TURN) will be ready.
1272 EXPECT_EQ(3U, session_->ReadyPorts().size());
1273 EXPECT_EQ(3U, ports_.size());
1274 EXPECT_EQ(1, FindPorts(ports_, "local", PROTO_UDP, kClientAddr));
1275 EXPECT_EQ(1, FindPorts(ports_, "local", PROTO_UDP, kClientIPv6Addr));
1276 EXPECT_EQ(1, FindPorts(ports_, "relay", PROTO_UDP, kClientIPv6Addr));
1277 EXPECT_EQ(0, FindPorts(ports_, "relay", PROTO_UDP, kClientAddr));
1278
1279 // We don't remove candidates, so there may be more than 3 elemenets in
1280 // |candidates_|, although |ready_candidates| only includes the candidates
1281 // in |ready_ports|.
1282 EXPECT_LE(3U, candidates_.size());
1283 const std::vector<Candidate>& ready_candidates = session_->ReadyCandidates();
1284 EXPECT_EQ(3U, ready_candidates.size());
1285 EXPECT_PRED4(HasCandidate, ready_candidates, "local", "udp", kClientAddr);
1286 EXPECT_PRED4(HasCandidate, ready_candidates, "relay", "udp",
1287 rtc::SocketAddress(kTurnUdpExtAddr.ipaddr(), 0));
1288 }
1289
1290 // Tests that if prune_turn_ports is set, each network interface
1291 // will has its own set of TurnPorts based on their priorities.
1292 TEST_F(BasicPortAllocatorTest, TestEachInterfaceHasItsOwnTurnPorts) {
1293 turn_server_.AddInternalSocket(kTurnTcpIntAddr, PROTO_TCP);
1294 turn_server_.AddInternalSocket(kTurnUdpIntIPv6Addr, PROTO_UDP);
1295 turn_server_.AddInternalSocket(kTurnTcpIntIPv6Addr, PROTO_TCP);
1296 // Add two interfaces both having IPv4 and IPv6 addresses.
1297 AddInterface(kClientAddr, "net1");
1298 AddInterface(kClientIPv6Addr, "net1");
1299 AddInterface(kClientAddr2, "net2");
1300 AddInterface(kClientIPv6Addr2, "net2");
1301 allocator_.reset(new BasicPortAllocator(&network_manager_));
1302 allocator_->SetConfiguration(allocator_->stun_servers(),
1303 allocator_->turn_servers(), 0, true);
1304 // Have both UDP/TCP and IPv4/IPv6 TURN ports.
1305 AddTurnServers(kTurnUdpIntAddr, kTurnTcpIntAddr);
1306 AddTurnServers(kTurnUdpIntIPv6Addr, kTurnTcpIntIPv6Addr);
1307
1308 allocator_->set_step_delay(kMinimumStepDelay);
1309 allocator_->set_flags(allocator().flags() |
1310 PORTALLOCATOR_ENABLE_SHARED_SOCKET |
1311 PORTALLOCATOR_ENABLE_IPV6);
1312 EXPECT_TRUE(CreateSession(ICE_CANDIDATE_COMPONENT_RTP));
1313 session_->StartGettingPorts();
1314 EXPECT_TRUE_WAIT(candidate_allocation_done_, kDefaultAllocationTimeout);
1315 // 10 ports (4 STUN and 1 TURN ports on each interface) will be ready to use.
1316 EXPECT_EQ(10U, session_->ReadyPorts().size());
1317 EXPECT_EQ(10U, ports_.size());
1318 EXPECT_EQ(1, FindPorts(ports_, "local", PROTO_UDP, kClientAddr));
1319 EXPECT_EQ(1, FindPorts(ports_, "local", PROTO_UDP, kClientAddr2));
1320 EXPECT_EQ(1, FindPorts(ports_, "local", PROTO_UDP, kClientIPv6Addr));
1321 EXPECT_EQ(1, FindPorts(ports_, "local", PROTO_UDP, kClientIPv6Addr2));
1322 EXPECT_EQ(1, FindPorts(ports_, "local", PROTO_TCP, kClientAddr));
1323 EXPECT_EQ(1, FindPorts(ports_, "local", PROTO_TCP, kClientAddr2));
1324 EXPECT_EQ(1, FindPorts(ports_, "local", PROTO_TCP, kClientIPv6Addr));
1325 EXPECT_EQ(1, FindPorts(ports_, "local", PROTO_TCP, kClientIPv6Addr2));
1326 EXPECT_EQ(1, FindPorts(ports_, "relay", PROTO_UDP, kClientIPv6Addr));
1327 EXPECT_EQ(1, FindPorts(ports_, "relay", PROTO_UDP, kClientIPv6Addr2));
1328
1329 // We don't remove candidates, so there may be more than 10 candidates
1330 // in |candidates_|.
1331 EXPECT_LE(10U, candidates_.size());
1332 const std::vector<Candidate>& ready_candidates = session_->ReadyCandidates();
1333 EXPECT_EQ(10U, ready_candidates.size());
1334 EXPECT_PRED4(HasCandidate, ready_candidates, "local", "udp", kClientAddr);
1335 EXPECT_PRED4(HasCandidate, ready_candidates, "local", "udp", kClientAddr2);
1336 EXPECT_PRED4(HasCandidate, ready_candidates, "local", "udp", kClientIPv6Addr);
1337 EXPECT_PRED4(HasCandidate, ready_candidates, "local", "udp",
1338 kClientIPv6Addr2);
1339 EXPECT_PRED4(HasCandidate, ready_candidates, "local", "tcp", kClientAddr);
1340 EXPECT_PRED4(HasCandidate, ready_candidates, "local", "tcp", kClientAddr2);
1341 EXPECT_PRED4(HasCandidate, ready_candidates, "local", "tcp", kClientIPv6Addr);
1342 EXPECT_PRED4(HasCandidate, ready_candidates, "local", "tcp",
1343 kClientIPv6Addr2);
1344 EXPECT_PRED4(HasCandidate, ready_candidates, "relay", "udp",
1345 rtc::SocketAddress(kTurnUdpExtAddr.ipaddr(), 0));
1346 }
1347
1177 // Testing DNS resolve for the TURN server, this will test AllocationSequence 1348 // Testing DNS resolve for the TURN server, this will test AllocationSequence
1178 // handling the unresolved address signal from TurnPort. 1349 // handling the unresolved address signal from TurnPort.
1179 TEST_F(BasicPortAllocatorTest, TestSharedSocketWithServerAddressResolve) { 1350 TEST_F(BasicPortAllocatorTest, TestSharedSocketWithServerAddressResolve) {
1180 turn_server_.AddInternalSocket(rtc::SocketAddress("127.0.0.1", 3478), 1351 turn_server_.AddInternalSocket(rtc::SocketAddress("127.0.0.1", 3478),
1181 PROTO_UDP); 1352 PROTO_UDP);
1182 AddInterface(kClientAddr); 1353 AddInterface(kClientAddr);
1183 allocator_.reset(new BasicPortAllocator(&network_manager_)); 1354 allocator_.reset(new BasicPortAllocator(&network_manager_));
1184 RelayServerConfig turn_server(RELAY_TURN); 1355 RelayServerConfig turn_server(RELAY_TURN);
1185 RelayCredentials credentials(kTurnUsername, kTurnPassword); 1356 RelayCredentials credentials(kTurnUsername, kTurnPassword);
1186 turn_server.credentials = credentials; 1357 turn_server.credentials = credentials;
(...skipping 275 matching lines...) Expand 10 before | Expand all | Expand 10 after
1462 ASSERT_EQ_WAIT(2U, candidates_.size(), 1000); 1633 ASSERT_EQ_WAIT(2U, candidates_.size(), 1000);
1463 EXPECT_EQ(2U, ports_.size()); 1634 EXPECT_EQ(2U, ports_.size());
1464 } 1635 }
1465 1636
1466 // Test that the ports and candidates are updated with new ufrag/pwd/etc. when 1637 // Test that the ports and candidates are updated with new ufrag/pwd/etc. when
1467 // a pooled session is taken out of the pool. 1638 // a pooled session is taken out of the pool.
1468 TEST_F(BasicPortAllocatorTest, TestTransportInformationUpdated) { 1639 TEST_F(BasicPortAllocatorTest, TestTransportInformationUpdated) {
1469 AddInterface(kClientAddr); 1640 AddInterface(kClientAddr);
1470 int pool_size = 1; 1641 int pool_size = 1;
1471 allocator_->SetConfiguration(allocator_->stun_servers(), 1642 allocator_->SetConfiguration(allocator_->stun_servers(),
1472 allocator_->turn_servers(), pool_size); 1643 allocator_->turn_servers(), pool_size, false);
1473 const PortAllocatorSession* peeked_session = allocator_->GetPooledSession(); 1644 const PortAllocatorSession* peeked_session = allocator_->GetPooledSession();
1474 ASSERT_NE(nullptr, peeked_session); 1645 ASSERT_NE(nullptr, peeked_session);
1475 EXPECT_EQ_WAIT(true, peeked_session->CandidatesAllocationDone(), 1646 EXPECT_EQ_WAIT(true, peeked_session->CandidatesAllocationDone(),
1476 kDefaultAllocationTimeout); 1647 kDefaultAllocationTimeout);
1477 // Expect that when TakePooledSession is called, 1648 // Expect that when TakePooledSession is called,
1478 // UpdateTransportInformationInternal will be called and the 1649 // UpdateTransportInformationInternal will be called and the
1479 // BasicPortAllocatorSession will update the ufrag/pwd of ports and 1650 // BasicPortAllocatorSession will update the ufrag/pwd of ports and
1480 // candidates. 1651 // candidates.
1481 session_ = 1652 session_ =
1482 allocator_->TakePooledSession(kContentName, 1, kIceUfrag0, kIcePwd0); 1653 allocator_->TakePooledSession(kContentName, 1, kIceUfrag0, kIcePwd0);
(...skipping 15 matching lines...) Expand all
1498 EXPECT_EQ(kIcePwd0, candidate.password()); 1669 EXPECT_EQ(kIcePwd0, candidate.password());
1499 } 1670 }
1500 } 1671 }
1501 1672
1502 // Test that a new candidate filter takes effect even on already-gathered 1673 // Test that a new candidate filter takes effect even on already-gathered
1503 // candidates. 1674 // candidates.
1504 TEST_F(BasicPortAllocatorTest, TestSetCandidateFilterAfterCandidatesGathered) { 1675 TEST_F(BasicPortAllocatorTest, TestSetCandidateFilterAfterCandidatesGathered) {
1505 AddInterface(kClientAddr); 1676 AddInterface(kClientAddr);
1506 int pool_size = 1; 1677 int pool_size = 1;
1507 allocator_->SetConfiguration(allocator_->stun_servers(), 1678 allocator_->SetConfiguration(allocator_->stun_servers(),
1508 allocator_->turn_servers(), pool_size); 1679 allocator_->turn_servers(), pool_size, false);
1509 const PortAllocatorSession* peeked_session = allocator_->GetPooledSession(); 1680 const PortAllocatorSession* peeked_session = allocator_->GetPooledSession();
1510 ASSERT_NE(nullptr, peeked_session); 1681 ASSERT_NE(nullptr, peeked_session);
1511 EXPECT_EQ_WAIT(true, peeked_session->CandidatesAllocationDone(), 1682 EXPECT_EQ_WAIT(true, peeked_session->CandidatesAllocationDone(),
1512 kDefaultAllocationTimeout); 1683 kDefaultAllocationTimeout);
1513 size_t initial_candidates_size = peeked_session->ReadyCandidates().size(); 1684 size_t initial_candidates_size = peeked_session->ReadyCandidates().size();
1514 size_t initial_ports_size = peeked_session->ReadyPorts().size(); 1685 size_t initial_ports_size = peeked_session->ReadyPorts().size();
1515 allocator_->set_candidate_filter(CF_RELAY); 1686 allocator_->set_candidate_filter(CF_RELAY);
1516 // Assume that when TakePooledSession is called, the candidate filter will be 1687 // Assume that when TakePooledSession is called, the candidate filter will be
1517 // applied to the pooled session. This is tested by PortAllocatorTest. 1688 // applied to the pooled session. This is tested by PortAllocatorTest.
1518 session_ = 1689 session_ =
(...skipping 11 matching lines...) Expand all
1530 for (const Candidate& candidate : candidates) { 1701 for (const Candidate& candidate : candidates) {
1531 // Expect only relay candidates now that the filter is applied. 1702 // Expect only relay candidates now that the filter is applied.
1532 EXPECT_EQ(std::string(RELAY_PORT_TYPE), candidate.type()); 1703 EXPECT_EQ(std::string(RELAY_PORT_TYPE), candidate.type());
1533 // Expect that the raddr is emptied due to the CF_RELAY filter. 1704 // Expect that the raddr is emptied due to the CF_RELAY filter.
1534 EXPECT_EQ(candidate.related_address(), 1705 EXPECT_EQ(candidate.related_address(),
1535 rtc::EmptySocketAddressWithFamily(candidate.address().family())); 1706 rtc::EmptySocketAddressWithFamily(candidate.address().family()));
1536 } 1707 }
1537 } 1708 }
1538 1709
1539 } // namespace cricket 1710 } // 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