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