1cae140d3e28cbdbc953ab05b79d3864afe666eb
[ric-plt/nodeb-rnib.git] / common / utils.go
1 //
2 // Copyright 2019 AT&T Intellectual Property
3 // Copyright 2019 Nokia
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 //  This source code is part of the near-RT RIC (RAN Intelligent Controller)
18 //  platform project (RICP).
19
20 package common
21
22 import (
23         "fmt"
24 )
25
26 //SDL namespace used by the RNIB
27 const rnibNamespace = "e2Manager"
28
29 /*
30 ValidateAndBuildCellIdKey builds key according to the specified format returns the resulting string
31 */
32 func ValidateAndBuildCellIdKey(cellId string) (string, error) {
33         if cellId == "" {
34                 return "", NewValidationError("#utils.ValidateAndBuildCellIdKey - an empty cell id received")
35         }
36         return fmt.Sprintf("CELL:%s", cellId), nil
37 }
38
39 /*
40 ValidateAndBuildNrCellIdKey builds key according to the specified format returns the resulting string
41 */
42 func ValidateAndBuildNrCellIdKey(cellId string) (string, error) {
43         if cellId == "" {
44                 return "", NewValidationError("#utils.ValidateAndBuildNrCellIdKey - an empty cell id received")
45         }
46         return fmt.Sprintf("NRCELL:%s", cellId), nil
47 }
48
49 /*
50 ValidateAndBuildNodeBNameKey builds key according to the specified format returns the resulting string
51 */
52 func ValidateAndBuildNodeBNameKey(inventoryName string) (string, error) {
53         if inventoryName == "" {
54                 return "", NewValidationError("#utils.ValidateAndBuildNodeBNameKey - an empty inventory name received")
55         }
56         return fmt.Sprintf("RAN:%s", inventoryName), nil
57 }
58
59 /*
60 ValidateAndBuildNodeBIdKey builds key according to the specified format returns the resulting string
61 */
62 func ValidateAndBuildNodeBIdKey(nodeType string, plmnId string, nbId string) (string, error) {
63         if nodeType == "" {
64                 return "", NewValidationError("#utils.ValidateAndBuildNodeBIdKey - an empty node type received")
65         }
66         if plmnId == "" {
67                 return "", NewValidationError("#utils.ValidateAndBuildNodeBIdKey - an empty plmnId received")
68         }
69         if nbId == "" {
70                 return "", NewValidationError("#utils.ValidateAndBuildNodeBIdKey - an empty nbId received")
71         }
72         return fmt.Sprintf("%s:%s:%s", nodeType, plmnId, nbId), nil
73 }
74
75 /*
76 ValidateAndBuildCellNamePciKey builds key according to the specified format returns the resulting string
77 */
78 func ValidateAndBuildCellNamePciKey(inventoryName string, pci uint32) (string, error) {
79         if inventoryName == "" {
80                 return "", NewValidationError("#utils.ValidateAndBuildCellNamePciKey - an empty inventory name received")
81         }
82         return fmt.Sprintf("PCI:%s:%02x", inventoryName, pci), nil
83 }
84
85 func ValidateAndBuildRanLoadInformationKey(inventoryName string) (string, error) {
86
87         if inventoryName == "" {
88                 return "", NewValidationError("#utils.ValidateAndBuildRanLoadInformationKey - an empty inventory name received")
89         }
90
91         return fmt.Sprintf("LOAD:%s", inventoryName), nil
92 }
93
94 func ValidateAndBuildE2TInstanceKey(address string) (string, error) {
95
96         if address == "" {
97                 return "", NewValidationError("#utils.ValidateAndBuildE2TInstanceKey - an empty E2T address received")
98         }
99
100         return fmt.Sprintf("E2TInstance:%s", address), nil
101 }
102
103 func BuildGeneralConfigurationKey() string {
104         return "GENERAL"
105 }
106
107 func MapE2TAddressesToKeys(addresses []string) []string {
108
109         keys := []string{}
110         for _, v := range addresses {
111                 if len(v) != 0 {
112                         keys = append(keys, fmt.Sprintf("E2TInstance:%s", v))
113                 }
114         }
115
116         return keys
117 }
118
119 //GetRNibNamespace returns namespace used by the RNIB in SDL.
120 func GetRNibNamespace() string {
121         return rnibNamespace
122 }