Squash-merging e2ap-v2.0 branch
[ric-plt/e2mgr.git] / E2Manager / models / e2_node_configuration_update_ack.go
1 //
2 // Copyright (c) 2022 Samsung Electronics Co., Ltd. All Rights Reserved.
3 //
4 // Licensed under the Apache License, Version 2.0 (the "License");
5 // you may not use this file except in compliance with the License.
6 // You may obtain a copy of the License at
7 //
8 //      http://www.apache.org/licenses/LICENSE-2.0
9 //
10 // Unless required by applicable law or agreed to in writing, software
11 // distributed under the License is distributed on an "AS IS" BASIS,
12 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 // See the License for the specific language governing permissions and
14 // limitations under the License.
15
16 //  This source code is part of the near-RT RIC (RAN Intelligent Controller)
17 //  platform project (RICP).
18
19 package models
20
21 import (
22         "encoding/xml"
23
24         "gerrit.o-ran-sc.org/r/ric-plt/nodeb-rnib.git/entities"
25 )
26
27 type E2nodeConfigurationUpdateAcknowledgeE2APPDU struct {
28         XMLName xml.Name `xml:"E2AP-PDU"`
29         Text    string   `xml:",chardata"`
30         Outcome interface{}
31 }
32
33 type E2nodeConfigurationUpdateAcknowledgeSuccessfulOutcome struct {
34         XMLName       xml.Name `xml:"successfulOutcome"`
35         Text          string   `xml:",chardata"`
36         ProcedureCode string   `xml:"procedureCode"`
37         Criticality   struct {
38                 Text   string `xml:",chardata"`
39                 Reject string `xml:"reject"`
40         } `xml:"criticality"`
41         Value struct {
42                 Text                                 string `xml:",chardata"`
43                 E2nodeConfigurationUpdateAcknowledge struct {
44                         Text        string `xml:",chardata"`
45                         ProtocolIEs struct {
46                                 Text                                    string                                    `xml:",chardata"`
47                                 E2nodeConfigurationUpdateAcknowledgeIEs []E2nodeConfigurationUpdateAcknowledgeIEs `xml:"E2nodeConfigurationUpdateAcknowledge-IEs"`
48                         } `xml:"protocolIEs"`
49                 } `xml:"E2nodeConfigurationUpdateAcknowledge"`
50         } `xml:"value"`
51 }
52
53 type E2nodeConfigurationUpdateAcknowledgeIEs struct {
54         Text        string `xml:",chardata"`
55         ID          string `xml:"id"`
56         Criticality struct {
57                 Text   string `xml:",chardata"`
58                 Reject string `xml:"reject"`
59         } `xml:"criticality"`
60         Value interface{} `xml:"value"`
61 }
62
63 type E2nodeConfigurationUpdateAcknowledgeTransID struct {
64         Text          string `xml:",chardata"`
65         TransactionID string `xml:"TransactionID"`
66 }
67
68 type E2nodeComponentConfigAdditionAckList struct {
69         Text                                 string `xml:",chardata"`
70         E2nodeComponentConfigAdditionAckList struct {
71                 Text                      string                                  `xml:",chardata"`
72                 ProtocolIESingleContainer []AdditionListProtocolIESingleContainer `xml:"ProtocolIE-SingleContainer"`
73         } `xml:"E2nodeComponentConfigAdditionAck-List"`
74 }
75
76 type AdditionListProtocolIESingleContainer struct {
77         Text        string `xml:",chardata"`
78         ID          string `xml:"id"`
79         Criticality struct {
80                 Text   string `xml:",chardata"`
81                 Reject string `xml:"reject"`
82         } `xml:"criticality"`
83         Value struct {
84                 Text                                 string             `xml:",chardata"`
85                 E2nodeComponentConfigAdditionAckItem ComponentAckDetail `xml:"E2nodeComponentConfigAdditionAck-Item"`
86         } `xml:"value"`
87 }
88
89 type E2nodeComponentConfigUpdateAckList struct {
90         Text                               string `xml:",chardata"`
91         E2nodeComponentConfigUpdateAckList struct {
92                 Text                      string                            `xml:",chardata"`
93                 ProtocolIESingleContainer []UpdateProtocolIESingleContainer `xml:"ProtocolIE-SingleContainer"`
94         } `xml:"E2nodeComponentConfigUpdateAck-List"`
95 }
96
97 type UpdateProtocolIESingleContainer 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                 E2nodeComponentConfigUpdateAckItem ComponentAckDetail `xml:"E2nodeComponentConfigUpdateAck-Item"`
107         } `xml:"value"`
108 }
109
110 type E2nodeComponentConfigRemovalAckList struct {
111         Text                                string `xml:",chardata"`
112         E2nodeComponentConfigRemovalAckList struct {
113                 Text                      string                             `xml:",chardata"`
114                 ProtocolIESingleContainer []RemovalProtocolIESingleContainer `xml:"ProtocolIE-SingleContainer"`
115         } `xml:"E2nodeComponentConfigRemovalAck-List"`
116 }
117
118 type RemovalProtocolIESingleContainer struct {
119         Text        string `xml:",chardata"`
120         ID          string `xml:"id"`
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                 E2nodeComponentConfigRemovalAckItem ComponentAckDetail `xml:"E2nodeComponentConfigRemovalAck-Item"`
128         } `xml:"value"`
129 }
130
131 type ComponentAckDetail struct {
132         Text                         string                `xml:",chardata"`
133         E2nodeComponentInterfaceType E2NodeComponentType   `xml:"e2nodeComponentInterfaceType"`
134         E2nodeComponentID            E2NodeComponentIDResp `xml:"e2nodeComponentID"`
135         E2nodeConfigUpdateAck        E2nodeConfigUpdateAckResp
136 }
137
138 func prepareAdditionAckList(e2nodeConfigs []entities.E2NodeComponentConfig) []AdditionListProtocolIESingleContainer {
139         additionListAckSingle := []AdditionListProtocolIESingleContainer{}
140         for _, v := range e2nodeConfigs {
141                 c := convertEntitiyToModelComponent(v)
142
143                 t := AdditionListProtocolIESingleContainer{
144                         ID: ProtocolIE_ID_id_E2nodeComponentConfigAdditionAck_Item,
145                         Value: struct {
146                                 Text                                 string             `xml:",chardata"`
147                                 E2nodeComponentConfigAdditionAckItem ComponentAckDetail `xml:"E2nodeComponentConfigAdditionAck-Item"`
148                         }{
149                                 E2nodeComponentConfigAdditionAckItem: *c,
150                         },
151                 }
152                 additionListAckSingle = append(additionListAckSingle, t)
153         }
154         return additionListAckSingle
155 }
156
157 func prepareUpdateAckList(e2nodeConfigs []entities.E2NodeComponentConfig) []UpdateProtocolIESingleContainer {
158         updateListAckSingle := []UpdateProtocolIESingleContainer{}
159         for _, v := range e2nodeConfigs {
160                 c := convertEntitiyToModelComponent(v)
161
162                 t := UpdateProtocolIESingleContainer{
163                         ID: ProtocolIE_ID_id_E2nodeComponentConfigUpdateAck_Item,
164                         Value: struct {
165                                 Text                               string             `xml:",chardata"`
166                                 E2nodeComponentConfigUpdateAckItem ComponentAckDetail `xml:"E2nodeComponentConfigUpdateAck-Item"`
167                         }{
168                                 E2nodeComponentConfigUpdateAckItem: *c,
169                         },
170                 }
171                 updateListAckSingle = append(updateListAckSingle, t)
172         }
173         return updateListAckSingle
174 }
175
176 func prepareRemovalAckList(e2nodeConfigs []entities.E2NodeComponentConfig) []RemovalProtocolIESingleContainer {
177         removalListAckSingle := []RemovalProtocolIESingleContainer{}
178         for _, v := range e2nodeConfigs {
179                 c := convertEntitiyToModelComponent(v)
180
181                 t := RemovalProtocolIESingleContainer{
182                         ID: ProtocolIE_ID_id_E2nodeComponentConfigRemovalAck_Item,
183                         Value: struct {
184                                 Text                                string             `xml:",chardata"`
185                                 E2nodeComponentConfigRemovalAckItem ComponentAckDetail `xml:"E2nodeComponentConfigRemovalAck-Item"`
186                         }{
187                                 E2nodeComponentConfigRemovalAckItem: *c,
188                         },
189                 }
190                 removalListAckSingle = append(removalListAckSingle, t)
191         }
192         return removalListAckSingle
193 }
194
195 func updateIDAndStatus(t *ComponentAckDetail, c entities.E2NodeComponentConfig, succss bool) {
196         switch c.E2NodeComponentInterfaceType {
197         case entities.E2NodeComponentInterfaceType_ng:
198                 t.E2nodeComponentID.Value = E2NodeIFTypeNG{
199                         AMFName: c.GetE2NodeComponentInterfaceTypeNG().AmfName,
200                 }
201         case entities.E2NodeComponentInterfaceType_e1:
202                 t.E2nodeComponentID.Value = E2NodeIFTypeE1{
203                         GNBCUCPID: c.GetE2NodeComponentInterfaceTypeE1().GetGNBCuCpId(),
204                 }
205         case entities.E2NodeComponentInterfaceType_s1:
206                 t.E2nodeComponentID.Value = E2NodeIFTypeS1{
207                         MMENAME: c.GetE2NodeComponentInterfaceTypeS1().GetMmeName(),
208                 }
209         case entities.E2NodeComponentInterfaceType_f1:
210                 t.E2nodeComponentID.Value = E2NodeIFTypeF1{
211                         GNBDUID: c.GetE2NodeComponentInterfaceTypeF1().GetGNBDuId(),
212                 }
213         case entities.E2NodeComponentInterfaceType_w1:
214                 t.E2nodeComponentID.Value = E2NodeIFTypeW1{
215                         NGENBDUID: c.GetE2NodeComponentInterfaceTypeW1().GetNgenbDuId(),
216                 }
217         }
218
219         if succss {
220                 t.E2nodeConfigUpdateAck = E2nodeConfigUpdateAckResp{
221                         Value: struct {
222                                 XMLName xml.Name `xml:"updateOutcome"`
223                                 Text    string   `xml:",chardata"`
224                                 Success string   `xml:"success"`
225                         }{},
226                 }
227         } else {
228                 t.E2nodeConfigUpdateAck = E2nodeConfigUpdateAckResp{
229                         Value: struct {
230                                 XMLName xml.Name `xml:"updateOutcome"`
231                                 Text    string   `xml:",chardata"`
232                                 Success string   `xml:"failure"`
233                         }{},
234                 }
235         }
236 }
237
238 func updateInterfaceType(t *ComponentAckDetail, c entities.E2NodeComponentConfig) {
239         switch c.E2NodeComponentInterfaceType {
240         case entities.E2NodeComponentInterfaceType_ng:
241                 t.E2nodeComponentInterfaceType = E2NodeComponentType{
242                         NG: &struct{}{},
243                 }
244         case entities.E2NodeComponentInterfaceType_e1:
245                 t.E2nodeComponentInterfaceType = E2NodeComponentType{
246                         E1: &struct{}{},
247                 }
248         case entities.E2NodeComponentInterfaceType_f1:
249                 t.E2nodeComponentInterfaceType = E2NodeComponentType{
250                         F1: &struct{}{},
251                 }
252         case entities.E2NodeComponentInterfaceType_w1:
253                 t.E2nodeComponentInterfaceType = E2NodeComponentType{
254                         W1: &struct{}{},
255                 }
256         case entities.E2NodeComponentInterfaceType_s1:
257                 t.E2nodeComponentInterfaceType = E2NodeComponentType{
258                         S1: &struct{}{},
259                 }
260         }
261 }
262
263 func convertEntitiyToModelComponent(component entities.E2NodeComponentConfig) *ComponentAckDetail {
264         componentAckDetail := &ComponentAckDetail{}
265         updateInterfaceType(componentAckDetail, component)
266         updateIDAndStatus(componentAckDetail, component, true)
267         return componentAckDetail
268 }
269
270 func NewE2nodeConfigurationUpdateSuccessResponseMessage(e2nodeConfigupdateMessage *E2nodeConfigurationUpdateMessage) *E2nodeConfigurationUpdateAcknowledgeE2APPDU {
271         successfulOutcome := E2nodeConfigurationUpdateAcknowledgeSuccessfulOutcome{
272                 ProcedureCode: ProcedureCode_id_E2nodeConfigurationUpdate,
273         }
274
275         e2nodeConfigurationUpdateAckIEs := []E2nodeConfigurationUpdateAcknowledgeIEs{}
276         txIEs := E2nodeConfigurationUpdateAcknowledgeIEs{
277                 ID: ProtocolIE_ID_id_TransactionID,
278                 Value: E2nodeConfigurationUpdateAcknowledgeTransID{
279                         TransactionID: e2nodeConfigupdateMessage.E2APPDU.InitiatingMessage.Value.E2nodeConfigurationUpdate.ProtocolIEs.E2nodeConfigurationUpdateIEs[0].Value.TransactionID,
280                 },
281         }
282
283         e2nodeConfigurationUpdateAckIEs = append(e2nodeConfigurationUpdateAckIEs, txIEs)
284
285         items := e2nodeConfigupdateMessage.ExtractConfigAdditionList()
286         if len(items) > 0 {
287                 addtionListAckIEs := E2nodeConfigurationUpdateAcknowledgeIEs{
288                         ID: ProtocolIE_ID_id_E2nodeComponentConfigAdditionAck,
289                         Value: E2nodeComponentConfigAdditionAckList{
290                                 E2nodeComponentConfigAdditionAckList: struct {
291                                         Text                      string                                  `xml:",chardata"`
292                                         ProtocolIESingleContainer []AdditionListProtocolIESingleContainer `xml:"ProtocolIE-SingleContainer"`
293                                 }{
294                                         ProtocolIESingleContainer: prepareAdditionAckList(items),
295                                 },
296                         },
297                 }
298                 e2nodeConfigurationUpdateAckIEs = append(e2nodeConfigurationUpdateAckIEs, addtionListAckIEs)
299         }
300
301         items = e2nodeConfigupdateMessage.ExtractConfigUpdateList()
302         if len(items) > 0 {
303                 updateListAckIEs := E2nodeConfigurationUpdateAcknowledgeIEs{
304                         ID: ProtocolIE_ID_id_E2nodeComponentConfigUpdateAck,
305                         Value: E2nodeComponentConfigUpdateAckList{
306                                 E2nodeComponentConfigUpdateAckList: struct {
307                                         Text                      string                            `xml:",chardata"`
308                                         ProtocolIESingleContainer []UpdateProtocolIESingleContainer `xml:"ProtocolIE-SingleContainer"`
309                                 }{
310                                         ProtocolIESingleContainer: prepareUpdateAckList(items),
311                                 },
312                         },
313                 }
314                 e2nodeConfigurationUpdateAckIEs = append(e2nodeConfigurationUpdateAckIEs, updateListAckIEs)
315         }
316
317         items = e2nodeConfigupdateMessage.ExtractConfigDeletionList()
318         if len(items) > 0 {
319                 removalListAckIEs := E2nodeConfigurationUpdateAcknowledgeIEs{
320                         ID: ProtocolIE_ID_id_E2nodeComponentConfigRemovalAck,
321                         Value: E2nodeComponentConfigRemovalAckList{
322                                 E2nodeComponentConfigRemovalAckList: struct {
323                                         Text                      string                             `xml:",chardata"`
324                                         ProtocolIESingleContainer []RemovalProtocolIESingleContainer `xml:"ProtocolIE-SingleContainer"`
325                                 }{
326                                         ProtocolIESingleContainer: prepareRemovalAckList(items),
327                                 },
328                         },
329                 }
330                 e2nodeConfigurationUpdateAckIEs = append(e2nodeConfigurationUpdateAckIEs, removalListAckIEs)
331         }
332
333         successfulOutcome.Value.E2nodeConfigurationUpdateAcknowledge.ProtocolIEs.E2nodeConfigurationUpdateAcknowledgeIEs = e2nodeConfigurationUpdateAckIEs
334         response := &E2nodeConfigurationUpdateAcknowledgeE2APPDU{
335                 Outcome: successfulOutcome,
336         }
337         return response
338 }