Add VES O1 pnfRegistration (stndDefined) capabilities.
[sim/o1-interface.git] / ntsimulator / ntsim-ng / core / app / network_function.c
index 2a5ff0f..e34d85c 100644 (file)
@@ -33,6 +33,7 @@
 #include "core/context.h"
 #include "core/session.h"
 #include "core/xpath.h"
+#include "core/datastore/schema.h"
 #include "core/datastore/populate.h"
 
 #include "core/faults/faults.h"
 #include "features/manual_notification/manual_notification.h"
 #include "features/netconf_call_home/netconf_call_home.h"
 #include "features/web_cut_through/web_cut_through.h"
+#include "features/ves_o1_pnf_registration/ves_o1_pnf_registration.h"
 
 #include "app_common.h"
+#include "nf_oran_du.h"
 
 #define NF_FUNCTION_CONTROL_BUFFER_LENGTH                       32
 
@@ -99,14 +102,14 @@ int network_function_run(void) {
     }
 
     //ietf-netconf-monitoring schemas populate with modules and submodules (overwrite default Netopeer2 behaviour)
-    rc = sr_oper_get_items_subscribe(session_running, IETF_NETCONF_MONITORING_MODULE, IETF_NETCONF_MONITORING_STATE_SCHEMAS_SCHEMA_XPATH, netconf_monitoring_state_schemas_cb, 0, SR_SUBSCR_DEFAULT, &session_subscription);
+    rc = sr_oper_get_items_subscribe(session_running, IETF_NETCONF_MONITORING_MODULE, IETF_NETCONF_MONITORING_STATE_SCHEMAS_SCHEMA_XPATH, netconf_monitoring_state_schemas_cb, 0, SR_SUBSCR_CTX_REUSE, &session_subscription);
     if(rc != SR_ERR_OK) {
         log_error("error from sr_oper_get_items_subscribe: %s\n", sr_strerror(rc));
         return 0;
     }
 
     //nc-notifications overwrite
-    rc = sr_oper_get_items_subscribe(session_running, NC_NOTIFICATIONS_MODULE, NC_NOTIFICATIONS_STREAMS_SCHEMA_XPATH, notifications_streams_cb, 0, SR_SUBSCR_DEFAULT, &session_subscription);
+    rc = sr_oper_get_items_subscribe(session_running, NC_NOTIFICATIONS_MODULE, NC_NOTIFICATIONS_STREAMS_SCHEMA_XPATH, notifications_streams_cb, 0, SR_SUBSCR_CTX_REUSE, &session_subscription);
     if(rc != SR_ERR_OK) {
         log_error("error from sr_oper_get_items_subscribe: %s\n", sr_strerror(rc));
         return 0;
@@ -216,6 +219,14 @@ int network_function_run(void) {
         log_add(1,"\n");
     }
 
+    if(strcmp(framework_environment.nts.function_type, "NTS_FUNCTION_TYPE_O_RAN_O_DU") == 0) {
+        rc = nf_oran_du_init();
+        if(rc != NTS_ERR_OK) {
+            log_error("nf_oran_du_init failed\n"); 
+            return NTS_ERR_FAILED; 
+        }
+    }
+
     while(!framework_sigint) {
         pthread_mutex_lock(&nf_function_control_lock);
         while(nf_function_control_buffer_in != nf_function_control_buffer_out) {
@@ -227,10 +238,36 @@ int network_function_run(void) {
             }
 
             if(strstr(nf_function_control_string, "datastore-populate") != 0) {
-                rc = datastore_populate(3);
+                rc = datastore_populate_all();
                 if(rc != NTS_ERR_OK) {
-                    log_error("datastore_populate() failed\n");
+                    log_error("datastore_populate_all() failed\n");
+                }
+
+                //subscribe to any changes so the operational is dynamic
+                char **xpaths = 0;
+                char **modules = 0;
+                int xpaths_count = datastore_schema_get_running_xpaths(&xpaths, &modules);
+                if(xpaths_count < 0) {
+                    log_error("datastore_schema_get_running_xpaths failed\n");
+                    return NTS_ERR_FAILED;
+                }
+
+                for(int i = 0; i < xpaths_count; i++) {
+                    //subscribe
+                    log_add_verbose(1, "subscribing to %s on module %s... ", xpaths[i], modules[i]);
+                    rc = sr_module_change_subscribe(session_running, modules[i], xpaths[i], datastore_dynamic_operational_auto_callback, 0, 0, SR_SUBSCR_DONE_ONLY | SR_SUBSCR_CTX_REUSE, &session_subscription);
+                    if(rc != SR_ERR_OK) {
+                        log_error("sr_module_change_subscribe error\n");
+                    }
+                    else {
+                        log_add(1, "done\n");
+                    }
+
+                    free(xpaths[i]);
+                    free(modules[i]);
                 }
+                free(modules);
+                free(xpaths);
             }
 
             if(strstr(nf_function_control_string, "ves-file-ready") != 0) {
@@ -260,6 +297,16 @@ int network_function_run(void) {
                 }
             }
 
+            if(strstr(nf_function_control_string, "ves-o1-pnf-registration") != 0) {
+                if(nf_function_control_string[0] == '1') {
+                    // check if O1 PNF registration is enabled and send PNF registration message if so
+                    rc = ves_o1_pnf_registration_feature_start(session_running);
+                    if(rc != 0) {
+                        log_error("ves_o1_pnf_registration_feature_start() failed\n");
+                    }
+                }
+            }
+
             if(strstr(nf_function_control_string, "ves-heartbeat") != 0) {
                 if(nf_function_control_string[0] == '1') {
                     // start feature for handling the heartbeat VES message
@@ -330,6 +377,7 @@ int network_function_run(void) {
     }
 
     faults_free();
+    nf_oran_du_free();
 
     return NTS_ERR_OK;
 }
@@ -661,7 +709,11 @@ static int network_function_info_get_items_cb(sr_session_ctx_t *session, const c
     if(web_cut_through_feature_get_status()) {
         strcat(started_features, "web-cut-through ");
     }
-    
+
+    if(ves_o1_pnf_registration_feature_get_status()) {
+        strcat(started_features, "ves-o1-pnf-registration ");
+    }
+
     if(strlen(started_features)) {
         started_features[strlen(started_features) - 1] = 0;
     }