/*************************************************************************//** * * 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 #include #include #include #include #include #include #include #include #include #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= 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| \n", argv[0]); fprintf(stderr, "Or: %s | | \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"); }