1 /*******************************************************************************
2 ################################################################################
3 # Copyright (c) [2020-2021] [HCL Technologies Ltd.] #
5 # Licensed under the Apache License, Version 2.0 (the "License"); #
6 # you may not use this file except in compliance with the License. #
7 # You may obtain a copy of the License at #
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 ################################################################################
17 *******************************************************************************/
19 /* This file contains functions to support the preparation of VES common header
28 #include "JsonHelper.hpp"
29 #include "VesCommonHeader.hpp"
30 #include "VesUtils.hpp"
32 static double seqNo = 0;
34 #define MAX_TIME_STR 35
36 /*******************************************************************
38 * @brief provide next sequence number of VES event
42 * Function : nextSequenceNo
45 * - provide next sequence number of VES event
48 * @return next sequence number of event - success
50 * ****************************************************************/
52 double VesCommonHeader::nextSequenceNo()
57 /*******************************************************************
59 * @brief provide current sequence number of VES event
63 * Function : getSequenceNo
66 * - provide current sequence number of VES event
69 * @return current sequence number of event - success
71 * ****************************************************************/
73 double VesCommonHeader::getSequenceNo()
78 /*******************************************************************
80 * @brief Convert Ves Event type to string
84 * Function : getEventTypeToStr
87 * - Convert Ves Event type to String
89 * @params[in] IN - void
90 * @return value of string - success
91 * empty string - failure
93 * ****************************************************************/
95 string VesCommonHeader::getEventTypeToStr()
100 case VesEventType::PNF_REGISTRATION:
101 str = "pnfRegistration";
103 case VesEventType::FAULT_NOTIFICATION:
110 case VesEventType::PM_NOTIFICATION:
111 str = "pmNotification";
113 case VesEventType::PM_SLICE:
116 case VesEventType::HEARTBEAT:
120 O1_LOG("\nO1 VesCommonHeader : VES msg Type not supported");
126 /*******************************************************************
128 * @brief create Ves Event Id from Ves Event type
132 * Function : getEventId
135 * - create Ves Event Id from Ves Event type
137 * @params[in] IN - void
138 * @return value of string - success
139 * empty string - failure
141 * ****************************************************************/
143 string VesCommonHeader::getEventId()
145 /*Currently PNF_REGISTRATION only supported. This function must be updated
147 std::ostringstream oss;
148 oss << mLastEpochTime;
149 string stringEpochTime = oss.str().substr(0, 10);
153 case VesEventType::PNF_REGISTRATION:
154 evntId = getSourceName() + "_" + MODEL_NUMBER_007_DEV;
156 case VesEventType::HEARTBEAT:
157 evntId = getEventTypeToStr() + "_" + formatTime(getCurrentTime());
159 case VesEventType::PM_SLICE:
160 evntId = "_" + stringEpochTime + "_" + "PM1min";
162 case VesEventType::FAULT_NOTIFICATION:
164 evntId = FAULT_EVENTID;
166 evntId ="O_RAN_COMPONENT_Alarms-61";
170 O1_LOG("\nO1 VesCommonHeader : this VES msg Type support in getEventId is \
177 /*******************************************************************
179 * @brief create Ves Event Type from Ves Event type
183 * Function : getEventType
186 * - create Ves Event Type from Ves Event type
188 * @params[in] IN - void
189 * @return value of string - success
190 * empty string - failure
192 * ****************************************************************/
194 string VesCommonHeader::getEventType()
196 /*Currently PNF_REGISTRATION only supported. This function must be updated
199 string evntType = "";
202 case VesEventType::PNF_REGISTRATION:
203 evntType = EVENT_TYPE_5G;
205 case VesEventType::HEARTBEAT:
206 evntType = EVENT_TYPE_ORAN_COMPONENT;
208 case VesEventType::PM_SLICE:
209 evntType = EVENT_TYPE_ORAN_COMPONENT_PM;
211 case VesEventType::FAULT_NOTIFICATION:
212 evntType = FAULT_TYPE;
215 O1_LOG("\nO1 VesCommonHeader : this VES msg Type support in getEvenType is \
222 /*******************************************************************
224 * @brief return priority of event
228 * Function : getPriority
231 * - send priority of event
233 * @params[in] IN - void
234 * @return value of string - success
235 * empty string - failure
237 * ****************************************************************/
239 string VesCommonHeader::getPriority()
241 /*Currently PNF_REGISTRATION only supported. This function must be updated
247 case VesEventType::PNF_REGISTRATION:
248 evntId = PRIORITY_LOW ;
250 case VesEventType::HEARTBEAT:
251 evntId = PRIORITY_LOW;
253 case VesEventType::PM_SLICE:
254 evntId = PRIORITY_LOW ;
256 case VesEventType::FAULT_NOTIFICATION:
257 evntId = PRIORITY_LOW ;
260 O1_LOG("\nO1 VesCommonHeader : This VES msg Type support in getPriority is \
269 /*******************************************************************
271 * @brief create Ves Event Name from Ves Event type
275 * Function : getEventName
278 * - create Ves Event Name from Ves Event type
280 * @params[in] IN - void
281 * @return value of string - success
282 * empty string - failure
283 * ****************************************************************/
285 string VesCommonHeader::getEventName()
287 /*Currently PNF_REGISTRATION only supported. This function must be updated
290 string evntName = "";
293 case VesEventType::PNF_REGISTRATION:
294 evntName = getEventTypeToStr() + "_" + EVENT_TYPE_5G;
296 case VesEventType::HEARTBEAT:
297 evntName = getEventTypeToStr() + "_" + EVENT_TYPE_ORAN_COMPONENT;
299 case VesEventType::PM_SLICE:
300 evntName = getEventTypeToStr() + "_" + EVENT_TYPE_ORAN_COMPONENT_PM;
302 case VesEventType::FAULT_NOTIFICATION:
304 evntName = FAULT_EVENT_NAME;
306 evntName ="O_RAN_COMPONENT_Alarms";
310 O1_LOG("\nO1 VesCommonHeader : This VES msg Type support in getEventName is \
317 /*******************************************************************
319 * @brief create Ves Event Name from Ves Event type
323 * Function : getReportingEntityId
326 * - create Ves Event Name from Ves Event type
328 * @params[in] IN - void
329 * @return value of string - success
330 * empty string - failure
331 * ****************************************************************/
333 string VesCommonHeader::getReportingEntityId()
335 /*Currently PNF_REGISTRATION and PM_SLICE are only supported.
336 This function must be updated in later releases*/
338 string evntName = "";
341 case VesEventType::PNF_REGISTRATION:
345 case VesEventType::FAULT_NOTIFICATION:
354 /*******************************************************************
356 * @brief create Reporting Entity Name from Ves Event type
360 * Function : getReportingEntityName
363 * - create Reporting Entity Name from Ves Event type
365 * @params[in] IN - void
366 * @return value of string - success
367 * empty string - failure
368 * ****************************************************************/
370 string VesCommonHeader::getReportingEntityName()
372 string evntName = "";
375 case VesEventType::PNF_REGISTRATION:
376 evntName = getSourceName();
378 case VesEventType::PM_SLICE:
379 evntName = PM_REPORTING_ENTITY;
381 case VesEventType::FAULT_NOTIFICATION:
385 O1_LOG("\nO1 VesCommonHeader : This VES msg Type support in \
386 getReportingEntityName is not available");
392 /*******************************************************************
394 * @brief create Source Name from Ves Event type
398 * Function : getSourceName
401 * - create Source Name from Ves Event type
403 * @params[in] IN - void
404 * @return value of string - success
405 * empty string - failure
406 * ****************************************************************/
408 string VesCommonHeader::getSourceName()
410 string sourceName = "";
414 case VesEventType::PNF_REGISTRATION:
415 sourceName = ODU_HIGH;
417 case VesEventType::FAULT_NOTIFICATION:
418 sourceName = ODU_HIGH;
426 /*******************************************************************
428 * @brief create Ves Event SourceId from Ves Event type
432 * Function : getSourceId
435 * - create Ves Event SourceId from Ves Event type
437 * @params[in] IN - void
438 * @return value of string - success
439 * empty string - failure
440 * ****************************************************************/
441 string VesCommonHeader::getSourceId()
443 string sourceId = "";
446 case VesEventType::FAULT_NOTIFICATION:
447 sourceId = SOURCE_ID;
455 /*******************************************************************
457 * @brief create Ves Event Name from Ves Event type
461 * Function : getnfcNamingCode
463 * Functionality: create Ves Event nfc naming code
465 * @params[in] IN - void
466 * @return value of string - success
467 * empty string - failure
468 * ****************************************************************/
470 string VesCommonHeader::getnfcNamingCode()
475 case VesEventType::FAULT_NOTIFICATION:
476 name = NFC_NAMING_CODE;
484 /*******************************************************************
486 * @brief create Ves Event Name from Ves Event type
490 * Function : getNamingCode
493 * - Network function type: 4 characters (aligned with vnf and pnf
496 * @params[in] IN - void
497 * @return value of string - success
498 * empty string - failure
499 * ****************************************************************/
501 string VesCommonHeader::getNamingCode()
504 string nammingcdoe = "";
507 case VesEventType::PNF_REGISTRATION:
508 nammingcdoe = NAMING_CODE_ODU;
510 case VesEventType::PM_SLICE:
512 case VesEventType::FAULT_NOTIFICATION:
513 nammingcdoe = NAMING_CODE_ODU;
516 O1_LOG("\nO1 VesCommonHeader : This VES msg Type support in \
517 getReportingEntityName is not available");
525 /*******************************************************************
527 * @brief provide current epoch time
531 * Function : getEpochTime
534 * - provide current epoch time
537 * @return epoch time - success
539 * ****************************************************************/
541 double VesCommonHeader::getEpochTime()
543 double epochTimeInMicrosec = std::chrono::duration_cast \
544 <std::chrono::microseconds> \
545 (std::chrono::system_clock::now().time_since_epoch()).count();
546 return epochTimeInMicrosec;
549 /*******************************************************************
551 * @brief get current time
555 * Function : getCurrentTime
561 * @return time - success
563 * ****************************************************************/
565 time_t VesCommonHeader::getCurrentTime()
572 /*******************************************************************
574 * @brief formats the current time like:
575 * "Thu, 14 Oct 2021 03:15:00 +0000"
579 * Function : formatTime
582 * - formats current time
585 * @return formatted time - success
587 * ****************************************************************/
589 std::string VesCommonHeader::formatTime(time_t t) {
590 std::ostringstream oss;
591 char dateStr[MAX_TIME_STR];
592 strftime(dateStr, sizeof(dateStr), "%a, %d %b %Y %T %z", gmtime(&t));
598 /*******************************************************************
600 * @brief create Ves stndDefinedNamespace from Ves Event type
604 * Function : getstndDefinedNamespace
606 * Functionality: create Ves tndDefinedNamespace
608 * @params[in] IN - void
609 * @return value of string - success
610 * empty string - failure
611 * ****************************************************************/
613 string VesCommonHeader::getstndDefinedNamespace()
615 string stndDefinedNamespace="";
618 case VesEventType::FAULT_NOTIFICATION:
619 stndDefinedNamespace = STND_DEFINED_NAMESPACE;
624 return stndDefinedNamespace;
628 /*******************************************************************
630 * @brief Prepare VES Message
637 * - prepare VES event
640 * @return true - success
643 * ****************************************************************/
646 bool VesCommonHeader::prepare(cJSON *commonHeader, \
655 nextSequenceNo(); //update the sequence number for next message
656 //local utility variables:
657 time_t intervalStartTime = getCurrentTime();
658 time_t intervalEndTime = intervalStartTime+60; /*adding 1 min to system time*/
659 double startEpochTime = getEpochTime();
660 mLastEpochTime = startEpochTime+60*100000; /*adding 1 min to epoch time*/
662 if(JsonHelper::addNodeToObject(commonHeader, "domain", \
663 getEventTypeToStr().c_str()) == 0) {
666 else if ( JsonHelper::addNodeToObject(commonHeader, "eventId", \
667 getEventId().c_str()) == 0)
671 else if(JsonHelper::addNodeToObject(commonHeader, "eventName", \
672 getEventName().c_str()) == 0)
676 else if(JsonHelper::addNodeToObject(commonHeader, "eventType", \
677 getEventType().c_str()) == 0)
682 if (mEventType == VesEventType::PM_SLICE)
684 cJSON *internalHeaderFields = JsonHelper::createNode();
685 if(internalHeaderFields == 0)
689 else if(JsonHelper::addJsonNodeToObject(commonHeader, "internalHeaderFields", \
690 internalHeaderFields) == 0)
694 else if(JsonHelper::addNodeToObject(internalHeaderFields, "intervalEndTime", \
695 formatTime(intervalEndTime).c_str()) == 0)
699 else if(JsonHelper::addNodeToObject(internalHeaderFields, "intervalStartTime", \
700 formatTime(intervalStartTime).c_str()) == 0)
706 if (mEventType == VesEventType::PNF_REGISTRATION)
711 if(JsonHelper::addNodeToObject(commonHeader, "sequence", \
712 getSequenceNo()) == 0)
716 else if(JsonHelper::addNodeToObject(commonHeader, "priority", \
717 getPriority().c_str()) == 0)
721 else if(JsonHelper::addNodeToObject(commonHeader, "reportingEntityId", \
722 getReportingEntityId().c_str() ) == 0)
726 else if(JsonHelper::addNodeToObject(commonHeader, "reportingEntityName", \
727 getReportingEntityName().c_str()) == 0)
731 else if(JsonHelper::addNodeToObject(commonHeader, "sourceId", \
732 getSourceId().c_str() ) == 0)
736 else if(JsonHelper::addNodeToObject(commonHeader, "sourceName", \
737 getSourceName().c_str()) == 0)
741 else if(JsonHelper::addNodeToObject(commonHeader, "startEpochMicrosec", \
742 startEpochTime) == 0)
746 else if(JsonHelper::addNodeToObject(commonHeader, "lastEpochMicrosec", \
747 mLastEpochTime) == 0)
751 else if(JsonHelper::addNodeToObject(commonHeader, "nfNamingCode", \
752 getNamingCode().c_str() ) == 0)
756 else if(JsonHelper::addNodeToObject(commonHeader, "nfVendorName", \
761 else if(JsonHelper::addNodeToObject(commonHeader, "nfcNamingCode", \
762 getnfcNamingCode().c_str() ) == 0)
766 else if(JsonHelper::addNodeToObject(commonHeader, "timeZoneOffset", \
767 TIME_ZONE_00_00) == 0)
772 if (mEventType == VesEventType::PM_SLICE)
774 if(JsonHelper::addNodeToObject(commonHeader, "version", \
782 if(JsonHelper::addNodeToObject(commonHeader, "version", \
783 COMMON_HEADER_VERSION) == 0)
788 if(JsonHelper::addNodeToObject(commonHeader, "stndDefinedNamespace", \
789 getstndDefinedNamespace().c_str())== 0)
793 if(JsonHelper::addNodeToObject(commonHeader, "vesEventListenerVersion", \
794 VES_EVENT_LISNERT_VERSION) == 0)
800 O1_LOG("\nO1 VesCommonHeader : VES common Header prepared");
805 /**********************************************************************
807 **********************************************************************/