From 55d2a285e4914afce7492c6b4b6feebe5485210b Mon Sep 17 00:00:00 2001 From: Markku Virtanen Date: Fri, 4 Jun 2021 14:46:56 +0300 Subject: [PATCH] Added REST notify error cause Change-Id: I428177806ab0e9539017e2cf7bac0bc5a96ea71a Signed-off-by: Markku Virtanen --- pkg/control/control.go | 27 ++++++++++++++++----------- pkg/control/registry.go | 9 ++++++++- pkg/control/restendpoint.go | 2 +- pkg/control/ut_messaging_test.go | 28 ++++++++++++++-------------- pkg/teststube2ap/stubE2.go | 27 ++++++++++++++++++++++++++- 5 files changed, 65 insertions(+), 28 deletions(-) diff --git a/pkg/control/control.go b/pkg/control/control.go index 580c8fc..70570cd 100755 --- a/pkg/control/control.go +++ b/pkg/control/control.go @@ -300,12 +300,14 @@ func (c *Control) processSubscriptionRequests(restSubscription *RESTSubscription _, xAppRmrEndpoint, err := ConstructEndpointAddresses(*clientEndpoint) if err != nil { - xapp.Logger.Error("%s", err.Error()) + c.registry.DeleteRESTSubscription(restSubId) + xapp.Logger.Error("XAPP-SubReq transaction not created, endpoint createtion failed for RESTSubId=%s, Meid=%s", *restSubId, *meid) return } var xAppEventInstanceID int64 var e2EventInstanceID int64 + var errorCause string for index := 0; index < len(subReqList.E2APSubscriptionRequests); index++ { subReqMsg := subReqList.E2APSubscriptionRequests[index] @@ -323,18 +325,19 @@ func (c *Control) processSubscriptionRequests(restSubscription *RESTSubscription if err != nil { // Send notification to xApp that prosessing of a Subscription Request has failed. e2EventInstanceID = (int64)(0) + errorCause = err.Error() resp := &models.SubscriptionResponse{ SubscriptionID: restSubId, SubscriptionInstances: []*models.SubscriptionInstance{ &models.SubscriptionInstance{E2EventInstanceID: &e2EventInstanceID, - ErrorCause: nil, //TODO: Suitable Error cause. + ErrorCause: &errorCause, XappEventInstanceID: &xAppEventInstanceID}, }, } // Mark REST subscription request processed. restSubscription.SetProcessed() - xapp.Logger.Info("Sending unsuccessful REST notification to endpoint=%v:%v, XappEventInstanceID=%v, E2EventInstanceID=%v, %s", - clientEndpoint.Host, *clientEndpoint.HTTPPort, xAppEventInstanceID, e2EventInstanceID, idstring(nil, trans)) + xapp.Logger.Info("Sending unsuccessful REST notification (cause %s) to endpoint=%v:%v, XappEventInstanceID=%v, E2EventInstanceID=%v, %s", + errorCause, clientEndpoint.Host, *clientEndpoint.HTTPPort, xAppEventInstanceID, e2EventInstanceID, idstring(nil, trans)) xapp.Subscription.Notify(resp, *clientEndpoint) c.UpdateCounter(cRestSubFailNotifToXapp) } else { @@ -375,15 +378,14 @@ func (c *Control) handleSubscriptionRequest(trans *TransactionXapp, subReqMsg *e err := c.tracker.Track(trans) if err != nil { - err = fmt.Errorf("XAPP-SubReq: %s", idstring(err, trans)) - xapp.Logger.Error("%s", err.Error()) + xapp.Logger.Error("XAPP-SubReq Tracking error: %s", idstring(err, trans)) + err = fmt.Errorf("Tracking failure") return nil, err } subs, err := c.registry.AssignToSubscription(trans, subReqMsg, c.ResetTestFlag, c) if err != nil { - err = fmt.Errorf("XAPP-SubReq: %s", idstring(err, trans)) - xapp.Logger.Error("%s", err.Error()) + xapp.Logger.Error("XAPP-SubReq Assign error: %s", idstring(err, trans)) return nil, err } @@ -400,14 +402,17 @@ func (c *Control) handleSubscriptionRequest(trans *TransactionXapp, subReqMsg *e trans.Release() return themsg, nil case *e2ap.E2APSubscriptionFailure: - err = fmt.Errorf("SubscriptionFailure received") + err = fmt.Errorf("E2 SubscriptionFailure received") return nil, err default: + err = fmt.Errorf("unexpected E2 subscription response received") break } + } else { + err = fmt.Errorf("E2 subscription response timeout") } - err = fmt.Errorf("XAPP-SubReq: failed %s", idstring(err, trans, subs)) - xapp.Logger.Error("%s", err.Error()) + + xapp.Logger.Error("XAPP-SubReq E2 subscription failed %s", idstring(err, trans, subs)) c.registry.RemoveFromSubscription(subs, trans, waitRouteCleanup_ms, c) return nil, err } diff --git a/pkg/control/registry.go b/pkg/control/registry.go index 416b415..bd4e15a 100644 --- a/pkg/control/registry.go +++ b/pkg/control/registry.go @@ -216,7 +216,8 @@ func (r *Registry) AssignToSubscription(trans *TransactionXapp, subReqMsg *e2ap. // actionType, err := r.CheckActionTypes(subReqMsg) if err != nil { - xapp.Logger.Debug("CREATE %s", err) + xapp.Logger.Info("CREATE %s", err) + err = fmt.Errorf("E2 content validation failed") return nil, err } @@ -236,6 +237,8 @@ func (r *Registry) AssignToSubscription(trans *TransactionXapp, subReqMsg *e2ap. subs, endPointFound := r.findExistingSubs(trans, subReqMsg) if subs == nil { if subs, err = r.allocateSubs(trans, subReqMsg, resetTestFlag); err != nil { + xapp.Logger.Error("%s", err.Error()) + err = fmt.Errorf("subscription not allocated") return nil, err } newAlloc = true @@ -289,6 +292,8 @@ func (r *Registry) RouteCreate(subs *Subscription, c *Control) error { err := r.rtmgrClient.SubscriptionRequestCreate(subRouteAction) if err != nil { c.UpdateCounter(cRouteCreateFail) + xapp.Logger.Error("%s", err.Error()) + err = fmt.Errorf("RTMGR route create failure") } return err } @@ -298,6 +303,8 @@ func (r *Registry) RouteCreateUpdate(subs *Subscription, c *Control) error { err := r.rtmgrClient.SubscriptionRequestUpdate(subRouteAction) if err != nil { c.UpdateCounter(cRouteCreateUpdateFail) + xapp.Logger.Error("%s", err.Error()) + err = fmt.Errorf("RTMGR route update failure") return err } c.UpdateCounter(cMergedSubscriptions) diff --git a/pkg/control/restendpoint.go b/pkg/control/restendpoint.go index 59c30d0..3b4f8f5 100644 --- a/pkg/control/restendpoint.go +++ b/pkg/control/restendpoint.go @@ -41,7 +41,7 @@ func ConstructEndpointAddresses(clientEndpoint models.SubscriptionParamsClientEn var xAppRMREndPoint string if host == "" || (HTTP_port == 0 && RMR_port == 0) { - err := fmt.Errorf("ClientEndpoint aprovided no PORT numbers") + err := fmt.Errorf("ClientEndpoint provided without PORT numbers") return "INVALID_HTTP_ADDRESS:" + host + (string)(*clientEndpoint.HTTPPort), "INVALID_RMR_ADDRESS:" + host + (string)(*clientEndpoint.RMRPort), err diff --git a/pkg/control/ut_messaging_test.go b/pkg/control/ut_messaging_test.go index 4f93f20..f272848 100644 --- a/pkg/control/ut_messaging_test.go +++ b/pkg/control/ut_messaging_test.go @@ -2418,7 +2418,7 @@ func TestRESTSubReqAndRouteNok(t *testing.T) { // Req params := xappConn1.GetRESTSubsReqReportParams(subReqCount) restSubId := xappConn1.SendRESTSubsReq(t, params) - xappConn1.ExpectRESTNotification(t, restSubId) + xappConn1.ExpectRESTNotificationNok(t, restSubId, "failAll") waiter.WaitResult(t) e2SubsId := xappConn1.WaitRESTNotification(t, restSubId) @@ -2465,7 +2465,7 @@ func TestRESTSubReqAndRouteUpdateNok(t *testing.T) { params.SetMeid("RAN_NAME_1") restSubId2 := xappConn2.SendRESTSubsReq(t, params) xapp.Logger.Info("Send REST subscriber request for second subscriber : %v", restSubId2) - xappConn2.ExpectRESTNotification(t, restSubId2) + xappConn2.ExpectRESTNotificationNok(t, restSubId2, "allFail") waiter.WaitResult(t) // e2SubsId2 := xappConn2.WaitRESTNotification(t, restSubId2) - TOD: missing delete xappConn2.WaitRESTNotification(t, restSubId2) @@ -2941,6 +2941,7 @@ func TestRESTSubReqRetryInSubmgr(t *testing.T) { // | | | // //----------------------------------------------------------------------------- + func TestRESTSubReqRetryNoRespSubDelRespInSubmgr(t *testing.T) { CaseBegin("TestRESTSubReqTwoRetriesNoRespSubDelRespInSubmgr start") @@ -2966,9 +2967,8 @@ func TestRESTSubReqRetryNoRespSubDelRespInSubmgr(t *testing.T) { xapp.Logger.Info("Ignore 2nd REST subscriber request for subscriber : %v", restSubId) delreq, delmsg := e2termConn1.RecvSubsDelReq(t) - xappConn1.ExpectRESTNotification(t, restSubId) + xappConn1.ExpectRESTNotificationNok(t, restSubId, "allFail") e2termConn1.SendSubsDelResp(t, delreq, delmsg) - // e2SubsId := xappConn1.WaitRESTNotification(t, restSubId) - TODO: Should we delete this? xappConn1.WaitRESTNotification(t, restSubId) // Wait that subs is cleaned @@ -3004,7 +3004,7 @@ func TestREST2eTermNotRespondingToSubReq(t *testing.T) { e2termConn1.RecvSubsDelReq(t) xapp.Logger.Info("Ignore 1st INTERNAL delete request for subscriber : %v", restSubId) - xappConn1.ExpectRESTNotification(t, restSubId) + xappConn1.ExpectRESTNotificationNok(t, restSubId, "allFail") e2termConn1.RecvSubsDelReq(t) xapp.Logger.Info("Ignore 2nd INTERNAL delete request for subscriber : %v", restSubId) @@ -3082,7 +3082,7 @@ func TestRESTSubReqTwoRetriesNoRespAtAllInSubmgr(t *testing.T) { e2termConn1.RecvSubsDelReq(t) xapp.Logger.Info("Ignore 1st INTERNAL delete request for subscriber : %v", restSubId) - xappConn1.ExpectRESTNotification(t, restSubId) + xappConn1.ExpectRESTNotificationNok(t, restSubId, "allFail") e2termConn1.RecvSubsDelReq(t) xapp.Logger.Info("Ignore 2nd INTERNAL delete request for subscriber : %v", restSubId) @@ -3149,7 +3149,7 @@ func TestRESTSubReqSubFailRespInSubmgr(t *testing.T) { e2termConn1.SendSubsFail(t, fparams1, cremsg1) delreq1, delmsg1 := e2termConn1.RecvSubsDelReq(t) - xappConn1.ExpectRESTNotification(t, restSubId) + xappConn1.ExpectRESTNotificationNok(t, restSubId, "allFail") e2termConn1.SendSubsDelResp(t, delreq1, delmsg1) e2SubsId := xappConn1.WaitRESTNotification(t, restSubId) xapp.Logger.Info("TEST: REST notification received e2SubsId=%v", e2SubsId) @@ -5167,7 +5167,7 @@ func TestRESTUnpackSubscriptionResponseDecodeFail(t *testing.T) { _, cremsg = e2termConn1.RecvSubsReq(t) - xappConn1.ExpectRESTNotification(t, restSubId) + xappConn1.ExpectRESTNotificationNok(t, restSubId, "allFail") // Subscription already created in E2 Node. fparams := &teststube2ap.E2StubSubsFailParams{} @@ -5240,7 +5240,7 @@ func TestRESTUnpackSubscriptionResponseUnknownInstanceId(t *testing.T) { _, cremsg = e2termConn1.RecvSubsReq(t) - xappConn1.ExpectRESTNotification(t, restSubId) + xappConn1.ExpectRESTNotificationNok(t, restSubId, "allFail") // Subscription already created in E2 Node. fparams := &teststube2ap.E2StubSubsFailParams{} @@ -5318,7 +5318,7 @@ func TestRESTUnpackSubscriptionResponseNoTransaction(t *testing.T) { _, cremsg = e2termConn1.RecvSubsReq(t) - xappConn1.ExpectRESTNotification(t, restSubId) + xappConn1.ExpectRESTNotificationNok(t, restSubId, "allFail") // Subscription already created in E2 Node. fparams := &teststube2ap.E2StubSubsFailParams{} @@ -5394,7 +5394,7 @@ func TestRESTUnpackSubscriptionFailureDecodeFail(t *testing.T) { _, cremsg = e2termConn1.RecvSubsReq(t) - xappConn1.ExpectRESTNotification(t, restSubId) + xappConn1.ExpectRESTNotificationNok(t, restSubId, "allFail") // Subscription already created in E2 Node. fparams := &teststube2ap.E2StubSubsFailParams{} @@ -5468,7 +5468,7 @@ func TestRESTUnpackSubscriptionFailureUnknownInstanceId(t *testing.T) { _, cremsg = e2termConn1.RecvSubsReq(t) - xappConn1.ExpectRESTNotification(t, restSubId) + xappConn1.ExpectRESTNotificationNok(t, restSubId, "allFail") // Subscription already created in E2 Node. fparams.SetCauseVal(0, 1, 3) // CauseRIC / duplicate-action @@ -5541,7 +5541,7 @@ func TestRESTUnpackSubscriptionFailureNoTransaction(t *testing.T) { _, cremsg = e2termConn1.RecvSubsReq(t) - xappConn1.ExpectRESTNotification(t, restSubId) + xappConn1.ExpectRESTNotificationNok(t, restSubId, "allFail") // Subscription already created in E2 Node. fparams.SetCauseVal(0, 1, 3) // CauseRIC / duplicate-action @@ -5984,7 +5984,7 @@ func TestRESTSubReqFailAsn1PackSubReqError(t *testing.T) { // E2t: Receive SubsDelReq delreq, delmsg := e2termConn1.RecvSubsDelReq(t) - xappConn1.ExpectRESTNotification(t, restSubId) + xappConn1.ExpectRESTNotificationNok(t, restSubId, "allFail") // Subscription does not exist in in E2 Node. e2termConn1.SendSubsDelFail(t, delreq, delmsg) diff --git a/pkg/teststube2ap/stubE2.go b/pkg/teststube2ap/stubE2.go index cb15b35..98c98f4 100644 --- a/pkg/teststube2ap/stubE2.go +++ b/pkg/teststube2ap/stubE2.go @@ -48,6 +48,7 @@ type RmrTransactionId struct { type E2RestIds struct { RestSubsId string E2SubsId uint32 + ErrorCause string } func (trans *RmrTransactionId) String() string { @@ -680,7 +681,20 @@ func (tc *E2Stub) SubscriptionRespHandler(resp *clientmodel.SubscriptionResponse //----------------------------------------------------------------------------- // //----------------------------------------------------------------------------- + func (tc *E2Stub) ExpectRESTNotification(t *testing.T, restSubsId string) { + tc.expectNotification(t, restSubsId, "") +} + +func (tc *E2Stub) ExpectRESTNotificationOk(t *testing.T, restSubsId string) { + tc.expectNotification(t, restSubsId, "allOk") +} + +func (tc *E2Stub) ExpectRESTNotificationNok(t *testing.T, restSubsId string, expectError string) { + tc.expectNotification(t, restSubsId, expectError) +} + +func (tc *E2Stub) expectNotification(t *testing.T, restSubsId string, expectError string) { tc.Info("### Started to wait REST notification for %v on port %v f(RMR port %v), %v responses expected", restSubsId, *tc.clientEndpoint.HTTPPort, *tc.clientEndpoint.RMRPort, tc.requestCount) tc.restSubsIdList = []string{restSubsId} @@ -695,6 +709,10 @@ func (tc *E2Stub) ExpectRESTNotification(t *testing.T, restSubsId string) { tc.TestError(t, "### REST notification count unexpectedly ZERO for %s (%v)", restSubsId, tc) } else if e2Ids.RestSubsId != restSubsId { tc.TestError(t, "### Unexpected REST notifications received |%s:%s| (%v)", e2Ids.RestSubsId, restSubsId, tc) + } else if e2Ids.ErrorCause == "" && expectError == "allFail" { + tc.TestError(t, "### Unexpected ok cause received from REST notifications |%s:%s| (%v)", e2Ids.RestSubsId, restSubsId, tc) + } else if e2Ids.ErrorCause != "" && expectError == "allOk" { + tc.TestError(t, "### Unexpected error cause (%s) received from REST notifications |%s:%s| (%v)", e2Ids.ErrorCause, e2Ids.RestSubsId, restSubsId, tc) } else { tc.requestCount-- if tc.requestCount == 0 { @@ -702,6 +720,9 @@ func (tc *E2Stub) ExpectRESTNotification(t *testing.T, restSubsId string) { } else { tc.Info("### Expected REST notifications received for %s, (%v)", e2Ids.RestSubsId, tc) } + if e2Ids.ErrorCause != "" && expectError == "allFail" { + tc.Info("### REST Notification: %s, ErrorCause: %v", e2Ids.RestSubsId, e2Ids.ErrorCause) + } tc.Info("### REST Notification received Notif for %s : %v", e2Ids.RestSubsId, e2Ids.E2SubsId) tc.ListedRESTNotifications <- e2Ids } @@ -758,7 +779,11 @@ func (tc *E2Stub) ListedRestNotifHandler(resp *clientmodel.SubscriptionResponse) tc.restSubsIdList = append(tc.restSubsIdList[:i], tc.restSubsIdList[i+1:]...) //tc.Info("Removed %s from Listed REST notifications, %v entries left", *resp.SubscriptionID, len(tc.restSubsIdList)) - tc.CallBackListedNotifications <- E2RestIds{*resp.SubscriptionID, uint32(*resp.SubscriptionInstances[0].E2EventInstanceID)} + if resp.SubscriptionInstances[0].ErrorCause != nil { + tc.CallBackListedNotifications <- E2RestIds{*resp.SubscriptionID, uint32(*resp.SubscriptionInstances[0].E2EventInstanceID), *resp.SubscriptionInstances[0].ErrorCause} + } else { + tc.CallBackListedNotifications <- E2RestIds{*resp.SubscriptionID, uint32(*resp.SubscriptionInstances[0].E2EventInstanceID), ""} + } if len(tc.restSubsIdList) == 0 { //tc.Info("All listed REST notifications received for endpoint=%s", tc.clientEndpoint) -- 2.16.6