2 ==================================================================================
3 Copyright (c) 2019 AT&T Intellectual Property.
4 Copyright (c) 2019 Nokia
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
10 http://www.apache.org/licenses/LICENSE-2.0
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 ==================================================================================
24 "gerrit.o-ran-sc.org/r/ric-plt/xapp-frame/pkg/xapp"
28 //-----------------------------------------------------------------------------
30 //-----------------------------------------------------------------------------
31 type Registry struct {
33 register map[uint16]*Subscription
35 rtmgrClient *RtmgrClient
38 // This method should run as a constructor
39 func (r *Registry) Initialize() {
40 r.register = make(map[uint16]*Subscription)
42 for i = 0; i < 65535; i++ {
43 r.subIds = append(r.subIds, i+1)
47 // Reserves and returns the next free sequence number
48 func (r *Registry) ReserveSubscription(endPoint *RmrEndpoint, meid *xapp.RMRMeid) (*Subscription, error) {
49 // Check is current SequenceNumber valid
50 // Allocate next SequenceNumber value and retry N times
52 defer r.mutex.Unlock()
53 var subs *Subscription = nil
54 var retrytimes uint16 = 1000
55 for ; subs == nil && retrytimes > 0; retrytimes-- {
56 sequenceNumber := r.subIds[0]
57 r.subIds = r.subIds[1:]
58 if _, ok := r.register[sequenceNumber]; ok == false {
59 subs := &Subscription{
63 RmrEndpoint: *endPoint,
67 r.register[sequenceNumber] = subs
71 err := subs.UpdateRoute(CREATE)
74 if _, ok := r.register[sequenceNumber]; ok {
75 delete(r.register, sequenceNumber)
82 return nil, fmt.Errorf("Registry: Failed to reserves subscription. RmrEndpoint: %s, Meid: %s", endPoint, meid.RanName)
85 func (r *Registry) GetSubscription(sn uint16) *Subscription {
87 defer r.mutex.Unlock()
88 xapp.Logger.Debug("Registry map: %v", r.register)
89 if _, ok := r.register[sn]; ok {
95 func (r *Registry) DelSubscription(sn uint16) bool {
97 defer r.mutex.Unlock()
98 if _, ok := r.register[sn]; ok {
99 r.subIds = append(r.subIds, sn)
100 delete(r.register, sn)