Fix bug in reverse mode.
This commit is contained in:
parent
78a711169e
commit
8bdc8fffcf
@ -34,6 +34,7 @@ main( int argc, char** argv )
|
||||
exit( EXIT_FAILURE );
|
||||
}
|
||||
iperf_defaults( test );
|
||||
iperf_set_verbose( test, 1 );
|
||||
|
||||
/* This main program doesn't use SIGALRM, so the iperf API may use it. */
|
||||
iperf_set_test_may_use_sigalrm(test, 1);
|
||||
@ -41,6 +42,11 @@ main( int argc, char** argv )
|
||||
iperf_set_test_role( test, 'c' );
|
||||
iperf_set_test_server_hostname( test, host );
|
||||
iperf_set_test_server_port( test, port );
|
||||
/* iperf_set_test_reverse( test, 1 ); */
|
||||
iperf_set_test_omit( test, 3 );
|
||||
iperf_set_test_duration( test, 5 );
|
||||
iperf_set_test_reporter_interval( test, 1 );
|
||||
iperf_set_test_stats_interval( test, 1 );
|
||||
|
||||
if ( iperf_run_client( test ) < 0 ) {
|
||||
fprintf( stderr, "%s: error - %s\n", argv0, iperf_strerror( i_errno ) );
|
||||
|
@ -33,6 +33,7 @@ main( int argc, char** argv )
|
||||
exit( EXIT_FAILURE );
|
||||
}
|
||||
iperf_defaults( test );
|
||||
iperf_set_verbose( test, 1 );
|
||||
iperf_set_test_role( test, 's' );
|
||||
iperf_set_test_server_port( test, port );
|
||||
|
||||
|
114
src/iperf_api.c
114
src/iperf_api.c
@ -832,6 +832,44 @@ iperf_init_test(struct iperf_test *test)
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void
|
||||
send_timer_proc(TimerClientData client_data, struct timeval *nowP)
|
||||
{
|
||||
struct iperf_stream *sp = client_data.p;
|
||||
|
||||
/* All we do here is set or clear the flag saying that this stream may
|
||||
** be sent to. The actual sending gets done in the send proc, after
|
||||
** checking the flag.
|
||||
*/
|
||||
iperf_check_throttle(sp, nowP);
|
||||
}
|
||||
|
||||
int
|
||||
iperf_create_send_timers(struct iperf_test * test)
|
||||
{
|
||||
struct timeval now;
|
||||
struct iperf_stream *sp;
|
||||
TimerClientData cd;
|
||||
|
||||
if (gettimeofday(&now, NULL) < 0) {
|
||||
i_errno = IEINITTEST;
|
||||
return -1;
|
||||
}
|
||||
SLIST_FOREACH(sp, &test->streams, streams) {
|
||||
sp->green_light = 1;
|
||||
if (test->settings->rate != 0) {
|
||||
cd.p = sp;
|
||||
sp->send_timer = tmr_create((struct timeval*) 0, send_timer_proc, cd, 100000L, 1);
|
||||
/* (Repeat every tenth second - arbitrary often value.) */
|
||||
if (sp->send_timer == NULL) {
|
||||
i_errno = IEINITTEST;
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* iperf_exchange_parameters - handles the param_Exchange part for client
|
||||
*
|
||||
@ -1673,50 +1711,46 @@ iperf_print_results(struct iperf_test *test)
|
||||
avg_jitter += sp->jitter;
|
||||
}
|
||||
|
||||
if (bytes_sent > 0) {
|
||||
unit_snprintf(ubuf, UNIT_LEN, (double) bytes_sent, 'A');
|
||||
bandwidth = (double) bytes_sent / (double) end_time;
|
||||
unit_snprintf(nbuf, UNIT_LEN, bandwidth, test->settings->unit_format);
|
||||
if (test->protocol->id == Ptcp) {
|
||||
if (!test->json_output)
|
||||
fputs(" Sent\n", stdout);
|
||||
if (test->sender_has_retransmits) {
|
||||
if (test->json_output)
|
||||
cJSON_AddItemToObject(json_summary_stream, "sent", iperf_json_printf("socket: %d start: %f end: %f seconds: %f bytes: %d bits_per_second: %f retransmits: %d", (int64_t) sp->socket, (double) start_time, (double) end_time, (double) end_time, (int64_t) bytes_sent, bandwidth * 8, (int64_t) sp->result->retransmits));
|
||||
else
|
||||
printf(report_bw_retrans_format, sp->socket, start_time, end_time, ubuf, nbuf, sp->result->retransmits);
|
||||
} else {
|
||||
if (test->json_output)
|
||||
cJSON_AddItemToObject(json_summary_stream, "sent", iperf_json_printf("socket: %d start: %f end: %f seconds: %f bytes: %d bits_per_second: %f", (int64_t) sp->socket, (double) start_time, (double) end_time, (double) end_time, (int64_t) bytes_sent, bandwidth * 8));
|
||||
else
|
||||
printf(report_bw_format, sp->socket, start_time, end_time, ubuf, nbuf);
|
||||
}
|
||||
} else {
|
||||
out_of_order_percent = 100.0 * sp->cnt_error / (sp->packet_count - sp->omitted_packet_count);
|
||||
unit_snprintf(ubuf, UNIT_LEN, (double) bytes_sent, 'A');
|
||||
bandwidth = (double) bytes_sent / (double) end_time;
|
||||
unit_snprintf(nbuf, UNIT_LEN, bandwidth, test->settings->unit_format);
|
||||
if (test->protocol->id == Ptcp) {
|
||||
if (!test->json_output)
|
||||
fputs(" Sent\n", stdout);
|
||||
if (test->sender_has_retransmits) {
|
||||
if (test->json_output)
|
||||
cJSON_AddItemToObject(json_summary_stream, "udp", iperf_json_printf("socket: %d start: %f end: %f seconds: %f bytes: %d bits_per_second: %f jitter_ms: %f outoforder: %d packets: %d percent: %f", (int64_t) sp->socket, (double) start_time, (double) end_time, (double) end_time, (int64_t) bytes_sent, bandwidth * 8, (double) sp->jitter * 1000.0, (int64_t) sp->cnt_error, (int64_t) (sp->packet_count - sp->omitted_packet_count), out_of_order_percent));
|
||||
else {
|
||||
printf(report_bw_udp_format, sp->socket, start_time, end_time, ubuf, nbuf, sp->jitter * 1000.0, sp->cnt_error, (sp->packet_count - sp->omitted_packet_count), out_of_order_percent);
|
||||
if (test->role == 'c')
|
||||
printf(report_datagrams, sp->socket, (sp->packet_count - sp->omitted_packet_count));
|
||||
if (sp->outoforder_packets > 0)
|
||||
printf(report_sum_outoforder, start_time, end_time, sp->cnt_error);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (bytes_received > 0) {
|
||||
unit_snprintf(ubuf, UNIT_LEN, (double) bytes_received, 'A');
|
||||
bandwidth = (double) bytes_received / (double) end_time;
|
||||
unit_snprintf(nbuf, UNIT_LEN, bandwidth, test->settings->unit_format);
|
||||
if (test->protocol->id == Ptcp) {
|
||||
if (!test->json_output)
|
||||
printf(" Received\n");
|
||||
cJSON_AddItemToObject(json_summary_stream, "sent", iperf_json_printf("socket: %d start: %f end: %f seconds: %f bytes: %d bits_per_second: %f retransmits: %d", (int64_t) sp->socket, (double) start_time, (double) end_time, (double) end_time, (int64_t) bytes_sent, bandwidth * 8, (int64_t) sp->result->retransmits));
|
||||
else
|
||||
printf(report_bw_retrans_format, sp->socket, start_time, end_time, ubuf, nbuf, sp->result->retransmits);
|
||||
} else {
|
||||
if (test->json_output)
|
||||
cJSON_AddItemToObject(json_summary_stream, "received", iperf_json_printf("socket: %d start: %f end: %f seconds: %f bytes: %d bits_per_second: %f", (int64_t) sp->socket, (double) start_time, (double) end_time, (double) end_time, (int64_t) bytes_received, bandwidth * 8));
|
||||
cJSON_AddItemToObject(json_summary_stream, "sent", iperf_json_printf("socket: %d start: %f end: %f seconds: %f bytes: %d bits_per_second: %f", (int64_t) sp->socket, (double) start_time, (double) end_time, (double) end_time, (int64_t) bytes_sent, bandwidth * 8));
|
||||
else
|
||||
printf(report_bw_format, sp->socket, start_time, end_time, ubuf, nbuf);
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
out_of_order_percent = 100.0 * sp->cnt_error / (sp->packet_count - sp->omitted_packet_count);
|
||||
if (test->json_output)
|
||||
cJSON_AddItemToObject(json_summary_stream, "udp", iperf_json_printf("socket: %d start: %f end: %f seconds: %f bytes: %d bits_per_second: %f jitter_ms: %f outoforder: %d packets: %d percent: %f", (int64_t) sp->socket, (double) start_time, (double) end_time, (double) end_time, (int64_t) bytes_sent, bandwidth * 8, (double) sp->jitter * 1000.0, (int64_t) sp->cnt_error, (int64_t) (sp->packet_count - sp->omitted_packet_count), out_of_order_percent));
|
||||
else {
|
||||
printf(report_bw_udp_format, sp->socket, start_time, end_time, ubuf, nbuf, sp->jitter * 1000.0, sp->cnt_error, (sp->packet_count - sp->omitted_packet_count), out_of_order_percent);
|
||||
if (test->role == 'c')
|
||||
printf(report_datagrams, sp->socket, (sp->packet_count - sp->omitted_packet_count));
|
||||
if (sp->outoforder_packets > 0)
|
||||
printf(report_sum_outoforder, start_time, end_time, sp->cnt_error);
|
||||
}
|
||||
}
|
||||
unit_snprintf(ubuf, UNIT_LEN, (double) bytes_received, 'A');
|
||||
bandwidth = (double) bytes_received / (double) end_time;
|
||||
unit_snprintf(nbuf, UNIT_LEN, bandwidth, test->settings->unit_format);
|
||||
if (test->protocol->id == Ptcp) {
|
||||
if (!test->json_output)
|
||||
printf(" Received\n");
|
||||
if (test->json_output)
|
||||
cJSON_AddItemToObject(json_summary_stream, "received", iperf_json_printf("socket: %d start: %f end: %f seconds: %f bytes: %d bits_per_second: %f", (int64_t) sp->socket, (double) start_time, (double) end_time, (double) end_time, (int64_t) bytes_received, bandwidth * 8));
|
||||
else
|
||||
printf(report_bw_format, sp->socket, start_time, end_time, ubuf, nbuf);
|
||||
}
|
||||
}
|
||||
|
||||
if (test->num_streams > 1) {
|
||||
|
@ -176,6 +176,7 @@ void warning(char *);
|
||||
int iperf_sum_results(struct iperf_test *);
|
||||
int iperf_exchange_results(struct iperf_test *);
|
||||
int iperf_init_test(struct iperf_test *);
|
||||
int iperf_create_send_timers(struct iperf_test *);
|
||||
int iperf_parse_arguments(struct iperf_test *, int, char **);
|
||||
void iperf_reset_test(struct iperf_test *);
|
||||
void iperf_reset_stats(struct iperf_test * test);
|
||||
|
@ -143,44 +143,6 @@ create_client_omit_timer(struct iperf_test * test)
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void
|
||||
send_timer_proc(TimerClientData client_data, struct timeval *nowP)
|
||||
{
|
||||
struct iperf_stream *sp = client_data.p;
|
||||
|
||||
/* All we do here is set or clear the flag saying that this stream may
|
||||
** be sent to. The actual sending gets done in the send proc, after
|
||||
** checking the flag.
|
||||
*/
|
||||
iperf_check_throttle(sp, nowP);
|
||||
}
|
||||
|
||||
static int
|
||||
create_send_timers(struct iperf_test * test)
|
||||
{
|
||||
struct timeval now;
|
||||
struct iperf_stream *sp;
|
||||
TimerClientData cd;
|
||||
|
||||
if (gettimeofday(&now, NULL) < 0) {
|
||||
i_errno = IEINITTEST;
|
||||
return -1;
|
||||
}
|
||||
SLIST_FOREACH(sp, &test->streams, streams) {
|
||||
sp->green_light = 1;
|
||||
if (test->settings->rate != 0) {
|
||||
cd.p = sp;
|
||||
sp->send_timer = tmr_create((struct timeval*) 0, send_timer_proc, cd, 100000L, 1);
|
||||
/* (Repeat every tenth second - arbitrary often value.) */
|
||||
if (sp->send_timer == NULL) {
|
||||
i_errno = IEINITTEST;
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
int
|
||||
iperf_handle_message_client(struct iperf_test *test)
|
||||
{
|
||||
@ -212,8 +174,9 @@ iperf_handle_message_client(struct iperf_test *test)
|
||||
return -1;
|
||||
if (create_client_omit_timer(test) < 0)
|
||||
return -1;
|
||||
if (create_send_timers(test) < 0)
|
||||
return -1;
|
||||
if (!test->reverse)
|
||||
if (iperf_create_send_timers(test) < 0)
|
||||
return -1;
|
||||
break;
|
||||
case TEST_RUNNING:
|
||||
break;
|
||||
|
@ -135,12 +135,10 @@ iperf_accept(struct iperf_test *test)
|
||||
|
||||
if (iperf_set_send_state(test, PARAM_EXCHANGE) != 0)
|
||||
return -1;
|
||||
if (iperf_exchange_parameters(test) < 0) {
|
||||
if (iperf_exchange_parameters(test) < 0)
|
||||
return -1;
|
||||
}
|
||||
if (test->on_connect) {
|
||||
if (test->on_connect)
|
||||
test->on_connect(test);
|
||||
}
|
||||
} else {
|
||||
/* XXX: Do we even need to receive cookie if we're just going to deny anyways? */
|
||||
if (Nread(s, cookie, COOKIE_SIZE, Ptcp) < 0) {
|
||||
@ -440,6 +438,11 @@ iperf_run_server(struct iperf_test *test)
|
||||
cleanup_server(test);
|
||||
return -1;
|
||||
}
|
||||
if (test->reverse)
|
||||
if (iperf_create_send_timers(test) < 0) {
|
||||
cleanup_server(test);
|
||||
return -1;
|
||||
}
|
||||
if (iperf_set_send_state(test, TEST_RUNNING) != 0) {
|
||||
cleanup_server(test);
|
||||
return -1;
|
||||
|
Loading…
Reference in New Issue
Block a user