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 20 matching lines...) Expand all Loading... | |
31 using stunprober::HostNameResolverInterface; | 31 using stunprober::HostNameResolverInterface; |
32 using stunprober::TaskRunner; | 32 using stunprober::TaskRunner; |
33 using stunprober::SocketFactory; | 33 using stunprober::SocketFactory; |
34 using stunprober::StunProber; | 34 using stunprober::StunProber; |
35 using stunprober::AsyncCallback; | 35 using stunprober::AsyncCallback; |
36 using stunprober::ClientSocketInterface; | 36 using stunprober::ClientSocketInterface; |
37 using stunprober::ServerSocketInterface; | 37 using stunprober::ServerSocketInterface; |
38 using stunprober::SocketFactory; | 38 using stunprober::SocketFactory; |
39 using stunprober::TaskRunner; | 39 using stunprober::TaskRunner; |
40 | 40 |
41 using NATTYPE = stunprober::StunProber::NATTYPE; | |
42 | |
41 DEFINE_bool(help, false, "Prints this message"); | 43 DEFINE_bool(help, false, "Prints this message"); |
42 DEFINE_int(interval, 10, "Interval of consecutive stun pings in milliseconds"); | 44 DEFINE_int(interval, 10, "Interval of consecutive stun pings in milliseconds"); |
43 DEFINE_bool(shared_socket, false, "Share socket mode for different remote IPs"); | 45 DEFINE_bool(shared_socket, false, "Share socket mode for different remote IPs"); |
44 DEFINE_int(pings_per_ip, | 46 DEFINE_int(pings_per_ip, |
45 10, | 47 10, |
46 "Number of consecutive stun pings to send for each IP"); | 48 "Number of consecutive stun pings to send for each IP"); |
47 DEFINE_int(timeout, | 49 DEFINE_int(timeout, |
48 1000, | 50 1000, |
49 "Milliseconds of wait after the last ping sent before exiting"); | 51 "Milliseconds of wait after the last ping sent before exiting"); |
50 DEFINE_string( | 52 DEFINE_string( |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
111 int interval_ms, | 113 int interval_ms, |
112 std::string suffix) { | 114 std::string suffix) { |
113 char output[1000]; | 115 char output[1000]; |
114 rtc::sprintfn(output, sizeof(output), "NetConnectivity6.%s.%s.%dms.%s", | 116 rtc::sprintfn(output, sizeof(output), "NetConnectivity6.%s.%s.%dms.%s", |
115 behind_nat ? "NAT" : "NoNAT", | 117 behind_nat ? "NAT" : "NoNAT", |
116 is_src_port_shared ? "SrcPortShared" : "SrcPortUnique", | 118 is_src_port_shared ? "SrcPortShared" : "SrcPortUnique", |
117 interval_ms, suffix.c_str()); | 119 interval_ms, suffix.c_str()); |
118 return std::string(output); | 120 return std::string(output); |
119 } | 121 } |
120 | 122 |
123 const char* PrintNATType(NATTYPE type) { | |
124 switch (type) { | |
125 case NATTYPE::NATTYPE_NO_NAT: | |
pthatcher2
2015/06/05 22:39:41
Do you really need "NATTYPE::" Prefixed everywhere
pthatcher2
2015/06/05 22:39:41
NATTYPE_NONE?
guoweis_webrtc
2015/06/07 17:29:39
Done.
guoweis_webrtc
2015/06/07 17:29:39
Done.
| |
126 return "not behind NAT"; | |
127 case NATTYPE::NATTYPE_NAT_TYPE_UNKNOWN: | |
pthatcher2
2015/06/05 22:39:41
Why not NATTYPE_UNKNOWN?
guoweis_webrtc
2015/06/07 17:29:39
Done.
| |
128 return "unknown NAT type"; | |
129 case NATTYPE::NATTYPE_SYM_NAT: | |
pthatcher2
2015/06/05 22:39:41
NATTYPE_SYMMETRIC?
guoweis_webrtc
2015/06/07 17:29:39
Done.
| |
130 return "Symmetric NAT"; | |
131 case NATTYPE::NATTYPE_NON_SYM_NAT: | |
pthatcher2
2015/06/05 22:39:41
NATTYPE_NON_SYMMETRIC?
guoweis_webrtc
2015/06/07 17:29:40
Done.
| |
132 return "Non-Symmetric NAT"; | |
pthatcher2
2015/06/05 22:39:41
Please capitalize all of them or none of them.
guoweis_webrtc
2015/06/07 17:29:40
Done.
| |
133 default: | |
134 return "unknown"; | |
pthatcher2
2015/06/05 22:39:41
Is this the same as NATTYPE_UNKNOWN?
guoweis_webrtc
2015/06/07 17:29:39
It's invalid. Updated.
| |
135 } | |
136 } | |
137 | |
121 void PrintStats(StunProber* prober) { | 138 void PrintStats(StunProber* prober) { |
122 StunProber::Stats stats; | 139 StunProber::Stats stats; |
123 if (!prober->GetStats(&stats)) { | 140 if (!prober->GetStats(&stats)) { |
124 LOG(LS_WARNING) << "Results are inconclusive."; | 141 LOG(LS_WARNING) << "Results are inconclusive."; |
125 return; | 142 return; |
126 } | 143 } |
127 | 144 |
128 LOG(LS_INFO) << "Shared Socket Mode: " << stats.shared_socket_mode; | 145 LOG(LS_INFO) << "Shared Socket Mode: " << stats.shared_socket_mode; |
129 LOG(LS_INFO) << "Requests sent: " << stats.num_request_sent; | 146 LOG(LS_INFO) << "Requests sent: " << stats.num_request_sent; |
130 LOG(LS_INFO) << "Responses received: " << stats.num_response_received; | 147 LOG(LS_INFO) << "Responses received: " << stats.num_response_received; |
131 LOG(LS_INFO) << "Target interval (ns): " << stats.target_request_interval_ns; | 148 LOG(LS_INFO) << "Target interval (ns): " << stats.target_request_interval_ns; |
132 LOG(LS_INFO) << "Actual interval (ns): " << stats.actual_request_interval_ns; | 149 LOG(LS_INFO) << "Actual interval (ns): " << stats.actual_request_interval_ns; |
133 LOG(LS_INFO) << "Behind NAT: " << stats.behind_nat; | 150 LOG(LS_INFO) << "NAT Type: " << PrintNATType(stats.nat_type); |
134 if (stats.behind_nat) { | |
135 LOG(LS_INFO) << "NAT is symmetrical: " << (stats.srflx_addrs.size() > 1); | |
136 } | |
137 LOG(LS_INFO) << "Host IP: " << stats.host_ip; | 151 LOG(LS_INFO) << "Host IP: " << stats.host_ip; |
138 LOG(LS_INFO) << "Server-reflexive ips: "; | 152 LOG(LS_INFO) << "Server-reflexive ips: "; |
139 for (auto& ip : stats.srflx_addrs) { | 153 for (auto& ip : stats.srflx_addrs) { |
140 LOG(LS_INFO) << "\t" << ip; | 154 LOG(LS_INFO) << "\t" << ip; |
141 } | 155 } |
142 | 156 |
143 std::string histogram_name = HistogramName( | 157 std::string histogram_name = |
144 stats.behind_nat, FLAG_shared_socket, FLAG_interval, "SuccessPercent"); | 158 HistogramName((stats.nat_type > NATTYPE::NATTYPE_NO_NAT), |
pthatcher2
2015/06/05 22:39:41
What if it's NATTYPE_UNKNOWN?
guoweis_webrtc
2015/06/07 17:29:40
Remove the code. Histogram doesn't make sense here
| |
159 FLAG_shared_socket, FLAG_interval, "SuccessPercent"); | |
145 | 160 |
146 LOG(LS_INFO) << "Histogram '" << histogram_name.c_str() | 161 LOG(LS_INFO) << "Histogram '" << histogram_name.c_str() |
147 << "' = " << stats.success_percent; | 162 << "' = " << stats.success_percent; |
148 | 163 |
149 histogram_name = HistogramName(stats.behind_nat, FLAG_shared_socket, | 164 histogram_name = |
150 FLAG_interval, "ResponseLatency"); | 165 HistogramName((stats.nat_type > NATTYPE::NATTYPE_NO_NAT), |
pthatcher2
2015/06/05 22:39:41
You could avoid duplication with
bool behind_nat
guoweis_webrtc
2015/06/07 17:29:39
Remove the code. Histogram doesn't make sense here
| |
166 FLAG_shared_socket, FLAG_interval, "ResponseLatency"); | |
151 | 167 |
152 LOG(LS_INFO) << "Histogram '" << histogram_name.c_str() | 168 LOG(LS_INFO) << "Histogram '" << histogram_name.c_str() |
153 << "' = " << stats.average_rtt_ms << " ms"; | 169 << "' = " << stats.average_rtt_ms << " ms"; |
154 } | 170 } |
155 | 171 |
156 void StopTrial(rtc::Thread* thread, StunProber* prober, int result) { | 172 void StopTrial(rtc::Thread* thread, StunProber* prober, int result) { |
157 thread->Quit(); | 173 thread->Quit(); |
158 if (prober) { | 174 if (prober) { |
159 LOG(LS_INFO) << "Result: " << result; | 175 LOG(LS_INFO) << "Result: " << result; |
160 if (result == StunProber::SUCCESS) { | 176 if (result == StunProber::SUCCESS) { |
(...skipping 30 matching lines...) Expand all Loading... | |
191 new SocketFactory(), new TaskRunner()); | 207 new SocketFactory(), new TaskRunner()); |
192 auto finish_callback = | 208 auto finish_callback = |
193 [thread, prober](int result) { StopTrial(thread, prober, result); }; | 209 [thread, prober](int result) { StopTrial(thread, prober, result); }; |
194 prober->Start(server_addresses, FLAG_shared_socket, FLAG_interval, | 210 prober->Start(server_addresses, FLAG_shared_socket, FLAG_interval, |
195 FLAG_pings_per_ip, FLAG_timeout, | 211 FLAG_pings_per_ip, FLAG_timeout, |
196 AsyncCallback(finish_callback)); | 212 AsyncCallback(finish_callback)); |
197 thread->Run(); | 213 thread->Run(); |
198 delete prober; | 214 delete prober; |
199 return 0; | 215 return 0; |
200 } | 216 } |
OLD | NEW |