[RIC-584] - Validate setup from network and antenna type in ENB REST APIs
[ric-plt/e2mgr.git] / E2Manager / managers / nodeb_validator.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 managers
21
22 import (
23         "gerrit.o-ran-sc.org/r/ric-plt/nodeb-rnib.git/entities"
24         "github.com/pkg/errors"
25 )
26
27 type NodebValidator struct {
28 }
29
30 func NewNodebValidator() *NodebValidator {
31         return &NodebValidator{}
32 }
33
34 func (h *NodebValidator) IsGnbValid(gnb *entities.Gnb) error {
35         if len(gnb.ServedNrCells) == 0 {
36                 return errors.New("gnb.servedNrCells")
37         }
38
39         for _, servedNrCell := range gnb.ServedNrCells {
40                 if servedNrCell.ServedNrCellInformation == nil {
41                         return errors.New("gnb.servedNrCellInformation")
42                 }
43
44                 err := isServedNrCellInformationValid(servedNrCell.ServedNrCellInformation)
45
46                 if err != nil {
47                         return err
48                 }
49
50                 if len(servedNrCell.NrNeighbourInfos) == 0 {
51                         continue
52                 }
53
54                 for _, nrNeighbourInformation := range servedNrCell.NrNeighbourInfos {
55
56                         err := isNrNeighbourInformationValid(nrNeighbourInformation)
57
58                         if err != nil {
59                                 return err
60                         }
61
62                 }
63         }
64
65         return nil
66 }
67
68 func isServedNrCellInformationValid(servedNrCellInformation *entities.ServedNRCellInformation) error {
69         if servedNrCellInformation.CellId == "" {
70                 return errors.New("servedNrCellInformation.cellId")
71         }
72
73         if servedNrCellInformation.ChoiceNrMode == nil {
74                 return errors.New("servedNrCellInformation.choiceNrMode")
75         }
76
77         if servedNrCellInformation.NrMode == entities.Nr_UNKNOWN {
78                 return errors.New("servedNrCellInformation.nrMode")
79         }
80
81         if len(servedNrCellInformation.ServedPlmns) == 0 {
82                 return errors.New("servedNrCellInformation.servedPlmns")
83         }
84
85         return isServedNrCellInfoChoiceNrModeValid(servedNrCellInformation.ChoiceNrMode)
86 }
87
88 func isServedNrCellInfoChoiceNrModeValid(choiceNrMode *entities.ServedNRCellInformation_ChoiceNRMode) error {
89         if choiceNrMode.Fdd != nil {
90                 return isServedNrCellInfoFddValid(choiceNrMode.Fdd)
91         }
92
93         if choiceNrMode.Tdd != nil {
94                 return isServedNrCellInfoTddValid(choiceNrMode.Tdd)
95         }
96
97         return errors.New("servedNrCellInformation.choiceNrMode.fdd / servedNrCellInformation.choiceNrMode.tdd")
98 }
99
100 func isServedNrCellInfoTddValid(tdd *entities.ServedNRCellInformation_ChoiceNRMode_TddInfo) error {
101         return nil
102 }
103
104 func isServedNrCellInfoFddValid(fdd *entities.ServedNRCellInformation_ChoiceNRMode_FddInfo) error {
105         return nil
106 }
107
108 func isNrNeighbourInformationValid(nrNeighbourInformation *entities.NrNeighbourInformation) error {
109         if nrNeighbourInformation.NrCgi == "" {
110                 return errors.New("nrNeighbourInformation.nrCgi")
111         }
112
113         if nrNeighbourInformation.ChoiceNrMode == nil {
114                 return errors.New("nrNeighbourInformation.choiceNrMode")
115         }
116
117         if nrNeighbourInformation.NrMode == entities.Nr_UNKNOWN {
118                 return errors.New("nrNeighbourInformation.nrMode")
119         }
120
121         return isNrNeighbourInfoChoiceNrModeValid(nrNeighbourInformation.ChoiceNrMode)
122 }
123
124 func isNrNeighbourInfoChoiceNrModeValid(choiceNrMode *entities.NrNeighbourInformation_ChoiceNRMode) error {
125         if choiceNrMode.Fdd != nil {
126                 return isNrNeighbourInfoFddValid(choiceNrMode.Fdd)
127         }
128
129         if choiceNrMode.Tdd != nil {
130                 return isNrNeighbourInfoTddValid(choiceNrMode.Tdd)
131         }
132
133         return errors.New("nrNeighbourInformation.choiceNrMode.fdd / nrNeighbourInformation.choiceNrMode.tdd")
134 }
135
136 func isNrNeighbourInfoTddValid(tdd *entities.NrNeighbourInformation_ChoiceNRMode_TddInfo) error {
137         return nil
138 }
139
140 func isNrNeighbourInfoFddValid(fdd *entities.NrNeighbourInformation_ChoiceNRMode_FddInfo) error {
141         return nil
142 }
143
144 func (h *NodebValidator) IsEnbValid(enb *entities.Enb) error {
145         if enb.EnbType == entities.EnbType_UNKNOWN_ENB_TYPE {
146                 return errors.New("enb.enbType")
147         }
148
149         if enb.ServedCells == nil || len(enb.ServedCells) == 0 {
150                 return errors.New("enb.servedCells")
151         }
152
153         for _, servedCell := range enb.ServedCells {
154                 err := isServedCellValid(servedCell)
155
156                 if err != nil {
157                         return err
158                 }
159         }
160
161         return nil
162 }
163
164 func (h *NodebValidator) IsNgEnbType(enbType entities.EnbType) bool {
165         return enbType == entities.EnbType_LONG_MACRO_NG_ENB ||
166                 enbType == entities.EnbType_MACRO_NG_ENB ||
167                 enbType == entities.EnbType_SHORT_MACRO_NG_ENB
168 }
169
170 func isServedCellValid(servedCell *entities.ServedCellInfo) error {
171
172         if servedCell.CellId == "" {
173                 return errors.New("servedCell.cellId")
174         }
175
176         if servedCell.EutraMode == entities.Eutra_UNKNOWN {
177                 return errors.New("servedCell.eutraMode")
178         }
179
180         if servedCell.Tac == "" {
181                 return errors.New("servedCell.tac")
182         }
183
184         if servedCell.BroadcastPlmns == nil || len(servedCell.BroadcastPlmns) == 0 {
185                 return errors.New("servedCell.broadcastPlmns")
186         }
187
188         if servedCell.ChoiceEutraMode == nil {
189                 return errors.New("servedCell.choiceEutraMode")
190         }
191
192         return isChoiceEutraModeValid(servedCell.ChoiceEutraMode)
193 }
194
195 func isChoiceEutraModeValid(choiceEutraMode *entities.ChoiceEUTRAMode) error {
196         if choiceEutraMode.Fdd != nil {
197                 return isFddInfoValid(choiceEutraMode.Fdd)
198         }
199
200         if choiceEutraMode.Tdd != nil {
201                 return isTddInfoValid(choiceEutraMode.Tdd)
202         }
203
204         return errors.New("servedCell.fdd / servedCell.tdd")
205 }
206
207 func isTddInfoValid(tdd *entities.TddInfo) error {
208         return nil
209 }
210
211 func isFddInfoValid(fdd *entities.FddInfo) error {
212         return nil
213 }