Balint Uveges | 871fa39 | 2019-04-02 20:31:11 +0000 | [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 | Mnemonic: rpe.go |
| 21 | Abstract: Contains RPE (Route Policy Engine) module definitions and generic RPE components |
| 22 | Date: 16 March 2019 |
| 23 | */ |
| 24 | |
| 25 | package rpe |
| 26 | |
| 27 | import ( |
| 28 | "errors" |
kalnagy | 9216265 | 2019-07-02 15:15:49 +0200 | [diff] [blame] | 29 | "routing-manager/pkg/rtmgr" |
zkoczka | eb2ff0d | 2019-09-26 16:59:54 +0200 | [diff] [blame] | 30 | "routing-manager/pkg/sbi" |
kalnagy | 9216265 | 2019-07-02 15:15:49 +0200 | [diff] [blame] | 31 | "strconv" |
zkoczka | dbb88b9 | 2019-10-17 10:34:38 +0200 | [diff] [blame] | 32 | "runtime" |
Balint Uveges | 871fa39 | 2019-04-02 20:31:11 +0000 | [diff] [blame] | 33 | ) |
| 34 | |
| 35 | var ( |
zkoczka | aaf8d39 | 2019-10-02 17:16:06 +0200 | [diff] [blame] | 36 | SupportedRpes = []*EngineConfig{ |
| 37 | { |
kalnagy | 9216265 | 2019-07-02 15:15:49 +0200 | [diff] [blame] | 38 | Name: "rmrpush", |
| 39 | Version: "pubsush", |
| 40 | Protocol: "rmruta", |
| 41 | Instance: NewRmrPush(), |
| 42 | IsAvailable: true, |
Balint Uveges | 871fa39 | 2019-04-02 20:31:11 +0000 | [diff] [blame] | 43 | }, |
| 44 | } |
| 45 | ) |
| 46 | |
zkoczka | aaf8d39 | 2019-10-02 17:16:06 +0200 | [diff] [blame] | 47 | func GetRpe(rpeName string) (Engine, error) { |
Balint Uveges | 871fa39 | 2019-04-02 20:31:11 +0000 | [diff] [blame] | 48 | for _, rpe := range SupportedRpes { |
kalnagy | 9216265 | 2019-07-02 15:15:49 +0200 | [diff] [blame] | 49 | if rpe.Name == rpeName && rpe.IsAvailable { |
| 50 | return rpe.Instance, nil |
Balint Uveges | 871fa39 | 2019-04-02 20:31:11 +0000 | [diff] [blame] | 51 | } |
| 52 | } |
Peter Szilagyi | 16d84d6 | 2019-04-24 14:51:02 +0000 | [diff] [blame] | 53 | return nil, errors.New("SBI:" + rpeName + " is not supported or still not a available") |
Balint Uveges | 871fa39 | 2019-04-02 20:31:11 +0000 | [diff] [blame] | 54 | } |
| 55 | |
kalnagy | 9216265 | 2019-07-02 15:15:49 +0200 | [diff] [blame] | 56 | type Rpe struct { |
| 57 | } |
| 58 | |
kalnagy | 9216265 | 2019-07-02 15:15:49 +0200 | [diff] [blame] | 59 | func getEndpointByName(eps *rtmgr.Endpoints, name string) *rtmgr.Endpoint { |
| 60 | for _, ep := range *eps { |
| 61 | if ep.Name == name { |
| 62 | rtmgr.Logger.Debug("name: %s", ep.Name) |
| 63 | rtmgr.Logger.Debug("ep: %v", ep) |
| 64 | return ep |
| 65 | } |
| 66 | } |
| 67 | return nil |
| 68 | } |
| 69 | |
zkoczka | eb2ff0d | 2019-09-26 16:59:54 +0200 | [diff] [blame] | 70 | func getEndpointByUuid(uuid string) *rtmgr.Endpoint { |
| 71 | endPoints := rtmgr.Eps |
| 72 | for _, ep := range endPoints { |
kalnagy | 9216265 | 2019-07-02 15:15:49 +0200 | [diff] [blame] | 73 | if ep.Uuid == uuid { |
| 74 | rtmgr.Logger.Debug("name: %s", ep.Uuid) |
| 75 | rtmgr.Logger.Debug("ep: %v", ep) |
| 76 | return ep |
| 77 | } |
| 78 | } |
| 79 | return nil |
| 80 | } |
kalnagy | 9216265 | 2019-07-02 15:15:49 +0200 | [diff] [blame] | 81 | |
zkoczka | aaf8d39 | 2019-10-02 17:16:06 +0200 | [diff] [blame] | 82 | func (r *Rpe) addRoute(messageType string, tx *rtmgr.Endpoint, rx *rtmgr.Endpoint, routeTable *rtmgr.RouteTable, subId int32) { |
zkoczka | dbb88b9 | 2019-10-17 10:34:38 +0200 | [diff] [blame] | 83 | if tx != nil && rx != nil { |
| 84 | txList := rtmgr.EndpointList{*tx} |
| 85 | rxList := []rtmgr.EndpointList{[]rtmgr.Endpoint{*rx}} |
| 86 | messageId := rtmgr.MessageTypes[messageType] |
| 87 | route := rtmgr.RouteTableEntry{ |
| 88 | MessageType: messageId, |
| 89 | TxList: txList, |
| 90 | RxGroups: rxList, |
| 91 | SubID: subId} |
| 92 | *routeTable = append(*routeTable, route) |
| 93 | rtmgr.Logger.Debug("Route added: MessageTyp: %v, Tx: %v, Rx: %v, SubId: %v", messageId, tx.Uuid, rx.Uuid, subId) |
| 94 | rtmgr.Logger.Trace("Route added: MessageTyp: %v, Tx: %v, Rx: %v, SubId: %v", messageId, tx, rx, subId) |
| 95 | } else { |
| 96 | pc,_,_,ok := runtime.Caller(1) |
| 97 | details := runtime.FuncForPC(pc) |
| 98 | if ok && details != nil { |
| 99 | rtmgr.Logger.Error("Route addition skipped: Either TX or RX endpoint not present. Caller function is %s", details.Name()) |
| 100 | } |
| 101 | } |
zkoczka | eb2ff0d | 2019-09-26 16:59:54 +0200 | [diff] [blame] | 102 | } |
| 103 | |
zkoczka | aaf8d39 | 2019-10-02 17:16:06 +0200 | [diff] [blame] | 104 | func (r *Rpe) generateXappRoutes(xAppEp *rtmgr.Endpoint, e2TermEp *rtmgr.Endpoint, subManEp *rtmgr.Endpoint, routeTable *rtmgr.RouteTable) { |
zkoczka | eb2ff0d | 2019-09-26 16:59:54 +0200 | [diff] [blame] | 105 | rtmgr.Logger.Debug("rpe.generateXappRoutes invoked") |
zkoczka | aaf8d39 | 2019-10-02 17:16:06 +0200 | [diff] [blame] | 106 | rtmgr.Logger.Debug("Endpoint: %v, xAppType: %v", xAppEp.Name, xAppEp.XAppType) |
| 107 | if xAppEp.XAppType != sbi.PlatformType && len(xAppEp.TxMessages) > 0 && len(xAppEp.RxMessages) > 0 { |
| 108 | //xApp -> Subscription Manager |
| 109 | r.addRoute("RIC_SUB_REQ", xAppEp, subManEp, routeTable, -1) |
| 110 | r.addRoute("RIC_SUB_DEL_REQ", xAppEp, subManEp, routeTable, -1) |
| 111 | //xApp -> E2 Termination |
| 112 | r.addRoute("RIC_CONTROL_REQ", xAppEp, e2TermEp, routeTable, -1) |
zkoczka | b95b076 | 2019-10-29 13:05:48 +0100 | [diff] [blame^] | 113 | //E2 Termination -> xApp |
| 114 | r.addRoute("RIC_CONTROL_ACK", e2TermEp, xAppEp, routeTable, -1) |
| 115 | r.addRoute("RIC_CONTROL_FAILURE", e2TermEp, xAppEp, routeTable, -1) |
zkoczka | eb2ff0d | 2019-09-26 16:59:54 +0200 | [diff] [blame] | 116 | } |
| 117 | } |
| 118 | |
| 119 | func (r *Rpe) generateSubscriptionRoutes(e2TermEp *rtmgr.Endpoint, subManEp *rtmgr.Endpoint, routeTable *rtmgr.RouteTable) { |
| 120 | rtmgr.Logger.Debug("rpe.addSubscriptionRoutes invoked") |
zkoczka | aaf8d39 | 2019-10-02 17:16:06 +0200 | [diff] [blame] | 121 | subscriptionList := &rtmgr.Subs |
| 122 | for _, subscription := range *subscriptionList { |
zkoczka | eb2ff0d | 2019-09-26 16:59:54 +0200 | [diff] [blame] | 123 | rtmgr.Logger.Debug("Subscription: %v", subscription) |
| 124 | xAppUuid := subscription.Fqdn + ":" + strconv.Itoa(int(subscription.Port)) |
| 125 | rtmgr.Logger.Debug("xApp UUID: %v", xAppUuid) |
| 126 | xAppEp := getEndpointByUuid(xAppUuid) |
| 127 | //Subscription Manager -> xApp |
zkoczka | aaf8d39 | 2019-10-02 17:16:06 +0200 | [diff] [blame] | 128 | r.addRoute("RIC_SUB_RESP", subManEp, xAppEp, routeTable, subscription.SubID) |
| 129 | r.addRoute("RIC_SUB_FAILURE", subManEp, xAppEp, routeTable, subscription.SubID) |
| 130 | r.addRoute("RIC_SUB_DEL_RESP", subManEp, xAppEp, routeTable, subscription.SubID) |
| 131 | r.addRoute("RIC_SUB_DEL_FAILURE", subManEp, xAppEp, routeTable, subscription.SubID) |
zkoczka | eb2ff0d | 2019-09-26 16:59:54 +0200 | [diff] [blame] | 132 | //E2 Termination -> xApp |
zkoczka | aaf8d39 | 2019-10-02 17:16:06 +0200 | [diff] [blame] | 133 | r.addRoute("RIC_INDICATION", e2TermEp, xAppEp, routeTable, subscription.SubID) |
| 134 | r.addRoute("RIC_CONTROL_ACK", e2TermEp, xAppEp, routeTable, subscription.SubID) |
| 135 | r.addRoute("RIC_CONTROL_FAILURE", e2TermEp, xAppEp, routeTable, subscription.SubID) |
zkoczka | eb2ff0d | 2019-09-26 16:59:54 +0200 | [diff] [blame] | 136 | } |
| 137 | } |
| 138 | |
| 139 | func (r *Rpe) generatePlatformRoutes(e2TermEp *rtmgr.Endpoint, subManEp *rtmgr.Endpoint, e2ManEp *rtmgr.Endpoint, ueManEp *rtmgr.Endpoint, routeTable *rtmgr.RouteTable) { |
| 140 | rtmgr.Logger.Debug("rpe.generatePlatformRoutes invoked") |
| 141 | //Platform Routes --- Subscription Routes |
| 142 | //Subscription Manager -> E2 Termination |
zkoczka | aaf8d39 | 2019-10-02 17:16:06 +0200 | [diff] [blame] | 143 | r.addRoute("RIC_SUB_REQ", subManEp, e2TermEp, routeTable, -1) |
| 144 | r.addRoute("RIC_SUB_DEL_REQ", subManEp, e2TermEp, routeTable, -1) |
zkoczka | eb2ff0d | 2019-09-26 16:59:54 +0200 | [diff] [blame] | 145 | //E2 Termination -> Subscription Manager |
zkoczka | aaf8d39 | 2019-10-02 17:16:06 +0200 | [diff] [blame] | 146 | r.addRoute("RIC_SUB_RESP", e2TermEp, subManEp, routeTable, -1) |
| 147 | r.addRoute("RIC_SUB_DEL_RESP", e2TermEp, subManEp, routeTable, -1) |
| 148 | r.addRoute("RIC_SUB_FAILURE", e2TermEp, subManEp, routeTable, -1) |
| 149 | r.addRoute("RIC_SUB_DEL_FAILURE", e2TermEp, subManEp, routeTable, -1) |
zkoczka | eb2ff0d | 2019-09-26 16:59:54 +0200 | [diff] [blame] | 150 | //TODO: UE Man Routes removed (since it is not existing) |
| 151 | //UE Manager -> Subscription Manager |
| 152 | //r.addRoute("RIC_SUB_REQ", ueManEp, subManEp, routeTable) |
| 153 | //r.addRoute("RIC_SUB_DEL_REQ", ueManEp, subManEp, routeTable) |
| 154 | ////UE Manager -> E2 Termination |
| 155 | //r.addRoute("RIC_CONTROL_REQ", ueManEp, e2TermEp, routeTable) |
| 156 | |
| 157 | //Platform Routes --- X2 Routes |
| 158 | //E2 Manager -> E2 Termination |
zkoczka | aaf8d39 | 2019-10-02 17:16:06 +0200 | [diff] [blame] | 159 | r.addRoute("RIC_X2_SETUP_REQ", e2ManEp, e2TermEp, routeTable, -1) |
zkoczka | b95b076 | 2019-10-29 13:05:48 +0100 | [diff] [blame^] | 160 | r.addRoute("RIC_X2_RESET_REQ", e2ManEp, e2TermEp, routeTable, -1) |
zkoczka | aaf8d39 | 2019-10-02 17:16:06 +0200 | [diff] [blame] | 161 | r.addRoute("RIC_X2_RESET_RESP", e2ManEp, e2TermEp, routeTable, -1) |
| 162 | r.addRoute("RIC_ENDC_X2_SETUP_REQ", e2ManEp, e2TermEp, routeTable, -1) |
zkoczka | 4d0e07a | 2019-10-15 15:05:57 +0200 | [diff] [blame] | 163 | r.addRoute("RIC_SCTP_CLEAR_ALL", e2ManEp, e2TermEp, routeTable, -1) |
zkoczka | b95b076 | 2019-10-29 13:05:48 +0100 | [diff] [blame^] | 164 | r.addRoute("RIC_ENB_CONF_UPDATE_ACK", e2ManEp, e2TermEp, routeTable, -1) |
| 165 | r.addRoute("RIC_ENB_CONF_UPDATE_FAILURE", e2ManEp, e2TermEp, routeTable, -1) |
| 166 | r.addRoute("RIC_ENDC_CONF_UPDATE_ACK", e2ManEp, e2TermEp, routeTable, -1) |
| 167 | r.addRoute("RIC_ENDC_CONF_UPDATE_FAILURE", e2ManEp, e2TermEp, routeTable, -1) |
zkoczka | eb2ff0d | 2019-09-26 16:59:54 +0200 | [diff] [blame] | 168 | //E2 Termination -> E2 Manager |
zkoczka | 4d0e07a | 2019-10-15 15:05:57 +0200 | [diff] [blame] | 169 | r.addRoute("E2_TERM_INIT", e2TermEp, e2ManEp, routeTable, -1) |
zkoczka | aaf8d39 | 2019-10-02 17:16:06 +0200 | [diff] [blame] | 170 | r.addRoute("RIC_X2_SETUP_RESP", e2TermEp, e2ManEp, routeTable, -1) |
zkoczka | b95b076 | 2019-10-29 13:05:48 +0100 | [diff] [blame^] | 171 | r.addRoute("RIC_X2_SETUP_FAILURE", e2ManEp, e2TermEp, routeTable, -1) |
| 172 | r.addRoute("RIC_X2_RESET_REQ", e2TermEp, e2ManEp, routeTable, -1) |
zkoczka | aaf8d39 | 2019-10-02 17:16:06 +0200 | [diff] [blame] | 173 | r.addRoute("RIC_X2_RESET_RESP", e2TermEp, e2ManEp, routeTable, -1) |
zkoczka | 988d1da | 2019-10-29 11:09:26 +0100 | [diff] [blame] | 174 | r.addRoute("RIC_ENDC_X2_SETUP_RESP", e2TermEp, e2ManEp, routeTable, -1) |
| 175 | r.addRoute("RIC_ENDC_X2_SETUP_FAILURE", e2TermEp, e2ManEp, routeTable, -1) |
zkoczka | b95b076 | 2019-10-29 13:05:48 +0100 | [diff] [blame^] | 176 | r.addRoute("RIC_ENDC_CONF_UPDATE", e2TermEp, e2ManEp, routeTable, -1) |
zkoczka | 4d0e07a | 2019-10-15 15:05:57 +0200 | [diff] [blame] | 177 | r.addRoute("RIC_SCTP_CONNECTION_FAILURE", e2TermEp, e2ManEp, routeTable, -1) |
zkoczka | b95b076 | 2019-10-29 13:05:48 +0100 | [diff] [blame^] | 178 | r.addRoute("RIC_ERROR_INDICATION", e2TermEp, e2ManEp, routeTable, -1) |
| 179 | r.addRoute("RIC_ENB_CONF_UPDATE", e2TermEp, e2ManEp, routeTable, -1) |
| 180 | r.addRoute("RIC_ENB_LOAD_INFORMATION", e2TermEp, e2ManEp, routeTable, -1) |
zkoczka | eb2ff0d | 2019-09-26 16:59:54 +0200 | [diff] [blame] | 181 | } |
| 182 | |
| 183 | func (r *Rpe) generateRouteTable(endPointList rtmgr.Endpoints) *rtmgr.RouteTable { |
| 184 | rtmgr.Logger.Debug("rpe.generateRouteTable invoked") |
| 185 | rtmgr.Logger.Debug("Endpoint List: %v", endPointList) |
| 186 | routeTable := &rtmgr.RouteTable{} |
| 187 | e2TermEp := getEndpointByName(&endPointList, "E2TERM") |
| 188 | if e2TermEp == nil { |
| 189 | rtmgr.Logger.Error("Platform component not found: %v", "E2 Termination") |
| 190 | rtmgr.Logger.Debug("Endpoints: %v", endPointList) |
| 191 | } |
| 192 | subManEp := getEndpointByName(&endPointList, "SUBMAN") |
| 193 | if subManEp == nil { |
| 194 | rtmgr.Logger.Error("Platform component not found: %v", "Subscription Manager") |
| 195 | rtmgr.Logger.Debug("Endpoints: %v", endPointList) |
| 196 | } |
| 197 | e2ManEp := getEndpointByName(&endPointList, "E2MAN") |
| 198 | if e2ManEp == nil { |
| 199 | rtmgr.Logger.Error("Platform component not found: %v", "E2 Manager") |
| 200 | rtmgr.Logger.Debug("Endpoints: %v", endPointList) |
| 201 | } |
| 202 | ueManEp := getEndpointByName(&endPointList, "UEMAN") |
| 203 | if ueManEp == nil { |
| 204 | rtmgr.Logger.Error("Platform component not found: %v", "UE Manger") |
| 205 | rtmgr.Logger.Debug("Endpoints: %v", endPointList) |
| 206 | } |
| 207 | r.generatePlatformRoutes(e2TermEp, subManEp, e2ManEp, ueManEp, routeTable) |
| 208 | |
| 209 | for _, endPoint := range endPointList { |
| 210 | rtmgr.Logger.Debug("Endpoint: %v, xAppType: %v", endPoint.Name, endPoint.XAppType) |
zkoczka | aaf8d39 | 2019-10-02 17:16:06 +0200 | [diff] [blame] | 211 | if endPoint.XAppType != sbi.PlatformType && len(endPoint.TxMessages) > 0 && len(endPoint.RxMessages) > 0 { |
| 212 | r.generateXappRoutes(endPoint, e2TermEp, subManEp, routeTable) |
zkoczka | eb2ff0d | 2019-09-26 16:59:54 +0200 | [diff] [blame] | 213 | r.generateSubscriptionRoutes(e2TermEp, subManEp, routeTable) |
| 214 | } |
| 215 | } |
| 216 | return routeTable |
kalnagy | 9216265 | 2019-07-02 15:15:49 +0200 | [diff] [blame] | 217 | } |