import (
"errors"
"routing-manager/pkg/rtmgr"
+ "routing-manager/pkg/sbi"
"strconv"
)
var (
SupportedRpes = []*RpeEngineConfig{
- &RpeEngineConfig{
- Name: "rmrpub",
- Version: "pubsub",
- Protocol: "rmruta",
- Instance: NewRmrPub(),
- IsAvailable: true,
- },
&RpeEngineConfig{
Name: "rmrpush",
Version: "pubsush",
type Rpe struct {
}
-/*
-Gets the raw xApp list and generates the list of sender endpoints and receiver endpoint groups
-Returns the Tx EndpointList map where the key is the messge type and also returns the nested map of Rx EndpointList's map where keys are message type and xapp type
-Endpoint object's message type already transcoded to integer id
-*/
-
-func (r *Rpe) getRouteRxTxLists(eps rtmgr.Endpoints) (*map[string]rtmgr.EndpointList, *map[string]map[string]rtmgr.EndpointList) {
- txlist := make(map[string]rtmgr.EndpointList)
- rxgroups := make(map[string]map[string]rtmgr.EndpointList)
- for _, ep := range eps {
- for _, message := range ep.RxMessages {
- messageid := rtmgr.MESSAGETYPES[message]
- if _, ok := rxgroups[messageid]; !ok {
- rxgroups[messageid] = make(map[string]rtmgr.EndpointList)
- }
- rxgroups[messageid][ep.XAppType] = append(rxgroups[messageid][ep.XAppType], (*ep))
- }
- for _, message := range ep.TxMessages {
- messageid := rtmgr.MESSAGETYPES[message]
- txlist[messageid] = append(txlist[messageid], (*ep))
- }
- }
- return &txlist, &rxgroups
-}
-
-/*
-Gets the raw xapp list and creates a route table for
-Returns the array of route table entries
-*/
-func (r *Rpe) getRouteTable(eps rtmgr.Endpoints) *rtmgr.RouteTable {
- tx, rx := r.getRouteRxTxLists(eps)
- var rt rtmgr.RouteTable
- for _, messagetype := range rtmgr.MESSAGETYPES {
- /*if _, ok := (*tx)[messagetype]; !ok {
- continue
- }
- if _, ok := (*rx)[messagetype]; !ok {
- continue
- }*/
- txList, ok := (*tx)[messagetype]
- if !ok {
- txList = rtmgr.EndpointList{}
- }
- var rxgroups []rtmgr.EndpointList
- for _, endpointlist := range (*rx)[messagetype] {
- rxgroups = append(rxgroups, endpointlist)
- }
- if len(txList) > 0 || len(rxgroups) > 0 {
- rte := rtmgr.RouteTableEntry{
- messagetype,
- txList,
- rxgroups,
- -1,
- }
- rt = append(rt, rte)
- }
- }
- r.addStaticRoutes(eps, &rt)
- r.addSubscriptionRoutes(eps, &rt, &rtmgr.Subs)
- return &rt
-}
-
-/*
-Adds specific static routes to the route table
-which cannot be calculated with endpoint tx/rx message types.
-*/
-func (r *Rpe) addStaticRoutes(eps rtmgr.Endpoints, rt *rtmgr.RouteTable) {
- var uemanep, submanep *rtmgr.Endpoint
- for _, ep := range eps {
- if ep.Name == "UEMAN" {
- uemanep = ep
- }
- if ep.Name == "SUBMAN" {
- submanep = ep
- }
- }
-
- if uemanep != nil && submanep != nil {
- txlist := rtmgr.EndpointList{*uemanep}
- rxlist := []rtmgr.EndpointList{[]rtmgr.Endpoint{*submanep}}
- rte1 := rtmgr.RouteTableEntry{
- rtmgr.MESSAGETYPES["RIC_SUB_REQ"],
- txlist,
- rxlist,
- -1,
- }
- rte2 := rtmgr.RouteTableEntry{
- rtmgr.MESSAGETYPES["RIC_SUB_DEL_REQ"],
- txlist,
- rxlist,
- -1,
- }
- *rt = append(*rt, rte1)
- *rt = append(*rt, rte2)
- } else {
- rtmgr.Logger.Warn("Cannot get the static route details of the platform components UEMAN/SUBMAN")
- }
-}
-
func getEndpointByName(eps *rtmgr.Endpoints, name string) *rtmgr.Endpoint {
for _, ep := range *eps {
if ep.Name == name {
return nil
}
-func getEndpointByUuid(eps *rtmgr.Endpoints, uuid string) *rtmgr.Endpoint {
- for _, ep := range *eps {
+func getEndpointByUuid(uuid string) *rtmgr.Endpoint {
+ endPoints := rtmgr.Eps
+ for _, ep := range endPoints {
if ep.Uuid == uuid {
rtmgr.Logger.Debug("name: %s", ep.Uuid)
rtmgr.Logger.Debug("ep: %v", ep)
}
return nil
}
-func (r *Rpe) addSubscriptionRoutes(eps rtmgr.Endpoints, rt *rtmgr.RouteTable, subs *rtmgr.SubscriptionList) {
- rtmgr.Logger.Debug("rpe.addSubscriptionRoutes invoked")
- rtmgr.Logger.Debug("params: %v", eps)
- var e2termep, submanep, xappEp *rtmgr.Endpoint
- var xappName string
- e2termep = getEndpointByName(&eps, "E2TERM")
- submanep = getEndpointByName(&eps, "SUBMAN")
- if e2termep != nil && submanep != nil {
- // looping through the subscription list, add routes one by one
- for _, sub := range *subs {
- // SubMan -> XApp
- xappName = sub.Fqdn + ":" + strconv.Itoa(int(sub.Port))
- xappEp = getEndpointByUuid(&eps, xappName)
- if xappEp == nil {
- rtmgr.Logger.Error("XApp not found: %s", xappName)
- rtmgr.Logger.Debug("Endpoints: %v", eps)
- } else {
- txlist := rtmgr.EndpointList{*submanep}
- rxlist := []rtmgr.EndpointList{[]rtmgr.Endpoint{*xappEp}}
- subManMsgs := []string{"RIC_SUB_RESP", "RIC_SUB_FAILURE", "RIC_SUB_DEL_RESP", "RIC_SUB_DEL_FAILURE"}
- for _, entry := range subManMsgs {
- rte := rtmgr.RouteTableEntry{
- rtmgr.MESSAGETYPES[entry],
- txlist,
- rxlist,
- sub.SubID,
- }
- *rt = append(*rt, rte)
- }
- // E2Term -> XApp
- txlist = rtmgr.EndpointList{*e2termep}
- rxlist = []rtmgr.EndpointList{[]rtmgr.Endpoint{*xappEp}}
- e2apMsgs := []string{"RIC_CONTROL_ACK", "RIC_CONTROL_FAILURE", "RIC_INDICATION"}
- for _, entry := range e2apMsgs {
- rte := rtmgr.RouteTableEntry{
- rtmgr.MESSAGETYPES[entry],
- txlist,
- rxlist,
- sub.SubID,
- }
- *rt = append(*rt, rte)
- }
- }
+
+func (r *Rpe) addRoute(messageType string, tx *rtmgr.Endpoint, rx *rtmgr.Endpoint, routeTable *rtmgr.RouteTable) {
+ txList := rtmgr.EndpointList{*tx}
+ rxList := []rtmgr.EndpointList{[]rtmgr.Endpoint{*rx}}
+ messageId := rtmgr.MESSAGETYPES[messageType]
+ route := rtmgr.RouteTableEntry{
+ messageId,
+ txList,
+ rxList,
+ -1}
+ *routeTable = append(*routeTable, route)
+ rtmgr.Logger.Debug("Route added: MessageTyp: %v, Tx: %v, Rx: %v, SubId: -1", messageId, txList, rxList)
+}
+
+func (r *Rpe) addSubscriptionRoute(messageType string, tx *rtmgr.Endpoint, rx *rtmgr.Endpoint, routeTable *rtmgr.RouteTable, subId int32) {
+ txList := rtmgr.EndpointList{*tx}
+ rxList := []rtmgr.EndpointList{[]rtmgr.Endpoint{*rx}}
+ messageId := rtmgr.MESSAGETYPES[messageType]
+ route := rtmgr.RouteTableEntry{
+ messageId,
+ txList,
+ rxList,
+ subId,
+ }
+ *routeTable = append(*routeTable, route)
+ rtmgr.Logger.Debug("Route added: MessageTyp: %v, Tx: %v, Rx: %v, SubId: %v", messageId, txList, rxList, subId)
+}
+
+func (r *Rpe) generateXappRoutes(e2TermEp *rtmgr.Endpoint, subManEp *rtmgr.Endpoint, routeTable *rtmgr.RouteTable) {
+ rtmgr.Logger.Debug("rpe.generateXappRoutes invoked")
+ endPointList := rtmgr.Eps
+ for _, endPoint := range endPointList {
+ rtmgr.Logger.Debug("Endpoint: %v, xAppType: %v", endPoint.Name, endPoint.XAppType)
+ if endPoint.XAppType != sbi.PLATFORMTYPE && len(endPoint.TxMessages) > 0 && len(endPoint.RxMessages) > 0 {
+ //xApp -> Subscription Manager
+ r.addRoute("RIC_SUB_REQ", endPoint, subManEp, routeTable)
+ r.addRoute("RIC_SUB_DEL_REQ", endPoint, subManEp, routeTable)
+ //xApp -> E2 Termination
+ r.addRoute("RIC_CONTROL_REQ", endPoint, e2TermEp, routeTable)
}
- rtmgr.Logger.Debug("addSubscriptionRoutes eps: %v", eps)
- } else {
- rtmgr.Logger.Warn("Subscription route update failure: Cannot get the static route details of the platform components E2TERM/SUBMAN")
}
+}
+func (r *Rpe) generateSubscriptionRoutes(e2TermEp *rtmgr.Endpoint, subManEp *rtmgr.Endpoint, routeTable *rtmgr.RouteTable) {
+ rtmgr.Logger.Debug("rpe.addSubscriptionRoutes invoked")
+ subscriptionList := rtmgr.Subs
+ for _, subscription := range subscriptionList {
+ rtmgr.Logger.Debug("Subscription: %v", subscription)
+ xAppUuid := subscription.Fqdn + ":" + strconv.Itoa(int(subscription.Port))
+ rtmgr.Logger.Debug("xApp UUID: %v", xAppUuid)
+ xAppEp := getEndpointByUuid(xAppUuid)
+ //Subscription Manager -> xApp
+ r.addSubscriptionRoute("RIC_SUB_RESP", subManEp, xAppEp, routeTable, subscription.SubID)
+ r.addSubscriptionRoute("RIC_SUB_FAILURE", subManEp, xAppEp, routeTable, subscription.SubID)
+ r.addSubscriptionRoute("RIC_SUB_DEL_RESP", subManEp, xAppEp, routeTable, subscription.SubID)
+ r.addSubscriptionRoute("RIC_SUB_DEL_FAILURE", subManEp, xAppEp, routeTable, subscription.SubID)
+ //E2 Termination -> xApp
+ r.addSubscriptionRoute("RIC_INDICATION", e2TermEp, xAppEp, routeTable, subscription.SubID)
+ r.addSubscriptionRoute("RIC_CONTROL_ACK", e2TermEp, xAppEp, routeTable, subscription.SubID)
+ r.addSubscriptionRoute("RIC_CONTROL_FAILURE", e2TermEp, xAppEp, routeTable, subscription.SubID)
+ }
+}
+
+func (r *Rpe) generatePlatformRoutes(e2TermEp *rtmgr.Endpoint, subManEp *rtmgr.Endpoint, e2ManEp *rtmgr.Endpoint, ueManEp *rtmgr.Endpoint, routeTable *rtmgr.RouteTable) {
+ rtmgr.Logger.Debug("rpe.generatePlatformRoutes invoked")
+ //Platform Routes --- Subscription Routes
+ //Subscription Manager -> E2 Termination
+ r.addRoute("RIC_SUB_REQ", subManEp, e2TermEp, routeTable)
+ r.addRoute("RIC_SUB_DEL_REQ", subManEp, e2TermEp, routeTable)
+ //E2 Termination -> Subscription Manager
+ r.addRoute("RIC_SUB_RESP", e2TermEp, subManEp, routeTable)
+ r.addRoute("RIC_SUB_DEL_RESP", e2TermEp, subManEp, routeTable)
+ r.addRoute("RIC_SUB_FAILURE", e2TermEp, subManEp, routeTable)
+ r.addRoute("RIC_SUB_DEL_FAILURE", e2TermEp, subManEp, routeTable)
+ //TODO: UE Man Routes removed (since it is not existing)
+ //UE Manager -> Subscription Manager
+ //r.addRoute("RIC_SUB_REQ", ueManEp, subManEp, routeTable)
+ //r.addRoute("RIC_SUB_DEL_REQ", ueManEp, subManEp, routeTable)
+ ////UE Manager -> E2 Termination
+ //r.addRoute("RIC_CONTROL_REQ", ueManEp, e2TermEp, routeTable)
+
+ //Platform Routes --- X2 Routes
+ //E2 Manager -> E2 Termination
+ r.addRoute("RIC_X2_SETUP_REQ", e2ManEp, e2TermEp, routeTable)
+ r.addRoute("RIC_X2_SETUP_RESP", e2ManEp, e2TermEp, routeTable)
+ r.addRoute("RIC_X2_SETUP_FAILURE", e2ManEp, e2TermEp, routeTable)
+ r.addRoute("RIC_X2_RESET_RESP", e2ManEp, e2TermEp, routeTable)
+ r.addRoute("RIC_ENDC_X2_SETUP_REQ", e2ManEp, e2TermEp, routeTable)
+ r.addRoute("RIC_ENDC_X2_SETUP_RESP", e2ManEp, e2TermEp, routeTable)
+ r.addRoute("RIC_ENDC_X2_SETUP_FAILURE", e2ManEp, e2TermEp, routeTable)
+ //E2 Termination -> E2 Manager
+ r.addRoute("RIC_X2_SETUP_REQ", e2TermEp, e2ManEp, routeTable)
+ r.addRoute("RIC_X2_SETUP_RESP", e2TermEp, e2ManEp, routeTable)
+ r.addRoute("RIC_X2_RESET", e2TermEp, e2ManEp, routeTable)
+ r.addRoute("RIC_X2_RESOURCE_STATUS_RESPONSE", e2TermEp, e2ManEp, routeTable)
+ r.addRoute("RIC_X2_RESET_RESP", e2TermEp, e2ManEp, routeTable)
+ r.addRoute("RIC_ENDC_X2_SETUP_REQ", e2ManEp, e2TermEp, routeTable)
+ r.addRoute("RIC_ENDC_X2_SETUP_RESP", e2ManEp, e2TermEp, routeTable)
+ r.addRoute("RIC_ENDC_X2_SETUP_FAILURE", e2ManEp, e2TermEp, routeTable)
+}
+
+func (r *Rpe) generateRouteTable(endPointList rtmgr.Endpoints) *rtmgr.RouteTable {
+ rtmgr.Logger.Debug("rpe.generateRouteTable invoked")
+ rtmgr.Logger.Debug("Endpoint List: %v", endPointList)
+ routeTable := &rtmgr.RouteTable{}
+ e2TermEp := getEndpointByName(&endPointList, "E2TERM")
+ if e2TermEp == nil {
+ rtmgr.Logger.Error("Platform component not found: %v", "E2 Termination")
+ rtmgr.Logger.Debug("Endpoints: %v", endPointList)
+ }
+ subManEp := getEndpointByName(&endPointList, "SUBMAN")
+ if subManEp == nil {
+ rtmgr.Logger.Error("Platform component not found: %v", "Subscription Manager")
+ rtmgr.Logger.Debug("Endpoints: %v", endPointList)
+ }
+ e2ManEp := getEndpointByName(&endPointList, "E2MAN")
+ if e2ManEp == nil {
+ rtmgr.Logger.Error("Platform component not found: %v", "E2 Manager")
+ rtmgr.Logger.Debug("Endpoints: %v", endPointList)
+ }
+ ueManEp := getEndpointByName(&endPointList, "UEMAN")
+ if ueManEp == nil {
+ rtmgr.Logger.Error("Platform component not found: %v", "UE Manger")
+ rtmgr.Logger.Debug("Endpoints: %v", endPointList)
+ }
+ r.generatePlatformRoutes(e2TermEp, subManEp, e2ManEp, ueManEp, routeTable)
+
+ for _, endPoint := range endPointList {
+ rtmgr.Logger.Debug("Endpoint: %v, xAppType: %v", endPoint.Name, endPoint.XAppType)
+ if endPoint.XAppType != sbi.PLATFORMTYPE && len(endPoint.TxMessages) > 0 && len(endPoint.RxMessages) > 0 {
+ r.generateXappRoutes(e2TermEp, subManEp, routeTable)
+ r.generateSubscriptionRoutes(e2TermEp, subManEp, routeTable)
+ }
+ }
+ return routeTable
}