• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1  /*
2  
3  	   Copyright (C) 1993-2011 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  */
44  char	netperf_id[]="\
45  @(#)netperf.c (c) Copyright 1993-2012 Hewlett-Packard Company. Version 2.6.0";
46  
47  #ifdef HAVE_CONFIG_H
48  #include "config.h"
49  #endif
50  
51  #include <stdio.h>
52  #include <stdlib.h>
53  #if HAVE_STRING_H
54  # if !STDC_HEADERS && HAVE_MEMORY_H
55  #  include <memory.h>
56  # endif
57  # include <string.h>
58  #endif
59  #ifdef HAVE_STRINGS_H
60  #include <strings.h>
61  #endif
62  
63  /* FreeBSD doesn't like socket.h before types are set. */
64  #if __FreeBSD__
65  # include <sys/types.h>
66  #endif
67  
68  #ifdef WIN32
69  #include <winsock2.h>
70  #include <windows.h>
71  #include "missing\stdint.h"
72  #endif /* WIN32 */
73  
74  #include "netsh.h"
75  #include "netlib.h"
76  #include "nettest_bsd.h"
77  
78  #ifdef WANT_UNIX
79  #include "nettest_unix.h"
80  #endif /* WANT_UNIX */
81  
82  #ifdef WANT_XTI
83  #include "nettest_xti.h"
84  #endif /* WANT_XTI */
85  
86  #ifdef WANT_DLPI
87  #include "nettest_dlpi.h"
88  #endif /* WANT_DLPI */
89  
90  #ifdef WANT_SDP
91  #include "nettest_sdp.h"
92  #endif
93  
94  /* The DNS tests have been removed from netperf2. Those wanting to do
95     DNS_RR tests should use netperf4 instead. */
96  
97  #ifdef DO_DNS
98  #error DNS tests have been removed from netperf. Use netperf4 instead
99  #endif /* DO_DNS */
100  
101  #ifdef WANT_SCTP
102  #include "nettest_sctp.h"
103  #endif
104  
105   /* this file contains the main for the netperf program. all the other
106      routines can be found in the file netsh.c */
107  
108  
109  int _cdecl
main(int argc,char * argv[])110  main(int argc, char *argv[])
111  {
112  
113  #ifdef WIN32
114    WSADATA	wsa_data ;
115  
116    /* Initialize the winsock lib ( version 2.2 ) */
117    if ( WSAStartup(MAKEWORD(2,2), &wsa_data) == SOCKET_ERROR ){
118      printf("WSAStartup() failed : %lu\n", GetLastError()) ;
119      return 1 ;
120    }
121  #endif /* WIN32 */
122  
123    netlib_init();
124    /* the call to set_defaults() is gone because we can initialize in
125       declarations (or is that definitions) unlike the old days */
126    scan_cmd_line(argc,argv);
127  
128    if (debug) {
129      dump_globals();
130      install_signal_catchers();
131    }
132  
133    if (debug) {
134      printf("remotehost is %s and port %s\n",host_name,test_port);
135      fflush(stdout);
136    }
137  
138  
139    if (!no_control) {
140      establish_control(host_name,test_port,address_family,
141  		      local_host_name,local_test_port,local_address_family);
142  
143      if (passphrase != NULL) {
144        netperf_request.content.request_type = PASSPHRASE;
145        strncpy((char *)netperf_request.content.test_specific_data,
146  	      passphrase,
147  	      sizeof(netperf_request.content.test_specific_data));
148        send_request_n(0);
149      }
150    }
151  
152    if (strcasecmp(test_name,"TCP_STREAM") == 0) {
153      send_tcp_stream(host_name);
154    }
155    else if (strcasecmp(test_name,"TCP_MAERTS") == 0) {
156      send_tcp_maerts(host_name);
157    }
158    else if (strcasecmp(test_name,"TCP_MSS") == 0) {
159      send_tcp_mss(host_name);
160    }
161  #ifdef HAVE_ICSC_EXS
162    else if (strcasecmp(test_name,"EXS_TCP_STREAM") == 0) {
163      send_exs_tcp_stream(host_name);
164    }
165  #endif /* HAVE_ICSC_EXS */
166  #ifdef HAVE_SENDFILE
167    else if (strcasecmp(test_name,"TCP_SENDFILE") == 0) {
168      sendfile_tcp_stream(host_name);
169    }
170  #endif /* HAVE_SENDFILE */
171    else if (strcasecmp(test_name,"TCP_RR") == 0) {
172      send_tcp_rr(host_name);
173    }
174    else if (strcasecmp(test_name,"TCP_CRR") == 0) {
175      send_tcp_conn_rr(host_name);
176    }
177    else if (strcasecmp(test_name,"TCP_CC") == 0) {
178      send_tcp_cc(host_name);
179    }
180  #ifdef DO_1644
181    else if (strcasecmp(test_name,"TCP_TRR") == 0) {
182      send_tcp_tran_rr(host_name);
183    }
184  #endif /* DO_1644 */
185  #ifdef DO_NBRR
186    else if (strcasecmp(test_name,"TCP_NBRR") == 0) {
187      send_tcp_nbrr(host_name);
188    }
189  #endif /* DO_NBRR */
190    else if (strcasecmp(test_name,"UDP_STREAM") == 0) {
191      send_udp_stream(host_name);
192    }
193    else if (strcasecmp(test_name,"UDP_RR") == 0) {
194      send_udp_rr(host_name);
195    }
196    else if (strcasecmp(test_name,"LOC_CPU") == 0) {
197      loc_cpu_rate();
198    }
199    else if (strcasecmp(test_name,"REM_CPU") == 0) {
200      rem_cpu_rate();
201    }
202  #ifdef WANT_DLPI
203    else if (strcasecmp(test_name,"DLCO_RR") == 0) {
204      send_dlpi_co_rr(host_name);
205    }
206    else if (strcasecmp(test_name,"DLCL_RR") == 0) {
207      send_dlpi_cl_rr(host_name);
208    }
209    else if (strcasecmp(test_name,"DLCO_STREAM") == 0) {
210      send_dlpi_co_stream(host_name);
211    }
212    else if (strcasecmp(test_name,"DLCL_STREAM") == 0) {
213      send_dlpi_cl_stream(host_name);
214    }
215  #endif /* WANT_DLPI */
216  #ifdef WANT_UNIX
217    else if (strcasecmp(test_name,"STREAM_RR") == 0) {
218      send_stream_rr(host_name);
219    }
220    else if (strcasecmp(test_name,"DG_RR") == 0) {
221      send_dg_rr(host_name);
222    }
223    else if (strcasecmp(test_name,"STREAM_STREAM") == 0) {
224      send_stream_stream(host_name);
225    }
226    else if (strcasecmp(test_name,"DG_STREAM") == 0) {
227      send_dg_stream(host_name);
228    }
229  #endif /* WANT_UNIX */
230  #ifdef WANT_XTI
231    else if (strcasecmp(test_name,"XTI_TCP_STREAM") == 0) {
232      send_xti_tcp_stream(host_name);
233    }
234    else if (strcasecmp(test_name,"XTI_TCP_RR") == 0) {
235      send_xti_tcp_rr(host_name);
236    }
237    else if (strcasecmp(test_name,"XTI_UDP_STREAM") == 0) {
238      send_xti_udp_stream(host_name);
239    }
240    else if (strcasecmp(test_name,"XTI_UDP_RR") == 0) {
241      send_xti_udp_rr(host_name);
242    }
243  #endif /* WANT_XTI */
244  
245  #ifdef WANT_SCTP
246    else if (strcasecmp(test_name, "SCTP_STREAM") == 0) {
247      send_sctp_stream(host_name);
248    }
249    else if (strcasecmp(test_name, "SCTP_RR") == 0) {
250      send_sctp_rr(host_name);
251    }
252    else if (strcasecmp(test_name, "SCTP_STREAM_MANY") == 0) {
253      send_sctp_stream_1toMany(host_name);
254    }
255    else if (strcasecmp(test_name, "SCTP_RR_MANY") == 0) {
256      send_sctp_rr_1toMany(host_name);
257    }
258  #endif
259  
260  #ifdef DO_DNS
261    else if (strcasecmp(test_name,"DNS_RR") == 0) {
262      fprintf(stderr,
263  	  "DNS tests can now be found in netperf4.\n");
264      fflush(stderr);
265      exit(-1);
266    }
267  #endif /* DO_DNS */
268  #ifdef WANT_SDP
269    else if (strcasecmp(test_name,"SDP_STREAM") == 0) {
270      send_sdp_stream(host_name);
271    }
272    else if (strcasecmp(test_name,"SDP_MAERTS") == 0) {
273      send_sdp_maerts(host_name);
274    }
275    else if (strcasecmp(test_name,"SDP_RR") == 0) {
276      send_sdp_rr(host_name);
277    }
278  #endif /* WANT_SDP */
279  #ifdef WANT_OMNI
280    else if (strcasecmp(test_name,"OMNI") == 0) {
281      send_omni(host_name);
282    }
283    else if (strcasecmp(test_name,"UUID") == 0) {
284      print_uuid(host_name);
285    }
286  #endif
287    else {
288      printf("The test you requested (%s) is unknown to this netperf.\n"
289  	   "Please verify that you have the correct test name, \n"
290  	   "and that test family has been compiled into this netperf.\n",
291  	   test_name);
292      exit(1);
293    }
294  
295    if (!no_control) {
296      shutdown_control();
297    }
298  
299  #ifdef WIN32
300    /* Cleanup the winsock lib */
301    WSACleanup();
302  #endif
303  
304    return(0);
305  }
306  
307  
308