diff options
author | PrakashH <pbhandar@techmahindra.com> | 2019-01-30 13:21:45 +0000 |
---|---|---|
committer | PrakashH <pbhandar@techmahindra.com> | 2019-01-30 13:21:45 +0000 |
commit | 3937a2e6a422f5cc6bb012e6c119f61dff76341f (patch) | |
tree | af21d7294ce6d3c1d8770e4bf762c215a2e20345 | |
parent | e03be3845828032fd363b3d9b9ef83424b3428b9 (diff) |
VES5.4.1 EVEL Library enhancements
Readme file update and AFXagent addition
Issue-ID: CERT-17
Change-Id: I77b956a8e16af844c4ae681c7305fad39dbf22f5
Signed-off-by: PrakashH <pbhandar@techmahindra.com>
21 files changed, 2798 insertions, 0 deletions
diff --git a/vnfs/VES5.0/evel/evel-library/code/VESreporting_vAFX/LICENSE.TXT b/vnfs/VES5.0/evel/evel-library/code/VESreporting_vAFX/LICENSE.TXT new file mode 100644 index 00000000..ae12da20 --- /dev/null +++ b/vnfs/VES5.0/evel/evel-library/code/VESreporting_vAFX/LICENSE.TXT @@ -0,0 +1,22 @@ +/* + * ============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. + * + */ diff --git a/vnfs/VES5.0/evel/evel-library/code/VESreporting_vAFX/Makefile b/vnfs/VES5.0/evel/evel-library/code/VESreporting_vAFX/Makefile new file mode 100644 index 00000000..6223b542 --- /dev/null +++ b/vnfs/VES5.0/evel/evel-library/code/VESreporting_vAFX/Makefile @@ -0,0 +1,57 @@ +############################################################################# +# +# 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. +# +############################################################################# + +CC=gcc +ARCH=$(shell getconf LONG_BIT) +CODE_ROOT=$(CURDIR)/../.. +#CODE_ROOT=../VES/evel/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= afx_ves_reporter.o afx_util.o\ + afx_bgpsyslog.o afx_perfmon.o afx_linkmon.o afx_svc.o + +all: afx_ves_reporter + +clean: + rm -f *.o afx_ves_reporter + +%.o: %.c + $(CC) $(CPPFLAGS) $(CFLAGS) $(INCLUDE_DIR) -c $< -o $@ + +afx_ves_reporter.o: afx_ves_reporter.c afx_ves_reporter.h +afx_svc.o: afx_svc.c afx_ves_reporter.h +afx_linkmon.o: afx_linkmon.c afx_ves_reporter.h +afx_perfmon.o: afx_perfmon.c afx_ves_reporter.h +afx_bgpsyslog.o: afx_bgpsyslog.c afx_ves_reporter.h +afx_util.o: afx_util.c afx_ves_reporter.h + +afx_ves_reporter: $(FILEOBJLIST) + $(CC) $(CPPFLAGS) $(CFLAGS) -o afx_ves_reporter \ + $(LIBS_DIR) \ + $(FILEOBJLIST) \ + -lpthread \ + -level \ + -lcurl + + diff --git a/vnfs/VES5.0/evel/evel-library/code/VESreporting_vAFX/README.md b/vnfs/VES5.0/evel/evel-library/code/VESreporting_vAFX/README.md new file mode 100644 index 00000000..509fc180 --- /dev/null +++ b/vnfs/VES5.0/evel/evel-library/code/VESreporting_vAFX/README.md @@ -0,0 +1,110 @@ +PROJECT DESCRIPTION + +The AFX agent is for AT&T internal use only. + +The AFX VES Agent collects and reports telemetry data from vAFX platform to VES Collector. + +This is a multi-threaded application consists of Event Handler thread, Heartbeat thread, link monitor thread, Service Monitor thread, Scaling Measurement thread and BGP (Border Gateway Protocol) Monitoring thread. + +It uses VES Library 5.4.1 version for invoking REST API to send messages to VES Open DCAE collector. Event handler thread is part of VES-Library that invokes CURL REST API calls and sends data to VES Collector over http(s). Event handler monitors data from multiple threads and sends the data once it is available. + + +Afxagent does following initializations + +Uses the VES library API evel_initialize() to initialize the VES library with information such as collector IP, port number, username, password etc +Reads the afxmodules.conf file for thread listings and compares with internal list of threads +Creates the threads based on afxmodules.conf thread listings. + +The contents of afxmodules.conf would be as below. If any of events not required, then you can remove it, so that only the required threads and the corresponding events are generated. + +HeartBeat +LinkMonitor +ServiceMonitor +ScalingMeasurements +SyslogBgp + +The explanation for each entry in afxmodules.conf is given below + +HeartBeat :: This generates periodic heartbeat event + +LinkMonitor :: This thread monitors the status of vNICs using ethtool interface. The list of vNICs that need to be monitored are configured in “afxintf.conf” file. When the status of vNICs change by either Ethernet cable pulled out or Ethernet interface going up and down the changed status is reported. + +ServiceMonitor :: This thread monitors the state of the afx@input* and afx@output* services by running “/bin/systemctl status afx@input*” or “/bin/systemctl status afx@output*” command. If there is a change in status from “active” to “Inactive” then Major severity fault is raised. If the change in status is from “inactive” to “active”, then Normal severity fault is raised. If both services status is inactive, then critical severity fault is raised. + +ScalingMeasurements :: This thread reports CPU load, memory usage and vNIC data in Scaling measurement messages periodically. + +SyslogBgp :: BGP monitoring thread forwards syslog messages in platform along with changes to BGP peer connections. At startup the thread reads “afxfilter.txt” file for the list of Tags including “exabgp”. The Thread forwards only those messages containing the tags in Syslog event to Collector. The thread also monitors BGP messages for connection to peer routers. A Fault event is reported when new connections are made or when existing connections are shut down. + +Compiling +========= +Compile the code as below + +Please note that VES library is compiled already and loaded +go to /demo/vnfs/VES5.0/evel/evel-library/code/VESreporting_vAFX directory +run the command 'make all' + +Make a zip file containing below files +/demo/vnfs/VES5.0/evel/evel-library/code/VESreporting_vAFX/afx_ves_reporter +/demo/vnfs/VES5.0/evel/evel-library/code/VESreporting_vAFX/install +/demo/vnfs/VES5.0/evel/evel-library/code/VESreporting_vAFX/vescred +/demo/vnfs/VES5.0/evel/evel-library/code/VESreporting_vAFX/run +/demo/vnfs/VES5.0/evel/evel-library/code/VESreporting_vAFX/afxmodules.conf +/demo/vnfs/VES5.0/evel/evel-library/code/VESreporting_vAFX/afxintf.conf +/demo/vnfs/VES5.0/evel/evel-library/code/VESreporting_vAFX/afxfilter.txt +libevel.so or libevel.a (or both) from /demo/vnfs/VES5.0/evel/evel-library/libs/x86_64 + + +Running AFXAGENT +================ + +Install below packages in the machine where the afxagent is intend to run + + sudo apt-get install exabgp + sudo apt-get install ethtool + sudo apt-get install libcurl3-dev + +[1] Getting started. +- FTP or SCP the zipped file created above and unzip into machine where afxagent is suppose to run + +[2] Setting up the dynamic linked library of VES +- Take the backup of existing /usr/lib/libevel.so file using the below command. + cp /usr/lib/libevel.so /usr/lib/libevel.so_bakup +- Go to unziped directory where libevel.so file is there and run all these commands from there. + sudo cp libevel.so /usr/lib + sudo ldconfig +[3] Updating the interface info in afxintf.conf file +- Run the "ifconfig" command and list the interfaces in afxintf.conf one below the other. For e.g, if the "ifconfig" shows 2 interfaces "lo" and "ens2", then you should have only below contents in afxintf.conf file. If you have more interfaces, you need to list those interfaces along with other keyword incremented (e.g next one would be, <interface name> DNS3_ RSLOTPORT_VLAN_CLASSTYPE) accordingly. + +lo DNS1_RSLOTPORT_VLAN_CLASSTYPE +ens2 DNS2_RSLOTPORT_VLAN_CLASSTYPE + +[4] Collector information update +- Get the collector IP address, port number, collector login / password +- Update the "vescred.conf" file with collector login and password. If the login/passwd is Sample1 / Passwd1, then "vescred.conf" file should look as below. +Sample1 +Passwd1 + +-Update the file "run" in the below format +./afx_ves_reporter <collector IP address> <collector port number> <credential file vescred.conf> <https/http=1/0> <debug=1/0> + +If collector URL is given as below https://zldcmtn23bdce2coll01.ed926b.mtn23b.tci.att.com:8443/eventListener/v5, + +then your run file would look like below + +unset http_proxy +unset https_proxy +./afx_ves_reporter zldcmtn23bdce2coll01.ed926b.mtn23b.tci.att.com 8443 ./vescred.conf 1 1 + +[5] Install HTTPS certificates. See the onap documentation + +[6] Running of afxagent +- Once the run is file is updated, now we have to run the VES agent using below command. + sudo ./run + +[7] Stopping of afxagent +- You can do CTRL C to stop if are seeing the terminal where afxagent is running. Otherwise, get the process ID and kill it as below + ps -aef | grep run + Kill <run process id> + +[8] Sample events +Event samples are given in sample_afxagent_events.txt file diff --git a/vnfs/VES5.0/evel/evel-library/code/VESreporting_vAFX/afx_bgpsyslog.c b/vnfs/VES5.0/evel/evel-library/code/VESreporting_vAFX/afx_bgpsyslog.c new file mode 100644 index 00000000..9cbb63c5 --- /dev/null +++ b/vnfs/VES5.0/evel/evel-library/code/VESreporting_vAFX/afx_bgpsyslog.c @@ -0,0 +1,353 @@ + /*****************************************************************************//*** + * Copyright(c) <2017>, AT&T Intellectual Property. All other rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: This product includes + * software developed by the AT&T. + * 4. Neither the name of AT&T nor the names of its contributors may be used to + * endorse or promote products derived from this software without specific + * prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY AT&T INTELLECTUAL PROPERTY ''AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL AT&T INTELLECTUAL PROPERTY BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + *****************************************************************************/ + +#include <pthread.h> +#include <stdio.h> +#include <stdlib.h> +#include <ctype.h> +#include <string.h> +#include <stdint.h> +#include <unistd.h> +#include <sys/stat.h> +#include <sys/time.h> +#include <sys/types.h> + +#include "evel.h" +#include "afx_ves_reporter.h" + +/* tracks syslog file */ +static unsigned long long prevpos=0; +/* memory for word parsing */ +static char ** bgp_res = NULL; +/* Search list of words */ +char* searchlist[MAX_SYSLOG_WORDS]; +int numWords=0; + +/**************************************************************************//** + * Sends syslog message with parsed syslog info + * + * @param info Pointer to the line + * @param tag Matched TAG field + * @param sevrty Severity of parsed line Emergency etc. + * + * @retvalue int + *****************************************************************************/ +void report_syslog( char *info, char *tag, char *sevrty ) +{ + EVENT_SYSLOG * psyslog = NULL; + EVEL_ERR_CODES evel_rc = EVEL_SUCCESS; + char vesevid[128]; + + sprintf(vesevid,"Syslog_vAfx_%s",oam_intfaddr); + psyslog = evel_new_syslog("Syslog_vAfx", vesevid, + EVEL_SOURCE_VIRTUAL_MACHINE, + escape_json(info), + tag); + if (psyslog != NULL) + { + evel_header_type_set((EVENT_HEADER *)psyslog, "applicationVnf"); + evel_nfnamingcode_set((EVENT_HEADER *)psyslog, "AFX"); + evel_nfcnamingcode_set((EVENT_HEADER *)psyslog, "AFX"); + evel_syslog_event_source_host_set(psyslog, "Virtual host"); + evel_syslog_facility_set(psyslog, EVEL_SYSLOG_FACILITY_LOCAL0); + evel_syslog_proc_set(psyslog, tag); + //evel_syslog_proc_id_set(psyslog, 1423); + evel_syslog_version_set(psyslog, 1); + //evel_syslog_addl_filter_set(psyslog, "Name1=Value1|Name2=Value2|Name3=Value3"); + evel_syslog_severity_set(psyslog, sevrty); + //evel_syslog_sdid_set(psyslog, "ourSDID@32473"); + //evel_syslog_s_data_set(psyslog,info); + evel_rc = evel_post_event((EVENT_HEADER *)psyslog); + if (evel_rc != EVEL_SUCCESS) + { + EVEL_ERROR(" AFX: Post failed %d (%s)", evel_rc, evel_error_string()); + } + } + else + { + EVEL_ERROR("New Syslog failed"); + } + EVEL_DEBUG("AFX: Processed full Syslog\n"); + +} + +/**************************************************************************//** + * Parses Syslog line for exabgp messages + * Raises BGP Fault event for peer connection setup and teardown + * Sends Syslog events for matching lines + * + * @param line Pointer to line + * + * @retvalue int Returns if matching line + *****************************************************************************/ +int processLine(char *line) +{ + int n_spaces = 0, i; + char *pos; + char *p; + int srchcondn = 0; + int peer_conn = 0; + int peer_reset = 0; + char vesevid[128]; + char sevrty[128]; + char *line_bk = NULL; + int status = 1; /** VFA Status is ACTIVE **/ + + if ((pos=strchr(line, '\n')) != NULL) + *pos = '\0'; + line_bk = strdup(line); + + if( !strstr(line,"EVEL") && !strstr(line,"commonEventHeader") && strstr(line,"exabgp") ) + { + if( strstr(line,"Connected to peer neighbor") ) peer_conn = 1; + else if( strstr(line,"peer reset") ) peer_reset = 1; + + if( peer_conn || peer_reset ) + { + n_spaces = 0; + p = strtok (line, " "); + /* split string and append tokens to 'res' */ + + while (p) { + bgp_res = realloc (bgp_res, sizeof (char*) * ++n_spaces); + + if (bgp_res == NULL){ + EVEL_DEBUG("Memory allocation failed"); + exit (-1); /* memory allocation failed */ + } + + bgp_res[n_spaces-1] = p; + + p = strtok (NULL, " "); + } + + /* realloc one extra element for the last NULL */ + bgp_res = realloc (bgp_res, sizeof (char*) * (n_spaces+1)); + bgp_res[n_spaces] = 0; + + if( n_spaces > 0 && (peer_conn || peer_reset) ) + { + EVEL_DEBUG ("Exabgp %d %d %d\n", peer_conn, peer_reset, n_spaces); + for (i = 0; i < (n_spaces+1); ++i) + { + if( bgp_res[i] != NULL )EVEL_DEBUG ("res[%d] = %s\n", i, bgp_res[i]); + } + if( peer_conn == 1 && n_spaces >= 21 ) + //if( !strcmp(bgp_res[21],"(out)") ) + { + char buf[256]; + EVEL_DEBUG("****************sending clear fault\n"); + sprintf(vesevid,"Fault_vAfx_bgp_nbr_%s",oam_intfaddr); + sprintf(buf," %s %s %s %s %s %s %s %s %s %s %s ", bgp_res[10], bgp_res[11], bgp_res[12], bgp_res[13], bgp_res[14],bgp_res[15], bgp_res[16], bgp_res[17], bgp_res[18], bgp_res[19], bgp_res[20]); + report_fault("Fault_vAfx_bgp_nbr", vesevid, EVEL_SEVERITY_NORMAL, "routing", "lo:0", "Bgp neighbor up alarm","bgp session to remote router is up",bgp_res[16],bgp_res[18],bgp_res[10], status); + } + if( peer_reset == 1 && n_spaces >= 21 ) + //if( !strcmp(bgp_res[21],"Shutdown]") ) + { char buf[256]; + EVEL_DEBUG("****************sending fault\n"); + sprintf(vesevid,"Fault_vAfx_bgp_nbr_%s",oam_intfaddr); + sprintf(buf," %s %s %s %s %s %s %s ", bgp_res[15], bgp_res[16], bgp_res[17], bgp_res[18], bgp_res[19],bgp_res[20], bgp_res[21]); + report_fault("Fault_vAfx_bgp_nbr", vesevid, EVEL_SEVERITY_MAJOR,"routing","lo:0","Bgp neighbor down alarm","bgp session to remote router is down",bgp_res[9],bgp_res[4],bgp_res[7], status); + } + } + } + + }// end exabgp + + + if( !strstr(line_bk,"EVEL") && !strstr(line,"commonEventHeader") && numWords > 0 ){ + for (i=0;i<numWords;i++) + { + if( strstr(line_bk,searchlist[i]) != NULL && + strstr(line_bk,"commonEventHeader") == NULL ) + { + srchcondn = 1; + pos = searchlist[i]; + break; + } + printf("srch:%s:%d:%d\n",searchlist[i],srchcondn,numWords); + } + + if( srchcondn ) + { + strcpy(sevrty,"Informational"); + if( strcasestr(line,"Emergency") != NULL ) strcpy(sevrty,"Emergency"); + else if( strcasestr(line_bk,"Alert") != NULL ) strcpy(sevrty,"Alert"); + else if( strcasestr(line_bk,"Critical") != NULL ) strcpy(sevrty,"Critical"); + else if( strcasestr(line_bk,"Error") != NULL ) strcpy(sevrty,"Error"); + else if( strcasestr(line_bk,"Warn") != NULL ) strcpy(sevrty,"Warning"); + else if( strcasestr(line_bk,"Notice") != NULL ) strcpy(sevrty,"Notice"); + else if( strcasestr(line_bk,"Debug") != NULL ) strcpy(sevrty,"Debug"); + report_syslog(line_bk,pos,sevrty); + } + } + + if(!srchcondn) + free(line_bk); + return srchcondn; + +} + + +/**************************************************************************//** + * function to read last n lines from the file + * at any point without reading the entire file + *****************************************************************************/ +void bgp_tail(FILE* in, int n) +{ + int count = 0; // To count '\n' characters + + // unsigned long long pos (stores upto 2^64 – 1 + // chars) assuming that long long int takes 8 + // bytes + unsigned long long pos; + char str[2*BGPBUFSIZE] = {0}; + + // Go to End of file + if (fseek(in, 0, SEEK_END)) + perror("fseek() failed"); + else + { + // pos will contain no. of chars in + // input file. + pos = ftell(in); + + // search for '\n' characters + while (pos>prevpos) + { + // Move 'pos' away from end of file. + if (!fseek(in, --pos, SEEK_SET)) + { + if (fgetc(in) == '\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; + //printf("Printing %d lines %d -\n", n,pos); + while (fgets(str, sizeof(str), in)) + { + //printf("%s\n", str); + processLine(strdup(str)); + prevpos += strlen(str); + } + } + //printf("\n\n"); +} + + +/**************************************************************************//** + * Thread function to Monitor Syslog for BGP connections + * Reads the filter words from AFX Filter input file + * Starts tailing syslog for BGP messages and filter words + * + * @param threadarg Thread arguments for startup message + * + *****************************************************************************/ +void *BgpLoggingAfxThread(void *threadarg) +{ + FILE* fp; + int i=0,j; + char line[64]; + char *pos; + FILE *file; + int taskid, sum; + char *hello_msg; + struct thread_data *my_data; + + my_data = (struct thread_data *) threadarg; + taskid = my_data->thread_id; + sum = my_data->sum; + hello_msg = my_data->message; + EVEL_DEBUG("Thread %d: %s Sum=%d\n", taskid, hello_msg, sum); + + sleep(1); + + /* Opens filter file and reads word list */ + file = fopen(AFX_SYSLOG_FILE, "r"); + + while(fgets(line, sizeof line, file)!=NULL) { + //check to be sure reading correctly + //printf("%s", line); + if ((pos=strchr(line, '\n')) != NULL) + *pos = '\0'; + remove_spaces(line); + //add each filename into array of programs + if( strlen(line) > 0 ) + { + searchlist[numWords]=strdup(line); + //count number of programs in file + numWords++; + } + } + fclose(file); + + //check to be sure going into array correctly + for (int j=0 ; j<numWords; j++) { + EVEL_DEBUG("Search %s\n", searchlist[j]); + } + + + // Open file in read mode + fp = fopen("/var/log/syslog", "r"); + if (fp == NULL) + { + printf("Error while opening file"); + exit(EXIT_FAILURE); + } + + // call tail() each time + while(1) + { + // read last index lines from the file + bgp_tail(fp, 8); + + // sleep for 3 seconds + // note difference in timestamps in logs + sleep(1); + } + + /* close the file before ending program */ + fclose(fp); + + if( bgp_res != NULL ) free(bgp_res); + + return 0; +} + + diff --git a/vnfs/VES5.0/evel/evel-library/code/VESreporting_vAFX/afx_linkmon.c b/vnfs/VES5.0/evel/evel-library/code/VESreporting_vAFX/afx_linkmon.c new file mode 100644 index 00000000..ac816b2f --- /dev/null +++ b/vnfs/VES5.0/evel/evel-library/code/VESreporting_vAFX/afx_linkmon.c @@ -0,0 +1,191 @@ + /*****************************************************************************//*** + * Copyright(c) <2017>, AT&T Intellectual Property. All other rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: This product includes + * software developed by the AT&T. + * 4. Neither the name of AT&T nor the names of its contributors may be used to + * endorse or promote products derived from this software without specific + * prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY AT&T INTELLECTUAL PROPERTY ''AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL AT&T INTELLECTUAL PROPERTY BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + *****************************************************************************/ + +#include <pthread.h> +#include <stdio.h> +#include <stdlib.h> +#include <ctype.h> +#include <string.h> +#include <stdint.h> +#include <unistd.h> +#include <sys/stat.h> +#include <sys/time.h> +#include <sys/types.h> + +#include "evel.h" +#include "afx_ves_reporter.h" + + +/**************************************************************************//** + * Thread function to Monitor Ethernet links + * Checks status of afx inout and afx output service every service monitor + * interval. It reports fault event at startup and whenever status changes + * + * @param threadarg Thread arguments for startup message + * + * @retvalue int Success 1 service running 0 service inactive + *****************************************************************************/ +void *LinkMonitorAfxThread(void *threadarg) +{ + int taskid, sum; + char *hello_msg; + struct thread_data *my_data; + FILE *fp; + char const* const fileName = AFX_INTERFACE_FILE; + char line[256]; + char cmd[256]; + char intf[256]; + char descr[256]; + char linkdata[256]; + int linkcount = 0; + char *search = ":"; + char *token; + char *pch; + time_t filetime = 0; + int newrun = 1; + int n_spaces = 0, i; + char ** res = NULL; + char *pos; + int tlinkstat; + LINKSTAT intfstats[MAX_INTERFACES]; + char vesevid[128]; + int status = 1; /** VFS Status is Active **/ + + + sleep(1); + my_data = (struct thread_data *) threadarg; + taskid = my_data->thread_id; + sum = my_data->sum; + hello_msg = my_data->message; + EVEL_INFO("AFX: Linkmon Thread %d: %s Sum=%d\n", taskid, hello_msg, sum); + +while(1) +{ + /*Check if file is modified recently */ + if( file_is_modified(fileName, &filetime) ) newrun = 1; + + FILE* file = fopen(fileName, "r"); /* should check the result */ + if( file == NULL ){ + EVEL_ERROR("AFX: Linkmon Interface config file unavailable\n"); + pthread_exit(NULL); + } + + while ( file != NULL && fgets(line, sizeof(line), file)) { + /* note that fgets don't strip the terminating \n, checking its + presence would allow to handle lines longer that sizeof(line) */ + sscanf(line,"%s %s",intf,descr); + //remove_spaces(line); + if ((pos=strchr(line, '\n')) != NULL) + *pos = '\0'; + //printf("%s", line); + sprintf(cmd,"/sbin/ethtool %s\n", intf); + //printf("%s", cmd); + if( newrun ){ + strcpy(intfstats[linkcount].linkname,intf); + strcpy(intfstats[linkcount].linkdescr,line); + } + + /* Open the ethtool interface command for reading. */ + fp = popen(cmd, "r"); + if (fp == NULL) { + EVEL_DEBUG("AFX Linkmon: Failed to run command\n" ); + //pthread_exit(NULL); + sleep(LINK_MONITOR_INTERVAL); + continue; + } + + while( !feof(fp) ) { + /* Read the output a line at a time - output it. */ + while (fgets(linkdata, sizeof(linkdata)-1, fp) != NULL) { + //EVEL_INFO("AFX: LinkMon :%s:",linkdata); + if ((pos=strchr(linkdata, '\n')) != NULL) + *pos = '\0'; + if( strstr(linkdata,"Supported link modes")) + { + pch = strstr(linkdata, search); + while( pch != NULL &&( *pch == ':' || *pch == ' ')) pch++; + if(pch!=NULL){ + //printf("Link mode %s\n",pch); + strcpy(intfstats[linkcount].linkmode,pch); + } + } + else if( strstr(linkdata,"Speed")) + { + token = strtok(linkdata, search); + token = strtok(NULL, search); + intfstats[linkcount].speedmbps = atoi(token); + //printf("Link speed %d\n",intfstats[linkcount].speedmbps); + } + else if( strstr(linkdata,"Link detected:")) + { + /* parse link data for connectivity */ + token = strtok(linkdata, search); + token = strtok(NULL, search); + while( *token == ' ') token++; + if( !strcmp(token,"yes")){ + tlinkstat = 1; + } else { + tlinkstat = 0; + } + if( newrun || tlinkstat != intfstats[linkcount].linkstat) + { + EVEL_DEBUG("AFX LinkMon Status changed report fault\n"); + if( tlinkstat == 1 ){ + sprintf(vesevid,"Fault_vAfx_LinkState_%s",oam_intfaddr); + report_fault("Fault_vAfx_Link_Status",vesevid,EVEL_SEVERITY_NORMAL,"link",intfstats[linkcount].linkdescr,"link up trap_alarm","physical or logical connection to a remote router is up","remrouter","rname",NULL, status); + } else { + sprintf(vesevid,"Fault_vAfx_LinkState_%s",oam_intfaddr); + report_fault("Fault_vAfx_Link_Status",vesevid,EVEL_SEVERITY_CRITICAL,"link",intfstats[linkcount].linkdescr,"link down trap_alarm","physical or logical connection to a remote router is down","remrouter","rname",NULL, status); + } + } + intfstats[linkcount].linkstat = tlinkstat; + } + else if( strstr(linkdata,"Cannot get link status:")) + { + sprintf(vesevid,"Fault_vAfx_LinkState_%s",oam_intfaddr); + report_fault("Fault_vAfx_Link_Status",vesevid,EVEL_SEVERITY_CRITICAL,"link",intfstats[linkcount].linkname,"link down trap_alarm","physical or logical connection to a remote router is down","remrouter","rname",NULL, status); + } + } + } + + /* close */ + pclose(fp); + linkcount++; + } + + newrun = linkcount = 0; + if(file)fclose(file); + + sleep(LINK_MONITOR_INTERVAL); + } + + pthread_exit(NULL); +} + diff --git a/vnfs/VES5.0/evel/evel-library/code/VESreporting_vAFX/afx_perfmon.c b/vnfs/VES5.0/evel/evel-library/code/VESreporting_vAFX/afx_perfmon.c new file mode 100644 index 00000000..9e9d231a --- /dev/null +++ b/vnfs/VES5.0/evel/evel-library/code/VESreporting_vAFX/afx_perfmon.c @@ -0,0 +1,650 @@ + /*****************************************************************************//*** + * Copyright(c) <2017>, AT&T Intellectual Property. All other rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: This product includes + * software developed by the AT&T. + * 4. Neither the name of AT&T nor the names of its contributors may be used to + * endorse or promote products derived from this software without specific + * prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY AT&T INTELLECTUAL PROPERTY ''AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL AT&T INTELLECTUAL PROPERTY BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + *****************************************************************************/ + +#include <pthread.h> +#include <stdio.h> +#include <stdlib.h> +#include <ctype.h> +#include <string.h> +#include <stdint.h> +#include <unistd.h> +#include <sys/stat.h> +#include <sys/time.h> +#include <sys/types.h> + +#include "evel.h" +#include "afx_ves_reporter.h" + +unsigned long long epoch_start = 0; +#define MAX_CHILDREN 100 + + +/**************************************************************************//** + * Utility to compare linknames for ordering + *****************************************************************************/ +int cmpfunc (const void * a, const void * b) +{ + VPP_METRICS_STRUCT *aptr = (VPP_METRICS_STRUCT *)a; + VPP_METRICS_STRUCT *bptr = (VPP_METRICS_STRUCT *)b; + return ( strcmp(aptr->linkname,bptr->linkname) ); +} + + + +/**************************************************************************//** + * Gets CPU Load Statistics + * + * @param measurement Pointer to measurement event + * + * + *****************************************************************************/ +void evel_get_cpu_stats(EVENT_MEASUREMENT * measurement) +{ + FILE *fp; + char path[1024]; + char ** res = NULL; + int n_spaces = 0, i; + char *p; + char cpname[256]; + + double usage=0.0; + double idle; + double intrpt; + double nice; + double softirq; + //double steal; + double sys; + //double user; + double usrl; + //double wait; + MEASUREMENT_CPU_USE *cpu_use = NULL; + + /* Open the command for reading. */ + fp = popen("/usr/bin/mpstat -P ALL ", "r"); + if (fp == NULL) { + EVEL_ERROR(" AFX: Perf thread Failed to run command\n" ); + pthread_exit(NULL); + } + + /* Read the output a line at a time - output it. */ + while (fgets(path, sizeof(path)-1, fp) != NULL) { + //printf("%s",path); + +n_spaces = 0; +p = strtok (path, " "); +/* split string and append tokens to 'res' */ + +while (p) { + res = realloc (res, sizeof (char*) * ++n_spaces); + + if (res == NULL) + exit (-1); /* memory allocation failed */ + + res[n_spaces-1] = p; + + p = strtok (NULL, " "); +} + +/* realloc one extra element for the last NULL */ +res = realloc (res, sizeof (char*) * (n_spaces+1)); +res[n_spaces] = 0; + +/* print the result */ +if( n_spaces > 2 && (!strcmp(res[2],"all") || isdigit(res[2][0])) ) +{ + //for (i = 0; i < (n_spaces+1); ++i) + //{ + // printf ("res[%d] = %s\n", i, res[i]); + //} + if(isdigit(res[2][0])) + { + sprintf (cpname,"cpu%s", res[2]); + } + else + sprintf (cpname,"%s", res[2]); + + usrl = atof(res[3]); + nice = atof(res[4]); + sys = atof(res[4]); + idle = atof(res[12]); + usage = 100.0 - idle; + + //allocate CPU stats structure + cpu_use = evel_measurement_new_cpu_use_add(measurement, cpname, 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,usrl); + //evel_measurement_cpu_use_wait_set(cpu_use,wait); + } +} + + } + +/* free the memory allocated */ +if(res != NULL) free (res); +res = NULL; + + /* close */ + pclose(fp); + +} + +/**************************************************************************//** + * tap live memory stats + *****************************************************************************/ +void evel_get_mem_stats(EVENT_MEASUREMENT * measurement) +{ +char buffer[4096]; +char line[100]; +char c; +int bcount=0,lcount=0; + +double membuffsz=0.0; +double memcache=0.0; +double memconfig=0.0; +double memfree=0.0; +double slab=0.0; +double slabrecl=0.0; +double slabunrecl=0.0; +double memused=0.0; +MEASUREMENT_MEM_USE *mem_use = NULL; + + +FILE * filp = fopen("/proc/meminfo", "rb"); +int bytes_read = fread(buffer, sizeof(char), 4096, filp); +fclose(filp); + +EVEL_INFO("AFX perfmon meminfo %d\n",bytes_read); + +while ( bcount < bytes_read ) +{ + for(lcount=0; buffer[bcount] != '\n';bcount++,lcount++) + { + line[lcount] = buffer[bcount]; + } + if( lcount > 0 ) + { + line[lcount] = '\0'; + //printf("%s\n",line); + if(!strncmp(line,"Buffers:", strlen("Buffers:"))) + { + sscanf(line+strlen("Buffers:"),"%lf",&membuffsz); + //printf("membuff %lf\n",membuffsz); + } + else if(!strncmp(line,"Cached:", strlen("Cached:"))) + { + sscanf(line+strlen("Cached:"),"%lf",&memcache); + } + else if(!strncmp(line,"MemTotal:", strlen("MemTotal:"))) + { + sscanf(line+strlen("MemTotal:"),"%lf",&memconfig); + } + else if(!strncmp(line,"MemFree:", strlen("MemFree:"))) + { + sscanf(line+strlen("MemFree:"),"%lf",&memfree); + } + else if(!strncmp(line,"Slab:", strlen("Slab:"))) + { + sscanf(line+strlen("Slab:"),"%lf",&slab); + } + else if(!strncmp(line,"SReclaimable:", strlen("SReclaimable:"))) + { + sscanf(line+strlen("SReclaimable:"),"%lf",&slabrecl); + } + else if(!strncmp(line,"SUnreclaim:", strlen("SUnreclaim:"))) + { + sscanf(line+strlen("SUnreclaim:"),"%lf",&slabunrecl); + } + } + bcount++; +} + +memused = memconfig - memfree - membuffsz - memcache - slab; +EVEL_INFO(" AFX perfmon memused %lf\n",memused); + + mem_use = evel_measurement_new_mem_use_add(measurement, "RAM", hostname, membuffsz); + evel_measurement_mem_use_memcache_set(mem_use,memcache); + evel_measurement_mem_use_memconfig_set(mem_use,memconfig); + evel_measurement_mem_use_memfree_set(mem_use,memfree); + evel_measurement_mem_use_slab_reclaimed_set(mem_use,slabrecl); + evel_measurement_mem_use_slab_unreclaimable_set(mem_use,slabunrecl); + evel_measurement_mem_use_usedup_set(mem_use,memused); + +} + +/** + * System command execution output + * @param <char> command - system command to execute + * @returb <char> execution output + */ +char *system_output (const char *command) +{ + FILE *pipe; + static char out[512]; + out[0]= '\0'; + pipe = popen (command, "r"); + if( pipe != NULL ) + { + fgets (out, sizeof(out), pipe); + pclose (pipe); + } + return out; +} + + +/** + * Finding all process's children + * @param <Int> - process ID + * @param <Int> - array of childs + */ +void find_children (int pid, int children[]) +{ + int child_pid, i = 1; + char empty_command[] = "/bin/ps h -o pid --ppid "; + char pid_string[5]; + + snprintf(pid_string, 5, "%d", pid); + + char *command = (char*) malloc(strlen(empty_command) + strlen(pid_string) + 1); + sprintf(command, "%s%s", empty_command, pid_string); + + FILE *fp = popen(command, "r"); + if( fp != NULL ) + { + while (fscanf(fp, "%i", &child_pid) != EOF) + { + children[i] = child_pid; + i++; + } + } + free(command); + pclose(fp); +} + + +/** + * Parsign `ps` command output + * @param <char> out - ps command output + * @return <int> cpu utilization + */ +int parse_cpu_utilization (char *out, float *pcpu, float *pmem) +{ + if( strlen(out) > 0 ) + { + sscanf (out, "%f %f", pcpu, pmem); + } + return 0; +} + + +void gather_afx_stats(EVENT_MEASUREMENT *vpp_m,char *lkstr) +{ + double totcpu=0.0,totmem=0.0; + float tmpcpu=0.0,tmpmem=0.0; + FILE *fp; + char path[512]; + char cmd[128]; + char grp[128]; + char cpustr[64]; + char memstr[64]; + char *p; + //unsigned pid = atoi(argv[1]); + unsigned pid; + // getting array with process children + int process_children[MAX_CHILDREN] = { 0 }; + unsigned i; + float common_cpu_usage = 0.0; + + /* Open the command for reading. */ + sprintf(cmd," pgrep -f \"%s\" | xargs --no-run-if-empty ps --no-headers ", lkstr); + fp = popen(cmd, "r"); + if (fp == NULL) { + EVEL_ERROR("AFX meas : Failed to run afx command\n" ); + pthread_exit(NULL); + } + + /* Read the output a line at a time - output it. */ + while ( !feof(fp) ) { + while (fgets(path, sizeof(path)-1, fp) != NULL) { + EVEL_DEBUG("AFX meas : %s",path); + p = &path[0]; + while( p!=NULL && isspace(*p))p++; + if( strstr(p,"sh -c") == NULL && isdigit(*p)) + { + sscanf(p,"%d ",&pid); + //printf(":%d:\n",pid); + process_children[0] = pid; // parent PID as first element + find_children(pid, process_children); + + // calculating summary processor utilization + for (i = 0; i < sizeof(process_children)/sizeof(int); ++i) + { + if (process_children[i] > 0) + { + char *command = (char*)malloc(128); + EVEL_DEBUG ("AFX meas :/bin/ps -p %i -o 'pcpu,pmem' --no-headers\n", process_children[i]); + sprintf (command, "/bin/ps -p %i -o 'pcpu,pmem' --no-headers", process_children[i]); + parse_cpu_utilization(system_output(command),&tmpcpu,&tmpmem); + totcpu += tmpcpu; + totmem += tmpmem; + } + } + sprintf(grp,"%s_%d",lkstr,pid); + EVEL_DEBUG("%s %d CPU %f MEM %f\n", grp, totcpu, totmem); + sprintf(cpustr,"%f",totcpu); + sprintf(memstr,"%f",totmem); + evel_measurement_custom_measurement_add(vpp_m,grp,"cpu",cpustr); + evel_measurement_custom_measurement_add(vpp_m,grp,"mem",memstr); + + } + } + } + pclose(fp); + + +} + + + +/**************************************************************************//** + * tap live afx stats + *****************************************************************************/ +void evel_get_afx_stats(EVENT_MEASUREMENT * measurement) +{ + gather_afx_stats(measurement,"AFXin"); + gather_afx_stats(measurement,"AFXout"); +} + +/**************************************************************************//** + * Thread function to Monitor AFX Performance parameters + * Opens interface list file to get list of interfaces + * Opens Device driver file every READ_INTERVAL and calculates + * Delta packets and bytes + * + * @param threadarg Thread arguments for startup message + * + * + *****************************************************************************/ +void *MeasureAfxThread(void *threadarg) +{ + struct thread_data *my_data; + int taskid, sum; + char *hello_msg; + struct timeval time_val; + int i; + //time_t start_epoch; + //time_t last_epoch; + EVEL_ERR_CODES evel_rc = EVEL_SUCCESS; + EVENT_MEASUREMENT* vpp_m = NULL; + EVENT_HEADER* vpp_m_header = NULL; + MEASUREMENT_VNIC_PERFORMANCE * vnic_performance = NULL; + //struct timeval tv_start; + FILE *fp; + char const* const fileName = AFX_INTERFACE_FILE; + char line[256]; + char intf[256]; + char descr[256]; + char linkdata[256]; + int linkcount = 0; + time_t filetime = 0; + int newrun = 0; + int n_spaces = 0, j; + char ** res = NULL; + char *pos; + char *p; + int tlinkstat; + VPP_METRICS_STRUCT intfstats[MAX_INTERFACES]; + VPP_METRICS_STRUCT *ptritem; + uint64_t curr_rx_bytes; + uint64_t curr_rx_packets; + uint64_t curr_rx_mcast; + uint64_t curr_tx_bytes; + uint64_t curr_tx_packets; + char vesevid[128]; + + + sleep(1); + my_data = (struct thread_data *) threadarg; + taskid = my_data->thread_id; + sum = my_data->sum; + hello_msg = my_data->message; + EVEL_INFO("AFX Perf Thread %d: %s Sum=%d\n", taskid, hello_msg, sum); + sprintf(vesevid,"measurementsForVfScaling_vAfx_%s",get_oam_intfaddr()); + + gettimeofday(&time_val, NULL); + epoch_start = time_val.tv_sec * 1000000 + time_val.tv_usec; + sleep(PERF_MONITOR_INTERVAL); + + while(1) { + + if( file_is_modified(fileName, &filetime) ) newrun = 1; + + if( newrun ) { + + linkcount = 0; + FILE* file = fopen(fileName, "r"); /* should check the result */ + + while ( file != NULL && fgets(line, sizeof(line), file)) { + /* note that fgets don't strip the terminating \n, checking its + presence would allow to handle lines longer that sizeof(line) */ + //printf("%s", line); + sscanf(line,"%s %s",intf,descr); + //remove_spaces(line); + if ((pos=strchr(line, '\n')) != NULL) + *pos = '\0'; + if( newrun ){ + memset(&intfstats[linkcount],0,sizeof(VPP_METRICS_STRUCT)); + strcpy(intfstats[linkcount].linkname,intf); + strcpy(intfstats[linkcount].linkdescr,line); + } + linkcount++; + } + fclose(file); + if ((pos=strchr(line, '\n')) != NULL) + *pos = '\0'; + qsort(intfstats,linkcount,sizeof(VPP_METRICS_STRUCT),cmpfunc); + } + + + /* Open the command for reading. */ + fp = popen("cat /proc/net/dev ", "r"); + if (fp == NULL) { + EVEL_DEBUG("Failed to run net command\n" ); + //exit(1); + sleep(PERF_MONITOR_INTERVAL); + continue; + } + + /* Read the output a line at a time - output it. */ + while ( !feof(fp) ) { + while (fgets(linkdata, sizeof(linkdata)-1, fp) != NULL) { + //printf("%s",linkdata); + +n_spaces = 0; +p = strtok (linkdata, " "); +/* split string and append tokens to 'res' */ + +while (p) { + res = realloc (res, sizeof (char*) * ++n_spaces); + + if (res == NULL){ + EVEL_DEBUG("Memory allocation failed"); + exit (-1); /* memory allocation failed */ + } + + res[n_spaces-1] = p; + + p = strtok (NULL, " "); +} + +/* realloc one extra element for the last NULL */ +res = realloc (res, sizeof (char*) * (n_spaces+1)); +res[n_spaces] = 0; + + + if( !strstr(res[0],"Inter") && !strstr(res[0],"face") ) + { + /* for (i = 0; i < (n_spaces+1); ++i) + { + printf ("res[%d] = %s\n", i, res[i]); + }*/ + if ((pos=strchr(res[0], ':')) != NULL) + *pos = '\0'; + /* using bsearch() to find value 32 in the array */ + ptritem = (VPP_METRICS_STRUCT*) bsearch (res[0], intfstats, linkcount, sizeof(VPP_METRICS_STRUCT), cmpfunc); + if( ptritem == NULL ) + { + EVEL_DEBUG("Item = %s could not be found\n", res[0]); + } + else if( !strcmp(res[0],ptritem->linkname) ) + { + EVEL_DEBUG( "AFX Perf values Link %d rxb %d rxp %d rxm %d txb %d txp %d\n", linkcount, ptritem->rx_bytes, ptritem->rx_packets, ptritem->rx_mcast, ptritem->tx_bytes, ptritem->tx_packets ); + + curr_rx_bytes = strtoull(res[1],NULL,10); + curr_rx_packets = strtoull(res[2],NULL,10); + curr_rx_mcast = strtoull(res[8],NULL,10); + curr_tx_bytes = strtoull(res[9],NULL,10); + curr_tx_packets = strtoull(res[10],NULL,10); + if( !newrun ){ + ptritem->delta_rx_bytes = curr_rx_bytes - ptritem->rx_bytes; + ptritem->delta_rx_packets = curr_rx_packets - ptritem->rx_packets; + ptritem->delta_rx_mcast = curr_rx_mcast - ptritem->rx_mcast; + ptritem->delta_tx_bytes = curr_tx_bytes - ptritem->tx_bytes; + ptritem->delta_tx_packets = curr_tx_packets - ptritem->tx_packets; + } + else + { + ptritem->delta_rx_bytes = 0; + ptritem->delta_rx_packets = 0; + ptritem->delta_rx_mcast = 0; + ptritem->delta_tx_bytes = 0; + ptritem->delta_tx_packets = 0; + } + ptritem->rx_bytes = curr_rx_bytes; + ptritem->rx_packets = curr_rx_packets; + ptritem->rx_mcast = curr_rx_mcast; + ptritem->tx_bytes = curr_tx_bytes; + ptritem->tx_packets = curr_tx_packets; + + //printf( "Acc %s %d %d %d %d %d\n", ptritem->linkname, curr_rx_bytes, curr_rx_packets, curr_rx_mcast, curr_tx_bytes, curr_tx_packets ); + //printf( "Delta %d %d %d %d %d\n", ptritem->delta_rx_bytes, ptritem->delta_rx_packets, ptritem->delta_rx_mcast, ptritem->delta_tx_bytes, ptritem->delta_tx_packets ); + + } + } + } + } + pclose(fp); + newrun = 0; + if(res != NULL) free (res); + res = NULL; + + /***************************************************************************/ + /* Collect metrics from the VNIC */ + /***************************************************************************/ + vpp_m = evel_new_measurement(PERF_MONITOR_INTERVAL,"measurementsForVfScaling_vAfx",vesevid); + + if(vpp_m != NULL) { + evel_header_type_set((EVENT_HEADER *)vpp_m, "applicationVnf"); + evel_nfcnamingcode_set((EVENT_HEADER *)vpp_m, "AFX"); + evel_nfnamingcode_set((EVENT_HEADER *)vpp_m, "AFX"); + EVEL_DEBUG("New measurement report created...\n"); + + for( i=0; i<linkcount;i++) + { + ptritem = &intfstats[i]; + vnic_performance = (MEASUREMENT_VNIC_PERFORMANCE *)evel_measurement_new_vnic_performance + (ptritem->linkdescr, "true"); + + evel_meas_vnic_performance_add(vpp_m, vnic_performance); + + //printf( "Acc %s %d %d %d %d %d\n", ptritem->linkname, curr_rx_bytes, curr_rx_packets, curr_rx_mcast, curr_tx_bytes, curr_tx_packets ); + //printf( "Delta %d %d %d %d %d\n", delta_rx_bytes, delta_rx_packets, delta_rx_mcast, delta_tx_bytes, delta_tx_packets ); + evel_vnic_performance_rx_octets_acc_set(vnic_performance, ptritem->rx_bytes); + evel_vnic_performance_rx_octets_delta_set(vnic_performance, ptritem->delta_rx_bytes); + evel_vnic_performance_tx_octets_acc_set(vnic_performance, ptritem->tx_bytes); + evel_vnic_performance_tx_octets_delta_set(vnic_performance, ptritem->delta_tx_bytes); + + evel_vnic_performance_rx_mcast_pkt_acc_set(vnic_performance, ptritem->rx_mcast); + evel_vnic_performance_rx_mcast_pkt_delta_set(vnic_performance, ptritem->delta_rx_mcast); + + evel_vnic_performance_rx_total_pkt_acc_set(vnic_performance, ptritem->rx_packets); + evel_vnic_performance_rx_total_pkt_delta_set(vnic_performance, ptritem->delta_rx_packets); + evel_vnic_performance_tx_total_pkt_acc_set(vnic_performance, ptritem->tx_packets); + evel_vnic_performance_tx_total_pkt_delta_set(vnic_performance, ptritem->delta_tx_packets); + + } + + evel_get_cpu_stats(vpp_m); + evel_get_mem_stats(vpp_m); + evel_get_afx_stats(vpp_m); + /***************************************************************************/ + /* Set parameters in the MEASUREMENT header packet */ + /***************************************************************************/ + struct timeval tv_now; + gettimeofday(&tv_now, NULL); + unsigned long long epoch_now = tv_now.tv_usec + 1000000 * tv_now.tv_sec; + + //last_epoch = start_epoch + PERF_MONITOR_INTERVAL * 1000000; + vpp_m_header = (EVENT_HEADER *)vpp_m; + evel_start_epoch_set(&vpp_m->header, epoch_start); + evel_last_epoch_set(&vpp_m->header, epoch_now); + epoch_start = epoch_now; + + evel_reporting_entity_name_set(&vpp_m->header, "AFXM"); + evel_reporting_entity_id_set(&vpp_m->header, hostname); + evel_rc = evel_post_event(vpp_m_header); + + if(evel_rc == EVEL_SUCCESS) { + EVEL_DEBUG("Measurement report correctly sent to the collector!\n"); + } + else { + EVEL_DEBUG("Post failed %d (%s)\n", evel_rc, evel_error_string()); + } + } + else { + EVEL_DEBUG("New measurement report failed (%s)\n", evel_error_string()); + } + + sleep(PERF_MONITOR_INTERVAL); + } + + /***************************************************************************/ + /* Terminate */ + /***************************************************************************/ + sleep(1); + + return 0; +} + diff --git a/vnfs/VES5.0/evel/evel-library/code/VESreporting_vAFX/afx_svc.c b/vnfs/VES5.0/evel/evel-library/code/VESreporting_vAFX/afx_svc.c new file mode 100644 index 00000000..e8ff5d42 --- /dev/null +++ b/vnfs/VES5.0/evel/evel-library/code/VESreporting_vAFX/afx_svc.c @@ -0,0 +1,228 @@ + /*****************************************************************************//*** + * Copyright(c) <2017>, AT&T Intellectual Property. All other rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: This product includes + * software developed by the AT&T. + * 4. Neither the name of AT&T nor the names of its contributors may be used to + * endorse or promote products derived from this software without specific + * prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY AT&T INTELLECTUAL PROPERTY ''AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL AT&T INTELLECTUAL PROPERTY BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + *****************************************************************************/ + +#include <pthread.h> +#include <stdio.h> +#include <stdlib.h> +#include <ctype.h> +#include <string.h> +#include <stdint.h> +#include <unistd.h> +#include <sys/stat.h> +#include <sys/time.h> +#include <sys/types.h> + +#include "evel.h" +#include "afx_ves_reporter.h" + +/**************************************************************************//** + * Monitor AFX services for current status + * returns success status 1 or failure 0. + * + * @param cmd Pointer to Shell cmd to monitor status. + * @param dtls Pointer to details of service + * Returns the start time of service + * + * @retvalue int Success 1 service running 0 service inactive + *****************************************************************************/ +int monitor_afx_service( char *cmd, char *detls, char *svc ) +{ + FILE *fp; + char line[256]; + int n_spaces = 0, i; + char ** res = NULL; + char *p; + int ret = 0; + int lnno = 0; + + + fp = popen(cmd,"r"); + if (fp == NULL) { + printf("Failed to run command\n" ); + return 0; + } + + /* Read the output a line at a time - output it. */ + while (fgets(line, sizeof(line)-1, fp) != NULL) { + //printf("%s",line); + lnno++; + +n_spaces = 0; +p = strtok (line, " "); +/* split string and append tokens to 'res' */ + +while (p) { + res = realloc (res, sizeof (char*) * ++n_spaces); + + if (res == NULL) + exit (-1); /* memory allocation failed */ + + res[n_spaces-1] = p; + + p = strtok (NULL, " "); +} + +/* realloc one extra element for the last NULL */ +res = realloc (res, sizeof (char*) * (n_spaces+1)); +res[n_spaces] = 0; + +if( n_spaces > 2 && lnno == 1 ) +{ + EVEL_DEBUG("AFX: Service %s\n",res[3]); + sprintf(svc,"%s",res[3]); + svc[strlen(svc)-1] = 0; +} + +/* print the result */ +if( n_spaces > 2 && !strcmp(res[0],"Active:") ) +{ + //for (i = 0; i < (n_spaces+1); ++i) + //{ + // printf ("res[%d] = %s\n", i, res[i]); + //} + if(!strncmp(res[1],"activ",5)){ + EVEL_DEBUG("AFX: Service Active\n"); + ret |= 1; + } else { + EVEL_DEBUG("AFX: Service Inactive\n"); + ret &= 0; + } +} + + } + +/* free the memory allocated */ +if(res != NULL) free (res); + + /* close */ + pclose(fp); + +return ret; + +} + +/**************************************************************************//** + * Thread function to Monitor AFX services + * Checks status of afx inout and afx output service every service monitor + * interval. It reports fault event at startup and whenever status changes + * + * @param threadarg Thread arguments for startup message + * + * @retvalue int Success 1 service running 0 service inactive + *****************************************************************************/ +void *ServiceMonitorAfxThread(void *threadarg) +{ + int taskid, sum; + char *hello_msg; + struct thread_data *my_data; + char cmd[256]; + char details[256]; + char *afxin = "afx@in*"; + char *afxout = "afx@out*"; + int instate = -1; + int outstate = -1; + int tmpstate; + char evid[128]; + char svc[128]; + int is_critical = 0; + + sleep(1); + my_data = (struct thread_data *) threadarg; + taskid = my_data->thread_id; + sum = my_data->sum; + hello_msg = my_data->message; + EVEL_INFO("AFX: Service Monitor Thread %d: %s Sum=%d\n", taskid, hello_msg, sum); + +while(1) +{ + /* invokes afx service monitor function and collects return value */ + sprintf(cmd,"/bin/systemctl status %s ",afxin); + tmpstate = monitor_afx_service( cmd, details,svc ); + if( tmpstate != instate ){ + printf("New afxin Service report sent %d\n",tmpstate); + instate = tmpstate; + if( instate == 1){ + sprintf(evid,"Fault_vAfx_SvcInput_%s",oam_intfaddr); + if (is_critical == 1){ + is_critical = 0; + sprintf(evid,"Fault_vAfx_SvcOutput_SvcInput_%s",oam_intfaddr); + report_fault("Fault_vAfx_Svc_input_Output",evid, + EVEL_SEVERITY_NORMAL, "routing", "AFXInput and AFXOutput", + "AFX services input and output down alarm", + details, NULL, NULL, NULL, instate); + } + sprintf(evid,"Fault_vAfx_SvcInput_%s",oam_intfaddr); + report_fault("Fault_vAfx_SvcInput",evid,EVEL_SEVERITY_NORMAL, "routing", "AFXInput", "AFX services input up alarm", details, NULL, NULL, NULL, instate); + }else{ + sprintf(evid,"Fault_vAfx_SvcInput_%s",oam_intfaddr); + report_fault("Fault_vAfx_SvcInput",evid,EVEL_SEVERITY_MAJOR, "routing", "AFXInput", "AFX services input down alarm", details, NULL, NULL, NULL, instate); + } + } + + /* invokes afx service monitor function and collects return value */ + sprintf(cmd,"/bin/systemctl status %s ",afxout); + tmpstate = monitor_afx_service( cmd, details, svc ); + if( tmpstate != outstate ){ + printf("New afxout Service report sent %d\n",tmpstate); + outstate = tmpstate; + if( outstate == 1){ + if (is_critical == 1){ + is_critical = 0; + sprintf(evid,"Fault_vAfx_SvcOutput_SvcInput_%s",oam_intfaddr); + report_fault("Fault_vAfx_Svc_input_Output",evid, + EVEL_SEVERITY_NORMAL, "routing", "AFXInput and AFXOutput", + "AFX services input and output down alarm", + details, NULL, NULL, NULL, outstate); + } + sprintf(evid,"Fault_vAfx_SvcOutput_%s",oam_intfaddr); + report_fault("Fault_vAfx_SvcOutput",evid,EVEL_SEVERITY_NORMAL, "routing", "AFXOutput", "AFX services output up alarm", details, NULL, NULL, NULL, outstate ); + } else { + sprintf(evid,"Fault_vAfx_SvcOutput_%s",oam_intfaddr); + report_fault("Fault_vAfx_SvcOutput",evid,EVEL_SEVERITY_MAJOR, "routing", "AFXOutput", "AFX services output down alarm", details, NULL, NULL, NULL, outstate); + } + } + if((instate == 0) && (outstate == 0) && (is_critical == 0)) + { + is_critical = 1; + + sprintf(evid,"Fault_vAfx_SvcOutput_SvcInput_%s",oam_intfaddr); + report_fault("Fault_vAfx_Svc_input_Output",evid,EVEL_SEVERITY_CRITICAL, + "routing", "AFXInput and AFXOutput", + "AFX services input and output down alarm", details, + NULL, NULL, NULL, instate); + } + + sleep(SERVICE_MONITOR_INTERVAL); +} + + pthread_exit(NULL); +} + + diff --git a/vnfs/VES5.0/evel/evel-library/code/VESreporting_vAFX/afx_util.c b/vnfs/VES5.0/evel/evel-library/code/VESreporting_vAFX/afx_util.c new file mode 100644 index 00000000..6820aaa6 --- /dev/null +++ b/vnfs/VES5.0/evel/evel-library/code/VESreporting_vAFX/afx_util.c @@ -0,0 +1,194 @@ +/*************************************************************************//** + * + * Main Agent which spins up monitoring threads + * + * Version 1.0: Gokul Singaraju gs244f Tech Mahindra Inc. + * + * 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. + * + ****************************************************************************/ +#include <stdio.h> +#include <unistd.h> +#include <string.h> /* for strncpy */ + +#include <sys/types.h> +#include <sys/socket.h> +#include <sys/ioctl.h> +#include <netinet/in.h> +#include <net/if.h> +#include <arpa/inet.h> + +#include "evel.h" +#include "afx_ves_reporter.h" + + +/**************************************************************************//** + * Utility function to Create and send fault events. + *****************************************************************************/ +void report_fault( char* evname, char *evid, EVEL_SEVERITIES sevty, char *categ, char *intf, char *trapname, char *descr, char *rem_router, char *routername, char *router_ip, int status ) +{ + EVENT_FAULT * fault = NULL; + EVEL_ERR_CODES evel_rc = EVEL_SUCCESS; + + /***************************************************************************/ + /* Fault */ + /***************************************************************************/ + if (status == 1) /** ACTIVE **/ + { + fault = evel_new_fault(evname, + evid, + trapname, + descr, + EVEL_PRIORITY_HIGH, + sevty, + EVEL_SOURCE_ROUTER, + EVEL_VF_STATUS_ACTIVE); + } + else + { + fault = evel_new_fault(evname, + evid, + trapname, + descr, + EVEL_PRIORITY_HIGH, + sevty, + EVEL_SOURCE_ROUTER, + EVEL_VF_STATUS_IDLE); + } + + if (fault != NULL) + { + evel_header_type_set((EVENT_HEADER *)fault, "applicationVnf"); + evel_nfcnamingcode_set((EVENT_HEADER *)fault, "AFX"); + evel_nfnamingcode_set((EVENT_HEADER *)fault, "AFX"); + + evel_fault_category_set(fault, categ); + if( intf != NULL) + evel_fault_interface_set(fault, intf ); + + if( strstr(evname,"Fault_vAfx_Link") != NULL || strstr(evname,"Fault_vAfx_bgp") != NULL) + { + evel_fault_addl_info_add(fault, "remote_router", rem_router); + evel_fault_addl_info_add(fault, "router_name", routername); + } + + if( strstr(evname,"Fault_vAfx_bgp") != NULL ) + evel_fault_addl_info_add(fault, "router_ip", router_ip); + + evel_rc = evel_post_event((EVENT_HEADER *)fault); + if (evel_rc != EVEL_SUCCESS) + { + EVEL_ERROR("Post failed %d (%s)", evel_rc, evel_error_string()); + } + } + else + { + EVEL_ERROR("New Fault failed"); + } + printf(" Generated Fault event\n"); +} + + +int file_is_modified(const char *path, time_t *oldMTime) { + struct stat file_stat; + int err = stat(path, &file_stat); + if (err != 0) { + perror(" [file_is_modified] stat"); + exit(1); + } + if( file_stat.st_mtime > *oldMTime) + { + *oldMTime = file_stat.st_mtime; + return 1; + } + else + return 0; +} + +void remove_spaces(char* source) +{ + char* i = source; + char* j = source; + while(*j != 0) + { + *i = *j++; + if(*i != ' ') + i++; + } + *i = 0; +} + + +char *get_oam_intfaddr() +{ + int fd; + int ret; + struct ifreq ifr; + char oamaddr[64]; + + fd = socket(AF_INET, SOCK_DGRAM, 0); + + /* I want to get an IPv4 IP address */ + ifr.ifr_addr.sa_family = AF_INET; + + /* I want IP address attached to "eth0" */ + strncpy(ifr.ifr_name, OAM_INTERFACE, IFNAMSIZ-1); + + ret = ioctl(fd, SIOCGIFADDR, &ifr); + + close(fd); + + if( ret == 0 ) + { + /* display result */ + sprintf(oamaddr,"%s", inet_ntoa(((struct sockaddr_in *)&ifr.ifr_addr)->sin_addr)); + //printf("Loopback address %s\n", oamaddr); + } + else + sprintf(oamaddr,"127.0.0.1"); + + return strdup(oamaddr); +} + + +char *escape_json(char *in) { + char out[2048]; + char *c; + char *o; + o = &out[0]; + for (c = in; *c != '\0'; c++) { + switch (*c) { + case '"': strcat(o,"\\\"");o+=2; break; + case '\\': strcat(o, "\\\\");o+=2; break; + case '\b': strcat(o, "\\b");o+=2; break; + case '\f': strcat(o, "\\f");o+=2; break; + case '\n': strcat(o, "\\n");o+=2; break; + case '\r': strcat(o, "\\r");o+=2; break; + case '\t': strcat(o, "\\t");o+=2; break; + default: + if ('\x00' <= *c && *c <= '\x1f') { + char tmp[8]; + strcat(o, "\\u"); + sprintf(tmp,"%04X",(int)*c); + strcat(o,tmp); o+=6; + } else { + *o = *c; o++; + } + } + } + *o = '\0'; + //free(in); + return strdup(out); +} + diff --git a/vnfs/VES5.0/evel/evel-library/code/VESreporting_vAFX/afx_ves_reporter.c b/vnfs/VES5.0/evel/evel-library/code/VESreporting_vAFX/afx_ves_reporter.c new file mode 100644 index 00000000..45c842dc --- /dev/null +++ b/vnfs/VES5.0/evel/evel-library/code/VESreporting_vAFX/afx_ves_reporter.c @@ -0,0 +1,372 @@ + +/*************************************************************************//** + * + * Main Agent which spins up monitoring threads + * + * Version 1.0: Gokul Singaraju gs244f Tech Mahindra Inc. + * + * 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. + * + ****************************************************************************/ + +#include <stdio.h> +#include <stdlib.h> +#include <ctype.h> +#include <string.h> +#include <stdint.h> +#include <unistd.h> +#include <pthread.h> +#include <sys/stat.h> +#include <sys/time.h> +#include <sys/types.h> +#include "evel.h" +#include "afx_ves_reporter.h" + +int (*afxFunctions[NUM_THREADS]) (void *threadarg); + +char *messages[NUM_THREADS]; +char hostname[BUFSIZE]; +char oam_intfaddr[BUFSIZE]; +struct thread_data thread_data_array[NUM_THREADS]; + + +void *HeartbeatAfxThread(void *threadarg) +{ + int taskid, sum; + char *hello_msg; + struct thread_data *my_data; + char hrtbtevid[256]; + + sleep(1); + my_data = (struct thread_data *) threadarg; + taskid = my_data->thread_id; + sum = my_data->sum; + hello_msg = my_data->message; + printf("Thread %d: %s Sum=%d\n", taskid, hello_msg, sum); + +while(1) +{ + EVENT_HEADER * heartbeat = NULL; + EVEL_ERR_CODES evel_rc = EVEL_SUCCESS; + + /***************************************************************************/ + /* Heartbeat */ + /***************************************************************************/ + sprintf(hrtbtevid,"Heartbeat_vAfx_%s",oam_intfaddr); + heartbeat = evel_new_heartbeat_nameid("Heartbeat_vAfx",hrtbtevid); + //heartbeat = evel_new_heartbeat(); + if (heartbeat != NULL) + { + evel_header_type_set(heartbeat, "applicationVnf"); + evel_nfcnamingcode_set(heartbeat, "AFX"); + evel_nfnamingcode_set(heartbeat, "AFX"); + evel_rc = evel_post_event(heartbeat); + 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(15); +} + + pthread_exit(NULL); +} + +int checklist(char *modname, char **list, int numt) +{ + int i; + for(i=0;i<numt;i++) + { + if( !strcasecmp(list[i],modname) ) + return 1; + } + return 0; +} + + +int start_threads(void) +{ + +pthread_t threads[NUM_THREADS]; +int *taskids[NUM_THREADS]; +int rc, t, sum; +char *modlist[NUM_THREADS]; +int modcounter = 0; +char line[128]; +char *pos; +FILE *file; + +pthread_attr_t attr; + +sum=0; +messages[0] = "Heartbeat started!"; +messages[1] = "Link monitoring started"; +messages[2] = "AFX Measurement started!"; +messages[3] = "Service Monitoring started"; +messages[4] = "BGP Monitoring started"; + + file = fopen(AFX_MODULES_FILE, "r"); /* should check the result */ + + if( file != NULL ){ + while ( file != NULL && fgets(line, sizeof(line), file)) { + /* note that fgets don't strip the terminating \n, checking its + presence would allow to handle lines longer that sizeof(line) */ + //printf("%s", line); + remove_spaces(line); + if ((pos=strchr(line, '\n')) != NULL) + *pos = '\0'; + if( modcounter >= NUM_THREADS ) + { + EVEL_ERROR("AFX modules file %s has more modules than allowed\n",AFX_MODULES_FILE); + exit(1); + } + modlist[modcounter] = strdup(line); + modcounter++; + } + fclose(file); + } + + +for(t=0;t<NUM_THREADS;t++) { + if( file == NULL || (t == 0 && checklist("HeartBeat",modlist, modcounter)) || + (t == 1 && checklist("LinkMonitor",modlist, modcounter)) || + (t == 2 && checklist("ScalingMeasurements",modlist, modcounter)) || + (t == 3 && checklist("ServiceMonitor",modlist, modcounter)) || + (t == 4 && checklist("SyslogBgp",modlist, modcounter)) + ) + { + sum = sum + t; + thread_data_array[t].thread_id = t; + thread_data_array[t].sum = sum; + thread_data_array[t].message = messages[t]; + + /* Initialize and set thread detached attribute */ + pthread_attr_init(&attr); + pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED); + + printf("Creating thread %d\n", t); + rc = pthread_create(&threads[t], NULL, afxFunctions[t], (void *) + &thread_data_array[t]); + if (rc) { + printf("ERROR; return code from pthread_create() is %d\n", rc); + exit(-1); + } + } + else threads[t] = NULL; +} + + //pthread_exit(NULL); + for(t=0;t<NUM_THREADS;t++) { + if( threads[t] != NULL ) + pthread_join(threads[t],NULL); + } + return sum; +} + +void read_lpfile(char *fname, char **usn, char **pwd) +{ + FILE *fp; + int i=0; // count how many lines are in the file + char line[256]; + char *pos; + + fp=fopen(fname, "r"); + while (fgets(line, sizeof(line), fp)) { + //printf("%s", line); + if ((pos=strchr(line, '\n')) != NULL) + *pos = '\0'; + i++; + if( i == 1 && strlen(line) < 64 ) *usn = strdup(line); + if( i == 2 && strlen(line) < 64 ) *pwd = strdup(line); + } + fclose(fp); +} + + +int main(int argc, char** argv) +{ + char* fqdn = argv[1]; + int port = atoi(argv[2]); + char *fqdn2 = NULL; + int port2; + char* lpfile = argv[3]; + char* lpfile2 = NULL; + //char* usname = argv[3]; + //char* passwd = argv[4]; + char* usname = NULL; + char* passwd = NULL; + char* usname2 = NULL; + char* passwd2 = NULL; + int secty = atoi(argv[4]); + int dbglvl = atoi(argv[5]); + //int hrtbtintval = atoi(argv[6]); + int rc = EVEL_SUCCESS; + char oam_intf[64]; + char const* const fileName = "afxintf.conf"; + char line[128]; + FILE *file=NULL; + char *pos; + struct stat sb; + + + printf("\nvAFX VES Processing (VPP) measurement collection\n"); + fflush(stdout); + +if( argc == 9 ) +{ + fqdn2 = argv[6]; + port2 = atoi(argv[7]); + lpfile2 = argv[8]; +} + + + if ( !(argc == 6 || argc == 9 ) || port < 0 || dbglvl < 0 ) + { + fprintf(stderr, "Usage: %s <DCAE FQDN>|<IP address> <port> <credential file> <debug level> \n", argv[0]); + fprintf(stderr, "Or: %s <DCAE FQDN>|<IP address> <port> <credential file> <debug level> <DCAE FQDN2>|<IP address2> <port2> <credential file2> \n", argv[0]); + exit(-1); + } + + if( stat(lpfile,&sb)<0 ) + { + fprintf(stderr, "Error: Invalid Login password file %s \n", lpfile); + EVEL_ERROR("Error: Invalid Login password file %s \n", lpfile); + exit(-1); + } + read_lpfile(lpfile,&usname,&passwd); + //fprintf(stderr, "Login:%s:\n", usname); + //fprintf(stderr, "Password:%s:\n", passwd); + if ( usname == NULL || passwd == NULL || strlen(usname) < 5 || strlen(passwd) < 5 ) + { + fprintf(stderr, "Error: Invalid credentials in file %s \n", lpfile); + EVEL_ERROR("Error: Invalid credentials in file %s \n", lpfile); + exit(-1); + } + +if( argc == 9 ) +{ + if( stat(lpfile2,&sb)<0 ) + { + fprintf(stderr, "Error: Invalid Redundant collector Login password file %s \n", lpfile2); + EVEL_ERROR("Error: Invalid Login password file %s \n", lpfile2); + exit(-1); + } + read_lpfile(lpfile2,&usname2,&passwd2); + if ( usname2 == NULL || passwd2 == NULL || strlen(usname2) < 5 || strlen(passwd2) < 5 ) + { + fprintf(stderr, "Error: Invalid credentials in file %s \n", lpfile2); + EVEL_ERROR("Error: Invalid credentials in file %s \n", lpfile2); + exit(-1); + } + //fprintf(stderr, "Login:%s:\n", usname2); + //fprintf(stderr, "Password:%s:\n", passwd2); +} + + srand(time(NULL)); + gethostname(hostname, BUFSIZE); + + strcpy(oam_intf,OAM_INTERFACE); + sprintf(oam_intfaddr,"%s",get_oam_intfaddr(oam_intf)); + + /**************************************************************************/ + /* Initialize */ + /**************************************************************************/ + do { + +if( argc == 6 ) +{ + rc = evel_initialize(fqdn, /* FQDN */ + port, /* Port */ + NULL, /* backup fqdn */ + 0, /* backup port */ + NULL, /* optional path */ + NULL, /* optional topic */ + 1000, /* Ring buf size */ + secty, /* HTTPS? */ + NULL, /*"/home/gs244f/sslcerts/testclient.crt",*/ + NULL, /*"/home/gs244f/sslcerts/testclient.key",*/ + NULL, /*"/etc/pki/ca-trust/source/ca-bundle.legacy.crt",*/ + NULL, /*"/home/gs244f/sslcerts/www.testsite.com.crt",*/ + 0, 0, + usname, /* Username */ + passwd, /* Password */ + NULL, /* Username2 */ + NULL, /* Password2 */ + NULL, /* source ip */ + NULL, /* backup ip */ + EVEL_SOURCE_VIRTUAL_MACHINE, /* Source type */ + "vAFX", /* Role */ + dbglvl); /* Verbosity */ + if(rc != EVEL_SUCCESS){ + fprintf(stderr, "\nFailed to initialize the EVEL library!!!\n"); + exit(-1); + } + else + { + printf("\nInitialization completed\n"); + } +} else { + + rc = evel_initialize(fqdn, /* FQDN */ + port, /* Port */ + fqdn2, /* backup fqdn */ + port2, /* backup port */ + NULL, /* optional path */ + NULL, /* optional topic */ + 1000, /* RingB size */ + secty, /* HTTPS? */ + NULL, /*"/home/gs244f/sslcerts/testclient.crt",*/ + NULL, /*"/home/gs244f/sslcerts/testclient.key",*/ + NULL, /*"/etc/pki/ca-trust/source/ca-bundle.legacy.crt",*/ + NULL, /*"/home/gs244f/sslcerts/www.testsite.com.crt",*/ + 0, 0, + usname, /* Username */ + passwd, /* Password */ + usname2, /* Username2 */ + passwd2, /* Password2 */ + NULL, /* source ip */ + NULL, /* backup ip */ + EVEL_SOURCE_VIRTUAL_MACHINE, /* Source type */ + "vAFX", /* Role */ + dbglvl); /* Verbosity */ + if(rc != EVEL_SUCCESS){ + fprintf(stderr, "\nFailed to initialize the EVEL library!!!\n"); + evel_terminate(); + exit(-1); + } + else + { + printf("\nInitialization completed\n"); + } +} + + } while( rc != EVEL_SUCCESS); + + afxFunctions[0] = HeartbeatAfxThread; + afxFunctions[1] = LinkMonitorAfxThread; + afxFunctions[2] = MeasureAfxThread; + afxFunctions[3] = ServiceMonitorAfxThread; + afxFunctions[4] = BgpLoggingAfxThread; + + start_threads(); + + evel_terminate(); + printf("Terminated\n"); +} + diff --git a/vnfs/VES5.0/evel/evel-library/code/VESreporting_vAFX/afx_ves_reporter.h b/vnfs/VES5.0/evel/evel-library/code/VESreporting_vAFX/afx_ves_reporter.h new file mode 100644 index 00000000..cfceca0b --- /dev/null +++ b/vnfs/VES5.0/evel/evel-library/code/VESreporting_vAFX/afx_ves_reporter.h @@ -0,0 +1,85 @@ +#ifndef _VES_REPORTER +#define _VES_REPORTER 1 + +#include <pthread.h> +#include <stdio.h> +#include <stdlib.h> +#include <ctype.h> +#include <string.h> +#include <stdint.h> +#include <unistd.h> +#include <sys/stat.h> +#include <sys/time.h> +#include <sys/types.h> + +#define NUM_THREADS 5 +#define MAX_INTERFACES 40 + +#define BUFSIZE 128 +#define BGPBUFSIZE 512 +#define PERF_MONITOR_INTERVAL 300 +#define LINK_MONITOR_INTERVAL 20 + +struct thread_data +{ + int thread_id; + int sum; + char *message; +}; + +#define AFX_MODULES_FILE "afxmodules.conf" + +void *LinkMonitorAfxThread(void *threadarg); +#define AFX_INTERFACE_FILE "afxintf.conf" + +#define OAM_INTERFACE "ens3" + +void *ServiceMonitorAfxThread(void *threadarg); +#define SERVICE_MONITOR_INTERVAL 30 + +void *BgpLoggingAfxThread(void *threadarg); +#define AFX_SYSLOG_FILE "afxfilter.txt" +#define MAX_SYSLOG_WORDS 50 + +void *MeasureAfxThread(void *threadarg); + +typedef struct linkstat { + + char linkname[32]; + char linkdescr[256]; + char linkmode[64]; + int speedmbps; + int linkstat; + +}LINKSTAT; + + +typedef struct dummy_vpp_metrics_struct { + + char linkname[32]; + char linkdescr[256]; + uint64_t rx_bytes; + uint64_t tx_bytes; + uint64_t rx_packets; + uint64_t tx_packets; + uint64_t rx_mcast; + uint64_t delta_rx_bytes; + uint64_t delta_rx_packets; + uint64_t delta_rx_mcast; + uint64_t delta_tx_bytes; + uint64_t delta_tx_packets; + +} VPP_METRICS_STRUCT; + +void report_fault( char* evname, char *evid, EVEL_SEVERITIES sevty, char *categ, char *intf, char *trapname, char *descr, char *rem_router, char *routername, char *router_ip, int status ); + +const char *openstack_vm_uuid(); +char *get_oam_intfaddr(); + +int file_is_modified(const char *path, time_t *oldMTime); +void remove_spaces(char* source); +char *escape_json(char *in); + +extern char hostname[BUFSIZE]; +extern char oam_intfaddr[BUFSIZE]; +#endif diff --git a/vnfs/VES5.0/evel/evel-library/code/VESreporting_vAFX/afxfilter.txt b/vnfs/VES5.0/evel/evel-library/code/VESreporting_vAFX/afxfilter.txt new file mode 100644 index 00000000..27dc90c6 --- /dev/null +++ b/vnfs/VES5.0/evel/evel-library/code/VESreporting_vAFX/afxfilter.txt @@ -0,0 +1,5 @@ +snmpd +exabgp + + + diff --git a/vnfs/VES5.0/evel/evel-library/code/VESreporting_vAFX/afxintf.conf b/vnfs/VES5.0/evel/evel-library/code/VESreporting_vAFX/afxintf.conf new file mode 100644 index 00000000..7fc36567 --- /dev/null +++ b/vnfs/VES5.0/evel/evel-library/code/VESreporting_vAFX/afxintf.conf @@ -0,0 +1,11 @@ +lo DNS1_RSLOTPORT_VLAN_CLASSTYPE +bond0 DNS2_RSLOTPORT_VLAN_CLASSTYPE +bond0.4020 DNS3_RSLOTPORT_VLAN_CLASSTYPE +bond0.4020.4020 DNS4_RSLOTPORT_VLAN_CLASSTYPE +bond0.4021 DNS5_RSLOTPORT_VLAN_CLASSTYPE +bond0.4021.4021 DNS6_RSLOTPORT_VLAN_CLASSTYPE +ens3 DNS7_RSLOTPORT_VLAN_CLASSTYPE +ens4 DNS8_RSLOTPORT_VLAN_CLASSTYPE +ens5 DNS9_RSLOTPORT_VLAN_CLASSTYPE +ens6 DNSa_RSLOTPORT_VLAN_CLASSTYPE +ens7 DNSb_RSLOTPORT_VLAN_CLASSTYPE diff --git a/vnfs/VES5.0/evel/evel-library/code/VESreporting_vAFX/afxmodules.conf b/vnfs/VES5.0/evel/evel-library/code/VESreporting_vAFX/afxmodules.conf new file mode 100644 index 00000000..0e806cd4 --- /dev/null +++ b/vnfs/VES5.0/evel/evel-library/code/VESreporting_vAFX/afxmodules.conf @@ -0,0 +1,5 @@ +HeartBeat +LinkMonitor +ScalingMeasurements +ServiceMonitor +SyslogBgp diff --git a/vnfs/VES5.0/evel/evel-library/code/VESreporting_vAFX/dep.xml b/vnfs/VES5.0/evel/evel-library/code/VESreporting_vAFX/dep.xml new file mode 100644 index 00000000..fc18229f --- /dev/null +++ b/vnfs/VES5.0/evel/evel-library/code/VESreporting_vAFX/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_vAFX/go-client.sh b/vnfs/VES5.0/evel/evel-library/code/VESreporting_vAFX/go-client.sh new file mode 100755 index 00000000..46b9fb04 --- /dev/null +++ b/vnfs/VES5.0/evel/evel-library/code/VESreporting_vAFX/go-client.sh @@ -0,0 +1,13 @@ +#!/bin/bash +export LD_LIBRARY_PATH="/opt/VES/libs/x86_64/" +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) + +#Usage +#./afx_ves_reporter <DCAE FQDN>|<IP address> <port> <credential file> <debug level> +# OR +#./afx_ves_reporter <DCAE FQDN>|<IP address> <port> <credential file> <debug level> <DCAE FQDN2>|<IP address2> <port2> <credential file2> + +./afx_ves_reporter $DCAE_COLLECTOR_IP $DCAE_COLLECTOR_PORT ./vescred 0 0 diff --git a/vnfs/VES5.0/evel/evel-library/code/VESreporting_vAFX/install b/vnfs/VES5.0/evel/evel-library/code/VESreporting_vAFX/install new file mode 100644 index 00000000..cc68775b --- /dev/null +++ b/vnfs/VES5.0/evel/evel-library/code/VESreporting_vAFX/install @@ -0,0 +1,5 @@ +# sudo apt-get install build-essential +# sudo apt-get install exabgp +# sudo apt-get install libcurl4-openssl-dev + sudo apt-get install ethtool + sudo apt-get install curl diff --git a/vnfs/VES5.0/evel/evel-library/code/VESreporting_vAFX/pom.xml b/vnfs/VES5.0/evel/evel-library/code/VESreporting_vAFX/pom.xml new file mode 100644 index 00000000..9b89913e --- /dev/null +++ b/vnfs/VES5.0/evel/evel-library/code/VESreporting_vAFX/pom.xml @@ -0,0 +1,86 @@ +<?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.openecomp.demo.vnf</groupId> + <artifactId>demo-aggregator</artifactId> + <version>1.1.0-SNAPSHOT</version> + <relativePath>../../pom.xml</relativePath> + </parent> + + <modelVersion>4.0.0</modelVersion> + <groupId>org.openecomp.demo.vnf.ves</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>
\ No newline at end of file diff --git a/vnfs/VES5.0/evel/evel-library/code/VESreporting_vAFX/run b/vnfs/VES5.0/evel/evel-library/code/VESreporting_vAFX/run new file mode 100755 index 00000000..a1b6a2f8 --- /dev/null +++ b/vnfs/VES5.0/evel/evel-library/code/VESreporting_vAFX/run @@ -0,0 +1,3 @@ +unset http_proxy +unset https_proxy +sudo ./afx_ves_reporter 198.18.18.101 8080 diff --git a/vnfs/VES5.0/evel/evel-library/code/VESreporting_vAFX/sample_afxagent_events.txt b/vnfs/VES5.0/evel/evel-library/code/VESreporting_vAFX/sample_afxagent_events.txt new file mode 100644 index 00000000..217d0922 --- /dev/null +++ b/vnfs/VES5.0/evel/evel-library/code/VESreporting_vAFX/sample_afxagent_events.txt @@ -0,0 +1,236 @@ + +{ + "event": { + "commonEventHeader": { + "domain": "fault", + "eventId": "Fault_vAfx_SvcInput_127.0.0.1", + "eventName": "Fault_vAfx_SvcInput", + "eventType": "applicationVnf", + "lastEpochMicrosec": 1548836408985806, + "nfNamingCode": "AFX", + "nfcNamingCode": "AFX", + "priority": "High", + "reportingEntityName": "prakash-VirtualBox", + "sequence": 1, + "sourceName": "prakash-VirtualBox", + "startEpochMicrosec": 1548836408985806, + "version": 3.0 + }, + "faultFields": { + "alarmCondition": "AFX services input down alarm", + "alarmInterfaceA": "AFXInput", + "eventCategory": "routing", + "eventSeverity": "MAJOR", + "eventSourceType": "router", + "faultFieldsVersion": 2.0, + "specificProblem": "", + "vfStatus": "Idle" + } + } +} +======================================= +{ + "event": { + "commonEventHeader": { + "domain": "fault", + "eventId": "Fault_vAfx_SvcOutput_SvcInput_127.0.0.1", + "eventName": "Fault_vAfx_Svc_input_Output", + "eventType": "applicationVnf", + "lastEpochMicrosec": 1548836409169637, + "nfNamingCode": "AFX", + "nfcNamingCode": "AFX", + "priority": "High", + "reportingEntityName": "prakash-VirtualBox", + "sequence": 1, + "sourceName": "prakash-VirtualBox", + "startEpochMicrosec": 1548836409169637, + "version": 3.0 + }, + "faultFields": { + "alarmCondition": "AFX services input and output down alarm", + "alarmInterfaceA": "AFXInput and AFXOutput", + "eventCategory": "routing", + "eventSeverity": "CRITICAL", + "eventSourceType": "router", + "faultFieldsVersion": 2.0, + "specificProblem": "", + "vfStatus": "Idle" + } + } +} +========================================== +{ + "event": { + "commonEventHeader": { + "domain": "heartbeat", + "eventId": "Heartbeat_vAfx_127.0.0.1", + "eventName": "Heartbeat_vAfx", + "eventType": "applicationVnf", + "lastEpochMicrosec": 1548836438754150, + "nfNamingCode": "AFX", + "nfcNamingCode": "AFX", + "priority": "Normal", + "reportingEntityName": "prakash-VirtualBox", + "sequence": 0, + "sourceName": "prakash-VirtualBox", + "startEpochMicrosec": 1548836438754150, + "version": 3.0 + } + } +} +======================================= +{ + "event": { + "commonEventHeader": { + "domain": "fault", + "eventId": "Fault_vAfx_LinkState_127.0.0.1", + "eventName": "Fault_vAfx_Link_Status", + "eventType": "applicationVnf", + "lastEpochMicrosec": 1548836597757702, + "nfNamingCode": "AFX", + "nfcNamingCode": "AFX", + "priority": "High", + "reportingEntityName": "prakash-VirtualBox", + "sequence": 0, + "sourceName": "prakash-VirtualBox", + "startEpochMicrosec": 1548836597757702, + "version": 3.0 + }, + "faultFields": { + "alarmAdditionalInformation": [ + { + "name": "remote_router", + "value": "remrouter" + }, + { + "name": "router_name", + "value": "rname" + } + ], + "alarmCondition": "link up trap_alarm", + "alarmInterfaceA": "lo DNS1_RSLOTPORT_VLAN_CLASSTYPE", + "eventCategory": "link", + "eventSeverity": "NORMAL", + "eventSourceType": "router", + "faultFieldsVersion": 2.0, + "specificProblem": "physical or logical connection to a remote router is up", + "vfStatus": "Active" + } + } +} +================================== +{ + "event": { + "commonEventHeader": { + "domain": "syslog", + "eventId": "Syslog_vAfx_127.0.0.1", + "eventName": "Syslog_vAfx", + "eventType": "applicationVnf", + "lastEpochMicrosec": 1548836608650212, + "nfNamingCode": "AFX", + "nfcNamingCode": "AFX", + "priority": "Normal", + "reportingEntityName": "prakash-VirtualBox", + "sequence": 0, + "sourceName": "prakash-VirtualBox", + "startEpochMicrosec": 1548836608650212, + "version": 3.0 + }, + "syslogFields": { + "eventSourceHost": "Virtual host", + "eventSourceType": "virtualMachine", + "syslogFacility": 16, + "syslogFieldsVersion": 3.0, + "syslogMsg": "Jan 30 13:53:27 prakash-VirtualBox prakash: peer reset exabgp", + "syslogProc": "exabgp", + "syslogTag": "exabgp", + "syslogVer": 1 + } + } +} +===================================== +{ + "event": { + "commonEventHeader": { + "domain": "measurementsForVfScaling", + "eventId": "measurementsForVfScaling_vAfx_127.0.0.1", + "eventName": "measurementsForVfScaling_vAfx", + "eventType": "applicationVnf", + "lastEpochMicrosec": 1548847073554361, + "nfNamingCode": "AFX", + "nfcNamingCode": "AFX", + "priority": "Normal", + "reportingEntityId": "prakash-VirtualBox", + "reportingEntityName": "AFXM", + "sequence": 0, + "sourceName": "prakash-VirtualBox", + "startEpochMicrosec": 1548847062917562, + "version": 3.0 + }, + "measurementsForVfScalingFields": { + "cpuUsageArray": [ + { + "cpuIdentifier": "all", + "cpuIdle": 72.59, + "cpuUsageNice": 0.06, + "cpuUsageSystem": 0.06, + "cpuUsageUser": 25.58, + "percentUsage": 27.41 + }, + { + "cpuIdentifier": "cpu0", + "cpuIdle": 72.59, + "cpuUsageNice": 0.06, + "cpuUsageSystem": 0.06, + "cpuUsageUser": 25.58, + "percentUsage": 27.41 + } + ], + "measurementInterval": 300, + "measurementsForVfScalingVersion": 2.0, + "memoryUsageArray": [ + { + "memoryBuffered": 28800.0, + "memoryCached": 366984.0, + "memoryConfigured": 2041304.0, + "memoryFree": 87852.0, + "memorySlabRecl": 40392.0, + "memorySlabUnrecl": 44368.0, + "memoryUsed": 1472908.0, + "vmIdentifier": "RAM" + } + ], + "vNicPerformanceArray": [ + { + "receivedMulticastPacketsAccumulated": 0.0, + "receivedMulticastPacketsDelta": 0.0, + "receivedOctetsAccumulated": 0.0, + "receivedOctetsDelta": 0.0, + "receivedTotalPacketsAccumulated": 0.0, + "receivedTotalPacketsDelta": 0.0, + "transmittedOctetsAccumulated": 0.0, + "transmittedOctetsDelta": 0.0, + "transmittedTotalPacketsAccumulated": 0.0, + "transmittedTotalPacketsDelta": 0.0, + "vNicIdentifier": "enpos3 DNSb_RSLOTPORT_VLAN_CLASSTYPE", + "valuesAreSuspect": "true" + }, + { + "receivedMulticastPacketsAccumulated": 0.0, + "receivedMulticastPacketsDelta": 0.0, + "receivedOctetsAccumulated": 3573127.0, + "receivedOctetsDelta": 0.0, + "receivedTotalPacketsAccumulated": 40040.0, + "receivedTotalPacketsDelta": 0.0, + "transmittedOctetsAccumulated": 3573127.0, + "transmittedOctetsDelta": 0.0, + "transmittedTotalPacketsAccumulated": 40040.0, + "transmittedTotalPacketsDelta": 0.0, + "vNicIdentifier": "lo DNS1_RSLOTPORT_VLAN_CLASSTYPE", + "valuesAreSuspect": "true" + } + ] + } + } +} + diff --git a/vnfs/VES5.0/evel/evel-library/code/VESreporting_vAFX/vescred b/vnfs/VES5.0/evel/evel-library/code/VESreporting_vAFX/vescred new file mode 100644 index 00000000..5cbfaad3 --- /dev/null +++ b/vnfs/VES5.0/evel/evel-library/code/VESreporting_vAFX/vescred @@ -0,0 +1,2 @@ +sample1 +sample1 diff --git a/vnfs/readme.md b/vnfs/readme.md new file mode 100644 index 00000000..8ce88f58 --- /dev/null +++ b/vnfs/readme.md @@ -0,0 +1,145 @@ +# ECOMP Vendor Event Listener Library + + +This project contains a C library that supports interfacing to AT&T's ECOMP +Vendor Event Listener. For an overview of ECOMP, see the +[ECOMP White Paper](http://att.com/ECOMP). + +Developed in 2016 for AT&T by: + * Alok Gupta (https://github.com/ag1367) + * Paul Potochniak (https://github.com/pp8491) + * Gayathri Patrachari(https://github.com/gp2421) + +Current Maintainers: + * Alok Gupta (https://github.com/ag1367) + * Paul Potochniak (https://github.com/pp8491) + * Gayathri Patrachari(https://github.com/gp2421) + +#The description about important directories are given here + + VES5.0 - This contains the code for VES library for VES5.4.1, sample agents + + VESreporting_vFW5.0 - This is the sample virtual firewall agent + + VESreporting_vLB5.0 - This is the sample virtual load balancer agent + + VES5.0/evel/evel-library/code/evel_library - Code for VES library 'evel' + + VES5.0/evel/evel-library/code/VESreporting_HB - Sample json based heartbeat event generated periodically + + VES5.0/evel/evel-library/code/VESreporting_fault - Sample json based fault event based on low byte/packet count on interface. + + VES5.0/evel/evel-library/code/VESreporting_syslog - Sample json based syslog event based on pattern being logged into any file + + VES5.0/evel/evel-library/code/VESreporting_vFW - Sample json based Firewall application that generates measurement event periodically. + +# Info on evel Library +This library supports following events. The corresponding factory functions to generate that event is also mentioned against it +- Faults - ::evel_new_fault +- Heartbeat - ::evel_new_heartbeat +- Measurements - ::evel_new_measurement +- State Change - ::evel_new_state_change +- Syslog - ::evel_new_syslog +- Other - ::evel_new_other +- Mobile Flow - ::evel_new_mobile_flow +- Sipsingnaling - ::evel_new_signaling +- Threshold Crossing Alert - ::evel_new_threshold_cross +- Voice Quality - ::evel_new_voice_quality + +# Setting the environment +Install gcc, libcurl3-dev packages as below + + sudo apt-get install gcc + sudo apt-get install libcurl3-dev + +Clone the code from demo repository + +#Compile VES library + Go to /demo/vnfs/VES5.0/evel/evel-library/bldjobs directory and run the below commands + make all ==> to create the VES library + make package ==> to create the VES package if needed + + FYI - 'make install' can also be given to make a package and install the package in another machine - see /demo/vnfs/VES5.0/evel/evel-library/bldjobs/Makefile for more details + + After compilation VES libraries are generated and are available at below location + /demo/vnfs/VES5.0/evel/evel-library/libs/x86_64 + +#Loading VES the library + Go to /demo/vnfs/VES5.0/evel/evel-library/libs/x86_64 directory and run below commands + sudo cp libevel.so /usr/lib + sudo ldconfig + +#Compiling agent code + After successful compiling of VES library and loading the library, go to agent directory and run 'make all' +For json heartbeat agent + > cd /demo/vnfs/VES5.0/evel/evel-library/VESreporting_HB + > make all + +For all other jason based agents (VESreporting_fault, VESreporting_syslog and VESreporting_vFW) also, the compilation to be carried out in the same manner as mentioned above. + +But for agents in VESreporting_vFW5.0 and VESreporting_vLB5.0, special care to be taken as below + - Copy the contents of the directory into ~/demo/vnfs/VES5.0/evel/evel-library/VESreporting directory + - run 'make all' to create an executable (alternatively, this agent gets compiled during compilation of evel library when VESreporting directory has the agent code. + +#Run the agent + - run the application using go-client.sh command in the agent directory as below + > sudo chmod +x go-client.sh + > sudo ./go-client.sh + +# Agent building guide + +Each application that wants to send events would call evel_initialize() function to initialize the parameter with evel library. For more details about the parameters passed, see the VES5.0/evel/evel-library/code/evel_library/evel.h file. The public APIs to the library are defined in evel.h + +EVEL_ERR_CODES evel_initialize(const char * const fqdn, + int port, + const char * const bakup_fqdn, + int bakup_port, + const char * const path, + const char * const topic, + int ring_buf_size, + int secure, + const char * const cert_file_path, + const char * const key_file_path, + const char * const ca_info, + const char * const ca_file_path, + long verify_peer, + long verify_host, + const char * const username, + const char * const password, + const char * const bakup_username, + const char * const bakup_password, + const char * const source_ip, + const char * const bakup_source_ip, + EVEL_SOURCE_TYPES source_type, + const char * const role, + int verbosity + ) { + fprintf(stderr, "Failed to initialize the EVEL library!!!"); + exit(-1); + } + +After successful running of evel_initialize() API, call the APIs to generate the events. + +For fault event generation, below APIs would be called. For other events see the APIs listed in VES5.0/evel/evel-library/code/evel_library/evel.h + + EVENT_FAULT * fault = evel_new_fault("Fault_vFW-ATT-LinkdownError", + "fault0001", + "My alarm condition", + "It broke very badly", + EVEL_PRIORITY_NORMAL, + EVEL_SEVERITY_MAJOR, + EVEL_SOURCE_HOST, + EVEL_VF_STATUS_PREP_TERMINATE); + if (fault != NULL) + { + evel_fault_type_set(fault, "Bad things happen..."); + evel_fault_interface_set(fault, "My Interface Card"); + evel_fault_addl_info_add(fault, "name1", "value1"); + evel_fault_addl_info_add(fault, "name2", "value2"); + evel_rc = evel_post_event((EVENT_HEADER *)fault); + if (evel_rc != EVEL_SUCCESS) + { + EVEL_ERROR("Post failed %d (%s)", evel_rc, evel_error_string()); + } + } + |