X-Git-Url: https://gerrit.o-ran-sc.org/r/gitweb?a=blobdiff_plain;f=pkg%2Fcontrol%2Fclient.go;h=b067f3bfeb17088f4012593821db2ff8a560ff58;hb=31797b49985822f1d402501f16ab2794838bebba;hp=598c7efb0a8f49ef3fc6ff92ea88a622bb58eef9;hpb=93cc3e245f87798c8753209980817727e0648401;p=ric-plt%2Fsubmgr.git diff --git a/pkg/control/client.go b/pkg/control/client.go index 598c7ef..b067f3b 100644 --- a/pkg/control/client.go +++ b/pkg/control/client.go @@ -20,57 +20,55 @@ package control import ( + "fmt" rtmgrclient "gerrit.o-ran-sc.org/r/ric-plt/submgr/pkg/rtmgr_client" rtmgrhandle "gerrit.o-ran-sc.org/r/ric-plt/submgr/pkg/rtmgr_client/handle" "gerrit.o-ran-sc.org/r/ric-plt/submgr/pkg/rtmgr_models" - "strings" - "strconv" - "errors" "gerrit.o-ran-sc.org/r/ric-plt/xapp-frame/pkg/xapp" + "strconv" + "strings" ) +//----------------------------------------------------------------------------- +// +//----------------------------------------------------------------------------- +type SubRouteInfo struct { + Command Action + EpList RmrEndpointList + SubID uint16 +} + +func (sri *SubRouteInfo) String() string { + return "routeinfo(" + sri.Command.String() + "/" + strconv.FormatUint(uint64(sri.SubID), 10) + "/[" + sri.EpList.String() + "])" +} + +//----------------------------------------------------------------------------- +// +//----------------------------------------------------------------------------- type RtmgrClient struct { rtClient *rtmgrclient.RoutingManager xappHandleParams *rtmgrhandle.ProvideXappSubscriptionHandleParams + xappDeleteParams *rtmgrhandle.DeleteXappSubscriptionHandleParams } -func (rc *RtmgrClient) SubscriptionRequestUpdate() error { - xapp.Logger.Debug("SubscriptionRequestUpdate() invoked") - subRouteAction := <-SubscriptionReqChan - // Routing manager handles subscription id as int32 to accomodate -1 and uint16 values +func (rc *RtmgrClient) SubscriptionRequestUpdate(subRouteAction SubRouteInfo) error { subID := int32(subRouteAction.SubID) - - xapp.Logger.Debug("Subscription action details received: ", subRouteAction) - - xappSubReq := rtmgr_models.XappSubscriptionData{&subRouteAction.Address, &subRouteAction.Port, &subID} - + xapp.Logger.Debug("%s ongoing", subRouteAction.String()) + xappSubReq := rtmgr_models.XappSubscriptionData{&subRouteAction.EpList.Endpoints[0].Addr, &subRouteAction.EpList.Endpoints[0].Port, &subID} + var err error switch subRouteAction.Command { case CREATE: - _, postErr := rc.rtClient.Handle.ProvideXappSubscriptionHandle(rc.xappHandleParams.WithXappSubscriptionData(&xappSubReq)) - if postErr != nil && !(strings.Contains(postErr.Error(), "status 200")) { - xapp.Logger.Error("Updating routing manager about subscription id = %d failed with error: %v", subID, postErr) - return postErr - } else { - xapp.Logger.Info("Succesfully updated routing manager about the subscription: %d", subID) - return nil - } + _, err = rc.rtClient.Handle.ProvideXappSubscriptionHandle(rc.xappHandleParams.WithXappSubscriptionData(&xappSubReq)) + case DELETE: + _, _, err = rc.rtClient.Handle.DeleteXappSubscriptionHandle(rc.xappDeleteParams.WithXappSubscriptionData(&xappSubReq)) default: - return nil + return fmt.Errorf("%s unknown", subRouteAction.String()) } -} -func (rc *RtmgrClient) SplitSource(src string) (*string, *uint16, error) { - tcpSrc := strings.Split(src, ":") - if len(tcpSrc) != 2 { - err := errors.New("Unable to get the source details of the xapp. Check the source string received from the rmr.") - return nil, nil, err - } - srcAddr := tcpSrc[0] - xapp.Logger.Info("---Debugging Inside splitsource tcpsrc[0] = %s and tcpsrc[1]= %s ", tcpSrc[0], tcpSrc[1]) - srcPort, err := strconv.ParseUint(tcpSrc[1], 10, 16) - if err != nil { - return nil, nil, err + if err != nil && !(strings.Contains(err.Error(), "status 200")) { + return fmt.Errorf("%s failed with error: %s", subRouteAction.String(), err.Error()) } - srcPortInt := uint16(srcPort) - return &srcAddr, &srcPortInt, nil + xapp.Logger.Debug("%s successful", subRouteAction.String()) + return nil + }