package control
/*
-#include <wrapper.h>
-
#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()
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)
- if err != nil {
- return nil, err
- }
- err, subReq := e2SubReq.Get()
+ err, subReq := e2SubReq.UnPack(&e2ap.PackedData{payload})
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
}
//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------
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
}
//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------
func (c *E2ap) UnpackSubscriptionFailure(payload []byte) (*e2ap.E2APSubscriptionFailure, error) {
e2SubFail := packerif.NewPackerSubscriptionFailure()
- packedData := &packer.PackedData{}
- packedData.Buf = payload
- err := e2SubFail.UnPack(packedData)
+ err, subFail := e2SubFail.UnPack(&e2ap.PackedData{payload})
if err != nil {
- return nil, err
- }
- err, subFail := e2SubFail.Get()
- 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
}
//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------
func (c *E2ap) UnpackSubscriptionDeleteRequest(payload []byte) (*e2ap.E2APSubscriptionDeleteRequest, error) {
e2SubDelReq := packerif.NewPackerSubscriptionDeleteRequest()
- packedData := &packer.PackedData{}
- packedData.Buf = payload
- err := e2SubDelReq.UnPack(packedData)
- if err != nil {
- return nil, err
- }
- err, subDelReq := e2SubDelReq.Get()
+ err, subDelReq := e2SubDelReq.UnPack(&e2ap.PackedData{payload})
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)
- if err != nil {
- return nil, err
- }
- err, packedData := e2SubDelReq.Pack(nil)
+ err, packedData := e2SubDelReq.Pack(req)
if err != nil {
- return nil, err
+ return 0, nil, err
}
- return packedData, nil
+ return xapp.RIC_SUB_DEL_REQ, packedData, nil
}
//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------
func (c *E2ap) UnpackSubscriptionDeleteResponse(payload []byte) (*e2ap.E2APSubscriptionDeleteResponse, error) {
e2SubDelResp := packerif.NewPackerSubscriptionDeleteResponse()
- packedData := &packer.PackedData{}
- packedData.Buf = payload
- err := e2SubDelResp.UnPack(packedData)
+ err, subDelResp := e2SubDelResp.UnPack(&e2ap.PackedData{payload})
if err != nil {
- return nil, err
- }
- err, subDelResp := e2SubDelResp.Get()
- 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
}
//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------
func (c *E2ap) UnpackSubscriptionDeleteFailure(payload []byte) (*e2ap.E2APSubscriptionDeleteFailure, error) {
e2SubDelFail := packerif.NewPackerSubscriptionDeleteFailure()
- packedData := &packer.PackedData{}
- packedData.Buf = payload
- err := e2SubDelFail.UnPack(packedData)
- if err != nil {
- return nil, err
- }
- err, subDelFail := e2SubDelFail.Get()
+ err, subDelFail := e2SubDelFail.UnPack(&e2ap.PackedData{payload})
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
}
+*/