X-Git-Url: https://gerrit.o-ran-sc.org/r/gitweb?a=blobdiff_plain;f=pkg%2Fcontrol%2Fe2ap.go;h=93bd42d5370b98eaf84122a3f1aec9972bdf7d73;hb=6bd579175aaa85f1dd864ad10fe4209ed6b450ea;hp=084c7eb35e888354eb0e524118ba88894961e904;hpb=8046c70a77be2de39ffda0092b1d86008145d81a;p=ric-plt%2Fsubmgr.git diff --git a/pkg/control/e2ap.go b/pkg/control/e2ap.go index 084c7eb..93bd42d 100644 --- a/pkg/control/e2ap.go +++ b/pkg/control/e2ap.go @@ -20,217 +20,249 @@ package control /* -#include - #cgo LDFLAGS: -le2ap_wrapper -le2ap */ import "C" import ( + "encoding/hex" + "encoding/json" "fmt" + "gerrit.o-ran-sc.org/r/ric-plt/e2ap/pkg/e2ap" "gerrit.o-ran-sc.org/r/ric-plt/e2ap/pkg/e2ap_wrapper" - "gerrit.o-ran-sc.org/r/ric-plt/e2ap/pkg/packer" - "unsafe" + "gerrit.o-ran-sc.org/r/ric-plt/xapp-frame/pkg/models" + "gerrit.o-ran-sc.org/r/ric-plt/xapp-frame/pkg/xapp" ) var packerif e2ap.E2APPackerIf = e2ap_wrapper.NewAsn1E2Packer() -type E2ap struct { +func GetPackerIf() e2ap.E2APPackerIf { + return packerif } -/* RICsubscriptionRequest */ - -// Used by e2t test stub -func (c *E2ap) GetSubscriptionRequestSequenceNumber(payload []byte) (subId uint16, err error) { - cptr := unsafe.Pointer(&payload[0]) - cret := C.e2ap_get_ric_subscription_request_sequence_number(cptr, C.size_t(len(payload))) - if cret < 0 { - return 0, fmt.Errorf("e2ap wrapper is unable to get Subscirption Request Sequence Number due to wrong or invalid payload. Erroxappde: %v", cret) - } - subId = uint16(cret) - return +func SetPackerIf(iface e2ap.E2APPackerIf) { + packerif = iface } -// Used by submgr, xapp test stub -func (c *E2ap) SetSubscriptionRequestSequenceNumber(payload []byte, newSubscriptionid uint16) (err error) { - cptr := unsafe.Pointer(&payload[0]) - size := C.e2ap_set_ric_subscription_request_sequence_number(cptr, C.size_t(len(payload)), C.long(newSubscriptionid)) - if size < 0 { - return fmt.Errorf("e2ap wrapper is unable to set Subscription Request Sequence Number due to wrong or invalid payload. Erroxappde: %v", size) - } - return +type E2ap struct { } -// Used by submgr, xapp test stub -func (c *E2ap) GetSubscriptionResponseSequenceNumber(payload []byte) (subId uint16, err error) { - cptr := unsafe.Pointer(&payload[0]) - cret := C.e2ap_get_ric_subscription_response_sequence_number(cptr, C.size_t(len(payload))) - if cret < 0 { - return 0, fmt.Errorf("e2ap wrapper is unable to get Subscirption Response Sequence Number due to wrong or invalid payload. Erroxappde: %v", cret) - } - subId = uint16(cret) - return +//----------------------------------------------------------------------------- +// +//----------------------------------------------------------------------------- +func (e *E2ap) SetASN1DebugPrintStatus(logLevel int) { + e2ap_wrapper.SetASN1DebugPrintStatus(logLevel) } -// Used by e2t test stub -func (c *E2ap) SetSubscriptionResponseSequenceNumber(payload []byte, newSubscriptionid uint16) (err error) { - cptr := unsafe.Pointer(&payload[0]) - size := C.e2ap_set_ric_subscription_response_sequence_number(cptr, C.size_t(len(payload)), C.long(newSubscriptionid)) - if size < 0 { - return fmt.Errorf("e2ap wrapper is unable to set Subscription Response Sequence Number due to wrong or invalid payload. Erroxappde: %v", size) +//----------------------------------------------------------------------------- +// +//----------------------------------------------------------------------------- +func (e *E2ap) FillSubscriptionReqMsgs(params interface{}, subreqList *e2ap.SubscriptionRequestList, restSubscription *RESTSubscription) error { + xapp.Logger.Debug("FillSubscriptionReqMsgs") + + p := params.(*models.SubscriptionParams) + + for _, subscriptionDetail := range p.SubscriptionDetails { + subReqMsg := e2ap.E2APSubscriptionRequest{} + + if p.RANFunctionID != nil { + subReqMsg.FunctionId = (e2ap.FunctionId)(*p.RANFunctionID) + } + e2EventInstanceID := restSubscription.GetE2IdFromXappIdToE2Id(*subscriptionDetail.XappEventInstanceID) + subReqMsg.RequestId = e2ap.RequestId{uint32(*subscriptionDetail.XappEventInstanceID), uint32(e2EventInstanceID)} + + if len(subscriptionDetail.EventTriggers) > 0 { + for _, val := range subscriptionDetail.EventTriggers { + subReqMsg.EventTriggerDefinition.Data.Data = append(subReqMsg.EventTriggerDefinition.Data.Data, byte(val)) + } + subReqMsg.EventTriggerDefinition.Data.Length = uint64(len(subscriptionDetail.EventTriggers)) + } + for _, actionToBeSetup := range subscriptionDetail.ActionToBeSetupList { + actionToBeSetupItem := e2ap.ActionToBeSetupItem{} + actionToBeSetupItem.ActionType = e2ap.E2AP_ActionTypeInvalid + actionToBeSetupItem.ActionId = uint64(*actionToBeSetup.ActionID) + + actionToBeSetupItem.ActionType = e2ap.E2AP_ActionTypeStrMap[*actionToBeSetup.ActionType] + actionToBeSetupItem.RicActionDefinitionPresent = true + + if len(actionToBeSetup.ActionDefinition) > 0 { + for _, val := range actionToBeSetup.ActionDefinition { + actionToBeSetupItem.ActionDefinitionChoice.Data.Data = append(actionToBeSetupItem.ActionDefinitionChoice.Data.Data, byte(val)) + } + actionToBeSetupItem.ActionDefinitionChoice.Data.Length = uint64(len(actionToBeSetup.ActionDefinition)) + + } + if actionToBeSetup.SubsequentAction != nil { + actionToBeSetupItem.SubsequentAction.Present = true + actionToBeSetupItem.SubsequentAction.Type = e2ap.E2AP_SubSeqActionTypeStrMap[*actionToBeSetup.SubsequentAction.SubsequentActionType] + actionToBeSetupItem.SubsequentAction.TimetoWait = e2ap.E2AP_TimeToWaitStrMap[*actionToBeSetup.SubsequentAction.TimeToWait] + } + subReqMsg.ActionSetups = append(subReqMsg.ActionSetups, actionToBeSetupItem) + } + subreqList.E2APSubscriptionRequests = append(subreqList.E2APSubscriptionRequests, subReqMsg) } - return + return nil } -/* RICsubscriptionDeleteRequest */ +//----------------------------------------------------------------------------- +// +//----------------------------------------------------------------------------- +func (e *E2ap) CheckActionNotAdmittedList(msgType int, actionNotAdmittedList e2ap.ActionNotAdmittedList, c *Control) ErrorInfo { -// Used by submgr, e2t test stub -func (c *E2ap) GetSubscriptionDeleteRequestSequenceNumber(payload []byte) (subId uint16, err error) { - cptr := unsafe.Pointer(&payload[0]) - cret := C.e2ap_get_ric_subscription_delete_request_sequence_number(cptr, C.size_t(len(payload))) - if cret < 0 { - return 0, fmt.Errorf("e2ap wrapper is unable to get Subscirption Delete Request Sequence Number due to wrong or invalid payload. Erroxappde: %v", cret) + var prefixString string + var errorInfo ErrorInfo + var actionNotAdmittedString string + if len(actionNotAdmittedList.Items) > 0 { + if msgType == xapp.RIC_SUB_RESP { + prefixString = "RICSubscriptionResponse partially accepted:" + c.UpdateCounter(cPartialSubRespFromE2) + } else if msgType == xapp.RIC_SUB_FAILURE { + prefixString = "RICSubscriptionFailure:" + } + jsonActionNotAdmittedList, err := json.Marshal(actionNotAdmittedList.Items) + if err != nil { + actionNotAdmittedString = "ActionNotAdmittedList > 0. Submgr json.Marshal error" + xapp.Logger.Error("CheckActionNotAdmittedList() json.Marshal error %s", err.Error()) + } else { + actionNotAdmittedString = "ActionNotAdmittedList: " + string(jsonActionNotAdmittedList) + } } - subId = uint16(cret) - return -} -// Used by xapp test stub -func (c *E2ap) SetSubscriptionDeleteRequestSequenceNumber(payload []byte, newSubscriptionid uint16) (err error) { - cptr := unsafe.Pointer(&payload[0]) - size := C.e2ap_set_ric_subscription_delete_request_sequence_number(cptr, C.size_t(len(payload)), C.long(newSubscriptionid)) - if size < 0 { - return fmt.Errorf("e2ap wrapper is unable to set Subscription Delete Request Sequence Number due to wrong or invalid payload. Erroxappde: %v", size) + if msgType == xapp.RIC_SUB_FAILURE { + prefixString = "RICSubscriptionFailure" + err := fmt.Errorf("%s", prefixString) + errorInfo.SetInfo(err.Error(), models.SubscriptionInstanceErrorSourceE2Node, "") } - return + err := fmt.Errorf("%s %s", prefixString, actionNotAdmittedString) + errorInfo.SetInfo(err.Error(), models.SubscriptionInstanceErrorSourceE2Node, "") + return errorInfo } -/* RICsubscriptionDeleteResponse */ - -// Used by submgr, e2t test stub -func (c *E2ap) GetSubscriptionDeleteResponseSequenceNumber(payload []byte) (subId uint16, err error) { - cptr := unsafe.Pointer(&payload[0]) - cret := C.e2ap_get_ric_subscription_delete_response_sequence_number(cptr, C.size_t(len(payload))) - if cret < 0 { - return 0, fmt.Errorf("e2ap wrapper is unable to get Subscirption Delete Response Sequence Number due to wrong or invalid payload. Erroxappde: %v", cret) +//----------------------------------------------------------------------------- +// +//----------------------------------------------------------------------------- +func (e *E2ap) UnpackSubscriptionRequest(payload []byte) (*e2ap.E2APSubscriptionRequest, error) { + e2SubReq := packerif.NewPackerSubscriptionRequest() + err, subReq := e2SubReq.UnPack(&e2ap.PackedData{payload}) + if err != nil { + return nil, fmt.Errorf("%s buf[%s]", err.Error(), hex.EncodeToString(payload)) } - subId = uint16(cret) - return + return subReq, nil } -// Used by e2t test stub -func (c *E2ap) SetSubscriptionDeleteResponseSequenceNumber(payload []byte, newSubscriptionid uint16) (err error) { - cptr := unsafe.Pointer(&payload[0]) - size := C.e2ap_set_ric_subscription_delete_response_sequence_number(cptr, C.size_t(len(payload)), C.long(newSubscriptionid)) - if size < 0 { - return fmt.Errorf("e2ap wrapper is unable to set Subscription Delete Response Sequence Number due to wrong or invalid payload. Erroxappde: %v", size) +func (c *E2ap) PackSubscriptionRequest(req *e2ap.E2APSubscriptionRequest) (int, *e2ap.PackedData, error) { + e2SubReq := packerif.NewPackerSubscriptionRequest() + err, packedData := e2SubReq.Pack(req) + if err != nil { + return 0, nil, err } - return + return xapp.RIC_SUB_REQ, packedData, nil } -/* RICsubscriptionRequestFailure */ - -// Used by submgr -func (c *E2ap) GetSubscriptionFailureSequenceNumber(payload []byte) (subId uint16, err error) { - cptr := unsafe.Pointer(&payload[0]) - cret := C.e2ap_get_ric_subscription_failure_sequence_number(cptr, C.size_t(len(payload))) - if cret < 0 { - return 0, fmt.Errorf("e2ap wrapper is unable to get Subscirption Failure Sequence Number due to wrong or invalid payload. Erroxappde: %v", cret) +//----------------------------------------------------------------------------- +// +//----------------------------------------------------------------------------- +func (e *E2ap) UnpackSubscriptionResponse(payload []byte) (*e2ap.E2APSubscriptionResponse, error) { + e2SubResp := packerif.NewPackerSubscriptionResponse() + err, subResp := e2SubResp.UnPack(&e2ap.PackedData{payload}) + if err != nil { + return nil, fmt.Errorf("%s buf[%s]", err.Error(), hex.EncodeToString(payload)) } - subId = uint16(cret) - return + return subResp, nil } -// Used by e2t test stub -func (c *E2ap) SetSubscriptionFailureSequenceNumber(payload []byte, newSubscriptionid uint16) (err error) { - cptr := unsafe.Pointer(&payload[0]) - size := C.e2ap_set_ric_subscription_failure_sequence_number(cptr, C.size_t(len(payload)), C.long(newSubscriptionid)) - if size < 0 { - return fmt.Errorf("e2ap wrapper is unable to set Subscription Failure Sequence Number due to wrong or invalid payload. Erroxappde: %v", size) +func (e *E2ap) PackSubscriptionResponse(req *e2ap.E2APSubscriptionResponse) (int, *e2ap.PackedData, error) { + e2SubResp := packerif.NewPackerSubscriptionResponse() + err, packedData := e2SubResp.Pack(req) + if err != nil { + return 0, nil, err } - return + return xapp.RIC_SUB_RESP, packedData, nil } -/* RICsubscriptionDeleteFailure */ - -// Used by submgr -func (c *E2ap) GetSubscriptionDeleteFailureSequenceNumber(payload []byte) (subId uint16, err error) { - cptr := unsafe.Pointer(&payload[0]) - cret := C.e2ap_get_ric_subscription_delete_failure_sequence_number(cptr, C.size_t(len(payload))) - if cret < 0 { - return 0, fmt.Errorf("e2ap wrapper is unable to get Subscirption Delete Failure Sequence Number due to wrong or invalid payload. Erroxappde: %v", cret) +//----------------------------------------------------------------------------- +// +//----------------------------------------------------------------------------- +func (e *E2ap) UnpackSubscriptionFailure(payload []byte) (*e2ap.E2APSubscriptionFailure, error) { + e2SubFail := packerif.NewPackerSubscriptionFailure() + err, subFail := e2SubFail.UnPack(&e2ap.PackedData{payload}) + if err != nil { + return nil, fmt.Errorf("%s buf[%s]", err.Error(), hex.EncodeToString(payload)) } - subId = uint16(cret) - return + return subFail, nil } -// Used by submgr -func (c *E2ap) SetSubscriptionDeleteFailureSequenceNumber(payload []byte, newSubscriptionid uint16) (err error) { - cptr := unsafe.Pointer(&payload[0]) - size := C.e2ap_set_ric_subscription_delete_failure_sequence_number(cptr, C.size_t(len(payload)), C.long(newSubscriptionid)) - if size < 0 { - return fmt.Errorf("e2ap wrapper is unable to set Subscription Delete Failure Sequence Number due to wrong or invalid payload. Erroxappde: %v", size) +func (e *E2ap) PackSubscriptionFailure(req *e2ap.E2APSubscriptionFailure) (int, *e2ap.PackedData, error) { + e2SubFail := packerif.NewPackerSubscriptionFailure() + err, packedData := e2SubFail.Pack(req) + if err != nil { + return 0, nil, err } - return + return xapp.RIC_SUB_FAILURE, packedData, nil } -// Used by submgr -func (c *E2ap) PackSubscriptionDeleteResponse(payload []byte, newSubscriptionid uint16) (newPayload []byte, err error) { +//----------------------------------------------------------------------------- +// +//----------------------------------------------------------------------------- +func (e *E2ap) UnpackSubscriptionDeleteRequest(payload []byte) (*e2ap.E2APSubscriptionDeleteRequest, error) { e2SubDelReq := packerif.NewPackerSubscriptionDeleteRequest() - packedData := &packer.PackedData{} - packedData.Buf = payload - err = e2SubDelReq.UnPack(packedData) + err, subDelReq := e2SubDelReq.UnPack(&e2ap.PackedData{payload}) if err != nil { - return make([]byte, 0), fmt.Errorf("PackSubDelResp: UnPack() failed: %s", err.Error()) - } - getErr, subDelReq := e2SubDelReq.Get() - if getErr != nil { - return make([]byte, 0), fmt.Errorf("PackSubDelResp: Get() failed: %s", getErr.Error()) + return nil, fmt.Errorf("%s buf[%s]", err.Error(), hex.EncodeToString(payload)) } + return subDelReq, nil +} - e2SubDelResp := packerif.NewPackerSubscriptionDeleteResponse() - subDelResp := e2ap.E2APSubscriptionDeleteResponse{} - subDelResp.RequestId.Id = subDelReq.RequestId.Id - subDelResp.RequestId.Seq = uint32(newSubscriptionid) - subDelResp.FunctionId = subDelReq.FunctionId - err = e2SubDelResp.Set(&subDelResp) +func (e *E2ap) PackSubscriptionDeleteRequest(req *e2ap.E2APSubscriptionDeleteRequest) (int, *e2ap.PackedData, error) { + e2SubDelReq := packerif.NewPackerSubscriptionDeleteRequest() + err, packedData := e2SubDelReq.Pack(req) if err != nil { - return make([]byte, 0), fmt.Errorf("PackSubDelResp: Set() failed: %s", err.Error()) + return 0, nil, err } - err, packedData = e2SubDelResp.Pack(nil) + return xapp.RIC_SUB_DEL_REQ, packedData, nil +} + +//----------------------------------------------------------------------------- +// +//----------------------------------------------------------------------------- +func (e *E2ap) UnpackSubscriptionDeleteResponse(payload []byte) (*e2ap.E2APSubscriptionDeleteResponse, error) { + e2SubDelResp := packerif.NewPackerSubscriptionDeleteResponse() + err, subDelResp := e2SubDelResp.UnPack(&e2ap.PackedData{payload}) if err != nil { - return make([]byte, 0), fmt.Errorf("PackSubDelResp: Pack() failed: %s", err.Error()) + return nil, fmt.Errorf("%s buf[%s]", err.Error(), hex.EncodeToString(payload)) } - return packedData.Buf, nil + return subDelResp, nil } -// Used by submgr -func (c *E2ap) PackSubscriptionDeleteRequest(payload []byte, newSubscriptionid uint16) (newPayload []byte, err error) { - e2SubReq := packerif.NewPackerSubscriptionRequest() - packedData := &packer.PackedData{} - packedData.Buf = payload - err = e2SubReq.UnPack(packedData) +func (e *E2ap) PackSubscriptionDeleteResponse(req *e2ap.E2APSubscriptionDeleteResponse) (int, *e2ap.PackedData, error) { + e2SubDelResp := packerif.NewPackerSubscriptionDeleteResponse() + err, packedData := e2SubDelResp.Pack(req) if err != nil { - return make([]byte, 0), fmt.Errorf("PackSubDelReq: UnPack() failed: %s", err.Error()) - } - getErr, subReq := e2SubReq.Get() - if getErr != nil { - return make([]byte, 0), fmt.Errorf("PackSubDelReq: Get() failed: %s", getErr.Error()) + return 0, nil, err } + return xapp.RIC_SUB_DEL_RESP, packedData, nil +} - e2SubDel := packerif.NewPackerSubscriptionDeleteRequest() - subDelReq := e2ap.E2APSubscriptionDeleteRequest{} - subDelReq.RequestId.Id = subReq.RequestId.Id - subDelReq.RequestId.Seq = uint32(newSubscriptionid) - subDelReq.FunctionId = subReq.FunctionId - err = e2SubDel.Set(&subDelReq) +//----------------------------------------------------------------------------- +// +//----------------------------------------------------------------------------- +func (e *E2ap) UnpackSubscriptionDeleteFailure(payload []byte) (*e2ap.E2APSubscriptionDeleteFailure, error) { + e2SubDelFail := packerif.NewPackerSubscriptionDeleteFailure() + err, subDelFail := e2SubDelFail.UnPack(&e2ap.PackedData{payload}) if err != nil { - return make([]byte, 0), fmt.Errorf("PackSubDelReq: Set() failed: %s", err.Error()) + return nil, fmt.Errorf("%s buf[%s]", err.Error(), hex.EncodeToString(payload)) } - err, packedData = e2SubDel.Pack(nil) + return subDelFail, nil +} + +/* +func (e *E2ap) PackSubscriptionDeleteFailure(req *e2ap.E2APSubscriptionDeleteFailure) (int, *e2ap.PackedData, error) { + e2SubDelFail := packerif.NewPackerSubscriptionDeleteFailure() + err, packedData := e2SubDelFail.Pack(req) if err != nil { - return make([]byte, 0), fmt.Errorf("PackSubDelReq: Pack() failed: %s", err.Error()) + return 0, nil, err } - return packedData.Buf, nil + return xapp.RIC_SUB_DEL_FAILURE, packedData, nil } +*/