1 /*************************************************************************//**
3 * Copyright © 2017 AT&T Intellectual Property. All rights reserved.
5 * Unless otherwise specified, all software contained herein is
6 * Licensed under the Apache License, Version 2.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
9 * http://www.apache.org/licenses/LICENSE-2.0
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
17 ****************************************************************************/
18 /**************************************************************************//**
20 * Implementation of EVEL functions relating to Signaling.
22 ****************************************************************************/
28 #include "evel_throttle.h"
30 /**************************************************************************//**
31 * Create a new Signaling event.
33 * @note The mandatory fields on the Signaling must be supplied to
34 * this factory function and are immutable once set. Optional fields
35 * have explicit setter functions, but again values may only be set
36 * once so that the event has immutable properties.
37 * @param event_name Unique Event Name confirming Domain AsdcModel Description
38 * @param event_id A universal identifier of the event for: troubleshooting correlation, analysis, etc
39 * @param vendor_name The vendor id to encode in the event vnf field.
40 * @param module The module to encode in the event.
41 * @param vnfname The Virtual network function to encode in the event.
42 * @returns pointer to the newly manufactured ::EVENT_SIGNALING. If the event
43 * is not used (i.e. posted) it must be released using
44 * ::evel_free_signaling.
45 * @retval NULL Failed to create the event.
46 *****************************************************************************/
47 EVENT_SIGNALING * evel_new_signaling(const char* ev_name, const char *ev_id,
48 const char * const vendor_name,
49 const char * const correlator,
50 const char * const local_ip_address,
51 const char * const local_port,
52 const char * const remote_ip_address,
53 const char * const remote_port)
55 EVENT_SIGNALING * event = NULL;
59 /***************************************************************************/
60 /* Check preconditions. */
61 /***************************************************************************/
62 assert(vendor_name != NULL);
64 /***************************************************************************/
65 /* Allocate the Signaling event. */
66 /***************************************************************************/
67 event = malloc(sizeof(EVENT_SIGNALING));
70 log_error_state("Out of memory");
73 memset(event, 0, sizeof(EVENT_SIGNALING));
74 EVEL_DEBUG("New Signaling event is at %lp", event);
76 /***************************************************************************/
77 /* Initialize the header & the Signaling fields. */
78 /***************************************************************************/
79 evel_init_header_nameid(&event->header,ev_name,ev_id);
80 event->header.event_domain = EVEL_DOMAIN_SIPSIGNALING;
81 event->major_version = EVEL_SIGNALING_MAJOR_VERSION;
82 event->minor_version = EVEL_SIGNALING_MINOR_VERSION;
83 evel_init_vendor_field(&event->vnfname_field, vendor_name);
84 evel_set_option_string(&event->correlator,correlator,"Init correlator");
85 evel_set_option_string(&event->local_ip_address,local_ip_address,"Init correlator");
86 evel_set_option_string(&event->local_port,local_port,"Init local port");
87 evel_set_option_string(&event->remote_ip_address,remote_ip_address,"Init remote ip");
88 evel_set_option_string(&event->remote_port,remote_port,"Init remote port");
89 evel_init_option_string(&event->compressed_sip);
90 evel_init_option_string(&event->summary_sip);
91 dlist_initialize(&event->additional_info);
99 /**************************************************************************//**
100 * Add an additional value name/value pair to the SIP signaling.
102 * The name and value are null delimited ASCII strings. The library takes
103 * a copy so the caller does not have to preserve values after the function
106 * @param event Pointer to the fault.
107 * @param name ASCIIZ string with the attribute's name. The caller
108 * does not need to preserve the value once the function
110 * @param value ASCIIZ string with the attribute's value. The caller
111 * does not need to preserve the value once the function
113 *****************************************************************************/
114 void evel_signaling_addl_info_add(EVENT_SIGNALING * event, char * name, char * value)
116 FAULT_ADDL_INFO * addl_info = NULL;
119 /***************************************************************************/
120 /* Check preconditions. */
121 /***************************************************************************/
122 assert(event != NULL);
123 assert(event->header.event_domain == EVEL_DOMAIN_SIPSIGNALING);
124 assert(name != NULL);
125 assert(value != NULL);
127 EVEL_DEBUG("Adding name=%s value=%s", name, value);
128 addl_info = malloc(sizeof(SIGNALING_ADDL_FIELD));
129 assert(addl_info != NULL);
130 memset(addl_info, 0, sizeof(SIGNALING_ADDL_FIELD));
131 addl_info->name = strdup(name);
132 addl_info->value = strdup(value);
133 assert(addl_info->name != NULL);
134 assert(addl_info->value != NULL);
136 dlist_push_last(&event->additional_info, addl_info);
142 /**************************************************************************//**
143 * Set the Event Type property of the Signaling event.
145 * @note The property is treated as immutable: it is only valid to call
146 * the setter once. However, we don't assert if the caller tries to
147 * overwrite, just ignoring the update instead.
149 * @param event Pointer to the Signaling event.
150 * @param type The Event Type to be set. ASCIIZ string. The caller
151 * does not need to preserve the value once the function
153 *****************************************************************************/
154 void evel_signaling_type_set(EVENT_SIGNALING * const event,
155 const char * const type)
159 /***************************************************************************/
160 /* Check preconditions and call evel_header_type_set. */
161 /***************************************************************************/
162 assert(event != NULL);
163 assert(event->header.event_domain == EVEL_DOMAIN_SIPSIGNALING);
164 evel_header_type_set(&event->header, type);
169 /**************************************************************************//**
170 * Set the Local Ip Address property of the Signaling event.
172 * @note The property is treated as immutable: it is only valid to call
173 * the setter once. However, we don't assert if the caller tries to
174 * overwrite, just ignoring the update instead.
176 * @param event Pointer to the Signaling event.
177 * @param local_ip_address
178 * The Local Ip Address to be set. ASCIIZ string. The
179 * caller does not need to preserve the value once the
181 *****************************************************************************/
182 void evel_signaling_local_ip_address_set(EVENT_SIGNALING * const event,
183 const char * const local_ip_address)
187 /***************************************************************************/
188 /* Check preconditions. */
189 /***************************************************************************/
190 assert(event != NULL);
191 assert(event->header.event_domain == EVEL_DOMAIN_SIPSIGNALING);
192 assert(local_ip_address != NULL);
194 evel_set_option_string(&event->local_ip_address,
201 /**************************************************************************//**
202 * Set the Local Port property of the Signaling event.
204 * @note The property is treated as immutable: it is only valid to call
205 * the setter once. However, we don't assert if the caller tries to
206 * overwrite, just ignoring the update instead.
208 * @param event Pointer to the Signaling event.
209 * @param local_port The Local Port to be set. ASCIIZ string. The caller
210 * does not need to preserve the value once the function
212 *****************************************************************************/
213 void evel_signaling_local_port_set(EVENT_SIGNALING * const event,
214 const char * const local_port)
218 /***************************************************************************/
219 /* Check preconditions. */
220 /***************************************************************************/
221 assert(event != NULL);
222 assert(event->header.event_domain == EVEL_DOMAIN_SIPSIGNALING);
223 assert(local_port != NULL);
225 evel_set_option_string(&event->local_port,
232 /**************************************************************************//**
233 * Set the Remote Ip Address property of the Signaling event.
235 * @note The property is treated as immutable: it is only valid to call
236 * the setter once. However, we don't assert if the caller tries to
237 * overwrite, just ignoring the update instead.
239 * @param event Pointer to the Signaling event.
240 * @param remote_ip_address
241 * The Remote Ip Address to be set. ASCIIZ string. The
242 * caller does not need to preserve the value once the
244 *****************************************************************************/
245 void evel_signaling_remote_ip_address_set(EVENT_SIGNALING * const event,
246 const char * const remote_ip_address)
250 /***************************************************************************/
251 /* Check preconditions. */
252 /***************************************************************************/
253 assert(event != NULL);
254 assert(event->header.event_domain == EVEL_DOMAIN_SIPSIGNALING);
255 assert(remote_ip_address != NULL);
257 evel_set_option_string(&event->remote_ip_address,
259 "Remote Ip Address");
264 /**************************************************************************//**
265 * Set the Remote Port property of the Signaling event.
267 * @note The property is treated as immutable: it is only valid to call
268 * the setter once. However, we don't assert if the caller tries to
269 * overwrite, just ignoring the update instead.
271 * @param event Pointer to the Signaling event.
272 * @param remote_port The Remote Port to be set. ASCIIZ string. The caller
273 * does not need to preserve the value once the function
275 *****************************************************************************/
276 void evel_signaling_remote_port_set(EVENT_SIGNALING * const event,
277 const char * const remote_port)
281 /***************************************************************************/
282 /* Check preconditions. */
283 /***************************************************************************/
284 assert(event != NULL);
285 assert(event->header.event_domain == EVEL_DOMAIN_SIPSIGNALING);
286 assert(remote_port != NULL);
288 evel_set_option_string(&event->remote_port,
295 /**************************************************************************//**
296 * Set the Vendor module property of the Signaling event.
298 * @note The property is treated as immutable: it is only valid to call
299 * the setter once. However, we don't assert if the caller tries to
300 * overwrite, just ignoring the update instead.
302 * @param event Pointer to the Signaling event.
303 * @param modulename The module name to be set. ASCIIZ string. The caller
304 * does not need to preserve the value once the function
306 *****************************************************************************/
307 void evel_signaling_vnfmodule_name_set(EVENT_SIGNALING * const event,
308 const char * const module_name)
312 /***************************************************************************/
313 /* Check preconditions. */
314 /***************************************************************************/
315 assert(event != NULL);
316 assert(event->header.event_domain == EVEL_DOMAIN_SIPSIGNALING);
317 assert(module_name != NULL);
319 evel_vendor_field_module_set(&event->vnfname_field, module_name);
324 /**************************************************************************//**
325 * Set the Vendor module property of the Signaling event.
327 * @note The property is treated as immutable: it is only valid to call
328 * the setter once. However, we don't assert if the caller tries to
329 * overwrite, just ignoring the update instead.
331 * @param event Pointer to the Signaling event.
332 * @param vnfname The Virtual Network function to be set. ASCIIZ string.
333 * The caller does not need to preserve the value once
334 * the function returns.
335 *****************************************************************************/
336 void evel_signaling_vnfname_set(EVENT_SIGNALING * const event,
337 const char * const vnfname)
341 /***************************************************************************/
342 /* Check preconditions. */
343 /***************************************************************************/
344 assert(event != NULL);
345 assert(event->header.event_domain == EVEL_DOMAIN_SIPSIGNALING);
346 assert(vnfname != NULL);
348 evel_vendor_field_vnfname_set(&event->vnfname_field, vnfname);
353 /**************************************************************************//**
354 * Set the Compressed SIP property of the Signaling event.
356 * @note The property is treated as immutable: it is only valid to call
357 * the setter once. However, we don't assert if the caller tries to
358 * overwrite, just ignoring the update instead.
360 * @param event Pointer to the Signaling event.
361 * @param compressed_sip
362 * The Compressed SIP to be set. ASCIIZ string. The caller
363 * does not need to preserve the value once the function
365 *****************************************************************************/
366 void evel_signaling_compressed_sip_set(EVENT_SIGNALING * const event,
367 const char * const compressed_sip)
371 /***************************************************************************/
372 /* Check preconditions. */
373 /***************************************************************************/
374 assert(event != NULL);
375 assert(event->header.event_domain == EVEL_DOMAIN_SIPSIGNALING);
376 assert(compressed_sip != NULL);
378 evel_set_option_string(&event->compressed_sip,
385 /**************************************************************************//**
386 * Set the Summary SIP property of the Signaling event.
388 * @note The property is treated as immutable: it is only valid to call
389 * the setter once. However, we don't assert if the caller tries to
390 * overwrite, just ignoring the update instead.
392 * @param event Pointer to the Signaling event.
393 * @param summary_sip The Summary SIP to be set. ASCIIZ string. The caller
394 * does not need to preserve the value once the function
396 *****************************************************************************/
397 void evel_signaling_summary_sip_set(EVENT_SIGNALING * const event,
398 const char * const summary_sip)
402 /***************************************************************************/
403 /* Check preconditions. */
404 /***************************************************************************/
405 assert(event != NULL);
406 assert(event->header.event_domain == EVEL_DOMAIN_SIPSIGNALING);
407 assert(summary_sip != NULL);
409 evel_set_option_string(&event->summary_sip,
416 /**************************************************************************//**
417 * Set the Correlator property of the Signaling event.
419 * @note The property is treated as immutable: it is only valid to call
420 * the setter once. However, we don't assert if the caller tries to
421 * overwrite, just ignoring the update instead.
423 * @param event Pointer to the Signaling event.
424 * @param correlator The correlator to be set. ASCIIZ string. The caller
425 * does not need to preserve the value once the function
427 *****************************************************************************/
428 void evel_signaling_correlator_set(EVENT_SIGNALING * const event,
429 const char * const correlator)
433 /***************************************************************************/
434 /* Check preconditions and call evel_header_type_set. */
435 /***************************************************************************/
436 assert(event != NULL);
437 assert(event->header.event_domain == EVEL_DOMAIN_SIPSIGNALING);
438 evel_set_option_string(&event->correlator,
445 /**************************************************************************//**
446 * Encode the Signaling in JSON according to AT&T's schema for the
449 * @param jbuf Pointer to the ::EVEL_JSON_BUFFER to encode into.
450 * @param event Pointer to the ::EVENT_HEADER to encode.
451 *****************************************************************************/
452 void evel_json_encode_signaling(EVEL_JSON_BUFFER * const jbuf,
453 EVENT_SIGNALING * const event)
455 SIGNALING_ADDL_FIELD * addl_info = NULL;
456 DLIST_ITEM * addl_info_item = NULL;
460 /***************************************************************************/
461 /* Check preconditions. */
462 /***************************************************************************/
463 assert(event != NULL);
464 assert(event->header.event_domain == EVEL_DOMAIN_SIPSIGNALING);
466 evel_json_encode_header(jbuf, &event->header);
467 evel_json_open_named_object(jbuf, "signalingFields");
469 /***************************************************************************/
470 /* Mandatory fields */
471 /***************************************************************************/
473 /***************************************************************************/
474 /* Optional fields */
475 /***************************************************************************/
476 evel_enc_kv_opt_string(jbuf, "compressedSip", &event->compressed_sip);
477 evel_enc_kv_opt_string(jbuf, "correlator", &event->correlator);
478 evel_enc_kv_opt_string(jbuf, "localIpAddress", &event->local_ip_address);
479 evel_enc_kv_opt_string(jbuf, "localPort", &event->local_port);
480 evel_enc_kv_opt_string(jbuf, "remoteIpAddress", &event->remote_ip_address);
481 evel_enc_kv_opt_string(jbuf, "remotePort", &event->remote_port);
482 evel_enc_version(jbuf, "signalingFieldsVersion", event->major_version,event->minor_version);
483 evel_enc_kv_opt_string(jbuf, "summarySip", &event->summary_sip);
484 evel_json_encode_vendor_field(jbuf, &event->vnfname_field);
487 /***************************************************************************/
488 /* Checkpoint, so that we can wind back if all fields are suppressed. */
489 /***************************************************************************/
490 evel_json_checkpoint(jbuf);
491 if (evel_json_open_opt_named_list(jbuf, "additionalInformation"))
493 bool item_added = false;
495 addl_info_item = dlist_get_first(&event->additional_info);
496 while (addl_info_item != NULL)
498 addl_info = (SIGNALING_ADDL_FIELD*) addl_info_item->item;
499 assert(addl_info != NULL);
501 if (!evel_throttle_suppress_nv_pair(jbuf->throttle_spec,
502 "additionalInformation",
505 evel_json_open_object(jbuf);
506 evel_enc_kv_string(jbuf, "name", addl_info->name);
507 evel_enc_kv_string(jbuf, "value", addl_info->value);
508 evel_json_close_object(jbuf);
511 addl_info_item = dlist_get_next(addl_info_item);
513 evel_json_close_list(jbuf);
515 /*************************************************************************/
516 /* If we've not written anything, rewind to before we opened the list. */
517 /*************************************************************************/
520 evel_json_rewind(jbuf);
524 evel_json_close_object(jbuf);
529 /**************************************************************************//**
530 * Free a Signaling event.
532 * Free off the event supplied. Will free all the contained allocated memory.
534 * @note It does not free the event itself, since that may be part of a larger
536 *****************************************************************************/
537 void evel_free_signaling(EVENT_SIGNALING * const event)
539 SIGNALING_ADDL_FIELD * addl_info = NULL;
542 /***************************************************************************/
543 /* Check preconditions. As an internal API we don't allow freeing NULL */
544 /* events as we do on the public API. */
545 /***************************************************************************/
546 assert(event != NULL);
547 assert(event->header.event_domain == EVEL_DOMAIN_SIPSIGNALING);
549 /***************************************************************************/
550 /* Free all internal strings then the header itself. */
551 /***************************************************************************/
552 addl_info = dlist_pop_last(&event->additional_info);
553 while (addl_info != NULL)
555 EVEL_DEBUG("Freeing Additional Info (%s, %s)",
558 free(addl_info->name);
559 free(addl_info->value);
561 addl_info = dlist_pop_last(&event->additional_info);
564 evel_free_event_vendor_field(&event->vnfname_field);
565 evel_free_option_string(&event->correlator);
566 evel_free_option_string(&event->local_ip_address);
567 evel_free_option_string(&event->local_port);
568 evel_free_option_string(&event->remote_ip_address);
569 evel_free_option_string(&event->remote_port);
570 evel_free_option_string(&event->compressed_sip);
571 evel_free_option_string(&event->summary_sip);
572 evel_free_header(&event->header);