blob: 9ce34a07dc51596b3b07d56f6e09d2423e5db9fc [file] [log] [blame]
kalnagy45114752019-06-18 14:40:39 +02001/*
2==================================================================================
3 Copyright (c) 2019 AT&T Intellectual Property.
4 Copyright (c) 2019 Nokia
5
6 Licensed under the Apache License, Version 2.0 (the "License");
7 you may not use this file except in compliance with the License.
8 You may obtain a copy of the License at
9
10 http://www.apache.org/licenses/LICENSE-2.0
11
12 Unless required by applicable law or agreed to in writing, software
13 distributed under the License is distributed on an "AS IS" BASIS,
14 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 See the License for the specific language governing permissions and
16 limitations under the License.
17==================================================================================
18*/
19
20package control
21
kalnagy45114752019-06-18 14:40:39 +020022import (
Peter Szilagyifbc56f92019-07-23 19:29:46 +000023 "errors"
kalnagy93cc3e22019-09-19 11:29:29 +020024 rtmgrclient "gerrit.o-ran-sc.org/r/ric-plt/submgr/pkg/rtmgr_client"
25 rtmgrhandle "gerrit.o-ran-sc.org/r/ric-plt/submgr/pkg/rtmgr_client/handle"
kalnagy1455c852019-10-21 13:06:23 +020026 "gerrit.o-ran-sc.org/r/ric-plt/xapp-frame/pkg/xapp"
27 httptransport "github.com/go-openapi/runtime/client"
28 "github.com/go-openapi/strfmt"
29 "github.com/spf13/viper"
Peter Szilagyifbc56f92019-07-23 19:29:46 +000030 "math/rand"
Juha Hyttinenff8dccd2019-12-10 14:34:07 +020031 "sync"
Peter Szilagyifbc56f92019-07-23 19:29:46 +000032 "time"
kalnagy45114752019-06-18 14:40:39 +020033)
34
Anssi Mannilaf1d0eb62019-12-17 15:29:55 +020035var subReqTime time.Duration = 5 * time.Second
Anssi Mannila8046c702020-01-02 13:39:05 +020036var subDelReqTime time.Duration = 5 * time.Second
37var maxSubReqTryCount uint64 = 2 // Initial try + retry
38var maxSubDelReqTryCount uint64 = 2 // Initial try + retry
Anssi Mannila2e99e2f2019-12-05 13:57:06 +020039
kalnagy45114752019-06-18 14:40:39 +020040type Control struct {
Juha Hyttinenc65f5b02019-12-30 14:24:04 +020041 e2ap *E2ap
42 registry *Registry
43 rtmgrClient *RtmgrClient
44 tracker *Tracker
45 timerMap *TimerMap
46 rmrSendMutex sync.Mutex
Juha Hyttinen47b842b2020-01-08 13:01:52 +020047 msgCounter uint64
kalnagy93cc3e22019-09-19 11:29:29 +020048}
49
50type RMRMeid struct {
Juha Hyttinenff8dccd2019-12-10 14:34:07 +020051 PlmnID string
52 EnbID string
Anssi Mannila2e99e2f2019-12-05 13:57:06 +020053 RanName string
kalnagy93cc3e22019-09-19 11:29:29 +020054}
55
kalnagy1455c852019-10-21 13:06:23 +020056var seedSN uint16
kalnagy93cc3e22019-09-19 11:29:29 +020057
58const (
59 CREATE Action = 0
kalnagy1455c852019-10-21 13:06:23 +020060 MERGE Action = 1
Anssi Mannila90fa0212019-12-12 10:47:47 +020061 NONE Action = 2
kalnagy93cc3e22019-09-19 11:29:29 +020062 DELETE Action = 3
63)
Peter Szilagyifbc56f92019-07-23 19:29:46 +000064
65func init() {
Anssi Mannila8046c702020-01-02 13:39:05 +020066 xapp.Logger.Info("SUBMGR")
Peter Szilagyifbc56f92019-07-23 19:29:46 +000067 viper.AutomaticEnv()
68 viper.SetEnvPrefix("submgr")
69 viper.AllowEmptyEnv(true)
kalnagy1455c852019-10-21 13:06:23 +020070 seedSN = uint16(viper.GetInt("seed_sn"))
71 if seedSN == 0 {
Peter Szilagyifbc56f92019-07-23 19:29:46 +000072 rand.Seed(time.Now().UnixNano())
kalnagy1455c852019-10-21 13:06:23 +020073 seedSN = uint16(rand.Intn(65535))
Peter Szilagyifbc56f92019-07-23 19:29:46 +000074 }
kalnagy1455c852019-10-21 13:06:23 +020075 if seedSN > 65535 {
76 seedSN = 0
Peter Szilagyifbc56f92019-07-23 19:29:46 +000077 }
kalnagy1455c852019-10-21 13:06:23 +020078 xapp.Logger.Info("SUBMGR: Initial Sequence Number: %v", seedSN)
kalnagy45114752019-06-18 14:40:39 +020079}
80
Juha Hyttinenff8dccd2019-12-10 14:34:07 +020081func NewControl() *Control {
Peter Szilagyifbc56f92019-07-23 19:29:46 +000082 registry := new(Registry)
kalnagy1455c852019-10-21 13:06:23 +020083 registry.Initialize(seedSN)
kalnagy93cc3e22019-09-19 11:29:29 +020084
Balint Uvegese9608cd2019-09-20 18:00:32 +000085 tracker := new(Tracker)
86 tracker.Init()
87
Anssi Mannila2e99e2f2019-12-05 13:57:06 +020088 timerMap := new(TimerMap)
89 timerMap.Init()
90
kalnagy1455c852019-10-21 13:06:23 +020091 transport := httptransport.New(viper.GetString("rtmgr.HostAddr")+":"+viper.GetString("rtmgr.port"), viper.GetString("rtmgr.baseUrl"), []string{"http"})
kalnagy93cc3e22019-09-19 11:29:29 +020092 client := rtmgrclient.New(transport, strfmt.Default)
93 handle := rtmgrhandle.NewProvideXappSubscriptionHandleParamsWithTimeout(10 * time.Second)
kalnagy1455c852019-10-21 13:06:23 +020094 deleteHandle := rtmgrhandle.NewDeleteXappSubscriptionHandleParamsWithTimeout(10 * time.Second)
95 rtmgrClient := RtmgrClient{client, handle, deleteHandle}
kalnagy93cc3e22019-09-19 11:29:29 +020096
Juha Hyttinenff8dccd2019-12-10 14:34:07 +020097 return &Control{e2ap: new(E2ap),
Juha Hyttinenc65f5b02019-12-30 14:24:04 +020098 registry: registry,
99 rtmgrClient: &rtmgrClient,
100 tracker: tracker,
101 timerMap: timerMap,
Juha Hyttinen47b842b2020-01-08 13:01:52 +0200102 msgCounter: 0,
Juha Hyttinenff8dccd2019-12-10 14:34:07 +0200103 }
kalnagy45114752019-06-18 14:40:39 +0200104}
105
106func (c *Control) Run() {
Peter Szilagyifbc56f92019-07-23 19:29:46 +0000107 xapp.Run(c)
kalnagy45114752019-06-18 14:40:39 +0200108}
109
kalnagy93cc3e22019-09-19 11:29:29 +0200110func (c *Control) rmrSend(params *xapp.RMRParams) (err error) {
Anssi Mannila2e99e2f2019-12-05 13:57:06 +0200111 status := false
112 i := 1
Juha Hyttinenff8dccd2019-12-10 14:34:07 +0200113 for ; i <= 10 && status == false; i++ {
Anssi Mannila90fa0212019-12-12 10:47:47 +0200114 c.rmrSendMutex.Lock()
Anssi Mannila2e99e2f2019-12-05 13:57:06 +0200115 status = xapp.Rmr.Send(params, false)
Anssi Mannila90fa0212019-12-12 10:47:47 +0200116 c.rmrSendMutex.Unlock()
Anssi Mannila2e99e2f2019-12-05 13:57:06 +0200117 if status == false {
Juha Hyttinenff8dccd2019-12-10 14:34:07 +0200118 xapp.Logger.Info("rmr.Send() failed. Retry count %v, Mtype: %v, SubId: %v, Xid %s", i, params.Mtype, params.SubId, params.Xid)
Anssi Mannila2e99e2f2019-12-05 13:57:06 +0200119 time.Sleep(500 * time.Millisecond)
120 }
121 }
122 if status == false {
123 err = errors.New("rmr.Send() failed")
124 xapp.Rmr.Free(params.Mbuf)
125 }
Peter Szilagyifbc56f92019-07-23 19:29:46 +0000126 return
kalnagy45114752019-06-18 14:40:39 +0200127}
128
kalnagye0018682019-09-26 16:28:25 +0200129func (c *Control) rmrReplyToSender(params *xapp.RMRParams) (err error) {
Anssi Mannila2e99e2f2019-12-05 13:57:06 +0200130 c.rmrSend(params)
kalnagye0018682019-09-26 16:28:25 +0200131 return
132}
133
Anssi Mannila90fa0212019-12-12 10:47:47 +0200134func (c *Control) Consume(msg *xapp.RMRParams) (err error) {
Juha Hyttinen47b842b2020-01-08 13:01:52 +0200135 c.msgCounter++
Anssi Mannila90fa0212019-12-12 10:47:47 +0200136 switch msg.Mtype {
137 case xapp.RICMessageTypes["RIC_SUB_REQ"]:
138 go c.handleSubscriptionRequest(msg)
139 case xapp.RICMessageTypes["RIC_SUB_RESP"]:
140 go c.handleSubscriptionResponse(msg)
141 case xapp.RICMessageTypes["RIC_SUB_FAILURE"]:
142 go c.handleSubscriptionFailure(msg)
143 case xapp.RICMessageTypes["RIC_SUB_DEL_REQ"]:
144 go c.handleSubscriptionDeleteRequest(msg)
145 case xapp.RICMessageTypes["RIC_SUB_DEL_RESP"]:
146 go c.handleSubscriptionDeleteResponse(msg)
Anssi Mannilaf1d0eb62019-12-17 15:29:55 +0200147 case xapp.RICMessageTypes["RIC_SUB_DEL_FAILURE"]:
148 go c.handleSubscriptionDeleteFailure(msg)
Anssi Mannila90fa0212019-12-12 10:47:47 +0200149 default:
150 xapp.Logger.Info("Unknown Message Type '%d', discarding", msg.Mtype)
Balint Uvegescd3881b2019-10-02 15:01:43 +0000151 }
Anssi Mannila90fa0212019-12-12 10:47:47 +0200152 return nil
Balint Uvegescd3881b2019-10-02 15:01:43 +0000153}
154
Anssi Mannila90fa0212019-12-12 10:47:47 +0200155func (c *Control) handleSubscriptionRequest(params *xapp.RMRParams) {
Juha Hyttinenff8dccd2019-12-10 14:34:07 +0200156 xapp.Logger.Info("SubReq received from Src: %s, Mtype: %v, SubId: %v, Xid: %s, Meid: %v", params.Src, params.Mtype, params.SubId, params.Xid, params.Meid)
Anssi Mannila2e99e2f2019-12-05 13:57:06 +0200157 xapp.Rmr.Free(params.Mbuf)
158 params.Mbuf = nil
kalnagy93cc3e22019-09-19 11:29:29 +0200159
160 /* Reserve a sequence number and set it in the payload */
Juha Hyttinen47b842b2020-01-08 13:01:52 +0200161 subs := c.registry.ReserveSubscription()
162 if subs == nil {
Juha Hyttinenff8dccd2019-12-10 14:34:07 +0200163 xapp.Logger.Error("SubReq: Failed to reserve sequence number. Dropping this msg. SubId: %v, Xid: %s", params.SubId, params.Xid)
164 return
Anssi Mannila2e99e2f2019-12-05 13:57:06 +0200165 }
kalnagy93cc3e22019-09-19 11:29:29 +0200166
Juha Hyttinen47b842b2020-01-08 13:01:52 +0200167 params.SubId = int(subs.Seq)
168 err := c.e2ap.SetSubscriptionRequestSequenceNumber(params.Payload, subs.Seq)
Peter Szilagyifbc56f92019-07-23 19:29:46 +0000169 if err != nil {
Anssi Mannila8046c702020-01-02 13:39:05 +0200170 xapp.Logger.Error("SubReq: Unable to get Sequence Number from Payload. Dropping this msg. Err: %v, SubId: %v, Xid: %s, Payload %X", err, params.SubId, params.Xid, params.Payload)
Juha Hyttinen47b842b2020-01-08 13:01:52 +0200171 c.registry.releaseSequenceNumber(subs.Seq)
Peter Szilagyifbc56f92019-07-23 19:29:46 +0000172 return
173 }
kalnagy93cc3e22019-09-19 11:29:29 +0200174
kalnagy1455c852019-10-21 13:06:23 +0200175 srcAddr, srcPort, err := c.rtmgrClient.SplitSource(params.Src)
kalnagy93cc3e22019-09-19 11:29:29 +0200176 if err != nil {
Anssi Mannila26c922a2019-12-17 11:18:08 +0200177 xapp.Logger.Error("SubReq: Failed to update routing-manager. Dropping this msg. Err: %s, SubId: %v, Xid: %s", err, params.SubId, params.Xid)
Juha Hyttinen47b842b2020-01-08 13:01:52 +0200178 c.registry.releaseSequenceNumber(subs.Seq)
kalnagy93cc3e22019-09-19 11:29:29 +0200179 return
180 }
181
Anssi Mannila8046c702020-01-02 13:39:05 +0200182 // Create transatcion record for every subscription request
183 var forwardRespToXapp bool = true
184 var responseReceived bool = false
Juha Hyttinen47b842b2020-01-08 13:01:52 +0200185 transaction, err := c.tracker.TrackTransaction(subs.Seq, CREATE, *srcAddr, *srcPort, params, responseReceived, forwardRespToXapp)
kalnagy93cc3e22019-09-19 11:29:29 +0200186 if err != nil {
Anssi Mannila26c922a2019-12-17 11:18:08 +0200187 xapp.Logger.Error("SubReq: Failed to create transaction record. Dropping this msg. Err: %v SubId: %v, Xid: %s", err, params.SubId, params.Xid)
Juha Hyttinen47b842b2020-01-08 13:01:52 +0200188 c.registry.releaseSequenceNumber(subs.Seq)
kalnagy93cc3e22019-09-19 11:29:29 +0200189 return
190 }
191
Anssi Mannila8046c702020-01-02 13:39:05 +0200192 // Update routing manager about the new subscription
Juha Hyttinen379ff082019-12-30 15:49:41 +0200193 subRouteAction := transaction.SubRouteInfo()
Anssi Mannila26c922a2019-12-17 11:18:08 +0200194 xapp.Logger.Info("SubReq: Starting routing manager update. SubId: %v, Xid: %s", params.SubId, params.Xid)
Juha Hyttinenff8dccd2019-12-10 14:34:07 +0200195
Juha Hyttinenc65f5b02019-12-30 14:24:04 +0200196 err = c.rtmgrClient.SubscriptionRequestUpdate(subRouteAction)
197 if err != nil {
Anssi Mannila8046c702020-01-02 13:39:05 +0200198 xapp.Logger.Error("SubReq: Failed to update routing manager. Dropping this msg. Err: %v, SubId: %v, Xid: %s", err, params.SubId, params.Xid)
Juha Hyttinen47b842b2020-01-08 13:01:52 +0200199 c.registry.releaseSequenceNumber(subs.Seq)
Juha Hyttinenc65f5b02019-12-30 14:24:04 +0200200 return
Anssi Mannila90fa0212019-12-12 10:47:47 +0200201 }
kalnagy93cc3e22019-09-19 11:29:29 +0200202
203 // Setting new subscription ID in the RMR header
Anssi Mannila8046c702020-01-02 13:39:05 +0200204 xapp.Logger.Info("SubReq: Forwarding SubReq to E2T: Mtype: %v, SubId: %v, Xid %s, Meid %v", params.Mtype, params.SubId, params.Xid, params.Meid)
Anssi Mannila2e99e2f2019-12-05 13:57:06 +0200205 err = c.rmrSend(params)
206 if err != nil {
Anssi Mannila26c922a2019-12-17 11:18:08 +0200207 xapp.Logger.Error("SubReq: Failed to send request to E2T %v, SubId: %v, Xid: %s", err, params.SubId, params.Xid)
Anssi Mannilaf1d0eb62019-12-17 15:29:55 +0200208 }
Juha Hyttinen47b842b2020-01-08 13:01:52 +0200209 c.timerMap.StartTimer("RIC_SUB_REQ", int(subs.Seq), subReqTime, FirstTry, c.handleSubscriptionRequestTimer)
Anssi Mannila26c922a2019-12-17 11:18:08 +0200210 xapp.Logger.Debug("SubReq: Debugging transaction table = %v", c.tracker.transactionTable)
Peter Szilagyifbc56f92019-07-23 19:29:46 +0000211 return
kalnagy45114752019-06-18 14:40:39 +0200212}
213
Anssi Mannila90fa0212019-12-12 10:47:47 +0200214func (c *Control) handleSubscriptionResponse(params *xapp.RMRParams) {
Juha Hyttinenff8dccd2019-12-10 14:34:07 +0200215 xapp.Logger.Info("SubResp received from Src: %s, Mtype: %v, SubId: %v, Meid: %v", params.Src, params.Mtype, params.SubId, params.Meid)
Anssi Mannila2e99e2f2019-12-05 13:57:06 +0200216 xapp.Rmr.Free(params.Mbuf)
217 params.Mbuf = nil
218
kalnagy1455c852019-10-21 13:06:23 +0200219 payloadSeqNum, err := c.e2ap.GetSubscriptionResponseSequenceNumber(params.Payload)
Peter Szilagyifbc56f92019-07-23 19:29:46 +0000220 if err != nil {
Anssi Mannila8046c702020-01-02 13:39:05 +0200221 xapp.Logger.Error("SubResp: Unable to get Sequence Number from Payload. Dropping this msg. Err: %v, SubId: %v, Xid: %s, Payload %X", err, params.SubId, params.Xid, params.Payload)
Peter Szilagyifbc56f92019-07-23 19:29:46 +0000222 return
223 }
Juha Hyttinenff8dccd2019-12-10 14:34:07 +0200224 xapp.Logger.Info("SubResp: Received payloadSeqNum: %v", payloadSeqNum)
Anssi Mannila2e99e2f2019-12-05 13:57:06 +0200225
kalnagy1455c852019-10-21 13:06:23 +0200226 if !c.registry.IsValidSequenceNumber(payloadSeqNum) {
Juha Hyttinenff8dccd2019-12-10 14:34:07 +0200227 xapp.Logger.Error("SubResp: Unknown payloadSeqNum. Dropping this msg. PayloadSeqNum: %v, SubId: %v", payloadSeqNum, params.SubId)
Peter Szilagyifbc56f92019-07-23 19:29:46 +0000228 return
229 }
Anssi Mannila2e99e2f2019-12-05 13:57:06 +0200230
Anssi Mannilaf1d0eb62019-12-17 15:29:55 +0200231 c.timerMap.StopTimer("RIC_SUB_REQ", int(payloadSeqNum))
Anssi Mannila2e99e2f2019-12-05 13:57:06 +0200232
Anssi Mannila8046c702020-01-02 13:39:05 +0200233 transaction, responseReceived, err := c.tracker.CheckResponseReceived(payloadSeqNum, CREATE)
Anssi Mannila2e99e2f2019-12-05 13:57:06 +0200234 if err != nil {
Anssi Mannila8046c702020-01-02 13:39:05 +0200235 xapp.Logger.Info("SubResp: Dropping this msg. Err: %v SubId: %v", err, payloadSeqNum)
Anssi Mannila2e99e2f2019-12-05 13:57:06 +0200236 return
237 }
Anssi Mannila8046c702020-01-02 13:39:05 +0200238
239 if responseReceived == true {
240 // Subscription timer already received
241 return
242 }
243 xapp.Logger.Info("SubResp: SubId: %v, from address: %v:%v.", payloadSeqNum, transaction.Xappkey.Addr, transaction.Xappkey.Port)
244
245 c.registry.setSubscriptionToConfirmed(payloadSeqNum)
Anssi Mannila2e99e2f2019-12-05 13:57:06 +0200246
Juha Hyttinenff8dccd2019-12-10 14:34:07 +0200247 params.SubId = int(payloadSeqNum)
248 params.Xid = transaction.OrigParams.Xid
249
250 xapp.Logger.Info("SubResp: Forwarding Subscription Response to xApp Mtype: %v, SubId: %v, Meid: %v", params.Mtype, params.SubId, params.Meid)
Anssi Mannila2e99e2f2019-12-05 13:57:06 +0200251 err = c.rmrReplyToSender(params)
252 if err != nil {
Anssi Mannila26c922a2019-12-17 11:18:08 +0200253 xapp.Logger.Error("SubResp: Failed to send response to xApp. Err: %v, SubId: %v, Xid: %s", err, params.SubId, params.Xid)
Anssi Mannila2e99e2f2019-12-05 13:57:06 +0200254 }
255
Anssi Mannila8046c702020-01-02 13:39:05 +0200256 xapp.Logger.Info("SubResp: SubId: %v, from address: %v:%v. Deleting transaction record", payloadSeqNum, transaction.Xappkey.Addr, transaction.Xappkey.Port)
257 _, err = c.tracker.completeTransaction(payloadSeqNum, CREATE)
kalnagye0018682019-09-26 16:28:25 +0200258 if err != nil {
Anssi Mannila26c922a2019-12-17 11:18:08 +0200259 xapp.Logger.Error("SubResp: Failed to delete transaction record. Err: %v, SubId: %v, Xid: %s", err, params.SubId, params.Xid)
kalnagye0018682019-09-26 16:28:25 +0200260 return
261 }
Anssi Mannila2e99e2f2019-12-05 13:57:06 +0200262 return
263}
264
Anssi Mannila90fa0212019-12-12 10:47:47 +0200265func (c *Control) handleSubscriptionFailure(params *xapp.RMRParams) {
Juha Hyttinenff8dccd2019-12-10 14:34:07 +0200266 xapp.Logger.Info("SubFail received from Src: %s, Mtype: %v, SubId: %v, Meid: %v", params.Src, params.Mtype, params.SubId, params.Meid)
Anssi Mannila2e99e2f2019-12-05 13:57:06 +0200267 xapp.Rmr.Free(params.Mbuf)
268 params.Mbuf = nil
269
270 payloadSeqNum, err := c.e2ap.GetSubscriptionFailureSequenceNumber(params.Payload)
271 if err != nil {
Anssi Mannila8046c702020-01-02 13:39:05 +0200272 xapp.Logger.Error("SubFail: Unable to get Sequence Number from Payload. Dropping this msg. Err: %v, SubId: %v, Xid: %s, Payload %X", err, params.SubId, params.Xid, params.Payload)
Anssi Mannila2e99e2f2019-12-05 13:57:06 +0200273 return
274 }
Anssi Mannila26c922a2019-12-17 11:18:08 +0200275 xapp.Logger.Info("SubFail: Received payloadSeqNum: %v", payloadSeqNum)
Anssi Mannila2e99e2f2019-12-05 13:57:06 +0200276
Anssi Mannilaf1d0eb62019-12-17 15:29:55 +0200277 c.timerMap.StopTimer("RIC_SUB_REQ", int(payloadSeqNum))
Anssi Mannila2e99e2f2019-12-05 13:57:06 +0200278
Anssi Mannila8046c702020-01-02 13:39:05 +0200279 transaction, responseReceived, err := c.tracker.CheckResponseReceived(payloadSeqNum, CREATE)
Juha Hyttinenff8dccd2019-12-10 14:34:07 +0200280 if err != nil {
Anssi Mannila8046c702020-01-02 13:39:05 +0200281 xapp.Logger.Info("SubFail: Dropping this msg. Err: %v SubId: %v", err, payloadSeqNum)
Anssi Mannila2e99e2f2019-12-05 13:57:06 +0200282 return
283 }
Anssi Mannila2e99e2f2019-12-05 13:57:06 +0200284
Anssi Mannila8046c702020-01-02 13:39:05 +0200285 if responseReceived == true {
286 // Subscription timer already received
287 return
Anssi Mannila2e99e2f2019-12-05 13:57:06 +0200288 }
Anssi Mannila8046c702020-01-02 13:39:05 +0200289 xapp.Logger.Info("SubFail: SubId: %v, from address: %v:%v. Forwarding response to xApp", payloadSeqNum, transaction.Xappkey.Addr, transaction.Xappkey.Port)
Anssi Mannila2e99e2f2019-12-05 13:57:06 +0200290
291 time.Sleep(3 * time.Second)
292
Juha Hyttinenc65f5b02019-12-30 14:24:04 +0200293 xapp.Logger.Info("SubFail: Starting routing manager update. SubId: %v, Xid: %s", params.SubId, params.Xid)
Juha Hyttinen379ff082019-12-30 15:49:41 +0200294 subRouteAction := transaction.SubRouteInfo()
Juha Hyttinenc65f5b02019-12-30 14:24:04 +0200295 err = c.rtmgrClient.SubscriptionRequestUpdate(subRouteAction)
296 if err != nil {
297 xapp.Logger.Error("SubFail: Failed to update routing manager. Err: %v, SubId: %v, Xid: %s", err, params.SubId, params.Xid)
Anssi Mannila90fa0212019-12-12 10:47:47 +0200298 }
Anssi Mannila2e99e2f2019-12-05 13:57:06 +0200299
Anssi Mannilaf1d0eb62019-12-17 15:29:55 +0200300 xapp.Logger.Info("SubFail: Deleting transaction record. SubId: %v, Xid: %s", params.SubId, params.Xid)
Anssi Mannila2e99e2f2019-12-05 13:57:06 +0200301 if c.registry.releaseSequenceNumber(payloadSeqNum) {
Anssi Mannila8046c702020-01-02 13:39:05 +0200302 _, err = c.tracker.completeTransaction(payloadSeqNum, CREATE)
Anssi Mannila2e99e2f2019-12-05 13:57:06 +0200303 if err != nil {
Anssi Mannila26c922a2019-12-17 11:18:08 +0200304 xapp.Logger.Error("SubFail: Failed to delete transaction record. Err: %v, SubId: %v, Xid: %s", err, params.SubId, params.Xid)
Anssi Mannila2e99e2f2019-12-05 13:57:06 +0200305 return
306 }
Anssi Mannila90fa0212019-12-12 10:47:47 +0200307 } else {
Anssi Mannila26c922a2019-12-17 11:18:08 +0200308 xapp.Logger.Error("SubFail: Failed to release sequency number. SubId: %v, Xid: %s", params.SubId, params.Xid)
Anssi Mannila90fa0212019-12-12 10:47:47 +0200309 return
Anssi Mannila2e99e2f2019-12-05 13:57:06 +0200310 }
311 return
312}
313
Anssi Mannila8046c702020-01-02 13:39:05 +0200314func (c *Control) handleSubscriptionRequestTimer(strId string, nbrId int, tryCount uint64) {
315 subId := uint16(nbrId)
316 xapp.Logger.Info("handleSubTimer: SubReq timer expired. subId: %v, tryCount: %v", subId, tryCount)
Anssi Mannilaf1d0eb62019-12-17 15:29:55 +0200317
Anssi Mannila8046c702020-01-02 13:39:05 +0200318 transaction, responseReceived, err := c.tracker.CheckResponseReceived(subId, CREATE)
Anssi Mannila2e99e2f2019-12-05 13:57:06 +0200319 if err != nil {
Anssi Mannila8046c702020-01-02 13:39:05 +0200320 xapp.Logger.Info("handleSubTimer: Dropping this timer action. Err: %v SubId: %v", err, subId)
Anssi Mannilaf1d0eb62019-12-17 15:29:55 +0200321 return
322 }
Anssi Mannila2e99e2f2019-12-05 13:57:06 +0200323
Anssi Mannila8046c702020-01-02 13:39:05 +0200324 if responseReceived == true {
325 // Subscription Response or Failure already received
326 return
327 }
328
329 if tryCount < maxSubReqTryCount {
330 xapp.Logger.Info("handleSubTimer: Resending SubReq to E2T: Mtype: %v, SubId: %v, Xid %s, Meid %v", transaction.OrigParams.Mtype, transaction.OrigParams.SubId, transaction.OrigParams.Xid, transaction.OrigParams.Meid)
331 // Set possible to handle new response for the subId
332 err = c.tracker.RetryTransaction(subId, CREATE)
Anssi Mannila2e99e2f2019-12-05 13:57:06 +0200333 if err != nil {
Anssi Mannila8046c702020-01-02 13:39:05 +0200334 xapp.Logger.Error("handleSubDelTimer: Failed to retry transaction record. Dropping timer action. Err %v, SubId: %v", err, transaction.OrigParams.SubId)
Anssi Mannila2e99e2f2019-12-05 13:57:06 +0200335 return
336 }
Anssi Mannila8046c702020-01-02 13:39:05 +0200337
338 err = c.rmrSend(transaction.OrigParams)
339 if err != nil {
340 xapp.Logger.Error("handleSubTimer: Failed to send request to E2T %v, SubId: %v, Xid: %s", err, transaction.OrigParams.SubId, transaction.OrigParams.Xid)
341 }
342
343 tryCount++
344 c.timerMap.StartTimer("RIC_SUB_REQ", int(subId), subReqTime, tryCount, c.handleSubscriptionRequestTimer)
345 return
Anssi Mannila2e99e2f2019-12-05 13:57:06 +0200346 }
Anssi Mannila8046c702020-01-02 13:39:05 +0200347
348 var subDelReqPayload []byte
349 subDelReqPayload, err = c.e2ap.PackSubscriptionDeleteRequest(transaction.OrigParams.Payload, subId)
350 if err != nil {
351 xapp.Logger.Error("handleSubTimer: Packing SubDelReq failed. Err: %v", err)
352 return
353 }
354
355 // Cancel failed subscription
356 var params xapp.RMRParams
357 params.Mtype = 12020 // RIC SUBSCRIPTION DELETE
358 params.SubId = int(subId)
359 params.Xid = transaction.OrigParams.Xid
360 params.Meid = transaction.OrigParams.Meid
361 params.Src = transaction.OrigParams.Src
362 params.PayloadLen = len(subDelReqPayload)
363 params.Payload = subDelReqPayload
364 params.Mbuf = nil
365
366 // Delete CREATE transaction
367 _, err = c.tracker.completeTransaction(subId, CREATE)
368 if err != nil {
369 xapp.Logger.Error("handleSubTimer: Failed to delete create transaction record. Dropping this timer action. Err: %v, SubId: %v, Xid: %s", err, subId, params.Xid)
370 return
371 }
372
373 // Create DELETE transaction
374 var forwardRespToXapp bool = false
375 _, err = c.trackDeleteTransaction(&params, subId, forwardRespToXapp)
376 if err != nil {
377 xapp.Logger.Error("handleSubTimer: Failed to create delete transaction record. Dropping this timer action. Err: %v, SubId: %v, Xid: %s", err, subId, params.Xid)
378 return
379 }
380
381 xapp.Logger.Info("handleSubTimer: Sending SubDelReq to E2T: Mtype: %v, SubId: %v, Meid: %v", params.Mtype, params.SubId, params.Meid)
382 c.rmrSend(&params)
383 if err != nil {
384 xapp.Logger.Error("handleSubTimer: Failed to send request to E2T %v. SubId: %v, Xid: %s", err, params.SubId, params.Xid)
385 }
386 c.timerMap.StartTimer("RIC_SUB_DEL_REQ", int(subId), subDelReqTime, FirstTry, c.handleSubscriptionDeleteRequestTimer)
kalnagy93cc3e22019-09-19 11:29:29 +0200387 return
388}
389
390func (act Action) String() string {
391 actions := [...]string{
392 "CREATE",
393 "MERGE",
Anssi Mannila90fa0212019-12-12 10:47:47 +0200394 "NONE",
kalnagy93cc3e22019-09-19 11:29:29 +0200395 "DELETE",
396 }
397
398 if act < CREATE || act > DELETE {
399 return "Unknown"
400 }
401 return actions[act]
402}
403
404func (act Action) valid() bool {
405 switch act {
406 case CREATE, MERGE, DELETE:
407 return true
408 default:
409 return false
410 }
411}
412
Anssi Mannila90fa0212019-12-12 10:47:47 +0200413func (c *Control) handleSubscriptionDeleteRequest(params *xapp.RMRParams) {
Juha Hyttinenff8dccd2019-12-10 14:34:07 +0200414 xapp.Logger.Info("SubDelReq received from Src: %s, Mtype: %v, SubId: %v, Xid: %s, Meid: %v", params.Src, params.Mtype, params.SubId, params.Xid, params.Meid)
Anssi Mannila2e99e2f2019-12-05 13:57:06 +0200415 xapp.Rmr.Free(params.Mbuf)
416 params.Mbuf = nil
417
kalnagy1455c852019-10-21 13:06:23 +0200418 payloadSeqNum, err := c.e2ap.GetSubscriptionDeleteRequestSequenceNumber(params.Payload)
kalnagy93cc3e22019-09-19 11:29:29 +0200419 if err != nil {
Anssi Mannila8046c702020-01-02 13:39:05 +0200420 xapp.Logger.Error("SubDelReq: Unable to get Sequence Number from Payload. Dropping this msg. Err: %v, SubId: %v, Xid: %s, Payload %X", err, params.SubId, params.Xid, params.Payload)
kalnagy93cc3e22019-09-19 11:29:29 +0200421 return
422 }
Anssi Mannila26c922a2019-12-17 11:18:08 +0200423 xapp.Logger.Info("SubDelReq: Received payloadSeqNum: %v", payloadSeqNum)
424
kalnagy1455c852019-10-21 13:06:23 +0200425 if c.registry.IsValidSequenceNumber(payloadSeqNum) {
Anssi Mannila8046c702020-01-02 13:39:05 +0200426 var forwardRespToXapp bool = true
427 _, err = c.trackDeleteTransaction(params, payloadSeqNum, forwardRespToXapp)
Anssi Mannila90fa0212019-12-12 10:47:47 +0200428 if err != nil {
Anssi Mannila26c922a2019-12-17 11:18:08 +0200429 xapp.Logger.Error("SubDelReq: Failed to create transaction record. Dropping this msg. Err: %v, SubId: %v, Xid: %s", err, params.SubId, params.Xid)
Anssi Mannila90fa0212019-12-12 10:47:47 +0200430 return
kalnagye0018682019-09-26 16:28:25 +0200431 }
Juha Hyttinen47b842b2020-01-08 13:01:52 +0200432 c.registry.setSubscriptionToUnConfirmed(payloadSeqNum)
Anssi Mannila90fa0212019-12-12 10:47:47 +0200433 } else {
Anssi Mannila26c922a2019-12-17 11:18:08 +0200434 xapp.Logger.Error("SubDelReq: Not valid sequence number. Dropping this msg. SubId: %v, Xid: %s", params.SubId, params.Xid)
Anssi Mannila90fa0212019-12-12 10:47:47 +0200435 return
kalnagy93cc3e22019-09-19 11:29:29 +0200436 }
Juha Hyttinenff8dccd2019-12-10 14:34:07 +0200437
438 xapp.Logger.Info("SubDelReq: Forwarding Request to E2T. Mtype: %v, SubId: %v, Xid: %s, Meid: %v", params.Mtype, params.SubId, params.Xid, params.Meid)
kalnagy93cc3e22019-09-19 11:29:29 +0200439 c.rmrSend(params)
Anssi Mannila2e99e2f2019-12-05 13:57:06 +0200440 if err != nil {
Anssi Mannila26c922a2019-12-17 11:18:08 +0200441 xapp.Logger.Error("SubDelReq: Failed to send request to E2T. Err %v, SubId: %v, Xid: %s", err, params.SubId, params.Xid)
Anssi Mannilaf1d0eb62019-12-17 15:29:55 +0200442 }
Anssi Mannila8046c702020-01-02 13:39:05 +0200443 c.timerMap.StartTimer("RIC_SUB_DEL_REQ", int(payloadSeqNum), subDelReqTime, FirstTry, c.handleSubscriptionDeleteRequestTimer)
Peter Szilagyifbc56f92019-07-23 19:29:46 +0000444 return
445}
kalnagye0018682019-09-26 16:28:25 +0200446
Anssi Mannila8046c702020-01-02 13:39:05 +0200447func (c *Control) trackDeleteTransaction(params *xapp.RMRParams, payloadSeqNum uint16, forwardRespToXapp bool) (transaction *Transaction, err error) {
kalnagy1455c852019-10-21 13:06:23 +0200448 srcAddr, srcPort, err := c.rtmgrClient.SplitSource(params.Src)
449 if err != nil {
Anssi Mannila8046c702020-01-02 13:39:05 +0200450 xapp.Logger.Error("Failed to split source address. Err: %s, SubId: %v, Xid: %s", err, payloadSeqNum, params.Xid)
kalnagy1455c852019-10-21 13:06:23 +0200451 }
Anssi Mannila8046c702020-01-02 13:39:05 +0200452 var respReceived bool = false
453 transaction, err = c.tracker.TrackTransaction(payloadSeqNum, DELETE, *srcAddr, *srcPort, params, respReceived, forwardRespToXapp)
kalnagye0018682019-09-26 16:28:25 +0200454 return
455}
456
457func (c *Control) handleSubscriptionDeleteResponse(params *xapp.RMRParams) (err error) {
Juha Hyttinenff8dccd2019-12-10 14:34:07 +0200458 xapp.Logger.Info("SubDelResp received from Src: %s, Mtype: %v, SubId: %v, Meid: %v", params.Src, params.Mtype, params.SubId, params.Meid)
Anssi Mannila2e99e2f2019-12-05 13:57:06 +0200459 xapp.Rmr.Free(params.Mbuf)
460 params.Mbuf = nil
461
kalnagy1455c852019-10-21 13:06:23 +0200462 payloadSeqNum, err := c.e2ap.GetSubscriptionDeleteResponseSequenceNumber(params.Payload)
kalnagye0018682019-09-26 16:28:25 +0200463 if err != nil {
Anssi Mannila8046c702020-01-02 13:39:05 +0200464 xapp.Logger.Error("SubDelResp: Unable to get Sequence Number from Payload. Dropping this msg. Err: %v, SubId: %v, Xid: %s, Payload %X", err, params.SubId, params.Xid, params.Payload)
kalnagye0018682019-09-26 16:28:25 +0200465 return
466 }
Anssi Mannila26c922a2019-12-17 11:18:08 +0200467 xapp.Logger.Info("SubDelResp: Received payloadSeqNum: %v", payloadSeqNum)
kalnagye0018682019-09-26 16:28:25 +0200468
Anssi Mannilaf1d0eb62019-12-17 15:29:55 +0200469 c.timerMap.StopTimer("RIC_SUB_DEL_REQ", int(payloadSeqNum))
470
Anssi Mannila8046c702020-01-02 13:39:05 +0200471 transaction, responseReceived, err := c.tracker.CheckResponseReceived(payloadSeqNum, DELETE)
Juha Hyttinenff8dccd2019-12-10 14:34:07 +0200472 if err != nil {
Anssi Mannila8046c702020-01-02 13:39:05 +0200473 xapp.Logger.Info("SubDelResp: Dropping this msg. Err: %v SubId: %v", err, payloadSeqNum)
Anssi Mannila2e99e2f2019-12-05 13:57:06 +0200474 return
475 }
Anssi Mannila2e99e2f2019-12-05 13:57:06 +0200476
Anssi Mannila8046c702020-01-02 13:39:05 +0200477 if responseReceived == true {
478 // Subscription Delete timer already received
479 return
Anssi Mannila2e99e2f2019-12-05 13:57:06 +0200480 }
Anssi Mannila8046c702020-01-02 13:39:05 +0200481 xapp.Logger.Info("SubDelResp: SubId: %v, from address: %v:%v. Forwarding response to xApp", payloadSeqNum, transaction.Xappkey.Addr, transaction.Xappkey.Port)
Anssi Mannila2e99e2f2019-12-05 13:57:06 +0200482
Anssi Mannila8046c702020-01-02 13:39:05 +0200483 if transaction.ForwardRespToXapp == true {
484 params.SubId = int(payloadSeqNum)
485 params.Xid = transaction.OrigParams.Xid
486 xapp.Logger.Info("Forwarding SubDelResp to xApp: Mtype: %v, SubId: %v, Xid: %v, Meid: %v", params.Mtype, params.SubId, params.Xid, params.Meid)
487 err = c.rmrReplyToSender(params)
488 if err != nil {
489 xapp.Logger.Error("SubDelResp: Failed to send response to xApp. Err: %v, SubId: %v, Xid: %s", err, params.SubId, params.Xid)
490 }
491
492 time.Sleep(3 * time.Second)
493 }
Anssi Mannila2e99e2f2019-12-05 13:57:06 +0200494
Juha Hyttinenc65f5b02019-12-30 14:24:04 +0200495 xapp.Logger.Info("SubDelResp: Starting routing manager update. SubId: %v, Xid: %s", params.SubId, params.Xid)
Juha Hyttinen379ff082019-12-30 15:49:41 +0200496 subRouteAction := SubRouteInfo{DELETE, transaction.Xappkey.Addr, transaction.Xappkey.Port, payloadSeqNum}
Juha Hyttinenc65f5b02019-12-30 14:24:04 +0200497 err = c.rtmgrClient.SubscriptionRequestUpdate(subRouteAction)
498 if err != nil {
499 xapp.Logger.Error("SubDelResp: Failed to update routing manager. Err: %v, SubId: %v, Xid: %s", err, params.SubId, params.Xid)
500 return
Anssi Mannila90fa0212019-12-12 10:47:47 +0200501 }
Anssi Mannila2e99e2f2019-12-05 13:57:06 +0200502
Anssi Mannilaf1d0eb62019-12-17 15:29:55 +0200503 xapp.Logger.Info("SubDelResp: Deleting transaction record. SubId: %v, Xid: %s", params.SubId, params.Xid)
kalnagy1455c852019-10-21 13:06:23 +0200504 if c.registry.releaseSequenceNumber(payloadSeqNum) {
Anssi Mannila8046c702020-01-02 13:39:05 +0200505 _, err = c.tracker.completeTransaction(payloadSeqNum, DELETE)
kalnagye0018682019-09-26 16:28:25 +0200506 if err != nil {
Anssi Mannila26c922a2019-12-17 11:18:08 +0200507 xapp.Logger.Error("SubDelResp: Failed to delete transaction record. Err: %v, SubId: %v, Xid: %s", err, params.SubId, params.Xid)
kalnagye0018682019-09-26 16:28:25 +0200508 return
509 }
Anssi Mannila90fa0212019-12-12 10:47:47 +0200510 } else {
Anssi Mannila26c922a2019-12-17 11:18:08 +0200511 xapp.Logger.Error("SubDelResp: Failed to release sequency number. SubId: %v, Xid: %s", params.SubId, params.Xid)
Anssi Mannila90fa0212019-12-12 10:47:47 +0200512 return
kalnagye0018682019-09-26 16:28:25 +0200513 }
514 return
515}
Anssi Mannila2e99e2f2019-12-05 13:57:06 +0200516
Anssi Mannila90fa0212019-12-12 10:47:47 +0200517func (c *Control) handleSubscriptionDeleteFailure(params *xapp.RMRParams) {
Juha Hyttinenff8dccd2019-12-10 14:34:07 +0200518 xapp.Logger.Info("SubDelFail received from Src: %s, Mtype: %v, SubId: %v, Meid: %v", params.Src, params.Mtype, params.SubId, params.Meid)
Anssi Mannila2e99e2f2019-12-05 13:57:06 +0200519 xapp.Rmr.Free(params.Mbuf)
520 params.Mbuf = nil
521
522 payloadSeqNum, err := c.e2ap.GetSubscriptionDeleteFailureSequenceNumber(params.Payload)
523 if err != nil {
Anssi Mannila8046c702020-01-02 13:39:05 +0200524 xapp.Logger.Error("SubDelFail: Unable to get Sequence Number from Payload. Dropping this msg. Err: %v, SubId: %v, Xid: %s, Payload %X", err, params.SubId, params.Xid, params.Payload)
Anssi Mannila2e99e2f2019-12-05 13:57:06 +0200525 return
526 }
Anssi Mannila26c922a2019-12-17 11:18:08 +0200527 xapp.Logger.Info("SubDelFail: Received payloadSeqNum: %v", payloadSeqNum)
Anssi Mannila2e99e2f2019-12-05 13:57:06 +0200528
Anssi Mannilaf1d0eb62019-12-17 15:29:55 +0200529 c.timerMap.StopTimer("RIC_SUB_DEL_REQ", int(payloadSeqNum))
Anssi Mannila2e99e2f2019-12-05 13:57:06 +0200530
Anssi Mannila8046c702020-01-02 13:39:05 +0200531 transaction, responseReceived, err := c.tracker.CheckResponseReceived(payloadSeqNum, DELETE)
Juha Hyttinenff8dccd2019-12-10 14:34:07 +0200532 if err != nil {
Anssi Mannila8046c702020-01-02 13:39:05 +0200533 xapp.Logger.Info("SubDelFail: Dropping this msg. Err: %v SubId: %v", err, payloadSeqNum)
Anssi Mannila2e99e2f2019-12-05 13:57:06 +0200534 return
535 }
Anssi Mannila2e99e2f2019-12-05 13:57:06 +0200536
Anssi Mannila8046c702020-01-02 13:39:05 +0200537 if responseReceived == true {
538 // Subscription Delete timer already received
539 return
Anssi Mannila2e99e2f2019-12-05 13:57:06 +0200540 }
Anssi Mannila8046c702020-01-02 13:39:05 +0200541 xapp.Logger.Info("SubDelFail: SubId: %v, from address: %v:%v. Forwarding response to xApp", payloadSeqNum, transaction.Xappkey.Addr, transaction.Xappkey.Port)
Anssi Mannila2e99e2f2019-12-05 13:57:06 +0200542
Anssi Mannila8046c702020-01-02 13:39:05 +0200543 if transaction.ForwardRespToXapp == true {
544 var subDelRespPayload []byte
545 subDelRespPayload, err = c.e2ap.PackSubscriptionDeleteResponse(transaction.OrigParams.Payload, payloadSeqNum)
546 if err != nil {
547 xapp.Logger.Error("SubDelFail:Packing SubDelResp failed. Err: %v", err)
548 return
549 }
550
551 params.Mtype = 12021 // RIC SUBSCRIPTION DELETE RESPONSE
552 params.SubId = int(payloadSeqNum)
553 params.Xid = transaction.OrigParams.Xid
554 params.Meid = transaction.OrigParams.Meid
555 params.Src = transaction.OrigParams.Src
556 params.PayloadLen = len(subDelRespPayload)
557 params.Payload = subDelRespPayload
558 params.Mbuf = nil
559 xapp.Logger.Info("SubDelFail: Forwarding SubDelFail to xApp: Mtype: %v, SubId: %v, Xid: %v, Meid: %v", params.Mtype, params.SubId, params.Xid, params.Meid)
560 err = c.rmrReplyToSender(params)
561 if err != nil {
562 xapp.Logger.Error("SubDelFail: Failed to send SubDelFail to xApp. Err: %v, SubId: %v, Xid: %s", err, params.SubId, params.Xid)
563 }
564
565 time.Sleep(3 * time.Second)
566 }
Anssi Mannila2e99e2f2019-12-05 13:57:06 +0200567
Juha Hyttinenc65f5b02019-12-30 14:24:04 +0200568 xapp.Logger.Info("SubDelFail: Starting routing manager update. SubId: %v, Xid: %s", params.SubId, params.Xid)
Juha Hyttinen379ff082019-12-30 15:49:41 +0200569 subRouteAction := SubRouteInfo{DELETE, transaction.Xappkey.Addr, transaction.Xappkey.Port, payloadSeqNum}
Anssi Mannila8046c702020-01-02 13:39:05 +0200570 err = c.rtmgrClient.SubscriptionRequestUpdate(subRouteAction)
Juha Hyttinenc65f5b02019-12-30 14:24:04 +0200571 if err != nil {
572 xapp.Logger.Error("SubDelFail: Failed to update routing manager. Err: %v, SubId: %v, Xid: %s", err, params.SubId, params.Xid)
573 return
Anssi Mannila90fa0212019-12-12 10:47:47 +0200574 }
Anssi Mannila2e99e2f2019-12-05 13:57:06 +0200575
Anssi Mannilaf1d0eb62019-12-17 15:29:55 +0200576 xapp.Logger.Info("SubDelFail: Deleting transaction record. SubId: %v, Xid: %s", params.SubId, params.Xid)
Anssi Mannila2e99e2f2019-12-05 13:57:06 +0200577 if c.registry.releaseSequenceNumber(payloadSeqNum) {
Anssi Mannila8046c702020-01-02 13:39:05 +0200578 _, err = c.tracker.completeTransaction(payloadSeqNum, DELETE)
Anssi Mannila2e99e2f2019-12-05 13:57:06 +0200579 if err != nil {
Anssi Mannila26c922a2019-12-17 11:18:08 +0200580 xapp.Logger.Error("SubDelFail: Failed to delete transaction record. Err: %v, SubId: %v, Xid: %s", err, params.SubId, params.Xid)
Anssi Mannila2e99e2f2019-12-05 13:57:06 +0200581 return
582 }
Anssi Mannila90fa0212019-12-12 10:47:47 +0200583 } else {
Juha Hyttinenff8dccd2019-12-10 14:34:07 +0200584 xapp.Logger.Error("SubDelFail: Failed to release sequency number. Err: %v, SubId: %v, Xid: %s", err, params.SubId, params.Xid)
Anssi Mannila90fa0212019-12-12 10:47:47 +0200585 return
Anssi Mannila2e99e2f2019-12-05 13:57:06 +0200586 }
587 return
588}
589
Anssi Mannila8046c702020-01-02 13:39:05 +0200590func (c *Control) handleSubscriptionDeleteRequestTimer(strId string, nbrId int, tryCount uint64) {
591 subId := uint16(nbrId)
592 xapp.Logger.Info("handleSubDelTimer: SubDelReq timer expired. subId: %v, tryCount: %v", subId, tryCount)
Anssi Mannilaf1d0eb62019-12-17 15:29:55 +0200593
Anssi Mannila8046c702020-01-02 13:39:05 +0200594 transaction, responseReceived, err := c.tracker.CheckResponseReceived(subId, DELETE)
Anssi Mannila2e99e2f2019-12-05 13:57:06 +0200595 if err != nil {
Anssi Mannila8046c702020-01-02 13:39:05 +0200596 xapp.Logger.Info("handleSubTimer: Dropping this timer action. Err: %v SubId: %v", err, subId)
Anssi Mannila2e99e2f2019-12-05 13:57:06 +0200597 return
598 }
Anssi Mannila2e99e2f2019-12-05 13:57:06 +0200599
Anssi Mannila8046c702020-01-02 13:39:05 +0200600 if responseReceived == true {
601 // Subscription Delete Response or Failure already received
602 return
Anssi Mannila2e99e2f2019-12-05 13:57:06 +0200603 }
Juha Hyttinenff8dccd2019-12-10 14:34:07 +0200604
Anssi Mannila8046c702020-01-02 13:39:05 +0200605 if tryCount < maxSubDelReqTryCount {
606 xapp.Logger.Info("handleSubDelTimer: Resending SubDelReq to E2T: Mtype: %v, SubId: %v, Xid %s, Meid %v", transaction.OrigParams.Mtype, transaction.OrigParams.SubId, transaction.OrigParams.Xid, transaction.OrigParams.Meid)
607 // Set possible to handle new response for the subId
608 err = c.tracker.RetryTransaction(subId, DELETE)
609 if err != nil {
610 xapp.Logger.Error("handleSubDelTimer: Failed to retry transaction record. Dropping timer action. Err %v, SubId: %v", err, transaction.OrigParams.SubId)
611 return
612 }
Juha Hyttinenff8dccd2019-12-10 14:34:07 +0200613
Anssi Mannila8046c702020-01-02 13:39:05 +0200614 err = c.rmrSend(transaction.OrigParams)
615 if err != nil {
616 xapp.Logger.Error("handleSubDelTimer: Failed to send request to E2T %v, SubId: %v, Xid: %s", err, transaction.OrigParams.SubId, transaction.OrigParams.Xid)
617 }
Anssi Mannila2e99e2f2019-12-05 13:57:06 +0200618
Anssi Mannila8046c702020-01-02 13:39:05 +0200619 tryCount++
620 c.timerMap.StartTimer("RIC_SUB_DEL_REQ", int(subId), subReqTime, tryCount, c.handleSubscriptionDeleteRequestTimer)
621 return
622 }
623
624 var params xapp.RMRParams
625 if transaction.ForwardRespToXapp == true {
626 var subDelRespPayload []byte
627 subDelRespPayload, err = c.e2ap.PackSubscriptionDeleteResponse(transaction.OrigParams.Payload, subId)
628 if err != nil {
629 xapp.Logger.Error("handleSubDelTimer: Unable to pack payload. Dropping this timer action. Err: %v, SubId: %v, Xid: %s, Payload %x", err, subId, transaction.OrigParams.Xid, transaction.OrigParams.Payload)
630 return
631 }
632
633 params.Mtype = 12021 // RIC SUBSCRIPTION DELETE RESPONSE
634 params.SubId = int(subId)
635 params.Meid = transaction.OrigParams.Meid
636 params.Xid = transaction.OrigParams.Xid
637 params.Src = transaction.OrigParams.Src
638 params.PayloadLen = len(subDelRespPayload)
639 params.Payload = subDelRespPayload
640 params.Mbuf = nil
641
642 xapp.Logger.Info("handleSubDelTimer: Sending SubDelResp to xApp: Mtype: %v, SubId: %v, Xid: %s, Meid: %v", params.Mtype, params.SubId, params.Xid, params.Meid)
643 err = c.rmrReplyToSender(&params)
644 if err != nil {
645 xapp.Logger.Error("handleSubDelTimer: Failed to send response to xApp: Err: %v, SubId: %v, Xid: %s", err, params.SubId, params.Xid)
646 }
647
648 time.Sleep(3 * time.Second)
649 }
650
651 xapp.Logger.Info("handleSubDelTimer: Starting routing manager update. SubId: %v, Xid: %s", subId, params.Xid)
Juha Hyttinen379ff082019-12-30 15:49:41 +0200652 subRouteAction := SubRouteInfo{DELETE, transaction.Xappkey.Addr, transaction.Xappkey.Port, subId}
Anssi Mannilaf1d0eb62019-12-17 15:29:55 +0200653 err = c.rtmgrClient.SubscriptionRequestUpdate(subRouteAction)
654 if err != nil {
Anssi Mannila8046c702020-01-02 13:39:05 +0200655 xapp.Logger.Error("handleSubDelTimer: Failed to update routing manager. Err: %v, SubId: %v, Xid: %s", err, subId, params.Xid)
Anssi Mannilaf1d0eb62019-12-17 15:29:55 +0200656 return
657 }
Anssi Mannila2e99e2f2019-12-05 13:57:06 +0200658
Anssi Mannila8046c702020-01-02 13:39:05 +0200659 xapp.Logger.Info("handleSubDelTimer: Deleting transaction record. SubId: %v, Xid: %s", subId, params.Xid)
Anssi Mannilaf1d0eb62019-12-17 15:29:55 +0200660 if c.registry.releaseSequenceNumber(subId) {
Anssi Mannila8046c702020-01-02 13:39:05 +0200661 _, err = c.tracker.completeTransaction(subId, DELETE)
Anssi Mannila2e99e2f2019-12-05 13:57:06 +0200662 if err != nil {
Anssi Mannila8046c702020-01-02 13:39:05 +0200663 xapp.Logger.Error("handleSubDelTimer: Failed to delete transaction record. Err: %v, SubId: %v, Xid: %s", err, subId, params.Xid)
Anssi Mannila2e99e2f2019-12-05 13:57:06 +0200664 return
665 }
Anssi Mannilaf1d0eb62019-12-17 15:29:55 +0200666 } else {
Anssi Mannila8046c702020-01-02 13:39:05 +0200667 xapp.Logger.Error("handleSubDelTimer: Failed to release sequency number. SubId: %v, Xid: %s", subId, params.Xid)
Anssi Mannila2e99e2f2019-12-05 13:57:06 +0200668 }
Anssi Mannila2e99e2f2019-12-05 13:57:06 +0200669 return
Anssi Mannilaf1d0eb62019-12-17 15:29:55 +0200670}