OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2009 The WebRTC Project Authors. All rights reserved. | 2 * Copyright 2009 The WebRTC Project Authors. All rights reserved. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license | 4 * Use of this source code is governed by a BSD-style license |
5 * that can be found in the LICENSE file in the root of the source | 5 * that can be found in the LICENSE file in the root of the source |
6 * tree. An additional intellectual property rights grant can be found | 6 * tree. An additional intellectual property rights grant can be found |
7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may |
8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. |
9 */ | 9 */ |
10 | 10 |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
72 static const int kMinPort = 10000; | 72 static const int kMinPort = 10000; |
73 static const int kMaxPort = 10099; | 73 static const int kMaxPort = 10099; |
74 | 74 |
75 // Based on ICE_UFRAG_LENGTH | 75 // Based on ICE_UFRAG_LENGTH |
76 static const char kIceUfrag0[] = "UF00"; | 76 static const char kIceUfrag0[] = "UF00"; |
77 // Based on ICE_PWD_LENGTH | 77 // Based on ICE_PWD_LENGTH |
78 static const char kIcePwd0[] = "TESTICEPWD00000000000000"; | 78 static const char kIcePwd0[] = "TESTICEPWD00000000000000"; |
79 | 79 |
80 static const char kContentName[] = "test content"; | 80 static const char kContentName[] = "test content"; |
81 | 81 |
82 static const int kDefaultAllocationTimeout = 1000; | 82 static const int kDefaultAllocationTimeout = 3000; |
83 static const char kTurnUsername[] = "test"; | 83 static const char kTurnUsername[] = "test"; |
84 static const char kTurnPassword[] = "test"; | 84 static const char kTurnPassword[] = "test"; |
85 | 85 |
86 // STUN timeout (with all retries) is 9500ms. | 86 // STUN timeout (with all retries) is 9500ms. |
87 // Add some margin of error for slow bots. | 87 // Add some margin of error for slow bots. |
88 // TODO(deadbeef): Use simulated clock instead of just increasing timeouts to | 88 // TODO(deadbeef): Use simulated clock instead of just increasing timeouts to |
89 // fix flaky tests. | 89 // fix flaky tests. |
90 static const int kStunTimeoutMs = 15000; | 90 static const int kStunTimeoutMs = 15000; |
91 | 91 |
92 namespace cricket { | 92 namespace cricket { |
(...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
236 const std::string& ice_ufrag, | 236 const std::string& ice_ufrag, |
237 const std::string& ice_pwd) { | 237 const std::string& ice_pwd) { |
238 std::unique_ptr<PortAllocatorSession> session = | 238 std::unique_ptr<PortAllocatorSession> session = |
239 allocator_->CreateSession(content_name, component, ice_ufrag, ice_pwd); | 239 allocator_->CreateSession(content_name, component, ice_ufrag, ice_pwd); |
240 session->SignalPortReady.connect(this, | 240 session->SignalPortReady.connect(this, |
241 &BasicPortAllocatorTest::OnPortReady); | 241 &BasicPortAllocatorTest::OnPortReady); |
242 session->SignalPortsPruned.connect(this, | 242 session->SignalPortsPruned.connect(this, |
243 &BasicPortAllocatorTest::OnPortsPruned); | 243 &BasicPortAllocatorTest::OnPortsPruned); |
244 session->SignalCandidatesReady.connect( | 244 session->SignalCandidatesReady.connect( |
245 this, &BasicPortAllocatorTest::OnCandidatesReady); | 245 this, &BasicPortAllocatorTest::OnCandidatesReady); |
| 246 session->SignalCandidatesRemoved.connect( |
| 247 this, &BasicPortAllocatorTest::OnCandidatesRemoved); |
246 session->SignalCandidatesAllocationDone.connect( | 248 session->SignalCandidatesAllocationDone.connect( |
247 this, &BasicPortAllocatorTest::OnCandidatesAllocationDone); | 249 this, &BasicPortAllocatorTest::OnCandidatesAllocationDone); |
248 return session; | 250 return session; |
249 } | 251 } |
250 | 252 |
251 // Return true if the addresses are the same, or the port is 0 in |pattern| | 253 // Return true if the addresses are the same, or the port is 0 in |pattern| |
252 // (acting as a wildcard) and the IPs are the same. | 254 // (acting as a wildcard) and the IPs are the same. |
253 // Even with a wildcard port, the port of the address should be nonzero if | 255 // Even with a wildcard port, the port of the address should be nonzero if |
254 // the IP is nonzero. | 256 // the IP is nonzero. |
255 static bool AddressMatch(const SocketAddress& address, | 257 static bool AddressMatch(const SocketAddress& address, |
(...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
397 EXPECT_PRED5(HasCandidateWithRelatedAddr, candidates_, "relay", "udp", | 399 EXPECT_PRED5(HasCandidateWithRelatedAddr, candidates_, "relay", "udp", |
398 rtc::SocketAddress(relay_candidate_tcp_transport_addr, 0), | 400 rtc::SocketAddress(relay_candidate_tcp_transport_addr, 0), |
399 rtc::SocketAddress(stun_candidate_addr, 0)); | 401 rtc::SocketAddress(stun_candidate_addr, 0)); |
400 ++total_candidates; | 402 ++total_candidates; |
401 } | 403 } |
402 | 404 |
403 EXPECT_EQ(total_candidates, candidates_.size()); | 405 EXPECT_EQ(total_candidates, candidates_.size()); |
404 EXPECT_EQ(total_ports, ports_.size()); | 406 EXPECT_EQ(total_ports, ports_.size()); |
405 } | 407 } |
406 | 408 |
| 409 rtc::VirtualSocketServer* virtual_socket_server() { return vss_.get(); } |
| 410 |
407 protected: | 411 protected: |
408 BasicPortAllocator& allocator() { return *allocator_; } | 412 BasicPortAllocator& allocator() { return *allocator_; } |
409 | 413 |
410 void OnPortReady(PortAllocatorSession* ses, PortInterface* port) { | 414 void OnPortReady(PortAllocatorSession* ses, PortInterface* port) { |
411 LOG(LS_INFO) << "OnPortReady: " << port->ToString(); | 415 LOG(LS_INFO) << "OnPortReady: " << port->ToString(); |
412 ports_.push_back(port); | 416 ports_.push_back(port); |
413 // Make sure the new port is added to ReadyPorts. | 417 // Make sure the new port is added to ReadyPorts. |
414 auto ready_ports = ses->ReadyPorts(); | 418 auto ready_ports = ses->ReadyPorts(); |
415 EXPECT_NE(ready_ports.end(), | 419 EXPECT_NE(ready_ports.end(), |
416 std::find(ready_ports.begin(), ready_ports.end(), port)); | 420 std::find(ready_ports.begin(), ready_ports.end(), port)); |
(...skipping 22 matching lines...) Expand all Loading... |
439 } | 443 } |
440 // Make sure the new candidates are added to Candidates. | 444 // Make sure the new candidates are added to Candidates. |
441 auto ses_candidates = ses->ReadyCandidates(); | 445 auto ses_candidates = ses->ReadyCandidates(); |
442 for (const Candidate& candidate : candidates) { | 446 for (const Candidate& candidate : candidates) { |
443 EXPECT_NE( | 447 EXPECT_NE( |
444 ses_candidates.end(), | 448 ses_candidates.end(), |
445 std::find(ses_candidates.begin(), ses_candidates.end(), candidate)); | 449 std::find(ses_candidates.begin(), ses_candidates.end(), candidate)); |
446 } | 450 } |
447 } | 451 } |
448 | 452 |
| 453 void OnCandidatesRemoved(PortAllocatorSession* session, |
| 454 const std::vector<Candidate>& removed_candidates) { |
| 455 auto new_end = std::remove_if( |
| 456 candidates_.begin(), candidates_.end(), |
| 457 [removed_candidates](Candidate& candidate) { |
| 458 for (const Candidate& removed_candidate : removed_candidates) { |
| 459 if (candidate.MatchesForRemoval(removed_candidate)) { |
| 460 return true; |
| 461 } |
| 462 } |
| 463 return false; |
| 464 }); |
| 465 candidates_.erase(new_end, candidates_.end()); |
| 466 } |
| 467 |
449 bool HasRelayAddress(const ProtocolAddress& proto_addr) { | 468 bool HasRelayAddress(const ProtocolAddress& proto_addr) { |
450 for (size_t i = 0; i < allocator_->turn_servers().size(); ++i) { | 469 for (size_t i = 0; i < allocator_->turn_servers().size(); ++i) { |
451 RelayServerConfig server_config = allocator_->turn_servers()[i]; | 470 RelayServerConfig server_config = allocator_->turn_servers()[i]; |
452 PortList::const_iterator relay_port; | 471 PortList::const_iterator relay_port; |
453 for (relay_port = server_config.ports.begin(); | 472 for (relay_port = server_config.ports.begin(); |
454 relay_port != server_config.ports.end(); ++relay_port) { | 473 relay_port != server_config.ports.end(); ++relay_port) { |
455 if (proto_addr.address == relay_port->address && | 474 if (proto_addr.address == relay_port->address && |
456 proto_addr.proto == relay_port->proto) | 475 proto_addr.proto == relay_port->proto) |
457 return true; | 476 return true; |
458 } | 477 } |
(...skipping 13 matching lines...) Expand all Loading... |
472 | 491 |
473 ServerAddresses stun_servers; | 492 ServerAddresses stun_servers; |
474 if (!stun_server.IsNil()) { | 493 if (!stun_server.IsNil()) { |
475 stun_servers.insert(stun_server); | 494 stun_servers.insert(stun_server); |
476 } | 495 } |
477 allocator_.reset(new BasicPortAllocator( | 496 allocator_.reset(new BasicPortAllocator( |
478 &network_manager_, nat_socket_factory_.get(), stun_servers)); | 497 &network_manager_, nat_socket_factory_.get(), stun_servers)); |
479 allocator().set_step_delay(kMinimumStepDelay); | 498 allocator().set_step_delay(kMinimumStepDelay); |
480 } | 499 } |
481 | 500 |
| 501 void TestUdpTurnPortPrunesTcpTurnPort() { |
| 502 turn_server_.AddInternalSocket(kTurnTcpIntAddr, PROTO_TCP); |
| 503 AddInterface(kClientAddr); |
| 504 allocator_.reset(new BasicPortAllocator(&network_manager_)); |
| 505 allocator_->SetConfiguration(allocator_->stun_servers(), |
| 506 allocator_->turn_servers(), 0, true); |
| 507 AddTurnServers(kTurnUdpIntAddr, kTurnTcpIntAddr); |
| 508 allocator_->set_step_delay(kMinimumStepDelay); |
| 509 allocator_->set_flags(allocator().flags() | |
| 510 PORTALLOCATOR_ENABLE_SHARED_SOCKET | |
| 511 PORTALLOCATOR_DISABLE_TCP); |
| 512 |
| 513 EXPECT_TRUE(CreateSession(ICE_CANDIDATE_COMPONENT_RTP)); |
| 514 session_->StartGettingPorts(); |
| 515 EXPECT_TRUE_WAIT(candidate_allocation_done_, kDefaultAllocationTimeout); |
| 516 // Only 2 ports (one STUN and one TURN) are actually being used. |
| 517 EXPECT_EQ(2U, session_->ReadyPorts().size()); |
| 518 // We have verified that each port, when it is added to |ports_|, it is |
| 519 // found in |ready_ports|, and when it is pruned, it is not found in |
| 520 // |ready_ports|, so we only need to verify the content in one of them. |
| 521 EXPECT_EQ(2U, ports_.size()); |
| 522 EXPECT_EQ(1, CountPorts(ports_, "local", PROTO_UDP, kClientAddr)); |
| 523 EXPECT_EQ(1, CountPorts(ports_, "relay", PROTO_UDP, kClientAddr)); |
| 524 EXPECT_EQ(0, CountPorts(ports_, "relay", PROTO_TCP, kClientAddr)); |
| 525 |
| 526 // Now that we remove candidates when a TURN port is pruned, |candidates_| |
| 527 // should only contains two candidates regardless whether the TCP TURN port |
| 528 // is created before or after the UDP turn port. |
| 529 EXPECT_EQ(2U, candidates_.size()); |
| 530 // There will only be 2 candidates in |ready_candidates| because it only |
| 531 // includes the candidates in the ready ports. |
| 532 const std::vector<Candidate>& ready_candidates = |
| 533 session_->ReadyCandidates(); |
| 534 EXPECT_EQ(2U, ready_candidates.size()); |
| 535 EXPECT_PRED4(HasCandidate, ready_candidates, "local", "udp", kClientAddr); |
| 536 EXPECT_PRED4(HasCandidate, ready_candidates, "relay", "udp", |
| 537 rtc::SocketAddress(kTurnUdpExtAddr.ipaddr(), 0)); |
| 538 } |
| 539 |
| 540 void TestIPv6TurnPortPrunesIPv4TurnPort() { |
| 541 turn_server_.AddInternalSocket(kTurnUdpIntIPv6Addr, PROTO_UDP); |
| 542 // Add two IP addresses on the same interface. |
| 543 AddInterface(kClientAddr, "net1"); |
| 544 AddInterface(kClientIPv6Addr, "net1"); |
| 545 allocator_.reset(new BasicPortAllocator(&network_manager_)); |
| 546 allocator_->SetConfiguration(allocator_->stun_servers(), |
| 547 allocator_->turn_servers(), 0, true); |
| 548 AddTurnServers(kTurnUdpIntIPv6Addr, rtc::SocketAddress()); |
| 549 AddTurnServers(kTurnUdpIntAddr, rtc::SocketAddress()); |
| 550 |
| 551 allocator_->set_step_delay(kMinimumStepDelay); |
| 552 allocator_->set_flags( |
| 553 allocator().flags() | PORTALLOCATOR_ENABLE_SHARED_SOCKET | |
| 554 PORTALLOCATOR_ENABLE_IPV6 | PORTALLOCATOR_DISABLE_TCP); |
| 555 |
| 556 EXPECT_TRUE(CreateSession(ICE_CANDIDATE_COMPONENT_RTP)); |
| 557 session_->StartGettingPorts(); |
| 558 EXPECT_TRUE_WAIT(candidate_allocation_done_, kDefaultAllocationTimeout); |
| 559 // Three ports (one IPv4 STUN, one IPv6 STUN and one TURN) will be ready. |
| 560 EXPECT_EQ(3U, session_->ReadyPorts().size()); |
| 561 EXPECT_EQ(3U, ports_.size()); |
| 562 EXPECT_EQ(1, CountPorts(ports_, "local", PROTO_UDP, kClientAddr)); |
| 563 EXPECT_EQ(1, CountPorts(ports_, "local", PROTO_UDP, kClientIPv6Addr)); |
| 564 EXPECT_EQ(1, CountPorts(ports_, "relay", PROTO_UDP, kClientIPv6Addr)); |
| 565 EXPECT_EQ(0, CountPorts(ports_, "relay", PROTO_UDP, kClientAddr)); |
| 566 |
| 567 // Now that we remove candidates when a TURN port is pruned, there will be |
| 568 // exactly 3 candidates in both |candidates_| and |ready_candidates|. |
| 569 EXPECT_EQ(3U, candidates_.size()); |
| 570 const std::vector<Candidate>& ready_candidates = |
| 571 session_->ReadyCandidates(); |
| 572 EXPECT_EQ(3U, ready_candidates.size()); |
| 573 EXPECT_PRED4(HasCandidate, ready_candidates, "local", "udp", kClientAddr); |
| 574 EXPECT_PRED4(HasCandidate, ready_candidates, "relay", "udp", |
| 575 rtc::SocketAddress(kTurnUdpExtAddr.ipaddr(), 0)); |
| 576 } |
| 577 |
| 578 void TestEachInterfaceHasItsOwnTurnPorts() { |
| 579 turn_server_.AddInternalSocket(kTurnTcpIntAddr, PROTO_TCP); |
| 580 turn_server_.AddInternalSocket(kTurnUdpIntIPv6Addr, PROTO_UDP); |
| 581 turn_server_.AddInternalSocket(kTurnTcpIntIPv6Addr, PROTO_TCP); |
| 582 // Add two interfaces both having IPv4 and IPv6 addresses. |
| 583 AddInterface(kClientAddr, "net1", rtc::ADAPTER_TYPE_WIFI); |
| 584 AddInterface(kClientIPv6Addr, "net1", rtc::ADAPTER_TYPE_WIFI); |
| 585 AddInterface(kClientAddr2, "net2", rtc::ADAPTER_TYPE_CELLULAR); |
| 586 AddInterface(kClientIPv6Addr2, "net2", rtc::ADAPTER_TYPE_CELLULAR); |
| 587 allocator_.reset(new BasicPortAllocator(&network_manager_)); |
| 588 allocator_->SetConfiguration(allocator_->stun_servers(), |
| 589 allocator_->turn_servers(), 0, true); |
| 590 // Have both UDP/TCP and IPv4/IPv6 TURN ports. |
| 591 AddTurnServers(kTurnUdpIntAddr, kTurnTcpIntAddr); |
| 592 AddTurnServers(kTurnUdpIntIPv6Addr, kTurnTcpIntIPv6Addr); |
| 593 |
| 594 allocator_->set_step_delay(kMinimumStepDelay); |
| 595 allocator_->set_flags(allocator().flags() | |
| 596 PORTALLOCATOR_ENABLE_SHARED_SOCKET | |
| 597 PORTALLOCATOR_ENABLE_IPV6); |
| 598 EXPECT_TRUE(CreateSession(ICE_CANDIDATE_COMPONENT_RTP)); |
| 599 session_->StartGettingPorts(); |
| 600 EXPECT_TRUE_WAIT(candidate_allocation_done_, kDefaultAllocationTimeout); |
| 601 // 10 ports (4 STUN and 1 TURN ports on each interface) will be ready to |
| 602 // use. |
| 603 EXPECT_EQ(10U, session_->ReadyPorts().size()); |
| 604 EXPECT_EQ(10U, ports_.size()); |
| 605 EXPECT_EQ(1, CountPorts(ports_, "local", PROTO_UDP, kClientAddr)); |
| 606 EXPECT_EQ(1, CountPorts(ports_, "local", PROTO_UDP, kClientAddr2)); |
| 607 EXPECT_EQ(1, CountPorts(ports_, "local", PROTO_UDP, kClientIPv6Addr)); |
| 608 EXPECT_EQ(1, CountPorts(ports_, "local", PROTO_UDP, kClientIPv6Addr2)); |
| 609 EXPECT_EQ(1, CountPorts(ports_, "local", PROTO_TCP, kClientAddr)); |
| 610 EXPECT_EQ(1, CountPorts(ports_, "local", PROTO_TCP, kClientAddr2)); |
| 611 EXPECT_EQ(1, CountPorts(ports_, "local", PROTO_TCP, kClientIPv6Addr)); |
| 612 EXPECT_EQ(1, CountPorts(ports_, "local", PROTO_TCP, kClientIPv6Addr2)); |
| 613 EXPECT_EQ(1, CountPorts(ports_, "relay", PROTO_UDP, kClientIPv6Addr)); |
| 614 EXPECT_EQ(1, CountPorts(ports_, "relay", PROTO_UDP, kClientIPv6Addr2)); |
| 615 |
| 616 // Now that we remove candidates when TURN ports are pruned, there will be |
| 617 // exactly 10 candidates in |candidates_|. |
| 618 EXPECT_EQ(10U, candidates_.size()); |
| 619 const std::vector<Candidate>& ready_candidates = |
| 620 session_->ReadyCandidates(); |
| 621 EXPECT_EQ(10U, ready_candidates.size()); |
| 622 EXPECT_PRED4(HasCandidate, ready_candidates, "local", "udp", kClientAddr); |
| 623 EXPECT_PRED4(HasCandidate, ready_candidates, "local", "udp", kClientAddr2); |
| 624 EXPECT_PRED4(HasCandidate, ready_candidates, "local", "udp", |
| 625 kClientIPv6Addr); |
| 626 EXPECT_PRED4(HasCandidate, ready_candidates, "local", "udp", |
| 627 kClientIPv6Addr2); |
| 628 EXPECT_PRED4(HasCandidate, ready_candidates, "local", "tcp", kClientAddr); |
| 629 EXPECT_PRED4(HasCandidate, ready_candidates, "local", "tcp", kClientAddr2); |
| 630 EXPECT_PRED4(HasCandidate, ready_candidates, "local", "tcp", |
| 631 kClientIPv6Addr); |
| 632 EXPECT_PRED4(HasCandidate, ready_candidates, "local", "tcp", |
| 633 kClientIPv6Addr2); |
| 634 EXPECT_PRED4(HasCandidate, ready_candidates, "relay", "udp", |
| 635 rtc::SocketAddress(kTurnUdpExtAddr.ipaddr(), 0)); |
| 636 } |
| 637 |
482 std::unique_ptr<rtc::PhysicalSocketServer> pss_; | 638 std::unique_ptr<rtc::PhysicalSocketServer> pss_; |
483 std::unique_ptr<rtc::VirtualSocketServer> vss_; | 639 std::unique_ptr<rtc::VirtualSocketServer> vss_; |
484 std::unique_ptr<rtc::FirewallSocketServer> fss_; | 640 std::unique_ptr<rtc::FirewallSocketServer> fss_; |
485 rtc::SocketServerScope ss_scope_; | 641 rtc::SocketServerScope ss_scope_; |
486 std::unique_ptr<rtc::NATServer> nat_server_; | 642 std::unique_ptr<rtc::NATServer> nat_server_; |
487 rtc::NATSocketFactory nat_factory_; | 643 rtc::NATSocketFactory nat_factory_; |
488 std::unique_ptr<rtc::BasicPacketSocketFactory> nat_socket_factory_; | 644 std::unique_ptr<rtc::BasicPacketSocketFactory> nat_socket_factory_; |
489 std::unique_ptr<TestStunServer> stun_server_; | 645 std::unique_ptr<TestStunServer> stun_server_; |
490 TestRelayServer relay_server_; | 646 TestRelayServer relay_server_; |
491 TestTurnServer turn_server_; | 647 TestTurnServer turn_server_; |
(...skipping 712 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1204 ASSERT_EQ(3U, ports_.size()); | 1360 ASSERT_EQ(3U, ports_.size()); |
1205 EXPECT_PRED4(HasCandidate, candidates_, "local", "udp", kClientAddr); | 1361 EXPECT_PRED4(HasCandidate, candidates_, "local", "udp", kClientAddr); |
1206 EXPECT_PRED4(HasCandidate, candidates_, "relay", "udp", | 1362 EXPECT_PRED4(HasCandidate, candidates_, "relay", "udp", |
1207 rtc::SocketAddress(kTurnUdpExtAddr.ipaddr(), 0)); | 1363 rtc::SocketAddress(kTurnUdpExtAddr.ipaddr(), 0)); |
1208 EXPECT_PRED4(HasCandidate, candidates_, "relay", "udp", | 1364 EXPECT_PRED4(HasCandidate, candidates_, "relay", "udp", |
1209 rtc::SocketAddress(kTurnUdpExtAddr.ipaddr(), 0)); | 1365 rtc::SocketAddress(kTurnUdpExtAddr.ipaddr(), 0)); |
1210 EXPECT_TRUE_WAIT(candidate_allocation_done_, kDefaultAllocationTimeout); | 1366 EXPECT_TRUE_WAIT(candidate_allocation_done_, kDefaultAllocationTimeout); |
1211 EXPECT_EQ(3U, candidates_.size()); | 1367 EXPECT_EQ(3U, candidates_.size()); |
1212 } | 1368 } |
1213 | 1369 |
1214 // Test that if prune_turn_ports is set, TCP TurnPort will not | 1370 // Test that if prune_turn_ports is set, TCP TURN port will not be used |
1215 // be used if UDP TurnPort is used. | 1371 // if UDP TurnPort is used, given that TCP TURN port becomes ready first. |
1216 TEST_F(BasicPortAllocatorTest, TestUdpTurnPortPrunesTcpTurnPorts) { | 1372 TEST_F(BasicPortAllocatorTest, |
1217 turn_server_.AddInternalSocket(kTurnTcpIntAddr, PROTO_TCP); | 1373 TestUdpTurnPortPrunesTcpTurnPortWithTcpPortReadyFirst) { |
1218 AddInterface(kClientAddr); | 1374 // UDP has longer delay than TCP so that TCP TURN port becomes ready first. |
1219 allocator_.reset(new BasicPortAllocator(&network_manager_)); | 1375 virtual_socket_server()->SetDelayOnAddress(kTurnUdpIntAddr, 200); |
1220 allocator_->SetConfiguration(allocator_->stun_servers(), | 1376 virtual_socket_server()->SetDelayOnAddress(kTurnTcpIntAddr, 100); |
1221 allocator_->turn_servers(), 0, true); | |
1222 AddTurnServers(kTurnUdpIntAddr, kTurnTcpIntAddr); | |
1223 allocator_->set_step_delay(kMinimumStepDelay); | |
1224 allocator_->set_flags(allocator().flags() | | |
1225 PORTALLOCATOR_ENABLE_SHARED_SOCKET | | |
1226 PORTALLOCATOR_DISABLE_TCP); | |
1227 | 1377 |
1228 EXPECT_TRUE(CreateSession(ICE_CANDIDATE_COMPONENT_RTP)); | 1378 TestUdpTurnPortPrunesTcpTurnPort(); |
1229 session_->StartGettingPorts(); | |
1230 EXPECT_TRUE_WAIT(candidate_allocation_done_, kDefaultAllocationTimeout); | |
1231 // Only 2 ports (one STUN and one TURN) are actually being used. | |
1232 EXPECT_EQ(2U, session_->ReadyPorts().size()); | |
1233 // We have verified that each port, when it is added to |ports_|, it is found | |
1234 // in |ready_ports|, and when it is pruned, it is not found in |ready_ports|, | |
1235 // so we only need to verify the content in one of them. | |
1236 EXPECT_EQ(2U, ports_.size()); | |
1237 EXPECT_EQ(1, CountPorts(ports_, "local", PROTO_UDP, kClientAddr)); | |
1238 EXPECT_EQ(1, CountPorts(ports_, "relay", PROTO_UDP, kClientAddr)); | |
1239 EXPECT_EQ(0, CountPorts(ports_, "relay", PROTO_TCP, kClientAddr)); | |
1240 | |
1241 // We don't remove candidates, so the size of |candidates_| will depend on | |
1242 // when the TCP TURN port becomes ready. If it is ready after the UDP TURN | |
1243 // port becomes ready, its candidates will be used there will be 3 candidates. | |
1244 // Otherwise there will be only 2 candidates. | |
1245 EXPECT_LE(2U, candidates_.size()); | |
1246 // There will only be 2 candidates in |ready_candidates| because it only | |
1247 // includes the candidates in the ready ports. | |
1248 const std::vector<Candidate>& ready_candidates = session_->ReadyCandidates(); | |
1249 EXPECT_EQ(2U, ready_candidates.size()); | |
1250 EXPECT_PRED4(HasCandidate, ready_candidates, "local", "udp", kClientAddr); | |
1251 EXPECT_PRED4(HasCandidate, ready_candidates, "relay", "udp", | |
1252 rtc::SocketAddress(kTurnUdpExtAddr.ipaddr(), 0)); | |
1253 } | 1379 } |
1254 | 1380 |
1255 // Tests that if prune_turn_ports is set, IPv4 TurnPort will not | 1381 // Test that if prune_turn_ports is set, TCP TURN port will not be used |
1256 // be used if IPv6 TurnPort is used. | 1382 // if UDP TurnPort is used, given that UDP TURN port becomes ready first. |
1257 TEST_F(BasicPortAllocatorTest, TestIPv6TurnPortPrunesIPv4TurnPorts) { | 1383 TEST_F(BasicPortAllocatorTest, |
1258 turn_server_.AddInternalSocket(kTurnUdpIntIPv6Addr, PROTO_UDP); | 1384 TestUdpTurnPortPrunesTcpTurnPortsWithUdpPortReadyFirst) { |
1259 // Add two IP addresses on the same interface. | 1385 // UDP has shorter delay than TCP so that UDP TURN port becomes ready first. |
1260 AddInterface(kClientAddr, "net1"); | 1386 virtual_socket_server()->SetDelayOnAddress(kTurnUdpIntAddr, 100); |
1261 AddInterface(kClientIPv6Addr, "net1"); | 1387 virtual_socket_server()->SetDelayOnAddress(kTurnTcpIntAddr, 200); |
1262 allocator_.reset(new BasicPortAllocator(&network_manager_)); | |
1263 allocator_->SetConfiguration(allocator_->stun_servers(), | |
1264 allocator_->turn_servers(), 0, true); | |
1265 AddTurnServers(kTurnUdpIntIPv6Addr, rtc::SocketAddress()); | |
1266 | 1388 |
1267 allocator_->set_step_delay(kMinimumStepDelay); | 1389 TestUdpTurnPortPrunesTcpTurnPort(); |
1268 allocator_->set_flags(allocator().flags() | | 1390 } |
1269 PORTALLOCATOR_ENABLE_SHARED_SOCKET | | |
1270 PORTALLOCATOR_ENABLE_IPV6 | PORTALLOCATOR_DISABLE_TCP); | |
1271 | 1391 |
1272 EXPECT_TRUE(CreateSession(ICE_CANDIDATE_COMPONENT_RTP)); | 1392 // Tests that if prune_turn_ports is set, IPv4 TurnPort will not be used |
1273 session_->StartGettingPorts(); | 1393 // if IPv6 TurnPort is used, given that IPv4 TURN port becomes ready first. |
1274 EXPECT_TRUE_WAIT(candidate_allocation_done_, kDefaultAllocationTimeout); | 1394 TEST_F(BasicPortAllocatorTest, |
1275 // Three ports (one IPv4 STUN, one IPv6 STUN and one TURN) will be ready. | 1395 TestIPv6TurnPortPrunesIPv4TurnPortWithIPv4PortReadyFirst) { |
1276 EXPECT_EQ(3U, session_->ReadyPorts().size()); | 1396 // IPv6 has longer delay than IPv4, so that IPv4 TURN port becomes ready |
1277 EXPECT_EQ(3U, ports_.size()); | 1397 // first. |
1278 EXPECT_EQ(1, CountPorts(ports_, "local", PROTO_UDP, kClientAddr)); | 1398 virtual_socket_server()->SetDelayOnAddress(kTurnUdpIntAddr, 100); |
1279 EXPECT_EQ(1, CountPorts(ports_, "local", PROTO_UDP, kClientIPv6Addr)); | 1399 virtual_socket_server()->SetDelayOnAddress(kTurnUdpIntIPv6Addr, 200); |
1280 EXPECT_EQ(1, CountPorts(ports_, "relay", PROTO_UDP, kClientIPv6Addr)); | |
1281 EXPECT_EQ(0, CountPorts(ports_, "relay", PROTO_UDP, kClientAddr)); | |
1282 | 1400 |
1283 // We don't remove candidates, so there may be more than 3 elemenets in | 1401 TestIPv6TurnPortPrunesIPv4TurnPort(); |
1284 // |candidates_|, although |ready_candidates| only includes the candidates | 1402 } |
1285 // in |ready_ports|. | 1403 |
1286 EXPECT_LE(3U, candidates_.size()); | 1404 // Tests that if prune_turn_ports is set, IPv4 TurnPort will not be used |
1287 const std::vector<Candidate>& ready_candidates = session_->ReadyCandidates(); | 1405 // if IPv6 TurnPort is used, given that IPv6 TURN port becomes ready first. |
1288 EXPECT_EQ(3U, ready_candidates.size()); | 1406 TEST_F(BasicPortAllocatorTest, |
1289 EXPECT_PRED4(HasCandidate, ready_candidates, "local", "udp", kClientAddr); | 1407 TestIPv6TurnPortPrunesIPv4TurnPortWithIPv6PortReadyFirst) { |
1290 EXPECT_PRED4(HasCandidate, ready_candidates, "relay", "udp", | 1408 // IPv6 has longer delay than IPv4, so that IPv6 TURN port becomes ready |
1291 rtc::SocketAddress(kTurnUdpExtAddr.ipaddr(), 0)); | 1409 // first. |
| 1410 virtual_socket_server()->SetDelayOnAddress(kTurnUdpIntAddr, 200); |
| 1411 virtual_socket_server()->SetDelayOnAddress(kTurnUdpIntIPv6Addr, 100); |
| 1412 |
| 1413 TestIPv6TurnPortPrunesIPv4TurnPort(); |
1292 } | 1414 } |
1293 | 1415 |
1294 // Tests that if prune_turn_ports is set, each network interface | 1416 // Tests that if prune_turn_ports is set, each network interface |
1295 // will has its own set of TurnPorts based on their priorities. | 1417 // will has its own set of TurnPorts based on their priorities, in the default |
1296 TEST_F(BasicPortAllocatorTest, TestEachInterfaceHasItsOwnTurnPorts) { | 1418 // case where no transit delay is set. |
1297 turn_server_.AddInternalSocket(kTurnTcpIntAddr, PROTO_TCP); | 1419 TEST_F(BasicPortAllocatorTest, TestEachInterfaceHasItsOwnTurnPortsNoDelay) { |
1298 turn_server_.AddInternalSocket(kTurnUdpIntIPv6Addr, PROTO_UDP); | 1420 TestEachInterfaceHasItsOwnTurnPorts(); |
1299 turn_server_.AddInternalSocket(kTurnTcpIntIPv6Addr, PROTO_TCP); | 1421 } |
1300 // Add two interfaces both having IPv4 and IPv6 addresses. | |
1301 AddInterface(kClientAddr, "net1", rtc::ADAPTER_TYPE_WIFI); | |
1302 AddInterface(kClientIPv6Addr, "net1", rtc::ADAPTER_TYPE_WIFI); | |
1303 AddInterface(kClientAddr2, "net2", rtc::ADAPTER_TYPE_CELLULAR); | |
1304 AddInterface(kClientIPv6Addr2, "net2", rtc::ADAPTER_TYPE_CELLULAR); | |
1305 allocator_.reset(new BasicPortAllocator(&network_manager_)); | |
1306 allocator_->SetConfiguration(allocator_->stun_servers(), | |
1307 allocator_->turn_servers(), 0, true); | |
1308 // Have both UDP/TCP and IPv4/IPv6 TURN ports. | |
1309 AddTurnServers(kTurnUdpIntAddr, kTurnTcpIntAddr); | |
1310 AddTurnServers(kTurnUdpIntIPv6Addr, kTurnTcpIntIPv6Addr); | |
1311 | 1422 |
1312 allocator_->set_step_delay(kMinimumStepDelay); | 1423 // Tests that if prune_turn_ports is set, each network interface |
1313 allocator_->set_flags(allocator().flags() | | 1424 // will has its own set of TurnPorts based on their priorities, given that |
1314 PORTALLOCATOR_ENABLE_SHARED_SOCKET | | 1425 // IPv4/TCP TURN port becomes ready first. |
1315 PORTALLOCATOR_ENABLE_IPV6); | 1426 TEST_F(BasicPortAllocatorTest, |
1316 EXPECT_TRUE(CreateSession(ICE_CANDIDATE_COMPONENT_RTP)); | 1427 TestEachInterfaceHasItsOwnTurnPortsWithTcpIPv4ReadyFirst) { |
1317 session_->StartGettingPorts(); | 1428 // IPv6/UDP have longer delay than IPv4/TCP, so that IPv4/TCP TURN port |
1318 EXPECT_TRUE_WAIT(candidate_allocation_done_, kDefaultAllocationTimeout); | 1429 // becomes ready last. |
1319 // 10 ports (4 STUN and 1 TURN ports on each interface) will be ready to use. | 1430 virtual_socket_server()->SetDelayOnAddress(kTurnTcpIntAddr, 10); |
1320 EXPECT_EQ(10U, session_->ReadyPorts().size()); | 1431 virtual_socket_server()->SetDelayOnAddress(kTurnUdpIntAddr, 100); |
1321 EXPECT_EQ(10U, ports_.size()); | 1432 virtual_socket_server()->SetDelayOnAddress(kTurnTcpIntIPv6Addr, 20); |
1322 EXPECT_EQ(1, CountPorts(ports_, "local", PROTO_UDP, kClientAddr)); | 1433 virtual_socket_server()->SetDelayOnAddress(kTurnUdpIntIPv6Addr, 300); |
1323 EXPECT_EQ(1, CountPorts(ports_, "local", PROTO_UDP, kClientAddr2)); | |
1324 EXPECT_EQ(1, CountPorts(ports_, "local", PROTO_UDP, kClientIPv6Addr)); | |
1325 EXPECT_EQ(1, CountPorts(ports_, "local", PROTO_UDP, kClientIPv6Addr2)); | |
1326 EXPECT_EQ(1, CountPorts(ports_, "local", PROTO_TCP, kClientAddr)); | |
1327 EXPECT_EQ(1, CountPorts(ports_, "local", PROTO_TCP, kClientAddr2)); | |
1328 EXPECT_EQ(1, CountPorts(ports_, "local", PROTO_TCP, kClientIPv6Addr)); | |
1329 EXPECT_EQ(1, CountPorts(ports_, "local", PROTO_TCP, kClientIPv6Addr2)); | |
1330 EXPECT_EQ(1, CountPorts(ports_, "relay", PROTO_UDP, kClientIPv6Addr)); | |
1331 EXPECT_EQ(1, CountPorts(ports_, "relay", PROTO_UDP, kClientIPv6Addr2)); | |
1332 | 1434 |
1333 // We don't remove candidates, so there may be more than 10 candidates | 1435 TestEachInterfaceHasItsOwnTurnPorts(); |
1334 // in |candidates_|. | |
1335 EXPECT_LE(10U, candidates_.size()); | |
1336 const std::vector<Candidate>& ready_candidates = session_->ReadyCandidates(); | |
1337 EXPECT_EQ(10U, ready_candidates.size()); | |
1338 EXPECT_PRED4(HasCandidate, ready_candidates, "local", "udp", kClientAddr); | |
1339 EXPECT_PRED4(HasCandidate, ready_candidates, "local", "udp", kClientAddr2); | |
1340 EXPECT_PRED4(HasCandidate, ready_candidates, "local", "udp", kClientIPv6Addr); | |
1341 EXPECT_PRED4(HasCandidate, ready_candidates, "local", "udp", | |
1342 kClientIPv6Addr2); | |
1343 EXPECT_PRED4(HasCandidate, ready_candidates, "local", "tcp", kClientAddr); | |
1344 EXPECT_PRED4(HasCandidate, ready_candidates, "local", "tcp", kClientAddr2); | |
1345 EXPECT_PRED4(HasCandidate, ready_candidates, "local", "tcp", kClientIPv6Addr); | |
1346 EXPECT_PRED4(HasCandidate, ready_candidates, "local", "tcp", | |
1347 kClientIPv6Addr2); | |
1348 EXPECT_PRED4(HasCandidate, ready_candidates, "relay", "udp", | |
1349 rtc::SocketAddress(kTurnUdpExtAddr.ipaddr(), 0)); | |
1350 } | 1436 } |
1351 | 1437 |
1352 // Testing DNS resolve for the TURN server, this will test AllocationSequence | 1438 // Testing DNS resolve for the TURN server, this will test AllocationSequence |
1353 // handling the unresolved address signal from TurnPort. | 1439 // handling the unresolved address signal from TurnPort. |
1354 TEST_F(BasicPortAllocatorTest, TestSharedSocketWithServerAddressResolve) { | 1440 TEST_F(BasicPortAllocatorTest, TestSharedSocketWithServerAddressResolve) { |
1355 turn_server_.AddInternalSocket(rtc::SocketAddress("127.0.0.1", 3478), | 1441 turn_server_.AddInternalSocket(rtc::SocketAddress("127.0.0.1", 3478), |
1356 PROTO_UDP); | 1442 PROTO_UDP); |
1357 AddInterface(kClientAddr); | 1443 AddInterface(kClientAddr); |
1358 allocator_.reset(new BasicPortAllocator(&network_manager_)); | 1444 allocator_.reset(new BasicPortAllocator(&network_manager_)); |
1359 RelayServerConfig turn_server(RELAY_TURN); | 1445 RelayServerConfig turn_server(RELAY_TURN); |
(...skipping 347 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1707 for (const Candidate& candidate : candidates) { | 1793 for (const Candidate& candidate : candidates) { |
1708 // Expect only relay candidates now that the filter is applied. | 1794 // Expect only relay candidates now that the filter is applied. |
1709 EXPECT_EQ(std::string(RELAY_PORT_TYPE), candidate.type()); | 1795 EXPECT_EQ(std::string(RELAY_PORT_TYPE), candidate.type()); |
1710 // Expect that the raddr is emptied due to the CF_RELAY filter. | 1796 // Expect that the raddr is emptied due to the CF_RELAY filter. |
1711 EXPECT_EQ(candidate.related_address(), | 1797 EXPECT_EQ(candidate.related_address(), |
1712 rtc::EmptySocketAddressWithFamily(candidate.address().family())); | 1798 rtc::EmptySocketAddressWithFamily(candidate.address().family())); |
1713 } | 1799 } |
1714 } | 1800 } |
1715 | 1801 |
1716 } // namespace cricket | 1802 } // namespace cricket |
OLD | NEW |