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

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: Add all tests and fix a bug to set port type 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
46 0); 47 kClientIPv6Addr("2401:fa00:4:1000:be30:5bff:fee5:c3", 0);
47 static const SocketAddress kClientAddr2("22.22.22.22", 0); 48 static const SocketAddress
49 kClientIPv6Addr2("2401:fa00:4:2000:be30:5bff:fee5:c3", 0);
48 static const SocketAddress kNatUdpAddr("77.77.77.77", rtc::NAT_SERVER_UDP_PORT); 50 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); 51 static const SocketAddress kNatTcpAddr("77.77.77.77", rtc::NAT_SERVER_TCP_PORT);
50 static const SocketAddress kRemoteClientAddr("22.22.22.22", 0); 52 static const SocketAddress kRemoteClientAddr("22.22.22.22", 0);
51 static const SocketAddress kStunAddr("99.99.99.1", cricket::STUN_SERVER_PORT); 53 static const SocketAddress kStunAddr("99.99.99.1", cricket::STUN_SERVER_PORT);
52 static const SocketAddress kRelayUdpIntAddr("99.99.99.2", 5000); 54 static const SocketAddress kRelayUdpIntAddr("99.99.99.2", 5000);
53 static const SocketAddress kRelayUdpExtAddr("99.99.99.3", 5001); 55 static const SocketAddress kRelayUdpExtAddr("99.99.99.3", 5001);
54 static const SocketAddress kRelayTcpIntAddr("99.99.99.2", 5002); 56 static const SocketAddress kRelayTcpIntAddr("99.99.99.2", 5002);
55 static const SocketAddress kRelayTcpExtAddr("99.99.99.3", 5003); 57 static const SocketAddress kRelayTcpExtAddr("99.99.99.3", 5003);
56 static const SocketAddress kRelaySslTcpIntAddr("99.99.99.2", 5004); 58 static const SocketAddress kRelaySslTcpIntAddr("99.99.99.2", 5004);
57 static const SocketAddress kRelaySslTcpExtAddr("99.99.99.3", 5005); 59 static const SocketAddress kRelaySslTcpExtAddr("99.99.99.3", 5005);
58 static const SocketAddress kTurnUdpIntAddr("99.99.99.4", 3478); 60 static const SocketAddress kTurnUdpIntAddr("99.99.99.4", 3478);
61 static const SocketAddress
62 kTurnUdpIntIPv6Addr("2402:fb00:4:1000:be30:5bff:fee5:c3", 3479);
59 static const SocketAddress kTurnTcpIntAddr("99.99.99.5", 3478); 63 static const SocketAddress kTurnTcpIntAddr("99.99.99.5", 3478);
64 static const SocketAddress
65 kTurnTcpIntIPv6Addr("2402:fb00:4:2000:be30:5bff:fee5:c3", 3479);
60 static const SocketAddress kTurnUdpExtAddr("99.99.99.6", 0); 66 static const SocketAddress kTurnUdpExtAddr("99.99.99.6", 0);
61 67
62 // Minimum and maximum port for port range tests. 68 // Minimum and maximum port for port range tests.
63 static const int kMinPort = 10000; 69 static const int kMinPort = 10000;
64 static const int kMaxPort = 10099; 70 static const int kMaxPort = 10099;
65 71
66 // Based on ICE_UFRAG_LENGTH 72 // Based on ICE_UFRAG_LENGTH
67 static const char kIceUfrag0[] = "UF00"; 73 static const char kIceUfrag0[] = "UF00";
68 // Based on ICE_PWD_LENGTH 74 // Based on ICE_PWD_LENGTH
69 static const char kIcePwd0[] = "TESTICEPWD00000000000000"; 75 static const char kIcePwd0[] = "TESTICEPWD00000000000000";
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after
177 AddTurnServers(udp_turn, tcp_turn); 183 AddTurnServers(udp_turn, tcp_turn);
178 } 184 }
179 185
180 void AddTurnServers(const rtc::SocketAddress& udp_turn, 186 void AddTurnServers(const rtc::SocketAddress& udp_turn,
181 const rtc::SocketAddress& tcp_turn) { 187 const rtc::SocketAddress& tcp_turn) {
182 RelayServerConfig turn_server(RELAY_TURN); 188 RelayServerConfig turn_server(RELAY_TURN);
183 RelayCredentials credentials(kTurnUsername, kTurnPassword); 189 RelayCredentials credentials(kTurnUsername, kTurnPassword);
184 turn_server.credentials = credentials; 190 turn_server.credentials = credentials;
185 191
186 if (!udp_turn.IsNil()) { 192 if (!udp_turn.IsNil()) {
187 turn_server.ports.push_back( 193 turn_server.ports.push_back(ProtocolAddress(udp_turn, PROTO_UDP, false));
188 ProtocolAddress(kTurnUdpIntAddr, PROTO_UDP, false));
189 } 194 }
190 if (!tcp_turn.IsNil()) { 195 if (!tcp_turn.IsNil()) {
191 turn_server.ports.push_back( 196 turn_server.ports.push_back(ProtocolAddress(tcp_turn, PROTO_TCP, false));
192 ProtocolAddress(kTurnTcpIntAddr, PROTO_TCP, false));
193 } 197 }
194 allocator_->AddTurnServer(turn_server); 198 allocator_->AddTurnServer(turn_server);
195 } 199 }
196 200
197 bool CreateSession(int component) { 201 bool CreateSession(int component) {
198 session_ = CreateSession("session", component); 202 session_ = CreateSession("session", component);
199 if (!session_) { 203 if (!session_) {
200 return false; 204 return false;
201 } 205 }
202 return true; 206 return true;
(...skipping 22 matching lines...) Expand all
225 std::unique_ptr<PortAllocatorSession> CreateSession( 229 std::unique_ptr<PortAllocatorSession> CreateSession(
226 const std::string& sid, 230 const std::string& sid,
227 const std::string& content_name, 231 const std::string& content_name,
228 int component, 232 int component,
229 const std::string& ice_ufrag, 233 const std::string& ice_ufrag,
230 const std::string& ice_pwd) { 234 const std::string& ice_pwd) {
231 std::unique_ptr<PortAllocatorSession> session = allocator_->CreateSession( 235 std::unique_ptr<PortAllocatorSession> session = allocator_->CreateSession(
232 sid, content_name, component, ice_ufrag, ice_pwd); 236 sid, content_name, component, ice_ufrag, ice_pwd);
233 session->SignalPortReady.connect(this, 237 session->SignalPortReady.connect(this,
234 &BasicPortAllocatorTest::OnPortReady); 238 &BasicPortAllocatorTest::OnPortReady);
239 session->SignalPortDeprecated.connect(
240 this, &BasicPortAllocatorTest::OnPortDeprecated);
235 session->SignalCandidatesReady.connect( 241 session->SignalCandidatesReady.connect(
236 this, &BasicPortAllocatorTest::OnCandidatesReady); 242 this, &BasicPortAllocatorTest::OnCandidatesReady);
237 session->SignalCandidatesAllocationDone.connect( 243 session->SignalCandidatesAllocationDone.connect(
238 this, &BasicPortAllocatorTest::OnCandidatesAllocationDone); 244 this, &BasicPortAllocatorTest::OnCandidatesAllocationDone);
239 return session; 245 return session;
240 } 246 }
241 247
242 // Return true if the addresses are the same, or the port is 0 in |pattern| 248 // 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. 249 // (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 250 // Even with a wildcard port, the port of the address should be nonzero if
245 // the IP is nonzero. 251 // the IP is nonzero.
246 static bool AddressMatch(const SocketAddress& address, 252 static bool AddressMatch(const SocketAddress& address,
247 const SocketAddress& pattern) { 253 const SocketAddress& pattern) {
248 return address.ipaddr() == pattern.ipaddr() && 254 return address.ipaddr() == pattern.ipaddr() &&
249 ((pattern.port() == 0 && 255 ((pattern.port() == 0 &&
250 (address.port() != 0 || IPIsAny(address.ipaddr()))) || 256 (address.port() != 0 || IPIsAny(address.ipaddr()))) ||
251 (pattern.port() != 0 && address.port() == pattern.port())); 257 (pattern.port() != 0 && address.port() == pattern.port()));
252 } 258 }
253 259
260 static int FindPorts(const std::vector<PortInterface*>& ports,
261 const std::string& type,
262 ProtocolType protocol,
263 const SocketAddress& client_addr) {
264 int found_ports = 0;
265 for (PortInterface* port : ports) {
266 if (port->Type() == type && port->GetProtocol() == protocol &&
267 port->Network()->GetBestIP() == client_addr.ipaddr()) {
268 ++found_ports;
269 }
270 }
271 return found_ports;
272 }
273
254 // Find a candidate and return it. 274 // Find a candidate and return it.
255 static bool FindCandidate(const std::vector<Candidate>& candidates, 275 static bool FindCandidate(const std::vector<Candidate>& candidates,
256 const std::string& type, 276 const std::string& type,
257 const std::string& proto, 277 const std::string& proto,
258 const SocketAddress& addr, 278 const SocketAddress& addr,
259 Candidate* found) { 279 Candidate* found) {
260 auto it = std::find_if(candidates.begin(), candidates.end(), 280 auto it = std::find_if(candidates.begin(), candidates.end(),
261 [type, proto, addr](const Candidate& c) { 281 [type, proto, addr](const Candidate& c) {
262 return c.type() == type && c.protocol() == proto && 282 return c.type() == type && c.protocol() == proto &&
263 AddressMatch(c.address(), addr); 283 AddressMatch(c.address(), addr);
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after
385 BasicPortAllocator& allocator() { return *allocator_; } 405 BasicPortAllocator& allocator() { return *allocator_; }
386 406
387 void OnPortReady(PortAllocatorSession* ses, PortInterface* port) { 407 void OnPortReady(PortAllocatorSession* ses, PortInterface* port) {
388 LOG(LS_INFO) << "OnPortReady: " << port->ToString(); 408 LOG(LS_INFO) << "OnPortReady: " << port->ToString();
389 ports_.push_back(port); 409 ports_.push_back(port);
390 // Make sure the new port is added to ReadyPorts. 410 // Make sure the new port is added to ReadyPorts.
391 auto ready_ports = ses->ReadyPorts(); 411 auto ready_ports = ses->ReadyPorts();
392 EXPECT_NE(ready_ports.end(), 412 EXPECT_NE(ready_ports.end(),
393 std::find(ready_ports.begin(), ready_ports.end(), port)); 413 std::find(ready_ports.begin(), ready_ports.end(), port));
394 } 414 }
415 void OnPortDeprecated(PortAllocatorSession* ses, PortInterface* port) {
416 LOG(LS_INFO) << "OnPortDeprecated: " << port->ToString();
417 ports_.erase(std::remove(ports_.begin(), ports_.end(), port), ports_.end());
418 // Make sure the deprecated port is not in ReadyPorts.
419 auto ready_ports = ses->ReadyPorts();
420 EXPECT_EQ(ready_ports.end(),
421 std::find(ready_ports.begin(), ready_ports.end(), port));
422 }
423
395 void OnCandidatesReady(PortAllocatorSession* ses, 424 void OnCandidatesReady(PortAllocatorSession* ses,
396 const std::vector<Candidate>& candidates) { 425 const std::vector<Candidate>& candidates) {
397 for (const Candidate& candidate : candidates) { 426 for (const Candidate& candidate : candidates) {
398 LOG(LS_INFO) << "OnCandidatesReady: " << candidate.ToString(); 427 LOG(LS_INFO) << "OnCandidatesReady: " << candidate.ToString();
399 // Sanity check that the ICE component is set. 428 // Sanity check that the ICE component is set.
400 EXPECT_EQ(ICE_CANDIDATE_COMPONENT_RTP, candidate.component()); 429 EXPECT_EQ(ICE_CANDIDATE_COMPONENT_RTP, candidate.component());
401 candidates_.push_back(candidate); 430 candidates_.push_back(candidate);
402 } 431 }
403 // Make sure the new candidates are added to Candidates. 432 // Make sure the new candidates are added to Candidates.
404 auto ses_candidates = ses->ReadyCandidates(); 433 auto ses_candidates = ses->ReadyCandidates();
(...skipping 762 matching lines...) Expand 10 before | Expand all | Expand 10 after
1167 ASSERT_EQ(3U, ports_.size()); 1196 ASSERT_EQ(3U, ports_.size());
1168 EXPECT_PRED4(HasCandidate, candidates_, "local", "udp", kClientAddr); 1197 EXPECT_PRED4(HasCandidate, candidates_, "local", "udp", kClientAddr);
1169 EXPECT_PRED4(HasCandidate, candidates_, "relay", "udp", 1198 EXPECT_PRED4(HasCandidate, candidates_, "relay", "udp",
1170 rtc::SocketAddress(kTurnUdpExtAddr.ipaddr(), 0)); 1199 rtc::SocketAddress(kTurnUdpExtAddr.ipaddr(), 0));
1171 EXPECT_PRED4(HasCandidate, candidates_, "relay", "udp", 1200 EXPECT_PRED4(HasCandidate, candidates_, "relay", "udp",
1172 rtc::SocketAddress(kTurnUdpExtAddr.ipaddr(), 0)); 1201 rtc::SocketAddress(kTurnUdpExtAddr.ipaddr(), 0));
1173 EXPECT_TRUE_WAIT(candidate_allocation_done_, kDefaultAllocationTimeout); 1202 EXPECT_TRUE_WAIT(candidate_allocation_done_, kDefaultAllocationTimeout);
1174 EXPECT_EQ(3U, candidates_.size()); 1203 EXPECT_EQ(3U, candidates_.size());
1175 } 1204 }
1176 1205
1206 // Test that if disabling low priority ports is set, TCP TurnPort will not
1207 // be used if UDP TurnPort is used.
1208 TEST_F(BasicPortAllocatorTest, TestUdpTurnPortDisablesTcpTurnPorts) {
1209 turn_server_.AddInternalSocket(kTurnTcpIntAddr, PROTO_TCP);
1210 AddInterface(kClientAddr);
1211 allocator_.reset(new BasicPortAllocator(&network_manager_));
1212 allocator_->SetConfiguration(allocator_->stun_servers(),
1213 allocator_->turn_servers(), 0, true);
1214 AddTurnServers(kTurnUdpIntAddr, kTurnTcpIntAddr);
1215 allocator_->set_step_delay(kMinimumStepDelay);
1216 allocator_->set_flags(allocator().flags() |
1217 PORTALLOCATOR_ENABLE_SHARED_SOCKET |
1218 PORTALLOCATOR_DISABLE_TCP);
1219
1220 EXPECT_TRUE(CreateSession(ICE_CANDIDATE_COMPONENT_RTP));
1221 session_->StartGettingPorts();
1222 EXPECT_TRUE_WAIT(candidate_allocation_done_, kDefaultAllocationTimeout);
1223 // Only 2 ports (one STUN and one TURN) are actually being used.
1224 EXPECT_EQ(2U, session_->ReadyPorts().size());
1225 // We have verified that each port, when it is added to |ports_|, it
1226 // is found in |ready_ports|, and when it is deprecated, it is
1227 // not found in |ready_ports|, so we only need to verify the content
1228 // in one of them.
1229 EXPECT_EQ(2U, ports_.size());
1230 EXPECT_EQ(1, FindPorts(ports_, "local", PROTO_UDP, kClientAddr));
1231 EXPECT_EQ(1, FindPorts(ports_, "relay", PROTO_UDP, kClientAddr));
1232 EXPECT_EQ(0, FindPorts(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.
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 disable_low_priority_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, FindPorts(ports_, "local", PROTO_UDP, kClientAddr));
1273 EXPECT_EQ(1, FindPorts(ports_, "local", PROTO_UDP, kClientIPv6Addr));
1274 EXPECT_EQ(1, FindPorts(ports_, "relay", PROTO_UDP, kClientIPv6Addr));
1275 EXPECT_EQ(0, FindPorts(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 disable_low_priority_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, FindPorts(ports_, "local", PROTO_UDP, kClientAddr));
1317 EXPECT_EQ(1, FindPorts(ports_, "local", PROTO_UDP, kClientAddr2));
1318 EXPECT_EQ(1, FindPorts(ports_, "local", PROTO_UDP, kClientIPv6Addr));
1319 EXPECT_EQ(1, FindPorts(ports_, "local", PROTO_UDP, kClientIPv6Addr2));
1320 EXPECT_EQ(1, FindPorts(ports_, "local", PROTO_TCP, kClientAddr));
1321 EXPECT_EQ(1, FindPorts(ports_, "local", PROTO_TCP, kClientAddr2));
1322 EXPECT_EQ(1, FindPorts(ports_, "local", PROTO_TCP, kClientIPv6Addr));
1323 EXPECT_EQ(1, FindPorts(ports_, "local", PROTO_TCP, kClientIPv6Addr2));
1324 EXPECT_EQ(1, FindPorts(ports_, "relay", PROTO_UDP, kClientIPv6Addr));
1325 EXPECT_EQ(1, FindPorts(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