X-Git-Url: https://gerrit.o-ran-sc.org/r/gitweb?a=blobdiff_plain;f=src%2Fo1%2Fves%2FSliceMeasurementEventStdDef.cpp;fp=src%2Fo1%2Fves%2FSliceMeasurementEventStdDef.cpp;h=1fccb6f5de61c6b069141f39aad3e17ea4c4dab1;hb=b113656b5f48fbe9769e6cb7cea172aa930446ba;hp=0000000000000000000000000000000000000000;hpb=e2417efa29f0d317a3ed1044ee20cc14df32e1d3;p=o-du%2Fl2.git diff --git a/src/o1/ves/SliceMeasurementEventStdDef.cpp b/src/o1/ves/SliceMeasurementEventStdDef.cpp new file mode 100644 index 000000000..1fccb6f5d --- /dev/null +++ b/src/o1/ves/SliceMeasurementEventStdDef.cpp @@ -0,0 +1,231 @@ +/******************************************************************************* +################################################################################ +# Copyright (c) [2022] [HCL Technologies Ltd.] # +# # +# Licensed under the Apache License, Version 2.0 (the "License"); # +# you may not use this file except in compliance with the License. # +# You may obtain a copy of the License at # +# # +# http://www.apache.org/licenses/LICENSE-2.0 # +# # +# Unless required by applicable law or agreed to in writing, software # +# distributed under the License is distributed on an "AS IS" BASIS, # +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # +# See the License for the specific language governing permissions and # +# limitations under the License. # +################################################################################ +*******************************************************************************/ + +/* This file contains macros and functions to support the preparation of pnf + Registration VES Event*/ + +#include +#include +#include +#include +#include "JsonHelper.hpp" +#include "SliceMeasurementEventStdDef.hpp" +#include "CmInterface.h" + +extern NRCellDU cellParams; + +/* Default constructor*/ +SliceMeasurementEventStdDef::SliceMeasurementEventStdDef() + : PerfMeasurementEvent(VesEventType::PM_SLICE) +{ + +} + +/* Default Destructor*/ +SliceMeasurementEventStdDef::~SliceMeasurementEventStdDef() +{ + +} + +/******************************************************************* + * + * @brief Returns ISO time String + * + * @details + * + * Function :getISOEventTime + * + * Functionality: + * - Returns ISO time String + * + * @params[in] IN - void + * @return value of string - success + * empty string - failure + * + * ****************************************************************/ + +std::string SliceMeasurementEventStdDef::getISOEventTime() { + auto now = std::chrono::system_clock::now(); + auto itt = std::chrono::system_clock::to_time_t(now); + std::ostringstream os; + os << std::put_time(gmtime(&itt), "%FT%TZ"); + return os.str(); +} + +/******************************************************************* +* +* @brief prepare Stnd Slice Measurement path +* +* @details +* +* Function : getMeaspath +* +* Functionality: +* - prepare Stnd Slice Measurement path +* +* @params[in] IN - void +* @return true - path on success +* false - failure +* +* ****************************************************************/ +std::string SliceMeasurementEventStdDef::getMeasPath(string str, int sd, int sst) +{ + O1_LOG("\n O1 SliceMeasurementEventStdDef cellLocalId :%d",cellParams.cellLocalId); + std::ostringstream os; + os<<"/"< (msg); + + bool ret = true; + + cJSON* stndDefinedFields = this->mVesEventFields; + if(JsonHelper::addNodeToObject(stndDefinedFields, "stndDefinedFieldsVersion",\ + STND_DEFINED_FEILD_VERSION) == 0) + { + ret = false; + } + else if(JsonHelper::addNodeToObject(stndDefinedFields, "schemaReference",\ + SLICE_SCHEMA) == 0) + { + ret = false; + } + + cJSON* data = JsonHelper::createNode(); + if(data == 0) + { + O1_LOG("\nO1 SliceMeasurementEventStdDef : could not create data JSON object"); + return false; + } + else if(JsonHelper::addJsonNodeToObject(stndDefinedFields, "data", \ + data) == 0) { + ret = false; + } + else if(JsonHelper::addNodeToObject(data, "id", SLICE_ID) == 0) + { + ret = false; + } + else if(JsonHelper::addNodeToObject(data, "start-time",\ + getISOEventTime().c_str()) == 0) + { + ret = false; + } + else if(JsonHelper::addNodeToObject(data, "administrative-state",\ + ADMINISTRATIVE_STATE) == 0) + { + ret = false; + } + else if(JsonHelper::addNodeToObject(data, "operational-state",\ + OPERATIONAL_STATE) == 0) + { + ret = false; + } + else if(JsonHelper::addNodeToObject(data, "user-label", USER_LABEL) == 0) + { + ret = false; + } + else if(JsonHelper::addNodeToObject(data, "job-tag", "") == 0) + { + ret = false; + } + else if(JsonHelper::addNodeToObject(data, "granularity-period",\ + GRANULARITY_PERIOD) == 0) + { + ret = false; + } + + cJSON *measure= cJSON_CreateArray(); + if (measure == NULL) + { + ret = false; + } + else if(cJSON_AddItemToObject(data, "measurements", measure) == 0) + { + ret = false; + } + + else if(ret) + { + const vector& sliceList = sliceMetrics->getSliceMetrics(); + for (size_t i{0}; i < sliceList.size(); i++) + { + for(int j=0;j