X-Git-Url: https://gerrit.o-ran-sc.org/r/gitweb?a=blobdiff_plain;f=pkg%2Fcontrol%2Fmessaging_test.go;h=2f7bc4a580614d2f591d0e861e45433dae716412;hb=8527f3b2ba74bd7bccb8d67acc952e23f5664e6c;hp=acd15448d66f6218f98382a4d76e136123f52c21;hpb=0d064ecdb5239a875857b5910f7f6e83f827d7a6;p=ric-plt%2Fsubmgr.git diff --git a/pkg/control/messaging_test.go b/pkg/control/messaging_test.go index acd1544..2f7bc4a 100644 --- a/pkg/control/messaging_test.go +++ b/pkg/control/messaging_test.go @@ -37,7 +37,7 @@ var e2asnpacker e2ap.E2APPackerIf = e2ap_wrapper.NewAsn1E2Packer() // //----------------------------------------------------------------------------- func (xappConn *testingXappControl) handle_xapp_subs_req(t *testing.T, oldTrans *xappTransaction) *xappTransaction { - xapp.Logger.Info("handle_xapp_subs_req") + xapp.Logger.Info("(%s) handle_xapp_subs_req", xappConn.desc) e2SubsReq := e2asnpacker.NewPackerSubscriptionRequest() //--------------------------------- @@ -86,7 +86,7 @@ func (xappConn *testingXappControl) handle_xapp_subs_req(t *testing.T, oldTrans trans = xappConn.newXappTransaction(nil, "RAN_NAME_1") } - params := &xapp.RMRParams{} + params := &RMRParams{&xapp.RMRParams{}} params.Mtype = xapp.RIC_SUB_REQ params.SubId = -1 params.Payload = packedMsg.Buf @@ -106,7 +106,7 @@ func (xappConn *testingXappControl) handle_xapp_subs_req(t *testing.T, oldTrans // //----------------------------------------------------------------------------- func (xappConn *testingXappControl) handle_xapp_subs_resp(t *testing.T, trans *xappTransaction) int { - xapp.Logger.Info("handle_xapp_subs_resp") + xapp.Logger.Info("(%s) handle_xapp_subs_resp", xappConn.desc) e2SubsResp := e2asnpacker.NewPackerSubscriptionResponse() var e2SubsId int @@ -145,11 +145,54 @@ func (xappConn *testingXappControl) handle_xapp_subs_resp(t *testing.T, trans *x return -1 } +//----------------------------------------------------------------------------- +// +//----------------------------------------------------------------------------- +func (xappConn *testingXappControl) handle_xapp_subs_fail(t *testing.T, trans *xappTransaction) int { + xapp.Logger.Info("(%s) handle_xapp_subs_fail", xappConn.desc) + e2SubsFail := e2asnpacker.NewPackerSubscriptionFailure() + var e2SubsId int + + //------------------------------- + // xapp activity: Recv Subs Fail + //------------------------------- + select { + case msg := <-xappConn.rmrConChan: + if msg.Mtype != xapp.RICMessageTypes["RIC_SUB_FAILURE"] { + testError(t, "(%s) Received RIC_SUB_FAILURE wrong mtype expected %s got %s, error", xappConn.desc, "RIC_SUB_FAILURE", xapp.RicMessageTypeToName[msg.Mtype]) + return -1 + } else if msg.Xid != trans.xid { + testError(t, "(%s) Received RIC_SUB_FAILURE wrong xid expected %s got %s, error", xappConn.desc, trans.xid, msg.Xid) + return -1 + } else { + packedData := &packer.PackedData{} + packedData.Buf = msg.Payload + e2SubsId = msg.SubId + unpackerr := e2SubsFail.UnPack(packedData) + + if unpackerr != nil { + testError(t, "(%s) RIC_SUB_FAILURE unpack failed err: %s", xappConn.desc, unpackerr.Error()) + } + geterr, resp := e2SubsFail.Get() + if geterr != nil { + testError(t, "(%s) RIC_SUB_FAILURE get failed err: %s", xappConn.desc, geterr.Error()) + } + + xapp.Logger.Info("(%s) Recv Subs Fail rmr: xid=%s subid=%d, asn: seqnro=%d", xappConn.desc, msg.Xid, msg.SubId, resp.RequestId.Seq) + return e2SubsId + } + case <-time.After(15 * time.Second): + testError(t, "(%s) Not Received RIC_SUB_FAILURE within 15 secs", xappConn.desc) + return -1 + } + return -1 +} + //----------------------------------------------------------------------------- // //----------------------------------------------------------------------------- func (xappConn *testingXappControl) handle_xapp_subs_del_req(t *testing.T, oldTrans *xappTransaction, e2SubsId int) *xappTransaction { - xapp.Logger.Info("handle_xapp_subs_del_req") + xapp.Logger.Info("(%s) handle_xapp_subs_del_req", xappConn.desc) e2SubsDelReq := e2asnpacker.NewPackerSubscriptionDeleteRequest() //--------------------------------- @@ -175,7 +218,7 @@ func (xappConn *testingXappControl) handle_xapp_subs_del_req(t *testing.T, oldTr trans = xappConn.newXappTransaction(nil, "RAN_NAME_1") } - params := &xapp.RMRParams{} + params := &RMRParams{&xapp.RMRParams{}} params.Mtype = xapp.RIC_SUB_DEL_REQ params.SubId = e2SubsId params.Payload = packedMsg.Buf @@ -195,7 +238,7 @@ func (xappConn *testingXappControl) handle_xapp_subs_del_req(t *testing.T, oldTr // //----------------------------------------------------------------------------- func (xappConn *testingXappControl) handle_xapp_subs_del_resp(t *testing.T, trans *xappTransaction) { - xapp.Logger.Info("handle_xapp_subs_del_resp") + xapp.Logger.Info("(%s) handle_xapp_subs_del_resp", xappConn.desc) e2SubsDelResp := e2asnpacker.NewPackerSubscriptionDeleteResponse() //--------------------------------- @@ -231,8 +274,8 @@ func (xappConn *testingXappControl) handle_xapp_subs_del_resp(t *testing.T, tran //----------------------------------------------------------------------------- // //----------------------------------------------------------------------------- -func (e2termConn *testingE2termControl) handle_e2term_subs_req(t *testing.T) (*e2ap.E2APSubscriptionRequest, *xapp.RMRParams) { - xapp.Logger.Info("handle_e2term_subs_req") +func (e2termConn *testingE2termControl) handle_e2term_subs_req(t *testing.T) (*e2ap.E2APSubscriptionRequest, *RMRParams) { + xapp.Logger.Info("(%s) handle_e2term_subs_req", e2termConn.desc) e2SubsReq := e2asnpacker.NewPackerSubscriptionRequest() //--------------------------------- @@ -262,8 +305,8 @@ func (e2termConn *testingE2termControl) handle_e2term_subs_req(t *testing.T) (*e return nil, nil } -func (e2termConn *testingE2termControl) handle_e2term_subs_resp(t *testing.T, req *e2ap.E2APSubscriptionRequest, msg *xapp.RMRParams) { - xapp.Logger.Info("handle_e2term_subs_resp") +func (e2termConn *testingE2termControl) handle_e2term_subs_resp(t *testing.T, req *e2ap.E2APSubscriptionRequest, msg *RMRParams) { + xapp.Logger.Info("(%s) handle_e2term_subs_resp", e2termConn.desc) e2SubsResp := e2asnpacker.NewPackerSubscriptionResponse() //--------------------------------- @@ -297,7 +340,7 @@ func (e2termConn *testingE2termControl) handle_e2term_subs_resp(t *testing.T, re testError(t, "(%s) pack NOK %s", e2termConn.desc, packerr.Error()) } - params := &xapp.RMRParams{} + params := &RMRParams{&xapp.RMRParams{}} params.Mtype = xapp.RIC_SUB_RESP params.SubId = msg.SubId params.Payload = packedMsg.Buf @@ -314,8 +357,53 @@ func (e2termConn *testingE2termControl) handle_e2term_subs_resp(t *testing.T, re //----------------------------------------------------------------------------- // //----------------------------------------------------------------------------- -func (e2termConn *testingE2termControl) handle_e2term_subs_del_req(t *testing.T) (*e2ap.E2APSubscriptionDeleteRequest, *xapp.RMRParams) { - xapp.Logger.Info("handle_e2term_subs_del_req") +func (e2termConn *testingE2termControl) handle_e2term_subs_fail(t *testing.T, req *e2ap.E2APSubscriptionRequest, msg *RMRParams) { + xapp.Logger.Info("(%s) handle_e2term_subs_fail", e2termConn.desc) + e2SubsFail := e2asnpacker.NewPackerSubscriptionFailure() + + //--------------------------------- + // e2term activity: Send Subs Fail + //--------------------------------- + xapp.Logger.Info("(%s) Send Subs Fail", e2termConn.desc) + + resp := &e2ap.E2APSubscriptionFailure{} + resp.RequestId.Id = req.RequestId.Id + resp.RequestId.Seq = req.RequestId.Seq + resp.FunctionId = req.FunctionId + + resp.ActionNotAdmittedList.Items = make([]e2ap.ActionNotAdmittedItem, len(resp.ActionNotAdmittedList.Items)) + for index := int(0); index < len(resp.ActionNotAdmittedList.Items); index++ { + resp.ActionNotAdmittedList.Items[index].ActionId = req.ActionSetups[index].ActionId + resp.ActionNotAdmittedList.Items[index].Cause.Content = 3 // CauseMisc + resp.ActionNotAdmittedList.Items[index].Cause.CauseVal = 4 // unspecified + } + + e2SubsFail.Set(resp) + xapp.Logger.Debug("%s", e2SubsFail.String()) + packerr, packedMsg := e2SubsFail.Pack(nil) + if packerr != nil { + testError(t, "(%s) pack NOK %s", e2termConn.desc, packerr.Error()) + } + + params := &RMRParams{&xapp.RMRParams{}} + params.Mtype = xapp.RIC_SUB_FAILURE + 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, "(%s) RMR SEND FAILED: %s", e2termConn.desc, snderr.Error()) + } +} + +//----------------------------------------------------------------------------- +// +//----------------------------------------------------------------------------- +func (e2termConn *testingE2termControl) handle_e2term_subs_del_req(t *testing.T) (*e2ap.E2APSubscriptionDeleteRequest, *RMRParams) { + xapp.Logger.Info("(%s) handle_e2term_subs_del_req", e2termConn.desc) e2SubsDelReq := e2asnpacker.NewPackerSubscriptionDeleteRequest() //--------------------------------- @@ -353,8 +441,8 @@ func handle_e2term_recv_empty() bool { return true } -func (e2termConn *testingE2termControl) handle_e2term_subs_del_resp(t *testing.T, req *e2ap.E2APSubscriptionDeleteRequest, msg *xapp.RMRParams) { - xapp.Logger.Info("handle_e2term_subs_del_resp") +func (e2termConn *testingE2termControl) handle_e2term_subs_del_resp(t *testing.T, req *e2ap.E2APSubscriptionDeleteRequest, msg *RMRParams) { + xapp.Logger.Info("(%s) handle_e2term_subs_del_resp", e2termConn.desc) e2SubsDelResp := e2asnpacker.NewPackerSubscriptionDeleteResponse() //--------------------------------- @@ -374,7 +462,7 @@ func (e2termConn *testingE2termControl) handle_e2term_subs_del_resp(t *testing.T testError(t, "(%s) pack NOK %s", e2termConn.desc, packerr.Error()) } - params := &xapp.RMRParams{} + params := &RMRParams{&xapp.RMRParams{}} params.Mtype = xapp.RIC_SUB_DEL_RESP params.SubId = msg.SubId params.Payload = packedMsg.Buf @@ -386,7 +474,46 @@ func (e2termConn *testingE2termControl) handle_e2term_subs_del_resp(t *testing.T if snderr != nil { testError(t, "(%s) RMR SEND FAILED: %s", e2termConn.desc, snderr.Error()) } +} + +//----------------------------------------------------------------------------- +// +//----------------------------------------------------------------------------- +func (e2termConn *testingE2termControl) handle_e2term_subs_del_fail(t *testing.T, req *e2ap.E2APSubscriptionDeleteRequest, msg *RMRParams) { + xapp.Logger.Info("(%s) handle_e2term_del_subs_fail", e2termConn.desc) + e2SubsDelFail := e2asnpacker.NewPackerSubscriptionDeleteFailure() + + //--------------------------------- + // e2term activity: Send Subs Del Fail + //--------------------------------- + xapp.Logger.Info("(%s) Send Subs Del Fail", e2termConn.desc) + + resp := &e2ap.E2APSubscriptionDeleteFailure{} + resp.RequestId.Id = req.RequestId.Id + resp.RequestId.Seq = req.RequestId.Seq + resp.FunctionId = req.FunctionId + resp.Cause.Content = 3 // CauseMisc + resp.Cause.CauseVal = 4 // unspecified + + e2SubsDelFail.Set(resp) + xapp.Logger.Debug("%s", e2SubsDelFail.String()) + packerr, packedMsg := e2SubsDelFail.Pack(nil) + if packerr != nil { + testError(t, "(%s) pack NOK %s", e2termConn.desc, packerr.Error()) + } + + params := &RMRParams{&xapp.RMRParams{}} + params.Mtype = xapp.RIC_SUB_DEL_FAILURE + 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, "(%s) RMR SEND FAILED: %s", e2termConn.desc, snderr.Error()) + } } //----------------------------------------------------------------------------- @@ -421,24 +548,24 @@ func (mc *testingMainControl) wait_subs_trans_clean(t *testing.T, e2SubsId int, return false } -func (mc *testingMainControl) get_seqcnt(t *testing.T) uint16 { +func (mc *testingMainControl) get_subid(t *testing.T) uint16 { mc.c.registry.mutex.Lock() defer mc.c.registry.mutex.Unlock() - return mc.c.registry.counter + return mc.c.registry.subIds[0] } -func (mc *testingMainControl) wait_seqcnt_change(t *testing.T, orig uint16, secs int) (uint16, bool) { +func (mc *testingMainControl) wait_subid_change(t *testing.T, origSubId uint16, secs int) (uint16, bool) { i := 1 for ; i <= secs*2; i++ { mc.c.registry.mutex.Lock() - curr := mc.c.registry.counter + currSubId := mc.c.registry.subIds[0] mc.c.registry.mutex.Unlock() - if curr != orig { - return curr, true + if currSubId != origSubId { + return currSubId, true } time.Sleep(500 * time.Millisecond) } - testError(t, "(general) no seq change within %d secs", secs) + testError(t, "(general) no subId change within %d secs", secs) return 0, false } @@ -495,8 +622,11 @@ func (mc *testingMainControl) wait_msgcounter_change(t *testing.T, orig uint64, //----------------------------------------------------------------------------- func TestSubReqAndSubDelOk(t *testing.T) { xapp.Logger.Info("TestSubReqAndSubDelOk") + rtmgrHttp.UseChannel(true) cretrans := xappConn1.handle_xapp_subs_req(t, nil) + msg := rtmgrHttp.WaitReq(t) + msg.RetOk() crereq, cremsg := e2termConn.handle_e2term_subs_req(t) e2termConn.handle_e2term_subs_resp(t, crereq, cremsg) e2SubsId := xappConn1.handle_xapp_subs_resp(t, cretrans) @@ -506,8 +636,12 @@ func TestSubReqAndSubDelOk(t *testing.T) { e2termConn.handle_e2term_subs_del_resp(t, delreq, delmsg) xappConn1.handle_xapp_subs_del_resp(t, deltrans) + msg = rtmgrHttp.WaitReq(t) + msg.RetOk() + //Wait that subs is cleaned mainCtrl.wait_subs_clean(t, e2SubsId, 10) + rtmgrHttp.UseChannel(false) } //----------------------------------------------------------------------------- @@ -920,7 +1054,7 @@ func TestSubReqRetryNoRespSubDelRespInSubmgr(t *testing.T) { // E2t: Receive 2nd SubsReq e2termConn.handle_e2term_subs_req(t) - // E2t: Send receive SubsReq and send SubsResp + // E2t: Send receive SubsDelReq and send SubsResp delreq, delmsg := e2termConn.handle_e2term_subs_del_req(t) e2termConn.handle_e2term_subs_del_resp(t, delreq, delmsg) @@ -980,6 +1114,47 @@ func TestSubReqTwoRetriesNoRespAtAllInSubmgr(t *testing.T) { mainCtrl.wait_subs_clean(t, int(delreq.RequestId.Seq), 10) } +//----------------------------------------------------------------------------- +// TestSubReqSubFailRespInSubmgr +// +// stub stub +// +-------+ +---------+ +---------+ +// | xapp | | submgr | | e2term | +// +-------+ +---------+ +---------+ +// | | | +// | SubReq | | +// |------------->| | +// | | | +// | | SubReq | +// | |------------->| +// | | | +// | | SubFail | +// | |<-------------| +// | | | +// | SubFail | | +// |<-------------| | +// | | | +// +//----------------------------------------------------------------------------- + +func TestSubReqSubFailRespInSubmgr(t *testing.T) { + + xapp.Logger.Info("TestSubReqSubFailRespInSubmgr start") + + // Xapp: Send SubsReq + cretrans := xappConn1.handle_xapp_subs_req(t, nil) + + // E2t: Receive SubsReq and send SubsFail + crereq, cremsg := e2termConn.handle_e2term_subs_req(t) + e2termConn.handle_e2term_subs_fail(t, crereq, cremsg) + + // Xapp: Receive SubsFail + e2SubsId := xappConn1.handle_xapp_subs_fail(t, cretrans) + + // Wait that subs is cleaned + mainCtrl.wait_subs_clean(t, e2SubsId, 10) +} + //----------------------------------------------------------------------------- // TestSubDelReqRetryInSubmgr // @@ -1029,7 +1204,7 @@ func TestSubDelReqRetryInSubmgr(t *testing.T) { delreq, delmsg := e2termConn.handle_e2term_subs_del_req(t) e2termConn.handle_e2term_subs_del_resp(t, delreq, delmsg) - // Xapp: Receive SubsDelReq + // Xapp: Receive SubsDelResp xappConn1.handle_xapp_subs_del_resp(t, deltrans) // Wait that subs is cleaned @@ -1082,7 +1257,57 @@ func TestSubDelReqTwoRetriesNoRespInSubmgr(t *testing.T) { // E2t: Receive 2nd SubsDelReq e2termConn.handle_e2term_subs_del_req(t) - // Xapp: Receive SubsDelReq + // Xapp: Receive SubsDelResp + xappConn1.handle_xapp_subs_del_resp(t, deltrans) + + // Wait that subs is cleaned + mainCtrl.wait_subs_clean(t, e2SubsId, 10) +} + +//----------------------------------------------------------------------------- +// TestSubDelReqSubDelFailRespInSubmgr +// +// stub stub +// +-------+ +---------+ +---------+ +// | xapp | | submgr | | e2term | +// +-------+ +---------+ +---------+ +// | | | +// | [SUBS CREATE] | +// | | | +// | | | +// | SubDelReq | | +// |------------->| | +// | | | +// | | SubDelReq | +// | |------------->| +// | | | +// | | SubDelFail | +// | |<-------------| +// | | | +// | SubDelResp | | +// |<-------------| | +// | | | +// +//----------------------------------------------------------------------------- + +func TestSubDelReqSubDelFailRespInSubmgr(t *testing.T) { + + xapp.Logger.Info("TestSubReqSubDelFailRespInSubmgr start") + + // Subs Create + cretrans := xappConn1.handle_xapp_subs_req(t, nil) + crereq, cremsg := e2termConn.handle_e2term_subs_req(t) + e2termConn.handle_e2term_subs_resp(t, crereq, cremsg) + e2SubsId := xappConn1.handle_xapp_subs_resp(t, cretrans) + + // Xapp: Send SubsDelReq + deltrans := xappConn1.handle_xapp_subs_del_req(t, nil, e2SubsId) + + // E2t: Send receive SubsDelReq and send SubsDelFail + delreq, delmsg := e2termConn.handle_e2term_subs_del_req(t) + e2termConn.handle_e2term_subs_del_fail(t, delreq, delmsg) + + // Xapp: Receive SubsDelResp xappConn1.handle_xapp_subs_del_resp(t, deltrans) // Wait that subs is cleaned