RIC-867: Submgr adaptations to E2APv2.0
[ric-plt/submgr.git] / pkg / teststube2ap / stubE2.go
index a021cd0..fbb9065 100644 (file)
@@ -30,7 +30,6 @@ import (
        "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"
 )
 
@@ -177,24 +176,14 @@ func (p *E2StubSubsFailParams) Set(req *e2ap.E2APSubscriptionRequest) {
        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)
-       }
+       p.Fail.Cause.Content = e2ap.E2AP_CauseContent_RICrequest
+       p.Fail.Cause.Value = e2ap.E2AP_CauseValue_RICrequest_control_message_invalid
 }
 
 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
+       p.Fail.Cause.Content = content
+       p.Fail.Cause.Value = causeval
 }
 
 //-----------------------------------------------------------------------------
@@ -298,12 +287,69 @@ func (tc *E2Stub) SendSubsResp(t *testing.T, req *e2ap.E2APSubscriptionRequest,
                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) SendPartialSubsResp(t *testing.T, req *e2ap.E2APSubscriptionRequest, msg *xapp.RMRParams, actionNotAdmittedList e2ap.ActionNotAdmittedList) {
+       tc.Debug("SendPartialSubsResp")
+
+       if len(actionNotAdmittedList.Items) == 0 {
+               tc.TestError(t, "SendPartialSubsResp() Empty actionNotAdmittedList.Items")
+               return
+       }
+
+       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
+
+       for index, actionNotAdmittedItem := range actionNotAdmittedList.Items {
+               for _, ActionToBeSetupItem := range req.ActionSetups {
+                       if ActionToBeSetupItem.ActionId == actionNotAdmittedItem.ActionId {
+                               actionNotAdmittedItem := e2ap.ActionNotAdmittedItem{}
+                               actionNotAdmittedItem.ActionId = ActionToBeSetupItem.ActionId
+                               actionNotAdmittedItem.Cause.Content = 1
+                               actionNotAdmittedItem.Cause.Value = 8
+                               resp.ActionNotAdmittedList.Items = append(resp.ActionNotAdmittedList.Items, actionNotAdmittedItem)
+                               // Remove the element
+                               req.ActionSetups = append(req.ActionSetups[:index], req.ActionSetups[index+1:]...)
+
+                       }
+               }
+       }
+       for _, ActionToBeSetupItem := range req.ActionSetups {
+               actionAdmittedItem := e2ap.ActionAdmittedItem{}
+               actionAdmittedItem.ActionId = ActionToBeSetupItem.ActionId
+               resp.ActionAdmittedList.Items = append(resp.ActionAdmittedList.Items, actionAdmittedItem)
        }
 
        packerr, packedMsg := e2SubsResp.Pack(resp)
@@ -670,16 +716,16 @@ func (tc *E2Stub) SendSubsDelFail(t *testing.T, req *e2ap.E2APSubscriptionDelete
 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.Debug("REST notification received for %v while no SubscriptionID was not set for E2EventInstanceID=%v, XappEventInstanceID=%v",
+                       *resp.SubscriptionID, *resp.SubscriptionInstances[0].E2EventInstanceID, *resp.SubscriptionInstances[0].XappEventInstanceID)
                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.Debug("REST notification received SubscriptionID=%s, E2EventInstanceID=%v, RequestorID=%v",
+                       *resp.SubscriptionID, *resp.SubscriptionInstances[0].E2EventInstanceID, *resp.SubscriptionInstances[0].XappEventInstanceID)
                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)
+               tc.Debug("MISMATCHING REST notification received SubscriptionID=%s<>%s, E2EventInstanceID=%v, XappEventInstanceID=%v",
+                       tc.subscriptionId, *resp.SubscriptionID, *resp.SubscriptionInstances[0].E2EventInstanceID, *resp.SubscriptionInstances[0].XappEventInstanceID)
        }
 }
 
@@ -701,29 +747,29 @@ func (tc *E2Stub) ExpectRESTNotificationNok(t *testing.T, restSubsId string, exp
 
 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.Debug("### Started to wait REST notification for restSubsId= %v, RMRPort=%v, requestCount=%v responses expected", restSubsId, *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)
+               tc.TestError(t, "### NO REST notifications SET received for restSubsId= %v, RMRPort=%v, request count ZERO!", restSubsId, *tc.clientEndpoint.RMRPort)
        }
        go func() {
                select {
                case e2Ids := <-tc.CallBackListedNotifications:
                        if tc.requestCount == 0 {
-                               tc.TestError(t, "### REST notification count unexpectedly ZERO for %s (%v)", restSubsId, tc)
+                               tc.TestError(t, "### REST notification count unexpectedly ZERO for restSubsId= %v", restSubsId)
                        } else if e2Ids.RestSubsId != restSubsId {
-                               tc.TestError(t, "### Unexpected REST notifications received, expected %s bunt got %s instead| (%v)", e2Ids.RestSubsId, restSubsId, tc)
+                               tc.TestError(t, "### Unexpected REST notifications received, expected %s but got %s instead", e2Ids.RestSubsId, restSubsId)
                        } else if e2Ids.ErrorCause == "" && expectError == "allFail" {
-                               tc.TestError(t, "### Unexpected ok cause received from REST notifications |%s:%s| (%v)", e2Ids.RestSubsId, restSubsId, tc)
+                               tc.TestError(t, "### Unexpected ok cause received from REST notifications |%s:%s|", e2Ids.RestSubsId, restSubsId)
                        } 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)
+                               tc.TestError(t, "### Unexpected ErrorCause: (%s), ErrorSource: (%s), TimeoutType: (%s) received from REST notifications |%s:%s|", e2Ids.ErrorCause, e2Ids.ErrorSource, e2Ids.TimeoutType, e2Ids.RestSubsId, restSubsId)
                        } else {
                                tc.requestCount--
                                if tc.requestCount == 0 {
-                                       tc.Debug("### All expected REST notifications received for %s (%v)", e2Ids.RestSubsId, tc)
+                                       tc.Debug("### All expected REST notifications received for restSubsId= %v)", e2Ids.RestSubsId)
                                } else {
-                                       tc.Debug("### Expected REST notifications received for %s, (%v)", e2Ids.RestSubsId, tc)
+                                       tc.Debug("### Expected REST notifications received for restSubsId= %v", e2Ids.RestSubsId)
                                }
                                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)
@@ -748,10 +794,10 @@ func (tc *E2Stub) WaitRESTNotification(t *testing.T, restSubsId string) uint32 {
        select {
        case e2SubsId := <-tc.ListedRESTNotifications:
                if e2SubsId.RestSubsId == restSubsId {
-                       tc.Debug("### Expected REST notifications received %s, e2SubsId %v for endpoint=%s, (%v)", e2SubsId.RestSubsId, e2SubsId.E2SubsId, tc.clientEndpoint, tc)
+                       tc.Debug("### Expected REST notifications received %s, e2SubsId %v", e2SubsId.RestSubsId, e2SubsId.E2SubsId)
                        return e2SubsId.E2SubsId
                } else {
-                       tc.TestError(t, "### Unexpected REST notification %s received, expected %s for endpoint=%s, (%v)", e2SubsId.RestSubsId, restSubsId, tc.clientEndpoint, tc)
+                       tc.TestError(t, "### Unexpected REST notification %s received, expected %v", e2SubsId.RestSubsId, restSubsId)
                        xapp.Logger.Debug("CALL STACK:\n %s", stack)
                        return 0
                }
@@ -766,10 +812,10 @@ func (tc *E2Stub) WaitRESTNotification(t *testing.T, restSubsId string) uint32 {
 // 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)
+               tc.Debug("### Started waiting ANY REST notifications received for RMRPort=%v", *tc.clientEndpoint.RMRPort)
                select {
                case e2SubsId := <-tc.CallBackNotification:
-                       tc.Debug("### ANY REST notifications received e2SubsId %v for endpoint=%s, (%v) via CallBackNotification", e2SubsId, tc.clientEndpoint, tc)
+                       tc.Debug("### ANY REST notifications received for e2SubsId %v RMRPort=%v", e2SubsId, *tc.clientEndpoint.RMRPort)
                        tc.RESTNotification <- (uint32)(e2SubsId)
                case <-time.After(15 * time.Second):
                        err := fmt.Errorf("### Timeout 15s expired while waiting ANY REST notification")
@@ -783,7 +829,7 @@ 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)
+               tc.Debug("### Expected ANY REST notification received for e2SubsId %v", e2SubsId)
                return e2SubsId
 
        case <-time.After(15 * time.Second):
@@ -796,7 +842,7 @@ func (tc *E2Stub) WaitAnyRESTNotification(t *testing.T) uint32 {
 func (tc *E2Stub) ListedRestNotifHandler(resp *clientmodel.SubscriptionResponse) {
 
        if len(tc.restSubsIdList) == 0 {
-               tc.Error("Unexpected listed REST notifications received for endpoint=%s, expected restSubsId list size was ZERO!", tc.clientEndpoint)
+               tc.Error("Unexpected listed REST notifications received for SubscriptionID=%s, expected restSubsId list size was ZERO!", *resp.SubscriptionID)
        } else {
                for i, subsId := range tc.restSubsIdList {
                        if *resp.SubscriptionID == subsId {
@@ -813,14 +859,14 @@ func (tc *E2Stub) ListedRestNotifHandler(resp *clientmodel.SubscriptionResponse)
                                //                              }
 
                                if len(tc.restSubsIdList) == 0 {
-                                       tc.Debug("All listed REST notifications received for endpoint=%s", tc.clientEndpoint)
+                                       tc.Debug("All listed REST notifications received for SubscriptionID=%s", *resp.SubscriptionID)
                                }
 
                                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)
+               tc.Error("UNKONWN REST notification received SubscriptionID=%s<>%s, InstanceID=%v, XappEventInstanceID=%v",
+                       tc.subscriptionId, *resp.SubscriptionID, *resp.SubscriptionInstances[0].E2EventInstanceID, *resp.SubscriptionInstances[0].XappEventInstanceID)
        }
 }
 
@@ -838,21 +884,9 @@ func (tc *E2Stub) GetE2RestIds(resp *clientmodel.SubscriptionResponse) *E2RestId
                        if resp.SubscriptionInstances[0].E2EventInstanceID != nil {
                                e2RestIds.E2SubsId = uint32(*resp.SubscriptionInstances[0].E2EventInstanceID)
                        }
-                       if resp.SubscriptionInstances[0].ErrorCause != nil {
-                               e2RestIds.ErrorCause = *resp.SubscriptionInstances[0].ErrorCause
-                       } else {
-                               e2RestIds.ErrorCause = "nil"
-                       }
-                       if resp.SubscriptionInstances[0].ErrorSource != nil {
-                               e2RestIds.ErrorSource = *resp.SubscriptionInstances[0].ErrorSource
-                       } else {
-                               e2RestIds.ErrorSource = "nil"
-                       }
-                       if resp.SubscriptionInstances[0].TimeoutType != nil {
-                               e2RestIds.TimeoutType = *resp.SubscriptionInstances[0].TimeoutType
-                       } else {
-                               e2RestIds.TimeoutType = "nil"
-                       }
+                       e2RestIds.ErrorCause = resp.SubscriptionInstances[0].ErrorCause
+                       e2RestIds.ErrorSource = resp.SubscriptionInstances[0].ErrorSource
+                       e2RestIds.TimeoutType = resp.SubscriptionInstances[0].TimeoutType
                }
        }
        return e2RestIds
@@ -862,7 +896,7 @@ func (tc *E2Stub) GetE2RestIds(resp *clientmodel.SubscriptionResponse) *E2RestId
 //
 //-----------------------------------------------------------------------------
 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.Debug("Started to wait REST notifications for restSubsIds=%v, RMRPort=%v", restSubsIds, *tc.clientEndpoint.RMRPort)
 
        tc.restSubsIdList = restSubsIds
        xapp.Subscription.SetResponseCB(tc.ListedRestNotifHandler)
@@ -900,11 +934,6 @@ func (tc *E2Stub) SendRESTSubsReq(t *testing.T, params *RESTSubsReqParams) strin
                // 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())
-               if resp != nil {
-                       tc.PrintSubscriptionInsctanceErrorInfo(resp)
-               } else {
-                       tc.Error("Subscribe resp == nil")
-               }
                return ""
        }
        tc.subscriptionId = *resp.SubscriptionID
@@ -912,28 +941,6 @@ func (tc *E2Stub) SendRESTSubsReq(t *testing.T, params *RESTSubsReqParams) strin
        return *resp.SubscriptionID
 }
 
-//-----------------------------------------------------------------------------
-//
-//-----------------------------------------------------------------------------
-func (tc *E2Stub) PrintSubscriptionInsctanceErrorInfo(resp *clientmodel.SubscriptionResponse) {
-       for _, subscriptionInstance := range resp.SubscriptionInstances {
-               if subscriptionInstance != nil {
-                       if subscriptionInstance.RejectCause != nil {
-                               tc.Error("subscriptionInstance.RejectCause= %s", *subscriptionInstance.RejectCause)
-                       }
-                       if subscriptionInstance.ErrorCause != nil {
-                               tc.Error("subscriptionInstance.ErrorCause= %s", *subscriptionInstance.ErrorCause)
-                       }
-                       if subscriptionInstance.ErrorSource != nil {
-                               tc.Error("subscriptionInstance.ErrorSource= %s", *subscriptionInstance.ErrorSource)
-                       }
-                       if subscriptionInstance.TimeoutType != nil {
-                               tc.Error("subscriptionInstance.TimeoutType = %s", *subscriptionInstance.TimeoutType)
-                       }
-               }
-       }
-}
-
 //-----------------------------------------------------------------------------
 //
 //-----------------------------------------------------------------------------
@@ -1033,7 +1040,7 @@ func (p *RESTSubsReqParams) SetE2SubscriptionDirectives(E2RetryCount int64, E2Ti
        p.SubsReqParams.E2SubscriptionDirectives = E2SubscriptionDirectives
        p.SubsReqParams.E2SubscriptionDirectives.E2RetryCount = &E2RetryCount
        p.SubsReqParams.E2SubscriptionDirectives.E2TimeoutTimerValue = E2TimeoutTimerValue
-       p.SubsReqParams.E2SubscriptionDirectives.RMRRoutingNeeded = &RMRRoutingNeeded
+       p.SubsReqParams.E2SubscriptionDirectives.RMRRoutingNeeded = RMRRoutingNeeded
 }
 
 func (p *RESTSubsReqParams) RemoveE2SubscriptionDirectives() {
@@ -1227,7 +1234,7 @@ func (p *RESTSubsReqParams) SetSubscriptionDirectives(e2Timeout int64, e2RetryCo
        e2SubscriptionDirectives := &clientmodel.SubscriptionParamsE2SubscriptionDirectives{}
        e2SubscriptionDirectives.E2TimeoutTimerValue = e2Timeout
        e2SubscriptionDirectives.E2RetryCount = &e2RetryCount
-       e2SubscriptionDirectives.RMRRoutingNeeded = &routingNeeded
+       e2SubscriptionDirectives.RMRRoutingNeeded = routingNeeded
        p.SubsReqParams.E2SubscriptionDirectives = e2SubscriptionDirectives
 
 }