baf5d233636def00d99c218cfc34500755f538ac
[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 package common
18
19 import (
20         "fmt"
21 )
22
23 /*
24 ValidateAndBuildCellIdKey builds key according to the specified format returns the resulting string
25 */
26 func ValidateAndBuildCellIdKey(cellId string) (string, error) {
27         if cellId == "" {
28                 return "", NewValidationError("#utils.ValidateAndBuildCellIdKey - an empty cell id received")
29         }
30         return fmt.Sprintf("CELL:%s", cellId), nil
31 }
32
33 /*
34 ValidateAndBuildNrCellIdKey builds key according to the specified format returns the resulting string
35 */
36 func ValidateAndBuildNrCellIdKey(cellId string) (string, error) {
37         if cellId == "" {
38                 return "", NewValidationError("#utils.ValidateAndBuildNrCellIdKey - an empty cell id received")
39         }
40         return fmt.Sprintf("NRCELL:%s", cellId), nil
41 }
42
43 /*
44 ValidateAndBuildNodeBNameKey builds key according to the specified format returns the resulting string
45 */
46 func ValidateAndBuildNodeBNameKey(inventoryName string) (string, error) {
47         if inventoryName == "" {
48                 return "", NewValidationError("#utils.ValidateAndBuildNodeBNameKey - an empty inventory name received")
49         }
50         return fmt.Sprintf("RAN:%s", inventoryName), nil
51 }
52
53 /*
54 ValidateAndBuildNodeBIdKey builds key according to the specified format returns the resulting string
55 */
56 func ValidateAndBuildNodeBIdKey(nodeType string, plmnId string, nbId string) (string, error) {
57         if nodeType == "" {
58                 return "", NewValidationError("#utils.ValidateAndBuildNodeBIdKey - an empty node type received")
59         }
60         if plmnId == "" {
61                 return "", NewValidationError("#utils.ValidateAndBuildNodeBIdKey - an empty plmnId received")
62         }
63         if nbId == "" {
64                 return "", NewValidationError("#utils.ValidateAndBuildNodeBIdKey - an empty nbId received")
65         }
66         return fmt.Sprintf("%s:%s:%s", nodeType, plmnId, nbId), nil
67 }
68
69 /*
70 ValidateAndBuildCellNamePciKey builds key according to the specified format returns the resulting string
71 */
72 func ValidateAndBuildCellNamePciKey(inventoryName string, pci uint32) (string, error) {
73         if inventoryName == "" {
74                 return "", NewValidationError("#utils.ValidateAndBuildCellNamePciKey - an empty inventory name received")
75         }
76         return fmt.Sprintf("PCI:%s:%02x", inventoryName, pci), nil
77 }
78
79 func ValidateAndBuildRanLoadInformationKey(inventoryName string) (string, error) {
80
81         if inventoryName == "" {
82                 return "", NewValidationError("#utils.ValidateAndBuildRanLoadInformationKey - an empty inventory name received")
83         }
84
85         return fmt.Sprintf("LOAD:%s", inventoryName), nil
86 }