Publish Route only once to the endpoint that requests it. Periodic/Event based distri...
[ric-plt/rtmgr.git] / pkg / nbi / control.go
index 5cde1b0..db6c405 100644 (file)
@@ -77,7 +77,6 @@ func initRtmgr() (nbiEngine Engine, sbiEngine sbi.Engine, sdlEngine sdl.Engine,
                 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 {
-       fmt.Printf("%v,%v,%v,%v",nbiEngine, sbiEngine, sdlEngine, rpeEngine)
                                         return nbiEngine, sbiEngine, sdlEngine, rpeEngine, nil
                                 }
                         }
@@ -145,14 +144,22 @@ func (c *Control) handleUpdateToRoutingManagerRequest(params *xapp.RMRParams) {
                return
        }
 
-       ep := sbiEngine.CreateEndpoint(string(params.Payload))
+       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())
+       if epstr == nil || whid < 0 {
+               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)
        policies := rpeEngine.GeneratePolicies(rtmgr.Eps, data)
-       err = sbiEngine.DistributeToEp(policies, ep)
+       err = sbiEngine.DistributeToEp(policies, *epstr, whid)
        if err != nil {
                xapp.Logger.Error("Routing table cannot be published due to: " + err.Error())
                return