16 #include <infiniband/opensm/osm_helper.h>
24 0xFF, 0x12, 0xA0, 0x1C,
25 0xFE, 0x80, 0x00, 0x00,
26 0x00, 0x00, 0x00, 0x00,
27 0x88, 0x99, 0xaa, 0xbb
73 if( p_rec->status != IB_SUCCESS )
74 if ( p_rec->status != IB_INVALID_PARAMETER )
75 EOUT(
"TOsm_query_result: Error on query (%s)", ib_get_err_str( p_rec->status));
97 ib_api_status_t status;
99 f_log = (osm_log_t*) malloc (
sizeof(osm_log_t));
101 EOUT(
"Problem with memory allocation");
105 memset(f_log, 0,
sizeof(osm_log_t));
106 osm_log_construct(f_log);
108 status = osm_log_init_v2(f_log, TRUE, 0x0001, NULL, 0, TRUE );
110 if( status != IB_SUCCESS ) {
111 EOUT(
"Problem with osm_log_init_v2");
116 osm_log_set_level(f_log, OSM_LOG_ERROR);
120 f_vendor = osm_vendor_new(f_log, 10);
124 EOUT(
"Cannot create vendor");
132 osm_mad_pool_construct( &f_mad_pool);
133 status = osm_mad_pool_init( &f_mad_pool);
134 if( status != IB_SUCCESS ) {
135 osm_log(f_log, OSM_LOG_ERROR,
"problem with mad_pool\n" );
144 uint32_t port_index = 0;
145 ib_api_status_t status;
153 status = osm_vendor_get_all_port_attr( f_vendor, attr_array, &num_ports );
154 if( status != IB_SUCCESS ) {
155 EOUT(
"osm_vendor_get_all_port_attr fails");
166 memcpy( &f_local_port, &(attr_array[port_index]),
sizeof( f_local_port ) );
170 f_bind_handle = osmv_bind_sa(f_vendor, &f_mad_pool, f_local_port.port_guid);
172 if(f_bind_handle == OSM_BIND_INVALID_HANDLE ) {
173 EOUT(
"Unable to bind to SA");
183 DOUT4(
"osm_vendor_delete commented");
185 DOUT4(
"osm_mad_pool_destroy");
186 osm_mad_pool_destroy(&f_mad_pool);
187 DOUT4(
"osm_log_destroy");
188 osm_log_destroy(f_log);
195 ib_member_rec_t *mc_req,
198 ib_api_status_t status = IB_SUCCESS;
200 osmv_user_query_t
user;
201 osmv_query_req_t req;
208 memset( &req, 0,
sizeof( req ) );
210 memset( res, 0,
sizeof(ib_sa_mad_t ) );
212 user.p_attr = mc_req;
213 user.comp_mask = comp_mask;
215 req.query_type = query_type;
216 req.timeout_ms = 1000;
218 req.flags = OSM_SA_FLAGS_SYNC;
219 req.query_context =
this;
221 req.p_query_input = &
user;
224 status = osmv_query_sa( f_bind_handle, &req );
226 if ( status != IB_SUCCESS ) {
227 EOUT(
"osmv_query_sa error -(%s)", ib_get_err_str(status));
232 memcpy(res, osm_madw_get_mad_ptr(fLastResult.p_result_madw),
sizeof(ib_sa_mad_t));
234 status = fLastResult.status;
236 if((status != IB_SUCCESS ) && (status == IB_REMOTE_ERROR))
237 EOUT(
"osmv_query_sa remote error");
244 if(fLastResult.p_result_madw != NULL )
246 osm_mad_pool_put( &f_mad_pool, fLastResult.p_result_madw );
247 fLastResult.p_result_madw = NULL;
250 return (status==IB_SUCCESS);
257 if ((mgid_raw==0) || (mlid==0))
return false;
259 ib_member_rec_t mc_req_rec;
260 uint64_t comp_mask=0;
261 ib_sa_mad_t res_sa_mad;
262 ib_member_rec_t *p_mc_res;
264 memset(&mc_req_rec, 0,
sizeof(ib_member_rec_t));
268 memcpy(&mc_req_rec.mgid.raw, mgid_raw,
sizeof(mc_req_rec.mgid.raw));
270 DOUT4(
" %s multicast port %016lx", (isadd ?
"Add to" :
"Remove from"), cl_ntoh64(f_local_port.port_guid));
273 memcpy(&mc_req_rec.port_gid.unicast.interface_id,
274 &f_local_port.port_guid,
275 sizeof(f_local_port.port_guid));
278 mc_req_rec.port_gid.unicast.prefix = CL_HTON64(0xFE80000000000000ULL);
288 mc_req_rec.mtu = IB_MTU_LEN_2048 | IB_PATH_SELECTOR_EXACTLY << 6;
292 mc_req_rec.tclass = 0;
294 mc_req_rec.pkey = cl_hton16(0xffff);
298 mc_req_rec.rate = IB_LINK_WIDTH_ACTIVE_4X;
302 mc_req_rec.pkt_life = 0 | IB_PATH_SELECTOR_GREATER_THAN << 6;
305 mc_req_rec.sl_flow_hop = 0;
311 mc_req_rec.scope_state = ib_member_set_scope_state(0x02, IB_MC_REC_STATE_FULL_MEMBER);
314 mc_req_rec.proxy_join = 0;
317 IB_MCR_COMPMASK_MGID |
318 IB_MCR_COMPMASK_PORT_GID |
319 IB_MCR_COMPMASK_QKEY |
320 IB_MCR_COMPMASK_PKEY |
322 IB_MCR_COMPMASK_FLOW |
323 IB_MCR_COMPMASK_JOIN_STATE |
324 IB_MCR_COMPMASK_TCLASS |
325 IB_MCR_COMPMASK_MTU_SEL |
326 IB_MCR_COMPMASK_MTU |
327 IB_MCR_COMPMASK_SCOPE |
328 IB_MCR_COMPMASK_LIFE |
329 IB_MCR_COMPMASK_LIFE_SEL;
331 bool res = Query_SA(isadd ? OSMV_QUERY_UD_MULTICAST_SET :
332 OSMV_QUERY_UD_MULTICAST_DELETE,
337 if (!res)
return false;
339 p_mc_res = (ib_member_rec_t*) ib_sa_mad_get_payload_ptr(&res_sa_mad);
341 *mlid = cl_ntoh16(p_mc_res->mlid);
349 ib_api_status_t status = IB_SUCCESS;
350 osmv_user_query_t
user;
351 osmv_query_req_t req;
352 ib_member_rec_t *p_rec;
353 uint32_t i,num_recs = 0;
355 memset( &req, 0,
sizeof( req ) );
359 user.attr_id = IB_MAD_ATTR_MCMEMBER_RECORD;
360 user.attr_offset = ib_get_attr_offset(
sizeof( ib_member_rec_t ) );
363 req.query_type = OSMV_QUERY_USER_DEFINED;
364 req.timeout_ms = 1000;
366 req.flags = OSM_SA_FLAGS_SYNC;
367 req.query_context =
this;
369 req.p_query_input = &
user;
372 status = osmv_query_sa(f_bind_handle, &req );
374 if( status != IB_SUCCESS ) {
375 EOUT(
"PrintAllMulticasts error"
376 "osmv_query_sa failed (%s)\n", ib_get_err_str( status ));
380 status = fLastResult.status;
382 if(status != IB_SUCCESS) {
383 EOUT(
"ib_query failed (%s)", ib_get_err_str( status ) ));
384 if(status==IB_REMOTE_ERROR)
EOUT(
"Remote error");
388 num_recs = fLastResult.result_cnt;
389 DOUT0(
"Number of Multicast records: %u", num_recs);
391 for( i = 0; i < num_recs; i++ ) {
392 p_rec = (ib_member_rec_t*) osmv_get_query_result( fLastResult.p_result_madw, i );
405 "mgid: %016lx : %016lx mlid: %04x mtu: %x pkey: %x rate: %x", i,
406 cl_ntoh64(p_rec->mgid.unicast.prefix),
407 cl_ntoh64(p_rec->mgid.unicast.interface_id),
408 cl_ntoh16(p_rec->mlid), p_rec->mtu, cl_ntoh16(p_rec->pkey), p_rec->rate));
411 osm_dump_mc_record( f_log, p_rec, OSM_LOG_ERROR);
415 if( fLastResult.p_result_madw != NULL )
417 osm_mad_pool_put( &f_mad_pool, fLastResult.p_result_madw );
418 fLastResult.p_result_madw = NULL;
421 return ( status==IB_SUCCESS );
429 ib_api_status_t status = IB_SUCCESS;
430 osmv_user_query_t
user;
431 osmv_query_req_t req;
432 ib_member_rec_t *p_rec;
433 uint32_t i,num_recs = 0;
435 memset( &req, 0,
sizeof( req ) );
439 user.attr_id = IB_MAD_ATTR_MCMEMBER_RECORD;
440 user.attr_offset = ib_get_attr_offset(
sizeof( ib_member_rec_t ) );
443 req.query_type = OSMV_QUERY_USER_DEFINED;
444 req.timeout_ms = 1000;
446 req.flags = OSM_SA_FLAGS_SYNC;
447 req.query_context =
this;
449 req.p_query_input = &
user;
452 status = osmv_query_sa(f_bind_handle, &req );
454 if( status != IB_SUCCESS ) {
455 EOUT(
"osmv_query_sa failed (%s)", ib_get_err_str(status));
459 status = fLastResult.status;
461 if(status != IB_SUCCESS) {
462 EOUT(
"PrintAllMulticasts error"
463 "ib_query failed (%s)\n", ib_get_err_str( status ) ));
464 if(status==IB_REMOTE_ERROR)
EOUT(
"PrintAllMulticasts Remote error");
468 num_recs = fLastResult.result_cnt;
470 for( i = 0; i < num_recs; i++ ) {
471 p_rec = (ib_member_rec_t*) osmv_get_query_result( fLastResult.p_result_madw, i );
473 if (memcmp(p_rec->mgid.raw, mgid,
sizeof(uint8_t)*16)!=0)
continue;
475 mlid = cl_ntoh16(p_rec->mlid);
481 if( fLastResult.p_result_madw != NULL )
483 osm_mad_pool_put( &f_mad_pool, fLastResult.p_result_madw );
484 fLastResult.p_result_madw = NULL;
void TOsm_query_callback(osmv_query_res_t *p_rec)
#define OSM_GUID_ARRAY_SIZE
#define VERBS_DEFAULT_QKEY
Interface class to opensm.
void SetResult(osmv_query_res_t *res)
bool QueryMyltucastGroup(uint8_t *mgid, uint16_t &mlid)
osm_bind_handle_t f_bind_handle
osm_mad_pool_t f_mad_pool
bool Query_SA(osmv_query_type_t query_type, uint64_t comp_mask, ib_member_rec_t *mc_req, ib_sa_mad_t *res)
bool PrintAllMulticasts()
bool ManageMultiCastGroup(bool isadd, uint8_t *mgid, uint16_t *mlid)
ib_port_attr_t f_local_port