1 /*******************************************************************************
2 ################################################################################
3 # Copyright (c) [2022] [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 macros and functions to support the preparation of pnf
20 Registration VES Event*/
26 #include "JsonHelper.hpp"
27 #include "SliceMeasurementEventStdDef.hpp"
28 #include "CmInterface.h"
30 extern NRCellDU cellParams;
32 /* Default constructor*/
33 SliceMeasurementEventStdDef::SliceMeasurementEventStdDef()
34 : PerfMeasurementEvent(VesEventType::PM_SLICE)
39 /* Default Destructor*/
40 SliceMeasurementEventStdDef::~SliceMeasurementEventStdDef()
45 /*******************************************************************
47 * @brief Returns ISO time String
51 * Function :getISOEventTime
54 * - Returns ISO time String
56 * @params[in] IN - void
57 * @return value of string - success
58 * empty string - failure
60 * ****************************************************************/
62 std::string SliceMeasurementEventStdDef::getISOEventTime() {
63 auto now = std::chrono::system_clock::now();
64 auto itt = std::chrono::system_clock::to_time_t(now);
65 std::ostringstream os;
66 os << std::put_time(gmtime(&itt), "%FT%TZ");
70 /*******************************************************************
72 * @brief prepare Stnd Slice Measurement path
76 * Function : getMeaspath
79 * - prepare Stnd Slice Measurement path
81 * @params[in] IN - void
82 * @return true - path on success
85 * ****************************************************************/
86 std::string SliceMeasurementEventStdDef::getMeasPath(string str, int sd, int sst)
88 O1_LOG("\n O1 SliceMeasurementEventStdDef cellLocalId :%d",cellParams.cellLocalId);
89 std::ostringstream os;
90 os<<"/"<<YANG_NAME<<":network-function/distributed-unit-functions[id='"\
91 << ODU_HIGH <<"']/cell[id='"<<cellParams.cellLocalId <<\
92 "']/supported-measurements[performance-measurement-type='user-equipment-average-throughput-"\
93 <<str<<"']/supported-snssai-subcounter-instances[slice-differentiator='"\
94 <<sd<<"'][slice-service-type='"<<sst<<"']" ;
99 /*******************************************************************
101 * @brief prepare Stnd Slice Measurement Fields
105 * Function : prepareEventFields
108 * - prepare Stnd Slice Measurement Fields in json format
110 * @params[in] IN - const pointer of Message type
111 * @return true - success
114 * ****************************************************************/
116 bool SliceMeasurementEventStdDef::prepareEventFields(const Message* msg)
119 const SliceMetrics* sliceMetrics = dynamic_cast<const SliceMetrics*> (msg);
123 cJSON* stndDefinedFields = this->mVesEventFields;
124 if(JsonHelper::addNodeToObject(stndDefinedFields, "stndDefinedFieldsVersion",\
125 STND_DEFINED_FEILD_VERSION) == 0)
129 else if(JsonHelper::addNodeToObject(stndDefinedFields, "schemaReference",\
135 cJSON* data = JsonHelper::createNode();
138 O1_LOG("\nO1 SliceMeasurementEventStdDef : could not create data JSON object");
141 else if(JsonHelper::addJsonNodeToObject(stndDefinedFields, "data", \
145 else if(JsonHelper::addNodeToObject(data, "id", SLICE_ID) == 0)
149 else if(JsonHelper::addNodeToObject(data, "start-time",\
150 getISOEventTime().c_str()) == 0)
154 else if(JsonHelper::addNodeToObject(data, "administrative-state",\
155 ADMINISTRATIVE_STATE) == 0)
159 else if(JsonHelper::addNodeToObject(data, "operational-state",\
160 OPERATIONAL_STATE) == 0)
164 else if(JsonHelper::addNodeToObject(data, "user-label", USER_LABEL) == 0)
168 else if(JsonHelper::addNodeToObject(data, "job-tag", "") == 0)
172 else if(JsonHelper::addNodeToObject(data, "granularity-period",\
173 GRANULARITY_PERIOD) == 0)
178 cJSON *measure= cJSON_CreateArray();
183 else if(cJSON_AddItemToObject(data, "measurements", measure) == 0)
190 const vector<SliceMetricRecord>& sliceList = sliceMetrics->getSliceMetrics();
191 for (size_t i{0}; i < sliceList.size(); i++)
193 for(int j=0;j<MAX_THP_TYPE;j++)
195 cJSON* arr = JsonHelper::createNode();
196 cJSON_AddItemToArray(measure,arr);
203 value = cJSON_CreateNumber(sliceList[i].DRB_UEThpDl_SNSSAI);
208 value = cJSON_CreateNumber(sliceList[i].DRB_UEThpUl_SNSSAI);
211 if(JsonHelper::addNodeToObject(arr, MEAS_REF, getMeasPath(str,\
212 sliceList[i].networkSliceIdentifier.sd,\
213 sliceList[i].networkSliceIdentifier.sst).c_str()) == 0)
218 cJSON_AddItemToObject(arr,"value", value);
220 cJSON *unit = cJSON_CreateString(THROUGHPUT_UNIT);
221 cJSON_AddItemToObject(arr,"unit", unit);
229 /**********************************************************************
231 **********************************************************************/