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 ==================================================================================
23 "gerrit.o-ran-sc.org/r/ric-plt/xapp-frame/pkg/xapp"
27 type Subscription struct {
32 func (s *Subscription) Confirmed() {
36 func (s *Subscription) UnConfirmed() {
40 func (s *Subscription) IsConfirmed() bool {
44 type Registry struct {
45 register map[uint16]*Subscription
50 // This method should run as a constructor
51 func (r *Registry) Initialize(seedsn uint16) {
52 r.register = make(map[uint16]*Subscription)
56 // Reserves and returns the next free sequence number
57 func (r *Registry) ReserveSubscription() *Subscription {
58 // Check is current SequenceNumber valid
59 // Allocate next SequenceNumber value and retry N times
61 defer r.mutex.Unlock()
62 var subs *Subscription = nil
63 var retrytimes uint16 = 1000
64 for ; subs == nil && retrytimes > 0; retrytimes-- {
65 sequenceNumber := r.counter
66 if r.counter == 65535 {
71 if _, ok := r.register[sequenceNumber]; ok == false {
72 r.register[sequenceNumber] = &Subscription{sequenceNumber, false}
73 return r.register[sequenceNumber]
79 // This function checks the validity of the given subscription id
80 func (r *Registry) GetSubscription(sn uint16) *Subscription {
82 defer r.mutex.Unlock()
83 xapp.Logger.Debug("Registry map: %v", r.register)
84 if _, ok := r.register[sn]; ok {
90 // This function checks the validity of the given subscription id
91 func (r *Registry) IsValidSequenceNumber(sn uint16) bool {
93 defer r.mutex.Unlock()
94 xapp.Logger.Debug("Registry map: %v", r.register)
95 if _, ok := r.register[sn]; ok {
101 // This function sets the give id as confirmed in the register
102 func (r *Registry) setSubscriptionToConfirmed(sn uint16) {
104 defer r.mutex.Unlock()
105 r.register[sn].Confirmed()
108 //This function sets the given id as unused in the register
109 func (r *Registry) setSubscriptionToUnConfirmed(sn uint16) {
111 defer r.mutex.Unlock()
112 r.register[sn].UnConfirmed()
115 //This function releases the given id as unused in the register
116 func (r *Registry) releaseSequenceNumber(sn uint16) bool {
118 defer r.mutex.Unlock()
119 if _, ok := r.register[sn]; ok {
120 delete(r.register, sn)