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(seedsn uint16) {
40 r.register = make(map[uint16]*Subscription)
44 // Reserves and returns the next free sequence number
45 func (r *Registry) ReserveSubscription(endPoint RmrEndpoint, meid *xapp.RMRMeid) (*Subscription, error) {
46 // Check is current SequenceNumber valid
47 // Allocate next SequenceNumber value and retry N times
49 defer r.mutex.Unlock()
50 var subs *Subscription = nil
51 var retrytimes uint16 = 1000
52 for ; subs == nil && retrytimes > 0; retrytimes-- {
53 sequenceNumber := r.counter
54 if r.counter == 65535 {
59 if _, ok := r.register[sequenceNumber]; ok == false {
60 subs := &Subscription{
63 RmrEndpoint: endPoint,
67 r.register[sequenceNumber] = subs
71 err := subs.UpdateRoute(CREATE, r.rtmgrClient)
74 if _, ok := r.register[sequenceNumber]; ok {
75 delete(r.register, sequenceNumber)
82 return nil, fmt.Errorf("Registry: Failed to reserves subcription. 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 subs := r.register[sn]
100 delete(r.register, sn)
104 err := subs.UpdateRoute(DELETE, r.rtmgrClient)
107 xapp.Logger.Error("Registry: Failed to del route. SubId: %d, RmrEndpoint: %s", subs.Seq, subs.RmrEndpoint)