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"
29 //-----------------------------------------------------------------------------
31 //-----------------------------------------------------------------------------
32 type Subscription struct {
39 RmrEndpoint // xapp endpoint. Now only one xapp can have relation to single subscription. To be changed in merge
43 func (s *Subscription) String() string {
45 defer s.mutex.Unlock()
46 return strconv.FormatUint(uint64(s.Seq), 10) + "/" + s.RmrEndpoint.String() + "/" + s.Meid.RanName
49 func (s *Subscription) GetSubId() uint16 {
51 defer s.mutex.Unlock()
55 func (s *Subscription) GetMeid() *xapp.RMRMeid {
57 defer s.mutex.Unlock()
64 func (s *Subscription) Confirmed() {
66 defer s.mutex.Unlock()
70 func (s *Subscription) UnConfirmed() {
72 defer s.mutex.Unlock()
76 func (s *Subscription) IsConfirmed() bool {
78 defer s.mutex.Unlock()
82 func (s *Subscription) SetTransaction(trans *Transaction) error {
84 defer s.mutex.Unlock()
86 subString := strconv.FormatUint(uint64(s.Seq), 10) + "/" + s.RmrEndpoint.String() + "/" + s.Meid.RanName
88 if (s.RmrEndpoint.Addr != trans.RmrEndpoint.Addr) || (s.RmrEndpoint.Port != trans.RmrEndpoint.Port) {
89 return fmt.Errorf("Subscription: %s endpoint mismatch with trans: %s", subString, trans)
92 return fmt.Errorf("Subscription: %s trans %s exist, can not register %s", subString, s.Trans, trans)
99 func (s *Subscription) UnSetTransaction(trans *Transaction) bool {
101 defer s.mutex.Unlock()
102 if trans == nil || trans == s.Trans {
109 func (s *Subscription) GetTransaction() *Transaction {
111 defer s.mutex.Unlock()
115 func (s *Subscription) updateRouteImpl(act Action) error {
116 xapp.Logger.Info("Subscription: Starting routing manager route add. SubId: %d, RmrEndpoint: %s", s.Seq, s.RmrEndpoint)
117 subRouteAction := SubRouteInfo{act, s.RmrEndpoint.Addr, s.RmrEndpoint.Port, s.Seq}
118 err := s.registry.rtmgrClient.SubscriptionRequestUpdate(subRouteAction)
120 return fmt.Errorf("Subscription: Failed to add route. SubId: %d, RmrEndpoint: %s", s.Seq, s.RmrEndpoint)
125 func (s *Subscription) UpdateRoute(act Action) error {
127 defer s.mutex.Unlock()
128 return s.updateRouteImpl(act)
131 func (s *Subscription) Release() {
132 xapp.Logger.Info("Subscription: Releasing %s", s)
134 defer s.mutex.Unlock()
135 s.registry.DelSubscription(s.Seq)
136 err := s.updateRouteImpl(DELETE)
138 xapp.Logger.Error("Registry: Failed to del route. SubId: %d, RmrEndpoint: %s", s.Seq, s.RmrEndpoint)