blob: 7e2d673b4c92a50d7cdcff7a283bf9aeb0142f03 [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 "C"
23
kalnagy45114752019-06-18 14:40:39 +020024import (
Peter Szilagyifbc56f92019-07-23 19:29:46 +000025 "errors"
kalnagy93cc3e22019-09-19 11:29:29 +020026 rtmgrclient "gerrit.o-ran-sc.org/r/ric-plt/submgr/pkg/rtmgr_client"
27 rtmgrhandle "gerrit.o-ran-sc.org/r/ric-plt/submgr/pkg/rtmgr_client/handle"
kalnagy1455c852019-10-21 13:06:23 +020028 "gerrit.o-ran-sc.org/r/ric-plt/xapp-frame/pkg/xapp"
29 httptransport "github.com/go-openapi/runtime/client"
30 "github.com/go-openapi/strfmt"
31 "github.com/spf13/viper"
Peter Szilagyifbc56f92019-07-23 19:29:46 +000032 "math/rand"
33 "strconv"
34 "time"
Anssi Mannila2e99e2f2019-12-05 13:57:06 +020035 "sync"
kalnagy45114752019-06-18 14:40:39 +020036)
37
Anssi Mannila2e99e2f2019-12-05 13:57:06 +020038var rmrSendMutex = &sync.Mutex{}
39
40var subReqTime time.Duration = 2 * time.Second
41var SubDelReqTime time.Duration = 2 * time.Second
42
kalnagy45114752019-06-18 14:40:39 +020043type Control struct {
kalnagy93cc3e22019-09-19 11:29:29 +020044 e2ap *E2ap
45 registry *Registry
46 rtmgrClient *RtmgrClient
47 tracker *Tracker
kalnagy1455c852019-10-21 13:06:23 +020048 rcChan chan *xapp.RMRParams
Anssi Mannila2e99e2f2019-12-05 13:57:06 +020049 timerMap *TimerMap
kalnagy93cc3e22019-09-19 11:29:29 +020050}
51
52type RMRMeid struct {
53 PlmnID string
54 EnbID string
Anssi Mannila2e99e2f2019-12-05 13:57:06 +020055 RanName string
kalnagy93cc3e22019-09-19 11:29:29 +020056}
57
kalnagy1455c852019-10-21 13:06:23 +020058var seedSN uint16
kalnagy93cc3e22019-09-19 11:29:29 +020059
60const (
61 CREATE Action = 0
kalnagy1455c852019-10-21 13:06:23 +020062 MERGE Action = 1
kalnagy93cc3e22019-09-19 11:29:29 +020063 DELETE Action = 3
64)
Peter Szilagyifbc56f92019-07-23 19:29:46 +000065
66func init() {
Anssi Mannila2e99e2f2019-12-05 13:57:06 +020067 xapp.Logger.Info("SUBMGR /ric-plt-submgr:r3-test-v2")
Peter Szilagyifbc56f92019-07-23 19:29:46 +000068 viper.AutomaticEnv()
69 viper.SetEnvPrefix("submgr")
70 viper.AllowEmptyEnv(true)
kalnagy1455c852019-10-21 13:06:23 +020071 seedSN = uint16(viper.GetInt("seed_sn"))
72 if seedSN == 0 {
Peter Szilagyifbc56f92019-07-23 19:29:46 +000073 rand.Seed(time.Now().UnixNano())
kalnagy1455c852019-10-21 13:06:23 +020074 seedSN = uint16(rand.Intn(65535))
Peter Szilagyifbc56f92019-07-23 19:29:46 +000075 }
kalnagy1455c852019-10-21 13:06:23 +020076 if seedSN > 65535 {
77 seedSN = 0
Peter Szilagyifbc56f92019-07-23 19:29:46 +000078 }
kalnagy1455c852019-10-21 13:06:23 +020079 xapp.Logger.Info("SUBMGR: Initial Sequence Number: %v", seedSN)
kalnagy45114752019-06-18 14:40:39 +020080}
81
82func NewControl() Control {
Peter Szilagyifbc56f92019-07-23 19:29:46 +000083 registry := new(Registry)
kalnagy1455c852019-10-21 13:06:23 +020084 registry.Initialize(seedSN)
kalnagy93cc3e22019-09-19 11:29:29 +020085
Balint Uvegese9608cd2019-09-20 18:00:32 +000086 tracker := new(Tracker)
87 tracker.Init()
88
Anssi Mannila2e99e2f2019-12-05 13:57:06 +020089 timerMap := new(TimerMap)
90 timerMap.Init()
91
kalnagy1455c852019-10-21 13:06:23 +020092 transport := httptransport.New(viper.GetString("rtmgr.HostAddr")+":"+viper.GetString("rtmgr.port"), viper.GetString("rtmgr.baseUrl"), []string{"http"})
kalnagy93cc3e22019-09-19 11:29:29 +020093 client := rtmgrclient.New(transport, strfmt.Default)
94 handle := rtmgrhandle.NewProvideXappSubscriptionHandleParamsWithTimeout(10 * time.Second)
kalnagy1455c852019-10-21 13:06:23 +020095 deleteHandle := rtmgrhandle.NewDeleteXappSubscriptionHandleParamsWithTimeout(10 * time.Second)
96 rtmgrClient := RtmgrClient{client, handle, deleteHandle}
kalnagy93cc3e22019-09-19 11:29:29 +020097
Anssi Mannila2e99e2f2019-12-05 13:57:06 +020098 return Control{new(E2ap), registry, &rtmgrClient, tracker, make(chan *xapp.RMRParams),timerMap}
kalnagy45114752019-06-18 14:40:39 +020099}
100
101func (c *Control) Run() {
Balint Uvegescd3881b2019-10-02 15:01:43 +0000102 go c.controlLoop()
Peter Szilagyifbc56f92019-07-23 19:29:46 +0000103 xapp.Run(c)
kalnagy45114752019-06-18 14:40:39 +0200104}
105
kalnagy93cc3e22019-09-19 11:29:29 +0200106func (c *Control) Consume(rp *xapp.RMRParams) (err error) {
kalnagy1455c852019-10-21 13:06:23 +0200107 c.rcChan <- rp
Peter Szilagyifbc56f92019-07-23 19:29:46 +0000108 return
kalnagy45114752019-06-18 14:40:39 +0200109}
110
kalnagy93cc3e22019-09-19 11:29:29 +0200111func (c *Control) rmrSend(params *xapp.RMRParams) (err error) {
Anssi Mannila2e99e2f2019-12-05 13:57:06 +0200112 status := false
113 i := 1
114 rmrSendMutex.Lock()
115 for ; i <= 10 && status == false; i++ {
116 status = xapp.Rmr.Send(params, false)
117 if status == false {
118 xapp.Logger.Info("rmr.Send() failed. Retry count %v, Mtype: %v, SubId: %v, Xid %s",i, params.Mtype, params.SubId, params.Xid)
119 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 }
126 rmrSendMutex.Unlock()
127
128 /*
kalnagy93cc3e22019-09-19 11:29:29 +0200129 if !xapp.Rmr.Send(params, false) {
Peter Szilagyifbc56f92019-07-23 19:29:46 +0000130 err = errors.New("rmr.Send() failed")
Anssi Mannila2e99e2f2019-12-05 13:57:06 +0200131 xapp.Rmr.Free(params.Mbuf)
Peter Szilagyifbc56f92019-07-23 19:29:46 +0000132 }
Anssi Mannila2e99e2f2019-12-05 13:57:06 +0200133 */
Peter Szilagyifbc56f92019-07-23 19:29:46 +0000134 return
kalnagy45114752019-06-18 14:40:39 +0200135}
136
kalnagye0018682019-09-26 16:28:25 +0200137func (c *Control) rmrReplyToSender(params *xapp.RMRParams) (err error) {
Anssi Mannila2e99e2f2019-12-05 13:57:06 +0200138 c.rmrSend(params)
kalnagye0018682019-09-26 16:28:25 +0200139 return
140}
141
Balint Uvegescd3881b2019-10-02 15:01:43 +0000142func (c *Control) controlLoop() {
143 for {
kalnagy1455c852019-10-21 13:06:23 +0200144 msg := <-c.rcChan
Balint Uvegescd3881b2019-10-02 15:01:43 +0000145 switch msg.Mtype {
kalnagy1455c852019-10-21 13:06:23 +0200146 case xapp.RICMessageTypes["RIC_SUB_REQ"]:
Anssi Mannila2e99e2f2019-12-05 13:57:06 +0200147 go c.handleSubscriptionRequest(msg)
kalnagy1455c852019-10-21 13:06:23 +0200148 case xapp.RICMessageTypes["RIC_SUB_RESP"]:
Anssi Mannila2e99e2f2019-12-05 13:57:06 +0200149 go c.handleSubscriptionResponse(msg)
150 case xapp.RICMessageTypes["RIC_SUB_FAILURE"]:
151 go c.handleSubscriptionFailure(msg)
kalnagy1455c852019-10-21 13:06:23 +0200152 case xapp.RICMessageTypes["RIC_SUB_DEL_REQ"]:
Anssi Mannila2e99e2f2019-12-05 13:57:06 +0200153 go c.handleSubscriptionDeleteRequest(msg)
kalnagy1455c852019-10-21 13:06:23 +0200154 case xapp.RICMessageTypes["RIC_SUB_DEL_RESP"]:
Anssi Mannila2e99e2f2019-12-05 13:57:06 +0200155 go c.handleSubscriptionDeleteResponse(msg)
kalnagy1455c852019-10-21 13:06:23 +0200156 default:
157 err := errors.New("Message Type " + strconv.Itoa(msg.Mtype) + " is discarded")
158 xapp.Logger.Error("Unknown message type: %v", err)
Balint Uvegescd3881b2019-10-02 15:01:43 +0000159 }
160 }
161}
162
kalnagy93cc3e22019-09-19 11:29:29 +0200163func (c *Control) handleSubscriptionRequest(params *xapp.RMRParams) (err error) {
Anssi Mannila2e99e2f2019-12-05 13:57:06 +0200164 xapp.Logger.Info("Subscription Request Received from Src: %s, Mtype: %v, SubId: %v, Xid: %s, Meid: %v",params.Src, params.Mtype, params.SubId, params.Xid, params.Meid)
165 xapp.Rmr.Free(params.Mbuf)
166 params.Mbuf = nil
kalnagy93cc3e22019-09-19 11:29:29 +0200167
168 /* Reserve a sequence number and set it in the payload */
Anssi Mannila2e99e2f2019-12-05 13:57:06 +0200169 newSubId, isIdValid := c.registry.ReserveSequenceNumber()
170 if isIdValid != true {
171 xapp.Logger.Info("Further processing of this SubscriptionRequest stopped. SubId: %v, Xid: %s",params.SubId, params.Xid)
172 return
173 }
kalnagy93cc3e22019-09-19 11:29:29 +0200174
Anssi Mannila0a9f2602019-12-09 15:26:44 +0200175 err = c.e2ap.SetSubscriptionRequestSequenceNumber(params.Payload, newSubId)
Peter Szilagyifbc56f92019-07-23 19:29:46 +0000176 if err != nil {
177 err = errors.New("Unable to set Subscription Sequence Number in Payload due to: " + err.Error())
178 return
179 }
kalnagy93cc3e22019-09-19 11:29:29 +0200180
kalnagy1455c852019-10-21 13:06:23 +0200181 srcAddr, srcPort, err := c.rtmgrClient.SplitSource(params.Src)
kalnagy93cc3e22019-09-19 11:29:29 +0200182 if err != nil {
183 xapp.Logger.Error("Failed to update routing-manager about the subscription request with reason: %s", err)
184 return
185 }
186
187 /* Create transatcion records for every subscription request */
kalnagy1455c852019-10-21 13:06:23 +0200188 xactKey := TransactionKey{newSubId, CREATE}
189 xactValue := Transaction{*srcAddr, *srcPort, params}
190 err = c.tracker.TrackTransaction(xactKey, xactValue)
kalnagy93cc3e22019-09-19 11:29:29 +0200191 if err != nil {
kalnagy1455c852019-10-21 13:06:23 +0200192 xapp.Logger.Error("Failed to create a Subscription Request transaction record due to %v", err)
kalnagy93cc3e22019-09-19 11:29:29 +0200193 return
194 }
195
196 /* Update routing manager about the new subscription*/
kalnagy1455c852019-10-21 13:06:23 +0200197 subRouteAction := SubRouteInfo{CREATE, *srcAddr, *srcPort, newSubId}
Anssi Mannila2e99e2f2019-12-05 13:57:06 +0200198 xapp.Logger.Info("Starting routing manager update")
199 c.rtmgrClient.SubscriptionRequestUpdate(subRouteAction)
200
201 //time.Sleep(3 * time.Second)
kalnagy93cc3e22019-09-19 11:29:29 +0200202
203 // Setting new subscription ID in the RMR header
kalnagy1455c852019-10-21 13:06:23 +0200204 params.SubId = int(newSubId)
Anssi Mannila2e99e2f2019-12-05 13:57:06 +0200205 xapp.Logger.Info("Forwarding Subscription Request to E2T: Mtype: %v, SubId: %v, Xid %s, Meid %v",params.Mtype, params.SubId, params.Xid, params.Meid)
206 err = c.rmrSend(params)
207 if err != nil {
208 xapp.Logger.Error("Failed to send request to E2T %v. SubId: %v, Xid: %s", err, params.SubId, params.Xid)
209 } /*else {
210 c.timerMap.StartTimer(newSubId, subReqTime, c.handleSubscriptionRequestTimer)
211 }*/
kalnagy1455c852019-10-21 13:06:23 +0200212 xapp.Logger.Debug("--- Debugging transaction table = %v", c.tracker.transactionTable)
Peter Szilagyifbc56f92019-07-23 19:29:46 +0000213 return
kalnagy45114752019-06-18 14:40:39 +0200214}
215
kalnagy93cc3e22019-09-19 11:29:29 +0200216func (c *Control) handleSubscriptionResponse(params *xapp.RMRParams) (err error) {
Anssi Mannila0a9f2602019-12-09 15:26:44 +0200217 xapp.Logger.Info("Subscription Response 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 +0200218 xapp.Rmr.Free(params.Mbuf)
219 params.Mbuf = nil
220
kalnagy1455c852019-10-21 13:06:23 +0200221 payloadSeqNum, err := c.e2ap.GetSubscriptionResponseSequenceNumber(params.Payload)
Peter Szilagyifbc56f92019-07-23 19:29:46 +0000222 if err != nil {
223 err = errors.New("Unable to get Subscription Sequence Number from Payload due to: " + err.Error())
224 return
225 }
Anssi Mannila2e99e2f2019-12-05 13:57:06 +0200226
227 xapp.Logger.Info("Received payloadSeqNum: %v",payloadSeqNum)
kalnagy1455c852019-10-21 13:06:23 +0200228 if !c.registry.IsValidSequenceNumber(payloadSeqNum) {
229 err = errors.New("Unknown Subscription ID: " + strconv.Itoa(int(payloadSeqNum)) + " in Subscritpion Response. Message discarded.")
Peter Szilagyifbc56f92019-07-23 19:29:46 +0000230 return
231 }
Anssi Mannila2e99e2f2019-12-05 13:57:06 +0200232
233// c.timerMap.StopTimer(payloadSeqNum)
234
kalnagy1455c852019-10-21 13:06:23 +0200235 c.registry.setSubscriptionToConfirmed(payloadSeqNum)
Anssi Mannila2e99e2f2019-12-05 13:57:06 +0200236 var transaction Transaction
237 transaction, err = c.tracker.RetriveTransaction(payloadSeqNum, CREATE)
238 if err != nil {
239 xapp.Logger.Error("Failed to retrive transaction record. Err: %v", err)
240 xapp.Logger.Info("Further processing of this Subscription Response stopped. SubId: %v, Xid: %s",params.SubId, params.Xid)
241 return
242 }
243 xapp.Logger.Info("Subscription ID: %v, from address: %v:%v. Retrieved old subId...", int(payloadSeqNum), transaction.XappInstanceAddress, transaction.XappPort)
244
245 params.SubId = int(payloadSeqNum)
246 params.Xid = transaction.OrigParams.Xid
247
248 xapp.Logger.Info("Forwarding Subscription Response to UEEC: Mtype: %v, SubId: %v, Xid: %s, Meid: %v",params.Mtype, params.SubId, params.Xid, params.Meid)
249 err = c.rmrReplyToSender(params)
250 if err != nil {
251 xapp.Logger.Error("Failed to send response to requestor %v. SubId: %v, Xid: %s", err, params.SubId, params.Xid)
252 }
253
254 xapp.Logger.Info("Subscription ID: %v, from address: %v:%v. Deleting transaction record", int(payloadSeqNum), transaction.XappInstanceAddress, transaction.XappPort)
255 transaction, err = c.tracker.completeTransaction(payloadSeqNum, CREATE)
kalnagye0018682019-09-26 16:28:25 +0200256 if err != nil {
kalnagy1455c852019-10-21 13:06:23 +0200257 xapp.Logger.Error("Failed to delete a Subscription Request transaction record due to %v", err)
kalnagye0018682019-09-26 16:28:25 +0200258 return
259 }
Anssi Mannila2e99e2f2019-12-05 13:57:06 +0200260 return
261}
262
263func (c *Control) handleSubscriptionFailure(params *xapp.RMRParams) (err error) {
264 xapp.Logger.Info("Subscription Failure Received from Src: %s, Mtype: %v, SubId: %v, Meid: %v",params.Src, params.Mtype, params.SubId, params.Meid)
265 xapp.Rmr.Free(params.Mbuf)
266 params.Mbuf = nil
267
268 payloadSeqNum, err := c.e2ap.GetSubscriptionFailureSequenceNumber(params.Payload)
269 if err != nil {
270 err = errors.New("Unable to get Subscription Sequence Number from Payload due to: " + err.Error())
271 return
272 }
273 xapp.Logger.Info("Received payloadSeqNum: %v", payloadSeqNum)
274
275 // should here be IsValidSequenceNumber check?
276
277// c.timerMap.StopTimer(payloadSeqNum)
278
279 var transaction Transaction
280 transaction, err = c.tracker.RetriveTransaction(payloadSeqNum, CREATE)
281 if err != nil {
282 xapp.Logger.Error("Failed to retrive transaction record. Err %v", err)
283 xapp.Logger.Info("Further processing of this Subscription Failure stopped. SubId: %v, Xid: %s",params.SubId, params.Xid)
284 return
285 }
286 xapp.Logger.Info("Subscription ID: %v, from address: %v:%v. Forwarding response to requestor...", int(payloadSeqNum), transaction.XappInstanceAddress, transaction.XappPort)
287
288 params.SubId = int(payloadSeqNum)
289 params.Xid = transaction.OrigParams.Xid
290
291 xapp.Logger.Info("Forwarding Subscription Failure to UEEC: Mtype: %v, SubId: %v, Xid: %v, Meid: %v",params.Mtype, params.SubId, params.Xid, params.Meid)
292 err = c.rmrReplyToSender(params)
293 if err != nil {
294 xapp.Logger.Error("Failed to send response to requestor %v. SubId: %v, Xid: %s", err, params.SubId, params.Xid)
295 }
296
297 time.Sleep(3 * time.Second)
298
299 xapp.Logger.Info("Starting routing manager update")
Anssi Mannila0a9f2602019-12-09 15:26:44 +0200300 subRouteAction := SubRouteInfo{CREATE, transaction.XappInstanceAddress, transaction.XappPort, payloadSeqNum}
Anssi Mannila2e99e2f2019-12-05 13:57:06 +0200301 c.rtmgrClient.SubscriptionRequestUpdate(subRouteAction)
302
303 xapp.Logger.Info("Deleting trancaction record")
304 if c.registry.releaseSequenceNumber(payloadSeqNum) {
305 transaction, err = c.tracker.completeTransaction(payloadSeqNum, CREATE)
306 if err != nil {
307 xapp.Logger.Error("Failed to delete a Subscription Request transaction record due to %v", err)
308 return
309 }
310 }
311 return
312}
313
314func (c *Control) handleSubscriptionRequestTimer(subId uint16) {
315 xapp.Logger.Info("Subscription Request timer expired. SubId: %v",subId)
316/*
317 transaction, err := c.tracker.completeTransaction(subId, CREATE)
318 if err != nil {
319 xapp.Logger.Error("Failed to delete a Subscription Request transaction record due to %v", err)
320 return
321 }
322 xapp.Logger.Info("SubId: %v, Xid %v, Meid: %v",subId, transaction.OrigParams.Xid, transaction.OrigParams.Meid)
323
324 var params xapp.RMRParams
325 params.Mtype = 12012 //xapp.RICMessageTypes["RIC_SUB_FAILURE"]
326 params.SubId = int(subId)
327 params.Meid = transaction.OrigParams.Meid
328 params.Xid = transaction.OrigParams.Xid
329 payload := []byte("40C9408098000003EA7E00050000010016EA6300020021EA6E00808180EA6F000400000000EA6F000400010040EA6F000400020080EA6F0004000300C0EA6F000400040100EA6F000400050140EA6F000400060180EA6F0004000701C0EA6F000400080200EA6F000400090240EA6F0004000A0280EA6F0004000B02C0EA6F0004000C0300EA6F0004000D0340EA6F0004000E0380EA6F0004000F03C0")
330 params.PayloadLen = len(payload)
331 params.Payload = payload
332
333 xapp.Logger.Info("Forwarding Subscription Failure to UEEC: Mtype: %v, SubId: %v, Xid: %s, Meid: %v",params.Mtype, params.SubId, params.Xid, params.Meid)
334 err = c.rmrReplyToSender(&params)
335 if err != nil {
336 xapp.Logger.Error("Failed to send response to requestor %v. SubId: %v, Xid: %s", err, params.SubId, params.Xid)
337 }
338*/
339/*
340 time.Sleep(3 * time.Second)
341
342 xapp.Logger.Info("Subscription ID: %v, from address: %v:%v. Deleting transaction record", int(subId), transaction.XappInstanceAddress, transaction.XappPort)
343
344 xapp.Logger.Info("Starting routing manager update")
345 subRouteAction := SubRouteInfo{DELETE, transaction.XappInstanceAddress, transaction.XappPort, payloadSeqNum}
346 c.rtmgrClient.SubscriptionRequestUpdate(subRouteAction)
347
348 xapp.Logger.Info("Deleting trancaction record")
349 if c.registry.releaseSequenceNumber(payloadSeqNum) {
350 transaction, err = c.tracker.completeTransaction(payloadSeqNum, CREATE)
351 if err != nil {
352 xapp.Logger.Error("Failed to delete a Subscription Request transaction record due to %v", err)
353 return
354 }
355 }
356*/
kalnagy93cc3e22019-09-19 11:29:29 +0200357 return
358}
359
360func (act Action) String() string {
361 actions := [...]string{
362 "CREATE",
363 "MERGE",
364 "DELETE",
365 }
366
367 if act < CREATE || act > DELETE {
368 return "Unknown"
369 }
370 return actions[act]
371}
372
373func (act Action) valid() bool {
374 switch act {
375 case CREATE, MERGE, DELETE:
376 return true
377 default:
378 return false
379 }
380}
381
382func (c *Control) handleSubscriptionDeleteRequest(params *xapp.RMRParams) (err error) {
Anssi Mannila2e99e2f2019-12-05 13:57:06 +0200383 xapp.Logger.Info("Subscription Delete Request Received from Src: %s, Mtype: %v, SubId: %v, Xid: %s, Meid: %v",params.Src, params.Mtype, params.SubId, params.Xid, params.Meid)
384 xapp.Rmr.Free(params.Mbuf)
385 params.Mbuf = nil
386
kalnagy1455c852019-10-21 13:06:23 +0200387 payloadSeqNum, err := c.e2ap.GetSubscriptionDeleteRequestSequenceNumber(params.Payload)
kalnagy93cc3e22019-09-19 11:29:29 +0200388 if err != nil {
389 err = errors.New("Unable to get Subscription Sequence Number from Payload due to: " + err.Error())
390 return
391 }
Anssi Mannila2e99e2f2019-12-05 13:57:06 +0200392 xapp.Logger.Info("Received payloadSeqNum: %v", payloadSeqNum)
kalnagy1455c852019-10-21 13:06:23 +0200393 if c.registry.IsValidSequenceNumber(payloadSeqNum) {
394 c.registry.deleteSubscription(payloadSeqNum)
395 trackErr := c.trackDeleteTransaction(params, payloadSeqNum)
kalnagye0018682019-09-26 16:28:25 +0200396 if trackErr != nil {
kalnagy1455c852019-10-21 13:06:23 +0200397 xapp.Logger.Error("Failed to create a Subscription Delete Request transaction record due to %v", trackErr)
kalnagye0018682019-09-26 16:28:25 +0200398 return trackErr
399 }
kalnagy93cc3e22019-09-19 11:29:29 +0200400 }
Anssi Mannila2e99e2f2019-12-05 13:57:06 +0200401
402 xapp.Logger.Info("Forwarding Delete Subscription 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 +0200403 c.rmrSend(params)
Anssi Mannila2e99e2f2019-12-05 13:57:06 +0200404 if err != nil {
405 xapp.Logger.Error("Failed to send request to E2T %v. SubId: %v, Xid: %s", err, params.SubId, params.Xid)
406 } /*else {
407 c.timerMap.StartTimer(payloadSeqNum, SubDelReqTime, c.handleSubscriptionDeleteRequestTimer)
408 }*/
Peter Szilagyifbc56f92019-07-23 19:29:46 +0000409 return
410}
kalnagye0018682019-09-26 16:28:25 +0200411
kalnagy1455c852019-10-21 13:06:23 +0200412func (c *Control) trackDeleteTransaction(params *xapp.RMRParams, payloadSeqNum uint16) (err error) {
413 srcAddr, srcPort, err := c.rtmgrClient.SplitSource(params.Src)
414 if err != nil {
415 xapp.Logger.Error("Failed to update routing-manager about the subscription delete request with reason: %s", err)
416 }
417 xactKey := TransactionKey{payloadSeqNum, DELETE}
418 xactValue := Transaction{*srcAddr, *srcPort, params}
419 err = c.tracker.TrackTransaction(xactKey, xactValue)
kalnagye0018682019-09-26 16:28:25 +0200420 return
421}
422
423func (c *Control) handleSubscriptionDeleteResponse(params *xapp.RMRParams) (err error) {
Anssi Mannila2e99e2f2019-12-05 13:57:06 +0200424 xapp.Logger.Info("Subscription Delete Response Received from Src: %s, Mtype: %v, SubId: %v, Meid: %v",params.Src, params.Mtype, params.SubId, params.Meid)
425 xapp.Rmr.Free(params.Mbuf)
426 params.Mbuf = nil
427
kalnagy1455c852019-10-21 13:06:23 +0200428 payloadSeqNum, err := c.e2ap.GetSubscriptionDeleteResponseSequenceNumber(params.Payload)
kalnagye0018682019-09-26 16:28:25 +0200429 if err != nil {
430 err = errors.New("Unable to get Subscription Sequence Number from Payload due to: " + err.Error())
431 return
432 }
Anssi Mannila2e99e2f2019-12-05 13:57:06 +0200433 xapp.Logger.Info("Received payloadSeqNum: %v", payloadSeqNum)
kalnagye0018682019-09-26 16:28:25 +0200434
Anssi Mannila2e99e2f2019-12-05 13:57:06 +0200435 // should here be IsValidSequenceNumber check?
436// c.timerMap.StopTimer(payloadSeqNum)
437
438 var transaction Transaction
439 transaction, err = c.tracker.RetriveTransaction(payloadSeqNum, DELETE)
440 if err != nil {
441 xapp.Logger.Error("Failed to retrive transaction record. Err %v", err)
442 xapp.Logger.Info("Further processing of this Subscription Delete Response stopped. SubId: %v, Xid: %s",params.SubId, params.Xid)
443 return
444 }
445 xapp.Logger.Info("Subscription ID: %v, from address: %v:%v. Forwarding response to requestor...", int(payloadSeqNum), transaction.XappInstanceAddress, transaction.XappPort)
446
447 params.SubId = int(payloadSeqNum)
448 params.Xid = transaction.OrigParams.Xid
449 xapp.Logger.Info("Forwarding Subscription Delete Response to UEEC: Mtype: %v, SubId: %v, Xid: %v, Meid: %v",params.Mtype, params.SubId, params.Xid, params.Meid)
450 err = c.rmrReplyToSender(params)
451 if err != nil {
452 xapp.Logger.Error("Failed to send response to requestor %v. SubId: %v, Xid: %s", err, params.SubId, params.Xid)
453// return
454 }
455
456 time.Sleep(3 * time.Second)
457
458 xapp.Logger.Info("Starting routing manager update")
459 subRouteAction := SubRouteInfo{DELETE, transaction.XappInstanceAddress, transaction.XappPort, payloadSeqNum}
460 c.rtmgrClient.SubscriptionRequestUpdate(subRouteAction)
461
462 xapp.Logger.Info("Deleting trancaction record")
kalnagy1455c852019-10-21 13:06:23 +0200463 if c.registry.releaseSequenceNumber(payloadSeqNum) {
464 transaction, err = c.tracker.completeTransaction(payloadSeqNum, DELETE)
kalnagye0018682019-09-26 16:28:25 +0200465 if err != nil {
kalnagy1455c852019-10-21 13:06:23 +0200466 xapp.Logger.Error("Failed to delete a Subscription Delete Request transaction record due to %v", err)
kalnagye0018682019-09-26 16:28:25 +0200467 return
468 }
kalnagye0018682019-09-26 16:28:25 +0200469 }
470 return
471}
Anssi Mannila2e99e2f2019-12-05 13:57:06 +0200472
473func (c *Control) handleSubscriptionDeleteFailure(params *xapp.RMRParams) (err error) {
474 xapp.Logger.Info("Subscription Delete Failure Received from Src: %s, Mtype: %v, SubId: %v, Meid: %v",params.Src, params.Mtype, params.SubId, params.Meid)
475 xapp.Rmr.Free(params.Mbuf)
476 params.Mbuf = nil
477
478 payloadSeqNum, err := c.e2ap.GetSubscriptionDeleteFailureSequenceNumber(params.Payload)
479 if err != nil {
480 err = errors.New("Unable to get Subscription Sequence Number from Payload due to: " + err.Error())
481 return
482 }
483 xapp.Logger.Info("Received payloadSeqNum: %v", payloadSeqNum)
484
485 // should here be IsValidSequenceNumber check?
486// c.timerMap.StopTimer(payloadSeqNum)
487
488 var transaction Transaction
489 transaction, err = c.tracker.RetriveTransaction(payloadSeqNum, DELETE)
490 if err != nil {
491 xapp.Logger.Error("Failed to retrive transaction record. Err %v", err)
492 xapp.Logger.Info("Further processing of this Subscription Delete Failure stopped. SubId: %v, Xid: %s",params.SubId, params.Xid)
493 return
494 }
495 xapp.Logger.Info("Subscription ID: %v, from address: %v:%v. Forwarding response to requestor...", int(payloadSeqNum), transaction.XappInstanceAddress, transaction.XappPort)
496
497 params.SubId = int(payloadSeqNum)
498 params.Xid = transaction.OrigParams.Xid
499 xapp.Logger.Info("Forwarding Subscription Delete Failure to UEEC: Mtype: %v, SubId: %v, Xid: %v, Meid: %v",params.Mtype, params.SubId, params.Xid, params.Meid)
500 err = c.rmrReplyToSender(params)
501 if err != nil {
502 xapp.Logger.Error("Failed to send response to requestor %v. SubId: %v, Xid: %s", err, params.SubId, params.Xid)
503// return
504 }
505
506 time.Sleep(3 * time.Second)
507
508 xapp.Logger.Info("Starting routing manager update")
509 subRouteAction := SubRouteInfo{DELETE, transaction.XappInstanceAddress, transaction.XappPort, payloadSeqNum}
510 c.rtmgrClient.SubscriptionRequestUpdate(subRouteAction)
511
512 xapp.Logger.Info("Deleting trancaction record")
513 if c.registry.releaseSequenceNumber(payloadSeqNum) {
514 transaction, err = c.tracker.completeTransaction(payloadSeqNum, DELETE)
515 if err != nil {
516 xapp.Logger.Error("Failed to delete a Subscription Delete Request transaction record due to %v", err)
517 return
518 }
519 }
520 return
521}
522
523func (c *Control) handleSubscriptionDeleteRequestTimer(subId uint16) {
524 xapp.Logger.Info("Subscription Delete Request timer expired. SubId: %v",subId)
525/*
526 transaction, err := c.tracker.completeTransaction(subId, DELETE)
527 if err != nil {
528 xapp.Logger.Error("Failed to delete a Subscription Delete Request transaction record due to %v", err)
529 return
530 }
531 xapp.Logger.Info("SubId: %v, Xid %v, Meid: %v",subId, transaction.OrigParams.Xid, transaction.OrigParams.Meid)
532
533 var params xapp.RMRParams
534 params.Mtype = 12022 //xapp.RICMessageTypes["RIC_SUB_DEL_FAILURE"]
535 params.SubId = int(subId)
536 params.Meid = transaction.OrigParams.Meid
537 params.Xid = transaction.OrigParams.Xid
538 payload := []byte("40CA4018000003EA7E00050000010016EA6300020021EA74000200C0")
539 params.PayloadLen = len(payload)
540 params.Payload = payload
541
542 xapp.Logger.Info("Forwarding Subscription Delete Failure to UEEC: Mtype: %v, SubId: %v, Xid: %s, Meid: %v",params.Mtype, params.SubId, params.Xid, params.Meid)
543 err = c.rmrReplyToSender(&params)
544 if err != nil {
545 xapp.Logger.Error("Failed to send response to requestor %v. SubId: %v, Xid: %s", err, params.SubId, params.Xid)
546 }
547*/
548/*
549 time.Sleep(3 * time.Second)
550 xapp.Logger.Info("Subscription ID: %v, from address: %v:%v. Deleting transaction record", int(subId), transaction.XappInstanceAddress, transaction.XappPort)
551
552 xapp.Logger.Info("Starting routing manager update")
553 subRouteAction := SubRouteInfo{DELETE, transaction.XappInstanceAddress, transaction.XappPort, payloadSeqNum}
554 c.rtmgrClient.SubscriptionRequestUpdate(subRouteAction)
555
556 xapp.Logger.Info("Deleting trancaction record")
557 if c.registry.releaseSequenceNumber(payloadSeqNum) {
558 transaction, err = c.tracker.completeTransaction(payloadSeqNum, DELETE)
559 if err != nil {
560 xapp.Logger.Error("Failed to delete a Subscription Delete Request transaction record due to %v", err)
561 return
562 }
563 }
564*/
565 return
566 }