From 8c690b8970f4409ddf6fee547b6246839b88c247 Mon Sep 17 00:00:00 2001 From: wahidw Date: Tue, 9 Mar 2021 12:46:10 +0000 Subject: [PATCH] Overwrite duplicate E2T address instead of sending error to E2Manager Signed-off-by: wahidw Change-Id: Ied3f56357e000d89ec11d2c6f8312634227b8cab --- Dockerfile | 2 +- RELNOTES | 3 + container-tag.yaml | 2 +- pkg/nbi/control.go | 191 ++++++++++++++++++++++++------------------------- pkg/nbi/httprestful.go | 189 ++++++++++++++++++++++++++---------------------- 5 files changed, 203 insertions(+), 184 deletions(-) diff --git a/Dockerfile b/Dockerfile index a711d6c..adae21d 100644 --- a/Dockerfile +++ b/Dockerfile @@ -23,7 +23,7 @@ # a Docker tag from the string in file container-tag.yaml #FROM golang:1.12.1 as rtmgrbuild -FROM nexus3.o-ran-sc.org:10004/o-ran-sc/bldr-ubuntu18-c-go:1.9.0 as rtmgrbuild +FROM nexus3.o-ran-sc.org:10002/o-ran-sc/bldr-ubuntu18-c-go:1.9.0 as rtmgrbuild # Install RMr shared library ARG RMRVERSION=4.5.2 diff --git a/RELNOTES b/RELNOTES index aa347ea..ffdc47a 100644 --- a/RELNOTES +++ b/RELNOTES @@ -1,3 +1,6 @@ +### v0.7.4 +* Overwrite duplicate E2T address instead of sending error to E2Manager + ### v0.7.3 * Upgraded to RMR v4.5.2 diff --git a/container-tag.yaml b/container-tag.yaml index abddac4..b3f65d6 100644 --- a/container-tag.yaml +++ b/container-tag.yaml @@ -2,4 +2,4 @@ # By default this file is in the docker build directory, # but the location can configured in the JJB template. --- -tag: 0.7.3 +tag: 0.7.4 diff --git a/pkg/nbi/control.go b/pkg/nbi/control.go index 5eff852..02899c6 100644 --- a/pkg/nbi/control.go +++ b/pkg/nbi/control.go @@ -26,7 +26,9 @@ import "C" import ( "errors" + //"fmt" "gerrit.o-ran-sc.org/r/ric-plt/xapp-frame/pkg/xapp" + "os" "routing-manager/pkg/rpe" "routing-manager/pkg/rtmgr" "routing-manager/pkg/sbi" @@ -34,8 +36,6 @@ import ( "strconv" "sync" "time" - "os" - "fmt" ) var m sync.Mutex @@ -55,15 +55,14 @@ type Control struct { rcChan chan *xapp.RMRParams } - func (c *Control) Run() { var err error go c.controlLoop() nbiEngine, sbiEngine, sdlEngine, rpeEngine, err = initRtmgr() if err != nil { - xapp.Logger.Error(err.Error()) - os.Exit(1) - } + xapp.Logger.Error(err.Error()) + os.Exit(1) + } xapp.Run(c) } @@ -73,16 +72,16 @@ func (c *Control) Consume(rp *xapp.RMRParams) (err error) { } func initRtmgr() (nbiEngine Engine, sbiEngine sbi.Engine, sdlEngine sdl.Engine, rpeEngine rpe.Engine, err error) { - if nbiEngine, err = GetNbi(xapp.Config.GetString("nbi")); err == nil && nbiEngine != nil { - if sbiEngine, err = sbi.GetSbi(xapp.Config.GetString("sbi")); err == nil && sbiEngine != nil { - if sdlEngine, err = sdl.GetSdl(xapp.Config.GetString("sdl")); err == nil && sdlEngine != nil { - if rpeEngine, err = rpe.GetRpe(xapp.Config.GetString("rpe")); err == nil && rpeEngine != nil { - return nbiEngine, sbiEngine, sdlEngine, rpeEngine, nil - } - } - } - } - return nil, nil, nil, nil, err + if nbiEngine, err = GetNbi(xapp.Config.GetString("nbi")); err == nil && nbiEngine != nil { + if sbiEngine, err = sbi.GetSbi(xapp.Config.GetString("sbi")); err == nil && sbiEngine != nil { + if sdlEngine, err = sdl.GetSdl(xapp.Config.GetString("sdl")); err == nil && sdlEngine != nil { + if rpeEngine, err = rpe.GetRpe(xapp.Config.GetString("rpe")); err == nil && rpeEngine != nil { + return nbiEngine, sbiEngine, sdlEngine, rpeEngine, nil + } + } + } + } + return nil, nil, nil, nil, err } func (c *Control) controlLoop() { @@ -90,43 +89,43 @@ func (c *Control) controlLoop() { msg := <-c.rcChan c.recievermr(msg) /* - xapp_msg := sbi.RMRParams{msg} - switch msg.Mtype { - case xapp.RICMessageTypes["RMRRM_REQ_TABLE"]: - if rtmgr.Rtmgr_ready == false { - xapp.Logger.Info("Update Route Table Request(RMR to RM), message discarded as routing manager is not ready") - } else { - xapp.Logger.Info("Update Route Table Request(RMR to RM)") - go c.handleUpdateToRoutingManagerRequest(msg) + xapp_msg := sbi.RMRParams{msg} + switch msg.Mtype { + case xapp.RICMessageTypes["RMRRM_REQ_TABLE"]: + if rtmgr.Rtmgr_ready == false { + xapp.Logger.Info("Update Route Table Request(RMR to RM), message discarded as routing manager is not ready") + } else { + xapp.Logger.Info("Update Route Table Request(RMR to RM)") + go c.handleUpdateToRoutingManagerRequest(msg) + } + case xapp.RICMessageTypes["RMRRM_TABLE_STATE"]: + xapp.Logger.Info("state of table to route mgr %s,payload %s", xapp_msg.String(), msg.Payload) + + default: + err := errors.New("Message Type " + strconv.Itoa(msg.Mtype) + " is discarded") + xapp.Logger.Error("Unknown message type: %v", err) } - case xapp.RICMessageTypes["RMRRM_TABLE_STATE"]: - xapp.Logger.Info("state of table to route mgr %s,payload %s", xapp_msg.String(), msg.Payload) - - default: - err := errors.New("Message Type " + strconv.Itoa(msg.Mtype) + " is discarded") - xapp.Logger.Error("Unknown message type: %v", err) - } - xapp.Rmr.Free(msg.Mbuf)*/ + xapp.Rmr.Free(msg.Mbuf)*/ } } func (c *Control) recievermr(msg *xapp.RMRParams) { xapp_msg := sbi.RMRParams{msg} - switch msg.Mtype { - case xapp.RICMessageTypes["RMRRM_REQ_TABLE"]: - if rtmgr.Rtmgr_ready == false { - xapp.Logger.Info("Update Route Table Request(RMR to RM), message discarded as routing manager is not ready") - } else { - xapp.Logger.Info("Update Route Table Request(RMR to RM)") - go c.handleUpdateToRoutingManagerRequest(msg) - } - case xapp.RICMessageTypes["RMRRM_TABLE_STATE"]: - xapp.Logger.Info("state of table to route mgr %s,payload %s", xapp_msg.String(), msg.Payload) - default: - err := errors.New("Message Type " + strconv.Itoa(msg.Mtype) + " is discarded") - xapp.Logger.Error("Unknown message type: %v", err) - } - xapp.Rmr.Free(msg.Mbuf) + switch msg.Mtype { + case xapp.RICMessageTypes["RMRRM_REQ_TABLE"]: + if rtmgr.Rtmgr_ready == false { + xapp.Logger.Info("Update Route Table Request(RMR to RM), message discarded as routing manager is not ready") + } else { + xapp.Logger.Info("Update Route Table Request(RMR to RM)") + go c.handleUpdateToRoutingManagerRequest(msg) + } + case xapp.RICMessageTypes["RMRRM_TABLE_STATE"]: + xapp.Logger.Info("state of table to route mgr %s,payload %s", xapp_msg.String(), msg.Payload) + default: + err := errors.New("Message Type " + strconv.Itoa(msg.Mtype) + " is discarded") + xapp.Logger.Error("Unknown message type: %v", err) + } + xapp.Rmr.Free(msg.Mbuf) } func (c *Control) handleUpdateToRoutingManagerRequest(params *xapp.RMRParams) { @@ -139,30 +138,30 @@ func (c *Control) handleUpdateToRoutingManagerRequest(params *xapp.RMRParams) { m.Lock() data, err := sdlEngine.ReadAll(xapp.Config.GetString("rtfile")) m.Unlock() - if data == nil { - if err != nil { - xapp.Logger.Error("Cannot get data from sdl interface due to: " + err.Error()) - return - } else { - xapp.Logger.Debug("Cannot get data from sdl interface") - return - } - } + if data == nil { + if err != nil { + xapp.Logger.Error("Cannot get data from sdl interface due to: " + err.Error()) + return + } else { + xapp.Logger.Debug("Cannot get data from sdl interface") + return + } + } ep := sbiEngine.CheckEndpoint(string(params.Payload)) if ep == nil { xapp.Logger.Error("Update Routing Table Request can't handle due to end point %s is not avail in complete ep list: ", string(params.Payload)) return } - epstr,whid := sbiEngine.CreateEndpoint(msg.String()) + epstr, whid := sbiEngine.CreateEndpoint(msg.String()) if epstr == nil || whid < 0 { - xapp.Logger.Error("Wormhole Id creation failed %d for %s",whid,msg.String() ) + xapp.Logger.Error("Wormhole Id creation failed %d for %s", whid, msg.String()) return } /*This is to ensure the latest routes are sent. Assumption is that in this time interval the routes are built for this endpoint */ - time.Sleep(100 * time.Millisecond) + time.Sleep(100 * time.Millisecond) policies := rpeEngine.GeneratePolicies(rtmgr.Eps, data) err = sbiEngine.DistributeToEp(policies, *epstr, whid) if err != nil { @@ -173,53 +172,53 @@ func (c *Control) handleUpdateToRoutingManagerRequest(params *xapp.RMRParams) { func sendRoutesToAll() (err error) { - m.Lock() - data, err := sdlEngine.ReadAll(xapp.Config.GetString("rtfile")) - fmt.Printf("data = %v,%v,%v",data,sdlEngine,sbiEngine) - m.Unlock() + m.Lock() + data, err := sdlEngine.ReadAll(xapp.Config.GetString("rtfile")) + //fmt.Printf("data = %v,%v,%v",data,sdlEngine,sbiEngine) + m.Unlock() if data == nil { - if err != nil { + if err != nil { return errors.New("Cannot get data from sdl interface due to: " + err.Error()) - } else { - xapp.Logger.Debug("Cannot get data from sdl interface, data is null") - return errors.New("Cannot get data from sdl interface") - } + } else { + xapp.Logger.Debug("Cannot get data from sdl interface, data is null") + return errors.New("Cannot get data from sdl interface") + } } - if sbiEngine == nil { + /* if sbiEngine == nil { fmt.Printf("SBI is nil") + }*/ + sbiEngine.UpdateEndpoints(data) + policies := rpeEngine.GeneratePolicies(rtmgr.Eps, data) + err = sbiEngine.DistributeAll(policies) + if err != nil { + return errors.New("Routing table cannot be published due to: " + err.Error()) } - sbiEngine.UpdateEndpoints(data) - policies := rpeEngine.GeneratePolicies(rtmgr.Eps, data) - err = sbiEngine.DistributeAll(policies) - if err != nil { - return errors.New("Routing table cannot be published due to: " + err.Error()) - } return nil } func Serve() { - nbiErr := nbiEngine.Initialize(xapp.Config.GetString("xmurl"), xapp.Config.GetString("nbiurl"), xapp.Config.GetString("rtfile"), xapp.Config.GetString("cfgfile"), xapp.Config.GetString("e2murl"), sdlEngine, rpeEngine, &m) - if nbiErr != nil { - xapp.Logger.Error("Failed to initialize nbi due to: " + nbiErr.Error()) - return - } - - err := sbiEngine.Initialize(xapp.Config.GetString("sbiurl")) - if err != nil { - xapp.Logger.Info("Failed to open push socket due to: " + err.Error()) - return - } - defer nbiEngine.Terminate() - defer sbiEngine.Terminate() - - for { - sendRoutesToAll() - - rtmgr.Rtmgr_ready = true - time.Sleep(INTERVAL * time.Second) - xapp.Logger.Debug("Periodic loop timed out. Setting triggerSBI flag to distribute updated routes.") - } + nbiErr := nbiEngine.Initialize(xapp.Config.GetString("xmurl"), xapp.Config.GetString("nbiurl"), xapp.Config.GetString("rtfile"), xapp.Config.GetString("cfgfile"), xapp.Config.GetString("e2murl"), sdlEngine, rpeEngine, &m) + if nbiErr != nil { + xapp.Logger.Error("Failed to initialize nbi due to: " + nbiErr.Error()) + return + } + + err := sbiEngine.Initialize(xapp.Config.GetString("sbiurl")) + if err != nil { + xapp.Logger.Info("Failed to open push socket due to: " + err.Error()) + return + } + defer nbiEngine.Terminate() + defer sbiEngine.Terminate() + + for { + sendRoutesToAll() + + rtmgr.Rtmgr_ready = true + time.Sleep(INTERVAL * time.Second) + xapp.Logger.Debug("Periodic loop timed out. Setting triggerSBI flag to distribute updated routes.") + } } diff --git a/pkg/nbi/httprestful.go b/pkg/nbi/httprestful.go index 555aefc..f505b63 100644 --- a/pkg/nbi/httprestful.go +++ b/pkg/nbi/httprestful.go @@ -58,8 +58,8 @@ import ( type HttpRestful struct { Engine - LaunchRest LaunchRestHandler - RetrieveStartupData RetrieveStartupDataHandler + LaunchRest LaunchRestHandler + RetrieveStartupData RetrieveStartupDataHandler } func NewHttpRestful() *HttpRestful { @@ -135,18 +135,18 @@ func provideXappHandleHandlerImpl(data *models.XappCallbackData) error { return err } else { appdata, err := recvXappCallbackData(data) - if err != nil { + if err != nil { xapp.Logger.Error("cannot get data from rest api dute to: " + err.Error()) - } else if appdata != nil { - xapp.Logger.Debug("Fetching all xApps deployed in xApp Manager through GET operation.") - alldata, err1 := httpGetXApps(xapp.Config.GetString("xmurl")) - if alldata != nil && err1 == nil { - m.Lock() - sdlEngine.WriteXApps(xapp.Config.GetString("rtfile"), alldata) - m.Unlock() + } else if appdata != nil { + xapp.Logger.Debug("Fetching all xApps deployed in xApp Manager through GET operation.") + alldata, err1 := httpGetXApps(xapp.Config.GetString("xmurl")) + if alldata != nil && err1 == nil { + m.Lock() + sdlEngine.WriteXApps(xapp.Config.GetString("rtfile"), alldata) + m.Unlock() return sendRoutesToAll() - } - } + } + } return nil } @@ -163,27 +163,27 @@ func validateXappSubscriptionData(data *models.XappSubscriptionData) error { return err } -func validateE2tData(data *models.E2tData) error { +func validateE2tData(data *models.E2tData) (error, bool) { e2taddress_key := *data.E2TAddress if e2taddress_key == "" { - return fmt.Errorf("E2TAddress is empty!!!") + return fmt.Errorf("E2TAddress is empty!!!"), false } stringSlice := strings.Split(e2taddress_key, ":") if len(stringSlice) == 1 { - return fmt.Errorf("E2T E2TAddress is not a proper format like ip:port, %v", e2taddress_key) + return fmt.Errorf("E2T E2TAddress is not a proper format like ip:port, %v", e2taddress_key), false } _, err := net.LookupIP(stringSlice[0]) if err != nil { - return fmt.Errorf("E2T E2TAddress DNS look up failed, E2TAddress: %v", stringSlice[0]) + return fmt.Errorf("E2T E2TAddress DNS look up failed, E2TAddress: %v", stringSlice[0]), false } if checkValidaE2TAddress(e2taddress_key) { - return fmt.Errorf("E2TAddress already exist!!!, E2TAddress: %v", e2taddress_key) + return fmt.Errorf("E2TAddress already exist!!!, E2TAddress: %v", e2taddress_key), true } - return nil + return nil, false } func validateDeleteE2tData(data *models.E2tDeleteData) error { @@ -222,8 +222,8 @@ func provideXappSubscriptionHandleImpl(data *models.XappSubscriptionData) error xapp.Logger.Error(err.Error()) return err } - xapp.Logger.Debug("received XApp subscription data") - addSubscription(&rtmgr.Subs, data) + xapp.Logger.Debug("received XApp subscription data") + addSubscription(&rtmgr.Subs, data) xapp.Logger.Debug("Endpoints: %v", rtmgr.Eps) return sendRoutesToAll() } @@ -254,8 +254,8 @@ func deleteXappSubscriptionHandleImpl(data *models.XappSubscriptionData) error { return err } - xapp.Logger.Debug("received XApp subscription delete data") - delSubscription(&rtmgr.Subs, data) + xapp.Logger.Debug("received XApp subscription delete data") + delSubscription(&rtmgr.Subs, data) return sendRoutesToAll() } @@ -281,25 +281,29 @@ func updateXappSubscriptionHandleImpl(data *models.XappList, subid uint16) error return err } } - xapp.Logger.Debug("received XApp subscription Merge data") - updateSubscription(&xapplist) + xapp.Logger.Debug("received XApp subscription Merge data") + updateSubscription(&xapplist) return sendRoutesToAll() } func createNewE2tHandleHandlerImpl(data *models.E2tData) error { xapp.Logger.Debug("Invoked createNewE2tHandleHandlerImpl") - err := validateE2tData(data) + err, IsDuplicate := validateE2tData(data) + if IsDuplicate == true { + return sendRoutesToAll() + } + if err != nil { xapp.Logger.Error(err.Error()) return err } //e2taddchan <- data e2data, meiddata, _ := recvNewE2Tdata(data) - xapp.Logger.Debug("received create New E2T data") - m.Lock() - sdlEngine.WriteNewE2TInstance(xapp.Config.GetString("rtfile"), e2data, meiddata) - m.Unlock() - return sendRoutesToAll() + xapp.Logger.Debug("received create New E2T data") + m.Lock() + sdlEngine.WriteNewE2TInstance(xapp.Config.GetString("rtfile"), e2data, meiddata) + m.Unlock() + return sendRoutesToAll() } @@ -328,10 +332,10 @@ func associateRanToE2THandlerImpl(data models.RanE2tMap) error { xapp.Logger.Warn(" Association of RAN to E2T Instance data validation failed: " + err.Error()) return err } - xapp.Logger.Debug("received associate RAN list to E2T instance mapping from E2 Manager") - m.Lock() - sdlEngine.WriteAssRANToE2TInstance(xapp.Config.GetString("rtfile"), data) - m.Unlock() + xapp.Logger.Debug("received associate RAN list to E2T instance mapping from E2 Manager") + m.Lock() + sdlEngine.WriteAssRANToE2TInstance(xapp.Config.GetString("rtfile"), data) + m.Unlock() return sendRoutesToAll() } @@ -343,10 +347,10 @@ func disassociateRanToE2THandlerImpl(data models.RanE2tMap) error { xapp.Logger.Warn(" Disassociation of RAN List from E2T Instance data validation failed: " + err.Error()) return err } - xapp.Logger.Debug("received disassociate RANs from E2T instance") - m.Lock() - sdlEngine.WriteDisAssRANFromE2TInstance(xapp.Config.GetString("rtfile"), data) - m.Unlock() + xapp.Logger.Debug("received disassociate RANs from E2T instance") + m.Lock() + sdlEngine.WriteDisAssRANFromE2TInstance(xapp.Config.GetString("rtfile"), data) + m.Unlock() return sendRoutesToAll() } @@ -359,9 +363,9 @@ func deleteE2tHandleHandlerImpl(data *models.E2tDeleteData) error { xapp.Logger.Error(err.Error()) return err } - m.Lock() - sdlEngine.WriteDeleteE2TInstance(xapp.Config.GetString("rtfile"), data) - m.Unlock() + m.Lock() + sdlEngine.WriteDeleteE2TInstance(xapp.Config.GetString("rtfile"), data) + m.Unlock() return sendRoutesToAll() } @@ -388,7 +392,7 @@ func dumpDebugData() (models.Debuginfo, error) { return response, err } -func launchRest(nbiif *string){ +func launchRest(nbiif *string) { swaggerSpec, err := loads.Embedded(restapi.SwaggerJSON, restapi.FlatSwaggerJSON) if err != nil { //log.Fatalln(err) @@ -416,9 +420,10 @@ func launchRest(nbiif *string){ xapp.Logger.Info("Data received on Http interface") err := provideXappHandleHandlerImpl(params.XappCallbackData) if err != nil { - xapp.Logger.Error("Invalid XApp callback data: " + err.Error()) + xapp.Logger.Error("RoutingManager->AppManager request Failed: " + err.Error()) return handle.NewProvideXappHandleBadRequest() } else { + xapp.Logger.Info("RoutingManager->AppManager request Success") return handle.NewGetHandlesOK() } }) @@ -426,8 +431,10 @@ func launchRest(nbiif *string){ func(params handle.ProvideXappSubscriptionHandleParams) middleware.Responder { err := provideXappSubscriptionHandleImpl(params.XappSubscriptionData) if err != nil { + xapp.Logger.Error("RoutingManager->SubManager Add Request Failed: " + err.Error()) return handle.NewProvideXappSubscriptionHandleBadRequest() } else { + xapp.Logger.Info("RoutingManager->SubManager Add Request Success, subid = %v, requestor = %v", *params.XappSubscriptionData.SubscriptionID, *params.XappSubscriptionData.Address) return handle.NewGetHandlesOK() } }) @@ -435,8 +442,10 @@ func launchRest(nbiif *string){ func(params handle.DeleteXappSubscriptionHandleParams) middleware.Responder { err := deleteXappSubscriptionHandleImpl(params.XappSubscriptionData) if err != nil { + xapp.Logger.Error("RoutingManager->SubManager Delete Request Failed: " + err.Error()) return handle.NewDeleteXappSubscriptionHandleNoContent() } else { + xapp.Logger.Info("RoutingManager->SubManager Delete Request Success, subid = %v, requestor = %v", *params.XappSubscriptionData.SubscriptionID, *params.XappSubscriptionData.Address) return handle.NewGetHandlesOK() } }) @@ -453,8 +462,10 @@ func launchRest(nbiif *string){ func(params handle.CreateNewE2tHandleParams) middleware.Responder { err := createNewE2tHandleHandlerImpl(params.E2tData) if err != nil { + xapp.Logger.Error("RoutingManager->E2Manager AddE2T Request Failed: " + err.Error()) return handle.NewCreateNewE2tHandleBadRequest() } else { + xapp.Logger.Info("RoutingManager->E2Manager AddE2T Request Success, E2T = %v", *params.E2tData.E2TAddress) return handle.NewCreateNewE2tHandleCreated() } }) @@ -463,8 +474,10 @@ func launchRest(nbiif *string){ func(params handle.AssociateRanToE2tHandleParams) middleware.Responder { err := associateRanToE2THandlerImpl(params.RanE2tList) if err != nil { + xapp.Logger.Error("RoutingManager->E2Manager associateRanToE2T Request Failed: " + err.Error()) return handle.NewAssociateRanToE2tHandleBadRequest() } else { + xapp.Logger.Info("RoutingManager->E2Manager associateRanToE2T Request Success, E2T = %v", params.RanE2tList) return handle.NewAssociateRanToE2tHandleCreated() } }) @@ -473,8 +486,10 @@ func launchRest(nbiif *string){ func(params handle.DissociateRanParams) middleware.Responder { err := disassociateRanToE2THandlerImpl(params.DissociateList) if err != nil { + xapp.Logger.Error("RoutingManager->E2Manager DisassociateRanToE2T Request Failed: " + err.Error()) return handle.NewDissociateRanBadRequest() } else { + xapp.Logger.Info("RoutingManager->E2Manager DisiassociateRanToE2T Request Success, E2T = %v", params.DissociateList) return handle.NewDissociateRanCreated() } }) @@ -483,8 +498,10 @@ func launchRest(nbiif *string){ func(params handle.DeleteE2tHandleParams) middleware.Responder { err := deleteE2tHandleHandlerImpl(params.E2tData) if err != nil { + xapp.Logger.Error("RoutingManager->E2Manager DeleteE2T Request Failed: " + err.Error()) return handle.NewDeleteE2tHandleBadRequest() } else { + xapp.Logger.Info("RoutingManager->E2Manager DeleteE2T Request Success, E2T = %v", *params.E2tData.E2TAddress) return handle.NewDeleteE2tHandleCreated() } }) @@ -497,25 +514,25 @@ func launchRest(nbiif *string){ return debug.NewGetDebuginfoOK().WithPayload(&response) } }) - api.HandleAddRmrRouteHandler = handle.AddRmrRouteHandlerFunc( - func(params handle.AddRmrRouteParams) middleware.Responder { - err := adddelrmrroute(params.RoutesList,true) + api.HandleAddRmrRouteHandler = handle.AddRmrRouteHandlerFunc( + func(params handle.AddRmrRouteParams) middleware.Responder { + err := adddelrmrroute(params.RoutesList, true) if err != nil { return handle.NewAddRmrRouteBadRequest() } else { return handle.NewAddRmrRouteCreated() } - }) - api.HandleDelRmrRouteHandler = handle.DelRmrRouteHandlerFunc( - func(params handle.DelRmrRouteParams) middleware.Responder { - err := adddelrmrroute(params.RoutesList,false) + }) + api.HandleDelRmrRouteHandler = handle.DelRmrRouteHandlerFunc( + func(params handle.DelRmrRouteParams) middleware.Responder { + err := adddelrmrroute(params.RoutesList, false) if err != nil { return handle.NewDelRmrRouteBadRequest() } else { return handle.NewDelRmrRouteCreated() } - }) + }) // start to serve API xapp.Logger.Info("Starting the HTTP Rest service") @@ -662,18 +679,18 @@ func retrieveStartupData(xmurl string, nbiif string, fileName string, configfile xapp.Logger.Info("Trying to fetch Subscriptions data from Subscription manager") for i := 1; i <= maxRetries; i++ { - readErr = nil - sub_list, err := xapp.Subscription.QuerySubscriptions() + readErr = nil + sub_list, err := xapp.Subscription.QuerySubscriptions() - if sub_list != nil && err == nil { - PopulateSubscription(sub_list) - break - } else { - readErr = err - xapp.Logger.Warn("cannot get xapp data due to: " + readErr.Error()) - } - time.Sleep(2 * time.Second) + if sub_list != nil && err == nil { + PopulateSubscription(sub_list) + break + } else { + readErr = err + xapp.Logger.Warn("cannot get xapp data due to: " + readErr.Error()) } + time.Sleep(2 * time.Second) + } if readErr != nil { return readErr @@ -687,17 +704,17 @@ func retrieveStartupData(xmurl string, nbiif string, fileName string, configfile //rlist := make(map[string]string) xapp.Logger.Info("Reading SDL for any routes") - rlist,sdlerr := xapp.Sdl.Read("routes") + rlist, sdlerr := xapp.Sdl.Read("routes") readErr = sdlerr if readErr == nil { - xapp.Logger.Info("Value is %s",rlist["routes"]) + xapp.Logger.Info("Value is %s", rlist["routes"]) if rlist["routes"] != nil { - formstring := fmt.Sprintf("%s",rlist["routes"]) - xapp.Logger.Info("Value of formed string = %s",formstring) - newstring := strings.Split(formstring," ") - for i,_ := range newstring { - xapp.Logger.Info("in Loop Value of formed string = %s",newstring) - rtmgr.DynamicRouteList = append(rtmgr.DynamicRouteList,newstring[i]) + formstring := fmt.Sprintf("%s", rlist["routes"]) + xapp.Logger.Info("Value of formed string = %s", formstring) + newstring := strings.Split(formstring, " ") + for i, _ := range newstring { + xapp.Logger.Info("in Loop Value of formed string = %s", newstring) + rtmgr.DynamicRouteList = append(rtmgr.DynamicRouteList, newstring[i]) } } @@ -815,10 +832,10 @@ func PopulateSubscription(sub_list xfmodel.SubscriptionList) { } } -func adddelrmrroute(routelist models.Routelist,rtflag bool) error { - xapp.Logger.Info("Updating rmrroute with Route list: %v,flag: %v", routelist,rtflag) +func adddelrmrroute(routelist models.Routelist, rtflag bool) error { + xapp.Logger.Info("Updating rmrroute with Route list: %v,flag: %v", routelist, rtflag) for _, rlist := range routelist { - var subid int32 + var subid int32 var data string if rlist.SubscriptionID == 0 { subid = -1 @@ -826,28 +843,28 @@ func adddelrmrroute(routelist models.Routelist,rtflag bool) error { subid = rlist.SubscriptionID } if rlist.SenderEndPoint == "" && rlist.SubscriptionID != 0 { - data = fmt.Sprintf("mse|%d|%d|%s\n",*rlist.MessageType,rlist.SubscriptionID,*rlist.TargetEndPoint) + data = fmt.Sprintf("mse|%d|%d|%s\n", *rlist.MessageType, rlist.SubscriptionID, *rlist.TargetEndPoint) } else if rlist.SenderEndPoint == "" && rlist.SubscriptionID == 0 { - data = fmt.Sprintf("mse|%d|-1|%s\n",*rlist.MessageType,*rlist.TargetEndPoint) + data = fmt.Sprintf("mse|%d|-1|%s\n", *rlist.MessageType, *rlist.TargetEndPoint) } else { - data = fmt.Sprintf("mse|%d,%s|%d|%s\n",*rlist.MessageType,rlist.SenderEndPoint,subid,*rlist.TargetEndPoint) + data = fmt.Sprintf("mse|%d,%s|%d|%s\n", *rlist.MessageType, rlist.SenderEndPoint, subid, *rlist.TargetEndPoint) } err := checkrepeatedroute(data) if rtflag == true { if err == true { - xapp.Logger.Info("Given route %s is a duplicate",data) + xapp.Logger.Info("Given route %s is a duplicate", data) } - rtmgr.DynamicRouteList = append(rtmgr.DynamicRouteList,data) - routearray := strings.Join(rtmgr.DynamicRouteList," ") - xapp.Sdl.Store("routes",routearray) + rtmgr.DynamicRouteList = append(rtmgr.DynamicRouteList, data) + routearray := strings.Join(rtmgr.DynamicRouteList, " ") + xapp.Sdl.Store("routes", routearray) } else { if err == true { - xapp.Logger.Info("Successfully deleted route: %s",data) - routearray := strings.Join(rtmgr.DynamicRouteList," ") - xapp.Sdl.Store("routes",routearray) - }else { - xapp.Logger.Info("No such route: %s",data) + xapp.Logger.Info("Successfully deleted route: %s", data) + routearray := strings.Join(rtmgr.DynamicRouteList, " ") + xapp.Sdl.Store("routes", routearray) + } else { + xapp.Logger.Info("No such route: %s", data) return errors.New("No such route: " + data) } @@ -856,8 +873,8 @@ func adddelrmrroute(routelist models.Routelist,rtflag bool) error { return sendRoutesToAll() } -func checkrepeatedroute (data string) bool { - for i:=0;i