Support for handling unordered IEs in RIC Subscription Response messgae
[ric-plt/submgr.git] / pkg / control / ut_messaging_test.go
index 3e9a51b..3d0b448 100644 (file)
@@ -432,7 +432,7 @@ func TestRESTSubReqAndE1apDeleteReqPackingError(t *testing.T) {
 }
 
 //-----------------------------------------------------------------------------
-// TestRESTSubReqAndE1apDeleteRespUnpackingError
+// TestRESTSubReqAndE2APDeleteRespUnpackingError
 //
 //   stub                             stub          stub
 // +-------+        +---------+    +---------+   +---------+
@@ -476,7 +476,7 @@ func TestRESTSubReqAndE1apDeleteReqPackingError(t *testing.T) {
 //
 //-----------------------------------------------------------------------------
 
-func TestRESTSubReqAndE1apDeleteRespUnpackingError(t *testing.T) {
+func TestRESTSubReqAndE2APDeleteRespUnpackingError(t *testing.T) {
 
        restSubId, e2SubsId := createSubscription(t, xappConn1, e2termConn1, nil)
 
@@ -880,6 +880,100 @@ func TestSubReqAndSubDelOk(t *testing.T) {
        mainCtrl.VerifyCounterValues(t)
 }
 
+//-----------------------------------------------------------------------------
+
+//-----------------------------------------------------------------------------
+// TestSubReqAndSubDelOkOutofOrderIEs
+//
+//   stub                          stub
+// +-------+     +---------+    +---------+
+// | xapp  |     | submgr  |    | e2term  |
+// +-------+     +---------+    +---------+
+//     |              |              |
+//     | SubReq       |              |
+//     |------------->|              |
+//     |              |              |
+//     |              | SubReq       |
+//     |              |------------->|
+//     |              |              |
+//     |              |      SubResp | (Out of Order IEs)
+//     |              |<-------------|
+//     |              |              |
+//     |      SubResp |              |
+//     |<-------------|              |
+//     |              |              |
+//     |              |              |
+//     | SubDelReq    |              |
+//     |------------->|              |
+//     |              |              |
+//     |              | SubDelReq    |
+//     |              |------------->|
+//     |              |              |
+//     |              |   SubDelResp |
+//     |              |<-------------|
+//     |              |              |
+//     |   SubDelResp |              |
+//     |<-------------|              |
+//
+//-----------------------------------------------------------------------------
+
+func TestSubReqAndSubDelOkOutofOrderIEs(t *testing.T) {
+       CaseBegin("TestSubReqAndSubDelOkOutofOrderIEs")
+
+       mainCtrl.c.e2ap.SetE2IEOrderCheck(0)
+       // Init counter check
+       mainCtrl.CounterValuesToBeVeriefied(t, CountersToBeAdded{
+               Counter{cSubReqFromXapp, 1},
+               Counter{cSubReqToE2, 1},
+               Counter{cSubRespFromE2, 1},
+               Counter{cSubRespToXapp, 1},
+               Counter{cSubDelReqFromXapp, 1},
+               Counter{cSubDelReqToE2, 1},
+               Counter{cSubDelRespFromE2, 1},
+               Counter{cSubDelRespToXapp, 1},
+       })
+
+       cretrans := xappConn1.SendSubsReq(t, nil, nil)
+       if cretrans == nil {
+               t.Logf("Could not send SubsReq")
+               t.FailNow()
+       }
+       crereq, cremsg := e2termConn1.RecvSubsReq(t)
+       if crereq == nil || cremsg == nil {
+               t.Logf("Could not recieve SubsReq")
+               t.FailNow()
+       }
+
+       e2termConn1.SendSubsResp(t, crereq, cremsg)
+
+       mainCtrl.c.e2ap.SetE2IEOrderCheck(0)
+
+       e2SubsId := xappConn1.RecvSubsResp(t, cretrans)
+       resp, _ := xapp.Subscription.QuerySubscriptions()
+       assert.Equal(t, resp[0].SubscriptionID, int64(e2SubsId))
+       assert.Equal(t, resp[0].Meid, "RAN_NAME_1")
+       assert.Equal(t, resp[0].ClientEndpoint, []string{"localhost:13560"})
+
+       deltrans := xappConn1.SendSubsDelReq(t, nil, e2SubsId)
+       delreq, delmsg := e2termConn1.RecvSubsDelReq(t)
+
+       e2termConn1.SendSubsDelResp(t, delreq, delmsg)
+       xappConn1.RecvSubsDelResp(t, deltrans)
+
+       //Wait that subs is cleaned
+       mainCtrl.wait_subs_clean(t, e2SubsId, 10)
+
+       xappConn1.TestMsgChanEmpty(t)
+       xappConn2.TestMsgChanEmpty(t)
+       e2termConn1.TestMsgChanEmpty(t)
+       mainCtrl.wait_registry_empty(t, 10)
+
+       mainCtrl.VerifyCounterValues(t)
+       mainCtrl.c.e2ap.SetE2IEOrderCheck(1)
+}
+
+//-----------------------------------------------------------------------------
+
 //-----------------------------------------------------------------------------
 // TestSubReqRetransmission
 //
@@ -2745,7 +2839,7 @@ func TestDelAllE2nodeSubsViaDebugIf(t *testing.T) {
        }
 
        // Simulate deletion through REST test and debug interface
-       mainCtrl.SendGetRequest(t, "localhost:8080", "/ric/v1/delete_all_e2node_subscriptions/RAN_NAME_1") // RAN_NAME_1 = ranName
+       mainCtrl.SendDeleteRequest(t, "localhost:8080", "/ric/v1/delete_all_e2node_subscriptions/RAN_NAME_1") // RAN_NAME_1 = ranName
        delreq, delmsg := e2termConn1.RecvSubsDelReq(t)
        e2termConn1.SendSubsDelResp(t, delreq, delmsg)
 
@@ -2833,7 +2927,7 @@ func TestDelAllxAppSubsViaDebugIf(t *testing.T) {
        assert.Equal(t, true, mainCtrl.VerifyStringExistInSlice("localhost", xappList))
 
        // Simulate deletion through REST test and debug interface
-       mainCtrl.SendGetRequest(t, "localhost:8080", "/ric/v1/delete_all_xapp_subscriptions/localhost") // localhost = xappServiceName
+       mainCtrl.SendDeleteRequest(t, "localhost:8080", "/ric/v1/delete_all_xapp_subscriptions/localhost") // localhost = xappServiceName
        delreq, delmsg := e2termConn1.RecvSubsDelReq(t)
        e2termConn1.SendSubsDelResp(t, delreq, delmsg)
 
@@ -4615,6 +4709,83 @@ func TestRESTSubReqSubFailRespInSubmgr(t *testing.T) {
        mainCtrl.VerifyAllClean(t)
 }
 
+//-----------------------------------------------------------------------------
+// TestRESTSubReqPartialResp
+//
+//   stub                          stub
+// +-------+        +---------+    +---------+
+// | xapp  |        | submgr  |    | e2term  |
+// +-------+        +---------+    +---------+
+//     |                 |              |
+//     | RESTSubReq      |              |
+//     |---------------->|              |
+//     | RESTSubResp     |              |
+//     |<----------------|              |
+//     |                 | SubReq       |
+//     |                 |------------->|
+//     |                 | SubResp      | Partially accepted
+//     |                 |<-------------|
+//     |                 |              |
+//     | RESTNotif       |              |
+//     |<----------------|              |
+//     |                 |              |
+//     |           [SUBS DELETE]        |
+//     |                 |              |
+//
+//-----------------------------------------------------------------------------
+
+func TestRESTSubReqPartialResp(t *testing.T) {
+
+       // Init counter check
+       mainCtrl.CounterValuesToBeVeriefied(t, CountersToBeAdded{
+               Counter{cRestSubReqFromXapp, 1},
+               Counter{cRestSubRespToXapp, 1},
+               Counter{cSubReqToE2, 1},
+               Counter{cSubRespFromE2, 1},
+               Counter{cPartialSubRespFromE2, 1},
+               Counter{cRestSubNotifToXapp, 1},
+               Counter{cRestSubDelReqFromXapp, 1},
+               Counter{cSubDelReqToE2, 1},
+               Counter{cSubDelRespFromE2, 1},
+               Counter{cRestSubDelRespToXapp, 1},
+       })
+
+       // Req
+       params := xappConn1.GetRESTSubsReqReportParams(subReqCount)
+
+       actionId := int64(2)
+       actionType := "report"
+       actionDefinition := []int64{5678, 1}
+       subsequestActionType := "continue"
+       timeToWait := "w10ms"
+       params.AppendActionToActionToBeSetupList(actionId, actionType, actionDefinition, subsequestActionType, timeToWait)
+
+       restSubId := xappConn1.SendRESTSubsReq(t, params)
+       crereq, cremsg := e2termConn1.RecvSubsReq(t)
+       xappConn1.ExpectRESTNotification(t, restSubId)
+
+       actionNotAdmittedItem := e2ap.ActionNotAdmittedItem{}
+       actionNotAdmittedItem.ActionId = 1
+       actionNotAdmittedItem.Cause.Content = 1
+       actionNotAdmittedItem.Cause.Value = 8
+       actionNotAdmittedList := e2ap.ActionNotAdmittedList{}
+       actionNotAdmittedList.Items = append(actionNotAdmittedList.Items, actionNotAdmittedItem)
+       e2termConn1.SendPartialSubsResp(t, crereq, cremsg, actionNotAdmittedList)
+       e2SubsId := xappConn1.WaitRESTNotification(t, restSubId)
+
+       queryXappSubscription(t, int64(e2SubsId), "RAN_NAME_1", []string{"localhost:13560"})
+
+       // Del
+       deleteSubscription(t, xappConn1, e2termConn1, &restSubId)
+
+       mainCtrl.wait_subs_clean(t, e2SubsId, 10)
+       //Wait that subs is cleaned
+       waitSubsCleanup(t, e2SubsId, 10)
+
+       mainCtrl.VerifyCounterValues(t)
+       mainCtrl.VerifyAllClean(t)
+}
+
 //-----------------------------------------------------------------------------
 // TestRESTSubDelReqRetryInSubmgr
 //