X-Git-Url: https://gerrit.o-ran-sc.org/r/gitweb?a=blobdiff_plain;f=pkg%2Frpe%2Frpe.go;h=20cd4e91b796b15aa19af74b7027593c62d54823;hb=refs%2Fchanges%2F59%2F1259%2F1;hp=f915ddd6df5e1be68a1da7584d1baf5caa1ef451;hpb=871fa393844ce1b61b8d5218d27687d9fc05803a;p=ric-plt%2Frtmgr.git diff --git a/pkg/rpe/rpe.go b/pkg/rpe/rpe.go index f915ddd..20cd4e9 100644 --- a/pkg/rpe/rpe.go +++ b/pkg/rpe/rpe.go @@ -26,98 +26,183 @@ package rpe import ( "errors" - "fmt" - "rtmgr" + "routing-manager/pkg/rtmgr" + "routing-manager/pkg/sbi" "strconv" + "runtime" ) var ( - SupportedRpes = []*RpeEngineConfig{ - &RpeEngineConfig{ - RpeEngine{ - Name: "rmr", - Version: "v1", - Protocol: "rmruta", - }, - generatePolicies(generateRMRPolicies), - true, + SupportedRpes = []*EngineConfig{ + { + Name: "rmrpush", + Version: "pubsush", + Protocol: "rmruta", + Instance: NewRmrPush(), + IsAvailable: true, }, } ) -func ListRpes() { - fmt.Printf("RPE:\n") +func GetRpe(rpeName string) (Engine, error) { for _, rpe := range SupportedRpes { - if rpe.IsAvailable { - rtmgr.Logger.Info(rpe.Engine.Name + "/" + rpe.Engine.Version) + if rpe.Name == rpeName && rpe.IsAvailable { + return rpe.Instance, nil } } + return nil, errors.New("SBI:" + rpeName + " is not supported or still not a available") } -func GetRpe(rpeName string) (*RpeEngineConfig, error) { - for _, rpe := range SupportedRpes { - if rpe.Engine.Name == rpeName && rpe.IsAvailable { - return rpe, nil +type Rpe struct { +} + +func getEndpointByName(eps *rtmgr.Endpoints, name string) *rtmgr.Endpoint { + for _, ep := range *eps { + if ep.Name == name { + rtmgr.Logger.Debug("name: %s", ep.Name) + rtmgr.Logger.Debug("ep: %v", ep) + return ep } } - return nil, errors.New("SBI:" + rpeName + "is not supported or still not a available") + return nil } -/* -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 getEndpointLists(xapps *[]rtmgr.XApp) (*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 _, xapp := range *xapps { - for _, instance := range xapp.Instances { - ep := rtmgr.Endpoint{ - instance.Name, - xapp.Name, - instance.Ip + ":" + strconv.Itoa(instance.Port), - } - for _, message := range instance.RxMessages { - messageid := rtmgr.MESSAGETYPES[message] - if _, ok := rxgroups[messageid]; !ok { - rxgroups[messageid] = make(map[string]rtmgr.EndpointList) - } - rxgroups[messageid][xapp.Name] = append(rxgroups[messageid][xapp.Name], ep) - } - for _, message := range instance.TxMessages { - messageid := rtmgr.MESSAGETYPES[message] - txlist[messageid] = append(txlist[messageid], ep) - } +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 ep } } - return &txlist, &rxgroups + return nil } -/* -Gets the raw xapp list and creates a route table for -Returns the array of route table entries -*/ -func getRouteTable(xapps *[]rtmgr.XApp) *rtmgr.RouteTable { - tx, rx := getEndpointLists(xapps) - var rt rtmgr.RouteTable - for _, messagetype := range rtmgr.MESSAGETYPES { - if _, ok := (*tx)[messagetype]; !ok { - continue - } - if _, ok := (*rx)[messagetype]; !ok { - continue - } - var rxgroups []rtmgr.EndpointList - for _, endpointlist := range (*rx)[messagetype] { - rxgroups = append(rxgroups, endpointlist) +func (r *Rpe) addRoute(messageType string, tx *rtmgr.Endpoint, rx *rtmgr.Endpoint, routeTable *rtmgr.RouteTable, subId int32) { + if tx != nil && rx != nil { + txList := rtmgr.EndpointList{*tx} + rxList := []rtmgr.EndpointList{[]rtmgr.Endpoint{*rx}} + messageId := rtmgr.MessageTypes[messageType] + route := rtmgr.RouteTableEntry{ + MessageType: messageId, + TxList: txList, + RxGroups: rxList, + SubID: subId} + *routeTable = append(*routeTable, route) + rtmgr.Logger.Debug("Route added: MessageTyp: %v, Tx: %v, Rx: %v, SubId: %v", messageId, tx.Uuid, rx.Uuid, subId) + rtmgr.Logger.Trace("Route added: MessageTyp: %v, Tx: %v, Rx: %v, SubId: %v", messageId, tx, rx, subId) + } else { + pc,_,_,ok := runtime.Caller(1) + details := runtime.FuncForPC(pc) + if ok && details != nil { + rtmgr.Logger.Error("Route addition skipped: Either TX or RX endpoint not present. Caller function is %s", details.Name()) + } } - rte := rtmgr.RouteTableEntry{ - messagetype, - (*tx)[messagetype], - rxgroups, +} + +func (r *Rpe) generateXappRoutes(xAppEp *rtmgr.Endpoint, e2TermEp *rtmgr.Endpoint, subManEp *rtmgr.Endpoint, routeTable *rtmgr.RouteTable) { + rtmgr.Logger.Debug("rpe.generateXappRoutes invoked") + rtmgr.Logger.Debug("Endpoint: %v, xAppType: %v", xAppEp.Name, xAppEp.XAppType) + if xAppEp.XAppType != sbi.PlatformType && len(xAppEp.TxMessages) > 0 && len(xAppEp.RxMessages) > 0 { + //xApp -> Subscription Manager + r.addRoute("RIC_SUB_REQ", xAppEp, subManEp, routeTable, -1) + r.addRoute("RIC_SUB_DEL_REQ", xAppEp, subManEp, routeTable, -1) + //xApp -> E2 Termination + r.addRoute("RIC_CONTROL_REQ", xAppEp, e2TermEp, routeTable, -1) + } +} + +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.addRoute("RIC_SUB_RESP", subManEp, xAppEp, routeTable, subscription.SubID) + r.addRoute("RIC_SUB_FAILURE", subManEp, xAppEp, routeTable, subscription.SubID) + r.addRoute("RIC_SUB_DEL_RESP", subManEp, xAppEp, routeTable, subscription.SubID) + r.addRoute("RIC_SUB_DEL_FAILURE", subManEp, xAppEp, routeTable, subscription.SubID) + //E2 Termination -> xApp + r.addRoute("RIC_INDICATION", e2TermEp, xAppEp, routeTable, subscription.SubID) + r.addRoute("RIC_CONTROL_ACK", e2TermEp, xAppEp, routeTable, subscription.SubID) + r.addRoute("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, -1) + r.addRoute("RIC_SUB_DEL_REQ", subManEp, e2TermEp, routeTable, -1) + //E2 Termination -> Subscription Manager + r.addRoute("RIC_SUB_RESP", e2TermEp, subManEp, routeTable, -1) + r.addRoute("RIC_SUB_DEL_RESP", e2TermEp, subManEp, routeTable, -1) + r.addRoute("RIC_SUB_FAILURE", e2TermEp, subManEp, routeTable, -1) + r.addRoute("RIC_SUB_DEL_FAILURE", e2TermEp, subManEp, routeTable, -1) + //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, -1) + r.addRoute("RIC_X2_SETUP_RESP", e2ManEp, e2TermEp, routeTable, -1) + r.addRoute("RIC_X2_SETUP_FAILURE", e2ManEp, e2TermEp, routeTable, -1) + r.addRoute("RIC_X2_RESET_RESP", e2ManEp, e2TermEp, routeTable, -1) + r.addRoute("RIC_ENDC_X2_SETUP_REQ", e2ManEp, e2TermEp, routeTable, -1) + r.addRoute("RIC_SCTP_CLEAR_ALL", e2ManEp, e2TermEp, routeTable, -1) + //E2 Termination -> E2 Manager + r.addRoute("E2_TERM_INIT", e2TermEp, e2ManEp, routeTable, -1) + r.addRoute("RIC_X2_SETUP_REQ", e2TermEp, e2ManEp, routeTable, -1) + r.addRoute("RIC_X2_SETUP_RESP", e2TermEp, e2ManEp, routeTable, -1) + r.addRoute("RIC_X2_RESET", e2TermEp, e2ManEp, routeTable, -1) + r.addRoute("RIC_X2_RESOURCE_STATUS_RESPONSE", e2TermEp, e2ManEp, routeTable, -1) + r.addRoute("RIC_X2_RESET_RESP", e2TermEp, e2ManEp, routeTable, -1) + r.addRoute("RIC_ENDC_X2_SETUP_RESP", e2TermEp, e2ManEp, routeTable, -1) + r.addRoute("RIC_ENDC_X2_SETUP_FAILURE", e2TermEp, e2ManEp, routeTable, -1) + r.addRoute("RIC_SCTP_CONNECTION_FAILURE", e2TermEp, e2ManEp, routeTable, -1) +} + +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(endPoint, e2TermEp, subManEp, routeTable) + r.generateSubscriptionRoutes(e2TermEp, subManEp, routeTable) } - rt = append(rt, rte) } - return &rt + return routeTable }