+ xapp.Logger.Debug("RMR route not created: createRMRRoute=%v", createRMRRoute)
+ }
+ r.mutex.Lock()
+
+ if err != nil {
+ if newAlloc {
+ r.subIds = append(r.subIds, subs.ReqId.InstanceId)
+ }
+ // Delete already added endpoint for the request
+ subs.EpList.DelEndpoint(trans.GetEndpoint())
+ return nil, errorInfo, err
+ }
+
+ if newAlloc {
+ r.register[subs.ReqId.InstanceId] = subs
+ }
+ xapp.Logger.Debug("CREATE %s", subs.String())
+ xapp.Logger.Debug("Registry: substable=%v", r.register)
+ return subs, errorInfo, nil
+}
+
+func (r *Registry) RouteCreate(subs *Subscription, c *Control) (ErrorInfo, error) {
+ errorInfo := ErrorInfo{}
+ subRouteAction := SubRouteInfo{subs.EpList, uint16(subs.ReqId.InstanceId)}
+ err := r.rtmgrClient.SubscriptionRequestCreate(subRouteAction)
+ if err != nil {
+ if strings.Contains(err.Error(), "status 400") {
+ errorInfo.TimeoutType = models.SubscriptionInstanceTimeoutTypeRTMGRTimeout
+ } else {
+ errorInfo.ErrorSource = models.SubscriptionInstanceErrorSourceRTMGR
+ }
+ errorInfo.ErrorCause = err.Error()
+ c.UpdateCounter(cRouteCreateFail)
+ xapp.Logger.Error("%s", err.Error())
+ err = fmt.Errorf("RTMGR route create failure")
+ }
+ return errorInfo, err
+}
+
+func (r *Registry) RouteCreateUpdate(subs *Subscription, c *Control) (ErrorInfo, error) {
+ errorInfo := ErrorInfo{}
+ subRouteAction := SubRouteInfo{subs.EpList, uint16(subs.ReqId.InstanceId)}
+ err := r.rtmgrClient.SubscriptionRequestUpdate(subRouteAction)
+ if err != nil {
+ if strings.Contains(err.Error(), "status 400") {
+ errorInfo.TimeoutType = models.SubscriptionInstanceTimeoutTypeRTMGRTimeout
+ } else {
+ errorInfo.ErrorSource = models.SubscriptionInstanceErrorSourceRTMGR
+ }
+ errorInfo.ErrorCause = err.Error()
+ c.UpdateCounter(cRouteCreateUpdateFail)
+ xapp.Logger.Error("%s", err.Error())
+ err = fmt.Errorf("RTMGR route update failure")
+ return errorInfo, err
+ }
+ c.UpdateCounter(cMergedSubscriptions)
+ return errorInfo, err
+}
+
+func (r *Registry) CheckActionTypes(subReqMsg *e2ap.E2APSubscriptionRequest) (uint64, error) {
+ var reportFound bool = false
+ var policyFound bool = false
+ var insertFound bool = false
+
+ for _, acts := range subReqMsg.ActionSetups {
+ if acts.ActionType == e2ap.E2AP_ActionTypeReport {
+ reportFound = true
+ }
+ if acts.ActionType == e2ap.E2AP_ActionTypePolicy {
+ policyFound = true
+ }
+ if acts.ActionType == e2ap.E2AP_ActionTypeInsert {
+ insertFound = true
+ }
+ }
+ if reportFound == true && policyFound == true || reportFound == true && insertFound == true || policyFound == true && insertFound == true {
+ return e2ap.E2AP_ActionTypeInvalid, fmt.Errorf("Different action types (Report, Policy or Insert) in same RICactions-ToBeSetup-List")
+ }
+ if reportFound == true {
+ return e2ap.E2AP_ActionTypeReport, nil
+ }
+ if policyFound == true {
+ return e2ap.E2AP_ActionTypePolicy, nil
+ }
+ if insertFound == true {
+ return e2ap.E2AP_ActionTypeInsert, nil
+ }
+ return e2ap.E2AP_ActionTypeInvalid, fmt.Errorf("Invalid action type in RICactions-ToBeSetup-List")
+}
+
+// TODO: Works with concurrent calls, but check if can be improved
+func (r *Registry) RemoveFromSubscription(subs *Subscription, trans *TransactionXapp, waitRouteClean time.Duration, c *Control) error {
+
+ r.mutex.Lock()
+ defer r.mutex.Unlock()
+ subs.mutex.Lock()
+ defer subs.mutex.Unlock()
+
+ delStatus := subs.EpList.DelEndpoint(trans.GetEndpoint())
+ epamount := subs.EpList.Size()
+ subId := subs.ReqId.InstanceId
+ if delStatus == false {
+ return nil
+ }
+
+ go func() {
+ if waitRouteClean > 0 {
+ xapp.Logger.Debug("Pending %v in order to wait route cleanup", waitRouteClean)
+ time.Sleep(waitRouteClean)
+ }
+
+ subs.mutex.Lock()
+ defer subs.mutex.Unlock()
+ xapp.Logger.Debug("CLEAN %s", subs.String())
+
+ if epamount == 0 {
+ //
+ // Subscription route delete
+ //
+ if subs.RMRRouteCreated == true {
+ r.RouteDelete(subs, trans, c)
+ }
+
+ //
+ // Subscription release
+ //
+ r.mutex.Lock()
+ defer r.mutex.Unlock()
+
+ if _, ok := r.register[subId]; ok {
+ xapp.Logger.Debug("RELEASE %s", subs.String())
+ delete(r.register, subId)
+ xapp.Logger.Debug("Registry: substable=%v", r.register)
+ }
+ r.subIds = append(r.subIds, subId)
+ } else if subs.EpList.Size() > 0 {
+ //
+ // Subscription route update
+ //
+ if subs.RMRRouteCreated == true {
+ r.RouteDeleteUpdate(subs, c)
+ }
+ }
+ }()
+
+ return nil
+}
+
+func (r *Registry) RouteDelete(subs *Subscription, trans *TransactionXapp, c *Control) {
+
+ tmpList := xapp.RmrEndpointList{}
+ tmpList.AddEndpoint(trans.GetEndpoint())
+ subRouteAction := SubRouteInfo{tmpList, uint16(subs.ReqId.InstanceId)}
+ if err := r.rtmgrClient.SubscriptionRequestDelete(subRouteAction); err != nil {
+ c.UpdateCounter(cRouteDeleteFail)
+ }
+}
+
+func (r *Registry) RouteDeleteUpdate(subs *Subscription, c *Control) {
+ subRouteAction := SubRouteInfo{subs.EpList, uint16(subs.ReqId.InstanceId)}
+ if err := r.rtmgrClient.SubscriptionRequestUpdate(subRouteAction); err != nil {
+ c.UpdateCounter(cRouteDeleteUpdateFail)
+ }
+}
+
+func (r *Registry) UpdateSubscriptionToDb(subs *Subscription, c *Control) {
+ r.mutex.Lock()
+ defer r.mutex.Unlock()
+ subs.mutex.Lock()
+ defer subs.mutex.Unlock()
+
+ epamount := subs.EpList.Size()
+ if epamount == 0 {
+ if _, ok := r.register[subs.ReqId.InstanceId]; ok {
+ // Not merged subscription is being deleted
+ c.RemoveSubscriptionFromDb(subs)
+
+ }
+ } else if subs.EpList.Size() > 0 {
+ // Endpoint of merged subscription is being deleted
+ c.WriteSubscriptionToDb(subs)
+ c.UpdateCounter(cUnmergedSubscriptions)