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