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