From 6d629ad71687993ee08b6193e957439f5c87aa22 Mon Sep 17 00:00:00 2001 From: Anssi Mannila Date: Mon, 25 Jan 2021 09:59:56 +0200 Subject: [PATCH] Code rework Change-Id: I18c300a388a18803646ae83a7630077dc629dc18 Signed-off-by: Anssi Mannila --- pkg/control/control.go | 57 +++++--------- pkg/control/sdl.go | 15 ++-- pkg/control/ut_messaging_test.go | 158 --------------------------------------- 3 files changed, 24 insertions(+), 206 deletions(-) diff --git a/pkg/control/control.go b/pkg/control/control.go index 7d180ad..933df7f 100755 --- a/pkg/control/control.go +++ b/pkg/control/control.go @@ -469,44 +469,25 @@ func (c *Control) handleSubscriptionCreate(subs *Subscription, parentTrans *Tran subRfMsg, valid := subs.GetCachedResponse() if subRfMsg == nil && valid == true { - - // - // In case of failure - // - make internal delete - // - in case duplicate cause, retry (currently max 1 retry) - // - maxRetries := uint64(1) - doRetry := true - for retries := uint64(0); retries <= maxRetries && doRetry; retries++ { - doRetry = false - - event := c.sendE2TSubscriptionRequest(subs, trans, parentTrans) - switch themsg := event.(type) { - case *e2ap.E2APSubscriptionResponse: - subRfMsg, valid = subs.SetCachedResponse(event, true) - subs.SubRespRcvd = true - case *e2ap.E2APSubscriptionFailure: - removeSubscriptionFromDb = true - subRfMsg, valid = subs.SetCachedResponse(event, false) - doRetry = true - for _, item := range themsg.ActionNotAdmittedList.Items { - if item.Cause.Content != e2ap.E2AP_CauseContent_Ric || (item.Cause.Value != e2ap.E2AP_CauseValue_Ric_duplicate_action && item.Cause.Value != e2ap.E2AP_CauseValue_Ric_duplicate_event) { - doRetry = false - break - } - } - xapp.Logger.Info("SUBS-SubReq: internal delete and possible retry due event(%s) retry(%t,%d/%d) %s", typeofSubsMessage(event), doRetry, retries, maxRetries, idstring(nil, trans, subs, parentTrans)) - c.sendE2TSubscriptionDeleteRequest(subs, trans, parentTrans) - case *SubmgrRestartTestEvent: - // This simulates that no response has been received and after restart subscriptions are restored from db - xapp.Logger.Debug("Test restart flag is active. Dropping this transaction to test restart case") - return - default: - xapp.Logger.Info("SUBS-SubReq: internal delete due event(%s) %s", typeofSubsMessage(event), idstring(nil, trans, subs, parentTrans)) - removeSubscriptionFromDb = true - subRfMsg, valid = subs.SetCachedResponse(nil, false) - c.sendE2TSubscriptionDeleteRequest(subs, trans, parentTrans) - } + event := c.sendE2TSubscriptionRequest(subs, trans, parentTrans) + switch event.(type) { + case *e2ap.E2APSubscriptionResponse: + subRfMsg, valid = subs.SetCachedResponse(event, true) + subs.SubRespRcvd = true + case *e2ap.E2APSubscriptionFailure: + removeSubscriptionFromDb = true + subRfMsg, valid = subs.SetCachedResponse(event, false) + xapp.Logger.Info("SUBS-SubReq: internal delete due event(%s) %s", typeofSubsMessage(event), idstring(nil, trans, subs, parentTrans)) + c.sendE2TSubscriptionDeleteRequest(subs, trans, parentTrans) + case *SubmgrRestartTestEvent: + // This simulates that no response has been received and after restart subscriptions are restored from db + xapp.Logger.Debug("Test restart flag is active. Dropping this transaction to test restart case") + return + default: + xapp.Logger.Info("SUBS-SubReq: internal delete due event(%s) %s", typeofSubsMessage(event), idstring(nil, trans, subs, parentTrans)) + removeSubscriptionFromDb = true + subRfMsg, valid = subs.SetCachedResponse(nil, false) + c.sendE2TSubscriptionDeleteRequest(subs, trans, parentTrans) } xapp.Logger.Debug("SUBS-SubReq: Handling (e2t response %s) %s", typeofSubsMessage(subRfMsg), idstring(nil, trans, subs, parentTrans)) } else { diff --git a/pkg/control/sdl.go b/pkg/control/sdl.go index 3a083fb..ecf6a85 100644 --- a/pkg/control/sdl.go +++ b/pkg/control/sdl.go @@ -67,8 +67,7 @@ func (c *Control) WriteSubscriptionToSdl(subId uint32, subs *Subscription) error return fmt.Errorf("SDL: WriteSubscriptionToSdl() json.Marshal error: %s", err.Error()) } - err = c.db.Set(strconv.FormatUint(uint64(subId), 10), jsonData) - if err != nil { + if err = c.db.Set(strconv.FormatUint(uint64(subId), 10), jsonData); err != nil { return fmt.Errorf("SDL: WriteSubscriptionToSdl(): %s", err.Error()) } else { xapp.Logger.Debug("SDL: Subscription written in db. subId = %v", subId) @@ -97,8 +96,7 @@ func (c *Control) ReadSubscriptionFromSdl(subId uint32) (*Subscription, error) { subscriptionInfo := &SubscriptionInfo{} jsonSubscriptionInfo := iSubscriptionInfo.(string) - err := json.Unmarshal([]byte(jsonSubscriptionInfo), subscriptionInfo) - if err != nil { + if err := json.Unmarshal([]byte(jsonSubscriptionInfo), subscriptionInfo); err != nil { return nil, fmt.Errorf("SDL: ReadSubscriptionFromSdl() json.unmarshal error: %s\n", err.Error()) } @@ -143,8 +141,7 @@ func (c *Control) CreateSubscription(subscriptionInfo *SubscriptionInfo, jsonSub func (c *Control) RemoveSubscriptionFromSdl(subId uint32) error { key := strconv.FormatUint(uint64(subId), 10) - err := c.db.Remove([]string{key}) - if err != nil { + if err := c.db.Remove([]string{key}); err != nil { return fmt.Errorf("SDL: RemoveSubscriptionfromSdl(): %s\n", err.Error()) } else { xapp.Logger.Debug("SDL: Subscription removed from db. subId = %v", subId) @@ -187,8 +184,7 @@ func (c *Control) ReadAllSubscriptionsFromSdl() ([]uint32, map[uint32]*Subscript subscriptionInfo := &SubscriptionInfo{} jsonSubscriptionInfo := iSubscriptionInfo.(string) - err := json.Unmarshal([]byte(jsonSubscriptionInfo), subscriptionInfo) - if err != nil { + if err := json.Unmarshal([]byte(jsonSubscriptionInfo), subscriptionInfo); err != nil { return nil, nil, fmt.Errorf("SDL: ReadAllSubscriptionsFromSdl() json.unmarshal error: %s\n", err.Error()) } @@ -219,8 +215,7 @@ func removeNumber(s []uint32, removedNum uint32) ([]uint32, error) { } func (c *Control) RemoveAllSubscriptionsFromSdl() error { - err := c.db.RemoveAll() - if err != nil { + if err := c.db.RemoveAll(); err != nil { return fmt.Errorf("SDL: RemoveAllSubscriptionsFromSdl(): %s\n", err.Error()) } else { xapp.Logger.Debug("SDL: All subscriptions removed from db") diff --git a/pkg/control/ut_messaging_test.go b/pkg/control/ut_messaging_test.go index f559f91..5b51126 100644 --- a/pkg/control/ut_messaging_test.go +++ b/pkg/control/ut_messaging_test.go @@ -731,164 +731,6 @@ func TestSubReqSubFailRespInSubmgr(t *testing.T) { mainCtrl.wait_registry_empty(t, 10) } -//----------------------------------------------------------------------------- -// TestSubReqSubFailRespInSubmgrWithDuplicate -// -// stub stub -// +-------+ +---------+ +---------+ -// | xapp | | submgr | | e2term | -// +-------+ +---------+ +---------+ -// | | | -// | SubReq | | -// |------------->| | -// | | | -// | | SubReq | -// | |------------->| -// | | | -// | | SubFail | -// | |<-------------| -// | | | -// | | SubDelReq | -// | |------------->| -// | | | -// | | SubDelResp | -// | |<-------------| -// | | | -// | | SubReq | -// | |------------->| -// | | | -// | | SubResp | -// | |<-------------| -// | | | -// | SubResp | | -// |<-------------| | -// | | | -// | [SUBS DELETE] | -// | | | -// -//----------------------------------------------------------------------------- - -func TestSubReqSubFailRespInSubmgrWithDuplicate(t *testing.T) { - - CaseBegin("TestSubReqSubFailRespInSubmgrWithDuplicate start") - - // Xapp: Send SubsReq - cretrans := xappConn1.SendSubsReq(t, nil, nil) - - // E2t: Receive SubsReq and send SubsFail (first) - crereq1, cremsg1 := e2termConn1.RecvSubsReq(t) - fparams1 := &teststube2ap.E2StubSubsFailParams{} - fparams1.Set(crereq1) - fparams1.SetCauseVal(-1, 5, 3) - e2termConn1.SendSubsFail(t, fparams1, cremsg1) - - // E2t: Receive SubsDelReq and send SubsDelResp (internal) - delreq1, delmsg1 := e2termConn1.RecvSubsDelReq(t) - e2termConn1.SendSubsDelResp(t, delreq1, delmsg1) - - // E2t: Receive SubsReq and send SubsResp (second) - crereq2, cremsg2 := e2termConn1.RecvSubsReq(t) - e2termConn1.SendSubsResp(t, crereq2, cremsg2) - - // XAPP: Receive SubsResp - e2SubsId := xappConn1.RecvSubsResp(t, cretrans) - - // Delete - deltrans2 := xappConn1.SendSubsDelReq(t, nil, e2SubsId) - delreq2, delmsg2 := e2termConn1.RecvSubsDelReq(t) - e2termConn1.SendSubsDelResp(t, delreq2, delmsg2) - xappConn1.RecvSubsDelResp(t, deltrans2) - - // 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) -} - -//----------------------------------------------------------------------------- -// TestSubReqSubFailRespInSubmgrWithDuplicateFail -// -// stub stub -// +-------+ +---------+ +---------+ -// | xapp | | submgr | | e2term | -// +-------+ +---------+ +---------+ -// | | | -// | SubReq | | -// |------------->| | -// | | | -// | | SubReq | -// | |------------->| -// | | | -// | | SubFail | -// | |<-------------| -// | | | -// | | SubDelReq | -// | |------------->| -// | | | -// | | SubDelResp | -// | |<-------------| -// | | | -// | | SubReq | -// | |------------->| -// | | | -// | | SubFail | -// | |<-------------| -// | | | -// | | SubDelReq | -// | |------------->| -// | | | -// | | SubDelResp | -// | |<-------------| -// | SubFail | | -// |<-------------| | -// | | | -// -//----------------------------------------------------------------------------- - -func TestSubReqSubFailRespInSubmgrWithDuplicateFail(t *testing.T) { - - CaseBegin("TestSubReqSubFailRespInSubmgrWithDuplicateFail start") - - // Xapp: Send SubsReq - cretrans := xappConn1.SendSubsReq(t, nil, nil) - - // E2t: Receive SubsReq and send SubsFail (first) - crereq1, cremsg1 := e2termConn1.RecvSubsReq(t) - fparams1 := &teststube2ap.E2StubSubsFailParams{} - fparams1.Set(crereq1) - fparams1.SetCauseVal(-1, 5, 3) - e2termConn1.SendSubsFail(t, fparams1, cremsg1) - - // E2t: Receive SubsDelReq and send SubsDelResp (internal first) - delreq1, delmsg1 := e2termConn1.RecvSubsDelReq(t) - e2termConn1.SendSubsDelResp(t, delreq1, delmsg1) - - // E2t: Receive SubsReq and send SubsFail (second) - crereq2, cremsg2 := e2termConn1.RecvSubsReq(t) - fparams2 := &teststube2ap.E2StubSubsFailParams{} - fparams2.Set(crereq2) - fparams2.SetCauseVal(-1, 5, 3) - e2termConn1.SendSubsFail(t, fparams2, cremsg2) - - // E2t: Receive SubsDelReq and send SubsDelResp (internal second) - delreq2, delmsg2 := e2termConn1.RecvSubsDelReq(t) - e2termConn1.SendSubsDelResp(t, delreq2, delmsg2) - - // Xapp: Receive SubsFail - e2SubsId := xappConn1.RecvSubsFail(t, cretrans) - - // 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) -} - //----------------------------------------------------------------------------- // TestSubDelReqRetryInSubmgr // -- 2.16.6