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