Annotation of embedaddon/iperf/src/iperf.h, revision 1.1
1.1 ! misho 1: /*
! 2: * iperf, Copyright (c) 2014, 2015, 2016, The Regents of the University of
! 3: * California, through Lawrence Berkeley National Laboratory (subject
! 4: * to receipt of any required approvals from the U.S. Dept. of
! 5: * Energy). All rights reserved.
! 6: *
! 7: * If you have questions about your rights to use or distribute this
! 8: * software, please contact Berkeley Lab's Technology Transfer
! 9: * Department at TTD@lbl.gov.
! 10: *
! 11: * NOTICE. This software is owned by the U.S. Department of Energy.
! 12: * As such, the U.S. Government has been granted for itself and others
! 13: * acting on its behalf a paid-up, nonexclusive, irrevocable,
! 14: * worldwide license in the Software to reproduce, prepare derivative
! 15: * works, and perform publicly and display publicly. Beginning five
! 16: * (5) years after the date permission to assert copyright is obtained
! 17: * from the U.S. Department of Energy, and subject to any subsequent
! 18: * five (5) year renewals, the U.S. Government is granted for itself
! 19: * and others acting on its behalf a paid-up, nonexclusive,
! 20: * irrevocable, worldwide license in the Software to reproduce,
! 21: * prepare derivative works, distribute copies to the public, perform
! 22: * publicly and display publicly, and to permit others to do so.
! 23: *
! 24: * This code is distributed under a BSD style license, see the LICENSE
! 25: * file for complete information.
! 26: */
! 27: #ifndef __IPERF_H
! 28: #define __IPERF_H
! 29:
! 30: #include "iperf_config.h"
! 31:
! 32: #include <sys/time.h>
! 33: #include <sys/types.h>
! 34: #ifdef HAVE_STDINT_H
! 35: #include <stdint.h>
! 36: #endif
! 37: #include <sys/select.h>
! 38: #include <sys/socket.h>
! 39: #include <netinet/tcp.h>
! 40:
! 41: #if defined(HAVE_CPUSET_SETAFFINITY)
! 42: #include <sys/param.h>
! 43: #include <sys/cpuset.h>
! 44: #endif /* HAVE_CPUSET_SETAFFINITY */
! 45:
! 46: #include "timer.h"
! 47: #include "queue.h"
! 48: #include "cjson.h"
! 49:
! 50: typedef uint64_t iperf_size_t;
! 51:
! 52: struct iperf_interval_results
! 53: {
! 54: iperf_size_t bytes_transferred; /* bytes transfered in this interval */
! 55: struct timeval interval_start_time;
! 56: struct timeval interval_end_time;
! 57: float interval_duration;
! 58:
! 59: /* for UDP */
! 60: int interval_packet_count;
! 61: int interval_outoforder_packets;
! 62: int interval_cnt_error;
! 63: int packet_count;
! 64: double jitter;
! 65: int outoforder_packets;
! 66: int cnt_error;
! 67:
! 68: int omitted;
! 69: #if (defined(linux) || defined(__FreeBSD__) || defined(__NetBSD__)) && \
! 70: defined(TCP_INFO)
! 71: struct tcp_info tcpInfo; /* getsockopt(TCP_INFO) for Linux, {Free,Net}BSD */
! 72: #else
! 73: /* Just placeholders, never accessed. */
! 74: char *tcpInfo;
! 75: #endif
! 76: int interval_retrans;
! 77: int interval_sacks;
! 78: int snd_cwnd;
! 79: TAILQ_ENTRY(iperf_interval_results) irlistentries;
! 80: void *custom_data;
! 81: int rtt;
! 82: };
! 83:
! 84: struct iperf_stream_result
! 85: {
! 86: iperf_size_t bytes_received;
! 87: iperf_size_t bytes_sent;
! 88: iperf_size_t bytes_received_this_interval;
! 89: iperf_size_t bytes_sent_this_interval;
! 90: iperf_size_t bytes_sent_omit;
! 91: int stream_prev_total_retrans;
! 92: int stream_retrans;
! 93: int stream_prev_total_sacks;
! 94: int stream_sacks;
! 95: int stream_max_rtt;
! 96: int stream_min_rtt;
! 97: int stream_sum_rtt;
! 98: int stream_count_rtt;
! 99: int stream_max_snd_cwnd;
! 100: struct timeval start_time;
! 101: struct timeval end_time;
! 102: struct timeval start_time_fixed;
! 103: TAILQ_HEAD(irlisthead, iperf_interval_results) interval_results;
! 104: void *data;
! 105: };
! 106:
! 107: #define COOKIE_SIZE 37 /* size of an ascii uuid */
! 108: struct iperf_settings
! 109: {
! 110: int domain; /* AF_INET or AF_INET6 */
! 111: int socket_bufsize; /* window size for TCP */
! 112: int blksize; /* size of read/writes (-l) */
! 113: uint64_t rate; /* target data rate */
! 114: int burst; /* packets per burst */
! 115: int mss; /* for TCP MSS */
! 116: int ttl; /* IP TTL option */
! 117: int tos; /* type of service bit */
! 118: int flowlabel; /* IPv6 flow label */
! 119: iperf_size_t bytes; /* number of bytes to send */
! 120: iperf_size_t blocks; /* number of blocks (packets) to send */
! 121: char unit_format; /* -f */
! 122: int num_ostreams; /* SCTP initmsg settings */
! 123: };
! 124:
! 125: struct iperf_test;
! 126:
! 127: struct iperf_stream
! 128: {
! 129: struct iperf_test* test;
! 130:
! 131: /* configurable members */
! 132: int local_port;
! 133: int remote_port;
! 134: int socket;
! 135: int id;
! 136: /* XXX: is settings just a pointer to the same struct in iperf_test? if not,
! 137: should it be? */
! 138: struct iperf_settings *settings; /* pointer to structure settings */
! 139:
! 140: /* non configurable members */
! 141: struct iperf_stream_result *result; /* structure pointer to result */
! 142: Timer *send_timer;
! 143: int green_light;
! 144: int buffer_fd; /* data to send, file descriptor */
! 145: char *buffer; /* data to send, mmapped */
! 146: int diskfile_fd; /* file to send, file descriptor */
! 147:
! 148: /*
! 149: * for udp measurements - This can be a structure outside stream, and
! 150: * stream can have a pointer to this
! 151: */
! 152: int packet_count;
! 153: int omitted_packet_count;
! 154: double jitter;
! 155: double prev_transit;
! 156: int outoforder_packets;
! 157: int omitted_outoforder_packets;
! 158: int cnt_error;
! 159: int omitted_cnt_error;
! 160: uint64_t target;
! 161:
! 162: struct sockaddr_storage local_addr;
! 163: struct sockaddr_storage remote_addr;
! 164:
! 165: int (*rcv) (struct iperf_stream * stream);
! 166: int (*snd) (struct iperf_stream * stream);
! 167:
! 168: /* chained send/receive routines for -F mode */
! 169: int (*rcv2) (struct iperf_stream * stream);
! 170: int (*snd2) (struct iperf_stream * stream);
! 171:
! 172: // struct iperf_stream *next;
! 173: SLIST_ENTRY(iperf_stream) streams;
! 174:
! 175: void *data;
! 176: };
! 177:
! 178: struct protocol {
! 179: int id;
! 180: char *name;
! 181: int (*accept)(struct iperf_test *);
! 182: int (*listen)(struct iperf_test *);
! 183: int (*connect)(struct iperf_test *);
! 184: int (*send)(struct iperf_stream *);
! 185: int (*recv)(struct iperf_stream *);
! 186: int (*init)(struct iperf_test *);
! 187: SLIST_ENTRY(protocol) protocols;
! 188: };
! 189:
! 190: struct iperf_textline {
! 191: char *line;
! 192: TAILQ_ENTRY(iperf_textline) textlineentries;
! 193: };
! 194:
! 195: struct xbind_entry {
! 196: char *name;
! 197: struct addrinfo *ai;
! 198: TAILQ_ENTRY(xbind_entry) link;
! 199: };
! 200:
! 201: struct iperf_test
! 202: {
! 203: char role; /* 'c' lient or 's' erver */
! 204: int sender; /* client & !reverse or server & reverse */
! 205: int sender_has_retransmits;
! 206: struct protocol *protocol;
! 207: signed char state;
! 208: char *server_hostname; /* -c option */
! 209: char *tmp_template;
! 210: char *bind_address; /* first -B option */
! 211: TAILQ_HEAD(xbind_addrhead, xbind_entry) xbind_addrs; /* all -X opts */
! 212: int bind_port; /* --cport option */
! 213: int server_port;
! 214: int omit; /* duration of omit period (-O flag) */
! 215: int duration; /* total duration of test (-t flag) */
! 216: char *diskfile_name; /* -F option */
! 217: int affinity, server_affinity; /* -A option */
! 218: #if defined(HAVE_CPUSET_SETAFFINITY)
! 219: cpuset_t cpumask;
! 220: #endif /* HAVE_CPUSET_SETAFFINITY */
! 221: char *title; /* -T option */
! 222: char *congestion; /* -C option */
! 223: char *pidfile; /* -P option */
! 224:
! 225: char *logfile; /* --logfile option */
! 226: FILE *outfile;
! 227:
! 228: int ctrl_sck;
! 229: int listener;
! 230: int prot_listener;
! 231:
! 232: /* boolean variables for Options */
! 233: int daemon; /* -D option */
! 234: int one_off; /* -1 option */
! 235: int no_delay; /* -N option */
! 236: int reverse; /* -R option */
! 237: int verbose; /* -V option - verbose mode */
! 238: int json_output; /* -J option - JSON output */
! 239: int zerocopy; /* -Z option - use sendfile */
! 240: int debug; /* -d option - enable debug */
! 241: int get_server_output; /* --get-server-output */
! 242: int udp_counters_64bit; /* --use-64-bit-udp-counters */
! 243: int no_fq_socket_pacing; /* --no-fq-socket-pacing */
! 244: int multisend;
! 245:
! 246: char *json_output_string; /* rendered JSON output if json_output is set */
! 247: /* Select related parameters */
! 248: int max_fd;
! 249: fd_set read_set; /* set of read sockets */
! 250: fd_set write_set; /* set of write sockets */
! 251:
! 252: /* Interval related members */
! 253: int omitting;
! 254: double stats_interval;
! 255: double reporter_interval;
! 256: void (*stats_callback) (struct iperf_test *);
! 257: void (*reporter_callback) (struct iperf_test *);
! 258: Timer *omit_timer;
! 259: Timer *timer;
! 260: int done;
! 261: Timer *stats_timer;
! 262: Timer *reporter_timer;
! 263:
! 264: double cpu_util[3]; /* cpu utilization of the test - total, user, system */
! 265: double remote_cpu_util[3]; /* cpu utilization for the remote host/client - total, user, system */
! 266:
! 267: int num_streams; /* total streams in the test (-P) */
! 268:
! 269: iperf_size_t bytes_sent;
! 270: iperf_size_t blocks_sent;
! 271: char cookie[COOKIE_SIZE];
! 272: // struct iperf_stream *streams; /* pointer to list of struct stream */
! 273: SLIST_HEAD(slisthead, iperf_stream) streams;
! 274: struct iperf_settings *settings;
! 275:
! 276: SLIST_HEAD(plisthead, protocol) protocols;
! 277:
! 278: /* callback functions */
! 279: void (*on_new_stream)(struct iperf_stream *);
! 280: void (*on_test_start)(struct iperf_test *);
! 281: void (*on_connect)(struct iperf_test *);
! 282: void (*on_test_finish)(struct iperf_test *);
! 283:
! 284: /* cJSON handles for use when in -J mode */\
! 285: cJSON *json_top;
! 286: cJSON *json_start;
! 287: cJSON *json_connected;
! 288: cJSON *json_intervals;
! 289: cJSON *json_end;
! 290:
! 291: /* Server output (use on client side only) */
! 292: char *server_output_text;
! 293: cJSON *json_server_output;
! 294:
! 295: /* Server output (use on server side only) */
! 296: TAILQ_HEAD(iperf_textlisthead, iperf_textline) server_output_list;
! 297:
! 298: };
! 299:
! 300: /* default settings */
! 301: #define PORT 5201 /* default port to listen on (don't use the same port as iperf2) */
! 302: #define uS_TO_NS 1000
! 303: #define SEC_TO_US 1000000LL
! 304: #define UDP_RATE (1024 * 1024) /* 1 Mbps */
! 305: #define OMIT 0 /* seconds */
! 306: #define DURATION 10 /* seconds */
! 307:
! 308: #define SEC_TO_NS 1000000000LL /* too big for enum/const on some platforms */
! 309: #define MAX_RESULT_STRING 4096
! 310:
! 311: /* constants for command line arg sanity checks */
! 312: #define MB (1024 * 1024)
! 313: #define MAX_TCP_BUFFER (512 * MB)
! 314: #define MAX_BLOCKSIZE MB
! 315: /* Maximum size UDP send is (64K - 1) - IP and UDP header sizes */
! 316: #define MAX_UDP_BLOCKSIZE (65535 - 8 - 20)
! 317: #define MIN_INTERVAL 0.1
! 318: #define MAX_INTERVAL 60.0
! 319: #define MAX_TIME 86400
! 320: #define MAX_BURST 1000
! 321: #define MAX_MSS (9 * 1024)
! 322: #define MAX_STREAMS 128
! 323:
! 324: #endif /* !__IPERF_H */
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>