Change location of VES5.0 code
[demo.git] / vnfs / VES5.0 / evel / evel-library / code / evel_demo / evel_demo.c
1 /**************************************************************************//**
2  * @file
3  * Utility providing example use of the ECOMP Vendor Event Listener API.
4  *
5  * This software is intended to show the essential elements of the library's
6  * use.
7  *
8  * License
9  * -------
10  *
11  * Copyright(c) <2016>, AT&T Intellectual Property.  All other rights reserved.
12  *
13  * Redistribution and use in source and binary forms, with or without
14  * modification, are permitted provided that the following conditions are met:
15  *
16  * 1. Redistributions of source code must retain the above copyright notice,
17  * this list of conditions and the following disclaimer.
18  * 2. Redistributions in binary form must reproduce the above copyright notice,
19  * this list of conditions and the following disclaimer in the documentation
20  * and/or other materials provided with the distribution.
21  * 3. All advertising materials mentioning features or use of this software
22  * must display the following acknowledgement:  This product includes software
23  * developed by the AT&T.
24  * 4. Neither the name of AT&T nor the names of its contributors may be used to
25  * endorse or promote products derived from this software without specific
26  * prior written permission.
27  *
28  * THIS SOFTWARE IS PROVIDED BY AT&T INTELLECTUAL PROPERTY ''AS IS'' AND ANY
29  * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
30  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
31  * DISCLAIMED. IN NO EVENT SHALL AT&T INTELLECTUAL PROPERTY BE LIABLE FOR ANY
32  * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
33  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
34  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
35  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
36  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
37  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
38  *****************************************************************************/
39
40 #include <stdio.h>
41 #include <stdlib.h>
42 #include <unistd.h>
43 #include <getopt.h>
44 #include <sys/signal.h>
45 #include <pthread.h>
46 #include <mcheck.h>
47 #include <sys/time.h>
48
49 #include "jsmn.h"
50 #include "evel.h"
51 #include "evel_demo.h"
52 #include "evel_test_control.h"
53
54 /**************************************************************************//**
55  * Definition of long options to the program.
56  *
57  * See the documentation for getopt_long() for details of the structure's use.
58  *****************************************************************************/
59 static const struct option long_options[] = {
60     {"help",     no_argument,       0, 'h'},
61     {"fqdn",     required_argument, 0, 'f'},
62     {"port",     required_argument, 0, 'n'},
63     {"path",     required_argument, 0, 'p'},
64     {"topic",    required_argument, 0, 't'},
65     {"https",    no_argument,       0, 's'},
66     {"verbose",  no_argument,       0, 'v'},
67     {"cycles",   required_argument, 0, 'c'},
68     {"username", required_argument, 0, 'u'},
69     {"password", required_argument, 0, 'w'},
70     {"nothrott", no_argument,       0, 'x'},
71     {0, 0, 0, 0}
72   };
73
74 /**************************************************************************//**
75  * Definition of short options to the program.
76  *****************************************************************************/
77 static const char* short_options = "hf:n:p:t:sc:u:w:vx";
78
79 /**************************************************************************//**
80  * Basic user help text describing the usage of the application.
81  *****************************************************************************/
82 static const char* usage_text =
83 "evel_demo [--help]\n"
84 "          --fqdn <domain>\n"
85 "          --port <port_number>\n"
86 "          [--path <path>]\n"
87 "          [--topic <topic>]\n"
88 "          [--username <username>]\n"
89 "          [--password <password>]\n"
90 "          [--https]\n"
91 "          [--cycles <cycles>]\n"
92 "          [--nothrott]\n"
93 "\n"
94 "Demonstrate use of the ECOMP Vendor Event Listener API.\n"
95 "\n"
96 "  -h         Display this usage message.\n"
97 "  --help\n"
98 "\n"
99 "  -f         The FQDN or IP address to the RESTful API.\n"
100 "  --fqdn\n"
101 "\n"
102 "  -n         The port number the RESTful API.\n"
103 "  --port\n"
104 "\n"
105 "  -p         The optional path prefix to the RESTful API.\n"
106 "  --path\n"
107 "\n"
108 "  -t         The optional topic part of the RESTful API.\n"
109 "  --topic\n"
110 "\n"
111 "  -u         The optional username for basic authentication of requests.\n"
112 "  --username\n"
113 "\n"
114 "  -w         The optional password for basic authentication of requests.\n"
115 "  --password\n"
116 "\n"
117 "  -s         Use HTTPS rather than HTTP for the transport.\n"
118 "  --https\n"
119 "\n"
120 "  -c         Loop <cycles> times round the main loop.  Default = 1.\n"
121 "  --cycles\n"
122 "\n"
123 "  -v         Generate much chattier logs.\n"
124 "  --verbose\n"
125 "\n"
126 "  -x         Exclude throttling commands from demonstration.\n"
127 "  --nothrott\n";
128
129 #define DEFAULT_SLEEP_SECONDS 3
130 #define MINIMUM_SLEEP_SECONDS 1
131
132 unsigned long long epoch_start = 0;
133
134 typedef enum {
135   SERVICE_CODEC,
136   SERVICE_TRANSCODING,
137   SERVICE_RTCP,
138   SERVICE_EOC_VQM,
139   SERVICE_MARKER
140 } SERVICE_EVENT;
141
142 /*****************************************************************************/
143 /* Local prototypes.                                                         */
144 /*****************************************************************************/
145 static void demo_heartbeat(void);
146 static void demo_fault(void);
147 static void demo_measurement(const int interval);
148 static void demo_mobile_flow(void);
149 static void demo_heartbeat_field_event(void);
150 static void demo_signaling(void);
151 static void demo_state_change(void);
152 static void demo_syslog(void);
153 static void demo_other(void);
154 static void demo_voicequality(void);
155
156 /**************************************************************************//**
157  * Global flag to initiate shutdown.
158  *****************************************************************************/
159 static int glob_exit_now = 0;
160
161 static char * api_fqdn = NULL;
162 static int api_port = 0;
163 static int api_secure = 0;
164
165 static void show_usage(FILE* fp)
166 {
167   fputs(usage_text, fp);
168 }
169
170 /**************************************************************************//**
171  * Main function.
172  *
173  * Parses the command-line then ...
174  *
175  * @param[in] argc  Argument count.
176  * @param[in] argv  Argument vector - for usage see usage_text.
177  *****************************************************************************/
178 int main(int argc, char ** argv)
179 {
180   sigset_t sig_set;
181   pthread_t thread_id;
182   int option_index = 0;
183   int param = 0;
184   char * api_path = NULL;
185   char * api_topic = NULL;
186   char * api_username = "";
187   char * api_password = "";
188   int verbose_mode = 0;
189   int exclude_throttling = 0;
190   int cycles = 1;
191   int cycle;
192   int measurement_interval = EVEL_MEASUREMENT_INTERVAL_UKNOWN;
193
194   /***************************************************************************/
195   /* We're very interested in memory management problems so check behavior.  */
196   /***************************************************************************/
197   mcheck(NULL);
198
199   if (argc < 2)
200   {
201     show_usage(stderr);
202     exit(-1);
203   }
204   param = getopt_long(argc, argv,
205                       short_options,
206                       long_options,
207                       &option_index);
208   while (param != -1)
209   {
210     switch (param)
211     {
212       case 'h':
213         show_usage(stdout);
214         exit(0);
215         break;
216
217       case 'f':
218         api_fqdn = optarg;
219         break;
220
221       case 'n':
222         api_port = atoi(optarg);
223         break;
224
225       case 'p':
226         api_path = optarg;
227         break;
228
229       case 't':
230         api_topic = optarg;
231         break;
232
233       case 'u':
234         api_username = optarg;
235         break;
236
237       case 'w':
238         api_password = optarg;
239         break;
240
241       case 's':
242         api_secure = 1;
243         break;
244
245       case 'c':
246         cycles = atoi(optarg);
247         break;
248
249       case 'v':
250         verbose_mode = 1;
251         break;
252
253       case 'x':
254         exclude_throttling = 1;
255         break;
256
257       case '?':
258         /*********************************************************************/
259         /* Unrecognized parameter - getopt_long already printed an error     */
260         /* message.                                                          */
261         /*********************************************************************/
262         break;
263
264       default:
265         fprintf(stderr, "Code error: recognized but missing option (%d)!\n",
266                 param);
267         exit(-1);
268     }
269
270     /*************************************************************************/
271     /* Extract next parameter.                                               */
272     /*************************************************************************/
273     param = getopt_long(argc, argv,
274                         short_options,
275                         long_options,
276                         &option_index);
277   }
278
279   /***************************************************************************/
280   /* All the command-line has parsed cleanly, so now check that the options  */
281   /* are meaningful.                                                         */
282   /***************************************************************************/
283   if (api_fqdn == NULL)
284   {
285     fprintf(stderr, "FQDN of the Vendor Event Listener API server must be "
286                     "specified.\n");
287     exit(1);
288   }
289   if (api_port <= 0 || api_port > 65535)
290   {
291     fprintf(stderr, "Port for the Vendor Event Listener API server must be "
292                     "specified between 1 and 65535.\n");
293     exit(1);
294   }
295   if (cycles <= 0)
296   {
297     fprintf(stderr, "Number of cycles around the main loop must be an"
298                     "integer greater than zero.\n");
299     exit(1);
300   }
301
302   /***************************************************************************/
303   /* Set up default signal behaviour.  Block all signals we trap explicitly  */
304   /* on the signal_watcher thread.                                           */
305   /***************************************************************************/
306   sigemptyset(&sig_set);
307   sigaddset(&sig_set, SIGALRM);
308   sigaddset(&sig_set, SIGINT);
309   pthread_sigmask(SIG_BLOCK, &sig_set, NULL);
310
311   /***************************************************************************/
312   /* Start the signal watcher thread.                                        */
313   /***************************************************************************/
314   if (pthread_create(&thread_id, NULL, signal_watcher, &sig_set) != 0)
315   {
316     fprintf(stderr, "Failed to start signal watcher thread.");
317     exit(1);
318   }
319   pthread_detach(thread_id);
320
321   /***************************************************************************/
322   /* Version info                                                            */
323   /***************************************************************************/
324   printf("%s built %s %s\n", argv[0], __DATE__, __TIME__);
325
326   /***************************************************************************/
327   /* Initialize the EVEL interface.                                          */
328   /***************************************************************************/
329   if (evel_initialize(api_fqdn,
330                       api_port,
331                       api_path,
332                       api_topic,
333                       api_secure,
334                       api_username,
335                       api_password,
336                       EVEL_SOURCE_VIRTUAL_MACHINE,
337                       "EVEL demo client",
338                       verbose_mode))
339   {
340     fprintf(stderr, "Failed to initialize the EVEL library!!!");
341     exit(-1);
342   }
343   else
344   {
345     EVEL_INFO("Initialization completed");
346   }
347
348   /***************************************************************************/
349   /* Work out a start time for measurements, and sleep for initial period.   */
350   /***************************************************************************/
351   struct timeval tv_start;
352   gettimeofday(&tv_start, NULL);
353   epoch_start = tv_start.tv_usec + 1000000 * tv_start.tv_sec;
354   sleep(DEFAULT_SLEEP_SECONDS);
355
356   /***************************************************************************/
357   /* MAIN LOOP                                                               */
358   /***************************************************************************/
359   printf("Starting %d loops...\n", cycles);
360   cycle = 0;
361   while (cycle++ < cycles)
362   {
363     EVEL_INFO("MAI: Starting main loop");
364     printf("\nStarting main loop %d\n", cycle);
365
366     /*************************************************************************/
367     /* A 20s-long repeating cycle of behaviour.                              */
368     /*************************************************************************/
369     if (exclude_throttling == 0)
370     {
371       switch (cycle % 20)
372       {
373         case 1:
374           printf("   1 - Resetting throttle specification for all domains\n");
375           evel_test_control_scenario(TC_RESET_ALL_DOMAINS,
376                                      api_secure,
377                                      api_fqdn,
378                                      api_port);
379           break;
380
381         case 2:
382           printf("   2 - Switching measurement interval to 2s\n");
383           evel_test_control_meas_interval(2,
384                                           api_secure,
385                                           api_fqdn,
386                                           api_port);
387           break;
388
389         case 3:
390           printf("   3 - Suppressing fault domain\n");
391           evel_test_control_scenario(TC_FAULT_SUPPRESS_FIELDS_AND_PAIRS,
392                                      api_secure,
393                                      api_fqdn,
394                                      api_port);
395           break;
396
397         case 4:
398           printf("   4 - Suppressing measurement domain\n");
399           evel_test_control_scenario(TC_MEAS_SUPPRESS_FIELDS_AND_PAIRS,
400                                      api_secure,
401                                      api_fqdn,
402                                      api_port);
403           break;
404
405         case 5:
406           printf("   5 - Switching measurement interval to 5s\n");
407           evel_test_control_meas_interval(5,
408                                           api_secure,
409                                           api_fqdn,
410                                           api_port);
411           break;
412
413         case 6:
414           printf("   6 - Suppressing mobile flow domain\n");
415           evel_test_control_scenario(TC_MOBILE_SUPPRESS_FIELDS_AND_PAIRS,
416                                      api_secure,
417                                      api_fqdn,
418                                      api_port);
419           break;
420
421         case 7:
422           printf("   7 - Suppressing state change domain\n");
423           evel_test_control_scenario(TC_STATE_SUPPRESS_FIELDS_AND_PAIRS,
424                                      api_secure,
425                                      api_fqdn,
426                                      api_port);
427           break;
428
429         case 8:
430           printf("   8 - Suppressing signaling domain\n");
431           evel_test_control_scenario(TC_SIGNALING_SUPPRESS_FIELDS,
432                                      api_secure,
433                                      api_fqdn,
434                                      api_port);
435           break;
436
437         case 9:
438           printf("   9 - Suppressing service event domain\n");
439           evel_test_control_scenario(TC_SERVICE_SUPPRESS_FIELDS_AND_PAIRS,
440                                      api_secure,
441                                      api_fqdn,
442                                      api_port);
443           break;
444
445         case 10:
446           printf("   10 - Switching measurement interval to 20s\n");
447           evel_test_control_meas_interval(20,
448                                           api_secure,
449                                           api_fqdn,
450                                           api_port);
451           break;
452
453         case 11:
454           printf("   11 - Suppressing syslog domain\n");
455           evel_test_control_scenario(TC_SYSLOG_SUPPRESS_FIELDS_AND_PAIRS,
456                                      api_secure,
457                                      api_fqdn,
458                                      api_port);
459           break;
460
461         case 12:
462           printf("   12 - Switching measurement interval to 10s\n");
463           evel_test_control_meas_interval(10,
464                                           api_secure,
465                                           api_fqdn,
466                                           api_port);
467           break;
468
469         case 15:
470           printf("   Requesting provide throttling spec\n");
471           evel_test_control_scenario(TC_PROVIDE_THROTTLING_SPEC,
472                                      api_secure,
473                                      api_fqdn,
474                                      api_port);
475           break;
476       }
477     }
478     fflush(stdout);
479
480     /*************************************************************************/
481     /* Send a bunch of events.                                               */
482     /*************************************************************************/
483     demo_heartbeat();
484     demo_fault();
485     demo_measurement((measurement_interval ==
486                                             EVEL_MEASUREMENT_INTERVAL_UKNOWN) ?
487                      DEFAULT_SLEEP_SECONDS : measurement_interval);
488     demo_mobile_flow();
489     demo_heartbeat_field_event();
490     demo_signaling();
491     demo_state_change();
492     demo_syslog();
493     demo_other();
494     demo_voicequality();
495
496     /*************************************************************************/
497     /* MAIN RETRY LOOP.  Check and implement the measurement interval.       */
498     /*************************************************************************/
499     if (cycle <= cycles)
500     {
501       int sleep_time;
502
503       /***********************************************************************/
504       /* We have a minimum loop time.                                        */
505       /***********************************************************************/
506       sleep(MINIMUM_SLEEP_SECONDS);
507
508       /***********************************************************************/
509       /* Get the latest measurement interval and sleep for the remainder.    */
510       /***********************************************************************/
511       measurement_interval = evel_get_measurement_interval();
512       printf("Measurement Interval = %d\n", measurement_interval);
513
514       if (measurement_interval == EVEL_MEASUREMENT_INTERVAL_UKNOWN)
515       {
516         sleep_time = DEFAULT_SLEEP_SECONDS - MINIMUM_SLEEP_SECONDS;
517       }
518       else
519       {
520         sleep_time = measurement_interval - MINIMUM_SLEEP_SECONDS;
521       }
522       sleep(sleep_time);
523     }
524   }
525
526   /***************************************************************************/
527   /* We are exiting, but allow the final set of events to be dispatched      */
528   /* properly first.                                                         */
529   /***************************************************************************/
530   sleep(2);
531   printf("All done - exiting!\n");
532   return 0;
533 }
534
535 /**************************************************************************//**
536  * Signal watcher.
537  *
538  * Signal catcher for incoming signal processing.  Work out which signal has
539  * been received and process it accordingly.
540  *
541  * param[in]  void_sig_set  The signal mask to listen for.
542  *****************************************************************************/
543 void *signal_watcher(void *void_sig_set)
544 {
545   sigset_t *sig_set = (sigset_t *)void_sig_set;
546   int sig = 0;
547   int old_type = 0;
548   siginfo_t sig_info;
549
550   /***************************************************************************/
551   /* Set this thread to be cancellable immediately.                          */
552   /***************************************************************************/
553   pthread_setcanceltype(PTHREAD_CANCEL_ASYNCHRONOUS, &old_type);
554
555   while (!glob_exit_now)
556   {
557     /*************************************************************************/
558     /* Wait for a signal to be received.                                     */
559     /*************************************************************************/
560     sig = sigwaitinfo(sig_set, &sig_info);
561     switch (sig)
562     {
563       case SIGALRM:
564         /*********************************************************************/
565         /* Failed to do something in the given amount of time.  Exit.        */
566         /*********************************************************************/
567         EVEL_ERROR( "Timeout alarm");
568         fprintf(stderr,"Timeout alarm - quitting!\n");
569         exit(2);
570         break;
571
572       case SIGINT:
573         EVEL_INFO( "Interrupted - quitting");
574         printf("\n\nInterrupted - quitting!\n");
575         glob_exit_now = 1;
576         break;
577     }
578   }
579
580   evel_terminate();
581   exit(0);
582   return(NULL);
583 }
584
585 /**************************************************************************//**
586  * Create and send a heartbeat event.
587  *****************************************************************************/
588 void demo_heartbeat(void)
589 {
590   EVENT_HEADER * heartbeat = NULL;
591   EVEL_ERR_CODES evel_rc = EVEL_SUCCESS;
592
593   /***************************************************************************/
594   /* Heartbeat                                                               */
595   /***************************************************************************/
596   heartbeat = evel_new_heartbeat();
597   if (heartbeat != NULL)
598   {
599     evel_rc = evel_post_event(heartbeat);
600     if (evel_rc != EVEL_SUCCESS)
601     {
602       EVEL_ERROR("Post failed %d (%s)", evel_rc, evel_error_string());
603     }
604   }
605   else
606   {
607     EVEL_ERROR("New Heartbeat failed");
608   }
609   printf("   Processed Heartbeat\n");
610 }
611
612 /**************************************************************************//**
613  * tap live cpu stats
614  *****************************************************************************/
615 void evel_get_cpu_stats(EVENT_MEASUREMENT * measurement)
616 {
617   FILE *fp;
618   char path[1024];
619   double usage;
620   double idle;
621   double intrpt;
622   double nice;
623   double softirq;
624   double steal;
625   double sys;
626   double user;
627   double wait;
628   MEASUREMENT_CPU_USE *cpu_use;
629
630   /* Open the command for reading. */
631   //fp = popen("/bin/ls /etc/", "r");
632   fp = popen("/usr/bin/top -bn 2 -d 0.01 | grep '^%Cpu' | tail -n 1 ", "r");
633   if (fp == NULL) {
634     printf("Failed to run command\n" );
635     exit(1);
636   }
637
638   /* Read the output a line at a time - output it. */
639   while (fgets(path, sizeof(path)-1, fp) != NULL) {
640     printf("%s", path+10);
641     sscanf(path+10," %lf us, %lf sy,  %lf ni,  %lf id,  %lf wa,  %lf hi,  %lf si,  %lf st",
642     &user,&sys,&nice,&idle,&wait,&intrpt,&softirq,&steal);
643   }
644
645   /* close */
646   pclose(fp);
647
648   cpu_use = evel_measurement_new_cpu_use_add(measurement, "cpu1", usage);
649   evel_measurement_cpu_use_idle_set(cpu_use,idle);
650   evel_measurement_cpu_use_interrupt_set(cpu_use,intrpt);
651   evel_measurement_cpu_use_nice_set(cpu_use,nice);
652   evel_measurement_cpu_use_softirq_set(cpu_use,softirq);
653   evel_measurement_cpu_use_steal_set(cpu_use,steal);
654   evel_measurement_cpu_use_system_set(cpu_use,sys);
655   evel_measurement_cpu_use_usageuser_set(cpu_use,user);
656   evel_measurement_cpu_use_wait_set(cpu_use,wait);
657   //evel_measurement_cpu_use_add(measurement, "cpu2", usage,idle,intrpt,nice,softirq,steal,sys,user,wait);
658 }
659
660 /**************************************************************************//**
661  * tap live disk stats
662  *****************************************************************************/
663 void evel_get_disk_stats(EVENT_MEASUREMENT * measurement)
664 {
665   FILE *fp;
666   char path[1024];
667   double rrqm;
668   double wrqm;
669   double rs;
670   double ws;
671   double rkbs;
672   double wkbs;
673   double avgrqs;
674   double avgqqs;
675   double wait;
676   double rawait;
677   double wawait;
678   double svctm;
679   double util;
680   MEASUREMENT_DISK_USE * disk_use = NULL;
681
682   /* Open the command for reading. */
683   //fp = popen("/bin/ls /etc/", "r");
684   fp = popen("/usr/bin/iostat -xtd | grep '^sda' | tail -n 1 ", "r");
685   if (fp == NULL) {
686     printf("Failed to run command\n" );
687     exit(1);
688   }
689
690   /* Read the output a line at a time - output it. */
691   while (fgets(path, sizeof(path)-1, fp) != NULL) {
692     printf("%s", path+10);
693     sscanf(path+10,"%lf    %lf    %lf    %lf    %lf    %lf    %lf    %lf    %lf    %lf    %lf    %lf    %lf",
694     &rrqm,&wrqm,&rs,&ws,&rkbs,&wkbs,&avgrqs,&avgqqs,&wait,&rawait,&wawait,&svctm,&util);
695   }
696
697   /* close */
698   pclose(fp);
699
700   disk_use = evel_measurement_new_disk_use_add(measurement, "sda");
701   evel_measurement_disk_use_iotimeavg_set(disk_use, rrqm);
702   evel_measurement_disk_use_iotimelast_set(disk_use, wrqm);
703   evel_measurement_disk_use_iotimemax_set(disk_use, rs);
704   evel_measurement_disk_use_iotimemin_set(disk_use, ws);
705   evel_measurement_disk_use_mergereadavg_set(disk_use, rkbs);
706   evel_measurement_disk_use_mergereadlast_set(disk_use, wkbs);
707   evel_measurement_disk_use_mergereadmax_set(disk_use, avgrqs);
708   evel_measurement_disk_use_mergereadmin_set(disk_use, avgqqs);
709   evel_measurement_disk_use_mergewritelast_set(disk_use, wait);
710   evel_measurement_disk_use_mergewritemax_set(disk_use, rawait);
711   evel_measurement_disk_use_mergewritemin_set(disk_use, wawait);
712   evel_measurement_disk_use_octetsreadavg_set(disk_use, svctm);
713   evel_measurement_disk_use_octetsreadlast_set(disk_use, util);
714 }
715
716
717 /**************************************************************************//**
718  * tap live memory stats
719  *****************************************************************************/
720 void evel_get_mem_stats(EVENT_MEASUREMENT * measurement)
721 {
722 char buffer[4096];
723 char line[100];
724 char c;
725 int  bcount=0,lcount=0;
726
727 double membuffsz=0.0;
728 double memcache=0.0;
729 double memconfig=0.0;
730 double memfree=0.0;
731 double slab=0.0;
732 double slabrecl=0.0;
733 double slabunrecl=0.0;
734 double memused=0.0;
735 MEASUREMENT_MEM_USE *mem_use = NULL;
736
737
738 FILE * filp = fopen("/proc/meminfo", "rb");
739 int bytes_read = fread(buffer, sizeof(char), 4096, filp);
740 fclose(filp);
741
742 printf("meminfo %d\n",bytes_read);
743
744 while ( bcount < bytes_read )
745 {
746   for(lcount=0; buffer[bcount] != '\n';bcount++,lcount++)
747   {
748      line[lcount] = buffer[bcount];
749   }
750   if( lcount > 0 )
751   {
752     line[lcount] = '\0';
753     //printf("%s\n",line);
754     if(!strncmp(line,"Buffers:", strlen("Buffers:")))
755     {
756         sscanf(line+strlen("Buffers:"),"%lf",&membuffsz);
757         //printf("membuff %lf\n",membuffsz);
758     }
759     else if(!strncmp(line,"Cached:", strlen("Cached:")))
760     {
761         sscanf(line+strlen("Cached:"),"%lf",&memcache);
762     }
763     else if(!strncmp(line,"MemTotal:", strlen("MemTotal:")))
764     {
765         sscanf(line+strlen("MemTotal:"),"%lf",&memconfig);
766     }
767     else if(!strncmp(line,"MemFree:", strlen("MemFree:")))
768     {
769         sscanf(line+strlen("MemFree:"),"%lf",&memfree);
770     }
771     else if(!strncmp(line,"Slab:", strlen("Slab:")))
772     {
773         sscanf(line+strlen("Slab:"),"%lf",&slab);
774     }
775     else if(!strncmp(line,"SReclaimable:", strlen("SReclaimable:")))
776     {
777         sscanf(line+strlen("SReclaimable:"),"%lf",&slabrecl);
778     }
779     else if(!strncmp(line,"SUnreclaim:", strlen("SUnreclaim:")))
780     {
781         sscanf(line+strlen("SUnreclaim:"),"%lf",&slabunrecl);
782     }
783   }
784   bcount++;
785 }
786
787 memused = memconfig - memfree - membuffsz - memcache - slab;
788 printf("memused %lf\n",memused);
789
790   mem_use = evel_measurement_new_mem_use_add(measurement, "RAM", "vm1", membuffsz);
791   evel_measurement_mem_use_memcache_set(mem_use,memcache);
792   evel_measurement_mem_use_memconfig_set(mem_use,memconfig);
793   evel_measurement_mem_use_memfree_set(mem_use,memfree);
794   evel_measurement_mem_use_slab_reclaimed_set(mem_use,slabrecl);
795   evel_measurement_mem_use_slab_unreclaimable_set(mem_use,slabunrecl);
796   evel_measurement_mem_use_usedup_set(mem_use,memused);
797
798 }
799
800 /**************************************************************************//**
801  * Create and send three fault events.
802  *****************************************************************************/
803 void demo_fault(void)
804 {
805   EVENT_FAULT * fault = NULL;
806   EVEL_ERR_CODES evel_rc = EVEL_SUCCESS;
807
808   /***************************************************************************/
809   /* Fault                                                                   */
810   /***************************************************************************/
811   fault = evel_new_fault("An alarm condition",
812                          "Things are broken",
813                          EVEL_PRIORITY_NORMAL,
814                          EVEL_SEVERITY_MAJOR,
815                          EVEL_SOURCE_VIRTUAL_MACHINE,
816                          EVEL_VF_STATUS_READY_TERMINATE);
817   if (fault != NULL)
818   {
819     evel_rc = evel_post_event((EVENT_HEADER *)fault);
820     if (evel_rc != EVEL_SUCCESS)
821     {
822       EVEL_ERROR("Post failed %d (%s)", evel_rc, evel_error_string());
823     }
824   }
825   else
826   {
827     EVEL_ERROR("New Fault failed");
828   }
829   printf("   Processed empty Fault\n");
830
831   fault = evel_new_fault("Another alarm condition",
832                          "It broke badly",
833                          EVEL_PRIORITY_NORMAL,
834                          EVEL_SEVERITY_MAJOR,
835                          EVEL_SOURCE_PORT,
836                          EVEL_VF_STATUS_REQ_TERMINATE);
837   if (fault != NULL)
838   {
839     evel_fault_type_set(fault, "Bad things happening");
840     evel_fault_category_set(fault, "Failed category");
841     evel_fault_interface_set(fault, "An Interface Card");
842     evel_rc = evel_post_event((EVENT_HEADER *)fault);
843     if (evel_rc != EVEL_SUCCESS)
844     {
845       EVEL_ERROR("Post failed %d (%s)", evel_rc, evel_error_string());
846     }
847   }
848   else
849   {
850     EVEL_ERROR("New Fault failed");
851   }
852   printf("   Processed partial Fault\n");
853
854   fault = evel_new_fault("My alarm condition",
855                          "It broke very badly",
856                          EVEL_PRIORITY_NORMAL,
857                          EVEL_SEVERITY_MAJOR,
858                          EVEL_SOURCE_HOST,
859                          EVEL_VF_STATUS_PREP_TERMINATE);
860   if (fault != NULL)
861   {
862     evel_fault_type_set(fault, "Bad things happen...");
863     evel_fault_interface_set(fault, "My Interface Card");
864     evel_fault_addl_info_add(fault, "name1", "value1");
865     evel_fault_addl_info_add(fault, "name2", "value2");
866     evel_rc = evel_post_event((EVENT_HEADER *)fault);
867     if (evel_rc != EVEL_SUCCESS)
868     {
869       EVEL_ERROR("Post failed %d (%s)", evel_rc, evel_error_string());
870     }
871   }
872   else
873   {
874     EVEL_ERROR("New Fault failed");
875   }
876   printf("   Processed full Fault\n");
877 }
878
879 /**************************************************************************//**
880  * Create and send a measurement event.
881  *****************************************************************************/
882 void demo_measurement(const int interval)
883 {
884   EVENT_MEASUREMENT * measurement = NULL;
885   MEASUREMENT_LATENCY_BUCKET * bucket = NULL;
886   MEASUREMENT_VNIC_PERFORMANCE * vnic_performance = NULL;
887   EVEL_ERR_CODES evel_rc = EVEL_SUCCESS;
888
889   /***************************************************************************/
890   /* Measurement                                                             */
891   /***************************************************************************/
892   measurement = evel_new_measurement(interval);
893   if (measurement != NULL)
894   {
895     evel_measurement_type_set(measurement, "Perf management...");
896     evel_measurement_conc_sess_set(measurement, 1);
897     evel_measurement_cfg_ents_set(measurement, 2);
898     evel_measurement_mean_req_lat_set(measurement, 4.4);
899     evel_measurement_request_rate_set(measurement, 6);
900     //evel_measurement_cpu_use_add(measurement, "cpu1", 11.11);
901     //evel_measurement_cpu_use_add(measurement, "cpu2", 22.22);
902     evel_measurement_addl_info_add(measurement, "name1", "value1");
903     evel_measurement_addl_info_add(measurement, "name2", "value2");
904     evel_get_cpu_stats(measurement);
905     evel_get_disk_stats(measurement);
906     evel_measurement_fsys_use_add(measurement,"00-11-22",100.11, 100.22, 33,
907                                   200.11, 200.22, 44);
908     evel_measurement_fsys_use_add(measurement,"33-44-55",300.11, 300.22, 55,
909                                   400.11, 400.22, 66);
910
911     bucket = evel_new_meas_latency_bucket(20);
912     evel_meas_latency_bucket_low_end_set(bucket, 0.0);
913     evel_meas_latency_bucket_high_end_set(bucket, 10.0);
914     evel_meas_latency_bucket_add(measurement, bucket);
915
916     bucket = evel_new_meas_latency_bucket(30);
917     evel_meas_latency_bucket_low_end_set(bucket, 10.0);
918     evel_meas_latency_bucket_high_end_set(bucket, 20.0);
919     evel_meas_latency_bucket_add(measurement, bucket);
920
921     vnic_performance = evel_measurement_new_vnic_performance("eth0", "true");
922                                            
923   evel_vnic_performance_rx_bcast_pkt_acc_set(vnic_performance, 1000000.023);
924   evel_vnic_performance_rx_bcast_pkt_delta_set(vnic_performance,1234.767346);
925   evel_vnic_performance_rx_discard_pkt_acc_set(vnic_performance, 127146784.234738587);
926   evel_vnic_performance_rx_discard_pkt_delta_set(vnic_performance, 123445);
927   evel_vnic_performance_rx_error_pkt_acc_set(vnic_performance, 2736448376);
928   evel_vnic_performance_rx_error_pkt_delta_set(vnic_performance, 3474438764);
929   evel_vnic_performance_rx_mcast_pkt_acc_set(vnic_performance, 42464676);
930   evel_vnic_performance_rx_mcast_pkt_delta_set(vnic_performance, 42678657654);
931   evel_vnic_performance_rx_octets_acc_set(vnic_performance, 47658745);
932   evel_vnic_performance_rx_octets_delta_set(vnic_performance, 47656465465);
933   evel_vnic_performance_rx_total_pkt_acc_set(vnic_performance, 4765764654444);
934   evel_vnic_performance_rx_total_pkt_delta_set(vnic_performance, 4545665656);
935   evel_vnic_performance_rx_ucast_pkt_acc_set(vnic_performance, 4765745546.);
936   evel_vnic_performance_rx_ucast_pkt_delta_set(vnic_performance, 4768765.78347856);
937   evel_vnic_performance_tx_bcast_pkt_acc_set(vnic_performance, 747665.347647);
938   evel_vnic_performance_tx_bcast_pkt_delta_set(vnic_performance, 3468765.4774);
939   evel_vnic_performance_tx_discarded_pkt_acc_set(vnic_performance, 53625345.53);
940   evel_vnic_performance_tx_discarded_pkt_delta_set(vnic_performance, 5465345.72455);
941   evel_vnic_performance_tx_error_pkt_acc_set(vnic_performance, 7632754.754);
942   evel_vnic_performance_tx_error_pkt_delta_set(vnic_performance, 34646875444.);
943   evel_vnic_performance_tx_mcast_pkt_acc_set(vnic_performance, 2734875.5534);
944   evel_vnic_performance_tx_mcast_pkt_delta_set(vnic_performance, 562346534.654);
945   evel_vnic_performance_tx_octets_acc_set(vnic_performance, 2785845.76874);
946   evel_vnic_performance_tx_octets_delta_set(vnic_performance, 76532645.75);
947   evel_vnic_performance_tx_total_pkt_acc_set(vnic_performance, 652365.5435);
948   evel_vnic_performance_tx_total_pkt_delta_set(vnic_performance, 754354.456);
949   evel_vnic_performance_tx_ucast_pkt_acc_set(vnic_performance, 738254835);
950   evel_vnic_performance_tx_ucast_pkt_delta_set(vnic_performance, 763274);
951     evel_meas_vnic_performance_add(measurement, vnic_performance);
952
953     vnic_performance = evel_measurement_new_vnic_performance("eth1", "false");
954   evel_vnic_performance_rx_mcast_pkt_delta_set(vnic_performance, 42678657654);
955   evel_vnic_performance_rx_octets_acc_set(vnic_performance, 47658745);
956   evel_vnic_performance_rx_octets_delta_set(vnic_performance, 47656465465);
957   evel_vnic_performance_rx_total_pkt_acc_set(vnic_performance, 4765764654444);
958   evel_vnic_performance_rx_total_pkt_delta_set(vnic_performance, 4545665656);
959   evel_vnic_performance_rx_ucast_pkt_acc_set(vnic_performance, 4765745546.);
960   evel_vnic_performance_rx_ucast_pkt_delta_set(vnic_performance, 4768765.78347856);
961   evel_vnic_performance_tx_bcast_pkt_acc_set(vnic_performance, 747665.347647);
962   evel_vnic_performance_tx_bcast_pkt_delta_set(vnic_performance, 3468765.4774);
963   evel_vnic_performance_tx_discarded_pkt_acc_set(vnic_performance, 53625345.53);
964     evel_meas_vnic_performance_add(measurement, vnic_performance);
965
966     evel_measurement_errors_set(measurement, 1, 0, 2, 1);
967
968     evel_measurement_feature_use_add(measurement, "FeatureA", 123);
969     evel_measurement_feature_use_add(measurement, "FeatureB", 567);
970
971     evel_measurement_codec_use_add(measurement, "G711a", 91);
972     evel_measurement_codec_use_add(measurement, "G729ab", 92);
973
974     evel_get_mem_stats(measurement);
975     evel_measurement_media_port_use_set(measurement, 1234);
976
977     evel_measurement_vnfc_scaling_metric_set(measurement, 1234.5678);
978
979     evel_measurement_custom_measurement_add(measurement,
980                                             "Group1", "Name1", "Value1");
981     evel_measurement_custom_measurement_add(measurement,
982                                             "Group2", "Name1", "Value1");
983     evel_measurement_custom_measurement_add(measurement,
984                                             "Group2", "Name2", "Value2");
985
986     /*************************************************************************/
987     /* Work out the time, to use as end of measurement period.               */
988     /*************************************************************************/
989     struct timeval tv_now;
990     gettimeofday(&tv_now, NULL);
991     unsigned long long epoch_now = tv_now.tv_usec + 1000000 * tv_now.tv_sec;
992     evel_start_epoch_set(&measurement->header, epoch_start);
993     evel_last_epoch_set(&measurement->header, epoch_now);
994     epoch_start = epoch_now;
995     evel_reporting_entity_name_set(&measurement->header, "measurer");
996     evel_reporting_entity_id_set(&measurement->header, "measurer_id");
997
998     evel_rc = evel_post_event((EVENT_HEADER *)measurement);
999     if (evel_rc != EVEL_SUCCESS)
1000     {
1001       EVEL_ERROR("Post Measurement failed %d (%s)",
1002                  evel_rc,
1003                  evel_error_string());
1004     }
1005   }
1006   else
1007   {
1008     EVEL_ERROR("New Measurement failed");
1009   }
1010   printf("   Processed Measurement\n");
1011 }
1012
1013 /**************************************************************************//**
1014  * Create and send three mobile flow events.
1015  *****************************************************************************/
1016 void demo_mobile_flow(void)
1017 {
1018   MOBILE_GTP_PER_FLOW_METRICS * metrics = NULL;
1019   EVENT_MOBILE_FLOW * mobile_flow = NULL;
1020   EVEL_ERR_CODES evel_rc = EVEL_SUCCESS;
1021
1022   /***************************************************************************/
1023   /* Mobile Flow                                                             */
1024   /***************************************************************************/
1025   metrics = evel_new_mobile_gtp_flow_metrics(12.3,
1026                                              3.12,
1027                                              100,
1028                                              2100,
1029                                              500,
1030                                              1470409421,
1031                                              987,
1032                                              1470409431,
1033                                              11,
1034                                              (time_t)1470409431,
1035                                              "Working",
1036                                              87,
1037                                              3,
1038                                              17,
1039                                              123654,
1040                                              4561,
1041                                              0,
1042                                              12,
1043                                              10,
1044                                              1,
1045                                              3,
1046                                              7,
1047                                              899,
1048                                              901,
1049                                              302,
1050                                              6,
1051                                              2,
1052                                              0,
1053                                              110,
1054                                              225);
1055   if (metrics != NULL)
1056   {
1057     mobile_flow = evel_new_mobile_flow("Outbound",
1058                                        metrics,
1059                                        "TCP",
1060                                        "IPv4",
1061                                        "2.3.4.1",
1062                                        2341,
1063                                        "4.2.3.1",
1064                                        4321);
1065     if (mobile_flow != NULL)
1066     {
1067       evel_rc = evel_post_event((EVENT_HEADER *)mobile_flow);
1068       if (evel_rc != EVEL_SUCCESS)
1069       {
1070         EVEL_ERROR("Post Mobile Flow failed %d (%s)",
1071                    evel_rc,
1072                    evel_error_string());
1073       }
1074     }
1075     else
1076     {
1077       EVEL_ERROR("New Mobile Flow failed");
1078     }
1079     printf("   Processed empty Mobile Flow\n");
1080   }
1081   else
1082   {
1083     EVEL_ERROR("New GTP Per Flow Metrics failed - skipping Mobile Flow");
1084     printf("   Skipped empty Mobile Flow\n");
1085   }
1086
1087   metrics = evel_new_mobile_gtp_flow_metrics(132.0001,
1088                                              31.2,
1089                                              101,
1090                                              2101,
1091                                              501,
1092                                              1470409422,
1093                                              988,
1094                                              1470409432,
1095                                              12,
1096                                              (time_t)1470409432,
1097                                              "Inactive",
1098                                              88,
1099                                              4,
1100                                              18,
1101                                              123655,
1102                                              4562,
1103                                              1,
1104                                              13,
1105                                              11,
1106                                              2,
1107                                              4,
1108                                              8,
1109                                              900,
1110                                              902,
1111                                              303,
1112                                              7,
1113                                              3,
1114                                              1,
1115                                              111,
1116                                              226);
1117   if (metrics != NULL)
1118   {
1119     mobile_flow = evel_new_mobile_flow("Inbound",
1120                                        metrics,
1121                                        "UDP",
1122                                        "IPv6",
1123                                        "2.3.4.2",
1124                                        2342,
1125                                        "4.2.3.2",
1126                                        4322);
1127     if (mobile_flow != NULL)
1128     {
1129       evel_mobile_flow_app_type_set(mobile_flow, "Demo application");
1130       evel_mobile_flow_app_prot_type_set(mobile_flow, "GSM");
1131       evel_mobile_flow_app_prot_ver_set(mobile_flow, "1");
1132       evel_mobile_flow_cid_set(mobile_flow, "65535");
1133       evel_mobile_flow_con_type_set(mobile_flow, "S1-U");
1134       evel_mobile_flow_ecgi_set(mobile_flow, "e65535");
1135       evel_mobile_flow_gtp_prot_type_set(mobile_flow, "GTP-U");
1136       evel_mobile_flow_gtp_prot_ver_set(mobile_flow, "1");
1137       evel_mobile_flow_http_header_set(mobile_flow,
1138                                        "http://www.something.com");
1139       evel_mobile_flow_imei_set(mobile_flow, "209917614823");
1140       evel_mobile_flow_imsi_set(mobile_flow, "355251/05/850925/8");
1141       evel_mobile_flow_lac_set(mobile_flow, "1");
1142       evel_mobile_flow_mcc_set(mobile_flow, "410");
1143       evel_mobile_flow_mnc_set(mobile_flow, "04");
1144       evel_mobile_flow_msisdn_set(mobile_flow, "6017123456789");
1145       evel_mobile_flow_other_func_role_set(mobile_flow, "MME");
1146       evel_mobile_flow_rac_set(mobile_flow, "514");
1147       evel_mobile_flow_radio_acc_tech_set(mobile_flow, "LTE");
1148       evel_mobile_flow_sac_set(mobile_flow, "1");
1149       evel_mobile_flow_samp_alg_set(mobile_flow, 1);
1150       evel_mobile_flow_tac_set(mobile_flow, "2099");
1151       evel_mobile_flow_tunnel_id_set(mobile_flow, "Tunnel 1");
1152       evel_mobile_flow_vlan_id_set(mobile_flow, "15");
1153
1154       evel_rc = evel_post_event((EVENT_HEADER *)mobile_flow);
1155       if (evel_rc != EVEL_SUCCESS)
1156       {
1157         EVEL_ERROR("Post Mobile Flow failed %d (%s)",
1158                    evel_rc,
1159                    evel_error_string());
1160       }
1161     }
1162     else
1163     {
1164       EVEL_ERROR("New Mobile Flow failed");
1165     }
1166     printf("   Processed partial Mobile Flow\n");
1167   }
1168   else
1169   {
1170     EVEL_ERROR("New GTP Per Flow Metrics failed - skipping Mobile Flow");
1171     printf("   Skipped partial Mobile Flow\n");
1172   }
1173
1174   metrics = evel_new_mobile_gtp_flow_metrics(12.32,
1175                                              3.122,
1176                                              1002,
1177                                              21002,
1178                                              5002,
1179                                              1470409423,
1180                                              9872,
1181                                              1470409433,
1182                                              112,
1183                                              (time_t)1470409433,
1184                                              "Failed",
1185                                              872,
1186                                              32,
1187                                              172,
1188                                              1236542,
1189                                              45612,
1190                                              2,
1191                                              122,
1192                                              102,
1193                                              12,
1194                                              32,
1195                                              72,
1196                                              8992,
1197                                              9012,
1198                                              3022,
1199                                              62,
1200                                              22,
1201                                              2,
1202                                              1102,
1203                                              2252);
1204   if (metrics != NULL)
1205   {
1206     evel_mobile_gtp_metrics_dur_con_fail_set(metrics, 12);
1207     evel_mobile_gtp_metrics_dur_tun_fail_set(metrics, 13);
1208     evel_mobile_gtp_metrics_act_by_set(metrics, "Remote");
1209     evel_mobile_gtp_metrics_act_time_set(metrics, (time_t)1470409423);
1210     evel_mobile_gtp_metrics_deact_by_set(metrics, "Remote");
1211     evel_mobile_gtp_metrics_con_status_set(metrics, "Connected");
1212     evel_mobile_gtp_metrics_tun_status_set(metrics, "Not tunneling");
1213     evel_mobile_gtp_metrics_iptos_set(metrics, 1, 13);
1214     evel_mobile_gtp_metrics_iptos_set(metrics, 17, 1);
1215     evel_mobile_gtp_metrics_iptos_set(metrics, 4, 99);
1216     evel_mobile_gtp_metrics_large_pkt_rtt_set(metrics, 80);
1217     evel_mobile_gtp_metrics_large_pkt_thresh_set(metrics, 600.0);
1218     evel_mobile_gtp_metrics_max_rcv_bit_rate_set(metrics, 1357924680);
1219     evel_mobile_gtp_metrics_max_trx_bit_rate_set(metrics, 235711);
1220     evel_mobile_gtp_metrics_num_echo_fail_set(metrics, 1);
1221     evel_mobile_gtp_metrics_num_tun_fail_set(metrics, 4);
1222     evel_mobile_gtp_metrics_num_http_errors_set(metrics, 2);
1223     evel_mobile_gtp_metrics_tcp_flag_count_add(metrics, EVEL_TCP_CWR, 10);
1224     evel_mobile_gtp_metrics_tcp_flag_count_add(metrics, EVEL_TCP_URG, 121);
1225     evel_mobile_gtp_metrics_qci_cos_count_add(
1226                                 metrics, EVEL_QCI_COS_UMTS_CONVERSATIONAL, 11);
1227     evel_mobile_gtp_metrics_qci_cos_count_add(
1228                                             metrics, EVEL_QCI_COS_LTE_65, 122);
1229
1230     mobile_flow = evel_new_mobile_flow("Outbound",
1231                                        metrics,
1232                                        "RTP",
1233                                        "IPv8",
1234                                        "2.3.4.3",
1235                                        2343,
1236                                        "4.2.3.3",
1237                                        4323);
1238     if (mobile_flow != NULL)
1239     {
1240       evel_mobile_flow_addl_field_add(mobile_flow, "name1", "value1");
1241       evel_mobile_flow_addl_field_add(mobile_flow, "name2", "value2");
1242       evel_mobile_flow_addl_field_add(mobile_flow, "name3", "value3");
1243
1244       evel_mobile_flow_app_type_set(mobile_flow, "Demo application 2");
1245       evel_mobile_flow_app_prot_type_set(mobile_flow, "GSM");
1246       evel_mobile_flow_app_prot_ver_set(mobile_flow, "2");
1247       evel_mobile_flow_cid_set(mobile_flow, "1");
1248       evel_mobile_flow_con_type_set(mobile_flow, "S1-U");
1249       evel_mobile_flow_ecgi_set(mobile_flow, "e1");
1250       evel_mobile_flow_gtp_prot_type_set(mobile_flow, "GTP-U");
1251       evel_mobile_flow_gtp_prot_ver_set(mobile_flow, "1");
1252       evel_mobile_flow_http_header_set(mobile_flow, "http://www.google.com");
1253       evel_mobile_flow_imei_set(mobile_flow, "209917614823");
1254       evel_mobile_flow_imsi_set(mobile_flow, "355251/05/850925/8");
1255       evel_mobile_flow_lac_set(mobile_flow, "1");
1256       evel_mobile_flow_mcc_set(mobile_flow, "410");
1257       evel_mobile_flow_mnc_set(mobile_flow, "04");
1258       evel_mobile_flow_msisdn_set(mobile_flow, "6017123456789");
1259       evel_mobile_flow_other_func_role_set(mobile_flow, "MMF");
1260       evel_mobile_flow_rac_set(mobile_flow, "514");
1261       evel_mobile_flow_radio_acc_tech_set(mobile_flow, "3G");
1262       evel_mobile_flow_sac_set(mobile_flow, "1");
1263       evel_mobile_flow_samp_alg_set(mobile_flow, 2);
1264       evel_mobile_flow_tac_set(mobile_flow, "2099");
1265       evel_mobile_flow_tunnel_id_set(mobile_flow, "Tunnel 2");
1266       evel_mobile_flow_vlan_id_set(mobile_flow, "4096");
1267
1268       evel_rc = evel_post_event((EVENT_HEADER *)mobile_flow);
1269       if (evel_rc != EVEL_SUCCESS)
1270       {
1271         EVEL_ERROR("Post Mobile Flow failed %d (%s)",
1272                    evel_rc,
1273                    evel_error_string());
1274       }
1275     }
1276     else
1277     {
1278       EVEL_ERROR("New Mobile Flow failed");
1279     }
1280     printf("   Processed full Mobile Flow\n");
1281   }
1282   else
1283   {
1284     EVEL_ERROR("New GTP Per Flow Metrics failed - skipping Mobile Flow");
1285     printf("   Skipped full Mobile Flow\n");
1286   }
1287 }
1288
1289 /**************************************************************************//**
1290  * Create and send a Heartbeat field event.
1291  *****************************************************************************/
1292 void demo_heartbeat_field_event(void)
1293 {
1294   EVENT_HEARTBEAT_FIELD * event = NULL;
1295   EVEL_ERR_CODES evel_rc = EVEL_SUCCESS;
1296
1297   event = evel_new_heartbeat_field(3);
1298   if (event != NULL)
1299   {
1300     evel_hrtbt_interval_set(event, 10);
1301     evel_hrtbt_field_addl_field_add(event, "Name1", "Value1");
1302     evel_hrtbt_field_addl_field_add(event, "Name2", "Value2");
1303
1304     evel_rc = evel_post_event((EVENT_HEADER *) event);
1305     if (evel_rc != EVEL_SUCCESS)
1306     {
1307       EVEL_ERROR("Post failed %d (%s)", evel_rc, evel_error_string());
1308     }
1309   }
1310   else
1311   {
1312     EVEL_ERROR("New heartbeat field failed");
1313   }
1314   printf("   Processed heartbeat Events\n");
1315 }
1316
1317 /**************************************************************************//**
1318  * Create and send a Signaling event.
1319  *****************************************************************************/
1320 void demo_signaling(void)
1321 {
1322   EVENT_SIGNALING * event = NULL;
1323   EVEL_ERR_CODES evel_rc = EVEL_SUCCESS;
1324
1325   event = evel_new_signaling("vendor_x", "correlator", "1.0.3.1", "1234", "192.168.1.3","3456");
1326   if (event != NULL)
1327   {
1328     evel_signaling_addl_info_add(event, "name1", "value1");
1329     evel_signaling_addl_info_add(event, "name2", "value2");
1330     evel_signaling_type_set(event, "Signaling");
1331     evel_signaling_correlator_set(event, "vendor_x_correlator");
1332     evel_signaling_local_ip_address_set(event, "1.0.3.1");
1333     evel_signaling_local_port_set(event, "1031");
1334     evel_signaling_remote_ip_address_set(event, "5.3.3.0");
1335     evel_signaling_remote_port_set(event, "5330");
1336     evel_signaling_compressed_sip_set(event, "compressed_sip");
1337     evel_signaling_summary_sip_set(event, "summary_sip");
1338     evel_signaling_vnfmodule_name_set(event, "vendor_x_module");
1339     evel_signaling_vnfname_set(event, "vendor_x_vnf");
1340     evel_rc = evel_post_event((EVENT_HEADER *) event);
1341     if (evel_rc != EVEL_SUCCESS)
1342     {
1343       EVEL_ERROR("Post failed %d (%s)", evel_rc, evel_error_string());
1344     }
1345   }
1346   else
1347   {
1348     EVEL_ERROR("New Signaling failed");
1349   }
1350   printf("   Processed Signaling\n");
1351 }
1352
1353 /**************************************************************************//**
1354  * Create and send a state change event.
1355  *****************************************************************************/
1356 void demo_state_change(void)
1357 {
1358   EVENT_STATE_CHANGE * state_change = NULL;
1359   EVEL_ERR_CODES evel_rc = EVEL_SUCCESS;
1360
1361   /***************************************************************************/
1362   /* State Change                                                            */
1363   /***************************************************************************/
1364   state_change = evel_new_state_change(EVEL_ENTITY_STATE_IN_SERVICE,
1365                                        EVEL_ENTITY_STATE_OUT_OF_SERVICE,
1366                                        "Interface");
1367   if (state_change != NULL)
1368   {
1369     evel_state_change_type_set(state_change, "State Change");
1370     evel_state_change_addl_field_add(state_change, "Name1", "Value1");
1371     evel_state_change_addl_field_add(state_change, "Name2", "Value2");
1372     evel_rc = evel_post_event((EVENT_HEADER *)state_change);
1373     if (evel_rc != EVEL_SUCCESS)
1374     {
1375       EVEL_ERROR("Post failed %d (%s)", evel_rc, evel_error_string());
1376     }
1377   }
1378   else
1379   {
1380     EVEL_ERROR("New State Change failed");
1381   }
1382   printf("   Processed State Change\n");
1383 }
1384
1385 /**************************************************************************//**
1386  * Create and send two syslog events.
1387  *****************************************************************************/
1388 void demo_syslog(void)
1389 {
1390   EVENT_SYSLOG * syslog = NULL;
1391   EVEL_ERR_CODES evel_rc = EVEL_SUCCESS;
1392
1393   /***************************************************************************/
1394   /* Syslog                                                                  */
1395   /***************************************************************************/
1396   syslog = evel_new_syslog(EVEL_SOURCE_VIRTUAL_NETWORK_FUNCTION,
1397                            "EVEL library message",
1398                            "EVEL");
1399   if (syslog != NULL)
1400   {
1401     evel_rc = evel_post_event((EVENT_HEADER *)syslog);
1402     if (evel_rc != EVEL_SUCCESS)
1403     {
1404       EVEL_ERROR("Post failed %d (%s)", evel_rc, evel_error_string());
1405     }
1406   }
1407   else
1408   {
1409     EVEL_ERROR("New Syslog failed");
1410   }
1411   printf("   Processed empty Syslog\n");
1412
1413   syslog = evel_new_syslog(EVEL_SOURCE_VIRTUAL_MACHINE,
1414                            "EVEL library message",
1415                            "EVEL");
1416   if (syslog != NULL)
1417   {
1418     evel_syslog_event_source_host_set(syslog, "Virtual host");
1419     evel_syslog_facility_set(syslog, EVEL_SYSLOG_FACILITY_LOCAL0);
1420     evel_syslog_proc_set(syslog, "vnf_process");
1421     evel_syslog_proc_id_set(syslog, 1423);
1422     evel_syslog_version_set(syslog, 1);
1423     evel_syslog_addl_filter_set(syslog, "Name1=Value1|Name2=Value2|Name3=Value3");
1424     evel_syslog_sdid_set(syslog, "u354@876876");
1425     evel_syslog_severity_set(syslog, "Error");
1426     evel_rc = evel_post_event((EVENT_HEADER *)syslog);
1427     if (evel_rc != EVEL_SUCCESS)
1428     {
1429       EVEL_ERROR("Post failed %d (%s)", evel_rc, evel_error_string());
1430     }
1431   }
1432   else
1433   {
1434     EVEL_ERROR("New Syslog failed");
1435   }
1436   printf("   Processed full Syslog\n");
1437 }
1438
1439
1440 /**************************************************************************//**
1441  * Create and send VoiceQuality events.
1442  *****************************************************************************/
1443 void demo_voicequality(void)
1444 {
1445   EVENT_VOICE_QUALITY * vq = NULL;
1446   EVEL_ERR_CODES evel_rc = EVEL_SUCCESS;
1447
1448   /***************************************************************************/
1449   /* Voice Quality                                                           */
1450   /***************************************************************************/
1451   vq = evel_new_voice_quality("calleeCodec", "callerCodec",
1452                            "correlator", "midrtcp",
1453                            "EVEL");
1454   if (vq != NULL)
1455   {
1456     evel_rc = evel_post_event((EVENT_HEADER *)vq);
1457     if (evel_rc != EVEL_SUCCESS)
1458     {
1459       EVEL_ERROR("Post failed %d (%s)", evel_rc, evel_error_string());
1460     }
1461   }
1462   else
1463   {
1464     EVEL_ERROR("New Syslog failed");
1465   }
1466   printf("   Processed empty Syslog\n");
1467
1468   vq = evel_new_voice_quality("calleeCodec", "callerCodec",
1469                            "correlator", "midrtcp",
1470                            "EVEL");
1471   if (vq != NULL)
1472   {
1473     evel_voice_quality_end_metrics_add(vq, "adjacent", EVEL_SERVICE_ENDPOINT_CALLER,
1474                                         0,1,2,3,4,5,6,7,8,9,10,11,12,13,4,15,16,17,18);
1475     evel_voice_quality_end_metrics_add(vq, "adjacent", EVEL_SERVICE_ENDPOINT_CALLEE,
1476                                         0,1,2,3,4,5,6,7,8,9,10,11,12,13,4,15,16,17,18);
1477
1478     evel_voice_quality_vnfmodule_name_set(vq, "vnfmodule");
1479     evel_voice_quality_vnfname_set(vq, "vFW");
1480     evel_voice_quality_phone_number_set(vq, "123456789");
1481
1482
1483     evel_rc = evel_post_event((EVENT_HEADER *)vq);
1484     if (evel_rc != EVEL_SUCCESS)
1485     {
1486       EVEL_ERROR("Post failed %d (%s)", evel_rc, evel_error_string());
1487     }
1488   }
1489   else
1490   {
1491     EVEL_ERROR("New Syslog failed");
1492   }
1493   printf("   Processed full Syslog\n");
1494 }
1495
1496 /**************************************************************************//**
1497  * Create and send two other events.
1498  *****************************************************************************/
1499 void demo_other(void)
1500 {
1501   EVENT_OTHER * other = NULL;
1502   EVEL_ERR_CODES evel_rc = EVEL_SUCCESS;
1503
1504   /***************************************************************************/
1505   /* Other                                                                   */
1506   /***************************************************************************/
1507   other = evel_new_other();
1508   if (other != NULL)
1509   {
1510     evel_rc = evel_post_event((EVENT_HEADER *)other);
1511     if (evel_rc != EVEL_SUCCESS)
1512     {
1513       EVEL_ERROR("Post failed %d (%s)", evel_rc, evel_error_string());
1514     }
1515   }
1516   else
1517   {
1518     EVEL_ERROR("New Other failed");
1519   }
1520   printf("   Processed empty Other\n");
1521
1522   other = evel_new_other();
1523   if (other != NULL)
1524   {
1525
1526
1527    char * jsstr = "{"
1528                  "\"data1\":[1,2,3,4,5,6,7,8,9],"
1529                  "\"data2\":["
1530                      "[3,4,5,6,1],"
1531                      "[8,4,5,6,1],"
1532                      "[10,4,5,3,61],"
1533                      "[3,4,5,6,1],"
1534                      "[3,4,5,6,1],"
1535                      "[3,4,5,6,1]"
1536                  "]"
1537              "}";
1538
1539
1540 char * jsstr2 = "{ \"employee\":{ \"name\":\"John\", \"age\":30, \"city\":\"New York\" } }";
1541
1542     evel_other_field_set_namedarraysize(other,50);
1543     evel_other_field_add_namedarray(other,"name1", "disk1", "10000");
1544     evel_other_field_add_namedarray(other,"name2", "disk2", "20000");
1545     evel_other_field_add_namedarray(other,"name1", "disk2", "20000");
1546     evel_other_field_add_namedarray(other,"name1", "disk1", "20000");
1547
1548      EVEL_JSON_OBJECT_INSTANCE * njinst = evel_new_jsonobjinstance(jsstr );
1549      evel_epoch_microsec_set(njinst,9287578586767);
1550      EVEL_INTERNAL_KEY * nkey = evel_new_internal_key("key1");
1551      evel_internal_key_keyorder_set(nkey , 2);
1552      evel_internal_key_keyvalue_set(nkey , "val1");
1553      EVEL_INTERNAL_KEY * nkey2= evel_new_internal_key("key2");
1554      evel_internal_key_keyorder_set(nkey2, 2);
1555      evel_internal_key_keyvalue_set(nkey2, "val2");
1556      evel_jsonobjinst_add_objectkey(njinst, nkey);
1557      evel_jsonobjinst_add_objectkey(njinst, nkey2);
1558
1559      EVEL_JSON_OBJECT_INSTANCE * njinst2 = evel_new_jsonobjinstance(jsstr2 );
1560      evel_epoch_microsec_set(njinst2,927578586767);
1561
1562     EVEL_JSON_OBJECT * myobj =  evel_new_jsonobject("Myjobject");
1563     evel_jsonobject_objectschema_set(myobj,"jsonschema5.0");
1564     evel_jsonobject_objectschemaurl_set(myobj,"http://jsonschema5.0.att.com");
1565     evel_jsonobject_nfsubscribedobjname_set(myobj,"nfobj1");
1566     evel_jsonobject_nfsubscriptionid_set(myobj,"nfid1234");
1567     evel_jsonobject_add_jsoninstance(myobj,njinst);
1568     evel_jsonobject_add_jsoninstance(myobj,njinst2);
1569     evel_other_field_add_jsonobj(other,myobj);
1570
1571     evel_other_field_add(other,
1572                          "Other field 1",
1573                          "Other value 1");
1574
1575
1576     evel_rc = evel_post_event((EVENT_HEADER *)other);
1577     if (evel_rc != EVEL_SUCCESS)
1578     {
1579       EVEL_ERROR("Post failed %d (%s)", evel_rc, evel_error_string());
1580     }
1581   }
1582   else
1583   {
1584     EVEL_ERROR("New Other failed");
1585   }
1586   printf("   Processed small Other\n");
1587   other = evel_new_other();
1588   if (other != NULL)
1589   {
1590     evel_other_field_add(other,
1591                          "Other field A",
1592                          "Other value A");
1593     evel_other_field_add(other,
1594                          "Other field B",
1595                          "Other value B");
1596     evel_other_field_add(other,
1597                          "Other field C",
1598                          "Other value C");
1599
1600     evel_rc = evel_post_event((EVENT_HEADER *)other);
1601     if (evel_rc != EVEL_SUCCESS)
1602     {
1603       EVEL_ERROR("Post failed %d (%s)", evel_rc, evel_error_string());
1604     }
1605   }
1606   else
1607   {
1608     EVEL_ERROR("New Other failed");
1609   }
1610   printf("   Processed large Other\n");
1611 }