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