Skip to content
Open
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
75 changes: 45 additions & 30 deletions src/iperf_api.c
Original file line number Diff line number Diff line change
Expand Up @@ -920,6 +920,21 @@ iperf_parse_arguments(struct iperf_test *test, int argc, char **argv)
client_flag = 1;
break;
case 'n':
/* take the same approach as with -b to make it backwards compatible */
/* -b <burst_size> as legacy
-b <burst_size>/<multisend> for new behaviour
-b <burst_size>/1 should make iperf3 repeatable */
slash = strchr(optarg, '/');
if (slash) {
*slash = '\0';
++slash;
test->multisend = atoi(slash);
if (test->multisend <= 0 ||
test->multisend > MAX_BURST) {
i_errno = IEBURST;
return -1;
}
}
test->settings->bytes = unit_atoi(optarg);
client_flag = 1;
break;
Expand All @@ -945,7 +960,7 @@ iperf_parse_arguments(struct iperf_test *test, int argc, char **argv)
break;
case 'w':
// XXX: This is a socket buffer, not specific to TCP
// Do sanity checks as double-precision floating point
// Do sanity checks as double-precision floating point
// to avoid possible integer overflows.
farg = unit_atof(optarg);
if (farg > (double) MAX_TCP_BUFFER) {
Expand Down Expand Up @@ -1055,7 +1070,7 @@ iperf_parse_arguments(struct iperf_test *test, int argc, char **argv)
case 'A':
#if defined(HAVE_CPU_AFFINITY)
test->affinity = strtol(optarg, &endptr, 0);
if (endptr == optarg ||
if (endptr == optarg ||
test->affinity < 0 || test->affinity > 1024) {
i_errno = IEAFFINITY;
return -1;
Expand Down Expand Up @@ -1181,7 +1196,7 @@ iperf_parse_arguments(struct iperf_test *test, int argc, char **argv)
if (test->role == 's' && (client_username || client_rsa_public_key)){
i_errno = IECLIENTONLY;
return -1;
} else if (test->role == 'c' && (client_username || client_rsa_public_key) &&
} else if (test->role == 'c' && (client_username || client_rsa_public_key) &&
!(client_username && client_rsa_public_key)) {
i_errno = IESETCLIENTAUTH;
return -1;
Expand All @@ -1191,7 +1206,7 @@ iperf_parse_arguments(struct iperf_test *test, int argc, char **argv)
size_t s;
if (iperf_getpass(&client_password, &s, stdin) < 0){
return -1;
}
}

if (strlen(client_username) > 20 || strlen(client_password) > 20){
i_errno = IESETCLIENTAUTH;
Expand All @@ -1211,7 +1226,7 @@ iperf_parse_arguments(struct iperf_test *test, int argc, char **argv)
if (test->role == 'c' && (server_rsa_private_key || test->server_authorized_users)){
i_errno = IESERVERONLY;
return -1;
} else if (test->role == 's' && (server_rsa_private_key || test->server_authorized_users) &&
} else if (test->role == 's' && (server_rsa_private_key || test->server_authorized_users) &&
!(server_rsa_private_key && test->server_authorized_users)) {
i_errno = IESETSERVERAUTH;
return -1;
Expand All @@ -1231,7 +1246,7 @@ iperf_parse_arguments(struct iperf_test *test, int argc, char **argv)
else
blksize = DEFAULT_TCP_BLKSIZE;
}
if ((test->protocol->id != Pudp && blksize <= 0)
if ((test->protocol->id != Pudp && blksize <= 0)
|| blksize > MAX_BLOCKSIZE) {
i_errno = IEBLOCKSIZE;
return -1;
Expand Down Expand Up @@ -2156,7 +2171,7 @@ protocol_new(void)
void
protocol_free(struct protocol *proto)
{
free(proto);
free(proto);
}

/**************************************************************************/
Expand Down Expand Up @@ -2331,7 +2346,7 @@ iperf_free_test(struct iperf_test *test)
/* Free protocol list */
while (!SLIST_EMPTY(&test->protocols)) {
prot = SLIST_FIRST(&test->protocols);
SLIST_REMOVE_HEAD(&test->protocols, protocols);
SLIST_REMOVE_HEAD(&test->protocols, protocols);
free(prot);
}

Expand Down Expand Up @@ -2416,7 +2431,7 @@ iperf_reset_test(struct iperf_test *test)
CPU_ZERO(&test->cpumask);
#endif /* HAVE_CPUSET_SETAFFINITY */
test->state = 0;

test->ctrl_sck = -1;
test->prot_listener = -1;

Expand All @@ -2428,7 +2443,7 @@ iperf_reset_test(struct iperf_test *test)

FD_ZERO(&test->read_set);
FD_ZERO(&test->write_set);

test->num_streams = 1;
test->settings->socket_bufsize = 0;
test->settings->blksize = DEFAULT_TCP_BLKSIZE;
Expand Down Expand Up @@ -2530,7 +2545,7 @@ iperf_stats_callback(struct iperf_test *test)
rp = sp->result;

temp.bytes_transferred = test->sender ? rp->bytes_sent_this_interval : rp->bytes_received_this_interval;

irp = TAILQ_LAST(&rp->interval_results, irlisthead);
/* result->end_time contains timestamp of previous interval */
if ( irp != NULL ) /* not the 1st interval */
Expand All @@ -2555,7 +2570,7 @@ iperf_stats_callback(struct iperf_test *test)
if (temp.snd_cwnd > rp->stream_max_snd_cwnd) {
rp->stream_max_snd_cwnd = temp.snd_cwnd;
}

temp.rtt = get_rtt(&temp);
if (temp.rtt > rp->stream_max_rtt) {
rp->stream_max_rtt = temp.rtt;
Expand Down Expand Up @@ -2789,7 +2804,7 @@ iperf_print_results(struct iperf_test *test)

start_time = 0.;
sp = SLIST_FIRST(&test->streams);
/*
/*
* If there is at least one stream, then figure out the length of time
* we were running the tests and print out some statistics about
* the streams. It's possible to not have any streams at all
Expand Down Expand Up @@ -2838,7 +2853,7 @@ iperf_print_results(struct iperf_test *test)
sender_packet_count = sp->peer_packet_count;
receiver_packet_count = sp->packet_count;
}

if (test->protocol->id == Ptcp || test->protocol->id == Psctp) {
if (test->sender_has_retransmits) {
total_retransmits += sp->result->stream_retrans;
Expand Down Expand Up @@ -2871,7 +2886,7 @@ iperf_print_results(struct iperf_test *test)
cJSON_AddItemToObject(json_summary_stream, "sender", iperf_json_printf("socket: %d start: %f end: %f seconds: %f bytes: %d bits_per_second: %f retransmits: %d max_snd_cwnd: %d max_rtt: %d min_rtt: %d mean_rtt: %d", (int64_t) sp->socket, (double) start_time, (double) sender_time, (double) sender_time, (int64_t) bytes_sent, bandwidth * 8, (int64_t) sp->result->stream_retrans, (int64_t) sp->result->stream_max_snd_cwnd, (int64_t) sp->result->stream_max_rtt, (int64_t) sp->result->stream_min_rtt, (int64_t) ((sp->result->stream_count_rtt == 0) ? 0 : sp->result->stream_sum_rtt / sp->result->stream_count_rtt)));
else
if (test->role == 's' && !test->sender) {
if (test->verbose)
if (test->verbose)
iperf_printf(test, report_sender_not_available_format, sp->socket);
}
else {
Expand Down Expand Up @@ -2899,7 +2914,7 @@ iperf_print_results(struct iperf_test *test)
lost_percent = 0.0;
}
if (test->json_output) {
/*
/*
* For hysterical raisins, we only emit one JSON
* object for the UDP summary, and it contains
* information for both the sender and receiver
Expand Down Expand Up @@ -2927,7 +2942,7 @@ iperf_print_results(struct iperf_test *test)
* results.
*/
if (test->role == 's' && !test->sender) {
if (test->verbose)
if (test->verbose)
iperf_printf(test, report_sender_not_available_format, sp->socket);
}
else {
Expand Down Expand Up @@ -2974,15 +2989,15 @@ iperf_print_results(struct iperf_test *test)
cJSON_AddItemToObject(json_summary_stream, "receiver", 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) receiver_time, (double) end_time, (int64_t) bytes_received, bandwidth * 8));
else
if (test->role == 's' && test->sender) {
if (test->verbose)
if (test->verbose)
iperf_printf(test, report_receiver_not_available_format, sp->socket);
}
else {
iperf_printf(test, report_bw_format, sp->socket, start_time, receiver_time, ubuf, nbuf, report_receiver);
}
}
else {
/*
/*
* Receiver summary, UDP. Note that JSON was emitted with
* the sender summary, so we only deal with human-readable
* data here.
Expand Down Expand Up @@ -3036,7 +3051,7 @@ iperf_print_results(struct iperf_test *test)
cJSON_AddItemToObject(test->json_end, "sum_sent", iperf_json_printf("start: %f end: %f seconds: %f bytes: %d bits_per_second: %f", (double) start_time, (double) sender_time, (double) sender_time, (int64_t) total_sent, bandwidth * 8));
else
if (test->role == 's' && !test->sender) {
if (test->verbose)
if (test->verbose)
iperf_printf(test, report_sender_not_available_summary_format, "SUM");
}
else {
Expand All @@ -3056,7 +3071,7 @@ iperf_print_results(struct iperf_test *test)
cJSON_AddItemToObject(test->json_end, "sum_received", iperf_json_printf("start: %f end: %f seconds: %f bytes: %d bits_per_second: %f", (double) start_time, (double) receiver_time, (double) receiver_time, (int64_t) total_received, bandwidth * 8));
else
if (test->role == 's' && test->sender) {
if (test->verbose)
if (test->verbose)
iperf_printf(test, report_receiver_not_available_summary_format, "SUM");
}
else {
Expand Down Expand Up @@ -3163,8 +3178,8 @@ iperf_print_results(struct iperf_test *test)

/**
* Main report-printing callback.
* Prints results either during a test (interval report only) or
* after the entire test has been run (last interval report plus
* Prints results either during a test (interval report only) or
* after the entire test has been run (last interval report plus
* overall summary).
*/
void
Expand All @@ -3181,7 +3196,7 @@ iperf_reporter_callback(struct iperf_test *test)
iperf_print_intermediate(test);
iperf_print_results(test);
break;
}
}

}

Expand Down Expand Up @@ -3237,10 +3252,10 @@ print_interval_results(struct iperf_test *test, struct iperf_stream *sp, cJSON *
bandwidth = 0.0;
}
unit_snprintf(nbuf, UNIT_LEN, bandwidth, test->settings->unit_format);

st = timeval_diff(&sp->result->start_time, &irp->interval_start_time);
et = timeval_diff(&sp->result->start_time, &irp->interval_end_time);

if (test->protocol->id == Ptcp || test->protocol->id == Psctp) {
if (test->sender_has_retransmits == 1) {
/* Interval, TCP with retransmits. */
Expand Down Expand Up @@ -3347,7 +3362,7 @@ iperf_new_stream(struct iperf_test *test, int s)

memset(sp->result, 0, sizeof(struct iperf_stream_result));
TAILQ_INIT(&sp->result->interval_results);

/* Create and randomize the buffer */
sp->buffer_fd = mkstemp(template);
if (sp->buffer_fd == -1) {
Expand Down Expand Up @@ -3619,10 +3634,10 @@ iperf_create_pidfile(struct iperf_test *test)
}
}
}

/*
* File didn't exist, we couldn't read it, or it didn't correspond to
* a running process. Try to create it.
* File didn't exist, we couldn't read it, or it didn't correspond to
* a running process. Try to create it.
*/
fd = open(test->pidfile, O_WRONLY | O_CREAT | O_TRUNC, S_IRUSR|S_IWUSR);
if (fd < 0) {
Expand Down