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