Merge "removed vFW vLB extra executables"
[demo.git] / vnfs / VES5.0 / evel / evel-library / code / evel_library / evel_strings.c
1 /**************************************************************************//**
2  * @file
3  * Implementation of EVEL functions to convert common enum types to strings.
4  *
5  * License
6  * -------
7  *
8  * Redistribution and use in source and binary forms, with or without
9  * modification, are permitted provided that the following conditions are met:
10  *
11  * 1. Redistributions of source code must retain the above copyright notice,
12  *    this list of conditions and the following disclaimer.
13  * 2. Redistributions in binary form must reproduce the above copyright notice,
14  *    this list of conditions and the following disclaimer in the documentation
15  *    and/or other materials provided with the distribution.
16  * 3. All advertising materials mentioning features or use of this software
17  *    must display the following acknowledgement:  This product includes
18  *    software developed by the AT&T.
19  * 4. Neither the name of AT&T nor the names of its contributors may be used to
20  *    endorse or promote products derived from this software without specific
21  *    prior written permission.
22  *
23  * THIS SOFTWARE IS PROVIDED BY AT&T INTELLECTUAL PROPERTY ''AS IS'' AND ANY
24  * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
25  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
26  * DISCLAIMED. IN NO EVENT SHALL AT&T INTELLECTUAL PROPERTY BE LIABLE FOR ANY
27  * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
28  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
29  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
30  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
31  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
32  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33  *****************************************************************************/
34
35 #include <string.h>
36 #include <assert.h>
37 #include <stdlib.h>
38
39 #include "evel_internal.h"
40
41 /**************************************************************************//**
42  * Map an ::EVEL_COUNTER_CRITICALITIES enum value to the equivalent string.
43  *
44  * @param criticality   The criticality to convert.
45  * @returns The equivalent string.
46  *****************************************************************************/
47 char * evel_criticality(const EVEL_COUNTER_CRITICALITIES criticality)
48 {
49   char * result;
50
51   EVEL_ENTER();
52
53   switch (criticality)
54   {
55     case EVEL_COUNTER_CRITICALITY_CRIT:
56       result = "CRIT";
57       break;
58
59     case EVEL_COUNTER_CRITICALITY_MAJ:
60       result = "MAJ";
61       break;
62
63     default:
64       EVEL_ERROR("Unexpected counter criticality %d", criticality);
65       assert(0);
66   }
67
68   EVEL_EXIT();
69
70   return result;
71 }
72
73 /**************************************************************************//**
74  * Map an ::EVEL_SEVERITIES enum value to the equivalent string.
75  *
76  * @param severity      The severity to convert.
77  * @returns The equivalent string.
78  *****************************************************************************/
79 char * evel_severity(const EVEL_SEVERITIES severity)
80 {
81   char * result;
82
83   EVEL_ENTER();
84
85   switch (severity)
86   {
87     case EVEL_SEVERITY_CRITICAL:
88       result = "CRITICAL";
89       break;
90
91     case EVEL_SEVERITY_MAJOR:
92       result = "MAJOR";
93       break;
94
95     case EVEL_SEVERITY_MINOR:
96       result = "MINOR";
97       break;
98
99     case EVEL_SEVERITY_WARNING:
100       result = "WARNING";
101       break;
102
103     case EVEL_SEVERITY_NORMAL:
104       result = "NORMAL";
105       break;
106
107     default:
108       EVEL_ERROR("Unexpected event severity %d", severity);
109       assert(0);
110   }
111
112   EVEL_EXIT();
113
114   return result;
115 }
116
117 /**************************************************************************//**
118  * Map an ::EVEL_ALERT_ACTIONS enum value to the equivalent string.
119  *
120  * @param alert_action  The alert_action to convert.
121  * @returns The equivalent string.
122  *****************************************************************************/
123 char * evel_alert_action(const EVEL_ALERT_ACTIONS alert_action)
124 {
125   char * result;
126
127   EVEL_ENTER();
128
129   switch (alert_action)
130   {
131     case EVEL_ALERT_ACTION_CLEAR:
132       result = "CLEAR";
133       break;
134
135     case EVEL_ALERT_ACTION_CONT:
136       result = "CONT";
137       break;
138
139     case EVEL_ALERT_ACTION_SET:
140       result = "SET";
141       break;
142
143     default:
144       EVEL_ERROR("Unexpected alert action %d", alert_action);
145       assert(0);
146   }
147
148   EVEL_EXIT();
149
150   return result;
151 }
152
153 /**************************************************************************//**
154  * Map an ::EVEL_ALERT_TYPES enum value to the equivalent string.
155  *
156  * @param alert_type    The alert_type to convert.
157  * @returns The equivalent string.
158  *****************************************************************************/
159 char * evel_alert_type(const EVEL_ALERT_TYPES alert_type)
160 {
161   char * result;
162
163   EVEL_ENTER();
164
165   switch (alert_type)
166   {
167     case EVEL_ALERT_TYPE_CARD:
168       result = "CARD-ANOMALY";
169       break;
170
171     case EVEL_ALERT_TYPE_ELEMENT:
172       result = "ELEMENT-ANOMALY";
173       break;
174
175     case EVEL_ALERT_TYPE_INTERFACE:
176       result = "INTERFACE-ANOMALY";
177       break;
178
179     case EVEL_ALERT_TYPE_SERVICE:
180       result = "SERVICE-ANOMALY";
181       break;
182
183     default:
184       EVEL_ERROR("Unexpected alert type %d", alert_type);
185       assert(0);
186   }
187
188   EVEL_EXIT();
189
190   return result;
191 }
192
193 /**************************************************************************//**
194  * Map an ::EVEL_EVENT_DOMAINS enum value to the equivalent string.
195  *
196  * @param domain        The domain to convert.
197  * @returns The equivalent string.
198  *****************************************************************************/
199 char * evel_event_domain(const EVEL_EVENT_DOMAINS domain)
200 {
201   char * result;
202
203   EVEL_ENTER();
204
205   switch (domain)
206   {
207     case EVEL_DOMAIN_HEARTBEAT:
208       result = "heartbeat";
209       break;
210
211     case EVEL_DOMAIN_FAULT:
212       result = "fault";
213       break;
214
215     case EVEL_DOMAIN_MEASUREMENT:
216       result = "measurementsForVfScaling";
217       break;
218
219     case EVEL_DOMAIN_REPORT:
220       result = "measurementsForVfReporting";
221       break;
222
223     case EVEL_DOMAIN_MOBILE_FLOW:
224       result = "mobileFlow";
225       break;
226
227     case EVEL_DOMAIN_HEARTBEAT_FIELD:
228       result = "heartbeat";
229       break;
230
231     case EVEL_DOMAIN_SIPSIGNALING:
232       result = "sipSignaling";
233       break;
234
235     case EVEL_DOMAIN_STATE_CHANGE:
236       result = "stateChange";
237       break;
238
239     case EVEL_DOMAIN_SYSLOG:
240       result = "syslog";
241       break;
242
243     case EVEL_DOMAIN_OTHER:
244       result = "other";
245       break;
246
247     case EVEL_DOMAIN_VOICE_QUALITY:
248       result = "voiceQuality";
249       break;
250
251     default:
252       result = NULL;
253       EVEL_ERROR("Unexpected domain %d", domain);
254       assert(0);
255   }
256
257   EVEL_EXIT();
258
259   return result;
260 }
261
262 /**************************************************************************//**
263  * Map an ::EVEL_EVENT_PRIORITIES enum value to the equivalent string.
264  *
265  * @param priority      The priority to convert.
266  * @returns The equivalent string.
267  *****************************************************************************/
268 char * evel_event_priority(const EVEL_EVENT_PRIORITIES priority)
269 {
270   char * result;
271
272   EVEL_ENTER();
273
274   switch (priority)
275   {
276     case EVEL_PRIORITY_HIGH:
277       result = "High";
278       break;
279
280     case EVEL_PRIORITY_MEDIUM:
281       result = "Medium";
282       break;
283
284     case EVEL_PRIORITY_NORMAL:
285       result = "Normal";
286       break;
287
288     case EVEL_PRIORITY_LOW:
289       result = "Low";
290       break;
291
292     default:
293       result = NULL;
294       EVEL_ERROR("Unexpected priority %d", priority);
295       assert(0);
296   }
297
298   EVEL_EXIT();
299
300   return result;
301 }
302
303 /**************************************************************************//**
304  * Map an ::EVEL_SOURCE_TYPES enum value to the equivalent string.
305  *
306  * @param source_type   The source type to convert.
307  * @returns The equivalent string.
308  *****************************************************************************/
309 char * evel_source_type(const EVEL_SOURCE_TYPES source_type)
310 {
311   char * result;
312
313   EVEL_ENTER();
314
315   switch (source_type)
316   {
317     case EVEL_SOURCE_OTHER:
318       result = "other";
319       break;
320
321     case EVEL_SOURCE_ROUTER:
322       result = "router";
323       break;
324
325     case EVEL_SOURCE_SWITCH:
326       result = "switch";
327       break;
328
329     case EVEL_SOURCE_HOST:
330       result = "host";
331       break;
332
333     case EVEL_SOURCE_CARD:
334       result = "card";
335       break;
336
337     case EVEL_SOURCE_PORT:
338       result = "port";
339       break;
340
341     case EVEL_SOURCE_SLOT_THRESHOLD:
342       result = "slotThreshold";
343       break;
344
345     case EVEL_SOURCE_PORT_THRESHOLD:
346       result = "portThreshold";
347       break;
348
349     case EVEL_SOURCE_VIRTUAL_MACHINE:
350       result = "virtualMachine";
351       break;
352
353     case EVEL_SOURCE_VIRTUAL_NETWORK_FUNCTION:
354       result = "virtualNetworkFunction";
355       break;
356
357     default:
358       result = NULL;
359       EVEL_ERROR("Unexpected Event Source Type %d", (int) source_type);
360       assert(0);
361   }
362
363   EVEL_EXIT();
364
365   return result;
366 }
367
368 /**************************************************************************//**
369  * Map an ::EVEL_VF_STATUSES enum value to the equivalent string.
370  *
371  * @param vf_status     The vf_status to convert.
372  * @returns The equivalent string.
373  *****************************************************************************/
374 char * evel_vf_status(const EVEL_VF_STATUSES vf_status)
375 {
376   char * result;
377
378   EVEL_ENTER();
379
380   switch (vf_status)
381   {
382     case EVEL_VF_STATUS_ACTIVE:
383       result = "Active";
384       break;
385
386     case EVEL_VF_STATUS_IDLE:
387       result = "Idle";
388       break;
389
390     case EVEL_VF_STATUS_PREP_TERMINATE:
391       result = "Preparing to terminate";
392       break;
393
394     case EVEL_VF_STATUS_READY_TERMINATE:
395       result = "Ready to terminate";
396       break;
397
398     case EVEL_VF_STATUS_REQ_TERMINATE:
399       result = "Requesting termination";
400       break;
401
402     default:
403       result = NULL;
404       EVEL_ERROR("Unexpected VF Status %d", vf_status);
405       assert(0);
406   }
407
408   EVEL_EXIT();
409
410   return result;
411 }
412
413 /**************************************************************************//**
414  * Convert a ::EVEL_ENTITY_STATE to it's string form for JSON encoding.
415  *
416  * @param state         The entity state to encode.
417  *
418  * @returns the corresponding string
419  *****************************************************************************/
420 char * evel_entity_state(const EVEL_ENTITY_STATE state)
421 {
422   char * result;
423
424   EVEL_ENTER();
425
426   switch (state)
427   {
428     case EVEL_ENTITY_STATE_IN_SERVICE:
429       result = "inService";
430       break;
431
432     case EVEL_ENTITY_STATE_MAINTENANCE:
433       result = "maintenance";
434       break;
435
436     case EVEL_ENTITY_STATE_OUT_OF_SERVICE:
437       result = "outOfService";
438       break;
439
440     default:
441       EVEL_ERROR("Unexpected entity state %d", state);
442       assert(0);
443   }
444
445   EVEL_EXIT();
446
447   return result;
448 }
449
450 /**************************************************************************//**
451  * Convert a ::EVEL_SERVICE_ENDPOINT_DESC to string form for JSON encoding.
452  *
453  * @param endpoint_desc endpoint description to encode.
454  *
455  * @returns the corresponding string
456  *****************************************************************************/
457 char * evel_service_endpoint_desc(const EVEL_ENTITY_STATE endpoint_desc)
458 {
459   char * result;
460
461   EVEL_ENTER();
462
463   switch (endpoint_desc)
464   {
465     case EVEL_SERVICE_ENDPOINT_CALLEE:
466       result = "Callee";
467       break;
468
469     case EVEL_SERVICE_ENDPOINT_CALLER:
470       result = "Caller";
471       break;
472
473     default:
474       EVEL_ERROR("Unexpected endpoint description %d", endpoint_desc);
475       assert(0);
476   }
477
478   EVEL_EXIT();
479
480   return result;
481 }