2009-10-25 01:15:04 +04:00
|
|
|
/*
|
2014-09-30 01:00:46 +04:00
|
|
|
* iperf, Copyright (c) 2014, The Regents of the University of
|
|
|
|
* California, through Lawrence Berkeley National Laboratory (subject
|
|
|
|
* to receipt of any required approvals from the U.S. Dept. of
|
|
|
|
* Energy). All rights reserved.
|
2011-04-21 00:33:09 +04:00
|
|
|
*
|
2014-09-30 01:00:46 +04:00
|
|
|
* If you have questions about your rights to use or distribute this
|
|
|
|
* software, please contact Berkeley Lab's Technology Transfer
|
|
|
|
* Department at TTD@lbl.gov.
|
|
|
|
*
|
|
|
|
* NOTICE. This software is owned by the U.S. Department of Energy.
|
|
|
|
* As such, the U.S. Government has been granted for itself and others
|
|
|
|
* acting on its behalf a paid-up, nonexclusive, irrevocable,
|
|
|
|
* worldwide license in the Software to reproduce, prepare derivative
|
|
|
|
* works, and perform publicly and display publicly. Beginning five
|
|
|
|
* (5) years after the date permission to assert copyright is obtained
|
|
|
|
* from the U.S. Department of Energy, and subject to any subsequent
|
|
|
|
* five (5) year renewals, the U.S. Government is granted for itself
|
|
|
|
* and others acting on its behalf a paid-up, nonexclusive,
|
|
|
|
* irrevocable, worldwide license in the Software to reproduce,
|
|
|
|
* prepare derivative works, distribute copies to the public, perform
|
|
|
|
* publicly and display publicly, and to permit others to do so.
|
|
|
|
*
|
|
|
|
* This code is distributed under a BSD style license, see the LICENSE
|
|
|
|
* file for complete information.
|
2009-10-25 01:15:04 +04:00
|
|
|
*/
|
2014-04-15 00:33:33 +04:00
|
|
|
#include "iperf_config.h"
|
2009-10-25 01:15:04 +04:00
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <getopt.h>
|
|
|
|
#include <errno.h>
|
|
|
|
#include <signal.h>
|
|
|
|
#include <unistd.h>
|
2014-05-19 21:15:36 +04:00
|
|
|
#ifdef HAVE_STDINT_H
|
2009-10-25 01:15:04 +04:00
|
|
|
#include <stdint.h>
|
2014-05-19 21:15:36 +04:00
|
|
|
#endif
|
2009-10-25 01:15:04 +04:00
|
|
|
#include <sys/socket.h>
|
|
|
|
#include <sys/types.h>
|
|
|
|
#include <netinet/in.h>
|
|
|
|
#include <arpa/inet.h>
|
|
|
|
#include <netdb.h>
|
2014-05-19 21:15:36 +04:00
|
|
|
#ifdef HAVE_STDINT_H
|
2009-10-25 01:15:04 +04:00
|
|
|
#include <stdint.h>
|
2014-05-19 21:15:36 +04:00
|
|
|
#endif
|
2009-10-25 01:15:04 +04:00
|
|
|
#include <netinet/tcp.h>
|
|
|
|
|
2009-11-03 01:43:19 +03:00
|
|
|
#include "iperf.h"
|
2009-10-25 01:15:04 +04:00
|
|
|
#include "iperf_api.h"
|
|
|
|
#include "units.h"
|
2014-09-15 21:42:36 +04:00
|
|
|
#include "iperf_locale.h"
|
2010-07-29 23:18:29 +04:00
|
|
|
#include "net.h"
|
2009-10-25 01:15:04 +04:00
|
|
|
|
2010-06-15 03:49:41 +04:00
|
|
|
|
2013-10-30 02:03:17 +04:00
|
|
|
static int run(struct iperf_test *test);
|
2009-10-25 01:15:04 +04:00
|
|
|
|
|
|
|
|
2013-10-30 02:03:17 +04:00
|
|
|
/**************************************************************************/
|
2009-10-25 01:15:04 +04:00
|
|
|
int
|
|
|
|
main(int argc, char **argv)
|
|
|
|
{
|
|
|
|
struct iperf_test *test;
|
2010-06-15 03:49:41 +04:00
|
|
|
|
2010-07-19 23:45:08 +04:00
|
|
|
// XXX: Setting the process affinity requires root on most systems.
|
|
|
|
// Is this a feature we really need?
|
2009-10-25 01:15:04 +04:00
|
|
|
#ifdef TEST_PROC_AFFINITY
|
|
|
|
/* didnt seem to work.... */
|
|
|
|
/*
|
|
|
|
* increasing the priority of the process to minimise packet generation
|
|
|
|
* delay
|
|
|
|
*/
|
2010-06-17 00:32:01 +04:00
|
|
|
int rc = setpriority(PRIO_PROCESS, 0, -15);
|
2009-10-25 01:15:04 +04:00
|
|
|
|
2010-06-17 00:32:01 +04:00
|
|
|
if (rc < 0) {
|
|
|
|
perror("setpriority:");
|
2013-02-01 23:42:35 +04:00
|
|
|
fprintf(stderr, "setting priority to valid level\n");
|
2010-06-17 00:32:01 +04:00
|
|
|
rc = setpriority(PRIO_PROCESS, 0, 0);
|
2009-10-25 01:15:04 +04:00
|
|
|
}
|
2010-06-17 00:32:01 +04:00
|
|
|
|
2009-10-25 01:15:04 +04:00
|
|
|
/* setting the affinity of the process */
|
|
|
|
cpu_set_t cpu_set;
|
2010-06-17 00:32:01 +04:00
|
|
|
int affinity = -1;
|
|
|
|
int ncores = 1;
|
2009-10-25 01:15:04 +04:00
|
|
|
|
|
|
|
sched_getaffinity(0, sizeof(cpu_set_t), &cpu_set);
|
|
|
|
if (errno)
|
2010-06-17 00:32:01 +04:00
|
|
|
perror("couldn't get affinity:");
|
2009-10-25 01:15:04 +04:00
|
|
|
|
|
|
|
if ((ncores = sysconf(_SC_NPROCESSORS_CONF)) <= 0)
|
2010-06-17 00:32:01 +04:00
|
|
|
err("sysconf: couldn't get _SC_NPROCESSORS_CONF");
|
2009-10-25 01:15:04 +04:00
|
|
|
|
|
|
|
CPU_ZERO(&cpu_set);
|
|
|
|
CPU_SET(affinity, &cpu_set);
|
|
|
|
if (sched_setaffinity(0, sizeof(cpu_set_t), &cpu_set) != 0)
|
2010-06-17 00:32:01 +04:00
|
|
|
err("couldn't change CPU affinity");
|
2009-10-25 01:15:04 +04:00
|
|
|
#endif
|
|
|
|
|
|
|
|
test = iperf_new_test();
|
2013-02-08 00:35:17 +04:00
|
|
|
if (!test)
|
|
|
|
iperf_errexit(NULL, "create new test error - %s", iperf_strerror(i_errno));
|
2009-10-25 01:15:04 +04:00
|
|
|
iperf_defaults(test); /* sets defaults */
|
|
|
|
|
2010-07-19 23:45:08 +04:00
|
|
|
if (iperf_parse_arguments(test, argc, argv) < 0) {
|
2013-02-08 00:35:17 +04:00
|
|
|
iperf_err(test, "parameter error - %s", iperf_strerror(i_errno));
|
2010-07-19 23:45:08 +04:00
|
|
|
fprintf(stderr, "\n");
|
|
|
|
usage_long();
|
|
|
|
exit(1);
|
2009-10-25 01:15:04 +04:00
|
|
|
}
|
|
|
|
|
2013-10-30 02:03:17 +04:00
|
|
|
if (run(test) < 0)
|
2013-02-08 00:35:17 +04:00
|
|
|
iperf_errexit(test, "error - %s", iperf_strerror(i_errno));
|
2010-06-23 23:13:37 +04:00
|
|
|
|
2009-10-25 01:15:04 +04:00
|
|
|
iperf_free_test(test);
|
|
|
|
|
2012-12-12 10:29:26 +04:00
|
|
|
return 0;
|
2009-10-25 01:15:04 +04:00
|
|
|
}
|
2009-11-03 01:43:19 +03:00
|
|
|
|
|
|
|
/**************************************************************************/
|
2013-10-30 02:03:17 +04:00
|
|
|
static int
|
|
|
|
run(struct iperf_test *test)
|
2009-11-03 01:43:19 +03:00
|
|
|
{
|
2013-06-08 02:28:05 +04:00
|
|
|
int consecutive_errors;
|
|
|
|
|
2010-06-16 02:26:12 +04:00
|
|
|
switch (test->role) {
|
|
|
|
case 's':
|
2013-11-27 03:40:19 +04:00
|
|
|
if (test->daemon) {
|
|
|
|
int rc = daemon(0, 0);
|
|
|
|
if (rc < 0) {
|
|
|
|
i_errno = IEDAEMON;
|
|
|
|
iperf_errexit(test, "error - %s", iperf_strerror(i_errno));
|
|
|
|
}
|
|
|
|
}
|
2013-06-08 02:28:05 +04:00
|
|
|
consecutive_errors = 0;
|
2014-01-25 04:42:10 +04:00
|
|
|
if (iperf_create_pidfile(test) < 0) {
|
|
|
|
i_errno = IEPIDFILE;
|
|
|
|
iperf_errexit(test, "error - %s", iperf_strerror(i_errno));
|
|
|
|
}
|
2010-08-03 02:45:53 +04:00
|
|
|
for (;;) {
|
2014-04-08 01:12:47 +04:00
|
|
|
if (iperf_run_server(test) < 0) {
|
2013-02-08 00:35:17 +04:00
|
|
|
iperf_err(test, "error - %s", iperf_strerror(i_errno));
|
2013-02-01 23:42:35 +04:00
|
|
|
fprintf(stderr, "\n");
|
2013-06-08 02:28:05 +04:00
|
|
|
++consecutive_errors;
|
|
|
|
if (consecutive_errors >= 5) {
|
2014-01-03 23:24:06 +04:00
|
|
|
fprintf(stderr, "too many errors, exiting\n");
|
2013-06-08 02:28:05 +04:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
} else
|
|
|
|
consecutive_errors = 0;
|
2010-08-03 02:45:53 +04:00
|
|
|
iperf_reset_test(test);
|
|
|
|
}
|
2014-01-25 04:42:10 +04:00
|
|
|
iperf_delete_pidfile(test);
|
2010-08-03 02:45:53 +04:00
|
|
|
break;
|
2014-04-08 01:12:47 +04:00
|
|
|
case 'c':
|
|
|
|
if (iperf_run_client(test) < 0)
|
2013-02-08 00:35:17 +04:00
|
|
|
iperf_errexit(test, "error - %s", iperf_strerror(i_errno));
|
2010-08-03 02:45:53 +04:00
|
|
|
break;
|
2010-06-16 02:26:12 +04:00
|
|
|
default:
|
2010-06-25 04:31:15 +04:00
|
|
|
usage();
|
2010-08-03 02:45:53 +04:00
|
|
|
break;
|
2009-11-03 01:43:19 +03:00
|
|
|
}
|
2010-08-03 02:45:53 +04:00
|
|
|
|
2012-12-12 10:29:26 +04:00
|
|
|
return 0;
|
2009-11-03 01:43:19 +03:00
|
|
|
}
|