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" |
| 26 | rtmgrhandle "gerrit.o-ran-sc.org/r/ric-plt/submgr/pkg/rtmgr_client/handle" |
kalnagy | 1455c85 | 2019-10-21 13:06:23 +0200 | [diff] [blame] | 27 | "gerrit.o-ran-sc.org/r/ric-plt/xapp-frame/pkg/xapp" |
| 28 | httptransport "github.com/go-openapi/runtime/client" |
| 29 | "github.com/go-openapi/strfmt" |
| 30 | "github.com/spf13/viper" |
Juha Hyttinen | ff8dccd | 2019-12-10 14:34:07 +0200 | [diff] [blame] | 31 | "sync" |
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 | |
Anssi Mannila | f1d0eb6 | 2019-12-17 15:29:55 +0200 | [diff] [blame] | 39 | var subReqTime time.Duration = 5 * time.Second |
Anssi Mannila | 8046c70 | 2020-01-02 13:39:05 +0200 | [diff] [blame] | 40 | var subDelReqTime time.Duration = 5 * time.Second |
| 41 | var maxSubReqTryCount uint64 = 2 // Initial try + retry |
| 42 | var maxSubDelReqTryCount uint64 = 2 // Initial try + retry |
Anssi Mannila | 2e99e2f | 2019-12-05 13:57:06 +0200 | [diff] [blame] | 43 | |
kalnagy | 4511475 | 2019-06-18 14:40:39 +0200 | [diff] [blame] | 44 | type Control struct { |
Juha Hyttinen | c65f5b0 | 2019-12-30 14:24:04 +0200 | [diff] [blame] | 45 | e2ap *E2ap |
| 46 | registry *Registry |
Juha Hyttinen | c65f5b0 | 2019-12-30 14:24:04 +0200 | [diff] [blame] | 47 | tracker *Tracker |
| 48 | timerMap *TimerMap |
| 49 | rmrSendMutex sync.Mutex |
Juha Hyttinen | 47b842b | 2020-01-08 13:01:52 +0200 | [diff] [blame] | 50 | msgCounter uint64 |
kalnagy | 93cc3e2 | 2019-09-19 11:29:29 +0200 | [diff] [blame] | 51 | } |
| 52 | |
| 53 | type RMRMeid struct { |
Juha Hyttinen | ff8dccd | 2019-12-10 14:34:07 +0200 | [diff] [blame] | 54 | PlmnID string |
| 55 | EnbID string |
Anssi Mannila | 2e99e2f | 2019-12-05 13:57:06 +0200 | [diff] [blame] | 56 | RanName string |
kalnagy | 93cc3e2 | 2019-09-19 11:29:29 +0200 | [diff] [blame] | 57 | } |
| 58 | |
kalnagy | 93cc3e2 | 2019-09-19 11:29:29 +0200 | [diff] [blame] | 59 | const ( |
| 60 | CREATE Action = 0 |
kalnagy | 1455c85 | 2019-10-21 13:06:23 +0200 | [diff] [blame] | 61 | MERGE Action = 1 |
Anssi Mannila | 90fa021 | 2019-12-12 10:47:47 +0200 | [diff] [blame] | 62 | NONE Action = 2 |
kalnagy | 93cc3e2 | 2019-09-19 11:29:29 +0200 | [diff] [blame] | 63 | DELETE Action = 3 |
| 64 | ) |
Peter Szilagyi | fbc56f9 | 2019-07-23 19:29:46 +0000 | [diff] [blame] | 65 | |
| 66 | func init() { |
Anssi Mannila | 8046c70 | 2020-01-02 13:39:05 +0200 | [diff] [blame] | 67 | xapp.Logger.Info("SUBMGR") |
Peter Szilagyi | fbc56f9 | 2019-07-23 19:29:46 +0000 | [diff] [blame] | 68 | viper.AutomaticEnv() |
| 69 | viper.SetEnvPrefix("submgr") |
| 70 | viper.AllowEmptyEnv(true) |
kalnagy | 4511475 | 2019-06-18 14:40:39 +0200 | [diff] [blame] | 71 | } |
| 72 | |
Juha Hyttinen | ff8dccd | 2019-12-10 14:34:07 +0200 | [diff] [blame] | 73 | func NewControl() *Control { |
Juha Hyttinen | 0388dd9 | 2020-01-09 14:14:16 +0200 | [diff] [blame] | 74 | |
Juha Hyttinen | 56e0383 | 2020-01-14 17:08:43 +0200 | [diff] [blame] | 75 | transport := httptransport.New(viper.GetString("rtmgr.HostAddr")+":"+viper.GetString("rtmgr.port"), viper.GetString("rtmgr.baseUrl"), []string{"http"}) |
| 76 | client := rtmgrclient.New(transport, strfmt.Default) |
| 77 | handle := rtmgrhandle.NewProvideXappSubscriptionHandleParamsWithTimeout(10 * time.Second) |
| 78 | deleteHandle := rtmgrhandle.NewDeleteXappSubscriptionHandleParamsWithTimeout(10 * time.Second) |
| 79 | rtmgrClient := RtmgrClient{client, handle, deleteHandle} |
| 80 | |
Peter Szilagyi | fbc56f9 | 2019-07-23 19:29:46 +0000 | [diff] [blame] | 81 | registry := new(Registry) |
Anssi Mannila | 5c161a9 | 2020-01-15 15:40:57 +0200 | [diff] [blame^] | 82 | registry.Initialize() |
Juha Hyttinen | 56e0383 | 2020-01-14 17:08:43 +0200 | [diff] [blame] | 83 | registry.rtmgrClient = &rtmgrClient |
kalnagy | 93cc3e2 | 2019-09-19 11:29:29 +0200 | [diff] [blame] | 84 | |
Balint Uveges | e9608cd | 2019-09-20 18:00:32 +0000 | [diff] [blame] | 85 | tracker := new(Tracker) |
| 86 | tracker.Init() |
| 87 | |
Anssi Mannila | 2e99e2f | 2019-12-05 13:57:06 +0200 | [diff] [blame] | 88 | timerMap := new(TimerMap) |
| 89 | timerMap.Init() |
| 90 | |
Juha Hyttinen | ff8dccd | 2019-12-10 14:34:07 +0200 | [diff] [blame] | 91 | return &Control{e2ap: new(E2ap), |
Juha Hyttinen | 56e0383 | 2020-01-14 17:08:43 +0200 | [diff] [blame] | 92 | registry: registry, |
| 93 | tracker: tracker, |
| 94 | timerMap: timerMap, |
| 95 | msgCounter: 0, |
Juha Hyttinen | ff8dccd | 2019-12-10 14:34:07 +0200 | [diff] [blame] | 96 | } |
kalnagy | 4511475 | 2019-06-18 14:40:39 +0200 | [diff] [blame] | 97 | } |
| 98 | |
| 99 | func (c *Control) Run() { |
Peter Szilagyi | fbc56f9 | 2019-07-23 19:29:46 +0000 | [diff] [blame] | 100 | xapp.Run(c) |
kalnagy | 4511475 | 2019-06-18 14:40:39 +0200 | [diff] [blame] | 101 | } |
| 102 | |
Juha Hyttinen | e406a34 | 2020-01-13 13:02:26 +0200 | [diff] [blame] | 103 | func (c *Control) rmrSendRaw(desc string, params *RMRParams) (err error) { |
| 104 | |
| 105 | xapp.Logger.Info("%s: %s", desc, params.String()) |
Anssi Mannila | 2e99e2f | 2019-12-05 13:57:06 +0200 | [diff] [blame] | 106 | status := false |
| 107 | i := 1 |
Juha Hyttinen | ff8dccd | 2019-12-10 14:34:07 +0200 | [diff] [blame] | 108 | for ; i <= 10 && status == false; i++ { |
Anssi Mannila | 90fa021 | 2019-12-12 10:47:47 +0200 | [diff] [blame] | 109 | c.rmrSendMutex.Lock() |
Juha Hyttinen | e406a34 | 2020-01-13 13:02:26 +0200 | [diff] [blame] | 110 | status = xapp.Rmr.Send(params.RMRParams, false) |
Anssi Mannila | 90fa021 | 2019-12-12 10:47:47 +0200 | [diff] [blame] | 111 | c.rmrSendMutex.Unlock() |
Anssi Mannila | 2e99e2f | 2019-12-05 13:57:06 +0200 | [diff] [blame] | 112 | if status == false { |
Juha Hyttinen | e406a34 | 2020-01-13 13:02:26 +0200 | [diff] [blame] | 113 | xapp.Logger.Info("rmr.Send() failed. Retry count %d, %s", i, params.String()) |
Anssi Mannila | 2e99e2f | 2019-12-05 13:57:06 +0200 | [diff] [blame] | 114 | time.Sleep(500 * time.Millisecond) |
| 115 | } |
| 116 | } |
| 117 | if status == false { |
Juha Hyttinen | e406a34 | 2020-01-13 13:02:26 +0200 | [diff] [blame] | 118 | err = fmt.Errorf("rmr.Send() failed. Retry count %d, %s", i, params.String()) |
| 119 | xapp.Logger.Error("%s: %s", desc, err.Error()) |
Anssi Mannila | 2e99e2f | 2019-12-05 13:57:06 +0200 | [diff] [blame] | 120 | xapp.Rmr.Free(params.Mbuf) |
| 121 | } |
Peter Szilagyi | fbc56f9 | 2019-07-23 19:29:46 +0000 | [diff] [blame] | 122 | return |
kalnagy | 4511475 | 2019-06-18 14:40:39 +0200 | [diff] [blame] | 123 | } |
| 124 | |
Juha Hyttinen | 63284a2 | 2020-01-15 10:45:11 +0200 | [diff] [blame] | 125 | func (c *Control) rmrSend(desc string, subs *Subscription, trans *Transaction) (err error) { |
Juha Hyttinen | e406a34 | 2020-01-13 13:02:26 +0200 | [diff] [blame] | 126 | params := &RMRParams{&xapp.RMRParams{}} |
| 127 | params.Mtype = trans.GetMtype() |
| 128 | params.SubId = int(subs.GetSubId()) |
Juha Hyttinen | 86a4620 | 2020-01-14 12:49:09 +0200 | [diff] [blame] | 129 | params.Xid = "" |
Juha Hyttinen | e406a34 | 2020-01-13 13:02:26 +0200 | [diff] [blame] | 130 | params.Meid = subs.GetMeid() |
| 131 | params.Src = "" |
Juha Hyttinen | 63284a2 | 2020-01-15 10:45:11 +0200 | [diff] [blame] | 132 | params.PayloadLen = len(trans.Payload.Buf) |
| 133 | params.Payload = trans.Payload.Buf |
Juha Hyttinen | e406a34 | 2020-01-13 13:02:26 +0200 | [diff] [blame] | 134 | params.Mbuf = nil |
| 135 | |
| 136 | return c.rmrSendRaw(desc, params) |
kalnagy | e001868 | 2019-09-26 16:28:25 +0200 | [diff] [blame] | 137 | } |
| 138 | |
Juha Hyttinen | 63284a2 | 2020-01-15 10:45:11 +0200 | [diff] [blame] | 139 | func (c *Control) rmrReplyToSender(desc string, subs *Subscription, trans *Transaction) (err error) { |
Juha Hyttinen | e406a34 | 2020-01-13 13:02:26 +0200 | [diff] [blame] | 140 | params := &RMRParams{&xapp.RMRParams{}} |
Juha Hyttinen | 63284a2 | 2020-01-15 10:45:11 +0200 | [diff] [blame] | 141 | params.Mtype = trans.GetMtype() |
Juha Hyttinen | e406a34 | 2020-01-13 13:02:26 +0200 | [diff] [blame] | 142 | params.SubId = int(subs.GetSubId()) |
| 143 | params.Xid = trans.GetXid() |
Juha Hyttinen | 86a4620 | 2020-01-14 12:49:09 +0200 | [diff] [blame] | 144 | params.Meid = trans.GetMeid() |
Juha Hyttinen | e406a34 | 2020-01-13 13:02:26 +0200 | [diff] [blame] | 145 | params.Src = "" |
Juha Hyttinen | 63284a2 | 2020-01-15 10:45:11 +0200 | [diff] [blame] | 146 | params.PayloadLen = len(trans.Payload.Buf) |
| 147 | params.Payload = trans.Payload.Buf |
Juha Hyttinen | e406a34 | 2020-01-13 13:02:26 +0200 | [diff] [blame] | 148 | params.Mbuf = nil |
| 149 | |
| 150 | return c.rmrSendRaw(desc, params) |
| 151 | } |
| 152 | |
| 153 | func (c *Control) Consume(params *xapp.RMRParams) (err error) { |
| 154 | xapp.Rmr.Free(params.Mbuf) |
| 155 | params.Mbuf = nil |
Juha Hyttinen | e406a34 | 2020-01-13 13:02:26 +0200 | [diff] [blame] | 156 | msg := &RMRParams{params} |
Juha Hyttinen | 47b842b | 2020-01-08 13:01:52 +0200 | [diff] [blame] | 157 | c.msgCounter++ |
Anssi Mannila | 90fa021 | 2019-12-12 10:47:47 +0200 | [diff] [blame] | 158 | switch msg.Mtype { |
| 159 | case xapp.RICMessageTypes["RIC_SUB_REQ"]: |
| 160 | go c.handleSubscriptionRequest(msg) |
| 161 | case xapp.RICMessageTypes["RIC_SUB_RESP"]: |
| 162 | go c.handleSubscriptionResponse(msg) |
| 163 | case xapp.RICMessageTypes["RIC_SUB_FAILURE"]: |
| 164 | go c.handleSubscriptionFailure(msg) |
| 165 | case xapp.RICMessageTypes["RIC_SUB_DEL_REQ"]: |
| 166 | go c.handleSubscriptionDeleteRequest(msg) |
| 167 | case xapp.RICMessageTypes["RIC_SUB_DEL_RESP"]: |
| 168 | go c.handleSubscriptionDeleteResponse(msg) |
Anssi Mannila | f1d0eb6 | 2019-12-17 15:29:55 +0200 | [diff] [blame] | 169 | case xapp.RICMessageTypes["RIC_SUB_DEL_FAILURE"]: |
| 170 | go c.handleSubscriptionDeleteFailure(msg) |
Anssi Mannila | 90fa021 | 2019-12-12 10:47:47 +0200 | [diff] [blame] | 171 | default: |
| 172 | xapp.Logger.Info("Unknown Message Type '%d', discarding", msg.Mtype) |
Balint Uveges | cd3881b | 2019-10-02 15:01:43 +0000 | [diff] [blame] | 173 | } |
Juha Hyttinen | 86a4620 | 2020-01-14 12:49:09 +0200 | [diff] [blame] | 174 | |
Anssi Mannila | 90fa021 | 2019-12-12 10:47:47 +0200 | [diff] [blame] | 175 | return nil |
Balint Uveges | cd3881b | 2019-10-02 15:01:43 +0000 | [diff] [blame] | 176 | } |
| 177 | |
Juha Hyttinen | e406a34 | 2020-01-13 13:02:26 +0200 | [diff] [blame] | 178 | func (c *Control) handleSubscriptionRequest(params *RMRParams) { |
| 179 | xapp.Logger.Info("SubReq from xapp: %s", params.String()) |
kalnagy | 93cc3e2 | 2019-09-19 11:29:29 +0200 | [diff] [blame] | 180 | |
Juha Hyttinen | 86a4620 | 2020-01-14 12:49:09 +0200 | [diff] [blame] | 181 | // |
| 182 | // |
| 183 | // |
| 184 | trans, err := c.tracker.TrackTransaction(NewRmrEndpoint(params.Src), |
Juha Hyttinen | 86a4620 | 2020-01-14 12:49:09 +0200 | [diff] [blame] | 185 | params.Xid, |
| 186 | params.Meid, |
| 187 | false, |
| 188 | true) |
Juha Hyttinen | 0d064ec | 2020-01-09 09:08:53 +0200 | [diff] [blame] | 189 | |
Juha Hyttinen | 0388dd9 | 2020-01-09 14:14:16 +0200 | [diff] [blame] | 190 | if err != nil { |
Juha Hyttinen | 86a4620 | 2020-01-14 12:49:09 +0200 | [diff] [blame] | 191 | xapp.Logger.Error("SubReq: %s, Dropping this msg. %s", err.Error(), params.String()) |
Juha Hyttinen | ff8dccd | 2019-12-10 14:34:07 +0200 | [diff] [blame] | 192 | return |
Anssi Mannila | 2e99e2f | 2019-12-05 13:57:06 +0200 | [diff] [blame] | 193 | } |
kalnagy | 93cc3e2 | 2019-09-19 11:29:29 +0200 | [diff] [blame] | 194 | |
Juha Hyttinen | e406a34 | 2020-01-13 13:02:26 +0200 | [diff] [blame] | 195 | // |
Juha Hyttinen | e406a34 | 2020-01-13 13:02:26 +0200 | [diff] [blame] | 196 | // |
| 197 | // |
Juha Hyttinen | 86a4620 | 2020-01-14 12:49:09 +0200 | [diff] [blame] | 198 | trans.SubReqMsg, err = c.e2ap.UnpackSubscriptionRequest(params.Payload) |
Peter Szilagyi | fbc56f9 | 2019-07-23 19:29:46 +0000 | [diff] [blame] | 199 | if err != nil { |
Juha Hyttinen | 86a4620 | 2020-01-14 12:49:09 +0200 | [diff] [blame] | 200 | xapp.Logger.Error("SubReq: %s Dropping this msg. %s", err.Error(), trans) |
| 201 | trans.Release() |
Peter Szilagyi | fbc56f9 | 2019-07-23 19:29:46 +0000 | [diff] [blame] | 202 | return |
| 203 | } |
kalnagy | 93cc3e2 | 2019-09-19 11:29:29 +0200 | [diff] [blame] | 204 | |
Juha Hyttinen | 86a4620 | 2020-01-14 12:49:09 +0200 | [diff] [blame] | 205 | // |
| 206 | // |
| 207 | // |
| 208 | subs, err := c.registry.ReserveSubscription(&trans.RmrEndpoint, trans.Meid) |
kalnagy | 93cc3e2 | 2019-09-19 11:29:29 +0200 | [diff] [blame] | 209 | if err != nil { |
Juha Hyttinen | 86a4620 | 2020-01-14 12:49:09 +0200 | [diff] [blame] | 210 | xapp.Logger.Error("SubReq: %s, Dropping this msg. %s", err.Error(), trans) |
| 211 | trans.Release() |
Juha Hyttinen | c65f5b0 | 2019-12-30 14:24:04 +0200 | [diff] [blame] | 212 | return |
Anssi Mannila | 90fa021 | 2019-12-12 10:47:47 +0200 | [diff] [blame] | 213 | } |
kalnagy | 93cc3e2 | 2019-09-19 11:29:29 +0200 | [diff] [blame] | 214 | |
Juha Hyttinen | e406a34 | 2020-01-13 13:02:26 +0200 | [diff] [blame] | 215 | err = subs.SetTransaction(trans) |
Anssi Mannila | 2e99e2f | 2019-12-05 13:57:06 +0200 | [diff] [blame] | 216 | if err != nil { |
Juha Hyttinen | 86a4620 | 2020-01-14 12:49:09 +0200 | [diff] [blame] | 217 | xapp.Logger.Error("SubReq: %s, Dropping this msg. %s", err.Error(), trans) |
Juha Hyttinen | 56e0383 | 2020-01-14 17:08:43 +0200 | [diff] [blame] | 218 | subs.Release() |
Juha Hyttinen | e406a34 | 2020-01-13 13:02:26 +0200 | [diff] [blame] | 219 | trans.Release() |
| 220 | return |
Anssi Mannila | f1d0eb6 | 2019-12-17 15:29:55 +0200 | [diff] [blame] | 221 | } |
Juha Hyttinen | e406a34 | 2020-01-13 13:02:26 +0200 | [diff] [blame] | 222 | |
Juha Hyttinen | 86a4620 | 2020-01-14 12:49:09 +0200 | [diff] [blame] | 223 | trans.SubReqMsg.RequestId.Seq = uint32(subs.GetSubId()) |
| 224 | |
| 225 | // |
| 226 | // TODO: subscription create is in fact owned by subscription and not transaction. |
| 227 | // Transaction is toward xapp while Subscription is toward ran. |
| 228 | // In merge several xapps may wake transactions, while only one subscription |
| 229 | // toward ran occurs -> subscription owns subscription creation toward ran |
| 230 | // |
| 231 | // This is intermediate solution while improving message handling |
| 232 | // |
Juha Hyttinen | 63284a2 | 2020-01-15 10:45:11 +0200 | [diff] [blame] | 233 | trans.Mtype, trans.Payload, err = c.e2ap.PackSubscriptionRequest(trans.SubReqMsg) |
Juha Hyttinen | 86a4620 | 2020-01-14 12:49:09 +0200 | [diff] [blame] | 234 | if err != nil { |
| 235 | xapp.Logger.Error("SubReq: %s for trans %s", err.Error(), trans) |
Juha Hyttinen | 56e0383 | 2020-01-14 17:08:43 +0200 | [diff] [blame] | 236 | subs.Release() |
Juha Hyttinen | 86a4620 | 2020-01-14 12:49:09 +0200 | [diff] [blame] | 237 | trans.Release() |
| 238 | return |
| 239 | } |
| 240 | |
Juha Hyttinen | 63284a2 | 2020-01-15 10:45:11 +0200 | [diff] [blame] | 241 | c.rmrSend("SubReq: SubReq to E2T", subs, trans) |
Juha Hyttinen | e406a34 | 2020-01-13 13:02:26 +0200 | [diff] [blame] | 242 | |
Juha Hyttinen | aafee7f | 2020-01-14 14:54:51 +0200 | [diff] [blame] | 243 | c.timerMap.StartTimer("RIC_SUB_REQ", int(subs.GetSubId()), subReqTime, FirstTry, c.handleSubscriptionRequestTimer) |
Juha Hyttinen | e406a34 | 2020-01-13 13:02:26 +0200 | [diff] [blame] | 244 | xapp.Logger.Debug("SubReq: Debugging trans table = %v", c.tracker.transactionXappTable) |
Peter Szilagyi | fbc56f9 | 2019-07-23 19:29:46 +0000 | [diff] [blame] | 245 | return |
kalnagy | 4511475 | 2019-06-18 14:40:39 +0200 | [diff] [blame] | 246 | } |
| 247 | |
Juha Hyttinen | e406a34 | 2020-01-13 13:02:26 +0200 | [diff] [blame] | 248 | func (c *Control) handleSubscriptionResponse(params *RMRParams) { |
| 249 | xapp.Logger.Info("SubResp from E2T: %s", params.String()) |
Anssi Mannila | 2e99e2f | 2019-12-05 13:57:06 +0200 | [diff] [blame] | 250 | |
Juha Hyttinen | aafee7f | 2020-01-14 14:54:51 +0200 | [diff] [blame] | 251 | // |
| 252 | // |
| 253 | // |
| 254 | SubRespMsg, err := c.e2ap.UnpackSubscriptionResponse(params.Payload) |
Peter Szilagyi | fbc56f9 | 2019-07-23 19:29:46 +0000 | [diff] [blame] | 255 | if err != nil { |
Juha Hyttinen | 662f68d | 2020-01-15 14:49:18 +0200 | [diff] [blame] | 256 | xapp.Logger.Error("SubResp: %s Dropping this msg. %s", err.Error(), params.String()) |
Peter Szilagyi | fbc56f9 | 2019-07-23 19:29:46 +0000 | [diff] [blame] | 257 | return |
| 258 | } |
Anssi Mannila | 2e99e2f | 2019-12-05 13:57:06 +0200 | [diff] [blame] | 259 | |
Juha Hyttinen | aafee7f | 2020-01-14 14:54:51 +0200 | [diff] [blame] | 260 | // |
| 261 | // |
| 262 | // |
| 263 | subs := c.registry.GetSubscription(uint16(SubRespMsg.RequestId.Seq)) |
| 264 | if subs == nil && params.SubId > 0 { |
| 265 | subs = c.registry.GetSubscription(uint16(params.SubId)) |
| 266 | } |
| 267 | |
Juha Hyttinen | 0d064ec | 2020-01-09 09:08:53 +0200 | [diff] [blame] | 268 | if subs == nil { |
Juha Hyttinen | aafee7f | 2020-01-14 14:54:51 +0200 | [diff] [blame] | 269 | xapp.Logger.Error("SubResp: Not valid subscription found payloadSeqNum: %d, SubId: %d. Dropping this msg. %s", SubRespMsg.RequestId.Seq, params.SubId, params.String()) |
| 270 | return |
| 271 | } |
| 272 | xapp.Logger.Info("SubResp: subscription found payloadSeqNum: %d, SubId: %d", SubRespMsg.RequestId.Seq, subs.GetSubId()) |
| 273 | |
| 274 | // |
| 275 | // |
| 276 | // |
| 277 | trans := subs.GetTransaction() |
| 278 | if trans == nil { |
| 279 | xapp.Logger.Error("SubResp: Unknown trans. Dropping this msg. SubId: %d", subs.GetSubId()) |
Peter Szilagyi | fbc56f9 | 2019-07-23 19:29:46 +0000 | [diff] [blame] | 280 | return |
| 281 | } |
Anssi Mannila | 2e99e2f | 2019-12-05 13:57:06 +0200 | [diff] [blame] | 282 | |
Juha Hyttinen | aafee7f | 2020-01-14 14:54:51 +0200 | [diff] [blame] | 283 | trans.SubRespMsg = SubRespMsg |
Juha Hyttinen | 0d064ec | 2020-01-09 09:08:53 +0200 | [diff] [blame] | 284 | |
Juha Hyttinen | aafee7f | 2020-01-14 14:54:51 +0200 | [diff] [blame] | 285 | // |
| 286 | // |
| 287 | // |
| 288 | c.timerMap.StopTimer("RIC_SUB_REQ", int(subs.GetSubId())) |
Anssi Mannila | 2e99e2f | 2019-12-05 13:57:06 +0200 | [diff] [blame] | 289 | |
Juha Hyttinen | e406a34 | 2020-01-13 13:02:26 +0200 | [diff] [blame] | 290 | responseReceived := trans.CheckResponseReceived() |
Anssi Mannila | 8046c70 | 2020-01-02 13:39:05 +0200 | [diff] [blame] | 291 | if responseReceived == true { |
| 292 | // Subscription timer already received |
| 293 | return |
| 294 | } |
Anssi Mannila | 8046c70 | 2020-01-02 13:39:05 +0200 | [diff] [blame] | 295 | |
Juha Hyttinen | 63284a2 | 2020-01-15 10:45:11 +0200 | [diff] [blame] | 296 | trans.Mtype, trans.Payload, err = c.e2ap.PackSubscriptionResponse(trans.SubRespMsg) |
Juha Hyttinen | aafee7f | 2020-01-14 14:54:51 +0200 | [diff] [blame] | 297 | if err != nil { |
| 298 | xapp.Logger.Error("SubResp: %s for trans %s", err.Error(), trans) |
| 299 | trans.Release() |
| 300 | return |
| 301 | } |
| 302 | |
Juha Hyttinen | 0d064ec | 2020-01-09 09:08:53 +0200 | [diff] [blame] | 303 | subs.Confirmed() |
Juha Hyttinen | e406a34 | 2020-01-13 13:02:26 +0200 | [diff] [blame] | 304 | trans.Release() |
Juha Hyttinen | 63284a2 | 2020-01-15 10:45:11 +0200 | [diff] [blame] | 305 | c.rmrReplyToSender("SubResp: SubResp to xapp", subs, trans) |
Anssi Mannila | 2e99e2f | 2019-12-05 13:57:06 +0200 | [diff] [blame] | 306 | return |
| 307 | } |
| 308 | |
Juha Hyttinen | e406a34 | 2020-01-13 13:02:26 +0200 | [diff] [blame] | 309 | func (c *Control) handleSubscriptionFailure(params *RMRParams) { |
| 310 | xapp.Logger.Info("SubFail from E2T: %s", params.String()) |
Anssi Mannila | 2e99e2f | 2019-12-05 13:57:06 +0200 | [diff] [blame] | 311 | |
Juha Hyttinen | 60bfcf9 | 2020-01-14 15:14:24 +0200 | [diff] [blame] | 312 | // |
| 313 | // |
| 314 | // |
| 315 | SubFailMsg, err := c.e2ap.UnpackSubscriptionFailure(params.Payload) |
Anssi Mannila | 2e99e2f | 2019-12-05 13:57:06 +0200 | [diff] [blame] | 316 | if err != nil { |
Juha Hyttinen | 60bfcf9 | 2020-01-14 15:14:24 +0200 | [diff] [blame] | 317 | xapp.Logger.Error("SubFail: %s Dropping this msg. %s", err.Error(), params.String()) |
Anssi Mannila | 2e99e2f | 2019-12-05 13:57:06 +0200 | [diff] [blame] | 318 | return |
| 319 | } |
Anssi Mannila | 2e99e2f | 2019-12-05 13:57:06 +0200 | [diff] [blame] | 320 | |
Juha Hyttinen | 60bfcf9 | 2020-01-14 15:14:24 +0200 | [diff] [blame] | 321 | // |
| 322 | // |
| 323 | // |
| 324 | subs := c.registry.GetSubscription(uint16(SubFailMsg.RequestId.Seq)) |
| 325 | if subs == nil && params.SubId > 0 { |
| 326 | subs = c.registry.GetSubscription(uint16(params.SubId)) |
| 327 | } |
| 328 | |
Juha Hyttinen | 0d064ec | 2020-01-09 09:08:53 +0200 | [diff] [blame] | 329 | if subs == nil { |
Juha Hyttinen | 60bfcf9 | 2020-01-14 15:14:24 +0200 | [diff] [blame] | 330 | xapp.Logger.Error("SubFail: Not valid subscription found payloadSeqNum: %d, SubId: %d. Dropping this msg. %s", SubFailMsg.RequestId.Seq, params.SubId, params.String()) |
Juha Hyttinen | 0d064ec | 2020-01-09 09:08:53 +0200 | [diff] [blame] | 331 | return |
| 332 | } |
Juha Hyttinen | 60bfcf9 | 2020-01-14 15:14:24 +0200 | [diff] [blame] | 333 | xapp.Logger.Info("SubFail: subscription found payloadSeqNum: %d, SubId: %d", SubFailMsg.RequestId.Seq, subs.GetSubId()) |
Juha Hyttinen | 0d064ec | 2020-01-09 09:08:53 +0200 | [diff] [blame] | 334 | |
Juha Hyttinen | 60bfcf9 | 2020-01-14 15:14:24 +0200 | [diff] [blame] | 335 | // |
| 336 | // |
| 337 | // |
Juha Hyttinen | e406a34 | 2020-01-13 13:02:26 +0200 | [diff] [blame] | 338 | trans := subs.GetTransaction() |
| 339 | if trans == nil { |
Juha Hyttinen | 60bfcf9 | 2020-01-14 15:14:24 +0200 | [diff] [blame] | 340 | xapp.Logger.Error("SubFail: Unknown trans. Dropping this msg. SubId: %d", subs.GetSubId()) |
Juha Hyttinen | 0d064ec | 2020-01-09 09:08:53 +0200 | [diff] [blame] | 341 | return |
| 342 | } |
Juha Hyttinen | 60bfcf9 | 2020-01-14 15:14:24 +0200 | [diff] [blame] | 343 | trans.SubFailMsg = SubFailMsg |
Juha Hyttinen | 0d064ec | 2020-01-09 09:08:53 +0200 | [diff] [blame] | 344 | |
Juha Hyttinen | 60bfcf9 | 2020-01-14 15:14:24 +0200 | [diff] [blame] | 345 | // |
| 346 | // |
| 347 | // |
| 348 | c.timerMap.StopTimer("RIC_SUB_REQ", int(subs.GetSubId())) |
Anssi Mannila | 2e99e2f | 2019-12-05 13:57:06 +0200 | [diff] [blame] | 349 | |
Juha Hyttinen | e406a34 | 2020-01-13 13:02:26 +0200 | [diff] [blame] | 350 | responseReceived := trans.CheckResponseReceived() |
Juha Hyttinen | ff8dccd | 2019-12-10 14:34:07 +0200 | [diff] [blame] | 351 | if err != nil { |
Anssi Mannila | 2e99e2f | 2019-12-05 13:57:06 +0200 | [diff] [blame] | 352 | return |
| 353 | } |
Anssi Mannila | 2e99e2f | 2019-12-05 13:57:06 +0200 | [diff] [blame] | 354 | |
Anssi Mannila | 8046c70 | 2020-01-02 13:39:05 +0200 | [diff] [blame] | 355 | if responseReceived == true { |
| 356 | // Subscription timer already received |
| 357 | return |
Anssi Mannila | 2e99e2f | 2019-12-05 13:57:06 +0200 | [diff] [blame] | 358 | } |
| 359 | |
Juha Hyttinen | 63284a2 | 2020-01-15 10:45:11 +0200 | [diff] [blame] | 360 | trans.Mtype, trans.Payload, err = c.e2ap.PackSubscriptionFailure(trans.SubFailMsg) |
Juha Hyttinen | 375c141 | 2020-01-14 20:17:50 +0200 | [diff] [blame] | 361 | if err == nil { |
Juha Hyttinen | 63284a2 | 2020-01-15 10:45:11 +0200 | [diff] [blame] | 362 | c.rmrReplyToSender("SubFail: SubFail to xapp", subs, trans) |
Juha Hyttinen | 60bfcf9 | 2020-01-14 15:14:24 +0200 | [diff] [blame] | 363 | time.Sleep(3 * time.Second) |
Juha Hyttinen | 375c141 | 2020-01-14 20:17:50 +0200 | [diff] [blame] | 364 | } else { |
| 365 | //TODO error handling improvement |
| 366 | xapp.Logger.Error("SubFail: %s for trans %s (continuing cleaning)", err.Error(), trans) |
Juha Hyttinen | 60bfcf9 | 2020-01-14 15:14:24 +0200 | [diff] [blame] | 367 | } |
Anssi Mannila | a189c86 | 2020-01-10 11:36:35 +0200 | [diff] [blame] | 368 | |
Juha Hyttinen | e406a34 | 2020-01-13 13:02:26 +0200 | [diff] [blame] | 369 | trans.Release() |
Juha Hyttinen | 56e0383 | 2020-01-14 17:08:43 +0200 | [diff] [blame] | 370 | subs.Release() |
Anssi Mannila | 2e99e2f | 2019-12-05 13:57:06 +0200 | [diff] [blame] | 371 | return |
| 372 | } |
| 373 | |
Anssi Mannila | 8046c70 | 2020-01-02 13:39:05 +0200 | [diff] [blame] | 374 | func (c *Control) handleSubscriptionRequestTimer(strId string, nbrId int, tryCount uint64) { |
Juha Hyttinen | e406a34 | 2020-01-13 13:02:26 +0200 | [diff] [blame] | 375 | xapp.Logger.Info("SubReq timeout: subId: %v, tryCount: %v", nbrId, tryCount) |
Anssi Mannila | f1d0eb6 | 2019-12-17 15:29:55 +0200 | [diff] [blame] | 376 | |
Juha Hyttinen | e406a34 | 2020-01-13 13:02:26 +0200 | [diff] [blame] | 377 | subs := c.registry.GetSubscription(uint16(nbrId)) |
Juha Hyttinen | 0d064ec | 2020-01-09 09:08:53 +0200 | [diff] [blame] | 378 | if subs == nil { |
Juha Hyttinen | e406a34 | 2020-01-13 13:02:26 +0200 | [diff] [blame] | 379 | xapp.Logger.Error("SubReq timeout: Unknown payloadSeqNum. Dropping this msg. SubId: %v", nbrId) |
Anssi Mannila | f1d0eb6 | 2019-12-17 15:29:55 +0200 | [diff] [blame] | 380 | return |
| 381 | } |
Anssi Mannila | 2e99e2f | 2019-12-05 13:57:06 +0200 | [diff] [blame] | 382 | |
Juha Hyttinen | e406a34 | 2020-01-13 13:02:26 +0200 | [diff] [blame] | 383 | trans := subs.GetTransaction() |
| 384 | if trans == nil { |
| 385 | xapp.Logger.Error("SubReq timeout: Unknown trans. Dropping this msg. SubId: %v", subs.GetSubId()) |
Juha Hyttinen | 0d064ec | 2020-01-09 09:08:53 +0200 | [diff] [blame] | 386 | return |
| 387 | } |
| 388 | |
Juha Hyttinen | e406a34 | 2020-01-13 13:02:26 +0200 | [diff] [blame] | 389 | responseReceived := trans.CheckResponseReceived() |
Juha Hyttinen | 0d064ec | 2020-01-09 09:08:53 +0200 | [diff] [blame] | 390 | |
Anssi Mannila | 8046c70 | 2020-01-02 13:39:05 +0200 | [diff] [blame] | 391 | if responseReceived == true { |
| 392 | // Subscription Response or Failure already received |
| 393 | return |
| 394 | } |
| 395 | |
| 396 | if tryCount < maxSubReqTryCount { |
Juha Hyttinen | 63284a2 | 2020-01-15 10:45:11 +0200 | [diff] [blame] | 397 | xapp.Logger.Info("SubReq timeout: subs: %s trans: %s", subs, trans) |
Anssi Mannila | 8046c70 | 2020-01-02 13:39:05 +0200 | [diff] [blame] | 398 | |
Juha Hyttinen | e406a34 | 2020-01-13 13:02:26 +0200 | [diff] [blame] | 399 | trans.RetryTransaction() |
Juha Hyttinen | 0d064ec | 2020-01-09 09:08:53 +0200 | [diff] [blame] | 400 | |
Juha Hyttinen | 63284a2 | 2020-01-15 10:45:11 +0200 | [diff] [blame] | 401 | c.rmrSend("SubReq timeout: SubReq to E2T", subs, trans) |
Anssi Mannila | 8046c70 | 2020-01-02 13:39:05 +0200 | [diff] [blame] | 402 | |
| 403 | tryCount++ |
Juha Hyttinen | e406a34 | 2020-01-13 13:02:26 +0200 | [diff] [blame] | 404 | c.timerMap.StartTimer("RIC_SUB_REQ", int(subs.GetSubId()), subReqTime, tryCount, c.handleSubscriptionRequestTimer) |
Anssi Mannila | 8046c70 | 2020-01-02 13:39:05 +0200 | [diff] [blame] | 405 | return |
Anssi Mannila | 2e99e2f | 2019-12-05 13:57:06 +0200 | [diff] [blame] | 406 | } |
Anssi Mannila | 8046c70 | 2020-01-02 13:39:05 +0200 | [diff] [blame] | 407 | |
Juha Hyttinen | 375c141 | 2020-01-14 20:17:50 +0200 | [diff] [blame] | 408 | // Release CREATE transaction |
Juha Hyttinen | e406a34 | 2020-01-13 13:02:26 +0200 | [diff] [blame] | 409 | trans.Release() |
Anssi Mannila | 8046c70 | 2020-01-02 13:39:05 +0200 | [diff] [blame] | 410 | |
Juha Hyttinen | e406a34 | 2020-01-13 13:02:26 +0200 | [diff] [blame] | 411 | // Create DELETE transaction (internal and no messages toward xapp) |
Juha Hyttinen | 86a4620 | 2020-01-14 12:49:09 +0200 | [diff] [blame] | 412 | deltrans, err := c.tracker.TrackTransaction(&trans.RmrEndpoint, |
Juha Hyttinen | 86a4620 | 2020-01-14 12:49:09 +0200 | [diff] [blame] | 413 | trans.GetXid(), |
| 414 | trans.GetMeid(), |
| 415 | false, |
| 416 | false) |
| 417 | |
Anssi Mannila | 8046c70 | 2020-01-02 13:39:05 +0200 | [diff] [blame] | 418 | if err != nil { |
Juha Hyttinen | e406a34 | 2020-01-13 13:02:26 +0200 | [diff] [blame] | 419 | xapp.Logger.Error("SubReq timeout: %s, Dropping this msg.", err.Error()) |
Juha Hyttinen | 86a4620 | 2020-01-14 12:49:09 +0200 | [diff] [blame] | 420 | //TODO improve error handling. Important at least in merge |
Juha Hyttinen | 56e0383 | 2020-01-14 17:08:43 +0200 | [diff] [blame] | 421 | subs.Release() |
Anssi Mannila | 8046c70 | 2020-01-02 13:39:05 +0200 | [diff] [blame] | 422 | return |
| 423 | } |
| 424 | |
Juha Hyttinen | 86a4620 | 2020-01-14 12:49:09 +0200 | [diff] [blame] | 425 | deltrans.SubDelReqMsg = &e2ap.E2APSubscriptionDeleteRequest{} |
| 426 | deltrans.SubDelReqMsg.RequestId.Id = trans.SubReqMsg.RequestId.Id |
| 427 | deltrans.SubDelReqMsg.RequestId.Seq = uint32(subs.GetSubId()) |
| 428 | deltrans.SubDelReqMsg.FunctionId = trans.SubReqMsg.FunctionId |
Juha Hyttinen | 63284a2 | 2020-01-15 10:45:11 +0200 | [diff] [blame] | 429 | deltrans.Mtype, deltrans.Payload, err = c.e2ap.PackSubscriptionDeleteRequest(deltrans.SubDelReqMsg) |
Juha Hyttinen | 86a4620 | 2020-01-14 12:49:09 +0200 | [diff] [blame] | 430 | if err != nil { |
| 431 | xapp.Logger.Error("SubReq timeout: Packing SubDelReq failed. Err: %v", err) |
| 432 | //TODO improve error handling. Important at least in merge |
| 433 | deltrans.Release() |
Juha Hyttinen | 56e0383 | 2020-01-14 17:08:43 +0200 | [diff] [blame] | 434 | subs.Release() |
Juha Hyttinen | 86a4620 | 2020-01-14 12:49:09 +0200 | [diff] [blame] | 435 | return |
| 436 | } |
Juha Hyttinen | 86a4620 | 2020-01-14 12:49:09 +0200 | [diff] [blame] | 437 | |
Juha Hyttinen | e406a34 | 2020-01-13 13:02:26 +0200 | [diff] [blame] | 438 | err = subs.SetTransaction(deltrans) |
Anssi Mannila | 8046c70 | 2020-01-02 13:39:05 +0200 | [diff] [blame] | 439 | if err != nil { |
Juha Hyttinen | e406a34 | 2020-01-13 13:02:26 +0200 | [diff] [blame] | 440 | xapp.Logger.Error("SubReq timeout: %s, Dropping this msg.", err.Error()) |
Juha Hyttinen | 86a4620 | 2020-01-14 12:49:09 +0200 | [diff] [blame] | 441 | //TODO improve error handling. Important at least in merge |
Juha Hyttinen | e406a34 | 2020-01-13 13:02:26 +0200 | [diff] [blame] | 442 | deltrans.Release() |
| 443 | return |
Anssi Mannila | 8046c70 | 2020-01-02 13:39:05 +0200 | [diff] [blame] | 444 | } |
Juha Hyttinen | e406a34 | 2020-01-13 13:02:26 +0200 | [diff] [blame] | 445 | |
Juha Hyttinen | 63284a2 | 2020-01-15 10:45:11 +0200 | [diff] [blame] | 446 | c.rmrSend("SubReq timer: SubDelReq to E2T", subs, deltrans) |
Juha Hyttinen | e406a34 | 2020-01-13 13:02:26 +0200 | [diff] [blame] | 447 | c.timerMap.StartTimer("RIC_SUB_DEL_REQ", int(subs.GetSubId()), subDelReqTime, FirstTry, c.handleSubscriptionDeleteRequestTimer) |
kalnagy | 93cc3e2 | 2019-09-19 11:29:29 +0200 | [diff] [blame] | 448 | return |
| 449 | } |
| 450 | |
Juha Hyttinen | e406a34 | 2020-01-13 13:02:26 +0200 | [diff] [blame] | 451 | func (c *Control) handleSubscriptionDeleteRequest(params *RMRParams) { |
| 452 | xapp.Logger.Info("SubDelReq from xapp: %s", params.String()) |
kalnagy | 93cc3e2 | 2019-09-19 11:29:29 +0200 | [diff] [blame] | 453 | |
Juha Hyttinen | aafee7f | 2020-01-14 14:54:51 +0200 | [diff] [blame] | 454 | // |
| 455 | // |
| 456 | // |
Juha Hyttinen | 86a4620 | 2020-01-14 12:49:09 +0200 | [diff] [blame] | 457 | trans, err := c.tracker.TrackTransaction(NewRmrEndpoint(params.Src), |
Juha Hyttinen | 86a4620 | 2020-01-14 12:49:09 +0200 | [diff] [blame] | 458 | params.Xid, |
| 459 | params.Meid, |
| 460 | false, |
| 461 | true) |
| 462 | |
Juha Hyttinen | e406a34 | 2020-01-13 13:02:26 +0200 | [diff] [blame] | 463 | if err != nil { |
Juha Hyttinen | 86a4620 | 2020-01-14 12:49:09 +0200 | [diff] [blame] | 464 | xapp.Logger.Error("SubDelReq: %s, Dropping this msg. %s", err.Error(), params.String()) |
Juha Hyttinen | e406a34 | 2020-01-13 13:02:26 +0200 | [diff] [blame] | 465 | return |
kalnagy | 93cc3e2 | 2019-09-19 11:29:29 +0200 | [diff] [blame] | 466 | } |
Anssi Mannila | 2e99e2f | 2019-12-05 13:57:06 +0200 | [diff] [blame] | 467 | |
Juha Hyttinen | b3dc156 | 2020-01-14 14:32:17 +0200 | [diff] [blame] | 468 | // |
| 469 | // |
| 470 | // |
| 471 | trans.SubDelReqMsg, err = c.e2ap.UnpackSubscriptionDeleteRequest(params.Payload) |
| 472 | if err != nil { |
| 473 | xapp.Logger.Error("SubDelReq: %s Dropping this msg. %s", err.Error(), trans) |
| 474 | trans.Release() |
| 475 | return |
kalnagy | 93cc3e2 | 2019-09-19 11:29:29 +0200 | [diff] [blame] | 476 | } |
Juha Hyttinen | b3dc156 | 2020-01-14 14:32:17 +0200 | [diff] [blame] | 477 | |
Juha Hyttinen | aafee7f | 2020-01-14 14:54:51 +0200 | [diff] [blame] | 478 | // |
| 479 | // |
| 480 | // |
| 481 | subs := c.registry.GetSubscription(uint16(trans.SubDelReqMsg.RequestId.Seq)) |
Juha Hyttinen | 86a4620 | 2020-01-14 12:49:09 +0200 | [diff] [blame] | 482 | if subs == nil && params.SubId > 0 { |
| 483 | subs = c.registry.GetSubscription(uint16(params.SubId)) |
| 484 | } |
Anssi Mannila | 26c922a | 2019-12-17 11:18:08 +0200 | [diff] [blame] | 485 | |
Juha Hyttinen | e406a34 | 2020-01-13 13:02:26 +0200 | [diff] [blame] | 486 | if subs == nil { |
Juha Hyttinen | b3dc156 | 2020-01-14 14:32:17 +0200 | [diff] [blame] | 487 | xapp.Logger.Error("SubDelReq: Not valid subscription found payloadSeqNum: %d, SubId: %d. Dropping this msg. %s", trans.SubDelReqMsg.RequestId.Seq, params.SubId, trans) |
Juha Hyttinen | 86a4620 | 2020-01-14 12:49:09 +0200 | [diff] [blame] | 488 | trans.Release() |
Anssi Mannila | 90fa021 | 2019-12-12 10:47:47 +0200 | [diff] [blame] | 489 | return |
kalnagy | 93cc3e2 | 2019-09-19 11:29:29 +0200 | [diff] [blame] | 490 | } |
Juha Hyttinen | b3dc156 | 2020-01-14 14:32:17 +0200 | [diff] [blame] | 491 | xapp.Logger.Info("SubDelReq: subscription found payloadSeqNum: %d, SubId: %d. %s", trans.SubDelReqMsg.RequestId.Seq, params.SubId, trans) |
Juha Hyttinen | e406a34 | 2020-01-13 13:02:26 +0200 | [diff] [blame] | 492 | |
| 493 | err = subs.SetTransaction(trans) |
| 494 | if err != nil { |
Juha Hyttinen | 86a4620 | 2020-01-14 12:49:09 +0200 | [diff] [blame] | 495 | xapp.Logger.Error("SubDelReq: %s, Dropping this msg. %s", err.Error(), trans) |
Juha Hyttinen | e406a34 | 2020-01-13 13:02:26 +0200 | [diff] [blame] | 496 | trans.Release() |
| 497 | return |
| 498 | } |
| 499 | |
Juha Hyttinen | b3dc156 | 2020-01-14 14:32:17 +0200 | [diff] [blame] | 500 | // |
| 501 | // TODO: subscription delete is in fact owned by subscription and not transaction. |
| 502 | // Transaction is toward xapp while Subscription is toward ran. |
| 503 | // In merge several xapps may wake transactions, while only one subscription |
| 504 | // toward ran occurs -> subscription owns subscription creation toward ran |
| 505 | // |
| 506 | // This is intermediate solution while improving message handling |
| 507 | // |
Juha Hyttinen | 63284a2 | 2020-01-15 10:45:11 +0200 | [diff] [blame] | 508 | trans.Mtype, trans.Payload, err = c.e2ap.PackSubscriptionDeleteRequest(trans.SubDelReqMsg) |
Juha Hyttinen | b3dc156 | 2020-01-14 14:32:17 +0200 | [diff] [blame] | 509 | if err != nil { |
| 510 | xapp.Logger.Error("SubDelReq: %s for trans %s", err.Error(), trans) |
| 511 | trans.Release() |
| 512 | return |
| 513 | } |
| 514 | |
Juha Hyttinen | e406a34 | 2020-01-13 13:02:26 +0200 | [diff] [blame] | 515 | subs.UnConfirmed() |
| 516 | |
Juha Hyttinen | 63284a2 | 2020-01-15 10:45:11 +0200 | [diff] [blame] | 517 | c.rmrSend("SubDelReq: SubDelReq to E2T", subs, trans) |
Juha Hyttinen | e406a34 | 2020-01-13 13:02:26 +0200 | [diff] [blame] | 518 | |
| 519 | c.timerMap.StartTimer("RIC_SUB_DEL_REQ", int(subs.GetSubId()), subDelReqTime, FirstTry, c.handleSubscriptionDeleteRequestTimer) |
kalnagy | e001868 | 2019-09-26 16:28:25 +0200 | [diff] [blame] | 520 | return |
| 521 | } |
| 522 | |
Juha Hyttinen | e406a34 | 2020-01-13 13:02:26 +0200 | [diff] [blame] | 523 | func (c *Control) handleSubscriptionDeleteResponse(params *RMRParams) (err error) { |
| 524 | xapp.Logger.Info("SubDelResp from E2T:%s", params.String()) |
Anssi Mannila | 2e99e2f | 2019-12-05 13:57:06 +0200 | [diff] [blame] | 525 | |
Juha Hyttinen | 4e7c8c5 | 2020-01-14 19:25:00 +0200 | [diff] [blame] | 526 | // |
| 527 | // |
| 528 | // |
| 529 | SubDelRespMsg, err := c.e2ap.UnpackSubscriptionDeleteResponse(params.Payload) |
kalnagy | e001868 | 2019-09-26 16:28:25 +0200 | [diff] [blame] | 530 | if err != nil { |
Juha Hyttinen | 4e7c8c5 | 2020-01-14 19:25:00 +0200 | [diff] [blame] | 531 | xapp.Logger.Error("SubDelResp: %s Dropping this msg. %s", err.Error(), params.String()) |
kalnagy | e001868 | 2019-09-26 16:28:25 +0200 | [diff] [blame] | 532 | return |
| 533 | } |
kalnagy | e001868 | 2019-09-26 16:28:25 +0200 | [diff] [blame] | 534 | |
Juha Hyttinen | 4e7c8c5 | 2020-01-14 19:25:00 +0200 | [diff] [blame] | 535 | // |
| 536 | // |
| 537 | // |
| 538 | subs := c.registry.GetSubscription(uint16(SubDelRespMsg.RequestId.Seq)) |
| 539 | if subs == nil && params.SubId > 0 { |
| 540 | subs = c.registry.GetSubscription(uint16(params.SubId)) |
| 541 | } |
| 542 | |
Juha Hyttinen | 0d064ec | 2020-01-09 09:08:53 +0200 | [diff] [blame] | 543 | if subs == nil { |
Juha Hyttinen | 4e7c8c5 | 2020-01-14 19:25:00 +0200 | [diff] [blame] | 544 | xapp.Logger.Error("SubDelResp: Not valid subscription found payloadSeqNum: %d, SubId: %d. Dropping this msg. %s", SubDelRespMsg.RequestId.Seq, params.SubId, params.String()) |
Anssi Mannila | 2e99e2f | 2019-12-05 13:57:06 +0200 | [diff] [blame] | 545 | return |
| 546 | } |
Juha Hyttinen | 4e7c8c5 | 2020-01-14 19:25:00 +0200 | [diff] [blame] | 547 | xapp.Logger.Info("SubDelResp: subscription found payloadSeqNum: %d, SubId: %d", SubDelRespMsg.RequestId.Seq, subs.GetSubId()) |
Anssi Mannila | 2e99e2f | 2019-12-05 13:57:06 +0200 | [diff] [blame] | 548 | |
Juha Hyttinen | 4e7c8c5 | 2020-01-14 19:25:00 +0200 | [diff] [blame] | 549 | // |
| 550 | // |
| 551 | // |
Juha Hyttinen | e406a34 | 2020-01-13 13:02:26 +0200 | [diff] [blame] | 552 | trans := subs.GetTransaction() |
| 553 | if trans == nil { |
Juha Hyttinen | 4e7c8c5 | 2020-01-14 19:25:00 +0200 | [diff] [blame] | 554 | xapp.Logger.Error("SubDelResp: Unknown trans. Dropping this msg. SubId: %d", subs.GetSubId()) |
Juha Hyttinen | 0d064ec | 2020-01-09 09:08:53 +0200 | [diff] [blame] | 555 | return |
| 556 | } |
| 557 | |
Juha Hyttinen | 4e7c8c5 | 2020-01-14 19:25:00 +0200 | [diff] [blame] | 558 | trans.SubDelRespMsg = SubDelRespMsg |
| 559 | |
| 560 | // |
| 561 | // |
| 562 | // |
Juha Hyttinen | e406a34 | 2020-01-13 13:02:26 +0200 | [diff] [blame] | 563 | c.timerMap.StopTimer("RIC_SUB_DEL_REQ", int(subs.GetSubId())) |
Juha Hyttinen | 0d064ec | 2020-01-09 09:08:53 +0200 | [diff] [blame] | 564 | |
Juha Hyttinen | e406a34 | 2020-01-13 13:02:26 +0200 | [diff] [blame] | 565 | responseReceived := trans.CheckResponseReceived() |
Anssi Mannila | 8046c70 | 2020-01-02 13:39:05 +0200 | [diff] [blame] | 566 | if responseReceived == true { |
| 567 | // Subscription Delete timer already received |
| 568 | return |
Anssi Mannila | 2e99e2f | 2019-12-05 13:57:06 +0200 | [diff] [blame] | 569 | } |
| 570 | |
Juha Hyttinen | 375c141 | 2020-01-14 20:17:50 +0200 | [diff] [blame] | 571 | c.sendSubscriptionDeleteResponse("SubDelResp", trans, subs) |
kalnagy | e001868 | 2019-09-26 16:28:25 +0200 | [diff] [blame] | 572 | return |
| 573 | } |
Anssi Mannila | 2e99e2f | 2019-12-05 13:57:06 +0200 | [diff] [blame] | 574 | |
Juha Hyttinen | e406a34 | 2020-01-13 13:02:26 +0200 | [diff] [blame] | 575 | func (c *Control) handleSubscriptionDeleteFailure(params *RMRParams) { |
| 576 | xapp.Logger.Info("SubDelFail from E2T:%s", params.String()) |
Anssi Mannila | 2e99e2f | 2019-12-05 13:57:06 +0200 | [diff] [blame] | 577 | |
Juha Hyttinen | 375c141 | 2020-01-14 20:17:50 +0200 | [diff] [blame] | 578 | // |
| 579 | // |
| 580 | // |
| 581 | SubDelFailMsg, err := c.e2ap.UnpackSubscriptionDeleteFailure(params.Payload) |
Anssi Mannila | 2e99e2f | 2019-12-05 13:57:06 +0200 | [diff] [blame] | 582 | if err != nil { |
Juha Hyttinen | 375c141 | 2020-01-14 20:17:50 +0200 | [diff] [blame] | 583 | xapp.Logger.Error("SubDelFail: %s Dropping this msg. %s", err.Error(), params.String()) |
Anssi Mannila | 2e99e2f | 2019-12-05 13:57:06 +0200 | [diff] [blame] | 584 | return |
| 585 | } |
Anssi Mannila | 2e99e2f | 2019-12-05 13:57:06 +0200 | [diff] [blame] | 586 | |
Juha Hyttinen | 375c141 | 2020-01-14 20:17:50 +0200 | [diff] [blame] | 587 | // |
| 588 | // |
| 589 | // |
| 590 | subs := c.registry.GetSubscription(uint16(SubDelFailMsg.RequestId.Seq)) |
| 591 | if subs == nil && params.SubId > 0 { |
| 592 | subs = c.registry.GetSubscription(uint16(params.SubId)) |
| 593 | } |
| 594 | |
Juha Hyttinen | 0d064ec | 2020-01-09 09:08:53 +0200 | [diff] [blame] | 595 | if subs == nil { |
Juha Hyttinen | 375c141 | 2020-01-14 20:17:50 +0200 | [diff] [blame] | 596 | xapp.Logger.Error("SubDelFail: Not valid subscription found payloadSeqNum: %d, SubId: %d. Dropping this msg. %s", SubDelFailMsg.RequestId.Seq, params.SubId, params.String()) |
Anssi Mannila | 2e99e2f | 2019-12-05 13:57:06 +0200 | [diff] [blame] | 597 | return |
| 598 | } |
Juha Hyttinen | 375c141 | 2020-01-14 20:17:50 +0200 | [diff] [blame] | 599 | xapp.Logger.Info("SubDelFail: subscription found payloadSeqNum: %d, SubId: %d", SubDelFailMsg.RequestId.Seq, subs.GetSubId()) |
Anssi Mannila | 2e99e2f | 2019-12-05 13:57:06 +0200 | [diff] [blame] | 600 | |
Juha Hyttinen | 375c141 | 2020-01-14 20:17:50 +0200 | [diff] [blame] | 601 | // |
| 602 | // |
| 603 | // |
Juha Hyttinen | e406a34 | 2020-01-13 13:02:26 +0200 | [diff] [blame] | 604 | trans := subs.GetTransaction() |
| 605 | if trans == nil { |
Juha Hyttinen | 375c141 | 2020-01-14 20:17:50 +0200 | [diff] [blame] | 606 | xapp.Logger.Error("SubDelFail: Unknown trans. Dropping this msg. SubId: %d", subs.GetSubId()) |
Juha Hyttinen | 0d064ec | 2020-01-09 09:08:53 +0200 | [diff] [blame] | 607 | return |
| 608 | } |
Juha Hyttinen | 375c141 | 2020-01-14 20:17:50 +0200 | [diff] [blame] | 609 | trans.SubDelFailMsg = SubDelFailMsg |
Juha Hyttinen | 0d064ec | 2020-01-09 09:08:53 +0200 | [diff] [blame] | 610 | |
Juha Hyttinen | 375c141 | 2020-01-14 20:17:50 +0200 | [diff] [blame] | 611 | // |
| 612 | // |
| 613 | // |
Juha Hyttinen | e406a34 | 2020-01-13 13:02:26 +0200 | [diff] [blame] | 614 | c.timerMap.StopTimer("RIC_SUB_DEL_REQ", int(subs.GetSubId())) |
Juha Hyttinen | 0d064ec | 2020-01-09 09:08:53 +0200 | [diff] [blame] | 615 | |
Juha Hyttinen | e406a34 | 2020-01-13 13:02:26 +0200 | [diff] [blame] | 616 | responseReceived := trans.CheckResponseReceived() |
Anssi Mannila | 8046c70 | 2020-01-02 13:39:05 +0200 | [diff] [blame] | 617 | if responseReceived == true { |
| 618 | // Subscription Delete timer already received |
| 619 | return |
Anssi Mannila | 2e99e2f | 2019-12-05 13:57:06 +0200 | [diff] [blame] | 620 | } |
Anssi Mannila | 8046c70 | 2020-01-02 13:39:05 +0200 | [diff] [blame] | 621 | |
Juha Hyttinen | 375c141 | 2020-01-14 20:17:50 +0200 | [diff] [blame] | 622 | c.sendSubscriptionDeleteResponse("SubDelFail", trans, subs) |
Anssi Mannila | 2e99e2f | 2019-12-05 13:57:06 +0200 | [diff] [blame] | 623 | return |
| 624 | } |
| 625 | |
Anssi Mannila | 8046c70 | 2020-01-02 13:39:05 +0200 | [diff] [blame] | 626 | func (c *Control) handleSubscriptionDeleteRequestTimer(strId string, nbrId int, tryCount uint64) { |
Juha Hyttinen | e406a34 | 2020-01-13 13:02:26 +0200 | [diff] [blame] | 627 | xapp.Logger.Info("SubDelReq timeout: subId: %v, tryCount: %v", nbrId, tryCount) |
Anssi Mannila | f1d0eb6 | 2019-12-17 15:29:55 +0200 | [diff] [blame] | 628 | |
Juha Hyttinen | e406a34 | 2020-01-13 13:02:26 +0200 | [diff] [blame] | 629 | subs := c.registry.GetSubscription(uint16(nbrId)) |
Juha Hyttinen | 0d064ec | 2020-01-09 09:08:53 +0200 | [diff] [blame] | 630 | if subs == nil { |
Juha Hyttinen | e406a34 | 2020-01-13 13:02:26 +0200 | [diff] [blame] | 631 | xapp.Logger.Error("SubDelReq timeout: Unknown payloadSeqNum. Dropping this msg. SubId: %v", nbrId) |
Anssi Mannila | 2e99e2f | 2019-12-05 13:57:06 +0200 | [diff] [blame] | 632 | return |
| 633 | } |
Anssi Mannila | 2e99e2f | 2019-12-05 13:57:06 +0200 | [diff] [blame] | 634 | |
Juha Hyttinen | e406a34 | 2020-01-13 13:02:26 +0200 | [diff] [blame] | 635 | trans := subs.GetTransaction() |
| 636 | if trans == nil { |
| 637 | xapp.Logger.Error("SubDelReq timeout: Unknown trans. Dropping this msg. SubId: %v", subs.GetSubId()) |
Juha Hyttinen | 0d064ec | 2020-01-09 09:08:53 +0200 | [diff] [blame] | 638 | return |
| 639 | } |
| 640 | |
Juha Hyttinen | e406a34 | 2020-01-13 13:02:26 +0200 | [diff] [blame] | 641 | responseReceived := trans.CheckResponseReceived() |
Anssi Mannila | 8046c70 | 2020-01-02 13:39:05 +0200 | [diff] [blame] | 642 | if responseReceived == true { |
| 643 | // Subscription Delete Response or Failure already received |
| 644 | return |
Anssi Mannila | 2e99e2f | 2019-12-05 13:57:06 +0200 | [diff] [blame] | 645 | } |
Juha Hyttinen | ff8dccd | 2019-12-10 14:34:07 +0200 | [diff] [blame] | 646 | |
Anssi Mannila | 8046c70 | 2020-01-02 13:39:05 +0200 | [diff] [blame] | 647 | if tryCount < maxSubDelReqTryCount { |
Anssi Mannila | 8046c70 | 2020-01-02 13:39:05 +0200 | [diff] [blame] | 648 | // Set possible to handle new response for the subId |
Juha Hyttinen | e406a34 | 2020-01-13 13:02:26 +0200 | [diff] [blame] | 649 | trans.RetryTransaction() |
Juha Hyttinen | 63284a2 | 2020-01-15 10:45:11 +0200 | [diff] [blame] | 650 | c.rmrSend("SubDelReq timeout: SubDelReq to E2T", subs, trans) |
Anssi Mannila | 8046c70 | 2020-01-02 13:39:05 +0200 | [diff] [blame] | 651 | tryCount++ |
Juha Hyttinen | e406a34 | 2020-01-13 13:02:26 +0200 | [diff] [blame] | 652 | c.timerMap.StartTimer("RIC_SUB_DEL_REQ", int(subs.GetSubId()), subReqTime, tryCount, c.handleSubscriptionDeleteRequestTimer) |
Anssi Mannila | 8046c70 | 2020-01-02 13:39:05 +0200 | [diff] [blame] | 653 | return |
| 654 | } |
| 655 | |
Juha Hyttinen | 375c141 | 2020-01-14 20:17:50 +0200 | [diff] [blame] | 656 | c.sendSubscriptionDeleteResponse("SubDelReq(timer)", trans, subs) |
| 657 | return |
| 658 | } |
| 659 | |
| 660 | func (c *Control) sendSubscriptionDeleteResponse(desc string, trans *Transaction, subs *Subscription) { |
| 661 | |
Juha Hyttinen | e406a34 | 2020-01-13 13:02:26 +0200 | [diff] [blame] | 662 | if trans.ForwardRespToXapp == true { |
Juha Hyttinen | 375c141 | 2020-01-14 20:17:50 +0200 | [diff] [blame] | 663 | //Always generate SubDelResp |
| 664 | trans.SubDelRespMsg = &e2ap.E2APSubscriptionDeleteResponse{} |
| 665 | trans.SubDelRespMsg.RequestId.Id = trans.SubDelReqMsg.RequestId.Id |
| 666 | trans.SubDelRespMsg.RequestId.Seq = uint32(subs.GetSubId()) |
| 667 | trans.SubDelRespMsg.FunctionId = trans.SubDelReqMsg.FunctionId |
| 668 | |
Juha Hyttinen | 9340072 | 2020-01-15 09:25:13 +0200 | [diff] [blame] | 669 | var err error |
Juha Hyttinen | 63284a2 | 2020-01-15 10:45:11 +0200 | [diff] [blame] | 670 | trans.Mtype, trans.Payload, err = c.e2ap.PackSubscriptionDeleteResponse(trans.SubDelRespMsg) |
Juha Hyttinen | 375c141 | 2020-01-14 20:17:50 +0200 | [diff] [blame] | 671 | if err == nil { |
Juha Hyttinen | 63284a2 | 2020-01-15 10:45:11 +0200 | [diff] [blame] | 672 | c.rmrReplyToSender(desc+": SubDelResp to xapp", subs, trans) |
Juha Hyttinen | 375c141 | 2020-01-14 20:17:50 +0200 | [diff] [blame] | 673 | time.Sleep(3 * time.Second) |
| 674 | } else { |
| 675 | //TODO error handling improvement |
| 676 | xapp.Logger.Error("%s: %s for trans %s (continuing cleaning)", desc, err.Error(), trans) |
Anssi Mannila | 8046c70 | 2020-01-02 13:39:05 +0200 | [diff] [blame] | 677 | } |
Anssi Mannila | 8046c70 | 2020-01-02 13:39:05 +0200 | [diff] [blame] | 678 | } |
Juha Hyttinen | 375c141 | 2020-01-14 20:17:50 +0200 | [diff] [blame] | 679 | |
Juha Hyttinen | e406a34 | 2020-01-13 13:02:26 +0200 | [diff] [blame] | 680 | trans.Release() |
Juha Hyttinen | 56e0383 | 2020-01-14 17:08:43 +0200 | [diff] [blame] | 681 | subs.Release() |
Anssi Mannila | f1d0eb6 | 2019-12-17 15:29:55 +0200 | [diff] [blame] | 682 | } |