Initial OpenECOMP Demo commit
[demo.git] / vnfs / VES / code / evel_library / evel_signaling.c
1 /**************************************************************************//**
2  * @file
3  * Implementation of EVEL functions relating to Signaling.
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_throttle.h"
40
41 /**************************************************************************//**
42  * Create a new Signaling event.
43  *
44  * @note    The mandatory fields on the Signaling must be supplied to
45  *          this factory function and are immutable once set.  Optional fields
46  *          have explicit setter functions, but again values may only be set
47  *          once so that the event has immutable properties.
48  * @param vendor_id     The vendor id to encode in the event instance id.
49  * @param event_id      The vendor event id to encode in the event instance id.
50  * @returns pointer to the newly manufactured ::EVENT_SIGNALING.  If the event
51  *          is not used (i.e. posted) it must be released using
52  *          ::evel_free_signaling.
53  * @retval  NULL  Failed to create the event.
54  *****************************************************************************/
55 EVENT_SIGNALING * evel_new_signaling(const char * const vendor_id,
56                                      const char * const event_id)
57 {
58   EVENT_SIGNALING * event = NULL;
59
60   EVEL_ENTER();
61
62   /***************************************************************************/
63   /* Check preconditions.                                                    */
64   /***************************************************************************/
65   assert(vendor_id != NULL);
66   assert(event_id != NULL);
67
68   /***************************************************************************/
69   /* Allocate the Signaling event.                                           */
70   /***************************************************************************/
71   event = malloc(sizeof(EVENT_SIGNALING));
72   if (event == NULL)
73   {
74     log_error_state("Out of memory");
75     goto exit_label;
76   }
77   memset(event, 0, sizeof(EVENT_SIGNALING));
78   EVEL_DEBUG("New Signaling event is at %lp", event);
79
80   /***************************************************************************/
81   /* Initialize the header & the Signaling fields.                           */
82   /***************************************************************************/
83   evel_init_header(&event->header);
84   event->header.event_domain = EVEL_DOMAIN_SIGNALING;
85   event->major_version = EVEL_SIGNALING_MAJOR_VERSION;
86   event->minor_version = EVEL_SIGNALING_MINOR_VERSION;
87   evel_init_event_instance_id(&event->instance_id, vendor_id, event_id);
88   evel_init_option_string(&event->correlator);
89   evel_init_option_string(&event->local_ip_address);
90   evel_init_option_string(&event->local_port);
91   evel_init_option_string(&event->remote_ip_address);
92   evel_init_option_string(&event->remote_port);
93   evel_init_option_string(&event->compressed_sip);
94   evel_init_option_string(&event->summary_sip);
95
96 exit_label:
97
98   EVEL_EXIT();
99   return event;
100 }
101
102 /**************************************************************************//**
103  * Set the Event Type property of the Signaling event.
104  *
105  * @note  The property is treated as immutable: it is only valid to call
106  *        the setter once.  However, we don't assert if the caller tries to
107  *        overwrite, just ignoring the update instead.
108  *
109  * @param event         Pointer to the Signaling event.
110  * @param type          The Event Type to be set. ASCIIZ string. The caller
111  *                      does not need to preserve the value once the function
112  *                      returns.
113  *****************************************************************************/
114 void evel_signaling_type_set(EVENT_SIGNALING * const event,
115                              const char * const type)
116 {
117   EVEL_ENTER();
118
119   /***************************************************************************/
120   /* Check preconditions and call evel_header_type_set.                      */
121   /***************************************************************************/
122   assert(event != NULL);
123   assert(event->header.event_domain == EVEL_DOMAIN_SIGNALING);
124   evel_header_type_set(&event->header, type);
125
126   EVEL_EXIT();
127 }
128
129 /**************************************************************************//**
130  * Set the Local Ip Address property of the Signaling event.
131  *
132  * @note  The property is treated as immutable: it is only valid to call
133  *        the setter once.  However, we don't assert if the caller tries to
134  *        overwrite, just ignoring the update instead.
135  *
136  * @param event         Pointer to the Signaling event.
137  * @param local_ip_address
138  *                      The Local Ip Address to be set. ASCIIZ string. The
139  *                      caller does not need to preserve the value once the
140  *                      function returns.
141  *****************************************************************************/
142 void evel_signaling_local_ip_address_set(EVENT_SIGNALING * const event,
143                                          const char * const local_ip_address)
144 {
145   EVEL_ENTER();
146
147   /***************************************************************************/
148   /* Check preconditions.                                                    */
149   /***************************************************************************/
150   assert(event != NULL);
151   assert(event->header.event_domain == EVEL_DOMAIN_SIGNALING);
152   assert(local_ip_address != NULL);
153
154   evel_set_option_string(&event->local_ip_address,
155                          local_ip_address,
156                          "Local Ip Address");
157
158   EVEL_EXIT();
159 }
160
161 /**************************************************************************//**
162  * Set the Local Port property of the Signaling event.
163  *
164  * @note  The property is treated as immutable: it is only valid to call
165  *        the setter once.  However, we don't assert if the caller tries to
166  *        overwrite, just ignoring the update instead.
167  *
168  * @param event         Pointer to the Signaling event.
169  * @param local_port    The Local Port to be set. ASCIIZ string. The caller
170  *                      does not need to preserve the value once the function
171  *                      returns.
172  *****************************************************************************/
173 void evel_signaling_local_port_set(EVENT_SIGNALING * const event,
174                                    const char * const local_port)
175 {
176   EVEL_ENTER();
177
178   /***************************************************************************/
179   /* Check preconditions.                                                    */
180   /***************************************************************************/
181   assert(event != NULL);
182   assert(event->header.event_domain == EVEL_DOMAIN_SIGNALING);
183   assert(local_port != NULL);
184
185   evel_set_option_string(&event->local_port,
186                          local_port,
187                          "Local Port");
188
189   EVEL_EXIT();
190 }
191
192 /**************************************************************************//**
193  * Set the Remote Ip Address property of the Signaling event.
194  *
195  * @note  The property is treated as immutable: it is only valid to call
196  *        the setter once.  However, we don't assert if the caller tries to
197  *        overwrite, just ignoring the update instead.
198  *
199  * @param event         Pointer to the Signaling event.
200  * @param remote_ip_address
201  *                      The Remote Ip Address to be set. ASCIIZ string. The
202  *                      caller does not need to preserve the value once the
203  *                      function returns.
204  *****************************************************************************/
205 void evel_signaling_remote_ip_address_set(EVENT_SIGNALING * const event,
206                                           const char * const remote_ip_address)
207 {
208   EVEL_ENTER();
209
210   /***************************************************************************/
211   /* Check preconditions.                                                    */
212   /***************************************************************************/
213   assert(event != NULL);
214   assert(event->header.event_domain == EVEL_DOMAIN_SIGNALING);
215   assert(remote_ip_address != NULL);
216
217   evel_set_option_string(&event->remote_ip_address,
218                          remote_ip_address,
219                          "Remote Ip Address");
220
221   EVEL_EXIT();
222 }
223
224 /**************************************************************************//**
225  * Set the Remote Port property of the Signaling event.
226  *
227  * @note  The property is treated as immutable: it is only valid to call
228  *        the setter once.  However, we don't assert if the caller tries to
229  *        overwrite, just ignoring the update instead.
230  *
231  * @param event         Pointer to the Signaling event.
232  * @param remote_port   The Remote Port to be set. ASCIIZ string. The caller
233  *                      does not need to preserve the value once the function
234  *                      returns.
235  *****************************************************************************/
236 void evel_signaling_remote_port_set(EVENT_SIGNALING * const event,
237                                     const char * const remote_port)
238 {
239   EVEL_ENTER();
240
241   /***************************************************************************/
242   /* Check preconditions.                                                    */
243   /***************************************************************************/
244   assert(event != NULL);
245   assert(event->header.event_domain == EVEL_DOMAIN_SIGNALING);
246   assert(remote_port != NULL);
247
248   evel_set_option_string(&event->remote_port,
249                          remote_port,
250                          "Remote Port");
251
252   EVEL_EXIT();
253 }
254
255 /**************************************************************************//**
256  * Set the Compressed SIP property of the Signaling event.
257  *
258  * @note  The property is treated as immutable: it is only valid to call
259  *        the setter once.  However, we don't assert if the caller tries to
260  *        overwrite, just ignoring the update instead.
261  *
262  * @param event         Pointer to the Signaling event.
263  * @param compressed_sip
264  *                      The Compressed SIP to be set. ASCIIZ string. The caller
265  *                      does not need to preserve the value once the function
266  *                      returns.
267  *****************************************************************************/
268 void evel_signaling_compressed_sip_set(EVENT_SIGNALING * const event,
269                                        const char * const compressed_sip)
270 {
271   EVEL_ENTER();
272
273   /***************************************************************************/
274   /* Check preconditions.                                                    */
275   /***************************************************************************/
276   assert(event != NULL);
277   assert(event->header.event_domain == EVEL_DOMAIN_SIGNALING);
278   assert(compressed_sip != NULL);
279
280   evel_set_option_string(&event->compressed_sip,
281                          compressed_sip,
282                          "Compressed SIP");
283
284   EVEL_EXIT();
285 }
286
287 /**************************************************************************//**
288  * Set the Summary SIP property of the Signaling event.
289  *
290  * @note  The property is treated as immutable: it is only valid to call
291  *        the setter once.  However, we don't assert if the caller tries to
292  *        overwrite, just ignoring the update instead.
293  *
294  * @param event         Pointer to the Signaling event.
295  * @param summary_sip   The Summary SIP to be set. ASCIIZ string. The caller
296  *                      does not need to preserve the value once the function
297  *                      returns.
298  *****************************************************************************/
299 void evel_signaling_summary_sip_set(EVENT_SIGNALING * const event,
300                                     const char * const summary_sip)
301 {
302   EVEL_ENTER();
303
304   /***************************************************************************/
305   /* Check preconditions.                                                    */
306   /***************************************************************************/
307   assert(event != NULL);
308   assert(event->header.event_domain == EVEL_DOMAIN_SIGNALING);
309   assert(summary_sip != NULL);
310
311   evel_set_option_string(&event->summary_sip,
312                          summary_sip,
313                          "Summary SIP");
314
315   EVEL_EXIT();
316 }
317
318 /**************************************************************************//**
319  * Set the Product Id property of the Signaling event.
320  *
321  * @note  The property is treated as immutable: it is only valid to call
322  *        the setter once.  However, we don't assert if the caller tries to
323  *        overwrite, just ignoring the update instead.
324  *
325  * @param event         Pointer to the Signaling event.
326  * @param product_id    The vendor product id to be set. ASCIIZ string. The
327  *                      caller does not need to preserve the value once the
328  *                      function returns.
329  *****************************************************************************/
330 void evel_signaling_product_id_set(EVENT_SIGNALING * const event,
331                                    const char * const product_id)
332 {
333   EVEL_ENTER();
334
335   /***************************************************************************/
336   /* Check preconditions and call evel_header_type_set.                      */
337   /***************************************************************************/
338   assert(event != NULL);
339   assert(event->header.event_domain == EVEL_DOMAIN_SIGNALING);
340   evel_set_option_string(&event->instance_id.product_id,
341                          product_id,
342                          "Product Id");
343
344   EVEL_EXIT();
345 }
346
347 /**************************************************************************//**
348  * Set the Subsystem Id property of the Signaling event.
349  *
350  * @note  The property is treated as immutable: it is only valid to call
351  *        the setter once.  However, we don't assert if the caller tries to
352  *        overwrite, just ignoring the update instead.
353  *
354  * @param event         Pointer to the Signaling event.
355  * @param subsystem_id  The vendor subsystem id to be set. ASCIIZ string. The
356  *                      caller does not need to preserve the value once the
357  *                      function returns.
358  *****************************************************************************/
359 void evel_signaling_subsystem_id_set(EVENT_SIGNALING * const event,
360                                      const char * const subsystem_id)
361 {
362   EVEL_ENTER();
363
364   /***************************************************************************/
365   /* Check preconditions and call evel_header_type_set.                      */
366   /***************************************************************************/
367   assert(event != NULL);
368   assert(event->header.event_domain == EVEL_DOMAIN_SIGNALING);
369   evel_set_option_string(&event->instance_id.subsystem_id,
370                          subsystem_id,
371                          "Subsystem Id");
372
373   EVEL_EXIT();
374 }
375
376 /**************************************************************************//**
377  * Set the Friendly Name property of the Signaling event.
378  *
379  * @note  The property is treated as immutable: it is only valid to call
380  *        the setter once.  However, we don't assert if the caller tries to
381  *        overwrite, just ignoring the update instead.
382  *
383  * @param event         Pointer to the Signaling event.
384  * @param friendly_name The vendor friendly name to be set. ASCIIZ string. The
385  *                      caller does not need to preserve the value once the
386  *                      function returns.
387  *****************************************************************************/
388 void evel_signaling_friendly_name_set(EVENT_SIGNALING * const event,
389                                       const char * const friendly_name)
390 {
391   EVEL_ENTER();
392
393   /***************************************************************************/
394   /* Check preconditions and call evel_header_type_set.                      */
395   /***************************************************************************/
396   assert(event != NULL);
397   assert(event->header.event_domain == EVEL_DOMAIN_SIGNALING);
398   evel_set_option_string(&event->instance_id.event_friendly_name,
399                          friendly_name,
400                          "Friendly Name");
401
402   EVEL_EXIT();
403 }
404
405 /**************************************************************************//**
406  * Set the Correlator property of the Signaling event.
407  *
408  * @note  The property is treated as immutable: it is only valid to call
409  *        the setter once.  However, we don't assert if the caller tries to
410  *        overwrite, just ignoring the update instead.
411  *
412  * @param event         Pointer to the Signaling event.
413  * @param correlator    The correlator to be set. ASCIIZ string. The caller
414  *                      does not need to preserve the value once the function
415  *                      returns.
416  *****************************************************************************/
417 void evel_signaling_correlator_set(EVENT_SIGNALING * const event,
418                                    const char * const correlator)
419 {
420   EVEL_ENTER();
421
422   /***************************************************************************/
423   /* Check preconditions and call evel_header_type_set.                      */
424   /***************************************************************************/
425   assert(event != NULL);
426   assert(event->header.event_domain == EVEL_DOMAIN_SIGNALING);
427   evel_set_option_string(&event->correlator,
428                          correlator,
429                          "Correlator");
430
431   EVEL_EXIT();
432 }
433
434 /**************************************************************************//**
435  * Encode the Signaling in JSON according to AT&T's schema for the
436  * event type.
437  *
438  * @param jbuf          Pointer to the ::EVEL_JSON_BUFFER to encode into.
439  * @param event         Pointer to the ::EVENT_HEADER to encode.
440  *****************************************************************************/
441 void evel_json_encode_signaling(EVEL_JSON_BUFFER * const jbuf,
442                                 EVENT_SIGNALING * const event)
443 {
444   EVEL_ENTER();
445
446   /***************************************************************************/
447   /* Check preconditions.                                                    */
448   /***************************************************************************/
449   assert(event != NULL);
450   assert(event->header.event_domain == EVEL_DOMAIN_SIGNALING);
451
452   evel_json_encode_header(jbuf, &event->header);
453   evel_json_open_named_object(jbuf, "signalingFields");
454
455   /***************************************************************************/
456   /* Mandatory fields                                                        */
457   /***************************************************************************/
458   evel_json_encode_instance_id(jbuf, &event->instance_id);
459   evel_enc_version(jbuf,
460                    "signalingFieldsVersion",
461                    event->major_version,
462                    event->minor_version);
463
464   /***************************************************************************/
465   /* Optional fields                                                         */
466   /***************************************************************************/
467   evel_enc_kv_opt_string(jbuf, "correlator", &event->correlator);
468   evel_enc_kv_opt_string(jbuf, "localIpAddress", &event->local_ip_address);
469   evel_enc_kv_opt_string(jbuf, "localPort", &event->local_port);
470   evel_enc_kv_opt_string(jbuf, "remoteIpAddress", &event->remote_ip_address);
471   evel_enc_kv_opt_string(jbuf, "remotePort", &event->remote_port);
472   evel_enc_kv_opt_string(jbuf, "compressedSip", &event->compressed_sip);
473   evel_enc_kv_opt_string(jbuf, "summarySip", &event->summary_sip);
474   evel_json_close_object(jbuf);
475
476   EVEL_EXIT();
477 }
478
479 /**************************************************************************//**
480  * Free a Signaling event.
481  *
482  * Free off the event supplied.  Will free all the contained allocated memory.
483  *
484  * @note It does not free the event itself, since that may be part of a larger
485  * structure.
486  *****************************************************************************/
487 void evel_free_signaling(EVENT_SIGNALING * const event)
488 {
489   EVEL_ENTER();
490
491   /***************************************************************************/
492   /* Check preconditions.  As an internal API we don't allow freeing NULL    */
493   /* events as we do on the public API.                                      */
494   /***************************************************************************/
495   assert(event != NULL);
496   assert(event->header.event_domain == EVEL_DOMAIN_SIGNALING);
497
498   evel_free_header(&event->header);
499   evel_free_event_instance_id(&event->instance_id);
500   evel_free_option_string(&event->correlator);
501   evel_free_option_string(&event->local_ip_address);
502   evel_free_option_string(&event->local_port);
503   evel_free_option_string(&event->remote_ip_address);
504   evel_free_option_string(&event->remote_port);
505   evel_free_option_string(&event->compressed_sip);
506   evel_free_option_string(&event->summary_sip);
507
508   EVEL_EXIT();
509 }