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 rtmgrclient "gerrit.o-ran-sc.org/r/ric-plt/submgr/pkg/rtmgr_client"
25 rtmgrhandle "gerrit.o-ran-sc.org/r/ric-plt/submgr/pkg/rtmgr_client/handle"
26 "gerrit.o-ran-sc.org/r/ric-plt/submgr/pkg/rtmgr_models"
27 "gerrit.o-ran-sc.org/r/ric-plt/xapp-frame/pkg/xapp"
32 type RtmgrClient struct {
33 rtClient *rtmgrclient.RoutingManager
34 xappHandleParams *rtmgrhandle.ProvideXappSubscriptionHandleParams
35 xappDeleteParams *rtmgrhandle.DeleteXappSubscriptionHandleParams
38 func (rc *RtmgrClient) SubscriptionRequestUpdate() error {
39 xapp.Logger.Debug("SubscriptionRequestUpdate() invoked")
40 subRouteAction := <-SubscriptionReqChan
41 // Routing manager handles subscription id as int32 to accomodate -1 and uint16 values
42 subID := int32(subRouteAction.SubID)
44 xapp.Logger.Debug("Subscription action details received: ", subRouteAction)
46 xappSubReq := rtmgr_models.XappSubscriptionData{&subRouteAction.Address, &subRouteAction.Port, &subID}
48 switch subRouteAction.Command {
50 _, postErr := rc.rtClient.Handle.ProvideXappSubscriptionHandle(rc.xappHandleParams.WithXappSubscriptionData(&xappSubReq))
51 if postErr != nil && !(strings.Contains(postErr.Error(), "status 200")) {
52 xapp.Logger.Error("Updating routing manager about subscription id = %d failed with error: %v", subID, postErr)
55 xapp.Logger.Info("Succesfully updated routing manager about the subscription: %d", subID)
59 _, _, deleteErr := rc.rtClient.Handle.DeleteXappSubscriptionHandle(rc.xappDeleteParams.WithXappSubscriptionData(&xappSubReq))
60 if deleteErr != nil && !(strings.Contains(deleteErr.Error(), "status 200")) {
61 xapp.Logger.Error("Deleting subscription id = %d in routing manager, failed with error: %v", subID, deleteErr)
64 xapp.Logger.Info("Succesfully deleted subscription: %d in routing manager.", subID)
72 func (rc *RtmgrClient) SplitSource(src string) (*string, *uint16, error) {
73 tcpSrc := strings.Split(src, ":")
75 err := errors.New("unable to get the source details of the xapp - check the source string received from the rmr")
79 xapp.Logger.Debug("---Debugging Inside splitsource tcpsrc[0] = %s and tcpsrc[1]= %s ", tcpSrc[0], tcpSrc[1])
80 srcPort, err := strconv.ParseUint(tcpSrc[1], 10, 16)
84 srcPortInt := uint16(srcPort)
85 return &srcAddr, &srcPortInt, nil