Some changes to the iperf3 API to work with bwctl, mostly having to

do with what defs are in which include file.  End result is we now have
only one public include file, iperf_api.h.
This commit is contained in:
jef 2012-09-28 16:00:14 -07:00
parent 56a97f9337
commit 98ce496b1b
18 changed files with 401 additions and 242 deletions

View File

@ -1,7 +1,7 @@
lib_LIBRARIES = libiperf.a # Build and install a static iperf library lib_LIBRARIES = libiperf.a # Build and install a static iperf library
bin_PROGRAMS = iperf3 # Build and install an iperf binary bin_PROGRAMS = iperf3 # Build and install an iperf binary
noinst_PROGRAMS = t_timer t_units t_uuid iperf3_profile # Build, but don't install the test programs and a profiled version of iperf3 noinst_PROGRAMS = t_timer t_units t_uuid iperf3_profile # Build, but don't install the test programs and a profiled version of iperf3
include_HEADERS = iperf_api.h iperf_error.h iperf_client_api.h iperf_server_api.h # Defines the headers that get installed with the program include_HEADERS = iperf_api.h # Defines the headers that get installed with the program
# Specify the source files and flags for the iperf library # Specify the source files and flags for the iperf library
@ -10,11 +10,8 @@ libiperf_a_SOURCES = \
iperf_api.c \ iperf_api.c \
iperf_api.h \ iperf_api.h \
iperf_error.c \ iperf_error.c \
iperf_error.h \ iperf_client_api.c \
iperf_client_api.c \
iperf_client_api.h \
iperf_server_api.c \ iperf_server_api.c \
iperf_server_api.h \
iperf_tcp.c \ iperf_tcp.c \
iperf_tcp.h \ iperf_tcp.h \
iperf_udp.c \ iperf_udp.c \

View File

@ -231,7 +231,7 @@ sharedstatedir = @sharedstatedir@
sysconfdir = @sysconfdir@ sysconfdir = @sysconfdir@
target_alias = @target_alias@ target_alias = @target_alias@
lib_LIBRARIES = libiperf.a # Build and install a static iperf library lib_LIBRARIES = libiperf.a # Build and install a static iperf library
include_HEADERS = iperf_api.h iperf_error.h iperf_client_api.h iperf_server_api.h # Defines the headers that get installed with the program include_HEADERS = iperf_api.h # Defines the headers that get installed with the program
# Specify the source files and flags for the iperf library # Specify the source files and flags for the iperf library
libiperf_a_SOURCES = \ libiperf_a_SOURCES = \
@ -239,11 +239,8 @@ libiperf_a_SOURCES = \
iperf_api.c \ iperf_api.c \
iperf_api.h \ iperf_api.h \
iperf_error.c \ iperf_error.c \
iperf_error.h \ iperf_client_api.c \
iperf_client_api.c \
iperf_client_api.h \
iperf_server_api.c \ iperf_server_api.c \
iperf_server_api.h \
iperf_tcp.c \ iperf_tcp.c \
iperf_tcp.h \ iperf_tcp.h \
iperf_udp.c \ iperf_udp.c \

View File

@ -48,7 +48,7 @@ struct iperf_stream_result
void *data; void *data;
}; };
#define COOKIE_SIZE 37 /* size of an ascii uuid */ #define COOKIE_SIZE 37 /* size of an ascii uuid */
struct iperf_settings struct iperf_settings
{ {
int domain; /* AF_INET or AF_INET6 */ int domain; /* AF_INET or AF_INET6 */
@ -173,52 +173,23 @@ struct iperf_test
void (*on_test_finish)(struct iperf_test *); void (*on_test_finish)(struct iperf_test *);
}; };
enum /* default settings */
{ #define PORT 5201 /* default port to listen on (don't use the same port as iperf2) */
/* default settings */ #define uS_TO_NS 1000
Ptcp = SOCK_STREAM, #define SEC_TO_US 1000000
Pudp = SOCK_DGRAM, #define RATE (1024 * 1024) /* 1 Mbps */
PORT = 5201, /* default port to listen on (don't use the same port as iperf2) */ #define DURATION 5 /* seconds */
uS_TO_NS = 1000,
SEC_TO_US = 1000000,
RATE = 1024 * 1024, /* 1 Mbps */
DURATION = 5, /* seconds */
DEFAULT_UDP_BLKSIZE = 1450, /* 1 packet per ethernet frame, IPV6 too */
DEFAULT_TCP_BLKSIZE = 128 * 1024, /* default read/write block size */
/* other useful constants */ #define SEC_TO_NS 1000000000 /* too big for enum/const on some platforms */
TEST_START = 1,
TEST_RUNNING = 2,
RESULT_REQUEST = 3,
TEST_END = 4,
STREAM_BEGIN = 5,
STREAM_RUNNING = 6,
STREAM_END = 7,
ALL_STREAMS_END = 8,
PARAM_EXCHANGE = 9,
CREATE_STREAMS = 10,
SERVER_TERMINATE = 11,
CLIENT_TERMINATE = 12,
EXCHANGE_RESULTS = 13,
DISPLAY_RESULTS = 14,
IPERF_START = 15,
IPERF_DONE = 16,
ACCESS_DENIED = -1,
SERVER_ERROR = -2,
};
#define SEC_TO_NS 1000000000 /* too big for enum on some platforms */
#define MAX_RESULT_STRING 4096 #define MAX_RESULT_STRING 4096
/* constants for command line arg sanity checks /* constants for command line arg sanity checks */
*/ #define MB (1024 * 1024)
#define MB 1024 * 1024 #define MAX_TCP_BUFFER (128 * MB)
#define MAX_TCP_BUFFER 128 * MB
#define MAX_BLOCKSIZE MB #define MAX_BLOCKSIZE MB
#define MAX_INTERVAL 60 #define MAX_INTERVAL 60
#define MAX_TIME 3600 #define MAX_TIME 3600
#define MAX_MSS 9 * 1024 #define MAX_MSS (9 * 1024)
#define MAX_STREAMS 128 #define MAX_STREAMS 128
#endif #endif /* !__IPERF_H */

View File

@ -34,7 +34,6 @@
#include "iperf_api.h" #include "iperf_api.h"
#include "iperf_udp.h" #include "iperf_udp.h"
#include "iperf_tcp.h" #include "iperf_tcp.h"
#include "iperf_error.h"
#include "timer.h" #include "timer.h"
#include "units.h" #include "units.h"
@ -67,6 +66,142 @@ void warning(char *str)
} }
/************** Getter routines for some fields inside iperf_test *************/
int
iperf_get_test_duration( struct iperf_test* ipt )
{
return ipt->duration;
}
uint64_t
iperf_get_test_rate( struct iperf_test* ipt )
{
return ipt->settings->rate;
}
char
iperf_get_test_role( struct iperf_test* ipt )
{
return ipt->role;
}
int
iperf_get_test_blksize( struct iperf_test* ipt )
{
return ipt->settings->blksize;
}
int
iperf_get_test_socket_bufsize( struct iperf_test* ipt )
{
return ipt->settings->socket_bufsize;
}
double
iperf_get_test_reporter_interval( struct iperf_test* ipt )
{
return ipt->reporter_interval;
}
double
iperf_get_test_stats_interval( struct iperf_test* ipt )
{
return ipt->stats_interval;
}
int
iperf_get_test_num_streams( struct iperf_test* ipt )
{
return ipt->num_streams;
}
int
iperf_get_test_server_port( struct iperf_test* ipt )
{
return ipt->server_port;
}
char*
iperf_get_test_server_hostname( struct iperf_test* ipt )
{
return ipt->server_hostname;
}
int
iperf_get_test_protocol_id( struct iperf_test* ipt )
{
return ipt->protocol->id;
}
/************** Setter routines for some fields inside iperf_test *************/
void
iperf_set_test_duration( struct iperf_test* ipt, int duration )
{
ipt->duration = duration;
}
void
iperf_set_test_reporter_interval( struct iperf_test* ipt, double reporter_interval )
{
ipt->reporter_interval = reporter_interval;
}
void
iperf_set_test_stats_interval( struct iperf_test* ipt, double stats_interval )
{
ipt->stats_interval = stats_interval;
}
void
iperf_set_test_state( struct iperf_test* ipt, char state )
{
ipt->state = state;
}
void
iperf_set_test_blksize( struct iperf_test* ipt, int blksize )
{
ipt->settings->blksize = blksize;
}
void
iperf_set_test_rate( struct iperf_test* ipt, uint64_t rate )
{
ipt->settings->rate = rate;
}
void
iperf_set_test_server_port( struct iperf_test* ipt, int server_port )
{
ipt->server_port = server_port;
}
void
iperf_set_test_socket_bufsize( struct iperf_test* ipt, int socket_bufsize )
{
ipt->settings->socket_bufsize = socket_bufsize;
}
void
iperf_set_test_num_streams( struct iperf_test* ipt, int num_streams )
{
ipt->num_streams = num_streams;
}
void
iperf_set_test_role( struct iperf_test* ipt, char role )
{
ipt->role = role;
}
void
iperf_set_test_server_hostname( struct iperf_test* ipt, char* server_hostname )
{
ipt->server_hostname = server_hostname;
}
/********************** Get/set test protocol structure ***********************/ /********************** Get/set test protocol structure ***********************/
struct protocol * struct protocol *
@ -600,6 +735,14 @@ package_parameters(struct iperf_test *test)
} }
/*!!! Forwards for debugging getopt version. */
int myopterr = 1;
int myoptind = 0;
int myoptopt;
char *myoptarg;
int mygetopt(int argc, char **argv, char *opts);
int int
parse_parameters(struct iperf_test *test) parse_parameters(struct iperf_test *test)
{ {
@ -630,19 +773,19 @@ parse_parameters(struct iperf_test *test)
} }
// XXX: Should we check for parameters exceeding maximum values here? // XXX: Should we check for parameters exceeding maximum values here?
while ((ch = getopt(n, params, "pt:n:m:uNP:Rw:l:b:S:")) != -1) { while ((ch = mygetopt(n, params, "pt:n:m:uNP:Rw:l:b:S:")) != -1) {
switch (ch) { switch (ch) {
case 'p': case 'p':
set_protocol(test, Ptcp); set_protocol(test, Ptcp);
break; break;
case 't': case 't':
test->duration = atoi(optarg); test->duration = atoi(myoptarg);
break; break;
case 'n': case 'n':
test->settings->bytes = atoll(optarg); test->settings->bytes = atoll(myoptarg);
break; break;
case 'm': case 'm':
test->settings->mss = atoi(optarg); test->settings->mss = atoi(myoptarg);
break; break;
case 'u': case 'u':
set_protocol(test, Pudp); set_protocol(test, Pudp);
@ -651,22 +794,22 @@ parse_parameters(struct iperf_test *test)
test->no_delay = 1; test->no_delay = 1;
break; break;
case 'P': case 'P':
test->num_streams = atoi(optarg); test->num_streams = atoi(myoptarg);
break; break;
case 'R': case 'R':
test->reverse = 1; test->reverse = 1;
break; break;
case 'w': case 'w':
test->settings->socket_bufsize = atoi(optarg); test->settings->socket_bufsize = atoi(myoptarg);
break; break;
case 'l': case 'l':
test->settings->blksize = atoi(optarg); test->settings->blksize = atoi(myoptarg);
break; break;
case 'b': case 'b':
test->settings->rate = atoll(optarg); test->settings->rate = atoll(myoptarg);
break; break;
case 'S': case 'S':
test->settings->tos = atoi(optarg); test->settings->tos = atoi(myoptarg);
break; break;
} }
} }
@ -900,7 +1043,7 @@ parse_results(struct iperf_test *test, char *results)
} }
} }
for (strp; *strp; strp = strchr(strp, '\n')+1) { for (; *strp; strp = strchr(strp, '\n')+1) {
sscanf(strp, "%d:%llu,%lf,%d,%d\n", &sid, &bytes_transferred, &jitter, sscanf(strp, "%d:%llu,%lf,%d,%d\n", &sid, &bytes_transferred, &jitter,
&cerror, &pcount); &cerror, &pcount);
SLIST_FOREACH(sp, &test->streams, streams) SLIST_FOREACH(sp, &test->streams, streams)
@ -1201,8 +1344,8 @@ iperf_print_intermediate(struct iperf_test *test)
char ubuf[UNIT_LEN]; char ubuf[UNIT_LEN];
char nbuf[UNIT_LEN]; char nbuf[UNIT_LEN];
struct iperf_stream *sp = NULL; struct iperf_stream *sp = NULL;
iperf_size_t bytes = 0, bytes_sent = 0, bytes_received = 0; iperf_size_t bytes = 0;
double start_time, end_time, avg_jitter; double start_time, end_time;
struct iperf_interval_results *ip = NULL; struct iperf_interval_results *ip = NULL;
SLIST_FOREACH(sp, &test->streams, streams) { SLIST_FOREACH(sp, &test->streams, streams) {
@ -1239,10 +1382,10 @@ iperf_print_results (struct iperf_test *test)
char ubuf[UNIT_LEN]; char ubuf[UNIT_LEN];
char nbuf[UNIT_LEN]; char nbuf[UNIT_LEN];
struct iperf_stream *sp = NULL; struct iperf_stream *sp = NULL;
iperf_size_t bytes = 0, bytes_sent = 0, bytes_received = 0; iperf_size_t bytes_sent = 0, bytes_received = 0;
iperf_size_t total_sent = 0, total_received = 0; iperf_size_t total_sent = 0, total_received = 0;
double start_time, end_time, avg_jitter; double start_time, end_time, avg_jitter;
struct iperf_interval_results *ip = NULL;
/* print final summary for all intervals */ /* print final summary for all intervals */
printf(report_bw_header); printf(report_bw_header);
@ -1250,6 +1393,7 @@ iperf_print_results (struct iperf_test *test)
start_time = 0.; start_time = 0.;
sp = SLIST_FIRST(&test->streams); sp = SLIST_FIRST(&test->streams);
end_time = timeval_diff(&sp->result->start_time, &sp->result->end_time); end_time = timeval_diff(&sp->result->start_time, &sp->result->end_time);
avg_jitter = 0;
SLIST_FOREACH(sp, &test->streams, streams) { SLIST_FOREACH(sp, &test->streams, streams) {
bytes_sent = sp->result->bytes_sent; bytes_sent = sp->result->bytes_sent;
bytes_received = sp->result->bytes_received; bytes_received = sp->result->bytes_received;
@ -1326,15 +1470,6 @@ iperf_print_results (struct iperf_test *test)
void void
iperf_reporter_callback(struct iperf_test * test) iperf_reporter_callback(struct iperf_test * test)
{ {
int total_packets = 0, lost_packets = 0;
char ubuf[UNIT_LEN];
char nbuf[UNIT_LEN];
struct iperf_stream *sp = NULL;
iperf_size_t bytes = 0, bytes_sent = 0, bytes_received = 0;
iperf_size_t total_sent = 0, total_received = 0;
double start_time, end_time, avg_jitter;
struct iperf_interval_results *ip = NULL;
switch (test->state) { switch (test->state) {
case TEST_RUNNING: case TEST_RUNNING:
case STREAM_RUNNING: case STREAM_RUNNING:
@ -1517,3 +1652,63 @@ sig_handler(int sig)
longjmp(env, 1); longjmp(env, 1);
} }
/*!!!*/
/* This is an old tiny version of getopt from Usenet mod.std.unix back
** in 1985. I added it here to help debug a SEGV error that was occuring
** inside the standard libc getopt(). However the SEGV does not occur
** with this version. I'm sure the underlying bug is still lurking in
** the code somewhere, but for now it is not being triggered.
*/
#define ERR(s, c) if(myopterr){\
char errbuf[2];\
errbuf[0] = c; errbuf[1] = '\n';\
(void) write(2, argv[0], (unsigned)strlen(argv[0]));\
(void) write(2, s, (unsigned)strlen(s));\
(void) write(2, errbuf, 2);}
int
mygetopt(int argc, char **argv, char *opts)
{
static int sp = 1;
register int c;
register char *cp;
if(sp == 1) {
if(myoptind >= argc ||
argv[myoptind][0] != '-' || argv[myoptind][1] == '\0')
return(EOF);
else if(strcmp(argv[myoptind], "--") == 0) {
myoptind++;
return(EOF);
}
}
myoptopt = c = argv[myoptind][sp];
if(c == ':' || (cp=strchr(opts, c)) == NULL) {
ERR(": illegal option -- ", c);
if(argv[myoptind][++sp] == '\0') {
myoptind++;
sp = 1;
}
return('?');
}
if(*++cp == ':') {
if(argv[myoptind][sp+1] != '\0')
myoptarg = &argv[myoptind++][sp+1];
else if(++myoptind >= argc) {
ERR(": option requires an argument -- ", c);
sp = 1;
return('?');
} else
myoptarg = argv[myoptind++];
sp = 1;
} else {
if(argv[myoptind][++sp] == '\0') {
sp = 1;
myoptind++;
}
myoptarg = NULL;
}
return(c);
}

View File

@ -11,7 +11,63 @@
#define __IPERF_API_H #define __IPERF_API_H
#include <setjmp.h> #include <setjmp.h>
#include "iperf.h"
struct iperf_test;
struct iperf_stream_result;
struct iperf_interval_results;
struct iperf_stream;
/* default settings */
#define Ptcp SOCK_STREAM
#define Pudp SOCK_DGRAM
#define DEFAULT_UDP_BLKSIZE 1450 /* 1 packet per ethernet frame, IPV6 too */
#define DEFAULT_TCP_BLKSIZE (128 * 1024) /* default read/write block size */
/* states */
#define TEST_START 1
#define TEST_RUNNING 2
#define RESULT_REQUEST 3
#define TEST_END 4
#define STREAM_BEGIN 5
#define STREAM_RUNNING 6
#define STREAM_END 7
#define ALL_STREAMS_END 8
#define PARAM_EXCHANGE 9
#define CREATE_STREAMS 10
#define SERVER_TERMINATE 11
#define CLIENT_TERMINATE 12
#define EXCHANGE_RESULTS 13
#define DISPLAY_RESULTS 14
#define IPERF_START 15
#define IPERF_DONE 16
#define ACCESS_DENIED (-1)
#define SERVER_ERROR (-2)
/* Getter routines for some fields inside iperf_test. */
int iperf_get_test_duration( struct iperf_test* ipt );
char iperf_get_test_role( struct iperf_test* ipt );
int iperf_get_test_blksize( struct iperf_test* ipt );
uint64_t iperf_get_test_rate( struct iperf_test* ipt );
int iperf_get_test_socket_bufsize( struct iperf_test* ipt );
double iperf_get_test_reporter_interval( struct iperf_test* ipt );
double iperf_get_test_stats_interval( struct iperf_test* ipt );
int iperf_get_test_num_streams( struct iperf_test* ipt );
int iperf_get_test_server_port( struct iperf_test* ipt );
char* iperf_get_test_server_hostname( struct iperf_test* ipt );
int iperf_get_test_protocol_id( struct iperf_test* ipt );
/* Setter routines for some fields inside iperf_test. */
void iperf_set_test_duration( struct iperf_test* ipt, int duration );
void iperf_set_test_reporter_interval( struct iperf_test* ipt, double reporter_interval );
void iperf_set_test_stats_interval( struct iperf_test* ipt, double stats_interval );
void iperf_set_test_state( struct iperf_test* ipt, char state );
void iperf_set_test_blksize( struct iperf_test* ipt, int blksize );
void iperf_set_test_rate( struct iperf_test* ipt, uint64_t rate );
void iperf_set_test_server_port( struct iperf_test* ipt, int server_port );
void iperf_set_test_socket_bufsize( struct iperf_test* ipt, int socket_bufsize );
void iperf_set_test_num_streams( struct iperf_test* ipt, int num_streams );
void iperf_set_test_role( struct iperf_test* ipt, char role );
void iperf_set_test_server_hostname( struct iperf_test* ipt, char* server_hostname );
/** /**
* exchange_parameters - handles the param_Exchange part for client * exchange_parameters - handles the param_Exchange part for client
@ -121,5 +177,81 @@ void iperf_on_test_finish(struct iperf_test *);
extern jmp_buf env; extern jmp_buf env;
#endif /* Client routines. */
int iperf_run_client(struct iperf_test *);
int iperf_connect(struct iperf_test *);
int iperf_create_streams(struct iperf_test *);
int iperf_handle_message_client(struct iperf_test *);
int iperf_client_end(struct iperf_test *);
/* Server routines. */
int iperf_run_server(struct iperf_test *);
int iperf_server_listen(struct iperf_test *);
int iperf_accept(struct iperf_test *);
int iperf_handle_message_server(struct iperf_test *);
void iperf_test_reset(struct iperf_test *);
/* Error routines. */
void iperf_error(char *);
char *iperf_strerror(int);
extern int i_errno;
enum {
IENONE = 0, // No error
/* Parameter errors */
IESERVCLIENT = 1, // Iperf cannot be both server and client
IENOROLE = 2, // Iperf must either be a client (-c) or server (-s)
IECLIENTONLY = 3, // This option is client only
IEDURATION = 4, // test duration too long. Maximum value = %dMAX_TIME
IENUMSTREAMS = 5, // Number of parallel streams too large. Maximum value = %dMAX_STREAMS
IEBLOCKSIZE = 6, // Block size too large. Maximum value = %dMAX_BLOCKSIZE
IEBUFSIZE = 7, // Socket buffer size too large. Maximum value = %dMAX_TCP_BUFFER
IEINTERVAL = 8, // Report interval too large. Maxumum value = %dMAX_INTERVAL
IEMSS = 9, // MSS too large. Maximum value = %dMAX_MSS
/* Test errors */
IENEWTEST = 10, // Unable to create a new test (check perror)
IEINITTEST = 11, // Test initialization failed (check perror)
IELISTEN = 12, // Unable to listen for connections (check perror)
IECONNECT = 13, // Unable to connect to server (check herror/perror) [from netdial]
IEACCEPT = 14, // Unable to accept connection from client (check herror/perror)
IESENDCOOKIE = 15, // Unable to send cookie to server (check perror)
IERECVCOOKIE = 16, // Unable to receive cookie from client (check perror)
IECTRLWRITE = 17, // Unable to write to the control socket (check perror)
IECTRLREAD = 18, // Unable to read from the control socket (check perror)
IECTRLCLOSE = 19, // Control socket has closed unexpectedly
IEMESSAGE = 20, // Received an unknown message
IESENDMESSAGE = 21, // Unable to send control message to client/server (check perror)
IERECVMESSAGE = 22, // Unable to receive control message from client/server (check perror)
IESENDPARAMS = 23, // Unable to send parameters to server (check perror)
IERECVPARAMS = 24, // Unable to receive parameters from client (check perror)
IEPACKAGERESULTS = 25, // Unable to package results (check perror)
IESENDRESULTS = 26, // Unable to send results to client/server (check perror)
IERECVRESULTS = 27, // Unable to receive results from client/server (check perror)
IESELECT = 28, // Select failed (check perror)
IECLIENTTERM = 29, // The client has terminated
IESERVERTERM = 30, // The server has terminated
IEACCESSDENIED = 31, // The server is busy running a test. Try again later.
IESETNODELAY = 32, // Unable to set TCP NODELAY (check perror)
IESETMSS = 33, // Unable to set TCP MSS (check perror)
IESETBUF = 34, // Unable to set socket buffer size (check perror)
IESETTOS = 35, // Unable to set IP TOS (check perror)
IESETCOS = 36, // Unable to set IPv6 traffic class (check perror)
IEREUSEADDR = 37, // Unable to set reuse address on socket (check perror)
IENONBLOCKING = 38, // Unable to set socket to non-blocking (check perror)
IESETWINDOWSIZE = 39, // Unable to set socket window size (check perror)
IEPROTOCOL = 40, // Protocol does not exist
/* Stream errors */
IECREATESTREAM = 41, // Unable to create a new stream (check herror/perror)
IEINITSTREAM = 42, // Unable to initialize stream (check herror/perror)
IESTREAMLISTEN = 43, // Unable to start stream listener (check perror)
IESTREAMCONNECT = 44, // Unable to connect stream (check herror/perror)
IESTREAMACCEPT = 45, // Unable to accepte stream connection (check perror)
IESTREAMWRITE = 46, // Unable to write to stream socket (check perror)
IESTREAMREAD = 47, // Unable to read from stream (check perror)
IESTREAMCLOSE = 48, // Stream has closed unexpectedly
IESTREAMID = 49, // Stream has invalid ID
/* Timer errors */
IENEWTIMER = 50, // Unable to create new timer (check perror)
IEUPDATETIMER = 51, // Unable to update timer (check perror)
};
#endif /* !__IPERF_API_H */

View File

@ -15,11 +15,10 @@
#include <sys/types.h> #include <sys/types.h>
#include <sys/select.h> #include <sys/select.h>
#include <sys/uio.h> #include <sys/uio.h>
#include <arpa/inet.h>
#include "iperf.h" #include "iperf.h"
#include "iperf_api.h" #include "iperf_api.h"
#include "iperf_client_api.h"
#include "iperf_error.h"
#include "iperf_util.h" #include "iperf_util.h"
#include "net.h" #include "net.h"
#include "timer.h" #include "timer.h"
@ -69,24 +68,28 @@ iperf_handle_message_client(struct iperf_test *test)
switch (test->state) { switch (test->state) {
case PARAM_EXCHANGE: case PARAM_EXCHANGE:
if (iperf_exchange_parameters(test) < 0) if (iperf_exchange_parameters(test) < 0) {
return (-1); return (-1);
}
if (test->on_connect) if (test->on_connect)
test->on_connect(test); test->on_connect(test);
break; break;
case CREATE_STREAMS: case CREATE_STREAMS:
if (iperf_create_streams(test) < 0) if (iperf_create_streams(test) < 0) {
return (-1); return (-1);
}
break; break;
case TEST_START: case TEST_START:
if (iperf_init_test(test) < 0) if (iperf_init_test(test) < 0) {
return (-1); return (-1);
}
break; break;
case TEST_RUNNING: case TEST_RUNNING:
break; break;
case EXCHANGE_RESULTS: case EXCHANGE_RESULTS:
if (iperf_exchange_results(test) < 0) if (iperf_exchange_results(test) < 0) {
return (-1); return (-1);
}
break; break;
case DISPLAY_RESULTS: case DISPLAY_RESULTS:
if (test->on_test_finish) if (test->on_test_finish)
@ -204,20 +207,23 @@ iperf_run_client(struct iperf_test * test)
return (-1); return (-1);
} else if (result > 0) { } else if (result > 0) {
if (FD_ISSET(test->ctrl_sck, &temp_read_set)) { if (FD_ISSET(test->ctrl_sck, &temp_read_set)) {
if (iperf_handle_message_client(test) < 0) if (iperf_handle_message_client(test) < 0) {
return (-1); return (-1);
}
FD_CLR(test->ctrl_sck, &temp_read_set); FD_CLR(test->ctrl_sck, &temp_read_set);
} }
if (test->state == TEST_RUNNING) { if (test->state == TEST_RUNNING) {
if (test->reverse) { if (test->reverse) {
// Reverse mode. Client receives. // Reverse mode. Client receives.
if (iperf_recv(test) < 0) if (iperf_recv(test) < 0) {
return (-1); return (-1);
}
} else { } else {
// Regular mode. Client sends. // Regular mode. Client sends.
if (iperf_send(test) < 0) if (iperf_send(test) < 0) {
return (-1); return (-1);
}
} }
/* Perform callbacks */ /* Perform callbacks */
@ -225,15 +231,17 @@ iperf_run_client(struct iperf_test * test)
test->stats_callback(test); test->stats_callback(test);
sec = (time_t) test->stats_interval; sec = (time_t) test->stats_interval;
usec = (test->stats_interval - sec) * SEC_TO_US; usec = (test->stats_interval - sec) * SEC_TO_US;
if (update_timer(test->stats_timer, sec, usec) < 0) if (update_timer(test->stats_timer, sec, usec) < 0) {
return (-1); return (-1);
}
} }
if (timer_expired(test->reporter_timer)) { if (timer_expired(test->reporter_timer)) {
test->reporter_callback(test); test->reporter_callback(test);
sec = (time_t) test->reporter_interval; sec = (time_t) test->reporter_interval;
usec = (test->reporter_interval - sec) * SEC_TO_US; usec = (test->reporter_interval - sec) * SEC_TO_US;
if (update_timer(test->reporter_timer, sec, usec) < 0) if (update_timer(test->reporter_timer, sec, usec) < 0) {
return (-1); return (-1);
}
} }
/* Send TEST_END if all data has been sent or timer expired */ /* Send TEST_END if all data has been sent or timer expired */

View File

@ -1,26 +0,0 @@
/*
* Copyright (c) 2009-2011, The Regents of the University of California,
* through Lawrence Berkeley National Laboratory (subject to receipt of any
* required approvals from the U.S. Dept. of Energy). All rights reserved.
*
* This code is distributed under a BSD style license, see the LICENSE file
* for complete information.
*/
#ifndef __IPERF_CLIENT_API_H
#define __IPERF_CLIENT_API_H
#include "iperf.h"
int iperf_run_client(struct iperf_test *);
int iperf_connect(struct iperf_test *);
int iperf_create_streams(struct iperf_test *);
int iperf_handle_message_client(struct iperf_test *);
int iperf_client_end(struct iperf_test *);
#endif

View File

@ -12,7 +12,7 @@
#include <netdb.h> #include <netdb.h>
#include <string.h> #include <string.h>
#include "iperf.h" #include "iperf.h"
#include "iperf_error.h" #include "iperf_api.h"
int i_errno; int i_errno;

View File

@ -1,87 +0,0 @@
/*
* Copyright (c) 2009-2011, The Regents of the University of California,
* through Lawrence Berkeley National Laboratory (subject to receipt of any
* required approvals from the U.S. Dept. of Energy). All rights reserved.
*
* This code is distributed under a BSD style license, see the LICENSE file
* for complete information.
*/
/* iperf_error.h
*
* Iperf error handling
*/
#ifndef __IPERF_ERROR_H
#define __IPERF_ERROR_H
void iperf_error(char *);
char *iperf_strerror(int);
extern int i_errno;
enum {
IENONE = 0, // No error
/* Parameter errors */
IESERVCLIENT = 1, // Iperf cannot be both server and client
IENOROLE = 2, // Iperf must either be a client (-c) or server (-s)
IECLIENTONLY = 3, // This option is client only
IEDURATION = 4, // test duration too long. Maximum value = %dMAX_TIME
IENUMSTREAMS = 5, // Number of parallel streams too large. Maximum value = %dMAX_STREAMS
IEBLOCKSIZE = 6, // Block size too large. Maximum value = %dMAX_BLOCKSIZE
IEBUFSIZE = 7, // Socket buffer size too large. Maximum value = %dMAX_TCP_BUFFER
IEINTERVAL = 8, // Report interval too large. Maxumum value = %dMAX_INTERVAL
IEMSS = 9, // MSS too large. Maximum value = %dMAX_MSS
/* Test errors */
IENEWTEST = 10, // Unable to create a new test (check perror)
IEINITTEST = 11, // Test initialization failed (check perror)
IELISTEN = 12, // Unable to listen for connections (check perror)
IECONNECT = 13, // Unable to connect to server (check herror/perror) [from netdial]
IEACCEPT = 14, // Unable to accept connection from client (check herror/perror)
IESENDCOOKIE = 15, // Unable to send cookie to server (check perror)
IERECVCOOKIE = 16, // Unable to receive cookie from client (check perror)
IECTRLWRITE = 17, // Unable to write to the control socket (check perror)
IECTRLREAD = 18, // Unable to read from the control socket (check perror)
IECTRLCLOSE = 19, // Control socket has closed unexpectedly
IEMESSAGE = 20, // Received an unknown message
IESENDMESSAGE = 21, // Unable to send control message to client/server (check perror)
IERECVMESSAGE = 22, // Unable to receive control message from client/server (check perror)
IESENDPARAMS = 23, // Unable to send parameters to server (check perror)
IERECVPARAMS = 24, // Unable to receive parameters from client (check perror)
IEPACKAGERESULTS = 25, // Unable to package results (check perror)
IESENDRESULTS = 26, // Unable to send results to client/server (check perror)
IERECVRESULTS = 27, // Unable to receive results from client/server (check perror)
IESELECT = 28, // Select failed (check perror)
IECLIENTTERM = 29, // The client has terminated
IESERVERTERM = 30, // The server has terminated
IEACCESSDENIED = 31, // The server is busy running a test. Try again later.
IESETNODELAY = 32, // Unable to set TCP NODELAY (check perror)
IESETMSS = 33, // Unable to set TCP MSS (check perror)
IESETBUF = 34, // Unable to set socket buffer size (check perror)
IESETTOS = 35, // Unable to set IP TOS (check perror)
IESETCOS = 36, // Unable to set IPv6 traffic class (check perror)
IEREUSEADDR = 37, // Unable to set reuse address on socket (check perror)
IENONBLOCKING = 38, // Unable to set socket to non-blocking (check perror)
IESETWINDOWSIZE = 39, // Unable to set socket window size (check perror)
IEPROTOCOL = 40, // Protocol does not exist
/* Stream errors */
IECREATESTREAM = 41, // Unable to create a new stream (check herror/perror)
IEINITSTREAM = 42, // Unable to initialize stream (check herror/perror)
IESTREAMLISTEN = 43, // Unable to start stream listener (check perror)
IESTREAMCONNECT = 44, // Unable to connect stream (check herror/perror)
IESTREAMACCEPT = 45, // Unable to accepte stream connection (check perror)
IESTREAMWRITE = 46, // Unable to write to stream socket (check perror)
IESTREAMREAD = 47, // Unable to read from stream (check perror)
IESTREAMCLOSE = 48, // Stream has closed unexpectedly
IESTREAMID = 49, // Stream has invalid ID
/* Timer errors */
IENEWTIMER = 50, // Unable to create new timer (check perror)
IEUPDATETIMER = 51, // Unable to update timer (check perror)
};
#endif

View File

@ -32,11 +32,9 @@
#include <setjmp.h> #include <setjmp.h>
#include "iperf.h" #include "iperf.h"
#include "iperf_server_api.h"
#include "iperf_api.h" #include "iperf_api.h"
#include "iperf_udp.h" #include "iperf_udp.h"
#include "iperf_tcp.h" #include "iperf_tcp.h"
#include "iperf_error.h"
#include "iperf_util.h" #include "iperf_util.h"
#include "timer.h" #include "timer.h"
#include "net.h" #include "net.h"
@ -49,9 +47,6 @@
int int
iperf_server_listen(struct iperf_test *test) iperf_server_listen(struct iperf_test *test)
{ {
char ubuf[UNIT_LEN];
int x;
if((test->listener = netannounce(test->settings->domain, Ptcp, test->bind_address, test->server_port)) < 0) { if((test->listener = netannounce(test->settings->domain, Ptcp, test->bind_address, test->server_port)) < 0) {
i_errno = IELISTEN; i_errno = IELISTEN;
return (-1); return (-1);
@ -72,6 +67,9 @@ iperf_server_listen(struct iperf_test *test)
// XXX: This code needs to be moved to after parameter exhange // XXX: This code needs to be moved to after parameter exhange
/* /*
char ubuf[UNIT_LEN];
int x;
if (test->protocol->id == Ptcp) { if (test->protocol->id == Ptcp) {
if (test->settings->socket_bufsize > 0) { if (test->settings->socket_bufsize > 0) {
unit_snprintf(ubuf, UNIT_LEN, (double) x, 'A'); unit_snprintf(ubuf, UNIT_LEN, (double) x, 'A');
@ -402,4 +400,3 @@ iperf_run_server(struct iperf_test *test)
return (0); return (0);
} }

View File

@ -1,26 +0,0 @@
/*
* Copyright (c) 2009-2011, The Regents of the University of California,
* through Lawrence Berkeley National Laboratory (subject to receipt of any
* required approvals from the U.S. Dept. of Energy). All rights reserved.
*
* This code is distributed under a BSD style license, see the LICENSE file
* for complete information.
*/
#ifndef __IPERF_SERVER_API_H
#define __IPERF_SERVER_API_H
#include "iperf.h"
int iperf_run_server(struct iperf_test *);
int iperf_server_listen(struct iperf_test *);
int iperf_accept(struct iperf_test *);
int iperf_handle_message_server(struct iperf_test *);
void iperf_test_reset(struct iperf_test *);
#endif

View File

@ -23,7 +23,6 @@
#include "iperf.h" #include "iperf.h"
#include "iperf_api.h" #include "iperf_api.h"
#include "iperf_tcp.h" #include "iperf_tcp.h"
#include "iperf_error.h"
#include "net.h" #include "net.h"

View File

@ -23,7 +23,6 @@
#include "iperf.h" #include "iperf.h"
#include "iperf_api.h" #include "iperf_api.h"
#include "iperf_udp.h" #include "iperf_udp.h"
#include "iperf_error.h"
#include "timer.h" #include "timer.h"
#include "net.h" #include "net.h"

View File

@ -15,8 +15,12 @@
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <unistd.h>
#include <string.h> #include <string.h>
#include <sys/select.h> #include <sys/select.h>
#include <sys/types.h>
#include <sys/time.h>
#include <time.h>
#include <errno.h> #include <errno.h>
#include "config.h" #include "config.h"
@ -44,7 +48,7 @@ make_cookie(char *cookie)
/* Generate a string based on hostname, time, randomness, and filler. */ /* Generate a string based on hostname, time, randomness, and filler. */
(void) gethostname(hostname, sizeof(hostname)); (void) gethostname(hostname, sizeof(hostname));
(void) gettimeofday(&tv, 0); (void) gettimeofday(&tv, 0);
(void) snprintf(temp, sizeof(temp), "%s.%d.%06d.%08lx%08lx.%s", hostname, tv.tv_sec, tv.tv_usec, (unsigned long int) random(), (unsigned long int) random(), "1234567890123456789012345678901234567890"); (void) snprintf(temp, sizeof(temp), "%s.%ld.%06ld.%08lx%08lx.%s", hostname, tv.tv_sec, tv.tv_usec, (unsigned long int) random(), (unsigned long int) random(), "1234567890123456789012345678901234567890");
/* Now truncate it to 36 bytes and terminate. */ /* Now truncate it to 36 bytes and terminate. */
memcpy(cookie, temp, 36); memcpy(cookie, temp, 36);

View File

@ -25,11 +25,8 @@
#include "iperf.h" #include "iperf.h"
#include "iperf_api.h" #include "iperf_api.h"
#include "iperf_client_api.h"
#include "iperf_server_api.h"
#include "units.h" #include "units.h"
#include "locale.h" #include "locale.h"
#include "iperf_error.h"
#include "net.h" #include "net.h"

View File

@ -9,6 +9,7 @@
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <unistd.h>
#include <sys/time.h> #include <sys/time.h>
#include "timer.h" #include "timer.h"

View File

@ -34,6 +34,7 @@
#include <string.h> #include <string.h>
#include <netinet/in.h> #include <netinet/in.h>
#include "iperf.h"
#include "iperf_api.h" #include "iperf_api.h"
#include "locale.h" #include "locale.h"

View File

@ -18,7 +18,7 @@
#include <time.h> #include <time.h>
#include "timer.h" #include "timer.h"
#include "iperf_error.h" #include "iperf_api.h"
double double
timeval_to_double(struct timeval * tv) timeval_to_double(struct timeval * tv)