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 /*******************************************************************
35 * @brief provide next sequence number of VES event
39 * Function : nextSequenceNo
42 * - provide next sequence number of VES event
45 * @return next sequence number of event - success
47 * ****************************************************************/
49 uint16_t VesCommonHeader::nextSequenceNo()
54 /*******************************************************************
56 * @brief provide current sequence number of VES event
60 * Function : getSequenceNo
63 * - provide current sequence number of VES event
66 * @return current sequence number of event - success
68 * ****************************************************************/
70 uint16_t VesCommonHeader::getSequenceNo()
75 /*******************************************************************
77 * @brief Convert Ves Event type to string
81 * Function : getEventTypeToStr
84 * - Convert Ves Event type to String
86 * @params[in] IN - void
87 * @return value of string - success
88 * empty string - failure
90 * ****************************************************************/
92 string VesCommonHeader::getEventTypeToStr()
97 case VesEventType::PNF_REGISTRATION:
98 str = "pnfRegistration";
100 case VesEventType::FAULT_NOTIFICATION:
101 str = "faultNotification";
103 case VesEventType::PM_NOTIFICATION:
104 str = "pmNotification";
106 case VesEventType::HEARTBEAT:
110 O1_LOG("\nO1 VesCommonHeader : VES msg Type not supported");
116 /*******************************************************************
118 * @brief create Ves Event Id from Ves Event type
122 * Function : getEventId
125 * - create Ves Event Id from Ves Event type
127 * @params[in] IN - void
128 * @return value of string - success
129 * empty string - failure
131 * ****************************************************************/
133 string VesCommonHeader::getEventId()
135 /*Currently PNF_REGISTRATION only supported. This function must be updated
140 case VesEventType::PNF_REGISTRATION:
141 evntId = getSourceName() + "_" + MODEL_NUMBER_007_DEV;
143 case VesEventType::HEARTBEAT:
144 evntId = getEventTypeToStr() + "_" + getCurrentTime();
147 O1_LOG("\nO1 VesCommonHeader : this VES msg Type support in getEventId is \
155 /*******************************************************************
157 * @brief create Ves Event Type
161 * Function : getEventType
164 * - create Ves Event Type
166 * @params[in] IN - void
167 * @return value of string - success
168 * empty string - failure
170 * ****************************************************************/
172 string VesCommonHeader::getEventType()
174 /*Currently PNF_REGISTRATION only supported. This function must be updated
177 string evntType = "";
180 case VesEventType::PNF_REGISTRATION:
181 evntType = EVENT_TYPE_5G;
183 case VesEventType::HEARTBEAT:
184 evntType = EVENT_TYPE_ORAN_COMPONENET;
187 O1_LOG("\nO1 VesCommonHeader : this VES msg Type support in getEvenType is \
194 /*******************************************************************
196 * @brief return priority of event
200 * Function : getPriority
203 * - send priority of event
205 * @params[in] IN - void
206 * @return value of string - success
207 * empty string - failure
209 * ****************************************************************/
211 string VesCommonHeader::getPriority()
213 /*Currently PNF_REGISTRATION only supported. This function must be updated
219 case VesEventType::PNF_REGISTRATION:
220 evntId = PRIORITY_LOW ;
222 case VesEventType::HEARTBEAT:
223 evntId = PRIORITY_LOW;
226 O1_LOG("\nO1 VesCommonHeader : This VES msg Type support in getPriority is \
235 /*******************************************************************
237 * @brief create Ves Event Name from Ves Event type
241 * Function : getEventName
244 * - create Ves Event Name from Ves Event type
246 * @params[in] IN - void
247 * @return value of string - success
248 * empty string - failure
249 * ****************************************************************/
251 string VesCommonHeader::getEventName()
253 /*Currently PNF_REGISTRATION only supported. This function must be updated
256 string evntName = "";
259 case VesEventType::PNF_REGISTRATION:
260 evntName = getEventTypeToStr() + "_" + EVENT_TYPE_5G;
262 case VesEventType::HEARTBEAT:
263 evntName = getEventTypeToStr() + "_" + EVENT_TYPE_ORAN_COMPONENET;
266 O1_LOG("\nO1 VesCommonHeader : This VES msg Type support in getEventName is \
273 /*******************************************************************
275 * @brief create Ves Event Name from Ves Event type
279 * Function : getReportingEntityName
282 * - create Ves Event Name from Ves Event type
284 * @params[in] IN - void
285 * @return value of string - success
286 * empty string - failure
287 * ****************************************************************/
289 string VesCommonHeader::getReportingEntityName()
291 /*Currently PNF_REGISTRATION only supported. This function must be updated
294 string evntName = "";
297 case VesEventType::PNF_REGISTRATION:
298 evntName = getSourceName();
301 O1_LOG("\nO1 VesCommonHeader : This VES msg Type support in \
302 getReportingEntityName is not available");
308 /*******************************************************************
310 * @brief create Ves Event Name from Ves Event type
314 * Function : getReportingEntityName
317 * - create Ves Event Name from Ves Event type
319 * @params[in] IN - void
320 * @return value of string - success
321 * empty string - failure
322 * ****************************************************************/
324 string VesCommonHeader::getSourceName()
326 /*Currently PNF_REGISTRATION only supported. This function need to be updated
331 /*******************************************************************
333 * @brief create Ves Event Name from Ves Event type
337 * Function : getNamingCode
340 * - Network function type: 4 characters (aligned with vnf and pnf
343 * @params[in] IN - void
344 * @return value of string - success
345 * empty string - failure
346 * ****************************************************************/
348 string VesCommonHeader::getNamingCode()
350 /*Currently PNF_REGISTRATION only supported. This function need to be updated
352 return NAMING_CODE_ODU;
357 /*******************************************************************
359 * @brief provide current epoch time
363 * Function : getEpochTime
366 * - provide current epoch time
369 * @return epoch time - success
371 * ****************************************************************/
373 uint64_t VesCommonHeader::getEpochTime()
375 uint64_t epochTimeInMicrosec = std::chrono::duration_cast \
376 <std::chrono::microseconds> \
377 (std::chrono::system_clock::now().time_since_epoch()).count();
378 return epochTimeInMicrosec;
381 /*******************************************************************
383 * @brief get current date-time
387 * Function : getCurrentTime
390 * - get current date-time
393 * @return time-date - success
395 * ****************************************************************/
397 string VesCommonHeader::getCurrentTime()
400 std::ostringstream oss;
402 strftime(dateStr, MAX_TIME_STR, "%F", localtime(&t));
407 /*******************************************************************
409 * @brief create Ves Event Name from Ves Event type
413 * Function : getEventName
416 * - create Ves Event Name from Ves Event type
418 * @params[in] IN - VesEventType , OUT - Ves Event Name
419 * @return ture - success
422 * ****************************************************************/
424 bool VesCommonHeader::prepare(cJSON *commonHeader, \
433 nextSequenceNo(); //update the sequence number for next message
434 if(JsonHelper::addNodeToObject(commonHeader, "domain", \
435 getEventTypeToStr().c_str()) == 0) {
438 else if ( JsonHelper::addNodeToObject(commonHeader, "eventId", \
439 getEventId().c_str()) == 0)
443 else if(JsonHelper::addNodeToObject(commonHeader, "eventName", \
444 getEventName().c_str()) == 0)
448 else if(JsonHelper::addNodeToObject(commonHeader, "eventType", \
449 getEventType().c_str()) == 0)
453 else if(JsonHelper::addNodeToObject(commonHeader, "sequence", \
454 getSequenceNo()) == 0)
458 else if(JsonHelper::addNodeToObject(commonHeader, "priority", \
459 getPriority().c_str()) == 0)
463 else if(JsonHelper::addNodeToObject(commonHeader, "reportingEntityId", \
468 else if(JsonHelper::addNodeToObject(commonHeader, "reportingEntityName", \
469 getReportingEntityName().c_str()) == 0)
473 else if(JsonHelper::addNodeToObject(commonHeader, "sourceId", \
478 else if(JsonHelper::addNodeToObject(commonHeader, "sourceName", \
479 getSourceName().c_str()) == 0)
483 else if(JsonHelper::addNodeToObject(commonHeader, "startEpochMicrosec", \
484 (double) getEpochTime()) == 0)
488 else if(JsonHelper::addNodeToObject(commonHeader, "lastEpochMicrosec", \
489 (double) getEpochTime()) == 0)
493 else if(JsonHelper::addNodeToObject(commonHeader, "nfNamingCode", \
494 getNamingCode().c_str()) == 0)
498 else if(JsonHelper::addNodeToObject(commonHeader, "nfVendorName", \
503 else if(JsonHelper::addNodeToObject(commonHeader, "timeZoneOffset", \
504 TIME_ZONE_00_00) == 0)
508 else if(JsonHelper::addNodeToObject(commonHeader, "version", \
513 else if(JsonHelper::addNodeToObject(commonHeader, "vesEventListenerVersion", \
514 VES_EVENT_LISTENER_7_2_1) == 0)
520 O1_LOG("\nO1 VesCommonHeader : VES common Header prepared");
526 /**********************************************************************
528 **********************************************************************/