more cleanup and bug fixes
Этот коммит содержится в:
родитель
a3281a3dc6
Коммит
e99faeae86
8
src/LICENSE.txt
Обычный файл
8
src/LICENSE.txt
Обычный файл
@ -0,0 +1,8 @@
|
||||
|
||||
/*
|
||||
* Copyright (c) 2009, 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.
|
||||
*/
|
||||
|
||||
|
9
src/README.txt
Обычный файл
9
src/README.txt
Обычный файл
@ -0,0 +1,9 @@
|
||||
|
||||
iperf3 should work on Linux, FreeBSD, and Mac OSX
|
||||
|
||||
Prerequists:
|
||||
libuuidgen
|
||||
|
||||
To build, just type 'make' (or 'gmake' on FreeBSD)
|
||||
|
||||
|
24
src/TODO.txt
Обычный файл
24
src/TODO.txt
Обычный файл
@ -0,0 +1,24 @@
|
||||
|
||||
Current list of things to fix/add to iperf 3.0
|
||||
|
||||
- finish/fix receive_result_from_server()
|
||||
- also: should this be called for TCP too, or only UDP (currently its both,
|
||||
but I think it should be UDP only, or maybe a command line option for TCP
|
||||
- document and verify the 'state machine'. Is it an error to send messages in the wrong order?
|
||||
- what is "STREAM_RUNNING" vs "TEST_RUNNING"??
|
||||
- (-i N) mode on server does not work
|
||||
- verify placment of all timing calls and total_bytes_sent computations
|
||||
- break up into client/sever files and TCP/UDP files
|
||||
- much better/standard error handling throughout
|
||||
- better packaging/makefile, README, LICENCE, etc files
|
||||
- cleanup/fix/test UDP mode
|
||||
- IPV6
|
||||
- add verbose and debug options
|
||||
- add human readable vs machine readable output mode
|
||||
(my idea on this is that "human readable" = compatable with old iperf,
|
||||
and that "machine readable is all name=value pairs -blt )
|
||||
- lots more testing
|
||||
- look for 'XXX' in code and address
|
||||
- deamon mode
|
||||
- see issue tracker for other wish list items
|
||||
|
@ -110,9 +110,9 @@ struct iperf_test
|
||||
|
||||
/* Select related parameters */
|
||||
int max_fd;
|
||||
fd_set read_set;
|
||||
fd_set temp_set;
|
||||
fd_set write_set;
|
||||
fd_set read_set; /* set of read sockets */
|
||||
fd_set temp_set; /* temp set for select */
|
||||
fd_set write_set; /* set of write sockets */
|
||||
|
||||
int (*accept) (struct iperf_test *);
|
||||
struct iperf_stream *(*new_stream) (struct iperf_test *);
|
||||
|
225
src/iperf_api.c
225
src/iperf_api.c
@ -57,21 +57,23 @@ all_data_sent(struct iperf_test *test)
|
||||
{
|
||||
if (test->default_settings->bytes == 0)
|
||||
return 0;
|
||||
else {
|
||||
else
|
||||
{
|
||||
uint64_t total_bytes = 0;
|
||||
struct iperf_stream *sp;
|
||||
|
||||
sp = test->streams;
|
||||
|
||||
while (sp) {
|
||||
while (sp)
|
||||
{
|
||||
total_bytes += sp->result->bytes_sent;
|
||||
sp = sp->next;
|
||||
}
|
||||
|
||||
if (total_bytes >= (test->num_streams * test->default_settings->bytes)) {
|
||||
if (total_bytes >= (test->num_streams * test->default_settings->bytes))
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
else
|
||||
} else
|
||||
return 0;
|
||||
}
|
||||
|
||||
@ -91,7 +93,7 @@ exchange_parameters(struct iperf_test *test)
|
||||
struct iperf_stream *sp;
|
||||
struct param_exchange *param;
|
||||
|
||||
//printf("in exchange_parameters \n");
|
||||
printf("in exchange_parameters \n");
|
||||
sp = test->streams;
|
||||
sp->settings->state = PARAM_EXCHANGE;
|
||||
param = (struct param_exchange *) sp->buffer;
|
||||
@ -117,11 +119,13 @@ exchange_parameters(struct iperf_test *test)
|
||||
//printf("result = %d state = %d, error = %d \n", result, sp->buffer[0], errno);
|
||||
|
||||
/* get answer back from server */
|
||||
do {
|
||||
do
|
||||
{
|
||||
//printf("exchange_parameters: reading result from server .. \n");
|
||||
result = recv(sp->socket, sp->buffer, sizeof(struct param_exchange), 0);
|
||||
} while (result == -1 && errno == EINTR);
|
||||
#else
|
||||
printf(" sending exchange params: size = %d \n", (int) sizeof(struct param_exchange));
|
||||
result = sp->snd(sp);
|
||||
if (result < 0)
|
||||
perror("Error sending exchange params to server");
|
||||
@ -130,7 +134,8 @@ exchange_parameters(struct iperf_test *test)
|
||||
|
||||
if (result < 0)
|
||||
perror("Error getting exchange params ack from server");
|
||||
if (result > 0 && sp->buffer[0] == ACCESS_DENIED) {
|
||||
if (result > 0 && sp->buffer[0] == ACCESS_DENIED)
|
||||
{
|
||||
fprintf(stderr, "Busy server Detected. Try again later. Exiting.\n");
|
||||
exit(-1);
|
||||
}
|
||||
@ -156,10 +161,11 @@ add_interval_list(struct iperf_stream_result *rp, struct iperf_interval_results
|
||||
|
||||
//printf("add_interval_list: Mbytes = %d, duration = %f \n", (int) (ip->bytes_transferred / 1000000), ip->interval_duration);
|
||||
|
||||
if (!rp->interval_results) {
|
||||
if (!rp->interval_results)
|
||||
{
|
||||
rp->interval_results = ip;
|
||||
}
|
||||
else {
|
||||
} else
|
||||
{
|
||||
n = rp->interval_results;
|
||||
while (n->next) /* find the end of the list */
|
||||
n = n->next;
|
||||
@ -179,7 +185,8 @@ display_interval_list(struct iperf_stream_result *rp, int tflag)
|
||||
|
||||
n = rp->interval_results;
|
||||
|
||||
while (n) {
|
||||
while (n)
|
||||
{
|
||||
printf("Interval = %f\tBytes transferred = %llu\n", n->interval_duration, n->bytes_transferred);
|
||||
if (tflag)
|
||||
print_tcpinfo(n);
|
||||
@ -218,7 +225,8 @@ receive_result_from_server(struct iperf_test *test)
|
||||
/* receive from server */
|
||||
|
||||
printf("reading results (size=%d) back from server \n", size);
|
||||
do {
|
||||
do
|
||||
{
|
||||
result = recv(sp->socket, buf, size, 0);
|
||||
} while (result == -1 && errno == EINTR);
|
||||
printf("Got size of results from server: %d \n", result);
|
||||
@ -267,14 +275,17 @@ Display(struct iperf_test *test)
|
||||
|
||||
printf("===============DISPLAY==================\n");
|
||||
|
||||
while (1) {
|
||||
if (n) {
|
||||
while (1)
|
||||
{
|
||||
if (n)
|
||||
{
|
||||
if (test->role == 'c')
|
||||
printf("position-%d\tsp=%d\tsocket=%d\tbytes sent=%llu\n", count++, (int) n, n->socket, n->result->bytes_sent);
|
||||
else
|
||||
printf("position-%d\tsp=%d\tsocket=%d\tbytes received=%llu\n", count++, (int) n, n->socket, n->result->bytes_received);
|
||||
|
||||
if (n->next == NULL) {
|
||||
if (n->next == NULL)
|
||||
{
|
||||
printf("=================END====================\n");
|
||||
fflush(stdout);
|
||||
break;
|
||||
@ -293,7 +304,8 @@ iperf_new_test()
|
||||
|
||||
printf("in iperf_new_test: reinit default settings \n");
|
||||
testp = (struct iperf_test *) malloc(sizeof(struct iperf_test));
|
||||
if (!testp) {
|
||||
if (!testp)
|
||||
{
|
||||
perror("malloc");
|
||||
return (NULL);
|
||||
}
|
||||
@ -344,8 +356,10 @@ iperf_init_test(struct iperf_test *test)
|
||||
int i, s = 0;
|
||||
|
||||
printf("in iperf_init_test \n");
|
||||
if (test->role == 's') { /* server */
|
||||
if (test->protocol == Pudp) {
|
||||
if (test->role == 's')
|
||||
{ /* server */
|
||||
if (test->protocol == Pudp)
|
||||
{
|
||||
test->listener_sock_udp = netannounce(Pudp, NULL, test->server_port);
|
||||
if (test->listener_sock_udp < 0)
|
||||
exit(0);
|
||||
@ -355,7 +369,8 @@ iperf_init_test(struct iperf_test *test)
|
||||
if (test->listener_sock_tcp < 0)
|
||||
exit(0);
|
||||
|
||||
if (test->protocol == Ptcp) {
|
||||
if (test->protocol == Ptcp)
|
||||
{
|
||||
if (set_tcp_windowsize(test->listener_sock_tcp, test->default_settings->socket_bufsize, SO_RCVBUF) < 0)
|
||||
perror("unable to set TCP window");
|
||||
}
|
||||
@ -371,21 +386,23 @@ iperf_init_test(struct iperf_test *test)
|
||||
if ((x = get_tcp_windowsize(test->listener_sock_tcp, SO_RCVBUF)) < 0)
|
||||
perror("SO_RCVBUF");
|
||||
|
||||
if (test->protocol == Ptcp) {
|
||||
if (test->protocol == Ptcp)
|
||||
{
|
||||
{
|
||||
if (test->default_settings->socket_bufsize > 0)
|
||||
{
|
||||
if (test->default_settings->socket_bufsize > 0) {
|
||||
unit_snprintf(ubuf, UNIT_LEN, (double) x, 'A');
|
||||
printf("TCP window size: %s\n", ubuf);
|
||||
}
|
||||
else {
|
||||
} else
|
||||
{
|
||||
printf("Using TCP Autotuning \n");
|
||||
}
|
||||
}
|
||||
}
|
||||
printf("-----------------------------------------------------------\n");
|
||||
|
||||
}
|
||||
else if (test->role == 'c') { /* Client */
|
||||
} else if (test->role == 'c')
|
||||
{ /* Client */
|
||||
FD_ZERO(&test->write_set);
|
||||
FD_SET(s, &test->write_set);
|
||||
|
||||
@ -393,9 +410,11 @@ iperf_init_test(struct iperf_test *test)
|
||||
* XXX: I think we need to create a TCP control socket here too for
|
||||
* UDP mode -blt
|
||||
*/
|
||||
for (i = 0; i < test->num_streams; i++) {
|
||||
for (i = 0; i < test->num_streams; i++)
|
||||
{
|
||||
s = netdial(test->protocol, test->server_hostname, test->server_port);
|
||||
if (s < 0) {
|
||||
if (s < 0)
|
||||
{
|
||||
fprintf(stderr, "netdial failed\n");
|
||||
exit(0);
|
||||
}
|
||||
@ -450,10 +469,12 @@ iperf_stats_callback(struct iperf_test *test)
|
||||
struct iperf_interval_results *ip, temp;
|
||||
|
||||
//printf("in stats_callback: num_streams = %d \n", test->num_streams);
|
||||
for (i = 0; i < test->num_streams; i++) {
|
||||
for (i = 0; i < test->num_streams; i++)
|
||||
{
|
||||
rp = sp->result;
|
||||
|
||||
if (!rp->interval_results) {
|
||||
if (!rp->interval_results)
|
||||
{
|
||||
if (test->role == 'c')
|
||||
temp.bytes_transferred = rp->bytes_sent;
|
||||
else
|
||||
@ -465,10 +486,11 @@ iperf_stats_callback(struct iperf_test *test)
|
||||
|
||||
gettimeofday(&sp->result->end_time, NULL);
|
||||
add_interval_list(rp, temp);
|
||||
}
|
||||
else {
|
||||
} else
|
||||
{
|
||||
ip = sp->result->interval_results;
|
||||
while (1) {
|
||||
while (1)
|
||||
{
|
||||
cumulative_bytes += ip->bytes_transferred;
|
||||
if (ip->next != NULL)
|
||||
ip = ip->next;
|
||||
@ -512,6 +534,7 @@ char *
|
||||
iperf_reporter_callback(struct iperf_test * test)
|
||||
{
|
||||
int total_packets = 0, lost_packets = 0, curr_state = 0;
|
||||
int first_stream = 1;
|
||||
char ubuf[UNIT_LEN];
|
||||
char nbuf[UNIT_LEN];
|
||||
struct iperf_stream *sp = NULL;
|
||||
@ -529,11 +552,14 @@ iperf_reporter_callback(struct iperf_test *test)
|
||||
curr_state = sp->settings->state;
|
||||
//printf("in iperf_reporter_callback: state = %d \n", curr_state);
|
||||
|
||||
if (curr_state == TEST_RUNNING) {
|
||||
if (curr_state == TEST_RUNNING || curr_state == STREAM_RUNNING)
|
||||
{
|
||||
/* print interval results */
|
||||
while (sp) { /* for each stream */
|
||||
while (sp)
|
||||
{ /* for each stream */
|
||||
ip = sp->result->interval_results;
|
||||
while (ip->next != NULL) {
|
||||
while (ip->next != NULL) /* find end of list. XXX: why not just keep track of this pointer?? */
|
||||
{
|
||||
ip_prev = ip;
|
||||
ip = ip->next;
|
||||
}
|
||||
@ -541,92 +567,110 @@ iperf_reporter_callback(struct iperf_test *test)
|
||||
bytes += ip->bytes_transferred;
|
||||
unit_snprintf(ubuf, UNIT_LEN, (double) (ip->bytes_transferred), 'A');
|
||||
|
||||
if (test->streams->result->interval_results->next != NULL) {
|
||||
if (test->streams->result->interval_results->next != NULL)
|
||||
{
|
||||
unit_snprintf(nbuf, UNIT_LEN,
|
||||
(double) (ip->bytes_transferred / (ip->interval_duration - ip_prev->interval_duration)),
|
||||
test->default_settings->unit_format);
|
||||
sprintf(message, report_bw_format, sp->socket, ip_prev->interval_duration, ip->interval_duration, ubuf, nbuf);
|
||||
|
||||
|
||||
}
|
||||
else {
|
||||
} else
|
||||
{
|
||||
if (first_stream) /* only print header for 1st stream */
|
||||
{
|
||||
sprintf(message, report_bw_header);
|
||||
safe_strcat(message_final, message);
|
||||
first_stream = 0;
|
||||
}
|
||||
|
||||
unit_snprintf(nbuf, UNIT_LEN, (double) (ip->bytes_transferred / ip->interval_duration), test->default_settings->unit_format);
|
||||
sprintf(message, report_bw_format, sp->socket, 0.0, ip->interval_duration, ubuf, nbuf);
|
||||
}
|
||||
if (strlen(message_final) + strlen(message) < MAX_RESULT_STRING)
|
||||
safe_strcat(message_final, message);
|
||||
else {
|
||||
else
|
||||
{
|
||||
printf("Error: results string too long \n");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (test->tcp_info) {
|
||||
if (test->tcp_info)
|
||||
{
|
||||
build_tcpinfo_message(ip, message);
|
||||
safe_strcat(message_final, message);
|
||||
}
|
||||
//printf("reporter_callback: built interval string: %s \n", message_final);
|
||||
sp = sp->next;
|
||||
} /* while (sp) */
|
||||
|
||||
|
||||
if (test->num_streams > 1) {
|
||||
if (test->num_streams > 1) /* sum of all streams */
|
||||
{
|
||||
unit_snprintf(ubuf, UNIT_LEN, (double) (bytes), 'A');
|
||||
|
||||
if (test->streams->result->interval_results->next != NULL) {
|
||||
if (test->streams->result->interval_results->next != NULL)
|
||||
{
|
||||
unit_snprintf(nbuf, UNIT_LEN, (double) (bytes / (ip->interval_duration - ip_prev->interval_duration)),
|
||||
test->default_settings->unit_format);
|
||||
sprintf(message, report_sum_bw_format, ip_prev->interval_duration, ip->interval_duration, ubuf, nbuf);
|
||||
}
|
||||
else {
|
||||
} else
|
||||
{
|
||||
unit_snprintf(nbuf, UNIT_LEN, (double) (bytes / ip->interval_duration), test->default_settings->unit_format);
|
||||
sprintf(message, report_sum_bw_format, 0.0, ip->interval_duration, ubuf, nbuf);
|
||||
}
|
||||
safe_strcat(message_final, message);
|
||||
if (test->tcp_info) {
|
||||
if (test->tcp_info)
|
||||
{
|
||||
build_tcpinfo_message(ip, message);
|
||||
safe_strcat(message_final, message);
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (curr_state == ALL_STREAMS_END || curr_state == RESULT_REQUEST) {
|
||||
} else
|
||||
{
|
||||
if (curr_state == ALL_STREAMS_END || curr_state == RESULT_REQUEST)
|
||||
{
|
||||
/* if TEST_RUNNING */
|
||||
sp = test->streams;
|
||||
|
||||
while (sp) {
|
||||
while (sp)
|
||||
{
|
||||
if (test->role == 'c')
|
||||
bytes += sp->result->bytes_sent;
|
||||
else
|
||||
bytes += sp->result->bytes_received;
|
||||
|
||||
if (test->protocol == Pudp) {
|
||||
if (test->protocol == Pudp)
|
||||
{
|
||||
total_packets += sp->packet_count;
|
||||
lost_packets += sp->cnt_error;
|
||||
}
|
||||
start_time = timeval_diff(&sp->result->start_time, &sp->result->start_time);
|
||||
end_time = timeval_diff(&sp->result->start_time, &sp->result->end_time);
|
||||
|
||||
if (test->role == 'c') {
|
||||
if (test->role == 'c')
|
||||
{
|
||||
unit_snprintf(ubuf, UNIT_LEN, (double) (sp->result->bytes_sent), 'A');
|
||||
unit_snprintf(nbuf, UNIT_LEN, (double) (sp->result->bytes_sent / end_time), test->default_settings->unit_format);
|
||||
|
||||
}
|
||||
else {
|
||||
} else
|
||||
{
|
||||
unit_snprintf(ubuf, UNIT_LEN, (double) (sp->result->bytes_received), 'A');
|
||||
unit_snprintf(nbuf, UNIT_LEN, (double) (sp->result->bytes_received / end_time), test->default_settings->unit_format);
|
||||
}
|
||||
|
||||
if (test->protocol == Ptcp) {
|
||||
if (test->protocol == Ptcp)
|
||||
{
|
||||
sprintf(message, report_bw_format, sp->socket, start_time, end_time, ubuf, nbuf);
|
||||
safe_strcat(message_final, message);
|
||||
}
|
||||
else { /* UDP mode */
|
||||
} else
|
||||
{ /* UDP mode */
|
||||
sprintf(message, report_bw_jitter_loss_format, sp->socket, start_time,
|
||||
end_time, ubuf, nbuf, sp->jitter * 1000, sp->cnt_error, sp->packet_count, (double) (100.0 * sp->cnt_error / sp->packet_count));
|
||||
safe_strcat(message_final, message);
|
||||
|
||||
if (test->role == 'c') {
|
||||
if (test->role == 'c')
|
||||
{
|
||||
sprintf(message, report_datagrams, sp->socket, sp->packet_count);
|
||||
safe_strcat(message_final, message);
|
||||
}
|
||||
@ -637,8 +681,8 @@ iperf_reporter_callback(struct iperf_test *test)
|
||||
* XXX: we need to do something with any TCP_INFO results here
|
||||
*/
|
||||
sp = sp->next;
|
||||
}
|
||||
} /* while (sp) */
|
||||
|
||||
sp = test->streams; /* reset to first socket */
|
||||
|
||||
start_time = timeval_diff(&sp->result->start_time, &sp->result->start_time);
|
||||
@ -647,18 +691,21 @@ iperf_reporter_callback(struct iperf_test *test)
|
||||
unit_snprintf(ubuf, UNIT_LEN, (double) bytes, 'A');
|
||||
unit_snprintf(nbuf, UNIT_LEN, (double) bytes / end_time, test->default_settings->unit_format);
|
||||
|
||||
if ((test->role == 'c' && test->num_streams > 1) || (test->role == 's')) {
|
||||
if (test->protocol == Ptcp) {
|
||||
if ((test->role == 'c' && test->num_streams > 1) || (test->role == 's'))
|
||||
{
|
||||
if (test->protocol == Ptcp)
|
||||
{
|
||||
sprintf(message, report_sum_bw_format, start_time, end_time, ubuf, nbuf);
|
||||
safe_strcat(message_final, message);
|
||||
}
|
||||
else {
|
||||
} else
|
||||
{
|
||||
sprintf(message, report_sum_bw_jitter_loss_format, start_time, end_time, ubuf, nbuf, sp->jitter, lost_packets, total_packets, (double) (100.0 * lost_packets / total_packets));
|
||||
safe_strcat(message_final, message);
|
||||
}
|
||||
|
||||
|
||||
if ((test->print_mss != 0) && (test->role == 'c')) {
|
||||
if ((test->print_mss != 0) && (test->role == 'c'))
|
||||
{
|
||||
sprintf(message, "\nThe TCP maximum segment size mss = %d \n", getsock_tcp_mss(sp->socket));
|
||||
safe_strcat(message_final, message);
|
||||
}
|
||||
@ -675,7 +722,8 @@ safe_strcat(char *s1, char *s2)
|
||||
//printf(" adding string %s to end of string %s \n", s1, s1);
|
||||
if (strlen(s1) + strlen(s2) < MAX_RESULT_STRING)
|
||||
strcat(s1, s2);
|
||||
else {
|
||||
else
|
||||
{
|
||||
printf("Error: results string too long \n");
|
||||
exit(-1); /* XXX: should return an error instead! */
|
||||
//return -1;
|
||||
@ -702,7 +750,8 @@ iperf_new_stream(struct iperf_test *testp)
|
||||
|
||||
//printf("in iperf_new_stream \n");
|
||||
sp = (struct iperf_stream *) malloc(sizeof(struct iperf_stream));
|
||||
if (!sp) {
|
||||
if (!sp)
|
||||
{
|
||||
perror("malloc");
|
||||
return (NULL);
|
||||
}
|
||||
@ -749,14 +798,17 @@ iperf_init_stream(struct iperf_stream *sp, struct iperf_test *testp)
|
||||
|
||||
len = sizeof(struct sockaddr_in);
|
||||
|
||||
if (getsockname(sp->socket, (struct sockaddr *)&sp->local_addr, &len) < 0) {
|
||||
if (getsockname(sp->socket, (struct sockaddr *) & sp->local_addr, &len) < 0)
|
||||
{
|
||||
perror("getsockname");
|
||||
}
|
||||
if (getpeername(sp->socket, (struct sockaddr *)&sp->remote_addr, &len) < 0) {
|
||||
if (getpeername(sp->socket, (struct sockaddr *) & sp->remote_addr, &len) < 0)
|
||||
{
|
||||
perror("getpeername");
|
||||
}
|
||||
//printf("in init_stream: calling set_tcp_windowsize: %d \n", testp->default_settings->socket_bufsize);
|
||||
if (testp->protocol == Ptcp) {
|
||||
if (testp->protocol == Ptcp)
|
||||
{
|
||||
if (set_tcp_windowsize(sp->socket, testp->default_settings->socket_bufsize,
|
||||
testp->role == 's' ? SO_RCVBUF : SO_SNDBUF) < 0)
|
||||
fprintf(stderr, "unable to set window size\n");
|
||||
@ -772,11 +824,12 @@ iperf_add_stream(struct iperf_test *test, struct iperf_stream *sp)
|
||||
{
|
||||
struct iperf_stream *n;
|
||||
|
||||
if (!test->streams) {
|
||||
if (!test->streams)
|
||||
{
|
||||
test->streams = sp;
|
||||
return 1;
|
||||
}
|
||||
else {
|
||||
} else
|
||||
{
|
||||
n = test->streams;
|
||||
while (n->next)
|
||||
n = n->next;
|
||||
@ -803,7 +856,8 @@ find_stream_by_socket(struct iperf_test *test, int sock)
|
||||
|
||||
n = test->streams;
|
||||
|
||||
while (1) {
|
||||
while (1)
|
||||
{
|
||||
if (n->socket == sock)
|
||||
break;
|
||||
|
||||
@ -838,7 +892,7 @@ iperf_run_client(struct iperf_test *test)
|
||||
int ret = 0;
|
||||
struct sigaction sact;
|
||||
|
||||
//printf("in iperf_run_client \n");
|
||||
printf("in iperf_run_client \n");
|
||||
tv.tv_sec = 15; /* timeout interval in seconds */
|
||||
tv.tv_usec = 0;
|
||||
|
||||
@ -847,7 +901,8 @@ iperf_run_client(struct iperf_test *test)
|
||||
sact.sa_handler = catcher;
|
||||
sigaction(SIGINT, &sact, NULL);
|
||||
|
||||
if (test->protocol == Pudp) {
|
||||
if (test->protocol == Pudp)
|
||||
{
|
||||
dtargus = (int64_t) (test->default_settings->blksize) * SEC_TO_US * 8;
|
||||
dtargus /= test->default_settings->rate;
|
||||
|
||||
@ -858,7 +913,8 @@ iperf_run_client(struct iperf_test *test)
|
||||
printf("iperf_run_client: adjustus: %lld, delayus: %lld \n", adjustus, delayus);
|
||||
|
||||
sp = test->streams;
|
||||
for (i = 0; i < test->num_streams; i++) {
|
||||
for (i = 0; i < test->num_streams; i++)
|
||||
{
|
||||
sp->send_timer = new_timer(0, dtargus);
|
||||
sp = sp->next;
|
||||
}
|
||||
@ -887,7 +943,8 @@ iperf_run_client(struct iperf_test *test)
|
||||
prot, test->num_streams, test->default_settings->blksize, (int) test->default_settings->bytes);
|
||||
|
||||
/* send data till the timer expires or bytes sent */
|
||||
while (!all_data_sent(test) && !timer->expired(timer)) {
|
||||
while (!all_data_sent(test) && !timer->expired(timer))
|
||||
{
|
||||
|
||||
#ifdef NEED_THIS /* not sure what this was for, so removed
|
||||
* -blt */
|
||||
@ -899,7 +956,8 @@ iperf_run_client(struct iperf_test *test)
|
||||
#endif
|
||||
|
||||
sp = test->streams;
|
||||
for (i = 0; i < test->num_streams; i++) {
|
||||
for (i = 0; i < test->num_streams; i++)
|
||||
{
|
||||
//printf("sending data to stream %d \n", i);
|
||||
result += sp->snd(sp);
|
||||
|
||||
@ -909,12 +967,15 @@ iperf_run_client(struct iperf_test *test)
|
||||
}
|
||||
|
||||
|
||||
if ((test->stats_interval != 0) && stats_interval->expired(stats_interval)) {
|
||||
if ((test->stats_interval != 0) && stats_interval->expired(stats_interval))
|
||||
{
|
||||
test->stats_callback(test);
|
||||
update_timer(stats_interval, test->stats_interval, 0);
|
||||
}
|
||||
if ((test->reporter_interval != 0) && reporter_interval->expired(reporter_interval)) {
|
||||
if ((test->reporter_interval != 0) && reporter_interval->expired(reporter_interval))
|
||||
{
|
||||
result_string = test->reporter_callback(test);
|
||||
//printf("interval expired: printing results: \n");
|
||||
puts(result_string);
|
||||
update_timer(reporter_interval, test->reporter_interval, 0);
|
||||
}
|
||||
@ -932,7 +993,8 @@ iperf_run_client(struct iperf_test *test)
|
||||
printf("Test Complete. \n");
|
||||
/* send STREAM_END packets */
|
||||
np = test->streams;
|
||||
do { /* send STREAM_END to all sockets */
|
||||
do
|
||||
{ /* send STREAM_END to all sockets */
|
||||
sp = np;
|
||||
sp->settings->state = STREAM_END;
|
||||
printf("sending state = STREAM_END to stream %d \n", sp->socket);
|
||||
@ -968,7 +1030,8 @@ iperf_run_client(struct iperf_test *test)
|
||||
/* Deleting all streams - CAN CHANGE FREE_STREAM FN */
|
||||
sp = test->streams;
|
||||
np = sp;
|
||||
do {
|
||||
do
|
||||
{
|
||||
sp = np;
|
||||
close(sp->socket);
|
||||
np = sp->next;
|
||||
|
@ -128,10 +128,18 @@ iperf_run_server(struct iperf_test * test)
|
||||
printf("in iperf_run_server \n");
|
||||
|
||||
FD_ZERO(&test->read_set);
|
||||
FD_ZERO(&test->temp_set);
|
||||
if (test->protocol == Ptcp)
|
||||
{
|
||||
/* add listener to the master set */
|
||||
FD_SET(test->listener_sock_tcp, &test->read_set);
|
||||
test->max_fd = test->listener_sock_tcp;
|
||||
} else
|
||||
{
|
||||
FD_SET(test->listener_sock_udp, &test->read_set);
|
||||
test->max_fd = test->listener_sock_udp;
|
||||
}
|
||||
|
||||
test->max_fd = test->listener_sock_tcp > test->listener_sock_udp ? test->listener_sock_tcp : test->listener_sock_udp;
|
||||
//printf("iperf_run_server: max_fd set to %d \n", test->max_fd);
|
||||
|
||||
test->num_streams = 0;
|
||||
@ -157,6 +165,8 @@ iperf_run_server(struct iperf_test * test)
|
||||
printf("Error in select(): %s, socket = %d\n", strerror(errno), test->max_fd + 1);
|
||||
exit(0);
|
||||
} else if (result > 0)
|
||||
{
|
||||
if (test->protocol == Ptcp)
|
||||
{
|
||||
/* Accept a new TCP connection */
|
||||
if (FD_ISSET(test->listener_sock_tcp, &test->temp_set))
|
||||
@ -171,8 +181,10 @@ iperf_run_server(struct iperf_test * test)
|
||||
FD_CLR(test->listener_sock_tcp, &test->temp_set);
|
||||
printf("iperf_run_server: accepted TCP connection \n");
|
||||
}
|
||||
} else
|
||||
{
|
||||
/* Accept a new UDP connection */
|
||||
else if (FD_ISSET(test->listener_sock_udp, &test->temp_set))
|
||||
if (FD_ISSET(test->listener_sock_udp, &test->temp_set))
|
||||
{
|
||||
test->protocol = Pudp;
|
||||
test->accept = iperf_udp_accept;
|
||||
@ -182,13 +194,10 @@ iperf_run_server(struct iperf_test * test)
|
||||
test->accept(test);
|
||||
test->default_settings->state = TEST_RUNNING;
|
||||
FD_CLR(test->listener_sock_udp, &test->temp_set);
|
||||
printf("iperf_run_server: accepted UDP connection \n");
|
||||
}
|
||||
}
|
||||
/* Process the sockets for read operation */
|
||||
/*
|
||||
* XXX: Need to try to read equal amounts from each socket, so
|
||||
* keep track of last socket read from, and always start with the
|
||||
* next socket
|
||||
*/
|
||||
nfd = test->max_fd + 1;
|
||||
for (j = 0; j <= test->max_fd; j++)
|
||||
{
|
||||
@ -196,7 +205,7 @@ iperf_run_server(struct iperf_test * test)
|
||||
if (FD_ISSET(j, &test->temp_set))
|
||||
{
|
||||
//printf("iperf_run_server: data ready on socket %d \n", j);
|
||||
/* find the correct stream - possibly time consuming */
|
||||
/* find the correct stream - possibly time consuming? */
|
||||
np = find_stream_by_socket(test, j);
|
||||
message = np->rcv(np); /* get data from client using
|
||||
* receiver callback */
|
||||
@ -205,6 +214,7 @@ iperf_run_server(struct iperf_test * test)
|
||||
handle_message(test, message, np);
|
||||
if (message == TEST_END)
|
||||
break; /* test done, so break out of loop */
|
||||
|
||||
} /* end if (FD_ISSET(j, &temp_set)) */
|
||||
} /* end for (j=0;...) */
|
||||
} /* end else (result>0) */
|
||||
|
@ -282,10 +282,9 @@ iperf_tcp_accept(struct iperf_test * test)
|
||||
} else
|
||||
{
|
||||
sp = test->new_stream(test);
|
||||
/* XXX: what is this for? */
|
||||
//setnonblocking(peersock);
|
||||
setnonblocking(peersock);
|
||||
|
||||
FD_SET(peersock, &test->read_set);
|
||||
FD_SET(peersock, &test->read_set); /* add new socket to master set */
|
||||
test->max_fd = (test->max_fd < peersock) ? peersock : test->max_fd;
|
||||
//printf("iperf_tcp_accept: max_fd now set to: %d \n", test->max_fd );
|
||||
|
||||
|
25
src/main.c
25
src/main.c
@ -1,33 +1,10 @@
|
||||
|
||||
/*
|
||||
* Copyright (c) 2004, The Regents of the University of California, through
|
||||
* Copyright (c) 2009, 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.
|
||||
*/
|
||||
|
||||
/*
|
||||
* TO DO list:
|
||||
* finish/fix receive_result_from_server()
|
||||
* - also: should this be called for TCP too, or only UDP (currently its both,
|
||||
* but I think it should be UDP only, or maybe a command line option for TCP
|
||||
* (and related to this, check, test, document 'state machine' aspect of this.
|
||||
* eg: are TEST_START and TEST_END, and STREAM_END / ALL_STREAMS_END all required?
|
||||
* is it an error to get these in a strange order? etc. )
|
||||
* verify placment of all timing calls and total_bytes_sent computations
|
||||
* break up into client/sever files and TCP/UDP files
|
||||
* much better/standard error handling throughout
|
||||
* better packaging/makefile, README, LICENCE, etc files
|
||||
* cleanup/fix/test UDP mode
|
||||
* IPV6
|
||||
* add verbose and debug options
|
||||
* add human readable vs machine readable output mode
|
||||
* (my idea on this is that "human readable" = compatable with old iperf,
|
||||
* and that "machine readable is all name=value pairs -blt )
|
||||
* lots more testing
|
||||
* look for 'XXX' in code and address
|
||||
* see issue tracker for other wish list items
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
@ -13,6 +13,10 @@
|
||||
#include "net.h"
|
||||
#include "timer.h"
|
||||
|
||||
/* netdial and netannouce code comes from libtask: http://swtch.com/libtask/
|
||||
* Copyright: http://swtch.com/libtask/COPYRIGHT
|
||||
*/
|
||||
|
||||
/* make connection to server */
|
||||
int
|
||||
netdial(int proto, char *client, int port)
|
||||
|
Загрузка…
Ссылка в новой задаче
Block a user