1 /*************************************************************************
3 * Copyright 2019 highstreet technologies GmbH and others
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
9 * http://www.apache.org/licenses/LICENSE-2.0
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 ***************************************************************************/
18 #ifndef EXAMPLES_NTSIMULATOR_UTILS_H_
19 #define EXAMPLES_NTSIMULATOR_UTILS_H_
22 #include "sysrepo/values.h"
23 #include "sysrepo/xpath.h"
25 #include <curl/curl.h>
29 #include <cjson/cJSON.h>
34 #define NETCONF_CONNECTIONS_PER_DEVICE (getSshConnectionsFromConfigJson() + getTlsConnectionsFromConfigJson())
35 #define SSH_CONNECTIONS_PER_DEVICE getSshConnectionsFromConfigJson()
36 #define TLS_CONNECTIONS_PER_DEVICE getTlsConnectionsFromConfigJson()
38 #define PREPARE_ADD_NEW_VALUE(v, num) {\
42 #define CREATE_NEW_VALUE(rc, v, num) {\
43 rc = sr_realloc_values(num, num+1, &v);\
44 if (SR_ERR_OK != rc) {\
59 void set_curl_common_info_ves(CURL *curl);
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);
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);
75 char* readConfigFileInString(void);
76 void writeConfigFile(char *config);
77 int writeSkeletonConfigFile(void);
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);
90 void generateRandomMacAddress(char *mac_address);
92 int writeSkeletonStatusFile(void);
93 char* readStatusFileInString(void);
95 int writeStatusNotificationCounters(counterAlarms ves_counter, counterAlarms netconf_counter);
96 void writeStatusFile(char *status);
97 int removeDeviceEntryFromStatusFile(char *deviceName);
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);
103 int getIntFromString(char *string, int def_value);
105 #endif /* EXAMPLES_NTSIMULATOR_UTILS_H_ */