| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2015 The WebRTC Project Authors. All rights reserved. | 2 * Copyright 2015 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 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 52 stun_server_2_->set_fake_stun_addr(kStunMappedAddr); | 52 stun_server_2_->set_fake_stun_addr(kStunMappedAddr); |
| 53 rtc::InitializeSSL(); | 53 rtc::InitializeSSL(); |
| 54 } | 54 } |
| 55 | 55 |
| 56 void set_expected_result(int result) { result_ = result; } | 56 void set_expected_result(int result) { result_ = result; } |
| 57 | 57 |
| 58 void StartProbing(rtc::PacketSocketFactory* socket_factory, | 58 void StartProbing(rtc::PacketSocketFactory* socket_factory, |
| 59 const std::vector<rtc::SocketAddress>& addrs, | 59 const std::vector<rtc::SocketAddress>& addrs, |
| 60 const rtc::NetworkManager::NetworkList& networks, | 60 const rtc::NetworkManager::NetworkList& networks, |
| 61 bool shared_socket, | 61 bool shared_socket, |
| 62 uint16 interval, | 62 uint16_t interval, |
| 63 uint16 pings_per_ip) { | 63 uint16_t pings_per_ip) { |
| 64 prober.reset( | 64 prober.reset( |
| 65 new StunProber(socket_factory, rtc::Thread::Current(), networks)); | 65 new StunProber(socket_factory, rtc::Thread::Current(), networks)); |
| 66 prober->Start(addrs, shared_socket, interval, pings_per_ip, | 66 prober->Start(addrs, shared_socket, interval, pings_per_ip, |
| 67 100 /* timeout_ms */, [this](StunProber* prober, int result) { | 67 100 /* timeout_ms */, [this](StunProber* prober, int result) { |
| 68 this->StopCallback(prober, result); | 68 this->StopCallback(prober, result); |
| 69 }); | 69 }); |
| 70 } | 70 } |
| 71 | 71 |
| 72 void RunProber(bool shared_mode) { | 72 void RunProber(bool shared_mode) { |
| 73 const int pings_per_ip = 3; | 73 const int pings_per_ip = 3; |
| 74 std::vector<rtc::SocketAddress> addrs; | 74 std::vector<rtc::SocketAddress> addrs; |
| 75 addrs.push_back(kStunAddr1); | 75 addrs.push_back(kStunAddr1); |
| 76 addrs.push_back(kStunAddr2); | 76 addrs.push_back(kStunAddr2); |
| 77 // Add a non-existing server. This shouldn't pollute the result. | 77 // Add a non-existing server. This shouldn't pollute the result. |
| 78 addrs.push_back(kFailedStunAddr); | 78 addrs.push_back(kFailedStunAddr); |
| 79 | 79 |
| 80 rtc::Network ipv4_network1("test_eth0", "Test Network Adapter 1", | 80 rtc::Network ipv4_network1("test_eth0", "Test Network Adapter 1", |
| 81 rtc::IPAddress(0x12345600U), 24); | 81 rtc::IPAddress(0x12345600U), 24); |
| 82 ipv4_network1.AddIP(rtc::IPAddress(0x12345678)); | 82 ipv4_network1.AddIP(rtc::IPAddress(0x12345678)); |
| 83 rtc::NetworkManager::NetworkList networks; | 83 rtc::NetworkManager::NetworkList networks; |
| 84 networks.push_back(&ipv4_network1); | 84 networks.push_back(&ipv4_network1); |
| 85 | 85 |
| 86 rtc::scoped_ptr<rtc::BasicPacketSocketFactory> socket_factory( | 86 rtc::scoped_ptr<rtc::BasicPacketSocketFactory> socket_factory( |
| 87 new rtc::BasicPacketSocketFactory()); | 87 new rtc::BasicPacketSocketFactory()); |
| 88 | 88 |
| 89 // Set up the expected results for verification. | 89 // Set up the expected results for verification. |
| 90 std::set<std::string> srflx_addresses; | 90 std::set<std::string> srflx_addresses; |
| 91 srflx_addresses.insert(kStunMappedAddr.ToString()); | 91 srflx_addresses.insert(kStunMappedAddr.ToString()); |
| 92 const uint32 total_pings_tried = | 92 const uint32_t total_pings_tried = |
| 93 static_cast<uint32>(pings_per_ip * addrs.size()); | 93 static_cast<uint32_t>(pings_per_ip * addrs.size()); |
| 94 | 94 |
| 95 // The reported total_pings should not count for pings sent to the | 95 // The reported total_pings should not count for pings sent to the |
| 96 // kFailedStunAddr. | 96 // kFailedStunAddr. |
| 97 const uint32 total_pings_reported = total_pings_tried - pings_per_ip; | 97 const uint32_t total_pings_reported = total_pings_tried - pings_per_ip; |
| 98 | 98 |
| 99 StartProbing(socket_factory.get(), addrs, networks, shared_mode, 3, | 99 StartProbing(socket_factory.get(), addrs, networks, shared_mode, 3, |
| 100 pings_per_ip); | 100 pings_per_ip); |
| 101 | 101 |
| 102 WAIT(stopped_, 1000); | 102 WAIT(stopped_, 1000); |
| 103 | 103 |
| 104 StunProber::Stats stats; | 104 StunProber::Stats stats; |
| 105 EXPECT_TRUE(prober->GetStats(&stats)); | 105 EXPECT_TRUE(prober->GetStats(&stats)); |
| 106 EXPECT_EQ(stats.success_percent, 100); | 106 EXPECT_EQ(stats.success_percent, 100); |
| 107 EXPECT_TRUE(stats.nat_type > stunprober::NATTYPE_NONE); | 107 EXPECT_TRUE(stats.nat_type > stunprober::NATTYPE_NONE); |
| 108 EXPECT_EQ(stats.srflx_addrs, srflx_addresses); | 108 EXPECT_EQ(stats.srflx_addrs, srflx_addresses); |
| 109 EXPECT_EQ(static_cast<uint32>(stats.num_request_sent), | 109 EXPECT_EQ(static_cast<uint32_t>(stats.num_request_sent), |
| 110 total_pings_reported); | 110 total_pings_reported); |
| 111 EXPECT_EQ(static_cast<uint32>(stats.num_response_received), | 111 EXPECT_EQ(static_cast<uint32_t>(stats.num_response_received), |
| 112 total_pings_reported); | 112 total_pings_reported); |
| 113 } | 113 } |
| 114 | 114 |
| 115 private: | 115 private: |
| 116 void StopCallback(StunProber* prober, int result) { | 116 void StopCallback(StunProber* prober, int result) { |
| 117 EXPECT_EQ(result, result_); | 117 EXPECT_EQ(result, result_); |
| 118 stopped_ = true; | 118 stopped_ = true; |
| 119 } | 119 } |
| 120 | 120 |
| 121 rtc::Thread* main_; | 121 rtc::Thread* main_; |
| 122 rtc::scoped_ptr<rtc::PhysicalSocketServer> pss_; | 122 rtc::scoped_ptr<rtc::PhysicalSocketServer> pss_; |
| 123 rtc::scoped_ptr<rtc::VirtualSocketServer> ss_; | 123 rtc::scoped_ptr<rtc::VirtualSocketServer> ss_; |
| 124 rtc::SocketServerScope ss_scope_; | 124 rtc::SocketServerScope ss_scope_; |
| 125 rtc::scoped_ptr<StunProber> prober; | 125 rtc::scoped_ptr<StunProber> prober; |
| 126 int result_ = 0; | 126 int result_ = 0; |
| 127 bool stopped_ = false; | 127 bool stopped_ = false; |
| 128 rtc::scoped_ptr<cricket::TestStunServer> stun_server_1_; | 128 rtc::scoped_ptr<cricket::TestStunServer> stun_server_1_; |
| 129 rtc::scoped_ptr<cricket::TestStunServer> stun_server_2_; | 129 rtc::scoped_ptr<cricket::TestStunServer> stun_server_2_; |
| 130 }; | 130 }; |
| 131 | 131 |
| 132 TEST_F(StunProberTest, NonSharedMode) { | 132 TEST_F(StunProberTest, NonSharedMode) { |
| 133 RunProber(false); | 133 RunProber(false); |
| 134 } | 134 } |
| 135 | 135 |
| 136 TEST_F(StunProberTest, SharedMode) { | 136 TEST_F(StunProberTest, SharedMode) { |
| 137 RunProber(true); | 137 RunProber(true); |
| 138 } | 138 } |
| 139 | 139 |
| 140 } // namespace stunprober | 140 } // namespace stunprober |
| OLD | NEW |