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

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

Powered by Google App Engine
This is Rietveld 408576698