int main(int argc, char **argv) { int mgmt_classes[2] = { IB_SMI_CLASS, IB_SMI_DIRECT_CLASS }; int ch = 0; char *trap_name = NULL; char *ca = NULL; int ca_port = 0; 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': ca = optarg; break; case 'P': ca_port = 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(ca, ca_port, mgmt_classes, 2); return (send_trap(trap_name)); }
static IDX_T add_log( fs_handle_type file, LOG_HEADER_T* head, const char* msg ) { UINT32 idx = head->free_head_; UINT32 pos, msg_size, ver_size, size; int res; enum { DATE_SIZE = 16 }; // "20080810 113000 " >> 20bytes TMR_DATE_T date; char date_buf[ DATE_SIZE + 1 ]; if( idx == NULL_IDX ) { return NULL_IDX; } head->free_head_ = head->next_[ idx ]; if( head->count_ == 0 ) { head->head_ = idx; } else { head->next_[ head->tail_ ] = idx; } head->count_++; head->prev_[ idx ] = head->tail_; head->next_[ idx ] = NULL_IDX; head->tail_ = idx; pos = head->first_log_pos_ + idx * ( 82 + 46 + 82 + LOG_SIZE + 2 + 2 ); // 현재 시각 정보 size = DATE_SIZE; tmr_GetDate( tmr_GetLocalTime(), &date ); msg_size = sprintf( date_buf, "%4d%02d%02d %02d%02d%02d ", date.year, date.month, date.day, date.hour, date.minute, date.second ); if(msg_size >= (DATE_SIZE+1)) { return NULL_IDX; } pantech_fseek( file, SEEK_SET, pos); res = pantech_fwrite( file, date_buf, DATE_SIZE ); if( res != DATE_SIZE ) { return NULL_IDX; } // Build Version ver_size = strlen( get_build_version() ); size += ver_size; res = pantech_fwrite( file, (char*)get_build_version(), ver_size ); if( res != ver_size ) { return NULL_IDX; } // \r\n 삽입 : 로그발생 시각, 버전명과 로그 내용을 구분하기위해 size += 2; res = pantech_fwrite( file, "\r\n", 2 ); if( res != 2 ) { return NULL_IDX; } // Msg msg_size = strlen( msg ); if( msg_size > LOG_SIZE - size ) { msg_size = LOG_SIZE - size; } size += msg_size; res = pantech_fwrite( file, (char*)msg, msg_size ); if( res != msg_size ) { return NULL_IDX; } // 나머지 부분 공백으로 padding res = pantech_fwrite( file, g_blank_buf + size, LOG_SIZE + 2 - size ); if( res != LOG_SIZE + 2 - size ) { return NULL_IDX; } return idx; }
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); }
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}; int timeout; int multicast = 0, startlid = 0, endlid = 0; char *err; char *ca = 0; int ca_port = 0; static char const str_opts[] = "C:P:t:s:danvDGMVhu"; static const struct option long_opts[] = { { "C", 1, 0, 'C'}, { "P", 1, 0, 'P'}, { "debug", 0, 0, 'd'}, { "all", 0, 0, 'a'}, { "no_dests", 0, 0, 'n'}, { "verbose", 0, 0, 'v'}, { "Direct", 0, 0, 'D'}, { "Guid", 0, 0, 'G'}, { "Multicast", 0, 0, 'M'}, { "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 'C': ca = optarg; break; case 'P': ca_port = strtoul(optarg, 0, 0); break; case 'a': dump_all++; break; case 'd': ibdebug++; break; case 'D': dest_type = IB_DEST_DRPATH; break; case 'G': dest_type = IB_DEST_GUID; break; case 'M': multicast++; break; case 'n': brief++; 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': madrpc_show_errors(1); verbose++; break; case 'V': fprintf(stderr, "%s %s\n", argv0, get_build_version() ); exit(-1); default: usage(); break; } } argc -= optind; argv += optind; if (!argc) usage(); if (argc > 1) startlid = strtoul(argv[1], 0, 0); if (argc > 2) endlid = strtoul(argv[2], 0, 0); madrpc_init(ca, ca_port, mgmt_classes, 3); if (!argc) { if (ib_resolve_self(&portid, 0, 0) < 0) IBERROR("can't resolve self addr"); } else { if (ib_resolve_portid_str(&portid, argv[0], dest_type, sm_id) < 0) IBERROR("can't resolve destination port %s", argv[1]); } if (multicast) err = dump_multicast_tables(&portid, startlid, endlid); else err = dump_unicast_tables(&portid, startlid, endlid); if (err) IBERROR("dump tables: %s", err); exit(0); }
int main(int argc, char *argv[]) { char names[UMAD_MAX_DEVICES][UMAD_CA_NAME_LEN]; int dev_port = -1; int list_only = 0, short_format = 0, list_ports = 0; int n, i; static char const str_opts[] = "dlspVhu"; static const struct option long_opts[] = { { "debug", 0, 0, 'd'}, { "list_of_cas", 0, 0, 'l'}, { "short", 0, 0, 's'}, { "port_list", 0, 0, 'p'}, { "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': debug++; break; case 'l': list_only++; break; case 's': short_format++; break; case 'p': list_ports++; break; case 'V': fprintf(stderr, "%s %s\n", argv0, get_build_version() ); exit(-1); default: usage(); break; } } argc -= optind; argv += optind; if (argc > 1) dev_port = strtol(argv[1], 0, 0); if (umad_init() < 0) IBPANIC("can't init UMAD library"); if ((n = umad_get_cas_names(names, UMAD_MAX_DEVICES)) < 0) IBPANIC("can't list IB device names"); if (argc) { for (i = 0; i < n; i++) if (!strncmp(names[i], argv[0], sizeof names[i])) break; if (i >= n) IBPANIC("'%s' IB device can't be found", argv[0]); strncpy(names[i], argv[0], sizeof names[i]); n = 1; } if (list_ports) { if (ports_list(names, n) < 0) IBPANIC("can't list ports"); return 0; } if (!list_only && argc) { if (ca_stat(argv[0], dev_port, short_format) < 0) IBPANIC("stat of IB device '%s' failed", argv[0]); return 0; } for (i = 0; i < n; i++) { if (list_only) printf("%s\n", names[i]); else if (ca_stat(names[i], -1, short_format) < 0) IBPANIC("stat of IB device '%s' failed", names[i]); } return 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); }
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; }
int main(int argc, char **argv) { int mgmt_classes[3] = {IB_SMI_CLASS, IB_SMI_DIRECT_CLASS, IB_SA_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 show_lid = 0, show_gid = 0; int port = 0; char *ca = 0; int ca_port = 0; static char const str_opts[] = "C:P:t:s:dDGglLVhu"; static const struct option long_opts[] = { { "C", 1, 0, 'C'}, { "P", 1, 0, 'P'}, { "debug", 0, 0, 'd'}, { "Direct", 0, 0, 'D'}, { "Guid", 0, 0, 'G'}, { "gid_show", 0, 0, 'g'}, { "lid_show", 0, 0, 'l'}, { "Lid_show", 0, 0, 'L'}, { "timeout", 1, 0, 't'}, { "sm_port", 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 'C': ca = optarg; break; case 'P': ca_port = strtoul(optarg, 0, 0); break; case 'd': ibdebug++; break; case 'D': dest_type = IB_DEST_DRPATH; break; case 'g': show_gid++; break; case 'G': dest_type = IB_DEST_GUID; break; case 'l': show_lid++; break; case 'L': show_lid = -100; 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); if (!show_lid && !show_gid) show_lid = show_gid = 1; madrpc_init(ca, ca_port, mgmt_classes, 3); 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]); } if (ib_resolve_addr(&portid, port, show_lid, show_gid) < 0) IBERROR("can't resolve requested address"); exit(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); }
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); }
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); }