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);
196 sprintf(hostname, "%s", getenv("HOSTNAME"));
198 long int useconds = getMicrosecondsSinceEpoch;
200 cJSON *commonEventHeader = cJSON_CreateObject();
201 if (commonEventHeader == NULL)
203 printf("Could not create JSON object: commonEventHeader\n");
207 if (cJSON_AddStringToObject(commonEventHeader, "domain", domain) == NULL)
209 printf("Could not create JSON object: domain\n");
214 sprintf(eventId, "%s_%s", hostname, dateAndTime);
216 if (cJSON_AddStringToObject(commonEventHeader, "eventId", eventId) == NULL)
218 printf("Could not create JSON object: eventId\n");
222 char event_name[200];
223 sprintf(event_name, "%s_%s", domain, event_type);
225 if (cJSON_AddStringToObject(commonEventHeader, "eventName", event_name) == NULL)
227 printf("Could not create JSON object: eventName\n");
231 if (cJSON_AddStringToObject(commonEventHeader, "eventType", event_type) == NULL)
233 printf("Could not create JSON object: eventType\n");
237 if (cJSON_AddNumberToObject(commonEventHeader, "sequence", (double)(seq_id)) == NULL)
239 printf("Could not create JSON object: sequence\n");
243 if (cJSON_AddStringToObject(commonEventHeader, "priority", "Low") == NULL)
245 printf("Could not create JSON object: priority\n");
249 if (cJSON_AddStringToObject(commonEventHeader, "reportingEntityId", "") == NULL)
251 printf("Could not create JSON object: reportingEntityId\n");
255 if (cJSON_AddStringToObject(commonEventHeader, "reportingEntityName", hostname) == NULL)
257 printf("Could not create JSON object: reportingEntityName\n");
261 if (cJSON_AddStringToObject(commonEventHeader, "sourceId", "") == NULL)
263 printf("Could not create JSON object: sourceId\n");
267 if (cJSON_AddStringToObject(commonEventHeader, "sourceName", source_name) == NULL)
269 printf("Could not create JSON object: sourceName\n");
273 if (cJSON_AddNumberToObject(commonEventHeader, "startEpochMicrosec", (double)(useconds)) == NULL)
275 printf("Could not create JSON object: startEpochMicrosec\n");
279 if (cJSON_AddNumberToObject(commonEventHeader, "lastEpochMicrosec", (double)(useconds)) == NULL)
281 printf("Could not create JSON object: lastEpochMicrosec\n");
285 if (cJSON_AddStringToObject(commonEventHeader, "nfNamingCode", "sdn controller") == NULL)
287 printf("Could not create JSON object: nfNamingCode\n");
291 if (cJSON_AddStringToObject(commonEventHeader, "nfVendorName", "sdn") == NULL)
293 printf("Could not create JSON object: nfVendorName\n");
297 if (cJSON_AddStringToObject(commonEventHeader, "timeZoneOffset", "+00:00") == NULL)
299 printf("Could not create JSON object: timeZoneOffset\n");
303 if (cJSON_AddStringToObject(commonEventHeader, "version", "4.0.1") == NULL)
305 printf("Could not create JSON object: version\n");
309 if (cJSON_AddStringToObject(commonEventHeader, "vesEventListenerVersion", "7.0.1") == NULL)
311 printf("Could not create JSON object: vesEventListenerVersion\n");
315 return commonEventHeader;
318 cJSON* vesCreateHeartbeatFields(int heartbeat_interval)
320 char dateAndTime[50];
321 getCurrentDateAndTime(dateAndTime);
323 cJSON *heartbeatFields = cJSON_CreateObject();
324 if (heartbeatFields == NULL)
326 printf("Could not create JSON object: heartbeatFields\n");
330 if (cJSON_AddStringToObject(heartbeatFields, "heartbeatFieldsVersion", "3.0") == NULL)
332 printf("Could not create JSON object: heartbeatFieldsVersion\n");
336 if (cJSON_AddNumberToObject(heartbeatFields, "heartbeatInterval", (double)(heartbeat_interval)) == NULL)
338 printf("Could not create JSON object: heartbeatInterval\n");
342 cJSON *additionalFields = cJSON_CreateObject();
343 if (additionalFields == NULL)
345 printf("Could not create JSON object: additionalFields\n");
348 cJSON_AddItemToObject(heartbeatFields, "additionalFields", additionalFields);
350 if (cJSON_AddStringToObject(additionalFields, "eventTime", dateAndTime) == NULL)
352 printf("Could not create JSON object: eventTime\n");
356 return heartbeatFields;
359 char* readConfigFileInString(void)
363 char config_file[200];
364 sprintf(config_file, "%s/configuration.json", getenv("SCRIPTS_DIR"));
365 FILE * f = fopen (config_file, "rb");
369 fseek (f, 0, SEEK_END);
371 fseek (f, 0, SEEK_SET);
372 buffer = malloc (length + 1);
375 fread (buffer, 1, length, f);
378 buffer[length] = '\0';
389 void writeConfigFile(char *config)
393 char config_file[200];
394 sprintf(config_file, "%s/configuration.json", getenv("SCRIPTS_DIR"));
395 FILE * f = fopen (config_file, "w");
404 printf("Could not write configuration file");
408 int getFaultNotificationDelayPeriodFromConfigJson(void)
410 char *stringConfig = readConfigFileInString();
411 int notificationDelay = 0;
413 if (stringConfig == NULL)
415 printf("Could not read JSON configuration file in string.");
419 cJSON *jsonConfig = cJSON_Parse(stringConfig);
420 if (jsonConfig == NULL)
423 const char *error_ptr = cJSON_GetErrorPtr();
424 if (error_ptr != NULL)
426 fprintf(stderr, "Could not parse JSON configuration! Error before: %s\n", error_ptr);
428 return SR_ERR_OPERATION_FAILED;
430 //we don't need the string anymore
433 cJSON *notifConfig = cJSON_GetObjectItemCaseSensitive(jsonConfig, "notification-config");
434 if (!cJSON_IsObject(notifConfig))
436 printf("Configuration JSON is not as expected: notification-config is not an object");
438 return SR_ERR_OPERATION_FAILED;
441 cJSON *faultNotifDelay = cJSON_GetObjectItemCaseSensitive(notifConfig, "fault-notification-delay-period");
442 if (!cJSON_IsNumber(faultNotifDelay))
444 printf("Configuration JSON is not as expected: fault-notification-delay-period is not a number");
446 return SR_ERR_OPERATION_FAILED;
449 notificationDelay = (int)(faultNotifDelay->valuedouble);
453 return notificationDelay;
456 int getVesHeartbeatPeriodFromConfigJson(void)
458 char *stringConfig = readConfigFileInString();
459 int vesHeartbeat = 0;
461 if (stringConfig == NULL)
463 printf("Could not read JSON configuration file in string.");
467 cJSON *jsonConfig = cJSON_Parse(stringConfig);
468 if (jsonConfig == NULL)
471 const char *error_ptr = cJSON_GetErrorPtr();
472 if (error_ptr != NULL)
474 fprintf(stderr, "Could not parse JSON configuration! Error before: %s\n", error_ptr);
476 return SR_ERR_OPERATION_FAILED;
478 //we don't need the string anymore
481 cJSON *notifConfig = cJSON_GetObjectItemCaseSensitive(jsonConfig, "notification-config");
482 if (!cJSON_IsObject(notifConfig))
484 printf("Configuration JSON is not as expected: notification-config is not an object");
486 return SR_ERR_OPERATION_FAILED;
489 cJSON *vesHeartbeatPeriod = cJSON_GetObjectItemCaseSensitive(notifConfig, "ves-heartbeat-period");
490 if (!cJSON_IsNumber(vesHeartbeatPeriod))
492 printf("Configuration JSON is not as expected: ves-heartbeat-period is not a number");
494 return SR_ERR_OPERATION_FAILED;
497 vesHeartbeat = (int)(vesHeartbeatPeriod->valuedouble);
506 * Dynamically allocated memory;
507 * Caller needs to free the memory after it uses the value.
510 char* getVesAuthMethodFromConfigJson(void)
512 char *stringConfig = readConfigFileInString();
514 if (stringConfig == NULL)
516 printf("Could not read JSON configuration file in string.");
520 cJSON *jsonConfig = cJSON_Parse(stringConfig);
521 if (jsonConfig == NULL)
524 const char *error_ptr = cJSON_GetErrorPtr();
525 if (error_ptr != NULL)
527 fprintf(stderr, "Could not parse JSON configuration! Error before: %s\n", error_ptr);
529 return SR_ERR_OPERATION_FAILED;
531 //we don't need the string anymore
534 cJSON *vesDetails = cJSON_GetObjectItemCaseSensitive(jsonConfig, "ves-endpoint-details");
535 if (!cJSON_IsObject(vesDetails))
537 printf("Configuration JSON is not as expected: ves-endpoint-details is not an object");
539 return SR_ERR_OPERATION_FAILED;
542 cJSON *vesAuthMethod = cJSON_GetObjectItemCaseSensitive(vesDetails, "ves-endpoint-auth-method");
543 if (!cJSON_IsString(vesAuthMethod))
545 printf("Configuration JSON is not as expected: ves-endpoint-auth-method is not an object");
547 return SR_ERR_OPERATION_FAILED;
550 char *auth_method_string = strdup(cJSON_GetStringValue(vesAuthMethod));
554 return auth_method_string;
558 * Dynamically allocated memory;
559 * Caller needs to free the memory after it uses the value.
562 char* getVesIpFromConfigJson(void)
564 char *stringConfig = readConfigFileInString();
566 if (stringConfig == NULL)
568 printf("Could not read JSON configuration file in string.");
572 cJSON *jsonConfig = cJSON_Parse(stringConfig);
573 if (jsonConfig == NULL)
576 const char *error_ptr = cJSON_GetErrorPtr();
577 if (error_ptr != NULL)
579 fprintf(stderr, "Could not parse JSON configuration! Error before: %s\n", error_ptr);
581 return SR_ERR_OPERATION_FAILED;
583 //we don't need the string anymore
586 cJSON *vesDetails = cJSON_GetObjectItemCaseSensitive(jsonConfig, "ves-endpoint-details");
587 if (!cJSON_IsObject(vesDetails))
589 printf("Configuration JSON is not as expected: ves-endpoint-details is not an object");
591 return SR_ERR_OPERATION_FAILED;
594 cJSON *vesIp = cJSON_GetObjectItemCaseSensitive(vesDetails, "ves-endpoint-ip");
595 if (!cJSON_IsString(vesIp))
597 printf("Configuration JSON is not as expected: ves-endpoint-ip is not an object");
599 return SR_ERR_OPERATION_FAILED;
602 char *ves_ip = strdup(cJSON_GetStringValue(vesIp));
609 int getVesPortFromConfigJson(void)
611 char *stringConfig = readConfigFileInString();
613 if (stringConfig == NULL)
615 printf("Could not read JSON configuration file in string.");
619 cJSON *jsonConfig = cJSON_Parse(stringConfig);
620 if (jsonConfig == NULL)
623 const char *error_ptr = cJSON_GetErrorPtr();
624 if (error_ptr != NULL)
626 fprintf(stderr, "Could not parse JSON configuration! Error before: %s\n", error_ptr);
628 return SR_ERR_OPERATION_FAILED;
630 //we don't need the string anymore
633 cJSON *vesDetails = cJSON_GetObjectItemCaseSensitive(jsonConfig, "ves-endpoint-details");
634 if (!cJSON_IsObject(vesDetails))
636 printf("Configuration JSON is not as expected: ves-endpoint-details is not an object");
638 return SR_ERR_OPERATION_FAILED;
641 cJSON *vesPort = cJSON_GetObjectItemCaseSensitive(vesDetails, "ves-endpoint-port");
642 if (!cJSON_IsNumber(vesPort))
644 printf("Configuration JSON is not as expected: ves-endpoint-port is not an object");
646 return SR_ERR_OPERATION_FAILED;
649 int port = (int)(vesPort->valuedouble);
656 int getVesRegistrationFromConfigJson(void)
658 char *stringConfig = readConfigFileInString();
660 if (stringConfig == NULL)
662 printf("Could not read JSON configuration file in string.");
666 cJSON *jsonConfig = cJSON_Parse(stringConfig);
667 if (jsonConfig == NULL)
670 const char *error_ptr = cJSON_GetErrorPtr();
671 if (error_ptr != NULL)
673 fprintf(stderr, "Could not parse JSON configuration! Error before: %s\n", error_ptr);
675 return SR_ERR_OPERATION_FAILED;
677 //we don't need the string anymore
680 cJSON *vesDetails = cJSON_GetObjectItemCaseSensitive(jsonConfig, "ves-endpoint-details");
681 if (!cJSON_IsObject(vesDetails))
683 printf("Configuration JSON is not as expected: ves-endpoint-details is not an object");
685 return SR_ERR_OPERATION_FAILED;
688 cJSON *vesReg = cJSON_GetObjectItemCaseSensitive(vesDetails, "ves-registration");
689 if (!cJSON_IsBool(vesReg))
691 printf("Configuration JSON is not as expected: ves-registration is not an object");
693 return SR_ERR_OPERATION_FAILED;
696 int is_ves_reg = (cJSON_IsTrue(vesReg)) ? TRUE : FALSE;
703 cJSON* vesCreatePnfRegistrationFields(int port, bool is_tls)
705 cJSON *pnfRegistrationFields = cJSON_CreateObject();
706 if (pnfRegistrationFields == NULL)
708 printf("Could not create JSON object: pnfRegistrationFields\n");
712 if (cJSON_AddStringToObject(pnfRegistrationFields, "pnfRegistrationFieldsVersion", "2.0") == NULL)
714 printf("Could not create JSON object: pnfRegistrationFieldsVersion\n");
718 if (cJSON_AddStringToObject(pnfRegistrationFields, "lastServiceDate", "2019-08-16") == NULL)
720 printf("Could not create JSON object: lastServiceDate\n");
725 generateRandomMacAddress(mac_addr);
727 if (cJSON_AddStringToObject(pnfRegistrationFields, "macAddress", mac_addr) == NULL)
729 printf("Could not create JSON object: macAddress\n");
733 if (cJSON_AddStringToObject(pnfRegistrationFields, "manufactureDate", "2019-08-16") == NULL)
735 printf("Could not create JSON object: manufactureDate\n");
739 if (cJSON_AddStringToObject(pnfRegistrationFields, "modelNumber", "Simulated Device Melacon") == NULL)
741 printf("Could not create JSON object: manufactureDate\n");
745 if (cJSON_AddStringToObject(pnfRegistrationFields, "oamV4IpAddress", getenv("NTS_IP")) == NULL)
747 printf("Could not create JSON object: oamV4IpAddress\n");
751 if (cJSON_AddStringToObject(pnfRegistrationFields, "oamV6IpAddress", "0:0:0:0:0:ffff:a0a:011") == NULL)
753 printf("Could not create JSON object: oamV6IpAddress\n");
757 char serial_number[100];
758 sprintf(serial_number, "%s-%s-%d-Simulated Device Melacon", getenv("HOSTNAME"), getenv("NTS_IP"), port);
760 if (cJSON_AddStringToObject(pnfRegistrationFields, "serialNumber", serial_number) == NULL)
762 printf("Could not create JSON object: serialNumber\n");
766 if (cJSON_AddStringToObject(pnfRegistrationFields, "softwareVersion", "2.3.5") == NULL)
768 printf("Could not create JSON object: softwareVersion\n");
772 if (cJSON_AddStringToObject(pnfRegistrationFields, "unitFamily", "Simulated Device") == NULL)
774 printf("Could not create JSON object: unitFamily\n");
778 if (cJSON_AddStringToObject(pnfRegistrationFields, "unitType", "O-RAN-sim") == NULL)
780 printf("Could not create JSON object: unitType\n");
784 if (cJSON_AddStringToObject(pnfRegistrationFields, "vendorName", "Melacon") == NULL)
786 printf("Could not create JSON object: vendorName\n");
790 cJSON *additionalFields = cJSON_CreateObject();
791 if (additionalFields == NULL)
793 printf("Could not create JSON object: additionalFields\n");
796 cJSON_AddItemToObject(pnfRegistrationFields, "additionalFields", additionalFields);
799 sprintf(portString, "%d", port);
801 if (cJSON_AddStringToObject(additionalFields, "oamPort", portString) == NULL)
803 printf("Could not create JSON object: oamPort\n");
809 //TLS specific configuration
810 if (cJSON_AddStringToObject(additionalFields, "protocol", "TLS") == NULL)
812 printf("Could not create JSON object: protocol\n");
816 //TODO here we have the username from the docker container hardcoded: netconf
817 if (cJSON_AddStringToObject(additionalFields, "username", "netconf") == NULL)
819 printf("Could not create JSON object: username\n");
823 if (cJSON_AddStringToObject(additionalFields, "keyId", "device-key") == NULL)
825 printf("Could not create JSON object: keyId\n");
831 //SSH specific configuration
832 if (cJSON_AddStringToObject(additionalFields, "protocol", "SSH") == NULL)
834 printf("Could not create JSON object: protocol\n");
838 //TODO here we have the username from the docker container hardcoded: netconf
839 if (cJSON_AddStringToObject(additionalFields, "username", "netconf") == NULL)
841 printf("Could not create JSON object: username\n");
845 //TODO here we have the password from the docker container hardcoded: netconf
846 if (cJSON_AddStringToObject(additionalFields, "password", "netconf") == NULL)
848 printf("Could not create JSON object: password\n");
853 if (cJSON_AddStringToObject(additionalFields, "reconnectOnChangedSchema", "false") == NULL)
855 printf("Could not create JSON object: reconnectOnChangedSchema\n");
859 if (cJSON_AddStringToObject(additionalFields, "sleep-factor", "1.5") == NULL)
861 printf("Could not create JSON object: sleep-factor\n");
865 if (cJSON_AddStringToObject(additionalFields, "tcpOnly", "false") == NULL)
867 printf("Could not create JSON object: tcpOnly\n");
871 if (cJSON_AddStringToObject(additionalFields, "connectionTimeout", "20000") == NULL)
873 printf("Could not create JSON object: connectionTimeout\n");
877 if (cJSON_AddStringToObject(additionalFields, "maxConnectionAttempts", "100") == NULL)
879 printf("Could not create JSON object: maxConnectionAttempts\n");
883 if (cJSON_AddStringToObject(additionalFields, "betweenAttemptsTimeout", "2000") == NULL)
885 printf("Could not create JSON object: betweenAttemptsTimeout\n");
889 if (cJSON_AddStringToObject(additionalFields, "keepaliveDelay", "120") == NULL)
891 printf("Could not create JSON object: keepaliveDelay\n");
895 return pnfRegistrationFields;
898 int getNetconfAvailableFromConfigJson(void)
900 char *stringConfig = readConfigFileInString();
902 if (stringConfig == NULL)
904 printf("Could not read JSON configuration file in string.");
908 cJSON *jsonConfig = cJSON_Parse(stringConfig);
909 if (jsonConfig == NULL)
912 const char *error_ptr = cJSON_GetErrorPtr();
913 if (error_ptr != NULL)
915 fprintf(stderr, "Could not parse JSON configuration! Error before: %s\n", error_ptr);
917 return SR_ERR_OPERATION_FAILED;
919 //we don't need the string anymore
922 cJSON *notifDetails = cJSON_GetObjectItemCaseSensitive(jsonConfig, "notification-config");
923 if (!cJSON_IsObject(notifDetails))
925 printf("Configuration JSON is not as expected: notification-config is not an object");
927 return SR_ERR_OPERATION_FAILED;
930 cJSON *isNetconfAvailable = cJSON_GetObjectItemCaseSensitive(notifDetails, "is-netconf-available");
931 if (!cJSON_IsBool(isNetconfAvailable))
933 printf("Configuration JSON is not as expected: is-netconf-available is not an object");
935 return SR_ERR_OPERATION_FAILED;
938 int is_netconf_available = (cJSON_IsTrue(isNetconfAvailable)) ? TRUE : FALSE;
942 return is_netconf_available;
945 int getVesAvailableFromConfigJson(void)
947 char *stringConfig = readConfigFileInString();
949 if (stringConfig == NULL)
951 printf("Could not read JSON configuration file in string.");
955 cJSON *jsonConfig = cJSON_Parse(stringConfig);
956 if (jsonConfig == NULL)
959 const char *error_ptr = cJSON_GetErrorPtr();
960 if (error_ptr != NULL)
962 fprintf(stderr, "Could not parse JSON configuration! Error before: %s\n", error_ptr);
964 return SR_ERR_OPERATION_FAILED;
966 //we don't need the string anymore
969 cJSON *notifDetails = cJSON_GetObjectItemCaseSensitive(jsonConfig, "notification-config");
970 if (!cJSON_IsObject(notifDetails))
972 printf("Configuration JSON is not as expected: notification-config is not an object");
974 return SR_ERR_OPERATION_FAILED;
977 cJSON *isVesAvailable = cJSON_GetObjectItemCaseSensitive(notifDetails, "is-ves-available");
978 if (!cJSON_IsBool(isVesAvailable))
980 printf("Configuration JSON is not as expected: is-ves-available is not an object");
982 return SR_ERR_OPERATION_FAILED;
985 int is_netconf_available = (cJSON_IsTrue(isVesAvailable)) ? TRUE : FALSE;
989 return is_netconf_available;
992 cJSON* vesCreateFaultFields(char *alarm_condition, char *alarm_object, char *severity, char *date_time, char *specific_problem)
994 cJSON *faultFields = cJSON_CreateObject();
995 if (faultFields == NULL)
997 printf("Could not create JSON object: faultFields\n");
1001 if (cJSON_AddStringToObject(faultFields, "faultFieldsVersion", "4.0") == NULL)
1003 printf("Could not create JSON object: faultFieldsVersion\n");
1007 if (cJSON_AddStringToObject(faultFields, "alarmCondition", alarm_condition) == NULL)
1009 printf("Could not create JSON object: alarmCondition\n");
1013 if (cJSON_AddStringToObject(faultFields, "alarmInterfaceA", alarm_object) == NULL)
1015 printf("Could not create JSON object: alarmInterfaceA\n");
1019 if (cJSON_AddStringToObject(faultFields, "eventSourceType", "O_RAN_COMPONENT") == NULL)
1021 printf("Could not create JSON object: eventSourceType\n");
1025 if (cJSON_AddStringToObject(faultFields, "specificProblem", specific_problem) == NULL)
1027 printf("Could not create JSON object: specificProblem\n");
1031 if (cJSON_AddStringToObject(faultFields, "eventSeverity", severity) == NULL)
1033 printf("Could not create JSON object: eventSeverity\n");
1037 if (cJSON_AddStringToObject(faultFields, "vfStatus", "Active") == NULL)
1039 printf("Could not create JSON object: vfStatus\n");
1043 cJSON *alarmAdditionalInformation = cJSON_CreateObject();
1044 if (alarmAdditionalInformation == NULL)
1046 printf("Could not create JSON object: alarmAdditionalInformation\n");
1049 cJSON_AddItemToObject(faultFields, "alarmAdditionalInformation", alarmAdditionalInformation);
1051 if (cJSON_AddStringToObject(alarmAdditionalInformation, "eventTime", date_time) == NULL)
1053 printf("Could not create JSON object: eventTime\n");
1057 if (cJSON_AddStringToObject(alarmAdditionalInformation, "equipType", "O-RAN-sim") == NULL)
1059 printf("Could not create JSON object: equipType\n");
1063 if (cJSON_AddStringToObject(alarmAdditionalInformation, "vendor", "Melacon") == NULL)
1065 printf("Could not create JSON object: vendor\n");
1069 if (cJSON_AddStringToObject(alarmAdditionalInformation, "model", "Simulated Device") == NULL)
1071 printf("Could not create JSON object: model\n");