+//-------------------------------------------------------------------
+// SUBS CREATE Handling
+//-------------------------------------------------------------------
+func (c *Control) handleSubscriptionCreate(subs *Subscription, parentTrans *TransactionXapp) {
+
+ trans := c.tracker.NewSubsTransaction(subs)
+ subs.WaitTransactionTurn(trans)
+ defer subs.ReleaseTransactionTurn(trans)
+ defer trans.Release()
+
+ xapp.Logger.Debug("SUBS-SubReq: Handling %s ", idstring(nil, trans, subs, parentTrans))
+
+ 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)
+ case *e2ap.E2APSubscriptionFailure:
+ 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)
+ default:
+ xapp.Logger.Info("SUBS-SubReq: internal delete due event(%s) %s", typeofSubsMessage(event), idstring(nil, trans, subs, parentTrans))
+ 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 {
+ xapp.Logger.Debug("SUBS-SubReq: Handling (cached response %s) %s", typeofSubsMessage(subRfMsg), idstring(nil, trans, subs, parentTrans))
+ }
+
+ //Now RemoveFromSubscription in here to avoid race conditions (mostly concerns delete)
+ if valid == false {
+ c.registry.RemoveFromSubscription(subs, parentTrans, 5*time.Second)
+ }
+ parentTrans.SendEvent(subRfMsg, 0)
+}
+
+//-------------------------------------------------------------------
+// SUBS DELETE Handling
+//-------------------------------------------------------------------
+
+func (c *Control) handleSubscriptionDelete(subs *Subscription, parentTrans *TransactionXapp) {
+
+ trans := c.tracker.NewSubsTransaction(subs)
+ subs.WaitTransactionTurn(trans)
+ defer subs.ReleaseTransactionTurn(trans)
+ defer trans.Release()
+
+ xapp.Logger.Debug("SUBS-SubDelReq: Handling %s", idstring(nil, trans, subs, parentTrans))
+
+ subs.mutex.Lock()
+ if subs.valid && subs.EpList.HasEndpoint(parentTrans.GetEndpoint()) && subs.EpList.Size() == 1 {
+ subs.valid = false
+ subs.mutex.Unlock()
+ c.sendE2TSubscriptionDeleteRequest(subs, trans, parentTrans)
+ } else {
+ subs.mutex.Unlock()
+ }
+ //Now RemoveFromSubscription in here to avoid race conditions (mostly concerns delete)
+ // If parallel deletes ongoing both might pass earlier sendE2TSubscriptionDeleteRequest(...) if
+ // RemoveFromSubscription locates in caller side (now in handleXAPPSubscriptionDeleteRequest(...))
+ c.registry.RemoveFromSubscription(subs, parentTrans, 5*time.Second)
+ parentTrans.SendEvent(nil, 0)
+}
+
+//-------------------------------------------------------------------
+// send to E2T Subscription Request
+//-------------------------------------------------------------------
+func (c *Control) sendE2TSubscriptionRequest(subs *Subscription, trans *TransactionSubs, parentTrans *TransactionXapp) interface{} {
+ var err error
+ var event interface{} = nil
+ var timedOut bool = false
+
+ subReqMsg := subs.SubReqMsg
+ subReqMsg.RequestId = subs.GetReqId().RequestId
+ trans.Mtype, trans.Payload, err = c.e2ap.PackSubscriptionRequest(subReqMsg)
+ if err != nil {
+ xapp.Logger.Error("SUBS-SubReq: %s", idstring(err, trans, subs, parentTrans))
+ return event
+ }
+
+ for retries := uint64(0); retries < e2tMaxSubReqTryCount; retries++ {
+ desc := fmt.Sprintf("(retry %d)", retries)
+ c.rmrSendToE2T(desc, subs, trans)
+ event, timedOut = trans.WaitEvent(e2tSubReqTimeout)
+ if timedOut {
+ continue
+ }
+ break
+ }
+ xapp.Logger.Debug("SUBS-SubReq: Response handling event(%s) %s", typeofSubsMessage(event), idstring(nil, trans, subs, parentTrans))
+ return event
+}
+
+//-------------------------------------------------------------------
+// send to E2T Subscription Delete Request
+//-------------------------------------------------------------------
+
+func (c *Control) sendE2TSubscriptionDeleteRequest(subs *Subscription, trans *TransactionSubs, parentTrans *TransactionXapp) interface{} {
+ var err error
+ var event interface{}
+ var timedOut bool
+
+ subDelReqMsg := &e2ap.E2APSubscriptionDeleteRequest{}
+ subDelReqMsg.RequestId = subs.GetReqId().RequestId
+ subDelReqMsg.FunctionId = subs.SubReqMsg.FunctionId
+ trans.Mtype, trans.Payload, err = c.e2ap.PackSubscriptionDeleteRequest(subDelReqMsg)
+ if err != nil {
+ xapp.Logger.Error("SUBS-SubDelReq: %s", idstring(err, trans, subs, parentTrans))
+ return event
+ }
+
+ for retries := uint64(0); retries < e2tMaxSubDelReqTryCount; retries++ {
+ desc := fmt.Sprintf("(retry %d)", retries)
+ c.rmrSendToE2T(desc, subs, trans)
+ event, timedOut = trans.WaitEvent(e2tSubDelReqTime)
+ if timedOut {
+ continue
+ }
+ break
+ }
+ xapp.Logger.Debug("SUBS-SubDelReq: Response handling event(%s) %s", typeofSubsMessage(event), idstring(nil, trans, subs, parentTrans))
+ return event