state machine cleanup (still in progress)
This commit is contained in:
parent
a951c98062
commit
a36921c2dd
@ -104,7 +104,7 @@ exchange_parameters(struct iperf_test * test)
|
|||||||
param->send_window = test->default_settings->socket_bufsize;
|
param->send_window = test->default_settings->socket_bufsize;
|
||||||
param->format = test->default_settings->unit_format;
|
param->format = test->default_settings->unit_format;
|
||||||
|
|
||||||
printf(" sending exchange params: size = %d \n", (int) sizeof(struct param_exchange));
|
//printf(" sending exchange params: size = %d \n", (int) sizeof(struct param_exchange));
|
||||||
/* XXX: can we use iperf_tcp_send for this? that would be cleaner */
|
/* XXX: can we use iperf_tcp_send for this? that would be cleaner */
|
||||||
result = send(sp->socket, sp->buffer, sizeof(struct param_exchange), 0);
|
result = send(sp->socket, sp->buffer, sizeof(struct param_exchange), 0);
|
||||||
if (result < 0)
|
if (result < 0)
|
||||||
@ -115,7 +115,7 @@ exchange_parameters(struct iperf_test * test)
|
|||||||
/* get answer back from server */
|
/* get answer back from server */
|
||||||
do
|
do
|
||||||
{
|
{
|
||||||
printf("exchange_parameters: reading result from server .. \n");
|
//printf("exchange_parameters: reading result from server .. \n");
|
||||||
result = recv(sp->socket, sp->buffer, sizeof(struct param_exchange), 0);
|
result = recv(sp->socket, sp->buffer, sizeof(struct param_exchange), 0);
|
||||||
} while (result == -1 && errno == EINTR);
|
} while (result == -1 && errno == EINTR);
|
||||||
if (result < 0)
|
if (result < 0)
|
||||||
@ -222,10 +222,6 @@ receive_result_from_server(struct iperf_test * test)
|
|||||||
printf(server_reporting, sp->socket);
|
printf(server_reporting, sp->socket);
|
||||||
puts(buf); /* prints results */
|
puts(buf); /* prints results */
|
||||||
|
|
||||||
printf("receive_result_from_server: send TEST_END to server \n");
|
|
||||||
sp->settings->state = TEST_END;
|
|
||||||
sp->snd(sp); /* send message to server */
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*************************************************************/
|
/*************************************************************/
|
||||||
@ -346,6 +342,7 @@ iperf_init_test(struct iperf_test * test)
|
|||||||
struct iperf_stream *sp;
|
struct iperf_stream *sp;
|
||||||
int i, s = 0;
|
int i, s = 0;
|
||||||
|
|
||||||
|
printf("in iperf_init_test \n");
|
||||||
if (test->role == 's')
|
if (test->role == 's')
|
||||||
{ /* server */
|
{ /* server */
|
||||||
if (test->protocol == Pudp)
|
if (test->protocol == Pudp)
|
||||||
@ -416,8 +413,7 @@ iperf_init_test(struct iperf_test * test)
|
|||||||
iperf_init_stream(sp, test);
|
iperf_init_stream(sp, test);
|
||||||
iperf_add_stream(test, sp);
|
iperf_add_stream(test, sp);
|
||||||
|
|
||||||
if (test->default_settings->state != RESULT_REQUEST)
|
connect_msg(sp); /* print connection established message */
|
||||||
connect_msg(sp);/* XXX: what is this ?? */
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -543,7 +539,7 @@ iperf_reporter_callback(struct iperf_test * test)
|
|||||||
|
|
||||||
sp = test->streams;
|
sp = test->streams;
|
||||||
curr_state = sp->settings->state;
|
curr_state = sp->settings->state;
|
||||||
printf("in iperf_reporter_callback: state = %d \n", curr_state);
|
//printf("in iperf_reporter_callback: state = %d \n", curr_state);
|
||||||
|
|
||||||
if (curr_state == TEST_RUNNING)
|
if (curr_state == TEST_RUNNING)
|
||||||
{
|
{
|
||||||
@ -697,34 +693,8 @@ iperf_reporter_callback(struct iperf_test * test)
|
|||||||
|
|
||||||
/**************************************************************************/
|
/**************************************************************************/
|
||||||
void
|
void
|
||||||
iperf_free_stream(struct iperf_test * test, struct iperf_stream * sp)
|
iperf_free_stream(struct iperf_stream * sp)
|
||||||
{
|
{
|
||||||
struct iperf_stream *prev, *start;
|
|
||||||
|
|
||||||
prev = test->streams;
|
|
||||||
start = test->streams;
|
|
||||||
|
|
||||||
if (test->streams->socket == sp->socket)
|
|
||||||
{
|
|
||||||
test->streams = test->streams->next;
|
|
||||||
} else
|
|
||||||
{
|
|
||||||
start = test->streams->next;
|
|
||||||
while (1)
|
|
||||||
{
|
|
||||||
if (start->socket == sp->socket)
|
|
||||||
{
|
|
||||||
prev->next = sp->next;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
if (start->next != NULL)
|
|
||||||
{
|
|
||||||
start = start->next;
|
|
||||||
prev = prev->next;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
free(sp->buffer);
|
free(sp->buffer);
|
||||||
free(sp->settings);
|
free(sp->settings);
|
||||||
free(sp->result);
|
free(sp->result);
|
||||||
@ -879,7 +849,7 @@ iperf_run_client(struct iperf_test * test)
|
|||||||
int ret = 0;
|
int ret = 0;
|
||||||
struct sigaction sact;
|
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_sec = 15; /* timeout interval in seconds */
|
||||||
tv.tv_usec = 0;
|
tv.tv_usec = 0;
|
||||||
|
|
||||||
@ -980,7 +950,7 @@ iperf_run_client(struct iperf_test * test)
|
|||||||
/* send STREAM_END packets */
|
/* send STREAM_END packets */
|
||||||
np = test->streams;
|
np = test->streams;
|
||||||
do
|
do
|
||||||
{
|
{ /* send STREAM_END to all sockets */
|
||||||
sp = np;
|
sp = np;
|
||||||
sp->settings->state = STREAM_END;
|
sp->settings->state = STREAM_END;
|
||||||
sp->snd(sp);
|
sp->snd(sp);
|
||||||
@ -999,7 +969,6 @@ iperf_run_client(struct iperf_test * test)
|
|||||||
result_string = test->reporter_callback(test);
|
result_string = test->reporter_callback(test);
|
||||||
puts(result_string);
|
puts(result_string);
|
||||||
|
|
||||||
|
|
||||||
/* Requesting for result from Server */
|
/* Requesting for result from Server */
|
||||||
test->default_settings->state = RESULT_REQUEST;
|
test->default_settings->state = RESULT_REQUEST;
|
||||||
//receive_result_from_server(test); /* XXX: currently broken! */
|
//receive_result_from_server(test); /* XXX: currently broken! */
|
||||||
@ -1009,6 +978,10 @@ iperf_run_client(struct iperf_test * test)
|
|||||||
|
|
||||||
//printf("Done getting/printing results. \n");
|
//printf("Done getting/printing results. \n");
|
||||||
|
|
||||||
|
printf("send TEST_END to server \n");
|
||||||
|
sp->settings->state = TEST_END;
|
||||||
|
sp->snd(sp); /* send message to server */
|
||||||
|
|
||||||
/* Deleting all streams - CAN CHANGE FREE_STREAM FN */
|
/* Deleting all streams - CAN CHANGE FREE_STREAM FN */
|
||||||
sp = test->streams;
|
sp = test->streams;
|
||||||
np = sp;
|
np = sp;
|
||||||
@ -1017,7 +990,7 @@ iperf_run_client(struct iperf_test * test)
|
|||||||
sp = np;
|
sp = np;
|
||||||
close(sp->socket);
|
close(sp->socket);
|
||||||
np = sp->next;
|
np = sp->next;
|
||||||
iperf_free_stream(test, sp);
|
iperf_free_stream(sp);
|
||||||
} while (np);
|
} while (np);
|
||||||
|
|
||||||
if (test->stats_interval != 0)
|
if (test->stats_interval != 0)
|
||||||
|
@ -155,7 +155,7 @@ void iperf_init_stream(struct iperf_stream * sp, struct iperf_test * testp)
|
|||||||
* iperf_free_stream -- free resources associated with test
|
* iperf_free_stream -- free resources associated with test
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
void iperf_free_stream(struct iperf_test * test, struct iperf_stream * sp);
|
void iperf_free_stream(struct iperf_stream * sp);
|
||||||
|
|
||||||
void get_tcpinfo(struct iperf_test *test, struct iperf_interval_results *rp);
|
void get_tcpinfo(struct iperf_test *test, struct iperf_interval_results *rp);
|
||||||
void print_tcpinfo(struct iperf_interval_results *);
|
void print_tcpinfo(struct iperf_interval_results *);
|
||||||
|
@ -75,7 +75,7 @@ param_received(struct iperf_stream * sp, struct param_exchange * param)
|
|||||||
buf[0] = ACCESS_DENIED;
|
buf[0] = ACCESS_DENIED;
|
||||||
}
|
}
|
||||||
free(buf);
|
free(buf);
|
||||||
printf("param_received: Sending message back to client \n");
|
//printf("param_received: Sending message back to client \n");
|
||||||
result = send(sp->socket, buf, sizeof(struct param_exchange), 0);
|
result = send(sp->socket, buf, sizeof(struct param_exchange), 0);
|
||||||
if (result < 0)
|
if (result < 0)
|
||||||
perror("param_received: Error sending param ack to client");
|
perror("param_received: Error sending param ack to client");
|
||||||
@ -190,8 +190,8 @@ iperf_run_server(struct iperf_test * test)
|
|||||||
{
|
{
|
||||||
/* XXX: test this! */
|
/* XXX: test this! */
|
||||||
close(np->socket);
|
close(np->socket);
|
||||||
FD_CLR(np->socket, &test->read_set);
|
//FD_CLR(np->socket, &test->read_set);
|
||||||
iperf_free_stream(test, np);
|
iperf_free_stream(np);
|
||||||
}
|
}
|
||||||
if (message == STREAM_END)
|
if (message == STREAM_END)
|
||||||
{
|
{
|
||||||
@ -221,10 +221,11 @@ iperf_run_server(struct iperf_test * test)
|
|||||||
do
|
do
|
||||||
{
|
{
|
||||||
sp = np;
|
sp = np;
|
||||||
|
printf(" closing socket: %d \n", sp->socket);
|
||||||
close(sp->socket);
|
close(sp->socket);
|
||||||
FD_CLR(sp->socket, &test->read_set);
|
//FD_CLR(sp->socket, &test->read_set);
|
||||||
np = sp->next;
|
np = sp->next; /* get next pointer before freeing */
|
||||||
iperf_free_stream(test, sp);
|
iperf_free_stream(sp);
|
||||||
} while (np != NULL);
|
} while (np != NULL);
|
||||||
|
|
||||||
printf("TEST_END\n\n");
|
printf("TEST_END\n\n");
|
||||||
|
@ -52,7 +52,6 @@ int
|
|||||||
iperf_tcp_recv(struct iperf_stream * sp)
|
iperf_tcp_recv(struct iperf_stream * sp)
|
||||||
{
|
{
|
||||||
int result, message;
|
int result, message;
|
||||||
char ch;
|
|
||||||
int size = sp->settings->blksize;
|
int size = sp->settings->blksize;
|
||||||
char *final_message = NULL;
|
char *final_message = NULL;
|
||||||
|
|
||||||
@ -66,7 +65,7 @@ iperf_tcp_recv(struct iperf_stream * sp)
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
/* get the 1st byte: then based on that, decide how much to read */
|
/* get the 1st byte: then based on that, decide how much to read */
|
||||||
if ((result = recv(sp->socket, &ch, sizeof(int), MSG_PEEK)) != sizeof(int))
|
if ((result = recv(sp->socket, &message, sizeof(int), MSG_PEEK)) != sizeof(int))
|
||||||
{
|
{
|
||||||
if (result == 0)
|
if (result == 0)
|
||||||
printf("Client Disconnected. \n");
|
printf("Client Disconnected. \n");
|
||||||
@ -74,9 +73,8 @@ iperf_tcp_recv(struct iperf_stream * sp)
|
|||||||
perror("iperf_tcp_recv: recv error: MSG_PEEK");
|
perror("iperf_tcp_recv: recv error: MSG_PEEK");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
message = (int) ch;
|
|
||||||
sp->settings->state = message;
|
sp->settings->state = message;
|
||||||
if (message != 7) /* tell me about non STREAM_RUNNING messages
|
if (message != STREAM_RUNNING) /* tell me about non STREAM_RUNNING messages
|
||||||
* for debugging */
|
* for debugging */
|
||||||
printf("iperf_tcp_recv: got message type %d \n", message);
|
printf("iperf_tcp_recv: got message type %d \n", message);
|
||||||
|
|
||||||
@ -107,7 +105,6 @@ iperf_tcp_recv(struct iperf_stream * sp)
|
|||||||
case TEST_START:
|
case TEST_START:
|
||||||
case STREAM_BEGIN:
|
case STREAM_BEGIN:
|
||||||
case STREAM_RUNNING:
|
case STREAM_RUNNING:
|
||||||
case STREAM_END:
|
|
||||||
size = sp->settings->blksize;
|
size = sp->settings->blksize;
|
||||||
#ifdef USE_RECV
|
#ifdef USE_RECV
|
||||||
/*
|
/*
|
||||||
@ -131,19 +128,23 @@ iperf_tcp_recv(struct iperf_stream * sp)
|
|||||||
//printf("iperf_tcp_recv: recv returned %d bytes \n", result);
|
//printf("iperf_tcp_recv: recv returned %d bytes \n", result);
|
||||||
sp->result->bytes_received += result;
|
sp->result->bytes_received += result;
|
||||||
break;
|
break;
|
||||||
|
case STREAM_END:
|
||||||
case ALL_STREAMS_END:
|
case ALL_STREAMS_END:
|
||||||
size = sizeof(struct param_exchange);
|
size = sizeof(struct param_exchange);
|
||||||
result = Nread(sp->socket, sp->buffer, size, Ptcp);
|
result = Nread(sp->socket, sp->buffer, size, Ptcp);
|
||||||
/* XXX: is there anything that should be done at the point ? */
|
break;
|
||||||
|
case TEST_END:
|
||||||
|
size = sizeof(struct param_exchange);
|
||||||
|
result = Nread(sp->socket, sp->buffer, size, Ptcp);
|
||||||
break;
|
break;
|
||||||
case RESULT_REQUEST:
|
case RESULT_REQUEST:
|
||||||
/* XXX: not working yet */
|
/* XXX: not working yet */
|
||||||
//final_message = iperf_reporter_callback(test);
|
//final_message = iperf_reporter_callback(test);
|
||||||
final_message = "final server results string will go here \n";
|
final_message = "final server results string will go here \n";
|
||||||
memcpy(sp->buffer, final_message, strlen(final_message));
|
//memcpy(sp->buffer, final_message, strlen(final_message));
|
||||||
result = send(sp->socket, sp->buffer, sp->settings->blksize, 0);
|
//result = send(sp->socket, sp->buffer, sp->settings->blksize, 0);
|
||||||
if (result < 0)
|
//if (result < 0)
|
||||||
perror("Error sending results back to client");
|
// perror("Error sending results back to client");
|
||||||
|
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
@ -167,53 +168,48 @@ iperf_tcp_send(struct iperf_stream * sp)
|
|||||||
{
|
{
|
||||||
int result;
|
int result;
|
||||||
int size = sp->settings->blksize;
|
int size = sp->settings->blksize;
|
||||||
struct param_exchange *param = (struct param_exchange *) sp->buffer;
|
|
||||||
|
|
||||||
if (!sp->buffer)
|
if (!sp->buffer)
|
||||||
{
|
{
|
||||||
perror("transmit buffer not allocated");
|
perror("transmit buffer not allocated");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
strncpy(param->cookie, sp->settings->cookie, 37);
|
|
||||||
|
//printf("iperf_tcp_send: state = %d \n", sp->settings->state);
|
||||||
|
sp->buffer[0] = sp->settings->state;
|
||||||
|
|
||||||
|
/* set read size based on message type */
|
||||||
switch (sp->settings->state)
|
switch (sp->settings->state)
|
||||||
{
|
{
|
||||||
case PARAM_EXCHANGE:
|
case PARAM_EXCHANGE:
|
||||||
param->state = PARAM_EXCHANGE;
|
|
||||||
size = sizeof(struct param_exchange);
|
size = sizeof(struct param_exchange);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case STREAM_BEGIN:
|
case STREAM_BEGIN:
|
||||||
param->state = STREAM_BEGIN;
|
|
||||||
size = sp->settings->blksize;
|
size = sp->settings->blksize;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case STREAM_END:
|
case STREAM_END:
|
||||||
param->state = STREAM_END;
|
size = sizeof(struct param_exchange);
|
||||||
size = sp->settings->blksize; /* XXX: this might not be right, will
|
|
||||||
* the last block always be full
|
|
||||||
* size? */
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case RESULT_REQUEST:
|
case RESULT_REQUEST:
|
||||||
param->state = RESULT_REQUEST;
|
size = sp->settings->blksize; /* XXX: what size should this be? */
|
||||||
size = sizeof(struct param_exchange);
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case ALL_STREAMS_END:
|
case ALL_STREAMS_END:
|
||||||
param->state = ALL_STREAMS_END;
|
|
||||||
size = sizeof(struct param_exchange);
|
size = sizeof(struct param_exchange);
|
||||||
break;
|
break;
|
||||||
|
case TEST_END:
|
||||||
|
size = sizeof(struct param_exchange);
|
||||||
|
break;
|
||||||
case STREAM_RUNNING:
|
case STREAM_RUNNING:
|
||||||
param->state = STREAM_RUNNING;
|
|
||||||
size = sp->settings->blksize;
|
size = sp->settings->blksize;
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
printf("State of the stream can't be determined\n");
|
printf("State of the stream can't be determined\n");
|
||||||
break;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
//printf(" in iperf_tcp_send, message type = %d (total = %d bytes) \n", param->state, size);
|
if(sp->settings->state != STREAM_RUNNING)
|
||||||
|
printf(" in iperf_tcp_send, message type = %d (total = %d bytes) \n", sp->settings->state, size);
|
||||||
|
|
||||||
#ifdef USE_SEND
|
#ifdef USE_SEND
|
||||||
result = send(sp->socket, sp->buffer, size, 0);
|
result = send(sp->socket, sp->buffer, size, 0);
|
||||||
#else
|
#else
|
||||||
@ -223,19 +219,15 @@ iperf_tcp_send(struct iperf_stream * sp)
|
|||||||
perror("Write error");
|
perror("Write error");
|
||||||
//printf(" iperf_tcp_send: %d bytes sent \n", result);
|
//printf(" iperf_tcp_send: %d bytes sent \n", result);
|
||||||
|
|
||||||
|
if (sp->settings->state == STREAM_BEGIN || sp->settings->state == STREAM_RUNNING)
|
||||||
|
sp->result->bytes_sent += result;
|
||||||
|
|
||||||
|
//printf("iperf_tcp_send: number bytes sent so far = %u \n", (uint64_t) sp->result->bytes_sent);
|
||||||
|
|
||||||
/* change state after 1st send */
|
/* change state after 1st send */
|
||||||
if (sp->settings->state == STREAM_BEGIN)
|
if (sp->settings->state == STREAM_BEGIN)
|
||||||
sp->settings->state = STREAM_RUNNING;
|
sp->settings->state = STREAM_RUNNING;
|
||||||
|
|
||||||
if (sp->buffer[0] != STREAM_END)
|
|
||||||
/*
|
|
||||||
* XXX: check/fix this. Maybe only want to increment the size with
|
|
||||||
* STREAM_BEGIN and STREAM_RUNNING?
|
|
||||||
*/
|
|
||||||
sp->result->bytes_sent += size;
|
|
||||||
|
|
||||||
//printf("iperf_tcp_send: number bytes sent so far = %u \n", (uint64_t) sp->result->bytes_sent);
|
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -287,7 +279,8 @@ iperf_tcp_accept(struct iperf_test * test)
|
|||||||
} else
|
} else
|
||||||
{
|
{
|
||||||
sp = test->new_stream(test);
|
sp = test->new_stream(test);
|
||||||
setnonblocking(peersock);
|
/* XXX: what is this for? */
|
||||||
|
//setnonblocking(peersock);
|
||||||
|
|
||||||
FD_SET(peersock, &test->read_set);
|
FD_SET(peersock, &test->read_set);
|
||||||
test->max_fd = (test->max_fd < peersock) ? peersock : test->max_fd;
|
test->max_fd = (test->max_fd < peersock) ? peersock : test->max_fd;
|
||||||
|
11
src/main.c
11
src/main.c
@ -224,17 +224,18 @@ iperf_run(struct iperf_test * test)
|
|||||||
switch (test->role)
|
switch (test->role)
|
||||||
{
|
{
|
||||||
case 's':
|
case 's':
|
||||||
iperf_run_server(test);
|
while (1)
|
||||||
|
{
|
||||||
|
iperf_run_server(test);
|
||||||
|
sleep(1);
|
||||||
|
iperf_init_test(test); /* re-initialize everything */
|
||||||
|
}
|
||||||
return 0;
|
return 0;
|
||||||
break;
|
|
||||||
case 'c':
|
case 'c':
|
||||||
iperf_run_client(test);
|
iperf_run_client(test);
|
||||||
return 0;
|
return 0;
|
||||||
break;
|
|
||||||
default:
|
default:
|
||||||
return -1;
|
return -1;
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
printf("Done iperf_run. \n");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user