PageRenderTime 27ms CodeModel.GetById 23ms RepoModel.GetById 0ms app.codeStats 1ms

/external/netperf/netlib.h

https://gitlab.com/brian0218/rk3188_r-box_android4.2.2_sdk
C Header | 621 lines | 431 code | 108 blank | 82 comment | 20 complexity | 25e430e63837d5b8f22778416580f812 MD5 | raw file
  1. /*
  2. Copyright (C) 1993-2005 Hewlett-Packard Company
  3. */
  4. #ifdef HAVE_CONFIG_H
  5. #include "config.h"
  6. #endif
  7. #if defined(HAVE_SYS_SOCKET_H)
  8. # include <sys/socket.h>
  9. #endif
  10. #if defined(HAVE_NETDB_H)
  11. # include <netdb.h>
  12. #endif
  13. #if !defined(HAVE_GETADDRINFO) || !defined(HAVE_GETNAMEINFO)
  14. # include "missing/getaddrinfo.h"
  15. #endif
  16. #define PAD_TIME 4
  17. /* library routine specifc defines */
  18. #define MAXSPECDATA 62 /* how many ints worth of data */
  19. /* can tests send... */
  20. #define MAXTIMES 4 /* how many times may we loop */
  21. /* to calibrate */
  22. #define MAXCPUS 256 /* how many CPU's can we track */
  23. #define MAXMESSAGESIZE 65536
  24. #define MAXALIGNMENT 16384
  25. #define MAXOFFSET 4096
  26. #define DATABUFFERLEN MAXMESSAGESIZE+MAXALIGNMENT+MAXOFFSET
  27. #define DEBUG_ON 1
  28. #define DEBUG_OFF 2
  29. #define DEBUG_OK 3
  30. #define NODE_IDENTIFY 4
  31. #define CPU_CALIBRATE 5
  32. #define DO_TCP_STREAM 10
  33. #define TCP_STREAM_RESPONSE 11
  34. #define TCP_STREAM_RESULTS 12
  35. #define DO_TCP_RR 13
  36. #define TCP_RR_RESPONSE 14
  37. #define TCP_RR_RESULTS 15
  38. #define DO_UDP_STREAM 16
  39. #define UDP_STREAM_RESPONSE 17
  40. #define UDP_STREAM_RESULTS 18
  41. #define DO_UDP_RR 19
  42. #define UDP_RR_RESPONSE 20
  43. #define UDP_RR_RESULTS 21
  44. #define DO_DLPI_CO_STREAM 22
  45. #define DLPI_CO_STREAM_RESPONSE 23
  46. #define DLPI_CO_STREAM_RESULTS 24
  47. #define DO_DLPI_CO_RR 25
  48. #define DLPI_CO_RR_RESPONSE 26
  49. #define DLPI_CO_RR_RESULTS 27
  50. #define DO_DLPI_CL_STREAM 28
  51. #define DLPI_CL_STREAM_RESPONSE 29
  52. #define DLPI_CL_STREAM_RESULTS 30
  53. #define DO_DLPI_CL_RR 31
  54. #define DLPI_CL_RR_RESPONSE 32
  55. #define DLPI_CL_RR_RESULTS 33
  56. #define DO_TCP_CRR 34
  57. #define TCP_CRR_RESPONSE 35
  58. #define TCP_CRR_RESULTS 36
  59. #define DO_STREAM_STREAM 37
  60. #define STREAM_STREAM_RESPONSE 38
  61. #define STREAM_STREAM_RESULTS 39
  62. #define DO_STREAM_RR 40
  63. #define STREAM_RR_RESPONSE 41
  64. #define STREAM_RR_RESULTS 42
  65. #define DO_DG_STREAM 43
  66. #define DG_STREAM_RESPONSE 44
  67. #define DG_STREAM_RESULTS 45
  68. #define DO_DG_RR 46
  69. #define DG_RR_RESPONSE 47
  70. #define DG_RR_RESULTS 48
  71. #define DO_FORE_STREAM 49
  72. #define FORE_STREAM_RESPONSE 50
  73. #define FORE_STREAM_RESULTS 51
  74. #define DO_FORE_RR 52
  75. #define FORE_RR_RESPONSE 53
  76. #define FORE_RR_RESULTS 54
  77. #define DO_HIPPI_STREAM 55
  78. #define HIPPI_STREAM_RESPONSE 56
  79. #define HIPPI_STREAM_RESULTS 57
  80. #define DO_HIPPI_RR 52
  81. #define HIPPI_RR_RESPONSE 53
  82. #define HIPPI_RR_RESULTS 54
  83. #define DO_XTI_TCP_STREAM 55
  84. #define XTI_TCP_STREAM_RESPONSE 56
  85. #define XTI_TCP_STREAM_RESULTS 57
  86. #define DO_XTI_TCP_RR 58
  87. #define XTI_TCP_RR_RESPONSE 59
  88. #define XTI_TCP_RR_RESULTS 60
  89. #define DO_XTI_UDP_STREAM 61
  90. #define XTI_UDP_STREAM_RESPONSE 62
  91. #define XTI_UDP_STREAM_RESULTS 63
  92. #define DO_XTI_UDP_RR 64
  93. #define XTI_UDP_RR_RESPONSE 65
  94. #define XTI_UDP_RR_RESULTS 66
  95. #define DO_XTI_TCP_CRR 67
  96. #define XTI_TCP_CRR_RESPONSE 68
  97. #define XTI_TCP_CRR_RESULTS 69
  98. #define DO_TCP_TRR 70
  99. #define TCP_TRR_RESPONSE 71
  100. #define TCP_TRR_RESULTS 72
  101. #define DO_TCP_NBRR 73
  102. #define TCP_NBRR_RESPONSE 74
  103. #define TCP_NBRR_RESULTS 75
  104. #define DO_TCPIPV6_STREAM 76
  105. #define TCPIPV6_STREAM_RESPONSE 77
  106. #define TCPIPV6_STREAM_RESULTS 78
  107. #define DO_TCPIPV6_RR 79
  108. #define TCPIPV6_RR_RESPONSE 80
  109. #define TCPIPV6_RR_RESULTS 81
  110. #define DO_UDPIPV6_STREAM 82
  111. #define UDPIPV6_STREAM_RESPONSE 83
  112. #define UDPIPV6_STREAM_RESULTS 84
  113. #define DO_UDPIPV6_RR 85
  114. #define UDPIPV6_RR_RESPONSE 86
  115. #define UDPIPV6_RR_RESULTS 87
  116. #define DO_TCPIPV6_CRR 88
  117. #define TCPIPV6_CRR_RESPONSE 89
  118. #define TCPIPV6_CRR_RESULTS 90
  119. #define DO_TCPIPV6_TRR 91
  120. #define TCPIPV6_TRR_RESPONSE 92
  121. #define TCPIPV6_TRR_RESULTS 93
  122. #define DO_TCP_MAERTS 94
  123. #define TCP_MAERTS_RESPONSE 95
  124. #define TCP_MAERTS_RESULTS 96
  125. #define DO_LWPSTR_STREAM 100
  126. #define LWPSTR_STREAM_RESPONSE 110
  127. #define LWPSTR_STREAM_RESULTS 120
  128. #define DO_LWPSTR_RR 130
  129. #define LWPSTR_RR_RESPONSE 140
  130. #define LWPSTR_RR_RESULTS 150
  131. #define DO_LWPDG_STREAM 160
  132. #define LWPDG_STREAM_RESPONSE 170
  133. #define LWPDG_STREAM_RESULTS 180
  134. #define DO_LWPDG_RR 190
  135. #define LWPDG_RR_RESPONSE 200
  136. #define LWPDG_RR_RESULTS 210
  137. #define DO_TCP_CC 300
  138. #define TCP_CC_RESPONSE 301
  139. #define TCP_CC_RESULTS 302
  140. /* The DNS_RR test has been removed from netperf but we leave these
  141. here for historical purposes. Those wanting to do DNS_RR tests
  142. should use netperf4 instead. */
  143. #define DO_DNS_RR 400
  144. #define DNS_RR_RESPONSE 401
  145. #define DNS_RR_RESULTS 402
  146. #define DO_SCTP_STREAM 500
  147. #define SCTP_STREAM_RESPONSE 501
  148. #define SCTP_STREAM_RESULT 502
  149. #define DO_SCTP_STREAM_MANY 510
  150. #define SCTP_STREAM_MANY_RESPONSE 511
  151. #define SCTP_STREAM_MANY_RESULT 512
  152. #define DO_SCTP_RR 520
  153. #define SCTP_RR_RESPONSE 521
  154. #define SCTP_RR_RESULT 502
  155. #define DO_SCTP_RR_MANY 530
  156. #define SCTP_RR_MANY_RESPONSE 531
  157. #define SCTP_RR_MANY_RESULT 532
  158. #define DO_SDP_STREAM 540
  159. #define SDP_STREAM_RESPONSE 541
  160. #define SDP_STREAM_RESULTS 542
  161. #define DO_SDP_RR 543
  162. #define SDP_RR_RESPONSE 544
  163. #define SDP_RR_RESULTS 545
  164. #define DO_SDP_MAERTS 546
  165. #define SDP_MAERTS_RESPONSE 547
  166. #define SDP_MAERTS_RESULTS 548
  167. #define DO_SDP_CRR 549
  168. #define SDP_CRR_RESPONSE 550
  169. #define SDP_CRR_RESULTS 551
  170. #define DO_SDP_CC 552
  171. #define SDP_CC_RESPONSE 553
  172. #define SDP_CC_RESULTS 554
  173. #if HAVE_INTTYPES_H
  174. # include <inttypes.h>
  175. #else
  176. # if HAVE_STDINT_H
  177. # include <stdint.h>
  178. # endif
  179. #endif
  180. enum sock_buffer{
  181. SEND_BUFFER,
  182. RECV_BUFFER
  183. };
  184. /* some of the fields in these structures are going to be doubles and */
  185. /* such. so, we probably want to ensure that they will start on */
  186. /* "double" boundaries. this will break compatability to pre-2.1 */
  187. /* releases, but then, backwards compatability has never been a */
  188. /* stated goal of netperf. raj 11/95 */
  189. union netperf_request_struct {
  190. struct {
  191. int request_type;
  192. int dummy;
  193. int test_specific_data[MAXSPECDATA];
  194. } content;
  195. double dummy;
  196. };
  197. union netperf_response_struct {
  198. struct {
  199. int response_type;
  200. int serv_errno;
  201. int test_specific_data[MAXSPECDATA];
  202. } content;
  203. double dummy;
  204. };
  205. struct ring_elt {
  206. struct ring_elt *next; /* next element in the ring */
  207. char *buffer_base; /* in case we have to free it at somepoint */
  208. char *buffer_ptr; /* the aligned and offset pointer */
  209. };
  210. /* +*+ SAF Sorry about the hacks with errno; NT made me do it :(
  211. WinNT does define an errno.
  212. It is mostly a legacy from the XENIX days.
  213. Depending upon the version of the C run time that is linked in, it is
  214. either a simple variable (like UNIX code expects), but more likely it
  215. is the address of a procedure to return the error number. So any
  216. code that sets errno is likely to be overwriting the address of this
  217. procedure. Worse, only a tiny fraction of NT's errors get set
  218. through errno.
  219. So I have changed the netperf code to use a define Set_errno when
  220. that is it's intent. On non-windows platforms this is just an
  221. assignment to errno. But on NT this calls SetLastError.
  222. I also define errno (now only used on right side of assignments)
  223. on NT to be GetLastError.
  224. Similarly, perror is defined on NT, but it only accesses the same
  225. XENIX errors that errno covers. So on NT this is redefined to be
  226. Perror and it expands all GetLastError texts. */
  227. #ifdef WIN32
  228. /* INVALID_SOCKET == INVALID_HANDLE_VALUE == (unsigned int)(~0) */
  229. /* SOCKET_ERROR == -1 */
  230. #define ENOTSOCK WSAENOTSOCK
  231. #define EINTR WSAEINTR
  232. #define ENOBUFS WSAENOBUFS
  233. #define EWOULDBLOCK WSAEWOULDBLOCK
  234. #define EAFNOSUPPORT WSAEAFNOSUPPORT
  235. /* I don't use a C++ style of comment because it upsets some C
  236. compilers, possibly even when it is inside an ifdef WIN32... */
  237. /* from public\sdk\inc\crt\errno.h */
  238. #define ENOSPC 28
  239. #ifdef errno
  240. /* delete the one from stdlib.h */
  241. /*#define errno (*_errno()) */
  242. #undef errno
  243. #endif
  244. #define errno GetLastError()
  245. #define Set_errno(num) SetLastError((num))
  246. #define perror(text) PrintWin32Error(stderr, (text))
  247. #define Print_errno(stream, text) PrintWin32Error((stream), (text))
  248. extern void PrintWin32Error(FILE *stream, LPSTR text);
  249. #if !defined(NT_PERF) && !defined(USE_LOOPER)
  250. #define NT_PERF
  251. #endif
  252. #else
  253. /* Really shouldn't use manifest constants! */
  254. /*+*+SAF There are other examples of "== -1" and "<0" that probably */
  255. /*+*+SAF should be cleaned up as well. */
  256. #define INVALID_SOCKET -1
  257. #define SOCKET_ERROR -1
  258. #define SOCKET int
  259. #define Set_errno(num) errno = (num)
  260. #define Print_errno(stream, text) fprintf((stream), "%s errno %d\n", (text), errno)
  261. #endif
  262. /* Robin & Rick's kludge to try to have a timer signal EINTR by closing */
  263. /* the socket from another thread can also return several other errors. */
  264. /* Let's define a macro to hide all of this. */
  265. #ifndef WIN32
  266. #define SOCKET_EINTR(return_value) (errno == EINTR)
  267. #define SOCKET_EADDRINUSE(return_value) (errno == EADDRINUSE)
  268. #define SOCKET_EADDRNOTAVAIL(return_value) (errno == EADDRNOTAVAIL)
  269. #else
  270. /* not quite sure I like the extra cases for WIN32 but that is what my
  271. WIN32 expert sugested. I'm not sure what WSA's to put for
  272. EADDRINUSE */
  273. #define SOCKET_EINTR(return_value) \
  274. (((return_value) == SOCKET_ERROR) && \
  275. ((errno == EINTR) || \
  276. (errno == WSAECONNABORTED) || \
  277. (errno == WSAECONNRESET) ))
  278. #define SOCKET_EADDRINUSE(return_value) \
  279. (((return_value) == SOCKET_ERROR) && \
  280. ((errno == WSAEADDRINUSE) ))
  281. #define SOCKET_EADDRNOTAVAIL(return_value) \
  282. (((return_value) == SOCKET_ERROR) && \
  283. ((errno == WSAEADDRNOTAVAIL) ))
  284. #endif
  285. #ifdef HAVE_SENDFILE
  286. struct sendfile_ring_elt {
  287. struct sendfile_ring_elt *next; /* next element in the ring */
  288. int fildes; /* the file descriptor of the source
  289. file */
  290. off_t offset; /* the offset from the beginning of
  291. the file for this send */
  292. size_t length; /* the number of bytes to send -
  293. this is redundant with the
  294. send_size variable but I decided
  295. to include it anyway */
  296. struct iovec *hdtrl; /* a pointer to a header/trailer
  297. that we do not initially use and
  298. so should be set to NULL when the
  299. ring is setup. */
  300. int flags; /* the flags to pass to sendfile() -
  301. presently unused and should be
  302. set to zero when the ring is
  303. setup. */
  304. };
  305. #endif /* HAVE_SENDFILE */
  306. /* the diferent codes to denote the type of CPU utilization */
  307. /* methods used */
  308. #define CPU_UNKNOWN 0
  309. #define HP_IDLE_COUNTER 1
  310. #define PSTAT 2
  311. #define TIMES 3
  312. #define LOOPER 4
  313. #define GETRUSAGE 5
  314. #define NT_METHOD 6
  315. #define KSTAT 7
  316. #define PROC_STAT 8
  317. #define SYSCTL 9
  318. #define PERFSTAT 10
  319. #define KSTAT_10 11
  320. #define OSX 12
  321. #define BADCH ('?')
  322. #ifndef NETLIB
  323. #ifdef WIN32
  324. #ifndef _GETOPT_
  325. #define _GETOPT_
  326. int getopt(int argc, char **argv, char *optstring);
  327. extern char *optarg; /* returned arg to go with this option */
  328. extern int optind; /* index to next argv element to process */
  329. extern int opterr; /* should error messages be printed? */
  330. extern int optopt; /* */
  331. #endif /* _GETOPT_ */
  332. extern SOCKET win_kludge_socket, win_kludge_socket2;
  333. #endif /* WIN32 */
  334. extern int local_proc_affinity, remote_proc_affinity;
  335. /* these are to allow netperf to be run easily through those evil,
  336. end-to-end breaking things known as firewalls */
  337. extern char local_data_port[10];
  338. extern char remote_data_port[10];
  339. extern char *local_data_address;
  340. extern char *remote_data_address;
  341. extern int local_data_family;
  342. extern int remote_data_family;
  343. extern union netperf_request_struct netperf_request;
  344. extern union netperf_response_struct netperf_response;
  345. extern float lib_local_cpu_util;
  346. extern float lib_elapsed;
  347. extern float lib_local_maxrate;
  348. extern char libfmt;
  349. extern int cpu_method;
  350. extern int lib_num_loc_cpus;
  351. extern int lib_num_rem_cpus;
  352. extern SOCKET server_sock;
  353. extern int times_up;
  354. extern FILE *where;
  355. extern int loops_per_msec;
  356. extern float lib_local_per_cpu_util[];
  357. extern void netlib_init();
  358. extern int netlib_get_page_size();
  359. extern void install_signal_catchers();
  360. extern void establish_control(char hostname[],
  361. char port[],
  362. int af,
  363. char local_hostname[],
  364. char local_port[],
  365. int local_af);
  366. extern void shutdown_control();
  367. extern void init_stat();
  368. extern void send_request();
  369. extern void recv_response();
  370. extern void send_response();
  371. extern void recv_request();
  372. extern void dump_request();
  373. extern void dump_addrinfo(FILE *dumploc, struct addrinfo *info,
  374. char *host, char *port, int family);
  375. extern void start_timer(int time);
  376. extern void stop_timer();
  377. extern void cpu_start(int measure_cpu);
  378. extern void cpu_stop(int measure_cpu, float *elapsed);
  379. extern void calculate_confidence(int confidence_iterations,
  380. float time,
  381. double result,
  382. float loc_cpu,
  383. float rem_cpu,
  384. float loc_sd,
  385. float rem_sd);
  386. extern void retrieve_confident_values(float *elapsed_time,
  387. double *thruput,
  388. float *local_cpu_utilization,
  389. float *remote_cpu_utilization,
  390. float *local_service_demand,
  391. float *remote_service_demand);
  392. extern void display_confidence();
  393. extern void set_sock_buffer(SOCKET sd,
  394. enum sock_buffer which,
  395. int requested_size,
  396. int *effective_sizep);
  397. extern char *format_units();
  398. extern char *inet_ftos(int family);
  399. extern char *inet_ttos(int type);
  400. extern char *inet_ptos(int protocol);
  401. extern double ntohd(double net_double);
  402. extern double htond(double host_double);
  403. extern int inet_nton(int af, const void *src, char *dst, int cnt);
  404. extern void libmain();
  405. extern double calc_thruput(double units_received);
  406. extern double calc_thruput_interval(double units_received,double elapsed);
  407. extern double calc_thruput_omni(double units_received);
  408. extern double calc_thruput_interval_omni(double units_received,double elapsed);
  409. extern float calibrate_local_cpu(float local_cpu_rate);
  410. extern float calibrate_remote_cpu();
  411. extern void bind_to_specific_processor(int processor_affinity,int use_cpu_map);
  412. extern int set_nonblock (SOCKET sock);
  413. #ifndef WIN32
  414. /* WIN32 requires that at least one of the file sets to select be
  415. non-null. Since msec_sleep routine is only called by nettest_dlpi &
  416. nettest_unix, let's duck this issue. */
  417. extern int msec_sleep( int msecs );
  418. #endif /* WIN32 */
  419. extern float calc_cpu_util(float elapsed_time);
  420. extern float calc_service_demand(double units_sent,
  421. float elapsed_time,
  422. float cpu_utilization,
  423. int num_cpus);
  424. extern float calc_service_demand_trans(double units_sent,
  425. float elapsed_time,
  426. float cpu_utilization,
  427. int num_cpus);
  428. #if defined(__hpux)
  429. extern void catcher(int, siginfo_t *,void *);
  430. #else
  431. extern void catcher(int);
  432. #endif /* __hpux */
  433. extern struct ring_elt *allocate_buffer_ring();
  434. extern void access_buffer(char *buffer_ptr,
  435. int length,
  436. int dirty_count,
  437. int clean_count);
  438. #ifdef HAVE_ICSC_EXS
  439. extern struct ring_elt *allocate_exs_buffer_ring();
  440. #endif /* HAVE_ICSC_EXS */
  441. #ifdef HAVE_SENDFILE
  442. extern struct sendfile_ring_elt *alloc_sendfile_buf_ring();
  443. #endif /* HAVE_SENDFILE */
  444. #ifdef WANT_DLPI
  445. /* it seems that AIX in its finite wisdom has some bogus define in an
  446. include file which defines "rem_addr" which then screws-up this extern
  447. unless we change the names to protect the guilty. reported by Eric
  448. Jones */
  449. extern int dl_connect(int fd, unsigned char *remote_addr, int remote_addr_len);
  450. extern int dl_bind(int fd, int sap, int mode, char *dlsap_ptr, int *dlsap_len);
  451. extern int dl_open(char devfile[], int ppa);
  452. #endif /* WANT_DLPI */
  453. extern char format_cpu_method(int method);
  454. extern unsigned int convert(char *string);
  455. extern unsigned int convert_timespec(char *string);
  456. #ifdef WANT_INTERVALS
  457. extern void start_itimer(unsigned int interval_len_msec);
  458. #endif
  459. /* these are all for the confidence interval stuff */
  460. extern double confidence;
  461. #endif
  462. #ifdef WIN32
  463. #define close(x) closesocket(x)
  464. #define strcasecmp(a,b) _stricmp(a,b)
  465. #define getpid() ((int)GetCurrentProcessId())
  466. #endif
  467. #ifdef WIN32
  468. #if 0
  469. /* Should really use safe string functions; but not for now... */
  470. #include <strsafe.h>
  471. /* Microsoft has deprecated _snprintf; it isn't guarenteed to null terminate the result buffer. */
  472. /* They want us to call StringCbPrintf instead; it always null terminates the string. */
  473. #endif
  474. #define snprintf _snprintf
  475. #endif
  476. /* Define a macro to align a buffer with an offset from a power of 2
  477. boundary. */
  478. #ifndef WIN32
  479. #define ULONG_PTR unsigned long
  480. #endif
  481. #define ALIGN_BUFFER(BufPtr, Align, Offset) \
  482. (char *)(( (ULONG_PTR)(BufPtr) + \
  483. (ULONG_PTR) (Align) -1) & \
  484. ~((ULONG_PTR) (Align) - 1)) + (ULONG_PTR)(Offset)
  485. /* if your system has bcopy and bzero, include it here, otherwise, we */
  486. /* will try to use memcpy aand memset. fix from Bruce Barnett @ GE. */
  487. #if defined(hpux) || defined (__VMS)
  488. #define HAVE_BCOPY
  489. #define HAVE_BZERO
  490. #endif
  491. #ifdef WIN32
  492. #define HAVE_MIN
  493. #else
  494. #define _stdcall
  495. #define _cdecl
  496. #endif
  497. #ifndef HAVE_BCOPY
  498. #define bcopy(s,d,h) memcpy((d),(s),(h))
  499. #endif /* HAVE_BCOPY */
  500. #ifndef HAVE_BZERO
  501. #define bzero(p,h) memset((p),0,(h))
  502. #endif /* HAVE_BZERO */
  503. #ifndef HAVE_MIN
  504. #define min(a,b) ((a < b) ? a : b)
  505. #endif /* HAVE_MIN */
  506. #ifdef USE_PERFSTAT
  507. # include <libperfstat.h>
  508. #endif