X-Git-Url: https://gerrit.o-ran-sc.org/r/gitweb?a=blobdiff_plain;f=ntsimulator%2Fntsim-ng%2Futils%2Fnts_utils.c;h=19cc9eb26b31462ac4caa6c464c7a0a36daa7604;hb=7ff0c8ce9187702caa356c0c1f30064c65c1f512;hp=60fa0157d72294374d327e257bce008123b22cd0;hpb=3bbf9d8a3c81afebcffb2b926cef219336dd53d6;p=sim%2Fo1-interface.git diff --git a/ntsimulator/ntsim-ng/utils/nts_utils.c b/ntsimulator/ntsim-ng/utils/nts_utils.c index 60fa015..19cc9eb 100644 --- a/ntsimulator/ntsim-ng/utils/nts_utils.c +++ b/ntsimulator/ntsim-ng/utils/nts_utils.c @@ -22,26 +22,16 @@ #include "utils/sys_utils.h" #include "core/framework.h" #include "core/session.h" +#include "core/xpath.h" #include #include #include -#define NTS_MANAGER_SDN_CONTROLLER_CONFIG_XPATH "/nts-manager:simulation/sdn-controller" -#define NTS_NF_SDN_CONTROLLER_CONFIG_XPATH "/nts-network-function:simulation/sdn-controller" -#define NTS_MANAGER_VES_ENDPOINT_CONFIG_XPATH "/nts-manager:simulation/ves-endpoint" -#define NTS_NF_VES_ENDPOINT_CONFIG_XPATH "/nts-network-function:simulation/ves-endpoint" -#define NTS_NETWORK_FUNCTION_FTYPE_SCHEMA_XPATH "/nts-network-function:simulation/network-function/function-type" -#define NTS_NETWORK_FUNCTION_MPAM_SCHEMA_XPATH "/nts-network-function:simulation/network-function/mount-point-addressing-method" -#define NTS_NETWORK_FUNCTION_FAULT_GENERATION_SCHEMA_XPATH "/nts-network-function:simulation/network-function/fault-generation" -#define NTS_NETWORK_FUNCTION_NETCONF_SCHEMA_XPATH "/nts-network-function:simulation/network-function/netconf" -#define NTS_NETWORK_FUNCTION_VES_SCHEMA_XPATH "/nts-network-function:simulation/network-function/ves" - - -cJSON* ves_create_common_event_header(const char *domain, const char *event_type, const char *source_name, const char *priority, int seq_id) { +cJSON* ves_create_common_event_header(const char *domain, const char *event_type, const char *hostname, int port, const char *priority, int seq_id) { assert(domain); assert(event_type); - assert(source_name); + assert(hostname); assert(priority); char *eventId = 0; @@ -100,6 +90,14 @@ cJSON* ves_create_common_event_header(const char *domain, const char *event_type return 0; } + char source_name[512]; + if(port) { + sprintf(source_name, "%s-%d", hostname, port); + } + else { + sprintf(source_name, "%s", hostname); + } + if(cJSON_AddStringToObject(common_event_header, "reportingEntityName", source_name) == 0) { log_error("cJSON AddStringToObject error\n"); cJSON_Delete(common_event_header); @@ -163,6 +161,168 @@ cJSON* ves_create_common_event_header(const char *domain, const char *event_type return common_event_header; } +cJSON* ves_create_common_event_header_721(const char *domain, const char *event_type, const char *hostname, int port, const char *priority, int seq_id, const char *stnd_defined_namespace) { + assert(domain); + assert(event_type); + assert(hostname); + assert(priority); + + char *eventId = 0; + long useconds = get_microseconds_since_epoch(); + + asprintf(&eventId, "%s-%d", event_type, seq_id); + if(eventId == 0) { + log_error("asprintf failed\n"); + return 0; + } + + cJSON *common_event_header = cJSON_CreateObject(); + if(common_event_header == 0) { + log_error("could not create JSON object\n"); + free(eventId); + return 0; + } + + if(cJSON_AddStringToObject(common_event_header, "domain", domain) == 0) { + log_error("cJSON AddStringToObject error\n"); + free(eventId); + cJSON_Delete(common_event_header); + return 0; + } + + if(cJSON_AddStringToObject(common_event_header, "eventId", eventId) == 0) { + log_error("cJSON AddStringToObject error\n"); + free(eventId); + cJSON_Delete(common_event_header); + return 0; + } + + free(eventId); + + char *eventName = 0; + asprintf(&eventName, "ves-stndDefined-%s", event_type); + if(eventId == 0) { + log_error("asprintf failed\n"); + return 0; + } + + if(cJSON_AddStringToObject(common_event_header, "eventName", eventName) == 0) { + log_error("cJSON AddStringToObject error\n"); + cJSON_Delete(common_event_header); + free(eventName); + return 0; + } + free(eventName); + + if(cJSON_AddStringToObject(common_event_header, "eventType", event_type) == 0) { + log_error("cJSON AddStringToObject error\n"); + cJSON_Delete(common_event_header); + return 0; + } + + if(cJSON_AddNumberToObject(common_event_header, "sequence", (double)(seq_id)) == 0) { + log_error("cJSON AddNumberToObject error\n"); + cJSON_Delete(common_event_header); + return 0; + } + + if(cJSON_AddStringToObject(common_event_header, "priority", priority) == 0) { + log_error("cJSON AddStringToObject error\n"); + cJSON_Delete(common_event_header); + return 0; + } + + if(cJSON_AddStringToObject(common_event_header, "reportingEntityId", "") == 0) { + log_error("cJSON AddStringToObject error\n"); + cJSON_Delete(common_event_header); + return 0; + } + + char source_name[512]; + if(port) { + sprintf(source_name, "%s-%d", hostname, port); + } + else { + sprintf(source_name, "%s", hostname); + } + + if(cJSON_AddStringToObject(common_event_header, "reportingEntityName", source_name) == 0) { + log_error("cJSON AddStringToObject error\n"); + cJSON_Delete(common_event_header); + return 0; + } + + if(cJSON_AddStringToObject(common_event_header, "sourceId", "") == 0) { + log_error("cJSON AddStringToObject error\n"); + cJSON_Delete(common_event_header); + return 0; + } + + if(cJSON_AddStringToObject(common_event_header, "sourceName", source_name) == 0) { + log_error("cJSON AddStringToObject error\n"); + cJSON_Delete(common_event_header); + return 0; + } + + if(cJSON_AddNumberToObject(common_event_header, "startEpochMicrosec", (double)(useconds)) == 0) { + log_error("cJSON AddNumberToObject error\n"); + cJSON_Delete(common_event_header); + return 0; + } + + if(cJSON_AddNumberToObject(common_event_header, "lastEpochMicrosec", (double)(useconds)) == 0) { + log_error("cJSON AddNumberToObject error\n"); + cJSON_Delete(common_event_header); + return 0; + } + + if(cJSON_AddStringToObject(common_event_header, "nfNamingCode", "sdn controller") == 0) { + log_error("cJSON AddStringToObject error\n"); + cJSON_Delete(common_event_header); + return 0; + } + + if(cJSON_AddStringToObject(common_event_header, "nfVendorName", "sdn") == 0) { + log_error("cJSON AddStringToObject error\n"); + cJSON_Delete(common_event_header); + return 0; + } + + if(cJSON_AddStringToObject(common_event_header, "timeZoneOffset", "+00:00") == 0) { + log_error("cJSON AddStringToObject error\n"); + cJSON_Delete(common_event_header); + return 0; + } + + if(cJSON_AddStringToObject(common_event_header, "version", "4.1") == 0) { + log_error("cJSON AddStringToObject error\n"); + cJSON_Delete(common_event_header); + return 0; + } + + if(cJSON_AddStringToObject(common_event_header, "vesEventListenerVersion", "7.2.1") == 0) { + log_error("cJSON AddStringToObject error\n"); + cJSON_Delete(common_event_header); + return 0; + } + + if(cJSON_AddStringToObject(common_event_header, "stndDefinedNamespace", stnd_defined_namespace) == 0) { + log_error("cJSON AddStringToObject error\n"); + cJSON_Delete(common_event_header); + return 0; + } + + if(cJSON_AddStringToObject(common_event_header, "nfcNamingCode", "NFC") == 0) { + log_error("cJSON AddStringToObject error\n"); + cJSON_Delete(common_event_header); + return 0; + } + + return common_event_header; +} + + + nts_mount_point_addressing_method_t nts_mount_point_addressing_method_get(sr_session_ctx_t *current_session) { assert_session(); @@ -180,7 +340,7 @@ nts_mount_point_addressing_method_t nts_mount_point_addressing_method_get(sr_ses } sr_val_t *value = 0; - rc = sr_get_item(session_running, NTS_NETWORK_FUNCTION_MPAM_SCHEMA_XPATH, 0, &value); + rc = sr_get_item(current_session, NTS_NF_NETWORK_FUNCTION_MPAM_SCHEMA_XPATH, 0, &value); if(rc == SR_ERR_OK) { if(strcmp(value->data.enum_val, "host-mapping") == 0) { ret = HOST_MAPPING; @@ -203,7 +363,7 @@ nts_mount_point_addressing_method_t nts_mount_point_addressing_method_get(sr_ses } // checkAS authentication via certificate not supported yet -ves_details_t *ves_endpoint_details_get(sr_session_ctx_t *current_session) { +ves_details_t *ves_endpoint_details_get(sr_session_ctx_t *current_session, const char *custom_path) { assert_session(); int rc; @@ -220,11 +380,16 @@ ves_details_t *ves_endpoint_details_get(sr_session_ctx_t *current_session) { struct lyd_node *data = 0; char *xpath_to_get; - if(framework_arguments.nts_mode == NTS_MODE_MANAGER) { - xpath_to_get = "/nts-manager:simulation/ves-endpoint"; + if(custom_path == 0) { + if(framework_arguments.nts_mode == NTS_MODE_MANAGER) { + xpath_to_get = NTS_MANAGER_VES_ENDPOINT_CONFIG_XPATH; + } + else { + xpath_to_get = NTS_NF_VES_ENDPOINT_CONFIG_XPATH; + } } else { - xpath_to_get = "/nts-network-function:simulation/ves-endpoint"; + xpath_to_get = (char *)custom_path; } rc = sr_get_subtree(current_session, xpath_to_get, 0, &data); @@ -295,9 +460,17 @@ ves_details_t *ves_endpoint_details_get(sr_session_ctx_t *current_session) { asprintf(&ret->url, "%s://[%s]:%d/eventListener/v7", ret->protocol, ret->ip, ret->port); } else { - asprintf(&ret->url, "%s://%s:%d/eventListener/v7", ret->protocol, ret->ip, ret->port); + if (framework_environment.ves_endpoint.port_absent == true) { + // hostname addressing with port missing + asprintf(&ret->url, "%s://%s/eventListener/v7", ret->protocol, ret->ip); + } + else { + // normal addressing with IP and Port + asprintf(&ret->url, "%s://%s:%d/eventListener/v7", ret->protocol, ret->ip, ret->port); + } + } - + if((ret->protocol == 0) || (ret->ip == 0) || (ret->auth_method == 0) || (ret->username == 0) || (ret->password == 0) || (ret->url == 0)) { free(ret->protocol); free(ret->ip); @@ -344,10 +517,10 @@ controller_details_t *controller_details_get(sr_session_ctx_t *current_session) char *xpath_to_get; if(framework_arguments.nts_mode == NTS_MODE_MANAGER) { - xpath_to_get = "/nts-manager:simulation/sdn-controller"; + xpath_to_get = NTS_MANAGER_SDN_CONTROLLER_CONFIG_XPATH; } else { - xpath_to_get = "/nts-network-function:simulation/sdn-controller"; + xpath_to_get = NTS_NF_SDN_CONTROLLER_CONFIG_XPATH; } rc = sr_get_subtree(current_session, xpath_to_get, 0, &data); @@ -384,6 +557,7 @@ controller_details_t *controller_details_get(sr_session_ctx_t *current_session) ret->protocol = 0; ret->ip = 0; ret->port = 0; + ret->nc_callhome_ip = 0; ret->nc_callhome_port = 0; ret->auth_method = 0; ret->username = 0; @@ -404,6 +578,9 @@ controller_details_t *controller_details_get(sr_session_ctx_t *current_session) else if(strcmp(chd->schema->name, "controller-port") == 0) { ret->port = ((const struct lyd_node_leaf_list *)chd)->value.uint16; } + else if(strcmp(chd->schema->name, "controller-netconf-call-home-ip") == 0) { + ret->nc_callhome_ip = strdup(val); + } else if(strcmp(chd->schema->name, "controller-netconf-call-home-port") == 0) { ret->nc_callhome_port = ((const struct lyd_node_leaf_list *)chd)->value.uint16; } @@ -421,12 +598,20 @@ controller_details_t *controller_details_get(sr_session_ctx_t *current_session) asprintf(&ret->base_url, "%s://[%s]:%d", ret->protocol, ret->ip, ret->port); } else { - asprintf(&ret->base_url, "%s://%s:%d", ret->protocol, ret->ip, ret->port); + if (framework_environment.sdn_controller.port_absent == true) { + // hostname without port addressing + asprintf(&ret->base_url, "%s://%s", ret->protocol, ret->ip); + } + else { + // normal IP and Port addressing + asprintf(&ret->base_url, "%s://%s:%d", ret->protocol, ret->ip, ret->port); + } } - if((ret->protocol == 0) || (ret->ip == 0) || (ret->auth_method == 0) || (ret->username == 0) || (ret->password == 0) || (ret->base_url == 0)) { + if((ret->protocol == 0) || (ret->ip == 0) || (ret->nc_callhome_ip == 0) || (ret->auth_method == 0) || (ret->username == 0) || (ret->password == 0) || (ret->base_url == 0)) { free(ret->protocol); free(ret->ip); + free(ret->nc_callhome_ip); free(ret->auth_method); free(ret->username); free(ret->password); @@ -443,6 +628,7 @@ void controller_details_free(controller_details_t *instance) { free(instance->protocol); free(instance->ip); + free(instance->nc_callhome_ip); free(instance->base_url); free(instance->auth_method); free(instance->username); @@ -578,6 +764,19 @@ int nts_utils_populate_info(sr_session_ctx_t *current_session, const char *funct return NTS_ERR_FAILED; } + if(strlen(framework_environment.sdn_controller.callhome_ip)) { + if(manager) { + rc = sr_set_item_str(current_session, NTS_MANAGER_SDN_CONTROLLER_CONFIG_XPATH"/controller-netconf-call-home-ip", (const char*)framework_environment.sdn_controller.callhome_ip, 0, 0); + } + else { + rc = sr_set_item_str(current_session, NTS_NF_SDN_CONTROLLER_CONFIG_XPATH"/controller-netconf-call-home-ip", (const char*)framework_environment.sdn_controller.callhome_ip, 0, 0); + } + if(rc != SR_ERR_OK) { + log_error("sr_set_item_str failed\n"); + return NTS_ERR_FAILED; + } + } + sprintf(int_to_str, "%d", framework_environment.sdn_controller.callhome_port); if(manager) { rc = sr_set_item_str(current_session, NTS_MANAGER_SDN_CONTROLLER_CONFIG_XPATH"/controller-netconf-call-home-port", (const char*)int_to_str, 0, 0); @@ -709,19 +908,19 @@ int nts_utils_populate_info(sr_session_ctx_t *current_session, const char *funct if(manager == false) { //presence containers - rc = sr_set_item_str(current_session, NTS_NETWORK_FUNCTION_FAULT_GENERATION_SCHEMA_XPATH, 0, 0, 0); + rc = sr_set_item_str(current_session, NTS_NF_FAULT_GENERATION_SCHEMA_XPATH, 0, 0, 0); if(rc != SR_ERR_OK) { log_error("sr_set_item_str failed\n"); return NTS_ERR_FAILED; } - rc = sr_set_item_str(current_session, NTS_NETWORK_FUNCTION_NETCONF_SCHEMA_XPATH, 0, 0, 0); + rc = sr_set_item_str(current_session, NTS_NF_NETCONF_SCHEMA_XPATH, 0, 0, 0); if(rc != SR_ERR_OK) { log_error("sr_set_item_str failed\n"); return NTS_ERR_FAILED; } - rc = sr_set_item_str(current_session, NTS_NETWORK_FUNCTION_VES_SCHEMA_XPATH, 0, 0, 0); + rc = sr_set_item_str(current_session, NTS_NF_VES_SCHEMA_XPATH, 0, 0, 0); if(rc != SR_ERR_OK) { log_error("sr_set_item_str failed\n"); return NTS_ERR_FAILED; @@ -729,14 +928,14 @@ int nts_utils_populate_info(sr_session_ctx_t *current_session, const char *funct } //also set the network-function module for easy identifying the function type - rc = sr_set_item_str(current_session, NTS_NETWORK_FUNCTION_FTYPE_SCHEMA_XPATH, function_type, 0, 0); + rc = sr_set_item_str(current_session, NTS_NF_NETWORK_FUNCTION_FTYPE_SCHEMA_XPATH, function_type, 0, 0); if(rc != SR_ERR_OK) { log_error("sr_set_item_str failed\n"); return NTS_ERR_FAILED; } //mount-point-addressing-method - rc = sr_set_item_str(current_session, NTS_NETWORK_FUNCTION_MPAM_SCHEMA_XPATH, "docker-mapping", 0, 0); + rc = sr_set_item_str(current_session, NTS_NF_NETWORK_FUNCTION_MPAM_SCHEMA_XPATH, framework_environment.nts.nf_mount_point_addressing_method, 0, 0); if(rc != SR_ERR_OK) { log_error("sr_set_item_str failed\n"); return NTS_ERR_FAILED;