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" |
Anssi Mannila | c92b421 | 2020-12-07 14:59:34 +0200 | [diff] [blame] | 24 | "net/http" |
Anssi Mannila | 54838ed | 2021-11-19 11:25:01 +0200 | [diff] [blame] | 25 | "sync" |
Anssi Mannila | c92b421 | 2020-12-07 14:59:34 +0200 | [diff] [blame] | 26 | "time" |
| 27 | |
Juha Hyttinen | 86a4620 | 2020-01-14 12:49:09 +0200 | [diff] [blame] | 28 | "gerrit.o-ran-sc.org/r/ric-plt/e2ap/pkg/e2ap" |
kalnagy | 93cc3e2 | 2019-09-19 11:29:29 +0200 | [diff] [blame] | 29 | rtmgrclient "gerrit.o-ran-sc.org/r/ric-plt/submgr/pkg/rtmgr_client" |
Juha Hyttinen | c9eb08a | 2020-02-28 08:53:33 +0200 | [diff] [blame] | 30 | "gerrit.o-ran-sc.org/r/ric-plt/xapp-frame/pkg/models" |
Anssi Mannila | f682ace | 2021-09-28 13:11:25 +0300 | [diff] [blame] | 31 | "gerrit.o-ran-sc.org/r/ric-plt/xapp-frame/pkg/restapi/operations/common" |
kalnagy | 1455c85 | 2019-10-21 13:06:23 +0200 | [diff] [blame] | 32 | "gerrit.o-ran-sc.org/r/ric-plt/xapp-frame/pkg/xapp" |
| 33 | httptransport "github.com/go-openapi/runtime/client" |
| 34 | "github.com/go-openapi/strfmt" |
archagge | afbf95f | 2021-04-14 08:54:05 +0300 | [diff] [blame] | 35 | "github.com/segmentio/ksuid" |
kalnagy | 1455c85 | 2019-10-21 13:06:23 +0200 | [diff] [blame] | 36 | "github.com/spf13/viper" |
kalnagy | 4511475 | 2019-06-18 14:40:39 +0200 | [diff] [blame] | 37 | ) |
| 38 | |
Juha Hyttinen | e406a34 | 2020-01-13 13:02:26 +0200 | [diff] [blame] | 39 | //----------------------------------------------------------------------------- |
| 40 | // |
| 41 | //----------------------------------------------------------------------------- |
| 42 | |
Juha Hyttinen | 5f8ffa0 | 2020-02-06 15:28:59 +0200 | [diff] [blame] | 43 | func idstring(err error, entries ...fmt.Stringer) string { |
| 44 | var retval string = "" |
| 45 | var filler string = "" |
| 46 | for _, entry := range entries { |
Markku Virtanen | 42723e2 | 2021-06-15 10:09:23 +0300 | [diff] [blame] | 47 | if entry != nil { |
| 48 | retval += filler + entry.String() |
| 49 | filler = " " |
| 50 | } else { |
| 51 | retval += filler + "(NIL)" |
| 52 | } |
Juha Hyttinen | 5f8ffa0 | 2020-02-06 15:28:59 +0200 | [diff] [blame] | 53 | } |
| 54 | if err != nil { |
| 55 | retval += filler + "err(" + err.Error() + ")" |
| 56 | filler = " " |
Juha Hyttinen | 5f8ffa0 | 2020-02-06 15:28:59 +0200 | [diff] [blame] | 57 | } |
| 58 | return retval |
| 59 | } |
| 60 | |
| 61 | //----------------------------------------------------------------------------- |
| 62 | // |
| 63 | //----------------------------------------------------------------------------- |
| 64 | |
Anssi Mannila | 2f26fb2 | 2020-12-07 08:32:13 +0200 | [diff] [blame] | 65 | var e2tSubReqTimeout time.Duration |
| 66 | var e2tSubDelReqTime time.Duration |
| 67 | var e2tRecvMsgTimeout time.Duration |
Markku Virtanen | fe2cdab | 2021-05-21 10:59:29 +0000 | [diff] [blame] | 68 | var waitRouteCleanup_ms time.Duration |
Anssi Mannila | 2f26fb2 | 2020-12-07 08:32:13 +0200 | [diff] [blame] | 69 | var e2tMaxSubReqTryCount uint64 // Initial try + retry |
| 70 | var e2tMaxSubDelReqTryCount uint64 // Initial try + retry |
Anssi Mannila | c7da4ee | 2021-10-22 09:52:02 +0300 | [diff] [blame] | 71 | var checkE2State string |
Anssi Mannila | c92b421 | 2020-12-07 14:59:34 +0200 | [diff] [blame] | 72 | var readSubsFromDb string |
Anssi Mannila | b73e7cd | 2021-08-03 11:57:11 +0300 | [diff] [blame] | 73 | var dbRetryForever string |
| 74 | var dbTryCount int |
Himanshu Puorhit | 84662c4 | 2023-08-29 15:46:18 +0530 | [diff] [blame^] | 75 | var e2IEOrderCheckValue uint8 |
Anssi Mannila | 2e99e2f | 2019-12-05 13:57:06 +0200 | [diff] [blame] | 76 | |
kalnagy | 4511475 | 2019-06-18 14:40:39 +0200 | [diff] [blame] | 77 | type Control struct { |
Juha Hyttinen | 9dc5adc | 2020-08-13 10:02:40 +0300 | [diff] [blame] | 78 | *xapp.RMRClient |
Anssi Mannila | 3cdd2e0 | 2021-10-14 12:35:41 +0300 | [diff] [blame] | 79 | e2ap *E2ap |
| 80 | registry *Registry |
| 81 | tracker *Tracker |
| 82 | restDuplicateCtrl *DuplicateCtrl |
Anssi Mannila | c7da4ee | 2021-10-22 09:52:02 +0300 | [diff] [blame] | 83 | e2IfState *E2IfState |
| 84 | e2IfStateDb XappRnibInterface |
Anssi Mannila | 3cdd2e0 | 2021-10-14 12:35:41 +0300 | [diff] [blame] | 85 | e2SubsDb Sdlnterface |
| 86 | restSubsDb Sdlnterface |
| 87 | CntRecvMsg uint64 |
| 88 | ResetTestFlag bool |
| 89 | Counters map[string]xapp.Counter |
| 90 | LoggerLevel int |
| 91 | UTTesting bool |
kalnagy | 93cc3e2 | 2019-09-19 11:29:29 +0200 | [diff] [blame] | 92 | } |
| 93 | |
| 94 | type RMRMeid struct { |
Juha Hyttinen | ff8dccd | 2019-12-10 14:34:07 +0200 | [diff] [blame] | 95 | PlmnID string |
| 96 | EnbID string |
Anssi Mannila | 2e99e2f | 2019-12-05 13:57:06 +0200 | [diff] [blame] | 97 | RanName string |
kalnagy | 93cc3e2 | 2019-09-19 11:29:29 +0200 | [diff] [blame] | 98 | } |
| 99 | |
Anssi Mannila | c92b421 | 2020-12-07 14:59:34 +0200 | [diff] [blame] | 100 | type SubmgrRestartTestEvent struct{} |
| 101 | type SubmgrRestartUpEvent struct{} |
Anssi Mannila | f682ace | 2021-09-28 13:11:25 +0300 | [diff] [blame] | 102 | type PackSubscriptionRequestErrortEvent struct { |
| 103 | ErrorInfo ErrorInfo |
| 104 | } |
| 105 | |
| 106 | func (p *PackSubscriptionRequestErrortEvent) SetEvent(errorInfo *ErrorInfo) { |
| 107 | p.ErrorInfo = *errorInfo |
| 108 | } |
| 109 | |
| 110 | type SDLWriteErrortEvent struct { |
| 111 | ErrorInfo ErrorInfo |
| 112 | } |
| 113 | |
| 114 | func (s *SDLWriteErrortEvent) SetEvent(errorInfo *ErrorInfo) { |
| 115 | s.ErrorInfo = *errorInfo |
| 116 | } |
Anssi Mannila | c92b421 | 2020-12-07 14:59:34 +0200 | [diff] [blame] | 117 | |
Peter Szilagyi | fbc56f9 | 2019-07-23 19:29:46 +0000 | [diff] [blame] | 118 | func init() { |
Anssi Mannila | f682ace | 2021-09-28 13:11:25 +0300 | [diff] [blame] | 119 | xapp.Logger.Debug("SUBMGR") |
Peter Szilagyi | fbc56f9 | 2019-07-23 19:29:46 +0000 | [diff] [blame] | 120 | viper.AutomaticEnv() |
| 121 | viper.SetEnvPrefix("submgr") |
| 122 | viper.AllowEmptyEnv(true) |
kalnagy | 4511475 | 2019-06-18 14:40:39 +0200 | [diff] [blame] | 123 | } |
| 124 | |
Juha Hyttinen | ff8dccd | 2019-12-10 14:34:07 +0200 | [diff] [blame] | 125 | func NewControl() *Control { |
Juha Hyttinen | 0388dd9 | 2020-01-09 14:14:16 +0200 | [diff] [blame] | 126 | |
Anssi Mannila | c92b421 | 2020-12-07 14:59:34 +0200 | [diff] [blame] | 127 | transport := httptransport.New(viper.GetString("rtmgr.HostAddr")+":"+viper.GetString("rtmgr.port"), viper.GetString("rtmgr.baseUrl"), []string{"http"}) |
| 128 | rtmgrClient := RtmgrClient{rtClient: rtmgrclient.New(transport, strfmt.Default)} |
| 129 | |
| 130 | registry := new(Registry) |
| 131 | registry.Initialize() |
| 132 | registry.rtmgrClient = &rtmgrClient |
| 133 | |
| 134 | tracker := new(Tracker) |
| 135 | tracker.Init() |
| 136 | |
Anssi Mannila | 3cdd2e0 | 2021-10-14 12:35:41 +0300 | [diff] [blame] | 137 | restDuplicateCtrl := new(DuplicateCtrl) |
| 138 | restDuplicateCtrl.Init() |
| 139 | |
Anssi Mannila | c7da4ee | 2021-10-22 09:52:02 +0300 | [diff] [blame] | 140 | e2IfState := new(E2IfState) |
| 141 | |
Anssi Mannila | c92b421 | 2020-12-07 14:59:34 +0200 | [diff] [blame] | 142 | c := &Control{e2ap: new(E2ap), |
Anssi Mannila | 3cdd2e0 | 2021-10-14 12:35:41 +0300 | [diff] [blame] | 143 | registry: registry, |
| 144 | tracker: tracker, |
| 145 | restDuplicateCtrl: restDuplicateCtrl, |
Anssi Mannila | c7da4ee | 2021-10-22 09:52:02 +0300 | [diff] [blame] | 146 | e2IfState: e2IfState, |
| 147 | e2IfStateDb: CreateXappRnibIfInstance(), |
Anssi Mannila | 3cdd2e0 | 2021-10-14 12:35:41 +0300 | [diff] [blame] | 148 | e2SubsDb: CreateSdl(), |
| 149 | restSubsDb: CreateRESTSdl(), |
| 150 | Counters: xapp.Metric.RegisterCounterGroup(GetMetricsOpts(), "SUBMGR"), |
Anssi Mannila | e1af87f | 2021-11-10 13:10:54 +0200 | [diff] [blame] | 151 | LoggerLevel: 1, |
Anssi Mannila | c92b421 | 2020-12-07 14:59:34 +0200 | [diff] [blame] | 152 | } |
Anssi Mannila | c7da4ee | 2021-10-22 09:52:02 +0300 | [diff] [blame] | 153 | |
| 154 | e2IfState.Init(c) |
Anssi Mannila | f6b7804 | 2021-02-18 12:36:59 +0200 | [diff] [blame] | 155 | c.ReadConfigParameters("") |
Anssi Mannila | c92b421 | 2020-12-07 14:59:34 +0200 | [diff] [blame] | 156 | |
| 157 | // Register REST handler for testing support |
Anssi Mannila | 92c3855 | 2021-12-29 09:59:24 +0200 | [diff] [blame] | 158 | xapp.Resource.InjectRoute("/ric/v1/symptomdata", c.SymptomDataHandler, "GET") |
Anssi Mannila | c92b421 | 2020-12-07 14:59:34 +0200 | [diff] [blame] | 159 | xapp.Resource.InjectRoute("/ric/v1/test/{testId}", c.TestRestHandler, "POST") |
Anssi Mannila | b73e7cd | 2021-08-03 11:57:11 +0300 | [diff] [blame] | 160 | xapp.Resource.InjectRoute("/ric/v1/restsubscriptions", c.GetAllRestSubscriptions, "GET") |
Anssi Mannila | 92c3855 | 2021-12-29 09:59:24 +0200 | [diff] [blame] | 161 | |
| 162 | xapp.Resource.InjectRoute("/ric/v1/get_all_e2nodes", c.GetAllE2Nodes, "GET") |
| 163 | xapp.Resource.InjectRoute("/ric/v1/get_e2node_rest_subscriptions/{ranName}", c.GetAllE2NodeRestSubscriptions, "GET") |
| 164 | |
| 165 | xapp.Resource.InjectRoute("/ric/v1/get_all_xapps", c.GetAllXapps, "GET") |
| 166 | xapp.Resource.InjectRoute("/ric/v1/get_xapp_rest_restsubscriptions/{xappServiceName}", c.GetAllXappRestSubscriptions, "GET") |
| 167 | xapp.Resource.InjectRoute("/ric/v1/get_e2subscriptions/{restId}", c.GetE2Subscriptions, "GET") |
| 168 | |
Anssi Mannila | d13ba63 | 2022-01-04 14:22:26 +0200 | [diff] [blame] | 169 | xapp.Resource.InjectRoute("/ric/v1/delete_all_e2node_subscriptions/{ranName}", c.DeleteAllE2nodeSubscriptions, "DELETE") |
| 170 | xapp.Resource.InjectRoute("/ric/v1/delete_all_xapp_subscriptions/{xappServiceName}", c.DeleteAllXappSubscriptions, "DELETE") |
Anssi Mannila | c92b421 | 2020-12-07 14:59:34 +0200 | [diff] [blame] | 171 | |
Anssi Mannila | e1af87f | 2021-11-10 13:10:54 +0200 | [diff] [blame] | 172 | if readSubsFromDb == "true" { |
| 173 | // Read subscriptions from db |
Anssi Mannila | 9c4697f | 2022-07-04 15:51:38 +0300 | [diff] [blame] | 174 | err := c.ReadE2Subscriptions() |
| 175 | if err != nil { |
| 176 | xapp.Logger.Error("ReadE2Subscriptions() failed %s", err.Error()) |
| 177 | } |
| 178 | err = c.ReadRESTSubscriptions() |
| 179 | if err != nil { |
| 180 | xapp.Logger.Error("ReadRESTSubscriptions() failed %s", err.Error()) |
| 181 | } |
Anssi Mannila | c92b421 | 2020-12-07 14:59:34 +0200 | [diff] [blame] | 182 | } |
| 183 | |
Anssi Mannila | 55d6fed | 2022-08-02 12:41:48 +0300 | [diff] [blame] | 184 | go func() { |
| 185 | err := xapp.Subscription.Listen(c.RESTSubscriptionHandler, c.RESTQueryHandler, c.RESTSubscriptionDeleteHandler) |
| 186 | if err != nil { |
| 187 | xapp.Logger.Error("xapp.Subscription.Listen failure: %s", err.Error()) |
| 188 | } |
| 189 | }() |
Anssi Mannila | c92b421 | 2020-12-07 14:59:34 +0200 | [diff] [blame] | 190 | return c |
| 191 | } |
| 192 | |
Abukar Mohamed | fbd4df5 | 2021-03-11 06:13:27 +0000 | [diff] [blame] | 193 | func (c *Control) SymptomDataHandler(w http.ResponseWriter, r *http.Request) { |
Anssi Mannila | 9c4697f | 2022-07-04 15:51:38 +0300 | [diff] [blame] | 194 | subscriptions, err := c.registry.QueryHandler() |
| 195 | if err != nil { |
| 196 | xapp.Logger.Error("QueryHandler() failed %s", err.Error()) |
| 197 | } |
| 198 | |
Abukar Mohamed | fbd4df5 | 2021-03-11 06:13:27 +0000 | [diff] [blame] | 199 | xapp.Resource.SendSymptomDataJson(w, r, subscriptions, "platform/subscriptions.json") |
| 200 | } |
| 201 | |
Anssi Mannila | c92b421 | 2020-12-07 14:59:34 +0200 | [diff] [blame] | 202 | //------------------------------------------------------------------- |
| 203 | // |
| 204 | //------------------------------------------------------------------- |
Anssi Mannila | 92c3855 | 2021-12-29 09:59:24 +0200 | [diff] [blame] | 205 | func (c *Control) RESTQueryHandler() (models.SubscriptionList, error) { |
| 206 | xapp.Logger.Debug("RESTQueryHandler() called") |
| 207 | |
| 208 | c.CntRecvMsg++ |
| 209 | |
| 210 | return c.registry.QueryHandler() |
Anssi Mannila | b73e7cd | 2021-08-03 11:57:11 +0300 | [diff] [blame] | 211 | } |
| 212 | |
| 213 | //------------------------------------------------------------------- |
| 214 | // |
| 215 | //------------------------------------------------------------------- |
| 216 | func (c *Control) ReadE2Subscriptions() error { |
| 217 | var err error |
| 218 | var subIds []uint32 |
| 219 | var register map[uint32]*Subscription |
| 220 | for i := 0; dbRetryForever == "true" || i < dbTryCount; i++ { |
Anssi Mannila | f682ace | 2021-09-28 13:11:25 +0300 | [diff] [blame] | 221 | xapp.Logger.Debug("Reading E2 subscriptions from db") |
Anssi Mannila | b73e7cd | 2021-08-03 11:57:11 +0300 | [diff] [blame] | 222 | subIds, register, err = c.ReadAllSubscriptionsFromSdl() |
| 223 | if err != nil { |
| 224 | xapp.Logger.Error("%v", err) |
| 225 | <-time.After(1 * time.Second) |
| 226 | } else { |
| 227 | c.registry.subIds = subIds |
| 228 | c.registry.register = register |
Anssi Mannila | 316b8d2 | 2021-12-21 09:43:59 +0200 | [diff] [blame] | 229 | go c.HandleUncompletedSubscriptions(register) |
Anssi Mannila | b73e7cd | 2021-08-03 11:57:11 +0300 | [diff] [blame] | 230 | return nil |
| 231 | } |
| 232 | } |
Anssi Mannila | f682ace | 2021-09-28 13:11:25 +0300 | [diff] [blame] | 233 | xapp.Logger.Debug("Continuing without retring") |
Anssi Mannila | b73e7cd | 2021-08-03 11:57:11 +0300 | [diff] [blame] | 234 | return err |
| 235 | } |
| 236 | |
| 237 | //------------------------------------------------------------------- |
| 238 | // |
| 239 | //------------------------------------------------------------------- |
| 240 | func (c *Control) ReadRESTSubscriptions() error { |
Anssi Mannila | 54838ed | 2021-11-19 11:25:01 +0200 | [diff] [blame] | 241 | |
| 242 | xapp.Logger.Debug("ReadRESTSubscriptions()") |
Anssi Mannila | b73e7cd | 2021-08-03 11:57:11 +0300 | [diff] [blame] | 243 | var err error |
| 244 | var restSubscriptions map[string]*RESTSubscription |
| 245 | for i := 0; dbRetryForever == "true" || i < dbTryCount; i++ { |
Anssi Mannila | f682ace | 2021-09-28 13:11:25 +0300 | [diff] [blame] | 246 | xapp.Logger.Debug("Reading REST subscriptions from db") |
Anssi Mannila | b73e7cd | 2021-08-03 11:57:11 +0300 | [diff] [blame] | 247 | restSubscriptions, err = c.ReadAllRESTSubscriptionsFromSdl() |
| 248 | if err != nil { |
| 249 | xapp.Logger.Error("%v", err) |
| 250 | <-time.After(1 * time.Second) |
| 251 | } else { |
Anssi Mannila | 54838ed | 2021-11-19 11:25:01 +0200 | [diff] [blame] | 252 | // Fix REST subscriptions ongoing status after restart |
| 253 | for restSubId, restSubscription := range restSubscriptions { |
| 254 | restSubscription.SubReqOngoing = false |
| 255 | restSubscription.SubDelReqOngoing = false |
Anssi Mannila | 9c4697f | 2022-07-04 15:51:38 +0300 | [diff] [blame] | 256 | err := c.WriteRESTSubscriptionToSdl(restSubId, restSubscription) |
| 257 | if err != nil { |
| 258 | xapp.Logger.Error("WriteRESTSubscriptionToSdl() failed:%s", err.Error()) |
| 259 | } |
Anssi Mannila | 54838ed | 2021-11-19 11:25:01 +0200 | [diff] [blame] | 260 | } |
Anssi Mannila | b73e7cd | 2021-08-03 11:57:11 +0300 | [diff] [blame] | 261 | c.registry.restSubscriptions = restSubscriptions |
| 262 | return nil |
| 263 | } |
| 264 | } |
Anssi Mannila | f682ace | 2021-09-28 13:11:25 +0300 | [diff] [blame] | 265 | xapp.Logger.Debug("Continuing without retring") |
Anssi Mannila | b73e7cd | 2021-08-03 11:57:11 +0300 | [diff] [blame] | 266 | return err |
| 267 | } |
| 268 | |
| 269 | //------------------------------------------------------------------- |
| 270 | // |
| 271 | //------------------------------------------------------------------- |
Anssi Mannila | f6b7804 | 2021-02-18 12:36:59 +0200 | [diff] [blame] | 272 | func (c *Control) ReadConfigParameters(f string) { |
Anssi Mannila | c92b421 | 2020-12-07 14:59:34 +0200 | [diff] [blame] | 273 | |
Anssi Mannila | c7da4ee | 2021-10-22 09:52:02 +0300 | [diff] [blame] | 274 | xapp.Logger.Debug("ReadConfigParameters") |
| 275 | |
Anssi Mannila | f682ace | 2021-09-28 13:11:25 +0300 | [diff] [blame] | 276 | c.LoggerLevel = int(xapp.Logger.GetLevel()) |
Anssi Mannila | 3d80b72 | 2021-11-12 13:17:15 +0200 | [diff] [blame] | 277 | xapp.Logger.Info("LoggerLevel = %v", c.LoggerLevel) |
Anssi Mannila | e1af87f | 2021-11-10 13:10:54 +0200 | [diff] [blame] | 278 | c.e2ap.SetASN1DebugPrintStatus(c.LoggerLevel) |
Anssi Mannila | f682ace | 2021-09-28 13:11:25 +0300 | [diff] [blame] | 279 | |
Anssi Mannila | 2f26fb2 | 2020-12-07 08:32:13 +0200 | [diff] [blame] | 280 | // viper.GetDuration returns nanoseconds |
| 281 | e2tSubReqTimeout = viper.GetDuration("controls.e2tSubReqTimeout_ms") * 1000000 |
Juha Hyttinen | 57140bc | 2020-12-11 13:03:06 +0200 | [diff] [blame] | 282 | if e2tSubReqTimeout == 0 { |
| 283 | e2tSubReqTimeout = 2000 * 1000000 |
Anssi Mannila | c7da4ee | 2021-10-22 09:52:02 +0300 | [diff] [blame] | 284 | xapp.Logger.Debug("WARNING: Using hard coded default value for e2tSubReqTimeout") |
Juha Hyttinen | 57140bc | 2020-12-11 13:03:06 +0200 | [diff] [blame] | 285 | } |
Anssi Mannila | c7da4ee | 2021-10-22 09:52:02 +0300 | [diff] [blame] | 286 | xapp.Logger.Debug("e2tSubReqTimeout= %v", e2tSubReqTimeout) |
Anssi Mannila | f682ace | 2021-09-28 13:11:25 +0300 | [diff] [blame] | 287 | |
Anssi Mannila | 2f26fb2 | 2020-12-07 08:32:13 +0200 | [diff] [blame] | 288 | e2tSubDelReqTime = viper.GetDuration("controls.e2tSubDelReqTime_ms") * 1000000 |
Juha Hyttinen | 57140bc | 2020-12-11 13:03:06 +0200 | [diff] [blame] | 289 | if e2tSubDelReqTime == 0 { |
| 290 | e2tSubDelReqTime = 2000 * 1000000 |
Anssi Mannila | c7da4ee | 2021-10-22 09:52:02 +0300 | [diff] [blame] | 291 | xapp.Logger.Debug("WARNING: Using hard coded default value for e2tSubDelReqTime") |
Juha Hyttinen | 57140bc | 2020-12-11 13:03:06 +0200 | [diff] [blame] | 292 | } |
Anssi Mannila | c7da4ee | 2021-10-22 09:52:02 +0300 | [diff] [blame] | 293 | xapp.Logger.Debug("e2tSubDelReqTime= %v", e2tSubDelReqTime) |
| 294 | |
Anssi Mannila | 2f26fb2 | 2020-12-07 08:32:13 +0200 | [diff] [blame] | 295 | e2tRecvMsgTimeout = viper.GetDuration("controls.e2tRecvMsgTimeout_ms") * 1000000 |
Juha Hyttinen | 57140bc | 2020-12-11 13:03:06 +0200 | [diff] [blame] | 296 | if e2tRecvMsgTimeout == 0 { |
| 297 | e2tRecvMsgTimeout = 2000 * 1000000 |
Anssi Mannila | c7da4ee | 2021-10-22 09:52:02 +0300 | [diff] [blame] | 298 | xapp.Logger.Debug("WARNING: Using hard coded default value for e2tRecvMsgTimeout") |
Juha Hyttinen | 57140bc | 2020-12-11 13:03:06 +0200 | [diff] [blame] | 299 | } |
Anssi Mannila | c7da4ee | 2021-10-22 09:52:02 +0300 | [diff] [blame] | 300 | xapp.Logger.Debug("e2tRecvMsgTimeout= %v", e2tRecvMsgTimeout) |
Markku Virtanen | fe2cdab | 2021-05-21 10:59:29 +0000 | [diff] [blame] | 301 | |
Anssi Mannila | 2f26fb2 | 2020-12-07 08:32:13 +0200 | [diff] [blame] | 302 | e2tMaxSubReqTryCount = viper.GetUint64("controls.e2tMaxSubReqTryCount") |
Juha Hyttinen | 57140bc | 2020-12-11 13:03:06 +0200 | [diff] [blame] | 303 | if e2tMaxSubReqTryCount == 0 { |
| 304 | e2tMaxSubReqTryCount = 1 |
Anssi Mannila | c7da4ee | 2021-10-22 09:52:02 +0300 | [diff] [blame] | 305 | xapp.Logger.Debug("WARNING: Using hard coded default value for e2tMaxSubReqTryCount") |
Juha Hyttinen | 57140bc | 2020-12-11 13:03:06 +0200 | [diff] [blame] | 306 | } |
Anssi Mannila | c7da4ee | 2021-10-22 09:52:02 +0300 | [diff] [blame] | 307 | xapp.Logger.Debug("e2tMaxSubReqTryCount= %v", e2tMaxSubReqTryCount) |
Markku Virtanen | fe2cdab | 2021-05-21 10:59:29 +0000 | [diff] [blame] | 308 | |
Anssi Mannila | 2f26fb2 | 2020-12-07 08:32:13 +0200 | [diff] [blame] | 309 | e2tMaxSubDelReqTryCount = viper.GetUint64("controls.e2tMaxSubDelReqTryCount") |
Juha Hyttinen | 57140bc | 2020-12-11 13:03:06 +0200 | [diff] [blame] | 310 | if e2tMaxSubDelReqTryCount == 0 { |
| 311 | e2tMaxSubDelReqTryCount = 1 |
Anssi Mannila | c7da4ee | 2021-10-22 09:52:02 +0300 | [diff] [blame] | 312 | xapp.Logger.Debug("WARNING: Using hard coded default value for e2tMaxSubDelReqTryCount") |
Juha Hyttinen | 57140bc | 2020-12-11 13:03:06 +0200 | [diff] [blame] | 313 | } |
Anssi Mannila | c7da4ee | 2021-10-22 09:52:02 +0300 | [diff] [blame] | 314 | xapp.Logger.Debug("e2tMaxSubDelReqTryCount= %v", e2tMaxSubDelReqTryCount) |
| 315 | |
| 316 | checkE2State = viper.GetString("controls.checkE2State") |
| 317 | if checkE2State == "" { |
| 318 | checkE2State = "true" |
| 319 | xapp.Logger.Debug("WARNING: Using hard coded default value for checkE2State") |
| 320 | } |
| 321 | xapp.Logger.Debug("checkE2State= %v", checkE2State) |
Anssi Mannila | 2f26fb2 | 2020-12-07 08:32:13 +0200 | [diff] [blame] | 322 | |
Anssi Mannila | c92b421 | 2020-12-07 14:59:34 +0200 | [diff] [blame] | 323 | readSubsFromDb = viper.GetString("controls.readSubsFromDb") |
| 324 | if readSubsFromDb == "" { |
| 325 | readSubsFromDb = "true" |
Anssi Mannila | c7da4ee | 2021-10-22 09:52:02 +0300 | [diff] [blame] | 326 | xapp.Logger.Debug("WARNING: Using hard coded default value for readSubsFromDb") |
Juha Hyttinen | 5f8ffa0 | 2020-02-06 15:28:59 +0200 | [diff] [blame] | 327 | } |
Anssi Mannila | c7da4ee | 2021-10-22 09:52:02 +0300 | [diff] [blame] | 328 | xapp.Logger.Debug("readSubsFromDb= %v", readSubsFromDb) |
Anssi Mannila | b73e7cd | 2021-08-03 11:57:11 +0300 | [diff] [blame] | 329 | |
| 330 | dbTryCount = viper.GetInt("controls.dbTryCount") |
| 331 | if dbTryCount == 0 { |
| 332 | dbTryCount = 200 |
Anssi Mannila | c7da4ee | 2021-10-22 09:52:02 +0300 | [diff] [blame] | 333 | xapp.Logger.Debug("WARNING: Using hard coded default value for dbTryCount") |
Anssi Mannila | b73e7cd | 2021-08-03 11:57:11 +0300 | [diff] [blame] | 334 | } |
Anssi Mannila | c7da4ee | 2021-10-22 09:52:02 +0300 | [diff] [blame] | 335 | xapp.Logger.Debug("dbTryCount= %v", dbTryCount) |
Anssi Mannila | b73e7cd | 2021-08-03 11:57:11 +0300 | [diff] [blame] | 336 | |
| 337 | dbRetryForever = viper.GetString("controls.dbRetryForever") |
| 338 | if dbRetryForever == "" { |
| 339 | dbRetryForever = "true" |
Anssi Mannila | c7da4ee | 2021-10-22 09:52:02 +0300 | [diff] [blame] | 340 | xapp.Logger.Debug("WARNING: Using hard coded default value for dbRetryForever") |
Anssi Mannila | b73e7cd | 2021-08-03 11:57:11 +0300 | [diff] [blame] | 341 | } |
Anssi Mannila | c7da4ee | 2021-10-22 09:52:02 +0300 | [diff] [blame] | 342 | xapp.Logger.Debug("dbRetryForever= %v", dbRetryForever) |
Anssi Mannila | b73e7cd | 2021-08-03 11:57:11 +0300 | [diff] [blame] | 343 | |
| 344 | // Internal cfg parameter, used to define a wait time for RMR route clean-up. None default |
| 345 | // value 100ms used currently only in unittests. |
| 346 | waitRouteCleanup_ms = viper.GetDuration("controls.waitRouteCleanup_ms") * 1000000 |
| 347 | if waitRouteCleanup_ms == 0 { |
| 348 | waitRouteCleanup_ms = 5000 * 1000000 |
Anssi Mannila | c7da4ee | 2021-10-22 09:52:02 +0300 | [diff] [blame] | 349 | xapp.Logger.Debug("WARNING: Using hard coded default value for waitRouteCleanup_ms") |
Anssi Mannila | b73e7cd | 2021-08-03 11:57:11 +0300 | [diff] [blame] | 350 | } |
Anssi Mannila | c7da4ee | 2021-10-22 09:52:02 +0300 | [diff] [blame] | 351 | xapp.Logger.Debug("waitRouteCleanup= %v", waitRouteCleanup_ms) |
Himanshu Puorhit | 84662c4 | 2023-08-29 15:46:18 +0530 | [diff] [blame^] | 352 | |
| 353 | viper.SetDefault("controls.checkE2IEOrder", 1) |
| 354 | e2IEOrderCheckValue = uint8(viper.GetUint("controls.checkE2IEOrder")) |
| 355 | c.e2ap.SetE2IEOrderCheck(e2IEOrderCheckValue) |
| 356 | xapp.Logger.Debug("e2IEOrderCheck= %v", e2IEOrderCheckValue) |
Anssi Mannila | c92b421 | 2020-12-07 14:59:34 +0200 | [diff] [blame] | 357 | } |
| 358 | |
| 359 | //------------------------------------------------------------------- |
| 360 | // |
| 361 | //------------------------------------------------------------------- |
| 362 | func (c *Control) HandleUncompletedSubscriptions(register map[uint32]*Subscription) { |
| 363 | |
| 364 | xapp.Logger.Debug("HandleUncompletedSubscriptions. len(register) = %v", len(register)) |
| 365 | for subId, subs := range register { |
| 366 | if subs.SubRespRcvd == false { |
Anssi Mannila | f682ace | 2021-09-28 13:11:25 +0300 | [diff] [blame] | 367 | // If policy subscription has already been made successfully unsuccessful update should not be deleted. |
| 368 | if subs.PolicyUpdate == false { |
| 369 | subs.NoRespToXapp = true |
| 370 | xapp.Logger.Debug("SendSubscriptionDeleteReq. subId = %v", subId) |
gunjarastogi | 4378baf | 2023-01-18 17:51:55 +0530 | [diff] [blame] | 371 | c.SendSubscriptionDeleteReq(subs, false) |
Anssi Mannila | f682ace | 2021-09-28 13:11:25 +0300 | [diff] [blame] | 372 | } |
Anssi Mannila | c92b421 | 2020-12-07 14:59:34 +0200 | [diff] [blame] | 373 | } |
| 374 | } |
Juha Hyttinen | 5f8ffa0 | 2020-02-06 15:28:59 +0200 | [diff] [blame] | 375 | } |
| 376 | |
| 377 | func (c *Control) ReadyCB(data interface{}) { |
Juha Hyttinen | 9dc5adc | 2020-08-13 10:02:40 +0300 | [diff] [blame] | 378 | if c.RMRClient == nil { |
| 379 | c.RMRClient = xapp.Rmr |
Juha Hyttinen | ff8dccd | 2019-12-10 14:34:07 +0200 | [diff] [blame] | 380 | } |
kalnagy | 4511475 | 2019-06-18 14:40:39 +0200 | [diff] [blame] | 381 | } |
| 382 | |
| 383 | func (c *Control) Run() { |
Juha Hyttinen | 5f8ffa0 | 2020-02-06 15:28:59 +0200 | [diff] [blame] | 384 | xapp.SetReadyCB(c.ReadyCB, nil) |
Anssi Mannila | f6b7804 | 2021-02-18 12:36:59 +0200 | [diff] [blame] | 385 | xapp.AddConfigChangeListener(c.ReadConfigParameters) |
Peter Szilagyi | fbc56f9 | 2019-07-23 19:29:46 +0000 | [diff] [blame] | 386 | xapp.Run(c) |
kalnagy | 4511475 | 2019-06-18 14:40:39 +0200 | [diff] [blame] | 387 | } |
| 388 | |
Juha Hyttinen | c9eb08a | 2020-02-28 08:53:33 +0200 | [diff] [blame] | 389 | //------------------------------------------------------------------- |
| 390 | // |
| 391 | //------------------------------------------------------------------- |
Anssi Mannila | 92c3855 | 2021-12-29 09:59:24 +0200 | [diff] [blame] | 392 | func (c *Control) GetOrCreateRestSubscription(p *models.SubscriptionParams, md5sum string, xAppRmrEndpoint string, xAppServiceName string) (*RESTSubscription, string, error) { |
Markku Virtanen | 42723e2 | 2021-06-15 10:09:23 +0300 | [diff] [blame] | 393 | |
| 394 | var restSubId string |
| 395 | var restSubscription *RESTSubscription |
| 396 | var err error |
| 397 | |
Anssi Mannila | 3cdd2e0 | 2021-10-14 12:35:41 +0300 | [diff] [blame] | 398 | prevRestSubsId, exists := c.restDuplicateCtrl.GetLastKnownRestSubsIdBasedOnMd5sum(md5sum) |
Markku Virtanen | 42723e2 | 2021-06-15 10:09:23 +0300 | [diff] [blame] | 399 | if p.SubscriptionID == "" { |
Anssi Mannila | f682ace | 2021-09-28 13:11:25 +0300 | [diff] [blame] | 400 | // Subscription does not contain REST subscription Id |
Markku Virtanen | 42723e2 | 2021-06-15 10:09:23 +0300 | [diff] [blame] | 401 | if exists { |
| 402 | restSubscription, err = c.registry.GetRESTSubscription(prevRestSubsId, false) |
| 403 | if restSubscription != nil { |
Anssi Mannila | f682ace | 2021-09-28 13:11:25 +0300 | [diff] [blame] | 404 | // Subscription not found |
Markku Virtanen | 42723e2 | 2021-06-15 10:09:23 +0300 | [diff] [blame] | 405 | restSubId = prevRestSubsId |
| 406 | if err == nil { |
Anssi Mannila | f682ace | 2021-09-28 13:11:25 +0300 | [diff] [blame] | 407 | xapp.Logger.Debug("Existing restSubId %s found by MD5sum %s for a request without subscription ID - using previous subscription", prevRestSubsId, md5sum) |
Markku Virtanen | 42723e2 | 2021-06-15 10:09:23 +0300 | [diff] [blame] | 408 | } else { |
Anssi Mannila | f682ace | 2021-09-28 13:11:25 +0300 | [diff] [blame] | 409 | xapp.Logger.Debug("Existing restSubId %s found by MD5sum %s for a request without subscription ID - Note: %s", prevRestSubsId, md5sum, err.Error()) |
Markku Virtanen | 42723e2 | 2021-06-15 10:09:23 +0300 | [diff] [blame] | 410 | } |
| 411 | } else { |
Anssi Mannila | f682ace | 2021-09-28 13:11:25 +0300 | [diff] [blame] | 412 | xapp.Logger.Debug("None existing restSubId %s referred by MD5sum %s for a request without subscription ID - deleting cached entry", prevRestSubsId, md5sum) |
Anssi Mannila | 3cdd2e0 | 2021-10-14 12:35:41 +0300 | [diff] [blame] | 413 | c.restDuplicateCtrl.DeleteLastKnownRestSubsIdBasedOnMd5sum(md5sum) |
Markku Virtanen | 42723e2 | 2021-06-15 10:09:23 +0300 | [diff] [blame] | 414 | } |
| 415 | } |
| 416 | |
| 417 | if restSubscription == nil { |
| 418 | restSubId = ksuid.New().String() |
Anssi Mannila | 92c3855 | 2021-12-29 09:59:24 +0200 | [diff] [blame] | 419 | restSubscription = c.registry.CreateRESTSubscription(&restSubId, &xAppServiceName, &xAppRmrEndpoint, p.Meid) |
Markku Virtanen | 42723e2 | 2021-06-15 10:09:23 +0300 | [diff] [blame] | 420 | } |
| 421 | } else { |
Anssi Mannila | f682ace | 2021-09-28 13:11:25 +0300 | [diff] [blame] | 422 | // Subscription contains REST subscription Id |
Markku Virtanen | 42723e2 | 2021-06-15 10:09:23 +0300 | [diff] [blame] | 423 | restSubId = p.SubscriptionID |
| 424 | |
Anssi Mannila | f682ace | 2021-09-28 13:11:25 +0300 | [diff] [blame] | 425 | xapp.Logger.Debug("RestSubscription ID %s provided via REST request", restSubId) |
Markku Virtanen | 42723e2 | 2021-06-15 10:09:23 +0300 | [diff] [blame] | 426 | restSubscription, err = c.registry.GetRESTSubscription(restSubId, false) |
| 427 | if err != nil { |
Anssi Mannila | f682ace | 2021-09-28 13:11:25 +0300 | [diff] [blame] | 428 | // Subscription with id in REST request does not exist |
Markku Virtanen | 42723e2 | 2021-06-15 10:09:23 +0300 | [diff] [blame] | 429 | xapp.Logger.Error("%s", err.Error()) |
| 430 | c.UpdateCounter(cRestSubFailToXapp) |
Anssi Mannila | cb7dd49 | 2021-10-01 11:10:26 +0300 | [diff] [blame] | 431 | return nil, "", err |
Markku Virtanen | 42723e2 | 2021-06-15 10:09:23 +0300 | [diff] [blame] | 432 | } |
| 433 | |
| 434 | if !exists { |
Anssi Mannila | f682ace | 2021-09-28 13:11:25 +0300 | [diff] [blame] | 435 | xapp.Logger.Debug("Existing restSubscription found for ID %s, new request based on md5sum", restSubId) |
Markku Virtanen | 42723e2 | 2021-06-15 10:09:23 +0300 | [diff] [blame] | 436 | } else { |
Anssi Mannila | f682ace | 2021-09-28 13:11:25 +0300 | [diff] [blame] | 437 | xapp.Logger.Debug("Existing restSubscription found for ID %s(%s), re-transmission based on md5sum match with previous request", prevRestSubsId, restSubId) |
Markku Virtanen | 42723e2 | 2021-06-15 10:09:23 +0300 | [diff] [blame] | 438 | } |
| 439 | } |
| 440 | |
Anssi Mannila | cb7dd49 | 2021-10-01 11:10:26 +0300 | [diff] [blame] | 441 | return restSubscription, restSubId, nil |
Markku Virtanen | 42723e2 | 2021-06-15 10:09:23 +0300 | [diff] [blame] | 442 | } |
| 443 | |
| 444 | //------------------------------------------------------------------- |
| 445 | // |
| 446 | //------------------------------------------------------------------- |
Anssi Mannila | f682ace | 2021-09-28 13:11:25 +0300 | [diff] [blame] | 447 | func (c *Control) RESTSubscriptionHandler(params interface{}) (*models.SubscriptionResponse, int) { |
archagge | afbf95f | 2021-04-14 08:54:05 +0300 | [diff] [blame] | 448 | |
Anssi Mannila | 316d8a1 | 2021-06-02 11:08:54 +0300 | [diff] [blame] | 449 | c.CntRecvMsg++ |
| 450 | c.UpdateCounter(cRestSubReqFromXapp) |
| 451 | |
archagge | afbf95f | 2021-04-14 08:54:05 +0300 | [diff] [blame] | 452 | subResp := models.SubscriptionResponse{} |
archagge | afbf95f | 2021-04-14 08:54:05 +0300 | [diff] [blame] | 453 | p := params.(*models.SubscriptionParams) |
| 454 | |
Anssi Mannila | de457a1 | 2021-06-02 16:19:48 +0300 | [diff] [blame] | 455 | if c.LoggerLevel > 2 { |
| 456 | c.PrintRESTSubscriptionRequest(p) |
| 457 | } |
| 458 | |
naman.gupta | 7dbc4ad | 2023-05-09 17:24:05 +0530 | [diff] [blame] | 459 | if c.e2IfState.IsE2ConnectionUp(p.Meid) == false || c.e2IfState.IsE2ConnectionUnderReset(p.Meid) == true { |
| 460 | if c.e2IfState.IsE2ConnectionUp(p.Meid) == false { |
| 461 | xapp.Logger.Error("No E2 connection for ranName %v", *p.Meid) |
| 462 | } else if c.e2IfState.IsE2ConnectionUnderReset(p.Meid) == true { |
| 463 | xapp.Logger.Error("E2 Node for ranName %v UNDER RESET", *p.Meid) |
| 464 | } |
Anssi Mannila | c7da4ee | 2021-10-22 09:52:02 +0300 | [diff] [blame] | 465 | c.UpdateCounter(cRestReqRejDueE2Down) |
| 466 | return nil, common.SubscribeServiceUnavailableCode |
| 467 | } |
| 468 | |
archagge | afbf95f | 2021-04-14 08:54:05 +0300 | [diff] [blame] | 469 | if p.ClientEndpoint == nil { |
Anssi Mannila | f682ace | 2021-09-28 13:11:25 +0300 | [diff] [blame] | 470 | err := fmt.Errorf("ClientEndpoint == nil") |
| 471 | xapp.Logger.Error("%v", err) |
Anssi Mannila | 316d8a1 | 2021-06-02 11:08:54 +0300 | [diff] [blame] | 472 | c.UpdateCounter(cRestSubFailToXapp) |
Anssi Mannila | cb7dd49 | 2021-10-01 11:10:26 +0300 | [diff] [blame] | 473 | return nil, common.SubscribeBadRequestCode |
archagge | afbf95f | 2021-04-14 08:54:05 +0300 | [diff] [blame] | 474 | } |
| 475 | |
Anssi Mannila | 6bd5791 | 2022-06-16 09:47:23 +0300 | [diff] [blame] | 476 | e2SubscriptionDirectives, err := c.GetE2SubscriptionDirectives(p) |
| 477 | if err != nil { |
| 478 | xapp.Logger.Error("%s", err) |
| 479 | c.UpdateCounter(cRestSubFailToXapp) |
| 480 | return nil, common.SubscribeBadRequestCode |
| 481 | } |
archagge | afbf95f | 2021-04-14 08:54:05 +0300 | [diff] [blame] | 482 | _, xAppRmrEndpoint, err := ConstructEndpointAddresses(*p.ClientEndpoint) |
| 483 | if err != nil { |
| 484 | xapp.Logger.Error("%s", err.Error()) |
Anssi Mannila | 316d8a1 | 2021-06-02 11:08:54 +0300 | [diff] [blame] | 485 | c.UpdateCounter(cRestSubFailToXapp) |
Anssi Mannila | cb7dd49 | 2021-10-01 11:10:26 +0300 | [diff] [blame] | 486 | return nil, common.SubscribeBadRequestCode |
archagge | afbf95f | 2021-04-14 08:54:05 +0300 | [diff] [blame] | 487 | } |
| 488 | |
Markku Virtanen | 42723e2 | 2021-06-15 10:09:23 +0300 | [diff] [blame] | 489 | md5sum, err := CalculateRequestMd5sum(params) |
| 490 | if err != nil { |
| 491 | xapp.Logger.Error("Failed to generate md5sum from incoming request - %s", err.Error()) |
| 492 | } |
| 493 | |
Anssi Mannila | 92c3855 | 2021-12-29 09:59:24 +0200 | [diff] [blame] | 494 | restSubscription, restSubId, err := c.GetOrCreateRestSubscription(p, md5sum, xAppRmrEndpoint, p.ClientEndpoint.Host) |
Markku Virtanen | 42723e2 | 2021-06-15 10:09:23 +0300 | [diff] [blame] | 495 | if err != nil { |
Anssi Mannila | cb7dd49 | 2021-10-01 11:10:26 +0300 | [diff] [blame] | 496 | xapp.Logger.Error("Subscription with id in REST request does not exist") |
| 497 | return nil, common.SubscribeNotFoundCode |
archagge | afbf95f | 2021-04-14 08:54:05 +0300 | [diff] [blame] | 498 | } |
| 499 | |
Konstantinos Archangelof | e93b00f | 2021-06-03 10:00:19 +0000 | [diff] [blame] | 500 | subResp.SubscriptionID = &restSubId |
archagge | afbf95f | 2021-04-14 08:54:05 +0300 | [diff] [blame] | 501 | subReqList := e2ap.SubscriptionRequestList{} |
| 502 | err = c.e2ap.FillSubscriptionReqMsgs(params, &subReqList, restSubscription) |
| 503 | if err != nil { |
| 504 | xapp.Logger.Error("%s", err.Error()) |
Anssi Mannila | 3cdd2e0 | 2021-10-14 12:35:41 +0300 | [diff] [blame] | 505 | c.restDuplicateCtrl.DeleteLastKnownRestSubsIdBasedOnMd5sum(md5sum) |
archagge | afbf95f | 2021-04-14 08:54:05 +0300 | [diff] [blame] | 506 | c.registry.DeleteRESTSubscription(&restSubId) |
Anssi Mannila | 316d8a1 | 2021-06-02 11:08:54 +0300 | [diff] [blame] | 507 | c.UpdateCounter(cRestSubFailToXapp) |
Anssi Mannila | cb7dd49 | 2021-10-01 11:10:26 +0300 | [diff] [blame] | 508 | return nil, common.SubscribeBadRequestCode |
archagge | afbf95f | 2021-04-14 08:54:05 +0300 | [diff] [blame] | 509 | } |
| 510 | |
Anssi Mannila | 3cdd2e0 | 2021-10-14 12:35:41 +0300 | [diff] [blame] | 511 | duplicate := c.restDuplicateCtrl.IsDuplicateToOngoingTransaction(restSubId, md5sum) |
Markku Virtanen | 42723e2 | 2021-06-15 10:09:23 +0300 | [diff] [blame] | 512 | if duplicate { |
Anssi Mannila | f682ace | 2021-09-28 13:11:25 +0300 | [diff] [blame] | 513 | err := fmt.Errorf("Retransmission blocker direct ACK for request of restSubsId %s restSubId MD5sum %s as retransmission", restSubId, md5sum) |
| 514 | xapp.Logger.Debug("%s", err) |
Anssi Mannila | b43397e | 2021-11-16 12:06:16 +0200 | [diff] [blame] | 515 | c.registry.DeleteRESTSubscription(&restSubId) |
Markku Virtanen | 42723e2 | 2021-06-15 10:09:23 +0300 | [diff] [blame] | 516 | c.UpdateCounter(cRestSubRespToXapp) |
Anssi Mannila | f682ace | 2021-09-28 13:11:25 +0300 | [diff] [blame] | 517 | return &subResp, common.SubscribeCreatedCode |
Markku Virtanen | b642a19 | 2021-06-09 09:08:14 +0000 | [diff] [blame] | 518 | } |
| 519 | |
Markku Virtanen | cd73ecc | 2021-06-23 06:16:01 +0000 | [diff] [blame] | 520 | c.WriteRESTSubscriptionToDb(restSubId, restSubscription) |
Anssi Mannila | f682ace | 2021-09-28 13:11:25 +0300 | [diff] [blame] | 521 | go c.processSubscriptionRequests(restSubscription, &subReqList, p.ClientEndpoint, p.Meid, &restSubId, xAppRmrEndpoint, md5sum, e2SubscriptionDirectives) |
archagge | afbf95f | 2021-04-14 08:54:05 +0300 | [diff] [blame] | 522 | |
Anssi Mannila | 316d8a1 | 2021-06-02 11:08:54 +0300 | [diff] [blame] | 523 | c.UpdateCounter(cRestSubRespToXapp) |
Anssi Mannila | f682ace | 2021-09-28 13:11:25 +0300 | [diff] [blame] | 524 | return &subResp, common.SubscribeCreatedCode |
| 525 | } |
| 526 | |
| 527 | //------------------------------------------------------------------- |
| 528 | // |
| 529 | //------------------------------------------------------------------- |
| 530 | func (c *Control) GetE2SubscriptionDirectives(p *models.SubscriptionParams) (*E2SubscriptionDirectives, error) { |
| 531 | |
| 532 | e2SubscriptionDirectives := &E2SubscriptionDirectives{} |
| 533 | if p == nil || p.E2SubscriptionDirectives == nil { |
| 534 | e2SubscriptionDirectives.E2TimeoutTimerValue = e2tSubReqTimeout |
| 535 | e2SubscriptionDirectives.E2MaxTryCount = int64(e2tMaxSubReqTryCount) |
| 536 | e2SubscriptionDirectives.CreateRMRRoute = true |
| 537 | xapp.Logger.Debug("p == nil || p.E2SubscriptionDirectives == nil. Using default values for E2TimeoutTimerValue = %v and E2RetryCount = %v RMRRoutingNeeded = true", e2tSubReqTimeout, e2tMaxSubReqTryCount) |
| 538 | } else { |
| 539 | if p.E2SubscriptionDirectives.E2TimeoutTimerValue >= 1 && p.E2SubscriptionDirectives.E2TimeoutTimerValue <= 10 { |
| 540 | e2SubscriptionDirectives.E2TimeoutTimerValue = time.Duration(p.E2SubscriptionDirectives.E2TimeoutTimerValue) * 1000000000 // Duration type cast returns nano seconds |
| 541 | } else { |
| 542 | return nil, fmt.Errorf("p.E2SubscriptionDirectives.E2TimeoutTimerValue out of range (1-10 seconds): %v", p.E2SubscriptionDirectives.E2TimeoutTimerValue) |
| 543 | } |
| 544 | if p.E2SubscriptionDirectives.E2RetryCount == nil { |
| 545 | xapp.Logger.Error("p.E2SubscriptionDirectives.E2RetryCount == nil. Using default value") |
| 546 | e2SubscriptionDirectives.E2MaxTryCount = int64(e2tMaxSubReqTryCount) |
| 547 | } else { |
| 548 | if *p.E2SubscriptionDirectives.E2RetryCount >= 0 && *p.E2SubscriptionDirectives.E2RetryCount <= 10 { |
| 549 | e2SubscriptionDirectives.E2MaxTryCount = *p.E2SubscriptionDirectives.E2RetryCount + 1 // E2MaxTryCount = First sending plus two retries |
| 550 | } else { |
| 551 | return nil, fmt.Errorf("p.E2SubscriptionDirectives.E2RetryCount out of range (0-10): %v", *p.E2SubscriptionDirectives.E2RetryCount) |
| 552 | } |
| 553 | } |
Anssi Mannila | cb7dd49 | 2021-10-01 11:10:26 +0300 | [diff] [blame] | 554 | e2SubscriptionDirectives.CreateRMRRoute = p.E2SubscriptionDirectives.RMRRoutingNeeded |
Anssi Mannila | f682ace | 2021-09-28 13:11:25 +0300 | [diff] [blame] | 555 | } |
| 556 | xapp.Logger.Debug("e2SubscriptionDirectives.E2TimeoutTimerValue: %v", e2SubscriptionDirectives.E2TimeoutTimerValue) |
| 557 | xapp.Logger.Debug("e2SubscriptionDirectives.E2MaxTryCount: %v", e2SubscriptionDirectives.E2MaxTryCount) |
| 558 | xapp.Logger.Debug("e2SubscriptionDirectives.CreateRMRRoute: %v", e2SubscriptionDirectives.CreateRMRRoute) |
| 559 | return e2SubscriptionDirectives, nil |
| 560 | } |
| 561 | |
| 562 | //------------------------------------------------------------------- |
| 563 | // |
| 564 | //------------------------------------------------------------------- |
archagge | afbf95f | 2021-04-14 08:54:05 +0300 | [diff] [blame] | 565 | |
| 566 | func (c *Control) processSubscriptionRequests(restSubscription *RESTSubscription, subReqList *e2ap.SubscriptionRequestList, |
Anssi Mannila | f682ace | 2021-09-28 13:11:25 +0300 | [diff] [blame] | 567 | clientEndpoint *models.SubscriptionParamsClientEndpoint, meid *string, restSubId *string, xAppRmrEndpoint string, md5sum string, e2SubscriptionDirectives *E2SubscriptionDirectives) { |
archagge | afbf95f | 2021-04-14 08:54:05 +0300 | [diff] [blame] | 568 | |
Anssi Mannila | 08c8fbd | 2021-10-05 12:47:41 +0300 | [diff] [blame] | 569 | c.SubscriptionProcessingStartDelay() |
Anssi Mannila | 54838ed | 2021-11-19 11:25:01 +0200 | [diff] [blame] | 570 | xapp.Logger.Debug("E2 SubscriptionRequest count = %v ", len(subReqList.E2APSubscriptionRequests)) |
archagge | afbf95f | 2021-04-14 08:54:05 +0300 | [diff] [blame] | 571 | |
Konstantinos Archangelof | e93b00f | 2021-06-03 10:00:19 +0000 | [diff] [blame] | 572 | var xAppEventInstanceID int64 |
| 573 | var e2EventInstanceID int64 |
Anssi Mannila | f682ace | 2021-09-28 13:11:25 +0300 | [diff] [blame] | 574 | errorInfo := &ErrorInfo{} |
Markku Virtanen | b642a19 | 2021-06-09 09:08:14 +0000 | [diff] [blame] | 575 | |
Anssi Mannila | 3cdd2e0 | 2021-10-14 12:35:41 +0300 | [diff] [blame] | 576 | defer c.restDuplicateCtrl.SetMd5sumFromLastOkRequest(*restSubId, md5sum) |
Markku Virtanen | b642a19 | 2021-06-09 09:08:14 +0000 | [diff] [blame] | 577 | |
archagge | afbf95f | 2021-04-14 08:54:05 +0300 | [diff] [blame] | 578 | for index := 0; index < len(subReqList.E2APSubscriptionRequests); index++ { |
| 579 | subReqMsg := subReqList.E2APSubscriptionRequests[index] |
Markku Virtanen | b642a19 | 2021-06-09 09:08:14 +0000 | [diff] [blame] | 580 | xAppEventInstanceID = (int64)(subReqMsg.RequestId.Id) |
archagge | afbf95f | 2021-04-14 08:54:05 +0300 | [diff] [blame] | 581 | |
Konstantinos Archangelof | e93b00f | 2021-06-03 10:00:19 +0000 | [diff] [blame] | 582 | trans := c.tracker.NewXappTransaction(xapp.NewRmrEndpoint(xAppRmrEndpoint), *restSubId, subReqMsg.RequestId, &xapp.RMRMeid{RanName: *meid}) |
archagge | afbf95f | 2021-04-14 08:54:05 +0300 | [diff] [blame] | 583 | if trans == nil { |
Markku Virtanen | b642a19 | 2021-06-09 09:08:14 +0000 | [diff] [blame] | 584 | // Send notification to xApp that prosessing of a Subscription Request has failed. |
| 585 | err := fmt.Errorf("Tracking failure") |
Anssi Mannila | f682ace | 2021-09-28 13:11:25 +0300 | [diff] [blame] | 586 | errorInfo.ErrorCause = err.Error() |
| 587 | c.sendUnsuccesfullResponseNotification(restSubId, restSubscription, xAppEventInstanceID, err, clientEndpoint, trans, errorInfo) |
Markku Virtanen | b642a19 | 2021-06-09 09:08:14 +0000 | [diff] [blame] | 588 | continue |
archagge | afbf95f | 2021-04-14 08:54:05 +0300 | [diff] [blame] | 589 | } |
| 590 | |
Anssi Mannila | f682ace | 2021-09-28 13:11:25 +0300 | [diff] [blame] | 591 | xapp.Logger.Debug("Handle SubscriptionRequest index=%v, %s", index, idstring(nil, trans)) |
Markku Virtanen | b642a19 | 2021-06-09 09:08:14 +0000 | [diff] [blame] | 592 | |
Anssi Mannila | f682ace | 2021-09-28 13:11:25 +0300 | [diff] [blame] | 593 | subRespMsg, errorInfo, err := c.handleSubscriptionRequest(trans, &subReqMsg, meid, *restSubId, e2SubscriptionDirectives) |
Markku Virtanen | 42723e2 | 2021-06-15 10:09:23 +0300 | [diff] [blame] | 594 | |
Anssi Mannila | f682ace | 2021-09-28 13:11:25 +0300 | [diff] [blame] | 595 | xapp.Logger.Debug("Handled SubscriptionRequest index=%v, %s", index, idstring(nil, trans)) |
Anssi Mannila | 53dbe7e | 2021-10-06 14:21:48 +0300 | [diff] [blame] | 596 | trans.Release() |
Markku Virtanen | 42723e2 | 2021-06-15 10:09:23 +0300 | [diff] [blame] | 597 | |
archagge | afbf95f | 2021-04-14 08:54:05 +0300 | [diff] [blame] | 598 | if err != nil { |
Anssi Mannila | 54838ed | 2021-11-19 11:25:01 +0200 | [diff] [blame] | 599 | if err.Error() == "TEST: restart event received" { |
| 600 | // This is just for UT cases. Stop here subscription processing |
| 601 | return |
| 602 | } |
Anssi Mannila | f682ace | 2021-09-28 13:11:25 +0300 | [diff] [blame] | 603 | c.sendUnsuccesfullResponseNotification(restSubId, restSubscription, xAppEventInstanceID, err, clientEndpoint, trans, errorInfo) |
archagge | afbf95f | 2021-04-14 08:54:05 +0300 | [diff] [blame] | 604 | } else { |
Konstantinos Archangelof | e93b00f | 2021-06-03 10:00:19 +0000 | [diff] [blame] | 605 | e2EventInstanceID = (int64)(subRespMsg.RequestId.InstanceId) |
Markku Virtanen | 42723e2 | 2021-06-15 10:09:23 +0300 | [diff] [blame] | 606 | restSubscription.AddMd5Sum(md5sum) |
Anssi Mannila | f682ace | 2021-09-28 13:11:25 +0300 | [diff] [blame] | 607 | xapp.Logger.Debug("SubscriptionRequest index=%v processed successfullyfor %s. endpoint=%v:%v, XappEventInstanceID=%v, E2EventInstanceID=%v, %s", |
Markku Virtanen | 42723e2 | 2021-06-15 10:09:23 +0300 | [diff] [blame] | 608 | index, *restSubId, clientEndpoint.Host, *clientEndpoint.HTTPPort, xAppEventInstanceID, e2EventInstanceID, idstring(nil, trans)) |
Anssi Mannila | 56233b0 | 2022-01-24 13:26:42 +0200 | [diff] [blame] | 609 | c.sendSuccesfullResponseNotification(restSubId, restSubscription, xAppEventInstanceID, e2EventInstanceID, clientEndpoint, trans, errorInfo) |
archagge | afbf95f | 2021-04-14 08:54:05 +0300 | [diff] [blame] | 610 | } |
archagge | afbf95f | 2021-04-14 08:54:05 +0300 | [diff] [blame] | 611 | } |
| 612 | } |
| 613 | |
| 614 | //------------------------------------------------------------------- |
| 615 | // |
| 616 | //------------------------------------------------------------------ |
Anssi Mannila | 08c8fbd | 2021-10-05 12:47:41 +0300 | [diff] [blame] | 617 | func (c *Control) SubscriptionProcessingStartDelay() { |
| 618 | if c.UTTesting == true { |
| 619 | // This is temporary fix for the UT problem that notification arrives before subscription response |
| 620 | // Correct fix would be to allow notification come before response and process it correctly |
| 621 | xapp.Logger.Debug("Setting 50 ms delay before starting processing Subscriptions") |
| 622 | <-time.After(time.Millisecond * 50) |
| 623 | xapp.Logger.Debug("Continuing after delay") |
| 624 | } |
| 625 | } |
| 626 | |
| 627 | //------------------------------------------------------------------- |
| 628 | // |
| 629 | //------------------------------------------------------------------ |
archagge | afbf95f | 2021-04-14 08:54:05 +0300 | [diff] [blame] | 630 | func (c *Control) handleSubscriptionRequest(trans *TransactionXapp, subReqMsg *e2ap.E2APSubscriptionRequest, meid *string, |
Anssi Mannila | f682ace | 2021-09-28 13:11:25 +0300 | [diff] [blame] | 631 | restSubId string, e2SubscriptionDirectives *E2SubscriptionDirectives) (*e2ap.E2APSubscriptionResponse, *ErrorInfo, error) { |
| 632 | |
| 633 | errorInfo := ErrorInfo{} |
archagge | afbf95f | 2021-04-14 08:54:05 +0300 | [diff] [blame] | 634 | |
| 635 | err := c.tracker.Track(trans) |
| 636 | if err != nil { |
Markku Virtanen | 55d2a28 | 2021-06-04 14:46:56 +0300 | [diff] [blame] | 637 | xapp.Logger.Error("XAPP-SubReq Tracking error: %s", idstring(err, trans)) |
Anssi Mannila | f682ace | 2021-09-28 13:11:25 +0300 | [diff] [blame] | 638 | errorInfo.ErrorCause = err.Error() |
Markku Virtanen | 55d2a28 | 2021-06-04 14:46:56 +0300 | [diff] [blame] | 639 | err = fmt.Errorf("Tracking failure") |
Anssi Mannila | f682ace | 2021-09-28 13:11:25 +0300 | [diff] [blame] | 640 | return nil, &errorInfo, err |
archagge | afbf95f | 2021-04-14 08:54:05 +0300 | [diff] [blame] | 641 | } |
| 642 | |
Anssi Mannila | f682ace | 2021-09-28 13:11:25 +0300 | [diff] [blame] | 643 | subs, errorInfo, err := c.registry.AssignToSubscription(trans, subReqMsg, c.ResetTestFlag, c, e2SubscriptionDirectives.CreateRMRRoute) |
archagge | afbf95f | 2021-04-14 08:54:05 +0300 | [diff] [blame] | 644 | if err != nil { |
Markku Virtanen | 55d2a28 | 2021-06-04 14:46:56 +0300 | [diff] [blame] | 645 | xapp.Logger.Error("XAPP-SubReq Assign error: %s", idstring(err, trans)) |
Anssi Mannila | f682ace | 2021-09-28 13:11:25 +0300 | [diff] [blame] | 646 | return nil, &errorInfo, err |
archagge | afbf95f | 2021-04-14 08:54:05 +0300 | [diff] [blame] | 647 | } |
| 648 | |
| 649 | // |
| 650 | // Wake subs request |
| 651 | // |
Anssi Mannila | c7da4ee | 2021-10-22 09:52:02 +0300 | [diff] [blame] | 652 | subs.OngoingReqCount++ |
Anssi Mannila | 54838ed | 2021-11-19 11:25:01 +0200 | [diff] [blame] | 653 | go c.handleSubscriptionCreate(subs, trans, e2SubscriptionDirectives, 0) |
archagge | afbf95f | 2021-04-14 08:54:05 +0300 | [diff] [blame] | 654 | event, _ := trans.WaitEvent(0) //blocked wait as timeout is handled in subs side |
Anssi Mannila | c7da4ee | 2021-10-22 09:52:02 +0300 | [diff] [blame] | 655 | subs.OngoingReqCount-- |
archagge | afbf95f | 2021-04-14 08:54:05 +0300 | [diff] [blame] | 656 | |
| 657 | err = nil |
| 658 | if event != nil { |
| 659 | switch themsg := event.(type) { |
| 660 | case *e2ap.E2APSubscriptionResponse: |
| 661 | trans.Release() |
Anssi Mannila | c7da4ee | 2021-10-22 09:52:02 +0300 | [diff] [blame] | 662 | if c.e2IfState.IsE2ConnectionUp(meid) == true { |
Anssi Mannila | 56233b0 | 2022-01-24 13:26:42 +0200 | [diff] [blame] | 663 | errorInfo = c.e2ap.CheckActionNotAdmittedList(xapp.RIC_SUB_RESP, themsg.ActionNotAdmittedList, c) |
Anssi Mannila | c7da4ee | 2021-10-22 09:52:02 +0300 | [diff] [blame] | 664 | return themsg, &errorInfo, nil |
| 665 | } else { |
| 666 | c.registry.RemoveFromSubscription(subs, trans, waitRouteCleanup_ms, c) |
| 667 | c.RemoveSubscriptionFromDb(subs) |
| 668 | err = fmt.Errorf("E2 interface down") |
| 669 | errorInfo.SetInfo(err.Error(), models.SubscriptionInstanceErrorSourceE2Node, "") |
Anssi Mannila | c7da4ee | 2021-10-22 09:52:02 +0300 | [diff] [blame] | 670 | } |
archagge | afbf95f | 2021-04-14 08:54:05 +0300 | [diff] [blame] | 671 | case *e2ap.E2APSubscriptionFailure: |
Anssi Mannila | 483bd16 | 2022-01-20 11:11:48 +0200 | [diff] [blame] | 672 | err = fmt.Errorf("RICSubscriptionFailure. E2NodeCause: (Cause:%v, Value %v)", themsg.Cause.Content, themsg.Cause.Value) |
| 673 | errorInfo.SetInfo(err.Error(), models.SubscriptionInstanceErrorSourceE2Node, "") |
Anssi Mannila | f682ace | 2021-09-28 13:11:25 +0300 | [diff] [blame] | 674 | case *PackSubscriptionRequestErrortEvent: |
Anssi Mannila | 56233b0 | 2022-01-24 13:26:42 +0200 | [diff] [blame] | 675 | err = fmt.Errorf("E2 RICSubscriptionRequest pack failure") |
Anssi Mannila | b43397e | 2021-11-16 12:06:16 +0200 | [diff] [blame] | 676 | errorInfo = themsg.ErrorInfo |
Anssi Mannila | f682ace | 2021-09-28 13:11:25 +0300 | [diff] [blame] | 677 | case *SDLWriteErrortEvent: |
| 678 | err = fmt.Errorf("SDL write failure") |
Anssi Mannila | b43397e | 2021-11-16 12:06:16 +0200 | [diff] [blame] | 679 | errorInfo = themsg.ErrorInfo |
Anssi Mannila | 54838ed | 2021-11-19 11:25:01 +0200 | [diff] [blame] | 680 | case *SubmgrRestartTestEvent: |
| 681 | err = fmt.Errorf("TEST: restart event received") |
| 682 | xapp.Logger.Debug("%s", err) |
| 683 | return nil, &errorInfo, err |
archagge | afbf95f | 2021-04-14 08:54:05 +0300 | [diff] [blame] | 684 | default: |
Anssi Mannila | f682ace | 2021-09-28 13:11:25 +0300 | [diff] [blame] | 685 | err = fmt.Errorf("Unexpected E2 subscription response received") |
| 686 | errorInfo.SetInfo(err.Error(), models.SubscriptionInstanceErrorSourceE2Node, "") |
archagge | afbf95f | 2021-04-14 08:54:05 +0300 | [diff] [blame] | 687 | break |
| 688 | } |
Markku Virtanen | 55d2a28 | 2021-06-04 14:46:56 +0300 | [diff] [blame] | 689 | } else { |
Anssi Mannila | 3d80b72 | 2021-11-12 13:17:15 +0200 | [diff] [blame] | 690 | // Timer expiry |
Anssi Mannila | 56233b0 | 2022-01-24 13:26:42 +0200 | [diff] [blame] | 691 | err = fmt.Errorf("E2 RICSubscriptionResponse timeout") |
Anssi Mannila | f682ace | 2021-09-28 13:11:25 +0300 | [diff] [blame] | 692 | errorInfo.SetInfo(err.Error(), "", models.SubscriptionInstanceTimeoutTypeE2Timeout) |
| 693 | if subs.PolicyUpdate == true { |
| 694 | return nil, &errorInfo, err |
| 695 | } |
archagge | afbf95f | 2021-04-14 08:54:05 +0300 | [diff] [blame] | 696 | } |
Markku Virtanen | 55d2a28 | 2021-06-04 14:46:56 +0300 | [diff] [blame] | 697 | |
Anssi Mannila | 9c4697f | 2022-07-04 15:51:38 +0300 | [diff] [blame] | 698 | xapp.Logger.Error("XAPP-SubReq E2 subscription failed: %s", idstring(err, trans, subs)) |
Anssi Mannila | 55d6fed | 2022-08-02 12:41:48 +0300 | [diff] [blame] | 699 | c.registry.RemoveFromSubscription(subs, trans, waitRouteCleanup_ms, c) |
| 700 | |
Anssi Mannila | f682ace | 2021-09-28 13:11:25 +0300 | [diff] [blame] | 701 | return nil, &errorInfo, err |
archagge | afbf95f | 2021-04-14 08:54:05 +0300 | [diff] [blame] | 702 | } |
| 703 | |
| 704 | //------------------------------------------------------------------- |
| 705 | // |
| 706 | //------------------------------------------------------------------- |
Markku Virtanen | 42723e2 | 2021-06-15 10:09:23 +0300 | [diff] [blame] | 707 | func (c *Control) sendUnsuccesfullResponseNotification(restSubId *string, restSubscription *RESTSubscription, xAppEventInstanceID int64, err error, |
Anssi Mannila | f682ace | 2021-09-28 13:11:25 +0300 | [diff] [blame] | 708 | clientEndpoint *models.SubscriptionParamsClientEndpoint, trans *TransactionXapp, errorInfo *ErrorInfo) { |
Markku Virtanen | 42723e2 | 2021-06-15 10:09:23 +0300 | [diff] [blame] | 709 | |
| 710 | // Send notification to xApp that prosessing of a Subscription Request has failed. |
| 711 | e2EventInstanceID := (int64)(0) |
Anssi Mannila | f682ace | 2021-09-28 13:11:25 +0300 | [diff] [blame] | 712 | if errorInfo.ErrorSource == "" { |
| 713 | // Submgr is default source of error |
| 714 | errorInfo.ErrorSource = models.SubscriptionInstanceErrorSourceSUBMGR |
| 715 | } |
Markku Virtanen | 42723e2 | 2021-06-15 10:09:23 +0300 | [diff] [blame] | 716 | resp := &models.SubscriptionResponse{ |
| 717 | SubscriptionID: restSubId, |
| 718 | SubscriptionInstances: []*models.SubscriptionInstance{ |
| 719 | &models.SubscriptionInstance{E2EventInstanceID: &e2EventInstanceID, |
Anssi Mannila | cb7dd49 | 2021-10-01 11:10:26 +0300 | [diff] [blame] | 720 | ErrorCause: errorInfo.ErrorCause, |
| 721 | ErrorSource: errorInfo.ErrorSource, |
| 722 | TimeoutType: errorInfo.TimeoutType, |
Markku Virtanen | 42723e2 | 2021-06-15 10:09:23 +0300 | [diff] [blame] | 723 | XappEventInstanceID: &xAppEventInstanceID}, |
| 724 | }, |
| 725 | } |
| 726 | // Mark REST subscription request processed. |
| 727 | restSubscription.SetProcessed(err) |
| 728 | c.UpdateRESTSubscriptionInDB(*restSubId, restSubscription, false) |
| 729 | if trans != nil { |
Anssi Mannila | 6bd5791 | 2022-06-16 09:47:23 +0300 | [diff] [blame] | 730 | xapp.Logger.Debug("Sending unsuccessful REST notification: ErrorCause:%s, ErrorSource:%s, TimeoutType:%s, to Endpoint=%v:%v, XappEventInstanceID=%v, E2EventInstanceID=%v, %s", |
| 731 | errorInfo.ErrorCause, errorInfo.ErrorSource, errorInfo.TimeoutType, clientEndpoint.Host, *clientEndpoint.HTTPPort, xAppEventInstanceID, e2EventInstanceID, idstring(nil, trans)) |
Markku Virtanen | 42723e2 | 2021-06-15 10:09:23 +0300 | [diff] [blame] | 732 | } else { |
Anssi Mannila | 6bd5791 | 2022-06-16 09:47:23 +0300 | [diff] [blame] | 733 | xapp.Logger.Debug("Sending unsuccessful REST notification: ErrorCause:%s, ErrorSource:%s, TimeoutType:%s, to Endpoint=%v:%v, XappEventInstanceID=%v, E2EventInstanceID=%v", |
| 734 | errorInfo.ErrorCause, errorInfo.ErrorSource, errorInfo.TimeoutType, clientEndpoint.Host, *clientEndpoint.HTTPPort, xAppEventInstanceID, e2EventInstanceID) |
Markku Virtanen | 42723e2 | 2021-06-15 10:09:23 +0300 | [diff] [blame] | 735 | } |
| 736 | |
| 737 | c.UpdateCounter(cRestSubFailNotifToXapp) |
Anssi Mannila | 9c4697f | 2022-07-04 15:51:38 +0300 | [diff] [blame] | 738 | err = xapp.Subscription.Notify(resp, *clientEndpoint) |
| 739 | if err != nil { |
| 740 | xapp.Logger.Error("xapp.Subscription.Notify failed %s", err.Error()) |
| 741 | } |
Anssi Mannila | c7da4ee | 2021-10-22 09:52:02 +0300 | [diff] [blame] | 742 | |
Anssi Mannila | b43397e | 2021-11-16 12:06:16 +0200 | [diff] [blame] | 743 | // E2 is down. Delete completely processed request safely now |
Anssi Mannila | c7da4ee | 2021-10-22 09:52:02 +0300 | [diff] [blame] | 744 | if c.e2IfState.IsE2ConnectionUp(&restSubscription.Meid) == false && restSubscription.SubReqOngoing == false { |
| 745 | c.registry.DeleteRESTSubscription(restSubId) |
| 746 | c.RemoveRESTSubscriptionFromDb(*restSubId) |
| 747 | } |
Markku Virtanen | 42723e2 | 2021-06-15 10:09:23 +0300 | [diff] [blame] | 748 | } |
| 749 | |
| 750 | //------------------------------------------------------------------- |
| 751 | // |
| 752 | //------------------------------------------------------------------- |
| 753 | func (c *Control) sendSuccesfullResponseNotification(restSubId *string, restSubscription *RESTSubscription, xAppEventInstanceID int64, e2EventInstanceID int64, |
Anssi Mannila | 56233b0 | 2022-01-24 13:26:42 +0200 | [diff] [blame] | 754 | clientEndpoint *models.SubscriptionParamsClientEndpoint, trans *TransactionXapp, errorInfo *ErrorInfo) { |
Markku Virtanen | 42723e2 | 2021-06-15 10:09:23 +0300 | [diff] [blame] | 755 | |
| 756 | // Store successfully processed InstanceId for deletion |
| 757 | restSubscription.AddE2InstanceId((uint32)(e2EventInstanceID)) |
| 758 | restSubscription.AddXappIdToE2Id(xAppEventInstanceID, e2EventInstanceID) |
| 759 | |
| 760 | // Send notification to xApp that a Subscription Request has been processed. |
| 761 | resp := &models.SubscriptionResponse{ |
| 762 | SubscriptionID: restSubId, |
| 763 | SubscriptionInstances: []*models.SubscriptionInstance{ |
| 764 | &models.SubscriptionInstance{E2EventInstanceID: &e2EventInstanceID, |
Anssi Mannila | 56233b0 | 2022-01-24 13:26:42 +0200 | [diff] [blame] | 765 | ErrorCause: errorInfo.ErrorCause, |
| 766 | ErrorSource: errorInfo.ErrorSource, |
Markku Virtanen | 42723e2 | 2021-06-15 10:09:23 +0300 | [diff] [blame] | 767 | XappEventInstanceID: &xAppEventInstanceID}, |
| 768 | }, |
| 769 | } |
| 770 | // Mark REST subscription request processesd. |
| 771 | restSubscription.SetProcessed(nil) |
| 772 | c.UpdateRESTSubscriptionInDB(*restSubId, restSubscription, false) |
Anssi Mannila | 6bd5791 | 2022-06-16 09:47:23 +0300 | [diff] [blame] | 773 | xapp.Logger.Debug("Sending successful REST notification: ErrorCause:%s, ErrorSource:%s, TimeoutType:%s, to Endpoint=%v:%v, XappEventInstanceID=%v, E2EventInstanceID=%v, %s", |
| 774 | errorInfo.ErrorCause, errorInfo.ErrorSource, errorInfo.TimeoutType, clientEndpoint.Host, *clientEndpoint.HTTPPort, xAppEventInstanceID, e2EventInstanceID, idstring(nil, trans)) |
Markku Virtanen | 42723e2 | 2021-06-15 10:09:23 +0300 | [diff] [blame] | 775 | c.UpdateCounter(cRestSubNotifToXapp) |
Anssi Mannila | 9c4697f | 2022-07-04 15:51:38 +0300 | [diff] [blame] | 776 | err := xapp.Subscription.Notify(resp, *clientEndpoint) |
| 777 | if err != nil { |
| 778 | xapp.Logger.Error("xapp.Subscription.Notify failed %s", err.Error()) |
| 779 | } |
Anssi Mannila | c7da4ee | 2021-10-22 09:52:02 +0300 | [diff] [blame] | 780 | |
Anssi Mannila | b43397e | 2021-11-16 12:06:16 +0200 | [diff] [blame] | 781 | // E2 is down. Delete completely processed request safely now |
Anssi Mannila | c7da4ee | 2021-10-22 09:52:02 +0300 | [diff] [blame] | 782 | if c.e2IfState.IsE2ConnectionUp(&restSubscription.Meid) == false && restSubscription.SubReqOngoing == false { |
| 783 | c.registry.DeleteRESTSubscription(restSubId) |
| 784 | c.RemoveRESTSubscriptionFromDb(*restSubId) |
| 785 | } |
Markku Virtanen | 42723e2 | 2021-06-15 10:09:23 +0300 | [diff] [blame] | 786 | } |
| 787 | |
| 788 | //------------------------------------------------------------------- |
| 789 | // |
| 790 | //------------------------------------------------------------------- |
Anssi Mannila | f682ace | 2021-09-28 13:11:25 +0300 | [diff] [blame] | 791 | func (c *Control) RESTSubscriptionDeleteHandler(restSubId string) int { |
archagge | afbf95f | 2021-04-14 08:54:05 +0300 | [diff] [blame] | 792 | |
| 793 | c.CntRecvMsg++ |
Konstantinos Archangelof | 27433e7 | 2021-05-31 08:30:35 +0000 | [diff] [blame] | 794 | c.UpdateCounter(cRestSubDelReqFromXapp) |
archagge | afbf95f | 2021-04-14 08:54:05 +0300 | [diff] [blame] | 795 | |
Anssi Mannila | f682ace | 2021-09-28 13:11:25 +0300 | [diff] [blame] | 796 | xapp.Logger.Debug("SubscriptionDeleteRequest from XAPP") |
archagge | afbf95f | 2021-04-14 08:54:05 +0300 | [diff] [blame] | 797 | |
Konstantinos Archangelof | e93b00f | 2021-06-03 10:00:19 +0000 | [diff] [blame] | 798 | restSubscription, err := c.registry.GetRESTSubscription(restSubId, true) |
archagge | afbf95f | 2021-04-14 08:54:05 +0300 | [diff] [blame] | 799 | if err != nil { |
| 800 | xapp.Logger.Error("%s", err.Error()) |
| 801 | if restSubscription == nil { |
| 802 | // Subscription was not found |
Anssi Mannila | c7da4ee | 2021-10-22 09:52:02 +0300 | [diff] [blame] | 803 | c.UpdateCounter(cRestSubDelRespToXapp) |
Anssi Mannila | f682ace | 2021-09-28 13:11:25 +0300 | [diff] [blame] | 804 | return common.UnsubscribeNoContentCode |
archagge | afbf95f | 2021-04-14 08:54:05 +0300 | [diff] [blame] | 805 | } else { |
| 806 | if restSubscription.SubReqOngoing == true { |
| 807 | err := fmt.Errorf("Handling of the REST Subscription Request still ongoing %s", restSubId) |
| 808 | xapp.Logger.Error("%s", err.Error()) |
Anssi Mannila | c7da4ee | 2021-10-22 09:52:02 +0300 | [diff] [blame] | 809 | c.UpdateCounter(cRestSubDelFailToXapp) |
Anssi Mannila | f682ace | 2021-09-28 13:11:25 +0300 | [diff] [blame] | 810 | return common.UnsubscribeBadRequestCode |
archagge | afbf95f | 2021-04-14 08:54:05 +0300 | [diff] [blame] | 811 | } else if restSubscription.SubDelReqOngoing == true { |
| 812 | // Previous request for same restSubId still ongoing |
Anssi Mannila | 3d80b72 | 2021-11-12 13:17:15 +0200 | [diff] [blame] | 813 | c.UpdateCounter(cRestSubDelRespToXapp) |
| 814 | return common.UnsubscribeNoContentCode |
archagge | afbf95f | 2021-04-14 08:54:05 +0300 | [diff] [blame] | 815 | } |
| 816 | } |
| 817 | } |
| 818 | |
| 819 | xAppRmrEndPoint := restSubscription.xAppRmrEndPoint |
| 820 | go func() { |
Anssi Mannila | f682ace | 2021-09-28 13:11:25 +0300 | [diff] [blame] | 821 | xapp.Logger.Debug("Deleteting handler: processing instances = %v", restSubscription.InstanceIds) |
archagge | afbf95f | 2021-04-14 08:54:05 +0300 | [diff] [blame] | 822 | for _, instanceId := range restSubscription.InstanceIds { |
Anssi Mannila | 54838ed | 2021-11-19 11:25:01 +0200 | [diff] [blame] | 823 | xAppEventInstanceID, err := c.SubscriptionDeleteHandler(&restSubId, &xAppRmrEndPoint, &restSubscription.Meid, instanceId, 0) |
Konstantinos Archangelof | e93b00f | 2021-06-03 10:00:19 +0000 | [diff] [blame] | 824 | |
archagge | afbf95f | 2021-04-14 08:54:05 +0300 | [diff] [blame] | 825 | if err != nil { |
| 826 | xapp.Logger.Error("%s", err.Error()) |
archagge | afbf95f | 2021-04-14 08:54:05 +0300 | [diff] [blame] | 827 | } |
Anssi Mannila | f682ace | 2021-09-28 13:11:25 +0300 | [diff] [blame] | 828 | xapp.Logger.Debug("Deleteting instanceId = %v", instanceId) |
Konstantinos Archangelof | e93b00f | 2021-06-03 10:00:19 +0000 | [diff] [blame] | 829 | restSubscription.DeleteXappIdToE2Id(xAppEventInstanceID) |
| 830 | restSubscription.DeleteE2InstanceId(instanceId) |
archagge | afbf95f | 2021-04-14 08:54:05 +0300 | [diff] [blame] | 831 | } |
Anssi Mannila | 3cdd2e0 | 2021-10-14 12:35:41 +0300 | [diff] [blame] | 832 | c.restDuplicateCtrl.DeleteLastKnownRestSubsIdBasedOnMd5sum(restSubscription.lastReqMd5sum) |
archagge | afbf95f | 2021-04-14 08:54:05 +0300 | [diff] [blame] | 833 | c.registry.DeleteRESTSubscription(&restSubId) |
Konstantinos Archangelof | 268d715 | 2021-06-14 12:24:00 +0300 | [diff] [blame] | 834 | c.RemoveRESTSubscriptionFromDb(restSubId) |
archagge | afbf95f | 2021-04-14 08:54:05 +0300 | [diff] [blame] | 835 | }() |
| 836 | |
Konstantinos Archangelof | 27433e7 | 2021-05-31 08:30:35 +0000 | [diff] [blame] | 837 | c.UpdateCounter(cRestSubDelRespToXapp) |
Anssi Mannila | f682ace | 2021-09-28 13:11:25 +0300 | [diff] [blame] | 838 | return common.UnsubscribeNoContentCode |
Juha Hyttinen | c9eb08a | 2020-02-28 08:53:33 +0200 | [diff] [blame] | 839 | } |
| 840 | |
archagge | afbf95f | 2021-04-14 08:54:05 +0300 | [diff] [blame] | 841 | //------------------------------------------------------------------- |
| 842 | // |
| 843 | //------------------------------------------------------------------- |
Anssi Mannila | 54838ed | 2021-11-19 11:25:01 +0200 | [diff] [blame] | 844 | func (c *Control) SubscriptionDeleteHandler(restSubId *string, endPoint *string, meid *string, instanceId uint32, waitRouteCleanupTime time.Duration) (int64, error) { |
archagge | afbf95f | 2021-04-14 08:54:05 +0300 | [diff] [blame] | 845 | |
Konstantinos Archangelof | e93b00f | 2021-06-03 10:00:19 +0000 | [diff] [blame] | 846 | var xAppEventInstanceID int64 |
| 847 | subs, err := c.registry.GetSubscriptionFirstMatch([]uint32{instanceId}) |
| 848 | if err != nil { |
Anssi Mannila | f682ace | 2021-09-28 13:11:25 +0300 | [diff] [blame] | 849 | xapp.Logger.Debug("Subscription Delete Handler subscription for restSubId=%v, E2EventInstanceID=%v not found %s", |
Konstantinos Archangelof | e93b00f | 2021-06-03 10:00:19 +0000 | [diff] [blame] | 850 | restSubId, instanceId, idstring(err, nil)) |
| 851 | return xAppEventInstanceID, nil |
| 852 | } |
| 853 | |
| 854 | xAppEventInstanceID = int64(subs.ReqId.Id) |
| 855 | trans := c.tracker.NewXappTransaction(xapp.NewRmrEndpoint(*endPoint), *restSubId, e2ap.RequestId{subs.ReqId.Id, 0}, &xapp.RMRMeid{RanName: *meid}) |
archagge | afbf95f | 2021-04-14 08:54:05 +0300 | [diff] [blame] | 856 | if trans == nil { |
| 857 | err := fmt.Errorf("XAPP-SubDelReq transaction not created. restSubId %s, endPoint %s, meid %s, instanceId %v", *restSubId, *endPoint, *meid, instanceId) |
| 858 | xapp.Logger.Error("%s", err.Error()) |
| 859 | } |
| 860 | defer trans.Release() |
| 861 | |
Konstantinos Archangelof | e93b00f | 2021-06-03 10:00:19 +0000 | [diff] [blame] | 862 | err = c.tracker.Track(trans) |
archagge | afbf95f | 2021-04-14 08:54:05 +0300 | [diff] [blame] | 863 | if err != nil { |
| 864 | err := fmt.Errorf("XAPP-SubDelReq %s:", idstring(err, trans)) |
| 865 | xapp.Logger.Error("%s", err.Error()) |
Konstantinos Archangelof | e93b00f | 2021-06-03 10:00:19 +0000 | [diff] [blame] | 866 | return xAppEventInstanceID, &time.ParseError{} |
archagge | afbf95f | 2021-04-14 08:54:05 +0300 | [diff] [blame] | 867 | } |
| 868 | // |
| 869 | // Wake subs delete |
| 870 | // |
Anssi Mannila | c7da4ee | 2021-10-22 09:52:02 +0300 | [diff] [blame] | 871 | subs.OngoingDelCount++ |
Anssi Mannila | 54838ed | 2021-11-19 11:25:01 +0200 | [diff] [blame] | 872 | go c.handleSubscriptionDelete(subs, trans, waitRouteCleanupTime) |
archagge | afbf95f | 2021-04-14 08:54:05 +0300 | [diff] [blame] | 873 | trans.WaitEvent(0) //blocked wait as timeout is handled in subs side |
Anssi Mannila | c7da4ee | 2021-10-22 09:52:02 +0300 | [diff] [blame] | 874 | subs.OngoingDelCount-- |
archagge | afbf95f | 2021-04-14 08:54:05 +0300 | [diff] [blame] | 875 | |
| 876 | xapp.Logger.Debug("XAPP-SubDelReq: Handling event %s ", idstring(nil, trans, subs)) |
| 877 | |
Anssi Mannila | 55d6fed | 2022-08-02 12:41:48 +0300 | [diff] [blame] | 878 | c.registry.RemoveFromSubscription(subs, trans, waitRouteCleanup_ms, c) |
archagge | afbf95f | 2021-04-14 08:54:05 +0300 | [diff] [blame] | 879 | |
Konstantinos Archangelof | e93b00f | 2021-06-03 10:00:19 +0000 | [diff] [blame] | 880 | return xAppEventInstanceID, nil |
archagge | afbf95f | 2021-04-14 08:54:05 +0300 | [diff] [blame] | 881 | } |
| 882 | |
| 883 | //------------------------------------------------------------------- |
| 884 | // |
| 885 | //------------------------------------------------------------------- |
Juha Hyttinen | c9eb08a | 2020-02-28 08:53:33 +0200 | [diff] [blame] | 886 | |
Juha Hyttinen | 83ada00 | 2020-01-30 10:36:33 +0200 | [diff] [blame] | 887 | func (c *Control) rmrSendToE2T(desc string, subs *Subscription, trans *TransactionSubs) (err error) { |
Juha Hyttinen | 9dc5adc | 2020-08-13 10:02:40 +0300 | [diff] [blame] | 888 | params := &xapp.RMRParams{} |
Juha Hyttinen | e406a34 | 2020-01-13 13:02:26 +0200 | [diff] [blame] | 889 | params.Mtype = trans.GetMtype() |
Juha Hyttinen | aada645 | 2020-04-07 08:47:58 +0300 | [diff] [blame] | 890 | params.SubId = int(subs.GetReqId().InstanceId) |
Juha Hyttinen | 86a4620 | 2020-01-14 12:49:09 +0200 | [diff] [blame] | 891 | params.Xid = "" |
Juha Hyttinen | e406a34 | 2020-01-13 13:02:26 +0200 | [diff] [blame] | 892 | params.Meid = subs.GetMeid() |
| 893 | params.Src = "" |
Juha Hyttinen | 63284a2 | 2020-01-15 10:45:11 +0200 | [diff] [blame] | 894 | params.PayloadLen = len(trans.Payload.Buf) |
| 895 | params.Payload = trans.Payload.Buf |
Juha Hyttinen | e406a34 | 2020-01-13 13:02:26 +0200 | [diff] [blame] | 896 | params.Mbuf = nil |
Anssi Mannila | f682ace | 2021-09-28 13:11:25 +0300 | [diff] [blame] | 897 | xapp.Logger.Debug("MSG to E2T: %s %s %s", desc, trans.String(), params.String()) |
Abukar Mohamed | fbd4df5 | 2021-03-11 06:13:27 +0000 | [diff] [blame] | 898 | err = c.SendWithRetry(params, false, 5) |
| 899 | if err != nil { |
| 900 | xapp.Logger.Error("rmrSendToE2T: Send failed: %+v", err) |
| 901 | } |
| 902 | return err |
kalnagy | e001868 | 2019-09-26 16:28:25 +0200 | [diff] [blame] | 903 | } |
| 904 | |
Juha Hyttinen | 83ada00 | 2020-01-30 10:36:33 +0200 | [diff] [blame] | 905 | func (c *Control) rmrSendToXapp(desc string, subs *Subscription, trans *TransactionXapp) (err error) { |
| 906 | |
Juha Hyttinen | 9dc5adc | 2020-08-13 10:02:40 +0300 | [diff] [blame] | 907 | params := &xapp.RMRParams{} |
Juha Hyttinen | 63284a2 | 2020-01-15 10:45:11 +0200 | [diff] [blame] | 908 | params.Mtype = trans.GetMtype() |
Juha Hyttinen | aada645 | 2020-04-07 08:47:58 +0300 | [diff] [blame] | 909 | params.SubId = int(subs.GetReqId().InstanceId) |
Juha Hyttinen | e406a34 | 2020-01-13 13:02:26 +0200 | [diff] [blame] | 910 | params.Xid = trans.GetXid() |
Juha Hyttinen | 86a4620 | 2020-01-14 12:49:09 +0200 | [diff] [blame] | 911 | params.Meid = trans.GetMeid() |
Juha Hyttinen | e406a34 | 2020-01-13 13:02:26 +0200 | [diff] [blame] | 912 | params.Src = "" |
Juha Hyttinen | 63284a2 | 2020-01-15 10:45:11 +0200 | [diff] [blame] | 913 | params.PayloadLen = len(trans.Payload.Buf) |
| 914 | params.Payload = trans.Payload.Buf |
Juha Hyttinen | e406a34 | 2020-01-13 13:02:26 +0200 | [diff] [blame] | 915 | params.Mbuf = nil |
Anssi Mannila | f682ace | 2021-09-28 13:11:25 +0300 | [diff] [blame] | 916 | xapp.Logger.Debug("MSG to XAPP: %s %s %s", desc, trans.String(), params.String()) |
Abukar Mohamed | fbd4df5 | 2021-03-11 06:13:27 +0000 | [diff] [blame] | 917 | err = c.SendWithRetry(params, false, 5) |
| 918 | if err != nil { |
| 919 | xapp.Logger.Error("rmrSendToXapp: Send failed: %+v", err) |
| 920 | } |
| 921 | return err |
Juha Hyttinen | e406a34 | 2020-01-13 13:02:26 +0200 | [diff] [blame] | 922 | } |
| 923 | |
Juha Hyttinen | 9dc5adc | 2020-08-13 10:02:40 +0300 | [diff] [blame] | 924 | func (c *Control) Consume(msg *xapp.RMRParams) (err error) { |
| 925 | if c.RMRClient == nil { |
Juha Hyttinen | 5f8ffa0 | 2020-02-06 15:28:59 +0200 | [diff] [blame] | 926 | err = fmt.Errorf("Rmr object nil can handle %s", msg.String()) |
| 927 | xapp.Logger.Error("%s", err.Error()) |
| 928 | return |
| 929 | } |
| 930 | c.CntRecvMsg++ |
| 931 | |
Juha Hyttinen | 9dc5adc | 2020-08-13 10:02:40 +0300 | [diff] [blame] | 932 | defer c.RMRClient.Free(msg.Mbuf) |
Juha Hyttinen | 83ada00 | 2020-01-30 10:36:33 +0200 | [diff] [blame] | 933 | |
Juha Hyttinen | a8a908d | 2020-05-26 15:12:47 +0300 | [diff] [blame] | 934 | // xapp-frame might use direct access to c buffer and |
| 935 | // when msg.Mbuf is freed, someone might take it into use |
| 936 | // and payload data might be invalid inside message handle function |
| 937 | // |
| 938 | // subscriptions won't load system a lot so there is no |
| 939 | // real performance hit by cloning buffer into new go byte slice |
| 940 | cPay := append(msg.Payload[:0:0], msg.Payload...) |
| 941 | msg.Payload = cPay |
| 942 | msg.PayloadLen = len(cPay) |
| 943 | |
Anssi Mannila | 90fa021 | 2019-12-12 10:47:47 +0200 | [diff] [blame] | 944 | switch msg.Mtype { |
Juha Hyttinen | c9eb08a | 2020-02-28 08:53:33 +0200 | [diff] [blame] | 945 | case xapp.RIC_SUB_REQ: |
Juha Hyttinen | 422d018 | 2020-01-17 13:37:05 +0200 | [diff] [blame] | 946 | go c.handleXAPPSubscriptionRequest(msg) |
Juha Hyttinen | c9eb08a | 2020-02-28 08:53:33 +0200 | [diff] [blame] | 947 | case xapp.RIC_SUB_RESP: |
Juha Hyttinen | 422d018 | 2020-01-17 13:37:05 +0200 | [diff] [blame] | 948 | go c.handleE2TSubscriptionResponse(msg) |
Juha Hyttinen | c9eb08a | 2020-02-28 08:53:33 +0200 | [diff] [blame] | 949 | case xapp.RIC_SUB_FAILURE: |
Juha Hyttinen | 422d018 | 2020-01-17 13:37:05 +0200 | [diff] [blame] | 950 | go c.handleE2TSubscriptionFailure(msg) |
Juha Hyttinen | c9eb08a | 2020-02-28 08:53:33 +0200 | [diff] [blame] | 951 | case xapp.RIC_SUB_DEL_REQ: |
Juha Hyttinen | 422d018 | 2020-01-17 13:37:05 +0200 | [diff] [blame] | 952 | go c.handleXAPPSubscriptionDeleteRequest(msg) |
Juha Hyttinen | c9eb08a | 2020-02-28 08:53:33 +0200 | [diff] [blame] | 953 | case xapp.RIC_SUB_DEL_RESP: |
Juha Hyttinen | 422d018 | 2020-01-17 13:37:05 +0200 | [diff] [blame] | 954 | go c.handleE2TSubscriptionDeleteResponse(msg) |
Juha Hyttinen | c9eb08a | 2020-02-28 08:53:33 +0200 | [diff] [blame] | 955 | case xapp.RIC_SUB_DEL_FAILURE: |
Juha Hyttinen | 422d018 | 2020-01-17 13:37:05 +0200 | [diff] [blame] | 956 | go c.handleE2TSubscriptionDeleteFailure(msg) |
gunjarastogi | 4378baf | 2023-01-18 17:51:55 +0530 | [diff] [blame] | 957 | case xapp.RIC_SUB_DEL_REQUIRED: |
| 958 | go c.handleE2TSubscriptionDeleteRequired(msg) |
Anssi Mannila | 90fa021 | 2019-12-12 10:47:47 +0200 | [diff] [blame] | 959 | default: |
Anssi Mannila | f682ace | 2021-09-28 13:11:25 +0300 | [diff] [blame] | 960 | xapp.Logger.Debug("Unknown Message Type '%d', discarding", msg.Mtype) |
Balint Uveges | cd3881b | 2019-10-02 15:01:43 +0000 | [diff] [blame] | 961 | } |
Juha Hyttinen | 5f8ffa0 | 2020-02-06 15:28:59 +0200 | [diff] [blame] | 962 | return |
Juha Hyttinen | 31797b4 | 2020-01-16 14:05:01 +0200 | [diff] [blame] | 963 | } |
| 964 | |
Juha Hyttinen | 422d018 | 2020-01-17 13:37:05 +0200 | [diff] [blame] | 965 | //------------------------------------------------------------------- |
| 966 | // handle from XAPP Subscription Request |
| 967 | //------------------------------------------------------------------ |
Juha Hyttinen | 9dc5adc | 2020-08-13 10:02:40 +0300 | [diff] [blame] | 968 | func (c *Control) handleXAPPSubscriptionRequest(params *xapp.RMRParams) { |
Anssi Mannila | f682ace | 2021-09-28 13:11:25 +0300 | [diff] [blame] | 969 | xapp.Logger.Debug("MSG from XAPP: %s", params.String()) |
Anssi Mannila | 4abf180 | 2021-01-28 13:06:46 +0200 | [diff] [blame] | 970 | c.UpdateCounter(cSubReqFromXapp) |
Juha Hyttinen | 422d018 | 2020-01-17 13:37:05 +0200 | [diff] [blame] | 971 | |
Anssi Mannila | c7da4ee | 2021-10-22 09:52:02 +0300 | [diff] [blame] | 972 | if c.e2IfState.IsE2ConnectionUp(¶ms.Meid.RanName) == false { |
| 973 | xapp.Logger.Error("No E2 connection for ranName %v", params.Meid.RanName) |
| 974 | return |
| 975 | } |
| 976 | |
Juha Hyttinen | 422d018 | 2020-01-17 13:37:05 +0200 | [diff] [blame] | 977 | subReqMsg, err := c.e2ap.UnpackSubscriptionRequest(params.Payload) |
| 978 | if err != nil { |
Juha Hyttinen | 83ada00 | 2020-01-30 10:36:33 +0200 | [diff] [blame] | 979 | xapp.Logger.Error("XAPP-SubReq: %s", idstring(err, params)) |
Juha Hyttinen | 422d018 | 2020-01-17 13:37:05 +0200 | [diff] [blame] | 980 | return |
| 981 | } |
| 982 | |
Anssi Mannila | 4c626a2 | 2021-02-11 12:50:48 +0200 | [diff] [blame] | 983 | trans := c.tracker.NewXappTransaction(xapp.NewRmrEndpoint(params.Src), params.Xid, subReqMsg.RequestId, params.Meid) |
Juha Hyttinen | 83ada00 | 2020-01-30 10:36:33 +0200 | [diff] [blame] | 984 | if trans == nil { |
| 985 | xapp.Logger.Error("XAPP-SubReq: %s", idstring(fmt.Errorf("transaction not created"), params)) |
Juha Hyttinen | 422d018 | 2020-01-17 13:37:05 +0200 | [diff] [blame] | 986 | return |
| 987 | } |
| 988 | defer trans.Release() |
| 989 | |
Anssi Mannila | 6b3796f | 2021-02-12 09:11:35 +0200 | [diff] [blame] | 990 | if err = c.tracker.Track(trans); err != nil { |
Juha Hyttinen | 83ada00 | 2020-01-30 10:36:33 +0200 | [diff] [blame] | 991 | xapp.Logger.Error("XAPP-SubReq: %s", idstring(err, trans)) |
| 992 | return |
| 993 | } |
| 994 | |
Anssi Mannila | f682ace | 2021-09-28 13:11:25 +0300 | [diff] [blame] | 995 | subs, _, err := c.registry.AssignToSubscription(trans, subReqMsg, c.ResetTestFlag, c, true) |
Juha Hyttinen | 422d018 | 2020-01-17 13:37:05 +0200 | [diff] [blame] | 996 | if err != nil { |
Juha Hyttinen | 83ada00 | 2020-01-30 10:36:33 +0200 | [diff] [blame] | 997 | xapp.Logger.Error("XAPP-SubReq: %s", idstring(err, trans)) |
Juha Hyttinen | 422d018 | 2020-01-17 13:37:05 +0200 | [diff] [blame] | 998 | return |
| 999 | } |
| 1000 | |
Anssi Mannila | 6b3796f | 2021-02-12 09:11:35 +0200 | [diff] [blame] | 1001 | c.wakeSubscriptionRequest(subs, trans) |
| 1002 | } |
| 1003 | |
| 1004 | //------------------------------------------------------------------- |
| 1005 | // Wake Subscription Request to E2node |
| 1006 | //------------------------------------------------------------------ |
| 1007 | func (c *Control) wakeSubscriptionRequest(subs *Subscription, trans *TransactionXapp) { |
| 1008 | |
Anssi Mannila | 55d6fed | 2022-08-02 12:41:48 +0300 | [diff] [blame] | 1009 | e2SubscriptionDirectives, err := c.GetE2SubscriptionDirectives(nil) |
| 1010 | if err != nil { |
| 1011 | xapp.Logger.Error("c.GetE2SubscriptionDirectives failure: %s", err.Error()) |
| 1012 | } |
Anssi Mannila | c7da4ee | 2021-10-22 09:52:02 +0300 | [diff] [blame] | 1013 | subs.OngoingReqCount++ |
Anssi Mannila | 54838ed | 2021-11-19 11:25:01 +0200 | [diff] [blame] | 1014 | go c.handleSubscriptionCreate(subs, trans, e2SubscriptionDirectives, waitRouteCleanup_ms) |
Juha Hyttinen | 422d018 | 2020-01-17 13:37:05 +0200 | [diff] [blame] | 1015 | event, _ := trans.WaitEvent(0) //blocked wait as timeout is handled in subs side |
Anssi Mannila | c7da4ee | 2021-10-22 09:52:02 +0300 | [diff] [blame] | 1016 | subs.OngoingReqCount-- |
Juha Hyttinen | 422d018 | 2020-01-17 13:37:05 +0200 | [diff] [blame] | 1017 | if event != nil { |
| 1018 | switch themsg := event.(type) { |
| 1019 | case *e2ap.E2APSubscriptionResponse: |
Anssi Mannila | 4c626a2 | 2021-02-11 12:50:48 +0200 | [diff] [blame] | 1020 | themsg.RequestId.Id = trans.RequestId.Id |
Juha Hyttinen | 422d018 | 2020-01-17 13:37:05 +0200 | [diff] [blame] | 1021 | trans.Mtype, trans.Payload, err = c.e2ap.PackSubscriptionResponse(themsg) |
| 1022 | if err == nil { |
Anssi Mannila | 64a0df4 | 2020-02-26 09:46:03 +0200 | [diff] [blame] | 1023 | trans.Release() |
Anssi Mannila | 4abf180 | 2021-01-28 13:06:46 +0200 | [diff] [blame] | 1024 | c.UpdateCounter(cSubRespToXapp) |
Anssi Mannila | 9c4697f | 2022-07-04 15:51:38 +0300 | [diff] [blame] | 1025 | err := c.rmrSendToXapp("", subs, trans) |
| 1026 | if err != nil { |
| 1027 | xapp.Logger.Error("rmrSendToXapp() failed:%s", err.Error()) |
| 1028 | } |
Juha Hyttinen | 422d018 | 2020-01-17 13:37:05 +0200 | [diff] [blame] | 1029 | return |
| 1030 | } |
| 1031 | case *e2ap.E2APSubscriptionFailure: |
Anssi Mannila | 4c626a2 | 2021-02-11 12:50:48 +0200 | [diff] [blame] | 1032 | themsg.RequestId.Id = trans.RequestId.Id |
Juha Hyttinen | 422d018 | 2020-01-17 13:37:05 +0200 | [diff] [blame] | 1033 | trans.Mtype, trans.Payload, err = c.e2ap.PackSubscriptionFailure(themsg) |
| 1034 | if err == nil { |
Anssi Mannila | 4abf180 | 2021-01-28 13:06:46 +0200 | [diff] [blame] | 1035 | c.UpdateCounter(cSubFailToXapp) |
Juha Hyttinen | 83ada00 | 2020-01-30 10:36:33 +0200 | [diff] [blame] | 1036 | c.rmrSendToXapp("", subs, trans) |
Juha Hyttinen | 422d018 | 2020-01-17 13:37:05 +0200 | [diff] [blame] | 1037 | } |
Juha Hyttinen | 422d018 | 2020-01-17 13:37:05 +0200 | [diff] [blame] | 1038 | default: |
Juha Hyttinen | 31797b4 | 2020-01-16 14:05:01 +0200 | [diff] [blame] | 1039 | break |
| 1040 | } |
| 1041 | } |
Anssi Mannila | f682ace | 2021-09-28 13:11:25 +0300 | [diff] [blame] | 1042 | xapp.Logger.Debug("XAPP-SubReq: failed %s", idstring(err, trans, subs)) |
Juha Hyttinen | 31797b4 | 2020-01-16 14:05:01 +0200 | [diff] [blame] | 1043 | } |
| 1044 | |
Juha Hyttinen | 422d018 | 2020-01-17 13:37:05 +0200 | [diff] [blame] | 1045 | //------------------------------------------------------------------- |
| 1046 | // handle from XAPP Subscription Delete Request |
| 1047 | //------------------------------------------------------------------ |
Juha Hyttinen | 9dc5adc | 2020-08-13 10:02:40 +0300 | [diff] [blame] | 1048 | func (c *Control) handleXAPPSubscriptionDeleteRequest(params *xapp.RMRParams) { |
Anssi Mannila | f682ace | 2021-09-28 13:11:25 +0300 | [diff] [blame] | 1049 | xapp.Logger.Debug("MSG from XAPP: %s", params.String()) |
Anssi Mannila | 4abf180 | 2021-01-28 13:06:46 +0200 | [diff] [blame] | 1050 | c.UpdateCounter(cSubDelReqFromXapp) |
Juha Hyttinen | 422d018 | 2020-01-17 13:37:05 +0200 | [diff] [blame] | 1051 | |
Anssi Mannila | c7da4ee | 2021-10-22 09:52:02 +0300 | [diff] [blame] | 1052 | if c.e2IfState.IsE2ConnectionUp(¶ms.Meid.RanName) == false { |
| 1053 | xapp.Logger.Error("No E2 connection for ranName %v", params.Meid.RanName) |
| 1054 | return |
| 1055 | } |
| 1056 | |
Juha Hyttinen | 422d018 | 2020-01-17 13:37:05 +0200 | [diff] [blame] | 1057 | subDelReqMsg, err := c.e2ap.UnpackSubscriptionDeleteRequest(params.Payload) |
Juha Hyttinen | 31797b4 | 2020-01-16 14:05:01 +0200 | [diff] [blame] | 1058 | if err != nil { |
Juha Hyttinen | 83ada00 | 2020-01-30 10:36:33 +0200 | [diff] [blame] | 1059 | xapp.Logger.Error("XAPP-SubDelReq %s", idstring(err, params)) |
Juha Hyttinen | 422d018 | 2020-01-17 13:37:05 +0200 | [diff] [blame] | 1060 | return |
| 1061 | } |
| 1062 | |
Anssi Mannila | 4c626a2 | 2021-02-11 12:50:48 +0200 | [diff] [blame] | 1063 | trans := c.tracker.NewXappTransaction(xapp.NewRmrEndpoint(params.Src), params.Xid, subDelReqMsg.RequestId, params.Meid) |
Juha Hyttinen | 83ada00 | 2020-01-30 10:36:33 +0200 | [diff] [blame] | 1064 | if trans == nil { |
| 1065 | xapp.Logger.Error("XAPP-SubDelReq: %s", idstring(fmt.Errorf("transaction not created"), params)) |
Juha Hyttinen | 422d018 | 2020-01-17 13:37:05 +0200 | [diff] [blame] | 1066 | return |
| 1067 | } |
| 1068 | defer trans.Release() |
| 1069 | |
Juha Hyttinen | 83ada00 | 2020-01-30 10:36:33 +0200 | [diff] [blame] | 1070 | err = c.tracker.Track(trans) |
Juha Hyttinen | 422d018 | 2020-01-17 13:37:05 +0200 | [diff] [blame] | 1071 | if err != nil { |
Juha Hyttinen | 83ada00 | 2020-01-30 10:36:33 +0200 | [diff] [blame] | 1072 | xapp.Logger.Error("XAPP-SubReq: %s", idstring(err, trans)) |
| 1073 | return |
| 1074 | } |
| 1075 | |
Juha Hyttinen | 47942b4 | 2020-02-27 10:41:43 +0200 | [diff] [blame] | 1076 | subs, err := c.registry.GetSubscriptionFirstMatch([]uint32{trans.GetSubId()}) |
Juha Hyttinen | 83ada00 | 2020-01-30 10:36:33 +0200 | [diff] [blame] | 1077 | if err != nil { |
| 1078 | xapp.Logger.Error("XAPP-SubDelReq: %s", idstring(err, trans)) |
Juha Hyttinen | 422d018 | 2020-01-17 13:37:05 +0200 | [diff] [blame] | 1079 | return |
| 1080 | } |
| 1081 | |
Juha Hyttinen | 422d018 | 2020-01-17 13:37:05 +0200 | [diff] [blame] | 1082 | // |
| 1083 | // Wake subs delete |
| 1084 | // |
Anssi Mannila | c7da4ee | 2021-10-22 09:52:02 +0300 | [diff] [blame] | 1085 | subs.OngoingDelCount++ |
Anssi Mannila | 54838ed | 2021-11-19 11:25:01 +0200 | [diff] [blame] | 1086 | go c.handleSubscriptionDelete(subs, trans, waitRouteCleanup_ms) |
Juha Hyttinen | 422d018 | 2020-01-17 13:37:05 +0200 | [diff] [blame] | 1087 | trans.WaitEvent(0) //blocked wait as timeout is handled in subs side |
Anssi Mannila | c7da4ee | 2021-10-22 09:52:02 +0300 | [diff] [blame] | 1088 | subs.OngoingDelCount-- |
Juha Hyttinen | 422d018 | 2020-01-17 13:37:05 +0200 | [diff] [blame] | 1089 | |
Juha Hyttinen | 83ada00 | 2020-01-30 10:36:33 +0200 | [diff] [blame] | 1090 | xapp.Logger.Debug("XAPP-SubDelReq: Handling event %s ", idstring(nil, trans, subs)) |
| 1091 | |
Anssi Mannila | c92b421 | 2020-12-07 14:59:34 +0200 | [diff] [blame] | 1092 | if subs.NoRespToXapp == true { |
| 1093 | // Do no send delete responses to xapps due to submgr restart is deleting uncompleted subscriptions |
Anssi Mannila | f682ace | 2021-09-28 13:11:25 +0300 | [diff] [blame] | 1094 | xapp.Logger.Debug("XAPP-SubDelReq: subs.NoRespToXapp == true") |
Anssi Mannila | c92b421 | 2020-12-07 14:59:34 +0200 | [diff] [blame] | 1095 | return |
| 1096 | } |
| 1097 | |
| 1098 | // Whatever is received success, fail or timeout, send successful delete response |
Juha Hyttinen | 422d018 | 2020-01-17 13:37:05 +0200 | [diff] [blame] | 1099 | subDelRespMsg := &e2ap.E2APSubscriptionDeleteResponse{} |
Anssi Mannila | 4c626a2 | 2021-02-11 12:50:48 +0200 | [diff] [blame] | 1100 | subDelRespMsg.RequestId.Id = trans.RequestId.Id |
| 1101 | subDelRespMsg.RequestId.InstanceId = subs.GetReqId().RequestId.InstanceId |
Juha Hyttinen | 422d018 | 2020-01-17 13:37:05 +0200 | [diff] [blame] | 1102 | subDelRespMsg.FunctionId = subs.SubReqMsg.FunctionId |
| 1103 | trans.Mtype, trans.Payload, err = c.e2ap.PackSubscriptionDeleteResponse(subDelRespMsg) |
| 1104 | if err == nil { |
Anssi Mannila | 4abf180 | 2021-01-28 13:06:46 +0200 | [diff] [blame] | 1105 | c.UpdateCounter(cSubDelRespToXapp) |
Anssi Mannila | 9c4697f | 2022-07-04 15:51:38 +0300 | [diff] [blame] | 1106 | err := c.rmrSendToXapp("", subs, trans) |
| 1107 | if err != nil { |
| 1108 | xapp.Logger.Error("rmrSendToXapp() failed:%s", err.Error()) |
| 1109 | } |
Juha Hyttinen | 422d018 | 2020-01-17 13:37:05 +0200 | [diff] [blame] | 1110 | } |
| 1111 | } |
| 1112 | |
| 1113 | //------------------------------------------------------------------- |
| 1114 | // SUBS CREATE Handling |
| 1115 | //------------------------------------------------------------------- |
Anssi Mannila | 54838ed | 2021-11-19 11:25:01 +0200 | [diff] [blame] | 1116 | func (c *Control) handleSubscriptionCreate(subs *Subscription, parentTrans *TransactionXapp, e2SubscriptionDirectives *E2SubscriptionDirectives, waitRouteCleanupTime time.Duration) { |
Juha Hyttinen | 422d018 | 2020-01-17 13:37:05 +0200 | [diff] [blame] | 1117 | |
Anssi Mannila | f682ace | 2021-09-28 13:11:25 +0300 | [diff] [blame] | 1118 | var event interface{} = nil |
Anssi Mannila | c92b421 | 2020-12-07 14:59:34 +0200 | [diff] [blame] | 1119 | var removeSubscriptionFromDb bool = false |
Juha Hyttinen | 83ada00 | 2020-01-30 10:36:33 +0200 | [diff] [blame] | 1120 | trans := c.tracker.NewSubsTransaction(subs) |
Juha Hyttinen | 422d018 | 2020-01-17 13:37:05 +0200 | [diff] [blame] | 1121 | subs.WaitTransactionTurn(trans) |
| 1122 | defer subs.ReleaseTransactionTurn(trans) |
| 1123 | defer trans.Release() |
| 1124 | |
Juha Hyttinen | 83ada00 | 2020-01-30 10:36:33 +0200 | [diff] [blame] | 1125 | xapp.Logger.Debug("SUBS-SubReq: Handling %s ", idstring(nil, trans, subs, parentTrans)) |
Juha Hyttinen | 422d018 | 2020-01-17 13:37:05 +0200 | [diff] [blame] | 1126 | |
Juha Hyttinen | 83ada00 | 2020-01-30 10:36:33 +0200 | [diff] [blame] | 1127 | subRfMsg, valid := subs.GetCachedResponse() |
| 1128 | if subRfMsg == nil && valid == true { |
Anssi Mannila | f682ace | 2021-09-28 13:11:25 +0300 | [diff] [blame] | 1129 | event = c.sendE2TSubscriptionRequest(subs, trans, parentTrans, e2SubscriptionDirectives) |
Anssi Mannila | 6d629ad | 2021-01-25 09:59:56 +0200 | [diff] [blame] | 1130 | switch event.(type) { |
| 1131 | case *e2ap.E2APSubscriptionResponse: |
| 1132 | subRfMsg, valid = subs.SetCachedResponse(event, true) |
| 1133 | subs.SubRespRcvd = true |
| 1134 | case *e2ap.E2APSubscriptionFailure: |
Anssi Mannila | 6d629ad | 2021-01-25 09:59:56 +0200 | [diff] [blame] | 1135 | subRfMsg, valid = subs.SetCachedResponse(event, false) |
Anssi Mannila | f682ace | 2021-09-28 13:11:25 +0300 | [diff] [blame] | 1136 | xapp.Logger.Debug("SUBS-SubReq: internal delete due failure event(%s) %s", typeofSubsMessage(event), idstring(nil, trans, subs, parentTrans)) |
Anssi Mannila | 6d629ad | 2021-01-25 09:59:56 +0200 | [diff] [blame] | 1137 | case *SubmgrRestartTestEvent: |
Anssi Mannila | 54838ed | 2021-11-19 11:25:01 +0200 | [diff] [blame] | 1138 | // This is used to simulate that no response has been received and after restart, subscriptions are restored from db |
Anssi Mannila | 6d629ad | 2021-01-25 09:59:56 +0200 | [diff] [blame] | 1139 | xapp.Logger.Debug("Test restart flag is active. Dropping this transaction to test restart case") |
Anssi Mannila | 54838ed | 2021-11-19 11:25:01 +0200 | [diff] [blame] | 1140 | subRfMsg, valid = subs.SetCachedResponse(event, false) |
| 1141 | parentTrans.SendEvent(subRfMsg, 0) |
| 1142 | return |
Anssi Mannila | f682ace | 2021-09-28 13:11:25 +0300 | [diff] [blame] | 1143 | case *PackSubscriptionRequestErrortEvent, *SDLWriteErrortEvent: |
| 1144 | subRfMsg, valid = subs.SetCachedResponse(event, false) |
Anssi Mannila | 6d629ad | 2021-01-25 09:59:56 +0200 | [diff] [blame] | 1145 | default: |
Anssi Mannila | 3d80b72 | 2021-11-12 13:17:15 +0200 | [diff] [blame] | 1146 | // Timer expiry |
Anssi Mannila | f682ace | 2021-09-28 13:11:25 +0300 | [diff] [blame] | 1147 | if subs.PolicyUpdate == false { |
| 1148 | xapp.Logger.Debug("SUBS-SubReq: internal delete due default event(%s) %s", typeofSubsMessage(event), idstring(nil, trans, subs, parentTrans)) |
Anssi Mannila | f682ace | 2021-09-28 13:11:25 +0300 | [diff] [blame] | 1149 | subRfMsg, valid = subs.SetCachedResponse(nil, false) |
| 1150 | c.sendE2TSubscriptionDeleteRequest(subs, trans, parentTrans) |
Anssi Mannila | 54838ed | 2021-11-19 11:25:01 +0200 | [diff] [blame] | 1151 | } else { |
| 1152 | subRfMsg, valid = subs.SetCachedResponse(nil, true) |
Anssi Mannila | f682ace | 2021-09-28 13:11:25 +0300 | [diff] [blame] | 1153 | } |
Juha Hyttinen | 83ada00 | 2020-01-30 10:36:33 +0200 | [diff] [blame] | 1154 | } |
| 1155 | xapp.Logger.Debug("SUBS-SubReq: Handling (e2t response %s) %s", typeofSubsMessage(subRfMsg), idstring(nil, trans, subs, parentTrans)) |
| 1156 | } else { |
| 1157 | xapp.Logger.Debug("SUBS-SubReq: Handling (cached response %s) %s", typeofSubsMessage(subRfMsg), idstring(nil, trans, subs, parentTrans)) |
Juha Hyttinen | 422d018 | 2020-01-17 13:37:05 +0200 | [diff] [blame] | 1158 | } |
Anssi Mannila | 54838ed | 2021-11-19 11:25:01 +0200 | [diff] [blame] | 1159 | if valid == false { |
| 1160 | removeSubscriptionFromDb = true |
| 1161 | } |
Juha Hyttinen | 422d018 | 2020-01-17 13:37:05 +0200 | [diff] [blame] | 1162 | |
Anssi Mannila | f682ace | 2021-09-28 13:11:25 +0300 | [diff] [blame] | 1163 | err := c.UpdateSubscriptionInDB(subs, removeSubscriptionFromDb) |
| 1164 | if err != nil { |
Anssi Mannila | 54838ed | 2021-11-19 11:25:01 +0200 | [diff] [blame] | 1165 | valid = false |
Anssi Mannila | f682ace | 2021-09-28 13:11:25 +0300 | [diff] [blame] | 1166 | c.sendE2TSubscriptionDeleteRequest(subs, trans, parentTrans) |
Anssi Mannila | 9c4697f | 2022-07-04 15:51:38 +0300 | [diff] [blame] | 1167 | |
Anssi Mannila | f682ace | 2021-09-28 13:11:25 +0300 | [diff] [blame] | 1168 | } |
| 1169 | |
Anssi Mannila | 2738517 | 2021-12-22 09:41:54 +0200 | [diff] [blame] | 1170 | // Now RemoveFromSubscription in here to avoid race conditions (mostly concerns delete) |
Juha Hyttinen | 429cfe6 | 2020-03-31 11:23:02 +0300 | [diff] [blame] | 1171 | if valid == false { |
Anssi Mannila | 55d6fed | 2022-08-02 12:41:48 +0300 | [diff] [blame] | 1172 | c.registry.RemoveFromSubscription(subs, parentTrans, waitRouteCleanupTime, c) |
Juha Hyttinen | 429cfe6 | 2020-03-31 11:23:02 +0300 | [diff] [blame] | 1173 | } |
Anssi Mannila | c92b421 | 2020-12-07 14:59:34 +0200 | [diff] [blame] | 1174 | |
Juha Hyttinen | 83ada00 | 2020-01-30 10:36:33 +0200 | [diff] [blame] | 1175 | parentTrans.SendEvent(subRfMsg, 0) |
Juha Hyttinen | 422d018 | 2020-01-17 13:37:05 +0200 | [diff] [blame] | 1176 | } |
| 1177 | |
| 1178 | //------------------------------------------------------------------- |
| 1179 | // SUBS DELETE Handling |
| 1180 | //------------------------------------------------------------------- |
Juha Hyttinen | 3944a22 | 2020-01-24 11:51:46 +0200 | [diff] [blame] | 1181 | |
Anssi Mannila | 54838ed | 2021-11-19 11:25:01 +0200 | [diff] [blame] | 1182 | func (c *Control) handleSubscriptionDelete(subs *Subscription, parentTrans *TransactionXapp, waitRouteCleanupTime time.Duration) { |
Juha Hyttinen | 422d018 | 2020-01-17 13:37:05 +0200 | [diff] [blame] | 1183 | |
Juha Hyttinen | 83ada00 | 2020-01-30 10:36:33 +0200 | [diff] [blame] | 1184 | trans := c.tracker.NewSubsTransaction(subs) |
Juha Hyttinen | 422d018 | 2020-01-17 13:37:05 +0200 | [diff] [blame] | 1185 | subs.WaitTransactionTurn(trans) |
| 1186 | defer subs.ReleaseTransactionTurn(trans) |
| 1187 | defer trans.Release() |
| 1188 | |
Juha Hyttinen | 83ada00 | 2020-01-30 10:36:33 +0200 | [diff] [blame] | 1189 | xapp.Logger.Debug("SUBS-SubDelReq: Handling %s", idstring(nil, trans, subs, parentTrans)) |
Juha Hyttinen | 422d018 | 2020-01-17 13:37:05 +0200 | [diff] [blame] | 1190 | |
Juha Hyttinen | 3944a22 | 2020-01-24 11:51:46 +0200 | [diff] [blame] | 1191 | subs.mutex.Lock() |
Anssi Mannila | 4abf180 | 2021-01-28 13:06:46 +0200 | [diff] [blame] | 1192 | |
Juha Hyttinen | 3944a22 | 2020-01-24 11:51:46 +0200 | [diff] [blame] | 1193 | if subs.valid && subs.EpList.HasEndpoint(parentTrans.GetEndpoint()) && subs.EpList.Size() == 1 { |
| 1194 | subs.valid = false |
| 1195 | subs.mutex.Unlock() |
| 1196 | c.sendE2TSubscriptionDeleteRequest(subs, trans, parentTrans) |
| 1197 | } else { |
| 1198 | subs.mutex.Unlock() |
| 1199 | } |
Anssi Mannila | 2738517 | 2021-12-22 09:41:54 +0200 | [diff] [blame] | 1200 | |
| 1201 | // Now RemoveFromSubscription in here to avoid race conditions (mostly concerns delete) |
Anssi Mannila | 54838ed | 2021-11-19 11:25:01 +0200 | [diff] [blame] | 1202 | c.registry.RemoveFromSubscription(subs, parentTrans, waitRouteCleanupTime, c) |
Juha Hyttinen | 47942b4 | 2020-02-27 10:41:43 +0200 | [diff] [blame] | 1203 | parentTrans.SendEvent(nil, 0) |
Juha Hyttinen | 422d018 | 2020-01-17 13:37:05 +0200 | [diff] [blame] | 1204 | } |
| 1205 | |
| 1206 | //------------------------------------------------------------------- |
| 1207 | // send to E2T Subscription Request |
| 1208 | //------------------------------------------------------------------- |
Anssi Mannila | f682ace | 2021-09-28 13:11:25 +0300 | [diff] [blame] | 1209 | func (c *Control) sendE2TSubscriptionRequest(subs *Subscription, trans *TransactionSubs, parentTrans *TransactionXapp, e2SubscriptionDirectives *E2SubscriptionDirectives) interface{} { |
Juha Hyttinen | 422d018 | 2020-01-17 13:37:05 +0200 | [diff] [blame] | 1210 | var err error |
| 1211 | var event interface{} = nil |
| 1212 | var timedOut bool = false |
Konstantinos Archangelof | 26dfa71 | 2021-06-04 12:10:26 +0000 | [diff] [blame] | 1213 | const ricRequestorId = 123 |
Juha Hyttinen | 422d018 | 2020-01-17 13:37:05 +0200 | [diff] [blame] | 1214 | |
| 1215 | subReqMsg := subs.SubReqMsg |
Juha Hyttinen | 83ada00 | 2020-01-30 10:36:33 +0200 | [diff] [blame] | 1216 | subReqMsg.RequestId = subs.GetReqId().RequestId |
Konstantinos Archangelof | 26dfa71 | 2021-06-04 12:10:26 +0000 | [diff] [blame] | 1217 | subReqMsg.RequestId.Id = ricRequestorId |
Juha Hyttinen | 422d018 | 2020-01-17 13:37:05 +0200 | [diff] [blame] | 1218 | trans.Mtype, trans.Payload, err = c.e2ap.PackSubscriptionRequest(subReqMsg) |
| 1219 | if err != nil { |
Anssi Mannila | b43397e | 2021-11-16 12:06:16 +0200 | [diff] [blame] | 1220 | xapp.Logger.Error("SUBS-SubReq ASN1 pack error: %s", idstring(err, trans, subs, parentTrans)) |
Anssi Mannila | f682ace | 2021-09-28 13:11:25 +0300 | [diff] [blame] | 1221 | return &PackSubscriptionRequestErrortEvent{ |
| 1222 | ErrorInfo{ |
| 1223 | ErrorSource: models.SubscriptionInstanceErrorSourceASN1, |
| 1224 | ErrorCause: err.Error(), |
| 1225 | }, |
| 1226 | } |
Juha Hyttinen | 422d018 | 2020-01-17 13:37:05 +0200 | [diff] [blame] | 1227 | } |
| 1228 | |
Anssi Mannila | c92b421 | 2020-12-07 14:59:34 +0200 | [diff] [blame] | 1229 | // Write uncompleted subscrition in db. If no response for subscrition it need to be re-processed (deleted) after restart |
Anssi Mannila | f682ace | 2021-09-28 13:11:25 +0300 | [diff] [blame] | 1230 | err = c.WriteSubscriptionToDb(subs) |
| 1231 | if err != nil { |
| 1232 | return &SDLWriteErrortEvent{ |
| 1233 | ErrorInfo{ |
| 1234 | ErrorSource: models.SubscriptionInstanceErrorSourceDBAAS, |
| 1235 | ErrorCause: err.Error(), |
| 1236 | }, |
| 1237 | } |
| 1238 | } |
Markku Virtanen | fe2cdab | 2021-05-21 10:59:29 +0000 | [diff] [blame] | 1239 | |
Anssi Mannila | f682ace | 2021-09-28 13:11:25 +0300 | [diff] [blame] | 1240 | for retries := int64(0); retries < e2SubscriptionDirectives.E2MaxTryCount; retries++ { |
Juha Hyttinen | 83ada00 | 2020-01-30 10:36:33 +0200 | [diff] [blame] | 1241 | desc := fmt.Sprintf("(retry %d)", retries) |
Anssi Mannila | 4abf180 | 2021-01-28 13:06:46 +0200 | [diff] [blame] | 1242 | if retries == 0 { |
| 1243 | c.UpdateCounter(cSubReqToE2) |
| 1244 | } else { |
| 1245 | c.UpdateCounter(cSubReReqToE2) |
| 1246 | } |
Anssi Mannila | 9c4697f | 2022-07-04 15:51:38 +0300 | [diff] [blame] | 1247 | err := c.rmrSendToE2T(desc, subs, trans) |
| 1248 | if err != nil { |
| 1249 | xapp.Logger.Error("rmrSendToE2T() failed:%s", err.Error()) |
| 1250 | } |
| 1251 | |
Anssi Mannila | c92b421 | 2020-12-07 14:59:34 +0200 | [diff] [blame] | 1252 | if subs.DoNotWaitSubResp == false { |
Anssi Mannila | f682ace | 2021-09-28 13:11:25 +0300 | [diff] [blame] | 1253 | event, timedOut = trans.WaitEvent(e2SubscriptionDirectives.E2TimeoutTimerValue) |
Anssi Mannila | c92b421 | 2020-12-07 14:59:34 +0200 | [diff] [blame] | 1254 | if timedOut { |
Anssi Mannila | 4abf180 | 2021-01-28 13:06:46 +0200 | [diff] [blame] | 1255 | c.UpdateCounter(cSubReqTimerExpiry) |
Anssi Mannila | c92b421 | 2020-12-07 14:59:34 +0200 | [diff] [blame] | 1256 | continue |
| 1257 | } |
| 1258 | } else { |
| 1259 | // Simulating case where subscrition request has been sent but response has not been received before restart |
| 1260 | event = &SubmgrRestartTestEvent{} |
Anssi Mannila | f682ace | 2021-09-28 13:11:25 +0300 | [diff] [blame] | 1261 | xapp.Logger.Debug("Restart event, DoNotWaitSubResp == true") |
Juha Hyttinen | 422d018 | 2020-01-17 13:37:05 +0200 | [diff] [blame] | 1262 | } |
| 1263 | break |
| 1264 | } |
Juha Hyttinen | 83ada00 | 2020-01-30 10:36:33 +0200 | [diff] [blame] | 1265 | xapp.Logger.Debug("SUBS-SubReq: Response handling event(%s) %s", typeofSubsMessage(event), idstring(nil, trans, subs, parentTrans)) |
Juha Hyttinen | 422d018 | 2020-01-17 13:37:05 +0200 | [diff] [blame] | 1266 | return event |
| 1267 | } |
| 1268 | |
| 1269 | //------------------------------------------------------------------- |
| 1270 | // send to E2T Subscription Delete Request |
| 1271 | //------------------------------------------------------------------- |
| 1272 | |
Juha Hyttinen | 83ada00 | 2020-01-30 10:36:33 +0200 | [diff] [blame] | 1273 | func (c *Control) sendE2TSubscriptionDeleteRequest(subs *Subscription, trans *TransactionSubs, parentTrans *TransactionXapp) interface{} { |
Juha Hyttinen | 422d018 | 2020-01-17 13:37:05 +0200 | [diff] [blame] | 1274 | var err error |
| 1275 | var event interface{} |
| 1276 | var timedOut bool |
Konstantinos Archangelof | 26dfa71 | 2021-06-04 12:10:26 +0000 | [diff] [blame] | 1277 | const ricRequestorId = 123 |
Juha Hyttinen | 422d018 | 2020-01-17 13:37:05 +0200 | [diff] [blame] | 1278 | |
| 1279 | subDelReqMsg := &e2ap.E2APSubscriptionDeleteRequest{} |
Juha Hyttinen | 83ada00 | 2020-01-30 10:36:33 +0200 | [diff] [blame] | 1280 | subDelReqMsg.RequestId = subs.GetReqId().RequestId |
Konstantinos Archangelof | 26dfa71 | 2021-06-04 12:10:26 +0000 | [diff] [blame] | 1281 | subDelReqMsg.RequestId.Id = ricRequestorId |
Juha Hyttinen | af91f97 | 2020-01-24 08:38:47 +0200 | [diff] [blame] | 1282 | subDelReqMsg.FunctionId = subs.SubReqMsg.FunctionId |
Juha Hyttinen | 422d018 | 2020-01-17 13:37:05 +0200 | [diff] [blame] | 1283 | trans.Mtype, trans.Payload, err = c.e2ap.PackSubscriptionDeleteRequest(subDelReqMsg) |
| 1284 | if err != nil { |
Juha Hyttinen | 83ada00 | 2020-01-30 10:36:33 +0200 | [diff] [blame] | 1285 | xapp.Logger.Error("SUBS-SubDelReq: %s", idstring(err, trans, subs, parentTrans)) |
Juha Hyttinen | 422d018 | 2020-01-17 13:37:05 +0200 | [diff] [blame] | 1286 | return event |
| 1287 | } |
| 1288 | |
| 1289 | for retries := uint64(0); retries < e2tMaxSubDelReqTryCount; retries++ { |
Juha Hyttinen | 83ada00 | 2020-01-30 10:36:33 +0200 | [diff] [blame] | 1290 | desc := fmt.Sprintf("(retry %d)", retries) |
Anssi Mannila | 4abf180 | 2021-01-28 13:06:46 +0200 | [diff] [blame] | 1291 | if retries == 0 { |
| 1292 | c.UpdateCounter(cSubDelReqToE2) |
| 1293 | } else { |
| 1294 | c.UpdateCounter(cSubDelReReqToE2) |
| 1295 | } |
Anssi Mannila | 9c4697f | 2022-07-04 15:51:38 +0300 | [diff] [blame] | 1296 | err := c.rmrSendToE2T(desc, subs, trans) |
| 1297 | if err != nil { |
| 1298 | xapp.Logger.Error("SUBS-SubDelReq: rmrSendToE2T failure: %s", idstring(err, trans, subs, parentTrans)) |
| 1299 | } |
Juha Hyttinen | 422d018 | 2020-01-17 13:37:05 +0200 | [diff] [blame] | 1300 | event, timedOut = trans.WaitEvent(e2tSubDelReqTime) |
| 1301 | if timedOut { |
Anssi Mannila | 4abf180 | 2021-01-28 13:06:46 +0200 | [diff] [blame] | 1302 | c.UpdateCounter(cSubDelReqTimerExpiry) |
Juha Hyttinen | 422d018 | 2020-01-17 13:37:05 +0200 | [diff] [blame] | 1303 | continue |
| 1304 | } |
| 1305 | break |
| 1306 | } |
Juha Hyttinen | 83ada00 | 2020-01-30 10:36:33 +0200 | [diff] [blame] | 1307 | xapp.Logger.Debug("SUBS-SubDelReq: Response handling event(%s) %s", typeofSubsMessage(event), idstring(nil, trans, subs, parentTrans)) |
Juha Hyttinen | 422d018 | 2020-01-17 13:37:05 +0200 | [diff] [blame] | 1308 | return event |
| 1309 | } |
| 1310 | |
| 1311 | //------------------------------------------------------------------- |
Anssi Mannila | 4abf180 | 2021-01-28 13:06:46 +0200 | [diff] [blame] | 1312 | // handle from E2T Subscription Response |
Juha Hyttinen | 422d018 | 2020-01-17 13:37:05 +0200 | [diff] [blame] | 1313 | //------------------------------------------------------------------- |
Juha Hyttinen | 9dc5adc | 2020-08-13 10:02:40 +0300 | [diff] [blame] | 1314 | func (c *Control) handleE2TSubscriptionResponse(params *xapp.RMRParams) { |
Anssi Mannila | f682ace | 2021-09-28 13:11:25 +0300 | [diff] [blame] | 1315 | xapp.Logger.Debug("MSG from E2T: %s", params.String()) |
Anssi Mannila | 4abf180 | 2021-01-28 13:06:46 +0200 | [diff] [blame] | 1316 | c.UpdateCounter(cSubRespFromE2) |
Anssi Mannila | 5112239 | 2021-05-25 11:51:31 +0300 | [diff] [blame] | 1317 | |
Juha Hyttinen | 422d018 | 2020-01-17 13:37:05 +0200 | [diff] [blame] | 1318 | subRespMsg, err := c.e2ap.UnpackSubscriptionResponse(params.Payload) |
| 1319 | if err != nil { |
Juha Hyttinen | 83ada00 | 2020-01-30 10:36:33 +0200 | [diff] [blame] | 1320 | xapp.Logger.Error("MSG-SubResp %s", idstring(err, params)) |
Juha Hyttinen | 422d018 | 2020-01-17 13:37:05 +0200 | [diff] [blame] | 1321 | return |
| 1322 | } |
Juha Hyttinen | aada645 | 2020-04-07 08:47:58 +0300 | [diff] [blame] | 1323 | subs, err := c.registry.GetSubscriptionFirstMatch([]uint32{subRespMsg.RequestId.InstanceId}) |
Juha Hyttinen | 422d018 | 2020-01-17 13:37:05 +0200 | [diff] [blame] | 1324 | if err != nil { |
Juha Hyttinen | 83ada00 | 2020-01-30 10:36:33 +0200 | [diff] [blame] | 1325 | xapp.Logger.Error("MSG-SubResp: %s", idstring(err, params)) |
Juha Hyttinen | 422d018 | 2020-01-17 13:37:05 +0200 | [diff] [blame] | 1326 | return |
Juha Hyttinen | 31797b4 | 2020-01-16 14:05:01 +0200 | [diff] [blame] | 1327 | } |
| 1328 | trans := subs.GetTransaction() |
| 1329 | if trans == nil { |
Juha Hyttinen | 422d018 | 2020-01-17 13:37:05 +0200 | [diff] [blame] | 1330 | err = fmt.Errorf("Ongoing transaction not found") |
Juha Hyttinen | 83ada00 | 2020-01-30 10:36:33 +0200 | [diff] [blame] | 1331 | xapp.Logger.Error("MSG-SubResp: %s", idstring(err, params, subs)) |
Juha Hyttinen | ff8dccd | 2019-12-10 14:34:07 +0200 | [diff] [blame] | 1332 | return |
Anssi Mannila | 2e99e2f | 2019-12-05 13:57:06 +0200 | [diff] [blame] | 1333 | } |
Anssi Mannila | 54838ed | 2021-11-19 11:25:01 +0200 | [diff] [blame] | 1334 | xapp.Logger.Debug("SUBS-SubResp: Sending event, trans= %v", trans) |
Juha Hyttinen | 422d018 | 2020-01-17 13:37:05 +0200 | [diff] [blame] | 1335 | sendOk, timedOut := trans.SendEvent(subRespMsg, e2tRecvMsgTimeout) |
| 1336 | if sendOk == false { |
| 1337 | err = fmt.Errorf("Passing event to transaction failed: sendOk(%t) timedOut(%t)", sendOk, timedOut) |
Juha Hyttinen | 83ada00 | 2020-01-30 10:36:33 +0200 | [diff] [blame] | 1338 | xapp.Logger.Error("MSG-SubResp: %s", idstring(err, trans, subs)) |
Peter Szilagyi | fbc56f9 | 2019-07-23 19:29:46 +0000 | [diff] [blame] | 1339 | } |
Peter Szilagyi | fbc56f9 | 2019-07-23 19:29:46 +0000 | [diff] [blame] | 1340 | return |
kalnagy | 4511475 | 2019-06-18 14:40:39 +0200 | [diff] [blame] | 1341 | } |
| 1342 | |
Juha Hyttinen | 422d018 | 2020-01-17 13:37:05 +0200 | [diff] [blame] | 1343 | //------------------------------------------------------------------- |
| 1344 | // handle from E2T Subscription Failure |
| 1345 | //------------------------------------------------------------------- |
Juha Hyttinen | 9dc5adc | 2020-08-13 10:02:40 +0300 | [diff] [blame] | 1346 | func (c *Control) handleE2TSubscriptionFailure(params *xapp.RMRParams) { |
Anssi Mannila | f682ace | 2021-09-28 13:11:25 +0300 | [diff] [blame] | 1347 | xapp.Logger.Debug("MSG from E2T: %s", params.String()) |
Anssi Mannila | 4abf180 | 2021-01-28 13:06:46 +0200 | [diff] [blame] | 1348 | c.UpdateCounter(cSubFailFromE2) |
Juha Hyttinen | 422d018 | 2020-01-17 13:37:05 +0200 | [diff] [blame] | 1349 | subFailMsg, err := c.e2ap.UnpackSubscriptionFailure(params.Payload) |
Peter Szilagyi | fbc56f9 | 2019-07-23 19:29:46 +0000 | [diff] [blame] | 1350 | if err != nil { |
Juha Hyttinen | 83ada00 | 2020-01-30 10:36:33 +0200 | [diff] [blame] | 1351 | xapp.Logger.Error("MSG-SubFail %s", idstring(err, params)) |
Peter Szilagyi | fbc56f9 | 2019-07-23 19:29:46 +0000 | [diff] [blame] | 1352 | return |
| 1353 | } |
Juha Hyttinen | aada645 | 2020-04-07 08:47:58 +0300 | [diff] [blame] | 1354 | subs, err := c.registry.GetSubscriptionFirstMatch([]uint32{subFailMsg.RequestId.InstanceId}) |
Juha Hyttinen | 31797b4 | 2020-01-16 14:05:01 +0200 | [diff] [blame] | 1355 | if err != nil { |
Juha Hyttinen | 83ada00 | 2020-01-30 10:36:33 +0200 | [diff] [blame] | 1356 | xapp.Logger.Error("MSG-SubFail: %s", idstring(err, params)) |
Juha Hyttinen | aafee7f | 2020-01-14 14:54:51 +0200 | [diff] [blame] | 1357 | return |
| 1358 | } |
Juha Hyttinen | 422d018 | 2020-01-17 13:37:05 +0200 | [diff] [blame] | 1359 | trans := subs.GetTransaction() |
| 1360 | if trans == nil { |
| 1361 | err = fmt.Errorf("Ongoing transaction not found") |
Juha Hyttinen | 83ada00 | 2020-01-30 10:36:33 +0200 | [diff] [blame] | 1362 | xapp.Logger.Error("MSG-SubFail: %s", idstring(err, params, subs)) |
Anssi Mannila | 8046c70 | 2020-01-02 13:39:05 +0200 | [diff] [blame] | 1363 | return |
| 1364 | } |
Juha Hyttinen | 422d018 | 2020-01-17 13:37:05 +0200 | [diff] [blame] | 1365 | sendOk, timedOut := trans.SendEvent(subFailMsg, e2tRecvMsgTimeout) |
| 1366 | if sendOk == false { |
| 1367 | err = fmt.Errorf("Passing event to transaction failed: sendOk(%t) timedOut(%t)", sendOk, timedOut) |
Juha Hyttinen | 83ada00 | 2020-01-30 10:36:33 +0200 | [diff] [blame] | 1368 | xapp.Logger.Error("MSG-SubFail: %s", idstring(err, trans, subs)) |
Juha Hyttinen | aafee7f | 2020-01-14 14:54:51 +0200 | [diff] [blame] | 1369 | } |
Anssi Mannila | 2e99e2f | 2019-12-05 13:57:06 +0200 | [diff] [blame] | 1370 | return |
| 1371 | } |
| 1372 | |
Juha Hyttinen | 422d018 | 2020-01-17 13:37:05 +0200 | [diff] [blame] | 1373 | //------------------------------------------------------------------- |
| 1374 | // handle from E2T Subscription Delete Response |
| 1375 | //------------------------------------------------------------------- |
Anssi Mannila | 9c4697f | 2022-07-04 15:51:38 +0300 | [diff] [blame] | 1376 | func (c *Control) handleE2TSubscriptionDeleteResponse(params *xapp.RMRParams) { |
Anssi Mannila | f682ace | 2021-09-28 13:11:25 +0300 | [diff] [blame] | 1377 | xapp.Logger.Debug("MSG from E2T: %s", params.String()) |
Anssi Mannila | 4abf180 | 2021-01-28 13:06:46 +0200 | [diff] [blame] | 1378 | c.UpdateCounter(cSubDelRespFromE2) |
Juha Hyttinen | 422d018 | 2020-01-17 13:37:05 +0200 | [diff] [blame] | 1379 | subDelRespMsg, err := c.e2ap.UnpackSubscriptionDeleteResponse(params.Payload) |
Anssi Mannila | 2e99e2f | 2019-12-05 13:57:06 +0200 | [diff] [blame] | 1380 | if err != nil { |
Juha Hyttinen | 83ada00 | 2020-01-30 10:36:33 +0200 | [diff] [blame] | 1381 | xapp.Logger.Error("MSG-SubDelResp: %s", idstring(err, params)) |
Anssi Mannila | 2e99e2f | 2019-12-05 13:57:06 +0200 | [diff] [blame] | 1382 | return |
| 1383 | } |
Juha Hyttinen | aada645 | 2020-04-07 08:47:58 +0300 | [diff] [blame] | 1384 | subs, err := c.registry.GetSubscriptionFirstMatch([]uint32{subDelRespMsg.RequestId.InstanceId}) |
Juha Hyttinen | 31797b4 | 2020-01-16 14:05:01 +0200 | [diff] [blame] | 1385 | if err != nil { |
Juha Hyttinen | 83ada00 | 2020-01-30 10:36:33 +0200 | [diff] [blame] | 1386 | xapp.Logger.Error("MSG-SubDelResp: %s", idstring(err, params)) |
Juha Hyttinen | 0d064ec | 2020-01-09 09:08:53 +0200 | [diff] [blame] | 1387 | return |
| 1388 | } |
Juha Hyttinen | 422d018 | 2020-01-17 13:37:05 +0200 | [diff] [blame] | 1389 | trans := subs.GetTransaction() |
| 1390 | if trans == nil { |
| 1391 | err = fmt.Errorf("Ongoing transaction not found") |
Juha Hyttinen | 83ada00 | 2020-01-30 10:36:33 +0200 | [diff] [blame] | 1392 | xapp.Logger.Error("MSG-SubDelResp: %s", idstring(err, params, subs)) |
Anssi Mannila | 8046c70 | 2020-01-02 13:39:05 +0200 | [diff] [blame] | 1393 | return |
Anssi Mannila | 2e99e2f | 2019-12-05 13:57:06 +0200 | [diff] [blame] | 1394 | } |
Juha Hyttinen | 422d018 | 2020-01-17 13:37:05 +0200 | [diff] [blame] | 1395 | sendOk, timedOut := trans.SendEvent(subDelRespMsg, e2tRecvMsgTimeout) |
| 1396 | if sendOk == false { |
| 1397 | err = fmt.Errorf("Passing event to transaction failed: sendOk(%t) timedOut(%t)", sendOk, timedOut) |
Juha Hyttinen | 83ada00 | 2020-01-30 10:36:33 +0200 | [diff] [blame] | 1398 | xapp.Logger.Error("MSG-SubDelResp: %s", idstring(err, trans, subs)) |
Juha Hyttinen | 60bfcf9 | 2020-01-14 15:14:24 +0200 | [diff] [blame] | 1399 | } |
Anssi Mannila | 2e99e2f | 2019-12-05 13:57:06 +0200 | [diff] [blame] | 1400 | return |
| 1401 | } |
| 1402 | |
Juha Hyttinen | 422d018 | 2020-01-17 13:37:05 +0200 | [diff] [blame] | 1403 | //------------------------------------------------------------------- |
| 1404 | // handle from E2T Subscription Delete Failure |
| 1405 | //------------------------------------------------------------------- |
Juha Hyttinen | 9dc5adc | 2020-08-13 10:02:40 +0300 | [diff] [blame] | 1406 | func (c *Control) handleE2TSubscriptionDeleteFailure(params *xapp.RMRParams) { |
Anssi Mannila | f682ace | 2021-09-28 13:11:25 +0300 | [diff] [blame] | 1407 | xapp.Logger.Debug("MSG from E2T: %s", params.String()) |
Anssi Mannila | 4abf180 | 2021-01-28 13:06:46 +0200 | [diff] [blame] | 1408 | c.UpdateCounter(cSubDelFailFromE2) |
Juha Hyttinen | 422d018 | 2020-01-17 13:37:05 +0200 | [diff] [blame] | 1409 | subDelFailMsg, err := c.e2ap.UnpackSubscriptionDeleteFailure(params.Payload) |
Juha Hyttinen | 31797b4 | 2020-01-16 14:05:01 +0200 | [diff] [blame] | 1410 | if err != nil { |
Juha Hyttinen | 83ada00 | 2020-01-30 10:36:33 +0200 | [diff] [blame] | 1411 | xapp.Logger.Error("MSG-SubDelFail: %s", idstring(err, params)) |
Anssi Mannila | f1d0eb6 | 2019-12-17 15:29:55 +0200 | [diff] [blame] | 1412 | return |
| 1413 | } |
Juha Hyttinen | aada645 | 2020-04-07 08:47:58 +0300 | [diff] [blame] | 1414 | subs, err := c.registry.GetSubscriptionFirstMatch([]uint32{subDelFailMsg.RequestId.InstanceId}) |
Anssi Mannila | 8046c70 | 2020-01-02 13:39:05 +0200 | [diff] [blame] | 1415 | if err != nil { |
Juha Hyttinen | 83ada00 | 2020-01-30 10:36:33 +0200 | [diff] [blame] | 1416 | xapp.Logger.Error("MSG-SubDelFail: %s", idstring(err, params)) |
Anssi Mannila | 8046c70 | 2020-01-02 13:39:05 +0200 | [diff] [blame] | 1417 | return |
| 1418 | } |
Juha Hyttinen | 422d018 | 2020-01-17 13:37:05 +0200 | [diff] [blame] | 1419 | trans := subs.GetTransaction() |
| 1420 | if trans == nil { |
| 1421 | err = fmt.Errorf("Ongoing transaction not found") |
Juha Hyttinen | 83ada00 | 2020-01-30 10:36:33 +0200 | [diff] [blame] | 1422 | xapp.Logger.Error("MSG-SubDelFail: %s", idstring(err, params, subs)) |
Juha Hyttinen | 86a4620 | 2020-01-14 12:49:09 +0200 | [diff] [blame] | 1423 | return |
| 1424 | } |
Juha Hyttinen | 422d018 | 2020-01-17 13:37:05 +0200 | [diff] [blame] | 1425 | sendOk, timedOut := trans.SendEvent(subDelFailMsg, e2tRecvMsgTimeout) |
| 1426 | if sendOk == false { |
| 1427 | err = fmt.Errorf("Passing event to transaction failed: sendOk(%t) timedOut(%t)", sendOk, timedOut) |
Juha Hyttinen | 83ada00 | 2020-01-30 10:36:33 +0200 | [diff] [blame] | 1428 | xapp.Logger.Error("MSG-SubDelFail: %s", idstring(err, trans, subs)) |
Anssi Mannila | 8046c70 | 2020-01-02 13:39:05 +0200 | [diff] [blame] | 1429 | } |
kalnagy | 93cc3e2 | 2019-09-19 11:29:29 +0200 | [diff] [blame] | 1430 | return |
| 1431 | } |
| 1432 | |
Juha Hyttinen | 422d018 | 2020-01-17 13:37:05 +0200 | [diff] [blame] | 1433 | //------------------------------------------------------------------- |
| 1434 | // |
| 1435 | //------------------------------------------------------------------- |
| 1436 | func typeofSubsMessage(v interface{}) string { |
| 1437 | if v == nil { |
| 1438 | return "NIL" |
kalnagy | 93cc3e2 | 2019-09-19 11:29:29 +0200 | [diff] [blame] | 1439 | } |
Juha Hyttinen | 422d018 | 2020-01-17 13:37:05 +0200 | [diff] [blame] | 1440 | switch v.(type) { |
Anssi Mannila | 5112239 | 2021-05-25 11:51:31 +0300 | [diff] [blame] | 1441 | //case *e2ap.E2APSubscriptionRequest: |
| 1442 | // return "SubReq" |
Juha Hyttinen | 422d018 | 2020-01-17 13:37:05 +0200 | [diff] [blame] | 1443 | case *e2ap.E2APSubscriptionResponse: |
| 1444 | return "SubResp" |
| 1445 | case *e2ap.E2APSubscriptionFailure: |
| 1446 | return "SubFail" |
Anssi Mannila | 5112239 | 2021-05-25 11:51:31 +0300 | [diff] [blame] | 1447 | //case *e2ap.E2APSubscriptionDeleteRequest: |
| 1448 | // return "SubDelReq" |
Juha Hyttinen | 422d018 | 2020-01-17 13:37:05 +0200 | [diff] [blame] | 1449 | case *e2ap.E2APSubscriptionDeleteResponse: |
| 1450 | return "SubDelResp" |
| 1451 | case *e2ap.E2APSubscriptionDeleteFailure: |
| 1452 | return "SubDelFail" |
| 1453 | default: |
| 1454 | return "Unknown" |
Juha Hyttinen | 31797b4 | 2020-01-16 14:05:01 +0200 | [diff] [blame] | 1455 | } |
Anssi Mannila | f1d0eb6 | 2019-12-17 15:29:55 +0200 | [diff] [blame] | 1456 | } |
Anssi Mannila | c92b421 | 2020-12-07 14:59:34 +0200 | [diff] [blame] | 1457 | |
| 1458 | //------------------------------------------------------------------- |
| 1459 | // |
| 1460 | //------------------------------------------------------------------- |
Anssi Mannila | f682ace | 2021-09-28 13:11:25 +0300 | [diff] [blame] | 1461 | func (c *Control) WriteSubscriptionToDb(subs *Subscription) error { |
Anssi Mannila | c92b421 | 2020-12-07 14:59:34 +0200 | [diff] [blame] | 1462 | xapp.Logger.Debug("WriteSubscriptionToDb() subId = %v", subs.ReqId.InstanceId) |
| 1463 | err := c.WriteSubscriptionToSdl(subs.ReqId.InstanceId, subs) |
| 1464 | if err != nil { |
| 1465 | xapp.Logger.Error("%v", err) |
Anssi Mannila | f682ace | 2021-09-28 13:11:25 +0300 | [diff] [blame] | 1466 | return err |
Anssi Mannila | c92b421 | 2020-12-07 14:59:34 +0200 | [diff] [blame] | 1467 | } |
Anssi Mannila | f682ace | 2021-09-28 13:11:25 +0300 | [diff] [blame] | 1468 | return nil |
Anssi Mannila | c92b421 | 2020-12-07 14:59:34 +0200 | [diff] [blame] | 1469 | } |
| 1470 | |
| 1471 | //------------------------------------------------------------------- |
| 1472 | // |
| 1473 | //------------------------------------------------------------------- |
Anssi Mannila | f682ace | 2021-09-28 13:11:25 +0300 | [diff] [blame] | 1474 | func (c *Control) UpdateSubscriptionInDB(subs *Subscription, removeSubscriptionFromDb bool) error { |
Anssi Mannila | c92b421 | 2020-12-07 14:59:34 +0200 | [diff] [blame] | 1475 | |
| 1476 | if removeSubscriptionFromDb == true { |
| 1477 | // Subscription was written in db already when subscription request was sent to BTS, except for merged request |
| 1478 | c.RemoveSubscriptionFromDb(subs) |
| 1479 | } else { |
| 1480 | // Update is needed for successful response and merge case here |
| 1481 | if subs.RetryFromXapp == false { |
Anssi Mannila | f682ace | 2021-09-28 13:11:25 +0300 | [diff] [blame] | 1482 | err := c.WriteSubscriptionToDb(subs) |
| 1483 | return err |
Anssi Mannila | c92b421 | 2020-12-07 14:59:34 +0200 | [diff] [blame] | 1484 | } |
| 1485 | } |
| 1486 | subs.RetryFromXapp = false |
Anssi Mannila | f682ace | 2021-09-28 13:11:25 +0300 | [diff] [blame] | 1487 | return nil |
Anssi Mannila | c92b421 | 2020-12-07 14:59:34 +0200 | [diff] [blame] | 1488 | } |
| 1489 | |
| 1490 | //------------------------------------------------------------------- |
| 1491 | // |
| 1492 | //------------------------------------------------------------------- |
| 1493 | func (c *Control) RemoveSubscriptionFromDb(subs *Subscription) { |
| 1494 | xapp.Logger.Debug("RemoveSubscriptionFromDb() subId = %v", subs.ReqId.InstanceId) |
| 1495 | err := c.RemoveSubscriptionFromSdl(subs.ReqId.InstanceId) |
| 1496 | if err != nil { |
| 1497 | xapp.Logger.Error("%v", err) |
| 1498 | } |
| 1499 | } |
| 1500 | |
Konstantinos Archangelof | 268d715 | 2021-06-14 12:24:00 +0300 | [diff] [blame] | 1501 | //------------------------------------------------------------------- |
| 1502 | // |
| 1503 | //------------------------------------------------------------------- |
| 1504 | func (c *Control) WriteRESTSubscriptionToDb(restSubId string, restSubs *RESTSubscription) { |
| 1505 | xapp.Logger.Debug("WriteRESTSubscriptionToDb() restSubId = %s", restSubId) |
| 1506 | err := c.WriteRESTSubscriptionToSdl(restSubId, restSubs) |
| 1507 | if err != nil { |
| 1508 | xapp.Logger.Error("%v", err) |
| 1509 | } |
| 1510 | } |
| 1511 | |
| 1512 | //------------------------------------------------------------------- |
| 1513 | // |
| 1514 | //------------------------------------------------------------------- |
| 1515 | func (c *Control) UpdateRESTSubscriptionInDB(restSubId string, restSubs *RESTSubscription, removeRestSubscriptionFromDb bool) { |
| 1516 | |
| 1517 | if removeRestSubscriptionFromDb == true { |
| 1518 | // Subscription was written in db already when subscription request was sent to BTS, except for merged request |
| 1519 | c.RemoveRESTSubscriptionFromDb(restSubId) |
| 1520 | } else { |
| 1521 | c.WriteRESTSubscriptionToDb(restSubId, restSubs) |
| 1522 | } |
| 1523 | } |
| 1524 | |
| 1525 | //------------------------------------------------------------------- |
| 1526 | // |
| 1527 | //------------------------------------------------------------------- |
| 1528 | func (c *Control) RemoveRESTSubscriptionFromDb(restSubId string) { |
| 1529 | xapp.Logger.Debug("RemoveRESTSubscriptionFromDb() restSubId = %s", restSubId) |
| 1530 | err := c.RemoveRESTSubscriptionFromSdl(restSubId) |
| 1531 | if err != nil { |
| 1532 | xapp.Logger.Error("%v", err) |
| 1533 | } |
| 1534 | } |
| 1535 | |
gunjarastogi | 4378baf | 2023-01-18 17:51:55 +0530 | [diff] [blame] | 1536 | func (c *Control) SendSubscriptionDeleteReq(subs *Subscription, e2SubsDelRequired bool) { |
Anssi Mannila | c92b421 | 2020-12-07 14:59:34 +0200 | [diff] [blame] | 1537 | |
Anssi Mannila | 54838ed | 2021-11-19 11:25:01 +0200 | [diff] [blame] | 1538 | if c.UTTesting == true { |
| 1539 | // Reqistry mutex is not locked after real restart but it can be when restart is simulated in unit tests |
| 1540 | c.registry.mutex = new(sync.Mutex) |
| 1541 | } |
| 1542 | |
Konstantinos Archangelof | 26dfa71 | 2021-06-04 12:10:26 +0000 | [diff] [blame] | 1543 | const ricRequestorId = 123 |
Anssi Mannila | c92b421 | 2020-12-07 14:59:34 +0200 | [diff] [blame] | 1544 | xapp.Logger.Debug("Sending subscription delete due to restart. subId = %v", subs.ReqId.InstanceId) |
| 1545 | |
| 1546 | // Send delete for every endpoint in the subscription |
Anssi Mannila | f682ace | 2021-09-28 13:11:25 +0300 | [diff] [blame] | 1547 | if subs.PolicyUpdate == false { |
| 1548 | subDelReqMsg := &e2ap.E2APSubscriptionDeleteRequest{} |
| 1549 | subDelReqMsg.RequestId = subs.GetReqId().RequestId |
| 1550 | subDelReqMsg.RequestId.Id = ricRequestorId |
| 1551 | subDelReqMsg.FunctionId = subs.SubReqMsg.FunctionId |
| 1552 | mType, payload, err := c.e2ap.PackSubscriptionDeleteRequest(subDelReqMsg) |
| 1553 | if err != nil { |
| 1554 | xapp.Logger.Error("SendSubscriptionDeleteReq() %s", idstring(err)) |
| 1555 | return |
| 1556 | } |
| 1557 | for _, endPoint := range subs.EpList.Endpoints { |
| 1558 | params := &xapp.RMRParams{} |
| 1559 | params.Mtype = mType |
| 1560 | params.SubId = int(subs.GetReqId().InstanceId) |
| 1561 | params.Xid = "" |
| 1562 | params.Meid = subs.Meid |
| 1563 | params.Src = endPoint.String() |
| 1564 | params.PayloadLen = len(payload.Buf) |
| 1565 | params.Payload = payload.Buf |
| 1566 | params.Mbuf = nil |
| 1567 | subs.DeleteFromDb = true |
gunjarastogi | 4378baf | 2023-01-18 17:51:55 +0530 | [diff] [blame] | 1568 | if !e2SubsDelRequired { |
| 1569 | c.handleXAPPSubscriptionDeleteRequest(params) |
| 1570 | } else { |
| 1571 | c.SendSubscriptionDeleteReqToE2T(subs, params) |
| 1572 | } |
Anssi Mannila | f682ace | 2021-09-28 13:11:25 +0300 | [diff] [blame] | 1573 | } |
Anssi Mannila | c92b421 | 2020-12-07 14:59:34 +0200 | [diff] [blame] | 1574 | } |
| 1575 | } |
Anssi Mannila | de457a1 | 2021-06-02 16:19:48 +0300 | [diff] [blame] | 1576 | |
| 1577 | func (c *Control) PrintRESTSubscriptionRequest(p *models.SubscriptionParams) { |
| 1578 | |
| 1579 | fmt.Println("CRESTSubscriptionRequest") |
Markku Virtanen | 987f8b1 | 2021-06-10 15:05:02 +0300 | [diff] [blame] | 1580 | |
Markku Virtanen | 2b512b6 | 2021-07-30 12:04:00 +0000 | [diff] [blame] | 1581 | if p == nil { |
| 1582 | return |
| 1583 | } |
| 1584 | |
Markku Virtanen | 987f8b1 | 2021-06-10 15:05:02 +0300 | [diff] [blame] | 1585 | if p.SubscriptionID != "" { |
| 1586 | fmt.Println(" SubscriptionID = ", p.SubscriptionID) |
| 1587 | } else { |
| 1588 | fmt.Println(" SubscriptionID = ''") |
| 1589 | } |
| 1590 | |
Anssi Mannila | de457a1 | 2021-06-02 16:19:48 +0300 | [diff] [blame] | 1591 | fmt.Printf(" ClientEndpoint.Host = %s\n", p.ClientEndpoint.Host) |
| 1592 | |
| 1593 | if p.ClientEndpoint.HTTPPort != nil { |
| 1594 | fmt.Printf(" ClientEndpoint.HTTPPort = %v\n", *p.ClientEndpoint.HTTPPort) |
| 1595 | } else { |
| 1596 | fmt.Println(" ClientEndpoint.HTTPPort = nil") |
| 1597 | } |
| 1598 | |
| 1599 | if p.ClientEndpoint.RMRPort != nil { |
| 1600 | fmt.Printf(" ClientEndpoint.RMRPort = %v\n", *p.ClientEndpoint.RMRPort) |
| 1601 | } else { |
| 1602 | fmt.Println(" ClientEndpoint.RMRPort = nil") |
| 1603 | } |
| 1604 | |
| 1605 | if p.Meid != nil { |
| 1606 | fmt.Printf(" Meid = %s\n", *p.Meid) |
| 1607 | } else { |
| 1608 | fmt.Println(" Meid = nil") |
| 1609 | } |
| 1610 | |
Anssi Mannila | f682ace | 2021-09-28 13:11:25 +0300 | [diff] [blame] | 1611 | if p.E2SubscriptionDirectives == nil { |
| 1612 | fmt.Println(" E2SubscriptionDirectives = nil") |
| 1613 | } else { |
| 1614 | fmt.Println(" E2SubscriptionDirectives") |
| 1615 | if p.E2SubscriptionDirectives.E2RetryCount == nil { |
| 1616 | fmt.Println(" E2RetryCount == nil") |
| 1617 | } else { |
| 1618 | fmt.Printf(" E2RetryCount = %v\n", *p.E2SubscriptionDirectives.E2RetryCount) |
| 1619 | } |
| 1620 | fmt.Printf(" E2TimeoutTimerValue = %v\n", p.E2SubscriptionDirectives.E2TimeoutTimerValue) |
Anssi Mannila | cb7dd49 | 2021-10-01 11:10:26 +0300 | [diff] [blame] | 1621 | fmt.Printf(" RMRRoutingNeeded = %v\n", p.E2SubscriptionDirectives.RMRRoutingNeeded) |
Anssi Mannila | f682ace | 2021-09-28 13:11:25 +0300 | [diff] [blame] | 1622 | } |
Anssi Mannila | de457a1 | 2021-06-02 16:19:48 +0300 | [diff] [blame] | 1623 | for _, subscriptionDetail := range p.SubscriptionDetails { |
| 1624 | if p.RANFunctionID != nil { |
| 1625 | fmt.Printf(" RANFunctionID = %v\n", *p.RANFunctionID) |
| 1626 | } else { |
| 1627 | fmt.Println(" RANFunctionID = nil") |
| 1628 | } |
Konstantinos Archangelof | e93b00f | 2021-06-03 10:00:19 +0000 | [diff] [blame] | 1629 | fmt.Printf(" SubscriptionDetail.XappEventInstanceID = %v\n", *subscriptionDetail.XappEventInstanceID) |
Konstantinos Archangelof | bd9c98e | 2021-06-07 17:32:10 +0000 | [diff] [blame] | 1630 | fmt.Printf(" SubscriptionDetail.EventTriggers = %v\n", subscriptionDetail.EventTriggers) |
Anssi Mannila | de457a1 | 2021-06-02 16:19:48 +0300 | [diff] [blame] | 1631 | |
| 1632 | for _, actionToBeSetup := range subscriptionDetail.ActionToBeSetupList { |
| 1633 | fmt.Printf(" SubscriptionDetail.ActionToBeSetup.ActionID = %v\n", *actionToBeSetup.ActionID) |
| 1634 | fmt.Printf(" SubscriptionDetail.ActionToBeSetup.ActionType = %s\n", *actionToBeSetup.ActionType) |
Konstantinos Archangelof | bd9c98e | 2021-06-07 17:32:10 +0000 | [diff] [blame] | 1635 | fmt.Printf(" SubscriptionDetail.ActionToBeSetup.ActionDefinition = %v\n", actionToBeSetup.ActionDefinition) |
Anssi Mannila | de457a1 | 2021-06-02 16:19:48 +0300 | [diff] [blame] | 1636 | |
Anssi Mannila | de457a1 | 2021-06-02 16:19:48 +0300 | [diff] [blame] | 1637 | if actionToBeSetup.SubsequentAction != nil { |
| 1638 | fmt.Printf(" SubscriptionDetail.ActionToBeSetup.SubsequentAction.SubsequentActionType = %s\n", *actionToBeSetup.SubsequentAction.SubsequentActionType) |
| 1639 | fmt.Printf(" SubscriptionDetail.ActionToBeSetup..SubsequentAction.TimeToWait = %s\n", *actionToBeSetup.SubsequentAction.TimeToWait) |
| 1640 | } else { |
| 1641 | fmt.Println(" SubscriptionDetail.ActionToBeSetup.SubsequentAction = nil") |
| 1642 | } |
| 1643 | } |
| 1644 | } |
| 1645 | } |
gunjarastogi | 4378baf | 2023-01-18 17:51:55 +0530 | [diff] [blame] | 1646 | |
| 1647 | //------------------------------------------------------------------- |
| 1648 | // handle from E2T Subscription Delete Required |
| 1649 | //------------------------------------------------------------------- |
| 1650 | func (c *Control) handleE2TSubscriptionDeleteRequired(params *xapp.RMRParams) { |
| 1651 | xapp.Logger.Info("MSG from E2T: %s", params.String()) |
| 1652 | c.UpdateCounter(cSubDelRequFromE2) |
| 1653 | subsDelRequMsg, err := c.e2ap.UnpackSubscriptionDeleteRequired(params.Payload) |
| 1654 | if err != nil { |
| 1655 | xapp.Logger.Error("MSG-SubDelRequired: %s", idstring(err, params)) |
| 1656 | //c.sendE2TErrorIndication(nil) |
| 1657 | return |
| 1658 | } |
| 1659 | var subscriptions = map[string][]e2ap.E2APSubscriptionDeleteRequired{} |
| 1660 | var subDB = []*Subscription{} |
| 1661 | for _, subsTobeRemove := range subsDelRequMsg.E2APSubscriptionDeleteRequiredRequests { |
| 1662 | subs, err := c.registry.GetSubscriptionFirstMatch([]uint32{subsTobeRemove.RequestId.InstanceId}) |
| 1663 | if err != nil { |
| 1664 | xapp.Logger.Error("MSG-SubDelFail: %s", idstring(err, params)) |
| 1665 | continue |
| 1666 | } |
| 1667 | // Check if Delete Subscription Already triggered |
| 1668 | if subs.OngoingDelCount > 0 { |
| 1669 | continue |
| 1670 | } |
| 1671 | subDB = append(subDB, subs) |
| 1672 | for _, endpoint := range subs.EpList.Endpoints { |
| 1673 | subscriptions[endpoint.Addr] = append(subscriptions[endpoint.Addr], subsTobeRemove) |
| 1674 | } |
| 1675 | // Sending Subscription Delete Request to E2T |
| 1676 | // c.SendSubscriptionDeleteReq(subs, true) |
| 1677 | } |
| 1678 | for _, subsTobeRemove := range subDB { |
| 1679 | // Sending Subscription Delete Request to E2T |
| 1680 | c.SendSubscriptionDeleteReq(subsTobeRemove, true) |
| 1681 | } |
| 1682 | } |
| 1683 | |
| 1684 | //----------------------------------------------------------------- |
| 1685 | // Initiate RIC Subscription Delete Request after receiving |
| 1686 | // RIC Subscription Delete Required from E2T |
| 1687 | //----------------------------------------------------------------- |
| 1688 | func (c *Control) SendSubscriptionDeleteReqToE2T(subs *Subscription, params *xapp.RMRParams) { |
| 1689 | xapp.Logger.Debug("MSG TO E2T: %s", params.String()) |
| 1690 | c.UpdateCounter(cSubDelReqToE2) |
| 1691 | |
| 1692 | if c.e2IfState.IsE2ConnectionUp(¶ms.Meid.RanName) == false { |
| 1693 | xapp.Logger.Error("No E2 connection for ranName %v", params.Meid.RanName) |
| 1694 | return |
| 1695 | } |
| 1696 | |
| 1697 | trans := c.tracker.NewXappTransaction(xapp.NewRmrEndpoint(params.Src), params.Xid, subs.ReqId.RequestId, params.Meid) |
| 1698 | if trans == nil { |
| 1699 | xapp.Logger.Error("XAPP-SubDelReq: %s", idstring(fmt.Errorf("transaction not created"), params)) |
| 1700 | return |
| 1701 | } |
| 1702 | defer trans.Release() |
| 1703 | |
| 1704 | err := c.tracker.Track(trans) |
| 1705 | if err != nil { |
| 1706 | xapp.Logger.Error("XAPP-SubReq: %s", idstring(err, trans)) |
| 1707 | return |
| 1708 | } |
| 1709 | |
| 1710 | // |
| 1711 | // Wake subs delete |
| 1712 | // |
| 1713 | subs.OngoingDelCount++ |
| 1714 | go c.handleSubscriptionDelete(subs, trans, waitRouteCleanup_ms) |
| 1715 | trans.WaitEvent(0) //blocked wait as timeout is handled in subs side |
| 1716 | subs.OngoingDelCount-- |
| 1717 | |
| 1718 | xapp.Logger.Debug("XAPP-SubDelReq: Handling event %s ", idstring(nil, trans, subs)) |
| 1719 | |
| 1720 | if subs.NoRespToXapp == true { |
| 1721 | // Do no send delete responses to xapps due to submgr restart is deleting uncompleted subscriptions |
| 1722 | xapp.Logger.Debug("XAPP-SubDelReq: subs.NoRespToXapp == true") |
| 1723 | return |
| 1724 | } |
| 1725 | } |