blob: e13fc46708822de7a0a31fd3d1d41576e1afd8ba [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
168 xapp.Resource.InjectRoute("/ric/v1/delete_all_e2node_subscriptions/{ranName}", c.DeleteAllE2nodeSubscriptions, "GET")
169 xapp.Resource.InjectRoute("/ric/v1/delete_all_xapp_subscriptions/{xappServiceName}", c.DeleteAllXappSubscriptions, "GET")
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))
Markku Virtanenb642a192021-06-09 09:08:14 +0000581 c.sendSuccesfullResponseNotification(restSubId, restSubscription, xAppEventInstanceID, e2EventInstanceID, clientEndpoint, trans)
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 {
635 return themsg, &errorInfo, nil
636 } else {
637 c.registry.RemoveFromSubscription(subs, trans, waitRouteCleanup_ms, c)
638 c.RemoveSubscriptionFromDb(subs)
639 err = fmt.Errorf("E2 interface down")
640 errorInfo.SetInfo(err.Error(), models.SubscriptionInstanceErrorSourceE2Node, "")
Anssi Mannilac7da4ee2021-10-22 09:52:02 +0300641 }
archaggeafbf95f2021-04-14 08:54:05 +0300642 case *e2ap.E2APSubscriptionFailure:
Markku Virtanen55d2a282021-06-04 14:46:56 +0300643 err = fmt.Errorf("E2 SubscriptionFailure received")
Anssi Mannilaf682ace2021-09-28 13:11:25 +0300644 errorInfo.SetInfo(err.Error(), models.SubscriptionInstanceErrorSourceE2Node, "")
Anssi Mannilaf682ace2021-09-28 13:11:25 +0300645 case *PackSubscriptionRequestErrortEvent:
646 err = fmt.Errorf("E2 SubscriptionRequest pack failure")
Anssi Mannilab43397e2021-11-16 12:06:16 +0200647 errorInfo = themsg.ErrorInfo
Anssi Mannilaf682ace2021-09-28 13:11:25 +0300648 case *SDLWriteErrortEvent:
649 err = fmt.Errorf("SDL write failure")
Anssi Mannilab43397e2021-11-16 12:06:16 +0200650 errorInfo = themsg.ErrorInfo
Anssi Mannila54838ed2021-11-19 11:25:01 +0200651 case *SubmgrRestartTestEvent:
652 err = fmt.Errorf("TEST: restart event received")
653 xapp.Logger.Debug("%s", err)
654 return nil, &errorInfo, err
archaggeafbf95f2021-04-14 08:54:05 +0300655 default:
Anssi Mannilaf682ace2021-09-28 13:11:25 +0300656 err = fmt.Errorf("Unexpected E2 subscription response received")
657 errorInfo.SetInfo(err.Error(), models.SubscriptionInstanceErrorSourceE2Node, "")
archaggeafbf95f2021-04-14 08:54:05 +0300658 break
659 }
Markku Virtanen55d2a282021-06-04 14:46:56 +0300660 } else {
Anssi Mannila3d80b722021-11-12 13:17:15 +0200661 // Timer expiry
Markku Virtanen55d2a282021-06-04 14:46:56 +0300662 err = fmt.Errorf("E2 subscription response timeout")
Anssi Mannilaf682ace2021-09-28 13:11:25 +0300663 errorInfo.SetInfo(err.Error(), "", models.SubscriptionInstanceTimeoutTypeE2Timeout)
664 if subs.PolicyUpdate == true {
665 return nil, &errorInfo, err
666 }
archaggeafbf95f2021-04-14 08:54:05 +0300667 }
Markku Virtanen55d2a282021-06-04 14:46:56 +0300668
669 xapp.Logger.Error("XAPP-SubReq E2 subscription failed %s", idstring(err, trans, subs))
Markku Virtanenfe2cdab2021-05-21 10:59:29 +0000670 c.registry.RemoveFromSubscription(subs, trans, waitRouteCleanup_ms, c)
Anssi Mannilaf682ace2021-09-28 13:11:25 +0300671 return nil, &errorInfo, err
archaggeafbf95f2021-04-14 08:54:05 +0300672}
673
674//-------------------------------------------------------------------
675//
676//-------------------------------------------------------------------
Markku Virtanen42723e22021-06-15 10:09:23 +0300677func (c *Control) sendUnsuccesfullResponseNotification(restSubId *string, restSubscription *RESTSubscription, xAppEventInstanceID int64, err error,
Anssi Mannilaf682ace2021-09-28 13:11:25 +0300678 clientEndpoint *models.SubscriptionParamsClientEndpoint, trans *TransactionXapp, errorInfo *ErrorInfo) {
Markku Virtanen42723e22021-06-15 10:09:23 +0300679
680 // Send notification to xApp that prosessing of a Subscription Request has failed.
681 e2EventInstanceID := (int64)(0)
Anssi Mannilaf682ace2021-09-28 13:11:25 +0300682 if errorInfo.ErrorSource == "" {
683 // Submgr is default source of error
684 errorInfo.ErrorSource = models.SubscriptionInstanceErrorSourceSUBMGR
685 }
Markku Virtanen42723e22021-06-15 10:09:23 +0300686 resp := &models.SubscriptionResponse{
687 SubscriptionID: restSubId,
688 SubscriptionInstances: []*models.SubscriptionInstance{
689 &models.SubscriptionInstance{E2EventInstanceID: &e2EventInstanceID,
Anssi Mannilacb7dd492021-10-01 11:10:26 +0300690 ErrorCause: errorInfo.ErrorCause,
691 ErrorSource: errorInfo.ErrorSource,
692 TimeoutType: errorInfo.TimeoutType,
Markku Virtanen42723e22021-06-15 10:09:23 +0300693 XappEventInstanceID: &xAppEventInstanceID},
694 },
695 }
696 // Mark REST subscription request processed.
697 restSubscription.SetProcessed(err)
698 c.UpdateRESTSubscriptionInDB(*restSubId, restSubscription, false)
699 if trans != nil {
Anssi Mannilaf682ace2021-09-28 13:11:25 +0300700 xapp.Logger.Debug("Sending unsuccessful REST notification (cause %s) to endpoint=%v:%v, XappEventInstanceID=%v, E2EventInstanceID=%v, %s",
701 errorInfo.ErrorCause, clientEndpoint.Host, *clientEndpoint.HTTPPort, xAppEventInstanceID, e2EventInstanceID, idstring(nil, trans))
Markku Virtanen42723e22021-06-15 10:09:23 +0300702 } else {
Anssi Mannilaf682ace2021-09-28 13:11:25 +0300703 xapp.Logger.Debug("Sending unsuccessful REST notification (cause %s) to endpoint=%v:%v, XappEventInstanceID=%v, E2EventInstanceID=%v",
704 errorInfo.ErrorCause, clientEndpoint.Host, *clientEndpoint.HTTPPort, xAppEventInstanceID, e2EventInstanceID)
Markku Virtanen42723e22021-06-15 10:09:23 +0300705 }
706
707 c.UpdateCounter(cRestSubFailNotifToXapp)
708 xapp.Subscription.Notify(resp, *clientEndpoint)
Anssi Mannilac7da4ee2021-10-22 09:52:02 +0300709
Anssi Mannilab43397e2021-11-16 12:06:16 +0200710 // E2 is down. Delete completely processed request safely now
Anssi Mannilac7da4ee2021-10-22 09:52:02 +0300711 if c.e2IfState.IsE2ConnectionUp(&restSubscription.Meid) == false && restSubscription.SubReqOngoing == false {
712 c.registry.DeleteRESTSubscription(restSubId)
713 c.RemoveRESTSubscriptionFromDb(*restSubId)
714 }
Markku Virtanen42723e22021-06-15 10:09:23 +0300715}
716
717//-------------------------------------------------------------------
718//
719//-------------------------------------------------------------------
720func (c *Control) sendSuccesfullResponseNotification(restSubId *string, restSubscription *RESTSubscription, xAppEventInstanceID int64, e2EventInstanceID int64,
721 clientEndpoint *models.SubscriptionParamsClientEndpoint, trans *TransactionXapp) {
722
723 // Store successfully processed InstanceId for deletion
724 restSubscription.AddE2InstanceId((uint32)(e2EventInstanceID))
725 restSubscription.AddXappIdToE2Id(xAppEventInstanceID, e2EventInstanceID)
726
727 // Send notification to xApp that a Subscription Request has been processed.
728 resp := &models.SubscriptionResponse{
729 SubscriptionID: restSubId,
730 SubscriptionInstances: []*models.SubscriptionInstance{
731 &models.SubscriptionInstance{E2EventInstanceID: &e2EventInstanceID,
Anssi Mannilacb7dd492021-10-01 11:10:26 +0300732 ErrorCause: "",
Markku Virtanen42723e22021-06-15 10:09:23 +0300733 XappEventInstanceID: &xAppEventInstanceID},
734 },
735 }
736 // Mark REST subscription request processesd.
737 restSubscription.SetProcessed(nil)
738 c.UpdateRESTSubscriptionInDB(*restSubId, restSubscription, false)
Anssi Mannilaf682ace2021-09-28 13:11:25 +0300739 xapp.Logger.Debug("Sending successful REST notification to endpoint=%v:%v, XappEventInstanceID=%v, E2EventInstanceID=%v, %s",
Markku Virtanen42723e22021-06-15 10:09:23 +0300740 clientEndpoint.Host, *clientEndpoint.HTTPPort, xAppEventInstanceID, e2EventInstanceID, idstring(nil, trans))
741
742 c.UpdateCounter(cRestSubNotifToXapp)
743 xapp.Subscription.Notify(resp, *clientEndpoint)
Anssi Mannilac7da4ee2021-10-22 09:52:02 +0300744
Anssi Mannilab43397e2021-11-16 12:06:16 +0200745 // E2 is down. Delete completely processed request safely now
Anssi Mannilac7da4ee2021-10-22 09:52:02 +0300746 if c.e2IfState.IsE2ConnectionUp(&restSubscription.Meid) == false && restSubscription.SubReqOngoing == false {
747 c.registry.DeleteRESTSubscription(restSubId)
748 c.RemoveRESTSubscriptionFromDb(*restSubId)
749 }
Markku Virtanen42723e22021-06-15 10:09:23 +0300750}
751
752//-------------------------------------------------------------------
753//
754//-------------------------------------------------------------------
Anssi Mannilaf682ace2021-09-28 13:11:25 +0300755func (c *Control) RESTSubscriptionDeleteHandler(restSubId string) int {
archaggeafbf95f2021-04-14 08:54:05 +0300756
757 c.CntRecvMsg++
Konstantinos Archangelof27433e72021-05-31 08:30:35 +0000758 c.UpdateCounter(cRestSubDelReqFromXapp)
archaggeafbf95f2021-04-14 08:54:05 +0300759
Anssi Mannilaf682ace2021-09-28 13:11:25 +0300760 xapp.Logger.Debug("SubscriptionDeleteRequest from XAPP")
archaggeafbf95f2021-04-14 08:54:05 +0300761
Konstantinos Archangelofe93b00f2021-06-03 10:00:19 +0000762 restSubscription, err := c.registry.GetRESTSubscription(restSubId, true)
archaggeafbf95f2021-04-14 08:54:05 +0300763 if err != nil {
764 xapp.Logger.Error("%s", err.Error())
765 if restSubscription == nil {
766 // Subscription was not found
Anssi Mannilac7da4ee2021-10-22 09:52:02 +0300767 c.UpdateCounter(cRestSubDelRespToXapp)
Anssi Mannilaf682ace2021-09-28 13:11:25 +0300768 return common.UnsubscribeNoContentCode
archaggeafbf95f2021-04-14 08:54:05 +0300769 } else {
770 if restSubscription.SubReqOngoing == true {
771 err := fmt.Errorf("Handling of the REST Subscription Request still ongoing %s", restSubId)
772 xapp.Logger.Error("%s", err.Error())
Anssi Mannilac7da4ee2021-10-22 09:52:02 +0300773 c.UpdateCounter(cRestSubDelFailToXapp)
Anssi Mannilaf682ace2021-09-28 13:11:25 +0300774 return common.UnsubscribeBadRequestCode
archaggeafbf95f2021-04-14 08:54:05 +0300775 } else if restSubscription.SubDelReqOngoing == true {
776 // Previous request for same restSubId still ongoing
Anssi Mannila3d80b722021-11-12 13:17:15 +0200777 c.UpdateCounter(cRestSubDelRespToXapp)
778 return common.UnsubscribeNoContentCode
archaggeafbf95f2021-04-14 08:54:05 +0300779 }
780 }
781 }
782
783 xAppRmrEndPoint := restSubscription.xAppRmrEndPoint
784 go func() {
Anssi Mannilaf682ace2021-09-28 13:11:25 +0300785 xapp.Logger.Debug("Deleteting handler: processing instances = %v", restSubscription.InstanceIds)
archaggeafbf95f2021-04-14 08:54:05 +0300786 for _, instanceId := range restSubscription.InstanceIds {
Anssi Mannila54838ed2021-11-19 11:25:01 +0200787 xAppEventInstanceID, err := c.SubscriptionDeleteHandler(&restSubId, &xAppRmrEndPoint, &restSubscription.Meid, instanceId, 0)
Konstantinos Archangelofe93b00f2021-06-03 10:00:19 +0000788
archaggeafbf95f2021-04-14 08:54:05 +0300789 if err != nil {
790 xapp.Logger.Error("%s", err.Error())
archaggeafbf95f2021-04-14 08:54:05 +0300791 }
Anssi Mannilaf682ace2021-09-28 13:11:25 +0300792 xapp.Logger.Debug("Deleteting instanceId = %v", instanceId)
Konstantinos Archangelofe93b00f2021-06-03 10:00:19 +0000793 restSubscription.DeleteXappIdToE2Id(xAppEventInstanceID)
794 restSubscription.DeleteE2InstanceId(instanceId)
archaggeafbf95f2021-04-14 08:54:05 +0300795 }
Anssi Mannila3cdd2e02021-10-14 12:35:41 +0300796 c.restDuplicateCtrl.DeleteLastKnownRestSubsIdBasedOnMd5sum(restSubscription.lastReqMd5sum)
archaggeafbf95f2021-04-14 08:54:05 +0300797 c.registry.DeleteRESTSubscription(&restSubId)
Konstantinos Archangelof268d7152021-06-14 12:24:00 +0300798 c.RemoveRESTSubscriptionFromDb(restSubId)
archaggeafbf95f2021-04-14 08:54:05 +0300799 }()
800
Konstantinos Archangelof27433e72021-05-31 08:30:35 +0000801 c.UpdateCounter(cRestSubDelRespToXapp)
Anssi Mannilaf682ace2021-09-28 13:11:25 +0300802 return common.UnsubscribeNoContentCode
Juha Hyttinenc9eb08a2020-02-28 08:53:33 +0200803}
804
archaggeafbf95f2021-04-14 08:54:05 +0300805//-------------------------------------------------------------------
806//
807//-------------------------------------------------------------------
Anssi Mannila54838ed2021-11-19 11:25:01 +0200808func (c *Control) SubscriptionDeleteHandler(restSubId *string, endPoint *string, meid *string, instanceId uint32, waitRouteCleanupTime time.Duration) (int64, error) {
archaggeafbf95f2021-04-14 08:54:05 +0300809
Konstantinos Archangelofe93b00f2021-06-03 10:00:19 +0000810 var xAppEventInstanceID int64
811 subs, err := c.registry.GetSubscriptionFirstMatch([]uint32{instanceId})
812 if err != nil {
Anssi Mannilaf682ace2021-09-28 13:11:25 +0300813 xapp.Logger.Debug("Subscription Delete Handler subscription for restSubId=%v, E2EventInstanceID=%v not found %s",
Konstantinos Archangelofe93b00f2021-06-03 10:00:19 +0000814 restSubId, instanceId, idstring(err, nil))
815 return xAppEventInstanceID, nil
816 }
817
818 xAppEventInstanceID = int64(subs.ReqId.Id)
819 trans := c.tracker.NewXappTransaction(xapp.NewRmrEndpoint(*endPoint), *restSubId, e2ap.RequestId{subs.ReqId.Id, 0}, &xapp.RMRMeid{RanName: *meid})
archaggeafbf95f2021-04-14 08:54:05 +0300820 if trans == nil {
821 err := fmt.Errorf("XAPP-SubDelReq transaction not created. restSubId %s, endPoint %s, meid %s, instanceId %v", *restSubId, *endPoint, *meid, instanceId)
822 xapp.Logger.Error("%s", err.Error())
823 }
824 defer trans.Release()
825
Konstantinos Archangelofe93b00f2021-06-03 10:00:19 +0000826 err = c.tracker.Track(trans)
archaggeafbf95f2021-04-14 08:54:05 +0300827 if err != nil {
828 err := fmt.Errorf("XAPP-SubDelReq %s:", idstring(err, trans))
829 xapp.Logger.Error("%s", err.Error())
Konstantinos Archangelofe93b00f2021-06-03 10:00:19 +0000830 return xAppEventInstanceID, &time.ParseError{}
archaggeafbf95f2021-04-14 08:54:05 +0300831 }
832 //
833 // Wake subs delete
834 //
Anssi Mannilac7da4ee2021-10-22 09:52:02 +0300835 subs.OngoingDelCount++
Anssi Mannila54838ed2021-11-19 11:25:01 +0200836 go c.handleSubscriptionDelete(subs, trans, waitRouteCleanupTime)
archaggeafbf95f2021-04-14 08:54:05 +0300837 trans.WaitEvent(0) //blocked wait as timeout is handled in subs side
Anssi Mannilac7da4ee2021-10-22 09:52:02 +0300838 subs.OngoingDelCount--
archaggeafbf95f2021-04-14 08:54:05 +0300839
840 xapp.Logger.Debug("XAPP-SubDelReq: Handling event %s ", idstring(nil, trans, subs))
841
Markku Virtanenfe2cdab2021-05-21 10:59:29 +0000842 c.registry.RemoveFromSubscription(subs, trans, waitRouteCleanup_ms, c)
archaggeafbf95f2021-04-14 08:54:05 +0300843
Konstantinos Archangelofe93b00f2021-06-03 10:00:19 +0000844 return xAppEventInstanceID, nil
archaggeafbf95f2021-04-14 08:54:05 +0300845}
846
847//-------------------------------------------------------------------
848//
849//-------------------------------------------------------------------
Juha Hyttinenc9eb08a2020-02-28 08:53:33 +0200850
Juha Hyttinen83ada002020-01-30 10:36:33 +0200851func (c *Control) rmrSendToE2T(desc string, subs *Subscription, trans *TransactionSubs) (err error) {
Juha Hyttinen9dc5adc2020-08-13 10:02:40 +0300852 params := &xapp.RMRParams{}
Juha Hyttinene406a342020-01-13 13:02:26 +0200853 params.Mtype = trans.GetMtype()
Juha Hyttinenaada6452020-04-07 08:47:58 +0300854 params.SubId = int(subs.GetReqId().InstanceId)
Juha Hyttinen86a46202020-01-14 12:49:09 +0200855 params.Xid = ""
Juha Hyttinene406a342020-01-13 13:02:26 +0200856 params.Meid = subs.GetMeid()
857 params.Src = ""
Juha Hyttinen63284a22020-01-15 10:45:11 +0200858 params.PayloadLen = len(trans.Payload.Buf)
859 params.Payload = trans.Payload.Buf
Juha Hyttinene406a342020-01-13 13:02:26 +0200860 params.Mbuf = nil
Anssi Mannilaf682ace2021-09-28 13:11:25 +0300861 xapp.Logger.Debug("MSG to E2T: %s %s %s", desc, trans.String(), params.String())
Abukar Mohamedfbd4df52021-03-11 06:13:27 +0000862 err = c.SendWithRetry(params, false, 5)
863 if err != nil {
864 xapp.Logger.Error("rmrSendToE2T: Send failed: %+v", err)
865 }
866 return err
kalnagye0018682019-09-26 16:28:25 +0200867}
868
Juha Hyttinen83ada002020-01-30 10:36:33 +0200869func (c *Control) rmrSendToXapp(desc string, subs *Subscription, trans *TransactionXapp) (err error) {
870
Juha Hyttinen9dc5adc2020-08-13 10:02:40 +0300871 params := &xapp.RMRParams{}
Juha Hyttinen63284a22020-01-15 10:45:11 +0200872 params.Mtype = trans.GetMtype()
Juha Hyttinenaada6452020-04-07 08:47:58 +0300873 params.SubId = int(subs.GetReqId().InstanceId)
Juha Hyttinene406a342020-01-13 13:02:26 +0200874 params.Xid = trans.GetXid()
Juha Hyttinen86a46202020-01-14 12:49:09 +0200875 params.Meid = trans.GetMeid()
Juha Hyttinene406a342020-01-13 13:02:26 +0200876 params.Src = ""
Juha Hyttinen63284a22020-01-15 10:45:11 +0200877 params.PayloadLen = len(trans.Payload.Buf)
878 params.Payload = trans.Payload.Buf
Juha Hyttinene406a342020-01-13 13:02:26 +0200879 params.Mbuf = nil
Anssi Mannilaf682ace2021-09-28 13:11:25 +0300880 xapp.Logger.Debug("MSG to XAPP: %s %s %s", desc, trans.String(), params.String())
Abukar Mohamedfbd4df52021-03-11 06:13:27 +0000881 err = c.SendWithRetry(params, false, 5)
882 if err != nil {
883 xapp.Logger.Error("rmrSendToXapp: Send failed: %+v", err)
884 }
885 return err
Juha Hyttinene406a342020-01-13 13:02:26 +0200886}
887
Juha Hyttinen9dc5adc2020-08-13 10:02:40 +0300888func (c *Control) Consume(msg *xapp.RMRParams) (err error) {
889 if c.RMRClient == nil {
Juha Hyttinen5f8ffa02020-02-06 15:28:59 +0200890 err = fmt.Errorf("Rmr object nil can handle %s", msg.String())
891 xapp.Logger.Error("%s", err.Error())
892 return
893 }
894 c.CntRecvMsg++
895
Juha Hyttinen9dc5adc2020-08-13 10:02:40 +0300896 defer c.RMRClient.Free(msg.Mbuf)
Juha Hyttinen83ada002020-01-30 10:36:33 +0200897
Juha Hyttinena8a908d2020-05-26 15:12:47 +0300898 // xapp-frame might use direct access to c buffer and
899 // when msg.Mbuf is freed, someone might take it into use
900 // and payload data might be invalid inside message handle function
901 //
902 // subscriptions won't load system a lot so there is no
903 // real performance hit by cloning buffer into new go byte slice
904 cPay := append(msg.Payload[:0:0], msg.Payload...)
905 msg.Payload = cPay
906 msg.PayloadLen = len(cPay)
907
Anssi Mannila90fa0212019-12-12 10:47:47 +0200908 switch msg.Mtype {
Juha Hyttinenc9eb08a2020-02-28 08:53:33 +0200909 case xapp.RIC_SUB_REQ:
Juha Hyttinen422d0182020-01-17 13:37:05 +0200910 go c.handleXAPPSubscriptionRequest(msg)
Juha Hyttinenc9eb08a2020-02-28 08:53:33 +0200911 case xapp.RIC_SUB_RESP:
Juha Hyttinen422d0182020-01-17 13:37:05 +0200912 go c.handleE2TSubscriptionResponse(msg)
Juha Hyttinenc9eb08a2020-02-28 08:53:33 +0200913 case xapp.RIC_SUB_FAILURE:
Juha Hyttinen422d0182020-01-17 13:37:05 +0200914 go c.handleE2TSubscriptionFailure(msg)
Juha Hyttinenc9eb08a2020-02-28 08:53:33 +0200915 case xapp.RIC_SUB_DEL_REQ:
Juha Hyttinen422d0182020-01-17 13:37:05 +0200916 go c.handleXAPPSubscriptionDeleteRequest(msg)
Juha Hyttinenc9eb08a2020-02-28 08:53:33 +0200917 case xapp.RIC_SUB_DEL_RESP:
Juha Hyttinen422d0182020-01-17 13:37:05 +0200918 go c.handleE2TSubscriptionDeleteResponse(msg)
Juha Hyttinenc9eb08a2020-02-28 08:53:33 +0200919 case xapp.RIC_SUB_DEL_FAILURE:
Juha Hyttinen422d0182020-01-17 13:37:05 +0200920 go c.handleE2TSubscriptionDeleteFailure(msg)
Anssi Mannila90fa0212019-12-12 10:47:47 +0200921 default:
Anssi Mannilaf682ace2021-09-28 13:11:25 +0300922 xapp.Logger.Debug("Unknown Message Type '%d', discarding", msg.Mtype)
Balint Uvegescd3881b2019-10-02 15:01:43 +0000923 }
Juha Hyttinen5f8ffa02020-02-06 15:28:59 +0200924 return
Juha Hyttinen31797b42020-01-16 14:05:01 +0200925}
926
Juha Hyttinen422d0182020-01-17 13:37:05 +0200927//-------------------------------------------------------------------
928// handle from XAPP Subscription Request
929//------------------------------------------------------------------
Juha Hyttinen9dc5adc2020-08-13 10:02:40 +0300930func (c *Control) handleXAPPSubscriptionRequest(params *xapp.RMRParams) {
Anssi Mannilaf682ace2021-09-28 13:11:25 +0300931 xapp.Logger.Debug("MSG from XAPP: %s", params.String())
Anssi Mannila4abf1802021-01-28 13:06:46 +0200932 c.UpdateCounter(cSubReqFromXapp)
Juha Hyttinen422d0182020-01-17 13:37:05 +0200933
Anssi Mannilac7da4ee2021-10-22 09:52:02 +0300934 if c.e2IfState.IsE2ConnectionUp(&params.Meid.RanName) == false {
935 xapp.Logger.Error("No E2 connection for ranName %v", params.Meid.RanName)
936 return
937 }
938
Juha Hyttinen422d0182020-01-17 13:37:05 +0200939 subReqMsg, err := c.e2ap.UnpackSubscriptionRequest(params.Payload)
940 if err != nil {
Juha Hyttinen83ada002020-01-30 10:36:33 +0200941 xapp.Logger.Error("XAPP-SubReq: %s", idstring(err, params))
Juha Hyttinen422d0182020-01-17 13:37:05 +0200942 return
943 }
944
Anssi Mannila4c626a22021-02-11 12:50:48 +0200945 trans := c.tracker.NewXappTransaction(xapp.NewRmrEndpoint(params.Src), params.Xid, subReqMsg.RequestId, params.Meid)
Juha Hyttinen83ada002020-01-30 10:36:33 +0200946 if trans == nil {
947 xapp.Logger.Error("XAPP-SubReq: %s", idstring(fmt.Errorf("transaction not created"), params))
Juha Hyttinen422d0182020-01-17 13:37:05 +0200948 return
949 }
950 defer trans.Release()
951
Anssi Mannila6b3796f2021-02-12 09:11:35 +0200952 if err = c.tracker.Track(trans); err != nil {
Juha Hyttinen83ada002020-01-30 10:36:33 +0200953 xapp.Logger.Error("XAPP-SubReq: %s", idstring(err, trans))
954 return
955 }
956
Anssi Mannilaf682ace2021-09-28 13:11:25 +0300957 subs, _, err := c.registry.AssignToSubscription(trans, subReqMsg, c.ResetTestFlag, c, true)
Juha Hyttinen422d0182020-01-17 13:37:05 +0200958 if err != nil {
Juha Hyttinen83ada002020-01-30 10:36:33 +0200959 xapp.Logger.Error("XAPP-SubReq: %s", idstring(err, trans))
Juha Hyttinen422d0182020-01-17 13:37:05 +0200960 return
961 }
962
Anssi Mannila6b3796f2021-02-12 09:11:35 +0200963 c.wakeSubscriptionRequest(subs, trans)
964}
965
966//-------------------------------------------------------------------
967// Wake Subscription Request to E2node
968//------------------------------------------------------------------
969func (c *Control) wakeSubscriptionRequest(subs *Subscription, trans *TransactionXapp) {
970
Anssi Mannilaf682ace2021-09-28 13:11:25 +0300971 e2SubscriptionDirectives, _ := c.GetE2SubscriptionDirectives(nil)
Anssi Mannilac7da4ee2021-10-22 09:52:02 +0300972 subs.OngoingReqCount++
Anssi Mannila54838ed2021-11-19 11:25:01 +0200973 go c.handleSubscriptionCreate(subs, trans, e2SubscriptionDirectives, waitRouteCleanup_ms)
Juha Hyttinen422d0182020-01-17 13:37:05 +0200974 event, _ := trans.WaitEvent(0) //blocked wait as timeout is handled in subs side
Anssi Mannilac7da4ee2021-10-22 09:52:02 +0300975 subs.OngoingReqCount--
Anssi Mannila6b3796f2021-02-12 09:11:35 +0200976 var err error
Juha Hyttinen422d0182020-01-17 13:37:05 +0200977 if event != nil {
978 switch themsg := event.(type) {
979 case *e2ap.E2APSubscriptionResponse:
Anssi Mannila4c626a22021-02-11 12:50:48 +0200980 themsg.RequestId.Id = trans.RequestId.Id
Juha Hyttinen422d0182020-01-17 13:37:05 +0200981 trans.Mtype, trans.Payload, err = c.e2ap.PackSubscriptionResponse(themsg)
982 if err == nil {
Anssi Mannila64a0df42020-02-26 09:46:03 +0200983 trans.Release()
Anssi Mannila4abf1802021-01-28 13:06:46 +0200984 c.UpdateCounter(cSubRespToXapp)
Juha Hyttinen83ada002020-01-30 10:36:33 +0200985 c.rmrSendToXapp("", subs, trans)
Juha Hyttinen422d0182020-01-17 13:37:05 +0200986 return
987 }
988 case *e2ap.E2APSubscriptionFailure:
Anssi Mannila4c626a22021-02-11 12:50:48 +0200989 themsg.RequestId.Id = trans.RequestId.Id
Juha Hyttinen422d0182020-01-17 13:37:05 +0200990 trans.Mtype, trans.Payload, err = c.e2ap.PackSubscriptionFailure(themsg)
991 if err == nil {
Anssi Mannila4abf1802021-01-28 13:06:46 +0200992 c.UpdateCounter(cSubFailToXapp)
Juha Hyttinen83ada002020-01-30 10:36:33 +0200993 c.rmrSendToXapp("", subs, trans)
Juha Hyttinen422d0182020-01-17 13:37:05 +0200994 }
Juha Hyttinen422d0182020-01-17 13:37:05 +0200995 default:
Juha Hyttinen31797b42020-01-16 14:05:01 +0200996 break
997 }
998 }
Anssi Mannilaf682ace2021-09-28 13:11:25 +0300999 xapp.Logger.Debug("XAPP-SubReq: failed %s", idstring(err, trans, subs))
Juha Hyttinen31797b42020-01-16 14:05:01 +02001000}
1001
Juha Hyttinen422d0182020-01-17 13:37:05 +02001002//-------------------------------------------------------------------
1003// handle from XAPP Subscription Delete Request
1004//------------------------------------------------------------------
Juha Hyttinen9dc5adc2020-08-13 10:02:40 +03001005func (c *Control) handleXAPPSubscriptionDeleteRequest(params *xapp.RMRParams) {
Anssi Mannilaf682ace2021-09-28 13:11:25 +03001006 xapp.Logger.Debug("MSG from XAPP: %s", params.String())
Anssi Mannila4abf1802021-01-28 13:06:46 +02001007 c.UpdateCounter(cSubDelReqFromXapp)
Juha Hyttinen422d0182020-01-17 13:37:05 +02001008
Anssi Mannilac7da4ee2021-10-22 09:52:02 +03001009 if c.e2IfState.IsE2ConnectionUp(&params.Meid.RanName) == false {
1010 xapp.Logger.Error("No E2 connection for ranName %v", params.Meid.RanName)
1011 return
1012 }
1013
Juha Hyttinen422d0182020-01-17 13:37:05 +02001014 subDelReqMsg, err := c.e2ap.UnpackSubscriptionDeleteRequest(params.Payload)
Juha Hyttinen31797b42020-01-16 14:05:01 +02001015 if err != nil {
Juha Hyttinen83ada002020-01-30 10:36:33 +02001016 xapp.Logger.Error("XAPP-SubDelReq %s", idstring(err, params))
Juha Hyttinen422d0182020-01-17 13:37:05 +02001017 return
1018 }
1019
Anssi Mannila4c626a22021-02-11 12:50:48 +02001020 trans := c.tracker.NewXappTransaction(xapp.NewRmrEndpoint(params.Src), params.Xid, subDelReqMsg.RequestId, params.Meid)
Juha Hyttinen83ada002020-01-30 10:36:33 +02001021 if trans == nil {
1022 xapp.Logger.Error("XAPP-SubDelReq: %s", idstring(fmt.Errorf("transaction not created"), params))
Juha Hyttinen422d0182020-01-17 13:37:05 +02001023 return
1024 }
1025 defer trans.Release()
1026
Juha Hyttinen83ada002020-01-30 10:36:33 +02001027 err = c.tracker.Track(trans)
Juha Hyttinen422d0182020-01-17 13:37:05 +02001028 if err != nil {
Juha Hyttinen83ada002020-01-30 10:36:33 +02001029 xapp.Logger.Error("XAPP-SubReq: %s", idstring(err, trans))
1030 return
1031 }
1032
Juha Hyttinen47942b42020-02-27 10:41:43 +02001033 subs, err := c.registry.GetSubscriptionFirstMatch([]uint32{trans.GetSubId()})
Juha Hyttinen83ada002020-01-30 10:36:33 +02001034 if err != nil {
1035 xapp.Logger.Error("XAPP-SubDelReq: %s", idstring(err, trans))
Juha Hyttinen422d0182020-01-17 13:37:05 +02001036 return
1037 }
1038
Juha Hyttinen422d0182020-01-17 13:37:05 +02001039 //
1040 // Wake subs delete
1041 //
Anssi Mannilac7da4ee2021-10-22 09:52:02 +03001042 subs.OngoingDelCount++
Anssi Mannila54838ed2021-11-19 11:25:01 +02001043 go c.handleSubscriptionDelete(subs, trans, waitRouteCleanup_ms)
Juha Hyttinen422d0182020-01-17 13:37:05 +02001044 trans.WaitEvent(0) //blocked wait as timeout is handled in subs side
Anssi Mannilac7da4ee2021-10-22 09:52:02 +03001045 subs.OngoingDelCount--
Juha Hyttinen422d0182020-01-17 13:37:05 +02001046
Juha Hyttinen83ada002020-01-30 10:36:33 +02001047 xapp.Logger.Debug("XAPP-SubDelReq: Handling event %s ", idstring(nil, trans, subs))
1048
Anssi Mannilac92b4212020-12-07 14:59:34 +02001049 if subs.NoRespToXapp == true {
1050 // Do no send delete responses to xapps due to submgr restart is deleting uncompleted subscriptions
Anssi Mannilaf682ace2021-09-28 13:11:25 +03001051 xapp.Logger.Debug("XAPP-SubDelReq: subs.NoRespToXapp == true")
Anssi Mannilac92b4212020-12-07 14:59:34 +02001052 return
1053 }
1054
1055 // Whatever is received success, fail or timeout, send successful delete response
Juha Hyttinen422d0182020-01-17 13:37:05 +02001056 subDelRespMsg := &e2ap.E2APSubscriptionDeleteResponse{}
Anssi Mannila4c626a22021-02-11 12:50:48 +02001057 subDelRespMsg.RequestId.Id = trans.RequestId.Id
1058 subDelRespMsg.RequestId.InstanceId = subs.GetReqId().RequestId.InstanceId
Juha Hyttinen422d0182020-01-17 13:37:05 +02001059 subDelRespMsg.FunctionId = subs.SubReqMsg.FunctionId
1060 trans.Mtype, trans.Payload, err = c.e2ap.PackSubscriptionDeleteResponse(subDelRespMsg)
1061 if err == nil {
Anssi Mannila4abf1802021-01-28 13:06:46 +02001062 c.UpdateCounter(cSubDelRespToXapp)
Juha Hyttinen83ada002020-01-30 10:36:33 +02001063 c.rmrSendToXapp("", subs, trans)
Juha Hyttinen422d0182020-01-17 13:37:05 +02001064 }
1065}
1066
1067//-------------------------------------------------------------------
1068// SUBS CREATE Handling
1069//-------------------------------------------------------------------
Anssi Mannila54838ed2021-11-19 11:25:01 +02001070func (c *Control) handleSubscriptionCreate(subs *Subscription, parentTrans *TransactionXapp, e2SubscriptionDirectives *E2SubscriptionDirectives, waitRouteCleanupTime time.Duration) {
Juha Hyttinen422d0182020-01-17 13:37:05 +02001071
Anssi Mannilaf682ace2021-09-28 13:11:25 +03001072 var event interface{} = nil
Anssi Mannilac92b4212020-12-07 14:59:34 +02001073 var removeSubscriptionFromDb bool = false
Juha Hyttinen83ada002020-01-30 10:36:33 +02001074 trans := c.tracker.NewSubsTransaction(subs)
Juha Hyttinen422d0182020-01-17 13:37:05 +02001075 subs.WaitTransactionTurn(trans)
1076 defer subs.ReleaseTransactionTurn(trans)
1077 defer trans.Release()
1078
Juha Hyttinen83ada002020-01-30 10:36:33 +02001079 xapp.Logger.Debug("SUBS-SubReq: Handling %s ", idstring(nil, trans, subs, parentTrans))
Juha Hyttinen422d0182020-01-17 13:37:05 +02001080
Juha Hyttinen83ada002020-01-30 10:36:33 +02001081 subRfMsg, valid := subs.GetCachedResponse()
1082 if subRfMsg == nil && valid == true {
Anssi Mannilaf682ace2021-09-28 13:11:25 +03001083 event = c.sendE2TSubscriptionRequest(subs, trans, parentTrans, e2SubscriptionDirectives)
Anssi Mannila6d629ad2021-01-25 09:59:56 +02001084 switch event.(type) {
1085 case *e2ap.E2APSubscriptionResponse:
1086 subRfMsg, valid = subs.SetCachedResponse(event, true)
1087 subs.SubRespRcvd = true
1088 case *e2ap.E2APSubscriptionFailure:
Anssi Mannila6d629ad2021-01-25 09:59:56 +02001089 subRfMsg, valid = subs.SetCachedResponse(event, false)
Anssi Mannilaf682ace2021-09-28 13:11:25 +03001090 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 +02001091 case *SubmgrRestartTestEvent:
Anssi Mannila54838ed2021-11-19 11:25:01 +02001092 // 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 +02001093 xapp.Logger.Debug("Test restart flag is active. Dropping this transaction to test restart case")
Anssi Mannila54838ed2021-11-19 11:25:01 +02001094 subRfMsg, valid = subs.SetCachedResponse(event, false)
1095 parentTrans.SendEvent(subRfMsg, 0)
1096 return
Anssi Mannilaf682ace2021-09-28 13:11:25 +03001097 case *PackSubscriptionRequestErrortEvent, *SDLWriteErrortEvent:
1098 subRfMsg, valid = subs.SetCachedResponse(event, false)
Anssi Mannila6d629ad2021-01-25 09:59:56 +02001099 default:
Anssi Mannila3d80b722021-11-12 13:17:15 +02001100 // Timer expiry
Anssi Mannilaf682ace2021-09-28 13:11:25 +03001101 if subs.PolicyUpdate == false {
1102 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 +03001103 subRfMsg, valid = subs.SetCachedResponse(nil, false)
1104 c.sendE2TSubscriptionDeleteRequest(subs, trans, parentTrans)
Anssi Mannila54838ed2021-11-19 11:25:01 +02001105 } else {
1106 subRfMsg, valid = subs.SetCachedResponse(nil, true)
Anssi Mannilaf682ace2021-09-28 13:11:25 +03001107 }
Juha Hyttinen83ada002020-01-30 10:36:33 +02001108 }
1109 xapp.Logger.Debug("SUBS-SubReq: Handling (e2t response %s) %s", typeofSubsMessage(subRfMsg), idstring(nil, trans, subs, parentTrans))
1110 } else {
1111 xapp.Logger.Debug("SUBS-SubReq: Handling (cached response %s) %s", typeofSubsMessage(subRfMsg), idstring(nil, trans, subs, parentTrans))
Juha Hyttinen422d0182020-01-17 13:37:05 +02001112 }
Anssi Mannila54838ed2021-11-19 11:25:01 +02001113 if valid == false {
1114 removeSubscriptionFromDb = true
1115 }
Juha Hyttinen422d0182020-01-17 13:37:05 +02001116
Anssi Mannilaf682ace2021-09-28 13:11:25 +03001117 err := c.UpdateSubscriptionInDB(subs, removeSubscriptionFromDb)
1118 if err != nil {
Anssi Mannila54838ed2021-11-19 11:25:01 +02001119 valid = false
Anssi Mannilaf682ace2021-09-28 13:11:25 +03001120 c.sendE2TSubscriptionDeleteRequest(subs, trans, parentTrans)
1121 }
1122
Anssi Mannila27385172021-12-22 09:41:54 +02001123 // Now RemoveFromSubscription in here to avoid race conditions (mostly concerns delete)
Juha Hyttinen429cfe62020-03-31 11:23:02 +03001124 if valid == false {
Anssi Mannila54838ed2021-11-19 11:25:01 +02001125 c.registry.RemoveFromSubscription(subs, parentTrans, waitRouteCleanupTime, c)
Juha Hyttinen429cfe62020-03-31 11:23:02 +03001126 }
Anssi Mannilac92b4212020-12-07 14:59:34 +02001127
Juha Hyttinen83ada002020-01-30 10:36:33 +02001128 parentTrans.SendEvent(subRfMsg, 0)
Juha Hyttinen422d0182020-01-17 13:37:05 +02001129}
1130
1131//-------------------------------------------------------------------
1132// SUBS DELETE Handling
1133//-------------------------------------------------------------------
Juha Hyttinen3944a222020-01-24 11:51:46 +02001134
Anssi Mannila54838ed2021-11-19 11:25:01 +02001135func (c *Control) handleSubscriptionDelete(subs *Subscription, parentTrans *TransactionXapp, waitRouteCleanupTime time.Duration) {
Juha Hyttinen422d0182020-01-17 13:37:05 +02001136
Juha Hyttinen83ada002020-01-30 10:36:33 +02001137 trans := c.tracker.NewSubsTransaction(subs)
Juha Hyttinen422d0182020-01-17 13:37:05 +02001138 subs.WaitTransactionTurn(trans)
1139 defer subs.ReleaseTransactionTurn(trans)
1140 defer trans.Release()
1141
Juha Hyttinen83ada002020-01-30 10:36:33 +02001142 xapp.Logger.Debug("SUBS-SubDelReq: Handling %s", idstring(nil, trans, subs, parentTrans))
Juha Hyttinen422d0182020-01-17 13:37:05 +02001143
Juha Hyttinen3944a222020-01-24 11:51:46 +02001144 subs.mutex.Lock()
Anssi Mannila4abf1802021-01-28 13:06:46 +02001145
Juha Hyttinen3944a222020-01-24 11:51:46 +02001146 if subs.valid && subs.EpList.HasEndpoint(parentTrans.GetEndpoint()) && subs.EpList.Size() == 1 {
1147 subs.valid = false
1148 subs.mutex.Unlock()
1149 c.sendE2TSubscriptionDeleteRequest(subs, trans, parentTrans)
1150 } else {
1151 subs.mutex.Unlock()
1152 }
Anssi Mannila27385172021-12-22 09:41:54 +02001153
1154 // Now RemoveFromSubscription in here to avoid race conditions (mostly concerns delete)
Anssi Mannila54838ed2021-11-19 11:25:01 +02001155 c.registry.RemoveFromSubscription(subs, parentTrans, waitRouteCleanupTime, c)
Juha Hyttinen47942b42020-02-27 10:41:43 +02001156 parentTrans.SendEvent(nil, 0)
Juha Hyttinen422d0182020-01-17 13:37:05 +02001157}
1158
1159//-------------------------------------------------------------------
1160// send to E2T Subscription Request
1161//-------------------------------------------------------------------
Anssi Mannilaf682ace2021-09-28 13:11:25 +03001162func (c *Control) sendE2TSubscriptionRequest(subs *Subscription, trans *TransactionSubs, parentTrans *TransactionXapp, e2SubscriptionDirectives *E2SubscriptionDirectives) interface{} {
Juha Hyttinen422d0182020-01-17 13:37:05 +02001163 var err error
1164 var event interface{} = nil
1165 var timedOut bool = false
Konstantinos Archangelof26dfa712021-06-04 12:10:26 +00001166 const ricRequestorId = 123
Juha Hyttinen422d0182020-01-17 13:37:05 +02001167
1168 subReqMsg := subs.SubReqMsg
Juha Hyttinen83ada002020-01-30 10:36:33 +02001169 subReqMsg.RequestId = subs.GetReqId().RequestId
Konstantinos Archangelof26dfa712021-06-04 12:10:26 +00001170 subReqMsg.RequestId.Id = ricRequestorId
Juha Hyttinen422d0182020-01-17 13:37:05 +02001171 trans.Mtype, trans.Payload, err = c.e2ap.PackSubscriptionRequest(subReqMsg)
1172 if err != nil {
Anssi Mannilab43397e2021-11-16 12:06:16 +02001173 xapp.Logger.Error("SUBS-SubReq ASN1 pack error: %s", idstring(err, trans, subs, parentTrans))
Anssi Mannilaf682ace2021-09-28 13:11:25 +03001174 return &PackSubscriptionRequestErrortEvent{
1175 ErrorInfo{
1176 ErrorSource: models.SubscriptionInstanceErrorSourceASN1,
1177 ErrorCause: err.Error(),
1178 },
1179 }
Juha Hyttinen422d0182020-01-17 13:37:05 +02001180 }
1181
Anssi Mannilac92b4212020-12-07 14:59:34 +02001182 // 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 +03001183 err = c.WriteSubscriptionToDb(subs)
1184 if err != nil {
1185 return &SDLWriteErrortEvent{
1186 ErrorInfo{
1187 ErrorSource: models.SubscriptionInstanceErrorSourceDBAAS,
1188 ErrorCause: err.Error(),
1189 },
1190 }
1191 }
Markku Virtanenfe2cdab2021-05-21 10:59:29 +00001192
Anssi Mannilaf682ace2021-09-28 13:11:25 +03001193 for retries := int64(0); retries < e2SubscriptionDirectives.E2MaxTryCount; retries++ {
Juha Hyttinen83ada002020-01-30 10:36:33 +02001194 desc := fmt.Sprintf("(retry %d)", retries)
Anssi Mannila4abf1802021-01-28 13:06:46 +02001195 if retries == 0 {
1196 c.UpdateCounter(cSubReqToE2)
1197 } else {
1198 c.UpdateCounter(cSubReReqToE2)
1199 }
Juha Hyttinen83ada002020-01-30 10:36:33 +02001200 c.rmrSendToE2T(desc, subs, trans)
Anssi Mannilac92b4212020-12-07 14:59:34 +02001201 if subs.DoNotWaitSubResp == false {
Anssi Mannilaf682ace2021-09-28 13:11:25 +03001202 event, timedOut = trans.WaitEvent(e2SubscriptionDirectives.E2TimeoutTimerValue)
Anssi Mannilac92b4212020-12-07 14:59:34 +02001203 if timedOut {
Anssi Mannila4abf1802021-01-28 13:06:46 +02001204 c.UpdateCounter(cSubReqTimerExpiry)
Anssi Mannilac92b4212020-12-07 14:59:34 +02001205 continue
1206 }
1207 } else {
1208 // Simulating case where subscrition request has been sent but response has not been received before restart
1209 event = &SubmgrRestartTestEvent{}
Anssi Mannilaf682ace2021-09-28 13:11:25 +03001210 xapp.Logger.Debug("Restart event, DoNotWaitSubResp == true")
Juha Hyttinen422d0182020-01-17 13:37:05 +02001211 }
1212 break
1213 }
Juha Hyttinen83ada002020-01-30 10:36:33 +02001214 xapp.Logger.Debug("SUBS-SubReq: Response handling event(%s) %s", typeofSubsMessage(event), idstring(nil, trans, subs, parentTrans))
Juha Hyttinen422d0182020-01-17 13:37:05 +02001215 return event
1216}
1217
1218//-------------------------------------------------------------------
1219// send to E2T Subscription Delete Request
1220//-------------------------------------------------------------------
1221
Juha Hyttinen83ada002020-01-30 10:36:33 +02001222func (c *Control) sendE2TSubscriptionDeleteRequest(subs *Subscription, trans *TransactionSubs, parentTrans *TransactionXapp) interface{} {
Juha Hyttinen422d0182020-01-17 13:37:05 +02001223 var err error
1224 var event interface{}
1225 var timedOut bool
Konstantinos Archangelof26dfa712021-06-04 12:10:26 +00001226 const ricRequestorId = 123
Juha Hyttinen422d0182020-01-17 13:37:05 +02001227
1228 subDelReqMsg := &e2ap.E2APSubscriptionDeleteRequest{}
Juha Hyttinen83ada002020-01-30 10:36:33 +02001229 subDelReqMsg.RequestId = subs.GetReqId().RequestId
Konstantinos Archangelof26dfa712021-06-04 12:10:26 +00001230 subDelReqMsg.RequestId.Id = ricRequestorId
Juha Hyttinenaf91f972020-01-24 08:38:47 +02001231 subDelReqMsg.FunctionId = subs.SubReqMsg.FunctionId
Juha Hyttinen422d0182020-01-17 13:37:05 +02001232 trans.Mtype, trans.Payload, err = c.e2ap.PackSubscriptionDeleteRequest(subDelReqMsg)
1233 if err != nil {
Juha Hyttinen83ada002020-01-30 10:36:33 +02001234 xapp.Logger.Error("SUBS-SubDelReq: %s", idstring(err, trans, subs, parentTrans))
Juha Hyttinen422d0182020-01-17 13:37:05 +02001235 return event
1236 }
1237
1238 for retries := uint64(0); retries < e2tMaxSubDelReqTryCount; retries++ {
Juha Hyttinen83ada002020-01-30 10:36:33 +02001239 desc := fmt.Sprintf("(retry %d)", retries)
Anssi Mannila4abf1802021-01-28 13:06:46 +02001240 if retries == 0 {
1241 c.UpdateCounter(cSubDelReqToE2)
1242 } else {
1243 c.UpdateCounter(cSubDelReReqToE2)
1244 }
Juha Hyttinen83ada002020-01-30 10:36:33 +02001245 c.rmrSendToE2T(desc, subs, trans)
Juha Hyttinen422d0182020-01-17 13:37:05 +02001246 event, timedOut = trans.WaitEvent(e2tSubDelReqTime)
1247 if timedOut {
Anssi Mannila4abf1802021-01-28 13:06:46 +02001248 c.UpdateCounter(cSubDelReqTimerExpiry)
Juha Hyttinen422d0182020-01-17 13:37:05 +02001249 continue
1250 }
1251 break
1252 }
Juha Hyttinen83ada002020-01-30 10:36:33 +02001253 xapp.Logger.Debug("SUBS-SubDelReq: Response handling event(%s) %s", typeofSubsMessage(event), idstring(nil, trans, subs, parentTrans))
Juha Hyttinen422d0182020-01-17 13:37:05 +02001254 return event
1255}
1256
1257//-------------------------------------------------------------------
Anssi Mannila4abf1802021-01-28 13:06:46 +02001258// handle from E2T Subscription Response
Juha Hyttinen422d0182020-01-17 13:37:05 +02001259//-------------------------------------------------------------------
Juha Hyttinen9dc5adc2020-08-13 10:02:40 +03001260func (c *Control) handleE2TSubscriptionResponse(params *xapp.RMRParams) {
Anssi Mannilaf682ace2021-09-28 13:11:25 +03001261 xapp.Logger.Debug("MSG from E2T: %s", params.String())
Anssi Mannila4abf1802021-01-28 13:06:46 +02001262 c.UpdateCounter(cSubRespFromE2)
Anssi Mannila51122392021-05-25 11:51:31 +03001263
Juha Hyttinen422d0182020-01-17 13:37:05 +02001264 subRespMsg, err := c.e2ap.UnpackSubscriptionResponse(params.Payload)
1265 if err != nil {
Juha Hyttinen83ada002020-01-30 10:36:33 +02001266 xapp.Logger.Error("MSG-SubResp %s", idstring(err, params))
Juha Hyttinen422d0182020-01-17 13:37:05 +02001267 return
1268 }
Juha Hyttinenaada6452020-04-07 08:47:58 +03001269 subs, err := c.registry.GetSubscriptionFirstMatch([]uint32{subRespMsg.RequestId.InstanceId})
Juha Hyttinen422d0182020-01-17 13:37:05 +02001270 if err != nil {
Juha Hyttinen83ada002020-01-30 10:36:33 +02001271 xapp.Logger.Error("MSG-SubResp: %s", idstring(err, params))
Juha Hyttinen422d0182020-01-17 13:37:05 +02001272 return
Juha Hyttinen31797b42020-01-16 14:05:01 +02001273 }
1274 trans := subs.GetTransaction()
1275 if trans == nil {
Juha Hyttinen422d0182020-01-17 13:37:05 +02001276 err = fmt.Errorf("Ongoing transaction not found")
Juha Hyttinen83ada002020-01-30 10:36:33 +02001277 xapp.Logger.Error("MSG-SubResp: %s", idstring(err, params, subs))
Juha Hyttinenff8dccd2019-12-10 14:34:07 +02001278 return
Anssi Mannila2e99e2f2019-12-05 13:57:06 +02001279 }
Anssi Mannila54838ed2021-11-19 11:25:01 +02001280 xapp.Logger.Debug("SUBS-SubResp: Sending event, trans= %v", trans)
Juha Hyttinen422d0182020-01-17 13:37:05 +02001281 sendOk, timedOut := trans.SendEvent(subRespMsg, e2tRecvMsgTimeout)
1282 if sendOk == false {
1283 err = fmt.Errorf("Passing event to transaction failed: sendOk(%t) timedOut(%t)", sendOk, timedOut)
Juha Hyttinen83ada002020-01-30 10:36:33 +02001284 xapp.Logger.Error("MSG-SubResp: %s", idstring(err, trans, subs))
Peter Szilagyifbc56f92019-07-23 19:29:46 +00001285 }
Peter Szilagyifbc56f92019-07-23 19:29:46 +00001286 return
kalnagy45114752019-06-18 14:40:39 +02001287}
1288
Juha Hyttinen422d0182020-01-17 13:37:05 +02001289//-------------------------------------------------------------------
1290// handle from E2T Subscription Failure
1291//-------------------------------------------------------------------
Juha Hyttinen9dc5adc2020-08-13 10:02:40 +03001292func (c *Control) handleE2TSubscriptionFailure(params *xapp.RMRParams) {
Anssi Mannilaf682ace2021-09-28 13:11:25 +03001293 xapp.Logger.Debug("MSG from E2T: %s", params.String())
Anssi Mannila4abf1802021-01-28 13:06:46 +02001294 c.UpdateCounter(cSubFailFromE2)
Juha Hyttinen422d0182020-01-17 13:37:05 +02001295 subFailMsg, err := c.e2ap.UnpackSubscriptionFailure(params.Payload)
Peter Szilagyifbc56f92019-07-23 19:29:46 +00001296 if err != nil {
Juha Hyttinen83ada002020-01-30 10:36:33 +02001297 xapp.Logger.Error("MSG-SubFail %s", idstring(err, params))
Peter Szilagyifbc56f92019-07-23 19:29:46 +00001298 return
1299 }
Juha Hyttinenaada6452020-04-07 08:47:58 +03001300 subs, err := c.registry.GetSubscriptionFirstMatch([]uint32{subFailMsg.RequestId.InstanceId})
Juha Hyttinen31797b42020-01-16 14:05:01 +02001301 if err != nil {
Juha Hyttinen83ada002020-01-30 10:36:33 +02001302 xapp.Logger.Error("MSG-SubFail: %s", idstring(err, params))
Juha Hyttinenaafee7f2020-01-14 14:54:51 +02001303 return
1304 }
Juha Hyttinen422d0182020-01-17 13:37:05 +02001305 trans := subs.GetTransaction()
1306 if trans == nil {
1307 err = fmt.Errorf("Ongoing transaction not found")
Juha Hyttinen83ada002020-01-30 10:36:33 +02001308 xapp.Logger.Error("MSG-SubFail: %s", idstring(err, params, subs))
Anssi Mannila8046c702020-01-02 13:39:05 +02001309 return
1310 }
Juha Hyttinen422d0182020-01-17 13:37:05 +02001311 sendOk, timedOut := trans.SendEvent(subFailMsg, e2tRecvMsgTimeout)
1312 if sendOk == false {
1313 err = fmt.Errorf("Passing event to transaction failed: sendOk(%t) timedOut(%t)", sendOk, timedOut)
Juha Hyttinen83ada002020-01-30 10:36:33 +02001314 xapp.Logger.Error("MSG-SubFail: %s", idstring(err, trans, subs))
Juha Hyttinenaafee7f2020-01-14 14:54:51 +02001315 }
Anssi Mannila2e99e2f2019-12-05 13:57:06 +02001316 return
1317}
1318
Juha Hyttinen422d0182020-01-17 13:37:05 +02001319//-------------------------------------------------------------------
1320// handle from E2T Subscription Delete Response
1321//-------------------------------------------------------------------
Juha Hyttinen9dc5adc2020-08-13 10:02:40 +03001322func (c *Control) handleE2TSubscriptionDeleteResponse(params *xapp.RMRParams) (err error) {
Anssi Mannilaf682ace2021-09-28 13:11:25 +03001323 xapp.Logger.Debug("MSG from E2T: %s", params.String())
Anssi Mannila4abf1802021-01-28 13:06:46 +02001324 c.UpdateCounter(cSubDelRespFromE2)
Juha Hyttinen422d0182020-01-17 13:37:05 +02001325 subDelRespMsg, err := c.e2ap.UnpackSubscriptionDeleteResponse(params.Payload)
Anssi Mannila2e99e2f2019-12-05 13:57:06 +02001326 if err != nil {
Juha Hyttinen83ada002020-01-30 10:36:33 +02001327 xapp.Logger.Error("MSG-SubDelResp: %s", idstring(err, params))
Anssi Mannila2e99e2f2019-12-05 13:57:06 +02001328 return
1329 }
Juha Hyttinenaada6452020-04-07 08:47:58 +03001330 subs, err := c.registry.GetSubscriptionFirstMatch([]uint32{subDelRespMsg.RequestId.InstanceId})
Juha Hyttinen31797b42020-01-16 14:05:01 +02001331 if err != nil {
Juha Hyttinen83ada002020-01-30 10:36:33 +02001332 xapp.Logger.Error("MSG-SubDelResp: %s", idstring(err, params))
Juha Hyttinen0d064ec2020-01-09 09:08:53 +02001333 return
1334 }
Juha Hyttinen422d0182020-01-17 13:37:05 +02001335 trans := subs.GetTransaction()
1336 if trans == nil {
1337 err = fmt.Errorf("Ongoing transaction not found")
Juha Hyttinen83ada002020-01-30 10:36:33 +02001338 xapp.Logger.Error("MSG-SubDelResp: %s", idstring(err, params, subs))
Anssi Mannila8046c702020-01-02 13:39:05 +02001339 return
Anssi Mannila2e99e2f2019-12-05 13:57:06 +02001340 }
Juha Hyttinen422d0182020-01-17 13:37:05 +02001341 sendOk, timedOut := trans.SendEvent(subDelRespMsg, e2tRecvMsgTimeout)
1342 if sendOk == false {
1343 err = fmt.Errorf("Passing event to transaction failed: sendOk(%t) timedOut(%t)", sendOk, timedOut)
Juha Hyttinen83ada002020-01-30 10:36:33 +02001344 xapp.Logger.Error("MSG-SubDelResp: %s", idstring(err, trans, subs))
Juha Hyttinen60bfcf92020-01-14 15:14:24 +02001345 }
Anssi Mannila2e99e2f2019-12-05 13:57:06 +02001346 return
1347}
1348
Juha Hyttinen422d0182020-01-17 13:37:05 +02001349//-------------------------------------------------------------------
1350// handle from E2T Subscription Delete Failure
1351//-------------------------------------------------------------------
Juha Hyttinen9dc5adc2020-08-13 10:02:40 +03001352func (c *Control) handleE2TSubscriptionDeleteFailure(params *xapp.RMRParams) {
Anssi Mannilaf682ace2021-09-28 13:11:25 +03001353 xapp.Logger.Debug("MSG from E2T: %s", params.String())
Anssi Mannila4abf1802021-01-28 13:06:46 +02001354 c.UpdateCounter(cSubDelFailFromE2)
Juha Hyttinen422d0182020-01-17 13:37:05 +02001355 subDelFailMsg, err := c.e2ap.UnpackSubscriptionDeleteFailure(params.Payload)
Juha Hyttinen31797b42020-01-16 14:05:01 +02001356 if err != nil {
Juha Hyttinen83ada002020-01-30 10:36:33 +02001357 xapp.Logger.Error("MSG-SubDelFail: %s", idstring(err, params))
Anssi Mannilaf1d0eb62019-12-17 15:29:55 +02001358 return
1359 }
Juha Hyttinenaada6452020-04-07 08:47:58 +03001360 subs, err := c.registry.GetSubscriptionFirstMatch([]uint32{subDelFailMsg.RequestId.InstanceId})
Anssi Mannila8046c702020-01-02 13:39:05 +02001361 if err != nil {
Juha Hyttinen83ada002020-01-30 10:36:33 +02001362 xapp.Logger.Error("MSG-SubDelFail: %s", idstring(err, params))
Anssi Mannila8046c702020-01-02 13:39:05 +02001363 return
1364 }
Juha Hyttinen422d0182020-01-17 13:37:05 +02001365 trans := subs.GetTransaction()
1366 if trans == nil {
1367 err = fmt.Errorf("Ongoing transaction not found")
Juha Hyttinen83ada002020-01-30 10:36:33 +02001368 xapp.Logger.Error("MSG-SubDelFail: %s", idstring(err, params, subs))
Juha Hyttinen86a46202020-01-14 12:49:09 +02001369 return
1370 }
Juha Hyttinen422d0182020-01-17 13:37:05 +02001371 sendOk, timedOut := trans.SendEvent(subDelFailMsg, e2tRecvMsgTimeout)
1372 if sendOk == false {
1373 err = fmt.Errorf("Passing event to transaction failed: sendOk(%t) timedOut(%t)", sendOk, timedOut)
Juha Hyttinen83ada002020-01-30 10:36:33 +02001374 xapp.Logger.Error("MSG-SubDelFail: %s", idstring(err, trans, subs))
Anssi Mannila8046c702020-01-02 13:39:05 +02001375 }
kalnagy93cc3e22019-09-19 11:29:29 +02001376 return
1377}
1378
Juha Hyttinen422d0182020-01-17 13:37:05 +02001379//-------------------------------------------------------------------
1380//
1381//-------------------------------------------------------------------
1382func typeofSubsMessage(v interface{}) string {
1383 if v == nil {
1384 return "NIL"
kalnagy93cc3e22019-09-19 11:29:29 +02001385 }
Juha Hyttinen422d0182020-01-17 13:37:05 +02001386 switch v.(type) {
Anssi Mannila51122392021-05-25 11:51:31 +03001387 //case *e2ap.E2APSubscriptionRequest:
1388 // return "SubReq"
Juha Hyttinen422d0182020-01-17 13:37:05 +02001389 case *e2ap.E2APSubscriptionResponse:
1390 return "SubResp"
1391 case *e2ap.E2APSubscriptionFailure:
1392 return "SubFail"
Anssi Mannila51122392021-05-25 11:51:31 +03001393 //case *e2ap.E2APSubscriptionDeleteRequest:
1394 // return "SubDelReq"
Juha Hyttinen422d0182020-01-17 13:37:05 +02001395 case *e2ap.E2APSubscriptionDeleteResponse:
1396 return "SubDelResp"
1397 case *e2ap.E2APSubscriptionDeleteFailure:
1398 return "SubDelFail"
1399 default:
1400 return "Unknown"
Juha Hyttinen31797b42020-01-16 14:05:01 +02001401 }
Anssi Mannilaf1d0eb62019-12-17 15:29:55 +02001402}
Anssi Mannilac92b4212020-12-07 14:59:34 +02001403
1404//-------------------------------------------------------------------
1405//
1406//-------------------------------------------------------------------
Anssi Mannilaf682ace2021-09-28 13:11:25 +03001407func (c *Control) WriteSubscriptionToDb(subs *Subscription) error {
Anssi Mannilac92b4212020-12-07 14:59:34 +02001408 xapp.Logger.Debug("WriteSubscriptionToDb() subId = %v", subs.ReqId.InstanceId)
1409 err := c.WriteSubscriptionToSdl(subs.ReqId.InstanceId, subs)
1410 if err != nil {
1411 xapp.Logger.Error("%v", err)
Anssi Mannilaf682ace2021-09-28 13:11:25 +03001412 return err
Anssi Mannilac92b4212020-12-07 14:59:34 +02001413 }
Anssi Mannilaf682ace2021-09-28 13:11:25 +03001414 return nil
Anssi Mannilac92b4212020-12-07 14:59:34 +02001415}
1416
1417//-------------------------------------------------------------------
1418//
1419//-------------------------------------------------------------------
Anssi Mannilaf682ace2021-09-28 13:11:25 +03001420func (c *Control) UpdateSubscriptionInDB(subs *Subscription, removeSubscriptionFromDb bool) error {
Anssi Mannilac92b4212020-12-07 14:59:34 +02001421
1422 if removeSubscriptionFromDb == true {
1423 // Subscription was written in db already when subscription request was sent to BTS, except for merged request
1424 c.RemoveSubscriptionFromDb(subs)
1425 } else {
1426 // Update is needed for successful response and merge case here
1427 if subs.RetryFromXapp == false {
Anssi Mannilaf682ace2021-09-28 13:11:25 +03001428 err := c.WriteSubscriptionToDb(subs)
1429 return err
Anssi Mannilac92b4212020-12-07 14:59:34 +02001430 }
1431 }
1432 subs.RetryFromXapp = false
Anssi Mannilaf682ace2021-09-28 13:11:25 +03001433 return nil
Anssi Mannilac92b4212020-12-07 14:59:34 +02001434}
1435
1436//-------------------------------------------------------------------
1437//
1438//-------------------------------------------------------------------
1439func (c *Control) RemoveSubscriptionFromDb(subs *Subscription) {
1440 xapp.Logger.Debug("RemoveSubscriptionFromDb() subId = %v", subs.ReqId.InstanceId)
1441 err := c.RemoveSubscriptionFromSdl(subs.ReqId.InstanceId)
1442 if err != nil {
1443 xapp.Logger.Error("%v", err)
1444 }
1445}
1446
Konstantinos Archangelof268d7152021-06-14 12:24:00 +03001447//-------------------------------------------------------------------
1448//
1449//-------------------------------------------------------------------
1450func (c *Control) WriteRESTSubscriptionToDb(restSubId string, restSubs *RESTSubscription) {
1451 xapp.Logger.Debug("WriteRESTSubscriptionToDb() restSubId = %s", restSubId)
1452 err := c.WriteRESTSubscriptionToSdl(restSubId, restSubs)
1453 if err != nil {
1454 xapp.Logger.Error("%v", err)
1455 }
1456}
1457
1458//-------------------------------------------------------------------
1459//
1460//-------------------------------------------------------------------
1461func (c *Control) UpdateRESTSubscriptionInDB(restSubId string, restSubs *RESTSubscription, removeRestSubscriptionFromDb bool) {
1462
1463 if removeRestSubscriptionFromDb == true {
1464 // Subscription was written in db already when subscription request was sent to BTS, except for merged request
1465 c.RemoveRESTSubscriptionFromDb(restSubId)
1466 } else {
1467 c.WriteRESTSubscriptionToDb(restSubId, restSubs)
1468 }
1469}
1470
1471//-------------------------------------------------------------------
1472//
1473//-------------------------------------------------------------------
1474func (c *Control) RemoveRESTSubscriptionFromDb(restSubId string) {
1475 xapp.Logger.Debug("RemoveRESTSubscriptionFromDb() restSubId = %s", restSubId)
1476 err := c.RemoveRESTSubscriptionFromSdl(restSubId)
1477 if err != nil {
1478 xapp.Logger.Error("%v", err)
1479 }
1480}
1481
Anssi Mannilac92b4212020-12-07 14:59:34 +02001482func (c *Control) SendSubscriptionDeleteReq(subs *Subscription) {
1483
Anssi Mannila54838ed2021-11-19 11:25:01 +02001484 if c.UTTesting == true {
1485 // Reqistry mutex is not locked after real restart but it can be when restart is simulated in unit tests
1486 c.registry.mutex = new(sync.Mutex)
1487 }
1488
Konstantinos Archangelof26dfa712021-06-04 12:10:26 +00001489 const ricRequestorId = 123
Anssi Mannilac92b4212020-12-07 14:59:34 +02001490 xapp.Logger.Debug("Sending subscription delete due to restart. subId = %v", subs.ReqId.InstanceId)
1491
1492 // Send delete for every endpoint in the subscription
Anssi Mannilaf682ace2021-09-28 13:11:25 +03001493 if subs.PolicyUpdate == false {
1494 subDelReqMsg := &e2ap.E2APSubscriptionDeleteRequest{}
1495 subDelReqMsg.RequestId = subs.GetReqId().RequestId
1496 subDelReqMsg.RequestId.Id = ricRequestorId
1497 subDelReqMsg.FunctionId = subs.SubReqMsg.FunctionId
1498 mType, payload, err := c.e2ap.PackSubscriptionDeleteRequest(subDelReqMsg)
1499 if err != nil {
1500 xapp.Logger.Error("SendSubscriptionDeleteReq() %s", idstring(err))
1501 return
1502 }
1503 for _, endPoint := range subs.EpList.Endpoints {
1504 params := &xapp.RMRParams{}
1505 params.Mtype = mType
1506 params.SubId = int(subs.GetReqId().InstanceId)
1507 params.Xid = ""
1508 params.Meid = subs.Meid
1509 params.Src = endPoint.String()
1510 params.PayloadLen = len(payload.Buf)
1511 params.Payload = payload.Buf
1512 params.Mbuf = nil
1513 subs.DeleteFromDb = true
1514 c.handleXAPPSubscriptionDeleteRequest(params)
1515 }
Anssi Mannilac92b4212020-12-07 14:59:34 +02001516 }
1517}
Anssi Mannilade457a12021-06-02 16:19:48 +03001518
1519func (c *Control) PrintRESTSubscriptionRequest(p *models.SubscriptionParams) {
1520
1521 fmt.Println("CRESTSubscriptionRequest")
Markku Virtanen987f8b12021-06-10 15:05:02 +03001522
Markku Virtanen2b512b62021-07-30 12:04:00 +00001523 if p == nil {
1524 return
1525 }
1526
Markku Virtanen987f8b12021-06-10 15:05:02 +03001527 if p.SubscriptionID != "" {
1528 fmt.Println(" SubscriptionID = ", p.SubscriptionID)
1529 } else {
1530 fmt.Println(" SubscriptionID = ''")
1531 }
1532
Anssi Mannilade457a12021-06-02 16:19:48 +03001533 fmt.Printf(" ClientEndpoint.Host = %s\n", p.ClientEndpoint.Host)
1534
1535 if p.ClientEndpoint.HTTPPort != nil {
1536 fmt.Printf(" ClientEndpoint.HTTPPort = %v\n", *p.ClientEndpoint.HTTPPort)
1537 } else {
1538 fmt.Println(" ClientEndpoint.HTTPPort = nil")
1539 }
1540
1541 if p.ClientEndpoint.RMRPort != nil {
1542 fmt.Printf(" ClientEndpoint.RMRPort = %v\n", *p.ClientEndpoint.RMRPort)
1543 } else {
1544 fmt.Println(" ClientEndpoint.RMRPort = nil")
1545 }
1546
1547 if p.Meid != nil {
1548 fmt.Printf(" Meid = %s\n", *p.Meid)
1549 } else {
1550 fmt.Println(" Meid = nil")
1551 }
1552
Anssi Mannilaf682ace2021-09-28 13:11:25 +03001553 if p.E2SubscriptionDirectives == nil {
1554 fmt.Println(" E2SubscriptionDirectives = nil")
1555 } else {
1556 fmt.Println(" E2SubscriptionDirectives")
1557 if p.E2SubscriptionDirectives.E2RetryCount == nil {
1558 fmt.Println(" E2RetryCount == nil")
1559 } else {
1560 fmt.Printf(" E2RetryCount = %v\n", *p.E2SubscriptionDirectives.E2RetryCount)
1561 }
1562 fmt.Printf(" E2TimeoutTimerValue = %v\n", p.E2SubscriptionDirectives.E2TimeoutTimerValue)
Anssi Mannilacb7dd492021-10-01 11:10:26 +03001563 fmt.Printf(" RMRRoutingNeeded = %v\n", p.E2SubscriptionDirectives.RMRRoutingNeeded)
Anssi Mannilaf682ace2021-09-28 13:11:25 +03001564 }
Anssi Mannilade457a12021-06-02 16:19:48 +03001565 for _, subscriptionDetail := range p.SubscriptionDetails {
1566 if p.RANFunctionID != nil {
1567 fmt.Printf(" RANFunctionID = %v\n", *p.RANFunctionID)
1568 } else {
1569 fmt.Println(" RANFunctionID = nil")
1570 }
Konstantinos Archangelofe93b00f2021-06-03 10:00:19 +00001571 fmt.Printf(" SubscriptionDetail.XappEventInstanceID = %v\n", *subscriptionDetail.XappEventInstanceID)
Konstantinos Archangelofbd9c98e2021-06-07 17:32:10 +00001572 fmt.Printf(" SubscriptionDetail.EventTriggers = %v\n", subscriptionDetail.EventTriggers)
Anssi Mannilade457a12021-06-02 16:19:48 +03001573
1574 for _, actionToBeSetup := range subscriptionDetail.ActionToBeSetupList {
1575 fmt.Printf(" SubscriptionDetail.ActionToBeSetup.ActionID = %v\n", *actionToBeSetup.ActionID)
1576 fmt.Printf(" SubscriptionDetail.ActionToBeSetup.ActionType = %s\n", *actionToBeSetup.ActionType)
Konstantinos Archangelofbd9c98e2021-06-07 17:32:10 +00001577 fmt.Printf(" SubscriptionDetail.ActionToBeSetup.ActionDefinition = %v\n", actionToBeSetup.ActionDefinition)
Anssi Mannilade457a12021-06-02 16:19:48 +03001578
Anssi Mannilade457a12021-06-02 16:19:48 +03001579 if actionToBeSetup.SubsequentAction != nil {
1580 fmt.Printf(" SubscriptionDetail.ActionToBeSetup.SubsequentAction.SubsequentActionType = %s\n", *actionToBeSetup.SubsequentAction.SubsequentActionType)
1581 fmt.Printf(" SubscriptionDetail.ActionToBeSetup..SubsequentAction.TimeToWait = %s\n", *actionToBeSetup.SubsequentAction.TimeToWait)
1582 } else {
1583 fmt.Println(" SubscriptionDetail.ActionToBeSetup.SubsequentAction = nil")
1584 }
1585 }
1586 }
1587}