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) Confirmed() {
50 defer s.mutex.Unlock()
54 func (s *Subscription) UnConfirmed() {
56 defer s.mutex.Unlock()
60 func (s *Subscription) IsConfirmed() bool {
62 defer s.mutex.Unlock()
66 func (s *Subscription) SetTransaction(trans *Transaction) error {
68 defer s.mutex.Unlock()
70 subString := strconv.FormatUint(uint64(s.Seq), 10) + "/" + s.RmrEndpoint.String() + "/" + s.Meid.RanName
72 if (s.RmrEndpoint.Addr != trans.RmrEndpoint.Addr) || (s.RmrEndpoint.Port != trans.RmrEndpoint.Port) {
73 return fmt.Errorf("Subscription: %s endpoint mismatch with trans: %s", subString, trans)
76 return fmt.Errorf("Subscription: %s trans %s exist, can not register %s", subString, s.Trans, trans)
83 func (s *Subscription) UnSetTransaction(trans *Transaction) bool {
85 defer s.mutex.Unlock()
86 if trans == nil || trans == s.Trans {
93 func (s *Subscription) GetTransaction() *Transaction {
95 defer s.mutex.Unlock()
99 func (s *Subscription) UpdateRoute(act Action, rtmgrClient *RtmgrClient) error {
101 defer s.mutex.Unlock()
102 xapp.Logger.Info("Subscription: Starting routing manager route add. SubId: %d, RmrEndpoint: %s", s.Seq, s.RmrEndpoint)
103 subRouteAction := SubRouteInfo{act, s.RmrEndpoint.Addr, s.RmrEndpoint.Port, s.Seq}
104 err := rtmgrClient.SubscriptionRequestUpdate(subRouteAction)
106 return fmt.Errorf("Subscription: Failed to add route. SubId: %d, RmrEndpoint: %s", s.Seq, s.RmrEndpoint)