OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2009 The WebRTC Project Authors. All rights reserved. | 2 * Copyright 2009 The WebRTC Project Authors. All rights reserved. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license | 4 * Use of this source code is governed by a BSD-style license |
5 * that can be found in the LICENSE file in the root of the source | 5 * that can be found in the LICENSE file in the root of the source |
6 * tree. An additional intellectual property rights grant can be found | 6 * tree. An additional intellectual property rights grant can be found |
7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may |
8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. |
9 */ | 9 */ |
10 | 10 |
11 #include <algorithm> | |
12 #include <memory> | 11 #include <memory> |
13 | 12 |
14 #include "webrtc/p2p/base/basicpacketsocketfactory.h" | 13 #include "webrtc/p2p/base/basicpacketsocketfactory.h" |
15 #include "webrtc/p2p/base/p2pconstants.h" | 14 #include "webrtc/p2p/base/p2pconstants.h" |
16 #include "webrtc/p2p/base/p2ptransportchannel.h" | 15 #include "webrtc/p2p/base/p2ptransportchannel.h" |
17 #include "webrtc/p2p/base/testrelayserver.h" | 16 #include "webrtc/p2p/base/testrelayserver.h" |
18 #include "webrtc/p2p/base/teststunserver.h" | 17 #include "webrtc/p2p/base/teststunserver.h" |
19 #include "webrtc/p2p/base/testturnserver.h" | 18 #include "webrtc/p2p/base/testturnserver.h" |
20 #include "webrtc/p2p/client/basicportallocator.h" | 19 #include "webrtc/p2p/client/basicportallocator.h" |
21 #include "webrtc/p2p/client/httpportallocator.h" | 20 #include "webrtc/p2p/client/httpportallocator.h" |
(...skipping 14 matching lines...) Expand all Loading... |
36 | 35 |
37 using cricket::ServerAddresses; | 36 using cricket::ServerAddresses; |
38 using rtc::IPAddress; | 37 using rtc::IPAddress; |
39 using rtc::SocketAddress; | 38 using rtc::SocketAddress; |
40 using rtc::Thread; | 39 using rtc::Thread; |
41 | 40 |
42 static const SocketAddress kClientAddr("11.11.11.11", 0); | 41 static const SocketAddress kClientAddr("11.11.11.11", 0); |
43 static const SocketAddress kLoopbackAddr("127.0.0.1", 0); | 42 static const SocketAddress kLoopbackAddr("127.0.0.1", 0); |
44 static const SocketAddress kPrivateAddr("192.168.1.11", 0); | 43 static const SocketAddress kPrivateAddr("192.168.1.11", 0); |
45 static const SocketAddress kPrivateAddr2("192.168.1.12", 0); | 44 static const SocketAddress kPrivateAddr2("192.168.1.12", 0); |
46 static const SocketAddress kClientIPv6Addr("2401:fa00:4:1000:be30:5bff:fee5:c3", | 45 static const SocketAddress kClientIPv6Addr( |
47 0); | 46 "2401:fa00:4:1000:be30:5bff:fee5:c3", 0); |
48 static const SocketAddress kClientAddr2("22.22.22.22", 0); | 47 static const SocketAddress kClientAddr2("22.22.22.22", 0); |
49 static const SocketAddress kNatUdpAddr("77.77.77.77", rtc::NAT_SERVER_UDP_PORT); | 48 static const SocketAddress kNatUdpAddr("77.77.77.77", rtc::NAT_SERVER_UDP_PORT); |
50 static const SocketAddress kNatTcpAddr("77.77.77.77", rtc::NAT_SERVER_TCP_PORT); | 49 static const SocketAddress kNatTcpAddr("77.77.77.77", rtc::NAT_SERVER_TCP_PORT); |
51 static const SocketAddress kRemoteClientAddr("22.22.22.22", 0); | 50 static const SocketAddress kRemoteClientAddr("22.22.22.22", 0); |
52 static const SocketAddress kStunAddr("99.99.99.1", cricket::STUN_SERVER_PORT); | 51 static const SocketAddress kStunAddr("99.99.99.1", cricket::STUN_SERVER_PORT); |
53 static const SocketAddress kRelayUdpIntAddr("99.99.99.2", 5000); | 52 static const SocketAddress kRelayUdpIntAddr("99.99.99.2", 5000); |
54 static const SocketAddress kRelayUdpExtAddr("99.99.99.3", 5001); | 53 static const SocketAddress kRelayUdpExtAddr("99.99.99.3", 5001); |
55 static const SocketAddress kRelayTcpIntAddr("99.99.99.2", 5002); | 54 static const SocketAddress kRelayTcpIntAddr("99.99.99.2", 5002); |
56 static const SocketAddress kRelayTcpExtAddr("99.99.99.3", 5003); | 55 static const SocketAddress kRelayTcpExtAddr("99.99.99.3", 5003); |
57 static const SocketAddress kRelaySslTcpIntAddr("99.99.99.2", 5004); | 56 static const SocketAddress kRelaySslTcpIntAddr("99.99.99.2", 5004); |
(...skipping 20 matching lines...) Expand all Loading... |
78 namespace cricket { | 77 namespace cricket { |
79 | 78 |
80 // Helper for dumping candidates | 79 // Helper for dumping candidates |
81 std::ostream& operator<<(std::ostream& os, const cricket::Candidate& c) { | 80 std::ostream& operator<<(std::ostream& os, const cricket::Candidate& c) { |
82 os << c.ToString(); | 81 os << c.ToString(); |
83 return os; | 82 return os; |
84 } | 83 } |
85 | 84 |
86 } // namespace cricket | 85 } // namespace cricket |
87 | 86 |
88 class BasicPortAllocatorTest : public testing::Test, | 87 class PortAllocatorTest : public testing::Test, public sigslot::has_slots<> { |
89 public sigslot::has_slots<> { | |
90 public: | 88 public: |
91 BasicPortAllocatorTest() | 89 PortAllocatorTest() |
92 : pss_(new rtc::PhysicalSocketServer), | 90 : pss_(new rtc::PhysicalSocketServer), |
93 vss_(new rtc::VirtualSocketServer(pss_.get())), | 91 vss_(new rtc::VirtualSocketServer(pss_.get())), |
94 fss_(new rtc::FirewallSocketServer(vss_.get())), | 92 fss_(new rtc::FirewallSocketServer(vss_.get())), |
95 ss_scope_(fss_.get()), | 93 ss_scope_(fss_.get()), |
96 nat_factory_(vss_.get(), kNatUdpAddr, kNatTcpAddr), | 94 nat_factory_(vss_.get(), kNatUdpAddr, kNatTcpAddr), |
97 nat_socket_factory_(new rtc::BasicPacketSocketFactory(&nat_factory_)), | 95 nat_socket_factory_(new rtc::BasicPacketSocketFactory(&nat_factory_)), |
98 stun_server_( | 96 stun_server_(cricket::TestStunServer::Create(Thread::Current(), |
99 cricket::TestStunServer::Create(Thread::Current(), kStunAddr)), | 97 kStunAddr)), |
100 relay_server_(Thread::Current(), | 98 relay_server_(Thread::Current(), kRelayUdpIntAddr, kRelayUdpExtAddr, |
101 kRelayUdpIntAddr, | 99 kRelayTcpIntAddr, kRelayTcpExtAddr, |
102 kRelayUdpExtAddr, | 100 kRelaySslTcpIntAddr, kRelaySslTcpExtAddr), |
103 kRelayTcpIntAddr, | |
104 kRelayTcpExtAddr, | |
105 kRelaySslTcpIntAddr, | |
106 kRelaySslTcpExtAddr), | |
107 turn_server_(Thread::Current(), kTurnUdpIntAddr, kTurnUdpExtAddr), | 101 turn_server_(Thread::Current(), kTurnUdpIntAddr, kTurnUdpExtAddr), |
108 candidate_allocation_done_(false) { | 102 candidate_allocation_done_(false) { |
109 cricket::ServerAddresses stun_servers; | 103 cricket::ServerAddresses stun_servers; |
110 stun_servers.insert(kStunAddr); | 104 stun_servers.insert(kStunAddr); |
111 // Passing the addresses of GTURN servers will enable GTURN in | 105 // Passing the addresses of GTURN servers will enable GTURN in |
112 // Basicportallocator. | 106 // Basicportallocator. |
113 allocator_.reset(new cricket::BasicPortAllocator( | 107 allocator_.reset(new cricket::BasicPortAllocator( |
114 &network_manager_, stun_servers, kRelayUdpIntAddr, kRelayTcpIntAddr, | 108 &network_manager_, |
115 kRelaySslTcpIntAddr)); | 109 stun_servers, |
| 110 kRelayUdpIntAddr, kRelayTcpIntAddr, kRelaySslTcpIntAddr)); |
116 allocator_->set_step_delay(cricket::kMinimumStepDelay); | 111 allocator_->set_step_delay(cricket::kMinimumStepDelay); |
117 } | 112 } |
118 | 113 |
119 void AddInterface(const SocketAddress& addr) { | 114 void AddInterface(const SocketAddress& addr) { |
120 network_manager_.AddInterface(addr); | 115 network_manager_.AddInterface(addr); |
121 } | 116 } |
122 void AddInterface(const SocketAddress& addr, const std::string& if_name) { | 117 void AddInterface(const SocketAddress& addr, const std::string& if_name) { |
123 network_manager_.AddInterface(addr, if_name); | 118 network_manager_.AddInterface(addr, if_name); |
124 } | 119 } |
125 void AddInterface(const SocketAddress& addr, | 120 void AddInterface(const SocketAddress& addr, |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
176 cricket::ProtocolAddress(kTurnUdpIntAddr, cricket::PROTO_UDP, false)); | 171 cricket::ProtocolAddress(kTurnUdpIntAddr, cricket::PROTO_UDP, false)); |
177 } | 172 } |
178 if (!tcp_turn.IsNil()) { | 173 if (!tcp_turn.IsNil()) { |
179 turn_server.ports.push_back( | 174 turn_server.ports.push_back( |
180 cricket::ProtocolAddress(kTurnTcpIntAddr, cricket::PROTO_TCP, false)); | 175 cricket::ProtocolAddress(kTurnTcpIntAddr, cricket::PROTO_TCP, false)); |
181 } | 176 } |
182 allocator_->AddTurnServer(turn_server); | 177 allocator_->AddTurnServer(turn_server); |
183 } | 178 } |
184 | 179 |
185 bool CreateSession(int component) { | 180 bool CreateSession(int component) { |
186 session_ = CreateSession("session", component); | 181 session_.reset(CreateSession("session", component)); |
187 if (!session_) { | 182 if (!session_) |
188 return false; | 183 return false; |
189 } | |
190 return true; | 184 return true; |
191 } | 185 } |
192 | 186 |
193 bool CreateSession(int component, const std::string& content_name) { | 187 bool CreateSession(int component, const std::string& content_name) { |
194 session_ = CreateSession("session", content_name, component); | 188 session_.reset(CreateSession("session", content_name, component)); |
195 if (!session_) { | 189 if (!session_) |
196 return false; | 190 return false; |
197 } | |
198 return true; | 191 return true; |
199 } | 192 } |
200 | 193 |
201 std::unique_ptr<cricket::PortAllocatorSession> CreateSession( | 194 cricket::PortAllocatorSession* CreateSession( |
202 const std::string& sid, | 195 const std::string& sid, int component) { |
203 int component) { | |
204 return CreateSession(sid, kContentName, component); | 196 return CreateSession(sid, kContentName, component); |
205 } | 197 } |
206 | 198 |
207 std::unique_ptr<cricket::PortAllocatorSession> CreateSession( | 199 cricket::PortAllocatorSession* CreateSession( |
208 const std::string& sid, | 200 const std::string& sid, const std::string& content_name, int component) { |
209 const std::string& content_name, | |
210 int component) { | |
211 return CreateSession(sid, content_name, component, kIceUfrag0, kIcePwd0); | 201 return CreateSession(sid, content_name, component, kIceUfrag0, kIcePwd0); |
212 } | 202 } |
213 | 203 |
214 std::unique_ptr<cricket::PortAllocatorSession> CreateSession( | 204 cricket::PortAllocatorSession* CreateSession( |
215 const std::string& sid, | 205 const std::string& sid, const std::string& content_name, int component, |
216 const std::string& content_name, | 206 const std::string& ice_ufrag, const std::string& ice_pwd) { |
217 int component, | 207 cricket::PortAllocatorSession* session = |
218 const std::string& ice_ufrag, | 208 allocator_->CreateSession( |
219 const std::string& ice_pwd) { | 209 sid, content_name, component, ice_ufrag, ice_pwd); |
220 std::unique_ptr<cricket::PortAllocatorSession> session = | |
221 allocator_->CreateSession(sid, content_name, component, ice_ufrag, | |
222 ice_pwd); | |
223 session->SignalPortReady.connect(this, | 210 session->SignalPortReady.connect(this, |
224 &BasicPortAllocatorTest::OnPortReady); | 211 &PortAllocatorTest::OnPortReady); |
225 session->SignalCandidatesReady.connect( | 212 session->SignalCandidatesReady.connect(this, |
226 this, &BasicPortAllocatorTest::OnCandidatesReady); | 213 &PortAllocatorTest::OnCandidatesReady); |
227 session->SignalCandidatesAllocationDone.connect( | 214 session->SignalCandidatesAllocationDone.connect(this, |
228 this, &BasicPortAllocatorTest::OnCandidatesAllocationDone); | 215 &PortAllocatorTest::OnCandidatesAllocationDone); |
229 return session; | 216 return session; |
230 } | 217 } |
231 | 218 |
232 static bool CheckCandidate(const cricket::Candidate& c, | 219 static bool CheckCandidate(const cricket::Candidate& c, |
233 int component, | 220 int component, const std::string& type, |
234 const std::string& type, | |
235 const std::string& proto, | 221 const std::string& proto, |
236 const SocketAddress& addr) { | 222 const SocketAddress& addr) { |
237 return (c.component() == component && c.type() == type && | 223 return (c.component() == component && c.type() == type && |
238 c.protocol() == proto && c.address().ipaddr() == addr.ipaddr() && | 224 c.protocol() == proto && c.address().ipaddr() == addr.ipaddr() && |
239 ((addr.port() == 0 && (c.address().port() != 0)) || | 225 ((addr.port() == 0 && (c.address().port() != 0)) || |
240 (c.address().port() == addr.port()))); | 226 (c.address().port() == addr.port()))); |
241 } | 227 } |
242 static bool CheckPort(const rtc::SocketAddress& addr, | 228 static bool CheckPort(const rtc::SocketAddress& addr, |
243 int min_port, | 229 int min_port, int max_port) { |
244 int max_port) { | |
245 return (addr.port() >= min_port && addr.port() <= max_port); | 230 return (addr.port() >= min_port && addr.port() <= max_port); |
246 } | 231 } |
247 | 232 |
248 void OnCandidatesAllocationDone(cricket::PortAllocatorSession* session) { | 233 void OnCandidatesAllocationDone(cricket::PortAllocatorSession* session) { |
249 // We should only get this callback once, except in the mux test where | 234 // We should only get this callback once, except in the mux test where |
250 // we have multiple port allocation sessions. | 235 // we have multiple port allocation sessions. |
251 if (session == session_.get()) { | 236 if (session == session_.get()) { |
252 ASSERT_FALSE(candidate_allocation_done_); | 237 ASSERT_FALSE(candidate_allocation_done_); |
253 candidate_allocation_done_ = true; | 238 candidate_allocation_done_ = true; |
254 } | 239 } |
255 EXPECT_TRUE(session->CandidatesAllocationDone()); | |
256 } | 240 } |
257 | 241 |
258 // Check if all ports allocated have send-buffer size |expected|. If | 242 // Check if all ports allocated have send-buffer size |expected|. If |
259 // |expected| == -1, check if GetOptions returns SOCKET_ERROR. | 243 // |expected| == -1, check if GetOptions returns SOCKET_ERROR. |
260 void CheckSendBufferSizesOfAllPorts(int expected) { | 244 void CheckSendBufferSizesOfAllPorts(int expected) { |
261 std::vector<cricket::PortInterface*>::iterator it; | 245 std::vector<cricket::PortInterface*>::iterator it; |
262 for (it = ports_.begin(); it < ports_.end(); ++it) { | 246 for (it = ports_.begin(); it < ports_.end(); ++it) { |
263 int send_buffer_size; | 247 int send_buffer_size; |
264 if (expected == -1) { | 248 if (expected == -1) { |
265 EXPECT_EQ(SOCKET_ERROR, | 249 EXPECT_EQ(SOCKET_ERROR, |
266 (*it)->GetOption(rtc::Socket::OPT_SNDBUF, &send_buffer_size)); | 250 (*it)->GetOption(rtc::Socket::OPT_SNDBUF, |
| 251 &send_buffer_size)); |
267 } else { | 252 } else { |
268 EXPECT_EQ(0, | 253 EXPECT_EQ(0, (*it)->GetOption(rtc::Socket::OPT_SNDBUF, |
269 (*it)->GetOption(rtc::Socket::OPT_SNDBUF, &send_buffer_size)); | 254 &send_buffer_size)); |
270 ASSERT_EQ(expected, send_buffer_size); | 255 ASSERT_EQ(expected, send_buffer_size); |
271 } | 256 } |
272 } | 257 } |
273 } | 258 } |
274 | 259 |
275 // This function starts the port/address gathering and check the existence of | 260 // This function starts the port/address gathering and check the existence of |
276 // candidates as specified. When |expect_stun_candidate| is true, | 261 // candidates as specified. When |expect_stun_candidate| is true, |
277 // |stun_candidate_addr| carries the expected reflective address, which is | 262 // |stun_candidate_addr| carries the expected reflective address, which is |
278 // also the related address for TURN candidate if it is expected. Otherwise, | 263 // also the related address for TURN candidate if it is expected. Otherwise, |
279 // it should be ignore. | 264 // it should be ignore. |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
330 EXPECT_EQ(stun_candidate_addr, | 315 EXPECT_EQ(stun_candidate_addr, |
331 candidates_[total_candidates].related_address().ipaddr()); | 316 candidates_[total_candidates].related_address().ipaddr()); |
332 ++total_candidates; | 317 ++total_candidates; |
333 } | 318 } |
334 | 319 |
335 EXPECT_EQ(total_candidates, candidates_.size()); | 320 EXPECT_EQ(total_candidates, candidates_.size()); |
336 EXPECT_EQ(total_ports, ports_.size()); | 321 EXPECT_EQ(total_ports, ports_.size()); |
337 } | 322 } |
338 | 323 |
339 protected: | 324 protected: |
340 cricket::BasicPortAllocator& allocator() { return *allocator_; } | 325 cricket::BasicPortAllocator& allocator() { |
| 326 return *allocator_; |
| 327 } |
341 | 328 |
342 void OnPortReady(cricket::PortAllocatorSession* ses, | 329 void OnPortReady(cricket::PortAllocatorSession* ses, |
343 cricket::PortInterface* port) { | 330 cricket::PortInterface* port) { |
344 LOG(LS_INFO) << "OnPortReady: " << port->ToString(); | 331 LOG(LS_INFO) << "OnPortReady: " << port->ToString(); |
345 ports_.push_back(port); | 332 ports_.push_back(port); |
346 // Make sure the new port is added to ReadyPorts. | |
347 auto ready_ports = ses->ReadyPorts(); | |
348 EXPECT_NE(ready_ports.end(), | |
349 std::find(ready_ports.begin(), ready_ports.end(), port)); | |
350 } | 333 } |
351 void OnCandidatesReady(cricket::PortAllocatorSession* ses, | 334 void OnCandidatesReady(cricket::PortAllocatorSession* ses, |
352 const std::vector<cricket::Candidate>& candidates) { | 335 const std::vector<cricket::Candidate>& candidates) { |
353 for (size_t i = 0; i < candidates.size(); ++i) { | 336 for (size_t i = 0; i < candidates.size(); ++i) { |
354 LOG(LS_INFO) << "OnCandidatesReady: " << candidates[i].ToString(); | 337 LOG(LS_INFO) << "OnCandidatesReady: " << candidates[i].ToString(); |
355 candidates_.push_back(candidates[i]); | 338 candidates_.push_back(candidates[i]); |
356 } | 339 } |
357 // Make sure the new candidates are added to Candidates. | |
358 auto ses_candidates = ses->ReadyCandidates(); | |
359 for (const cricket::Candidate& candidate : candidates) { | |
360 EXPECT_NE( | |
361 ses_candidates.end(), | |
362 std::find(ses_candidates.begin(), ses_candidates.end(), candidate)); | |
363 } | |
364 } | 340 } |
365 | 341 |
366 bool HasRelayAddress(const cricket::ProtocolAddress& proto_addr) { | 342 bool HasRelayAddress(const cricket::ProtocolAddress& proto_addr) { |
367 for (size_t i = 0; i < allocator_->turn_servers().size(); ++i) { | 343 for (size_t i = 0; i < allocator_->turn_servers().size(); ++i) { |
368 cricket::RelayServerConfig server_config = allocator_->turn_servers()[i]; | 344 cricket::RelayServerConfig server_config = allocator_->turn_servers()[i]; |
369 cricket::PortList::const_iterator relay_port; | 345 cricket::PortList::const_iterator relay_port; |
370 for (relay_port = server_config.ports.begin(); | 346 for (relay_port = server_config.ports.begin(); |
371 relay_port != server_config.ports.end(); ++relay_port) { | 347 relay_port != server_config.ports.end(); ++relay_port) { |
372 if (proto_addr.address == relay_port->address && | 348 if (proto_addr.address == relay_port->address && |
373 proto_addr.proto == relay_port->proto) | 349 proto_addr.proto == relay_port->proto) |
374 return true; | 350 return true; |
375 } | 351 } |
376 } | 352 } |
377 return false; | 353 return false; |
378 } | 354 } |
379 | 355 |
380 void ResetWithStunServer(const rtc::SocketAddress& stun_server, | 356 void ResetWithStunServer(const rtc::SocketAddress& stun_server, |
381 bool with_nat) { | 357 bool with_nat) { |
(...skipping 26 matching lines...) Expand all Loading... |
408 cricket::TestTurnServer turn_server_; | 384 cricket::TestTurnServer turn_server_; |
409 rtc::FakeNetworkManager network_manager_; | 385 rtc::FakeNetworkManager network_manager_; |
410 std::unique_ptr<cricket::BasicPortAllocator> allocator_; | 386 std::unique_ptr<cricket::BasicPortAllocator> allocator_; |
411 std::unique_ptr<cricket::PortAllocatorSession> session_; | 387 std::unique_ptr<cricket::PortAllocatorSession> session_; |
412 std::vector<cricket::PortInterface*> ports_; | 388 std::vector<cricket::PortInterface*> ports_; |
413 std::vector<cricket::Candidate> candidates_; | 389 std::vector<cricket::Candidate> candidates_; |
414 bool candidate_allocation_done_; | 390 bool candidate_allocation_done_; |
415 }; | 391 }; |
416 | 392 |
417 // Tests that we can init the port allocator and create a session. | 393 // Tests that we can init the port allocator and create a session. |
418 TEST_F(BasicPortAllocatorTest, TestBasic) { | 394 TEST_F(PortAllocatorTest, TestBasic) { |
419 EXPECT_EQ(&network_manager_, allocator().network_manager()); | 395 EXPECT_EQ(&network_manager_, allocator().network_manager()); |
420 EXPECT_EQ(kStunAddr, *allocator().stun_servers().begin()); | 396 EXPECT_EQ(kStunAddr, *allocator().stun_servers().begin()); |
421 ASSERT_EQ(1u, allocator().turn_servers().size()); | 397 ASSERT_EQ(1u, allocator().turn_servers().size()); |
422 EXPECT_EQ(cricket::RELAY_GTURN, allocator().turn_servers()[0].type); | 398 EXPECT_EQ(cricket::RELAY_GTURN, allocator().turn_servers()[0].type); |
423 // Empty relay credentials are used for GTURN. | 399 // Empty relay credentials are used for GTURN. |
424 EXPECT_TRUE(allocator().turn_servers()[0].credentials.username.empty()); | 400 EXPECT_TRUE(allocator().turn_servers()[0].credentials.username.empty()); |
425 EXPECT_TRUE(allocator().turn_servers()[0].credentials.password.empty()); | 401 EXPECT_TRUE(allocator().turn_servers()[0].credentials.password.empty()); |
426 EXPECT_TRUE(HasRelayAddress( | 402 EXPECT_TRUE(HasRelayAddress(cricket::ProtocolAddress( |
427 cricket::ProtocolAddress(kRelayUdpIntAddr, cricket::PROTO_UDP))); | 403 kRelayUdpIntAddr, cricket::PROTO_UDP))); |
428 EXPECT_TRUE(HasRelayAddress( | 404 EXPECT_TRUE(HasRelayAddress(cricket::ProtocolAddress( |
429 cricket::ProtocolAddress(kRelayTcpIntAddr, cricket::PROTO_TCP))); | 405 kRelayTcpIntAddr, cricket::PROTO_TCP))); |
430 EXPECT_TRUE(HasRelayAddress( | 406 EXPECT_TRUE(HasRelayAddress(cricket::ProtocolAddress( |
431 cricket::ProtocolAddress(kRelaySslTcpIntAddr, cricket::PROTO_SSLTCP))); | 407 kRelaySslTcpIntAddr, cricket::PROTO_SSLTCP))); |
432 EXPECT_TRUE(CreateSession(cricket::ICE_CANDIDATE_COMPONENT_RTP)); | 408 EXPECT_TRUE(CreateSession(cricket::ICE_CANDIDATE_COMPONENT_RTP)); |
433 EXPECT_FALSE(session_->CandidatesAllocationDone()); | |
434 } | 409 } |
435 | 410 |
436 // Tests that our network filtering works properly. | 411 // Tests that our network filtering works properly. |
437 TEST_F(BasicPortAllocatorTest, TestIgnoreOnlyLoopbackNetworkByDefault) { | 412 TEST_F(PortAllocatorTest, TestIgnoreOnlyLoopbackNetworkByDefault) { |
438 AddInterface(SocketAddress(IPAddress(0x12345600U), 0), "test_eth0", | 413 AddInterface(SocketAddress(IPAddress(0x12345600U), 0), "test_eth0", |
439 rtc::ADAPTER_TYPE_ETHERNET); | 414 rtc::ADAPTER_TYPE_ETHERNET); |
440 AddInterface(SocketAddress(IPAddress(0x12345601U), 0), "test_wlan0", | 415 AddInterface(SocketAddress(IPAddress(0x12345601U), 0), "test_wlan0", |
441 rtc::ADAPTER_TYPE_WIFI); | 416 rtc::ADAPTER_TYPE_WIFI); |
442 AddInterface(SocketAddress(IPAddress(0x12345602U), 0), "test_cell0", | 417 AddInterface(SocketAddress(IPAddress(0x12345602U), 0), "test_cell0", |
443 rtc::ADAPTER_TYPE_CELLULAR); | 418 rtc::ADAPTER_TYPE_CELLULAR); |
444 AddInterface(SocketAddress(IPAddress(0x12345603U), 0), "test_vpn0", | 419 AddInterface(SocketAddress(IPAddress(0x12345603U), 0), "test_vpn0", |
445 rtc::ADAPTER_TYPE_VPN); | 420 rtc::ADAPTER_TYPE_VPN); |
446 AddInterface(SocketAddress(IPAddress(0x12345604U), 0), "test_lo", | 421 AddInterface(SocketAddress(IPAddress(0x12345604U), 0), "test_lo", |
447 rtc::ADAPTER_TYPE_LOOPBACK); | 422 rtc::ADAPTER_TYPE_LOOPBACK); |
448 EXPECT_TRUE(CreateSession(cricket::ICE_CANDIDATE_COMPONENT_RTP)); | 423 EXPECT_TRUE(CreateSession(cricket::ICE_CANDIDATE_COMPONENT_RTP)); |
449 session_->set_flags(cricket::PORTALLOCATOR_DISABLE_STUN | | 424 session_->set_flags(cricket::PORTALLOCATOR_DISABLE_STUN | |
450 cricket::PORTALLOCATOR_DISABLE_RELAY | | 425 cricket::PORTALLOCATOR_DISABLE_RELAY | |
451 cricket::PORTALLOCATOR_DISABLE_TCP); | 426 cricket::PORTALLOCATOR_DISABLE_TCP); |
452 session_->StartGettingPorts(); | 427 session_->StartGettingPorts(); |
453 EXPECT_TRUE_WAIT(candidate_allocation_done_, kDefaultAllocationTimeout); | 428 EXPECT_TRUE_WAIT(candidate_allocation_done_, kDefaultAllocationTimeout); |
454 EXPECT_EQ(4U, candidates_.size()); | 429 EXPECT_EQ(4U, candidates_.size()); |
455 for (cricket::Candidate candidate : candidates_) { | 430 for (cricket::Candidate candidate : candidates_) { |
456 EXPECT_LT(candidate.address().ip(), 0x12345604U); | 431 EXPECT_LT(candidate.address().ip(), 0x12345604U); |
457 } | 432 } |
458 } | 433 } |
459 | 434 |
460 TEST_F(BasicPortAllocatorTest, TestIgnoreNetworksAccordingToIgnoreMask) { | 435 TEST_F(PortAllocatorTest, TestIgnoreNetworksAccordingToIgnoreMask) { |
461 AddInterface(SocketAddress(IPAddress(0x12345600U), 0), "test_eth0", | 436 AddInterface(SocketAddress(IPAddress(0x12345600U), 0), "test_eth0", |
462 rtc::ADAPTER_TYPE_ETHERNET); | 437 rtc::ADAPTER_TYPE_ETHERNET); |
463 AddInterface(SocketAddress(IPAddress(0x12345601U), 0), "test_wlan0", | 438 AddInterface(SocketAddress(IPAddress(0x12345601U), 0), "test_wlan0", |
464 rtc::ADAPTER_TYPE_WIFI); | 439 rtc::ADAPTER_TYPE_WIFI); |
465 AddInterface(SocketAddress(IPAddress(0x12345602U), 0), "test_cell0", | 440 AddInterface(SocketAddress(IPAddress(0x12345602U), 0), "test_cell0", |
466 rtc::ADAPTER_TYPE_CELLULAR); | 441 rtc::ADAPTER_TYPE_CELLULAR); |
467 allocator_->SetNetworkIgnoreMask(rtc::ADAPTER_TYPE_ETHERNET | | 442 allocator_->SetNetworkIgnoreMask(rtc::ADAPTER_TYPE_ETHERNET | |
468 rtc::ADAPTER_TYPE_LOOPBACK | | 443 rtc::ADAPTER_TYPE_LOOPBACK | |
469 rtc::ADAPTER_TYPE_WIFI); | 444 rtc::ADAPTER_TYPE_WIFI); |
470 EXPECT_TRUE(CreateSession(cricket::ICE_CANDIDATE_COMPONENT_RTP)); | 445 EXPECT_TRUE(CreateSession(cricket::ICE_CANDIDATE_COMPONENT_RTP)); |
471 session_->set_flags(cricket::PORTALLOCATOR_DISABLE_STUN | | 446 session_->set_flags(cricket::PORTALLOCATOR_DISABLE_STUN | |
472 cricket::PORTALLOCATOR_DISABLE_RELAY | | 447 cricket::PORTALLOCATOR_DISABLE_RELAY | |
473 cricket::PORTALLOCATOR_DISABLE_TCP); | 448 cricket::PORTALLOCATOR_DISABLE_TCP); |
474 session_->StartGettingPorts(); | 449 session_->StartGettingPorts(); |
475 EXPECT_TRUE_WAIT(candidate_allocation_done_, kDefaultAllocationTimeout); | 450 EXPECT_TRUE_WAIT(candidate_allocation_done_, kDefaultAllocationTimeout); |
476 EXPECT_EQ(1U, candidates_.size()); | 451 EXPECT_EQ(1U, candidates_.size()); |
477 EXPECT_EQ(0x12345602U, candidates_[0].address().ip()); | 452 EXPECT_EQ(0x12345602U, candidates_[0].address().ip()); |
478 } | 453 } |
479 | 454 |
480 // Tests that we allocator session not trying to allocate ports for every 250ms. | 455 // Tests that we allocator session not trying to allocate ports for every 250ms. |
481 TEST_F(BasicPortAllocatorTest, TestNoNetworkInterface) { | 456 TEST_F(PortAllocatorTest, TestNoNetworkInterface) { |
482 EXPECT_TRUE(CreateSession(cricket::ICE_CANDIDATE_COMPONENT_RTP)); | 457 EXPECT_TRUE(CreateSession(cricket::ICE_CANDIDATE_COMPONENT_RTP)); |
483 session_->StartGettingPorts(); | 458 session_->StartGettingPorts(); |
484 // Waiting for one second to make sure BasicPortAllocatorSession has not | 459 // Waiting for one second to make sure BasicPortAllocatorSession has not |
485 // called OnAllocate multiple times. In old behavior it's called every 250ms. | 460 // called OnAllocate multiple times. In old behavior it's called every 250ms. |
486 // When there are no network interfaces, each execution of OnAllocate will | 461 // When there are no network interfaces, each execution of OnAllocate will |
487 // result in SignalCandidatesAllocationDone signal. | 462 // result in SignalCandidatesAllocationDone signal. |
488 rtc::Thread::Current()->ProcessMessages(1000); | 463 rtc::Thread::Current()->ProcessMessages(1000); |
489 EXPECT_TRUE(candidate_allocation_done_); | 464 EXPECT_TRUE(candidate_allocation_done_); |
490 EXPECT_EQ(0U, candidates_.size()); | 465 EXPECT_EQ(0U, candidates_.size()); |
491 } | 466 } |
492 | 467 |
493 // Test that we could use loopback interface as host candidate. | 468 // Test that we could use loopback interface as host candidate. |
494 TEST_F(BasicPortAllocatorTest, TestLoopbackNetworkInterface) { | 469 TEST_F(PortAllocatorTest, TestLoopbackNetworkInterface) { |
495 AddInterface(kLoopbackAddr, "test_loopback", rtc::ADAPTER_TYPE_LOOPBACK); | 470 AddInterface(kLoopbackAddr, "test_loopback", rtc::ADAPTER_TYPE_LOOPBACK); |
496 allocator_->SetNetworkIgnoreMask(0); | 471 allocator_->SetNetworkIgnoreMask(0); |
497 EXPECT_TRUE(CreateSession(cricket::ICE_CANDIDATE_COMPONENT_RTP)); | 472 EXPECT_TRUE(CreateSession(cricket::ICE_CANDIDATE_COMPONENT_RTP)); |
498 session_->set_flags(cricket::PORTALLOCATOR_DISABLE_STUN | | 473 session_->set_flags(cricket::PORTALLOCATOR_DISABLE_STUN | |
499 cricket::PORTALLOCATOR_DISABLE_RELAY | | 474 cricket::PORTALLOCATOR_DISABLE_RELAY | |
500 cricket::PORTALLOCATOR_DISABLE_TCP); | 475 cricket::PORTALLOCATOR_DISABLE_TCP); |
501 session_->StartGettingPorts(); | 476 session_->StartGettingPorts(); |
502 EXPECT_TRUE_WAIT(candidate_allocation_done_, kDefaultAllocationTimeout); | 477 EXPECT_TRUE_WAIT(candidate_allocation_done_, kDefaultAllocationTimeout); |
503 EXPECT_EQ(1U, candidates_.size()); | 478 EXPECT_EQ(1U, candidates_.size()); |
504 } | 479 } |
505 | 480 |
506 // Tests that we can get all the desired addresses successfully. | 481 // Tests that we can get all the desired addresses successfully. |
507 TEST_F(BasicPortAllocatorTest, TestGetAllPortsWithMinimumStepDelay) { | 482 TEST_F(PortAllocatorTest, TestGetAllPortsWithMinimumStepDelay) { |
508 AddInterface(kClientAddr); | 483 AddInterface(kClientAddr); |
509 EXPECT_TRUE(CreateSession(cricket::ICE_CANDIDATE_COMPONENT_RTP)); | 484 EXPECT_TRUE(CreateSession(cricket::ICE_CANDIDATE_COMPONENT_RTP)); |
510 session_->StartGettingPorts(); | 485 session_->StartGettingPorts(); |
511 ASSERT_EQ_WAIT(7U, candidates_.size(), kDefaultAllocationTimeout); | 486 ASSERT_EQ_WAIT(7U, candidates_.size(), kDefaultAllocationTimeout); |
512 EXPECT_EQ(4U, ports_.size()); | 487 EXPECT_EQ(4U, ports_.size()); |
513 EXPECT_PRED5(CheckCandidate, candidates_[0], | 488 EXPECT_PRED5(CheckCandidate, candidates_[0], |
514 cricket::ICE_CANDIDATE_COMPONENT_RTP, "local", "udp", | 489 cricket::ICE_CANDIDATE_COMPONENT_RTP, "local", "udp", kClientAddr); |
515 kClientAddr); | |
516 EXPECT_PRED5(CheckCandidate, candidates_[1], | 490 EXPECT_PRED5(CheckCandidate, candidates_[1], |
517 cricket::ICE_CANDIDATE_COMPONENT_RTP, "stun", "udp", | 491 cricket::ICE_CANDIDATE_COMPONENT_RTP, "stun", "udp", kClientAddr); |
518 kClientAddr); | |
519 EXPECT_PRED5(CheckCandidate, candidates_[2], | 492 EXPECT_PRED5(CheckCandidate, candidates_[2], |
520 cricket::ICE_CANDIDATE_COMPONENT_RTP, "relay", "udp", | 493 cricket::ICE_CANDIDATE_COMPONENT_RTP, "relay", "udp", kRelayUdpIntAddr); |
521 kRelayUdpIntAddr); | |
522 EXPECT_PRED5(CheckCandidate, candidates_[3], | 494 EXPECT_PRED5(CheckCandidate, candidates_[3], |
523 cricket::ICE_CANDIDATE_COMPONENT_RTP, "relay", "udp", | 495 cricket::ICE_CANDIDATE_COMPONENT_RTP, "relay", "udp", kRelayUdpExtAddr); |
524 kRelayUdpExtAddr); | |
525 EXPECT_PRED5(CheckCandidate, candidates_[4], | 496 EXPECT_PRED5(CheckCandidate, candidates_[4], |
526 cricket::ICE_CANDIDATE_COMPONENT_RTP, "relay", "tcp", | 497 cricket::ICE_CANDIDATE_COMPONENT_RTP, "relay", "tcp", kRelayTcpIntAddr); |
527 kRelayTcpIntAddr); | |
528 EXPECT_PRED5(CheckCandidate, candidates_[5], | 498 EXPECT_PRED5(CheckCandidate, candidates_[5], |
529 cricket::ICE_CANDIDATE_COMPONENT_RTP, "local", "tcp", | 499 cricket::ICE_CANDIDATE_COMPONENT_RTP, "local", "tcp", kClientAddr); |
530 kClientAddr); | |
531 EXPECT_PRED5(CheckCandidate, candidates_[6], | 500 EXPECT_PRED5(CheckCandidate, candidates_[6], |
532 cricket::ICE_CANDIDATE_COMPONENT_RTP, "relay", "ssltcp", | 501 cricket::ICE_CANDIDATE_COMPONENT_RTP, |
533 kRelaySslTcpIntAddr); | 502 "relay", "ssltcp", kRelaySslTcpIntAddr); |
534 EXPECT_TRUE(candidate_allocation_done_); | 503 EXPECT_TRUE(candidate_allocation_done_); |
535 } | 504 } |
536 | 505 |
537 // Test that when the same network interface is brought down and up, the | 506 // Test that when the same network interface is brought down and up, the |
538 // port allocator session will restart a new allocation sequence if | 507 // port allocator session will restart a new allocation sequence if |
539 // it is not stopped. | 508 // it is not stopped. |
540 TEST_F(BasicPortAllocatorTest, TestSameNetworkDownAndUpWhenSessionNotStopped) { | 509 TEST_F(PortAllocatorTest, TestSameNetworkDownAndUpWhenSessionNotStopped) { |
541 std::string if_name("test_net0"); | 510 std::string if_name("test_net0"); |
542 AddInterface(kClientAddr, if_name); | 511 AddInterface(kClientAddr, if_name); |
543 EXPECT_TRUE(CreateSession(cricket::ICE_CANDIDATE_COMPONENT_RTP)); | 512 EXPECT_TRUE(CreateSession(cricket::ICE_CANDIDATE_COMPONENT_RTP)); |
544 session_->StartGettingPorts(); | 513 session_->StartGettingPorts(); |
545 ASSERT_EQ_WAIT(7U, candidates_.size(), kDefaultAllocationTimeout); | 514 ASSERT_EQ_WAIT(7U, candidates_.size(), kDefaultAllocationTimeout); |
546 EXPECT_EQ(4U, ports_.size()); | 515 EXPECT_EQ(4U, ports_.size()); |
547 EXPECT_TRUE(candidate_allocation_done_); | 516 EXPECT_TRUE(candidate_allocation_done_); |
548 candidate_allocation_done_ = false; | 517 candidate_allocation_done_ = false; |
549 candidates_.clear(); | 518 candidates_.clear(); |
550 ports_.clear(); | 519 ports_.clear(); |
551 | 520 |
552 RemoveInterface(kClientAddr); | 521 RemoveInterface(kClientAddr); |
553 ASSERT_EQ_WAIT(0U, candidates_.size(), kDefaultAllocationTimeout); | 522 ASSERT_EQ_WAIT(0U, candidates_.size(), kDefaultAllocationTimeout); |
554 EXPECT_EQ(0U, ports_.size()); | 523 EXPECT_EQ(0U, ports_.size()); |
555 EXPECT_FALSE(candidate_allocation_done_); | 524 EXPECT_FALSE(candidate_allocation_done_); |
556 | 525 |
557 // When the same interfaces are added again, new candidates/ports should be | 526 // When the same interfaces are added again, new candidates/ports should be |
558 // generated. | 527 // generated. |
559 AddInterface(kClientAddr, if_name); | 528 AddInterface(kClientAddr, if_name); |
560 ASSERT_EQ_WAIT(7U, candidates_.size(), kDefaultAllocationTimeout); | 529 ASSERT_EQ_WAIT(7U, candidates_.size(), kDefaultAllocationTimeout); |
561 EXPECT_EQ(4U, ports_.size()); | 530 EXPECT_EQ(4U, ports_.size()); |
562 EXPECT_TRUE(candidate_allocation_done_); | 531 EXPECT_TRUE(candidate_allocation_done_); |
563 } | 532 } |
564 | 533 |
565 // Test that when the same network interface is brought down and up, the | 534 // Test that when the same network interface is brought down and up, the |
566 // port allocator session will not restart a new allocation sequence if | 535 // port allocator session will not restart a new allocation sequence if |
567 // it is stopped. | 536 // it is stopped. |
568 TEST_F(BasicPortAllocatorTest, TestSameNetworkDownAndUpWhenSessionStopped) { | 537 TEST_F(PortAllocatorTest, TestSameNetworkDownAndUpWhenSessionStopped) { |
569 std::string if_name("test_net0"); | 538 std::string if_name("test_net0"); |
570 AddInterface(kClientAddr, if_name); | 539 AddInterface(kClientAddr, if_name); |
571 EXPECT_TRUE(CreateSession(cricket::ICE_CANDIDATE_COMPONENT_RTP)); | 540 EXPECT_TRUE(CreateSession(cricket::ICE_CANDIDATE_COMPONENT_RTP)); |
572 session_->StartGettingPorts(); | 541 session_->StartGettingPorts(); |
573 ASSERT_EQ_WAIT(7U, candidates_.size(), kDefaultAllocationTimeout); | 542 ASSERT_EQ_WAIT(7U, candidates_.size(), kDefaultAllocationTimeout); |
574 EXPECT_EQ(4U, ports_.size()); | 543 EXPECT_EQ(4U, ports_.size()); |
575 EXPECT_TRUE(candidate_allocation_done_); | 544 EXPECT_TRUE(candidate_allocation_done_); |
576 session_->StopGettingPorts(); | 545 session_->StopGettingPorts(); |
577 candidates_.clear(); | 546 candidates_.clear(); |
578 ports_.clear(); | 547 ports_.clear(); |
579 | 548 |
580 RemoveInterface(kClientAddr); | 549 RemoveInterface(kClientAddr); |
581 ASSERT_EQ_WAIT(0U, candidates_.size(), kDefaultAllocationTimeout); | 550 ASSERT_EQ_WAIT(0U, candidates_.size(), kDefaultAllocationTimeout); |
582 EXPECT_EQ(0U, ports_.size()); | 551 EXPECT_EQ(0U, ports_.size()); |
583 | 552 |
584 // When the same interfaces are added again, new candidates/ports should not | 553 // When the same interfaces are added again, new candidates/ports should not |
585 // be generated because the session has stopped. | 554 // be generated because the session has stopped. |
586 AddInterface(kClientAddr, if_name); | 555 AddInterface(kClientAddr, if_name); |
587 ASSERT_EQ_WAIT(0U, candidates_.size(), kDefaultAllocationTimeout); | 556 ASSERT_EQ_WAIT(0U, candidates_.size(), kDefaultAllocationTimeout); |
588 EXPECT_EQ(0U, ports_.size()); | 557 EXPECT_EQ(0U, ports_.size()); |
589 EXPECT_TRUE(candidate_allocation_done_); | 558 EXPECT_TRUE(candidate_allocation_done_); |
590 } | 559 } |
591 | 560 |
592 // Verify candidates with default step delay of 1sec. | 561 // Verify candidates with default step delay of 1sec. |
593 TEST_F(BasicPortAllocatorTest, TestGetAllPortsWithOneSecondStepDelay) { | 562 TEST_F(PortAllocatorTest, TestGetAllPortsWithOneSecondStepDelay) { |
594 AddInterface(kClientAddr); | 563 AddInterface(kClientAddr); |
595 allocator_->set_step_delay(cricket::kDefaultStepDelay); | 564 allocator_->set_step_delay(cricket::kDefaultStepDelay); |
596 EXPECT_TRUE(CreateSession(cricket::ICE_CANDIDATE_COMPONENT_RTP)); | 565 EXPECT_TRUE(CreateSession(cricket::ICE_CANDIDATE_COMPONENT_RTP)); |
597 session_->StartGettingPorts(); | 566 session_->StartGettingPorts(); |
598 ASSERT_EQ_WAIT(2U, candidates_.size(), 1000); | 567 ASSERT_EQ_WAIT(2U, candidates_.size(), 1000); |
599 EXPECT_EQ(2U, ports_.size()); | 568 EXPECT_EQ(2U, ports_.size()); |
600 ASSERT_EQ_WAIT(4U, candidates_.size(), 2000); | 569 ASSERT_EQ_WAIT(4U, candidates_.size(), 2000); |
601 EXPECT_EQ(3U, ports_.size()); | 570 EXPECT_EQ(3U, ports_.size()); |
602 EXPECT_PRED5(CheckCandidate, candidates_[2], | 571 EXPECT_PRED5(CheckCandidate, candidates_[2], |
603 cricket::ICE_CANDIDATE_COMPONENT_RTP, "relay", "udp", | 572 cricket::ICE_CANDIDATE_COMPONENT_RTP, "relay", "udp", kRelayUdpIntAddr); |
604 kRelayUdpIntAddr); | |
605 EXPECT_PRED5(CheckCandidate, candidates_[3], | 573 EXPECT_PRED5(CheckCandidate, candidates_[3], |
606 cricket::ICE_CANDIDATE_COMPONENT_RTP, "relay", "udp", | 574 cricket::ICE_CANDIDATE_COMPONENT_RTP, "relay", "udp", kRelayUdpExtAddr); |
607 kRelayUdpExtAddr); | |
608 ASSERT_EQ_WAIT(6U, candidates_.size(), 1500); | 575 ASSERT_EQ_WAIT(6U, candidates_.size(), 1500); |
609 EXPECT_PRED5(CheckCandidate, candidates_[4], | 576 EXPECT_PRED5(CheckCandidate, candidates_[4], |
610 cricket::ICE_CANDIDATE_COMPONENT_RTP, "relay", "tcp", | 577 cricket::ICE_CANDIDATE_COMPONENT_RTP, "relay", "tcp", kRelayTcpIntAddr); |
611 kRelayTcpIntAddr); | |
612 EXPECT_PRED5(CheckCandidate, candidates_[5], | 578 EXPECT_PRED5(CheckCandidate, candidates_[5], |
613 cricket::ICE_CANDIDATE_COMPONENT_RTP, "local", "tcp", | 579 cricket::ICE_CANDIDATE_COMPONENT_RTP, "local", "tcp", kClientAddr); |
614 kClientAddr); | |
615 EXPECT_EQ(4U, ports_.size()); | 580 EXPECT_EQ(4U, ports_.size()); |
616 ASSERT_EQ_WAIT(7U, candidates_.size(), 2000); | 581 ASSERT_EQ_WAIT(7U, candidates_.size(), 2000); |
617 EXPECT_PRED5(CheckCandidate, candidates_[6], | 582 EXPECT_PRED5(CheckCandidate, candidates_[6], |
618 cricket::ICE_CANDIDATE_COMPONENT_RTP, "relay", "ssltcp", | 583 cricket::ICE_CANDIDATE_COMPONENT_RTP, |
619 kRelaySslTcpIntAddr); | 584 "relay", "ssltcp", kRelaySslTcpIntAddr); |
620 EXPECT_EQ(4U, ports_.size()); | 585 EXPECT_EQ(4U, ports_.size()); |
621 EXPECT_TRUE(candidate_allocation_done_); | 586 EXPECT_TRUE(candidate_allocation_done_); |
622 // If we Stop gathering now, we shouldn't get a second "done" callback. | 587 // If we Stop gathering now, we shouldn't get a second "done" callback. |
623 session_->StopGettingPorts(); | 588 session_->StopGettingPorts(); |
624 } | 589 } |
625 | 590 |
626 TEST_F(BasicPortAllocatorTest, TestSetupVideoRtpPortsWithNormalSendBuffers) { | 591 TEST_F(PortAllocatorTest, TestSetupVideoRtpPortsWithNormalSendBuffers) { |
627 AddInterface(kClientAddr); | 592 AddInterface(kClientAddr); |
628 EXPECT_TRUE( | 593 EXPECT_TRUE(CreateSession(cricket::ICE_CANDIDATE_COMPONENT_RTP, |
629 CreateSession(cricket::ICE_CANDIDATE_COMPONENT_RTP, cricket::CN_VIDEO)); | 594 cricket::CN_VIDEO)); |
630 session_->StartGettingPorts(); | 595 session_->StartGettingPorts(); |
631 ASSERT_EQ_WAIT(7U, candidates_.size(), kDefaultAllocationTimeout); | 596 ASSERT_EQ_WAIT(7U, candidates_.size(), kDefaultAllocationTimeout); |
632 EXPECT_TRUE(candidate_allocation_done_); | 597 EXPECT_TRUE(candidate_allocation_done_); |
633 // If we Stop gathering now, we shouldn't get a second "done" callback. | 598 // If we Stop gathering now, we shouldn't get a second "done" callback. |
634 session_->StopGettingPorts(); | 599 session_->StopGettingPorts(); |
635 | 600 |
636 // All ports should have unset send-buffer sizes. | 601 // All ports should have unset send-buffer sizes. |
637 CheckSendBufferSizesOfAllPorts(-1); | 602 CheckSendBufferSizesOfAllPorts(-1); |
638 } | 603 } |
639 | 604 |
640 // Tests that we can get callback after StopGetAllPorts. | 605 // Tests that we can get callback after StopGetAllPorts. |
641 TEST_F(BasicPortAllocatorTest, TestStopGetAllPorts) { | 606 TEST_F(PortAllocatorTest, TestStopGetAllPorts) { |
642 AddInterface(kClientAddr); | 607 AddInterface(kClientAddr); |
643 EXPECT_TRUE(CreateSession(cricket::ICE_CANDIDATE_COMPONENT_RTP)); | 608 EXPECT_TRUE(CreateSession(cricket::ICE_CANDIDATE_COMPONENT_RTP)); |
644 session_->StartGettingPorts(); | 609 session_->StartGettingPorts(); |
645 ASSERT_EQ_WAIT(2U, candidates_.size(), kDefaultAllocationTimeout); | 610 ASSERT_EQ_WAIT(2U, candidates_.size(), kDefaultAllocationTimeout); |
646 EXPECT_EQ(2U, ports_.size()); | 611 EXPECT_EQ(2U, ports_.size()); |
647 session_->StopGettingPorts(); | 612 session_->StopGettingPorts(); |
648 EXPECT_TRUE_WAIT(candidate_allocation_done_, kDefaultAllocationTimeout); | 613 EXPECT_TRUE_WAIT(candidate_allocation_done_, kDefaultAllocationTimeout); |
649 } | 614 } |
650 | 615 |
651 // Test that we restrict client ports appropriately when a port range is set. | 616 // Test that we restrict client ports appropriately when a port range is set. |
652 // We check the candidates for udp/stun/tcp ports, and the from address | 617 // We check the candidates for udp/stun/tcp ports, and the from address |
653 // for relay ports. | 618 // for relay ports. |
654 TEST_F(BasicPortAllocatorTest, TestGetAllPortsPortRange) { | 619 TEST_F(PortAllocatorTest, TestGetAllPortsPortRange) { |
655 AddInterface(kClientAddr); | 620 AddInterface(kClientAddr); |
656 // Check that an invalid port range fails. | 621 // Check that an invalid port range fails. |
657 EXPECT_FALSE(SetPortRange(kMaxPort, kMinPort)); | 622 EXPECT_FALSE(SetPortRange(kMaxPort, kMinPort)); |
658 // Check that a null port range succeeds. | 623 // Check that a null port range succeeds. |
659 EXPECT_TRUE(SetPortRange(0, 0)); | 624 EXPECT_TRUE(SetPortRange(0, 0)); |
660 // Check that a valid port range succeeds. | 625 // Check that a valid port range succeeds. |
661 EXPECT_TRUE(SetPortRange(kMinPort, kMaxPort)); | 626 EXPECT_TRUE(SetPortRange(kMinPort, kMaxPort)); |
662 EXPECT_TRUE(CreateSession(cricket::ICE_CANDIDATE_COMPONENT_RTP)); | 627 EXPECT_TRUE(CreateSession(cricket::ICE_CANDIDATE_COMPONENT_RTP)); |
663 session_->StartGettingPorts(); | 628 session_->StartGettingPorts(); |
664 ASSERT_EQ_WAIT(7U, candidates_.size(), kDefaultAllocationTimeout); | 629 ASSERT_EQ_WAIT(7U, candidates_.size(), kDefaultAllocationTimeout); |
665 EXPECT_EQ(4U, ports_.size()); | 630 EXPECT_EQ(4U, ports_.size()); |
666 // Check the port number for the UDP port object. | 631 // Check the port number for the UDP port object. |
667 EXPECT_PRED3(CheckPort, candidates_[0].address(), kMinPort, kMaxPort); | 632 EXPECT_PRED3(CheckPort, candidates_[0].address(), kMinPort, kMaxPort); |
668 // Check the port number for the STUN port object. | 633 // Check the port number for the STUN port object. |
669 EXPECT_PRED3(CheckPort, candidates_[1].address(), kMinPort, kMaxPort); | 634 EXPECT_PRED3(CheckPort, candidates_[1].address(), kMinPort, kMaxPort); |
670 // Check the port number used to connect to the relay server. | 635 // Check the port number used to connect to the relay server. |
671 EXPECT_PRED3(CheckPort, relay_server_.GetConnection(0).source(), kMinPort, | 636 EXPECT_PRED3(CheckPort, relay_server_.GetConnection(0).source(), |
672 kMaxPort); | 637 kMinPort, kMaxPort); |
673 // Check the port number for the TCP port object. | 638 // Check the port number for the TCP port object. |
674 EXPECT_PRED3(CheckPort, candidates_[5].address(), kMinPort, kMaxPort); | 639 EXPECT_PRED3(CheckPort, candidates_[5].address(), kMinPort, kMaxPort); |
675 EXPECT_TRUE(candidate_allocation_done_); | 640 EXPECT_TRUE(candidate_allocation_done_); |
676 } | 641 } |
677 | 642 |
678 // Test that we don't crash or malfunction if we have no network adapters. | 643 // Test that we don't crash or malfunction if we have no network adapters. |
679 TEST_F(BasicPortAllocatorTest, TestGetAllPortsNoAdapters) { | 644 TEST_F(PortAllocatorTest, TestGetAllPortsNoAdapters) { |
680 EXPECT_TRUE(CreateSession(cricket::ICE_CANDIDATE_COMPONENT_RTP)); | 645 EXPECT_TRUE(CreateSession(cricket::ICE_CANDIDATE_COMPONENT_RTP)); |
681 session_->StartGettingPorts(); | 646 session_->StartGettingPorts(); |
682 rtc::Thread::Current()->ProcessMessages(100); | 647 rtc::Thread::Current()->ProcessMessages(100); |
683 // Without network adapter, we should not get any candidate. | 648 // Without network adapter, we should not get any candidate. |
684 EXPECT_EQ(0U, candidates_.size()); | 649 EXPECT_EQ(0U, candidates_.size()); |
685 EXPECT_TRUE(candidate_allocation_done_); | 650 EXPECT_TRUE(candidate_allocation_done_); |
686 } | 651 } |
687 | 652 |
688 // Test that when enumeration is disabled, we should not have any ports when | 653 // Test that when enumeration is disabled, we should not have any ports when |
689 // candidate_filter() is set to CF_RELAY and no relay is specified. | 654 // candidate_filter() is set to CF_RELAY and no relay is specified. |
690 TEST_F(BasicPortAllocatorTest, | 655 TEST_F(PortAllocatorTest, |
691 TestDisableAdapterEnumerationWithoutNatRelayTransportOnly) { | 656 TestDisableAdapterEnumerationWithoutNatRelayTransportOnly) { |
692 ResetWithStunServerNoNat(kStunAddr); | 657 ResetWithStunServerNoNat(kStunAddr); |
693 allocator().set_candidate_filter(cricket::CF_RELAY); | 658 allocator().set_candidate_filter(cricket::CF_RELAY); |
694 // Expect to see no ports and no candidates. | 659 // Expect to see no ports and no candidates. |
695 CheckDisableAdapterEnumeration(0U, rtc::IPAddress(), rtc::IPAddress(), | 660 CheckDisableAdapterEnumeration(0U, rtc::IPAddress(), rtc::IPAddress(), |
696 rtc::IPAddress(), rtc::IPAddress()); | 661 rtc::IPAddress(), rtc::IPAddress()); |
697 } | 662 } |
698 | 663 |
699 // Test that even with multiple interfaces, the result should still be a single | 664 // Test that even with multiple interfaces, the result should still be a single |
700 // default private, one STUN and one TURN candidate since we bind to any address | 665 // default private, one STUN and one TURN candidate since we bind to any address |
701 // (i.e. all 0s). | 666 // (i.e. all 0s). |
702 TEST_F(BasicPortAllocatorTest, | 667 TEST_F(PortAllocatorTest, |
703 TestDisableAdapterEnumerationBehindNatMultipleInterfaces) { | 668 TestDisableAdapterEnumerationBehindNatMultipleInterfaces) { |
704 AddInterface(kPrivateAddr); | 669 AddInterface(kPrivateAddr); |
705 AddInterface(kPrivateAddr2); | 670 AddInterface(kPrivateAddr2); |
706 ResetWithStunServerAndNat(kStunAddr); | 671 ResetWithStunServerAndNat(kStunAddr); |
707 AddTurnServers(kTurnUdpIntAddr, rtc::SocketAddress()); | 672 AddTurnServers(kTurnUdpIntAddr, rtc::SocketAddress()); |
708 | 673 |
709 // Enable IPv6 here. Since the network_manager doesn't have IPv6 default | 674 // Enable IPv6 here. Since the network_manager doesn't have IPv6 default |
710 // address set and we have no IPv6 STUN server, there should be no IPv6 | 675 // address set and we have no IPv6 STUN server, there should be no IPv6 |
711 // candidates. | 676 // candidates. |
712 EXPECT_TRUE(CreateSession(cricket::ICE_CANDIDATE_COMPONENT_RTP)); | 677 EXPECT_TRUE(CreateSession(cricket::ICE_CANDIDATE_COMPONENT_RTP)); |
713 session_->set_flags(cricket::PORTALLOCATOR_ENABLE_IPV6); | 678 session_->set_flags(cricket::PORTALLOCATOR_ENABLE_IPV6); |
714 | 679 |
715 // Expect to see 3 ports for IPv4: HOST/STUN, TURN/UDP and TCP ports, 2 ports | 680 // Expect to see 3 ports for IPv4: HOST/STUN, TURN/UDP and TCP ports, 2 ports |
716 // for IPv6: HOST, and TCP. Only IPv4 candidates: a default private, STUN and | 681 // for IPv6: HOST, and TCP. Only IPv4 candidates: a default private, STUN and |
717 // TURN/UDP candidates. | 682 // TURN/UDP candidates. |
718 CheckDisableAdapterEnumeration(5U, kPrivateAddr.ipaddr(), | 683 CheckDisableAdapterEnumeration(5U, kPrivateAddr.ipaddr(), |
719 kNatUdpAddr.ipaddr(), kTurnUdpExtAddr.ipaddr(), | 684 kNatUdpAddr.ipaddr(), kTurnUdpExtAddr.ipaddr(), |
720 rtc::IPAddress()); | 685 rtc::IPAddress()); |
721 } | 686 } |
722 | 687 |
723 // Test that we should get a default private, STUN, TURN/UDP and TURN/TCP | 688 // Test that we should get a default private, STUN, TURN/UDP and TURN/TCP |
724 // candidates when both TURN/UDP and TURN/TCP servers are specified. | 689 // candidates when both TURN/UDP and TURN/TCP servers are specified. |
725 TEST_F(BasicPortAllocatorTest, TestDisableAdapterEnumerationBehindNatWithTcp) { | 690 TEST_F(PortAllocatorTest, TestDisableAdapterEnumerationBehindNatWithTcp) { |
726 turn_server_.AddInternalSocket(kTurnTcpIntAddr, cricket::PROTO_TCP); | 691 turn_server_.AddInternalSocket(kTurnTcpIntAddr, cricket::PROTO_TCP); |
727 AddInterface(kPrivateAddr); | 692 AddInterface(kPrivateAddr); |
728 ResetWithStunServerAndNat(kStunAddr); | 693 ResetWithStunServerAndNat(kStunAddr); |
729 AddTurnServers(kTurnUdpIntAddr, kTurnTcpIntAddr); | 694 AddTurnServers(kTurnUdpIntAddr, kTurnTcpIntAddr); |
730 // Expect to see 4 ports - STUN, TURN/UDP, TURN/TCP and TCP port. A default | 695 // Expect to see 4 ports - STUN, TURN/UDP, TURN/TCP and TCP port. A default |
731 // private, STUN, TURN/UDP, and TURN/TCP candidates. | 696 // private, STUN, TURN/UDP, and TURN/TCP candidates. |
732 CheckDisableAdapterEnumeration(4U, kPrivateAddr.ipaddr(), | 697 CheckDisableAdapterEnumeration(4U, kPrivateAddr.ipaddr(), |
733 kNatUdpAddr.ipaddr(), kTurnUdpExtAddr.ipaddr(), | 698 kNatUdpAddr.ipaddr(), kTurnUdpExtAddr.ipaddr(), |
734 kTurnUdpExtAddr.ipaddr()); | 699 kTurnUdpExtAddr.ipaddr()); |
735 } | 700 } |
736 | 701 |
737 // Test that when adapter enumeration is disabled, for endpoints without | 702 // Test that when adapter enumeration is disabled, for endpoints without |
738 // STUN/TURN specified, a default private candidate is still generated. | 703 // STUN/TURN specified, a default private candidate is still generated. |
739 TEST_F(BasicPortAllocatorTest, | 704 TEST_F(PortAllocatorTest, TestDisableAdapterEnumerationWithoutNatOrServers) { |
740 TestDisableAdapterEnumerationWithoutNatOrServers) { | |
741 ResetWithNoServersOrNat(); | 705 ResetWithNoServersOrNat(); |
742 // Expect to see 2 ports: STUN and TCP ports, one default private candidate. | 706 // Expect to see 2 ports: STUN and TCP ports, one default private candidate. |
743 CheckDisableAdapterEnumeration(2U, kPrivateAddr.ipaddr(), rtc::IPAddress(), | 707 CheckDisableAdapterEnumeration(2U, kPrivateAddr.ipaddr(), rtc::IPAddress(), |
744 rtc::IPAddress(), rtc::IPAddress()); | 708 rtc::IPAddress(), rtc::IPAddress()); |
745 } | 709 } |
746 | 710 |
747 // Test that when adapter enumeration is disabled, with | 711 // Test that when adapter enumeration is disabled, with |
748 // PORTALLOCATOR_DISABLE_LOCALHOST_CANDIDATE specified, for endpoints not behind | 712 // PORTALLOCATOR_DISABLE_LOCALHOST_CANDIDATE specified, for endpoints not behind |
749 // a NAT, there is no local candidate. | 713 // a NAT, there is no local candidate. |
750 TEST_F(BasicPortAllocatorTest, | 714 TEST_F(PortAllocatorTest, |
751 TestDisableAdapterEnumerationWithoutNatLocalhostCandidateDisabled) { | 715 TestDisableAdapterEnumerationWithoutNatLocalhostCandidateDisabled) { |
752 ResetWithStunServerNoNat(kStunAddr); | 716 ResetWithStunServerNoNat(kStunAddr); |
753 EXPECT_TRUE(CreateSession(cricket::ICE_CANDIDATE_COMPONENT_RTP)); | 717 EXPECT_TRUE(CreateSession(cricket::ICE_CANDIDATE_COMPONENT_RTP)); |
754 session_->set_flags(cricket::PORTALLOCATOR_DISABLE_DEFAULT_LOCAL_CANDIDATE); | 718 session_->set_flags(cricket::PORTALLOCATOR_DISABLE_DEFAULT_LOCAL_CANDIDATE); |
755 // Expect to see 2 ports: STUN and TCP ports, localhost candidate and STUN | 719 // Expect to see 2 ports: STUN and TCP ports, localhost candidate and STUN |
756 // candidate. | 720 // candidate. |
757 CheckDisableAdapterEnumeration(2U, rtc::IPAddress(), rtc::IPAddress(), | 721 CheckDisableAdapterEnumeration(2U, rtc::IPAddress(), rtc::IPAddress(), |
758 rtc::IPAddress(), rtc::IPAddress()); | 722 rtc::IPAddress(), rtc::IPAddress()); |
759 } | 723 } |
760 | 724 |
761 // Test that when adapter enumeration is disabled, with | 725 // Test that when adapter enumeration is disabled, with |
762 // PORTALLOCATOR_DISABLE_LOCALHOST_CANDIDATE specified, for endpoints not behind | 726 // PORTALLOCATOR_DISABLE_LOCALHOST_CANDIDATE specified, for endpoints not behind |
763 // a NAT, there is no local candidate. However, this specified default route | 727 // a NAT, there is no local candidate. However, this specified default route |
764 // (kClientAddr) which was discovered when sending STUN requests, will become | 728 // (kClientAddr) which was discovered when sending STUN requests, will become |
765 // the srflx addresses. | 729 // the srflx addresses. |
766 TEST_F( | 730 TEST_F( |
767 BasicPortAllocatorTest, | 731 PortAllocatorTest, |
768 TestDisableAdapterEnumerationWithoutNatLocalhostCandidateDisabledWithDiffere
ntDefaultRoute) { | 732 TestDisableAdapterEnumerationWithoutNatLocalhostCandidateDisabledWithDiffere
ntDefaultRoute) { |
769 ResetWithStunServerNoNat(kStunAddr); | 733 ResetWithStunServerNoNat(kStunAddr); |
770 AddInterfaceAsDefaultRoute(kClientAddr); | 734 AddInterfaceAsDefaultRoute(kClientAddr); |
771 EXPECT_TRUE(CreateSession(cricket::ICE_CANDIDATE_COMPONENT_RTP)); | 735 EXPECT_TRUE(CreateSession(cricket::ICE_CANDIDATE_COMPONENT_RTP)); |
772 session_->set_flags(cricket::PORTALLOCATOR_DISABLE_DEFAULT_LOCAL_CANDIDATE); | 736 session_->set_flags(cricket::PORTALLOCATOR_DISABLE_DEFAULT_LOCAL_CANDIDATE); |
773 // Expect to see 2 ports: STUN and TCP ports, localhost candidate and STUN | 737 // Expect to see 2 ports: STUN and TCP ports, localhost candidate and STUN |
774 // candidate. | 738 // candidate. |
775 CheckDisableAdapterEnumeration(2U, rtc::IPAddress(), kClientAddr.ipaddr(), | 739 CheckDisableAdapterEnumeration(2U, rtc::IPAddress(), kClientAddr.ipaddr(), |
776 rtc::IPAddress(), rtc::IPAddress()); | 740 rtc::IPAddress(), rtc::IPAddress()); |
777 } | 741 } |
778 | 742 |
779 // Test that when adapter enumeration is disabled, with | 743 // Test that when adapter enumeration is disabled, with |
780 // PORTALLOCATOR_DISABLE_LOCALHOST_CANDIDATE specified, for endpoints behind a | 744 // PORTALLOCATOR_DISABLE_LOCALHOST_CANDIDATE specified, for endpoints behind a |
781 // NAT, there is only one STUN candidate. | 745 // NAT, there is only one STUN candidate. |
782 TEST_F(BasicPortAllocatorTest, | 746 TEST_F(PortAllocatorTest, |
783 TestDisableAdapterEnumerationWithNatLocalhostCandidateDisabled) { | 747 TestDisableAdapterEnumerationWithNatLocalhostCandidateDisabled) { |
784 ResetWithStunServerAndNat(kStunAddr); | 748 ResetWithStunServerAndNat(kStunAddr); |
785 EXPECT_TRUE(CreateSession(cricket::ICE_CANDIDATE_COMPONENT_RTP)); | 749 EXPECT_TRUE(CreateSession(cricket::ICE_CANDIDATE_COMPONENT_RTP)); |
786 session_->set_flags(cricket::PORTALLOCATOR_DISABLE_DEFAULT_LOCAL_CANDIDATE); | 750 session_->set_flags(cricket::PORTALLOCATOR_DISABLE_DEFAULT_LOCAL_CANDIDATE); |
787 // Expect to see 2 ports: STUN and TCP ports, and single STUN candidate. | 751 // Expect to see 2 ports: STUN and TCP ports, and single STUN candidate. |
788 CheckDisableAdapterEnumeration(2U, rtc::IPAddress(), kNatUdpAddr.ipaddr(), | 752 CheckDisableAdapterEnumeration(2U, rtc::IPAddress(), kNatUdpAddr.ipaddr(), |
789 rtc::IPAddress(), rtc::IPAddress()); | 753 rtc::IPAddress(), rtc::IPAddress()); |
790 } | 754 } |
791 | 755 |
792 // Test that we disable relay over UDP, and only TCP is used when connecting to | 756 // Test that we disable relay over UDP, and only TCP is used when connecting to |
793 // the relay server. | 757 // the relay server. |
794 TEST_F(BasicPortAllocatorTest, TestDisableUdpTurn) { | 758 TEST_F(PortAllocatorTest, TestDisableUdpTurn) { |
795 turn_server_.AddInternalSocket(kTurnTcpIntAddr, cricket::PROTO_TCP); | 759 turn_server_.AddInternalSocket(kTurnTcpIntAddr, cricket::PROTO_TCP); |
796 AddInterface(kClientAddr); | 760 AddInterface(kClientAddr); |
797 ResetWithStunServerAndNat(kStunAddr); | 761 ResetWithStunServerAndNat(kStunAddr); |
798 AddTurnServers(kTurnUdpIntAddr, kTurnTcpIntAddr); | 762 AddTurnServers(kTurnUdpIntAddr, kTurnTcpIntAddr); |
799 EXPECT_TRUE(CreateSession(cricket::ICE_CANDIDATE_COMPONENT_RTP)); | 763 EXPECT_TRUE(CreateSession(cricket::ICE_CANDIDATE_COMPONENT_RTP)); |
800 session_->set_flags(cricket::PORTALLOCATOR_DISABLE_UDP_RELAY | | 764 session_->set_flags(cricket::PORTALLOCATOR_DISABLE_UDP_RELAY | |
801 cricket::PORTALLOCATOR_DISABLE_UDP | | 765 cricket::PORTALLOCATOR_DISABLE_UDP | |
802 cricket::PORTALLOCATOR_DISABLE_STUN | | 766 cricket::PORTALLOCATOR_DISABLE_STUN | |
803 cricket::PORTALLOCATOR_ENABLE_SHARED_SOCKET); | 767 cricket::PORTALLOCATOR_ENABLE_SHARED_SOCKET); |
804 | 768 |
(...skipping 13 matching lines...) Expand all Loading... |
818 cricket::ICE_CANDIDATE_COMPONENT_RTP, "local", "tcp", | 782 cricket::ICE_CANDIDATE_COMPONENT_RTP, "local", "tcp", |
819 kClientAddr); | 783 kClientAddr); |
820 } | 784 } |
821 | 785 |
822 // Disable for asan, see | 786 // Disable for asan, see |
823 // https://code.google.com/p/webrtc/issues/detail?id=4743 for details. | 787 // https://code.google.com/p/webrtc/issues/detail?id=4743 for details. |
824 #if !defined(ADDRESS_SANITIZER) | 788 #if !defined(ADDRESS_SANITIZER) |
825 | 789 |
826 // Test that we can get OnCandidatesAllocationDone callback when all the ports | 790 // Test that we can get OnCandidatesAllocationDone callback when all the ports |
827 // are disabled. | 791 // are disabled. |
828 TEST_F(BasicPortAllocatorTest, TestDisableAllPorts) { | 792 TEST_F(PortAllocatorTest, TestDisableAllPorts) { |
829 AddInterface(kClientAddr); | 793 AddInterface(kClientAddr); |
830 EXPECT_TRUE(CreateSession(cricket::ICE_CANDIDATE_COMPONENT_RTP)); | 794 EXPECT_TRUE(CreateSession(cricket::ICE_CANDIDATE_COMPONENT_RTP)); |
831 session_->set_flags(cricket::PORTALLOCATOR_DISABLE_UDP | | 795 session_->set_flags(cricket::PORTALLOCATOR_DISABLE_UDP | |
832 cricket::PORTALLOCATOR_DISABLE_STUN | | 796 cricket::PORTALLOCATOR_DISABLE_STUN | |
833 cricket::PORTALLOCATOR_DISABLE_RELAY | | 797 cricket::PORTALLOCATOR_DISABLE_RELAY | |
834 cricket::PORTALLOCATOR_DISABLE_TCP); | 798 cricket::PORTALLOCATOR_DISABLE_TCP); |
835 session_->StartGettingPorts(); | 799 session_->StartGettingPorts(); |
836 rtc::Thread::Current()->ProcessMessages(100); | 800 rtc::Thread::Current()->ProcessMessages(100); |
837 EXPECT_EQ(0U, candidates_.size()); | 801 EXPECT_EQ(0U, candidates_.size()); |
838 EXPECT_TRUE(candidate_allocation_done_); | 802 EXPECT_TRUE(candidate_allocation_done_); |
839 } | 803 } |
840 | 804 |
841 // Test that we don't crash or malfunction if we can't create UDP sockets. | 805 // Test that we don't crash or malfunction if we can't create UDP sockets. |
842 TEST_F(BasicPortAllocatorTest, TestGetAllPortsNoUdpSockets) { | 806 TEST_F(PortAllocatorTest, TestGetAllPortsNoUdpSockets) { |
843 AddInterface(kClientAddr); | 807 AddInterface(kClientAddr); |
844 fss_->set_udp_sockets_enabled(false); | 808 fss_->set_udp_sockets_enabled(false); |
845 EXPECT_TRUE(CreateSession(1)); | 809 EXPECT_TRUE(CreateSession(1)); |
846 session_->StartGettingPorts(); | 810 session_->StartGettingPorts(); |
847 ASSERT_EQ_WAIT(5U, candidates_.size(), kDefaultAllocationTimeout); | 811 ASSERT_EQ_WAIT(5U, candidates_.size(), kDefaultAllocationTimeout); |
848 EXPECT_EQ(2U, ports_.size()); | 812 EXPECT_EQ(2U, ports_.size()); |
849 EXPECT_PRED5(CheckCandidate, candidates_[0], | 813 EXPECT_PRED5(CheckCandidate, candidates_[0], |
850 cricket::ICE_CANDIDATE_COMPONENT_RTP, "relay", "udp", | 814 cricket::ICE_CANDIDATE_COMPONENT_RTP, "relay", "udp", kRelayUdpIntAddr); |
851 kRelayUdpIntAddr); | |
852 EXPECT_PRED5(CheckCandidate, candidates_[1], | 815 EXPECT_PRED5(CheckCandidate, candidates_[1], |
853 cricket::ICE_CANDIDATE_COMPONENT_RTP, "relay", "udp", | 816 cricket::ICE_CANDIDATE_COMPONENT_RTP, "relay", "udp", kRelayUdpExtAddr); |
854 kRelayUdpExtAddr); | |
855 EXPECT_PRED5(CheckCandidate, candidates_[2], | 817 EXPECT_PRED5(CheckCandidate, candidates_[2], |
856 cricket::ICE_CANDIDATE_COMPONENT_RTP, "relay", "tcp", | 818 cricket::ICE_CANDIDATE_COMPONENT_RTP, "relay", "tcp", kRelayTcpIntAddr); |
857 kRelayTcpIntAddr); | |
858 EXPECT_PRED5(CheckCandidate, candidates_[3], | 819 EXPECT_PRED5(CheckCandidate, candidates_[3], |
859 cricket::ICE_CANDIDATE_COMPONENT_RTP, "local", "tcp", | 820 cricket::ICE_CANDIDATE_COMPONENT_RTP, "local", "tcp", kClientAddr); |
860 kClientAddr); | |
861 EXPECT_PRED5(CheckCandidate, candidates_[4], | 821 EXPECT_PRED5(CheckCandidate, candidates_[4], |
862 cricket::ICE_CANDIDATE_COMPONENT_RTP, "relay", "ssltcp", | 822 cricket::ICE_CANDIDATE_COMPONENT_RTP, |
863 kRelaySslTcpIntAddr); | 823 "relay", "ssltcp", kRelaySslTcpIntAddr); |
864 EXPECT_TRUE(candidate_allocation_done_); | 824 EXPECT_TRUE(candidate_allocation_done_); |
865 } | 825 } |
866 | 826 |
867 #endif // if !defined(ADDRESS_SANITIZER) | 827 #endif // if !defined(ADDRESS_SANITIZER) |
868 | 828 |
869 // Test that we don't crash or malfunction if we can't create UDP sockets or | 829 // Test that we don't crash or malfunction if we can't create UDP sockets or |
870 // listen on TCP sockets. We still give out a local TCP address, since | 830 // listen on TCP sockets. We still give out a local TCP address, since |
871 // apparently this is needed for the remote side to accept our connection. | 831 // apparently this is needed for the remote side to accept our connection. |
872 TEST_F(BasicPortAllocatorTest, TestGetAllPortsNoUdpSocketsNoTcpListen) { | 832 TEST_F(PortAllocatorTest, TestGetAllPortsNoUdpSocketsNoTcpListen) { |
873 AddInterface(kClientAddr); | 833 AddInterface(kClientAddr); |
874 fss_->set_udp_sockets_enabled(false); | 834 fss_->set_udp_sockets_enabled(false); |
875 fss_->set_tcp_listen_enabled(false); | 835 fss_->set_tcp_listen_enabled(false); |
876 EXPECT_TRUE(CreateSession(1)); | 836 EXPECT_TRUE(CreateSession(1)); |
877 session_->StartGettingPorts(); | 837 session_->StartGettingPorts(); |
878 ASSERT_EQ_WAIT(5U, candidates_.size(), kDefaultAllocationTimeout); | 838 ASSERT_EQ_WAIT(5U, candidates_.size(), kDefaultAllocationTimeout); |
879 EXPECT_EQ(2U, ports_.size()); | 839 EXPECT_EQ(2U, ports_.size()); |
880 EXPECT_PRED5(CheckCandidate, candidates_[0], 1, "relay", "udp", | 840 EXPECT_PRED5(CheckCandidate, candidates_[0], |
881 kRelayUdpIntAddr); | 841 1, "relay", "udp", kRelayUdpIntAddr); |
882 EXPECT_PRED5(CheckCandidate, candidates_[1], 1, "relay", "udp", | 842 EXPECT_PRED5(CheckCandidate, candidates_[1], |
883 kRelayUdpExtAddr); | 843 1, "relay", "udp", kRelayUdpExtAddr); |
884 EXPECT_PRED5(CheckCandidate, candidates_[2], 1, "relay", "tcp", | 844 EXPECT_PRED5(CheckCandidate, candidates_[2], |
885 kRelayTcpIntAddr); | 845 1, "relay", "tcp", kRelayTcpIntAddr); |
886 EXPECT_PRED5(CheckCandidate, candidates_[3], 1, "local", "tcp", kClientAddr); | 846 EXPECT_PRED5(CheckCandidate, candidates_[3], |
887 EXPECT_PRED5(CheckCandidate, candidates_[4], 1, "relay", "ssltcp", | 847 1, "local", "tcp", kClientAddr); |
888 kRelaySslTcpIntAddr); | 848 EXPECT_PRED5(CheckCandidate, candidates_[4], |
| 849 1, "relay", "ssltcp", kRelaySslTcpIntAddr); |
889 EXPECT_TRUE(candidate_allocation_done_); | 850 EXPECT_TRUE(candidate_allocation_done_); |
890 } | 851 } |
891 | 852 |
892 // Test that we don't crash or malfunction if we can't create any sockets. | 853 // Test that we don't crash or malfunction if we can't create any sockets. |
893 // TODO(deadbeef): Find a way to exit early here. | 854 // TODO: Find a way to exit early here. |
894 TEST_F(BasicPortAllocatorTest, TestGetAllPortsNoSockets) { | 855 TEST_F(PortAllocatorTest, TestGetAllPortsNoSockets) { |
895 AddInterface(kClientAddr); | 856 AddInterface(kClientAddr); |
896 fss_->set_tcp_sockets_enabled(false); | 857 fss_->set_tcp_sockets_enabled(false); |
897 fss_->set_udp_sockets_enabled(false); | 858 fss_->set_udp_sockets_enabled(false); |
898 EXPECT_TRUE(CreateSession(cricket::ICE_CANDIDATE_COMPONENT_RTP)); | 859 EXPECT_TRUE(CreateSession(cricket::ICE_CANDIDATE_COMPONENT_RTP)); |
899 session_->StartGettingPorts(); | 860 session_->StartGettingPorts(); |
900 WAIT(candidates_.size() > 0, 2000); | 861 WAIT(candidates_.size() > 0, 2000); |
901 // TODO(deadbeef): Check candidate_allocation_done signal. | 862 // TODO - Check candidate_allocation_done signal. |
902 // In case of Relay, ports creation will succeed but sockets will fail. | 863 // In case of Relay, ports creation will succeed but sockets will fail. |
903 // There is no error reporting from RelayEntry to handle this failure. | 864 // There is no error reporting from RelayEntry to handle this failure. |
904 } | 865 } |
905 | 866 |
906 // Testing STUN timeout. | 867 // Testing STUN timeout. |
907 TEST_F(BasicPortAllocatorTest, TestGetAllPortsNoUdpAllowed) { | 868 TEST_F(PortAllocatorTest, TestGetAllPortsNoUdpAllowed) { |
908 fss_->AddRule(false, rtc::FP_UDP, rtc::FD_ANY, kClientAddr); | 869 fss_->AddRule(false, rtc::FP_UDP, rtc::FD_ANY, kClientAddr); |
909 AddInterface(kClientAddr); | 870 AddInterface(kClientAddr); |
910 EXPECT_TRUE(CreateSession(cricket::ICE_CANDIDATE_COMPONENT_RTP)); | 871 EXPECT_TRUE(CreateSession(cricket::ICE_CANDIDATE_COMPONENT_RTP)); |
911 session_->StartGettingPorts(); | 872 session_->StartGettingPorts(); |
912 EXPECT_EQ_WAIT(2U, candidates_.size(), kDefaultAllocationTimeout); | 873 EXPECT_EQ_WAIT(2U, candidates_.size(), kDefaultAllocationTimeout); |
913 EXPECT_EQ(2U, ports_.size()); | 874 EXPECT_EQ(2U, ports_.size()); |
914 EXPECT_PRED5(CheckCandidate, candidates_[0], | 875 EXPECT_PRED5(CheckCandidate, candidates_[0], |
915 cricket::ICE_CANDIDATE_COMPONENT_RTP, "local", "udp", | 876 cricket::ICE_CANDIDATE_COMPONENT_RTP, "local", "udp", kClientAddr); |
916 kClientAddr); | |
917 EXPECT_PRED5(CheckCandidate, candidates_[1], | 877 EXPECT_PRED5(CheckCandidate, candidates_[1], |
918 cricket::ICE_CANDIDATE_COMPONENT_RTP, "local", "tcp", | 878 cricket::ICE_CANDIDATE_COMPONENT_RTP, "local", "tcp", kClientAddr); |
919 kClientAddr); | |
920 // RelayPort connection timeout is 3sec. TCP connection with RelayServer | 879 // RelayPort connection timeout is 3sec. TCP connection with RelayServer |
921 // will be tried after 3 seconds. | 880 // will be tried after 3 seconds. |
922 EXPECT_EQ_WAIT(6U, candidates_.size(), 4000); | 881 EXPECT_EQ_WAIT(6U, candidates_.size(), 4000); |
923 EXPECT_EQ(3U, ports_.size()); | 882 EXPECT_EQ(3U, ports_.size()); |
924 EXPECT_PRED5(CheckCandidate, candidates_[2], | 883 EXPECT_PRED5(CheckCandidate, candidates_[2], |
925 cricket::ICE_CANDIDATE_COMPONENT_RTP, "relay", "udp", | 884 cricket::ICE_CANDIDATE_COMPONENT_RTP, "relay", "udp", kRelayUdpIntAddr); |
926 kRelayUdpIntAddr); | |
927 EXPECT_PRED5(CheckCandidate, candidates_[3], | 885 EXPECT_PRED5(CheckCandidate, candidates_[3], |
928 cricket::ICE_CANDIDATE_COMPONENT_RTP, "relay", "tcp", | 886 cricket::ICE_CANDIDATE_COMPONENT_RTP, "relay", "tcp", kRelayTcpIntAddr); |
929 kRelayTcpIntAddr); | |
930 EXPECT_PRED5(CheckCandidate, candidates_[4], | 887 EXPECT_PRED5(CheckCandidate, candidates_[4], |
931 cricket::ICE_CANDIDATE_COMPONENT_RTP, "relay", "ssltcp", | 888 cricket::ICE_CANDIDATE_COMPONENT_RTP, "relay", "ssltcp", |
932 kRelaySslTcpIntAddr); | 889 kRelaySslTcpIntAddr); |
933 EXPECT_PRED5(CheckCandidate, candidates_[5], | 890 EXPECT_PRED5(CheckCandidate, candidates_[5], |
934 cricket::ICE_CANDIDATE_COMPONENT_RTP, "relay", "udp", | 891 cricket::ICE_CANDIDATE_COMPONENT_RTP, "relay", "udp", kRelayUdpExtAddr); |
935 kRelayUdpExtAddr); | |
936 // Stun Timeout is 9sec. | 892 // Stun Timeout is 9sec. |
937 EXPECT_TRUE_WAIT(candidate_allocation_done_, 9000); | 893 EXPECT_TRUE_WAIT(candidate_allocation_done_, 9000); |
938 } | 894 } |
939 | 895 |
940 TEST_F(BasicPortAllocatorTest, TestCandidatePriorityOfMultipleInterfaces) { | 896 TEST_F(PortAllocatorTest, TestCandidatePriorityOfMultipleInterfaces) { |
941 AddInterface(kClientAddr); | 897 AddInterface(kClientAddr); |
942 AddInterface(kClientAddr2); | 898 AddInterface(kClientAddr2); |
943 // Allocating only host UDP ports. This is done purely for testing | 899 // Allocating only host UDP ports. This is done purely for testing |
944 // convenience. | 900 // convenience. |
945 allocator().set_flags(cricket::PORTALLOCATOR_DISABLE_TCP | | 901 allocator().set_flags(cricket::PORTALLOCATOR_DISABLE_TCP | |
946 cricket::PORTALLOCATOR_DISABLE_STUN | | 902 cricket::PORTALLOCATOR_DISABLE_STUN | |
947 cricket::PORTALLOCATOR_DISABLE_RELAY); | 903 cricket::PORTALLOCATOR_DISABLE_RELAY); |
948 EXPECT_TRUE(CreateSession(cricket::ICE_CANDIDATE_COMPONENT_RTP)); | 904 EXPECT_TRUE(CreateSession(cricket::ICE_CANDIDATE_COMPONENT_RTP)); |
949 session_->StartGettingPorts(); | 905 session_->StartGettingPorts(); |
950 EXPECT_TRUE_WAIT(candidate_allocation_done_, kDefaultAllocationTimeout); | 906 EXPECT_TRUE_WAIT(candidate_allocation_done_, kDefaultAllocationTimeout); |
951 ASSERT_EQ(2U, candidates_.size()); | 907 ASSERT_EQ(2U, candidates_.size()); |
952 EXPECT_EQ(2U, ports_.size()); | 908 EXPECT_EQ(2U, ports_.size()); |
953 // Candidates priorities should be different. | 909 // Candidates priorities should be different. |
954 EXPECT_NE(candidates_[0].priority(), candidates_[1].priority()); | 910 EXPECT_NE(candidates_[0].priority(), candidates_[1].priority()); |
955 } | 911 } |
956 | 912 |
957 // Test to verify ICE restart process. | 913 // Test to verify ICE restart process. |
958 TEST_F(BasicPortAllocatorTest, TestGetAllPortsRestarts) { | 914 TEST_F(PortAllocatorTest, TestGetAllPortsRestarts) { |
959 AddInterface(kClientAddr); | 915 AddInterface(kClientAddr); |
960 EXPECT_TRUE(CreateSession(cricket::ICE_CANDIDATE_COMPONENT_RTP)); | 916 EXPECT_TRUE(CreateSession(cricket::ICE_CANDIDATE_COMPONENT_RTP)); |
961 session_->StartGettingPorts(); | 917 session_->StartGettingPorts(); |
962 EXPECT_EQ_WAIT(7U, candidates_.size(), kDefaultAllocationTimeout); | 918 EXPECT_EQ_WAIT(7U, candidates_.size(), kDefaultAllocationTimeout); |
963 EXPECT_EQ(4U, ports_.size()); | 919 EXPECT_EQ(4U, ports_.size()); |
964 EXPECT_TRUE(candidate_allocation_done_); | 920 EXPECT_TRUE(candidate_allocation_done_); |
965 // TODO(deadbeef): Extend this to verify ICE restart. | 921 // TODO - Extend this to verify ICE restart. |
966 } | 922 } |
967 | 923 |
968 // Test ICE candidate filter mechanism with options Relay/Host/Reflexive. | 924 // Test ICE candidate filter mechanism with options Relay/Host/Reflexive. |
969 // This test also verifies that when the allocator is only allowed to use | 925 // This test also verifies that when the allocator is only allowed to use |
970 // relay (i.e. IceTransportsType is relay), the raddr is an empty | 926 // relay (i.e. IceTransportsType is relay), the raddr is an empty |
971 // address with the correct family. This is to prevent any local | 927 // address with the correct family. This is to prevent any local |
972 // reflective address leakage in the sdp line. | 928 // reflective address leakage in the sdp line. |
973 TEST_F(BasicPortAllocatorTest, TestCandidateFilterWithRelayOnly) { | 929 TEST_F(PortAllocatorTest, TestCandidateFilterWithRelayOnly) { |
974 AddInterface(kClientAddr); | 930 AddInterface(kClientAddr); |
975 // GTURN is not configured here. | 931 // GTURN is not configured here. |
976 ResetWithTurnServersNoNat(kTurnUdpIntAddr, rtc::SocketAddress()); | 932 ResetWithTurnServersNoNat(kTurnUdpIntAddr, rtc::SocketAddress()); |
977 allocator().set_candidate_filter(cricket::CF_RELAY); | 933 allocator().set_candidate_filter(cricket::CF_RELAY); |
978 EXPECT_TRUE(CreateSession(cricket::ICE_CANDIDATE_COMPONENT_RTP)); | 934 EXPECT_TRUE(CreateSession(cricket::ICE_CANDIDATE_COMPONENT_RTP)); |
979 session_->StartGettingPorts(); | 935 session_->StartGettingPorts(); |
980 EXPECT_TRUE_WAIT(candidate_allocation_done_, kDefaultAllocationTimeout); | 936 EXPECT_TRUE_WAIT(candidate_allocation_done_, kDefaultAllocationTimeout); |
981 EXPECT_PRED5(CheckCandidate, candidates_[0], | 937 EXPECT_PRED5(CheckCandidate, |
982 cricket::ICE_CANDIDATE_COMPONENT_RTP, "relay", "udp", | 938 candidates_[0], |
| 939 cricket::ICE_CANDIDATE_COMPONENT_RTP, |
| 940 "relay", |
| 941 "udp", |
983 rtc::SocketAddress(kTurnUdpExtAddr.ipaddr(), 0)); | 942 rtc::SocketAddress(kTurnUdpExtAddr.ipaddr(), 0)); |
984 | 943 |
985 EXPECT_EQ(1U, candidates_.size()); | 944 EXPECT_EQ(1U, candidates_.size()); |
986 EXPECT_EQ(1U, ports_.size()); // Only Relay port will be in ready state. | 945 EXPECT_EQ(1U, ports_.size()); // Only Relay port will be in ready state. |
987 for (size_t i = 0; i < candidates_.size(); ++i) { | 946 for (size_t i = 0; i < candidates_.size(); ++i) { |
988 EXPECT_EQ(std::string(cricket::RELAY_PORT_TYPE), candidates_[i].type()); | 947 EXPECT_EQ(std::string(cricket::RELAY_PORT_TYPE), candidates_[i].type()); |
989 EXPECT_EQ( | 948 EXPECT_EQ( |
990 candidates_[0].related_address(), | 949 candidates_[0].related_address(), |
991 rtc::EmptySocketAddressWithFamily(candidates_[0].address().family())); | 950 rtc::EmptySocketAddressWithFamily(candidates_[0].address().family())); |
992 } | 951 } |
993 } | 952 } |
994 | 953 |
995 TEST_F(BasicPortAllocatorTest, TestCandidateFilterWithHostOnly) { | 954 TEST_F(PortAllocatorTest, TestCandidateFilterWithHostOnly) { |
996 AddInterface(kClientAddr); | 955 AddInterface(kClientAddr); |
997 allocator().set_flags(cricket::PORTALLOCATOR_ENABLE_SHARED_SOCKET); | 956 allocator().set_flags(cricket::PORTALLOCATOR_ENABLE_SHARED_SOCKET); |
998 allocator().set_candidate_filter(cricket::CF_HOST); | 957 allocator().set_candidate_filter(cricket::CF_HOST); |
999 EXPECT_TRUE(CreateSession(cricket::ICE_CANDIDATE_COMPONENT_RTP)); | 958 EXPECT_TRUE(CreateSession(cricket::ICE_CANDIDATE_COMPONENT_RTP)); |
1000 session_->StartGettingPorts(); | 959 session_->StartGettingPorts(); |
1001 EXPECT_TRUE_WAIT(candidate_allocation_done_, kDefaultAllocationTimeout); | 960 EXPECT_TRUE_WAIT(candidate_allocation_done_, kDefaultAllocationTimeout); |
1002 EXPECT_EQ(2U, candidates_.size()); // Host UDP/TCP candidates only. | 961 EXPECT_EQ(2U, candidates_.size()); // Host UDP/TCP candidates only. |
1003 EXPECT_EQ(2U, ports_.size()); // UDP/TCP ports only. | 962 EXPECT_EQ(2U, ports_.size()); // UDP/TCP ports only. |
1004 for (size_t i = 0; i < candidates_.size(); ++i) { | 963 for (size_t i = 0; i < candidates_.size(); ++i) { |
1005 EXPECT_EQ(std::string(cricket::LOCAL_PORT_TYPE), candidates_[i].type()); | 964 EXPECT_EQ(std::string(cricket::LOCAL_PORT_TYPE), candidates_[i].type()); |
1006 } | 965 } |
1007 } | 966 } |
1008 | 967 |
1009 // Host is behind the NAT. | 968 // Host is behind the NAT. |
1010 TEST_F(BasicPortAllocatorTest, TestCandidateFilterWithReflexiveOnly) { | 969 TEST_F(PortAllocatorTest, TestCandidateFilterWithReflexiveOnly) { |
1011 AddInterface(kPrivateAddr); | 970 AddInterface(kPrivateAddr); |
1012 ResetWithStunServerAndNat(kStunAddr); | 971 ResetWithStunServerAndNat(kStunAddr); |
1013 | 972 |
1014 allocator().set_flags(cricket::PORTALLOCATOR_ENABLE_SHARED_SOCKET); | 973 allocator().set_flags(cricket::PORTALLOCATOR_ENABLE_SHARED_SOCKET); |
1015 allocator().set_candidate_filter(cricket::CF_REFLEXIVE); | 974 allocator().set_candidate_filter(cricket::CF_REFLEXIVE); |
1016 EXPECT_TRUE(CreateSession(cricket::ICE_CANDIDATE_COMPONENT_RTP)); | 975 EXPECT_TRUE(CreateSession(cricket::ICE_CANDIDATE_COMPONENT_RTP)); |
1017 session_->StartGettingPorts(); | 976 session_->StartGettingPorts(); |
1018 EXPECT_TRUE_WAIT(candidate_allocation_done_, kDefaultAllocationTimeout); | 977 EXPECT_TRUE_WAIT(candidate_allocation_done_, kDefaultAllocationTimeout); |
1019 // Host is behind NAT, no private address will be exposed. Hence only UDP | 978 // Host is behind NAT, no private address will be exposed. Hence only UDP |
1020 // port with STUN candidate will be sent outside. | 979 // port with STUN candidate will be sent outside. |
1021 EXPECT_EQ(1U, candidates_.size()); // Only STUN candidate. | 980 EXPECT_EQ(1U, candidates_.size()); // Only STUN candidate. |
1022 EXPECT_EQ(1U, ports_.size()); // Only UDP port will be in ready state. | 981 EXPECT_EQ(1U, ports_.size()); // Only UDP port will be in ready state. |
1023 for (size_t i = 0; i < candidates_.size(); ++i) { | 982 for (size_t i = 0; i < candidates_.size(); ++i) { |
1024 EXPECT_EQ(std::string(cricket::STUN_PORT_TYPE), candidates_[i].type()); | 983 EXPECT_EQ(std::string(cricket::STUN_PORT_TYPE), candidates_[i].type()); |
1025 EXPECT_EQ( | 984 EXPECT_EQ( |
1026 candidates_[0].related_address(), | 985 candidates_[0].related_address(), |
1027 rtc::EmptySocketAddressWithFamily(candidates_[0].address().family())); | 986 rtc::EmptySocketAddressWithFamily(candidates_[0].address().family())); |
1028 } | 987 } |
1029 } | 988 } |
1030 | 989 |
1031 // Host is not behind the NAT. | 990 // Host is not behind the NAT. |
1032 TEST_F(BasicPortAllocatorTest, TestCandidateFilterWithReflexiveOnlyAndNoNAT) { | 991 TEST_F(PortAllocatorTest, TestCandidateFilterWithReflexiveOnlyAndNoNAT) { |
1033 AddInterface(kClientAddr); | 992 AddInterface(kClientAddr); |
1034 allocator().set_flags(cricket::PORTALLOCATOR_ENABLE_SHARED_SOCKET); | 993 allocator().set_flags(cricket::PORTALLOCATOR_ENABLE_SHARED_SOCKET); |
1035 allocator().set_candidate_filter(cricket::CF_REFLEXIVE); | 994 allocator().set_candidate_filter(cricket::CF_REFLEXIVE); |
1036 EXPECT_TRUE(CreateSession(cricket::ICE_CANDIDATE_COMPONENT_RTP)); | 995 EXPECT_TRUE(CreateSession(cricket::ICE_CANDIDATE_COMPONENT_RTP)); |
1037 session_->StartGettingPorts(); | 996 session_->StartGettingPorts(); |
1038 EXPECT_TRUE_WAIT(candidate_allocation_done_, kDefaultAllocationTimeout); | 997 EXPECT_TRUE_WAIT(candidate_allocation_done_, kDefaultAllocationTimeout); |
1039 // Host has a public address, both UDP and TCP candidates will be exposed. | 998 // Host has a public address, both UDP and TCP candidates will be exposed. |
1040 EXPECT_EQ(2U, candidates_.size()); // Local UDP + TCP candidate. | 999 EXPECT_EQ(2U, candidates_.size()); // Local UDP + TCP candidate. |
1041 EXPECT_EQ(2U, ports_.size()); // UDP and TCP ports will be in ready state. | 1000 EXPECT_EQ(2U, ports_.size()); // UDP and TCP ports will be in ready state. |
1042 for (size_t i = 0; i < candidates_.size(); ++i) { | 1001 for (size_t i = 0; i < candidates_.size(); ++i) { |
1043 EXPECT_EQ(std::string(cricket::LOCAL_PORT_TYPE), candidates_[i].type()); | 1002 EXPECT_EQ(std::string(cricket::LOCAL_PORT_TYPE), candidates_[i].type()); |
1044 } | 1003 } |
1045 } | 1004 } |
1046 | 1005 |
1047 // Test that we get the same ufrag and pwd for all candidates. | 1006 // Test that we get the same ufrag and pwd for all candidates. |
1048 TEST_F(BasicPortAllocatorTest, TestEnableSharedUfrag) { | 1007 TEST_F(PortAllocatorTest, TestEnableSharedUfrag) { |
1049 AddInterface(kClientAddr); | 1008 AddInterface(kClientAddr); |
1050 EXPECT_TRUE(CreateSession(cricket::ICE_CANDIDATE_COMPONENT_RTP)); | 1009 EXPECT_TRUE(CreateSession(cricket::ICE_CANDIDATE_COMPONENT_RTP)); |
1051 session_->StartGettingPorts(); | 1010 session_->StartGettingPorts(); |
1052 ASSERT_EQ_WAIT(7U, candidates_.size(), kDefaultAllocationTimeout); | 1011 ASSERT_EQ_WAIT(7U, candidates_.size(), kDefaultAllocationTimeout); |
1053 EXPECT_PRED5(CheckCandidate, candidates_[0], | 1012 EXPECT_PRED5(CheckCandidate, candidates_[0], |
1054 cricket::ICE_CANDIDATE_COMPONENT_RTP, "local", "udp", | 1013 cricket::ICE_CANDIDATE_COMPONENT_RTP, "local", "udp", kClientAddr); |
1055 kClientAddr); | |
1056 EXPECT_PRED5(CheckCandidate, candidates_[1], | 1014 EXPECT_PRED5(CheckCandidate, candidates_[1], |
1057 cricket::ICE_CANDIDATE_COMPONENT_RTP, "stun", "udp", | 1015 cricket::ICE_CANDIDATE_COMPONENT_RTP, "stun", "udp", kClientAddr); |
1058 kClientAddr); | |
1059 EXPECT_PRED5(CheckCandidate, candidates_[5], | 1016 EXPECT_PRED5(CheckCandidate, candidates_[5], |
1060 cricket::ICE_CANDIDATE_COMPONENT_RTP, "local", "tcp", | 1017 cricket::ICE_CANDIDATE_COMPONENT_RTP, "local", "tcp", kClientAddr); |
1061 kClientAddr); | |
1062 EXPECT_EQ(4U, ports_.size()); | 1018 EXPECT_EQ(4U, ports_.size()); |
1063 EXPECT_EQ(kIceUfrag0, candidates_[0].username()); | 1019 EXPECT_EQ(kIceUfrag0, candidates_[0].username()); |
1064 EXPECT_EQ(kIceUfrag0, candidates_[1].username()); | 1020 EXPECT_EQ(kIceUfrag0, candidates_[1].username()); |
1065 EXPECT_EQ(kIceUfrag0, candidates_[2].username()); | 1021 EXPECT_EQ(kIceUfrag0, candidates_[2].username()); |
1066 EXPECT_EQ(kIcePwd0, candidates_[0].password()); | 1022 EXPECT_EQ(kIcePwd0, candidates_[0].password()); |
1067 EXPECT_EQ(kIcePwd0, candidates_[1].password()); | 1023 EXPECT_EQ(kIcePwd0, candidates_[1].password()); |
1068 EXPECT_TRUE(candidate_allocation_done_); | 1024 EXPECT_TRUE(candidate_allocation_done_); |
1069 } | 1025 } |
1070 | 1026 |
1071 // Test that when PORTALLOCATOR_ENABLE_SHARED_SOCKET is enabled only one port | 1027 // Test that when PORTALLOCATOR_ENABLE_SHARED_SOCKET is enabled only one port |
1072 // is allocated for udp and stun. Also verify there is only one candidate | 1028 // is allocated for udp and stun. Also verify there is only one candidate |
1073 // (local) if stun candidate is same as local candidate, which will be the case | 1029 // (local) if stun candidate is same as local candidate, which will be the case |
1074 // in a public network like the below test. | 1030 // in a public network like the below test. |
1075 TEST_F(BasicPortAllocatorTest, TestSharedSocketWithoutNat) { | 1031 TEST_F(PortAllocatorTest, TestSharedSocketWithoutNat) { |
1076 AddInterface(kClientAddr); | 1032 AddInterface(kClientAddr); |
1077 allocator_->set_flags(allocator().flags() | | 1033 allocator_->set_flags(allocator().flags() | |
1078 cricket::PORTALLOCATOR_ENABLE_SHARED_SOCKET); | 1034 cricket::PORTALLOCATOR_ENABLE_SHARED_SOCKET); |
1079 EXPECT_TRUE(CreateSession(cricket::ICE_CANDIDATE_COMPONENT_RTP)); | 1035 EXPECT_TRUE(CreateSession(cricket::ICE_CANDIDATE_COMPONENT_RTP)); |
1080 session_->StartGettingPorts(); | 1036 session_->StartGettingPorts(); |
1081 ASSERT_EQ_WAIT(6U, candidates_.size(), kDefaultAllocationTimeout); | 1037 ASSERT_EQ_WAIT(6U, candidates_.size(), kDefaultAllocationTimeout); |
1082 EXPECT_EQ(3U, ports_.size()); | 1038 EXPECT_EQ(3U, ports_.size()); |
1083 EXPECT_PRED5(CheckCandidate, candidates_[0], | 1039 EXPECT_PRED5(CheckCandidate, candidates_[0], |
1084 cricket::ICE_CANDIDATE_COMPONENT_RTP, "local", "udp", | 1040 cricket::ICE_CANDIDATE_COMPONENT_RTP, "local", "udp", kClientAddr); |
1085 kClientAddr); | |
1086 EXPECT_TRUE_WAIT(candidate_allocation_done_, kDefaultAllocationTimeout); | 1041 EXPECT_TRUE_WAIT(candidate_allocation_done_, kDefaultAllocationTimeout); |
1087 } | 1042 } |
1088 | 1043 |
1089 // Test that when PORTALLOCATOR_ENABLE_SHARED_SOCKET is enabled only one port | 1044 // Test that when PORTALLOCATOR_ENABLE_SHARED_SOCKET is enabled only one port |
1090 // is allocated for udp and stun. In this test we should expect both stun and | 1045 // is allocated for udp and stun. In this test we should expect both stun and |
1091 // local candidates as client behind a nat. | 1046 // local candidates as client behind a nat. |
1092 TEST_F(BasicPortAllocatorTest, TestSharedSocketWithNat) { | 1047 TEST_F(PortAllocatorTest, TestSharedSocketWithNat) { |
1093 AddInterface(kClientAddr); | 1048 AddInterface(kClientAddr); |
1094 ResetWithStunServerAndNat(kStunAddr); | 1049 ResetWithStunServerAndNat(kStunAddr); |
1095 | 1050 |
1096 allocator_->set_flags(allocator().flags() | | 1051 allocator_->set_flags(allocator().flags() | |
1097 cricket::PORTALLOCATOR_ENABLE_SHARED_SOCKET); | 1052 cricket::PORTALLOCATOR_ENABLE_SHARED_SOCKET); |
1098 EXPECT_TRUE(CreateSession(cricket::ICE_CANDIDATE_COMPONENT_RTP)); | 1053 EXPECT_TRUE(CreateSession(cricket::ICE_CANDIDATE_COMPONENT_RTP)); |
1099 session_->StartGettingPorts(); | 1054 session_->StartGettingPorts(); |
1100 ASSERT_EQ_WAIT(3U, candidates_.size(), kDefaultAllocationTimeout); | 1055 ASSERT_EQ_WAIT(3U, candidates_.size(), kDefaultAllocationTimeout); |
1101 ASSERT_EQ(2U, ports_.size()); | 1056 ASSERT_EQ(2U, ports_.size()); |
1102 EXPECT_PRED5(CheckCandidate, candidates_[0], | 1057 EXPECT_PRED5(CheckCandidate, candidates_[0], |
1103 cricket::ICE_CANDIDATE_COMPONENT_RTP, "local", "udp", | 1058 cricket::ICE_CANDIDATE_COMPONENT_RTP, "local", "udp", kClientAddr); |
1104 kClientAddr); | |
1105 EXPECT_PRED5(CheckCandidate, candidates_[1], | 1059 EXPECT_PRED5(CheckCandidate, candidates_[1], |
1106 cricket::ICE_CANDIDATE_COMPONENT_RTP, "stun", "udp", | 1060 cricket::ICE_CANDIDATE_COMPONENT_RTP, "stun", "udp", |
1107 rtc::SocketAddress(kNatUdpAddr.ipaddr(), 0)); | 1061 rtc::SocketAddress(kNatUdpAddr.ipaddr(), 0)); |
1108 EXPECT_TRUE_WAIT(candidate_allocation_done_, kDefaultAllocationTimeout); | 1062 EXPECT_TRUE_WAIT(candidate_allocation_done_, kDefaultAllocationTimeout); |
1109 EXPECT_EQ(3U, candidates_.size()); | 1063 EXPECT_EQ(3U, candidates_.size()); |
1110 } | 1064 } |
1111 | 1065 |
1112 // Test TURN port in shared socket mode with UDP and TCP TURN server addresses. | 1066 // Test TURN port in shared socket mode with UDP and TCP TURN server addresses. |
1113 TEST_F(BasicPortAllocatorTest, TestSharedSocketWithoutNatUsingTurn) { | 1067 TEST_F(PortAllocatorTest, TestSharedSocketWithoutNatUsingTurn) { |
1114 turn_server_.AddInternalSocket(kTurnTcpIntAddr, cricket::PROTO_TCP); | 1068 turn_server_.AddInternalSocket(kTurnTcpIntAddr, cricket::PROTO_TCP); |
1115 AddInterface(kClientAddr); | 1069 AddInterface(kClientAddr); |
1116 allocator_.reset(new cricket::BasicPortAllocator(&network_manager_)); | 1070 allocator_.reset(new cricket::BasicPortAllocator(&network_manager_)); |
1117 | 1071 |
1118 AddTurnServers(kTurnUdpIntAddr, kTurnTcpIntAddr); | 1072 AddTurnServers(kTurnUdpIntAddr, kTurnTcpIntAddr); |
1119 | 1073 |
1120 allocator_->set_step_delay(cricket::kMinimumStepDelay); | 1074 allocator_->set_step_delay(cricket::kMinimumStepDelay); |
1121 allocator_->set_flags(allocator().flags() | | 1075 allocator_->set_flags(allocator().flags() | |
1122 cricket::PORTALLOCATOR_ENABLE_SHARED_SOCKET | | 1076 cricket::PORTALLOCATOR_ENABLE_SHARED_SOCKET | |
1123 cricket::PORTALLOCATOR_DISABLE_TCP); | 1077 cricket::PORTALLOCATOR_DISABLE_TCP); |
1124 | 1078 |
1125 EXPECT_TRUE(CreateSession(cricket::ICE_CANDIDATE_COMPONENT_RTP)); | 1079 EXPECT_TRUE(CreateSession(cricket::ICE_CANDIDATE_COMPONENT_RTP)); |
1126 session_->StartGettingPorts(); | 1080 session_->StartGettingPorts(); |
1127 | 1081 |
1128 ASSERT_EQ_WAIT(3U, candidates_.size(), kDefaultAllocationTimeout); | 1082 ASSERT_EQ_WAIT(3U, candidates_.size(), kDefaultAllocationTimeout); |
1129 ASSERT_EQ(3U, ports_.size()); | 1083 ASSERT_EQ(3U, ports_.size()); |
1130 EXPECT_PRED5(CheckCandidate, candidates_[0], | 1084 EXPECT_PRED5(CheckCandidate, candidates_[0], |
1131 cricket::ICE_CANDIDATE_COMPONENT_RTP, "local", "udp", | 1085 cricket::ICE_CANDIDATE_COMPONENT_RTP, "local", "udp", kClientAddr); |
1132 kClientAddr); | |
1133 EXPECT_PRED5(CheckCandidate, candidates_[1], | 1086 EXPECT_PRED5(CheckCandidate, candidates_[1], |
1134 cricket::ICE_CANDIDATE_COMPONENT_RTP, "relay", "udp", | 1087 cricket::ICE_CANDIDATE_COMPONENT_RTP, "relay", "udp", |
1135 rtc::SocketAddress(kTurnUdpExtAddr.ipaddr(), 0)); | 1088 rtc::SocketAddress(kTurnUdpExtAddr.ipaddr(), 0)); |
1136 EXPECT_PRED5(CheckCandidate, candidates_[2], | 1089 EXPECT_PRED5(CheckCandidate, candidates_[2], |
1137 cricket::ICE_CANDIDATE_COMPONENT_RTP, "relay", "udp", | 1090 cricket::ICE_CANDIDATE_COMPONENT_RTP, "relay", "udp", |
1138 rtc::SocketAddress(kTurnUdpExtAddr.ipaddr(), 0)); | 1091 rtc::SocketAddress(kTurnUdpExtAddr.ipaddr(), 0)); |
1139 EXPECT_TRUE_WAIT(candidate_allocation_done_, kDefaultAllocationTimeout); | 1092 EXPECT_TRUE_WAIT(candidate_allocation_done_, kDefaultAllocationTimeout); |
1140 EXPECT_EQ(3U, candidates_.size()); | 1093 EXPECT_EQ(3U, candidates_.size()); |
1141 } | 1094 } |
1142 | 1095 |
1143 // Testing DNS resolve for the TURN server, this will test AllocationSequence | 1096 // Testing DNS resolve for the TURN server, this will test AllocationSequence |
1144 // handling the unresolved address signal from TurnPort. | 1097 // handling the unresolved address signal from TurnPort. |
1145 TEST_F(BasicPortAllocatorTest, TestSharedSocketWithServerAddressResolve) { | 1098 TEST_F(PortAllocatorTest, TestSharedSocketWithServerAddressResolve) { |
1146 turn_server_.AddInternalSocket(rtc::SocketAddress("127.0.0.1", 3478), | 1099 turn_server_.AddInternalSocket(rtc::SocketAddress("127.0.0.1", 3478), |
1147 cricket::PROTO_UDP); | 1100 cricket::PROTO_UDP); |
1148 AddInterface(kClientAddr); | 1101 AddInterface(kClientAddr); |
1149 allocator_.reset(new cricket::BasicPortAllocator(&network_manager_)); | 1102 allocator_.reset(new cricket::BasicPortAllocator(&network_manager_)); |
1150 cricket::RelayServerConfig turn_server(cricket::RELAY_TURN); | 1103 cricket::RelayServerConfig turn_server(cricket::RELAY_TURN); |
1151 cricket::RelayCredentials credentials(kTurnUsername, kTurnPassword); | 1104 cricket::RelayCredentials credentials(kTurnUsername, kTurnPassword); |
1152 turn_server.credentials = credentials; | 1105 turn_server.credentials = credentials; |
1153 turn_server.ports.push_back(cricket::ProtocolAddress( | 1106 turn_server.ports.push_back(cricket::ProtocolAddress( |
1154 rtc::SocketAddress("localhost", 3478), cricket::PROTO_UDP, false)); | 1107 rtc::SocketAddress("localhost", 3478), cricket::PROTO_UDP, false)); |
1155 allocator_->AddTurnServer(turn_server); | 1108 allocator_->AddTurnServer(turn_server); |
1156 | 1109 |
1157 allocator_->set_step_delay(cricket::kMinimumStepDelay); | 1110 allocator_->set_step_delay(cricket::kMinimumStepDelay); |
1158 allocator_->set_flags(allocator().flags() | | 1111 allocator_->set_flags(allocator().flags() | |
1159 cricket::PORTALLOCATOR_ENABLE_SHARED_SOCKET | | 1112 cricket::PORTALLOCATOR_ENABLE_SHARED_SOCKET | |
1160 cricket::PORTALLOCATOR_DISABLE_TCP); | 1113 cricket::PORTALLOCATOR_DISABLE_TCP); |
1161 | 1114 |
1162 EXPECT_TRUE(CreateSession(cricket::ICE_CANDIDATE_COMPONENT_RTP)); | 1115 EXPECT_TRUE(CreateSession(cricket::ICE_CANDIDATE_COMPONENT_RTP)); |
1163 session_->StartGettingPorts(); | 1116 session_->StartGettingPorts(); |
1164 | 1117 |
1165 EXPECT_EQ_WAIT(2U, ports_.size(), kDefaultAllocationTimeout); | 1118 EXPECT_EQ_WAIT(2U, ports_.size(), kDefaultAllocationTimeout); |
1166 } | 1119 } |
1167 | 1120 |
1168 // Test that when PORTALLOCATOR_ENABLE_SHARED_SOCKET is enabled only one port | 1121 // Test that when PORTALLOCATOR_ENABLE_SHARED_SOCKET is enabled only one port |
1169 // is allocated for udp/stun/turn. In this test we should expect all local, | 1122 // is allocated for udp/stun/turn. In this test we should expect all local, |
1170 // stun and turn candidates. | 1123 // stun and turn candidates. |
1171 TEST_F(BasicPortAllocatorTest, TestSharedSocketWithNatUsingTurn) { | 1124 TEST_F(PortAllocatorTest, TestSharedSocketWithNatUsingTurn) { |
1172 AddInterface(kClientAddr); | 1125 AddInterface(kClientAddr); |
1173 ResetWithStunServerAndNat(kStunAddr); | 1126 ResetWithStunServerAndNat(kStunAddr); |
1174 | 1127 |
1175 AddTurnServers(kTurnUdpIntAddr, rtc::SocketAddress()); | 1128 AddTurnServers(kTurnUdpIntAddr, rtc::SocketAddress()); |
1176 | 1129 |
1177 allocator_->set_flags(allocator().flags() | | 1130 allocator_->set_flags(allocator().flags() | |
1178 cricket::PORTALLOCATOR_ENABLE_SHARED_SOCKET | | 1131 cricket::PORTALLOCATOR_ENABLE_SHARED_SOCKET | |
1179 cricket::PORTALLOCATOR_DISABLE_TCP); | 1132 cricket::PORTALLOCATOR_DISABLE_TCP); |
1180 | 1133 |
1181 EXPECT_TRUE(CreateSession(cricket::ICE_CANDIDATE_COMPONENT_RTP)); | 1134 EXPECT_TRUE(CreateSession(cricket::ICE_CANDIDATE_COMPONENT_RTP)); |
1182 session_->StartGettingPorts(); | 1135 session_->StartGettingPorts(); |
1183 | 1136 |
1184 ASSERT_EQ_WAIT(3U, candidates_.size(), kDefaultAllocationTimeout); | 1137 ASSERT_EQ_WAIT(3U, candidates_.size(), kDefaultAllocationTimeout); |
1185 ASSERT_EQ(2U, ports_.size()); | 1138 ASSERT_EQ(2U, ports_.size()); |
1186 EXPECT_PRED5(CheckCandidate, candidates_[0], | 1139 EXPECT_PRED5(CheckCandidate, candidates_[0], |
1187 cricket::ICE_CANDIDATE_COMPONENT_RTP, "local", "udp", | 1140 cricket::ICE_CANDIDATE_COMPONENT_RTP, "local", "udp", kClientAddr); |
1188 kClientAddr); | |
1189 EXPECT_PRED5(CheckCandidate, candidates_[1], | 1141 EXPECT_PRED5(CheckCandidate, candidates_[1], |
1190 cricket::ICE_CANDIDATE_COMPONENT_RTP, "stun", "udp", | 1142 cricket::ICE_CANDIDATE_COMPONENT_RTP, "stun", "udp", |
1191 rtc::SocketAddress(kNatUdpAddr.ipaddr(), 0)); | 1143 rtc::SocketAddress(kNatUdpAddr.ipaddr(), 0)); |
1192 EXPECT_PRED5(CheckCandidate, candidates_[2], | 1144 EXPECT_PRED5(CheckCandidate, candidates_[2], |
1193 cricket::ICE_CANDIDATE_COMPONENT_RTP, "relay", "udp", | 1145 cricket::ICE_CANDIDATE_COMPONENT_RTP, "relay", "udp", |
1194 rtc::SocketAddress(kTurnUdpExtAddr.ipaddr(), 0)); | 1146 rtc::SocketAddress(kTurnUdpExtAddr.ipaddr(), 0)); |
1195 EXPECT_TRUE_WAIT(candidate_allocation_done_, kDefaultAllocationTimeout); | 1147 EXPECT_TRUE_WAIT(candidate_allocation_done_, kDefaultAllocationTimeout); |
1196 EXPECT_EQ(3U, candidates_.size()); | 1148 EXPECT_EQ(3U, candidates_.size()); |
1197 // Local port will be created first and then TURN port. | 1149 // Local port will be created first and then TURN port. |
1198 EXPECT_EQ(2U, ports_[0]->Candidates().size()); | 1150 EXPECT_EQ(2U, ports_[0]->Candidates().size()); |
1199 EXPECT_EQ(1U, ports_[1]->Candidates().size()); | 1151 EXPECT_EQ(1U, ports_[1]->Candidates().size()); |
1200 } | 1152 } |
1201 | 1153 |
1202 // Test that when PORTALLOCATOR_ENABLE_SHARED_SOCKET is enabled and the TURN | 1154 // Test that when PORTALLOCATOR_ENABLE_SHARED_SOCKET is enabled and the TURN |
1203 // server is also used as the STUN server, we should get 'local', 'stun', and | 1155 // server is also used as the STUN server, we should get 'local', 'stun', and |
1204 // 'relay' candidates. | 1156 // 'relay' candidates. |
1205 TEST_F(BasicPortAllocatorTest, TestSharedSocketWithNatUsingTurnAsStun) { | 1157 TEST_F(PortAllocatorTest, TestSharedSocketWithNatUsingTurnAsStun) { |
1206 AddInterface(kClientAddr); | 1158 AddInterface(kClientAddr); |
1207 // Use an empty SocketAddress to add a NAT without STUN server. | 1159 // Use an empty SocketAddress to add a NAT without STUN server. |
1208 ResetWithStunServerAndNat(SocketAddress()); | 1160 ResetWithStunServerAndNat(SocketAddress()); |
1209 AddTurnServers(kTurnUdpIntAddr, rtc::SocketAddress()); | 1161 AddTurnServers(kTurnUdpIntAddr, rtc::SocketAddress()); |
1210 | 1162 |
1211 // Must set the step delay to 0 to make sure the relay allocation phase is | 1163 // Must set the step delay to 0 to make sure the relay allocation phase is |
1212 // started before the STUN candidates are obtained, so that the STUN binding | 1164 // started before the STUN candidates are obtained, so that the STUN binding |
1213 // response is processed when both StunPort and TurnPort exist to reproduce | 1165 // response is processed when both StunPort and TurnPort exist to reproduce |
1214 // webrtc issue 3537. | 1166 // webrtc issue 3537. |
1215 allocator_->set_step_delay(0); | 1167 allocator_->set_step_delay(0); |
1216 allocator_->set_flags(allocator().flags() | | 1168 allocator_->set_flags(allocator().flags() | |
1217 cricket::PORTALLOCATOR_ENABLE_SHARED_SOCKET | | 1169 cricket::PORTALLOCATOR_ENABLE_SHARED_SOCKET | |
1218 cricket::PORTALLOCATOR_DISABLE_TCP); | 1170 cricket::PORTALLOCATOR_DISABLE_TCP); |
1219 | 1171 |
1220 EXPECT_TRUE(CreateSession(cricket::ICE_CANDIDATE_COMPONENT_RTP)); | 1172 EXPECT_TRUE(CreateSession(cricket::ICE_CANDIDATE_COMPONENT_RTP)); |
1221 session_->StartGettingPorts(); | 1173 session_->StartGettingPorts(); |
1222 | 1174 |
1223 ASSERT_EQ_WAIT(3U, candidates_.size(), kDefaultAllocationTimeout); | 1175 ASSERT_EQ_WAIT(3U, candidates_.size(), kDefaultAllocationTimeout); |
1224 EXPECT_PRED5(CheckCandidate, candidates_[0], | 1176 EXPECT_PRED5(CheckCandidate, candidates_[0], |
1225 cricket::ICE_CANDIDATE_COMPONENT_RTP, "local", "udp", | 1177 cricket::ICE_CANDIDATE_COMPONENT_RTP, "local", "udp", kClientAddr); |
1226 kClientAddr); | |
1227 EXPECT_PRED5(CheckCandidate, candidates_[1], | 1178 EXPECT_PRED5(CheckCandidate, candidates_[1], |
1228 cricket::ICE_CANDIDATE_COMPONENT_RTP, "stun", "udp", | 1179 cricket::ICE_CANDIDATE_COMPONENT_RTP, "stun", "udp", |
1229 rtc::SocketAddress(kNatUdpAddr.ipaddr(), 0)); | 1180 rtc::SocketAddress(kNatUdpAddr.ipaddr(), 0)); |
1230 EXPECT_PRED5(CheckCandidate, candidates_[2], | 1181 EXPECT_PRED5(CheckCandidate, candidates_[2], |
1231 cricket::ICE_CANDIDATE_COMPONENT_RTP, "relay", "udp", | 1182 cricket::ICE_CANDIDATE_COMPONENT_RTP, "relay", "udp", |
1232 rtc::SocketAddress(kTurnUdpExtAddr.ipaddr(), 0)); | 1183 rtc::SocketAddress(kTurnUdpExtAddr.ipaddr(), 0)); |
1233 EXPECT_EQ(candidates_[2].related_address(), candidates_[1].address()); | 1184 EXPECT_EQ(candidates_[2].related_address(), candidates_[1].address()); |
1234 | 1185 |
1235 EXPECT_TRUE_WAIT(candidate_allocation_done_, kDefaultAllocationTimeout); | 1186 EXPECT_TRUE_WAIT(candidate_allocation_done_, kDefaultAllocationTimeout); |
1236 EXPECT_EQ(3U, candidates_.size()); | 1187 EXPECT_EQ(3U, candidates_.size()); |
1237 // Local port will be created first and then TURN port. | 1188 // Local port will be created first and then TURN port. |
1238 EXPECT_EQ(2U, ports_[0]->Candidates().size()); | 1189 EXPECT_EQ(2U, ports_[0]->Candidates().size()); |
1239 EXPECT_EQ(1U, ports_[1]->Candidates().size()); | 1190 EXPECT_EQ(1U, ports_[1]->Candidates().size()); |
1240 } | 1191 } |
1241 | 1192 |
1242 // Test that when only a TCP TURN server is available, we do NOT use it as | 1193 // Test that when only a TCP TURN server is available, we do NOT use it as |
1243 // a UDP STUN server, as this could leak our IP address. Thus we should only | 1194 // a UDP STUN server, as this could leak our IP address. Thus we should only |
1244 // expect two ports, a UDPPort and TurnPort. | 1195 // expect two ports, a UDPPort and TurnPort. |
1245 TEST_F(BasicPortAllocatorTest, TestSharedSocketWithNatUsingTurnTcpOnly) { | 1196 TEST_F(PortAllocatorTest, TestSharedSocketWithNatUsingTurnTcpOnly) { |
1246 turn_server_.AddInternalSocket(kTurnTcpIntAddr, cricket::PROTO_TCP); | 1197 turn_server_.AddInternalSocket(kTurnTcpIntAddr, cricket::PROTO_TCP); |
1247 AddInterface(kClientAddr); | 1198 AddInterface(kClientAddr); |
1248 ResetWithStunServerAndNat(rtc::SocketAddress()); | 1199 ResetWithStunServerAndNat(rtc::SocketAddress()); |
1249 AddTurnServers(rtc::SocketAddress(), kTurnTcpIntAddr); | 1200 AddTurnServers(rtc::SocketAddress(), kTurnTcpIntAddr); |
1250 | 1201 |
1251 allocator_->set_flags(allocator().flags() | | 1202 allocator_->set_flags(allocator().flags() | |
1252 cricket::PORTALLOCATOR_ENABLE_SHARED_SOCKET | | 1203 cricket::PORTALLOCATOR_ENABLE_SHARED_SOCKET | |
1253 cricket::PORTALLOCATOR_DISABLE_TCP); | 1204 cricket::PORTALLOCATOR_DISABLE_TCP); |
1254 | 1205 |
1255 EXPECT_TRUE(CreateSession(cricket::ICE_CANDIDATE_COMPONENT_RTP)); | 1206 EXPECT_TRUE(CreateSession(cricket::ICE_CANDIDATE_COMPONENT_RTP)); |
(...skipping 11 matching lines...) Expand all Loading... |
1267 EXPECT_EQ(2U, candidates_.size()); | 1218 EXPECT_EQ(2U, candidates_.size()); |
1268 EXPECT_EQ(1U, ports_[0]->Candidates().size()); | 1219 EXPECT_EQ(1U, ports_[0]->Candidates().size()); |
1269 EXPECT_EQ(1U, ports_[1]->Candidates().size()); | 1220 EXPECT_EQ(1U, ports_[1]->Candidates().size()); |
1270 } | 1221 } |
1271 | 1222 |
1272 // Test that even when PORTALLOCATOR_ENABLE_SHARED_SOCKET is NOT enabled, the | 1223 // Test that even when PORTALLOCATOR_ENABLE_SHARED_SOCKET is NOT enabled, the |
1273 // TURN server is used as the STUN server and we get 'local', 'stun', and | 1224 // TURN server is used as the STUN server and we get 'local', 'stun', and |
1274 // 'relay' candidates. | 1225 // 'relay' candidates. |
1275 // TODO(deadbeef): Remove this test when support for non-shared socket mode | 1226 // TODO(deadbeef): Remove this test when support for non-shared socket mode |
1276 // is removed. | 1227 // is removed. |
1277 TEST_F(BasicPortAllocatorTest, TestNonSharedSocketWithNatUsingTurnAsStun) { | 1228 TEST_F(PortAllocatorTest, TestNonSharedSocketWithNatUsingTurnAsStun) { |
1278 AddInterface(kClientAddr); | 1229 AddInterface(kClientAddr); |
1279 // Use an empty SocketAddress to add a NAT without STUN server. | 1230 // Use an empty SocketAddress to add a NAT without STUN server. |
1280 ResetWithStunServerAndNat(SocketAddress()); | 1231 ResetWithStunServerAndNat(SocketAddress()); |
1281 AddTurnServers(kTurnUdpIntAddr, rtc::SocketAddress()); | 1232 AddTurnServers(kTurnUdpIntAddr, rtc::SocketAddress()); |
1282 | 1233 |
1283 allocator_->set_flags(allocator().flags() | | 1234 allocator_->set_flags(allocator().flags() | |
1284 cricket::PORTALLOCATOR_DISABLE_TCP); | 1235 cricket::PORTALLOCATOR_DISABLE_TCP); |
1285 | 1236 |
1286 EXPECT_TRUE(CreateSession(cricket::ICE_CANDIDATE_COMPONENT_RTP)); | 1237 EXPECT_TRUE(CreateSession(cricket::ICE_CANDIDATE_COMPONENT_RTP)); |
1287 session_->StartGettingPorts(); | 1238 session_->StartGettingPorts(); |
(...skipping 15 matching lines...) Expand all Loading... |
1303 | 1254 |
1304 EXPECT_TRUE_WAIT(candidate_allocation_done_, kDefaultAllocationTimeout); | 1255 EXPECT_TRUE_WAIT(candidate_allocation_done_, kDefaultAllocationTimeout); |
1305 EXPECT_EQ(3U, candidates_.size()); | 1256 EXPECT_EQ(3U, candidates_.size()); |
1306 EXPECT_EQ(1U, ports_[0]->Candidates().size()); | 1257 EXPECT_EQ(1U, ports_[0]->Candidates().size()); |
1307 EXPECT_EQ(1U, ports_[1]->Candidates().size()); | 1258 EXPECT_EQ(1U, ports_[1]->Candidates().size()); |
1308 EXPECT_EQ(1U, ports_[2]->Candidates().size()); | 1259 EXPECT_EQ(1U, ports_[2]->Candidates().size()); |
1309 } | 1260 } |
1310 | 1261 |
1311 // Test that even when both a STUN and TURN server are configured, the TURN | 1262 // Test that even when both a STUN and TURN server are configured, the TURN |
1312 // server is used as a STUN server and we get a 'stun' candidate. | 1263 // server is used as a STUN server and we get a 'stun' candidate. |
1313 TEST_F(BasicPortAllocatorTest, TestSharedSocketWithNatUsingTurnAndStun) { | 1264 TEST_F(PortAllocatorTest, TestSharedSocketWithNatUsingTurnAndStun) { |
1314 AddInterface(kClientAddr); | 1265 AddInterface(kClientAddr); |
1315 // Configure with STUN server but destroy it, so we can ensure that it's | 1266 // Configure with STUN server but destroy it, so we can ensure that it's |
1316 // the TURN server actually being used as a STUN server. | 1267 // the TURN server actually being used as a STUN server. |
1317 ResetWithStunServerAndNat(kStunAddr); | 1268 ResetWithStunServerAndNat(kStunAddr); |
1318 stun_server_.reset(); | 1269 stun_server_.reset(); |
1319 AddTurnServers(kTurnUdpIntAddr, rtc::SocketAddress()); | 1270 AddTurnServers(kTurnUdpIntAddr, rtc::SocketAddress()); |
1320 | 1271 |
1321 allocator_->set_flags(allocator().flags() | | 1272 allocator_->set_flags(allocator().flags() | |
1322 cricket::PORTALLOCATOR_ENABLE_SHARED_SOCKET | | 1273 cricket::PORTALLOCATOR_ENABLE_SHARED_SOCKET | |
1323 cricket::PORTALLOCATOR_DISABLE_TCP); | 1274 cricket::PORTALLOCATOR_DISABLE_TCP); |
(...skipping 13 matching lines...) Expand all Loading... |
1337 rtc::SocketAddress(kTurnUdpExtAddr.ipaddr(), 0)); | 1288 rtc::SocketAddress(kTurnUdpExtAddr.ipaddr(), 0)); |
1338 EXPECT_EQ(candidates_[2].related_address(), candidates_[1].address()); | 1289 EXPECT_EQ(candidates_[2].related_address(), candidates_[1].address()); |
1339 | 1290 |
1340 // Don't bother waiting for STUN timeout, since we already verified | 1291 // Don't bother waiting for STUN timeout, since we already verified |
1341 // that we got a STUN candidate from the TURN server. | 1292 // that we got a STUN candidate from the TURN server. |
1342 } | 1293 } |
1343 | 1294 |
1344 // This test verifies when PORTALLOCATOR_ENABLE_SHARED_SOCKET flag is enabled | 1295 // This test verifies when PORTALLOCATOR_ENABLE_SHARED_SOCKET flag is enabled |
1345 // and fail to generate STUN candidate, local UDP candidate is generated | 1296 // and fail to generate STUN candidate, local UDP candidate is generated |
1346 // properly. | 1297 // properly. |
1347 TEST_F(BasicPortAllocatorTest, TestSharedSocketNoUdpAllowed) { | 1298 TEST_F(PortAllocatorTest, TestSharedSocketNoUdpAllowed) { |
1348 allocator().set_flags(allocator().flags() | | 1299 allocator().set_flags(allocator().flags() | |
1349 cricket::PORTALLOCATOR_DISABLE_RELAY | | 1300 cricket::PORTALLOCATOR_DISABLE_RELAY | |
1350 cricket::PORTALLOCATOR_DISABLE_TCP | | 1301 cricket::PORTALLOCATOR_DISABLE_TCP | |
1351 cricket::PORTALLOCATOR_ENABLE_SHARED_SOCKET); | 1302 cricket::PORTALLOCATOR_ENABLE_SHARED_SOCKET); |
1352 fss_->AddRule(false, rtc::FP_UDP, rtc::FD_ANY, kClientAddr); | 1303 fss_->AddRule(false, rtc::FP_UDP, rtc::FD_ANY, kClientAddr); |
1353 AddInterface(kClientAddr); | 1304 AddInterface(kClientAddr); |
1354 EXPECT_TRUE(CreateSession(cricket::ICE_CANDIDATE_COMPONENT_RTP)); | 1305 EXPECT_TRUE(CreateSession(cricket::ICE_CANDIDATE_COMPONENT_RTP)); |
1355 session_->StartGettingPorts(); | 1306 session_->StartGettingPorts(); |
1356 ASSERT_EQ_WAIT(1U, ports_.size(), kDefaultAllocationTimeout); | 1307 ASSERT_EQ_WAIT(1U, ports_.size(), kDefaultAllocationTimeout); |
1357 EXPECT_EQ(1U, candidates_.size()); | 1308 EXPECT_EQ(1U, candidates_.size()); |
1358 EXPECT_PRED5(CheckCandidate, candidates_[0], | 1309 EXPECT_PRED5(CheckCandidate, candidates_[0], |
1359 cricket::ICE_CANDIDATE_COMPONENT_RTP, "local", "udp", | 1310 cricket::ICE_CANDIDATE_COMPONENT_RTP, "local", "udp", kClientAddr); |
1360 kClientAddr); | |
1361 // STUN timeout is 9sec. We need to wait to get candidate done signal. | 1311 // STUN timeout is 9sec. We need to wait to get candidate done signal. |
1362 EXPECT_TRUE_WAIT(candidate_allocation_done_, 10000); | 1312 EXPECT_TRUE_WAIT(candidate_allocation_done_, 10000); |
1363 EXPECT_EQ(1U, candidates_.size()); | 1313 EXPECT_EQ(1U, candidates_.size()); |
1364 } | 1314 } |
1365 | 1315 |
1366 // Test that when the NetworkManager doesn't have permission to enumerate | 1316 // Test that when the NetworkManager doesn't have permission to enumerate |
1367 // adapters, the PORTALLOCATOR_DISABLE_ADAPTER_ENUMERATION is specified | 1317 // adapters, the PORTALLOCATOR_DISABLE_ADAPTER_ENUMERATION is specified |
1368 // automatically. | 1318 // automatically. |
1369 TEST_F(BasicPortAllocatorTest, TestNetworkPermissionBlocked) { | 1319 TEST_F(PortAllocatorTest, TestNetworkPermissionBlocked) { |
1370 network_manager_.set_default_local_addresses(kPrivateAddr.ipaddr(), | 1320 network_manager_.set_default_local_addresses(kPrivateAddr.ipaddr(), |
1371 rtc::IPAddress()); | 1321 rtc::IPAddress()); |
1372 network_manager_.set_enumeration_permission( | 1322 network_manager_.set_enumeration_permission( |
1373 rtc::NetworkManager::ENUMERATION_BLOCKED); | 1323 rtc::NetworkManager::ENUMERATION_BLOCKED); |
1374 allocator().set_flags(allocator().flags() | | 1324 allocator().set_flags(allocator().flags() | |
1375 cricket::PORTALLOCATOR_DISABLE_RELAY | | 1325 cricket::PORTALLOCATOR_DISABLE_RELAY | |
1376 cricket::PORTALLOCATOR_DISABLE_TCP | | 1326 cricket::PORTALLOCATOR_DISABLE_TCP | |
1377 cricket::PORTALLOCATOR_ENABLE_SHARED_SOCKET); | 1327 cricket::PORTALLOCATOR_ENABLE_SHARED_SOCKET); |
1378 EXPECT_EQ(0U, allocator_->flags() & | 1328 EXPECT_EQ(0U, allocator_->flags() & |
1379 cricket::PORTALLOCATOR_DISABLE_ADAPTER_ENUMERATION); | 1329 cricket::PORTALLOCATOR_DISABLE_ADAPTER_ENUMERATION); |
1380 EXPECT_TRUE(CreateSession(cricket::ICE_CANDIDATE_COMPONENT_RTP)); | 1330 EXPECT_TRUE(CreateSession(cricket::ICE_CANDIDATE_COMPONENT_RTP)); |
1381 EXPECT_EQ(0U, session_->flags() & | 1331 EXPECT_EQ(0U, session_->flags() & |
1382 cricket::PORTALLOCATOR_DISABLE_ADAPTER_ENUMERATION); | 1332 cricket::PORTALLOCATOR_DISABLE_ADAPTER_ENUMERATION); |
1383 session_->StartGettingPorts(); | 1333 session_->StartGettingPorts(); |
1384 EXPECT_EQ_WAIT(1U, ports_.size(), kDefaultAllocationTimeout); | 1334 EXPECT_EQ_WAIT(1U, ports_.size(), kDefaultAllocationTimeout); |
1385 EXPECT_EQ(1U, candidates_.size()); | 1335 EXPECT_EQ(1U, candidates_.size()); |
1386 EXPECT_PRED5(CheckCandidate, candidates_[0], | 1336 EXPECT_PRED5(CheckCandidate, candidates_[0], |
1387 cricket::ICE_CANDIDATE_COMPONENT_RTP, "local", "udp", | 1337 cricket::ICE_CANDIDATE_COMPONENT_RTP, "local", "udp", |
1388 kPrivateAddr); | 1338 kPrivateAddr); |
1389 EXPECT_NE(0U, session_->flags() & | 1339 EXPECT_TRUE((session_->flags() & |
1390 cricket::PORTALLOCATOR_DISABLE_ADAPTER_ENUMERATION); | 1340 cricket::PORTALLOCATOR_DISABLE_ADAPTER_ENUMERATION) != 0); |
1391 } | 1341 } |
1392 | 1342 |
1393 // This test verifies allocator can use IPv6 addresses along with IPv4. | 1343 // This test verifies allocator can use IPv6 addresses along with IPv4. |
1394 TEST_F(BasicPortAllocatorTest, TestEnableIPv6Addresses) { | 1344 TEST_F(PortAllocatorTest, TestEnableIPv6Addresses) { |
1395 allocator().set_flags(allocator().flags() | | 1345 allocator().set_flags(allocator().flags() | |
1396 cricket::PORTALLOCATOR_DISABLE_RELAY | | 1346 cricket::PORTALLOCATOR_DISABLE_RELAY | |
1397 cricket::PORTALLOCATOR_ENABLE_IPV6 | | 1347 cricket::PORTALLOCATOR_ENABLE_IPV6 | |
1398 cricket::PORTALLOCATOR_ENABLE_SHARED_SOCKET); | 1348 cricket::PORTALLOCATOR_ENABLE_SHARED_SOCKET); |
1399 AddInterface(kClientIPv6Addr); | 1349 AddInterface(kClientIPv6Addr); |
1400 AddInterface(kClientAddr); | 1350 AddInterface(kClientAddr); |
1401 allocator_->set_step_delay(cricket::kMinimumStepDelay); | 1351 allocator_->set_step_delay(cricket::kMinimumStepDelay); |
1402 EXPECT_TRUE(CreateSession(cricket::ICE_CANDIDATE_COMPONENT_RTP)); | 1352 EXPECT_TRUE(CreateSession(cricket::ICE_CANDIDATE_COMPONENT_RTP)); |
1403 session_->StartGettingPorts(); | 1353 session_->StartGettingPorts(); |
1404 ASSERT_EQ_WAIT(4U, ports_.size(), kDefaultAllocationTimeout); | 1354 ASSERT_EQ_WAIT(4U, ports_.size(), kDefaultAllocationTimeout); |
1405 EXPECT_EQ(4U, candidates_.size()); | 1355 EXPECT_EQ(4U, candidates_.size()); |
1406 EXPECT_TRUE_WAIT(candidate_allocation_done_, kDefaultAllocationTimeout); | 1356 EXPECT_TRUE_WAIT(candidate_allocation_done_, kDefaultAllocationTimeout); |
1407 EXPECT_PRED5(CheckCandidate, candidates_[0], | 1357 EXPECT_PRED5(CheckCandidate, candidates_[0], |
1408 cricket::ICE_CANDIDATE_COMPONENT_RTP, "local", "udp", | 1358 cricket::ICE_CANDIDATE_COMPONENT_RTP, "local", "udp", |
1409 kClientIPv6Addr); | 1359 kClientIPv6Addr); |
1410 EXPECT_PRED5(CheckCandidate, candidates_[1], | 1360 EXPECT_PRED5(CheckCandidate, candidates_[1], |
1411 cricket::ICE_CANDIDATE_COMPONENT_RTP, "local", "udp", | 1361 cricket::ICE_CANDIDATE_COMPONENT_RTP, "local", "udp", |
1412 kClientAddr); | 1362 kClientAddr); |
1413 EXPECT_PRED5(CheckCandidate, candidates_[2], | 1363 EXPECT_PRED5(CheckCandidate, candidates_[2], |
1414 cricket::ICE_CANDIDATE_COMPONENT_RTP, "local", "tcp", | 1364 cricket::ICE_CANDIDATE_COMPONENT_RTP, "local", "tcp", |
1415 kClientIPv6Addr); | 1365 kClientIPv6Addr); |
1416 EXPECT_PRED5(CheckCandidate, candidates_[3], | 1366 EXPECT_PRED5(CheckCandidate, candidates_[3], |
1417 cricket::ICE_CANDIDATE_COMPONENT_RTP, "local", "tcp", | 1367 cricket::ICE_CANDIDATE_COMPONENT_RTP, "local", "tcp", |
1418 kClientAddr); | 1368 kClientAddr); |
1419 EXPECT_EQ(4U, candidates_.size()); | 1369 EXPECT_EQ(4U, candidates_.size()); |
1420 } | 1370 } |
1421 | 1371 |
1422 TEST_F(BasicPortAllocatorTest, TestStopGettingPorts) { | 1372 TEST_F(PortAllocatorTest, TestStopGettingPorts) { |
1423 AddInterface(kClientAddr); | 1373 AddInterface(kClientAddr); |
1424 allocator_->set_step_delay(cricket::kDefaultStepDelay); | 1374 allocator_->set_step_delay(cricket::kDefaultStepDelay); |
1425 EXPECT_TRUE(CreateSession(cricket::ICE_CANDIDATE_COMPONENT_RTP)); | 1375 EXPECT_TRUE(CreateSession(cricket::ICE_CANDIDATE_COMPONENT_RTP)); |
1426 session_->StartGettingPorts(); | 1376 session_->StartGettingPorts(); |
1427 ASSERT_EQ_WAIT(2U, candidates_.size(), 1000); | 1377 ASSERT_EQ_WAIT(2U, candidates_.size(), 1000); |
1428 EXPECT_EQ(2U, ports_.size()); | 1378 EXPECT_EQ(2U, ports_.size()); |
1429 session_->StopGettingPorts(); | 1379 session_->StopGettingPorts(); |
1430 EXPECT_TRUE_WAIT(candidate_allocation_done_, 1000); | 1380 EXPECT_TRUE_WAIT(candidate_allocation_done_, 1000); |
1431 | 1381 |
1432 // After stopping getting ports, adding a new interface will not start | 1382 // After stopping getting ports, adding a new interface will not start |
1433 // getting ports again. | 1383 // getting ports again. |
1434 candidates_.clear(); | 1384 candidates_.clear(); |
1435 ports_.clear(); | 1385 ports_.clear(); |
1436 candidate_allocation_done_ = false; | 1386 candidate_allocation_done_ = false; |
1437 network_manager_.AddInterface(kClientAddr2); | 1387 network_manager_.AddInterface(kClientAddr2); |
1438 rtc::Thread::Current()->ProcessMessages(1000); | 1388 rtc::Thread::Current()->ProcessMessages(1000); |
1439 EXPECT_EQ(0U, candidates_.size()); | 1389 EXPECT_EQ(0U, candidates_.size()); |
1440 EXPECT_EQ(0U, ports_.size()); | 1390 EXPECT_EQ(0U, ports_.size()); |
1441 } | 1391 } |
1442 | 1392 |
1443 TEST_F(BasicPortAllocatorTest, TestClearGettingPorts) { | 1393 TEST_F(PortAllocatorTest, TestClearGettingPorts) { |
1444 AddInterface(kClientAddr); | 1394 AddInterface(kClientAddr); |
1445 allocator_->set_step_delay(cricket::kDefaultStepDelay); | 1395 allocator_->set_step_delay(cricket::kDefaultStepDelay); |
1446 EXPECT_TRUE(CreateSession(cricket::ICE_CANDIDATE_COMPONENT_RTP)); | 1396 EXPECT_TRUE(CreateSession(cricket::ICE_CANDIDATE_COMPONENT_RTP)); |
1447 session_->StartGettingPorts(); | 1397 session_->StartGettingPorts(); |
1448 ASSERT_EQ_WAIT(2U, candidates_.size(), 1000); | 1398 ASSERT_EQ_WAIT(2U, candidates_.size(), 1000); |
1449 EXPECT_EQ(2U, ports_.size()); | 1399 EXPECT_EQ(2U, ports_.size()); |
1450 session_->ClearGettingPorts(); | 1400 session_->ClearGettingPorts(); |
1451 WAIT(candidate_allocation_done_, 1000); | 1401 WAIT(candidate_allocation_done_, 1000); |
1452 EXPECT_FALSE(candidate_allocation_done_); | 1402 EXPECT_FALSE(candidate_allocation_done_); |
1453 | 1403 |
1454 // After clearing getting ports, adding a new interface will start getting | 1404 // After clearing getting ports, adding a new interface will start getting |
1455 // ports again. | 1405 // ports again. |
1456 candidates_.clear(); | 1406 candidates_.clear(); |
1457 ports_.clear(); | 1407 ports_.clear(); |
1458 candidate_allocation_done_ = false; | 1408 candidate_allocation_done_ = false; |
1459 network_manager_.AddInterface(kClientAddr2); | 1409 network_manager_.AddInterface(kClientAddr2); |
1460 ASSERT_EQ_WAIT(2U, candidates_.size(), 1000); | 1410 ASSERT_EQ_WAIT(2U, candidates_.size(), 1000); |
1461 EXPECT_EQ(2U, ports_.size()); | 1411 EXPECT_EQ(2U, ports_.size()); |
1462 } | 1412 } |
1463 | |
1464 // Test that the ports and candidates are updated with new ufrag/pwd/etc. when | |
1465 // a pooled session is taken out of the pool. | |
1466 TEST_F(BasicPortAllocatorTest, TestTransportInformationUpdated) { | |
1467 AddInterface(kClientAddr); | |
1468 int pool_size = 1; | |
1469 allocator_->SetConfiguration(allocator_->stun_servers(), | |
1470 allocator_->turn_servers(), pool_size); | |
1471 const cricket::PortAllocatorSession* peeked_session = | |
1472 allocator_->GetPooledSession(); | |
1473 ASSERT_NE(nullptr, peeked_session); | |
1474 EXPECT_EQ_WAIT(true, peeked_session->CandidatesAllocationDone(), | |
1475 kDefaultAllocationTimeout); | |
1476 // Expect that when TakePooledSession is called, | |
1477 // UpdateTransportInformationInternal will be called and the | |
1478 // BasicPortAllocatorSession will update the ufrag/pwd of ports and | |
1479 // candidates. | |
1480 session_ = | |
1481 allocator_->TakePooledSession(kContentName, 1, kIceUfrag0, kIcePwd0); | |
1482 ASSERT_NE(nullptr, session_.get()); | |
1483 auto ready_ports = session_->ReadyPorts(); | |
1484 auto candidates = session_->ReadyCandidates(); | |
1485 EXPECT_FALSE(ready_ports.empty()); | |
1486 EXPECT_FALSE(candidates.empty()); | |
1487 for (const cricket::PortInterface* port_interface : ready_ports) { | |
1488 const cricket::Port* port = | |
1489 static_cast<const cricket::Port*>(port_interface); | |
1490 EXPECT_EQ(kContentName, port->content_name()); | |
1491 EXPECT_EQ(1, port->component()); | |
1492 EXPECT_EQ(kIceUfrag0, port->username_fragment()); | |
1493 EXPECT_EQ(kIcePwd0, port->password()); | |
1494 } | |
1495 for (const cricket::Candidate& candidate : candidates) { | |
1496 EXPECT_EQ(1, candidate.component()); | |
1497 EXPECT_EQ(kIceUfrag0, candidate.username()); | |
1498 EXPECT_EQ(kIcePwd0, candidate.password()); | |
1499 } | |
1500 } | |
OLD | NEW |