/*---------------------------------------------------------------------------*/ hg_class_t * HG_Test_server_init(int argc, char *argv[], hg_addr_t **addr_table, unsigned int *addr_table_size, unsigned int *max_number_of_peers, hg_context_t **context) { size_t bulk_size = 1024 * 1024 * MERCURY_TESTING_BUFFER_SIZE; hg_return_t ret; hg_test_na_class_g = NA_Test_server_init(argc, argv, NA_FALSE, &hg_test_addr_name_table_g, &hg_test_addr_table_size_g, max_number_of_peers); hg_test_na_context_g = NA_Context_create(hg_test_na_class_g); /* Initalize atomic variable to finalize server */ hg_atomic_set32(&hg_test_finalizing_count_g, 0); #ifdef MERCURY_TESTING_HAS_THREAD_POOL hg_thread_mutex_init(&hg_test_local_bulk_handle_mutex_g); hg_thread_pool_init(MERCURY_TESTING_NUM_THREADS, &hg_test_thread_pool_g); printf("# Starting server with %d threads...\n", MERCURY_TESTING_NUM_THREADS); #endif ret = HG_Hl_init_na(hg_test_na_class_g, hg_test_na_context_g); if (ret != HG_SUCCESS) { fprintf(stderr, "Could not initialize Mercury\n"); goto done; } /* Register test routines */ hg_test_register(HG_CLASS_DEFAULT); /* Create bulk buffer that can be used for receiving data */ HG_Bulk_create(HG_CLASS_DEFAULT, 1, NULL, &bulk_size, HG_BULK_READWRITE, &hg_test_local_bulk_handle_g); if (hg_test_addr_table_size_g > 1) { unsigned int i; hg_test_addr_table_g = (hg_addr_t *) malloc(hg_test_addr_table_size_g * sizeof(hg_addr_t)); for (i = 0; i < hg_test_addr_table_size_g; i++) { ret = HG_Hl_addr_lookup_wait(HG_CONTEXT_DEFAULT, HG_REQUEST_CLASS_DEFAULT, hg_test_addr_name_table_g[i], &hg_test_addr_table_g[i], HG_MAX_IDLE_TIME); if (ret != HG_SUCCESS) { fprintf(stderr, "Could not find addr %s\n", hg_test_addr_name_table_g[i]); goto done; } } } if (addr_table) *addr_table = hg_test_addr_table_g; if (addr_table_size) *addr_table_size = hg_test_addr_table_size_g; /* Used by CTest Test Driver */ printf("Waiting for client...\n"); fflush(stdout); if (context) *context = HG_CONTEXT_DEFAULT; done: return HG_CLASS_DEFAULT; }
/*---------------------------------------------------------------------------*/ hg_class_t * HG_Test_client_init(int argc, char *argv[], hg_addr_t *addr, int *rank, hg_context_t **context, hg_request_class_t **request_class) { char test_addr_name[NA_TEST_MAX_ADDR_NAME]; hg_return_t ret; hg_test_na_class_g = NA_Test_client_init(argc, argv, test_addr_name, NA_TEST_MAX_ADDR_NAME, &hg_test_rank_g); hg_test_na_context_g = NA_Context_create(hg_test_na_class_g); ret = HG_Hl_init_na(hg_test_na_class_g, hg_test_na_context_g); if (ret != HG_SUCCESS) { fprintf(stderr, "Could not initialize Mercury\n"); goto done; } if (na_test_use_self_g) { size_t bulk_size = 1024 * 1024 * MERCURY_TESTING_BUFFER_SIZE; /* Self addr */ HG_Addr_self(HG_CLASS_DEFAULT, &hg_test_addr_g); /* In case of self we need the local thread pool */ #ifdef MERCURY_TESTING_HAS_THREAD_POOL hg_thread_mutex_init(&hg_test_local_bulk_handle_mutex_g); hg_thread_pool_init(MERCURY_TESTING_NUM_THREADS, &hg_test_thread_pool_g); printf("# Starting server with %d threads...\n", MERCURY_TESTING_NUM_THREADS); #endif /* Create bulk buffer that can be used for receiving data */ HG_Bulk_create(HG_CLASS_DEFAULT, 1, NULL, &bulk_size, HG_BULK_READWRITE, &hg_test_local_bulk_handle_g); } else { /* Look up addr using port name info */ ret = HG_Hl_addr_lookup_wait(HG_CONTEXT_DEFAULT, HG_REQUEST_CLASS_DEFAULT, test_addr_name, &hg_test_addr_g, HG_MAX_IDLE_TIME); if (ret != HG_SUCCESS) { fprintf(stderr, "Could not find addr %s\n", test_addr_name); goto done; } } /* Register routines */ hg_test_register(HG_CLASS_DEFAULT); /* When finalize is called we need to free the addr etc */ hg_test_is_client_g = HG_TRUE; if (addr) *addr = hg_test_addr_g; if (rank) *rank = hg_test_rank_g; if (context) *context = HG_CONTEXT_DEFAULT; if (request_class) * request_class = HG_REQUEST_CLASS_DEFAULT; done: return HG_CLASS_DEFAULT; }
/*---------------------------------------------------------------------------*/ static hg_return_t hg_test_drc_token_request(struct hg_test_info *hg_test_info) { hg_request_t *request = NULL; hg_handle_t handle; #ifdef HG_TEST_DRC_USE_TOKEN hg_string_t token; #else hg_uint32_t credential; #endif hg_test_drc_grant_in_t in_struct; hg_test_drc_grant_out_t out_struct; hg_return_t ret = HG_SUCCESS; #ifndef HG_TEST_DRC_IGNORE int rc; #endif /* Look up target addr using target name info */ ret = HG_Hl_addr_lookup_wait(hg_test_info->context, hg_test_info->request_class, hg_test_info->na_test_info.target_name, &hg_test_info->target_addr, HG_MAX_IDLE_TIME); if (ret != HG_SUCCESS) { HG_LOG_ERROR("Could not find addr for target %s", hg_test_info->na_test_info.target_name); goto done; } /* Create new request */ request = hg_request_create(hg_test_info->request_class); /* Create request with invalid RPC id */ ret = HG_Create(hg_test_info->context, hg_test_info->target_addr, hg_test_drc_grant_id_g, &handle); if (ret != HG_SUCCESS) { HG_LOG_ERROR("Could not create handle"); goto done; } /* Get WLM ID and set input */ #ifndef HG_TEST_DRC_IGNORE in_struct.wlm_id = drc_get_wlm_id(); #else in_struct.wlm_id = 12340; #endif /* Forward call to target addr */ printf("# %u requesting access to remote...\n", in_struct.wlm_id); fflush(stdout); ret = HG_Forward(handle, hg_test_drc_token_request_cb, request, &in_struct); if (ret != HG_SUCCESS) { HG_LOG_ERROR("Could not forward call with id=%d", hg_test_drc_grant_id_g); goto done; } /* Wait for completion */ hg_request_wait(request, HG_MAX_IDLE_TIME, NULL); /* Get output */ ret = HG_Get_output(handle, &out_struct); if (ret != HG_SUCCESS) { HG_LOG_ERROR("Could not get output"); goto done; } #ifdef HG_TEST_DRC_USE_TOKEN /* Get token back */ token = out_struct.token; printf("# Received token %s\n", token); fflush(stdout); /* Translate token */ #ifndef HG_TEST_DRC_IGNORE rc = drc_access_with_token(token, 0, &hg_test_info->credential_info); if (rc != DRC_SUCCESS) {/* failed to grant access to the credential */ HG_LOG_ERROR("drc_access_with_token() failed (%d, %s)", rc, drc_strerror(-rc)); ret = HG_PROTOCOL_ERROR; goto done; } #endif #else /* Get credential back */ credential = out_struct.credential; printf("# Received credential %u\n", credential); fflush(stdout); /* Access credential */ #ifndef HG_TEST_DRC_IGNORE drc_access_again: rc = drc_access(credential, 0, &hg_test_info->credential_info); if (rc != DRC_SUCCESS) { /* failed to access credential */ if (rc == -DRC_EINVAL) { sleep(1); goto drc_access_again; } HG_LOG_ERROR("drc_access() failed (%d, %s)", rc, drc_strerror(-rc)); ret = HG_PROTOCOL_ERROR; goto done; } #endif #endif /* Set cookie for further use */ #ifndef HG_TEST_DRC_IGNORE hg_test_info->cookie = drc_get_first_cookie(hg_test_info->credential_info); #else hg_test_info->cookie = 123456789; #endif printf("# Cookie is %u\n", hg_test_info->cookie); fflush(stdout); /* Clean up resources */ ret = HG_Free_output(handle, &out_struct); if (ret != HG_SUCCESS) { HG_LOG_ERROR("Could not free output"); goto done; } ret = HG_Destroy(handle); if (ret != HG_SUCCESS) { HG_LOG_ERROR("Could not destroy handle"); goto done; } hg_request_destroy(request); /* Free target addr */ ret = HG_Addr_free(hg_test_info->hg_class, hg_test_info->target_addr); if (ret != HG_SUCCESS) { HG_LOG_ERROR("Could not free addr"); goto done; } done: return ret; }