blob: c05a42635bb6e4b9d56a6d60ce83af20dfb1c196 [file] [log] [blame]
/*
* Copyright (c) 2009, 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.
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <getopt.h>
#include <errno.h>
#include <signal.h>
#include <unistd.h>
#include <stdint.h>
#include <sys/queue.h>
#include <sys/socket.h>
#include <sys/types.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <netdb.h>
#include <stdint.h>
#include <netinet/tcp.h>
#include "iperf.h"
#include "iperf_api.h"
#include "iperf_client_api.h"
#include "iperf_server_api.h"
#include "units.h"
#include "locale.h"
#include "iperf_error.h"
int iperf_run(struct iperf_test *);
/**************************************************************************/
int
main(int argc, char **argv)
{
struct iperf_test *test;
// XXX: Setting the process affinity requires root on most systems.
// Is this a feature we really need?
#ifdef TEST_PROC_AFFINITY
/* didnt seem to work.... */
/*
* increasing the priority of the process to minimise packet generation
* delay
*/
int rc = setpriority(PRIO_PROCESS, 0, -15);
if (rc < 0) {
perror("setpriority:");
printf("setting priority to valid level\n");
rc = setpriority(PRIO_PROCESS, 0, 0);
}
/* setting the affinity of the process */
cpu_set_t cpu_set;
int affinity = -1;
int ncores = 1;
sched_getaffinity(0, sizeof(cpu_set_t), &cpu_set);
if (errno)
perror("couldn't get affinity:");
if ((ncores = sysconf(_SC_NPROCESSORS_CONF)) <= 0)
err("sysconf: couldn't get _SC_NPROCESSORS_CONF");
CPU_ZERO(&cpu_set);
CPU_SET(affinity, &cpu_set);
if (sched_setaffinity(0, sizeof(cpu_set_t), &cpu_set) != 0)
err("couldn't change CPU affinity");
#endif
test = iperf_new_test();
if (!test) {
iperf_error("create new test error");
exit(1);
}
iperf_defaults(test); /* sets defaults */
if (iperf_parse_arguments(test, argc, argv) < 0) {
iperf_error("parameter error");
fprintf(stderr, "\n");
usage_long();
exit(1);
}
if (iperf_run(test) < 0) {
iperf_error("error");
exit(1);
}
iperf_free_test(test);
printf("\niperf Done.\n");
return 0;
}
/**************************************************************************/
int
iperf_run(struct iperf_test * test)
{
switch (test->role) {
case 's':
return iperf_run_server(test);
case 'c':
return iperf_run_client(test);
default:
usage();
return 0;
}
}