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 {
38 RmrEndpoint // xapp endpoint. Now only one xapp can have relation to single subscription. To be changed in merge
42 func (s *Subscription) String() string {
44 defer s.mutex.Unlock()
45 return strconv.FormatUint(uint64(s.Seq), 10) + "/" + s.RmrEndpoint.String() + "/" + s.Meid.RanName
48 func (s *Subscription) GetSubId() uint16 {
50 defer s.mutex.Unlock()
54 func (s *Subscription) GetMeid() *xapp.RMRMeid {
56 defer s.mutex.Unlock()
63 func (s *Subscription) Confirmed() {
65 defer s.mutex.Unlock()
69 func (s *Subscription) UnConfirmed() {
71 defer s.mutex.Unlock()
75 func (s *Subscription) IsConfirmed() bool {
77 defer s.mutex.Unlock()
81 func (s *Subscription) SetTransaction(trans *Transaction) error {
83 defer s.mutex.Unlock()
85 subString := strconv.FormatUint(uint64(s.Seq), 10) + "/" + s.RmrEndpoint.String() + "/" + s.Meid.RanName
87 if (s.RmrEndpoint.Addr != trans.RmrEndpoint.Addr) || (s.RmrEndpoint.Port != trans.RmrEndpoint.Port) {
88 return fmt.Errorf("Subscription: %s endpoint mismatch with trans: %s", subString, trans)
91 return fmt.Errorf("Subscription: %s trans %s exist, can not register %s", subString, s.Trans, trans)
98 func (s *Subscription) UnSetTransaction(trans *Transaction) bool {
100 defer s.mutex.Unlock()
101 if trans == nil || trans == s.Trans {
108 func (s *Subscription) GetTransaction() *Transaction {
110 defer s.mutex.Unlock()
114 func (s *Subscription) UpdateRoute(act Action, rtmgrClient *RtmgrClient) error {
116 defer s.mutex.Unlock()
117 xapp.Logger.Info("Subscription: Starting routing manager route add. SubId: %d, RmrEndpoint: %s", s.Seq, s.RmrEndpoint)
118 subRouteAction := SubRouteInfo{act, s.RmrEndpoint.Addr, s.RmrEndpoint.Port, s.Seq}
119 err := rtmgrClient.SubscriptionRequestUpdate(subRouteAction)
121 return fmt.Errorf("Subscription: Failed to add route. SubId: %d, RmrEndpoint: %s", s.Seq, s.RmrEndpoint)