Merge "Cell and Network slicing configuration over o1. IssueID: ODUHIGH-383"
[o-du/l2.git] / src / o1 / ves / SliceMeasurementEvent.cpp
1 /*******************************************************************************
2 ################################################################################
3 #   Copyright (c) [2020-2021] [HCL Technologies Ltd.]                          #
4 #                                                                              #
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                                    #
8 #                                                                              #
9 #       http://www.apache.org/licenses/LICENSE-2.0                             #
10 #                                                                              #
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 *******************************************************************************/
18
19 /* This file contains SliceMeasurementEvent class for  preparing the
20    Slice Measurement VES Event*/
21
22 #include "SliceMeasurementEvent.hpp"
23 #include "JsonHelper.hpp"
24 #include "PmInterface.h"
25
26 #define MEASUREMENT_INTERVAL 60
27 #define MEASUREMENT_FIELDS_VERSION 4.0
28
29 /* Constructor*/
30 SliceMeasurementEvent::SliceMeasurementEvent() 
31                         : PerfMeasurementEvent(VesEventType::PM_SLICE)
32 {
33 }
34 /* Default destructor*/
35 SliceMeasurementEvent::~SliceMeasurementEvent()
36 {
37 }
38
39 /*******************************************************************
40 *
41 * @brief prepare Slice Measurement Fields
42 *
43 * @details
44 *
45 * Function : prepareEventFields
46 *
47 * Functionality:
48 * - prepare Slice Measurement Fields  in json format
49 *
50 * @params[in] IN - const pointer of Message type
51 * @return true - success
52 *         false - failure
53 *
54 * ****************************************************************/
55
56 bool SliceMeasurementEvent::prepareEventFields(const Message* msg)
57 {
58
59     const SliceMetrics* sliceMetrics = dynamic_cast<const SliceMetrics*> (msg);
60     
61     bool ret = true;
62     cJSON *measurementFields = this->mVesEventFields;
63
64     if(JsonHelper::addNodeToObject(measurementFields, \
65                                     "measurementFieldsVersion", \
66                                     MEASUREMENT_FIELDS_VERSION) == 0)
67     {
68         ret = false;
69     }
70
71     cJSON *networkSliceArray = JsonHelper::createArray();
72
73     if(networkSliceArray == 0)
74     {
75         ret = false;
76     }
77
78     else if (JsonHelper::addJsonNodeToObject(measurementFields, \
79                                             "networkSliceArray", \
80                                             networkSliceArray) == 0)
81     {
82         ret = false;
83     }
84     else if(ret)
85     {
86         const vector<SliceMetricRecord>& sliceList = sliceMetrics->getSliceMetrics();
87         for (size_t i{0}; i < sliceList.size(); i++)            
88         {
89             cJSON *Slice = JsonHelper::createNode();
90            char networkId[12];
91            sprintf(networkId,"%d%x\n", sliceList[i].networkSliceIdentifier.sst,sliceList[i].networkSliceIdentifier.sd);
92             //O1_LOG("sliceList[i].networkSliceIdentifier  %s",networkId);
93             if(Slice == 0)
94             {
95                 ret = false;
96             }
97             else if (JsonHelper::addJsonNodeToArray(networkSliceArray, Slice) == 0)
98             {
99                 ret = false;
100             }
101
102             else if (JsonHelper::addNodeToObject(Slice, \
103                                                 "DRB.UEThpDl.SNSSAI", \
104                                                  sliceList[i].DRB_UEThpDl_SNSSAI) == 0)
105             {
106                 ret = false;
107             }
108
109             else if (JsonHelper::addNodeToObject(Slice, \
110                                                 "DRB.UEThpUl.SNSSAI", \
111                                                 sliceList[i].DRB_UEThpUl_SNSSAI) == 0)
112             {
113                 ret = false;
114             }
115             else if (JsonHelper::addNodeToObject(Slice, \
116                                                 "networkSliceIdentifier", \
117                                                  networkId) == 0)
118             {
119                 ret = false;
120             }
121         }
122     }
123
124     if(JsonHelper::addNodeToObject(measurementFields, \
125                                    "measurementInterval", \
126                                     MEASUREMENT_INTERVAL) == 0)
127     {
128         ret = false;
129     }
130
131     return ret;
132 }
133
134 /**********************************************************************
135          End of file
136 **********************************************************************/