Alex Stancu | 29ce368 | 2019-11-02 10:38:59 +0200 | [diff] [blame] | 1 | /* |
| 2 | * utils.h |
| 3 | * |
| 4 | * Created on: Feb 19, 2019 |
| 5 | * Author: parallels |
| 6 | */ |
| 7 | |
| 8 | #ifndef EXAMPLES_NTSIMULATOR_UTILS_H_ |
| 9 | #define EXAMPLES_NTSIMULATOR_UTILS_H_ |
| 10 | |
| 11 | #include "sysrepo.h" |
| 12 | #include "sysrepo/values.h" |
| 13 | #include "sysrepo/xpath.h" |
| 14 | |
| 15 | #include <curl/curl.h> |
| 16 | #include <stdlib.h> |
| 17 | #include <stdbool.h> |
| 18 | #include <stdio.h> |
| 19 | #include <cjson/cJSON.h> |
| 20 | |
| 21 | #define TRUE 1 |
| 22 | #define FALSE 0 |
| 23 | |
| 24 | #define NETCONF_CONNECTIONS_PER_DEVICE 10 |
| 25 | |
| 26 | #define PREPARE_ADD_NEW_VALUE(v, num) {\ |
| 27 | num++;\ |
| 28 | } |
| 29 | |
| 30 | #define CREATE_NEW_VALUE(rc, v, num) {\ |
| 31 | rc = sr_realloc_values(num, num+1, &v);\ |
| 32 | if (SR_ERR_OK != rc) {\ |
| 33 | return rc;\ |
| 34 | }\ |
| 35 | num++;\ |
| 36 | } |
| 37 | |
| 38 | void set_curl_common_info_ves(CURL *curl); |
| 39 | |
| 40 | long random_at_most(long max); |
| 41 | void getCurrentDateAndTime(char *date_and_time); |
| 42 | int getSecondsFromLastQuarterInterval(void); |
| 43 | int getSecondsFromLastDayInterval(void); |
| 44 | void getPreviousQuarterInterval(int number_of_intervals, char *date_and_time); |
| 45 | void getPreviousDayPmTimestamp(int number_of_intervals, char *date_and_time); |
| 46 | long int getMicrosecondsSinceEpoch(void); |
| 47 | void prepare_ves_message_curl(CURL *curl); |
| 48 | |
| 49 | cJSON* vesCreateCommonEventHeader(char *domain, char *event_type, char *source_name, int seq_id); |
| 50 | cJSON* vesCreateHeartbeatFields(int heartbeat_interval); |
| 51 | cJSON* vesCreatePnfRegistrationFields(int port, bool is_tls); |
| 52 | cJSON* vesCreateFaultFields(char *alarm_condition, char *alarm_object, char *severity, char *date_time, char *specific_problem); |
| 53 | |
| 54 | char* readConfigFileInString(void); |
| 55 | void writeConfigFile(char *config); |
| 56 | |
| 57 | int getFaultNotificationDelayPeriodFromConfigJson(void); |
| 58 | int getVesHeartbeatPeriodFromConfigJson(void); |
| 59 | char* getVesAuthMethodFromConfigJson(void); |
| 60 | char* getVesIpFromConfigJson(void); |
| 61 | int getVesPortFromConfigJson(void); |
| 62 | int getVesRegistrationFromConfigJson(void); |
| 63 | int getNetconfAvailableFromConfigJson(void); |
| 64 | int getVesAvailableFromConfigJson(void); |
| 65 | |
| 66 | void generateRandomMacAddress(char *mac_address); |
| 67 | |
| 68 | #endif /* EXAMPLES_NTSIMULATOR_UTILS_H_ */ |