Skip to content
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
1 change: 1 addition & 0 deletions src/iperf.h
Original file line number Diff line number Diff line change
Expand Up @@ -312,6 +312,7 @@ struct iperf_test
int server_port;
int omit; /* duration of omit period (-O flag) */
int duration; /* total duration of test (-t flag) */
int max_server_duration; /* maximum possible duration of test as enforced by the server (--max-server-duration flag) */
char *diskfile_name; /* -F option */
int affinity, server_affinity; /* -A option */
#if defined(HAVE_CPUSET_SETAFFINITY)
Expand Down
5 changes: 5 additions & 0 deletions src/iperf3.1
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,11 @@ Restart the server after \fIn\fR seconds in case it gets stuck.
In one-off mode, this is the number of seconds the server will wait
before exiting.
.TP
.BR --server-max-duration " "
The maximum time, in seconds, that an iperf client can run against the server.
When the sum of the client's time and omit values exceeds the max duration set by the server
or the client's time value is 0, the measurement is rejected.
.TP
.BR --server-bitrate-limit " \fIn\fR[KMGT][/\fCn\fR]"
Set a limit on the server side, which will cause a test to abort if
the client specifies a test of more than \fIn\fR bits per second, or
Expand Down
18 changes: 17 additions & 1 deletion src/iperf_api.c
Original file line number Diff line number Diff line change
Expand Up @@ -1114,7 +1114,8 @@ iperf_parse_arguments(struct iperf_test *test, int argc, char **argv)
{"udp", no_argument, NULL, 'u'},
{"bitrate", required_argument, NULL, 'b'},
{"bandwidth", required_argument, NULL, 'b'},
{"server-bitrate-limit", required_argument, NULL, OPT_SERVER_BITRATE_LIMIT},
{"server-bitrate-limit", required_argument, NULL, OPT_SERVER_BITRATE_LIMIT},
{"server-max-duration", required_argument, NULL, OPT_SERVER_MAX_DURATION},
{"time", required_argument, NULL, 't'},
{"bytes", required_argument, NULL, 'n'},
{"blockcount", required_argument, NULL, 'k'},
Expand Down Expand Up @@ -1555,6 +1556,14 @@ iperf_parse_arguments(struct iperf_test *test, int argc, char **argv)
}
server_flag = 1;
break;
case OPT_SERVER_MAX_DURATION:
test->max_server_duration = atoi(optarg);
if (test->max_server_duration < 0 || test->max_server_duration > MAX_TIME) {
i_errno = IEDURATION;
return -1;
}
server_flag = 1;
break;
case OPT_RCV_TIMEOUT:
rcv_timeout_in = atoi(optarg);
if (rcv_timeout_in < MIN_NO_MSG_RCVD_TIMEOUT || rcv_timeout_in > MAX_TIME * SEC_TO_mS) {
Expand Down Expand Up @@ -2576,6 +2585,13 @@ get_parameters(struct iperf_test *test)
if (test->settings->rate)
cJSON_AddNumberToObject(test->json_start, "target_bitrate", test->settings->rate);
cJSON_Delete(j);

/* Ensure that the client does not request to run longer than the server's configured max */
if ((test->max_server_duration > 0) && (((test->duration + test->omit) > test->max_server_duration) || (test->duration == 0))) {
i_errno = IEMAXSERVERTESTDURATIONEXCEEDED;
r = -1;
}

}
return r;
}
Expand Down
2 changes: 2 additions & 0 deletions src/iperf_api.h
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ typedef atomic_uint_fast64_t atomic_iperf_size_t;
#define OPT_CNTL_KA 31
#define OPT_SKIP_RX_COPY 32
#define OPT_JSON_STREAM_FULL_OUTPUT 33
#define OPT_SERVER_MAX_DURATION 34

/* states */
#define TEST_START 1
Expand Down Expand Up @@ -440,6 +441,7 @@ enum {
IEUDPFILETRANSFER = 34, // Cannot transfer file using UDP
IESERVERAUTHUSERS = 35, // Cannot access authorized users file
IECNTLKA = 36, // Control connection Keepalive period should be larger than the full retry period (interval * count)
IEMAXSERVERTESTDURATIONEXCEEDED = 37, // Client's duration exceeds server's maximum duration
/* Test errors */
IENEWTEST = 100, // Unable to create a new test (check perror)
IEINITTEST = 101, // Test initialization failed (check perror)
Expand Down
3 changes: 3 additions & 0 deletions src/iperf_error.c
Original file line number Diff line number Diff line change
Expand Up @@ -551,6 +551,9 @@ iperf_strerror(int int_errno)
snprintf(errstr, len, "unable to set/get socket keepalive TCP number of retries (TCP_KEEPCNT) option");
perr = 1;
break;
case IEMAXSERVERTESTDURATIONEXCEEDED:
snprintf(errstr, len, "client's requested duration exceeds the server's maximum permitted limit");
break;
default:
snprintf(errstr, len, "int_errno=%d", int_errno);
perr = 1;
Expand Down
1 change: 1 addition & 0 deletions src/iperf_locale.c
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,7 @@ const char usage_longstr[] = "Usage: iperf3 [-s|-c host] [options]\n"
" total data rate. Default is 5 seconds)\n"
" --idle-timeout # restart idle server after # seconds in case it\n"
" got stuck (default - no timeout)\n"
" --server-max-duration # max time, in seconds, that an iperf test can run against the server\n"
#if defined(HAVE_SSL)
" --rsa-private-key-path path to the RSA private key used to decrypt\n"
" authentication credentials\n"
Expand Down