Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add debug messges when State changes #1734

Merged
merged 1 commit into from
Jul 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions src/iperf_api.c
Original file line number Diff line number Diff line change
Expand Up @@ -481,6 +481,10 @@ iperf_set_test_stats_interval(struct iperf_test *ipt, double stats_interval)
void
iperf_set_test_state(struct iperf_test *ipt, signed char state)
{
if (ipt->debug_level >= DEBUG_LEVEL_INFO) {
iperf_printf(ipt, "State change: State set to %d-%s (from %d-%s)\n",
state, state_to_text(state), ipt->state, state_to_text(ipt->state));
}
ipt->state = state;
}

Expand Down Expand Up @@ -1862,7 +1866,7 @@ int
iperf_set_send_state(struct iperf_test *test, signed char state)
{
if (test->ctrl_sck >= 0) {
test->state = state;
iperf_set_test_state(test, state);
if (Nwrite(test->ctrl_sck, (char*) &state, sizeof(state), Ptcp) < 0) {
i_errno = IESENDMESSAGE;
return -1;
Expand Down Expand Up @@ -4746,14 +4750,14 @@ iperf_got_sigend(struct iperf_test *test)
test->done = 1;
cpu_util(test->cpu_util);
test->stats_callback(test);
test->state = DISPLAY_RESULTS; /* change local state only */
iperf_set_test_state(test, DISPLAY_RESULTS); /* change local state only */
if (test->on_test_finish)
test->on_test_finish(test);
test->reporter_callback(test);
}

if (test->ctrl_sck >= 0) {
test->state = (test->role == 'c') ? CLIENT_TERMINATE : SERVER_TERMINATE;
iperf_set_test_state(test, (test->role == 'c') ? CLIENT_TERMINATE : SERVER_TERMINATE);
(void) Nwrite(test->ctrl_sck, (char*) &test->state, sizeof(signed char), Ptcp);
}
i_errno = (test->role == 'c') ? IECLIENTTERM : IESERVERTERM;
Expand Down
9 changes: 9 additions & 0 deletions src/iperf_client_api.c
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,11 @@ iperf_handle_message_client(struct iperf_test *test)
i_errno = IEINITTEST;
return -1;
}

if (test->debug_level >= DEBUG_LEVEL_INFO) {
iperf_printf(test, "Reading new State from the Server - current state is %d-%s\n", test->state, state_to_text(test->state));
}

/*!!! Why is this read() and not Nread()? */
if ((rval = read(test->ctrl_sck, (char*) &test->state, sizeof(signed char))) <= 0) {
if (rval == 0) {
Expand All @@ -299,6 +304,10 @@ iperf_handle_message_client(struct iperf_test *test)
}
}

if (test->debug_level >= DEBUG_LEVEL_INFO) {
iperf_printf(test, "State change: client received and changed State to %d-%s\n", test->state, state_to_text(test->state));
}

switch (test->state) {
case PARAM_EXCHANGE:
if (iperf_exchange_parameters(test) < 0)
Expand Down
14 changes: 11 additions & 3 deletions src/iperf_server_api.c
Original file line number Diff line number Diff line change
Expand Up @@ -218,19 +218,27 @@ iperf_handle_message_server(struct iperf_test *test)
int rval;
struct iperf_stream *sp;

if (test->debug_level >= DEBUG_LEVEL_INFO) {
iperf_printf(test, "Reading new State from the Client - current state is %d-%s\n", test->state, state_to_text(test->state));
}

// XXX: Need to rethink how this behaves to fit API
if ((rval = Nread(test->ctrl_sck, (char*) &test->state, sizeof(signed char), Ptcp)) <= 0) {
if (rval == 0) {
iperf_err(test, "the client has unexpectedly closed the connection");
i_errno = IECTRLCLOSE;
test->state = IPERF_DONE;
iperf_set_test_state(test, IPERF_DONE);
return 0;
} else {
i_errno = IERECVMESSAGE;
return -1;
}
}

if (test->debug_level >= DEBUG_LEVEL_INFO) {
iperf_printf(test, "State change: server received and changed State to %d-%s\n", test->state, state_to_text(test->state));
}

switch(test->state) {
case TEST_START:
break;
Expand Down Expand Up @@ -273,7 +281,7 @@ iperf_handle_message_server(struct iperf_test *test)
FD_CLR(sp->socket, &test->write_set);
close(sp->socket);
}
test->state = IPERF_DONE;
iperf_set_test_state(test, IPERF_DONE);
break;
default:
i_errno = IEMESSAGE;
Expand Down Expand Up @@ -552,7 +560,7 @@ iperf_run_server(struct iperf_test *test)
iperf_time_now(&last_receive_time); // Initialize last time something was received
last_receive_blocks = 0;

test->state = IPERF_START;
iperf_set_test_state(test, IPERF_START);
send_streams_accepted = 0;
rec_streams_accepted = 0;
rcv_timeout_us = (test->settings->rcv_timeout.secs * SEC_TO_US) + test->settings->rcv_timeout.usecs;
Expand Down
3 changes: 2 additions & 1 deletion src/iperf_tcp.c
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
#include "iperf.h"
#include "iperf_api.h"
#include "iperf_tcp.h"
#include "iperf_util.h"
#include "net.h"
#include "cjson.h"

Expand Down Expand Up @@ -69,7 +70,7 @@ iperf_tcp_recv(struct iperf_stream *sp)
}
else {
if (sp->test->debug)
printf("Late receive, state = %d\n", sp->test->state);
printf("Late receive, state = %d-%s\n", sp->test->state, state_to_text(sp->test->state));
}

return r;
Expand Down
27 changes: 27 additions & 0 deletions src/iperf_util.c
Original file line number Diff line number Diff line change
Expand Up @@ -595,3 +595,30 @@ getline(char **buf, size_t *bufsiz, FILE *fp)
}

#endif

/* Translate numeric State to text - for debugging pupposes */
char *
state_to_text(signed char state)
{
char *txt;

switch (state) {
case 0: txt = "Test reset"; break;
case TEST_START: txt = "TEST_START - starting a new test"; break;
case TEST_RUNNING: txt = "TEST_RUNNING"; break;
case TEST_END: txt = "TEST_END"; break;
case PARAM_EXCHANGE: txt = "PARAM_EXCHANGE - Client to Server Parameters Exchange"; break;
case CREATE_STREAMS: txt = "CREATE_STREAMS"; break;
case SERVER_TERMINATE: txt = "SERVER_TERMINATE"; break;
case CLIENT_TERMINATE: txt = "CLIENT_TERMINATE"; break;
case EXCHANGE_RESULTS: txt = "EXCHANGE_RESULTS"; break;
case DISPLAY_RESULTS: txt = "DISPLAY_RESULTS"; break;
case IPERF_START: txt = "IPERF_START - waiting for a new test"; break;
case IPERF_DONE: txt = "IPERF_DONE"; break;
case ACCESS_DENIED: txt = "ACCESS_DENIED - Server is busy"; break;
case SERVER_ERROR: txt = "SERVER_ERROR"; break;
default: txt = "Unknown State";
}

return txt;
}
2 changes: 2 additions & 0 deletions src/iperf_util.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,4 +64,6 @@ extern int daemon(int nochdir, int noclose);
ssize_t getline(char **buf, size_t *bufsiz, FILE *fp);
#endif /* HAVE_GETLINE */

char * state_to_text(signed char state);

#endif
Loading