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.
19 This source code is part of the near-RT RIC (RAN Intelligent Controller)
20 platform project (RICP).
22 ==================================================================================
26 Abstract: Contains RPE (Route Policy Engine) module definitions and generic RPE components
34 "gerrit.o-ran-sc.org/r/ric-plt/xapp-frame/pkg/xapp"
35 "routing-manager/pkg/rtmgr"
36 "routing-manager/pkg/sbi"
42 SupportedRpes = []*EngineConfig{
47 Instance: NewRmrPush(),
53 func GetRpe(rpeName string) (Engine, error) {
54 for _, rpe := range SupportedRpes {
55 if rpe.Name == rpeName && rpe.IsAvailable {
56 return rpe.Instance, nil
59 return nil, errors.New("SBI:" + rpeName + " is not supported or still not a available")
65 func getEndpointByName(eps *rtmgr.Endpoints, name string) *rtmgr.Endpoint {
66 for _, ep := range *eps {
68 xapp.Logger.Debug("name: %s", ep.Name)
69 xapp.Logger.Debug("ep: %v", ep)
76 func getEndpointListByName(eps *rtmgr.Endpoints, name string) []rtmgr.Endpoint {
77 var eplist []rtmgr.Endpoint
79 for _, ep := range *eps {
81 xapp.Logger.Debug("name: %s", ep.Name)
82 xapp.Logger.Debug("ep: %v", ep)
83 eplist = append(eplist, *ep)
89 func getEndpointByUuid(uuid string) *rtmgr.Endpoint {
90 endPoints := rtmgr.Eps
91 for _, ep := range endPoints {
93 xapp.Logger.Debug("name: %s", ep.Uuid)
94 xapp.Logger.Debug("ep: %v", ep)
101 func (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{}
105 if tx == nil && rx == nil {
106 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())
113 txList = rtmgr.EndpointList{*tx}
116 rxList = []rtmgr.EndpointList{[]rtmgr.Endpoint{*rx}}
118 messageId := strconv.Itoa(xapp.RICMessageTypes[messageType])
119 route := rtmgr.RouteTableEntry{
120 MessageType: messageId,
124 RouteType: routeType}
125 *routeTable = append(*routeTable, route)
126 // xapp.Logger.Debug("Route added: MessageTyp: %v, Tx: %v, Rx: %v, SubId: %v", messageId, tx.Uuid, rx.Uuid, subId)
127 // xapp.Logger.Trace("Route added: MessageTyp: %v, Tx: %v, Rx: %v, SubId: %v", messageId, tx, rx, subId)
131 func (r *Rpe) addRoute_rx_list(messageType string, tx *rtmgr.Endpoint, rx []rtmgr.Endpoint, routeTable *rtmgr.RouteTable, subId int32, routeType string) {
132 txList := rtmgr.EndpointList{}
133 rxList := []rtmgr.EndpointList{}
136 txList = rtmgr.EndpointList{*tx}
140 rxList = []rtmgr.EndpointList{rx}
143 messageId := strconv.Itoa(xapp.RICMessageTypes[messageType])
144 route := rtmgr.RouteTableEntry{
145 MessageType: messageId,
149 RouteType: routeType}
150 *routeTable = append(*routeTable, route)
151 // xapp.Logger.Debug("Route added: MessageTyp: %v, Tx: %v, Rx: %v, SubId: %v", messageId, tx.Uuid, rx.Uuid, subId)
152 // xapp.Logger.Trace("Route added: MessageTyp: %v, Tx: %v, Rx: %v, SubId: %v", messageId, tx, rx, subId)
155 func (r *Rpe) generateXappRoutes(xAppEp *rtmgr.Endpoint, e2TermEp *rtmgr.Endpoint, subManEp *rtmgr.Endpoint, routeTable *rtmgr.RouteTable) {
156 xapp.Logger.Debug("rpe.generateXappRoutes invoked")
157 xapp.Logger.Debug("Endpoint: %v, xAppType: %v", xAppEp.Name, xAppEp.XAppType)
158 if xAppEp.XAppType != sbi.PlatformType && (len(xAppEp.TxMessages) > 0 || len(xAppEp.RxMessages) > 0) {
160 //xApp -> Subscription Manager
161 r.addRoute("RIC_SUB_REQ", xAppEp, subManEp, routeTable, -1, "")
162 r.addRoute("RIC_SUB_DEL_REQ", xAppEp, subManEp, routeTable, -1, "")
163 //xApp -> E2 Termination
164 // r.addRoute("RIC_CONTROL_REQ", xAppEp, e2TermEp, routeTable, -1, "")
165 r.addRoute("RIC_CONTROL_REQ", xAppEp, nil, routeTable, -1, "%meid")
166 //E2 Termination -> xApp
167 /// r.addRoute("RIC_CONTROL_ACK", e2TermEp, xAppEp, routeTable, -1, "")
168 /// r.addRoute("RIC_CONTROL_FAILURE", e2TermEp, xAppEp, routeTable, -1, "")
169 r.addRoute("RIC_CONTROL_ACK", nil, xAppEp, routeTable, -1, "")
170 r.addRoute("RIC_CONTROL_FAILURE", nil, xAppEp, routeTable, -1, "")
173 if xAppEp.XAppType != sbi.PlatformType && len(xAppEp.Policies) > 0 {
174 xapp.Logger.Debug("rpe.generateXappRoutes found policies section")
175 for _, policy := range xAppEp.Policies {
176 r.addRoute("A1_POLICY_REQ", nil, xAppEp, routeTable, policy, "")
182 func (r *Rpe) generateSubscriptionRoutes(selectedxAppEp *rtmgr.Endpoint, e2TermEp *rtmgr.Endpoint, subManEp *rtmgr.Endpoint, routeTable *rtmgr.RouteTable) {
183 xapp.Logger.Debug("rpe.addSubscriptionRoutes invoked")
184 subscriptionList := &rtmgr.Subs
185 for _, subscription := range *subscriptionList {
186 xapp.Logger.Debug("Subscription: %v", subscription)
187 xAppUuid := subscription.Fqdn + ":" + strconv.Itoa(int(subscription.Port))
188 xapp.Logger.Debug("xApp UUID: %v", xAppUuid)
189 xAppEp := getEndpointByUuid(xAppUuid)
190 if xAppEp.Uuid == selectedxAppEp.Uuid {
191 xapp.Logger.Debug("xApp UUID is matched for selected xApp.UUID: %v and xApp.Name: %v", selectedxAppEp.Uuid, selectedxAppEp.Name)
193 //Subscription Manager -> xApp
194 r.addRoute("RIC_SUB_RESP", subManEp, xAppEp, routeTable, subscription.SubID, "")
195 r.addRoute("RIC_SUB_FAILURE", subManEp, xAppEp, routeTable, subscription.SubID, "")
196 r.addRoute("RIC_SUB_DEL_RESP", subManEp, xAppEp, routeTable, subscription.SubID, "")
197 r.addRoute("RIC_SUB_DEL_FAILURE", subManEp, xAppEp, routeTable, subscription.SubID, "")
198 //E2 Termination -> xApp
199 r.addRoute("RIC_INDICATION", e2TermEp, xAppEp, routeTable, subscription.SubID, "")
200 r.addRoute("RIC_CONTROL_ACK", e2TermEp, xAppEp, routeTable, subscription.SubID, "")
201 r.addRoute("RIC_CONTROL_FAILURE", e2TermEp, xAppEp, routeTable, subscription.SubID, "")
206 func (r *Rpe) generatePlatformRoutes(e2TermEp []rtmgr.Endpoint, subManEp *rtmgr.Endpoint, e2ManEp *rtmgr.Endpoint, ueManEp *rtmgr.Endpoint, rsmEp *rtmgr.Endpoint, a1mediatorEp *rtmgr.Endpoint, routeTable *rtmgr.RouteTable) {
207 xapp.Logger.Debug("rpe.generatePlatformRoutes invoked")
208 //Platform Routes --- Subscription Routes
209 //Subscription Manager -> E2 Termination
210 for _, routes := range *rtmgr.PrsCfg {
211 var sendEp *rtmgr.Endpoint
212 var Ep *rtmgr.Endpoint
213 switch routes.SenderEndPoint {
223 sendEp = a1mediatorEp
225 switch routes.EndPoint {
238 r.addRoute(routes.MessageType, sendEp, Ep, routeTable, routes.SubscriptionId, routes.Meid)
241 if len(e2TermEp) > 0 {
242 r.addRoute_rx_list("RIC_SCTP_CLEAR_ALL", e2ManEp, e2TermEp, routeTable, -1, "")
243 r.addRoute_rx_list("E2_TERM_KEEP_ALIVE_REQ", e2ManEp, e2TermEp, routeTable, -1, "")
247 func (r *Rpe) generateRouteTable(endPointList rtmgr.Endpoints) *rtmgr.RouteTable {
248 xapp.Logger.Debug("rpe.generateRouteTable invoked")
249 xapp.Logger.Debug("Endpoint List: %v", endPointList)
250 routeTable := &rtmgr.RouteTable{}
251 e2TermEp := getEndpointByName(&endPointList, "E2TERM")
253 xapp.Logger.Error("Platform component not found: %v", "E2 Termination")
254 xapp.Logger.Debug("Endpoints: %v", endPointList)
256 subManEp := getEndpointByName(&endPointList, "SUBMAN")
258 xapp.Logger.Error("Platform component not found: %v", "Subscription Manager")
259 xapp.Logger.Debug("Endpoints: %v", endPointList)
261 e2ManEp := getEndpointByName(&endPointList, "E2MAN")
263 xapp.Logger.Error("Platform component not found: %v", "E2 Manager")
264 xapp.Logger.Debug("Endpoints: %v", endPointList)
266 ueManEp := getEndpointByName(&endPointList, "UEMAN")
268 xapp.Logger.Error("Platform component not found: %v", "UE Manger")
269 xapp.Logger.Debug("Endpoints: %v", endPointList)
271 rsmEp := getEndpointByName(&endPointList, "RSM")
273 xapp.Logger.Error("Platform component not found: %v", "Resource Status Manager")
274 xapp.Logger.Debug("Endpoints: %v", endPointList)
276 A1MediatorEp := getEndpointByName(&endPointList, "A1MEDIATOR")
277 if A1MediatorEp == nil {
278 xapp.Logger.Error("Platform component not found: %v", "A1Mediator")
279 xapp.Logger.Debug("Endpoints: %v", endPointList)
282 e2TermListEp := getEndpointListByName(&endPointList, "E2TERMINST")
283 if len(e2TermListEp) == 0 {
284 xapp.Logger.Error("Platform component not found: %v", "E2 Termination List")
285 xapp.Logger.Debug("Endpoints: %v", endPointList)
287 r.generatePlatformRoutes(e2TermListEp, subManEp, e2ManEp, ueManEp, rsmEp, A1MediatorEp, routeTable)
289 for _, endPoint := range endPointList {
290 xapp.Logger.Debug("Endpoint: %v, xAppType: %v", endPoint.Name, endPoint.XAppType)
291 if endPoint.XAppType != sbi.PlatformType && (len(endPoint.TxMessages) > 0 || len(endPoint.RxMessages) > 0) {
292 r.generateXappRoutes(endPoint, e2TermEp, subManEp, routeTable)
293 r.generateSubscriptionRoutes(endPoint, e2TermEp, subManEp, routeTable)