Added ranfunctionOid for E2APv1.1 for e2setup req.
[ric-plt/e2mgr.git] / E2Manager / models / e2_setup_request_message.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 models
21
22 import (
23         "encoding/xml"
24         "strings"
25
26         "gerrit.o-ran-sc.org/r/ric-plt/nodeb-rnib.git/entities"
27 )
28
29 type Gnb struct {
30         Text        string `xml:",chardata"`
31         GlobalGNBID struct {
32                 Text   string `xml:",chardata"`
33                 PlmnID string `xml:"plmn-id"`
34                 GnbID  struct {
35                         Text  string `xml:",chardata"`
36                         GnbID string `xml:"gnb-ID"`
37                 } `xml:"gnb-id"`
38         } `xml:"global-gNB-ID"`
39 }
40
41 type EnGnb struct {
42         Text        string `xml:",chardata"`
43         GlobalGNBID struct {
44                 Text   string `xml:",chardata"`
45                 PlmnID string `xml:"pLMN-Identity"`
46                 GnbID  struct {
47                         Text  string `xml:",chardata"`
48                         GnbID string `xml:"gNB-ID"`
49                 } `xml:"gNB-ID"`
50         } `xml:"global-gNB-ID"`
51 }
52
53 type NgEnbId struct {
54         Text            string `xml:",chardata"`
55         EnbIdMacro      string `xml:"enb-ID-macro"`
56         EnbIdShortMacro string `xml:"enb-ID-shortmacro"`
57         EnbIdLongMacro  string `xml:"enb-ID-longmacro"`
58 }
59
60 type NgEnb struct {
61         Text          string `xml:",chardata"`
62         GlobalNgENBID struct {
63                 Text   string  `xml:",chardata"`
64                 PlmnID string  `xml:"plmn-id"`
65                 EnbID  NgEnbId `xml:"enb-id"`
66         } `xml:"global-ng-eNB-ID"`
67 }
68
69 type EnbId struct {
70         Text            string `xml:",chardata"`
71         MacroEnbId      string `xml:"macro-eNB-ID"`
72         HomeEnbId       string `xml:"home-eNB-ID"`
73         ShortMacroEnbId string `xml:"short-Macro-eNB-ID"`
74         LongMacroEnbId  string `xml:"long-Macro-eNB-ID"`
75 }
76
77 type Enb struct {
78         Text        string `xml:",chardata"`
79         GlobalENBID struct {
80                 Text   string `xml:",chardata"`
81                 PlmnID string `xml:"pLMN-Identity"`
82                 EnbID  EnbId  `xml:"eNB-ID"`
83         } `xml:"global-eNB-ID"`
84 }
85
86 type GlobalE2NodeId struct {
87         Text  string `xml:",chardata"`
88         GNB   Gnb    `xml:"gNB"`
89         EnGNB EnGnb  `xml:"en-gNB"`
90         NgENB NgEnb  `xml:"ng-eNB"`
91         ENB   Enb    `xml:"eNB"`
92 }
93
94 type E2SetupRequest struct {
95         Text        string `xml:",chardata"`
96         ProtocolIEs struct {
97                 Text              string `xml:",chardata"`
98                 E2setupRequestIEs []struct {
99                         Text        string `xml:",chardata"`
100                         ID          string `xml:"id"`
101                         Criticality struct {
102                                 Text   string `xml:",chardata"`
103                                 Reject string `xml:"reject"`
104                         } `xml:"criticality"`
105                         Value struct {
106                                 Text             string           `xml:",chardata"`
107                                 GlobalE2nodeID   GlobalE2NodeId   `xml:"GlobalE2node-ID"`
108                                 RANfunctionsList RANfunctionsList `xml:"RANfunctions-List"`
109                         } `xml:"value"`
110                 } `xml:"E2setupRequestIEs"`
111         } `xml:"protocolIEs"`
112 }
113
114 type E2SetupRequestMessage struct {
115         XMLName xml.Name `xml:"E2SetupRequestMessage"`
116         Text    string   `xml:",chardata"`
117         E2APPDU struct {
118                 Text              string `xml:",chardata"`
119                 InitiatingMessage struct {
120                         Text          string `xml:",chardata"`
121                         ProcedureCode string `xml:"procedureCode"`
122                         Criticality   struct {
123                                 Text   string `xml:",chardata"`
124                                 Reject string `xml:"reject"`
125                         } `xml:"criticality"`
126                         Value struct {
127                                 Text           string         `xml:",chardata"`
128                                 E2setupRequest E2SetupRequest `xml:"E2setupRequest"`
129                         } `xml:"value"`
130                 } `xml:"initiatingMessage"`
131         } `xml:"E2AP-PDU"`
132 }
133
134 type RanFunctionItem struct {
135         Text                  string `xml:",chardata"`
136         RanFunctionID         uint32 `xml:"ranFunctionID"`
137         RanFunctionDefinition string `xml:"ranFunctionDefinition"`
138         RanFunctionRevision   uint32 `xml:"ranFunctionRevision"`
139         RanFunctionOID        string `xml:"ranFunctionOID"`
140 }
141
142 type RANfunctionsList struct {
143         Text                      string `xml:",chardata"`
144         ProtocolIESingleContainer []struct {
145                 Text        string `xml:",chardata"`
146                 ID          string `xml:"id"`
147                 Criticality struct {
148                         Text   string `xml:",chardata"`
149                         Reject string `xml:"reject"`
150                 } `xml:"criticality"`
151                 Value struct {
152                         Text            string          `xml:",chardata"`
153                         RANfunctionItem RanFunctionItem `xml:"RANfunction-Item"`
154                 } `xml:"value"`
155         } `xml:"ProtocolIE-SingleContainer"`
156 }
157
158 func (m *E2SetupRequestMessage) ExtractRanFunctionsList() []*entities.RanFunction {
159         // TODO: verify e2SetupRequestIEs structure with Adi
160         e2SetupRequestIes := m.E2APPDU.InitiatingMessage.Value.E2setupRequest.ProtocolIEs.E2setupRequestIEs
161         if len(e2SetupRequestIes) < 2 {
162                 return nil
163         }
164
165         ranFunctionsListContainer := e2SetupRequestIes[1].Value.RANfunctionsList.ProtocolIESingleContainer
166         funcs := make([]*entities.RanFunction, len(ranFunctionsListContainer))
167         for i := 0; i < len(funcs); i++ {
168                 ranFunctionItem := ranFunctionsListContainer[i].Value.RANfunctionItem
169
170                 funcs[i] = &entities.RanFunction{
171                         RanFunctionId:         ranFunctionItem.RanFunctionID,
172                         RanFunctionDefinition: ranFunctionItem.RanFunctionDefinition,
173                         RanFunctionRevision:   ranFunctionItem.RanFunctionRevision,
174                         RanFunctionOid:        ranFunctionItem.RanFunctionOID,
175                 }
176         }
177         return funcs
178 }
179
180 func (m *E2SetupRequestMessage) getGlobalE2NodeId() GlobalE2NodeId {
181         return m.E2APPDU.InitiatingMessage.Value.E2setupRequest.ProtocolIEs.E2setupRequestIEs[0].Value.GlobalE2nodeID
182 }
183
184 func (m *E2SetupRequestMessage) GetPlmnId() string {
185         globalE2NodeId := m.getGlobalE2NodeId()
186         if id := globalE2NodeId.GNB.GlobalGNBID.PlmnID; id != "" {
187                 return m.trimSpaces(id)
188         }
189         if id := globalE2NodeId.EnGNB.GlobalGNBID.PlmnID; id != "" {
190                 return m.trimSpaces(id)
191         }
192         if id := globalE2NodeId.ENB.GlobalENBID.PlmnID; id != "" {
193                 return m.trimSpaces(id)
194         }
195         if id := globalE2NodeId.NgENB.GlobalNgENBID.PlmnID; id != "" {
196                 return m.trimSpaces(id)
197         }
198         return ""
199 }
200
201 func (m *E2SetupRequestMessage) getInnerEnbId(enbId EnbId) string {
202
203         if id := enbId.HomeEnbId; id != "" {
204                 return id
205         }
206
207         if id := enbId.LongMacroEnbId; id != "" {
208                 return id
209         }
210
211         if id := enbId.MacroEnbId; id != "" {
212                 return id
213         }
214
215         if id := enbId.ShortMacroEnbId; id != "" {
216                 return id
217         }
218
219         return ""
220 }
221
222 func (m *E2SetupRequestMessage) getInnerNgEnbId(enbId NgEnbId) string {
223         if id := enbId.EnbIdLongMacro; id != "" {
224                 return id
225         }
226
227         if id := enbId.EnbIdMacro; id != "" {
228                 return id
229         }
230
231         if id := enbId.EnbIdShortMacro; id != "" {
232                 return id
233         }
234
235         return ""
236 }
237
238 func (m *E2SetupRequestMessage) GetNbId() string {
239         globalE2NodeId := m.getGlobalE2NodeId()
240
241         if id := globalE2NodeId.GNB.GlobalGNBID.GnbID.GnbID; id != "" {
242                 return m.trimSpaces(id)
243         }
244
245         if id := globalE2NodeId.EnGNB.GlobalGNBID.GnbID.GnbID; id != "" {
246                 return m.trimSpaces(id)
247         }
248
249         if id := m.getInnerEnbId(globalE2NodeId.ENB.GlobalENBID.EnbID); id != "" {
250                 return m.trimSpaces(id)
251         }
252
253         if id := m.getInnerNgEnbId(globalE2NodeId.NgENB.GlobalNgENBID.EnbID); id != "" {
254                 return m.trimSpaces(id)
255         }
256
257         return ""
258 }
259
260 func (m *E2SetupRequestMessage) trimSpaces(str string) string {
261         return strings.NewReplacer(" ", "", "\n", "").Replace(str)
262 }