kalnagy | 93cc3e2 | 2019-09-19 11:29:29 +0200 | [diff] [blame] | 1 | /* |
| 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 | |
| 20 | package control |
| 21 | |
| 22 | import ( |
Juha Hyttinen | 31797b4 | 2020-01-16 14:05:01 +0200 | [diff] [blame] | 23 | "fmt" |
kalnagy | 93cc3e2 | 2019-09-19 11:29:29 +0200 | [diff] [blame] | 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" |
kalnagy | 93cc3e2 | 2019-09-19 11:29:29 +0200 | [diff] [blame] | 27 | "gerrit.o-ran-sc.org/r/ric-plt/xapp-frame/pkg/xapp" |
kalnagy | 1455c85 | 2019-10-21 13:06:23 +0200 | [diff] [blame] | 28 | "strconv" |
| 29 | "strings" |
Juha Hyttinen | 12d31af | 2020-01-22 12:59:01 +0200 | [diff] [blame] | 30 | "time" |
kalnagy | 93cc3e2 | 2019-09-19 11:29:29 +0200 | [diff] [blame] | 31 | ) |
| 32 | |
Juha Hyttinen | 31797b4 | 2020-01-16 14:05:01 +0200 | [diff] [blame] | 33 | //----------------------------------------------------------------------------- |
| 34 | // |
| 35 | //----------------------------------------------------------------------------- |
| 36 | type SubRouteInfo struct { |
Juha Hyttinen | 83ada00 | 2020-01-30 10:36:33 +0200 | [diff] [blame] | 37 | EpList RmrEndpointList |
| 38 | SubID uint16 |
Juha Hyttinen | 31797b4 | 2020-01-16 14:05:01 +0200 | [diff] [blame] | 39 | } |
| 40 | |
| 41 | func (sri *SubRouteInfo) String() string { |
Juha Hyttinen | 83ada00 | 2020-01-30 10:36:33 +0200 | [diff] [blame] | 42 | return "routeinfo(" + strconv.FormatUint(uint64(sri.SubID), 10) + "/[" + sri.EpList.String() + "])" |
Juha Hyttinen | 31797b4 | 2020-01-16 14:05:01 +0200 | [diff] [blame] | 43 | } |
| 44 | |
| 45 | //----------------------------------------------------------------------------- |
| 46 | // |
| 47 | //----------------------------------------------------------------------------- |
kalnagy | 93cc3e2 | 2019-09-19 11:29:29 +0200 | [diff] [blame] | 48 | type RtmgrClient struct { |
Juha Hyttinen | 12d31af | 2020-01-22 12:59:01 +0200 | [diff] [blame] | 49 | rtClient *rtmgrclient.RoutingManager |
kalnagy | 93cc3e2 | 2019-09-19 11:29:29 +0200 | [diff] [blame] | 50 | } |
| 51 | |
Juha Hyttinen | 83ada00 | 2020-01-30 10:36:33 +0200 | [diff] [blame] | 52 | func (rc *RtmgrClient) SubscriptionRequestCreate(subRouteAction SubRouteInfo) error { |
kalnagy | 93cc3e2 | 2019-09-19 11:29:29 +0200 | [diff] [blame] | 53 | subID := int32(subRouteAction.SubID) |
Juha Hyttinen | 83ada00 | 2020-01-30 10:36:33 +0200 | [diff] [blame] | 54 | xapp.Logger.Debug("CREATE %s ongoing", subRouteAction.String()) |
| 55 | createData := rtmgr_models.XappSubscriptionData{&subRouteAction.EpList.Endpoints[0].Addr, &subRouteAction.EpList.Endpoints[0].Port, &subID} |
| 56 | createHandle := rtmgrhandle.NewProvideXappSubscriptionHandleParamsWithTimeout(10 * time.Second) |
| 57 | createHandle.WithXappSubscriptionData(&createData) |
| 58 | _, err := rc.rtClient.Handle.ProvideXappSubscriptionHandle(createHandle) |
Juha Hyttinen | 31797b4 | 2020-01-16 14:05:01 +0200 | [diff] [blame] | 59 | if err != nil && !(strings.Contains(err.Error(), "status 200")) { |
Juha Hyttinen | 83ada00 | 2020-01-30 10:36:33 +0200 | [diff] [blame] | 60 | return fmt.Errorf("CREATE %s failed with error: %s", subRouteAction.String(), err.Error()) |
kalnagy | 93cc3e2 | 2019-09-19 11:29:29 +0200 | [diff] [blame] | 61 | } |
Juha Hyttinen | 83ada00 | 2020-01-30 10:36:33 +0200 | [diff] [blame] | 62 | xapp.Logger.Debug("CREATE %s successful", subRouteAction.String()) |
| 63 | return nil |
| 64 | } |
| 65 | |
| 66 | func (rc *RtmgrClient) SubscriptionRequestUpdate(subRouteAction SubRouteInfo) error { |
| 67 | xapp.Logger.Debug("UPDATE %s ongoing", subRouteAction.String()) |
| 68 | var updateData rtmgr_models.XappList |
| 69 | for i := range subRouteAction.EpList.Endpoints { |
| 70 | updateData = append(updateData, &rtmgr_models.XappElement{Address: &subRouteAction.EpList.Endpoints[i].Addr, Port: &subRouteAction.EpList.Endpoints[i].Port}) |
| 71 | } |
| 72 | updateHandle := rtmgrhandle.NewUpdateXappSubscriptionHandleParamsWithTimeout(10 * time.Second) |
| 73 | updateHandle.WithSubscriptionID(subRouteAction.SubID) |
| 74 | updateHandle.WithXappList(updateData) |
| 75 | _, err := rc.rtClient.Handle.UpdateXappSubscriptionHandle(updateHandle) |
| 76 | if err != nil && !(strings.Contains(err.Error(), "status 200")) { |
| 77 | return fmt.Errorf("UPDATE %s failed with error: %s", subRouteAction.String(), err.Error()) |
| 78 | } |
| 79 | xapp.Logger.Debug("UPDATE %s successful", subRouteAction.String()) |
Juha Hyttinen | 31797b4 | 2020-01-16 14:05:01 +0200 | [diff] [blame] | 80 | return nil |
| 81 | |
kalnagy | 93cc3e2 | 2019-09-19 11:29:29 +0200 | [diff] [blame] | 82 | } |
Juha Hyttinen | 83ada00 | 2020-01-30 10:36:33 +0200 | [diff] [blame] | 83 | |
| 84 | func (rc *RtmgrClient) SubscriptionRequestDelete(subRouteAction SubRouteInfo) error { |
| 85 | subID := int32(subRouteAction.SubID) |
| 86 | xapp.Logger.Debug("DELETE %s ongoing", subRouteAction.String()) |
| 87 | deleteData := rtmgr_models.XappSubscriptionData{&subRouteAction.EpList.Endpoints[0].Addr, &subRouteAction.EpList.Endpoints[0].Port, &subID} |
| 88 | deleteHandle := rtmgrhandle.NewDeleteXappSubscriptionHandleParamsWithTimeout(10 * time.Second) |
| 89 | deleteHandle.WithXappSubscriptionData(&deleteData) |
| 90 | _, _, err := rc.rtClient.Handle.DeleteXappSubscriptionHandle(deleteHandle) |
| 91 | if err != nil && !(strings.Contains(err.Error(), "status 200")) { |
| 92 | return fmt.Errorf("DELETE %s failed with error: %s", subRouteAction.String(), err.Error()) |
| 93 | } |
| 94 | xapp.Logger.Debug("DELETE %s successful", subRouteAction.String()) |
| 95 | return nil |
| 96 | } |