X-Git-Url: https://gerrit.o-ran-sc.org/r/gitweb?a=blobdiff_plain;f=pkg%2Fcontrol%2Fe2ap.go;h=f17012bcc6809d8ad0f35c9c37474b0898b5e685;hb=e5e672c043d80c7a531b9d6d640ca8879d9bf01b;hp=8f7fb6387de5ceb92dbb2d18a5c5bcc19a1f47a8;hpb=375c141ce21767f7bda94ec435fdf833b41fbbd2;p=ric-plt%2Fsubmgr.git diff --git a/pkg/control/e2ap.go b/pkg/control/e2ap.go index 8f7fb63..f17012b 100644 --- a/pkg/control/e2ap.go +++ b/pkg/control/e2ap.go @@ -20,52 +20,96 @@ package control /* -#include - #cgo LDFLAGS: -le2ap_wrapper -le2ap */ import "C" import ( + "encoding/hex" + "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" + "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() +func GetPackerIf() e2ap.E2APPackerIf { + return packerif +} + +func SetPackerIf(iface e2ap.E2APPackerIf) { + packerif = iface +} + type E2ap struct { } +//----------------------------------------------------------------------------- +// +//----------------------------------------------------------------------------- +func (c *E2ap) FillSubscriptionReqMsgs(params interface{}, subreqList *e2ap.SubscriptionRequestList, restSubscription *RESTSubscription) error { + xapp.Logger.Info("FillSubscriptionReqMsgs") + + p := params.(*models.SubscriptionParams) + + for _, subscriptionDetail := range p.SubscriptionDetails { + subReqMsg := e2ap.E2APSubscriptionRequest{} + + if p.RANFunctionID != nil { + subReqMsg.FunctionId = (e2ap.FunctionId)(*p.RANFunctionID) + } + subReqMsg.RequestId = e2ap.RequestId{uint32(*subscriptionDetail.RequestorID), uint32(*subscriptionDetail.InstanceID)} + + subReqMsg.EventTriggerDefinition.Data.Data = []byte(subscriptionDetail.EventTriggers.OctetString) + subReqMsg.EventTriggerDefinition.Data.Length = uint64(len(subscriptionDetail.EventTriggers.OctetString)) + + 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 actionToBeSetup.ActionDefinition != nil { + actionToBeSetupItem.ActionDefinitionChoice.Data.Data = []byte(actionToBeSetup.ActionDefinition.OctetString) + actionToBeSetupItem.ActionDefinitionChoice.Data.Length = uint64(len(actionToBeSetup.ActionDefinition.OctetString)) + + } + 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 nil +} + //----------------------------------------------------------------------------- // //----------------------------------------------------------------------------- func (c *E2ap) UnpackSubscriptionRequest(payload []byte) (*e2ap.E2APSubscriptionRequest, error) { e2SubReq := packerif.NewPackerSubscriptionRequest() - packedData := &packer.PackedData{} - packedData.Buf = payload - err := e2SubReq.UnPack(packedData) + err, subReq := e2SubReq.UnPack(&e2ap.PackedData{payload}) if err != nil { - return nil, err - } - err, subReq := e2SubReq.Get() - if err != nil { - return nil, err + return nil, fmt.Errorf("%s buf[%s]", err.Error(), hex.EncodeToString(payload)) } return subReq, nil } -func (c *E2ap) PackSubscriptionRequest(req *e2ap.E2APSubscriptionRequest) (*packer.PackedData, error) { +func (c *E2ap) PackSubscriptionRequest(req *e2ap.E2APSubscriptionRequest) (int, *e2ap.PackedData, error) { e2SubReq := packerif.NewPackerSubscriptionRequest() - err := e2SubReq.Set(req) - if err != nil { - return nil, err - } - err, packedData := e2SubReq.Pack(nil) + err, packedData := e2SubReq.Pack(req) if err != nil { - return nil, err + return 0, nil, err } - return packedData, nil + return xapp.RIC_SUB_REQ, packedData, nil } //----------------------------------------------------------------------------- @@ -73,30 +117,20 @@ func (c *E2ap) PackSubscriptionRequest(req *e2ap.E2APSubscriptionRequest) (*pack //----------------------------------------------------------------------------- func (c *E2ap) UnpackSubscriptionResponse(payload []byte) (*e2ap.E2APSubscriptionResponse, error) { e2SubResp := packerif.NewPackerSubscriptionResponse() - packedData := &packer.PackedData{} - packedData.Buf = payload - err := e2SubResp.UnPack(packedData) - if err != nil { - return nil, err - } - err, subResp := e2SubResp.Get() + err, subResp := e2SubResp.UnPack(&e2ap.PackedData{payload}) if err != nil { - return nil, err + return nil, fmt.Errorf("%s buf[%s]", err.Error(), hex.EncodeToString(payload)) } return subResp, nil } -func (c *E2ap) PackSubscriptionResponse(req *e2ap.E2APSubscriptionResponse) (*packer.PackedData, error) { +func (c *E2ap) PackSubscriptionResponse(req *e2ap.E2APSubscriptionResponse) (int, *e2ap.PackedData, error) { e2SubResp := packerif.NewPackerSubscriptionResponse() - err := e2SubResp.Set(req) + err, packedData := e2SubResp.Pack(req) if err != nil { - return nil, err + return 0, nil, err } - err, packedData := e2SubResp.Pack(nil) - if err != nil { - return nil, err - } - return packedData, nil + return xapp.RIC_SUB_RESP, packedData, nil } //----------------------------------------------------------------------------- @@ -104,30 +138,20 @@ func (c *E2ap) PackSubscriptionResponse(req *e2ap.E2APSubscriptionResponse) (*pa //----------------------------------------------------------------------------- func (c *E2ap) UnpackSubscriptionFailure(payload []byte) (*e2ap.E2APSubscriptionFailure, error) { e2SubFail := packerif.NewPackerSubscriptionFailure() - packedData := &packer.PackedData{} - packedData.Buf = payload - err := e2SubFail.UnPack(packedData) - if err != nil { - return nil, err - } - err, subFail := e2SubFail.Get() + err, subFail := e2SubFail.UnPack(&e2ap.PackedData{payload}) if err != nil { - return nil, err + return nil, fmt.Errorf("%s buf[%s]", err.Error(), hex.EncodeToString(payload)) } return subFail, nil } -func (c *E2ap) PackSubscriptionFailure(req *e2ap.E2APSubscriptionFailure) (*packer.PackedData, error) { +func (c *E2ap) PackSubscriptionFailure(req *e2ap.E2APSubscriptionFailure) (int, *e2ap.PackedData, error) { e2SubFail := packerif.NewPackerSubscriptionFailure() - err := e2SubFail.Set(req) - if err != nil { - return nil, err - } - err, packedData := e2SubFail.Pack(nil) + err, packedData := e2SubFail.Pack(req) if err != nil { - return nil, err + return 0, nil, err } - return packedData, nil + return xapp.RIC_SUB_FAILURE, packedData, nil } //----------------------------------------------------------------------------- @@ -135,30 +159,20 @@ func (c *E2ap) PackSubscriptionFailure(req *e2ap.E2APSubscriptionFailure) (*pack //----------------------------------------------------------------------------- func (c *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 nil, err - } - err, subDelReq := e2SubDelReq.Get() - if err != nil { - return nil, err + return nil, fmt.Errorf("%s buf[%s]", err.Error(), hex.EncodeToString(payload)) } return subDelReq, nil } -func (c *E2ap) PackSubscriptionDeleteRequest(req *e2ap.E2APSubscriptionDeleteRequest) (*packer.PackedData, error) { +func (c *E2ap) PackSubscriptionDeleteRequest(req *e2ap.E2APSubscriptionDeleteRequest) (int, *e2ap.PackedData, error) { e2SubDelReq := packerif.NewPackerSubscriptionDeleteRequest() - err := e2SubDelReq.Set(req) + err, packedData := e2SubDelReq.Pack(req) if err != nil { - return nil, err + return 0, nil, err } - err, packedData := e2SubDelReq.Pack(nil) - if err != nil { - return nil, err - } - return packedData, nil + return xapp.RIC_SUB_DEL_REQ, packedData, nil } //----------------------------------------------------------------------------- @@ -166,30 +180,20 @@ func (c *E2ap) PackSubscriptionDeleteRequest(req *e2ap.E2APSubscriptionDeleteReq //----------------------------------------------------------------------------- func (c *E2ap) UnpackSubscriptionDeleteResponse(payload []byte) (*e2ap.E2APSubscriptionDeleteResponse, error) { e2SubDelResp := packerif.NewPackerSubscriptionDeleteResponse() - packedData := &packer.PackedData{} - packedData.Buf = payload - err := e2SubDelResp.UnPack(packedData) - if err != nil { - return nil, err - } - err, subDelResp := e2SubDelResp.Get() + err, subDelResp := e2SubDelResp.UnPack(&e2ap.PackedData{payload}) if err != nil { - return nil, err + return nil, fmt.Errorf("%s buf[%s]", err.Error(), hex.EncodeToString(payload)) } return subDelResp, nil } -func (c *E2ap) PackSubscriptionDeleteResponse(req *e2ap.E2APSubscriptionDeleteResponse) (*packer.PackedData, error) { +func (c *E2ap) PackSubscriptionDeleteResponse(req *e2ap.E2APSubscriptionDeleteResponse) (int, *e2ap.PackedData, error) { e2SubDelResp := packerif.NewPackerSubscriptionDeleteResponse() - err := e2SubDelResp.Set(req) + err, packedData := e2SubDelResp.Pack(req) if err != nil { - return nil, err + return 0, nil, err } - err, packedData := e2SubDelResp.Pack(nil) - if err != nil { - return nil, err - } - return packedData, nil + return xapp.RIC_SUB_DEL_RESP, packedData, nil } //----------------------------------------------------------------------------- @@ -197,28 +201,20 @@ func (c *E2ap) PackSubscriptionDeleteResponse(req *e2ap.E2APSubscriptionDeleteRe //----------------------------------------------------------------------------- func (c *E2ap) UnpackSubscriptionDeleteFailure(payload []byte) (*e2ap.E2APSubscriptionDeleteFailure, error) { e2SubDelFail := packerif.NewPackerSubscriptionDeleteFailure() - packedData := &packer.PackedData{} - packedData.Buf = payload - err := e2SubDelFail.UnPack(packedData) + err, subDelFail := e2SubDelFail.UnPack(&e2ap.PackedData{payload}) if err != nil { - return nil, err - } - err, subDelFail := e2SubDelFail.Get() - if err != nil { - return nil, err + return nil, fmt.Errorf("%s buf[%s]", err.Error(), hex.EncodeToString(payload)) } return subDelFail, nil } -func (c *E2ap) PackSubscriptionDeleteFailure(req *e2ap.E2APSubscriptionDeleteFailure) (*packer.PackedData, error) { +/* +func (c *E2ap) PackSubscriptionDeleteFailure(req *e2ap.E2APSubscriptionDeleteFailure) (int, *e2ap.PackedData, error) { e2SubDelFail := packerif.NewPackerSubscriptionDeleteFailure() - err := e2SubDelFail.Set(req) + err, packedData := e2SubDelFail.Pack(req) if err != nil { - return nil, err + return 0, nil, err } - err, packedData := e2SubDelFail.Pack(nil) - if err != nil { - return nil, err - } - return packedData, nil + return xapp.RIC_SUB_DEL_FAILURE, packedData, nil } +*/