static void setup(char *CA, SInt16 port, int *fd, int *agent) { umad_init(); *fd = umad_open_port(CA, port); if (UNLIKELY((*fd) < 0)) { FATAL("umad_open_port() failed with error %d: %s", -(*fd), strerror(-(*fd))); } #define MGMT_VERSION MAD_HEADER_CLASS_VERSION_SA #define RMPP_VERSION 1 *agent = umad_register((*fd), IB_SA_CLASS, MGMT_VERSION, RMPP_VERSION, NULL); if (UNLIKELY((*agent) < 0)) { FATAL("umad_register() failed with error %d: %s", -(*agent), strerror(-(*agent))); } }
int main(int argc, char **argv) { char *guid_file = "port_guids.list"; int mgmt_classes[2] = { IB_SMI_CLASS, IB_SMI_DIRECT_CLASS }; ib_portid_t dport_id; int port, agent; uint8_t *umad; int len; if (argc > 1) guid_file = argv[1]; srcport = mad_rpc_open_port(NULL, 0, mgmt_classes, 2); if (!srcport) err("Failed to open port"); resolve_sm_portid(NULL, 0, &dport_id); dport_id.qp = 1; if (!dport_id.qkey) dport_id.qkey = IB_DEFAULT_QP1_QKEY; len = umad_size() + 256; umad = calloc(1, len); if (!umad) { err("cannot alloc mem for umad: %s\n", strerror(errno)); return -1; } port = mad_rpc_portid(srcport); agent = umad_register(port, IB_SA_CLASS, 2, 0, NULL); rereg_and_test_port(guid_file, port, agent, &dport_id, TMO); free(umad); umad_unregister(port, agent); umad_close_port(port); umad_done(); return 0; }
/****************************************************************************** * join_multicast_group ******************************************************************************/ int join_multicast_group(subn_adm_method method,struct mcast_parameters *params) { int portid = -1; int agentid = -1; void *umad_buff = NULL; void *mad = NULL; int length = MAD_SIZE; int test_result = 0; // mlid will be assigned to the new LID after the join if (umad_init() < 0) { fprintf(stderr, "failed to init the UMAD library\n"); goto cleanup; } /* use casting to loose the "const char0 *" */ portid = umad_open_port((char*)params->ib_devname,params->ib_port); if (portid < 0) { fprintf(stderr,"failed to open UMAD port %d\n",params->ib_port); goto cleanup; } agentid = umad_register(portid,MANAGMENT_CLASS_SUBN_ADM, 2, 0, 0); if (agentid < 0) { fprintf(stderr,"failed to register UMAD agent for MADs\n"); goto cleanup; } umad_buff = umad_alloc(1, umad_size() + MAD_SIZE); if (!umad_buff) { fprintf(stderr, "failed to allocate MAD buffer\n"); goto cleanup; } mad = umad_get_mad(umad_buff); prepare_mcast_mad(method,params,(struct sa_mad_packet_t *)mad); if (umad_set_addr(umad_buff,params->sm_lid,1,params->sm_sl,QP1_WELL_KNOWN_Q_KEY) < 0) { fprintf(stderr, "failed to set the destination address of the SMP\n"); goto cleanup; } if (umad_send(portid,agentid,umad_buff,MAD_SIZE,100,5) < 0) { fprintf(stderr, "failed to send MAD\n"); goto cleanup; } if (umad_recv(portid,umad_buff,&length,5000) < 0) { fprintf(stderr, "failed to receive MAD response\n"); goto cleanup; } if (check_mad_status((struct sa_mad_packet_t*)mad)) { fprintf(stderr, "failed to get mlid from MAD\n"); goto cleanup; } // "Join multicast group" message was sent if (method == SUBN_ADM_METHOD_SET) { get_mlid_from_mad((struct sa_mad_packet_t*)mad,¶ms->mlid); params->mcast_state |= MCAST_IS_JOINED; // "Leave multicast group" message was sent } else { params->mcast_state &= ~MCAST_IS_JOINED; } cleanup: if (umad_buff) umad_free(umad_buff); if (portid >= 0) { if (agentid >= 0) { if (umad_unregister(portid, agentid)) { fprintf(stderr, "failed to deregister UMAD agent for MADs\n"); test_result = 1; } } if (umad_close_port(portid)) { fprintf(stderr, "failed to close UMAD portid\n"); test_result = 1; } } return test_result; }