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"
31 static uint16_t seqNo = 0;
33 #define MAX_TIME_STR 35
35 /*******************************************************************
37 * @brief provide next sequence number of VES event
41 * Function : nextSequenceNo
44 * - provide next sequence number of VES event
47 * @return next sequence number of event - success
49 * ****************************************************************/
51 uint16_t VesCommonHeader::nextSequenceNo()
56 /*******************************************************************
58 * @brief provide current sequence number of VES event
62 * Function : getSequenceNo
65 * - provide current sequence number of VES event
68 * @return current sequence number of event - success
70 * ****************************************************************/
72 uint16_t VesCommonHeader::getSequenceNo()
77 /*******************************************************************
79 * @brief Convert Ves Event type to string
83 * Function : getEventTypeToStr
86 * - Convert Ves Event type to String
88 * @params[in] IN - void
89 * @return value of string - success
90 * empty string - failure
92 * ****************************************************************/
94 string VesCommonHeader::getEventTypeToStr()
99 case VesEventType::PNF_REGISTRATION:
100 str = "pnfRegistration";
102 case VesEventType::FAULT_NOTIFICATION:
103 str = "faultNotification";
105 case VesEventType::PM_NOTIFICATION:
106 str = "pmNotification";
108 case VesEventType::PM_SLICE:
111 case VesEventType::HEARTBEAT:
115 O1_LOG("\nO1 VesCommonHeader : VES msg Type not supported");
121 /*******************************************************************
123 * @brief create Ves Event Id from Ves Event type
127 * Function : getEventId
130 * - create Ves Event Id from Ves Event type
132 * @params[in] IN - void
133 * @return value of string - success
134 * empty string - failure
136 * ****************************************************************/
138 string VesCommonHeader::getEventId()
140 /*Currently PNF_REGISTRATION only supported. This function must be updated
142 std::ostringstream oss;
143 oss << mLastEpochTime;
144 string stringEpochTime = oss.str().substr(0, 10);
148 case VesEventType::PNF_REGISTRATION:
149 evntId = getSourceName() + "_" + MODEL_NUMBER_007_DEV;
151 case VesEventType::HEARTBEAT:
152 evntId = getEventTypeToStr() + "_" + formatTime(getCurrentTime());
154 case VesEventType::PM_SLICE:
155 evntId = "_" + stringEpochTime + "_" + "PM1min";
157 case VesEventType::FAULT_NOTIFICATION:
158 evntId = getSourceName() + "_" + MODEL_NUMBER_007_DEV;
161 O1_LOG("\nO1 VesCommonHeader : this VES msg Type support in getEventId is \
168 /*******************************************************************
170 * @brief create Ves Event Type
174 * Function : getEventType
177 * - create Ves Event Type
179 * @params[in] IN - void
180 * @return value of string - success
181 * empty string - failure
183 * ****************************************************************/
185 string VesCommonHeader::getEventType()
187 /*Currently PNF_REGISTRATION only supported. This function must be updated
190 string evntType = "";
193 case VesEventType::PNF_REGISTRATION:
194 evntType = EVENT_TYPE_5G;
196 case VesEventType::HEARTBEAT:
197 evntType = EVENT_TYPE_ORAN_COMPONENT;
199 case VesEventType::PM_SLICE:
200 evntType = EVENT_TYPE_ORAN_COMPONENT_PM;
202 case VesEventType::FAULT_NOTIFICATION:
203 evntType = EVENT_TYPE_5G;
206 O1_LOG("\nO1 VesCommonHeader : this VES msg Type support in getEvenType is \
213 /*******************************************************************
215 * @brief return priority of event
219 * Function : getPriority
222 * - send priority of event
224 * @params[in] IN - void
225 * @return value of string - success
226 * empty string - failure
228 * ****************************************************************/
230 string VesCommonHeader::getPriority()
232 /*Currently PNF_REGISTRATION only supported. This function must be updated
238 case VesEventType::PNF_REGISTRATION:
239 evntId = PRIORITY_LOW ;
241 case VesEventType::HEARTBEAT:
242 evntId = PRIORITY_LOW;
244 case VesEventType::PM_SLICE:
245 evntId = PRIORITY_LOW ;
247 case VesEventType::FAULT_NOTIFICATION:
248 evntId = PRIORITY_LOW ;
251 O1_LOG("\nO1 VesCommonHeader : This VES msg Type support in getPriority is \
260 /*******************************************************************
262 * @brief create Ves Event Name from Ves Event type
266 * Function : getEventName
269 * - create Ves Event Name from Ves Event type
271 * @params[in] IN - void
272 * @return value of string - success
273 * empty string - failure
274 * ****************************************************************/
276 string VesCommonHeader::getEventName()
278 /*Currently PNF_REGISTRATION only supported. This function must be updated
281 string evntName = "";
284 case VesEventType::PNF_REGISTRATION:
285 evntName = getEventTypeToStr() + "_" + EVENT_TYPE_5G;
287 case VesEventType::HEARTBEAT:
288 evntName = getEventTypeToStr() + "_" + EVENT_TYPE_ORAN_COMPONENT;
290 case VesEventType::PM_SLICE:
291 evntName = getEventTypeToStr() + "_" + EVENT_TYPE_ORAN_COMPONENT_PM;
293 case VesEventType::FAULT_NOTIFICATION:
294 evntName = getEventTypeToStr() + "_" + EVENT_TYPE_5G;
297 O1_LOG("\nO1 VesCommonHeader : This VES msg Type support in getEventName is \
304 /*******************************************************************
306 * @brief create Ves Event Name from Ves Event type
310 * Function : getReportingEntityName
313 * - create Ves Event Name from Ves Event type
315 * @params[in] IN - void
316 * @return value of string - success
317 * empty string - failure
318 * ****************************************************************/
320 string VesCommonHeader::getReportingEntityName()
322 /*Currently PNF_REGISTRATION and PM_SLICE are only supported.
323 This function must be updated in later releases*/
325 string evntName = "";
328 case VesEventType::PNF_REGISTRATION:
329 evntName = getSourceName();
331 case VesEventType::PM_SLICE:
332 evntName = PM_REPORTING_ENTITY;
334 case VesEventType::FAULT_NOTIFICATION:
335 evntName = getSourceName();
338 O1_LOG("\nO1 VesCommonHeader : This VES msg Type support in \
339 getReportingEntityName is not available");
345 /*******************************************************************
347 * @brief create Ves Event Name from Ves Event type
351 * Function : getReportingEntityName
354 * - create Ves Event Name from Ves Event type
356 * @params[in] IN - void
357 * @return value of string - success
358 * empty string - failure
359 * ****************************************************************/
361 string VesCommonHeader::getSourceName()
366 /*******************************************************************
368 * @brief create Ves Event Name from Ves Event type
372 * Function : getNamingCode
375 * - Network function type: 4 characters (aligned with vnf and pnf
378 * @params[in] IN - void
379 * @return value of string - success
380 * empty string - failure
381 * ****************************************************************/
383 string VesCommonHeader::getNamingCode()
385 return NAMING_CODE_ODU;
390 /*******************************************************************
392 * @brief provide current epoch time
396 * Function : getEpochTime
399 * - provide current epoch time
402 * @return epoch time - success
404 * ****************************************************************/
406 uint64_t VesCommonHeader::getEpochTime()
408 uint64_t epochTimeInMicrosec = std::chrono::duration_cast \
409 <std::chrono::microseconds> \
410 (std::chrono::system_clock::now().time_since_epoch()).count();
411 return epochTimeInMicrosec;
414 /*******************************************************************
416 * @brief get current time
420 * Function : getCurrentTime
426 * @return time - success
428 * ****************************************************************/
430 time_t VesCommonHeader::getCurrentTime()
437 /*******************************************************************
439 * @brief formats the current time like:
440 * "Thu, 14 Oct 2021 03:15:00 +0000"
444 * Function : formatTime
447 * - formats current time
450 * @return formatted time - success
452 * ****************************************************************/
454 std::string VesCommonHeader::formatTime(time_t t) {
455 std::ostringstream oss;
456 char dateStr[MAX_TIME_STR];
457 strftime(dateStr, sizeof(dateStr), "%a, %d %b %Y %T %z", gmtime(&t));
462 /*******************************************************************
464 * @brief create Ves Event Name from Ves Event type
468 * Function : getEventName
471 * - create Ves Event Name from Ves Event type
473 * @params[in] IN - VesEventType , OUT - Ves Event Name
474 * @return ture - success
477 * ****************************************************************/
479 bool VesCommonHeader::prepare(cJSON *commonHeader, \
488 nextSequenceNo(); //update the sequence number for next message
489 //local utility variables:
490 time_t intervalStartTime = getCurrentTime();
491 time_t intervalEndTime = intervalStartTime+60; /*adding 1 min to system time*/
492 uint64_t startEpochTime = getEpochTime();
493 mLastEpochTime = startEpochTime+60*100000; /*adding 1 min to epoch time*/
495 if(JsonHelper::addNodeToObject(commonHeader, "domain", \
496 getEventTypeToStr().c_str()) == 0) {
499 else if ( JsonHelper::addNodeToObject(commonHeader, "eventId", \
500 getEventId().c_str()) == 0)
504 else if(JsonHelper::addNodeToObject(commonHeader, "eventName", \
505 getEventName().c_str()) == 0)
509 else if(JsonHelper::addNodeToObject(commonHeader, "eventType", \
510 getEventType().c_str()) == 0)
515 if (mEventType == VesEventType::PM_SLICE)
517 cJSON *internalHeaderFields = JsonHelper::createNode();
518 if(internalHeaderFields == 0)
522 else if(JsonHelper::addJsonNodeToObject(commonHeader, "internalHeaderFields", \
523 internalHeaderFields) == 0)
527 else if(JsonHelper::addNodeToObject(internalHeaderFields, "intervalEndTime", \
528 formatTime(intervalEndTime).c_str()) == 0)
532 else if(JsonHelper::addNodeToObject(internalHeaderFields, "intervalStartTime", \
533 formatTime(intervalStartTime).c_str()) == 0)
537 else if(JsonHelper::addNodeToObject(commonHeader, "nfcNamingCode", \
542 else if(JsonHelper::addNodeToObject(commonHeader, "stndDefinedNamespace", \
549 if (mEventType == VesEventType::PNF_REGISTRATION)
554 if(JsonHelper::addNodeToObject(commonHeader, "sequence", \
555 getSequenceNo()) == 0)
559 else if(JsonHelper::addNodeToObject(commonHeader, "priority", \
560 getPriority().c_str()) == 0)
564 else if(JsonHelper::addNodeToObject(commonHeader, "reportingEntityId", \
569 else if(JsonHelper::addNodeToObject(commonHeader, "reportingEntityName", \
570 getReportingEntityName().c_str()) == 0)
574 else if(JsonHelper::addNodeToObject(commonHeader, "sourceId", \
579 else if(JsonHelper::addNodeToObject(commonHeader, "sourceName", \
580 getSourceName().c_str()) == 0)
584 else if(JsonHelper::addNodeToObject(commonHeader, "startEpochMicrosec", \
585 (double)startEpochTime) == 0)
589 else if(JsonHelper::addNodeToObject(commonHeader, "lastEpochMicrosec", \
590 (double)mLastEpochTime) == 0)
594 else if(JsonHelper::addNodeToObject(commonHeader, "nfNamingCode", \
595 (type==VesEventType::PNF_REGISTRATION) ? \
596 getNamingCode().c_str() : "") == 0)
600 else if(JsonHelper::addNodeToObject(commonHeader, "nfVendorName", \
605 else if(JsonHelper::addNodeToObject(commonHeader, "timeZoneOffset", \
606 TIME_ZONE_00_00) == 0)
611 if (mEventType == VesEventType::PM_SLICE)
613 if(JsonHelper::addNodeToObject(commonHeader, "version", \
621 if(JsonHelper::addNodeToObject(commonHeader, "version", \
628 if(JsonHelper::addNodeToObject(commonHeader, "vesEventListenerVersion", \
629 VES_EVENT_LISTENER_7_2_1) == 0)
635 O1_LOG("\nO1 VesCommonHeader : VES common Header prepared");
640 /**********************************************************************
642 **********************************************************************/