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).
24 "gerrit.o-ran-sc.org/r/ric-plt/nodeb-rnib.git/entities"
25 "github.com/golang/protobuf/ptypes/wrappers"
30 Text string `xml:",chardata"`
32 Text string `xml:",chardata"`
33 PlmnID string `xml:"plmn-id"`
35 Text string `xml:",chardata"`
36 GnbID string `xml:"gnb-ID"`
38 } `xml:"global-gNB-ID"`
42 Text string `xml:",chardata"`
44 Text string `xml:",chardata"`
45 PlmnID string `xml:"pLMN-Identity"`
47 Text string `xml:",chardata"`
48 GnbID string `xml:"gNB-ID"`
50 } `xml:"global-gNB-ID"`
54 Text string `xml:",chardata"`
55 EnbIdMacro string `xml:"enb-ID-macro"`
56 EnbIdShortMacro string `xml:"enb-ID-shortmacro"`
57 EnbIdLongMacro string `xml:"enb-ID-longmacro"`
61 Text string `xml:",chardata"`
62 GlobalNgENBID struct {
63 Text string `xml:",chardata"`
64 PlmnID string `xml:"plmn-id"`
65 EnbID NgEnbId `xml:"enb-id"`
66 } `xml:"global-ng-eNB-ID"`
70 Text string `xml:",chardata"`
71 MacroEnbId string `xml:"macro-eNB-ID"`
72 HomeEnbId string `xml:"home-eNB-ID"`
73 ShortMacroEnbId string `xml:"short-Macro-eNB-ID"`
74 LongMacroEnbId string `xml:"long-Macro-eNB-ID"`
78 Text string `xml:",chardata"`
80 Text string `xml:",chardata"`
81 PlmnID string `xml:"pLMN-Identity"`
82 EnbID EnbId `xml:"eNB-ID"`
83 } `xml:"global-eNB-ID"`
86 type GlobalE2NodeId struct {
87 Text string `xml:",chardata"`
89 EnGNB EnGnb `xml:"en-gNB"`
90 NgENB NgEnb `xml:"ng-eNB"`
94 type E2SetupRequest struct {
95 Text string `xml:",chardata"`
97 Text string `xml:",chardata"`
98 E2setupRequestIEs []struct {
99 Text string `xml:",chardata"`
102 Text string `xml:",chardata"`
103 Reject string `xml:"reject"`
104 } `xml:"criticality"`
106 Text string `xml:",chardata"`
107 GlobalE2nodeID GlobalE2NodeId `xml:"GlobalE2node-ID"`
108 RANfunctionsList RANfunctionsList `xml:"RANfunctions-List"`
110 } `xml:"E2setupRequestIEs"`
111 } `xml:"protocolIEs"`
114 type E2SetupRequestMessage struct {
115 XMLName xml.Name `xml:"E2SetupRequestMessage"`
116 Text string `xml:",chardata"`
118 Text string `xml:",chardata"`
119 InitiatingMessage struct {
120 Text string `xml:",chardata"`
121 ProcedureCode string `xml:"procedureCode"`
123 Text string `xml:",chardata"`
124 Reject string `xml:"reject"`
125 } `xml:"criticality"`
127 Text string `xml:",chardata"`
128 E2setupRequest E2SetupRequest `xml:"E2setupRequest"`
130 } `xml:"initiatingMessage"`
134 type RanFunctionItem struct {
135 Text string `xml:",chardata"`
136 RanFunctionID uint32 `xml:"ranFunctionID"`
137 RanFunctionDefinition RanFunctionDefinition `xml:"ranFunctionDefinition"`
138 RanFunctionRevision uint32 `xml:"ranFunctionRevision"`
141 type RanFunctionDefinition struct {
142 Text string `xml:",chardata"`
143 E2smGnbNrtRanFunctionDefinition E2smGnbNrtRanFunctionDefinition `xml:"E2SM-gNB-NRT-RANfunction-Definition"`
146 type RanFunctionName struct {
147 Text string `xml:",chardata"`
148 RanFunctionShortName string `xml:"ranFunction-ShortName"`
149 RanFunctionE2smOid string `xml:"ranFunction-E2SM-OID"`
150 RanFunctionDescription string `xml:"ranFunction-Description"`
151 RanFunctionInstance *uint32 `xml:"ranFunction-Instance"`
154 type RicEventTriggerStyleList struct {
155 Text string `xml:",chardata"`
156 RicEventTriggerStyleType uint32 `xml:"ric-EventTriggerStyle-Type"`
157 RicEventTriggerStyleName string `xml:"ric-EventTriggerStyle-Name"`
158 RicEventTriggerFormatType uint32 `xml:"ric-EventTriggerFormat-Type"`
161 type RanParameterDefItem struct {
162 Text string `xml:",chardata"`
163 RanParameterID uint32 `xml:"ranParameter-ID"`
164 RanParameterName string `xml:"ranParameter-Name"`
165 RanParameterType RanParameterType `xml:"ranParameter-Type"`
168 type RanParameterType struct {
169 Text string `xml:",chardata"`
170 Boolean *struct{} `xml:"boolean,omitempty"`
171 Integer *struct{} `xml:"integer,omitempty"`
172 Enumerated *struct{} `xml:"enumerated,omitempty"`
173 BitString *struct{} `xml:"bit-string,omitempty"`
174 OctetString *struct{} `xml:"octet-string,omitempty"`
175 PrintableString *struct{} `xml:"printable-string,omitempty"`
178 type RicReportStyleList struct {
179 Text string `xml:",chardata"`
180 RicReportStyleType uint32 `xml:"ric-ReportStyle-Type"`
181 RicReportStyleName string `xml:"ric-ReportStyle-Name"`
182 RicReportActionFormatType uint32 `xml:"ric-ReportActionFormat-Type"`
183 RicReportRanParameterDefList struct {
184 Text string `xml:",chardata"`
185 RanParameterDefItem []RanParameterDefItem `xml:"RANparameterDef-Item"`
186 } `xml:"ric-ReportRanParameterDef-List"`
187 RicIndicationHeaderFormatType uint32 `xml:"ric-IndicationHeaderFormat-Type"`
188 RicIndicationMessageFormatType uint32 `xml:"ric-IndicationMessageFormat-Type"`
191 type RicInsertStyleList struct {
192 Text string `xml:",chardata"`
193 RicInsertStyleType uint32 `xml:"ric-InsertStyle-Type"`
194 RicInsertStyleName string `xml:"ric-InsertStyle-Name"`
195 RicInsertActionFormatType uint32 `xml:"ric-InsertActionFormat-Type"`
196 RicInsertRanParameterDefList struct {
197 Text string `xml:",chardata"`
198 RanParameterDefItem []RanParameterDefItem `xml:"RANparameterDef-Item"`
199 } `xml:"ric-InsertRanParameterDef-List"`
200 RicIndicationHeaderFormatType uint32 `xml:"ric-IndicationHeaderFormat-Type"`
201 RicIndicationMessageFormatType uint32 `xml:"ric-IndicationMessageFormat-Type"`
202 RicCallProcessIdFormatType uint32 `xml:"ric-CallProcessIDFormat-Type"`
205 type RicControlStyleList struct {
206 Text string `xml:",chardata"`
207 RicControlStyleType uint32 `xml:"ric-ControlStyle-Type"`
208 RicControlStyleName string `xml:"ric-ControlStyle-Name"`
209 RicControlHeaderFormatType uint32 `xml:"ric-ControlHeaderFormat-Type"`
210 RicControlMessageFormatType uint32 `xml:"ric-ControlMessageFormat-Type"`
211 RicCallProcessIdFormatType uint32 `xml:"ric-CallProcessIDFormat-Type"`
214 type RicPolicyStyleList struct {
215 Text string `xml:",chardata"`
216 RicPolicyStyleType uint32 `xml:"ric-PolicyStyle-Type"`
217 RicPolicyStyleName string `xml:"ric-PolicyStyle-Name"`
218 RicPolicyActionFormatType uint32 `xml:"ric-PolicyActionFormat-Type"`
219 RicPolicyRanParameterDefList struct {
220 Text string `xml:",chardata"`
221 RanParameterDefItem []RanParameterDefItem `xml:"RANparameterDef-Item"`
222 } `xml:"ric-PolicyRanParameterDef-List"`
225 type E2smGnbNrtRanFunctionDefinition struct {
226 Text string `xml:",chardata"`
227 RanFunctionName RanFunctionName `xml:"ranFunction-Name"`
228 RicEventTriggerStyleList struct {
229 Text string `xml:",chardata"`
230 RicEventTriggerStyleList []RicEventTriggerStyleList `xml:"RIC-EventTriggerStyle-List"`
231 } `xml:"ric-EventTriggerStyle-List"`
232 RicReportStyleList struct {
233 Text string `xml:",chardata"`
234 RicReportStyleList []RicReportStyleList `xml:"RIC-ReportStyle-List"`
235 } `xml:"ric-ReportStyle-List"`
236 RicInsertStyleList struct {
237 Text string `xml:",chardata"`
238 RicInsertStyleList []RicInsertStyleList `xml:"RIC-InsertStyle-List"`
239 } `xml:"ric-InsertStyle-List"`
240 RicControlStyleList struct {
241 Text string `xml:",chardata"`
242 RicControlStyleList []RicControlStyleList `xml:"RIC-ControlStyle-List"`
243 } `xml:"ric-ControlStyle-List"`
244 RicPolicyStyleList struct {
245 Text string `xml:",chardata"`
246 RicPolicyStyleList []RicPolicyStyleList `xml:"RIC-PolicyStyle-List"`
247 } `xml:"ric-PolicyStyle-List"`
250 type RANfunctionsList struct {
251 Text string `xml:",chardata"`
252 ProtocolIESingleContainer []struct {
253 Text string `xml:",chardata"`
256 Text string `xml:",chardata"`
257 Reject string `xml:"reject"`
258 } `xml:"criticality"`
260 Text string `xml:",chardata"`
261 RANfunctionItem RanFunctionItem `xml:"RANfunction-Item"`
263 } `xml:"ProtocolIE-SingleContainer"`
266 func (m *E2SetupRequestMessage) ExtractRanFunctionsList() []*entities.RanFunction {
267 // TODO: verify e2SetupRequestIEs structure with Adi
268 e2SetupRequestIes := m.E2APPDU.InitiatingMessage.Value.E2setupRequest.ProtocolIEs.E2setupRequestIEs
269 if len(e2SetupRequestIes) < 2 {
273 ranFunctionsListContainer := e2SetupRequestIes[1].Value.RANfunctionsList.ProtocolIESingleContainer
274 funcs := make([]*entities.RanFunction, len(ranFunctionsListContainer))
275 for i := 0; i < len(funcs); i++ {
276 ranFunctionItem := ranFunctionsListContainer[i].Value.RANfunctionItem
278 funcs[i] = &entities.RanFunction{
279 RanFunctionId: &wrappers.UInt32Value{Value: ranFunctionItem.RanFunctionID},
280 RanFunctionDefinition: m.buildRanFunctionDefinitionProto(&ranFunctionItem.RanFunctionDefinition),
281 RanFunctionRevision: &wrappers.UInt32Value{Value: ranFunctionItem.RanFunctionRevision},
287 func (m *E2SetupRequestMessage) buildRanFunctionDefinitionProto(def *RanFunctionDefinition) *entities.RanFunctionDefinition {
288 return &entities.RanFunctionDefinition{
289 E2SmGnbNrtRanFunctionDefinition: &entities.E2SmGnbNrtRanFunctionDefinition{
290 RanFunctionName: buildRanFunctionNameProto(def),
291 RicEventTriggerStyles: buildRicEventTriggerStylesProto(def),
292 RicReportStyles: buildRicReportStylesProto(def),
293 RicInsertStyles: buildRicInsertStylesProto(def),
294 RicControlStyles: buildRicControlStylesProto(def),
295 RicPolicyStyles: buildRicPolicyStylesProto(def),
300 func buildRanFunctionNameProto(def *RanFunctionDefinition) *entities.RanFunctionName {
301 defRanFunctionName := def.E2smGnbNrtRanFunctionDefinition.RanFunctionName
302 ranFunctionName := &entities.RanFunctionName{
303 RanFunctionShortName: &wrappers.StringValue{Value: defRanFunctionName.RanFunctionShortName},
304 RanFunctionE2SmOid: &wrappers.StringValue{Value: defRanFunctionName.RanFunctionE2smOid},
305 RanFunctionDescription: &wrappers.StringValue{Value: defRanFunctionName.RanFunctionDescription},
308 if defRanFunctionName.RanFunctionInstance != nil {
309 ranFunctionName.OptionalRanFunctionInstance = &entities.RanFunctionName_RanFunctionInstance{
310 RanFunctionInstance: *defRanFunctionName.RanFunctionInstance,
314 return ranFunctionName
317 func buildRicEventTriggerStylesProto(def *RanFunctionDefinition) []*entities.RicEventTriggerStyle {
318 defRicEventTriggerStyleList := def.E2smGnbNrtRanFunctionDefinition.RicEventTriggerStyleList.RicEventTriggerStyleList
319 ricEventTriggerStyles := make([]*entities.RicEventTriggerStyle, len(defRicEventTriggerStyleList))
321 for i, v := range defRicEventTriggerStyleList {
322 ricEventTriggerStyles[i] = &entities.RicEventTriggerStyle{
323 RicEventTriggerStyleType: &wrappers.UInt32Value{Value: v.RicEventTriggerStyleType},
324 RicEventTriggerStyleName: &wrappers.StringValue{Value: v.RicEventTriggerStyleName},
325 RicEventTriggerFormatType: &wrappers.UInt32Value{Value: v.RicEventTriggerFormatType},
329 return ricEventTriggerStyles
332 func buildRicReportStylesProto(def *RanFunctionDefinition) []*entities.RicReportStyle {
333 defRicReportStyleList := def.E2smGnbNrtRanFunctionDefinition.RicReportStyleList.RicReportStyleList
334 ricReportStyles := make([]*entities.RicReportStyle, len(defRicReportStyleList))
336 for i, v := range defRicReportStyleList {
337 ricReportStyles[i] = &entities.RicReportStyle{
338 RicReportStyleType: &wrappers.UInt32Value{Value: v.RicReportStyleType},
339 RicReportStyleName: &wrappers.StringValue{Value: v.RicReportStyleName},
340 RicReportActionFormatType: &wrappers.UInt32Value{Value: v.RicReportActionFormatType},
341 RicReportRanParameterDefs: buildRicReportRanParameterDefsProto(v),
342 RicIndicationHeaderFormatType: &wrappers.UInt32Value{Value: v.RicIndicationHeaderFormatType},
343 RicIndicationMessageFormatType: &wrappers.UInt32Value{Value: v.RicIndicationMessageFormatType},
347 return ricReportStyles
350 func buildRicReportRanParameterDefsProto(ricReportStyleList RicReportStyleList) []*entities.RanParameterDef {
351 ricReportRanParameterDefList := ricReportStyleList.RicReportRanParameterDefList.RanParameterDefItem
352 ranParameterDefs := make([]*entities.RanParameterDef, len(ricReportRanParameterDefList))
354 for i, v := range ricReportRanParameterDefList {
355 ranParameterDefs[i] = &entities.RanParameterDef{
356 RanParameterId: &wrappers.UInt32Value{Value: v.RanParameterID},
357 RanParameterName: &wrappers.StringValue{Value: v.RanParameterName},
358 RanParameterType: getRanParameterTypeEnumValue(v.RanParameterType),
362 return ranParameterDefs
365 func getRanParameterTypeEnumValue(ranParameterType RanParameterType) entities.RanParameterType {
366 if ranParameterType.Boolean != nil {
367 return entities.RanParameterType_BOOLEAN
370 if ranParameterType.BitString != nil {
371 return entities.RanParameterType_BIT_STRING
374 if ranParameterType.Enumerated != nil {
375 return entities.RanParameterType_ENUMERATED
378 if ranParameterType.Integer != nil {
379 return entities.RanParameterType_INTEGER
382 if ranParameterType.OctetString != nil {
383 return entities.RanParameterType_OCTET_STRING
386 if ranParameterType.PrintableString != nil {
387 return entities.RanParameterType_PRINTABLE_STRING
390 return entities.RanParameterType_UNKNOWN_RAN_PARAMETER_TYPE
393 func buildRicInsertStylesProto(def *RanFunctionDefinition) []*entities.RicInsertStyle {
394 defRicInsertStyleList := def.E2smGnbNrtRanFunctionDefinition.RicInsertStyleList.RicInsertStyleList
395 ricInsertStyles := make([]*entities.RicInsertStyle, len(defRicInsertStyleList))
397 for i, v := range defRicInsertStyleList {
398 ricInsertStyles[i] = &entities.RicInsertStyle{
399 RicInsertStyleType: &wrappers.UInt32Value{Value: v.RicInsertStyleType},
400 RicInsertStyleName: &wrappers.StringValue{Value: v.RicInsertStyleName},
401 RicInsertActionFormatType: &wrappers.UInt32Value{Value: v.RicInsertActionFormatType},
402 RicInsertRanParameterDefs: buildRicInsertRanParameterDefsProto(v),
403 RicIndicationHeaderFormatType: &wrappers.UInt32Value{Value: v.RicIndicationHeaderFormatType},
404 RicIndicationMessageFormatType: &wrappers.UInt32Value{Value: v.RicIndicationMessageFormatType},
405 RicCallProcessIdFormatType: &wrappers.UInt32Value{Value: v.RicCallProcessIdFormatType},
409 return ricInsertStyles
412 func buildRicInsertRanParameterDefsProto(ricInsertStyleList RicInsertStyleList) []*entities.RanParameterDef {
413 ricInsertRanParameterDefList := ricInsertStyleList.RicInsertRanParameterDefList.RanParameterDefItem
414 ranParameterDefs := make([]*entities.RanParameterDef, len(ricInsertRanParameterDefList))
416 for i, v := range ricInsertRanParameterDefList {
417 ranParameterDefs[i] = &entities.RanParameterDef{
418 RanParameterId: &wrappers.UInt32Value{Value: v.RanParameterID},
419 RanParameterName: &wrappers.StringValue{Value: v.RanParameterName},
420 RanParameterType: getRanParameterTypeEnumValue(v.RanParameterType),
424 return ranParameterDefs
427 func buildRicControlStylesProto(def *RanFunctionDefinition) []*entities.RicControlStyle {
428 defRicControlStyleList := def.E2smGnbNrtRanFunctionDefinition.RicControlStyleList.RicControlStyleList
429 ricControlStyles := make([]*entities.RicControlStyle, len(defRicControlStyleList))
431 for i, v := range defRicControlStyleList {
432 ricControlStyles[i] = &entities.RicControlStyle{
433 RicControlStyleType: &wrappers.UInt32Value{Value: v.RicControlStyleType},
434 RicControlStyleName: &wrappers.StringValue{Value: v.RicControlStyleName},
435 RicControlHeaderFormatType: &wrappers.UInt32Value{Value: v.RicControlHeaderFormatType},
436 RicControlMessageFormatType: &wrappers.UInt32Value{Value: v.RicControlMessageFormatType},
437 RicCallProcessIdFormatType: &wrappers.UInt32Value{Value: v.RicCallProcessIdFormatType},
441 return ricControlStyles
444 func buildRicPolicyRanParameterDefsProto(ricPolicyStyleList RicPolicyStyleList) []*entities.RanParameterDef {
445 ricPolicyRanParameterDefList := ricPolicyStyleList.RicPolicyRanParameterDefList.RanParameterDefItem
446 ranParameterDefs := make([]*entities.RanParameterDef, len(ricPolicyRanParameterDefList))
448 for i, v := range ricPolicyRanParameterDefList {
449 ranParameterDefs[i] = &entities.RanParameterDef{
450 RanParameterId: &wrappers.UInt32Value{Value: v.RanParameterID},
451 RanParameterName: &wrappers.StringValue{Value: v.RanParameterName},
452 RanParameterType: getRanParameterTypeEnumValue(v.RanParameterType),
456 return ranParameterDefs
459 func buildRicPolicyStylesProto(def *RanFunctionDefinition) []*entities.RicPolicyStyle {
460 defRicPolicyStyleList := def.E2smGnbNrtRanFunctionDefinition.RicPolicyStyleList.RicPolicyStyleList
461 ricPolicyStyles := make([]*entities.RicPolicyStyle, len(defRicPolicyStyleList))
463 for i, v := range defRicPolicyStyleList {
464 ricPolicyStyles[i] = &entities.RicPolicyStyle{
465 RicPolicyStyleType: &wrappers.UInt32Value{Value: v.RicPolicyStyleType},
466 RicPolicyStyleName: &wrappers.StringValue{Value: v.RicPolicyStyleName},
467 RicPolicyActionFormatType: &wrappers.UInt32Value{Value: v.RicPolicyActionFormatType},
468 RicPolicyRanParameterDefs: buildRicPolicyRanParameterDefsProto(v),
472 return ricPolicyStyles
475 func (m *E2SetupRequestMessage) getGlobalE2NodeId() GlobalE2NodeId {
476 return m.E2APPDU.InitiatingMessage.Value.E2setupRequest.ProtocolIEs.E2setupRequestIEs[0].Value.GlobalE2nodeID
479 func (m *E2SetupRequestMessage) GetPlmnId() string {
480 globalE2NodeId := m.getGlobalE2NodeId()
481 if id := globalE2NodeId.GNB.GlobalGNBID.PlmnID; id != "" {
482 return m.trimSpaces(id)
484 if id := globalE2NodeId.EnGNB.GlobalGNBID.PlmnID; id != "" {
485 return m.trimSpaces(id)
487 if id := globalE2NodeId.ENB.GlobalENBID.PlmnID; id != "" {
488 return m.trimSpaces(id)
490 if id := globalE2NodeId.NgENB.GlobalNgENBID.PlmnID; id != "" {
491 return m.trimSpaces(id)
496 func (m *E2SetupRequestMessage) getInnerEnbId(enbId EnbId) string {
498 if id := enbId.HomeEnbId; id != "" {
502 if id := enbId.LongMacroEnbId; id != "" {
506 if id := enbId.MacroEnbId; id != "" {
510 if id := enbId.ShortMacroEnbId; id != "" {
517 func (m *E2SetupRequestMessage) getInnerNgEnbId(enbId NgEnbId) string {
518 if id := enbId.EnbIdLongMacro; id != "" {
522 if id := enbId.EnbIdMacro; id != "" {
526 if id := enbId.EnbIdShortMacro; id != "" {
533 func (m *E2SetupRequestMessage) GetNbId() string {
534 globalE2NodeId := m.getGlobalE2NodeId()
536 if id := globalE2NodeId.GNB.GlobalGNBID.GnbID.GnbID; id != "" {
537 return m.trimSpaces(id)
540 if id := globalE2NodeId.EnGNB.GlobalGNBID.GnbID.GnbID; id != "" {
541 return m.trimSpaces(id)
544 if id := m.getInnerEnbId(globalE2NodeId.ENB.GlobalENBID.EnbID); id != "" {
545 return m.trimSpaces(id)
548 if id := m.getInnerNgEnbId(globalE2NodeId.NgENB.GlobalNgENBID.EnbID); id != "" {
549 return m.trimSpaces(id)
555 func (m *E2SetupRequestMessage) trimSpaces(str string) string {
556 return strings.NewReplacer(" ", "", "\n", "").Replace(str)