1f410cb1a3d735e72c79dc090aaed4c5830d2b7e
[demo.git] / vnfs / VES / 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_SERVICE:
228       result = "serviceEvents";
229       break;
230
231     case EVEL_DOMAIN_SIGNALING:
232       result = "signaling";
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     default:
248       result = NULL;
249       EVEL_ERROR("Unexpected domain %d", domain);
250       assert(0);
251   }
252
253   EVEL_EXIT();
254
255   return result;
256 }
257
258 /**************************************************************************//**
259  * Map an ::EVEL_EVENT_PRIORITIES enum value to the equivalent string.
260  *
261  * @param priority      The priority to convert.
262  * @returns The equivalent string.
263  *****************************************************************************/
264 char * evel_event_priority(const EVEL_EVENT_PRIORITIES priority)
265 {
266   char * result;
267
268   EVEL_ENTER();
269
270   switch (priority)
271   {
272     case EVEL_PRIORITY_HIGH:
273       result = "High";
274       break;
275
276     case EVEL_PRIORITY_MEDIUM:
277       result = "Medium";
278       break;
279
280     case EVEL_PRIORITY_NORMAL:
281       result = "Normal";
282       break;
283
284     case EVEL_PRIORITY_LOW:
285       result = "Low";
286       break;
287
288     default:
289       result = NULL;
290       EVEL_ERROR("Unexpected priority %d", priority);
291       assert(0);
292   }
293
294   EVEL_EXIT();
295
296   return result;
297 }
298
299 /**************************************************************************//**
300  * Map an ::EVEL_SOURCE_TYPES enum value to the equivalent string.
301  *
302  * @param source_type   The source type to convert.
303  * @returns The equivalent string.
304  *****************************************************************************/
305 char * evel_source_type(const EVEL_SOURCE_TYPES source_type)
306 {
307   char * result;
308
309   EVEL_ENTER();
310
311   switch (source_type)
312   {
313     case EVEL_SOURCE_OTHER:
314       result = "other";
315       break;
316
317     case EVEL_SOURCE_ROUTER:
318       result = "router";
319       break;
320
321     case EVEL_SOURCE_SWITCH:
322       result = "switch";
323       break;
324
325     case EVEL_SOURCE_HOST:
326       result = "host";
327       break;
328
329     case EVEL_SOURCE_CARD:
330       result = "card";
331       break;
332
333     case EVEL_SOURCE_PORT:
334       result = "port";
335       break;
336
337     case EVEL_SOURCE_SLOT_THRESHOLD:
338       result = "slotThreshold";
339       break;
340
341     case EVEL_SOURCE_PORT_THRESHOLD:
342       result = "portThreshold";
343       break;
344
345     case EVEL_SOURCE_VIRTUAL_MACHINE:
346       result = "virtualMachine";
347       break;
348
349     case EVEL_SOURCE_VIRTUAL_NETWORK_FUNCTION:
350       result = "virtualNetworkFunction";
351       break;
352
353     default:
354       result = NULL;
355       EVEL_ERROR("Unexpected Event Source Type %d", (int) source_type);
356       assert(0);
357   }
358
359   EVEL_EXIT();
360
361   return result;
362 }
363
364 /**************************************************************************//**
365  * Map an ::EVEL_VF_STATUSES enum value to the equivalent string.
366  *
367  * @param vf_status     The vf_status to convert.
368  * @returns The equivalent string.
369  *****************************************************************************/
370 char * evel_vf_status(const EVEL_VF_STATUSES vf_status)
371 {
372   char * result;
373
374   EVEL_ENTER();
375
376   switch (vf_status)
377   {
378     case EVEL_VF_STATUS_ACTIVE:
379       result = "Active";
380       break;
381
382     case EVEL_VF_STATUS_IDLE:
383       result = "Idle";
384       break;
385
386     case EVEL_VF_STATUS_PREP_TERMINATE:
387       result = "Preparing to terminate";
388       break;
389
390     case EVEL_VF_STATUS_READY_TERMINATE:
391       result = "Ready to terminate";
392       break;
393
394     case EVEL_VF_STATUS_REQ_TERMINATE:
395       result = "Requesting termination";
396       break;
397
398     default:
399       result = NULL;
400       EVEL_ERROR("Unexpected VF Status %d", vf_status);
401       assert(0);
402   }
403
404   EVEL_EXIT();
405
406   return result;
407 }
408
409 /**************************************************************************//**
410  * Convert a ::EVEL_ENTITY_STATE to it's string form for JSON encoding.
411  *
412  * @param state         The entity state to encode.
413  *
414  * @returns the corresponding string
415  *****************************************************************************/
416 char * evel_entity_state(const EVEL_ENTITY_STATE state)
417 {
418   char * result;
419
420   EVEL_ENTER();
421
422   switch (state)
423   {
424     case EVEL_ENTITY_STATE_IN_SERVICE:
425       result = "inService";
426       break;
427
428     case EVEL_ENTITY_STATE_MAINTENANCE:
429       result = "maintenance";
430       break;
431
432     case EVEL_ENTITY_STATE_OUT_OF_SERVICE:
433       result = "outOfService";
434       break;
435
436     default:
437       EVEL_ERROR("Unexpected entity state %d", state);
438       assert(0);
439   }
440
441   EVEL_EXIT();
442
443   return result;
444 }
445
446 /**************************************************************************//**
447  * Convert a ::EVEL_SERVICE_ENDPOINT_DESC to string form for JSON encoding.
448  *
449  * @param endpoint_desc endpoint description to encode.
450  *
451  * @returns the corresponding string
452  *****************************************************************************/
453 char * evel_service_endpoint_desc(const EVEL_ENTITY_STATE endpoint_desc)
454 {
455   char * result;
456
457   EVEL_ENTER();
458
459   switch (endpoint_desc)
460   {
461     case EVEL_SERVICE_ENDPOINT_CALLEE:
462       result = "Callee";
463       break;
464
465     case EVEL_SERVICE_ENDPOINT_CALLER:
466       result = "Caller";
467       break;
468
469     default:
470       EVEL_ERROR("Unexpected endpoint description %d", endpoint_desc);
471       assert(0);
472   }
473
474   EVEL_EXIT();
475
476   return result;
477 }