2 * Copyright (c) 2008 Lawrence Livermore National Security
4 * Produced at Lawrence Livermore National Laboratory.
5 * Written by Ira Weiny <weiny2@llnl.gov>.
7 * This software is available to you under a choice of one of two
8 * licenses. You may choose to be licensed under the terms of the GNU
9 * General Public License (GPL) Version 2, available from the file
10 * COPYING in the main directory of this source tree, or the
11 * OpenIB.org BSD license below:
13 * Redistribution and use in source and binary forms, with or
14 * without modification, are permitted provided that the following
17 * - Redistributions of source code must retain the above
18 * copyright notice, this list of conditions and the following
21 * - Redistributions in binary form must reproduce the above
22 * copyright notice, this list of conditions and the following
23 * disclaimer in the documentation and/or other materials
24 * provided with the distribution.
26 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
27 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
28 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
29 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
30 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
31 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
32 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
45 #include <infiniband/mad.h>
46 #include <infiniband/iba/ib_types.h>
48 #include "ibdiag_common.h"
52 static int send_144_node_desc_update(void)
55 ib_portid_t selfportid;
58 ib_mad_notice_attr_t notice;
60 if (ib_resolve_self(&selfportid, &selfport, NULL))
61 IBERROR("can't resolve self");
63 if (ib_resolve_smlid(&sm_port, 0))
64 IBERROR("can't resolve SM destination port");
66 memset(&trap_rpc, 0, sizeof(trap_rpc));
67 trap_rpc.mgtclass = IB_SMI_CLASS;
68 trap_rpc.method = IB_MAD_METHOD_TRAP;
69 trap_rpc.trid = mad_trid();
70 trap_rpc.attr.id = NOTICE;
71 trap_rpc.datasz = IB_SMP_DATA_SIZE;
72 trap_rpc.dataoffs = IB_SMP_DATA_OFFS;
74 memset(¬ice, 0, sizeof(notice));
75 notice.generic_type = 0x80 | IB_NOTICE_TYPE_INFO;
76 notice.g_or_v.generic.prod_type_lsb = cl_hton16(IB_NODE_TYPE_CA);
77 notice.g_or_v.generic.trap_num = cl_hton16(144);
78 notice.issuer_lid = cl_hton16(selfportid.lid);
79 notice.data_details.ntc_144.lid = cl_hton16(selfportid.lid);
80 notice.data_details.ntc_144.local_changes =
81 TRAP_144_MASK_OTHER_LOCAL_CHANGES;
82 notice.data_details.ntc_144.change_flgs =
83 TRAP_144_MASK_NODE_DESCRIPTION_CHANGE;
85 return (mad_send(&trap_rpc, &sm_port, NULL, ¬ice));
88 typedef struct _trap_def {
90 int (*send_func) (void);
93 trap_def_t traps[2] = {
94 {"node_desc_change", send_144_node_desc_update},
98 static void usage(void)
102 fprintf(stderr, "Usage: %s [-hV]"
103 " [-C <ca_name>] [-P <ca_port>] [<trap_name>]\n", argv0);
104 fprintf(stderr, " -V print version\n");
105 fprintf(stderr, " <trap_name> can be one of the following\n");
106 for (i = 0; traps[i].trap_name; i++) {
107 fprintf(stderr, " %s\n", traps[i].trap_name);
109 fprintf(stderr, " default behavior is to send \"%s\"\n",
115 int send_trap(char *trap_name)
119 for (i = 0; traps[i].trap_name; i++) {
120 if (strcmp(traps[i].trap_name, trap_name) == 0) {
121 return (traps[i].send_func());
128 int main(int argc, char **argv)
130 int mgmt_classes[2] = { IB_SMI_CLASS, IB_SMI_DIRECT_CLASS };
132 char *trap_name = NULL;
136 static char const str_opts[] = "hVP:C:";
137 static const struct option long_opts[] = {
138 {"Version", 0, 0, 'V'},
147 while ((ch = getopt_long(argc, argv, str_opts, long_opts, NULL)) != -1) {
150 fprintf(stderr, "%s %s\n", argv0, get_build_version());
156 ca_port = strtoul(optarg, NULL, 0);
167 trap_name = traps[0].trap_name;
172 madrpc_show_errors(1);
173 madrpc_init(ca, ca_port, mgmt_classes, 2);
175 return (send_trap(trap_name));