Add new test cases 34/6134/2
authorAnssi Mannila <anssi.mannila@nokia.com>
Tue, 25 May 2021 08:51:31 +0000 (11:51 +0300)
committerAnssi Mannila <anssi.mannila@nokia.com>
Tue, 25 May 2021 10:57:30 +0000 (13:57 +0300)
Change-Id: Idb6809a9b9228e3f465e20b1f8a3f83a3fea2b96
Signed-off-by: Anssi Mannila <anssi.mannila@nokia.com>
pkg/control/control.go
pkg/control/ut_ctrl_submgr_test.go
pkg/control/ut_messaging_test.go
pkg/teststube2ap/stubE2.go

index 9b3f43d..800145e 100755 (executable)
@@ -882,6 +882,7 @@ func (c *Control) sendE2TSubscriptionDeleteRequest(subs *Subscription, trans *Tr
 func (c *Control) handleE2TSubscriptionResponse(params *xapp.RMRParams) {
        xapp.Logger.Info("MSG from E2T: %s", params.String())
        c.UpdateCounter(cSubRespFromE2)
+
        subRespMsg, err := c.e2ap.UnpackSubscriptionResponse(params.Payload)
        if err != nil {
                xapp.Logger.Error("MSG-SubResp %s", idstring(err, params))
@@ -1004,14 +1005,14 @@ func typeofSubsMessage(v interface{}) string {
                return "NIL"
        }
        switch v.(type) {
-       case *e2ap.E2APSubscriptionRequest:
-               return "SubReq"
+       //case *e2ap.E2APSubscriptionRequest:
+       //      return "SubReq"
        case *e2ap.E2APSubscriptionResponse:
                return "SubResp"
        case *e2ap.E2APSubscriptionFailure:
                return "SubFail"
-       case *e2ap.E2APSubscriptionDeleteRequest:
-               return "SubDelReq"
+       //case *e2ap.E2APSubscriptionDeleteRequest:
+       //      return "SubDelReq"
        case *e2ap.E2APSubscriptionDeleteResponse:
                return "SubDelResp"
        case *e2ap.E2APSubscriptionDeleteFailure:
index 038c20a..9ec0e84 100644 (file)
@@ -95,8 +95,15 @@ func (mc *testingSubmgrControl) SimulateRestart(t *testing.T) {
        go mainCtrl.c.HandleUncompletedSubscriptions(mainCtrl.c.registry.register)
 }
 
+func (mc *testingSubmgrControl) MakeTransactionNil(t *testing.T, subId uint32) {
+
+       mc.TestLog(t, "Makin transaction nil for SubId=%v", subId)
+       subs := mainCtrl.c.registry.GetSubscription(subId)
+       subs.TheTrans = nil
+}
+
 func (mc *testingSubmgrControl) SetResetTestFlag(t *testing.T, status bool) {
-       mc.TestLog(t, "ResetTestFlag set to %v=", status)
+       mc.TestLog(t, "ResetTestFlag set to %v", status)
        mainCtrl.c.ResetTestFlag = status
 }
 
index d20b872..e3d6655 100644 (file)
@@ -4891,6 +4891,837 @@ func TestRESTSubReqReportSameActionDiffSubsAction(t *testing.T) {
 
 }
 
+//-----------------------------------------------------------------------------
+// TestRESTUnpackSubscriptionResponseDecodeFail
+//
+//   stub                             stub
+// +-------+        +---------+    +---------+
+// | xapp  |        | submgr  |    | e2term  |
+// +-------+        +---------+    +---------+
+//     |                 |              |
+//     | RestSubReq      |              |
+//     |---------------->|              |
+//     |                 |              |
+//     |     RESTSubResp |              |
+//     |<----------------|              |
+//     |                 |              |
+//     |                 | SubReq       |
+//     |                 |------------->|
+//     |                 |              |
+//     |                 |      SubResp | ASN.1 decode fails
+//     |                 |<-------------|
+//     |                 |              |
+//     |                 | SubReq       |
+//     |                 |------------->|
+//     |                 |              |
+//     |                 |      SubFail | Duplicated action
+//     |                 |<-------------|
+//     | RESTNotif (fail)|              |
+//     |<----------------|              |
+//     |                 | SubDelReq    |
+//     |                 |------------->|
+//     |                 |              |
+//     |                 |   SubDelResp |
+//     |                 |<-------------|
+//
+//-----------------------------------------------------------------------------
+func TestRESTUnpackSubscriptionResponseDecodeFail(t *testing.T) {
+       xapp.Logger.Info("TEST: TestRESTUnpackSubscriptionResponseDecodeFail")
+       subReqCount := 1
+       parameterSet := 1 // E2SM-gNB-X2
+       actionDefinitionPresent := true
+       actionParamCount := 1
+
+       // Req
+       params := xappConn1.GetRESTSubsReqReportParams(subReqCount, parameterSet, actionDefinitionPresent, actionParamCount)
+       restSubId := xappConn1.SendRESTSubsReq(t, params)
+
+       crereq, cremsg := e2termConn1.RecvSubsReq(t)
+       // Decode of this response fails which will result resending original request
+       e2termConn1.SendInvalidE2Asn1Resp(t, cremsg, xapp.RIC_SUB_RESP)
+
+       _, cremsg = e2termConn1.RecvSubsReq(t)
+
+       xappConn1.ExpectRESTNotification(t, restSubId)
+
+       // Subscription already created in E2 Node.
+       fparams := &teststube2ap.E2StubSubsFailParams{}
+       fparams.Set(crereq)
+       fparams.SetCauseVal(0, 1, 3) // CauseRIC / duplicate-action
+       e2termConn1.SendSubsFail(t, fparams, cremsg)
+
+       delreq, delmsg := e2termConn1.RecvSubsDelReq(t)
+       e2termConn1.SendSubsDelResp(t, delreq, delmsg)
+
+       instanceId := xappConn1.WaitRESTNotification(t, restSubId)
+       xapp.Logger.Info("TEST: REST notification received e2SubsId=%v", instanceId)
+
+       // Wait that subs is cleaned
+       mainCtrl.wait_subs_clean(t, crereq.RequestId.InstanceId, 10)
+
+       xappConn1.TestMsgChanEmpty(t)
+       e2termConn1.TestMsgChanEmpty(t)
+       mainCtrl.wait_registry_empty(t, 10)
+}
+
+//-----------------------------------------------------------------------------
+// TestRESTUnpackSubscriptionResponseUnknownInstanceId
+//
+//   stub                             stub
+// +-------+        +---------+    +---------+
+// | xapp  |        | submgr  |    | e2term  |
+// +-------+        +---------+    +---------+
+//     |                 |              |
+//     | RestSubReq      |              |
+//     |---------------->|              |
+//     |                 |              |
+//     |     RESTSubResp |              |
+//     |<----------------|              |
+//     |                 |              |
+//     |                 | SubReq       |
+//     |                 |------------->|
+//     |                 |              |
+//     |                 |      SubResp | Unknown instanceId
+//     |                 |<-------------|
+//     |                 |              |
+//     |                 | SubReq       |
+//     |                 |------------->|
+//     |                 |              |
+//     |                 |      SubFail | Duplicated action
+//     |                 |<-------------|
+//     | RESTNotif (fail)|              |
+//     |<----------------|              |
+//     |                 | SubDelReq    |
+//     |                 |------------->|
+//     |                 |              |
+//     |                 |   SubDelResp |
+//     |                 |<-------------|
+//
+//-----------------------------------------------------------------------------
+func TestRESTUnpackSubscriptionResponseUnknownInstanceId(t *testing.T) {
+       xapp.Logger.Info("TEST: TestRESTUnpackSubscriptionResponseUnknownInstanceId")
+       subReqCount := 1
+       parameterSet := 1 // E2SM-gNB-X2
+       actionDefinitionPresent := true
+       actionParamCount := 1
+
+       // Req
+       params := xappConn1.GetRESTSubsReqReportParams(subReqCount, parameterSet, actionDefinitionPresent, actionParamCount)
+       restSubId := xappConn1.SendRESTSubsReq(t, params)
+
+       crereq, cremsg := e2termConn1.RecvSubsReq(t)
+
+       // Unknown instanceId in this response which will result resending original request
+       orgInstanceId := crereq.RequestId.InstanceId
+       crereq.RequestId.InstanceId = 0
+       e2termConn1.SendSubsResp(t, crereq, cremsg)
+
+       _, cremsg = e2termConn1.RecvSubsReq(t)
+
+       xappConn1.ExpectRESTNotification(t, restSubId)
+
+       // Subscription already created in E2 Node.
+       fparams := &teststube2ap.E2StubSubsFailParams{}
+       fparams.Set(crereq)
+       fparams.SetCauseVal(0, 1, 3) // CauseRIC / duplicate-action
+       e2termConn1.SendSubsFail(t, fparams, cremsg)
+
+       delreq, delmsg := e2termConn1.RecvSubsDelReq(t)
+       e2termConn1.SendSubsDelResp(t, delreq, delmsg)
+
+       instanceId := xappConn1.WaitRESTNotification(t, restSubId)
+       xapp.Logger.Info("TEST: REST notification received e2SubsId=%v", instanceId)
+
+       // Wait that subs is cleaned
+       mainCtrl.wait_subs_clean(t, orgInstanceId, 10)
+
+       xappConn1.TestMsgChanEmpty(t)
+       e2termConn1.TestMsgChanEmpty(t)
+       mainCtrl.wait_registry_empty(t, 10)
+}
+
+//-----------------------------------------------------------------------------
+// TestRESTUnpackSubscriptionResponseNoTransaction
+//
+//   stub                             stub
+// +-------+        +---------+    +---------+
+// | xapp  |        | submgr  |    | e2term  |
+// +-------+        +---------+    +---------+
+//     |                 |              |
+//     | RestSubReq      |              |
+//     |---------------->|              |
+//     |                 |              |
+//     |     RESTSubResp |              |
+//     |<----------------|              |
+//     |                 |              |
+//     |                 | SubReq       |
+//     |                 |------------->|
+//     |                 |              |
+//     |                 |      SubResp | No transaction for the response
+//     |                 |<-------------|
+//     |                 |              |
+//     |                 | SubReq       |
+//     |                 |------------->|
+//     |                 |              |
+//     |                 |      SubFail | Duplicated action
+//     |                 |<-------------|
+//     | RESTNotif (fail)|              |
+//     |<----------------|              |
+//     |                 | SubDelReq    |
+//     |                 |------------->|
+//     |                 |              |
+//     |                 |   SubDelResp |
+//     |                 |<-------------|
+//     |                 |              |
+//     |                 | SubDelReq    |
+//     |                 |------------->|
+//     |                 |              |
+//     |                 |   SubDelResp |
+//     |                 |<-------------|
+//
+//-----------------------------------------------------------------------------
+func TestRESTUnpackSubscriptionResponseNoTransaction(t *testing.T) {
+       xapp.Logger.Info("TEST: TestRESTUnpackSubscriptionResponseNoTransaction")
+       subReqCount := 1
+       parameterSet := 1 // E2SM-gNB-X2
+       actionDefinitionPresent := true
+       actionParamCount := 1
+
+       // Req
+       params := xappConn1.GetRESTSubsReqReportParams(subReqCount, parameterSet, actionDefinitionPresent, actionParamCount)
+       restSubId := xappConn1.SendRESTSubsReq(t, params)
+
+       crereq, cremsg := e2termConn1.RecvSubsReq(t)
+
+       mainCtrl.MakeTransactionNil(t, crereq.RequestId.InstanceId)
+       // No transaction exist for this response which will result resending original request
+       e2termConn1.SendSubsResp(t, crereq, cremsg)
+
+       _, cremsg = e2termConn1.RecvSubsReq(t)
+
+       xappConn1.ExpectRESTNotification(t, restSubId)
+
+       // Subscription already created in E2 Node.
+       fparams := &teststube2ap.E2StubSubsFailParams{}
+       fparams.Set(crereq)
+       fparams.SetCauseVal(0, 1, 3) // CauseRIC / duplicate-action
+       e2termConn1.SendSubsFail(t, fparams, cremsg)
+
+       delreq, delmsg := e2termConn1.RecvSubsDelReq(t)
+       e2termConn1.SendSubsDelResp(t, delreq, delmsg)
+
+       // Resending happens because there no transaction
+       delreq, delmsg = e2termConn1.RecvSubsDelReq(t)
+       e2termConn1.SendSubsDelResp(t, delreq, delmsg)
+
+       instanceId := xappConn1.WaitRESTNotification(t, restSubId)
+       xapp.Logger.Info("TEST: REST notification received e2SubsId=%v", instanceId)
+
+       // Wait that subs is cleaned
+       mainCtrl.wait_subs_clean(t, crereq.RequestId.InstanceId, 10)
+
+       xappConn1.TestMsgChanEmpty(t)
+       e2termConn1.TestMsgChanEmpty(t)
+       mainCtrl.wait_registry_empty(t, 10)
+
+}
+
+//-----------------------------------------------------------------------------
+// TestRESTUnpackSubscriptionFailureDecodeFail
+//
+//   stub                             stub
+// +-------+        +---------+    +---------+
+// | xapp  |        | submgr  |    | e2term  |
+// +-------+        +---------+    +---------+
+//     |                 |              |
+//     | RestSubReq      |              |
+//     |---------------->|              |
+//     |                 |              |
+//     |     RESTSubResp |              |
+//     |<----------------|              |
+//     |                 |              |
+//     |                 | SubReq       |
+//     |                 |------------->|
+//     |                 |              |
+//     |                 |      SubFail | ASN.1 decode fails
+//     |                 |<-------------|
+//     |                 |              |
+//     |                 | SubReq       |
+//     |                 |------------->|
+//     |                 |              |
+//     |                 |      SubFail | Duplicated action
+//     |                 |<-------------|
+//     | RESTNotif (fail)|              |
+//     |<----------------|              |
+//     |                 | SubDelReq    |
+//     |                 |------------->|
+//     |                 |              |
+//     |                 |   SubDelResp |
+//     |                 |<-------------|
+//
+//-----------------------------------------------------------------------------
+func TestRESTUnpackSubscriptionFailureDecodeFail(t *testing.T) {
+       xapp.Logger.Info("TEST: TestRESTUnpackSubscriptionFailureDecodeFail")
+       subReqCount := 1
+       parameterSet := 1 // E2SM-gNB-X2
+       actionDefinitionPresent := true
+       actionParamCount := 1
+
+       // Req
+       params := xappConn1.GetRESTSubsReqReportParams(subReqCount, parameterSet, actionDefinitionPresent, actionParamCount)
+       restSubId := xappConn1.SendRESTSubsReq(t, params)
+
+       crereq, cremsg := e2termConn1.RecvSubsReq(t)
+
+       // Decode of this response fails which will result resending original request
+       e2termConn1.SendInvalidE2Asn1Resp(t, cremsg, xapp.RIC_SUB_FAILURE)
+
+       _, cremsg = e2termConn1.RecvSubsReq(t)
+
+       xappConn1.ExpectRESTNotification(t, restSubId)
+
+       // Subscription already created in E2 Node.
+       fparams := &teststube2ap.E2StubSubsFailParams{}
+       fparams.Set(crereq)
+       fparams.SetCauseVal(0, 1, 3) // CauseRIC / duplicate-action
+       e2termConn1.SendSubsFail(t, fparams, cremsg)
+
+       delreq, delmsg := e2termConn1.RecvSubsDelReq(t)
+       e2termConn1.SendSubsDelResp(t, delreq, delmsg)
+
+       instanceId := xappConn1.WaitRESTNotification(t, restSubId)
+       xapp.Logger.Info("TEST: REST notification received e2SubsId=%v", instanceId)
+
+       // Wait that subs is cleaned
+       mainCtrl.wait_subs_clean(t, crereq.RequestId.InstanceId, 10)
+
+       xappConn1.TestMsgChanEmpty(t)
+       e2termConn1.TestMsgChanEmpty(t)
+       mainCtrl.wait_registry_empty(t, 10)
+}
+
+//-----------------------------------------------------------------------------
+// TestRESTUnpackSubscriptionResponseUnknownInstanceId
+//
+//   stub                             stub
+// +-------+        +---------+    +---------+
+// | xapp  |        | submgr  |    | e2term  |
+// +-------+        +---------+    +---------+
+//     |                 |              |
+//     | RestSubReq      |              |
+//     |---------------->|              |
+//     |                 |              |
+//     |     RESTSubResp |              |
+//     |<----------------|              |
+//     |                 |              |
+//     |                 | SubReq       |
+//     |                 |------------->|
+//     |                 |              |
+//     |                 |      SubFail | Unknown instanceId
+//     |                 |<-------------|
+//     |                 |              |
+//     |                 | SubReq       |
+//     |                 |------------->|
+//     |                 |              |
+//     |                 |      SubFail | Duplicated action
+//     |                 |<-------------|
+//     | RESTNotif (fail)|              |
+//     |<----------------|              |
+//     |                 | SubDelReq    |
+//     |                 |------------->|
+//     |                 |              |
+//     |                 |   SubDelResp |
+//     |                 |<-------------|
+//
+//-----------------------------------------------------------------------------
+func TestRESTUnpackSubscriptionFailureUnknownInstanceId(t *testing.T) {
+       xapp.Logger.Info("TEST: TestRESTUnpackSubscriptionFailureUnknownInstanceId")
+       subReqCount := 1
+       parameterSet := 1 // E2SM-gNB-X2
+       actionDefinitionPresent := true
+       actionParamCount := 1
+
+       // Req
+       params := xappConn1.GetRESTSubsReqReportParams(subReqCount, parameterSet, actionDefinitionPresent, actionParamCount)
+       restSubId := xappConn1.SendRESTSubsReq(t, params)
+
+       crereq, cremsg := e2termConn1.RecvSubsReq(t)
+
+       // Unknown instanceId in this response which will result resending original request
+       fparams := &teststube2ap.E2StubSubsFailParams{}
+       fparams.Set(crereq)
+       fparams.Fail.RequestId.InstanceId = 0
+       e2termConn1.SendSubsFail(t, fparams, cremsg)
+
+       _, cremsg = e2termConn1.RecvSubsReq(t)
+
+       xappConn1.ExpectRESTNotification(t, restSubId)
+
+       // Subscription already created in E2 Node.
+       fparams.SetCauseVal(0, 1, 3) // CauseRIC / duplicate-action
+       e2termConn1.SendSubsFail(t, fparams, cremsg)
+
+       delreq, delmsg := e2termConn1.RecvSubsDelReq(t)
+       e2termConn1.SendSubsDelResp(t, delreq, delmsg)
+
+       instanceId := xappConn1.WaitRESTNotification(t, restSubId)
+       xapp.Logger.Info("TEST: REST notification received e2SubsId=%v", instanceId)
+
+       // Wait that subs is cleaned
+       mainCtrl.wait_subs_clean(t, crereq.RequestId.InstanceId, 10)
+
+       xappConn1.TestMsgChanEmpty(t)
+       e2termConn1.TestMsgChanEmpty(t)
+       mainCtrl.wait_registry_empty(t, 10)
+}
+
+//-----------------------------------------------------------------------------
+// TestRESTUnpackSubscriptionFailureNoTransaction
+//
+//   stub                             stub
+// +-------+        +---------+    +---------+
+// | xapp  |        | submgr  |    | e2term  |
+// +-------+        +---------+    +---------+
+//     |                 |              |
+//     | RestSubReq      |              |
+//     |---------------->|              |
+//     |                 |              |
+//     |     RESTSubResp |              |
+//     |<----------------|              |
+//     |                 |              |
+//     |                 | SubReq       |
+//     |                 |------------->|
+//     |                 |              |
+//     |                 |      SubFail | No transaction for the response
+//     |                 |<-------------|
+//     |                 |              |
+//     |                 | SubReq       |
+//     |                 |------------->|
+//     |                 |              |
+//     |                 |      SubFail | Duplicated action
+//     |                 |<-------------|
+//     | RESTNotif (fail)|              |
+//     |<----------------|              |
+//     |                 | SubDelReq    |
+//     |                 |------------->|
+//     |                 |              |
+//     |                 |   SubDelResp |
+//     |                 |<-------------|
+//
+//-----------------------------------------------------------------------------
+func TestRESTUnpackSubscriptionFailureNoTransaction(t *testing.T) {
+       xapp.Logger.Info("TEST: TestRESTUnpackSubscriptionFailureNoTransaction")
+       subReqCount := 1
+       parameterSet := 1 // E2SM-gNB-X2
+       actionDefinitionPresent := true
+       actionParamCount := 1
+
+       // Req
+       params := xappConn1.GetRESTSubsReqReportParams(subReqCount, parameterSet, actionDefinitionPresent, actionParamCount)
+       restSubId := xappConn1.SendRESTSubsReq(t, params)
+
+       crereq, cremsg := e2termConn1.RecvSubsReq(t)
+
+       mainCtrl.MakeTransactionNil(t, crereq.RequestId.InstanceId)
+
+       // No transaction exist for this response which will result resending original request
+       fparams := &teststube2ap.E2StubSubsFailParams{}
+       fparams.Set(crereq)
+       e2termConn1.SendSubsFail(t, fparams, cremsg)
+
+       _, cremsg = e2termConn1.RecvSubsReq(t)
+
+       xappConn1.ExpectRESTNotification(t, restSubId)
+
+       // Subscription already created in E2 Node.
+       fparams.SetCauseVal(0, 1, 3) // CauseRIC / duplicate-action
+       e2termConn1.SendSubsFail(t, fparams, cremsg)
+
+       delreq, delmsg := e2termConn1.RecvSubsDelReq(t)
+       e2termConn1.SendSubsDelResp(t, delreq, delmsg)
+
+       // Resending happens because there no transaction
+       delreq, delmsg = e2termConn1.RecvSubsDelReq(t)
+       e2termConn1.SendSubsDelResp(t, delreq, delmsg)
+
+       instanceId := xappConn1.WaitRESTNotification(t, restSubId)
+       xapp.Logger.Info("TEST: REST notification received e2SubsId=%v", instanceId)
+
+       // Wait that subs is cleaned
+       mainCtrl.wait_subs_clean(t, crereq.RequestId.InstanceId, 10)
+
+       xappConn1.TestMsgChanEmpty(t)
+       e2termConn1.TestMsgChanEmpty(t)
+       mainCtrl.wait_registry_empty(t, 10)
+}
+
+//-----------------------------------------------------------------------------
+// TestRESTUnpackSubscriptionDeleteResponseDecodeFail
+//
+//   stub                             stub
+// +-------+        +---------+    +---------+
+// | xapp  |        | submgr  |    | e2term  |
+// +-------+        +---------+    +---------+
+//     |                 |              |
+//     |            [SUBS CREATE]       |
+//     |                 |              |
+//     |                 |              |
+//     | RESTSubDelReq   |              |
+//     |---------------->|              |
+//     |                 |              |
+//     |  RESTSubDelResp |              |
+//     |<----------------|              |
+//     |                 |              |
+//     |                 | SubDelReq    |
+//     |                 |------------->|
+//     |                 |              |
+//     |                 |   SubDelResp | ASN.1 decode fails
+//     |                 |<-------------|
+//     |                 |              |
+//     |                 | SubDelReq    |
+//     |                 |------------->|
+//     |                 |              |
+//     |                 |   SubDelFail | Subscription does exist any more
+//     |                 |<-------------|
+//     |                 |              |
+//
+//-----------------------------------------------------------------------------
+func TestRESTUnpackSubscriptionDeleteResponseDecodeFail(t *testing.T) {
+       xapp.Logger.Info("TEST: TestRESTUnpackSubscriptionDeleteResponseDecodeFail")
+
+       // Req
+       var params *teststube2ap.RESTSubsReqParams = nil
+       restSubId, e2SubsId := createSubscription(t, xappConn1, e2termConn1, params)
+
+       // Del
+       xappConn1.SendRESTSubsDelReq(t, &restSubId)
+
+       // E2t: Receive 1st SubsDelReq
+       delreq, delmsg := e2termConn1.RecvSubsDelReq(t)
+
+       // Decode of this response fails which will result resending original request
+       e2termConn1.SendInvalidE2Asn1Resp(t, delmsg, xapp.RIC_SUB_DEL_REQ)
+
+       // E2t: Receive 2nd SubsDelReq and send SubsDelResp
+       delreq, delmsg = e2termConn1.RecvSubsDelReq(t)
+
+       // Subscription does not exist in in E2 Node.
+       e2termConn1.SendSubsDelFail(t, delreq, delmsg)
+
+       // Wait that subs is cleaned
+       mainCtrl.wait_subs_clean(t, e2SubsId, 10)
+
+       xappConn1.TestMsgChanEmpty(t)
+       e2termConn1.TestMsgChanEmpty(t)
+       mainCtrl.wait_registry_empty(t, 10)
+}
+
+//-----------------------------------------------------------------------------
+// TestRESTUnpackSubscriptionDeleteResponseUnknownInstanceId
+//
+//   stub                             stub
+// +-------+        +---------+    +---------+
+// | xapp  |        | submgr  |    | e2term  |
+// +-------+        +---------+    +---------+
+//     |                 |              |
+//     |            [SUBS CREATE]       |
+//     |                 |              |
+//     |                 |              |
+//     | RESTSubDelReq   |              |
+//     |---------------->|              |
+//     |                 |              |
+//     |  RESTSubDelResp |              |
+//     |<----------------|              |
+//     |                 |              |
+//     |                 | SubDelReq    |
+//     |                 |------------->|
+//     |                 |              |
+//     |                 |   SubDelResp | Unknown instanceId
+//     |                 |<-------------|
+//     |                 |              |
+//     |                 | SubDelReq    |
+//     |                 |------------->|
+//     |                 |              |
+//     |                 |   SubDelFail | Subscription does exist any more
+//     |                 |<-------------|
+//
+//-----------------------------------------------------------------------------
+func TestRESTUnpackSubscriptionDeleteResponseUnknownInstanceId(t *testing.T) {
+       xapp.Logger.Info("TEST: TestRESTUnpackSubscriptionDeleteResponseUnknownInstanceId")
+
+       // Req
+       var params *teststube2ap.RESTSubsReqParams = nil
+       restSubId, e2SubsId := createSubscription(t, xappConn1, e2termConn1, params)
+
+       // Del
+       xappConn1.SendRESTSubsDelReq(t, &restSubId)
+
+       // E2t: Receive 1st SubsDelReq
+       delreq, delmsg := e2termConn1.RecvSubsDelReq(t)
+
+       // Unknown instanceId in this response which will result resending original request
+       delreq.RequestId.InstanceId = 0
+       e2termConn1.SendSubsDelResp(t, delreq, delmsg)
+
+       // E2t: Receive 2nd SubsDelReq
+       delreq, delmsg = e2termConn1.RecvSubsDelReq(t)
+
+       // Subscription does not exist in in E2 Node.
+       e2termConn1.SendSubsDelFail(t, delreq, delmsg)
+
+       // Wait that subs is cleaned
+       mainCtrl.wait_subs_clean(t, e2SubsId, 10)
+
+       xappConn1.TestMsgChanEmpty(t)
+       e2termConn1.TestMsgChanEmpty(t)
+       mainCtrl.wait_registry_empty(t, 10)
+}
+
+//-----------------------------------------------------------------------------
+// TestRESTUnpackSubscriptionDeleteResponseNoTransaction
+//
+//   stub                             stub
+// +-------+        +---------+    +---------+
+// | xapp  |        | submgr  |    | e2term  |
+// +-------+        +---------+    +---------+
+//     |                 |              |
+//     |            [SUBS CREATE]       |
+//     |                 |              |
+//     |                 |              |
+//     | RESTSubDelReq   |              |
+//     |---------------->|              |
+//     |                 |              |
+//     |  RESTSubDelResp |              |
+//     |<----------------|              |
+//     |                 |              |
+//     |                 | SubDelReq    |
+//     |                 |------------->|
+//     |                 |              |
+//     |                 |   SubDelResp | No transaction for the response
+//     |                 |<-------------|
+//     |                 |              |
+//     |                 | SubDelReq    |
+//     |                 |------------->|
+//     |                 |              |
+//     |                 |   SubDelFail | Subscription does exist any more
+//     |                 |<-------------|
+//
+//-----------------------------------------------------------------------------
+func TestRESTUnpackSubscriptionDeleteResponseNoTransaction(t *testing.T) {
+       xapp.Logger.Info("TEST: TestRESTUnpackSubscriptionDeleteResponseNoTransaction")
+
+       // Req
+       var params *teststube2ap.RESTSubsReqParams = nil
+       restSubId, e2SubsId := createSubscription(t, xappConn1, e2termConn1, params)
+
+       // Del
+       xappConn1.SendRESTSubsDelReq(t, &restSubId)
+
+       // E2t: Receive 1st SubsDelReq
+       delreq, delmsg := e2termConn1.RecvSubsDelReq(t)
+
+       mainCtrl.MakeTransactionNil(t, e2SubsId)
+
+       // No transaction exist for this response which will result resending original request
+       e2termConn1.SendSubsDelResp(t, delreq, delmsg)
+
+       // E2t: Receive 2nd SubsDelReq
+       delreq, delmsg = e2termConn1.RecvSubsDelReq(t)
+
+       // Subscription does not exist in in E2 Node.
+       e2termConn1.SendSubsDelFail(t, delreq, delmsg)
+
+       // Wait that subs is cleaned
+       mainCtrl.wait_subs_clean(t, e2SubsId, 10)
+
+       xappConn1.TestMsgChanEmpty(t)
+       e2termConn1.TestMsgChanEmpty(t)
+       mainCtrl.wait_registry_empty(t, 10)
+}
+
+//-----------------------------------------------------------------------------
+// TestRESTUnpackSubscriptionDeleteFailureDecodeFail
+//
+//   stub                             stub
+// +-------+        +---------+    +---------+
+// | xapp  |        | submgr  |    | e2term  |
+// +-------+        +---------+    +---------+
+//     |                 |              |
+//     |            [SUBS CREATE]       |
+//     |                 |              |
+//     |                 |              |
+//     | RESTSubDelReq   |              |
+//     |---------------->|              |
+//     |                 |              |
+//     |  RESTSubDelResp |              |
+//     |<----------------|              |
+//     |                 |              |
+//     |                 | SubDelReq    |
+//     |                 |------------->|
+//     |                 |              |
+//     |                 |   SubDelFail | ASN.1 decode fails
+//     |                 |<-------------|
+//     |                 |              |
+//     |                 | SubDelReq    |
+//     |                 |------------->|
+//     |                 |              |
+//     |                 |   SubDelFail | Subscription does exist any more
+//     |                 |<-------------|
+//
+//-----------------------------------------------------------------------------
+func TestRESTUnpackSubscriptionDeleteFailureDecodeFail(t *testing.T) {
+       xapp.Logger.Info("TEST: TestRESTUnpackSubscriptionDeleteFailureDecodeFail")
+
+       // Req
+       var params *teststube2ap.RESTSubsReqParams = nil
+       restSubId, e2SubsId := createSubscription(t, xappConn1, e2termConn1, params)
+
+       // Del
+       xappConn1.SendRESTSubsDelReq(t, &restSubId)
+
+       // E2t: Receive 1st SubsDelReq
+       delreq, delmsg := e2termConn1.RecvSubsDelReq(t)
+
+       // Decode of this response fails which will result resending original request
+       e2termConn1.SendInvalidE2Asn1Resp(t, delmsg, xapp.RIC_SUB_DEL_FAILURE)
+
+       // E2t: Receive 2nd SubsDelReq and send SubsDelResp
+       delreq, delmsg = e2termConn1.RecvSubsDelReq(t)
+
+       // Subscription does not exist in in E2 Node.
+       e2termConn1.SendSubsDelFail(t, delreq, delmsg)
+
+       // Wait that subs is cleaned
+       mainCtrl.wait_subs_clean(t, e2SubsId, 10)
+
+       xappConn1.TestMsgChanEmpty(t)
+       e2termConn1.TestMsgChanEmpty(t)
+       mainCtrl.wait_registry_empty(t, 10)
+}
+
+//-----------------------------------------------------------------------------
+// TestRESTUnpackSubscriptionDeleteailureUnknownInstanceId
+//
+//   stub                             stub
+// +-------+        +---------+    +---------+
+// | xapp  |        | submgr  |    | e2term  |
+// +-------+        +---------+    +---------+
+//     |                 |              |
+//     |            [SUBS CREATE]       |
+//     |                 |              |
+//     |                 |              |
+//     | RESTSubDelReq   |              |
+//     |---------------->|              |
+//     |                 |              |
+//     |  RESTSubDelResp |              |
+//     |<----------------|              |
+//     |                 |              |
+//     |                 | SubDelReq    |
+//     |                 |------------->|
+//     |                 |              |
+//     |                 |   SubDelFail | Unknown instanceId
+//     |                 |<-------------|
+//     |                 |              |
+//     |                 | SubDelReq    |
+//     |                 |------------->|
+//     |                 |              |
+//     |                 |   SubDelFail | Subscription does exist any more
+//     |                 |<-------------|
+//
+//-----------------------------------------------------------------------------
+func TestRESTUnpackSubscriptionDeleteailureUnknownInstanceId(t *testing.T) {
+       xapp.Logger.Info("TEST: TestRESTUnpackSubscriptionDeleteailureUnknownInstanceId")
+
+       // Req
+       var params *teststube2ap.RESTSubsReqParams = nil
+       restSubId, e2SubsId := createSubscription(t, xappConn1, e2termConn1, params)
+
+       // Del
+       xappConn1.SendRESTSubsDelReq(t, &restSubId)
+
+       // E2t: Receive 1st SubsDelReq
+       delreq, delmsg := e2termConn1.RecvSubsDelReq(t)
+
+       // Unknown instanceId in this response which will result resending original request
+       delreq.RequestId.InstanceId = 0
+       e2termConn1.SendSubsDelFail(t, delreq, delmsg)
+
+       // E2t: Receive 2nd SubsDelReq
+       delreq, delmsg = e2termConn1.RecvSubsDelReq(t)
+
+       // Subscription does not exist in in E2 Node.
+       e2termConn1.SendSubsDelFail(t, delreq, delmsg)
+
+       // Wait that subs is cleaned
+       mainCtrl.wait_subs_clean(t, e2SubsId, 10)
+
+       xappConn1.TestMsgChanEmpty(t)
+       e2termConn1.TestMsgChanEmpty(t)
+       mainCtrl.wait_registry_empty(t, 10)
+}
+
+//-----------------------------------------------------------------------------
+// TestRESTUnpackSubscriptionDeleteFailureNoTransaction
+//
+//   stub                             stub
+// +-------+        +---------+    +---------+
+// | xapp  |        | submgr  |    | e2term  |
+// +-------+        +---------+    +---------+
+//     |                 |              |
+//     |            [SUBS CREATE]       |
+//     |                 |              |
+//     |                 |              |
+//     | RESTSubDelReq   |              |
+//     |---------------->|              |
+//     |                 |              |
+//     |  RESTSubDelResp |              |
+//     |<----------------|              |
+//     |                 |              |
+//     |                 | SubDelReq    |
+//     |                 |------------->|
+//     |                 |              |
+//     |                 |   SubDelFail | No transaction for the response
+//     |                 |<-------------|
+//     |                 |              |
+//     |                 | SubDelReq    |
+//     |                 |------------->|
+//     |                 |              |
+//     |                 |   SubDelFail | Subscription does exist any more
+//     |                 |<-------------|
+//
+//-----------------------------------------------------------------------------
+func TestRESTUnpackSubscriptionDeleteFailureNoTransaction(t *testing.T) {
+       xapp.Logger.Info("TEST: TestRESTUnpackSubscriptionDeleteFailureNoTransaction")
+
+       // Req
+       var params *teststube2ap.RESTSubsReqParams = nil
+       restSubId, e2SubsId := createSubscription(t, xappConn1, e2termConn1, params)
+
+       // Del
+       xappConn1.SendRESTSubsDelReq(t, &restSubId)
+
+       // E2t: Receive 1st SubsDelReq
+       delreq, delmsg := e2termConn1.RecvSubsDelReq(t)
+
+       mainCtrl.MakeTransactionNil(t, e2SubsId)
+
+       // No transaction exist for this response which will result resending original request
+       e2termConn1.SendSubsDelFail(t, delreq, delmsg)
+
+       // E2t: Receive 2nd SubsDelReq
+       delreq, delmsg = e2termConn1.RecvSubsDelReq(t)
+
+       // Subscription does not exist in in E2 Node.
+       e2termConn1.SendSubsDelFail(t, delreq, delmsg)
+
+       // Wait that subs is cleaned
+       mainCtrl.wait_subs_clean(t, e2SubsId, 10)
+
+       xappConn1.TestMsgChanEmpty(t)
+       e2termConn1.TestMsgChanEmpty(t)
+       mainCtrl.wait_registry_empty(t, 10)
+}
+
 ////////////////////////////////////////////////////////////////////////////////////
 //   Services for UT cases
 ////////////////////////////////////////////////////////////////////////////////////
index bcc6aae..5d28d3b 100644 (file)
@@ -324,6 +324,38 @@ func (tc *E2Stub) SendSubsResp(t *testing.T, req *e2ap.E2APSubscriptionRequest,
        }
 }
 
+//-----------------------------------------------------------------------------
+//
+//-----------------------------------------------------------------------------
+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.Info("SEND INVALID ASN.1 SUB RESP")
+
+       } else if params.Mtype == xapp.RIC_SUB_FAILURE {
+               tc.Info("SEND INVALID ASN.1 SUB FAILURE")
+
+       } else if params.Mtype == xapp.RIC_SUB_DEL_RESP {
+               tc.Info("SEND INVALID ASN.1 SUB DEL RESP")
+
+       } else if params.Mtype == xapp.RIC_SUB_DEL_FAILURE {
+               tc.Info("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())
+       }
+}
+
 //-----------------------------------------------------------------------------
 //
 //-----------------------------------------------------------------------------
@@ -597,7 +629,7 @@ func (tc *E2Stub) SendSubsDelFail(t *testing.T, req *e2ap.E2APSubscriptionDelete
        resp.RequestId.Id = req.RequestId.Id
        resp.RequestId.InstanceId = req.RequestId.InstanceId
        resp.FunctionId = req.FunctionId
-       resp.Cause.Content = 4 // CauseMisc
+       resp.Cause.Content = 5 // CauseMisc
        resp.Cause.Value = 3   // unspecified
 
        packerr, packedMsg := e2SubsDelFail.Pack(resp)