blob: 49b7968428661dce37f445fb8804481bf465a843 [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 Mannila3cdd2e02021-10-14 12:35:41 +0300183 go xapp.Subscription.Listen(c.RESTSubscriptionHandler, c.RESTQueryHandler, c.RESTSubscriptionDeleteHandler)
Anssi Mannilac92b4212020-12-07 14:59:34 +0200184 return c
185}
186
Abukar Mohamedfbd4df52021-03-11 06:13:27 +0000187func (c *Control) SymptomDataHandler(w http.ResponseWriter, r *http.Request) {
Anssi Mannila9c4697f2022-07-04 15:51:38 +0300188 subscriptions, err := c.registry.QueryHandler()
189 if err != nil {
190 xapp.Logger.Error("QueryHandler() failed %s", err.Error())
191 }
192
Abukar Mohamedfbd4df52021-03-11 06:13:27 +0000193 xapp.Resource.SendSymptomDataJson(w, r, subscriptions, "platform/subscriptions.json")
194}
195
Anssi Mannilac92b4212020-12-07 14:59:34 +0200196//-------------------------------------------------------------------
197//
198//-------------------------------------------------------------------
Anssi Mannila92c38552021-12-29 09:59:24 +0200199func (c *Control) RESTQueryHandler() (models.SubscriptionList, error) {
200 xapp.Logger.Debug("RESTQueryHandler() called")
201
202 c.CntRecvMsg++
203
204 return c.registry.QueryHandler()
Anssi Mannilab73e7cd2021-08-03 11:57:11 +0300205}
206
207//-------------------------------------------------------------------
208//
209//-------------------------------------------------------------------
210func (c *Control) ReadE2Subscriptions() error {
211 var err error
212 var subIds []uint32
213 var register map[uint32]*Subscription
214 for i := 0; dbRetryForever == "true" || i < dbTryCount; i++ {
Anssi Mannilaf682ace2021-09-28 13:11:25 +0300215 xapp.Logger.Debug("Reading E2 subscriptions from db")
Anssi Mannilab73e7cd2021-08-03 11:57:11 +0300216 subIds, register, err = c.ReadAllSubscriptionsFromSdl()
217 if err != nil {
218 xapp.Logger.Error("%v", err)
219 <-time.After(1 * time.Second)
220 } else {
221 c.registry.subIds = subIds
222 c.registry.register = register
Anssi Mannila316b8d22021-12-21 09:43:59 +0200223 go c.HandleUncompletedSubscriptions(register)
Anssi Mannilab73e7cd2021-08-03 11:57:11 +0300224 return nil
225 }
226 }
Anssi Mannilaf682ace2021-09-28 13:11:25 +0300227 xapp.Logger.Debug("Continuing without retring")
Anssi Mannilab73e7cd2021-08-03 11:57:11 +0300228 return err
229}
230
231//-------------------------------------------------------------------
232//
233//-------------------------------------------------------------------
234func (c *Control) ReadRESTSubscriptions() error {
Anssi Mannila54838ed2021-11-19 11:25:01 +0200235
236 xapp.Logger.Debug("ReadRESTSubscriptions()")
Anssi Mannilab73e7cd2021-08-03 11:57:11 +0300237 var err error
238 var restSubscriptions map[string]*RESTSubscription
239 for i := 0; dbRetryForever == "true" || i < dbTryCount; i++ {
Anssi Mannilaf682ace2021-09-28 13:11:25 +0300240 xapp.Logger.Debug("Reading REST subscriptions from db")
Anssi Mannilab73e7cd2021-08-03 11:57:11 +0300241 restSubscriptions, err = c.ReadAllRESTSubscriptionsFromSdl()
242 if err != nil {
243 xapp.Logger.Error("%v", err)
244 <-time.After(1 * time.Second)
245 } else {
Anssi Mannila54838ed2021-11-19 11:25:01 +0200246 // Fix REST subscriptions ongoing status after restart
247 for restSubId, restSubscription := range restSubscriptions {
248 restSubscription.SubReqOngoing = false
249 restSubscription.SubDelReqOngoing = false
Anssi Mannila9c4697f2022-07-04 15:51:38 +0300250 err := c.WriteRESTSubscriptionToSdl(restSubId, restSubscription)
251 if err != nil {
252 xapp.Logger.Error("WriteRESTSubscriptionToSdl() failed:%s", err.Error())
253 }
Anssi Mannila54838ed2021-11-19 11:25:01 +0200254 }
Anssi Mannilab73e7cd2021-08-03 11:57:11 +0300255 c.registry.restSubscriptions = restSubscriptions
256 return nil
257 }
258 }
Anssi Mannilaf682ace2021-09-28 13:11:25 +0300259 xapp.Logger.Debug("Continuing without retring")
Anssi Mannilab73e7cd2021-08-03 11:57:11 +0300260 return err
261}
262
263//-------------------------------------------------------------------
264//
265//-------------------------------------------------------------------
Anssi Mannilaf6b78042021-02-18 12:36:59 +0200266func (c *Control) ReadConfigParameters(f string) {
Anssi Mannilac92b4212020-12-07 14:59:34 +0200267
Anssi Mannilac7da4ee2021-10-22 09:52:02 +0300268 xapp.Logger.Debug("ReadConfigParameters")
269
Anssi Mannilaf682ace2021-09-28 13:11:25 +0300270 c.LoggerLevel = int(xapp.Logger.GetLevel())
Anssi Mannila3d80b722021-11-12 13:17:15 +0200271 xapp.Logger.Info("LoggerLevel = %v", c.LoggerLevel)
Anssi Mannilae1af87f2021-11-10 13:10:54 +0200272 c.e2ap.SetASN1DebugPrintStatus(c.LoggerLevel)
Anssi Mannilaf682ace2021-09-28 13:11:25 +0300273
Anssi Mannila2f26fb22020-12-07 08:32:13 +0200274 // viper.GetDuration returns nanoseconds
275 e2tSubReqTimeout = viper.GetDuration("controls.e2tSubReqTimeout_ms") * 1000000
Juha Hyttinen57140bc2020-12-11 13:03:06 +0200276 if e2tSubReqTimeout == 0 {
277 e2tSubReqTimeout = 2000 * 1000000
Anssi Mannilac7da4ee2021-10-22 09:52:02 +0300278 xapp.Logger.Debug("WARNING: Using hard coded default value for e2tSubReqTimeout")
Juha Hyttinen57140bc2020-12-11 13:03:06 +0200279 }
Anssi Mannilac7da4ee2021-10-22 09:52:02 +0300280 xapp.Logger.Debug("e2tSubReqTimeout= %v", e2tSubReqTimeout)
Anssi Mannilaf682ace2021-09-28 13:11:25 +0300281
Anssi Mannila2f26fb22020-12-07 08:32:13 +0200282 e2tSubDelReqTime = viper.GetDuration("controls.e2tSubDelReqTime_ms") * 1000000
Juha Hyttinen57140bc2020-12-11 13:03:06 +0200283 if e2tSubDelReqTime == 0 {
284 e2tSubDelReqTime = 2000 * 1000000
Anssi Mannilac7da4ee2021-10-22 09:52:02 +0300285 xapp.Logger.Debug("WARNING: Using hard coded default value for e2tSubDelReqTime")
Juha Hyttinen57140bc2020-12-11 13:03:06 +0200286 }
Anssi Mannilac7da4ee2021-10-22 09:52:02 +0300287 xapp.Logger.Debug("e2tSubDelReqTime= %v", e2tSubDelReqTime)
288
Anssi Mannila2f26fb22020-12-07 08:32:13 +0200289 e2tRecvMsgTimeout = viper.GetDuration("controls.e2tRecvMsgTimeout_ms") * 1000000
Juha Hyttinen57140bc2020-12-11 13:03:06 +0200290 if e2tRecvMsgTimeout == 0 {
291 e2tRecvMsgTimeout = 2000 * 1000000
Anssi Mannilac7da4ee2021-10-22 09:52:02 +0300292 xapp.Logger.Debug("WARNING: Using hard coded default value for e2tRecvMsgTimeout")
Juha Hyttinen57140bc2020-12-11 13:03:06 +0200293 }
Anssi Mannilac7da4ee2021-10-22 09:52:02 +0300294 xapp.Logger.Debug("e2tRecvMsgTimeout= %v", e2tRecvMsgTimeout)
Markku Virtanenfe2cdab2021-05-21 10:59:29 +0000295
Anssi Mannila2f26fb22020-12-07 08:32:13 +0200296 e2tMaxSubReqTryCount = viper.GetUint64("controls.e2tMaxSubReqTryCount")
Juha Hyttinen57140bc2020-12-11 13:03:06 +0200297 if e2tMaxSubReqTryCount == 0 {
298 e2tMaxSubReqTryCount = 1
Anssi Mannilac7da4ee2021-10-22 09:52:02 +0300299 xapp.Logger.Debug("WARNING: Using hard coded default value for e2tMaxSubReqTryCount")
Juha Hyttinen57140bc2020-12-11 13:03:06 +0200300 }
Anssi Mannilac7da4ee2021-10-22 09:52:02 +0300301 xapp.Logger.Debug("e2tMaxSubReqTryCount= %v", e2tMaxSubReqTryCount)
Markku Virtanenfe2cdab2021-05-21 10:59:29 +0000302
Anssi Mannila2f26fb22020-12-07 08:32:13 +0200303 e2tMaxSubDelReqTryCount = viper.GetUint64("controls.e2tMaxSubDelReqTryCount")
Juha Hyttinen57140bc2020-12-11 13:03:06 +0200304 if e2tMaxSubDelReqTryCount == 0 {
305 e2tMaxSubDelReqTryCount = 1
Anssi Mannilac7da4ee2021-10-22 09:52:02 +0300306 xapp.Logger.Debug("WARNING: Using hard coded default value for e2tMaxSubDelReqTryCount")
Juha Hyttinen57140bc2020-12-11 13:03:06 +0200307 }
Anssi Mannilac7da4ee2021-10-22 09:52:02 +0300308 xapp.Logger.Debug("e2tMaxSubDelReqTryCount= %v", e2tMaxSubDelReqTryCount)
309
310 checkE2State = viper.GetString("controls.checkE2State")
311 if checkE2State == "" {
312 checkE2State = "true"
313 xapp.Logger.Debug("WARNING: Using hard coded default value for checkE2State")
314 }
315 xapp.Logger.Debug("checkE2State= %v", checkE2State)
Anssi Mannila2f26fb22020-12-07 08:32:13 +0200316
Anssi Mannilac92b4212020-12-07 14:59:34 +0200317 readSubsFromDb = viper.GetString("controls.readSubsFromDb")
318 if readSubsFromDb == "" {
319 readSubsFromDb = "true"
Anssi Mannilac7da4ee2021-10-22 09:52:02 +0300320 xapp.Logger.Debug("WARNING: Using hard coded default value for readSubsFromDb")
Juha Hyttinen5f8ffa02020-02-06 15:28:59 +0200321 }
Anssi Mannilac7da4ee2021-10-22 09:52:02 +0300322 xapp.Logger.Debug("readSubsFromDb= %v", readSubsFromDb)
Anssi Mannilab73e7cd2021-08-03 11:57:11 +0300323
324 dbTryCount = viper.GetInt("controls.dbTryCount")
325 if dbTryCount == 0 {
326 dbTryCount = 200
Anssi Mannilac7da4ee2021-10-22 09:52:02 +0300327 xapp.Logger.Debug("WARNING: Using hard coded default value for dbTryCount")
Anssi Mannilab73e7cd2021-08-03 11:57:11 +0300328 }
Anssi Mannilac7da4ee2021-10-22 09:52:02 +0300329 xapp.Logger.Debug("dbTryCount= %v", dbTryCount)
Anssi Mannilab73e7cd2021-08-03 11:57:11 +0300330
331 dbRetryForever = viper.GetString("controls.dbRetryForever")
332 if dbRetryForever == "" {
333 dbRetryForever = "true"
Anssi Mannilac7da4ee2021-10-22 09:52:02 +0300334 xapp.Logger.Debug("WARNING: Using hard coded default value for dbRetryForever")
Anssi Mannilab73e7cd2021-08-03 11:57:11 +0300335 }
Anssi Mannilac7da4ee2021-10-22 09:52:02 +0300336 xapp.Logger.Debug("dbRetryForever= %v", dbRetryForever)
Anssi Mannilab73e7cd2021-08-03 11:57:11 +0300337
338 // Internal cfg parameter, used to define a wait time for RMR route clean-up. None default
339 // value 100ms used currently only in unittests.
340 waitRouteCleanup_ms = viper.GetDuration("controls.waitRouteCleanup_ms") * 1000000
341 if waitRouteCleanup_ms == 0 {
342 waitRouteCleanup_ms = 5000 * 1000000
Anssi Mannilac7da4ee2021-10-22 09:52:02 +0300343 xapp.Logger.Debug("WARNING: Using hard coded default value for waitRouteCleanup_ms")
Anssi Mannilab73e7cd2021-08-03 11:57:11 +0300344 }
Anssi Mannilac7da4ee2021-10-22 09:52:02 +0300345 xapp.Logger.Debug("waitRouteCleanup= %v", waitRouteCleanup_ms)
Anssi Mannilac92b4212020-12-07 14:59:34 +0200346}
347
348//-------------------------------------------------------------------
349//
350//-------------------------------------------------------------------
351func (c *Control) HandleUncompletedSubscriptions(register map[uint32]*Subscription) {
352
353 xapp.Logger.Debug("HandleUncompletedSubscriptions. len(register) = %v", len(register))
354 for subId, subs := range register {
355 if subs.SubRespRcvd == false {
Anssi Mannilaf682ace2021-09-28 13:11:25 +0300356 // If policy subscription has already been made successfully unsuccessful update should not be deleted.
357 if subs.PolicyUpdate == false {
358 subs.NoRespToXapp = true
359 xapp.Logger.Debug("SendSubscriptionDeleteReq. subId = %v", subId)
360 c.SendSubscriptionDeleteReq(subs)
361 }
Anssi Mannilac92b4212020-12-07 14:59:34 +0200362 }
363 }
Juha Hyttinen5f8ffa02020-02-06 15:28:59 +0200364}
365
366func (c *Control) ReadyCB(data interface{}) {
Juha Hyttinen9dc5adc2020-08-13 10:02:40 +0300367 if c.RMRClient == nil {
368 c.RMRClient = xapp.Rmr
Juha Hyttinenff8dccd2019-12-10 14:34:07 +0200369 }
kalnagy45114752019-06-18 14:40:39 +0200370}
371
372func (c *Control) Run() {
Juha Hyttinen5f8ffa02020-02-06 15:28:59 +0200373 xapp.SetReadyCB(c.ReadyCB, nil)
Anssi Mannilaf6b78042021-02-18 12:36:59 +0200374 xapp.AddConfigChangeListener(c.ReadConfigParameters)
Peter Szilagyifbc56f92019-07-23 19:29:46 +0000375 xapp.Run(c)
kalnagy45114752019-06-18 14:40:39 +0200376}
377
Juha Hyttinenc9eb08a2020-02-28 08:53:33 +0200378//-------------------------------------------------------------------
379//
380//-------------------------------------------------------------------
Anssi Mannila92c38552021-12-29 09:59:24 +0200381func (c *Control) GetOrCreateRestSubscription(p *models.SubscriptionParams, md5sum string, xAppRmrEndpoint string, xAppServiceName string) (*RESTSubscription, string, error) {
Markku Virtanen42723e22021-06-15 10:09:23 +0300382
383 var restSubId string
384 var restSubscription *RESTSubscription
385 var err error
386
Anssi Mannila3cdd2e02021-10-14 12:35:41 +0300387 prevRestSubsId, exists := c.restDuplicateCtrl.GetLastKnownRestSubsIdBasedOnMd5sum(md5sum)
Markku Virtanen42723e22021-06-15 10:09:23 +0300388 if p.SubscriptionID == "" {
Anssi Mannilaf682ace2021-09-28 13:11:25 +0300389 // Subscription does not contain REST subscription Id
Markku Virtanen42723e22021-06-15 10:09:23 +0300390 if exists {
391 restSubscription, err = c.registry.GetRESTSubscription(prevRestSubsId, false)
392 if restSubscription != nil {
Anssi Mannilaf682ace2021-09-28 13:11:25 +0300393 // Subscription not found
Markku Virtanen42723e22021-06-15 10:09:23 +0300394 restSubId = prevRestSubsId
395 if err == nil {
Anssi Mannilaf682ace2021-09-28 13:11:25 +0300396 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 +0300397 } else {
Anssi Mannilaf682ace2021-09-28 13:11:25 +0300398 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 +0300399 }
400 } else {
Anssi Mannilaf682ace2021-09-28 13:11:25 +0300401 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 +0300402 c.restDuplicateCtrl.DeleteLastKnownRestSubsIdBasedOnMd5sum(md5sum)
Markku Virtanen42723e22021-06-15 10:09:23 +0300403 }
404 }
405
406 if restSubscription == nil {
407 restSubId = ksuid.New().String()
Anssi Mannila92c38552021-12-29 09:59:24 +0200408 restSubscription = c.registry.CreateRESTSubscription(&restSubId, &xAppServiceName, &xAppRmrEndpoint, p.Meid)
Markku Virtanen42723e22021-06-15 10:09:23 +0300409 }
410 } else {
Anssi Mannilaf682ace2021-09-28 13:11:25 +0300411 // Subscription contains REST subscription Id
Markku Virtanen42723e22021-06-15 10:09:23 +0300412 restSubId = p.SubscriptionID
413
Anssi Mannilaf682ace2021-09-28 13:11:25 +0300414 xapp.Logger.Debug("RestSubscription ID %s provided via REST request", restSubId)
Markku Virtanen42723e22021-06-15 10:09:23 +0300415 restSubscription, err = c.registry.GetRESTSubscription(restSubId, false)
416 if err != nil {
Anssi Mannilaf682ace2021-09-28 13:11:25 +0300417 // Subscription with id in REST request does not exist
Markku Virtanen42723e22021-06-15 10:09:23 +0300418 xapp.Logger.Error("%s", err.Error())
419 c.UpdateCounter(cRestSubFailToXapp)
Anssi Mannilacb7dd492021-10-01 11:10:26 +0300420 return nil, "", err
Markku Virtanen42723e22021-06-15 10:09:23 +0300421 }
422
423 if !exists {
Anssi Mannilaf682ace2021-09-28 13:11:25 +0300424 xapp.Logger.Debug("Existing restSubscription found for ID %s, new request based on md5sum", restSubId)
Markku Virtanen42723e22021-06-15 10:09:23 +0300425 } else {
Anssi Mannilaf682ace2021-09-28 13:11:25 +0300426 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 +0300427 }
428 }
429
Anssi Mannilacb7dd492021-10-01 11:10:26 +0300430 return restSubscription, restSubId, nil
Markku Virtanen42723e22021-06-15 10:09:23 +0300431}
432
433//-------------------------------------------------------------------
434//
435//-------------------------------------------------------------------
Anssi Mannilaf682ace2021-09-28 13:11:25 +0300436func (c *Control) RESTSubscriptionHandler(params interface{}) (*models.SubscriptionResponse, int) {
archaggeafbf95f2021-04-14 08:54:05 +0300437
Anssi Mannila316d8a12021-06-02 11:08:54 +0300438 c.CntRecvMsg++
439 c.UpdateCounter(cRestSubReqFromXapp)
440
archaggeafbf95f2021-04-14 08:54:05 +0300441 subResp := models.SubscriptionResponse{}
archaggeafbf95f2021-04-14 08:54:05 +0300442 p := params.(*models.SubscriptionParams)
443
Anssi Mannilade457a12021-06-02 16:19:48 +0300444 if c.LoggerLevel > 2 {
445 c.PrintRESTSubscriptionRequest(p)
446 }
447
Anssi Mannilac7da4ee2021-10-22 09:52:02 +0300448 if c.e2IfState.IsE2ConnectionUp(p.Meid) == false {
449 xapp.Logger.Error("No E2 connection for ranName %v", *p.Meid)
450 c.UpdateCounter(cRestReqRejDueE2Down)
451 return nil, common.SubscribeServiceUnavailableCode
452 }
453
archaggeafbf95f2021-04-14 08:54:05 +0300454 if p.ClientEndpoint == nil {
Anssi Mannilaf682ace2021-09-28 13:11:25 +0300455 err := fmt.Errorf("ClientEndpoint == nil")
456 xapp.Logger.Error("%v", err)
Anssi Mannila316d8a12021-06-02 11:08:54 +0300457 c.UpdateCounter(cRestSubFailToXapp)
Anssi Mannilacb7dd492021-10-01 11:10:26 +0300458 return nil, common.SubscribeBadRequestCode
archaggeafbf95f2021-04-14 08:54:05 +0300459 }
460
Anssi Mannila6bd57912022-06-16 09:47:23 +0300461 e2SubscriptionDirectives, err := c.GetE2SubscriptionDirectives(p)
462 if err != nil {
463 xapp.Logger.Error("%s", err)
464 c.UpdateCounter(cRestSubFailToXapp)
465 return nil, common.SubscribeBadRequestCode
466 }
archaggeafbf95f2021-04-14 08:54:05 +0300467 _, xAppRmrEndpoint, err := ConstructEndpointAddresses(*p.ClientEndpoint)
468 if err != nil {
469 xapp.Logger.Error("%s", err.Error())
Anssi Mannila316d8a12021-06-02 11:08:54 +0300470 c.UpdateCounter(cRestSubFailToXapp)
Anssi Mannilacb7dd492021-10-01 11:10:26 +0300471 return nil, common.SubscribeBadRequestCode
archaggeafbf95f2021-04-14 08:54:05 +0300472 }
473
Markku Virtanen42723e22021-06-15 10:09:23 +0300474 md5sum, err := CalculateRequestMd5sum(params)
475 if err != nil {
476 xapp.Logger.Error("Failed to generate md5sum from incoming request - %s", err.Error())
477 }
478
Anssi Mannila92c38552021-12-29 09:59:24 +0200479 restSubscription, restSubId, err := c.GetOrCreateRestSubscription(p, md5sum, xAppRmrEndpoint, p.ClientEndpoint.Host)
Markku Virtanen42723e22021-06-15 10:09:23 +0300480 if err != nil {
Anssi Mannilacb7dd492021-10-01 11:10:26 +0300481 xapp.Logger.Error("Subscription with id in REST request does not exist")
482 return nil, common.SubscribeNotFoundCode
archaggeafbf95f2021-04-14 08:54:05 +0300483 }
484
Konstantinos Archangelofe93b00f2021-06-03 10:00:19 +0000485 subResp.SubscriptionID = &restSubId
archaggeafbf95f2021-04-14 08:54:05 +0300486 subReqList := e2ap.SubscriptionRequestList{}
487 err = c.e2ap.FillSubscriptionReqMsgs(params, &subReqList, restSubscription)
488 if err != nil {
489 xapp.Logger.Error("%s", err.Error())
Anssi Mannila3cdd2e02021-10-14 12:35:41 +0300490 c.restDuplicateCtrl.DeleteLastKnownRestSubsIdBasedOnMd5sum(md5sum)
archaggeafbf95f2021-04-14 08:54:05 +0300491 c.registry.DeleteRESTSubscription(&restSubId)
Anssi Mannila316d8a12021-06-02 11:08:54 +0300492 c.UpdateCounter(cRestSubFailToXapp)
Anssi Mannilacb7dd492021-10-01 11:10:26 +0300493 return nil, common.SubscribeBadRequestCode
archaggeafbf95f2021-04-14 08:54:05 +0300494 }
495
Anssi Mannila3cdd2e02021-10-14 12:35:41 +0300496 duplicate := c.restDuplicateCtrl.IsDuplicateToOngoingTransaction(restSubId, md5sum)
Markku Virtanen42723e22021-06-15 10:09:23 +0300497 if duplicate {
Anssi Mannilaf682ace2021-09-28 13:11:25 +0300498 err := fmt.Errorf("Retransmission blocker direct ACK for request of restSubsId %s restSubId MD5sum %s as retransmission", restSubId, md5sum)
499 xapp.Logger.Debug("%s", err)
Anssi Mannilab43397e2021-11-16 12:06:16 +0200500 c.registry.DeleteRESTSubscription(&restSubId)
Markku Virtanen42723e22021-06-15 10:09:23 +0300501 c.UpdateCounter(cRestSubRespToXapp)
Anssi Mannilaf682ace2021-09-28 13:11:25 +0300502 return &subResp, common.SubscribeCreatedCode
Markku Virtanenb642a192021-06-09 09:08:14 +0000503 }
504
Markku Virtanencd73ecc2021-06-23 06:16:01 +0000505 c.WriteRESTSubscriptionToDb(restSubId, restSubscription)
Anssi Mannilaf682ace2021-09-28 13:11:25 +0300506 go c.processSubscriptionRequests(restSubscription, &subReqList, p.ClientEndpoint, p.Meid, &restSubId, xAppRmrEndpoint, md5sum, e2SubscriptionDirectives)
archaggeafbf95f2021-04-14 08:54:05 +0300507
Anssi Mannila316d8a12021-06-02 11:08:54 +0300508 c.UpdateCounter(cRestSubRespToXapp)
Anssi Mannilaf682ace2021-09-28 13:11:25 +0300509 return &subResp, common.SubscribeCreatedCode
510}
511
512//-------------------------------------------------------------------
513//
514//-------------------------------------------------------------------
515func (c *Control) GetE2SubscriptionDirectives(p *models.SubscriptionParams) (*E2SubscriptionDirectives, error) {
516
517 e2SubscriptionDirectives := &E2SubscriptionDirectives{}
518 if p == nil || p.E2SubscriptionDirectives == nil {
519 e2SubscriptionDirectives.E2TimeoutTimerValue = e2tSubReqTimeout
520 e2SubscriptionDirectives.E2MaxTryCount = int64(e2tMaxSubReqTryCount)
521 e2SubscriptionDirectives.CreateRMRRoute = true
522 xapp.Logger.Debug("p == nil || p.E2SubscriptionDirectives == nil. Using default values for E2TimeoutTimerValue = %v and E2RetryCount = %v RMRRoutingNeeded = true", e2tSubReqTimeout, e2tMaxSubReqTryCount)
523 } else {
524 if p.E2SubscriptionDirectives.E2TimeoutTimerValue >= 1 && p.E2SubscriptionDirectives.E2TimeoutTimerValue <= 10 {
525 e2SubscriptionDirectives.E2TimeoutTimerValue = time.Duration(p.E2SubscriptionDirectives.E2TimeoutTimerValue) * 1000000000 // Duration type cast returns nano seconds
526 } else {
527 return nil, fmt.Errorf("p.E2SubscriptionDirectives.E2TimeoutTimerValue out of range (1-10 seconds): %v", p.E2SubscriptionDirectives.E2TimeoutTimerValue)
528 }
529 if p.E2SubscriptionDirectives.E2RetryCount == nil {
530 xapp.Logger.Error("p.E2SubscriptionDirectives.E2RetryCount == nil. Using default value")
531 e2SubscriptionDirectives.E2MaxTryCount = int64(e2tMaxSubReqTryCount)
532 } else {
533 if *p.E2SubscriptionDirectives.E2RetryCount >= 0 && *p.E2SubscriptionDirectives.E2RetryCount <= 10 {
534 e2SubscriptionDirectives.E2MaxTryCount = *p.E2SubscriptionDirectives.E2RetryCount + 1 // E2MaxTryCount = First sending plus two retries
535 } else {
536 return nil, fmt.Errorf("p.E2SubscriptionDirectives.E2RetryCount out of range (0-10): %v", *p.E2SubscriptionDirectives.E2RetryCount)
537 }
538 }
Anssi Mannilacb7dd492021-10-01 11:10:26 +0300539 e2SubscriptionDirectives.CreateRMRRoute = p.E2SubscriptionDirectives.RMRRoutingNeeded
Anssi Mannilaf682ace2021-09-28 13:11:25 +0300540 }
541 xapp.Logger.Debug("e2SubscriptionDirectives.E2TimeoutTimerValue: %v", e2SubscriptionDirectives.E2TimeoutTimerValue)
542 xapp.Logger.Debug("e2SubscriptionDirectives.E2MaxTryCount: %v", e2SubscriptionDirectives.E2MaxTryCount)
543 xapp.Logger.Debug("e2SubscriptionDirectives.CreateRMRRoute: %v", e2SubscriptionDirectives.CreateRMRRoute)
544 return e2SubscriptionDirectives, nil
545}
546
547//-------------------------------------------------------------------
548//
549//-------------------------------------------------------------------
archaggeafbf95f2021-04-14 08:54:05 +0300550
551func (c *Control) processSubscriptionRequests(restSubscription *RESTSubscription, subReqList *e2ap.SubscriptionRequestList,
Anssi Mannilaf682ace2021-09-28 13:11:25 +0300552 clientEndpoint *models.SubscriptionParamsClientEndpoint, meid *string, restSubId *string, xAppRmrEndpoint string, md5sum string, e2SubscriptionDirectives *E2SubscriptionDirectives) {
archaggeafbf95f2021-04-14 08:54:05 +0300553
Anssi Mannila08c8fbd2021-10-05 12:47:41 +0300554 c.SubscriptionProcessingStartDelay()
Anssi Mannila54838ed2021-11-19 11:25:01 +0200555 xapp.Logger.Debug("E2 SubscriptionRequest count = %v ", len(subReqList.E2APSubscriptionRequests))
archaggeafbf95f2021-04-14 08:54:05 +0300556
Konstantinos Archangelofe93b00f2021-06-03 10:00:19 +0000557 var xAppEventInstanceID int64
558 var e2EventInstanceID int64
Anssi Mannilaf682ace2021-09-28 13:11:25 +0300559 errorInfo := &ErrorInfo{}
Markku Virtanenb642a192021-06-09 09:08:14 +0000560
Anssi Mannila3cdd2e02021-10-14 12:35:41 +0300561 defer c.restDuplicateCtrl.SetMd5sumFromLastOkRequest(*restSubId, md5sum)
Markku Virtanenb642a192021-06-09 09:08:14 +0000562
archaggeafbf95f2021-04-14 08:54:05 +0300563 for index := 0; index < len(subReqList.E2APSubscriptionRequests); index++ {
564 subReqMsg := subReqList.E2APSubscriptionRequests[index]
Markku Virtanenb642a192021-06-09 09:08:14 +0000565 xAppEventInstanceID = (int64)(subReqMsg.RequestId.Id)
archaggeafbf95f2021-04-14 08:54:05 +0300566
Konstantinos Archangelofe93b00f2021-06-03 10:00:19 +0000567 trans := c.tracker.NewXappTransaction(xapp.NewRmrEndpoint(xAppRmrEndpoint), *restSubId, subReqMsg.RequestId, &xapp.RMRMeid{RanName: *meid})
archaggeafbf95f2021-04-14 08:54:05 +0300568 if trans == nil {
Markku Virtanenb642a192021-06-09 09:08:14 +0000569 // Send notification to xApp that prosessing of a Subscription Request has failed.
570 err := fmt.Errorf("Tracking failure")
Anssi Mannilaf682ace2021-09-28 13:11:25 +0300571 errorInfo.ErrorCause = err.Error()
572 c.sendUnsuccesfullResponseNotification(restSubId, restSubscription, xAppEventInstanceID, err, clientEndpoint, trans, errorInfo)
Markku Virtanenb642a192021-06-09 09:08:14 +0000573 continue
archaggeafbf95f2021-04-14 08:54:05 +0300574 }
575
Anssi Mannilaf682ace2021-09-28 13:11:25 +0300576 xapp.Logger.Debug("Handle SubscriptionRequest index=%v, %s", index, idstring(nil, trans))
Markku Virtanenb642a192021-06-09 09:08:14 +0000577
Anssi Mannilaf682ace2021-09-28 13:11:25 +0300578 subRespMsg, errorInfo, err := c.handleSubscriptionRequest(trans, &subReqMsg, meid, *restSubId, e2SubscriptionDirectives)
Markku Virtanen42723e22021-06-15 10:09:23 +0300579
Anssi Mannilaf682ace2021-09-28 13:11:25 +0300580 xapp.Logger.Debug("Handled SubscriptionRequest index=%v, %s", index, idstring(nil, trans))
Anssi Mannila53dbe7e2021-10-06 14:21:48 +0300581 trans.Release()
Markku Virtanen42723e22021-06-15 10:09:23 +0300582
archaggeafbf95f2021-04-14 08:54:05 +0300583 if err != nil {
Anssi Mannila54838ed2021-11-19 11:25:01 +0200584 if err.Error() == "TEST: restart event received" {
585 // This is just for UT cases. Stop here subscription processing
586 return
587 }
Anssi Mannilaf682ace2021-09-28 13:11:25 +0300588 c.sendUnsuccesfullResponseNotification(restSubId, restSubscription, xAppEventInstanceID, err, clientEndpoint, trans, errorInfo)
archaggeafbf95f2021-04-14 08:54:05 +0300589 } else {
Konstantinos Archangelofe93b00f2021-06-03 10:00:19 +0000590 e2EventInstanceID = (int64)(subRespMsg.RequestId.InstanceId)
Markku Virtanen42723e22021-06-15 10:09:23 +0300591 restSubscription.AddMd5Sum(md5sum)
Anssi Mannilaf682ace2021-09-28 13:11:25 +0300592 xapp.Logger.Debug("SubscriptionRequest index=%v processed successfullyfor %s. endpoint=%v:%v, XappEventInstanceID=%v, E2EventInstanceID=%v, %s",
Markku Virtanen42723e22021-06-15 10:09:23 +0300593 index, *restSubId, clientEndpoint.Host, *clientEndpoint.HTTPPort, xAppEventInstanceID, e2EventInstanceID, idstring(nil, trans))
Anssi Mannila56233b02022-01-24 13:26:42 +0200594 c.sendSuccesfullResponseNotification(restSubId, restSubscription, xAppEventInstanceID, e2EventInstanceID, clientEndpoint, trans, errorInfo)
archaggeafbf95f2021-04-14 08:54:05 +0300595 }
archaggeafbf95f2021-04-14 08:54:05 +0300596 }
597}
598
599//-------------------------------------------------------------------
600//
601//------------------------------------------------------------------
Anssi Mannila08c8fbd2021-10-05 12:47:41 +0300602func (c *Control) SubscriptionProcessingStartDelay() {
603 if c.UTTesting == true {
604 // This is temporary fix for the UT problem that notification arrives before subscription response
605 // Correct fix would be to allow notification come before response and process it correctly
606 xapp.Logger.Debug("Setting 50 ms delay before starting processing Subscriptions")
607 <-time.After(time.Millisecond * 50)
608 xapp.Logger.Debug("Continuing after delay")
609 }
610}
611
612//-------------------------------------------------------------------
613//
614//------------------------------------------------------------------
archaggeafbf95f2021-04-14 08:54:05 +0300615func (c *Control) handleSubscriptionRequest(trans *TransactionXapp, subReqMsg *e2ap.E2APSubscriptionRequest, meid *string,
Anssi Mannilaf682ace2021-09-28 13:11:25 +0300616 restSubId string, e2SubscriptionDirectives *E2SubscriptionDirectives) (*e2ap.E2APSubscriptionResponse, *ErrorInfo, error) {
617
618 errorInfo := ErrorInfo{}
archaggeafbf95f2021-04-14 08:54:05 +0300619
620 err := c.tracker.Track(trans)
621 if err != nil {
Markku Virtanen55d2a282021-06-04 14:46:56 +0300622 xapp.Logger.Error("XAPP-SubReq Tracking error: %s", idstring(err, trans))
Anssi Mannilaf682ace2021-09-28 13:11:25 +0300623 errorInfo.ErrorCause = err.Error()
Markku Virtanen55d2a282021-06-04 14:46:56 +0300624 err = fmt.Errorf("Tracking failure")
Anssi Mannilaf682ace2021-09-28 13:11:25 +0300625 return nil, &errorInfo, err
archaggeafbf95f2021-04-14 08:54:05 +0300626 }
627
Anssi Mannilaf682ace2021-09-28 13:11:25 +0300628 subs, errorInfo, err := c.registry.AssignToSubscription(trans, subReqMsg, c.ResetTestFlag, c, e2SubscriptionDirectives.CreateRMRRoute)
archaggeafbf95f2021-04-14 08:54:05 +0300629 if err != nil {
Markku Virtanen55d2a282021-06-04 14:46:56 +0300630 xapp.Logger.Error("XAPP-SubReq Assign error: %s", idstring(err, trans))
Anssi Mannilaf682ace2021-09-28 13:11:25 +0300631 return nil, &errorInfo, err
archaggeafbf95f2021-04-14 08:54:05 +0300632 }
633
634 //
635 // Wake subs request
636 //
Anssi Mannilac7da4ee2021-10-22 09:52:02 +0300637 subs.OngoingReqCount++
Anssi Mannila54838ed2021-11-19 11:25:01 +0200638 go c.handleSubscriptionCreate(subs, trans, e2SubscriptionDirectives, 0)
archaggeafbf95f2021-04-14 08:54:05 +0300639 event, _ := trans.WaitEvent(0) //blocked wait as timeout is handled in subs side
Anssi Mannilac7da4ee2021-10-22 09:52:02 +0300640 subs.OngoingReqCount--
archaggeafbf95f2021-04-14 08:54:05 +0300641
642 err = nil
643 if event != nil {
644 switch themsg := event.(type) {
645 case *e2ap.E2APSubscriptionResponse:
646 trans.Release()
Anssi Mannilac7da4ee2021-10-22 09:52:02 +0300647 if c.e2IfState.IsE2ConnectionUp(meid) == true {
Anssi Mannila56233b02022-01-24 13:26:42 +0200648 errorInfo = c.e2ap.CheckActionNotAdmittedList(xapp.RIC_SUB_RESP, themsg.ActionNotAdmittedList, c)
Anssi Mannilac7da4ee2021-10-22 09:52:02 +0300649 return themsg, &errorInfo, nil
650 } else {
651 c.registry.RemoveFromSubscription(subs, trans, waitRouteCleanup_ms, c)
652 c.RemoveSubscriptionFromDb(subs)
653 err = fmt.Errorf("E2 interface down")
654 errorInfo.SetInfo(err.Error(), models.SubscriptionInstanceErrorSourceE2Node, "")
Anssi Mannilac7da4ee2021-10-22 09:52:02 +0300655 }
archaggeafbf95f2021-04-14 08:54:05 +0300656 case *e2ap.E2APSubscriptionFailure:
Anssi Mannila483bd162022-01-20 11:11:48 +0200657 err = fmt.Errorf("RICSubscriptionFailure. E2NodeCause: (Cause:%v, Value %v)", themsg.Cause.Content, themsg.Cause.Value)
658 errorInfo.SetInfo(err.Error(), models.SubscriptionInstanceErrorSourceE2Node, "")
Anssi Mannilaf682ace2021-09-28 13:11:25 +0300659 case *PackSubscriptionRequestErrortEvent:
Anssi Mannila56233b02022-01-24 13:26:42 +0200660 err = fmt.Errorf("E2 RICSubscriptionRequest pack failure")
Anssi Mannilab43397e2021-11-16 12:06:16 +0200661 errorInfo = themsg.ErrorInfo
Anssi Mannilaf682ace2021-09-28 13:11:25 +0300662 case *SDLWriteErrortEvent:
663 err = fmt.Errorf("SDL write failure")
Anssi Mannilab43397e2021-11-16 12:06:16 +0200664 errorInfo = themsg.ErrorInfo
Anssi Mannila54838ed2021-11-19 11:25:01 +0200665 case *SubmgrRestartTestEvent:
666 err = fmt.Errorf("TEST: restart event received")
667 xapp.Logger.Debug("%s", err)
668 return nil, &errorInfo, err
archaggeafbf95f2021-04-14 08:54:05 +0300669 default:
Anssi Mannilaf682ace2021-09-28 13:11:25 +0300670 err = fmt.Errorf("Unexpected E2 subscription response received")
671 errorInfo.SetInfo(err.Error(), models.SubscriptionInstanceErrorSourceE2Node, "")
archaggeafbf95f2021-04-14 08:54:05 +0300672 break
673 }
Markku Virtanen55d2a282021-06-04 14:46:56 +0300674 } else {
Anssi Mannila3d80b722021-11-12 13:17:15 +0200675 // Timer expiry
Anssi Mannila56233b02022-01-24 13:26:42 +0200676 err = fmt.Errorf("E2 RICSubscriptionResponse timeout")
Anssi Mannilaf682ace2021-09-28 13:11:25 +0300677 errorInfo.SetInfo(err.Error(), "", models.SubscriptionInstanceTimeoutTypeE2Timeout)
678 if subs.PolicyUpdate == true {
679 return nil, &errorInfo, err
680 }
archaggeafbf95f2021-04-14 08:54:05 +0300681 }
Markku Virtanen55d2a282021-06-04 14:46:56 +0300682
Anssi Mannila9c4697f2022-07-04 15:51:38 +0300683 xapp.Logger.Error("XAPP-SubReq E2 subscription failed: %s", idstring(err, trans, subs))
684 err2 := c.registry.RemoveFromSubscription(subs, trans, waitRouteCleanup_ms, c)
685 if err2 != nil {
686 xapp.Logger.Error("RemoveFromSubscription failed: %s", err2.Error())
687 }
Anssi Mannilaf682ace2021-09-28 13:11:25 +0300688 return nil, &errorInfo, err
archaggeafbf95f2021-04-14 08:54:05 +0300689}
690
691//-------------------------------------------------------------------
692//
693//-------------------------------------------------------------------
Markku Virtanen42723e22021-06-15 10:09:23 +0300694func (c *Control) sendUnsuccesfullResponseNotification(restSubId *string, restSubscription *RESTSubscription, xAppEventInstanceID int64, err error,
Anssi Mannilaf682ace2021-09-28 13:11:25 +0300695 clientEndpoint *models.SubscriptionParamsClientEndpoint, trans *TransactionXapp, errorInfo *ErrorInfo) {
Markku Virtanen42723e22021-06-15 10:09:23 +0300696
697 // Send notification to xApp that prosessing of a Subscription Request has failed.
698 e2EventInstanceID := (int64)(0)
Anssi Mannilaf682ace2021-09-28 13:11:25 +0300699 if errorInfo.ErrorSource == "" {
700 // Submgr is default source of error
701 errorInfo.ErrorSource = models.SubscriptionInstanceErrorSourceSUBMGR
702 }
Markku Virtanen42723e22021-06-15 10:09:23 +0300703 resp := &models.SubscriptionResponse{
704 SubscriptionID: restSubId,
705 SubscriptionInstances: []*models.SubscriptionInstance{
706 &models.SubscriptionInstance{E2EventInstanceID: &e2EventInstanceID,
Anssi Mannilacb7dd492021-10-01 11:10:26 +0300707 ErrorCause: errorInfo.ErrorCause,
708 ErrorSource: errorInfo.ErrorSource,
709 TimeoutType: errorInfo.TimeoutType,
Markku Virtanen42723e22021-06-15 10:09:23 +0300710 XappEventInstanceID: &xAppEventInstanceID},
711 },
712 }
713 // Mark REST subscription request processed.
714 restSubscription.SetProcessed(err)
715 c.UpdateRESTSubscriptionInDB(*restSubId, restSubscription, false)
716 if trans != nil {
Anssi Mannila6bd57912022-06-16 09:47:23 +0300717 xapp.Logger.Debug("Sending unsuccessful REST notification: ErrorCause:%s, ErrorSource:%s, TimeoutType:%s, to Endpoint=%v:%v, XappEventInstanceID=%v, E2EventInstanceID=%v, %s",
718 errorInfo.ErrorCause, errorInfo.ErrorSource, errorInfo.TimeoutType, clientEndpoint.Host, *clientEndpoint.HTTPPort, xAppEventInstanceID, e2EventInstanceID, idstring(nil, trans))
Markku Virtanen42723e22021-06-15 10:09:23 +0300719 } else {
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",
721 errorInfo.ErrorCause, errorInfo.ErrorSource, errorInfo.TimeoutType, clientEndpoint.Host, *clientEndpoint.HTTPPort, xAppEventInstanceID, e2EventInstanceID)
Markku Virtanen42723e22021-06-15 10:09:23 +0300722 }
723
724 c.UpdateCounter(cRestSubFailNotifToXapp)
Anssi Mannila9c4697f2022-07-04 15:51:38 +0300725 err = xapp.Subscription.Notify(resp, *clientEndpoint)
726 if err != nil {
727 xapp.Logger.Error("xapp.Subscription.Notify failed %s", err.Error())
728 }
Anssi Mannilac7da4ee2021-10-22 09:52:02 +0300729
Anssi Mannilab43397e2021-11-16 12:06:16 +0200730 // E2 is down. Delete completely processed request safely now
Anssi Mannilac7da4ee2021-10-22 09:52:02 +0300731 if c.e2IfState.IsE2ConnectionUp(&restSubscription.Meid) == false && restSubscription.SubReqOngoing == false {
732 c.registry.DeleteRESTSubscription(restSubId)
733 c.RemoveRESTSubscriptionFromDb(*restSubId)
734 }
Markku Virtanen42723e22021-06-15 10:09:23 +0300735}
736
737//-------------------------------------------------------------------
738//
739//-------------------------------------------------------------------
740func (c *Control) sendSuccesfullResponseNotification(restSubId *string, restSubscription *RESTSubscription, xAppEventInstanceID int64, e2EventInstanceID int64,
Anssi Mannila56233b02022-01-24 13:26:42 +0200741 clientEndpoint *models.SubscriptionParamsClientEndpoint, trans *TransactionXapp, errorInfo *ErrorInfo) {
Markku Virtanen42723e22021-06-15 10:09:23 +0300742
743 // Store successfully processed InstanceId for deletion
744 restSubscription.AddE2InstanceId((uint32)(e2EventInstanceID))
745 restSubscription.AddXappIdToE2Id(xAppEventInstanceID, e2EventInstanceID)
746
747 // Send notification to xApp that a Subscription Request has been processed.
748 resp := &models.SubscriptionResponse{
749 SubscriptionID: restSubId,
750 SubscriptionInstances: []*models.SubscriptionInstance{
751 &models.SubscriptionInstance{E2EventInstanceID: &e2EventInstanceID,
Anssi Mannila56233b02022-01-24 13:26:42 +0200752 ErrorCause: errorInfo.ErrorCause,
753 ErrorSource: errorInfo.ErrorSource,
Markku Virtanen42723e22021-06-15 10:09:23 +0300754 XappEventInstanceID: &xAppEventInstanceID},
755 },
756 }
757 // Mark REST subscription request processesd.
758 restSubscription.SetProcessed(nil)
759 c.UpdateRESTSubscriptionInDB(*restSubId, restSubscription, false)
Anssi Mannila6bd57912022-06-16 09:47:23 +0300760 xapp.Logger.Debug("Sending successful REST notification: ErrorCause:%s, ErrorSource:%s, TimeoutType:%s, to Endpoint=%v:%v, XappEventInstanceID=%v, E2EventInstanceID=%v, %s",
761 errorInfo.ErrorCause, errorInfo.ErrorSource, errorInfo.TimeoutType, clientEndpoint.Host, *clientEndpoint.HTTPPort, xAppEventInstanceID, e2EventInstanceID, idstring(nil, trans))
Markku Virtanen42723e22021-06-15 10:09:23 +0300762 c.UpdateCounter(cRestSubNotifToXapp)
Anssi Mannila9c4697f2022-07-04 15:51:38 +0300763 err := xapp.Subscription.Notify(resp, *clientEndpoint)
764 if err != nil {
765 xapp.Logger.Error("xapp.Subscription.Notify failed %s", err.Error())
766 }
Anssi Mannilac7da4ee2021-10-22 09:52:02 +0300767
Anssi Mannilab43397e2021-11-16 12:06:16 +0200768 // E2 is down. Delete completely processed request safely now
Anssi Mannilac7da4ee2021-10-22 09:52:02 +0300769 if c.e2IfState.IsE2ConnectionUp(&restSubscription.Meid) == false && restSubscription.SubReqOngoing == false {
770 c.registry.DeleteRESTSubscription(restSubId)
771 c.RemoveRESTSubscriptionFromDb(*restSubId)
772 }
Markku Virtanen42723e22021-06-15 10:09:23 +0300773}
774
775//-------------------------------------------------------------------
776//
777//-------------------------------------------------------------------
Anssi Mannilaf682ace2021-09-28 13:11:25 +0300778func (c *Control) RESTSubscriptionDeleteHandler(restSubId string) int {
archaggeafbf95f2021-04-14 08:54:05 +0300779
780 c.CntRecvMsg++
Konstantinos Archangelof27433e72021-05-31 08:30:35 +0000781 c.UpdateCounter(cRestSubDelReqFromXapp)
archaggeafbf95f2021-04-14 08:54:05 +0300782
Anssi Mannilaf682ace2021-09-28 13:11:25 +0300783 xapp.Logger.Debug("SubscriptionDeleteRequest from XAPP")
archaggeafbf95f2021-04-14 08:54:05 +0300784
Konstantinos Archangelofe93b00f2021-06-03 10:00:19 +0000785 restSubscription, err := c.registry.GetRESTSubscription(restSubId, true)
archaggeafbf95f2021-04-14 08:54:05 +0300786 if err != nil {
787 xapp.Logger.Error("%s", err.Error())
788 if restSubscription == nil {
789 // Subscription was not found
Anssi Mannilac7da4ee2021-10-22 09:52:02 +0300790 c.UpdateCounter(cRestSubDelRespToXapp)
Anssi Mannilaf682ace2021-09-28 13:11:25 +0300791 return common.UnsubscribeNoContentCode
archaggeafbf95f2021-04-14 08:54:05 +0300792 } else {
793 if restSubscription.SubReqOngoing == true {
794 err := fmt.Errorf("Handling of the REST Subscription Request still ongoing %s", restSubId)
795 xapp.Logger.Error("%s", err.Error())
Anssi Mannilac7da4ee2021-10-22 09:52:02 +0300796 c.UpdateCounter(cRestSubDelFailToXapp)
Anssi Mannilaf682ace2021-09-28 13:11:25 +0300797 return common.UnsubscribeBadRequestCode
archaggeafbf95f2021-04-14 08:54:05 +0300798 } else if restSubscription.SubDelReqOngoing == true {
799 // Previous request for same restSubId still ongoing
Anssi Mannila3d80b722021-11-12 13:17:15 +0200800 c.UpdateCounter(cRestSubDelRespToXapp)
801 return common.UnsubscribeNoContentCode
archaggeafbf95f2021-04-14 08:54:05 +0300802 }
803 }
804 }
805
806 xAppRmrEndPoint := restSubscription.xAppRmrEndPoint
807 go func() {
Anssi Mannilaf682ace2021-09-28 13:11:25 +0300808 xapp.Logger.Debug("Deleteting handler: processing instances = %v", restSubscription.InstanceIds)
archaggeafbf95f2021-04-14 08:54:05 +0300809 for _, instanceId := range restSubscription.InstanceIds {
Anssi Mannila54838ed2021-11-19 11:25:01 +0200810 xAppEventInstanceID, err := c.SubscriptionDeleteHandler(&restSubId, &xAppRmrEndPoint, &restSubscription.Meid, instanceId, 0)
Konstantinos Archangelofe93b00f2021-06-03 10:00:19 +0000811
archaggeafbf95f2021-04-14 08:54:05 +0300812 if err != nil {
813 xapp.Logger.Error("%s", err.Error())
archaggeafbf95f2021-04-14 08:54:05 +0300814 }
Anssi Mannilaf682ace2021-09-28 13:11:25 +0300815 xapp.Logger.Debug("Deleteting instanceId = %v", instanceId)
Konstantinos Archangelofe93b00f2021-06-03 10:00:19 +0000816 restSubscription.DeleteXappIdToE2Id(xAppEventInstanceID)
817 restSubscription.DeleteE2InstanceId(instanceId)
archaggeafbf95f2021-04-14 08:54:05 +0300818 }
Anssi Mannila3cdd2e02021-10-14 12:35:41 +0300819 c.restDuplicateCtrl.DeleteLastKnownRestSubsIdBasedOnMd5sum(restSubscription.lastReqMd5sum)
archaggeafbf95f2021-04-14 08:54:05 +0300820 c.registry.DeleteRESTSubscription(&restSubId)
Konstantinos Archangelof268d7152021-06-14 12:24:00 +0300821 c.RemoveRESTSubscriptionFromDb(restSubId)
archaggeafbf95f2021-04-14 08:54:05 +0300822 }()
823
Konstantinos Archangelof27433e72021-05-31 08:30:35 +0000824 c.UpdateCounter(cRestSubDelRespToXapp)
Anssi Mannilaf682ace2021-09-28 13:11:25 +0300825 return common.UnsubscribeNoContentCode
Juha Hyttinenc9eb08a2020-02-28 08:53:33 +0200826}
827
archaggeafbf95f2021-04-14 08:54:05 +0300828//-------------------------------------------------------------------
829//
830//-------------------------------------------------------------------
Anssi Mannila54838ed2021-11-19 11:25:01 +0200831func (c *Control) SubscriptionDeleteHandler(restSubId *string, endPoint *string, meid *string, instanceId uint32, waitRouteCleanupTime time.Duration) (int64, error) {
archaggeafbf95f2021-04-14 08:54:05 +0300832
Konstantinos Archangelofe93b00f2021-06-03 10:00:19 +0000833 var xAppEventInstanceID int64
834 subs, err := c.registry.GetSubscriptionFirstMatch([]uint32{instanceId})
835 if err != nil {
Anssi Mannilaf682ace2021-09-28 13:11:25 +0300836 xapp.Logger.Debug("Subscription Delete Handler subscription for restSubId=%v, E2EventInstanceID=%v not found %s",
Konstantinos Archangelofe93b00f2021-06-03 10:00:19 +0000837 restSubId, instanceId, idstring(err, nil))
838 return xAppEventInstanceID, nil
839 }
840
841 xAppEventInstanceID = int64(subs.ReqId.Id)
842 trans := c.tracker.NewXappTransaction(xapp.NewRmrEndpoint(*endPoint), *restSubId, e2ap.RequestId{subs.ReqId.Id, 0}, &xapp.RMRMeid{RanName: *meid})
archaggeafbf95f2021-04-14 08:54:05 +0300843 if trans == nil {
844 err := fmt.Errorf("XAPP-SubDelReq transaction not created. restSubId %s, endPoint %s, meid %s, instanceId %v", *restSubId, *endPoint, *meid, instanceId)
845 xapp.Logger.Error("%s", err.Error())
846 }
847 defer trans.Release()
848
Konstantinos Archangelofe93b00f2021-06-03 10:00:19 +0000849 err = c.tracker.Track(trans)
archaggeafbf95f2021-04-14 08:54:05 +0300850 if err != nil {
851 err := fmt.Errorf("XAPP-SubDelReq %s:", idstring(err, trans))
852 xapp.Logger.Error("%s", err.Error())
Konstantinos Archangelofe93b00f2021-06-03 10:00:19 +0000853 return xAppEventInstanceID, &time.ParseError{}
archaggeafbf95f2021-04-14 08:54:05 +0300854 }
855 //
856 // Wake subs delete
857 //
Anssi Mannilac7da4ee2021-10-22 09:52:02 +0300858 subs.OngoingDelCount++
Anssi Mannila54838ed2021-11-19 11:25:01 +0200859 go c.handleSubscriptionDelete(subs, trans, waitRouteCleanupTime)
archaggeafbf95f2021-04-14 08:54:05 +0300860 trans.WaitEvent(0) //blocked wait as timeout is handled in subs side
Anssi Mannilac7da4ee2021-10-22 09:52:02 +0300861 subs.OngoingDelCount--
archaggeafbf95f2021-04-14 08:54:05 +0300862
863 xapp.Logger.Debug("XAPP-SubDelReq: Handling event %s ", idstring(nil, trans, subs))
864
Anssi Mannila9c4697f2022-07-04 15:51:38 +0300865 err = c.registry.RemoveFromSubscription(subs, trans, waitRouteCleanup_ms, c)
866 if err != nil {
867 xapp.Logger.Error("XAPP-SubDelReq %s:", idstring(fmt.Errorf("RemoveFromSubscription faliled"), trans, subs))
868 }
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 Mannilaf682ace2021-09-28 13:11:25 +0300997 e2SubscriptionDirectives, _ := c.GetE2SubscriptionDirectives(nil)
Anssi Mannilac7da4ee2021-10-22 09:52:02 +0300998 subs.OngoingReqCount++
Anssi Mannila54838ed2021-11-19 11:25:01 +0200999 go c.handleSubscriptionCreate(subs, trans, e2SubscriptionDirectives, waitRouteCleanup_ms)
Juha Hyttinen422d0182020-01-17 13:37:05 +02001000 event, _ := trans.WaitEvent(0) //blocked wait as timeout is handled in subs side
Anssi Mannilac7da4ee2021-10-22 09:52:02 +03001001 subs.OngoingReqCount--
Anssi Mannila6b3796f2021-02-12 09:11:35 +02001002 var err error
Juha Hyttinen422d0182020-01-17 13:37:05 +02001003 if event != nil {
1004 switch themsg := event.(type) {
1005 case *e2ap.E2APSubscriptionResponse:
Anssi Mannila4c626a22021-02-11 12:50:48 +02001006 themsg.RequestId.Id = trans.RequestId.Id
Juha Hyttinen422d0182020-01-17 13:37:05 +02001007 trans.Mtype, trans.Payload, err = c.e2ap.PackSubscriptionResponse(themsg)
1008 if err == nil {
Anssi Mannila64a0df42020-02-26 09:46:03 +02001009 trans.Release()
Anssi Mannila4abf1802021-01-28 13:06:46 +02001010 c.UpdateCounter(cSubRespToXapp)
Anssi Mannila9c4697f2022-07-04 15:51:38 +03001011 err := c.rmrSendToXapp("", subs, trans)
1012 if err != nil {
1013 xapp.Logger.Error("rmrSendToXapp() failed:%s", err.Error())
1014 }
Juha Hyttinen422d0182020-01-17 13:37:05 +02001015 return
1016 }
1017 case *e2ap.E2APSubscriptionFailure:
Anssi Mannila4c626a22021-02-11 12:50:48 +02001018 themsg.RequestId.Id = trans.RequestId.Id
Juha Hyttinen422d0182020-01-17 13:37:05 +02001019 trans.Mtype, trans.Payload, err = c.e2ap.PackSubscriptionFailure(themsg)
1020 if err == nil {
Anssi Mannila4abf1802021-01-28 13:06:46 +02001021 c.UpdateCounter(cSubFailToXapp)
Juha Hyttinen83ada002020-01-30 10:36:33 +02001022 c.rmrSendToXapp("", subs, trans)
Juha Hyttinen422d0182020-01-17 13:37:05 +02001023 }
Juha Hyttinen422d0182020-01-17 13:37:05 +02001024 default:
Juha Hyttinen31797b42020-01-16 14:05:01 +02001025 break
1026 }
1027 }
Anssi Mannilaf682ace2021-09-28 13:11:25 +03001028 xapp.Logger.Debug("XAPP-SubReq: failed %s", idstring(err, trans, subs))
Juha Hyttinen31797b42020-01-16 14:05:01 +02001029}
1030
Juha Hyttinen422d0182020-01-17 13:37:05 +02001031//-------------------------------------------------------------------
1032// handle from XAPP Subscription Delete Request
1033//------------------------------------------------------------------
Juha Hyttinen9dc5adc2020-08-13 10:02:40 +03001034func (c *Control) handleXAPPSubscriptionDeleteRequest(params *xapp.RMRParams) {
Anssi Mannilaf682ace2021-09-28 13:11:25 +03001035 xapp.Logger.Debug("MSG from XAPP: %s", params.String())
Anssi Mannila4abf1802021-01-28 13:06:46 +02001036 c.UpdateCounter(cSubDelReqFromXapp)
Juha Hyttinen422d0182020-01-17 13:37:05 +02001037
Anssi Mannilac7da4ee2021-10-22 09:52:02 +03001038 if c.e2IfState.IsE2ConnectionUp(&params.Meid.RanName) == false {
1039 xapp.Logger.Error("No E2 connection for ranName %v", params.Meid.RanName)
1040 return
1041 }
1042
Juha Hyttinen422d0182020-01-17 13:37:05 +02001043 subDelReqMsg, err := c.e2ap.UnpackSubscriptionDeleteRequest(params.Payload)
Juha Hyttinen31797b42020-01-16 14:05:01 +02001044 if err != nil {
Juha Hyttinen83ada002020-01-30 10:36:33 +02001045 xapp.Logger.Error("XAPP-SubDelReq %s", idstring(err, params))
Juha Hyttinen422d0182020-01-17 13:37:05 +02001046 return
1047 }
1048
Anssi Mannila4c626a22021-02-11 12:50:48 +02001049 trans := c.tracker.NewXappTransaction(xapp.NewRmrEndpoint(params.Src), params.Xid, subDelReqMsg.RequestId, params.Meid)
Juha Hyttinen83ada002020-01-30 10:36:33 +02001050 if trans == nil {
1051 xapp.Logger.Error("XAPP-SubDelReq: %s", idstring(fmt.Errorf("transaction not created"), params))
Juha Hyttinen422d0182020-01-17 13:37:05 +02001052 return
1053 }
1054 defer trans.Release()
1055
Juha Hyttinen83ada002020-01-30 10:36:33 +02001056 err = c.tracker.Track(trans)
Juha Hyttinen422d0182020-01-17 13:37:05 +02001057 if err != nil {
Juha Hyttinen83ada002020-01-30 10:36:33 +02001058 xapp.Logger.Error("XAPP-SubReq: %s", idstring(err, trans))
1059 return
1060 }
1061
Juha Hyttinen47942b42020-02-27 10:41:43 +02001062 subs, err := c.registry.GetSubscriptionFirstMatch([]uint32{trans.GetSubId()})
Juha Hyttinen83ada002020-01-30 10:36:33 +02001063 if err != nil {
1064 xapp.Logger.Error("XAPP-SubDelReq: %s", idstring(err, trans))
Juha Hyttinen422d0182020-01-17 13:37:05 +02001065 return
1066 }
1067
Juha Hyttinen422d0182020-01-17 13:37:05 +02001068 //
1069 // Wake subs delete
1070 //
Anssi Mannilac7da4ee2021-10-22 09:52:02 +03001071 subs.OngoingDelCount++
Anssi Mannila54838ed2021-11-19 11:25:01 +02001072 go c.handleSubscriptionDelete(subs, trans, waitRouteCleanup_ms)
Juha Hyttinen422d0182020-01-17 13:37:05 +02001073 trans.WaitEvent(0) //blocked wait as timeout is handled in subs side
Anssi Mannilac7da4ee2021-10-22 09:52:02 +03001074 subs.OngoingDelCount--
Juha Hyttinen422d0182020-01-17 13:37:05 +02001075
Juha Hyttinen83ada002020-01-30 10:36:33 +02001076 xapp.Logger.Debug("XAPP-SubDelReq: Handling event %s ", idstring(nil, trans, subs))
1077
Anssi Mannilac92b4212020-12-07 14:59:34 +02001078 if subs.NoRespToXapp == true {
1079 // Do no send delete responses to xapps due to submgr restart is deleting uncompleted subscriptions
Anssi Mannilaf682ace2021-09-28 13:11:25 +03001080 xapp.Logger.Debug("XAPP-SubDelReq: subs.NoRespToXapp == true")
Anssi Mannilac92b4212020-12-07 14:59:34 +02001081 return
1082 }
1083
1084 // Whatever is received success, fail or timeout, send successful delete response
Juha Hyttinen422d0182020-01-17 13:37:05 +02001085 subDelRespMsg := &e2ap.E2APSubscriptionDeleteResponse{}
Anssi Mannila4c626a22021-02-11 12:50:48 +02001086 subDelRespMsg.RequestId.Id = trans.RequestId.Id
1087 subDelRespMsg.RequestId.InstanceId = subs.GetReqId().RequestId.InstanceId
Juha Hyttinen422d0182020-01-17 13:37:05 +02001088 subDelRespMsg.FunctionId = subs.SubReqMsg.FunctionId
1089 trans.Mtype, trans.Payload, err = c.e2ap.PackSubscriptionDeleteResponse(subDelRespMsg)
1090 if err == nil {
Anssi Mannila4abf1802021-01-28 13:06:46 +02001091 c.UpdateCounter(cSubDelRespToXapp)
Anssi Mannila9c4697f2022-07-04 15:51:38 +03001092 err := c.rmrSendToXapp("", subs, trans)
1093 if err != nil {
1094 xapp.Logger.Error("rmrSendToXapp() failed:%s", err.Error())
1095 }
Juha Hyttinen422d0182020-01-17 13:37:05 +02001096 }
1097}
1098
1099//-------------------------------------------------------------------
1100// SUBS CREATE Handling
1101//-------------------------------------------------------------------
Anssi Mannila54838ed2021-11-19 11:25:01 +02001102func (c *Control) handleSubscriptionCreate(subs *Subscription, parentTrans *TransactionXapp, e2SubscriptionDirectives *E2SubscriptionDirectives, waitRouteCleanupTime time.Duration) {
Juha Hyttinen422d0182020-01-17 13:37:05 +02001103
Anssi Mannilaf682ace2021-09-28 13:11:25 +03001104 var event interface{} = nil
Anssi Mannilac92b4212020-12-07 14:59:34 +02001105 var removeSubscriptionFromDb bool = false
Juha Hyttinen83ada002020-01-30 10:36:33 +02001106 trans := c.tracker.NewSubsTransaction(subs)
Juha Hyttinen422d0182020-01-17 13:37:05 +02001107 subs.WaitTransactionTurn(trans)
1108 defer subs.ReleaseTransactionTurn(trans)
1109 defer trans.Release()
1110
Juha Hyttinen83ada002020-01-30 10:36:33 +02001111 xapp.Logger.Debug("SUBS-SubReq: Handling %s ", idstring(nil, trans, subs, parentTrans))
Juha Hyttinen422d0182020-01-17 13:37:05 +02001112
Juha Hyttinen83ada002020-01-30 10:36:33 +02001113 subRfMsg, valid := subs.GetCachedResponse()
1114 if subRfMsg == nil && valid == true {
Anssi Mannilaf682ace2021-09-28 13:11:25 +03001115 event = c.sendE2TSubscriptionRequest(subs, trans, parentTrans, e2SubscriptionDirectives)
Anssi Mannila6d629ad2021-01-25 09:59:56 +02001116 switch event.(type) {
1117 case *e2ap.E2APSubscriptionResponse:
1118 subRfMsg, valid = subs.SetCachedResponse(event, true)
1119 subs.SubRespRcvd = true
1120 case *e2ap.E2APSubscriptionFailure:
Anssi Mannila6d629ad2021-01-25 09:59:56 +02001121 subRfMsg, valid = subs.SetCachedResponse(event, false)
Anssi Mannilaf682ace2021-09-28 13:11:25 +03001122 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 +02001123 case *SubmgrRestartTestEvent:
Anssi Mannila54838ed2021-11-19 11:25:01 +02001124 // 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 +02001125 xapp.Logger.Debug("Test restart flag is active. Dropping this transaction to test restart case")
Anssi Mannila54838ed2021-11-19 11:25:01 +02001126 subRfMsg, valid = subs.SetCachedResponse(event, false)
1127 parentTrans.SendEvent(subRfMsg, 0)
1128 return
Anssi Mannilaf682ace2021-09-28 13:11:25 +03001129 case *PackSubscriptionRequestErrortEvent, *SDLWriteErrortEvent:
1130 subRfMsg, valid = subs.SetCachedResponse(event, false)
Anssi Mannila6d629ad2021-01-25 09:59:56 +02001131 default:
Anssi Mannila3d80b722021-11-12 13:17:15 +02001132 // Timer expiry
Anssi Mannilaf682ace2021-09-28 13:11:25 +03001133 if subs.PolicyUpdate == false {
1134 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 +03001135 subRfMsg, valid = subs.SetCachedResponse(nil, false)
1136 c.sendE2TSubscriptionDeleteRequest(subs, trans, parentTrans)
Anssi Mannila54838ed2021-11-19 11:25:01 +02001137 } else {
1138 subRfMsg, valid = subs.SetCachedResponse(nil, true)
Anssi Mannilaf682ace2021-09-28 13:11:25 +03001139 }
Juha Hyttinen83ada002020-01-30 10:36:33 +02001140 }
1141 xapp.Logger.Debug("SUBS-SubReq: Handling (e2t response %s) %s", typeofSubsMessage(subRfMsg), idstring(nil, trans, subs, parentTrans))
1142 } else {
1143 xapp.Logger.Debug("SUBS-SubReq: Handling (cached response %s) %s", typeofSubsMessage(subRfMsg), idstring(nil, trans, subs, parentTrans))
Juha Hyttinen422d0182020-01-17 13:37:05 +02001144 }
Anssi Mannila54838ed2021-11-19 11:25:01 +02001145 if valid == false {
1146 removeSubscriptionFromDb = true
1147 }
Juha Hyttinen422d0182020-01-17 13:37:05 +02001148
Anssi Mannilaf682ace2021-09-28 13:11:25 +03001149 err := c.UpdateSubscriptionInDB(subs, removeSubscriptionFromDb)
1150 if err != nil {
Anssi Mannila54838ed2021-11-19 11:25:01 +02001151 valid = false
Anssi Mannilaf682ace2021-09-28 13:11:25 +03001152 c.sendE2TSubscriptionDeleteRequest(subs, trans, parentTrans)
Anssi Mannila9c4697f2022-07-04 15:51:38 +03001153
Anssi Mannilaf682ace2021-09-28 13:11:25 +03001154 }
1155
Anssi Mannila27385172021-12-22 09:41:54 +02001156 // Now RemoveFromSubscription in here to avoid race conditions (mostly concerns delete)
Juha Hyttinen429cfe62020-03-31 11:23:02 +03001157 if valid == false {
Anssi Mannila9c4697f2022-07-04 15:51:38 +03001158 err = c.registry.RemoveFromSubscription(subs, parentTrans, waitRouteCleanupTime, c)
1159 if err != nil {
1160 xapp.Logger.Error("RemoveFromSubscription() failed:%s", err.Error())
1161 }
Juha Hyttinen429cfe62020-03-31 11:23:02 +03001162 }
Anssi Mannilac92b4212020-12-07 14:59:34 +02001163
Juha Hyttinen83ada002020-01-30 10:36:33 +02001164 parentTrans.SendEvent(subRfMsg, 0)
Juha Hyttinen422d0182020-01-17 13:37:05 +02001165}
1166
1167//-------------------------------------------------------------------
1168// SUBS DELETE Handling
1169//-------------------------------------------------------------------
Juha Hyttinen3944a222020-01-24 11:51:46 +02001170
Anssi Mannila54838ed2021-11-19 11:25:01 +02001171func (c *Control) handleSubscriptionDelete(subs *Subscription, parentTrans *TransactionXapp, waitRouteCleanupTime time.Duration) {
Juha Hyttinen422d0182020-01-17 13:37:05 +02001172
Juha Hyttinen83ada002020-01-30 10:36:33 +02001173 trans := c.tracker.NewSubsTransaction(subs)
Juha Hyttinen422d0182020-01-17 13:37:05 +02001174 subs.WaitTransactionTurn(trans)
1175 defer subs.ReleaseTransactionTurn(trans)
1176 defer trans.Release()
1177
Juha Hyttinen83ada002020-01-30 10:36:33 +02001178 xapp.Logger.Debug("SUBS-SubDelReq: Handling %s", idstring(nil, trans, subs, parentTrans))
Juha Hyttinen422d0182020-01-17 13:37:05 +02001179
Juha Hyttinen3944a222020-01-24 11:51:46 +02001180 subs.mutex.Lock()
Anssi Mannila4abf1802021-01-28 13:06:46 +02001181
Juha Hyttinen3944a222020-01-24 11:51:46 +02001182 if subs.valid && subs.EpList.HasEndpoint(parentTrans.GetEndpoint()) && subs.EpList.Size() == 1 {
1183 subs.valid = false
1184 subs.mutex.Unlock()
1185 c.sendE2TSubscriptionDeleteRequest(subs, trans, parentTrans)
1186 } else {
1187 subs.mutex.Unlock()
1188 }
Anssi Mannila27385172021-12-22 09:41:54 +02001189
1190 // Now RemoveFromSubscription in here to avoid race conditions (mostly concerns delete)
Anssi Mannila54838ed2021-11-19 11:25:01 +02001191 c.registry.RemoveFromSubscription(subs, parentTrans, waitRouteCleanupTime, c)
Juha Hyttinen47942b42020-02-27 10:41:43 +02001192 parentTrans.SendEvent(nil, 0)
Juha Hyttinen422d0182020-01-17 13:37:05 +02001193}
1194
1195//-------------------------------------------------------------------
1196// send to E2T Subscription Request
1197//-------------------------------------------------------------------
Anssi Mannilaf682ace2021-09-28 13:11:25 +03001198func (c *Control) sendE2TSubscriptionRequest(subs *Subscription, trans *TransactionSubs, parentTrans *TransactionXapp, e2SubscriptionDirectives *E2SubscriptionDirectives) interface{} {
Juha Hyttinen422d0182020-01-17 13:37:05 +02001199 var err error
1200 var event interface{} = nil
1201 var timedOut bool = false
Konstantinos Archangelof26dfa712021-06-04 12:10:26 +00001202 const ricRequestorId = 123
Juha Hyttinen422d0182020-01-17 13:37:05 +02001203
1204 subReqMsg := subs.SubReqMsg
Juha Hyttinen83ada002020-01-30 10:36:33 +02001205 subReqMsg.RequestId = subs.GetReqId().RequestId
Konstantinos Archangelof26dfa712021-06-04 12:10:26 +00001206 subReqMsg.RequestId.Id = ricRequestorId
Juha Hyttinen422d0182020-01-17 13:37:05 +02001207 trans.Mtype, trans.Payload, err = c.e2ap.PackSubscriptionRequest(subReqMsg)
1208 if err != nil {
Anssi Mannilab43397e2021-11-16 12:06:16 +02001209 xapp.Logger.Error("SUBS-SubReq ASN1 pack error: %s", idstring(err, trans, subs, parentTrans))
Anssi Mannilaf682ace2021-09-28 13:11:25 +03001210 return &PackSubscriptionRequestErrortEvent{
1211 ErrorInfo{
1212 ErrorSource: models.SubscriptionInstanceErrorSourceASN1,
1213 ErrorCause: err.Error(),
1214 },
1215 }
Juha Hyttinen422d0182020-01-17 13:37:05 +02001216 }
1217
Anssi Mannilac92b4212020-12-07 14:59:34 +02001218 // 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 +03001219 err = c.WriteSubscriptionToDb(subs)
1220 if err != nil {
1221 return &SDLWriteErrortEvent{
1222 ErrorInfo{
1223 ErrorSource: models.SubscriptionInstanceErrorSourceDBAAS,
1224 ErrorCause: err.Error(),
1225 },
1226 }
1227 }
Markku Virtanenfe2cdab2021-05-21 10:59:29 +00001228
Anssi Mannilaf682ace2021-09-28 13:11:25 +03001229 for retries := int64(0); retries < e2SubscriptionDirectives.E2MaxTryCount; retries++ {
Juha Hyttinen83ada002020-01-30 10:36:33 +02001230 desc := fmt.Sprintf("(retry %d)", retries)
Anssi Mannila4abf1802021-01-28 13:06:46 +02001231 if retries == 0 {
1232 c.UpdateCounter(cSubReqToE2)
1233 } else {
1234 c.UpdateCounter(cSubReReqToE2)
1235 }
Anssi Mannila9c4697f2022-07-04 15:51:38 +03001236 err := c.rmrSendToE2T(desc, subs, trans)
1237 if err != nil {
1238 xapp.Logger.Error("rmrSendToE2T() failed:%s", err.Error())
1239 }
1240
Anssi Mannilac92b4212020-12-07 14:59:34 +02001241 if subs.DoNotWaitSubResp == false {
Anssi Mannilaf682ace2021-09-28 13:11:25 +03001242 event, timedOut = trans.WaitEvent(e2SubscriptionDirectives.E2TimeoutTimerValue)
Anssi Mannilac92b4212020-12-07 14:59:34 +02001243 if timedOut {
Anssi Mannila4abf1802021-01-28 13:06:46 +02001244 c.UpdateCounter(cSubReqTimerExpiry)
Anssi Mannilac92b4212020-12-07 14:59:34 +02001245 continue
1246 }
1247 } else {
1248 // Simulating case where subscrition request has been sent but response has not been received before restart
1249 event = &SubmgrRestartTestEvent{}
Anssi Mannilaf682ace2021-09-28 13:11:25 +03001250 xapp.Logger.Debug("Restart event, DoNotWaitSubResp == true")
Juha Hyttinen422d0182020-01-17 13:37:05 +02001251 }
1252 break
1253 }
Juha Hyttinen83ada002020-01-30 10:36:33 +02001254 xapp.Logger.Debug("SUBS-SubReq: Response handling event(%s) %s", typeofSubsMessage(event), idstring(nil, trans, subs, parentTrans))
Juha Hyttinen422d0182020-01-17 13:37:05 +02001255 return event
1256}
1257
1258//-------------------------------------------------------------------
1259// send to E2T Subscription Delete Request
1260//-------------------------------------------------------------------
1261
Juha Hyttinen83ada002020-01-30 10:36:33 +02001262func (c *Control) sendE2TSubscriptionDeleteRequest(subs *Subscription, trans *TransactionSubs, parentTrans *TransactionXapp) interface{} {
Juha Hyttinen422d0182020-01-17 13:37:05 +02001263 var err error
1264 var event interface{}
1265 var timedOut bool
Konstantinos Archangelof26dfa712021-06-04 12:10:26 +00001266 const ricRequestorId = 123
Juha Hyttinen422d0182020-01-17 13:37:05 +02001267
1268 subDelReqMsg := &e2ap.E2APSubscriptionDeleteRequest{}
Juha Hyttinen83ada002020-01-30 10:36:33 +02001269 subDelReqMsg.RequestId = subs.GetReqId().RequestId
Konstantinos Archangelof26dfa712021-06-04 12:10:26 +00001270 subDelReqMsg.RequestId.Id = ricRequestorId
Juha Hyttinenaf91f972020-01-24 08:38:47 +02001271 subDelReqMsg.FunctionId = subs.SubReqMsg.FunctionId
Juha Hyttinen422d0182020-01-17 13:37:05 +02001272 trans.Mtype, trans.Payload, err = c.e2ap.PackSubscriptionDeleteRequest(subDelReqMsg)
1273 if err != nil {
Juha Hyttinen83ada002020-01-30 10:36:33 +02001274 xapp.Logger.Error("SUBS-SubDelReq: %s", idstring(err, trans, subs, parentTrans))
Juha Hyttinen422d0182020-01-17 13:37:05 +02001275 return event
1276 }
1277
1278 for retries := uint64(0); retries < e2tMaxSubDelReqTryCount; retries++ {
Juha Hyttinen83ada002020-01-30 10:36:33 +02001279 desc := fmt.Sprintf("(retry %d)", retries)
Anssi Mannila4abf1802021-01-28 13:06:46 +02001280 if retries == 0 {
1281 c.UpdateCounter(cSubDelReqToE2)
1282 } else {
1283 c.UpdateCounter(cSubDelReReqToE2)
1284 }
Anssi Mannila9c4697f2022-07-04 15:51:38 +03001285 err := c.rmrSendToE2T(desc, subs, trans)
1286 if err != nil {
1287 xapp.Logger.Error("SUBS-SubDelReq: rmrSendToE2T failure: %s", idstring(err, trans, subs, parentTrans))
1288 }
Juha Hyttinen422d0182020-01-17 13:37:05 +02001289 event, timedOut = trans.WaitEvent(e2tSubDelReqTime)
1290 if timedOut {
Anssi Mannila4abf1802021-01-28 13:06:46 +02001291 c.UpdateCounter(cSubDelReqTimerExpiry)
Juha Hyttinen422d0182020-01-17 13:37:05 +02001292 continue
1293 }
1294 break
1295 }
Juha Hyttinen83ada002020-01-30 10:36:33 +02001296 xapp.Logger.Debug("SUBS-SubDelReq: Response handling event(%s) %s", typeofSubsMessage(event), idstring(nil, trans, subs, parentTrans))
Juha Hyttinen422d0182020-01-17 13:37:05 +02001297 return event
1298}
1299
1300//-------------------------------------------------------------------
Anssi Mannila4abf1802021-01-28 13:06:46 +02001301// handle from E2T Subscription Response
Juha Hyttinen422d0182020-01-17 13:37:05 +02001302//-------------------------------------------------------------------
Juha Hyttinen9dc5adc2020-08-13 10:02:40 +03001303func (c *Control) handleE2TSubscriptionResponse(params *xapp.RMRParams) {
Anssi Mannilaf682ace2021-09-28 13:11:25 +03001304 xapp.Logger.Debug("MSG from E2T: %s", params.String())
Anssi Mannila4abf1802021-01-28 13:06:46 +02001305 c.UpdateCounter(cSubRespFromE2)
Anssi Mannila51122392021-05-25 11:51:31 +03001306
Juha Hyttinen422d0182020-01-17 13:37:05 +02001307 subRespMsg, err := c.e2ap.UnpackSubscriptionResponse(params.Payload)
1308 if err != nil {
Juha Hyttinen83ada002020-01-30 10:36:33 +02001309 xapp.Logger.Error("MSG-SubResp %s", idstring(err, params))
Juha Hyttinen422d0182020-01-17 13:37:05 +02001310 return
1311 }
Juha Hyttinenaada6452020-04-07 08:47:58 +03001312 subs, err := c.registry.GetSubscriptionFirstMatch([]uint32{subRespMsg.RequestId.InstanceId})
Juha Hyttinen422d0182020-01-17 13:37:05 +02001313 if err != nil {
Juha Hyttinen83ada002020-01-30 10:36:33 +02001314 xapp.Logger.Error("MSG-SubResp: %s", idstring(err, params))
Juha Hyttinen422d0182020-01-17 13:37:05 +02001315 return
Juha Hyttinen31797b42020-01-16 14:05:01 +02001316 }
1317 trans := subs.GetTransaction()
1318 if trans == nil {
Juha Hyttinen422d0182020-01-17 13:37:05 +02001319 err = fmt.Errorf("Ongoing transaction not found")
Juha Hyttinen83ada002020-01-30 10:36:33 +02001320 xapp.Logger.Error("MSG-SubResp: %s", idstring(err, params, subs))
Juha Hyttinenff8dccd2019-12-10 14:34:07 +02001321 return
Anssi Mannila2e99e2f2019-12-05 13:57:06 +02001322 }
Anssi Mannila54838ed2021-11-19 11:25:01 +02001323 xapp.Logger.Debug("SUBS-SubResp: Sending event, trans= %v", trans)
Juha Hyttinen422d0182020-01-17 13:37:05 +02001324 sendOk, timedOut := trans.SendEvent(subRespMsg, e2tRecvMsgTimeout)
1325 if sendOk == false {
1326 err = fmt.Errorf("Passing event to transaction failed: sendOk(%t) timedOut(%t)", sendOk, timedOut)
Juha Hyttinen83ada002020-01-30 10:36:33 +02001327 xapp.Logger.Error("MSG-SubResp: %s", idstring(err, trans, subs))
Peter Szilagyifbc56f92019-07-23 19:29:46 +00001328 }
Peter Szilagyifbc56f92019-07-23 19:29:46 +00001329 return
kalnagy45114752019-06-18 14:40:39 +02001330}
1331
Juha Hyttinen422d0182020-01-17 13:37:05 +02001332//-------------------------------------------------------------------
1333// handle from E2T Subscription Failure
1334//-------------------------------------------------------------------
Juha Hyttinen9dc5adc2020-08-13 10:02:40 +03001335func (c *Control) handleE2TSubscriptionFailure(params *xapp.RMRParams) {
Anssi Mannilaf682ace2021-09-28 13:11:25 +03001336 xapp.Logger.Debug("MSG from E2T: %s", params.String())
Anssi Mannila4abf1802021-01-28 13:06:46 +02001337 c.UpdateCounter(cSubFailFromE2)
Juha Hyttinen422d0182020-01-17 13:37:05 +02001338 subFailMsg, err := c.e2ap.UnpackSubscriptionFailure(params.Payload)
Peter Szilagyifbc56f92019-07-23 19:29:46 +00001339 if err != nil {
Juha Hyttinen83ada002020-01-30 10:36:33 +02001340 xapp.Logger.Error("MSG-SubFail %s", idstring(err, params))
Peter Szilagyifbc56f92019-07-23 19:29:46 +00001341 return
1342 }
Juha Hyttinenaada6452020-04-07 08:47:58 +03001343 subs, err := c.registry.GetSubscriptionFirstMatch([]uint32{subFailMsg.RequestId.InstanceId})
Juha Hyttinen31797b42020-01-16 14:05:01 +02001344 if err != nil {
Juha Hyttinen83ada002020-01-30 10:36:33 +02001345 xapp.Logger.Error("MSG-SubFail: %s", idstring(err, params))
Juha Hyttinenaafee7f2020-01-14 14:54:51 +02001346 return
1347 }
Juha Hyttinen422d0182020-01-17 13:37:05 +02001348 trans := subs.GetTransaction()
1349 if trans == nil {
1350 err = fmt.Errorf("Ongoing transaction not found")
Juha Hyttinen83ada002020-01-30 10:36:33 +02001351 xapp.Logger.Error("MSG-SubFail: %s", idstring(err, params, subs))
Anssi Mannila8046c702020-01-02 13:39:05 +02001352 return
1353 }
Juha Hyttinen422d0182020-01-17 13:37:05 +02001354 sendOk, timedOut := trans.SendEvent(subFailMsg, e2tRecvMsgTimeout)
1355 if sendOk == false {
1356 err = fmt.Errorf("Passing event to transaction failed: sendOk(%t) timedOut(%t)", sendOk, timedOut)
Juha Hyttinen83ada002020-01-30 10:36:33 +02001357 xapp.Logger.Error("MSG-SubFail: %s", idstring(err, trans, subs))
Juha Hyttinenaafee7f2020-01-14 14:54:51 +02001358 }
Anssi Mannila2e99e2f2019-12-05 13:57:06 +02001359 return
1360}
1361
Juha Hyttinen422d0182020-01-17 13:37:05 +02001362//-------------------------------------------------------------------
1363// handle from E2T Subscription Delete Response
1364//-------------------------------------------------------------------
Anssi Mannila9c4697f2022-07-04 15:51:38 +03001365func (c *Control) handleE2TSubscriptionDeleteResponse(params *xapp.RMRParams) {
Anssi Mannilaf682ace2021-09-28 13:11:25 +03001366 xapp.Logger.Debug("MSG from E2T: %s", params.String())
Anssi Mannila4abf1802021-01-28 13:06:46 +02001367 c.UpdateCounter(cSubDelRespFromE2)
Juha Hyttinen422d0182020-01-17 13:37:05 +02001368 subDelRespMsg, err := c.e2ap.UnpackSubscriptionDeleteResponse(params.Payload)
Anssi Mannila2e99e2f2019-12-05 13:57:06 +02001369 if err != nil {
Juha Hyttinen83ada002020-01-30 10:36:33 +02001370 xapp.Logger.Error("MSG-SubDelResp: %s", idstring(err, params))
Anssi Mannila2e99e2f2019-12-05 13:57:06 +02001371 return
1372 }
Juha Hyttinenaada6452020-04-07 08:47:58 +03001373 subs, err := c.registry.GetSubscriptionFirstMatch([]uint32{subDelRespMsg.RequestId.InstanceId})
Juha Hyttinen31797b42020-01-16 14:05:01 +02001374 if err != nil {
Juha Hyttinen83ada002020-01-30 10:36:33 +02001375 xapp.Logger.Error("MSG-SubDelResp: %s", idstring(err, params))
Juha Hyttinen0d064ec2020-01-09 09:08:53 +02001376 return
1377 }
Juha Hyttinen422d0182020-01-17 13:37:05 +02001378 trans := subs.GetTransaction()
1379 if trans == nil {
1380 err = fmt.Errorf("Ongoing transaction not found")
Juha Hyttinen83ada002020-01-30 10:36:33 +02001381 xapp.Logger.Error("MSG-SubDelResp: %s", idstring(err, params, subs))
Anssi Mannila8046c702020-01-02 13:39:05 +02001382 return
Anssi Mannila2e99e2f2019-12-05 13:57:06 +02001383 }
Juha Hyttinen422d0182020-01-17 13:37:05 +02001384 sendOk, timedOut := trans.SendEvent(subDelRespMsg, e2tRecvMsgTimeout)
1385 if sendOk == false {
1386 err = fmt.Errorf("Passing event to transaction failed: sendOk(%t) timedOut(%t)", sendOk, timedOut)
Juha Hyttinen83ada002020-01-30 10:36:33 +02001387 xapp.Logger.Error("MSG-SubDelResp: %s", idstring(err, trans, subs))
Juha Hyttinen60bfcf92020-01-14 15:14:24 +02001388 }
Anssi Mannila2e99e2f2019-12-05 13:57:06 +02001389 return
1390}
1391
Juha Hyttinen422d0182020-01-17 13:37:05 +02001392//-------------------------------------------------------------------
1393// handle from E2T Subscription Delete Failure
1394//-------------------------------------------------------------------
Juha Hyttinen9dc5adc2020-08-13 10:02:40 +03001395func (c *Control) handleE2TSubscriptionDeleteFailure(params *xapp.RMRParams) {
Anssi Mannilaf682ace2021-09-28 13:11:25 +03001396 xapp.Logger.Debug("MSG from E2T: %s", params.String())
Anssi Mannila4abf1802021-01-28 13:06:46 +02001397 c.UpdateCounter(cSubDelFailFromE2)
Juha Hyttinen422d0182020-01-17 13:37:05 +02001398 subDelFailMsg, err := c.e2ap.UnpackSubscriptionDeleteFailure(params.Payload)
Juha Hyttinen31797b42020-01-16 14:05:01 +02001399 if err != nil {
Juha Hyttinen83ada002020-01-30 10:36:33 +02001400 xapp.Logger.Error("MSG-SubDelFail: %s", idstring(err, params))
Anssi Mannilaf1d0eb62019-12-17 15:29:55 +02001401 return
1402 }
Juha Hyttinenaada6452020-04-07 08:47:58 +03001403 subs, err := c.registry.GetSubscriptionFirstMatch([]uint32{subDelFailMsg.RequestId.InstanceId})
Anssi Mannila8046c702020-01-02 13:39:05 +02001404 if err != nil {
Juha Hyttinen83ada002020-01-30 10:36:33 +02001405 xapp.Logger.Error("MSG-SubDelFail: %s", idstring(err, params))
Anssi Mannila8046c702020-01-02 13:39:05 +02001406 return
1407 }
Juha Hyttinen422d0182020-01-17 13:37:05 +02001408 trans := subs.GetTransaction()
1409 if trans == nil {
1410 err = fmt.Errorf("Ongoing transaction not found")
Juha Hyttinen83ada002020-01-30 10:36:33 +02001411 xapp.Logger.Error("MSG-SubDelFail: %s", idstring(err, params, subs))
Juha Hyttinen86a46202020-01-14 12:49:09 +02001412 return
1413 }
Juha Hyttinen422d0182020-01-17 13:37:05 +02001414 sendOk, timedOut := trans.SendEvent(subDelFailMsg, e2tRecvMsgTimeout)
1415 if sendOk == false {
1416 err = fmt.Errorf("Passing event to transaction failed: sendOk(%t) timedOut(%t)", sendOk, timedOut)
Juha Hyttinen83ada002020-01-30 10:36:33 +02001417 xapp.Logger.Error("MSG-SubDelFail: %s", idstring(err, trans, subs))
Anssi Mannila8046c702020-01-02 13:39:05 +02001418 }
kalnagy93cc3e22019-09-19 11:29:29 +02001419 return
1420}
1421
Juha Hyttinen422d0182020-01-17 13:37:05 +02001422//-------------------------------------------------------------------
1423//
1424//-------------------------------------------------------------------
1425func typeofSubsMessage(v interface{}) string {
1426 if v == nil {
1427 return "NIL"
kalnagy93cc3e22019-09-19 11:29:29 +02001428 }
Juha Hyttinen422d0182020-01-17 13:37:05 +02001429 switch v.(type) {
Anssi Mannila51122392021-05-25 11:51:31 +03001430 //case *e2ap.E2APSubscriptionRequest:
1431 // return "SubReq"
Juha Hyttinen422d0182020-01-17 13:37:05 +02001432 case *e2ap.E2APSubscriptionResponse:
1433 return "SubResp"
1434 case *e2ap.E2APSubscriptionFailure:
1435 return "SubFail"
Anssi Mannila51122392021-05-25 11:51:31 +03001436 //case *e2ap.E2APSubscriptionDeleteRequest:
1437 // return "SubDelReq"
Juha Hyttinen422d0182020-01-17 13:37:05 +02001438 case *e2ap.E2APSubscriptionDeleteResponse:
1439 return "SubDelResp"
1440 case *e2ap.E2APSubscriptionDeleteFailure:
1441 return "SubDelFail"
1442 default:
1443 return "Unknown"
Juha Hyttinen31797b42020-01-16 14:05:01 +02001444 }
Anssi Mannilaf1d0eb62019-12-17 15:29:55 +02001445}
Anssi Mannilac92b4212020-12-07 14:59:34 +02001446
1447//-------------------------------------------------------------------
1448//
1449//-------------------------------------------------------------------
Anssi Mannilaf682ace2021-09-28 13:11:25 +03001450func (c *Control) WriteSubscriptionToDb(subs *Subscription) error {
Anssi Mannilac92b4212020-12-07 14:59:34 +02001451 xapp.Logger.Debug("WriteSubscriptionToDb() subId = %v", subs.ReqId.InstanceId)
1452 err := c.WriteSubscriptionToSdl(subs.ReqId.InstanceId, subs)
1453 if err != nil {
1454 xapp.Logger.Error("%v", err)
Anssi Mannilaf682ace2021-09-28 13:11:25 +03001455 return err
Anssi Mannilac92b4212020-12-07 14:59:34 +02001456 }
Anssi Mannilaf682ace2021-09-28 13:11:25 +03001457 return nil
Anssi Mannilac92b4212020-12-07 14:59:34 +02001458}
1459
1460//-------------------------------------------------------------------
1461//
1462//-------------------------------------------------------------------
Anssi Mannilaf682ace2021-09-28 13:11:25 +03001463func (c *Control) UpdateSubscriptionInDB(subs *Subscription, removeSubscriptionFromDb bool) error {
Anssi Mannilac92b4212020-12-07 14:59:34 +02001464
1465 if removeSubscriptionFromDb == true {
1466 // Subscription was written in db already when subscription request was sent to BTS, except for merged request
1467 c.RemoveSubscriptionFromDb(subs)
1468 } else {
1469 // Update is needed for successful response and merge case here
1470 if subs.RetryFromXapp == false {
Anssi Mannilaf682ace2021-09-28 13:11:25 +03001471 err := c.WriteSubscriptionToDb(subs)
1472 return err
Anssi Mannilac92b4212020-12-07 14:59:34 +02001473 }
1474 }
1475 subs.RetryFromXapp = false
Anssi Mannilaf682ace2021-09-28 13:11:25 +03001476 return nil
Anssi Mannilac92b4212020-12-07 14:59:34 +02001477}
1478
1479//-------------------------------------------------------------------
1480//
1481//-------------------------------------------------------------------
1482func (c *Control) RemoveSubscriptionFromDb(subs *Subscription) {
1483 xapp.Logger.Debug("RemoveSubscriptionFromDb() subId = %v", subs.ReqId.InstanceId)
1484 err := c.RemoveSubscriptionFromSdl(subs.ReqId.InstanceId)
1485 if err != nil {
1486 xapp.Logger.Error("%v", err)
1487 }
1488}
1489
Konstantinos Archangelof268d7152021-06-14 12:24:00 +03001490//-------------------------------------------------------------------
1491//
1492//-------------------------------------------------------------------
1493func (c *Control) WriteRESTSubscriptionToDb(restSubId string, restSubs *RESTSubscription) {
1494 xapp.Logger.Debug("WriteRESTSubscriptionToDb() restSubId = %s", restSubId)
1495 err := c.WriteRESTSubscriptionToSdl(restSubId, restSubs)
1496 if err != nil {
1497 xapp.Logger.Error("%v", err)
1498 }
1499}
1500
1501//-------------------------------------------------------------------
1502//
1503//-------------------------------------------------------------------
1504func (c *Control) UpdateRESTSubscriptionInDB(restSubId string, restSubs *RESTSubscription, removeRestSubscriptionFromDb bool) {
1505
1506 if removeRestSubscriptionFromDb == true {
1507 // Subscription was written in db already when subscription request was sent to BTS, except for merged request
1508 c.RemoveRESTSubscriptionFromDb(restSubId)
1509 } else {
1510 c.WriteRESTSubscriptionToDb(restSubId, restSubs)
1511 }
1512}
1513
1514//-------------------------------------------------------------------
1515//
1516//-------------------------------------------------------------------
1517func (c *Control) RemoveRESTSubscriptionFromDb(restSubId string) {
1518 xapp.Logger.Debug("RemoveRESTSubscriptionFromDb() restSubId = %s", restSubId)
1519 err := c.RemoveRESTSubscriptionFromSdl(restSubId)
1520 if err != nil {
1521 xapp.Logger.Error("%v", err)
1522 }
1523}
1524
Anssi Mannilac92b4212020-12-07 14:59:34 +02001525func (c *Control) SendSubscriptionDeleteReq(subs *Subscription) {
1526
Anssi Mannila54838ed2021-11-19 11:25:01 +02001527 if c.UTTesting == true {
1528 // Reqistry mutex is not locked after real restart but it can be when restart is simulated in unit tests
1529 c.registry.mutex = new(sync.Mutex)
1530 }
1531
Konstantinos Archangelof26dfa712021-06-04 12:10:26 +00001532 const ricRequestorId = 123
Anssi Mannilac92b4212020-12-07 14:59:34 +02001533 xapp.Logger.Debug("Sending subscription delete due to restart. subId = %v", subs.ReqId.InstanceId)
1534
1535 // Send delete for every endpoint in the subscription
Anssi Mannilaf682ace2021-09-28 13:11:25 +03001536 if subs.PolicyUpdate == false {
1537 subDelReqMsg := &e2ap.E2APSubscriptionDeleteRequest{}
1538 subDelReqMsg.RequestId = subs.GetReqId().RequestId
1539 subDelReqMsg.RequestId.Id = ricRequestorId
1540 subDelReqMsg.FunctionId = subs.SubReqMsg.FunctionId
1541 mType, payload, err := c.e2ap.PackSubscriptionDeleteRequest(subDelReqMsg)
1542 if err != nil {
1543 xapp.Logger.Error("SendSubscriptionDeleteReq() %s", idstring(err))
1544 return
1545 }
1546 for _, endPoint := range subs.EpList.Endpoints {
1547 params := &xapp.RMRParams{}
1548 params.Mtype = mType
1549 params.SubId = int(subs.GetReqId().InstanceId)
1550 params.Xid = ""
1551 params.Meid = subs.Meid
1552 params.Src = endPoint.String()
1553 params.PayloadLen = len(payload.Buf)
1554 params.Payload = payload.Buf
1555 params.Mbuf = nil
1556 subs.DeleteFromDb = true
1557 c.handleXAPPSubscriptionDeleteRequest(params)
1558 }
Anssi Mannilac92b4212020-12-07 14:59:34 +02001559 }
1560}
Anssi Mannilade457a12021-06-02 16:19:48 +03001561
1562func (c *Control) PrintRESTSubscriptionRequest(p *models.SubscriptionParams) {
1563
1564 fmt.Println("CRESTSubscriptionRequest")
Markku Virtanen987f8b12021-06-10 15:05:02 +03001565
Markku Virtanen2b512b62021-07-30 12:04:00 +00001566 if p == nil {
1567 return
1568 }
1569
Markku Virtanen987f8b12021-06-10 15:05:02 +03001570 if p.SubscriptionID != "" {
1571 fmt.Println(" SubscriptionID = ", p.SubscriptionID)
1572 } else {
1573 fmt.Println(" SubscriptionID = ''")
1574 }
1575
Anssi Mannilade457a12021-06-02 16:19:48 +03001576 fmt.Printf(" ClientEndpoint.Host = %s\n", p.ClientEndpoint.Host)
1577
1578 if p.ClientEndpoint.HTTPPort != nil {
1579 fmt.Printf(" ClientEndpoint.HTTPPort = %v\n", *p.ClientEndpoint.HTTPPort)
1580 } else {
1581 fmt.Println(" ClientEndpoint.HTTPPort = nil")
1582 }
1583
1584 if p.ClientEndpoint.RMRPort != nil {
1585 fmt.Printf(" ClientEndpoint.RMRPort = %v\n", *p.ClientEndpoint.RMRPort)
1586 } else {
1587 fmt.Println(" ClientEndpoint.RMRPort = nil")
1588 }
1589
1590 if p.Meid != nil {
1591 fmt.Printf(" Meid = %s\n", *p.Meid)
1592 } else {
1593 fmt.Println(" Meid = nil")
1594 }
1595
Anssi Mannilaf682ace2021-09-28 13:11:25 +03001596 if p.E2SubscriptionDirectives == nil {
1597 fmt.Println(" E2SubscriptionDirectives = nil")
1598 } else {
1599 fmt.Println(" E2SubscriptionDirectives")
1600 if p.E2SubscriptionDirectives.E2RetryCount == nil {
1601 fmt.Println(" E2RetryCount == nil")
1602 } else {
1603 fmt.Printf(" E2RetryCount = %v\n", *p.E2SubscriptionDirectives.E2RetryCount)
1604 }
1605 fmt.Printf(" E2TimeoutTimerValue = %v\n", p.E2SubscriptionDirectives.E2TimeoutTimerValue)
Anssi Mannilacb7dd492021-10-01 11:10:26 +03001606 fmt.Printf(" RMRRoutingNeeded = %v\n", p.E2SubscriptionDirectives.RMRRoutingNeeded)
Anssi Mannilaf682ace2021-09-28 13:11:25 +03001607 }
Anssi Mannilade457a12021-06-02 16:19:48 +03001608 for _, subscriptionDetail := range p.SubscriptionDetails {
1609 if p.RANFunctionID != nil {
1610 fmt.Printf(" RANFunctionID = %v\n", *p.RANFunctionID)
1611 } else {
1612 fmt.Println(" RANFunctionID = nil")
1613 }
Konstantinos Archangelofe93b00f2021-06-03 10:00:19 +00001614 fmt.Printf(" SubscriptionDetail.XappEventInstanceID = %v\n", *subscriptionDetail.XappEventInstanceID)
Konstantinos Archangelofbd9c98e2021-06-07 17:32:10 +00001615 fmt.Printf(" SubscriptionDetail.EventTriggers = %v\n", subscriptionDetail.EventTriggers)
Anssi Mannilade457a12021-06-02 16:19:48 +03001616
1617 for _, actionToBeSetup := range subscriptionDetail.ActionToBeSetupList {
1618 fmt.Printf(" SubscriptionDetail.ActionToBeSetup.ActionID = %v\n", *actionToBeSetup.ActionID)
1619 fmt.Printf(" SubscriptionDetail.ActionToBeSetup.ActionType = %s\n", *actionToBeSetup.ActionType)
Konstantinos Archangelofbd9c98e2021-06-07 17:32:10 +00001620 fmt.Printf(" SubscriptionDetail.ActionToBeSetup.ActionDefinition = %v\n", actionToBeSetup.ActionDefinition)
Anssi Mannilade457a12021-06-02 16:19:48 +03001621
Anssi Mannilade457a12021-06-02 16:19:48 +03001622 if actionToBeSetup.SubsequentAction != nil {
1623 fmt.Printf(" SubscriptionDetail.ActionToBeSetup.SubsequentAction.SubsequentActionType = %s\n", *actionToBeSetup.SubsequentAction.SubsequentActionType)
1624 fmt.Printf(" SubscriptionDetail.ActionToBeSetup..SubsequentAction.TimeToWait = %s\n", *actionToBeSetup.SubsequentAction.TimeToWait)
1625 } else {
1626 fmt.Println(" SubscriptionDetail.ActionToBeSetup.SubsequentAction = nil")
1627 }
1628 }
1629 }
1630}