xref: /iperf/src/iperf.h (revision 2b8ad3e4)
1a951c980SBrian Tierney /*
21a908ce1SBruce A. Mah  * iperf, Copyright (c) 2014-2020, The Regents of the University of
3da9f046fSBruce A. Mah  * California, through Lawrence Berkeley National Laboratory (subject
4da9f046fSBruce A. Mah  * to receipt of any required approvals from the U.S. Dept. of
5da9f046fSBruce A. Mah  * Energy).  All rights reserved.
67d375156SJon Dugan  *
7da9f046fSBruce A. Mah  * If you have questions about your rights to use or distribute this
8da9f046fSBruce A. Mah  * software, please contact Berkeley Lab's Technology Transfer
9da9f046fSBruce A. Mah  * Department at [email protected].
10da9f046fSBruce A. Mah  *
11da9f046fSBruce A. Mah  * NOTICE.  This software is owned by the U.S. Department of Energy.
12da9f046fSBruce A. Mah  * As such, the U.S. Government has been granted for itself and others
13da9f046fSBruce A. Mah  * acting on its behalf a paid-up, nonexclusive, irrevocable,
14da9f046fSBruce A. Mah  * worldwide license in the Software to reproduce, prepare derivative
15da9f046fSBruce A. Mah  * works, and perform publicly and display publicly.  Beginning five
16da9f046fSBruce A. Mah  * (5) years after the date permission to assert copyright is obtained
17da9f046fSBruce A. Mah  * from the U.S. Department of Energy, and subject to any subsequent
18da9f046fSBruce A. Mah  * five (5) year renewals, the U.S. Government is granted for itself
19da9f046fSBruce A. Mah  * and others acting on its behalf a paid-up, nonexclusive,
20da9f046fSBruce A. Mah  * irrevocable, worldwide license in the Software to reproduce,
21da9f046fSBruce A. Mah  * prepare derivative works, distribute copies to the public, perform
22da9f046fSBruce A. Mah  * publicly and display publicly, and to permit others to do so.
23da9f046fSBruce A. Mah  *
24da9f046fSBruce A. Mah  * This code is distributed under a BSD style license, see the LICENSE
25da9f046fSBruce A. Mah  * file for complete information.
26a951c980SBrian Tierney  */
27982c704aSsethdelliott #ifndef __IPERF_H
28982c704aSsethdelliott #define __IPERF_H
29a951c980SBrian Tierney 
3040050b7bSBruce A. Mah #include "iperf_config.h"
3140050b7bSBruce A. Mah 
32f4a3ddaaSAaronMatthewBrown #include <sys/time.h>
338430ad49Ssethdelliott #include <sys/types.h>
34426221a3SBruce A. Mah #ifdef HAVE_STDINT_H
358430ad49Ssethdelliott #include <stdint.h>
36426221a3SBruce A. Mah #endif
371ceacc13SFredrik Fornwall #include <sys/select.h>
38f4a3ddaaSAaronMatthewBrown #include <sys/socket.h>
39d88f4cecSPhilip Prindeville #ifndef _GNU_SOURCE
40a8ee9c65Sf1rebird # define _GNU_SOURCE
41d88f4cecSPhilip Prindeville #endif
4247985d7fSShuo Chen #ifdef HAVE_LINUX_TCP_H
4347985d7fSShuo Chen #include <linux/tcp.h>
4447985d7fSShuo Chen #else
45f4a3ddaaSAaronMatthewBrown #include <netinet/tcp.h>
4647985d7fSShuo Chen #endif
4721581a72SBruce A. Mah #include <net/if.h> // for IFNAMSIZ
48deefb95fSBruce A. Mah 
4940a1faf3SBruce A. Mah #if defined(HAVE_CPUSET_SETAFFINITY)
50deefb95fSBruce A. Mah #include <sys/param.h>
51deefb95fSBruce A. Mah #include <sys/cpuset.h>
5240a1faf3SBruce A. Mah #endif /* HAVE_CPUSET_SETAFFINITY */
53deefb95fSBruce A. Mah 
5419329249SBruce A. Mah #if defined(HAVE_INTTYPES_H)
5519329249SBruce A. Mah # include <inttypes.h>
5619329249SBruce A. Mah #else
5719329249SBruce A. Mah # ifndef PRIu64
5819329249SBruce A. Mah #  if sizeof(long) == 8
5919329249SBruce A. Mah #   define PRIu64		"lu"
6019329249SBruce A. Mah #  else
6119329249SBruce A. Mah #   define PRIu64		"llu"
6219329249SBruce A. Mah #  endif
6319329249SBruce A. Mah # endif
6419329249SBruce A. Mah #endif
6519329249SBruce A. Mah 
66ec2d0670SJef Poskanzer #include "timer.h"
671fac1d26SJon Dugan #include "queue.h"
689bfb54c0SJef Poskanzer #include "cjson.h"
69cde81d76SBen Fox-Moore #include "iperf_time.h"
70f4a3ddaaSAaronMatthewBrown 
71e28f12c7Sralcini #if defined(HAVE_SSL)
72e28f12c7Sralcini #include <openssl/bio.h>
73e28f12c7Sralcini #include <openssl/evp.h>
74e28f12c7Sralcini #endif // HAVE_SSL
75e28f12c7Sralcini 
7670c85f62SBruce A. Mah #if !defined(__IPERF_API_H)
77e9287700SJon Dugan typedef uint64_t iperf_size_t;
7870c85f62SBruce A. Mah #endif // __IPERF_API_H
79a951c980SBrian Tierney 
80a951c980SBrian Tierney struct iperf_interval_results
81a951c980SBrian Tierney {
8250d6cce6Sa1346054     iperf_size_t bytes_transferred; /* bytes transferred in this interval */
83cde81d76SBen Fox-Moore     struct iperf_time interval_start_time;
84cde81d76SBen Fox-Moore     struct iperf_time interval_end_time;
85a951c980SBrian Tierney     float     interval_duration;
8695360b20SJef Poskanzer 
8795360b20SJef Poskanzer     /* for UDP */
8895360b20SJef Poskanzer     int       interval_packet_count;
8995360b20SJef Poskanzer     int       interval_outoforder_packets;
9095360b20SJef Poskanzer     int       interval_cnt_error;
9195360b20SJef Poskanzer     int       packet_count;
9295360b20SJef Poskanzer     double    jitter;
9395360b20SJef Poskanzer     int       outoforder_packets;
9495360b20SJef Poskanzer     int       cnt_error;
9595360b20SJef Poskanzer 
96a953f5aaSJef Poskanzer     int omitted;
9786daf673SHavard Eidnes #if (defined(linux) || defined(__FreeBSD__) || defined(__NetBSD__)) && \
9886daf673SHavard Eidnes 	defined(TCP_INFO)
9986daf673SHavard Eidnes     struct tcp_info tcpInfo; /* getsockopt(TCP_INFO) for Linux, {Free,Net}BSD */
100a951c980SBrian Tierney #else
101d7ebadafSJef Poskanzer     /* Just placeholders, never accessed. */
102d7ebadafSJef Poskanzer     char *tcpInfo;
103a951c980SBrian Tierney #endif
10469376ec7SJef Poskanzer     int interval_retrans;
1055cdc6a4aSBruce A. Mah     int interval_sacks;
1065cdc6a4aSBruce A. Mah     int snd_cwnd;
10747985d7fSShuo Chen     int snd_wnd;
1088bb79aeeSjef     TAILQ_ENTRY(iperf_interval_results) irlistentries;
109a951c980SBrian Tierney     void     *custom_data;
110432ef7ebSBruce A. Mah     int rtt;
1115d14d106STran Viet Hoang     int rttvar;
11252375c10SBruce A. Mah     int pmtu;
113a951c980SBrian Tierney };
114a951c980SBrian Tierney 
115a951c980SBrian Tierney struct iperf_stream_result
116a951c980SBrian Tierney {
117a951c980SBrian Tierney     iperf_size_t bytes_received;
118a951c980SBrian Tierney     iperf_size_t bytes_sent;
1196146bde4SBrian Tierney     iperf_size_t bytes_received_this_interval;
1206146bde4SBrian Tierney     iperf_size_t bytes_sent_this_interval;
1213b231126SJoe McEachern     iperf_size_t bytes_sent_omit;
12269376ec7SJef Poskanzer     int stream_prev_total_retrans;
12369376ec7SJef Poskanzer     int stream_retrans;
1245cdc6a4aSBruce A. Mah     int stream_prev_total_sacks;
1255cdc6a4aSBruce A. Mah     int stream_sacks;
126432ef7ebSBruce A. Mah     int stream_max_rtt;
12729dbc41cSBruce A. Mah     int stream_min_rtt;
12829dbc41cSBruce A. Mah     int stream_sum_rtt;
12929dbc41cSBruce A. Mah     int stream_count_rtt;
130432ef7ebSBruce A. Mah     int stream_max_snd_cwnd;
13147985d7fSShuo Chen     int stream_max_snd_wnd;
132cde81d76SBen Fox-Moore     struct iperf_time start_time;
133cde81d76SBen Fox-Moore     struct iperf_time end_time;
134cde81d76SBen Fox-Moore     struct iperf_time start_time_fixed;
13510e2cc24SBruce A. Mah     double sender_time;
13610e2cc24SBruce A. Mah     double receiver_time;
1378bb79aeeSjef     TAILQ_HEAD(irlisthead, iperf_interval_results) interval_results;
138a951c980SBrian Tierney     void     *data;
139a951c980SBrian Tierney };
140a951c980SBrian Tierney 
1418f4e66c9SBrian Tierney #define COOKIE_SIZE 37		/* size of an ascii uuid */
142a951c980SBrian Tierney struct iperf_settings
143a951c980SBrian Tierney {
144f99bd3b2Ssethdelliott     int       domain;               /* AF_INET or AF_INET6 */
145a951c980SBrian Tierney     int       socket_bufsize;       /* window size for TCP */
146a951c980SBrian Tierney     int       blksize;              /* size of read/writes (-l) */
147a0c6f0ecSDavid Bar-On     iperf_size_t  rate;                 /* target data rate for application pacing*/
148a0c6f0ecSDavid Bar-On     iperf_size_t  bitrate_limit;   /* server's maximum allowed total data rate for all streams*/
14950d6cce6Sa1346054     double        bitrate_limit_interval;  /* interval for averaging total data rate */
150a0c6f0ecSDavid Bar-On     int           bitrate_limit_stats_per_interval;     /* calculated number of stats periods for averaging total data rate */
151a094d9feSBruce A. Mah     uint64_t  fqrate;               /* target data rate for FQ pacing*/
152cba8584bSBruce A. Mah     int	      pacing_timer;	    /* pacing timer in microseconds */
153bdf5335cSJef Poskanzer     int       burst;                /* packets per burst */
154a951c980SBrian Tierney     int       mss;                  /* for TCP MSS */
155112a907cSsethdelliott     int       ttl;                  /* IP TTL option */
156112a907cSsethdelliott     int       tos;                  /* type of service bit */
157c687db9dSJef Poskanzer     int       flowlabel;            /* IPv6 flow label */
158112a907cSsethdelliott     iperf_size_t bytes;             /* number of bytes to send */
159329523a5SBruce A. Mah     iperf_size_t blocks;            /* number of blocks (packets) to send */
160a951c980SBrian Tierney     char      unit_format;          /* -f */
161e1420625SBruce A. Mah     int       num_ostreams;         /* SCTP initmsg settings */
16249a5771aSDavid Bar-On     int       dont_fragment;        /* Whether to set IP flag Do-Not_Fragment */
163e28f12c7Sralcini #if defined(HAVE_SSL)
164a51045deSralcini     char      *authtoken;           /* Authentication token */
165e28f12c7Sralcini     char      *client_username;
166e28f12c7Sralcini     char      *client_password;
167e28f12c7Sralcini     EVP_PKEY  *client_rsa_pubkey;
168e28f12c7Sralcini #endif // HAVE_SSL
1699d7d60acSBruce A. Mah     int	      connect_timeout;	    /* socket connection timeout, in ms */
170be66b575SDavid Bar-On     int       idle_timeout;         /* server idle time timeout */
1717bdd5b0eSDavid Bar-On     unsigned int snd_timeout; /* Timeout for sending tcp messages in active mode, in us */
1728ffe72e2SDavid Bar-On     struct iperf_time rcv_timeout;  /* Timeout for receiving messages in active mode, in us */
173a951c980SBrian Tierney };
174a951c980SBrian Tierney 
1759bfb54c0SJef Poskanzer struct iperf_test;
1769bfb54c0SJef Poskanzer 
177a951c980SBrian Tierney struct iperf_stream
178a951c980SBrian Tierney {
1799bfb54c0SJef Poskanzer     struct iperf_test* test;
1809bfb54c0SJef Poskanzer 
181a951c980SBrian Tierney     /* configurable members */
182a951c980SBrian Tierney     int       local_port;
183a951c980SBrian Tierney     int       remote_port;
184982c704aSsethdelliott     int       socket;
185465b565cSsethdelliott     int       id;
1860778f04cSBoris Okunev     int       sender;
1875ed85b8fSBrian Tierney 	/* XXX: is settings just a pointer to the same struct in iperf_test? if not,
188a3281a3dSBrian Tierney 		should it be? */
189a951c980SBrian Tierney     struct iperf_settings *settings;	/* pointer to structure settings */
190a951c980SBrian Tierney 
191a951c980SBrian Tierney     /* non configurable members */
192a951c980SBrian Tierney     struct iperf_stream_result *result;	/* structure pointer to result */
193ec2d0670SJef Poskanzer     Timer     *send_timer;
194647d3b95SJef Poskanzer     int       green_light;
195987b4323SJef Poskanzer     int       buffer_fd;	/* data to send, file descriptor */
196987b4323SJef Poskanzer     char      *buffer;		/* data to send, mmapped */
197d1260e6fSTony Weng     int       pending_size;     /* pending data to send */
198e32a7bcdSJef Poskanzer     int       diskfile_fd;	/* file to send, file descriptor */
199c458a115SBruce A. Mah     int	      diskfile_left;	/* remaining file data on disk */
200a951c980SBrian Tierney 
201a951c980SBrian Tierney     /*
202a951c980SBrian Tierney      * for udp measurements - This can be a structure outside stream, and
203a951c980SBrian Tierney      * stream can have a pointer to this
204a951c980SBrian Tierney      */
205a951c980SBrian Tierney     int       packet_count;
206e255a12eSBruce A. Mah     int	      peer_packet_count;
20757892604SJef Poskanzer     int       omitted_packet_count;
208a951c980SBrian Tierney     double    jitter;
209a951c980SBrian Tierney     double    prev_transit;
210a951c980SBrian Tierney     int       outoforder_packets;
2113b231126SJoe McEachern     int       omitted_outoforder_packets;
212a951c980SBrian Tierney     int       cnt_error;
2133b231126SJoe McEachern     int       omitted_cnt_error;
214a951c980SBrian Tierney     uint64_t  target;
215a951c980SBrian Tierney 
216a951c980SBrian Tierney     struct sockaddr_storage local_addr;
217a951c980SBrian Tierney     struct sockaddr_storage remote_addr;
218a951c980SBrian Tierney 
219a951c980SBrian Tierney     int       (*rcv) (struct iperf_stream * stream);
220a951c980SBrian Tierney     int       (*snd) (struct iperf_stream * stream);
221a951c980SBrian Tierney 
222e32a7bcdSJef Poskanzer     /* chained send/receive routines for -F mode */
223e32a7bcdSJef Poskanzer     int       (*rcv2) (struct iperf_stream * stream);
224e32a7bcdSJef Poskanzer     int       (*snd2) (struct iperf_stream * stream);
225e32a7bcdSJef Poskanzer 
226dd4bc008Ssethdelliott //    struct iperf_stream *next;
227dd4bc008Ssethdelliott     SLIST_ENTRY(iperf_stream) streams;
228a951c980SBrian Tierney 
229a951c980SBrian Tierney     void     *data;
230a951c980SBrian Tierney };
231a951c980SBrian Tierney 
2328a0b5a5dSsethdelliott struct protocol {
2338a0b5a5dSsethdelliott     int       id;
2348a0b5a5dSsethdelliott     char      *name;
2358a0b5a5dSsethdelliott     int       (*accept)(struct iperf_test *);
2368a0b5a5dSsethdelliott     int       (*listen)(struct iperf_test *);
2378a0b5a5dSsethdelliott     int       (*connect)(struct iperf_test *);
2388a0b5a5dSsethdelliott     int       (*send)(struct iperf_stream *);
2398a0b5a5dSsethdelliott     int       (*recv)(struct iperf_stream *);
2408a0b5a5dSsethdelliott     int       (*init)(struct iperf_test *);
2418a0b5a5dSsethdelliott     SLIST_ENTRY(protocol) protocols;
2428a0b5a5dSsethdelliott };
2438a0b5a5dSsethdelliott 
244ba8d6e62SBruce A. Mah struct iperf_textline {
245ba8d6e62SBruce A. Mah     char *line;
246ba8d6e62SBruce A. Mah     TAILQ_ENTRY(iperf_textline) textlineentries;
247ba8d6e62SBruce A. Mah };
248ba8d6e62SBruce A. Mah 
249e1420625SBruce A. Mah struct xbind_entry {
250e1420625SBruce A. Mah     char *name;
251e1420625SBruce A. Mah     struct addrinfo *ai;
252e1420625SBruce A. Mah     TAILQ_ENTRY(xbind_entry) link;
253e1420625SBruce A. Mah };
254e1420625SBruce A. Mah 
2550778f04cSBoris Okunev enum iperf_mode {
2560778f04cSBoris Okunev 	SENDER = 1,
2570778f04cSBoris Okunev 	RECEIVER = 0,
2580778f04cSBoris Okunev 	BIDIRECTIONAL = -1
2590778f04cSBoris Okunev };
2600778f04cSBoris Okunev 
261a951c980SBrian Tierney enum debug_level {
262a951c980SBrian Tierney     DEBUG_LEVEL_ERROR = 1,
2632c042fd4SJef Poskanzer     DEBUG_LEVEL_WARN = 2,
2640778f04cSBoris Okunev     DEBUG_LEVEL_INFO = 3,
26569bdbfd3SJef Poskanzer     DEBUG_LEVEL_DEBUG = 4,
2660778f04cSBoris Okunev     DEBUG_LEVEL_MAX = 4
26766ce7ad4Ssethdelliott };
26801943402SJef Poskanzer 
269a951c980SBrian Tierney 
2707b2abbc5SBruce A. Mah struct iperf_test
271e1420625SBruce A. Mah {
27221581a72SBruce A. Mah     char      role;                             /* 'c' lient or 's' erver */
273e1420625SBruce A. Mah     enum iperf_mode mode;
274ac468c8bSBruce A. Mah     int       sender_has_retransmits;
275a951c980SBrian Tierney     int       other_side_has_retransmits;       /* used if mode == BIDIRECTIONAL */
27657892604SJef Poskanzer     struct protocol *protocol;
277a951c980SBrian Tierney     signed char state;
278e32a7bcdSJef Poskanzer     char     *server_hostname;                  /* -c option */
2798a7e01ebSJef Poskanzer     char     *tmp_template;
28040a1faf3SBruce A. Mah     char     *bind_address;                     /* first -B option */
281deefb95fSBruce A. Mah     char     *bind_dev;                         /* bind to network device */
28240a1faf3SBruce A. Mah     TAILQ_HEAD(xbind_addrhead, xbind_entry) xbind_addrs; /* all -X opts */
283d38ab4c8SJef Poskanzer     int       bind_port;                        /* --cport option */
284829d619aSBruce A. Mah     int       server_port;
28562bfa88cSJef Poskanzer     int       omit;                             /* duration of omit period (-O flag) */
2867eeaa1cbSBruce A. Mah     int       duration;                         /* total duration of test (-t flag) */
2877eeaa1cbSBruce A. Mah     char     *diskfile_name;			/* -F option */
288441d8b75SBruce A. Mah     int       affinity, server_affinity;	/* -A option */
289982c704aSsethdelliott #if defined(HAVE_CPUSET_SETAFFINITY)
290aeb6938dSBruce A. Mah     cpuset_t cpumask;
291aeb6938dSBruce A. Mah #endif /* HAVE_CPUSET_SETAFFINITY */
292aeb6938dSBruce A. Mah     char     *title;				/* -T option */
293982c704aSsethdelliott     char     *extra_data;			/* --extra-data */
29466ce7ad4Ssethdelliott     char     *congestion;			/* -C option */
2958a0b5a5dSsethdelliott     char     *congestion_used;			/* what was actually used */
296982c704aSsethdelliott     char     *remote_congestion_used;		/* what the other side used */
2970fd60a36SBruce A. Mah     char     *pidfile;				/* -P option */
298e28f12c7Sralcini 
299e28f12c7Sralcini     char     *logfile;				/* --logfile option */
300a51045deSralcini     FILE     *outfile;
301e28f12c7Sralcini 
302bd143779Sralcini     int       ctrl_sck;
303e28f12c7Sralcini     int       listener;
3040fd60a36SBruce A. Mah     int       prot_listener;
305112a907cSsethdelliott 
306a951c980SBrian Tierney     int	      ctrl_sck_mss;			/* MSS for the control channel */
307dba611dbSBruce A. Mah 
308a951c980SBrian Tierney #if defined(HAVE_SSL)
30932885561Ssethdelliott     char      *server_authorized_users;
3100778f04cSBoris Okunev     EVP_PKEY  *server_rsa_private_key;
31132885561Ssethdelliott     int       server_skew_threshold;
3129bfb54c0SJef Poskanzer #endif // HAVE_SSL
313987b4323SJef Poskanzer 
314cf59099bSBruce A. Mah     /* boolean variables for Options */
315ba8d6e62SBruce A. Mah     int       daemon;                           /* -D option */
316329523a5SBruce A. Mah     int       one_off;                          /* -1 option */
31708a2de45SQuaSoft     int       no_delay;                         /* -N option */
318a27f6534SJef Poskanzer     int       reverse;                          /* -R option */
319cbea72b6SPhil Levchenko     int       bidirectional;                    /* --bidirectional */
3201a908ce1SBruce A. Mah     int	      verbose;                          /* -V option - verbose mode */
3211a908ce1SBruce A. Mah     int	      json_output;                      /* -J option - JSON output */
322a27f6534SJef Poskanzer     int	      zerocopy;                         /* -Z option - use sendfile */
3232939863bSBruce A. Mah     int       debug;				/* -d option - enable debug */
324a951c980SBrian Tierney     enum      debug_level debug_level;          /* -d option option - level of debug messages to show */
325a951c980SBrian Tierney     int	      get_server_output;		/* --get-server-output */
326e99faeaeSBrian Tierney     int	      udp_counters_64bit;		/* --use-64-bit-udp-counters */
327e99faeaeSBrian Tierney     int       forceflush; /* --forceflush - flushing output at every interval */
328a951c980SBrian Tierney     int	      multisend;
329f1b3bd81Ssethdelliott     int	      repeating_payload;                /* --repeating-payload */
33057892604SJef Poskanzer     int       timestamps;			/* --timestamps */
3310bd8d9daSsethdelliott     char     *timestamp_format;
3320bd8d9daSsethdelliott 
333ff385f98Ssethdelliott     char     *json_output_string; /* rendered JSON output if json_output is set */
334ff385f98Ssethdelliott     /* Select related parameters */
33557892604SJef Poskanzer     int       max_fd;
336ec2d0670SJef Poskanzer     fd_set    read_set;                         /* set of read sockets */
337ec2d0670SJef Poskanzer     fd_set    write_set;                        /* set of write sockets */
338ec2d0670SJef Poskanzer 
339ec2d0670SJef Poskanzer     /* Interval related members */
340ad426c6fSsethdelliott     int       omitting;
341056361fcSJef Poskanzer     double    stats_interval;
342056361fcSJef Poskanzer     double    reporter_interval;
343fd10304cSsethdelliott     void      (*stats_callback) (struct iperf_test *);
344a951c980SBrian Tierney     void      (*reporter_callback) (struct iperf_test *);
345aebbe3a0Ssethdelliott     Timer     *omit_timer;
346f1b3bd81Ssethdelliott     Timer     *timer;
347329523a5SBruce A. Mah     int        done;
3480778f04cSBoris Okunev     Timer     *stats_timer;
3490778f04cSBoris Okunev     Timer     *reporter_timer;
3500778f04cSBoris Okunev 
3510778f04cSBoris Okunev     double cpu_util[3];                            /* cpu utilization of the test - total, user, system */
352a0c6f0ecSDavid Bar-On     double remote_cpu_util[3];                     /* cpu utilization for the remote host/client - total, user, system */
353a0c6f0ecSDavid Bar-On 
35450d6cce6Sa1346054     int       num_streams;                      /* total streams in the test (-P) */
355a0c6f0ecSDavid Bar-On 
356a0c6f0ecSDavid Bar-On     iperf_size_t bytes_sent;
357be66b575SDavid Bar-On     iperf_size_t blocks_sent;
358be66b575SDavid Bar-On 
359be66b575SDavid Bar-On     iperf_size_t bytes_received;
360be66b575SDavid Bar-On     iperf_size_t blocks_received;
361be66b575SDavid Bar-On 
362112a907cSsethdelliott     iperf_size_t bitrate_limit_stats_count;               /* Number of stats periods accumulated for server's total bitrate average */
363dd4bc008Ssethdelliott     iperf_size_t *bitrate_limit_intervals_traffic_bytes;  /* Pointer to a cyclic array that includes the last interval's bytes transferred */
364dd4bc008Ssethdelliott     iperf_size_t bitrate_limit_last_interval_index;       /* Index of the last interval traffic inserted into the cyclic array */
365112a907cSsethdelliott     int          bitrate_limit_exceeded;                  /* Set by callback routine when average data rate exceeded the server's bitrate limit */
3668a0b5a5dSsethdelliott 
367dd4bc008Ssethdelliott     int server_last_run_rc;                      /* Save last server run rc for next test */
3684df383f6Ssethdelliott     uint server_forced_idle_restarts_count;      /* count number of forced server restarts to make sure it is not stack */
3694df383f6Ssethdelliott     uint server_forced_no_msg_restarts_count;    /* count number of forced server restarts to make sure it is not stack */
3704df383f6Ssethdelliott     uint server_test_number;                     /* count number of tests performed by a server */
3714df383f6Ssethdelliott 
3724df383f6Ssethdelliott     char      cookie[COOKIE_SIZE];
3734df383f6Ssethdelliott //    struct iperf_stream *streams;               /* pointer to list of struct stream */
3749bfb54c0SJef Poskanzer     SLIST_HEAD(slisthead, iperf_stream) streams;
3759bfb54c0SJef Poskanzer     struct iperf_settings *settings;
3769bfb54c0SJef Poskanzer 
3779bfb54c0SJef Poskanzer     SLIST_HEAD(plisthead, protocol) protocols;
378a134ba0aSBruce A. Mah 
3799bfb54c0SJef Poskanzer     /* callback functions */
3809bfb54c0SJef Poskanzer     void      (*on_new_stream)(struct iperf_stream *);
381ba8d6e62SBruce A. Mah     void      (*on_test_start)(struct iperf_test *);
382ba8d6e62SBruce A. Mah     void      (*on_connect)(struct iperf_test *);
383ba8d6e62SBruce A. Mah     void      (*on_test_finish)(struct iperf_test *);
384ba8d6e62SBruce A. Mah 
385ba8d6e62SBruce A. Mah     /* cJSON handles for use when in -J mode */\
386ba8d6e62SBruce A. Mah     cJSON *json_top;
387ba8d6e62SBruce A. Mah     cJSON *json_start;
388ba8d6e62SBruce A. Mah     cJSON *json_connected;
389a951c980SBrian Tierney     cJSON *json_intervals;
390a951c980SBrian Tierney     cJSON *json_end;
391a951c980SBrian Tierney 
39298ce496bSjef     /* Server output (use on client side only) */
39398ce496bSjef     char *server_output_text;
3948ffe72e2SDavid Bar-On     cJSON *json_server_output;
3958ffe72e2SDavid Bar-On 
396e232c5d1SJef Poskanzer     /* Server output (use on server side only) */
397647d3b95SJef Poskanzer     TAILQ_HEAD(iperf_textlisthead, iperf_textline) server_output_list;
3989393606fSJef Poskanzer 
3991133dd0bSJef Poskanzer };
400a951c980SBrian Tierney 
401e232c5d1SJef Poskanzer /* default settings */
4028d41fbd7SBrian Tierney #define PORT 5201  /* default port to listen on (don't use the same port as iperf2) */
403a951c980SBrian Tierney #define uS_TO_NS 1000
4041ff12f4cSBruce A. Mah #define mS_TO_US 1000
4051ff12f4cSBruce A. Mah #define SEC_TO_mS 1000
40698ce496bSjef #define SEC_TO_US 1000000LL
40798ce496bSjef #define UDP_RATE (1024 * 1024) /* 1 Mbps */
4085ec1d758SJef Poskanzer #define OMIT 0 /* seconds */
40970866d6dSBrian Tierney #define DURATION 10 /* seconds */
41003224c9fSBruce A. Mah 
41103224c9fSBruce A. Mah #define SEC_TO_NS 1000000000LL	/* too big for enum/const on some platforms */
41296d0c77cSBruce A. Mah #define MAX_RESULT_STRING 4096
41396d0c77cSBruce A. Mah 
41456536642SJef Poskanzer #define UDP_BUFFER_EXTRA 1024
41556536642SJef Poskanzer 
416c8a98bd3SBruce A. Mah /* constants for command line arg sanity checks */
417bdf5335cSJef Poskanzer #define MB (1024 * 1024)
41898ce496bSjef #define MAX_TCP_BUFFER (512 * MB)
419d44c04d4SBrian Tierney #define MAX_BLOCKSIZE MB
420d44c04d4SBrian Tierney /* Minimum size UDP send is the size of two 32-bit ints followed by a 64-bit int */
4211a908ce1SBruce A. Mah #define MIN_UDP_BLOCKSIZE (4 + 4 + 8)
4221a908ce1SBruce A. Mah /* Maximum size UDP send is (64K - 1) - IP and UDP header sizes */
42338bac802SBruce A. Mah #define MAX_UDP_BLOCKSIZE (65535 - 8 - 20)
42438bac802SBruce A. Mah #define MIN_INTERVAL 0.1
4252eace5a9SDavid Bar-On #define MAX_INTERVAL 60.0
4262eace5a9SDavid Bar-On #define MAX_TIME 86400
4272eace5a9SDavid Bar-On #define MAX_BURST 1000
42815ec8e6eSDavid Bar-On #define MAX_MSS (9 * 1024)
4292eace5a9SDavid Bar-On #define MAX_STREAMS 128
430*2b8ad3e4SDimitri Papadopoulos 
4312eace5a9SDavid Bar-On #define TIMESTAMP_FORMAT "%c "
4322eace5a9SDavid Bar-On 
43398ce496bSjef extern int gerror; /* error value from getaddrinfo(3), for use in internal error handling */
434 
435 /* UDP "connect" message and reply (textual value for Wireshark, etc. readability - legacy was numeric) */
436 #define UDP_CONNECT_MSG 0x36373839          // "6789" - legacy value was 123456789
437 #define UDP_CONNECT_REPLY 0x39383736        // "9876" - legacy value was 987654321
438 #define LEGACY_UDP_CONNECT_REPLY 987654321  // Old servers may still reply with the legacy value
439 
440 /* In Reverse mode, maximum number of packets to wait for "accept" response - to handle out of order packets */
441 #define MAX_REVERSE_OUT_OF_ORDER_PACKETS 2
442 
443 #endif /* !__IPERF_H */
444