Reverting the code after releasing the image

Change-Id: Ie8c567f805ccb3dc404d512b0a891f38c11d772d
Signed-off-by: wahidw <abdulwahid.w@nokia.com>
diff --git a/cmd/rtmgr.go b/cmd/rtmgr.go
index 2bb7f8d..63b67b7 100644
--- a/cmd/rtmgr.go
+++ b/cmd/rtmgr.go
@@ -64,6 +64,8 @@
 	return nil, nil, nil, nil, err
 }
 
+
+
 func serveSBI(triggerSBI <-chan bool, sbiEngine sbi.Engine, sdlEngine sdl.Engine, rpeEngine rpe.Engine, m *sync.Mutex) {
 	for {
 		if <-triggerSBI {
@@ -84,6 +86,23 @@
 	}
 }
 
+func sendRoutesToAll(sbiEngine sbi.Engine, sdlEngine sdl.Engine, rpeEngine rpe.Engine) {
+
+	data, err := sdlEngine.ReadAll(xapp.Config.GetString("rtfile"))
+	if err != nil || data == nil {
+		xapp.Logger.Error("Cannot get data from sdl interface due to: " + err.Error())
+		return
+	}
+	sbiEngine.UpdateEndpoints(data)
+	policies := rpeEngine.GeneratePolicies(rtmgr.Eps, data)
+	err = sbiEngine.DistributeAll(policies)
+	if err != nil {
+		xapp.Logger.Error("Routing table cannot be published due to: " + err.Error())
+		return
+	}
+}
+
+
 func serve(nbiEngine nbi.Engine, sbiEngine sbi.Engine, sdlEngine sdl.Engine, rpeEngine rpe.Engine, m *sync.Mutex) {
 
 	triggerSBI := make(chan bool)
@@ -116,8 +135,9 @@
 			}
 		}
 
-		triggerSBI <- true
+		sendRoutesToAll(sbiEngine, sdlEngine, rpeEngine)
 
+		rtmgr.Rtmgr_ready = true
 		time.Sleep(INTERVAL * time.Second)
 		xapp.Logger.Debug("Periodic loop timed out. Setting triggerSBI flag to distribute updated routes.")
 	}
@@ -134,19 +154,33 @@
 }
 
 func main() {
+
 	nbiEngine, sbiEngine, sdlEngine, rpeEngine, err := initRtmgr()
 	if err != nil {
 		xapp.Logger.Error(err.Error())
 		os.Exit(1)
 	}
+
 	SetupCloseHandler()
+
 	xapp.Logger.Info("Start " + SERVICENAME + " service")
 	rtmgr.Eps = make(rtmgr.Endpoints)
+	rtmgr.Rtmgr_ready = false
 
 	var m sync.Mutex
 
-	c := sbi.NewControl()
-	go c.Run()
+// RMR thread is starting port: 4560
+	c := nbi.NewControl()
+	go c.Run(sbiEngine, sdlEngine, rpeEngine, &m)
+
+// Waiting for RMR to be ready
+	time.Sleep(time.Duration(2) * time.Second)
+	for xapp.Rmr.IsReady() == false {
+	        time.Sleep(time.Duration(2) * time.Second)
+	}
+
+	dummy_whid := int(xapp.Rmr.Openwh("localhost:4560"))
+	xapp.Logger.Info("created dummy Wormhole ID for routingmanager and dummy_whid :%d", dummy_whid)
 
 	serve(nbiEngine, sbiEngine, sdlEngine, rpeEngine, &m)
 	os.Exit(0)