1 /* 2 * Copyright (c) 2009-2011, The Regents of the University of California, 3 * through Lawrence Berkeley National Laboratory (subject to receipt of any 4 * required approvals from the U.S. Dept. of Energy). All rights reserved. 5 * 6 * This code is distributed under a BSD style license, see the LICENSE file 7 * for complete information. 8 */ 9 10 #ifndef __IPERF_H 11 #define __IPERF_H 12 13 #include <sys/time.h> 14 #include <sys/types.h> 15 #include <stdint.h> 16 #include <sys/socket.h> 17 #include <netinet/tcp.h> 18 #include "timer.h" 19 #include "queue.h" 20 #include "cjson.h" 21 22 typedef uint64_t iperf_size_t; 23 24 struct iperf_interval_results 25 { 26 iperf_size_t bytes_transferred; /* bytes transfered in this interval */ 27 struct timeval interval_start_time; 28 struct timeval interval_end_time; 29 float interval_duration; 30 int omitted; 31 #if defined(linux) || defined(__FreeBSD__) 32 struct tcp_info tcpInfo; /* getsockopt(TCP_INFO) for Linux and FreeBSD */ 33 #else 34 /* Just placeholders, never accessed. */ 35 char *tcpInfo; 36 #endif 37 int interval_retrans; 38 TAILQ_ENTRY(iperf_interval_results) irlistentries; 39 void *custom_data; 40 }; 41 42 struct iperf_stream_result 43 { 44 iperf_size_t bytes_received; 45 iperf_size_t bytes_sent; 46 iperf_size_t bytes_received_this_interval; 47 iperf_size_t bytes_sent_this_interval; 48 int stream_prev_total_retrans; 49 int stream_retrans; 50 struct timeval start_time; 51 struct timeval end_time; 52 TAILQ_HEAD(irlisthead, iperf_interval_results) interval_results; 53 void *data; 54 }; 55 56 #define COOKIE_SIZE 37 /* size of an ascii uuid */ 57 struct iperf_settings 58 { 59 int domain; /* AF_INET or AF_INET6 */ 60 int socket_bufsize; /* window size for TCP */ 61 int blksize; /* size of read/writes (-l) */ 62 uint64_t rate; /* target data rate, UDP only */ 63 int mss; /* for TCP MSS */ 64 int ttl; /* IP TTL option */ 65 int tos; /* type of service bit */ 66 int flowlabel; /* IPv6 flow label */ 67 iperf_size_t bytes; /* number of bytes to send */ 68 char unit_format; /* -f */ 69 }; 70 71 struct iperf_test; 72 73 struct iperf_stream 74 { 75 struct iperf_test* test; 76 77 /* configurable members */ 78 int local_port; 79 int remote_port; 80 int socket; 81 int id; 82 /* XXX: is settings just a pointer to the same struct in iperf_test? if not, 83 should it be? */ 84 struct iperf_settings *settings; /* pointer to structure settings */ 85 86 /* non configurable members */ 87 struct iperf_stream_result *result; /* structure pointer to result */ 88 Timer *send_timer; 89 int green_light; 90 int buffer_fd; /* data to send, file descriptor */ 91 char *buffer; /* data to send, mmapped */ 92 int diskfile_fd; /* file to send, file descriptor */ 93 94 /* 95 * for udp measurements - This can be a structure outside stream, and 96 * stream can have a pointer to this 97 */ 98 int packet_count; 99 int omitted_packet_count; 100 double jitter; 101 double prev_transit; 102 int outoforder_packets; 103 int cnt_error; 104 uint64_t target; 105 106 struct sockaddr_storage local_addr; 107 struct sockaddr_storage remote_addr; 108 109 int (*rcv) (struct iperf_stream * stream); 110 int (*snd) (struct iperf_stream * stream); 111 112 /* chained send/receive routines for -F mode */ 113 int (*rcv2) (struct iperf_stream * stream); 114 int (*snd2) (struct iperf_stream * stream); 115 116 // struct iperf_stream *next; 117 SLIST_ENTRY(iperf_stream) streams; 118 119 void *data; 120 }; 121 122 struct protocol { 123 int id; 124 char *name; 125 int (*accept)(struct iperf_test *); 126 int (*listen)(struct iperf_test *); 127 int (*connect)(struct iperf_test *); 128 int (*send)(struct iperf_stream *); 129 int (*recv)(struct iperf_stream *); 130 int (*init)(struct iperf_test *); 131 SLIST_ENTRY(protocol) protocols; 132 }; 133 134 struct iperf_test 135 { 136 char role; /* 'c' lient or 's' erver */ 137 int sender; /* client & !reverse or server & reverse */ 138 int sender_has_retransmits; 139 struct protocol *protocol; 140 signed char state; 141 char *server_hostname; /* -c option */ 142 char *bind_address; /* -B option */ 143 int server_port; 144 int omit; /* duration of omit period (-O flag) */ 145 int duration; /* total duration of test (-t flag) */ 146 char *diskfile_name; /* -F option */ 147 int affinity, server_affinity; /* -A option */ 148 char *title; /* -T option */ 149 150 int ctrl_sck; 151 int listener; 152 int prot_listener; 153 154 /* boolean variables for Options */ 155 int daemon; /* -D option */ 156 int no_delay; /* -N option */ 157 int reverse; /* -R option */ 158 int verbose; /* -V option - verbose mode */ 159 int json_output; /* -J option - JSON output */ 160 int zerocopy; /* -Z option - use sendfile */ 161 162 int multisend; 163 int may_use_sigalrm; 164 165 /* Select related parameters */ 166 int max_fd; 167 fd_set read_set; /* set of read sockets */ 168 fd_set write_set; /* set of write sockets */ 169 170 /* Interval related members */ 171 int omitting; 172 double stats_interval; 173 double reporter_interval; 174 void (*stats_callback) (struct iperf_test *); 175 void (*reporter_callback) (struct iperf_test *); 176 Timer *omit_timer; 177 Timer *timer; 178 int done; 179 Timer *stats_timer; 180 Timer *reporter_timer; 181 182 double cpu_util; /* cpu utilization of the test */ 183 double remote_cpu_util; /* cpu utilization for the remote host/client */ 184 185 int num_streams; /* total streams in the test (-P) */ 186 187 iperf_size_t bytes_sent; 188 char cookie[COOKIE_SIZE]; 189 // struct iperf_stream *streams; /* pointer to list of struct stream */ 190 SLIST_HEAD(slisthead, iperf_stream) streams; 191 struct iperf_settings *settings; 192 193 SLIST_HEAD(plisthead, protocol) protocols; 194 195 /* callback functions */ 196 void (*on_new_stream)(struct iperf_stream *); 197 void (*on_test_start)(struct iperf_test *); 198 void (*on_connect)(struct iperf_test *); 199 void (*on_test_finish)(struct iperf_test *); 200 201 /* cJSON handles for use when in -J mode */\ 202 cJSON *json_top; 203 cJSON *json_start; 204 cJSON *json_intervals; 205 cJSON *json_end; 206 }; 207 208 /* default settings */ 209 #define PORT 5201 /* default port to listen on (don't use the same port as iperf2) */ 210 #define uS_TO_NS 1000 211 #define SEC_TO_US 1000000LL 212 #define UDP_RATE (1024 * 1024) /* 1 Mbps */ 213 #define OMIT 0 /* seconds */ 214 #define DURATION 10 /* seconds */ 215 216 #define SEC_TO_NS 1000000000LL /* too big for enum/const on some platforms */ 217 #define MAX_RESULT_STRING 4096 218 219 /* constants for command line arg sanity checks */ 220 #define MB (1024 * 1024) 221 #define MAX_TCP_BUFFER (512 * MB) 222 #define MAX_BLOCKSIZE MB 223 #define MIN_INTERVAL 0.1 224 #define MAX_INTERVAL 60.0 225 #define MAX_TIME 3600 226 #define MAX_MSS (9 * 1024) 227 #define MAX_STREAMS 128 228 229 #endif /* !__IPERF_H */ 230