Initial VES for DANOS vRouter
[demo.git] / vnfs / VESreporting_vFW5.0_DANOS / evel / evel-library / code / evel_library / evel_strings.c
1 /*************************************************************************//**
2  *
3  * Copyright © 2017 AT&T Intellectual Property. All rights reserved.
4  *
5  * Unless otherwise specified, all software contained herein is
6  * Licensed under the Apache License, Version 2.0 (the "License");
7  * you may not use this file except in compliance with the License.
8  * You may obtain a copy of the License at
9  *        http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and 
15  * limitations under the License.
16  * ECOMP is a trademark and service mark of AT&T Intellectual Property.
17  ****************************************************************************/
18 /**************************************************************************//**
19  * @file
20  * Implementation of EVEL functions to convert common enum types to strings.
21  *
22  ****************************************************************************/
23
24 #include <string.h>
25 #include <assert.h>
26 #include <stdlib.h>
27
28 #include "evel_internal.h"
29
30 /**************************************************************************//**
31  * Map an ::EVEL_COUNTER_CRITICALITIES enum value to the equivalent string.
32  *
33  * @param criticality   The criticality to convert.
34  * @returns The equivalent string.
35  *****************************************************************************/
36 char * evel_criticality(const EVEL_COUNTER_CRITICALITIES criticality)
37 {
38   char * result;
39
40   EVEL_ENTER();
41
42   switch (criticality)
43   {
44     case EVEL_COUNTER_CRITICALITY_CRIT:
45       result = "CRIT";
46       break;
47
48     case EVEL_COUNTER_CRITICALITY_MAJ:
49       result = "MAJ";
50       break;
51
52     default:
53       EVEL_ERROR("Unexpected counter criticality %d", criticality);
54       assert(0);
55   }
56
57   EVEL_EXIT();
58
59   return result;
60 }
61
62 /**************************************************************************//**
63  * Map an ::EVEL_SEVERITIES enum value to the equivalent string.
64  *
65  * @param severity      The severity to convert.
66  * @returns The equivalent string.
67  *****************************************************************************/
68 char * evel_severity(const EVEL_SEVERITIES severity)
69 {
70   char * result;
71
72   EVEL_ENTER();
73
74   switch (severity)
75   {
76     case EVEL_SEVERITY_CRITICAL:
77       result = "CRITICAL";
78       break;
79
80     case EVEL_SEVERITY_MAJOR:
81       result = "MAJOR";
82       break;
83
84     case EVEL_SEVERITY_MINOR:
85       result = "MINOR";
86       break;
87
88     case EVEL_SEVERITY_WARNING:
89       result = "WARNING";
90       break;
91
92     case EVEL_SEVERITY_NORMAL:
93       result = "NORMAL";
94       break;
95
96     default:
97       EVEL_ERROR("Unexpected event severity %d", severity);
98       assert(0);
99   }
100
101   EVEL_EXIT();
102
103   return result;
104 }
105
106 /**************************************************************************//**
107  * Map an ::EVEL_ALERT_ACTIONS enum value to the equivalent string.
108  *
109  * @param alert_action  The alert_action to convert.
110  * @returns The equivalent string.
111  *****************************************************************************/
112 char * evel_alert_action(const EVEL_ALERT_ACTIONS alert_action)
113 {
114   char * result;
115
116   EVEL_ENTER();
117
118   switch (alert_action)
119   {
120     case EVEL_ALERT_ACTION_CLEAR:
121       result = "CLEAR";
122       break;
123
124     case EVEL_ALERT_ACTION_CONT:
125       result = "CONT";
126       break;
127
128     case EVEL_ALERT_ACTION_SET:
129       result = "SET";
130       break;
131
132     default:
133       EVEL_ERROR("Unexpected alert action %d", alert_action);
134       assert(0);
135   }
136
137   EVEL_EXIT();
138
139   return result;
140 }
141
142 /**************************************************************************//**
143  * Map an ::EVEL_ALERT_TYPES enum value to the equivalent string.
144  *
145  * @param alert_type    The alert_type to convert.
146  * @returns The equivalent string.
147  *****************************************************************************/
148 char * evel_alert_type(const EVEL_ALERT_TYPES alert_type)
149 {
150   char * result;
151
152   EVEL_ENTER();
153
154   switch (alert_type)
155   {
156     case EVEL_ALERT_TYPE_CARD:
157       result = "CARD-ANOMALY";
158       break;
159
160     case EVEL_ALERT_TYPE_ELEMENT:
161       result = "ELEMENT-ANOMALY";
162       break;
163
164     case EVEL_ALERT_TYPE_INTERFACE:
165       result = "INTERFACE-ANOMALY";
166       break;
167
168     case EVEL_ALERT_TYPE_SERVICE:
169       result = "SERVICE-ANOMALY";
170       break;
171
172     default:
173       EVEL_ERROR("Unexpected alert type %d", alert_type);
174       assert(0);
175   }
176
177   EVEL_EXIT();
178
179   return result;
180 }
181
182 /**************************************************************************//**
183  * Map an ::EVEL_EVENT_DOMAINS enum value to the equivalent string.
184  *
185  * @param domain        The domain to convert.
186  * @returns The equivalent string.
187  *****************************************************************************/
188 char * evel_event_domain(const EVEL_EVENT_DOMAINS domain)
189 {
190   char * result;
191
192   EVEL_ENTER();
193
194   switch (domain)
195   {
196     case EVEL_DOMAIN_HEARTBEAT:
197       result = "heartbeat";
198       break;
199
200     case EVEL_DOMAIN_FAULT:
201       result = "fault";
202       break;
203
204     case EVEL_DOMAIN_MEASUREMENT:
205       result = "measurementsForVfScaling";
206       break;
207
208     case EVEL_DOMAIN_REPORT:
209       result = "measurementsForVfReporting";
210       break;
211
212     case EVEL_DOMAIN_MOBILE_FLOW:
213       result = "mobileFlow";
214       break;
215
216     case EVEL_DOMAIN_HEARTBEAT_FIELD:
217       result = "heartbeat";
218       break;
219
220     case EVEL_DOMAIN_SIPSIGNALING:
221       result = "sipSignaling";
222       break;
223
224     case EVEL_DOMAIN_STATE_CHANGE:
225       result = "stateChange";
226       break;
227
228     case EVEL_DOMAIN_SYSLOG:
229       result = "syslog";
230       break;
231
232     case EVEL_DOMAIN_OTHER:
233       result = "other";
234       break;
235
236     case EVEL_DOMAIN_VOICE_QUALITY:
237       result = "voiceQuality";
238       break;
239
240     case EVEL_DOMAIN_THRESHOLD_CROSS:
241       result = "thresholdCrossingAlert";
242       break;
243
244     default:
245       result = NULL;
246       EVEL_ERROR("Unexpected domain %d", domain);
247       assert(0);
248   }
249
250   EVEL_EXIT();
251
252   return result;
253 }
254
255 /**************************************************************************//**
256  * Map an ::EVEL_EVENT_PRIORITIES enum value to the equivalent string.
257  *
258  * @param priority      The priority to convert.
259  * @returns The equivalent string.
260  *****************************************************************************/
261 char * evel_event_priority(const EVEL_EVENT_PRIORITIES priority)
262 {
263   char * result;
264
265   EVEL_ENTER();
266
267   switch (priority)
268   {
269     case EVEL_PRIORITY_HIGH:
270       result = "High";
271       break;
272
273     case EVEL_PRIORITY_MEDIUM:
274       result = "Medium";
275       break;
276
277     case EVEL_PRIORITY_NORMAL:
278       result = "Normal";
279       break;
280
281     case EVEL_PRIORITY_LOW:
282       result = "Low";
283       break;
284
285     default:
286       result = NULL;
287       EVEL_ERROR("Unexpected priority %d", priority);
288       assert(0);
289   }
290
291   EVEL_EXIT();
292
293   return result;
294 }
295
296 /**************************************************************************//**
297  * Map an ::EVEL_SOURCE_TYPES enum value to the equivalent string.
298  *
299  * @param source_type   The source type to convert.
300  * @returns The equivalent string.
301  *****************************************************************************/
302 char * evel_source_type(const EVEL_SOURCE_TYPES source_type)
303 {
304   char * result;
305
306   EVEL_ENTER();
307
308   switch (source_type)
309   {
310     case EVEL_SOURCE_OTHER:
311       result = "other";
312       break;
313
314     case EVEL_SOURCE_ROUTER:
315       result = "router";
316       break;
317
318     case EVEL_SOURCE_SWITCH:
319       result = "switch";
320       break;
321
322     case EVEL_SOURCE_HOST:
323       result = "host";
324       break;
325
326     case EVEL_SOURCE_CARD:
327       result = "card";
328       break;
329
330     case EVEL_SOURCE_PORT:
331       result = "port";
332       break;
333
334     case EVEL_SOURCE_SLOT_THRESHOLD:
335       result = "slotThreshold";
336       break;
337
338     case EVEL_SOURCE_PORT_THRESHOLD:
339       result = "portThreshold";
340       break;
341
342     case EVEL_SOURCE_VIRTUAL_MACHINE:
343       result = "virtualMachine";
344       break;
345
346     case EVEL_SOURCE_VIRTUAL_NETWORK_FUNCTION:
347       result = "virtualNetworkFunction";
348       break;
349
350     default:
351       result = NULL;
352       EVEL_ERROR("Unexpected Event Source Type %d", (int) source_type);
353       assert(0);
354   }
355
356   EVEL_EXIT();
357
358   return result;
359 }
360
361 /**************************************************************************//**
362  * Map an ::EVEL_VF_STATUSES enum value to the equivalent string.
363  *
364  * @param vf_status     The vf_status to convert.
365  * @returns The equivalent string.
366  *****************************************************************************/
367 char * evel_vf_status(const EVEL_VF_STATUSES vf_status)
368 {
369   char * result;
370
371   EVEL_ENTER();
372
373   switch (vf_status)
374   {
375     case EVEL_VF_STATUS_ACTIVE:
376       result = "Active";
377       break;
378
379     case EVEL_VF_STATUS_IDLE:
380       result = "Idle";
381       break;
382
383     case EVEL_VF_STATUS_PREP_TERMINATE:
384       result = "Preparing to terminate";
385       break;
386
387     case EVEL_VF_STATUS_READY_TERMINATE:
388       result = "Ready to terminate";
389       break;
390
391     case EVEL_VF_STATUS_REQ_TERMINATE:
392       result = "Requesting termination";
393       break;
394
395     default:
396       result = NULL;
397       EVEL_ERROR("Unexpected VF Status %d", vf_status);
398       assert(0);
399   }
400
401   EVEL_EXIT();
402
403   return result;
404 }
405
406 /**************************************************************************//**
407  * Convert a ::EVEL_ENTITY_STATE to it's string form for JSON encoding.
408  *
409  * @param state         The entity state to encode.
410  *
411  * @returns the corresponding string
412  *****************************************************************************/
413 char * evel_entity_state(const EVEL_ENTITY_STATE state)
414 {
415   char * result;
416
417   EVEL_ENTER();
418
419   switch (state)
420   {
421     case EVEL_ENTITY_STATE_IN_SERVICE:
422       result = "inService";
423       break;
424
425     case EVEL_ENTITY_STATE_MAINTENANCE:
426       result = "maintenance";
427       break;
428
429     case EVEL_ENTITY_STATE_OUT_OF_SERVICE:
430       result = "outOfService";
431       break;
432
433     default:
434       EVEL_ERROR("Unexpected entity state %d", state);
435       assert(0);
436   }
437
438   EVEL_EXIT();
439
440   return result;
441 }
442
443 /**************************************************************************//**
444  * Convert a ::EVEL_SERVICE_ENDPOINT_DESC to string form for JSON encoding.
445  *
446  * @param endpoint_desc endpoint description to encode.
447  *
448  * @returns the corresponding string
449  *****************************************************************************/
450 char * evel_service_endpoint_desc(const EVEL_ENTITY_STATE endpoint_desc)
451 {
452   char * result;
453
454   EVEL_ENTER();
455
456   switch (endpoint_desc)
457   {
458     case EVEL_SERVICE_ENDPOINT_CALLEE:
459       result = "Callee";
460       break;
461
462     case EVEL_SERVICE_ENDPOINT_CALLER:
463       result = "Caller";
464       break;
465
466     default:
467       EVEL_ERROR("Unexpected endpoint description %d", endpoint_desc);
468       assert(0);
469   }
470
471   EVEL_EXIT();
472
473   return result;
474 }