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 ( |
Juha Hyttinen | 0388dd9 | 2020-01-09 14:14:16 +0200 | [diff] [blame] | 23 | "fmt" |
Juha Hyttinen | 422d018 | 2020-01-17 13:37:05 +0200 | [diff] [blame] | 24 | "gerrit.o-ran-sc.org/r/ric-plt/e2ap/pkg/e2ap" |
Juha Hyttinen | c9eb08a | 2020-02-28 08:53:33 +0200 | [diff] [blame] | 25 | "gerrit.o-ran-sc.org/r/ric-plt/xapp-frame/pkg/models" |
Anssi Mannila | 2e99e2f | 2019-12-05 13:57:06 +0200 | [diff] [blame] | 26 | "gerrit.o-ran-sc.org/r/ric-plt/xapp-frame/pkg/xapp" |
| 27 | "sync" |
Juha Hyttinen | 12d31af | 2020-01-22 12:59:01 +0200 | [diff] [blame] | 28 | "time" |
Anssi Mannila | 2e99e2f | 2019-12-05 13:57:06 +0200 | [diff] [blame] | 29 | ) |
| 30 | |
Juha Hyttinen | 0d064ec | 2020-01-09 09:08:53 +0200 | [diff] [blame] | 31 | //----------------------------------------------------------------------------- |
| 32 | // |
| 33 | //----------------------------------------------------------------------------- |
Juha Hyttinen | 83ada00 | 2020-01-30 10:36:33 +0200 | [diff] [blame] | 34 | |
kalnagy | 4511475 | 2019-06-18 14:40:39 +0200 | [diff] [blame] | 35 | type Registry struct { |
Juha Hyttinen | 0388dd9 | 2020-01-09 14:14:16 +0200 | [diff] [blame] | 36 | mutex sync.Mutex |
Juha Hyttinen | 83ada00 | 2020-01-30 10:36:33 +0200 | [diff] [blame] | 37 | register map[uint32]*Subscription |
| 38 | subIds []uint32 |
Juha Hyttinen | 0388dd9 | 2020-01-09 14:14:16 +0200 | [diff] [blame] | 39 | rtmgrClient *RtmgrClient |
kalnagy | 4511475 | 2019-06-18 14:40:39 +0200 | [diff] [blame] | 40 | } |
| 41 | |
Anssi Mannila | 5c161a9 | 2020-01-15 15:40:57 +0200 | [diff] [blame] | 42 | func (r *Registry) Initialize() { |
Juha Hyttinen | 83ada00 | 2020-01-30 10:36:33 +0200 | [diff] [blame] | 43 | r.register = make(map[uint32]*Subscription) |
| 44 | var i uint32 |
Anssi Mannila | 5c161a9 | 2020-01-15 15:40:57 +0200 | [diff] [blame] | 45 | for i = 0; i < 65535; i++ { |
| 46 | r.subIds = append(r.subIds, i+1) |
| 47 | } |
kalnagy | 4511475 | 2019-06-18 14:40:39 +0200 | [diff] [blame] | 48 | } |
| 49 | |
Juha Hyttinen | c9eb08a | 2020-02-28 08:53:33 +0200 | [diff] [blame] | 50 | func (r *Registry) QueryHandler() (models.SubscriptionList, error) { |
| 51 | r.mutex.Lock() |
| 52 | defer r.mutex.Unlock() |
| 53 | |
| 54 | resp := models.SubscriptionList{} |
| 55 | for _, subs := range r.register { |
| 56 | subs.mutex.Lock() |
Juha Hyttinen | aada645 | 2020-04-07 08:47:58 +0300 | [diff] [blame] | 57 | resp = append(resp, &models.SubscriptionData{SubscriptionID: int64(subs.ReqId.InstanceId), Meid: subs.Meid.RanName, Endpoint: subs.EpList.StringList()}) |
Juha Hyttinen | c9eb08a | 2020-02-28 08:53:33 +0200 | [diff] [blame] | 58 | subs.mutex.Unlock() |
| 59 | } |
| 60 | return resp, nil |
| 61 | } |
| 62 | |
Juha Hyttinen | 83ada00 | 2020-01-30 10:36:33 +0200 | [diff] [blame] | 63 | func (r *Registry) allocateSubs(trans *TransactionXapp, subReqMsg *e2ap.E2APSubscriptionRequest) (*Subscription, error) { |
Juha Hyttinen | 12d31af | 2020-01-22 12:59:01 +0200 | [diff] [blame] | 64 | if len(r.subIds) > 0 { |
Juha Hyttinen | aada645 | 2020-04-07 08:47:58 +0300 | [diff] [blame] | 65 | subId := r.subIds[0] |
Juha Hyttinen | 12d31af | 2020-01-22 12:59:01 +0200 | [diff] [blame] | 66 | r.subIds = r.subIds[1:] |
Juha Hyttinen | aada645 | 2020-04-07 08:47:58 +0300 | [diff] [blame] | 67 | if _, ok := r.register[subId]; ok == true { |
| 68 | r.subIds = append(r.subIds, subId) |
Juha Hyttinen | 3944a22 | 2020-01-24 11:51:46 +0200 | [diff] [blame] | 69 | return nil, fmt.Errorf("Registry: Failed to reserve subscription exists") |
Juha Hyttinen | 12d31af | 2020-01-22 12:59:01 +0200 | [diff] [blame] | 70 | } |
Juha Hyttinen | 3944a22 | 2020-01-24 11:51:46 +0200 | [diff] [blame] | 71 | subs := &Subscription{ |
| 72 | registry: r, |
Juha Hyttinen | 3944a22 | 2020-01-24 11:51:46 +0200 | [diff] [blame] | 73 | Meid: trans.Meid, |
| 74 | SubReqMsg: subReqMsg, |
| 75 | valid: true, |
| 76 | } |
Juha Hyttinen | 83ada00 | 2020-01-30 10:36:33 +0200 | [diff] [blame] | 77 | subs.ReqId.Id = 123 |
Juha Hyttinen | aada645 | 2020-04-07 08:47:58 +0300 | [diff] [blame] | 78 | subs.ReqId.InstanceId = subId |
Juha Hyttinen | 3944a22 | 2020-01-24 11:51:46 +0200 | [diff] [blame] | 79 | |
| 80 | if subs.EpList.AddEndpoint(trans.GetEndpoint()) == false { |
Juha Hyttinen | aada645 | 2020-04-07 08:47:58 +0300 | [diff] [blame] | 81 | r.subIds = append(r.subIds, subs.ReqId.InstanceId) |
Juha Hyttinen | 3944a22 | 2020-01-24 11:51:46 +0200 | [diff] [blame] | 82 | return nil, fmt.Errorf("Registry: Endpoint existing already in subscription") |
| 83 | } |
| 84 | |
| 85 | return subs, nil |
Juha Hyttinen | 12d31af | 2020-01-22 12:59:01 +0200 | [diff] [blame] | 86 | } |
Juha Hyttinen | 3944a22 | 2020-01-24 11:51:46 +0200 | [diff] [blame] | 87 | return nil, fmt.Errorf("Registry: Failed to reserve subscription no free ids") |
| 88 | } |
| 89 | |
Anssi Mannila | 2f26fb2 | 2020-12-07 08:32:13 +0200 | [diff] [blame] | 90 | func (r *Registry) findExistingSubs(trans *TransactionXapp, subReqMsg *e2ap.E2APSubscriptionRequest) (*Subscription, bool) { |
Juha Hyttinen | 83ada00 | 2020-01-30 10:36:33 +0200 | [diff] [blame] | 91 | |
Juha Hyttinen | 3944a22 | 2020-01-24 11:51:46 +0200 | [diff] [blame] | 92 | for _, subs := range r.register { |
Juha Hyttinen | 83ada00 | 2020-01-30 10:36:33 +0200 | [diff] [blame] | 93 | if subs.IsMergeable(trans, subReqMsg) { |
Juha Hyttinen | 3944a22 | 2020-01-24 11:51:46 +0200 | [diff] [blame] | 94 | |
| 95 | // |
| 96 | // check if there has been race conditions |
| 97 | // |
| 98 | subs.mutex.Lock() |
| 99 | //subs has been set to invalid |
| 100 | if subs.valid == false { |
| 101 | subs.mutex.Unlock() |
| 102 | continue |
| 103 | } |
Juha Hyttinen | 83ada00 | 2020-01-30 10:36:33 +0200 | [diff] [blame] | 104 | // If size is zero, entry is to be deleted |
| 105 | if subs.EpList.Size() == 0 { |
| 106 | subs.mutex.Unlock() |
| 107 | continue |
| 108 | } |
Anssi Mannila | 2f26fb2 | 2020-12-07 08:32:13 +0200 | [diff] [blame] | 109 | // 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] | 110 | if subs.EpList.AddEndpoint(trans.GetEndpoint()) == false { |
| 111 | subs.mutex.Unlock() |
Anssi Mannila | 2f26fb2 | 2020-12-07 08:32:13 +0200 | [diff] [blame] | 112 | xapp.Logger.Debug("Registry: Subs with requesting endpoint found. %s for %s", subs.String(), trans.String()) |
| 113 | return subs, true |
Juha Hyttinen | 3944a22 | 2020-01-24 11:51:46 +0200 | [diff] [blame] | 114 | } |
| 115 | subs.mutex.Unlock() |
| 116 | |
Anssi Mannila | 2f26fb2 | 2020-12-07 08:32:13 +0200 | [diff] [blame] | 117 | xapp.Logger.Debug("Registry: Mergeable subs found. %s for %s", subs.String(), trans.String()) |
| 118 | return subs, false |
Juha Hyttinen | 3944a22 | 2020-01-24 11:51:46 +0200 | [diff] [blame] | 119 | } |
| 120 | } |
Anssi Mannila | 2f26fb2 | 2020-12-07 08:32:13 +0200 | [diff] [blame] | 121 | return nil, false |
Juha Hyttinen | 3944a22 | 2020-01-24 11:51:46 +0200 | [diff] [blame] | 122 | } |
| 123 | |
Juha Hyttinen | 83ada00 | 2020-01-30 10:36:33 +0200 | [diff] [blame] | 124 | func (r *Registry) AssignToSubscription(trans *TransactionXapp, subReqMsg *e2ap.E2APSubscriptionRequest) (*Subscription, error) { |
Juha Hyttinen | 3944a22 | 2020-01-24 11:51:46 +0200 | [diff] [blame] | 125 | var err error |
| 126 | var newAlloc bool |
| 127 | r.mutex.Lock() |
| 128 | defer r.mutex.Unlock() |
| 129 | |
Anssi Mannila | 9bcb0a4 | 2020-02-11 11:30:44 +0200 | [diff] [blame] | 130 | // |
| 131 | // Check validity of subscription action types |
| 132 | // |
| 133 | actionType, err := r.CheckActionTypes(subReqMsg) |
| 134 | if err != nil { |
| 135 | xapp.Logger.Debug("CREATE %s", err) |
| 136 | return nil, err |
| 137 | } |
Juha Hyttinen | 3944a22 | 2020-01-24 11:51:46 +0200 | [diff] [blame] | 138 | |
Anssi Mannila | 9bcb0a4 | 2020-02-11 11:30:44 +0200 | [diff] [blame] | 139 | // |
| 140 | // Find possible existing Policy subscription |
| 141 | // |
| 142 | if actionType == e2ap.E2AP_ActionTypePolicy { |
Juha Hyttinen | 47942b4 | 2020-02-27 10:41:43 +0200 | [diff] [blame] | 143 | if subs, ok := r.register[trans.GetSubId()]; ok { |
Anssi Mannila | 2f26fb2 | 2020-12-07 08:32:13 +0200 | [diff] [blame] | 144 | xapp.Logger.Debug("CREATE %s. Existing subscription for Policy found.", subs.String()) |
Anssi Mannila | cc7d9e0 | 2020-04-08 12:58:53 +0300 | [diff] [blame] | 145 | // Update message data to subscription |
| 146 | subs.SubReqMsg = subReqMsg |
Anssi Mannila | 9bcb0a4 | 2020-02-11 11:30:44 +0200 | [diff] [blame] | 147 | subs.SetCachedResponse(nil, true) |
| 148 | return subs, nil |
| 149 | } |
| 150 | } |
| 151 | |
Anssi Mannila | 2f26fb2 | 2020-12-07 08:32:13 +0200 | [diff] [blame] | 152 | subs, endPointFound := r.findExistingSubs(trans, subReqMsg) |
Juha Hyttinen | 3944a22 | 2020-01-24 11:51:46 +0200 | [diff] [blame] | 153 | if subs == nil { |
| 154 | subs, err = r.allocateSubs(trans, subReqMsg) |
| 155 | if err != nil { |
| 156 | return nil, err |
| 157 | } |
| 158 | newAlloc = true |
Anssi Mannila | 2f26fb2 | 2020-12-07 08:32:13 +0200 | [diff] [blame] | 159 | } else if endPointFound == true { |
| 160 | // Requesting endpoint is already present in existing subscription. This can happen if xApp is restarted. |
| 161 | xapp.Logger.Debug("CREATE: subscription already exists. %s", subs.String()) |
| 162 | xapp.Logger.Debug("Registry: substable=%v", r.register) |
| 163 | return subs, nil |
Juha Hyttinen | 12d31af | 2020-01-22 12:59:01 +0200 | [diff] [blame] | 164 | } |
| 165 | |
| 166 | // |
| 167 | // Add to subscription |
| 168 | // |
| 169 | subs.mutex.Lock() |
| 170 | defer subs.mutex.Unlock() |
| 171 | |
Juha Hyttinen | 12d31af | 2020-01-22 12:59:01 +0200 | [diff] [blame] | 172 | epamount := subs.EpList.Size() |
| 173 | |
| 174 | r.mutex.Unlock() |
| 175 | // |
| 176 | // Subscription route updates |
| 177 | // |
Juha Hyttinen | 12d31af | 2020-01-22 12:59:01 +0200 | [diff] [blame] | 178 | if epamount == 1 { |
Juha Hyttinen | aada645 | 2020-04-07 08:47:58 +0300 | [diff] [blame] | 179 | subRouteAction := SubRouteInfo{subs.EpList, uint16(subs.ReqId.InstanceId)} |
Juha Hyttinen | 83ada00 | 2020-01-30 10:36:33 +0200 | [diff] [blame] | 180 | err = r.rtmgrClient.SubscriptionRequestCreate(subRouteAction) |
Juha Hyttinen | 12d31af | 2020-01-22 12:59:01 +0200 | [diff] [blame] | 181 | } else { |
Juha Hyttinen | aada645 | 2020-04-07 08:47:58 +0300 | [diff] [blame] | 182 | subRouteAction := SubRouteInfo{subs.EpList, uint16(subs.ReqId.InstanceId)} |
Juha Hyttinen | 12d31af | 2020-01-22 12:59:01 +0200 | [diff] [blame] | 183 | err = r.rtmgrClient.SubscriptionRequestUpdate(subRouteAction) |
| 184 | } |
| 185 | r.mutex.Lock() |
| 186 | |
| 187 | if err != nil { |
Juha Hyttinen | 3944a22 | 2020-01-24 11:51:46 +0200 | [diff] [blame] | 188 | if newAlloc { |
Juha Hyttinen | aada645 | 2020-04-07 08:47:58 +0300 | [diff] [blame] | 189 | r.subIds = append(r.subIds, subs.ReqId.InstanceId) |
Juha Hyttinen | 3944a22 | 2020-01-24 11:51:46 +0200 | [diff] [blame] | 190 | } |
Juha Hyttinen | 12d31af | 2020-01-22 12:59:01 +0200 | [diff] [blame] | 191 | return nil, err |
| 192 | } |
Juha Hyttinen | 12d31af | 2020-01-22 12:59:01 +0200 | [diff] [blame] | 193 | |
Juha Hyttinen | 3944a22 | 2020-01-24 11:51:46 +0200 | [diff] [blame] | 194 | if newAlloc { |
Juha Hyttinen | aada645 | 2020-04-07 08:47:58 +0300 | [diff] [blame] | 195 | r.register[subs.ReqId.InstanceId] = subs |
Juha Hyttinen | 3944a22 | 2020-01-24 11:51:46 +0200 | [diff] [blame] | 196 | } |
Juha Hyttinen | 83ada00 | 2020-01-30 10:36:33 +0200 | [diff] [blame] | 197 | xapp.Logger.Debug("CREATE %s", subs.String()) |
Juha Hyttinen | 12d31af | 2020-01-22 12:59:01 +0200 | [diff] [blame] | 198 | xapp.Logger.Debug("Registry: substable=%v", r.register) |
| 199 | return subs, nil |
| 200 | } |
| 201 | |
Anssi Mannila | 9bcb0a4 | 2020-02-11 11:30:44 +0200 | [diff] [blame] | 202 | func (r *Registry) CheckActionTypes(subReqMsg *e2ap.E2APSubscriptionRequest) (uint64, error) { |
| 203 | var reportFound bool = false |
| 204 | var policyFound bool = false |
Anssi Mannila | f0d9526 | 2020-08-17 13:00:20 +0300 | [diff] [blame] | 205 | var insertFound bool = false |
Anssi Mannila | 9bcb0a4 | 2020-02-11 11:30:44 +0200 | [diff] [blame] | 206 | |
| 207 | for _, acts := range subReqMsg.ActionSetups { |
| 208 | if acts.ActionType == e2ap.E2AP_ActionTypeReport { |
| 209 | reportFound = true |
| 210 | } |
| 211 | if acts.ActionType == e2ap.E2AP_ActionTypePolicy { |
| 212 | policyFound = true |
| 213 | } |
Anssi Mannila | f0d9526 | 2020-08-17 13:00:20 +0300 | [diff] [blame] | 214 | if acts.ActionType == e2ap.E2AP_ActionTypeInsert { |
| 215 | insertFound = true |
| 216 | } |
Anssi Mannila | 9bcb0a4 | 2020-02-11 11:30:44 +0200 | [diff] [blame] | 217 | } |
Anssi Mannila | f0d9526 | 2020-08-17 13:00:20 +0300 | [diff] [blame] | 218 | if reportFound == true && policyFound == true || reportFound == true && insertFound == true || policyFound == true && insertFound == true { |
| 219 | 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] | 220 | } |
| 221 | if reportFound == true { |
| 222 | return e2ap.E2AP_ActionTypeReport, nil |
| 223 | } |
| 224 | if policyFound == true { |
| 225 | return e2ap.E2AP_ActionTypePolicy, nil |
| 226 | } |
Anssi Mannila | f0d9526 | 2020-08-17 13:00:20 +0300 | [diff] [blame] | 227 | if insertFound == true { |
| 228 | return e2ap.E2AP_ActionTypeInsert, nil |
| 229 | } |
Anssi Mannila | 9bcb0a4 | 2020-02-11 11:30:44 +0200 | [diff] [blame] | 230 | return e2ap.E2AP_ActionTypeInvalid, fmt.Errorf("Invalid action type in RICactions-ToBeSetup-List") |
| 231 | } |
| 232 | |
Juha Hyttinen | 83ada00 | 2020-01-30 10:36:33 +0200 | [diff] [blame] | 233 | // TODO: Works with concurrent calls, but check if can be improved |
| 234 | func (r *Registry) RemoveFromSubscription(subs *Subscription, trans *TransactionXapp, waitRouteClean time.Duration) error { |
Juha Hyttinen | 3944a22 | 2020-01-24 11:51:46 +0200 | [diff] [blame] | 235 | |
Juha Hyttinen | 12d31af | 2020-01-22 12:59:01 +0200 | [diff] [blame] | 236 | r.mutex.Lock() |
| 237 | defer r.mutex.Unlock() |
| 238 | subs.mutex.Lock() |
| 239 | defer subs.mutex.Unlock() |
| 240 | |
| 241 | delStatus := subs.EpList.DelEndpoint(trans.GetEndpoint()) |
| 242 | epamount := subs.EpList.Size() |
Juha Hyttinen | aada645 | 2020-04-07 08:47:58 +0300 | [diff] [blame] | 243 | subId := subs.ReqId.InstanceId |
Juha Hyttinen | 12d31af | 2020-01-22 12:59:01 +0200 | [diff] [blame] | 244 | |
Juha Hyttinen | 83ada00 | 2020-01-30 10:36:33 +0200 | [diff] [blame] | 245 | if delStatus == false { |
| 246 | return nil |
Anssi Mannila | 2e99e2f | 2019-12-05 13:57:06 +0200 | [diff] [blame] | 247 | } |
Juha Hyttinen | 83ada00 | 2020-01-30 10:36:33 +0200 | [diff] [blame] | 248 | |
Juha Hyttinen | f44377d | 2020-02-12 10:18:40 +0200 | [diff] [blame] | 249 | go func() { |
| 250 | if waitRouteClean > 0 { |
| 251 | time.Sleep(waitRouteClean) |
Juha Hyttinen | 83ada00 | 2020-01-30 10:36:33 +0200 | [diff] [blame] | 252 | } |
Juha Hyttinen | f44377d | 2020-02-12 10:18:40 +0200 | [diff] [blame] | 253 | |
| 254 | subs.mutex.Lock() |
| 255 | defer subs.mutex.Unlock() |
| 256 | xapp.Logger.Info("CLEAN %s", subs.String()) |
| 257 | |
| 258 | if epamount == 0 { |
| 259 | // |
| 260 | // Subscription route delete |
| 261 | // |
Juha Hyttinen | 9dc5adc | 2020-08-13 10:02:40 +0300 | [diff] [blame] | 262 | tmpList := xapp.RmrEndpointList{} |
Juha Hyttinen | f44377d | 2020-02-12 10:18:40 +0200 | [diff] [blame] | 263 | tmpList.AddEndpoint(trans.GetEndpoint()) |
Juha Hyttinen | aada645 | 2020-04-07 08:47:58 +0300 | [diff] [blame] | 264 | subRouteAction := SubRouteInfo{tmpList, uint16(subId)} |
Juha Hyttinen | f44377d | 2020-02-12 10:18:40 +0200 | [diff] [blame] | 265 | r.rtmgrClient.SubscriptionRequestDelete(subRouteAction) |
| 266 | |
| 267 | // |
| 268 | // Subscription release |
| 269 | // |
| 270 | r.mutex.Lock() |
| 271 | defer r.mutex.Unlock() |
| 272 | |
Juha Hyttinen | aada645 | 2020-04-07 08:47:58 +0300 | [diff] [blame] | 273 | if _, ok := r.register[subId]; ok { |
Juha Hyttinen | f44377d | 2020-02-12 10:18:40 +0200 | [diff] [blame] | 274 | xapp.Logger.Debug("RELEASE %s", subs.String()) |
Juha Hyttinen | aada645 | 2020-04-07 08:47:58 +0300 | [diff] [blame] | 275 | delete(r.register, subId) |
Juha Hyttinen | f44377d | 2020-02-12 10:18:40 +0200 | [diff] [blame] | 276 | xapp.Logger.Debug("Registry: substable=%v", r.register) |
| 277 | } |
Juha Hyttinen | aada645 | 2020-04-07 08:47:58 +0300 | [diff] [blame] | 278 | r.subIds = append(r.subIds, subId) |
Juha Hyttinen | f44377d | 2020-02-12 10:18:40 +0200 | [diff] [blame] | 279 | |
| 280 | } else if subs.EpList.Size() > 0 { |
| 281 | // |
| 282 | // Subscription route updates |
| 283 | // |
Juha Hyttinen | aada645 | 2020-04-07 08:47:58 +0300 | [diff] [blame] | 284 | subRouteAction := SubRouteInfo{subs.EpList, uint16(subId)} |
Juha Hyttinen | f44377d | 2020-02-12 10:18:40 +0200 | [diff] [blame] | 285 | r.rtmgrClient.SubscriptionRequestUpdate(subRouteAction) |
| 286 | } |
| 287 | |
| 288 | }() |
Juha Hyttinen | 12d31af | 2020-01-22 12:59:01 +0200 | [diff] [blame] | 289 | |
| 290 | return nil |
Juha Hyttinen | 47b842b | 2020-01-08 13:01:52 +0200 | [diff] [blame] | 291 | } |
Anssi Mannila | 2e99e2f | 2019-12-05 13:57:06 +0200 | [diff] [blame] | 292 | |
Juha Hyttinen | aada645 | 2020-04-07 08:47:58 +0300 | [diff] [blame] | 293 | func (r *Registry) GetSubscription(subId uint32) *Subscription { |
Juha Hyttinen | 47b842b | 2020-01-08 13:01:52 +0200 | [diff] [blame] | 294 | r.mutex.Lock() |
| 295 | defer r.mutex.Unlock() |
Juha Hyttinen | aada645 | 2020-04-07 08:47:58 +0300 | [diff] [blame] | 296 | if _, ok := r.register[subId]; ok { |
| 297 | return r.register[subId] |
Anssi Mannila | 2e99e2f | 2019-12-05 13:57:06 +0200 | [diff] [blame] | 298 | } |
Juha Hyttinen | 47b842b | 2020-01-08 13:01:52 +0200 | [diff] [blame] | 299 | return nil |
Peter Szilagyi | fbc56f9 | 2019-07-23 19:29:46 +0000 | [diff] [blame] | 300 | } |
| 301 | |
Juha Hyttinen | aada645 | 2020-04-07 08:47:58 +0300 | [diff] [blame] | 302 | func (r *Registry) GetSubscriptionFirstMatch(subIds []uint32) (*Subscription, error) { |
Juha Hyttinen | 422d018 | 2020-01-17 13:37:05 +0200 | [diff] [blame] | 303 | r.mutex.Lock() |
| 304 | defer r.mutex.Unlock() |
Juha Hyttinen | aada645 | 2020-04-07 08:47:58 +0300 | [diff] [blame] | 305 | for _, subId := range subIds { |
| 306 | if _, ok := r.register[subId]; ok { |
| 307 | return r.register[subId], nil |
Juha Hyttinen | 422d018 | 2020-01-17 13:37:05 +0200 | [diff] [blame] | 308 | } |
| 309 | } |
Juha Hyttinen | aada645 | 2020-04-07 08:47:58 +0300 | [diff] [blame] | 310 | return nil, fmt.Errorf("No valid subscription found with subIds %v", subIds) |
Juha Hyttinen | 422d018 | 2020-01-17 13:37:05 +0200 | [diff] [blame] | 311 | } |