4 * Created on: Feb 19, 2019
15 void set_curl_common_info_ves(CURL *curl)
17 struct curl_slist *chunk = NULL;
18 chunk = curl_slist_append(chunk, "Content-Type: application/json");
19 chunk = curl_slist_append(chunk, "Accept: application/json");
21 curl_easy_setopt(curl, CURLOPT_HTTPHEADER, chunk);
23 curl_easy_setopt(curl, CURLOPT_CONNECTTIMEOUT, 2L); // seconds timeout for a connection
24 curl_easy_setopt(curl, CURLOPT_TIMEOUT, 5L); //seconds timeout for an operation
26 curl_easy_setopt(curl, CURLOPT_VERBOSE, 1L);
29 void getCurrentDateAndTime(char *date_and_time)
31 time_t t = time(NULL);
32 struct tm tm = *localtime(&t);
36 gettimeofday(&tv, NULL);
37 millisec = lrint(tv.tv_usec/1000.0); // Round to nearest millisec
39 { // Allow for rounding up to nearest second
44 sprintf(date_and_time, "%04d-%02d-%02dT%02d:%02d:%02d.%01dZ",
45 tm.tm_year + 1900, tm.tm_mon + 1, tm.tm_mday,
46 tm.tm_hour, tm.tm_min, tm.tm_sec, millisec/100);
51 void generateRandomMacAddress(char *mac_address)
53 long rand1, rand2, rand3, rand4, rand5, rand6;
54 rand1 = random_at_most(255);
55 rand2 = random_at_most(255);
56 rand3 = random_at_most(255);
57 rand4 = random_at_most(255);
58 rand5 = random_at_most(255);
59 rand6 = random_at_most(255);
61 sprintf(mac_address, "%02X:%02X:%02X:%02X:%02X:%02X", rand1, rand2, rand3, rand4, rand5, rand6);
66 long random_at_most(long max) {
68 // max <= RAND_MAX < ULONG_MAX, so this is okay.
69 num_bins = (unsigned long) max + 1,
70 num_rand = (unsigned long) RAND_MAX + 1,
71 bin_size = num_rand / num_bins,
72 defect = num_rand % num_bins;
78 // This is carefully written not to overflow
79 while (num_rand - defect <= (unsigned long)x);
81 // Truncated division is intentional
85 int getSecondsFromLastQuarterInterval(void)
87 time_t t = time(NULL);
88 time_t t_past = time(NULL);
89 struct tm tm = *localtime(&t);
90 struct tm tm_15_min_ago = tm;
92 //round to the last quarter hour
93 tm_15_min_ago.tm_min -= (tm_15_min_ago.tm_min % 15);
94 tm_15_min_ago.tm_sec = 0;
96 t=mktime(&tm_15_min_ago);
99 double seconds = difftime(t_past, t);
104 int getSecondsFromLastDayInterval(void)
106 time_t t = time(NULL);
107 time_t t_past = time(NULL);
108 struct tm tm = *localtime(&t);
109 struct tm tm_day_ago = tm;
111 //round to the last quarter hour
112 tm_day_ago.tm_hour = 0;
113 tm_day_ago.tm_min = 0;
114 tm_day_ago.tm_sec = 0;
116 t=mktime(&tm_day_ago);
119 double seconds = difftime(t_past, t);
124 void getPreviousQuarterInterval(int number_of_intervals, char *date_and_time)
126 time_t t = time(NULL);
127 t -= 15 * 60 * number_of_intervals;
128 struct tm tm = *localtime(&t);
130 tm.tm_min -= (tm.tm_min % 15);
133 sprintf(date_and_time, "%04d-%02d-%02dT%02d:%02d:%02d.0Z",
134 tm.tm_year + 1900, tm.tm_mon + 1, tm.tm_mday,
135 tm.tm_hour, tm.tm_min, tm.tm_sec);
140 void getPreviousDayPmTimestamp(int number_of_intervals, char *date_and_time)
142 time_t t = time(NULL);
143 t -= 24 * 60 * 60 * number_of_intervals;
144 struct tm tm = *localtime(&t);
150 sprintf(date_and_time, "%04d-%02d-%02dT%02d:%02d:%02d.0Z",
151 tm.tm_year + 1900, tm.tm_mon + 1, tm.tm_mday,
152 tm.tm_hour, tm.tm_min, tm.tm_sec);
157 long int getMicrosecondsSinceEpoch(void)
159 time_t t = time(NULL);
160 struct tm tm = *localtime(&t);
164 gettimeofday(&tv, NULL);
165 useconds = t*1000 + tv.tv_usec; //add the microseconds to the seconds
170 //TODO need to implement other authentication methods as well, not only no-auth
171 void prepare_ves_message_curl(CURL *curl)
173 curl_easy_reset(curl);
174 set_curl_common_info_ves(curl);
176 char *ves_ip = getVesIpFromConfigJson();
177 int ves_port = getVesPortFromConfigJson();
180 sprintf(url, "http://%s:%d/eventListener/v7", ves_ip, ves_port);
181 curl_easy_setopt(curl, CURLOPT_URL, url);
185 // curl_easy_setopt(curl, CURLOPT_HTTPAUTH, CURLAUTH_ANY);
190 cJSON* vesCreateCommonEventHeader(char *domain, char *event_type, char *source_name, int seq_id)
192 char dateAndTime[50];
193 getCurrentDateAndTime(dateAndTime);
195 long int useconds = getMicrosecondsSinceEpoch;
197 cJSON *commonEventHeader = cJSON_CreateObject();
198 if (commonEventHeader == NULL)
200 printf("Could not create JSON object: commonEventHeader\n");
204 if (cJSON_AddStringToObject(commonEventHeader, "domain", domain) == NULL)
206 printf("Could not create JSON object: domain\n");
211 sprintf(eventId, "%s_%s", source_name, dateAndTime);
213 if (cJSON_AddStringToObject(commonEventHeader, "eventId", eventId) == NULL)
215 printf("Could not create JSON object: eventId\n");
219 char event_name[200];
220 sprintf(event_name, "%s_%s", domain, event_type);
222 if (cJSON_AddStringToObject(commonEventHeader, "eventName", event_name) == NULL)
224 printf("Could not create JSON object: eventName\n");
228 if (cJSON_AddStringToObject(commonEventHeader, "eventType", event_type) == NULL)
230 printf("Could not create JSON object: eventType\n");
234 if (cJSON_AddNumberToObject(commonEventHeader, "sequence", (double)(seq_id)) == NULL)
236 printf("Could not create JSON object: sequence\n");
240 if (cJSON_AddStringToObject(commonEventHeader, "priority", "Low") == NULL)
242 printf("Could not create JSON object: priority\n");
246 if (cJSON_AddStringToObject(commonEventHeader, "reportingEntityId", "") == NULL)
248 printf("Could not create JSON object: reportingEntityId\n");
252 if (cJSON_AddStringToObject(commonEventHeader, "reportingEntityName", source_name) == NULL)
254 printf("Could not create JSON object: reportingEntityName\n");
258 if (cJSON_AddStringToObject(commonEventHeader, "sourceId", "") == NULL)
260 printf("Could not create JSON object: sourceId\n");
264 if (cJSON_AddStringToObject(commonEventHeader, "sourceName", source_name) == NULL)
266 printf("Could not create JSON object: sourceName\n");
270 if (cJSON_AddNumberToObject(commonEventHeader, "startEpochMicrosec", (double)(useconds)) == NULL)
272 printf("Could not create JSON object: startEpochMicrosec\n");
276 if (cJSON_AddNumberToObject(commonEventHeader, "lastEpochMicrosec", (double)(useconds)) == NULL)
278 printf("Could not create JSON object: lastEpochMicrosec\n");
282 if (cJSON_AddStringToObject(commonEventHeader, "nfNamingCode", "sdn controller") == NULL)
284 printf("Could not create JSON object: nfNamingCode\n");
288 if (cJSON_AddStringToObject(commonEventHeader, "nfVendorName", "sdn") == NULL)
290 printf("Could not create JSON object: nfVendorName\n");
294 if (cJSON_AddStringToObject(commonEventHeader, "timeZoneOffset", "+00:00") == NULL)
296 printf("Could not create JSON object: timeZoneOffset\n");
300 if (cJSON_AddStringToObject(commonEventHeader, "version", "4.0.1") == NULL)
302 printf("Could not create JSON object: version\n");
306 if (cJSON_AddStringToObject(commonEventHeader, "vesEventListenerVersion", "7.0.1") == NULL)
308 printf("Could not create JSON object: vesEventListenerVersion\n");
312 return commonEventHeader;
315 cJSON* vesCreateHeartbeatFields(int heartbeat_interval)
317 char dateAndTime[50];
318 getCurrentDateAndTime(dateAndTime);
320 cJSON *heartbeatFields = cJSON_CreateObject();
321 if (heartbeatFields == NULL)
323 printf("Could not create JSON object: heartbeatFields\n");
327 if (cJSON_AddStringToObject(heartbeatFields, "heartbeatFieldsVersion", "3.0") == NULL)
329 printf("Could not create JSON object: heartbeatFieldsVersion\n");
333 if (cJSON_AddNumberToObject(heartbeatFields, "heartbeatInterval", (double)(heartbeat_interval)) == NULL)
335 printf("Could not create JSON object: heartbeatInterval\n");
339 cJSON *additionalFields = cJSON_CreateObject();
340 if (additionalFields == NULL)
342 printf("Could not create JSON object: additionalFields\n");
345 cJSON_AddItemToObject(heartbeatFields, "additionalFields", additionalFields);
347 if (cJSON_AddStringToObject(additionalFields, "eventTime", dateAndTime) == NULL)
349 printf("Could not create JSON object: eventTime\n");
353 return heartbeatFields;
356 char* readConfigFileInString(void)
360 char config_file[200];
361 sprintf(config_file, "%s/configuration.json", getenv("SCRIPTS_DIR"));
362 FILE * f = fopen (config_file, "rb");
366 fseek (f, 0, SEEK_END);
368 fseek (f, 0, SEEK_SET);
369 buffer = malloc (length + 1);
372 fread (buffer, 1, length, f);
375 buffer[length] = '\0';
386 void writeConfigFile(char *config)
390 char config_file[200];
391 sprintf(config_file, "%s/configuration.json", getenv("SCRIPTS_DIR"));
392 FILE * f = fopen (config_file, "w");
401 printf("Could not write configuration file");
405 int getFaultNotificationDelayPeriodFromConfigJson(void)
407 char *stringConfig = readConfigFileInString();
408 int notificationDelay = 0;
410 if (stringConfig == NULL)
412 printf("Could not read JSON configuration file in string.");
416 cJSON *jsonConfig = cJSON_Parse(stringConfig);
417 if (jsonConfig == NULL)
420 const char *error_ptr = cJSON_GetErrorPtr();
421 if (error_ptr != NULL)
423 fprintf(stderr, "Could not parse JSON configuration! Error before: %s\n", error_ptr);
425 return SR_ERR_OPERATION_FAILED;
427 //we don't need the string anymore
430 cJSON *notifConfig = cJSON_GetObjectItemCaseSensitive(jsonConfig, "notification-config");
431 if (!cJSON_IsObject(notifConfig))
433 printf("Configuration JSON is not as expected: notification-config is not an object");
435 return SR_ERR_OPERATION_FAILED;
438 cJSON *faultNotifDelay = cJSON_GetObjectItemCaseSensitive(notifConfig, "fault-notification-delay-period");
439 if (!cJSON_IsNumber(faultNotifDelay))
441 printf("Configuration JSON is not as expected: fault-notification-delay-period is not a number");
443 return SR_ERR_OPERATION_FAILED;
446 notificationDelay = (int)(faultNotifDelay->valuedouble);
450 return notificationDelay;
453 int getVesHeartbeatPeriodFromConfigJson(void)
455 char *stringConfig = readConfigFileInString();
456 int vesHeartbeat = 0;
458 if (stringConfig == NULL)
460 printf("Could not read JSON configuration file in string.");
464 cJSON *jsonConfig = cJSON_Parse(stringConfig);
465 if (jsonConfig == NULL)
468 const char *error_ptr = cJSON_GetErrorPtr();
469 if (error_ptr != NULL)
471 fprintf(stderr, "Could not parse JSON configuration! Error before: %s\n", error_ptr);
473 return SR_ERR_OPERATION_FAILED;
475 //we don't need the string anymore
478 cJSON *notifConfig = cJSON_GetObjectItemCaseSensitive(jsonConfig, "notification-config");
479 if (!cJSON_IsObject(notifConfig))
481 printf("Configuration JSON is not as expected: notification-config is not an object");
483 return SR_ERR_OPERATION_FAILED;
486 cJSON *vesHeartbeatPeriod = cJSON_GetObjectItemCaseSensitive(notifConfig, "ves-heartbeat-period");
487 if (!cJSON_IsNumber(vesHeartbeatPeriod))
489 printf("Configuration JSON is not as expected: ves-heartbeat-period is not a number");
491 return SR_ERR_OPERATION_FAILED;
494 vesHeartbeat = (int)(vesHeartbeatPeriod->valuedouble);
503 * Dynamically allocated memory;
504 * Caller needs to free the memory after it uses the value.
507 char* getVesAuthMethodFromConfigJson(void)
509 char *stringConfig = readConfigFileInString();
511 if (stringConfig == NULL)
513 printf("Could not read JSON configuration file in string.");
517 cJSON *jsonConfig = cJSON_Parse(stringConfig);
518 if (jsonConfig == NULL)
521 const char *error_ptr = cJSON_GetErrorPtr();
522 if (error_ptr != NULL)
524 fprintf(stderr, "Could not parse JSON configuration! Error before: %s\n", error_ptr);
526 return SR_ERR_OPERATION_FAILED;
528 //we don't need the string anymore
531 cJSON *vesDetails = cJSON_GetObjectItemCaseSensitive(jsonConfig, "ves-endpoint-details");
532 if (!cJSON_IsObject(vesDetails))
534 printf("Configuration JSON is not as expected: ves-endpoint-details is not an object");
536 return SR_ERR_OPERATION_FAILED;
539 cJSON *vesAuthMethod = cJSON_GetObjectItemCaseSensitive(vesDetails, "ves-endpoint-auth-method");
540 if (!cJSON_IsString(vesAuthMethod))
542 printf("Configuration JSON is not as expected: ves-endpoint-auth-method is not an object");
544 return SR_ERR_OPERATION_FAILED;
547 char *auth_method_string = strdup(cJSON_GetStringValue(vesAuthMethod));
551 return auth_method_string;
555 * Dynamically allocated memory;
556 * Caller needs to free the memory after it uses the value.
559 char* getVesIpFromConfigJson(void)
561 char *stringConfig = readConfigFileInString();
563 if (stringConfig == NULL)
565 printf("Could not read JSON configuration file in string.");
569 cJSON *jsonConfig = cJSON_Parse(stringConfig);
570 if (jsonConfig == NULL)
573 const char *error_ptr = cJSON_GetErrorPtr();
574 if (error_ptr != NULL)
576 fprintf(stderr, "Could not parse JSON configuration! Error before: %s\n", error_ptr);
578 return SR_ERR_OPERATION_FAILED;
580 //we don't need the string anymore
583 cJSON *vesDetails = cJSON_GetObjectItemCaseSensitive(jsonConfig, "ves-endpoint-details");
584 if (!cJSON_IsObject(vesDetails))
586 printf("Configuration JSON is not as expected: ves-endpoint-details is not an object");
588 return SR_ERR_OPERATION_FAILED;
591 cJSON *vesIp = cJSON_GetObjectItemCaseSensitive(vesDetails, "ves-endpoint-ip");
592 if (!cJSON_IsString(vesIp))
594 printf("Configuration JSON is not as expected: ves-endpoint-ip is not an object");
596 return SR_ERR_OPERATION_FAILED;
599 char *ves_ip = strdup(cJSON_GetStringValue(vesIp));
606 int getVesPortFromConfigJson(void)
608 char *stringConfig = readConfigFileInString();
610 if (stringConfig == NULL)
612 printf("Could not read JSON configuration file in string.");
616 cJSON *jsonConfig = cJSON_Parse(stringConfig);
617 if (jsonConfig == NULL)
620 const char *error_ptr = cJSON_GetErrorPtr();
621 if (error_ptr != NULL)
623 fprintf(stderr, "Could not parse JSON configuration! Error before: %s\n", error_ptr);
625 return SR_ERR_OPERATION_FAILED;
627 //we don't need the string anymore
630 cJSON *vesDetails = cJSON_GetObjectItemCaseSensitive(jsonConfig, "ves-endpoint-details");
631 if (!cJSON_IsObject(vesDetails))
633 printf("Configuration JSON is not as expected: ves-endpoint-details is not an object");
635 return SR_ERR_OPERATION_FAILED;
638 cJSON *vesPort = cJSON_GetObjectItemCaseSensitive(vesDetails, "ves-endpoint-port");
639 if (!cJSON_IsNumber(vesPort))
641 printf("Configuration JSON is not as expected: ves-endpoint-port is not an object");
643 return SR_ERR_OPERATION_FAILED;
646 int port = (int)(vesPort->valuedouble);
653 int getVesRegistrationFromConfigJson(void)
655 char *stringConfig = readConfigFileInString();
657 if (stringConfig == NULL)
659 printf("Could not read JSON configuration file in string.");
663 cJSON *jsonConfig = cJSON_Parse(stringConfig);
664 if (jsonConfig == NULL)
667 const char *error_ptr = cJSON_GetErrorPtr();
668 if (error_ptr != NULL)
670 fprintf(stderr, "Could not parse JSON configuration! Error before: %s\n", error_ptr);
672 return SR_ERR_OPERATION_FAILED;
674 //we don't need the string anymore
677 cJSON *vesDetails = cJSON_GetObjectItemCaseSensitive(jsonConfig, "ves-endpoint-details");
678 if (!cJSON_IsObject(vesDetails))
680 printf("Configuration JSON is not as expected: ves-endpoint-details is not an object");
682 return SR_ERR_OPERATION_FAILED;
685 cJSON *vesReg = cJSON_GetObjectItemCaseSensitive(vesDetails, "ves-registration");
686 if (!cJSON_IsBool(vesReg))
688 printf("Configuration JSON is not as expected: ves-registration is not an object");
690 return SR_ERR_OPERATION_FAILED;
693 int is_ves_reg = (cJSON_IsTrue(vesReg)) ? TRUE : FALSE;
700 cJSON* vesCreatePnfRegistrationFields(int port, bool is_tls)
702 cJSON *pnfRegistrationFields = cJSON_CreateObject();
703 if (pnfRegistrationFields == NULL)
705 printf("Could not create JSON object: pnfRegistrationFields\n");
709 if (cJSON_AddStringToObject(pnfRegistrationFields, "pnfRegistrationFieldsVersion", "2.0") == NULL)
711 printf("Could not create JSON object: pnfRegistrationFieldsVersion\n");
715 if (cJSON_AddStringToObject(pnfRegistrationFields, "lastServiceDate", "2019-08-16") == NULL)
717 printf("Could not create JSON object: lastServiceDate\n");
722 generateRandomMacAddress(mac_addr);
724 if (cJSON_AddStringToObject(pnfRegistrationFields, "macAddress", mac_addr) == NULL)
726 printf("Could not create JSON object: macAddress\n");
730 if (cJSON_AddStringToObject(pnfRegistrationFields, "manufactureDate", "2019-08-16") == NULL)
732 printf("Could not create JSON object: manufactureDate\n");
736 if (cJSON_AddStringToObject(pnfRegistrationFields, "modelNumber", "Simulated Device Melacon") == NULL)
738 printf("Could not create JSON object: manufactureDate\n");
742 if (cJSON_AddStringToObject(pnfRegistrationFields, "oamV4IpAddress", getenv("NTS_IP")) == NULL)
744 printf("Could not create JSON object: oamV4IpAddress\n");
748 if (cJSON_AddStringToObject(pnfRegistrationFields, "oamV6IpAddress", "0:0:0:0:0:ffff:a0a:011") == NULL)
750 printf("Could not create JSON object: oamV6IpAddress\n");
754 char serial_number[100];
755 sprintf(serial_number, "%s-%s-%d-Simulated Device Melacon", getenv("HOSTNAME"), getenv("NTS_IP"), port);
757 if (cJSON_AddStringToObject(pnfRegistrationFields, "serialNumber", serial_number) == NULL)
759 printf("Could not create JSON object: serialNumber\n");
763 if (cJSON_AddStringToObject(pnfRegistrationFields, "softwareVersion", "2.3.5") == NULL)
765 printf("Could not create JSON object: softwareVersion\n");
769 if (cJSON_AddStringToObject(pnfRegistrationFields, "unitFamily", "Simulated Device") == NULL)
771 printf("Could not create JSON object: unitFamily\n");
775 if (cJSON_AddStringToObject(pnfRegistrationFields, "unitType", "O-RAN-sim") == NULL)
777 printf("Could not create JSON object: unitType\n");
781 if (cJSON_AddStringToObject(pnfRegistrationFields, "vendorName", "Melacon") == NULL)
783 printf("Could not create JSON object: vendorName\n");
787 cJSON *additionalFields = cJSON_CreateObject();
788 if (additionalFields == NULL)
790 printf("Could not create JSON object: additionalFields\n");
793 cJSON_AddItemToObject(pnfRegistrationFields, "additionalFields", additionalFields);
796 sprintf(portString, "%d", port);
798 if (cJSON_AddStringToObject(additionalFields, "oamPort", portString) == NULL)
800 printf("Could not create JSON object: oamPort\n");
806 //TLS specific configuration
807 if (cJSON_AddStringToObject(additionalFields, "protocol", "TLS") == NULL)
809 printf("Could not create JSON object: protocol\n");
813 //TODO here we have the username from the docker container hardcoded: netconf
814 if (cJSON_AddStringToObject(additionalFields, "username", "netconf") == NULL)
816 printf("Could not create JSON object: username\n");
820 if (cJSON_AddStringToObject(additionalFields, "keyId", "device-key") == NULL)
822 printf("Could not create JSON object: keyId\n");
828 //SSH specific configuration
829 if (cJSON_AddStringToObject(additionalFields, "protocol", "SSH") == NULL)
831 printf("Could not create JSON object: protocol\n");
835 //TODO here we have the username from the docker container hardcoded: netconf
836 if (cJSON_AddStringToObject(additionalFields, "username", "netconf") == NULL)
838 printf("Could not create JSON object: username\n");
842 //TODO here we have the password from the docker container hardcoded: netconf
843 if (cJSON_AddStringToObject(additionalFields, "password", "netconf") == NULL)
845 printf("Could not create JSON object: password\n");
850 if (cJSON_AddStringToObject(additionalFields, "reconnectOnChangedSchema", "false") == NULL)
852 printf("Could not create JSON object: reconnectOnChangedSchema\n");
856 if (cJSON_AddStringToObject(additionalFields, "sleep-factor", "1.5") == NULL)
858 printf("Could not create JSON object: sleep-factor\n");
862 if (cJSON_AddStringToObject(additionalFields, "tcpOnly", "false") == NULL)
864 printf("Could not create JSON object: tcpOnly\n");
868 if (cJSON_AddStringToObject(additionalFields, "connectionTimeout", "20000") == NULL)
870 printf("Could not create JSON object: connectionTimeout\n");
874 if (cJSON_AddStringToObject(additionalFields, "maxConnectionAttempts", "100") == NULL)
876 printf("Could not create JSON object: maxConnectionAttempts\n");
880 if (cJSON_AddStringToObject(additionalFields, "betweenAttemptsTimeout", "2000") == NULL)
882 printf("Could not create JSON object: betweenAttemptsTimeout\n");
886 if (cJSON_AddStringToObject(additionalFields, "keepaliveDelay", "120") == NULL)
888 printf("Could not create JSON object: keepaliveDelay\n");
892 return pnfRegistrationFields;
895 int getNetconfAvailableFromConfigJson(void)
897 char *stringConfig = readConfigFileInString();
899 if (stringConfig == NULL)
901 printf("Could not read JSON configuration file in string.");
905 cJSON *jsonConfig = cJSON_Parse(stringConfig);
906 if (jsonConfig == NULL)
909 const char *error_ptr = cJSON_GetErrorPtr();
910 if (error_ptr != NULL)
912 fprintf(stderr, "Could not parse JSON configuration! Error before: %s\n", error_ptr);
914 return SR_ERR_OPERATION_FAILED;
916 //we don't need the string anymore
919 cJSON *notifDetails = cJSON_GetObjectItemCaseSensitive(jsonConfig, "notification-config");
920 if (!cJSON_IsObject(notifDetails))
922 printf("Configuration JSON is not as expected: notification-config is not an object");
924 return SR_ERR_OPERATION_FAILED;
927 cJSON *isNetconfAvailable = cJSON_GetObjectItemCaseSensitive(notifDetails, "is-netconf-available");
928 if (!cJSON_IsBool(isNetconfAvailable))
930 printf("Configuration JSON is not as expected: is-netconf-available is not an object");
932 return SR_ERR_OPERATION_FAILED;
935 int is_netconf_available = (cJSON_IsTrue(isNetconfAvailable)) ? TRUE : FALSE;
939 return is_netconf_available;
942 int getVesAvailableFromConfigJson(void)
944 char *stringConfig = readConfigFileInString();
946 if (stringConfig == NULL)
948 printf("Could not read JSON configuration file in string.");
952 cJSON *jsonConfig = cJSON_Parse(stringConfig);
953 if (jsonConfig == NULL)
956 const char *error_ptr = cJSON_GetErrorPtr();
957 if (error_ptr != NULL)
959 fprintf(stderr, "Could not parse JSON configuration! Error before: %s\n", error_ptr);
961 return SR_ERR_OPERATION_FAILED;
963 //we don't need the string anymore
966 cJSON *notifDetails = cJSON_GetObjectItemCaseSensitive(jsonConfig, "notification-config");
967 if (!cJSON_IsObject(notifDetails))
969 printf("Configuration JSON is not as expected: notification-config is not an object");
971 return SR_ERR_OPERATION_FAILED;
974 cJSON *isVesAvailable = cJSON_GetObjectItemCaseSensitive(notifDetails, "is-ves-available");
975 if (!cJSON_IsBool(isVesAvailable))
977 printf("Configuration JSON is not as expected: is-ves-available is not an object");
979 return SR_ERR_OPERATION_FAILED;
982 int is_netconf_available = (cJSON_IsTrue(isVesAvailable)) ? TRUE : FALSE;
986 return is_netconf_available;
989 cJSON* vesCreateFaultFields(char *alarm_condition, char *alarm_object, char *severity, char *date_time, char *specific_problem)
991 cJSON *faultFields = cJSON_CreateObject();
992 if (faultFields == NULL)
994 printf("Could not create JSON object: faultFields\n");
998 if (cJSON_AddStringToObject(faultFields, "faultFieldsVersion", "4.0") == NULL)
1000 printf("Could not create JSON object: faultFieldsVersion\n");
1004 if (cJSON_AddStringToObject(faultFields, "alarmCondition", alarm_condition) == NULL)
1006 printf("Could not create JSON object: alarmCondition\n");
1010 if (cJSON_AddStringToObject(faultFields, "alarmInterfaceA", alarm_object) == NULL)
1012 printf("Could not create JSON object: alarmInterfaceA\n");
1016 if (cJSON_AddStringToObject(faultFields, "eventSourceType", "O_RAN_COMPONENT") == NULL)
1018 printf("Could not create JSON object: eventSourceType\n");
1022 if (cJSON_AddStringToObject(faultFields, "specificProblem", specific_problem) == NULL)
1024 printf("Could not create JSON object: specificProblem\n");
1028 if (cJSON_AddStringToObject(faultFields, "eventSeverity", severity) == NULL)
1030 printf("Could not create JSON object: eventSeverity\n");
1034 if (cJSON_AddStringToObject(faultFields, "vfStatus", "Active") == NULL)
1036 printf("Could not create JSON object: vfStatus\n");
1040 cJSON *alarmAdditionalInformation = cJSON_CreateObject();
1041 if (alarmAdditionalInformation == NULL)
1043 printf("Could not create JSON object: alarmAdditionalInformation\n");
1046 cJSON_AddItemToObject(faultFields, "alarmAdditionalInformation", alarmAdditionalInformation);
1048 if (cJSON_AddStringToObject(alarmAdditionalInformation, "eventTime", date_time) == NULL)
1050 printf("Could not create JSON object: eventTime\n");
1054 if (cJSON_AddStringToObject(alarmAdditionalInformation, "equipType", "O-RAN-sim") == NULL)
1056 printf("Could not create JSON object: equipType\n");
1060 if (cJSON_AddStringToObject(alarmAdditionalInformation, "vendor", "Melacon") == NULL)
1062 printf("Could not create JSON object: vendor\n");
1066 if (cJSON_AddStringToObject(alarmAdditionalInformation, "model", "Simulated Device") == NULL)
1068 printf("Could not create JSON object: model\n");