c04650949acddc5f93b86d6fb04cd123f967c9cf
[sim/o1-interface.git] / ntsimulator / inc / utils / utils.h
1 /*************************************************************************
2 *
3 * Copyright 2019 highstreet technologies GmbH and others
4 *
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
8 *
9 *     http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 ***************************************************************************/
17
18 #ifndef EXAMPLES_NTSIMULATOR_UTILS_H_
19 #define EXAMPLES_NTSIMULATOR_UTILS_H_
20
21 #include "sysrepo.h"
22 #include "sysrepo/values.h"
23 #include "sysrepo/xpath.h"
24
25 #include <curl/curl.h>
26 #include <stdlib.h>
27 #include <stdbool.h>
28 #include <stdio.h>
29 #include <cjson/cJSON.h>
30
31 #define TRUE 1
32 #define FALSE 0
33
34 #define NETCONF_CONNECTIONS_PER_DEVICE (getSshConnectionsFromConfigJson() + getTlsConnectionsFromConfigJson())
35 #define SSH_CONNECTIONS_PER_DEVICE getSshConnectionsFromConfigJson()
36 #define TLS_CONNECTIONS_PER_DEVICE getTlsConnectionsFromConfigJson()
37
38 #define PREPARE_ADD_NEW_VALUE(v, num)   {\
39                                                                                 num++;\
40                                                                                 }
41
42 #define CREATE_NEW_VALUE(rc, v, num)    {\
43                                                                                 rc = sr_realloc_values(num, num+1, &v);\
44                                                                                 if (SR_ERR_OK != rc) {\
45                                                                                         return rc;\
46                                                                                 }\
47                                                                                 num++;\
48                                                                                 }
49
50 typedef struct
51 {
52         int normal;
53         int warning;
54         int minor;
55         int major;
56         int critical;
57 } counterAlarms;
58
59 void            set_curl_common_info_ves(CURL *curl);
60
61 long            random_at_most(long max);
62 void            getCurrentDateAndTime(char *date_and_time);
63 int             getSecondsFromLastQuarterInterval(void);
64 int             getSecondsFromLastDayInterval(void);
65 void            getPreviousQuarterInterval(int number_of_intervals, char *date_and_time);
66 void            getPreviousDayPmTimestamp(int number_of_intervals, char *date_and_time);
67 long int        getMicrosecondsSinceEpoch(void);
68 void            prepare_ves_message_curl(CURL *curl);
69
70 cJSON*  vesCreateCommonEventHeader(char *domain, char *event_type, char *source_name, int seq_id);
71 cJSON*  vesCreateHeartbeatFields(int heartbeat_interval);
72 cJSON*  vesCreatePnfRegistrationFields(int port, bool is_tls);
73 cJSON*  vesCreateFaultFields(char *alarm_condition, char *alarm_object, char *severity, char *date_time, char *specific_problem);
74
75 char*   readConfigFileInString(void);
76 void    writeConfigFile(char *config);
77 int     writeSkeletonConfigFile(void);
78
79 int     getFaultNotificationDelayPeriodFromConfigJson(int *period_array, int *count);
80 int     getVesHeartbeatPeriodFromConfigJson(void);
81 char*   getVesAuthMethodFromConfigJson(void);
82 char*   getVesIpFromConfigJson(void);
83 int     getVesPortFromConfigJson(void);
84 int     getVesRegistrationFromConfigJson(void);
85 int     getNetconfAvailableFromConfigJson(void);
86 int     getVesAvailableFromConfigJson(void);
87 int     getSshConnectionsFromConfigJson(void);
88 int     getTlsConnectionsFromConfigJson(void);
89
90 void    generateRandomMacAddress(char *mac_address);
91
92 int     writeSkeletonStatusFile(void);
93 char*   readStatusFileInString(void);
94
95 int     writeStatusNotificationCounters(counterAlarms ves_counter, counterAlarms netconf_counter);
96 void    writeStatusFile(char *status);
97 int     removeDeviceEntryFromStatusFile(char *deviceName);
98
99 cJSON*  getDeviceListFromStatusFile(void);
100 int     compute_notifications_count(counterAlarms *ves_counter, counterAlarms *netconf_counter);
101 int     getDeviceCounters(char *containerId, counterAlarms *ves_counter, counterAlarms *netconf_counter);
102
103 int     getIntFromString(char *string, int def_value);
104
105 #endif /* EXAMPLES_NTSIMULATOR_UTILS_H_ */