RICPLT-2957 Clean old test directory. Unittests can handle these cases
[ric-plt/submgr.git] / pkg / control / messaging_test.go
index e5d426b..60a5dc0 100644 (file)
@@ -34,11 +34,14 @@ import (
 
 var e2asnpacker e2ap.E2APPackerIf = e2ap_wrapper.NewAsn1E2Packer()
 
+//
+//
+//
 func createSubsReq() *e2ap.E2APSubscriptionRequest {
        req := &e2ap.E2APSubscriptionRequest{}
 
        req.RequestId.Id = 1
-       req.RequestId.Seq = 22
+       req.RequestId.Seq = 0
        req.FunctionId = 1
 
        req.EventTriggerDefinition.InterfaceId.GlobalEnbId.Present = true
@@ -66,6 +69,9 @@ func createSubsReq() *e2ap.E2APSubscriptionRequest {
        return req
 }
 
+//
+//
+//
 func createSubsResp(req *e2ap.E2APSubscriptionRequest) *e2ap.E2APSubscriptionResponse {
 
        resp := &e2ap.E2APSubscriptionResponse{}
@@ -90,9 +96,32 @@ func createSubsResp(req *e2ap.E2APSubscriptionRequest) *e2ap.E2APSubscriptionRes
        return resp
 }
 
+//
+//
+//
+func createSubsDelReq(e2SubsId uint32) *e2ap.E2APSubscriptionDeleteRequest {
+       req := &e2ap.E2APSubscriptionDeleteRequest{}
+       req.RequestId.Id = 1
+       req.RequestId.Seq = e2SubsId
+       req.FunctionId = 1
+       return req
+}
+
+//
+//
+//
+func createSubsDelResp(req *e2ap.E2APSubscriptionDeleteRequest) *e2ap.E2APSubscriptionDeleteResponse {
+       resp := &e2ap.E2APSubscriptionDeleteResponse{}
+       resp.RequestId.Id = req.RequestId.Id
+       resp.RequestId.Seq = req.RequestId.Seq
+       resp.FunctionId = req.FunctionId
+       return resp
+}
+
 //-----------------------------------------------------------------------------
 // TestSubRequestSubResponseOk
 //
+//   stub                          stub
 // +-------+     +---------+    +---------+
 // | xapp  |     | submgr  |    | e2term  |
 // +-------+     +---------+    +---------+
@@ -109,27 +138,41 @@ func createSubsResp(req *e2ap.E2APSubscriptionRequest) *e2ap.E2APSubscriptionRes
 //     |      SubResp |              |
 //     |<-------------|              |
 //     |              |              |
+//     |              |              |
+//     | SubDelReq    |              |
+//     |------------->|              |
+//     |              |              |
+//     |              | SubDelReq    |
+//     |              |------------->|
+//     |              |              |
+//     |              |   SubDelResp |
+//     |              |<-------------|
+//     |              |              |
+//     |   SubDelResp |              |
+//     |<-------------|              |
 //
 //-----------------------------------------------------------------------------
-func TestSubRequestSubResponseOk(t *testing.T) {
+func TestSubReqAndSubDelOk(t *testing.T) {
 
-       xapp.Logger.Info("TestSimple start")
+       xapp.Logger.Info("TestSubReqAndSubDelOk start")
        e2SubsReq := e2asnpacker.NewPackerSubscriptionRequest()
        e2SubsResp := e2asnpacker.NewPackerSubscriptionResponse()
+       e2SubsDelReq := e2asnpacker.NewPackerSubscriptionDeleteRequest()
+       e2SubsDelResp := e2asnpacker.NewPackerSubscriptionDeleteResponse()
+       var e2SubsId int
 
        //---------------------------------
-       // xapp activity
+       // xapp activity: Send Subs Req
        //---------------------------------
        select {
        case <-time.After(5 * time.Second):
+               xapp.Logger.Info("(xappConn) Send Subs Req")
                req := createSubsReq()
                e2SubsReq.Set(req)
                xapp.Logger.Debug("%s", e2SubsReq.String())
                err, packedMsg := e2SubsReq.Pack(nil)
                if err != nil {
                        testError(t, "(xappConn) pack NOK %s", err.Error())
-               } else {
-                       xapp.Logger.Info("(xappConn) pack OK")
                }
 
                params := &xapp.RMRParams{}
@@ -147,14 +190,14 @@ func TestSubRequestSubResponseOk(t *testing.T) {
        }
 
        //---------------------------------
-       // e2term activity
+       // e2term activity: Recv Subs Req & Send Subs Resp
        //---------------------------------
        select {
        case msg := <-e2termConn.rmrConChan:
                if msg.Mtype != xapp.RICMessageTypes["RIC_SUB_REQ"] {
                        testError(t, "(e2termConn) Received non RIC_SUB_REQ message")
                } else {
-
+                       xapp.Logger.Info("(e2termConn) Recv Subs Req & Send Subs Resp")
                        packedData := &packer.PackedData{}
                        packedData.Buf = msg.Payload
                        unpackerr := e2SubsReq.UnPack(packedData)
@@ -172,8 +215,6 @@ func TestSubRequestSubResponseOk(t *testing.T) {
                        packerr, packedMsg := e2SubsResp.Pack(nil)
                        if packerr != nil {
                                testError(t, "(e2termConn) pack NOK %s", packerr.Error())
-                       } else {
-                               xapp.Logger.Info("(e2termConn) pack OK")
                        }
 
                        params := &xapp.RMRParams{}
@@ -195,17 +236,20 @@ func TestSubRequestSubResponseOk(t *testing.T) {
        }
 
        //---------------------------------
-       // xapp activity
+       // xapp activity: Recv Subs Resp
        //---------------------------------
        select {
        case msg := <-xappConn.rmrConChan:
                if msg.Mtype != xapp.RICMessageTypes["RIC_SUB_RESP"] {
                        testError(t, "(xappConn) Received non RIC_SUB_RESP message")
                } else {
+                       xapp.Logger.Info("(xappConn) Recv Subs Resp")
 
                        packedData := &packer.PackedData{}
                        packedData.Buf = msg.Payload
+                       e2SubsId = msg.SubId
                        unpackerr := e2SubsResp.UnPack(packedData)
+
                        if unpackerr != nil {
                                testError(t, "(xappConn) RIC_SUB_RESP unpack failed err: %s", unpackerr.Error())
                        }
@@ -219,4 +263,105 @@ func TestSubRequestSubResponseOk(t *testing.T) {
                testError(t, "(xappConn) Not Received RIC_SUB_RESP within 15 secs")
        }
 
+       //---------------------------------
+       // xapp activity: Send Subs Del Req
+       //---------------------------------
+       select {
+       case <-time.After(2 * time.Second):
+               xapp.Logger.Info("(xappConn) Send Subs Del Req")
+               req := createSubsDelReq(uint32(e2SubsId))
+               e2SubsDelReq.Set(req)
+               xapp.Logger.Debug("%s", e2SubsDelReq.String())
+               err, packedMsg := e2SubsDelReq.Pack(nil)
+               if err != nil {
+                       testError(t, "(xappConn) pack NOK %s", err.Error())
+               }
+
+               params := &xapp.RMRParams{}
+               params.Mtype = xapp.RIC_SUB_DEL_REQ
+               params.SubId = e2SubsId
+               params.Payload = packedMsg.Buf
+               params.Meid = &xapp.RMRMeid{RanName: "RAN_NAME_1"}
+               params.Xid = "XID_1"
+               params.Mbuf = nil
+
+               snderr := xappConn.RmrSend(params)
+               if snderr != nil {
+                       testError(t, "(xappConn) RMR SEND FAILED: %s", snderr.Error())
+               }
+       }
+
+       //---------------------------------
+       // e2term activity: Recv Subs Del Req & Send Subs Del Resp
+       //---------------------------------
+       select {
+       case msg := <-e2termConn.rmrConChan:
+               if msg.Mtype != xapp.RICMessageTypes["RIC_SUB_DEL_REQ"] {
+                       testError(t, "(e2termConn) Received non RIC_SUB_DEL_REQ message")
+               } else {
+                       xapp.Logger.Info("(e2termConn) Recv Subs Del Req & Send Subs Del Resp")
+
+                       packedData := &packer.PackedData{}
+                       packedData.Buf = msg.Payload
+                       unpackerr := e2SubsDelReq.UnPack(packedData)
+                       if unpackerr != nil {
+                               testError(t, "(e2termConn) RIC_SUB_DEL_REQ unpack failed err: %s", unpackerr.Error())
+                       }
+                       geterr, req := e2SubsDelReq.Get()
+                       if geterr != nil {
+                               testError(t, "(e2termConn) RIC_SUB_DEL_REQ get failed err: %s", geterr.Error())
+                       }
+
+                       resp := createSubsDelResp(req)
+                       e2SubsDelResp.Set(resp)
+                       xapp.Logger.Debug("%s", e2SubsDelResp.String())
+                       packerr, packedMsg := e2SubsDelResp.Pack(nil)
+                       if packerr != nil {
+                               testError(t, "(e2termConn) pack NOK %s", packerr.Error())
+                       }
+
+                       params := &xapp.RMRParams{}
+                       params.Mtype = xapp.RIC_SUB_DEL_RESP
+                       params.SubId = msg.SubId
+                       params.Payload = packedMsg.Buf
+                       params.Meid = msg.Meid
+                       params.Xid = msg.Xid
+                       params.Mbuf = nil
+
+                       snderr := e2termConn.RmrSend(params)
+                       if snderr != nil {
+                               testError(t, "(e2termConn) RMR SEND FAILED: %s", snderr.Error())
+                       }
+
+               }
+       case <-time.After(15 * time.Second):
+               testError(t, "(e2termConn) Not Received RIC_SUB_DEL_REQ within 15 secs")
+       }
+
+       //---------------------------------
+       // xapp activity: Recv Subs Del Resp
+       //---------------------------------
+       select {
+       case msg := <-xappConn.rmrConChan:
+               if msg.Mtype != xapp.RICMessageTypes["RIC_SUB_DEL_RESP"] {
+                       testError(t, "(xappConn) Received non RIC_SUB_DEL_RESP message")
+               } else {
+                       xapp.Logger.Info("(xappConn) Recv Subs Del Resp")
+
+                       packedData := &packer.PackedData{}
+                       packedData.Buf = msg.Payload
+                       unpackerr := e2SubsDelResp.UnPack(packedData)
+                       if unpackerr != nil {
+                               testError(t, "(xappConn) RIC_SUB_DEL_RESP unpack failed err: %s", unpackerr.Error())
+                       }
+                       geterr, _ := e2SubsDelResp.Get()
+                       if geterr != nil {
+                               testError(t, "(xappConn) RIC_SUB_DEL_RESP get failed err: %s", geterr.Error())
+                       }
+
+               }
+       case <-time.After(15 * time.Second):
+               testError(t, "(xappConn) Not Received RIC_SUB_DEL_RESP within 15 secs")
+       }
+
 }