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

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

Issue 1263663002: Remove GICE. (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Fix tests Created 5 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 /* 1 /*
2 * Copyright 2009 The WebRTC Project Authors. All rights reserved. 2 * Copyright 2009 The WebRTC Project Authors. All rights reserved.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license 4 * Use of this source code is governed by a BSD-style license
5 * that can be found in the LICENSE file in the root of the source 5 * that can be found in the LICENSE file in the root of the source
6 * tree. An additional intellectual property rights grant can be found 6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may 7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree. 8 * be found in the AUTHORS file in the root of the source tree.
9 */ 9 */
10 10
(...skipping 626 matching lines...) Expand 10 before | Expand all | Expand 10 after
637 for (size_t i = 0; i < candidates_.size(); ++i) { 637 for (size_t i = 0; i < candidates_.size(); ++i) {
638 EXPECT_EQ(std::string(cricket::RELAY_PORT_TYPE), candidates_[i].type()); 638 EXPECT_EQ(std::string(cricket::RELAY_PORT_TYPE), candidates_[i].type());
639 EXPECT_EQ( 639 EXPECT_EQ(
640 candidates_[0].related_address(), 640 candidates_[0].related_address(),
641 rtc::EmptySocketAddressWithFamily(candidates_[0].address().family())); 641 rtc::EmptySocketAddressWithFamily(candidates_[0].address().family()));
642 } 642 }
643 } 643 }
644 644
645 TEST_F(PortAllocatorTest, TestCandidateFilterWithHostOnly) { 645 TEST_F(PortAllocatorTest, TestCandidateFilterWithHostOnly) {
646 AddInterface(kClientAddr); 646 AddInterface(kClientAddr);
647 allocator().set_flags(cricket::PORTALLOCATOR_ENABLE_SHARED_UFRAG | 647 allocator().set_flags(cricket::PORTALLOCATOR_ENABLE_SHARED_SOCKET);
648 cricket::PORTALLOCATOR_ENABLE_SHARED_SOCKET);
649 allocator().set_candidate_filter(cricket::CF_HOST); 648 allocator().set_candidate_filter(cricket::CF_HOST);
650 EXPECT_TRUE(CreateSession(cricket::ICE_CANDIDATE_COMPONENT_RTP)); 649 EXPECT_TRUE(CreateSession(cricket::ICE_CANDIDATE_COMPONENT_RTP));
651 session_->StartGettingPorts(); 650 session_->StartGettingPorts();
652 EXPECT_TRUE_WAIT(candidate_allocation_done_, kDefaultAllocationTimeout); 651 EXPECT_TRUE_WAIT(candidate_allocation_done_, kDefaultAllocationTimeout);
653 EXPECT_EQ(2U, candidates_.size()); // Host UDP/TCP candidates only. 652 EXPECT_EQ(2U, candidates_.size()); // Host UDP/TCP candidates only.
654 EXPECT_EQ(2U, ports_.size()); // UDP/TCP ports only. 653 EXPECT_EQ(2U, ports_.size()); // UDP/TCP ports only.
655 for (size_t i = 0; i < candidates_.size(); ++i) { 654 for (size_t i = 0; i < candidates_.size(); ++i) {
656 EXPECT_EQ(std::string(cricket::LOCAL_PORT_TYPE), candidates_[i].type()); 655 EXPECT_EQ(std::string(cricket::LOCAL_PORT_TYPE), candidates_[i].type());
657 } 656 }
658 } 657 }
659 658
660 // Host is behind the NAT. 659 // Host is behind the NAT.
661 TEST_F(PortAllocatorTest, TestCandidateFilterWithReflexiveOnly) { 660 TEST_F(PortAllocatorTest, TestCandidateFilterWithReflexiveOnly) {
662 AddInterface(kPrivateAddr); 661 AddInterface(kPrivateAddr);
663 ResetWithNatServer(kStunAddr); 662 ResetWithNatServer(kStunAddr);
664 663
665 allocator().set_flags(cricket::PORTALLOCATOR_ENABLE_SHARED_UFRAG | 664 allocator().set_flags(cricket::PORTALLOCATOR_ENABLE_SHARED_SOCKET);
666 cricket::PORTALLOCATOR_ENABLE_SHARED_SOCKET);
667 allocator().set_candidate_filter(cricket::CF_REFLEXIVE); 665 allocator().set_candidate_filter(cricket::CF_REFLEXIVE);
668 EXPECT_TRUE(CreateSession(cricket::ICE_CANDIDATE_COMPONENT_RTP)); 666 EXPECT_TRUE(CreateSession(cricket::ICE_CANDIDATE_COMPONENT_RTP));
669 session_->StartGettingPorts(); 667 session_->StartGettingPorts();
670 EXPECT_TRUE_WAIT(candidate_allocation_done_, kDefaultAllocationTimeout); 668 EXPECT_TRUE_WAIT(candidate_allocation_done_, kDefaultAllocationTimeout);
671 // Host is behind NAT, no private address will be exposed. Hence only UDP 669 // Host is behind NAT, no private address will be exposed. Hence only UDP
672 // port with STUN candidate will be sent outside. 670 // port with STUN candidate will be sent outside.
673 EXPECT_EQ(1U, candidates_.size()); // Only STUN candidate. 671 EXPECT_EQ(1U, candidates_.size()); // Only STUN candidate.
674 EXPECT_EQ(1U, ports_.size()); // Only UDP port will be in ready state. 672 EXPECT_EQ(1U, ports_.size()); // Only UDP port will be in ready state.
675 for (size_t i = 0; i < candidates_.size(); ++i) { 673 for (size_t i = 0; i < candidates_.size(); ++i) {
676 EXPECT_EQ(std::string(cricket::STUN_PORT_TYPE), candidates_[i].type()); 674 EXPECT_EQ(std::string(cricket::STUN_PORT_TYPE), candidates_[i].type());
677 EXPECT_EQ( 675 EXPECT_EQ(
678 candidates_[0].related_address(), 676 candidates_[0].related_address(),
679 rtc::EmptySocketAddressWithFamily(candidates_[0].address().family())); 677 rtc::EmptySocketAddressWithFamily(candidates_[0].address().family()));
680 } 678 }
681 } 679 }
682 680
683 // Host is not behind the NAT. 681 // Host is not behind the NAT.
684 TEST_F(PortAllocatorTest, TestCandidateFilterWithReflexiveOnlyAndNoNAT) { 682 TEST_F(PortAllocatorTest, TestCandidateFilterWithReflexiveOnlyAndNoNAT) {
685 AddInterface(kClientAddr); 683 AddInterface(kClientAddr);
686 allocator().set_flags(cricket::PORTALLOCATOR_ENABLE_SHARED_UFRAG | 684 allocator().set_flags(cricket::PORTALLOCATOR_ENABLE_SHARED_SOCKET);
687 cricket::PORTALLOCATOR_ENABLE_SHARED_SOCKET);
688 allocator().set_candidate_filter(cricket::CF_REFLEXIVE); 685 allocator().set_candidate_filter(cricket::CF_REFLEXIVE);
689 EXPECT_TRUE(CreateSession(cricket::ICE_CANDIDATE_COMPONENT_RTP)); 686 EXPECT_TRUE(CreateSession(cricket::ICE_CANDIDATE_COMPONENT_RTP));
690 session_->StartGettingPorts(); 687 session_->StartGettingPorts();
691 EXPECT_TRUE_WAIT(candidate_allocation_done_, kDefaultAllocationTimeout); 688 EXPECT_TRUE_WAIT(candidate_allocation_done_, kDefaultAllocationTimeout);
692 // Host has a public address, both UDP and TCP candidates will be exposed. 689 // Host has a public address, both UDP and TCP candidates will be exposed.
693 EXPECT_EQ(2U, candidates_.size()); // Local UDP + TCP candidate. 690 EXPECT_EQ(2U, candidates_.size()); // Local UDP + TCP candidate.
694 EXPECT_EQ(2U, ports_.size()); // UDP and TCP ports will be in ready state. 691 EXPECT_EQ(2U, ports_.size()); // UDP and TCP ports will be in ready state.
695 for (size_t i = 0; i < candidates_.size(); ++i) { 692 for (size_t i = 0; i < candidates_.size(); ++i) {
696 EXPECT_EQ(std::string(cricket::LOCAL_PORT_TYPE), candidates_[i].type()); 693 EXPECT_EQ(std::string(cricket::LOCAL_PORT_TYPE), candidates_[i].type());
697 } 694 }
698 } 695 }
699 696
700 // Test that when the PORTALLOCATOR_ENABLE_SHARED_UFRAG is enabled we got same 697 // Test that we get the same ufrag and pwd for all candidates.
701 // ufrag and pwd for the collected candidates.
702 TEST_F(PortAllocatorTest, TestEnableSharedUfrag) { 698 TEST_F(PortAllocatorTest, TestEnableSharedUfrag) {
703 allocator().set_flags(allocator().flags() |
704 cricket::PORTALLOCATOR_ENABLE_SHARED_UFRAG);
705 AddInterface(kClientAddr); 699 AddInterface(kClientAddr);
706 EXPECT_TRUE(CreateSession(cricket::ICE_CANDIDATE_COMPONENT_RTP)); 700 EXPECT_TRUE(CreateSession(cricket::ICE_CANDIDATE_COMPONENT_RTP));
707 session_->StartGettingPorts(); 701 session_->StartGettingPorts();
708 ASSERT_EQ_WAIT(7U, candidates_.size(), kDefaultAllocationTimeout); 702 ASSERT_EQ_WAIT(7U, candidates_.size(), kDefaultAllocationTimeout);
709 EXPECT_PRED5(CheckCandidate, candidates_[0], 703 EXPECT_PRED5(CheckCandidate, candidates_[0],
710 cricket::ICE_CANDIDATE_COMPONENT_RTP, "local", "udp", kClientAddr); 704 cricket::ICE_CANDIDATE_COMPONENT_RTP, "local", "udp", kClientAddr);
711 EXPECT_PRED5(CheckCandidate, candidates_[1], 705 EXPECT_PRED5(CheckCandidate, candidates_[1],
712 cricket::ICE_CANDIDATE_COMPONENT_RTP, "stun", "udp", kClientAddr); 706 cricket::ICE_CANDIDATE_COMPONENT_RTP, "stun", "udp", kClientAddr);
713 EXPECT_PRED5(CheckCandidate, candidates_[5], 707 EXPECT_PRED5(CheckCandidate, candidates_[5],
714 cricket::ICE_CANDIDATE_COMPONENT_RTP, "local", "tcp", kClientAddr); 708 cricket::ICE_CANDIDATE_COMPONENT_RTP, "local", "tcp", kClientAddr);
715 EXPECT_EQ(4U, ports_.size()); 709 EXPECT_EQ(4U, ports_.size());
716 EXPECT_EQ(kIceUfrag0, candidates_[0].username()); 710 EXPECT_EQ(kIceUfrag0, candidates_[0].username());
717 EXPECT_EQ(kIceUfrag0, candidates_[1].username()); 711 EXPECT_EQ(kIceUfrag0, candidates_[1].username());
718 EXPECT_EQ(kIceUfrag0, candidates_[2].username()); 712 EXPECT_EQ(kIceUfrag0, candidates_[2].username());
719 EXPECT_EQ(kIcePwd0, candidates_[0].password()); 713 EXPECT_EQ(kIcePwd0, candidates_[0].password());
720 EXPECT_EQ(kIcePwd0, candidates_[1].password()); 714 EXPECT_EQ(kIcePwd0, candidates_[1].password());
721 EXPECT_TRUE(candidate_allocation_done_); 715 EXPECT_TRUE(candidate_allocation_done_);
722 } 716 }
723 717
724 // Test that when the PORTALLOCATOR_ENABLE_SHARED_UFRAG isn't enabled we got
725 // different ufrag and pwd for the collected candidates.
726 TEST_F(PortAllocatorTest, TestDisableSharedUfrag) {
727 allocator().set_flags(allocator().flags() &
728 ~cricket::PORTALLOCATOR_ENABLE_SHARED_UFRAG);
729 AddInterface(kClientAddr);
730 EXPECT_TRUE(CreateSession(cricket::ICE_CANDIDATE_COMPONENT_RTP));
731 session_->StartGettingPorts();
732 ASSERT_EQ_WAIT(7U, candidates_.size(), kDefaultAllocationTimeout);
733 EXPECT_PRED5(CheckCandidate, candidates_[0],
734 cricket::ICE_CANDIDATE_COMPONENT_RTP, "local", "udp", kClientAddr);
735 EXPECT_PRED5(CheckCandidate, candidates_[1],
736 cricket::ICE_CANDIDATE_COMPONENT_RTP, "stun", "udp", kClientAddr);
737 EXPECT_EQ(4U, ports_.size());
738 // Port should generate random ufrag and pwd.
739 EXPECT_NE(kIceUfrag0, candidates_[0].username());
740 EXPECT_NE(kIceUfrag0, candidates_[1].username());
741 EXPECT_NE(candidates_[0].username(), candidates_[1].username());
742 EXPECT_NE(kIcePwd0, candidates_[0].password());
743 EXPECT_NE(kIcePwd0, candidates_[1].password());
744 EXPECT_NE(candidates_[0].password(), candidates_[1].password());
745 EXPECT_TRUE(candidate_allocation_done_);
746 }
747
748 // Test that when PORTALLOCATOR_ENABLE_SHARED_SOCKET is enabled only one port 718 // Test that when PORTALLOCATOR_ENABLE_SHARED_SOCKET is enabled only one port
749 // is allocated for udp and stun. Also verify there is only one candidate 719 // is allocated for udp and stun. Also verify there is only one candidate
750 // (local) if stun candidate is same as local candidate, which will be the case 720 // (local) if stun candidate is same as local candidate, which will be the case
751 // in a public network like the below test. 721 // in a public network like the below test.
752 TEST_F(PortAllocatorTest, TestSharedSocketWithoutNat) { 722 TEST_F(PortAllocatorTest, TestSharedSocketWithoutNat) {
753 AddInterface(kClientAddr); 723 AddInterface(kClientAddr);
754 allocator_->set_flags(allocator().flags() | 724 allocator_->set_flags(allocator().flags() |
755 cricket::PORTALLOCATOR_ENABLE_SHARED_UFRAG |
756 cricket::PORTALLOCATOR_ENABLE_SHARED_SOCKET); 725 cricket::PORTALLOCATOR_ENABLE_SHARED_SOCKET);
757 EXPECT_TRUE(CreateSession(cricket::ICE_CANDIDATE_COMPONENT_RTP)); 726 EXPECT_TRUE(CreateSession(cricket::ICE_CANDIDATE_COMPONENT_RTP));
758 session_->StartGettingPorts(); 727 session_->StartGettingPorts();
759 ASSERT_EQ_WAIT(6U, candidates_.size(), kDefaultAllocationTimeout); 728 ASSERT_EQ_WAIT(6U, candidates_.size(), kDefaultAllocationTimeout);
760 EXPECT_EQ(3U, ports_.size()); 729 EXPECT_EQ(3U, ports_.size());
761 EXPECT_PRED5(CheckCandidate, candidates_[0], 730 EXPECT_PRED5(CheckCandidate, candidates_[0],
762 cricket::ICE_CANDIDATE_COMPONENT_RTP, "local", "udp", kClientAddr); 731 cricket::ICE_CANDIDATE_COMPONENT_RTP, "local", "udp", kClientAddr);
763 EXPECT_TRUE_WAIT(candidate_allocation_done_, kDefaultAllocationTimeout); 732 EXPECT_TRUE_WAIT(candidate_allocation_done_, kDefaultAllocationTimeout);
764 } 733 }
765 734
766 // Test that when PORTALLOCATOR_ENABLE_SHARED_SOCKET is enabled only one port 735 // Test that when PORTALLOCATOR_ENABLE_SHARED_SOCKET is enabled only one port
767 // is allocated for udp and stun. In this test we should expect both stun and 736 // is allocated for udp and stun. In this test we should expect both stun and
768 // local candidates as client behind a nat. 737 // local candidates as client behind a nat.
769 TEST_F(PortAllocatorTest, TestSharedSocketWithNat) { 738 TEST_F(PortAllocatorTest, TestSharedSocketWithNat) {
770 AddInterface(kClientAddr); 739 AddInterface(kClientAddr);
771 ResetWithNatServer(kStunAddr); 740 ResetWithNatServer(kStunAddr);
772 741
773 allocator_->set_flags(allocator().flags() | 742 allocator_->set_flags(allocator().flags() |
774 cricket::PORTALLOCATOR_ENABLE_SHARED_UFRAG |
775 cricket::PORTALLOCATOR_ENABLE_SHARED_SOCKET); 743 cricket::PORTALLOCATOR_ENABLE_SHARED_SOCKET);
776 EXPECT_TRUE(CreateSession(cricket::ICE_CANDIDATE_COMPONENT_RTP)); 744 EXPECT_TRUE(CreateSession(cricket::ICE_CANDIDATE_COMPONENT_RTP));
777 session_->StartGettingPorts(); 745 session_->StartGettingPorts();
778 ASSERT_EQ_WAIT(3U, candidates_.size(), kDefaultAllocationTimeout); 746 ASSERT_EQ_WAIT(3U, candidates_.size(), kDefaultAllocationTimeout);
779 ASSERT_EQ(2U, ports_.size()); 747 ASSERT_EQ(2U, ports_.size());
780 EXPECT_PRED5(CheckCandidate, candidates_[0], 748 EXPECT_PRED5(CheckCandidate, candidates_[0],
781 cricket::ICE_CANDIDATE_COMPONENT_RTP, "local", "udp", kClientAddr); 749 cricket::ICE_CANDIDATE_COMPONENT_RTP, "local", "udp", kClientAddr);
782 EXPECT_PRED5(CheckCandidate, candidates_[1], 750 EXPECT_PRED5(CheckCandidate, candidates_[1],
783 cricket::ICE_CANDIDATE_COMPONENT_RTP, "stun", "udp", 751 cricket::ICE_CANDIDATE_COMPONENT_RTP, "stun", "udp",
784 rtc::SocketAddress(kNatUdpAddr.ipaddr(), 0)); 752 rtc::SocketAddress(kNatUdpAddr.ipaddr(), 0));
785 EXPECT_TRUE_WAIT(candidate_allocation_done_, kDefaultAllocationTimeout); 753 EXPECT_TRUE_WAIT(candidate_allocation_done_, kDefaultAllocationTimeout);
786 EXPECT_EQ(3U, candidates_.size()); 754 EXPECT_EQ(3U, candidates_.size());
787 } 755 }
788 756
789 // Test TURN port in shared socket mode with UDP and TCP TURN server addresses. 757 // Test TURN port in shared socket mode with UDP and TCP TURN server addresses.
790 TEST_F(PortAllocatorTest, TestSharedSocketWithoutNatUsingTurn) { 758 TEST_F(PortAllocatorTest, TestSharedSocketWithoutNatUsingTurn) {
791 turn_server_.AddInternalSocket(kTurnTcpIntAddr, cricket::PROTO_TCP); 759 turn_server_.AddInternalSocket(kTurnTcpIntAddr, cricket::PROTO_TCP);
792 AddInterface(kClientAddr); 760 AddInterface(kClientAddr);
793 allocator_.reset(new cricket::BasicPortAllocator(&network_manager_)); 761 allocator_.reset(new cricket::BasicPortAllocator(&network_manager_));
794 762
795 AddTurnServers(kTurnUdpIntAddr, kTurnTcpIntAddr); 763 AddTurnServers(kTurnUdpIntAddr, kTurnTcpIntAddr);
796 764
797 allocator_->set_step_delay(cricket::kMinimumStepDelay); 765 allocator_->set_step_delay(cricket::kMinimumStepDelay);
798 allocator_->set_flags(allocator().flags() | 766 allocator_->set_flags(allocator().flags() |
799 cricket::PORTALLOCATOR_ENABLE_SHARED_UFRAG |
800 cricket::PORTALLOCATOR_ENABLE_SHARED_SOCKET | 767 cricket::PORTALLOCATOR_ENABLE_SHARED_SOCKET |
801 cricket::PORTALLOCATOR_DISABLE_TCP); 768 cricket::PORTALLOCATOR_DISABLE_TCP);
802 769
803 EXPECT_TRUE(CreateSession(cricket::ICE_CANDIDATE_COMPONENT_RTP)); 770 EXPECT_TRUE(CreateSession(cricket::ICE_CANDIDATE_COMPONENT_RTP));
804 session_->StartGettingPorts(); 771 session_->StartGettingPorts();
805 772
806 ASSERT_EQ_WAIT(3U, candidates_.size(), kDefaultAllocationTimeout); 773 ASSERT_EQ_WAIT(3U, candidates_.size(), kDefaultAllocationTimeout);
807 ASSERT_EQ(3U, ports_.size()); 774 ASSERT_EQ(3U, ports_.size());
808 EXPECT_PRED5(CheckCandidate, candidates_[0], 775 EXPECT_PRED5(CheckCandidate, candidates_[0],
809 cricket::ICE_CANDIDATE_COMPONENT_RTP, "local", "udp", kClientAddr); 776 cricket::ICE_CANDIDATE_COMPONENT_RTP, "local", "udp", kClientAddr);
(...skipping 17 matching lines...) Expand all
827 cricket::RelayServerConfig relay_server(cricket::RELAY_TURN); 794 cricket::RelayServerConfig relay_server(cricket::RELAY_TURN);
828 cricket::RelayCredentials credentials(kTurnUsername, kTurnPassword); 795 cricket::RelayCredentials credentials(kTurnUsername, kTurnPassword);
829 relay_server.credentials = credentials; 796 relay_server.credentials = credentials;
830 relay_server.ports.push_back(cricket::ProtocolAddress( 797 relay_server.ports.push_back(cricket::ProtocolAddress(
831 rtc::SocketAddress("localhost", 3478), 798 rtc::SocketAddress("localhost", 3478),
832 cricket::PROTO_UDP, false)); 799 cricket::PROTO_UDP, false));
833 allocator_->AddRelay(relay_server); 800 allocator_->AddRelay(relay_server);
834 801
835 allocator_->set_step_delay(cricket::kMinimumStepDelay); 802 allocator_->set_step_delay(cricket::kMinimumStepDelay);
836 allocator_->set_flags(allocator().flags() | 803 allocator_->set_flags(allocator().flags() |
837 cricket::PORTALLOCATOR_ENABLE_SHARED_UFRAG |
838 cricket::PORTALLOCATOR_ENABLE_SHARED_SOCKET | 804 cricket::PORTALLOCATOR_ENABLE_SHARED_SOCKET |
839 cricket::PORTALLOCATOR_DISABLE_TCP); 805 cricket::PORTALLOCATOR_DISABLE_TCP);
840 806
841 EXPECT_TRUE(CreateSession(cricket::ICE_CANDIDATE_COMPONENT_RTP)); 807 EXPECT_TRUE(CreateSession(cricket::ICE_CANDIDATE_COMPONENT_RTP));
842 session_->StartGettingPorts(); 808 session_->StartGettingPorts();
843 809
844 EXPECT_EQ_WAIT(2U, ports_.size(), kDefaultAllocationTimeout); 810 EXPECT_EQ_WAIT(2U, ports_.size(), kDefaultAllocationTimeout);
845 } 811 }
846 812
847 // Test that when PORTALLOCATOR_ENABLE_SHARED_SOCKET is enabled only one port 813 // Test that when PORTALLOCATOR_ENABLE_SHARED_SOCKET is enabled only one port
848 // is allocated for udp/stun/turn. In this test we should expect all local, 814 // is allocated for udp/stun/turn. In this test we should expect all local,
849 // stun and turn candidates. 815 // stun and turn candidates.
850 TEST_F(PortAllocatorTest, TestSharedSocketWithNatUsingTurn) { 816 TEST_F(PortAllocatorTest, TestSharedSocketWithNatUsingTurn) {
851 AddInterface(kClientAddr); 817 AddInterface(kClientAddr);
852 ResetWithNatServer(kStunAddr); 818 ResetWithNatServer(kStunAddr);
853 819
854 AddTurnServers(kTurnUdpIntAddr, rtc::SocketAddress()); 820 AddTurnServers(kTurnUdpIntAddr, rtc::SocketAddress());
855 821
856 allocator_->set_flags(allocator().flags() | 822 allocator_->set_flags(allocator().flags() |
857 cricket::PORTALLOCATOR_ENABLE_SHARED_UFRAG |
858 cricket::PORTALLOCATOR_ENABLE_SHARED_SOCKET | 823 cricket::PORTALLOCATOR_ENABLE_SHARED_SOCKET |
859 cricket::PORTALLOCATOR_DISABLE_TCP); 824 cricket::PORTALLOCATOR_DISABLE_TCP);
860 825
861 EXPECT_TRUE(CreateSession(cricket::ICE_CANDIDATE_COMPONENT_RTP)); 826 EXPECT_TRUE(CreateSession(cricket::ICE_CANDIDATE_COMPONENT_RTP));
862 session_->StartGettingPorts(); 827 session_->StartGettingPorts();
863 828
864 ASSERT_EQ_WAIT(3U, candidates_.size(), kDefaultAllocationTimeout); 829 ASSERT_EQ_WAIT(3U, candidates_.size(), kDefaultAllocationTimeout);
865 ASSERT_EQ(2U, ports_.size()); 830 ASSERT_EQ(2U, ports_.size());
866 EXPECT_PRED5(CheckCandidate, candidates_[0], 831 EXPECT_PRED5(CheckCandidate, candidates_[0],
867 cricket::ICE_CANDIDATE_COMPONENT_RTP, "local", "udp", kClientAddr); 832 cricket::ICE_CANDIDATE_COMPONENT_RTP, "local", "udp", kClientAddr);
(...skipping 18 matching lines...) Expand all
886 // Use an empty SocketAddress to add a NAT without STUN server. 851 // Use an empty SocketAddress to add a NAT without STUN server.
887 ResetWithNatServer(SocketAddress()); 852 ResetWithNatServer(SocketAddress());
888 AddTurnServers(kTurnUdpIntAddr, rtc::SocketAddress()); 853 AddTurnServers(kTurnUdpIntAddr, rtc::SocketAddress());
889 854
890 // Must set the step delay to 0 to make sure the relay allocation phase is 855 // Must set the step delay to 0 to make sure the relay allocation phase is
891 // started before the STUN candidates are obtained, so that the STUN binding 856 // started before the STUN candidates are obtained, so that the STUN binding
892 // response is processed when both StunPort and TurnPort exist to reproduce 857 // response is processed when both StunPort and TurnPort exist to reproduce
893 // webrtc issue 3537. 858 // webrtc issue 3537.
894 allocator_->set_step_delay(0); 859 allocator_->set_step_delay(0);
895 allocator_->set_flags(allocator().flags() | 860 allocator_->set_flags(allocator().flags() |
896 cricket::PORTALLOCATOR_ENABLE_SHARED_UFRAG |
897 cricket::PORTALLOCATOR_ENABLE_SHARED_SOCKET | 861 cricket::PORTALLOCATOR_ENABLE_SHARED_SOCKET |
898 cricket::PORTALLOCATOR_DISABLE_TCP); 862 cricket::PORTALLOCATOR_DISABLE_TCP);
899 863
900 EXPECT_TRUE(CreateSession(cricket::ICE_CANDIDATE_COMPONENT_RTP)); 864 EXPECT_TRUE(CreateSession(cricket::ICE_CANDIDATE_COMPONENT_RTP));
901 session_->StartGettingPorts(); 865 session_->StartGettingPorts();
902 866
903 ASSERT_EQ_WAIT(3U, candidates_.size(), kDefaultAllocationTimeout); 867 ASSERT_EQ_WAIT(3U, candidates_.size(), kDefaultAllocationTimeout);
904 EXPECT_PRED5(CheckCandidate, candidates_[0], 868 EXPECT_PRED5(CheckCandidate, candidates_[0],
905 cricket::ICE_CANDIDATE_COMPONENT_RTP, "local", "udp", kClientAddr); 869 cricket::ICE_CANDIDATE_COMPONENT_RTP, "local", "udp", kClientAddr);
906 EXPECT_PRED5(CheckCandidate, candidates_[1], 870 EXPECT_PRED5(CheckCandidate, candidates_[1],
(...skipping 14 matching lines...) Expand all
921 // Test that when only a TCP TURN server is available, we do NOT use it as 885 // Test that when only a TCP TURN server is available, we do NOT use it as
922 // a UDP STUN server, as this could leak our IP address. Thus we should only 886 // a UDP STUN server, as this could leak our IP address. Thus we should only
923 // expect two ports, a UDPPort and TurnPort. 887 // expect two ports, a UDPPort and TurnPort.
924 TEST_F(PortAllocatorTest, TestSharedSocketWithNatUsingTurnTcpOnly) { 888 TEST_F(PortAllocatorTest, TestSharedSocketWithNatUsingTurnTcpOnly) {
925 turn_server_.AddInternalSocket(kTurnTcpIntAddr, cricket::PROTO_TCP); 889 turn_server_.AddInternalSocket(kTurnTcpIntAddr, cricket::PROTO_TCP);
926 AddInterface(kClientAddr); 890 AddInterface(kClientAddr);
927 ResetWithNatServer(rtc::SocketAddress()); 891 ResetWithNatServer(rtc::SocketAddress());
928 AddTurnServers(rtc::SocketAddress(), kTurnTcpIntAddr); 892 AddTurnServers(rtc::SocketAddress(), kTurnTcpIntAddr);
929 893
930 allocator_->set_flags(allocator().flags() | 894 allocator_->set_flags(allocator().flags() |
931 cricket::PORTALLOCATOR_ENABLE_SHARED_UFRAG |
932 cricket::PORTALLOCATOR_ENABLE_SHARED_SOCKET | 895 cricket::PORTALLOCATOR_ENABLE_SHARED_SOCKET |
933 cricket::PORTALLOCATOR_DISABLE_TCP); 896 cricket::PORTALLOCATOR_DISABLE_TCP);
934 897
935 EXPECT_TRUE(CreateSession(cricket::ICE_CANDIDATE_COMPONENT_RTP)); 898 EXPECT_TRUE(CreateSession(cricket::ICE_CANDIDATE_COMPONENT_RTP));
936 session_->StartGettingPorts(); 899 session_->StartGettingPorts();
937 900
938 ASSERT_EQ_WAIT(2U, candidates_.size(), kDefaultAllocationTimeout); 901 ASSERT_EQ_WAIT(2U, candidates_.size(), kDefaultAllocationTimeout);
939 ASSERT_EQ(2U, ports_.size()); 902 ASSERT_EQ(2U, ports_.size());
940 EXPECT_PRED5(CheckCandidate, candidates_[0], 903 EXPECT_PRED5(CheckCandidate, candidates_[0],
941 cricket::ICE_CANDIDATE_COMPONENT_RTP, "local", "udp", 904 cricket::ICE_CANDIDATE_COMPONENT_RTP, "local", "udp",
(...skipping 12 matching lines...) Expand all
954 // 'relay' candidates. 917 // 'relay' candidates.
955 // TODO(deadbeef): Remove this test when support for non-shared socket mode 918 // TODO(deadbeef): Remove this test when support for non-shared socket mode
956 // is removed. 919 // is removed.
957 TEST_F(PortAllocatorTest, TestNonSharedSocketWithNatUsingTurnAsStun) { 920 TEST_F(PortAllocatorTest, TestNonSharedSocketWithNatUsingTurnAsStun) {
958 AddInterface(kClientAddr); 921 AddInterface(kClientAddr);
959 // Use an empty SocketAddress to add a NAT without STUN server. 922 // Use an empty SocketAddress to add a NAT without STUN server.
960 ResetWithNatServer(SocketAddress()); 923 ResetWithNatServer(SocketAddress());
961 AddTurnServers(kTurnUdpIntAddr, rtc::SocketAddress()); 924 AddTurnServers(kTurnUdpIntAddr, rtc::SocketAddress());
962 925
963 allocator_->set_flags(allocator().flags() | 926 allocator_->set_flags(allocator().flags() |
964 cricket::PORTALLOCATOR_ENABLE_SHARED_UFRAG |
965 cricket::PORTALLOCATOR_DISABLE_TCP); 927 cricket::PORTALLOCATOR_DISABLE_TCP);
966 928
967 EXPECT_TRUE(CreateSession(cricket::ICE_CANDIDATE_COMPONENT_RTP)); 929 EXPECT_TRUE(CreateSession(cricket::ICE_CANDIDATE_COMPONENT_RTP));
968 session_->StartGettingPorts(); 930 session_->StartGettingPorts();
969 931
970 ASSERT_EQ_WAIT(3U, candidates_.size(), kDefaultAllocationTimeout); 932 ASSERT_EQ_WAIT(3U, candidates_.size(), kDefaultAllocationTimeout);
971 ASSERT_EQ(3U, ports_.size()); 933 ASSERT_EQ(3U, ports_.size());
972 EXPECT_PRED5(CheckCandidate, candidates_[0], 934 EXPECT_PRED5(CheckCandidate, candidates_[0],
973 cricket::ICE_CANDIDATE_COMPONENT_RTP, "local", "udp", 935 cricket::ICE_CANDIDATE_COMPONENT_RTP, "local", "udp",
974 kClientAddr); 936 kClientAddr);
(...skipping 18 matching lines...) Expand all
993 // server is used as a STUN server and we get a 'stun' candidate. 955 // server is used as a STUN server and we get a 'stun' candidate.
994 TEST_F(PortAllocatorTest, TestSharedSocketWithNatUsingTurnAndStun) { 956 TEST_F(PortAllocatorTest, TestSharedSocketWithNatUsingTurnAndStun) {
995 AddInterface(kClientAddr); 957 AddInterface(kClientAddr);
996 // Configure with STUN server but destroy it, so we can ensure that it's 958 // Configure with STUN server but destroy it, so we can ensure that it's
997 // the TURN server actually being used as a STUN server. 959 // the TURN server actually being used as a STUN server.
998 ResetWithNatServer(kStunAddr); 960 ResetWithNatServer(kStunAddr);
999 stun_server_.reset(); 961 stun_server_.reset();
1000 AddTurnServers(kTurnUdpIntAddr, rtc::SocketAddress()); 962 AddTurnServers(kTurnUdpIntAddr, rtc::SocketAddress());
1001 963
1002 allocator_->set_flags(allocator().flags() | 964 allocator_->set_flags(allocator().flags() |
1003 cricket::PORTALLOCATOR_ENABLE_SHARED_UFRAG |
1004 cricket::PORTALLOCATOR_ENABLE_SHARED_SOCKET | 965 cricket::PORTALLOCATOR_ENABLE_SHARED_SOCKET |
1005 cricket::PORTALLOCATOR_DISABLE_TCP); 966 cricket::PORTALLOCATOR_DISABLE_TCP);
1006 967
1007 EXPECT_TRUE(CreateSession(cricket::ICE_CANDIDATE_COMPONENT_RTP)); 968 EXPECT_TRUE(CreateSession(cricket::ICE_CANDIDATE_COMPONENT_RTP));
1008 session_->StartGettingPorts(); 969 session_->StartGettingPorts();
1009 970
1010 ASSERT_EQ_WAIT(3U, candidates_.size(), kDefaultAllocationTimeout); 971 ASSERT_EQ_WAIT(3U, candidates_.size(), kDefaultAllocationTimeout);
1011 EXPECT_PRED5(CheckCandidate, candidates_[0], 972 EXPECT_PRED5(CheckCandidate, candidates_[0],
1012 cricket::ICE_CANDIDATE_COMPONENT_RTP, "local", "udp", 973 cricket::ICE_CANDIDATE_COMPONENT_RTP, "local", "udp",
1013 kClientAddr); 974 kClientAddr);
1014 EXPECT_PRED5(CheckCandidate, candidates_[1], 975 EXPECT_PRED5(CheckCandidate, candidates_[1],
1015 cricket::ICE_CANDIDATE_COMPONENT_RTP, "stun", "udp", 976 cricket::ICE_CANDIDATE_COMPONENT_RTP, "stun", "udp",
1016 rtc::SocketAddress(kNatUdpAddr.ipaddr(), 0)); 977 rtc::SocketAddress(kNatUdpAddr.ipaddr(), 0));
1017 EXPECT_PRED5(CheckCandidate, candidates_[2], 978 EXPECT_PRED5(CheckCandidate, candidates_[2],
1018 cricket::ICE_CANDIDATE_COMPONENT_RTP, "relay", "udp", 979 cricket::ICE_CANDIDATE_COMPONENT_RTP, "relay", "udp",
1019 rtc::SocketAddress(kTurnUdpExtAddr.ipaddr(), 0)); 980 rtc::SocketAddress(kTurnUdpExtAddr.ipaddr(), 0));
1020 EXPECT_EQ(candidates_[2].related_address(), candidates_[1].address()); 981 EXPECT_EQ(candidates_[2].related_address(), candidates_[1].address());
1021 982
1022 // Don't bother waiting for STUN timeout, since we already verified 983 // Don't bother waiting for STUN timeout, since we already verified
1023 // that we got a STUN candidate from the TURN server. 984 // that we got a STUN candidate from the TURN server.
1024 } 985 }
1025 986
1026 // This test verifies when PORTALLOCATOR_ENABLE_SHARED_SOCKET flag is enabled 987 // This test verifies when PORTALLOCATOR_ENABLE_SHARED_SOCKET flag is enabled
1027 // and fail to generate STUN candidate, local UDP candidate is generated 988 // and fail to generate STUN candidate, local UDP candidate is generated
1028 // properly. 989 // properly.
1029 TEST_F(PortAllocatorTest, TestSharedSocketNoUdpAllowed) { 990 TEST_F(PortAllocatorTest, TestSharedSocketNoUdpAllowed) {
1030 allocator().set_flags(allocator().flags() | 991 allocator().set_flags(allocator().flags() |
1031 cricket::PORTALLOCATOR_DISABLE_RELAY | 992 cricket::PORTALLOCATOR_DISABLE_RELAY |
1032 cricket::PORTALLOCATOR_DISABLE_TCP | 993 cricket::PORTALLOCATOR_DISABLE_TCP |
1033 cricket::PORTALLOCATOR_ENABLE_SHARED_UFRAG |
1034 cricket::PORTALLOCATOR_ENABLE_SHARED_SOCKET); 994 cricket::PORTALLOCATOR_ENABLE_SHARED_SOCKET);
1035 fss_->AddRule(false, rtc::FP_UDP, rtc::FD_ANY, kClientAddr); 995 fss_->AddRule(false, rtc::FP_UDP, rtc::FD_ANY, kClientAddr);
1036 AddInterface(kClientAddr); 996 AddInterface(kClientAddr);
1037 EXPECT_TRUE(CreateSession(cricket::ICE_CANDIDATE_COMPONENT_RTP)); 997 EXPECT_TRUE(CreateSession(cricket::ICE_CANDIDATE_COMPONENT_RTP));
1038 session_->StartGettingPorts(); 998 session_->StartGettingPorts();
1039 ASSERT_EQ_WAIT(1U, ports_.size(), kDefaultAllocationTimeout); 999 ASSERT_EQ_WAIT(1U, ports_.size(), kDefaultAllocationTimeout);
1040 EXPECT_EQ(1U, candidates_.size()); 1000 EXPECT_EQ(1U, candidates_.size());
1041 EXPECT_PRED5(CheckCandidate, candidates_[0], 1001 EXPECT_PRED5(CheckCandidate, candidates_[0],
1042 cricket::ICE_CANDIDATE_COMPONENT_RTP, "local", "udp", kClientAddr); 1002 cricket::ICE_CANDIDATE_COMPONENT_RTP, "local", "udp", kClientAddr);
1043 // STUN timeout is 9sec. We need to wait to get candidate done signal. 1003 // STUN timeout is 9sec. We need to wait to get candidate done signal.
1044 EXPECT_TRUE_WAIT(candidate_allocation_done_, 10000); 1004 EXPECT_TRUE_WAIT(candidate_allocation_done_, 10000);
1045 EXPECT_EQ(1U, candidates_.size()); 1005 EXPECT_EQ(1U, candidates_.size());
1046 } 1006 }
1047 1007
1048 // This test verifies allocator can use IPv6 addresses along with IPv4. 1008 // This test verifies allocator can use IPv6 addresses along with IPv4.
1049 TEST_F(PortAllocatorTest, TestEnableIPv6Addresses) { 1009 TEST_F(PortAllocatorTest, TestEnableIPv6Addresses) {
1050 allocator().set_flags(allocator().flags() | 1010 allocator().set_flags(allocator().flags() |
1051 cricket::PORTALLOCATOR_DISABLE_RELAY | 1011 cricket::PORTALLOCATOR_DISABLE_RELAY |
1052 cricket::PORTALLOCATOR_ENABLE_IPV6 | 1012 cricket::PORTALLOCATOR_ENABLE_IPV6 |
1053 cricket::PORTALLOCATOR_ENABLE_SHARED_UFRAG |
1054 cricket::PORTALLOCATOR_ENABLE_SHARED_SOCKET); 1013 cricket::PORTALLOCATOR_ENABLE_SHARED_SOCKET);
1055 AddInterface(kClientIPv6Addr); 1014 AddInterface(kClientIPv6Addr);
1056 AddInterface(kClientAddr); 1015 AddInterface(kClientAddr);
1057 allocator_->set_step_delay(cricket::kMinimumStepDelay); 1016 allocator_->set_step_delay(cricket::kMinimumStepDelay);
1058 EXPECT_TRUE(CreateSession(cricket::ICE_CANDIDATE_COMPONENT_RTP)); 1017 EXPECT_TRUE(CreateSession(cricket::ICE_CANDIDATE_COMPONENT_RTP));
1059 session_->StartGettingPorts(); 1018 session_->StartGettingPorts();
1060 ASSERT_EQ_WAIT(4U, ports_.size(), kDefaultAllocationTimeout); 1019 ASSERT_EQ_WAIT(4U, ports_.size(), kDefaultAllocationTimeout);
1061 EXPECT_EQ(4U, candidates_.size()); 1020 EXPECT_EQ(4U, candidates_.size());
1062 EXPECT_TRUE_WAIT(candidate_allocation_done_, kDefaultAllocationTimeout); 1021 EXPECT_TRUE_WAIT(candidate_allocation_done_, kDefaultAllocationTimeout);
1063 EXPECT_PRED5(CheckCandidate, candidates_[0], 1022 EXPECT_PRED5(CheckCandidate, candidates_[0],
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
1102 alloc.SetStunHosts(stun_servers); 1061 alloc.SetStunHosts(stun_servers);
1103 EXPECT_EQ(2U, alloc.relay_hosts().size()); 1062 EXPECT_EQ(2U, alloc.relay_hosts().size());
1104 EXPECT_EQ(2U, alloc.stun_hosts().size()); 1063 EXPECT_EQ(2U, alloc.stun_hosts().size());
1105 } 1064 }
1106 1065
1107 // Test that the HttpPortAllocator uses correct URL to create sessions. 1066 // Test that the HttpPortAllocator uses correct URL to create sessions.
1108 TEST(HttpPortAllocatorTest, TestSessionRequestUrl) { 1067 TEST(HttpPortAllocatorTest, TestSessionRequestUrl) {
1109 rtc::FakeNetworkManager network_manager; 1068 rtc::FakeNetworkManager network_manager;
1110 cricket::HttpPortAllocator alloc(&network_manager, "unit test agent"); 1069 cricket::HttpPortAllocator alloc(&network_manager, "unit test agent");
1111 1070
1112 // Disable PORTALLOCATOR_ENABLE_SHARED_UFRAG.
1113 alloc.set_flags(alloc.flags() & ~cricket::PORTALLOCATOR_ENABLE_SHARED_UFRAG);
1114 rtc::scoped_ptr<cricket::HttpPortAllocatorSessionBase> session( 1071 rtc::scoped_ptr<cricket::HttpPortAllocatorSessionBase> session(
1115 static_cast<cricket::HttpPortAllocatorSession*>( 1072 static_cast<cricket::HttpPortAllocatorSession*>(
1116 alloc.CreateSessionInternal( 1073 alloc.CreateSessionInternal(
1117 "test content", 0, kIceUfrag0, kIcePwd0))); 1074 "test content", 0, kIceUfrag0, kIcePwd0)));
1118 std::string url = session->GetSessionRequestUrl(); 1075 std::string url = session->GetSessionRequestUrl();
1119 LOG(LS_INFO) << "url: " << url; 1076 LOG(LS_INFO) << "url: " << url;
1120 EXPECT_EQ(std::string(cricket::HttpPortAllocator::kCreateSessionURL), url);
1121
1122 // Enable PORTALLOCATOR_ENABLE_SHARED_UFRAG.
1123 alloc.set_flags(alloc.flags() | cricket::PORTALLOCATOR_ENABLE_SHARED_UFRAG);
1124 session.reset(static_cast<cricket::HttpPortAllocatorSession*>(
1125 alloc.CreateSessionInternal("test content", 0, kIceUfrag0, kIcePwd0)));
1126 url = session->GetSessionRequestUrl();
1127 LOG(LS_INFO) << "url: " << url;
1128 std::vector<std::string> parts; 1077 std::vector<std::string> parts;
1129 rtc::split(url, '?', &parts); 1078 rtc::split(url, '?', &parts);
1130 ASSERT_EQ(2U, parts.size()); 1079 ASSERT_EQ(2U, parts.size());
1131 1080
1132 std::vector<std::string> args_parts; 1081 std::vector<std::string> args_parts;
1133 rtc::split(parts[1], '&', &args_parts); 1082 rtc::split(parts[1], '&', &args_parts);
1134 1083
1135 std::map<std::string, std::string> args; 1084 std::map<std::string, std::string> args;
1136 for (std::vector<std::string>::iterator it = args_parts.begin(); 1085 for (std::vector<std::string>::iterator it = args_parts.begin();
1137 it != args_parts.end(); ++it) { 1086 it != args_parts.end(); ++it) {
(...skipping 14 matching lines...) Expand all
1152 EXPECT_TRUE(CreateSession(cricket::ICE_CANDIDATE_COMPONENT_RTP)); 1101 EXPECT_TRUE(CreateSession(cricket::ICE_CANDIDATE_COMPONENT_RTP));
1153 session_->StartGettingPorts(); 1102 session_->StartGettingPorts();
1154 ASSERT_EQ_WAIT(7U, candidates_.size(), kDefaultAllocationTimeout); 1103 ASSERT_EQ_WAIT(7U, candidates_.size(), kDefaultAllocationTimeout);
1155 EXPECT_EQ(4U, ports_.size()); 1104 EXPECT_EQ(4U, ports_.size());
1156 1105
1157 auto it = ports_.begin(); 1106 auto it = ports_.begin();
1158 for (; it != ports_.end(); ++it) { 1107 for (; it != ports_.end(); ++it) {
1159 (reinterpret_cast<cricket::Port*>(*it))->Destroy(); 1108 (reinterpret_cast<cricket::Port*>(*it))->Destroy();
1160 } 1109 }
1161 } 1110 }
OLDNEW
« webrtc/p2p/client/httpportallocator.cc ('K') | « webrtc/p2p/client/httpportallocator.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698