kalnagy | 4511475 | 2019-06-18 14:40:39 +0200 | [diff] [blame] | 1 | /* |
| 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 | |
| 20 | package control |
| 21 | |
kalnagy | 4511475 | 2019-06-18 14:40:39 +0200 | [diff] [blame] | 22 | import ( |
Juha Hyttinen | e406a34 | 2020-01-13 13:02:26 +0200 | [diff] [blame] | 23 | "fmt" |
Juha Hyttinen | 86a4620 | 2020-01-14 12:49:09 +0200 | [diff] [blame] | 24 | "gerrit.o-ran-sc.org/r/ric-plt/e2ap/pkg/e2ap" |
kalnagy | 93cc3e2 | 2019-09-19 11:29:29 +0200 | [diff] [blame] | 25 | rtmgrclient "gerrit.o-ran-sc.org/r/ric-plt/submgr/pkg/rtmgr_client" |
Juha Hyttinen | 5f8ffa0 | 2020-02-06 15:28:59 +0200 | [diff] [blame] | 26 | "gerrit.o-ran-sc.org/r/ric-plt/submgr/pkg/xapptweaks" |
Juha Hyttinen | c9eb08a | 2020-02-28 08:53:33 +0200 | [diff] [blame] | 27 | "gerrit.o-ran-sc.org/r/ric-plt/xapp-frame/pkg/models" |
kalnagy | 1455c85 | 2019-10-21 13:06:23 +0200 | [diff] [blame] | 28 | "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 Szilagyi | fbc56f9 | 2019-07-23 19:29:46 +0000 | [diff] [blame] | 32 | "time" |
kalnagy | 4511475 | 2019-06-18 14:40:39 +0200 | [diff] [blame] | 33 | ) |
| 34 | |
Juha Hyttinen | e406a34 | 2020-01-13 13:02:26 +0200 | [diff] [blame] | 35 | //----------------------------------------------------------------------------- |
| 36 | // |
| 37 | //----------------------------------------------------------------------------- |
| 38 | |
Juha Hyttinen | 5f8ffa0 | 2020-02-06 15:28:59 +0200 | [diff] [blame] | 39 | func idstring(err error, entries ...fmt.Stringer) string { |
| 40 | var retval string = "" |
| 41 | var filler string = "" |
| 42 | for _, entry := range entries { |
| 43 | retval += filler + entry.String() |
| 44 | filler = " " |
| 45 | } |
| 46 | if err != nil { |
| 47 | retval += filler + "err(" + err.Error() + ")" |
| 48 | filler = " " |
| 49 | |
| 50 | } |
| 51 | return retval |
| 52 | } |
| 53 | |
| 54 | //----------------------------------------------------------------------------- |
| 55 | // |
| 56 | //----------------------------------------------------------------------------- |
| 57 | |
Juha Hyttinen | 422d018 | 2020-01-17 13:37:05 +0200 | [diff] [blame] | 58 | var e2tSubReqTimeout time.Duration = 5 * time.Second |
| 59 | var e2tSubDelReqTime time.Duration = 5 * time.Second |
| 60 | var e2tMaxSubReqTryCount uint64 = 2 // Initial try + retry |
| 61 | var e2tMaxSubDelReqTryCount uint64 = 2 // Initial try + retry |
| 62 | |
| 63 | var e2tRecvMsgTimeout time.Duration = 5 * time.Second |
Anssi Mannila | 2e99e2f | 2019-12-05 13:57:06 +0200 | [diff] [blame] | 64 | |
kalnagy | 4511475 | 2019-06-18 14:40:39 +0200 | [diff] [blame] | 65 | type Control struct { |
Juha Hyttinen | 5f8ffa0 | 2020-02-06 15:28:59 +0200 | [diff] [blame] | 66 | xapptweaks.XappWrapper |
| 67 | e2ap *E2ap |
| 68 | registry *Registry |
| 69 | tracker *Tracker |
Juha Hyttinen | c9eb08a | 2020-02-28 08:53:33 +0200 | [diff] [blame] | 70 | //subscriber *xapp.Subscriber |
kalnagy | 93cc3e2 | 2019-09-19 11:29:29 +0200 | [diff] [blame] | 71 | } |
| 72 | |
| 73 | type RMRMeid struct { |
Juha Hyttinen | ff8dccd | 2019-12-10 14:34:07 +0200 | [diff] [blame] | 74 | PlmnID string |
| 75 | EnbID string |
Anssi Mannila | 2e99e2f | 2019-12-05 13:57:06 +0200 | [diff] [blame] | 76 | RanName string |
kalnagy | 93cc3e2 | 2019-09-19 11:29:29 +0200 | [diff] [blame] | 77 | } |
| 78 | |
Peter Szilagyi | fbc56f9 | 2019-07-23 19:29:46 +0000 | [diff] [blame] | 79 | func init() { |
Anssi Mannila | 8046c70 | 2020-01-02 13:39:05 +0200 | [diff] [blame] | 80 | xapp.Logger.Info("SUBMGR") |
Peter Szilagyi | fbc56f9 | 2019-07-23 19:29:46 +0000 | [diff] [blame] | 81 | viper.AutomaticEnv() |
| 82 | viper.SetEnvPrefix("submgr") |
| 83 | viper.AllowEmptyEnv(true) |
kalnagy | 4511475 | 2019-06-18 14:40:39 +0200 | [diff] [blame] | 84 | } |
| 85 | |
Juha Hyttinen | ff8dccd | 2019-12-10 14:34:07 +0200 | [diff] [blame] | 86 | func NewControl() *Control { |
Juha Hyttinen | 0388dd9 | 2020-01-09 14:14:16 +0200 | [diff] [blame] | 87 | |
Juha Hyttinen | 56e0383 | 2020-01-14 17:08:43 +0200 | [diff] [blame] | 88 | transport := httptransport.New(viper.GetString("rtmgr.HostAddr")+":"+viper.GetString("rtmgr.port"), viper.GetString("rtmgr.baseUrl"), []string{"http"}) |
Juha Hyttinen | 12d31af | 2020-01-22 12:59:01 +0200 | [diff] [blame] | 89 | rtmgrClient := RtmgrClient{rtClient: rtmgrclient.New(transport, strfmt.Default)} |
Juha Hyttinen | 56e0383 | 2020-01-14 17:08:43 +0200 | [diff] [blame] | 90 | |
Peter Szilagyi | fbc56f9 | 2019-07-23 19:29:46 +0000 | [diff] [blame] | 91 | registry := new(Registry) |
Anssi Mannila | 5c161a9 | 2020-01-15 15:40:57 +0200 | [diff] [blame] | 92 | registry.Initialize() |
Juha Hyttinen | 56e0383 | 2020-01-14 17:08:43 +0200 | [diff] [blame] | 93 | registry.rtmgrClient = &rtmgrClient |
kalnagy | 93cc3e2 | 2019-09-19 11:29:29 +0200 | [diff] [blame] | 94 | |
Balint Uveges | e9608cd | 2019-09-20 18:00:32 +0000 | [diff] [blame] | 95 | tracker := new(Tracker) |
| 96 | tracker.Init() |
| 97 | |
Juha Hyttinen | c9eb08a | 2020-02-28 08:53:33 +0200 | [diff] [blame] | 98 | //subscriber := xapp.NewSubscriber(viper.GetString("subscription.host"), viper.GetInt("subscription.timeout")) |
Anssi Mannila | 2e99e2f | 2019-12-05 13:57:06 +0200 | [diff] [blame] | 99 | |
Juha Hyttinen | 5f8ffa0 | 2020-02-06 15:28:59 +0200 | [diff] [blame] | 100 | c := &Control{e2ap: new(E2ap), |
| 101 | registry: registry, |
| 102 | tracker: tracker, |
Juha Hyttinen | c9eb08a | 2020-02-28 08:53:33 +0200 | [diff] [blame] | 103 | //subscriber: subscriber, |
Juha Hyttinen | 5f8ffa0 | 2020-02-06 15:28:59 +0200 | [diff] [blame] | 104 | } |
| 105 | c.XappWrapper.Init("") |
Juha Hyttinen | c9eb08a | 2020-02-28 08:53:33 +0200 | [diff] [blame] | 106 | go xapp.Subscription.Listen(c.SubscriptionHandler, c.QueryHandler) |
| 107 | //go c.subscriber.Listen(c.SubscriptionHandler, c.QueryHandler) |
Juha Hyttinen | 5f8ffa0 | 2020-02-06 15:28:59 +0200 | [diff] [blame] | 108 | return c |
| 109 | } |
| 110 | |
| 111 | func (c *Control) ReadyCB(data interface{}) { |
| 112 | if c.Rmr == nil { |
| 113 | c.Rmr = xapp.Rmr |
Juha Hyttinen | ff8dccd | 2019-12-10 14:34:07 +0200 | [diff] [blame] | 114 | } |
kalnagy | 4511475 | 2019-06-18 14:40:39 +0200 | [diff] [blame] | 115 | } |
| 116 | |
| 117 | func (c *Control) Run() { |
Juha Hyttinen | 5f8ffa0 | 2020-02-06 15:28:59 +0200 | [diff] [blame] | 118 | xapp.SetReadyCB(c.ReadyCB, nil) |
Peter Szilagyi | fbc56f9 | 2019-07-23 19:29:46 +0000 | [diff] [blame] | 119 | xapp.Run(c) |
kalnagy | 4511475 | 2019-06-18 14:40:39 +0200 | [diff] [blame] | 120 | } |
| 121 | |
Juha Hyttinen | c9eb08a | 2020-02-28 08:53:33 +0200 | [diff] [blame] | 122 | //------------------------------------------------------------------- |
| 123 | // |
| 124 | //------------------------------------------------------------------- |
| 125 | func (c *Control) SubscriptionHandler(stype models.SubscriptionType, params interface{}) (models.SubscriptionResult, error) { |
| 126 | /* |
| 127 | switch p := params.(type) { |
| 128 | case *models.ReportParams: |
| 129 | trans := c.tracker.NewXappTransaction(NewRmrEndpoint(p.ClientEndpoint),"" , 0, &xapp.RMRMeid{RanName: p.Meid}) |
| 130 | if trans == nil { |
| 131 | xapp.Logger.Error("XAPP-SubReq: %s", idstring(fmt.Errorf("transaction not created"), params)) |
| 132 | return |
| 133 | } |
| 134 | defer trans.Release() |
| 135 | case *models.ControlParams: |
| 136 | case *models.PolicyParams: |
| 137 | } |
| 138 | */ |
| 139 | return models.SubscriptionResult{}, fmt.Errorf("Subscription rest interface not implemented") |
| 140 | } |
| 141 | |
| 142 | func (c *Control) QueryHandler() (models.SubscriptionList, error) { |
| 143 | return c.registry.QueryHandler() |
| 144 | } |
| 145 | |
| 146 | //------------------------------------------------------------------- |
| 147 | // |
| 148 | //------------------------------------------------------------------- |
| 149 | |
Juha Hyttinen | 83ada00 | 2020-01-30 10:36:33 +0200 | [diff] [blame] | 150 | func (c *Control) rmrSendToE2T(desc string, subs *Subscription, trans *TransactionSubs) (err error) { |
Juha Hyttinen | 5f8ffa0 | 2020-02-06 15:28:59 +0200 | [diff] [blame] | 151 | params := xapptweaks.NewParams(nil) |
Juha Hyttinen | e406a34 | 2020-01-13 13:02:26 +0200 | [diff] [blame] | 152 | params.Mtype = trans.GetMtype() |
Juha Hyttinen | 83ada00 | 2020-01-30 10:36:33 +0200 | [diff] [blame] | 153 | params.SubId = int(subs.GetReqId().Seq) |
Juha Hyttinen | 86a4620 | 2020-01-14 12:49:09 +0200 | [diff] [blame] | 154 | params.Xid = "" |
Juha Hyttinen | e406a34 | 2020-01-13 13:02:26 +0200 | [diff] [blame] | 155 | params.Meid = subs.GetMeid() |
| 156 | params.Src = "" |
Juha Hyttinen | 63284a2 | 2020-01-15 10:45:11 +0200 | [diff] [blame] | 157 | params.PayloadLen = len(trans.Payload.Buf) |
| 158 | params.Payload = trans.Payload.Buf |
Juha Hyttinen | e406a34 | 2020-01-13 13:02:26 +0200 | [diff] [blame] | 159 | params.Mbuf = nil |
Juha Hyttinen | 5f8ffa0 | 2020-02-06 15:28:59 +0200 | [diff] [blame] | 160 | xapp.Logger.Info("MSG to E2T: %s %s %s", desc, trans.String(), params.String()) |
Juha Hyttinen | d708a43 | 2020-03-09 09:37:06 +0200 | [diff] [blame^] | 161 | return c.RmrSend(params, 5) |
kalnagy | e001868 | 2019-09-26 16:28:25 +0200 | [diff] [blame] | 162 | } |
| 163 | |
Juha Hyttinen | 83ada00 | 2020-01-30 10:36:33 +0200 | [diff] [blame] | 164 | func (c *Control) rmrSendToXapp(desc string, subs *Subscription, trans *TransactionXapp) (err error) { |
| 165 | |
Juha Hyttinen | 5f8ffa0 | 2020-02-06 15:28:59 +0200 | [diff] [blame] | 166 | params := xapptweaks.NewParams(nil) |
Juha Hyttinen | 63284a2 | 2020-01-15 10:45:11 +0200 | [diff] [blame] | 167 | params.Mtype = trans.GetMtype() |
Juha Hyttinen | 83ada00 | 2020-01-30 10:36:33 +0200 | [diff] [blame] | 168 | params.SubId = int(subs.GetReqId().Seq) |
Juha Hyttinen | e406a34 | 2020-01-13 13:02:26 +0200 | [diff] [blame] | 169 | params.Xid = trans.GetXid() |
Juha Hyttinen | 86a4620 | 2020-01-14 12:49:09 +0200 | [diff] [blame] | 170 | params.Meid = trans.GetMeid() |
Juha Hyttinen | e406a34 | 2020-01-13 13:02:26 +0200 | [diff] [blame] | 171 | params.Src = "" |
Juha Hyttinen | 63284a2 | 2020-01-15 10:45:11 +0200 | [diff] [blame] | 172 | params.PayloadLen = len(trans.Payload.Buf) |
| 173 | params.Payload = trans.Payload.Buf |
Juha Hyttinen | e406a34 | 2020-01-13 13:02:26 +0200 | [diff] [blame] | 174 | params.Mbuf = nil |
Juha Hyttinen | 5f8ffa0 | 2020-02-06 15:28:59 +0200 | [diff] [blame] | 175 | xapp.Logger.Info("MSG to XAPP: %s %s %s", desc, trans.String(), params.String()) |
Juha Hyttinen | d708a43 | 2020-03-09 09:37:06 +0200 | [diff] [blame^] | 176 | return c.RmrSend(params, 5) |
Juha Hyttinen | e406a34 | 2020-01-13 13:02:26 +0200 | [diff] [blame] | 177 | } |
| 178 | |
| 179 | func (c *Control) Consume(params *xapp.RMRParams) (err error) { |
Juha Hyttinen | 5f8ffa0 | 2020-02-06 15:28:59 +0200 | [diff] [blame] | 180 | msg := xapptweaks.NewParams(params) |
| 181 | if c.Rmr == nil { |
| 182 | err = fmt.Errorf("Rmr object nil can handle %s", msg.String()) |
| 183 | xapp.Logger.Error("%s", err.Error()) |
| 184 | return |
| 185 | } |
| 186 | c.CntRecvMsg++ |
| 187 | |
| 188 | defer c.Rmr.Free(msg.Mbuf) |
Juha Hyttinen | 83ada00 | 2020-01-30 10:36:33 +0200 | [diff] [blame] | 189 | |
Anssi Mannila | 90fa021 | 2019-12-12 10:47:47 +0200 | [diff] [blame] | 190 | switch msg.Mtype { |
Juha Hyttinen | c9eb08a | 2020-02-28 08:53:33 +0200 | [diff] [blame] | 191 | case xapp.RIC_SUB_REQ: |
Juha Hyttinen | 422d018 | 2020-01-17 13:37:05 +0200 | [diff] [blame] | 192 | go c.handleXAPPSubscriptionRequest(msg) |
Juha Hyttinen | c9eb08a | 2020-02-28 08:53:33 +0200 | [diff] [blame] | 193 | case xapp.RIC_SUB_RESP: |
Juha Hyttinen | 422d018 | 2020-01-17 13:37:05 +0200 | [diff] [blame] | 194 | go c.handleE2TSubscriptionResponse(msg) |
Juha Hyttinen | c9eb08a | 2020-02-28 08:53:33 +0200 | [diff] [blame] | 195 | case xapp.RIC_SUB_FAILURE: |
Juha Hyttinen | 422d018 | 2020-01-17 13:37:05 +0200 | [diff] [blame] | 196 | go c.handleE2TSubscriptionFailure(msg) |
Juha Hyttinen | c9eb08a | 2020-02-28 08:53:33 +0200 | [diff] [blame] | 197 | case xapp.RIC_SUB_DEL_REQ: |
Juha Hyttinen | 422d018 | 2020-01-17 13:37:05 +0200 | [diff] [blame] | 198 | go c.handleXAPPSubscriptionDeleteRequest(msg) |
Juha Hyttinen | c9eb08a | 2020-02-28 08:53:33 +0200 | [diff] [blame] | 199 | case xapp.RIC_SUB_DEL_RESP: |
Juha Hyttinen | 422d018 | 2020-01-17 13:37:05 +0200 | [diff] [blame] | 200 | go c.handleE2TSubscriptionDeleteResponse(msg) |
Juha Hyttinen | c9eb08a | 2020-02-28 08:53:33 +0200 | [diff] [blame] | 201 | case xapp.RIC_SUB_DEL_FAILURE: |
Juha Hyttinen | 422d018 | 2020-01-17 13:37:05 +0200 | [diff] [blame] | 202 | go c.handleE2TSubscriptionDeleteFailure(msg) |
Anssi Mannila | 90fa021 | 2019-12-12 10:47:47 +0200 | [diff] [blame] | 203 | default: |
| 204 | xapp.Logger.Info("Unknown Message Type '%d', discarding", msg.Mtype) |
Balint Uveges | cd3881b | 2019-10-02 15:01:43 +0000 | [diff] [blame] | 205 | } |
Juha Hyttinen | 5f8ffa0 | 2020-02-06 15:28:59 +0200 | [diff] [blame] | 206 | return |
Juha Hyttinen | 31797b4 | 2020-01-16 14:05:01 +0200 | [diff] [blame] | 207 | } |
| 208 | |
Juha Hyttinen | 422d018 | 2020-01-17 13:37:05 +0200 | [diff] [blame] | 209 | //------------------------------------------------------------------- |
| 210 | // handle from XAPP Subscription Request |
| 211 | //------------------------------------------------------------------ |
Juha Hyttinen | 5f8ffa0 | 2020-02-06 15:28:59 +0200 | [diff] [blame] | 212 | func (c *Control) handleXAPPSubscriptionRequest(params *xapptweaks.RMRParams) { |
Juha Hyttinen | 83ada00 | 2020-01-30 10:36:33 +0200 | [diff] [blame] | 213 | xapp.Logger.Info("MSG from XAPP: %s", params.String()) |
Juha Hyttinen | 422d018 | 2020-01-17 13:37:05 +0200 | [diff] [blame] | 214 | |
| 215 | subReqMsg, err := c.e2ap.UnpackSubscriptionRequest(params.Payload) |
| 216 | if err != nil { |
Juha Hyttinen | 83ada00 | 2020-01-30 10:36:33 +0200 | [diff] [blame] | 217 | xapp.Logger.Error("XAPP-SubReq: %s", idstring(err, params)) |
Juha Hyttinen | 422d018 | 2020-01-17 13:37:05 +0200 | [diff] [blame] | 218 | return |
| 219 | } |
| 220 | |
Juha Hyttinen | 47942b4 | 2020-02-27 10:41:43 +0200 | [diff] [blame] | 221 | trans := c.tracker.NewXappTransaction(NewRmrEndpoint(params.Src), params.Xid, subReqMsg.RequestId.Seq, params.Meid) |
Juha Hyttinen | 83ada00 | 2020-01-30 10:36:33 +0200 | [diff] [blame] | 222 | if trans == nil { |
| 223 | xapp.Logger.Error("XAPP-SubReq: %s", idstring(fmt.Errorf("transaction not created"), params)) |
Juha Hyttinen | 422d018 | 2020-01-17 13:37:05 +0200 | [diff] [blame] | 224 | return |
| 225 | } |
| 226 | defer trans.Release() |
| 227 | |
Juha Hyttinen | 83ada00 | 2020-01-30 10:36:33 +0200 | [diff] [blame] | 228 | err = c.tracker.Track(trans) |
| 229 | if err != nil { |
| 230 | xapp.Logger.Error("XAPP-SubReq: %s", idstring(err, trans)) |
| 231 | return |
| 232 | } |
| 233 | |
Juha Hyttinen | 422d018 | 2020-01-17 13:37:05 +0200 | [diff] [blame] | 234 | subs, err := c.registry.AssignToSubscription(trans, subReqMsg) |
| 235 | if err != nil { |
Juha Hyttinen | 83ada00 | 2020-01-30 10:36:33 +0200 | [diff] [blame] | 236 | xapp.Logger.Error("XAPP-SubReq: %s", idstring(err, trans)) |
Juha Hyttinen | 422d018 | 2020-01-17 13:37:05 +0200 | [diff] [blame] | 237 | return |
| 238 | } |
| 239 | |
Juha Hyttinen | 422d018 | 2020-01-17 13:37:05 +0200 | [diff] [blame] | 240 | // |
| 241 | // Wake subs request |
| 242 | // |
| 243 | go c.handleSubscriptionCreate(subs, trans) |
| 244 | event, _ := trans.WaitEvent(0) //blocked wait as timeout is handled in subs side |
| 245 | |
| 246 | err = nil |
| 247 | if event != nil { |
| 248 | switch themsg := event.(type) { |
| 249 | case *e2ap.E2APSubscriptionResponse: |
| 250 | trans.Mtype, trans.Payload, err = c.e2ap.PackSubscriptionResponse(themsg) |
| 251 | if err == nil { |
Anssi Mannila | 64a0df4 | 2020-02-26 09:46:03 +0200 | [diff] [blame] | 252 | trans.Release() |
Juha Hyttinen | 83ada00 | 2020-01-30 10:36:33 +0200 | [diff] [blame] | 253 | c.rmrSendToXapp("", subs, trans) |
Juha Hyttinen | 422d018 | 2020-01-17 13:37:05 +0200 | [diff] [blame] | 254 | return |
| 255 | } |
| 256 | case *e2ap.E2APSubscriptionFailure: |
| 257 | trans.Mtype, trans.Payload, err = c.e2ap.PackSubscriptionFailure(themsg) |
| 258 | if err == nil { |
Juha Hyttinen | 83ada00 | 2020-01-30 10:36:33 +0200 | [diff] [blame] | 259 | c.rmrSendToXapp("", subs, trans) |
Juha Hyttinen | 422d018 | 2020-01-17 13:37:05 +0200 | [diff] [blame] | 260 | } |
Juha Hyttinen | 422d018 | 2020-01-17 13:37:05 +0200 | [diff] [blame] | 261 | default: |
Juha Hyttinen | 31797b4 | 2020-01-16 14:05:01 +0200 | [diff] [blame] | 262 | break |
| 263 | } |
| 264 | } |
Juha Hyttinen | 83ada00 | 2020-01-30 10:36:33 +0200 | [diff] [blame] | 265 | xapp.Logger.Info("XAPP-SubReq: failed %s", idstring(err, trans, subs)) |
Juha Hyttinen | f44377d | 2020-02-12 10:18:40 +0200 | [diff] [blame] | 266 | c.registry.RemoveFromSubscription(subs, trans, 5*time.Second) |
Juha Hyttinen | 31797b4 | 2020-01-16 14:05:01 +0200 | [diff] [blame] | 267 | } |
| 268 | |
Juha Hyttinen | 422d018 | 2020-01-17 13:37:05 +0200 | [diff] [blame] | 269 | //------------------------------------------------------------------- |
| 270 | // handle from XAPP Subscription Delete Request |
| 271 | //------------------------------------------------------------------ |
Juha Hyttinen | 5f8ffa0 | 2020-02-06 15:28:59 +0200 | [diff] [blame] | 272 | func (c *Control) handleXAPPSubscriptionDeleteRequest(params *xapptweaks.RMRParams) { |
Juha Hyttinen | 83ada00 | 2020-01-30 10:36:33 +0200 | [diff] [blame] | 273 | xapp.Logger.Info("MSG from XAPP: %s", params.String()) |
Juha Hyttinen | 422d018 | 2020-01-17 13:37:05 +0200 | [diff] [blame] | 274 | |
| 275 | subDelReqMsg, err := c.e2ap.UnpackSubscriptionDeleteRequest(params.Payload) |
Juha Hyttinen | 31797b4 | 2020-01-16 14:05:01 +0200 | [diff] [blame] | 276 | if err != nil { |
Juha Hyttinen | 83ada00 | 2020-01-30 10:36:33 +0200 | [diff] [blame] | 277 | xapp.Logger.Error("XAPP-SubDelReq %s", idstring(err, params)) |
Juha Hyttinen | 422d018 | 2020-01-17 13:37:05 +0200 | [diff] [blame] | 278 | return |
| 279 | } |
| 280 | |
Juha Hyttinen | 47942b4 | 2020-02-27 10:41:43 +0200 | [diff] [blame] | 281 | trans := c.tracker.NewXappTransaction(NewRmrEndpoint(params.Src), params.Xid, subDelReqMsg.RequestId.Seq, params.Meid) |
Juha Hyttinen | 83ada00 | 2020-01-30 10:36:33 +0200 | [diff] [blame] | 282 | if trans == nil { |
| 283 | xapp.Logger.Error("XAPP-SubDelReq: %s", idstring(fmt.Errorf("transaction not created"), params)) |
Juha Hyttinen | 422d018 | 2020-01-17 13:37:05 +0200 | [diff] [blame] | 284 | return |
| 285 | } |
| 286 | defer trans.Release() |
| 287 | |
Juha Hyttinen | 83ada00 | 2020-01-30 10:36:33 +0200 | [diff] [blame] | 288 | err = c.tracker.Track(trans) |
Juha Hyttinen | 422d018 | 2020-01-17 13:37:05 +0200 | [diff] [blame] | 289 | if err != nil { |
Juha Hyttinen | 83ada00 | 2020-01-30 10:36:33 +0200 | [diff] [blame] | 290 | xapp.Logger.Error("XAPP-SubReq: %s", idstring(err, trans)) |
| 291 | return |
| 292 | } |
| 293 | |
Juha Hyttinen | 47942b4 | 2020-02-27 10:41:43 +0200 | [diff] [blame] | 294 | subs, err := c.registry.GetSubscriptionFirstMatch([]uint32{trans.GetSubId()}) |
Juha Hyttinen | 83ada00 | 2020-01-30 10:36:33 +0200 | [diff] [blame] | 295 | if err != nil { |
| 296 | xapp.Logger.Error("XAPP-SubDelReq: %s", idstring(err, trans)) |
Juha Hyttinen | 422d018 | 2020-01-17 13:37:05 +0200 | [diff] [blame] | 297 | return |
| 298 | } |
| 299 | |
Juha Hyttinen | 422d018 | 2020-01-17 13:37:05 +0200 | [diff] [blame] | 300 | // |
| 301 | // Wake subs delete |
| 302 | // |
| 303 | go c.handleSubscriptionDelete(subs, trans) |
| 304 | trans.WaitEvent(0) //blocked wait as timeout is handled in subs side |
| 305 | |
Juha Hyttinen | 83ada00 | 2020-01-30 10:36:33 +0200 | [diff] [blame] | 306 | xapp.Logger.Debug("XAPP-SubDelReq: Handling event %s ", idstring(nil, trans, subs)) |
| 307 | |
Juha Hyttinen | 422d018 | 2020-01-17 13:37:05 +0200 | [diff] [blame] | 308 | // Whatever is received send ok delete response |
| 309 | subDelRespMsg := &e2ap.E2APSubscriptionDeleteResponse{} |
Juha Hyttinen | 47942b4 | 2020-02-27 10:41:43 +0200 | [diff] [blame] | 310 | subDelRespMsg.RequestId = subs.GetReqId().RequestId |
Juha Hyttinen | 422d018 | 2020-01-17 13:37:05 +0200 | [diff] [blame] | 311 | subDelRespMsg.FunctionId = subs.SubReqMsg.FunctionId |
| 312 | trans.Mtype, trans.Payload, err = c.e2ap.PackSubscriptionDeleteResponse(subDelRespMsg) |
| 313 | if err == nil { |
Juha Hyttinen | 83ada00 | 2020-01-30 10:36:33 +0200 | [diff] [blame] | 314 | c.rmrSendToXapp("", subs, trans) |
Juha Hyttinen | 422d018 | 2020-01-17 13:37:05 +0200 | [diff] [blame] | 315 | } |
Juha Hyttinen | 83ada00 | 2020-01-30 10:36:33 +0200 | [diff] [blame] | 316 | |
Juha Hyttinen | f44377d | 2020-02-12 10:18:40 +0200 | [diff] [blame] | 317 | c.registry.RemoveFromSubscription(subs, trans, 5*time.Second) |
Juha Hyttinen | 422d018 | 2020-01-17 13:37:05 +0200 | [diff] [blame] | 318 | } |
| 319 | |
| 320 | //------------------------------------------------------------------- |
| 321 | // SUBS CREATE Handling |
| 322 | //------------------------------------------------------------------- |
Juha Hyttinen | 83ada00 | 2020-01-30 10:36:33 +0200 | [diff] [blame] | 323 | func (c *Control) handleSubscriptionCreate(subs *Subscription, parentTrans *TransactionXapp) { |
Juha Hyttinen | 422d018 | 2020-01-17 13:37:05 +0200 | [diff] [blame] | 324 | |
Juha Hyttinen | 83ada00 | 2020-01-30 10:36:33 +0200 | [diff] [blame] | 325 | trans := c.tracker.NewSubsTransaction(subs) |
Juha Hyttinen | 422d018 | 2020-01-17 13:37:05 +0200 | [diff] [blame] | 326 | subs.WaitTransactionTurn(trans) |
| 327 | defer subs.ReleaseTransactionTurn(trans) |
| 328 | defer trans.Release() |
| 329 | |
Juha Hyttinen | 83ada00 | 2020-01-30 10:36:33 +0200 | [diff] [blame] | 330 | xapp.Logger.Debug("SUBS-SubReq: Handling %s ", idstring(nil, trans, subs, parentTrans)) |
Juha Hyttinen | 422d018 | 2020-01-17 13:37:05 +0200 | [diff] [blame] | 331 | |
Juha Hyttinen | 83ada00 | 2020-01-30 10:36:33 +0200 | [diff] [blame] | 332 | subRfMsg, valid := subs.GetCachedResponse() |
| 333 | if subRfMsg == nil && valid == true { |
| 334 | event := c.sendE2TSubscriptionRequest(subs, trans, parentTrans) |
| 335 | switch event.(type) { |
| 336 | case *e2ap.E2APSubscriptionResponse: |
| 337 | subRfMsg, valid = subs.SetCachedResponse(event, true) |
| 338 | case *e2ap.E2APSubscriptionFailure: |
| 339 | subRfMsg, valid = subs.SetCachedResponse(event, false) |
| 340 | default: |
| 341 | xapp.Logger.Info("SUBS-SubReq: internal delete due event(%s) %s", typeofSubsMessage(event), idstring(nil, trans, subs, parentTrans)) |
| 342 | subRfMsg, valid = subs.SetCachedResponse(nil, false) |
| 343 | c.sendE2TSubscriptionDeleteRequest(subs, trans, parentTrans) |
| 344 | } |
| 345 | xapp.Logger.Debug("SUBS-SubReq: Handling (e2t response %s) %s", typeofSubsMessage(subRfMsg), idstring(nil, trans, subs, parentTrans)) |
| 346 | } else { |
| 347 | xapp.Logger.Debug("SUBS-SubReq: Handling (cached response %s) %s", typeofSubsMessage(subRfMsg), idstring(nil, trans, subs, parentTrans)) |
Juha Hyttinen | 422d018 | 2020-01-17 13:37:05 +0200 | [diff] [blame] | 348 | } |
| 349 | |
Juha Hyttinen | 83ada00 | 2020-01-30 10:36:33 +0200 | [diff] [blame] | 350 | parentTrans.SendEvent(subRfMsg, 0) |
Juha Hyttinen | 422d018 | 2020-01-17 13:37:05 +0200 | [diff] [blame] | 351 | } |
| 352 | |
| 353 | //------------------------------------------------------------------- |
| 354 | // SUBS DELETE Handling |
| 355 | //------------------------------------------------------------------- |
Juha Hyttinen | 3944a22 | 2020-01-24 11:51:46 +0200 | [diff] [blame] | 356 | |
Juha Hyttinen | 83ada00 | 2020-01-30 10:36:33 +0200 | [diff] [blame] | 357 | func (c *Control) handleSubscriptionDelete(subs *Subscription, parentTrans *TransactionXapp) { |
Juha Hyttinen | 422d018 | 2020-01-17 13:37:05 +0200 | [diff] [blame] | 358 | |
Juha Hyttinen | 83ada00 | 2020-01-30 10:36:33 +0200 | [diff] [blame] | 359 | trans := c.tracker.NewSubsTransaction(subs) |
Juha Hyttinen | 422d018 | 2020-01-17 13:37:05 +0200 | [diff] [blame] | 360 | subs.WaitTransactionTurn(trans) |
| 361 | defer subs.ReleaseTransactionTurn(trans) |
| 362 | defer trans.Release() |
| 363 | |
Juha Hyttinen | 83ada00 | 2020-01-30 10:36:33 +0200 | [diff] [blame] | 364 | xapp.Logger.Debug("SUBS-SubDelReq: Handling %s", idstring(nil, trans, subs, parentTrans)) |
Juha Hyttinen | 422d018 | 2020-01-17 13:37:05 +0200 | [diff] [blame] | 365 | |
Juha Hyttinen | 3944a22 | 2020-01-24 11:51:46 +0200 | [diff] [blame] | 366 | subs.mutex.Lock() |
| 367 | if subs.valid && subs.EpList.HasEndpoint(parentTrans.GetEndpoint()) && subs.EpList.Size() == 1 { |
| 368 | subs.valid = false |
| 369 | subs.mutex.Unlock() |
| 370 | c.sendE2TSubscriptionDeleteRequest(subs, trans, parentTrans) |
| 371 | } else { |
| 372 | subs.mutex.Unlock() |
| 373 | } |
Juha Hyttinen | 422d018 | 2020-01-17 13:37:05 +0200 | [diff] [blame] | 374 | |
Juha Hyttinen | 47942b4 | 2020-02-27 10:41:43 +0200 | [diff] [blame] | 375 | parentTrans.SendEvent(nil, 0) |
Juha Hyttinen | 422d018 | 2020-01-17 13:37:05 +0200 | [diff] [blame] | 376 | } |
| 377 | |
| 378 | //------------------------------------------------------------------- |
| 379 | // send to E2T Subscription Request |
| 380 | //------------------------------------------------------------------- |
Juha Hyttinen | 83ada00 | 2020-01-30 10:36:33 +0200 | [diff] [blame] | 381 | func (c *Control) sendE2TSubscriptionRequest(subs *Subscription, trans *TransactionSubs, parentTrans *TransactionXapp) interface{} { |
Juha Hyttinen | 422d018 | 2020-01-17 13:37:05 +0200 | [diff] [blame] | 382 | var err error |
| 383 | var event interface{} = nil |
| 384 | var timedOut bool = false |
| 385 | |
| 386 | subReqMsg := subs.SubReqMsg |
Juha Hyttinen | 83ada00 | 2020-01-30 10:36:33 +0200 | [diff] [blame] | 387 | subReqMsg.RequestId = subs.GetReqId().RequestId |
Juha Hyttinen | 422d018 | 2020-01-17 13:37:05 +0200 | [diff] [blame] | 388 | trans.Mtype, trans.Payload, err = c.e2ap.PackSubscriptionRequest(subReqMsg) |
| 389 | if err != nil { |
Juha Hyttinen | 83ada00 | 2020-01-30 10:36:33 +0200 | [diff] [blame] | 390 | xapp.Logger.Error("SUBS-SubReq: %s", idstring(err, trans, subs, parentTrans)) |
Juha Hyttinen | 422d018 | 2020-01-17 13:37:05 +0200 | [diff] [blame] | 391 | return event |
| 392 | } |
| 393 | |
| 394 | for retries := uint64(0); retries < e2tMaxSubReqTryCount; retries++ { |
Juha Hyttinen | 83ada00 | 2020-01-30 10:36:33 +0200 | [diff] [blame] | 395 | desc := fmt.Sprintf("(retry %d)", retries) |
| 396 | c.rmrSendToE2T(desc, subs, trans) |
Juha Hyttinen | 422d018 | 2020-01-17 13:37:05 +0200 | [diff] [blame] | 397 | event, timedOut = trans.WaitEvent(e2tSubReqTimeout) |
| 398 | if timedOut { |
| 399 | continue |
| 400 | } |
| 401 | break |
| 402 | } |
Juha Hyttinen | 83ada00 | 2020-01-30 10:36:33 +0200 | [diff] [blame] | 403 | xapp.Logger.Debug("SUBS-SubReq: Response handling event(%s) %s", typeofSubsMessage(event), idstring(nil, trans, subs, parentTrans)) |
Juha Hyttinen | 422d018 | 2020-01-17 13:37:05 +0200 | [diff] [blame] | 404 | return event |
| 405 | } |
| 406 | |
| 407 | //------------------------------------------------------------------- |
| 408 | // send to E2T Subscription Delete Request |
| 409 | //------------------------------------------------------------------- |
| 410 | |
Juha Hyttinen | 83ada00 | 2020-01-30 10:36:33 +0200 | [diff] [blame] | 411 | func (c *Control) sendE2TSubscriptionDeleteRequest(subs *Subscription, trans *TransactionSubs, parentTrans *TransactionXapp) interface{} { |
Juha Hyttinen | 422d018 | 2020-01-17 13:37:05 +0200 | [diff] [blame] | 412 | var err error |
| 413 | var event interface{} |
| 414 | var timedOut bool |
| 415 | |
| 416 | subDelReqMsg := &e2ap.E2APSubscriptionDeleteRequest{} |
Juha Hyttinen | 83ada00 | 2020-01-30 10:36:33 +0200 | [diff] [blame] | 417 | subDelReqMsg.RequestId = subs.GetReqId().RequestId |
Juha Hyttinen | af91f97 | 2020-01-24 08:38:47 +0200 | [diff] [blame] | 418 | subDelReqMsg.FunctionId = subs.SubReqMsg.FunctionId |
Juha Hyttinen | 422d018 | 2020-01-17 13:37:05 +0200 | [diff] [blame] | 419 | trans.Mtype, trans.Payload, err = c.e2ap.PackSubscriptionDeleteRequest(subDelReqMsg) |
| 420 | if err != nil { |
Juha Hyttinen | 83ada00 | 2020-01-30 10:36:33 +0200 | [diff] [blame] | 421 | xapp.Logger.Error("SUBS-SubDelReq: %s", idstring(err, trans, subs, parentTrans)) |
Juha Hyttinen | 422d018 | 2020-01-17 13:37:05 +0200 | [diff] [blame] | 422 | return event |
| 423 | } |
| 424 | |
| 425 | for retries := uint64(0); retries < e2tMaxSubDelReqTryCount; retries++ { |
Juha Hyttinen | 83ada00 | 2020-01-30 10:36:33 +0200 | [diff] [blame] | 426 | desc := fmt.Sprintf("(retry %d)", retries) |
| 427 | c.rmrSendToE2T(desc, subs, trans) |
Juha Hyttinen | 422d018 | 2020-01-17 13:37:05 +0200 | [diff] [blame] | 428 | event, timedOut = trans.WaitEvent(e2tSubDelReqTime) |
| 429 | if timedOut { |
| 430 | continue |
| 431 | } |
| 432 | break |
| 433 | } |
Juha Hyttinen | 83ada00 | 2020-01-30 10:36:33 +0200 | [diff] [blame] | 434 | xapp.Logger.Debug("SUBS-SubDelReq: Response handling event(%s) %s", typeofSubsMessage(event), idstring(nil, trans, subs, parentTrans)) |
Juha Hyttinen | 422d018 | 2020-01-17 13:37:05 +0200 | [diff] [blame] | 435 | return event |
| 436 | } |
| 437 | |
| 438 | //------------------------------------------------------------------- |
| 439 | // handle from E2T Subscription Reponse |
| 440 | //------------------------------------------------------------------- |
Juha Hyttinen | 5f8ffa0 | 2020-02-06 15:28:59 +0200 | [diff] [blame] | 441 | func (c *Control) handleE2TSubscriptionResponse(params *xapptweaks.RMRParams) { |
Juha Hyttinen | 83ada00 | 2020-01-30 10:36:33 +0200 | [diff] [blame] | 442 | xapp.Logger.Info("MSG from E2T: %s", params.String()) |
Juha Hyttinen | 422d018 | 2020-01-17 13:37:05 +0200 | [diff] [blame] | 443 | subRespMsg, err := c.e2ap.UnpackSubscriptionResponse(params.Payload) |
| 444 | if err != nil { |
Juha Hyttinen | 83ada00 | 2020-01-30 10:36:33 +0200 | [diff] [blame] | 445 | xapp.Logger.Error("MSG-SubResp %s", idstring(err, params)) |
Juha Hyttinen | 422d018 | 2020-01-17 13:37:05 +0200 | [diff] [blame] | 446 | return |
| 447 | } |
Juha Hyttinen | 83ada00 | 2020-01-30 10:36:33 +0200 | [diff] [blame] | 448 | subs, err := c.registry.GetSubscriptionFirstMatch([]uint32{subRespMsg.RequestId.Seq}) |
Juha Hyttinen | 422d018 | 2020-01-17 13:37:05 +0200 | [diff] [blame] | 449 | if err != nil { |
Juha Hyttinen | 83ada00 | 2020-01-30 10:36:33 +0200 | [diff] [blame] | 450 | xapp.Logger.Error("MSG-SubResp: %s", idstring(err, params)) |
Juha Hyttinen | 422d018 | 2020-01-17 13:37:05 +0200 | [diff] [blame] | 451 | return |
Juha Hyttinen | 31797b4 | 2020-01-16 14:05:01 +0200 | [diff] [blame] | 452 | } |
| 453 | trans := subs.GetTransaction() |
| 454 | if trans == nil { |
Juha Hyttinen | 422d018 | 2020-01-17 13:37:05 +0200 | [diff] [blame] | 455 | err = fmt.Errorf("Ongoing transaction not found") |
Juha Hyttinen | 83ada00 | 2020-01-30 10:36:33 +0200 | [diff] [blame] | 456 | xapp.Logger.Error("MSG-SubResp: %s", idstring(err, params, subs)) |
Juha Hyttinen | ff8dccd | 2019-12-10 14:34:07 +0200 | [diff] [blame] | 457 | return |
Anssi Mannila | 2e99e2f | 2019-12-05 13:57:06 +0200 | [diff] [blame] | 458 | } |
Juha Hyttinen | 422d018 | 2020-01-17 13:37:05 +0200 | [diff] [blame] | 459 | sendOk, timedOut := trans.SendEvent(subRespMsg, e2tRecvMsgTimeout) |
| 460 | if sendOk == false { |
| 461 | err = fmt.Errorf("Passing event to transaction failed: sendOk(%t) timedOut(%t)", sendOk, timedOut) |
Juha Hyttinen | 83ada00 | 2020-01-30 10:36:33 +0200 | [diff] [blame] | 462 | xapp.Logger.Error("MSG-SubResp: %s", idstring(err, trans, subs)) |
Peter Szilagyi | fbc56f9 | 2019-07-23 19:29:46 +0000 | [diff] [blame] | 463 | } |
Peter Szilagyi | fbc56f9 | 2019-07-23 19:29:46 +0000 | [diff] [blame] | 464 | return |
kalnagy | 4511475 | 2019-06-18 14:40:39 +0200 | [diff] [blame] | 465 | } |
| 466 | |
Juha Hyttinen | 422d018 | 2020-01-17 13:37:05 +0200 | [diff] [blame] | 467 | //------------------------------------------------------------------- |
| 468 | // handle from E2T Subscription Failure |
| 469 | //------------------------------------------------------------------- |
Juha Hyttinen | 5f8ffa0 | 2020-02-06 15:28:59 +0200 | [diff] [blame] | 470 | func (c *Control) handleE2TSubscriptionFailure(params *xapptweaks.RMRParams) { |
Juha Hyttinen | 83ada00 | 2020-01-30 10:36:33 +0200 | [diff] [blame] | 471 | xapp.Logger.Info("MSG from E2T: %s", params.String()) |
Juha Hyttinen | 422d018 | 2020-01-17 13:37:05 +0200 | [diff] [blame] | 472 | subFailMsg, err := c.e2ap.UnpackSubscriptionFailure(params.Payload) |
Peter Szilagyi | fbc56f9 | 2019-07-23 19:29:46 +0000 | [diff] [blame] | 473 | if err != nil { |
Juha Hyttinen | 83ada00 | 2020-01-30 10:36:33 +0200 | [diff] [blame] | 474 | xapp.Logger.Error("MSG-SubFail %s", idstring(err, params)) |
Peter Szilagyi | fbc56f9 | 2019-07-23 19:29:46 +0000 | [diff] [blame] | 475 | return |
| 476 | } |
Juha Hyttinen | 83ada00 | 2020-01-30 10:36:33 +0200 | [diff] [blame] | 477 | subs, err := c.registry.GetSubscriptionFirstMatch([]uint32{subFailMsg.RequestId.Seq}) |
Juha Hyttinen | 31797b4 | 2020-01-16 14:05:01 +0200 | [diff] [blame] | 478 | if err != nil { |
Juha Hyttinen | 83ada00 | 2020-01-30 10:36:33 +0200 | [diff] [blame] | 479 | xapp.Logger.Error("MSG-SubFail: %s", idstring(err, params)) |
Juha Hyttinen | aafee7f | 2020-01-14 14:54:51 +0200 | [diff] [blame] | 480 | return |
| 481 | } |
Juha Hyttinen | 422d018 | 2020-01-17 13:37:05 +0200 | [diff] [blame] | 482 | trans := subs.GetTransaction() |
| 483 | if trans == nil { |
| 484 | err = fmt.Errorf("Ongoing transaction not found") |
Juha Hyttinen | 83ada00 | 2020-01-30 10:36:33 +0200 | [diff] [blame] | 485 | xapp.Logger.Error("MSG-SubFail: %s", idstring(err, params, subs)) |
Anssi Mannila | 8046c70 | 2020-01-02 13:39:05 +0200 | [diff] [blame] | 486 | return |
| 487 | } |
Juha Hyttinen | 422d018 | 2020-01-17 13:37:05 +0200 | [diff] [blame] | 488 | sendOk, timedOut := trans.SendEvent(subFailMsg, e2tRecvMsgTimeout) |
| 489 | if sendOk == false { |
| 490 | err = fmt.Errorf("Passing event to transaction failed: sendOk(%t) timedOut(%t)", sendOk, timedOut) |
Juha Hyttinen | 83ada00 | 2020-01-30 10:36:33 +0200 | [diff] [blame] | 491 | xapp.Logger.Error("MSG-SubFail: %s", idstring(err, trans, subs)) |
Juha Hyttinen | aafee7f | 2020-01-14 14:54:51 +0200 | [diff] [blame] | 492 | } |
Anssi Mannila | 2e99e2f | 2019-12-05 13:57:06 +0200 | [diff] [blame] | 493 | return |
| 494 | } |
| 495 | |
Juha Hyttinen | 422d018 | 2020-01-17 13:37:05 +0200 | [diff] [blame] | 496 | //------------------------------------------------------------------- |
| 497 | // handle from E2T Subscription Delete Response |
| 498 | //------------------------------------------------------------------- |
Juha Hyttinen | 5f8ffa0 | 2020-02-06 15:28:59 +0200 | [diff] [blame] | 499 | func (c *Control) handleE2TSubscriptionDeleteResponse(params *xapptweaks.RMRParams) (err error) { |
Juha Hyttinen | 83ada00 | 2020-01-30 10:36:33 +0200 | [diff] [blame] | 500 | xapp.Logger.Info("MSG from E2T: %s", params.String()) |
Juha Hyttinen | 422d018 | 2020-01-17 13:37:05 +0200 | [diff] [blame] | 501 | subDelRespMsg, err := c.e2ap.UnpackSubscriptionDeleteResponse(params.Payload) |
Anssi Mannila | 2e99e2f | 2019-12-05 13:57:06 +0200 | [diff] [blame] | 502 | if err != nil { |
Juha Hyttinen | 83ada00 | 2020-01-30 10:36:33 +0200 | [diff] [blame] | 503 | xapp.Logger.Error("MSG-SubDelResp: %s", idstring(err, params)) |
Anssi Mannila | 2e99e2f | 2019-12-05 13:57:06 +0200 | [diff] [blame] | 504 | return |
| 505 | } |
Juha Hyttinen | 83ada00 | 2020-01-30 10:36:33 +0200 | [diff] [blame] | 506 | subs, err := c.registry.GetSubscriptionFirstMatch([]uint32{subDelRespMsg.RequestId.Seq}) |
Juha Hyttinen | 31797b4 | 2020-01-16 14:05:01 +0200 | [diff] [blame] | 507 | if err != nil { |
Juha Hyttinen | 83ada00 | 2020-01-30 10:36:33 +0200 | [diff] [blame] | 508 | xapp.Logger.Error("MSG-SubDelResp: %s", idstring(err, params)) |
Juha Hyttinen | 0d064ec | 2020-01-09 09:08:53 +0200 | [diff] [blame] | 509 | return |
| 510 | } |
Juha Hyttinen | 422d018 | 2020-01-17 13:37:05 +0200 | [diff] [blame] | 511 | trans := subs.GetTransaction() |
| 512 | if trans == nil { |
| 513 | err = fmt.Errorf("Ongoing transaction not found") |
Juha Hyttinen | 83ada00 | 2020-01-30 10:36:33 +0200 | [diff] [blame] | 514 | xapp.Logger.Error("MSG-SubDelResp: %s", idstring(err, params, subs)) |
Anssi Mannila | 8046c70 | 2020-01-02 13:39:05 +0200 | [diff] [blame] | 515 | return |
Anssi Mannila | 2e99e2f | 2019-12-05 13:57:06 +0200 | [diff] [blame] | 516 | } |
Juha Hyttinen | 422d018 | 2020-01-17 13:37:05 +0200 | [diff] [blame] | 517 | sendOk, timedOut := trans.SendEvent(subDelRespMsg, e2tRecvMsgTimeout) |
| 518 | if sendOk == false { |
| 519 | err = fmt.Errorf("Passing event to transaction failed: sendOk(%t) timedOut(%t)", sendOk, timedOut) |
Juha Hyttinen | 83ada00 | 2020-01-30 10:36:33 +0200 | [diff] [blame] | 520 | xapp.Logger.Error("MSG-SubDelResp: %s", idstring(err, trans, subs)) |
Juha Hyttinen | 60bfcf9 | 2020-01-14 15:14:24 +0200 | [diff] [blame] | 521 | } |
Anssi Mannila | 2e99e2f | 2019-12-05 13:57:06 +0200 | [diff] [blame] | 522 | return |
| 523 | } |
| 524 | |
Juha Hyttinen | 422d018 | 2020-01-17 13:37:05 +0200 | [diff] [blame] | 525 | //------------------------------------------------------------------- |
| 526 | // handle from E2T Subscription Delete Failure |
| 527 | //------------------------------------------------------------------- |
Juha Hyttinen | 5f8ffa0 | 2020-02-06 15:28:59 +0200 | [diff] [blame] | 528 | func (c *Control) handleE2TSubscriptionDeleteFailure(params *xapptweaks.RMRParams) { |
Juha Hyttinen | 83ada00 | 2020-01-30 10:36:33 +0200 | [diff] [blame] | 529 | xapp.Logger.Info("MSG from E2T: %s", params.String()) |
Juha Hyttinen | 422d018 | 2020-01-17 13:37:05 +0200 | [diff] [blame] | 530 | subDelFailMsg, err := c.e2ap.UnpackSubscriptionDeleteFailure(params.Payload) |
Juha Hyttinen | 31797b4 | 2020-01-16 14:05:01 +0200 | [diff] [blame] | 531 | if err != nil { |
Juha Hyttinen | 83ada00 | 2020-01-30 10:36:33 +0200 | [diff] [blame] | 532 | xapp.Logger.Error("MSG-SubDelFail: %s", idstring(err, params)) |
Anssi Mannila | f1d0eb6 | 2019-12-17 15:29:55 +0200 | [diff] [blame] | 533 | return |
| 534 | } |
Juha Hyttinen | 83ada00 | 2020-01-30 10:36:33 +0200 | [diff] [blame] | 535 | subs, err := c.registry.GetSubscriptionFirstMatch([]uint32{subDelFailMsg.RequestId.Seq}) |
Anssi Mannila | 8046c70 | 2020-01-02 13:39:05 +0200 | [diff] [blame] | 536 | if err != nil { |
Juha Hyttinen | 83ada00 | 2020-01-30 10:36:33 +0200 | [diff] [blame] | 537 | xapp.Logger.Error("MSG-SubDelFail: %s", idstring(err, params)) |
Anssi Mannila | 8046c70 | 2020-01-02 13:39:05 +0200 | [diff] [blame] | 538 | return |
| 539 | } |
Juha Hyttinen | 422d018 | 2020-01-17 13:37:05 +0200 | [diff] [blame] | 540 | trans := subs.GetTransaction() |
| 541 | if trans == nil { |
| 542 | err = fmt.Errorf("Ongoing transaction not found") |
Juha Hyttinen | 83ada00 | 2020-01-30 10:36:33 +0200 | [diff] [blame] | 543 | xapp.Logger.Error("MSG-SubDelFail: %s", idstring(err, params, subs)) |
Juha Hyttinen | 86a4620 | 2020-01-14 12:49:09 +0200 | [diff] [blame] | 544 | return |
| 545 | } |
Juha Hyttinen | 422d018 | 2020-01-17 13:37:05 +0200 | [diff] [blame] | 546 | sendOk, timedOut := trans.SendEvent(subDelFailMsg, e2tRecvMsgTimeout) |
| 547 | if sendOk == false { |
| 548 | err = fmt.Errorf("Passing event to transaction failed: sendOk(%t) timedOut(%t)", sendOk, timedOut) |
Juha Hyttinen | 83ada00 | 2020-01-30 10:36:33 +0200 | [diff] [blame] | 549 | xapp.Logger.Error("MSG-SubDelFail: %s", idstring(err, trans, subs)) |
Anssi Mannila | 8046c70 | 2020-01-02 13:39:05 +0200 | [diff] [blame] | 550 | } |
kalnagy | 93cc3e2 | 2019-09-19 11:29:29 +0200 | [diff] [blame] | 551 | return |
| 552 | } |
| 553 | |
Juha Hyttinen | 422d018 | 2020-01-17 13:37:05 +0200 | [diff] [blame] | 554 | //------------------------------------------------------------------- |
| 555 | // |
| 556 | //------------------------------------------------------------------- |
| 557 | func typeofSubsMessage(v interface{}) string { |
| 558 | if v == nil { |
| 559 | return "NIL" |
kalnagy | 93cc3e2 | 2019-09-19 11:29:29 +0200 | [diff] [blame] | 560 | } |
Juha Hyttinen | 422d018 | 2020-01-17 13:37:05 +0200 | [diff] [blame] | 561 | switch v.(type) { |
| 562 | case *e2ap.E2APSubscriptionRequest: |
| 563 | return "SubReq" |
| 564 | case *e2ap.E2APSubscriptionResponse: |
| 565 | return "SubResp" |
| 566 | case *e2ap.E2APSubscriptionFailure: |
| 567 | return "SubFail" |
| 568 | case *e2ap.E2APSubscriptionDeleteRequest: |
| 569 | return "SubDelReq" |
| 570 | case *e2ap.E2APSubscriptionDeleteResponse: |
| 571 | return "SubDelResp" |
| 572 | case *e2ap.E2APSubscriptionDeleteFailure: |
| 573 | return "SubDelFail" |
| 574 | default: |
| 575 | return "Unknown" |
Juha Hyttinen | 31797b4 | 2020-01-16 14:05:01 +0200 | [diff] [blame] | 576 | } |
Anssi Mannila | f1d0eb6 | 2019-12-17 15:29:55 +0200 | [diff] [blame] | 577 | } |