blob: 84717ac9d4fa491b3295dd0914df4ba7e782c79d [file] [log] [blame]
The Android Open Source Project02fb0ac2009-03-03 19:30:07 -08001/*
2
3 Copyright (C) 1993-2007 Hewlett-Packard Company
4 ALL RIGHTS RESERVED.
5
6 The enclosed software and documentation includes copyrighted works
7 of Hewlett-Packard Co. For as long as you comply with the following
8 limitations, you are hereby authorized to (i) use, reproduce, and
9 modify the software and documentation, and to (ii) distribute the
10 software and documentation, including modifications, for
11 non-commercial purposes only.
12
13 1. The enclosed software and documentation is made available at no
14 charge in order to advance the general development of
15 high-performance networking products.
16
17 2. You may not delete any copyright notices contained in the
18 software or documentation. All hard copies, and copies in
19 source code or object code form, of the software or
20 documentation (including modifications) must contain at least
21 one of the copyright notices.
22
23 3. The enclosed software and documentation has not been subjected
24 to testing and quality control and is not a Hewlett-Packard Co.
25 product. At a future time, Hewlett-Packard Co. may or may not
26 offer a version of the software and documentation as a product.
27
28 4. THE SOFTWARE AND DOCUMENTATION IS PROVIDED "AS IS".
29 HEWLETT-PACKARD COMPANY DOES NOT WARRANT THAT THE USE,
30 REPRODUCTION, MODIFICATION OR DISTRIBUTION OF THE SOFTWARE OR
31 DOCUMENTATION WILL NOT INFRINGE A THIRD PARTY'S INTELLECTUAL
32 PROPERTY RIGHTS. HP DOES NOT WARRANT THAT THE SOFTWARE OR
33 DOCUMENTATION IS ERROR FREE. HP DISCLAIMS ALL WARRANTIES,
34 EXPRESS AND IMPLIED, WITH REGARD TO THE SOFTWARE AND THE
35 DOCUMENTATION. HP SPECIFICALLY DISCLAIMS ALL WARRANTIES OF
36 MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
37
38 5. HEWLETT-PACKARD COMPANY WILL NOT IN ANY EVENT BE LIABLE FOR ANY
39 DIRECT, INDIRECT, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES
40 (INCLUDING LOST PROFITS) RELATED TO ANY USE, REPRODUCTION,
41 MODIFICATION, OR DISTRIBUTION OF THE SOFTWARE OR DOCUMENTATION.
42
43*/
44char netperf_id[]="\
45@(#)netperf.c (c) Copyright 1993-2007 Hewlett-Packard Company. Version 2.4.3";
46
47#ifdef HAVE_CONFIG_H
48#include "config.h"
49#endif
50
51#include <stdio.h>
52#include <stdlib.h>
53#ifdef HAVE_STRINGS_H
54#include <strings.h>
55#endif
56
57/* FreeBSD doesn't like socket.h before types are set. */
58#if __FreeBSD__
59# include <sys/types.h>
60#endif
61
62#ifndef WIN32
63/* this should only be temporary */
64#include <sys/socket.h>
65#endif
66
67#ifdef WIN32
68#include <winsock2.h>
69#include <windows.h>
70#endif /* WIN32 */
71
72#include "netsh.h"
73#include "netlib.h"
74#include "nettest_bsd.h"
75
76#ifdef WANT_UNIX
77#include "nettest_unix.h"
78#endif /* WANT_UNIX */
79
80#ifdef WANT_XTI
81#include "nettest_xti.h"
82#endif /* WANT_XTI */
83
84#ifdef WANT_DLPI
85#include "nettest_dlpi.h"
86#endif /* WANT_DLPI */
87
88#ifdef WANT_SDP
89#include "nettest_sdp.h"
90#endif
91
92/* The DNS tests have been removed from netperf2. Those wanting to do
93 DNS_RR tests should use netperf4 instead. */
94
95#ifdef DO_DNS
96#error DNS tests have been removed from netperf. Use netperf4 instead
97#endif /* DO_DNS */
98
99#ifdef WANT_SCTP
100#include "nettest_sctp.h"
101#endif
102
103 /* this file contains the main for the netperf program. all the other */
104 /* routines can be found in the file netsh.c */
105
106
107int _cdecl
108main(int argc, char *argv[])
109{
110
111#ifdef WIN32
112 WSADATA wsa_data ;
113
114 /* Initialize the winsock lib ( version 2.2 ) */
115 if ( WSAStartup(MAKEWORD(2,2), &wsa_data) == SOCKET_ERROR ){
116 printf("WSAStartup() failed : %d\n", GetLastError()) ;
117 return 1 ;
118 }
119#endif /* WIN32 */
120
121 netlib_init();
122 set_defaults();
123 scan_cmd_line(argc,argv);
124
125 if (debug) {
126 dump_globals();
127 install_signal_catchers();
128 }
129
130 if (debug) {
131 printf("remotehost is %s and port %s\n",host_name,test_port);
132 fflush(stdout);
133 }
134
135
136 if (!no_control) {
137 establish_control(host_name,test_port,address_family,
138 local_host_name,local_test_port,local_address_family);
139 }
140
141 if (strcasecmp(test_name,"TCP_STREAM") == 0) {
142 send_tcp_stream(host_name);
143 }
144 else if (strcasecmp(test_name,"TCP_MAERTS") == 0) {
145 send_tcp_maerts(host_name);
146 }
147#ifdef HAVE_ICSC_EXS
148 else if (strcasecmp(test_name,"EXS_TCP_STREAM") == 0) {
149 send_exs_tcp_stream(host_name);
150 }
151#endif /* HAVE_ICSC_EXS */
152#ifdef HAVE_SENDFILE
153 else if (strcasecmp(test_name,"TCP_SENDFILE") == 0) {
154 sendfile_tcp_stream(host_name);
155 }
156#endif /* HAVE_SENDFILE */
157 else if (strcasecmp(test_name,"TCP_RR") == 0) {
158 send_tcp_rr(host_name);
159 }
160 else if (strcasecmp(test_name,"TCP_CRR") == 0) {
161 send_tcp_conn_rr(host_name);
162 }
163 else if (strcasecmp(test_name,"TCP_CC") == 0) {
164 send_tcp_cc(host_name);
165 }
166#ifdef DO_1644
167 else if (strcasecmp(test_name,"TCP_TRR") == 0) {
168 send_tcp_tran_rr(host_name);
169 }
170#endif /* DO_1644 */
171#ifdef DO_NBRR
172 else if (strcasecmp(test_name,"TCP_NBRR") == 0) {
173 send_tcp_nbrr(host_name);
174 }
175#endif /* DO_NBRR */
176 else if (strcasecmp(test_name,"UDP_STREAM") == 0) {
177 send_udp_stream(host_name);
178 }
179 else if (strcasecmp(test_name,"UDP_RR") == 0) {
180 send_udp_rr(host_name);
181 }
182 else if (strcasecmp(test_name,"LOC_CPU") == 0) {
183 loc_cpu_rate();
184 }
185 else if (strcasecmp(test_name,"REM_CPU") == 0) {
186 rem_cpu_rate();
187 }
188#ifdef WANT_DLPI
189 else if (strcasecmp(test_name,"DLCO_RR") == 0) {
190 send_dlpi_co_rr(host_name);
191 }
192 else if (strcasecmp(test_name,"DLCL_RR") == 0) {
193 send_dlpi_cl_rr(host_name);
194 }
195 else if (strcasecmp(test_name,"DLCO_STREAM") == 0) {
196 send_dlpi_co_stream(host_name);
197 }
198 else if (strcasecmp(test_name,"DLCL_STREAM") == 0) {
199 send_dlpi_cl_stream(host_name);
200 }
201#endif /* WANT_DLPI */
202#ifdef WANT_UNIX
203 else if (strcasecmp(test_name,"STREAM_RR") == 0) {
204 send_stream_rr(host_name);
205 }
206 else if (strcasecmp(test_name,"DG_RR") == 0) {
207 send_dg_rr(host_name);
208 }
209 else if (strcasecmp(test_name,"STREAM_STREAM") == 0) {
210 send_stream_stream(host_name);
211 }
212 else if (strcasecmp(test_name,"DG_STREAM") == 0) {
213 send_dg_stream(host_name);
214 }
215#endif /* WANT_UNIX */
216#ifdef WANT_XTI
217 else if (strcasecmp(test_name,"XTI_TCP_STREAM") == 0) {
218 send_xti_tcp_stream(host_name);
219 }
220 else if (strcasecmp(test_name,"XTI_TCP_RR") == 0) {
221 send_xti_tcp_rr(host_name);
222 }
223 else if (strcasecmp(test_name,"XTI_UDP_STREAM") == 0) {
224 send_xti_udp_stream(host_name);
225 }
226 else if (strcasecmp(test_name,"XTI_UDP_RR") == 0) {
227 send_xti_udp_rr(host_name);
228 }
229#endif /* WANT_XTI */
230
231#ifdef WANT_SCTP
232 else if (strcasecmp(test_name, "SCTP_STREAM") == 0) {
233 send_sctp_stream(host_name);
234 }
235 else if (strcasecmp(test_name, "SCTP_RR") == 0) {
236 send_sctp_rr(host_name);
237 }
238 else if (strcasecmp(test_name, "SCTP_STREAM_MANY") == 0) {
239 send_sctp_stream_1toMany(host_name);
240 }
241 else if (strcasecmp(test_name, "SCTP_RR_MANY") == 0) {
242 send_sctp_stream_1toMany(host_name);
243 }
244#endif
245
246#ifdef DO_DNS
247 else if (strcasecmp(test_name,"DNS_RR") == 0) {
248 fprintf(stderr,
249 "DNS tests can now be found in netperf4.\n");
250 fflush(stderr);
251 exit(-1);
252 }
253#endif /* DO_DNS */
254#ifdef WANT_SDP
255 else if (strcasecmp(test_name,"SDP_STREAM") == 0) {
256 send_sdp_stream(host_name);
257 }
258 else if (strcasecmp(test_name,"SDP_MAERTS") == 0) {
259 send_sdp_maerts(host_name);
260 }
261 else if (strcasecmp(test_name,"SDP_RR") == 0) {
262 send_sdp_rr(host_name);
263 }
264#endif /* WANT_SDP */
265 else {
266 printf("The test you requested is unknown to this netperf.\n");
267 printf("Please verify that you have the correct test name, \n");
268 printf("and that test family has been compiled into this netperf.\n");
269 exit(1);
270 }
271
272 if (!no_control) {
273 shutdown_control();
274 }
275
276#ifdef WIN32
277 /* Cleanup the winsock lib */
278 WSACleanup();
279#endif
280
281 return(0);
282}
283
284