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