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" |
kalnagy | 1455c85 | 2019-10-21 13:06:23 +0200 | [diff] [blame] | 37 | "github.com/spf13/viper" |
kalnagy | 4511475 | 2019-06-18 14:40:39 +0200 | [diff] [blame] | 38 | ) |
| 39 | |
Juha Hyttinen | e406a34 | 2020-01-13 13:02:26 +0200 | [diff] [blame] | 40 | //----------------------------------------------------------------------------- |
| 41 | // |
| 42 | //----------------------------------------------------------------------------- |
| 43 | |
Juha Hyttinen | 5f8ffa0 | 2020-02-06 15:28:59 +0200 | [diff] [blame] | 44 | func idstring(err error, entries ...fmt.Stringer) string { |
| 45 | var retval string = "" |
| 46 | var filler string = "" |
| 47 | for _, entry := range entries { |
| 48 | retval += filler + entry.String() |
| 49 | filler = " " |
| 50 | } |
| 51 | if err != nil { |
| 52 | retval += filler + "err(" + err.Error() + ")" |
| 53 | filler = " " |
Juha Hyttinen | 5f8ffa0 | 2020-02-06 15:28:59 +0200 | [diff] [blame] | 54 | } |
| 55 | return retval |
| 56 | } |
| 57 | |
| 58 | //----------------------------------------------------------------------------- |
| 59 | // |
| 60 | //----------------------------------------------------------------------------- |
| 61 | |
Anssi Mannila | 2f26fb2 | 2020-12-07 08:32:13 +0200 | [diff] [blame] | 62 | var e2tSubReqTimeout time.Duration |
| 63 | var e2tSubDelReqTime time.Duration |
| 64 | var e2tRecvMsgTimeout time.Duration |
| 65 | var e2tMaxSubReqTryCount uint64 // Initial try + retry |
| 66 | var e2tMaxSubDelReqTryCount uint64 // Initial try + retry |
Anssi Mannila | c92b421 | 2020-12-07 14:59:34 +0200 | [diff] [blame] | 67 | var readSubsFromDb string |
Anssi Mannila | 2e99e2f | 2019-12-05 13:57:06 +0200 | [diff] [blame] | 68 | |
kalnagy | 4511475 | 2019-06-18 14:40:39 +0200 | [diff] [blame] | 69 | type Control struct { |
Juha Hyttinen | 9dc5adc | 2020-08-13 10:02:40 +0300 | [diff] [blame] | 70 | *xapp.RMRClient |
Juha Hyttinen | 5f8ffa0 | 2020-02-06 15:28:59 +0200 | [diff] [blame] | 71 | e2ap *E2ap |
| 72 | registry *Registry |
| 73 | tracker *Tracker |
Anssi Mannila | c92b421 | 2020-12-07 14:59:34 +0200 | [diff] [blame] | 74 | db Sdlnterface |
Juha Hyttinen | c9eb08a | 2020-02-28 08:53:33 +0200 | [diff] [blame] | 75 | //subscriber *xapp.Subscriber |
Anssi Mannila | c92b421 | 2020-12-07 14:59:34 +0200 | [diff] [blame] | 76 | CntRecvMsg uint64 |
| 77 | ResetTestFlag bool |
Anssi Mannila | 4abf180 | 2021-01-28 13:06:46 +0200 | [diff] [blame] | 78 | Counters map[string]xapp.Counter |
kalnagy | 93cc3e2 | 2019-09-19 11:29:29 +0200 | [diff] [blame] | 79 | } |
| 80 | |
| 81 | type RMRMeid struct { |
Juha Hyttinen | ff8dccd | 2019-12-10 14:34:07 +0200 | [diff] [blame] | 82 | PlmnID string |
| 83 | EnbID string |
Anssi Mannila | 2e99e2f | 2019-12-05 13:57:06 +0200 | [diff] [blame] | 84 | RanName string |
kalnagy | 93cc3e2 | 2019-09-19 11:29:29 +0200 | [diff] [blame] | 85 | } |
| 86 | |
Anssi Mannila | c92b421 | 2020-12-07 14:59:34 +0200 | [diff] [blame] | 87 | type SubmgrRestartTestEvent struct{} |
| 88 | type SubmgrRestartUpEvent struct{} |
| 89 | |
Peter Szilagyi | fbc56f9 | 2019-07-23 19:29:46 +0000 | [diff] [blame] | 90 | func init() { |
Anssi Mannila | 8046c70 | 2020-01-02 13:39:05 +0200 | [diff] [blame] | 91 | xapp.Logger.Info("SUBMGR") |
Peter Szilagyi | fbc56f9 | 2019-07-23 19:29:46 +0000 | [diff] [blame] | 92 | viper.AutomaticEnv() |
| 93 | viper.SetEnvPrefix("submgr") |
| 94 | viper.AllowEmptyEnv(true) |
kalnagy | 4511475 | 2019-06-18 14:40:39 +0200 | [diff] [blame] | 95 | } |
| 96 | |
Juha Hyttinen | ff8dccd | 2019-12-10 14:34:07 +0200 | [diff] [blame] | 97 | func NewControl() *Control { |
Juha Hyttinen | 0388dd9 | 2020-01-09 14:14:16 +0200 | [diff] [blame] | 98 | |
Anssi Mannila | c92b421 | 2020-12-07 14:59:34 +0200 | [diff] [blame] | 99 | transport := httptransport.New(viper.GetString("rtmgr.HostAddr")+":"+viper.GetString("rtmgr.port"), viper.GetString("rtmgr.baseUrl"), []string{"http"}) |
| 100 | rtmgrClient := RtmgrClient{rtClient: rtmgrclient.New(transport, strfmt.Default)} |
| 101 | |
| 102 | registry := new(Registry) |
| 103 | registry.Initialize() |
| 104 | registry.rtmgrClient = &rtmgrClient |
| 105 | |
| 106 | tracker := new(Tracker) |
| 107 | tracker.Init() |
| 108 | |
Anssi Mannila | c92b421 | 2020-12-07 14:59:34 +0200 | [diff] [blame] | 109 | c := &Control{e2ap: new(E2ap), |
| 110 | registry: registry, |
| 111 | tracker: tracker, |
| 112 | db: CreateSdl(), |
| 113 | //subscriber: subscriber, |
Anssi Mannila | 4abf180 | 2021-01-28 13:06:46 +0200 | [diff] [blame] | 114 | Counters: xapp.Metric.RegisterCounterGroup(GetMetricsOpts(), "SUBMGR"), |
Anssi Mannila | c92b421 | 2020-12-07 14:59:34 +0200 | [diff] [blame] | 115 | } |
Anssi Mannila | f6b7804 | 2021-02-18 12:36:59 +0200 | [diff] [blame] | 116 | c.ReadConfigParameters("") |
Anssi Mannila | c92b421 | 2020-12-07 14:59:34 +0200 | [diff] [blame] | 117 | |
| 118 | // Register REST handler for testing support |
| 119 | xapp.Resource.InjectRoute("/ric/v1/test/{testId}", c.TestRestHandler, "POST") |
Abukar Mohamed | fbd4df5 | 2021-03-11 06:13:27 +0000 | [diff] [blame^] | 120 | xapp.Resource.InjectRoute("/ric/v1/symptomdata", c.SymptomDataHandler, "GET") |
Anssi Mannila | c92b421 | 2020-12-07 14:59:34 +0200 | [diff] [blame] | 121 | |
| 122 | go xapp.Subscription.Listen(c.SubscriptionHandler, c.QueryHandler, c.SubscriptionDeleteHandler) |
Anssi Mannila | c92b421 | 2020-12-07 14:59:34 +0200 | [diff] [blame] | 123 | |
| 124 | if readSubsFromDb == "false" { |
| 125 | return c |
| 126 | } |
| 127 | |
| 128 | // Read subscriptions from db |
| 129 | xapp.Logger.Info("Reading subscriptions from db") |
| 130 | subIds, register, err := c.ReadAllSubscriptionsFromSdl() |
| 131 | if err != nil { |
| 132 | xapp.Logger.Error("%v", err) |
| 133 | } else { |
| 134 | c.registry.subIds = subIds |
| 135 | c.registry.register = register |
| 136 | c.HandleUncompletedSubscriptions(register) |
| 137 | } |
| 138 | return c |
| 139 | } |
| 140 | |
Abukar Mohamed | fbd4df5 | 2021-03-11 06:13:27 +0000 | [diff] [blame^] | 141 | func (c *Control) SymptomDataHandler(w http.ResponseWriter, r *http.Request) { |
| 142 | subscriptions, _ := c.registry.QueryHandler() |
| 143 | xapp.Resource.SendSymptomDataJson(w, r, subscriptions, "platform/subscriptions.json") |
| 144 | } |
| 145 | |
Anssi Mannila | c92b421 | 2020-12-07 14:59:34 +0200 | [diff] [blame] | 146 | //------------------------------------------------------------------- |
| 147 | // |
| 148 | //------------------------------------------------------------------- |
Anssi Mannila | f6b7804 | 2021-02-18 12:36:59 +0200 | [diff] [blame] | 149 | func (c *Control) ReadConfigParameters(f string) { |
Anssi Mannila | c92b421 | 2020-12-07 14:59:34 +0200 | [diff] [blame] | 150 | |
Anssi Mannila | 2f26fb2 | 2020-12-07 08:32:13 +0200 | [diff] [blame] | 151 | // viper.GetDuration returns nanoseconds |
| 152 | e2tSubReqTimeout = viper.GetDuration("controls.e2tSubReqTimeout_ms") * 1000000 |
Juha Hyttinen | 57140bc | 2020-12-11 13:03:06 +0200 | [diff] [blame] | 153 | if e2tSubReqTimeout == 0 { |
| 154 | e2tSubReqTimeout = 2000 * 1000000 |
| 155 | } |
Anssi Mannila | 2f26fb2 | 2020-12-07 08:32:13 +0200 | [diff] [blame] | 156 | xapp.Logger.Info("e2tSubReqTimeout %v", e2tSubReqTimeout) |
| 157 | e2tSubDelReqTime = viper.GetDuration("controls.e2tSubDelReqTime_ms") * 1000000 |
Juha Hyttinen | 57140bc | 2020-12-11 13:03:06 +0200 | [diff] [blame] | 158 | if e2tSubDelReqTime == 0 { |
| 159 | e2tSubDelReqTime = 2000 * 1000000 |
| 160 | } |
Anssi Mannila | 2f26fb2 | 2020-12-07 08:32:13 +0200 | [diff] [blame] | 161 | xapp.Logger.Info("e2tSubDelReqTime %v", e2tSubDelReqTime) |
| 162 | e2tRecvMsgTimeout = viper.GetDuration("controls.e2tRecvMsgTimeout_ms") * 1000000 |
Juha Hyttinen | 57140bc | 2020-12-11 13:03:06 +0200 | [diff] [blame] | 163 | if e2tRecvMsgTimeout == 0 { |
| 164 | e2tRecvMsgTimeout = 2000 * 1000000 |
| 165 | } |
Anssi Mannila | 2f26fb2 | 2020-12-07 08:32:13 +0200 | [diff] [blame] | 166 | xapp.Logger.Info("e2tRecvMsgTimeout %v", e2tRecvMsgTimeout) |
| 167 | e2tMaxSubReqTryCount = viper.GetUint64("controls.e2tMaxSubReqTryCount") |
Juha Hyttinen | 57140bc | 2020-12-11 13:03:06 +0200 | [diff] [blame] | 168 | if e2tMaxSubReqTryCount == 0 { |
| 169 | e2tMaxSubReqTryCount = 1 |
| 170 | } |
Anssi Mannila | 2f26fb2 | 2020-12-07 08:32:13 +0200 | [diff] [blame] | 171 | xapp.Logger.Info("e2tMaxSubReqTryCount %v", e2tMaxSubReqTryCount) |
| 172 | e2tMaxSubDelReqTryCount = viper.GetUint64("controls.e2tMaxSubDelReqTryCount") |
Juha Hyttinen | 57140bc | 2020-12-11 13:03:06 +0200 | [diff] [blame] | 173 | if e2tMaxSubDelReqTryCount == 0 { |
| 174 | e2tMaxSubDelReqTryCount = 1 |
| 175 | } |
Anssi Mannila | 2f26fb2 | 2020-12-07 08:32:13 +0200 | [diff] [blame] | 176 | xapp.Logger.Info("e2tMaxSubDelReqTryCount %v", e2tMaxSubDelReqTryCount) |
| 177 | |
Anssi Mannila | c92b421 | 2020-12-07 14:59:34 +0200 | [diff] [blame] | 178 | readSubsFromDb = viper.GetString("controls.readSubsFromDb") |
| 179 | if readSubsFromDb == "" { |
| 180 | readSubsFromDb = "true" |
Juha Hyttinen | 5f8ffa0 | 2020-02-06 15:28:59 +0200 | [diff] [blame] | 181 | } |
Anssi Mannila | c92b421 | 2020-12-07 14:59:34 +0200 | [diff] [blame] | 182 | xapp.Logger.Info("readSubsFromDb %v", readSubsFromDb) |
| 183 | } |
| 184 | |
| 185 | //------------------------------------------------------------------- |
| 186 | // |
| 187 | //------------------------------------------------------------------- |
| 188 | func (c *Control) HandleUncompletedSubscriptions(register map[uint32]*Subscription) { |
| 189 | |
| 190 | xapp.Logger.Debug("HandleUncompletedSubscriptions. len(register) = %v", len(register)) |
| 191 | for subId, subs := range register { |
| 192 | if subs.SubRespRcvd == false { |
| 193 | subs.NoRespToXapp = true |
| 194 | xapp.Logger.Debug("SendSubscriptionDeleteReq. subId = %v", subId) |
| 195 | c.SendSubscriptionDeleteReq(subs) |
| 196 | } |
| 197 | } |
Juha Hyttinen | 5f8ffa0 | 2020-02-06 15:28:59 +0200 | [diff] [blame] | 198 | } |
| 199 | |
| 200 | func (c *Control) ReadyCB(data interface{}) { |
Juha Hyttinen | 9dc5adc | 2020-08-13 10:02:40 +0300 | [diff] [blame] | 201 | if c.RMRClient == nil { |
| 202 | c.RMRClient = xapp.Rmr |
Juha Hyttinen | ff8dccd | 2019-12-10 14:34:07 +0200 | [diff] [blame] | 203 | } |
kalnagy | 4511475 | 2019-06-18 14:40:39 +0200 | [diff] [blame] | 204 | } |
| 205 | |
| 206 | func (c *Control) Run() { |
Juha Hyttinen | 5f8ffa0 | 2020-02-06 15:28:59 +0200 | [diff] [blame] | 207 | xapp.SetReadyCB(c.ReadyCB, nil) |
Anssi Mannila | f6b7804 | 2021-02-18 12:36:59 +0200 | [diff] [blame] | 208 | xapp.AddConfigChangeListener(c.ReadConfigParameters) |
Peter Szilagyi | fbc56f9 | 2019-07-23 19:29:46 +0000 | [diff] [blame] | 209 | xapp.Run(c) |
kalnagy | 4511475 | 2019-06-18 14:40:39 +0200 | [diff] [blame] | 210 | } |
| 211 | |
Juha Hyttinen | c9eb08a | 2020-02-28 08:53:33 +0200 | [diff] [blame] | 212 | //------------------------------------------------------------------- |
| 213 | // |
| 214 | //------------------------------------------------------------------- |
Juha Hyttinen | 429cfe6 | 2020-03-31 11:23:02 +0300 | [diff] [blame] | 215 | func (c *Control) SubscriptionHandler(stype models.SubscriptionType, params interface{}) (*models.SubscriptionResponse, error) { |
Juha Hyttinen | c9eb08a | 2020-02-28 08:53:33 +0200 | [diff] [blame] | 216 | /* |
| 217 | switch p := params.(type) { |
| 218 | case *models.ReportParams: |
| 219 | trans := c.tracker.NewXappTransaction(NewRmrEndpoint(p.ClientEndpoint),"" , 0, &xapp.RMRMeid{RanName: p.Meid}) |
| 220 | if trans == nil { |
| 221 | xapp.Logger.Error("XAPP-SubReq: %s", idstring(fmt.Errorf("transaction not created"), params)) |
| 222 | return |
| 223 | } |
| 224 | defer trans.Release() |
| 225 | case *models.ControlParams: |
| 226 | case *models.PolicyParams: |
| 227 | } |
| 228 | */ |
Juha Hyttinen | 429cfe6 | 2020-03-31 11:23:02 +0300 | [diff] [blame] | 229 | return &models.SubscriptionResponse{}, fmt.Errorf("Subscription rest interface not implemented") |
| 230 | } |
| 231 | |
Anssi Mannila | c92b421 | 2020-12-07 14:59:34 +0200 | [diff] [blame] | 232 | func (c *Control) SubscriptionDeleteHandler(s string) error { |
| 233 | return nil |
Juha Hyttinen | c9eb08a | 2020-02-28 08:53:33 +0200 | [diff] [blame] | 234 | } |
| 235 | |
| 236 | func (c *Control) QueryHandler() (models.SubscriptionList, error) { |
Anssi Mannila | 4c626a2 | 2021-02-11 12:50:48 +0200 | [diff] [blame] | 237 | xapp.Logger.Info("QueryHandler() called") |
| 238 | |
Juha Hyttinen | c9eb08a | 2020-02-28 08:53:33 +0200 | [diff] [blame] | 239 | return c.registry.QueryHandler() |
| 240 | } |
| 241 | |
Anssi Mannila | c92b421 | 2020-12-07 14:59:34 +0200 | [diff] [blame] | 242 | func (c *Control) TestRestHandler(w http.ResponseWriter, r *http.Request) { |
Anssi Mannila | c92b421 | 2020-12-07 14:59:34 +0200 | [diff] [blame] | 243 | xapp.Logger.Info("TestRestHandler() called") |
| 244 | |
| 245 | pathParams := mux.Vars(r) |
| 246 | s := pathParams["testId"] |
| 247 | |
| 248 | // This can be used to delete single subscription from db |
| 249 | if contains := strings.Contains(s, "deletesubid="); contains == true { |
| 250 | var splits = strings.Split(s, "=") |
| 251 | if subId, err := strconv.ParseInt(splits[1], 10, 64); err == nil { |
| 252 | xapp.Logger.Info("RemoveSubscriptionFromSdl() called. subId = %v", subId) |
| 253 | c.RemoveSubscriptionFromSdl(uint32(subId)) |
| 254 | return |
| 255 | } |
| 256 | } |
| 257 | |
| 258 | // This can be used to remove all subscriptions db from |
| 259 | if s == "emptydb" { |
| 260 | xapp.Logger.Info("RemoveAllSubscriptionsFromSdl() called") |
| 261 | c.RemoveAllSubscriptionsFromSdl() |
| 262 | return |
| 263 | } |
| 264 | |
| 265 | // This is meant to cause submgr's restart in testing |
| 266 | if s == "restart" { |
| 267 | xapp.Logger.Info("os.Exit(1) called") |
| 268 | os.Exit(1) |
| 269 | } |
| 270 | |
| 271 | xapp.Logger.Info("Unsupported rest command received %s", s) |
| 272 | } |
| 273 | |
Juha Hyttinen | c9eb08a | 2020-02-28 08:53:33 +0200 | [diff] [blame] | 274 | //------------------------------------------------------------------- |
| 275 | // |
| 276 | //------------------------------------------------------------------- |
| 277 | |
Juha Hyttinen | 83ada00 | 2020-01-30 10:36:33 +0200 | [diff] [blame] | 278 | func (c *Control) rmrSendToE2T(desc string, subs *Subscription, trans *TransactionSubs) (err error) { |
Juha Hyttinen | 9dc5adc | 2020-08-13 10:02:40 +0300 | [diff] [blame] | 279 | params := &xapp.RMRParams{} |
Juha Hyttinen | e406a34 | 2020-01-13 13:02:26 +0200 | [diff] [blame] | 280 | params.Mtype = trans.GetMtype() |
Juha Hyttinen | aada645 | 2020-04-07 08:47:58 +0300 | [diff] [blame] | 281 | params.SubId = int(subs.GetReqId().InstanceId) |
Juha Hyttinen | 86a4620 | 2020-01-14 12:49:09 +0200 | [diff] [blame] | 282 | params.Xid = "" |
Juha Hyttinen | e406a34 | 2020-01-13 13:02:26 +0200 | [diff] [blame] | 283 | params.Meid = subs.GetMeid() |
| 284 | params.Src = "" |
Juha Hyttinen | 63284a2 | 2020-01-15 10:45:11 +0200 | [diff] [blame] | 285 | params.PayloadLen = len(trans.Payload.Buf) |
| 286 | params.Payload = trans.Payload.Buf |
Juha Hyttinen | e406a34 | 2020-01-13 13:02:26 +0200 | [diff] [blame] | 287 | params.Mbuf = nil |
Juha Hyttinen | 5f8ffa0 | 2020-02-06 15:28:59 +0200 | [diff] [blame] | 288 | 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^] | 289 | err = c.SendWithRetry(params, false, 5) |
| 290 | if err != nil { |
| 291 | xapp.Logger.Error("rmrSendToE2T: Send failed: %+v", err) |
| 292 | } |
| 293 | return err |
kalnagy | e001868 | 2019-09-26 16:28:25 +0200 | [diff] [blame] | 294 | } |
| 295 | |
Juha Hyttinen | 83ada00 | 2020-01-30 10:36:33 +0200 | [diff] [blame] | 296 | func (c *Control) rmrSendToXapp(desc string, subs *Subscription, trans *TransactionXapp) (err error) { |
| 297 | |
Juha Hyttinen | 9dc5adc | 2020-08-13 10:02:40 +0300 | [diff] [blame] | 298 | params := &xapp.RMRParams{} |
Juha Hyttinen | 63284a2 | 2020-01-15 10:45:11 +0200 | [diff] [blame] | 299 | params.Mtype = trans.GetMtype() |
Juha Hyttinen | aada645 | 2020-04-07 08:47:58 +0300 | [diff] [blame] | 300 | params.SubId = int(subs.GetReqId().InstanceId) |
Juha Hyttinen | e406a34 | 2020-01-13 13:02:26 +0200 | [diff] [blame] | 301 | params.Xid = trans.GetXid() |
Juha Hyttinen | 86a4620 | 2020-01-14 12:49:09 +0200 | [diff] [blame] | 302 | params.Meid = trans.GetMeid() |
Juha Hyttinen | e406a34 | 2020-01-13 13:02:26 +0200 | [diff] [blame] | 303 | params.Src = "" |
Juha Hyttinen | 63284a2 | 2020-01-15 10:45:11 +0200 | [diff] [blame] | 304 | params.PayloadLen = len(trans.Payload.Buf) |
| 305 | params.Payload = trans.Payload.Buf |
Juha Hyttinen | e406a34 | 2020-01-13 13:02:26 +0200 | [diff] [blame] | 306 | params.Mbuf = nil |
Juha Hyttinen | 5f8ffa0 | 2020-02-06 15:28:59 +0200 | [diff] [blame] | 307 | 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^] | 308 | err = c.SendWithRetry(params, false, 5) |
| 309 | if err != nil { |
| 310 | xapp.Logger.Error("rmrSendToXapp: Send failed: %+v", err) |
| 311 | } |
| 312 | return err |
Juha Hyttinen | e406a34 | 2020-01-13 13:02:26 +0200 | [diff] [blame] | 313 | } |
| 314 | |
Juha Hyttinen | 9dc5adc | 2020-08-13 10:02:40 +0300 | [diff] [blame] | 315 | func (c *Control) Consume(msg *xapp.RMRParams) (err error) { |
| 316 | if c.RMRClient == nil { |
Juha Hyttinen | 5f8ffa0 | 2020-02-06 15:28:59 +0200 | [diff] [blame] | 317 | err = fmt.Errorf("Rmr object nil can handle %s", msg.String()) |
| 318 | xapp.Logger.Error("%s", err.Error()) |
| 319 | return |
| 320 | } |
| 321 | c.CntRecvMsg++ |
| 322 | |
Juha Hyttinen | 9dc5adc | 2020-08-13 10:02:40 +0300 | [diff] [blame] | 323 | defer c.RMRClient.Free(msg.Mbuf) |
Juha Hyttinen | 83ada00 | 2020-01-30 10:36:33 +0200 | [diff] [blame] | 324 | |
Juha Hyttinen | a8a908d | 2020-05-26 15:12:47 +0300 | [diff] [blame] | 325 | // xapp-frame might use direct access to c buffer and |
| 326 | // when msg.Mbuf is freed, someone might take it into use |
| 327 | // and payload data might be invalid inside message handle function |
| 328 | // |
| 329 | // subscriptions won't load system a lot so there is no |
| 330 | // real performance hit by cloning buffer into new go byte slice |
| 331 | cPay := append(msg.Payload[:0:0], msg.Payload...) |
| 332 | msg.Payload = cPay |
| 333 | msg.PayloadLen = len(cPay) |
| 334 | |
Anssi Mannila | 90fa021 | 2019-12-12 10:47:47 +0200 | [diff] [blame] | 335 | switch msg.Mtype { |
Juha Hyttinen | c9eb08a | 2020-02-28 08:53:33 +0200 | [diff] [blame] | 336 | case xapp.RIC_SUB_REQ: |
Juha Hyttinen | 422d018 | 2020-01-17 13:37:05 +0200 | [diff] [blame] | 337 | go c.handleXAPPSubscriptionRequest(msg) |
Juha Hyttinen | c9eb08a | 2020-02-28 08:53:33 +0200 | [diff] [blame] | 338 | case xapp.RIC_SUB_RESP: |
Juha Hyttinen | 422d018 | 2020-01-17 13:37:05 +0200 | [diff] [blame] | 339 | go c.handleE2TSubscriptionResponse(msg) |
Juha Hyttinen | c9eb08a | 2020-02-28 08:53:33 +0200 | [diff] [blame] | 340 | case xapp.RIC_SUB_FAILURE: |
Juha Hyttinen | 422d018 | 2020-01-17 13:37:05 +0200 | [diff] [blame] | 341 | go c.handleE2TSubscriptionFailure(msg) |
Juha Hyttinen | c9eb08a | 2020-02-28 08:53:33 +0200 | [diff] [blame] | 342 | case xapp.RIC_SUB_DEL_REQ: |
Juha Hyttinen | 422d018 | 2020-01-17 13:37:05 +0200 | [diff] [blame] | 343 | go c.handleXAPPSubscriptionDeleteRequest(msg) |
Juha Hyttinen | c9eb08a | 2020-02-28 08:53:33 +0200 | [diff] [blame] | 344 | case xapp.RIC_SUB_DEL_RESP: |
Juha Hyttinen | 422d018 | 2020-01-17 13:37:05 +0200 | [diff] [blame] | 345 | go c.handleE2TSubscriptionDeleteResponse(msg) |
Juha Hyttinen | c9eb08a | 2020-02-28 08:53:33 +0200 | [diff] [blame] | 346 | case xapp.RIC_SUB_DEL_FAILURE: |
Juha Hyttinen | 422d018 | 2020-01-17 13:37:05 +0200 | [diff] [blame] | 347 | go c.handleE2TSubscriptionDeleteFailure(msg) |
Anssi Mannila | 90fa021 | 2019-12-12 10:47:47 +0200 | [diff] [blame] | 348 | default: |
| 349 | xapp.Logger.Info("Unknown Message Type '%d', discarding", msg.Mtype) |
Balint Uveges | cd3881b | 2019-10-02 15:01:43 +0000 | [diff] [blame] | 350 | } |
Juha Hyttinen | 5f8ffa0 | 2020-02-06 15:28:59 +0200 | [diff] [blame] | 351 | return |
Juha Hyttinen | 31797b4 | 2020-01-16 14:05:01 +0200 | [diff] [blame] | 352 | } |
| 353 | |
Juha Hyttinen | 422d018 | 2020-01-17 13:37:05 +0200 | [diff] [blame] | 354 | //------------------------------------------------------------------- |
| 355 | // handle from XAPP Subscription Request |
| 356 | //------------------------------------------------------------------ |
Juha Hyttinen | 9dc5adc | 2020-08-13 10:02:40 +0300 | [diff] [blame] | 357 | func (c *Control) handleXAPPSubscriptionRequest(params *xapp.RMRParams) { |
Juha Hyttinen | 83ada00 | 2020-01-30 10:36:33 +0200 | [diff] [blame] | 358 | xapp.Logger.Info("MSG from XAPP: %s", params.String()) |
Anssi Mannila | 4abf180 | 2021-01-28 13:06:46 +0200 | [diff] [blame] | 359 | c.UpdateCounter(cSubReqFromXapp) |
Juha Hyttinen | 422d018 | 2020-01-17 13:37:05 +0200 | [diff] [blame] | 360 | |
| 361 | subReqMsg, err := c.e2ap.UnpackSubscriptionRequest(params.Payload) |
| 362 | if err != nil { |
Juha Hyttinen | 83ada00 | 2020-01-30 10:36:33 +0200 | [diff] [blame] | 363 | xapp.Logger.Error("XAPP-SubReq: %s", idstring(err, params)) |
Juha Hyttinen | 422d018 | 2020-01-17 13:37:05 +0200 | [diff] [blame] | 364 | return |
| 365 | } |
| 366 | |
Anssi Mannila | 4c626a2 | 2021-02-11 12:50:48 +0200 | [diff] [blame] | 367 | 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] | 368 | if trans == nil { |
| 369 | 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] | 370 | return |
| 371 | } |
| 372 | defer trans.Release() |
| 373 | |
Anssi Mannila | 6b3796f | 2021-02-12 09:11:35 +0200 | [diff] [blame] | 374 | if err = c.tracker.Track(trans); err != nil { |
Juha Hyttinen | 83ada00 | 2020-01-30 10:36:33 +0200 | [diff] [blame] | 375 | xapp.Logger.Error("XAPP-SubReq: %s", idstring(err, trans)) |
| 376 | return |
| 377 | } |
| 378 | |
Juha Hyttinen | 429cfe6 | 2020-03-31 11:23:02 +0300 | [diff] [blame] | 379 | //TODO handle subscription toward e2term inside AssignToSubscription / hide handleSubscriptionCreate in it? |
Anssi Mannila | 4abf180 | 2021-01-28 13:06:46 +0200 | [diff] [blame] | 380 | subs, err := c.registry.AssignToSubscription(trans, subReqMsg, c.ResetTestFlag, c) |
Juha Hyttinen | 422d018 | 2020-01-17 13:37:05 +0200 | [diff] [blame] | 381 | if err != nil { |
Juha Hyttinen | 83ada00 | 2020-01-30 10:36:33 +0200 | [diff] [blame] | 382 | xapp.Logger.Error("XAPP-SubReq: %s", idstring(err, trans)) |
Juha Hyttinen | 422d018 | 2020-01-17 13:37:05 +0200 | [diff] [blame] | 383 | return |
| 384 | } |
| 385 | |
Anssi Mannila | 6b3796f | 2021-02-12 09:11:35 +0200 | [diff] [blame] | 386 | c.wakeSubscriptionRequest(subs, trans) |
| 387 | } |
| 388 | |
| 389 | //------------------------------------------------------------------- |
| 390 | // Wake Subscription Request to E2node |
| 391 | //------------------------------------------------------------------ |
| 392 | func (c *Control) wakeSubscriptionRequest(subs *Subscription, trans *TransactionXapp) { |
| 393 | |
Juha Hyttinen | 422d018 | 2020-01-17 13:37:05 +0200 | [diff] [blame] | 394 | go c.handleSubscriptionCreate(subs, trans) |
| 395 | 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] | 396 | var err error |
Juha Hyttinen | 422d018 | 2020-01-17 13:37:05 +0200 | [diff] [blame] | 397 | if event != nil { |
| 398 | switch themsg := event.(type) { |
| 399 | case *e2ap.E2APSubscriptionResponse: |
Anssi Mannila | 4c626a2 | 2021-02-11 12:50:48 +0200 | [diff] [blame] | 400 | themsg.RequestId.Id = trans.RequestId.Id |
Juha Hyttinen | 422d018 | 2020-01-17 13:37:05 +0200 | [diff] [blame] | 401 | trans.Mtype, trans.Payload, err = c.e2ap.PackSubscriptionResponse(themsg) |
| 402 | if err == nil { |
Anssi Mannila | 64a0df4 | 2020-02-26 09:46:03 +0200 | [diff] [blame] | 403 | trans.Release() |
Anssi Mannila | 4abf180 | 2021-01-28 13:06:46 +0200 | [diff] [blame] | 404 | c.UpdateCounter(cSubRespToXapp) |
Juha Hyttinen | 83ada00 | 2020-01-30 10:36:33 +0200 | [diff] [blame] | 405 | c.rmrSendToXapp("", subs, trans) |
Juha Hyttinen | 422d018 | 2020-01-17 13:37:05 +0200 | [diff] [blame] | 406 | return |
| 407 | } |
| 408 | case *e2ap.E2APSubscriptionFailure: |
Anssi Mannila | 4c626a2 | 2021-02-11 12:50:48 +0200 | [diff] [blame] | 409 | themsg.RequestId.Id = trans.RequestId.Id |
Juha Hyttinen | 422d018 | 2020-01-17 13:37:05 +0200 | [diff] [blame] | 410 | trans.Mtype, trans.Payload, err = c.e2ap.PackSubscriptionFailure(themsg) |
| 411 | if err == nil { |
Anssi Mannila | 4abf180 | 2021-01-28 13:06:46 +0200 | [diff] [blame] | 412 | c.UpdateCounter(cSubFailToXapp) |
Juha Hyttinen | 83ada00 | 2020-01-30 10:36:33 +0200 | [diff] [blame] | 413 | c.rmrSendToXapp("", subs, trans) |
Juha Hyttinen | 422d018 | 2020-01-17 13:37:05 +0200 | [diff] [blame] | 414 | } |
Juha Hyttinen | 422d018 | 2020-01-17 13:37:05 +0200 | [diff] [blame] | 415 | default: |
Juha Hyttinen | 31797b4 | 2020-01-16 14:05:01 +0200 | [diff] [blame] | 416 | break |
| 417 | } |
| 418 | } |
Juha Hyttinen | 83ada00 | 2020-01-30 10:36:33 +0200 | [diff] [blame] | 419 | xapp.Logger.Info("XAPP-SubReq: failed %s", idstring(err, trans, subs)) |
Juha Hyttinen | 429cfe6 | 2020-03-31 11:23:02 +0300 | [diff] [blame] | 420 | //c.registry.RemoveFromSubscription(subs, trans, 5*time.Second) |
Juha Hyttinen | 31797b4 | 2020-01-16 14:05:01 +0200 | [diff] [blame] | 421 | } |
| 422 | |
Juha Hyttinen | 422d018 | 2020-01-17 13:37:05 +0200 | [diff] [blame] | 423 | //------------------------------------------------------------------- |
| 424 | // handle from XAPP Subscription Delete Request |
| 425 | //------------------------------------------------------------------ |
Juha Hyttinen | 9dc5adc | 2020-08-13 10:02:40 +0300 | [diff] [blame] | 426 | func (c *Control) handleXAPPSubscriptionDeleteRequest(params *xapp.RMRParams) { |
Juha Hyttinen | 83ada00 | 2020-01-30 10:36:33 +0200 | [diff] [blame] | 427 | xapp.Logger.Info("MSG from XAPP: %s", params.String()) |
Anssi Mannila | 4abf180 | 2021-01-28 13:06:46 +0200 | [diff] [blame] | 428 | c.UpdateCounter(cSubDelReqFromXapp) |
Juha Hyttinen | 422d018 | 2020-01-17 13:37:05 +0200 | [diff] [blame] | 429 | |
| 430 | subDelReqMsg, err := c.e2ap.UnpackSubscriptionDeleteRequest(params.Payload) |
Juha Hyttinen | 31797b4 | 2020-01-16 14:05:01 +0200 | [diff] [blame] | 431 | if err != nil { |
Juha Hyttinen | 83ada00 | 2020-01-30 10:36:33 +0200 | [diff] [blame] | 432 | xapp.Logger.Error("XAPP-SubDelReq %s", idstring(err, params)) |
Juha Hyttinen | 422d018 | 2020-01-17 13:37:05 +0200 | [diff] [blame] | 433 | return |
| 434 | } |
| 435 | |
Anssi Mannila | 4c626a2 | 2021-02-11 12:50:48 +0200 | [diff] [blame] | 436 | 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] | 437 | if trans == nil { |
| 438 | 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] | 439 | return |
| 440 | } |
| 441 | defer trans.Release() |
| 442 | |
Juha Hyttinen | 83ada00 | 2020-01-30 10:36:33 +0200 | [diff] [blame] | 443 | err = c.tracker.Track(trans) |
Juha Hyttinen | 422d018 | 2020-01-17 13:37:05 +0200 | [diff] [blame] | 444 | if err != nil { |
Juha Hyttinen | 83ada00 | 2020-01-30 10:36:33 +0200 | [diff] [blame] | 445 | xapp.Logger.Error("XAPP-SubReq: %s", idstring(err, trans)) |
| 446 | return |
| 447 | } |
| 448 | |
Juha Hyttinen | 47942b4 | 2020-02-27 10:41:43 +0200 | [diff] [blame] | 449 | subs, err := c.registry.GetSubscriptionFirstMatch([]uint32{trans.GetSubId()}) |
Juha Hyttinen | 83ada00 | 2020-01-30 10:36:33 +0200 | [diff] [blame] | 450 | if err != nil { |
| 451 | xapp.Logger.Error("XAPP-SubDelReq: %s", idstring(err, trans)) |
Juha Hyttinen | 422d018 | 2020-01-17 13:37:05 +0200 | [diff] [blame] | 452 | return |
| 453 | } |
| 454 | |
Juha Hyttinen | 422d018 | 2020-01-17 13:37:05 +0200 | [diff] [blame] | 455 | // |
| 456 | // Wake subs delete |
| 457 | // |
| 458 | go c.handleSubscriptionDelete(subs, trans) |
| 459 | trans.WaitEvent(0) //blocked wait as timeout is handled in subs side |
| 460 | |
Juha Hyttinen | 83ada00 | 2020-01-30 10:36:33 +0200 | [diff] [blame] | 461 | xapp.Logger.Debug("XAPP-SubDelReq: Handling event %s ", idstring(nil, trans, subs)) |
| 462 | |
Anssi Mannila | c92b421 | 2020-12-07 14:59:34 +0200 | [diff] [blame] | 463 | if subs.NoRespToXapp == true { |
| 464 | // Do no send delete responses to xapps due to submgr restart is deleting uncompleted subscriptions |
| 465 | return |
| 466 | } |
| 467 | |
| 468 | // Whatever is received success, fail or timeout, send successful delete response |
Juha Hyttinen | 422d018 | 2020-01-17 13:37:05 +0200 | [diff] [blame] | 469 | subDelRespMsg := &e2ap.E2APSubscriptionDeleteResponse{} |
Anssi Mannila | 4c626a2 | 2021-02-11 12:50:48 +0200 | [diff] [blame] | 470 | subDelRespMsg.RequestId.Id = trans.RequestId.Id |
| 471 | subDelRespMsg.RequestId.InstanceId = subs.GetReqId().RequestId.InstanceId |
Juha Hyttinen | 422d018 | 2020-01-17 13:37:05 +0200 | [diff] [blame] | 472 | subDelRespMsg.FunctionId = subs.SubReqMsg.FunctionId |
| 473 | trans.Mtype, trans.Payload, err = c.e2ap.PackSubscriptionDeleteResponse(subDelRespMsg) |
| 474 | if err == nil { |
Anssi Mannila | 4abf180 | 2021-01-28 13:06:46 +0200 | [diff] [blame] | 475 | c.UpdateCounter(cSubDelRespToXapp) |
Juha Hyttinen | 83ada00 | 2020-01-30 10:36:33 +0200 | [diff] [blame] | 476 | c.rmrSendToXapp("", subs, trans) |
Juha Hyttinen | 422d018 | 2020-01-17 13:37:05 +0200 | [diff] [blame] | 477 | } |
Juha Hyttinen | 83ada00 | 2020-01-30 10:36:33 +0200 | [diff] [blame] | 478 | |
Juha Hyttinen | 429cfe6 | 2020-03-31 11:23:02 +0300 | [diff] [blame] | 479 | //TODO handle subscription toward e2term insiged RemoveFromSubscription / hide handleSubscriptionDelete in it? |
| 480 | //c.registry.RemoveFromSubscription(subs, trans, 5*time.Second) |
Juha Hyttinen | 422d018 | 2020-01-17 13:37:05 +0200 | [diff] [blame] | 481 | } |
| 482 | |
| 483 | //------------------------------------------------------------------- |
| 484 | // SUBS CREATE Handling |
| 485 | //------------------------------------------------------------------- |
Juha Hyttinen | 83ada00 | 2020-01-30 10:36:33 +0200 | [diff] [blame] | 486 | func (c *Control) handleSubscriptionCreate(subs *Subscription, parentTrans *TransactionXapp) { |
Juha Hyttinen | 422d018 | 2020-01-17 13:37:05 +0200 | [diff] [blame] | 487 | |
Anssi Mannila | c92b421 | 2020-12-07 14:59:34 +0200 | [diff] [blame] | 488 | var removeSubscriptionFromDb bool = false |
Juha Hyttinen | 83ada00 | 2020-01-30 10:36:33 +0200 | [diff] [blame] | 489 | trans := c.tracker.NewSubsTransaction(subs) |
Juha Hyttinen | 422d018 | 2020-01-17 13:37:05 +0200 | [diff] [blame] | 490 | subs.WaitTransactionTurn(trans) |
| 491 | defer subs.ReleaseTransactionTurn(trans) |
| 492 | defer trans.Release() |
| 493 | |
Juha Hyttinen | 83ada00 | 2020-01-30 10:36:33 +0200 | [diff] [blame] | 494 | xapp.Logger.Debug("SUBS-SubReq: Handling %s ", idstring(nil, trans, subs, parentTrans)) |
Juha Hyttinen | 422d018 | 2020-01-17 13:37:05 +0200 | [diff] [blame] | 495 | |
Juha Hyttinen | 83ada00 | 2020-01-30 10:36:33 +0200 | [diff] [blame] | 496 | subRfMsg, valid := subs.GetCachedResponse() |
| 497 | if subRfMsg == nil && valid == true { |
Anssi Mannila | 6d629ad | 2021-01-25 09:59:56 +0200 | [diff] [blame] | 498 | event := c.sendE2TSubscriptionRequest(subs, trans, parentTrans) |
| 499 | switch event.(type) { |
| 500 | case *e2ap.E2APSubscriptionResponse: |
| 501 | subRfMsg, valid = subs.SetCachedResponse(event, true) |
| 502 | subs.SubRespRcvd = true |
| 503 | case *e2ap.E2APSubscriptionFailure: |
| 504 | removeSubscriptionFromDb = true |
| 505 | subRfMsg, valid = subs.SetCachedResponse(event, false) |
Anssi Mannila | ebaeae6 | 2021-02-12 11:56:20 +0200 | [diff] [blame] | 506 | xapp.Logger.Info("SUBS-SubReq: internal delete due event(%s) %s", typeofSubsMessage(event), idstring(nil, trans, subs, parentTrans)) |
Anssi Mannila | 6d629ad | 2021-01-25 09:59:56 +0200 | [diff] [blame] | 507 | case *SubmgrRestartTestEvent: |
| 508 | // This simulates that no response has been received and after restart subscriptions are restored from db |
| 509 | xapp.Logger.Debug("Test restart flag is active. Dropping this transaction to test restart case") |
| 510 | return |
| 511 | default: |
| 512 | xapp.Logger.Info("SUBS-SubReq: internal delete due event(%s) %s", typeofSubsMessage(event), idstring(nil, trans, subs, parentTrans)) |
| 513 | removeSubscriptionFromDb = true |
| 514 | subRfMsg, valid = subs.SetCachedResponse(nil, false) |
| 515 | c.sendE2TSubscriptionDeleteRequest(subs, trans, parentTrans) |
Juha Hyttinen | 83ada00 | 2020-01-30 10:36:33 +0200 | [diff] [blame] | 516 | } |
| 517 | xapp.Logger.Debug("SUBS-SubReq: Handling (e2t response %s) %s", typeofSubsMessage(subRfMsg), idstring(nil, trans, subs, parentTrans)) |
| 518 | } else { |
| 519 | 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] | 520 | } |
| 521 | |
Juha Hyttinen | 429cfe6 | 2020-03-31 11:23:02 +0300 | [diff] [blame] | 522 | //Now RemoveFromSubscription in here to avoid race conditions (mostly concerns delete) |
| 523 | if valid == false { |
Anssi Mannila | c92b421 | 2020-12-07 14:59:34 +0200 | [diff] [blame] | 524 | c.registry.RemoveFromSubscription(subs, parentTrans, 5*time.Second, c) |
Juha Hyttinen | 429cfe6 | 2020-03-31 11:23:02 +0300 | [diff] [blame] | 525 | } |
Anssi Mannila | c92b421 | 2020-12-07 14:59:34 +0200 | [diff] [blame] | 526 | |
| 527 | c.UpdateSubscriptionInDB(subs, removeSubscriptionFromDb) |
Juha Hyttinen | 83ada00 | 2020-01-30 10:36:33 +0200 | [diff] [blame] | 528 | parentTrans.SendEvent(subRfMsg, 0) |
Juha Hyttinen | 422d018 | 2020-01-17 13:37:05 +0200 | [diff] [blame] | 529 | } |
| 530 | |
| 531 | //------------------------------------------------------------------- |
| 532 | // SUBS DELETE Handling |
| 533 | //------------------------------------------------------------------- |
Juha Hyttinen | 3944a22 | 2020-01-24 11:51:46 +0200 | [diff] [blame] | 534 | |
Juha Hyttinen | 83ada00 | 2020-01-30 10:36:33 +0200 | [diff] [blame] | 535 | func (c *Control) handleSubscriptionDelete(subs *Subscription, parentTrans *TransactionXapp) { |
Juha Hyttinen | 422d018 | 2020-01-17 13:37:05 +0200 | [diff] [blame] | 536 | |
Juha Hyttinen | 83ada00 | 2020-01-30 10:36:33 +0200 | [diff] [blame] | 537 | trans := c.tracker.NewSubsTransaction(subs) |
Juha Hyttinen | 422d018 | 2020-01-17 13:37:05 +0200 | [diff] [blame] | 538 | subs.WaitTransactionTurn(trans) |
| 539 | defer subs.ReleaseTransactionTurn(trans) |
| 540 | defer trans.Release() |
| 541 | |
Juha Hyttinen | 83ada00 | 2020-01-30 10:36:33 +0200 | [diff] [blame] | 542 | xapp.Logger.Debug("SUBS-SubDelReq: Handling %s", idstring(nil, trans, subs, parentTrans)) |
Juha Hyttinen | 422d018 | 2020-01-17 13:37:05 +0200 | [diff] [blame] | 543 | |
Juha Hyttinen | 3944a22 | 2020-01-24 11:51:46 +0200 | [diff] [blame] | 544 | subs.mutex.Lock() |
Anssi Mannila | 4abf180 | 2021-01-28 13:06:46 +0200 | [diff] [blame] | 545 | |
Juha Hyttinen | 3944a22 | 2020-01-24 11:51:46 +0200 | [diff] [blame] | 546 | if subs.valid && subs.EpList.HasEndpoint(parentTrans.GetEndpoint()) && subs.EpList.Size() == 1 { |
| 547 | subs.valid = false |
| 548 | subs.mutex.Unlock() |
| 549 | c.sendE2TSubscriptionDeleteRequest(subs, trans, parentTrans) |
| 550 | } else { |
| 551 | subs.mutex.Unlock() |
| 552 | } |
Juha Hyttinen | 429cfe6 | 2020-03-31 11:23:02 +0300 | [diff] [blame] | 553 | //Now RemoveFromSubscription in here to avoid race conditions (mostly concerns delete) |
| 554 | // If parallel deletes ongoing both might pass earlier sendE2TSubscriptionDeleteRequest(...) if |
| 555 | // RemoveFromSubscription locates in caller side (now in handleXAPPSubscriptionDeleteRequest(...)) |
Anssi Mannila | c92b421 | 2020-12-07 14:59:34 +0200 | [diff] [blame] | 556 | c.registry.RemoveFromSubscription(subs, parentTrans, 5*time.Second, c) |
| 557 | c.registry.UpdateSubscriptionToDb(subs, c) |
Juha Hyttinen | 47942b4 | 2020-02-27 10:41:43 +0200 | [diff] [blame] | 558 | parentTrans.SendEvent(nil, 0) |
Juha Hyttinen | 422d018 | 2020-01-17 13:37:05 +0200 | [diff] [blame] | 559 | } |
| 560 | |
| 561 | //------------------------------------------------------------------- |
| 562 | // send to E2T Subscription Request |
| 563 | //------------------------------------------------------------------- |
Juha Hyttinen | 83ada00 | 2020-01-30 10:36:33 +0200 | [diff] [blame] | 564 | func (c *Control) sendE2TSubscriptionRequest(subs *Subscription, trans *TransactionSubs, parentTrans *TransactionXapp) interface{} { |
Juha Hyttinen | 422d018 | 2020-01-17 13:37:05 +0200 | [diff] [blame] | 565 | var err error |
| 566 | var event interface{} = nil |
| 567 | var timedOut bool = false |
| 568 | |
| 569 | subReqMsg := subs.SubReqMsg |
Juha Hyttinen | 83ada00 | 2020-01-30 10:36:33 +0200 | [diff] [blame] | 570 | subReqMsg.RequestId = subs.GetReqId().RequestId |
Juha Hyttinen | 422d018 | 2020-01-17 13:37:05 +0200 | [diff] [blame] | 571 | trans.Mtype, trans.Payload, err = c.e2ap.PackSubscriptionRequest(subReqMsg) |
| 572 | if err != nil { |
Juha Hyttinen | 83ada00 | 2020-01-30 10:36:33 +0200 | [diff] [blame] | 573 | xapp.Logger.Error("SUBS-SubReq: %s", idstring(err, trans, subs, parentTrans)) |
Juha Hyttinen | 422d018 | 2020-01-17 13:37:05 +0200 | [diff] [blame] | 574 | return event |
| 575 | } |
| 576 | |
Anssi Mannila | c92b421 | 2020-12-07 14:59:34 +0200 | [diff] [blame] | 577 | // Write uncompleted subscrition in db. If no response for subscrition it need to be re-processed (deleted) after restart |
| 578 | c.WriteSubscriptionToDb(subs) |
Juha Hyttinen | 422d018 | 2020-01-17 13:37:05 +0200 | [diff] [blame] | 579 | for retries := uint64(0); retries < e2tMaxSubReqTryCount; retries++ { |
Juha Hyttinen | 83ada00 | 2020-01-30 10:36:33 +0200 | [diff] [blame] | 580 | desc := fmt.Sprintf("(retry %d)", retries) |
Anssi Mannila | 4abf180 | 2021-01-28 13:06:46 +0200 | [diff] [blame] | 581 | if retries == 0 { |
| 582 | c.UpdateCounter(cSubReqToE2) |
| 583 | } else { |
| 584 | c.UpdateCounter(cSubReReqToE2) |
| 585 | } |
Juha Hyttinen | 83ada00 | 2020-01-30 10:36:33 +0200 | [diff] [blame] | 586 | c.rmrSendToE2T(desc, subs, trans) |
Anssi Mannila | c92b421 | 2020-12-07 14:59:34 +0200 | [diff] [blame] | 587 | if subs.DoNotWaitSubResp == false { |
| 588 | event, timedOut = trans.WaitEvent(e2tSubReqTimeout) |
| 589 | if timedOut { |
Anssi Mannila | 4abf180 | 2021-01-28 13:06:46 +0200 | [diff] [blame] | 590 | c.UpdateCounter(cSubReqTimerExpiry) |
Anssi Mannila | c92b421 | 2020-12-07 14:59:34 +0200 | [diff] [blame] | 591 | continue |
| 592 | } |
| 593 | } else { |
| 594 | // Simulating case where subscrition request has been sent but response has not been received before restart |
| 595 | event = &SubmgrRestartTestEvent{} |
Juha Hyttinen | 422d018 | 2020-01-17 13:37:05 +0200 | [diff] [blame] | 596 | } |
| 597 | break |
| 598 | } |
Juha Hyttinen | 83ada00 | 2020-01-30 10:36:33 +0200 | [diff] [blame] | 599 | 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] | 600 | return event |
| 601 | } |
| 602 | |
| 603 | //------------------------------------------------------------------- |
| 604 | // send to E2T Subscription Delete Request |
| 605 | //------------------------------------------------------------------- |
| 606 | |
Juha Hyttinen | 83ada00 | 2020-01-30 10:36:33 +0200 | [diff] [blame] | 607 | func (c *Control) sendE2TSubscriptionDeleteRequest(subs *Subscription, trans *TransactionSubs, parentTrans *TransactionXapp) interface{} { |
Juha Hyttinen | 422d018 | 2020-01-17 13:37:05 +0200 | [diff] [blame] | 608 | var err error |
| 609 | var event interface{} |
| 610 | var timedOut bool |
| 611 | |
| 612 | subDelReqMsg := &e2ap.E2APSubscriptionDeleteRequest{} |
Juha Hyttinen | 83ada00 | 2020-01-30 10:36:33 +0200 | [diff] [blame] | 613 | subDelReqMsg.RequestId = subs.GetReqId().RequestId |
Juha Hyttinen | af91f97 | 2020-01-24 08:38:47 +0200 | [diff] [blame] | 614 | subDelReqMsg.FunctionId = subs.SubReqMsg.FunctionId |
Juha Hyttinen | 422d018 | 2020-01-17 13:37:05 +0200 | [diff] [blame] | 615 | trans.Mtype, trans.Payload, err = c.e2ap.PackSubscriptionDeleteRequest(subDelReqMsg) |
| 616 | if err != nil { |
Juha Hyttinen | 83ada00 | 2020-01-30 10:36:33 +0200 | [diff] [blame] | 617 | xapp.Logger.Error("SUBS-SubDelReq: %s", idstring(err, trans, subs, parentTrans)) |
Juha Hyttinen | 422d018 | 2020-01-17 13:37:05 +0200 | [diff] [blame] | 618 | return event |
| 619 | } |
| 620 | |
| 621 | for retries := uint64(0); retries < e2tMaxSubDelReqTryCount; retries++ { |
Juha Hyttinen | 83ada00 | 2020-01-30 10:36:33 +0200 | [diff] [blame] | 622 | desc := fmt.Sprintf("(retry %d)", retries) |
Anssi Mannila | 4abf180 | 2021-01-28 13:06:46 +0200 | [diff] [blame] | 623 | if retries == 0 { |
| 624 | c.UpdateCounter(cSubDelReqToE2) |
| 625 | } else { |
| 626 | c.UpdateCounter(cSubDelReReqToE2) |
| 627 | } |
Juha Hyttinen | 83ada00 | 2020-01-30 10:36:33 +0200 | [diff] [blame] | 628 | c.rmrSendToE2T(desc, subs, trans) |
Juha Hyttinen | 422d018 | 2020-01-17 13:37:05 +0200 | [diff] [blame] | 629 | event, timedOut = trans.WaitEvent(e2tSubDelReqTime) |
| 630 | if timedOut { |
Anssi Mannila | 4abf180 | 2021-01-28 13:06:46 +0200 | [diff] [blame] | 631 | c.UpdateCounter(cSubDelReqTimerExpiry) |
Juha Hyttinen | 422d018 | 2020-01-17 13:37:05 +0200 | [diff] [blame] | 632 | continue |
| 633 | } |
| 634 | break |
| 635 | } |
Juha Hyttinen | 83ada00 | 2020-01-30 10:36:33 +0200 | [diff] [blame] | 636 | 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] | 637 | return event |
| 638 | } |
| 639 | |
| 640 | //------------------------------------------------------------------- |
Anssi Mannila | 4abf180 | 2021-01-28 13:06:46 +0200 | [diff] [blame] | 641 | // handle from E2T Subscription Response |
Juha Hyttinen | 422d018 | 2020-01-17 13:37:05 +0200 | [diff] [blame] | 642 | //------------------------------------------------------------------- |
Juha Hyttinen | 9dc5adc | 2020-08-13 10:02:40 +0300 | [diff] [blame] | 643 | func (c *Control) handleE2TSubscriptionResponse(params *xapp.RMRParams) { |
Juha Hyttinen | 83ada00 | 2020-01-30 10:36:33 +0200 | [diff] [blame] | 644 | xapp.Logger.Info("MSG from E2T: %s", params.String()) |
Anssi Mannila | 4abf180 | 2021-01-28 13:06:46 +0200 | [diff] [blame] | 645 | c.UpdateCounter(cSubRespFromE2) |
Juha Hyttinen | 422d018 | 2020-01-17 13:37:05 +0200 | [diff] [blame] | 646 | subRespMsg, err := c.e2ap.UnpackSubscriptionResponse(params.Payload) |
| 647 | if err != nil { |
Juha Hyttinen | 83ada00 | 2020-01-30 10:36:33 +0200 | [diff] [blame] | 648 | xapp.Logger.Error("MSG-SubResp %s", idstring(err, params)) |
Juha Hyttinen | 422d018 | 2020-01-17 13:37:05 +0200 | [diff] [blame] | 649 | return |
| 650 | } |
Juha Hyttinen | aada645 | 2020-04-07 08:47:58 +0300 | [diff] [blame] | 651 | subs, err := c.registry.GetSubscriptionFirstMatch([]uint32{subRespMsg.RequestId.InstanceId}) |
Juha Hyttinen | 422d018 | 2020-01-17 13:37:05 +0200 | [diff] [blame] | 652 | if err != nil { |
Juha Hyttinen | 83ada00 | 2020-01-30 10:36:33 +0200 | [diff] [blame] | 653 | xapp.Logger.Error("MSG-SubResp: %s", idstring(err, params)) |
Juha Hyttinen | 422d018 | 2020-01-17 13:37:05 +0200 | [diff] [blame] | 654 | return |
Juha Hyttinen | 31797b4 | 2020-01-16 14:05:01 +0200 | [diff] [blame] | 655 | } |
| 656 | trans := subs.GetTransaction() |
| 657 | if trans == nil { |
Juha Hyttinen | 422d018 | 2020-01-17 13:37:05 +0200 | [diff] [blame] | 658 | err = fmt.Errorf("Ongoing transaction not found") |
Juha Hyttinen | 83ada00 | 2020-01-30 10:36:33 +0200 | [diff] [blame] | 659 | xapp.Logger.Error("MSG-SubResp: %s", idstring(err, params, subs)) |
Juha Hyttinen | ff8dccd | 2019-12-10 14:34:07 +0200 | [diff] [blame] | 660 | return |
Anssi Mannila | 2e99e2f | 2019-12-05 13:57:06 +0200 | [diff] [blame] | 661 | } |
Juha Hyttinen | 422d018 | 2020-01-17 13:37:05 +0200 | [diff] [blame] | 662 | sendOk, timedOut := trans.SendEvent(subRespMsg, e2tRecvMsgTimeout) |
| 663 | if sendOk == false { |
| 664 | 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] | 665 | xapp.Logger.Error("MSG-SubResp: %s", idstring(err, trans, subs)) |
Peter Szilagyi | fbc56f9 | 2019-07-23 19:29:46 +0000 | [diff] [blame] | 666 | } |
Peter Szilagyi | fbc56f9 | 2019-07-23 19:29:46 +0000 | [diff] [blame] | 667 | return |
kalnagy | 4511475 | 2019-06-18 14:40:39 +0200 | [diff] [blame] | 668 | } |
| 669 | |
Juha Hyttinen | 422d018 | 2020-01-17 13:37:05 +0200 | [diff] [blame] | 670 | //------------------------------------------------------------------- |
| 671 | // handle from E2T Subscription Failure |
| 672 | //------------------------------------------------------------------- |
Juha Hyttinen | 9dc5adc | 2020-08-13 10:02:40 +0300 | [diff] [blame] | 673 | func (c *Control) handleE2TSubscriptionFailure(params *xapp.RMRParams) { |
Juha Hyttinen | 83ada00 | 2020-01-30 10:36:33 +0200 | [diff] [blame] | 674 | xapp.Logger.Info("MSG from E2T: %s", params.String()) |
Anssi Mannila | 4abf180 | 2021-01-28 13:06:46 +0200 | [diff] [blame] | 675 | c.UpdateCounter(cSubFailFromE2) |
Juha Hyttinen | 422d018 | 2020-01-17 13:37:05 +0200 | [diff] [blame] | 676 | subFailMsg, err := c.e2ap.UnpackSubscriptionFailure(params.Payload) |
Peter Szilagyi | fbc56f9 | 2019-07-23 19:29:46 +0000 | [diff] [blame] | 677 | if err != nil { |
Juha Hyttinen | 83ada00 | 2020-01-30 10:36:33 +0200 | [diff] [blame] | 678 | xapp.Logger.Error("MSG-SubFail %s", idstring(err, params)) |
Peter Szilagyi | fbc56f9 | 2019-07-23 19:29:46 +0000 | [diff] [blame] | 679 | return |
| 680 | } |
Juha Hyttinen | aada645 | 2020-04-07 08:47:58 +0300 | [diff] [blame] | 681 | subs, err := c.registry.GetSubscriptionFirstMatch([]uint32{subFailMsg.RequestId.InstanceId}) |
Juha Hyttinen | 31797b4 | 2020-01-16 14:05:01 +0200 | [diff] [blame] | 682 | if err != nil { |
Juha Hyttinen | 83ada00 | 2020-01-30 10:36:33 +0200 | [diff] [blame] | 683 | xapp.Logger.Error("MSG-SubFail: %s", idstring(err, params)) |
Juha Hyttinen | aafee7f | 2020-01-14 14:54:51 +0200 | [diff] [blame] | 684 | return |
| 685 | } |
Juha Hyttinen | 422d018 | 2020-01-17 13:37:05 +0200 | [diff] [blame] | 686 | trans := subs.GetTransaction() |
| 687 | if trans == nil { |
| 688 | err = fmt.Errorf("Ongoing transaction not found") |
Juha Hyttinen | 83ada00 | 2020-01-30 10:36:33 +0200 | [diff] [blame] | 689 | xapp.Logger.Error("MSG-SubFail: %s", idstring(err, params, subs)) |
Anssi Mannila | 8046c70 | 2020-01-02 13:39:05 +0200 | [diff] [blame] | 690 | return |
| 691 | } |
Juha Hyttinen | 422d018 | 2020-01-17 13:37:05 +0200 | [diff] [blame] | 692 | sendOk, timedOut := trans.SendEvent(subFailMsg, e2tRecvMsgTimeout) |
| 693 | if sendOk == false { |
| 694 | 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] | 695 | xapp.Logger.Error("MSG-SubFail: %s", idstring(err, trans, subs)) |
Juha Hyttinen | aafee7f | 2020-01-14 14:54:51 +0200 | [diff] [blame] | 696 | } |
Anssi Mannila | 2e99e2f | 2019-12-05 13:57:06 +0200 | [diff] [blame] | 697 | return |
| 698 | } |
| 699 | |
Juha Hyttinen | 422d018 | 2020-01-17 13:37:05 +0200 | [diff] [blame] | 700 | //------------------------------------------------------------------- |
| 701 | // handle from E2T Subscription Delete Response |
| 702 | //------------------------------------------------------------------- |
Juha Hyttinen | 9dc5adc | 2020-08-13 10:02:40 +0300 | [diff] [blame] | 703 | func (c *Control) handleE2TSubscriptionDeleteResponse(params *xapp.RMRParams) (err error) { |
Juha Hyttinen | 83ada00 | 2020-01-30 10:36:33 +0200 | [diff] [blame] | 704 | xapp.Logger.Info("MSG from E2T: %s", params.String()) |
Anssi Mannila | 4abf180 | 2021-01-28 13:06:46 +0200 | [diff] [blame] | 705 | c.UpdateCounter(cSubDelRespFromE2) |
Juha Hyttinen | 422d018 | 2020-01-17 13:37:05 +0200 | [diff] [blame] | 706 | subDelRespMsg, err := c.e2ap.UnpackSubscriptionDeleteResponse(params.Payload) |
Anssi Mannila | 2e99e2f | 2019-12-05 13:57:06 +0200 | [diff] [blame] | 707 | if err != nil { |
Juha Hyttinen | 83ada00 | 2020-01-30 10:36:33 +0200 | [diff] [blame] | 708 | xapp.Logger.Error("MSG-SubDelResp: %s", idstring(err, params)) |
Anssi Mannila | 2e99e2f | 2019-12-05 13:57:06 +0200 | [diff] [blame] | 709 | return |
| 710 | } |
Juha Hyttinen | aada645 | 2020-04-07 08:47:58 +0300 | [diff] [blame] | 711 | subs, err := c.registry.GetSubscriptionFirstMatch([]uint32{subDelRespMsg.RequestId.InstanceId}) |
Juha Hyttinen | 31797b4 | 2020-01-16 14:05:01 +0200 | [diff] [blame] | 712 | if err != nil { |
Juha Hyttinen | 83ada00 | 2020-01-30 10:36:33 +0200 | [diff] [blame] | 713 | xapp.Logger.Error("MSG-SubDelResp: %s", idstring(err, params)) |
Juha Hyttinen | 0d064ec | 2020-01-09 09:08:53 +0200 | [diff] [blame] | 714 | return |
| 715 | } |
Juha Hyttinen | 422d018 | 2020-01-17 13:37:05 +0200 | [diff] [blame] | 716 | trans := subs.GetTransaction() |
| 717 | if trans == nil { |
| 718 | err = fmt.Errorf("Ongoing transaction not found") |
Juha Hyttinen | 83ada00 | 2020-01-30 10:36:33 +0200 | [diff] [blame] | 719 | xapp.Logger.Error("MSG-SubDelResp: %s", idstring(err, params, subs)) |
Anssi Mannila | 8046c70 | 2020-01-02 13:39:05 +0200 | [diff] [blame] | 720 | return |
Anssi Mannila | 2e99e2f | 2019-12-05 13:57:06 +0200 | [diff] [blame] | 721 | } |
Juha Hyttinen | 422d018 | 2020-01-17 13:37:05 +0200 | [diff] [blame] | 722 | sendOk, timedOut := trans.SendEvent(subDelRespMsg, e2tRecvMsgTimeout) |
| 723 | if sendOk == false { |
| 724 | 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] | 725 | xapp.Logger.Error("MSG-SubDelResp: %s", idstring(err, trans, subs)) |
Juha Hyttinen | 60bfcf9 | 2020-01-14 15:14:24 +0200 | [diff] [blame] | 726 | } |
Anssi Mannila | 2e99e2f | 2019-12-05 13:57:06 +0200 | [diff] [blame] | 727 | return |
| 728 | } |
| 729 | |
Juha Hyttinen | 422d018 | 2020-01-17 13:37:05 +0200 | [diff] [blame] | 730 | //------------------------------------------------------------------- |
| 731 | // handle from E2T Subscription Delete Failure |
| 732 | //------------------------------------------------------------------- |
Juha Hyttinen | 9dc5adc | 2020-08-13 10:02:40 +0300 | [diff] [blame] | 733 | func (c *Control) handleE2TSubscriptionDeleteFailure(params *xapp.RMRParams) { |
Juha Hyttinen | 83ada00 | 2020-01-30 10:36:33 +0200 | [diff] [blame] | 734 | xapp.Logger.Info("MSG from E2T: %s", params.String()) |
Anssi Mannila | 4abf180 | 2021-01-28 13:06:46 +0200 | [diff] [blame] | 735 | c.UpdateCounter(cSubDelFailFromE2) |
Juha Hyttinen | 422d018 | 2020-01-17 13:37:05 +0200 | [diff] [blame] | 736 | subDelFailMsg, err := c.e2ap.UnpackSubscriptionDeleteFailure(params.Payload) |
Juha Hyttinen | 31797b4 | 2020-01-16 14:05:01 +0200 | [diff] [blame] | 737 | if err != nil { |
Juha Hyttinen | 83ada00 | 2020-01-30 10:36:33 +0200 | [diff] [blame] | 738 | xapp.Logger.Error("MSG-SubDelFail: %s", idstring(err, params)) |
Anssi Mannila | f1d0eb6 | 2019-12-17 15:29:55 +0200 | [diff] [blame] | 739 | return |
| 740 | } |
Juha Hyttinen | aada645 | 2020-04-07 08:47:58 +0300 | [diff] [blame] | 741 | subs, err := c.registry.GetSubscriptionFirstMatch([]uint32{subDelFailMsg.RequestId.InstanceId}) |
Anssi Mannila | 8046c70 | 2020-01-02 13:39:05 +0200 | [diff] [blame] | 742 | if err != nil { |
Juha Hyttinen | 83ada00 | 2020-01-30 10:36:33 +0200 | [diff] [blame] | 743 | xapp.Logger.Error("MSG-SubDelFail: %s", idstring(err, params)) |
Anssi Mannila | 8046c70 | 2020-01-02 13:39:05 +0200 | [diff] [blame] | 744 | return |
| 745 | } |
Juha Hyttinen | 422d018 | 2020-01-17 13:37:05 +0200 | [diff] [blame] | 746 | trans := subs.GetTransaction() |
| 747 | if trans == nil { |
| 748 | err = fmt.Errorf("Ongoing transaction not found") |
Juha Hyttinen | 83ada00 | 2020-01-30 10:36:33 +0200 | [diff] [blame] | 749 | xapp.Logger.Error("MSG-SubDelFail: %s", idstring(err, params, subs)) |
Juha Hyttinen | 86a4620 | 2020-01-14 12:49:09 +0200 | [diff] [blame] | 750 | return |
| 751 | } |
Juha Hyttinen | 422d018 | 2020-01-17 13:37:05 +0200 | [diff] [blame] | 752 | sendOk, timedOut := trans.SendEvent(subDelFailMsg, e2tRecvMsgTimeout) |
| 753 | if sendOk == false { |
| 754 | 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] | 755 | xapp.Logger.Error("MSG-SubDelFail: %s", idstring(err, trans, subs)) |
Anssi Mannila | 8046c70 | 2020-01-02 13:39:05 +0200 | [diff] [blame] | 756 | } |
kalnagy | 93cc3e2 | 2019-09-19 11:29:29 +0200 | [diff] [blame] | 757 | return |
| 758 | } |
| 759 | |
Juha Hyttinen | 422d018 | 2020-01-17 13:37:05 +0200 | [diff] [blame] | 760 | //------------------------------------------------------------------- |
| 761 | // |
| 762 | //------------------------------------------------------------------- |
| 763 | func typeofSubsMessage(v interface{}) string { |
| 764 | if v == nil { |
| 765 | return "NIL" |
kalnagy | 93cc3e2 | 2019-09-19 11:29:29 +0200 | [diff] [blame] | 766 | } |
Juha Hyttinen | 422d018 | 2020-01-17 13:37:05 +0200 | [diff] [blame] | 767 | switch v.(type) { |
| 768 | case *e2ap.E2APSubscriptionRequest: |
| 769 | return "SubReq" |
| 770 | case *e2ap.E2APSubscriptionResponse: |
| 771 | return "SubResp" |
| 772 | case *e2ap.E2APSubscriptionFailure: |
| 773 | return "SubFail" |
| 774 | case *e2ap.E2APSubscriptionDeleteRequest: |
| 775 | return "SubDelReq" |
| 776 | case *e2ap.E2APSubscriptionDeleteResponse: |
| 777 | return "SubDelResp" |
| 778 | case *e2ap.E2APSubscriptionDeleteFailure: |
| 779 | return "SubDelFail" |
| 780 | default: |
| 781 | return "Unknown" |
Juha Hyttinen | 31797b4 | 2020-01-16 14:05:01 +0200 | [diff] [blame] | 782 | } |
Anssi Mannila | f1d0eb6 | 2019-12-17 15:29:55 +0200 | [diff] [blame] | 783 | } |
Anssi Mannila | c92b421 | 2020-12-07 14:59:34 +0200 | [diff] [blame] | 784 | |
| 785 | //------------------------------------------------------------------- |
| 786 | // |
| 787 | //------------------------------------------------------------------- |
| 788 | func (c *Control) WriteSubscriptionToDb(subs *Subscription) { |
| 789 | xapp.Logger.Debug("WriteSubscriptionToDb() subId = %v", subs.ReqId.InstanceId) |
| 790 | err := c.WriteSubscriptionToSdl(subs.ReqId.InstanceId, subs) |
| 791 | if err != nil { |
| 792 | xapp.Logger.Error("%v", err) |
| 793 | } |
| 794 | } |
| 795 | |
| 796 | //------------------------------------------------------------------- |
| 797 | // |
| 798 | //------------------------------------------------------------------- |
| 799 | func (c *Control) UpdateSubscriptionInDB(subs *Subscription, removeSubscriptionFromDb bool) { |
| 800 | |
| 801 | if removeSubscriptionFromDb == true { |
| 802 | // Subscription was written in db already when subscription request was sent to BTS, except for merged request |
| 803 | c.RemoveSubscriptionFromDb(subs) |
| 804 | } else { |
| 805 | // Update is needed for successful response and merge case here |
| 806 | if subs.RetryFromXapp == false { |
| 807 | c.WriteSubscriptionToDb(subs) |
| 808 | } |
| 809 | } |
| 810 | subs.RetryFromXapp = false |
| 811 | } |
| 812 | |
| 813 | //------------------------------------------------------------------- |
| 814 | // |
| 815 | //------------------------------------------------------------------- |
| 816 | func (c *Control) RemoveSubscriptionFromDb(subs *Subscription) { |
| 817 | xapp.Logger.Debug("RemoveSubscriptionFromDb() subId = %v", subs.ReqId.InstanceId) |
| 818 | err := c.RemoveSubscriptionFromSdl(subs.ReqId.InstanceId) |
| 819 | if err != nil { |
| 820 | xapp.Logger.Error("%v", err) |
| 821 | } |
| 822 | } |
| 823 | |
| 824 | func (c *Control) SendSubscriptionDeleteReq(subs *Subscription) { |
| 825 | |
| 826 | xapp.Logger.Debug("Sending subscription delete due to restart. subId = %v", subs.ReqId.InstanceId) |
| 827 | |
| 828 | // Send delete for every endpoint in the subscription |
| 829 | subDelReqMsg := &e2ap.E2APSubscriptionDeleteRequest{} |
| 830 | subDelReqMsg.RequestId = subs.GetReqId().RequestId |
| 831 | subDelReqMsg.FunctionId = subs.SubReqMsg.FunctionId |
| 832 | mType, payload, err := c.e2ap.PackSubscriptionDeleteRequest(subDelReqMsg) |
| 833 | if err != nil { |
| 834 | xapp.Logger.Error("SendSubscriptionDeleteReq() %s", idstring(err)) |
| 835 | return |
| 836 | } |
| 837 | for _, endPoint := range subs.EpList.Endpoints { |
| 838 | params := &xapp.RMRParams{} |
| 839 | params.Mtype = mType |
| 840 | params.SubId = int(subs.GetReqId().InstanceId) |
| 841 | params.Xid = "" |
| 842 | params.Meid = subs.Meid |
| 843 | params.Src = endPoint.String() |
| 844 | params.PayloadLen = len(payload.Buf) |
| 845 | params.Payload = payload.Buf |
| 846 | params.Mbuf = nil |
| 847 | |
| 848 | if params == nil { |
| 849 | xapp.Logger.Error("SendSubscriptionDeleteReq() params == nil") |
| 850 | return |
| 851 | } |
| 852 | |
| 853 | subs.DeleteFromDb = true |
| 854 | c.handleXAPPSubscriptionDeleteRequest(params) |
| 855 | } |
| 856 | } |