blob: f233bc47330a31535d662f765d65745a6344a88a [file] [log] [blame]
kalnagy45114752019-06-18 14:40:39 +02001/*
2==================================================================================
3 Copyright (c) 2019 AT&T Intellectual Property.
4 Copyright (c) 2019 Nokia
5
6 Licensed under the Apache License, Version 2.0 (the "License");
7 you may not use this file except in compliance with the License.
8 You may obtain a copy of the License at
9
10 http://www.apache.org/licenses/LICENSE-2.0
11
12 Unless required by applicable law or agreed to in writing, software
13 distributed under the License is distributed on an "AS IS" BASIS,
14 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 See the License for the specific language governing permissions and
16 limitations under the License.
17==================================================================================
18*/
19
20package control
21
Peter Szilagyifbc56f92019-07-23 19:29:46 +000022/*
Juha Hyttinenff8dccd2019-12-10 14:34:07 +020023#cgo LDFLAGS: -le2ap_wrapper -le2ap
Peter Szilagyifbc56f92019-07-23 19:29:46 +000024*/
25import "C"
26
kalnagy45114752019-06-18 14:40:39 +020027import (
Juha Hyttinen662f68d2020-01-15 14:49:18 +020028 "encoding/hex"
Anssi Mannila56233b02022-01-24 13:26:42 +020029 "encoding/json"
Juha Hyttinen662f68d2020-01-15 14:49:18 +020030 "fmt"
Markku Virtanenfa39fed2021-05-25 08:18:43 +000031
Anssi Mannila8046c702020-01-02 13:39:05 +020032 "gerrit.o-ran-sc.org/r/ric-plt/e2ap/pkg/e2ap"
33 "gerrit.o-ran-sc.org/r/ric-plt/e2ap/pkg/e2ap_wrapper"
archaggeafbf95f2021-04-14 08:54:05 +030034 "gerrit.o-ran-sc.org/r/ric-plt/xapp-frame/pkg/models"
Juha Hyttinen63284a22020-01-15 10:45:11 +020035 "gerrit.o-ran-sc.org/r/ric-plt/xapp-frame/pkg/xapp"
kalnagy45114752019-06-18 14:40:39 +020036)
37
Anssi Mannila8046c702020-01-02 13:39:05 +020038var packerif e2ap.E2APPackerIf = e2ap_wrapper.NewAsn1E2Packer()
39
Markku Virtanenfa39fed2021-05-25 08:18:43 +000040func GetPackerIf() e2ap.E2APPackerIf {
41 return packerif
42}
43
44func SetPackerIf(iface e2ap.E2APPackerIf) {
45 packerif = iface
46}
47
kalnagy45114752019-06-18 14:40:39 +020048type E2ap struct {
49}
50
Juha Hyttinen86a46202020-01-14 12:49:09 +020051//-----------------------------------------------------------------------------
52//
53//-----------------------------------------------------------------------------
Anssi Mannila56233b02022-01-24 13:26:42 +020054func (e *E2ap) SetASN1DebugPrintStatus(logLevel int) {
Anssi Mannilae1af87f2021-11-10 13:10:54 +020055 e2ap_wrapper.SetASN1DebugPrintStatus(logLevel)
56}
57
Himanshu Puorhit84662c42023-08-29 15:46:18 +053058func (e *E2ap) SetE2IEOrderCheck(ieOrderCheck uint8) {
59 e2ap_wrapper.SetE2IEOrderCheck(ieOrderCheck)
60}
61
Anssi Mannilae1af87f2021-11-10 13:10:54 +020062//-----------------------------------------------------------------------------
63//
64//-----------------------------------------------------------------------------
Anssi Mannila56233b02022-01-24 13:26:42 +020065func (e *E2ap) FillSubscriptionReqMsgs(params interface{}, subreqList *e2ap.SubscriptionRequestList, restSubscription *RESTSubscription) error {
Anssi Mannilaf682ace2021-09-28 13:11:25 +030066 xapp.Logger.Debug("FillSubscriptionReqMsgs")
archaggeafbf95f2021-04-14 08:54:05 +030067
68 p := params.(*models.SubscriptionParams)
69
70 for _, subscriptionDetail := range p.SubscriptionDetails {
71 subReqMsg := e2ap.E2APSubscriptionRequest{}
72
73 if p.RANFunctionID != nil {
74 subReqMsg.FunctionId = (e2ap.FunctionId)(*p.RANFunctionID)
75 }
Konstantinos Archangelofe93b00f2021-06-03 10:00:19 +000076 e2EventInstanceID := restSubscription.GetE2IdFromXappIdToE2Id(*subscriptionDetail.XappEventInstanceID)
77 subReqMsg.RequestId = e2ap.RequestId{uint32(*subscriptionDetail.XappEventInstanceID), uint32(e2EventInstanceID)}
archaggeafbf95f2021-04-14 08:54:05 +030078
Konstantinos Archangelofbd9c98e2021-06-07 17:32:10 +000079 if len(subscriptionDetail.EventTriggers) > 0 {
80 for _, val := range subscriptionDetail.EventTriggers {
81 subReqMsg.EventTriggerDefinition.Data.Data = append(subReqMsg.EventTriggerDefinition.Data.Data, byte(val))
82 }
83 subReqMsg.EventTriggerDefinition.Data.Length = uint64(len(subscriptionDetail.EventTriggers))
84 }
archaggeafbf95f2021-04-14 08:54:05 +030085 for _, actionToBeSetup := range subscriptionDetail.ActionToBeSetupList {
86 actionToBeSetupItem := e2ap.ActionToBeSetupItem{}
87 actionToBeSetupItem.ActionType = e2ap.E2AP_ActionTypeInvalid
88 actionToBeSetupItem.ActionId = uint64(*actionToBeSetup.ActionID)
89
90 actionToBeSetupItem.ActionType = e2ap.E2AP_ActionTypeStrMap[*actionToBeSetup.ActionType]
91 actionToBeSetupItem.RicActionDefinitionPresent = true
92
Konstantinos Archangelofbd9c98e2021-06-07 17:32:10 +000093 if len(actionToBeSetup.ActionDefinition) > 0 {
94 for _, val := range actionToBeSetup.ActionDefinition {
95 actionToBeSetupItem.ActionDefinitionChoice.Data.Data = append(actionToBeSetupItem.ActionDefinitionChoice.Data.Data, byte(val))
96 }
97 actionToBeSetupItem.ActionDefinitionChoice.Data.Length = uint64(len(actionToBeSetup.ActionDefinition))
archaggeafbf95f2021-04-14 08:54:05 +030098
99 }
100 if actionToBeSetup.SubsequentAction != nil {
101 actionToBeSetupItem.SubsequentAction.Present = true
102 actionToBeSetupItem.SubsequentAction.Type = e2ap.E2AP_SubSeqActionTypeStrMap[*actionToBeSetup.SubsequentAction.SubsequentActionType]
103 actionToBeSetupItem.SubsequentAction.TimetoWait = e2ap.E2AP_TimeToWaitStrMap[*actionToBeSetup.SubsequentAction.TimeToWait]
104 }
105 subReqMsg.ActionSetups = append(subReqMsg.ActionSetups, actionToBeSetupItem)
106 }
107 subreqList.E2APSubscriptionRequests = append(subreqList.E2APSubscriptionRequests, subReqMsg)
108 }
109 return nil
110}
111
112//-----------------------------------------------------------------------------
113//
114//-----------------------------------------------------------------------------
Anssi Mannila56233b02022-01-24 13:26:42 +0200115func (e *E2ap) CheckActionNotAdmittedList(msgType int, actionNotAdmittedList e2ap.ActionNotAdmittedList, c *Control) ErrorInfo {
116
117 var prefixString string
118 var errorInfo ErrorInfo
119 var actionNotAdmittedString string
120 if len(actionNotAdmittedList.Items) > 0 {
121 if msgType == xapp.RIC_SUB_RESP {
122 prefixString = "RICSubscriptionResponse partially accepted:"
123 c.UpdateCounter(cPartialSubRespFromE2)
124 } else if msgType == xapp.RIC_SUB_FAILURE {
125 prefixString = "RICSubscriptionFailure:"
126 }
127 jsonActionNotAdmittedList, err := json.Marshal(actionNotAdmittedList.Items)
128 if err != nil {
129 actionNotAdmittedString = "ActionNotAdmittedList > 0. Submgr json.Marshal error"
130 xapp.Logger.Error("CheckActionNotAdmittedList() json.Marshal error %s", err.Error())
131 } else {
132 actionNotAdmittedString = "ActionNotAdmittedList: " + string(jsonActionNotAdmittedList)
133 }
134 }
Anssi Mannila6bd57912022-06-16 09:47:23 +0300135
136 if msgType == xapp.RIC_SUB_FAILURE {
137 prefixString = "RICSubscriptionFailure"
138 err := fmt.Errorf("%s", prefixString)
139 errorInfo.SetInfo(err.Error(), models.SubscriptionInstanceErrorSourceE2Node, "")
140 }
Anssi Mannila56233b02022-01-24 13:26:42 +0200141 err := fmt.Errorf("%s %s", prefixString, actionNotAdmittedString)
142 errorInfo.SetInfo(err.Error(), models.SubscriptionInstanceErrorSourceE2Node, "")
143 return errorInfo
144}
145
146//-----------------------------------------------------------------------------
147//
148//-----------------------------------------------------------------------------
149func (e *E2ap) UnpackSubscriptionRequest(payload []byte) (*e2ap.E2APSubscriptionRequest, error) {
Anssi Mannila8046c702020-01-02 13:39:05 +0200150 e2SubReq := packerif.NewPackerSubscriptionRequest()
Juha Hyttinena9bf76c2020-02-05 14:06:57 +0200151 err, subReq := e2SubReq.UnPack(&e2ap.PackedData{payload})
Juha Hyttinen86a46202020-01-14 12:49:09 +0200152 if err != nil {
Juha Hyttinen662f68d2020-01-15 14:49:18 +0200153 return nil, fmt.Errorf("%s buf[%s]", err.Error(), hex.EncodeToString(payload))
Anssi Mannila8046c702020-01-02 13:39:05 +0200154 }
Juha Hyttinen86a46202020-01-14 12:49:09 +0200155 return subReq, nil
156}
Anssi Mannila8046c702020-01-02 13:39:05 +0200157
Juha Hyttinena9bf76c2020-02-05 14:06:57 +0200158func (c *E2ap) PackSubscriptionRequest(req *e2ap.E2APSubscriptionRequest) (int, *e2ap.PackedData, error) {
Juha Hyttinen86a46202020-01-14 12:49:09 +0200159 e2SubReq := packerif.NewPackerSubscriptionRequest()
Juha Hyttinen01a4c492020-02-04 19:29:26 +0200160 err, packedData := e2SubReq.Pack(req)
Anssi Mannila8046c702020-01-02 13:39:05 +0200161 if err != nil {
Juha Hyttinen63284a22020-01-15 10:45:11 +0200162 return 0, nil, err
Anssi Mannila8046c702020-01-02 13:39:05 +0200163 }
Juha Hyttinen63284a22020-01-15 10:45:11 +0200164 return xapp.RIC_SUB_REQ, packedData, nil
Juha Hyttinen86a46202020-01-14 12:49:09 +0200165}
166
167//-----------------------------------------------------------------------------
168//
169//-----------------------------------------------------------------------------
Anssi Mannila56233b02022-01-24 13:26:42 +0200170func (e *E2ap) UnpackSubscriptionResponse(payload []byte) (*e2ap.E2APSubscriptionResponse, error) {
Juha Hyttinenaafee7f2020-01-14 14:54:51 +0200171 e2SubResp := packerif.NewPackerSubscriptionResponse()
Juha Hyttinena9bf76c2020-02-05 14:06:57 +0200172 err, subResp := e2SubResp.UnPack(&e2ap.PackedData{payload})
Juha Hyttinenaafee7f2020-01-14 14:54:51 +0200173 if err != nil {
Juha Hyttinen662f68d2020-01-15 14:49:18 +0200174 return nil, fmt.Errorf("%s buf[%s]", err.Error(), hex.EncodeToString(payload))
Juha Hyttinenaafee7f2020-01-14 14:54:51 +0200175 }
176 return subResp, nil
177}
178
Anssi Mannila56233b02022-01-24 13:26:42 +0200179func (e *E2ap) PackSubscriptionResponse(req *e2ap.E2APSubscriptionResponse) (int, *e2ap.PackedData, error) {
Juha Hyttinenaafee7f2020-01-14 14:54:51 +0200180 e2SubResp := packerif.NewPackerSubscriptionResponse()
Juha Hyttinen01a4c492020-02-04 19:29:26 +0200181 err, packedData := e2SubResp.Pack(req)
Juha Hyttinenaafee7f2020-01-14 14:54:51 +0200182 if err != nil {
Juha Hyttinen63284a22020-01-15 10:45:11 +0200183 return 0, nil, err
Juha Hyttinenaafee7f2020-01-14 14:54:51 +0200184 }
Juha Hyttinen63284a22020-01-15 10:45:11 +0200185 return xapp.RIC_SUB_RESP, packedData, nil
Juha Hyttinenaafee7f2020-01-14 14:54:51 +0200186}
187
188//-----------------------------------------------------------------------------
189//
190//-----------------------------------------------------------------------------
Anssi Mannila56233b02022-01-24 13:26:42 +0200191func (e *E2ap) UnpackSubscriptionFailure(payload []byte) (*e2ap.E2APSubscriptionFailure, error) {
Juha Hyttinen60bfcf92020-01-14 15:14:24 +0200192 e2SubFail := packerif.NewPackerSubscriptionFailure()
Juha Hyttinena9bf76c2020-02-05 14:06:57 +0200193 err, subFail := e2SubFail.UnPack(&e2ap.PackedData{payload})
Juha Hyttinen60bfcf92020-01-14 15:14:24 +0200194 if err != nil {
Juha Hyttinen662f68d2020-01-15 14:49:18 +0200195 return nil, fmt.Errorf("%s buf[%s]", err.Error(), hex.EncodeToString(payload))
Juha Hyttinen60bfcf92020-01-14 15:14:24 +0200196 }
197 return subFail, nil
198}
199
Anssi Mannila56233b02022-01-24 13:26:42 +0200200func (e *E2ap) PackSubscriptionFailure(req *e2ap.E2APSubscriptionFailure) (int, *e2ap.PackedData, error) {
Juha Hyttinen60bfcf92020-01-14 15:14:24 +0200201 e2SubFail := packerif.NewPackerSubscriptionFailure()
Juha Hyttinen01a4c492020-02-04 19:29:26 +0200202 err, packedData := e2SubFail.Pack(req)
Juha Hyttinen60bfcf92020-01-14 15:14:24 +0200203 if err != nil {
Juha Hyttinen63284a22020-01-15 10:45:11 +0200204 return 0, nil, err
Juha Hyttinen60bfcf92020-01-14 15:14:24 +0200205 }
Juha Hyttinen63284a22020-01-15 10:45:11 +0200206 return xapp.RIC_SUB_FAILURE, packedData, nil
Juha Hyttinen60bfcf92020-01-14 15:14:24 +0200207}
208
209//-----------------------------------------------------------------------------
210//
211//-----------------------------------------------------------------------------
Anssi Mannila56233b02022-01-24 13:26:42 +0200212func (e *E2ap) UnpackSubscriptionDeleteRequest(payload []byte) (*e2ap.E2APSubscriptionDeleteRequest, error) {
Juha Hyttinen86a46202020-01-14 12:49:09 +0200213 e2SubDelReq := packerif.NewPackerSubscriptionDeleteRequest()
Juha Hyttinena9bf76c2020-02-05 14:06:57 +0200214 err, subDelReq := e2SubDelReq.UnPack(&e2ap.PackedData{payload})
Juha Hyttinen86a46202020-01-14 12:49:09 +0200215 if err != nil {
Juha Hyttinen662f68d2020-01-15 14:49:18 +0200216 return nil, fmt.Errorf("%s buf[%s]", err.Error(), hex.EncodeToString(payload))
Juha Hyttinen86a46202020-01-14 12:49:09 +0200217 }
Juha Hyttinenaafee7f2020-01-14 14:54:51 +0200218 return subDelReq, nil
Juha Hyttinen86a46202020-01-14 12:49:09 +0200219}
220
Anssi Mannila56233b02022-01-24 13:26:42 +0200221func (e *E2ap) PackSubscriptionDeleteRequest(req *e2ap.E2APSubscriptionDeleteRequest) (int, *e2ap.PackedData, error) {
Juha Hyttinen86a46202020-01-14 12:49:09 +0200222 e2SubDelReq := packerif.NewPackerSubscriptionDeleteRequest()
Juha Hyttinen01a4c492020-02-04 19:29:26 +0200223 err, packedData := e2SubDelReq.Pack(req)
Juha Hyttinen86a46202020-01-14 12:49:09 +0200224 if err != nil {
Juha Hyttinen63284a22020-01-15 10:45:11 +0200225 return 0, nil, err
Juha Hyttinen86a46202020-01-14 12:49:09 +0200226 }
Juha Hyttinen63284a22020-01-15 10:45:11 +0200227 return xapp.RIC_SUB_DEL_REQ, packedData, nil
Juha Hyttinen86a46202020-01-14 12:49:09 +0200228}
229
Juha Hyttinenaafee7f2020-01-14 14:54:51 +0200230//-----------------------------------------------------------------------------
231//
232//-----------------------------------------------------------------------------
Anssi Mannila56233b02022-01-24 13:26:42 +0200233func (e *E2ap) UnpackSubscriptionDeleteResponse(payload []byte) (*e2ap.E2APSubscriptionDeleteResponse, error) {
Juha Hyttinenaafee7f2020-01-14 14:54:51 +0200234 e2SubDelResp := packerif.NewPackerSubscriptionDeleteResponse()
Juha Hyttinena9bf76c2020-02-05 14:06:57 +0200235 err, subDelResp := e2SubDelResp.UnPack(&e2ap.PackedData{payload})
Juha Hyttinenaafee7f2020-01-14 14:54:51 +0200236 if err != nil {
Juha Hyttinen662f68d2020-01-15 14:49:18 +0200237 return nil, fmt.Errorf("%s buf[%s]", err.Error(), hex.EncodeToString(payload))
Juha Hyttinenaafee7f2020-01-14 14:54:51 +0200238 }
239 return subDelResp, nil
240}
241
Anssi Mannila56233b02022-01-24 13:26:42 +0200242func (e *E2ap) PackSubscriptionDeleteResponse(req *e2ap.E2APSubscriptionDeleteResponse) (int, *e2ap.PackedData, error) {
Juha Hyttinen86a46202020-01-14 12:49:09 +0200243 e2SubDelResp := packerif.NewPackerSubscriptionDeleteResponse()
Juha Hyttinen01a4c492020-02-04 19:29:26 +0200244 err, packedData := e2SubDelResp.Pack(req)
Juha Hyttinen86a46202020-01-14 12:49:09 +0200245 if err != nil {
Juha Hyttinen63284a22020-01-15 10:45:11 +0200246 return 0, nil, err
Juha Hyttinen86a46202020-01-14 12:49:09 +0200247 }
Juha Hyttinen63284a22020-01-15 10:45:11 +0200248 return xapp.RIC_SUB_DEL_RESP, packedData, nil
Anssi Mannila8046c702020-01-02 13:39:05 +0200249}
Juha Hyttinen375c1412020-01-14 20:17:50 +0200250
251//-----------------------------------------------------------------------------
252//
253//-----------------------------------------------------------------------------
Anssi Mannila56233b02022-01-24 13:26:42 +0200254func (e *E2ap) UnpackSubscriptionDeleteFailure(payload []byte) (*e2ap.E2APSubscriptionDeleteFailure, error) {
Juha Hyttinen375c1412020-01-14 20:17:50 +0200255 e2SubDelFail := packerif.NewPackerSubscriptionDeleteFailure()
Juha Hyttinena9bf76c2020-02-05 14:06:57 +0200256 err, subDelFail := e2SubDelFail.UnPack(&e2ap.PackedData{payload})
Juha Hyttinen375c1412020-01-14 20:17:50 +0200257 if err != nil {
Juha Hyttinen662f68d2020-01-15 14:49:18 +0200258 return nil, fmt.Errorf("%s buf[%s]", err.Error(), hex.EncodeToString(payload))
Juha Hyttinen375c1412020-01-14 20:17:50 +0200259 }
260 return subDelFail, nil
261}
262
Konstantinos Archangelof37f85a02021-05-24 12:30:06 +0000263/*
Anssi Mannila56233b02022-01-24 13:26:42 +0200264func (e *E2ap) PackSubscriptionDeleteFailure(req *e2ap.E2APSubscriptionDeleteFailure) (int, *e2ap.PackedData, error) {
Juha Hyttinen375c1412020-01-14 20:17:50 +0200265 e2SubDelFail := packerif.NewPackerSubscriptionDeleteFailure()
Juha Hyttinen01a4c492020-02-04 19:29:26 +0200266 err, packedData := e2SubDelFail.Pack(req)
Juha Hyttinen375c1412020-01-14 20:17:50 +0200267 if err != nil {
Juha Hyttinen63284a22020-01-15 10:45:11 +0200268 return 0, nil, err
Juha Hyttinen375c1412020-01-14 20:17:50 +0200269 }
Juha Hyttinen63284a22020-01-15 10:45:11 +0200270 return xapp.RIC_SUB_DEL_FAILURE, packedData, nil
Juha Hyttinen375c1412020-01-14 20:17:50 +0200271}
Konstantinos Archangelof37f85a02021-05-24 12:30:06 +0000272*/
gunjarastogi4378baf2023-01-18 17:51:55 +0530273
274//-----------------------------------------------------------------------------
275// Changes to support "RIC_SUB_DEL_REQUIRED"
276//-----------------------------------------------------------------------------
277func (c *E2ap) UnpackSubscriptionDeleteRequired(payload []byte) (*e2ap.SubscriptionDeleteRequiredList, error) {
278 e2SubDelRequ := packerif.NewPackerSubscriptionDeleteRequired()
279 err, subsToBeRemove := e2SubDelRequ.UnPack(&e2ap.PackedData{payload})
280 if err != nil {
281 return nil, fmt.Errorf("%s buf[%s]", err.Error(), hex.EncodeToString(payload))
282 }
283 return subsToBeRemove, nil
284}
285
286func (c *E2ap) PackSubscriptionDeleteRequired(req *e2ap.SubscriptionDeleteRequiredList) (int, *e2ap.PackedData, error) {
287 e2SubDelRequ := packerif.NewPackerSubscriptionDeleteRequired()
288 err, packedData := e2SubDelRequ.Pack(req)
289 if err != nil {
290 return 0, nil, err
291 }
292 return xapp.RIC_SUB_DEL_REQUIRED, packedData, nil
293}