From e987dff7d71bf2255646df58bf22fa603f8d3935 Mon Sep 17 00:00:00 2001 From: PrakashH Date: Tue, 29 Jan 2019 20:41:28 +0000 Subject: VES 7.1 C Lib/Agent Enhancements HB-Fault-Measurement-Syslog-2Collector enhancement Issue-ID: VNFSDK-364 Change-Id: Iba5dc8b0493431a23de4fb8e24b6fc3a6661c4e4 Signed-off-by: PrakashH --- .../code/VESreporting_vFW/.meas_config.json.swp | Bin 0 -> 12288 bytes .../evel-library/code/VESreporting_vFW/LICENSE.TXT | 22 + .../evel-library/code/VESreporting_vFW/Makefile | 52 ++ .../evel-library/code/VESreporting_vFW/README.md | 37 ++ .../evel-library/code/VESreporting_vFW/dep.xml | 25 + .../code/VESreporting_vFW/go-client.sh | 6 + .../VESreporting_vFW/go-client_2_collectors.sh | 12 + .../evel/evel-library/code/VESreporting_vFW/jsmn.c | 672 ++++++++++++++++++++ .../evel/evel-library/code/VESreporting_vFW/jsmn.h | 136 ++++ .../code/VESreporting_vFW/meas_config.json | 52 ++ .../evel-library/code/VESreporting_vFW/pom.xml | 83 +++ .../VESreporting_vFW/sample_measurement_event.txt | 65 ++ .../VESreporting_vFW/vpp_measurement_reporter.c | 694 +++++++++++++++++++++ 13 files changed, 1856 insertions(+) create mode 100644 veslibrary/ves_clibrary/evel/evel-library/code/VESreporting_vFW/.meas_config.json.swp create mode 100644 veslibrary/ves_clibrary/evel/evel-library/code/VESreporting_vFW/LICENSE.TXT create mode 100644 veslibrary/ves_clibrary/evel/evel-library/code/VESreporting_vFW/Makefile create mode 100644 veslibrary/ves_clibrary/evel/evel-library/code/VESreporting_vFW/README.md create mode 100644 veslibrary/ves_clibrary/evel/evel-library/code/VESreporting_vFW/dep.xml create mode 100755 veslibrary/ves_clibrary/evel/evel-library/code/VESreporting_vFW/go-client.sh create mode 100755 veslibrary/ves_clibrary/evel/evel-library/code/VESreporting_vFW/go-client_2_collectors.sh create mode 100644 veslibrary/ves_clibrary/evel/evel-library/code/VESreporting_vFW/jsmn.c create mode 100644 veslibrary/ves_clibrary/evel/evel-library/code/VESreporting_vFW/jsmn.h create mode 100644 veslibrary/ves_clibrary/evel/evel-library/code/VESreporting_vFW/meas_config.json create mode 100644 veslibrary/ves_clibrary/evel/evel-library/code/VESreporting_vFW/pom.xml create mode 100644 veslibrary/ves_clibrary/evel/evel-library/code/VESreporting_vFW/sample_measurement_event.txt create mode 100644 veslibrary/ves_clibrary/evel/evel-library/code/VESreporting_vFW/vpp_measurement_reporter.c (limited to 'veslibrary/ves_clibrary/evel/evel-library/code/VESreporting_vFW') diff --git a/veslibrary/ves_clibrary/evel/evel-library/code/VESreporting_vFW/.meas_config.json.swp b/veslibrary/ves_clibrary/evel/evel-library/code/VESreporting_vFW/.meas_config.json.swp new file mode 100644 index 0000000..c918d8e Binary files /dev/null and b/veslibrary/ves_clibrary/evel/evel-library/code/VESreporting_vFW/.meas_config.json.swp differ diff --git a/veslibrary/ves_clibrary/evel/evel-library/code/VESreporting_vFW/LICENSE.TXT b/veslibrary/ves_clibrary/evel/evel-library/code/VESreporting_vFW/LICENSE.TXT new file mode 100644 index 0000000..16285cd --- /dev/null +++ b/veslibrary/ves_clibrary/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/veslibrary/ves_clibrary/evel/evel-library/code/VESreporting_vFW/Makefile b/veslibrary/ves_clibrary/evel/evel-library/code/VESreporting_vFW/Makefile new file mode 100644 index 0000000..9d1812f --- /dev/null +++ b/veslibrary/ves_clibrary/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/veslibrary/ves_clibrary/evel/evel-library/code/VESreporting_vFW/README.md b/veslibrary/ves_clibrary/evel/evel-library/code/VESreporting_vFW/README.md new file mode 100644 index 0000000..6921cdc --- /dev/null +++ b/veslibrary/ves_clibrary/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/veslibrary/ves_clibrary/evel/evel-library/code/VESreporting_vFW/dep.xml b/veslibrary/ves_clibrary/evel/evel-library/code/VESreporting_vFW/dep.xml new file mode 100644 index 0000000..fc18229 --- /dev/null +++ b/veslibrary/ves_clibrary/evel/evel-library/code/VESreporting_vFW/dep.xml @@ -0,0 +1,25 @@ + + demo + + tar.gz + + + + + . + / + + *.sh + *.md + *.TXT + *.c + Makefile + + + + + + + diff --git a/veslibrary/ves_clibrary/evel/evel-library/code/VESreporting_vFW/go-client.sh b/veslibrary/ves_clibrary/evel/evel-library/code/VESreporting_vFW/go-client.sh new file mode 100755 index 0000000..b2b3a08 --- /dev/null +++ b/veslibrary/ves_clibrary/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/veslibrary/ves_clibrary/evel/evel-library/code/VESreporting_vFW/go-client_2_collectors.sh b/veslibrary/ves_clibrary/evel/evel-library/code/VESreporting_vFW/go-client_2_collectors.sh new file mode 100755 index 0000000..65f7126 --- /dev/null +++ b/veslibrary/ves_clibrary/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 | | + +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/veslibrary/ves_clibrary/evel/evel-library/code/VESreporting_vFW/jsmn.c b/veslibrary/ves_clibrary/evel/evel-library/code/VESreporting_vFW/jsmn.c new file mode 100644 index 0000000..1d72ba4 --- /dev/null +++ b/veslibrary/ves_clibrary/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 +#include +#include +#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/veslibrary/ves_clibrary/evel/evel-library/code/VESreporting_vFW/jsmn.h b/veslibrary/ves_clibrary/evel/evel-library/code/VESreporting_vFW/jsmn.h new file mode 100644 index 0000000..f9d838b --- /dev/null +++ b/veslibrary/ves_clibrary/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 + +#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/veslibrary/ves_clibrary/evel/evel-library/code/VESreporting_vFW/meas_config.json b/veslibrary/ves_clibrary/evel/evel-library/code/VESreporting_vFW/meas_config.json new file mode 100644 index 0000000..c06172d --- /dev/null +++ b/veslibrary/ves_clibrary/evel/evel-library/code/VESreporting_vFW/meas_config.json @@ -0,0 +1,52 @@ +{ + "tmp_directParameters": { + "eventName": "Measurement_vFirewall-AT&T_nicPerformance", + "eventType": "applicationVnf", + "nfcNamingCode": "AFX", + "nfNamingCode": "AFX", + "nfVendorName": "AT&T", + "priority": "Low", + "reportingEntityId": "cc305d54-75b4-431b-adb2-eb6b9e541234", + "reportingEntityName": "ibcx0001vm002oam001", + "sourceId": "de305d54-75b4-431b-adb2-eb6b9e546014", + "sourceName": "scfx0001vm002cap001", + "timeZoneOffset": "UTC-05:30", + "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/veslibrary/ves_clibrary/evel/evel-library/code/VESreporting_vFW/pom.xml b/veslibrary/ves_clibrary/evel/evel-library/code/VESreporting_vFW/pom.xml new file mode 100644 index 0000000..f9f42eb --- /dev/null +++ b/veslibrary/ves_clibrary/evel/evel-library/code/VESreporting_vFW/pom.xml @@ -0,0 +1,83 @@ + + + + + + org.onap.demo.vnf + demo-aggregator + 1.2.0-SNAPSHOT + ../../pom.xml + + + 4.0.0 + org.onap.demo.vnf.ves5 + ves_vfw_reporting + + + + + + maven-jar-plugin + 2.3.2 + + + default-jar + never + + + + + + maven-assembly-plugin + 2.5.3 + + dep.xml + + + + create-archive + package + + single + + + + + + + org.codehaus.mojo + exec-maven-plugin + + + none + + + + true + + + + + + + diff --git a/veslibrary/ves_clibrary/evel/evel-library/code/VESreporting_vFW/sample_measurement_event.txt b/veslibrary/ves_clibrary/evel/evel-library/code/VESreporting_vFW/sample_measurement_event.txt new file mode 100644 index 0000000..b76b382 --- /dev/null +++ b/veslibrary/ves_clibrary/evel/evel-library/code/VESreporting_vFW/sample_measurement_event.txt @@ -0,0 +1,65 @@ +{ + "event": { + "commonEventHeader": { + "domain": "measurement", + "eventId": "mvfs000000005", + "eventName": "Measurement_vFirewall-AT&T_nicPerformance", + "eventType": "applicationVnf", + "lastEpochMicrosec": 1547139835280053, + "nfNamingCode": "AFX", + "nfVendorName": "AT&T", + "nfcNamingCode": "AFX", + "priority": "Normal", + "reportingEntityId": "cc305d54-75b4-431b-adb2-eb6b9e541234", + "reportingEntityName": "ibcx0001vm002oam001", + "sequence": 0, + "sourceId": "de305d54-75b4-431b-adb2-eb6b9e546014", + "sourceName": "scfx0001vm002cap001", + "startEpochMicrosec": 1547139813738836, + "timeZoneOffset": "UTC-05:30", + "version": "4.1", + "vesEventListenerVersion": "7.1" + }, + "measurementFields": { + "cpuUsageArray": [ + { + "cpuIdentifier": "Cpu1", + "cpuIdle": 25.0, + "cpuUsageSystem": 25.0, + "cpuUsageUser": 33.3, + "percentUsage": 0.0 + } + ], + "measurementFieldsVersion": "4.0", + "measurementInterval": 60, + "nicPerformanceArray": [ + { + "nicIdentifier": "lo", + "receivedOctetsDelta": 2811.0, + "receivedTotalPacketsDelta": 18.0, + "transmittedOctetsDelta": 2811.0, + "transmittedTotalPacketsDelta": 18.0, + "valuesAreSuspect": "true" + }, + { + "nicIdentifier": "enp0s3", + "receivedOctetsDelta": 354.0, + "receivedTotalPacketsDelta": 4.0, + "transmittedOctetsDelta": 350.0, + "transmittedTotalPacketsDelta": 4.0, + "valuesAreSuspect": "true" + }, + { + "nicIdentifier": "docker0", + "receivedOctetsDelta": 0.0, + "receivedTotalPacketsDelta": 0.0, + "transmittedOctetsDelta": 0.0, + "transmittedTotalPacketsDelta": 0.0, + "valuesAreSuspect": "true" + } + ], + "requestRate": 0.0 + } + } +} + diff --git a/veslibrary/ves_clibrary/evel/evel-library/code/VESreporting_vFW/vpp_measurement_reporter.c b/veslibrary/ves_clibrary/evel/evel-library/code/VESreporting_vFW/vpp_measurement_reporter.c new file mode 100644 index 0000000..40bd3aa --- /dev/null +++ b/veslibrary/ves_clibrary/evel/evel-library/code/VESreporting_vFW/vpp_measurement_reporter.c @@ -0,0 +1,694 @@ +/*************************************************************************//** + * + * 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 +#include +#include +#include +#include +#include +#include +#include +#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| | \n", argv[0]); + fprintf(stderr, "OR\n"); + fprintf(stderr, "Usage: %s | \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_NIC_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 nfVendor[BUFSIZE]; + char prio[BUFSIZE]; + char reportEId[BUFSIZE]; + char reportEName[BUFSIZE]; + char srcId[BUFSIZE]; + char srcName[BUFSIZE]; + char timeZOff[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 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_NIC_PERFORMANCE *)evel_measurement_new_nic_performance(meas_linkstat[i].linkname, "true"); + evel_meas_nic_performance_add(vpp_m, vnic_performance); + evel_nic_performance_rx_total_pkt_delta_set(vnic_performance, packets_in); + evel_nic_performance_tx_total_pkt_delta_set(vnic_performance, packets_out); + + evel_nic_performance_rx_octets_delta_set(vnic_performance, bytes_in); + evel_nic_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; iheader, 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(timeZOff != NULL) + evel_time_zone_offset_set(&vpp_m->header, timeZOff); + if(nfVendor != NULL) + evel_nf_vendor_name_set(&vpp_m->header, nfVendor); + 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); +} + -- cgit 1.2.3-korg