blob: d6421e54d4e52aea93a92ef9baa75a9fe7ee0bef [file] [log] [blame]
/*
==================================================================================
Copyright (c) 2019 AT&T Intellectual Property.
Copyright (c) 2019 Nokia
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
==================================================================================
*/
package teststube2ap
import (
"fmt"
"runtime/debug"
"strconv"
"testing"
"time"
"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/submgr/pkg/teststub"
clientmodel "gerrit.o-ran-sc.org/r/ric-plt/xapp-frame/pkg/clientmodel"
//"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 e2asnpacker e2ap.E2APPackerIf = e2ap_wrapper.NewAsn1E2Packer()
//-----------------------------------------------------------------------------
//
//-----------------------------------------------------------------------------
type RmrTransactionId struct {
xid string
meid *xapp.RMRMeid
}
type E2RestIds struct {
RestSubsId string
E2SubsId uint32
ErrorCause string
ErrorSource string
TimeoutType string
}
func (trans *RmrTransactionId) String() string {
meidstr := "N/A"
if trans.meid != nil {
meidstr = trans.meid.String()
}
return "trans(" + trans.xid + "/" + meidstr + ")"
}
type E2Stub struct {
teststub.RmrStubControl
xid_seq uint64
subscriptionId string
requestCount int
CallBackNotification chan int64
RESTNotification chan uint32
CallBackListedNotifications chan E2RestIds
ListedRESTNotifications chan E2RestIds
clientEndpoint clientmodel.SubscriptionParamsClientEndpoint
meid string
restSubsIdList []string
}
//-----------------------------------------------------------------------------
//
//-----------------------------------------------------------------------------
func CreateNewE2Stub(desc string, srcId teststub.RmrSrcId, rtgSvc teststub.RmrRtgSvc, stat string, mtypeseed int, ranName string, host string, RMRPort int64, HTTPPort int64) *E2Stub {
tc := &E2Stub{}
tc.RmrStubControl.Init(desc, srcId, rtgSvc, stat, mtypeseed)
tc.xid_seq = 1
tc.SetCheckXid(true)
tc.CallBackNotification = make(chan int64)
tc.RESTNotification = make(chan uint32)
tc.CallBackListedNotifications = make(chan E2RestIds)
tc.ListedRESTNotifications = make(chan E2RestIds, 2)
var endPoint clientmodel.SubscriptionParamsClientEndpoint
endPoint.Host = host
endPoint.HTTPPort = &HTTPPort
endPoint.RMRPort = &RMRPort
tc.clientEndpoint = endPoint
tc.meid = ranName
return tc
}
//-----------------------------------------------------------------------------
//
//-----------------------------------------------------------------------------
func CreateNewE2termStub(desc string, srcId teststub.RmrSrcId, rtgSvc teststub.RmrRtgSvc, stat string, mtypeseed int) *E2Stub {
tc := &E2Stub{}
tc.RmrStubControl.Init(desc, srcId, rtgSvc, stat, mtypeseed)
tc.xid_seq = 1
tc.SetCheckXid(false)
return tc
}
//-----------------------------------------------------------------------------
//
//-----------------------------------------------------------------------------
func (tc *E2Stub) NewRmrTransactionId(xid string, ranname string) *RmrTransactionId {
trans := &RmrTransactionId{}
if len(xid) == 0 {
trans.xid = tc.GetDesc() + "_XID_" + strconv.FormatUint(uint64(tc.xid_seq), 10)
tc.xid_seq++
} else {
trans.xid = xid
}
trans.meid = &xapp.RMRMeid{RanName: ranname}
tc.Debug("New test %s", trans.String())
return trans
}
//-----------------------------------------------------------------------------
//
//-----------------------------------------------------------------------------
type E2StubSubsReqParams struct {
Req *e2ap.E2APSubscriptionRequest
}
func (p *E2StubSubsReqParams) Init() {
p.Req = &e2ap.E2APSubscriptionRequest{}
p.Req.RequestId.Id = 1
p.Req.RequestId.InstanceId = 0
p.Req.FunctionId = 1
// gnb -> enb outgoing
// enb -> gnb incoming
// X2 36423-f40.doc
p.Req.EventTriggerDefinition.Data.Length = 1
p.Req.EventTriggerDefinition.Data.Data = make([]uint8, p.Req.EventTriggerDefinition.Data.Length)
p.Req.EventTriggerDefinition.Data.Data[0] = 1
p.Req.ActionSetups = make([]e2ap.ActionToBeSetupItem, 1)
p.Req.ActionSetups[0].ActionId = 0
p.Req.ActionSetups[0].ActionType = e2ap.E2AP_ActionTypeReport
p.Req.ActionSetups[0].RicActionDefinitionPresent = true
p.Req.ActionSetups[0].ActionDefinitionChoice.Data.Length = 1
p.Req.ActionSetups[0].ActionDefinitionChoice.Data.Data = make([]uint8, p.Req.ActionSetups[0].ActionDefinitionChoice.Data.Length)
p.Req.ActionSetups[0].ActionDefinitionChoice.Data.Data[0] = 1
p.Req.ActionSetups[0].SubsequentAction.Present = true
p.Req.ActionSetups[0].SubsequentAction.Type = e2ap.E2AP_SubSeqActionTypeContinue
p.Req.ActionSetups[0].SubsequentAction.TimetoWait = e2ap.E2AP_TimeToWaitZero
}
//-----------------------------------------------------------------------------
//
//-----------------------------------------------------------------------------
type E2StubSubsFailParams struct {
Req *e2ap.E2APSubscriptionRequest
Fail *e2ap.E2APSubscriptionFailure
}
func (p *E2StubSubsFailParams) Set(req *e2ap.E2APSubscriptionRequest) {
p.Req = req
p.Fail = &e2ap.E2APSubscriptionFailure{}
p.Fail.RequestId.Id = p.Req.RequestId.Id
p.Fail.RequestId.InstanceId = p.Req.RequestId.InstanceId
p.Fail.FunctionId = p.Req.FunctionId
p.Fail.ActionNotAdmittedList.Items = make([]e2ap.ActionNotAdmittedItem, len(p.Req.ActionSetups))
for index := int(0); index < len(p.Fail.ActionNotAdmittedList.Items); index++ {
p.Fail.ActionNotAdmittedList.Items[index].ActionId = p.Req.ActionSetups[index].ActionId
p.SetCauseVal(index, 5, 1)
}
}
func (p *E2StubSubsFailParams) SetCauseVal(ind int, content uint8, causeval uint8) {
if ind < 0 {
for index := int(0); index < len(p.Fail.ActionNotAdmittedList.Items); index++ {
p.Fail.ActionNotAdmittedList.Items[index].Cause.Content = content
p.Fail.ActionNotAdmittedList.Items[index].Cause.Value = causeval
}
return
}
p.Fail.ActionNotAdmittedList.Items[ind].Cause.Content = content
p.Fail.ActionNotAdmittedList.Items[ind].Cause.Value = causeval
}
//-----------------------------------------------------------------------------
//
//-----------------------------------------------------------------------------
func (tc *E2Stub) SendSubsReq(t *testing.T, rparams *E2StubSubsReqParams, oldTrans *RmrTransactionId) *RmrTransactionId {
trans := oldTrans
if oldTrans == nil {
trans = tc.NewRmrTransactionId("", "RAN_NAME_1")
}
tc.Debug("SendSubsReq %s", trans.String())
e2SubsReq := e2asnpacker.NewPackerSubscriptionRequest()
//---------------------------------
// xapp activity: Send Subs Req
//---------------------------------
myparams := rparams
if myparams == nil {
myparams = &E2StubSubsReqParams{}
myparams.Init()
}
err, packedMsg := e2SubsReq.Pack(myparams.Req)
if err != nil {
tc.TestError(t, "pack NOK %s %s", trans.String(), err.Error())
return nil
}
tc.Debug("%s %s", trans.String(), e2SubsReq.String())
params := &xapp.RMRParams{}
params.Mtype = xapp.RIC_SUB_REQ
params.SubId = -1
params.Payload = packedMsg.Buf
params.PayloadLen = len(packedMsg.Buf)
params.Meid = trans.meid
params.Xid = trans.xid
params.Mbuf = nil
tc.Debug("SEND SUB REQ: %s", params.String())
snderr := tc.SendWithRetry(params, false, 5)
if snderr != nil {
tc.TestError(t, "RMR SEND FAILED: %s %s", trans.String(), snderr.Error())
return nil
}
return trans
}
//-----------------------------------------------------------------------------
//
//-----------------------------------------------------------------------------
func (tc *E2Stub) RecvSubsReq(t *testing.T) (*e2ap.E2APSubscriptionRequest, *xapp.RMRParams) {
tc.Debug("RecvSubsReq")
e2SubsReq := e2asnpacker.NewPackerSubscriptionRequest()
//---------------------------------
// e2term activity: Recv Subs Req
//---------------------------------
msg := tc.WaitMsg(15)
if msg != nil {
if msg.Mtype != xapp.RICMessageTypes["RIC_SUB_REQ"] {
tc.TestError(t, "Received wrong mtype expected %s got %s, error", "RIC_SUB_REQ", xapp.RicMessageTypeToName[msg.Mtype])
} else {
tc.Debug("Recv Subs Req")
packedData := &e2ap.PackedData{}
packedData.Buf = msg.Payload
unpackerr, req := e2SubsReq.UnPack(packedData)
if unpackerr != nil {
tc.TestError(t, "RIC_SUB_REQ unpack failed err: %s", unpackerr.Error())
}
return req, msg
}
} else {
tc.TestError(t, "Not Received msg within %d secs", 15)
}
return nil, nil
}
//-----------------------------------------------------------------------------
//
//-----------------------------------------------------------------------------
func (tc *E2Stub) SendSubsResp(t *testing.T, req *e2ap.E2APSubscriptionRequest, msg *xapp.RMRParams) {
tc.Debug("SendSubsResp")
e2SubsResp := e2asnpacker.NewPackerSubscriptionResponse()
//---------------------------------
// e2term activity: Send Subs Resp
//---------------------------------
resp := &e2ap.E2APSubscriptionResponse{}
resp.RequestId.Id = req.RequestId.Id
resp.RequestId.InstanceId = req.RequestId.InstanceId
resp.FunctionId = req.FunctionId
resp.ActionAdmittedList.Items = make([]e2ap.ActionAdmittedItem, len(req.ActionSetups))
for index := int(0); index < len(req.ActionSetups); index++ {
resp.ActionAdmittedList.Items[index].ActionId = req.ActionSetups[index].ActionId
}
for index := uint64(0); index < 1; index++ {
item := e2ap.ActionNotAdmittedItem{}
item.ActionId = index
item.Cause.Content = 1
item.Cause.Value = 1
resp.ActionNotAdmittedList.Items = append(resp.ActionNotAdmittedList.Items, item)
}
packerr, packedMsg := e2SubsResp.Pack(resp)
if packerr != nil {
tc.TestError(t, "pack NOK %s", packerr.Error())
}
tc.Debug("%s", e2SubsResp.String())
params := &xapp.RMRParams{}
params.Mtype = xapp.RIC_SUB_RESP
//params.SubId = msg.SubId
params.SubId = -1
params.Payload = packedMsg.Buf
params.PayloadLen = len(packedMsg.Buf)
params.Meid = msg.Meid
//params.Xid = msg.Xid
params.Mbuf = nil
tc.Debug("SEND SUB RESP: %s", params.String())
snderr := tc.SendWithRetry(params, false, 5)
if snderr != nil {
tc.TestError(t, "RMR SEND FAILED: %s", snderr.Error())
}
}
//-----------------------------------------------------------------------------
//
//-----------------------------------------------------------------------------
func (tc *E2Stub) SendInvalidE2Asn1Resp(t *testing.T, msg *xapp.RMRParams, msgType int) {
params := &xapp.RMRParams{}
params.Mtype = msgType
params.SubId = -1
params.Payload = []byte{1, 2, 3, 4, 5}
params.PayloadLen = 5
params.Meid = msg.Meid
params.Xid = ""
params.Mbuf = nil
if params.Mtype == xapp.RIC_SUB_RESP {
tc.Debug("SEND INVALID ASN.1 SUB RESP")
} else if params.Mtype == xapp.RIC_SUB_FAILURE {
tc.Debug("SEND INVALID ASN.1 SUB FAILURE")
} else if params.Mtype == xapp.RIC_SUB_DEL_RESP {
tc.Debug("SEND INVALID ASN.1 SUB DEL RESP")
} else if params.Mtype == xapp.RIC_SUB_DEL_FAILURE {
tc.Debug("SEND INVALID ASN.1 SUB DEL FAILURE")
}
snderr := tc.SendWithRetry(params, false, 5)
if snderr != nil {
tc.TestError(t, "RMR SEND FAILED: %s", snderr.Error())
}
}
//-----------------------------------------------------------------------------
//
//-----------------------------------------------------------------------------
func (tc *E2Stub) RecvSubsResp(t *testing.T, trans *RmrTransactionId) uint32 {
tc.Debug("RecvSubsResp")
e2SubsResp := e2asnpacker.NewPackerSubscriptionResponse()
var e2SubsId uint32
//---------------------------------
// xapp activity: Recv Subs Resp
//---------------------------------
msg := tc.WaitMsg(15)
if msg != nil {
if msg.Mtype != xapp.RICMessageTypes["RIC_SUB_RESP"] {
tc.TestError(t, "Received RIC_SUB_RESP wrong mtype expected %s got %s, error", "RIC_SUB_RESP", xapp.RicMessageTypeToName[msg.Mtype])
return 0
} else if msg.Xid != trans.xid {
tc.TestError(t, "Received RIC_SUB_RESP wrong xid expected %s got %s, error", trans.xid, msg.Xid)
return 0
} else {
packedData := &e2ap.PackedData{}
packedData.Buf = msg.Payload
if msg.SubId > 0 {
e2SubsId = uint32(msg.SubId)
} else {
e2SubsId = 0
}
unpackerr, resp := e2SubsResp.UnPack(packedData)
if unpackerr != nil {
tc.TestError(t, "RIC_SUB_RESP unpack failed err: %s", unpackerr.Error())
}
tc.Debug("Recv Subs Resp rmr: xid=%s subid=%d, asn: instanceid=%d", msg.Xid, msg.SubId, resp.RequestId.InstanceId)
return e2SubsId
}
} else {
tc.TestError(t, "Not Received msg within %d secs", 15)
}
return 0
}
//-----------------------------------------------------------------------------
//
//-----------------------------------------------------------------------------
func (tc *E2Stub) SendSubsFail(t *testing.T, fparams *E2StubSubsFailParams, msg *xapp.RMRParams) {
tc.Debug("SendSubsFail")
e2SubsFail := e2asnpacker.NewPackerSubscriptionFailure()
//---------------------------------
// e2term activity: Send Subs Fail
//---------------------------------
packerr, packedMsg := e2SubsFail.Pack(fparams.Fail)
if packerr != nil {
tc.TestError(t, "pack NOK %s", packerr.Error())
}
tc.Debug("%s", e2SubsFail.String())
params := &xapp.RMRParams{}
params.Mtype = xapp.RIC_SUB_FAILURE
params.SubId = msg.SubId
params.Payload = packedMsg.Buf
params.PayloadLen = len(packedMsg.Buf)
params.Meid = msg.Meid
params.Xid = msg.Xid
params.Mbuf = nil
tc.Debug("SEND SUB FAIL: %s", params.String())
snderr := tc.SendWithRetry(params, false, 5)
if snderr != nil {
tc.TestError(t, "RMR SEND FAILED: %s", snderr.Error())
}
}
//-----------------------------------------------------------------------------
//
//-----------------------------------------------------------------------------
func (tc *E2Stub) RecvSubsFail(t *testing.T, trans *RmrTransactionId) uint32 {
tc.Debug("RecvSubsFail")
e2SubsFail := e2asnpacker.NewPackerSubscriptionFailure()
var e2SubsId uint32
//-------------------------------
// xapp activity: Recv Subs Fail
//-------------------------------
msg := tc.WaitMsg(15)
if msg != nil {
if msg.Mtype != xapp.RICMessageTypes["RIC_SUB_FAILURE"] {
tc.TestError(t, "Received RIC_SUB_FAILURE wrong mtype expected %s got %s, error", "RIC_SUB_FAILURE", xapp.RicMessageTypeToName[msg.Mtype])
return 0
} else if msg.Xid != trans.xid {
tc.TestError(t, "Received RIC_SUB_FAILURE wrong xid expected %s got %s, error", trans.xid, msg.Xid)
return 0
} else {
packedData := &e2ap.PackedData{}
packedData.Buf = msg.Payload
if msg.SubId > 0 {
e2SubsId = uint32(msg.SubId)
} else {
e2SubsId = 0
}
unpackerr, resp := e2SubsFail.UnPack(packedData)
if unpackerr != nil {
tc.TestError(t, "RIC_SUB_FAILURE unpack failed err: %s", unpackerr.Error())
}
tc.Debug("Recv Subs Fail rmr: xid=%s subid=%d, asn: instanceid=%d", msg.Xid, msg.SubId, resp.RequestId.InstanceId)
return e2SubsId
}
} else {
tc.TestError(t, "Not Received msg within %d secs", 15)
}
return 0
}
//-----------------------------------------------------------------------------
//
//-----------------------------------------------------------------------------
func (tc *E2Stub) SendSubsDelReq(t *testing.T, oldTrans *RmrTransactionId, e2SubsId uint32) *RmrTransactionId {
trans := oldTrans
if oldTrans == nil {
trans = tc.NewRmrTransactionId("", "RAN_NAME_1")
}
tc.Debug("SendSubsDelReq %s", trans.String())
e2SubsDelReq := e2asnpacker.NewPackerSubscriptionDeleteRequest()
//---------------------------------
// xapp activity: Send Subs Del Req
//---------------------------------
req := &e2ap.E2APSubscriptionDeleteRequest{}
req.RequestId.Id = 1
req.RequestId.InstanceId = e2SubsId
req.FunctionId = 1
err, packedMsg := e2SubsDelReq.Pack(req)
if err != nil {
tc.TestError(t, "pack NOK %s %s", trans.String(), err.Error())
return nil
}
tc.Debug("%s %s", trans.String(), e2SubsDelReq.String())
params := &xapp.RMRParams{}
params.Mtype = xapp.RIC_SUB_DEL_REQ
params.SubId = int(e2SubsId)
params.Payload = packedMsg.Buf
params.PayloadLen = len(packedMsg.Buf)
params.Meid = trans.meid
params.Xid = trans.xid
params.Mbuf = nil
tc.Debug("SEND SUB DEL REQ: %s", params.String())
snderr := tc.SendWithRetry(params, false, 5)
if snderr != nil {
tc.TestError(t, "RMR SEND FAILED: %s %s", trans.String(), snderr.Error())
return nil
}
return trans
}
//-----------------------------------------------------------------------------
//
//-----------------------------------------------------------------------------
func (tc *E2Stub) RecvSubsDelReq(t *testing.T) (*e2ap.E2APSubscriptionDeleteRequest, *xapp.RMRParams) {
tc.Debug("RecvSubsDelReq")
e2SubsDelReq := e2asnpacker.NewPackerSubscriptionDeleteRequest()
//---------------------------------
// e2term activity: Recv Subs Del Req
//---------------------------------
msg := tc.WaitMsg(15)
if msg != nil {
if msg.Mtype != xapp.RICMessageTypes["RIC_SUB_DEL_REQ"] {
tc.TestError(t, "Received wrong mtype expected %s got %s, error", "RIC_SUB_DEL_REQ", xapp.RicMessageTypeToName[msg.Mtype])
} else {
tc.Debug("Recv Subs Del Req")
packedData := &e2ap.PackedData{}
packedData.Buf = msg.Payload
unpackerr, req := e2SubsDelReq.UnPack(packedData)
if unpackerr != nil {
tc.TestError(t, "RIC_SUB_DEL_REQ unpack failed err: %s", unpackerr.Error())
}
return req, msg
}
} else {
tc.TestError(t, "Not Received msg within %d secs", 15)
}
return nil, nil
}
//-----------------------------------------------------------------------------
//
//-----------------------------------------------------------------------------
func (tc *E2Stub) SendSubsDelResp(t *testing.T, req *e2ap.E2APSubscriptionDeleteRequest, msg *xapp.RMRParams) {
tc.Debug("SendSubsDelResp")
e2SubsDelResp := e2asnpacker.NewPackerSubscriptionDeleteResponse()
//---------------------------------
// e2term activity: Send Subs Del Resp
//---------------------------------
resp := &e2ap.E2APSubscriptionDeleteResponse{}
resp.RequestId.Id = req.RequestId.Id
resp.RequestId.InstanceId = req.RequestId.InstanceId
resp.FunctionId = req.FunctionId
packerr, packedMsg := e2SubsDelResp.Pack(resp)
if packerr != nil {
tc.TestError(t, "pack NOK %s", packerr.Error())
}
tc.Debug("%s", e2SubsDelResp.String())
params := &xapp.RMRParams{}
params.Mtype = xapp.RIC_SUB_DEL_RESP
params.SubId = msg.SubId
params.Payload = packedMsg.Buf
params.PayloadLen = len(packedMsg.Buf)
params.Meid = msg.Meid
params.Xid = msg.Xid
params.Mbuf = nil
tc.Debug("SEND SUB DEL RESP: %s", params.String())
snderr := tc.SendWithRetry(params, false, 5)
if snderr != nil {
tc.TestError(t, "RMR SEND FAILED: %s", snderr.Error())
}
}
//-----------------------------------------------------------------------------
//
//-----------------------------------------------------------------------------
func (tc *E2Stub) RecvSubsDelResp(t *testing.T, trans *RmrTransactionId) {
tc.Debug("RecvSubsDelResp")
e2SubsDelResp := e2asnpacker.NewPackerSubscriptionDeleteResponse()
//---------------------------------
// xapp activity: Recv Subs Del Resp
//---------------------------------
msg := tc.WaitMsg(15)
if msg != nil {
if msg.Mtype != xapp.RICMessageTypes["RIC_SUB_DEL_RESP"] {
tc.TestError(t, "Received RIC_SUB_DEL_RESP wrong mtype expected %s got %s, error", "RIC_SUB_DEL_RESP", xapp.RicMessageTypeToName[msg.Mtype])
return
} else if trans != nil && msg.Xid != trans.xid {
tc.TestError(t, "Received RIC_SUB_DEL_RESP wrong xid expected %s got %s, error", trans.xid, msg.Xid)
return
} else {
packedData := &e2ap.PackedData{}
packedData.Buf = msg.Payload
unpackerr, resp := e2SubsDelResp.UnPack(packedData)
if unpackerr != nil {
tc.TestError(t, "RIC_SUB_DEL_RESP unpack failed err: %s", unpackerr.Error())
}
tc.Debug("Recv Subs Del Resp rmr: xid=%s subid=%d, asn: instanceid=%d", msg.Xid, msg.SubId, resp.RequestId.InstanceId)
return
}
} else {
tc.TestError(t, "Not Received msg within %d secs", 15)
}
}
//-----------------------------------------------------------------------------
//
//-----------------------------------------------------------------------------
func (tc *E2Stub) SendSubsDelFail(t *testing.T, req *e2ap.E2APSubscriptionDeleteRequest, msg *xapp.RMRParams) {
tc.Debug("SendSubsDelFail")
e2SubsDelFail := e2asnpacker.NewPackerSubscriptionDeleteFailure()
//---------------------------------
// e2term activity: Send Subs Del Fail
//---------------------------------
resp := &e2ap.E2APSubscriptionDeleteFailure{}
resp.RequestId.Id = req.RequestId.Id
resp.RequestId.InstanceId = req.RequestId.InstanceId
resp.FunctionId = req.FunctionId
resp.Cause.Content = 5 // CauseMisc
resp.Cause.Value = 3 // unspecified
packerr, packedMsg := e2SubsDelFail.Pack(resp)
if packerr != nil {
tc.TestError(t, "pack NOK %s", packerr.Error())
}
tc.Debug("%s", e2SubsDelFail.String())
params := &xapp.RMRParams{}
params.Mtype = xapp.RIC_SUB_DEL_FAILURE
params.SubId = msg.SubId
params.Payload = packedMsg.Buf
params.PayloadLen = len(packedMsg.Buf)
params.Meid = msg.Meid
params.Xid = msg.Xid
params.Mbuf = nil
tc.Debug("SEND SUB DEL FAIL: %s", params.String())
snderr := tc.SendWithRetry(params, false, 5)
if snderr != nil {
tc.TestError(t, "RMR SEND FAILED: %s", snderr.Error())
}
}
// REST code below all
/*****************************************************************************/
// REST interface specific functions are below
//-----------------------------------------------------------------------------
// Callback handler for subscription response notifications
//-----------------------------------------------------------------------------
func (tc *E2Stub) SubscriptionRespHandler(resp *clientmodel.SubscriptionResponse) {
if tc.subscriptionId == "SUBSCRIPTIONID NOT SET" {
tc.Debug("REST notification received for %v while no SubscriptionID was not set for E2EventInstanceID=%v, XappEventInstanceID=%v (%v)",
*resp.SubscriptionID, *resp.SubscriptionInstances[0].E2EventInstanceID, *resp.SubscriptionInstances[0].XappEventInstanceID, tc)
tc.CallBackNotification <- *resp.SubscriptionInstances[0].E2EventInstanceID
} else if tc.subscriptionId == *resp.SubscriptionID {
tc.Debug("REST notification received SubscriptionID=%s, E2EventInstanceID=%v, RequestorID=%v (%v)",
*resp.SubscriptionID, *resp.SubscriptionInstances[0].E2EventInstanceID, *resp.SubscriptionInstances[0].XappEventInstanceID, tc)
tc.CallBackNotification <- *resp.SubscriptionInstances[0].E2EventInstanceID
} else {
tc.Debug("MISMATCHING REST notification received SubscriptionID=%s<>%s, E2EventInstanceID=%v, XappEventInstanceID=%v (%v)",
tc.subscriptionId, *resp.SubscriptionID, *resp.SubscriptionInstances[0].E2EventInstanceID, *resp.SubscriptionInstances[0].XappEventInstanceID, tc)
}
}
//-----------------------------------------------------------------------------
//
//-----------------------------------------------------------------------------
func (tc *E2Stub) ExpectRESTNotification(t *testing.T, restSubsId string) {
tc.expectNotification(t, restSubsId, "")
}
func (tc *E2Stub) ExpectRESTNotificationOk(t *testing.T, restSubsId string) {
tc.expectNotification(t, restSubsId, "allOk")
}
func (tc *E2Stub) ExpectRESTNotificationNok(t *testing.T, restSubsId string, expectError string) {
tc.expectNotification(t, restSubsId, expectError)
}
func (tc *E2Stub) expectNotification(t *testing.T, restSubsId string, expectError string) {
tc.Debug("### Started to wait REST notification for %v on port %v f(RMR port %v), %v responses expected", restSubsId, *tc.clientEndpoint.HTTPPort, *tc.clientEndpoint.RMRPort, tc.requestCount)
tc.restSubsIdList = []string{restSubsId}
xapp.Subscription.SetResponseCB(tc.ListedRestNotifHandler)
if tc.requestCount == 0 {
tc.TestError(t, "### NO REST notifications SET received for endpoint=%s, request zount ZERO! (%v)", tc.clientEndpoint, *tc)
}
go func() {
select {
case e2Ids := <-tc.CallBackListedNotifications:
if tc.requestCount == 0 {
tc.TestError(t, "### REST notification count unexpectedly ZERO for %s (%v)", restSubsId, *tc)
} else if e2Ids.RestSubsId != restSubsId {
tc.TestError(t, "### Unexpected REST notifications received, expected %s bunt got %s instead| (%v)", e2Ids.RestSubsId, restSubsId, *tc)
} else if e2Ids.ErrorCause == "" && expectError == "allFail" {
tc.TestError(t, "### Unexpected ok cause received from REST notifications |%s:%s| (%v)", e2Ids.RestSubsId, restSubsId, *tc)
} else if e2Ids.ErrorCause != "" && expectError == "allOk" {
tc.TestError(t, "### Unexpected ErrorCause: (%s), ErrorSource: (%s), TimeoutType: (%s) received from REST notifications |%s:%s| (%v)", e2Ids.ErrorCause, e2Ids.ErrorSource, e2Ids.TimeoutType, e2Ids.RestSubsId, restSubsId, *tc)
} else {
tc.requestCount--
if tc.requestCount == 0 {
tc.Debug("### All expected REST notifications received for %s (%v)", e2Ids.RestSubsId, *tc)
} else {
tc.Debug("### Expected REST notifications received for %s, (%v)", e2Ids.RestSubsId, *tc)
}
if e2Ids.ErrorCause != "" && expectError == "allFail" {
tc.Debug("### REST Notification: RestSubsId: %s, ErrorCause: %s, ErrorSource: (%s), TimeoutType: (%s)", e2Ids.RestSubsId, e2Ids.ErrorCause, e2Ids.ErrorSource, e2Ids.TimeoutType)
}
tc.Debug("### REST Notification received Notif for %s : %v", e2Ids.RestSubsId, e2Ids.E2SubsId)
tc.ListedRESTNotifications <- e2Ids
if len(tc.ListedRESTNotifications) > 1 {
panic("expectNotification - ListedRESTNotifications stacking up")
}
}
case <-time.After(15 * time.Second):
err := fmt.Errorf("### Timeout 15s expired while expecting REST notification for subsId: %v", restSubsId)
tc.TestError(t, "%s", err.Error())
}
}()
}
func (tc *E2Stub) WaitRESTNotification(t *testing.T, restSubsId string) uint32 {
stack := string(debug.Stack())
select {
case e2SubsId := <-tc.ListedRESTNotifications:
if e2SubsId.RestSubsId == restSubsId {
tc.Debug("### Expected REST notifications received %s, e2SubsId %v for endpoint=%v, (%v)", e2SubsId.RestSubsId, e2SubsId.E2SubsId, tc.clientEndpoint, *tc)
return e2SubsId.E2SubsId
} else {
tc.TestError(t, "### Unexpected REST notification %s received, expected %v for endpoint=%v, (%v)", e2SubsId.RestSubsId, restSubsId, tc.clientEndpoint, *tc)
xapp.Logger.Debug("CALL STACK:\n %s", stack)
return 0
}
case <-time.After(15 * time.Second):
err := fmt.Errorf("### Timeout 15s expired while waiting REST notification for subsId: %v", restSubsId)
tc.TestError(t, "%s", err.Error())
xapp.Logger.Debug("CALL STACK:\n %s", stack)
panic("WaitRESTNotification - timeout error")
}
}
// Note, this function should be followed by a handling of <-xappConn1.RESTNotification.
func (tc *E2Stub) ExpectAnyNotification(t *testing.T) {
go func() {
tc.Debug("### Started waiting ANY REST notifications received for endpoint=%s, (%v)", tc.clientEndpoint, tc)
select {
case e2SubsId := <-tc.CallBackNotification:
tc.Debug("### ANY REST notifications received e2SubsId %v for endpoint=%s, (%v) via CallBackNotification", e2SubsId, tc.clientEndpoint, tc)
tc.RESTNotification <- (uint32)(e2SubsId)
case <-time.After(15 * time.Second):
err := fmt.Errorf("### Timeout 15s expired while waiting ANY REST notification")
tc.TestError(t, "%s", err.Error())
tc.RESTNotification <- 0
}
}()
}
func (tc *E2Stub) WaitAnyRESTNotification(t *testing.T) uint32 {
select {
case e2SubsId := <-tc.RESTNotification:
tc.Debug("### Expected ANY REST notification received - e2SubsId %v for endpoint=%s, (%v)", e2SubsId, tc.clientEndpoint, tc)
return e2SubsId
case <-time.After(15 * time.Second):
err := fmt.Errorf("### Timeout 15s expired while waiting ANY REST notification")
tc.TestError(t, "%s", err.Error())
panic("WaitRESTNotification - timeout error")
}
}
func (tc *E2Stub) ListedRestNotifHandler(resp *clientmodel.SubscriptionResponse) {
if len(tc.restSubsIdList) == 0 {
tc.Error("Unexpected listed REST notifications received for endpoint=%v, expected restSubsId list size was ZERO!", tc.clientEndpoint)
} else {
for i, subsId := range tc.restSubsIdList {
if *resp.SubscriptionID == subsId {
//tc.Debug("Listed REST notifications received SubscriptionID=%s, InstanceID=%v, XappEventInstanceID=%v",
// *resp.SubscriptionID, *resp.SubscriptionInstances[0].InstanceID, *resp.SubscriptionInstances[0].XappEventInstanceID)
tc.restSubsIdList = append(tc.restSubsIdList[:i], tc.restSubsIdList[i+1:]...)
//tc.Debug("Removed %s from Listed REST notifications, %v entries left", *resp.SubscriptionID, len(tc.restSubsIdList))
// if resp.SubscriptionInstances[0].ErrorCause != nil {
tc.CallBackListedNotifications <- *tc.GetE2RestIds(resp)
// } else {
// tc.CallBackListedNotifications <- E2RestIds{*resp.SubscriptionID, uint32(*resp.SubscriptionInstances[0].E2EventInstanceID), "", "", ""}
// }
if len(tc.restSubsIdList) == 0 {
tc.Debug("All listed REST notifications received for endpoint=%v", tc.clientEndpoint)
}
return
}
}
tc.Error("UNKONWN REST notification received SubscriptionID=%s<>%s, InstanceID=%v, XappEventInstanceID=%v (%v)",
tc.subscriptionId, *resp.SubscriptionID, *resp.SubscriptionInstances[0].E2EventInstanceID, *resp.SubscriptionInstances[0].XappEventInstanceID, tc)
}
}
//-----------------------------------------------------------------------------
//
//-----------------------------------------------------------------------------
func (tc *E2Stub) GetE2RestIds(resp *clientmodel.SubscriptionResponse) *E2RestIds {
e2RestIds := &E2RestIds{}
if resp != nil {
if resp.SubscriptionID != nil {
e2RestIds.RestSubsId = *resp.SubscriptionID
}
if resp.SubscriptionInstances != nil {
if resp.SubscriptionInstances[0].E2EventInstanceID != nil {
e2RestIds.E2SubsId = uint32(*resp.SubscriptionInstances[0].E2EventInstanceID)
}
e2RestIds.ErrorCause = resp.SubscriptionInstances[0].ErrorCause
e2RestIds.ErrorSource = resp.SubscriptionInstances[0].ErrorSource
e2RestIds.TimeoutType = resp.SubscriptionInstances[0].TimeoutType
}
}
return e2RestIds
}
//-----------------------------------------------------------------------------
//
//-----------------------------------------------------------------------------
func (tc *E2Stub) WaitListedRestNotifications(t *testing.T, restSubsIds []string) {
tc.Debug("Started to wait REST notifications %v on port %v f(RMR port %v)", restSubsIds, *tc.clientEndpoint.HTTPPort, *tc.clientEndpoint.RMRPort)
tc.restSubsIdList = restSubsIds
xapp.Subscription.SetResponseCB(tc.ListedRestNotifHandler)
for i := 0; i < len(restSubsIds); i++ {
go func() {
select {
case e2Ids := <-tc.CallBackListedNotifications:
tc.Debug("Listed Notification waiter received Notif for %s : %v", e2Ids.RestSubsId, e2Ids.E2SubsId)
tc.ListedRESTNotifications <- e2Ids
case <-time.After(15 * time.Second):
err := fmt.Errorf("Timeout 15s expired while waiting Listed REST notification")
tc.TestError(t, "%s", err.Error())
tc.RESTNotification <- 0
}
}()
}
}
//-----------------------------------------------------------------------------
//
//-----------------------------------------------------------------------------
func (tc *E2Stub) SendRESTSubsReq(t *testing.T, params *RESTSubsReqParams) string {
tc.Debug("======== Posting REST subscriptions to Submgr ======")
if params == nil {
tc.Debug("SendRESTReportSubsReq: params == nil")
return ""
}
tc.subscriptionId = "SUBSCRIPTIONID NOT SET"
resp, err := xapp.Subscription.Subscribe(&params.SubsReqParams)
if err != nil {
// Swagger generated code makes checks for the values that are inserted the subscription function
// If error cause is unknown and POST is not done, the problem is in the inserted values
tc.Error("======== REST subscription request failed %s ========", err.Error())
return ""
}
tc.subscriptionId = *resp.SubscriptionID
tc.Debug("======== REST subscriptions posted successfully. SubscriptionID = %s, RequestCount = %v ========", *resp.SubscriptionID, tc.requestCount)
return *resp.SubscriptionID
}
//-----------------------------------------------------------------------------
//
//-----------------------------------------------------------------------------
func (tc *E2Stub) GetRESTSubsReqReportParams(subReqCount int) *RESTSubsReqParams {
reportParams := RESTSubsReqParams{}
reportParams.GetRESTSubsReqReportParams(subReqCount, &tc.clientEndpoint, &tc.meid)
tc.requestCount = subReqCount
return &reportParams
}
//-----------------------------------------------------------------------------
//
//-----------------------------------------------------------------------------
type RESTSubsReqParams struct {
SubsReqParams clientmodel.SubscriptionParams
}
func (p *RESTSubsReqParams) GetRESTSubsReqReportParams(subReqCount int, clientEndpoint *clientmodel.SubscriptionParamsClientEndpoint, meid *string) {
// E2SM-gNB-X2
p.SubsReqParams.ClientEndpoint = clientEndpoint
p.SubsReqParams.Meid = meid
var rANFunctionID int64 = 33
p.SubsReqParams.RANFunctionID = &rANFunctionID
actionId := int64(1)
actionType := "report"
subsequestActioType := "continue"
timeToWait := "w10ms"
for requestCount := 0; requestCount < subReqCount; requestCount++ {
reqId := int64(requestCount) + 1
subscriptionDetail := &clientmodel.SubscriptionDetail{
XappEventInstanceID: &reqId,
EventTriggers: clientmodel.EventTriggerDefinition{
int64(1234 + requestCount),
},
ActionToBeSetupList: clientmodel.ActionsToBeSetup{
&clientmodel.ActionToBeSetup{
ActionID: &actionId,
ActionType: &actionType,
ActionDefinition: clientmodel.ActionDefinition{
int64(5678 + requestCount),
},
SubsequentAction: &clientmodel.SubsequentAction{
SubsequentActionType: &subsequestActioType,
TimeToWait: &timeToWait,
},
},
},
}
p.SubsReqParams.SubscriptionDetails = append(p.SubsReqParams.SubscriptionDetails, subscriptionDetail)
}
}
func (p *RESTSubsReqParams) SetMeid(MEID string) {
p.SubsReqParams.Meid = &MEID
}
func (p *RESTSubsReqParams) SetEndpoint(HTTP_port int64, RMR_port int64, host string) {
var endpoint clientmodel.SubscriptionParamsClientEndpoint
endpoint.HTTPPort = &HTTP_port
endpoint.RMRPort = &RMR_port
endpoint.Host = host
p.SubsReqParams.ClientEndpoint = &endpoint
}
func (p *RESTSubsReqParams) SetEndpointHost(host string) {
if p.SubsReqParams.ClientEndpoint.Host != "" {
if p.SubsReqParams.ClientEndpoint.Host != host {
// Renaming toto, print something tc.Debug("Posting REST subscription request to Submgr")
err := fmt.Errorf("hostname change attempt: %s -> %s", p.SubsReqParams.ClientEndpoint.Host, host)
panic(err)
}
}
p.SubsReqParams.ClientEndpoint.Host = host
}
func (p *RESTSubsReqParams) SetHTTPEndpoint(HTTP_port int64, host string) {
p.SubsReqParams.ClientEndpoint.HTTPPort = &HTTP_port
p.SetEndpointHost(host)
if p.SubsReqParams.ClientEndpoint.RMRPort == nil {
var RMR_port int64
p.SubsReqParams.ClientEndpoint.RMRPort = &RMR_port
}
}
func (p *RESTSubsReqParams) SetE2SubscriptionDirectives(E2RetryCount int64, E2TimeoutTimerValue int64, RMRRoutingNeeded bool) {
E2SubscriptionDirectives := &clientmodel.SubscriptionParamsE2SubscriptionDirectives{}
p.SubsReqParams.E2SubscriptionDirectives = E2SubscriptionDirectives
p.SubsReqParams.E2SubscriptionDirectives.E2RetryCount = &E2RetryCount
p.SubsReqParams.E2SubscriptionDirectives.E2TimeoutTimerValue = E2TimeoutTimerValue
p.SubsReqParams.E2SubscriptionDirectives.RMRRoutingNeeded = RMRRoutingNeeded
}
func (p *RESTSubsReqParams) RemoveE2SubscriptionDirectives() {
p.SubsReqParams.E2SubscriptionDirectives = nil
}
func (p *RESTSubsReqParams) SetSubActionTypes(actionType string) {
for _, subDetail := range p.SubsReqParams.SubscriptionDetails {
for _, action := range subDetail.ActionToBeSetupList {
if action != nil {
action.ActionType = &actionType
}
}
}
}
func (p *RESTSubsReqParams) SetSubActionIDs(actionId int64) {
for _, subDetail := range p.SubsReqParams.SubscriptionDetails {
for _, action := range subDetail.ActionToBeSetupList {
if action != nil {
action.ActionID = &actionId
}
}
}
}
func (p *RESTSubsReqParams) SetSubActionDefinition(actionDefinition []int64) {
for _, subDetail := range p.SubsReqParams.SubscriptionDetails {
for _, action := range subDetail.ActionToBeSetupList {
if action != nil {
action.ActionDefinition = actionDefinition
}
}
}
}
func (p *RESTSubsReqParams) SetSubEventTriggerDefinition(eventTriggerDefinition []int64) {
for _, subDetail := range p.SubsReqParams.SubscriptionDetails {
if subDetail != nil {
subDetail.EventTriggers = eventTriggerDefinition
}
}
}
func (p *RESTSubsReqParams) AppendActionToActionToBeSetupList(actionId int64, actionType string, actionDefinition []int64, subsequentActionType string, timeToWait string) {
actionToBeSetup := &clientmodel.ActionToBeSetup{
ActionID: &actionId,
ActionType: &actionType,
ActionDefinition: clientmodel.ActionDefinition(actionDefinition),
SubsequentAction: &clientmodel.SubsequentAction{
SubsequentActionType: &subsequentActionType,
TimeToWait: &timeToWait,
},
}
for _, subDetail := range p.SubsReqParams.SubscriptionDetails {
if subDetail != nil {
subDetail.ActionToBeSetupList = append(subDetail.ActionToBeSetupList, actionToBeSetup)
}
}
}
func (p *RESTSubsReqParams) SetRMREndpoint(RMR_port int64, host string) {
p.SubsReqParams.ClientEndpoint.RMRPort = &RMR_port
p.SetEndpointHost(host)
if p.SubsReqParams.ClientEndpoint.HTTPPort == nil {
var HTTP_port int64
p.SubsReqParams.ClientEndpoint.HTTPPort = &HTTP_port
}
}
func (p *RESTSubsReqParams) SetTimeToWait(timeToWait string) {
for _, subDetail := range p.SubsReqParams.SubscriptionDetails {
for _, action := range subDetail.ActionToBeSetupList {
if action != nil && action.SubsequentAction != nil {
action.SubsequentAction.TimeToWait = &timeToWait
}
}
}
}
func (p *RESTSubsReqParams) SetSubscriptionID(SubscriptionID *string) {
if *SubscriptionID == "" {
return
}
p.SubsReqParams.SubscriptionID = *SubscriptionID
}
func (p *RESTSubsReqParams) SetXappEventInstanceID(xappEventInstanceId int64) {
for _, subDetail := range p.SubsReqParams.SubscriptionDetails {
if subDetail != nil {
subDetail.XappEventInstanceID = &xappEventInstanceId
}
}
}
//-----------------------------------------------------------------------------
//
//-----------------------------------------------------------------------------
func (tc *E2Stub) SendRESTSubsDelReq(t *testing.T, subscriptionID *string) {
tc.Debug("======== Posting REST DELETE subscription(s) to Submgr ======")
if *subscriptionID == "" {
tc.Error("REST error in deleting subscriptions. Empty SubscriptionID = %s", *subscriptionID)
}
tc.Debug("REST deleting E2 subscriptions. SubscriptionID = %s", *subscriptionID)
err := xapp.Subscription.Unsubscribe(*subscriptionID)
if err != nil {
tc.Error("REST Delete subscription failed %s", err.Error())
}
tc.Debug("REST delete subscription pushed to submgr successfully. SubscriptionID = %s", *subscriptionID)
}
//-----------------------------------------------------------------------------
//
//-----------------------------------------------------------------------------
func (tc *E2Stub) GetRESTSubsReqPolicyParams(subReqCount int) *RESTSubsReqParams {
policyParams := RESTSubsReqParams{}
policyParams.GetRESTSubsReqPolicyParams(subReqCount, &tc.clientEndpoint, &tc.meid)
tc.requestCount = subReqCount
return &policyParams
}
//-----------------------------------------------------------------------------
//
//-----------------------------------------------------------------------------
func (tc *E2Stub) DecrementRequestCount() {
if tc.requestCount > 0 {
tc.requestCount -= 1
} else {
tc.Error("FAILED to decrement request count, count already ZERO")
}
}
//-----------------------------------------------------------------------------
//
//-----------------------------------------------------------------------------
func (p *RESTSubsReqParams) GetRESTSubsReqPolicyParams(subReqCount int, clientEndpoint *clientmodel.SubscriptionParamsClientEndpoint, meid *string) {
p.SubsReqParams.ClientEndpoint = clientEndpoint
p.SubsReqParams.Meid = meid
var rANFunctionID int64 = 33
p.SubsReqParams.RANFunctionID = &rANFunctionID
actionId := int64(1)
actionType := "policy"
subsequestActioType := "continue"
timeToWait := "w10ms"
for requestCount := 0; requestCount < subReqCount; requestCount++ {
reqId := int64(requestCount) + 1
subscriptionDetail := &clientmodel.SubscriptionDetail{
XappEventInstanceID: &reqId,
EventTriggers: clientmodel.EventTriggerDefinition{
int64(1234 + requestCount),
},
ActionToBeSetupList: clientmodel.ActionsToBeSetup{
&clientmodel.ActionToBeSetup{
ActionID: &actionId,
ActionType: &actionType,
ActionDefinition: clientmodel.ActionDefinition{
int64(5678 + requestCount),
},
SubsequentAction: &clientmodel.SubsequentAction{
SubsequentActionType: &subsequestActioType,
TimeToWait: &timeToWait,
},
},
},
}
p.SubsReqParams.SubscriptionDetails = append(p.SubsReqParams.SubscriptionDetails, subscriptionDetail)
}
}
func (p *RESTSubsReqParams) SetSubscriptionDirectives(e2Timeout int64, e2RetryCount int64, routingNeeded bool) {
e2SubscriptionDirectives := &clientmodel.SubscriptionParamsE2SubscriptionDirectives{}
e2SubscriptionDirectives.E2TimeoutTimerValue = e2Timeout
e2SubscriptionDirectives.E2RetryCount = &e2RetryCount
e2SubscriptionDirectives.RMRRoutingNeeded = routingNeeded
p.SubsReqParams.E2SubscriptionDirectives = e2SubscriptionDirectives
}