commit 2e390fcec6c9ee3bb43902bbd6566608d4fe3677
Author: Radek Pazdera <rpazdera(a)redhat.com>
Date: Fri May 25 18:01:54 2012 +0200
multicast: Moved IGMP parameters to separate file
The original parameters.h was getting too heavy, there
was more macros than code. The file was split it into
* parameters_igmp.h
* parameters_multicast.h
Also some code cleanup was done.
Signed-off-by: Radek Pazdera <rpazdera(a)redhat.com>
test_tools/multicast/igmp_utils.h | 2 +-
test_tools/multicast/multicast_utils.h | 2 +-
test_tools/multicast/parameters_igmp.h | 154 +++++++++++++++
.../{parameters.h => parameters_multicast.h} | 205 ++++++--------------
4 files changed, 211 insertions(+), 152 deletions(-)
---
diff --git a/test_tools/multicast/igmp_utils.h b/test_tools/multicast/igmp_utils.h
index 901d01f..125232b 100644
--- a/test_tools/multicast/igmp_utils.h
+++ b/test_tools/multicast/igmp_utils.h
@@ -43,7 +43,7 @@
#include <linux/igmp.h>
#define IGMP
-#include "parameters.h"
+#include "parameters_igmp.h"
int __verbosity = 0;
diff --git a/test_tools/multicast/multicast_utils.h b/test_tools/multicast/multicast_utils.h
index 25d0c38..70fcf59 100644
--- a/test_tools/multicast/multicast_utils.h
+++ b/test_tools/multicast/multicast_utils.h
@@ -43,7 +43,7 @@
#error "At least one of SEND/RECEIVE macros must be defined!"
#endif
-#include "parameters.h"
+#include "parameters_multicast.h"
#define MESSAGE "Hello world!"
diff --git a/test_tools/multicast/parameters_igmp.h b/test_tools/multicast/parameters_igmp.h
new file mode 100644
index 0000000..31a9c87
--- /dev/null
+++ b/test_tools/multicast/parameters_igmp.h
@@ -0,0 +1,154 @@
+/*
+ * parameters_igmp.h - common code for parsing sender/receiver parameters
+ * Copyright (C) 2012 Red Hat Inc.
+ *
+ * Author: Radek Pazdera (rpazdera(a)redhat.com)
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ * 02110-1301, USA.
+ */
+
+#ifndef __PARAMETERS_IGMP_H__
+#define __PARAMETERS_IGMP_H__
+
+#include <stdio.h>
+#include <string.h>
+#include <errno.h>
+
+#include <netinet/in.h>
+#include <sys/types.h>
+#include <sys/socket.h>
+
+#include <signal.h>
+#include <time.h>
+
+#include <getopt.h>
+#include <stdlib.h>
+#include <unistd.h>
+
+extern int __verbosity;
+
+enum __igmp_query_types {
+ IGMP_GENERAL_QUERY = 1,
+ IGMP_GROUP_SPECIFIC_QUERY = 2,
+ IGMP_GROUP_AND_SOURCE_SPECIFIC_QUERY = 3
+};
+
+/** Structure that carries test parameters */
+struct parameters
+{
+ struct in_addr multiaddr;
+ struct in_addr interface;
+
+ short query_type;
+ struct in_addr sourceaddr;
+ struct in_addr destaddr;
+ int max_resp_time;
+};
+
+/** Initialize parameters struct with default values. */
+void default_parameters(struct parameters* params)
+{
+ memset(¶ms->multiaddr, 0, sizeof(struct in_addr));
+ memset(¶ms->interface, 0, sizeof(struct in_addr));
+
+ params->query_type = IGMP_GENERAL_QUERY;
+ memset(¶ms->sourceaddr, 0, sizeof(struct in_addr));
+ memset(¶ms->destaddr, 0, sizeof(struct in_addr));
+ params->max_resp_time = 0;
+}
+
+void usage(char *program_name, int retval)
+{
+ printf("usage: %s\n", program_name);
+ printf(" -h | --help print this\n");
+ printf(" -v | --verbose print additional information during the runtime\n");
+ printf(" -i | --interface a.b.c.d local interface to use for communication\n");
+
+ printf("\n");
+
+ printf(" -a | --multicast_address a.b.c.d multicast group address (v2 and v3 only)\n");
+ printf(" -s | --source_address a.b.c.d multicast source (v3 only)\n");
+ printf(" -d | --dest_address a.b.c.d destination address of the IP packet\n");
+
+ printf("\n");
+
+ printf(" -q | --query_type query type [1,2,3]\n");
+ printf(" -r | --max_resp_time x maximum response time\n");
+ exit(retval);
+}
+
+/** Generic function for parsing arguments */
+void parse_args(int argc, char** argv, struct parameters* args)
+{
+ int dest_was_set = 0;
+
+ static const char* opts = "i:a:q:s:d:r:hv";
+ static struct option long_options[] =
+ {
+ {"interface", required_argument, NULL, 'i'},
+ {"multicast_address", required_argument, NULL, 'a'},
+ {"query_type", required_argument, NULL, 'q'},
+ {"source_address", required_argument, NULL, 's'},
+ {"dest_address", required_argument, NULL, 'd'},
+ {"max_resp_time", required_argument, NULL, 'r'},
+ {"help", no_argument, NULL, 'h'},
+ {"verbose", no_argument, NULL, 'v'},
+ {0, 0, NULL, 0}
+ };
+
+ default_parameters(args);
+
+ int opt;
+ int option_index = 0;
+ while((opt = getopt_long(argc, argv, opts, long_options,
+ &option_index)) != -1) {
+ switch (opt) {
+ case 'i':
+ inet_pton(AF_INET, optarg, &(args->interface));
+ break;
+ case 'a':
+ inet_pton(AF_INET, optarg, &(args->multiaddr));
+ break;
+ case 'q':
+ args->query_type = atoi(optarg);
+ break;
+ case 's':
+ inet_pton(AF_INET, optarg, &(args->sourceaddr));
+ break;
+ case 'd':
+ inet_pton(AF_INET, optarg, &(args->destaddr));
+ dest_was_set = 1;
+ break;
+ case 'r':
+ args->max_resp_time = atoi(optarg);
+ break;
+ case 'h':
+ usage(argv[0], EXIT_SUCCESS);
+ break;
+ case 'v':
+ __verbosity = 1;
+ break;
+ default: /* '?' */
+ fprintf(stderr, "%s: invalid options\n", argv[0]);
+ usage(argv[0], EXIT_FAILURE);
+ }
+ }
+
+ if (!dest_was_set)
+ args->destaddr = args->multiaddr;
+}
+
+#endif
diff --git a/test_tools/multicast/parameters.h b/test_tools/multicast/parameters_multicast.h
similarity index 51%
rename from test_tools/multicast/parameters.h
rename to test_tools/multicast/parameters_multicast.h
index a9fda9d..ecaaf79 100644
--- a/test_tools/multicast/parameters.h
+++ b/test_tools/multicast/parameters_multicast.h
@@ -1,5 +1,6 @@
/*
- * parameters.h - common code for parsing sender/receiver parameters
+ * parameters_multicast.h - common code for parsing sender/receiver
+ * parameters
* Copyright (C) 2012 Red Hat Inc.
*
* Author: Radek Pazdera (rpazdera(a)redhat.com)
@@ -20,8 +21,8 @@
* 02110-1301, USA.
*/
-#ifndef __PARAMETERS_H__
-#define __PARAMETERS_H__
+#ifndef __PARAMETERS_MULTICAST_H__
+#define __PARAMETERS_MULTICAST_H__
#include <stdio.h>
#include <string.h>
@@ -40,24 +41,16 @@
extern int __verbosity;
-#ifdef IGMP
-enum __igmp_query_types {
- IGMP_GENERAL_QUERY = 1,
- IGMP_GROUP_SPECIFIC_QUERY = 2,
- IGMP_GROUP_AND_SOURCE_SPECIFIC_QUERY = 3
-};
-#endif
-
/** Structure that carries test parameters */
struct parameters
{
- int duration; /* seconds */
-
struct in_addr multiaddr;
- short port;
struct in_addr interface;
-#if defined(RECEIVE) || defined(IGMP)
+ int duration; /* seconds */
+ short port;
+
+#ifdef RECEIVE
struct in_addr sourceaddr;
#endif
@@ -66,80 +59,46 @@ struct parameters
int ttl;
int loop;
#endif
-
-#ifdef IGMP
- short query_type;
- struct in_addr destaddr;
- int max_resp_time;
-#endif
};
/** Initialize parameters struct with default values. */
void default_parameters(struct parameters* params)
{
- params->duration = 10;
+ params->duration = 0;
params->port = 0;
memset(¶ms->multiaddr, 0, sizeof(struct in_addr));
memset(¶ms->interface, 0, sizeof(struct in_addr));
-
-#if defined(RECEIVE) || defined(IGMP)
+#ifdef RECEIVE
memset(¶ms->sourceaddr, 0, sizeof(struct in_addr));
#endif
-
#ifdef SEND
params->delay = 0.1;
params->ttl = 1;
params->loop = 1;
#endif
-
-#ifdef IGMP
- params->query_type = IGMP_GENERAL_QUERY;
- memset(¶ms->destaddr, 0, sizeof(struct in_addr));
- params->max_resp_time = 10;
-#endif
}
void usage(char *program_name, int retval)
{
printf("usage: %s\n", program_name);
- printf(" -h | --help print this\n");
- printf(" -i | --interface a.b.c.d local interface to use for communication\n");
- printf(" -v | --verbose print additional information during the runtime\n");
-
- printf("\n");
-
- printf(" -d | --duration x test duration\n");
-
-#ifdef SEND
- printf(" -f | --delay x delay between messages\n");
-#endif
+ printf(" -h | --help print this\n");
+ printf(" -v | --verbose print additional information during the runtime\n");
+ printf(" -i | --interface a.b.c.d local interface to use for communication\n");
+ printf(" -d | --duration x test duration\n");
printf("\n");
- printf(" -a | --address a.b.c.d multicast group address\n");
-
-#if defined(SEND) || defined(IGMP)
- printf(" -s | --source_address a.b.c.d source address\n");
+ printf(" -a | --multicast_address a.b.c.d multicast group address\n");
+#ifdef RECEIVE
+ printf(" -s | --source_address a.b.c.d multicast source (for SSM)\n");
#endif
-
-#ifdef IGMP
- printf(" -z | --dest_address a.b.c.d destination address\n");
-#endif
-
-#if defined(SEND) || defined(RECEIVE)
- printf(" -p | --port x port number\n");
-#endif
-
+ printf(" -p | --port x port number\n");
+#ifdef SEND
printf("\n");
-#ifdef IGMP
- printf(" -q | --query_type query type\n");
- printf(" -r | --max_resp_time x maximum response time\n");
-#endif
-
-#ifdef SEND
- printf(" -t | --ttl x time to live for IP packet\n");
- printf(" -l | --loop x loopback multicast communication\n");
+ printf(" -t | --ttl x time to live for IP packet\n");
+ printf(" -l | --loop x loopback multicast communication\n");
+ printf(" -f | --delay x delay between messages\n");
#endif
exit(retval);
@@ -149,60 +108,37 @@ void usage(char *program_name, int retval)
void parse_args(int argc, char** argv, struct parameters* args)
{
#ifdef SEND
- #define __send_opts "f:t:l:p:"
+ #define __send_opts "f:t:l:"
#else
#define __send_opts ""
#endif
-#if defined(RECEIVE) || defined(IGMP)
- #define __recv_opts "s:p:"
+#ifdef RECEIVE
+ #define __recv_opts "s:"
#else
#define __recv_opts ""
#endif
-#ifdef IGMP
- #define __igmp_opts "q:z:r:"
-#else
- #define __igmp_opts ""
-#endif
-
-#ifdef IGMP
- int dest_was_set = 0;
-#endif
-
- static const char* opts = "d:a:i:v" __send_opts __recv_opts
- __igmp_opts;
+ static const char* opts = __send_opts __recv_opts "d:a:p:i:hv";
static struct option long_options[] =
{
- {"help", required_argument, NULL, 'h'},
- {"interface", required_argument, NULL, 'i'},
- {"verbose", no_argument, NULL, 'v'},
- {"duration", required_argument, NULL, 'd'},
- {"multicast_address", required_argument, NULL, 'a'},
-
-#if defined(RECEIVE) || defined(IGMP)
- {"source_address", required_argument, NULL, 's'},
-#endif
-
#ifdef SEND
{"delay", required_argument, NULL, 'f'},
{"ttl", required_argument, NULL, 't'},
{"loop", required_argument, NULL, 'l'},
#endif
-
-#if defined(SEND) || defined(RECEIVE)
- {"port", required_argument, NULL, 'p'},
-#endif
-
-#ifdef IGMP
- {"query_type", required_argument, NULL, 'q'},
- {"dest_address", required_argument, NULL, 'z'},
- {"max_resp_time", required_argument, NULL, 'r'},
-
+#ifdef RECEIVE
+ {"source_address", required_argument, NULL, 's'},
#endif
- {0, 0, NULL, 0}
+ {"duration", required_argument, NULL, 'd'},
+ {"multicast_address", required_argument, NULL, 'a'},
+ {"port", required_argument, NULL, 'p'},
+ {"interface", required_argument, NULL, 'i'},
+ {"help", no_argument, NULL, 'h'},
+ {"verbose", no_argument, NULL, 'v'},
+ {0, 0, NULL, 0}
};
default_parameters(args);
@@ -212,6 +148,22 @@ void parse_args(int argc, char** argv, struct parameters* args)
while((opt = getopt_long(argc, argv, opts, long_options,
&option_index)) != -1) {
switch (opt) {
+#ifdef SEND
+ case 'f':
+ args->delay = atof(optarg);
+ break;
+ case 't':
+ args->ttl = atoi(optarg);
+ break;
+ case 'l':
+ args->loop = atoi(optarg);
+ break;
+#endif
+#ifdef RECEIVE
+ case 's':
+ inet_pton(AF_INET, optarg, &(args->sourceaddr));
+ break;
+#endif
case 'd':
args->duration = atoi(optarg);
break;
@@ -221,67 +173,20 @@ void parse_args(int argc, char** argv, struct parameters* args)
case 'p':
args->port = atoi(optarg);
break;
- case 'h':
- usage(argv[1], EXIT_SUCCESS);
- break;
case 'i':
inet_pton(AF_INET, optarg, &(args->interface));
break;
+ case 'h':
+ usage(argv[0], EXIT_SUCCESS);
+ break;
case 'v':
__verbosity = 1;
break;
-#if defined(RECEIVE) || defined(IGMP)
- case 's':
- inet_pton(AF_INET, optarg, &(args->sourceaddr));
- break;
-#endif
-
-#ifdef SEND
- case 'f':
- args->delay = atof(optarg);
- break;
- case 't':
- args->ttl = atoi(optarg);
- break;
- case 'l':
- args->loop = atoi(optarg);
- break;
-#endif
-
-#ifdef IGMP
- case 'q':
- args->query_type = atoi(optarg);
- /*if (strcmp(optarg, "general") == 0) {
- args->query_type = IGMP_GENERAL_QUERY;
- } else if (strcmp(optarg, "group_specific") == 0) {
- args->query_type = IGMP_GROUP_SPECIFIC_QUERY;
- } else if (strcmp(optarg, "group_and_source_specific") == 0) {
- args->query_type = IGMP_GROUP_AND_SOURCE_SPECIFIC_QUERY;
- } else {
- fprintf(stderr, "%s: undefined query type\n",
- argv[0]);
- exit(EXIT_FAILURE);
- }*/
- break;
- case 'z':
- inet_pton(AF_INET, optarg, &(args->destaddr));
- dest_was_set = 1;
- break;
- case 'r':
- args->max_resp_time = atoi(optarg);
- break;
-#endif
default: /* '?' */
- fprintf(stderr, "%s: invalid test options\n", argv[0]);
+ fprintf(stderr, "%s: invalid options\n", argv[0]);
usage(argv[0], EXIT_FAILURE);
}
}
-
-#ifdef IGMP
- if (!dest_was_set)
- args->destaddr = args->multiaddr;
-#endif
-
}
#endif