X-Git-Url: https://gerrit.o-ran-sc.org/r/gitweb?a=blobdiff_plain;f=pkg%2Frpe%2Frpe.go;h=5dd8f4d250bf00383d57d7242db0e5fef40a1310;hb=92162653c9741f2417d1a36ec1c211d6863d0a68;hp=636a439a9d02b1a62212202676fab75912f709c2;hpb=419d851344e85fffeeb9a65726cd02e97dbfe7df;p=ric-plt%2Frtmgr.git diff --git a/pkg/rpe/rpe.go b/pkg/rpe/rpe.go index 636a439..5dd8f4d 100644 --- a/pkg/rpe/rpe.go +++ b/pkg/rpe/rpe.go @@ -26,49 +26,39 @@ package rpe import ( "errors" - "fmt" - "rtmgr" + "routing-manager/pkg/rtmgr" + "strconv" ) var ( SupportedRpes = []*RpeEngineConfig{ &RpeEngineConfig{ - RpeEngine{ - Name: "rmrpub", - Version: "pubsub", - Protocol: "rmruta", - }, - generatePolicies(generateRMRPubPolicies), - true, + Name: "rmrpub", + Version: "pubsub", + Protocol: "rmruta", + Instance: NewRmrPub(), + IsAvailable: true, }, &RpeEngineConfig{ - RpeEngine{ - Name: "rmrpush", - Version: "push", - Protocol: "rmruta", - }, - generatePolicies(generateRMRPushPolicies), - true, + Name: "rmrpush", + Version: "pubsush", + Protocol: "rmruta", + Instance: NewRmrPush(), + IsAvailable: true, }, } ) -func ListRpes() { - fmt.Printf("RPE:\n") +func GetRpe(rpeName string) (RpeEngine, 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 - } - } - return nil, errors.New("SBI:" + rpeName + " is not supported or still not a available") +type Rpe struct { } /* @@ -77,7 +67,7 @@ Returns the Tx EndpointList map where the key is the messge type and also return Endpoint object's message type already transcoded to integer id */ -func getRouteRxTxLists(eps rtmgr.Endpoints) (*map[string]rtmgr.EndpointList, *map[string]map[string]rtmgr.EndpointList) { +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 { @@ -100,26 +90,144 @@ func getRouteRxTxLists(eps rtmgr.Endpoints) (*map[string]rtmgr.EndpointList, *ma Gets the raw xapp list and creates a route table for Returns the array of route table entries */ -func getRouteTable(eps rtmgr.Endpoints) *rtmgr.RouteTable { - tx, rx := getRouteRxTxLists(eps) +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 { + /*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) } - rte := rtmgr.RouteTableEntry{ - messagetype, - (*tx)[messagetype], - rxgroups, + if len(txList) > 0 || len(rxgroups) > 0 { + rte := rtmgr.RouteTableEntry{ + messagetype, + txList, + rxgroups, + -1, + } + rt = append(rt, rte) } - 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 { + rtmgr.Logger.Debug("name: %s", ep.Name) + rtmgr.Logger.Debug("ep: %v", ep) + return ep + } + } + return nil +} + +func getEndpointByUuid(eps *rtmgr.Endpoints, uuid string) *rtmgr.Endpoint { + for _, ep := range *eps { + if ep.Uuid == uuid { + rtmgr.Logger.Debug("name: %s", ep.Uuid) + rtmgr.Logger.Debug("ep: %v", ep) + return 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) + } + } + } + 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") + } + +}