2 // Copyright 2019 AT&T Intellectual Property
3 // Copyright 2019 Nokia
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
9 // http://www.apache.org/licenses/LICENSE-2.0
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.
17 // This source code is part of the near-RT RIC (RAN Intelligent Controller)
18 // platform project (RICP).
26 "gerrit.o-ran-sc.org/r/ric-plt/nodeb-rnib.git/entities"
32 Text string `xml:",chardata"`
34 Text string `xml:",chardata"`
35 PlmnID string `xml:"plmn-id"`
37 Text string `xml:",chardata"`
38 GnbID string `xml:"gnb-ID"`
40 } `xml:"global-gNB-ID"`
44 Text string `xml:",chardata"`
46 Text string `xml:",chardata"`
47 PlmnID string `xml:"pLMN-Identity"`
49 Text string `xml:",chardata"`
50 GnbID string `xml:"gNB-ID"`
52 } `xml:"global-gNB-ID"`
56 Text string `xml:",chardata"`
57 EnbIdMacro string `xml:"enb-ID-macro"`
58 EnbIdShortMacro string `xml:"enb-ID-shortmacro"`
59 EnbIdLongMacro string `xml:"enb-ID-longmacro"`
63 Text string `xml:",chardata"`
64 GlobalNgENBID struct {
65 Text string `xml:",chardata"`
66 PlmnID string `xml:"plmn-id"`
67 EnbID NgEnbId `xml:"enb-id"`
68 } `xml:"global-ng-eNB-ID"`
72 Text string `xml:",chardata"`
73 MacroEnbId string `xml:"macro-eNB-ID"`
74 HomeEnbId string `xml:"home-eNB-ID"`
75 ShortMacroEnbId string `xml:"short-Macro-eNB-ID"`
76 LongMacroEnbId string `xml:"long-Macro-eNB-ID"`
80 Text string `xml:",chardata"`
82 Text string `xml:",chardata"`
83 PlmnID string `xml:"pLMN-Identity"`
84 EnbID EnbId `xml:"eNB-ID"`
85 } `xml:"global-eNB-ID"`
88 type GlobalE2NodeId struct {
89 Text string `xml:",chardata"`
91 EnGNB EnGnb `xml:"en-gNB"`
92 NgENB NgEnb `xml:"ng-eNB"`
96 type E2SetupRequest struct {
97 Text string `xml:",chardata"`
99 Text string `xml:",chardata"`
100 E2setupRequestIEs []struct {
101 Text string `xml:",chardata"`
104 Text string `xml:",chardata"`
105 Reject string `xml:"reject"`
106 } `xml:"criticality"`
108 Text string `xml:",chardata"`
109 GlobalE2nodeID GlobalE2NodeId `xml:"GlobalE2node-ID"`
110 RANfunctionsList RANfunctionsList `xml:"RANfunctions-List"`
112 } `xml:"E2setupRequestIEs"`
113 } `xml:"protocolIEs"`
116 type E2SetupRequestMessage struct {
117 XMLName xml.Name `xml:"E2SetupRequestMessage"`
118 Text string `xml:",chardata"`
120 Text string `xml:",chardata"`
121 InitiatingMessage struct {
122 Text string `xml:",chardata"`
123 ProcedureCode string `xml:"procedureCode"`
125 Text string `xml:",chardata"`
126 Reject string `xml:"reject"`
127 } `xml:"criticality"`
129 Text string `xml:",chardata"`
130 E2setupRequest E2SetupRequest `xml:"E2setupRequest"`
132 } `xml:"initiatingMessage"`
136 type RanFunctionItem struct {
137 Text string `xml:",chardata"`
138 RanFunctionID string `xml:"ranFunctionID"`
139 RanFunctionDefinition string `xml:"ranFunctionDefinition"`
140 RanFunctionRevision string `xml:"ranFunctionRevision"`
143 type RANfunctionsList struct {
144 Text string `xml:",chardata"`
145 ProtocolIESingleContainer []struct {
146 Text string `xml:",chardata"`
149 Text string `xml:",chardata"`
150 Reject string `xml:"reject"`
151 } `xml:"criticality"`
153 Text string `xml:",chardata"`
154 RANfunctionItem RanFunctionItem `xml:"RANfunction-Item"`
156 } `xml:"ProtocolIE-SingleContainer"`
159 func (m *E2SetupRequestMessage) ExtractRanFunctionsList() ([]*entities.RanFunction, error) {
160 list := m.E2APPDU.InitiatingMessage.Value.E2setupRequest.ProtocolIEs.E2setupRequestIEs[1].Value.RANfunctionsList.ProtocolIESingleContainer
161 funcs := make([]*entities.RanFunction, len(list))
162 for i := 0; i < len(funcs); i++ {
163 funcs[i] = &entities.RanFunction{}
164 id, err := strconv.ParseUint(list[i].Value.RANfunctionItem.RanFunctionID, 10, 32)
166 return nil, errors.New(fmt.Sprintf("#e2_setup_request_message.ExtractRanFunctionsList - Failed parse uint RanFunctionID from %s", list[i].Value.RANfunctionItem.RanFunctionID))
168 funcs[i].RanFunctionId = uint32(id)
169 rev, err := strconv.ParseUint(list[i].Value.RANfunctionItem.RanFunctionRevision, 10, 32)
171 return nil, errors.New(fmt.Sprintf("#e2_setup_request_message.ExtractRanFunctionsList - Failed parse uint RanFunctionRevision from %s", list[i].Value.RANfunctionItem.RanFunctionRevision))
173 funcs[i].RanFunctionDefinition = m.trimSpaces(list[i].Value.RANfunctionItem.RanFunctionDefinition)
174 funcs[i].RanFunctionRevision = uint32(rev)
179 func (m *E2SetupRequestMessage) getGlobalE2NodeId() GlobalE2NodeId {
180 return m.E2APPDU.InitiatingMessage.Value.E2setupRequest.ProtocolIEs.E2setupRequestIEs[0].Value.GlobalE2nodeID
183 //func (m *E2SetupRequestMessage) GetNodeType() entities.Node_Type {
184 // globalE2NodeId := m.getGlobalE2NodeId()
185 // if id := globalE2NodeId.GNB.GlobalGNBID.PlmnID; id != "" {
186 // return entities.Node_GNB
188 // if id := globalE2NodeId.EnGNB.GlobalGNBID.PlmnID; id != "" {
189 // return entities.Node_GNB
191 // if id := globalE2NodeId.ENB.GlobalENBID.PlmnID; id != "" {
192 // return entities.Node_ENB
194 // if id := globalE2NodeId.NgENB.GlobalNgENBID.PlmnID; id != "" {
195 // return entities.Node_ENB
197 // return entities.Node_UNKNOWN
200 func (m *E2SetupRequestMessage) GetPlmnId() string {
201 globalE2NodeId := m.getGlobalE2NodeId()
202 if id := globalE2NodeId.GNB.GlobalGNBID.PlmnID; id != "" {
203 return m.trimSpaces(id)
205 if id := globalE2NodeId.EnGNB.GlobalGNBID.PlmnID; id != "" {
206 return m.trimSpaces(id)
208 if id := globalE2NodeId.ENB.GlobalENBID.PlmnID; id != "" {
209 return m.trimSpaces(id)
211 if id := globalE2NodeId.NgENB.GlobalNgENBID.PlmnID; id != "" {
212 return m.trimSpaces(id)
217 func (m *E2SetupRequestMessage) getInnerEnbId(enbId EnbId) string {
219 if id := enbId.HomeEnbId; id != "" {
223 if id := enbId.LongMacroEnbId; id != "" {
227 if id := enbId.MacroEnbId; id != "" {
231 if id := enbId.ShortMacroEnbId; id != "" {
238 func (m *E2SetupRequestMessage) getInnerNgEnbId(enbId NgEnbId) string {
239 if id := enbId.EnbIdLongMacro; id != "" {
243 if id := enbId.EnbIdMacro; id != "" {
247 if id := enbId.EnbIdShortMacro; id != "" {
254 func (m *E2SetupRequestMessage) GetNbId() string {
255 globalE2NodeId := m.getGlobalE2NodeId()
257 if id := globalE2NodeId.GNB.GlobalGNBID.GnbID.GnbID; id != "" {
258 return m.trimSpaces(id)
261 if id := globalE2NodeId.EnGNB.GlobalGNBID.GnbID.GnbID; id != "" {
262 return m.trimSpaces(id)
265 if id := m.getInnerEnbId(globalE2NodeId.ENB.GlobalENBID.EnbID); id != "" {
266 return m.trimSpaces(id)
269 if id := m.getInnerNgEnbId(globalE2NodeId.NgENB.GlobalNgENBID.EnbID); id != "" {
270 return m.trimSpaces(id)
276 func (m *E2SetupRequestMessage) trimSpaces(str string) string {
277 return strings.NewReplacer(" ", "", "\n", "").Replace(str)