blob: 706dc3b434df2f7f2f6d8a9d09ca6e0b6b40935e [file] [log] [blame]
kalnagy45114752019-06-18 14:40:39 +02001/*
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
20package control
21
kalnagy45114752019-06-18 14:40:39 +020022import (
Juha Hyttinene406a342020-01-13 13:02:26 +020023 "fmt"
Anssi Mannilac92b4212020-12-07 14:59:34 +020024 "net/http"
Anssi Mannila54838ed2021-11-19 11:25:01 +020025 "sync"
Anssi Mannilac92b4212020-12-07 14:59:34 +020026 "time"
27
Juha Hyttinen86a46202020-01-14 12:49:09 +020028 "gerrit.o-ran-sc.org/r/ric-plt/e2ap/pkg/e2ap"
kalnagy93cc3e22019-09-19 11:29:29 +020029 rtmgrclient "gerrit.o-ran-sc.org/r/ric-plt/submgr/pkg/rtmgr_client"
Juha Hyttinenc9eb08a2020-02-28 08:53:33 +020030 "gerrit.o-ran-sc.org/r/ric-plt/xapp-frame/pkg/models"
Anssi Mannilaf682ace2021-09-28 13:11:25 +030031 "gerrit.o-ran-sc.org/r/ric-plt/xapp-frame/pkg/restapi/operations/common"
kalnagy1455c852019-10-21 13:06:23 +020032 "gerrit.o-ran-sc.org/r/ric-plt/xapp-frame/pkg/xapp"
33 httptransport "github.com/go-openapi/runtime/client"
34 "github.com/go-openapi/strfmt"
archaggeafbf95f2021-04-14 08:54:05 +030035 "github.com/segmentio/ksuid"
kalnagy1455c852019-10-21 13:06:23 +020036 "github.com/spf13/viper"
kalnagy45114752019-06-18 14:40:39 +020037)
38
Juha Hyttinene406a342020-01-13 13:02:26 +020039//-----------------------------------------------------------------------------
40//
41//-----------------------------------------------------------------------------
42
Juha Hyttinen5f8ffa02020-02-06 15:28:59 +020043func idstring(err error, entries ...fmt.Stringer) string {
44 var retval string = ""
45 var filler string = ""
46 for _, entry := range entries {
Markku Virtanen42723e22021-06-15 10:09:23 +030047 if entry != nil {
48 retval += filler + entry.String()
49 filler = " "
50 } else {
51 retval += filler + "(NIL)"
52 }
Juha Hyttinen5f8ffa02020-02-06 15:28:59 +020053 }
54 if err != nil {
55 retval += filler + "err(" + err.Error() + ")"
56 filler = " "
Juha Hyttinen5f8ffa02020-02-06 15:28:59 +020057 }
58 return retval
59}
60
61//-----------------------------------------------------------------------------
62//
63//-----------------------------------------------------------------------------
64
Anssi Mannila2f26fb22020-12-07 08:32:13 +020065var e2tSubReqTimeout time.Duration
66var e2tSubDelReqTime time.Duration
67var e2tRecvMsgTimeout time.Duration
Markku Virtanenfe2cdab2021-05-21 10:59:29 +000068var waitRouteCleanup_ms time.Duration
Anssi Mannila2f26fb22020-12-07 08:32:13 +020069var e2tMaxSubReqTryCount uint64 // Initial try + retry
70var e2tMaxSubDelReqTryCount uint64 // Initial try + retry
Anssi Mannilac7da4ee2021-10-22 09:52:02 +030071var checkE2State string
Anssi Mannilac92b4212020-12-07 14:59:34 +020072var readSubsFromDb string
Anssi Mannilab73e7cd2021-08-03 11:57:11 +030073var dbRetryForever string
74var dbTryCount int
Anssi Mannila2e99e2f2019-12-05 13:57:06 +020075
kalnagy45114752019-06-18 14:40:39 +020076type Control struct {
Juha Hyttinen9dc5adc2020-08-13 10:02:40 +030077 *xapp.RMRClient
Anssi Mannila3cdd2e02021-10-14 12:35:41 +030078 e2ap *E2ap
79 registry *Registry
80 tracker *Tracker
81 restDuplicateCtrl *DuplicateCtrl
Anssi Mannilac7da4ee2021-10-22 09:52:02 +030082 e2IfState *E2IfState
83 e2IfStateDb XappRnibInterface
Anssi Mannila3cdd2e02021-10-14 12:35:41 +030084 e2SubsDb Sdlnterface
85 restSubsDb Sdlnterface
86 CntRecvMsg uint64
87 ResetTestFlag bool
88 Counters map[string]xapp.Counter
89 LoggerLevel int
90 UTTesting bool
kalnagy93cc3e22019-09-19 11:29:29 +020091}
92
93type RMRMeid struct {
Juha Hyttinenff8dccd2019-12-10 14:34:07 +020094 PlmnID string
95 EnbID string
Anssi Mannila2e99e2f2019-12-05 13:57:06 +020096 RanName string
kalnagy93cc3e22019-09-19 11:29:29 +020097}
98
Anssi Mannilac92b4212020-12-07 14:59:34 +020099type SubmgrRestartTestEvent struct{}
100type SubmgrRestartUpEvent struct{}
Anssi Mannilaf682ace2021-09-28 13:11:25 +0300101type PackSubscriptionRequestErrortEvent struct {
102 ErrorInfo ErrorInfo
103}
104
105func (p *PackSubscriptionRequestErrortEvent) SetEvent(errorInfo *ErrorInfo) {
106 p.ErrorInfo = *errorInfo
107}
108
109type SDLWriteErrortEvent struct {
110 ErrorInfo ErrorInfo
111}
112
113func (s *SDLWriteErrortEvent) SetEvent(errorInfo *ErrorInfo) {
114 s.ErrorInfo = *errorInfo
115}
Anssi Mannilac92b4212020-12-07 14:59:34 +0200116
Peter Szilagyifbc56f92019-07-23 19:29:46 +0000117func init() {
Anssi Mannilaf682ace2021-09-28 13:11:25 +0300118 xapp.Logger.Debug("SUBMGR")
Peter Szilagyifbc56f92019-07-23 19:29:46 +0000119 viper.AutomaticEnv()
120 viper.SetEnvPrefix("submgr")
121 viper.AllowEmptyEnv(true)
kalnagy45114752019-06-18 14:40:39 +0200122}
123
Juha Hyttinenff8dccd2019-12-10 14:34:07 +0200124func NewControl() *Control {
Juha Hyttinen0388dd92020-01-09 14:14:16 +0200125
Anssi Mannilac92b4212020-12-07 14:59:34 +0200126 transport := httptransport.New(viper.GetString("rtmgr.HostAddr")+":"+viper.GetString("rtmgr.port"), viper.GetString("rtmgr.baseUrl"), []string{"http"})
127 rtmgrClient := RtmgrClient{rtClient: rtmgrclient.New(transport, strfmt.Default)}
128
129 registry := new(Registry)
130 registry.Initialize()
131 registry.rtmgrClient = &rtmgrClient
132
133 tracker := new(Tracker)
134 tracker.Init()
135
Anssi Mannila3cdd2e02021-10-14 12:35:41 +0300136 restDuplicateCtrl := new(DuplicateCtrl)
137 restDuplicateCtrl.Init()
138
Anssi Mannilac7da4ee2021-10-22 09:52:02 +0300139 e2IfState := new(E2IfState)
140
Anssi Mannilac92b4212020-12-07 14:59:34 +0200141 c := &Control{e2ap: new(E2ap),
Anssi Mannila3cdd2e02021-10-14 12:35:41 +0300142 registry: registry,
143 tracker: tracker,
144 restDuplicateCtrl: restDuplicateCtrl,
Anssi Mannilac7da4ee2021-10-22 09:52:02 +0300145 e2IfState: e2IfState,
146 e2IfStateDb: CreateXappRnibIfInstance(),
Anssi Mannila3cdd2e02021-10-14 12:35:41 +0300147 e2SubsDb: CreateSdl(),
148 restSubsDb: CreateRESTSdl(),
149 Counters: xapp.Metric.RegisterCounterGroup(GetMetricsOpts(), "SUBMGR"),
Anssi Mannilae1af87f2021-11-10 13:10:54 +0200150 LoggerLevel: 1,
Anssi Mannilac92b4212020-12-07 14:59:34 +0200151 }
Anssi Mannilac7da4ee2021-10-22 09:52:02 +0300152
153 e2IfState.Init(c)
Anssi Mannilaf6b78042021-02-18 12:36:59 +0200154 c.ReadConfigParameters("")
Anssi Mannilac92b4212020-12-07 14:59:34 +0200155
156 // Register REST handler for testing support
Anssi Mannila92c38552021-12-29 09:59:24 +0200157 xapp.Resource.InjectRoute("/ric/v1/symptomdata", c.SymptomDataHandler, "GET")
Anssi Mannilac92b4212020-12-07 14:59:34 +0200158 xapp.Resource.InjectRoute("/ric/v1/test/{testId}", c.TestRestHandler, "POST")
Anssi Mannilab73e7cd2021-08-03 11:57:11 +0300159 xapp.Resource.InjectRoute("/ric/v1/restsubscriptions", c.GetAllRestSubscriptions, "GET")
Anssi Mannila92c38552021-12-29 09:59:24 +0200160
161 xapp.Resource.InjectRoute("/ric/v1/get_all_e2nodes", c.GetAllE2Nodes, "GET")
162 xapp.Resource.InjectRoute("/ric/v1/get_e2node_rest_subscriptions/{ranName}", c.GetAllE2NodeRestSubscriptions, "GET")
163
164 xapp.Resource.InjectRoute("/ric/v1/get_all_xapps", c.GetAllXapps, "GET")
165 xapp.Resource.InjectRoute("/ric/v1/get_xapp_rest_restsubscriptions/{xappServiceName}", c.GetAllXappRestSubscriptions, "GET")
166 xapp.Resource.InjectRoute("/ric/v1/get_e2subscriptions/{restId}", c.GetE2Subscriptions, "GET")
167
Anssi Mannilad13ba632022-01-04 14:22:26 +0200168 xapp.Resource.InjectRoute("/ric/v1/delete_all_e2node_subscriptions/{ranName}", c.DeleteAllE2nodeSubscriptions, "DELETE")
169 xapp.Resource.InjectRoute("/ric/v1/delete_all_xapp_subscriptions/{xappServiceName}", c.DeleteAllXappSubscriptions, "DELETE")
Anssi Mannilac92b4212020-12-07 14:59:34 +0200170
Anssi Mannilae1af87f2021-11-10 13:10:54 +0200171 if readSubsFromDb == "true" {
172 // Read subscriptions from db
Anssi Mannila9c4697f2022-07-04 15:51:38 +0300173 err := c.ReadE2Subscriptions()
174 if err != nil {
175 xapp.Logger.Error("ReadE2Subscriptions() failed %s", err.Error())
176 }
177 err = c.ReadRESTSubscriptions()
178 if err != nil {
179 xapp.Logger.Error("ReadRESTSubscriptions() failed %s", err.Error())
180 }
Anssi Mannilac92b4212020-12-07 14:59:34 +0200181 }
182
Anssi Mannila55d6fed2022-08-02 12:41:48 +0300183 go func() {
184 err := xapp.Subscription.Listen(c.RESTSubscriptionHandler, c.RESTQueryHandler, c.RESTSubscriptionDeleteHandler)
185 if err != nil {
186 xapp.Logger.Error("xapp.Subscription.Listen failure: %s", err.Error())
187 }
188 }()
Anssi Mannilac92b4212020-12-07 14:59:34 +0200189 return c
190}
191
Abukar Mohamedfbd4df52021-03-11 06:13:27 +0000192func (c *Control) SymptomDataHandler(w http.ResponseWriter, r *http.Request) {
Anssi Mannila9c4697f2022-07-04 15:51:38 +0300193 subscriptions, err := c.registry.QueryHandler()
194 if err != nil {
195 xapp.Logger.Error("QueryHandler() failed %s", err.Error())
196 }
197
Abukar Mohamedfbd4df52021-03-11 06:13:27 +0000198 xapp.Resource.SendSymptomDataJson(w, r, subscriptions, "platform/subscriptions.json")
199}
200
Anssi Mannilac92b4212020-12-07 14:59:34 +0200201//-------------------------------------------------------------------
202//
203//-------------------------------------------------------------------
Anssi Mannila92c38552021-12-29 09:59:24 +0200204func (c *Control) RESTQueryHandler() (models.SubscriptionList, error) {
205 xapp.Logger.Debug("RESTQueryHandler() called")
206
207 c.CntRecvMsg++
208
209 return c.registry.QueryHandler()
Anssi Mannilab73e7cd2021-08-03 11:57:11 +0300210}
211
212//-------------------------------------------------------------------
213//
214//-------------------------------------------------------------------
215func (c *Control) ReadE2Subscriptions() error {
216 var err error
217 var subIds []uint32
218 var register map[uint32]*Subscription
219 for i := 0; dbRetryForever == "true" || i < dbTryCount; i++ {
Anssi Mannilaf682ace2021-09-28 13:11:25 +0300220 xapp.Logger.Debug("Reading E2 subscriptions from db")
Anssi Mannilab73e7cd2021-08-03 11:57:11 +0300221 subIds, register, err = c.ReadAllSubscriptionsFromSdl()
222 if err != nil {
223 xapp.Logger.Error("%v", err)
224 <-time.After(1 * time.Second)
225 } else {
226 c.registry.subIds = subIds
227 c.registry.register = register
Anssi Mannila316b8d22021-12-21 09:43:59 +0200228 go c.HandleUncompletedSubscriptions(register)
Anssi Mannilab73e7cd2021-08-03 11:57:11 +0300229 return nil
230 }
231 }
Anssi Mannilaf682ace2021-09-28 13:11:25 +0300232 xapp.Logger.Debug("Continuing without retring")
Anssi Mannilab73e7cd2021-08-03 11:57:11 +0300233 return err
234}
235
236//-------------------------------------------------------------------
237//
238//-------------------------------------------------------------------
239func (c *Control) ReadRESTSubscriptions() error {
Anssi Mannila54838ed2021-11-19 11:25:01 +0200240
241 xapp.Logger.Debug("ReadRESTSubscriptions()")
Anssi Mannilab73e7cd2021-08-03 11:57:11 +0300242 var err error
243 var restSubscriptions map[string]*RESTSubscription
244 for i := 0; dbRetryForever == "true" || i < dbTryCount; i++ {
Anssi Mannilaf682ace2021-09-28 13:11:25 +0300245 xapp.Logger.Debug("Reading REST subscriptions from db")
Anssi Mannilab73e7cd2021-08-03 11:57:11 +0300246 restSubscriptions, err = c.ReadAllRESTSubscriptionsFromSdl()
247 if err != nil {
248 xapp.Logger.Error("%v", err)
249 <-time.After(1 * time.Second)
250 } else {
Anssi Mannila54838ed2021-11-19 11:25:01 +0200251 // Fix REST subscriptions ongoing status after restart
252 for restSubId, restSubscription := range restSubscriptions {
253 restSubscription.SubReqOngoing = false
254 restSubscription.SubDelReqOngoing = false
Anssi Mannila9c4697f2022-07-04 15:51:38 +0300255 err := c.WriteRESTSubscriptionToSdl(restSubId, restSubscription)
256 if err != nil {
257 xapp.Logger.Error("WriteRESTSubscriptionToSdl() failed:%s", err.Error())
258 }
Anssi Mannila54838ed2021-11-19 11:25:01 +0200259 }
Anssi Mannilab73e7cd2021-08-03 11:57:11 +0300260 c.registry.restSubscriptions = restSubscriptions
261 return nil
262 }
263 }
Anssi Mannilaf682ace2021-09-28 13:11:25 +0300264 xapp.Logger.Debug("Continuing without retring")
Anssi Mannilab73e7cd2021-08-03 11:57:11 +0300265 return err
266}
267
268//-------------------------------------------------------------------
269//
270//-------------------------------------------------------------------
Anssi Mannilaf6b78042021-02-18 12:36:59 +0200271func (c *Control) ReadConfigParameters(f string) {
Anssi Mannilac92b4212020-12-07 14:59:34 +0200272
Anssi Mannilac7da4ee2021-10-22 09:52:02 +0300273 xapp.Logger.Debug("ReadConfigParameters")
274
Anssi Mannilaf682ace2021-09-28 13:11:25 +0300275 c.LoggerLevel = int(xapp.Logger.GetLevel())
Anssi Mannila3d80b722021-11-12 13:17:15 +0200276 xapp.Logger.Info("LoggerLevel = %v", c.LoggerLevel)
Anssi Mannilae1af87f2021-11-10 13:10:54 +0200277 c.e2ap.SetASN1DebugPrintStatus(c.LoggerLevel)
Anssi Mannilaf682ace2021-09-28 13:11:25 +0300278
Anssi Mannila2f26fb22020-12-07 08:32:13 +0200279 // viper.GetDuration returns nanoseconds
280 e2tSubReqTimeout = viper.GetDuration("controls.e2tSubReqTimeout_ms") * 1000000
Juha Hyttinen57140bc2020-12-11 13:03:06 +0200281 if e2tSubReqTimeout == 0 {
282 e2tSubReqTimeout = 2000 * 1000000
Anssi Mannilac7da4ee2021-10-22 09:52:02 +0300283 xapp.Logger.Debug("WARNING: Using hard coded default value for e2tSubReqTimeout")
Juha Hyttinen57140bc2020-12-11 13:03:06 +0200284 }
Anssi Mannilac7da4ee2021-10-22 09:52:02 +0300285 xapp.Logger.Debug("e2tSubReqTimeout= %v", e2tSubReqTimeout)
Anssi Mannilaf682ace2021-09-28 13:11:25 +0300286
Anssi Mannila2f26fb22020-12-07 08:32:13 +0200287 e2tSubDelReqTime = viper.GetDuration("controls.e2tSubDelReqTime_ms") * 1000000
Juha Hyttinen57140bc2020-12-11 13:03:06 +0200288 if e2tSubDelReqTime == 0 {
289 e2tSubDelReqTime = 2000 * 1000000
Anssi Mannilac7da4ee2021-10-22 09:52:02 +0300290 xapp.Logger.Debug("WARNING: Using hard coded default value for e2tSubDelReqTime")
Juha Hyttinen57140bc2020-12-11 13:03:06 +0200291 }
Anssi Mannilac7da4ee2021-10-22 09:52:02 +0300292 xapp.Logger.Debug("e2tSubDelReqTime= %v", e2tSubDelReqTime)
293
Anssi Mannila2f26fb22020-12-07 08:32:13 +0200294 e2tRecvMsgTimeout = viper.GetDuration("controls.e2tRecvMsgTimeout_ms") * 1000000
Juha Hyttinen57140bc2020-12-11 13:03:06 +0200295 if e2tRecvMsgTimeout == 0 {
296 e2tRecvMsgTimeout = 2000 * 1000000
Anssi Mannilac7da4ee2021-10-22 09:52:02 +0300297 xapp.Logger.Debug("WARNING: Using hard coded default value for e2tRecvMsgTimeout")
Juha Hyttinen57140bc2020-12-11 13:03:06 +0200298 }
Anssi Mannilac7da4ee2021-10-22 09:52:02 +0300299 xapp.Logger.Debug("e2tRecvMsgTimeout= %v", e2tRecvMsgTimeout)
Markku Virtanenfe2cdab2021-05-21 10:59:29 +0000300
Anssi Mannila2f26fb22020-12-07 08:32:13 +0200301 e2tMaxSubReqTryCount = viper.GetUint64("controls.e2tMaxSubReqTryCount")
Juha Hyttinen57140bc2020-12-11 13:03:06 +0200302 if e2tMaxSubReqTryCount == 0 {
303 e2tMaxSubReqTryCount = 1
Anssi Mannilac7da4ee2021-10-22 09:52:02 +0300304 xapp.Logger.Debug("WARNING: Using hard coded default value for e2tMaxSubReqTryCount")
Juha Hyttinen57140bc2020-12-11 13:03:06 +0200305 }
Anssi Mannilac7da4ee2021-10-22 09:52:02 +0300306 xapp.Logger.Debug("e2tMaxSubReqTryCount= %v", e2tMaxSubReqTryCount)
Markku Virtanenfe2cdab2021-05-21 10:59:29 +0000307
Anssi Mannila2f26fb22020-12-07 08:32:13 +0200308 e2tMaxSubDelReqTryCount = viper.GetUint64("controls.e2tMaxSubDelReqTryCount")
Juha Hyttinen57140bc2020-12-11 13:03:06 +0200309 if e2tMaxSubDelReqTryCount == 0 {
310 e2tMaxSubDelReqTryCount = 1
Anssi Mannilac7da4ee2021-10-22 09:52:02 +0300311 xapp.Logger.Debug("WARNING: Using hard coded default value for e2tMaxSubDelReqTryCount")
Juha Hyttinen57140bc2020-12-11 13:03:06 +0200312 }
Anssi Mannilac7da4ee2021-10-22 09:52:02 +0300313 xapp.Logger.Debug("e2tMaxSubDelReqTryCount= %v", e2tMaxSubDelReqTryCount)
314
315 checkE2State = viper.GetString("controls.checkE2State")
316 if checkE2State == "" {
317 checkE2State = "true"
318 xapp.Logger.Debug("WARNING: Using hard coded default value for checkE2State")
319 }
320 xapp.Logger.Debug("checkE2State= %v", checkE2State)
Anssi Mannila2f26fb22020-12-07 08:32:13 +0200321
Anssi Mannilac92b4212020-12-07 14:59:34 +0200322 readSubsFromDb = viper.GetString("controls.readSubsFromDb")
323 if readSubsFromDb == "" {
324 readSubsFromDb = "true"
Anssi Mannilac7da4ee2021-10-22 09:52:02 +0300325 xapp.Logger.Debug("WARNING: Using hard coded default value for readSubsFromDb")
Juha Hyttinen5f8ffa02020-02-06 15:28:59 +0200326 }
Anssi Mannilac7da4ee2021-10-22 09:52:02 +0300327 xapp.Logger.Debug("readSubsFromDb= %v", readSubsFromDb)
Anssi Mannilab73e7cd2021-08-03 11:57:11 +0300328
329 dbTryCount = viper.GetInt("controls.dbTryCount")
330 if dbTryCount == 0 {
331 dbTryCount = 200
Anssi Mannilac7da4ee2021-10-22 09:52:02 +0300332 xapp.Logger.Debug("WARNING: Using hard coded default value for dbTryCount")
Anssi Mannilab73e7cd2021-08-03 11:57:11 +0300333 }
Anssi Mannilac7da4ee2021-10-22 09:52:02 +0300334 xapp.Logger.Debug("dbTryCount= %v", dbTryCount)
Anssi Mannilab73e7cd2021-08-03 11:57:11 +0300335
336 dbRetryForever = viper.GetString("controls.dbRetryForever")
337 if dbRetryForever == "" {
338 dbRetryForever = "true"
Anssi Mannilac7da4ee2021-10-22 09:52:02 +0300339 xapp.Logger.Debug("WARNING: Using hard coded default value for dbRetryForever")
Anssi Mannilab73e7cd2021-08-03 11:57:11 +0300340 }
Anssi Mannilac7da4ee2021-10-22 09:52:02 +0300341 xapp.Logger.Debug("dbRetryForever= %v", dbRetryForever)
Anssi Mannilab73e7cd2021-08-03 11:57:11 +0300342
343 // Internal cfg parameter, used to define a wait time for RMR route clean-up. None default
344 // value 100ms used currently only in unittests.
345 waitRouteCleanup_ms = viper.GetDuration("controls.waitRouteCleanup_ms") * 1000000
346 if waitRouteCleanup_ms == 0 {
347 waitRouteCleanup_ms = 5000 * 1000000
Anssi Mannilac7da4ee2021-10-22 09:52:02 +0300348 xapp.Logger.Debug("WARNING: Using hard coded default value for waitRouteCleanup_ms")
Anssi Mannilab73e7cd2021-08-03 11:57:11 +0300349 }
Anssi Mannilac7da4ee2021-10-22 09:52:02 +0300350 xapp.Logger.Debug("waitRouteCleanup= %v", waitRouteCleanup_ms)
Anssi Mannilac92b4212020-12-07 14:59:34 +0200351}
352
353//-------------------------------------------------------------------
354//
355//-------------------------------------------------------------------
356func (c *Control) HandleUncompletedSubscriptions(register map[uint32]*Subscription) {
357
358 xapp.Logger.Debug("HandleUncompletedSubscriptions. len(register) = %v", len(register))
359 for subId, subs := range register {
360 if subs.SubRespRcvd == false {
Anssi Mannilaf682ace2021-09-28 13:11:25 +0300361 // If policy subscription has already been made successfully unsuccessful update should not be deleted.
362 if subs.PolicyUpdate == false {
363 subs.NoRespToXapp = true
364 xapp.Logger.Debug("SendSubscriptionDeleteReq. subId = %v", subId)
365 c.SendSubscriptionDeleteReq(subs)
366 }
Anssi Mannilac92b4212020-12-07 14:59:34 +0200367 }
368 }
Juha Hyttinen5f8ffa02020-02-06 15:28:59 +0200369}
370
371func (c *Control) ReadyCB(data interface{}) {
Juha Hyttinen9dc5adc2020-08-13 10:02:40 +0300372 if c.RMRClient == nil {
373 c.RMRClient = xapp.Rmr
Juha Hyttinenff8dccd2019-12-10 14:34:07 +0200374 }
kalnagy45114752019-06-18 14:40:39 +0200375}
376
377func (c *Control) Run() {
Juha Hyttinen5f8ffa02020-02-06 15:28:59 +0200378 xapp.SetReadyCB(c.ReadyCB, nil)
Anssi Mannilaf6b78042021-02-18 12:36:59 +0200379 xapp.AddConfigChangeListener(c.ReadConfigParameters)
Peter Szilagyifbc56f92019-07-23 19:29:46 +0000380 xapp.Run(c)
kalnagy45114752019-06-18 14:40:39 +0200381}
382
Juha Hyttinenc9eb08a2020-02-28 08:53:33 +0200383//-------------------------------------------------------------------
384//
385//-------------------------------------------------------------------
Anssi Mannila92c38552021-12-29 09:59:24 +0200386func (c *Control) GetOrCreateRestSubscription(p *models.SubscriptionParams, md5sum string, xAppRmrEndpoint string, xAppServiceName string) (*RESTSubscription, string, error) {
Markku Virtanen42723e22021-06-15 10:09:23 +0300387
388 var restSubId string
389 var restSubscription *RESTSubscription
390 var err error
391
Anssi Mannila3cdd2e02021-10-14 12:35:41 +0300392 prevRestSubsId, exists := c.restDuplicateCtrl.GetLastKnownRestSubsIdBasedOnMd5sum(md5sum)
Markku Virtanen42723e22021-06-15 10:09:23 +0300393 if p.SubscriptionID == "" {
Anssi Mannilaf682ace2021-09-28 13:11:25 +0300394 // Subscription does not contain REST subscription Id
Markku Virtanen42723e22021-06-15 10:09:23 +0300395 if exists {
396 restSubscription, err = c.registry.GetRESTSubscription(prevRestSubsId, false)
397 if restSubscription != nil {
Anssi Mannilaf682ace2021-09-28 13:11:25 +0300398 // Subscription not found
Markku Virtanen42723e22021-06-15 10:09:23 +0300399 restSubId = prevRestSubsId
400 if err == nil {
Anssi Mannilaf682ace2021-09-28 13:11:25 +0300401 xapp.Logger.Debug("Existing restSubId %s found by MD5sum %s for a request without subscription ID - using previous subscription", prevRestSubsId, md5sum)
Markku Virtanen42723e22021-06-15 10:09:23 +0300402 } else {
Anssi Mannilaf682ace2021-09-28 13:11:25 +0300403 xapp.Logger.Debug("Existing restSubId %s found by MD5sum %s for a request without subscription ID - Note: %s", prevRestSubsId, md5sum, err.Error())
Markku Virtanen42723e22021-06-15 10:09:23 +0300404 }
405 } else {
Anssi Mannilaf682ace2021-09-28 13:11:25 +0300406 xapp.Logger.Debug("None existing restSubId %s referred by MD5sum %s for a request without subscription ID - deleting cached entry", prevRestSubsId, md5sum)
Anssi Mannila3cdd2e02021-10-14 12:35:41 +0300407 c.restDuplicateCtrl.DeleteLastKnownRestSubsIdBasedOnMd5sum(md5sum)
Markku Virtanen42723e22021-06-15 10:09:23 +0300408 }
409 }
410
411 if restSubscription == nil {
412 restSubId = ksuid.New().String()
Anssi Mannila92c38552021-12-29 09:59:24 +0200413 restSubscription = c.registry.CreateRESTSubscription(&restSubId, &xAppServiceName, &xAppRmrEndpoint, p.Meid)
Markku Virtanen42723e22021-06-15 10:09:23 +0300414 }
415 } else {
Anssi Mannilaf682ace2021-09-28 13:11:25 +0300416 // Subscription contains REST subscription Id
Markku Virtanen42723e22021-06-15 10:09:23 +0300417 restSubId = p.SubscriptionID
418
Anssi Mannilaf682ace2021-09-28 13:11:25 +0300419 xapp.Logger.Debug("RestSubscription ID %s provided via REST request", restSubId)
Markku Virtanen42723e22021-06-15 10:09:23 +0300420 restSubscription, err = c.registry.GetRESTSubscription(restSubId, false)
421 if err != nil {
Anssi Mannilaf682ace2021-09-28 13:11:25 +0300422 // Subscription with id in REST request does not exist
Markku Virtanen42723e22021-06-15 10:09:23 +0300423 xapp.Logger.Error("%s", err.Error())
424 c.UpdateCounter(cRestSubFailToXapp)
Anssi Mannilacb7dd492021-10-01 11:10:26 +0300425 return nil, "", err
Markku Virtanen42723e22021-06-15 10:09:23 +0300426 }
427
428 if !exists {
Anssi Mannilaf682ace2021-09-28 13:11:25 +0300429 xapp.Logger.Debug("Existing restSubscription found for ID %s, new request based on md5sum", restSubId)
Markku Virtanen42723e22021-06-15 10:09:23 +0300430 } else {
Anssi Mannilaf682ace2021-09-28 13:11:25 +0300431 xapp.Logger.Debug("Existing restSubscription found for ID %s(%s), re-transmission based on md5sum match with previous request", prevRestSubsId, restSubId)
Markku Virtanen42723e22021-06-15 10:09:23 +0300432 }
433 }
434
Anssi Mannilacb7dd492021-10-01 11:10:26 +0300435 return restSubscription, restSubId, nil
Markku Virtanen42723e22021-06-15 10:09:23 +0300436}
437
438//-------------------------------------------------------------------
439//
440//-------------------------------------------------------------------
Anssi Mannilaf682ace2021-09-28 13:11:25 +0300441func (c *Control) RESTSubscriptionHandler(params interface{}) (*models.SubscriptionResponse, int) {
archaggeafbf95f2021-04-14 08:54:05 +0300442
Anssi Mannila316d8a12021-06-02 11:08:54 +0300443 c.CntRecvMsg++
444 c.UpdateCounter(cRestSubReqFromXapp)
445
archaggeafbf95f2021-04-14 08:54:05 +0300446 subResp := models.SubscriptionResponse{}
archaggeafbf95f2021-04-14 08:54:05 +0300447 p := params.(*models.SubscriptionParams)
448
Anssi Mannilade457a12021-06-02 16:19:48 +0300449 if c.LoggerLevel > 2 {
450 c.PrintRESTSubscriptionRequest(p)
451 }
452
Anssi Mannilac7da4ee2021-10-22 09:52:02 +0300453 if c.e2IfState.IsE2ConnectionUp(p.Meid) == false {
454 xapp.Logger.Error("No E2 connection for ranName %v", *p.Meid)
455 c.UpdateCounter(cRestReqRejDueE2Down)
456 return nil, common.SubscribeServiceUnavailableCode
457 }
458
archaggeafbf95f2021-04-14 08:54:05 +0300459 if p.ClientEndpoint == nil {
Anssi Mannilaf682ace2021-09-28 13:11:25 +0300460 err := fmt.Errorf("ClientEndpoint == nil")
461 xapp.Logger.Error("%v", err)
Anssi Mannila316d8a12021-06-02 11:08:54 +0300462 c.UpdateCounter(cRestSubFailToXapp)
Anssi Mannilacb7dd492021-10-01 11:10:26 +0300463 return nil, common.SubscribeBadRequestCode
archaggeafbf95f2021-04-14 08:54:05 +0300464 }
465
Anssi Mannila6bd57912022-06-16 09:47:23 +0300466 e2SubscriptionDirectives, err := c.GetE2SubscriptionDirectives(p)
467 if err != nil {
468 xapp.Logger.Error("%s", err)
469 c.UpdateCounter(cRestSubFailToXapp)
470 return nil, common.SubscribeBadRequestCode
471 }
archaggeafbf95f2021-04-14 08:54:05 +0300472 _, xAppRmrEndpoint, err := ConstructEndpointAddresses(*p.ClientEndpoint)
473 if err != nil {
474 xapp.Logger.Error("%s", err.Error())
Anssi Mannila316d8a12021-06-02 11:08:54 +0300475 c.UpdateCounter(cRestSubFailToXapp)
Anssi Mannilacb7dd492021-10-01 11:10:26 +0300476 return nil, common.SubscribeBadRequestCode
archaggeafbf95f2021-04-14 08:54:05 +0300477 }
478
Markku Virtanen42723e22021-06-15 10:09:23 +0300479 md5sum, err := CalculateRequestMd5sum(params)
480 if err != nil {
481 xapp.Logger.Error("Failed to generate md5sum from incoming request - %s", err.Error())
482 }
483
Anssi Mannila92c38552021-12-29 09:59:24 +0200484 restSubscription, restSubId, err := c.GetOrCreateRestSubscription(p, md5sum, xAppRmrEndpoint, p.ClientEndpoint.Host)
Markku Virtanen42723e22021-06-15 10:09:23 +0300485 if err != nil {
Anssi Mannilacb7dd492021-10-01 11:10:26 +0300486 xapp.Logger.Error("Subscription with id in REST request does not exist")
487 return nil, common.SubscribeNotFoundCode
archaggeafbf95f2021-04-14 08:54:05 +0300488 }
489
Konstantinos Archangelofe93b00f2021-06-03 10:00:19 +0000490 subResp.SubscriptionID = &restSubId
archaggeafbf95f2021-04-14 08:54:05 +0300491 subReqList := e2ap.SubscriptionRequestList{}
492 err = c.e2ap.FillSubscriptionReqMsgs(params, &subReqList, restSubscription)
493 if err != nil {
494 xapp.Logger.Error("%s", err.Error())
Anssi Mannila3cdd2e02021-10-14 12:35:41 +0300495 c.restDuplicateCtrl.DeleteLastKnownRestSubsIdBasedOnMd5sum(md5sum)
archaggeafbf95f2021-04-14 08:54:05 +0300496 c.registry.DeleteRESTSubscription(&restSubId)
Anssi Mannila316d8a12021-06-02 11:08:54 +0300497 c.UpdateCounter(cRestSubFailToXapp)
Anssi Mannilacb7dd492021-10-01 11:10:26 +0300498 return nil, common.SubscribeBadRequestCode
archaggeafbf95f2021-04-14 08:54:05 +0300499 }
500
Anssi Mannila3cdd2e02021-10-14 12:35:41 +0300501 duplicate := c.restDuplicateCtrl.IsDuplicateToOngoingTransaction(restSubId, md5sum)
Markku Virtanen42723e22021-06-15 10:09:23 +0300502 if duplicate {
Anssi Mannilaf682ace2021-09-28 13:11:25 +0300503 err := fmt.Errorf("Retransmission blocker direct ACK for request of restSubsId %s restSubId MD5sum %s as retransmission", restSubId, md5sum)
504 xapp.Logger.Debug("%s", err)
Anssi Mannilab43397e2021-11-16 12:06:16 +0200505 c.registry.DeleteRESTSubscription(&restSubId)
Markku Virtanen42723e22021-06-15 10:09:23 +0300506 c.UpdateCounter(cRestSubRespToXapp)
Anssi Mannilaf682ace2021-09-28 13:11:25 +0300507 return &subResp, common.SubscribeCreatedCode
Markku Virtanenb642a192021-06-09 09:08:14 +0000508 }
509
Markku Virtanencd73ecc2021-06-23 06:16:01 +0000510 c.WriteRESTSubscriptionToDb(restSubId, restSubscription)
Anssi Mannilaf682ace2021-09-28 13:11:25 +0300511 go c.processSubscriptionRequests(restSubscription, &subReqList, p.ClientEndpoint, p.Meid, &restSubId, xAppRmrEndpoint, md5sum, e2SubscriptionDirectives)
archaggeafbf95f2021-04-14 08:54:05 +0300512
Anssi Mannila316d8a12021-06-02 11:08:54 +0300513 c.UpdateCounter(cRestSubRespToXapp)
Anssi Mannilaf682ace2021-09-28 13:11:25 +0300514 return &subResp, common.SubscribeCreatedCode
515}
516
517//-------------------------------------------------------------------
518//
519//-------------------------------------------------------------------
520func (c *Control) GetE2SubscriptionDirectives(p *models.SubscriptionParams) (*E2SubscriptionDirectives, error) {
521
522 e2SubscriptionDirectives := &E2SubscriptionDirectives{}
523 if p == nil || p.E2SubscriptionDirectives == nil {
524 e2SubscriptionDirectives.E2TimeoutTimerValue = e2tSubReqTimeout
525 e2SubscriptionDirectives.E2MaxTryCount = int64(e2tMaxSubReqTryCount)
526 e2SubscriptionDirectives.CreateRMRRoute = true
527 xapp.Logger.Debug("p == nil || p.E2SubscriptionDirectives == nil. Using default values for E2TimeoutTimerValue = %v and E2RetryCount = %v RMRRoutingNeeded = true", e2tSubReqTimeout, e2tMaxSubReqTryCount)
528 } else {
529 if p.E2SubscriptionDirectives.E2TimeoutTimerValue >= 1 && p.E2SubscriptionDirectives.E2TimeoutTimerValue <= 10 {
530 e2SubscriptionDirectives.E2TimeoutTimerValue = time.Duration(p.E2SubscriptionDirectives.E2TimeoutTimerValue) * 1000000000 // Duration type cast returns nano seconds
531 } else {
532 return nil, fmt.Errorf("p.E2SubscriptionDirectives.E2TimeoutTimerValue out of range (1-10 seconds): %v", p.E2SubscriptionDirectives.E2TimeoutTimerValue)
533 }
534 if p.E2SubscriptionDirectives.E2RetryCount == nil {
535 xapp.Logger.Error("p.E2SubscriptionDirectives.E2RetryCount == nil. Using default value")
536 e2SubscriptionDirectives.E2MaxTryCount = int64(e2tMaxSubReqTryCount)
537 } else {
538 if *p.E2SubscriptionDirectives.E2RetryCount >= 0 && *p.E2SubscriptionDirectives.E2RetryCount <= 10 {
539 e2SubscriptionDirectives.E2MaxTryCount = *p.E2SubscriptionDirectives.E2RetryCount + 1 // E2MaxTryCount = First sending plus two retries
540 } else {
541 return nil, fmt.Errorf("p.E2SubscriptionDirectives.E2RetryCount out of range (0-10): %v", *p.E2SubscriptionDirectives.E2RetryCount)
542 }
543 }
Anssi Mannilacb7dd492021-10-01 11:10:26 +0300544 e2SubscriptionDirectives.CreateRMRRoute = p.E2SubscriptionDirectives.RMRRoutingNeeded
Anssi Mannilaf682ace2021-09-28 13:11:25 +0300545 }
546 xapp.Logger.Debug("e2SubscriptionDirectives.E2TimeoutTimerValue: %v", e2SubscriptionDirectives.E2TimeoutTimerValue)
547 xapp.Logger.Debug("e2SubscriptionDirectives.E2MaxTryCount: %v", e2SubscriptionDirectives.E2MaxTryCount)
548 xapp.Logger.Debug("e2SubscriptionDirectives.CreateRMRRoute: %v", e2SubscriptionDirectives.CreateRMRRoute)
549 return e2SubscriptionDirectives, nil
550}
551
552//-------------------------------------------------------------------
553//
554//-------------------------------------------------------------------
archaggeafbf95f2021-04-14 08:54:05 +0300555
556func (c *Control) processSubscriptionRequests(restSubscription *RESTSubscription, subReqList *e2ap.SubscriptionRequestList,
Anssi Mannilaf682ace2021-09-28 13:11:25 +0300557 clientEndpoint *models.SubscriptionParamsClientEndpoint, meid *string, restSubId *string, xAppRmrEndpoint string, md5sum string, e2SubscriptionDirectives *E2SubscriptionDirectives) {
archaggeafbf95f2021-04-14 08:54:05 +0300558
Anssi Mannila08c8fbd2021-10-05 12:47:41 +0300559 c.SubscriptionProcessingStartDelay()
Anssi Mannila54838ed2021-11-19 11:25:01 +0200560 xapp.Logger.Debug("E2 SubscriptionRequest count = %v ", len(subReqList.E2APSubscriptionRequests))
archaggeafbf95f2021-04-14 08:54:05 +0300561
Konstantinos Archangelofe93b00f2021-06-03 10:00:19 +0000562 var xAppEventInstanceID int64
563 var e2EventInstanceID int64
Anssi Mannilaf682ace2021-09-28 13:11:25 +0300564 errorInfo := &ErrorInfo{}
Markku Virtanenb642a192021-06-09 09:08:14 +0000565
Anssi Mannila3cdd2e02021-10-14 12:35:41 +0300566 defer c.restDuplicateCtrl.SetMd5sumFromLastOkRequest(*restSubId, md5sum)
Markku Virtanenb642a192021-06-09 09:08:14 +0000567
archaggeafbf95f2021-04-14 08:54:05 +0300568 for index := 0; index < len(subReqList.E2APSubscriptionRequests); index++ {
569 subReqMsg := subReqList.E2APSubscriptionRequests[index]
Markku Virtanenb642a192021-06-09 09:08:14 +0000570 xAppEventInstanceID = (int64)(subReqMsg.RequestId.Id)
archaggeafbf95f2021-04-14 08:54:05 +0300571
Konstantinos Archangelofe93b00f2021-06-03 10:00:19 +0000572 trans := c.tracker.NewXappTransaction(xapp.NewRmrEndpoint(xAppRmrEndpoint), *restSubId, subReqMsg.RequestId, &xapp.RMRMeid{RanName: *meid})
archaggeafbf95f2021-04-14 08:54:05 +0300573 if trans == nil {
Markku Virtanenb642a192021-06-09 09:08:14 +0000574 // Send notification to xApp that prosessing of a Subscription Request has failed.
575 err := fmt.Errorf("Tracking failure")
Anssi Mannilaf682ace2021-09-28 13:11:25 +0300576 errorInfo.ErrorCause = err.Error()
577 c.sendUnsuccesfullResponseNotification(restSubId, restSubscription, xAppEventInstanceID, err, clientEndpoint, trans, errorInfo)
Markku Virtanenb642a192021-06-09 09:08:14 +0000578 continue
archaggeafbf95f2021-04-14 08:54:05 +0300579 }
580
Anssi Mannilaf682ace2021-09-28 13:11:25 +0300581 xapp.Logger.Debug("Handle SubscriptionRequest index=%v, %s", index, idstring(nil, trans))
Markku Virtanenb642a192021-06-09 09:08:14 +0000582
Anssi Mannilaf682ace2021-09-28 13:11:25 +0300583 subRespMsg, errorInfo, err := c.handleSubscriptionRequest(trans, &subReqMsg, meid, *restSubId, e2SubscriptionDirectives)
Markku Virtanen42723e22021-06-15 10:09:23 +0300584
Anssi Mannilaf682ace2021-09-28 13:11:25 +0300585 xapp.Logger.Debug("Handled SubscriptionRequest index=%v, %s", index, idstring(nil, trans))
Anssi Mannila53dbe7e2021-10-06 14:21:48 +0300586 trans.Release()
Markku Virtanen42723e22021-06-15 10:09:23 +0300587
archaggeafbf95f2021-04-14 08:54:05 +0300588 if err != nil {
Anssi Mannila54838ed2021-11-19 11:25:01 +0200589 if err.Error() == "TEST: restart event received" {
590 // This is just for UT cases. Stop here subscription processing
591 return
592 }
Anssi Mannilaf682ace2021-09-28 13:11:25 +0300593 c.sendUnsuccesfullResponseNotification(restSubId, restSubscription, xAppEventInstanceID, err, clientEndpoint, trans, errorInfo)
archaggeafbf95f2021-04-14 08:54:05 +0300594 } else {
Konstantinos Archangelofe93b00f2021-06-03 10:00:19 +0000595 e2EventInstanceID = (int64)(subRespMsg.RequestId.InstanceId)
Markku Virtanen42723e22021-06-15 10:09:23 +0300596 restSubscription.AddMd5Sum(md5sum)
Anssi Mannilaf682ace2021-09-28 13:11:25 +0300597 xapp.Logger.Debug("SubscriptionRequest index=%v processed successfullyfor %s. endpoint=%v:%v, XappEventInstanceID=%v, E2EventInstanceID=%v, %s",
Markku Virtanen42723e22021-06-15 10:09:23 +0300598 index, *restSubId, clientEndpoint.Host, *clientEndpoint.HTTPPort, xAppEventInstanceID, e2EventInstanceID, idstring(nil, trans))
Anssi Mannila56233b02022-01-24 13:26:42 +0200599 c.sendSuccesfullResponseNotification(restSubId, restSubscription, xAppEventInstanceID, e2EventInstanceID, clientEndpoint, trans, errorInfo)
archaggeafbf95f2021-04-14 08:54:05 +0300600 }
archaggeafbf95f2021-04-14 08:54:05 +0300601 }
602}
603
604//-------------------------------------------------------------------
605//
606//------------------------------------------------------------------
Anssi Mannila08c8fbd2021-10-05 12:47:41 +0300607func (c *Control) SubscriptionProcessingStartDelay() {
608 if c.UTTesting == true {
609 // This is temporary fix for the UT problem that notification arrives before subscription response
610 // Correct fix would be to allow notification come before response and process it correctly
611 xapp.Logger.Debug("Setting 50 ms delay before starting processing Subscriptions")
612 <-time.After(time.Millisecond * 50)
613 xapp.Logger.Debug("Continuing after delay")
614 }
615}
616
617//-------------------------------------------------------------------
618//
619//------------------------------------------------------------------
archaggeafbf95f2021-04-14 08:54:05 +0300620func (c *Control) handleSubscriptionRequest(trans *TransactionXapp, subReqMsg *e2ap.E2APSubscriptionRequest, meid *string,
Anssi Mannilaf682ace2021-09-28 13:11:25 +0300621 restSubId string, e2SubscriptionDirectives *E2SubscriptionDirectives) (*e2ap.E2APSubscriptionResponse, *ErrorInfo, error) {
622
623 errorInfo := ErrorInfo{}
archaggeafbf95f2021-04-14 08:54:05 +0300624
625 err := c.tracker.Track(trans)
626 if err != nil {
Markku Virtanen55d2a282021-06-04 14:46:56 +0300627 xapp.Logger.Error("XAPP-SubReq Tracking error: %s", idstring(err, trans))
Anssi Mannilaf682ace2021-09-28 13:11:25 +0300628 errorInfo.ErrorCause = err.Error()
Markku Virtanen55d2a282021-06-04 14:46:56 +0300629 err = fmt.Errorf("Tracking failure")
Anssi Mannilaf682ace2021-09-28 13:11:25 +0300630 return nil, &errorInfo, err
archaggeafbf95f2021-04-14 08:54:05 +0300631 }
632
Anssi Mannilaf682ace2021-09-28 13:11:25 +0300633 subs, errorInfo, err := c.registry.AssignToSubscription(trans, subReqMsg, c.ResetTestFlag, c, e2SubscriptionDirectives.CreateRMRRoute)
archaggeafbf95f2021-04-14 08:54:05 +0300634 if err != nil {
Markku Virtanen55d2a282021-06-04 14:46:56 +0300635 xapp.Logger.Error("XAPP-SubReq Assign error: %s", idstring(err, trans))
Anssi Mannilaf682ace2021-09-28 13:11:25 +0300636 return nil, &errorInfo, err
archaggeafbf95f2021-04-14 08:54:05 +0300637 }
638
639 //
640 // Wake subs request
641 //
Anssi Mannilac7da4ee2021-10-22 09:52:02 +0300642 subs.OngoingReqCount++
Anssi Mannila54838ed2021-11-19 11:25:01 +0200643 go c.handleSubscriptionCreate(subs, trans, e2SubscriptionDirectives, 0)
archaggeafbf95f2021-04-14 08:54:05 +0300644 event, _ := trans.WaitEvent(0) //blocked wait as timeout is handled in subs side
Anssi Mannilac7da4ee2021-10-22 09:52:02 +0300645 subs.OngoingReqCount--
archaggeafbf95f2021-04-14 08:54:05 +0300646
647 err = nil
648 if event != nil {
649 switch themsg := event.(type) {
650 case *e2ap.E2APSubscriptionResponse:
651 trans.Release()
Anssi Mannilac7da4ee2021-10-22 09:52:02 +0300652 if c.e2IfState.IsE2ConnectionUp(meid) == true {
Anssi Mannila56233b02022-01-24 13:26:42 +0200653 errorInfo = c.e2ap.CheckActionNotAdmittedList(xapp.RIC_SUB_RESP, themsg.ActionNotAdmittedList, c)
Anssi Mannilac7da4ee2021-10-22 09:52:02 +0300654 return themsg, &errorInfo, nil
655 } else {
656 c.registry.RemoveFromSubscription(subs, trans, waitRouteCleanup_ms, c)
657 c.RemoveSubscriptionFromDb(subs)
658 err = fmt.Errorf("E2 interface down")
659 errorInfo.SetInfo(err.Error(), models.SubscriptionInstanceErrorSourceE2Node, "")
Anssi Mannilac7da4ee2021-10-22 09:52:02 +0300660 }
archaggeafbf95f2021-04-14 08:54:05 +0300661 case *e2ap.E2APSubscriptionFailure:
Anssi Mannila483bd162022-01-20 11:11:48 +0200662 err = fmt.Errorf("RICSubscriptionFailure. E2NodeCause: (Cause:%v, Value %v)", themsg.Cause.Content, themsg.Cause.Value)
663 errorInfo.SetInfo(err.Error(), models.SubscriptionInstanceErrorSourceE2Node, "")
Anssi Mannilaf682ace2021-09-28 13:11:25 +0300664 case *PackSubscriptionRequestErrortEvent:
Anssi Mannila56233b02022-01-24 13:26:42 +0200665 err = fmt.Errorf("E2 RICSubscriptionRequest pack failure")
Anssi Mannilab43397e2021-11-16 12:06:16 +0200666 errorInfo = themsg.ErrorInfo
Anssi Mannilaf682ace2021-09-28 13:11:25 +0300667 case *SDLWriteErrortEvent:
668 err = fmt.Errorf("SDL write failure")
Anssi Mannilab43397e2021-11-16 12:06:16 +0200669 errorInfo = themsg.ErrorInfo
Anssi Mannila54838ed2021-11-19 11:25:01 +0200670 case *SubmgrRestartTestEvent:
671 err = fmt.Errorf("TEST: restart event received")
672 xapp.Logger.Debug("%s", err)
673 return nil, &errorInfo, err
archaggeafbf95f2021-04-14 08:54:05 +0300674 default:
Anssi Mannilaf682ace2021-09-28 13:11:25 +0300675 err = fmt.Errorf("Unexpected E2 subscription response received")
676 errorInfo.SetInfo(err.Error(), models.SubscriptionInstanceErrorSourceE2Node, "")
archaggeafbf95f2021-04-14 08:54:05 +0300677 break
678 }
Markku Virtanen55d2a282021-06-04 14:46:56 +0300679 } else {
Anssi Mannila3d80b722021-11-12 13:17:15 +0200680 // Timer expiry
Anssi Mannila56233b02022-01-24 13:26:42 +0200681 err = fmt.Errorf("E2 RICSubscriptionResponse timeout")
Anssi Mannilaf682ace2021-09-28 13:11:25 +0300682 errorInfo.SetInfo(err.Error(), "", models.SubscriptionInstanceTimeoutTypeE2Timeout)
683 if subs.PolicyUpdate == true {
684 return nil, &errorInfo, err
685 }
archaggeafbf95f2021-04-14 08:54:05 +0300686 }
Markku Virtanen55d2a282021-06-04 14:46:56 +0300687
Anssi Mannila9c4697f2022-07-04 15:51:38 +0300688 xapp.Logger.Error("XAPP-SubReq E2 subscription failed: %s", idstring(err, trans, subs))
Anssi Mannila55d6fed2022-08-02 12:41:48 +0300689 c.registry.RemoveFromSubscription(subs, trans, waitRouteCleanup_ms, c)
690
Anssi Mannilaf682ace2021-09-28 13:11:25 +0300691 return nil, &errorInfo, err
archaggeafbf95f2021-04-14 08:54:05 +0300692}
693
694//-------------------------------------------------------------------
695//
696//-------------------------------------------------------------------
Markku Virtanen42723e22021-06-15 10:09:23 +0300697func (c *Control) sendUnsuccesfullResponseNotification(restSubId *string, restSubscription *RESTSubscription, xAppEventInstanceID int64, err error,
Anssi Mannilaf682ace2021-09-28 13:11:25 +0300698 clientEndpoint *models.SubscriptionParamsClientEndpoint, trans *TransactionXapp, errorInfo *ErrorInfo) {
Markku Virtanen42723e22021-06-15 10:09:23 +0300699
700 // Send notification to xApp that prosessing of a Subscription Request has failed.
701 e2EventInstanceID := (int64)(0)
Anssi Mannilaf682ace2021-09-28 13:11:25 +0300702 if errorInfo.ErrorSource == "" {
703 // Submgr is default source of error
704 errorInfo.ErrorSource = models.SubscriptionInstanceErrorSourceSUBMGR
705 }
Markku Virtanen42723e22021-06-15 10:09:23 +0300706 resp := &models.SubscriptionResponse{
707 SubscriptionID: restSubId,
708 SubscriptionInstances: []*models.SubscriptionInstance{
709 &models.SubscriptionInstance{E2EventInstanceID: &e2EventInstanceID,
Anssi Mannilacb7dd492021-10-01 11:10:26 +0300710 ErrorCause: errorInfo.ErrorCause,
711 ErrorSource: errorInfo.ErrorSource,
712 TimeoutType: errorInfo.TimeoutType,
Markku Virtanen42723e22021-06-15 10:09:23 +0300713 XappEventInstanceID: &xAppEventInstanceID},
714 },
715 }
716 // Mark REST subscription request processed.
717 restSubscription.SetProcessed(err)
718 c.UpdateRESTSubscriptionInDB(*restSubId, restSubscription, false)
719 if trans != nil {
Anssi Mannila6bd57912022-06-16 09:47:23 +0300720 xapp.Logger.Debug("Sending unsuccessful REST notification: ErrorCause:%s, ErrorSource:%s, TimeoutType:%s, to Endpoint=%v:%v, XappEventInstanceID=%v, E2EventInstanceID=%v, %s",
721 errorInfo.ErrorCause, errorInfo.ErrorSource, errorInfo.TimeoutType, clientEndpoint.Host, *clientEndpoint.HTTPPort, xAppEventInstanceID, e2EventInstanceID, idstring(nil, trans))
Markku Virtanen42723e22021-06-15 10:09:23 +0300722 } else {
Anssi Mannila6bd57912022-06-16 09:47:23 +0300723 xapp.Logger.Debug("Sending unsuccessful REST notification: ErrorCause:%s, ErrorSource:%s, TimeoutType:%s, to Endpoint=%v:%v, XappEventInstanceID=%v, E2EventInstanceID=%v",
724 errorInfo.ErrorCause, errorInfo.ErrorSource, errorInfo.TimeoutType, clientEndpoint.Host, *clientEndpoint.HTTPPort, xAppEventInstanceID, e2EventInstanceID)
Markku Virtanen42723e22021-06-15 10:09:23 +0300725 }
726
727 c.UpdateCounter(cRestSubFailNotifToXapp)
Anssi Mannila9c4697f2022-07-04 15:51:38 +0300728 err = xapp.Subscription.Notify(resp, *clientEndpoint)
729 if err != nil {
730 xapp.Logger.Error("xapp.Subscription.Notify failed %s", err.Error())
731 }
Anssi Mannilac7da4ee2021-10-22 09:52:02 +0300732
Anssi Mannilab43397e2021-11-16 12:06:16 +0200733 // E2 is down. Delete completely processed request safely now
Anssi Mannilac7da4ee2021-10-22 09:52:02 +0300734 if c.e2IfState.IsE2ConnectionUp(&restSubscription.Meid) == false && restSubscription.SubReqOngoing == false {
735 c.registry.DeleteRESTSubscription(restSubId)
736 c.RemoveRESTSubscriptionFromDb(*restSubId)
737 }
Markku Virtanen42723e22021-06-15 10:09:23 +0300738}
739
740//-------------------------------------------------------------------
741//
742//-------------------------------------------------------------------
743func (c *Control) sendSuccesfullResponseNotification(restSubId *string, restSubscription *RESTSubscription, xAppEventInstanceID int64, e2EventInstanceID int64,
Anssi Mannila56233b02022-01-24 13:26:42 +0200744 clientEndpoint *models.SubscriptionParamsClientEndpoint, trans *TransactionXapp, errorInfo *ErrorInfo) {
Markku Virtanen42723e22021-06-15 10:09:23 +0300745
746 // Store successfully processed InstanceId for deletion
747 restSubscription.AddE2InstanceId((uint32)(e2EventInstanceID))
748 restSubscription.AddXappIdToE2Id(xAppEventInstanceID, e2EventInstanceID)
749
750 // Send notification to xApp that a Subscription Request has been processed.
751 resp := &models.SubscriptionResponse{
752 SubscriptionID: restSubId,
753 SubscriptionInstances: []*models.SubscriptionInstance{
754 &models.SubscriptionInstance{E2EventInstanceID: &e2EventInstanceID,
Anssi Mannila56233b02022-01-24 13:26:42 +0200755 ErrorCause: errorInfo.ErrorCause,
756 ErrorSource: errorInfo.ErrorSource,
Markku Virtanen42723e22021-06-15 10:09:23 +0300757 XappEventInstanceID: &xAppEventInstanceID},
758 },
759 }
760 // Mark REST subscription request processesd.
761 restSubscription.SetProcessed(nil)
762 c.UpdateRESTSubscriptionInDB(*restSubId, restSubscription, false)
Anssi Mannila6bd57912022-06-16 09:47:23 +0300763 xapp.Logger.Debug("Sending successful REST notification: ErrorCause:%s, ErrorSource:%s, TimeoutType:%s, to Endpoint=%v:%v, XappEventInstanceID=%v, E2EventInstanceID=%v, %s",
764 errorInfo.ErrorCause, errorInfo.ErrorSource, errorInfo.TimeoutType, clientEndpoint.Host, *clientEndpoint.HTTPPort, xAppEventInstanceID, e2EventInstanceID, idstring(nil, trans))
Markku Virtanen42723e22021-06-15 10:09:23 +0300765 c.UpdateCounter(cRestSubNotifToXapp)
Anssi Mannila9c4697f2022-07-04 15:51:38 +0300766 err := xapp.Subscription.Notify(resp, *clientEndpoint)
767 if err != nil {
768 xapp.Logger.Error("xapp.Subscription.Notify failed %s", err.Error())
769 }
Anssi Mannilac7da4ee2021-10-22 09:52:02 +0300770
Anssi Mannilab43397e2021-11-16 12:06:16 +0200771 // E2 is down. Delete completely processed request safely now
Anssi Mannilac7da4ee2021-10-22 09:52:02 +0300772 if c.e2IfState.IsE2ConnectionUp(&restSubscription.Meid) == false && restSubscription.SubReqOngoing == false {
773 c.registry.DeleteRESTSubscription(restSubId)
774 c.RemoveRESTSubscriptionFromDb(*restSubId)
775 }
Markku Virtanen42723e22021-06-15 10:09:23 +0300776}
777
778//-------------------------------------------------------------------
779//
780//-------------------------------------------------------------------
Anssi Mannilaf682ace2021-09-28 13:11:25 +0300781func (c *Control) RESTSubscriptionDeleteHandler(restSubId string) int {
archaggeafbf95f2021-04-14 08:54:05 +0300782
783 c.CntRecvMsg++
Konstantinos Archangelof27433e72021-05-31 08:30:35 +0000784 c.UpdateCounter(cRestSubDelReqFromXapp)
archaggeafbf95f2021-04-14 08:54:05 +0300785
Anssi Mannilaf682ace2021-09-28 13:11:25 +0300786 xapp.Logger.Debug("SubscriptionDeleteRequest from XAPP")
archaggeafbf95f2021-04-14 08:54:05 +0300787
Konstantinos Archangelofe93b00f2021-06-03 10:00:19 +0000788 restSubscription, err := c.registry.GetRESTSubscription(restSubId, true)
archaggeafbf95f2021-04-14 08:54:05 +0300789 if err != nil {
790 xapp.Logger.Error("%s", err.Error())
791 if restSubscription == nil {
792 // Subscription was not found
Anssi Mannilac7da4ee2021-10-22 09:52:02 +0300793 c.UpdateCounter(cRestSubDelRespToXapp)
Anssi Mannilaf682ace2021-09-28 13:11:25 +0300794 return common.UnsubscribeNoContentCode
archaggeafbf95f2021-04-14 08:54:05 +0300795 } else {
796 if restSubscription.SubReqOngoing == true {
797 err := fmt.Errorf("Handling of the REST Subscription Request still ongoing %s", restSubId)
798 xapp.Logger.Error("%s", err.Error())
Anssi Mannilac7da4ee2021-10-22 09:52:02 +0300799 c.UpdateCounter(cRestSubDelFailToXapp)
Anssi Mannilaf682ace2021-09-28 13:11:25 +0300800 return common.UnsubscribeBadRequestCode
archaggeafbf95f2021-04-14 08:54:05 +0300801 } else if restSubscription.SubDelReqOngoing == true {
802 // Previous request for same restSubId still ongoing
Anssi Mannila3d80b722021-11-12 13:17:15 +0200803 c.UpdateCounter(cRestSubDelRespToXapp)
804 return common.UnsubscribeNoContentCode
archaggeafbf95f2021-04-14 08:54:05 +0300805 }
806 }
807 }
808
809 xAppRmrEndPoint := restSubscription.xAppRmrEndPoint
810 go func() {
Anssi Mannilaf682ace2021-09-28 13:11:25 +0300811 xapp.Logger.Debug("Deleteting handler: processing instances = %v", restSubscription.InstanceIds)
archaggeafbf95f2021-04-14 08:54:05 +0300812 for _, instanceId := range restSubscription.InstanceIds {
Anssi Mannila54838ed2021-11-19 11:25:01 +0200813 xAppEventInstanceID, err := c.SubscriptionDeleteHandler(&restSubId, &xAppRmrEndPoint, &restSubscription.Meid, instanceId, 0)
Konstantinos Archangelofe93b00f2021-06-03 10:00:19 +0000814
archaggeafbf95f2021-04-14 08:54:05 +0300815 if err != nil {
816 xapp.Logger.Error("%s", err.Error())
archaggeafbf95f2021-04-14 08:54:05 +0300817 }
Anssi Mannilaf682ace2021-09-28 13:11:25 +0300818 xapp.Logger.Debug("Deleteting instanceId = %v", instanceId)
Konstantinos Archangelofe93b00f2021-06-03 10:00:19 +0000819 restSubscription.DeleteXappIdToE2Id(xAppEventInstanceID)
820 restSubscription.DeleteE2InstanceId(instanceId)
archaggeafbf95f2021-04-14 08:54:05 +0300821 }
Anssi Mannila3cdd2e02021-10-14 12:35:41 +0300822 c.restDuplicateCtrl.DeleteLastKnownRestSubsIdBasedOnMd5sum(restSubscription.lastReqMd5sum)
archaggeafbf95f2021-04-14 08:54:05 +0300823 c.registry.DeleteRESTSubscription(&restSubId)
Konstantinos Archangelof268d7152021-06-14 12:24:00 +0300824 c.RemoveRESTSubscriptionFromDb(restSubId)
archaggeafbf95f2021-04-14 08:54:05 +0300825 }()
826
Konstantinos Archangelof27433e72021-05-31 08:30:35 +0000827 c.UpdateCounter(cRestSubDelRespToXapp)
Anssi Mannilaf682ace2021-09-28 13:11:25 +0300828 return common.UnsubscribeNoContentCode
Juha Hyttinenc9eb08a2020-02-28 08:53:33 +0200829}
830
archaggeafbf95f2021-04-14 08:54:05 +0300831//-------------------------------------------------------------------
832//
833//-------------------------------------------------------------------
Anssi Mannila54838ed2021-11-19 11:25:01 +0200834func (c *Control) SubscriptionDeleteHandler(restSubId *string, endPoint *string, meid *string, instanceId uint32, waitRouteCleanupTime time.Duration) (int64, error) {
archaggeafbf95f2021-04-14 08:54:05 +0300835
Konstantinos Archangelofe93b00f2021-06-03 10:00:19 +0000836 var xAppEventInstanceID int64
837 subs, err := c.registry.GetSubscriptionFirstMatch([]uint32{instanceId})
838 if err != nil {
Anssi Mannilaf682ace2021-09-28 13:11:25 +0300839 xapp.Logger.Debug("Subscription Delete Handler subscription for restSubId=%v, E2EventInstanceID=%v not found %s",
Konstantinos Archangelofe93b00f2021-06-03 10:00:19 +0000840 restSubId, instanceId, idstring(err, nil))
841 return xAppEventInstanceID, nil
842 }
843
844 xAppEventInstanceID = int64(subs.ReqId.Id)
845 trans := c.tracker.NewXappTransaction(xapp.NewRmrEndpoint(*endPoint), *restSubId, e2ap.RequestId{subs.ReqId.Id, 0}, &xapp.RMRMeid{RanName: *meid})
archaggeafbf95f2021-04-14 08:54:05 +0300846 if trans == nil {
847 err := fmt.Errorf("XAPP-SubDelReq transaction not created. restSubId %s, endPoint %s, meid %s, instanceId %v", *restSubId, *endPoint, *meid, instanceId)
848 xapp.Logger.Error("%s", err.Error())
849 }
850 defer trans.Release()
851
Konstantinos Archangelofe93b00f2021-06-03 10:00:19 +0000852 err = c.tracker.Track(trans)
archaggeafbf95f2021-04-14 08:54:05 +0300853 if err != nil {
854 err := fmt.Errorf("XAPP-SubDelReq %s:", idstring(err, trans))
855 xapp.Logger.Error("%s", err.Error())
Konstantinos Archangelofe93b00f2021-06-03 10:00:19 +0000856 return xAppEventInstanceID, &time.ParseError{}
archaggeafbf95f2021-04-14 08:54:05 +0300857 }
858 //
859 // Wake subs delete
860 //
Anssi Mannilac7da4ee2021-10-22 09:52:02 +0300861 subs.OngoingDelCount++
Anssi Mannila54838ed2021-11-19 11:25:01 +0200862 go c.handleSubscriptionDelete(subs, trans, waitRouteCleanupTime)
archaggeafbf95f2021-04-14 08:54:05 +0300863 trans.WaitEvent(0) //blocked wait as timeout is handled in subs side
Anssi Mannilac7da4ee2021-10-22 09:52:02 +0300864 subs.OngoingDelCount--
archaggeafbf95f2021-04-14 08:54:05 +0300865
866 xapp.Logger.Debug("XAPP-SubDelReq: Handling event %s ", idstring(nil, trans, subs))
867
Anssi Mannila55d6fed2022-08-02 12:41:48 +0300868 c.registry.RemoveFromSubscription(subs, trans, waitRouteCleanup_ms, c)
archaggeafbf95f2021-04-14 08:54:05 +0300869
Konstantinos Archangelofe93b00f2021-06-03 10:00:19 +0000870 return xAppEventInstanceID, nil
archaggeafbf95f2021-04-14 08:54:05 +0300871}
872
873//-------------------------------------------------------------------
874//
875//-------------------------------------------------------------------
Juha Hyttinenc9eb08a2020-02-28 08:53:33 +0200876
Juha Hyttinen83ada002020-01-30 10:36:33 +0200877func (c *Control) rmrSendToE2T(desc string, subs *Subscription, trans *TransactionSubs) (err error) {
Juha Hyttinen9dc5adc2020-08-13 10:02:40 +0300878 params := &xapp.RMRParams{}
Juha Hyttinene406a342020-01-13 13:02:26 +0200879 params.Mtype = trans.GetMtype()
Juha Hyttinenaada6452020-04-07 08:47:58 +0300880 params.SubId = int(subs.GetReqId().InstanceId)
Juha Hyttinen86a46202020-01-14 12:49:09 +0200881 params.Xid = ""
Juha Hyttinene406a342020-01-13 13:02:26 +0200882 params.Meid = subs.GetMeid()
883 params.Src = ""
Juha Hyttinen63284a22020-01-15 10:45:11 +0200884 params.PayloadLen = len(trans.Payload.Buf)
885 params.Payload = trans.Payload.Buf
Juha Hyttinene406a342020-01-13 13:02:26 +0200886 params.Mbuf = nil
Anssi Mannilaf682ace2021-09-28 13:11:25 +0300887 xapp.Logger.Debug("MSG to E2T: %s %s %s", desc, trans.String(), params.String())
Abukar Mohamedfbd4df52021-03-11 06:13:27 +0000888 err = c.SendWithRetry(params, false, 5)
889 if err != nil {
890 xapp.Logger.Error("rmrSendToE2T: Send failed: %+v", err)
891 }
892 return err
kalnagye0018682019-09-26 16:28:25 +0200893}
894
Juha Hyttinen83ada002020-01-30 10:36:33 +0200895func (c *Control) rmrSendToXapp(desc string, subs *Subscription, trans *TransactionXapp) (err error) {
896
Juha Hyttinen9dc5adc2020-08-13 10:02:40 +0300897 params := &xapp.RMRParams{}
Juha Hyttinen63284a22020-01-15 10:45:11 +0200898 params.Mtype = trans.GetMtype()
Juha Hyttinenaada6452020-04-07 08:47:58 +0300899 params.SubId = int(subs.GetReqId().InstanceId)
Juha Hyttinene406a342020-01-13 13:02:26 +0200900 params.Xid = trans.GetXid()
Juha Hyttinen86a46202020-01-14 12:49:09 +0200901 params.Meid = trans.GetMeid()
Juha Hyttinene406a342020-01-13 13:02:26 +0200902 params.Src = ""
Juha Hyttinen63284a22020-01-15 10:45:11 +0200903 params.PayloadLen = len(trans.Payload.Buf)
904 params.Payload = trans.Payload.Buf
Juha Hyttinene406a342020-01-13 13:02:26 +0200905 params.Mbuf = nil
Anssi Mannilaf682ace2021-09-28 13:11:25 +0300906 xapp.Logger.Debug("MSG to XAPP: %s %s %s", desc, trans.String(), params.String())
Abukar Mohamedfbd4df52021-03-11 06:13:27 +0000907 err = c.SendWithRetry(params, false, 5)
908 if err != nil {
909 xapp.Logger.Error("rmrSendToXapp: Send failed: %+v", err)
910 }
911 return err
Juha Hyttinene406a342020-01-13 13:02:26 +0200912}
913
Juha Hyttinen9dc5adc2020-08-13 10:02:40 +0300914func (c *Control) Consume(msg *xapp.RMRParams) (err error) {
915 if c.RMRClient == nil {
Juha Hyttinen5f8ffa02020-02-06 15:28:59 +0200916 err = fmt.Errorf("Rmr object nil can handle %s", msg.String())
917 xapp.Logger.Error("%s", err.Error())
918 return
919 }
920 c.CntRecvMsg++
921
Juha Hyttinen9dc5adc2020-08-13 10:02:40 +0300922 defer c.RMRClient.Free(msg.Mbuf)
Juha Hyttinen83ada002020-01-30 10:36:33 +0200923
Juha Hyttinena8a908d2020-05-26 15:12:47 +0300924 // xapp-frame might use direct access to c buffer and
925 // when msg.Mbuf is freed, someone might take it into use
926 // and payload data might be invalid inside message handle function
927 //
928 // subscriptions won't load system a lot so there is no
929 // real performance hit by cloning buffer into new go byte slice
930 cPay := append(msg.Payload[:0:0], msg.Payload...)
931 msg.Payload = cPay
932 msg.PayloadLen = len(cPay)
933
Anssi Mannila90fa0212019-12-12 10:47:47 +0200934 switch msg.Mtype {
Juha Hyttinenc9eb08a2020-02-28 08:53:33 +0200935 case xapp.RIC_SUB_REQ:
Juha Hyttinen422d0182020-01-17 13:37:05 +0200936 go c.handleXAPPSubscriptionRequest(msg)
Juha Hyttinenc9eb08a2020-02-28 08:53:33 +0200937 case xapp.RIC_SUB_RESP:
Juha Hyttinen422d0182020-01-17 13:37:05 +0200938 go c.handleE2TSubscriptionResponse(msg)
Juha Hyttinenc9eb08a2020-02-28 08:53:33 +0200939 case xapp.RIC_SUB_FAILURE:
Juha Hyttinen422d0182020-01-17 13:37:05 +0200940 go c.handleE2TSubscriptionFailure(msg)
Juha Hyttinenc9eb08a2020-02-28 08:53:33 +0200941 case xapp.RIC_SUB_DEL_REQ:
Juha Hyttinen422d0182020-01-17 13:37:05 +0200942 go c.handleXAPPSubscriptionDeleteRequest(msg)
Juha Hyttinenc9eb08a2020-02-28 08:53:33 +0200943 case xapp.RIC_SUB_DEL_RESP:
Juha Hyttinen422d0182020-01-17 13:37:05 +0200944 go c.handleE2TSubscriptionDeleteResponse(msg)
Juha Hyttinenc9eb08a2020-02-28 08:53:33 +0200945 case xapp.RIC_SUB_DEL_FAILURE:
Juha Hyttinen422d0182020-01-17 13:37:05 +0200946 go c.handleE2TSubscriptionDeleteFailure(msg)
Anssi Mannila90fa0212019-12-12 10:47:47 +0200947 default:
Anssi Mannilaf682ace2021-09-28 13:11:25 +0300948 xapp.Logger.Debug("Unknown Message Type '%d', discarding", msg.Mtype)
Balint Uvegescd3881b2019-10-02 15:01:43 +0000949 }
Juha Hyttinen5f8ffa02020-02-06 15:28:59 +0200950 return
Juha Hyttinen31797b42020-01-16 14:05:01 +0200951}
952
Juha Hyttinen422d0182020-01-17 13:37:05 +0200953//-------------------------------------------------------------------
954// handle from XAPP Subscription Request
955//------------------------------------------------------------------
Juha Hyttinen9dc5adc2020-08-13 10:02:40 +0300956func (c *Control) handleXAPPSubscriptionRequest(params *xapp.RMRParams) {
Anssi Mannilaf682ace2021-09-28 13:11:25 +0300957 xapp.Logger.Debug("MSG from XAPP: %s", params.String())
Anssi Mannila4abf1802021-01-28 13:06:46 +0200958 c.UpdateCounter(cSubReqFromXapp)
Juha Hyttinen422d0182020-01-17 13:37:05 +0200959
Anssi Mannilac7da4ee2021-10-22 09:52:02 +0300960 if c.e2IfState.IsE2ConnectionUp(&params.Meid.RanName) == false {
961 xapp.Logger.Error("No E2 connection for ranName %v", params.Meid.RanName)
962 return
963 }
964
Juha Hyttinen422d0182020-01-17 13:37:05 +0200965 subReqMsg, err := c.e2ap.UnpackSubscriptionRequest(params.Payload)
966 if err != nil {
Juha Hyttinen83ada002020-01-30 10:36:33 +0200967 xapp.Logger.Error("XAPP-SubReq: %s", idstring(err, params))
Juha Hyttinen422d0182020-01-17 13:37:05 +0200968 return
969 }
970
Anssi Mannila4c626a22021-02-11 12:50:48 +0200971 trans := c.tracker.NewXappTransaction(xapp.NewRmrEndpoint(params.Src), params.Xid, subReqMsg.RequestId, params.Meid)
Juha Hyttinen83ada002020-01-30 10:36:33 +0200972 if trans == nil {
973 xapp.Logger.Error("XAPP-SubReq: %s", idstring(fmt.Errorf("transaction not created"), params))
Juha Hyttinen422d0182020-01-17 13:37:05 +0200974 return
975 }
976 defer trans.Release()
977
Anssi Mannila6b3796f2021-02-12 09:11:35 +0200978 if err = c.tracker.Track(trans); err != nil {
Juha Hyttinen83ada002020-01-30 10:36:33 +0200979 xapp.Logger.Error("XAPP-SubReq: %s", idstring(err, trans))
980 return
981 }
982
Anssi Mannilaf682ace2021-09-28 13:11:25 +0300983 subs, _, err := c.registry.AssignToSubscription(trans, subReqMsg, c.ResetTestFlag, c, true)
Juha Hyttinen422d0182020-01-17 13:37:05 +0200984 if err != nil {
Juha Hyttinen83ada002020-01-30 10:36:33 +0200985 xapp.Logger.Error("XAPP-SubReq: %s", idstring(err, trans))
Juha Hyttinen422d0182020-01-17 13:37:05 +0200986 return
987 }
988
Anssi Mannila6b3796f2021-02-12 09:11:35 +0200989 c.wakeSubscriptionRequest(subs, trans)
990}
991
992//-------------------------------------------------------------------
993// Wake Subscription Request to E2node
994//------------------------------------------------------------------
995func (c *Control) wakeSubscriptionRequest(subs *Subscription, trans *TransactionXapp) {
996
Anssi Mannila55d6fed2022-08-02 12:41:48 +0300997 e2SubscriptionDirectives, err := c.GetE2SubscriptionDirectives(nil)
998 if err != nil {
999 xapp.Logger.Error("c.GetE2SubscriptionDirectives failure: %s", err.Error())
1000 }
Anssi Mannilac7da4ee2021-10-22 09:52:02 +03001001 subs.OngoingReqCount++
Anssi Mannila54838ed2021-11-19 11:25:01 +02001002 go c.handleSubscriptionCreate(subs, trans, e2SubscriptionDirectives, waitRouteCleanup_ms)
Juha Hyttinen422d0182020-01-17 13:37:05 +02001003 event, _ := trans.WaitEvent(0) //blocked wait as timeout is handled in subs side
Anssi Mannilac7da4ee2021-10-22 09:52:02 +03001004 subs.OngoingReqCount--
Juha Hyttinen422d0182020-01-17 13:37:05 +02001005 if event != nil {
1006 switch themsg := event.(type) {
1007 case *e2ap.E2APSubscriptionResponse:
Anssi Mannila4c626a22021-02-11 12:50:48 +02001008 themsg.RequestId.Id = trans.RequestId.Id
Juha Hyttinen422d0182020-01-17 13:37:05 +02001009 trans.Mtype, trans.Payload, err = c.e2ap.PackSubscriptionResponse(themsg)
1010 if err == nil {
Anssi Mannila64a0df42020-02-26 09:46:03 +02001011 trans.Release()
Anssi Mannila4abf1802021-01-28 13:06:46 +02001012 c.UpdateCounter(cSubRespToXapp)
Anssi Mannila9c4697f2022-07-04 15:51:38 +03001013 err := c.rmrSendToXapp("", subs, trans)
1014 if err != nil {
1015 xapp.Logger.Error("rmrSendToXapp() failed:%s", err.Error())
1016 }
Juha Hyttinen422d0182020-01-17 13:37:05 +02001017 return
1018 }
1019 case *e2ap.E2APSubscriptionFailure:
Anssi Mannila4c626a22021-02-11 12:50:48 +02001020 themsg.RequestId.Id = trans.RequestId.Id
Juha Hyttinen422d0182020-01-17 13:37:05 +02001021 trans.Mtype, trans.Payload, err = c.e2ap.PackSubscriptionFailure(themsg)
1022 if err == nil {
Anssi Mannila4abf1802021-01-28 13:06:46 +02001023 c.UpdateCounter(cSubFailToXapp)
Juha Hyttinen83ada002020-01-30 10:36:33 +02001024 c.rmrSendToXapp("", subs, trans)
Juha Hyttinen422d0182020-01-17 13:37:05 +02001025 }
Juha Hyttinen422d0182020-01-17 13:37:05 +02001026 default:
Juha Hyttinen31797b42020-01-16 14:05:01 +02001027 break
1028 }
1029 }
Anssi Mannilaf682ace2021-09-28 13:11:25 +03001030 xapp.Logger.Debug("XAPP-SubReq: failed %s", idstring(err, trans, subs))
Juha Hyttinen31797b42020-01-16 14:05:01 +02001031}
1032
Juha Hyttinen422d0182020-01-17 13:37:05 +02001033//-------------------------------------------------------------------
1034// handle from XAPP Subscription Delete Request
1035//------------------------------------------------------------------
Juha Hyttinen9dc5adc2020-08-13 10:02:40 +03001036func (c *Control) handleXAPPSubscriptionDeleteRequest(params *xapp.RMRParams) {
Anssi Mannilaf682ace2021-09-28 13:11:25 +03001037 xapp.Logger.Debug("MSG from XAPP: %s", params.String())
Anssi Mannila4abf1802021-01-28 13:06:46 +02001038 c.UpdateCounter(cSubDelReqFromXapp)
Juha Hyttinen422d0182020-01-17 13:37:05 +02001039
Anssi Mannilac7da4ee2021-10-22 09:52:02 +03001040 if c.e2IfState.IsE2ConnectionUp(&params.Meid.RanName) == false {
1041 xapp.Logger.Error("No E2 connection for ranName %v", params.Meid.RanName)
1042 return
1043 }
1044
Juha Hyttinen422d0182020-01-17 13:37:05 +02001045 subDelReqMsg, err := c.e2ap.UnpackSubscriptionDeleteRequest(params.Payload)
Juha Hyttinen31797b42020-01-16 14:05:01 +02001046 if err != nil {
Juha Hyttinen83ada002020-01-30 10:36:33 +02001047 xapp.Logger.Error("XAPP-SubDelReq %s", idstring(err, params))
Juha Hyttinen422d0182020-01-17 13:37:05 +02001048 return
1049 }
1050
Anssi Mannila4c626a22021-02-11 12:50:48 +02001051 trans := c.tracker.NewXappTransaction(xapp.NewRmrEndpoint(params.Src), params.Xid, subDelReqMsg.RequestId, params.Meid)
Juha Hyttinen83ada002020-01-30 10:36:33 +02001052 if trans == nil {
1053 xapp.Logger.Error("XAPP-SubDelReq: %s", idstring(fmt.Errorf("transaction not created"), params))
Juha Hyttinen422d0182020-01-17 13:37:05 +02001054 return
1055 }
1056 defer trans.Release()
1057
Juha Hyttinen83ada002020-01-30 10:36:33 +02001058 err = c.tracker.Track(trans)
Juha Hyttinen422d0182020-01-17 13:37:05 +02001059 if err != nil {
Juha Hyttinen83ada002020-01-30 10:36:33 +02001060 xapp.Logger.Error("XAPP-SubReq: %s", idstring(err, trans))
1061 return
1062 }
1063
Juha Hyttinen47942b42020-02-27 10:41:43 +02001064 subs, err := c.registry.GetSubscriptionFirstMatch([]uint32{trans.GetSubId()})
Juha Hyttinen83ada002020-01-30 10:36:33 +02001065 if err != nil {
1066 xapp.Logger.Error("XAPP-SubDelReq: %s", idstring(err, trans))
Juha Hyttinen422d0182020-01-17 13:37:05 +02001067 return
1068 }
1069
Juha Hyttinen422d0182020-01-17 13:37:05 +02001070 //
1071 // Wake subs delete
1072 //
Anssi Mannilac7da4ee2021-10-22 09:52:02 +03001073 subs.OngoingDelCount++
Anssi Mannila54838ed2021-11-19 11:25:01 +02001074 go c.handleSubscriptionDelete(subs, trans, waitRouteCleanup_ms)
Juha Hyttinen422d0182020-01-17 13:37:05 +02001075 trans.WaitEvent(0) //blocked wait as timeout is handled in subs side
Anssi Mannilac7da4ee2021-10-22 09:52:02 +03001076 subs.OngoingDelCount--
Juha Hyttinen422d0182020-01-17 13:37:05 +02001077
Juha Hyttinen83ada002020-01-30 10:36:33 +02001078 xapp.Logger.Debug("XAPP-SubDelReq: Handling event %s ", idstring(nil, trans, subs))
1079
Anssi Mannilac92b4212020-12-07 14:59:34 +02001080 if subs.NoRespToXapp == true {
1081 // Do no send delete responses to xapps due to submgr restart is deleting uncompleted subscriptions
Anssi Mannilaf682ace2021-09-28 13:11:25 +03001082 xapp.Logger.Debug("XAPP-SubDelReq: subs.NoRespToXapp == true")
Anssi Mannilac92b4212020-12-07 14:59:34 +02001083 return
1084 }
1085
1086 // Whatever is received success, fail or timeout, send successful delete response
Juha Hyttinen422d0182020-01-17 13:37:05 +02001087 subDelRespMsg := &e2ap.E2APSubscriptionDeleteResponse{}
Anssi Mannila4c626a22021-02-11 12:50:48 +02001088 subDelRespMsg.RequestId.Id = trans.RequestId.Id
1089 subDelRespMsg.RequestId.InstanceId = subs.GetReqId().RequestId.InstanceId
Juha Hyttinen422d0182020-01-17 13:37:05 +02001090 subDelRespMsg.FunctionId = subs.SubReqMsg.FunctionId
1091 trans.Mtype, trans.Payload, err = c.e2ap.PackSubscriptionDeleteResponse(subDelRespMsg)
1092 if err == nil {
Anssi Mannila4abf1802021-01-28 13:06:46 +02001093 c.UpdateCounter(cSubDelRespToXapp)
Anssi Mannila9c4697f2022-07-04 15:51:38 +03001094 err := c.rmrSendToXapp("", subs, trans)
1095 if err != nil {
1096 xapp.Logger.Error("rmrSendToXapp() failed:%s", err.Error())
1097 }
Juha Hyttinen422d0182020-01-17 13:37:05 +02001098 }
1099}
1100
1101//-------------------------------------------------------------------
1102// SUBS CREATE Handling
1103//-------------------------------------------------------------------
Anssi Mannila54838ed2021-11-19 11:25:01 +02001104func (c *Control) handleSubscriptionCreate(subs *Subscription, parentTrans *TransactionXapp, e2SubscriptionDirectives *E2SubscriptionDirectives, waitRouteCleanupTime time.Duration) {
Juha Hyttinen422d0182020-01-17 13:37:05 +02001105
Anssi Mannilaf682ace2021-09-28 13:11:25 +03001106 var event interface{} = nil
Anssi Mannilac92b4212020-12-07 14:59:34 +02001107 var removeSubscriptionFromDb bool = false
Juha Hyttinen83ada002020-01-30 10:36:33 +02001108 trans := c.tracker.NewSubsTransaction(subs)
Juha Hyttinen422d0182020-01-17 13:37:05 +02001109 subs.WaitTransactionTurn(trans)
1110 defer subs.ReleaseTransactionTurn(trans)
1111 defer trans.Release()
1112
Juha Hyttinen83ada002020-01-30 10:36:33 +02001113 xapp.Logger.Debug("SUBS-SubReq: Handling %s ", idstring(nil, trans, subs, parentTrans))
Juha Hyttinen422d0182020-01-17 13:37:05 +02001114
Juha Hyttinen83ada002020-01-30 10:36:33 +02001115 subRfMsg, valid := subs.GetCachedResponse()
1116 if subRfMsg == nil && valid == true {
Anssi Mannilaf682ace2021-09-28 13:11:25 +03001117 event = c.sendE2TSubscriptionRequest(subs, trans, parentTrans, e2SubscriptionDirectives)
Anssi Mannila6d629ad2021-01-25 09:59:56 +02001118 switch event.(type) {
1119 case *e2ap.E2APSubscriptionResponse:
1120 subRfMsg, valid = subs.SetCachedResponse(event, true)
1121 subs.SubRespRcvd = true
1122 case *e2ap.E2APSubscriptionFailure:
Anssi Mannila6d629ad2021-01-25 09:59:56 +02001123 subRfMsg, valid = subs.SetCachedResponse(event, false)
Anssi Mannilaf682ace2021-09-28 13:11:25 +03001124 xapp.Logger.Debug("SUBS-SubReq: internal delete due failure event(%s) %s", typeofSubsMessage(event), idstring(nil, trans, subs, parentTrans))
Anssi Mannila6d629ad2021-01-25 09:59:56 +02001125 case *SubmgrRestartTestEvent:
Anssi Mannila54838ed2021-11-19 11:25:01 +02001126 // This is used to simulate that no response has been received and after restart, subscriptions are restored from db
Anssi Mannila6d629ad2021-01-25 09:59:56 +02001127 xapp.Logger.Debug("Test restart flag is active. Dropping this transaction to test restart case")
Anssi Mannila54838ed2021-11-19 11:25:01 +02001128 subRfMsg, valid = subs.SetCachedResponse(event, false)
1129 parentTrans.SendEvent(subRfMsg, 0)
1130 return
Anssi Mannilaf682ace2021-09-28 13:11:25 +03001131 case *PackSubscriptionRequestErrortEvent, *SDLWriteErrortEvent:
1132 subRfMsg, valid = subs.SetCachedResponse(event, false)
Anssi Mannila6d629ad2021-01-25 09:59:56 +02001133 default:
Anssi Mannila3d80b722021-11-12 13:17:15 +02001134 // Timer expiry
Anssi Mannilaf682ace2021-09-28 13:11:25 +03001135 if subs.PolicyUpdate == false {
1136 xapp.Logger.Debug("SUBS-SubReq: internal delete due default event(%s) %s", typeofSubsMessage(event), idstring(nil, trans, subs, parentTrans))
Anssi Mannilaf682ace2021-09-28 13:11:25 +03001137 subRfMsg, valid = subs.SetCachedResponse(nil, false)
1138 c.sendE2TSubscriptionDeleteRequest(subs, trans, parentTrans)
Anssi Mannila54838ed2021-11-19 11:25:01 +02001139 } else {
1140 subRfMsg, valid = subs.SetCachedResponse(nil, true)
Anssi Mannilaf682ace2021-09-28 13:11:25 +03001141 }
Juha Hyttinen83ada002020-01-30 10:36:33 +02001142 }
1143 xapp.Logger.Debug("SUBS-SubReq: Handling (e2t response %s) %s", typeofSubsMessage(subRfMsg), idstring(nil, trans, subs, parentTrans))
1144 } else {
1145 xapp.Logger.Debug("SUBS-SubReq: Handling (cached response %s) %s", typeofSubsMessage(subRfMsg), idstring(nil, trans, subs, parentTrans))
Juha Hyttinen422d0182020-01-17 13:37:05 +02001146 }
Anssi Mannila54838ed2021-11-19 11:25:01 +02001147 if valid == false {
1148 removeSubscriptionFromDb = true
1149 }
Juha Hyttinen422d0182020-01-17 13:37:05 +02001150
Anssi Mannilaf682ace2021-09-28 13:11:25 +03001151 err := c.UpdateSubscriptionInDB(subs, removeSubscriptionFromDb)
1152 if err != nil {
Anssi Mannila54838ed2021-11-19 11:25:01 +02001153 valid = false
Anssi Mannilaf682ace2021-09-28 13:11:25 +03001154 c.sendE2TSubscriptionDeleteRequest(subs, trans, parentTrans)
Anssi Mannila9c4697f2022-07-04 15:51:38 +03001155
Anssi Mannilaf682ace2021-09-28 13:11:25 +03001156 }
1157
Anssi Mannila27385172021-12-22 09:41:54 +02001158 // Now RemoveFromSubscription in here to avoid race conditions (mostly concerns delete)
Juha Hyttinen429cfe62020-03-31 11:23:02 +03001159 if valid == false {
Anssi Mannila55d6fed2022-08-02 12:41:48 +03001160 c.registry.RemoveFromSubscription(subs, parentTrans, waitRouteCleanupTime, c)
Juha Hyttinen429cfe62020-03-31 11:23:02 +03001161 }
Anssi Mannilac92b4212020-12-07 14:59:34 +02001162
Juha Hyttinen83ada002020-01-30 10:36:33 +02001163 parentTrans.SendEvent(subRfMsg, 0)
Juha Hyttinen422d0182020-01-17 13:37:05 +02001164}
1165
1166//-------------------------------------------------------------------
1167// SUBS DELETE Handling
1168//-------------------------------------------------------------------
Juha Hyttinen3944a222020-01-24 11:51:46 +02001169
Anssi Mannila54838ed2021-11-19 11:25:01 +02001170func (c *Control) handleSubscriptionDelete(subs *Subscription, parentTrans *TransactionXapp, waitRouteCleanupTime time.Duration) {
Juha Hyttinen422d0182020-01-17 13:37:05 +02001171
Juha Hyttinen83ada002020-01-30 10:36:33 +02001172 trans := c.tracker.NewSubsTransaction(subs)
Juha Hyttinen422d0182020-01-17 13:37:05 +02001173 subs.WaitTransactionTurn(trans)
1174 defer subs.ReleaseTransactionTurn(trans)
1175 defer trans.Release()
1176
Juha Hyttinen83ada002020-01-30 10:36:33 +02001177 xapp.Logger.Debug("SUBS-SubDelReq: Handling %s", idstring(nil, trans, subs, parentTrans))
Juha Hyttinen422d0182020-01-17 13:37:05 +02001178
Juha Hyttinen3944a222020-01-24 11:51:46 +02001179 subs.mutex.Lock()
Anssi Mannila4abf1802021-01-28 13:06:46 +02001180
Juha Hyttinen3944a222020-01-24 11:51:46 +02001181 if subs.valid && subs.EpList.HasEndpoint(parentTrans.GetEndpoint()) && subs.EpList.Size() == 1 {
1182 subs.valid = false
1183 subs.mutex.Unlock()
1184 c.sendE2TSubscriptionDeleteRequest(subs, trans, parentTrans)
1185 } else {
1186 subs.mutex.Unlock()
1187 }
Anssi Mannila27385172021-12-22 09:41:54 +02001188
1189 // Now RemoveFromSubscription in here to avoid race conditions (mostly concerns delete)
Anssi Mannila54838ed2021-11-19 11:25:01 +02001190 c.registry.RemoveFromSubscription(subs, parentTrans, waitRouteCleanupTime, c)
Juha Hyttinen47942b42020-02-27 10:41:43 +02001191 parentTrans.SendEvent(nil, 0)
Juha Hyttinen422d0182020-01-17 13:37:05 +02001192}
1193
1194//-------------------------------------------------------------------
1195// send to E2T Subscription Request
1196//-------------------------------------------------------------------
Anssi Mannilaf682ace2021-09-28 13:11:25 +03001197func (c *Control) sendE2TSubscriptionRequest(subs *Subscription, trans *TransactionSubs, parentTrans *TransactionXapp, e2SubscriptionDirectives *E2SubscriptionDirectives) interface{} {
Juha Hyttinen422d0182020-01-17 13:37:05 +02001198 var err error
1199 var event interface{} = nil
1200 var timedOut bool = false
Konstantinos Archangelof26dfa712021-06-04 12:10:26 +00001201 const ricRequestorId = 123
Juha Hyttinen422d0182020-01-17 13:37:05 +02001202
1203 subReqMsg := subs.SubReqMsg
Juha Hyttinen83ada002020-01-30 10:36:33 +02001204 subReqMsg.RequestId = subs.GetReqId().RequestId
Konstantinos Archangelof26dfa712021-06-04 12:10:26 +00001205 subReqMsg.RequestId.Id = ricRequestorId
Juha Hyttinen422d0182020-01-17 13:37:05 +02001206 trans.Mtype, trans.Payload, err = c.e2ap.PackSubscriptionRequest(subReqMsg)
1207 if err != nil {
Anssi Mannilab43397e2021-11-16 12:06:16 +02001208 xapp.Logger.Error("SUBS-SubReq ASN1 pack error: %s", idstring(err, trans, subs, parentTrans))
Anssi Mannilaf682ace2021-09-28 13:11:25 +03001209 return &PackSubscriptionRequestErrortEvent{
1210 ErrorInfo{
1211 ErrorSource: models.SubscriptionInstanceErrorSourceASN1,
1212 ErrorCause: err.Error(),
1213 },
1214 }
Juha Hyttinen422d0182020-01-17 13:37:05 +02001215 }
1216
Anssi Mannilac92b4212020-12-07 14:59:34 +02001217 // Write uncompleted subscrition in db. If no response for subscrition it need to be re-processed (deleted) after restart
Anssi Mannilaf682ace2021-09-28 13:11:25 +03001218 err = c.WriteSubscriptionToDb(subs)
1219 if err != nil {
1220 return &SDLWriteErrortEvent{
1221 ErrorInfo{
1222 ErrorSource: models.SubscriptionInstanceErrorSourceDBAAS,
1223 ErrorCause: err.Error(),
1224 },
1225 }
1226 }
Markku Virtanenfe2cdab2021-05-21 10:59:29 +00001227
Anssi Mannilaf682ace2021-09-28 13:11:25 +03001228 for retries := int64(0); retries < e2SubscriptionDirectives.E2MaxTryCount; retries++ {
Juha Hyttinen83ada002020-01-30 10:36:33 +02001229 desc := fmt.Sprintf("(retry %d)", retries)
Anssi Mannila4abf1802021-01-28 13:06:46 +02001230 if retries == 0 {
1231 c.UpdateCounter(cSubReqToE2)
1232 } else {
1233 c.UpdateCounter(cSubReReqToE2)
1234 }
Anssi Mannila9c4697f2022-07-04 15:51:38 +03001235 err := c.rmrSendToE2T(desc, subs, trans)
1236 if err != nil {
1237 xapp.Logger.Error("rmrSendToE2T() failed:%s", err.Error())
1238 }
1239
Anssi Mannilac92b4212020-12-07 14:59:34 +02001240 if subs.DoNotWaitSubResp == false {
Anssi Mannilaf682ace2021-09-28 13:11:25 +03001241 event, timedOut = trans.WaitEvent(e2SubscriptionDirectives.E2TimeoutTimerValue)
Anssi Mannilac92b4212020-12-07 14:59:34 +02001242 if timedOut {
Anssi Mannila4abf1802021-01-28 13:06:46 +02001243 c.UpdateCounter(cSubReqTimerExpiry)
Anssi Mannilac92b4212020-12-07 14:59:34 +02001244 continue
1245 }
1246 } else {
1247 // Simulating case where subscrition request has been sent but response has not been received before restart
1248 event = &SubmgrRestartTestEvent{}
Anssi Mannilaf682ace2021-09-28 13:11:25 +03001249 xapp.Logger.Debug("Restart event, DoNotWaitSubResp == true")
Juha Hyttinen422d0182020-01-17 13:37:05 +02001250 }
1251 break
1252 }
Juha Hyttinen83ada002020-01-30 10:36:33 +02001253 xapp.Logger.Debug("SUBS-SubReq: Response handling event(%s) %s", typeofSubsMessage(event), idstring(nil, trans, subs, parentTrans))
Juha Hyttinen422d0182020-01-17 13:37:05 +02001254 return event
1255}
1256
1257//-------------------------------------------------------------------
1258// send to E2T Subscription Delete Request
1259//-------------------------------------------------------------------
1260
Juha Hyttinen83ada002020-01-30 10:36:33 +02001261func (c *Control) sendE2TSubscriptionDeleteRequest(subs *Subscription, trans *TransactionSubs, parentTrans *TransactionXapp) interface{} {
Juha Hyttinen422d0182020-01-17 13:37:05 +02001262 var err error
1263 var event interface{}
1264 var timedOut bool
Konstantinos Archangelof26dfa712021-06-04 12:10:26 +00001265 const ricRequestorId = 123
Juha Hyttinen422d0182020-01-17 13:37:05 +02001266
1267 subDelReqMsg := &e2ap.E2APSubscriptionDeleteRequest{}
Juha Hyttinen83ada002020-01-30 10:36:33 +02001268 subDelReqMsg.RequestId = subs.GetReqId().RequestId
Konstantinos Archangelof26dfa712021-06-04 12:10:26 +00001269 subDelReqMsg.RequestId.Id = ricRequestorId
Juha Hyttinenaf91f972020-01-24 08:38:47 +02001270 subDelReqMsg.FunctionId = subs.SubReqMsg.FunctionId
Juha Hyttinen422d0182020-01-17 13:37:05 +02001271 trans.Mtype, trans.Payload, err = c.e2ap.PackSubscriptionDeleteRequest(subDelReqMsg)
1272 if err != nil {
Juha Hyttinen83ada002020-01-30 10:36:33 +02001273 xapp.Logger.Error("SUBS-SubDelReq: %s", idstring(err, trans, subs, parentTrans))
Juha Hyttinen422d0182020-01-17 13:37:05 +02001274 return event
1275 }
1276
1277 for retries := uint64(0); retries < e2tMaxSubDelReqTryCount; retries++ {
Juha Hyttinen83ada002020-01-30 10:36:33 +02001278 desc := fmt.Sprintf("(retry %d)", retries)
Anssi Mannila4abf1802021-01-28 13:06:46 +02001279 if retries == 0 {
1280 c.UpdateCounter(cSubDelReqToE2)
1281 } else {
1282 c.UpdateCounter(cSubDelReReqToE2)
1283 }
Anssi Mannila9c4697f2022-07-04 15:51:38 +03001284 err := c.rmrSendToE2T(desc, subs, trans)
1285 if err != nil {
1286 xapp.Logger.Error("SUBS-SubDelReq: rmrSendToE2T failure: %s", idstring(err, trans, subs, parentTrans))
1287 }
Juha Hyttinen422d0182020-01-17 13:37:05 +02001288 event, timedOut = trans.WaitEvent(e2tSubDelReqTime)
1289 if timedOut {
Anssi Mannila4abf1802021-01-28 13:06:46 +02001290 c.UpdateCounter(cSubDelReqTimerExpiry)
Juha Hyttinen422d0182020-01-17 13:37:05 +02001291 continue
1292 }
1293 break
1294 }
Juha Hyttinen83ada002020-01-30 10:36:33 +02001295 xapp.Logger.Debug("SUBS-SubDelReq: Response handling event(%s) %s", typeofSubsMessage(event), idstring(nil, trans, subs, parentTrans))
Juha Hyttinen422d0182020-01-17 13:37:05 +02001296 return event
1297}
1298
1299//-------------------------------------------------------------------
Anssi Mannila4abf1802021-01-28 13:06:46 +02001300// handle from E2T Subscription Response
Juha Hyttinen422d0182020-01-17 13:37:05 +02001301//-------------------------------------------------------------------
Juha Hyttinen9dc5adc2020-08-13 10:02:40 +03001302func (c *Control) handleE2TSubscriptionResponse(params *xapp.RMRParams) {
Anssi Mannilaf682ace2021-09-28 13:11:25 +03001303 xapp.Logger.Debug("MSG from E2T: %s", params.String())
Anssi Mannila4abf1802021-01-28 13:06:46 +02001304 c.UpdateCounter(cSubRespFromE2)
Anssi Mannila51122392021-05-25 11:51:31 +03001305
Juha Hyttinen422d0182020-01-17 13:37:05 +02001306 subRespMsg, err := c.e2ap.UnpackSubscriptionResponse(params.Payload)
1307 if err != nil {
Juha Hyttinen83ada002020-01-30 10:36:33 +02001308 xapp.Logger.Error("MSG-SubResp %s", idstring(err, params))
Juha Hyttinen422d0182020-01-17 13:37:05 +02001309 return
1310 }
Juha Hyttinenaada6452020-04-07 08:47:58 +03001311 subs, err := c.registry.GetSubscriptionFirstMatch([]uint32{subRespMsg.RequestId.InstanceId})
Juha Hyttinen422d0182020-01-17 13:37:05 +02001312 if err != nil {
Juha Hyttinen83ada002020-01-30 10:36:33 +02001313 xapp.Logger.Error("MSG-SubResp: %s", idstring(err, params))
Juha Hyttinen422d0182020-01-17 13:37:05 +02001314 return
Juha Hyttinen31797b42020-01-16 14:05:01 +02001315 }
1316 trans := subs.GetTransaction()
1317 if trans == nil {
Juha Hyttinen422d0182020-01-17 13:37:05 +02001318 err = fmt.Errorf("Ongoing transaction not found")
Juha Hyttinen83ada002020-01-30 10:36:33 +02001319 xapp.Logger.Error("MSG-SubResp: %s", idstring(err, params, subs))
Juha Hyttinenff8dccd2019-12-10 14:34:07 +02001320 return
Anssi Mannila2e99e2f2019-12-05 13:57:06 +02001321 }
Anssi Mannila54838ed2021-11-19 11:25:01 +02001322 xapp.Logger.Debug("SUBS-SubResp: Sending event, trans= %v", trans)
Juha Hyttinen422d0182020-01-17 13:37:05 +02001323 sendOk, timedOut := trans.SendEvent(subRespMsg, e2tRecvMsgTimeout)
1324 if sendOk == false {
1325 err = fmt.Errorf("Passing event to transaction failed: sendOk(%t) timedOut(%t)", sendOk, timedOut)
Juha Hyttinen83ada002020-01-30 10:36:33 +02001326 xapp.Logger.Error("MSG-SubResp: %s", idstring(err, trans, subs))
Peter Szilagyifbc56f92019-07-23 19:29:46 +00001327 }
Peter Szilagyifbc56f92019-07-23 19:29:46 +00001328 return
kalnagy45114752019-06-18 14:40:39 +02001329}
1330
Juha Hyttinen422d0182020-01-17 13:37:05 +02001331//-------------------------------------------------------------------
1332// handle from E2T Subscription Failure
1333//-------------------------------------------------------------------
Juha Hyttinen9dc5adc2020-08-13 10:02:40 +03001334func (c *Control) handleE2TSubscriptionFailure(params *xapp.RMRParams) {
Anssi Mannilaf682ace2021-09-28 13:11:25 +03001335 xapp.Logger.Debug("MSG from E2T: %s", params.String())
Anssi Mannila4abf1802021-01-28 13:06:46 +02001336 c.UpdateCounter(cSubFailFromE2)
Juha Hyttinen422d0182020-01-17 13:37:05 +02001337 subFailMsg, err := c.e2ap.UnpackSubscriptionFailure(params.Payload)
Peter Szilagyifbc56f92019-07-23 19:29:46 +00001338 if err != nil {
Juha Hyttinen83ada002020-01-30 10:36:33 +02001339 xapp.Logger.Error("MSG-SubFail %s", idstring(err, params))
Peter Szilagyifbc56f92019-07-23 19:29:46 +00001340 return
1341 }
Juha Hyttinenaada6452020-04-07 08:47:58 +03001342 subs, err := c.registry.GetSubscriptionFirstMatch([]uint32{subFailMsg.RequestId.InstanceId})
Juha Hyttinen31797b42020-01-16 14:05:01 +02001343 if err != nil {
Juha Hyttinen83ada002020-01-30 10:36:33 +02001344 xapp.Logger.Error("MSG-SubFail: %s", idstring(err, params))
Juha Hyttinenaafee7f2020-01-14 14:54:51 +02001345 return
1346 }
Juha Hyttinen422d0182020-01-17 13:37:05 +02001347 trans := subs.GetTransaction()
1348 if trans == nil {
1349 err = fmt.Errorf("Ongoing transaction not found")
Juha Hyttinen83ada002020-01-30 10:36:33 +02001350 xapp.Logger.Error("MSG-SubFail: %s", idstring(err, params, subs))
Anssi Mannila8046c702020-01-02 13:39:05 +02001351 return
1352 }
Juha Hyttinen422d0182020-01-17 13:37:05 +02001353 sendOk, timedOut := trans.SendEvent(subFailMsg, e2tRecvMsgTimeout)
1354 if sendOk == false {
1355 err = fmt.Errorf("Passing event to transaction failed: sendOk(%t) timedOut(%t)", sendOk, timedOut)
Juha Hyttinen83ada002020-01-30 10:36:33 +02001356 xapp.Logger.Error("MSG-SubFail: %s", idstring(err, trans, subs))
Juha Hyttinenaafee7f2020-01-14 14:54:51 +02001357 }
Anssi Mannila2e99e2f2019-12-05 13:57:06 +02001358 return
1359}
1360
Juha Hyttinen422d0182020-01-17 13:37:05 +02001361//-------------------------------------------------------------------
1362// handle from E2T Subscription Delete Response
1363//-------------------------------------------------------------------
Anssi Mannila9c4697f2022-07-04 15:51:38 +03001364func (c *Control) handleE2TSubscriptionDeleteResponse(params *xapp.RMRParams) {
Anssi Mannilaf682ace2021-09-28 13:11:25 +03001365 xapp.Logger.Debug("MSG from E2T: %s", params.String())
Anssi Mannila4abf1802021-01-28 13:06:46 +02001366 c.UpdateCounter(cSubDelRespFromE2)
Juha Hyttinen422d0182020-01-17 13:37:05 +02001367 subDelRespMsg, err := c.e2ap.UnpackSubscriptionDeleteResponse(params.Payload)
Anssi Mannila2e99e2f2019-12-05 13:57:06 +02001368 if err != nil {
Juha Hyttinen83ada002020-01-30 10:36:33 +02001369 xapp.Logger.Error("MSG-SubDelResp: %s", idstring(err, params))
Anssi Mannila2e99e2f2019-12-05 13:57:06 +02001370 return
1371 }
Juha Hyttinenaada6452020-04-07 08:47:58 +03001372 subs, err := c.registry.GetSubscriptionFirstMatch([]uint32{subDelRespMsg.RequestId.InstanceId})
Juha Hyttinen31797b42020-01-16 14:05:01 +02001373 if err != nil {
Juha Hyttinen83ada002020-01-30 10:36:33 +02001374 xapp.Logger.Error("MSG-SubDelResp: %s", idstring(err, params))
Juha Hyttinen0d064ec2020-01-09 09:08:53 +02001375 return
1376 }
Juha Hyttinen422d0182020-01-17 13:37:05 +02001377 trans := subs.GetTransaction()
1378 if trans == nil {
1379 err = fmt.Errorf("Ongoing transaction not found")
Juha Hyttinen83ada002020-01-30 10:36:33 +02001380 xapp.Logger.Error("MSG-SubDelResp: %s", idstring(err, params, subs))
Anssi Mannila8046c702020-01-02 13:39:05 +02001381 return
Anssi Mannila2e99e2f2019-12-05 13:57:06 +02001382 }
Juha Hyttinen422d0182020-01-17 13:37:05 +02001383 sendOk, timedOut := trans.SendEvent(subDelRespMsg, e2tRecvMsgTimeout)
1384 if sendOk == false {
1385 err = fmt.Errorf("Passing event to transaction failed: sendOk(%t) timedOut(%t)", sendOk, timedOut)
Juha Hyttinen83ada002020-01-30 10:36:33 +02001386 xapp.Logger.Error("MSG-SubDelResp: %s", idstring(err, trans, subs))
Juha Hyttinen60bfcf92020-01-14 15:14:24 +02001387 }
Anssi Mannila2e99e2f2019-12-05 13:57:06 +02001388 return
1389}
1390
Juha Hyttinen422d0182020-01-17 13:37:05 +02001391//-------------------------------------------------------------------
1392// handle from E2T Subscription Delete Failure
1393//-------------------------------------------------------------------
Juha Hyttinen9dc5adc2020-08-13 10:02:40 +03001394func (c *Control) handleE2TSubscriptionDeleteFailure(params *xapp.RMRParams) {
Anssi Mannilaf682ace2021-09-28 13:11:25 +03001395 xapp.Logger.Debug("MSG from E2T: %s", params.String())
Anssi Mannila4abf1802021-01-28 13:06:46 +02001396 c.UpdateCounter(cSubDelFailFromE2)
Juha Hyttinen422d0182020-01-17 13:37:05 +02001397 subDelFailMsg, err := c.e2ap.UnpackSubscriptionDeleteFailure(params.Payload)
Juha Hyttinen31797b42020-01-16 14:05:01 +02001398 if err != nil {
Juha Hyttinen83ada002020-01-30 10:36:33 +02001399 xapp.Logger.Error("MSG-SubDelFail: %s", idstring(err, params))
Anssi Mannilaf1d0eb62019-12-17 15:29:55 +02001400 return
1401 }
Juha Hyttinenaada6452020-04-07 08:47:58 +03001402 subs, err := c.registry.GetSubscriptionFirstMatch([]uint32{subDelFailMsg.RequestId.InstanceId})
Anssi Mannila8046c702020-01-02 13:39:05 +02001403 if err != nil {
Juha Hyttinen83ada002020-01-30 10:36:33 +02001404 xapp.Logger.Error("MSG-SubDelFail: %s", idstring(err, params))
Anssi Mannila8046c702020-01-02 13:39:05 +02001405 return
1406 }
Juha Hyttinen422d0182020-01-17 13:37:05 +02001407 trans := subs.GetTransaction()
1408 if trans == nil {
1409 err = fmt.Errorf("Ongoing transaction not found")
Juha Hyttinen83ada002020-01-30 10:36:33 +02001410 xapp.Logger.Error("MSG-SubDelFail: %s", idstring(err, params, subs))
Juha Hyttinen86a46202020-01-14 12:49:09 +02001411 return
1412 }
Juha Hyttinen422d0182020-01-17 13:37:05 +02001413 sendOk, timedOut := trans.SendEvent(subDelFailMsg, e2tRecvMsgTimeout)
1414 if sendOk == false {
1415 err = fmt.Errorf("Passing event to transaction failed: sendOk(%t) timedOut(%t)", sendOk, timedOut)
Juha Hyttinen83ada002020-01-30 10:36:33 +02001416 xapp.Logger.Error("MSG-SubDelFail: %s", idstring(err, trans, subs))
Anssi Mannila8046c702020-01-02 13:39:05 +02001417 }
kalnagy93cc3e22019-09-19 11:29:29 +02001418 return
1419}
1420
Juha Hyttinen422d0182020-01-17 13:37:05 +02001421//-------------------------------------------------------------------
1422//
1423//-------------------------------------------------------------------
1424func typeofSubsMessage(v interface{}) string {
1425 if v == nil {
1426 return "NIL"
kalnagy93cc3e22019-09-19 11:29:29 +02001427 }
Juha Hyttinen422d0182020-01-17 13:37:05 +02001428 switch v.(type) {
Anssi Mannila51122392021-05-25 11:51:31 +03001429 //case *e2ap.E2APSubscriptionRequest:
1430 // return "SubReq"
Juha Hyttinen422d0182020-01-17 13:37:05 +02001431 case *e2ap.E2APSubscriptionResponse:
1432 return "SubResp"
1433 case *e2ap.E2APSubscriptionFailure:
1434 return "SubFail"
Anssi Mannila51122392021-05-25 11:51:31 +03001435 //case *e2ap.E2APSubscriptionDeleteRequest:
1436 // return "SubDelReq"
Juha Hyttinen422d0182020-01-17 13:37:05 +02001437 case *e2ap.E2APSubscriptionDeleteResponse:
1438 return "SubDelResp"
1439 case *e2ap.E2APSubscriptionDeleteFailure:
1440 return "SubDelFail"
1441 default:
1442 return "Unknown"
Juha Hyttinen31797b42020-01-16 14:05:01 +02001443 }
Anssi Mannilaf1d0eb62019-12-17 15:29:55 +02001444}
Anssi Mannilac92b4212020-12-07 14:59:34 +02001445
1446//-------------------------------------------------------------------
1447//
1448//-------------------------------------------------------------------
Anssi Mannilaf682ace2021-09-28 13:11:25 +03001449func (c *Control) WriteSubscriptionToDb(subs *Subscription) error {
Anssi Mannilac92b4212020-12-07 14:59:34 +02001450 xapp.Logger.Debug("WriteSubscriptionToDb() subId = %v", subs.ReqId.InstanceId)
1451 err := c.WriteSubscriptionToSdl(subs.ReqId.InstanceId, subs)
1452 if err != nil {
1453 xapp.Logger.Error("%v", err)
Anssi Mannilaf682ace2021-09-28 13:11:25 +03001454 return err
Anssi Mannilac92b4212020-12-07 14:59:34 +02001455 }
Anssi Mannilaf682ace2021-09-28 13:11:25 +03001456 return nil
Anssi Mannilac92b4212020-12-07 14:59:34 +02001457}
1458
1459//-------------------------------------------------------------------
1460//
1461//-------------------------------------------------------------------
Anssi Mannilaf682ace2021-09-28 13:11:25 +03001462func (c *Control) UpdateSubscriptionInDB(subs *Subscription, removeSubscriptionFromDb bool) error {
Anssi Mannilac92b4212020-12-07 14:59:34 +02001463
1464 if removeSubscriptionFromDb == true {
1465 // Subscription was written in db already when subscription request was sent to BTS, except for merged request
1466 c.RemoveSubscriptionFromDb(subs)
1467 } else {
1468 // Update is needed for successful response and merge case here
1469 if subs.RetryFromXapp == false {
Anssi Mannilaf682ace2021-09-28 13:11:25 +03001470 err := c.WriteSubscriptionToDb(subs)
1471 return err
Anssi Mannilac92b4212020-12-07 14:59:34 +02001472 }
1473 }
1474 subs.RetryFromXapp = false
Anssi Mannilaf682ace2021-09-28 13:11:25 +03001475 return nil
Anssi Mannilac92b4212020-12-07 14:59:34 +02001476}
1477
1478//-------------------------------------------------------------------
1479//
1480//-------------------------------------------------------------------
1481func (c *Control) RemoveSubscriptionFromDb(subs *Subscription) {
1482 xapp.Logger.Debug("RemoveSubscriptionFromDb() subId = %v", subs.ReqId.InstanceId)
1483 err := c.RemoveSubscriptionFromSdl(subs.ReqId.InstanceId)
1484 if err != nil {
1485 xapp.Logger.Error("%v", err)
1486 }
1487}
1488
Konstantinos Archangelof268d7152021-06-14 12:24:00 +03001489//-------------------------------------------------------------------
1490//
1491//-------------------------------------------------------------------
1492func (c *Control) WriteRESTSubscriptionToDb(restSubId string, restSubs *RESTSubscription) {
1493 xapp.Logger.Debug("WriteRESTSubscriptionToDb() restSubId = %s", restSubId)
1494 err := c.WriteRESTSubscriptionToSdl(restSubId, restSubs)
1495 if err != nil {
1496 xapp.Logger.Error("%v", err)
1497 }
1498}
1499
1500//-------------------------------------------------------------------
1501//
1502//-------------------------------------------------------------------
1503func (c *Control) UpdateRESTSubscriptionInDB(restSubId string, restSubs *RESTSubscription, removeRestSubscriptionFromDb bool) {
1504
1505 if removeRestSubscriptionFromDb == true {
1506 // Subscription was written in db already when subscription request was sent to BTS, except for merged request
1507 c.RemoveRESTSubscriptionFromDb(restSubId)
1508 } else {
1509 c.WriteRESTSubscriptionToDb(restSubId, restSubs)
1510 }
1511}
1512
1513//-------------------------------------------------------------------
1514//
1515//-------------------------------------------------------------------
1516func (c *Control) RemoveRESTSubscriptionFromDb(restSubId string) {
1517 xapp.Logger.Debug("RemoveRESTSubscriptionFromDb() restSubId = %s", restSubId)
1518 err := c.RemoveRESTSubscriptionFromSdl(restSubId)
1519 if err != nil {
1520 xapp.Logger.Error("%v", err)
1521 }
1522}
1523
Anssi Mannilac92b4212020-12-07 14:59:34 +02001524func (c *Control) SendSubscriptionDeleteReq(subs *Subscription) {
1525
Anssi Mannila54838ed2021-11-19 11:25:01 +02001526 if c.UTTesting == true {
1527 // Reqistry mutex is not locked after real restart but it can be when restart is simulated in unit tests
1528 c.registry.mutex = new(sync.Mutex)
1529 }
1530
Konstantinos Archangelof26dfa712021-06-04 12:10:26 +00001531 const ricRequestorId = 123
Anssi Mannilac92b4212020-12-07 14:59:34 +02001532 xapp.Logger.Debug("Sending subscription delete due to restart. subId = %v", subs.ReqId.InstanceId)
1533
1534 // Send delete for every endpoint in the subscription
Anssi Mannilaf682ace2021-09-28 13:11:25 +03001535 if subs.PolicyUpdate == false {
1536 subDelReqMsg := &e2ap.E2APSubscriptionDeleteRequest{}
1537 subDelReqMsg.RequestId = subs.GetReqId().RequestId
1538 subDelReqMsg.RequestId.Id = ricRequestorId
1539 subDelReqMsg.FunctionId = subs.SubReqMsg.FunctionId
1540 mType, payload, err := c.e2ap.PackSubscriptionDeleteRequest(subDelReqMsg)
1541 if err != nil {
1542 xapp.Logger.Error("SendSubscriptionDeleteReq() %s", idstring(err))
1543 return
1544 }
1545 for _, endPoint := range subs.EpList.Endpoints {
1546 params := &xapp.RMRParams{}
1547 params.Mtype = mType
1548 params.SubId = int(subs.GetReqId().InstanceId)
1549 params.Xid = ""
1550 params.Meid = subs.Meid
1551 params.Src = endPoint.String()
1552 params.PayloadLen = len(payload.Buf)
1553 params.Payload = payload.Buf
1554 params.Mbuf = nil
1555 subs.DeleteFromDb = true
1556 c.handleXAPPSubscriptionDeleteRequest(params)
1557 }
Anssi Mannilac92b4212020-12-07 14:59:34 +02001558 }
1559}
Anssi Mannilade457a12021-06-02 16:19:48 +03001560
1561func (c *Control) PrintRESTSubscriptionRequest(p *models.SubscriptionParams) {
1562
1563 fmt.Println("CRESTSubscriptionRequest")
Markku Virtanen987f8b12021-06-10 15:05:02 +03001564
Markku Virtanen2b512b62021-07-30 12:04:00 +00001565 if p == nil {
1566 return
1567 }
1568
Markku Virtanen987f8b12021-06-10 15:05:02 +03001569 if p.SubscriptionID != "" {
1570 fmt.Println(" SubscriptionID = ", p.SubscriptionID)
1571 } else {
1572 fmt.Println(" SubscriptionID = ''")
1573 }
1574
Anssi Mannilade457a12021-06-02 16:19:48 +03001575 fmt.Printf(" ClientEndpoint.Host = %s\n", p.ClientEndpoint.Host)
1576
1577 if p.ClientEndpoint.HTTPPort != nil {
1578 fmt.Printf(" ClientEndpoint.HTTPPort = %v\n", *p.ClientEndpoint.HTTPPort)
1579 } else {
1580 fmt.Println(" ClientEndpoint.HTTPPort = nil")
1581 }
1582
1583 if p.ClientEndpoint.RMRPort != nil {
1584 fmt.Printf(" ClientEndpoint.RMRPort = %v\n", *p.ClientEndpoint.RMRPort)
1585 } else {
1586 fmt.Println(" ClientEndpoint.RMRPort = nil")
1587 }
1588
1589 if p.Meid != nil {
1590 fmt.Printf(" Meid = %s\n", *p.Meid)
1591 } else {
1592 fmt.Println(" Meid = nil")
1593 }
1594
Anssi Mannilaf682ace2021-09-28 13:11:25 +03001595 if p.E2SubscriptionDirectives == nil {
1596 fmt.Println(" E2SubscriptionDirectives = nil")
1597 } else {
1598 fmt.Println(" E2SubscriptionDirectives")
1599 if p.E2SubscriptionDirectives.E2RetryCount == nil {
1600 fmt.Println(" E2RetryCount == nil")
1601 } else {
1602 fmt.Printf(" E2RetryCount = %v\n", *p.E2SubscriptionDirectives.E2RetryCount)
1603 }
1604 fmt.Printf(" E2TimeoutTimerValue = %v\n", p.E2SubscriptionDirectives.E2TimeoutTimerValue)
Anssi Mannilacb7dd492021-10-01 11:10:26 +03001605 fmt.Printf(" RMRRoutingNeeded = %v\n", p.E2SubscriptionDirectives.RMRRoutingNeeded)
Anssi Mannilaf682ace2021-09-28 13:11:25 +03001606 }
Anssi Mannilade457a12021-06-02 16:19:48 +03001607 for _, subscriptionDetail := range p.SubscriptionDetails {
1608 if p.RANFunctionID != nil {
1609 fmt.Printf(" RANFunctionID = %v\n", *p.RANFunctionID)
1610 } else {
1611 fmt.Println(" RANFunctionID = nil")
1612 }
Konstantinos Archangelofe93b00f2021-06-03 10:00:19 +00001613 fmt.Printf(" SubscriptionDetail.XappEventInstanceID = %v\n", *subscriptionDetail.XappEventInstanceID)
Konstantinos Archangelofbd9c98e2021-06-07 17:32:10 +00001614 fmt.Printf(" SubscriptionDetail.EventTriggers = %v\n", subscriptionDetail.EventTriggers)
Anssi Mannilade457a12021-06-02 16:19:48 +03001615
1616 for _, actionToBeSetup := range subscriptionDetail.ActionToBeSetupList {
1617 fmt.Printf(" SubscriptionDetail.ActionToBeSetup.ActionID = %v\n", *actionToBeSetup.ActionID)
1618 fmt.Printf(" SubscriptionDetail.ActionToBeSetup.ActionType = %s\n", *actionToBeSetup.ActionType)
Konstantinos Archangelofbd9c98e2021-06-07 17:32:10 +00001619 fmt.Printf(" SubscriptionDetail.ActionToBeSetup.ActionDefinition = %v\n", actionToBeSetup.ActionDefinition)
Anssi Mannilade457a12021-06-02 16:19:48 +03001620
Anssi Mannilade457a12021-06-02 16:19:48 +03001621 if actionToBeSetup.SubsequentAction != nil {
1622 fmt.Printf(" SubscriptionDetail.ActionToBeSetup.SubsequentAction.SubsequentActionType = %s\n", *actionToBeSetup.SubsequentAction.SubsequentActionType)
1623 fmt.Printf(" SubscriptionDetail.ActionToBeSetup..SubsequentAction.TimeToWait = %s\n", *actionToBeSetup.SubsequentAction.TimeToWait)
1624 } else {
1625 fmt.Println(" SubscriptionDetail.ActionToBeSetup.SubsequentAction = nil")
1626 }
1627 }
1628 }
1629}