コード例 #1
0
static char *
node_desc(ib_portid_t *dest, char **argv, int argc)
{
	int       node_type, l;
	uint64_t  node_guid;
	char      nd[IB_SMP_DATA_SIZE];
	uint8_t   data[IB_SMP_DATA_SIZE];
	char      dots[128];
	char     *nodename = NULL;

	if (!smp_query(data, dest, IB_ATTR_NODE_INFO, 0, 0))
		return "node info query failed";

	mad_decode_field(data, IB_NODE_TYPE_F, &node_type);
	mad_decode_field(data, IB_NODE_GUID_F, &node_guid);

	if (!smp_query(nd, dest, IB_ATTR_NODE_DESC, 0, 0))
		return "node desc query failed";

	nodename = remap_node_name(node_name_map, node_guid, nd);

	l = strlen(nodename);
	if (l < 32) {
		memset(dots, '.', 32 - l);
		dots[32 - l] = '\0';
	} else {
		dots[0] = '.';
		dots[1] = '\0';
	}

	printf("Node Description:%s%s\n", dots, nodename);
	free(nodename);
	return 0;
}
コード例 #2
0
char *
check_switch(ib_portid_t *portid, int *nports, uint64_t *guid,
	     uint8_t *sw, char *nd)
{
	uint8_t ni[IB_SMP_DATA_SIZE] = {0};
	int type;

	DEBUG("checking node type");
	if (!smp_query(ni, portid, IB_ATTR_NODE_INFO, 0, 0)) {
		xdump(stderr, "nodeinfo\n", ni, sizeof ni);
		return "node info failed: valid addr?";
	}

	if (!smp_query(nd, portid, IB_ATTR_NODE_DESC, 0, 0))
		return "node desc failed";

	mad_decode_field(ni, IB_NODE_TYPE_F, &type);
	if (type != IB_NODE_SWITCH)
		return "not a switch";

	DEBUG("Gathering information about switch");
	mad_decode_field(ni, IB_NODE_NPORTS_F, nports);
	mad_decode_field(ni, IB_NODE_GUID_F, guid);

	if (!smp_query(sw, portid, IB_ATTR_SWITCH_INFO, 0, 0))
		return "switch info failed: is a switch node?";

	return 0;
}
コード例 #3
0
static char *
guid_info(ib_portid_t *dest, char **argv, int argc)
{
	uint8_t data[IB_SMP_DATA_SIZE];
	uint32_t i, j, k;
	uint64_t *p;
	unsigned mod;
	int n;

	/* Get the guid capacity */
	if (!smp_query(data, dest, IB_ATTR_PORT_INFO, 0, 0))
		return "port info failed";
	mad_decode_field(data, IB_PORT_GUID_CAP_F, &n);

	for (i = 0; i < (n + 7) / 8; i++) {
		mod =  i;
		if (!smp_query(data, dest, IB_ATTR_GUID_INFO, mod, 0))
			return "guid info query failed";
		if (i + 1 == (n + 7) / 8)
			k = ((n + 1 - i * 8) / 2) * 2;
		else
			k = 8;
		p = (uint64_t *) data;
		for (j = 0; j < k; j += 2, p += 2) {
			printf("%4u: 0x%016"PRIx64" 0x%016"PRIx64"\n",
				(i * 8) + j,
				ntohll(p[0]), ntohll(p[1]));
		}
	}
	printf("%d guids capacity for this port\n", n);

	return 0;
}
コード例 #4
0
static char *
pkey_table(ib_portid_t *dest, char **argv, int argc)
{
	uint8_t data[IB_SMP_DATA_SIZE];
	uint32_t i, j, k;
	uint16_t *p;
	unsigned mod;
	int n, t, phy_ports;
	int portnum = 0;

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

	/* Get the partition capacity */
	if (!smp_query(data, dest, IB_ATTR_NODE_INFO, 0, 0))
		return "node info query failed";

	mad_decode_field(data, IB_NODE_TYPE_F, &t);
	mad_decode_field(data, IB_NODE_NPORTS_F, &phy_ports);
	if (portnum > phy_ports)
		return "invalid port number";

	if ((t == IB_NODE_SWITCH) && (portnum != 0)) {
		if (!smp_query(data, dest, IB_ATTR_SWITCH_INFO, 0, 0))
			return "switch info failed";
		mad_decode_field(data, IB_SW_PARTITION_ENFORCE_CAP_F, &n);
	} else
		mad_decode_field(data, IB_NODE_PARTITION_CAP_F, &n);

	for (i = 0; i < (n + 31) / 32; i++) {
		mod =  i | (portnum << 16);
		if (!smp_query(data, dest, IB_ATTR_PKEY_TBL, mod, 0))
			return "pkey table query failed";
		if (i + 1 == (n + 31) / 32)
			k = ((n + 7 - i * 32) / 8) * 8;
		else
			k = 32;
		p = (uint16_t *) data;
		for (j = 0; j < k; j += 8, p += 8) {
			printf("%4u: 0x%04x 0x%04x 0x%04x 0x%04x 0x%04x 0x%04x 0x%04x 0x%04x\n",
				(i * 32) + j,
				ntohs(p[0]), ntohs(p[1]),
				ntohs(p[2]), ntohs(p[3]),
				ntohs(p[4]), ntohs(p[5]),
				ntohs(p[6]), ntohs(p[7]));
		}
	}
	printf("%d pkeys capacity for this port\n", n);

	return 0;
}
コード例 #5
0
ファイル: ibnetdiscover.c プロジェクト: 2014-class/freerouter
/*
 * Returns 0 if non switch node is found, 1 if switch is found, -1 if error.
 */
int
get_node(Node *node, Port *port, ib_portid_t *portid)
{
	char portinfo[64];
	char switchinfo[64];
	void *pi = portinfo, *ni = node->nodeinfo, *nd = node->nodedesc;
	void *si = switchinfo;

	if (!smp_query(ni, portid, IB_ATTR_NODE_INFO, 0, timeout))
		return -1;

	mad_decode_field(ni, IB_NODE_GUID_F, &node->nodeguid);
	mad_decode_field(ni, IB_NODE_TYPE_F, &node->type);
	mad_decode_field(ni, IB_NODE_NPORTS_F, &node->numports);
	mad_decode_field(ni, IB_NODE_DEVID_F, &node->devid);
	mad_decode_field(ni, IB_NODE_VENDORID_F, &node->vendid);
	mad_decode_field(ni, IB_NODE_SYSTEM_GUID_F, &node->sysimgguid);
	mad_decode_field(ni, IB_NODE_PORT_GUID_F, &node->portguid);
	mad_decode_field(ni, IB_NODE_LOCAL_PORT_F, &node->localport);
	port->portnum = node->localport;
	port->portguid = node->portguid;

	if (!smp_query(nd, portid, IB_ATTR_NODE_DESC, 0, timeout))
		return -1;

	if (!smp_query(pi, portid, IB_ATTR_PORT_INFO, 0, timeout))
		return -1;
	decode_port_info(pi, port);

	if (node->type != SWITCH_NODE)
		return 0;

	node->smalid = port->lid;
	node->smalmc = port->lmc;

	/* after we have the sma information find out the real PortInfo for this port */
	if (!smp_query(pi, portid, IB_ATTR_PORT_INFO, node->localport, timeout))
	        return -1;
	decode_port_info(pi, port);

        if (!smp_query(si, portid, IB_ATTR_SWITCH_INFO, 0, timeout))
                node->smaenhsp0 = 0;	/* assume base SP0 */
	else
        	mad_decode_field(si, IB_SW_ENHANCED_PORT0_F, &node->smaenhsp0);

	DEBUG("portid %s: got switch node %" PRIx64 " '%s'",
	      portid2str(portid), node->nodeguid, node->nodedesc);
	return 1;
}
コード例 #6
0
static char *
sl2vl_table(ib_portid_t *dest, char **argv, int argc)
{
	uint8_t data[IB_SMP_DATA_SIZE];
	int type, num_ports, portnum = 0;
	int i;
	char *ret;

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

	if (!smp_query(data, dest, IB_ATTR_NODE_INFO, 0, 0))
		return "node info query failed";

	mad_decode_field(data, IB_NODE_TYPE_F, &type);
	mad_decode_field(data, IB_NODE_NPORTS_F, &num_ports);
	if (portnum > num_ports)
		return "invalid port number";

	printf("# SL2VL table: %s\n", portid2str(dest));
	printf("#                 SL: |");
	for (i = 0 ; i < 16 ; i++)
		printf("%2d|", i);
	printf("\n");

	if (type != IB_NODE_SWITCH)
		return sl2vl_dump_table_entry(dest, 0, 0);

	for (i = 0 ; i <= num_ports ; i++) {
		ret = sl2vl_dump_table_entry(dest, i, portnum);
		if (ret)
			return ret;
	}
	return 0;
}
コード例 #7
0
char *
dump_unicast_tables(ib_portid_t *portid, int startlid, int endlid)
{
	char lft[IB_SMP_DATA_SIZE];
	char nd[IB_SMP_DATA_SIZE];
	uint8_t sw[IB_SMP_DATA_SIZE];
	char str[200], *s;
	uint64_t nodeguid;
	int block, i, e, nports, top;
	int n = 0, startblock, endblock;

	if ((s = check_switch(portid, &nports, &nodeguid, sw, nd)))
		return s;

	mad_decode_field(sw, IB_SW_LINEAR_FDB_TOP_F, &top);

	if (!endlid || endlid > top)
		endlid = top;

	if (endlid > IB_MAX_UCAST_LID) {
		IBWARN("ilegal lft top %d, truncate to %d", endlid, IB_MAX_UCAST_LID);
		endlid = IB_MAX_UCAST_LID;
	}

	printf("Unicast lids [0x%x-0x%x] of switch %s guid 0x%016" PRIx64 " (%s):\n",
		startlid, endlid, portid2str(portid), nodeguid, clean_nodedesc(nd));

	DEBUG("Switch top is 0x%x\n", top);

	printf("  Lid  Out   Destination\n");
	printf("       Port     Info \n");
	startblock = startlid / IB_SMP_DATA_SIZE;
	endblock = ALIGN(endlid, IB_SMP_DATA_SIZE) / IB_SMP_DATA_SIZE;
	for (block = startblock; block <= endblock; block++) {
		DEBUG("reading block %d", block);
		if (!smp_query(lft, portid, IB_ATTR_LINEARFORWTBL, block, 0))
			return "linear forwarding table get failed";
		i = block * IB_SMP_DATA_SIZE;
		e = i + IB_SMP_DATA_SIZE;
		if (i < startlid)
			i = startlid;
		if (e > endlid + 1)
			e = endlid + 1;

		for (;i < e; i++) {
			unsigned outport = lft[i % IB_SMP_DATA_SIZE];
			unsigned valid = (outport <= nports);

			if (!valid && !dump_all)
				continue;
			dump_lid(str, sizeof str, i, valid);
			printf("0x%04x %03u %s\n", i, outport & 0xff, str);
			n++;
		}
	}

	printf("%d %slids dumped \n", n, dump_all ? "" : "valid ");
	return 0;
}
コード例 #8
0
static char *
vlarb_table(ib_portid_t *dest, char **argv, int argc)
{
	uint8_t data[IB_SMP_DATA_SIZE];
	int portnum = 0;
	int type, enhsp0, lowcap, highcap;
	char *ret = 0;

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

	/* port number of 0 could mean SP0 or port MAD arrives on */
	if (portnum == 0) {
		if (!smp_query(data, dest, IB_ATTR_NODE_INFO, 0, 0))
			return "node info query failed";

		mad_decode_field(data, IB_NODE_TYPE_F, &type);
		if (type == IB_NODE_SWITCH) {
			if (!smp_query(data, dest, IB_ATTR_SWITCH_INFO, 0, 0))
				return "switch info query failed";
			mad_decode_field(data, IB_SW_ENHANCED_PORT0_F, &enhsp0);
			if (!enhsp0) {
				printf("# No VLArbitration tables (BSP0): %s port %d\n",
                        		portid2str(dest), 0);
				return 0;
			}
		}
	}

	if (!smp_query(data, dest, IB_ATTR_PORT_INFO, portnum, 0))
		return "port info query failed";

	mad_decode_field(data, IB_PORT_VL_ARBITRATION_LOW_CAP_F, &lowcap);
	mad_decode_field(data, IB_PORT_VL_ARBITRATION_HIGH_CAP_F,&highcap);

	printf("# VLArbitration tables: %s port %d LowCap %d HighCap %d\n",
			portid2str(dest), portnum, lowcap, highcap);

	if (lowcap > 0)
		ret = vlarb_dump_table(dest, portnum, "Low", 1, lowcap);

	if (!ret && highcap > 0)
		ret = vlarb_dump_table(dest, portnum, "High", 3, highcap);

	return ret;
}
コード例 #9
0
static char *vlarb_dump_table_entry(ib_portid_t *dest, int portnum, int offset, unsigned cap)
{
	char buf[2048];
	char data[IB_SMP_DATA_SIZE];

	if (!smp_query(data, dest, IB_ATTR_VL_ARBITRATION,
			(offset << 16) | portnum, 0))
		return "vl arb query failed";
	mad_dump_vlarbitration(buf, sizeof(buf), data, cap * 2);
	printf("%s", buf);
	return 0;
}
コード例 #10
0
static int
get_node_info(ib_portid_t *dest, uint8_t *data)
{
	int node_type;

	if (!smp_query(data, dest, IB_ATTR_NODE_INFO, 0, 0))
		return -1;

	node_type = mad_get_field(data, 0, IB_NODE_TYPE_F);
	if (node_type == IB_NODE_SWITCH)	/* Switch NodeType ? */
		return 0;
	else
		return 1;
}
コード例 #11
0
static char *
switch_info(ib_portid_t *dest, char **argv, int argc)
{
	char buf[2048];
	char data[IB_SMP_DATA_SIZE];

	if (!smp_query(data, dest, IB_ATTR_SWITCH_INFO, 0, 0))
		return "switch info query failed";

	mad_dump_switchinfo(buf, sizeof buf, data, sizeof data);

	printf("# Switch info: %s\n%s", portid2str(dest), buf);
	return 0;
}
コード例 #12
0
static char *sl2vl_dump_table_entry(ib_portid_t *dest, int in, int out)
{
	char buf[2048];
	char data[IB_SMP_DATA_SIZE];
	int portnum = (in << 8) | out;

	if (!smp_query(data, dest, IB_ATTR_SLVL_TABLE, portnum, 0))
		return "slvl query failed";

	mad_dump_sltovl(buf, sizeof buf, data, sizeof data);
	printf("ports: in %2d, out %2d: ", in, out);
	printf("%s", buf);
	return 0;
}
コード例 #13
0
static int
ib_resolve_addr(ib_portid_t *portid, int portnum, int show_lid, int show_gid)
{
	char   gid_str[INET6_ADDRSTRLEN];
	uint8_t portinfo[64];
	uint8_t nodeinfo[64];
	uint64_t guid, prefix;
	ibmad_gid_t gid;
	int lmc;

	if (!smp_query(nodeinfo, portid, IB_ATTR_NODE_INFO, 0, 0))
		return -1;

	if (!smp_query(portinfo, portid, IB_ATTR_PORT_INFO, portnum, 0))
		return -1;

	mad_decode_field(portinfo, IB_PORT_LID_F, &portid->lid);
	mad_decode_field(portinfo, IB_PORT_GID_PREFIX_F, &prefix);
	mad_decode_field(portinfo, IB_PORT_LMC_F, &lmc);
	mad_decode_field(nodeinfo, IB_NODE_PORT_GUID_F, &guid);

	mad_encode_field(gid, IB_GID_PREFIX_F, &prefix);
	mad_encode_field(gid, IB_GID_GUID_F, &guid);

	if (show_gid) {
		printf("GID %s ", inet_ntop(AF_INET6, gid, gid_str,
			sizeof gid_str));
	}

	if (show_lid > 0)
		printf("LID start 0x%x end 0x%x", portid->lid, portid->lid + (1 << lmc) - 1);
	else if (show_lid < 0)
		printf("LID start %d end %d", portid->lid, portid->lid + (1 << lmc) - 1);
	printf("\n");
	return 0;
}
コード例 #14
0
ファイル: ibnetdiscover.c プロジェクト: 2014-class/freerouter
int
get_port(Port *port, int portnum, ib_portid_t *portid)
{
	char portinfo[64];
	void *pi = portinfo;

	port->portnum = portnum;

	if (!smp_query(pi, portid, IB_ATTR_PORT_INFO, portnum, timeout))
		return -1;
	decode_port_info(pi, port);

	DEBUG("portid %s portnum %d: lid %d state %d physstate %d %s %s",
		portid2str(portid), portnum, port->lid, port->state, port->physstate, get_linkwidth_str(port->linkwidth), get_linkspeed_str(port->linkspeed));
	return 1;
}
コード例 #15
0
static char *
port_info(ib_portid_t *dest, char **argv, int argc)
{
	char buf[2048];
	char data[IB_SMP_DATA_SIZE];
	int portnum = 0;

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

	if (!smp_query(data, dest, IB_ATTR_PORT_INFO, portnum, 0))
		return "port info query failed";

	mad_dump_portinfo(buf, sizeof buf, data, sizeof data);

	printf("# Port info: %s port %d\n%s", portid2str(dest), portnum, buf);
	return 0;
}
コード例 #16
0
static int
get_port_info(ib_portid_t *dest, uint8_t *data, int portnum, int port_op)
{
	char buf[2048];
	char val[64];

	if (!smp_query(data, dest, IB_ATTR_PORT_INFO, portnum, 0))
		return -1;

	if (port_op != 4) {
		mad_dump_portstates(buf, sizeof buf, data, sizeof data);
		mad_decode_field(data, IB_PORT_LINK_WIDTH_SUPPORTED_F, val);
		mad_dump_field(IB_PORT_LINK_WIDTH_SUPPORTED_F, buf + strlen(buf), sizeof buf - strlen(buf), val);
		sprintf(buf+strlen(buf), "%s", "\n");
		mad_decode_field(data, IB_PORT_LINK_WIDTH_ENABLED_F, val);
		mad_dump_field(IB_PORT_LINK_WIDTH_ENABLED_F, buf + strlen(buf), sizeof buf - strlen(buf), val);
		sprintf(buf+strlen(buf), "%s", "\n");
		mad_decode_field(data, IB_PORT_LINK_WIDTH_ACTIVE_F, val);
		mad_dump_field(IB_PORT_LINK_WIDTH_ACTIVE_F, buf + strlen(buf), sizeof buf - strlen(buf), val);
		sprintf(buf+strlen(buf), "%s", "\n");
		mad_decode_field(data, IB_PORT_LINK_SPEED_SUPPORTED_F, val);
		mad_dump_field(IB_PORT_LINK_SPEED_SUPPORTED_F, buf + strlen(buf), sizeof buf - strlen(buf), val);
		sprintf(buf+strlen(buf), "%s", "\n");
		mad_decode_field(data, IB_PORT_LINK_SPEED_ENABLED_F, val);
		mad_dump_field(IB_PORT_LINK_SPEED_ENABLED_F, buf + strlen(buf), sizeof buf - strlen(buf), val);
		sprintf(buf+strlen(buf), "%s", "\n");
		mad_decode_field(data, IB_PORT_LINK_SPEED_ACTIVE_F, val);
		mad_dump_field(IB_PORT_LINK_SPEED_ACTIVE_F, buf + strlen(buf), sizeof buf - strlen(buf), val);
		sprintf(buf+strlen(buf), "%s", "\n");
	} else {
		mad_decode_field(data, IB_PORT_LINK_SPEED_ENABLED_F, val);
		mad_dump_field(IB_PORT_LINK_SPEED_ENABLED_F, buf, sizeof buf, val);
		sprintf(buf+strlen(buf), "%s", "\n");
	}

	printf("# Port info: %s port %d\n%s", portid2str(dest), portnum, buf);
	return 0;
}
コード例 #17
0
int
dump_lid(char *str, int strlen, int lid, int valid)
{
	char nd[IB_SMP_DATA_SIZE] = {0};
	uint8_t ni[IB_SMP_DATA_SIZE] = {0};
	uint8_t pi[IB_SMP_DATA_SIZE] = {0};
	ib_portid_t lidport = {0};
	static int last_port_lid, base_port_lid;
	char ntype[50], sguid[30], desc[64];
	static uint64_t portguid;
	int baselid, lmc, type;

	if (brief) {
		str[0] = 0;
		return 0;
	}

	if (lid <= last_port_lid) {
		if (!valid)
			return snprintf(str, strlen, ": (path #%d - illegal port)",
					lid - base_port_lid);
		else if (!portguid)
			return snprintf(str, strlen,
					": (path #%d out of %d)",
					lid - base_port_lid + 1,
					last_port_lid - base_port_lid + 1);
		else {
			return snprintf(str, strlen,
					": (path #%d out of %d: portguid %s)",
					lid - base_port_lid + 1,
					last_port_lid - base_port_lid + 1,
					mad_dump_val(IB_NODE_PORT_GUID_F, sguid, sizeof sguid, &portguid));
		}
	}

	if (!valid)
		return snprintf(str, strlen, ": (illegal port)");

	portguid = 0;
	lidport.lid = lid;

	if (!smp_query(nd, &lidport, IB_ATTR_NODE_DESC, 0, 100) ||
	    !smp_query(pi, &lidport, IB_ATTR_PORT_INFO, 0, 100) ||
	    !smp_query(ni, &lidport, IB_ATTR_NODE_INFO, 0, 100))
		return snprintf(str, strlen, ": (unknown node and type)");

	mad_decode_field(ni, IB_NODE_PORT_GUID_F, &portguid);
	mad_decode_field(ni, IB_NODE_TYPE_F, &type);

	mad_decode_field(pi, IB_PORT_LID_F, &baselid);
	mad_decode_field(pi, IB_PORT_LMC_F, &lmc);

	if (lmc > 0) {
		base_port_lid = baselid;
		last_port_lid = baselid + (1 << lmc) - 1;
	}

	return snprintf(str, strlen, ": (%s portguid %s: %s)",
		mad_dump_val(IB_NODE_TYPE_F, ntype, sizeof ntype, &type),
		mad_dump_val(IB_NODE_PORT_GUID_F, sguid, sizeof sguid, &portguid),
		mad_dump_val(IB_NODE_DESC_F, desc, sizeof desc, clean_nodedesc(nd)));
}
コード例 #18
0
char *
dump_multicast_tables(ib_portid_t *portid, int startlid, int endlid)
{
	char nd[IB_SMP_DATA_SIZE] = {0};
	uint8_t sw[IB_SMP_DATA_SIZE] = {0};
	char str[512];
	char *s;
	uint64_t nodeguid;
	uint32_t mod;
	int block, i, j, e, nports, cap, chunks;
	int n = 0, startblock, lastblock;

	if ((s = check_switch(portid, &nports, &nodeguid, sw, nd)))
		return s;

	mad_decode_field(sw, IB_SW_MCAST_FDB_CAP_F, &cap);

	if (!endlid || endlid > IB_MIN_MCAST_LID + cap - 1)
		endlid = IB_MIN_MCAST_LID + cap - 1;

	if (!startlid)
		startlid = IB_MIN_MCAST_LID;

	if (startlid < IB_MIN_MCAST_LID) {
		IBWARN("illegal start mlid %x, set to %x", startlid, IB_MIN_MCAST_LID);
		startlid = IB_MIN_MCAST_LID;
	}

	if (endlid > IB_MAX_MCAST_LID) {
		IBWARN("illegal end mlid %x, truncate to %x", endlid, IB_MAX_MCAST_LID);
		endlid = IB_MAX_MCAST_LID;
	}

	printf("Multicast mlids [0x%x-0x%x] of switch %s guid 0x%016" PRIx64 " (%s):\n",
		startlid, endlid, portid2str(portid), nodeguid, clean_nodedesc(nd));

	if (brief)
		printf(" MLid       Port Mask\n");
	else {
		if (nports > 9) {
			for (i = 0, s = str; i <= nports; i++) {
				*s++ = (i%10) ? ' ' : '0' + i/10;
				*s++ = ' ';
			}
			*s = 0;
			printf("            %s\n", str);
		}
		for (i = 0, s = str; i <= nports; i++)
			s += sprintf(s, "%d ", i%10);
		printf("     Ports: %s\n", str);
		printf(" MLid\n");
	}
	if (verbose)
		printf("Switch muticast mlids capability is 0x%d\n", cap);

	chunks = ALIGN(nports + 1, 16) / 16;

	startblock = startlid / IB_MLIDS_IN_BLOCK;
	lastblock = endlid / IB_MLIDS_IN_BLOCK;
	for (block = startblock; block <= lastblock; block++) {
		for (j = 0; j < chunks; j++) {
			mod = (block - IB_MIN_MCAST_LID/IB_MLIDS_IN_BLOCK) | (j << 28);

			DEBUG("reading block %x chunk %d mod %x", block, j, mod);
			if (!smp_query(mft + j, portid, IB_ATTR_MULTICASTFORWTBL, mod, 0))
				return "multicast forwarding table get failed";
		}

		i = block * IB_MLIDS_IN_BLOCK;
		e = i + IB_MLIDS_IN_BLOCK;
		if (i < startlid)
			i = startlid;
		if (e > endlid + 1)
			e = endlid + 1;

		for (; i < e; i++) {
			if (dump_mlid(str, sizeof str, i, nports, mft) == 0)
				continue;
			printf("0x%04x      %s\n", i, str);
			n++;
		}
	}

	printf("%d %smlids dumped \n", n, dump_all ? "" : "valid ");
	return 0;
}
コード例 #19
0
ファイル: perfquery.c プロジェクト: 2014-class/freerouter
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);
}