2 // ========================LICENSE_START=================================
5 // Copyright (C) 2021: Nordix Foundation
7 // Licensed under the Apache License, Version 2.0 (the "License");
8 // you may not use this file except in compliance with the License.
9 // You may obtain a copy of the License at
11 // http://www.apache.org/licenses/LICENSE-2.0
13 // Unless required by applicable law or agreed to in writing, software
14 // distributed under the License is distributed on an "AS IS" BASIS,
15 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 // See the License for the specific language governing permissions and
17 // limitations under the License.
18 // ========================LICENSE_END===================================
29 "oransc.org/usecase/oduclosedloop/internal/structures"
32 type StdDefinedMessage struct {
33 Event Event `json:"event"`
37 CommonEventHeader CommonEventHeader `json:"commonEventHeader"`
38 StndDefinedFields StndDefinedFields `json:"stndDefinedFields"`
41 type CommonEventHeader struct {
42 Domain string `json:"domain"`
43 StndDefinedNamespace string `json:"stndDefinedNamespace"`
46 type StndDefinedFields struct {
47 StndDefinedFieldsVersion string `json:"stndDefinedFieldsVersion"`
48 SchemaReference string `json:"schemaReference"`
49 Data Data `json:"data"`
53 DataId string `json:"id"`
54 Measurements []Measurement `json:"measurements"`
57 type Measurement struct {
58 MeasurementTypeInstanceReference string `json:"measurement-type-instance-reference"`
59 Value int `json:"value"`
60 Unit string `json:"unit"`
63 func (message StdDefinedMessage) GetMeasurements() []Measurement {
64 return message.Event.StndDefinedFields.Data.Measurements
67 func (meas Measurement) CreateSliceMetric() *structures.SliceMetric {
69 var duid, cellid string
72 typeParts := strings.Split(meas.MeasurementTypeInstanceReference, "/")
73 for _, part := range typeParts {
74 if strings.Contains(part, "distributed-unit-functions") {
75 duid = getValueInsideQuotes(part)
77 } else if strings.Contains(part, "cell[") {
78 cellid = getValueInsideQuotes(part)
80 } else if strings.Contains(part, "performance-measurement-type") {
81 pmName = getValueInsideQuotes(part)
83 } else if strings.Contains(part, "slice-differentiator") {
84 sd = getPropertyNumber(part)
86 } else if strings.Contains(part, "slice-differentiator") {
87 res, err := strconv.Atoi(getValueInsideQuotes(part))
95 sm := structures.NewSliceMetric(duid, cellid, sd, sst)
96 sm.PM[pmName] = meas.Value
100 func getValueInsideQuotes(text string) string {
101 re := regexp.MustCompile(`\'(.*?)\'`)
103 match := re.FindAllString(text, -1)
106 res = strings.Trim(match[0], "'")
111 func getPropertyNumber(text string) int {
112 re := regexp.MustCompile("[0-9]+")
113 match := re.FindAllString(text, -1)
117 res, err = strconv.Atoi(match[0])