Fix for delta values reported by vFW vLB
[demo.git] / vnfs / VES5.0 / evel / evel-library / code / evel_training / 08-raise-mobile-flow / hello_evel_world.c
1 #include <stdio.h>
2 #include <stdlib.h>
3 #include <unistd.h>
4
5 #include "evel.h"
6
7 /*****************************************************************************/
8 /* Local prototypes.                                                         */
9 /*****************************************************************************/
10 static void demo_mobile_flow(void);
11
12 int main(int argc, char ** argv)
13 {
14   EVEL_ERR_CODES evel_rc = EVEL_SUCCESS;
15   EVENT_HEADER * heartbeat = NULL;
16
17   printf("\nHello AT&T Vendor Event world!\n");
18   fflush(stdout);
19
20   if (argc != 5)
21   {
22     fprintf(stderr,
23             "Usage: %s <FQDN>|<IP address> <port> "
24             "<username> <password>\n", argv[0]);
25     exit(-1);
26   }
27
28   /***************************************************************************/
29   /* Initialize                                                              */
30   /***************************************************************************/
31   if (evel_initialize(argv[1],                      /* FQDN                  */
32                       atoi(argv[2]),                /* Port                  */
33                       NULL,                         /* optional path         */
34                       NULL,                         /* optional topic        */
35                       0,                            /* HTTPS?                */
36                       argv[3],                      /* Username              */
37                       argv[4],                      /* Password              */
38                       EVEL_SOURCE_VIRTUAL_MACHINE,  /* Source type           */
39                       "EVEL training demo",         /* Role                  */
40                       0))                           /* Verbosity             */
41   {
42     fprintf(stderr, "\nFailed to initialize the EVEL library!!!\n");
43     exit(-1);
44   }
45   else
46   {
47     printf("\nInitialization completed\n");
48   }
49
50   /***************************************************************************/
51   /* Send a heartbeat just to show we're alive!                              */
52   /***************************************************************************/
53   heartbeat = evel_new_heartbeat();
54   if (heartbeat != NULL)
55   {
56     evel_rc = evel_post_event(heartbeat);
57     if (evel_rc != EVEL_SUCCESS)
58     {
59       printf("Post failed %d (%s)", evel_rc, evel_error_string());
60     }
61   }
62   else
63   {
64     printf("New heartbeat failed");
65   }
66
67   /***************************************************************************/
68   /* Raise a measurement                                                     */
69   /***************************************************************************/
70   demo_mobile_flow();
71
72   /***************************************************************************/
73   /* Terminate                                                               */
74   /***************************************************************************/
75   sleep(1);
76   evel_terminate();
77   printf("Terminated\n");
78
79   return 0;
80 }
81
82 /**************************************************************************//**
83  * Create and send three mobile flow events.
84  *****************************************************************************/
85 void demo_mobile_flow(void)
86 {
87   MOBILE_GTP_PER_FLOW_METRICS * metrics = NULL;
88   EVENT_MOBILE_FLOW * mobile_flow = NULL;
89   EVEL_ERR_CODES evel_rc = EVEL_SUCCESS;
90
91   metrics = evel_new_mobile_gtp_flow_metrics(12.32,
92                                              3.122,
93                                              1002,
94                                              21002,
95                                              5002,
96                                              1470409423,
97                                              9872,
98                                              1470409433,
99                                              112,
100                                              (time_t)1470409433,
101                                              "Failed",
102                                              872,
103                                              32,
104                                              172,
105                                              1236542,
106                                              45612,
107                                              2,
108                                              122,
109                                              102,
110                                              12,
111                                              32,
112                                              72,
113                                              8992,
114                                              9012,
115                                              3022,
116                                              62,
117                                              22,
118                                              2,
119                                              1102,
120                                              2252);
121   if (metrics != NULL)
122   {
123     evel_mobile_gtp_metrics_dur_con_fail_set(metrics, 12);
124     evel_mobile_gtp_metrics_dur_tun_fail_set(metrics, 13);
125     evel_mobile_gtp_metrics_act_by_set(metrics, "Remote");
126     evel_mobile_gtp_metrics_act_time_set(metrics, (time_t)1470409423);
127     evel_mobile_gtp_metrics_deact_by_set(metrics, "Remote");
128     evel_mobile_gtp_metrics_con_status_set(metrics, "Connected");
129     evel_mobile_gtp_metrics_tun_status_set(metrics, "Not tunneling");
130     evel_mobile_gtp_metrics_iptos_set(metrics, 1, 13);
131     evel_mobile_gtp_metrics_iptos_set(metrics, 17, 1);
132     evel_mobile_gtp_metrics_iptos_set(metrics, 4, 99);
133     evel_mobile_gtp_metrics_large_pkt_rtt_set(metrics, 80);
134     evel_mobile_gtp_metrics_large_pkt_thresh_set(metrics, 600.0);
135     evel_mobile_gtp_metrics_max_rcv_bit_rate_set(metrics, 1357924680);
136     evel_mobile_gtp_metrics_max_trx_bit_rate_set(metrics, 235711);
137     evel_mobile_gtp_metrics_num_echo_fail_set(metrics, 1);
138     evel_mobile_gtp_metrics_num_tun_fail_set(metrics, 4);
139     evel_mobile_gtp_metrics_num_http_errors_set(metrics, 2);
140     evel_mobile_gtp_metrics_tcp_flag_count_add(metrics, EVEL_TCP_CWR, 10);
141     evel_mobile_gtp_metrics_tcp_flag_count_add(metrics, EVEL_TCP_URG, 121);
142     evel_mobile_gtp_metrics_qci_cos_count_add(
143                                 metrics, EVEL_QCI_COS_UMTS_CONVERSATIONAL, 11);
144     evel_mobile_gtp_metrics_qci_cos_count_add(
145                                             metrics, EVEL_QCI_COS_LTE_65, 122);
146
147     mobile_flow = evel_new_mobile_flow("Outbound",
148                                        metrics,
149                                        "RTP",
150                                        "IPv8",
151                                        "2.3.4.3",
152                                        2343,
153                                        "4.2.3.3",
154                                        4323);
155     if (mobile_flow != NULL)
156     {
157       evel_mobile_flow_app_type_set(mobile_flow, "Demo application 2");
158       evel_mobile_flow_app_prot_type_set(mobile_flow, "GSM");
159       evel_mobile_flow_app_prot_ver_set(mobile_flow, "2");
160       evel_mobile_flow_cid_set(mobile_flow, "1");
161       evel_mobile_flow_con_type_set(mobile_flow, "S1-U");
162       evel_mobile_flow_ecgi_set(mobile_flow, "e1");
163       evel_mobile_flow_gtp_prot_type_set(mobile_flow, "GTP-U");
164       evel_mobile_flow_gtp_prot_ver_set(mobile_flow, "1");
165       evel_mobile_flow_http_header_set(mobile_flow, "http://www.google.com");
166       evel_mobile_flow_imei_set(mobile_flow, "209917614823");
167       evel_mobile_flow_imsi_set(mobile_flow, "355251/05/850925/8");
168       evel_mobile_flow_lac_set(mobile_flow, "1");
169       evel_mobile_flow_mcc_set(mobile_flow, "410");
170       evel_mobile_flow_mnc_set(mobile_flow, "04");
171       evel_mobile_flow_msisdn_set(mobile_flow, "6017123456789");
172       evel_mobile_flow_other_func_role_set(mobile_flow, "MMF");
173       evel_mobile_flow_rac_set(mobile_flow, "514");
174       evel_mobile_flow_radio_acc_tech_set(mobile_flow, "3G");
175       evel_mobile_flow_sac_set(mobile_flow, "1");
176       evel_mobile_flow_samp_alg_set(mobile_flow, 2);
177       evel_mobile_flow_tac_set(mobile_flow, "2099");
178       evel_mobile_flow_tunnel_id_set(mobile_flow, "Tunnel 2");
179       evel_mobile_flow_vlan_id_set(mobile_flow, "4096");
180
181       evel_rc = evel_post_event((EVENT_HEADER *)mobile_flow);
182       if (evel_rc == EVEL_SUCCESS)
183       {
184         printf("Post OK!\n");
185       }
186       else
187       {
188         printf("Post Failed %d (%s)\n", evel_rc, evel_error_string());
189       }
190     }
191     else
192     {
193       printf("Failed to create event (%s)\n", evel_error_string());
194     }
195     printf("   Processed full Mobile Flow\n");
196   }
197   else
198   {
199     printf("New GTP Per Flow Metrics failed\n");
200   }
201 }