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"
28 //-----------------------------------------------------------------------------
30 //-----------------------------------------------------------------------------
31 type Subscription struct {
37 RmrEndpoint // xapp endpoint
41 func (s *Subscription) String() string {
43 defer s.mutex.Unlock()
44 return strconv.FormatUint(uint64(s.Seq), 10) + "/" + s.RmrEndpoint.String() + "/" + s.Meid.RanName
47 func (s *Subscription) Confirmed() {
49 defer s.mutex.Unlock()
53 func (s *Subscription) UnConfirmed() {
55 defer s.mutex.Unlock()
59 func (s *Subscription) IsConfirmed() bool {
61 defer s.mutex.Unlock()
65 func (s *Subscription) SetTransaction(trans *Transaction) bool {
67 defer s.mutex.Unlock()
75 func (s *Subscription) UnSetTransaction(trans *Transaction) bool {
77 defer s.mutex.Unlock()
78 if trans == nil || trans == s.Trans {
85 func (s *Subscription) GetTransaction() *Transaction {
87 defer s.mutex.Unlock()
91 func (s *Subscription) SubRouteInfo(act Action) SubRouteInfo {
93 defer s.mutex.Unlock()
94 return SubRouteInfo{act, s.RmrEndpoint.Addr, s.RmrEndpoint.Port, s.Seq}
97 //-----------------------------------------------------------------------------
99 //-----------------------------------------------------------------------------
100 type Registry struct {
101 register map[uint16]*Subscription
106 // This method should run as a constructor
107 func (r *Registry) Initialize(seedsn uint16) {
108 r.register = make(map[uint16]*Subscription)
112 // Reserves and returns the next free sequence number
113 func (r *Registry) ReserveSubscription(endPoint RmrEndpoint, meid *xapp.RMRMeid) *Subscription {
114 // Check is current SequenceNumber valid
115 // Allocate next SequenceNumber value and retry N times
117 defer r.mutex.Unlock()
118 var subs *Subscription = nil
119 var retrytimes uint16 = 1000
120 for ; subs == nil && retrytimes > 0; retrytimes-- {
121 sequenceNumber := r.counter
122 if r.counter == 65535 {
127 if _, ok := r.register[sequenceNumber]; ok == false {
128 r.register[sequenceNumber] = &Subscription{
131 RmrEndpoint: endPoint,
135 return r.register[sequenceNumber]
141 func (r *Registry) GetSubscription(sn uint16) *Subscription {
143 defer r.mutex.Unlock()
144 xapp.Logger.Debug("Registry map: %v", r.register)
145 if _, ok := r.register[sn]; ok {
146 return r.register[sn]
151 //This function releases the given id as unused in the register
152 func (r *Registry) releaseSequenceNumber(sn uint16) bool {
154 defer r.mutex.Unlock()
155 if _, ok := r.register[sn]; ok {
156 delete(r.register, sn)