Make CallHome address different that the SDN Controller RESTCONF address.
[sim/o1-interface.git] / ntsimulator / ntsim-ng / utils / nts_utils.c
index 14f2c34..92fac83 100644 (file)
@@ -178,7 +178,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_NF_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;
@@ -293,7 +293,15 @@ 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)) {
@@ -382,6 +390,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;
@@ -402,6 +411,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;
         }
@@ -419,12 +431,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);
@@ -441,6 +461,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);
@@ -576,6 +597,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);