1219820Sjeff/* 2219820Sjeff * Copyright (c) 2006-2008 Voltaire, Inc. All rights reserved. 3219820Sjeff * Copyright (c) 2002-2006 Mellanox Technologies LTD. All rights reserved. 4219820Sjeff * Copyright (c) 1996-2003 Intel Corporation. All rights reserved. 5219820Sjeff * 6219820Sjeff * This software is available to you under a choice of one of two 7219820Sjeff * licenses. You may choose to be licensed under the terms of the GNU 8219820Sjeff * General Public License (GPL) Version 2, available from the file 9219820Sjeff * COPYING in the main directory of this source tree, or the 10219820Sjeff * OpenIB.org BSD license below: 11219820Sjeff * 12219820Sjeff * Redistribution and use in source and binary forms, with or 13219820Sjeff * without modification, are permitted provided that the following 14219820Sjeff * conditions are met: 15219820Sjeff * 16219820Sjeff * - Redistributions of source code must retain the above 17219820Sjeff * copyright notice, this list of conditions and the following 18219820Sjeff * disclaimer. 19219820Sjeff * 20219820Sjeff * - Redistributions in binary form must reproduce the above 21219820Sjeff * copyright notice, this list of conditions and the following 22219820Sjeff * disclaimer in the documentation and/or other materials 23219820Sjeff * provided with the distribution. 24219820Sjeff * 25219820Sjeff * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 26219820Sjeff * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 27219820Sjeff * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 28219820Sjeff * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS 29219820Sjeff * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN 30219820Sjeff * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 31219820Sjeff * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 32219820Sjeff * SOFTWARE. 33219820Sjeff * 34219820Sjeff */ 35219820Sjeff 36219820Sjeff/* 37219820Sjeff * Abstract: 38219820Sjeff * Implementation of service records testing flow.. 39219820Sjeff * Top level is osmt_run_service_records_flow: 40219820Sjeff * osmt_register_service 41219820Sjeff * osmt_get_service_by_name 42219820Sjeff * osmt_get_all_services 43219820Sjeff * osmt_delete_service_by_name 44219820Sjeff * 45219820Sjeff */ 46219820Sjeff 47219820Sjeff#ifndef __WIN__ 48219820Sjeff#include <unistd.h> 49219820Sjeff#else 50219820Sjeff#include <time.h> 51219820Sjeff#endif 52219820Sjeff#include <stdio.h> 53219820Sjeff#include <stdlib.h> 54219820Sjeff#include <string.h> 55219820Sjeff#include <complib/cl_debug.h> 56219820Sjeff#include "osmtest.h" 57219820Sjeff 58219820Sjeff/********************************************************************** 59219820Sjeff **********************************************************************/ 60219820Sjeff 61219820Sjeffib_api_status_t 62219820Sjeffosmt_register_service(IN osmtest_t * const p_osmt, 63219820Sjeff IN ib_net64_t service_id, 64219820Sjeff IN ib_net16_t service_pkey, 65219820Sjeff IN ib_net32_t service_lease, 66219820Sjeff IN uint8_t service_key_lsb, IN char *service_name) 67219820Sjeff{ 68219820Sjeff osmv_query_req_t req; 69219820Sjeff osmv_user_query_t user; 70219820Sjeff osmtest_req_context_t context; 71219820Sjeff ib_service_record_t svc_rec; 72219820Sjeff osm_log_t *p_log = &p_osmt->log; 73219820Sjeff ib_api_status_t status; 74219820Sjeff 75219820Sjeff OSM_LOG_ENTER(p_log); 76219820Sjeff 77219820Sjeff OSM_LOG(&p_osmt->log, OSM_LOG_INFO, 78219820Sjeff "Registering service: name: %s id: 0x%" PRIx64 "\n", 79219820Sjeff service_name, cl_ntoh64(service_id)); 80219820Sjeff 81219820Sjeff memset(&req, 0, sizeof(req)); 82219820Sjeff memset(&context, 0, sizeof(context)); 83219820Sjeff memset(&user, 0, sizeof(user)); 84219820Sjeff memset(&svc_rec, 0, sizeof(svc_rec)); 85219820Sjeff 86219820Sjeff /* set the new service record fields */ 87219820Sjeff svc_rec.service_id = service_id; 88219820Sjeff svc_rec.service_pkey = service_pkey; 89219820Sjeff svc_rec.service_gid.unicast.prefix = 0; 90219820Sjeff svc_rec.service_gid.unicast.interface_id = p_osmt->local_port.port_guid; 91219820Sjeff svc_rec.service_lease = service_lease; 92219820Sjeff memset(&svc_rec.service_key, 0, 16 * sizeof(uint8_t)); 93219820Sjeff svc_rec.service_key[0] = service_key_lsb; 94219820Sjeff memset(svc_rec.service_name, 0, sizeof(svc_rec.service_name)); 95219820Sjeff memcpy(svc_rec.service_name, service_name, 96219820Sjeff (strlen(service_name) + 1) * sizeof(char)); 97219820Sjeff 98219820Sjeff /* prepare the data used for this query */ 99219820Sjeff /* sa_mad_data.method = IB_MAD_METHOD_SET; */ 100219820Sjeff /* sa_mad_data.sm_key = 0; */ 101219820Sjeff 102219820Sjeff context.p_osmt = p_osmt; 103219820Sjeff req.query_context = &context; 104219820Sjeff req.query_type = OSMV_QUERY_USER_DEFINED; 105219820Sjeff req.pfn_query_cb = osmtest_query_res_cb; 106219820Sjeff req.p_query_input = &user; 107219820Sjeff req.flags = OSM_SA_FLAGS_SYNC; 108219820Sjeff req.sm_key = 0; 109219820Sjeff req.timeout_ms = p_osmt->opt.transaction_timeout; 110219820Sjeff 111219820Sjeff user.method = IB_MAD_METHOD_SET; 112219820Sjeff user.attr_id = IB_MAD_ATTR_SERVICE_RECORD; 113219820Sjeff if (ib_pkey_is_invalid(service_pkey)) { 114219820Sjeff /* if given an invalid service_pkey - don't turn the PKEY compmask on */ 115219820Sjeff user.comp_mask = IB_SR_COMPMASK_SID | 116219820Sjeff IB_SR_COMPMASK_SGID | 117219820Sjeff IB_SR_COMPMASK_SLEASE | 118219820Sjeff IB_SR_COMPMASK_SKEY | IB_SR_COMPMASK_SNAME; 119219820Sjeff } else { 120219820Sjeff user.comp_mask = IB_SR_COMPMASK_SID | 121219820Sjeff IB_SR_COMPMASK_SGID | 122219820Sjeff IB_SR_COMPMASK_SPKEY | 123219820Sjeff IB_SR_COMPMASK_SLEASE | 124219820Sjeff IB_SR_COMPMASK_SKEY | IB_SR_COMPMASK_SNAME; 125219820Sjeff } 126219820Sjeff user.attr_offset = ib_get_attr_offset(sizeof(ib_service_record_t)); 127219820Sjeff user.p_attr = &svc_rec; 128219820Sjeff 129219820Sjeff status = osmv_query_sa(p_osmt->h_bind, &req); 130219820Sjeff if (status != IB_SUCCESS) { 131219820Sjeff OSM_LOG(&p_osmt->log, OSM_LOG_ERROR, "ERR 4A01: " 132219820Sjeff "ib_query failed (%s)\n", ib_get_err_str(status)); 133219820Sjeff goto Exit; 134219820Sjeff } 135219820Sjeff 136219820Sjeff status = context.result.status; 137219820Sjeff 138219820Sjeff if (status != IB_SUCCESS) { 139219820Sjeff OSM_LOG(&p_osmt->log, OSM_LOG_ERROR, "ERR 4A02: " 140219820Sjeff "ib_query failed (%s)\n", ib_get_err_str(status)); 141219820Sjeff 142219820Sjeff if (status == IB_REMOTE_ERROR) { 143219820Sjeff OSM_LOG(&p_osmt->log, OSM_LOG_ERROR, 144219820Sjeff "Remote error = %s\n", 145219820Sjeff ib_get_mad_status_str(osm_madw_get_mad_ptr 146219820Sjeff (context.result. 147219820Sjeff p_result_madw))); 148219820Sjeff } 149219820Sjeff goto Exit; 150219820Sjeff } 151219820Sjeff 152219820SjeffExit: 153219820Sjeff if (context.result.p_result_madw != NULL) { 154219820Sjeff osm_mad_pool_put(&p_osmt->mad_pool, 155219820Sjeff context.result.p_result_madw); 156219820Sjeff context.result.p_result_madw = NULL; 157219820Sjeff } 158219820Sjeff 159219820Sjeff OSM_LOG_EXIT(&p_osmt->log); 160219820Sjeff return status; 161219820Sjeff} 162219820Sjeff 163219820Sjeff/********************************************************************** 164219820Sjeff **********************************************************************/ 165219820Sjeff 166219820Sjeffib_api_status_t 167219820Sjeffosmt_register_service_with_full_key(IN osmtest_t * const p_osmt, 168219820Sjeff IN ib_net64_t service_id, 169219820Sjeff IN ib_net16_t service_pkey, 170219820Sjeff IN ib_net32_t service_lease, 171219820Sjeff IN uint8_t * service_key, 172219820Sjeff IN char *service_name) 173219820Sjeff{ 174219820Sjeff osmv_query_req_t req; 175219820Sjeff osmv_user_query_t user; 176219820Sjeff osmtest_req_context_t context; 177219820Sjeff ib_service_record_t svc_rec, *p_rec; 178219820Sjeff osm_log_t *p_log = &p_osmt->log; 179219820Sjeff ib_api_status_t status; 180219820Sjeff uint8_t i, skey[16]; 181219820Sjeff 182219820Sjeff OSM_LOG_ENTER(p_log); 183219820Sjeff 184219820Sjeff OSM_LOG(&p_osmt->log, OSM_LOG_INFO, 185219820Sjeff "Registering service: name: %s id: 0x%" PRIx64 "\n", 186219820Sjeff service_name, cl_ntoh64(service_id)); 187219820Sjeff 188219820Sjeff memset(&req, 0, sizeof(req)); 189219820Sjeff memset(&context, 0, sizeof(context)); 190219820Sjeff memset(&user, 0, sizeof(user)); 191219820Sjeff memset(&svc_rec, 0, sizeof(svc_rec)); 192219820Sjeff 193219820Sjeff /* set the new service record fields */ 194219820Sjeff svc_rec.service_id = service_id; 195219820Sjeff svc_rec.service_pkey = service_pkey; 196219820Sjeff svc_rec.service_gid.unicast.prefix = 0; 197219820Sjeff svc_rec.service_gid.unicast.interface_id = p_osmt->local_port.port_guid; 198219820Sjeff svc_rec.service_lease = service_lease; 199219820Sjeff memset(&svc_rec.service_key, 0, 16 * sizeof(uint8_t)); 200219820Sjeff memcpy(svc_rec.service_key, service_key, 16 * sizeof(uint8_t)); 201219820Sjeff memset(svc_rec.service_name, 0, sizeof(svc_rec.service_name)); 202219820Sjeff memset(skey, 0, 16 * sizeof(uint8_t)); 203219820Sjeff memcpy(svc_rec.service_name, service_name, 204219820Sjeff (strlen(service_name) + 1) * sizeof(char)); 205219820Sjeff 206219820Sjeff /* prepare the data used for this query */ 207219820Sjeff /* sa_mad_data.method = IB_MAD_METHOD_SET; */ 208219820Sjeff /* sa_mad_data.sm_key = 0; */ 209219820Sjeff 210219820Sjeff context.p_osmt = p_osmt; 211219820Sjeff req.query_context = &context; 212219820Sjeff req.query_type = OSMV_QUERY_USER_DEFINED; 213219820Sjeff req.pfn_query_cb = osmtest_query_res_cb; 214219820Sjeff req.p_query_input = &user; 215219820Sjeff req.flags = OSM_SA_FLAGS_SYNC; 216219820Sjeff req.sm_key = 0; 217219820Sjeff req.timeout_ms = p_osmt->opt.transaction_timeout; 218219820Sjeff 219219820Sjeff user.method = IB_MAD_METHOD_SET; 220219820Sjeff user.attr_id = IB_MAD_ATTR_SERVICE_RECORD; 221219820Sjeff if (ib_pkey_is_invalid(service_pkey)) { 222219820Sjeff /* if given an invalid service_pkey - don't turn the PKEY compmask on */ 223219820Sjeff user.comp_mask = IB_SR_COMPMASK_SID | 224219820Sjeff IB_SR_COMPMASK_SGID | 225219820Sjeff IB_SR_COMPMASK_SLEASE | 226219820Sjeff IB_SR_COMPMASK_SKEY | IB_SR_COMPMASK_SNAME; 227219820Sjeff } else { 228219820Sjeff user.comp_mask = IB_SR_COMPMASK_SID | 229219820Sjeff IB_SR_COMPMASK_SGID | 230219820Sjeff IB_SR_COMPMASK_SPKEY | 231219820Sjeff IB_SR_COMPMASK_SLEASE | 232219820Sjeff IB_SR_COMPMASK_SKEY | IB_SR_COMPMASK_SNAME; 233219820Sjeff } 234219820Sjeff user.attr_offset = ib_get_attr_offset(sizeof(ib_service_record_t)); 235219820Sjeff user.p_attr = &svc_rec; 236219820Sjeff 237219820Sjeff status = osmv_query_sa(p_osmt->h_bind, &req); 238219820Sjeff if (status != IB_SUCCESS) { 239219820Sjeff OSM_LOG(&p_osmt->log, OSM_LOG_ERROR, "ERR 4A03: " 240219820Sjeff "ib_query failed (%s)\n", ib_get_err_str(status)); 241219820Sjeff goto Exit; 242219820Sjeff } 243219820Sjeff 244219820Sjeff status = context.result.status; 245219820Sjeff if (status != IB_SUCCESS) { 246219820Sjeff OSM_LOG(&p_osmt->log, OSM_LOG_ERROR, "ERR 4A04: " 247219820Sjeff "ib_query failed (%s)\n", ib_get_err_str(status)); 248219820Sjeff 249219820Sjeff if (status == IB_REMOTE_ERROR) { 250219820Sjeff OSM_LOG(&p_osmt->log, OSM_LOG_ERROR, 251219820Sjeff "Remote error = %s\n", 252219820Sjeff ib_get_mad_status_str(osm_madw_get_mad_ptr 253219820Sjeff (context.result. 254219820Sjeff p_result_madw))); 255219820Sjeff } 256219820Sjeff goto Exit; 257219820Sjeff } 258219820Sjeff 259219820Sjeff /* Check service key on context to see if match */ 260219820Sjeff p_rec = osmv_get_query_svc_rec(context.result.p_result_madw, 0); 261219820Sjeff OSM_LOG(&p_osmt->log, OSM_LOG_VERBOSE, 262219820Sjeff "Comparing service key...\n" "return key is:\n"); 263219820Sjeff for (i = 0; i <= 15; i++) { 264219820Sjeff OSM_LOG(&p_osmt->log, OSM_LOG_VERBOSE, 265219820Sjeff "service_key sent[%u] = %u, service_key returned[%u] = %u\n", 266219820Sjeff i, service_key[i], i, p_rec->service_key[i]); 267219820Sjeff } 268219820Sjeff /* since c15-0.1.14 not supported all key association queries should bring in return zero in service key */ 269219820Sjeff if (memcmp(skey, p_rec->service_key, 16 * sizeof(uint8_t)) != 0) { 270219820Sjeff status = IB_REMOTE_ERROR; 271219820Sjeff OSM_LOG(&p_osmt->log, OSM_LOG_ERROR, "ERR 4A33: " 272219820Sjeff "Data mismatch in service_key\n"); 273219820Sjeff goto Exit; 274219820Sjeff } 275219820Sjeff 276219820SjeffExit: 277219820Sjeff if (context.result.p_result_madw != NULL) { 278219820Sjeff osm_mad_pool_put(&p_osmt->mad_pool, 279219820Sjeff context.result.p_result_madw); 280219820Sjeff context.result.p_result_madw = NULL; 281219820Sjeff } 282219820Sjeff 283219820Sjeff OSM_LOG_EXIT(&p_osmt->log); 284219820Sjeff return status; 285219820Sjeff} 286219820Sjeff 287219820Sjeff/********************************************************************** 288219820Sjeff **********************************************************************/ 289219820Sjeff 290219820Sjeffib_api_status_t 291219820Sjeffosmt_register_service_with_data(IN osmtest_t * const p_osmt, 292219820Sjeff IN ib_net64_t service_id, 293219820Sjeff IN ib_net16_t service_pkey, 294219820Sjeff IN ib_net32_t service_lease, 295219820Sjeff IN uint8_t service_key_lsb, 296219820Sjeff IN uint8_t * service_data8, 297219820Sjeff IN ib_net16_t * service_data16, 298219820Sjeff IN ib_net32_t * service_data32, 299219820Sjeff IN ib_net64_t * service_data64, 300219820Sjeff IN char *service_name) 301219820Sjeff{ 302219820Sjeff osmv_query_req_t req; 303219820Sjeff osmv_user_query_t user; 304219820Sjeff osmtest_req_context_t context; 305219820Sjeff ib_service_record_t svc_rec, *p_rec; 306219820Sjeff osm_log_t *p_log = &p_osmt->log; 307219820Sjeff ib_api_status_t status; 308219820Sjeff /* ib_service_record_t* p_rec; */ 309219820Sjeff 310219820Sjeff OSM_LOG_ENTER(p_log); 311219820Sjeff 312219820Sjeff OSM_LOG(&p_osmt->log, OSM_LOG_INFO, 313219820Sjeff "Registering service: name: %s id: 0x%" PRIx64 "\n", 314219820Sjeff service_name, cl_ntoh64(service_id)); 315219820Sjeff 316219820Sjeff memset(&req, 0, sizeof(req)); 317219820Sjeff memset(&context, 0, sizeof(context)); 318219820Sjeff memset(&user, 0, sizeof(user)); 319219820Sjeff memset(&svc_rec, 0, sizeof(svc_rec)); 320219820Sjeff 321219820Sjeff /* set the new service record fields */ 322219820Sjeff svc_rec.service_id = service_id; 323219820Sjeff svc_rec.service_pkey = service_pkey; 324219820Sjeff svc_rec.service_gid.unicast.prefix = 0; 325219820Sjeff svc_rec.service_gid.unicast.interface_id = p_osmt->local_port.port_guid; 326219820Sjeff svc_rec.service_lease = service_lease; 327219820Sjeff memset(&svc_rec.service_key, 0, 16 * sizeof(uint8_t)); 328219820Sjeff svc_rec.service_key[0] = service_key_lsb; 329219820Sjeff 330219820Sjeff /* Copy data to service_data arrays */ 331219820Sjeff memcpy(svc_rec.service_data8, service_data8, 16 * sizeof(uint8_t)); 332219820Sjeff memcpy(svc_rec.service_data16, service_data16, 8 * sizeof(ib_net16_t)); 333219820Sjeff memcpy(svc_rec.service_data32, service_data32, 4 * sizeof(ib_net32_t)); 334219820Sjeff memcpy(svc_rec.service_data64, service_data64, 2 * sizeof(ib_net64_t)); 335219820Sjeff 336219820Sjeff memset(svc_rec.service_name, 0, sizeof(svc_rec.service_name)); 337219820Sjeff memcpy(svc_rec.service_name, service_name, 338219820Sjeff (strlen(service_name) + 1) * sizeof(char)); 339219820Sjeff 340219820Sjeff /* prepare the data used for this query */ 341219820Sjeff /* sa_mad_data.method = IB_MAD_METHOD_SET; */ 342219820Sjeff /* sa_mad_data.sm_key = 0; */ 343219820Sjeff 344219820Sjeff context.p_osmt = p_osmt; 345219820Sjeff req.query_context = &context; 346219820Sjeff req.query_type = OSMV_QUERY_USER_DEFINED; 347219820Sjeff req.pfn_query_cb = osmtest_query_res_cb; 348219820Sjeff req.p_query_input = &user; 349219820Sjeff req.flags = OSM_SA_FLAGS_SYNC; 350219820Sjeff req.sm_key = 0; 351219820Sjeff req.timeout_ms = p_osmt->opt.transaction_timeout; 352219820Sjeff 353219820Sjeff user.method = IB_MAD_METHOD_SET; 354219820Sjeff user.attr_id = IB_MAD_ATTR_SERVICE_RECORD; 355219820Sjeff if (ib_pkey_is_invalid(service_pkey)) { 356219820Sjeff /* if given an invalid service_pkey - don't turn the PKEY compmask on */ 357219820Sjeff user.comp_mask = IB_SR_COMPMASK_SID | 358219820Sjeff IB_SR_COMPMASK_SGID | 359219820Sjeff IB_SR_COMPMASK_SLEASE | 360219820Sjeff IB_SR_COMPMASK_SKEY | 361219820Sjeff IB_SR_COMPMASK_SNAME | 362219820Sjeff IB_SR_COMPMASK_SDATA8_0 | 363219820Sjeff IB_SR_COMPMASK_SDATA8_1 | 364219820Sjeff IB_SR_COMPMASK_SDATA16_0 | 365219820Sjeff IB_SR_COMPMASK_SDATA16_1 | 366219820Sjeff IB_SR_COMPMASK_SDATA32_0 | 367219820Sjeff IB_SR_COMPMASK_SDATA32_1 | 368219820Sjeff IB_SR_COMPMASK_SDATA64_0 | IB_SR_COMPMASK_SDATA64_1; 369219820Sjeff } else { 370219820Sjeff user.comp_mask = IB_SR_COMPMASK_SID | 371219820Sjeff IB_SR_COMPMASK_SGID | 372219820Sjeff IB_SR_COMPMASK_SPKEY | 373219820Sjeff IB_SR_COMPMASK_SLEASE | 374219820Sjeff IB_SR_COMPMASK_SKEY | 375219820Sjeff IB_SR_COMPMASK_SNAME | 376219820Sjeff IB_SR_COMPMASK_SDATA8_0 | 377219820Sjeff IB_SR_COMPMASK_SDATA8_1 | 378219820Sjeff IB_SR_COMPMASK_SDATA16_0 | 379219820Sjeff IB_SR_COMPMASK_SDATA16_1 | 380219820Sjeff IB_SR_COMPMASK_SDATA32_0 | 381219820Sjeff IB_SR_COMPMASK_SDATA32_1 | 382219820Sjeff IB_SR_COMPMASK_SDATA64_0 | IB_SR_COMPMASK_SDATA64_1; 383219820Sjeff } 384219820Sjeff user.attr_offset = ib_get_attr_offset(sizeof(ib_service_record_t)); 385219820Sjeff user.p_attr = &svc_rec; 386219820Sjeff 387219820Sjeff /* Dump to Service Data b4 send */ 388219820Sjeff OSM_LOG(&p_osmt->log, OSM_LOG_VERBOSE, 389219820Sjeff "Dumping service data b4 send\n"); 390219820Sjeff osm_dump_service_record(&p_osmt->log, &svc_rec, OSM_LOG_VERBOSE); 391219820Sjeff 392219820Sjeff status = osmv_query_sa(p_osmt->h_bind, &req); 393219820Sjeff if (status != IB_SUCCESS) { 394219820Sjeff OSM_LOG(&p_osmt->log, OSM_LOG_ERROR, "ERR 4A05: " 395219820Sjeff "ib_query failed (%s)\n", ib_get_err_str(status)); 396219820Sjeff goto Exit; 397219820Sjeff } 398219820Sjeff 399219820Sjeff status = context.result.status; 400219820Sjeff 401219820Sjeff if (status != IB_SUCCESS) { 402219820Sjeff OSM_LOG(&p_osmt->log, OSM_LOG_ERROR, "ERR 4A06: " 403219820Sjeff "ib_query failed (%s)\n", ib_get_err_str(status)); 404219820Sjeff 405219820Sjeff if (status == IB_REMOTE_ERROR) { 406219820Sjeff OSM_LOG(&p_osmt->log, OSM_LOG_ERROR, 407219820Sjeff "Remote error = %s\n", 408219820Sjeff ib_get_mad_status_str(osm_madw_get_mad_ptr 409219820Sjeff (context.result. 410219820Sjeff p_result_madw))); 411219820Sjeff } 412219820Sjeff goto Exit; 413219820Sjeff } 414219820Sjeff 415219820Sjeff /* Check data on context to see if match */ 416219820Sjeff p_rec = osmv_get_query_svc_rec(context.result.p_result_madw, 0); 417219820Sjeff OSM_LOG(&p_osmt->log, OSM_LOG_VERBOSE, "Comparing service data...\n"); 418219820Sjeff if (memcmp(service_data8, p_rec->service_data8, 16 * sizeof(uint8_t)) != 419219820Sjeff 0 420219820Sjeff || memcmp(service_data16, p_rec->service_data16, 421219820Sjeff 8 * sizeof(uint16_t)) != 0 422219820Sjeff || memcmp(service_data32, p_rec->service_data32, 423219820Sjeff 4 * sizeof(uint32_t)) != 0 424219820Sjeff || memcmp(service_data64, p_rec->service_data64, 425219820Sjeff 2 * sizeof(uint64_t)) != 0) { 426219820Sjeff status = IB_REMOTE_ERROR; 427219820Sjeff OSM_LOG(&p_osmt->log, OSM_LOG_ERROR, 428219820Sjeff "Data mismatch in service_data8\n"); 429219820Sjeff goto Exit; 430219820Sjeff } 431219820Sjeff 432219820SjeffExit: 433219820Sjeff if (context.result.p_result_madw != NULL) { 434219820Sjeff osm_mad_pool_put(&p_osmt->mad_pool, 435219820Sjeff context.result.p_result_madw); 436219820Sjeff context.result.p_result_madw = NULL; 437219820Sjeff } 438219820Sjeff 439219820Sjeff OSM_LOG_EXIT(&p_osmt->log); 440219820Sjeff return status; 441219820Sjeff} 442219820Sjeff 443219820Sjeff/********************************************************************** 444219820Sjeff **********************************************************************/ 445219820Sjeff 446219820Sjeffib_api_status_t 447219820Sjeffosmt_get_service_by_id_and_name(IN osmtest_t * const p_osmt, 448219820Sjeff IN uint32_t rec_num, 449219820Sjeff IN ib_net64_t sid, 450219820Sjeff IN char *sr_name, 451219820Sjeff OUT ib_service_record_t * p_out_rec) 452219820Sjeff{ 453219820Sjeff 454219820Sjeff ib_api_status_t status = IB_SUCCESS; 455219820Sjeff osmtest_req_context_t context; 456219820Sjeff osmv_query_req_t req; 457219820Sjeff ib_service_record_t svc_rec, *p_rec; 458219820Sjeff uint32_t num_recs = 0; 459219820Sjeff osmv_user_query_t user; 460219820Sjeff 461219820Sjeff OSM_LOG_ENTER(&p_osmt->log); 462219820Sjeff 463219820Sjeff OSM_LOG(&p_osmt->log, OSM_LOG_VERBOSE, 464219820Sjeff "Getting service record: id: 0x%016" PRIx64 465219820Sjeff " and name: %s\n", cl_ntoh64(sid), sr_name); 466219820Sjeff 467219820Sjeff /* 468219820Sjeff * Do a blocking query for this record in the subnet. 469219820Sjeff * The result is returned in the result field of the caller's 470219820Sjeff * context structure. 471219820Sjeff * 472219820Sjeff * The query structures are locals. 473219820Sjeff */ 474219820Sjeff memset(&req, 0, sizeof(req)); 475219820Sjeff memset(&context, 0, sizeof(context)); 476219820Sjeff 477219820Sjeff context.p_osmt = p_osmt; 478219820Sjeff 479219820Sjeff /* prepare the data used for this query */ 480219820Sjeff req.query_type = OSMV_QUERY_USER_DEFINED; 481219820Sjeff req.timeout_ms = p_osmt->opt.transaction_timeout; 482219820Sjeff req.retry_cnt = p_osmt->opt.retry_count; 483219820Sjeff req.flags = OSM_SA_FLAGS_SYNC; 484219820Sjeff req.query_context = &context; 485219820Sjeff req.pfn_query_cb = osmtest_query_res_cb; 486219820Sjeff req.sm_key = 0; 487219820Sjeff 488219820Sjeff memset(&svc_rec, 0, sizeof(svc_rec)); 489219820Sjeff memset(&user, 0, sizeof(user)); 490219820Sjeff /* set the new service record fields */ 491219820Sjeff memset(svc_rec.service_name, 0, sizeof(svc_rec.service_name)); 492219820Sjeff memcpy(svc_rec.service_name, sr_name, 493219820Sjeff (strlen(sr_name) + 1) * sizeof(char)); 494219820Sjeff svc_rec.service_id = sid; 495219820Sjeff req.p_query_input = &user; 496219820Sjeff 497219820Sjeff user.method = IB_MAD_METHOD_GET; 498219820Sjeff user.attr_id = IB_MAD_ATTR_SERVICE_RECORD; 499219820Sjeff user.comp_mask = IB_SR_COMPMASK_SID | IB_SR_COMPMASK_SNAME; 500219820Sjeff user.attr_offset = ib_get_attr_offset(sizeof(ib_service_record_t)); 501219820Sjeff user.p_attr = &svc_rec; 502219820Sjeff 503219820Sjeff status = osmv_query_sa(p_osmt->h_bind, &req); 504219820Sjeff if (status != IB_SUCCESS) { 505219820Sjeff OSM_LOG(&p_osmt->log, OSM_LOG_ERROR, "ERR 4A07: " 506219820Sjeff "ib_query failed (%s)\n", ib_get_err_str(status)); 507219820Sjeff goto Exit; 508219820Sjeff } 509219820Sjeff 510219820Sjeff status = context.result.status; 511219820Sjeff num_recs = context.result.result_cnt; 512219820Sjeff 513219820Sjeff if (status != IB_SUCCESS) { 514219820Sjeff char mad_stat_err[256]; 515219820Sjeff 516219820Sjeff /* If the failure is due to IB_SA_MAD_STATUS_NO_RECORDS and rec_num is 0, 517219820Sjeff then this is fine */ 518219820Sjeff if (status == IB_REMOTE_ERROR) 519219820Sjeff strcpy(mad_stat_err, 520219820Sjeff ib_get_mad_status_str(osm_madw_get_mad_ptr 521219820Sjeff (context.result. 522219820Sjeff p_result_madw))); 523219820Sjeff else 524219820Sjeff strcpy(mad_stat_err, ib_get_err_str(status)); 525219820Sjeff if (status == IB_REMOTE_ERROR && 526219820Sjeff !strcmp(mad_stat_err, "IB_SA_MAD_STATUS_NO_RECORDS") && 527219820Sjeff rec_num == 0) { 528219820Sjeff OSM_LOG(&p_osmt->log, OSM_LOG_ERROR, 529219820Sjeff "IS EXPECTED ERROR ^^^^\n"); 530219820Sjeff status = IB_SUCCESS; 531219820Sjeff } else { 532219820Sjeff OSM_LOG(&p_osmt->log, OSM_LOG_ERROR, "ERR 4A08: " 533219820Sjeff "Query failed: %s (%s)\n", 534219820Sjeff ib_get_err_str(status), mad_stat_err); 535219820Sjeff goto Exit; 536219820Sjeff } 537219820Sjeff } 538219820Sjeff 539219820Sjeff if (rec_num && num_recs != rec_num) { 540219820Sjeff OSM_LOG(&p_osmt->log, OSM_LOG_ERROR, 541219820Sjeff "Unmatched number of records: expected: %d, received: %d\n", 542219820Sjeff rec_num, num_recs); 543219820Sjeff status = IB_REMOTE_ERROR; 544219820Sjeff goto Exit; 545219820Sjeff } 546219820Sjeff 547219820Sjeff p_rec = osmv_get_query_svc_rec(context.result.p_result_madw, 0); 548219820Sjeff *p_out_rec = *p_rec; 549219820Sjeff 550219820Sjeff if (num_recs) { 551219820Sjeff OSM_LOG(&p_osmt->log, OSM_LOG_VERBOSE, 552219820Sjeff "Found service record: name: %s id: 0x%016" PRIx64 "\n", 553219820Sjeff p_rec->service_name, cl_ntoh64(p_rec->service_id)); 554219820Sjeff 555219820Sjeff osm_dump_service_record(&p_osmt->log, p_rec, OSM_LOG_DEBUG); 556219820Sjeff } 557219820Sjeff 558219820SjeffExit: 559219820Sjeff OSM_LOG(&p_osmt->log, OSM_LOG_VERBOSE, 560219820Sjeff "Expected and found %d records\n", rec_num); 561219820Sjeff 562219820Sjeff if (context.result.p_result_madw != NULL) { 563219820Sjeff osm_mad_pool_put(&p_osmt->mad_pool, 564219820Sjeff context.result.p_result_madw); 565219820Sjeff context.result.p_result_madw = NULL; 566219820Sjeff } 567219820Sjeff 568219820Sjeff OSM_LOG_EXIT(&p_osmt->log); 569219820Sjeff return status; 570219820Sjeff} 571219820Sjeff 572219820Sjeff/********************************************************************** 573219820Sjeff **********************************************************************/ 574219820Sjeff 575219820Sjeffib_api_status_t 576219820Sjeffosmt_get_service_by_id(IN osmtest_t * const p_osmt, 577219820Sjeff IN uint32_t rec_num, 578219820Sjeff IN ib_net64_t sid, OUT ib_service_record_t * p_out_rec) 579219820Sjeff{ 580219820Sjeff 581219820Sjeff ib_api_status_t status = IB_SUCCESS; 582219820Sjeff osmtest_req_context_t context; 583219820Sjeff osmv_query_req_t req; 584219820Sjeff ib_service_record_t svc_rec, *p_rec; 585219820Sjeff uint32_t num_recs = 0; 586219820Sjeff osmv_user_query_t user; 587219820Sjeff 588219820Sjeff OSM_LOG_ENTER(&p_osmt->log); 589219820Sjeff 590219820Sjeff OSM_LOG(&p_osmt->log, OSM_LOG_VERBOSE, 591219820Sjeff "Getting service record: id: 0x%016" PRIx64 "\n", 592219820Sjeff cl_ntoh64(sid)); 593219820Sjeff 594219820Sjeff /* 595219820Sjeff * Do a blocking query for this record in the subnet. 596219820Sjeff * The result is returned in the result field of the caller's 597219820Sjeff * context structure. 598219820Sjeff * 599219820Sjeff * The query structures are locals. 600219820Sjeff */ 601219820Sjeff memset(&req, 0, sizeof(req)); 602219820Sjeff memset(&context, 0, sizeof(context)); 603219820Sjeff 604219820Sjeff context.p_osmt = p_osmt; 605219820Sjeff 606219820Sjeff /* prepare the data used for this query */ 607219820Sjeff req.query_type = OSMV_QUERY_USER_DEFINED; 608219820Sjeff req.timeout_ms = p_osmt->opt.transaction_timeout; 609219820Sjeff req.retry_cnt = p_osmt->opt.retry_count; 610219820Sjeff req.flags = OSM_SA_FLAGS_SYNC; 611219820Sjeff req.query_context = &context; 612219820Sjeff req.pfn_query_cb = osmtest_query_res_cb; 613219820Sjeff req.sm_key = 0; 614219820Sjeff 615219820Sjeff memset(&svc_rec, 0, sizeof(svc_rec)); 616219820Sjeff memset(&user, 0, sizeof(user)); 617219820Sjeff /* set the new service record fields */ 618219820Sjeff svc_rec.service_id = sid; 619219820Sjeff req.p_query_input = &user; 620219820Sjeff 621219820Sjeff user.method = IB_MAD_METHOD_GET; 622219820Sjeff user.attr_id = IB_MAD_ATTR_SERVICE_RECORD; 623219820Sjeff user.comp_mask = IB_SR_COMPMASK_SID; 624219820Sjeff user.attr_offset = ib_get_attr_offset(sizeof(ib_service_record_t)); 625219820Sjeff user.p_attr = &svc_rec; 626219820Sjeff 627219820Sjeff status = osmv_query_sa(p_osmt->h_bind, &req); 628219820Sjeff if (status != IB_SUCCESS) { 629219820Sjeff OSM_LOG(&p_osmt->log, OSM_LOG_ERROR, "ERR 4A09: " 630219820Sjeff "ib_query failed (%s)\n", ib_get_err_str(status)); 631219820Sjeff goto Exit; 632219820Sjeff } 633219820Sjeff 634219820Sjeff status = context.result.status; 635219820Sjeff num_recs = context.result.result_cnt; 636219820Sjeff 637219820Sjeff if (status != IB_SUCCESS) { 638219820Sjeff char mad_stat_err[256]; 639219820Sjeff 640219820Sjeff /* If the failure is due to IB_SA_MAD_STATUS_NO_RECORDS and rec_num is 0, 641219820Sjeff then this is fine */ 642219820Sjeff if (status == IB_REMOTE_ERROR) 643219820Sjeff strcpy(mad_stat_err, 644219820Sjeff ib_get_mad_status_str(osm_madw_get_mad_ptr 645219820Sjeff (context.result. 646219820Sjeff p_result_madw))); 647219820Sjeff else 648219820Sjeff strcpy(mad_stat_err, ib_get_err_str(status)); 649219820Sjeff 650219820Sjeff if (status == IB_REMOTE_ERROR && 651219820Sjeff !strcmp(mad_stat_err, "IB_SA_MAD_STATUS_NO_RECORDS") && 652219820Sjeff rec_num == 0) { 653219820Sjeff OSM_LOG(&p_osmt->log, OSM_LOG_ERROR, 654219820Sjeff "IS EXPECTED ERROR ^^^^\n"); 655219820Sjeff status = IB_SUCCESS; 656219820Sjeff } else { 657219820Sjeff OSM_LOG(&p_osmt->log, OSM_LOG_ERROR, "ERR 4A0A: " 658219820Sjeff "Query failed: %s (%s)\n", 659219820Sjeff ib_get_err_str(status), mad_stat_err); 660219820Sjeff goto Exit; 661219820Sjeff } 662219820Sjeff } 663219820Sjeff 664219820Sjeff if (rec_num && num_recs != rec_num) { 665219820Sjeff OSM_LOG(&p_osmt->log, OSM_LOG_ERROR, "ERR 4A0B: " 666219820Sjeff "Unmatched number of records: expected: %d received: %d\n", 667219820Sjeff rec_num, num_recs); 668219820Sjeff status = IB_REMOTE_ERROR; 669219820Sjeff goto Exit; 670219820Sjeff } 671219820Sjeff 672219820Sjeff p_rec = osmv_get_query_svc_rec(context.result.p_result_madw, 0); 673219820Sjeff *p_out_rec = *p_rec; 674219820Sjeff 675219820Sjeff if (num_recs) { 676219820Sjeff OSM_LOG(&p_osmt->log, OSM_LOG_VERBOSE, 677219820Sjeff "Found service record: name: %s id: 0x%016" PRIx64 "\n", 678219820Sjeff p_rec->service_name, cl_ntoh64(p_rec->service_id)); 679219820Sjeff 680219820Sjeff osm_dump_service_record(&p_osmt->log, p_rec, OSM_LOG_DEBUG); 681219820Sjeff } 682219820Sjeff 683219820SjeffExit: 684219820Sjeff OSM_LOG(&p_osmt->log, OSM_LOG_VERBOSE, 685219820Sjeff "Expected and found %d records\n", rec_num); 686219820Sjeff 687219820Sjeff if (context.result.p_result_madw != NULL) { 688219820Sjeff osm_mad_pool_put(&p_osmt->mad_pool, 689219820Sjeff context.result.p_result_madw); 690219820Sjeff context.result.p_result_madw = NULL; 691219820Sjeff } 692219820Sjeff 693219820Sjeff OSM_LOG_EXIT(&p_osmt->log); 694219820Sjeff return status; 695219820Sjeff} 696219820Sjeff 697219820Sjeff/********************************************************************** 698219820Sjeff **********************************************************************/ 699219820Sjeff 700219820Sjeffib_api_status_t 701219820Sjeffosmt_get_service_by_name_and_key(IN osmtest_t * const p_osmt, 702219820Sjeff IN char *sr_name, 703219820Sjeff IN uint32_t rec_num, 704219820Sjeff IN uint8_t * skey, 705219820Sjeff OUT ib_service_record_t * p_out_rec) 706219820Sjeff{ 707219820Sjeff 708219820Sjeff ib_api_status_t status = IB_SUCCESS; 709219820Sjeff osmtest_req_context_t context; 710219820Sjeff osmv_query_req_t req; 711219820Sjeff ib_service_record_t svc_rec, *p_rec; 712219820Sjeff uint32_t num_recs = 0, i; 713219820Sjeff osmv_user_query_t user; 714219820Sjeff 715219820Sjeff OSM_LOG_ENTER(&p_osmt->log); 716219820Sjeff 717219820Sjeff OSM_LOG(&p_osmt->log, OSM_LOG_VERBOSE, 718219820Sjeff "Getting service record: name: %s and key: " 719219820Sjeff "0x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x\n", 720219820Sjeff sr_name, skey[0], skey[1], skey[2], skey[3], skey[4], skey[5], 721219820Sjeff skey[6], skey[7], skey[8], skey[9], skey[10], skey[11], 722219820Sjeff skey[12], skey[13], skey[14], skey[15]); 723219820Sjeff 724219820Sjeff /* 725219820Sjeff * Do a blocking query for this record in the subnet. 726219820Sjeff * The result is returned in the result field of the caller's 727219820Sjeff * context structure. 728219820Sjeff * 729219820Sjeff * The query structures are locals. 730219820Sjeff */ 731219820Sjeff memset(&req, 0, sizeof(req)); 732219820Sjeff memset(&context, 0, sizeof(context)); 733219820Sjeff 734219820Sjeff context.p_osmt = p_osmt; 735219820Sjeff 736219820Sjeff /* prepare the data used for this query */ 737219820Sjeff req.query_type = OSMV_QUERY_USER_DEFINED; 738219820Sjeff req.timeout_ms = p_osmt->opt.transaction_timeout; 739219820Sjeff req.retry_cnt = p_osmt->opt.retry_count; 740219820Sjeff req.flags = OSM_SA_FLAGS_SYNC; 741219820Sjeff req.query_context = &context; 742219820Sjeff req.pfn_query_cb = osmtest_query_res_cb; 743219820Sjeff req.sm_key = 0; 744219820Sjeff 745219820Sjeff memset(&svc_rec, 0, sizeof(svc_rec)); 746219820Sjeff memset(&user, 0, sizeof(user)); 747219820Sjeff /* set the new service record fields */ 748219820Sjeff memset(svc_rec.service_name, 0, sizeof(svc_rec.service_name)); 749219820Sjeff memcpy(svc_rec.service_name, sr_name, 750219820Sjeff (strlen(sr_name) + 1) * sizeof(char)); 751219820Sjeff for (i = 0; i <= 15; i++) 752219820Sjeff svc_rec.service_key[i] = skey[i]; 753219820Sjeff 754219820Sjeff req.p_query_input = &user; 755219820Sjeff 756219820Sjeff user.method = IB_MAD_METHOD_GET; 757219820Sjeff user.attr_id = IB_MAD_ATTR_SERVICE_RECORD; 758219820Sjeff user.comp_mask = IB_SR_COMPMASK_SNAME | IB_SR_COMPMASK_SKEY; 759219820Sjeff user.attr_offset = ib_get_attr_offset(sizeof(ib_service_record_t)); 760219820Sjeff user.p_attr = &svc_rec; 761219820Sjeff status = osmv_query_sa(p_osmt->h_bind, &req); 762219820Sjeff if (status != IB_SUCCESS) { 763219820Sjeff OSM_LOG(&p_osmt->log, OSM_LOG_ERROR, "ERR 4A0C: " 764219820Sjeff "ib_query failed (%s)\n", ib_get_err_str(status)); 765219820Sjeff goto Exit; 766219820Sjeff } 767219820Sjeff 768219820Sjeff status = context.result.status; 769219820Sjeff num_recs = context.result.result_cnt; 770219820Sjeff 771219820Sjeff if (status != IB_SUCCESS) { 772219820Sjeff char mad_stat_err[256]; 773219820Sjeff 774219820Sjeff /* If the failure is due to IB_SA_MAD_STATUS_NO_RECORDS and rec_num is 0, 775219820Sjeff then this is fine */ 776219820Sjeff if (status == IB_REMOTE_ERROR) 777219820Sjeff strcpy(mad_stat_err, 778219820Sjeff ib_get_mad_status_str(osm_madw_get_mad_ptr 779219820Sjeff (context.result. 780219820Sjeff p_result_madw))); 781219820Sjeff else 782219820Sjeff strcpy(mad_stat_err, ib_get_err_str(status)); 783219820Sjeff 784219820Sjeff if (status == IB_REMOTE_ERROR && 785219820Sjeff !strcmp(mad_stat_err, "IB_SA_MAD_STATUS_NO_RECORDS") && 786219820Sjeff rec_num == 0) { 787219820Sjeff OSM_LOG(&p_osmt->log, OSM_LOG_ERROR, 788219820Sjeff "IS EXPECTED ERROR ^^^^\n"); 789219820Sjeff status = IB_SUCCESS; 790219820Sjeff } else { 791219820Sjeff OSM_LOG(&p_osmt->log, OSM_LOG_ERROR, "ERR 4A0D: " 792219820Sjeff "Query failed:%s (%s)\n", 793219820Sjeff ib_get_err_str(status), mad_stat_err); 794219820Sjeff goto Exit; 795219820Sjeff } 796219820Sjeff } 797219820Sjeff 798219820Sjeff if (rec_num && num_recs != rec_num) { 799219820Sjeff OSM_LOG(&p_osmt->log, OSM_LOG_ERROR, 800219820Sjeff "Unmatched number of records: expected: %d, received: %d\n", 801219820Sjeff rec_num, num_recs); 802219820Sjeff status = IB_REMOTE_ERROR; 803219820Sjeff goto Exit; 804219820Sjeff } 805219820Sjeff 806219820Sjeff p_rec = osmv_get_query_svc_rec(context.result.p_result_madw, 0); 807219820Sjeff *p_out_rec = *p_rec; 808219820Sjeff 809219820Sjeff if (num_recs) { 810219820Sjeff OSM_LOG(&p_osmt->log, OSM_LOG_VERBOSE, 811219820Sjeff "Found service record: name: %s id: 0x%016" PRIx64 "\n", 812219820Sjeff sr_name, cl_ntoh64(p_rec->service_id)); 813219820Sjeff 814219820Sjeff osm_dump_service_record(&p_osmt->log, p_rec, OSM_LOG_DEBUG); 815219820Sjeff } 816219820Sjeff 817219820SjeffExit: 818219820Sjeff OSM_LOG(&p_osmt->log, OSM_LOG_VERBOSE, 819219820Sjeff "Expected and found %d records\n", rec_num); 820219820Sjeff 821219820Sjeff if (context.result.p_result_madw != NULL) { 822219820Sjeff osm_mad_pool_put(&p_osmt->mad_pool, 823219820Sjeff context.result.p_result_madw); 824219820Sjeff context.result.p_result_madw = NULL; 825219820Sjeff } 826219820Sjeff 827219820Sjeff OSM_LOG_EXIT(&p_osmt->log); 828219820Sjeff return status; 829219820Sjeff} 830219820Sjeff 831219820Sjeff/********************************************************************** 832219820Sjeff **********************************************************************/ 833219820Sjeff 834219820Sjeffib_api_status_t 835219820Sjeffosmt_get_service_by_name(IN osmtest_t * const p_osmt, 836219820Sjeff IN char *sr_name, 837219820Sjeff IN uint32_t rec_num, 838219820Sjeff OUT ib_service_record_t * p_out_rec) 839219820Sjeff{ 840219820Sjeff 841219820Sjeff ib_api_status_t status = IB_SUCCESS; 842219820Sjeff osmtest_req_context_t context; 843219820Sjeff osmv_query_req_t req; 844219820Sjeff ib_service_record_t *p_rec; 845219820Sjeff ib_svc_name_t service_name; 846219820Sjeff uint32_t num_recs = 0; 847219820Sjeff 848219820Sjeff OSM_LOG_ENTER(&p_osmt->log); 849219820Sjeff 850219820Sjeff OSM_LOG(&p_osmt->log, OSM_LOG_VERBOSE, 851219820Sjeff "Getting service record: name: %s\n", sr_name); 852219820Sjeff 853219820Sjeff /* 854219820Sjeff * Do a blocking query for this record in the subnet. 855219820Sjeff * The result is returned in the result field of the caller's 856219820Sjeff * context structure. 857219820Sjeff * 858219820Sjeff * The query structures are locals. 859219820Sjeff */ 860219820Sjeff memset(&req, 0, sizeof(req)); 861219820Sjeff memset(&context, 0, sizeof(context)); 862219820Sjeff 863219820Sjeff context.p_osmt = p_osmt; 864219820Sjeff 865219820Sjeff /* prepare the data used for this query */ 866219820Sjeff req.query_type = OSMV_QUERY_SVC_REC_BY_NAME; 867219820Sjeff req.timeout_ms = p_osmt->opt.transaction_timeout; 868219820Sjeff req.retry_cnt = p_osmt->opt.retry_count; 869219820Sjeff req.flags = OSM_SA_FLAGS_SYNC; 870219820Sjeff req.query_context = &context; 871219820Sjeff req.pfn_query_cb = osmtest_query_res_cb; 872219820Sjeff req.sm_key = 0; 873219820Sjeff 874219820Sjeff memset(service_name, 0, sizeof(service_name)); 875219820Sjeff memcpy(service_name, sr_name, (strlen(sr_name) + 1) * sizeof(char)); 876219820Sjeff req.p_query_input = service_name; 877219820Sjeff 878219820Sjeff status = osmv_query_sa(p_osmt->h_bind, &req); 879219820Sjeff if (status != IB_SUCCESS) { 880219820Sjeff OSM_LOG(&p_osmt->log, OSM_LOG_ERROR, "ERR 4A0E: " 881219820Sjeff "ib_query failed (%s)\n", ib_get_err_str(status)); 882219820Sjeff goto Exit; 883219820Sjeff } 884219820Sjeff 885219820Sjeff status = context.result.status; 886219820Sjeff num_recs = context.result.result_cnt; 887219820Sjeff 888219820Sjeff if (status != IB_SUCCESS) { 889219820Sjeff char mad_stat_err[256]; 890219820Sjeff 891219820Sjeff /* If the failure is due to IB_SA_MAD_STATUS_NO_RECORDS and rec_num is 0, 892219820Sjeff then this is fine */ 893219820Sjeff if (status == IB_REMOTE_ERROR) 894219820Sjeff strcpy(mad_stat_err, 895219820Sjeff ib_get_mad_status_str(osm_madw_get_mad_ptr 896219820Sjeff (context.result. 897219820Sjeff p_result_madw))); 898219820Sjeff else 899219820Sjeff strcpy(mad_stat_err, ib_get_err_str(status)); 900219820Sjeff 901219820Sjeff if (status == IB_REMOTE_ERROR && 902219820Sjeff !strcmp(mad_stat_err, "IB_SA_MAD_STATUS_NO_RECORDS") && 903219820Sjeff rec_num == 0) { 904219820Sjeff OSM_LOG(&p_osmt->log, OSM_LOG_ERROR, 905219820Sjeff "IS EXPECTED ERROR ^^^^\n"); 906219820Sjeff status = IB_SUCCESS; 907219820Sjeff } else { 908219820Sjeff OSM_LOG(&p_osmt->log, OSM_LOG_ERROR, "ERR 4A0F: " 909219820Sjeff "Query failed: %s (%s)\n", 910219820Sjeff ib_get_err_str(status), mad_stat_err); 911219820Sjeff goto Exit; 912219820Sjeff } 913219820Sjeff } 914219820Sjeff 915219820Sjeff if (rec_num && num_recs != rec_num) { 916219820Sjeff OSM_LOG(&p_osmt->log, OSM_LOG_ERROR, "ERR 4A10: " 917219820Sjeff "Unmatched number of records: expected: %d, received: %d\n", 918219820Sjeff rec_num, num_recs); 919219820Sjeff status = IB_REMOTE_ERROR; 920219820Sjeff goto Exit; 921219820Sjeff } 922219820Sjeff 923219820Sjeff p_rec = osmv_get_query_svc_rec(context.result.p_result_madw, 0); 924219820Sjeff *p_out_rec = *p_rec; 925219820Sjeff 926219820Sjeff if (num_recs) { 927219820Sjeff OSM_LOG(&p_osmt->log, OSM_LOG_VERBOSE, 928219820Sjeff "Found service record: name: %s id: 0x%016" PRIx64 "\n", 929219820Sjeff sr_name, cl_ntoh64(p_rec->service_id)); 930219820Sjeff 931219820Sjeff osm_dump_service_record(&p_osmt->log, p_rec, OSM_LOG_DEBUG); 932219820Sjeff } 933219820Sjeff 934219820SjeffExit: 935219820Sjeff OSM_LOG(&p_osmt->log, OSM_LOG_VERBOSE, 936219820Sjeff "Expected and found %d records\n", rec_num); 937219820Sjeff 938219820Sjeff if (context.result.p_result_madw != NULL) { 939219820Sjeff osm_mad_pool_put(&p_osmt->mad_pool, 940219820Sjeff context.result.p_result_madw); 941219820Sjeff context.result.p_result_madw = NULL; 942219820Sjeff } 943219820Sjeff 944219820Sjeff OSM_LOG_EXIT(&p_osmt->log); 945219820Sjeff return status; 946219820Sjeff} 947219820Sjeff 948219820Sjeff/********************************************************************** 949219820Sjeff **********************************************************************/ 950219820Sjeff 951219820Sjeff#ifdef VENDOR_RMPP_SUPPORT 952219820Sjeffib_api_status_t 953219820Sjeffosmt_get_all_services_and_check_names(IN osmtest_t * const p_osmt, 954219820Sjeff IN ib_svc_name_t * 955219820Sjeff const p_valid_service_names_arr, 956219820Sjeff IN uint8_t num_of_valid_names, 957219820Sjeff OUT uint32_t * num_services) 958219820Sjeff{ 959219820Sjeff ib_api_status_t status = IB_SUCCESS; 960219820Sjeff osmtest_req_context_t context; 961219820Sjeff osmv_query_req_t req; 962219820Sjeff ib_service_record_t *p_rec; 963219820Sjeff uint32_t num_recs = 0, i, j; 964219820Sjeff uint8_t *p_checked_names; 965219820Sjeff 966219820Sjeff OSM_LOG_ENTER(&p_osmt->log); 967219820Sjeff 968219820Sjeff /* Prepare tracker for the checked names */ 969219820Sjeff p_checked_names = 970219820Sjeff (uint8_t *) malloc(sizeof(uint8_t) * num_of_valid_names); 971219820Sjeff for (j = 0; j < num_of_valid_names; j++) { 972219820Sjeff p_checked_names[j] = 0; 973219820Sjeff } 974219820Sjeff 975219820Sjeff OSM_LOG(&p_osmt->log, OSM_LOG_VERBOSE, "Getting all service records\n"); 976219820Sjeff 977219820Sjeff /* 978219820Sjeff * Do a blocking query for this record in the subnet. 979219820Sjeff * The result is returned in the result field of the caller's 980219820Sjeff * context structure. 981219820Sjeff * 982219820Sjeff * The query structures are locals. 983219820Sjeff */ 984219820Sjeff memset(&req, 0, sizeof(req)); 985219820Sjeff memset(&context, 0, sizeof(context)); 986219820Sjeff 987219820Sjeff context.p_osmt = p_osmt; 988219820Sjeff 989219820Sjeff req.query_type = OSMV_QUERY_ALL_SVC_RECS; 990219820Sjeff req.timeout_ms = p_osmt->opt.transaction_timeout; 991219820Sjeff req.retry_cnt = p_osmt->opt.retry_count; 992219820Sjeff req.flags = OSM_SA_FLAGS_SYNC; 993219820Sjeff req.query_context = &context; 994219820Sjeff req.pfn_query_cb = osmtest_query_res_cb; 995219820Sjeff req.sm_key = 0; 996219820Sjeff 997219820Sjeff status = osmv_query_sa(p_osmt->h_bind, &req); 998219820Sjeff if (status != IB_SUCCESS) { 999219820Sjeff OSM_LOG(&p_osmt->log, OSM_LOG_ERROR, "ERR 4A12: " 1000219820Sjeff "ib_query failed (%s)\n", ib_get_err_str(status)); 1001219820Sjeff goto Exit; 1002219820Sjeff } 1003219820Sjeff 1004219820Sjeff status = context.result.status; 1005219820Sjeff 1006219820Sjeff if (status != IB_SUCCESS) { 1007219820Sjeff if (status != IB_INVALID_PARAMETER) { 1008219820Sjeff OSM_LOG(&p_osmt->log, OSM_LOG_ERROR, "ERR 4A13: " 1009219820Sjeff "ib_query failed (%s)\n", ib_get_err_str(status)); 1010219820Sjeff } 1011219820Sjeff if (status == IB_REMOTE_ERROR) { 1012219820Sjeff OSM_LOG(&p_osmt->log, OSM_LOG_ERROR, 1013219820Sjeff "Remote error = %s\n", 1014219820Sjeff ib_get_mad_status_str(osm_madw_get_mad_ptr 1015219820Sjeff (context.result. 1016219820Sjeff p_result_madw))); 1017219820Sjeff } 1018219820Sjeff goto Exit; 1019219820Sjeff } 1020219820Sjeff 1021219820Sjeff num_recs = context.result.result_cnt; 1022219820Sjeff OSM_LOG(&p_osmt->log, OSM_LOG_VERBOSE, 1023219820Sjeff "Received %u records\n", num_recs); 1024219820Sjeff 1025219820Sjeff for (i = 0; i < num_recs; i++) { 1026219820Sjeff p_rec = osmv_get_query_svc_rec(context.result.p_result_madw, i); 1027219820Sjeff OSM_LOG(&p_osmt->log, OSM_LOG_VERBOSE, 1028219820Sjeff "Found service record: name: %s id: 0x%016" PRIx64 "\n", 1029219820Sjeff p_rec->service_name, cl_ntoh64(p_rec->service_id)); 1030219820Sjeff osm_dump_service_record(&p_osmt->log, p_rec, OSM_LOG_VERBOSE); 1031219820Sjeff for (j = 0; j < num_of_valid_names; j++) { 1032219820Sjeff /* If the service names exist in the record, mark it as checked (1) */ 1033219820Sjeff OSM_LOG(&p_osmt->log, OSM_LOG_VERBOSE, 1034219820Sjeff "-I- Comparing source name : >%s<, with record name : >%s<, idx : %d\n", 1035219820Sjeff p_valid_service_names_arr[j], 1036219820Sjeff p_rec->service_name, p_checked_names[j]); 1037219820Sjeff if (strcmp 1038219820Sjeff ((char *)p_valid_service_names_arr[j], 1039219820Sjeff (char *)p_rec->service_name) == 0) { 1040219820Sjeff OSM_LOG(&p_osmt->log, OSM_LOG_VERBOSE, 1041219820Sjeff "-I- The service %s is valid\n", 1042219820Sjeff p_valid_service_names_arr[j]); 1043219820Sjeff p_checked_names[j] = 1; 1044219820Sjeff break; 1045219820Sjeff } 1046219820Sjeff } 1047219820Sjeff } 1048219820Sjeff /* Check that all service names have been identified */ 1049219820Sjeff for (j = 0; j < num_of_valid_names; j++) 1050219820Sjeff if (p_checked_names[j] == 0) { 1051219820Sjeff OSM_LOG(&p_osmt->log, OSM_LOG_ERROR, "ERR 4A14: " 1052219820Sjeff "Missing valid service: name: %s\n", 1053219820Sjeff p_valid_service_names_arr[j]); 1054219820Sjeff status = IB_ERROR; 1055219820Sjeff goto Exit; 1056219820Sjeff } 1057219820Sjeff *num_services = num_recs; 1058219820Sjeff 1059219820SjeffExit: 1060219820Sjeff if (context.result.p_result_madw != NULL) { 1061219820Sjeff osm_mad_pool_put(&p_osmt->mad_pool, 1062219820Sjeff context.result.p_result_madw); 1063219820Sjeff context.result.p_result_madw = NULL; 1064219820Sjeff } 1065219820Sjeff 1066219820Sjeff OSM_LOG_EXIT(&p_osmt->log); 1067219820Sjeff return status; 1068219820Sjeff} 1069219820Sjeff#endif 1070219820Sjeff 1071219820Sjeff/********************************************************************** 1072219820Sjeff **********************************************************************/ 1073219820Sjeff 1074219820Sjeffib_api_status_t 1075219820Sjeffosmt_delete_service_by_name(IN osmtest_t * const p_osmt, 1076219820Sjeff IN uint8_t IsServiceExist, 1077219820Sjeff IN char *sr_name, IN uint32_t rec_num) 1078219820Sjeff{ 1079219820Sjeff osmv_query_req_t req; 1080219820Sjeff osmv_user_query_t user; 1081219820Sjeff osmtest_req_context_t context; 1082219820Sjeff ib_service_record_t svc_rec; 1083219820Sjeff ib_api_status_t status; 1084219820Sjeff 1085219820Sjeff OSM_LOG_ENTER(&p_osmt->log); 1086219820Sjeff 1087219820Sjeff OSM_LOG(&p_osmt->log, OSM_LOG_INFO, 1088219820Sjeff "Trying to Delete service name: %s\n", sr_name); 1089219820Sjeff 1090219820Sjeff memset(&svc_rec, 0, sizeof(svc_rec)); 1091219820Sjeff 1092219820Sjeff status = osmt_get_service_by_name(p_osmt, sr_name, rec_num, &svc_rec); 1093219820Sjeff if (status != IB_SUCCESS) { 1094219820Sjeff OSM_LOG(&p_osmt->log, OSM_LOG_ERROR, "ERR 4A15: " 1095219820Sjeff "Failed to get service: name: %s\n", sr_name); 1096219820Sjeff goto ExitNoDel; 1097219820Sjeff } 1098219820Sjeff 1099219820Sjeff memset(&req, 0, sizeof(req)); 1100219820Sjeff memset(&context, 0, sizeof(context)); 1101219820Sjeff memset(&user, 0, sizeof(user)); 1102219820Sjeff 1103219820Sjeff /* set the new service record fields */ 1104219820Sjeff memset(svc_rec.service_name, 0, sizeof(svc_rec.service_name)); 1105219820Sjeff memcpy(svc_rec.service_name, sr_name, 1106219820Sjeff (strlen(sr_name) + 1) * sizeof(char)); 1107219820Sjeff 1108219820Sjeff /* prepare the data used for this query */ 1109219820Sjeff context.p_osmt = p_osmt; 1110219820Sjeff req.timeout_ms = p_osmt->opt.transaction_timeout; 1111219820Sjeff req.query_context = &context; 1112219820Sjeff req.query_type = OSMV_QUERY_USER_DEFINED; /* basically a don't care here */ 1113219820Sjeff req.pfn_query_cb = osmtest_query_res_cb; 1114219820Sjeff req.p_query_input = &user; 1115219820Sjeff req.flags = OSM_SA_FLAGS_SYNC; 1116219820Sjeff req.sm_key = 0; 1117219820Sjeff 1118219820Sjeff user.method = IB_MAD_METHOD_DELETE; 1119219820Sjeff user.attr_id = IB_MAD_ATTR_SERVICE_RECORD; 1120219820Sjeff user.comp_mask = IB_SR_COMPMASK_SNAME; 1121219820Sjeff user.attr_offset = ib_get_attr_offset(sizeof(ib_service_record_t)); 1122219820Sjeff user.p_attr = &svc_rec; 1123219820Sjeff 1124219820Sjeff status = osmv_query_sa(p_osmt->h_bind, &req); 1125219820Sjeff if (status != IB_SUCCESS) { 1126219820Sjeff OSM_LOG(&p_osmt->log, OSM_LOG_ERROR, "ERR 4A16: " 1127219820Sjeff "ib_query failed (%s)\n", ib_get_err_str(status)); 1128219820Sjeff goto Exit; 1129219820Sjeff } 1130219820Sjeff 1131219820Sjeff status = context.result.status; 1132219820Sjeff if (IsServiceExist) { 1133219820Sjeff /* If IsServiceExist = 1 then we should succeed here */ 1134219820Sjeff if (status != IB_SUCCESS) { 1135219820Sjeff OSM_LOG(&p_osmt->log, OSM_LOG_ERROR, "ERR 4A17: " 1136219820Sjeff "ib_query failed (%s)\n", 1137219820Sjeff ib_get_err_str(status)); 1138219820Sjeff 1139219820Sjeff if (status == IB_REMOTE_ERROR) { 1140219820Sjeff OSM_LOG(&p_osmt->log, OSM_LOG_ERROR, 1141219820Sjeff "ERR 4A18: Remote error = %s\n", 1142219820Sjeff ib_get_mad_status_str 1143219820Sjeff (osm_madw_get_mad_ptr 1144219820Sjeff (context.result.p_result_madw))); 1145219820Sjeff } 1146219820Sjeff } 1147219820Sjeff } else { 1148219820Sjeff /* If IsServiceExist = 0 then we should fail here */ 1149219820Sjeff if (status == IB_SUCCESS) { 1150219820Sjeff OSM_LOG(&p_osmt->log, OSM_LOG_ERROR, "ERR 4A19: " 1151219820Sjeff "Succeeded to delete service: %s which " 1152219820Sjeff "shouldn't exist", sr_name); 1153219820Sjeff status = IB_ERROR; 1154219820Sjeff } else { 1155219820Sjeff /* The deletion should have failed, since the service_name 1156219820Sjeff shouldn't exist. */ 1157219820Sjeff OSM_LOG(&p_osmt->log, OSM_LOG_ERROR, 1158219820Sjeff "IS EXPECTED ERROR ^^^^\n"); 1159219820Sjeff OSM_LOG(&p_osmt->log, OSM_LOG_INFO, 1160219820Sjeff "Failed to delete service_name: %s\n", sr_name); 1161219820Sjeff status = IB_SUCCESS; 1162219820Sjeff } 1163219820Sjeff } 1164219820Sjeff 1165219820SjeffExit: 1166219820Sjeff if (context.result.p_result_madw != NULL) { 1167219820Sjeff osm_mad_pool_put(&p_osmt->mad_pool, 1168219820Sjeff context.result.p_result_madw); 1169219820Sjeff context.result.p_result_madw = NULL; 1170219820Sjeff } 1171219820Sjeff 1172219820SjeffExitNoDel: 1173219820Sjeff OSM_LOG_EXIT(&p_osmt->log); 1174219820Sjeff return status; 1175219820Sjeff} 1176219820Sjeff 1177219820Sjeff/********************************************************************** 1178219820Sjeff **********************************************************************/ 1179219820Sjeff 1180219820Sjeff/* 1181219820Sjeff * Run a complete service records flow: 1182219820Sjeff * - register a service 1183219820Sjeff * - register a service (with a lease period) 1184219820Sjeff * - get a service by name 1185219820Sjeff * - get all services / must be 2 1186219820Sjeff * - delete a service 1187219820Sjeff * - get all services / must be 1 1188219820Sjeff * - wait for the lease to expire 1189219820Sjeff * - get all services / must be 0 1190219820Sjeff * - get / set service by data 1191219820Sjeff */ 1192219820Sjeffib_api_status_t osmt_run_service_records_flow(IN osmtest_t * const p_osmt) 1193219820Sjeff{ 1194219820Sjeff ib_service_record_t srv_rec; 1195219820Sjeff ib_api_status_t status; 1196219820Sjeff uint8_t instance, i; 1197219820Sjeff uint8_t service_data8[16], service_key[16]; 1198219820Sjeff ib_net16_t service_data16[8]; 1199219820Sjeff ib_net32_t service_data32[4]; 1200219820Sjeff ib_net64_t service_data64[2]; 1201219820Sjeff uint64_t pid = getpid(); 1202219820Sjeff uint64_t id[7]; 1203219820Sjeff /* We use up to seven service names - we use the extra for bad flow */ 1204219820Sjeff ib_svc_name_t service_name[7]; 1205219820Sjeff#ifdef VENDOR_RMPP_SUPPORT 1206219820Sjeff /* This array contain only the valid names after registering vs SM */ 1207219820Sjeff ib_svc_name_t service_valid_names[3]; 1208219820Sjeff uint32_t num_recs = 0; 1209219820Sjeff#endif 1210219820Sjeff 1211219820Sjeff OSM_LOG_ENTER(&p_osmt->log); 1212219820Sjeff 1213219820Sjeff /* Init Service names */ 1214219820Sjeff for (i = 0; i < 7; i++) { 1215219820Sjeff#ifdef __WIN__ 1216219820Sjeff uint64_t rand_val = rand() - (uint64_t) i; 1217219820Sjeff#else 1218219820Sjeff uint64_t rand_val = random() - (uint64_t) i; 1219219820Sjeff#endif 1220219820Sjeff id[i] = abs((int)(pid - rand_val)); 1221219820Sjeff /* Just to be unique any place on any host */ 1222219820Sjeff sprintf((char *)(service_name[i]), 1223219820Sjeff "osmt.srvc.%" PRIu64 ".%" PRIu64, rand_val, pid); 1224219820Sjeff /*printf("-I- Service Name is : %s, ID is : 0x%" PRIx64 "\n",service_name[i],id[i]); */ 1225219820Sjeff } 1226219820Sjeff 1227219820Sjeff status = osmt_register_service(p_osmt, cl_ntoh64(id[0]), /* IN ib_net64_t service_id, */ 1228219820Sjeff IB_DEFAULT_PKEY, /* IN ib_net16_t service_pkey, */ 1229219820Sjeff 0xFFFFFFFF, /* IN ib_net32_t service_lease, */ 1230219820Sjeff 11, /* IN uint8_t service_key_lsb, */ 1231219820Sjeff (char *)service_name[0] /* IN char *service_name */ 1232219820Sjeff ); 1233219820Sjeff if (status != IB_SUCCESS) { 1234219820Sjeff goto Exit; 1235219820Sjeff } 1236219820Sjeff 1237219820Sjeff status = osmt_register_service(p_osmt, cl_ntoh64(id[1]), /* IN ib_net64_t service_id, */ 1238219820Sjeff IB_DEFAULT_PKEY, /* IN ib_net16_t service_pkey, */ 1239219820Sjeff cl_hton32(0x00000004), /* IN ib_net32_t service_lease, */ 1240219820Sjeff 11, /* IN uint8_t service_key_lsb, */ 1241219820Sjeff (char *)service_name[1] /* IN char *service_name */ 1242219820Sjeff ); 1243219820Sjeff if (status != IB_SUCCESS) { 1244219820Sjeff goto Exit; 1245219820Sjeff } 1246219820Sjeff 1247219820Sjeff status = osmt_register_service(p_osmt, cl_ntoh64(id[2]), /* IN ib_net64_t service_id, */ 1248219820Sjeff 0, /* IN ib_net16_t service_pkey, */ 1249219820Sjeff 0xFFFFFFFF, /* IN ib_net32_t service_lease, */ 1250219820Sjeff 11, /* Remove Service Record IN uint8_t service_key_lsb, */ 1251219820Sjeff (char *)service_name[2] /* IN char *service_name */ 1252219820Sjeff ); 1253219820Sjeff 1254219820Sjeff if (status != IB_SUCCESS) { 1255219820Sjeff goto Exit; 1256219820Sjeff } 1257219820Sjeff 1258219820Sjeff /* Generate 2 instances of service record with consecutive data */ 1259219820Sjeff for (instance = 0; instance < 2; instance++) { 1260219820Sjeff /* First, clear all arrays */ 1261219820Sjeff memset(service_data8, 0, 16 * sizeof(uint8_t)); 1262219820Sjeff memset(service_data16, 0, 8 * sizeof(uint16_t)); 1263219820Sjeff memset(service_data32, 0, 4 * sizeof(uint32_t)); 1264219820Sjeff memset(service_data64, 0, 2 * sizeof(uint64_t)); 1265219820Sjeff service_data8[instance] = instance + 1; 1266219820Sjeff service_data16[instance] = cl_hton16(instance + 2); 1267219820Sjeff service_data32[instance] = cl_hton32(instance + 3); 1268219820Sjeff service_data64[instance] = cl_hton64(instance + 4); 1269219820Sjeff status = osmt_register_service_with_data(p_osmt, cl_ntoh64(id[3]), /* IN ib_net64_t service_id, */ 1270219820Sjeff IB_DEFAULT_PKEY, /* IN ib_net16_t service_pkey, */ 1271219820Sjeff cl_ntoh32(10), /* IN ib_net32_t service_lease, */ 1272219820Sjeff 12, /* IN uint8_t service_key_lsb, */ 1273219820Sjeff service_data8, service_data16, service_data32, service_data64, /* service data structures */ 1274219820Sjeff (char *)service_name[3] /* IN char *service_name */ 1275219820Sjeff ); 1276219820Sjeff 1277219820Sjeff if (status != IB_SUCCESS) { 1278219820Sjeff goto Exit; 1279219820Sjeff } 1280219820Sjeff 1281219820Sjeff } 1282219820Sjeff 1283219820Sjeff /* Trying to create service with zero key */ 1284219820Sjeff memset(service_key, 0, 16 * sizeof(uint8_t)); 1285219820Sjeff status = osmt_register_service_with_full_key(p_osmt, cl_ntoh64(id[5]), /* IN ib_net64_t service_id, */ 1286219820Sjeff 0, /* IN ib_net16_t service_pkey, */ 1287219820Sjeff 0xFFFFFFFF, /* IN ib_net32_t service_lease, */ 1288219820Sjeff service_key, /* full service_key, */ 1289219820Sjeff (char *)service_name[5] /* IN char *service_name */ 1290219820Sjeff ); 1291219820Sjeff 1292219820Sjeff if (status != IB_SUCCESS) { 1293219820Sjeff goto Exit; 1294219820Sjeff } 1295219820Sjeff 1296219820Sjeff /* Now update it with Unique key and different service name */ 1297219820Sjeff for (i = 0; i <= 15; i++) { 1298219820Sjeff service_key[i] = i + 1; 1299219820Sjeff } 1300219820Sjeff status = osmt_register_service_with_full_key(p_osmt, cl_ntoh64(id[5]), /* IN ib_net64_t service_id, */ 1301219820Sjeff 0, /* IN ib_net16_t service_pkey, */ 1302219820Sjeff 0xFFFFFFFF, /* IN ib_net32_t service_lease, */ 1303219820Sjeff service_key, /* full service_key, */ 1304219820Sjeff (char *)service_name[6] /* IN char *service_name */ 1305219820Sjeff ); 1306219820Sjeff if (status != IB_SUCCESS) { 1307219820Sjeff goto Exit; 1308219820Sjeff } 1309219820Sjeff 1310219820Sjeff /* Let OpenSM handle it */ 1311219820Sjeff usleep(100); 1312219820Sjeff 1313219820Sjeff /* Make sure service_name[0] exists */ 1314219820Sjeff status = osmt_get_service_by_name(p_osmt, 1315219820Sjeff (char *)service_name[0], 1, &srv_rec); 1316219820Sjeff if (status != IB_SUCCESS) { 1317219820Sjeff OSM_LOG(&p_osmt->log, OSM_LOG_ERROR, "ERR 4A1A: " 1318219820Sjeff "Fail to find service: name: %s\n", 1319219820Sjeff (char *)service_name[0]); 1320219820Sjeff status = IB_ERROR; 1321219820Sjeff goto Exit; 1322219820Sjeff } 1323219820Sjeff 1324219820Sjeff /* Make sure service_name[1] exists */ 1325219820Sjeff status = osmt_get_service_by_name(p_osmt, 1326219820Sjeff (char *)service_name[1], 1, &srv_rec); 1327219820Sjeff if (status != IB_SUCCESS) { 1328219820Sjeff OSM_LOG(&p_osmt->log, OSM_LOG_ERROR, "ERR 4A1B: " 1329219820Sjeff "Fail to find service: name: %s\n", 1330219820Sjeff (char *)service_name[1]); 1331219820Sjeff status = IB_ERROR; 1332219820Sjeff goto Exit; 1333219820Sjeff } 1334219820Sjeff 1335219820Sjeff /* Make sure service_name[2] exists */ 1336219820Sjeff status = osmt_get_service_by_name(p_osmt, 1337219820Sjeff (char *)service_name[2], 1, &srv_rec); 1338219820Sjeff if (status != IB_SUCCESS) { 1339219820Sjeff OSM_LOG(&p_osmt->log, OSM_LOG_ERROR, "ERR 4A1C: " 1340219820Sjeff "Fail to find service: name: %s\n", 1341219820Sjeff (char *)service_name[2]); 1342219820Sjeff status = IB_ERROR; 1343219820Sjeff goto Exit; 1344219820Sjeff } 1345219820Sjeff 1346219820Sjeff /* Make sure service_name[3] exists. */ 1347219820Sjeff /* After 10 seconds the service should not exist: service_lease = 10 */ 1348219820Sjeff status = osmt_get_service_by_name(p_osmt, 1349219820Sjeff (char *)service_name[3], 1, &srv_rec); 1350219820Sjeff if (status != IB_SUCCESS) { 1351219820Sjeff OSM_LOG(&p_osmt->log, OSM_LOG_ERROR, "ERR 4A1D: " 1352219820Sjeff "Fail to find service: name: %s\n", 1353219820Sjeff (char *)service_name[3]); 1354219820Sjeff status = IB_ERROR; 1355219820Sjeff goto Exit; 1356219820Sjeff } 1357219820Sjeff 1358219820Sjeff sleep(10); 1359219820Sjeff 1360219820Sjeff status = osmt_get_service_by_name(p_osmt, 1361219820Sjeff (char *)service_name[3], 0, &srv_rec); 1362219820Sjeff if (status != IB_SUCCESS) { 1363219820Sjeff OSM_LOG(&p_osmt->log, OSM_LOG_ERROR, "ERR 4A1E: " 1364219820Sjeff "Found service: name: %s that should have been " 1365219820Sjeff "deleted due to service lease expiring\n", 1366219820Sjeff (char *)service_name[3]); 1367219820Sjeff status = IB_ERROR; 1368219820Sjeff goto Exit; 1369219820Sjeff } 1370219820Sjeff 1371219820Sjeff /* Check that for service: id[5] only one record exists */ 1372219820Sjeff status = osmt_get_service_by_id(p_osmt, 1, cl_ntoh64(id[5]), &srv_rec); 1373219820Sjeff if (status != IB_SUCCESS) { 1374219820Sjeff OSM_LOG(&p_osmt->log, OSM_LOG_ERROR, "ERR 4A1F: " 1375219820Sjeff "Found number of records != 1 for " 1376219820Sjeff "service: id: 0x%016" PRIx64 "\n", id[5]); 1377219820Sjeff status = IB_ERROR; 1378219820Sjeff goto Exit; 1379219820Sjeff } 1380219820Sjeff 1381219820Sjeff /* Bad Flow of Get with invalid Service ID: id[6] */ 1382219820Sjeff status = osmt_get_service_by_id(p_osmt, 0, cl_ntoh64(id[6]), &srv_rec); 1383219820Sjeff if (status != IB_SUCCESS) { 1384219820Sjeff OSM_LOG(&p_osmt->log, OSM_LOG_ERROR, "ERR 4A20: " 1385219820Sjeff "Found service: id: 0x%016" PRIx64 " " 1386219820Sjeff "that is invalid\n", id[6]); 1387219820Sjeff status = IB_ERROR; 1388219820Sjeff goto Exit; 1389219820Sjeff } 1390219820Sjeff 1391219820Sjeff /* Check by both id and service name: id[0], service_name[0] */ 1392219820Sjeff status = osmt_get_service_by_id_and_name(p_osmt, 1, cl_ntoh64(id[0]), 1393219820Sjeff (char *)service_name[0], 1394219820Sjeff &srv_rec); 1395219820Sjeff if (status != IB_SUCCESS) { 1396219820Sjeff OSM_LOG(&p_osmt->log, OSM_LOG_ERROR, "ERR 4A21: " 1397219820Sjeff "Fail to find service: id: 0x%016" PRIx64 " " 1398219820Sjeff "name: %s\n", id[0], (char *)service_name[0]); 1399219820Sjeff status = IB_ERROR; 1400219820Sjeff goto Exit; 1401219820Sjeff } 1402219820Sjeff 1403219820Sjeff /* Check by both id and service name: id[5], service_name[6] */ 1404219820Sjeff status = osmt_get_service_by_id_and_name(p_osmt, 1, cl_ntoh64(id[5]), 1405219820Sjeff (char *)service_name[6], 1406219820Sjeff &srv_rec); 1407219820Sjeff if (status != IB_SUCCESS) { 1408219820Sjeff OSM_LOG(&p_osmt->log, OSM_LOG_ERROR, "ERR 4A22: " 1409219820Sjeff "Fail to find service: id: 0x%016" PRIx64 " " 1410219820Sjeff "name: %s\n", id[5], (char *)service_name[6]); 1411219820Sjeff status = IB_ERROR; 1412219820Sjeff goto Exit; 1413219820Sjeff } 1414219820Sjeff 1415219820Sjeff /* Bad Flow of Get with invalid name(service_name[3]) and valid ID(id[0]) */ 1416219820Sjeff status = osmt_get_service_by_id_and_name(p_osmt, 0, cl_ntoh64(id[0]), 1417219820Sjeff (char *)service_name[3], 1418219820Sjeff &srv_rec); 1419219820Sjeff if (status != IB_SUCCESS) { 1420219820Sjeff OSM_LOG(&p_osmt->log, OSM_LOG_ERROR, "ERR 4A23: " 1421219820Sjeff "Found service: id: 0x%016" PRIx64 1422219820Sjeff "name: %s which is an invalid service\n", 1423219820Sjeff id[0], (char *)service_name[3]); 1424219820Sjeff status = IB_ERROR; 1425219820Sjeff goto Exit; 1426219820Sjeff } 1427219820Sjeff 1428219820Sjeff /* Bad Flow of Get with unmatched name(service_name[5]) and id(id[3]) (both valid) */ 1429219820Sjeff status = osmt_get_service_by_id_and_name(p_osmt, 0, cl_ntoh64(id[3]), 1430219820Sjeff (char *)service_name[5], 1431219820Sjeff &srv_rec); 1432219820Sjeff if (status != IB_SUCCESS) { 1433219820Sjeff OSM_LOG(&p_osmt->log, OSM_LOG_ERROR, "ERR 4A24: " 1434219820Sjeff "Found service: id: 0x%016" PRIx64 1435219820Sjeff "name: %s which is an invalid service\n", 1436219820Sjeff id[3], (char *)service_name[5]); 1437219820Sjeff status = IB_ERROR; 1438219820Sjeff goto Exit; 1439219820Sjeff } 1440219820Sjeff 1441219820Sjeff /* Bad Flow of Get with service name that doesn't exist (service_name[4]) */ 1442219820Sjeff status = osmt_get_service_by_name(p_osmt, 1443219820Sjeff (char *)service_name[4], 0, &srv_rec); 1444219820Sjeff if (status != IB_SUCCESS) { 1445219820Sjeff OSM_LOG(&p_osmt->log, OSM_LOG_ERROR, "ERR 4A25: " 1446219820Sjeff "Found service: name: %s that shouldn't exist\n", 1447219820Sjeff (char *)service_name[4]); 1448219820Sjeff status = IB_ERROR; 1449219820Sjeff goto Exit; 1450219820Sjeff } 1451219820Sjeff 1452219820Sjeff /* Bad Flow : Check that getting service_name[5] brings no records since another service 1453219820Sjeff has been updated with the same ID (service_name[6] */ 1454219820Sjeff status = osmt_get_service_by_name(p_osmt, 1455219820Sjeff (char *)service_name[5], 0, &srv_rec); 1456219820Sjeff if (status != IB_SUCCESS) { 1457219820Sjeff OSM_LOG(&p_osmt->log, OSM_LOG_ERROR, "ERR 4A26: " 1458219820Sjeff "Found service: name: %s which is an " 1459219820Sjeff "invalid service\n", (char *)service_name[5]); 1460219820Sjeff status = IB_ERROR; 1461219820Sjeff goto Exit; 1462219820Sjeff } 1463219820Sjeff 1464219820Sjeff /* Check that getting service_name[6] by name ONLY is valid, 1465219820Sjeff since we do not support key&name association, also trusted queries */ 1466219820Sjeff status = osmt_get_service_by_name(p_osmt, 1467219820Sjeff (char *)service_name[6], 1, &srv_rec); 1468219820Sjeff if (status != IB_SUCCESS) { 1469219820Sjeff OSM_LOG(&p_osmt->log, OSM_LOG_ERROR, "ERR 4A27: " 1470219820Sjeff "Fail to find service: name: %s\n", 1471219820Sjeff (char *)service_name[6]); 1472219820Sjeff status = IB_ERROR; 1473219820Sjeff goto Exit; 1474219820Sjeff } 1475219820Sjeff 1476219820Sjeff /* Test Service Key */ 1477219820Sjeff memset(service_key, 0, 16 * sizeof(uint8_t)); 1478219820Sjeff 1479219820Sjeff /* Check for service_name[5] with service_key=0 - the service shouldn't 1480219820Sjeff exist with this name. */ 1481219820Sjeff status = osmt_get_service_by_name_and_key(p_osmt, 1482219820Sjeff (char *)service_name[5], 1483219820Sjeff 0, service_key, &srv_rec); 1484219820Sjeff if (status != IB_SUCCESS) { 1485219820Sjeff OSM_LOG(&p_osmt->log, OSM_LOG_ERROR, "ERR 4A28: " 1486219820Sjeff "Found service: name: %s key:0 which is an " 1487219820Sjeff "invalid service (wrong name)\n", 1488219820Sjeff (char *)service_name[5]); 1489219820Sjeff status = IB_ERROR; 1490219820Sjeff goto Exit; 1491219820Sjeff } 1492219820Sjeff 1493219820Sjeff /* Check for service_name[6] with service_key=0 - the service should 1494219820Sjeff exist with different key. */ 1495219820Sjeff status = osmt_get_service_by_name_and_key(p_osmt, 1496219820Sjeff (char *)service_name[6], 1497219820Sjeff 0, service_key, &srv_rec); 1498219820Sjeff if (status != IB_SUCCESS) { 1499219820Sjeff OSM_LOG(&p_osmt->log, OSM_LOG_ERROR, "ERR 4A29: " 1500219820Sjeff "Found service: name: %s key: 0 which is an " 1501219820Sjeff "invalid service (wrong service_key)\n", 1502219820Sjeff (char *)service_name[6]); 1503219820Sjeff status = IB_ERROR; 1504219820Sjeff goto Exit; 1505219820Sjeff } 1506219820Sjeff 1507219820Sjeff /* check for service_name[6] with the correct service_key */ 1508219820Sjeff for (i = 0; i <= 15; i++) 1509219820Sjeff service_key[i] = i + 1; 1510219820Sjeff status = osmt_get_service_by_name_and_key(p_osmt, 1511219820Sjeff (char *)service_name[6], 1512219820Sjeff 1, service_key, &srv_rec); 1513219820Sjeff if (status != IB_SUCCESS) { 1514219820Sjeff OSM_LOG(&p_osmt->log, OSM_LOG_ERROR, "ERR 4A2A: " 1515219820Sjeff "Fail to find service: name: %s with " 1516219820Sjeff "correct service key\n", (char *)service_name[6]); 1517219820Sjeff status = IB_ERROR; 1518219820Sjeff goto Exit; 1519219820Sjeff } 1520219820Sjeff#ifdef VENDOR_RMPP_SUPPORT 1521219820Sjeff /* These ar the only service_names which are valid */ 1522219820Sjeff memcpy(&service_valid_names[0], &service_name[0], sizeof(uint8_t) * 64); 1523219820Sjeff memcpy(&service_valid_names[1], &service_name[2], sizeof(uint8_t) * 64); 1524219820Sjeff memcpy(&service_valid_names[2], &service_name[6], sizeof(uint8_t) * 64); 1525219820Sjeff 1526219820Sjeff status = 1527219820Sjeff osmt_get_all_services_and_check_names(p_osmt, service_valid_names, 1528219820Sjeff 3, &num_recs); 1529219820Sjeff if (status != IB_SUCCESS) { 1530219820Sjeff OSM_LOG(&p_osmt->log, OSM_LOG_ERROR, "ERR 4A2B: " 1531219820Sjeff "Fail to find all services that should exist\n"); 1532219820Sjeff status = IB_ERROR; 1533219820Sjeff goto Exit; 1534219820Sjeff } 1535219820Sjeff#endif 1536219820Sjeff 1537219820Sjeff /* Delete service_name[0] */ 1538219820Sjeff status = osmt_delete_service_by_name(p_osmt, 1, 1539219820Sjeff (char *)service_name[0], 1); 1540219820Sjeff if (status != IB_SUCCESS) { 1541219820Sjeff OSM_LOG(&p_osmt->log, OSM_LOG_ERROR, "ERR 4A2C: " 1542219820Sjeff "Fail to delete service: name: %s\n", 1543219820Sjeff (char *)service_name[0]); 1544219820Sjeff status = IB_ERROR; 1545219820Sjeff goto Exit; 1546219820Sjeff } 1547219820Sjeff 1548219820Sjeff /* Make sure deletion of service_name[0] succeeded */ 1549219820Sjeff status = osmt_get_service_by_name(p_osmt, 1550219820Sjeff (char *)service_name[0], 0, &srv_rec); 1551219820Sjeff if (status != IB_SUCCESS) { 1552219820Sjeff OSM_LOG(&p_osmt->log, OSM_LOG_ERROR, "ERR 4A2D: " 1553219820Sjeff "Found service: name: %s that was deleted\n", 1554219820Sjeff (char *)service_name[0]); 1555219820Sjeff status = IB_ERROR; 1556219820Sjeff goto Exit; 1557219820Sjeff } 1558219820Sjeff 1559219820Sjeff /* Make sure service_name[1] doesn't exist (expired service lease) */ 1560219820Sjeff status = osmt_get_service_by_name(p_osmt, 1561219820Sjeff (char *)service_name[1], 0, &srv_rec); 1562219820Sjeff if (status != IB_SUCCESS) { 1563219820Sjeff OSM_LOG(&p_osmt->log, OSM_LOG_ERROR, "ERR 4A2E: " 1564219820Sjeff "Found service: name: %s that should have expired\n", 1565219820Sjeff (char *)service_name[1]); 1566219820Sjeff status = IB_ERROR; 1567219820Sjeff goto Exit; 1568219820Sjeff } 1569219820Sjeff 1570219820Sjeff /* Make sure service_name[2] exists */ 1571219820Sjeff status = osmt_get_service_by_name(p_osmt, 1572219820Sjeff (char *)service_name[2], 1, &srv_rec); 1573219820Sjeff if (status != IB_SUCCESS) { 1574219820Sjeff OSM_LOG(&p_osmt->log, OSM_LOG_ERROR, "ERR 4A2F: " 1575219820Sjeff "Fail to find service: name: %s\n", 1576219820Sjeff (char *)service_name[2]); 1577219820Sjeff status = IB_ERROR; 1578219820Sjeff goto Exit; 1579219820Sjeff } 1580219820Sjeff 1581219820Sjeff /* Bad Flow - try to delete non-existent service_name[5] */ 1582219820Sjeff status = osmt_delete_service_by_name(p_osmt, 0, 1583219820Sjeff (char *)service_name[5], 0); 1584219820Sjeff if (status != IB_SUCCESS) { 1585219820Sjeff OSM_LOG(&p_osmt->log, OSM_LOG_ERROR, "ERR 4A30: " 1586219820Sjeff "Succeed to delete non-existent service: name: %s\n", 1587219820Sjeff (char *)service_name[5]); 1588219820Sjeff status = IB_ERROR; 1589219820Sjeff goto Exit; 1590219820Sjeff } 1591219820Sjeff 1592219820Sjeff /* Delete service_name[2] */ 1593219820Sjeff status = osmt_delete_service_by_name(p_osmt, 1, 1594219820Sjeff (char *)service_name[2], 1); 1595219820Sjeff if (status != IB_SUCCESS) { 1596219820Sjeff OSM_LOG(&p_osmt->log, OSM_LOG_ERROR, "ERR 4A31: " 1597219820Sjeff "Fail to delete service: name: %s\n", 1598219820Sjeff (char *)service_name[2]); 1599219820Sjeff status = IB_ERROR; 1600219820Sjeff goto Exit; 1601219820Sjeff } 1602219820Sjeff 1603219820Sjeff /* Delete service_name[6] */ 1604219820Sjeff status = osmt_delete_service_by_name(p_osmt, 1, 1605219820Sjeff (char *)service_name[6], 1); 1606219820Sjeff if (status != IB_SUCCESS) { 1607219820Sjeff OSM_LOG(&p_osmt->log, OSM_LOG_ERROR, "ERR 4A32: " 1608219820Sjeff "Failed to delete service name: %s\n", 1609219820Sjeff (char *)service_name[6]); 1610219820Sjeff goto Exit; 1611219820Sjeff } 1612219820Sjeff 1613219820SjeffExit: 1614219820Sjeff OSM_LOG_EXIT(&p_osmt->log); 1615219820Sjeff return status; 1616219820Sjeff} 1617