X-Git-Url: https://gerrit.o-ran-sc.org/r/gitweb?a=blobdiff_plain;f=ntsimulator%2Fsrc%2Futils%2Futils.c;h=49b181684b448136be27180732dc24edd2f505bf;hb=f2d8f1002fa93848c80a88e5658db4816cba3020;hp=5242f6d777882dadfb264a14027961247cd99625;hpb=22d42e2cb4dced153aa8ee785ea2a102962a31b4;p=sim%2Fo1-interface.git diff --git a/ntsimulator/src/utils/utils.c b/ntsimulator/src/utils/utils.c index 5242f6d..49b1816 100644 --- a/ntsimulator/src/utils/utils.c +++ b/ntsimulator/src/utils/utils.c @@ -193,11 +193,38 @@ void prepare_ves_message_curl(CURL *curl) char *ves_ip = getVesIpFromConfigJson(); int ves_port = getVesPortFromConfigJson(); + char *ves_auth_method = getVesAuthMethodFromConfigJson(); + if (strcmp(ves_auth_method, "basic-auth") == 0) + { + char *ves_username = getVesUsernameFromConfigJson(); + char *ves_password = getVesPasswordFromConfigJson(); + + char credentials[200]; + sprintf(credentials, "%s:%s", ves_username, ves_password); - char url[100]; - sprintf(url, "http://%s:%d/eventListener/v7", ves_ip, ves_port); + free(ves_username); + free(ves_password); + + curl_easy_setopt(curl, CURLOPT_USERPWD, credentials); + } + free(ves_auth_method); + + char url[300]; + char ves_protocol[15] = "https"; + if( !strcmp(getenv("VES_HTTPS"), "false") ) + { + strcpy(ves_protocol ,"http" ); + printf("VES connection protocol %s enabled\n", ves_protocol); + } + + sprintf(url, "%s://%s:%d/eventListener/v7", ves_protocol, ves_ip, ves_port); curl_easy_setopt(curl, CURLOPT_URL, url); + curl_easy_setopt(curl, CURLOPT_SSL_VERIFYPEER, 0L); + curl_easy_setopt(curl, CURLOPT_SSL_VERIFYHOST, 0L); + curl_easy_setopt(curl, CURLOPT_PROXY_SSL_VERIFYPEER, 0L); + curl_easy_setopt(curl, CURLOPT_PROXY_SSL_VERIFYHOST, 0L); + free(ves_ip); return; @@ -420,11 +447,11 @@ char* readConfigFileInString(void) if(NULL != scripts_dir) { - sprintf(config_file, "%s/configuration.json", scripts_dir); + sprintf(config_file, "%s/configuration.json", scripts_dir); } else { - sprintf(config_file, "%s/configuration.json", scripts_dir_default); + sprintf(config_file, "%s/configuration.json", scripts_dir_default); printf("warning: opening config file in default path: <%s>\n", config_file); } @@ -467,12 +494,12 @@ void writeConfigFile(char *config) if(NULL != scripts_dir) { - sprintf(config_file, "%s/configuration.json", scripts_dir); + sprintf(config_file, "%s/configuration.json", scripts_dir); } else { - sprintf(config_file, "%s/configuration.json", scripts_dir_default); - printf("warning: opening config file in default path: <%s>\n", + sprintf(config_file, "%s/configuration.json", scripts_dir_default); + printf("warning: opening config file in default path: <%s>\n", config_file); } // end of fix <-- @@ -664,50 +691,156 @@ char* getVesAuthMethodFromConfigJson(void) */ char* getVesIpFromConfigJson(void) { - char *stringConfig = readConfigFileInString(); + char *stringConfig = readConfigFileInString(); - if (stringConfig == NULL) - { - printf("Could not read JSON configuration file in string."); - return 0; - } + if (stringConfig == NULL) + { + printf("Could not read JSON configuration file in string."); + return 0; + } - cJSON *jsonConfig = cJSON_Parse(stringConfig); - if (jsonConfig == NULL) - { - free(stringConfig); - const char *error_ptr = cJSON_GetErrorPtr(); - if (error_ptr != NULL) - { - fprintf(stderr, "Could not parse JSON configuration! Error before: %s\n", error_ptr); - } - return NULL; - } - //we don't need the string anymore - free(stringConfig); - stringConfig = NULL; + cJSON *jsonConfig = cJSON_Parse(stringConfig); + if (jsonConfig == NULL) + { + free(stringConfig); + const char *error_ptr = cJSON_GetErrorPtr(); + if (error_ptr != NULL) + { + fprintf(stderr, "Could not parse JSON configuration! Error before: %s\n", error_ptr); + } + return NULL; + } + //we don't need the string anymore + free(stringConfig); + stringConfig = NULL; - cJSON *vesDetails = cJSON_GetObjectItemCaseSensitive(jsonConfig, "ves-endpoint-details"); - if (!cJSON_IsObject(vesDetails)) - { - printf("Configuration JSON is not as expected: ves-endpoint-details is not an object"); - cJSON_Delete(jsonConfig); - return NULL; - } + cJSON *vesDetails = cJSON_GetObjectItemCaseSensitive(jsonConfig, "ves-endpoint-details"); + if (!cJSON_IsObject(vesDetails)) + { + printf("Configuration JSON is not as expected: ves-endpoint-details is not an object"); + cJSON_Delete(jsonConfig); + return NULL; + } - cJSON *vesIp = cJSON_GetObjectItemCaseSensitive(vesDetails, "ves-endpoint-ip"); - if (!cJSON_IsString(vesIp)) - { - printf("Configuration JSON is not as expected: ves-endpoint-ip is not an object"); - cJSON_Delete(jsonConfig); - return NULL; - } + cJSON *vesIp = cJSON_GetObjectItemCaseSensitive(vesDetails, "ves-endpoint-ip"); + if (!cJSON_IsString(vesIp)) + { + printf("Configuration JSON is not as expected: ves-endpoint-ip is not an object"); + cJSON_Delete(jsonConfig); + return NULL; + } - char *ves_ip = strdup(cJSON_GetStringValue(vesIp)); + char *ves_ip = strdup(cJSON_GetStringValue(vesIp)); - cJSON_Delete(jsonConfig); + cJSON_Delete(jsonConfig); + + return ves_ip; +} + +/* + * Dynamically allocated memory; + * Caller needs to free the memory after it uses the value. + * +*/ +char* getVesUsernameFromConfigJson(void) +{ + char *stringConfig = readConfigFileInString(); + + if (stringConfig == NULL) + { + printf("Could not read JSON configuration file in string."); + return 0; + } + + cJSON *jsonConfig = cJSON_Parse(stringConfig); + if (jsonConfig == NULL) + { + free(stringConfig); + const char *error_ptr = cJSON_GetErrorPtr(); + if (error_ptr != NULL) + { + fprintf(stderr, "Could not parse JSON configuration! Error before: %s\n", error_ptr); + } + return NULL; + } + //we don't need the string anymore + free(stringConfig); + stringConfig = NULL; - return ves_ip; + cJSON *vesDetails = cJSON_GetObjectItemCaseSensitive(jsonConfig, "ves-endpoint-details"); + if (!cJSON_IsObject(vesDetails)) + { + printf("Configuration JSON is not as expected: ves-endpoint-details is not an object"); + cJSON_Delete(jsonConfig); + return NULL; + } + + cJSON *vesUsername = cJSON_GetObjectItemCaseSensitive(vesDetails, "ves-endpoint-username"); + if (!cJSON_IsString(vesUsername)) + { + printf("Configuration JSON is not as expected: ves-endpoint-username is not an object"); + cJSON_Delete(jsonConfig); + return NULL; + } + + char *ves_username = strdup(cJSON_GetStringValue(vesUsername)); + + cJSON_Delete(jsonConfig); + + return ves_username; +} + +/* + * Dynamically allocated memory; + * Caller needs to free the memory after it uses the value. + * +*/ +char* getVesPasswordFromConfigJson(void) +{ + char *stringConfig = readConfigFileInString(); + + if (stringConfig == NULL) + { + printf("Could not read JSON configuration file in string."); + return 0; + } + + cJSON *jsonConfig = cJSON_Parse(stringConfig); + if (jsonConfig == NULL) + { + free(stringConfig); + const char *error_ptr = cJSON_GetErrorPtr(); + if (error_ptr != NULL) + { + fprintf(stderr, "Could not parse JSON configuration! Error before: %s\n", error_ptr); + } + return NULL; + } + //we don't need the string anymore + free(stringConfig); + stringConfig = NULL; + + cJSON *vesDetails = cJSON_GetObjectItemCaseSensitive(jsonConfig, "ves-endpoint-details"); + if (!cJSON_IsObject(vesDetails)) + { + printf("Configuration JSON is not as expected: ves-endpoint-details is not an object"); + cJSON_Delete(jsonConfig); + return NULL; + } + + cJSON *vesPassword = cJSON_GetObjectItemCaseSensitive(vesDetails, "ves-endpoint-password"); + if (!cJSON_IsString(vesPassword)) + { + printf("Configuration JSON is not as expected: ves-endpoint-password is not an object"); + cJSON_Delete(jsonConfig); + return NULL; + } + + char *ves_password = strdup(cJSON_GetStringValue(vesPassword)); + + cJSON_Delete(jsonConfig); + + return ves_password; } int getVesPortFromConfigJson(void) @@ -858,7 +991,7 @@ cJSON* vesCreatePnfRegistrationFields(int port, bool is_tls) return NULL; } - if (cJSON_AddStringToObject(pnfRegistrationFields, "oamV4IpAddress", getenv("NTS_IP")) == NULL) + if (cJSON_AddStringToObject(pnfRegistrationFields, "oamV4IpAddress", getenv("EXTERNAL_NTS_IP")) == NULL) { printf("Could not create JSON object: oamV4IpAddress\n"); cJSON_Delete(pnfRegistrationFields); @@ -873,7 +1006,7 @@ cJSON* vesCreatePnfRegistrationFields(int port, bool is_tls) } char serial_number[100]; - sprintf(serial_number, "%s-%s-%d-Simulated Device Melacon", getenv("HOSTNAME"), getenv("NTS_IP"), port); + sprintf(serial_number, "%s-%s-%d-Simulated Device Melacon", getenv("HOSTNAME"), getenv("EXTERNAL_NTS_IP"), port); if (cJSON_AddStringToObject(pnfRegistrationFields, "serialNumber", serial_number) == NULL) { @@ -2082,6 +2215,50 @@ int writeSkeletonConfigFile() return SR_ERR_OPERATION_FAILED; } + cJSON *controllerDetails = cJSON_CreateObject(); + if (controllerDetails == NULL) + { + printf("Could not create JSON object: controllerDetails\n"); + cJSON_Delete(configObject); + return SR_ERR_OPERATION_FAILED; + } + cJSON_AddItemToObject(configObject, "controller-details", controllerDetails); + + if (cJSON_AddStringToObject(controllerDetails, "controller-ip", "172.17.0.1") == NULL) + { + printf("Could not create JSON object: controller-ip\n"); + cJSON_Delete(configObject); + return SR_ERR_OPERATION_FAILED; + } + + if (cJSON_AddNumberToObject(controllerDetails, "controller-port", 8181) == NULL) + { + printf("Could not create JSON object: controller-port\n"); + cJSON_Delete(configObject); + return SR_ERR_OPERATION_FAILED; + } + + if (cJSON_AddNumberToObject(controllerDetails, "netconf-call-home-port", 6666) == NULL) + { + printf("Could not create JSON object: netconf-call-home-port\n"); + cJSON_Delete(configObject); + return SR_ERR_OPERATION_FAILED; + } + + if (cJSON_AddStringToObject(controllerDetails, "controller-username", "admin") == NULL) + { + printf("Could not create JSON object: controller-username\n"); + cJSON_Delete(configObject); + return SR_ERR_OPERATION_FAILED; + } + + if (cJSON_AddStringToObject(controllerDetails, "controller-password", "admin") == NULL) + { + printf("Could not create JSON object: controller-password\n"); + cJSON_Delete(configObject); + return SR_ERR_OPERATION_FAILED; + } + if (cJSON_AddNumberToObject(configObject, "ssh-connections", 1) == NULL) { printf("Could not create JSON object: ssh-connections\n"); @@ -2096,6 +2273,13 @@ int writeSkeletonConfigFile() return SR_ERR_OPERATION_FAILED; } + if (cJSON_AddFalseToObject(configObject, "netconf-call-home") == NULL) + { + printf("Could not create JSON object: netconf-call-home\n"); + cJSON_Delete(configObject); + return SR_ERR_OPERATION_FAILED; + } + char *config_string = NULL; config_string = cJSON_PrintUnformatted(configObject);