4fcbe0dd1c1fd01d7b08771d8d81c19c14eba274
[ric-plt/e2mgr.git] / E2Manager / models / ric_service_update_message.go
1 //
2 // Copyright (c) 2020 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         "gerrit.o-ran-sc.org/r/ric-plt/nodeb-rnib.git/entities"
24 )
25
26 type RANfunctionsItemProtocolIESingleContainer struct {
27                 Text        string `xml:",chardata"`
28                 Id          string `xml:"id"`
29                 Criticality struct {
30                                 Text   string `xml:",chardata"`
31                                 Ignore string `xml:"ignore"`
32                 } `xml:"criticality"`
33                 Value struct {
34                                 Text              string `xml:",chardata"`
35                                 RANfunctionItem struct {
36                                                 Text                string `xml:",chardata"`
37                                                 RanFunctionID       uint32 `xml:"ranFunctionID"`
38                                                 RanFunctionDefinition string `xml:"ranFunctionDefinition"`
39                                                 RanFunctionRevision uint32 `xml:"ranFunctionRevision"`
40                                 } `xml:"RANfunction-Item"`
41                 } `xml:"value"`
42 }
43
44 type RANfunctionsItemIDProtocolIESingleContainer struct {
45                 Text        string `xml:",chardata"`
46                 Id          string `xml:"id"`
47                 Criticality struct {
48                                 Text   string `xml:",chardata"`
49                                 Ignore string `xml:"ignore"`
50                 } `xml:"criticality"`
51                 Value struct {
52                                 Text              string `xml:",chardata"`
53                                 RANfunctionIDItem struct {
54                                                 Text                string `xml:",chardata"`
55                                                 RanFunctionID       uint32 `xml:"ranFunctionID"`
56                                                 RanFunctionRevision uint32 `xml:"ranFunctionRevision"`
57                                 } `xml:"RANfunctionID-Item"`
58                 } `xml:"value"`
59 }
60
61
62 type RICServiceUpdateIEs struct {
63         Text        string `xml:",chardata"`
64         ID          int `xml:"id"`
65         Criticality struct {
66                 Text   string `xml:",chardata"`
67                 Reject string `xml:"reject"`
68         } `xml:"criticality"`
69         Value struct {
70                 Text   string `xml:",chardata"`
71                 RANfunctionsList struct {
72                         Text   string `xml:",chardata"`
73                         RANfunctionsItemProtocolIESingleContainer []RANfunctionsItemProtocolIESingleContainer `xml:"ProtocolIE-SingleContainer"`
74                 } `xml:"RANfunctions-List"`
75                 RANfunctionsIDList struct {
76                         Text   string `xml:",chardata"`
77                         RANfunctionsItemIDProtocolIESingleContainer []RANfunctionsItemIDProtocolIESingleContainer `xml:"ProtocolIE-SingleContainer"`
78                 } `xml:"RANfunctionsID-List"`
79         }`xml:"value"`
80 }
81
82 type RICServiceUpdateInitiatingMessage struct {
83         Text          string `xml:",chardata"`
84         ProcedureCode string `xml:"procedureCode"`
85         Criticality   struct {
86                 Text   string `xml:",chardata"`
87                 Reject string `xml:"reject"`
88         } `xml:"criticality"`
89         Value struct {
90                 Text            string `xml:",chardata"`
91                 RICServiceUpdate struct {
92                         Text        string `xml:",chardata"`
93                         ProtocolIEs struct {
94                                 Text               string `xml:",chardata"`
95                                 RICServiceUpdateIEs []RICServiceUpdateIEs `xml:"RICserviceUpdate-IEs"`
96                         } `xml:"protocolIEs"`
97                 } `xml:"RICserviceUpdate"`
98         } `xml:"value"`
99 }
100
101 type RICServiceUpdateE2APPDU struct {
102         XMLName xml.Name `xml:"E2AP-PDU"`
103         Text    string `xml:",chardata"`
104         InitiatingMessage  RICServiceUpdateInitiatingMessage `xml:"initiatingMessage"`
105 }
106
107 type RICServiceUpdateMessage struct{
108         XMLName xml.Name `xml:"RICserviceUpdateMessage"`
109         Text    string   `xml:",chardata"`
110         E2APPDU RICServiceUpdateE2APPDU  `xml:"E2AP-PDU"`
111 }
112
113 func (m *RICServiceUpdateE2APPDU) ExtractRanFunctionsList() []*entities.RanFunction {
114         serviceUpdateRequestIes := m.InitiatingMessage.Value.RICServiceUpdate.ProtocolIEs.RICServiceUpdateIEs
115         if len(serviceUpdateRequestIes) < 2 {
116                 return nil
117         }
118
119         ranFunctionsListContainer := serviceUpdateRequestIes[1].Value.RANfunctionsList.RANfunctionsItemProtocolIESingleContainer
120         funcs := make([]*entities.RanFunction, len(ranFunctionsListContainer))
121         for i := 0; i < len(funcs); i++ {
122                 ranFunctionItem := ranFunctionsListContainer[i].Value.RANfunctionItem
123
124                 funcs[i] = &entities.RanFunction{
125                         RanFunctionId:         ranFunctionItem.RanFunctionID,
126                         RanFunctionDefinition: ranFunctionItem.RanFunctionDefinition,
127                         RanFunctionRevision:   ranFunctionItem.RanFunctionRevision,
128                 }
129         }
130         return funcs
131 }