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.
16 * ECOMP is a trademark and service mark of AT&T Intellectual Property.
17 ****************************************************************************/
19 /**************************************************************************//**
21 * Implementation of EVEL functions relating to Event Headers - since
22 * Heartbeats only contain the Event Header, the Heartbeat factory function is
24 *****************************************************************************/
32 #include "evel_internal.h"
33 #include "evel_throttle.h"
36 /**************************************************************************//**
37 * Unique sequence number for events from this VNF.
38 *****************************************************************************/
39 static int event_sequence = 1;
41 /**************************************************************************//**
42 * Set the next event_sequence to use.
44 * @param sequence The next sequence number to use.
45 *****************************************************************************/
46 void evel_set_global_event_sequence(const int sequence)
50 EVEL_INFO("Setting event sequence to %d, was %d ", sequence, event_sequence);
51 event_sequence = sequence;
57 /**************************************************************************//**
58 * Create a new heartbeat event of given name and type.
60 * @note that the heartbeat is just a "naked" commonEventHeader!
62 * @param event_name Unique Event Name: in format
63 * {DomainAbbreviation}_{AsdcModel or ApplicationPlatform}_{DescriptionOfInfoBeingConveyed}
64 * @param event_id Uniquely identify event for correlation and analysis
66 * @returns pointer to the newly manufactured ::EVENT_HEADER. If the event is
67 * not used it must be released using ::evel_free_event
68 * @retval NULL Failed to create the event.
69 *****************************************************************************/
70 EVENT_HEADER * evel_new_heartbeat_nameid(const char* ev_name, const char *ev_id)
72 EVENT_HEADER * heartbeat = NULL;
75 assert(ev_name != NULL);
76 assert(ev_id != NULL);
78 /***************************************************************************/
79 /* Allocate the header. */
80 /***************************************************************************/
81 heartbeat = malloc(sizeof(EVENT_HEADER));
82 if (heartbeat == NULL)
84 log_error_state("Out of memory");
87 memset(heartbeat, 0, sizeof(EVENT_HEADER));
89 /***************************************************************************/
90 /* Initialize the header. Get a new event sequence number. Note that if */
91 /* any memory allocation fails in here we will fail gracefully because */
92 /* everything downstream can cope with NULLs. */
93 /***************************************************************************/
94 evel_init_header_nameid(heartbeat,ev_name,ev_id);
101 /**************************************************************************//**
102 * Create a new heartbeat event.
104 * @note that the heartbeat is just a "naked" commonEventHeader!
106 * @returns pointer to the newly manufactured ::EVENT_HEADER. If the event is
107 * not used it must be released using ::evel_free_event
108 * @retval NULL Failed to create the event.
109 *****************************************************************************/
110 EVENT_HEADER * evel_new_heartbeat()
112 EVENT_HEADER * heartbeat = NULL;
115 /***************************************************************************/
116 /* Allocate the header. */
117 /***************************************************************************/
118 heartbeat = malloc(sizeof(EVENT_HEADER));
119 if (heartbeat == NULL)
121 log_error_state("Out of memory");
124 memset(heartbeat, 0, sizeof(EVENT_HEADER));
126 /***************************************************************************/
127 /* Initialize the header. Get a new event sequence number. Note that if */
128 /* any memory allocation fails in here we will fail gracefully because */
129 /* everything downstream can cope with NULLs. */
130 /***************************************************************************/
131 evel_init_header(heartbeat,"Heartbeat");
132 evel_force_option_string(&heartbeat->event_type, "Autonomous heartbeat");
139 /**************************************************************************//**
140 * Initialize a newly created event header.
142 * @param header Pointer to the header being initialized.
143 *****************************************************************************/
144 void evel_init_header(EVENT_HEADER * const header,const char *const eventname)
146 char scratchpad[EVEL_MAX_STRING_LEN + 1] = {0};
151 assert(header != NULL);
153 gettimeofday(&tv, NULL);
155 /***************************************************************************/
156 /* Initialize the header. Get a new event sequence number. Note that if */
157 /* any memory allocation fails in here we will fail gracefully because */
158 /* everything downstream can cope with NULLs. */
159 /***************************************************************************/
160 header->event_domain = EVEL_DOMAIN_HEARTBEAT;
161 snprintf(scratchpad, EVEL_MAX_STRING_LEN, "%d", event_sequence);
162 header->event_id = strdup(scratchpad);
163 if( eventname == NULL )
164 header->event_name = strdup(functional_role);
166 header->event_name = strdup(eventname);
167 header->last_epoch_microsec = tv.tv_usec + 1000000 * tv.tv_sec;
168 header->priority = EVEL_PRIORITY_NORMAL;
169 header->reporting_entity_name = strdup(openstack_vm_name());
170 header->source_name = strdup(openstack_vm_name());
171 header->sequence = 0;
172 header->start_epoch_microsec = header->last_epoch_microsec;
173 header->major_version = EVEL_HEADER_MAJOR_VERSION;
174 header->minor_version = EVEL_HEADER_MINOR_VERSION;
177 /***************************************************************************/
178 /* Optional parameters. */
179 /***************************************************************************/
180 evel_init_option_string(&header->event_type);
181 evel_init_option_string(&header->nfcnaming_code);
182 evel_init_option_string(&header->nfnaming_code);
183 evel_init_option_string(&header->reporting_entity_id);
184 evel_init_option_string(&header->source_id);
185 evel_init_option_intheader(&header->internal_field);
186 dlist_initialize(&header->batch_events);
192 /**************************************************************************//**
193 * Initialize a newly created event header.
195 * @param header Pointer to the header being initialized.
196 * @param eventname Eventname string
197 * @param eventid Event id : unique id for classification and analysis
198 * @param header Pointer to the header being initialized.
199 *****************************************************************************/
200 void evel_init_header_nameid(EVENT_HEADER * const header,const char *const eventname, const char *eventid)
206 assert(header != NULL);
207 assert(eventname != NULL);
208 assert(eventid != NULL);
210 gettimeofday(&tv, NULL);
212 /***************************************************************************/
213 /* Initialize the header. Reset event sequence number. Note that if */
214 /* any memory allocation fails in here we will fail gracefully because */
215 /* everything downstream can cope with NULLs. */
216 /***************************************************************************/
217 header->event_domain = EVEL_DOMAIN_HEARTBEAT;
218 header->event_id = strdup(eventid);
219 header->event_name = strdup(eventname);
220 header->last_epoch_microsec = tv.tv_usec + 1000000 * tv.tv_sec;
221 header->priority = EVEL_PRIORITY_NORMAL;
222 header->reporting_entity_name = strdup(openstack_vm_name());
223 header->source_name = strdup(openstack_vm_name());
224 header->sequence = 0;
225 header->start_epoch_microsec = header->last_epoch_microsec;
226 header->major_version = EVEL_HEADER_MAJOR_VERSION;
227 header->minor_version = EVEL_HEADER_MINOR_VERSION;
229 /***************************************************************************/
230 /* Optional parameters. */
231 /***************************************************************************/
232 evel_init_option_string(&header->event_type);
233 evel_init_option_string(&header->nfcnaming_code);
234 evel_init_option_string(&header->nfnaming_code);
235 evel_init_option_string(&header->reporting_entity_id);
236 evel_init_option_string(&header->source_id);
237 evel_init_option_intheader(&header->internal_field);
238 dlist_initialize(&header->batch_events);
243 /**************************************************************************//**
244 * Set the Event Type property of the event header.
246 * @note The property is treated as immutable: it is only valid to call
247 * the setter once. However, we don't assert if the caller tries to
248 * overwrite, just ignoring the update instead.
250 * @param header Pointer to the ::EVENT_HEADER.
251 * @param type The Event Type to be set. ASCIIZ string. The caller
252 * does not need to preserve the value once the function
254 *****************************************************************************/
255 void evel_header_type_set(EVENT_HEADER * const header,
256 const char * const type)
260 /***************************************************************************/
261 /* Check preconditions. */
262 /***************************************************************************/
263 assert(header != NULL);
264 assert(type != NULL);
266 evel_set_option_string(&header->event_type, type, "Event Type");
271 /**************************************************************************//**
272 * Set the Event Sequence property of the event header.
274 * @note The Start Epoch defaults to the time of event creation.
276 * @param header Pointer to the ::EVENT_HEADER.
277 * @param start_epoch_microsec
278 * The start epoch to set, in microseconds.
279 *****************************************************************************/
280 void evel_event_sequence_set(EVENT_HEADER * const header,const int sequence_number)
284 /***************************************************************************/
285 /* Check preconditions and assign the new value. */
286 /***************************************************************************/
287 assert(header != NULL);
288 header->sequence = sequence_number;
294 /**************************************************************************//**
295 * Set the Start Epoch property of the event header.
297 * @note The Start Epoch defaults to the time of event creation.
299 * @param header Pointer to the ::EVENT_HEADER.
300 * @param start_epoch_microsec
301 * The start epoch to set, in microseconds.
302 *****************************************************************************/
303 void evel_start_epoch_set(EVENT_HEADER * const header,
304 const unsigned long long start_epoch_microsec)
308 /***************************************************************************/
309 /* Check preconditions and assign the new value. */
310 /***************************************************************************/
311 assert(header != NULL);
312 header->start_epoch_microsec = start_epoch_microsec;
317 /**************************************************************************//**
318 * Set the Last Epoch property of the event header.
320 * @note The Last Epoch defaults to the time of event creation.
322 * @param header Pointer to the ::EVENT_HEADER.
323 * @param last_epoch_microsec
324 * The last epoch to set, in microseconds.
325 *****************************************************************************/
326 void evel_last_epoch_set(EVENT_HEADER * const header,
327 const unsigned long long last_epoch_microsec)
331 /***************************************************************************/
332 /* Check preconditions and assign the new value. */
333 /***************************************************************************/
334 assert(header != NULL);
335 header->last_epoch_microsec = last_epoch_microsec;
340 /**************************************************************************//**
341 * Set the NFC Naming code property of the event header.
343 * @param header Pointer to the ::EVENT_HEADER.
344 * @param nfcnamingcode String
345 *****************************************************************************/
346 void evel_nfcnamingcode_set(EVENT_HEADER * const header,
347 const char * const nfcnam)
351 /***************************************************************************/
352 /* Check preconditions and assign the new value. */
353 /***************************************************************************/
354 assert(header != NULL);
355 assert(nfcnam != NULL);
356 evel_set_option_string(&header->nfcnaming_code, nfcnam, "NFC Naming Code");
361 /**************************************************************************//**
362 * Set the NF Naming code property of the event header.
364 * @param header Pointer to the ::EVENT_HEADER.
365 * @param nfnamingcode String
366 *****************************************************************************/
367 void evel_nfnamingcode_set(EVENT_HEADER * const header,
368 const char * const nfnam)
372 /***************************************************************************/
373 /* Check preconditions and assign the new value. */
374 /***************************************************************************/
375 assert(header != NULL);
376 assert(nfnam != NULL);
377 evel_set_option_string(&header->nfnaming_code, nfnam, "NF Naming Code");
383 /**************************************************************************//**
384 * Set the Reporting Entity Name property of the event header.
386 * @note The Reporting Entity Name defaults to the OpenStack VM Name.
388 * @param header Pointer to the ::EVENT_HEADER.
389 * @param entity_name The entity name to set.
390 *****************************************************************************/
391 void evel_reporting_entity_name_set(EVENT_HEADER * const header,
392 const char * const entity_name)
396 /***************************************************************************/
397 /* Check preconditions and assign the new value. */
398 /***************************************************************************/
399 assert(header != NULL);
400 assert(entity_name != NULL);
401 assert(header->reporting_entity_name != NULL);
403 /***************************************************************************/
404 /* Free the previously allocated memory and replace it with a copy of the */
406 /***************************************************************************/
407 free(header->reporting_entity_name);
408 header->reporting_entity_name = strdup(entity_name);
413 /**************************************************************************//**
414 * Set the Source Name property of the event header.
416 * @note The Source Name defaults to the OpenStack VM Name.
418 * @param header Pointer to the ::EVENT_HEADER.
419 * @param entity_name The source name to set.
420 *****************************************************************************/
421 void evel_source_name_set(EVENT_HEADER * const header,
422 const char * const source_name)
426 /***************************************************************************/
427 /* Check preconditions and assign the new value. */
428 /***************************************************************************/
429 assert(header != NULL);
430 assert(source_name != NULL);
432 /***************************************************************************/
433 /* Free the previously allocated memory and replace it with a copy of the */
435 /***************************************************************************/
436 free(header->source_name);
437 header->source_name = strdup(source_name);
442 /**************************************************************************//**
443 * Set the Reporting Entity Id property of the event header.
445 * @note The Reporting Entity Id defaults to the OpenStack VM UUID.
447 * @param header Pointer to the ::EVENT_HEADER.
448 * @param entity_id The entity id to set.
449 *****************************************************************************/
450 void evel_reporting_entity_id_set(EVENT_HEADER * const header,
451 const char * const entity_id)
455 /***************************************************************************/
456 /* Check preconditions and assign the new value. */
457 /***************************************************************************/
458 assert(header != NULL);
459 assert(entity_id != NULL);
461 /***************************************************************************/
462 /* Free the previously allocated memory and replace it with a copy of the */
463 /* provided one. Note that evel_force_option_string strdups entity_id. */
464 /***************************************************************************/
465 evel_free_option_string(&header->reporting_entity_id);
466 evel_force_option_string(&header->reporting_entity_id, entity_id);
471 /**************************************************************************//**
472 * Set the Source Id property of the event header.
474 * @note The Source Id defaults to the OpenStack VM UUID.
476 * @param header Pointer to the ::EVENT_HEADER.
477 * @param entity_id The Source id to set.
478 *****************************************************************************/
479 void evel_source_id_set(EVENT_HEADER * const header,
480 const char * const source_id)
484 /***************************************************************************/
485 /* Check preconditions and assign the new value. */
486 /***************************************************************************/
487 assert(header != NULL);
488 assert(source_id != NULL);
490 /***************************************************************************/
491 /* Free the previously allocated memory and replace it with a copy of the */
492 /* provided one. Note that evel_force_option_string strdups entity_id. */
493 /***************************************************************************/
494 evel_free_option_string(&header->source_id);
495 evel_force_option_string(&header->source_id, source_id);
500 /**************************************************************************//**
501 * Encode the event as a JSON event object according to AT&T's schema.
503 * @param jbuf Pointer to the ::EVEL_JSON_BUFFER to encode into.
504 * @param event Pointer to the ::EVENT_HEADER to encode.
505 *****************************************************************************/
506 void evel_json_encode_header(EVEL_JSON_BUFFER * jbuf,
507 EVENT_HEADER * event)
514 /***************************************************************************/
515 /* Check preconditions. */
516 /***************************************************************************/
517 assert(jbuf != NULL);
518 assert(jbuf->json != NULL);
519 assert(jbuf->max_size > 0);
520 assert(event != NULL);
522 domain = evel_event_domain(event->event_domain);
523 priority = evel_event_priority(event->priority);
524 evel_json_open_named_object(jbuf, "commonEventHeader");
526 /***************************************************************************/
527 /* Mandatory fields. */
528 /***************************************************************************/
529 evel_enc_kv_string(jbuf, "domain", domain);
530 evel_enc_kv_string(jbuf, "eventId", event->event_id);
531 evel_enc_kv_string(jbuf, "eventName", event->event_name);
532 evel_enc_kv_ull(jbuf, "lastEpochMicrosec", event->last_epoch_microsec);
533 evel_enc_kv_string(jbuf, "priority", priority);
535 jbuf, "reportingEntityName", event->reporting_entity_name);
536 evel_enc_kv_int(jbuf, "sequence", event->sequence);
537 evel_enc_kv_string(jbuf, "sourceName", event->source_name);
538 evel_enc_kv_ull(jbuf, "startEpochMicrosec", event->start_epoch_microsec);
540 jbuf, "version", event->major_version, event->minor_version);
542 /***************************************************************************/
543 /* Optional fields. */
544 /***************************************************************************/
545 evel_enc_kv_opt_string(jbuf, "eventType", &event->event_type);
546 evel_enc_kv_opt_string(
547 jbuf, "reportingEntityId", &event->reporting_entity_id);
548 evel_enc_kv_opt_string(jbuf, "sourceId", &event->source_id);
549 evel_enc_kv_opt_string(jbuf, "nfcNamingCode", &event->nfcnaming_code);
550 evel_enc_kv_opt_string(jbuf, "nfNamingCode", &event->nfnaming_code);
552 evel_json_close_object(jbuf);
557 /**************************************************************************//**
558 * Free an event header.
560 * Free off the event header supplied. Will free all the contained allocated
563 * @note It does not free the header itself, since that may be part of a
565 *****************************************************************************/
566 void evel_free_header(EVENT_HEADER * const event)
570 /***************************************************************************/
571 /* Check preconditions. As an internal API we don't allow freeing NULL */
572 /* events as we do on the public API. */
573 /***************************************************************************/
574 assert(event != NULL);
576 /***************************************************************************/
577 /* Free all internal strings. */
578 /***************************************************************************/
579 free(event->event_id);
580 evel_free_option_string(&event->event_type);
581 free(event->event_name);
582 evel_free_option_string(&event->reporting_entity_id);
583 free(event->reporting_entity_name);
584 evel_free_option_string(&event->source_id);
585 evel_free_option_string(&event->nfcnaming_code);
586 evel_free_option_string(&event->nfnaming_code);
587 evel_free_option_intheader(&event->internal_field);
588 free(event->source_name);
594 /**************************************************************************//**
595 * Encode the event as a JSON event object according to AT&T's schema.
597 * @param json Pointer to where to store the JSON encoded data.
598 * @param max_size Size of storage available in json_body.
599 * @param event Pointer to the ::EVENT_HEADER to encode.
600 * @returns Number of bytes actually written.
601 *****************************************************************************/
602 void evel_json_encode_eventtype(
603 EVEL_JSON_BUFFER * jbuf,
604 EVENT_HEADER * event)
606 switch (event->event_domain)
608 case EVEL_DOMAIN_HEARTBEAT:
609 evel_json_encode_header(jbuf, event);
612 case EVEL_DOMAIN_FAULT:
613 evel_json_encode_fault(jbuf, (EVENT_FAULT *)event);
616 case EVEL_DOMAIN_MEASUREMENT:
617 evel_json_encode_measurement(jbuf, (EVENT_MEASUREMENT *)event);
620 case EVEL_DOMAIN_MOBILE_FLOW:
621 evel_json_encode_mobile_flow(jbuf, (EVENT_MOBILE_FLOW *)event);
624 case EVEL_DOMAIN_REPORT:
625 evel_json_encode_report(jbuf, (EVENT_REPORT *)event);
628 case EVEL_DOMAIN_HEARTBEAT_FIELD:
629 evel_json_encode_hrtbt_field(jbuf, (EVENT_HEARTBEAT_FIELD *)event);
632 case EVEL_DOMAIN_SIPSIGNALING:
633 evel_json_encode_signaling(jbuf, (EVENT_SIGNALING *)event);
636 case EVEL_DOMAIN_STATE_CHANGE:
637 evel_json_encode_state_change(jbuf, (EVENT_STATE_CHANGE *)event);
640 case EVEL_DOMAIN_SYSLOG:
641 evel_json_encode_syslog(jbuf, (EVENT_SYSLOG *)event);
644 case EVEL_DOMAIN_OTHER:
645 evel_json_encode_other(jbuf, (EVENT_OTHER *)event);
648 case EVEL_DOMAIN_VOICE_QUALITY:
649 evel_json_encode_voice_quality(jbuf, (EVENT_VOICE_QUALITY *)event);
652 case EVEL_DOMAIN_THRESHOLD_CROSS:
653 evel_json_encode_threshold_cross(jbuf, (EVENT_THRESHOLD_CROSS *)event);
656 case EVEL_DOMAIN_INTERNAL:
658 EVEL_ERROR("Unexpected domain %d", event->event_domain);
665 /**************************************************************************//**
666 * Encode the event as a JSON event object according to AT&T's schema.
668 * @param json Pointer to where to store the JSON encoded data.
669 * @param max_size Size of storage available in json_body.
670 * @param event Pointer to the ::EVENT_HEADER to encode.
671 * @returns Number of bytes actually written.
672 *****************************************************************************/
673 int evel_json_encode_event(char * json,
675 EVENT_HEADER * event)
677 EVEL_JSON_BUFFER json_buffer;
678 EVEL_JSON_BUFFER * jbuf = &json_buffer;
679 EVEL_THROTTLE_SPEC * throttle_spec;
683 /***************************************************************************/
684 /* Get the latest throttle specification for the domain. */
685 /***************************************************************************/
686 throttle_spec = evel_get_throttle_spec(event->event_domain);
688 /***************************************************************************/
689 /* Initialize the JSON_BUFFER and open the top-level objects. */
690 /***************************************************************************/
691 evel_json_buffer_init(jbuf, json, max_size, throttle_spec);
692 evel_json_open_object(jbuf);
693 evel_json_open_named_object(jbuf, "event");
695 evel_json_encode_eventtype(jbuf, event);
697 evel_json_close_object(jbuf);
698 evel_json_close_object(jbuf);
700 /***************************************************************************/
702 /***************************************************************************/
703 assert(jbuf->depth == 0);
704 if( jbuf->offset >= max_size ){
705 EVEL_ERROR("Event exceeded size limit %d", max_size);
713 /**************************************************************************//**
714 * Encode the event as a JSON event object according to AT&T's schema.
716 * @param json Pointer to where to store the JSON encoded data.
717 * @param max_size Size of storage available in json_body.
718 * @param event Pointer to the ::EVENT_HEADER to encode.
719 * @returns Number of bytes actually written.
720 *****************************************************************************/
721 int evel_json_encode_batch_event(char * json,
723 EVENT_HEADER * event)
725 EVEL_JSON_BUFFER json_buffer;
726 EVEL_JSON_BUFFER *jbuf = &json_buffer;
727 EVEL_THROTTLE_SPEC * throttle_spec;
729 EVENT_HEADER * batch_field = NULL;
730 DLIST_ITEM * batch_field_item = NULL;
734 /***************************************************************************/
735 /* Get the latest throttle specification for the domain. */
736 /***************************************************************************/
737 throttle_spec = evel_get_throttle_spec(event->event_domain);
739 /***************************************************************************/
740 /* Initialize the JSON_BUFFER and open the top-level objects. */
741 /***************************************************************************/
742 if (event->event_domain == EVEL_DOMAIN_BATCH){
743 evel_json_buffer_init(jbuf, json, max_size, throttle_spec);
745 if(dlist_count(&event->batch_events) > 0)
747 evel_json_open_object(jbuf);
748 evel_json_open_named_list(jbuf, "eventList");
749 batch_field_item = dlist_get_first(&event->batch_events);
750 while (batch_field_item != NULL)
752 batch_field = (EVENT_HEADER *) batch_field_item->item;
753 if(batch_field != NULL){
754 EVEL_DEBUG("Batch Event %p %p added curr fsize %d offset %d depth %d check %d", batch_field_item->item, batch_field, tot_size,jbuf->offset,jbuf->depth,jbuf->checkpoint);
755 evel_json_open_object(jbuf);
756 evel_json_encode_eventtype(jbuf, batch_field);
757 evel_json_close_object(jbuf);
759 tot_size += jbuf->offset;
760 EVEL_DEBUG("Batch Event result size %d offset %d depth %d check %d", tot_size,jbuf->offset,jbuf->depth,jbuf->checkpoint);
761 if( tot_size >= max_size ){
762 EVEL_ERROR("Batch Event exceeded size limit %d", tot_size);
765 batch_field_item = dlist_get_next(batch_field_item);
768 evel_json_close_list(jbuf);
769 evel_json_close_object(jbuf);
773 /***************************************************************************/
775 /***************************************************************************/
776 //assert(jbuf->depth == 0);
784 /**************************************************************************//**
785 * Initialize an event instance id.
787 * @param vfield Pointer to the event vnfname field being initialized.
788 * @param vendor_id The vendor id to encode in the event instance id.
789 * @param event_id The event id to encode in the event instance id.
790 *****************************************************************************/
791 void evel_init_vendor_field(VENDOR_VNFNAME_FIELD * const vfield,
792 const char * const vendor_name)
796 /***************************************************************************/
797 /* Check preconditions. */
798 /***************************************************************************/
799 assert(vfield != NULL);
800 assert(vendor_name != NULL);
802 /***************************************************************************/
803 /* Store the mandatory parts. */
804 /***************************************************************************/
805 vfield->vendorname = strdup(vendor_name);
806 evel_init_option_string(&vfield->vfmodule);
807 evel_init_option_string(&vfield->vnfname);
809 /***************************************************************************/
810 /* Initialize the optional parts. */
811 /***************************************************************************/
816 /**************************************************************************//**
817 * Set the Vendor module property of the Vendor.
819 * @note The property is treated as immutable: it is only valid to call
820 * the setter once. However, we don't assert if the caller tries to
821 * overwrite, just ignoring the update instead.
823 * @param vfield Pointer to the Vendor field.
824 * @param module_name The module name to be set. ASCIIZ string. The caller
825 * does not need to preserve the value once the function
827 *****************************************************************************/
828 void evel_vendor_field_module_set(VENDOR_VNFNAME_FIELD * const vfield,
829 const char * const module_name)
833 /***************************************************************************/
834 /* Check preconditions. */
835 /***************************************************************************/
836 assert(vfield != NULL);
837 assert(module_name != NULL);
839 evel_set_option_string(&vfield->vfmodule, module_name, "Module name set");
844 /**************************************************************************//**
845 * Set the Vendor module property of the Vendor.
847 * @note The property is treated as immutable: it is only valid to call
848 * the setter once. However, we don't assert if the caller tries to
849 * overwrite, just ignoring the update instead.
851 * @param vfield Pointer to the Vendor field.
852 * @param module_name The module name to be set. ASCIIZ string. The caller
853 * does not need to preserve the value once the function
855 *****************************************************************************/
856 void evel_vendor_field_vnfname_set(VENDOR_VNFNAME_FIELD * const vfield,
857 const char * const vnfname)
861 /***************************************************************************/
862 /* Check preconditions. */
863 /***************************************************************************/
864 assert(vfield != NULL);
865 assert(vnfname != NULL);
867 evel_set_option_string(&vfield->vnfname, vnfname, "Virtual Network Function name set");
872 /**************************************************************************//**
873 * Free an event instance id.
875 * @param vfield Pointer to the event vnfname_field being freed.
876 *****************************************************************************/
877 void evel_free_event_vendor_field(VENDOR_VNFNAME_FIELD * const vfield)
881 /***************************************************************************/
882 /* Check preconditions. */
883 /***************************************************************************/
884 assert(vfield->vendorname != NULL);
886 /***************************************************************************/
887 /* Free everything. */
888 /***************************************************************************/
889 evel_free_option_string(&vfield->vfmodule);
890 evel_free_option_string(&vfield->vnfname);
891 free(vfield->vendorname);
896 /**************************************************************************//**
897 * Encode the instance id as a JSON object according to AT&T's schema.
899 * @param jbuf Pointer to the ::EVEL_JSON_BUFFER to encode into.
900 * @param vfield Pointer to the ::VENDOR_VNFNAME_FIELD to encode.
901 *****************************************************************************/
902 void evel_json_encode_vendor_field(EVEL_JSON_BUFFER * jbuf,
903 VENDOR_VNFNAME_FIELD * vfield)
907 /***************************************************************************/
908 /* Check preconditions. */
909 /***************************************************************************/
910 assert(jbuf != NULL);
911 assert(jbuf->json != NULL);
912 assert(jbuf->max_size > 0);
913 assert(vfield != NULL);
914 assert(vfield->vendorname != NULL);
916 evel_json_open_named_object(jbuf, "vendorVnfNameFields");
918 /***************************************************************************/
919 /* Mandatory fields. */
920 /***************************************************************************/
921 evel_enc_kv_string(jbuf, "vendorName", vfield->vendorname);
922 evel_enc_kv_opt_string(jbuf, "vfModuleName", &vfield->vfmodule);
923 evel_enc_kv_opt_string(jbuf, "vnfName", &vfield->vnfname);
925 /***************************************************************************/
926 /* Optional fields. */
927 /***************************************************************************/
929 evel_json_close_object(jbuf);