From: Alex Stancu Date: Wed, 15 Apr 2020 09:22:20 +0000 (+0300) Subject: Add support for notification generation pattern X-Git-Tag: 0.6.1~4 X-Git-Url: https://gerrit.o-ran-sc.org/r/gitweb?p=sim%2Fo1-interface.git;a=commitdiff_plain;h=610985b805c2b5c730bbc247ccbf76dd624792d0 Add support for notification generation pattern 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 --- diff --git a/ntsimulator/inc/utils/utils.h b/ntsimulator/inc/utils/utils.h index 9ce7e1f..6208600 100644 --- a/ntsimulator/inc/utils/utils.h +++ b/ntsimulator/inc/utils/utils.h @@ -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); diff --git a/ntsimulator/scripts/configuration.json b/ntsimulator/scripts/configuration.json index 7587cad..98d9b8d 100644 --- a/ntsimulator/scripts/configuration.json +++ b/ntsimulator/scripts/configuration.json @@ -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", diff --git a/ntsimulator/src/ntsimulator-manager/ntsimulator-manager.c b/ntsimulator/src/ntsimulator-manager/ntsimulator-manager.c index 836fc6f..ea120c7 100644 --- a/ntsimulator/src/ntsimulator-manager/ntsimulator-manager.c +++ b/ntsimulator/src/ntsimulator-manager/ntsimulator-manager.c @@ -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; diff --git a/ntsimulator/src/ntsimulator-manager/simulator-operations.c b/ntsimulator/src/ntsimulator-manager/simulator-operations.c index 5f55f4e..f734307 100644 --- a/ntsimulator/src/ntsimulator-manager/simulator-operations.c +++ b/ntsimulator/src/ntsimulator-manager/simulator-operations.c @@ -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 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; + } } } diff --git a/ntsimulator/src/utils/utils.c b/ntsimulator/src/utils/utils.c index 7d1d2a0..15bb426 100644 --- a/ntsimulator/src/utils/utils.c +++ b/ntsimulator/src/utils/utils.c @@ -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) diff --git a/ntsimulator/yang/nts-manager/network-topology-simulator.yang b/ntsimulator/yang/nts-manager/network-topology-simulator.yang index 32570eb..1bc43cb 100644 --- a/ntsimulator/yang/nts-manager/network-topology-simulator.yang +++ b/ntsimulator/yang/nts-manager/network-topology-simulator.yang @@ -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;