kalnagy | 4511475 | 2019-06-18 14:40:39 +0200 | [diff] [blame] | 1 | /* |
| 2 | ================================================================================== |
| 3 | Copyright (c) 2019 AT&T Intellectual Property. |
| 4 | Copyright (c) 2019 Nokia |
| 5 | |
| 6 | Licensed under the Apache License, Version 2.0 (the "License"); |
| 7 | you may not use this file except in compliance with the License. |
| 8 | You may obtain a copy of the License at |
| 9 | |
| 10 | http://www.apache.org/licenses/LICENSE-2.0 |
| 11 | |
| 12 | Unless required by applicable law or agreed to in writing, software |
| 13 | distributed under the License is distributed on an "AS IS" BASIS, |
| 14 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 15 | See the License for the specific language governing permissions and |
| 16 | limitations under the License. |
| 17 | ================================================================================== |
| 18 | */ |
| 19 | |
| 20 | package control |
| 21 | |
Anssi Mannila | 2e99e2f | 2019-12-05 13:57:06 +0200 | [diff] [blame] | 22 | import ( |
Anssi Mannila | b73e7cd | 2021-08-03 11:57:11 +0300 | [diff] [blame] | 23 | "encoding/json" |
Juha Hyttinen | 0388dd9 | 2020-01-09 14:14:16 +0200 | [diff] [blame] | 24 | "fmt" |
Anssi Mannila | f682ace | 2021-09-28 13:11:25 +0300 | [diff] [blame] | 25 | "strings" |
archagge | afbf95f | 2021-04-14 08:54:05 +0300 | [diff] [blame] | 26 | "sync" |
| 27 | "time" |
| 28 | |
Juha Hyttinen | 422d018 | 2020-01-17 13:37:05 +0200 | [diff] [blame] | 29 | "gerrit.o-ran-sc.org/r/ric-plt/e2ap/pkg/e2ap" |
Juha Hyttinen | c9eb08a | 2020-02-28 08:53:33 +0200 | [diff] [blame] | 30 | "gerrit.o-ran-sc.org/r/ric-plt/xapp-frame/pkg/models" |
Anssi Mannila | 2e99e2f | 2019-12-05 13:57:06 +0200 | [diff] [blame] | 31 | "gerrit.o-ran-sc.org/r/ric-plt/xapp-frame/pkg/xapp" |
Anssi Mannila | 2e99e2f | 2019-12-05 13:57:06 +0200 | [diff] [blame] | 32 | ) |
| 33 | |
Juha Hyttinen | 0d064ec | 2020-01-09 09:08:53 +0200 | [diff] [blame] | 34 | //----------------------------------------------------------------------------- |
| 35 | // |
| 36 | //----------------------------------------------------------------------------- |
Juha Hyttinen | 83ada00 | 2020-01-30 10:36:33 +0200 | [diff] [blame] | 37 | |
archagge | afbf95f | 2021-04-14 08:54:05 +0300 | [diff] [blame] | 38 | type RESTSubscription struct { |
Anssi Mannila | d13ba63 | 2022-01-04 14:22:26 +0200 | [diff] [blame] | 39 | Created string |
Anssi Mannila | 92c3855 | 2021-12-29 09:59:24 +0200 | [diff] [blame] | 40 | xAppServiceName string |
archagge | afbf95f | 2021-04-14 08:54:05 +0300 | [diff] [blame] | 41 | xAppRmrEndPoint string |
| 42 | Meid string |
| 43 | InstanceIds []uint32 |
Konstantinos Archangelof | e93b00f | 2021-06-03 10:00:19 +0000 | [diff] [blame] | 44 | xAppIdToE2Id map[int64]int64 |
archagge | afbf95f | 2021-04-14 08:54:05 +0300 | [diff] [blame] | 45 | SubReqOngoing bool |
| 46 | SubDelReqOngoing bool |
Markku Virtanen | 42723e2 | 2021-06-15 10:09:23 +0300 | [diff] [blame] | 47 | lastReqMd5sum string |
archagge | afbf95f | 2021-04-14 08:54:05 +0300 | [diff] [blame] | 48 | } |
| 49 | |
Konstantinos Archangelof | e93b00f | 2021-06-03 10:00:19 +0000 | [diff] [blame] | 50 | func (r *RESTSubscription) AddE2InstanceId(instanceId uint32) { |
Markku Virtanen | 42723e2 | 2021-06-15 10:09:23 +0300 | [diff] [blame] | 51 | |
| 52 | for _, v := range r.InstanceIds { |
| 53 | if v == instanceId { |
| 54 | return |
| 55 | } |
| 56 | |
| 57 | } |
| 58 | |
archagge | afbf95f | 2021-04-14 08:54:05 +0300 | [diff] [blame] | 59 | r.InstanceIds = append(r.InstanceIds, instanceId) |
| 60 | } |
| 61 | |
Markku Virtanen | 42723e2 | 2021-06-15 10:09:23 +0300 | [diff] [blame] | 62 | func (r *RESTSubscription) AddMd5Sum(md5sum string) { |
| 63 | if md5sum != "" { |
| 64 | r.lastReqMd5sum = md5sum |
| 65 | } else { |
| 66 | xapp.Logger.Error("EMPTY md5sum attempted to be add to subscrition") |
| 67 | } |
| 68 | } |
| 69 | |
Konstantinos Archangelof | e93b00f | 2021-06-03 10:00:19 +0000 | [diff] [blame] | 70 | func (r *RESTSubscription) DeleteE2InstanceId(instanceId uint32) { |
| 71 | r.InstanceIds = r.InstanceIds[1:] |
| 72 | } |
| 73 | |
| 74 | func (r *RESTSubscription) AddXappIdToE2Id(xAppEventInstanceID int64, e2EventInstanceID int64) { |
| 75 | r.xAppIdToE2Id[xAppEventInstanceID] = e2EventInstanceID |
| 76 | } |
| 77 | |
| 78 | func (r *RESTSubscription) GetE2IdFromXappIdToE2Id(xAppEventInstanceID int64) int64 { |
| 79 | return r.xAppIdToE2Id[xAppEventInstanceID] |
| 80 | } |
| 81 | |
| 82 | func (r *RESTSubscription) DeleteXappIdToE2Id(xAppEventInstanceID int64) { |
| 83 | delete(r.xAppIdToE2Id, xAppEventInstanceID) |
| 84 | } |
| 85 | |
Markku Virtanen | 42723e2 | 2021-06-15 10:09:23 +0300 | [diff] [blame] | 86 | func (r *RESTSubscription) SetProcessed(err error) { |
archagge | afbf95f | 2021-04-14 08:54:05 +0300 | [diff] [blame] | 87 | r.SubReqOngoing = false |
Markku Virtanen | 42723e2 | 2021-06-15 10:09:23 +0300 | [diff] [blame] | 88 | if err != nil { |
| 89 | r.lastReqMd5sum = "" |
| 90 | } |
archagge | afbf95f | 2021-04-14 08:54:05 +0300 | [diff] [blame] | 91 | } |
| 92 | |
kalnagy | 4511475 | 2019-06-18 14:40:39 +0200 | [diff] [blame] | 93 | type Registry struct { |
Anssi Mannila | 54838ed | 2021-11-19 11:25:01 +0200 | [diff] [blame] | 94 | mutex *sync.Mutex |
archagge | afbf95f | 2021-04-14 08:54:05 +0300 | [diff] [blame] | 95 | register map[uint32]*Subscription |
| 96 | subIds []uint32 |
| 97 | rtmgrClient *RtmgrClient |
| 98 | restSubscriptions map[string]*RESTSubscription |
kalnagy | 4511475 | 2019-06-18 14:40:39 +0200 | [diff] [blame] | 99 | } |
| 100 | |
Anssi Mannila | 5c161a9 | 2020-01-15 15:40:57 +0200 | [diff] [blame] | 101 | func (r *Registry) Initialize() { |
Anssi Mannila | 54838ed | 2021-11-19 11:25:01 +0200 | [diff] [blame] | 102 | r.mutex = new(sync.Mutex) |
Juha Hyttinen | 83ada00 | 2020-01-30 10:36:33 +0200 | [diff] [blame] | 103 | r.register = make(map[uint32]*Subscription) |
archagge | afbf95f | 2021-04-14 08:54:05 +0300 | [diff] [blame] | 104 | r.restSubscriptions = make(map[string]*RESTSubscription) |
| 105 | |
Juha Hyttinen | 83ada00 | 2020-01-30 10:36:33 +0200 | [diff] [blame] | 106 | var i uint32 |
Anssi Mannila | c92b421 | 2020-12-07 14:59:34 +0200 | [diff] [blame] | 107 | for i = 1; i < 65535; i++ { |
| 108 | r.subIds = append(r.subIds, i) |
Anssi Mannila | 5c161a9 | 2020-01-15 15:40:57 +0200 | [diff] [blame] | 109 | } |
kalnagy | 4511475 | 2019-06-18 14:40:39 +0200 | [diff] [blame] | 110 | } |
| 111 | |
Anssi Mannila | 92c3855 | 2021-12-29 09:59:24 +0200 | [diff] [blame] | 112 | func (r *Registry) GetAllRestSubscriptionsJson() []byte { |
| 113 | |
Anssi Mannila | b73e7cd | 2021-08-03 11:57:11 +0300 | [diff] [blame] | 114 | r.mutex.Lock() |
| 115 | defer r.mutex.Unlock() |
| 116 | restSubscriptionsJson, err := json.Marshal(r.restSubscriptions) |
| 117 | if err != nil { |
Anssi Mannila | 92c3855 | 2021-12-29 09:59:24 +0200 | [diff] [blame] | 118 | xapp.Logger.Error("GetAllRestSubscriptions() json.Marshal error: %v", err) |
Anssi Mannila | b73e7cd | 2021-08-03 11:57:11 +0300 | [diff] [blame] | 119 | } |
| 120 | return restSubscriptionsJson |
| 121 | } |
| 122 | |
Anssi Mannila | 92c3855 | 2021-12-29 09:59:24 +0200 | [diff] [blame] | 123 | func (r *Registry) GetAllE2NodeRestSubscriptionsJson(ranName string) []byte { |
| 124 | |
| 125 | restSubscriptions := r.GetAllE2NodeRestSubscriptions(ranName) |
| 126 | e2NodeRestSubscriptionsJson, err := json.Marshal(restSubscriptions) |
| 127 | if err != nil { |
| 128 | xapp.Logger.Error("GetE2NodeRestSubscriptions() json.Marshal error: %v", err) |
| 129 | } |
| 130 | return e2NodeRestSubscriptionsJson |
| 131 | } |
| 132 | |
| 133 | func (r *Registry) GetAllE2NodeRestSubscriptions(ranName string) map[string]RESTSubscription { |
| 134 | |
| 135 | r.mutex.Lock() |
| 136 | defer r.mutex.Unlock() |
| 137 | var restSubscriptions map[string]RESTSubscription |
| 138 | restSubscriptions = make(map[string]RESTSubscription) |
| 139 | for restSubsId, restSubscription := range r.restSubscriptions { |
| 140 | if restSubscription.Meid == ranName { |
| 141 | restSubscriptions[restSubsId] = *restSubscription |
| 142 | } |
| 143 | } |
| 144 | return restSubscriptions |
| 145 | } |
| 146 | |
| 147 | func (r *Registry) GetAllXappsJson() []byte { |
| 148 | |
| 149 | r.mutex.Lock() |
| 150 | var xappList []string |
| 151 | var xappsMap map[string]string |
| 152 | xappsMap = make(map[string]string) |
| 153 | for _, restSubscription := range r.restSubscriptions { |
| 154 | _, ok := xappsMap[restSubscription.xAppServiceName] |
| 155 | if !ok { |
| 156 | xappsMap[restSubscription.xAppServiceName] = restSubscription.xAppServiceName |
| 157 | xappList = append(xappList, restSubscription.xAppServiceName) |
| 158 | } |
| 159 | } |
| 160 | r.mutex.Unlock() |
| 161 | |
| 162 | xappsJson, err := json.Marshal(xappList) |
| 163 | if err != nil { |
| 164 | xapp.Logger.Error("GetXapps() json.Marshal error: %v", err) |
| 165 | } |
| 166 | return xappsJson |
| 167 | } |
| 168 | |
| 169 | func (r *Registry) GetAllXapps() map[string]string { |
| 170 | |
| 171 | r.mutex.Lock() |
| 172 | defer r.mutex.Unlock() |
| 173 | var xappsMap map[string]string |
| 174 | xappsMap = make(map[string]string) |
| 175 | for _, restSubscription := range r.restSubscriptions { |
| 176 | _, ok := xappsMap[restSubscription.xAppServiceName] |
| 177 | if !ok { |
| 178 | xappsMap[restSubscription.xAppServiceName] = restSubscription.xAppServiceName |
| 179 | } |
| 180 | } |
| 181 | return xappsMap |
| 182 | } |
| 183 | |
| 184 | func (r *Registry) GetAllXappRestSubscriptionsJson(xAppServiceName string) []byte { |
| 185 | |
| 186 | xappRestSubscriptions := r.GetAllXappRestSubscriptions(xAppServiceName) |
| 187 | xappRestSubscriptionsJson, err := json.Marshal(xappRestSubscriptions) |
| 188 | if err != nil { |
| 189 | xapp.Logger.Error("GetXappRestSubscriptions() json.Marshal error: %v", err) |
| 190 | } |
| 191 | return xappRestSubscriptionsJson |
| 192 | } |
| 193 | |
| 194 | func (r *Registry) GetAllXappRestSubscriptions(xAppServiceName string) map[string]RESTSubscription { |
| 195 | |
| 196 | r.mutex.Lock() |
| 197 | defer r.mutex.Unlock() |
| 198 | var xappRestSubscriptions map[string]RESTSubscription |
| 199 | xappRestSubscriptions = make(map[string]RESTSubscription) |
| 200 | for restSubsId, xappRestSubscription := range r.restSubscriptions { |
| 201 | if xappRestSubscription.xAppServiceName == xAppServiceName { |
| 202 | xappRestSubscriptions[restSubsId] = *xappRestSubscription |
| 203 | } |
| 204 | } |
| 205 | return xappRestSubscriptions |
| 206 | } |
| 207 | |
| 208 | func (r *Registry) GetE2SubscriptionsJson(restSubsId string) ([]byte, error) { |
| 209 | |
| 210 | // Get all E2 subscriptions of a REST subscription |
| 211 | restSubs, err := r.GetRESTSubscription(restSubsId, false) |
| 212 | if err != nil { |
| 213 | return nil, err |
| 214 | } |
| 215 | |
| 216 | r.mutex.Lock() |
| 217 | var e2Subscriptions []Subscription |
| 218 | for _, e2SubId := range restSubs.InstanceIds { |
| 219 | e2Subscription, ok := r.register[e2SubId] |
| 220 | if ok { |
| 221 | e2Subscriptions = append(e2Subscriptions, *e2Subscription) |
| 222 | } |
| 223 | } |
| 224 | r.mutex.Unlock() |
| 225 | e2SubscriptionsJson, err := json.Marshal(e2Subscriptions) |
| 226 | if err != nil { |
| 227 | xapp.Logger.Error("GetE2Subscriptions() json.Marshal error: %v", err) |
| 228 | } |
| 229 | return e2SubscriptionsJson, nil |
| 230 | } |
| 231 | |
| 232 | func (r *Registry) CreateRESTSubscription(restSubId *string, xappServiceName *string, xAppRmrEndPoint *string, maid *string) *RESTSubscription { |
archagge | afbf95f | 2021-04-14 08:54:05 +0300 | [diff] [blame] | 233 | r.mutex.Lock() |
| 234 | defer r.mutex.Unlock() |
| 235 | newRestSubscription := RESTSubscription{} |
Anssi Mannila | d13ba63 | 2022-01-04 14:22:26 +0200 | [diff] [blame] | 236 | newRestSubscription.Created = time.Now().Format("2006-01-02 15:04:05.000") |
Anssi Mannila | 92c3855 | 2021-12-29 09:59:24 +0200 | [diff] [blame] | 237 | newRestSubscription.xAppServiceName = *xappServiceName |
archagge | afbf95f | 2021-04-14 08:54:05 +0300 | [diff] [blame] | 238 | newRestSubscription.xAppRmrEndPoint = *xAppRmrEndPoint |
| 239 | newRestSubscription.Meid = *maid |
| 240 | newRestSubscription.SubReqOngoing = true |
| 241 | newRestSubscription.SubDelReqOngoing = false |
| 242 | r.restSubscriptions[*restSubId] = &newRestSubscription |
Konstantinos Archangelof | e93b00f | 2021-06-03 10:00:19 +0000 | [diff] [blame] | 243 | newRestSubscription.xAppIdToE2Id = make(map[int64]int64) |
Anssi Mannila | f682ace | 2021-09-28 13:11:25 +0300 | [diff] [blame] | 244 | xapp.Logger.Debug("Registry: Created REST subscription successfully. restSubId=%v, subscriptionCount=%v, e2apSubscriptionCount=%v", *restSubId, len(r.restSubscriptions), len(r.register)) |
| 245 | return &newRestSubscription |
archagge | afbf95f | 2021-04-14 08:54:05 +0300 | [diff] [blame] | 246 | } |
| 247 | |
| 248 | func (r *Registry) DeleteRESTSubscription(restSubId *string) { |
| 249 | r.mutex.Lock() |
| 250 | defer r.mutex.Unlock() |
| 251 | delete(r.restSubscriptions, *restSubId) |
Anssi Mannila | f682ace | 2021-09-28 13:11:25 +0300 | [diff] [blame] | 252 | xapp.Logger.Debug("Registry: Deleted REST subscription successfully. restSubId=%v, subscriptionCount=%v", *restSubId, len(r.restSubscriptions)) |
archagge | afbf95f | 2021-04-14 08:54:05 +0300 | [diff] [blame] | 253 | } |
| 254 | |
Konstantinos Archangelof | e93b00f | 2021-06-03 10:00:19 +0000 | [diff] [blame] | 255 | func (r *Registry) GetRESTSubscription(restSubId string, IsDelReqOngoing bool) (*RESTSubscription, error) { |
archagge | afbf95f | 2021-04-14 08:54:05 +0300 | [diff] [blame] | 256 | r.mutex.Lock() |
| 257 | defer r.mutex.Unlock() |
| 258 | if restSubscription, ok := r.restSubscriptions[restSubId]; ok { |
| 259 | // Subscription deletion is not allowed if prosessing subscription request in not ready |
| 260 | if restSubscription.SubDelReqOngoing == false && restSubscription.SubReqOngoing == false { |
Konstantinos Archangelof | e93b00f | 2021-06-03 10:00:19 +0000 | [diff] [blame] | 261 | if IsDelReqOngoing == true { |
| 262 | restSubscription.SubDelReqOngoing = true |
| 263 | } |
archagge | afbf95f | 2021-04-14 08:54:05 +0300 | [diff] [blame] | 264 | r.restSubscriptions[restSubId] = restSubscription |
| 265 | return restSubscription, nil |
| 266 | } else { |
Markku Virtanen | da34eec | 2021-05-20 08:22:04 +0000 | [diff] [blame] | 267 | return restSubscription, fmt.Errorf("Registry: REST request is still ongoing for the endpoint=%v, restSubId=%v, SubDelReqOngoing=%v, SubReqOngoing=%v", restSubscription, restSubId, restSubscription.SubDelReqOngoing, restSubscription.SubReqOngoing) |
archagge | afbf95f | 2021-04-14 08:54:05 +0300 | [diff] [blame] | 268 | } |
archagge | afbf95f | 2021-04-14 08:54:05 +0300 | [diff] [blame] | 269 | } |
| 270 | return nil, fmt.Errorf("Registry: No valid subscription found with restSubId=%v", restSubId) |
| 271 | } |
| 272 | |
Juha Hyttinen | c9eb08a | 2020-02-28 08:53:33 +0200 | [diff] [blame] | 273 | func (r *Registry) QueryHandler() (models.SubscriptionList, error) { |
| 274 | r.mutex.Lock() |
| 275 | defer r.mutex.Unlock() |
| 276 | |
| 277 | resp := models.SubscriptionList{} |
| 278 | for _, subs := range r.register { |
| 279 | subs.mutex.Lock() |
archagge | a5c58bc | 2021-04-14 08:54:05 +0300 | [diff] [blame] | 280 | resp = append(resp, &models.SubscriptionData{SubscriptionID: int64(subs.ReqId.InstanceId), Meid: subs.Meid.RanName, ClientEndpoint: subs.EpList.StringList()}) |
Juha Hyttinen | c9eb08a | 2020-02-28 08:53:33 +0200 | [diff] [blame] | 281 | subs.mutex.Unlock() |
| 282 | } |
| 283 | return resp, nil |
| 284 | } |
| 285 | |
Anssi Mannila | f682ace | 2021-09-28 13:11:25 +0300 | [diff] [blame] | 286 | func (r *Registry) allocateSubs(trans *TransactionXapp, subReqMsg *e2ap.E2APSubscriptionRequest, resetTestFlag bool, rmrRoutecreated bool) (*Subscription, error) { |
Juha Hyttinen | 12d31af | 2020-01-22 12:59:01 +0200 | [diff] [blame] | 287 | if len(r.subIds) > 0 { |
Juha Hyttinen | aada645 | 2020-04-07 08:47:58 +0300 | [diff] [blame] | 288 | subId := r.subIds[0] |
Juha Hyttinen | 12d31af | 2020-01-22 12:59:01 +0200 | [diff] [blame] | 289 | r.subIds = r.subIds[1:] |
Juha Hyttinen | aada645 | 2020-04-07 08:47:58 +0300 | [diff] [blame] | 290 | if _, ok := r.register[subId]; ok == true { |
| 291 | r.subIds = append(r.subIds, subId) |
Juha Hyttinen | 3944a22 | 2020-01-24 11:51:46 +0200 | [diff] [blame] | 292 | return nil, fmt.Errorf("Registry: Failed to reserve subscription exists") |
Juha Hyttinen | 12d31af | 2020-01-22 12:59:01 +0200 | [diff] [blame] | 293 | } |
Juha Hyttinen | 3944a22 | 2020-01-24 11:51:46 +0200 | [diff] [blame] | 294 | subs := &Subscription{ |
Anssi Mannila | c92b421 | 2020-12-07 14:59:34 +0200 | [diff] [blame] | 295 | registry: r, |
| 296 | Meid: trans.Meid, |
Anssi Mannila | f682ace | 2021-09-28 13:11:25 +0300 | [diff] [blame] | 297 | RMRRouteCreated: rmrRoutecreated, |
Anssi Mannila | c92b421 | 2020-12-07 14:59:34 +0200 | [diff] [blame] | 298 | SubReqMsg: subReqMsg, |
Anssi Mannila | c7da4ee | 2021-10-22 09:52:02 +0300 | [diff] [blame] | 299 | OngoingReqCount: 0, |
| 300 | OngoingDelCount: 0, |
Anssi Mannila | c92b421 | 2020-12-07 14:59:34 +0200 | [diff] [blame] | 301 | valid: true, |
Anssi Mannila | f682ace | 2021-09-28 13:11:25 +0300 | [diff] [blame] | 302 | PolicyUpdate: false, |
Anssi Mannila | c92b421 | 2020-12-07 14:59:34 +0200 | [diff] [blame] | 303 | RetryFromXapp: false, |
| 304 | SubRespRcvd: false, |
| 305 | DeleteFromDb: false, |
| 306 | NoRespToXapp: false, |
| 307 | DoNotWaitSubResp: false, |
Juha Hyttinen | 3944a22 | 2020-01-24 11:51:46 +0200 | [diff] [blame] | 308 | } |
Konstantinos Archangelof | e93b00f | 2021-06-03 10:00:19 +0000 | [diff] [blame] | 309 | subs.ReqId.Id = subReqMsg.RequestId.Id |
Juha Hyttinen | aada645 | 2020-04-07 08:47:58 +0300 | [diff] [blame] | 310 | subs.ReqId.InstanceId = subId |
Anssi Mannila | f682ace | 2021-09-28 13:11:25 +0300 | [diff] [blame] | 311 | r.SetResetTestFlag(resetTestFlag, subs) |
Juha Hyttinen | 3944a22 | 2020-01-24 11:51:46 +0200 | [diff] [blame] | 312 | |
| 313 | if subs.EpList.AddEndpoint(trans.GetEndpoint()) == false { |
Juha Hyttinen | aada645 | 2020-04-07 08:47:58 +0300 | [diff] [blame] | 314 | r.subIds = append(r.subIds, subs.ReqId.InstanceId) |
Juha Hyttinen | 3944a22 | 2020-01-24 11:51:46 +0200 | [diff] [blame] | 315 | return nil, fmt.Errorf("Registry: Endpoint existing already in subscription") |
| 316 | } |
Juha Hyttinen | 3944a22 | 2020-01-24 11:51:46 +0200 | [diff] [blame] | 317 | return subs, nil |
Juha Hyttinen | 12d31af | 2020-01-22 12:59:01 +0200 | [diff] [blame] | 318 | } |
Juha Hyttinen | 3944a22 | 2020-01-24 11:51:46 +0200 | [diff] [blame] | 319 | return nil, fmt.Errorf("Registry: Failed to reserve subscription no free ids") |
| 320 | } |
| 321 | |
Anssi Mannila | 2f26fb2 | 2020-12-07 08:32:13 +0200 | [diff] [blame] | 322 | func (r *Registry) findExistingSubs(trans *TransactionXapp, subReqMsg *e2ap.E2APSubscriptionRequest) (*Subscription, bool) { |
Juha Hyttinen | 83ada00 | 2020-01-30 10:36:33 +0200 | [diff] [blame] | 323 | |
Juha Hyttinen | 3944a22 | 2020-01-24 11:51:46 +0200 | [diff] [blame] | 324 | for _, subs := range r.register { |
Juha Hyttinen | 83ada00 | 2020-01-30 10:36:33 +0200 | [diff] [blame] | 325 | if subs.IsMergeable(trans, subReqMsg) { |
Juha Hyttinen | 3944a22 | 2020-01-24 11:51:46 +0200 | [diff] [blame] | 326 | |
| 327 | // |
| 328 | // check if there has been race conditions |
| 329 | // |
| 330 | subs.mutex.Lock() |
| 331 | //subs has been set to invalid |
| 332 | if subs.valid == false { |
| 333 | subs.mutex.Unlock() |
| 334 | continue |
| 335 | } |
Juha Hyttinen | 83ada00 | 2020-01-30 10:36:33 +0200 | [diff] [blame] | 336 | // If size is zero, entry is to be deleted |
| 337 | if subs.EpList.Size() == 0 { |
| 338 | subs.mutex.Unlock() |
| 339 | continue |
| 340 | } |
Anssi Mannila | 2f26fb2 | 2020-12-07 08:32:13 +0200 | [diff] [blame] | 341 | // Try to add to endpointlist. Adding fails if endpoint is already in the list |
Juha Hyttinen | 3944a22 | 2020-01-24 11:51:46 +0200 | [diff] [blame] | 342 | if subs.EpList.AddEndpoint(trans.GetEndpoint()) == false { |
| 343 | subs.mutex.Unlock() |
Anssi Mannila | 2f26fb2 | 2020-12-07 08:32:13 +0200 | [diff] [blame] | 344 | xapp.Logger.Debug("Registry: Subs with requesting endpoint found. %s for %s", subs.String(), trans.String()) |
| 345 | return subs, true |
Juha Hyttinen | 3944a22 | 2020-01-24 11:51:46 +0200 | [diff] [blame] | 346 | } |
| 347 | subs.mutex.Unlock() |
| 348 | |
Anssi Mannila | 2f26fb2 | 2020-12-07 08:32:13 +0200 | [diff] [blame] | 349 | xapp.Logger.Debug("Registry: Mergeable subs found. %s for %s", subs.String(), trans.String()) |
| 350 | return subs, false |
Juha Hyttinen | 3944a22 | 2020-01-24 11:51:46 +0200 | [diff] [blame] | 351 | } |
| 352 | } |
Anssi Mannila | 2f26fb2 | 2020-12-07 08:32:13 +0200 | [diff] [blame] | 353 | return nil, false |
Juha Hyttinen | 3944a22 | 2020-01-24 11:51:46 +0200 | [diff] [blame] | 354 | } |
| 355 | |
Anssi Mannila | f682ace | 2021-09-28 13:11:25 +0300 | [diff] [blame] | 356 | func (r *Registry) AssignToSubscription(trans *TransactionXapp, subReqMsg *e2ap.E2APSubscriptionRequest, resetTestFlag bool, c *Control, createRMRRoute bool) (*Subscription, ErrorInfo, error) { |
Juha Hyttinen | 3944a22 | 2020-01-24 11:51:46 +0200 | [diff] [blame] | 357 | var err error |
| 358 | var newAlloc bool |
Anssi Mannila | f682ace | 2021-09-28 13:11:25 +0300 | [diff] [blame] | 359 | errorInfo := ErrorInfo{} |
Juha Hyttinen | 3944a22 | 2020-01-24 11:51:46 +0200 | [diff] [blame] | 360 | r.mutex.Lock() |
| 361 | defer r.mutex.Unlock() |
| 362 | |
Anssi Mannila | 9bcb0a4 | 2020-02-11 11:30:44 +0200 | [diff] [blame] | 363 | // |
| 364 | // Check validity of subscription action types |
| 365 | // |
| 366 | actionType, err := r.CheckActionTypes(subReqMsg) |
| 367 | if err != nil { |
Anssi Mannila | f682ace | 2021-09-28 13:11:25 +0300 | [diff] [blame] | 368 | xapp.Logger.Debug("CREATE %s", err) |
Markku Virtanen | 55d2a28 | 2021-06-04 14:46:56 +0300 | [diff] [blame] | 369 | err = fmt.Errorf("E2 content validation failed") |
Anssi Mannila | f682ace | 2021-09-28 13:11:25 +0300 | [diff] [blame] | 370 | return nil, errorInfo, err |
Anssi Mannila | 9bcb0a4 | 2020-02-11 11:30:44 +0200 | [diff] [blame] | 371 | } |
Juha Hyttinen | 3944a22 | 2020-01-24 11:51:46 +0200 | [diff] [blame] | 372 | |
Anssi Mannila | 9bcb0a4 | 2020-02-11 11:30:44 +0200 | [diff] [blame] | 373 | // |
| 374 | // Find possible existing Policy subscription |
| 375 | // |
| 376 | if actionType == e2ap.E2AP_ActionTypePolicy { |
Juha Hyttinen | 47942b4 | 2020-02-27 10:41:43 +0200 | [diff] [blame] | 377 | if subs, ok := r.register[trans.GetSubId()]; ok { |
Anssi Mannila | 2f26fb2 | 2020-12-07 08:32:13 +0200 | [diff] [blame] | 378 | xapp.Logger.Debug("CREATE %s. Existing subscription for Policy found.", subs.String()) |
Anssi Mannila | cc7d9e0 | 2020-04-08 12:58:53 +0300 | [diff] [blame] | 379 | // Update message data to subscription |
| 380 | subs.SubReqMsg = subReqMsg |
Anssi Mannila | f682ace | 2021-09-28 13:11:25 +0300 | [diff] [blame] | 381 | subs.PolicyUpdate = true |
Anssi Mannila | 9bcb0a4 | 2020-02-11 11:30:44 +0200 | [diff] [blame] | 382 | subs.SetCachedResponse(nil, true) |
Anssi Mannila | f682ace | 2021-09-28 13:11:25 +0300 | [diff] [blame] | 383 | r.SetResetTestFlag(resetTestFlag, subs) |
| 384 | return subs, errorInfo, nil |
Anssi Mannila | 9bcb0a4 | 2020-02-11 11:30:44 +0200 | [diff] [blame] | 385 | } |
| 386 | } |
| 387 | |
Anssi Mannila | 2f26fb2 | 2020-12-07 08:32:13 +0200 | [diff] [blame] | 388 | subs, endPointFound := r.findExistingSubs(trans, subReqMsg) |
Juha Hyttinen | 3944a22 | 2020-01-24 11:51:46 +0200 | [diff] [blame] | 389 | if subs == nil { |
Anssi Mannila | f682ace | 2021-09-28 13:11:25 +0300 | [diff] [blame] | 390 | if subs, err = r.allocateSubs(trans, subReqMsg, resetTestFlag, createRMRRoute); err != nil { |
Markku Virtanen | 55d2a28 | 2021-06-04 14:46:56 +0300 | [diff] [blame] | 391 | xapp.Logger.Error("%s", err.Error()) |
| 392 | err = fmt.Errorf("subscription not allocated") |
Anssi Mannila | f682ace | 2021-09-28 13:11:25 +0300 | [diff] [blame] | 393 | return nil, errorInfo, err |
Juha Hyttinen | 3944a22 | 2020-01-24 11:51:46 +0200 | [diff] [blame] | 394 | } |
| 395 | newAlloc = true |
Anssi Mannila | 2f26fb2 | 2020-12-07 08:32:13 +0200 | [diff] [blame] | 396 | } else if endPointFound == true { |
| 397 | // Requesting endpoint is already present in existing subscription. This can happen if xApp is restarted. |
Anssi Mannila | c92b421 | 2020-12-07 14:59:34 +0200 | [diff] [blame] | 398 | subs.RetryFromXapp = true |
Anssi Mannila | 316d8a1 | 2021-06-02 11:08:54 +0300 | [diff] [blame] | 399 | xapp.Logger.Debug("CREATE subReqMsg.InstanceId=%v. Same subscription %s already exists.", subReqMsg.InstanceId, subs.String()) |
| 400 | c.UpdateCounter(cDuplicateE2SubReq) |
Anssi Mannila | f682ace | 2021-09-28 13:11:25 +0300 | [diff] [blame] | 401 | return subs, errorInfo, nil |
Juha Hyttinen | 12d31af | 2020-01-22 12:59:01 +0200 | [diff] [blame] | 402 | } |
| 403 | |
| 404 | // |
| 405 | // Add to subscription |
| 406 | // |
| 407 | subs.mutex.Lock() |
| 408 | defer subs.mutex.Unlock() |
| 409 | |
Juha Hyttinen | 12d31af | 2020-01-22 12:59:01 +0200 | [diff] [blame] | 410 | epamount := subs.EpList.Size() |
Anssi Mannila | f682ace | 2021-09-28 13:11:25 +0300 | [diff] [blame] | 411 | xapp.Logger.Debug("AssignToSubscription subs.EpList.Size()=%v", subs.EpList.Size()) |
Juha Hyttinen | 12d31af | 2020-01-22 12:59:01 +0200 | [diff] [blame] | 412 | |
| 413 | r.mutex.Unlock() |
| 414 | // |
| 415 | // Subscription route updates |
| 416 | // |
Anssi Mannila | f682ace | 2021-09-28 13:11:25 +0300 | [diff] [blame] | 417 | if createRMRRoute == true { |
| 418 | if epamount == 1 { |
| 419 | errorInfo, err = r.RouteCreate(subs, c) |
| 420 | } else { |
| 421 | errorInfo, err = r.RouteCreateUpdate(subs, c) |
| 422 | } |
Juha Hyttinen | 12d31af | 2020-01-22 12:59:01 +0200 | [diff] [blame] | 423 | } else { |
Anssi Mannila | f682ace | 2021-09-28 13:11:25 +0300 | [diff] [blame] | 424 | xapp.Logger.Debug("RMR route not created: createRMRRoute=%v", createRMRRoute) |
Juha Hyttinen | 12d31af | 2020-01-22 12:59:01 +0200 | [diff] [blame] | 425 | } |
| 426 | r.mutex.Lock() |
| 427 | |
| 428 | if err != nil { |
Juha Hyttinen | 3944a22 | 2020-01-24 11:51:46 +0200 | [diff] [blame] | 429 | if newAlloc { |
Juha Hyttinen | aada645 | 2020-04-07 08:47:58 +0300 | [diff] [blame] | 430 | r.subIds = append(r.subIds, subs.ReqId.InstanceId) |
Juha Hyttinen | 3944a22 | 2020-01-24 11:51:46 +0200 | [diff] [blame] | 431 | } |
Anssi Mannila | 4abf180 | 2021-01-28 13:06:46 +0200 | [diff] [blame] | 432 | // Delete already added endpoint for the request |
| 433 | subs.EpList.DelEndpoint(trans.GetEndpoint()) |
Anssi Mannila | f682ace | 2021-09-28 13:11:25 +0300 | [diff] [blame] | 434 | return nil, errorInfo, err |
Juha Hyttinen | 12d31af | 2020-01-22 12:59:01 +0200 | [diff] [blame] | 435 | } |
Juha Hyttinen | 12d31af | 2020-01-22 12:59:01 +0200 | [diff] [blame] | 436 | |
Juha Hyttinen | 3944a22 | 2020-01-24 11:51:46 +0200 | [diff] [blame] | 437 | if newAlloc { |
Juha Hyttinen | aada645 | 2020-04-07 08:47:58 +0300 | [diff] [blame] | 438 | r.register[subs.ReqId.InstanceId] = subs |
Juha Hyttinen | 3944a22 | 2020-01-24 11:51:46 +0200 | [diff] [blame] | 439 | } |
Juha Hyttinen | 83ada00 | 2020-01-30 10:36:33 +0200 | [diff] [blame] | 440 | xapp.Logger.Debug("CREATE %s", subs.String()) |
Juha Hyttinen | 12d31af | 2020-01-22 12:59:01 +0200 | [diff] [blame] | 441 | xapp.Logger.Debug("Registry: substable=%v", r.register) |
Anssi Mannila | f682ace | 2021-09-28 13:11:25 +0300 | [diff] [blame] | 442 | return subs, errorInfo, nil |
Juha Hyttinen | 12d31af | 2020-01-22 12:59:01 +0200 | [diff] [blame] | 443 | } |
| 444 | |
Anssi Mannila | f682ace | 2021-09-28 13:11:25 +0300 | [diff] [blame] | 445 | func (r *Registry) RouteCreate(subs *Subscription, c *Control) (ErrorInfo, error) { |
| 446 | errorInfo := ErrorInfo{} |
Anssi Mannila | 4abf180 | 2021-01-28 13:06:46 +0200 | [diff] [blame] | 447 | subRouteAction := SubRouteInfo{subs.EpList, uint16(subs.ReqId.InstanceId)} |
| 448 | err := r.rtmgrClient.SubscriptionRequestCreate(subRouteAction) |
| 449 | if err != nil { |
Anssi Mannila | f682ace | 2021-09-28 13:11:25 +0300 | [diff] [blame] | 450 | if strings.Contains(err.Error(), "status 400") { |
| 451 | errorInfo.TimeoutType = models.SubscriptionInstanceTimeoutTypeRTMGRTimeout |
| 452 | } else { |
| 453 | errorInfo.ErrorSource = models.SubscriptionInstanceErrorSourceRTMGR |
| 454 | } |
| 455 | errorInfo.ErrorCause = err.Error() |
Anssi Mannila | 4abf180 | 2021-01-28 13:06:46 +0200 | [diff] [blame] | 456 | c.UpdateCounter(cRouteCreateFail) |
Markku Virtanen | 55d2a28 | 2021-06-04 14:46:56 +0300 | [diff] [blame] | 457 | xapp.Logger.Error("%s", err.Error()) |
| 458 | err = fmt.Errorf("RTMGR route create failure") |
Anssi Mannila | 4abf180 | 2021-01-28 13:06:46 +0200 | [diff] [blame] | 459 | } |
Anssi Mannila | f682ace | 2021-09-28 13:11:25 +0300 | [diff] [blame] | 460 | return errorInfo, err |
Anssi Mannila | 4abf180 | 2021-01-28 13:06:46 +0200 | [diff] [blame] | 461 | } |
| 462 | |
Anssi Mannila | f682ace | 2021-09-28 13:11:25 +0300 | [diff] [blame] | 463 | func (r *Registry) RouteCreateUpdate(subs *Subscription, c *Control) (ErrorInfo, error) { |
| 464 | errorInfo := ErrorInfo{} |
Anssi Mannila | 4abf180 | 2021-01-28 13:06:46 +0200 | [diff] [blame] | 465 | subRouteAction := SubRouteInfo{subs.EpList, uint16(subs.ReqId.InstanceId)} |
| 466 | err := r.rtmgrClient.SubscriptionRequestUpdate(subRouteAction) |
| 467 | if err != nil { |
Anssi Mannila | f682ace | 2021-09-28 13:11:25 +0300 | [diff] [blame] | 468 | if strings.Contains(err.Error(), "status 400") { |
| 469 | errorInfo.TimeoutType = models.SubscriptionInstanceTimeoutTypeRTMGRTimeout |
| 470 | } else { |
| 471 | errorInfo.ErrorSource = models.SubscriptionInstanceErrorSourceRTMGR |
| 472 | } |
| 473 | errorInfo.ErrorCause = err.Error() |
Anssi Mannila | 4abf180 | 2021-01-28 13:06:46 +0200 | [diff] [blame] | 474 | c.UpdateCounter(cRouteCreateUpdateFail) |
Markku Virtanen | 55d2a28 | 2021-06-04 14:46:56 +0300 | [diff] [blame] | 475 | xapp.Logger.Error("%s", err.Error()) |
| 476 | err = fmt.Errorf("RTMGR route update failure") |
Anssi Mannila | f682ace | 2021-09-28 13:11:25 +0300 | [diff] [blame] | 477 | return errorInfo, err |
Anssi Mannila | 4abf180 | 2021-01-28 13:06:46 +0200 | [diff] [blame] | 478 | } |
| 479 | c.UpdateCounter(cMergedSubscriptions) |
Anssi Mannila | f682ace | 2021-09-28 13:11:25 +0300 | [diff] [blame] | 480 | return errorInfo, err |
Anssi Mannila | 4abf180 | 2021-01-28 13:06:46 +0200 | [diff] [blame] | 481 | } |
| 482 | |
Anssi Mannila | 9bcb0a4 | 2020-02-11 11:30:44 +0200 | [diff] [blame] | 483 | func (r *Registry) CheckActionTypes(subReqMsg *e2ap.E2APSubscriptionRequest) (uint64, error) { |
| 484 | var reportFound bool = false |
| 485 | var policyFound bool = false |
Anssi Mannila | f0d9526 | 2020-08-17 13:00:20 +0300 | [diff] [blame] | 486 | var insertFound bool = false |
Anssi Mannila | 9bcb0a4 | 2020-02-11 11:30:44 +0200 | [diff] [blame] | 487 | |
| 488 | for _, acts := range subReqMsg.ActionSetups { |
| 489 | if acts.ActionType == e2ap.E2AP_ActionTypeReport { |
| 490 | reportFound = true |
| 491 | } |
| 492 | if acts.ActionType == e2ap.E2AP_ActionTypePolicy { |
| 493 | policyFound = true |
| 494 | } |
Anssi Mannila | f0d9526 | 2020-08-17 13:00:20 +0300 | [diff] [blame] | 495 | if acts.ActionType == e2ap.E2AP_ActionTypeInsert { |
| 496 | insertFound = true |
| 497 | } |
Anssi Mannila | 9bcb0a4 | 2020-02-11 11:30:44 +0200 | [diff] [blame] | 498 | } |
Anssi Mannila | f0d9526 | 2020-08-17 13:00:20 +0300 | [diff] [blame] | 499 | if reportFound == true && policyFound == true || reportFound == true && insertFound == true || policyFound == true && insertFound == true { |
| 500 | return e2ap.E2AP_ActionTypeInvalid, fmt.Errorf("Different action types (Report, Policy or Insert) in same RICactions-ToBeSetup-List") |
Anssi Mannila | 9bcb0a4 | 2020-02-11 11:30:44 +0200 | [diff] [blame] | 501 | } |
| 502 | if reportFound == true { |
| 503 | return e2ap.E2AP_ActionTypeReport, nil |
| 504 | } |
| 505 | if policyFound == true { |
| 506 | return e2ap.E2AP_ActionTypePolicy, nil |
| 507 | } |
Anssi Mannila | f0d9526 | 2020-08-17 13:00:20 +0300 | [diff] [blame] | 508 | if insertFound == true { |
| 509 | return e2ap.E2AP_ActionTypeInsert, nil |
| 510 | } |
Anssi Mannila | 9bcb0a4 | 2020-02-11 11:30:44 +0200 | [diff] [blame] | 511 | return e2ap.E2AP_ActionTypeInvalid, fmt.Errorf("Invalid action type in RICactions-ToBeSetup-List") |
| 512 | } |
| 513 | |
Anssi Mannila | 55d6fed | 2022-08-02 12:41:48 +0300 | [diff] [blame] | 514 | func (r *Registry) RemoveFromSubscription(subs *Subscription, trans *TransactionXapp, waitRouteClean time.Duration, c *Control) { |
Juha Hyttinen | 3944a22 | 2020-01-24 11:51:46 +0200 | [diff] [blame] | 515 | |
Anssi Mannila | 54838ed | 2021-11-19 11:25:01 +0200 | [diff] [blame] | 516 | xapp.Logger.Debug("RemoveFromSubscription %s", idstring(nil, trans, subs, trans)) |
Juha Hyttinen | 12d31af | 2020-01-22 12:59:01 +0200 | [diff] [blame] | 517 | r.mutex.Lock() |
| 518 | defer r.mutex.Unlock() |
| 519 | subs.mutex.Lock() |
| 520 | defer subs.mutex.Unlock() |
| 521 | |
| 522 | delStatus := subs.EpList.DelEndpoint(trans.GetEndpoint()) |
| 523 | epamount := subs.EpList.Size() |
Anssi Mannila | 54838ed | 2021-11-19 11:25:01 +0200 | [diff] [blame] | 524 | |
Juha Hyttinen | aada645 | 2020-04-07 08:47:58 +0300 | [diff] [blame] | 525 | subId := subs.ReqId.InstanceId |
Juha Hyttinen | 83ada00 | 2020-01-30 10:36:33 +0200 | [diff] [blame] | 526 | if delStatus == false { |
Anssi Mannila | 55d6fed | 2022-08-02 12:41:48 +0300 | [diff] [blame] | 527 | return |
Anssi Mannila | 2e99e2f | 2019-12-05 13:57:06 +0200 | [diff] [blame] | 528 | } |
Juha Hyttinen | 83ada00 | 2020-01-30 10:36:33 +0200 | [diff] [blame] | 529 | |
Anssi Mannila | 54838ed | 2021-11-19 11:25:01 +0200 | [diff] [blame] | 530 | if waitRouteClean > 0 { |
| 531 | // Wait here that response is delivered to xApp via RMR before route is cleaned |
| 532 | xapp.Logger.Debug("Pending %v in order to wait route cleanup", waitRouteClean) |
Anssi Mannila | 9c4697f | 2022-07-04 15:51:38 +0300 | [diff] [blame] | 533 | r.mutex.Unlock() |
Anssi Mannila | 54838ed | 2021-11-19 11:25:01 +0200 | [diff] [blame] | 534 | time.Sleep(waitRouteClean) |
Anssi Mannila | 9c4697f | 2022-07-04 15:51:38 +0300 | [diff] [blame] | 535 | r.mutex.Lock() |
Anssi Mannila | 54838ed | 2021-11-19 11:25:01 +0200 | [diff] [blame] | 536 | } |
| 537 | |
| 538 | xapp.Logger.Debug("CLEAN %s", subs.String()) |
| 539 | |
| 540 | if epamount == 0 { |
| 541 | // |
| 542 | // Subscription route delete |
| 543 | // |
| 544 | if subs.RMRRouteCreated == true { |
| 545 | r.RouteDelete(subs, trans, c) |
Juha Hyttinen | 83ada00 | 2020-01-30 10:36:33 +0200 | [diff] [blame] | 546 | } |
Juha Hyttinen | f44377d | 2020-02-12 10:18:40 +0200 | [diff] [blame] | 547 | |
Anssi Mannila | 54838ed | 2021-11-19 11:25:01 +0200 | [diff] [blame] | 548 | // Not merged subscription is being deleted |
| 549 | xapp.Logger.Debug("Subscription route delete RemoveSubscriptionFromDb") |
| 550 | c.RemoveSubscriptionFromDb(subs) |
Juha Hyttinen | f44377d | 2020-02-12 10:18:40 +0200 | [diff] [blame] | 551 | |
Anssi Mannila | 54838ed | 2021-11-19 11:25:01 +0200 | [diff] [blame] | 552 | // |
| 553 | // Subscription release |
| 554 | // |
Juha Hyttinen | f44377d | 2020-02-12 10:18:40 +0200 | [diff] [blame] | 555 | |
Anssi Mannila | 54838ed | 2021-11-19 11:25:01 +0200 | [diff] [blame] | 556 | if _, ok := r.register[subId]; ok { |
| 557 | xapp.Logger.Debug("RELEASE %s", subs.String()) |
| 558 | delete(r.register, subId) |
| 559 | xapp.Logger.Debug("Registry: substable=%v", r.register) |
Juha Hyttinen | f44377d | 2020-02-12 10:18:40 +0200 | [diff] [blame] | 560 | } |
Anssi Mannila | 54838ed | 2021-11-19 11:25:01 +0200 | [diff] [blame] | 561 | r.subIds = append(r.subIds, subId) |
| 562 | } else if subs.EpList.Size() > 0 { |
| 563 | // |
| 564 | // Subscription route update |
| 565 | // |
| 566 | if subs.RMRRouteCreated == true { |
| 567 | r.RouteDeleteUpdate(subs, c) |
| 568 | } |
Juha Hyttinen | 12d31af | 2020-01-22 12:59:01 +0200 | [diff] [blame] | 569 | |
Anssi Mannila | 54838ed | 2021-11-19 11:25:01 +0200 | [diff] [blame] | 570 | // Endpoint of merged subscription is being deleted |
| 571 | xapp.Logger.Debug("Subscription route update WriteSubscriptionToDb") |
Anssi Mannila | 9c4697f | 2022-07-04 15:51:38 +0300 | [diff] [blame] | 572 | err := c.WriteSubscriptionToDb(subs) |
| 573 | if err != nil { |
| 574 | xapp.Logger.Error("tracker.UnTrackTransaction() failed:%s", err.Error()) |
| 575 | } |
Anssi Mannila | 54838ed | 2021-11-19 11:25:01 +0200 | [diff] [blame] | 576 | c.UpdateCounter(cUnmergedSubscriptions) |
| 577 | } |
Anssi Mannila | 55d6fed | 2022-08-02 12:41:48 +0300 | [diff] [blame] | 578 | return |
Juha Hyttinen | 47b842b | 2020-01-08 13:01:52 +0200 | [diff] [blame] | 579 | } |
Anssi Mannila | 2e99e2f | 2019-12-05 13:57:06 +0200 | [diff] [blame] | 580 | |
Anssi Mannila | 4abf180 | 2021-01-28 13:06:46 +0200 | [diff] [blame] | 581 | func (r *Registry) RouteDelete(subs *Subscription, trans *TransactionXapp, c *Control) { |
| 582 | tmpList := xapp.RmrEndpointList{} |
| 583 | tmpList.AddEndpoint(trans.GetEndpoint()) |
| 584 | subRouteAction := SubRouteInfo{tmpList, uint16(subs.ReqId.InstanceId)} |
| 585 | if err := r.rtmgrClient.SubscriptionRequestDelete(subRouteAction); err != nil { |
| 586 | c.UpdateCounter(cRouteDeleteFail) |
| 587 | } |
| 588 | } |
| 589 | |
| 590 | func (r *Registry) RouteDeleteUpdate(subs *Subscription, c *Control) { |
| 591 | subRouteAction := SubRouteInfo{subs.EpList, uint16(subs.ReqId.InstanceId)} |
| 592 | if err := r.rtmgrClient.SubscriptionRequestUpdate(subRouteAction); err != nil { |
| 593 | c.UpdateCounter(cRouteDeleteUpdateFail) |
| 594 | } |
| 595 | } |
| 596 | |
Juha Hyttinen | aada645 | 2020-04-07 08:47:58 +0300 | [diff] [blame] | 597 | func (r *Registry) GetSubscription(subId uint32) *Subscription { |
Juha Hyttinen | 47b842b | 2020-01-08 13:01:52 +0200 | [diff] [blame] | 598 | r.mutex.Lock() |
| 599 | defer r.mutex.Unlock() |
Juha Hyttinen | aada645 | 2020-04-07 08:47:58 +0300 | [diff] [blame] | 600 | if _, ok := r.register[subId]; ok { |
| 601 | return r.register[subId] |
Anssi Mannila | 2e99e2f | 2019-12-05 13:57:06 +0200 | [diff] [blame] | 602 | } |
Juha Hyttinen | 47b842b | 2020-01-08 13:01:52 +0200 | [diff] [blame] | 603 | return nil |
Peter Szilagyi | fbc56f9 | 2019-07-23 19:29:46 +0000 | [diff] [blame] | 604 | } |
| 605 | |
Juha Hyttinen | aada645 | 2020-04-07 08:47:58 +0300 | [diff] [blame] | 606 | func (r *Registry) GetSubscriptionFirstMatch(subIds []uint32) (*Subscription, error) { |
Juha Hyttinen | 422d018 | 2020-01-17 13:37:05 +0200 | [diff] [blame] | 607 | r.mutex.Lock() |
| 608 | defer r.mutex.Unlock() |
Juha Hyttinen | aada645 | 2020-04-07 08:47:58 +0300 | [diff] [blame] | 609 | for _, subId := range subIds { |
| 610 | if _, ok := r.register[subId]; ok { |
| 611 | return r.register[subId], nil |
Juha Hyttinen | 422d018 | 2020-01-17 13:37:05 +0200 | [diff] [blame] | 612 | } |
| 613 | } |
Juha Hyttinen | aada645 | 2020-04-07 08:47:58 +0300 | [diff] [blame] | 614 | return nil, fmt.Errorf("No valid subscription found with subIds %v", subIds) |
Juha Hyttinen | 422d018 | 2020-01-17 13:37:05 +0200 | [diff] [blame] | 615 | } |
Anssi Mannila | f682ace | 2021-09-28 13:11:25 +0300 | [diff] [blame] | 616 | |
| 617 | func (r *Registry) SetResetTestFlag(resetTestFlag bool, subs *Subscription) { |
| 618 | if resetTestFlag == true { |
| 619 | // This is used in submgr restart unit tests |
| 620 | xapp.Logger.Debug("resetTestFlag == true") |
| 621 | subs.DoNotWaitSubResp = true |
| 622 | } else { |
| 623 | xapp.Logger.Debug("resetTestFlag == false") |
| 624 | } |
| 625 | } |
Anssi Mannila | c7da4ee | 2021-10-22 09:52:02 +0300 | [diff] [blame] | 626 | |
| 627 | func (r *Registry) DeleteAllE2Subscriptions(ranName string, c *Control) { |
| 628 | |
| 629 | xapp.Logger.Debug("Registry: DeleteAllE2Subscriptions()") |
| 630 | for subId, subs := range r.register { |
| 631 | if subs.Meid.RanName == ranName { |
| 632 | if subs.OngoingReqCount != 0 || subs.OngoingDelCount != 0 { |
| 633 | // Subscription creation or deletion processes need to be processed gracefully till the end. |
| 634 | // Subscription is deleted at end of the process in both cases. |
| 635 | xapp.Logger.Debug("Registry: E2 subscription under prosessing ongoing cannot delete it yet. subId=%v, OngoingReqCount=%v, OngoingDelCount=%v", subId, subs.OngoingReqCount, subs.OngoingDelCount) |
| 636 | continue |
| 637 | } else { |
| 638 | // Delete route |
| 639 | if subs.RMRRouteCreated == true { |
| 640 | for _, ep := range subs.EpList.Endpoints { |
| 641 | tmpList := xapp.RmrEndpointList{} |
| 642 | tmpList.AddEndpoint(&ep) |
| 643 | subRouteAction := SubRouteInfo{tmpList, uint16(subs.ReqId.InstanceId)} |
| 644 | if err := r.rtmgrClient.SubscriptionRequestDelete(subRouteAction); err != nil { |
| 645 | c.UpdateCounter(cRouteDeleteFail) |
| 646 | } |
| 647 | } |
| 648 | } |
| 649 | // Delete E2 subscription from registry and db |
| 650 | xapp.Logger.Debug("Registry: Subscription delete. subId=%v", subId) |
| 651 | delete(r.register, subId) |
| 652 | r.subIds = append(r.subIds, subId) |
| 653 | c.RemoveSubscriptionFromDb(subs) |
| 654 | } |
| 655 | } |
| 656 | } |
| 657 | |
| 658 | // Delete REST subscription from registry and db |
| 659 | for restSubId, restSubs := range r.restSubscriptions { |
Konstantinos Archangelof | 3a96973 | 2022-07-21 12:05:19 +0300 | [diff] [blame] | 660 | if restSubs.Meid == ranName { |
| 661 | if restSubs.SubReqOngoing == true || restSubs.SubDelReqOngoing == true { |
| 662 | // Subscription creation or deletion processes need to be processed gracefully till the end. |
| 663 | // Subscription is deleted at end of the process in both cases. |
| 664 | xapp.Logger.Debug("Registry: REST subscription under prosessing ongoing cannot delete it yet. RestSubId=%v, SubReqOngoing=%v, SubDelReqOngoing=%v", restSubId, restSubs.SubReqOngoing, restSubs.SubDelReqOngoing) |
| 665 | continue |
| 666 | } else { |
| 667 | xapp.Logger.Debug("Registry: REST subscription delete. subId=%v", restSubId) |
| 668 | delete(r.restSubscriptions, restSubId) |
| 669 | c.RemoveRESTSubscriptionFromDb(restSubId) |
| 670 | } |
Anssi Mannila | c7da4ee | 2021-10-22 09:52:02 +0300 | [diff] [blame] | 671 | } |
| 672 | } |
| 673 | } |