RIC:1060: Change in PTL
[ric-plt/nodeb-rnib.git] / common / utils.go
1 //
2 // Copyright 2019 AT&T Intellectual Property
3 // Copyright 2019 Nokia
4 // Copyright 2023 Capgemini
5 //
6 // Licensed under the Apache License, Version 2.0 (the "License");
7 // you may not use this file except in compliance with the License.
8 // You may obtain a copy of the License at
9 //
10 //      http://www.apache.org/licenses/LICENSE-2.0
11 //
12 // Unless required by applicable law or agreed to in writing, software
13 // distributed under the License is distributed on an "AS IS" BASIS,
14 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 // See the License for the specific language governing permissions and
16 // limitations under the License.
17
18 //  This source code is part of the near-RT RIC (RAN Intelligent Controller)
19 //  platform project (RICP).
20
21 package common
22
23 import (
24         "fmt"
25 )
26
27 //SDL namespace used by the RNIB
28 const rnibNamespace = "e2Manager"
29
30 /*
31 ValidateAndBuildCellIdKey builds key according to the specified format returns the resulting string
32 */
33 func ValidateAndBuildCellIdKey(cellId string) (string, error) {
34         if cellId == "" {
35                 return "", NewValidationError("#utils.ValidateAndBuildCellIdKey - an empty cell id received")
36         }
37         return fmt.Sprintf("CELL:%s", cellId), nil
38 }
39
40 /*
41 ValidateAndBuildNrCellIdKey builds key according to the specified format returns the resulting string
42 */
43 func ValidateAndBuildNrCellIdKey(cellId string) (string, error) {
44         if cellId == "" {
45                 return "", NewValidationError("#utils.ValidateAndBuildNrCellIdKey - an empty cell id received")
46         }
47         return fmt.Sprintf("NRCELL:%s", cellId), nil
48 }
49
50 /*
51 ValidateAndBuildNodeBNameKey builds key according to the specified format returns the resulting string
52 */
53 func ValidateAndBuildNodeBNameKey(inventoryName string) (string, error) {
54         if inventoryName == "" {
55                 return "", NewValidationError("#utils.ValidateAndBuildNodeBNameKey - an empty inventory name received")
56         }
57         return fmt.Sprintf("RAN:%s", inventoryName), nil
58 }
59
60 /*
61 ValidateAndBuildNodeBIdKey builds key according to the specified format returns the resulting string
62 */
63 func ValidateAndBuildNodeBIdKey(nodeType string, plmnId string, nbId string, cuupId string, duId string) (string, error) {
64         if nodeType == "" {
65                 return "", NewValidationError("#utils.ValidateAndBuildNodeBIdKey - an empty node type received")
66         }
67         if plmnId == "" {
68                 return "", NewValidationError("#utils.ValidateAndBuildNodeBIdKey - an empty plmnId received")
69         }
70         if nbId == "" {
71                 return "", NewValidationError("#utils.ValidateAndBuildNodeBIdKey - an empty nbId received")
72         }
73         /*Note: Deployment where CU-UP and DU are combined
74           (but do not include the CP-CP) and have a single E2 connection
75            is not supported. The combination of CU-CP, CU-UP, and DU will be
76            treated as a single gNB and expect it to have only the
77            global gNB ID in its E2 Setup ID*/
78
79         if cuupId != "" && duId != ""{
80                 return fmt.Sprintf("%s:%s:%s", nodeType, plmnId, nbId), nil
81         }else if cuupId != "" {
82                 return fmt.Sprintf("%s:%s:%s:%s", nodeType, plmnId, nbId, cuupId), nil
83         }else if duId != "" {
84                 return fmt.Sprintf("%s:%s:%s:%s", nodeType, plmnId, nbId, duId ), nil
85         }else {
86         return fmt.Sprintf("%s:%s:%s", nodeType, plmnId, nbId), nil
87 }
88 }
89
90 /*
91 ValidateAndBuildCellNamePciKey builds key according to the specified format returns the resulting string
92 */
93 func ValidateAndBuildCellNamePciKey(inventoryName string, pci uint32) (string, error) {
94         if inventoryName == "" {
95                 return "", NewValidationError("#utils.ValidateAndBuildCellNamePciKey - an empty inventory name received")
96         }
97         return fmt.Sprintf("PCI:%s:%02x", inventoryName, pci), nil
98 }
99
100 func ValidateAndBuildRanLoadInformationKey(inventoryName string) (string, error) {
101
102         if inventoryName == "" {
103                 return "", NewValidationError("#utils.ValidateAndBuildRanLoadInformationKey - an empty inventory name received")
104         }
105
106         return fmt.Sprintf("LOAD:%s", inventoryName), nil
107 }
108
109 func ValidateAndBuildE2TInstanceKey(address string) (string, error) {
110
111         if address == "" {
112                 return "", NewValidationError("#utils.ValidateAndBuildE2TInstanceKey - an empty E2T address received")
113         }
114
115         return fmt.Sprintf("E2TInstance:%s", address), nil
116 }
117
118 func BuildGeneralConfigurationKey() string {
119         return "GENERAL"
120 }
121
122 func MapE2TAddressesToKeys(addresses []string) []string {
123
124         keys := []string{}
125         for _, v := range addresses {
126                 if len(v) != 0 {
127                         keys = append(keys, fmt.Sprintf("E2TInstance:%s", v))
128                 }
129         }
130
131         return keys
132 }
133
134 //GetRNibNamespace returns namespace used by the RNIB in SDL.
135 func GetRNibNamespace() string {
136         return rnibNamespace
137 }