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