ab219bb5194df239671c6e679e501fae6a086690
[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             if(Slice == 0)
91             {
92                 ret = false;
93             }
94             else if (JsonHelper::addJsonNodeToArray(networkSliceArray, Slice) == 0)
95             {
96                 ret = false;
97             }
98
99             else if (JsonHelper::addNodeToObject(Slice, \
100                                                 "DRB.UEThpDl.SNSSAI", \
101                                                  sliceList[i].DRB_UEThpDl_SNSSAI) == 0)
102             {
103                 ret = false;
104             }
105
106             else if (JsonHelper::addNodeToObject(Slice, \
107                                                 "DRB.UEThpUl.SNSSAI", \
108                                                 sliceList[i].DRB_UEThpUl_SNSSAI) == 0)
109             {
110                 ret = false;
111             }
112             else if (JsonHelper::addNodeToObject(Slice, \
113                                                 "networkSliceIdentifier", \
114                                                 sliceList[i].networkSliceIdentifier) == 0)
115             {
116                 ret = false;
117             }
118         }
119     }
120
121     if(JsonHelper::addNodeToObject(measurementFields, \
122                                    "measurementInterval", \
123                                     MEASUREMENT_INTERVAL) == 0)
124     {
125         ret = false;
126     }
127
128     return ret;
129 }
130
131 /**********************************************************************
132          End of file
133 **********************************************************************/