blob: 0c97afb62bd0d4fd064c24a900d68055ddefa295 [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
173 c.ReadE2Subscriptions()
174 c.ReadRESTSubscriptions()
Anssi Mannilac92b4212020-12-07 14:59:34 +0200175 }
176
Anssi Mannila3cdd2e02021-10-14 12:35:41 +0300177 go xapp.Subscription.Listen(c.RESTSubscriptionHandler, c.RESTQueryHandler, c.RESTSubscriptionDeleteHandler)
Anssi Mannilac92b4212020-12-07 14:59:34 +0200178 return c
179}
180
Abukar Mohamedfbd4df52021-03-11 06:13:27 +0000181func (c *Control) SymptomDataHandler(w http.ResponseWriter, r *http.Request) {
182 subscriptions, _ := c.registry.QueryHandler()
183 xapp.Resource.SendSymptomDataJson(w, r, subscriptions, "platform/subscriptions.json")
184}
185
Anssi Mannilac92b4212020-12-07 14:59:34 +0200186//-------------------------------------------------------------------
187//
188//-------------------------------------------------------------------
Anssi Mannila92c38552021-12-29 09:59:24 +0200189func (c *Control) RESTQueryHandler() (models.SubscriptionList, error) {
190 xapp.Logger.Debug("RESTQueryHandler() called")
191
192 c.CntRecvMsg++
193
194 return c.registry.QueryHandler()
Anssi Mannilab73e7cd2021-08-03 11:57:11 +0300195}
196
197//-------------------------------------------------------------------
198//
199//-------------------------------------------------------------------
200func (c *Control) ReadE2Subscriptions() error {
201 var err error
202 var subIds []uint32
203 var register map[uint32]*Subscription
204 for i := 0; dbRetryForever == "true" || i < dbTryCount; i++ {
Anssi Mannilaf682ace2021-09-28 13:11:25 +0300205 xapp.Logger.Debug("Reading E2 subscriptions from db")
Anssi Mannilab73e7cd2021-08-03 11:57:11 +0300206 subIds, register, err = c.ReadAllSubscriptionsFromSdl()
207 if err != nil {
208 xapp.Logger.Error("%v", err)
209 <-time.After(1 * time.Second)
210 } else {
211 c.registry.subIds = subIds
212 c.registry.register = register
Anssi Mannila316b8d22021-12-21 09:43:59 +0200213 go c.HandleUncompletedSubscriptions(register)
Anssi Mannilab73e7cd2021-08-03 11:57:11 +0300214 return nil
215 }
216 }
Anssi Mannilaf682ace2021-09-28 13:11:25 +0300217 xapp.Logger.Debug("Continuing without retring")
Anssi Mannilab73e7cd2021-08-03 11:57:11 +0300218 return err
219}
220
221//-------------------------------------------------------------------
222//
223//-------------------------------------------------------------------
224func (c *Control) ReadRESTSubscriptions() error {
Anssi Mannila54838ed2021-11-19 11:25:01 +0200225
226 xapp.Logger.Debug("ReadRESTSubscriptions()")
Anssi Mannilab73e7cd2021-08-03 11:57:11 +0300227 var err error
228 var restSubscriptions map[string]*RESTSubscription
229 for i := 0; dbRetryForever == "true" || i < dbTryCount; i++ {
Anssi Mannilaf682ace2021-09-28 13:11:25 +0300230 xapp.Logger.Debug("Reading REST subscriptions from db")
Anssi Mannilab73e7cd2021-08-03 11:57:11 +0300231 restSubscriptions, err = c.ReadAllRESTSubscriptionsFromSdl()
232 if err != nil {
233 xapp.Logger.Error("%v", err)
234 <-time.After(1 * time.Second)
235 } else {
Anssi Mannila54838ed2021-11-19 11:25:01 +0200236 // Fix REST subscriptions ongoing status after restart
237 for restSubId, restSubscription := range restSubscriptions {
238 restSubscription.SubReqOngoing = false
239 restSubscription.SubDelReqOngoing = false
240 c.WriteRESTSubscriptionToSdl(restSubId, restSubscription)
241 }
Anssi Mannilab73e7cd2021-08-03 11:57:11 +0300242 c.registry.restSubscriptions = restSubscriptions
243 return nil
244 }
245 }
Anssi Mannilaf682ace2021-09-28 13:11:25 +0300246 xapp.Logger.Debug("Continuing without retring")
Anssi Mannilab73e7cd2021-08-03 11:57:11 +0300247 return err
248}
249
250//-------------------------------------------------------------------
251//
252//-------------------------------------------------------------------
Anssi Mannilaf6b78042021-02-18 12:36:59 +0200253func (c *Control) ReadConfigParameters(f string) {
Anssi Mannilac92b4212020-12-07 14:59:34 +0200254
Anssi Mannilac7da4ee2021-10-22 09:52:02 +0300255 xapp.Logger.Debug("ReadConfigParameters")
256
Anssi Mannilaf682ace2021-09-28 13:11:25 +0300257 c.LoggerLevel = int(xapp.Logger.GetLevel())
Anssi Mannila3d80b722021-11-12 13:17:15 +0200258 xapp.Logger.Info("LoggerLevel = %v", c.LoggerLevel)
Anssi Mannilae1af87f2021-11-10 13:10:54 +0200259 c.e2ap.SetASN1DebugPrintStatus(c.LoggerLevel)
Anssi Mannilaf682ace2021-09-28 13:11:25 +0300260
Anssi Mannila2f26fb22020-12-07 08:32:13 +0200261 // viper.GetDuration returns nanoseconds
262 e2tSubReqTimeout = viper.GetDuration("controls.e2tSubReqTimeout_ms") * 1000000
Juha Hyttinen57140bc2020-12-11 13:03:06 +0200263 if e2tSubReqTimeout == 0 {
264 e2tSubReqTimeout = 2000 * 1000000
Anssi Mannilac7da4ee2021-10-22 09:52:02 +0300265 xapp.Logger.Debug("WARNING: Using hard coded default value for e2tSubReqTimeout")
Juha Hyttinen57140bc2020-12-11 13:03:06 +0200266 }
Anssi Mannilac7da4ee2021-10-22 09:52:02 +0300267 xapp.Logger.Debug("e2tSubReqTimeout= %v", e2tSubReqTimeout)
Anssi Mannilaf682ace2021-09-28 13:11:25 +0300268
Anssi Mannila2f26fb22020-12-07 08:32:13 +0200269 e2tSubDelReqTime = viper.GetDuration("controls.e2tSubDelReqTime_ms") * 1000000
Juha Hyttinen57140bc2020-12-11 13:03:06 +0200270 if e2tSubDelReqTime == 0 {
271 e2tSubDelReqTime = 2000 * 1000000
Anssi Mannilac7da4ee2021-10-22 09:52:02 +0300272 xapp.Logger.Debug("WARNING: Using hard coded default value for e2tSubDelReqTime")
Juha Hyttinen57140bc2020-12-11 13:03:06 +0200273 }
Anssi Mannilac7da4ee2021-10-22 09:52:02 +0300274 xapp.Logger.Debug("e2tSubDelReqTime= %v", e2tSubDelReqTime)
275
Anssi Mannila2f26fb22020-12-07 08:32:13 +0200276 e2tRecvMsgTimeout = viper.GetDuration("controls.e2tRecvMsgTimeout_ms") * 1000000
Juha Hyttinen57140bc2020-12-11 13:03:06 +0200277 if e2tRecvMsgTimeout == 0 {
278 e2tRecvMsgTimeout = 2000 * 1000000
Anssi Mannilac7da4ee2021-10-22 09:52:02 +0300279 xapp.Logger.Debug("WARNING: Using hard coded default value for e2tRecvMsgTimeout")
Juha Hyttinen57140bc2020-12-11 13:03:06 +0200280 }
Anssi Mannilac7da4ee2021-10-22 09:52:02 +0300281 xapp.Logger.Debug("e2tRecvMsgTimeout= %v", e2tRecvMsgTimeout)
Markku Virtanenfe2cdab2021-05-21 10:59:29 +0000282
Anssi Mannila2f26fb22020-12-07 08:32:13 +0200283 e2tMaxSubReqTryCount = viper.GetUint64("controls.e2tMaxSubReqTryCount")
Juha Hyttinen57140bc2020-12-11 13:03:06 +0200284 if e2tMaxSubReqTryCount == 0 {
285 e2tMaxSubReqTryCount = 1
Anssi Mannilac7da4ee2021-10-22 09:52:02 +0300286 xapp.Logger.Debug("WARNING: Using hard coded default value for e2tMaxSubReqTryCount")
Juha Hyttinen57140bc2020-12-11 13:03:06 +0200287 }
Anssi Mannilac7da4ee2021-10-22 09:52:02 +0300288 xapp.Logger.Debug("e2tMaxSubReqTryCount= %v", e2tMaxSubReqTryCount)
Markku Virtanenfe2cdab2021-05-21 10:59:29 +0000289
Anssi Mannila2f26fb22020-12-07 08:32:13 +0200290 e2tMaxSubDelReqTryCount = viper.GetUint64("controls.e2tMaxSubDelReqTryCount")
Juha Hyttinen57140bc2020-12-11 13:03:06 +0200291 if e2tMaxSubDelReqTryCount == 0 {
292 e2tMaxSubDelReqTryCount = 1
Anssi Mannilac7da4ee2021-10-22 09:52:02 +0300293 xapp.Logger.Debug("WARNING: Using hard coded default value for e2tMaxSubDelReqTryCount")
Juha Hyttinen57140bc2020-12-11 13:03:06 +0200294 }
Anssi Mannilac7da4ee2021-10-22 09:52:02 +0300295 xapp.Logger.Debug("e2tMaxSubDelReqTryCount= %v", e2tMaxSubDelReqTryCount)
296
297 checkE2State = viper.GetString("controls.checkE2State")
298 if checkE2State == "" {
299 checkE2State = "true"
300 xapp.Logger.Debug("WARNING: Using hard coded default value for checkE2State")
301 }
302 xapp.Logger.Debug("checkE2State= %v", checkE2State)
Anssi Mannila2f26fb22020-12-07 08:32:13 +0200303
Anssi Mannilac92b4212020-12-07 14:59:34 +0200304 readSubsFromDb = viper.GetString("controls.readSubsFromDb")
305 if readSubsFromDb == "" {
306 readSubsFromDb = "true"
Anssi Mannilac7da4ee2021-10-22 09:52:02 +0300307 xapp.Logger.Debug("WARNING: Using hard coded default value for readSubsFromDb")
Juha Hyttinen5f8ffa02020-02-06 15:28:59 +0200308 }
Anssi Mannilac7da4ee2021-10-22 09:52:02 +0300309 xapp.Logger.Debug("readSubsFromDb= %v", readSubsFromDb)
Anssi Mannilab73e7cd2021-08-03 11:57:11 +0300310
311 dbTryCount = viper.GetInt("controls.dbTryCount")
312 if dbTryCount == 0 {
313 dbTryCount = 200
Anssi Mannilac7da4ee2021-10-22 09:52:02 +0300314 xapp.Logger.Debug("WARNING: Using hard coded default value for dbTryCount")
Anssi Mannilab73e7cd2021-08-03 11:57:11 +0300315 }
Anssi Mannilac7da4ee2021-10-22 09:52:02 +0300316 xapp.Logger.Debug("dbTryCount= %v", dbTryCount)
Anssi Mannilab73e7cd2021-08-03 11:57:11 +0300317
318 dbRetryForever = viper.GetString("controls.dbRetryForever")
319 if dbRetryForever == "" {
320 dbRetryForever = "true"
Anssi Mannilac7da4ee2021-10-22 09:52:02 +0300321 xapp.Logger.Debug("WARNING: Using hard coded default value for dbRetryForever")
Anssi Mannilab73e7cd2021-08-03 11:57:11 +0300322 }
Anssi Mannilac7da4ee2021-10-22 09:52:02 +0300323 xapp.Logger.Debug("dbRetryForever= %v", dbRetryForever)
Anssi Mannilab73e7cd2021-08-03 11:57:11 +0300324
325 // Internal cfg parameter, used to define a wait time for RMR route clean-up. None default
326 // value 100ms used currently only in unittests.
327 waitRouteCleanup_ms = viper.GetDuration("controls.waitRouteCleanup_ms") * 1000000
328 if waitRouteCleanup_ms == 0 {
329 waitRouteCleanup_ms = 5000 * 1000000
Anssi Mannilac7da4ee2021-10-22 09:52:02 +0300330 xapp.Logger.Debug("WARNING: Using hard coded default value for waitRouteCleanup_ms")
Anssi Mannilab73e7cd2021-08-03 11:57:11 +0300331 }
Anssi Mannilac7da4ee2021-10-22 09:52:02 +0300332 xapp.Logger.Debug("waitRouteCleanup= %v", waitRouteCleanup_ms)
Anssi Mannilac92b4212020-12-07 14:59:34 +0200333}
334
335//-------------------------------------------------------------------
336//
337//-------------------------------------------------------------------
338func (c *Control) HandleUncompletedSubscriptions(register map[uint32]*Subscription) {
339
340 xapp.Logger.Debug("HandleUncompletedSubscriptions. len(register) = %v", len(register))
341 for subId, subs := range register {
342 if subs.SubRespRcvd == false {
Anssi Mannilaf682ace2021-09-28 13:11:25 +0300343 // If policy subscription has already been made successfully unsuccessful update should not be deleted.
344 if subs.PolicyUpdate == false {
345 subs.NoRespToXapp = true
346 xapp.Logger.Debug("SendSubscriptionDeleteReq. subId = %v", subId)
347 c.SendSubscriptionDeleteReq(subs)
348 }
Anssi Mannilac92b4212020-12-07 14:59:34 +0200349 }
350 }
Juha Hyttinen5f8ffa02020-02-06 15:28:59 +0200351}
352
353func (c *Control) ReadyCB(data interface{}) {
Juha Hyttinen9dc5adc2020-08-13 10:02:40 +0300354 if c.RMRClient == nil {
355 c.RMRClient = xapp.Rmr
Juha Hyttinenff8dccd2019-12-10 14:34:07 +0200356 }
kalnagy45114752019-06-18 14:40:39 +0200357}
358
359func (c *Control) Run() {
Juha Hyttinen5f8ffa02020-02-06 15:28:59 +0200360 xapp.SetReadyCB(c.ReadyCB, nil)
Anssi Mannilaf6b78042021-02-18 12:36:59 +0200361 xapp.AddConfigChangeListener(c.ReadConfigParameters)
Peter Szilagyifbc56f92019-07-23 19:29:46 +0000362 xapp.Run(c)
kalnagy45114752019-06-18 14:40:39 +0200363}
364
Juha Hyttinenc9eb08a2020-02-28 08:53:33 +0200365//-------------------------------------------------------------------
366//
367//-------------------------------------------------------------------
Anssi Mannila92c38552021-12-29 09:59:24 +0200368func (c *Control) GetOrCreateRestSubscription(p *models.SubscriptionParams, md5sum string, xAppRmrEndpoint string, xAppServiceName string) (*RESTSubscription, string, error) {
Markku Virtanen42723e22021-06-15 10:09:23 +0300369
370 var restSubId string
371 var restSubscription *RESTSubscription
372 var err error
373
Anssi Mannila3cdd2e02021-10-14 12:35:41 +0300374 prevRestSubsId, exists := c.restDuplicateCtrl.GetLastKnownRestSubsIdBasedOnMd5sum(md5sum)
Markku Virtanen42723e22021-06-15 10:09:23 +0300375 if p.SubscriptionID == "" {
Anssi Mannilaf682ace2021-09-28 13:11:25 +0300376 // Subscription does not contain REST subscription Id
Markku Virtanen42723e22021-06-15 10:09:23 +0300377 if exists {
378 restSubscription, err = c.registry.GetRESTSubscription(prevRestSubsId, false)
379 if restSubscription != nil {
Anssi Mannilaf682ace2021-09-28 13:11:25 +0300380 // Subscription not found
Markku Virtanen42723e22021-06-15 10:09:23 +0300381 restSubId = prevRestSubsId
382 if err == nil {
Anssi Mannilaf682ace2021-09-28 13:11:25 +0300383 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 +0300384 } else {
Anssi Mannilaf682ace2021-09-28 13:11:25 +0300385 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 +0300386 }
387 } else {
Anssi Mannilaf682ace2021-09-28 13:11:25 +0300388 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 +0300389 c.restDuplicateCtrl.DeleteLastKnownRestSubsIdBasedOnMd5sum(md5sum)
Markku Virtanen42723e22021-06-15 10:09:23 +0300390 }
391 }
392
393 if restSubscription == nil {
394 restSubId = ksuid.New().String()
Anssi Mannila92c38552021-12-29 09:59:24 +0200395 restSubscription = c.registry.CreateRESTSubscription(&restSubId, &xAppServiceName, &xAppRmrEndpoint, p.Meid)
Markku Virtanen42723e22021-06-15 10:09:23 +0300396 }
397 } else {
Anssi Mannilaf682ace2021-09-28 13:11:25 +0300398 // Subscription contains REST subscription Id
Markku Virtanen42723e22021-06-15 10:09:23 +0300399 restSubId = p.SubscriptionID
400
Anssi Mannilaf682ace2021-09-28 13:11:25 +0300401 xapp.Logger.Debug("RestSubscription ID %s provided via REST request", restSubId)
Markku Virtanen42723e22021-06-15 10:09:23 +0300402 restSubscription, err = c.registry.GetRESTSubscription(restSubId, false)
403 if err != nil {
Anssi Mannilaf682ace2021-09-28 13:11:25 +0300404 // Subscription with id in REST request does not exist
Markku Virtanen42723e22021-06-15 10:09:23 +0300405 xapp.Logger.Error("%s", err.Error())
406 c.UpdateCounter(cRestSubFailToXapp)
Anssi Mannilacb7dd492021-10-01 11:10:26 +0300407 return nil, "", err
Markku Virtanen42723e22021-06-15 10:09:23 +0300408 }
409
410 if !exists {
Anssi Mannilaf682ace2021-09-28 13:11:25 +0300411 xapp.Logger.Debug("Existing restSubscription found for ID %s, new request based on md5sum", restSubId)
Markku Virtanen42723e22021-06-15 10:09:23 +0300412 } else {
Anssi Mannilaf682ace2021-09-28 13:11:25 +0300413 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 +0300414 }
415 }
416
Anssi Mannilacb7dd492021-10-01 11:10:26 +0300417 return restSubscription, restSubId, nil
Markku Virtanen42723e22021-06-15 10:09:23 +0300418}
419
420//-------------------------------------------------------------------
421//
422//-------------------------------------------------------------------
Anssi Mannilaf682ace2021-09-28 13:11:25 +0300423func (c *Control) RESTSubscriptionHandler(params interface{}) (*models.SubscriptionResponse, int) {
archaggeafbf95f2021-04-14 08:54:05 +0300424
Anssi Mannila316d8a12021-06-02 11:08:54 +0300425 c.CntRecvMsg++
426 c.UpdateCounter(cRestSubReqFromXapp)
427
archaggeafbf95f2021-04-14 08:54:05 +0300428 subResp := models.SubscriptionResponse{}
archaggeafbf95f2021-04-14 08:54:05 +0300429 p := params.(*models.SubscriptionParams)
430
Anssi Mannilade457a12021-06-02 16:19:48 +0300431 if c.LoggerLevel > 2 {
432 c.PrintRESTSubscriptionRequest(p)
433 }
434
Anssi Mannilac7da4ee2021-10-22 09:52:02 +0300435 if c.e2IfState.IsE2ConnectionUp(p.Meid) == false {
436 xapp.Logger.Error("No E2 connection for ranName %v", *p.Meid)
437 c.UpdateCounter(cRestReqRejDueE2Down)
438 return nil, common.SubscribeServiceUnavailableCode
439 }
440
archaggeafbf95f2021-04-14 08:54:05 +0300441 if p.ClientEndpoint == nil {
Anssi Mannilaf682ace2021-09-28 13:11:25 +0300442 err := fmt.Errorf("ClientEndpoint == nil")
443 xapp.Logger.Error("%v", err)
Anssi Mannila316d8a12021-06-02 11:08:54 +0300444 c.UpdateCounter(cRestSubFailToXapp)
Anssi Mannilacb7dd492021-10-01 11:10:26 +0300445 return nil, common.SubscribeBadRequestCode
archaggeafbf95f2021-04-14 08:54:05 +0300446 }
447
448 _, xAppRmrEndpoint, err := ConstructEndpointAddresses(*p.ClientEndpoint)
449 if err != nil {
450 xapp.Logger.Error("%s", err.Error())
Anssi Mannila316d8a12021-06-02 11:08:54 +0300451 c.UpdateCounter(cRestSubFailToXapp)
Anssi Mannilacb7dd492021-10-01 11:10:26 +0300452 return nil, common.SubscribeBadRequestCode
archaggeafbf95f2021-04-14 08:54:05 +0300453 }
454
Markku Virtanen42723e22021-06-15 10:09:23 +0300455 md5sum, err := CalculateRequestMd5sum(params)
456 if err != nil {
457 xapp.Logger.Error("Failed to generate md5sum from incoming request - %s", err.Error())
458 }
459
Anssi Mannila92c38552021-12-29 09:59:24 +0200460 restSubscription, restSubId, err := c.GetOrCreateRestSubscription(p, md5sum, xAppRmrEndpoint, p.ClientEndpoint.Host)
Markku Virtanen42723e22021-06-15 10:09:23 +0300461 if err != nil {
Anssi Mannilacb7dd492021-10-01 11:10:26 +0300462 xapp.Logger.Error("Subscription with id in REST request does not exist")
463 return nil, common.SubscribeNotFoundCode
archaggeafbf95f2021-04-14 08:54:05 +0300464 }
465
Konstantinos Archangelofe93b00f2021-06-03 10:00:19 +0000466 subResp.SubscriptionID = &restSubId
archaggeafbf95f2021-04-14 08:54:05 +0300467 subReqList := e2ap.SubscriptionRequestList{}
468 err = c.e2ap.FillSubscriptionReqMsgs(params, &subReqList, restSubscription)
469 if err != nil {
470 xapp.Logger.Error("%s", err.Error())
Anssi Mannila3cdd2e02021-10-14 12:35:41 +0300471 c.restDuplicateCtrl.DeleteLastKnownRestSubsIdBasedOnMd5sum(md5sum)
archaggeafbf95f2021-04-14 08:54:05 +0300472 c.registry.DeleteRESTSubscription(&restSubId)
Anssi Mannila316d8a12021-06-02 11:08:54 +0300473 c.UpdateCounter(cRestSubFailToXapp)
Anssi Mannilacb7dd492021-10-01 11:10:26 +0300474 return nil, common.SubscribeBadRequestCode
archaggeafbf95f2021-04-14 08:54:05 +0300475 }
476
Anssi Mannila3cdd2e02021-10-14 12:35:41 +0300477 duplicate := c.restDuplicateCtrl.IsDuplicateToOngoingTransaction(restSubId, md5sum)
Markku Virtanen42723e22021-06-15 10:09:23 +0300478 if duplicate {
Anssi Mannilaf682ace2021-09-28 13:11:25 +0300479 err := fmt.Errorf("Retransmission blocker direct ACK for request of restSubsId %s restSubId MD5sum %s as retransmission", restSubId, md5sum)
480 xapp.Logger.Debug("%s", err)
Anssi Mannilab43397e2021-11-16 12:06:16 +0200481 c.registry.DeleteRESTSubscription(&restSubId)
Markku Virtanen42723e22021-06-15 10:09:23 +0300482 c.UpdateCounter(cRestSubRespToXapp)
Anssi Mannilaf682ace2021-09-28 13:11:25 +0300483 return &subResp, common.SubscribeCreatedCode
Markku Virtanenb642a192021-06-09 09:08:14 +0000484 }
485
Markku Virtanencd73ecc2021-06-23 06:16:01 +0000486 c.WriteRESTSubscriptionToDb(restSubId, restSubscription)
Anssi Mannilaf682ace2021-09-28 13:11:25 +0300487 e2SubscriptionDirectives, err := c.GetE2SubscriptionDirectives(p)
488 if err != nil {
489 xapp.Logger.Error("%s", err)
Anssi Mannilab43397e2021-11-16 12:06:16 +0200490 c.registry.DeleteRESTSubscription(&restSubId)
Anssi Mannilacb7dd492021-10-01 11:10:26 +0300491 return nil, common.SubscribeBadRequestCode
Anssi Mannilaf682ace2021-09-28 13:11:25 +0300492 }
493 go c.processSubscriptionRequests(restSubscription, &subReqList, p.ClientEndpoint, p.Meid, &restSubId, xAppRmrEndpoint, md5sum, e2SubscriptionDirectives)
archaggeafbf95f2021-04-14 08:54:05 +0300494
Anssi Mannila316d8a12021-06-02 11:08:54 +0300495 c.UpdateCounter(cRestSubRespToXapp)
Anssi Mannilaf682ace2021-09-28 13:11:25 +0300496 return &subResp, common.SubscribeCreatedCode
497}
498
499//-------------------------------------------------------------------
500//
501//-------------------------------------------------------------------
502func (c *Control) GetE2SubscriptionDirectives(p *models.SubscriptionParams) (*E2SubscriptionDirectives, error) {
503
504 e2SubscriptionDirectives := &E2SubscriptionDirectives{}
505 if p == nil || p.E2SubscriptionDirectives == nil {
506 e2SubscriptionDirectives.E2TimeoutTimerValue = e2tSubReqTimeout
507 e2SubscriptionDirectives.E2MaxTryCount = int64(e2tMaxSubReqTryCount)
508 e2SubscriptionDirectives.CreateRMRRoute = true
509 xapp.Logger.Debug("p == nil || p.E2SubscriptionDirectives == nil. Using default values for E2TimeoutTimerValue = %v and E2RetryCount = %v RMRRoutingNeeded = true", e2tSubReqTimeout, e2tMaxSubReqTryCount)
510 } else {
511 if p.E2SubscriptionDirectives.E2TimeoutTimerValue >= 1 && p.E2SubscriptionDirectives.E2TimeoutTimerValue <= 10 {
512 e2SubscriptionDirectives.E2TimeoutTimerValue = time.Duration(p.E2SubscriptionDirectives.E2TimeoutTimerValue) * 1000000000 // Duration type cast returns nano seconds
513 } else {
514 return nil, fmt.Errorf("p.E2SubscriptionDirectives.E2TimeoutTimerValue out of range (1-10 seconds): %v", p.E2SubscriptionDirectives.E2TimeoutTimerValue)
515 }
516 if p.E2SubscriptionDirectives.E2RetryCount == nil {
517 xapp.Logger.Error("p.E2SubscriptionDirectives.E2RetryCount == nil. Using default value")
518 e2SubscriptionDirectives.E2MaxTryCount = int64(e2tMaxSubReqTryCount)
519 } else {
520 if *p.E2SubscriptionDirectives.E2RetryCount >= 0 && *p.E2SubscriptionDirectives.E2RetryCount <= 10 {
521 e2SubscriptionDirectives.E2MaxTryCount = *p.E2SubscriptionDirectives.E2RetryCount + 1 // E2MaxTryCount = First sending plus two retries
522 } else {
523 return nil, fmt.Errorf("p.E2SubscriptionDirectives.E2RetryCount out of range (0-10): %v", *p.E2SubscriptionDirectives.E2RetryCount)
524 }
525 }
Anssi Mannilacb7dd492021-10-01 11:10:26 +0300526 e2SubscriptionDirectives.CreateRMRRoute = p.E2SubscriptionDirectives.RMRRoutingNeeded
Anssi Mannilaf682ace2021-09-28 13:11:25 +0300527 }
528 xapp.Logger.Debug("e2SubscriptionDirectives.E2TimeoutTimerValue: %v", e2SubscriptionDirectives.E2TimeoutTimerValue)
529 xapp.Logger.Debug("e2SubscriptionDirectives.E2MaxTryCount: %v", e2SubscriptionDirectives.E2MaxTryCount)
530 xapp.Logger.Debug("e2SubscriptionDirectives.CreateRMRRoute: %v", e2SubscriptionDirectives.CreateRMRRoute)
531 return e2SubscriptionDirectives, nil
532}
533
534//-------------------------------------------------------------------
535//
536//-------------------------------------------------------------------
archaggeafbf95f2021-04-14 08:54:05 +0300537
538func (c *Control) processSubscriptionRequests(restSubscription *RESTSubscription, subReqList *e2ap.SubscriptionRequestList,
Anssi Mannilaf682ace2021-09-28 13:11:25 +0300539 clientEndpoint *models.SubscriptionParamsClientEndpoint, meid *string, restSubId *string, xAppRmrEndpoint string, md5sum string, e2SubscriptionDirectives *E2SubscriptionDirectives) {
archaggeafbf95f2021-04-14 08:54:05 +0300540
Anssi Mannila08c8fbd2021-10-05 12:47:41 +0300541 c.SubscriptionProcessingStartDelay()
Anssi Mannila54838ed2021-11-19 11:25:01 +0200542 xapp.Logger.Debug("E2 SubscriptionRequest count = %v ", len(subReqList.E2APSubscriptionRequests))
archaggeafbf95f2021-04-14 08:54:05 +0300543
Konstantinos Archangelofe93b00f2021-06-03 10:00:19 +0000544 var xAppEventInstanceID int64
545 var e2EventInstanceID int64
Anssi Mannilaf682ace2021-09-28 13:11:25 +0300546 errorInfo := &ErrorInfo{}
Markku Virtanenb642a192021-06-09 09:08:14 +0000547
Anssi Mannila3cdd2e02021-10-14 12:35:41 +0300548 defer c.restDuplicateCtrl.SetMd5sumFromLastOkRequest(*restSubId, md5sum)
Markku Virtanenb642a192021-06-09 09:08:14 +0000549
archaggeafbf95f2021-04-14 08:54:05 +0300550 for index := 0; index < len(subReqList.E2APSubscriptionRequests); index++ {
551 subReqMsg := subReqList.E2APSubscriptionRequests[index]
Markku Virtanenb642a192021-06-09 09:08:14 +0000552 xAppEventInstanceID = (int64)(subReqMsg.RequestId.Id)
archaggeafbf95f2021-04-14 08:54:05 +0300553
Konstantinos Archangelofe93b00f2021-06-03 10:00:19 +0000554 trans := c.tracker.NewXappTransaction(xapp.NewRmrEndpoint(xAppRmrEndpoint), *restSubId, subReqMsg.RequestId, &xapp.RMRMeid{RanName: *meid})
archaggeafbf95f2021-04-14 08:54:05 +0300555 if trans == nil {
Markku Virtanenb642a192021-06-09 09:08:14 +0000556 // Send notification to xApp that prosessing of a Subscription Request has failed.
557 err := fmt.Errorf("Tracking failure")
Anssi Mannilaf682ace2021-09-28 13:11:25 +0300558 errorInfo.ErrorCause = err.Error()
559 c.sendUnsuccesfullResponseNotification(restSubId, restSubscription, xAppEventInstanceID, err, clientEndpoint, trans, errorInfo)
Markku Virtanenb642a192021-06-09 09:08:14 +0000560 continue
archaggeafbf95f2021-04-14 08:54:05 +0300561 }
562
Anssi Mannilaf682ace2021-09-28 13:11:25 +0300563 xapp.Logger.Debug("Handle SubscriptionRequest index=%v, %s", index, idstring(nil, trans))
Markku Virtanenb642a192021-06-09 09:08:14 +0000564
Anssi Mannilaf682ace2021-09-28 13:11:25 +0300565 subRespMsg, errorInfo, err := c.handleSubscriptionRequest(trans, &subReqMsg, meid, *restSubId, e2SubscriptionDirectives)
Markku Virtanen42723e22021-06-15 10:09:23 +0300566
Anssi Mannilaf682ace2021-09-28 13:11:25 +0300567 xapp.Logger.Debug("Handled SubscriptionRequest index=%v, %s", index, idstring(nil, trans))
Anssi Mannila53dbe7e2021-10-06 14:21:48 +0300568 trans.Release()
Markku Virtanen42723e22021-06-15 10:09:23 +0300569
archaggeafbf95f2021-04-14 08:54:05 +0300570 if err != nil {
Anssi Mannila54838ed2021-11-19 11:25:01 +0200571 if err.Error() == "TEST: restart event received" {
572 // This is just for UT cases. Stop here subscription processing
573 return
574 }
Anssi Mannilaf682ace2021-09-28 13:11:25 +0300575 c.sendUnsuccesfullResponseNotification(restSubId, restSubscription, xAppEventInstanceID, err, clientEndpoint, trans, errorInfo)
archaggeafbf95f2021-04-14 08:54:05 +0300576 } else {
Konstantinos Archangelofe93b00f2021-06-03 10:00:19 +0000577 e2EventInstanceID = (int64)(subRespMsg.RequestId.InstanceId)
Markku Virtanen42723e22021-06-15 10:09:23 +0300578 restSubscription.AddMd5Sum(md5sum)
Anssi Mannilaf682ace2021-09-28 13:11:25 +0300579 xapp.Logger.Debug("SubscriptionRequest index=%v processed successfullyfor %s. endpoint=%v:%v, XappEventInstanceID=%v, E2EventInstanceID=%v, %s",
Markku Virtanen42723e22021-06-15 10:09:23 +0300580 index, *restSubId, clientEndpoint.Host, *clientEndpoint.HTTPPort, xAppEventInstanceID, e2EventInstanceID, idstring(nil, trans))
Anssi Mannila56233b02022-01-24 13:26:42 +0200581 c.sendSuccesfullResponseNotification(restSubId, restSubscription, xAppEventInstanceID, e2EventInstanceID, clientEndpoint, trans, errorInfo)
archaggeafbf95f2021-04-14 08:54:05 +0300582 }
archaggeafbf95f2021-04-14 08:54:05 +0300583 }
584}
585
586//-------------------------------------------------------------------
587//
588//------------------------------------------------------------------
Anssi Mannila08c8fbd2021-10-05 12:47:41 +0300589func (c *Control) SubscriptionProcessingStartDelay() {
590 if c.UTTesting == true {
591 // This is temporary fix for the UT problem that notification arrives before subscription response
592 // Correct fix would be to allow notification come before response and process it correctly
593 xapp.Logger.Debug("Setting 50 ms delay before starting processing Subscriptions")
594 <-time.After(time.Millisecond * 50)
595 xapp.Logger.Debug("Continuing after delay")
596 }
597}
598
599//-------------------------------------------------------------------
600//
601//------------------------------------------------------------------
archaggeafbf95f2021-04-14 08:54:05 +0300602func (c *Control) handleSubscriptionRequest(trans *TransactionXapp, subReqMsg *e2ap.E2APSubscriptionRequest, meid *string,
Anssi Mannilaf682ace2021-09-28 13:11:25 +0300603 restSubId string, e2SubscriptionDirectives *E2SubscriptionDirectives) (*e2ap.E2APSubscriptionResponse, *ErrorInfo, error) {
604
605 errorInfo := ErrorInfo{}
archaggeafbf95f2021-04-14 08:54:05 +0300606
607 err := c.tracker.Track(trans)
608 if err != nil {
Markku Virtanen55d2a282021-06-04 14:46:56 +0300609 xapp.Logger.Error("XAPP-SubReq Tracking error: %s", idstring(err, trans))
Anssi Mannilaf682ace2021-09-28 13:11:25 +0300610 errorInfo.ErrorCause = err.Error()
Markku Virtanen55d2a282021-06-04 14:46:56 +0300611 err = fmt.Errorf("Tracking failure")
Anssi Mannilaf682ace2021-09-28 13:11:25 +0300612 return nil, &errorInfo, err
archaggeafbf95f2021-04-14 08:54:05 +0300613 }
614
Anssi Mannilaf682ace2021-09-28 13:11:25 +0300615 subs, errorInfo, err := c.registry.AssignToSubscription(trans, subReqMsg, c.ResetTestFlag, c, e2SubscriptionDirectives.CreateRMRRoute)
archaggeafbf95f2021-04-14 08:54:05 +0300616 if err != nil {
Markku Virtanen55d2a282021-06-04 14:46:56 +0300617 xapp.Logger.Error("XAPP-SubReq Assign error: %s", idstring(err, trans))
Anssi Mannilaf682ace2021-09-28 13:11:25 +0300618 return nil, &errorInfo, err
archaggeafbf95f2021-04-14 08:54:05 +0300619 }
620
621 //
622 // Wake subs request
623 //
Anssi Mannilac7da4ee2021-10-22 09:52:02 +0300624 subs.OngoingReqCount++
Anssi Mannila54838ed2021-11-19 11:25:01 +0200625 go c.handleSubscriptionCreate(subs, trans, e2SubscriptionDirectives, 0)
archaggeafbf95f2021-04-14 08:54:05 +0300626 event, _ := trans.WaitEvent(0) //blocked wait as timeout is handled in subs side
Anssi Mannilac7da4ee2021-10-22 09:52:02 +0300627 subs.OngoingReqCount--
archaggeafbf95f2021-04-14 08:54:05 +0300628
629 err = nil
630 if event != nil {
631 switch themsg := event.(type) {
632 case *e2ap.E2APSubscriptionResponse:
633 trans.Release()
Anssi Mannilac7da4ee2021-10-22 09:52:02 +0300634 if c.e2IfState.IsE2ConnectionUp(meid) == true {
Anssi Mannila56233b02022-01-24 13:26:42 +0200635 errorInfo = c.e2ap.CheckActionNotAdmittedList(xapp.RIC_SUB_RESP, themsg.ActionNotAdmittedList, c)
Anssi Mannilac7da4ee2021-10-22 09:52:02 +0300636 return themsg, &errorInfo, nil
637 } else {
638 c.registry.RemoveFromSubscription(subs, trans, waitRouteCleanup_ms, c)
639 c.RemoveSubscriptionFromDb(subs)
640 err = fmt.Errorf("E2 interface down")
641 errorInfo.SetInfo(err.Error(), models.SubscriptionInstanceErrorSourceE2Node, "")
Anssi Mannilac7da4ee2021-10-22 09:52:02 +0300642 }
archaggeafbf95f2021-04-14 08:54:05 +0300643 case *e2ap.E2APSubscriptionFailure:
Anssi Mannila483bd162022-01-20 11:11:48 +0200644 err = fmt.Errorf("RICSubscriptionFailure. E2NodeCause: (Cause:%v, Value %v)", themsg.Cause.Content, themsg.Cause.Value)
645 errorInfo.SetInfo(err.Error(), models.SubscriptionInstanceErrorSourceE2Node, "")
Anssi Mannilaf682ace2021-09-28 13:11:25 +0300646 case *PackSubscriptionRequestErrortEvent:
Anssi Mannila56233b02022-01-24 13:26:42 +0200647 err = fmt.Errorf("E2 RICSubscriptionRequest pack failure")
Anssi Mannilab43397e2021-11-16 12:06:16 +0200648 errorInfo = themsg.ErrorInfo
Anssi Mannilaf682ace2021-09-28 13:11:25 +0300649 case *SDLWriteErrortEvent:
650 err = fmt.Errorf("SDL write failure")
Anssi Mannilab43397e2021-11-16 12:06:16 +0200651 errorInfo = themsg.ErrorInfo
Anssi Mannila54838ed2021-11-19 11:25:01 +0200652 case *SubmgrRestartTestEvent:
653 err = fmt.Errorf("TEST: restart event received")
654 xapp.Logger.Debug("%s", err)
655 return nil, &errorInfo, err
archaggeafbf95f2021-04-14 08:54:05 +0300656 default:
Anssi Mannilaf682ace2021-09-28 13:11:25 +0300657 err = fmt.Errorf("Unexpected E2 subscription response received")
658 errorInfo.SetInfo(err.Error(), models.SubscriptionInstanceErrorSourceE2Node, "")
archaggeafbf95f2021-04-14 08:54:05 +0300659 break
660 }
Markku Virtanen55d2a282021-06-04 14:46:56 +0300661 } else {
Anssi Mannila3d80b722021-11-12 13:17:15 +0200662 // Timer expiry
Anssi Mannila56233b02022-01-24 13:26:42 +0200663 err = fmt.Errorf("E2 RICSubscriptionResponse timeout")
Anssi Mannilaf682ace2021-09-28 13:11:25 +0300664 errorInfo.SetInfo(err.Error(), "", models.SubscriptionInstanceTimeoutTypeE2Timeout)
665 if subs.PolicyUpdate == true {
666 return nil, &errorInfo, err
667 }
archaggeafbf95f2021-04-14 08:54:05 +0300668 }
Markku Virtanen55d2a282021-06-04 14:46:56 +0300669
670 xapp.Logger.Error("XAPP-SubReq E2 subscription failed %s", idstring(err, trans, subs))
Markku Virtanenfe2cdab2021-05-21 10:59:29 +0000671 c.registry.RemoveFromSubscription(subs, trans, waitRouteCleanup_ms, c)
Anssi Mannilaf682ace2021-09-28 13:11:25 +0300672 return nil, &errorInfo, err
archaggeafbf95f2021-04-14 08:54:05 +0300673}
674
675//-------------------------------------------------------------------
676//
677//-------------------------------------------------------------------
Markku Virtanen42723e22021-06-15 10:09:23 +0300678func (c *Control) sendUnsuccesfullResponseNotification(restSubId *string, restSubscription *RESTSubscription, xAppEventInstanceID int64, err error,
Anssi Mannilaf682ace2021-09-28 13:11:25 +0300679 clientEndpoint *models.SubscriptionParamsClientEndpoint, trans *TransactionXapp, errorInfo *ErrorInfo) {
Markku Virtanen42723e22021-06-15 10:09:23 +0300680
681 // Send notification to xApp that prosessing of a Subscription Request has failed.
682 e2EventInstanceID := (int64)(0)
Anssi Mannilaf682ace2021-09-28 13:11:25 +0300683 if errorInfo.ErrorSource == "" {
684 // Submgr is default source of error
685 errorInfo.ErrorSource = models.SubscriptionInstanceErrorSourceSUBMGR
686 }
Markku Virtanen42723e22021-06-15 10:09:23 +0300687 resp := &models.SubscriptionResponse{
688 SubscriptionID: restSubId,
689 SubscriptionInstances: []*models.SubscriptionInstance{
690 &models.SubscriptionInstance{E2EventInstanceID: &e2EventInstanceID,
Anssi Mannilacb7dd492021-10-01 11:10:26 +0300691 ErrorCause: errorInfo.ErrorCause,
692 ErrorSource: errorInfo.ErrorSource,
693 TimeoutType: errorInfo.TimeoutType,
Markku Virtanen42723e22021-06-15 10:09:23 +0300694 XappEventInstanceID: &xAppEventInstanceID},
695 },
696 }
697 // Mark REST subscription request processed.
698 restSubscription.SetProcessed(err)
699 c.UpdateRESTSubscriptionInDB(*restSubId, restSubscription, false)
700 if trans != nil {
Anssi Mannila56233b02022-01-24 13:26:42 +0200701 xapp.Logger.Debug("Sending unsuccessful REST notification (Error cause %s) to endpoint=%v:%v, XappEventInstanceID=%v, E2EventInstanceID=%v, %s",
Anssi Mannilaf682ace2021-09-28 13:11:25 +0300702 errorInfo.ErrorCause, clientEndpoint.Host, *clientEndpoint.HTTPPort, xAppEventInstanceID, e2EventInstanceID, idstring(nil, trans))
Markku Virtanen42723e22021-06-15 10:09:23 +0300703 } else {
Anssi Mannila56233b02022-01-24 13:26:42 +0200704 xapp.Logger.Debug("Sending unsuccessful REST notification (Error cause %s) to endpoint=%v:%v, XappEventInstanceID=%v, E2EventInstanceID=%v",
Anssi Mannilaf682ace2021-09-28 13:11:25 +0300705 errorInfo.ErrorCause, clientEndpoint.Host, *clientEndpoint.HTTPPort, xAppEventInstanceID, e2EventInstanceID)
Markku Virtanen42723e22021-06-15 10:09:23 +0300706 }
707
708 c.UpdateCounter(cRestSubFailNotifToXapp)
709 xapp.Subscription.Notify(resp, *clientEndpoint)
Anssi Mannilac7da4ee2021-10-22 09:52:02 +0300710
Anssi Mannilab43397e2021-11-16 12:06:16 +0200711 // E2 is down. Delete completely processed request safely now
Anssi Mannilac7da4ee2021-10-22 09:52:02 +0300712 if c.e2IfState.IsE2ConnectionUp(&restSubscription.Meid) == false && restSubscription.SubReqOngoing == false {
713 c.registry.DeleteRESTSubscription(restSubId)
714 c.RemoveRESTSubscriptionFromDb(*restSubId)
715 }
Markku Virtanen42723e22021-06-15 10:09:23 +0300716}
717
718//-------------------------------------------------------------------
719//
720//-------------------------------------------------------------------
721func (c *Control) sendSuccesfullResponseNotification(restSubId *string, restSubscription *RESTSubscription, xAppEventInstanceID int64, e2EventInstanceID int64,
Anssi Mannila56233b02022-01-24 13:26:42 +0200722 clientEndpoint *models.SubscriptionParamsClientEndpoint, trans *TransactionXapp, errorInfo *ErrorInfo) {
Markku Virtanen42723e22021-06-15 10:09:23 +0300723
724 // Store successfully processed InstanceId for deletion
725 restSubscription.AddE2InstanceId((uint32)(e2EventInstanceID))
726 restSubscription.AddXappIdToE2Id(xAppEventInstanceID, e2EventInstanceID)
727
728 // Send notification to xApp that a Subscription Request has been processed.
729 resp := &models.SubscriptionResponse{
730 SubscriptionID: restSubId,
731 SubscriptionInstances: []*models.SubscriptionInstance{
732 &models.SubscriptionInstance{E2EventInstanceID: &e2EventInstanceID,
Anssi Mannila56233b02022-01-24 13:26:42 +0200733 ErrorCause: errorInfo.ErrorCause,
734 ErrorSource: errorInfo.ErrorSource,
Markku Virtanen42723e22021-06-15 10:09:23 +0300735 XappEventInstanceID: &xAppEventInstanceID},
736 },
737 }
738 // Mark REST subscription request processesd.
739 restSubscription.SetProcessed(nil)
740 c.UpdateRESTSubscriptionInDB(*restSubId, restSubscription, false)
Anssi Mannila56233b02022-01-24 13:26:42 +0200741 if errorInfo.ErrorCause != " " {
742 xapp.Logger.Debug("Sending successful REST notification (Error cause %s) to endpoint=%v:%v, XappEventInstanceID=%v, E2EventInstanceID=%v, %s",
743 errorInfo.ErrorCause, clientEndpoint.Host, *clientEndpoint.HTTPPort, xAppEventInstanceID, e2EventInstanceID, idstring(nil, trans))
744 } else {
745 xapp.Logger.Debug("Sending successful REST notification to endpoint=%v:%v, XappEventInstanceID=%v, E2EventInstanceID=%v, %s",
746 clientEndpoint.Host, *clientEndpoint.HTTPPort, xAppEventInstanceID, e2EventInstanceID, idstring(nil, trans))
747 }
Markku Virtanen42723e22021-06-15 10:09:23 +0300748 c.UpdateCounter(cRestSubNotifToXapp)
749 xapp.Subscription.Notify(resp, *clientEndpoint)
Anssi Mannilac7da4ee2021-10-22 09:52:02 +0300750
Anssi Mannilab43397e2021-11-16 12:06:16 +0200751 // E2 is down. Delete completely processed request safely now
Anssi Mannilac7da4ee2021-10-22 09:52:02 +0300752 if c.e2IfState.IsE2ConnectionUp(&restSubscription.Meid) == false && restSubscription.SubReqOngoing == false {
753 c.registry.DeleteRESTSubscription(restSubId)
754 c.RemoveRESTSubscriptionFromDb(*restSubId)
755 }
Markku Virtanen42723e22021-06-15 10:09:23 +0300756}
757
758//-------------------------------------------------------------------
759//
760//-------------------------------------------------------------------
Anssi Mannilaf682ace2021-09-28 13:11:25 +0300761func (c *Control) RESTSubscriptionDeleteHandler(restSubId string) int {
archaggeafbf95f2021-04-14 08:54:05 +0300762
763 c.CntRecvMsg++
Konstantinos Archangelof27433e72021-05-31 08:30:35 +0000764 c.UpdateCounter(cRestSubDelReqFromXapp)
archaggeafbf95f2021-04-14 08:54:05 +0300765
Anssi Mannilaf682ace2021-09-28 13:11:25 +0300766 xapp.Logger.Debug("SubscriptionDeleteRequest from XAPP")
archaggeafbf95f2021-04-14 08:54:05 +0300767
Konstantinos Archangelofe93b00f2021-06-03 10:00:19 +0000768 restSubscription, err := c.registry.GetRESTSubscription(restSubId, true)
archaggeafbf95f2021-04-14 08:54:05 +0300769 if err != nil {
770 xapp.Logger.Error("%s", err.Error())
771 if restSubscription == nil {
772 // Subscription was not found
Anssi Mannilac7da4ee2021-10-22 09:52:02 +0300773 c.UpdateCounter(cRestSubDelRespToXapp)
Anssi Mannilaf682ace2021-09-28 13:11:25 +0300774 return common.UnsubscribeNoContentCode
archaggeafbf95f2021-04-14 08:54:05 +0300775 } else {
776 if restSubscription.SubReqOngoing == true {
777 err := fmt.Errorf("Handling of the REST Subscription Request still ongoing %s", restSubId)
778 xapp.Logger.Error("%s", err.Error())
Anssi Mannilac7da4ee2021-10-22 09:52:02 +0300779 c.UpdateCounter(cRestSubDelFailToXapp)
Anssi Mannilaf682ace2021-09-28 13:11:25 +0300780 return common.UnsubscribeBadRequestCode
archaggeafbf95f2021-04-14 08:54:05 +0300781 } else if restSubscription.SubDelReqOngoing == true {
782 // Previous request for same restSubId still ongoing
Anssi Mannila3d80b722021-11-12 13:17:15 +0200783 c.UpdateCounter(cRestSubDelRespToXapp)
784 return common.UnsubscribeNoContentCode
archaggeafbf95f2021-04-14 08:54:05 +0300785 }
786 }
787 }
788
789 xAppRmrEndPoint := restSubscription.xAppRmrEndPoint
790 go func() {
Anssi Mannilaf682ace2021-09-28 13:11:25 +0300791 xapp.Logger.Debug("Deleteting handler: processing instances = %v", restSubscription.InstanceIds)
archaggeafbf95f2021-04-14 08:54:05 +0300792 for _, instanceId := range restSubscription.InstanceIds {
Anssi Mannila54838ed2021-11-19 11:25:01 +0200793 xAppEventInstanceID, err := c.SubscriptionDeleteHandler(&restSubId, &xAppRmrEndPoint, &restSubscription.Meid, instanceId, 0)
Konstantinos Archangelofe93b00f2021-06-03 10:00:19 +0000794
archaggeafbf95f2021-04-14 08:54:05 +0300795 if err != nil {
796 xapp.Logger.Error("%s", err.Error())
archaggeafbf95f2021-04-14 08:54:05 +0300797 }
Anssi Mannilaf682ace2021-09-28 13:11:25 +0300798 xapp.Logger.Debug("Deleteting instanceId = %v", instanceId)
Konstantinos Archangelofe93b00f2021-06-03 10:00:19 +0000799 restSubscription.DeleteXappIdToE2Id(xAppEventInstanceID)
800 restSubscription.DeleteE2InstanceId(instanceId)
archaggeafbf95f2021-04-14 08:54:05 +0300801 }
Anssi Mannila3cdd2e02021-10-14 12:35:41 +0300802 c.restDuplicateCtrl.DeleteLastKnownRestSubsIdBasedOnMd5sum(restSubscription.lastReqMd5sum)
archaggeafbf95f2021-04-14 08:54:05 +0300803 c.registry.DeleteRESTSubscription(&restSubId)
Konstantinos Archangelof268d7152021-06-14 12:24:00 +0300804 c.RemoveRESTSubscriptionFromDb(restSubId)
archaggeafbf95f2021-04-14 08:54:05 +0300805 }()
806
Konstantinos Archangelof27433e72021-05-31 08:30:35 +0000807 c.UpdateCounter(cRestSubDelRespToXapp)
Anssi Mannilaf682ace2021-09-28 13:11:25 +0300808 return common.UnsubscribeNoContentCode
Juha Hyttinenc9eb08a2020-02-28 08:53:33 +0200809}
810
archaggeafbf95f2021-04-14 08:54:05 +0300811//-------------------------------------------------------------------
812//
813//-------------------------------------------------------------------
Anssi Mannila54838ed2021-11-19 11:25:01 +0200814func (c *Control) SubscriptionDeleteHandler(restSubId *string, endPoint *string, meid *string, instanceId uint32, waitRouteCleanupTime time.Duration) (int64, error) {
archaggeafbf95f2021-04-14 08:54:05 +0300815
Konstantinos Archangelofe93b00f2021-06-03 10:00:19 +0000816 var xAppEventInstanceID int64
817 subs, err := c.registry.GetSubscriptionFirstMatch([]uint32{instanceId})
818 if err != nil {
Anssi Mannilaf682ace2021-09-28 13:11:25 +0300819 xapp.Logger.Debug("Subscription Delete Handler subscription for restSubId=%v, E2EventInstanceID=%v not found %s",
Konstantinos Archangelofe93b00f2021-06-03 10:00:19 +0000820 restSubId, instanceId, idstring(err, nil))
821 return xAppEventInstanceID, nil
822 }
823
824 xAppEventInstanceID = int64(subs.ReqId.Id)
825 trans := c.tracker.NewXappTransaction(xapp.NewRmrEndpoint(*endPoint), *restSubId, e2ap.RequestId{subs.ReqId.Id, 0}, &xapp.RMRMeid{RanName: *meid})
archaggeafbf95f2021-04-14 08:54:05 +0300826 if trans == nil {
827 err := fmt.Errorf("XAPP-SubDelReq transaction not created. restSubId %s, endPoint %s, meid %s, instanceId %v", *restSubId, *endPoint, *meid, instanceId)
828 xapp.Logger.Error("%s", err.Error())
829 }
830 defer trans.Release()
831
Konstantinos Archangelofe93b00f2021-06-03 10:00:19 +0000832 err = c.tracker.Track(trans)
archaggeafbf95f2021-04-14 08:54:05 +0300833 if err != nil {
834 err := fmt.Errorf("XAPP-SubDelReq %s:", idstring(err, trans))
835 xapp.Logger.Error("%s", err.Error())
Konstantinos Archangelofe93b00f2021-06-03 10:00:19 +0000836 return xAppEventInstanceID, &time.ParseError{}
archaggeafbf95f2021-04-14 08:54:05 +0300837 }
838 //
839 // Wake subs delete
840 //
Anssi Mannilac7da4ee2021-10-22 09:52:02 +0300841 subs.OngoingDelCount++
Anssi Mannila54838ed2021-11-19 11:25:01 +0200842 go c.handleSubscriptionDelete(subs, trans, waitRouteCleanupTime)
archaggeafbf95f2021-04-14 08:54:05 +0300843 trans.WaitEvent(0) //blocked wait as timeout is handled in subs side
Anssi Mannilac7da4ee2021-10-22 09:52:02 +0300844 subs.OngoingDelCount--
archaggeafbf95f2021-04-14 08:54:05 +0300845
846 xapp.Logger.Debug("XAPP-SubDelReq: Handling event %s ", idstring(nil, trans, subs))
847
Markku Virtanenfe2cdab2021-05-21 10:59:29 +0000848 c.registry.RemoveFromSubscription(subs, trans, waitRouteCleanup_ms, c)
archaggeafbf95f2021-04-14 08:54:05 +0300849
Konstantinos Archangelofe93b00f2021-06-03 10:00:19 +0000850 return xAppEventInstanceID, nil
archaggeafbf95f2021-04-14 08:54:05 +0300851}
852
853//-------------------------------------------------------------------
854//
855//-------------------------------------------------------------------
Juha Hyttinenc9eb08a2020-02-28 08:53:33 +0200856
Juha Hyttinen83ada002020-01-30 10:36:33 +0200857func (c *Control) rmrSendToE2T(desc string, subs *Subscription, trans *TransactionSubs) (err error) {
Juha Hyttinen9dc5adc2020-08-13 10:02:40 +0300858 params := &xapp.RMRParams{}
Juha Hyttinene406a342020-01-13 13:02:26 +0200859 params.Mtype = trans.GetMtype()
Juha Hyttinenaada6452020-04-07 08:47:58 +0300860 params.SubId = int(subs.GetReqId().InstanceId)
Juha Hyttinen86a46202020-01-14 12:49:09 +0200861 params.Xid = ""
Juha Hyttinene406a342020-01-13 13:02:26 +0200862 params.Meid = subs.GetMeid()
863 params.Src = ""
Juha Hyttinen63284a22020-01-15 10:45:11 +0200864 params.PayloadLen = len(trans.Payload.Buf)
865 params.Payload = trans.Payload.Buf
Juha Hyttinene406a342020-01-13 13:02:26 +0200866 params.Mbuf = nil
Anssi Mannilaf682ace2021-09-28 13:11:25 +0300867 xapp.Logger.Debug("MSG to E2T: %s %s %s", desc, trans.String(), params.String())
Abukar Mohamedfbd4df52021-03-11 06:13:27 +0000868 err = c.SendWithRetry(params, false, 5)
869 if err != nil {
870 xapp.Logger.Error("rmrSendToE2T: Send failed: %+v", err)
871 }
872 return err
kalnagye0018682019-09-26 16:28:25 +0200873}
874
Juha Hyttinen83ada002020-01-30 10:36:33 +0200875func (c *Control) rmrSendToXapp(desc string, subs *Subscription, trans *TransactionXapp) (err error) {
876
Juha Hyttinen9dc5adc2020-08-13 10:02:40 +0300877 params := &xapp.RMRParams{}
Juha Hyttinen63284a22020-01-15 10:45:11 +0200878 params.Mtype = trans.GetMtype()
Juha Hyttinenaada6452020-04-07 08:47:58 +0300879 params.SubId = int(subs.GetReqId().InstanceId)
Juha Hyttinene406a342020-01-13 13:02:26 +0200880 params.Xid = trans.GetXid()
Juha Hyttinen86a46202020-01-14 12:49:09 +0200881 params.Meid = trans.GetMeid()
Juha Hyttinene406a342020-01-13 13:02:26 +0200882 params.Src = ""
Juha Hyttinen63284a22020-01-15 10:45:11 +0200883 params.PayloadLen = len(trans.Payload.Buf)
884 params.Payload = trans.Payload.Buf
Juha Hyttinene406a342020-01-13 13:02:26 +0200885 params.Mbuf = nil
Anssi Mannilaf682ace2021-09-28 13:11:25 +0300886 xapp.Logger.Debug("MSG to XAPP: %s %s %s", desc, trans.String(), params.String())
Abukar Mohamedfbd4df52021-03-11 06:13:27 +0000887 err = c.SendWithRetry(params, false, 5)
888 if err != nil {
889 xapp.Logger.Error("rmrSendToXapp: Send failed: %+v", err)
890 }
891 return err
Juha Hyttinene406a342020-01-13 13:02:26 +0200892}
893
Juha Hyttinen9dc5adc2020-08-13 10:02:40 +0300894func (c *Control) Consume(msg *xapp.RMRParams) (err error) {
895 if c.RMRClient == nil {
Juha Hyttinen5f8ffa02020-02-06 15:28:59 +0200896 err = fmt.Errorf("Rmr object nil can handle %s", msg.String())
897 xapp.Logger.Error("%s", err.Error())
898 return
899 }
900 c.CntRecvMsg++
901
Juha Hyttinen9dc5adc2020-08-13 10:02:40 +0300902 defer c.RMRClient.Free(msg.Mbuf)
Juha Hyttinen83ada002020-01-30 10:36:33 +0200903
Juha Hyttinena8a908d2020-05-26 15:12:47 +0300904 // xapp-frame might use direct access to c buffer and
905 // when msg.Mbuf is freed, someone might take it into use
906 // and payload data might be invalid inside message handle function
907 //
908 // subscriptions won't load system a lot so there is no
909 // real performance hit by cloning buffer into new go byte slice
910 cPay := append(msg.Payload[:0:0], msg.Payload...)
911 msg.Payload = cPay
912 msg.PayloadLen = len(cPay)
913
Anssi Mannila90fa0212019-12-12 10:47:47 +0200914 switch msg.Mtype {
Juha Hyttinenc9eb08a2020-02-28 08:53:33 +0200915 case xapp.RIC_SUB_REQ:
Juha Hyttinen422d0182020-01-17 13:37:05 +0200916 go c.handleXAPPSubscriptionRequest(msg)
Juha Hyttinenc9eb08a2020-02-28 08:53:33 +0200917 case xapp.RIC_SUB_RESP:
Juha Hyttinen422d0182020-01-17 13:37:05 +0200918 go c.handleE2TSubscriptionResponse(msg)
Juha Hyttinenc9eb08a2020-02-28 08:53:33 +0200919 case xapp.RIC_SUB_FAILURE:
Juha Hyttinen422d0182020-01-17 13:37:05 +0200920 go c.handleE2TSubscriptionFailure(msg)
Juha Hyttinenc9eb08a2020-02-28 08:53:33 +0200921 case xapp.RIC_SUB_DEL_REQ:
Juha Hyttinen422d0182020-01-17 13:37:05 +0200922 go c.handleXAPPSubscriptionDeleteRequest(msg)
Juha Hyttinenc9eb08a2020-02-28 08:53:33 +0200923 case xapp.RIC_SUB_DEL_RESP:
Juha Hyttinen422d0182020-01-17 13:37:05 +0200924 go c.handleE2TSubscriptionDeleteResponse(msg)
Juha Hyttinenc9eb08a2020-02-28 08:53:33 +0200925 case xapp.RIC_SUB_DEL_FAILURE:
Juha Hyttinen422d0182020-01-17 13:37:05 +0200926 go c.handleE2TSubscriptionDeleteFailure(msg)
Anssi Mannila90fa0212019-12-12 10:47:47 +0200927 default:
Anssi Mannilaf682ace2021-09-28 13:11:25 +0300928 xapp.Logger.Debug("Unknown Message Type '%d', discarding", msg.Mtype)
Balint Uvegescd3881b2019-10-02 15:01:43 +0000929 }
Juha Hyttinen5f8ffa02020-02-06 15:28:59 +0200930 return
Juha Hyttinen31797b42020-01-16 14:05:01 +0200931}
932
Juha Hyttinen422d0182020-01-17 13:37:05 +0200933//-------------------------------------------------------------------
934// handle from XAPP Subscription Request
935//------------------------------------------------------------------
Juha Hyttinen9dc5adc2020-08-13 10:02:40 +0300936func (c *Control) handleXAPPSubscriptionRequest(params *xapp.RMRParams) {
Anssi Mannilaf682ace2021-09-28 13:11:25 +0300937 xapp.Logger.Debug("MSG from XAPP: %s", params.String())
Anssi Mannila4abf1802021-01-28 13:06:46 +0200938 c.UpdateCounter(cSubReqFromXapp)
Juha Hyttinen422d0182020-01-17 13:37:05 +0200939
Anssi Mannilac7da4ee2021-10-22 09:52:02 +0300940 if c.e2IfState.IsE2ConnectionUp(&params.Meid.RanName) == false {
941 xapp.Logger.Error("No E2 connection for ranName %v", params.Meid.RanName)
942 return
943 }
944
Juha Hyttinen422d0182020-01-17 13:37:05 +0200945 subReqMsg, err := c.e2ap.UnpackSubscriptionRequest(params.Payload)
946 if err != nil {
Juha Hyttinen83ada002020-01-30 10:36:33 +0200947 xapp.Logger.Error("XAPP-SubReq: %s", idstring(err, params))
Juha Hyttinen422d0182020-01-17 13:37:05 +0200948 return
949 }
950
Anssi Mannila4c626a22021-02-11 12:50:48 +0200951 trans := c.tracker.NewXappTransaction(xapp.NewRmrEndpoint(params.Src), params.Xid, subReqMsg.RequestId, params.Meid)
Juha Hyttinen83ada002020-01-30 10:36:33 +0200952 if trans == nil {
953 xapp.Logger.Error("XAPP-SubReq: %s", idstring(fmt.Errorf("transaction not created"), params))
Juha Hyttinen422d0182020-01-17 13:37:05 +0200954 return
955 }
956 defer trans.Release()
957
Anssi Mannila6b3796f2021-02-12 09:11:35 +0200958 if err = c.tracker.Track(trans); err != nil {
Juha Hyttinen83ada002020-01-30 10:36:33 +0200959 xapp.Logger.Error("XAPP-SubReq: %s", idstring(err, trans))
960 return
961 }
962
Anssi Mannilaf682ace2021-09-28 13:11:25 +0300963 subs, _, err := c.registry.AssignToSubscription(trans, subReqMsg, c.ResetTestFlag, c, true)
Juha Hyttinen422d0182020-01-17 13:37:05 +0200964 if err != nil {
Juha Hyttinen83ada002020-01-30 10:36:33 +0200965 xapp.Logger.Error("XAPP-SubReq: %s", idstring(err, trans))
Juha Hyttinen422d0182020-01-17 13:37:05 +0200966 return
967 }
968
Anssi Mannila6b3796f2021-02-12 09:11:35 +0200969 c.wakeSubscriptionRequest(subs, trans)
970}
971
972//-------------------------------------------------------------------
973// Wake Subscription Request to E2node
974//------------------------------------------------------------------
975func (c *Control) wakeSubscriptionRequest(subs *Subscription, trans *TransactionXapp) {
976
Anssi Mannilaf682ace2021-09-28 13:11:25 +0300977 e2SubscriptionDirectives, _ := c.GetE2SubscriptionDirectives(nil)
Anssi Mannilac7da4ee2021-10-22 09:52:02 +0300978 subs.OngoingReqCount++
Anssi Mannila54838ed2021-11-19 11:25:01 +0200979 go c.handleSubscriptionCreate(subs, trans, e2SubscriptionDirectives, waitRouteCleanup_ms)
Juha Hyttinen422d0182020-01-17 13:37:05 +0200980 event, _ := trans.WaitEvent(0) //blocked wait as timeout is handled in subs side
Anssi Mannilac7da4ee2021-10-22 09:52:02 +0300981 subs.OngoingReqCount--
Anssi Mannila6b3796f2021-02-12 09:11:35 +0200982 var err error
Juha Hyttinen422d0182020-01-17 13:37:05 +0200983 if event != nil {
984 switch themsg := event.(type) {
985 case *e2ap.E2APSubscriptionResponse:
Anssi Mannila4c626a22021-02-11 12:50:48 +0200986 themsg.RequestId.Id = trans.RequestId.Id
Juha Hyttinen422d0182020-01-17 13:37:05 +0200987 trans.Mtype, trans.Payload, err = c.e2ap.PackSubscriptionResponse(themsg)
988 if err == nil {
Anssi Mannila64a0df42020-02-26 09:46:03 +0200989 trans.Release()
Anssi Mannila4abf1802021-01-28 13:06:46 +0200990 c.UpdateCounter(cSubRespToXapp)
Juha Hyttinen83ada002020-01-30 10:36:33 +0200991 c.rmrSendToXapp("", subs, trans)
Juha Hyttinen422d0182020-01-17 13:37:05 +0200992 return
993 }
994 case *e2ap.E2APSubscriptionFailure:
Anssi Mannila4c626a22021-02-11 12:50:48 +0200995 themsg.RequestId.Id = trans.RequestId.Id
Juha Hyttinen422d0182020-01-17 13:37:05 +0200996 trans.Mtype, trans.Payload, err = c.e2ap.PackSubscriptionFailure(themsg)
997 if err == nil {
Anssi Mannila4abf1802021-01-28 13:06:46 +0200998 c.UpdateCounter(cSubFailToXapp)
Juha Hyttinen83ada002020-01-30 10:36:33 +0200999 c.rmrSendToXapp("", subs, trans)
Juha Hyttinen422d0182020-01-17 13:37:05 +02001000 }
Juha Hyttinen422d0182020-01-17 13:37:05 +02001001 default:
Juha Hyttinen31797b42020-01-16 14:05:01 +02001002 break
1003 }
1004 }
Anssi Mannilaf682ace2021-09-28 13:11:25 +03001005 xapp.Logger.Debug("XAPP-SubReq: failed %s", idstring(err, trans, subs))
Juha Hyttinen31797b42020-01-16 14:05:01 +02001006}
1007
Juha Hyttinen422d0182020-01-17 13:37:05 +02001008//-------------------------------------------------------------------
1009// handle from XAPP Subscription Delete Request
1010//------------------------------------------------------------------
Juha Hyttinen9dc5adc2020-08-13 10:02:40 +03001011func (c *Control) handleXAPPSubscriptionDeleteRequest(params *xapp.RMRParams) {
Anssi Mannilaf682ace2021-09-28 13:11:25 +03001012 xapp.Logger.Debug("MSG from XAPP: %s", params.String())
Anssi Mannila4abf1802021-01-28 13:06:46 +02001013 c.UpdateCounter(cSubDelReqFromXapp)
Juha Hyttinen422d0182020-01-17 13:37:05 +02001014
Anssi Mannilac7da4ee2021-10-22 09:52:02 +03001015 if c.e2IfState.IsE2ConnectionUp(&params.Meid.RanName) == false {
1016 xapp.Logger.Error("No E2 connection for ranName %v", params.Meid.RanName)
1017 return
1018 }
1019
Juha Hyttinen422d0182020-01-17 13:37:05 +02001020 subDelReqMsg, err := c.e2ap.UnpackSubscriptionDeleteRequest(params.Payload)
Juha Hyttinen31797b42020-01-16 14:05:01 +02001021 if err != nil {
Juha Hyttinen83ada002020-01-30 10:36:33 +02001022 xapp.Logger.Error("XAPP-SubDelReq %s", idstring(err, params))
Juha Hyttinen422d0182020-01-17 13:37:05 +02001023 return
1024 }
1025
Anssi Mannila4c626a22021-02-11 12:50:48 +02001026 trans := c.tracker.NewXappTransaction(xapp.NewRmrEndpoint(params.Src), params.Xid, subDelReqMsg.RequestId, params.Meid)
Juha Hyttinen83ada002020-01-30 10:36:33 +02001027 if trans == nil {
1028 xapp.Logger.Error("XAPP-SubDelReq: %s", idstring(fmt.Errorf("transaction not created"), params))
Juha Hyttinen422d0182020-01-17 13:37:05 +02001029 return
1030 }
1031 defer trans.Release()
1032
Juha Hyttinen83ada002020-01-30 10:36:33 +02001033 err = c.tracker.Track(trans)
Juha Hyttinen422d0182020-01-17 13:37:05 +02001034 if err != nil {
Juha Hyttinen83ada002020-01-30 10:36:33 +02001035 xapp.Logger.Error("XAPP-SubReq: %s", idstring(err, trans))
1036 return
1037 }
1038
Juha Hyttinen47942b42020-02-27 10:41:43 +02001039 subs, err := c.registry.GetSubscriptionFirstMatch([]uint32{trans.GetSubId()})
Juha Hyttinen83ada002020-01-30 10:36:33 +02001040 if err != nil {
1041 xapp.Logger.Error("XAPP-SubDelReq: %s", idstring(err, trans))
Juha Hyttinen422d0182020-01-17 13:37:05 +02001042 return
1043 }
1044
Juha Hyttinen422d0182020-01-17 13:37:05 +02001045 //
1046 // Wake subs delete
1047 //
Anssi Mannilac7da4ee2021-10-22 09:52:02 +03001048 subs.OngoingDelCount++
Anssi Mannila54838ed2021-11-19 11:25:01 +02001049 go c.handleSubscriptionDelete(subs, trans, waitRouteCleanup_ms)
Juha Hyttinen422d0182020-01-17 13:37:05 +02001050 trans.WaitEvent(0) //blocked wait as timeout is handled in subs side
Anssi Mannilac7da4ee2021-10-22 09:52:02 +03001051 subs.OngoingDelCount--
Juha Hyttinen422d0182020-01-17 13:37:05 +02001052
Juha Hyttinen83ada002020-01-30 10:36:33 +02001053 xapp.Logger.Debug("XAPP-SubDelReq: Handling event %s ", idstring(nil, trans, subs))
1054
Anssi Mannilac92b4212020-12-07 14:59:34 +02001055 if subs.NoRespToXapp == true {
1056 // Do no send delete responses to xapps due to submgr restart is deleting uncompleted subscriptions
Anssi Mannilaf682ace2021-09-28 13:11:25 +03001057 xapp.Logger.Debug("XAPP-SubDelReq: subs.NoRespToXapp == true")
Anssi Mannilac92b4212020-12-07 14:59:34 +02001058 return
1059 }
1060
1061 // Whatever is received success, fail or timeout, send successful delete response
Juha Hyttinen422d0182020-01-17 13:37:05 +02001062 subDelRespMsg := &e2ap.E2APSubscriptionDeleteResponse{}
Anssi Mannila4c626a22021-02-11 12:50:48 +02001063 subDelRespMsg.RequestId.Id = trans.RequestId.Id
1064 subDelRespMsg.RequestId.InstanceId = subs.GetReqId().RequestId.InstanceId
Juha Hyttinen422d0182020-01-17 13:37:05 +02001065 subDelRespMsg.FunctionId = subs.SubReqMsg.FunctionId
1066 trans.Mtype, trans.Payload, err = c.e2ap.PackSubscriptionDeleteResponse(subDelRespMsg)
1067 if err == nil {
Anssi Mannila4abf1802021-01-28 13:06:46 +02001068 c.UpdateCounter(cSubDelRespToXapp)
Juha Hyttinen83ada002020-01-30 10:36:33 +02001069 c.rmrSendToXapp("", subs, trans)
Juha Hyttinen422d0182020-01-17 13:37:05 +02001070 }
1071}
1072
1073//-------------------------------------------------------------------
1074// SUBS CREATE Handling
1075//-------------------------------------------------------------------
Anssi Mannila54838ed2021-11-19 11:25:01 +02001076func (c *Control) handleSubscriptionCreate(subs *Subscription, parentTrans *TransactionXapp, e2SubscriptionDirectives *E2SubscriptionDirectives, waitRouteCleanupTime time.Duration) {
Juha Hyttinen422d0182020-01-17 13:37:05 +02001077
Anssi Mannilaf682ace2021-09-28 13:11:25 +03001078 var event interface{} = nil
Anssi Mannilac92b4212020-12-07 14:59:34 +02001079 var removeSubscriptionFromDb bool = false
Juha Hyttinen83ada002020-01-30 10:36:33 +02001080 trans := c.tracker.NewSubsTransaction(subs)
Juha Hyttinen422d0182020-01-17 13:37:05 +02001081 subs.WaitTransactionTurn(trans)
1082 defer subs.ReleaseTransactionTurn(trans)
1083 defer trans.Release()
1084
Juha Hyttinen83ada002020-01-30 10:36:33 +02001085 xapp.Logger.Debug("SUBS-SubReq: Handling %s ", idstring(nil, trans, subs, parentTrans))
Juha Hyttinen422d0182020-01-17 13:37:05 +02001086
Juha Hyttinen83ada002020-01-30 10:36:33 +02001087 subRfMsg, valid := subs.GetCachedResponse()
1088 if subRfMsg == nil && valid == true {
Anssi Mannilaf682ace2021-09-28 13:11:25 +03001089 event = c.sendE2TSubscriptionRequest(subs, trans, parentTrans, e2SubscriptionDirectives)
Anssi Mannila6d629ad2021-01-25 09:59:56 +02001090 switch event.(type) {
1091 case *e2ap.E2APSubscriptionResponse:
1092 subRfMsg, valid = subs.SetCachedResponse(event, true)
1093 subs.SubRespRcvd = true
1094 case *e2ap.E2APSubscriptionFailure:
Anssi Mannila6d629ad2021-01-25 09:59:56 +02001095 subRfMsg, valid = subs.SetCachedResponse(event, false)
Anssi Mannilaf682ace2021-09-28 13:11:25 +03001096 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 +02001097 case *SubmgrRestartTestEvent:
Anssi Mannila54838ed2021-11-19 11:25:01 +02001098 // 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 +02001099 xapp.Logger.Debug("Test restart flag is active. Dropping this transaction to test restart case")
Anssi Mannila54838ed2021-11-19 11:25:01 +02001100 subRfMsg, valid = subs.SetCachedResponse(event, false)
1101 parentTrans.SendEvent(subRfMsg, 0)
1102 return
Anssi Mannilaf682ace2021-09-28 13:11:25 +03001103 case *PackSubscriptionRequestErrortEvent, *SDLWriteErrortEvent:
1104 subRfMsg, valid = subs.SetCachedResponse(event, false)
Anssi Mannila6d629ad2021-01-25 09:59:56 +02001105 default:
Anssi Mannila3d80b722021-11-12 13:17:15 +02001106 // Timer expiry
Anssi Mannilaf682ace2021-09-28 13:11:25 +03001107 if subs.PolicyUpdate == false {
1108 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 +03001109 subRfMsg, valid = subs.SetCachedResponse(nil, false)
1110 c.sendE2TSubscriptionDeleteRequest(subs, trans, parentTrans)
Anssi Mannila54838ed2021-11-19 11:25:01 +02001111 } else {
1112 subRfMsg, valid = subs.SetCachedResponse(nil, true)
Anssi Mannilaf682ace2021-09-28 13:11:25 +03001113 }
Juha Hyttinen83ada002020-01-30 10:36:33 +02001114 }
1115 xapp.Logger.Debug("SUBS-SubReq: Handling (e2t response %s) %s", typeofSubsMessage(subRfMsg), idstring(nil, trans, subs, parentTrans))
1116 } else {
1117 xapp.Logger.Debug("SUBS-SubReq: Handling (cached response %s) %s", typeofSubsMessage(subRfMsg), idstring(nil, trans, subs, parentTrans))
Juha Hyttinen422d0182020-01-17 13:37:05 +02001118 }
Anssi Mannila54838ed2021-11-19 11:25:01 +02001119 if valid == false {
1120 removeSubscriptionFromDb = true
1121 }
Juha Hyttinen422d0182020-01-17 13:37:05 +02001122
Anssi Mannilaf682ace2021-09-28 13:11:25 +03001123 err := c.UpdateSubscriptionInDB(subs, removeSubscriptionFromDb)
1124 if err != nil {
Anssi Mannila54838ed2021-11-19 11:25:01 +02001125 valid = false
Anssi Mannilaf682ace2021-09-28 13:11:25 +03001126 c.sendE2TSubscriptionDeleteRequest(subs, trans, parentTrans)
1127 }
1128
Anssi Mannila27385172021-12-22 09:41:54 +02001129 // Now RemoveFromSubscription in here to avoid race conditions (mostly concerns delete)
Juha Hyttinen429cfe62020-03-31 11:23:02 +03001130 if valid == false {
Anssi Mannila54838ed2021-11-19 11:25:01 +02001131 c.registry.RemoveFromSubscription(subs, parentTrans, waitRouteCleanupTime, c)
Juha Hyttinen429cfe62020-03-31 11:23:02 +03001132 }
Anssi Mannilac92b4212020-12-07 14:59:34 +02001133
Juha Hyttinen83ada002020-01-30 10:36:33 +02001134 parentTrans.SendEvent(subRfMsg, 0)
Juha Hyttinen422d0182020-01-17 13:37:05 +02001135}
1136
1137//-------------------------------------------------------------------
1138// SUBS DELETE Handling
1139//-------------------------------------------------------------------
Juha Hyttinen3944a222020-01-24 11:51:46 +02001140
Anssi Mannila54838ed2021-11-19 11:25:01 +02001141func (c *Control) handleSubscriptionDelete(subs *Subscription, parentTrans *TransactionXapp, waitRouteCleanupTime time.Duration) {
Juha Hyttinen422d0182020-01-17 13:37:05 +02001142
Juha Hyttinen83ada002020-01-30 10:36:33 +02001143 trans := c.tracker.NewSubsTransaction(subs)
Juha Hyttinen422d0182020-01-17 13:37:05 +02001144 subs.WaitTransactionTurn(trans)
1145 defer subs.ReleaseTransactionTurn(trans)
1146 defer trans.Release()
1147
Juha Hyttinen83ada002020-01-30 10:36:33 +02001148 xapp.Logger.Debug("SUBS-SubDelReq: Handling %s", idstring(nil, trans, subs, parentTrans))
Juha Hyttinen422d0182020-01-17 13:37:05 +02001149
Juha Hyttinen3944a222020-01-24 11:51:46 +02001150 subs.mutex.Lock()
Anssi Mannila4abf1802021-01-28 13:06:46 +02001151
Juha Hyttinen3944a222020-01-24 11:51:46 +02001152 if subs.valid && subs.EpList.HasEndpoint(parentTrans.GetEndpoint()) && subs.EpList.Size() == 1 {
1153 subs.valid = false
1154 subs.mutex.Unlock()
1155 c.sendE2TSubscriptionDeleteRequest(subs, trans, parentTrans)
1156 } else {
1157 subs.mutex.Unlock()
1158 }
Anssi Mannila27385172021-12-22 09:41:54 +02001159
1160 // Now RemoveFromSubscription in here to avoid race conditions (mostly concerns delete)
Anssi Mannila54838ed2021-11-19 11:25:01 +02001161 c.registry.RemoveFromSubscription(subs, parentTrans, waitRouteCleanupTime, c)
Juha Hyttinen47942b42020-02-27 10:41:43 +02001162 parentTrans.SendEvent(nil, 0)
Juha Hyttinen422d0182020-01-17 13:37:05 +02001163}
1164
1165//-------------------------------------------------------------------
1166// send to E2T Subscription Request
1167//-------------------------------------------------------------------
Anssi Mannilaf682ace2021-09-28 13:11:25 +03001168func (c *Control) sendE2TSubscriptionRequest(subs *Subscription, trans *TransactionSubs, parentTrans *TransactionXapp, e2SubscriptionDirectives *E2SubscriptionDirectives) interface{} {
Juha Hyttinen422d0182020-01-17 13:37:05 +02001169 var err error
1170 var event interface{} = nil
1171 var timedOut bool = false
Konstantinos Archangelof26dfa712021-06-04 12:10:26 +00001172 const ricRequestorId = 123
Juha Hyttinen422d0182020-01-17 13:37:05 +02001173
1174 subReqMsg := subs.SubReqMsg
Juha Hyttinen83ada002020-01-30 10:36:33 +02001175 subReqMsg.RequestId = subs.GetReqId().RequestId
Konstantinos Archangelof26dfa712021-06-04 12:10:26 +00001176 subReqMsg.RequestId.Id = ricRequestorId
Juha Hyttinen422d0182020-01-17 13:37:05 +02001177 trans.Mtype, trans.Payload, err = c.e2ap.PackSubscriptionRequest(subReqMsg)
1178 if err != nil {
Anssi Mannilab43397e2021-11-16 12:06:16 +02001179 xapp.Logger.Error("SUBS-SubReq ASN1 pack error: %s", idstring(err, trans, subs, parentTrans))
Anssi Mannilaf682ace2021-09-28 13:11:25 +03001180 return &PackSubscriptionRequestErrortEvent{
1181 ErrorInfo{
1182 ErrorSource: models.SubscriptionInstanceErrorSourceASN1,
1183 ErrorCause: err.Error(),
1184 },
1185 }
Juha Hyttinen422d0182020-01-17 13:37:05 +02001186 }
1187
Anssi Mannilac92b4212020-12-07 14:59:34 +02001188 // 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 +03001189 err = c.WriteSubscriptionToDb(subs)
1190 if err != nil {
1191 return &SDLWriteErrortEvent{
1192 ErrorInfo{
1193 ErrorSource: models.SubscriptionInstanceErrorSourceDBAAS,
1194 ErrorCause: err.Error(),
1195 },
1196 }
1197 }
Markku Virtanenfe2cdab2021-05-21 10:59:29 +00001198
Anssi Mannilaf682ace2021-09-28 13:11:25 +03001199 for retries := int64(0); retries < e2SubscriptionDirectives.E2MaxTryCount; retries++ {
Juha Hyttinen83ada002020-01-30 10:36:33 +02001200 desc := fmt.Sprintf("(retry %d)", retries)
Anssi Mannila4abf1802021-01-28 13:06:46 +02001201 if retries == 0 {
1202 c.UpdateCounter(cSubReqToE2)
1203 } else {
1204 c.UpdateCounter(cSubReReqToE2)
1205 }
Juha Hyttinen83ada002020-01-30 10:36:33 +02001206 c.rmrSendToE2T(desc, subs, trans)
Anssi Mannilac92b4212020-12-07 14:59:34 +02001207 if subs.DoNotWaitSubResp == false {
Anssi Mannilaf682ace2021-09-28 13:11:25 +03001208 event, timedOut = trans.WaitEvent(e2SubscriptionDirectives.E2TimeoutTimerValue)
Anssi Mannilac92b4212020-12-07 14:59:34 +02001209 if timedOut {
Anssi Mannila4abf1802021-01-28 13:06:46 +02001210 c.UpdateCounter(cSubReqTimerExpiry)
Anssi Mannilac92b4212020-12-07 14:59:34 +02001211 continue
1212 }
1213 } else {
1214 // Simulating case where subscrition request has been sent but response has not been received before restart
1215 event = &SubmgrRestartTestEvent{}
Anssi Mannilaf682ace2021-09-28 13:11:25 +03001216 xapp.Logger.Debug("Restart event, DoNotWaitSubResp == true")
Juha Hyttinen422d0182020-01-17 13:37:05 +02001217 }
1218 break
1219 }
Juha Hyttinen83ada002020-01-30 10:36:33 +02001220 xapp.Logger.Debug("SUBS-SubReq: Response handling event(%s) %s", typeofSubsMessage(event), idstring(nil, trans, subs, parentTrans))
Juha Hyttinen422d0182020-01-17 13:37:05 +02001221 return event
1222}
1223
1224//-------------------------------------------------------------------
1225// send to E2T Subscription Delete Request
1226//-------------------------------------------------------------------
1227
Juha Hyttinen83ada002020-01-30 10:36:33 +02001228func (c *Control) sendE2TSubscriptionDeleteRequest(subs *Subscription, trans *TransactionSubs, parentTrans *TransactionXapp) interface{} {
Juha Hyttinen422d0182020-01-17 13:37:05 +02001229 var err error
1230 var event interface{}
1231 var timedOut bool
Konstantinos Archangelof26dfa712021-06-04 12:10:26 +00001232 const ricRequestorId = 123
Juha Hyttinen422d0182020-01-17 13:37:05 +02001233
1234 subDelReqMsg := &e2ap.E2APSubscriptionDeleteRequest{}
Juha Hyttinen83ada002020-01-30 10:36:33 +02001235 subDelReqMsg.RequestId = subs.GetReqId().RequestId
Konstantinos Archangelof26dfa712021-06-04 12:10:26 +00001236 subDelReqMsg.RequestId.Id = ricRequestorId
Juha Hyttinenaf91f972020-01-24 08:38:47 +02001237 subDelReqMsg.FunctionId = subs.SubReqMsg.FunctionId
Juha Hyttinen422d0182020-01-17 13:37:05 +02001238 trans.Mtype, trans.Payload, err = c.e2ap.PackSubscriptionDeleteRequest(subDelReqMsg)
1239 if err != nil {
Juha Hyttinen83ada002020-01-30 10:36:33 +02001240 xapp.Logger.Error("SUBS-SubDelReq: %s", idstring(err, trans, subs, parentTrans))
Juha Hyttinen422d0182020-01-17 13:37:05 +02001241 return event
1242 }
1243
1244 for retries := uint64(0); retries < e2tMaxSubDelReqTryCount; retries++ {
Juha Hyttinen83ada002020-01-30 10:36:33 +02001245 desc := fmt.Sprintf("(retry %d)", retries)
Anssi Mannila4abf1802021-01-28 13:06:46 +02001246 if retries == 0 {
1247 c.UpdateCounter(cSubDelReqToE2)
1248 } else {
1249 c.UpdateCounter(cSubDelReReqToE2)
1250 }
Juha Hyttinen83ada002020-01-30 10:36:33 +02001251 c.rmrSendToE2T(desc, subs, trans)
Juha Hyttinen422d0182020-01-17 13:37:05 +02001252 event, timedOut = trans.WaitEvent(e2tSubDelReqTime)
1253 if timedOut {
Anssi Mannila4abf1802021-01-28 13:06:46 +02001254 c.UpdateCounter(cSubDelReqTimerExpiry)
Juha Hyttinen422d0182020-01-17 13:37:05 +02001255 continue
1256 }
1257 break
1258 }
Juha Hyttinen83ada002020-01-30 10:36:33 +02001259 xapp.Logger.Debug("SUBS-SubDelReq: Response handling event(%s) %s", typeofSubsMessage(event), idstring(nil, trans, subs, parentTrans))
Juha Hyttinen422d0182020-01-17 13:37:05 +02001260 return event
1261}
1262
1263//-------------------------------------------------------------------
Anssi Mannila4abf1802021-01-28 13:06:46 +02001264// handle from E2T Subscription Response
Juha Hyttinen422d0182020-01-17 13:37:05 +02001265//-------------------------------------------------------------------
Juha Hyttinen9dc5adc2020-08-13 10:02:40 +03001266func (c *Control) handleE2TSubscriptionResponse(params *xapp.RMRParams) {
Anssi Mannilaf682ace2021-09-28 13:11:25 +03001267 xapp.Logger.Debug("MSG from E2T: %s", params.String())
Anssi Mannila4abf1802021-01-28 13:06:46 +02001268 c.UpdateCounter(cSubRespFromE2)
Anssi Mannila51122392021-05-25 11:51:31 +03001269
Juha Hyttinen422d0182020-01-17 13:37:05 +02001270 subRespMsg, err := c.e2ap.UnpackSubscriptionResponse(params.Payload)
1271 if err != nil {
Juha Hyttinen83ada002020-01-30 10:36:33 +02001272 xapp.Logger.Error("MSG-SubResp %s", idstring(err, params))
Juha Hyttinen422d0182020-01-17 13:37:05 +02001273 return
1274 }
Juha Hyttinenaada6452020-04-07 08:47:58 +03001275 subs, err := c.registry.GetSubscriptionFirstMatch([]uint32{subRespMsg.RequestId.InstanceId})
Juha Hyttinen422d0182020-01-17 13:37:05 +02001276 if err != nil {
Juha Hyttinen83ada002020-01-30 10:36:33 +02001277 xapp.Logger.Error("MSG-SubResp: %s", idstring(err, params))
Juha Hyttinen422d0182020-01-17 13:37:05 +02001278 return
Juha Hyttinen31797b42020-01-16 14:05:01 +02001279 }
1280 trans := subs.GetTransaction()
1281 if trans == nil {
Juha Hyttinen422d0182020-01-17 13:37:05 +02001282 err = fmt.Errorf("Ongoing transaction not found")
Juha Hyttinen83ada002020-01-30 10:36:33 +02001283 xapp.Logger.Error("MSG-SubResp: %s", idstring(err, params, subs))
Juha Hyttinenff8dccd2019-12-10 14:34:07 +02001284 return
Anssi Mannila2e99e2f2019-12-05 13:57:06 +02001285 }
Anssi Mannila54838ed2021-11-19 11:25:01 +02001286 xapp.Logger.Debug("SUBS-SubResp: Sending event, trans= %v", trans)
Juha Hyttinen422d0182020-01-17 13:37:05 +02001287 sendOk, timedOut := trans.SendEvent(subRespMsg, e2tRecvMsgTimeout)
1288 if sendOk == false {
1289 err = fmt.Errorf("Passing event to transaction failed: sendOk(%t) timedOut(%t)", sendOk, timedOut)
Juha Hyttinen83ada002020-01-30 10:36:33 +02001290 xapp.Logger.Error("MSG-SubResp: %s", idstring(err, trans, subs))
Peter Szilagyifbc56f92019-07-23 19:29:46 +00001291 }
Peter Szilagyifbc56f92019-07-23 19:29:46 +00001292 return
kalnagy45114752019-06-18 14:40:39 +02001293}
1294
Juha Hyttinen422d0182020-01-17 13:37:05 +02001295//-------------------------------------------------------------------
1296// handle from E2T Subscription Failure
1297//-------------------------------------------------------------------
Juha Hyttinen9dc5adc2020-08-13 10:02:40 +03001298func (c *Control) handleE2TSubscriptionFailure(params *xapp.RMRParams) {
Anssi Mannilaf682ace2021-09-28 13:11:25 +03001299 xapp.Logger.Debug("MSG from E2T: %s", params.String())
Anssi Mannila4abf1802021-01-28 13:06:46 +02001300 c.UpdateCounter(cSubFailFromE2)
Juha Hyttinen422d0182020-01-17 13:37:05 +02001301 subFailMsg, err := c.e2ap.UnpackSubscriptionFailure(params.Payload)
Peter Szilagyifbc56f92019-07-23 19:29:46 +00001302 if err != nil {
Juha Hyttinen83ada002020-01-30 10:36:33 +02001303 xapp.Logger.Error("MSG-SubFail %s", idstring(err, params))
Peter Szilagyifbc56f92019-07-23 19:29:46 +00001304 return
1305 }
Juha Hyttinenaada6452020-04-07 08:47:58 +03001306 subs, err := c.registry.GetSubscriptionFirstMatch([]uint32{subFailMsg.RequestId.InstanceId})
Juha Hyttinen31797b42020-01-16 14:05:01 +02001307 if err != nil {
Juha Hyttinen83ada002020-01-30 10:36:33 +02001308 xapp.Logger.Error("MSG-SubFail: %s", idstring(err, params))
Juha Hyttinenaafee7f2020-01-14 14:54:51 +02001309 return
1310 }
Juha Hyttinen422d0182020-01-17 13:37:05 +02001311 trans := subs.GetTransaction()
1312 if trans == nil {
1313 err = fmt.Errorf("Ongoing transaction not found")
Juha Hyttinen83ada002020-01-30 10:36:33 +02001314 xapp.Logger.Error("MSG-SubFail: %s", idstring(err, params, subs))
Anssi Mannila8046c702020-01-02 13:39:05 +02001315 return
1316 }
Juha Hyttinen422d0182020-01-17 13:37:05 +02001317 sendOk, timedOut := trans.SendEvent(subFailMsg, e2tRecvMsgTimeout)
1318 if sendOk == false {
1319 err = fmt.Errorf("Passing event to transaction failed: sendOk(%t) timedOut(%t)", sendOk, timedOut)
Juha Hyttinen83ada002020-01-30 10:36:33 +02001320 xapp.Logger.Error("MSG-SubFail: %s", idstring(err, trans, subs))
Juha Hyttinenaafee7f2020-01-14 14:54:51 +02001321 }
Anssi Mannila2e99e2f2019-12-05 13:57:06 +02001322 return
1323}
1324
Juha Hyttinen422d0182020-01-17 13:37:05 +02001325//-------------------------------------------------------------------
1326// handle from E2T Subscription Delete Response
1327//-------------------------------------------------------------------
Juha Hyttinen9dc5adc2020-08-13 10:02:40 +03001328func (c *Control) handleE2TSubscriptionDeleteResponse(params *xapp.RMRParams) (err error) {
Anssi Mannilaf682ace2021-09-28 13:11:25 +03001329 xapp.Logger.Debug("MSG from E2T: %s", params.String())
Anssi Mannila4abf1802021-01-28 13:06:46 +02001330 c.UpdateCounter(cSubDelRespFromE2)
Juha Hyttinen422d0182020-01-17 13:37:05 +02001331 subDelRespMsg, err := c.e2ap.UnpackSubscriptionDeleteResponse(params.Payload)
Anssi Mannila2e99e2f2019-12-05 13:57:06 +02001332 if err != nil {
Juha Hyttinen83ada002020-01-30 10:36:33 +02001333 xapp.Logger.Error("MSG-SubDelResp: %s", idstring(err, params))
Anssi Mannila2e99e2f2019-12-05 13:57:06 +02001334 return
1335 }
Juha Hyttinenaada6452020-04-07 08:47:58 +03001336 subs, err := c.registry.GetSubscriptionFirstMatch([]uint32{subDelRespMsg.RequestId.InstanceId})
Juha Hyttinen31797b42020-01-16 14:05:01 +02001337 if err != nil {
Juha Hyttinen83ada002020-01-30 10:36:33 +02001338 xapp.Logger.Error("MSG-SubDelResp: %s", idstring(err, params))
Juha Hyttinen0d064ec2020-01-09 09:08:53 +02001339 return
1340 }
Juha Hyttinen422d0182020-01-17 13:37:05 +02001341 trans := subs.GetTransaction()
1342 if trans == nil {
1343 err = fmt.Errorf("Ongoing transaction not found")
Juha Hyttinen83ada002020-01-30 10:36:33 +02001344 xapp.Logger.Error("MSG-SubDelResp: %s", idstring(err, params, subs))
Anssi Mannila8046c702020-01-02 13:39:05 +02001345 return
Anssi Mannila2e99e2f2019-12-05 13:57:06 +02001346 }
Juha Hyttinen422d0182020-01-17 13:37:05 +02001347 sendOk, timedOut := trans.SendEvent(subDelRespMsg, e2tRecvMsgTimeout)
1348 if sendOk == false {
1349 err = fmt.Errorf("Passing event to transaction failed: sendOk(%t) timedOut(%t)", sendOk, timedOut)
Juha Hyttinen83ada002020-01-30 10:36:33 +02001350 xapp.Logger.Error("MSG-SubDelResp: %s", idstring(err, trans, subs))
Juha Hyttinen60bfcf92020-01-14 15:14:24 +02001351 }
Anssi Mannila2e99e2f2019-12-05 13:57:06 +02001352 return
1353}
1354
Juha Hyttinen422d0182020-01-17 13:37:05 +02001355//-------------------------------------------------------------------
1356// handle from E2T Subscription Delete Failure
1357//-------------------------------------------------------------------
Juha Hyttinen9dc5adc2020-08-13 10:02:40 +03001358func (c *Control) handleE2TSubscriptionDeleteFailure(params *xapp.RMRParams) {
Anssi Mannilaf682ace2021-09-28 13:11:25 +03001359 xapp.Logger.Debug("MSG from E2T: %s", params.String())
Anssi Mannila4abf1802021-01-28 13:06:46 +02001360 c.UpdateCounter(cSubDelFailFromE2)
Juha Hyttinen422d0182020-01-17 13:37:05 +02001361 subDelFailMsg, err := c.e2ap.UnpackSubscriptionDeleteFailure(params.Payload)
Juha Hyttinen31797b42020-01-16 14:05:01 +02001362 if err != nil {
Juha Hyttinen83ada002020-01-30 10:36:33 +02001363 xapp.Logger.Error("MSG-SubDelFail: %s", idstring(err, params))
Anssi Mannilaf1d0eb62019-12-17 15:29:55 +02001364 return
1365 }
Juha Hyttinenaada6452020-04-07 08:47:58 +03001366 subs, err := c.registry.GetSubscriptionFirstMatch([]uint32{subDelFailMsg.RequestId.InstanceId})
Anssi Mannila8046c702020-01-02 13:39:05 +02001367 if err != nil {
Juha Hyttinen83ada002020-01-30 10:36:33 +02001368 xapp.Logger.Error("MSG-SubDelFail: %s", idstring(err, params))
Anssi Mannila8046c702020-01-02 13:39:05 +02001369 return
1370 }
Juha Hyttinen422d0182020-01-17 13:37:05 +02001371 trans := subs.GetTransaction()
1372 if trans == nil {
1373 err = fmt.Errorf("Ongoing transaction not found")
Juha Hyttinen83ada002020-01-30 10:36:33 +02001374 xapp.Logger.Error("MSG-SubDelFail: %s", idstring(err, params, subs))
Juha Hyttinen86a46202020-01-14 12:49:09 +02001375 return
1376 }
Juha Hyttinen422d0182020-01-17 13:37:05 +02001377 sendOk, timedOut := trans.SendEvent(subDelFailMsg, e2tRecvMsgTimeout)
1378 if sendOk == false {
1379 err = fmt.Errorf("Passing event to transaction failed: sendOk(%t) timedOut(%t)", sendOk, timedOut)
Juha Hyttinen83ada002020-01-30 10:36:33 +02001380 xapp.Logger.Error("MSG-SubDelFail: %s", idstring(err, trans, subs))
Anssi Mannila8046c702020-01-02 13:39:05 +02001381 }
kalnagy93cc3e22019-09-19 11:29:29 +02001382 return
1383}
1384
Juha Hyttinen422d0182020-01-17 13:37:05 +02001385//-------------------------------------------------------------------
1386//
1387//-------------------------------------------------------------------
1388func typeofSubsMessage(v interface{}) string {
1389 if v == nil {
1390 return "NIL"
kalnagy93cc3e22019-09-19 11:29:29 +02001391 }
Juha Hyttinen422d0182020-01-17 13:37:05 +02001392 switch v.(type) {
Anssi Mannila51122392021-05-25 11:51:31 +03001393 //case *e2ap.E2APSubscriptionRequest:
1394 // return "SubReq"
Juha Hyttinen422d0182020-01-17 13:37:05 +02001395 case *e2ap.E2APSubscriptionResponse:
1396 return "SubResp"
1397 case *e2ap.E2APSubscriptionFailure:
1398 return "SubFail"
Anssi Mannila51122392021-05-25 11:51:31 +03001399 //case *e2ap.E2APSubscriptionDeleteRequest:
1400 // return "SubDelReq"
Juha Hyttinen422d0182020-01-17 13:37:05 +02001401 case *e2ap.E2APSubscriptionDeleteResponse:
1402 return "SubDelResp"
1403 case *e2ap.E2APSubscriptionDeleteFailure:
1404 return "SubDelFail"
1405 default:
1406 return "Unknown"
Juha Hyttinen31797b42020-01-16 14:05:01 +02001407 }
Anssi Mannilaf1d0eb62019-12-17 15:29:55 +02001408}
Anssi Mannilac92b4212020-12-07 14:59:34 +02001409
1410//-------------------------------------------------------------------
1411//
1412//-------------------------------------------------------------------
Anssi Mannilaf682ace2021-09-28 13:11:25 +03001413func (c *Control) WriteSubscriptionToDb(subs *Subscription) error {
Anssi Mannilac92b4212020-12-07 14:59:34 +02001414 xapp.Logger.Debug("WriteSubscriptionToDb() subId = %v", subs.ReqId.InstanceId)
1415 err := c.WriteSubscriptionToSdl(subs.ReqId.InstanceId, subs)
1416 if err != nil {
1417 xapp.Logger.Error("%v", err)
Anssi Mannilaf682ace2021-09-28 13:11:25 +03001418 return err
Anssi Mannilac92b4212020-12-07 14:59:34 +02001419 }
Anssi Mannilaf682ace2021-09-28 13:11:25 +03001420 return nil
Anssi Mannilac92b4212020-12-07 14:59:34 +02001421}
1422
1423//-------------------------------------------------------------------
1424//
1425//-------------------------------------------------------------------
Anssi Mannilaf682ace2021-09-28 13:11:25 +03001426func (c *Control) UpdateSubscriptionInDB(subs *Subscription, removeSubscriptionFromDb bool) error {
Anssi Mannilac92b4212020-12-07 14:59:34 +02001427
1428 if removeSubscriptionFromDb == true {
1429 // Subscription was written in db already when subscription request was sent to BTS, except for merged request
1430 c.RemoveSubscriptionFromDb(subs)
1431 } else {
1432 // Update is needed for successful response and merge case here
1433 if subs.RetryFromXapp == false {
Anssi Mannilaf682ace2021-09-28 13:11:25 +03001434 err := c.WriteSubscriptionToDb(subs)
1435 return err
Anssi Mannilac92b4212020-12-07 14:59:34 +02001436 }
1437 }
1438 subs.RetryFromXapp = false
Anssi Mannilaf682ace2021-09-28 13:11:25 +03001439 return nil
Anssi Mannilac92b4212020-12-07 14:59:34 +02001440}
1441
1442//-------------------------------------------------------------------
1443//
1444//-------------------------------------------------------------------
1445func (c *Control) RemoveSubscriptionFromDb(subs *Subscription) {
1446 xapp.Logger.Debug("RemoveSubscriptionFromDb() subId = %v", subs.ReqId.InstanceId)
1447 err := c.RemoveSubscriptionFromSdl(subs.ReqId.InstanceId)
1448 if err != nil {
1449 xapp.Logger.Error("%v", err)
1450 }
1451}
1452
Konstantinos Archangelof268d7152021-06-14 12:24:00 +03001453//-------------------------------------------------------------------
1454//
1455//-------------------------------------------------------------------
1456func (c *Control) WriteRESTSubscriptionToDb(restSubId string, restSubs *RESTSubscription) {
1457 xapp.Logger.Debug("WriteRESTSubscriptionToDb() restSubId = %s", restSubId)
1458 err := c.WriteRESTSubscriptionToSdl(restSubId, restSubs)
1459 if err != nil {
1460 xapp.Logger.Error("%v", err)
1461 }
1462}
1463
1464//-------------------------------------------------------------------
1465//
1466//-------------------------------------------------------------------
1467func (c *Control) UpdateRESTSubscriptionInDB(restSubId string, restSubs *RESTSubscription, removeRestSubscriptionFromDb bool) {
1468
1469 if removeRestSubscriptionFromDb == true {
1470 // Subscription was written in db already when subscription request was sent to BTS, except for merged request
1471 c.RemoveRESTSubscriptionFromDb(restSubId)
1472 } else {
1473 c.WriteRESTSubscriptionToDb(restSubId, restSubs)
1474 }
1475}
1476
1477//-------------------------------------------------------------------
1478//
1479//-------------------------------------------------------------------
1480func (c *Control) RemoveRESTSubscriptionFromDb(restSubId string) {
1481 xapp.Logger.Debug("RemoveRESTSubscriptionFromDb() restSubId = %s", restSubId)
1482 err := c.RemoveRESTSubscriptionFromSdl(restSubId)
1483 if err != nil {
1484 xapp.Logger.Error("%v", err)
1485 }
1486}
1487
Anssi Mannilac92b4212020-12-07 14:59:34 +02001488func (c *Control) SendSubscriptionDeleteReq(subs *Subscription) {
1489
Anssi Mannila54838ed2021-11-19 11:25:01 +02001490 if c.UTTesting == true {
1491 // Reqistry mutex is not locked after real restart but it can be when restart is simulated in unit tests
1492 c.registry.mutex = new(sync.Mutex)
1493 }
1494
Konstantinos Archangelof26dfa712021-06-04 12:10:26 +00001495 const ricRequestorId = 123
Anssi Mannilac92b4212020-12-07 14:59:34 +02001496 xapp.Logger.Debug("Sending subscription delete due to restart. subId = %v", subs.ReqId.InstanceId)
1497
1498 // Send delete for every endpoint in the subscription
Anssi Mannilaf682ace2021-09-28 13:11:25 +03001499 if subs.PolicyUpdate == false {
1500 subDelReqMsg := &e2ap.E2APSubscriptionDeleteRequest{}
1501 subDelReqMsg.RequestId = subs.GetReqId().RequestId
1502 subDelReqMsg.RequestId.Id = ricRequestorId
1503 subDelReqMsg.FunctionId = subs.SubReqMsg.FunctionId
1504 mType, payload, err := c.e2ap.PackSubscriptionDeleteRequest(subDelReqMsg)
1505 if err != nil {
1506 xapp.Logger.Error("SendSubscriptionDeleteReq() %s", idstring(err))
1507 return
1508 }
1509 for _, endPoint := range subs.EpList.Endpoints {
1510 params := &xapp.RMRParams{}
1511 params.Mtype = mType
1512 params.SubId = int(subs.GetReqId().InstanceId)
1513 params.Xid = ""
1514 params.Meid = subs.Meid
1515 params.Src = endPoint.String()
1516 params.PayloadLen = len(payload.Buf)
1517 params.Payload = payload.Buf
1518 params.Mbuf = nil
1519 subs.DeleteFromDb = true
1520 c.handleXAPPSubscriptionDeleteRequest(params)
1521 }
Anssi Mannilac92b4212020-12-07 14:59:34 +02001522 }
1523}
Anssi Mannilade457a12021-06-02 16:19:48 +03001524
1525func (c *Control) PrintRESTSubscriptionRequest(p *models.SubscriptionParams) {
1526
1527 fmt.Println("CRESTSubscriptionRequest")
Markku Virtanen987f8b12021-06-10 15:05:02 +03001528
Markku Virtanen2b512b62021-07-30 12:04:00 +00001529 if p == nil {
1530 return
1531 }
1532
Markku Virtanen987f8b12021-06-10 15:05:02 +03001533 if p.SubscriptionID != "" {
1534 fmt.Println(" SubscriptionID = ", p.SubscriptionID)
1535 } else {
1536 fmt.Println(" SubscriptionID = ''")
1537 }
1538
Anssi Mannilade457a12021-06-02 16:19:48 +03001539 fmt.Printf(" ClientEndpoint.Host = %s\n", p.ClientEndpoint.Host)
1540
1541 if p.ClientEndpoint.HTTPPort != nil {
1542 fmt.Printf(" ClientEndpoint.HTTPPort = %v\n", *p.ClientEndpoint.HTTPPort)
1543 } else {
1544 fmt.Println(" ClientEndpoint.HTTPPort = nil")
1545 }
1546
1547 if p.ClientEndpoint.RMRPort != nil {
1548 fmt.Printf(" ClientEndpoint.RMRPort = %v\n", *p.ClientEndpoint.RMRPort)
1549 } else {
1550 fmt.Println(" ClientEndpoint.RMRPort = nil")
1551 }
1552
1553 if p.Meid != nil {
1554 fmt.Printf(" Meid = %s\n", *p.Meid)
1555 } else {
1556 fmt.Println(" Meid = nil")
1557 }
1558
Anssi Mannilaf682ace2021-09-28 13:11:25 +03001559 if p.E2SubscriptionDirectives == nil {
1560 fmt.Println(" E2SubscriptionDirectives = nil")
1561 } else {
1562 fmt.Println(" E2SubscriptionDirectives")
1563 if p.E2SubscriptionDirectives.E2RetryCount == nil {
1564 fmt.Println(" E2RetryCount == nil")
1565 } else {
1566 fmt.Printf(" E2RetryCount = %v\n", *p.E2SubscriptionDirectives.E2RetryCount)
1567 }
1568 fmt.Printf(" E2TimeoutTimerValue = %v\n", p.E2SubscriptionDirectives.E2TimeoutTimerValue)
Anssi Mannilacb7dd492021-10-01 11:10:26 +03001569 fmt.Printf(" RMRRoutingNeeded = %v\n", p.E2SubscriptionDirectives.RMRRoutingNeeded)
Anssi Mannilaf682ace2021-09-28 13:11:25 +03001570 }
Anssi Mannilade457a12021-06-02 16:19:48 +03001571 for _, subscriptionDetail := range p.SubscriptionDetails {
1572 if p.RANFunctionID != nil {
1573 fmt.Printf(" RANFunctionID = %v\n", *p.RANFunctionID)
1574 } else {
1575 fmt.Println(" RANFunctionID = nil")
1576 }
Konstantinos Archangelofe93b00f2021-06-03 10:00:19 +00001577 fmt.Printf(" SubscriptionDetail.XappEventInstanceID = %v\n", *subscriptionDetail.XappEventInstanceID)
Konstantinos Archangelofbd9c98e2021-06-07 17:32:10 +00001578 fmt.Printf(" SubscriptionDetail.EventTriggers = %v\n", subscriptionDetail.EventTriggers)
Anssi Mannilade457a12021-06-02 16:19:48 +03001579
1580 for _, actionToBeSetup := range subscriptionDetail.ActionToBeSetupList {
1581 fmt.Printf(" SubscriptionDetail.ActionToBeSetup.ActionID = %v\n", *actionToBeSetup.ActionID)
1582 fmt.Printf(" SubscriptionDetail.ActionToBeSetup.ActionType = %s\n", *actionToBeSetup.ActionType)
Konstantinos Archangelofbd9c98e2021-06-07 17:32:10 +00001583 fmt.Printf(" SubscriptionDetail.ActionToBeSetup.ActionDefinition = %v\n", actionToBeSetup.ActionDefinition)
Anssi Mannilade457a12021-06-02 16:19:48 +03001584
Anssi Mannilade457a12021-06-02 16:19:48 +03001585 if actionToBeSetup.SubsequentAction != nil {
1586 fmt.Printf(" SubscriptionDetail.ActionToBeSetup.SubsequentAction.SubsequentActionType = %s\n", *actionToBeSetup.SubsequentAction.SubsequentActionType)
1587 fmt.Printf(" SubscriptionDetail.ActionToBeSetup..SubsequentAction.TimeToWait = %s\n", *actionToBeSetup.SubsequentAction.TimeToWait)
1588 } else {
1589 fmt.Println(" SubscriptionDetail.ActionToBeSetup.SubsequentAction = nil")
1590 }
1591 }
1592 }
1593}