+
+func (c *Control) handleSubscriptionDeleteRequest(params *RMRParams) {
+ xapp.Logger.Info("SubDelReq from xapp: %s", params.String())
+
+ //
+ //
+ //
+ trans, err := c.tracker.TrackTransaction(NewRmrEndpoint(params.Src),
+ params.Xid,
+ params.Meid,
+ false,
+ true)
+
+ if err != nil {
+ xapp.Logger.Error("SubDelReq: %s, Dropping this msg. %s", err.Error(), params.String())
+ return
+ }
+
+ //
+ //
+ //
+ trans.SubDelReqMsg, err = c.e2ap.UnpackSubscriptionDeleteRequest(params.Payload)
+ if err != nil {
+ xapp.Logger.Error("SubDelReq: %s Dropping this msg. %s", err.Error(), trans)
+ trans.Release()
+ return
+ }
+
+ //
+ //
+ //
+ subs := c.registry.GetSubscription(uint16(trans.SubDelReqMsg.RequestId.Seq))
+ if subs == nil && params.SubId > 0 {
+ subs = c.registry.GetSubscription(uint16(params.SubId))
+ }
+
+ if subs == nil {
+ xapp.Logger.Error("SubDelReq: Not valid subscription found payloadSeqNum: %d, SubId: %d. Dropping this msg. %s", trans.SubDelReqMsg.RequestId.Seq, params.SubId, trans)
+ trans.Release()
+ return
+ }
+ xapp.Logger.Info("SubDelReq: subscription found payloadSeqNum: %d, SubId: %d. %s", trans.SubDelReqMsg.RequestId.Seq, params.SubId, trans)
+
+ err = subs.SetTransaction(trans)
+ if err != nil {
+ xapp.Logger.Error("SubDelReq: %s, Dropping this msg. %s", err.Error(), trans)
+ trans.Release()
+ return
+ }
+
+ //
+ // TODO: subscription delete is in fact owned by subscription and not transaction.
+ // Transaction is toward xapp while Subscription is toward ran.
+ // In merge several xapps may wake transactions, while only one subscription
+ // toward ran occurs -> subscription owns subscription creation toward ran
+ //
+ // This is intermediate solution while improving message handling
+ //
+ trans.Mtype, trans.Payload, err = c.e2ap.PackSubscriptionDeleteRequest(trans.SubDelReqMsg)
+ if err != nil {
+ xapp.Logger.Error("SubDelReq: %s for trans %s", err.Error(), trans)
+ trans.Release()
+ return
+ }
+
+ subs.UnConfirmed()
+
+ c.rmrSend("SubDelReq: SubDelReq to E2T", subs, trans)
+
+ c.timerMap.StartTimer("RIC_SUB_DEL_REQ", int(subs.GetSubId()), subDelReqTime, FirstTry, c.handleSubscriptionDeleteRequestTimer)
+ return
+}
+
+func (c *Control) handleSubscriptionDeleteResponse(params *RMRParams) (err error) {
+ xapp.Logger.Info("SubDelResp from E2T:%s", params.String())
+
+ //
+ //
+ //
+ SubDelRespMsg, err := c.e2ap.UnpackSubscriptionDeleteResponse(params.Payload)
+ if err != nil {
+ xapp.Logger.Error("SubDelResp: %s Dropping this msg. %s", err.Error(), params.String())
+ return
+ }
+
+ //
+ //
+ //
+ subs := c.registry.GetSubscription(uint16(SubDelRespMsg.RequestId.Seq))
+ if subs == nil && params.SubId > 0 {
+ subs = c.registry.GetSubscription(uint16(params.SubId))
+ }
+
+ if subs == nil {
+ xapp.Logger.Error("SubDelResp: Not valid subscription found payloadSeqNum: %d, SubId: %d. Dropping this msg. %s", SubDelRespMsg.RequestId.Seq, params.SubId, params.String())
+ return
+ }
+ xapp.Logger.Info("SubDelResp: subscription found payloadSeqNum: %d, SubId: %d", SubDelRespMsg.RequestId.Seq, subs.GetSubId())
+
+ //
+ //
+ //
+ trans := subs.GetTransaction()
+ if trans == nil {
+ xapp.Logger.Error("SubDelResp: Unknown trans. Dropping this msg. SubId: %d", subs.GetSubId())
+ return
+ }
+
+ trans.SubDelRespMsg = SubDelRespMsg
+
+ //
+ //
+ //
+ c.timerMap.StopTimer("RIC_SUB_DEL_REQ", int(subs.GetSubId()))
+
+ responseReceived := trans.CheckResponseReceived()
+ if responseReceived == true {
+ // Subscription Delete timer already received
+ return
+ }
+
+ c.sendSubscriptionDeleteResponse("SubDelResp", trans, subs)
+ return
+}
+
+func (c *Control) handleSubscriptionDeleteFailure(params *RMRParams) {
+ xapp.Logger.Info("SubDelFail from E2T:%s", params.String())
+
+ //
+ //
+ //
+ SubDelFailMsg, err := c.e2ap.UnpackSubscriptionDeleteFailure(params.Payload)
+ if err != nil {
+ xapp.Logger.Error("SubDelFail: %s Dropping this msg. %s", err.Error(), params.String())
+ return
+ }
+
+ //
+ //
+ //
+ subs := c.registry.GetSubscription(uint16(SubDelFailMsg.RequestId.Seq))
+ if subs == nil && params.SubId > 0 {
+ subs = c.registry.GetSubscription(uint16(params.SubId))
+ }
+
+ if subs == nil {
+ xapp.Logger.Error("SubDelFail: Not valid subscription found payloadSeqNum: %d, SubId: %d. Dropping this msg. %s", SubDelFailMsg.RequestId.Seq, params.SubId, params.String())
+ return
+ }
+ xapp.Logger.Info("SubDelFail: subscription found payloadSeqNum: %d, SubId: %d", SubDelFailMsg.RequestId.Seq, subs.GetSubId())
+
+ //
+ //
+ //
+ trans := subs.GetTransaction()
+ if trans == nil {
+ xapp.Logger.Error("SubDelFail: Unknown trans. Dropping this msg. SubId: %d", subs.GetSubId())
+ return
+ }
+ trans.SubDelFailMsg = SubDelFailMsg
+
+ //
+ //
+ //
+ c.timerMap.StopTimer("RIC_SUB_DEL_REQ", int(subs.GetSubId()))
+
+ responseReceived := trans.CheckResponseReceived()
+ if responseReceived == true {
+ // Subscription Delete timer already received
+ return
+ }
+
+ c.sendSubscriptionDeleteResponse("SubDelFail", trans, subs)
+ return
+}
+
+func (c *Control) handleSubscriptionDeleteRequestTimer(strId string, nbrId int, tryCount uint64) {
+ xapp.Logger.Info("SubDelReq timeout: subId: %v, tryCount: %v", nbrId, tryCount)
+
+ subs := c.registry.GetSubscription(uint16(nbrId))
+ if subs == nil {
+ xapp.Logger.Error("SubDelReq timeout: Unknown payloadSeqNum. Dropping this msg. SubId: %v", nbrId)
+ return
+ }
+
+ trans := subs.GetTransaction()
+ if trans == nil {
+ xapp.Logger.Error("SubDelReq timeout: Unknown trans. Dropping this msg. SubId: %v", subs.GetSubId())
+ return
+ }
+
+ responseReceived := trans.CheckResponseReceived()
+ if responseReceived == true {
+ // Subscription Delete Response or Failure already received
+ return
+ }
+
+ if tryCount < maxSubDelReqTryCount {
+ // Set possible to handle new response for the subId
+ trans.RetryTransaction()
+ c.rmrSend("SubDelReq timeout: SubDelReq to E2T", subs, trans)
+ tryCount++
+ c.timerMap.StartTimer("RIC_SUB_DEL_REQ", int(subs.GetSubId()), subReqTime, tryCount, c.handleSubscriptionDeleteRequestTimer)
+ return
+ }
+
+ c.sendSubscriptionDeleteResponse("SubDelReq(timer)", trans, subs)
+ return
+}
+
+func (c *Control) sendSubscriptionDeleteResponse(desc string, trans *Transaction, subs *Subscription) {
+
+ if trans.ForwardRespToXapp == true {
+ //Always generate SubDelResp
+ trans.SubDelRespMsg = &e2ap.E2APSubscriptionDeleteResponse{}
+ trans.SubDelRespMsg.RequestId.Id = trans.SubDelReqMsg.RequestId.Id
+ trans.SubDelRespMsg.RequestId.Seq = uint32(subs.GetSubId())
+ trans.SubDelRespMsg.FunctionId = trans.SubDelReqMsg.FunctionId
+
+ var err error
+ trans.Mtype, trans.Payload, err = c.e2ap.PackSubscriptionDeleteResponse(trans.SubDelRespMsg)
+ if err == nil {
+ c.rmrReplyToSender(desc+": SubDelResp to xapp", subs, trans)
+ time.Sleep(3 * time.Second)
+ } else {
+ //TODO error handling improvement
+ xapp.Logger.Error("%s: %s for trans %s (continuing cleaning)", desc, err.Error(), trans)
+ }
+ }
+
+ trans.Release()
+ subs.Release()
+}