diff options
author | PrakashH <pbhandar@techmahindra.com> | 2019-01-28 17:14:52 +0000 |
---|---|---|
committer | PrakashH <pbhandar@techmahindra.com> | 2019-01-28 17:45:15 +0000 |
commit | af7aa682517d3ccaace9a089194e6a4333f4cdaa (patch) | |
tree | f9da027c69fff993b907ca93130aa47fe9c9786d /vnfs/VES5.0/evel | |
parent | 3bf047e64a1121208719e7603bf91c69d532ecf8 (diff) |
VES EVEL Library VES 5.4.1 enhancements
HB-Fault-Measurement-Syslog-2Collector enhancement.
Issue-ID: CERT-17
Change-Id: Ieff01ee5461e50c7e7d07d10ec66c1c97cf8c5b1
Signed-off-by: PrakashH <pbhandar@techmahindra.com>
Diffstat (limited to 'vnfs/VES5.0/evel')
53 files changed, 7397 insertions, 165 deletions
diff --git a/vnfs/VES5.0/evel/evel-library/code/VESreporting_HB/LICENSE.TXT b/vnfs/VES5.0/evel/evel-library/code/VESreporting_HB/LICENSE.TXT new file mode 100644 index 00000000..16285cd2 --- /dev/null +++ b/vnfs/VES5.0/evel/evel-library/code/VESreporting_HB/LICENSE.TXT @@ -0,0 +1,22 @@ +/* + * ============LICENSE_START========================================== + * =================================================================== + * Copyright © 2017 AT&T Intellectual Property. All rights reserved. + * =================================================================== + * Unless otherwise specified, all software contained herein is + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END============================================ + * + * ECOMP is trademark and service mark of AT&T Intellectual Property. + * + */ diff --git a/vnfs/VES5.0/evel/evel-library/code/VESreporting_HB/Makefile b/vnfs/VES5.0/evel/evel-library/code/VESreporting_HB/Makefile new file mode 100644 index 00000000..e0077597 --- /dev/null +++ b/vnfs/VES5.0/evel/evel-library/code/VESreporting_HB/Makefile @@ -0,0 +1,52 @@ +############################################################################# +# +# Copyright © 2018 AT&T Intellectual Property. All rights reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +############################################################################# + +CC=gcc +ARCH=$(shell getconf LONG_BIT) +CODE_ROOT=$(CURDIR)/../.. +#CODE_ROOT=../code/evel-library +LIBS_DIR=$(CODE_ROOT)/libs/x86_$(ARCH) +#LIBS_DIR=/usr/lib +INCLUDE_DIR= -I $(CODE_ROOT)/code/evel_library -I . + +#****************************************************************************** +# Standard compiler flags. * +#****************************************************************************** +CPPFLAGS= +CFLAGS=-Wall -g -fPIC +FILEOBJLIST= jsmn.o ves_heartbeat_reporter.o + +all: ves_heartbeat_reporter + +clean: + rm -f *.o ves_heartbeat_reporter + +%.o: %.c + $(CC) $(CPPFLAGS) $(CFLAGS) $(INCLUDE_DIR) -c $< -o $@ + +jsmn.o: jsmn.c jsmn.h +ves_heartbeat_reporter.o: ves_heartbeat_reporter.c + +ves_heartbeat_reporter: $(FILEOBJLIST) + $(CC) $(CPPFLAGS) $(CFLAGS) -o ves_heartbeat_reporter \ + -L $(LIBS_DIR) \ + $(FILEOBJLIST) \ + -lpthread \ + -level \ + -lcurl + + diff --git a/vnfs/VES5.0/evel/evel-library/code/VESreporting_HB/README.md b/vnfs/VES5.0/evel/evel-library/code/VESreporting_HB/README.md new file mode 100644 index 00000000..a0d8e762 --- /dev/null +++ b/vnfs/VES5.0/evel/evel-library/code/VESreporting_HB/README.md @@ -0,0 +1,37 @@ + +PROJECT DESCRIPTION + +--- +This project contains the source code and scripts for the periodic generation of heartbeat events. The folder contains: + + - README.md: this file. + + - LICENSE.TXT: the license text. + + - ves_heartbeat_reporter.c and other .c files: source code that uses the ECOMP Vendor Event Listener Library (VES) to generate the periodic hertbeat events. It reads hb_config.json file for parameter values and poppulate the heartbeat event. If eventName parameter value is not given, the application terminates. If reportingEntityName and sourceName parameter values are not given, then it gets the hostname and poppulates it. If heartbeatInterval is not given, it defaults to 60 seconds. + + - Makefile: makefile that compiles ves_heartbeat_reporter.c and generates ves_heartbeat_reporter binary. + + - go-client.sh/go-client_2_collectors.sh: bash script that starts up the ves_heartbeat_reporter. It reads input parameters like DCAE IP address and port from configuration files contained in /opt/config. Based on the collector configuration, use go-client.sh for single collector configuration, or use go-client_2_collectors.sh for 2 collectors configuration. + + +USAGE +----- + +Update the configuration files with proper parameters values so that events generated would contain those values + +To run the ves_heartbeat_reporter in single collector configuration, please execute the following steps: + + - Make the go-client.sh script executable + chmod +x go-client.sh + + - Run the go-client.sh script + ./go-client.sh + +For 2 collectors configuration, please execute following steps: + + - Make the go-client.sh script executable + chmod +x go-client_2_collectors.sh + + - Run the go-client_2_collectors.sh script + ./go-client_2_collectors.sh diff --git a/vnfs/VES5.0/evel/evel-library/code/VESreporting_HB/dep.xml b/vnfs/VES5.0/evel/evel-library/code/VESreporting_HB/dep.xml new file mode 100644 index 00000000..fc18229f --- /dev/null +++ b/vnfs/VES5.0/evel/evel-library/code/VESreporting_HB/dep.xml @@ -0,0 +1,25 @@ +<assembly xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.2" + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.2 http://maven.apache.org/xsd/assembly-1.1.2.xsd"> + <id>demo</id> + <formats> + <format>tar.gz</format> + </formats> + <fileSets> + + <fileSet> + <directory>.</directory> + <outputDirectory>/</outputDirectory> + <includes> + <include>*.sh</include> + <include>*.md</include> + <include>*.TXT</include> + <include>*.c</include> + <include>Makefile</include> + </includes> + </fileSet> + + </fileSets> +</assembly> + + diff --git a/vnfs/VES5.0/evel/evel-library/code/VESreporting_HB/go-client.sh b/vnfs/VES5.0/evel/evel-library/code/VESreporting_HB/go-client.sh new file mode 100755 index 00000000..22b930d1 --- /dev/null +++ b/vnfs/VES5.0/evel/evel-library/code/VESreporting_HB/go-client.sh @@ -0,0 +1,6 @@ +#!/bin/bash + +export LD_LIBRARY_PATH="/opt/VES/evel/evel-library/libs/x86_64/" +DCAE_COLLECTOR_IP=$(cat /opt/config/dcae_collector_ip.txt) +DCAE_COLLECTOR_PORT=$(cat /opt/config/dcae_collector_port.txt) +./ves_heartbeat_reporter $DCAE_COLLECTOR_IP $DCAE_COLLECTOR_PORT diff --git a/vnfs/VES5.0/evel/evel-library/code/VESreporting_HB/go-client_2_collectors.sh b/vnfs/VES5.0/evel/evel-library/code/VESreporting_HB/go-client_2_collectors.sh new file mode 100755 index 00000000..b3747e29 --- /dev/null +++ b/vnfs/VES5.0/evel/evel-library/code/VESreporting_HB/go-client_2_collectors.sh @@ -0,0 +1,12 @@ +#!/bin/bash + +export LD_LIBRARY_PATH="/opt/VES/evel/evel-library/libs/x86_64/" + +#Usage for 2 collectors: +#./ves_heartbeat_reporter <FQDN>|<IP address> <port> <FQDN>|<IP address> <port> + +DCAE_COLLECTOR_IP=$(cat /opt/config/dcae_collector_ip.txt) +DCAE_COLLECTOR_PORT=$(cat /opt/config/dcae_collector_port.txt) +DCAE_COLLECTOR_IP2=$(cat /opt/config/dcae_collector_ip2.txt) +DCAE_COLLECTOR_PORT2=$(cat /opt/config/dcae_collector_port2.txt) +./ves_heartbeat_reporter $DCAE_COLLECTOR_IP $DCAE_COLLECTOR_PORT $DCAE_COLLECTOR_IP2 $DCAE_COLLECTOR_PORT2 diff --git a/vnfs/VES5.0/evel/evel-library/code/VESreporting_HB/hb_config.json b/vnfs/VES5.0/evel/evel-library/code/VESreporting_HB/hb_config.json new file mode 100644 index 00000000..db32d2db --- /dev/null +++ b/vnfs/VES5.0/evel/evel-library/code/VESreporting_HB/hb_config.json @@ -0,0 +1,13 @@ +{ + "tmp_directParameters": { + "eventType": "platform", + "eventName": "Heartbeat_VNF-AT&T_heartbeat", + "nfcNamingCode": "ssc", + "nfNamingCode": "scfx", + "reportingEntityId": "cc305d54-75b4-431b-adb2-eb6b9e541234", + "reportingEntityName": "ibcx0001vm002oam001", + "sourceId": "de305d54-75b4-431b-adb2-eb6b9e546014", + "sourceName": "scfx0001vm002cap001", + "heartbeatInterval": 10 + } +} diff --git a/vnfs/VES5.0/evel/evel-library/code/VESreporting_HB/jsmn.c b/vnfs/VES5.0/evel/evel-library/code/VESreporting_HB/jsmn.c new file mode 100644 index 00000000..f663403e --- /dev/null +++ b/vnfs/VES5.0/evel/evel-library/code/VESreporting_HB/jsmn.c @@ -0,0 +1,615 @@ +/*************************************************************************//** + * + * Copyright © 2017 AT&T Intellectual Property. All rights reserved. + * + * Unless otherwise specified, all software contained herein is + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ECOMP is a trademark and service mark of AT&T Intellectual Property. + ****************************************************************************/ +#include<stdio.h> +#include<stdlib.h> +#include<string.h> +#include "jsmn.h" + +/** + * Allocates a fresh unused token from the token pull. + */ +static jsmntok_t *jsmn_alloc_token(jsmn_parser *parser, + jsmntok_t *tokens, size_t num_tokens) { + jsmntok_t *tok; + if (parser->toknext >= num_tokens) { + return NULL; + } + tok = &tokens[parser->toknext++]; + tok->start = tok->end = -1; + tok->size = 0; +//#ifdef JSMN_PARENT_LINKS + tok->parent = -1; +//#endif + return tok; +} + +/** + * Fills token type and boundaries. + */ +static void jsmn_fill_token(jsmntok_t *token, jsmntype_t type, + int start, int end) { +//printf("jsmn_fill_token:: start-%d, end-%d\n", start, end); + token->type = type; + token->start = start; + token->end = end; + token->size = 0; +} + +/** + * Fills next available token with JSON primitive. + */ +static int jsmn_parse_primitive(jsmn_parser *parser, const char *js, + size_t len, jsmntok_t *tokens, size_t num_tokens) { + jsmntok_t *token; + int start; + + start = parser->pos; + + for (; parser->pos < len && js[parser->pos] != '\0'; parser->pos++) { +//printf("jsmn_parse_primitive:: the char is - %c\n", js[parser->pos]); + switch (js[parser->pos]) { +#ifndef JSMN_STRICT + /* In strict mode primitive must be followed by "," or "}" or "]" */ + case ':': +#endif + case '\t' : case '\r' : case '\n' : case ' ' : + case ',' : case ']' : case '}' : + goto found; + } + if (js[parser->pos] < 32 || js[parser->pos] >= 127) { + parser->pos = start; + return JSMN_ERROR_INVAL; + } + } +#ifdef JSMN_STRICT + /* In strict mode primitive must be followed by a comma/object/array */ + parser->pos = start; + return JSMN_ERROR_PART; +#endif + +found: + if (tokens == NULL) { + parser->pos--; + return 0; + } + token = jsmn_alloc_token(parser, tokens, num_tokens); + if (token == NULL) { + parser->pos = start; + return JSMN_ERROR_NOMEM; + } + jsmn_fill_token(token, JSMN_PRIMITIVE, start, parser->pos); +//#ifdef JSMN_PARENT_LINKS + token->parent = parser->toksuper; +//#endif + parser->pos--; + return 0; +} + +/** + * Fills next token with JSON string. + */ +static int jsmn_parse_string(jsmn_parser *parser, const char *js, + size_t len, jsmntok_t *tokens, size_t num_tokens) { + jsmntok_t *token; + + int start = parser->pos; + + parser->pos++; + + /* Skip starting quote */ + for (; parser->pos < len && js[parser->pos] != '\0'; parser->pos++) { + char c = js[parser->pos]; + char d = js[parser->pos + 1]; +// char e = js[parser->pos + 2]; +//printf("jsmn_parse_string: value-%c, pos-%d\n", c,parser->pos); + + /* Quote: end of string */ +// if (c == '\"') { + if (d == '\"') { +// if ((d == '\"')&&((e == ' ')||(e == ','))) { +parser->pos++; +//printf("jsmn_parse_string: end of string\n"); + if (tokens == NULL) { +//printf("jsmn_parse_string: end tokens is NULL\n"); + return 0; + } + token = jsmn_alloc_token(parser, tokens, num_tokens); +//printf("jsmn_parse_string: Allocated tokens \n"); + if (token == NULL) { +//printf("jsmn_parse_string: Allocated tokens is NULL\n"); + parser->pos = start; + return JSMN_ERROR_NOMEM; + } + jsmn_fill_token(token, JSMN_STRING, start+1, parser->pos); +//printf("jsmn_parse_string: Allocated tokens is filled\n"); +//#ifdef JSMN_PARENT_LINKS + token->parent = parser->toksuper; +//#endif + return 0; + } + + /* Backslash: Quoted symbol expected */ + if (c == '\\' && parser->pos + 1 < len) { + int i; + parser->pos++; +//printf("jsmn_parse_string: value - %c, POS-%3d \n",c, js[parser->pos]); + switch (js[parser->pos]) { + /* Allowed escaped symbols */ + case '\"': case '/' : case '\\' : case 'b' : + case 'f' : case 'r' : case 'n' : case 't' : + break; + /* Allows escaped symbol \uXXXX */ + case 'u': + parser->pos++; + for(i = 0; i < 4 && parser->pos < len && js[parser->pos] != '\0'; i++) { + /* If it isn't a hex character we have an error */ + if(!((js[parser->pos] >= 48 && js[parser->pos] <= 57) || /* 0-9 */ + (js[parser->pos] >= 65 && js[parser->pos] <= 70) || /* A-F */ + (js[parser->pos] >= 97 && js[parser->pos] <= 102))) { /* a-f */ + parser->pos = start; + return JSMN_ERROR_INVAL; + } + parser->pos++; + } + parser->pos--; + break; + /* Unexpected symbol */ + default: + parser->pos = start; + return JSMN_ERROR_INVAL; + } + } + } + parser->pos = start; +printf("jsmn_parse_string: exiting with ERROR_PART, pos-%d", parser->pos); + return JSMN_ERROR_PART; +} + +/** + * Parse JSON string and fill tokens. + */ +int jsmn_parse(jsmn_parser *parser, const char *js, size_t len, + jsmntok_t *tokens, unsigned int num_tokens) { + int r; + int i; + jsmntok_t *token; + int count = parser->toknext; + + for (; parser->pos < len && js[parser->pos] != '\0'; parser->pos++) { + char c; + jsmntype_t type; + + c = js[parser->pos]; +//printf("jsmn_parse: value of c - %c\n",c); + switch (c) { + case '{': case '[': + count++; + if (tokens == NULL) { + break; + } + token = jsmn_alloc_token(parser, tokens, num_tokens); + if (token == NULL) + return JSMN_ERROR_NOMEM; + if (parser->toksuper != -1) { + tokens[parser->toksuper].size++; +//#ifdef JSMN_PARENT_LINKS + token->parent = parser->toksuper; +//#endif + } + token->type = (c == '{' ? JSMN_OBJECT : JSMN_ARRAY); + token->start = parser->pos; + parser->toksuper = parser->toknext - 1; + break; + case '}': case ']': + if (tokens == NULL) + break; + type = (c == '}' ? JSMN_OBJECT : JSMN_ARRAY); +//#ifdef JSMN_PARENT_LINKS + if (parser->toknext < 1) { + return JSMN_ERROR_INVAL; + } + token = &tokens[parser->toknext - 1]; + for (;;) { + if (token->start != -1 && token->end == -1) { + if (token->type != type) { + return JSMN_ERROR_INVAL; + } + token->end = parser->pos + 1; + parser->toksuper = token->parent; + break; + } + if (token->parent == -1) { + break; + } + token = &tokens[token->parent]; + } +//#else +// for (i = parser->toknext - 1; i >= 0; i--) { +// token = &tokens[i]; +// if (token->start != -1 && token->end == -1) { +// if (token->type != type) { +// return JSMN_ERROR_INVAL; +// } +// parser->toksuper = -1; +// token->end = parser->pos + 1; +// break; +// } +// } +// /* Error if unmatched closing bracket */ +// if (i == -1) return JSMN_ERROR_INVAL; +// for (; i >= 0; i--) { +// token = &tokens[i]; +// if (token->start != -1 && token->end == -1) { +// parser->toksuper = i; +// break; +// } +// } +//#endif + break; + case '\"': + r = jsmn_parse_string(parser, js, len, tokens, num_tokens); + if (r < 0) return r; + count++; + if (parser->toksuper != -1 && tokens != NULL) + tokens[parser->toksuper].size++; + break; + case '\t' : case '\r' : case '\n' : case ' ': + break; + case ':': + parser->toksuper = parser->toknext - 1; +//printf("jsmn_parse: value of c is :: - %c\n",c); + break; + case ',': + if (tokens != NULL && parser->toksuper != -1 && + tokens[parser->toksuper].type != JSMN_ARRAY && + tokens[parser->toksuper].type != JSMN_OBJECT) { +//#ifdef JSMN_PARENT_LINKS + parser->toksuper = tokens[parser->toksuper].parent; +//#else +// for (i = parser->toknext - 1; i >= 0; i--) { +// if (tokens[i].type == JSMN_ARRAY || tokens[i].type == JSMN_OBJECT) { +// if (tokens[i].start != -1 && tokens[i].end == -1) { +// parser->toksuper = i; +// break; +// } +// } +// } +//#endif + } + break; +#ifdef JSMN_STRICT + /* In strict mode primitives are: numbers and booleans */ + case '-': case '0': case '1' : case '2': case '3' : case '4': + case '5': case '6': case '7' : case '8': case '9': + case 't': case 'f': case 'n' : + /* And they must not be keys of the object */ + if (tokens != NULL && parser->toksuper != -1) { + jsmntok_t *t = &tokens[parser->toksuper]; + if (t->type == JSMN_OBJECT || + (t->type == JSMN_STRING && t->size != 0)) { + return JSMN_ERROR_INVAL; + } + } +#else + /* In non-strict mode every unquoted value is a primitive */ + default: +#endif + r = jsmn_parse_primitive(parser, js, len, tokens, num_tokens); + if (r < 0) return r; + count++; + if (parser->toksuper != -1 && tokens != NULL) + tokens[parser->toksuper].size++; + break; + +#ifdef JSMN_STRICT + /* Unexpected char in strict mode */ + default: + return JSMN_ERROR_INVAL; +#endif + } + } + + if (tokens != NULL) { + for (i = parser->toknext - 1; i >= 0; i--) { +//printf("index -%2d, start is %3d, end is %3d\n", i, tokens[i].start, tokens[i].end); + /* Unmatched opened object or array */ + if (tokens[i].start != -1 && tokens[i].end == -1) { + return JSMN_ERROR_PART; + } + } + } + + return count; +} + +/** + * Creates a new parser based over a given buffer with an array of tokens + * available. + */ +void jsmn_init(jsmn_parser *parser) { + parser->pos = 0; + parser->toknext = 0; + parser->toksuper = -1; +} + +int jsoneq(const char *json, jsmntok_t *tok, const char *s) +{ + if (tok->type == JSMN_STRING && (int) strlen(s) == tok->end - tok->start && + strncmp(json + tok->start, s, tok->end - tok->start) == 0) { + return 0; + } + return -1; +} + +void printToken(char * js, jsmntok_t * tokens, int numToken) +{ + for (int i = 1; i < numToken; i++) + { + printf("Token number-%2d, parent-%2d, type-%d size-%2d, parameter -", i, tokens[i].parent, tokens[i].type, tokens[i].size); + if (tokens[i].type == JSMN_STRING || tokens[i].type == JSMN_PRIMITIVE) { + printf("%.*s\n", tokens[i].end - tokens[i].start, js + tokens[i].start); + } else if (tokens[i].type == JSMN_ARRAY) { + printf("[%d elems]\n", tokens[i].size); + } else if (tokens[i].type == JSMN_OBJECT) { + printf("{%d elems}\n", tokens[i].size); + } else { + printf("value?? - "); + TOKEN_PRINT(tokens[i]); + } + } +} + +int getStringToken(char * js, jsmntok_t * tokens, int numToken, char * param, char * pParam, char * value, int maxValueSize) +{ + int i = 0; + int dpToken = 0; + + memset(value, 0, maxValueSize); + + for (i = 1; i < numToken; i++) + { + if(jsoneq(js, &tokens[i], pParam) == 0) + break; + } + if (i < numToken) + { + dpToken = ++i; + } + else + { + printf("The parameter %s is not present in JSON file\n", pParam); + return 1; //Parent token not seen + } + for (i=1; i < numToken; i++) + { + if (tokens[i].parent == dpToken && tokens[i].type == JSMN_STRING && tokens[i].size == 1) + { + if(jsoneq(js, &tokens[i], param) != 0) + continue; + TOKEN_COPY(js, tokens[i+1], value); + + return 0; //Success + } + } + printf("The parameter %s is not present in JSON file\n", param); + return 2; //parameter not found +} + +int getIntToken(char * js, jsmntok_t * tokens, int numToken, char * param, char * pParam, int * value) +{ + int i = 0; + int dpToken = 0; + char val[128]; + + memset(val, 0, 128); + for (i = 1; i < numToken; i++) + { + if(jsoneq(js, &tokens[i], pParam) == 0) + break; + } + if (i < numToken) + { + dpToken = ++i; + } + else + { + printf("The parameter %s is not present in JSON file\n", pParam); + return 1; //Parent token not seen + } + for (i=1; i < numToken; i++) + { + if (tokens[i].parent == dpToken && tokens[i].type == JSMN_STRING && tokens[i].size == 1) + { + if(jsoneq(js, &tokens[i], param) != 0) + { + continue; + } + + if(tokens[i+1].type != JSMN_PRIMITIVE) + return 3; //Wrong parameter type + +// printf("INT parameter / Value - %s", param); + TOKEN_COPY(js, tokens[i+1], val); + *value = atoi(val); +// printf(" - %d\n", *value); + + return 0; //success + } + } + printf("The parameter %s is not present in JSON file\n", param); + return 2; //parameter not found +} + +void parseDirectParameters(char * js, jsmntok_t * tokens, int numToken) +{ + int i = 0; + int dpToken = 0; + char param[128]; + char value[128]; + + for (i = 1; i < numToken; i++) + { + if(jsoneq(js, &tokens[i], "directParameters") == 0) + break; + } + + if (i < numToken) + { + dpToken = ++i; + } + + for (int i = 1; i < numToken; i++) + { + memset(param, 0, 128); + memset(value, 0, 128); + if (tokens[i].parent == dpToken && tokens[i].type == JSMN_STRING && tokens[i].size == 1) + { + TOKEN_COPY(js, tokens[i], param); +// printf("parameter / Value - %s", param); + TOKEN_COPY(js, tokens[i+1], value); +// printf(" - %s\n", value); + } + } +} + +int getArrayTokens(char * js, jsmntok_t * tokens, int numToken, char * param, char * pParam, ARRAYVAL * arrayValue, int * numElements) +{ + int i = 0; + int dpToken = 0; + + for (i = 1; i < numToken; i++) + { + if(jsoneq(js, &tokens[i], pParam) == 0) + break; + } + if (i < numToken) + { + dpToken = ++i; + } + else + { + printf("The parameter %s is not present in JSON file\n", pParam); + return 1; //Parent token not seen + } + for (i=1; i < numToken; i++) + { + if (tokens[i].parent == dpToken && tokens[i].type == JSMN_STRING && tokens[i].size == 1) + { +// printf("value of token %d\n", i); + if(jsoneq(js, &tokens[i], param) != 0) + continue; + + if (tokens[i+1].type == JSMN_ARRAY) + { + *numElements = tokens[i+1].size; +// printf("[%d elems]\n", *numElements); + + for (int k = 0; k < *numElements; k++) + { + TOKEN_COPY(js, tokens[i+2+k], arrayValue[k].arrayString); +// printf(" - %s\n", arrayValue[k].arrayString); + } + return 0; //Success + } + } + } + printf("The parameter %s is not present in JSON file\n", param); + return 2; //parameter not found +} + +int isTokenPresent(char * js, jsmntok_t * tokens, int numToken, char * param, char * pParam) +{ + int i = 0; + int dpToken = 0; + char val[128]; + + memset(val, 0, 128); + for (i = 1; i < numToken; i++) + { + if(jsoneq(js, &tokens[i], pParam) == 0) + break; + } + if (i < numToken) + { + dpToken = ++i; + } + else + { + printf("The parameter %s is not present in JSON file\n", pParam); + return 1; //Parent token not seen + } + for (i=1; i < numToken; i++) + { + if (tokens[i].parent == dpToken && tokens[i].type == JSMN_STRING) + { + if(jsoneq(js, &tokens[i], param) != 0) + { + return 0; //Token present + } + } + } + printf("The parameter %s is not present in JSON file\n", param); + return 2; //Token Not present +} + +int read_keyVal_params(char * js, jsmntok_t * tokens, int numToken, char * param, char * pParam, KEYVALRESULT * keyValueResultList, int * numElements) +{ + int i = 0; + int dpToken = 0; + + for (i = 1; i < numToken; i++) + { + if(jsoneq(js, &tokens[i], pParam) == 0) + break; + } + if (i < numToken) + { + dpToken = ++i; + } + else + { + printf("The parameter %s is not present in JSON file\n", pParam); + return 1; //Parent token not seen + } + for (i=1; i < numToken; i++) + { + if (tokens[i].parent == dpToken && tokens[i].type == JSMN_STRING && tokens[i].size == 1) + { +// printf("value of token %d\n", i); + if(jsoneq(js, &tokens[i], param) != 0) + continue; + + if (tokens[i+1].type == JSMN_OBJECT) + { + *numElements = tokens[i+1].size; +// printf("{%d elems}\n", *numElements); + + for (int k = 0; k < *numElements; k++) + { + TOKEN_COPY(js, tokens[i+2+k*2], keyValueResultList[k].keyStr); +// printf("Key - %s", keyValueResultList[k].keyStr); + TOKEN_COPY(js, tokens[i+3+k*2], keyValueResultList[k].valStr); +// printf("Value - %s\n", keyValueResultList[k].valStr); + } + return 0; //Success + } + } + } + printf("The parameter %s is not present in JSON file\n", param); + return 2; //parameter not found +} diff --git a/vnfs/VES5.0/evel/evel-library/code/VESreporting_HB/jsmn.h b/vnfs/VES5.0/evel/evel-library/code/VESreporting_HB/jsmn.h new file mode 100644 index 00000000..67034943 --- /dev/null +++ b/vnfs/VES5.0/evel/evel-library/code/VESreporting_HB/jsmn.h @@ -0,0 +1,134 @@ +/*************************************************************************//** + * + * Copyright © 2017 AT&T Intellectual Property. All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + ****************************************************************************/ + +#ifndef __JSMN_H_ +#define __JSMN_H_ + +#include <stddef.h> + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * JSON type identifier. Basic types are: + * o Object + * o Array + * o String + * o Other primitive: number, boolean (true/false) or null + */ +typedef enum { + JSMN_UNDEFINED = 0, + JSMN_OBJECT = 1, + JSMN_ARRAY = 2, + JSMN_STRING = 3, + JSMN_PRIMITIVE = 4 +} jsmntype_t; + +enum jsmnerr { + /* Not enough tokens were provided */ + JSMN_ERROR_NOMEM = -1, + /* Invalid character inside JSON string */ + JSMN_ERROR_INVAL = -2, + /* The string is not a full JSON packet, more bytes expected */ + JSMN_ERROR_PART = -3 +}; + +typedef struct arrayValues { + char arrayString[32]; +} ARRAYVAL; + +typedef struct keyValResult { + char keyStr[80]; + char valStr[250]; + char resultStr[80]; +} KEYVALRESULT; + +/** + * JSON token description. + * @param type type (object, array, string etc.) + * @param start start position in JSON data string + * @param end end position in JSON data string + */ +typedef struct { + jsmntype_t type; + int start; + int end; + int size; +//#ifdef JSMN_PARENT_LINKS + int parent; +//#endif +} jsmntok_t; + +/** + * JSON parser. Contains an array of token blocks available. Also stores + * the string being parsed now and current position in that string + */ +typedef struct { + unsigned int pos; /* offset in the JSON string */ + unsigned int toknext; /* next token to allocate */ + int toksuper; /* superior token node, e.g parent object or array */ +} jsmn_parser; + +#define TOKEN_EQ(t, tok_start, tok_end, tok_type) \ + ((t).start == tok_start \ + && (t).end == tok_end \ + && (t).type == (tok_type)) + +#define TOKEN_STRING(js, t, s) \ + (strncmp(js+(t).start, s, (t).end - (t).start) == 0 \ + && strlen(s) == (t).end - (t).start) + +#define TOKEN_COPY(js, t, s) \ + strncpy(s, js+(t).start, (t).end - (t).start) + +#define TOKEN_PRINT(t) \ + printf("start: %d, end: %d, type: %d, size: %d\n", \ + (t).start, (t).end, (t).type, (t).size) + + +/** + * Create JSON parser over an array of tokens + */ +void jsmn_init(jsmn_parser *parser); + +/** + * Run JSON parser. It parses a JSON data string into and array of tokens, each describing + * a single JSON object. + */ +int jsmn_parse(jsmn_parser *parser, const char *js, size_t len, + jsmntok_t *tokens, unsigned int num_tokens); + +int jsoneq(const char *json, jsmntok_t *tok, const char *s); + +void printToken(char * js, jsmntok_t * tokens, int numToken); + +int getStringToken(char * js, jsmntok_t * tokens, int numToken, char * param, char * pParam, char * value, int maxValueSize); + +int getIntToken(char * js, jsmntok_t * tokens, int numToken, char * param, char * pParam, int * value); + +int getArrayTokens(char * js, jsmntok_t * tokens, int numToken, char * param, char * pParam, ARRAYVAL * arrayValue, int * numElements); + +int isTokenPresent(char * js, jsmntok_t * tokens, int numToken, char * param, char * pParam); + +int read_keyVal_params(char * js, jsmntok_t * tokens, int numToken, char * param, char * pParam, KEYVALRESULT * keyValueResultList, int * numElements); + +#ifdef __cplusplus +} +#endif + +#endif /* __JSMN_H_ */ diff --git a/vnfs/VES5.0/evel/evel-library/code/VESreporting_HB/pom.xml b/vnfs/VES5.0/evel/evel-library/code/VESreporting_HB/pom.xml new file mode 100644 index 00000000..f9f42ebb --- /dev/null +++ b/vnfs/VES5.0/evel/evel-library/code/VESreporting_HB/pom.xml @@ -0,0 +1,83 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- + ============LICENSE_START========================================== + =================================================================== + Copyright © 2017 AT&T Intellectual Property. All rights reserved. + =================================================================== + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + ============LICENSE_END============================================ + + ECOMP and OpenECOMP are trademarks + and service marks of AT&T Intellectual Property. +--> +<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> + +<parent> + <groupId>org.onap.demo.vnf</groupId> + <artifactId>demo-aggregator</artifactId> + <version>1.2.0-SNAPSHOT</version> + <relativePath>../../pom.xml</relativePath> + </parent> + + <modelVersion>4.0.0</modelVersion> + <groupId>org.onap.demo.vnf.ves5</groupId> + <artifactId>ves_vfw_reporting</artifactId> + + <build> + <plugins> + + <plugin> + <artifactId>maven-jar-plugin</artifactId> + <version>2.3.2</version> + <executions> + <execution> + <id>default-jar</id> + <phase>never</phase> + </execution> + </executions> + </plugin> + + <plugin> + <artifactId>maven-assembly-plugin</artifactId> + <version>2.5.3</version> + <configuration> + <descriptor>dep.xml</descriptor> + </configuration> + <executions> + <execution> + <id>create-archive</id> + <phase>package</phase> + <goals> + <goal>single</goal> + </goals> + </execution> + </executions> + </plugin> + + <plugin> + <groupId>org.codehaus.mojo</groupId> + <artifactId>exec-maven-plugin</artifactId> + <executions> + <execution> + <phase>none</phase> + </execution> + </executions> + <configuration> + <skip>true</skip> + </configuration> + </plugin> + + </plugins> + </build> + +</project> diff --git a/vnfs/VES5.0/evel/evel-library/code/VESreporting_HB/sample_heartbeat_events.txt b/vnfs/VES5.0/evel/evel-library/code/VESreporting_HB/sample_heartbeat_events.txt new file mode 100644 index 00000000..f318fa7e --- /dev/null +++ b/vnfs/VES5.0/evel/evel-library/code/VESreporting_HB/sample_heartbeat_events.txt @@ -0,0 +1,26 @@ +{ + "event": { + "commonEventHeader": { + "domain": "heartbeat", + "eventId": "heartbeat000000001", + "eventName": "Heartbeat_VNF-AT&T_heartbeat", + "eventType": "platform", + "lastEpochMicrosec": 1548490889528042, + "nfNamingCode": "scfx", + "nfcNamingCode": "ssc", + "priority": "Normal", + "reportingEntityId": "cc305d54-75b4-431b-adb2-eb6b9e541234", + "reportingEntityName": "ibcx0001vm002oam001", + "sequence": 0, + "sourceId": "de305d54-75b4-431b-adb2-eb6b9e546014", + "sourceName": "scfx0001vm002cap001", + "startEpochMicrosec": 1548490879514800, + "version": 3.0 + }, + "heartbeatField": { + "heartbeatFieldsVersion": 1.0, + "heartbeatInterval": 10 + } + } +} + diff --git a/vnfs/VES5.0/evel/evel-library/code/VESreporting_HB/ves_heartbeat_reporter.c b/vnfs/VES5.0/evel/evel-library/code/VESreporting_HB/ves_heartbeat_reporter.c new file mode 100644 index 00000000..70779252 --- /dev/null +++ b/vnfs/VES5.0/evel/evel-library/code/VESreporting_HB/ves_heartbeat_reporter.c @@ -0,0 +1,255 @@ +/*************************************************************************//** + * + * Copyright © 2018 AT&T Intellectual Property. All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + ****************************************************************************/ + +#include <stdio.h> +#include <stdlib.h> +#include <unistd.h> +#include <pthread.h> +#include <string.h> +#include <netdb.h> +#include <sys/time.h> +#include <sys/stat.h> +#include "jsmn.h" +#include "evel.h" + +#define BUFSIZE 128 +#define MAX_BUFFER_SIZE 4096 +#define MAX_TOKENS 1000 + +void *HeartbeatThread(void *threadarg); + +unsigned long long epoch_start = 0; + +int main(int argc, char** argv) +{ + char* fqdn = argv[1]; + int port = atoi(argv[2]); + int i=0; + int rc; + pthread_attr_t attr; + pthread_t hb_thread; + char* fqdn2 = NULL; + int port2 = 0; + + if(argc == 5) + { + fqdn2 = argv[3]; + port2 = atoi(argv[4]); + } + + if (!((argc == 3) || (argc == 5))) + { + fprintf(stderr, "Usage: %s <FQDN>|<IP address> <port> <FQDN>|<IP address> <port> \n", argv[0]); + fprintf(stderr, "OR\n"); + fprintf(stderr, "Usage: %s <FQDN>|<IP address> <port> \n", argv[0]); + exit(-1); + } + + /**************************************************************************/ + /* Initialize */ + /**************************************************************************/ + if(evel_initialize(fqdn, /* FQDN */ + port, /* Port */ + fqdn2, /* Backup FQDN */ + port2, /* Backup port */ + NULL, /* optional path */ + NULL, /* optional topic */ + 100, /* Ring Buffer size */ + 0, /* HTTPS? */ + NULL, /* cert file */ + NULL, /* key file */ + NULL, /* ca info */ + NULL, /* ca file */ + 0, /* verify peer */ + 0, /* verify host */ + "sample1", /* Username */ + "sample1", /* Password */ + "sample1", /* Username2 */ + "sample1", /* Password2 */ + NULL, /* Source ip */ + NULL, /* Source ip2 */ + EVEL_SOURCE_VIRTUAL_MACHINE, /* Source type */ + "vHeartbeat", /* Role */ + 1)) /* Verbosity */ + { + fprintf(stderr, "\nFailed to initialize the EVEL library!!!\n"); + exit(-1); + } + else + { + printf("\nInitialization completed\n"); + } + + /* Initialize and set thread detached attribute */ + pthread_attr_init(&attr); + pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED); + + printf("Main:Creating thread \n"); + rc = pthread_create(&hb_thread, NULL, HeartbeatThread, &i); + if (rc) + { + printf("ERROR; return code from pthread_create() is %d\n", rc); + exit(-1); + } + printf("Main:Created HB thread \n"); + + pthread_join(hb_thread, NULL); + + evel_terminate(); + printf("Terminated\n"); + return 0; +} + +void *HeartbeatThread(void *threadarg) +{ + + EVENT_HEARTBEAT_FIELD * event = NULL; + EVENT_HEADER* hb_header = NULL; + EVEL_ERR_CODES evel_rc = EVEL_SUCCESS; + + int numToken; + jsmntok_t tokens[MAX_TOKENS]; + char js[MAX_BUFFER_SIZE]; + + jsmn_parser p; + char ch[BUFSIZE]; + int ret = 0; + char stringVal[BUFSIZE]; + char eName[BUFSIZE]; + int hb_interval; + + char event_id1[10] = "heartbeat"; + char event_id2[15] = {0}; + int event_id3 = 0; + char event_id[BUFSIZE] = {0}; + + sleep(1); + printf("Running HB thread \n"); + fflush(stdout); + + while(1) + { + + FILE * file = fopen("hb_config.json", "r"); + + memset(js, 0, MAX_BUFFER_SIZE); + memset(ch, 0, BUFSIZE); + + while((fgets(ch, (BUFSIZE-1), file)) !=NULL) + { + strcat(js, ch); + memset(ch, 0, BUFSIZE); + } +// printf("the file content is \n %s \n", js); + + jsmn_init(&p); + numToken = jsmn_parse(&p, js, strlen(js), tokens, MAX_TOKENS); + printf("Token count-%d\n", numToken); + +// printToken(js,tokens, numToken); + + ret = getStringToken(js, tokens, numToken, "eventName", "tmp_directParameters", eName, BUFSIZE); + if (ret != 0) + { + printf("Missing mandatory parameters - eventName is not there in tmp_directParameters. Exiting...\n"); + exit(1); + } + + ret = getIntToken(js, tokens, numToken, "heartbeatInterval", "tmp_directParameters", &hb_interval); + if (ret != 0) + { + printf("The parameter heartbeatInterval is not defined, defaulted to 60 seconds\n"); + hb_interval = 60; + } + + /***************************************************************************/ + /* Heartbeat */ + /***************************************************************************/ + memset(event_id, 0, BUFSIZE); + memset(event_id2, 0, 15); + sprintf(event_id2, "%09d", event_id3++); + strcat(event_id, event_id1); + strcat(event_id, event_id2); + + event = evel_new_heartbeat_field(hb_interval, eName, event_id); + if (event != NULL) + { + hb_header = (EVENT_HEADER *)event; + + ret = getStringToken(js, tokens, numToken, "eventType", "tmp_directParameters", stringVal, BUFSIZE); + if (ret == 0) + { + evel_header_type_set(&event->header, stringVal); + } + + struct timeval tv_now; + gettimeofday(&tv_now, NULL); + unsigned long long epoch_now = tv_now.tv_usec + 1000000 * tv_now.tv_sec; + + evel_start_epoch_set(&event->header, epoch_start); + evel_last_epoch_set(&event->header, epoch_now); + epoch_start = epoch_now; + + ret = getStringToken(js, tokens, numToken, "nfcNamingCode", "tmp_directParameters", stringVal, BUFSIZE); + if (ret == 0) + evel_nfcnamingcode_set(&event->header, stringVal); + + ret = getStringToken(js, tokens, numToken, "nfNamingCode", "tmp_directParameters", stringVal, BUFSIZE); + if (ret == 0) + evel_nfnamingcode_set(&event->header, stringVal); + + ret = getStringToken(js, tokens, numToken, "reportingEntityName", "tmp_directParameters", stringVal, BUFSIZE); + if (ret == 0) + evel_reporting_entity_name_set(&event->header, stringVal); + else + { + printf("Missing mandatory parameters - reportingEntityName is not there in tmp_directParameters\n"); + printf("Defaulting reportingEntityName to hostname\n"); + } + + ret = getStringToken(js, tokens, numToken, "reportingEntityId", "tmp_directParameters", stringVal, BUFSIZE); + if (ret == 0) + evel_reporting_entity_id_set(&event->header, stringVal); + + ret = getStringToken(js, tokens, numToken, "sourceId", "tmp_directParameters", stringVal, BUFSIZE); + if (ret == 0) + evel_source_id_set(&event->header, stringVal); + + ret = getStringToken(js, tokens, numToken, "sourceName", "tmp_directParameters", stringVal, BUFSIZE); + if (ret == 0) + evel_source_name_set(&event->header, stringVal); + else + { + printf("Missing mandatory parameters - sourceName is not there in tmp_directParameters\n"); + printf("Defaulting sourceName to hostname\n"); + } + + evel_rc = evel_post_event(hb_header); + if (evel_rc != EVEL_SUCCESS) + { + EVEL_ERROR("Post failed %d (%s)", evel_rc, evel_error_string()); + } + } + else + { + EVEL_ERROR("New Heartbeat failed"); + } + printf(" Processed Heartbeat\n"); + + sleep(hb_interval); + } +} diff --git a/vnfs/VES5.0/evel/evel-library/code/VESreporting_fault/LICENSE.TXT b/vnfs/VES5.0/evel/evel-library/code/VESreporting_fault/LICENSE.TXT new file mode 100644 index 00000000..16285cd2 --- /dev/null +++ b/vnfs/VES5.0/evel/evel-library/code/VESreporting_fault/LICENSE.TXT @@ -0,0 +1,22 @@ +/* + * ============LICENSE_START========================================== + * =================================================================== + * Copyright © 2017 AT&T Intellectual Property. All rights reserved. + * =================================================================== + * Unless otherwise specified, all software contained herein is + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END============================================ + * + * ECOMP is trademark and service mark of AT&T Intellectual Property. + * + */ diff --git a/vnfs/VES5.0/evel/evel-library/code/VESreporting_fault/Makefile b/vnfs/VES5.0/evel/evel-library/code/VESreporting_fault/Makefile new file mode 100644 index 00000000..4837c7d1 --- /dev/null +++ b/vnfs/VES5.0/evel/evel-library/code/VESreporting_fault/Makefile @@ -0,0 +1,52 @@ +############################################################################# +# +# Copyright © 2019 AT&T Intellectual Property. All rights reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +############################################################################# + +CC=gcc +ARCH=$(shell getconf LONG_BIT) +CODE_ROOT=$(CURDIR)/../.. +#CODE_ROOT=../code/evel-library +LIBS_DIR=$(CODE_ROOT)/libs/x86_$(ARCH) +#LIBS_DIR=/usr/lib +INCLUDE_DIR= -I $(CODE_ROOT)/code/evel_library -I . + +#****************************************************************************** +# Standard compiler flags. * +#****************************************************************************** +CPPFLAGS= +CFLAGS=-Wall -g -fPIC +FILEOBJLIST= jsmn.o ves_fault_reporter.o + +all: ves_fault_reporter + +clean: + rm -f *.o ves_fault_reporter + +%.o: %.c + $(CC) $(CPPFLAGS) $(CFLAGS) $(INCLUDE_DIR) -c $< -o $@ + +jsmn.o: jsmn.c jsmn.h +ves_fault_reporter.o: ves_fault_reporter.c + +ves_fault_reporter: $(FILEOBJLIST) + $(CC) $(CPPFLAGS) $(CFLAGS) -o ves_fault_reporter \ + -L $(LIBS_DIR) \ + $(FILEOBJLIST) \ + -lpthread \ + -level \ + -lcurl + + diff --git a/vnfs/VES5.0/evel/evel-library/code/VESreporting_fault/README.md b/vnfs/VES5.0/evel/evel-library/code/VESreporting_fault/README.md new file mode 100644 index 00000000..5a7ea414 --- /dev/null +++ b/vnfs/VES5.0/evel/evel-library/code/VESreporting_fault/README.md @@ -0,0 +1,37 @@ + +PROJECT DESCRIPTION + +--- +This project contains the source code and scripts for the generation of fault events. The folder contains: + + - README.md: this file. + + - LICENSE.TXT: the license text. + + - ves_fault_reporter.c and other .c files: source code that uses the ECOMP Vendor Event Listener Library (VES) to generate the fault events. Fault is generated based on the link status. If number of bytes transmitted/received is less than the low water mark, the fault is generated. The application reads flt_config.json file for parameter values and poppulate the fault event. If eventName, eventSourceType, vfStatus, specificProblem or alarmCondition parameter value is not given, the application terminates. If reportingEntityName and sourceName parameter values are not given, then it gets the hostname and poppulates it. If tmp_faultCheckInterval is not given, it defaults to 60 seconds. + + - Makefile: makefile that compiles ves_fault_reporter.c and generates ves_fault_reporter binary. + + - go-client.sh/go-client_2_collectors.sh: bash script that starts up the ves_fault_reporter. It reads input parameters like DCAE IP address and port from configuration files contained in /opt/config. Based on the collector configuration, use go-client.sh for single collector configuration, or use go-client_2_collectors.sh for 2 collectors configuration. + + +USAGE +----- + +Update the configuration files with proper parameters values so that events generated would contain those values + +To run the ves_fault_reporter in single collector configuration, please execute the following steps: + + - Make the go-client.sh script executable + chmod +x go-client.sh + + - Run the go-client.sh script + ./go-client.sh + +For 2 collectors configuration, please execute following steps: + + - Make the go-client.sh script executable + chmod +x go-client_2_collectors.sh + + - Run the go-client_2_collectors.sh script + ./go-client_2_collectors.sh diff --git a/vnfs/VES5.0/evel/evel-library/code/VESreporting_fault/dep.xml b/vnfs/VES5.0/evel/evel-library/code/VESreporting_fault/dep.xml new file mode 100644 index 00000000..fc18229f --- /dev/null +++ b/vnfs/VES5.0/evel/evel-library/code/VESreporting_fault/dep.xml @@ -0,0 +1,25 @@ +<assembly xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.2" + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.2 http://maven.apache.org/xsd/assembly-1.1.2.xsd"> + <id>demo</id> + <formats> + <format>tar.gz</format> + </formats> + <fileSets> + + <fileSet> + <directory>.</directory> + <outputDirectory>/</outputDirectory> + <includes> + <include>*.sh</include> + <include>*.md</include> + <include>*.TXT</include> + <include>*.c</include> + <include>Makefile</include> + </includes> + </fileSet> + + </fileSets> +</assembly> + + diff --git a/vnfs/VES5.0/evel/evel-library/code/VESreporting_fault/flt_config.json b/vnfs/VES5.0/evel/evel-library/code/VESreporting_fault/flt_config.json new file mode 100644 index 00000000..90654ef5 --- /dev/null +++ b/vnfs/VES5.0/evel/evel-library/code/VESreporting_fault/flt_config.json @@ -0,0 +1,71 @@ +{ + "tmp_directParameters": { + "eventType": "applicationVnf", + "nfcNamingCode": "AFX", + "nfNamingCode": "AFX", + "priority": "Low", + "reportingEntityId": "cc305d54-75b4-431b-adb2-eb6b9e541234", + "reportingEntityName": "ibcx0001vm002oam001", + "sourceId": "de305d54-75b4-431b-adb2-eb6b9e546014", + "sourceName": "scfx0001vm002cap001", + "vfStatus": "Idle", + "tmp_device": ["lo", "enp0s3", "docker0"] + + }, + "tmp_indirectParameters": [ + "tmp_faultInstance01": { + "eventName": "Fault_vFirewall-AT&T_linkDownError", + "eventCategory": "link", + "eventSourceType": "router", + "tmp_init":{ + "tmp_t0BytesIn": "sudo cat /proc/net/dev | grep $tmp_device | tr -s ' ' | cut -d ':' -f2 | cut -d ' ' -f2", + "tmp_t0BytesOut": "sudo cat /proc/net/dev | grep $tmp_device | tr -s ' ' | cut -d ':' -f2 | cut -d ' ' -f10", + "tmp_t0PacketsIn": "sudo cat /proc/net/dev | grep $tmp_device | tr -s ' ' | cut -d ':' -f2 | cut -d ' ' -f3", + "tmp_t0PacketsOut": "sudo cat /proc/net/dev | grep $tmp_device | tr -s ' ' | cut -d ':' -f2 | cut -d ' ' -f11" + }, + "alarmInterfaceA": "$tmp_device", + "tmp_faultCheckInterval": 20, + "tmp_lowWaterMark": 100, + "tmp_command": { + "tmp_t1BytesIn": "sudo cat /proc/net/dev | grep $tmp_device | tr -s ' ' | cut -d ':' -f2 | cut -d ' ' -f2", + "tmp_t1BytesOut": "sudo cat /proc/net/dev | grep $tmp_device | tr -s ' ' | cut -d ':' -f2 | cut -d ' ' -f10", + "tmp_t1PacketsIn": "sudo cat /proc/net/dev | grep $tmp_device | tr -s ' ' | cut -d ':' -f2 | cut -d ' ' -f3", + "tmp_t1PacketsOut": "sudo cat /proc/net/dev | grep $tmp_device | tr -s ' ' | cut -d ':' -f2 | cut -d ' ' -f11" + }, + "tmp_BytesIn": "$(tmp_t1BytesIn - tmp_t0BytesIn)", + "tmp_PacketsIn": "$(tmp_t1PacketsIn - tmp_t0PacketsIn)", + "tmp_BytesOut": "$(tmp_t1BytesOut - tmp_t0BytesOut)", + "tmp_PacketsOut": "$(tmp_t1PacketsOut - tmp_t0PacketsOut)", + "tmp_alarmSetParameters": { + "specificProblem": "physical or logical connection to a remote router is down", + "eventSeverity": "MAJOR", + "alarmCondition": "link down trap_alarm" + }, + "tmp_alarmClearParameters": { + "specificProblem": "physical or logical connection to a remote router is up", + "eventSeverity": "NORMAL", + "alarmCondition": "link up trap_alarm" + } + }, + "tmp_faultInstance02": { + "eventName": "Fault_vFirewall-AT&T_serviceDownError", + "alarmInterfaceA": "afx@input.service", + "eventCategory": "other", + "eventSourceType": "virtualMachine", + "tmp_faultCheckInterval": 10, + "tmp_command": { + "tmp_cmd1": "/bin/systemctl is-active afx@input* |grep -E 'inactive|failed' | wc -l" + }, + "tmp_alarmSetParameters": { + "specificProblem": "service is down", + "eventSeverity": "MAJOR", + "alarmCondition": "service down trap_alarm" + }, + "tmp_alarmClearParameters": { + "specificProblem": "service is up", + "eventSeverity": "NORMAL", + "alarmCondition": "service up trap_alarm" + } + } + ] +} diff --git a/vnfs/VES5.0/evel/evel-library/code/VESreporting_fault/go-client.sh b/vnfs/VES5.0/evel/evel-library/code/VESreporting_fault/go-client.sh new file mode 100755 index 00000000..5a598821 --- /dev/null +++ b/vnfs/VES5.0/evel/evel-library/code/VESreporting_fault/go-client.sh @@ -0,0 +1,6 @@ +#!/bin/bash + +export LD_LIBRARY_PATH="/opt/VES/evel/evel-library/libs/x86_64/" +DCAE_COLLECTOR_IP=$(cat /opt/config/dcae_collector_ip.txt) +DCAE_COLLECTOR_PORT=$(cat /opt/config/dcae_collector_port.txt) +./ves_fault_reporter $DCAE_COLLECTOR_IP $DCAE_COLLECTOR_PORT diff --git a/vnfs/VES5.0/evel/evel-library/code/VESreporting_fault/go-client_2_collectors.sh b/vnfs/VES5.0/evel/evel-library/code/VESreporting_fault/go-client_2_collectors.sh new file mode 100755 index 00000000..09d65f03 --- /dev/null +++ b/vnfs/VES5.0/evel/evel-library/code/VESreporting_fault/go-client_2_collectors.sh @@ -0,0 +1,12 @@ +#!/bin/bash + +export LD_LIBRARY_PATH="/opt/VES/evel/evel-library/libs/x86_64/" + +#Usage for 2 collectors: +#./ves_fault_reporter <FQDN>|<IP address> <port> <FQDN>|<IP address> <port> + +DCAE_COLLECTOR_IP=$(cat /opt/config/dcae_collector_ip.txt) +DCAE_COLLECTOR_PORT=$(cat /opt/config/dcae_collector_port.txt) +DCAE_COLLECTOR_IP2=$(cat /opt/config/dcae_collector_ip2.txt) +DCAE_COLLECTOR_PORT2=$(cat /opt/config/dcae_collector_port2.txt) +./ves_fault_reporter $DCAE_COLLECTOR_IP $DCAE_COLLECTOR_PORT $DCAE_COLLECTOR_IP2 $DCAE_COLLECTOR_PORT2 diff --git a/vnfs/VES5.0/evel/evel-library/code/VESreporting_fault/jsmn.c b/vnfs/VES5.0/evel/evel-library/code/VESreporting_fault/jsmn.c new file mode 100644 index 00000000..1d72ba4d --- /dev/null +++ b/vnfs/VES5.0/evel/evel-library/code/VESreporting_fault/jsmn.c @@ -0,0 +1,672 @@ +/*************************************************************************//** + * + * Copyright © 2017 AT&T Intellectual Property. All rights reserved. + * + * Unless otherwise specified, all software contained herein is + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ECOMP is a trademark and service mark of AT&T Intellectual Property. + ****************************************************************************/ +#include<stdio.h> +#include<stdlib.h> +#include<string.h> +#include "jsmn.h" + +/** + * Allocates a fresh unused token from the token pull. + */ +static jsmntok_t *jsmn_alloc_token(jsmn_parser *parser, + jsmntok_t *tokens, size_t num_tokens) { + jsmntok_t *tok; + if (parser->toknext >= num_tokens) { + return NULL; + } + tok = &tokens[parser->toknext++]; + tok->start = tok->end = -1; + tok->size = 0; +//#ifdef JSMN_PARENT_LINKS + tok->parent = -1; +//#endif + return tok; +} + +/** + * Fills token type and boundaries. + */ +static void jsmn_fill_token(jsmntok_t *token, jsmntype_t type, + int start, int end) { +//printf("jsmn_fill_token:: start-%d, end-%d\n", start, end); + token->type = type; + token->start = start; + token->end = end; + token->size = 0; +} + +/** + * Fills next available token with JSON primitive. + */ +static int jsmn_parse_primitive(jsmn_parser *parser, const char *js, + size_t len, jsmntok_t *tokens, size_t num_tokens) { + jsmntok_t *token; + int start; + + start = parser->pos; + + for (; parser->pos < len && js[parser->pos] != '\0'; parser->pos++) { +//printf("jsmn_parse_primitive:: the char is - %c\n", js[parser->pos]); + switch (js[parser->pos]) { +#ifndef JSMN_STRICT + /* In strict mode primitive must be followed by "," or "}" or "]" */ + case ':': +#endif + case '\t' : case '\r' : case '\n' : case ' ' : + case ',' : case ']' : case '}' : + goto found; + } + if (js[parser->pos] < 32 || js[parser->pos] >= 127) { + parser->pos = start; + return JSMN_ERROR_INVAL; + } + } +#ifdef JSMN_STRICT + /* In strict mode primitive must be followed by a comma/object/array */ + parser->pos = start; + return JSMN_ERROR_PART; +#endif + +found: + if (tokens == NULL) { + parser->pos--; + return 0; + } + token = jsmn_alloc_token(parser, tokens, num_tokens); + if (token == NULL) { + parser->pos = start; + return JSMN_ERROR_NOMEM; + } + jsmn_fill_token(token, JSMN_PRIMITIVE, start, parser->pos); +//#ifdef JSMN_PARENT_LINKS + token->parent = parser->toksuper; +//#endif + parser->pos--; + return 0; +} + +/** + * Fills next token with JSON string. + */ +static int jsmn_parse_string(jsmn_parser *parser, const char *js, + size_t len, jsmntok_t *tokens, size_t num_tokens) { + jsmntok_t *token; + + int start = parser->pos; + + parser->pos++; + + /* Skip starting quote */ + for (; parser->pos < len && js[parser->pos] != '\0'; parser->pos++) { + char c = js[parser->pos]; + char d = js[parser->pos + 1]; +// char e = js[parser->pos + 2]; +//printf("jsmn_parse_string: value-%c, pos-%d\n", c,parser->pos); + + /* Quote: end of string */ +// if (c == '\"') { + if (d == '\"') { +// if ((d == '\"')&&((e == ' ')||(e == ','))) { +parser->pos++; +//printf("jsmn_parse_string: end of string\n"); + if (tokens == NULL) { +//printf("jsmn_parse_string: end tokens is NULL\n"); + return 0; + } + token = jsmn_alloc_token(parser, tokens, num_tokens); +//printf("jsmn_parse_string: Allocated tokens \n"); + if (token == NULL) { +//printf("jsmn_parse_string: Allocated tokens is NULL\n"); + parser->pos = start; + return JSMN_ERROR_NOMEM; + } + jsmn_fill_token(token, JSMN_STRING, start+1, parser->pos); +//printf("jsmn_parse_string: Allocated tokens is filled\n"); +//#ifdef JSMN_PARENT_LINKS + token->parent = parser->toksuper; +//#endif + return 0; + } + + /* Backslash: Quoted symbol expected */ + if (c == '\\' && parser->pos + 1 < len) { + int i; + parser->pos++; +//printf("jsmn_parse_string: value - %c, POS-%3d \n",c, js[parser->pos]); + switch (js[parser->pos]) { + /* Allowed escaped symbols */ + case '\"': case '/' : case '\\' : case 'b' : + case 'f' : case 'r' : case 'n' : case 't' : + break; + /* Allows escaped symbol \uXXXX */ + case 'u': + parser->pos++; + for(i = 0; i < 4 && parser->pos < len && js[parser->pos] != '\0'; i++) { + /* If it isn't a hex character we have an error */ + if(!((js[parser->pos] >= 48 && js[parser->pos] <= 57) || /* 0-9 */ + (js[parser->pos] >= 65 && js[parser->pos] <= 70) || /* A-F */ + (js[parser->pos] >= 97 && js[parser->pos] <= 102))) { /* a-f */ + parser->pos = start; + return JSMN_ERROR_INVAL; + } + parser->pos++; + } + parser->pos--; + break; + /* Unexpected symbol */ + default: + parser->pos = start; + return JSMN_ERROR_INVAL; + } + } + } + parser->pos = start; +printf("jsmn_parse_string: exiting with ERROR_PART, pos-%d", parser->pos); + return JSMN_ERROR_PART; +} + +/** + * Parse JSON string and fill tokens. + */ +int jsmn_parse(jsmn_parser *parser, const char *js, size_t len, + jsmntok_t *tokens, unsigned int num_tokens) { + int r; + int i; + jsmntok_t *token; + int count = parser->toknext; + + for (; parser->pos < len && js[parser->pos] != '\0'; parser->pos++) { + char c; + jsmntype_t type; + + c = js[parser->pos]; +//printf("jsmn_parse: value of c - %c\n",c); + switch (c) { + case '{': case '[': + count++; + if (tokens == NULL) { + break; + } + token = jsmn_alloc_token(parser, tokens, num_tokens); + if (token == NULL) + return JSMN_ERROR_NOMEM; + if (parser->toksuper != -1) { + tokens[parser->toksuper].size++; +//#ifdef JSMN_PARENT_LINKS + token->parent = parser->toksuper; +//#endif + } + token->type = (c == '{' ? JSMN_OBJECT : JSMN_ARRAY); + token->start = parser->pos; + parser->toksuper = parser->toknext - 1; + break; + case '}': case ']': + if (tokens == NULL) + break; + type = (c == '}' ? JSMN_OBJECT : JSMN_ARRAY); +//#ifdef JSMN_PARENT_LINKS + if (parser->toknext < 1) { + return JSMN_ERROR_INVAL; + } + token = &tokens[parser->toknext - 1]; + for (;;) { + if (token->start != -1 && token->end == -1) { + if (token->type != type) { + return JSMN_ERROR_INVAL; + } + token->end = parser->pos + 1; + parser->toksuper = token->parent; + break; + } + if (token->parent == -1) { + break; + } + token = &tokens[token->parent]; + } +//#else +// for (i = parser->toknext - 1; i >= 0; i--) { +// token = &tokens[i]; +// if (token->start != -1 && token->end == -1) { +// if (token->type != type) { +// return JSMN_ERROR_INVAL; +// } +// parser->toksuper = -1; +// token->end = parser->pos + 1; +// break; +// } +// } +// /* Error if unmatched closing bracket */ +// if (i == -1) return JSMN_ERROR_INVAL; +// for (; i >= 0; i--) { +// token = &tokens[i]; +// if (token->start != -1 && token->end == -1) { +// parser->toksuper = i; +// break; +// } +// } +//#endif + break; + case '\"': + r = jsmn_parse_string(parser, js, len, tokens, num_tokens); + if (r < 0) return r; + count++; + if (parser->toksuper != -1 && tokens != NULL) + tokens[parser->toksuper].size++; + break; + case '\t' : case '\r' : case '\n' : case ' ': + break; + case ':': + parser->toksuper = parser->toknext - 1; +//printf("jsmn_parse: value of c is :: - %c\n",c); + break; + case ',': + if (tokens != NULL && parser->toksuper != -1 && + tokens[parser->toksuper].type != JSMN_ARRAY && + tokens[parser->toksuper].type != JSMN_OBJECT) { +//#ifdef JSMN_PARENT_LINKS + parser->toksuper = tokens[parser->toksuper].parent; +//#else +// for (i = parser->toknext - 1; i >= 0; i--) { +// if (tokens[i].type == JSMN_ARRAY || tokens[i].type == JSMN_OBJECT) { +// if (tokens[i].start != -1 && tokens[i].end == -1) { +// parser->toksuper = i; +// break; +// } +// } +// } +//#endif + } + break; +#ifdef JSMN_STRICT + /* In strict mode primitives are: numbers and booleans */ + case '-': case '0': case '1' : case '2': case '3' : case '4': + case '5': case '6': case '7' : case '8': case '9': + case 't': case 'f': case 'n' : + /* And they must not be keys of the object */ + if (tokens != NULL && parser->toksuper != -1) { + jsmntok_t *t = &tokens[parser->toksuper]; + if (t->type == JSMN_OBJECT || + (t->type == JSMN_STRING && t->size != 0)) { + return JSMN_ERROR_INVAL; + } + } +#else + /* In non-strict mode every unquoted value is a primitive */ + default: +#endif + r = jsmn_parse_primitive(parser, js, len, tokens, num_tokens); + if (r < 0) return r; + count++; + if (parser->toksuper != -1 && tokens != NULL) + tokens[parser->toksuper].size++; + break; + +#ifdef JSMN_STRICT + /* Unexpected char in strict mode */ + default: + return JSMN_ERROR_INVAL; +#endif + } + } + + if (tokens != NULL) { + for (i = parser->toknext - 1; i >= 0; i--) { +//printf("index -%2d, start is %3d, end is %3d\n", i, tokens[i].start, tokens[i].end); + /* Unmatched opened object or array */ + if (tokens[i].start != -1 && tokens[i].end == -1) { + return JSMN_ERROR_PART; + } + } + } + + return count; +} + +/** + * Creates a new parser based over a given buffer with an array of tokens + * available. + */ +void jsmn_init(jsmn_parser *parser) { + parser->pos = 0; + parser->toknext = 0; + parser->toksuper = -1; +} + +int jsoneq(const char *json, jsmntok_t *tok, const char *s) +{ + if (tok->type == JSMN_STRING && (int) strlen(s) == tok->end - tok->start && + strncmp(json + tok->start, s, tok->end - tok->start) == 0) { + return 0; + } + return -1; +} + +void printToken(char * js, jsmntok_t * tokens, int numToken) +{ + for (int i = 1; i < numToken; i++) + { + printf("Token number-%2d, parent-%2d, type-%d size-%2d, parameter -", i, tokens[i].parent, tokens[i].type, tokens[i].size); + if (tokens[i].type == JSMN_STRING || tokens[i].type == JSMN_PRIMITIVE) { + printf("%.*s\n", tokens[i].end - tokens[i].start, js + tokens[i].start); + } else if (tokens[i].type == JSMN_ARRAY) { + printf("[%d elems]\n", tokens[i].size); + } else if (tokens[i].type == JSMN_OBJECT) { + printf("{%d elems}\n", tokens[i].size); + } else { + printf("value?? - "); + TOKEN_PRINT(tokens[i]); + } + } +} + +int getStringToken(char * js, jsmntok_t * tokens, int numToken, char * param, char * pParam, char * value, int maxValueSize) +{ + int i = 0; + int dpToken = 0; + + memset(value, 0, maxValueSize); + + for (i = 1; i < numToken; i++) + { + if(jsoneq(js, &tokens[i], pParam) == 0) + break; + } + if (i < numToken) + { + dpToken = ++i; + } + else + { + printf("The parameter %s is not present in JSON file\n", pParam); + return 1; //Parent token not seen + } + for (i=1; i < numToken; i++) + { + if (tokens[i].parent == dpToken && tokens[i].type == JSMN_STRING && tokens[i].size == 1) + { + if(jsoneq(js, &tokens[i], param) != 0) + continue; + TOKEN_COPY(js, tokens[i+1], value); + + return 0; //Success + } + } + printf("The parameter %s is not present in JSON file\n", param); + return 2; //parameter not found +} + + +int getStringTokenV2(char * js, jsmntok_t * tokens, int numToken, char * param, char * pParam, char * gParam,char * value, int maxValueSize) +{ + int i = 0; + int dpToken = 0; + + memset(value, 0, maxValueSize); + + for (i = 1; i < numToken; i++) + { + if(jsoneq(js, &tokens[i], gParam) == 0) + break; + } + if (i < numToken) + { + dpToken = ++i; + } + else + { + printf("The parameter %s is not present in JSON file\n", pParam); + return 1; //Grand Parent token not seen + } + + for (i=dpToken; i < numToken; i++) + { + if (tokens[i].parent == dpToken && tokens[i].type == JSMN_STRING && tokens[i].size == 1) + { + if(jsoneq(js, &tokens[i], pParam) == 0) + break; + } + } + if (i < numToken) + { + dpToken = ++i; + } + else + { + printf("The parameter %s is not present in JSON file\n", pParam); + return 2; //Parent token not seen + } + + for (i=dpToken; i < numToken; i++) + { + if (tokens[i].parent == dpToken && tokens[i].type == JSMN_STRING && tokens[i].size == 1) + { + if(jsoneq(js, &tokens[i], param) != 0) + continue; + TOKEN_COPY(js, tokens[i+1], value); + + return 0; //Success + } + } + + printf("The parameter %s is not present in JSON file\n", param); + return 2; //parameter not found +} + +int getIntToken(char * js, jsmntok_t * tokens, int numToken, char * param, char * pParam, int * value) +{ + int i = 0; + int dpToken = 0; + char val[128]; + + memset(val, 0, 128); + for (i = 1; i < numToken; i++) + { + if(jsoneq(js, &tokens[i], pParam) == 0) + break; + } + if (i < numToken) + { + dpToken = ++i; + } + else + { + printf("The parameter %s is not present in JSON file\n", pParam); + return 1; //Parent token not seen + } + for (i=1; i < numToken; i++) + { + if (tokens[i].parent == dpToken && tokens[i].type == JSMN_STRING && tokens[i].size == 1) + { + if(jsoneq(js, &tokens[i], param) != 0) + { + continue; + } + + if(tokens[i+1].type != JSMN_PRIMITIVE) + return 3; //Wrong parameter type + +// printf("INT parameter / Value - %s", param); + TOKEN_COPY(js, tokens[i+1], val); + *value = atoi(val); +// printf(" - %d\n", *value); + + return 0; //success + } + } + printf("The parameter %s is not present in JSON file\n", param); + return 2; //parameter not found +} + +void parseDirectParameters(char * js, jsmntok_t * tokens, int numToken) +{ + int i = 0; + int dpToken = 0; + char param[128]; + char value[128]; + + for (i = 1; i < numToken; i++) + { + if(jsoneq(js, &tokens[i], "directParameters") == 0) + break; + } + + if (i < numToken) + { + dpToken = ++i; + } + + for (int i = 1; i < numToken; i++) + { + memset(param, 0, 128); + memset(value, 0, 128); + if (tokens[i].parent == dpToken && tokens[i].type == JSMN_STRING && tokens[i].size == 1) + { + TOKEN_COPY(js, tokens[i], param); +// printf("parameter / Value - %s", param); + TOKEN_COPY(js, tokens[i+1], value); +// printf(" - %s\n", value); + } + } +} + +int getArrayTokens(char * js, jsmntok_t * tokens, int numToken, char * param, char * pParam, ARRAYVAL * arrayValue, int * numElements) +{ + int i = 0; + int dpToken = 0; + + for (i = 1; i < numToken; i++) + { + if(jsoneq(js, &tokens[i], pParam) == 0) + break; + } + if (i < numToken) + { + dpToken = ++i; + } + else + { + printf("The parameter %s is not present in JSON file\n", pParam); + return 1; //Parent token not seen + } + for (i=1; i < numToken; i++) + { + if (tokens[i].parent == dpToken && tokens[i].type == JSMN_STRING && tokens[i].size == 1) + { +// printf("value of token %d\n", i); + if(jsoneq(js, &tokens[i], param) != 0) + continue; + + if (tokens[i+1].type == JSMN_ARRAY) + { + *numElements = tokens[i+1].size; +// printf("[%d elems]\n", *numElements); + + for (int k = 0; k < *numElements; k++) + { + TOKEN_COPY(js, tokens[i+2+k], arrayValue[k].arrayString); +// printf(" - %s\n", arrayValue[k].arrayString); + } + return 0; //Success + } + } + } + printf("The parameter %s is not present in JSON file\n", param); + return 2; //parameter not found +} + +int isTokenPresent(char * js, jsmntok_t * tokens, int numToken, char * param, char * pParam) +{ + int i = 0; + int dpToken = 0; + char val[128]; + + memset(val, 0, 128); + for (i = 1; i < numToken; i++) + { + if(jsoneq(js, &tokens[i], pParam) == 0) + break; + } + if (i < numToken) + { + dpToken = ++i; + } + else + { + printf("The parameter %s is not present in JSON file\n", pParam); + return 1; //Parent token not seen + } + for (i=1; i < numToken; i++) + { + if (tokens[i].parent == dpToken && tokens[i].type == JSMN_STRING) + { + if(jsoneq(js, &tokens[i], param) == 0) + { + return 0; //Token present + } + } + } + printf("The parameter %s is not present in JSON file\n", param); + return 2; //Token Not present +} + +int read_keyVal_params(char * js, jsmntok_t * tokens, int numToken, char * param, char * pParam, KEYVALRESULT * keyValueResultList, int * numElements) +{ + int i = 0; + int dpToken = 0; + + for (i = 1; i < numToken; i++) + { + if(jsoneq(js, &tokens[i], pParam) == 0) + break; + } + if (i < numToken) + { + dpToken = ++i; + } + else + { + printf("The parameter %s is not present in JSON file\n", pParam); + return 1; //Parent token not seen + } + for (i=1; i < numToken; i++) + { + if (tokens[i].parent == dpToken && tokens[i].type == JSMN_STRING && tokens[i].size == 1) + { +// printf("value of token %d\n", i); + if(jsoneq(js, &tokens[i], param) != 0) + continue; + + if (tokens[i+1].type == JSMN_OBJECT) + { + *numElements = tokens[i+1].size; +// printf("{%d elems}\n", *numElements); + + for (int k = 0; k < *numElements; k++) + { + TOKEN_COPY(js, tokens[i+2+k*2], keyValueResultList[k].keyStr); +// printf("Key - %s", keyValueResultList[k].keyStr); + TOKEN_COPY(js, tokens[i+3+k*2], keyValueResultList[k].valStr); +// printf("Value - %s\n", keyValueResultList[k].valStr); + } + return 0; //Success + } + } + } + printf("The parameter %s is not present in JSON file\n", param); + return 2; //parameter not found +} diff --git a/vnfs/VES5.0/evel/evel-library/code/VESreporting_fault/jsmn.h b/vnfs/VES5.0/evel/evel-library/code/VESreporting_fault/jsmn.h new file mode 100644 index 00000000..f9d838b6 --- /dev/null +++ b/vnfs/VES5.0/evel/evel-library/code/VESreporting_fault/jsmn.h @@ -0,0 +1,136 @@ +/*************************************************************************//** + * + * Copyright © 2017 AT&T Intellectual Property. All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + ****************************************************************************/ + +#ifndef __JSMN_H_ +#define __JSMN_H_ + +#include <stddef.h> + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * JSON type identifier. Basic types are: + * o Object + * o Array + * o String + * o Other primitive: number, boolean (true/false) or null + */ +typedef enum { + JSMN_UNDEFINED = 0, + JSMN_OBJECT = 1, + JSMN_ARRAY = 2, + JSMN_STRING = 3, + JSMN_PRIMITIVE = 4 +} jsmntype_t; + +enum jsmnerr { + /* Not enough tokens were provided */ + JSMN_ERROR_NOMEM = -1, + /* Invalid character inside JSON string */ + JSMN_ERROR_INVAL = -2, + /* The string is not a full JSON packet, more bytes expected */ + JSMN_ERROR_PART = -3 +}; + +typedef struct arrayValues { + char arrayString[32]; +} ARRAYVAL; + +typedef struct keyValResult { + char keyStr[80]; + char valStr[250]; + char resultStr[80]; +} KEYVALRESULT; + +/** + * JSON token description. + * @param type type (object, array, string etc.) + * @param start start position in JSON data string + * @param end end position in JSON data string + */ +typedef struct { + jsmntype_t type; + int start; + int end; + int size; +//#ifdef JSMN_PARENT_LINKS + int parent; +//#endif +} jsmntok_t; + +/** + * JSON parser. Contains an array of token blocks available. Also stores + * the string being parsed now and current position in that string + */ +typedef struct { + unsigned int pos; /* offset in the JSON string */ + unsigned int toknext; /* next token to allocate */ + int toksuper; /* superior token node, e.g parent object or array */ +} jsmn_parser; + +#define TOKEN_EQ(t, tok_start, tok_end, tok_type) \ + ((t).start == tok_start \ + && (t).end == tok_end \ + && (t).type == (tok_type)) + +#define TOKEN_STRING(js, t, s) \ + (strncmp(js+(t).start, s, (t).end - (t).start) == 0 \ + && strlen(s) == (t).end - (t).start) + +#define TOKEN_COPY(js, t, s) \ + strncpy(s, js+(t).start, (t).end - (t).start) + +#define TOKEN_PRINT(t) \ + printf("start: %d, end: %d, type: %d, size: %d\n", \ + (t).start, (t).end, (t).type, (t).size) + + +/** + * Create JSON parser over an array of tokens + */ +void jsmn_init(jsmn_parser *parser); + +/** + * Run JSON parser. It parses a JSON data string into and array of tokens, each describing + * a single JSON object. + */ +int jsmn_parse(jsmn_parser *parser, const char *js, size_t len, + jsmntok_t *tokens, unsigned int num_tokens); + +int jsoneq(const char *json, jsmntok_t *tok, const char *s); + +void printToken(char * js, jsmntok_t * tokens, int numToken); + +int getStringToken(char * js, jsmntok_t * tokens, int numToken, char * param, char * pParam, char * value, int maxValueSize); + +int getIntToken(char * js, jsmntok_t * tokens, int numToken, char * param, char * pParam, int * value); + +int getArrayTokens(char * js, jsmntok_t * tokens, int numToken, char * param, char * pParam, ARRAYVAL * arrayValue, int * numElements); + +int isTokenPresent(char * js, jsmntok_t * tokens, int numToken, char * param, char * pParam); + +int read_keyVal_params(char * js, jsmntok_t * tokens, int numToken, char * param, char * pParam, KEYVALRESULT * keyValueResultList, int * numElements); + +int getStringTokenV2(char * js, jsmntok_t * tokens, int numToken, char * param, char * pParam, char *gParam, char * value, int maxValueSize); + +#ifdef __cplusplus +} +#endif + +#endif /* __JSMN_H_ */ diff --git a/vnfs/VES5.0/evel/evel-library/code/VESreporting_fault/pom.xml b/vnfs/VES5.0/evel/evel-library/code/VESreporting_fault/pom.xml new file mode 100644 index 00000000..f9f42ebb --- /dev/null +++ b/vnfs/VES5.0/evel/evel-library/code/VESreporting_fault/pom.xml @@ -0,0 +1,83 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- + ============LICENSE_START========================================== + =================================================================== + Copyright © 2017 AT&T Intellectual Property. All rights reserved. + =================================================================== + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + ============LICENSE_END============================================ + + ECOMP and OpenECOMP are trademarks + and service marks of AT&T Intellectual Property. +--> +<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> + +<parent> + <groupId>org.onap.demo.vnf</groupId> + <artifactId>demo-aggregator</artifactId> + <version>1.2.0-SNAPSHOT</version> + <relativePath>../../pom.xml</relativePath> + </parent> + + <modelVersion>4.0.0</modelVersion> + <groupId>org.onap.demo.vnf.ves5</groupId> + <artifactId>ves_vfw_reporting</artifactId> + + <build> + <plugins> + + <plugin> + <artifactId>maven-jar-plugin</artifactId> + <version>2.3.2</version> + <executions> + <execution> + <id>default-jar</id> + <phase>never</phase> + </execution> + </executions> + </plugin> + + <plugin> + <artifactId>maven-assembly-plugin</artifactId> + <version>2.5.3</version> + <configuration> + <descriptor>dep.xml</descriptor> + </configuration> + <executions> + <execution> + <id>create-archive</id> + <phase>package</phase> + <goals> + <goal>single</goal> + </goals> + </execution> + </executions> + </plugin> + + <plugin> + <groupId>org.codehaus.mojo</groupId> + <artifactId>exec-maven-plugin</artifactId> + <executions> + <execution> + <phase>none</phase> + </execution> + </executions> + <configuration> + <skip>true</skip> + </configuration> + </plugin> + + </plugins> + </build> + +</project> diff --git a/vnfs/VES5.0/evel/evel-library/code/VESreporting_fault/sample_fault_events.txt b/vnfs/VES5.0/evel/evel-library/code/VESreporting_fault/sample_fault_events.txt new file mode 100644 index 00000000..516d1013 --- /dev/null +++ b/vnfs/VES5.0/evel/evel-library/code/VESreporting_fault/sample_fault_events.txt @@ -0,0 +1,98 @@ +{ + "event": { + "commonEventHeader": { + "domain": "fault", + "eventId": "fault000000001", + "eventName": "Fault_vFirewall-AT&T_linkDownError", + "eventType": "applicationVnf", + "lastEpochMicrosec": 1548491713599115, + "nfNamingCode": "AFX", + "nfcNamingCode": "AFX", + "priority": "Low", + "reportingEntityId": "cc305d54-75b4-431b-adb2-eb6b9e541234", + "reportingEntityName": "ibcx0001vm002oam001", + "sequence": 1, + "sourceId": "de305d54-75b4-431b-adb2-eb6b9e546014", + "sourceName": "scfx0001vm002cap001", + "startEpochMicrosec": 1548491713599115, + "version": 3.0 + }, + "faultFields": { + "alarmCondition": "link down trap_alarm", + "alarmInterfaceA": "docker0", + "eventCategory": "link", + "eventSeverity": "MAJOR", + "eventSourceType": "router", + "faultFieldsVersion": 2.0, + "specificProblem": "physical or logical connection to a remote router is down", + "vfStatus": "Idle" + } + } +} +=================================== + +{ + "event": { + "commonEventHeader": { + "domain": "fault", + "eventId": "fault000000001", + "eventName": "Fault_vFirewall-AT&T_serviceDownError", + "eventType": "applicationVnf", + "lastEpochMicrosec": 1548491702433326, + "nfNamingCode": "AFX", + "nfcNamingCode": "AFX", + "priority": "Low", + "reportingEntityId": "cc305d54-75b4-431b-adb2-eb6b9e541234", + "reportingEntityName": "ibcx0001vm002oam001", + "sequence": 1, + "sourceId": "de305d54-75b4-431b-adb2-eb6b9e546014", + "sourceName": "scfx0001vm002cap001", + "startEpochMicrosec": 1548491702433326, + "version": 3.0 + }, + "faultFields": { + "alarmCondition": "service down trap_alarm", + "alarmInterfaceA": "afx@input.service", + "eventCategory": "other", + "eventSeverity": "MAJOR", + "eventSourceType": "virtualMachine", + "faultFieldsVersion": 2.0, + "specificProblem": "service is down", + "vfStatus": "Idle" + } + } +} + +========================== +{ + "event": { + "commonEventHeader": { + "domain": "fault", + "eventId": "fault000000001", + "eventName": "Fault_vFirewall-AT&T_linkDownError", + "eventType": "applicationVnf", + "lastEpochMicrosec": 1548491569186353, + "nfNamingCode": "AFX", + "nfcNamingCode": "AFX", + "priority": "Low", + "reportingEntityId": "cc305d54-75b4-431b-adb2-eb6b9e541234", + "reportingEntityName": "ibcx0001vm002oam001", + "sequence": 0, + "sourceId": "de305d54-75b4-431b-adb2-eb6b9e546014", + "sourceName": "scfx0001vm002cap001", + "startEpochMicrosec": 1548491548714540, + "version": 3.0 + }, + "faultFields": { + "alarmCondition": "link up trap_alarm", + "alarmInterfaceA": "lo", + "eventCategory": "link", + "eventSeverity": "NORMAL", + "eventSourceType": "router", + "faultFieldsVersion": 2.0, + "specificProblem": "physical or logical connection to a remote router is up", + "vfStatus": "Idle" + } + } +} + diff --git a/vnfs/VES5.0/evel/evel-library/code/VESreporting_fault/ves_fault_reporter.c b/vnfs/VES5.0/evel/evel-library/code/VESreporting_fault/ves_fault_reporter.c new file mode 100644 index 00000000..3757d177 --- /dev/null +++ b/vnfs/VES5.0/evel/evel-library/code/VESreporting_fault/ves_fault_reporter.c @@ -0,0 +1,1328 @@ +/*************************************************************************//** + * + * Copyright © 2019 AT&T Intellectual Property. All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + ****************************************************************************/ + +#include <stdio.h> +#include <stdlib.h> +#include <unistd.h> +#include <pthread.h> +#include <string.h> +#include <netdb.h> +#include <sys/time.h> +#include <sys/stat.h> +#include "jsmn.h" +#include "evel.h" + +#define BUFSIZE 128 +#define MAX_BUFFER_SIZE 4096 +#define MAX_TOKENS 1000 +#define MAX_INTERFACES 40 + +void *FaultThread(void *threadarg); +void *FaultThread01(void *threadarg); +void *FaultThread02(void *threadarg); +void *FaultThread03(void *threadarg); + +typedef struct dummy_vpp_metrics_struct { + int curr_bytes_in; + int curr_bytes_out; + int curr_packets_in; + int curr_packets_out; + int last_bytes_in; + int last_bytes_out; + int last_packets_in; + int last_packets_out; +} vpp_metrics_struct; + +typedef struct linkstat { + + char linkname[32]; + char linkdescr[64]; + char linkmode[64]; + int speedmbps; + int fault_raised; + unsigned long long last_epoch; + +}LINKSTAT; + +//vpp_metrics_struct meas_intfstat[MAX_INTERFACES]; +//LINKSTAT meas_linkstat[MAX_INTERFACES]; +//int request_rate=0; +vpp_metrics_struct fault_intfstat[MAX_INTERFACES]; +LINKSTAT fault_linkstat[MAX_INTERFACES]; + +unsigned long long epoch_start = 0; + +int format_val_params(KEYVALRESULT * keyValArray, int numElements, const char *replace, const char *search) +{ + char *sp; + int i =0; + int search_len; + int replace_len; + int tail_len; + + for (i=0; i<numElements; i++) + { + if ((sp = strstr(keyValArray[i].valStr, search)) == NULL) { + printf("\n String not found\n"); + return 1; //Error search string not found + } + + search_len = strlen(search); + replace_len = strlen(replace); + tail_len = strlen(sp+search_len); + memmove(sp+replace_len,sp+search_len,tail_len+1); + memcpy(sp, replace, replace_len); +// printf("\n Changed value for i=%d is %s", i, keyValArray[i].valStr); + } + return 0; //search and replace is successful +} + +void runCommands(KEYVALRESULT * commandArray, int numCommands) +{ + + char buf[BUFSIZE]; /* buffer used to store VPP metrics */ + FILE *fp; /* file descriptor to pipe cmd to shell */ + int i; + + for(i = 0; i < numCommands; i++) + { + memset(buf, 0, BUFSIZE); + + // Open a pipe and read VPP values + if ((fp = popen(commandArray[i].valStr, "r")) == NULL) { + printf("Error opening pipe!\n"); + return; + } + + while (fgets(buf, BUFSIZE, fp) != NULL); + // printf("\n the vpp value is %d\n", atoi(buf)); + strcpy(commandArray[i].resultStr, buf); + + if(pclose(fp)) { + printf("Command not found or exited with error status\n"); + return; + } + } + //for(i = 0; i < numCommands; i++) + // printf("\n commandArray[%d].resultStr is- %s\n", i, commandArray[i].resultStr); +} + + +void copy_vpp_metic_data(vpp_metrics_struct *intfstats, KEYVALRESULT * cmdArray, int numCmds, int linkNum) +{ + int i; + + // Store the current metric in the last metric + intfstats[linkNum].last_bytes_in = intfstats[linkNum].curr_bytes_in; + intfstats[linkNum].last_bytes_out = intfstats[linkNum].curr_bytes_out; + intfstats[linkNum].last_packets_in = intfstats[linkNum].curr_packets_in; + intfstats[linkNum].last_packets_out = intfstats[linkNum].curr_packets_out; + + // Store metrics read from the vNIC in the current + for(i=0; i<numCmds; i++) + { + if((strcmp(cmdArray[i].keyStr, "tmp_t0BytesIn") == 0) || + (strcmp(cmdArray[i].keyStr, "tmp_t1BytesIn") == 0)) + intfstats[linkNum].curr_bytes_in = atoi(cmdArray[i].resultStr); + + if((strcmp(cmdArray[i].keyStr, "tmp_t0BytesOut") == 0) || + (strcmp(cmdArray[i].keyStr, "tmp_t1BytesOut") == 0)) + intfstats[linkNum].curr_bytes_out = atoi(cmdArray[i].resultStr); + + if((strcmp(cmdArray[i].keyStr, "tmp_t0PacketsIn") == 0) || + (strcmp(cmdArray[i].keyStr, "tmp_t1PacketsIn") == 0)) + intfstats[linkNum].curr_packets_in = atoi(cmdArray[i].resultStr); + + if((strcmp(cmdArray[i].keyStr, "tmp_t0PacketsOut") == 0) || + (strcmp(cmdArray[i].keyStr, "tmp_t1PacketsOut") == 0)) + intfstats[linkNum].curr_packets_out = atoi(cmdArray[i].resultStr); + } + // printf("intfstats[%d].curr_bytes_in = %d\n", linkNum, intfstats[linkNum].curr_bytes_in); + // printf("intfstats[%d].curr_bytes_out = %d\n", linkNum, intfstats[linkNum].curr_bytes_out); + // printf("intfstats[%d].curr_packets_in = %d\n", linkNum, intfstats[linkNum].curr_packets_in); + // printf("intfstats[%d].curr_packets_out = %d\n", linkNum, intfstats[linkNum].curr_packets_out); +} + +int get_severity(char * inStr) +{ + int result = -1; + + if(strcmp(inStr, "CRITICAL") == 0) + result = EVEL_SEVERITY_CRITICAL; + else if(strcmp(inStr, "MAJOR") == 0) + result = EVEL_SEVERITY_MAJOR; + else if(strcmp(inStr, "MINOR") == 0) + result = EVEL_SEVERITY_MINOR; + else if(strcmp(inStr, "WARNING") == 0) + result = EVEL_SEVERITY_WARNING; + else if(strcmp(inStr, "NORMAL") == 0) + result = EVEL_SEVERITY_NORMAL; + + return result; +} + +int get_priority(char * inStr) +{ + int result = -1; + + if(strcmp(inStr, "High") == 0) + result = EVEL_PRIORITY_HIGH; + else if(strcmp(inStr, "Medium") == 0) + result = EVEL_PRIORITY_MEDIUM; + else if(strcmp(inStr, "Normal") == 0) + result = EVEL_PRIORITY_NORMAL; + else if(strcmp(inStr, "Low") == 0) + result = EVEL_PRIORITY_LOW; + + return result; +} + +int get_source(char * inStr) +{ + int result = -1; + + if(strcmp(inStr, "other") == 0) + result = EVEL_SOURCE_OTHER; + else if(strcmp(inStr, "router") == 0) + result = EVEL_SOURCE_ROUTER; + else if(strcmp(inStr, "switch") == 0) + result = EVEL_SOURCE_SWITCH; + else if(strcmp(inStr, "host") == 0) + result = EVEL_SOURCE_HOST; + else if(strcmp(inStr, "card") == 0) + result = EVEL_SOURCE_CARD; + else if(strcmp(inStr, "port") == 0) + result = EVEL_SOURCE_PORT; + else if(strcmp(inStr, "slotThreshold") == 0) + result = EVEL_SOURCE_SLOT_THRESHOLD; + else if(strcmp(inStr, "portThreshold") == 0) + result = EVEL_SOURCE_PORT_THRESHOLD; + else if(strcmp(inStr, "virtualMachine") == 0) + result = EVEL_SOURCE_VIRTUAL_MACHINE; + else if(strcmp(inStr, "virtualNetworkFunction") == 0) + result = EVEL_SOURCE_VIRTUAL_NETWORK_FUNCTION; + + return result; +} + +int get_vf_status(char * inStr) +{ + int result = -1; + + if(strcmp(inStr, "Active") == 0) + result = EVEL_VF_STATUS_ACTIVE; + else if(strcmp(inStr, "Idle") == 0) + result = EVEL_VF_STATUS_IDLE; + else if(strcmp(inStr, "Preparing to terminate") == 0) + result = EVEL_VF_STATUS_PREP_TERMINATE; + else if(strcmp(inStr, "Ready to terminate") == 0) + result = EVEL_VF_STATUS_READY_TERMINATE; + else if(strcmp(inStr, "Requesting termination") == 0) + result = EVEL_VF_STATUS_REQ_TERMINATE; + + return result; +} + +int main(int argc, char** argv) +{ + char* fqdn = argv[1]; + int port = atoi(argv[2]); + int i=0; + int rc; + pthread_attr_t attr; + pthread_t flt_thread; + char* fqdn2 = NULL; + int port2 = 0; + + if(argc == 5) + { + fqdn2 = argv[3]; + port2 = atoi(argv[4]); + } + + if (!((argc == 3) || (argc == 5))) + { + fprintf(stderr, "Usage: %s <FQDN>|<IP address> <port> <FQDN>|<IP address> <port> \n", argv[0]); + fprintf(stderr, "OR\n"); + fprintf(stderr, "Usage: %s <FQDN>|<IP address> <port> \n", argv[0]); + exit(-1); + } + + /**************************************************************************/ + /* Initialize */ + /**************************************************************************/ + if(evel_initialize(fqdn, /* FQDN */ + port, /* Port */ + fqdn2, /* Backup FQDN */ + port2, /* Backup port */ + NULL, /* optional path */ + NULL, /* optional topic */ + 100, /* Ring Buffer size */ + 0, /* HTTPS? */ + NULL, /* cert file */ + NULL, /* key file */ + NULL, /* ca info */ + NULL, /* ca file */ + 0, /* verify peer */ + 0, /* verify host */ + "sample1", /* Username */ + "sample1", /* Password */ + "sample1", /* Username2 */ + "sample1", /* Password2 */ + NULL, /* Source ip */ + NULL, /* Source ip2 */ + EVEL_SOURCE_VIRTUAL_MACHINE, /* Source type */ + "vFault", /* Role */ + 1)) /* Verbosity */ + { + fprintf(stderr, "\nFailed to initialize the EVEL library!!!\n"); + exit(-1); + } + else + { + printf("\nInitialization completed\n"); + } + + /* Initialize and set thread detached attribute */ + pthread_attr_init(&attr); + pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED); + + printf("Main:Creating thread \n"); + rc = pthread_create(&flt_thread, NULL, FaultThread, &i); + if (rc) + { + printf("ERROR; return code from pthread_create() is %d\n", rc); + exit(-1); + } + printf("Main:Created Fault thread \n"); + + pthread_join(flt_thread, NULL); + + evel_terminate(); + printf("Terminated\n"); + return 0; +} + +void *FaultThread(void *mainFault) +{ + + pthread_attr_t attr; + pthread_t flt_thread01; + pthread_t flt_thread02; + pthread_t flt_thread03; + int faultInstance01 = 0; + int faultInstance02 = 0; + int faultInstance03 = 0; + int rc; + + int numToken; + jsmntok_t tokens[MAX_TOKENS]; + char js[MAX_BUFFER_SIZE]; + + jsmn_parser p; + char ch[BUFSIZE]; + int ret = 0; + + memset(js, 0, MAX_BUFFER_SIZE); + memset(ch, 0, BUFSIZE); + + sleep(1); + printf("Running Main Fault thread \n"); + fflush(stdout); + + /* Initialize and set thread detached attribute */ + pthread_attr_init(&attr); + pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED); + + FILE * file = fopen("flt_config.json", "r"); + + while((fgets(ch, (BUFSIZE-1), file)) !=NULL) + { + strcat(js, ch); + memset(ch, 0, BUFSIZE); + } + //printf("MainFaulThread::the file content is \n %s \n", js); + //printf("\n MainFaulThread::MMMMMMMMMMMMMMM\n"); + + jsmn_init(&p); + numToken = jsmn_parse(&p, js, strlen(js), tokens, MAX_TOKENS); + //printf("count-%d\n", numToken); + + //printToken(js,tokens, numToken); + + printf("Main Fault Thread: Creating other fault threads\n"); + + ret = isTokenPresent(js, tokens, numToken, "tmp_faultInstance01", "tmp_indirectParameters"); + if (ret == 0) + { +// rc = pthread_create(&flt_thread01, NULL, FaultThread01, "tmp_faultInstance01"); + rc = pthread_create(&flt_thread01, NULL, FaultThread01, &ret); + if (rc) + { + printf("Main Fault Thread::ERROR; return code from pthread_create() is %d\n", rc); + exit(-1); + } + faultInstance01 = 1; + } + + ret = isTokenPresent(js, tokens, numToken, "tmp_faultInstance02", "tmp_indirectParameters"); + if (ret == 0) + { +// rc = pthread_create(&flt_thread02, NULL, FaultThread02, "tmp_faultInstance02"); + rc = pthread_create(&flt_thread02, NULL, FaultThread02, &ret); + if (rc) + { + printf("Main Fault Thread::ERROR; return code from pthread_create() is %d\n", rc); + exit(-1); + } + faultInstance02 = 1; + } + + ret = isTokenPresent(js, tokens, numToken, "tmp_faultInstance03", "tmp_indirectParameters"); + if (ret == 0) + { + rc = pthread_create(&flt_thread03, NULL, FaultThread03, &ret); + if (rc) + { + printf("Main Fault Thread::ERROR; return code from pthread_create() is %d\n", rc); + exit(-1); + } + faultInstance03 = 1; + } + + if (faultInstance01 == 1) + { + pthread_join(flt_thread01, NULL); + } + + if (faultInstance02 == 1) + { + pthread_join(flt_thread02, NULL); + } + + if (faultInstance03 == 1) + { + pthread_join(flt_thread03, NULL); + } + + while(1) + { + sleep(100); + } +} + +void *FaultThread01(void *faultInstanceTag) +{ + EVEL_ERR_CODES evel_rc = EVEL_SUCCESS; + EVENT_FAULT * fault = NULL; + EVENT_HEADER* fault_header = NULL; + int bytes_in; + int bytes_out; + int packets_in; + int packets_out; + unsigned long long epoch_now; + int lowWaterMark; + + struct timeval time_val; + char event_id1[10] = "fault"; + char event_id2[15] = {0}; + char event_id[BUFSIZE] = {0}; + int fault_event_id = 0; + + int numToken; + jsmntok_t tokens[MAX_TOKENS]; + char js[MAX_BUFFER_SIZE]; + + jsmn_parser p; + char ch[BUFSIZE]; + int ret = 0; + char eName[BUFSIZE]; + char eType[BUFSIZE]; + char nfcCode[BUFSIZE]; + char nfCode[BUFSIZE]; + char prio[BUFSIZE]; + char reportEId[BUFSIZE]; + char reportEName[BUFSIZE]; + char srcId[BUFSIZE]; + char srcName[BUFSIZE]; + char eCategory[BUFSIZE]; + char eventSrcTyp[BUFSIZE]; + char specProb[BUFSIZE]; + char alarmCondn[BUFSIZE]; + char eventSev[BUFSIZE]; + char vfStatus[BUFSIZE]; + + int priority; + int srcTyp; + int vfStat; + int eSev; + + char hostname[BUFSIZE]; + + int flt_interval; + ARRAYVAL intfArray[MAX_INTERFACES]; + KEYVALRESULT keyValResultArray[32]; + KEYVALRESULT commandArray[32]; + int numInitCommands = 0; + int numCommands = 0; + int linkCount = 0; + int i = 0; + + memset(hostname, 0, BUFSIZE); + gethostname(hostname, BUFSIZE); + printf("FAULT01::The hostname is %s\n", hostname); + + sleep(1); + printf("FAULT01::Running Fault thread \n"); + fflush(stdout); + + memset(&intfArray[0],0,(sizeof(ARRAYVAL) * MAX_INTERFACES)); + memset(&keyValResultArray[0],0,(sizeof(KEYVALRESULT) * 32)); + + memset(js, 0, MAX_BUFFER_SIZE); + memset(ch, 0, BUFSIZE); + memset(&fault_intfstat[0],0,(sizeof(vpp_metrics_struct)* MAX_INTERFACES)); + memset(&fault_linkstat[0],0,(sizeof(LINKSTAT) * MAX_INTERFACES)); + + FILE * file = fopen("flt_config.json", "r"); + + while((fgets(ch, (BUFSIZE-1), file)) !=NULL) + { + strcat(js, ch); + memset(ch, 0, BUFSIZE); + } +// printf("FAULT01::the file content is \n %s \n", js); + + jsmn_init(&p); + numToken = jsmn_parse(&p, js, strlen(js), tokens, MAX_TOKENS); + printf("FAULT01::count-%d\n", numToken); + +// printToken(js,tokens, numToken); + + + ret = getIntToken(js, tokens, numToken, "tmp_faultCheckInterval", "tmp_faultInstance01", &flt_interval); + if (ret != 0) + { + printf("FAULT01::The parameter tmp_faultCheckInterval is not defined, defaulted to 60 seconds\n"); + flt_interval = 60; + } + + ret = getIntToken(js, tokens, numToken, "tmp_lowWaterMark", "tmp_faultInstance01", &lowWaterMark); + if (ret != 0) + { + printf("FAULT01::The parameter tmp_lowWaterMark is not defined, defaulted to 100\n"); + lowWaterMark = 100; + } + + ret = getArrayTokens(js, tokens, numToken, "tmp_device", "tmp_directParameters", intfArray, &linkCount); + + printf("FAULT01::Array link count is %d\n", linkCount); + + /* Copy the link information */ + for(i=0;i<linkCount;i++) + { + strcpy(fault_linkstat[i].linkname, &intfArray[i]); +// printf("FAULT01::Link name %s\n", fault_linkstat[i].linkname); + } + + //read_fault_config_file(); + + read_keyVal_params(js, tokens, numToken, "tmp_init", "tmp_faultInstance01", keyValResultArray, &numInitCommands); + + for(i=0;i<linkCount;i++) + { + memset(&commandArray[0],0,(sizeof(KEYVALRESULT) * 32)); + memcpy(commandArray, keyValResultArray, (sizeof(KEYVALRESULT) * 32)); + format_val_params(commandArray, numInitCommands, fault_linkstat[i].linkname, "$tmp_device"); + runCommands(commandArray, numInitCommands); + copy_vpp_metic_data(fault_intfstat, commandArray, numInitCommands, i); + } + + gettimeofday(&time_val, NULL); + + sleep(flt_interval); + + /***************************************************************************/ + /* Collect metrics from the VNIC */ + /***************************************************************************/ + while(1) + { + + ret = getIntToken(js, tokens, numToken, "tmp_faultCheckInterval", "tmp_faultInstance01", &flt_interval); + if (ret != 0) + { + flt_interval = 60; + } + + ret = getIntToken(js, tokens, numToken, "tmp_lowWaterMark", "tmp_faultInstance01", &lowWaterMark); + if (ret != 0) + { + lowWaterMark = 100; + } + + ret = getStringToken(js, tokens, numToken, "eventName", "tmp_faultInstance01", eName, BUFSIZE); + if (ret != 0) + { + printf("FAULT01::Missing mandatory parameters - eventName is not there in tmp_faultInstance01. Exiting...\n"); + exit(1); + } + + ret = getStringToken(js, tokens, numToken, "eventType", "tmp_directParameters", eType, BUFSIZE); + ret = getStringToken(js, tokens, numToken, "nfcNamingCode", "tmp_directParameters", nfcCode, BUFSIZE); + ret = getStringToken(js, tokens, numToken, "nfNamingCode", "tmp_directParameters", nfCode, BUFSIZE); + ret = getStringToken(js, tokens, numToken, "reportingEntityId", "tmp_directParameters", reportEId, BUFSIZE); + ret = getStringToken(js, tokens, numToken, "sourceId", "tmp_directParameters", srcId, BUFSIZE); + ret = getStringToken(js, tokens, numToken, "eventCategory", "tmp_faultInstance01", eCategory, BUFSIZE); + + ret = getStringToken(js, tokens, numToken, "eventSourceType", "tmp_faultInstance01", eventSrcTyp, BUFSIZE); + if (ret != 0) + { + printf("FAULT01::Missing mandatory parameters - eventSourceType is not there in tmp_directParameters, exiting..\n"); + exit(1); + } + srcTyp = get_source(eventSrcTyp); + if(srcTyp == -1) + { + printf("FAULT01::Fault eventSourceType value is not matching, eventSourceType-%s \n", eventSrcTyp); + exit(1); + } + + ret = getStringToken(js, tokens, numToken, "vfStatus", "tmp_directParameters", vfStatus, BUFSIZE); + if (ret != 0) + { + printf("FAULT01::Missing mandatory parameters - vfStatus is not there in tmp_directParameters, exiting..\n"); + exit(1); + } + vfStat = get_vf_status(vfStatus); + if(vfStat == -1) + { + printf("FAULT01::Fault vfStatus value is not matching, vfStatus-%s \n", vfStatus); + exit(1); + } + + read_keyVal_params(js, tokens, numToken, "tmp_command", "tmp_faultInstance01", keyValResultArray, &numCommands); + + for(i=0;i<linkCount;i++) + { + memset(&commandArray[0],0,(sizeof(KEYVALRESULT) * 32)); + memcpy(commandArray, keyValResultArray, (sizeof(KEYVALRESULT) * 32)); + format_val_params(commandArray, numCommands, fault_linkstat[i].linkname, "$tmp_device"); + runCommands(commandArray, numCommands); + copy_vpp_metic_data(fault_intfstat, commandArray, numInitCommands, i); + } + + for (int i = 0; i < linkCount; i++) + { + if(fault_intfstat[i].curr_bytes_in - fault_intfstat[i].last_bytes_in > 0) { + bytes_in = fault_intfstat[i].curr_bytes_in - fault_intfstat[i].last_bytes_in; + } + else { + bytes_in = 0; + } + if(fault_intfstat[i].curr_bytes_out - fault_intfstat[i].last_bytes_out > 0) { + bytes_out = fault_intfstat[i].curr_bytes_out - fault_intfstat[i].last_bytes_out; + } + else { + bytes_out = 0; + } + if(fault_intfstat[i].curr_packets_in - fault_intfstat[i].last_packets_in > 0) { + packets_in = fault_intfstat[i].curr_packets_in - fault_intfstat[i].last_packets_in; + } + else { + packets_in = 0; + } + if(fault_intfstat[i].curr_packets_out - fault_intfstat[i].last_packets_out > 0) { + packets_out = fault_intfstat[i].curr_packets_out - fault_intfstat[i].last_packets_out; + } + else { + packets_out = 0; + } + if (((bytes_in < lowWaterMark) || (bytes_out < lowWaterMark) || + (packets_in < lowWaterMark) || (packets_out < lowWaterMark)) && + (fault_linkstat[i].fault_raised == 0)) + { + printf("\n%d - bytes in %d, ouot %d, packets in %d, out %d", i, bytes_in, bytes_out, packets_in, packets_out); + printf("\nFAULT01::Raising fault\n"); + memset(event_id, 0, BUFSIZE); + fault_event_id = fault_event_id+1; + sprintf(event_id2, "%09d", fault_event_id); + strcat(event_id, event_id1); + strcat(event_id, event_id2); + + ret = getIntToken(js, tokens, numToken, "tmp_faultCheckInterval", "tmp_faultInstance01", &flt_interval); + if (ret != 0) + { + printf("FAULT01::The parameter tmp_faultCheckInterval is not defined, defaulted to 60 seconds\n"); + flt_interval = 60; + } + + ret = getIntToken(js, tokens, numToken, "tmp_lowWaterMark", "tmp_faultInstance01", &lowWaterMark); + if (ret != 0) + { + printf("FAULT01::The parameter tmp_lowWaterMark is not defined, defaulted to 100\n"); + lowWaterMark = 100; + } + ret = getStringToken(js, tokens, numToken, "reportingEntityName", "tmp_directParameters", reportEName, BUFSIZE); + if (ret != 0) + { + printf("FAULT01::Missing mandatory parameters - reportingEntityName is not there in tmp_directParameters\n"); + printf("FAULT01::Defaulting reportingEntityName to hostname\n"); + strcpy(reportEName, hostname); + } + ret = getStringToken(js, tokens, numToken, "sourceName", "tmp_directParameters", srcName, BUFSIZE); + if (ret != 0) + { + printf("FAULT01::Missing mandatory parameters - sourceName is not there in tmp_directParameters\n"); + printf("FAULT01::Defaulting sourceName to hostname\n"); + strcpy(srcName, hostname); + } + + ret = getStringToken(js, tokens, numToken, "priority", "tmp_directParameters", prio, BUFSIZE); + if (ret != 0) + { + printf("FAULT01::Missing mandatory parameters - priority is not there in tmp_directParameters\nDefaulting priority to Low\n"); + strcpy(prio, "Medium"); + } + priority = get_priority(prio); + if(priority == -1) + { + printf("FAULT01::Fault priority value is not matching, prioirty-%s \n", prio); + exit(1); + } + + ret = getStringTokenV2(js, tokens, numToken, "specificProblem", "tmp_alarmSetParameters", "tmp_faultInstance01", specProb, BUFSIZE); + if (ret != 0) + { + printf("FAULT01::Missing mandatory parameters - specificProblem is not there in tmp_alarmSetParameters, exiting ...\n"); + exit(1); + } + ret = getStringTokenV2(js, tokens, numToken, "alarmCondition", "tmp_alarmSetParameters", "tmp_faultInstance01", alarmCondn, BUFSIZE); + if (ret != 0) + { + printf("FAULT01::Missing mandatory parameters - alarmCondition is not there in tmp_alarmSetParameters, exiting ...\n"); + exit(1); + } + ret = getStringTokenV2(js, tokens, numToken, "eventSeverity", "tmp_alarmSetParameters", "tmp_faultInstance01", eventSev, BUFSIZE); + if (ret != 0) + { + printf("FAULT01::Missing mandatory parameters - eventSeverity is not there in tmp_alarmSetParameters\n"); + printf("FAULT01::Defaulting eventSeverity to MAJOR\n"); + strcpy(eventSev, "MAJOR"); + } + eSev = get_severity(eventSev); + if(eSev == -1) + { + printf("FAULT01::Fault eventSeverity value is not matching, eventSeverity-%s \n", eventSev); + exit(1); + } + + fault = evel_new_fault(eName, event_id, alarmCondn, + specProb, priority, eSev, srcTyp,vfStat); + if (fault != NULL) + { + fault_linkstat[i].fault_raised = 1; + + struct timeval tv_now; + gettimeofday(&tv_now, NULL); + epoch_now = tv_now.tv_usec + 1000000 * tv_now.tv_sec; + fault_linkstat[i].last_epoch = epoch_now; + + fault_header = (EVENT_HEADER *)fault; + + evel_fault_category_set(fault, eCategory); + evel_fault_interface_set(fault, fault_linkstat[i].linkname); + + if (eType != NULL) + evel_fault_type_set(fault, eType); + + evel_start_epoch_set(&fault->header, epoch_now); + evel_last_epoch_set(&fault->header, epoch_now); + if(nfcCode != NULL) + evel_nfcnamingcode_set(&fault->header, nfcCode); + if(nfCode != NULL) + evel_nfnamingcode_set(&fault->header, nfCode); + evel_reporting_entity_name_set(&fault->header, reportEName); + if(reportEId != NULL) + evel_reporting_entity_id_set(&fault->header, reportEId); + if(srcId != NULL ) + evel_source_id_set(&fault->header, srcId); + if(srcName!= NULL ) + evel_source_name_set(&fault->header, srcName); + + evel_rc = evel_post_event(fault_header); + + if(evel_rc == EVEL_SUCCESS) + printf("FAULT01::Fault event is correctly sent to the collector!\n"); + else + printf("FAULT01::Post failed %d (%s)\n", evel_rc, evel_error_string()); + } + else + { + printf("FAULT01::New new fault failed (%s)\n", evel_error_string()); + } + } + else if (((bytes_in > lowWaterMark) && (bytes_out > lowWaterMark) && + (packets_in > lowWaterMark) && (packets_out > lowWaterMark)) && + (fault_linkstat[i].fault_raised == 1)) + { + printf("\nFAULT01:: Clearing fault\n"); + memset(event_id, 0, BUFSIZE); + sprintf(event_id2, "%09d", (i+1)); + strcat(event_id, event_id1); + strcat(event_id, event_id2); + + ret = getIntToken(js, tokens, numToken, "tmp_faultCheckInterval", "tmp_faultInstance01", &flt_interval); + if (ret != 0) + { + printf("FAULT01::The parameter tmp_faultCheckInterval is not defined, defaulted to 60 seconds\n"); + flt_interval = 60; + } + + ret = getIntToken(js, tokens, numToken, "tmp_lowWaterMark", "tmp_faultInstance01", &lowWaterMark); + if (ret != 0) + { + printf("FAULT01::The parameter tmp_lowWaterMark is not defined, defaulted to 100\n"); + lowWaterMark = 100; + } + ret = getStringToken(js, tokens, numToken, "reportingEntityName", "tmp_directParameters", reportEName, BUFSIZE); + if (ret != 0) + { + printf("FAULT01::Missing mandatory parameters - reportingEntityName is not there in tmp_directParameters\n"); + printf("FAULT01::Defaulting reportingEntityName to hostname\n"); + strcpy(reportEName, hostname); + } + ret = getStringToken(js, tokens, numToken, "sourceName", "tmp_directParameters", srcName, BUFSIZE); + if (ret != 0) + { + printf("FAULT01::Missing mandatory parameters - sourceName is not there in tmp_directParameters\n"); + printf("FAULT01::Defaulting sourceName to hostname\n"); + strcpy(srcName, hostname); + } + + ret = getStringToken(js, tokens, numToken, "priority", "tmp_directParameters", prio, BUFSIZE); + if (ret != 0) + { + printf("FAULT01::Missing mandatory parameters - priority is not there in tmp_directParameters\nDefaulting priority to Low\n"); + strcpy(prio, "Medium"); + } + priority = get_priority(prio); + if(priority == -1) + { + printf("FAULT01::Fault priority value is not matching, prioirty-%s \n", prio); + exit(1); + } + + ret = getStringTokenV2(js, tokens, numToken, "specificProblem", "tmp_alarmClearParameters", "tmp_faultInstance01", specProb, BUFSIZE); + if (ret != 0) + { + printf("FAULT01::Missing mandatory parameters - specificProblem is not there in tmp_alarmClearParameters, exiting ...\n"); + exit(1); + } + + ret = getStringTokenV2(js, tokens, numToken, "alarmCondition", "tmp_alarmClearParameters", "tmp_faultInstance01", alarmCondn, BUFSIZE); + if (ret != 0) + { + printf("FAULT01::Missing mandatory parameters - alarmCondition is not there in tmp_alarmClearParameters, exiting ...\n"); + exit(1); + } + + ret = getStringTokenV2(js, tokens, numToken, "eventSeverity", "tmp_alarmClearParameters", "tmp_faultInstance01", eventSev, BUFSIZE); + if (ret != 0) + { + printf("FAULT01::Missing mandatory parameters - eventSeverity is not there in tmp_alarmClearParameters\n"); + printf("FAULT01::Defaulting eventSeverity to MAJOR\n"); + strcpy(eventSev, "NORMAL"); + } + eSev = get_severity(eventSev); + if(eSev == -1) + { + printf("FAULT01::Fault eventSeverity value is not matching, eventSeverity-%s \n", eventSev); + exit(1); + } + + fault = evel_new_fault(eName, event_id, alarmCondn, + specProb, priority, eSev, srcTyp,vfStat); + if (fault != NULL) + { + fault_linkstat[i].fault_raised = 0; + + struct timeval tv_now; + gettimeofday(&tv_now, NULL); + epoch_now = tv_now.tv_usec + 1000000 * tv_now.tv_sec; + + fault_header = (EVENT_HEADER *)fault; + evel_fault_category_set(fault, eCategory); + evel_fault_interface_set(fault, fault_linkstat[i].linkname); + + if (eType != NULL) + evel_fault_type_set(fault, eType); + + evel_start_epoch_set(&fault->header, fault_linkstat[i].last_epoch); + evel_last_epoch_set(&fault->header, epoch_now); + fault_linkstat[i].last_epoch = 0; + + if(nfcCode != NULL) + evel_nfcnamingcode_set(&fault->header, nfcCode); + if(nfCode != NULL) + evel_nfnamingcode_set(&fault->header, nfCode); + evel_reporting_entity_name_set(&fault->header, reportEName); + if(reportEId != NULL) + evel_reporting_entity_id_set(&fault->header, reportEId); + if(srcId != NULL ) + evel_source_id_set(&fault->header, srcId); + if(srcName!= NULL ) + evel_source_name_set(&fault->header, srcName); + + evel_rc = evel_post_event(fault_header); + + if(evel_rc == EVEL_SUCCESS) + printf("FAULT01::Fault event is correctly sent to the collector!\n"); + else + printf("FAULT01::Post failed %d (%s)\n", evel_rc, evel_error_string()); + } + else + printf("FAULT01::New fault failed (%s)\n", evel_error_string()); + } + } + + sleep(flt_interval); + } + + /***************************************************************************/ + /* Terminate */ + /***************************************************************************/ + sleep(1); +} + +void *FaultThread02(void *faultInstanceTag) +{ + EVEL_ERR_CODES evel_rc = EVEL_SUCCESS; + EVENT_FAULT * fault = NULL; + EVENT_HEADER* fault_header = NULL; + unsigned long long epoch_now; + unsigned long long last_epoch; + + struct timeval time_val; + char event_id1[10] = "fault"; + char event_id2[15] = {0}; + char event_id[BUFSIZE] = {0}; + int fault_event_id = 0; + int i=0; + + int numToken; + jsmntok_t tokens[MAX_TOKENS]; + char js[MAX_BUFFER_SIZE]; + + jsmn_parser p; + char ch[BUFSIZE]; + int ret = 0; + char eName[BUFSIZE]; + char eType[BUFSIZE]; + char aInterface[BUFSIZE]; + char nfcCode[BUFSIZE]; + char nfCode[BUFSIZE]; + char prio[BUFSIZE]; + char reportEId[BUFSIZE]; + char reportEName[BUFSIZE]; + char srcId[BUFSIZE]; + char srcName[BUFSIZE]; + char eCategory[BUFSIZE]; + char eventSrcTyp[BUFSIZE]; + char specProb[BUFSIZE]; + char alarmCondn[BUFSIZE]; + char eventSev[BUFSIZE]; + char vfStatus[BUFSIZE]; + + int priority; + int srcTyp; + int vfStat; + int eSev; + + char hostname[BUFSIZE]; + + int flt_interval; + KEYVALRESULT keyValResultArray[32]; + KEYVALRESULT commandArray[32]; + int numInitCommands = 0; + int numCommands = 0; + int fault_raised = 0; + + memset(hostname, 0, BUFSIZE); + gethostname(hostname, BUFSIZE); + printf("FAULT02::The hostname is %s\n", hostname); + + sleep(1); + printf("FAULT02::Running Fault thread \n"); + fflush(stdout); + + memset(&keyValResultArray[0],0,(sizeof(KEYVALRESULT) * 32)); + + memset(js, 0, MAX_BUFFER_SIZE); + memset(ch, 0, BUFSIZE); + + FILE * file = fopen("flt_config.json", "r"); + + while((fgets(ch, (BUFSIZE-1), file)) !=NULL) + { + strcat(js, ch); + memset(ch, 0, BUFSIZE); + } +// printf("FAULT02::the file content is \n %s \n", js); + + jsmn_init(&p); + numToken = jsmn_parse(&p, js, strlen(js), tokens, MAX_TOKENS); + printf("FAULT02::count-%d\n", numToken); + +// printToken(js,tokens, numToken); + + ret = getIntToken(js, tokens, numToken, "tmp_faultCheckInterval", "tmp_faultInstance02", &flt_interval); + if (ret != 0) + { + printf("FAULT02::The parameter tmp_faultCheckInterval is not defined, defaulted to 60 seconds\n"); + flt_interval = 60; + } + + + read_keyVal_params(js, tokens, numToken, "tmp_init", "tmp_faultInstance02", keyValResultArray, &numInitCommands); + + memset(&commandArray[0],0,(sizeof(KEYVALRESULT) * 32)); + memcpy(commandArray, keyValResultArray, (sizeof(KEYVALRESULT) * 32)); + runCommands(commandArray, numInitCommands); + + gettimeofday(&time_val, NULL); + + sleep(flt_interval); + + /***************************************************************************/ + /* Collect metrics from the VNIC */ + /***************************************************************************/ + while(1) { + + ret = getIntToken(js, tokens, numToken, "tmp_faultCheckInterval", "tmp_faultInstance02", &flt_interval); + if (ret != 0) + { + flt_interval = 60; + } + + ret = getStringToken(js, tokens, numToken, "eventName", "tmp_faultInstance02", eName, BUFSIZE); + if (ret != 0) + { + printf("FAULT02::Missing mandatory parameters - eventName is not there in tmp_faultInstance02. Exiting...\n"); + exit(1); + } + + ret = getStringToken(js, tokens, numToken, "eventType", "tmp_directParameters", eType, BUFSIZE); + ret = getStringToken(js, tokens, numToken, "nfcNamingCode", "tmp_directParameters", nfcCode, BUFSIZE); + ret = getStringToken(js, tokens, numToken, "nfNamingCode", "tmp_directParameters", nfCode, BUFSIZE); + ret = getStringToken(js, tokens, numToken, "reportingEntityId", "tmp_directParameters", reportEId, BUFSIZE); + ret = getStringToken(js, tokens, numToken, "sourceId", "tmp_directParameters", srcId, BUFSIZE); + ret = getStringToken(js, tokens, numToken, "eventCategory", "tmp_faultInstance02", eCategory, BUFSIZE); + ret = getStringToken(js, tokens, numToken, "alarmInterfaceA", "tmp_faultInstance02", aInterface, BUFSIZE); + + ret = getStringToken(js, tokens, numToken, "eventSourceType", "tmp_faultInstance02", eventSrcTyp, BUFSIZE); + if (ret != 0) + { + printf("FAULT02::Missing mandatory parameters - eventSourceType is not there in tmp_directParameters, exiting..\n"); + exit(1); + } + srcTyp = get_source(eventSrcTyp); + if(srcTyp == -1) + { + printf("FAULT02::Fault eventSourceType value is not matching, eventSourceType-%s \n", eventSrcTyp); + exit(1); + } + + ret = getStringToken(js, tokens, numToken, "vfStatus", "tmp_directParameters", vfStatus, BUFSIZE); + if (ret != 0) + { + printf("FAULT02::Missing mandatory parameters - vfStatus is not there in tmp_directParameters, exiting..\n"); + exit(1); + } + vfStat = get_vf_status(vfStatus); + if(vfStat == -1) + { + printf("FAULT02::Fault vfStatus value is not matching, vfStatus-%s \n", vfStatus); + exit(1); + } + + read_keyVal_params(js, tokens, numToken, "tmp_command", "tmp_faultInstance02", keyValResultArray, &numCommands); + + memset(&commandArray[0],0,(sizeof(KEYVALRESULT) * 32)); + memcpy(commandArray, keyValResultArray, (sizeof(KEYVALRESULT) * 32)); + runCommands(commandArray, numCommands); + + /******************************************************************************** + * Put the condition to set the fault here + *******************************************************************************/ + if ((atoi(commandArray[0].resultStr) == 1) && (fault_raised == 0)) + { + printf("\nFAULT02::Raising fault\n"); + memset(event_id, 0, BUFSIZE); + fault_event_id = fault_event_id+1; + sprintf(event_id2, "%09d", fault_event_id); + strcat(event_id, event_id1); + strcat(event_id, event_id2); + + ret = getIntToken(js, tokens, numToken, "tmp_faultCheckInterval", "tmp_faultInstance02", &flt_interval); + if (ret != 0) + { + printf("FAULT02::The parameter tmp_faultCheckInterval is not defined, defaulted to 60 seconds\n"); + flt_interval = 60; + } + + ret = getStringToken(js, tokens, numToken, "reportingEntityName", "tmp_directParameters", reportEName, BUFSIZE); + if (ret != 0) + { + printf("FAULT02::Missing mandatory parameters - reportingEntityName is not there in tmp_directParameters\n"); + printf("FAULT02::Defaulting reportingEntityName to hostname\n"); + strcpy(reportEName, hostname); + } + ret = getStringToken(js, tokens, numToken, "sourceName", "tmp_directParameters", srcName, BUFSIZE); + if (ret != 0) + { + printf("FAULT02::Missing mandatory parameters - sourceName is not there in tmp_directParameters\n"); + printf("FAULT02::Defaulting sourceName to hostname\n"); + strcpy(srcName, hostname); + } + + ret = getStringToken(js, tokens, numToken, "priority", "tmp_directParameters", prio, BUFSIZE); + if (ret != 0) + { + printf("FAULT02::Missing mandatory parameters - priority is not there in tmp_directParameters\nDefaulting priority to Low\n"); + strcpy(prio, "Medium"); + } + priority = get_priority(prio); + if(priority == -1) + { + printf("FAULT02::Fault priority value is not matching, prioirty-%s \n", prio); + exit(1); + } + + ret = getStringTokenV2(js, tokens, numToken, "specificProblem", "tmp_alarmSetParameters", "tmp_faultInstance02", specProb, BUFSIZE); + if (ret != 0) + { + printf("FAULT02::Missing mandatory parameters - specificProblem is not there in tmp_alarmSetParameters, exiting ...\n"); + exit(1); + } + ret = getStringTokenV2(js, tokens, numToken, "alarmCondition", "tmp_alarmSetParameters", "tmp_faultInstance02", alarmCondn, BUFSIZE); + if (ret != 0) + { + printf("FAULT02::Missing mandatory parameters - alarmCondition is not there in tmp_alarmSetParameters, exiting ...\n"); + exit(1); + } + ret = getStringTokenV2(js, tokens, numToken, "eventSeverity", "tmp_alarmSetParameters", "tmp_faultInstance02", eventSev, BUFSIZE); + if (ret != 0) + { + printf("FAULT02::Missing mandatory parameters - eventSeverity is not there in tmp_alarmSetParameters\n"); + printf("FAULT02::Defaulting eventSeverity to MAJOR\n"); + strcpy(eventSev, "MAJOR"); + } + eSev = get_severity(eventSev); + if(eSev == -1) + { + printf("FAULT02::Fault eventSeverity value is not matching, eventSeverity-%s \n", eventSev); + exit(1); + } + + fault = evel_new_fault(eName, event_id, alarmCondn, + specProb, priority, eSev, srcTyp,vfStat); + if (fault != NULL) + { + fault_raised = 1; + + struct timeval tv_now; + gettimeofday(&tv_now, NULL); + epoch_now = tv_now.tv_usec + 1000000 * tv_now.tv_sec; + last_epoch = epoch_now; + + fault_header = (EVENT_HEADER *)fault; + + evel_fault_category_set(fault, eCategory); + if (aInterface != NULL) + evel_fault_interface_set(fault, aInterface); + + if (eType != NULL) + evel_fault_type_set(fault, eType); + + evel_start_epoch_set(&fault->header, epoch_now); + evel_last_epoch_set(&fault->header, epoch_now); + if(nfcCode != NULL) + evel_nfcnamingcode_set(&fault->header, nfcCode); + if(nfCode != NULL) + evel_nfnamingcode_set(&fault->header, nfCode); + evel_reporting_entity_name_set(&fault->header, reportEName); + if(reportEId != NULL) + evel_reporting_entity_id_set(&fault->header, reportEId); + if(srcId != NULL ) + evel_source_id_set(&fault->header, srcId); + if(srcName!= NULL ) + evel_source_name_set(&fault->header, srcName); + + evel_rc = evel_post_event(fault_header); + + if(evel_rc == EVEL_SUCCESS) { + printf("FAULT02::Fault event is correctly sent to the collector!\n"); + } + else { + printf("FAULT02::Post failed %d (%s)\n", evel_rc, evel_error_string()); + } + } + else { + printf("FAULT02::New new fault failed (%s)\n", evel_error_string()); + } + } + /******************************************************************************** + * Put the condition to clear the fault here + *******************************************************************************/ + else if ((atoi(commandArray[0].resultStr) == 0) && (fault_raised == 1)) + { + printf("\nFAULT02:: Clearing fault\n"); + memset(event_id, 0, BUFSIZE); + sprintf(event_id2, "%09d", (i+1)); + strcat(event_id, event_id1); + strcat(event_id, event_id2); + + ret = getIntToken(js, tokens, numToken, "tmp_faultCheckInterval", "tmp_faultInstance02", &flt_interval); + if (ret != 0) + { + printf("FAULT02::The parameter tmp_faultCheckInterval is not defined, defaulted to 60 seconds\n"); + flt_interval = 60; + } + + ret = getStringToken(js, tokens, numToken, "reportingEntityName", "tmp_directParameters", reportEName, BUFSIZE); + if (ret != 0) + { + printf("FAULT02::Missing mandatory parameters - reportingEntityName is not there in tmp_directParameters\n"); + printf("FAULT02::Defaulting reportingEntityName to hostname\n"); + strcpy(reportEName, hostname); + } + ret = getStringToken(js, tokens, numToken, "sourceName", "tmp_directParameters", srcName, BUFSIZE); + if (ret != 0) + { + printf("FAULT02::Missing mandatory parameters - sourceName is not there in tmp_directParameters\n"); + printf("FAULT02::Defaulting sourceName to hostname\n"); + strcpy(srcName, hostname); + } + + ret = getStringToken(js, tokens, numToken, "priority", "tmp_directParameters", prio, BUFSIZE); + if (ret != 0) + { + printf("FAULT02::Missing mandatory parameters - priority is not there in tmp_directParameters\nDefaulting priority to Low\n"); + strcpy(prio, "Medium"); + } + priority = get_priority(prio); + if(priority == -1) + { + printf("FAULT02::Fault priority value is not matching, prioirty-%s \n", prio); + exit(1); + } + + ret = getStringTokenV2(js, tokens, numToken, "specificProblem", "tmp_alarmClearParameters", "tmp_faultInstance02", specProb, BUFSIZE); + if (ret != 0) + { + printf("FAULT02::Missing mandatory parameters - specificProblem is not there in tmp_alarmClearParameters, exiting ...\n"); + exit(1); + } + + ret = getStringTokenV2(js, tokens, numToken, "alarmCondition", "tmp_alarmClearParameters", "tmp_faultInstance02", alarmCondn, BUFSIZE); + if (ret != 0) + { + printf("FAULT02::Missing mandatory parameters - alarmCondition is not there in tmp_alarmClearParameters, exiting ...\n"); + exit(1); + } + + ret = getStringTokenV2(js, tokens, numToken, "eventSeverity", "tmp_alarmClearParameters", "tmp_faultInstance02", eventSev, BUFSIZE); + if (ret != 0) + { + printf("FAULT02::Missing mandatory parameters - eventSeverity is not there in tmp_alarmClearParameters\n"); + printf("FAULT02::Defaulting eventSeverity to MAJOR\n"); + strcpy(eventSev, "NORMAL"); + } + eSev = get_severity(eventSev); + if(eSev == -1) + { + printf("FAULT02::Fault eventSeverity value is not matching, eventSeverity-%s \n", eventSev); + exit(1); + } + + fault = evel_new_fault(eName, event_id, alarmCondn, + specProb, priority, eSev, srcTyp,vfStat); + if (fault != NULL) + { + fault_raised = 0; + + struct timeval tv_now; + gettimeofday(&tv_now, NULL); + epoch_now = tv_now.tv_usec + 1000000 * tv_now.tv_sec; + + fault_header = (EVENT_HEADER *)fault; + evel_fault_category_set(fault, eCategory); + if (aInterface != NULL) + evel_fault_interface_set(fault, aInterface); + + if (eType != NULL) + evel_fault_type_set(fault, eType); + + evel_start_epoch_set(&fault->header, last_epoch); + evel_last_epoch_set(&fault->header, epoch_now); + last_epoch = 0; + + if(nfcCode != NULL) + evel_nfcnamingcode_set(&fault->header, nfcCode); + if(nfCode != NULL) + evel_nfnamingcode_set(&fault->header, nfCode); + evel_reporting_entity_name_set(&fault->header, reportEName); + if(reportEId != NULL) + evel_reporting_entity_id_set(&fault->header, reportEId); + if(srcId != NULL ) + evel_source_id_set(&fault->header, srcId); + if(srcName!= NULL ) + evel_source_name_set(&fault->header, srcName); + + evel_rc = evel_post_event(fault_header); + + if(evel_rc == EVEL_SUCCESS) { + printf("FAULT02::Fault event is correctly sent to the collector!\n"); + } + else { + printf("FAULT02::Post failed %d (%s)\n", evel_rc, evel_error_string()); + } + } + else { + printf("FAULT02::New fault failed (%s)\n", evel_error_string()); + } + + } + + sleep(flt_interval); + } + + /***************************************************************************/ + /* Terminate */ + /***************************************************************************/ + sleep(1); +} + +void *FaultThread03(void *faultInstanceTag) +{ + sleep(4); + printf("FAULT03::thread created\n"); + fflush(stdout); + while (1) + { sleep (100); } +} + diff --git a/vnfs/VES5.0/evel/evel-library/code/VESreporting_syslog/LICENSE.TXT b/vnfs/VES5.0/evel/evel-library/code/VESreporting_syslog/LICENSE.TXT new file mode 100644 index 00000000..16285cd2 --- /dev/null +++ b/vnfs/VES5.0/evel/evel-library/code/VESreporting_syslog/LICENSE.TXT @@ -0,0 +1,22 @@ +/* + * ============LICENSE_START========================================== + * =================================================================== + * Copyright © 2017 AT&T Intellectual Property. All rights reserved. + * =================================================================== + * Unless otherwise specified, all software contained herein is + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END============================================ + * + * ECOMP is trademark and service mark of AT&T Intellectual Property. + * + */ diff --git a/vnfs/VES5.0/evel/evel-library/code/VESreporting_syslog/Makefile b/vnfs/VES5.0/evel/evel-library/code/VESreporting_syslog/Makefile new file mode 100644 index 00000000..4b0fd85d --- /dev/null +++ b/vnfs/VES5.0/evel/evel-library/code/VESreporting_syslog/Makefile @@ -0,0 +1,52 @@ +############################################################################# +# +# Copyright © 2019 AT&T Intellectual Property. All rights reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +############################################################################# + +CC=gcc +ARCH=$(shell getconf LONG_BIT) +CODE_ROOT=$(CURDIR)/../.. +#CODE_ROOT=../code/evel-library +LIBS_DIR=$(CODE_ROOT)/libs/x86_$(ARCH) +#LIBS_DIR=/usr/lib +INCLUDE_DIR= -I $(CODE_ROOT)/code/evel_library -I . + +#****************************************************************************** +# Standard compiler flags. * +#****************************************************************************** +CPPFLAGS= +CFLAGS=-Wall -g -fPIC +FILEOBJLIST= jsmn.o ves_syslog_reporter.o + +all: ves_syslog_reporter + +clean: + rm -f *.o ves_syslog_reporter + +%.o: %.c + $(CC) $(CPPFLAGS) $(CFLAGS) $(INCLUDE_DIR) -c $< -o $@ + +jsmn.o: jsmn.c jsmn.h +ves_syslog_reporter.o: ves_syslog_reporter.c + +ves_syslog_reporter: $(FILEOBJLIST) + $(CC) $(CPPFLAGS) $(CFLAGS) -o ves_syslog_reporter \ + -L $(LIBS_DIR) \ + $(FILEOBJLIST) \ + -lpthread \ + -level \ + -lcurl + + diff --git a/vnfs/VES5.0/evel/evel-library/code/VESreporting_syslog/README.md b/vnfs/VES5.0/evel/evel-library/code/VESreporting_syslog/README.md new file mode 100644 index 00000000..9aecc2ac --- /dev/null +++ b/vnfs/VES5.0/evel/evel-library/code/VESreporting_syslog/README.md @@ -0,0 +1,37 @@ + +PROJECT DESCRIPTION + +--- +This project contains the source code and scripts for the generation of syslog events. The folder contains: + + - README.md: this file. + + - LICENSE.TXT: the license text. + + - ves_syslog_reporter.c and other .c files: source code that uses the ECOMP Vendor Event Listener Library (VES) to generate the syslog events. Syslog events are generated based on /var/log/syslog entries. If a specific pattern is observed in the syslog file, then it generates the syslog event. The application reads syslog_config.json file for parameter values and poppulate the syslog event. If eventName, eventSourceType, syslogTag and tmp_syslogFile parameter value is not given, the application terminates. If reportingEntityName and/or sourceName parameter values are not given, then it gets the hostname and poppulates it. + + - Makefile: makefile that compiles ves_syslog_reporter.c and generates ves_syslog_reporter binary. + + - go-client.sh/go-client_2_collectors.sh: bash script that starts up the ves_syslog_reporter. It reads input parameters like DCAE IP address and port from configuration files contained in /opt/config. Based on the collector configuration, use go-client.sh for single collector configuration, or use go-client_2_collectors.sh for 2 collectors configuration. + + +USAGE +----- + +Update the configuration files with proper parameters values so that events generated would contain those values + +To run the ves_syslog_reporter in single collector configuration, please execute the following steps: + + - Make the go-client.sh script executable + chmod +x go-client.sh + + - Run the go-client.sh script + ./go-client.sh + +For 2 collectors configuration, please execute following steps: + + - Make the go-client.sh script executable + chmod +x go-client_2_collectors.sh + + - Run the go-client_2_collectors.sh script + ./go-client_2_collectors.sh diff --git a/vnfs/VES5.0/evel/evel-library/code/VESreporting_syslog/dep.xml b/vnfs/VES5.0/evel/evel-library/code/VESreporting_syslog/dep.xml new file mode 100644 index 00000000..fc18229f --- /dev/null +++ b/vnfs/VES5.0/evel/evel-library/code/VESreporting_syslog/dep.xml @@ -0,0 +1,25 @@ +<assembly xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.2" + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.2 http://maven.apache.org/xsd/assembly-1.1.2.xsd"> + <id>demo</id> + <formats> + <format>tar.gz</format> + </formats> + <fileSets> + + <fileSet> + <directory>.</directory> + <outputDirectory>/</outputDirectory> + <includes> + <include>*.sh</include> + <include>*.md</include> + <include>*.TXT</include> + <include>*.c</include> + <include>Makefile</include> + </includes> + </fileSet> + + </fileSets> +</assembly> + + diff --git a/vnfs/VES5.0/evel/evel-library/code/VESreporting_syslog/go-client.sh b/vnfs/VES5.0/evel/evel-library/code/VESreporting_syslog/go-client.sh new file mode 100755 index 00000000..0701456a --- /dev/null +++ b/vnfs/VES5.0/evel/evel-library/code/VESreporting_syslog/go-client.sh @@ -0,0 +1,6 @@ +#!/bin/bash + +export LD_LIBRARY_PATH="/opt/VES/evel/evel-library/libs/x86_64/" +DCAE_COLLECTOR_IP=$(cat /opt/config/dcae_collector_ip.txt) +DCAE_COLLECTOR_PORT=$(cat /opt/config/dcae_collector_port.txt) +./ves_syslog_reporter $DCAE_COLLECTOR_IP $DCAE_COLLECTOR_PORT diff --git a/vnfs/VES5.0/evel/evel-library/code/VESreporting_syslog/go-client_2_collectors.sh b/vnfs/VES5.0/evel/evel-library/code/VESreporting_syslog/go-client_2_collectors.sh new file mode 100755 index 00000000..492d76d2 --- /dev/null +++ b/vnfs/VES5.0/evel/evel-library/code/VESreporting_syslog/go-client_2_collectors.sh @@ -0,0 +1,12 @@ +#!/bin/bash + +export LD_LIBRARY_PATH="/opt/VES/evel/evel-library/libs/x86_64/" + +#Usage for 2 collectors: +#./ves_syslog_reporter <FQDN>|<IP address> <port> <FQDN>|<IP address> <port> + +DCAE_COLLECTOR_IP=$(cat /opt/config/dcae_collector_ip.txt) +DCAE_COLLECTOR_PORT=$(cat /opt/config/dcae_collector_port.txt) +DCAE_COLLECTOR_IP2=$(cat /opt/config/dcae_collector_ip2.txt) +DCAE_COLLECTOR_PORT2=$(cat /opt/config/dcae_collector_port2.txt) +./ves_syslog_reporter $DCAE_COLLECTOR_IP $DCAE_COLLECTOR_PORT $DCAE_COLLECTOR_IP2 $DCAE_COLLECTOR_PORT2 diff --git a/vnfs/VES5.0/evel/evel-library/code/VESreporting_syslog/jsmn.c b/vnfs/VES5.0/evel/evel-library/code/VESreporting_syslog/jsmn.c new file mode 100644 index 00000000..1d72ba4d --- /dev/null +++ b/vnfs/VES5.0/evel/evel-library/code/VESreporting_syslog/jsmn.c @@ -0,0 +1,672 @@ +/*************************************************************************//** + * + * Copyright © 2017 AT&T Intellectual Property. All rights reserved. + * + * Unless otherwise specified, all software contained herein is + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ECOMP is a trademark and service mark of AT&T Intellectual Property. + ****************************************************************************/ +#include<stdio.h> +#include<stdlib.h> +#include<string.h> +#include "jsmn.h" + +/** + * Allocates a fresh unused token from the token pull. + */ +static jsmntok_t *jsmn_alloc_token(jsmn_parser *parser, + jsmntok_t *tokens, size_t num_tokens) { + jsmntok_t *tok; + if (parser->toknext >= num_tokens) { + return NULL; + } + tok = &tokens[parser->toknext++]; + tok->start = tok->end = -1; + tok->size = 0; +//#ifdef JSMN_PARENT_LINKS + tok->parent = -1; +//#endif + return tok; +} + +/** + * Fills token type and boundaries. + */ +static void jsmn_fill_token(jsmntok_t *token, jsmntype_t type, + int start, int end) { +//printf("jsmn_fill_token:: start-%d, end-%d\n", start, end); + token->type = type; + token->start = start; + token->end = end; + token->size = 0; +} + +/** + * Fills next available token with JSON primitive. + */ +static int jsmn_parse_primitive(jsmn_parser *parser, const char *js, + size_t len, jsmntok_t *tokens, size_t num_tokens) { + jsmntok_t *token; + int start; + + start = parser->pos; + + for (; parser->pos < len && js[parser->pos] != '\0'; parser->pos++) { +//printf("jsmn_parse_primitive:: the char is - %c\n", js[parser->pos]); + switch (js[parser->pos]) { +#ifndef JSMN_STRICT + /* In strict mode primitive must be followed by "," or "}" or "]" */ + case ':': +#endif + case '\t' : case '\r' : case '\n' : case ' ' : + case ',' : case ']' : case '}' : + goto found; + } + if (js[parser->pos] < 32 || js[parser->pos] >= 127) { + parser->pos = start; + return JSMN_ERROR_INVAL; + } + } +#ifdef JSMN_STRICT + /* In strict mode primitive must be followed by a comma/object/array */ + parser->pos = start; + return JSMN_ERROR_PART; +#endif + +found: + if (tokens == NULL) { + parser->pos--; + return 0; + } + token = jsmn_alloc_token(parser, tokens, num_tokens); + if (token == NULL) { + parser->pos = start; + return JSMN_ERROR_NOMEM; + } + jsmn_fill_token(token, JSMN_PRIMITIVE, start, parser->pos); +//#ifdef JSMN_PARENT_LINKS + token->parent = parser->toksuper; +//#endif + parser->pos--; + return 0; +} + +/** + * Fills next token with JSON string. + */ +static int jsmn_parse_string(jsmn_parser *parser, const char *js, + size_t len, jsmntok_t *tokens, size_t num_tokens) { + jsmntok_t *token; + + int start = parser->pos; + + parser->pos++; + + /* Skip starting quote */ + for (; parser->pos < len && js[parser->pos] != '\0'; parser->pos++) { + char c = js[parser->pos]; + char d = js[parser->pos + 1]; +// char e = js[parser->pos + 2]; +//printf("jsmn_parse_string: value-%c, pos-%d\n", c,parser->pos); + + /* Quote: end of string */ +// if (c == '\"') { + if (d == '\"') { +// if ((d == '\"')&&((e == ' ')||(e == ','))) { +parser->pos++; +//printf("jsmn_parse_string: end of string\n"); + if (tokens == NULL) { +//printf("jsmn_parse_string: end tokens is NULL\n"); + return 0; + } + token = jsmn_alloc_token(parser, tokens, num_tokens); +//printf("jsmn_parse_string: Allocated tokens \n"); + if (token == NULL) { +//printf("jsmn_parse_string: Allocated tokens is NULL\n"); + parser->pos = start; + return JSMN_ERROR_NOMEM; + } + jsmn_fill_token(token, JSMN_STRING, start+1, parser->pos); +//printf("jsmn_parse_string: Allocated tokens is filled\n"); +//#ifdef JSMN_PARENT_LINKS + token->parent = parser->toksuper; +//#endif + return 0; + } + + /* Backslash: Quoted symbol expected */ + if (c == '\\' && parser->pos + 1 < len) { + int i; + parser->pos++; +//printf("jsmn_parse_string: value - %c, POS-%3d \n",c, js[parser->pos]); + switch (js[parser->pos]) { + /* Allowed escaped symbols */ + case '\"': case '/' : case '\\' : case 'b' : + case 'f' : case 'r' : case 'n' : case 't' : + break; + /* Allows escaped symbol \uXXXX */ + case 'u': + parser->pos++; + for(i = 0; i < 4 && parser->pos < len && js[parser->pos] != '\0'; i++) { + /* If it isn't a hex character we have an error */ + if(!((js[parser->pos] >= 48 && js[parser->pos] <= 57) || /* 0-9 */ + (js[parser->pos] >= 65 && js[parser->pos] <= 70) || /* A-F */ + (js[parser->pos] >= 97 && js[parser->pos] <= 102))) { /* a-f */ + parser->pos = start; + return JSMN_ERROR_INVAL; + } + parser->pos++; + } + parser->pos--; + break; + /* Unexpected symbol */ + default: + parser->pos = start; + return JSMN_ERROR_INVAL; + } + } + } + parser->pos = start; +printf("jsmn_parse_string: exiting with ERROR_PART, pos-%d", parser->pos); + return JSMN_ERROR_PART; +} + +/** + * Parse JSON string and fill tokens. + */ +int jsmn_parse(jsmn_parser *parser, const char *js, size_t len, + jsmntok_t *tokens, unsigned int num_tokens) { + int r; + int i; + jsmntok_t *token; + int count = parser->toknext; + + for (; parser->pos < len && js[parser->pos] != '\0'; parser->pos++) { + char c; + jsmntype_t type; + + c = js[parser->pos]; +//printf("jsmn_parse: value of c - %c\n",c); + switch (c) { + case '{': case '[': + count++; + if (tokens == NULL) { + break; + } + token = jsmn_alloc_token(parser, tokens, num_tokens); + if (token == NULL) + return JSMN_ERROR_NOMEM; + if (parser->toksuper != -1) { + tokens[parser->toksuper].size++; +//#ifdef JSMN_PARENT_LINKS + token->parent = parser->toksuper; +//#endif + } + token->type = (c == '{' ? JSMN_OBJECT : JSMN_ARRAY); + token->start = parser->pos; + parser->toksuper = parser->toknext - 1; + break; + case '}': case ']': + if (tokens == NULL) + break; + type = (c == '}' ? JSMN_OBJECT : JSMN_ARRAY); +//#ifdef JSMN_PARENT_LINKS + if (parser->toknext < 1) { + return JSMN_ERROR_INVAL; + } + token = &tokens[parser->toknext - 1]; + for (;;) { + if (token->start != -1 && token->end == -1) { + if (token->type != type) { + return JSMN_ERROR_INVAL; + } + token->end = parser->pos + 1; + parser->toksuper = token->parent; + break; + } + if (token->parent == -1) { + break; + } + token = &tokens[token->parent]; + } +//#else +// for (i = parser->toknext - 1; i >= 0; i--) { +// token = &tokens[i]; +// if (token->start != -1 && token->end == -1) { +// if (token->type != type) { +// return JSMN_ERROR_INVAL; +// } +// parser->toksuper = -1; +// token->end = parser->pos + 1; +// break; +// } +// } +// /* Error if unmatched closing bracket */ +// if (i == -1) return JSMN_ERROR_INVAL; +// for (; i >= 0; i--) { +// token = &tokens[i]; +// if (token->start != -1 && token->end == -1) { +// parser->toksuper = i; +// break; +// } +// } +//#endif + break; + case '\"': + r = jsmn_parse_string(parser, js, len, tokens, num_tokens); + if (r < 0) return r; + count++; + if (parser->toksuper != -1 && tokens != NULL) + tokens[parser->toksuper].size++; + break; + case '\t' : case '\r' : case '\n' : case ' ': + break; + case ':': + parser->toksuper = parser->toknext - 1; +//printf("jsmn_parse: value of c is :: - %c\n",c); + break; + case ',': + if (tokens != NULL && parser->toksuper != -1 && + tokens[parser->toksuper].type != JSMN_ARRAY && + tokens[parser->toksuper].type != JSMN_OBJECT) { +//#ifdef JSMN_PARENT_LINKS + parser->toksuper = tokens[parser->toksuper].parent; +//#else +// for (i = parser->toknext - 1; i >= 0; i--) { +// if (tokens[i].type == JSMN_ARRAY || tokens[i].type == JSMN_OBJECT) { +// if (tokens[i].start != -1 && tokens[i].end == -1) { +// parser->toksuper = i; +// break; +// } +// } +// } +//#endif + } + break; +#ifdef JSMN_STRICT + /* In strict mode primitives are: numbers and booleans */ + case '-': case '0': case '1' : case '2': case '3' : case '4': + case '5': case '6': case '7' : case '8': case '9': + case 't': case 'f': case 'n' : + /* And they must not be keys of the object */ + if (tokens != NULL && parser->toksuper != -1) { + jsmntok_t *t = &tokens[parser->toksuper]; + if (t->type == JSMN_OBJECT || + (t->type == JSMN_STRING && t->size != 0)) { + return JSMN_ERROR_INVAL; + } + } +#else + /* In non-strict mode every unquoted value is a primitive */ + default: +#endif + r = jsmn_parse_primitive(parser, js, len, tokens, num_tokens); + if (r < 0) return r; + count++; + if (parser->toksuper != -1 && tokens != NULL) + tokens[parser->toksuper].size++; + break; + +#ifdef JSMN_STRICT + /* Unexpected char in strict mode */ + default: + return JSMN_ERROR_INVAL; +#endif + } + } + + if (tokens != NULL) { + for (i = parser->toknext - 1; i >= 0; i--) { +//printf("index -%2d, start is %3d, end is %3d\n", i, tokens[i].start, tokens[i].end); + /* Unmatched opened object or array */ + if (tokens[i].start != -1 && tokens[i].end == -1) { + return JSMN_ERROR_PART; + } + } + } + + return count; +} + +/** + * Creates a new parser based over a given buffer with an array of tokens + * available. + */ +void jsmn_init(jsmn_parser *parser) { + parser->pos = 0; + parser->toknext = 0; + parser->toksuper = -1; +} + +int jsoneq(const char *json, jsmntok_t *tok, const char *s) +{ + if (tok->type == JSMN_STRING && (int) strlen(s) == tok->end - tok->start && + strncmp(json + tok->start, s, tok->end - tok->start) == 0) { + return 0; + } + return -1; +} + +void printToken(char * js, jsmntok_t * tokens, int numToken) +{ + for (int i = 1; i < numToken; i++) + { + printf("Token number-%2d, parent-%2d, type-%d size-%2d, parameter -", i, tokens[i].parent, tokens[i].type, tokens[i].size); + if (tokens[i].type == JSMN_STRING || tokens[i].type == JSMN_PRIMITIVE) { + printf("%.*s\n", tokens[i].end - tokens[i].start, js + tokens[i].start); + } else if (tokens[i].type == JSMN_ARRAY) { + printf("[%d elems]\n", tokens[i].size); + } else if (tokens[i].type == JSMN_OBJECT) { + printf("{%d elems}\n", tokens[i].size); + } else { + printf("value?? - "); + TOKEN_PRINT(tokens[i]); + } + } +} + +int getStringToken(char * js, jsmntok_t * tokens, int numToken, char * param, char * pParam, char * value, int maxValueSize) +{ + int i = 0; + int dpToken = 0; + + memset(value, 0, maxValueSize); + + for (i = 1; i < numToken; i++) + { + if(jsoneq(js, &tokens[i], pParam) == 0) + break; + } + if (i < numToken) + { + dpToken = ++i; + } + else + { + printf("The parameter %s is not present in JSON file\n", pParam); + return 1; //Parent token not seen + } + for (i=1; i < numToken; i++) + { + if (tokens[i].parent == dpToken && tokens[i].type == JSMN_STRING && tokens[i].size == 1) + { + if(jsoneq(js, &tokens[i], param) != 0) + continue; + TOKEN_COPY(js, tokens[i+1], value); + + return 0; //Success + } + } + printf("The parameter %s is not present in JSON file\n", param); + return 2; //parameter not found +} + + +int getStringTokenV2(char * js, jsmntok_t * tokens, int numToken, char * param, char * pParam, char * gParam,char * value, int maxValueSize) +{ + int i = 0; + int dpToken = 0; + + memset(value, 0, maxValueSize); + + for (i = 1; i < numToken; i++) + { + if(jsoneq(js, &tokens[i], gParam) == 0) + break; + } + if (i < numToken) + { + dpToken = ++i; + } + else + { + printf("The parameter %s is not present in JSON file\n", pParam); + return 1; //Grand Parent token not seen + } + + for (i=dpToken; i < numToken; i++) + { + if (tokens[i].parent == dpToken && tokens[i].type == JSMN_STRING && tokens[i].size == 1) + { + if(jsoneq(js, &tokens[i], pParam) == 0) + break; + } + } + if (i < numToken) + { + dpToken = ++i; + } + else + { + printf("The parameter %s is not present in JSON file\n", pParam); + return 2; //Parent token not seen + } + + for (i=dpToken; i < numToken; i++) + { + if (tokens[i].parent == dpToken && tokens[i].type == JSMN_STRING && tokens[i].size == 1) + { + if(jsoneq(js, &tokens[i], param) != 0) + continue; + TOKEN_COPY(js, tokens[i+1], value); + + return 0; //Success + } + } + + printf("The parameter %s is not present in JSON file\n", param); + return 2; //parameter not found +} + +int getIntToken(char * js, jsmntok_t * tokens, int numToken, char * param, char * pParam, int * value) +{ + int i = 0; + int dpToken = 0; + char val[128]; + + memset(val, 0, 128); + for (i = 1; i < numToken; i++) + { + if(jsoneq(js, &tokens[i], pParam) == 0) + break; + } + if (i < numToken) + { + dpToken = ++i; + } + else + { + printf("The parameter %s is not present in JSON file\n", pParam); + return 1; //Parent token not seen + } + for (i=1; i < numToken; i++) + { + if (tokens[i].parent == dpToken && tokens[i].type == JSMN_STRING && tokens[i].size == 1) + { + if(jsoneq(js, &tokens[i], param) != 0) + { + continue; + } + + if(tokens[i+1].type != JSMN_PRIMITIVE) + return 3; //Wrong parameter type + +// printf("INT parameter / Value - %s", param); + TOKEN_COPY(js, tokens[i+1], val); + *value = atoi(val); +// printf(" - %d\n", *value); + + return 0; //success + } + } + printf("The parameter %s is not present in JSON file\n", param); + return 2; //parameter not found +} + +void parseDirectParameters(char * js, jsmntok_t * tokens, int numToken) +{ + int i = 0; + int dpToken = 0; + char param[128]; + char value[128]; + + for (i = 1; i < numToken; i++) + { + if(jsoneq(js, &tokens[i], "directParameters") == 0) + break; + } + + if (i < numToken) + { + dpToken = ++i; + } + + for (int i = 1; i < numToken; i++) + { + memset(param, 0, 128); + memset(value, 0, 128); + if (tokens[i].parent == dpToken && tokens[i].type == JSMN_STRING && tokens[i].size == 1) + { + TOKEN_COPY(js, tokens[i], param); +// printf("parameter / Value - %s", param); + TOKEN_COPY(js, tokens[i+1], value); +// printf(" - %s\n", value); + } + } +} + +int getArrayTokens(char * js, jsmntok_t * tokens, int numToken, char * param, char * pParam, ARRAYVAL * arrayValue, int * numElements) +{ + int i = 0; + int dpToken = 0; + + for (i = 1; i < numToken; i++) + { + if(jsoneq(js, &tokens[i], pParam) == 0) + break; + } + if (i < numToken) + { + dpToken = ++i; + } + else + { + printf("The parameter %s is not present in JSON file\n", pParam); + return 1; //Parent token not seen + } + for (i=1; i < numToken; i++) + { + if (tokens[i].parent == dpToken && tokens[i].type == JSMN_STRING && tokens[i].size == 1) + { +// printf("value of token %d\n", i); + if(jsoneq(js, &tokens[i], param) != 0) + continue; + + if (tokens[i+1].type == JSMN_ARRAY) + { + *numElements = tokens[i+1].size; +// printf("[%d elems]\n", *numElements); + + for (int k = 0; k < *numElements; k++) + { + TOKEN_COPY(js, tokens[i+2+k], arrayValue[k].arrayString); +// printf(" - %s\n", arrayValue[k].arrayString); + } + return 0; //Success + } + } + } + printf("The parameter %s is not present in JSON file\n", param); + return 2; //parameter not found +} + +int isTokenPresent(char * js, jsmntok_t * tokens, int numToken, char * param, char * pParam) +{ + int i = 0; + int dpToken = 0; + char val[128]; + + memset(val, 0, 128); + for (i = 1; i < numToken; i++) + { + if(jsoneq(js, &tokens[i], pParam) == 0) + break; + } + if (i < numToken) + { + dpToken = ++i; + } + else + { + printf("The parameter %s is not present in JSON file\n", pParam); + return 1; //Parent token not seen + } + for (i=1; i < numToken; i++) + { + if (tokens[i].parent == dpToken && tokens[i].type == JSMN_STRING) + { + if(jsoneq(js, &tokens[i], param) == 0) + { + return 0; //Token present + } + } + } + printf("The parameter %s is not present in JSON file\n", param); + return 2; //Token Not present +} + +int read_keyVal_params(char * js, jsmntok_t * tokens, int numToken, char * param, char * pParam, KEYVALRESULT * keyValueResultList, int * numElements) +{ + int i = 0; + int dpToken = 0; + + for (i = 1; i < numToken; i++) + { + if(jsoneq(js, &tokens[i], pParam) == 0) + break; + } + if (i < numToken) + { + dpToken = ++i; + } + else + { + printf("The parameter %s is not present in JSON file\n", pParam); + return 1; //Parent token not seen + } + for (i=1; i < numToken; i++) + { + if (tokens[i].parent == dpToken && tokens[i].type == JSMN_STRING && tokens[i].size == 1) + { +// printf("value of token %d\n", i); + if(jsoneq(js, &tokens[i], param) != 0) + continue; + + if (tokens[i+1].type == JSMN_OBJECT) + { + *numElements = tokens[i+1].size; +// printf("{%d elems}\n", *numElements); + + for (int k = 0; k < *numElements; k++) + { + TOKEN_COPY(js, tokens[i+2+k*2], keyValueResultList[k].keyStr); +// printf("Key - %s", keyValueResultList[k].keyStr); + TOKEN_COPY(js, tokens[i+3+k*2], keyValueResultList[k].valStr); +// printf("Value - %s\n", keyValueResultList[k].valStr); + } + return 0; //Success + } + } + } + printf("The parameter %s is not present in JSON file\n", param); + return 2; //parameter not found +} diff --git a/vnfs/VES5.0/evel/evel-library/code/VESreporting_syslog/jsmn.h b/vnfs/VES5.0/evel/evel-library/code/VESreporting_syslog/jsmn.h new file mode 100644 index 00000000..f9d838b6 --- /dev/null +++ b/vnfs/VES5.0/evel/evel-library/code/VESreporting_syslog/jsmn.h @@ -0,0 +1,136 @@ +/*************************************************************************//** + * + * Copyright © 2017 AT&T Intellectual Property. All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + ****************************************************************************/ + +#ifndef __JSMN_H_ +#define __JSMN_H_ + +#include <stddef.h> + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * JSON type identifier. Basic types are: + * o Object + * o Array + * o String + * o Other primitive: number, boolean (true/false) or null + */ +typedef enum { + JSMN_UNDEFINED = 0, + JSMN_OBJECT = 1, + JSMN_ARRAY = 2, + JSMN_STRING = 3, + JSMN_PRIMITIVE = 4 +} jsmntype_t; + +enum jsmnerr { + /* Not enough tokens were provided */ + JSMN_ERROR_NOMEM = -1, + /* Invalid character inside JSON string */ + JSMN_ERROR_INVAL = -2, + /* The string is not a full JSON packet, more bytes expected */ + JSMN_ERROR_PART = -3 +}; + +typedef struct arrayValues { + char arrayString[32]; +} ARRAYVAL; + +typedef struct keyValResult { + char keyStr[80]; + char valStr[250]; + char resultStr[80]; +} KEYVALRESULT; + +/** + * JSON token description. + * @param type type (object, array, string etc.) + * @param start start position in JSON data string + * @param end end position in JSON data string + */ +typedef struct { + jsmntype_t type; + int start; + int end; + int size; +//#ifdef JSMN_PARENT_LINKS + int parent; +//#endif +} jsmntok_t; + +/** + * JSON parser. Contains an array of token blocks available. Also stores + * the string being parsed now and current position in that string + */ +typedef struct { + unsigned int pos; /* offset in the JSON string */ + unsigned int toknext; /* next token to allocate */ + int toksuper; /* superior token node, e.g parent object or array */ +} jsmn_parser; + +#define TOKEN_EQ(t, tok_start, tok_end, tok_type) \ + ((t).start == tok_start \ + && (t).end == tok_end \ + && (t).type == (tok_type)) + +#define TOKEN_STRING(js, t, s) \ + (strncmp(js+(t).start, s, (t).end - (t).start) == 0 \ + && strlen(s) == (t).end - (t).start) + +#define TOKEN_COPY(js, t, s) \ + strncpy(s, js+(t).start, (t).end - (t).start) + +#define TOKEN_PRINT(t) \ + printf("start: %d, end: %d, type: %d, size: %d\n", \ + (t).start, (t).end, (t).type, (t).size) + + +/** + * Create JSON parser over an array of tokens + */ +void jsmn_init(jsmn_parser *parser); + +/** + * Run JSON parser. It parses a JSON data string into and array of tokens, each describing + * a single JSON object. + */ +int jsmn_parse(jsmn_parser *parser, const char *js, size_t len, + jsmntok_t *tokens, unsigned int num_tokens); + +int jsoneq(const char *json, jsmntok_t *tok, const char *s); + +void printToken(char * js, jsmntok_t * tokens, int numToken); + +int getStringToken(char * js, jsmntok_t * tokens, int numToken, char * param, char * pParam, char * value, int maxValueSize); + +int getIntToken(char * js, jsmntok_t * tokens, int numToken, char * param, char * pParam, int * value); + +int getArrayTokens(char * js, jsmntok_t * tokens, int numToken, char * param, char * pParam, ARRAYVAL * arrayValue, int * numElements); + +int isTokenPresent(char * js, jsmntok_t * tokens, int numToken, char * param, char * pParam); + +int read_keyVal_params(char * js, jsmntok_t * tokens, int numToken, char * param, char * pParam, KEYVALRESULT * keyValueResultList, int * numElements); + +int getStringTokenV2(char * js, jsmntok_t * tokens, int numToken, char * param, char * pParam, char *gParam, char * value, int maxValueSize); + +#ifdef __cplusplus +} +#endif + +#endif /* __JSMN_H_ */ diff --git a/vnfs/VES5.0/evel/evel-library/code/VESreporting_syslog/pom.xml b/vnfs/VES5.0/evel/evel-library/code/VESreporting_syslog/pom.xml new file mode 100644 index 00000000..f9f42ebb --- /dev/null +++ b/vnfs/VES5.0/evel/evel-library/code/VESreporting_syslog/pom.xml @@ -0,0 +1,83 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- + ============LICENSE_START========================================== + =================================================================== + Copyright © 2017 AT&T Intellectual Property. All rights reserved. + =================================================================== + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + ============LICENSE_END============================================ + + ECOMP and OpenECOMP are trademarks + and service marks of AT&T Intellectual Property. +--> +<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> + +<parent> + <groupId>org.onap.demo.vnf</groupId> + <artifactId>demo-aggregator</artifactId> + <version>1.2.0-SNAPSHOT</version> + <relativePath>../../pom.xml</relativePath> + </parent> + + <modelVersion>4.0.0</modelVersion> + <groupId>org.onap.demo.vnf.ves5</groupId> + <artifactId>ves_vfw_reporting</artifactId> + + <build> + <plugins> + + <plugin> + <artifactId>maven-jar-plugin</artifactId> + <version>2.3.2</version> + <executions> + <execution> + <id>default-jar</id> + <phase>never</phase> + </execution> + </executions> + </plugin> + + <plugin> + <artifactId>maven-assembly-plugin</artifactId> + <version>2.5.3</version> + <configuration> + <descriptor>dep.xml</descriptor> + </configuration> + <executions> + <execution> + <id>create-archive</id> + <phase>package</phase> + <goals> + <goal>single</goal> + </goals> + </execution> + </executions> + </plugin> + + <plugin> + <groupId>org.codehaus.mojo</groupId> + <artifactId>exec-maven-plugin</artifactId> + <executions> + <execution> + <phase>none</phase> + </execution> + </executions> + <configuration> + <skip>true</skip> + </configuration> + </plugin> + + </plugins> + </build> + +</project> diff --git a/vnfs/VES5.0/evel/evel-library/code/VESreporting_syslog/sample_syslog_event.txt b/vnfs/VES5.0/evel/evel-library/code/VESreporting_syslog/sample_syslog_event.txt new file mode 100644 index 00000000..3a6ec916 --- /dev/null +++ b/vnfs/VES5.0/evel/evel-library/code/VESreporting_syslog/sample_syslog_event.txt @@ -0,0 +1,30 @@ +{ + "event": { + "commonEventHeader": { + "domain": "syslog", + "eventId": "syslog000000000", + "eventName": "syslog_vFirewall-AT&T_connectionReset", + "eventType": "applicationVnf", + "lastEpochMicrosec": 1548493308853168, + "nfNamingCode": "AFX", + "nfcNamingCode": "AFX", + "priority": "Normal", + "reportingEntityId": "cc305d54-75b4-431b-adb2-eb6b9e541234", + "reportingEntityName": "ibcx0001vm002oam001", + "sequence": 0, + "sourceId": "de305d54-75b4-431b-adb2-eb6b9e546014", + "sourceName": "scfx0001vm002cap001", + "startEpochMicrosec": 1548493278782875, + "version": 3.0 + }, + "syslogFields": { + "eventSourceType": "virtualMachine", + "syslogFacility": 16, + "syslogFieldsVersion": 3.0, + "syslogMsg": "Jan 26 14:31:46 prakash-VirtualBox prakash: peer reset qwerty", + "syslogProc": "vSyslog", + "syslogTag": "peer reset" + } + } +} + diff --git a/vnfs/VES5.0/evel/evel-library/code/VESreporting_syslog/syslog_config.json b/vnfs/VES5.0/evel/evel-library/code/VESreporting_syslog/syslog_config.json new file mode 100644 index 00000000..6a434e43 --- /dev/null +++ b/vnfs/VES5.0/evel/evel-library/code/VESreporting_syslog/syslog_config.json @@ -0,0 +1,20 @@ +{ + "tmp_directParameters": { + "eventName": "syslog_vFirewall-AT&T_connectionReset", + "eventType": "applicationVnf", + "nfcNamingCode": "AFX", + "nfNamingCode": "AFX", + "nfVendorName": "AT&T", + "reportingEntityId": "cc305d54-75b4-431b-adb2-eb6b9e541234", + "reportingEntityName": "ibcx0001vm002oam001", + "sourceId": "de305d54-75b4-431b-adb2-eb6b9e546014", + "sourceName": "scfx0001vm002cap001", + "timeZoneOffset": "UTC-05:30", + "eventSourceType": "virtualMachine", + "syslogProc": "vSyslog", + "syslogTag": "peer reset" + }, + "tmp_indirectParameters": { + "tmp_syslogFile": "/var/log/syslog" + } +} diff --git a/vnfs/VES5.0/evel/evel-library/code/VESreporting_syslog/ves_syslog_reporter.c b/vnfs/VES5.0/evel/evel-library/code/VESreporting_syslog/ves_syslog_reporter.c new file mode 100644 index 00000000..b7226e74 --- /dev/null +++ b/vnfs/VES5.0/evel/evel-library/code/VESreporting_syslog/ves_syslog_reporter.c @@ -0,0 +1,375 @@ +/*************************************************************************//** + * + * Copyright © 2018 AT&T Intellectual Property. All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + ****************************************************************************/ + +#include <stdio.h> +#include <stdlib.h> +#include <unistd.h> +#include <pthread.h> +#include <string.h> +#include <netdb.h> +#include <sys/time.h> +#include <sys/stat.h> +#include "jsmn.h" +#include "evel.h" + +#define BUFSIZE 128 +#define MAX_BUFFER_SIZE 4096 +#define MAX_TOKENS 1000 + +void *SyslogThread(void *threadarg); + +unsigned long long epoch_start = 0; + +void report_syslog(char * js, jsmntok_t * tokens, int numToken, char * syslog_tag, char * eName, int srcTyp, char * syslog_msg) +{ + EVENT_HEARTBEAT_FIELD * event = NULL; + EVENT_HEADER* syslog_header = NULL; + EVEL_ERR_CODES evel_rc = EVEL_SUCCESS; + char stringVal[BUFSIZE]; + + char event_id1[10] = "syslog"; + char event_id2[15] = {0}; + int event_id3 = 0; + char event_id[BUFSIZE] = {0}; + + int ret = 0; + /***************************************************************************/ + /* Syslog */ + /***************************************************************************/ + memset(event_id, 0, BUFSIZE); + memset(event_id2, 0, 15); + sprintf(event_id2, "%09d", event_id3++); + strcat(event_id, event_id1); + strcat(event_id, event_id2); + + + event = evel_new_syslog(eName, event_id, srcTyp, syslog_msg, syslog_tag); + + if (event != NULL) + { + syslog_header = (EVENT_HEADER *)event; + + ret = getStringToken(js, tokens, numToken, "syslogProc", "tmp_directParameters", stringVal, BUFSIZE); + if (ret == 0) + evel_syslog_proc_set(event, stringVal); + evel_syslog_facility_set(event, EVEL_SYSLOG_FACILITY_LOCAL0); + ret = getStringToken(js, tokens, numToken, "eventType", "tmp_directParameters", stringVal, BUFSIZE); + if (ret == 0) + evel_header_type_set(&event->header, stringVal); + + struct timeval tv_now; + gettimeofday(&tv_now, NULL); + unsigned long long epoch_now = tv_now.tv_usec + 1000000 * tv_now.tv_sec; + + evel_start_epoch_set(&event->header, epoch_start); + evel_last_epoch_set(&event->header, epoch_now); + epoch_start = epoch_now; + + ret = getStringToken(js, tokens, numToken, "nfcNamingCode", "tmp_directParameters", stringVal, BUFSIZE); + if (ret == 0) + evel_nfcnamingcode_set(&event->header, stringVal); + + ret = getStringToken(js, tokens, numToken, "nfNamingCode", "tmp_directParameters", stringVal, BUFSIZE); + if (ret == 0) + evel_nfnamingcode_set(&event->header, stringVal); + + ret = getStringToken(js, tokens, numToken, "reportingEntityName", "tmp_directParameters", stringVal, BUFSIZE); + if (ret == 0) + evel_reporting_entity_name_set(&event->header, stringVal); + else + { + printf("Missing mandatory parameters - reportingEntityName is not there in tmp_directParameters\n"); + printf("Defaulting reportingEntityName to hostname\n"); + } + + ret = getStringToken(js, tokens, numToken, "reportingEntityId", "tmp_directParameters", stringVal, BUFSIZE); + if (ret == 0) + evel_reporting_entity_id_set(&event->header, stringVal); + + ret = getStringToken(js, tokens, numToken, "sourceId", "tmp_directParameters", stringVal, BUFSIZE); + if (ret == 0) + evel_source_id_set(&event->header, stringVal); + + ret = getStringToken(js, tokens, numToken, "sourceName", "tmp_directParameters", stringVal, BUFSIZE); + if (ret == 0) + evel_source_name_set(&event->header, stringVal); + else + { + printf("Missing mandatory parameters - sourceName is not there in tmp_directParameters\n"); + printf("Defaulting sourceName to hostname\n"); + } + + evel_rc = evel_post_event(syslog_header); + if (evel_rc != EVEL_SUCCESS) + { + EVEL_ERROR("Post failed %d (%s)", evel_rc, evel_error_string()); + } + } + else + { + EVEL_ERROR("New Syslog failed"); + } + printf(" Processed Syslog\n"); +} + +int get_source(char * inStr) +{ + int result = -1; + + if(strcmp(inStr, "other") == 0) + result = EVEL_SOURCE_OTHER; + else if(strcmp(inStr, "router") == 0) + result = EVEL_SOURCE_ROUTER; + else if(strcmp(inStr, "switch") == 0) + result = EVEL_SOURCE_SWITCH; + else if(strcmp(inStr, "host") == 0) + result = EVEL_SOURCE_HOST; + else if(strcmp(inStr, "card") == 0) + result = EVEL_SOURCE_CARD; + else if(strcmp(inStr, "port") == 0) + result = EVEL_SOURCE_PORT; + else if(strcmp(inStr, "slotThreshold") == 0) + result = EVEL_SOURCE_SLOT_THRESHOLD; + else if(strcmp(inStr, "portThreshold") == 0) + result = EVEL_SOURCE_PORT_THRESHOLD; + else if(strcmp(inStr, "virtualMachine") == 0) + result = EVEL_SOURCE_VIRTUAL_MACHINE; + else if(strcmp(inStr, "virtualNetworkFunction") == 0) + result = EVEL_SOURCE_VIRTUAL_NETWORK_FUNCTION; + + return result; +} + + +int main(int argc, char** argv) +{ + char* fqdn = argv[1]; + int port = atoi(argv[2]); + int i=0; + int rc; + pthread_attr_t attr; + pthread_t syslog_thread; + char* fqdn2 = NULL; + int port2 = 0; + + if(argc == 5) + { + fqdn2 = argv[3]; + port2 = atoi(argv[4]); + } + + if (!((argc == 3) || (argc == 5))) + { + fprintf(stderr, "Usage: %s <FQDN>|<IP address> <port> <FQDN>|<IP address> <port> \n", argv[0]); + fprintf(stderr, "OR\n"); + fprintf(stderr, "Usage: %s <FQDN>|<IP address> <port> \n", argv[0]); + exit(-1); + } + + /**************************************************************************/ + /* Initialize */ + /**************************************************************************/ + if(evel_initialize(fqdn, /* FQDN */ + port, /* Port */ + fqdn2, /* Backup FQDN */ + port2, /* Backup port */ + NULL, /* optional path */ + NULL, /* optional topic */ + 100, /* Ring Buffer size */ + 0, /* HTTPS? */ + NULL, /* cert file */ + NULL, /* key file */ + NULL, /* ca info */ + NULL, /* ca file */ + 0, /* verify peer */ + 0, /* verify host */ + "sample1", /* Username */ + "sample1", /* Password */ + "sample1", /* Username2 */ + "sample1", /* Password2 */ + NULL, /* Source ip */ + NULL, /* Source ip2 */ + EVEL_SOURCE_VIRTUAL_MACHINE, /* Source type */ + "vSyslog", /* Role */ + 1)) /* Verbosity */ + { + fprintf(stderr, "\nFailed to initialize the EVEL library!!!\n"); + exit(-1); + } + else + { + printf("\nInitialization completed\n"); + } + + /* Initialize and set thread detached attribute */ + pthread_attr_init(&attr); + pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED); + + printf("Main:Creating thread \n"); + rc = pthread_create(&syslog_thread, NULL, SyslogThread, &i); + if (rc) + { + printf("ERROR; return code from pthread_create() is %d\n", rc); + exit(-1); + } + printf("Main:Created Syslog thread \n"); + + pthread_join(syslog_thread, NULL); + + evel_terminate(); + printf("Terminated\n"); + return 0; +} + +void *SyslogThread(void *threadarg) +{ + + int numToken; + jsmntok_t tokens[MAX_TOKENS]; + char js[MAX_BUFFER_SIZE]; + FILE * fp; + jsmn_parser p; + char ch[BUFSIZE]; + int ret = 0; + char eName[BUFSIZE]; + char eventSrcTyp[BUFSIZE]; + char syslog_tag[BUFSIZE]; + char syslog_msg[8*BUFSIZE]; + char str[8*BUFSIZE]; + char syslog_file[BUFSIZE]; + int srcTyp = 0; + int count = 0; + unsigned long long pos; + unsigned long long prevpos = 0; + + sleep(1); + printf("Running Syslog thread \n"); + fflush(stdout); + + while(1) + { + + FILE * file = fopen("syslog_config.json", "r"); + + memset(js, 0, MAX_BUFFER_SIZE); + memset(ch, 0, BUFSIZE); + + while((fgets(ch, (BUFSIZE-1), file)) !=NULL) + { + strcat(js, ch); + memset(ch, 0, BUFSIZE); + } +// printf("the file content is \n %s \n", js); + + jsmn_init(&p); + numToken = jsmn_parse(&p, js, strlen(js), tokens, MAX_TOKENS); +// printf("Token count-%d\n", numToken); + +// printToken(js,tokens, numToken); + + ret = getStringToken(js, tokens, numToken, "tmp_syslogFile", "tmp_indirectParameters", syslog_file, BUFSIZE); + if (ret != 0) + { + printf("Missing mandatory parameters - tmp_syslogFile is not there in tmp_indirectParameters. Exiting...\n"); + exit(1); + } + + ret = getStringToken(js, tokens, numToken, "syslogTag", "tmp_directParameters", syslog_tag, BUFSIZE); + if (ret != 0) + { + printf("Missing mandatory parameters - syslogTag is not there in tmp_directParameters, exiting..\n"); + exit(1); + } + + ret = getStringToken(js, tokens, numToken, "eventName", "tmp_directParameters", eName, BUFSIZE); + if (ret != 0) + { + printf("Missing mandatory parameters - eventName is not there in tmp_directParameters. Exiting...\n"); + exit(1); + } + + ret = getStringToken(js, tokens, numToken, "eventSourceType", "tmp_directParameters", eventSrcTyp, BUFSIZE); + if (ret != 0) + { + printf("Missing mandatory parameters - eventSourceType is not there in tmp_directParameters, exiting..\n"); + exit(1); + } + srcTyp = get_source(eventSrcTyp); + if(srcTyp == -1) + { + printf("Fault eventSourceType value is not matching, eventSourceType-%s \n", eventSrcTyp); + exit(1); + } + + // Open file in read mode + fp = fopen(syslog_file, "r"); + if (fp == NULL) + { + printf("Error while opening file"); + exit(EXIT_FAILURE); + } + + memset(str, 0, 8*BUFSIZE); + if (fseek(fp, 0, SEEK_END)) + perror("fseek() failed"); + else + { + // pos will contain no. of chars in input file. + int n = 8; + pos = ftell(fp); + + // search for '\n' characters + while (pos>prevpos) + { + // Move 'pos' away from end of file. + if (!fseek(fp, --pos, SEEK_SET)) + { + if (fgetc(fp) == '\n') + + // stop reading when n newlines is found + if (count++ == n) + break; + } + else + perror("fseek() failed"); + } + //printf("pos %d prevpos %d\n",pos,prevpos); + + // print last n lines + prevpos = pos; + + while (fgets(str, sizeof(str), fp)) + { + char * position; + // printf("str is - %s\n", str); + if ((position=strchr(str, '\n')) != NULL) + *position = '\0'; + if(strstr(str, syslog_tag) && !strstr(str,"EVEL") && !strstr(str,"commonEventHeader") && !strstr(str,"syslogMsg") && !strstr(str,"syslogTag")) + { + memset(syslog_msg, 0, 8*BUFSIZE); + memcpy(syslog_msg, str, 8*BUFSIZE); + report_syslog(js, tokens, numToken, syslog_tag, eName, srcTyp, syslog_msg); + } + + prevpos += strlen(str); + //printf("new prevpos is %d, size of str is %d\n", prevpos, strlen(str)); + } + } + sleep(3); + } +} + diff --git a/vnfs/VES5.0/evel/evel-library/code/VESreporting_vFW/LICENSE.TXT b/vnfs/VES5.0/evel/evel-library/code/VESreporting_vFW/LICENSE.TXT new file mode 100644 index 00000000..16285cd2 --- /dev/null +++ b/vnfs/VES5.0/evel/evel-library/code/VESreporting_vFW/LICENSE.TXT @@ -0,0 +1,22 @@ +/* + * ============LICENSE_START========================================== + * =================================================================== + * Copyright © 2017 AT&T Intellectual Property. All rights reserved. + * =================================================================== + * Unless otherwise specified, all software contained herein is + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END============================================ + * + * ECOMP is trademark and service mark of AT&T Intellectual Property. + * + */ diff --git a/vnfs/VES5.0/evel/evel-library/code/VESreporting_vFW/Makefile b/vnfs/VES5.0/evel/evel-library/code/VESreporting_vFW/Makefile new file mode 100644 index 00000000..9d1812fa --- /dev/null +++ b/vnfs/VES5.0/evel/evel-library/code/VESreporting_vFW/Makefile @@ -0,0 +1,52 @@ +############################################################################# +# +# Copyright © 2019 AT&T Intellectual Property. All rights reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +############################################################################# + +CC=gcc +ARCH=$(shell getconf LONG_BIT) +CODE_ROOT=$(CURDIR)/../.. +#CODE_ROOT=../code/evel-library +LIBS_DIR=$(CODE_ROOT)/libs/x86_$(ARCH) +#LIBS_DIR=/usr/lib +INCLUDE_DIR= -I $(CODE_ROOT)/code/evel_library -I . + +#****************************************************************************** +# Standard compiler flags. * +#****************************************************************************** +CPPFLAGS= +CFLAGS=-Wall -g -fPIC +FILEOBJLIST= jsmn.o vpp_measurement_reporter.o + +all: vpp_measurement_reporter + +clean: + rm -f *.o vpp_measurement_reporter + +%.o: %.c + $(CC) $(CPPFLAGS) $(CFLAGS) $(INCLUDE_DIR) -c $< -o $@ + +jsmn.o: jsmn.c jsmn.h +vpp_measurement_reporter.o: vpp_measurement_reporter.c + +vpp_measurement_reporter: $(FILEOBJLIST) + $(CC) $(CPPFLAGS) $(CFLAGS) -o vpp_measurement_reporter \ + -L $(LIBS_DIR) \ + $(FILEOBJLIST) \ + -lpthread \ + -level \ + -lcurl + + diff --git a/vnfs/VES5.0/evel/evel-library/code/VESreporting_vFW/README.md b/vnfs/VES5.0/evel/evel-library/code/VESreporting_vFW/README.md new file mode 100644 index 00000000..6921cdc4 --- /dev/null +++ b/vnfs/VES5.0/evel/evel-library/code/VESreporting_vFW/README.md @@ -0,0 +1,37 @@ + +PROJECT DESCRIPTION + +--- +This project contains the source code and scripts for the periodic generation of measurement events. The folder contains: + + - README.md: this file. + + - LICENSE.TXT: the license text. + + - vpp_measurement_reporter.c and other .c files: source code that uses the ECOMP Vendor Event Listener Library (VES) to generate the measurement events. Measurement event is generated periodically on each of the interfaces. It gives the number of bytes/packets that transmitted/received. The application reads meas_config.json file for parameter values and poppulate the measurement event. If eventName parameter value is not given, the application terminates. If reportingEntityName and sourceName parameter values are not given, then it gets the hostname and poppulates it. If measurementInterval is not given, it defaults to 60 seconds. + + - Makefile: makefile that compiles vpp_measurement_reporter.c and generates vpp_measurement_reporter binary. + + - go-client.sh/go-client_2_collectors.sh: bash script that starts up the vpp_measurement_reporter. It reads input parameters like DCAE IP address and port from configuration files contained in /opt/config. Based on the collector configuration, use go-client.sh for single collector configuration, or use go-client_2_collectors.sh for 2 collectors configuration. + + +USAGE +----- + +Update the configuration files with proper parameters values so that events generated would contain those values + +To run the vpp_measurement_reporter in single collector configuration, please execute the following steps: + + - Make the go-client.sh script executable + chmod +x go-client.sh + + - Run the go-client.sh script + ./go-client.sh + +For 2 collectors configuration, please execute following steps: + + - Make the go-client.sh script executable + chmod +x go-client_2_collectors.sh + + - Run the go-client_2_collectors.sh script + ./go-client_2_collectors.sh diff --git a/vnfs/VES5.0/evel/evel-library/code/VESreporting_vFW/dep.xml b/vnfs/VES5.0/evel/evel-library/code/VESreporting_vFW/dep.xml new file mode 100644 index 00000000..fc18229f --- /dev/null +++ b/vnfs/VES5.0/evel/evel-library/code/VESreporting_vFW/dep.xml @@ -0,0 +1,25 @@ +<assembly xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.2" + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.2 http://maven.apache.org/xsd/assembly-1.1.2.xsd"> + <id>demo</id> + <formats> + <format>tar.gz</format> + </formats> + <fileSets> + + <fileSet> + <directory>.</directory> + <outputDirectory>/</outputDirectory> + <includes> + <include>*.sh</include> + <include>*.md</include> + <include>*.TXT</include> + <include>*.c</include> + <include>Makefile</include> + </includes> + </fileSet> + + </fileSets> +</assembly> + + diff --git a/vnfs/VES5.0/evel/evel-library/code/VESreporting_vFW/go-client.sh b/vnfs/VES5.0/evel/evel-library/code/VESreporting_vFW/go-client.sh new file mode 100755 index 00000000..b2b3a08e --- /dev/null +++ b/vnfs/VES5.0/evel/evel-library/code/VESreporting_vFW/go-client.sh @@ -0,0 +1,6 @@ +#!/bin/bash + +export LD_LIBRARY_PATH="/opt/VES/evel/evel-library/libs/x86_64/" +DCAE_COLLECTOR_IP=$(cat /opt/config/dcae_collector_ip.txt) +DCAE_COLLECTOR_PORT=$(cat /opt/config/dcae_collector_port.txt) +./vpp_measurement_reporter $DCAE_COLLECTOR_IP $DCAE_COLLECTOR_PORT diff --git a/vnfs/VES5.0/evel/evel-library/code/VESreporting_vFW/go-client_2_collectors.sh b/vnfs/VES5.0/evel/evel-library/code/VESreporting_vFW/go-client_2_collectors.sh new file mode 100755 index 00000000..65f71268 --- /dev/null +++ b/vnfs/VES5.0/evel/evel-library/code/VESreporting_vFW/go-client_2_collectors.sh @@ -0,0 +1,12 @@ +#!/bin/bash + +export LD_LIBRARY_PATH="/opt/VES/evel/evel-library/libs/x86_64/" + +#Usage for 2 collectors: +#./vpp_measurement_reporter <FQDN>|<IP address> <port> <FQDN>|<IP address> <port> + +DCAE_COLLECTOR_IP=$(cat /opt/config/dcae_collector_ip.txt) +DCAE_COLLECTOR_PORT=$(cat /opt/config/dcae_collector_port.txt) +DCAE_COLLECTOR_IP2=$(cat /opt/config/dcae_collector_ip2.txt) +DCAE_COLLECTOR_PORT2=$(cat /opt/config/dcae_collector_port2.txt) +./vpp_measurement_reporter $DCAE_COLLECTOR_IP $DCAE_COLLECTOR_PORT $DCAE_COLLECTOR_IP2 $DCAE_COLLECTOR_PORT2 diff --git a/vnfs/VES5.0/evel/evel-library/code/VESreporting_vFW/jsmn.c b/vnfs/VES5.0/evel/evel-library/code/VESreporting_vFW/jsmn.c new file mode 100644 index 00000000..1d72ba4d --- /dev/null +++ b/vnfs/VES5.0/evel/evel-library/code/VESreporting_vFW/jsmn.c @@ -0,0 +1,672 @@ +/*************************************************************************//** + * + * Copyright © 2017 AT&T Intellectual Property. All rights reserved. + * + * Unless otherwise specified, all software contained herein is + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ECOMP is a trademark and service mark of AT&T Intellectual Property. + ****************************************************************************/ +#include<stdio.h> +#include<stdlib.h> +#include<string.h> +#include "jsmn.h" + +/** + * Allocates a fresh unused token from the token pull. + */ +static jsmntok_t *jsmn_alloc_token(jsmn_parser *parser, + jsmntok_t *tokens, size_t num_tokens) { + jsmntok_t *tok; + if (parser->toknext >= num_tokens) { + return NULL; + } + tok = &tokens[parser->toknext++]; + tok->start = tok->end = -1; + tok->size = 0; +//#ifdef JSMN_PARENT_LINKS + tok->parent = -1; +//#endif + return tok; +} + +/** + * Fills token type and boundaries. + */ +static void jsmn_fill_token(jsmntok_t *token, jsmntype_t type, + int start, int end) { +//printf("jsmn_fill_token:: start-%d, end-%d\n", start, end); + token->type = type; + token->start = start; + token->end = end; + token->size = 0; +} + +/** + * Fills next available token with JSON primitive. + */ +static int jsmn_parse_primitive(jsmn_parser *parser, const char *js, + size_t len, jsmntok_t *tokens, size_t num_tokens) { + jsmntok_t *token; + int start; + + start = parser->pos; + + for (; parser->pos < len && js[parser->pos] != '\0'; parser->pos++) { +//printf("jsmn_parse_primitive:: the char is - %c\n", js[parser->pos]); + switch (js[parser->pos]) { +#ifndef JSMN_STRICT + /* In strict mode primitive must be followed by "," or "}" or "]" */ + case ':': +#endif + case '\t' : case '\r' : case '\n' : case ' ' : + case ',' : case ']' : case '}' : + goto found; + } + if (js[parser->pos] < 32 || js[parser->pos] >= 127) { + parser->pos = start; + return JSMN_ERROR_INVAL; + } + } +#ifdef JSMN_STRICT + /* In strict mode primitive must be followed by a comma/object/array */ + parser->pos = start; + return JSMN_ERROR_PART; +#endif + +found: + if (tokens == NULL) { + parser->pos--; + return 0; + } + token = jsmn_alloc_token(parser, tokens, num_tokens); + if (token == NULL) { + parser->pos = start; + return JSMN_ERROR_NOMEM; + } + jsmn_fill_token(token, JSMN_PRIMITIVE, start, parser->pos); +//#ifdef JSMN_PARENT_LINKS + token->parent = parser->toksuper; +//#endif + parser->pos--; + return 0; +} + +/** + * Fills next token with JSON string. + */ +static int jsmn_parse_string(jsmn_parser *parser, const char *js, + size_t len, jsmntok_t *tokens, size_t num_tokens) { + jsmntok_t *token; + + int start = parser->pos; + + parser->pos++; + + /* Skip starting quote */ + for (; parser->pos < len && js[parser->pos] != '\0'; parser->pos++) { + char c = js[parser->pos]; + char d = js[parser->pos + 1]; +// char e = js[parser->pos + 2]; +//printf("jsmn_parse_string: value-%c, pos-%d\n", c,parser->pos); + + /* Quote: end of string */ +// if (c == '\"') { + if (d == '\"') { +// if ((d == '\"')&&((e == ' ')||(e == ','))) { +parser->pos++; +//printf("jsmn_parse_string: end of string\n"); + if (tokens == NULL) { +//printf("jsmn_parse_string: end tokens is NULL\n"); + return 0; + } + token = jsmn_alloc_token(parser, tokens, num_tokens); +//printf("jsmn_parse_string: Allocated tokens \n"); + if (token == NULL) { +//printf("jsmn_parse_string: Allocated tokens is NULL\n"); + parser->pos = start; + return JSMN_ERROR_NOMEM; + } + jsmn_fill_token(token, JSMN_STRING, start+1, parser->pos); +//printf("jsmn_parse_string: Allocated tokens is filled\n"); +//#ifdef JSMN_PARENT_LINKS + token->parent = parser->toksuper; +//#endif + return 0; + } + + /* Backslash: Quoted symbol expected */ + if (c == '\\' && parser->pos + 1 < len) { + int i; + parser->pos++; +//printf("jsmn_parse_string: value - %c, POS-%3d \n",c, js[parser->pos]); + switch (js[parser->pos]) { + /* Allowed escaped symbols */ + case '\"': case '/' : case '\\' : case 'b' : + case 'f' : case 'r' : case 'n' : case 't' : + break; + /* Allows escaped symbol \uXXXX */ + case 'u': + parser->pos++; + for(i = 0; i < 4 && parser->pos < len && js[parser->pos] != '\0'; i++) { + /* If it isn't a hex character we have an error */ + if(!((js[parser->pos] >= 48 && js[parser->pos] <= 57) || /* 0-9 */ + (js[parser->pos] >= 65 && js[parser->pos] <= 70) || /* A-F */ + (js[parser->pos] >= 97 && js[parser->pos] <= 102))) { /* a-f */ + parser->pos = start; + return JSMN_ERROR_INVAL; + } + parser->pos++; + } + parser->pos--; + break; + /* Unexpected symbol */ + default: + parser->pos = start; + return JSMN_ERROR_INVAL; + } + } + } + parser->pos = start; +printf("jsmn_parse_string: exiting with ERROR_PART, pos-%d", parser->pos); + return JSMN_ERROR_PART; +} + +/** + * Parse JSON string and fill tokens. + */ +int jsmn_parse(jsmn_parser *parser, const char *js, size_t len, + jsmntok_t *tokens, unsigned int num_tokens) { + int r; + int i; + jsmntok_t *token; + int count = parser->toknext; + + for (; parser->pos < len && js[parser->pos] != '\0'; parser->pos++) { + char c; + jsmntype_t type; + + c = js[parser->pos]; +//printf("jsmn_parse: value of c - %c\n",c); + switch (c) { + case '{': case '[': + count++; + if (tokens == NULL) { + break; + } + token = jsmn_alloc_token(parser, tokens, num_tokens); + if (token == NULL) + return JSMN_ERROR_NOMEM; + if (parser->toksuper != -1) { + tokens[parser->toksuper].size++; +//#ifdef JSMN_PARENT_LINKS + token->parent = parser->toksuper; +//#endif + } + token->type = (c == '{' ? JSMN_OBJECT : JSMN_ARRAY); + token->start = parser->pos; + parser->toksuper = parser->toknext - 1; + break; + case '}': case ']': + if (tokens == NULL) + break; + type = (c == '}' ? JSMN_OBJECT : JSMN_ARRAY); +//#ifdef JSMN_PARENT_LINKS + if (parser->toknext < 1) { + return JSMN_ERROR_INVAL; + } + token = &tokens[parser->toknext - 1]; + for (;;) { + if (token->start != -1 && token->end == -1) { + if (token->type != type) { + return JSMN_ERROR_INVAL; + } + token->end = parser->pos + 1; + parser->toksuper = token->parent; + break; + } + if (token->parent == -1) { + break; + } + token = &tokens[token->parent]; + } +//#else +// for (i = parser->toknext - 1; i >= 0; i--) { +// token = &tokens[i]; +// if (token->start != -1 && token->end == -1) { +// if (token->type != type) { +// return JSMN_ERROR_INVAL; +// } +// parser->toksuper = -1; +// token->end = parser->pos + 1; +// break; +// } +// } +// /* Error if unmatched closing bracket */ +// if (i == -1) return JSMN_ERROR_INVAL; +// for (; i >= 0; i--) { +// token = &tokens[i]; +// if (token->start != -1 && token->end == -1) { +// parser->toksuper = i; +// break; +// } +// } +//#endif + break; + case '\"': + r = jsmn_parse_string(parser, js, len, tokens, num_tokens); + if (r < 0) return r; + count++; + if (parser->toksuper != -1 && tokens != NULL) + tokens[parser->toksuper].size++; + break; + case '\t' : case '\r' : case '\n' : case ' ': + break; + case ':': + parser->toksuper = parser->toknext - 1; +//printf("jsmn_parse: value of c is :: - %c\n",c); + break; + case ',': + if (tokens != NULL && parser->toksuper != -1 && + tokens[parser->toksuper].type != JSMN_ARRAY && + tokens[parser->toksuper].type != JSMN_OBJECT) { +//#ifdef JSMN_PARENT_LINKS + parser->toksuper = tokens[parser->toksuper].parent; +//#else +// for (i = parser->toknext - 1; i >= 0; i--) { +// if (tokens[i].type == JSMN_ARRAY || tokens[i].type == JSMN_OBJECT) { +// if (tokens[i].start != -1 && tokens[i].end == -1) { +// parser->toksuper = i; +// break; +// } +// } +// } +//#endif + } + break; +#ifdef JSMN_STRICT + /* In strict mode primitives are: numbers and booleans */ + case '-': case '0': case '1' : case '2': case '3' : case '4': + case '5': case '6': case '7' : case '8': case '9': + case 't': case 'f': case 'n' : + /* And they must not be keys of the object */ + if (tokens != NULL && parser->toksuper != -1) { + jsmntok_t *t = &tokens[parser->toksuper]; + if (t->type == JSMN_OBJECT || + (t->type == JSMN_STRING && t->size != 0)) { + return JSMN_ERROR_INVAL; + } + } +#else + /* In non-strict mode every unquoted value is a primitive */ + default: +#endif + r = jsmn_parse_primitive(parser, js, len, tokens, num_tokens); + if (r < 0) return r; + count++; + if (parser->toksuper != -1 && tokens != NULL) + tokens[parser->toksuper].size++; + break; + +#ifdef JSMN_STRICT + /* Unexpected char in strict mode */ + default: + return JSMN_ERROR_INVAL; +#endif + } + } + + if (tokens != NULL) { + for (i = parser->toknext - 1; i >= 0; i--) { +//printf("index -%2d, start is %3d, end is %3d\n", i, tokens[i].start, tokens[i].end); + /* Unmatched opened object or array */ + if (tokens[i].start != -1 && tokens[i].end == -1) { + return JSMN_ERROR_PART; + } + } + } + + return count; +} + +/** + * Creates a new parser based over a given buffer with an array of tokens + * available. + */ +void jsmn_init(jsmn_parser *parser) { + parser->pos = 0; + parser->toknext = 0; + parser->toksuper = -1; +} + +int jsoneq(const char *json, jsmntok_t *tok, const char *s) +{ + if (tok->type == JSMN_STRING && (int) strlen(s) == tok->end - tok->start && + strncmp(json + tok->start, s, tok->end - tok->start) == 0) { + return 0; + } + return -1; +} + +void printToken(char * js, jsmntok_t * tokens, int numToken) +{ + for (int i = 1; i < numToken; i++) + { + printf("Token number-%2d, parent-%2d, type-%d size-%2d, parameter -", i, tokens[i].parent, tokens[i].type, tokens[i].size); + if (tokens[i].type == JSMN_STRING || tokens[i].type == JSMN_PRIMITIVE) { + printf("%.*s\n", tokens[i].end - tokens[i].start, js + tokens[i].start); + } else if (tokens[i].type == JSMN_ARRAY) { + printf("[%d elems]\n", tokens[i].size); + } else if (tokens[i].type == JSMN_OBJECT) { + printf("{%d elems}\n", tokens[i].size); + } else { + printf("value?? - "); + TOKEN_PRINT(tokens[i]); + } + } +} + +int getStringToken(char * js, jsmntok_t * tokens, int numToken, char * param, char * pParam, char * value, int maxValueSize) +{ + int i = 0; + int dpToken = 0; + + memset(value, 0, maxValueSize); + + for (i = 1; i < numToken; i++) + { + if(jsoneq(js, &tokens[i], pParam) == 0) + break; + } + if (i < numToken) + { + dpToken = ++i; + } + else + { + printf("The parameter %s is not present in JSON file\n", pParam); + return 1; //Parent token not seen + } + for (i=1; i < numToken; i++) + { + if (tokens[i].parent == dpToken && tokens[i].type == JSMN_STRING && tokens[i].size == 1) + { + if(jsoneq(js, &tokens[i], param) != 0) + continue; + TOKEN_COPY(js, tokens[i+1], value); + + return 0; //Success + } + } + printf("The parameter %s is not present in JSON file\n", param); + return 2; //parameter not found +} + + +int getStringTokenV2(char * js, jsmntok_t * tokens, int numToken, char * param, char * pParam, char * gParam,char * value, int maxValueSize) +{ + int i = 0; + int dpToken = 0; + + memset(value, 0, maxValueSize); + + for (i = 1; i < numToken; i++) + { + if(jsoneq(js, &tokens[i], gParam) == 0) + break; + } + if (i < numToken) + { + dpToken = ++i; + } + else + { + printf("The parameter %s is not present in JSON file\n", pParam); + return 1; //Grand Parent token not seen + } + + for (i=dpToken; i < numToken; i++) + { + if (tokens[i].parent == dpToken && tokens[i].type == JSMN_STRING && tokens[i].size == 1) + { + if(jsoneq(js, &tokens[i], pParam) == 0) + break; + } + } + if (i < numToken) + { + dpToken = ++i; + } + else + { + printf("The parameter %s is not present in JSON file\n", pParam); + return 2; //Parent token not seen + } + + for (i=dpToken; i < numToken; i++) + { + if (tokens[i].parent == dpToken && tokens[i].type == JSMN_STRING && tokens[i].size == 1) + { + if(jsoneq(js, &tokens[i], param) != 0) + continue; + TOKEN_COPY(js, tokens[i+1], value); + + return 0; //Success + } + } + + printf("The parameter %s is not present in JSON file\n", param); + return 2; //parameter not found +} + +int getIntToken(char * js, jsmntok_t * tokens, int numToken, char * param, char * pParam, int * value) +{ + int i = 0; + int dpToken = 0; + char val[128]; + + memset(val, 0, 128); + for (i = 1; i < numToken; i++) + { + if(jsoneq(js, &tokens[i], pParam) == 0) + break; + } + if (i < numToken) + { + dpToken = ++i; + } + else + { + printf("The parameter %s is not present in JSON file\n", pParam); + return 1; //Parent token not seen + } + for (i=1; i < numToken; i++) + { + if (tokens[i].parent == dpToken && tokens[i].type == JSMN_STRING && tokens[i].size == 1) + { + if(jsoneq(js, &tokens[i], param) != 0) + { + continue; + } + + if(tokens[i+1].type != JSMN_PRIMITIVE) + return 3; //Wrong parameter type + +// printf("INT parameter / Value - %s", param); + TOKEN_COPY(js, tokens[i+1], val); + *value = atoi(val); +// printf(" - %d\n", *value); + + return 0; //success + } + } + printf("The parameter %s is not present in JSON file\n", param); + return 2; //parameter not found +} + +void parseDirectParameters(char * js, jsmntok_t * tokens, int numToken) +{ + int i = 0; + int dpToken = 0; + char param[128]; + char value[128]; + + for (i = 1; i < numToken; i++) + { + if(jsoneq(js, &tokens[i], "directParameters") == 0) + break; + } + + if (i < numToken) + { + dpToken = ++i; + } + + for (int i = 1; i < numToken; i++) + { + memset(param, 0, 128); + memset(value, 0, 128); + if (tokens[i].parent == dpToken && tokens[i].type == JSMN_STRING && tokens[i].size == 1) + { + TOKEN_COPY(js, tokens[i], param); +// printf("parameter / Value - %s", param); + TOKEN_COPY(js, tokens[i+1], value); +// printf(" - %s\n", value); + } + } +} + +int getArrayTokens(char * js, jsmntok_t * tokens, int numToken, char * param, char * pParam, ARRAYVAL * arrayValue, int * numElements) +{ + int i = 0; + int dpToken = 0; + + for (i = 1; i < numToken; i++) + { + if(jsoneq(js, &tokens[i], pParam) == 0) + break; + } + if (i < numToken) + { + dpToken = ++i; + } + else + { + printf("The parameter %s is not present in JSON file\n", pParam); + return 1; //Parent token not seen + } + for (i=1; i < numToken; i++) + { + if (tokens[i].parent == dpToken && tokens[i].type == JSMN_STRING && tokens[i].size == 1) + { +// printf("value of token %d\n", i); + if(jsoneq(js, &tokens[i], param) != 0) + continue; + + if (tokens[i+1].type == JSMN_ARRAY) + { + *numElements = tokens[i+1].size; +// printf("[%d elems]\n", *numElements); + + for (int k = 0; k < *numElements; k++) + { + TOKEN_COPY(js, tokens[i+2+k], arrayValue[k].arrayString); +// printf(" - %s\n", arrayValue[k].arrayString); + } + return 0; //Success + } + } + } + printf("The parameter %s is not present in JSON file\n", param); + return 2; //parameter not found +} + +int isTokenPresent(char * js, jsmntok_t * tokens, int numToken, char * param, char * pParam) +{ + int i = 0; + int dpToken = 0; + char val[128]; + + memset(val, 0, 128); + for (i = 1; i < numToken; i++) + { + if(jsoneq(js, &tokens[i], pParam) == 0) + break; + } + if (i < numToken) + { + dpToken = ++i; + } + else + { + printf("The parameter %s is not present in JSON file\n", pParam); + return 1; //Parent token not seen + } + for (i=1; i < numToken; i++) + { + if (tokens[i].parent == dpToken && tokens[i].type == JSMN_STRING) + { + if(jsoneq(js, &tokens[i], param) == 0) + { + return 0; //Token present + } + } + } + printf("The parameter %s is not present in JSON file\n", param); + return 2; //Token Not present +} + +int read_keyVal_params(char * js, jsmntok_t * tokens, int numToken, char * param, char * pParam, KEYVALRESULT * keyValueResultList, int * numElements) +{ + int i = 0; + int dpToken = 0; + + for (i = 1; i < numToken; i++) + { + if(jsoneq(js, &tokens[i], pParam) == 0) + break; + } + if (i < numToken) + { + dpToken = ++i; + } + else + { + printf("The parameter %s is not present in JSON file\n", pParam); + return 1; //Parent token not seen + } + for (i=1; i < numToken; i++) + { + if (tokens[i].parent == dpToken && tokens[i].type == JSMN_STRING && tokens[i].size == 1) + { +// printf("value of token %d\n", i); + if(jsoneq(js, &tokens[i], param) != 0) + continue; + + if (tokens[i+1].type == JSMN_OBJECT) + { + *numElements = tokens[i+1].size; +// printf("{%d elems}\n", *numElements); + + for (int k = 0; k < *numElements; k++) + { + TOKEN_COPY(js, tokens[i+2+k*2], keyValueResultList[k].keyStr); +// printf("Key - %s", keyValueResultList[k].keyStr); + TOKEN_COPY(js, tokens[i+3+k*2], keyValueResultList[k].valStr); +// printf("Value - %s\n", keyValueResultList[k].valStr); + } + return 0; //Success + } + } + } + printf("The parameter %s is not present in JSON file\n", param); + return 2; //parameter not found +} diff --git a/vnfs/VES5.0/evel/evel-library/code/VESreporting_vFW/jsmn.h b/vnfs/VES5.0/evel/evel-library/code/VESreporting_vFW/jsmn.h new file mode 100644 index 00000000..f9d838b6 --- /dev/null +++ b/vnfs/VES5.0/evel/evel-library/code/VESreporting_vFW/jsmn.h @@ -0,0 +1,136 @@ +/*************************************************************************//** + * + * Copyright © 2017 AT&T Intellectual Property. All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + ****************************************************************************/ + +#ifndef __JSMN_H_ +#define __JSMN_H_ + +#include <stddef.h> + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * JSON type identifier. Basic types are: + * o Object + * o Array + * o String + * o Other primitive: number, boolean (true/false) or null + */ +typedef enum { + JSMN_UNDEFINED = 0, + JSMN_OBJECT = 1, + JSMN_ARRAY = 2, + JSMN_STRING = 3, + JSMN_PRIMITIVE = 4 +} jsmntype_t; + +enum jsmnerr { + /* Not enough tokens were provided */ + JSMN_ERROR_NOMEM = -1, + /* Invalid character inside JSON string */ + JSMN_ERROR_INVAL = -2, + /* The string is not a full JSON packet, more bytes expected */ + JSMN_ERROR_PART = -3 +}; + +typedef struct arrayValues { + char arrayString[32]; +} ARRAYVAL; + +typedef struct keyValResult { + char keyStr[80]; + char valStr[250]; + char resultStr[80]; +} KEYVALRESULT; + +/** + * JSON token description. + * @param type type (object, array, string etc.) + * @param start start position in JSON data string + * @param end end position in JSON data string + */ +typedef struct { + jsmntype_t type; + int start; + int end; + int size; +//#ifdef JSMN_PARENT_LINKS + int parent; +//#endif +} jsmntok_t; + +/** + * JSON parser. Contains an array of token blocks available. Also stores + * the string being parsed now and current position in that string + */ +typedef struct { + unsigned int pos; /* offset in the JSON string */ + unsigned int toknext; /* next token to allocate */ + int toksuper; /* superior token node, e.g parent object or array */ +} jsmn_parser; + +#define TOKEN_EQ(t, tok_start, tok_end, tok_type) \ + ((t).start == tok_start \ + && (t).end == tok_end \ + && (t).type == (tok_type)) + +#define TOKEN_STRING(js, t, s) \ + (strncmp(js+(t).start, s, (t).end - (t).start) == 0 \ + && strlen(s) == (t).end - (t).start) + +#define TOKEN_COPY(js, t, s) \ + strncpy(s, js+(t).start, (t).end - (t).start) + +#define TOKEN_PRINT(t) \ + printf("start: %d, end: %d, type: %d, size: %d\n", \ + (t).start, (t).end, (t).type, (t).size) + + +/** + * Create JSON parser over an array of tokens + */ +void jsmn_init(jsmn_parser *parser); + +/** + * Run JSON parser. It parses a JSON data string into and array of tokens, each describing + * a single JSON object. + */ +int jsmn_parse(jsmn_parser *parser, const char *js, size_t len, + jsmntok_t *tokens, unsigned int num_tokens); + +int jsoneq(const char *json, jsmntok_t *tok, const char *s); + +void printToken(char * js, jsmntok_t * tokens, int numToken); + +int getStringToken(char * js, jsmntok_t * tokens, int numToken, char * param, char * pParam, char * value, int maxValueSize); + +int getIntToken(char * js, jsmntok_t * tokens, int numToken, char * param, char * pParam, int * value); + +int getArrayTokens(char * js, jsmntok_t * tokens, int numToken, char * param, char * pParam, ARRAYVAL * arrayValue, int * numElements); + +int isTokenPresent(char * js, jsmntok_t * tokens, int numToken, char * param, char * pParam); + +int read_keyVal_params(char * js, jsmntok_t * tokens, int numToken, char * param, char * pParam, KEYVALRESULT * keyValueResultList, int * numElements); + +int getStringTokenV2(char * js, jsmntok_t * tokens, int numToken, char * param, char * pParam, char *gParam, char * value, int maxValueSize); + +#ifdef __cplusplus +} +#endif + +#endif /* __JSMN_H_ */ diff --git a/vnfs/VES5.0/evel/evel-library/code/VESreporting_vFW/meas_config.json b/vnfs/VES5.0/evel/evel-library/code/VESreporting_vFW/meas_config.json new file mode 100644 index 00000000..bbd3e453 --- /dev/null +++ b/vnfs/VES5.0/evel/evel-library/code/VESreporting_vFW/meas_config.json @@ -0,0 +1,50 @@ +{ + "tmp_directParameters": { + "eventName": "Measurement_vFirewall-AT&T_nicPerformance", + "eventType": "applicationVnf", + "nfcNamingCode": "AFX", + "nfNamingCode": "AFX", + "priority": "Low", + "reportingEntityId": "cc305d54-75b4-431b-adb2-eb6b9e541234", + "reportingEntityName": "ibcx0001vm002oam001", + "sourceId": "de305d54-75b4-431b-adb2-eb6b9e546014", + "sourceName": "scfx0001vm002cap001", + "measurementInterval": 20, + "tmp_device": ["lo", "enp0s3", "docker0"] + + }, + "tmp_indirectParameters": { + "tmp_init":{ + "tmp_t0BytesIn": "sudo cat /proc/net/dev | grep $tmp_device | tr -s ' ' | cut -d ':' -f2 | cut -d ' ' -f2", + "tmp_t0BytesOut": "sudo cat /proc/net/dev | grep $tmp_device | tr -s ' ' | cut -d ':' -f2 | cut -d ' ' -f10", + "tmp_t0PacketsIn": "sudo cat /proc/net/dev | grep $tmp_device | tr -s ' ' | cut -d ':' -f2 | cut -d ' ' -f3", + "tmp_t0PacketsOut": "sudo cat /proc/net/dev | grep $tmp_device | tr -s ' ' | cut -d ':' -f2 | cut -d ' ' -f11" + }, + "vNicPerformance": { + "tmp_vnic_command": { + "tmp_t1BytesIn": "sudo cat /proc/net/dev | grep $tmp_device | tr -s ' ' | cut -d ':' -f2 | cut -d ' ' -f2", + "tmp_t1BytesOut": "sudo cat /proc/net/dev | grep $tmp_device | tr -s ' ' | cut -d ':' -f2 | cut -d ' ' -f10", + "tmp_t1PacketsIn": "sudo cat /proc/net/dev | grep $tmp_device | tr -s ' ' | cut -d ':' -f2 | cut -d ' ' -f3", + "tmp_t1PacketsOut": "sudo cat /proc/net/dev | grep $tmp_device | tr -s ' ' | cut -d ':' -f2 | cut -d ' ' -f11" + }, + "receivedOctetsDelta": "$(tmp_t1BytesIn - tmp_t0BytesIn)", + "receivedTotalPacketsDelta": "$(tmp_t1PacketsIn - tmp_t0PacketsIn)", + "transmittedOctetsDelta": "$(tmp_t1BytesOut - tmp_t0BytesOut)", + "transmittedTotalPacketsDelta": "$(tmp_t1PacketsOut - tmp_t0PacketsOut)", + "valuesAreSuspect": "true", + "vNicIdentifier": "$tmp_device" + } + "cpuUsage": { + "tmp_cpuuse_command": { + "tmp_cpuUseCmd": "/usr/bin/top -bn 2 -d 0.01 | grep '^%Cpu' | tail -n 1 | cut -d ':' -f2", + "tmp_cpuIdle": "/usr/bin/top -bn 2 -d 0.01 | grep '^%Cpu' | tail -n 1 |cut -d ':' -f2 | cut -d ',' -f4 | cut -b 1-5", + "tmp_cpuUsageSystem": "/usr/bin/top -bn 2 -d 0.01 | grep '^%Cpu' | tail -n 1 |cut -d ':' -f2 | cut -d ',' -f2 | cut -b 1-5", + "tmp_cpuUsageUser": "/usr/bin/top -bn 2 -d 0.01 | grep '^%Cpu' | tail -n 1 |cut -d ':' -f2 | cut -d ',' -f1 | cut -b 1-5" + }, + "cpuIdentifier": "Cpu1", + "cpuIdle": "$tmp_cpuIdle", + "cpuUsageSystem": "$tmp_cpuUsageSystem", + "cpuUsageUser": "$tmp_cpuUsageUser" + } + } +} diff --git a/vnfs/VES5.0/evel/evel-library/code/VESreporting_vFW/pom.xml b/vnfs/VES5.0/evel/evel-library/code/VESreporting_vFW/pom.xml new file mode 100644 index 00000000..f9f42ebb --- /dev/null +++ b/vnfs/VES5.0/evel/evel-library/code/VESreporting_vFW/pom.xml @@ -0,0 +1,83 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- + ============LICENSE_START========================================== + =================================================================== + Copyright © 2017 AT&T Intellectual Property. All rights reserved. + =================================================================== + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + ============LICENSE_END============================================ + + ECOMP and OpenECOMP are trademarks + and service marks of AT&T Intellectual Property. +--> +<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> + +<parent> + <groupId>org.onap.demo.vnf</groupId> + <artifactId>demo-aggregator</artifactId> + <version>1.2.0-SNAPSHOT</version> + <relativePath>../../pom.xml</relativePath> + </parent> + + <modelVersion>4.0.0</modelVersion> + <groupId>org.onap.demo.vnf.ves5</groupId> + <artifactId>ves_vfw_reporting</artifactId> + + <build> + <plugins> + + <plugin> + <artifactId>maven-jar-plugin</artifactId> + <version>2.3.2</version> + <executions> + <execution> + <id>default-jar</id> + <phase>never</phase> + </execution> + </executions> + </plugin> + + <plugin> + <artifactId>maven-assembly-plugin</artifactId> + <version>2.5.3</version> + <configuration> + <descriptor>dep.xml</descriptor> + </configuration> + <executions> + <execution> + <id>create-archive</id> + <phase>package</phase> + <goals> + <goal>single</goal> + </goals> + </execution> + </executions> + </plugin> + + <plugin> + <groupId>org.codehaus.mojo</groupId> + <artifactId>exec-maven-plugin</artifactId> + <executions> + <execution> + <phase>none</phase> + </execution> + </executions> + <configuration> + <skip>true</skip> + </configuration> + </plugin> + + </plugins> + </build> + +</project> diff --git a/vnfs/VES5.0/evel/evel-library/code/VESreporting_vFW/sample_measurement_event.txt b/vnfs/VES5.0/evel/evel-library/code/VESreporting_vFW/sample_measurement_event.txt new file mode 100644 index 00000000..e66fa197 --- /dev/null +++ b/vnfs/VES5.0/evel/evel-library/code/VESreporting_vFW/sample_measurement_event.txt @@ -0,0 +1,62 @@ +{ + "event": { + "commonEventHeader": { + "domain": "measurementsForVfScaling", + "eventId": "mvfs000000002", + "eventName": "Measurement_vFirewall-AT&T_nicPerformance", + "eventType": "applicationVnf", + "lastEpochMicrosec": 1548492802113484, + "nfNamingCode": "AFX", + "nfcNamingCode": "AFX", + "priority": "Normal", + "reportingEntityId": "cc305d54-75b4-431b-adb2-eb6b9e541234", + "reportingEntityName": "ibcx0001vm002oam001", + "sequence": 0, + "sourceId": "de305d54-75b4-431b-adb2-eb6b9e546014", + "sourceName": "scfx0001vm002cap001", + "startEpochMicrosec": 1548492780026901, + "version": 3.0 + }, + "measurementsForVfScalingFields": { + "cpuUsageArray": [ + { + "cpuIdentifier": "Cpu1", + "cpuIdle": 33.3, + "cpuUsageSystem": 0.0, + "cpuUsageUser": 66.7, + "percentUsage": 0.0 + } + ], + "measurementInterval": 20, + "measurementsForVfScalingVersion": 2.0, + "requestRate": 0, + "vNicPerformanceArray": [ + { + "receivedOctetsDelta": 2721.0, + "receivedTotalPacketsDelta": 18.0, + "transmittedOctetsDelta": 2721.0, + "transmittedTotalPacketsDelta": 18.0, + "vNicIdentifier": "lo", + "valuesAreSuspect": "true" + }, + { + "receivedOctetsDelta": 531.0, + "receivedTotalPacketsDelta": 6.0, + "transmittedOctetsDelta": 525.0, + "transmittedTotalPacketsDelta": 6.0, + "vNicIdentifier": "enp0s3", + "valuesAreSuspect": "true" + }, + { + "receivedOctetsDelta": 0.0, + "receivedTotalPacketsDelta": 0.0, + "transmittedOctetsDelta": 0.0, + "transmittedTotalPacketsDelta": 0.0, + "vNicIdentifier": "docker0", + "valuesAreSuspect": "true" + } + ] + } + } +} + diff --git a/vnfs/VES5.0/evel/evel-library/code/VESreporting_vFW/vpp_measurement_reporter.c b/vnfs/VES5.0/evel/evel-library/code/VESreporting_vFW/vpp_measurement_reporter.c new file mode 100644 index 00000000..15b20d10 --- /dev/null +++ b/vnfs/VES5.0/evel/evel-library/code/VESreporting_vFW/vpp_measurement_reporter.c @@ -0,0 +1,685 @@ +/*************************************************************************//** + * + * Copyright © 2019 AT&T Intellectual Property. All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + ****************************************************************************/ + +#include <stdio.h> +#include <stdlib.h> +#include <unistd.h> +#include <pthread.h> +#include <string.h> +#include <netdb.h> +#include <sys/time.h> +#include <sys/stat.h> +#include "jsmn.h" +#include "evel.h" + +#define BUFSIZE 128 +#define MAX_BUFFER_SIZE 4096 +#define MAX_TOKENS 1000 +#define MAX_INTERFACES 40 + +void *MeasThread(void *threadarg); + +typedef struct dummy_vpp_metrics_struct { + int curr_bytes_in; + int curr_bytes_out; + int curr_packets_in; + int curr_packets_out; + int last_bytes_in; + int last_bytes_out; + int last_packets_in; + int last_packets_out; +} vpp_metrics_struct; + +typedef struct linkstat { + + char linkname[32]; + char linkdescr[64]; + char linkmode[64]; + int speedmbps; + +}LINKSTAT; + +vpp_metrics_struct meas_intfstat[MAX_INTERFACES]; +LINKSTAT meas_linkstat[MAX_INTERFACES]; + +unsigned long long epoch_start = 0; + +int format_val_params(KEYVALRESULT * keyValArray, int numElements, const char *replace, const char *search) +{ + char *sp; + int i =0; + int search_len; + int replace_len; + int tail_len; + + for (i=0; i<numElements; i++) + { + if ((sp = strstr(keyValArray[i].valStr, search)) == NULL) { + printf("\n String not found\n"); + return 1; //Error search string not found + } + + search_len = strlen(search); + replace_len = strlen(replace); + tail_len = strlen(sp+search_len); + memmove(sp+replace_len,sp+search_len,tail_len+1); + memcpy(sp, replace, replace_len); +// printf("\n Changed value for i=%d is %s", i, keyValArray[i].valStr); + } + return 0; //search and replace is successful +} + +void runCommands(KEYVALRESULT * commandArray, int numCommands) +{ + + char buf[BUFSIZE]; /* buffer used to store VPP metrics */ + FILE *fp; /* file descriptor to pipe cmd to shell */ + int i; + + for(i = 0; i < numCommands; i++) + { + memset(buf, 0, BUFSIZE); + + // Open a pipe and read VPP values + if ((fp = popen(commandArray[i].valStr, "r")) == NULL) { + printf("Error opening pipe!\n"); + return; + } + + while (fgets(buf, BUFSIZE, fp) != NULL); + strcpy(commandArray[i].resultStr, buf); + + if(pclose(fp)) { + printf("Command not found or exited with error status\n"); + return; + } + } + //for(i = 0; i < numCommands; i++) + // printf("-%d-valstr and resultStr is- %s - %s\n", i, commandArray[i].valStr, commandArray[i].resultStr); + printf("%d - %d - %d - %d\n", atoi(commandArray[0].resultStr), atoi(commandArray[1].resultStr), atoi(commandArray[2].resultStr), atoi(commandArray[3].resultStr)); +} + + +void copy_vpp_metic_data(vpp_metrics_struct *intfstats, KEYVALRESULT * cmdArray, int numCmds, int linkNum) +{ + int i; + + // Store the current metric in the last metric + intfstats[linkNum].last_bytes_in = intfstats[linkNum].curr_bytes_in; + intfstats[linkNum].last_bytes_out = intfstats[linkNum].curr_bytes_out; + intfstats[linkNum].last_packets_in = intfstats[linkNum].curr_packets_in; + intfstats[linkNum].last_packets_out = intfstats[linkNum].curr_packets_out; + + // Store metrics read from the vNIC in the current + for(i=0; i<numCmds; i++) + { + if((strcmp(cmdArray[i].keyStr, "tmp_t0BytesIn") == 0) || + (strcmp(cmdArray[i].keyStr, "tmp_t1BytesIn") == 0)) + intfstats[linkNum].curr_bytes_in = atoi(cmdArray[i].resultStr); + + if((strcmp(cmdArray[i].keyStr, "tmp_t0BytesOut") == 0) || + (strcmp(cmdArray[i].keyStr, "tmp_t1BytesOut") == 0)) + intfstats[linkNum].curr_bytes_out = atoi(cmdArray[i].resultStr); + + if((strcmp(cmdArray[i].keyStr, "tmp_t0PacketsIn") == 0) || + (strcmp(cmdArray[i].keyStr, "tmp_t1PacketsIn") == 0)) + intfstats[linkNum].curr_packets_in = atoi(cmdArray[i].resultStr); + + if((strcmp(cmdArray[i].keyStr, "tmp_t0PacketsOut") == 0) || + (strcmp(cmdArray[i].keyStr, "tmp_t1PacketsOut") == 0)) + intfstats[linkNum].curr_packets_out = atoi(cmdArray[i].resultStr); + } + // printf("intfstats[%d].curr_bytes_in = %d\n", linkNum, intfstats[linkNum].curr_bytes_in); + // printf("intfstats[%d].curr_bytes_out = %d\n", linkNum, intfstats[linkNum].curr_bytes_out); + // printf("intfstats[%d].curr_packets_in = %d\n", linkNum, intfstats[linkNum].curr_packets_in); + // printf("intfstats[%d].curr_packets_out = %d\n", linkNum, intfstats[linkNum].curr_packets_out); +} + +int get_priority(char * inStr) +{ + int result = -1; + + if(strcmp(inStr, "High") == 0) + result = EVEL_PRIORITY_HIGH; + else if(strcmp(inStr, "Medium") == 0) + result = EVEL_PRIORITY_MEDIUM; + else if(strcmp(inStr, "Normal") == 0) + result = EVEL_PRIORITY_NORMAL; + else if(strcmp(inStr, "Low") == 0) + result = EVEL_PRIORITY_LOW; + + return result; +} + +/**************************************************************************//** + * tap live cpu stats + *****************************************************************************/ +void evel_get_cpu_stats(EVENT_MEASUREMENT * measurement) +{ + FILE *fp; + char path[1024]; + double usage=0.0; + double idle; + double intrpt; + double nice; + double softirq; + double steal; + double sys; + double user; + double wait; + MEASUREMENT_CPU_USE *cpu_use = NULL; + + /* Open the command for reading. */ + //fp = popen("/bin/ls /etc/", "r"); + fp = popen("/usr/bin/top -bn 2 -d 0.01 | grep '^%Cpu' | tail -n 1 ", "r"); + if (fp == NULL) { + printf("Failed to run command\n" ); + exit(1); + } + + /* Read the output a line at a time - output it. */ + while (fgets(path, sizeof(path)-1, fp) != NULL) { + printf("%s", path+10); + sscanf(path+10," %lf us, %lf sy, %lf ni, %lf id, %lf wa, %lf hi, %lf si, %lf st", + &user,&sys,&nice,&idle,&wait,&intrpt,&softirq,&steal); + } + + /* close */ + pclose(fp); + + cpu_use = evel_measurement_new_cpu_use_add(measurement, "cpu1", usage); + if( cpu_use != NULL ){ + + evel_measurement_cpu_use_idle_set(cpu_use,idle); + //evel_measurement_cpu_use_interrupt_set(cpu_use,intrpt); + //evel_measurement_cpu_use_nice_set(cpu_use,nice); + //evel_measurement_cpu_use_softirq_set(cpu_use,softirq); + //evel_measurement_cpu_use_steal_set(cpu_use,steal); + evel_measurement_cpu_use_system_set(cpu_use,sys); + evel_measurement_cpu_use_usageuser_set(cpu_use,user); + //evel_measurement_cpu_use_wait_set(cpu_use,wait); + //evel_measurement_cpu_use_add(measurement, "cpu2", usage,idle,intrpt,nice,softirq,steal,sys,user,wait); + } +} + +int measure_traffic() +{ + + FILE *fp; + int status; + char count[10]; + time_t rawtime; + struct tm * timeinfo; + char period [21]; + char cmd [100]; + char secs [3]; + int sec; + int request_rate=0; + + printf("Checking app traffic\n"); + time (&rawtime); + timeinfo = localtime (&rawtime); + strftime(period,21,"%d/%b/%Y:%H:%M:",timeinfo); + strftime(secs,3,"%S",timeinfo); + sec = atoi(secs); + if (sec == 0) sec = 59; + sprintf(secs, "%02d", sec); + strncat(period, secs, 21); + // ....x....1....x....2. + // 15/Oct/2016:17:51:19 + strcpy(cmd, "sudo docker logs vHello | grep -c "); + strncat(cmd, period, 100); + fp = popen(cmd, "r"); + if (fp == NULL) { + EVEL_ERROR("popen failed to execute command"); + } + + if (fgets(count, 10, fp) != NULL) { + request_rate = atoi(count); + printf("Reporting request rate for second: %s as %d\n", period, request_rate); + + } + else { + EVEL_ERROR("New Measurement failed"); + } + printf("Processed measurement\n"); + + status = pclose(fp); + if (status == -1) { + EVEL_ERROR("pclose returned an error"); + } + return request_rate; +} + + + +int main(int argc, char** argv) +{ + char* fqdn = argv[1]; + int port = atoi(argv[2]); + int i=0; + int rc; + pthread_attr_t attr; + pthread_t meas_thread; + char* fqdn2 = NULL; + int port2 = 0; + + if(argc == 5) + { + fqdn2 = argv[3]; + port2 = atoi(argv[4]); + } + + if (!((argc == 3) || (argc == 5))) + { + fprintf(stderr, "Usage: %s <FQDN>|<IP address> <port> <FQDN>|<IP address> <port> \n", argv[0]); + fprintf(stderr, "OR\n"); + fprintf(stderr, "Usage: %s <FQDN>|<IP address> <port> \n", argv[0]); + exit(-1); + } + + /**************************************************************************/ + /* Initialize */ + /**************************************************************************/ + if(evel_initialize(fqdn, /* FQDN */ + port, /* Port */ + fqdn2, /* Backup FQDN */ + port2, /* Backup port */ + NULL, /* optional path */ + NULL, /* optional topic */ + 100, /* Ring Buffer size */ + 0, /* HTTPS? */ + NULL, /* cert file */ + NULL, /* key file */ + NULL, /* ca info */ + NULL, /* ca file */ + 0, /* verify peer */ + 0, /* verify host */ + "sample1", /* Username */ + "sample1", /* Password */ + "sample1", /* Username2 */ + "sample1", /* Password2 */ + NULL, /* Source ip */ + NULL, /* Source ip2 */ + EVEL_SOURCE_VIRTUAL_MACHINE, /* Source type */ + "vFirewall", /* Role */ + 1)) /* Verbosity */ + { + fprintf(stderr, "\nFailed to initialize the EVEL library!!!\n"); + exit(-1); + } + else + { + printf("\nInitialization completed\n"); + } + + /* Initialize and set thread detached attribute */ + pthread_attr_init(&attr); + pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED); + + printf("Main:Creating thread \n"); + rc = pthread_create(&meas_thread, NULL, MeasThread, &i); + if (rc) + { + printf("ERROR; return code from pthread_create() is %d\n", rc); + exit(-1); + } + printf("Main:Created Meas thread \n"); + + pthread_join(meas_thread, NULL); + + evel_terminate(); + printf("Terminated\n"); + return 0; +} + +void *MeasThread(void *mainMeas) +{ + EVEL_ERR_CODES evel_rc = EVEL_SUCCESS; + EVENT_MEASUREMENT * vpp_m = NULL; + MEASUREMENT_CPU_USE *cpu_use = NULL; + EVENT_HEADER* vpp_m_header = NULL; + int bytes_in; + int bytes_out; + int packets_in; + int packets_out; + unsigned long long epoch_now; + int request_rate = 0; + + struct timeval time_val; + MEASUREMENT_VNIC_PERFORMANCE * vnic_performance = NULL; + char event_id1[10] = "mvfs"; + char event_id2[15] = {0}; + char event_id[BUFSIZE] = {0}; + int meas_event_id = 0; + + int numToken; + jsmntok_t tokens[MAX_TOKENS]; + char js[MAX_BUFFER_SIZE]; + + jsmn_parser p; + char ch[BUFSIZE]; + int ret = 0; + char eName[BUFSIZE]; + char eType[BUFSIZE]; + char nfcCode[BUFSIZE]; + char nfCode[BUFSIZE]; + char prio[BUFSIZE]; + char reportEId[BUFSIZE]; + char reportEName[BUFSIZE]; + char srcId[BUFSIZE]; + char srcName[BUFSIZE]; + char cpuId[BUFSIZE]; + + int priority; + + char hostname[BUFSIZE]; + + int meas_interval; + ARRAYVAL intfArray[MAX_INTERFACES]; + KEYVALRESULT keyValResultArray[32]; + KEYVALRESULT keyValResultArray2[32]; + KEYVALRESULT vnicCommandArray[32]; + KEYVALRESULT cpuUsageCommandArray[32]; + int numInitCommands = 0; + int numVnicCommands = 0; + int numCpuUsageCommands = 0; + int linkCount = 0; + double usage=0.0; + double cpuIdle=0.0; + double cpuSystem=0.0; + double cpuUser=0.0; + double intrpt; + double nice; + double softirq; + double steal; + double wait; + + int i = 0; + + memset(hostname, 0, BUFSIZE); + gethostname(hostname, BUFSIZE); + printf("MeasThread::The hostname is %s\n", hostname); + + sleep(1); + printf("MeasThread::Running Meas thread \n"); + fflush(stdout); + + memset(&intfArray[0],0,(sizeof(ARRAYVAL) * MAX_INTERFACES)); + memset(&keyValResultArray[0],0,(sizeof(KEYVALRESULT) * 32)); + + memset(js, 0, MAX_BUFFER_SIZE); + memset(ch, 0, BUFSIZE); + memset(&meas_intfstat[0],0,(sizeof(vpp_metrics_struct)* MAX_INTERFACES)); + memset(&meas_linkstat[0],0,(sizeof(LINKSTAT) * MAX_INTERFACES)); + + FILE * file = fopen("meas_config.json", "r"); + + while((fgets(ch, (BUFSIZE-1), file)) !=NULL) + { + strcat(js, ch); + memset(ch, 0, BUFSIZE); + } +// printf("MeasThread::the file content is \n %s \n", js); + + jsmn_init(&p); + numToken = jsmn_parse(&p, js, strlen(js), tokens, MAX_TOKENS); + printf("MeasThread::count-%d\n", numToken); + +// printToken(js,tokens, numToken); + + + ret = getIntToken(js, tokens, numToken, "measurementInterval", "tmp_directParameters", &meas_interval); + if (ret != 0) + { + printf("MeasThread::The parameter measurementInterval is not defined, defaulted to 60 seconds\n"); + meas_interval = 60; + } + + ret = getArrayTokens(js, tokens, numToken, "tmp_device", "tmp_directParameters", intfArray, &linkCount); + + printf("MeasThread::Array link count is %d\n", linkCount); + + /* Copy the link information */ + for(i=0;i<linkCount;i++) + { + strcpy(meas_linkstat[i].linkname, &intfArray[i]); +// printf("MeasThread::Link name %s\n", meas_linkstat[i].linkname); + } + + + read_keyVal_params(js, tokens, numToken, "tmp_init", "tmp_indirectParameters", keyValResultArray, &numInitCommands); + + for(i=0;i<linkCount;i++) + { + memset(&vnicCommandArray[0],0,(sizeof(KEYVALRESULT) * 32)); + memcpy(vnicCommandArray, keyValResultArray, (sizeof(KEYVALRESULT) * 32)); + format_val_params(vnicCommandArray, numInitCommands, meas_linkstat[i].linkname, "$tmp_device"); + runCommands(vnicCommandArray, numInitCommands); + copy_vpp_metic_data(meas_intfstat, vnicCommandArray, numInitCommands, i); + } + + gettimeofday(&time_val, NULL); + + sleep(meas_interval); + + /***************************************************************************/ + /* Collect metrics from the VNIC */ + /***************************************************************************/ + while(1) + { + + ret = getIntToken(js, tokens, numToken, "measurementInterval", "tmp_directParameters", &meas_interval); + if (ret != 0) + { + meas_interval = 60; + } + + ret = getStringToken(js, tokens, numToken, "eventName", "tmp_directParameters", eName, BUFSIZE); + if (ret != 0) + { + printf("MeasThread::Missing mandatory parameters - eventName is not there in tmp_directParameters. Exiting...\n"); + exit(1); + } + + ret = getStringToken(js, tokens, numToken, "eventType", "tmp_directParameters", eType, BUFSIZE); + ret = getStringToken(js, tokens, numToken, "nfcNamingCode", "tmp_directParameters", nfcCode, BUFSIZE); + ret = getStringToken(js, tokens, numToken, "nfNamingCode", "tmp_directParameters", nfCode, BUFSIZE); + ret = getStringToken(js, tokens, numToken, "reportingEntityId", "tmp_directParameters", reportEId, BUFSIZE); + ret = getStringToken(js, tokens, numToken, "sourceId", "tmp_directParameters", srcId, BUFSIZE); + ret = getStringToken(js, tokens, numToken, "reportingEntityName", "tmp_directParameters", reportEName, BUFSIZE); + if (ret != 0) + { + printf("MeasThread::Missing mandatory parameters - reportingEntityName is not there in tmp_directParameters\n"); + printf("MeasThread::Defaulting reportingEntityName to hostname\n"); + strcpy(reportEName, hostname); + } + ret = getStringToken(js, tokens, numToken, "sourceName", "tmp_directParameters", srcName, BUFSIZE); + if (ret != 0) + { + printf("MeasThread::Missing mandatory parameters - sourceName is not there in tmp_directParameters\n"); + printf("MeasThread::Defaulting sourceName to hostname\n"); + strcpy(srcName, hostname); + } + + ret = getStringToken(js, tokens, numToken, "priority", "tmp_directParameters", prio, BUFSIZE); + if (ret != 0) + { + printf("MeasThread::Missing mandatory parameters - priority is not there in tmp_directParameters\nDefaulting priority to Low\n"); + strcpy(prio, "Medium"); + } + priority = get_priority(prio); + if(priority == -1) + { + printf("MeasThread::Meas priority value is not matching, prioirty-%s \n", prio); + exit(1); + } + + read_keyVal_params(js, tokens, numToken, "tmp_vnic_command", "vNicPerformance", keyValResultArray, &numVnicCommands); + + for(i=0;i<linkCount;i++) + { + memset(&vnicCommandArray[0],0,(sizeof(KEYVALRESULT) * 32)); + memcpy(vnicCommandArray, keyValResultArray, (sizeof(KEYVALRESULT) * 32)); + format_val_params(vnicCommandArray, numVnicCommands, meas_linkstat[i].linkname, "$tmp_device"); + runCommands(vnicCommandArray, numVnicCommands); + copy_vpp_metic_data(meas_intfstat, vnicCommandArray, numVnicCommands, i); + } + + memset(event_id, 0, BUFSIZE); + meas_event_id = meas_event_id+1; + sprintf(event_id2, "%09d", meas_event_id); + strcat(event_id, event_id1); + strcat(event_id, event_id2); + + vpp_m = evel_new_measurement(meas_interval, eName,event_id); + + if(vpp_m != NULL) + { + printf("New measurement report created...\n"); + + for (int i = 0; i < linkCount; i++) + { + if(meas_intfstat[i].curr_bytes_in - meas_intfstat[i].last_bytes_in > 0) { + bytes_in = meas_intfstat[i].curr_bytes_in - meas_intfstat[i].last_bytes_in; + } + else { + bytes_in = 0; + } + if(meas_intfstat[i].curr_bytes_out - meas_intfstat[i].last_bytes_out > 0) { + bytes_out = meas_intfstat[i].curr_bytes_out - meas_intfstat[i].last_bytes_out; + } + else { + bytes_out = 0; + } + if(meas_intfstat[i].curr_packets_in - meas_intfstat[i].last_packets_in > 0) { + packets_in = meas_intfstat[i].curr_packets_in - meas_intfstat[i].last_packets_in; + } + else { + packets_in = 0; + } + if(meas_intfstat[i].curr_packets_out - meas_intfstat[i].last_packets_out > 0) { + packets_out = meas_intfstat[i].curr_packets_out - meas_intfstat[i].last_packets_out; + } + else { + packets_out = 0; + } + vnic_performance = (MEASUREMENT_VNIC_PERFORMANCE *)evel_measurement_new_vnic_performance(meas_linkstat[i].linkname, "true"); + evel_meas_vnic_performance_add(vpp_m, vnic_performance); + evel_vnic_performance_rx_total_pkt_delta_set(vnic_performance, packets_in); + evel_vnic_performance_tx_total_pkt_delta_set(vnic_performance, packets_out); + + evel_vnic_performance_rx_octets_delta_set(vnic_performance, bytes_in); + evel_vnic_performance_tx_octets_delta_set(vnic_performance, bytes_out); + + if (strcmp(meas_linkstat[i].linkname, "docker") == 0) + { + request_rate = measure_traffic(); + } + } + + evel_measurement_request_rate_set(vpp_m, request_rate); + + //evel_get_cpu_stats(vpp_m); + memset(&keyValResultArray2[0],0,(sizeof(KEYVALRESULT) * 32)); + memset(&cpuUsageCommandArray[0],0,(sizeof(KEYVALRESULT) * 32)); + + ret = getStringToken(js, tokens, numToken, "cpuIdentifier", "cpuUsage", cpuId, BUFSIZE); + if (ret != 0) + { + printf("MeasThread::Missing parameters - cpuIdentifier is not there in cpuUsage, default to Cpu1\n"); + strcpy(cpuId, "Cpu1"); + } + read_keyVal_params(js, tokens, numToken, "tmp_cpuuse_command", "cpuUsage", keyValResultArray2, &numCpuUsageCommands); + memcpy(cpuUsageCommandArray, keyValResultArray2, (sizeof(KEYVALRESULT) * 32)); + runCommands(cpuUsageCommandArray, numCpuUsageCommands); + + cpu_use = evel_measurement_new_cpu_use_add(vpp_m, cpuId, usage); + if( cpu_use != NULL ) + { +/**************************** + for(i=0; i<numCpuUsageCommands; i++) + { + if(strcmp(cpuUsageCommandArray[i].keyStr, "tmp_cpuIdle") == 0) + { + cpuIdle = atof(cpuUsageCommandArray[i].resultStr); + } + if(strcmp(cpuUsageCommandArray[i].keyStr, "tmp_cpuUsageSystem") == 0) + { + cpuSystem = atof(cpuUsageCommandArray[i].resultStr); + } + if(strcmp(cpuUsageCommandArray[i].keyStr, "tmp_cpuUsageUser") == 0) + { + cpuUser = atof(cpuUsageCommandArray[i].resultStr); + } + } **********************/ + printf("%s", cpuUsageCommandArray[0].resultStr); + sscanf(cpuUsageCommandArray[0].resultStr, " %lf us, %lf sy, %lf ni, %lf id, %lf wa, %lf hi, %lf si, %lf st", &cpuUser,&cpuSystem,&nice,&cpuIdle,&wait,&intrpt,&softirq,&steal); +printf("user - %f, system - %f, idle - %f\n", cpuUser, cpuSystem, cpuIdle); + + evel_measurement_cpu_use_idle_set(cpu_use, cpuIdle); + evel_measurement_cpu_use_system_set(cpu_use, cpuSystem); + evel_measurement_cpu_use_usageuser_set(cpu_use, cpuUser); + } + + struct timeval tv_now; + gettimeofday(&tv_now, NULL); + epoch_now = tv_now.tv_usec + 1000000 * tv_now.tv_sec; + + vpp_m_header = (EVENT_HEADER *)vpp_m; + + + if (eType != NULL) + evel_measurement_type_set(vpp_m, eType); + + evel_start_epoch_set(&vpp_m->header, epoch_start); + evel_last_epoch_set(&vpp_m->header, epoch_now); + epoch_start= epoch_now; + + if(nfcCode != NULL) + evel_nfcnamingcode_set(&vpp_m->header, nfcCode); + if(nfCode != NULL) + evel_nfnamingcode_set(&vpp_m->header, nfCode); + evel_reporting_entity_name_set(&vpp_m->header, reportEName); + if(reportEId != NULL) + evel_reporting_entity_id_set(&vpp_m->header, reportEId); + if(srcId != NULL ) + evel_source_id_set(&vpp_m->header, srcId); + if(srcName!= NULL ) + evel_source_name_set(&vpp_m->header, srcName); + + evel_rc = evel_post_event(vpp_m_header); + + if(evel_rc == EVEL_SUCCESS) + printf("MeasThread::Meas event is correctly sent to the collector!\n"); + else + printf("MeasThread::Post failed %d (%s)\n", evel_rc, evel_error_string()); + } + else + { + printf("MeasThread::Measurement event creation failed (%s)\n", evel_error_string()); + } + + sleep(meas_interval); + } + + /***************************************************************************/ + /* Terminate */ + /***************************************************************************/ + sleep(1); +} + diff --git a/vnfs/VES5.0/evel/evel-library/code/evel_library/evel.h b/vnfs/VES5.0/evel/evel-library/code/evel_library/evel.h index d62911de..8cdc4b57 100644 --- a/vnfs/VES5.0/evel/evel-library/code/evel_library/evel.h +++ b/vnfs/VES5.0/evel/evel-library/code/evel_library/evel.h @@ -1622,6 +1622,22 @@ EVENT_HEADER * evel_new_heartbeat(void); *****************************************************************************/ EVENT_HEADER * evel_new_heartbeat_nameid(const char* ev_name, const char *ev_id); +/**************************************************************************//** + * Create a new Heartbeat fields event. + * + * @note The mandatory fields on the Heartbeat fields must be supplied to + * this factory function and are immutable once set. Optional fields + * have explicit setter functions, but again values may only be set + * once so that the event has immutable properties. + * @param ev_name Unique Event Name confirming Domain AsdcModel Description + * @param ev_id A universal identifier of the event for: troubleshooting correlation, analysis, etc + * @param interval heartbeat interval + * @returns pointer to the newly manufactured ::EVENT_HEARTBEAT_FIELD. If the event + * is not used (i.e. posted) it must be released using + * ::evel_free_hrtbt_field. + * @retval NULL Failed to create the event. + *****************************************************************************/ +EVENT_HEARTBEAT_FIELD * evel_new_heartbeat_field(int interval,const char* ev_name, const char *ev_id); /**************************************************************************//** * Free an event header. @@ -1706,6 +1722,17 @@ void evel_reporting_entity_name_set(EVENT_HEADER * const header, const char * const entity_name); /**************************************************************************//** + * Set the Source Name property of the event header. + * + * @note The Source Name defaults to the OpenStack VM Name. + * + * @param header Pointer to the ::EVENT_HEADER. + * @param entity_name The source name to set. + *****************************************************************************/ +void evel_source_name_set(EVENT_HEADER * const header, + const char * const source_name); + +/**************************************************************************//** * Set the Reporting Entity Id property of the event header. * * @note The Reporting Entity Id defaults to the OpenStack VM UUID. @@ -1717,6 +1744,17 @@ void evel_reporting_entity_id_set(EVENT_HEADER * const header, const char * const entity_id); /**************************************************************************//** + * Set the Source Id property of the event header. + * + * @note The Source Id defaults to the OpenStack VM UUID. + * + * @param header Pointer to the ::EVENT_HEADER. + * @param entity_id The Source id to set. + *****************************************************************************/ +void evel_source_id_set(EVENT_HEADER * const header, + const char * const source_id); + +/**************************************************************************//** * Set the NFC Naming code property of the event header. * * @param header Pointer to the ::EVENT_HEADER. diff --git a/vnfs/VES5.0/evel/evel-library/code/evel_library/evel_event.c b/vnfs/VES5.0/evel/evel-library/code/evel_library/evel_event.c index 1656fa75..89c5c15e 100644 --- a/vnfs/VES5.0/evel/evel-library/code/evel_library/evel_event.c +++ b/vnfs/VES5.0/evel/evel-library/code/evel_library/evel_event.c @@ -411,6 +411,35 @@ void evel_reporting_entity_name_set(EVENT_HEADER * const header, } /**************************************************************************//** + * Set the Source Name property of the event header. + * + * @note The Source Name defaults to the OpenStack VM Name. + * + * @param header Pointer to the ::EVENT_HEADER. + * @param entity_name The source name to set. + *****************************************************************************/ +void evel_source_name_set(EVENT_HEADER * const header, + const char * const source_name) +{ + EVEL_ENTER(); + + /***************************************************************************/ + /* Check preconditions and assign the new value. */ + /***************************************************************************/ + assert(header != NULL); + assert(source_name != NULL); + + /***************************************************************************/ + /* Free the previously allocated memory and replace it with a copy of the */ + /* provided one. */ + /***************************************************************************/ + free(header->source_name); + header->source_name = strdup(source_name); + + EVEL_EXIT(); +} + +/**************************************************************************//** * Set the Reporting Entity Id property of the event header. * * @note The Reporting Entity Id defaults to the OpenStack VM UUID. @@ -440,6 +469,35 @@ void evel_reporting_entity_id_set(EVENT_HEADER * const header, } /**************************************************************************//** + * Set the Source Id property of the event header. + * + * @note The Source Id defaults to the OpenStack VM UUID. + * + * @param header Pointer to the ::EVENT_HEADER. + * @param entity_id The Source id to set. + *****************************************************************************/ +void evel_source_id_set(EVENT_HEADER * const header, + const char * const source_id) +{ + EVEL_ENTER(); + + /***************************************************************************/ + /* Check preconditions and assign the new value. */ + /***************************************************************************/ + assert(header != NULL); + assert(source_id != NULL); + + /***************************************************************************/ + /* Free the previously allocated memory and replace it with a copy of the */ + /* provided one. Note that evel_force_option_string strdups entity_id. */ + /***************************************************************************/ + evel_free_option_string(&header->source_id); + evel_force_option_string(&header->source_id, source_id); + + EVEL_EXIT(); +} + +/**************************************************************************//** * Encode the event as a JSON event object according to AT&T's schema. * * @param jbuf Pointer to the ::EVEL_JSON_BUFFER to encode into. diff --git a/vnfs/VES5.0/evel/evel-library/code/evel_library/evel_event_mgr.c b/vnfs/VES5.0/evel/evel-library/code/evel_library/evel_event_mgr.c index 347f0284..cc676a6f 100644 --- a/vnfs/VES5.0/evel/evel-library/code/evel_library/evel_event_mgr.c +++ b/vnfs/VES5.0/evel/evel-library/code/evel_library/evel_event_mgr.c @@ -64,6 +64,7 @@ static bool evel_token_equals_string(const MEMORY_CHUNK * const chunk, const jsmntok_t * const json_token, const char * check_string); static EVEL_ERR_CODES evel_setup_curl(); +static EVEL_ERR_CODES evel_send_to_another_collector(const EVEL_EVENT_DOMAINS evel_domain, char * json_body, size_t json_size); /**************************************************************************//** * Buffers for error strings from libcurl. @@ -135,8 +136,8 @@ static char * evel_password = NULL; static char * evel_username2 = NULL; static char * evel_password2 = NULL; -static int http_response_code = 0; -static int evel_collector_id = 0; +static long http_response_code = 0; +static int evel_collector_id = 1; /**************************************************************************//** * Initialize the event handler. * @@ -224,7 +225,7 @@ EVEL_ERR_CODES event_handler_initialize(const char * const event_api_url, } /***************************************************************************/ - /* Store other parameters + /* Store other parameters */ /***************************************************************************/ evel_secure = secure; evel_verbosity = verbosity; @@ -349,10 +350,10 @@ static EVEL_ERR_CODES evel_setup_curl() EVEL_ENTER(); - if (evel_collector_id > 4) + if (evel_collector_id > 2) { rc = EVEL_CURL_LIBRARY_FAIL; - log_error_state("Wrong evel_collector- value > 4"); + log_error_state("Wrong evel_collector- value > 2"); goto exit_label; } @@ -374,21 +375,6 @@ static EVEL_ERR_CODES evel_setup_curl() username = evel_username2; password = evel_password2; } - else if (evel_collector_id == 3) - { - api_url = evel_batch_api_url; - source_ip = evel_source_ip; - username = evel_username; - password = evel_password; - } - else if (evel_collector_id == 4) - { - api_url = evel_bbatch_api_url; - source_ip = evel_source_ip_bakup; - username = evel_username2; - password = evel_password2; - } - /***************************************************************************/ /* Clean-up the cURL library. */ /***************************************************************************/ @@ -1021,6 +1007,57 @@ exit_label: } /**************************************************************************//** + * Send event to another collector + * + * Identify the next collector and try sending the event to that collector + ****************************************************************************/ +static EVEL_ERR_CODES evel_send_to_another_collector( + const EVEL_EVENT_DOMAINS evel_domain, + char * json_body, + size_t json_size) +{ + int rc = EVEL_SUCCESS; + CURLcode curl_rc; + + EVEL_ENTER(); + + if ((evel_collector_id == 1) && (curr_global_handles == 2)) + { + evel_collector_id =2; + } + else if (evel_collector_id == 2) + { + evel_collector_id =1; + } + + rc = evel_setup_curl(); + + if ( rc == EVEL_SUCCESS) + { + if (evel_collector_id == 1) + { + if (evel_domain == EVEL_DOMAIN_BATCH) + curl_rc = curl_easy_setopt(curl_handle, CURLOPT_URL, evel_batch_api_url); + else + curl_rc = curl_easy_setopt(curl_handle, CURLOPT_URL, evel_event_api_url); + } + else if (evel_collector_id == 2) + { + if (evel_domain == EVEL_DOMAIN_BATCH) + curl_rc = curl_easy_setopt(curl_handle, CURLOPT_URL, evel_bbatch_api_url); + else + curl_rc = curl_easy_setopt(curl_handle, CURLOPT_URL, evel_bevent_api_url); + } + + rc = evel_post_api(json_body, json_size); + } + + EVEL_EXIT(); + + return rc; +} + +/**************************************************************************//** * Callback function to provide data to send. * * Copy data into the supplied buffer, read_callback::ptr, checking size @@ -1135,6 +1172,50 @@ static void * event_handler(void * arg __attribute__ ((unused))) EVEL_ERROR("Event Handler State was not INACTIVE at start-up - " "Handler will exit immediately!"); } + /***************************************************************************/ + /* Set the connection to collector */ + /***************************************************************************/ + while (true) + { + evel_collector_id = 1; + rc = evel_setup_curl(); + + if ( rc != EVEL_SUCCESS) + { + EVEL_ERROR("Failed to setup the first collector. Error code=%d", rc); + if (curr_global_handles == 2) + { + EVEL_DEBUG("Switching to other collector"); + + evel_collector_id = 2; + + rc = evel_setup_curl(); + if ( rc != EVEL_SUCCESS) + { + EVEL_ERROR("Failed to setup the connection to second collector also, Error code%d", rc); + sleep(EVEL_COLLECTOR_RECONNECTION_WAIT_TIME); + collector_down_count = collector_down_count + 1; + EVEL_ERROR("Collectors setup issue- retry count=%d", collector_down_count); + } + else + { + collector_down_count = 0; + break; + } + } + else + { + sleep(EVEL_COLLECTOR_RECONNECTION_WAIT_TIME); + collector_down_count = collector_down_count + 1; + EVEL_ERROR("Collector setup issue-retry count=%d", collector_down_count); + } + } + else + { + collector_down_count = 0; + break; + } + } while (evt_handler_state == EVT_HANDLER_ACTIVE) { @@ -1158,54 +1239,9 @@ static void * event_handler(void * arg __attribute__ ((unused))) json_size = evel_json_encode_batch_event(json_body, EVEL_MAX_JSON_BODY, msg); /***************************************************************************/ - /* Set the connection to collector */ - /***************************************************************************/ - while (true) - { - evel_collector_id =3; - rc = evel_setup_curl(); - - if ( rc != EVEL_SUCCESS) - { - EVEL_ERROR("Failed to setup the first collector. Error code=%d", rc); - if (curr_global_handles == 2) - { - EVEL_DEBUG("Switching to other collector"); - - evel_collector_id = 4; - - rc = evel_setup_curl(); - if ( rc != EVEL_SUCCESS) - { - EVEL_ERROR("Failed to setup the connection to second collector also, Error code%d", rc); - sleep(EVEL_COLLECTOR_RECONNECTION_WAIT_TIME); - collector_down_count = collector_down_count + 1; - EVEL_ERROR("Collectors setup issue- retry count=%d", collector_down_count); - } - else - { - break; - collector_down_count = 0; - } - } - else - { - sleep(EVEL_COLLECTOR_RECONNECTION_WAIT_TIME); - collector_down_count = collector_down_count + 1; - EVEL_ERROR("Collector setup issue-retry count=%d", collector_down_count); - } - } - else - { - break; - collector_down_count = 0; - } - } - - /***************************************************************************/ /* Set the URL for the API. */ /***************************************************************************/ - if (evel_collector_id == 3) + if (evel_collector_id == 1) { curl_rc = curl_easy_setopt(curl_handle, CURLOPT_URL, evel_batch_api_url); } @@ -1242,45 +1278,51 @@ static void * event_handler(void * arg __attribute__ ((unused))) while (true) { - if ((evel_collector_id == 3) && (curr_global_handles == 2)) + if (curr_global_handles == 2) { - evel_collector_id =4; + rc = evel_send_to_another_collector(msg->event_domain, json_body, json_size); + + switch_coll = 0; + if ((rc == EVEL_SUCCESS) && ((http_response_code / 100) != 2)) + { + switch_coll = 1; + if (http_response_code == 400) // 400 - Bad JSON related return code + switch_coll = 0; + } + if ((rc != EVEL_SUCCESS) || (switch_coll == 1)) + { + sleep(EVEL_COLLECTOR_RECONNECTION_WAIT_TIME); + collector_down_count = collector_down_count + 1; + EVEL_ERROR("Collector setup issue-retry count=%d", collector_down_count); + } + else + { + break; + } } - else if (evel_collector_id == 4) + else { - evel_collector_id =3; + sleep(EVEL_COLLECTOR_RECONNECTION_WAIT_TIME); + collector_down_count = collector_down_count + 1; + EVEL_ERROR("Collector setup issue-retry count=%d", collector_down_count); } - rc = evel_setup_curl(); - - if ( rc != EVEL_SUCCESS) - { - sleep(EVEL_COLLECTOR_RECONNECTION_WAIT_TIME); - collector_down_count = collector_down_count + 1; - EVEL_ERROR("Collector setup issue-retry count=%d", collector_down_count); - continue; - } + rc = evel_send_to_another_collector(msg->event_domain, json_body, json_size); - if (evel_collector_id == 3) - { - curl_rc = curl_easy_setopt(curl_handle, CURLOPT_URL, evel_batch_api_url); - } - else if (evel_collector_id == 4) + switch_coll = 0; + if ((rc == EVEL_SUCCESS) && ((http_response_code / 100) != 2)) { - curl_rc = curl_easy_setopt(curl_handle, CURLOPT_URL, evel_bbatch_api_url); + switch_coll = 1; + if (http_response_code == 400) // 400 - Bad JSON related return code + switch_coll = 0; } - - rc = evel_post_api(json_body, json_size); - if ( rc != EVEL_SUCCESS) + if ((rc != EVEL_SUCCESS) || (switch_coll == 1)) { - sleep(EVEL_COLLECTOR_RECONNECTION_WAIT_TIME); collector_down_count = collector_down_count + 1; EVEL_ERROR("Collector setup issue-retry count=%d", collector_down_count); - continue; } else { - EVEL_DEBUG("Successfully sent msg after retry=%d", collector_down_count); break; } } @@ -1296,57 +1338,12 @@ static void * event_handler(void * arg __attribute__ ((unused))) json_size = evel_json_encode_event(json_body, EVEL_MAX_JSON_BODY, msg); /***************************************************************************/ - /* Set the connection to collector */ - /***************************************************************************/ - while (true) - { - evel_collector_id = 1; - rc = evel_setup_curl(); - - if ( rc != EVEL_SUCCESS) - { - EVEL_ERROR("Failed to setup the first collector. Error code=%d", rc); - if (curr_global_handles == 2) - { - EVEL_DEBUG("Switching to other collector"); - - evel_collector_id = 2; - - rc = evel_setup_curl(); - if ( rc != EVEL_SUCCESS) - { - EVEL_ERROR("Failed to setup the connection to second collector also, Error code%d", rc); - sleep(EVEL_COLLECTOR_RECONNECTION_WAIT_TIME); - collector_down_count = collector_down_count + 1; - EVEL_ERROR("Collectors setup issue- retry count=%d", collector_down_count); - } - else - { - break; - collector_down_count = 0; - } - } - else - { - sleep(EVEL_COLLECTOR_RECONNECTION_WAIT_TIME); - collector_down_count = collector_down_count + 1; - EVEL_ERROR("Collector setup issue-retry count=%d", collector_down_count); - } - } - else - { - break; - collector_down_count = 0; - } - } - /***************************************************************************/ /* Set the URL for the API. */ /***************************************************************************/ if (evel_collector_id == 1) curl_rc = curl_easy_setopt(curl_handle, CURLOPT_URL, evel_event_api_url); else curl_rc = curl_easy_setopt(curl_handle, CURLOPT_URL, evel_bevent_api_url); - if (curl_rc != CURLE_OK) { rc = EVEL_CURL_LIBRARY_FAIL; @@ -1375,45 +1372,51 @@ static void * event_handler(void * arg __attribute__ ((unused))) while (true) { - if ((evel_collector_id == 1) && (curr_global_handles == 2)) + if (curr_global_handles == 2) { - evel_collector_id =2; + rc = evel_send_to_another_collector(msg->event_domain, json_body, json_size); + + switch_coll = 0; + if ((rc == EVEL_SUCCESS) && ((http_response_code / 100) != 2)) + { + switch_coll = 1; + if (http_response_code == 400) // 400 - Bad JSON related return code + switch_coll = 0; + } + if ((rc != EVEL_SUCCESS) || (switch_coll == 1)) + { + sleep(EVEL_COLLECTOR_RECONNECTION_WAIT_TIME); + collector_down_count = collector_down_count + 1; + EVEL_ERROR("Collector setup issue-retry count=%d", collector_down_count); + } + else + { + break; + } } - else if (evel_collector_id == 2) + else { - evel_collector_id =1; + sleep(EVEL_COLLECTOR_RECONNECTION_WAIT_TIME); + collector_down_count = collector_down_count + 1; + EVEL_ERROR("Collector setup issue-retry count=%d", collector_down_count); } - rc = evel_setup_curl(); - - if ( rc != EVEL_SUCCESS) - { - sleep(EVEL_COLLECTOR_RECONNECTION_WAIT_TIME); - collector_down_count = collector_down_count + 1; - EVEL_ERROR("Collector setup issue-retry count=%d", collector_down_count); - continue; - } + rc = evel_send_to_another_collector(msg->event_domain, json_body, json_size); - if (evel_collector_id == 1) - { - curl_rc = curl_easy_setopt(curl_handle, CURLOPT_URL, evel_event_api_url); - } - else if (evel_collector_id == 2) + switch_coll = 0; + if ((rc == EVEL_SUCCESS) && ((http_response_code / 100) != 2)) { - curl_rc = curl_easy_setopt(curl_handle, CURLOPT_URL, evel_bevent_api_url); + switch_coll = 1; + if (http_response_code == 400) // 400 - Bad JSON related return code + switch_coll = 0; } - - rc = evel_post_api(json_body, json_size); - if ( rc != EVEL_SUCCESS) + if ((rc != EVEL_SUCCESS) || (switch_coll == 1)) { - sleep(EVEL_COLLECTOR_RECONNECTION_WAIT_TIME); collector_down_count = collector_down_count + 1; EVEL_ERROR("Collector setup issue-retry count=%d", collector_down_count); - continue; } else { - EVEL_DEBUG("Successfully sent msg after retry=%d", collector_down_count); break; } } diff --git a/vnfs/VES5.0/evel/evel-library/code/evel_library/evel_heartbeat_fields.c b/vnfs/VES5.0/evel/evel-library/code/evel_library/evel_heartbeat_fields.c index 031632a3..be8527c4 100644 --- a/vnfs/VES5.0/evel/evel-library/code/evel_library/evel_heartbeat_fields.c +++ b/vnfs/VES5.0/evel/evel-library/code/evel_library/evel_heartbeat_fields.c @@ -36,10 +36,9 @@ * this factory function and are immutable once set. Optional fields * have explicit setter functions, but again values may only be set * once so that the event has immutable properties. - * @param event_name Unique Event Name confirming Domain AsdcModel Description - * @param event_id A universal identifier of the event for: troubleshooting correlation, analysis, etc - * @param vendor_id The vendor id to encode in the event instance id. - * @param event_id The vendor event id to encode in the event instance id. + * @param ev_name Unique Event Name confirming Domain AsdcModel Description + * @param ev_id A universal identifier of the event for: troubleshooting correlation, analysis, etc + * @param interval heartbeat interval * @returns pointer to the newly manufactured ::EVENT_HEARTBEAT_FIELD. If the event * is not used (i.e. posted) it must be released using * ::evel_free_hrtbt_field. diff --git a/vnfs/VES5.0/evel/evel-library/libs/x86_64/libevel.a b/vnfs/VES5.0/evel/evel-library/libs/x86_64/libevel.a Binary files differnew file mode 100755 index 00000000..b35d58e0 --- /dev/null +++ b/vnfs/VES5.0/evel/evel-library/libs/x86_64/libevel.a |