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

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

Issue 1215713003: Ensuring that UDP TURN servers are always used as STUN servers. (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Fixing compiler warning from size_t->int cast Created 5 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « webrtc/p2p/client/basicportallocator.cc ('k') | no next file » | 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 22 matching lines...) Expand all
33 using cricket::ServerAddresses; 33 using cricket::ServerAddresses;
34 using rtc::SocketAddress; 34 using rtc::SocketAddress;
35 using rtc::Thread; 35 using rtc::Thread;
36 36
37 static const SocketAddress kClientAddr("11.11.11.11", 0); 37 static const SocketAddress kClientAddr("11.11.11.11", 0);
38 static const SocketAddress kPrivateAddr("192.168.1.11", 0); 38 static const SocketAddress kPrivateAddr("192.168.1.11", 0);
39 static const SocketAddress kPrivateAddr2("192.168.1.12", 0); 39 static const SocketAddress kPrivateAddr2("192.168.1.12", 0);
40 static const SocketAddress kClientIPv6Addr( 40 static const SocketAddress kClientIPv6Addr(
41 "2401:fa00:4:1000:be30:5bff:fee5:c3", 0); 41 "2401:fa00:4:1000:be30:5bff:fee5:c3", 0);
42 static const SocketAddress kClientAddr2("22.22.22.22", 0); 42 static const SocketAddress kClientAddr2("22.22.22.22", 0);
43 static const SocketAddress kNatAddr("77.77.77.77", rtc::NAT_SERVER_PORT); 43 static const SocketAddress kNatUdpAddr("77.77.77.77", rtc::NAT_SERVER_UDP_PORT);
44 static const SocketAddress kNatTcpAddr("77.77.77.77", rtc::NAT_SERVER_TCP_PORT);
44 static const SocketAddress kRemoteClientAddr("22.22.22.22", 0); 45 static const SocketAddress kRemoteClientAddr("22.22.22.22", 0);
45 static const SocketAddress kStunAddr("99.99.99.1", cricket::STUN_SERVER_PORT); 46 static const SocketAddress kStunAddr("99.99.99.1", cricket::STUN_SERVER_PORT);
46 static const SocketAddress kRelayUdpIntAddr("99.99.99.2", 5000); 47 static const SocketAddress kRelayUdpIntAddr("99.99.99.2", 5000);
47 static const SocketAddress kRelayUdpExtAddr("99.99.99.3", 5001); 48 static const SocketAddress kRelayUdpExtAddr("99.99.99.3", 5001);
48 static const SocketAddress kRelayTcpIntAddr("99.99.99.2", 5002); 49 static const SocketAddress kRelayTcpIntAddr("99.99.99.2", 5002);
49 static const SocketAddress kRelayTcpExtAddr("99.99.99.3", 5003); 50 static const SocketAddress kRelayTcpExtAddr("99.99.99.3", 5003);
50 static const SocketAddress kRelaySslTcpIntAddr("99.99.99.2", 5004); 51 static const SocketAddress kRelaySslTcpIntAddr("99.99.99.2", 5004);
51 static const SocketAddress kRelaySslTcpExtAddr("99.99.99.3", 5005); 52 static const SocketAddress kRelaySslTcpExtAddr("99.99.99.3", 5005);
52 static const SocketAddress kTurnUdpIntAddr("99.99.99.4", 3478); 53 static const SocketAddress kTurnUdpIntAddr("99.99.99.4", 3478);
53 static const SocketAddress kTurnTcpIntAddr("99.99.99.5", 3478); 54 static const SocketAddress kTurnTcpIntAddr("99.99.99.5", 3478);
(...skipping 24 matching lines...) Expand all
78 79
79 } // namespace cricket 80 } // namespace cricket
80 81
81 class PortAllocatorTest : public testing::Test, public sigslot::has_slots<> { 82 class PortAllocatorTest : public testing::Test, public sigslot::has_slots<> {
82 public: 83 public:
83 PortAllocatorTest() 84 PortAllocatorTest()
84 : pss_(new rtc::PhysicalSocketServer), 85 : pss_(new rtc::PhysicalSocketServer),
85 vss_(new rtc::VirtualSocketServer(pss_.get())), 86 vss_(new rtc::VirtualSocketServer(pss_.get())),
86 fss_(new rtc::FirewallSocketServer(vss_.get())), 87 fss_(new rtc::FirewallSocketServer(vss_.get())),
87 ss_scope_(fss_.get()), 88 ss_scope_(fss_.get()),
88 nat_factory_(vss_.get(), kNatAddr), 89 nat_factory_(vss_.get(), kNatUdpAddr, kNatTcpAddr),
89 nat_socket_factory_(&nat_factory_), 90 nat_socket_factory_(&nat_factory_),
90 stun_server_(cricket::TestStunServer::Create(Thread::Current(), 91 stun_server_(cricket::TestStunServer::Create(Thread::Current(),
91 kStunAddr)), 92 kStunAddr)),
92 relay_server_(Thread::Current(), kRelayUdpIntAddr, kRelayUdpExtAddr, 93 relay_server_(Thread::Current(), kRelayUdpIntAddr, kRelayUdpExtAddr,
93 kRelayTcpIntAddr, kRelayTcpExtAddr, 94 kRelayTcpIntAddr, kRelayTcpExtAddr,
94 kRelaySslTcpIntAddr, kRelaySslTcpExtAddr), 95 kRelaySslTcpIntAddr, kRelaySslTcpExtAddr),
95 turn_server_(Thread::Current(), kTurnUdpIntAddr, kTurnUdpExtAddr), 96 turn_server_(Thread::Current(), kTurnUdpIntAddr, kTurnUdpExtAddr),
96 candidate_allocation_done_(false) { 97 candidate_allocation_done_(false) {
97 cricket::ServerAddresses stun_servers; 98 cricket::ServerAddresses stun_servers;
98 stun_servers.insert(kStunAddr); 99 stun_servers.insert(kStunAddr);
99 // Passing the addresses of GTURN servers will enable GTURN in 100 // Passing the addresses of GTURN servers will enable GTURN in
100 // Basicportallocator. 101 // Basicportallocator.
101 allocator_.reset(new cricket::BasicPortAllocator( 102 allocator_.reset(new cricket::BasicPortAllocator(
102 &network_manager_, 103 &network_manager_,
103 stun_servers, 104 stun_servers,
104 kRelayUdpIntAddr, kRelayTcpIntAddr, kRelaySslTcpIntAddr)); 105 kRelayUdpIntAddr, kRelayTcpIntAddr, kRelaySslTcpIntAddr));
105 allocator_->set_step_delay(cricket::kMinimumStepDelay); 106 allocator_->set_step_delay(cricket::kMinimumStepDelay);
106 } 107 }
107 108
108 void AddInterface(const SocketAddress& addr) { 109 void AddInterface(const SocketAddress& addr) {
109 network_manager_.AddInterface(addr); 110 network_manager_.AddInterface(addr);
110 } 111 }
111 bool SetPortRange(int min_port, int max_port) { 112 bool SetPortRange(int min_port, int max_port) {
112 return allocator_->SetPortRange(min_port, max_port); 113 return allocator_->SetPortRange(min_port, max_port);
113 } 114 }
114 void ResetWithNatServer(const rtc::SocketAddress& stun_server) { 115 void ResetWithNatServer(const rtc::SocketAddress& stun_server) {
115 nat_server_.reset(new rtc::NATServer( 116 nat_server_.reset(new rtc::NATServer(
116 rtc::NAT_OPEN_CONE, vss_.get(), kNatAddr, vss_.get(), kNatAddr)); 117 rtc::NAT_OPEN_CONE, vss_.get(), kNatUdpAddr, kNatTcpAddr, vss_.get(),
118 rtc::SocketAddress(kNatUdpAddr.ipaddr(), 0)));
117 119
118 ServerAddresses stun_servers; 120 ServerAddresses stun_servers;
119 if (!stun_server.IsNil()) { 121 if (!stun_server.IsNil()) {
120 stun_servers.insert(stun_server); 122 stun_servers.insert(stun_server);
121 } 123 }
122 allocator_.reset(new cricket::BasicPortAllocator( 124 allocator_.reset(new cricket::BasicPortAllocator(
123 &network_manager_, &nat_socket_factory_, stun_servers)); 125 &network_manager_, &nat_socket_factory_, stun_servers));
124 allocator().set_step_delay(cricket::kMinimumStepDelay); 126 allocator().set_step_delay(cricket::kMinimumStepDelay);
125 } 127 }
126 128
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after
234 session_->set_flags(cricket::PORTALLOCATOR_DISABLE_ADAPTER_ENUMERATION); 236 session_->set_flags(cricket::PORTALLOCATOR_DISABLE_ADAPTER_ENUMERATION);
235 session_->StartGettingPorts(); 237 session_->StartGettingPorts();
236 EXPECT_TRUE_WAIT(candidate_allocation_done_, kDefaultAllocationTimeout); 238 EXPECT_TRUE_WAIT(candidate_allocation_done_, kDefaultAllocationTimeout);
237 239
238 // Only 2 candidates as local UDP/TCP are all 0s and get trimmed out. 240 // Only 2 candidates as local UDP/TCP are all 0s and get trimmed out.
239 EXPECT_EQ(2U, candidates_.size()); 241 EXPECT_EQ(2U, candidates_.size());
240 EXPECT_EQ(2U, ports_.size()); // One stunport and one turnport. 242 EXPECT_EQ(2U, ports_.size()); // One stunport and one turnport.
241 243
242 EXPECT_PRED5(CheckCandidate, candidates_[0], 244 EXPECT_PRED5(CheckCandidate, candidates_[0],
243 cricket::ICE_CANDIDATE_COMPONENT_RTP, "stun", "udp", 245 cricket::ICE_CANDIDATE_COMPONENT_RTP, "stun", "udp",
244 rtc::SocketAddress(kNatAddr.ipaddr(), 0)); 246 rtc::SocketAddress(kNatUdpAddr.ipaddr(), 0));
245 EXPECT_EQ( 247 EXPECT_EQ(
246 rtc::EmptySocketAddressWithFamily(candidates_[0].address().family()), 248 rtc::EmptySocketAddressWithFamily(candidates_[0].address().family()),
247 candidates_[0].related_address()); 249 candidates_[0].related_address());
248 250
249 EXPECT_PRED5(CheckCandidate, candidates_[1], 251 EXPECT_PRED5(CheckCandidate, candidates_[1],
250 cricket::ICE_CANDIDATE_COMPONENT_RTP, "relay", "udp", 252 cricket::ICE_CANDIDATE_COMPONENT_RTP, "relay", "udp",
251 rtc::SocketAddress(kTurnUdpExtAddr.ipaddr(), 0)); 253 rtc::SocketAddress(kTurnUdpExtAddr.ipaddr(), 0));
252 EXPECT_EQ(kNatAddr.ipaddr(), candidates_[1].related_address().ipaddr()); 254 EXPECT_EQ(kNatUdpAddr.ipaddr(), candidates_[1].related_address().ipaddr());
253 } 255 }
254 256
255 protected: 257 protected:
256 cricket::BasicPortAllocator& allocator() { 258 cricket::BasicPortAllocator& allocator() {
257 return *allocator_; 259 return *allocator_;
258 } 260 }
259 261
260 void OnPortReady(cricket::PortAllocatorSession* ses, 262 void OnPortReady(cricket::PortAllocatorSession* ses,
261 cricket::PortInterface* port) { 263 cricket::PortInterface* port) {
262 LOG(LS_INFO) << "OnPortReady: " << port->ToString(); 264 LOG(LS_INFO) << "OnPortReady: " << port->ToString();
(...skipping 509 matching lines...) Expand 10 before | Expand all | Expand 10 after
772 cricket::PORTALLOCATOR_ENABLE_SHARED_UFRAG | 774 cricket::PORTALLOCATOR_ENABLE_SHARED_UFRAG |
773 cricket::PORTALLOCATOR_ENABLE_SHARED_SOCKET); 775 cricket::PORTALLOCATOR_ENABLE_SHARED_SOCKET);
774 EXPECT_TRUE(CreateSession(cricket::ICE_CANDIDATE_COMPONENT_RTP)); 776 EXPECT_TRUE(CreateSession(cricket::ICE_CANDIDATE_COMPONENT_RTP));
775 session_->StartGettingPorts(); 777 session_->StartGettingPorts();
776 ASSERT_EQ_WAIT(3U, candidates_.size(), kDefaultAllocationTimeout); 778 ASSERT_EQ_WAIT(3U, candidates_.size(), kDefaultAllocationTimeout);
777 ASSERT_EQ(2U, ports_.size()); 779 ASSERT_EQ(2U, ports_.size());
778 EXPECT_PRED5(CheckCandidate, candidates_[0], 780 EXPECT_PRED5(CheckCandidate, candidates_[0],
779 cricket::ICE_CANDIDATE_COMPONENT_RTP, "local", "udp", kClientAddr); 781 cricket::ICE_CANDIDATE_COMPONENT_RTP, "local", "udp", kClientAddr);
780 EXPECT_PRED5(CheckCandidate, candidates_[1], 782 EXPECT_PRED5(CheckCandidate, candidates_[1],
781 cricket::ICE_CANDIDATE_COMPONENT_RTP, "stun", "udp", 783 cricket::ICE_CANDIDATE_COMPONENT_RTP, "stun", "udp",
782 rtc::SocketAddress(kNatAddr.ipaddr(), 0)); 784 rtc::SocketAddress(kNatUdpAddr.ipaddr(), 0));
783 EXPECT_TRUE_WAIT(candidate_allocation_done_, kDefaultAllocationTimeout); 785 EXPECT_TRUE_WAIT(candidate_allocation_done_, kDefaultAllocationTimeout);
784 EXPECT_EQ(3U, candidates_.size()); 786 EXPECT_EQ(3U, candidates_.size());
785 } 787 }
786 788
787 // Test TURN port in shared socket mode with UDP and TCP TURN server adderesses. 789 // Test TURN port in shared socket mode with UDP and TCP TURN server addresses.
788 TEST_F(PortAllocatorTest, TestSharedSocketWithoutNatUsingTurn) { 790 TEST_F(PortAllocatorTest, TestSharedSocketWithoutNatUsingTurn) {
789 turn_server_.AddInternalSocket(kTurnTcpIntAddr, cricket::PROTO_TCP); 791 turn_server_.AddInternalSocket(kTurnTcpIntAddr, cricket::PROTO_TCP);
790 AddInterface(kClientAddr); 792 AddInterface(kClientAddr);
791 allocator_.reset(new cricket::BasicPortAllocator(&network_manager_)); 793 allocator_.reset(new cricket::BasicPortAllocator(&network_manager_));
792 794
793 AddTurnServers(kTurnUdpIntAddr, kTurnTcpIntAddr); 795 AddTurnServers(kTurnUdpIntAddr, kTurnTcpIntAddr);
794 796
795 allocator_->set_step_delay(cricket::kMinimumStepDelay); 797 allocator_->set_step_delay(cricket::kMinimumStepDelay);
796 allocator_->set_flags(allocator().flags() | 798 allocator_->set_flags(allocator().flags() |
797 cricket::PORTALLOCATOR_ENABLE_SHARED_UFRAG | 799 cricket::PORTALLOCATOR_ENABLE_SHARED_UFRAG |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
858 860
859 EXPECT_TRUE(CreateSession(cricket::ICE_CANDIDATE_COMPONENT_RTP)); 861 EXPECT_TRUE(CreateSession(cricket::ICE_CANDIDATE_COMPONENT_RTP));
860 session_->StartGettingPorts(); 862 session_->StartGettingPorts();
861 863
862 ASSERT_EQ_WAIT(3U, candidates_.size(), kDefaultAllocationTimeout); 864 ASSERT_EQ_WAIT(3U, candidates_.size(), kDefaultAllocationTimeout);
863 ASSERT_EQ(2U, ports_.size()); 865 ASSERT_EQ(2U, ports_.size());
864 EXPECT_PRED5(CheckCandidate, candidates_[0], 866 EXPECT_PRED5(CheckCandidate, candidates_[0],
865 cricket::ICE_CANDIDATE_COMPONENT_RTP, "local", "udp", kClientAddr); 867 cricket::ICE_CANDIDATE_COMPONENT_RTP, "local", "udp", kClientAddr);
866 EXPECT_PRED5(CheckCandidate, candidates_[1], 868 EXPECT_PRED5(CheckCandidate, candidates_[1],
867 cricket::ICE_CANDIDATE_COMPONENT_RTP, "stun", "udp", 869 cricket::ICE_CANDIDATE_COMPONENT_RTP, "stun", "udp",
868 rtc::SocketAddress(kNatAddr.ipaddr(), 0)); 870 rtc::SocketAddress(kNatUdpAddr.ipaddr(), 0));
869 EXPECT_PRED5(CheckCandidate, candidates_[2], 871 EXPECT_PRED5(CheckCandidate, candidates_[2],
870 cricket::ICE_CANDIDATE_COMPONENT_RTP, "relay", "udp", 872 cricket::ICE_CANDIDATE_COMPONENT_RTP, "relay", "udp",
871 rtc::SocketAddress(kTurnUdpExtAddr.ipaddr(), 0)); 873 rtc::SocketAddress(kTurnUdpExtAddr.ipaddr(), 0));
872 EXPECT_TRUE_WAIT(candidate_allocation_done_, kDefaultAllocationTimeout); 874 EXPECT_TRUE_WAIT(candidate_allocation_done_, kDefaultAllocationTimeout);
873 EXPECT_EQ(3U, candidates_.size()); 875 EXPECT_EQ(3U, candidates_.size());
874 // Local port will be created first and then TURN port. 876 // Local port will be created first and then TURN port.
875 EXPECT_EQ(2U, ports_[0]->Candidates().size()); 877 EXPECT_EQ(2U, ports_[0]->Candidates().size());
876 EXPECT_EQ(1U, ports_[1]->Candidates().size()); 878 EXPECT_EQ(1U, ports_[1]->Candidates().size());
877 } 879 }
878 880
(...skipping 17 matching lines...) Expand all
896 cricket::PORTALLOCATOR_DISABLE_TCP); 898 cricket::PORTALLOCATOR_DISABLE_TCP);
897 899
898 EXPECT_TRUE(CreateSession(cricket::ICE_CANDIDATE_COMPONENT_RTP)); 900 EXPECT_TRUE(CreateSession(cricket::ICE_CANDIDATE_COMPONENT_RTP));
899 session_->StartGettingPorts(); 901 session_->StartGettingPorts();
900 902
901 ASSERT_EQ_WAIT(3U, candidates_.size(), kDefaultAllocationTimeout); 903 ASSERT_EQ_WAIT(3U, candidates_.size(), kDefaultAllocationTimeout);
902 EXPECT_PRED5(CheckCandidate, candidates_[0], 904 EXPECT_PRED5(CheckCandidate, candidates_[0],
903 cricket::ICE_CANDIDATE_COMPONENT_RTP, "local", "udp", kClientAddr); 905 cricket::ICE_CANDIDATE_COMPONENT_RTP, "local", "udp", kClientAddr);
904 EXPECT_PRED5(CheckCandidate, candidates_[1], 906 EXPECT_PRED5(CheckCandidate, candidates_[1],
905 cricket::ICE_CANDIDATE_COMPONENT_RTP, "stun", "udp", 907 cricket::ICE_CANDIDATE_COMPONENT_RTP, "stun", "udp",
906 rtc::SocketAddress(kNatAddr.ipaddr(), 0)); 908 rtc::SocketAddress(kNatUdpAddr.ipaddr(), 0));
907 EXPECT_PRED5(CheckCandidate, candidates_[2], 909 EXPECT_PRED5(CheckCandidate, candidates_[2],
908 cricket::ICE_CANDIDATE_COMPONENT_RTP, "relay", "udp", 910 cricket::ICE_CANDIDATE_COMPONENT_RTP, "relay", "udp",
909 rtc::SocketAddress(kTurnUdpExtAddr.ipaddr(), 0)); 911 rtc::SocketAddress(kTurnUdpExtAddr.ipaddr(), 0));
910 EXPECT_EQ(candidates_[2].related_address(), candidates_[1].address()); 912 EXPECT_EQ(candidates_[2].related_address(), candidates_[1].address());
911 913
912 EXPECT_TRUE_WAIT(candidate_allocation_done_, kDefaultAllocationTimeout); 914 EXPECT_TRUE_WAIT(candidate_allocation_done_, kDefaultAllocationTimeout);
913 EXPECT_EQ(3U, candidates_.size()); 915 EXPECT_EQ(3U, candidates_.size());
914 // Local port will be created first and then TURN port. 916 // Local port will be created first and then TURN port.
915 EXPECT_EQ(2U, ports_[0]->Candidates().size()); 917 EXPECT_EQ(2U, ports_[0]->Candidates().size());
916 EXPECT_EQ(1U, ports_[1]->Candidates().size()); 918 EXPECT_EQ(1U, ports_[1]->Candidates().size());
917 } 919 }
918 920
921 // 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
923 // expect two ports, a UDPPort and TurnPort.
924 TEST_F(PortAllocatorTest, TestSharedSocketWithNatUsingTurnTcpOnly) {
925 turn_server_.AddInternalSocket(kTurnTcpIntAddr, cricket::PROTO_TCP);
926 AddInterface(kClientAddr);
927 ResetWithNatServer(rtc::SocketAddress());
928 AddTurnServers(rtc::SocketAddress(), kTurnTcpIntAddr);
929
930 allocator_->set_flags(allocator().flags() |
931 cricket::PORTALLOCATOR_ENABLE_SHARED_UFRAG |
932 cricket::PORTALLOCATOR_ENABLE_SHARED_SOCKET |
933 cricket::PORTALLOCATOR_DISABLE_TCP);
934
935 EXPECT_TRUE(CreateSession(cricket::ICE_CANDIDATE_COMPONENT_RTP));
936 session_->StartGettingPorts();
937
938 ASSERT_EQ_WAIT(2U, candidates_.size(), kDefaultAllocationTimeout);
939 ASSERT_EQ(2U, ports_.size());
940 EXPECT_PRED5(CheckCandidate, candidates_[0],
941 cricket::ICE_CANDIDATE_COMPONENT_RTP, "local", "udp",
942 kClientAddr);
943 EXPECT_PRED5(CheckCandidate, candidates_[1],
944 cricket::ICE_CANDIDATE_COMPONENT_RTP, "relay", "udp",
945 rtc::SocketAddress(kTurnUdpExtAddr.ipaddr(), 0));
946 EXPECT_TRUE_WAIT(candidate_allocation_done_, kDefaultAllocationTimeout);
947 EXPECT_EQ(2U, candidates_.size());
948 EXPECT_EQ(1U, ports_[0]->Candidates().size());
949 EXPECT_EQ(1U, ports_[1]->Candidates().size());
950 }
951
952 // Test that even when PORTALLOCATOR_ENABLE_SHARED_SOCKET is NOT enabled, the
953 // TURN server is used as the STUN server and we get 'local', 'stun', and
954 // 'relay' candidates.
955 // TODO(deadbeef): Remove this test when support for non-shared socket mode
956 // is removed.
957 TEST_F(PortAllocatorTest, TestNonSharedSocketWithNatUsingTurnAsStun) {
958 AddInterface(kClientAddr);
959 // Use an empty SocketAddress to add a NAT without STUN server.
960 ResetWithNatServer(SocketAddress());
961 AddTurnServers(kTurnUdpIntAddr, rtc::SocketAddress());
962
963 allocator_->set_flags(allocator().flags() |
964 cricket::PORTALLOCATOR_ENABLE_SHARED_UFRAG |
965 cricket::PORTALLOCATOR_DISABLE_TCP);
966
967 EXPECT_TRUE(CreateSession(cricket::ICE_CANDIDATE_COMPONENT_RTP));
968 session_->StartGettingPorts();
969
970 ASSERT_EQ_WAIT(3U, candidates_.size(), kDefaultAllocationTimeout);
971 ASSERT_EQ(3U, ports_.size());
972 EXPECT_PRED5(CheckCandidate, candidates_[0],
973 cricket::ICE_CANDIDATE_COMPONENT_RTP, "local", "udp",
974 kClientAddr);
975 EXPECT_PRED5(CheckCandidate, candidates_[1],
976 cricket::ICE_CANDIDATE_COMPONENT_RTP, "stun", "udp",
977 rtc::SocketAddress(kNatUdpAddr.ipaddr(), 0));
978 EXPECT_PRED5(CheckCandidate, candidates_[2],
979 cricket::ICE_CANDIDATE_COMPONENT_RTP, "relay", "udp",
980 rtc::SocketAddress(kTurnUdpExtAddr.ipaddr(), 0));
981 // Not using shared socket, so the STUN request's server reflexive address
982 // should be different than the TURN request's server reflexive address.
983 EXPECT_NE(candidates_[2].related_address(), candidates_[1].address());
984
985 EXPECT_TRUE_WAIT(candidate_allocation_done_, kDefaultAllocationTimeout);
986 EXPECT_EQ(3U, candidates_.size());
987 EXPECT_EQ(1U, ports_[0]->Candidates().size());
988 EXPECT_EQ(1U, ports_[1]->Candidates().size());
989 EXPECT_EQ(1U, ports_[2]->Candidates().size());
990 }
991
992 // Test that even when both a STUN and TURN server are configured, the TURN
993 // server is used as a STUN server and we get a 'stun' candidate.
994 TEST_F(PortAllocatorTest, TestSharedSocketWithNatUsingTurnAndStun) {
995 AddInterface(kClientAddr);
996 // 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.
998 ResetWithNatServer(kStunAddr);
999 stun_server_.reset();
1000 AddTurnServers(kTurnUdpIntAddr, rtc::SocketAddress());
1001
1002 allocator_->set_flags(allocator().flags() |
1003 cricket::PORTALLOCATOR_ENABLE_SHARED_UFRAG |
1004 cricket::PORTALLOCATOR_ENABLE_SHARED_SOCKET |
1005 cricket::PORTALLOCATOR_DISABLE_TCP);
1006
1007 EXPECT_TRUE(CreateSession(cricket::ICE_CANDIDATE_COMPONENT_RTP));
1008 session_->StartGettingPorts();
1009
1010 ASSERT_EQ_WAIT(3U, candidates_.size(), kDefaultAllocationTimeout);
1011 EXPECT_PRED5(CheckCandidate, candidates_[0],
1012 cricket::ICE_CANDIDATE_COMPONENT_RTP, "local", "udp",
1013 kClientAddr);
1014 EXPECT_PRED5(CheckCandidate, candidates_[1],
1015 cricket::ICE_CANDIDATE_COMPONENT_RTP, "stun", "udp",
1016 rtc::SocketAddress(kNatUdpAddr.ipaddr(), 0));
1017 EXPECT_PRED5(CheckCandidate, candidates_[2],
1018 cricket::ICE_CANDIDATE_COMPONENT_RTP, "relay", "udp",
1019 rtc::SocketAddress(kTurnUdpExtAddr.ipaddr(), 0));
1020 EXPECT_EQ(candidates_[2].related_address(), candidates_[1].address());
1021
1022 // Don't bother waiting for STUN timeout, since we already verified
1023 // that we got a STUN candidate from the TURN server.
1024 }
1025
919 // This test verifies when PORTALLOCATOR_ENABLE_SHARED_SOCKET flag is enabled 1026 // This test verifies when PORTALLOCATOR_ENABLE_SHARED_SOCKET flag is enabled
920 // and fail to generate STUN candidate, local UDP candidate is generated 1027 // and fail to generate STUN candidate, local UDP candidate is generated
921 // properly. 1028 // properly.
922 TEST_F(PortAllocatorTest, TestSharedSocketNoUdpAllowed) { 1029 TEST_F(PortAllocatorTest, TestSharedSocketNoUdpAllowed) {
923 allocator().set_flags(allocator().flags() | 1030 allocator().set_flags(allocator().flags() |
924 cricket::PORTALLOCATOR_DISABLE_RELAY | 1031 cricket::PORTALLOCATOR_DISABLE_RELAY |
925 cricket::PORTALLOCATOR_DISABLE_TCP | 1032 cricket::PORTALLOCATOR_DISABLE_TCP |
926 cricket::PORTALLOCATOR_ENABLE_SHARED_UFRAG | 1033 cricket::PORTALLOCATOR_ENABLE_SHARED_UFRAG |
927 cricket::PORTALLOCATOR_ENABLE_SHARED_SOCKET); 1034 cricket::PORTALLOCATOR_ENABLE_SHARED_SOCKET);
928 fss_->AddRule(false, rtc::FP_UDP, rtc::FD_ANY, kClientAddr); 1035 fss_->AddRule(false, rtc::FP_UDP, rtc::FD_ANY, kClientAddr);
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after
1045 EXPECT_TRUE(CreateSession(cricket::ICE_CANDIDATE_COMPONENT_RTP)); 1152 EXPECT_TRUE(CreateSession(cricket::ICE_CANDIDATE_COMPONENT_RTP));
1046 session_->StartGettingPorts(); 1153 session_->StartGettingPorts();
1047 ASSERT_EQ_WAIT(7U, candidates_.size(), kDefaultAllocationTimeout); 1154 ASSERT_EQ_WAIT(7U, candidates_.size(), kDefaultAllocationTimeout);
1048 EXPECT_EQ(4U, ports_.size()); 1155 EXPECT_EQ(4U, ports_.size());
1049 1156
1050 auto it = ports_.begin(); 1157 auto it = ports_.begin();
1051 for (; it != ports_.end(); ++it) { 1158 for (; it != ports_.end(); ++it) {
1052 (reinterpret_cast<cricket::Port*>(*it))->Destroy(); 1159 (reinterpret_cast<cricket::Port*>(*it))->Destroy();
1053 } 1160 }
1054 } 1161 }
OLDNEW
« no previous file with comments | « webrtc/p2p/client/basicportallocator.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698