Skip to content

Commit

Permalink
Added iperf error code (iperf_error.*). Also added iperf_parse_parame…
Browse files Browse the repository at this point in the history
…ters().
  • Loading branch information
sethdelliott committed Jul 19, 2010
1 parent 7585c69 commit 8430ad4
Show file tree
Hide file tree
Showing 7 changed files with 285 additions and 156 deletions.
2 changes: 1 addition & 1 deletion src/Makefile.old
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
CFLAGS=-g -Wall
OBJS=main.o iperf_api.o iperf_server_api.o iperf_tcp.o iperf_udp.o timer.o net.o tcp_window_size.o units.o iperf_util.o tcp_info.o locale.o
OBJS=main.o iperf_api.o iperf_server_api.o iperf_tcp.o iperf_udp.o timer.o net.o tcp_window_size.o units.o iperf_util.o tcp_info.o locale.o iperf_error.o
LDFLAGS=

UNAME=$(shell uname)
Expand Down
6 changes: 4 additions & 2 deletions src/iperf.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,12 @@
approvals from the U.S. Dept. of Energy). All rights reserved.
*/

#ifndef __IPERF_H
#define __IPERF_H
#ifndef __IPERF_H
#define __IPERF_H

#include <sys/time.h>
#include <sys/types.h>
#include <stdint.h>
#include <sys/socket.h>
#include <netinet/tcp.h>

Expand Down
204 changes: 204 additions & 0 deletions src/iperf_api.c
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
#include "iperf_api.h"
#include "iperf_udp.h"
#include "iperf_tcp.h"
#include "iperf_error.h"
#include "timer.h"
#include "net.h"
#include "units.h"
Expand All @@ -56,6 +57,209 @@ usage_long()
fprintf(stderr, usage_long2);
}

int
iperf_parse_arguments(struct iperf_test *test, int argc, char **argv)
{
static struct option longopts[] =
{
{"client", required_argument, NULL, 'c'},
{"server", no_argument, NULL, 's'},
{"time", required_argument, NULL, 't'},
{"port", required_argument, NULL, 'p'},
{"parallel", required_argument, NULL, 'P'},
{"udp", no_argument, NULL, 'u'},
{"tcpInfo", no_argument, NULL, 'T'},
{"bandwidth", required_argument, NULL, 'b'},
{"length", required_argument, NULL, 'l'},
{"window", required_argument, NULL, 'w'},
{"interval", required_argument, NULL, 'i'},
{"bytes", required_argument, NULL, 'n'},
{"NoDelay", no_argument, NULL, 'N'},
{"Print-mss", no_argument, NULL, 'm'},
{"Set-mss", required_argument, NULL, 'M'},
{"version", no_argument, NULL, 'v'},
{"verbose", no_argument, NULL, 'V'},
{"debug", no_argument, NULL, 'd'},
{"help", no_argument, NULL, 'h'},
{"daemon", no_argument, NULL, 'D'},
{"format", required_argument, NULL, 'f'},
{"reverse", no_argument, NULL, 'R'},

/* XXX: The following ifdef needs to be split up. linux-congestion is not necessarily supported
* by systems that support tos.
*/
#ifdef ADD_WHEN_SUPPORTED
{"tos", required_argument, NULL, 'S'},
{"linux-congestion", required_argument, NULL, 'Z'},
#endif
{NULL, 0, NULL, 0}
};
char ch;

while ((ch = getopt_long(argc, argv, "c:p:st:uP:b:l:w:i:n:mRNTvhVdM:f:", longopts, NULL)) != -1) {
switch (ch) {
case 'c':
if (test->role == 's') {
ierrno = IESERVCLIENT;
return (-1);
} else {
test->role = 'c';
test->server_hostname = (char *) malloc(strlen(optarg)+1);
strncpy(test->server_hostname, optarg, strlen(optarg));
}
break;
case 'p':
test->server_port = atoi(optarg);
break;
case 's':
if (test->role == 'c') {
ierrno = IESERVCLIENT;
return (-1);
} else {
test->role = 's';
}
break;
case 't':
if (test->role == 's') {
ierrno = IECLIENTONLY;
return (-1);
}
test->duration = atoi(optarg);
if (test->duration > MAX_TIME) {
ierrno = IEDURATION;
return (-1);
}
break;
case 'u':
if (test->role == 's') {
ierrno = IECLIENTONLY;
return (-1);
}
test->protocol = Pudp;
test->default_settings->blksize = DEFAULT_UDP_BLKSIZE;
test->new_stream = iperf_new_udp_stream;
break;
case 'P':
if (test->role == 's') {
ierrno = IECLIENTONLY;
return (-1);
}
test->num_streams = atoi(optarg);
if (test->num_streams > MAX_STREAMS) {
ierrno = IENUMSTREAMS;
return (-1);
}
break;
case 'b':
if (test->role == 's') {
ierrno = IECLIENTONLY;
return (-1);
}
test->default_settings->rate = unit_atof(optarg);
break;
case 'l':
if (test->role == 's') {
ierrno = IECLIENTONLY;
return (-1);
}
test->default_settings->blksize = unit_atoi(optarg);
if (test->default_settings->blksize > MAX_BLOCKSIZE) {
ierrno = IEBLOCKSIZE;
return (-1);
}
break;
case 'w':
// XXX: This is a socket buffer, not specific to TCP
if (test->role == 's') {
ierrno = IECLIENTONLY;
return (-1);
}
test->default_settings->socket_bufsize = unit_atof(optarg);
if (test->default_settings->socket_bufsize > MAX_TCP_BUFFER) {
ierrno = IEBUFSIZE;
return (-1);
}
break;
case 'i':
/* XXX: could potentially want separate stat collection and reporting intervals,
but just set them to be the same for now */
test->stats_interval = atoi(optarg);
test->reporter_interval = atoi(optarg);
if (test->stats_interval > MAX_INTERVAL) {
ierrno = IEINTERVAL;
return (-1);
}
break;
case 'n':
if (test->role == 's') {
ierrno = IECLIENTONLY;
return (-1);
}
test->default_settings->bytes = unit_atoi(optarg);
break;
case 'm':
test->print_mss = 1;
break;
case 'N':
if (test->role == 's') {
ierrno = IECLIENTONLY;
return (-1);
}
test->no_delay = 1;
break;
case 'M':
if (test->role == 's') {
ierrno = IECLIENTONLY;
return (-1);
}
test->default_settings->mss = atoi(optarg);
if (test->default_settings->mss > MAX_MSS) {
ierrno = IEMSS;
return (-1);
}
break;
case 'f':
test->default_settings->unit_format = *optarg;
break;
case 'T':
test->tcp_info = 1;
break;
case 'V':
test->verbose = 1;
break;
case 'd':
test->debug = 1;
break;
case 'R':
if (test->role == 's') {
ierrno = IECLIENTONLY;
return (-1);
}
test->reverse = 1;
break;
case 'v':
printf(version);
exit(0);
case 'h':
default:
usage_long();
exit(1);
}
}
/* For subsequent calls to getopt */
#ifdef __APPLE__
optreset = 1;
#endif
optind = 0;

if ((test->role != 'c') && (test->role != 's')) {
ierrno = IENOROLE;
return (-1);
}

return (0);
}

int
all_data_sent(struct iperf_test * test)
{
Expand Down
1 change: 1 addition & 0 deletions src/iperf_api.h
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@ int iperf_handle_message_client(struct iperf_test *);
int iperf_exchange_results(struct iperf_test *);
int parse_results(struct iperf_test *, char *);
void iperf_init_test(struct iperf_test *);
int iperf_parse_arguments(struct iperf_test *, int, char **);

#endif

41 changes: 41 additions & 0 deletions src/iperf_error.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
#include <stdio.h>
#include "iperf.h"
#include "iperf_error.h"

int ierrno;

void
ierror(char *estr)
{
fprintf(stderr, "%s: ", estr);

switch (ierrno) {
case IESERVCLIENT:
fprintf(stderr, "iperf cannot be both server and client\n");
break;
case IENOROLE:
fprintf(stderr, "iperf instance must either be a client (-c) or server (-s)\n");
break;
case IECLIENTONLY:
fprintf(stderr, "some option you are trying to set is client only\n");
break;
case IEDURATION:
fprintf(stderr, "test duration too long (maximum = %d seconds)\n", MAX_TIME);
break;
case IENUMSTREAMS:
fprintf(stderr, "number of parallel streams too large (maximum = %d)\n", MAX_STREAMS);
break;
case IEBLOCKSIZE:
fprintf(stderr, "block size too large (maximum = %d bytes)\n", MAX_BLOCKSIZE);
break;
case IEBUFSIZE:
fprintf(stderr, "socket buffer size too large (maximum = %d bytes)\n", MAX_TCP_BUFFER);
break;
case IEINTERVAL:
fprintf(stderr, "report interval too large (maximum = %d seconds)\n", MAX_INTERVAL);
break;
case IEMSS:
fprintf(stderr, "TCP MSS too large (maximum = %d bytes)\n", MAX_MSS);
break;
}
}
25 changes: 25 additions & 0 deletions src/iperf_error.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/* iperf_error.h
*
* Iperf error handling
*/

#ifndef __IPERF_ERROR_H
#define __IPERF_ERROR_H

void ierror(char *);

extern int ierrno;

enum {
IESERVCLIENT = 1, // Iperf cannot be both server and client
IENOROLE = 2, // Iperf must either be a client (-c) or server (-s)
IECLIENTONLY = 3, // This option is client only
IEDURATION = 4, // test duration too long. Maximum value = %dMAX_TIME
IENUMSTREAMS = 5, // Number of parallel streams too large. Maximum value = %dMAX_STREAMS
IEBLOCKSIZE = 6, // Block size too large. Maximum value = %dMAX_BLOCKSIZE
IEBUFSIZE = 7, // Socket buffer size too large. Maximum value = %dMAX_TCP_BUFFER
IEINTERVAL = 8, // Report interval too large. Maxumum value = %dMAX_INTERVAL
IEMSS = 9, // MSS too large. Maximum value = %dMAX_MSS
};

#endif
Loading

0 comments on commit 8430ad4

Please sign in to comment.