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