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