Added UT cases for Del Req e2ap un/packing errors
[ric-plt/submgr.git] / pkg / control / ut_messaging_test.go
index 891437f..e6d6646 100644 (file)
@@ -24,11 +24,178 @@ import (
        "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/teststube2ap"
        "gerrit.o-ran-sc.org/r/ric-plt/xapp-frame/pkg/xapp"
        "github.com/stretchr/testify/assert"
 )
 
+func TestSuiteSetup(t *testing.T) {
+       // The effect of this call shall endure thgough the UT suite!
+       // If this causes any issues, the previout interface can be restored
+       // like this:git log
+       // SetPackerIf(e2ap_wrapper.NewAsn1E2APPacker())
+
+       SetPackerIf(e2ap_wrapper.NewUtAsn1E2APPacker())
+}
+
+//-----------------------------------------------------------------------------
+// TestRESTSubReqAndDeleteOkWithE2apUtWrapper
+//
+//   stub                             stub          stub
+// +-------+        +---------+    +---------+   +---------+
+// | xapp  |        | submgr  |    | e2term  |   |  rtmgr  |
+// +-------+        +---------+    +---------+   +---------+
+//     |                 |              |             |
+//     | RESTSubReq      |              |             |
+//     |---------------->|              |             |
+//     |                 | RouteCreate  |             |
+//     |                 |--------------------------->|  // The order of these events may vary
+//     |                 |              |             |
+//     |     RESTSubResp |              |             |  // The order of these events may vary
+//     |<----------------|              |             |
+//     |                 | RouteResponse|             |
+//     |                 |<---------------------------|  // The order of these events may vary
+//     |                 |              |             |
+//     |                 | SubReq       |             |
+//     |                 |------------->|             |  // The order of these events may vary
+//     |                 |              |             |
+//     |                 |      SubResp |             |
+//     |                 |<-------------|             |
+//     |      RESTNotif1 |              |             |
+//     |<----------------|              |             |
+//     |                 |              |             |
+//     | RESTSubDelReq   |              |             |
+//     |---------------->|              |             |
+//     |                 | SubDelReq    |             |
+//     |                 |------------->|             |
+//     |                 |              |             |
+//     |   RESTSubDelResp|              |             |
+//     |<----------------|              |             |
+//     |                 |              |             |
+//     |                 |   SubDelResp |             |
+//     |                 |<-------------|             |
+//     |                 |              |             |
+//     |                 |              |             |
+//
+//-----------------------------------------------------------------------------
+func TestRESTSubReqAndDeleteOkWithE2apUtWrapper(t *testing.T) {
+
+       restSubId, e2SubsId := createSubscription(t, xappConn1, e2termConn1, nil)
+
+       deleteSubscription(t, xappConn1, e2termConn1, &restSubId)
+
+       waitSubsCleanup(t, e2SubsId, 10)
+}
+
+//-----------------------------------------------------------------------------
+// TestRESTSubReqAndE1apDeleteReqPackingError
+//
+//   stub                             stub          stub
+// +-------+        +---------+    +---------+   +---------+
+// | xapp  |        | submgr  |    | e2term  |   |  rtmgr  |
+// +-------+        +---------+    +---------+   +---------+
+//     |                 |              |             |
+//     | RESTSubReq      |              |             |
+//     |---------------->|              |             |
+//     |                 | RouteCreate  |             |
+//     |                 |--------------------------->|  // The order of these events may vary
+//     |                 |              |             |
+//     |     RESTSubResp |              |             |  // The order of these events may vary
+//     |<----------------|              |             |
+//     |                 | RouteResponse|             |
+//     |                 |<---------------------------|  // The order of these events may vary
+//     |                 |              |             |
+//     |                 | SubReq       |             |
+//     |                 |------------->|             |  // The order of these events may vary
+//     |                 |              |             |
+//     |                 |      SubResp |             |
+//     |                 |<-------------|             |
+//     |      RESTNotif1 |              |             |
+//     |<----------------|              |             |
+//     |                 |              |             |
+//     | RESTSubDelReq   |              |             |
+//     |---------------->|              |             |
+//     |                 |              |             |
+//     |   RESTSubDelResp|              |             |
+//     |<----------------|              |             |
+//     |                 |              |             |
+//     |                 |              |             |
+//
+//-----------------------------------------------------------------------------
+func TestRESTSubReqAndE1apDeleteReqPackingError(t *testing.T) {
+
+       restSubId, e2SubsId := createSubscription(t, xappConn1, e2termConn1, nil)
+
+       e2ap_wrapper.AllowE2apToProcess(e2ap_wrapper.SUB_DEL_REQ, false)
+       xappConn1.SendRESTSubsDelReq(t, &restSubId)
+       defer e2ap_wrapper.AllowE2apToProcess(e2ap_wrapper.SUB_DEL_REQ, true)
+
+       waitSubsCleanup(t, e2SubsId, 10)
+}
+
+//-----------------------------------------------------------------------------
+// TestRESTSubReqAndE1apDeleteRespUnpackingError
+//
+//   stub                             stub          stub
+// +-------+        +---------+    +---------+   +---------+
+// | xapp  |        | submgr  |    | e2term  |   |  rtmgr  |
+// +-------+        +---------+    +---------+   +---------+
+//     |                 |              |             |
+//     | RESTSubReq      |              |             |
+//     |---------------->|              |             |
+//     |                 | RouteCreate  |             |
+//     |                 |--------------------------->|  // The order of these events may vary
+//     |                 |              |             |
+//     |     RESTSubResp |              |             |  // The order of these events may vary
+//     |<----------------|              |             |
+//     |                 | RouteResponse|             |
+//     |                 |<---------------------------|  // The order of these events may vary
+//     |                 |              |             |
+//     |                 | SubReq       |             |
+//     |                 |------------->|             |  // The order of these events may vary
+//     |                 |              |             |
+//     |                 |      SubResp |             |
+//     |                 |<-------------|             |
+//     |      RESTNotif1 |              |             |
+//     |<----------------|              |             |
+//     |                 |              |             |
+//     | RESTSubDelReq   |              |             |
+//     |---------------->|              |             |
+//     |                 | SubDelReq    |             |
+//     |                 |------------->|             |
+//     |                 |              |             |
+//     |   RESTSubDelResp|              |             |
+//     |<----------------|              |             | // The order of these events may vary
+//     |                 |              |             |
+//     |                 |   SubDelResp |             |
+//     |                 |<-------------|             | // 1.st NOK
+//     |                 |              |             |
+//     |                 | SubDelReq    |             |
+//     |                 |------------->|             |
+//     |                 |              |             |
+//     |                 |   SubDelResp |             |
+//     |                 |<-------------|             | // 2.nd NOK
+//
+//-----------------------------------------------------------------------------
+
+func TestRESTSubReqAndE1apDeleteRespUnpackingError(t *testing.T) {
+
+       restSubId, e2SubsId := createSubscription(t, xappConn1, e2termConn1, nil)
+
+       xappConn1.SendRESTSubsDelReq(t, &restSubId)
+       e2ap_wrapper.AllowE2apToProcess(e2ap_wrapper.SUB_DEL_RESP, false)
+       delreq, delmsg := e2termConn1.RecvSubsDelReq(t)
+       e2termConn1.SendSubsDelResp(t, delreq, delmsg)
+
+       delreq, delmsg = e2termConn1.RecvSubsDelReq(t)
+       e2termConn1.SendSubsDelResp(t, delreq, delmsg)
+
+       defer e2ap_wrapper.AllowE2apToProcess(e2ap_wrapper.SUB_DEL_RESP, true)
+
+       waitSubsCleanup(t, e2SubsId, 10)
+}
+
 //-----------------------------------------------------------------------------
 // TestSubReqAndRouteNok
 //
@@ -4167,8 +4334,10 @@ func TestRESTSubReqAndSubDelOkSameActionWithRestartsInMiddle(t *testing.T) {
        //      mainCtrl.SimulateRestart(t)
        //      xapp.Logger.Debug("mainCtrl.SimulateRestart done")
 
-       // Delete subscription 1
+       // Delete subscription 1, and wait until it has removed the first endpoint
+       subepcnt := mainCtrl.get_subs_entrypoint_cnt(t, e2SubsId1)
        xappConn1.SendRESTSubsDelReq(t, &restSubId1)
+       mainCtrl.wait_subs_entrypoint_cnt_change(t, e2SubsId1, subepcnt, 10)
 
        // When SDL support for the REST Interface is added
        // the submgr restart statement below should be removed
@@ -4176,7 +4345,6 @@ func TestRESTSubReqAndSubDelOkSameActionWithRestartsInMiddle(t *testing.T) {
 
        //      mainCtrl.SimulateRestart(t)
        //      xapp.Logger.Debug("mainCtrl.SimulateRestart done")
-
        queryXappSubscription(t, int64(e2SubsId1), "RAN_NAME_1", []string{"localhost:13660"})
 
        // Delete subscription 2
@@ -4435,7 +4603,6 @@ func TestRESTTwoReportSubReqAndSubDelOk(t *testing.T) {
        mainCtrl.VerifyCounterValues(t)
 }
 
-/*
 func TestRESTTwoReportSubReqAndSubDelOkNoActParams(t *testing.T) {
 
        subReqCount := 2
@@ -4471,8 +4638,7 @@ func TestRESTTwoReportSubReqAndSubDelOkNoActParams(t *testing.T) {
 
        mainCtrl.VerifyCounterValues(t)
 }
-*/
-/*
+
 func TestRESTFullAmountReportSubReqAndSubDelOk(t *testing.T) {
 
        subReqCount := 19
@@ -4508,7 +4674,6 @@ func TestRESTFullAmountReportSubReqAndSubDelOk(t *testing.T) {
 
        mainCtrl.VerifyCounterValues(t)
 }
-*/
 
 func TestRESTSubReqReportSameActionDiffEventTriggerDefinitionLen(t *testing.T) {
        CaseBegin("TestRESTSubReqReportSameActionDiffEventTriggerDefinitionLen")
@@ -4876,6 +5041,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
 ////////////////////////////////////////////////////////////////////////////////////