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>
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);
{
"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",
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 */
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;
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();
}
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);
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);
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;
+ }
}
}
}
}
-int getFaultNotificationDelayPeriodFromConfigJson(void)
+int getFaultNotificationDelayPeriodFromConfigJson(int *period_array, int *count)
{
char *stringConfig = readConfigFileInString();
int notificationDelay = 0;
}
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)
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.";
"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;