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