[ofa-general] [PATCH 2/5] Add an optional test utility 'ibsendtrap'

Ira Weiny weiny2 at llnl.gov
Fri Mar 21 15:51:17 PDT 2008


>From 9294bf0041e88a077918619d5a93be318075cd74 Mon Sep 17 00:00:00 2001
From: Ira K. Weiny <weiny2 at llnl.gov>
Date: Fri, 21 Mar 2008 14:26:05 -0700
Subject: [PATCH] Add an optional test utility 'ibsendtrap'
use --enable-test-utils to build this tool

Signed-off-by: Ira K. Weiny <weiny2 at llnl.gov>
---
 infiniband-diags/Makefile.am      |    8 ++
 infiniband-diags/configure.in     |   12 +++
 infiniband-diags/src/ibsendtrap.c |  179 +++++++++++++++++++++++++++++++++++++
 3 files changed, 199 insertions(+), 0 deletions(-)
 create mode 100644 infiniband-diags/src/ibsendtrap.c

diff --git a/infiniband-diags/Makefile.am b/infiniband-diags/Makefile.am
index 07a6233..d29d417 100644
--- a/infiniband-diags/Makefile.am
+++ b/infiniband-diags/Makefile.am
@@ -12,6 +12,10 @@ sbin_PROGRAMS = src/ibaddr src/ibnetdiscover src/ibping src/ibportstate \
 	        src/perfquery src/sminfo src/smpdump src/smpquery \
 	        src/saquery src/vendstat
 
+if ENABLE_TEST_UTILS
+sbin_PROGRAMS += src/ibsendtrap
+endif
+
 sbin_SCRIPTS = scripts/ibcheckerrs scripts/ibchecknet scripts/ibchecknode \
                scripts/ibcheckport scripts/ibhosts scripts/ibstatus \
 	       scripts/ibswitches scripts/ibnodes scripts/ibrouters \
@@ -71,6 +75,10 @@ src_saquery_SOURCES = src/saquery.c src/ibdiag_common.c
 src_saquery_CFLAGS = -Wall -DOSM_VENDOR_INTF_OPENIB -DVENDOR_RMPP_SUPPORT -DDUAL_SIDED_RMPP $(DBGFLAGS)
 src_saquery_LDFLAGS = -Wl,--rpath -Wl,$(libdir)
 
+src_ibsendtrap_SOURCES = src/ibsendtrap.c src/ibdiag_common.c
+src_ibsendtrap_CFLAGS = -Wall $(DBGFLAGS)
+src_ibsendtrap_LDFLAGS = -Wl,--rpath -Wl,$(libdir)
+
 src_vendstat_SOURCES = src/vendstat.c src/ibdiag_common.c
 src_vendstat_CFLAGS = -Wall $(DBGFLAGS)
 
diff --git a/infiniband-diags/configure.in b/infiniband-diags/configure.in
index 7468935..33eece1 100644
--- a/infiniband-diags/configure.in
+++ b/infiniband-diags/configure.in
@@ -72,6 +72,18 @@ AC_CHECK_FUNCS([strchr strrchr strtol strtoul memset])
 dnl Checks for typedefs, structures, and compiler characteristics.
 AC_C_CONST
 
+dnl Check if we should include test utilities
+AC_MSG_CHECKING(for --enable-test-utils)
+AC_ARG_ENABLE(test-utils,
+[  --enable-test-utils build additional test utilities],
+[case "${enableval}" in
+  yes) tutils=yes ;;
+  no)  tutils=no ;;
+  *) AC_MSG_ERROR(bad value ${enableval} for --enable-test-utils) ;;
+esac],[tutils=no])
+AM_CONDITIONAL(ENABLE_TEST_UTILS, test x$tutils = xyes)
+AC_MSG_RESULT(${tutils=no})
+
 dnl Check for perl and perl install location
 AC_MSG_CHECKING(for --with-perl-path )
 AC_ARG_WITH(perl-path,
diff --git a/infiniband-diags/src/ibsendtrap.c b/infiniband-diags/src/ibsendtrap.c
new file mode 100644
index 0000000..ae5069b
--- /dev/null
+++ b/infiniband-diags/src/ibsendtrap.c
@@ -0,0 +1,179 @@
+/*
+ * Copyright (c) 2008 Lawrence Livermore National Security
+ *
+ * Produced at Lawrence Livermore National Laboratory.
+ * Written by Ira Weiny <weiny2 at llnl.gov>.
+ *
+ * This software is available to you under a choice of one of two
+ * licenses.  You may choose to be licensed under the terms of the GNU
+ * General Public License (GPL) Version 2, available from the file
+ * COPYING in the main directory of this source tree, or the
+ * OpenIB.org BSD license below:
+ *
+ *     Redistribution and use in source and binary forms, with or
+ *     without modification, are permitted provided that the following
+ *     conditions are met:
+ *
+ *      - Redistributions of source code must retain the above
+ *        copyright notice, this list of conditions and the following
+ *        disclaimer.
+ *
+ *      - Redistributions in binary form must reproduce the above
+ *        copyright notice, this list of conditions and the following
+ *        disclaimer in the documentation and/or other materials
+ *        provided with the distribution.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+ * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
+ * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
+ * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ *
+ */
+
+#include <stdio.h>
+#include <unistd.h>
+
+#define _GNU_SOURCE
+#include <getopt.h>
+
+#include <infiniband/mad.h>
+#include <infiniband/iba/ib_types.h>
+
+#include "ibdiag_common.h"
+
+char     *argv0 = "";
+char	 *sa_hca_name = NULL;
+uint32_t  sa_port_num = 0;
+
+
+static int
+send_144_node_desc_update(void)
+{
+	ib_portid_t sm_port;
+	ib_portid_t selfportid;
+	int selfport;
+	ib_rpc_t  trap_rpc;
+	ib_mad_notice_attr_t notice;
+
+	if (ib_resolve_self(&selfportid, &selfport, NULL))
+		IBERROR("can't resolve self");
+
+	if (ib_resolve_smlid(&sm_port, 0))
+		IBERROR("can't resolve SM destination port");
+
+	memset(&trap_rpc, 0, sizeof(trap_rpc));
+	trap_rpc.mgtclass = IB_SMI_CLASS;
+	trap_rpc.method = IB_MAD_METHOD_TRAP;
+	trap_rpc.trid = mad_trid();
+	trap_rpc.attr.id = NOTICE;
+	trap_rpc.datasz = IB_SMP_DATA_SIZE;
+	trap_rpc.dataoffs = IB_SMP_DATA_OFFS;
+
+	memset(&notice, 0, sizeof(notice));
+	notice.generic_type = 0x80 | IB_NOTICE_TYPE_INFO;
+	notice.g_or_v.generic.prod_type_lsb = cl_hton16(IB_NODE_TYPE_CA);
+	notice.g_or_v.generic.trap_num = cl_hton16(144);
+	notice.issuer_lid = cl_hton16(selfportid.lid);
+	notice.data_details.ntc_144.lid = cl_hton16(selfportid.lid);
+	notice.data_details.ntc_144.local_changes = TRAP_144_MASK_OTHER_LOCAL_CHANGES;
+	notice.data_details.ntc_144.change_flgs = TRAP_144_MASK_NODE_DESCRIPTION_CHANGE;
+
+	return (mad_send(&trap_rpc, &sm_port, NULL, &notice));
+}
+
+typedef struct _trap_def {
+	char *trap_name;
+	int (*send_func)(void);
+} trap_def_t;
+
+trap_def_t traps[2] = {
+	{ "node_desc_change", send_144_node_desc_update },
+	{ NULL, NULL }
+};
+
+static void
+usage(void)
+{
+	int i = 0;
+	fprintf(stderr, "Usage: %s [-hV]"
+		"[-C <ca_name> -P <ca_port>] <trap_name>\n",
+		argv0);
+	fprintf(stderr, "   Queries node records by default\n");
+	fprintf(stderr, "   -C <ca_name> specify the SA query HCA\n");
+	fprintf(stderr, "   -P <ca_port> specify the SA query port\n");
+	fprintf(stderr, "   -V print version\n");
+	fprintf(stderr, "   <trap_name> can be one of the following\n");
+	for (i=0; traps[i].trap_name; i++) {
+		fprintf(stderr, "      %s\n", traps[i].trap_name);
+	}
+	fprintf(stderr, "   default behavior is to send \"%s\"\n",
+		traps[0].trap_name);
+
+	exit(-1);
+}
+
+int
+send_trap(char *trap_name)
+{
+	int i = 0;
+	for (i=0; traps[i].trap_name; i++) {
+		if (strcmp(traps[i].trap_name, trap_name) == 0) {
+			return (traps[i].send_func());
+		}
+	}
+	usage();
+	exit(1);
+}
+
+int
+main(int argc, char **argv)
+{
+	int mgmt_classes[2] = {IB_SMI_CLASS, IB_SMI_DIRECT_CLASS};
+	int ch = 0;
+	char *trap_name = NULL;
+
+	static char const str_opts[] = "hVP:C:";
+	static const struct option long_opts [] = {
+	   {"Version", 0, 0, 'V'},
+	   {"P", 1, 0, 'P'},
+	   {"C", 1, 0, 'C'},
+	   {"help", 0, 0, 'h'},
+	   { }
+	};
+
+	argv0 = argv[0];
+
+	while ((ch = getopt_long(argc, argv, str_opts, long_opts, NULL)) != -1) {
+		switch (ch) {
+		case 'V':
+			fprintf(stderr, "%s %s\n", argv0, get_build_version());
+			exit(-1);
+		case 'C':
+			sa_hca_name = optarg;
+			break;
+		case 'P':
+			sa_port_num = strtoul(optarg, NULL, 0);
+			break;
+		case 'h':
+		default:
+			usage();
+		}
+	}
+	argc -= optind;
+	argv += optind;
+
+	if (!argv[0]) {
+		trap_name = traps[0].trap_name;
+	} else {
+		trap_name = argv[0];
+	}
+
+	madrpc_show_errors(1);
+	madrpc_init(NULL, 0, mgmt_classes, 2);
+
+	return (send_trap(trap_name));
+}
-- 
1.5.1



More information about the general mailing list