blob: 4097ae0dc803ba17b987aa0f367857e9b7a40d64 [file] [log] [blame]
Balint Uveges871fa392019-04-02 20:31:11 +00001/*
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.
wahidw761934a2019-11-27 06:07:26 +000017
18
19 This source code is part of the near-RT RIC (RAN Intelligent Controller)
20 platform project (RICP).
21
Balint Uveges871fa392019-04-02 20:31:11 +000022==================================================================================
23*/
24/*
25 Mnemonic: rpe.go
26 Abstract: Contains RPE (Route Policy Engine) module definitions and generic RPE components
27 Date: 16 March 2019
28*/
29
30package rpe
31
32import (
33 "errors"
wahidwa8596ec2019-12-05 06:30:42 +000034 "gerrit.o-ran-sc.org/r/ric-plt/xapp-frame/pkg/xapp"
kalnagy92162652019-07-02 15:15:49 +020035 "routing-manager/pkg/rtmgr"
zkoczkaeb2ff0d2019-09-26 16:59:54 +020036 "routing-manager/pkg/sbi"
prabhukaliswamyb47d12d2019-12-03 15:06:30 +000037 "runtime"
wahidwa8596ec2019-12-05 06:30:42 +000038 "strconv"
Balint Uveges871fa392019-04-02 20:31:11 +000039)
40
41var (
zkoczkaaaf8d392019-10-02 17:16:06 +020042 SupportedRpes = []*EngineConfig{
43 {
kalnagy92162652019-07-02 15:15:49 +020044 Name: "rmrpush",
45 Version: "pubsush",
46 Protocol: "rmruta",
47 Instance: NewRmrPush(),
48 IsAvailable: true,
Balint Uveges871fa392019-04-02 20:31:11 +000049 },
50 }
51)
52
zkoczkaaaf8d392019-10-02 17:16:06 +020053func GetRpe(rpeName string) (Engine, error) {
Balint Uveges871fa392019-04-02 20:31:11 +000054 for _, rpe := range SupportedRpes {
kalnagy92162652019-07-02 15:15:49 +020055 if rpe.Name == rpeName && rpe.IsAvailable {
56 return rpe.Instance, nil
Balint Uveges871fa392019-04-02 20:31:11 +000057 }
58 }
Peter Szilagyi16d84d62019-04-24 14:51:02 +000059 return nil, errors.New("SBI:" + rpeName + " is not supported or still not a available")
Balint Uveges871fa392019-04-02 20:31:11 +000060}
61
kalnagy92162652019-07-02 15:15:49 +020062type Rpe struct {
63}
64
kalnagy92162652019-07-02 15:15:49 +020065func getEndpointByName(eps *rtmgr.Endpoints, name string) *rtmgr.Endpoint {
66 for _, ep := range *eps {
67 if ep.Name == name {
wahidwa8596ec2019-12-05 06:30:42 +000068 xapp.Logger.Debug("name: %s", ep.Name)
69 xapp.Logger.Debug("ep: %v", ep)
kalnagy92162652019-07-02 15:15:49 +020070 return ep
71 }
72 }
73 return nil
74}
75
rangajal749099b2019-12-10 09:37:08 +000076func getEndpointListByName(eps *rtmgr.Endpoints, name string) []rtmgr.Endpoint {
wahidwda0fd3a2020-01-01 04:28:41 +000077 var eplist []rtmgr.Endpoint
rangajal749099b2019-12-10 09:37:08 +000078
wahidwda0fd3a2020-01-01 04:28:41 +000079 for _, ep := range *eps {
80 if ep.Name == name {
81 xapp.Logger.Debug("name: %s", ep.Name)
82 xapp.Logger.Debug("ep: %v", ep)
83 eplist = append(eplist, *ep)
84 }
85 }
86 return eplist
rangajal749099b2019-12-10 09:37:08 +000087}
88
zkoczkaeb2ff0d2019-09-26 16:59:54 +020089func getEndpointByUuid(uuid string) *rtmgr.Endpoint {
90 endPoints := rtmgr.Eps
91 for _, ep := range endPoints {
kalnagy92162652019-07-02 15:15:49 +020092 if ep.Uuid == uuid {
wahidwa8596ec2019-12-05 06:30:42 +000093 xapp.Logger.Debug("name: %s", ep.Uuid)
94 xapp.Logger.Debug("ep: %v", ep)
kalnagy92162652019-07-02 15:15:49 +020095 return ep
96 }
97 }
98 return nil
99}
kalnagy92162652019-07-02 15:15:49 +0200100
rangajal749099b2019-12-10 09:37:08 +0000101func (r *Rpe) addRoute(messageType string, tx *rtmgr.Endpoint, rx *rtmgr.Endpoint, routeTable *rtmgr.RouteTable, subId int32, routeType string) {
102 txList := rtmgr.EndpointList{}
103 rxList := []rtmgr.EndpointList{}
104
105 if tx == nil && rx == nil {
wahidwda0fd3a2020-01-01 04:28:41 +0000106 pc, _, _, ok := runtime.Caller(1)
107 details := runtime.FuncForPC(pc)
108 if ok && details != nil {
109 xapp.Logger.Error("Route addition skipped: Either TX or RX endpoint not present. Caller function is %s", details.Name())
wahidwa8596ec2019-12-05 06:30:42 +0000110 }
wahidwa8596ec2019-12-05 06:30:42 +0000111 } else {
wahidwda0fd3a2020-01-01 04:28:41 +0000112 if tx != nil {
113 txList = rtmgr.EndpointList{*tx}
114 }
115 if rx != nil {
116 rxList = []rtmgr.EndpointList{[]rtmgr.Endpoint{*rx}}
117 }
wahidwbce67472020-06-15 13:52:55 +0000118 //messageId := strconv.Itoa(xapp.RICMessageTypes[messageType])
119 messageId := rtmgr.Mtype[messageType]
wahidwda0fd3a2020-01-01 04:28:41 +0000120 route := rtmgr.RouteTableEntry{
121 MessageType: messageId,
122 TxList: txList,
123 RxGroups: rxList,
124 SubID: subId,
125 RouteType: routeType}
126 *routeTable = append(*routeTable, route)
127 // xapp.Logger.Debug("Route added: MessageTyp: %v, Tx: %v, Rx: %v, SubId: %v", messageId, tx.Uuid, rx.Uuid, subId)
128 // xapp.Logger.Trace("Route added: MessageTyp: %v, Tx: %v, Rx: %v, SubId: %v", messageId, tx, rx, subId)
wahidwa8596ec2019-12-05 06:30:42 +0000129 }
zkoczkaeb2ff0d2019-09-26 16:59:54 +0200130}
131
rangajal749099b2019-12-10 09:37:08 +0000132func (r *Rpe) addRoute_rx_list(messageType string, tx *rtmgr.Endpoint, rx []rtmgr.Endpoint, routeTable *rtmgr.RouteTable, subId int32, routeType string) {
133 txList := rtmgr.EndpointList{}
134 rxList := []rtmgr.EndpointList{}
135
wahidwda0fd3a2020-01-01 04:28:41 +0000136 if tx != nil {
137 txList = rtmgr.EndpointList{*tx}
rangajal749099b2019-12-10 09:37:08 +0000138 }
139
wahidwda0fd3a2020-01-01 04:28:41 +0000140 if rx != nil {
wahidw6977ffd2020-02-08 19:00:02 +0000141 for _, item := range rx {
142 ep := []rtmgr.Endpoint{item}
143 rxList = append(rxList, ep)
144 }
rangajal749099b2019-12-10 09:37:08 +0000145 }
146
wahidwbce67472020-06-15 13:52:55 +0000147 //messageId := strconv.Itoa(xapp.RICMessageTypes[messageType])
148 messageId := rtmgr.Mtype[messageType]
rangajal749099b2019-12-10 09:37:08 +0000149 route := rtmgr.RouteTableEntry{
wahidwda0fd3a2020-01-01 04:28:41 +0000150 MessageType: messageId,
151 TxList: txList,
152 RxGroups: rxList,
153 SubID: subId,
154 RouteType: routeType}
rangajal749099b2019-12-10 09:37:08 +0000155 *routeTable = append(*routeTable, route)
wahidwda0fd3a2020-01-01 04:28:41 +0000156 // xapp.Logger.Debug("Route added: MessageTyp: %v, Tx: %v, Rx: %v, SubId: %v", messageId, tx.Uuid, rx.Uuid, subId)
157 // xapp.Logger.Trace("Route added: MessageTyp: %v, Tx: %v, Rx: %v, SubId: %v", messageId, tx, rx, subId)
rangajal749099b2019-12-10 09:37:08 +0000158}
159
wahidwcd7867c2020-02-05 10:01:12 +0000160func (r *Rpe) generateXappRoutes(xAppEp *rtmgr.Endpoint, subManEp *rtmgr.Endpoint, routeTable *rtmgr.RouteTable) {
wahidwa8596ec2019-12-05 06:30:42 +0000161 xapp.Logger.Debug("rpe.generateXappRoutes invoked")
162 xapp.Logger.Debug("Endpoint: %v, xAppType: %v", xAppEp.Name, xAppEp.XAppType)
163 if xAppEp.XAppType != sbi.PlatformType && (len(xAppEp.TxMessages) > 0 || len(xAppEp.RxMessages) > 0) {
wahidwda0fd3a2020-01-01 04:28:41 +0000164 /// TODO ---
zkoczkaaaf8d392019-10-02 17:16:06 +0200165 //xApp -> Subscription Manager
rangajal749099b2019-12-10 09:37:08 +0000166 r.addRoute("RIC_SUB_REQ", xAppEp, subManEp, routeTable, -1, "")
167 r.addRoute("RIC_SUB_DEL_REQ", xAppEp, subManEp, routeTable, -1, "")
zkoczkaaaf8d392019-10-02 17:16:06 +0200168 //xApp -> E2 Termination
wahidwda0fd3a2020-01-01 04:28:41 +0000169 // r.addRoute("RIC_CONTROL_REQ", xAppEp, e2TermEp, routeTable, -1, "")
prabhukaliswamye110ee02019-12-23 09:51:01 +0000170 r.addRoute("RIC_CONTROL_REQ", xAppEp, nil, routeTable, -1, "%meid")
zkoczkab95b0762019-10-29 13:05:48 +0100171 //E2 Termination -> xApp
wahidwda0fd3a2020-01-01 04:28:41 +0000172 /// r.addRoute("RIC_CONTROL_ACK", e2TermEp, xAppEp, routeTable, -1, "")
173 /// r.addRoute("RIC_CONTROL_FAILURE", e2TermEp, xAppEp, routeTable, -1, "")
prabhukaliswamye110ee02019-12-23 09:51:01 +0000174 r.addRoute("RIC_CONTROL_ACK", nil, xAppEp, routeTable, -1, "")
175 r.addRoute("RIC_CONTROL_FAILURE", nil, xAppEp, routeTable, -1, "")
zkoczkaeb2ff0d2019-09-26 16:59:54 +0200176 }
wahidwa8596ec2019-12-05 06:30:42 +0000177 //xApp->A1Mediator
178 if xAppEp.XAppType != sbi.PlatformType && len(xAppEp.Policies) > 0 {
179 xapp.Logger.Debug("rpe.generateXappRoutes found policies section")
180 for _, policy := range xAppEp.Policies {
rangajal749099b2019-12-10 09:37:08 +0000181 r.addRoute("A1_POLICY_REQ", nil, xAppEp, routeTable, policy, "")
wahidwa8596ec2019-12-05 06:30:42 +0000182 }
183 }
184
zkoczkaeb2ff0d2019-09-26 16:59:54 +0200185}
186
rangajal0baa70d2020-03-31 12:28:53 +0000187
188func (r *Rpe) generateXappToXappRoutes(RecvxAppEp *rtmgr.Endpoint, endPointList rtmgr.Endpoints, routeTable *rtmgr.RouteTable) {
189 xapp.Logger.Debug("rpe.generateXappToXappRoutes invoked")
190
191 for _, rxmsg := range RecvxAppEp.RxMessages {
192
193 var src_present bool
194 xapp.Logger.Debug("RecvxAppEp.RxMessages Endpoint: %v, xAppType: %v and rxmsg: %v ", RecvxAppEp.Name, RecvxAppEp.XAppType, rxmsg)
195 if (rxmsg != "RIC_SUB_RESP" && rxmsg != "RIC_SUB_FAILURE" && rxmsg != "RIC_SUB_DEL_RESP" && rxmsg != "RIC_SUB_DEL_FAILURE" && rxmsg != "RIC_INDICATION" && rxmsg != "RIC_CONTROL_ACK" && rxmsg != "RIC_CONTROL_FAILURE" && rxmsg != "A1_POLICY_REQ") {
196 for _, SrcxAppEp := range endPointList {
197 if SrcxAppEp.XAppType != sbi.PlatformType && (len(SrcxAppEp.TxMessages) > 0) && SrcxAppEp.Name != RecvxAppEp.Name {
198 for _, txmsg := range SrcxAppEp.TxMessages {
199 if (rxmsg == txmsg) {
200 r.addRoute(rxmsg, SrcxAppEp, RecvxAppEp, routeTable, -1, "")
201 src_present = true
202 break
203 }
204 }
205 }
206 }
207 if src_present == false {
208 r.addRoute(rxmsg, nil, RecvxAppEp, routeTable, -1, "")
209 }
210 }
211
212 }
213}
214
wahidwcd7867c2020-02-05 10:01:12 +0000215func (r *Rpe) generateSubscriptionRoutes(selectedxAppEp *rtmgr.Endpoint, subManEp *rtmgr.Endpoint, routeTable *rtmgr.RouteTable) {
wahidwa8596ec2019-12-05 06:30:42 +0000216 xapp.Logger.Debug("rpe.addSubscriptionRoutes invoked")
zkoczkaaaf8d392019-10-02 17:16:06 +0200217 subscriptionList := &rtmgr.Subs
218 for _, subscription := range *subscriptionList {
wahidwa8596ec2019-12-05 06:30:42 +0000219 xapp.Logger.Debug("Subscription: %v", subscription)
zkoczkaeb2ff0d2019-09-26 16:59:54 +0200220 xAppUuid := subscription.Fqdn + ":" + strconv.Itoa(int(subscription.Port))
wahidwa8596ec2019-12-05 06:30:42 +0000221 xapp.Logger.Debug("xApp UUID: %v", xAppUuid)
zkoczkaeb2ff0d2019-09-26 16:59:54 +0200222 xAppEp := getEndpointByUuid(xAppUuid)
rangajald14518e2020-04-21 12:33:37 +0000223 if xAppEp != nil {
224 if xAppEp.Uuid == selectedxAppEp.Uuid {
225 xapp.Logger.Debug("xApp UUID is matched for selected xApp.UUID: %v and xApp.Name: %v", selectedxAppEp.Uuid, selectedxAppEp.Name)
226 /// TODO
227 //Subscription Manager -> xApp
228 r.addRoute("RIC_SUB_RESP", subManEp, xAppEp, routeTable, subscription.SubID, "")
229 r.addRoute("RIC_SUB_FAILURE", subManEp, xAppEp, routeTable, subscription.SubID, "")
230 r.addRoute("RIC_SUB_DEL_RESP", subManEp, xAppEp, routeTable, subscription.SubID, "")
231 r.addRoute("RIC_SUB_DEL_FAILURE", subManEp, xAppEp, routeTable, subscription.SubID, "")
232 //E2 Termination -> xApp
233 r.addRoute("RIC_INDICATION", nil, xAppEp, routeTable, subscription.SubID, "")
234 r.addRoute("RIC_CONTROL_ACK", nil, xAppEp, routeTable, subscription.SubID, "")
235 r.addRoute("RIC_CONTROL_FAILURE", nil, xAppEp, routeTable, subscription.SubID, "")
236 }
237 } else {
238 xapp.Logger.Error("generateSubscriptionRoutes xAppEp is nil, xApp UUID: %v", xAppUuid)
prabhukaliswamyb47d12d2019-12-03 15:06:30 +0000239 }
zkoczkaeb2ff0d2019-09-26 16:59:54 +0200240 }
241}
242
wahidwcd7867c2020-02-05 10:01:12 +0000243func (r *Rpe) generatePlatformRoutes(e2TermEp []rtmgr.Endpoint, subManEp *rtmgr.Endpoint, e2ManEp *rtmgr.Endpoint, rsmEp *rtmgr.Endpoint, a1mediatorEp *rtmgr.Endpoint, routeTable *rtmgr.RouteTable) {
wahidwa8596ec2019-12-05 06:30:42 +0000244 xapp.Logger.Debug("rpe.generatePlatformRoutes invoked")
zkoczkaeb2ff0d2019-09-26 16:59:54 +0200245 //Platform Routes --- Subscription Routes
246 //Subscription Manager -> E2 Termination
wahidw8f7ca652020-07-08 18:59:53 +0530247 if rtmgr.PrsCfg == nil {
248 xapp.Logger.Info("No static routes configuration")
249 return
250 }
wahidwda0fd3a2020-01-01 04:28:41 +0000251 for _, routes := range *rtmgr.PrsCfg {
252 var sendEp *rtmgr.Endpoint
253 var Ep *rtmgr.Endpoint
254 switch routes.SenderEndPoint {
255 case "SUBMAN":
256 sendEp = subManEp
257 case "E2MAN":
258 sendEp = e2ManEp
wahidwda0fd3a2020-01-01 04:28:41 +0000259 case "RSM":
260 sendEp = rsmEp
261 case "A1MEDIATOR":
262 sendEp = a1mediatorEp
263 }
264 switch routes.EndPoint {
265 case "SUBMAN":
266 Ep = subManEp
267 case "E2MAN":
268 Ep = e2ManEp
wahidwcd7867c2020-02-05 10:01:12 +0000269 //case "UEMAN":
270 // Ep = ueManEp
wahidwda0fd3a2020-01-01 04:28:41 +0000271 case "RSM":
272 Ep = rsmEp
273 case "A1MEDIATOR":
274 Ep = a1mediatorEp
275 }
rangajal6d209042020-01-08 12:18:39 +0000276
wahidwda0fd3a2020-01-01 04:28:41 +0000277 r.addRoute(routes.MessageType, sendEp, Ep, routeTable, routes.SubscriptionId, routes.Meid)
278 }
rangajal6d209042020-01-08 12:18:39 +0000279
280 if len(e2TermEp) > 0 {
281 r.addRoute_rx_list("RIC_SCTP_CLEAR_ALL", e2ManEp, e2TermEp, routeTable, -1, "")
282 r.addRoute_rx_list("E2_TERM_KEEP_ALIVE_REQ", e2ManEp, e2TermEp, routeTable, -1, "")
wahidwdd6b0562020-03-31 03:09:45 +0000283 r.addRoute_rx_list("RIC_E2_SETUP_RESP", e2ManEp, e2TermEp, routeTable, -1, "")
284 r.addRoute_rx_list("RIC_E2_SETUP_FAILURE", e2ManEp, e2TermEp, routeTable, -1, "")
rangajal6d209042020-01-08 12:18:39 +0000285 }
zkoczkaeb2ff0d2019-09-26 16:59:54 +0200286}
287
288func (r *Rpe) generateRouteTable(endPointList rtmgr.Endpoints) *rtmgr.RouteTable {
wahidwa8596ec2019-12-05 06:30:42 +0000289 xapp.Logger.Debug("rpe.generateRouteTable invoked")
290 xapp.Logger.Debug("Endpoint List: %v", endPointList)
zkoczkaeb2ff0d2019-09-26 16:59:54 +0200291 routeTable := &rtmgr.RouteTable{}
wahidwcd7867c2020-02-05 10:01:12 +0000292 /*e2TermEp := getEndpointByName(&endPointList, "E2TERM")
zkoczkaeb2ff0d2019-09-26 16:59:54 +0200293 if e2TermEp == nil {
wahidwa8596ec2019-12-05 06:30:42 +0000294 xapp.Logger.Error("Platform component not found: %v", "E2 Termination")
295 xapp.Logger.Debug("Endpoints: %v", endPointList)
wahidwcd7867c2020-02-05 10:01:12 +0000296 }*/
zkoczkaeb2ff0d2019-09-26 16:59:54 +0200297 subManEp := getEndpointByName(&endPointList, "SUBMAN")
298 if subManEp == nil {
wahidwa8596ec2019-12-05 06:30:42 +0000299 xapp.Logger.Error("Platform component not found: %v", "Subscription Manager")
300 xapp.Logger.Debug("Endpoints: %v", endPointList)
zkoczkaeb2ff0d2019-09-26 16:59:54 +0200301 }
302 e2ManEp := getEndpointByName(&endPointList, "E2MAN")
303 if e2ManEp == nil {
wahidwa8596ec2019-12-05 06:30:42 +0000304 xapp.Logger.Error("Platform component not found: %v", "E2 Manager")
305 xapp.Logger.Debug("Endpoints: %v", endPointList)
zkoczkaeb2ff0d2019-09-26 16:59:54 +0200306 }
prabhukaliswamybe9f2682019-11-22 07:24:09 +0000307 rsmEp := getEndpointByName(&endPointList, "RSM")
308 if rsmEp == nil {
wahidwa8596ec2019-12-05 06:30:42 +0000309 xapp.Logger.Error("Platform component not found: %v", "Resource Status Manager")
310 xapp.Logger.Debug("Endpoints: %v", endPointList)
prabhukaliswamybe9f2682019-11-22 07:24:09 +0000311 }
wahidwa8596ec2019-12-05 06:30:42 +0000312 A1MediatorEp := getEndpointByName(&endPointList, "A1MEDIATOR")
313 if A1MediatorEp == nil {
314 xapp.Logger.Error("Platform component not found: %v", "A1Mediator")
315 xapp.Logger.Debug("Endpoints: %v", endPointList)
316 }
317
rangajal749099b2019-12-10 09:37:08 +0000318 e2TermListEp := getEndpointListByName(&endPointList, "E2TERMINST")
319 if len(e2TermListEp) == 0 {
320 xapp.Logger.Error("Platform component not found: %v", "E2 Termination List")
321 xapp.Logger.Debug("Endpoints: %v", endPointList)
322 }
wahidwcd7867c2020-02-05 10:01:12 +0000323 r.generatePlatformRoutes(e2TermListEp, subManEp, e2ManEp, rsmEp, A1MediatorEp, routeTable)
zkoczkaeb2ff0d2019-09-26 16:59:54 +0200324
325 for _, endPoint := range endPointList {
wahidwa8596ec2019-12-05 06:30:42 +0000326 xapp.Logger.Debug("Endpoint: %v, xAppType: %v", endPoint.Name, endPoint.XAppType)
327 if endPoint.XAppType != sbi.PlatformType && (len(endPoint.TxMessages) > 0 || len(endPoint.RxMessages) > 0) {
wahidwcd7867c2020-02-05 10:01:12 +0000328 r.generateXappRoutes(endPoint, subManEp, routeTable)
329 r.generateSubscriptionRoutes(endPoint, subManEp, routeTable)
rangajal0baa70d2020-03-31 12:28:53 +0000330 r.generateXappToXappRoutes(endPoint, endPointList, routeTable)
331
zkoczkaeb2ff0d2019-09-26 16:59:54 +0200332 }
333 }
334 return routeTable
kalnagy92162652019-07-02 15:15:49 +0200335}