blob: d377d8ea0b90dab88948a009d5894bd88a2a98d1 [file] [log] [blame]
kalnagy93cc3e22019-09-19 11:29:29 +02001/*
2==================================================================================
3 Copyright (c) 2019 AT&T Intellectual Property.
4 Copyright (c) 2019 Nokia
5
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
9
10 http://www.apache.org/licenses/LICENSE-2.0
11
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==================================================================================
18*/
19
20package control
21
22import (
kalnagy1455c852019-10-21 13:06:23 +020023 "errors"
kalnagy93cc3e22019-09-19 11:29:29 +020024 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"
kalnagy93cc3e22019-09-19 11:29:29 +020027 "gerrit.o-ran-sc.org/r/ric-plt/xapp-frame/pkg/xapp"
kalnagy1455c852019-10-21 13:06:23 +020028 "strconv"
29 "strings"
kalnagy93cc3e22019-09-19 11:29:29 +020030)
31
32type RtmgrClient struct {
33 rtClient *rtmgrclient.RoutingManager
34 xappHandleParams *rtmgrhandle.ProvideXappSubscriptionHandleParams
kalnagye0018682019-09-26 16:28:25 +020035 xappDeleteParams *rtmgrhandle.DeleteXappSubscriptionHandleParams
kalnagy93cc3e22019-09-19 11:29:29 +020036}
37
Anssi Mannila2e99e2f2019-12-05 13:57:06 +020038func (rc *RtmgrClient) SubscriptionRequestUpdate(subRouteAction SubRouteInfo) error {
kalnagy93cc3e22019-09-19 11:29:29 +020039 xapp.Logger.Debug("SubscriptionRequestUpdate() invoked")
kalnagy93cc3e22019-09-19 11:29:29 +020040 subID := int32(subRouteAction.SubID)
Anssi Mannila2e99e2f2019-12-05 13:57:06 +020041 xapp.Logger.Debug("Subscription action details received. subRouteAction.Command: %v, Address %s, Port %v, subID %v", int16(subRouteAction.Command), subRouteAction.Address, subRouteAction.Port, subID)
kalnagy93cc3e22019-09-19 11:29:29 +020042 xappSubReq := rtmgr_models.XappSubscriptionData{&subRouteAction.Address, &subRouteAction.Port, &subID}
43
44 switch subRouteAction.Command {
45 case CREATE:
46 _, postErr := rc.rtClient.Handle.ProvideXappSubscriptionHandle(rc.xappHandleParams.WithXappSubscriptionData(&xappSubReq))
kalnagy1455c852019-10-21 13:06:23 +020047 if postErr != nil && !(strings.Contains(postErr.Error(), "status 200")) {
kalnagy93cc3e22019-09-19 11:29:29 +020048 xapp.Logger.Error("Updating routing manager about subscription id = %d failed with error: %v", subID, postErr)
49 return postErr
50 } else {
51 xapp.Logger.Info("Succesfully updated routing manager about the subscription: %d", subID)
52 return nil
53 }
kalnagye0018682019-09-26 16:28:25 +020054 case DELETE:
55 _, _, deleteErr := rc.rtClient.Handle.DeleteXappSubscriptionHandle(rc.xappDeleteParams.WithXappSubscriptionData(&xappSubReq))
kalnagy1455c852019-10-21 13:06:23 +020056 if deleteErr != nil && !(strings.Contains(deleteErr.Error(), "status 200")) {
kalnagye0018682019-09-26 16:28:25 +020057 xapp.Logger.Error("Deleting subscription id = %d in routing manager, failed with error: %v", subID, deleteErr)
58 return deleteErr
59 } else {
60 xapp.Logger.Info("Succesfully deleted subscription: %d in routing manager.", subID)
61 return nil
62 }
kalnagy93cc3e22019-09-19 11:29:29 +020063 default:
Anssi Mannila2e99e2f2019-12-05 13:57:06 +020064 xapp.Logger.Debug("Unknown subRouteAction.Command: %v, subID: %v", subRouteAction.Command, subRouteAction.Address, subRouteAction.Port, subID)
kalnagy93cc3e22019-09-19 11:29:29 +020065 return nil
66 }
67}
68
69func (rc *RtmgrClient) SplitSource(src string) (*string, *uint16, error) {
70 tcpSrc := strings.Split(src, ":")
71 if len(tcpSrc) != 2 {
kalnagy1455c852019-10-21 13:06:23 +020072 err := errors.New("unable to get the source details of the xapp - check the source string received from the rmr")
kalnagy93cc3e22019-09-19 11:29:29 +020073 return nil, nil, err
74 }
75 srcAddr := tcpSrc[0]
kalnagy1455c852019-10-21 13:06:23 +020076 xapp.Logger.Debug("---Debugging Inside splitsource tcpsrc[0] = %s and tcpsrc[1]= %s ", tcpSrc[0], tcpSrc[1])
kalnagy93cc3e22019-09-19 11:29:29 +020077 srcPort, err := strconv.ParseUint(tcpSrc[1], 10, 16)
78 if err != nil {
79 return nil, nil, err
80 }
81 srcPortInt := uint16(srcPort)
82 return &srcAddr, &srcPortInt, nil
83}