| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2009 The WebRTC Project Authors. All rights reserved. | 2 * Copyright 2009 The WebRTC Project Authors. All rights reserved. |
| 3 * | 3 * |
| 4 * Use of this source code is governed by a BSD-style license | 4 * Use of this source code is governed by a BSD-style license |
| 5 * that can be found in the LICENSE file in the root of the source | 5 * that can be found in the LICENSE file in the root of the source |
| 6 * tree. An additional intellectual property rights grant can be found | 6 * tree. An additional intellectual property rights grant can be found |
| 7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may |
| 8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. |
| 9 */ | 9 */ |
| 10 | 10 |
| (...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 104 allocator_.reset(new cricket::BasicPortAllocator( | 104 allocator_.reset(new cricket::BasicPortAllocator( |
| 105 &network_manager_, | 105 &network_manager_, |
| 106 stun_servers, | 106 stun_servers, |
| 107 kRelayUdpIntAddr, kRelayTcpIntAddr, kRelaySslTcpIntAddr)); | 107 kRelayUdpIntAddr, kRelayTcpIntAddr, kRelaySslTcpIntAddr)); |
| 108 allocator_->set_step_delay(cricket::kMinimumStepDelay); | 108 allocator_->set_step_delay(cricket::kMinimumStepDelay); |
| 109 } | 109 } |
| 110 | 110 |
| 111 void AddInterface(const SocketAddress& addr) { | 111 void AddInterface(const SocketAddress& addr) { |
| 112 network_manager_.AddInterface(addr); | 112 network_manager_.AddInterface(addr); |
| 113 } | 113 } |
| 114 void AddInterface(const SocketAddress& addr, const std::string& if_name) { |
| 115 network_manager_.AddInterface(addr, if_name); |
| 116 } |
| 114 void AddInterfaceAsDefaultRoute(const SocketAddress& addr) { | 117 void AddInterfaceAsDefaultRoute(const SocketAddress& addr) { |
| 115 AddInterface(addr); | 118 AddInterface(addr); |
| 116 // When a binding comes from the any address, the |addr| will be used as the | 119 // When a binding comes from the any address, the |addr| will be used as the |
| 117 // srflx address. | 120 // srflx address. |
| 118 vss_->SetDefaultRoute(addr.ipaddr()); | 121 vss_->SetDefaultRoute(addr.ipaddr()); |
| 119 } | 122 } |
| 123 void RemoveInterface(const SocketAddress& addr) { |
| 124 network_manager_.RemoveInterface(addr); |
| 125 } |
| 120 bool SetPortRange(int min_port, int max_port) { | 126 bool SetPortRange(int min_port, int max_port) { |
| 121 return allocator_->SetPortRange(min_port, max_port); | 127 return allocator_->SetPortRange(min_port, max_port); |
| 122 } | 128 } |
| 123 // Endpoint is on the public network. No STUN or TURN. | 129 // Endpoint is on the public network. No STUN or TURN. |
| 124 void ResetWithNoServersOrNat() { | 130 void ResetWithNoServersOrNat() { |
| 125 allocator_.reset(new cricket::BasicPortAllocator(&network_manager_)); | 131 allocator_.reset(new cricket::BasicPortAllocator(&network_manager_)); |
| 126 allocator_->set_step_delay(cricket::kMinimumStepDelay); | 132 allocator_->set_step_delay(cricket::kMinimumStepDelay); |
| 127 } | 133 } |
| 128 // Endpoint is behind a NAT, with STUN specified. | 134 // Endpoint is behind a NAT, with STUN specified. |
| 129 void ResetWithStunServerAndNat(const rtc::SocketAddress& stun_server) { | 135 void ResetWithStunServerAndNat(const rtc::SocketAddress& stun_server) { |
| (...skipping 295 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 425 EXPECT_PRED5(CheckCandidate, candidates_[4], | 431 EXPECT_PRED5(CheckCandidate, candidates_[4], |
| 426 cricket::ICE_CANDIDATE_COMPONENT_RTP, "relay", "tcp", kRelayTcpIntAddr); | 432 cricket::ICE_CANDIDATE_COMPONENT_RTP, "relay", "tcp", kRelayTcpIntAddr); |
| 427 EXPECT_PRED5(CheckCandidate, candidates_[5], | 433 EXPECT_PRED5(CheckCandidate, candidates_[5], |
| 428 cricket::ICE_CANDIDATE_COMPONENT_RTP, "local", "tcp", kClientAddr); | 434 cricket::ICE_CANDIDATE_COMPONENT_RTP, "local", "tcp", kClientAddr); |
| 429 EXPECT_PRED5(CheckCandidate, candidates_[6], | 435 EXPECT_PRED5(CheckCandidate, candidates_[6], |
| 430 cricket::ICE_CANDIDATE_COMPONENT_RTP, | 436 cricket::ICE_CANDIDATE_COMPONENT_RTP, |
| 431 "relay", "ssltcp", kRelaySslTcpIntAddr); | 437 "relay", "ssltcp", kRelaySslTcpIntAddr); |
| 432 EXPECT_TRUE(candidate_allocation_done_); | 438 EXPECT_TRUE(candidate_allocation_done_); |
| 433 } | 439 } |
| 434 | 440 |
| 441 // Test that when the same network interface is brought down and up, the |
| 442 // port allocator session will restart a new allocation sequence if |
| 443 // it is not stopped. |
| 444 TEST_F(PortAllocatorTest, TestSameNetworkDownAndUpWhenSessionNotStopped) { |
| 445 std::string if_name("test_net0"); |
| 446 AddInterface(kClientAddr, if_name); |
| 447 EXPECT_TRUE(CreateSession(cricket::ICE_CANDIDATE_COMPONENT_RTP)); |
| 448 session_->StartGettingPorts(); |
| 449 ASSERT_EQ_WAIT(7U, candidates_.size(), kDefaultAllocationTimeout); |
| 450 EXPECT_EQ(4U, ports_.size()); |
| 451 EXPECT_TRUE(candidate_allocation_done_); |
| 452 candidate_allocation_done_ = false; |
| 453 candidates_.clear(); |
| 454 ports_.clear(); |
| 455 |
| 456 RemoveInterface(kClientAddr); |
| 457 ASSERT_EQ_WAIT(0U, candidates_.size(), kDefaultAllocationTimeout); |
| 458 EXPECT_EQ(0U, ports_.size()); |
| 459 EXPECT_FALSE(candidate_allocation_done_); |
| 460 |
| 461 // When the same interfaces are added again, new candidates/ports should be |
| 462 // generated. |
| 463 AddInterface(kClientAddr, if_name); |
| 464 ASSERT_EQ_WAIT(7U, candidates_.size(), kDefaultAllocationTimeout); |
| 465 EXPECT_EQ(4U, ports_.size()); |
| 466 EXPECT_TRUE(candidate_allocation_done_); |
| 467 } |
| 468 |
| 469 // Test that when the same network interface is brought down and up, the |
| 470 // port allocator session will not restart a new allocation sequence if |
| 471 // it is stopped. |
| 472 TEST_F(PortAllocatorTest, TestSameNetworkDownAndUpWhenSessionStopped) { |
| 473 std::string if_name("test_net0"); |
| 474 AddInterface(kClientAddr, if_name); |
| 475 EXPECT_TRUE(CreateSession(cricket::ICE_CANDIDATE_COMPONENT_RTP)); |
| 476 session_->StartGettingPorts(); |
| 477 ASSERT_EQ_WAIT(7U, candidates_.size(), kDefaultAllocationTimeout); |
| 478 EXPECT_EQ(4U, ports_.size()); |
| 479 EXPECT_TRUE(candidate_allocation_done_); |
| 480 session_->StopGettingPorts(); |
| 481 candidates_.clear(); |
| 482 ports_.clear(); |
| 483 |
| 484 RemoveInterface(kClientAddr); |
| 485 ASSERT_EQ_WAIT(0U, candidates_.size(), kDefaultAllocationTimeout); |
| 486 EXPECT_EQ(0U, ports_.size()); |
| 487 |
| 488 // When the same interfaces are added again, new candidates/ports should not |
| 489 // be generated because the session has stopped. |
| 490 AddInterface(kClientAddr, if_name); |
| 491 ASSERT_EQ_WAIT(0U, candidates_.size(), kDefaultAllocationTimeout); |
| 492 EXPECT_EQ(0U, ports_.size()); |
| 493 EXPECT_TRUE(candidate_allocation_done_); |
| 494 } |
| 495 |
| 435 // Verify candidates with default step delay of 1sec. | 496 // Verify candidates with default step delay of 1sec. |
| 436 TEST_F(PortAllocatorTest, TestGetAllPortsWithOneSecondStepDelay) { | 497 TEST_F(PortAllocatorTest, TestGetAllPortsWithOneSecondStepDelay) { |
| 437 AddInterface(kClientAddr); | 498 AddInterface(kClientAddr); |
| 438 allocator_->set_step_delay(cricket::kDefaultStepDelay); | 499 allocator_->set_step_delay(cricket::kDefaultStepDelay); |
| 439 EXPECT_TRUE(CreateSession(cricket::ICE_CANDIDATE_COMPONENT_RTP)); | 500 EXPECT_TRUE(CreateSession(cricket::ICE_CANDIDATE_COMPONENT_RTP)); |
| 440 session_->StartGettingPorts(); | 501 session_->StartGettingPorts(); |
| 441 ASSERT_EQ_WAIT(2U, candidates_.size(), 1000); | 502 ASSERT_EQ_WAIT(2U, candidates_.size(), 1000); |
| 442 EXPECT_EQ(2U, ports_.size()); | 503 EXPECT_EQ(2U, ports_.size()); |
| 443 ASSERT_EQ_WAIT(4U, candidates_.size(), 2000); | 504 ASSERT_EQ_WAIT(4U, candidates_.size(), 2000); |
| 444 EXPECT_EQ(3U, ports_.size()); | 505 EXPECT_EQ(3U, ports_.size()); |
| (...skipping 766 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1211 cricket::ICE_CANDIDATE_COMPONENT_RTP, "local", "udp", | 1272 cricket::ICE_CANDIDATE_COMPONENT_RTP, "local", "udp", |
| 1212 kClientAddr); | 1273 kClientAddr); |
| 1213 EXPECT_PRED5(CheckCandidate, candidates_[2], | 1274 EXPECT_PRED5(CheckCandidate, candidates_[2], |
| 1214 cricket::ICE_CANDIDATE_COMPONENT_RTP, "local", "tcp", | 1275 cricket::ICE_CANDIDATE_COMPONENT_RTP, "local", "tcp", |
| 1215 kClientIPv6Addr); | 1276 kClientIPv6Addr); |
| 1216 EXPECT_PRED5(CheckCandidate, candidates_[3], | 1277 EXPECT_PRED5(CheckCandidate, candidates_[3], |
| 1217 cricket::ICE_CANDIDATE_COMPONENT_RTP, "local", "tcp", | 1278 cricket::ICE_CANDIDATE_COMPONENT_RTP, "local", "tcp", |
| 1218 kClientAddr); | 1279 kClientAddr); |
| 1219 EXPECT_EQ(4U, candidates_.size()); | 1280 EXPECT_EQ(4U, candidates_.size()); |
| 1220 } | 1281 } |
| OLD | NEW |