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