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 ==================================================================================
28 rtmgrclient "gerrit.o-ran-sc.org/r/ric-plt/submgr/pkg/rtmgr_client"
29 rtmgrhandle "gerrit.o-ran-sc.org/r/ric-plt/submgr/pkg/rtmgr_client/handle"
30 "gerrit.o-ran-sc.org/r/ric-plt/submgr/pkg/rtmgr_models"
31 "gerrit.o-ran-sc.org/r/ric-plt/xapp-frame/pkg/xapp"
34 //-----------------------------------------------------------------------------
36 //-----------------------------------------------------------------------------
37 type SubRouteInfo struct {
38 EpList xapp.RmrEndpointList
42 func (sri *SubRouteInfo) String() string {
43 return "routeinfo(" + strconv.FormatUint(uint64(sri.SubID), 10) + "/[" + sri.EpList.String() + "])"
46 //-----------------------------------------------------------------------------
48 //-----------------------------------------------------------------------------
49 type RtmgrClient struct {
50 rtClient *rtmgrclient.RoutingManager
53 func (rc *RtmgrClient) SubscriptionRequestCreate(subRouteAction SubRouteInfo) error {
54 subID := int32(subRouteAction.SubID)
55 xapp.Logger.Debug("CREATE %s ongoing", subRouteAction.String())
56 createData := rtmgr_models.XappSubscriptionData{&subRouteAction.EpList.Endpoints[0].Addr, &subRouteAction.EpList.Endpoints[0].Port, &subID}
57 createHandle := rtmgrhandle.NewProvideXappSubscriptionHandleParamsWithTimeout(2 * time.Second)
58 createHandle.WithXappSubscriptionData(&createData)
59 _, err := rc.rtClient.Handle.ProvideXappSubscriptionHandle(createHandle)
60 if err != nil && !(strings.Contains(err.Error(), "status 200")) {
61 return fmt.Errorf("CREATE %s failed with error: %s", subRouteAction.String(), err.Error())
63 xapp.Logger.Debug("CREATE %s successful", subRouteAction.String())
67 func (rc *RtmgrClient) SubscriptionRequestUpdate(subRouteAction SubRouteInfo) error {
68 xapp.Logger.Debug("UPDATE %s ongoing", subRouteAction.String())
69 var updateData rtmgr_models.XappList
70 for i := range subRouteAction.EpList.Endpoints {
71 updateData = append(updateData, &rtmgr_models.XappElement{Address: &subRouteAction.EpList.Endpoints[i].Addr, Port: &subRouteAction.EpList.Endpoints[i].Port})
73 updateHandle := rtmgrhandle.NewUpdateXappSubscriptionHandleParamsWithTimeout(2 * time.Second)
74 updateHandle.WithSubscriptionID(subRouteAction.SubID)
75 updateHandle.WithXappList(updateData)
76 _, err := rc.rtClient.Handle.UpdateXappSubscriptionHandle(updateHandle)
77 if err != nil && !(strings.Contains(err.Error(), "status 200")) {
78 return fmt.Errorf("UPDATE %s failed with error: %s", subRouteAction.String(), err.Error())
80 xapp.Logger.Debug("UPDATE %s successful", subRouteAction.String())
85 func (rc *RtmgrClient) SubscriptionRequestDelete(subRouteAction SubRouteInfo) error {
86 subID := int32(subRouteAction.SubID)
87 xapp.Logger.Debug("DELETE %s ongoing", subRouteAction.String())
88 deleteData := rtmgr_models.XappSubscriptionData{&subRouteAction.EpList.Endpoints[0].Addr, &subRouteAction.EpList.Endpoints[0].Port, &subID}
89 deleteHandle := rtmgrhandle.NewDeleteXappSubscriptionHandleParamsWithTimeout(2 * time.Second)
90 deleteHandle.WithXappSubscriptionData(&deleteData)
91 _, _, err := rc.rtClient.Handle.DeleteXappSubscriptionHandle(deleteHandle)
92 if err != nil && !(strings.Contains(err.Error(), "status 200")) {
93 return fmt.Errorf("DELETE %s failed with error: %s", subRouteAction.String(), err.Error())
95 xapp.Logger.Debug("DELETE %s successful", subRouteAction.String())