Skip to content

Commit

Permalink
Per reviewer comment - reimplemented to support backward compatibility
Browse files Browse the repository at this point in the history
  • Loading branch information
davidBar-On committed Apr 8, 2023
1 parent 8aaa205 commit 87cef99
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 14 deletions.
1 change: 1 addition & 0 deletions src/iperf.h
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,7 @@ struct iperf_stream
*/
int packet_count;
int peer_packet_count;
int peer_omitted_packet_count;
int omitted_packet_count;
double jitter;
double prev_transit;
Expand Down
70 changes: 56 additions & 14 deletions src/iperf_api.c
Original file line number Diff line number Diff line change
Expand Up @@ -2410,7 +2410,9 @@ send_results(struct iperf_test *test)
cJSON_AddNumberToObject(j_stream, "retransmits", retransmits);
cJSON_AddNumberToObject(j_stream, "jitter", sp->jitter);
cJSON_AddNumberToObject(j_stream, "errors", sp->cnt_error);
cJSON_AddNumberToObject(j_stream, "omitted_errors", sp->omitted_cnt_error);
cJSON_AddNumberToObject(j_stream, "packets", sp->packet_count);
cJSON_AddNumberToObject(j_stream, "omitted_packets", sp->omitted_packet_count);

iperf_time_diff(&sp->result->start_time, &sp->result->start_time, &temp_time);
start_time = iperf_time_in_secs(&temp_time);
Expand Down Expand Up @@ -2457,10 +2459,12 @@ get_results(struct iperf_test *test)
cJSON *j_retransmits;
cJSON *j_jitter;
cJSON *j_errors;
cJSON *j_omitted_errors;
cJSON *j_packets;
cJSON *j_omitted_packets;
cJSON *j_server_output;
cJSON *j_start_time, *j_end_time;
int sid, cerror, pcount;
int sid, cerror, pcount, omitted_cerror, omitted_pcount;
double jitter;
iperf_size_t bytes_transferred;
int retransmits;
Expand Down Expand Up @@ -2513,19 +2517,29 @@ get_results(struct iperf_test *test)
j_retransmits = cJSON_GetObjectItem(j_stream, "retransmits");
j_jitter = cJSON_GetObjectItem(j_stream, "jitter");
j_errors = cJSON_GetObjectItem(j_stream, "errors");
j_omitted_errors = cJSON_GetObjectItem(j_stream, "omitted_errors");
j_packets = cJSON_GetObjectItem(j_stream, "packets");
j_omitted_packets = cJSON_GetObjectItem(j_stream, "omitted_packets");
j_start_time = cJSON_GetObjectItem(j_stream, "start_time");
j_end_time = cJSON_GetObjectItem(j_stream, "end_time");
if (j_id == NULL || j_bytes == NULL || j_retransmits == NULL || j_jitter == NULL || j_errors == NULL || j_packets == NULL) {
i_errno = IERECVRESULTS;
r = -1;
} else if ( (j_omitted_errors == NULL && j_omitted_packets != NULL) || (j_omitted_errors != NULL && j_omitted_packets == NULL) ) {
/* For backward compatibility allow to not receive "omitted" statistcs */
i_errno = IERECVRESULTS;
r = -1;
} else {
sid = j_id->valueint;
bytes_transferred = j_bytes->valueint;
retransmits = j_retransmits->valueint;
jitter = j_jitter->valuedouble;
cerror = j_errors->valueint;
pcount = j_packets->valueint;
if (j_omitted_packets != NULL) {
omitted_cerror = j_omitted_errors->valueint;
omitted_pcount = j_omitted_packets->valueint;
}
SLIST_FOREACH(sp, &test->streams, streams)
if (sp->id == sid) break;
if (sp == NULL) {
Expand All @@ -2537,6 +2551,18 @@ get_results(struct iperf_test *test)
sp->cnt_error = cerror;
sp->peer_packet_count = pcount;
sp->result->bytes_received = bytes_transferred;
if (j_omitted_packets != NULL) {
sp->omitted_cnt_error = omitted_cerror;
sp->peer_omitted_packet_count = omitted_pcount;
} else {
sp->peer_omitted_packet_count = sp->omitted_packet_count;
if (sp->peer_omitted_packet_count > 0) {
/* -1 indicates unknown error count since it includes the omitted count */
sp->omitted_cnt_error = (sp->cnt_error > 0) ? -1 : 0;
} else {
sp->omitted_cnt_error = sp->cnt_error;
}
}
/*
* We have to handle the possibility that
* start_time and end_time might not be
Expand All @@ -2556,6 +2582,11 @@ get_results(struct iperf_test *test)
sp->peer_packet_count = pcount;
sp->result->bytes_sent = bytes_transferred;
sp->result->stream_retrans = retransmits;
if (j_omitted_packets != NULL) {
sp->peer_omitted_packet_count = omitted_pcount;
} else {
sp->peer_omitted_packet_count = sp->peer_packet_count;
}
if (j_start_time && j_end_time) {
sp->result->sender_time = j_end_time->valuedouble - j_start_time->valuedouble;
}
Expand Down Expand Up @@ -3583,6 +3614,7 @@ iperf_print_results(struct iperf_test *test)
int total_retransmits = 0;
int total_packets = 0, lost_packets = 0;
int sender_packet_count = 0, receiver_packet_count = 0; /* for this stream, this interval */
int sender_omitted_packet_count = 0, receiver_omitted_packet_count = 0; /* for this stream, this interval */
int sender_total_packets = 0, receiver_total_packets = 0; /* running total */
char ubuf[UNIT_LEN];
char nbuf[UNIT_LEN];
Expand All @@ -3593,7 +3625,7 @@ iperf_print_results(struct iperf_test *test)
iperf_size_t bytes_received, total_received = 0;
double start_time, end_time = 0.0, avg_jitter = 0.0, lost_percent = 0.0;
double sender_time = 0.0, receiver_time = 0.0;
struct iperf_time temp_time;
struct iperf_time temp_time;
double bandwidth;

char mbuf[UNIT_LEN];
Expand Down Expand Up @@ -3631,8 +3663,8 @@ iperf_print_results(struct iperf_test *test)
*/

if (sp) {
iperf_time_diff(&sp->result->start_time, &sp->result->end_time, &temp_time);
end_time = iperf_time_in_secs(&temp_time);
iperf_time_diff(&sp->result->start_time, &sp->result->end_time, &temp_time);
end_time = iperf_time_in_secs(&temp_time);
if (sp->sender) {
sp->result->sender_time = end_time;
if (sp->result->receiver_time == 0.0) {
Expand Down Expand Up @@ -3663,11 +3695,15 @@ iperf_print_results(struct iperf_test *test)

if (sp->sender) {
sender_packet_count = sp->packet_count;
sender_omitted_packet_count = sp->omitted_packet_count;
receiver_packet_count = sp->peer_packet_count;
receiver_omitted_packet_count = sp->peer_omitted_packet_count;
}
else {
sender_packet_count = sp->peer_packet_count;
sender_omitted_packet_count = sp->peer_omitted_packet_count;
receiver_packet_count = sp->packet_count;
receiver_omitted_packet_count = sp->omitted_packet_count;
}

if (test->protocol->id == Ptcp || test->protocol->id == Psctp) {
Expand All @@ -3681,9 +3717,11 @@ iperf_print_results(struct iperf_test *test)
*/
int packet_count = sender_packet_count ? sender_packet_count : receiver_packet_count;
total_packets += (packet_count - sp->omitted_packet_count);
sender_total_packets += (sender_packet_count - sp->omitted_packet_count);
receiver_total_packets += (receiver_packet_count - sp->omitted_packet_count);
lost_packets += (sp->cnt_error - sp->omitted_cnt_error);
sender_total_packets += (sender_packet_count - sender_omitted_packet_count);
receiver_total_packets += (receiver_packet_count - receiver_omitted_packet_count);
lost_packets += sp->cnt_error;
if (sp->omitted_cnt_error > -1)
lost_packets -= sp->omitted_cnt_error;
avg_jitter += sp->jitter;
}

Expand Down Expand Up @@ -3723,15 +3761,15 @@ iperf_print_results(struct iperf_test *test)
}
} else {
/* Sender summary, UDP. */
if (sender_packet_count - sp->omitted_packet_count > 0) {
lost_percent = 100.0 * (sp->cnt_error - sp->omitted_cnt_error) / (sender_packet_count - sp->omitted_packet_count);
if (sender_packet_count - sender_omitted_packet_count > 0) {
lost_percent = 100.0 * (sp->cnt_error - sp->omitted_cnt_error) / (sender_packet_count - sender_omitted_packet_count);
}
else {
lost_percent = 0.0;
}
if (test->json_output) {
/*
* For hysterical raisins, we only emit one JSON
* For historical reasons, we only emit one JSON
* object for the UDP summary, and it contains
* information for both the sender and receiver
* side.
Expand Down Expand Up @@ -3762,7 +3800,7 @@ iperf_print_results(struct iperf_test *test)
iperf_printf(test, report_sender_not_available_format, sp->socket);
}
else {
iperf_printf(test, report_bw_udp_format, sp->socket, mbuf, start_time, sender_time, ubuf, nbuf, 0.0, 0, (sender_packet_count - sp->omitted_packet_count), (double) 0, report_sender);
iperf_printf(test, report_bw_udp_format, sp->socket, mbuf, start_time, sender_time, ubuf, nbuf, 0.0, 0, (sender_packet_count - sender_omitted_packet_count), (double) 0, report_sender);
}
if ((sp->outoforder_packets - sp->omitted_outoforder_packets) > 0)
iperf_printf(test, report_sum_outoforder, mbuf, start_time, sender_time, (sp->outoforder_packets - sp->omitted_outoforder_packets));
Expand Down Expand Up @@ -3819,8 +3857,8 @@ iperf_print_results(struct iperf_test *test)
* data here.
*/
if (! test->json_output) {
if (receiver_packet_count - sp->omitted_packet_count > 0) {
lost_percent = 100.0 * (sp->cnt_error - sp->omitted_cnt_error) / (receiver_packet_count - sp->omitted_packet_count);
if (receiver_packet_count - receiver_omitted_packet_count > 0 && sp->omitted_cnt_error > -1) {
lost_percent = 100.0 * (sp->cnt_error - sp->omitted_cnt_error) / (receiver_packet_count - receiver_omitted_packet_count);
}
else {
lost_percent = 0.0;
Expand All @@ -3831,7 +3869,11 @@ iperf_print_results(struct iperf_test *test)
iperf_printf(test, report_receiver_not_available_format, sp->socket);
}
else {
iperf_printf(test, report_bw_udp_format, sp->socket, mbuf, start_time, receiver_time, ubuf, nbuf, sp->jitter * 1000.0, (sp->cnt_error - sp->omitted_cnt_error), (receiver_packet_count - sp->omitted_packet_count), lost_percent, report_receiver);
if (sp->omitted_cnt_error > -1) {
iperf_printf(test, report_bw_udp_format, sp->socket, mbuf, start_time, receiver_time, ubuf, nbuf, sp->jitter * 1000.0, (sp->cnt_error - sp->omitted_cnt_error), (receiver_packet_count - receiver_omitted_packet_count), lost_percent, report_receiver);
} else {
iperf_printf(test, report_bw_udp_format_no_omitted_error, sp->socket, mbuf, start_time, receiver_time, ubuf, nbuf, sp->jitter * 1000.0, (receiver_packet_count - receiver_omitted_packet_count), report_receiver);
}
}
}
}
Expand Down
3 changes: 3 additions & 0 deletions src/iperf_locale.c
Original file line number Diff line number Diff line change
Expand Up @@ -384,6 +384,9 @@ const char report_bw_retrans_cwnd_format[] =
const char report_bw_udp_format[] =
"[%3d]%s %6.2f-%-6.2f sec %ss %ss/sec %5.3f ms %d/%d (%.2g%%) %s\n";

const char report_bw_udp_format_no_omitted_error[] =
"[%3d]%s %6.2f-%-6.2f sec %ss %ss/sec %5.3f ms Unknown/%d %s\n";

const char report_bw_udp_sender_format[] =
"[%3d]%s %6.2f-%-6.2f sec %ss %ss/sec %s %d %s\n";

Expand Down
1 change: 1 addition & 0 deletions src/iperf_locale.h
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ extern const char report_bw_format[] ;
extern const char report_bw_retrans_format[] ;
extern const char report_bw_retrans_cwnd_format[] ;
extern const char report_bw_udp_format[] ;
extern const char report_bw_udp_format_no_omitted_error[] ;
extern const char report_bw_udp_sender_format[] ;
extern const char report_summary[] ;
extern const char report_sum_bw_format[] ;
Expand Down

0 comments on commit 87cef99

Please sign in to comment.