Add support for notification generation pattern 71/3271/1
authorAlex Stancu <alexandru.stancu@highstreet-technologies.com>
Wed, 15 Apr 2020 09:22:20 +0000 (12:22 +0300)
committerAlex Stancu <alexandru.stancu@highstreet-technologies.com>
Wed, 15 Apr 2020 09:22:38 +0000 (12:22 +0300)
Add support for patterns when generating notifications, defined through a leaf-list in the simulator-config.

Issue-ID: SIM-24
Change-Id: I3e18619491fb4fbe0cdd3212be2a495fad099e33
Signed-off-by: Alex Stancu <alexandru.stancu@highstreet-technologies.com>
ntsimulator/inc/utils/utils.h
ntsimulator/scripts/configuration.json
ntsimulator/src/ntsimulator-manager/ntsimulator-manager.c
ntsimulator/src/ntsimulator-manager/simulator-operations.c
ntsimulator/src/ntsimulator-manager/simulator-operations.h
ntsimulator/src/o-ran-notifications/o-ran-notifications.c
ntsimulator/src/utils/utils.c
ntsimulator/yang/nts-manager/network-topology-simulator.yang

index 9ce7e1f..6208600 100644 (file)
@@ -73,7 +73,7 @@ cJSON*        vesCreateFaultFields(char *alarm_condition, char *alarm_object, char *sev
 char*  readConfigFileInString(void);
 void   writeConfigFile(char *config);
 
-int    getFaultNotificationDelayPeriodFromConfigJson(void);
+int    getFaultNotificationDelayPeriodFromConfigJson(int *period_array, int *count);
 int    getVesHeartbeatPeriodFromConfigJson(void);
 char*  getVesAuthMethodFromConfigJson(void);
 char*  getVesIpFromConfigJson(void);
index 7587cad..98d9b8d 100644 (file)
@@ -1,9 +1,9 @@
 {
        "notification-config":  {
-               "fault-notification-delay-period":      0,
                "ves-heartbeat-period": 0,
                "is-netconf-available": true,
-               "is-ves-available":     true
+               "is-ves-available":     true,
+               "fault-notification-delay-period":      [0]
        },
        "ves-endpoint-details": {
                "ves-endpoint-ip":      "172.17.0.1",
index 836fc6f..ea120c7 100644 (file)
@@ -225,18 +225,19 @@ simulator_config_change_cb(sr_session_ctx_t *session, const char *module_name, s
     sr_free_val(val);
        val = NULL;
 
+    size_t count = 0;
+
     /* get the value from sysrepo, we do not care if the value did not change in our case */
-    rc = sr_get_item(session, "/network-topology-simulator:simulator-config/notification-config/fault-notification-delay-period", &val);
+    rc = sr_get_items(session, "/network-topology-simulator:simulator-config/notification-config/fault-notification-delay-period", &val, &count);
     if (rc != SR_ERR_OK) {
         goto sr_error;
     }
 
-    rc = notification_delay_period_changed(val->data.uint32_val);
+    rc = notification_delay_period_changed(val, count);
     if (rc != SR_ERR_OK) {
         goto sr_error;
     }
-
-    sr_free_val(val);
+    sr_free_values(val, count);
        val = NULL;
 
     /* get the value from sysrepo, we do not care if the value did not change in our case */
@@ -693,7 +694,7 @@ main(int argc, char **argv)
         goto cleanup;
     }
 
-    rc = notification_delay_period_changed(0);
+    rc = notification_delay_period_changed(NULL, 0);
     if (rc != SR_ERR_OK) {
        printf("Could not write the delay period to file!\n");
         goto cleanup;
index 5f55f4e..f734307 100644 (file)
@@ -1076,7 +1076,7 @@ char* get_docker_container_resource_stats(device_stack_t *theStack)
        return NULL;     /* return with exit code indicating success. */
 }
 
-int notification_delay_period_changed(int period)
+int notification_delay_period_changed(sr_val_t *val, size_t count)
 {
        char *stringConfiguration = readConfigFileInString();
 
@@ -1110,15 +1110,49 @@ int notification_delay_period_changed(int period)
        }
 
        cJSON *faultNotifDelay = cJSON_GetObjectItemCaseSensitive(notifConfig, "fault-notification-delay-period");
-       if (!cJSON_IsNumber(faultNotifDelay))
+       if (!cJSON_IsArray(faultNotifDelay))
        {
-               printf("Configuration JSON is not as expected: fault-notification-delay-period is not an object");
+               printf("Configuration JSON is not as expected: fault-notification-delay-period is not an array.");
                cJSON_Delete(jsonConfig);
                return SR_ERR_OPERATION_FAILED;
        }
 
-       //we set the value of the fault-notification-delay-period object
-       cJSON_SetNumberValue(faultNotifDelay, period);
+    cJSON_DeleteItemFromObject(notifConfig, "fault-notification-delay-period");
+
+    faultNotifDelay = NULL;
+
+    faultNotifDelay = cJSON_CreateArray();
+    if (faultNotifDelay == NULL) 
+    {
+        cJSON_Delete(jsonConfig);
+               return SR_ERR_OPERATION_FAILED;
+    }
+    cJSON_AddItemToObject(notifConfig, "fault-notification-delay-period", faultNotifDelay);
+
+    if (val != NULL && count > 0)
+    {
+        cJSON *arrayEntry = NULL;
+        for (size_t i=0; i<count; ++i)
+        {
+            arrayEntry = cJSON_CreateNumber(val[i].data.uint32_val);
+            if (arrayEntry == NULL) 
+            {
+                cJSON_Delete(jsonConfig);
+                return SR_ERR_OPERATION_FAILED;
+            }
+            cJSON_AddItemToArray(faultNotifDelay, arrayEntry);
+        }
+    }
+    else
+    {
+        cJSON *arrayEntry =  cJSON_CreateNumber(0);
+        if (arrayEntry == NULL) 
+        {
+            cJSON_Delete(jsonConfig);
+            return SR_ERR_OPERATION_FAILED;
+        }
+        cJSON_AddItemToArray(faultNotifDelay, arrayEntry);
+    }
 
        //writing the new JSON to the configuration file
        stringConfiguration = cJSON_Print(jsonConfig);
index 4914423..3b93e48 100644 (file)
@@ -96,7 +96,7 @@ int get_docker_containers_operational_state_curl(device_stack_t *theStack);
 
 char* get_docker_container_resource_stats();
 
-int notification_delay_period_changed(int period);
+int notification_delay_period_changed(sr_val_t *val, size_t count);
 int ves_heartbeat_period_changed(int period);
 int ves_ip_changed(char *new_ip);
 int ves_port_changed(int new_port);
index 230fad2..a46ae04 100644 (file)
@@ -389,27 +389,44 @@ main(int argc, char **argv)
     signal(SIGINT, sigint_handler);
     signal(SIGPIPE, SIG_IGN);
 
-
     while (!exit_application) {
-        notification_delay_period = getFaultNotificationDelayPeriodFromConfigJson();
+        int notif_delay[100], count = 0;
 
-        if (notification_delay_period > 0)
+        rc = getFaultNotificationDelayPeriodFromConfigJson(notif_delay, &count);
+        if (rc != SR_ERR_OK)
         {
-               send_dummy_notif(session);
+            printf("Could not get fault notification delay period.");
+            sleep(1);
+            continue;
+        }
 
-            sleep(notification_delay_period);
+        if (count > 1)
+        {
+            for (int i = 0; i < count; ++i)
+            {
+                sleep(notif_delay[i]);
+                send_dummy_notif(session);                
+            }
         }
-        else
+        else if (count == 1)
         {
-               sleep(1);
-            // reset the counters when the notifciation delay period is switched back to 0
-            netconf_alarm_counter.normal = netconf_alarm_counter.warning = \
-            netconf_alarm_counter.minor = netconf_alarm_counter.major = \
-            netconf_alarm_counter.critical = 0;
-            
-            ves_alarm_counter.normal = ves_alarm_counter.warning = \
-            ves_alarm_counter.minor = ves_alarm_counter.major = \
-            ves_alarm_counter.critical = 0;
+            if (notif_delay[0] > 0)
+            {
+                sleep(notif_delay[0]);
+                send_dummy_notif(session);
+            }
+            else 
+            {
+                sleep(1);
+                // reset the counters when the notifciation delay period is switched back to 0
+                netconf_alarm_counter.normal = netconf_alarm_counter.warning = \
+                netconf_alarm_counter.minor = netconf_alarm_counter.major = \
+                netconf_alarm_counter.critical = 0;
+                
+                ves_alarm_counter.normal = ves_alarm_counter.warning = \
+                ves_alarm_counter.minor = ves_alarm_counter.major = \
+                ves_alarm_counter.critical = 0;
+            }
         }
 
     }
index 7d1d2a0..15bb426 100644 (file)
@@ -452,7 +452,7 @@ void        writeConfigFile(char *config)
        }
 }
 
-int    getFaultNotificationDelayPeriodFromConfigJson(void)
+int getFaultNotificationDelayPeriodFromConfigJson(int *period_array, int *count)
 {
        char *stringConfig = readConfigFileInString();
        int notificationDelay = 0;
@@ -487,18 +487,34 @@ int       getFaultNotificationDelayPeriodFromConfigJson(void)
        }
 
        cJSON *faultNotifDelay = cJSON_GetObjectItemCaseSensitive(notifConfig, "fault-notification-delay-period");
-       if (!cJSON_IsNumber(faultNotifDelay))
+       if (!cJSON_IsArray(faultNotifDelay))
        {
-               printf("Configuration JSON is not as expected: fault-notification-delay-period is not a number");
+               printf("Configuration JSON is not as expected: fault-notification-delay-period is not an array.");
                cJSON_Delete(jsonConfig);
                return SR_ERR_OPERATION_FAILED;
        }
 
-       notificationDelay = (int)(faultNotifDelay->valuedouble);
+    cJSON *iterator = NULL;
+    *count = 0;
+    int i = 0;
+
+    cJSON_ArrayForEach(iterator, faultNotifDelay) 
+    {
+        if (cJSON_IsNumber(iterator)) 
+        {
+            period_array[i++] = iterator->valueint;
+        } 
+        else 
+        {
+            printf("Invalid number in array!");
+        }
+    }
+
+    *count = i;
 
        cJSON_Delete(jsonConfig);
 
-       return notificationDelay;
+       return SR_ERR_OK;
 }
 
 int    getVesHeartbeatPeriodFromConfigJson(void)
index 32570eb..1bc43cb 100644 (file)
@@ -16,7 +16,12 @@ module network-topology-simulator {
   description
     "This module contains a collection of YANG definitions for managing the Network Topology Simulator.";
 
-  
+  revision 2020-04-13 {
+    description
+      "Change fault-notification-delay-period to leaf-list.";
+    reference
+      "O-RAN SC SIM project";
+  }
   revision 2020-04-10 {
     description
       "Add notification count in status.";
@@ -198,11 +203,13 @@ module network-topology-simulator {
         "The number of devices to be mounted in ODL. The configured number should not exceed the number of mounted devices.";
     }
     container notification-config {
-      leaf fault-notification-delay-period {
+      leaf-list fault-notification-delay-period {
         type uint32;
-        default "0";
+        min-elements 1;
+        max-elements 99;
         description
-          "Interval in seconds between two consecutive notifications. If the attribute is set to 0, nofitications are not generated.";
+          "Defines a pattern of generating notifications, represented by the amount of time between two generated fault notifications. The pattern is circular, it restarts at the beginning after all the leaf-list items are being used.
+          E.g.: if the leaf-list contains three items: 4, 8 and 10, then a fault-notification will be generated, then after 4 seconds a new notification will be generaed, then after 8 seconds, then after 10 seconds, then again after 4 seconds etc.";
       }
       leaf ves-heartbeat-period {
         type uint32;