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 Registry struct {
28 register map[uint16]bool
33 // This method should run as a constructor
34 func (r *Registry) Initialize(seedsn uint16) {
35 r.register = make(map[uint16]bool)
39 // Reserves and returns the next free sequence number
40 func (r *Registry) ReserveSequenceNumber() (uint16, bool) {
41 // Check is current SequenceNumber valid
43 defer r.mutex.Unlock()
44 sequenceNumber := r.counter
45 if _, ok := r.register[sequenceNumber]; ok {
46 xapp.Logger.Error("Invalid SeqenceNumber sequenceNumber: %v", sequenceNumber)
47 return sequenceNumber, false
49 r.register[sequenceNumber] = false
51 // Allocate next SequenceNumber value
52 if r.counter == 65535 {
57 return sequenceNumber, true
60 // This function checks the validity of the given subscription id
61 func (r *Registry) IsValidSequenceNumber(sn uint16) bool {
63 defer r.mutex.Unlock()
64 xapp.Logger.Debug("Registry map: %v", r.register)
65 if _, ok := r.register[sn]; ok {
71 // This function sets the give id as confirmed in the register
72 func (r *Registry) setSubscriptionToConfirmed(sn uint16) {
74 defer r.mutex.Unlock()
78 //This function sets the given id as unused in the register
79 func (r *Registry) deleteSubscription(sn uint16) {
81 defer r.mutex.Unlock()
82 r.register[sn] = false
85 //This function releases the given id as unused in the register
86 func (r *Registry) releaseSequenceNumber(sn uint16) bool {
88 defer r.mutex.Unlock()
89 if _, ok := r.register[sn]; ok {
90 delete(r.register, sn)