Merge "Support for handling unordered IEs in RIC Subscription Response messgae"
[ric-plt/submgr.git] / pkg / control / control.go
index 3dacc59..1f769e1 100755 (executable)
@@ -72,6 +72,7 @@ var checkE2State string
 var readSubsFromDb string
 var dbRetryForever string
 var dbTryCount int
+var e2IEOrderCheckValue uint8
 
 type Control struct {
        *xapp.RMRClient
@@ -348,6 +349,11 @@ func (c *Control) ReadConfigParameters(f string) {
                xapp.Logger.Debug("WARNING: Using hard coded default value for waitRouteCleanup_ms")
        }
        xapp.Logger.Debug("waitRouteCleanup= %v", waitRouteCleanup_ms)
+
+       viper.SetDefault("controls.checkE2IEOrder", 1)
+       e2IEOrderCheckValue = uint8(viper.GetUint("controls.checkE2IEOrder"))
+       c.e2ap.SetE2IEOrderCheck(e2IEOrderCheckValue)
+       xapp.Logger.Debug("e2IEOrderCheck= %v", e2IEOrderCheckValue)
 }
 
 //-------------------------------------------------------------------
@@ -450,8 +456,12 @@ func (c *Control) RESTSubscriptionHandler(params interface{}) (*models.Subscript
                c.PrintRESTSubscriptionRequest(p)
        }
 
-       if c.e2IfState.IsE2ConnectionUp(p.Meid) == false {
-               xapp.Logger.Error("No E2 connection for ranName %v", *p.Meid)
+       if c.e2IfState.IsE2ConnectionUp(p.Meid) == false || c.e2IfState.IsE2ConnectionUnderReset(p.Meid) == true {
+               if c.e2IfState.IsE2ConnectionUp(p.Meid) == false {
+                       xapp.Logger.Error("No E2 connection for ranName %v", *p.Meid)
+               } else if c.e2IfState.IsE2ConnectionUnderReset(p.Meid) == true {
+                       xapp.Logger.Error("E2 Node for ranName %v UNDER RESET", *p.Meid)
+               }
                c.UpdateCounter(cRestReqRejDueE2Down)
                return nil, common.SubscribeServiceUnavailableCode
        }
@@ -686,7 +696,11 @@ func (c *Control) handleSubscriptionRequest(trans *TransactionXapp, subReqMsg *e
        }
 
        xapp.Logger.Error("XAPP-SubReq E2 subscription failed: %s", idstring(err, trans, subs))
-       c.registry.RemoveFromSubscription(subs, trans, waitRouteCleanup_ms, c)
+       // If policy type subscription fails we cannot remove it only internally. Once subscription has been created
+       // successfully, it must be deleted on both sides.
+       if subs.PolicyUpdate == false {
+               c.registry.RemoveFromSubscription(subs, trans, waitRouteCleanup_ms, c)
+       }
 
        return nil, &errorInfo, err
 }
@@ -1122,7 +1136,13 @@ func (c *Control) handleSubscriptionCreate(subs *Subscription, parentTrans *Tran
                        subRfMsg, valid = subs.SetCachedResponse(event, true)
                        subs.SubRespRcvd = true
                case *e2ap.E2APSubscriptionFailure:
-                       subRfMsg, valid = subs.SetCachedResponse(event, false)
+                       if subs.PolicyUpdate == false {
+                               subRfMsg, valid = subs.SetCachedResponse(event, false)
+                       } else {
+                               // In policy update case where subscription has already been created successfully in Gnb
+                               // we cannot delete subscription internally in submgr
+                               subRfMsg, valid = subs.SetCachedResponse(event, true)
+                       }
                        xapp.Logger.Debug("SUBS-SubReq: internal delete due failure event(%s) %s", typeofSubsMessage(event), idstring(nil, trans, subs, parentTrans))
                case *SubmgrRestartTestEvent:
                        // This is used to simulate that no response has been received and after restart, subscriptions are restored from db
@@ -1146,6 +1166,9 @@ func (c *Control) handleSubscriptionCreate(subs *Subscription, parentTrans *Tran
        } else {
                xapp.Logger.Debug("SUBS-SubReq: Handling (cached response %s) %s", typeofSubsMessage(subRfMsg), idstring(nil, trans, subs, parentTrans))
        }
+       xapp.Logger.Debug("subs.PolicyUpdate: %v", subs.PolicyUpdate)
+       xapp.Logger.Debug("subs: %v", subs)
+
        if valid == false {
                removeSubscriptionFromDb = true
        }