Annotation of embedaddon/iperf/src/iperf_api.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_API_H
        !            28: #define        __IPERF_API_H
        !            29: 
        !            30: #include <sys/time.h>
        !            31: #include <setjmp.h>
        !            32: 
        !            33: struct iperf_test;
        !            34: struct iperf_stream_result;
        !            35: struct iperf_interval_results;
        !            36: struct iperf_stream;
        !            37: 
        !            38: /* default settings */
        !            39: #define Ptcp SOCK_STREAM
        !            40: #define Pudp SOCK_DGRAM
        !            41: #define Psctp 12
        !            42: #define DEFAULT_UDP_BLKSIZE 8192
        !            43: #define DEFAULT_TCP_BLKSIZE (128 * 1024)  /* default read/write block size */
        !            44: #define DEFAULT_SCTP_BLKSIZE (64 * 1024)
        !            45: 
        !            46: /* short option equivalents, used to support options that only have long form */
        !            47: #define OPT_SCTP 1
        !            48: #define OPT_LOGFILE 2
        !            49: #define OPT_GET_SERVER_OUTPUT 3
        !            50: #define OPT_UDP_COUNTERS_64BIT 4
        !            51: #define OPT_CLIENT_PORT 5
        !            52: #define OPT_NUMSTREAMS 6
        !            53: #define OPT_NO_FQ_SOCKET_PACING 9
        !            54: 
        !            55: /* states */
        !            56: #define TEST_START 1
        !            57: #define TEST_RUNNING 2
        !            58: #define RESULT_REQUEST 3
        !            59: #define TEST_END 4
        !            60: #define STREAM_BEGIN 5
        !            61: #define STREAM_RUNNING 6
        !            62: #define STREAM_END 7
        !            63: #define ALL_STREAMS_END 8
        !            64: #define PARAM_EXCHANGE 9
        !            65: #define CREATE_STREAMS 10
        !            66: #define SERVER_TERMINATE 11
        !            67: #define CLIENT_TERMINATE 12
        !            68: #define EXCHANGE_RESULTS 13
        !            69: #define DISPLAY_RESULTS 14
        !            70: #define IPERF_START 15
        !            71: #define IPERF_DONE 16
        !            72: #define ACCESS_DENIED (-1)
        !            73: #define SERVER_ERROR (-2)
        !            74: 
        !            75: /* Getter routines for some fields inside iperf_test. */
        !            76: int    iperf_get_verbose( struct iperf_test* ipt );
        !            77: int    iperf_get_control_socket( struct iperf_test* ipt );
        !            78: int    iperf_get_test_omit( struct iperf_test* ipt );
        !            79: int    iperf_get_test_duration( struct iperf_test* ipt );
        !            80: char   iperf_get_test_role( struct iperf_test* ipt );
        !            81: int    iperf_get_test_reverse( struct iperf_test* ipt );
        !            82: int    iperf_get_test_blksize( struct iperf_test* ipt );
        !            83: FILE*  iperf_get_test_outfile( struct iperf_test* ipt );
        !            84: uint64_t iperf_get_test_rate( struct iperf_test* ipt );
        !            85: int     iperf_get_test_burst( struct iperf_test* ipt );
        !            86: int    iperf_get_test_socket_bufsize( struct iperf_test* ipt );
        !            87: double iperf_get_test_reporter_interval( struct iperf_test* ipt );
        !            88: double iperf_get_test_stats_interval( struct iperf_test* ipt );
        !            89: int    iperf_get_test_num_streams( struct iperf_test* ipt );
        !            90: int    iperf_get_test_server_port( struct iperf_test* ipt );
        !            91: char*  iperf_get_test_server_hostname( struct iperf_test* ipt );
        !            92: char*  iperf_get_test_template( struct iperf_test* ipt );
        !            93: int    iperf_get_test_protocol_id( struct iperf_test* ipt );
        !            94: int    iperf_get_test_json_output( struct iperf_test* ipt );
        !            95: char*  iperf_get_test_json_output_string ( struct iperf_test* ipt );
        !            96: int    iperf_get_test_zerocopy( struct iperf_test* ipt );
        !            97: int    iperf_get_test_get_server_output( struct iperf_test* ipt );
        !            98: char*  iperf_get_test_bind_address ( struct iperf_test* ipt );
        !            99: int    iperf_get_test_udp_counters_64bit( struct iperf_test* ipt );
        !           100: int    iperf_get_test_one_off( struct iperf_test* ipt );
        !           101: 
        !           102: /* Setter routines for some fields inside iperf_test. */
        !           103: void   iperf_set_verbose( struct iperf_test* ipt, int verbose );
        !           104: void   iperf_set_control_socket( struct iperf_test* ipt, int ctrl_sck );
        !           105: void   iperf_set_test_omit( struct iperf_test* ipt, int omit );
        !           106: void   iperf_set_test_duration( struct iperf_test* ipt, int duration );
        !           107: void   iperf_set_test_reporter_interval( struct iperf_test* ipt, double reporter_interval );
        !           108: void   iperf_set_test_stats_interval( struct iperf_test* ipt, double stats_interval );
        !           109: void   iperf_set_test_state( struct iperf_test* ipt, signed char state );
        !           110: void   iperf_set_test_blksize( struct iperf_test* ipt, int blksize );
        !           111: void   iperf_set_test_rate( struct iperf_test* ipt, uint64_t rate );
        !           112: void   iperf_set_test_burst( struct iperf_test* ipt, int burst );
        !           113: void   iperf_set_test_server_port( struct iperf_test* ipt, int server_port );
        !           114: void   iperf_set_test_socket_bufsize( struct iperf_test* ipt, int socket_bufsize );
        !           115: void   iperf_set_test_num_streams( struct iperf_test* ipt, int num_streams );
        !           116: void   iperf_set_test_role( struct iperf_test* ipt, char role );
        !           117: void   iperf_set_test_server_hostname( struct iperf_test* ipt, char* server_hostname );
        !           118: void    iperf_set_test_template( struct iperf_test *ipt, char *tmp_template );
        !           119: void   iperf_set_test_reverse( struct iperf_test* ipt, int reverse );
        !           120: void   iperf_set_test_json_output( struct iperf_test* ipt, int json_output );
        !           121: int    iperf_has_zerocopy( void );
        !           122: void   iperf_set_test_zerocopy( struct iperf_test* ipt, int zerocopy );
        !           123: void   iperf_set_test_get_server_output( struct iperf_test* ipt, int get_server_output );
        !           124: void   iperf_set_test_bind_address( struct iperf_test* ipt, char *bind_address );
        !           125: void   iperf_set_test_udp_counters_64bit( struct iperf_test* ipt, int udp_counters_64bit );
        !           126: void   iperf_set_test_one_off( struct iperf_test* ipt, int one_off );
        !           127: 
        !           128: /**
        !           129:  * exchange_parameters - handles the param_Exchange part for client
        !           130:  *
        !           131:  */
        !           132: int      iperf_exchange_parameters(struct iperf_test * test);
        !           133: 
        !           134: /**
        !           135:  * add_to_interval_list -- adds new interval to the interval_list
        !           136:  *
        !           137:  */
        !           138: void      add_to_interval_list(struct iperf_stream_result * rp, struct iperf_interval_results *temp);
        !           139: 
        !           140: /**
        !           141:  * connect_msg -- displays connection message
        !           142:  * denoting senfer/receiver details
        !           143:  *
        !           144:  */
        !           145: void      connect_msg(struct iperf_stream * sp);
        !           146: 
        !           147: /**
        !           148:  * iperf_stats_callback -- handles the statistic gathering
        !           149:  *
        !           150:  */
        !           151: void     iperf_stats_callback(struct iperf_test * test);
        !           152: 
        !           153: /**
        !           154:  * iperf_reporter_callback -- handles the report printing
        !           155:  *
        !           156:  */
        !           157: void     iperf_reporter_callback(struct iperf_test * test);
        !           158: 
        !           159: /**
        !           160:  * iperf_new_test -- return a new iperf_test with default values
        !           161:  *
        !           162:  * returns NULL on failure
        !           163:  *
        !           164:  */
        !           165: struct iperf_test *iperf_new_test();
        !           166: 
        !           167: int      iperf_defaults(struct iperf_test * testp);
        !           168: 
        !           169: /**
        !           170:  * iperf_free_test -- free resources used by test, calls iperf_free_stream to
        !           171:  * free streams
        !           172:  *
        !           173:  */
        !           174: void      iperf_free_test(struct iperf_test * testp);
        !           175: 
        !           176: /**
        !           177:  * iperf_new_stream -- return a net iperf_stream with default values
        !           178:  *
        !           179:  * returns NULL on failure
        !           180:  *
        !           181:  */
        !           182: struct iperf_stream *iperf_new_stream(struct iperf_test *, int);
        !           183: 
        !           184: /**
        !           185:  * iperf_add_stream -- add a stream to a test
        !           186:  *
        !           187:  */
        !           188: void      iperf_add_stream(struct iperf_test * test, struct iperf_stream * stream);
        !           189: 
        !           190: /**
        !           191:  * iperf_init_stream -- init resources associated with test
        !           192:  *
        !           193:  */
        !           194: int       iperf_init_stream(struct iperf_stream *, struct iperf_test *);
        !           195: 
        !           196: /**
        !           197:  * iperf_free_stream -- free resources associated with test
        !           198:  *
        !           199:  */
        !           200: void      iperf_free_stream(struct iperf_stream * sp);
        !           201: 
        !           202: int has_tcpinfo(void);
        !           203: int has_tcpinfo_retransmits(void);
        !           204: void save_tcpinfo(struct iperf_stream *sp, struct iperf_interval_results *irp);
        !           205: long get_total_retransmits(struct iperf_interval_results *irp);
        !           206: long get_snd_cwnd(struct iperf_interval_results *irp);
        !           207: long get_rtt(struct iperf_interval_results *irp);
        !           208: void print_tcpinfo(struct iperf_test *test);
        !           209: void build_tcpinfo_message(struct iperf_interval_results *r, char *message);
        !           210: 
        !           211: int iperf_set_send_state(struct iperf_test *test, signed char state);
        !           212: void iperf_check_throttle(struct iperf_stream *sp, struct timeval *nowP);
        !           213: int iperf_send(struct iperf_test *, fd_set *) /* __attribute__((hot)) */;
        !           214: int iperf_recv(struct iperf_test *, fd_set *);
        !           215: void iperf_catch_sigend(void (*handler)(int));
        !           216: void iperf_got_sigend(struct iperf_test *test) __attribute__ ((noreturn));
        !           217: void usage();
        !           218: void usage_long();
        !           219: void warning(char *);
        !           220: int iperf_exchange_results(struct iperf_test *);
        !           221: int iperf_init_test(struct iperf_test *);
        !           222: int iperf_create_send_timers(struct iperf_test *);
        !           223: int iperf_parse_arguments(struct iperf_test *, int, char **);
        !           224: void iperf_reset_test(struct iperf_test *);
        !           225: void iperf_reset_stats(struct iperf_test * test);
        !           226: 
        !           227: struct protocol *get_protocol(struct iperf_test *, int);
        !           228: int set_protocol(struct iperf_test *, int);
        !           229: 
        !           230: void iperf_on_new_stream(struct iperf_stream *);
        !           231: void iperf_on_test_start(struct iperf_test *);
        !           232: void iperf_on_connect(struct iperf_test *);
        !           233: void iperf_on_test_finish(struct iperf_test *);
        !           234: 
        !           235: extern jmp_buf env;
        !           236: 
        !           237: /* Client routines. */
        !           238: int iperf_run_client(struct iperf_test *);
        !           239: int iperf_connect(struct iperf_test *);
        !           240: int iperf_create_streams(struct iperf_test *);
        !           241: int iperf_handle_message_client(struct iperf_test *);
        !           242: int iperf_client_end(struct iperf_test *);
        !           243: 
        !           244: /* Server routines. */
        !           245: int iperf_run_server(struct iperf_test *);
        !           246: int iperf_server_listen(struct iperf_test *);
        !           247: int iperf_accept(struct iperf_test *);
        !           248: int iperf_handle_message_server(struct iperf_test *);
        !           249: void iperf_test_reset(struct iperf_test *);
        !           250: int iperf_create_pidfile(struct iperf_test *);
        !           251: int iperf_delete_pidfile(struct iperf_test *);
        !           252: 
        !           253: /* JSON output routines. */
        !           254: int iperf_json_start(struct iperf_test *);
        !           255: int iperf_json_finish(struct iperf_test *);
        !           256: 
        !           257: /* CPU affinity routines */
        !           258: int iperf_setaffinity(struct iperf_test *, int affinity);
        !           259: int iperf_clearaffinity(struct iperf_test *);
        !           260: 
        !           261: /* Custom printf routine. */
        !           262: int iprintf(struct iperf_test *test, const char *format, ...) __attribute__ ((format(printf,2,3)));
        !           263: int iflush(struct iperf_test *test);
        !           264: 
        !           265: /* Error routines. */
        !           266: void iperf_err(struct iperf_test *test, const char *format, ...) __attribute__ ((format(printf,2,3)));
        !           267: void iperf_errexit(struct iperf_test *test, const char *format, ...) __attribute__ ((format(printf,2,3),noreturn));
        !           268: char *iperf_strerror(int);
        !           269: extern int i_errno;
        !           270: enum {
        !           271:     IENONE = 0,             // No error
        !           272:     /* Parameter errors */
        !           273:     IESERVCLIENT = 1,       // Iperf cannot be both server and client
        !           274:     IENOROLE = 2,           // Iperf must either be a client (-c) or server (-s)
        !           275:     IESERVERONLY = 3,       // This option is server only
        !           276:     IECLIENTONLY = 4,       // This option is client only
        !           277:     IEDURATION = 5,         // test duration too long. Maximum value = %dMAX_TIME
        !           278:     IENUMSTREAMS = 6,       // Number of parallel streams too large. Maximum value = %dMAX_STREAMS
        !           279:     IEBLOCKSIZE = 7,        // Block size too large. Maximum value = %dMAX_BLOCKSIZE
        !           280:     IEBUFSIZE = 8,          // Socket buffer size too large. Maximum value = %dMAX_TCP_BUFFER
        !           281:     IEINTERVAL = 9,         // Invalid report interval (min = %gMIN_INTERVAL, max = %gMAX_INTERVAL seconds)
        !           282:     IEMSS = 10,             // MSS too large. Maximum value = %dMAX_MSS
        !           283:     IENOSENDFILE = 11,      // This OS does not support sendfile
        !           284:     IEOMIT = 12,            // Bogus value for --omit
        !           285:     IEUNIMP = 13,           // Not implemented yet
        !           286:     IEFILE = 14,            // -F file couldn't be opened
        !           287:     IEBURST = 15,           // Invalid burst count. Maximum value = %dMAX_BURST
        !           288:     IEENDCONDITIONS = 16,   // Only one test end condition (-t, -n, -k) may be specified
        !           289:     IELOGFILE = 17,        // Can't open log file
        !           290:     IENOSCTP = 18,         // No SCTP support available
        !           291:     IEBIND = 19,                       // Local port specified with no local bind option
        !           292:     IEUDPBLOCKSIZE = 20,    // Block size too large. Maximum value = %dMAX_UDP_BLOCKSIZE
        !           293:     IEBADTOS = 21,         // Bad TOS value
        !           294:     /* Test errors */
        !           295:     IENEWTEST = 100,        // Unable to create a new test (check perror)
        !           296:     IEINITTEST = 101,       // Test initialization failed (check perror)
        !           297:     IELISTEN = 102,         // Unable to listen for connections (check perror)
        !           298:     IECONNECT = 103,        // Unable to connect to server (check herror/perror) [from netdial]
        !           299:     IEACCEPT = 104,         // Unable to accept connection from client (check herror/perror)
        !           300:     IESENDCOOKIE = 105,     // Unable to send cookie to server (check perror)
        !           301:     IERECVCOOKIE = 106,     // Unable to receive cookie from client (check perror)
        !           302:     IECTRLWRITE = 107,      // Unable to write to the control socket (check perror)
        !           303:     IECTRLREAD = 108,       // Unable to read from the control socket (check perror)
        !           304:     IECTRLCLOSE = 109,      // Control socket has closed unexpectedly
        !           305:     IEMESSAGE = 110,        // Received an unknown message
        !           306:     IESENDMESSAGE = 111,    // Unable to send control message to client/server (check perror)
        !           307:     IERECVMESSAGE = 112,    // Unable to receive control message from client/server (check perror)
        !           308:     IESENDPARAMS = 113,     // Unable to send parameters to server (check perror)
        !           309:     IERECVPARAMS = 114,     // Unable to receive parameters from client (check perror)
        !           310:     IEPACKAGERESULTS = 115, // Unable to package results (check perror)
        !           311:     IESENDRESULTS = 116,    // Unable to send results to client/server (check perror)
        !           312:     IERECVRESULTS = 117,    // Unable to receive results from client/server (check perror)
        !           313:     IESELECT = 118,         // Select failed (check perror)
        !           314:     IECLIENTTERM = 119,     // The client has terminated
        !           315:     IESERVERTERM = 120,     // The server has terminated
        !           316:     IEACCESSDENIED = 121,   // The server is busy running a test. Try again later.
        !           317:     IESETNODELAY = 122,     // Unable to set TCP/SCTP NODELAY (check perror)
        !           318:     IESETMSS = 123,         // Unable to set TCP/SCTP MSS (check perror)
        !           319:     IESETBUF = 124,         // Unable to set socket buffer size (check perror)
        !           320:     IESETTOS = 125,         // Unable to set IP TOS (check perror)
        !           321:     IESETCOS = 126,         // Unable to set IPv6 traffic class (check perror)
        !           322:     IESETFLOW = 127,        // Unable to set IPv6 flow label
        !           323:     IEREUSEADDR = 128,      // Unable to set reuse address on socket (check perror)
        !           324:     IENONBLOCKING = 129,    // Unable to set socket to non-blocking (check perror)
        !           325:     IESETWINDOWSIZE = 130,  // Unable to set socket window size (check perror)
        !           326:     IEPROTOCOL = 131,       // Protocol does not exist
        !           327:     IEAFFINITY = 132,       // Unable to set CPU affinity (check perror)
        !           328:     IEDAEMON = 133,        // Unable to become a daemon process
        !           329:     IESETCONGESTION = 134,  // Unable to set TCP_CONGESTION
        !           330:     IEPIDFILE = 135,       // Unable to write PID file
        !           331:     IEV6ONLY = 136,        // Unable to set/unset IPV6_V6ONLY (check perror)
        !           332:     IESETSCTPDISABLEFRAG = 137, // Unable to set SCTP Fragmentation (check perror)
        !           333:     IESETSCTPNSTREAM= 138,  //  Unable to set SCTP number of streams (check perror)
        !           334:     IESETSCTPBINDX= 139,    // Unable to process sctp_bindx() parameters
        !           335:     IESETPACING= 140,       // Unable to set socket pacing rate
        !           336:     /* Stream errors */
        !           337:     IECREATESTREAM = 200,   // Unable to create a new stream (check herror/perror)
        !           338:     IEINITSTREAM = 201,     // Unable to initialize stream (check herror/perror)
        !           339:     IESTREAMLISTEN = 202,   // Unable to start stream listener (check perror) 
        !           340:     IESTREAMCONNECT = 203,  // Unable to connect stream (check herror/perror)
        !           341:     IESTREAMACCEPT = 204,   // Unable to accepte stream connection (check perror)
        !           342:     IESTREAMWRITE = 205,    // Unable to write to stream socket (check perror)
        !           343:     IESTREAMREAD = 206,     // Unable to read from stream (check perror)
        !           344:     IESTREAMCLOSE = 207,    // Stream has closed unexpectedly
        !           345:     IESTREAMID = 208,       // Stream has invalid ID
        !           346:     /* Timer errors */
        !           347:     IENEWTIMER = 300,       // Unable to create new timer (check perror)
        !           348:     IEUPDATETIMER = 301,    // Unable to update timer (check perror)
        !           349: };
        !           350: 
        !           351: #endif /* !__IPERF_API_H */

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>