Exemple #1
0
int
main(int argc, char **argv)
{
	int mgmt_classes[4] = {IB_SMI_CLASS, IB_SMI_DIRECT_CLASS, IB_SA_CLASS, IB_PERFORMANCE_CLASS};
	ib_portid_t *sm_id = 0, sm_portid = {0};
	ib_portid_t portid = {0};
	extern int ibdebug;
	int dest_type = IB_DEST_LID;
	int timeout = 0;	/* use default */
	int mask = 0xffff, all_ports = 0;
	int reset = 0, reset_only = 0;
	int port = 0;
	int udebug = 0;
	char *ca = 0;
	int ca_port = 0;
	int extended = 0;
	uint16_t cap_mask;
	int all_ports_loop = 0;
	int loop_ports = 0;
	int node_type, num_ports = 0;
	uint8_t data[IB_SMP_DATA_SIZE];
	int start_port = 1;
	int enhancedport0;
	int i;

	static char const str_opts[] = "C:P:s:t:dGealrRVhu";
	static const struct option long_opts[] = {
		{ "C", 1, 0, 'C'},
		{ "P", 1, 0, 'P'},
		{ "debug", 0, 0, 'd'},
		{ "Guid", 0, 0, 'G'},
		{ "extended", 0, 0, 'e'},
		{ "all_ports", 0, 0, 'a'},
		{ "loop_ports", 0, 0, 'l'},
		{ "reset_after_read", 0, 0, 'r'},
		{ "Reset_only", 0, 0, 'R'},
		{ "sm_portid", 1, 0, 's'},
		{ "timeout", 1, 0, 't'},
		{ "Version", 0, 0, 'V'},
		{ "help", 0, 0, 'h'},
		{ "usage", 0, 0, 'u'},
		{ }
	};

	argv0 = argv[0];

	while (1) {
		int ch = getopt_long(argc, argv, str_opts, long_opts, NULL);
		if ( ch == -1 )
			break;
		switch(ch) {
		case 'C':
			ca = optarg;
			break;
		case 'P':
			ca_port = strtoul(optarg, 0, 0);
			break;
		case 'e':
			extended = 1;
			break;
		case 'a':
			all_ports++;
			port = ALL_PORTS;
			break;
		case 'l':
			loop_ports++;
			break;
		case 'd':
			ibdebug++;
			madrpc_show_errors(1);
			umad_debug(udebug);
			udebug++;
			break;
		case 'G':
			dest_type = IB_DEST_GUID;
			break;
		case 's':
			if (ib_resolve_portid_str(&sm_portid, optarg, IB_DEST_LID, 0) < 0)
				IBERROR("can't resolve SM destination port %s", optarg);
			sm_id = &sm_portid;
			break;
		case 'r':
			reset++;
			break;
		case 'R':
			reset_only++;
			break;
		case 't':
			timeout = strtoul(optarg, 0, 0);
			madrpc_set_timeout(timeout);
			break;
		case 'V':
			fprintf(stderr, "%s %s\n", argv0, get_build_version() );
			exit(-1);
		default:
			usage();
			break;
		}
	}
	argc -= optind;
	argv += optind;

	if (argc > 1)
		port = strtoul(argv[1], 0, 0);
	if (argc > 2)
		mask = strtoul(argv[2], 0, 0);

	madrpc_init(ca, ca_port, mgmt_classes, 4);

	if (argc) {
		if (ib_resolve_portid_str(&portid, argv[0], dest_type, sm_id) < 0)
			IBERROR("can't resolve destination port %s", argv[0]);
	} else {
		if (ib_resolve_self(&portid, &port, 0) < 0)
			IBERROR("can't resolve self port %s", argv[0]);
	}

	/* PerfMgt ClassPortInfo is a required attribute */
	if (!perf_classportinfo_query(pc, &portid, port, timeout))
		IBERROR("classportinfo query");
	/* ClassPortInfo should be supported as part of libibmad */
	memcpy(&cap_mask, pc+2, sizeof(cap_mask));	/* CapabilityMask */
	cap_mask = ntohs(cap_mask);
	if (!(cap_mask & 0x100)) { /* bit 8 is AllPortSelect */
		if (!all_ports && port == ALL_PORTS)
			IBERROR("AllPortSelect not supported");
		if (all_ports)
			all_ports_loop = 1;
	}

	if (all_ports_loop || (loop_ports && (all_ports || port == ALL_PORTS))) {
		if (smp_query(data, &portid, IB_ATTR_NODE_INFO, 0, 0) < 0)
			IBERROR("smp query nodeinfo failed");
		node_type = mad_get_field(data, 0, IB_NODE_TYPE_F);
		mad_decode_field(data, IB_NODE_NPORTS_F, &num_ports);
		if (!num_ports)
			IBERROR("smp query nodeinfo: num ports invalid");

		if (node_type == IB_NODE_SWITCH) {
			if (smp_query(data, &portid, IB_ATTR_SWITCH_INFO, 0, 0) < 0)
				IBERROR("smp query nodeinfo failed");
			enhancedport0 = mad_get_field(data, 0, IB_SW_ENHANCED_PORT0_F);
			if (enhancedport0)
				start_port = 0;
		}
		if (all_ports_loop && !loop_ports)
			IBWARN("Emulating AllPortSelect by iterating through all ports");
	}

	if (reset_only)
		goto do_reset;

	if (all_ports_loop || (loop_ports && (all_ports || port == ALL_PORTS))) {
		for (i = start_port; i <= num_ports; i++)
			dump_perfcounters(extended, timeout, cap_mask, &portid, i,
					  (all_ports_loop && !loop_ports));
		if (all_ports_loop && !loop_ports) {
			if (extended != 1)
				output_aggregate_perfcounters(&portid);
			else
				output_aggregate_perfcounters_ext(&portid);
		}
	}
	else
		dump_perfcounters(extended, timeout, cap_mask, &portid, port, 0);

	if (!reset)
		exit(0);

do_reset:

	if (all_ports_loop || (loop_ports && (all_ports || port == ALL_PORTS))) {
		for (i = start_port; i <= num_ports; i++)
			reset_counters(extended, timeout, mask, &portid, i);
	}
	else
		reset_counters(extended, timeout, mask, &portid, port);

	exit(0);
}
Exemple #2
0
int
main(int argc, char **argv)
{
	int mgmt_classes[4] = {IB_SMI_CLASS, IB_SMI_DIRECT_CLASS, IB_SA_CLASS, IB_MLX_VENDOR_CLASS};
	ib_portid_t *sm_id = 0, sm_portid = {0};
	ib_portid_t portid = {0};
	extern int ibdebug;
	int dest_type = IB_DEST_LID;
	int timeout = 0;	/* use default */
	int port = 0;
	char buf[1024];
	int udebug = 0;
	char *ca = 0;
	int ca_port = 0;
	ib_vendor_call_t call;
	is3_general_info_t *gi;
	is3_config_space_t *cs;
	int general_info = 0;
	int xmit_wait = 0;
	int i;

	static char const str_opts[] = "C:P:s:t:dNwGVhu";
	static const struct option long_opts[] = {
		{ "C", 1, 0, 'C'},
		{ "P", 1, 0, 'P'},
		{ "N", 1, 0, 'N'},
		{ "w", 1, 0, 'w'},
		{ "debug", 0, 0, 'd'},
		{ "Guid", 0, 0, 'G'},
		{ "sm_portid", 1, 0, 's'},
		{ "timeout", 1, 0, 't'},
		{ "Version", 0, 0, 'V'},
		{ "help", 0, 0, 'h'},
		{ "usage", 0, 0, 'u'},
		{ }
	};

	argv0 = argv[0];

	while (1) {
		int ch = getopt_long(argc, argv, str_opts, long_opts, NULL);
		if ( ch == -1 )
			break;
		switch(ch) {
		case 'C':
			ca = optarg;
			break;
		case 'P':
			ca_port = strtoul(optarg, 0, 0);
			break;
		case 'N':
			general_info = 1;
			break;
		case 'w':
			xmit_wait = 1;
			break;
		case 'd':
			ibdebug++;
			madrpc_show_errors(1);
			umad_debug(udebug);
			udebug++;
			break;
		case 'G':
			dest_type = IB_DEST_GUID;
			break;
		case 's':
			if (ib_resolve_portid_str(&sm_portid, optarg, IB_DEST_LID, 0) < 0)
				IBERROR("can't resolve SM destination port %s", optarg);
			sm_id = &sm_portid;
			break;
		case 't':
			timeout = strtoul(optarg, 0, 0);
			madrpc_set_timeout(timeout);
			break;
		case 'V':
			fprintf(stderr, "%s %s\n", argv0, get_build_version() );
			exit(-1);
		default:
			usage();
			break;
		}
	}
	argc -= optind;
	argv += optind;

	if (argc > 1)
		port = strtoul(argv[1], 0, 0);

	madrpc_init(ca, ca_port, mgmt_classes, 4);

	if (argc) {
		if (ib_resolve_portid_str(&portid, argv[0], dest_type, sm_id) < 0)
			IBERROR("can't resolve destination port %s", argv[0]);
	} else {
		if (ib_resolve_self(&portid, &port, 0) < 0)
			IBERROR("can't resolve self port %s", argv[0]);
	}

	/* Only General Info and Port Xmit Wait Counters */
	/* queries are currently supported */
	if (!general_info && !xmit_wait)
		IBERROR("at least one of -N and -w must be specified");

	/* These are Mellanox specific vendor MADs */
	/* but vendors change the VendorId so how know for sure ? */
	/* Would need a list of these and it might not be complete */
	/* so for right now, punt on this */

	memset(&call, 0, sizeof(call));
	call.mgmt_class = IB_MLX_VENDOR_CLASS;
	call.method = IB_MAD_METHOD_GET;
	call.timeout = timeout;

	memset(&buf, 0, sizeof(buf));
	/* vendor ClassPortInfo is required attribute if class supported */
	call.attrid = CLASS_PORT_INFO;
	if (!ib_vendor_call(&buf, &portid, &call))
		IBERROR("classportinfo query");

	memset(&buf, 0, sizeof(buf));
	call.attrid = IB_MLX_IS3_GENERAL_INFO;
	if (!ib_vendor_call(&buf, &portid, &call))
		IBERROR("vendstat");
	gi = (is3_general_info_t *)&buf;

	if (general_info) {
		/* dump IS3 general info here */
		printf("hw_dev_rev:  0x%04x\n", ntohs(gi->hw_info.hw_revision));
		printf("hw_dev_id:   0x%04x\n", ntohs(gi->hw_info.device_id));
		printf("hw_uptime:   0x%08x\n", ntohl(gi->hw_info.uptime));
		printf("fw_version:  %02d.%02d.%02d\n",
		       gi->fw_info.major, gi->fw_info.minor, gi->fw_info.sub_minor);
		printf("fw_build_id: 0x%04x\n", ntohl(gi->fw_info.build_id));
		printf("fw_date:     %02d/%02d/%04x\n",
		       gi->fw_info.month, gi->fw_info.day, ntohs(gi->fw_info.year));
		printf("fw_psid:     '%s'\n", gi->fw_info.psid);
		printf("fw_ini_ver:  %d\n", ntohl(gi->fw_info.ini_file_version));
		printf("sw_version:  %02d.%02d.%02d\n",
		       gi->sw_info.major, gi->sw_info.minor, gi->sw_info.sub_minor);
	}

	if (xmit_wait) {
		if (ntohs(gi->hw_info.device_id) != IS3_DEVICE_ID)
			IBERROR("Unsupported device ID 0x%x", ntohs(gi->hw_info.device_id));

		memset(&buf, 0, sizeof(buf));
		call.attrid = IB_MLX_IS3_CONFIG_SPACE_ACCESS;
		/* Limit of 18 accesses per MAD ? */
		call.mod = 2 << 22 | 16 << 16; /* 16 records */
		/* Set record addresses for each port */
		cs = (is3_config_space_t *)&buf;
		for (i = 0; i < 16; i++)
			cs->record[i].address = htonl(IB_MLX_IS3_PORT_XMIT_WAIT + ((i + 1) << 12));
		if (!ib_vendor_call(&buf, &portid, &call))
			IBERROR("vendstat");

		for (i = 0; i < 16; i++)
			if (cs->record[i].data)	/* PortXmitWait is 32 bit counter */
				printf("Port %d: PortXmitWait 0x%x\n", i + 4, ntohl(cs->record[i].data)); /* port 4 is first port */

		/* Last 8 ports is another query */
		memset(&buf, 0, sizeof(buf));
		call.attrid = IB_MLX_IS3_CONFIG_SPACE_ACCESS;
                call.mod = 2 << 22 | 8 << 16; /* 8 records */
		/* Set record addresses for each port */
		cs = (is3_config_space_t *)&buf;
		for (i = 0; i < 8; i++)
			cs->record[i].address = htonl(IB_MLX_IS3_PORT_XMIT_WAIT + ((i + 17) << 12));
		if (!ib_vendor_call(&buf, &portid, &call))
			IBERROR("vendstat");

		for (i = 0; i < 8; i++)
			if (cs->record[i].data) /* PortXmitWait is 32 bit counter */
				printf("Port %d: PortXmitWait 0x%x\n",
				       i < 4 ? i + 21 : i - 3,
				       ntohl(cs->record[i].data));
	}

	exit(0);
}
Exemple #3
0
int main(int argc, char ** argv)
{
    int                 c;
    uint8               hfi         = 1;
    uint8               port        = 0;
	int					index;
	QUERY				query;
	OutputStringMap_t	*outputTypeMap = NULL;

	memset(&query, 0, sizeof(query));	// initialize reserved fields

	// default query for this application is for all node records
	query.InputType 	= InputTypeNoInput;
	query.OutputType 	= OutputTypeStlNodeRecord;

	// process command line arguments
	while (-1 != (c = getopt_long(argc,argv, "vIh:p:l:k:i:t:s:n:g:u:m:d:P:G:a:A:o:S:L:", options, &index)))
    {
        switch (c)
        {
            case '$':
                Usage_full();
                break;
            case 'v':
                g_verbose++;
				if (g_verbose>1) oib_set_dbg(stderr);
				if (g_verbose>2) umad_debug(g_verbose-2);
                break;
			case 'I':   // issue query in legacy InfiniBand format (IB)
				g_IB = 1;
				query.OutputType = OutputTypeNodeRecord;
				break;
            case 'h':	// hfi to issue query from
				if (FSUCCESS != StringToUint8(&hfi, optarg, NULL, 0, TRUE)) {
					fprintf(stderr, "opasaquery: Invalid HFI Number: %s\n", optarg);
					Usage();
				}
                break;
            case 'p':	// port to issue query from
				if (FSUCCESS != StringToUint8(&port, optarg, NULL, 0, TRUE)) {
					fprintf(stderr, "opasaquery: Invalid Port Number: %s\n", optarg);
					Usage();
				}
                break;

            case 'l':	// query by lid
				multiInputCheck(query.InputType);
				query.InputType = InputTypeLid;
				if (FSUCCESS != StringToUint16(&query.InputValue.Lid, optarg, NULL, 0, TRUE)) {
					fprintf(stderr, "opasaquery: Invalid LID: %s\n", optarg);
					Usage();
				}
                break;
            case 'k':	// query by pkey
				multiInputCheck(query.InputType);
				query.InputType = InputTypePKey;
				if (FSUCCESS != StringToUint16(&query.InputValue.PKey, optarg, NULL, 0, TRUE)) {
					fprintf(stderr, "opasaquery: Invalid PKey: %s\n", optarg);
					Usage();
				}
				break;
            case 'i':	// query by vfindex
				multiInputCheck(query.InputType);
				query.InputType = InputTypeIndex;
				if (FSUCCESS != StringToUint16(&query.InputValue.vfIndex, optarg, NULL, 0, TRUE)) {
					fprintf(stderr, "opasaquery: Invalid vfIndex: %s\n", optarg);
					Usage();
				}
				break;
            case 'S':	// query by serviceId
				multiInputCheck(query.InputType);
				query.InputType = InputTypeServiceId;
				if (FSUCCESS != StringToUint64(&query.InputValue.ServiceId, optarg, NULL, 0, TRUE)) {
					fprintf(stderr, "opasaquery: Invalid ServiceId: %s\n", optarg);
					Usage();
				}
				break;
            case 'L':	// query by service level
				multiInputCheck(query.InputType);
				query.InputType = InputTypeSL;
				if (FSUCCESS != StringToUint8(&query.InputValue.SL, optarg, NULL, 0, TRUE)
					|| query.InputValue.SL > 15) {
					fprintf(stderr, "opasaquery: Invalid SL: %s\n", optarg);
					Usage();
				}
                break;
            case 't':	// query by node type
				multiInputCheck(query.InputType);
				query.InputType = InputTypeNodeType;
				query.InputValue.TypeOfNode = checkNodeType(optarg);
                break;
            case 's':	// query by system image guid
				multiInputCheck(query.InputType);
				query.InputType = InputTypeSystemImageGuid;
				if (FSUCCESS != StringToUint64(&query.InputValue.Guid, optarg, NULL, 0, TRUE)) {
					fprintf(stderr, "opasaquery: Invalid GUID: %s\n", optarg);
					Usage();
				}
                break;
            case 'n':	// query by node guid
				multiInputCheck(query.InputType);
				query.InputType = InputTypeNodeGuid;
				if (FSUCCESS != StringToUint64(&query.InputValue.Guid, optarg, NULL, 0, TRUE)) {
					fprintf(stderr, "opasaquery: Invalid GUID: %s\n", optarg);
					Usage();
				}
                break;
            case 'g':	// query by port guid
				multiInputCheck(query.InputType);
				query.InputType = InputTypePortGuid;
				if (FSUCCESS != StringToUint64(&query.InputValue.Guid, optarg, NULL, 0, TRUE)) {
					fprintf(stderr, "opasaquery: Invalid GUID: %s\n", optarg);
					Usage();
				}
                break;
            case 'u':	// query by gid
				multiInputCheck(query.InputType);
				query.InputType = InputTypePortGid;
				if (FSUCCESS != StringToGid(&query.InputValue.Gid.AsReg64s.H,&query.InputValue.Gid.AsReg64s.L, optarg, NULL, TRUE)) {
					fprintf(stderr, "opasaquery: Invalid GID: %s\n", optarg);
					Usage();
				}
                break;
            case 'm':	// query by multicast gid
				multiInputCheck(query.InputType);
				query.InputType = InputTypeMcGid;
				if (FSUCCESS != StringToGid(&query.InputValue.Gid.AsReg64s.H,&query.InputValue.Gid.AsReg64s.L, optarg, NULL, TRUE)) {
					fprintf(stderr, "opasaquery: Invalid GID: %s\n", optarg);
					Usage();
				}
                break;
            case 'd':	// query by node description
				multiInputCheck(query.InputType);
				query.InputType = InputTypeNodeDesc;
				query.InputValue.NodeDesc.NameLength = MIN(strlen(optarg), NODE_DESCRIPTION_ARRAY_SIZE);
				strncpy((char*)query.InputValue.NodeDesc.Name, optarg, NODE_DESCRIPTION_ARRAY_SIZE);
                break;
			case 'P':	// query by source:dest port guids
				{
					char *p;
					multiInputCheck(query.InputType);
					query.InputType = InputTypePortGuidPair;
					if (FSUCCESS != StringToUint64(&query.InputValue.PortGuidPair.SourcePortGuid, optarg, &p, 0, TRUE)
						|| ! p || *p == '\0') {
						fprintf(stderr, "opasaquery: Invalid GUID Pair: %s\n", optarg);
						Usage();
					}
					if (FSUCCESS != StringToUint64(&query.InputValue.PortGuidPair.DestPortGuid, p, NULL, 0, TRUE)) {
						fprintf(stderr, "opasaquery: Invalid GUID Pair: %s\n", optarg);
						Usage();
					}
				}
                break;
			case 'G':	// query by source:dest port gids
				{
					char *p;
					multiInputCheck(query.InputType);
					query.InputType = InputTypeGidPair;
					if (FSUCCESS != StringToGid(&query.InputValue.GidPair.SourceGid.AsReg64s.H,&query.InputValue.GidPair.SourceGid.AsReg64s.L, optarg, &p, TRUE)
						|| ! p || *p == '\0') {
						fprintf(stderr, "opasaquery: Invalid GID Pair: %s\n", optarg);
						Usage();
					}
					if (FSUCCESS != StringToGid(&query.InputValue.GidPair.DestGid.AsReg64s.H,&query.InputValue.GidPair.DestGid.AsReg64s.L, p, NULL, TRUE)) {
						fprintf(stderr, "opasaquery: Invalid GID Pair: %s\n", optarg);
						Usage();
					}
				}
				break;
			case 'a':	// multipath query by src1:src2:...;dest1:dest2:... port guids
				{
					char *p =optarg;
					int i = 0;
					errno = 0;
					multiInputCheck(query.InputType);
					query.InputType = InputTypePortGuidList;
					do {
						if (FSUCCESS != StringToUint64(&query.InputValue.PortGuidList.GuidList[i], p, &p, 0, TRUE)) {
							fprintf(stderr, "opasaquery: Invalid GUID List: %s\n", optarg);
							Usage();
						}
						i++;
						query.InputValue.PortGuidList.SourceGuidCount++;
					} while (p && *p != '\0' && *p != ';');
					if (p && *p != '\0')
					{
						p++; // skip the semi-colon.
						do {
							if (FSUCCESS != StringToUint64(&query.InputValue.PortGuidList.GuidList[i], p, &p, 0, TRUE)) {
								fprintf(stderr, "opasaquery: Invalid GUID List: %s\n", optarg);
								Usage();
							}
							i++;
							query.InputValue.PortGuidList.DestGuidCount++;
						} while (p && *p != '\0');
					} else {
						Usage();
					}
				}
                break;
			case 'A':	// multipath query by src1:src2:...;dest1:dest2:... gids
				{
					char *p=optarg;
					int i = 0;
					errno = 0;
					multiInputCheck(query.InputType);
					query.InputType = InputTypeGidList;
					do {
						if (FSUCCESS != StringToGid(&query.InputValue.GidList.GidList[i].AsReg64s.H,&query.InputValue.GidList.GidList[i].AsReg64s.L, p, &p, TRUE)) {
							fprintf(stderr, "opasaquery: Invalid GID List: %s\n", optarg);
							Usage();
						}
						i++;
						query.InputValue.GidList.SourceGidCount++;
					} while (p && *p != '\0' && *p != ';');
					if (p && *p != '\0')
					{
						p++; // skip the semi-colon
						do {
							if (FSUCCESS != StringToGid(&query.InputValue.GidList.GidList[i].AsReg64s.H,&query.InputValue.GidList.GidList[i].AsReg64s.L, p, &p, TRUE)) {
								fprintf(stderr, "opasaquery: Invalid GID List: %s\n", optarg);
								Usage();
							}
							i++;
							query.InputValue.GidList.DestGidCount++;
						} while (p && *p != '\0');
					} else {
						Usage();
					}
				}
                break;

            case 'o':	// select output record desired
				outputTypeMap = GetOutputTypeMap(optarg);
                break;
            default:
                fprintf(stderr, "opasaquery: Invalid option -%c\n", c);
                Usage();
                break;
        }
    } /* end while */

	if (optind < argc)
	{
		Usage();
	}

	if (NULL != outputTypeMap)
		query.OutputType = GetOutputType(outputTypeMap); 

	PrintDestInitFile(&g_dest, stdout);
	if (g_verbose)
		PrintDestInitFile(&g_dbgDest, stdout);
	else
		PrintDestInitNone(&g_dbgDest);

	if(oib_open_port_by_num(&sa_oib_session,hfi,port) != 0)
	{
		fprintf(stderr, "opasaquery: Could not open oib session.\n");
		return FERROR;
	}

	// perform the query and display output
	do_query(sa_oib_session, &query);

	oib_close_port(sa_oib_session);

	if (g_exitstatus == 2)
		Usage();

	return g_exitstatus;
}
static int process_opt(int ch, char *optarg)
{
	char *endp;
	long val;

	switch (ch) {
	case 'z':
		read_ibdiag_config(optarg);
		break;
	case 'h':
		ibdiag_show_usage();
		break;
	case 'V':
		fprintf(stderr, "%s %s\n", prog_name, get_build_version());
		exit(0);
	case 'e':
		madrpc_show_errors(1);
		break;
	case 'v':
		ibverbose++;
		break;
	case 'd':
		ibdebug++;
		madrpc_show_errors(1);
		umad_debug(ibdebug - 1);
		break;
	case 'C':
		ibd_ca = optarg;
		break;
	case 'P':
		ibd_ca_port = strtoul(optarg, 0, 0);
		break;
	case 'D':
		ibd_dest_type = IB_DEST_DRPATH;
		break;
	case 'L':
		ibd_dest_type = IB_DEST_LID;
		break;
	case 'G':
		ibd_dest_type = IB_DEST_GUID;
		break;
	case 't':
		errno = 0;
		val = strtol(optarg, &endp, 0);
		if (errno || (endp && *endp != '\0') || val <= 0 ||
		    val > INT_MAX)
			IBERROR("Invalid timeout \"%s\".  Timeout requires a "
				"positive integer value < %d.", optarg, INT_MAX);
		else {
			madrpc_set_timeout((int)val);
			ibd_timeout = (int)val;
		}
		break;
	case 's':
		/* srcport is not required when resolving via IB_DEST_LID */
		if (resolve_portid_str(ibd_ca, ibd_ca_port, &sm_portid, optarg,
				IB_DEST_LID, 0, NULL) < 0)
			IBERROR("cannot resolve SM destination port %s",
				optarg);
		ibd_sm_id = &sm_portid;
		break;
	case 'K':
		show_keys = 1;
		break;
	case 'y':
		errno = 0;
		ibd_mkey = strtoull(optarg, &endp, 0);
		if (errno || *endp != '\0') {
			errno = 0;
			ibd_mkey = strtoull(getpass("M_Key: "), &endp, 0);
			if (errno || *endp != '\0') {
				IBERROR("Bad M_Key");
			}
                }
                break;
	default:
		return -1;
	}

	return 0;
}
Exemple #5
0
int
main(int argc, char **argv)
{
	int mgmt_classes[3] = {IB_SMI_CLASS, IB_SMI_DIRECT_CLASS, IB_SA_CLASS};
	int ping_class = IB_VENDOR_OPENIB_PING_CLASS;
	ib_portid_t *sm_id = 0, sm_portid = {0};
	int timeout = 0, udebug = 0, server = 0, flood = 0;
	int oui = IB_OPENIB_OUI;
	uint64_t rtt;
	unsigned count = ~0;
	extern int ibdebug;
	char *err;
	char *ca = 0;
	int ca_port = 0;

	static char const str_opts[] = "C:P:t:s:c:o:devGfSVhu";
	static const struct option long_opts[] = {
		{ "C", 1, 0, 'C'},
		{ "P", 1, 0, 'P'},
		{ "debug", 0, 0, 'd'},
		{ "err_show", 0, 0, 'e'},
		{ "verbose", 0, 0, 'v'},
		{ "Guid", 0, 0, 'G'},
		{ "s", 1, 0, 's'},
		{ "timeout", 1, 0, 't'},
		{ "c", 1, 0, 'c'},
		{ "flood", 0, 0, 'f'},
		{ "o", 1, 0, 'o'},
		{ "Server", 0, 0, 'S'},
		{ "Version", 0, 0, 'V'},
		{ "help", 0, 0, 'h'},
		{ "usage", 0, 0, 'u'},
		{ }
	};

	argv0 = argv[0];

	while (1) {
		int ch = getopt_long(argc, argv, str_opts, long_opts, NULL);
		if ( ch == -1 )
			break;
		switch(ch) {
		case 'C':
			ca = optarg;
			break;
		case 'P':
			ca_port = strtoul(optarg, 0, 0);
			break;
		case 'c':
			count = strtoul(optarg, 0, 0);
			break;
		case 'd':
			ibdebug++;
			madrpc_show_errors(1);
			umad_debug(udebug);
			udebug++;
			break;
		case 'e':
			madrpc_show_errors(1);
			break;
		case 'f':
			flood++;
			break;
		case 'G':
			dest_type = IB_DEST_GUID;
			break;
		case 'o':
			oui = strtoul(optarg, 0, 0);
			break;
		case 's':
			if (ib_resolve_portid_str(&sm_portid, optarg, IB_DEST_LID, 0) < 0)
				IBERROR("can't resolve SM destination port %s", optarg);
			sm_id = &sm_portid;
			break;
		case 'S':
			server++;
			break;
		case 't':
			timeout = strtoul(optarg, 0, 0);
			madrpc_set_timeout(timeout);
			break;
		case 'v':
			verbose++;
			break;
		case 'V':
			fprintf(stderr, "%s %s\n", argv0, get_build_version() );
			exit(-1);
		default:
			usage();
			break;
		}
	}
	argc -= optind;
	argv += optind;

	if (!argc && !server)
		usage();

	madrpc_init(ca, ca_port, mgmt_classes, 3);

	if (server) {
		if (mad_register_server(ping_class, 0, 0, oui) < 0)
			IBERROR("can't serve class %d on this port", ping_class);

		get_host_and_domain(host_and_domain, sizeof host_and_domain);

		if ((err = ibping_serv()))
			IBERROR("ibping to %s: %s", portid2str(&portid), err);
		exit(0);
	}

	if (mad_register_client(ping_class, 0) < 0)
		IBERROR("can't register ping class %d on this port", ping_class);

	if (ib_resolve_portid_str(&portid, argv[0], dest_type, sm_id) < 0)
		IBERROR("can't resolve destination port %s", argv[0]);

	signal(SIGINT, report);
	signal(SIGTERM, report);

	start = getcurrenttime();

	while (count-- > 0) {
		ntrans++;
		if ((rtt = ibping(&portid, flood)) == ~0ull) {
			DEBUG("ibping to %s failed", portid2str(&portid));
			lost++;
		} else {
			if (rtt < minrtt)
				minrtt = rtt;
			if (rtt > maxrtt)
				maxrtt = rtt;
			total_rtt += rtt;
			replied++;
		}

		if (!flood)
			sleep(1);
	}

	report(0);

	exit(-1);
}
Exemple #6
0
int
main(int argc, char **argv)
{
	int mgmt_classes[3] = {IB_SMI_CLASS, IB_SMI_DIRECT_CLASS, IB_SA_CLASS};
	ib_portid_t portid = {0};
	ib_portid_t *sm_id = 0, sm_portid = {0};
	extern int ibdebug;
	int timeout = 0, udebug = 0;
	char *ca = 0;
	int ca_port = 0;
	char *err;
	op_fn_t *fn;

	static char const str_opts[] = "C:P:t:s:devDcGVhu";
	static const struct option long_opts[] = {
		{ "C", 1, 0, 'C'},
		{ "P", 1, 0, 'P'},
		{ "debug", 0, 0, 'd'},
		{ "err_show", 0, 0, 'e'},
		{ "verbose", 0, 0, 'v'},
		{ "Direct", 0, 0, 'D'},
		{ "combined", 0, 0, 'c'},
		{ "Guid", 0, 0, 'G'},
		{ "smlid", 1, 0, 's'},
		{ "timeout", 1, 0, 't'},
		{ "node-name-map", 1, 0, 1},
		{ "Version", 0, 0, 'V'},
		{ "help", 0, 0, 'h'},
		{ "usage", 0, 0, 'u'},
		{ }
	};

	argv0 = argv[0];

	while (1) {
		int ch = getopt_long(argc, argv, str_opts, long_opts, NULL);
		if ( ch == -1 )
			break;
		switch(ch) {
		case 1:
			node_name_map_file = strdup(optarg);
			break;
		case 'd':
			ibdebug++;
			madrpc_show_errors(1);
			umad_debug(udebug);
			udebug++;
			break;
		case 'e':
			madrpc_show_errors(1);
			break;
		case 'D':
			dest_type = IB_DEST_DRPATH;
			break;
		case 'c':
			dest_type = IB_DEST_DRSLID;
			break;
		case 'G':
			dest_type = IB_DEST_GUID;
			break;
		case 'C':
			ca = optarg;
			break;
		case 'P':
			ca_port = strtoul(optarg, 0, 0);
			break;
		case 's':
			if (ib_resolve_portid_str(&sm_portid, optarg, IB_DEST_LID, 0) < 0)
				IBERROR("can't resolve SM destination port %s", optarg);
			sm_id = &sm_portid;
			break;
		case 't':
			timeout = strtoul(optarg, 0, 0);
			madrpc_set_timeout(timeout);
			break;
		case 'v':
			verbose++;
			break;
		case 'V':
			fprintf(stderr, "%s %s\n", argv0, get_build_version() );
			exit(-1);
		default:
			usage();
			break;
		}
	}
	argc -= optind;
	argv += optind;

	if (argc < 2)
		usage();

	if (!(fn = match_op(argv[0])))
		IBERROR("operation '%s' not supported", argv[0]);

	madrpc_init(ca, ca_port, mgmt_classes, 3);
	node_name_map = open_node_name_map(node_name_map_file);

	if (dest_type != IB_DEST_DRSLID) {
		if (ib_resolve_portid_str(&portid, argv[1], dest_type, sm_id) < 0)
			IBERROR("can't resolve destination port %s", argv[1]);
		if ((err = fn(&portid, argv+2, argc-2)))
			IBERROR("operation %s: %s", argv[0], err);
	} else {
		char concat[64];

		memset(concat, 0, 64);
		snprintf(concat, sizeof(concat), "%s %s", argv[1], argv[2]);
		if (ib_resolve_portid_str(&portid, concat, dest_type, sm_id) < 0)
			IBERROR("can't resolve destination port %s", concat);
		if ((err = fn(&portid, argv+3, argc-3)))
			IBERROR("operation %s: %s", argv[0], err);
	}
	close_node_name_map(node_name_map);
	exit(0);
}
Exemple #7
0
int
main(int argc, char **argv)
{
	int mgmt_classes[3] = {IB_SMI_CLASS, IB_SMI_DIRECT_CLASS, IB_SA_CLASS};
	ib_portid_t portid = {0};
	ib_portid_t *sm_id = 0, sm_portid = {0};
	extern int ibdebug;
	int err;
	int timeout = 0, udebug = 0;
	char *ca = 0;
	int ca_port = 0;
	int port_op = 0;	/* default to query */
	int speed = 15;
	int is_switch = 1;
	int state, physstate, lwe, lws, lwa, lse, lss, lsa;
	int peerlocalportnum, peerlwe, peerlws, peerlwa, peerlse, peerlss, peerlsa;
	int width, peerwidth, peerspeed;
	uint8_t data[IB_SMP_DATA_SIZE];
	ib_portid_t peerportid = {0};
	int portnum = 0;
	ib_portid_t selfportid = {0};
	int selfport = 0;

	static char const str_opts[] = "C:P:t:s:devDGVhu";
	static const struct option long_opts[] = {
		{ "C", 1, 0, 'C'},
		{ "P", 1, 0, 'P'},
		{ "debug", 0, 0, 'd'},
		{ "err_show", 0, 0, 'e'},
		{ "verbose", 0, 0, 'v'},
		{ "Direct", 0, 0, 'D'},
		{ "Guid", 0, 0, 'G'},
		{ "timeout", 1, 0, 't'},
		{ "s", 1, 0, 's'},
		{ "Version", 0, 0, 'V'},
		{ "help", 0, 0, 'h'},
		{ "usage", 0, 0, 'u'},
		{ }
	};

	argv0 = argv[0];

	while (1) {
		int ch = getopt_long(argc, argv, str_opts, long_opts, NULL);
		if ( ch == -1 )
			break;
		switch(ch) {
		case 'd':
			ibdebug++;
			madrpc_show_errors(1);
			umad_debug(udebug);
			udebug++;
			break;
		case 'e':
			madrpc_show_errors(1);
			break;
		case 'D':
			dest_type = IB_DEST_DRPATH;
			break;
		case 'G':
			dest_type = IB_DEST_GUID;
			break;
		case 'C':
			ca = optarg;
			break;
		case 'P':
			ca_port = strtoul(optarg, 0, 0);
			break;
		case 's':
			if (ib_resolve_portid_str(&sm_portid, optarg, IB_DEST_LID, 0) < 0)
				IBERROR("can't resolve SM destination port %s", optarg);
			sm_id = &sm_portid;
			break;
		case 't':
			timeout = strtoul(optarg, 0, 0);
			madrpc_set_timeout(timeout);
			break;
		case 'v':
			verbose++;
			break;
		case 'V':
			fprintf(stderr, "%s %s\n", argv0, get_build_version() );
			exit(-1);
		default:
			usage();
			break;
		}
	}
	argc -= optind;
	argv += optind;

	if (argc < 2)
		usage();

	madrpc_init(ca, ca_port, mgmt_classes, 3);

	if (ib_resolve_portid_str(&portid, argv[0], dest_type, sm_id) < 0)
		IBERROR("can't resolve destination port %s", argv[0]);

	/* First, make sure it is a switch port if it is a "set" */
	if (argc >= 3) {
		if (!strcmp(argv[2], "enable"))
			port_op = 1;
		else if (!strcmp(argv[2], "disable"))
			port_op = 2;
		else if (!strcmp(argv[2], "reset"))
			port_op = 3;
		else if (!strcmp(argv[2], "speed")) {
			if (argc < 4)
				IBERROR("speed requires an additional parameter");
			port_op = 4;
			/* Parse speed value */
			speed = strtoul(argv[3], 0, 0);
			if (speed > 15)
				IBERROR("invalid speed value %d", speed);
		}
	}

	err = get_node_info(&portid, data);
	if (err < 0)
		IBERROR("smp query nodeinfo failed");
	if (err) {		/* not switch */
		if (port_op == 0)	/* query op */
			is_switch = 0;
		else if (port_op != 4)	/* other than speed op */
			IBERROR("smp query nodeinfo: Node type not switch");
	}

	if (argc-1 > 0)
		portnum = strtol(argv[1], 0, 0);

	if (port_op)
		printf("Initial PortInfo:\n");
	else
		printf("PortInfo:\n");
	err = get_port_info(&portid, data, portnum, port_op);
	if (err < 0)
		IBERROR("smp query portinfo failed");

	/* Only if one of the "set" options is chosen */
	if (port_op) {
		if (port_op == 1)		/* Enable port */
			mad_set_field(data, 0, IB_PORT_PHYS_STATE_F, 2);	/* Polling */
		else if ((port_op == 2) || (port_op == 3)) { /* Disable port */
			mad_set_field(data, 0, IB_PORT_STATE_F, 1);             /* Down */
			mad_set_field(data, 0, IB_PORT_PHYS_STATE_F, 3);        /* Disabled */
		} else if (port_op == 4) {	/* Set speed */
			mad_set_field(data, 0, IB_PORT_LINK_SPEED_ENABLED_F, speed);
			mad_set_field(data, 0, IB_PORT_STATE_F, 0);
			mad_set_field(data, 0, IB_PORT_PHYS_STATE_F, 0);
		}

		err = set_port_info(&portid, data, portnum, port_op);
		if (err < 0)
			IBERROR("smp set portinfo failed");

		if (port_op == 3) {	/* Reset port - so also enable */
			mad_set_field(data, 0, IB_PORT_PHYS_STATE_F, 2);	/* Polling */
			err = set_port_info(&portid, data, portnum, port_op);
			if (err < 0)
				IBERROR("smp set portinfo failed");
		}
	} else {	/* query op */
		/* only compare peer port if switch port */
		if (is_switch) {
			/* First, exclude SP0 */
			if (portnum) {
				/* Now, make sure PortState is Active */
				/* Or is PortPhysicalState LinkUp sufficient ? */
				mad_decode_field(data, IB_PORT_STATE_F, &state);
				mad_decode_field(data, IB_PORT_PHYS_STATE_F, &physstate);
				if (state == 4) {	/* Active */
					mad_decode_field(data, IB_PORT_LINK_WIDTH_ENABLED_F, &lwe );
					mad_decode_field(data, IB_PORT_LINK_WIDTH_SUPPORTED_F, &lws);
					mad_decode_field(data, IB_PORT_LINK_WIDTH_ACTIVE_F, &lwa);
					mad_decode_field(data, IB_PORT_LINK_SPEED_SUPPORTED_F, &lss);
					mad_decode_field(data, IB_PORT_LINK_SPEED_ACTIVE_F, &lsa);
					mad_decode_field(data, IB_PORT_LINK_SPEED_ENABLED_F, &lse);

					/* Setup portid for peer port */
					memcpy(&peerportid, &portid, sizeof(peerportid));
					peerportid.drpath.cnt = 1;
					peerportid.drpath.p[1] = portnum;

					/* Set DrSLID to local lid */
					if (ib_resolve_self(&selfportid, &selfport, 0) < 0)
						IBERROR("could not resolve self");
					peerportid.drpath.drslid = selfportid.lid;
					peerportid.drpath.drdlid = 0xffff;

					/* Get peer port NodeInfo to obtain peer port number */
					err = get_node_info(&peerportid, data);
					if (err < 0)
						IBERROR("smp query nodeinfo failed");

					mad_decode_field(data, IB_NODE_LOCAL_PORT_F, &peerlocalportnum);

					printf("Peer PortInfo:\n");
					/* Get peer port characteristics */
					err = get_port_info(&peerportid, data, peerlocalportnum, port_op);
					if (err < 0)
						IBERROR("smp query peer portinfofailed");

					mad_decode_field(data, IB_PORT_LINK_WIDTH_ENABLED_F, &peerlwe );
					mad_decode_field(data, IB_PORT_LINK_WIDTH_SUPPORTED_F, &peerlws);
					mad_decode_field(data, IB_PORT_LINK_WIDTH_ACTIVE_F, &peerlwa);
					mad_decode_field(data, IB_PORT_LINK_SPEED_SUPPORTED_F, &peerlss);
					mad_decode_field(data, IB_PORT_LINK_SPEED_ACTIVE_F, &peerlsa);
					mad_decode_field(data, IB_PORT_LINK_SPEED_ENABLED_F, &peerlse);

					/* Now validate peer port characteristics */
					/* Examine Link Width */
					width = get_link_width(lwe, lws);
					peerwidth = get_link_width(peerlwe, peerlws);
					validate_width(width, peerwidth, lwa);

					/* Examine Link Speed */
					speed = get_link_speed(lse, lss);
					peerspeed = get_link_speed(peerlse, peerlss);
					validate_speed(speed, peerspeed, lsa);
				}
			}
		}
	}

	exit(0);
}