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" |
| 25 | "os" |
| 26 | "strconv" |
| 27 | "strings" |
| 28 | "time" |
| 29 | |
Juha Hyttinen | 86a4620 | 2020-01-14 12:49:09 +0200 | [diff] [blame] | 30 | "gerrit.o-ran-sc.org/r/ric-plt/e2ap/pkg/e2ap" |
kalnagy | 93cc3e2 | 2019-09-19 11:29:29 +0200 | [diff] [blame] | 31 | 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] | 32 | "gerrit.o-ran-sc.org/r/ric-plt/xapp-frame/pkg/models" |
kalnagy | 1455c85 | 2019-10-21 13:06:23 +0200 | [diff] [blame] | 33 | "gerrit.o-ran-sc.org/r/ric-plt/xapp-frame/pkg/xapp" |
| 34 | httptransport "github.com/go-openapi/runtime/client" |
| 35 | "github.com/go-openapi/strfmt" |
Anssi Mannila | c92b421 | 2020-12-07 14:59:34 +0200 | [diff] [blame] | 36 | "github.com/gorilla/mux" |
archagge | afbf95f | 2021-04-14 08:54:05 +0300 | [diff] [blame] | 37 | "github.com/segmentio/ksuid" |
kalnagy | 1455c85 | 2019-10-21 13:06:23 +0200 | [diff] [blame] | 38 | "github.com/spf13/viper" |
kalnagy | 4511475 | 2019-06-18 14:40:39 +0200 | [diff] [blame] | 39 | ) |
| 40 | |
Juha Hyttinen | e406a34 | 2020-01-13 13:02:26 +0200 | [diff] [blame] | 41 | //----------------------------------------------------------------------------- |
| 42 | // |
| 43 | //----------------------------------------------------------------------------- |
| 44 | |
Juha Hyttinen | 5f8ffa0 | 2020-02-06 15:28:59 +0200 | [diff] [blame] | 45 | func idstring(err error, entries ...fmt.Stringer) string { |
| 46 | var retval string = "" |
| 47 | var filler string = "" |
| 48 | for _, entry := range entries { |
Markku Virtanen | 42723e2 | 2021-06-15 10:09:23 +0300 | [diff] [blame] | 49 | if entry != nil { |
| 50 | retval += filler + entry.String() |
| 51 | filler = " " |
| 52 | } else { |
| 53 | retval += filler + "(NIL)" |
| 54 | } |
Juha Hyttinen | 5f8ffa0 | 2020-02-06 15:28:59 +0200 | [diff] [blame] | 55 | } |
| 56 | if err != nil { |
| 57 | retval += filler + "err(" + err.Error() + ")" |
| 58 | filler = " " |
Juha Hyttinen | 5f8ffa0 | 2020-02-06 15:28:59 +0200 | [diff] [blame] | 59 | } |
| 60 | return retval |
| 61 | } |
| 62 | |
| 63 | //----------------------------------------------------------------------------- |
| 64 | // |
| 65 | //----------------------------------------------------------------------------- |
| 66 | |
Anssi Mannila | 2f26fb2 | 2020-12-07 08:32:13 +0200 | [diff] [blame] | 67 | var e2tSubReqTimeout time.Duration |
| 68 | var e2tSubDelReqTime time.Duration |
| 69 | var e2tRecvMsgTimeout time.Duration |
Markku Virtanen | fe2cdab | 2021-05-21 10:59:29 +0000 | [diff] [blame] | 70 | var waitRouteCleanup_ms time.Duration |
Anssi Mannila | 2f26fb2 | 2020-12-07 08:32:13 +0200 | [diff] [blame] | 71 | var e2tMaxSubReqTryCount uint64 // Initial try + retry |
| 72 | var e2tMaxSubDelReqTryCount uint64 // Initial try + retry |
Anssi Mannila | c92b421 | 2020-12-07 14:59:34 +0200 | [diff] [blame] | 73 | var readSubsFromDb string |
Markku Virtanen | b642a19 | 2021-06-09 09:08:14 +0000 | [diff] [blame] | 74 | var restDuplicateCtrl duplicateCtrl |
Anssi Mannila | b73e7cd | 2021-08-03 11:57:11 +0300 | [diff] [blame^] | 75 | var dbRetryForever string |
| 76 | var dbTryCount int |
Anssi Mannila | 2e99e2f | 2019-12-05 13:57:06 +0200 | [diff] [blame] | 77 | |
kalnagy | 4511475 | 2019-06-18 14:40:39 +0200 | [diff] [blame] | 78 | type Control struct { |
Juha Hyttinen | 9dc5adc | 2020-08-13 10:02:40 +0300 | [diff] [blame] | 79 | *xapp.RMRClient |
Anssi Mannila | de457a1 | 2021-06-02 16:19:48 +0300 | [diff] [blame] | 80 | e2ap *E2ap |
| 81 | registry *Registry |
| 82 | tracker *Tracker |
Konstantinos Archangelof | 268d715 | 2021-06-14 12:24:00 +0300 | [diff] [blame] | 83 | e2SubsDb Sdlnterface |
| 84 | restSubsDb Sdlnterface |
Anssi Mannila | c92b421 | 2020-12-07 14:59:34 +0200 | [diff] [blame] | 85 | CntRecvMsg uint64 |
| 86 | ResetTestFlag bool |
Anssi Mannila | 4abf180 | 2021-01-28 13:06:46 +0200 | [diff] [blame] | 87 | Counters map[string]xapp.Counter |
Anssi Mannila | de457a1 | 2021-06-02 16:19:48 +0300 | [diff] [blame] | 88 | LoggerLevel uint32 |
kalnagy | 93cc3e2 | 2019-09-19 11:29:29 +0200 | [diff] [blame] | 89 | } |
| 90 | |
| 91 | type RMRMeid struct { |
Juha Hyttinen | ff8dccd | 2019-12-10 14:34:07 +0200 | [diff] [blame] | 92 | PlmnID string |
| 93 | EnbID string |
Anssi Mannila | 2e99e2f | 2019-12-05 13:57:06 +0200 | [diff] [blame] | 94 | RanName string |
kalnagy | 93cc3e2 | 2019-09-19 11:29:29 +0200 | [diff] [blame] | 95 | } |
| 96 | |
Anssi Mannila | c92b421 | 2020-12-07 14:59:34 +0200 | [diff] [blame] | 97 | type SubmgrRestartTestEvent struct{} |
| 98 | type SubmgrRestartUpEvent struct{} |
| 99 | |
Peter Szilagyi | fbc56f9 | 2019-07-23 19:29:46 +0000 | [diff] [blame] | 100 | func init() { |
Anssi Mannila | 8046c70 | 2020-01-02 13:39:05 +0200 | [diff] [blame] | 101 | xapp.Logger.Info("SUBMGR") |
Peter Szilagyi | fbc56f9 | 2019-07-23 19:29:46 +0000 | [diff] [blame] | 102 | viper.AutomaticEnv() |
| 103 | viper.SetEnvPrefix("submgr") |
| 104 | viper.AllowEmptyEnv(true) |
kalnagy | 4511475 | 2019-06-18 14:40:39 +0200 | [diff] [blame] | 105 | } |
| 106 | |
Juha Hyttinen | ff8dccd | 2019-12-10 14:34:07 +0200 | [diff] [blame] | 107 | func NewControl() *Control { |
Juha Hyttinen | 0388dd9 | 2020-01-09 14:14:16 +0200 | [diff] [blame] | 108 | |
Anssi Mannila | c92b421 | 2020-12-07 14:59:34 +0200 | [diff] [blame] | 109 | transport := httptransport.New(viper.GetString("rtmgr.HostAddr")+":"+viper.GetString("rtmgr.port"), viper.GetString("rtmgr.baseUrl"), []string{"http"}) |
| 110 | rtmgrClient := RtmgrClient{rtClient: rtmgrclient.New(transport, strfmt.Default)} |
| 111 | |
| 112 | registry := new(Registry) |
| 113 | registry.Initialize() |
| 114 | registry.rtmgrClient = &rtmgrClient |
| 115 | |
| 116 | tracker := new(Tracker) |
| 117 | tracker.Init() |
| 118 | |
Anssi Mannila | c92b421 | 2020-12-07 14:59:34 +0200 | [diff] [blame] | 119 | c := &Control{e2ap: new(E2ap), |
Anssi Mannila | de457a1 | 2021-06-02 16:19:48 +0300 | [diff] [blame] | 120 | registry: registry, |
| 121 | tracker: tracker, |
Konstantinos Archangelof | 268d715 | 2021-06-14 12:24:00 +0300 | [diff] [blame] | 122 | e2SubsDb: CreateSdl(), |
| 123 | restSubsDb: CreateRESTSdl(), |
Anssi Mannila | de457a1 | 2021-06-02 16:19:48 +0300 | [diff] [blame] | 124 | Counters: xapp.Metric.RegisterCounterGroup(GetMetricsOpts(), "SUBMGR"), |
| 125 | LoggerLevel: 3, |
Anssi Mannila | c92b421 | 2020-12-07 14:59:34 +0200 | [diff] [blame] | 126 | } |
Anssi Mannila | f6b7804 | 2021-02-18 12:36:59 +0200 | [diff] [blame] | 127 | c.ReadConfigParameters("") |
Anssi Mannila | c92b421 | 2020-12-07 14:59:34 +0200 | [diff] [blame] | 128 | |
| 129 | // Register REST handler for testing support |
| 130 | xapp.Resource.InjectRoute("/ric/v1/test/{testId}", c.TestRestHandler, "POST") |
Anssi Mannila | b73e7cd | 2021-08-03 11:57:11 +0300 | [diff] [blame^] | 131 | xapp.Resource.InjectRoute("/ric/v1/restsubscriptions", c.GetAllRestSubscriptions, "GET") |
Abukar Mohamed | fbd4df5 | 2021-03-11 06:13:27 +0000 | [diff] [blame] | 132 | xapp.Resource.InjectRoute("/ric/v1/symptomdata", c.SymptomDataHandler, "GET") |
Anssi Mannila | c92b421 | 2020-12-07 14:59:34 +0200 | [diff] [blame] | 133 | |
archagge | afbf95f | 2021-04-14 08:54:05 +0300 | [diff] [blame] | 134 | go xapp.Subscription.Listen(c.SubscriptionHandler, c.QueryHandler, c.SubscriptionDeleteHandlerCB) |
Anssi Mannila | c92b421 | 2020-12-07 14:59:34 +0200 | [diff] [blame] | 135 | |
| 136 | if readSubsFromDb == "false" { |
| 137 | return c |
| 138 | } |
| 139 | |
Markku Virtanen | b642a19 | 2021-06-09 09:08:14 +0000 | [diff] [blame] | 140 | restDuplicateCtrl.Init() |
| 141 | |
Anssi Mannila | c92b421 | 2020-12-07 14:59:34 +0200 | [diff] [blame] | 142 | // Read subscriptions from db |
Anssi Mannila | b73e7cd | 2021-08-03 11:57:11 +0300 | [diff] [blame^] | 143 | c.ReadE2Subscriptions() |
| 144 | c.ReadRESTSubscriptions() |
Konstantinos Archangelof | 268d715 | 2021-06-14 12:24:00 +0300 | [diff] [blame] | 145 | |
Anssi Mannila | b73e7cd | 2021-08-03 11:57:11 +0300 | [diff] [blame^] | 146 | /* |
| 147 | xapp.Logger.Info("Reading subscriptions from db") |
| 148 | subIds, register, err := c.ReadAllSubscriptionsFromSdl() |
| 149 | if err != nil { |
| 150 | xapp.Logger.Error("%v", err) |
| 151 | } else { |
| 152 | c.registry.subIds = subIds |
| 153 | c.registry.register = register |
| 154 | c.HandleUncompletedSubscriptions(register) |
| 155 | } |
| 156 | |
| 157 | restSubscriptions, err := c.ReadAllRESTSubscriptionsFromSdl() |
| 158 | if err != nil { |
| 159 | xapp.Logger.Error("%v", err) |
| 160 | } else { |
| 161 | c.registry.restSubscriptions = restSubscriptions |
| 162 | } |
| 163 | */ |
Anssi Mannila | c92b421 | 2020-12-07 14:59:34 +0200 | [diff] [blame] | 164 | return c |
| 165 | } |
| 166 | |
Abukar Mohamed | fbd4df5 | 2021-03-11 06:13:27 +0000 | [diff] [blame] | 167 | func (c *Control) SymptomDataHandler(w http.ResponseWriter, r *http.Request) { |
| 168 | subscriptions, _ := c.registry.QueryHandler() |
| 169 | xapp.Resource.SendSymptomDataJson(w, r, subscriptions, "platform/subscriptions.json") |
| 170 | } |
| 171 | |
Anssi Mannila | c92b421 | 2020-12-07 14:59:34 +0200 | [diff] [blame] | 172 | //------------------------------------------------------------------- |
| 173 | // |
| 174 | //------------------------------------------------------------------- |
Anssi Mannila | b73e7cd | 2021-08-03 11:57:11 +0300 | [diff] [blame^] | 175 | func (c *Control) GetAllRestSubscriptions(w http.ResponseWriter, r *http.Request) { |
| 176 | xapp.Logger.Info("GetAllRestSubscriptions() called") |
| 177 | response := c.registry.GetAllRestSubscriptions() |
| 178 | w.Write(response) |
| 179 | } |
| 180 | |
| 181 | //------------------------------------------------------------------- |
| 182 | // |
| 183 | //------------------------------------------------------------------- |
| 184 | func (c *Control) ReadE2Subscriptions() error { |
| 185 | var err error |
| 186 | var subIds []uint32 |
| 187 | var register map[uint32]*Subscription |
| 188 | for i := 0; dbRetryForever == "true" || i < dbTryCount; i++ { |
| 189 | xapp.Logger.Info("Reading E2 subscriptions from db") |
| 190 | subIds, register, err = c.ReadAllSubscriptionsFromSdl() |
| 191 | if err != nil { |
| 192 | xapp.Logger.Error("%v", err) |
| 193 | <-time.After(1 * time.Second) |
| 194 | } else { |
| 195 | c.registry.subIds = subIds |
| 196 | c.registry.register = register |
| 197 | c.HandleUncompletedSubscriptions(register) |
| 198 | return nil |
| 199 | } |
| 200 | } |
| 201 | xapp.Logger.Info("Continuing without retring") |
| 202 | return err |
| 203 | } |
| 204 | |
| 205 | //------------------------------------------------------------------- |
| 206 | // |
| 207 | //------------------------------------------------------------------- |
| 208 | func (c *Control) ReadRESTSubscriptions() error { |
| 209 | var err error |
| 210 | var restSubscriptions map[string]*RESTSubscription |
| 211 | for i := 0; dbRetryForever == "true" || i < dbTryCount; i++ { |
| 212 | xapp.Logger.Info("Reading REST subscriptions from db") |
| 213 | restSubscriptions, err = c.ReadAllRESTSubscriptionsFromSdl() |
| 214 | if err != nil { |
| 215 | xapp.Logger.Error("%v", err) |
| 216 | <-time.After(1 * time.Second) |
| 217 | } else { |
| 218 | c.registry.restSubscriptions = restSubscriptions |
| 219 | return nil |
| 220 | } |
| 221 | } |
| 222 | xapp.Logger.Info("Continuing without retring") |
| 223 | return err |
| 224 | } |
| 225 | |
| 226 | //------------------------------------------------------------------- |
| 227 | // |
| 228 | //------------------------------------------------------------------- |
Anssi Mannila | f6b7804 | 2021-02-18 12:36:59 +0200 | [diff] [blame] | 229 | func (c *Control) ReadConfigParameters(f string) { |
Anssi Mannila | c92b421 | 2020-12-07 14:59:34 +0200 | [diff] [blame] | 230 | |
Anssi Mannila | 2f26fb2 | 2020-12-07 08:32:13 +0200 | [diff] [blame] | 231 | // viper.GetDuration returns nanoseconds |
| 232 | e2tSubReqTimeout = viper.GetDuration("controls.e2tSubReqTimeout_ms") * 1000000 |
Juha Hyttinen | 57140bc | 2020-12-11 13:03:06 +0200 | [diff] [blame] | 233 | if e2tSubReqTimeout == 0 { |
| 234 | e2tSubReqTimeout = 2000 * 1000000 |
| 235 | } |
Anssi Mannila | 2f26fb2 | 2020-12-07 08:32:13 +0200 | [diff] [blame] | 236 | xapp.Logger.Info("e2tSubReqTimeout %v", e2tSubReqTimeout) |
| 237 | e2tSubDelReqTime = viper.GetDuration("controls.e2tSubDelReqTime_ms") * 1000000 |
Juha Hyttinen | 57140bc | 2020-12-11 13:03:06 +0200 | [diff] [blame] | 238 | if e2tSubDelReqTime == 0 { |
| 239 | e2tSubDelReqTime = 2000 * 1000000 |
| 240 | } |
Anssi Mannila | 2f26fb2 | 2020-12-07 08:32:13 +0200 | [diff] [blame] | 241 | xapp.Logger.Info("e2tSubDelReqTime %v", e2tSubDelReqTime) |
| 242 | e2tRecvMsgTimeout = viper.GetDuration("controls.e2tRecvMsgTimeout_ms") * 1000000 |
Juha Hyttinen | 57140bc | 2020-12-11 13:03:06 +0200 | [diff] [blame] | 243 | if e2tRecvMsgTimeout == 0 { |
| 244 | e2tRecvMsgTimeout = 2000 * 1000000 |
| 245 | } |
Anssi Mannila | 2f26fb2 | 2020-12-07 08:32:13 +0200 | [diff] [blame] | 246 | xapp.Logger.Info("e2tRecvMsgTimeout %v", e2tRecvMsgTimeout) |
Markku Virtanen | fe2cdab | 2021-05-21 10:59:29 +0000 | [diff] [blame] | 247 | |
Anssi Mannila | 2f26fb2 | 2020-12-07 08:32:13 +0200 | [diff] [blame] | 248 | e2tMaxSubReqTryCount = viper.GetUint64("controls.e2tMaxSubReqTryCount") |
Juha Hyttinen | 57140bc | 2020-12-11 13:03:06 +0200 | [diff] [blame] | 249 | if e2tMaxSubReqTryCount == 0 { |
| 250 | e2tMaxSubReqTryCount = 1 |
| 251 | } |
Anssi Mannila | 2f26fb2 | 2020-12-07 08:32:13 +0200 | [diff] [blame] | 252 | xapp.Logger.Info("e2tMaxSubReqTryCount %v", e2tMaxSubReqTryCount) |
Markku Virtanen | fe2cdab | 2021-05-21 10:59:29 +0000 | [diff] [blame] | 253 | |
Anssi Mannila | 2f26fb2 | 2020-12-07 08:32:13 +0200 | [diff] [blame] | 254 | e2tMaxSubDelReqTryCount = viper.GetUint64("controls.e2tMaxSubDelReqTryCount") |
Juha Hyttinen | 57140bc | 2020-12-11 13:03:06 +0200 | [diff] [blame] | 255 | if e2tMaxSubDelReqTryCount == 0 { |
| 256 | e2tMaxSubDelReqTryCount = 1 |
| 257 | } |
Anssi Mannila | 2f26fb2 | 2020-12-07 08:32:13 +0200 | [diff] [blame] | 258 | xapp.Logger.Info("e2tMaxSubDelReqTryCount %v", e2tMaxSubDelReqTryCount) |
| 259 | |
Anssi Mannila | c92b421 | 2020-12-07 14:59:34 +0200 | [diff] [blame] | 260 | readSubsFromDb = viper.GetString("controls.readSubsFromDb") |
| 261 | if readSubsFromDb == "" { |
| 262 | readSubsFromDb = "true" |
Juha Hyttinen | 5f8ffa0 | 2020-02-06 15:28:59 +0200 | [diff] [blame] | 263 | } |
Anssi Mannila | c92b421 | 2020-12-07 14:59:34 +0200 | [diff] [blame] | 264 | xapp.Logger.Info("readSubsFromDb %v", readSubsFromDb) |
Anssi Mannila | b73e7cd | 2021-08-03 11:57:11 +0300 | [diff] [blame^] | 265 | |
| 266 | dbTryCount = viper.GetInt("controls.dbTryCount") |
| 267 | if dbTryCount == 0 { |
| 268 | dbTryCount = 200 |
| 269 | } |
| 270 | xapp.Logger.Info("dbTryCount %v", dbTryCount) |
| 271 | |
| 272 | dbRetryForever = viper.GetString("controls.dbRetryForever") |
| 273 | if dbRetryForever == "" { |
| 274 | dbRetryForever = "true" |
| 275 | } |
| 276 | xapp.Logger.Info("dbRetryForever %v", dbRetryForever) |
| 277 | |
Anssi Mannila | de457a1 | 2021-06-02 16:19:48 +0300 | [diff] [blame] | 278 | c.LoggerLevel = viper.GetUint32("logger.level") |
| 279 | if c.LoggerLevel == 0 { |
| 280 | c.LoggerLevel = 3 |
| 281 | } |
Anssi Mannila | b73e7cd | 2021-08-03 11:57:11 +0300 | [diff] [blame^] | 282 | xapp.Logger.Info("LoggerLevel %v", c.LoggerLevel) |
| 283 | |
| 284 | // Internal cfg parameter, used to define a wait time for RMR route clean-up. None default |
| 285 | // value 100ms used currently only in unittests. |
| 286 | waitRouteCleanup_ms = viper.GetDuration("controls.waitRouteCleanup_ms") * 1000000 |
| 287 | if waitRouteCleanup_ms == 0 { |
| 288 | waitRouteCleanup_ms = 5000 * 1000000 |
| 289 | } |
| 290 | xapp.Logger.Info("waitRouteCleanup %v", waitRouteCleanup_ms) |
Anssi Mannila | c92b421 | 2020-12-07 14:59:34 +0200 | [diff] [blame] | 291 | } |
| 292 | |
| 293 | //------------------------------------------------------------------- |
| 294 | // |
| 295 | //------------------------------------------------------------------- |
| 296 | func (c *Control) HandleUncompletedSubscriptions(register map[uint32]*Subscription) { |
| 297 | |
| 298 | xapp.Logger.Debug("HandleUncompletedSubscriptions. len(register) = %v", len(register)) |
| 299 | for subId, subs := range register { |
| 300 | if subs.SubRespRcvd == false { |
| 301 | subs.NoRespToXapp = true |
| 302 | xapp.Logger.Debug("SendSubscriptionDeleteReq. subId = %v", subId) |
| 303 | c.SendSubscriptionDeleteReq(subs) |
| 304 | } |
| 305 | } |
Juha Hyttinen | 5f8ffa0 | 2020-02-06 15:28:59 +0200 | [diff] [blame] | 306 | } |
| 307 | |
| 308 | func (c *Control) ReadyCB(data interface{}) { |
Juha Hyttinen | 9dc5adc | 2020-08-13 10:02:40 +0300 | [diff] [blame] | 309 | if c.RMRClient == nil { |
| 310 | c.RMRClient = xapp.Rmr |
Juha Hyttinen | ff8dccd | 2019-12-10 14:34:07 +0200 | [diff] [blame] | 311 | } |
kalnagy | 4511475 | 2019-06-18 14:40:39 +0200 | [diff] [blame] | 312 | } |
| 313 | |
| 314 | func (c *Control) Run() { |
Juha Hyttinen | 5f8ffa0 | 2020-02-06 15:28:59 +0200 | [diff] [blame] | 315 | xapp.SetReadyCB(c.ReadyCB, nil) |
Anssi Mannila | f6b7804 | 2021-02-18 12:36:59 +0200 | [diff] [blame] | 316 | xapp.AddConfigChangeListener(c.ReadConfigParameters) |
Peter Szilagyi | fbc56f9 | 2019-07-23 19:29:46 +0000 | [diff] [blame] | 317 | xapp.Run(c) |
kalnagy | 4511475 | 2019-06-18 14:40:39 +0200 | [diff] [blame] | 318 | } |
| 319 | |
Juha Hyttinen | c9eb08a | 2020-02-28 08:53:33 +0200 | [diff] [blame] | 320 | //------------------------------------------------------------------- |
| 321 | // |
| 322 | //------------------------------------------------------------------- |
Markku Virtanen | 42723e2 | 2021-06-15 10:09:23 +0300 | [diff] [blame] | 323 | func (c *Control) GetOrCreateRestSubscription(p *models.SubscriptionParams, md5sum string, xAppRmrEndpoint string) (*RESTSubscription, string, error) { |
| 324 | |
| 325 | var restSubId string |
| 326 | var restSubscription *RESTSubscription |
| 327 | var err error |
| 328 | |
| 329 | prevRestSubsId, exists := restDuplicateCtrl.GetLastKnownRestSubsIdBasedOnMd5sum(md5sum) |
| 330 | if p.SubscriptionID == "" { |
| 331 | if exists { |
| 332 | restSubscription, err = c.registry.GetRESTSubscription(prevRestSubsId, false) |
| 333 | if restSubscription != nil { |
| 334 | restSubId = prevRestSubsId |
| 335 | if err == nil { |
| 336 | xapp.Logger.Info("Existing restSubId %s found by MD5sum %s for a request without subscription ID - using previous subscription", prevRestSubsId, md5sum) |
| 337 | } else { |
| 338 | xapp.Logger.Info("Existing restSubId %s found by MD5sum %s for a request without subscription ID - Note: %s", prevRestSubsId, md5sum, err.Error()) |
| 339 | } |
| 340 | } else { |
| 341 | xapp.Logger.Info("None existing restSubId %s referred by MD5sum %s for a request without subscription ID - deleting cached entry", prevRestSubsId, md5sum) |
| 342 | restDuplicateCtrl.DeleteLastKnownRestSubsIdBasedOnMd5sum(md5sum) |
| 343 | } |
| 344 | } |
| 345 | |
| 346 | if restSubscription == nil { |
| 347 | restSubId = ksuid.New().String() |
| 348 | restSubscription, err = c.registry.CreateRESTSubscription(&restSubId, &xAppRmrEndpoint, p.Meid) |
| 349 | if err != nil { |
| 350 | xapp.Logger.Error("%s", err.Error()) |
| 351 | c.UpdateCounter(cRestSubFailToXapp) |
| 352 | return nil, "", err |
| 353 | } |
| 354 | } |
| 355 | } else { |
| 356 | restSubId = p.SubscriptionID |
| 357 | |
| 358 | xapp.Logger.Info("RestSubscription ID %s provided via REST request", restSubId) |
| 359 | |
| 360 | restSubscription, err = c.registry.GetRESTSubscription(restSubId, false) |
| 361 | if err != nil { |
| 362 | xapp.Logger.Error("%s", err.Error()) |
| 363 | c.UpdateCounter(cRestSubFailToXapp) |
| 364 | return nil, "", err |
| 365 | } |
| 366 | |
| 367 | if !exists { |
| 368 | xapp.Logger.Info("Existing restSubscription found for ID %s, new request based on md5sum", restSubId) |
| 369 | } else { |
| 370 | xapp.Logger.Info("Existing restSubscription found for ID %s(%s), re-transmission based on md5sum match with previous request", prevRestSubsId, restSubId) |
| 371 | } |
| 372 | } |
| 373 | |
| 374 | return restSubscription, restSubId, nil |
| 375 | } |
| 376 | |
| 377 | //------------------------------------------------------------------- |
| 378 | // |
| 379 | //------------------------------------------------------------------- |
archagge | a5c58bc | 2021-04-14 08:54:05 +0300 | [diff] [blame] | 380 | func (c *Control) SubscriptionHandler(params interface{}) (*models.SubscriptionResponse, error) { |
archagge | afbf95f | 2021-04-14 08:54:05 +0300 | [diff] [blame] | 381 | |
Anssi Mannila | 316d8a1 | 2021-06-02 11:08:54 +0300 | [diff] [blame] | 382 | c.CntRecvMsg++ |
| 383 | c.UpdateCounter(cRestSubReqFromXapp) |
| 384 | |
archagge | afbf95f | 2021-04-14 08:54:05 +0300 | [diff] [blame] | 385 | subResp := models.SubscriptionResponse{} |
archagge | afbf95f | 2021-04-14 08:54:05 +0300 | [diff] [blame] | 386 | p := params.(*models.SubscriptionParams) |
| 387 | |
Anssi Mannila | de457a1 | 2021-06-02 16:19:48 +0300 | [diff] [blame] | 388 | if c.LoggerLevel > 2 { |
| 389 | c.PrintRESTSubscriptionRequest(p) |
| 390 | } |
| 391 | |
archagge | afbf95f | 2021-04-14 08:54:05 +0300 | [diff] [blame] | 392 | if p.ClientEndpoint == nil { |
| 393 | xapp.Logger.Error("ClientEndpoint == nil") |
Anssi Mannila | 316d8a1 | 2021-06-02 11:08:54 +0300 | [diff] [blame] | 394 | c.UpdateCounter(cRestSubFailToXapp) |
archagge | afbf95f | 2021-04-14 08:54:05 +0300 | [diff] [blame] | 395 | return nil, fmt.Errorf("") |
| 396 | } |
| 397 | |
| 398 | _, xAppRmrEndpoint, err := ConstructEndpointAddresses(*p.ClientEndpoint) |
| 399 | if err != nil { |
| 400 | xapp.Logger.Error("%s", err.Error()) |
Anssi Mannila | 316d8a1 | 2021-06-02 11:08:54 +0300 | [diff] [blame] | 401 | c.UpdateCounter(cRestSubFailToXapp) |
archagge | afbf95f | 2021-04-14 08:54:05 +0300 | [diff] [blame] | 402 | return nil, err |
| 403 | } |
| 404 | |
Markku Virtanen | 42723e2 | 2021-06-15 10:09:23 +0300 | [diff] [blame] | 405 | md5sum, err := CalculateRequestMd5sum(params) |
| 406 | if err != nil { |
| 407 | xapp.Logger.Error("Failed to generate md5sum from incoming request - %s", err.Error()) |
| 408 | } |
| 409 | |
| 410 | restSubscription, restSubId, err := c.GetOrCreateRestSubscription(p, md5sum, xAppRmrEndpoint) |
| 411 | if err != nil { |
| 412 | xapp.Logger.Error("Failed to get/allocate REST subscription") |
| 413 | return nil, err |
archagge | afbf95f | 2021-04-14 08:54:05 +0300 | [diff] [blame] | 414 | } |
| 415 | |
Konstantinos Archangelof | e93b00f | 2021-06-03 10:00:19 +0000 | [diff] [blame] | 416 | subResp.SubscriptionID = &restSubId |
archagge | afbf95f | 2021-04-14 08:54:05 +0300 | [diff] [blame] | 417 | subReqList := e2ap.SubscriptionRequestList{} |
| 418 | err = c.e2ap.FillSubscriptionReqMsgs(params, &subReqList, restSubscription) |
| 419 | if err != nil { |
| 420 | xapp.Logger.Error("%s", err.Error()) |
Markku Virtanen | 42723e2 | 2021-06-15 10:09:23 +0300 | [diff] [blame] | 421 | restDuplicateCtrl.DeleteLastKnownRestSubsIdBasedOnMd5sum(md5sum) |
archagge | afbf95f | 2021-04-14 08:54:05 +0300 | [diff] [blame] | 422 | c.registry.DeleteRESTSubscription(&restSubId) |
Anssi Mannila | 316d8a1 | 2021-06-02 11:08:54 +0300 | [diff] [blame] | 423 | c.UpdateCounter(cRestSubFailToXapp) |
archagge | afbf95f | 2021-04-14 08:54:05 +0300 | [diff] [blame] | 424 | return nil, err |
| 425 | } |
| 426 | |
Markku Virtanen | 42723e2 | 2021-06-15 10:09:23 +0300 | [diff] [blame] | 427 | duplicate := restDuplicateCtrl.IsDuplicateToOngoingTransaction(restSubId, md5sum) |
| 428 | if duplicate { |
| 429 | xapp.Logger.Info("Retransmission blocker direct ACK for request of restSubsId %s restSubId MD5sum %s as retransmission", restSubId, md5sum) |
| 430 | c.UpdateCounter(cRestSubRespToXapp) |
| 431 | return &subResp, nil |
Markku Virtanen | b642a19 | 2021-06-09 09:08:14 +0000 | [diff] [blame] | 432 | } |
| 433 | |
Markku Virtanen | 42723e2 | 2021-06-15 10:09:23 +0300 | [diff] [blame] | 434 | go c.processSubscriptionRequests(restSubscription, &subReqList, p.ClientEndpoint, p.Meid, &restSubId, xAppRmrEndpoint, md5sum) |
archagge | afbf95f | 2021-04-14 08:54:05 +0300 | [diff] [blame] | 435 | |
Anssi Mannila | 316d8a1 | 2021-06-02 11:08:54 +0300 | [diff] [blame] | 436 | c.UpdateCounter(cRestSubRespToXapp) |
archagge | afbf95f | 2021-04-14 08:54:05 +0300 | [diff] [blame] | 437 | return &subResp, nil |
Juha Hyttinen | 429cfe6 | 2020-03-31 11:23:02 +0300 | [diff] [blame] | 438 | } |
| 439 | |
archagge | afbf95f | 2021-04-14 08:54:05 +0300 | [diff] [blame] | 440 | //------------------------------------------------------------------- |
| 441 | // |
| 442 | //------------------------------------------------------------------- |
| 443 | |
| 444 | func (c *Control) processSubscriptionRequests(restSubscription *RESTSubscription, subReqList *e2ap.SubscriptionRequestList, |
Markku Virtanen | 42723e2 | 2021-06-15 10:09:23 +0300 | [diff] [blame] | 445 | clientEndpoint *models.SubscriptionParamsClientEndpoint, meid *string, restSubId *string, xAppRmrEndpoint string, md5sum string) { |
archagge | afbf95f | 2021-04-14 08:54:05 +0300 | [diff] [blame] | 446 | |
| 447 | xapp.Logger.Info("Subscription Request count=%v ", len(subReqList.E2APSubscriptionRequests)) |
| 448 | |
Konstantinos Archangelof | e93b00f | 2021-06-03 10:00:19 +0000 | [diff] [blame] | 449 | var xAppEventInstanceID int64 |
| 450 | var e2EventInstanceID int64 |
Markku Virtanen | b642a19 | 2021-06-09 09:08:14 +0000 | [diff] [blame] | 451 | |
Markku Virtanen | 42723e2 | 2021-06-15 10:09:23 +0300 | [diff] [blame] | 452 | defer restDuplicateCtrl.SetMd5sumFromLastOkRequest(*restSubId, md5sum) |
Markku Virtanen | b642a19 | 2021-06-09 09:08:14 +0000 | [diff] [blame] | 453 | |
archagge | afbf95f | 2021-04-14 08:54:05 +0300 | [diff] [blame] | 454 | for index := 0; index < len(subReqList.E2APSubscriptionRequests); index++ { |
| 455 | subReqMsg := subReqList.E2APSubscriptionRequests[index] |
Markku Virtanen | b642a19 | 2021-06-09 09:08:14 +0000 | [diff] [blame] | 456 | xAppEventInstanceID = (int64)(subReqMsg.RequestId.Id) |
archagge | afbf95f | 2021-04-14 08:54:05 +0300 | [diff] [blame] | 457 | |
Konstantinos Archangelof | e93b00f | 2021-06-03 10:00:19 +0000 | [diff] [blame] | 458 | 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] | 459 | if trans == nil { |
Markku Virtanen | b642a19 | 2021-06-09 09:08:14 +0000 | [diff] [blame] | 460 | // Send notification to xApp that prosessing of a Subscription Request has failed. |
| 461 | err := fmt.Errorf("Tracking failure") |
| 462 | c.sendUnsuccesfullResponseNotification(restSubId, restSubscription, xAppEventInstanceID, err, clientEndpoint, trans) |
| 463 | continue |
archagge | afbf95f | 2021-04-14 08:54:05 +0300 | [diff] [blame] | 464 | } |
| 465 | |
archagge | afbf95f | 2021-04-14 08:54:05 +0300 | [diff] [blame] | 466 | xapp.Logger.Info("Handle SubscriptionRequest index=%v, %s", index, idstring(nil, trans)) |
Markku Virtanen | b642a19 | 2021-06-09 09:08:14 +0000 | [diff] [blame] | 467 | |
Markku Virtanen | 42723e2 | 2021-06-15 10:09:23 +0300 | [diff] [blame] | 468 | subRespMsg, err := c.handleSubscriptionRequest(trans, &subReqMsg, meid, *restSubId) |
| 469 | |
| 470 | xapp.Logger.Info("Handled SubscriptionRequest index=%v, %s", index, idstring(nil, trans)) |
| 471 | |
archagge | afbf95f | 2021-04-14 08:54:05 +0300 | [diff] [blame] | 472 | if err != nil { |
Markku Virtanen | b642a19 | 2021-06-09 09:08:14 +0000 | [diff] [blame] | 473 | c.sendUnsuccesfullResponseNotification(restSubId, restSubscription, xAppEventInstanceID, err, clientEndpoint, trans) |
archagge | afbf95f | 2021-04-14 08:54:05 +0300 | [diff] [blame] | 474 | } else { |
Konstantinos Archangelof | e93b00f | 2021-06-03 10:00:19 +0000 | [diff] [blame] | 475 | e2EventInstanceID = (int64)(subRespMsg.RequestId.InstanceId) |
Markku Virtanen | 42723e2 | 2021-06-15 10:09:23 +0300 | [diff] [blame] | 476 | restSubscription.AddMd5Sum(md5sum) |
| 477 | xapp.Logger.Info("SubscriptionRequest index=%v processed successfullyfor %s. endpoint=%v:%v, XappEventInstanceID=%v, E2EventInstanceID=%v, %s", |
| 478 | index, *restSubId, clientEndpoint.Host, *clientEndpoint.HTTPPort, xAppEventInstanceID, e2EventInstanceID, idstring(nil, trans)) |
Markku Virtanen | b642a19 | 2021-06-09 09:08:14 +0000 | [diff] [blame] | 479 | c.sendSuccesfullResponseNotification(restSubId, restSubscription, xAppEventInstanceID, e2EventInstanceID, clientEndpoint, trans) |
archagge | afbf95f | 2021-04-14 08:54:05 +0300 | [diff] [blame] | 480 | } |
Markku Virtanen | b642a19 | 2021-06-09 09:08:14 +0000 | [diff] [blame] | 481 | trans.Release() |
archagge | afbf95f | 2021-04-14 08:54:05 +0300 | [diff] [blame] | 482 | } |
| 483 | } |
| 484 | |
| 485 | //------------------------------------------------------------------- |
| 486 | // |
| 487 | //------------------------------------------------------------------ |
| 488 | func (c *Control) handleSubscriptionRequest(trans *TransactionXapp, subReqMsg *e2ap.E2APSubscriptionRequest, meid *string, |
Markku Virtanen | 42723e2 | 2021-06-15 10:09:23 +0300 | [diff] [blame] | 489 | restSubId string) (*e2ap.E2APSubscriptionResponse, error) { |
archagge | afbf95f | 2021-04-14 08:54:05 +0300 | [diff] [blame] | 490 | |
| 491 | err := c.tracker.Track(trans) |
| 492 | if err != nil { |
Markku Virtanen | 55d2a28 | 2021-06-04 14:46:56 +0300 | [diff] [blame] | 493 | xapp.Logger.Error("XAPP-SubReq Tracking error: %s", idstring(err, trans)) |
| 494 | err = fmt.Errorf("Tracking failure") |
archagge | afbf95f | 2021-04-14 08:54:05 +0300 | [diff] [blame] | 495 | return nil, err |
| 496 | } |
| 497 | |
| 498 | subs, err := c.registry.AssignToSubscription(trans, subReqMsg, c.ResetTestFlag, c) |
| 499 | if err != nil { |
Markku Virtanen | 55d2a28 | 2021-06-04 14:46:56 +0300 | [diff] [blame] | 500 | xapp.Logger.Error("XAPP-SubReq Assign error: %s", idstring(err, trans)) |
archagge | afbf95f | 2021-04-14 08:54:05 +0300 | [diff] [blame] | 501 | return nil, err |
| 502 | } |
| 503 | |
| 504 | // |
| 505 | // Wake subs request |
| 506 | // |
| 507 | go c.handleSubscriptionCreate(subs, trans) |
| 508 | event, _ := trans.WaitEvent(0) //blocked wait as timeout is handled in subs side |
| 509 | |
| 510 | err = nil |
| 511 | if event != nil { |
| 512 | switch themsg := event.(type) { |
| 513 | case *e2ap.E2APSubscriptionResponse: |
| 514 | trans.Release() |
| 515 | return themsg, nil |
| 516 | case *e2ap.E2APSubscriptionFailure: |
Markku Virtanen | 55d2a28 | 2021-06-04 14:46:56 +0300 | [diff] [blame] | 517 | err = fmt.Errorf("E2 SubscriptionFailure received") |
archagge | afbf95f | 2021-04-14 08:54:05 +0300 | [diff] [blame] | 518 | return nil, err |
| 519 | default: |
Markku Virtanen | 55d2a28 | 2021-06-04 14:46:56 +0300 | [diff] [blame] | 520 | err = fmt.Errorf("unexpected E2 subscription response received") |
archagge | afbf95f | 2021-04-14 08:54:05 +0300 | [diff] [blame] | 521 | break |
| 522 | } |
Markku Virtanen | 55d2a28 | 2021-06-04 14:46:56 +0300 | [diff] [blame] | 523 | } else { |
| 524 | err = fmt.Errorf("E2 subscription response timeout") |
archagge | afbf95f | 2021-04-14 08:54:05 +0300 | [diff] [blame] | 525 | } |
Markku Virtanen | 55d2a28 | 2021-06-04 14:46:56 +0300 | [diff] [blame] | 526 | |
| 527 | xapp.Logger.Error("XAPP-SubReq E2 subscription failed %s", idstring(err, trans, subs)) |
Markku Virtanen | fe2cdab | 2021-05-21 10:59:29 +0000 | [diff] [blame] | 528 | c.registry.RemoveFromSubscription(subs, trans, waitRouteCleanup_ms, c) |
archagge | afbf95f | 2021-04-14 08:54:05 +0300 | [diff] [blame] | 529 | return nil, err |
| 530 | } |
| 531 | |
| 532 | //------------------------------------------------------------------- |
| 533 | // |
| 534 | //------------------------------------------------------------------- |
Markku Virtanen | 42723e2 | 2021-06-15 10:09:23 +0300 | [diff] [blame] | 535 | func (c *Control) sendUnsuccesfullResponseNotification(restSubId *string, restSubscription *RESTSubscription, xAppEventInstanceID int64, err error, |
| 536 | clientEndpoint *models.SubscriptionParamsClientEndpoint, trans *TransactionXapp) { |
| 537 | |
| 538 | // Send notification to xApp that prosessing of a Subscription Request has failed. |
| 539 | e2EventInstanceID := (int64)(0) |
| 540 | errorCause := err.Error() |
| 541 | resp := &models.SubscriptionResponse{ |
| 542 | SubscriptionID: restSubId, |
| 543 | SubscriptionInstances: []*models.SubscriptionInstance{ |
| 544 | &models.SubscriptionInstance{E2EventInstanceID: &e2EventInstanceID, |
| 545 | ErrorCause: &errorCause, |
| 546 | XappEventInstanceID: &xAppEventInstanceID}, |
| 547 | }, |
| 548 | } |
| 549 | // Mark REST subscription request processed. |
| 550 | restSubscription.SetProcessed(err) |
| 551 | c.UpdateRESTSubscriptionInDB(*restSubId, restSubscription, false) |
| 552 | if trans != nil { |
| 553 | xapp.Logger.Info("Sending unsuccessful REST notification (cause %s) to endpoint=%v:%v, XappEventInstanceID=%v, E2EventInstanceID=%v, %s", |
| 554 | errorCause, clientEndpoint.Host, *clientEndpoint.HTTPPort, xAppEventInstanceID, e2EventInstanceID, idstring(nil, trans)) |
| 555 | } else { |
| 556 | xapp.Logger.Info("Sending unsuccessful REST notification (cause %s) to endpoint=%v:%v, XappEventInstanceID=%v, E2EventInstanceID=%v", |
| 557 | errorCause, clientEndpoint.Host, *clientEndpoint.HTTPPort, xAppEventInstanceID, e2EventInstanceID) |
| 558 | } |
| 559 | |
| 560 | c.UpdateCounter(cRestSubFailNotifToXapp) |
| 561 | xapp.Subscription.Notify(resp, *clientEndpoint) |
| 562 | } |
| 563 | |
| 564 | //------------------------------------------------------------------- |
| 565 | // |
| 566 | //------------------------------------------------------------------- |
| 567 | func (c *Control) sendSuccesfullResponseNotification(restSubId *string, restSubscription *RESTSubscription, xAppEventInstanceID int64, e2EventInstanceID int64, |
| 568 | clientEndpoint *models.SubscriptionParamsClientEndpoint, trans *TransactionXapp) { |
| 569 | |
| 570 | // Store successfully processed InstanceId for deletion |
| 571 | restSubscription.AddE2InstanceId((uint32)(e2EventInstanceID)) |
| 572 | restSubscription.AddXappIdToE2Id(xAppEventInstanceID, e2EventInstanceID) |
| 573 | |
| 574 | // Send notification to xApp that a Subscription Request has been processed. |
| 575 | resp := &models.SubscriptionResponse{ |
| 576 | SubscriptionID: restSubId, |
| 577 | SubscriptionInstances: []*models.SubscriptionInstance{ |
| 578 | &models.SubscriptionInstance{E2EventInstanceID: &e2EventInstanceID, |
| 579 | ErrorCause: nil, |
| 580 | XappEventInstanceID: &xAppEventInstanceID}, |
| 581 | }, |
| 582 | } |
| 583 | // Mark REST subscription request processesd. |
| 584 | restSubscription.SetProcessed(nil) |
| 585 | c.UpdateRESTSubscriptionInDB(*restSubId, restSubscription, false) |
| 586 | xapp.Logger.Info("Sending successful REST notification to endpoint=%v:%v, XappEventInstanceID=%v, E2EventInstanceID=%v, %s", |
| 587 | clientEndpoint.Host, *clientEndpoint.HTTPPort, xAppEventInstanceID, e2EventInstanceID, idstring(nil, trans)) |
| 588 | |
| 589 | c.UpdateCounter(cRestSubNotifToXapp) |
| 590 | xapp.Subscription.Notify(resp, *clientEndpoint) |
| 591 | } |
| 592 | |
| 593 | //------------------------------------------------------------------- |
| 594 | // |
| 595 | //------------------------------------------------------------------- |
archagge | afbf95f | 2021-04-14 08:54:05 +0300 | [diff] [blame] | 596 | func (c *Control) SubscriptionDeleteHandlerCB(restSubId string) error { |
| 597 | |
| 598 | c.CntRecvMsg++ |
Konstantinos Archangelof | 27433e7 | 2021-05-31 08:30:35 +0000 | [diff] [blame] | 599 | c.UpdateCounter(cRestSubDelReqFromXapp) |
archagge | afbf95f | 2021-04-14 08:54:05 +0300 | [diff] [blame] | 600 | |
| 601 | xapp.Logger.Info("SubscriptionDeleteRequest from XAPP") |
| 602 | |
Konstantinos Archangelof | e93b00f | 2021-06-03 10:00:19 +0000 | [diff] [blame] | 603 | restSubscription, err := c.registry.GetRESTSubscription(restSubId, true) |
archagge | afbf95f | 2021-04-14 08:54:05 +0300 | [diff] [blame] | 604 | if err != nil { |
| 605 | xapp.Logger.Error("%s", err.Error()) |
| 606 | if restSubscription == nil { |
| 607 | // Subscription was not found |
| 608 | return nil |
| 609 | } else { |
| 610 | if restSubscription.SubReqOngoing == true { |
| 611 | err := fmt.Errorf("Handling of the REST Subscription Request still ongoing %s", restSubId) |
| 612 | xapp.Logger.Error("%s", err.Error()) |
| 613 | return err |
| 614 | } else if restSubscription.SubDelReqOngoing == true { |
| 615 | // Previous request for same restSubId still ongoing |
| 616 | return nil |
| 617 | } |
| 618 | } |
| 619 | } |
| 620 | |
| 621 | xAppRmrEndPoint := restSubscription.xAppRmrEndPoint |
| 622 | go func() { |
Markku Virtanen | 42723e2 | 2021-06-15 10:09:23 +0300 | [diff] [blame] | 623 | xapp.Logger.Info("Deleteting instances = %v", restSubscription.InstanceIds) |
archagge | afbf95f | 2021-04-14 08:54:05 +0300 | [diff] [blame] | 624 | for _, instanceId := range restSubscription.InstanceIds { |
Konstantinos Archangelof | e93b00f | 2021-06-03 10:00:19 +0000 | [diff] [blame] | 625 | xAppEventInstanceID, err := c.SubscriptionDeleteHandler(&restSubId, &xAppRmrEndPoint, &restSubscription.Meid, instanceId) |
| 626 | |
archagge | afbf95f | 2021-04-14 08:54:05 +0300 | [diff] [blame] | 627 | if err != nil { |
| 628 | xapp.Logger.Error("%s", err.Error()) |
| 629 | //return err |
| 630 | } |
| 631 | xapp.Logger.Info("Deleteting instanceId = %v", instanceId) |
Konstantinos Archangelof | e93b00f | 2021-06-03 10:00:19 +0000 | [diff] [blame] | 632 | restSubscription.DeleteXappIdToE2Id(xAppEventInstanceID) |
| 633 | restSubscription.DeleteE2InstanceId(instanceId) |
archagge | afbf95f | 2021-04-14 08:54:05 +0300 | [diff] [blame] | 634 | } |
Markku Virtanen | 42723e2 | 2021-06-15 10:09:23 +0300 | [diff] [blame] | 635 | restDuplicateCtrl.DeleteLastKnownRestSubsIdBasedOnMd5sum(restSubscription.lastReqMd5sum) |
archagge | afbf95f | 2021-04-14 08:54:05 +0300 | [diff] [blame] | 636 | c.registry.DeleteRESTSubscription(&restSubId) |
Konstantinos Archangelof | 268d715 | 2021-06-14 12:24:00 +0300 | [diff] [blame] | 637 | c.RemoveRESTSubscriptionFromDb(restSubId) |
archagge | afbf95f | 2021-04-14 08:54:05 +0300 | [diff] [blame] | 638 | }() |
| 639 | |
Konstantinos Archangelof | 27433e7 | 2021-05-31 08:30:35 +0000 | [diff] [blame] | 640 | c.UpdateCounter(cRestSubDelRespToXapp) |
archagge | afbf95f | 2021-04-14 08:54:05 +0300 | [diff] [blame] | 641 | |
Anssi Mannila | c92b421 | 2020-12-07 14:59:34 +0200 | [diff] [blame] | 642 | return nil |
Juha Hyttinen | c9eb08a | 2020-02-28 08:53:33 +0200 | [diff] [blame] | 643 | } |
| 644 | |
archagge | afbf95f | 2021-04-14 08:54:05 +0300 | [diff] [blame] | 645 | //------------------------------------------------------------------- |
| 646 | // |
| 647 | //------------------------------------------------------------------- |
Konstantinos Archangelof | e93b00f | 2021-06-03 10:00:19 +0000 | [diff] [blame] | 648 | func (c *Control) SubscriptionDeleteHandler(restSubId *string, endPoint *string, meid *string, instanceId uint32) (int64, error) { |
archagge | afbf95f | 2021-04-14 08:54:05 +0300 | [diff] [blame] | 649 | |
Konstantinos Archangelof | e93b00f | 2021-06-03 10:00:19 +0000 | [diff] [blame] | 650 | var xAppEventInstanceID int64 |
| 651 | subs, err := c.registry.GetSubscriptionFirstMatch([]uint32{instanceId}) |
| 652 | if err != nil { |
| 653 | xapp.Logger.Info("Subscription Delete Handler subscription for restSubId=%v, E2EventInstanceID=%v not found %s", |
| 654 | restSubId, instanceId, idstring(err, nil)) |
| 655 | return xAppEventInstanceID, nil |
| 656 | } |
| 657 | |
| 658 | xAppEventInstanceID = int64(subs.ReqId.Id) |
| 659 | 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] | 660 | if trans == nil { |
| 661 | err := fmt.Errorf("XAPP-SubDelReq transaction not created. restSubId %s, endPoint %s, meid %s, instanceId %v", *restSubId, *endPoint, *meid, instanceId) |
| 662 | xapp.Logger.Error("%s", err.Error()) |
| 663 | } |
| 664 | defer trans.Release() |
| 665 | |
Konstantinos Archangelof | e93b00f | 2021-06-03 10:00:19 +0000 | [diff] [blame] | 666 | err = c.tracker.Track(trans) |
archagge | afbf95f | 2021-04-14 08:54:05 +0300 | [diff] [blame] | 667 | if err != nil { |
| 668 | err := fmt.Errorf("XAPP-SubDelReq %s:", idstring(err, trans)) |
| 669 | xapp.Logger.Error("%s", err.Error()) |
Konstantinos Archangelof | e93b00f | 2021-06-03 10:00:19 +0000 | [diff] [blame] | 670 | return xAppEventInstanceID, &time.ParseError{} |
archagge | afbf95f | 2021-04-14 08:54:05 +0300 | [diff] [blame] | 671 | } |
| 672 | // |
| 673 | // Wake subs delete |
| 674 | // |
| 675 | go c.handleSubscriptionDelete(subs, trans) |
| 676 | trans.WaitEvent(0) //blocked wait as timeout is handled in subs side |
| 677 | |
| 678 | xapp.Logger.Debug("XAPP-SubDelReq: Handling event %s ", idstring(nil, trans, subs)) |
| 679 | |
Markku Virtanen | fe2cdab | 2021-05-21 10:59:29 +0000 | [diff] [blame] | 680 | c.registry.RemoveFromSubscription(subs, trans, waitRouteCleanup_ms, c) |
archagge | afbf95f | 2021-04-14 08:54:05 +0300 | [diff] [blame] | 681 | |
Konstantinos Archangelof | e93b00f | 2021-06-03 10:00:19 +0000 | [diff] [blame] | 682 | return xAppEventInstanceID, nil |
archagge | afbf95f | 2021-04-14 08:54:05 +0300 | [diff] [blame] | 683 | } |
| 684 | |
| 685 | //------------------------------------------------------------------- |
| 686 | // |
| 687 | //------------------------------------------------------------------- |
Juha Hyttinen | c9eb08a | 2020-02-28 08:53:33 +0200 | [diff] [blame] | 688 | func (c *Control) QueryHandler() (models.SubscriptionList, error) { |
Anssi Mannila | 4c626a2 | 2021-02-11 12:50:48 +0200 | [diff] [blame] | 689 | xapp.Logger.Info("QueryHandler() called") |
| 690 | |
archagge | afbf95f | 2021-04-14 08:54:05 +0300 | [diff] [blame] | 691 | c.CntRecvMsg++ |
| 692 | |
Juha Hyttinen | c9eb08a | 2020-02-28 08:53:33 +0200 | [diff] [blame] | 693 | return c.registry.QueryHandler() |
| 694 | } |
| 695 | |
Anssi Mannila | c92b421 | 2020-12-07 14:59:34 +0200 | [diff] [blame] | 696 | func (c *Control) TestRestHandler(w http.ResponseWriter, r *http.Request) { |
Anssi Mannila | c92b421 | 2020-12-07 14:59:34 +0200 | [diff] [blame] | 697 | xapp.Logger.Info("TestRestHandler() called") |
| 698 | |
| 699 | pathParams := mux.Vars(r) |
| 700 | s := pathParams["testId"] |
| 701 | |
| 702 | // This can be used to delete single subscription from db |
| 703 | if contains := strings.Contains(s, "deletesubid="); contains == true { |
| 704 | var splits = strings.Split(s, "=") |
| 705 | if subId, err := strconv.ParseInt(splits[1], 10, 64); err == nil { |
| 706 | xapp.Logger.Info("RemoveSubscriptionFromSdl() called. subId = %v", subId) |
| 707 | c.RemoveSubscriptionFromSdl(uint32(subId)) |
| 708 | return |
| 709 | } |
| 710 | } |
| 711 | |
| 712 | // This can be used to remove all subscriptions db from |
| 713 | if s == "emptydb" { |
| 714 | xapp.Logger.Info("RemoveAllSubscriptionsFromSdl() called") |
| 715 | c.RemoveAllSubscriptionsFromSdl() |
Konstantinos Archangelof | 268d715 | 2021-06-14 12:24:00 +0300 | [diff] [blame] | 716 | c.RemoveAllRESTSubscriptionsFromSdl() |
Anssi Mannila | c92b421 | 2020-12-07 14:59:34 +0200 | [diff] [blame] | 717 | return |
| 718 | } |
| 719 | |
| 720 | // This is meant to cause submgr's restart in testing |
| 721 | if s == "restart" { |
| 722 | xapp.Logger.Info("os.Exit(1) called") |
| 723 | os.Exit(1) |
| 724 | } |
| 725 | |
| 726 | xapp.Logger.Info("Unsupported rest command received %s", s) |
| 727 | } |
| 728 | |
Juha Hyttinen | c9eb08a | 2020-02-28 08:53:33 +0200 | [diff] [blame] | 729 | //------------------------------------------------------------------- |
| 730 | // |
| 731 | //------------------------------------------------------------------- |
| 732 | |
Juha Hyttinen | 83ada00 | 2020-01-30 10:36:33 +0200 | [diff] [blame] | 733 | func (c *Control) rmrSendToE2T(desc string, subs *Subscription, trans *TransactionSubs) (err error) { |
Juha Hyttinen | 9dc5adc | 2020-08-13 10:02:40 +0300 | [diff] [blame] | 734 | params := &xapp.RMRParams{} |
Juha Hyttinen | e406a34 | 2020-01-13 13:02:26 +0200 | [diff] [blame] | 735 | params.Mtype = trans.GetMtype() |
Juha Hyttinen | aada645 | 2020-04-07 08:47:58 +0300 | [diff] [blame] | 736 | params.SubId = int(subs.GetReqId().InstanceId) |
Juha Hyttinen | 86a4620 | 2020-01-14 12:49:09 +0200 | [diff] [blame] | 737 | params.Xid = "" |
Juha Hyttinen | e406a34 | 2020-01-13 13:02:26 +0200 | [diff] [blame] | 738 | params.Meid = subs.GetMeid() |
| 739 | params.Src = "" |
Juha Hyttinen | 63284a2 | 2020-01-15 10:45:11 +0200 | [diff] [blame] | 740 | params.PayloadLen = len(trans.Payload.Buf) |
| 741 | params.Payload = trans.Payload.Buf |
Juha Hyttinen | e406a34 | 2020-01-13 13:02:26 +0200 | [diff] [blame] | 742 | params.Mbuf = nil |
Juha Hyttinen | 5f8ffa0 | 2020-02-06 15:28:59 +0200 | [diff] [blame] | 743 | xapp.Logger.Info("MSG to E2T: %s %s %s", desc, trans.String(), params.String()) |
Abukar Mohamed | fbd4df5 | 2021-03-11 06:13:27 +0000 | [diff] [blame] | 744 | err = c.SendWithRetry(params, false, 5) |
| 745 | if err != nil { |
| 746 | xapp.Logger.Error("rmrSendToE2T: Send failed: %+v", err) |
| 747 | } |
| 748 | return err |
kalnagy | e001868 | 2019-09-26 16:28:25 +0200 | [diff] [blame] | 749 | } |
| 750 | |
Juha Hyttinen | 83ada00 | 2020-01-30 10:36:33 +0200 | [diff] [blame] | 751 | func (c *Control) rmrSendToXapp(desc string, subs *Subscription, trans *TransactionXapp) (err error) { |
| 752 | |
Juha Hyttinen | 9dc5adc | 2020-08-13 10:02:40 +0300 | [diff] [blame] | 753 | params := &xapp.RMRParams{} |
Juha Hyttinen | 63284a2 | 2020-01-15 10:45:11 +0200 | [diff] [blame] | 754 | params.Mtype = trans.GetMtype() |
Juha Hyttinen | aada645 | 2020-04-07 08:47:58 +0300 | [diff] [blame] | 755 | params.SubId = int(subs.GetReqId().InstanceId) |
Juha Hyttinen | e406a34 | 2020-01-13 13:02:26 +0200 | [diff] [blame] | 756 | params.Xid = trans.GetXid() |
Juha Hyttinen | 86a4620 | 2020-01-14 12:49:09 +0200 | [diff] [blame] | 757 | params.Meid = trans.GetMeid() |
Juha Hyttinen | e406a34 | 2020-01-13 13:02:26 +0200 | [diff] [blame] | 758 | params.Src = "" |
Juha Hyttinen | 63284a2 | 2020-01-15 10:45:11 +0200 | [diff] [blame] | 759 | params.PayloadLen = len(trans.Payload.Buf) |
| 760 | params.Payload = trans.Payload.Buf |
Juha Hyttinen | e406a34 | 2020-01-13 13:02:26 +0200 | [diff] [blame] | 761 | params.Mbuf = nil |
Juha Hyttinen | 5f8ffa0 | 2020-02-06 15:28:59 +0200 | [diff] [blame] | 762 | xapp.Logger.Info("MSG to XAPP: %s %s %s", desc, trans.String(), params.String()) |
Abukar Mohamed | fbd4df5 | 2021-03-11 06:13:27 +0000 | [diff] [blame] | 763 | err = c.SendWithRetry(params, false, 5) |
| 764 | if err != nil { |
| 765 | xapp.Logger.Error("rmrSendToXapp: Send failed: %+v", err) |
| 766 | } |
| 767 | return err |
Juha Hyttinen | e406a34 | 2020-01-13 13:02:26 +0200 | [diff] [blame] | 768 | } |
| 769 | |
Juha Hyttinen | 9dc5adc | 2020-08-13 10:02:40 +0300 | [diff] [blame] | 770 | func (c *Control) Consume(msg *xapp.RMRParams) (err error) { |
| 771 | if c.RMRClient == nil { |
Juha Hyttinen | 5f8ffa0 | 2020-02-06 15:28:59 +0200 | [diff] [blame] | 772 | err = fmt.Errorf("Rmr object nil can handle %s", msg.String()) |
| 773 | xapp.Logger.Error("%s", err.Error()) |
| 774 | return |
| 775 | } |
| 776 | c.CntRecvMsg++ |
| 777 | |
Juha Hyttinen | 9dc5adc | 2020-08-13 10:02:40 +0300 | [diff] [blame] | 778 | defer c.RMRClient.Free(msg.Mbuf) |
Juha Hyttinen | 83ada00 | 2020-01-30 10:36:33 +0200 | [diff] [blame] | 779 | |
Juha Hyttinen | a8a908d | 2020-05-26 15:12:47 +0300 | [diff] [blame] | 780 | // xapp-frame might use direct access to c buffer and |
| 781 | // when msg.Mbuf is freed, someone might take it into use |
| 782 | // and payload data might be invalid inside message handle function |
| 783 | // |
| 784 | // subscriptions won't load system a lot so there is no |
| 785 | // real performance hit by cloning buffer into new go byte slice |
| 786 | cPay := append(msg.Payload[:0:0], msg.Payload...) |
| 787 | msg.Payload = cPay |
| 788 | msg.PayloadLen = len(cPay) |
| 789 | |
Anssi Mannila | 90fa021 | 2019-12-12 10:47:47 +0200 | [diff] [blame] | 790 | switch msg.Mtype { |
Juha Hyttinen | c9eb08a | 2020-02-28 08:53:33 +0200 | [diff] [blame] | 791 | case xapp.RIC_SUB_REQ: |
Juha Hyttinen | 422d018 | 2020-01-17 13:37:05 +0200 | [diff] [blame] | 792 | go c.handleXAPPSubscriptionRequest(msg) |
Juha Hyttinen | c9eb08a | 2020-02-28 08:53:33 +0200 | [diff] [blame] | 793 | case xapp.RIC_SUB_RESP: |
Juha Hyttinen | 422d018 | 2020-01-17 13:37:05 +0200 | [diff] [blame] | 794 | go c.handleE2TSubscriptionResponse(msg) |
Juha Hyttinen | c9eb08a | 2020-02-28 08:53:33 +0200 | [diff] [blame] | 795 | case xapp.RIC_SUB_FAILURE: |
Juha Hyttinen | 422d018 | 2020-01-17 13:37:05 +0200 | [diff] [blame] | 796 | go c.handleE2TSubscriptionFailure(msg) |
Juha Hyttinen | c9eb08a | 2020-02-28 08:53:33 +0200 | [diff] [blame] | 797 | case xapp.RIC_SUB_DEL_REQ: |
Juha Hyttinen | 422d018 | 2020-01-17 13:37:05 +0200 | [diff] [blame] | 798 | go c.handleXAPPSubscriptionDeleteRequest(msg) |
Juha Hyttinen | c9eb08a | 2020-02-28 08:53:33 +0200 | [diff] [blame] | 799 | case xapp.RIC_SUB_DEL_RESP: |
Juha Hyttinen | 422d018 | 2020-01-17 13:37:05 +0200 | [diff] [blame] | 800 | go c.handleE2TSubscriptionDeleteResponse(msg) |
Juha Hyttinen | c9eb08a | 2020-02-28 08:53:33 +0200 | [diff] [blame] | 801 | case xapp.RIC_SUB_DEL_FAILURE: |
Juha Hyttinen | 422d018 | 2020-01-17 13:37:05 +0200 | [diff] [blame] | 802 | go c.handleE2TSubscriptionDeleteFailure(msg) |
Anssi Mannila | 90fa021 | 2019-12-12 10:47:47 +0200 | [diff] [blame] | 803 | default: |
| 804 | xapp.Logger.Info("Unknown Message Type '%d', discarding", msg.Mtype) |
Balint Uveges | cd3881b | 2019-10-02 15:01:43 +0000 | [diff] [blame] | 805 | } |
Juha Hyttinen | 5f8ffa0 | 2020-02-06 15:28:59 +0200 | [diff] [blame] | 806 | return |
Juha Hyttinen | 31797b4 | 2020-01-16 14:05:01 +0200 | [diff] [blame] | 807 | } |
| 808 | |
Juha Hyttinen | 422d018 | 2020-01-17 13:37:05 +0200 | [diff] [blame] | 809 | //------------------------------------------------------------------- |
| 810 | // handle from XAPP Subscription Request |
| 811 | //------------------------------------------------------------------ |
Juha Hyttinen | 9dc5adc | 2020-08-13 10:02:40 +0300 | [diff] [blame] | 812 | func (c *Control) handleXAPPSubscriptionRequest(params *xapp.RMRParams) { |
Juha Hyttinen | 83ada00 | 2020-01-30 10:36:33 +0200 | [diff] [blame] | 813 | xapp.Logger.Info("MSG from XAPP: %s", params.String()) |
Anssi Mannila | 4abf180 | 2021-01-28 13:06:46 +0200 | [diff] [blame] | 814 | c.UpdateCounter(cSubReqFromXapp) |
Juha Hyttinen | 422d018 | 2020-01-17 13:37:05 +0200 | [diff] [blame] | 815 | |
| 816 | subReqMsg, err := c.e2ap.UnpackSubscriptionRequest(params.Payload) |
| 817 | if err != nil { |
Juha Hyttinen | 83ada00 | 2020-01-30 10:36:33 +0200 | [diff] [blame] | 818 | xapp.Logger.Error("XAPP-SubReq: %s", idstring(err, params)) |
Juha Hyttinen | 422d018 | 2020-01-17 13:37:05 +0200 | [diff] [blame] | 819 | return |
| 820 | } |
| 821 | |
Anssi Mannila | 4c626a2 | 2021-02-11 12:50:48 +0200 | [diff] [blame] | 822 | 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] | 823 | if trans == nil { |
| 824 | 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] | 825 | return |
| 826 | } |
| 827 | defer trans.Release() |
| 828 | |
Anssi Mannila | 6b3796f | 2021-02-12 09:11:35 +0200 | [diff] [blame] | 829 | if err = c.tracker.Track(trans); err != nil { |
Juha Hyttinen | 83ada00 | 2020-01-30 10:36:33 +0200 | [diff] [blame] | 830 | xapp.Logger.Error("XAPP-SubReq: %s", idstring(err, trans)) |
| 831 | return |
| 832 | } |
| 833 | |
Juha Hyttinen | 429cfe6 | 2020-03-31 11:23:02 +0300 | [diff] [blame] | 834 | //TODO handle subscription toward e2term inside AssignToSubscription / hide handleSubscriptionCreate in it? |
Anssi Mannila | 4abf180 | 2021-01-28 13:06:46 +0200 | [diff] [blame] | 835 | subs, err := c.registry.AssignToSubscription(trans, subReqMsg, c.ResetTestFlag, c) |
Juha Hyttinen | 422d018 | 2020-01-17 13:37:05 +0200 | [diff] [blame] | 836 | if err != nil { |
Juha Hyttinen | 83ada00 | 2020-01-30 10:36:33 +0200 | [diff] [blame] | 837 | xapp.Logger.Error("XAPP-SubReq: %s", idstring(err, trans)) |
Juha Hyttinen | 422d018 | 2020-01-17 13:37:05 +0200 | [diff] [blame] | 838 | return |
| 839 | } |
| 840 | |
Anssi Mannila | 6b3796f | 2021-02-12 09:11:35 +0200 | [diff] [blame] | 841 | c.wakeSubscriptionRequest(subs, trans) |
| 842 | } |
| 843 | |
| 844 | //------------------------------------------------------------------- |
| 845 | // Wake Subscription Request to E2node |
| 846 | //------------------------------------------------------------------ |
| 847 | func (c *Control) wakeSubscriptionRequest(subs *Subscription, trans *TransactionXapp) { |
| 848 | |
Juha Hyttinen | 422d018 | 2020-01-17 13:37:05 +0200 | [diff] [blame] | 849 | go c.handleSubscriptionCreate(subs, trans) |
| 850 | event, _ := trans.WaitEvent(0) //blocked wait as timeout is handled in subs side |
Anssi Mannila | 6b3796f | 2021-02-12 09:11:35 +0200 | [diff] [blame] | 851 | var err error |
Juha Hyttinen | 422d018 | 2020-01-17 13:37:05 +0200 | [diff] [blame] | 852 | if event != nil { |
| 853 | switch themsg := event.(type) { |
| 854 | case *e2ap.E2APSubscriptionResponse: |
Anssi Mannila | 4c626a2 | 2021-02-11 12:50:48 +0200 | [diff] [blame] | 855 | themsg.RequestId.Id = trans.RequestId.Id |
Juha Hyttinen | 422d018 | 2020-01-17 13:37:05 +0200 | [diff] [blame] | 856 | trans.Mtype, trans.Payload, err = c.e2ap.PackSubscriptionResponse(themsg) |
| 857 | if err == nil { |
Anssi Mannila | 64a0df4 | 2020-02-26 09:46:03 +0200 | [diff] [blame] | 858 | trans.Release() |
Anssi Mannila | 4abf180 | 2021-01-28 13:06:46 +0200 | [diff] [blame] | 859 | c.UpdateCounter(cSubRespToXapp) |
Juha Hyttinen | 83ada00 | 2020-01-30 10:36:33 +0200 | [diff] [blame] | 860 | c.rmrSendToXapp("", subs, trans) |
Juha Hyttinen | 422d018 | 2020-01-17 13:37:05 +0200 | [diff] [blame] | 861 | return |
| 862 | } |
| 863 | case *e2ap.E2APSubscriptionFailure: |
Anssi Mannila | 4c626a2 | 2021-02-11 12:50:48 +0200 | [diff] [blame] | 864 | themsg.RequestId.Id = trans.RequestId.Id |
Juha Hyttinen | 422d018 | 2020-01-17 13:37:05 +0200 | [diff] [blame] | 865 | trans.Mtype, trans.Payload, err = c.e2ap.PackSubscriptionFailure(themsg) |
| 866 | if err == nil { |
Anssi Mannila | 4abf180 | 2021-01-28 13:06:46 +0200 | [diff] [blame] | 867 | c.UpdateCounter(cSubFailToXapp) |
Juha Hyttinen | 83ada00 | 2020-01-30 10:36:33 +0200 | [diff] [blame] | 868 | c.rmrSendToXapp("", subs, trans) |
Juha Hyttinen | 422d018 | 2020-01-17 13:37:05 +0200 | [diff] [blame] | 869 | } |
Juha Hyttinen | 422d018 | 2020-01-17 13:37:05 +0200 | [diff] [blame] | 870 | default: |
Juha Hyttinen | 31797b4 | 2020-01-16 14:05:01 +0200 | [diff] [blame] | 871 | break |
| 872 | } |
| 873 | } |
Juha Hyttinen | 83ada00 | 2020-01-30 10:36:33 +0200 | [diff] [blame] | 874 | xapp.Logger.Info("XAPP-SubReq: failed %s", idstring(err, trans, subs)) |
Juha Hyttinen | 429cfe6 | 2020-03-31 11:23:02 +0300 | [diff] [blame] | 875 | //c.registry.RemoveFromSubscription(subs, trans, 5*time.Second) |
Juha Hyttinen | 31797b4 | 2020-01-16 14:05:01 +0200 | [diff] [blame] | 876 | } |
| 877 | |
Juha Hyttinen | 422d018 | 2020-01-17 13:37:05 +0200 | [diff] [blame] | 878 | //------------------------------------------------------------------- |
| 879 | // handle from XAPP Subscription Delete Request |
| 880 | //------------------------------------------------------------------ |
Juha Hyttinen | 9dc5adc | 2020-08-13 10:02:40 +0300 | [diff] [blame] | 881 | func (c *Control) handleXAPPSubscriptionDeleteRequest(params *xapp.RMRParams) { |
Juha Hyttinen | 83ada00 | 2020-01-30 10:36:33 +0200 | [diff] [blame] | 882 | xapp.Logger.Info("MSG from XAPP: %s", params.String()) |
Anssi Mannila | 4abf180 | 2021-01-28 13:06:46 +0200 | [diff] [blame] | 883 | c.UpdateCounter(cSubDelReqFromXapp) |
Juha Hyttinen | 422d018 | 2020-01-17 13:37:05 +0200 | [diff] [blame] | 884 | |
| 885 | subDelReqMsg, err := c.e2ap.UnpackSubscriptionDeleteRequest(params.Payload) |
Juha Hyttinen | 31797b4 | 2020-01-16 14:05:01 +0200 | [diff] [blame] | 886 | if err != nil { |
Juha Hyttinen | 83ada00 | 2020-01-30 10:36:33 +0200 | [diff] [blame] | 887 | xapp.Logger.Error("XAPP-SubDelReq %s", idstring(err, params)) |
Juha Hyttinen | 422d018 | 2020-01-17 13:37:05 +0200 | [diff] [blame] | 888 | return |
| 889 | } |
| 890 | |
Anssi Mannila | 4c626a2 | 2021-02-11 12:50:48 +0200 | [diff] [blame] | 891 | 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] | 892 | if trans == nil { |
| 893 | 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] | 894 | return |
| 895 | } |
| 896 | defer trans.Release() |
| 897 | |
Juha Hyttinen | 83ada00 | 2020-01-30 10:36:33 +0200 | [diff] [blame] | 898 | err = c.tracker.Track(trans) |
Juha Hyttinen | 422d018 | 2020-01-17 13:37:05 +0200 | [diff] [blame] | 899 | if err != nil { |
Juha Hyttinen | 83ada00 | 2020-01-30 10:36:33 +0200 | [diff] [blame] | 900 | xapp.Logger.Error("XAPP-SubReq: %s", idstring(err, trans)) |
| 901 | return |
| 902 | } |
| 903 | |
Juha Hyttinen | 47942b4 | 2020-02-27 10:41:43 +0200 | [diff] [blame] | 904 | subs, err := c.registry.GetSubscriptionFirstMatch([]uint32{trans.GetSubId()}) |
Juha Hyttinen | 83ada00 | 2020-01-30 10:36:33 +0200 | [diff] [blame] | 905 | if err != nil { |
| 906 | xapp.Logger.Error("XAPP-SubDelReq: %s", idstring(err, trans)) |
Juha Hyttinen | 422d018 | 2020-01-17 13:37:05 +0200 | [diff] [blame] | 907 | return |
| 908 | } |
| 909 | |
Juha Hyttinen | 422d018 | 2020-01-17 13:37:05 +0200 | [diff] [blame] | 910 | // |
| 911 | // Wake subs delete |
| 912 | // |
| 913 | go c.handleSubscriptionDelete(subs, trans) |
| 914 | trans.WaitEvent(0) //blocked wait as timeout is handled in subs side |
| 915 | |
Juha Hyttinen | 83ada00 | 2020-01-30 10:36:33 +0200 | [diff] [blame] | 916 | xapp.Logger.Debug("XAPP-SubDelReq: Handling event %s ", idstring(nil, trans, subs)) |
| 917 | |
Anssi Mannila | c92b421 | 2020-12-07 14:59:34 +0200 | [diff] [blame] | 918 | if subs.NoRespToXapp == true { |
| 919 | // Do no send delete responses to xapps due to submgr restart is deleting uncompleted subscriptions |
| 920 | return |
| 921 | } |
| 922 | |
| 923 | // Whatever is received success, fail or timeout, send successful delete response |
Juha Hyttinen | 422d018 | 2020-01-17 13:37:05 +0200 | [diff] [blame] | 924 | subDelRespMsg := &e2ap.E2APSubscriptionDeleteResponse{} |
Anssi Mannila | 4c626a2 | 2021-02-11 12:50:48 +0200 | [diff] [blame] | 925 | subDelRespMsg.RequestId.Id = trans.RequestId.Id |
| 926 | subDelRespMsg.RequestId.InstanceId = subs.GetReqId().RequestId.InstanceId |
Juha Hyttinen | 422d018 | 2020-01-17 13:37:05 +0200 | [diff] [blame] | 927 | subDelRespMsg.FunctionId = subs.SubReqMsg.FunctionId |
| 928 | trans.Mtype, trans.Payload, err = c.e2ap.PackSubscriptionDeleteResponse(subDelRespMsg) |
| 929 | if err == nil { |
Anssi Mannila | 4abf180 | 2021-01-28 13:06:46 +0200 | [diff] [blame] | 930 | c.UpdateCounter(cSubDelRespToXapp) |
Juha Hyttinen | 83ada00 | 2020-01-30 10:36:33 +0200 | [diff] [blame] | 931 | c.rmrSendToXapp("", subs, trans) |
Juha Hyttinen | 422d018 | 2020-01-17 13:37:05 +0200 | [diff] [blame] | 932 | } |
Juha Hyttinen | 83ada00 | 2020-01-30 10:36:33 +0200 | [diff] [blame] | 933 | |
Juha Hyttinen | 429cfe6 | 2020-03-31 11:23:02 +0300 | [diff] [blame] | 934 | //TODO handle subscription toward e2term insiged RemoveFromSubscription / hide handleSubscriptionDelete in it? |
| 935 | //c.registry.RemoveFromSubscription(subs, trans, 5*time.Second) |
Juha Hyttinen | 422d018 | 2020-01-17 13:37:05 +0200 | [diff] [blame] | 936 | } |
| 937 | |
| 938 | //------------------------------------------------------------------- |
| 939 | // SUBS CREATE Handling |
| 940 | //------------------------------------------------------------------- |
Juha Hyttinen | 83ada00 | 2020-01-30 10:36:33 +0200 | [diff] [blame] | 941 | func (c *Control) handleSubscriptionCreate(subs *Subscription, parentTrans *TransactionXapp) { |
Juha Hyttinen | 422d018 | 2020-01-17 13:37:05 +0200 | [diff] [blame] | 942 | |
Anssi Mannila | c92b421 | 2020-12-07 14:59:34 +0200 | [diff] [blame] | 943 | var removeSubscriptionFromDb bool = false |
Juha Hyttinen | 83ada00 | 2020-01-30 10:36:33 +0200 | [diff] [blame] | 944 | trans := c.tracker.NewSubsTransaction(subs) |
Juha Hyttinen | 422d018 | 2020-01-17 13:37:05 +0200 | [diff] [blame] | 945 | subs.WaitTransactionTurn(trans) |
| 946 | defer subs.ReleaseTransactionTurn(trans) |
| 947 | defer trans.Release() |
| 948 | |
Juha Hyttinen | 83ada00 | 2020-01-30 10:36:33 +0200 | [diff] [blame] | 949 | xapp.Logger.Debug("SUBS-SubReq: Handling %s ", idstring(nil, trans, subs, parentTrans)) |
Juha Hyttinen | 422d018 | 2020-01-17 13:37:05 +0200 | [diff] [blame] | 950 | |
Juha Hyttinen | 83ada00 | 2020-01-30 10:36:33 +0200 | [diff] [blame] | 951 | subRfMsg, valid := subs.GetCachedResponse() |
| 952 | if subRfMsg == nil && valid == true { |
Anssi Mannila | 6d629ad | 2021-01-25 09:59:56 +0200 | [diff] [blame] | 953 | event := c.sendE2TSubscriptionRequest(subs, trans, parentTrans) |
| 954 | switch event.(type) { |
| 955 | case *e2ap.E2APSubscriptionResponse: |
| 956 | subRfMsg, valid = subs.SetCachedResponse(event, true) |
| 957 | subs.SubRespRcvd = true |
| 958 | case *e2ap.E2APSubscriptionFailure: |
| 959 | removeSubscriptionFromDb = true |
| 960 | subRfMsg, valid = subs.SetCachedResponse(event, false) |
Markku Virtanen | 42723e2 | 2021-06-15 10:09:23 +0300 | [diff] [blame] | 961 | xapp.Logger.Info("SUBS-SubReq: internal delete due failure event(%s) %s", typeofSubsMessage(event), idstring(nil, trans, subs, parentTrans)) |
archagge | afbf95f | 2021-04-14 08:54:05 +0300 | [diff] [blame] | 962 | c.sendE2TSubscriptionDeleteRequest(subs, trans, parentTrans) |
Anssi Mannila | 6d629ad | 2021-01-25 09:59:56 +0200 | [diff] [blame] | 963 | case *SubmgrRestartTestEvent: |
| 964 | // This simulates that no response has been received and after restart subscriptions are restored from db |
| 965 | xapp.Logger.Debug("Test restart flag is active. Dropping this transaction to test restart case") |
| 966 | return |
| 967 | default: |
Markku Virtanen | 42723e2 | 2021-06-15 10:09:23 +0300 | [diff] [blame] | 968 | xapp.Logger.Info("SUBS-SubReq: internal delete due default event(%s) %s", typeofSubsMessage(event), idstring(nil, trans, subs, parentTrans)) |
Anssi Mannila | 6d629ad | 2021-01-25 09:59:56 +0200 | [diff] [blame] | 969 | removeSubscriptionFromDb = true |
| 970 | subRfMsg, valid = subs.SetCachedResponse(nil, false) |
| 971 | c.sendE2TSubscriptionDeleteRequest(subs, trans, parentTrans) |
Juha Hyttinen | 83ada00 | 2020-01-30 10:36:33 +0200 | [diff] [blame] | 972 | } |
| 973 | xapp.Logger.Debug("SUBS-SubReq: Handling (e2t response %s) %s", typeofSubsMessage(subRfMsg), idstring(nil, trans, subs, parentTrans)) |
| 974 | } else { |
| 975 | 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] | 976 | } |
| 977 | |
Juha Hyttinen | 429cfe6 | 2020-03-31 11:23:02 +0300 | [diff] [blame] | 978 | //Now RemoveFromSubscription in here to avoid race conditions (mostly concerns delete) |
| 979 | if valid == false { |
Markku Virtanen | fe2cdab | 2021-05-21 10:59:29 +0000 | [diff] [blame] | 980 | c.registry.RemoveFromSubscription(subs, parentTrans, waitRouteCleanup_ms, c) |
Juha Hyttinen | 429cfe6 | 2020-03-31 11:23:02 +0300 | [diff] [blame] | 981 | } |
Anssi Mannila | c92b421 | 2020-12-07 14:59:34 +0200 | [diff] [blame] | 982 | |
| 983 | c.UpdateSubscriptionInDB(subs, removeSubscriptionFromDb) |
Juha Hyttinen | 83ada00 | 2020-01-30 10:36:33 +0200 | [diff] [blame] | 984 | parentTrans.SendEvent(subRfMsg, 0) |
Juha Hyttinen | 422d018 | 2020-01-17 13:37:05 +0200 | [diff] [blame] | 985 | } |
| 986 | |
| 987 | //------------------------------------------------------------------- |
| 988 | // SUBS DELETE Handling |
| 989 | //------------------------------------------------------------------- |
Juha Hyttinen | 3944a22 | 2020-01-24 11:51:46 +0200 | [diff] [blame] | 990 | |
Juha Hyttinen | 83ada00 | 2020-01-30 10:36:33 +0200 | [diff] [blame] | 991 | func (c *Control) handleSubscriptionDelete(subs *Subscription, parentTrans *TransactionXapp) { |
Juha Hyttinen | 422d018 | 2020-01-17 13:37:05 +0200 | [diff] [blame] | 992 | |
Juha Hyttinen | 83ada00 | 2020-01-30 10:36:33 +0200 | [diff] [blame] | 993 | trans := c.tracker.NewSubsTransaction(subs) |
Juha Hyttinen | 422d018 | 2020-01-17 13:37:05 +0200 | [diff] [blame] | 994 | subs.WaitTransactionTurn(trans) |
| 995 | defer subs.ReleaseTransactionTurn(trans) |
| 996 | defer trans.Release() |
| 997 | |
Juha Hyttinen | 83ada00 | 2020-01-30 10:36:33 +0200 | [diff] [blame] | 998 | xapp.Logger.Debug("SUBS-SubDelReq: Handling %s", idstring(nil, trans, subs, parentTrans)) |
Juha Hyttinen | 422d018 | 2020-01-17 13:37:05 +0200 | [diff] [blame] | 999 | |
Juha Hyttinen | 3944a22 | 2020-01-24 11:51:46 +0200 | [diff] [blame] | 1000 | subs.mutex.Lock() |
Anssi Mannila | 4abf180 | 2021-01-28 13:06:46 +0200 | [diff] [blame] | 1001 | |
Juha Hyttinen | 3944a22 | 2020-01-24 11:51:46 +0200 | [diff] [blame] | 1002 | if subs.valid && subs.EpList.HasEndpoint(parentTrans.GetEndpoint()) && subs.EpList.Size() == 1 { |
| 1003 | subs.valid = false |
| 1004 | subs.mutex.Unlock() |
| 1005 | c.sendE2TSubscriptionDeleteRequest(subs, trans, parentTrans) |
| 1006 | } else { |
| 1007 | subs.mutex.Unlock() |
| 1008 | } |
Juha Hyttinen | 429cfe6 | 2020-03-31 11:23:02 +0300 | [diff] [blame] | 1009 | //Now RemoveFromSubscription in here to avoid race conditions (mostly concerns delete) |
| 1010 | // If parallel deletes ongoing both might pass earlier sendE2TSubscriptionDeleteRequest(...) if |
| 1011 | // RemoveFromSubscription locates in caller side (now in handleXAPPSubscriptionDeleteRequest(...)) |
Markku Virtanen | fe2cdab | 2021-05-21 10:59:29 +0000 | [diff] [blame] | 1012 | c.registry.RemoveFromSubscription(subs, parentTrans, waitRouteCleanup_ms, c) |
Anssi Mannila | c92b421 | 2020-12-07 14:59:34 +0200 | [diff] [blame] | 1013 | c.registry.UpdateSubscriptionToDb(subs, c) |
Juha Hyttinen | 47942b4 | 2020-02-27 10:41:43 +0200 | [diff] [blame] | 1014 | parentTrans.SendEvent(nil, 0) |
Juha Hyttinen | 422d018 | 2020-01-17 13:37:05 +0200 | [diff] [blame] | 1015 | } |
| 1016 | |
| 1017 | //------------------------------------------------------------------- |
| 1018 | // send to E2T Subscription Request |
| 1019 | //------------------------------------------------------------------- |
Juha Hyttinen | 83ada00 | 2020-01-30 10:36:33 +0200 | [diff] [blame] | 1020 | func (c *Control) sendE2TSubscriptionRequest(subs *Subscription, trans *TransactionSubs, parentTrans *TransactionXapp) interface{} { |
Juha Hyttinen | 422d018 | 2020-01-17 13:37:05 +0200 | [diff] [blame] | 1021 | var err error |
| 1022 | var event interface{} = nil |
| 1023 | var timedOut bool = false |
Konstantinos Archangelof | 26dfa71 | 2021-06-04 12:10:26 +0000 | [diff] [blame] | 1024 | const ricRequestorId = 123 |
Juha Hyttinen | 422d018 | 2020-01-17 13:37:05 +0200 | [diff] [blame] | 1025 | |
| 1026 | subReqMsg := subs.SubReqMsg |
Juha Hyttinen | 83ada00 | 2020-01-30 10:36:33 +0200 | [diff] [blame] | 1027 | subReqMsg.RequestId = subs.GetReqId().RequestId |
Konstantinos Archangelof | 26dfa71 | 2021-06-04 12:10:26 +0000 | [diff] [blame] | 1028 | subReqMsg.RequestId.Id = ricRequestorId |
Juha Hyttinen | 422d018 | 2020-01-17 13:37:05 +0200 | [diff] [blame] | 1029 | trans.Mtype, trans.Payload, err = c.e2ap.PackSubscriptionRequest(subReqMsg) |
| 1030 | if err != nil { |
Juha Hyttinen | 83ada00 | 2020-01-30 10:36:33 +0200 | [diff] [blame] | 1031 | xapp.Logger.Error("SUBS-SubReq: %s", idstring(err, trans, subs, parentTrans)) |
Juha Hyttinen | 422d018 | 2020-01-17 13:37:05 +0200 | [diff] [blame] | 1032 | return event |
| 1033 | } |
| 1034 | |
Anssi Mannila | c92b421 | 2020-12-07 14:59:34 +0200 | [diff] [blame] | 1035 | // Write uncompleted subscrition in db. If no response for subscrition it need to be re-processed (deleted) after restart |
| 1036 | c.WriteSubscriptionToDb(subs) |
Markku Virtanen | fe2cdab | 2021-05-21 10:59:29 +0000 | [diff] [blame] | 1037 | |
Juha Hyttinen | 422d018 | 2020-01-17 13:37:05 +0200 | [diff] [blame] | 1038 | for retries := uint64(0); retries < e2tMaxSubReqTryCount; retries++ { |
Juha Hyttinen | 83ada00 | 2020-01-30 10:36:33 +0200 | [diff] [blame] | 1039 | desc := fmt.Sprintf("(retry %d)", retries) |
Anssi Mannila | 4abf180 | 2021-01-28 13:06:46 +0200 | [diff] [blame] | 1040 | if retries == 0 { |
| 1041 | c.UpdateCounter(cSubReqToE2) |
| 1042 | } else { |
| 1043 | c.UpdateCounter(cSubReReqToE2) |
| 1044 | } |
Juha Hyttinen | 83ada00 | 2020-01-30 10:36:33 +0200 | [diff] [blame] | 1045 | c.rmrSendToE2T(desc, subs, trans) |
Anssi Mannila | c92b421 | 2020-12-07 14:59:34 +0200 | [diff] [blame] | 1046 | if subs.DoNotWaitSubResp == false { |
| 1047 | event, timedOut = trans.WaitEvent(e2tSubReqTimeout) |
| 1048 | if timedOut { |
Anssi Mannila | 4abf180 | 2021-01-28 13:06:46 +0200 | [diff] [blame] | 1049 | c.UpdateCounter(cSubReqTimerExpiry) |
Anssi Mannila | c92b421 | 2020-12-07 14:59:34 +0200 | [diff] [blame] | 1050 | continue |
| 1051 | } |
| 1052 | } else { |
| 1053 | // Simulating case where subscrition request has been sent but response has not been received before restart |
| 1054 | event = &SubmgrRestartTestEvent{} |
Juha Hyttinen | 422d018 | 2020-01-17 13:37:05 +0200 | [diff] [blame] | 1055 | } |
| 1056 | break |
| 1057 | } |
Juha Hyttinen | 83ada00 | 2020-01-30 10:36:33 +0200 | [diff] [blame] | 1058 | 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] | 1059 | return event |
| 1060 | } |
| 1061 | |
| 1062 | //------------------------------------------------------------------- |
| 1063 | // send to E2T Subscription Delete Request |
| 1064 | //------------------------------------------------------------------- |
| 1065 | |
Juha Hyttinen | 83ada00 | 2020-01-30 10:36:33 +0200 | [diff] [blame] | 1066 | func (c *Control) sendE2TSubscriptionDeleteRequest(subs *Subscription, trans *TransactionSubs, parentTrans *TransactionXapp) interface{} { |
Juha Hyttinen | 422d018 | 2020-01-17 13:37:05 +0200 | [diff] [blame] | 1067 | var err error |
| 1068 | var event interface{} |
| 1069 | var timedOut bool |
Konstantinos Archangelof | 26dfa71 | 2021-06-04 12:10:26 +0000 | [diff] [blame] | 1070 | const ricRequestorId = 123 |
Juha Hyttinen | 422d018 | 2020-01-17 13:37:05 +0200 | [diff] [blame] | 1071 | |
| 1072 | subDelReqMsg := &e2ap.E2APSubscriptionDeleteRequest{} |
Juha Hyttinen | 83ada00 | 2020-01-30 10:36:33 +0200 | [diff] [blame] | 1073 | subDelReqMsg.RequestId = subs.GetReqId().RequestId |
Konstantinos Archangelof | 26dfa71 | 2021-06-04 12:10:26 +0000 | [diff] [blame] | 1074 | subDelReqMsg.RequestId.Id = ricRequestorId |
Juha Hyttinen | af91f97 | 2020-01-24 08:38:47 +0200 | [diff] [blame] | 1075 | subDelReqMsg.FunctionId = subs.SubReqMsg.FunctionId |
Juha Hyttinen | 422d018 | 2020-01-17 13:37:05 +0200 | [diff] [blame] | 1076 | trans.Mtype, trans.Payload, err = c.e2ap.PackSubscriptionDeleteRequest(subDelReqMsg) |
| 1077 | if err != nil { |
Juha Hyttinen | 83ada00 | 2020-01-30 10:36:33 +0200 | [diff] [blame] | 1078 | xapp.Logger.Error("SUBS-SubDelReq: %s", idstring(err, trans, subs, parentTrans)) |
Juha Hyttinen | 422d018 | 2020-01-17 13:37:05 +0200 | [diff] [blame] | 1079 | return event |
| 1080 | } |
| 1081 | |
| 1082 | for retries := uint64(0); retries < e2tMaxSubDelReqTryCount; retries++ { |
Juha Hyttinen | 83ada00 | 2020-01-30 10:36:33 +0200 | [diff] [blame] | 1083 | desc := fmt.Sprintf("(retry %d)", retries) |
Anssi Mannila | 4abf180 | 2021-01-28 13:06:46 +0200 | [diff] [blame] | 1084 | if retries == 0 { |
| 1085 | c.UpdateCounter(cSubDelReqToE2) |
| 1086 | } else { |
| 1087 | c.UpdateCounter(cSubDelReReqToE2) |
| 1088 | } |
Juha Hyttinen | 83ada00 | 2020-01-30 10:36:33 +0200 | [diff] [blame] | 1089 | c.rmrSendToE2T(desc, subs, trans) |
Juha Hyttinen | 422d018 | 2020-01-17 13:37:05 +0200 | [diff] [blame] | 1090 | event, timedOut = trans.WaitEvent(e2tSubDelReqTime) |
| 1091 | if timedOut { |
Anssi Mannila | 4abf180 | 2021-01-28 13:06:46 +0200 | [diff] [blame] | 1092 | c.UpdateCounter(cSubDelReqTimerExpiry) |
Juha Hyttinen | 422d018 | 2020-01-17 13:37:05 +0200 | [diff] [blame] | 1093 | continue |
| 1094 | } |
| 1095 | break |
| 1096 | } |
Juha Hyttinen | 83ada00 | 2020-01-30 10:36:33 +0200 | [diff] [blame] | 1097 | 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] | 1098 | return event |
| 1099 | } |
| 1100 | |
| 1101 | //------------------------------------------------------------------- |
Anssi Mannila | 4abf180 | 2021-01-28 13:06:46 +0200 | [diff] [blame] | 1102 | // handle from E2T Subscription Response |
Juha Hyttinen | 422d018 | 2020-01-17 13:37:05 +0200 | [diff] [blame] | 1103 | //------------------------------------------------------------------- |
Juha Hyttinen | 9dc5adc | 2020-08-13 10:02:40 +0300 | [diff] [blame] | 1104 | func (c *Control) handleE2TSubscriptionResponse(params *xapp.RMRParams) { |
Juha Hyttinen | 83ada00 | 2020-01-30 10:36:33 +0200 | [diff] [blame] | 1105 | xapp.Logger.Info("MSG from E2T: %s", params.String()) |
Anssi Mannila | 4abf180 | 2021-01-28 13:06:46 +0200 | [diff] [blame] | 1106 | c.UpdateCounter(cSubRespFromE2) |
Anssi Mannila | 5112239 | 2021-05-25 11:51:31 +0300 | [diff] [blame] | 1107 | |
Juha Hyttinen | 422d018 | 2020-01-17 13:37:05 +0200 | [diff] [blame] | 1108 | subRespMsg, err := c.e2ap.UnpackSubscriptionResponse(params.Payload) |
| 1109 | if err != nil { |
Juha Hyttinen | 83ada00 | 2020-01-30 10:36:33 +0200 | [diff] [blame] | 1110 | xapp.Logger.Error("MSG-SubResp %s", idstring(err, params)) |
Juha Hyttinen | 422d018 | 2020-01-17 13:37:05 +0200 | [diff] [blame] | 1111 | return |
| 1112 | } |
Juha Hyttinen | aada645 | 2020-04-07 08:47:58 +0300 | [diff] [blame] | 1113 | subs, err := c.registry.GetSubscriptionFirstMatch([]uint32{subRespMsg.RequestId.InstanceId}) |
Juha Hyttinen | 422d018 | 2020-01-17 13:37:05 +0200 | [diff] [blame] | 1114 | if err != nil { |
Juha Hyttinen | 83ada00 | 2020-01-30 10:36:33 +0200 | [diff] [blame] | 1115 | xapp.Logger.Error("MSG-SubResp: %s", idstring(err, params)) |
Juha Hyttinen | 422d018 | 2020-01-17 13:37:05 +0200 | [diff] [blame] | 1116 | return |
Juha Hyttinen | 31797b4 | 2020-01-16 14:05:01 +0200 | [diff] [blame] | 1117 | } |
| 1118 | trans := subs.GetTransaction() |
| 1119 | if trans == nil { |
Juha Hyttinen | 422d018 | 2020-01-17 13:37:05 +0200 | [diff] [blame] | 1120 | err = fmt.Errorf("Ongoing transaction not found") |
Juha Hyttinen | 83ada00 | 2020-01-30 10:36:33 +0200 | [diff] [blame] | 1121 | xapp.Logger.Error("MSG-SubResp: %s", idstring(err, params, subs)) |
Juha Hyttinen | ff8dccd | 2019-12-10 14:34:07 +0200 | [diff] [blame] | 1122 | return |
Anssi Mannila | 2e99e2f | 2019-12-05 13:57:06 +0200 | [diff] [blame] | 1123 | } |
Juha Hyttinen | 422d018 | 2020-01-17 13:37:05 +0200 | [diff] [blame] | 1124 | sendOk, timedOut := trans.SendEvent(subRespMsg, e2tRecvMsgTimeout) |
| 1125 | if sendOk == false { |
| 1126 | 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] | 1127 | xapp.Logger.Error("MSG-SubResp: %s", idstring(err, trans, subs)) |
Peter Szilagyi | fbc56f9 | 2019-07-23 19:29:46 +0000 | [diff] [blame] | 1128 | } |
Peter Szilagyi | fbc56f9 | 2019-07-23 19:29:46 +0000 | [diff] [blame] | 1129 | return |
kalnagy | 4511475 | 2019-06-18 14:40:39 +0200 | [diff] [blame] | 1130 | } |
| 1131 | |
Juha Hyttinen | 422d018 | 2020-01-17 13:37:05 +0200 | [diff] [blame] | 1132 | //------------------------------------------------------------------- |
| 1133 | // handle from E2T Subscription Failure |
| 1134 | //------------------------------------------------------------------- |
Juha Hyttinen | 9dc5adc | 2020-08-13 10:02:40 +0300 | [diff] [blame] | 1135 | func (c *Control) handleE2TSubscriptionFailure(params *xapp.RMRParams) { |
Juha Hyttinen | 83ada00 | 2020-01-30 10:36:33 +0200 | [diff] [blame] | 1136 | xapp.Logger.Info("MSG from E2T: %s", params.String()) |
Anssi Mannila | 4abf180 | 2021-01-28 13:06:46 +0200 | [diff] [blame] | 1137 | c.UpdateCounter(cSubFailFromE2) |
Juha Hyttinen | 422d018 | 2020-01-17 13:37:05 +0200 | [diff] [blame] | 1138 | subFailMsg, err := c.e2ap.UnpackSubscriptionFailure(params.Payload) |
Peter Szilagyi | fbc56f9 | 2019-07-23 19:29:46 +0000 | [diff] [blame] | 1139 | if err != nil { |
Juha Hyttinen | 83ada00 | 2020-01-30 10:36:33 +0200 | [diff] [blame] | 1140 | xapp.Logger.Error("MSG-SubFail %s", idstring(err, params)) |
Peter Szilagyi | fbc56f9 | 2019-07-23 19:29:46 +0000 | [diff] [blame] | 1141 | return |
| 1142 | } |
Juha Hyttinen | aada645 | 2020-04-07 08:47:58 +0300 | [diff] [blame] | 1143 | subs, err := c.registry.GetSubscriptionFirstMatch([]uint32{subFailMsg.RequestId.InstanceId}) |
Juha Hyttinen | 31797b4 | 2020-01-16 14:05:01 +0200 | [diff] [blame] | 1144 | if err != nil { |
Juha Hyttinen | 83ada00 | 2020-01-30 10:36:33 +0200 | [diff] [blame] | 1145 | xapp.Logger.Error("MSG-SubFail: %s", idstring(err, params)) |
Juha Hyttinen | aafee7f | 2020-01-14 14:54:51 +0200 | [diff] [blame] | 1146 | return |
| 1147 | } |
Juha Hyttinen | 422d018 | 2020-01-17 13:37:05 +0200 | [diff] [blame] | 1148 | trans := subs.GetTransaction() |
| 1149 | if trans == nil { |
| 1150 | err = fmt.Errorf("Ongoing transaction not found") |
Juha Hyttinen | 83ada00 | 2020-01-30 10:36:33 +0200 | [diff] [blame] | 1151 | xapp.Logger.Error("MSG-SubFail: %s", idstring(err, params, subs)) |
Anssi Mannila | 8046c70 | 2020-01-02 13:39:05 +0200 | [diff] [blame] | 1152 | return |
| 1153 | } |
Juha Hyttinen | 422d018 | 2020-01-17 13:37:05 +0200 | [diff] [blame] | 1154 | sendOk, timedOut := trans.SendEvent(subFailMsg, e2tRecvMsgTimeout) |
| 1155 | if sendOk == false { |
| 1156 | 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] | 1157 | xapp.Logger.Error("MSG-SubFail: %s", idstring(err, trans, subs)) |
Juha Hyttinen | aafee7f | 2020-01-14 14:54:51 +0200 | [diff] [blame] | 1158 | } |
Anssi Mannila | 2e99e2f | 2019-12-05 13:57:06 +0200 | [diff] [blame] | 1159 | return |
| 1160 | } |
| 1161 | |
Juha Hyttinen | 422d018 | 2020-01-17 13:37:05 +0200 | [diff] [blame] | 1162 | //------------------------------------------------------------------- |
| 1163 | // handle from E2T Subscription Delete Response |
| 1164 | //------------------------------------------------------------------- |
Juha Hyttinen | 9dc5adc | 2020-08-13 10:02:40 +0300 | [diff] [blame] | 1165 | func (c *Control) handleE2TSubscriptionDeleteResponse(params *xapp.RMRParams) (err error) { |
Juha Hyttinen | 83ada00 | 2020-01-30 10:36:33 +0200 | [diff] [blame] | 1166 | xapp.Logger.Info("MSG from E2T: %s", params.String()) |
Anssi Mannila | 4abf180 | 2021-01-28 13:06:46 +0200 | [diff] [blame] | 1167 | c.UpdateCounter(cSubDelRespFromE2) |
Juha Hyttinen | 422d018 | 2020-01-17 13:37:05 +0200 | [diff] [blame] | 1168 | subDelRespMsg, err := c.e2ap.UnpackSubscriptionDeleteResponse(params.Payload) |
Anssi Mannila | 2e99e2f | 2019-12-05 13:57:06 +0200 | [diff] [blame] | 1169 | if err != nil { |
Juha Hyttinen | 83ada00 | 2020-01-30 10:36:33 +0200 | [diff] [blame] | 1170 | xapp.Logger.Error("MSG-SubDelResp: %s", idstring(err, params)) |
Anssi Mannila | 2e99e2f | 2019-12-05 13:57:06 +0200 | [diff] [blame] | 1171 | return |
| 1172 | } |
Juha Hyttinen | aada645 | 2020-04-07 08:47:58 +0300 | [diff] [blame] | 1173 | subs, err := c.registry.GetSubscriptionFirstMatch([]uint32{subDelRespMsg.RequestId.InstanceId}) |
Juha Hyttinen | 31797b4 | 2020-01-16 14:05:01 +0200 | [diff] [blame] | 1174 | if err != nil { |
Juha Hyttinen | 83ada00 | 2020-01-30 10:36:33 +0200 | [diff] [blame] | 1175 | xapp.Logger.Error("MSG-SubDelResp: %s", idstring(err, params)) |
Juha Hyttinen | 0d064ec | 2020-01-09 09:08:53 +0200 | [diff] [blame] | 1176 | return |
| 1177 | } |
Juha Hyttinen | 422d018 | 2020-01-17 13:37:05 +0200 | [diff] [blame] | 1178 | trans := subs.GetTransaction() |
| 1179 | if trans == nil { |
| 1180 | err = fmt.Errorf("Ongoing transaction not found") |
Juha Hyttinen | 83ada00 | 2020-01-30 10:36:33 +0200 | [diff] [blame] | 1181 | xapp.Logger.Error("MSG-SubDelResp: %s", idstring(err, params, subs)) |
Anssi Mannila | 8046c70 | 2020-01-02 13:39:05 +0200 | [diff] [blame] | 1182 | return |
Anssi Mannila | 2e99e2f | 2019-12-05 13:57:06 +0200 | [diff] [blame] | 1183 | } |
Juha Hyttinen | 422d018 | 2020-01-17 13:37:05 +0200 | [diff] [blame] | 1184 | sendOk, timedOut := trans.SendEvent(subDelRespMsg, e2tRecvMsgTimeout) |
| 1185 | if sendOk == false { |
| 1186 | 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] | 1187 | xapp.Logger.Error("MSG-SubDelResp: %s", idstring(err, trans, subs)) |
Juha Hyttinen | 60bfcf9 | 2020-01-14 15:14:24 +0200 | [diff] [blame] | 1188 | } |
Anssi Mannila | 2e99e2f | 2019-12-05 13:57:06 +0200 | [diff] [blame] | 1189 | return |
| 1190 | } |
| 1191 | |
Juha Hyttinen | 422d018 | 2020-01-17 13:37:05 +0200 | [diff] [blame] | 1192 | //------------------------------------------------------------------- |
| 1193 | // handle from E2T Subscription Delete Failure |
| 1194 | //------------------------------------------------------------------- |
Juha Hyttinen | 9dc5adc | 2020-08-13 10:02:40 +0300 | [diff] [blame] | 1195 | func (c *Control) handleE2TSubscriptionDeleteFailure(params *xapp.RMRParams) { |
Juha Hyttinen | 83ada00 | 2020-01-30 10:36:33 +0200 | [diff] [blame] | 1196 | xapp.Logger.Info("MSG from E2T: %s", params.String()) |
Anssi Mannila | 4abf180 | 2021-01-28 13:06:46 +0200 | [diff] [blame] | 1197 | c.UpdateCounter(cSubDelFailFromE2) |
Juha Hyttinen | 422d018 | 2020-01-17 13:37:05 +0200 | [diff] [blame] | 1198 | subDelFailMsg, err := c.e2ap.UnpackSubscriptionDeleteFailure(params.Payload) |
Juha Hyttinen | 31797b4 | 2020-01-16 14:05:01 +0200 | [diff] [blame] | 1199 | if err != nil { |
Juha Hyttinen | 83ada00 | 2020-01-30 10:36:33 +0200 | [diff] [blame] | 1200 | xapp.Logger.Error("MSG-SubDelFail: %s", idstring(err, params)) |
Anssi Mannila | f1d0eb6 | 2019-12-17 15:29:55 +0200 | [diff] [blame] | 1201 | return |
| 1202 | } |
Juha Hyttinen | aada645 | 2020-04-07 08:47:58 +0300 | [diff] [blame] | 1203 | subs, err := c.registry.GetSubscriptionFirstMatch([]uint32{subDelFailMsg.RequestId.InstanceId}) |
Anssi Mannila | 8046c70 | 2020-01-02 13:39:05 +0200 | [diff] [blame] | 1204 | if err != nil { |
Juha Hyttinen | 83ada00 | 2020-01-30 10:36:33 +0200 | [diff] [blame] | 1205 | xapp.Logger.Error("MSG-SubDelFail: %s", idstring(err, params)) |
Anssi Mannila | 8046c70 | 2020-01-02 13:39:05 +0200 | [diff] [blame] | 1206 | return |
| 1207 | } |
Juha Hyttinen | 422d018 | 2020-01-17 13:37:05 +0200 | [diff] [blame] | 1208 | trans := subs.GetTransaction() |
| 1209 | if trans == nil { |
| 1210 | err = fmt.Errorf("Ongoing transaction not found") |
Juha Hyttinen | 83ada00 | 2020-01-30 10:36:33 +0200 | [diff] [blame] | 1211 | xapp.Logger.Error("MSG-SubDelFail: %s", idstring(err, params, subs)) |
Juha Hyttinen | 86a4620 | 2020-01-14 12:49:09 +0200 | [diff] [blame] | 1212 | return |
| 1213 | } |
Juha Hyttinen | 422d018 | 2020-01-17 13:37:05 +0200 | [diff] [blame] | 1214 | sendOk, timedOut := trans.SendEvent(subDelFailMsg, e2tRecvMsgTimeout) |
| 1215 | if sendOk == false { |
| 1216 | 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] | 1217 | xapp.Logger.Error("MSG-SubDelFail: %s", idstring(err, trans, subs)) |
Anssi Mannila | 8046c70 | 2020-01-02 13:39:05 +0200 | [diff] [blame] | 1218 | } |
kalnagy | 93cc3e2 | 2019-09-19 11:29:29 +0200 | [diff] [blame] | 1219 | return |
| 1220 | } |
| 1221 | |
Juha Hyttinen | 422d018 | 2020-01-17 13:37:05 +0200 | [diff] [blame] | 1222 | //------------------------------------------------------------------- |
| 1223 | // |
| 1224 | //------------------------------------------------------------------- |
| 1225 | func typeofSubsMessage(v interface{}) string { |
| 1226 | if v == nil { |
| 1227 | return "NIL" |
kalnagy | 93cc3e2 | 2019-09-19 11:29:29 +0200 | [diff] [blame] | 1228 | } |
Juha Hyttinen | 422d018 | 2020-01-17 13:37:05 +0200 | [diff] [blame] | 1229 | switch v.(type) { |
Anssi Mannila | 5112239 | 2021-05-25 11:51:31 +0300 | [diff] [blame] | 1230 | //case *e2ap.E2APSubscriptionRequest: |
| 1231 | // return "SubReq" |
Juha Hyttinen | 422d018 | 2020-01-17 13:37:05 +0200 | [diff] [blame] | 1232 | case *e2ap.E2APSubscriptionResponse: |
| 1233 | return "SubResp" |
| 1234 | case *e2ap.E2APSubscriptionFailure: |
| 1235 | return "SubFail" |
Anssi Mannila | 5112239 | 2021-05-25 11:51:31 +0300 | [diff] [blame] | 1236 | //case *e2ap.E2APSubscriptionDeleteRequest: |
| 1237 | // return "SubDelReq" |
Juha Hyttinen | 422d018 | 2020-01-17 13:37:05 +0200 | [diff] [blame] | 1238 | case *e2ap.E2APSubscriptionDeleteResponse: |
| 1239 | return "SubDelResp" |
| 1240 | case *e2ap.E2APSubscriptionDeleteFailure: |
| 1241 | return "SubDelFail" |
| 1242 | default: |
| 1243 | return "Unknown" |
Juha Hyttinen | 31797b4 | 2020-01-16 14:05:01 +0200 | [diff] [blame] | 1244 | } |
Anssi Mannila | f1d0eb6 | 2019-12-17 15:29:55 +0200 | [diff] [blame] | 1245 | } |
Anssi Mannila | c92b421 | 2020-12-07 14:59:34 +0200 | [diff] [blame] | 1246 | |
| 1247 | //------------------------------------------------------------------- |
| 1248 | // |
| 1249 | //------------------------------------------------------------------- |
| 1250 | func (c *Control) WriteSubscriptionToDb(subs *Subscription) { |
| 1251 | xapp.Logger.Debug("WriteSubscriptionToDb() subId = %v", subs.ReqId.InstanceId) |
| 1252 | err := c.WriteSubscriptionToSdl(subs.ReqId.InstanceId, subs) |
| 1253 | if err != nil { |
| 1254 | xapp.Logger.Error("%v", err) |
| 1255 | } |
| 1256 | } |
| 1257 | |
| 1258 | //------------------------------------------------------------------- |
| 1259 | // |
| 1260 | //------------------------------------------------------------------- |
| 1261 | func (c *Control) UpdateSubscriptionInDB(subs *Subscription, removeSubscriptionFromDb bool) { |
| 1262 | |
| 1263 | if removeSubscriptionFromDb == true { |
| 1264 | // Subscription was written in db already when subscription request was sent to BTS, except for merged request |
| 1265 | c.RemoveSubscriptionFromDb(subs) |
| 1266 | } else { |
| 1267 | // Update is needed for successful response and merge case here |
| 1268 | if subs.RetryFromXapp == false { |
| 1269 | c.WriteSubscriptionToDb(subs) |
| 1270 | } |
| 1271 | } |
| 1272 | subs.RetryFromXapp = false |
| 1273 | } |
| 1274 | |
| 1275 | //------------------------------------------------------------------- |
| 1276 | // |
| 1277 | //------------------------------------------------------------------- |
| 1278 | func (c *Control) RemoveSubscriptionFromDb(subs *Subscription) { |
| 1279 | xapp.Logger.Debug("RemoveSubscriptionFromDb() subId = %v", subs.ReqId.InstanceId) |
| 1280 | err := c.RemoveSubscriptionFromSdl(subs.ReqId.InstanceId) |
| 1281 | if err != nil { |
| 1282 | xapp.Logger.Error("%v", err) |
| 1283 | } |
| 1284 | } |
| 1285 | |
Konstantinos Archangelof | 268d715 | 2021-06-14 12:24:00 +0300 | [diff] [blame] | 1286 | //------------------------------------------------------------------- |
| 1287 | // |
| 1288 | //------------------------------------------------------------------- |
| 1289 | func (c *Control) WriteRESTSubscriptionToDb(restSubId string, restSubs *RESTSubscription) { |
| 1290 | xapp.Logger.Debug("WriteRESTSubscriptionToDb() restSubId = %s", restSubId) |
| 1291 | err := c.WriteRESTSubscriptionToSdl(restSubId, restSubs) |
| 1292 | if err != nil { |
| 1293 | xapp.Logger.Error("%v", err) |
| 1294 | } |
| 1295 | } |
| 1296 | |
| 1297 | //------------------------------------------------------------------- |
| 1298 | // |
| 1299 | //------------------------------------------------------------------- |
| 1300 | func (c *Control) UpdateRESTSubscriptionInDB(restSubId string, restSubs *RESTSubscription, removeRestSubscriptionFromDb bool) { |
| 1301 | |
| 1302 | if removeRestSubscriptionFromDb == true { |
| 1303 | // Subscription was written in db already when subscription request was sent to BTS, except for merged request |
| 1304 | c.RemoveRESTSubscriptionFromDb(restSubId) |
| 1305 | } else { |
| 1306 | c.WriteRESTSubscriptionToDb(restSubId, restSubs) |
| 1307 | } |
| 1308 | } |
| 1309 | |
| 1310 | //------------------------------------------------------------------- |
| 1311 | // |
| 1312 | //------------------------------------------------------------------- |
| 1313 | func (c *Control) RemoveRESTSubscriptionFromDb(restSubId string) { |
| 1314 | xapp.Logger.Debug("RemoveRESTSubscriptionFromDb() restSubId = %s", restSubId) |
| 1315 | err := c.RemoveRESTSubscriptionFromSdl(restSubId) |
| 1316 | if err != nil { |
| 1317 | xapp.Logger.Error("%v", err) |
| 1318 | } |
| 1319 | } |
| 1320 | |
Anssi Mannila | c92b421 | 2020-12-07 14:59:34 +0200 | [diff] [blame] | 1321 | func (c *Control) SendSubscriptionDeleteReq(subs *Subscription) { |
| 1322 | |
Konstantinos Archangelof | 26dfa71 | 2021-06-04 12:10:26 +0000 | [diff] [blame] | 1323 | const ricRequestorId = 123 |
Anssi Mannila | c92b421 | 2020-12-07 14:59:34 +0200 | [diff] [blame] | 1324 | xapp.Logger.Debug("Sending subscription delete due to restart. subId = %v", subs.ReqId.InstanceId) |
| 1325 | |
| 1326 | // Send delete for every endpoint in the subscription |
| 1327 | subDelReqMsg := &e2ap.E2APSubscriptionDeleteRequest{} |
| 1328 | subDelReqMsg.RequestId = subs.GetReqId().RequestId |
Konstantinos Archangelof | 26dfa71 | 2021-06-04 12:10:26 +0000 | [diff] [blame] | 1329 | subDelReqMsg.RequestId.Id = ricRequestorId |
Anssi Mannila | c92b421 | 2020-12-07 14:59:34 +0200 | [diff] [blame] | 1330 | subDelReqMsg.FunctionId = subs.SubReqMsg.FunctionId |
| 1331 | mType, payload, err := c.e2ap.PackSubscriptionDeleteRequest(subDelReqMsg) |
| 1332 | if err != nil { |
| 1333 | xapp.Logger.Error("SendSubscriptionDeleteReq() %s", idstring(err)) |
| 1334 | return |
| 1335 | } |
| 1336 | for _, endPoint := range subs.EpList.Endpoints { |
| 1337 | params := &xapp.RMRParams{} |
| 1338 | params.Mtype = mType |
| 1339 | params.SubId = int(subs.GetReqId().InstanceId) |
| 1340 | params.Xid = "" |
| 1341 | params.Meid = subs.Meid |
| 1342 | params.Src = endPoint.String() |
| 1343 | params.PayloadLen = len(payload.Buf) |
| 1344 | params.Payload = payload.Buf |
| 1345 | params.Mbuf = nil |
Anssi Mannila | c92b421 | 2020-12-07 14:59:34 +0200 | [diff] [blame] | 1346 | subs.DeleteFromDb = true |
| 1347 | c.handleXAPPSubscriptionDeleteRequest(params) |
| 1348 | } |
| 1349 | } |
Anssi Mannila | de457a1 | 2021-06-02 16:19:48 +0300 | [diff] [blame] | 1350 | |
| 1351 | func (c *Control) PrintRESTSubscriptionRequest(p *models.SubscriptionParams) { |
| 1352 | |
| 1353 | fmt.Println("CRESTSubscriptionRequest") |
Markku Virtanen | 987f8b1 | 2021-06-10 15:05:02 +0300 | [diff] [blame] | 1354 | |
| 1355 | if p.SubscriptionID != "" { |
| 1356 | fmt.Println(" SubscriptionID = ", p.SubscriptionID) |
| 1357 | } else { |
| 1358 | fmt.Println(" SubscriptionID = ''") |
| 1359 | } |
| 1360 | |
Anssi Mannila | de457a1 | 2021-06-02 16:19:48 +0300 | [diff] [blame] | 1361 | fmt.Printf(" ClientEndpoint.Host = %s\n", p.ClientEndpoint.Host) |
| 1362 | |
| 1363 | if p.ClientEndpoint.HTTPPort != nil { |
| 1364 | fmt.Printf(" ClientEndpoint.HTTPPort = %v\n", *p.ClientEndpoint.HTTPPort) |
| 1365 | } else { |
| 1366 | fmt.Println(" ClientEndpoint.HTTPPort = nil") |
| 1367 | } |
| 1368 | |
| 1369 | if p.ClientEndpoint.RMRPort != nil { |
| 1370 | fmt.Printf(" ClientEndpoint.RMRPort = %v\n", *p.ClientEndpoint.RMRPort) |
| 1371 | } else { |
| 1372 | fmt.Println(" ClientEndpoint.RMRPort = nil") |
| 1373 | } |
| 1374 | |
| 1375 | if p.Meid != nil { |
| 1376 | fmt.Printf(" Meid = %s\n", *p.Meid) |
| 1377 | } else { |
| 1378 | fmt.Println(" Meid = nil") |
| 1379 | } |
| 1380 | |
| 1381 | for _, subscriptionDetail := range p.SubscriptionDetails { |
| 1382 | if p.RANFunctionID != nil { |
| 1383 | fmt.Printf(" RANFunctionID = %v\n", *p.RANFunctionID) |
| 1384 | } else { |
| 1385 | fmt.Println(" RANFunctionID = nil") |
| 1386 | } |
Konstantinos Archangelof | e93b00f | 2021-06-03 10:00:19 +0000 | [diff] [blame] | 1387 | fmt.Printf(" SubscriptionDetail.XappEventInstanceID = %v\n", *subscriptionDetail.XappEventInstanceID) |
Konstantinos Archangelof | bd9c98e | 2021-06-07 17:32:10 +0000 | [diff] [blame] | 1388 | fmt.Printf(" SubscriptionDetail.EventTriggers = %v\n", subscriptionDetail.EventTriggers) |
Anssi Mannila | de457a1 | 2021-06-02 16:19:48 +0300 | [diff] [blame] | 1389 | |
| 1390 | for _, actionToBeSetup := range subscriptionDetail.ActionToBeSetupList { |
| 1391 | fmt.Printf(" SubscriptionDetail.ActionToBeSetup.ActionID = %v\n", *actionToBeSetup.ActionID) |
| 1392 | fmt.Printf(" SubscriptionDetail.ActionToBeSetup.ActionType = %s\n", *actionToBeSetup.ActionType) |
Konstantinos Archangelof | bd9c98e | 2021-06-07 17:32:10 +0000 | [diff] [blame] | 1393 | fmt.Printf(" SubscriptionDetail.ActionToBeSetup.ActionDefinition = %v\n", actionToBeSetup.ActionDefinition) |
Anssi Mannila | de457a1 | 2021-06-02 16:19:48 +0300 | [diff] [blame] | 1394 | |
Anssi Mannila | de457a1 | 2021-06-02 16:19:48 +0300 | [diff] [blame] | 1395 | if actionToBeSetup.SubsequentAction != nil { |
| 1396 | fmt.Printf(" SubscriptionDetail.ActionToBeSetup.SubsequentAction.SubsequentActionType = %s\n", *actionToBeSetup.SubsequentAction.SubsequentActionType) |
| 1397 | fmt.Printf(" SubscriptionDetail.ActionToBeSetup..SubsequentAction.TimeToWait = %s\n", *actionToBeSetup.SubsequentAction.TimeToWait) |
| 1398 | } else { |
| 1399 | fmt.Println(" SubscriptionDetail.ActionToBeSetup.SubsequentAction = nil") |
| 1400 | } |
| 1401 | } |
| 1402 | } |
| 1403 | } |