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