Refactoring some code

Signed-off-by: wahidw <abdulwahid.w@nokia.com>
Change-Id: Ib99a659498a17a4093926918e26b7694f0f2ff54
diff --git a/RELNOTES b/RELNOTES
index 9e7ed4d..28a9cb6 100644
--- a/RELNOTES
+++ b/RELNOTES
@@ -1,3 +1,6 @@
+### v0.7.8
+* Refactoring rtmgr code 
+
 ### v0.7.7
 * go.mod updated from 1.12 go version to 1.13
 
diff --git a/cmd/rtmgr.go b/cmd/rtmgr.go
index 2d3d81e..834df26 100644
--- a/cmd/rtmgr.go
+++ b/cmd/rtmgr.go
@@ -32,31 +32,19 @@
 */
 package main
 
-//TODO: change flag to pflag (won't need any argument parse)
-
 import (
 	"gerrit.o-ran-sc.org/r/ric-plt/xapp-frame/pkg/xapp"
 	"os"
 	"os/signal"
 	"routing-manager/pkg/nbi"
-	//"routing-manager/pkg/rpe"
+	"routing-manager/pkg/nbi/restful"
 	"routing-manager/pkg/rtmgr"
-	//"routing-manager/pkg/sbi"
-	//"routing-manager/pkg/sdl"
 	"syscall"
 	"time"
 )
 
 const SERVICENAME = "rtmgr"
 
-/*type RMRUpdateType int
-
-const (
-	XappType = iota
-	SubsType
-	E2Type
-)*/
-
 func SetupCloseHandler() {
 	c := make(chan os.Signal, 2)
 	signal.Notify(c, os.Interrupt, syscall.SIGTERM)
@@ -90,6 +78,10 @@
 	dummy_whid := int(xapp.Rmr.Openwh("rtmgr:4560"))
 	xapp.Logger.Info("created dummy Wormhole ID for routingmanager and dummy_whid :%d", dummy_whid)
 
+	go func() {
+		restful.LaunchRest(xapp.Config.GetString("nbiurl"))
+	}()
+
 	nbi.Serve()
 	os.Exit(0)
 }
diff --git a/container-tag.yaml b/container-tag.yaml
index 1090f9b..6ce4ec2 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.7
+tag: 0.7.8
diff --git a/pkg/nbi/control.go b/pkg/nbi/control.go
index 2ed63d8..91f2475 100644
--- a/pkg/nbi/control.go
+++ b/pkg/nbi/control.go
@@ -74,7 +74,7 @@
 }
 
 func (c *Control) SymptomDataHandler(w http.ResponseWriter, r *http.Request) {
-	resp, _ := dumpDebugData()
+	resp, _ := DumpDebugData()
 	xapp.Resource.SendSymptomDataJson(w, r, resp, "platform/rttable.json")
 }
 
diff --git a/pkg/nbi/httprestful.go b/pkg/nbi/httprestful.go
index 60d65fb..9222e0b 100644
--- a/pkg/nbi/httprestful.go
+++ b/pkg/nbi/httprestful.go
@@ -37,16 +37,16 @@
 	"fmt"
 	xfmodel "gerrit.o-ran-sc.org/r/ric-plt/xapp-frame/pkg/models"
 	"gerrit.o-ran-sc.org/r/ric-plt/xapp-frame/pkg/xapp"
-	"github.com/go-openapi/loads"
-	"github.com/go-openapi/runtime/middleware"
+	//"github.com/go-openapi/loads"
+	//"github.com/go-openapi/runtime/middleware"
 	"net"
-	"net/url"
-	"os"
+	//"net/url"
+	//"os"
 	"routing-manager/pkg/models"
-	"routing-manager/pkg/restapi"
-	"routing-manager/pkg/restapi/operations"
-	"routing-manager/pkg/restapi/operations/debug"
-	"routing-manager/pkg/restapi/operations/handle"
+	//"routing-manager/pkg/restapi"
+	//"routing-manager/pkg/restapi/operations"
+	//"routing-manager/pkg/restapi/operations/debug"
+	//"routing-manager/pkg/restapi/operations/handle"
 	"routing-manager/pkg/rpe"
 	"routing-manager/pkg/rtmgr"
 	"routing-manager/pkg/sdl"
@@ -58,13 +58,13 @@
 
 type HttpRestful struct {
 	Engine
-	LaunchRest          LaunchRestHandler
+	//LaunchRest          LaunchRestHandler
 	RetrieveStartupData RetrieveStartupDataHandler
 }
 
 func NewHttpRestful() *HttpRestful {
 	instance := new(HttpRestful)
-	instance.LaunchRest = launchRest
+	//instance.LaunchRest = launchRest
 	instance.RetrieveStartupData = retrieveStartupData
 	return instance
 }
@@ -124,7 +124,7 @@
 	return nil
 }
 
-func provideXappHandleHandlerImpl(data *models.XappCallbackData) error {
+func ProvideXappHandleHandlerImpl(data *models.XappCallbackData) error {
 	if data == nil {
 		xapp.Logger.Debug("Received callback data")
 		return nil
@@ -217,7 +217,7 @@
 
 }
 
-func provideXappSubscriptionHandleImpl(data *models.XappSubscriptionData) error {
+func ProvideXappSubscriptionHandleImpl(data *models.XappSubscriptionData) error {
 	xapp.Logger.Debug("Invoked provideXappSubscriptionHandleImpl")
 	err := validateXappSubscriptionData(data)
 	if err != nil {
@@ -243,7 +243,7 @@
 	return present
 }
 
-func deleteXappSubscriptionHandleImpl(data *models.XappSubscriptionData) error {
+func DeleteXappSubscriptionHandleImpl(data *models.XappSubscriptionData) error {
 	xapp.Logger.Debug("Invoked deleteXappSubscriptionHandleImpl")
 	err := validateXappSubscriptionData(data)
 	if err != nil {
@@ -264,7 +264,7 @@
 
 }
 
-func updateXappSubscriptionHandleImpl(data *models.XappList, subid uint16) error {
+func UpdateXappSubscriptionHandleImpl(data *models.XappList, subid uint16) error {
 	xapp.Logger.Debug("Invoked updateXappSubscriptionHandleImpl")
 
 	var fqdnlist []rtmgr.FqDn
@@ -291,7 +291,7 @@
 	return sendRoutesToAll()
 }
 
-func createNewE2tHandleHandlerImpl(data *models.E2tData) error {
+func CreateNewE2tHandleHandlerImpl(data *models.E2tData) error {
 	xapp.Logger.Debug("Invoked createNewE2tHandleHandlerImpl")
 	err, IsDuplicate := validateE2tData(data)
 	if IsDuplicate == true {
@@ -342,7 +342,7 @@
 	return nil
 }
 
-func associateRanToE2THandlerImpl(data models.RanE2tMap) error {
+func AssociateRanToE2THandlerImpl(data models.RanE2tMap) error {
 	xapp.Logger.Debug("Invoked associateRanToE2THandlerImpl")
 	err := validateE2TAddressRANListData(data)
 	if err != nil {
@@ -358,7 +358,7 @@
 
 }
 
-func disassociateRanToE2THandlerImpl(data models.RanE2tMap) error {
+func DisassociateRanToE2THandlerImpl(data models.RanE2tMap) error {
 	xapp.Logger.Debug("Invoked disassociateRanToE2THandlerImpl")
 	err := validateE2TAddressRANListData(data)
 	if err != nil {
@@ -374,7 +374,7 @@
 
 }
 
-func deleteE2tHandleHandlerImpl(data *models.E2tDeleteData) error {
+func DeleteE2tHandleHandlerImpl(data *models.E2tDeleteData) error {
 	xapp.Logger.Debug("Invoked deleteE2tHandleHandlerImpl")
 
 	err := validateDeleteE2tData(data)
@@ -390,7 +390,7 @@
 
 }
 
-func dumpDebugData() (models.Debuginfo, error) {
+func DumpDebugData() (models.Debuginfo, error) {
 	var response models.Debuginfo
 	sdlEngine, _ := sdl.GetSdl("file")
 	rpeEngine, _ := rpe.GetRpe("rmrpush")
@@ -412,155 +412,6 @@
 	return response, err
 }
 
-func launchRest(nbiif *string) {
-	swaggerSpec, err := loads.Embedded(restapi.SwaggerJSON, restapi.FlatSwaggerJSON)
-	if err != nil {
-		//log.Fatalln(err)
-		xapp.Logger.Error(err.Error())
-		os.Exit(1)
-	}
-	nbiUrl, err := url.Parse(*nbiif)
-	if err != nil {
-		xapp.Logger.Error(err.Error())
-		os.Exit(1)
-	}
-	api := operations.NewRoutingManagerAPI(swaggerSpec)
-	server := restapi.NewServer(api)
-	defer server.Shutdown()
-
-	server.Port, err = strconv.Atoi(nbiUrl.Port())
-	if err != nil {
-		xapp.Logger.Error("Invalid NBI RestAPI port")
-		os.Exit(1)
-	}
-	server.Host = "0.0.0.0"
-	// set handlers
-	api.HandleProvideXappHandleHandler = handle.ProvideXappHandleHandlerFunc(
-		func(params handle.ProvideXappHandleParams) middleware.Responder {
-			xapp.Logger.Info("Data received on Http interface")
-			err := provideXappHandleHandlerImpl(params.XappCallbackData)
-			if err != nil {
-				xapp.Logger.Error("RoutingManager->AppManager request Failed: " + err.Error())
-				return handle.NewProvideXappHandleBadRequest()
-			} else {
-				xapp.Logger.Info("RoutingManager->AppManager request Success")
-				return handle.NewGetHandlesOK()
-			}
-		})
-	api.HandleProvideXappSubscriptionHandleHandler = handle.ProvideXappSubscriptionHandleHandlerFunc(
-		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()
-			}
-		})
-	api.HandleDeleteXappSubscriptionHandleHandler = handle.DeleteXappSubscriptionHandleHandlerFunc(
-		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()
-			}
-		})
-	api.HandleUpdateXappSubscriptionHandleHandler = handle.UpdateXappSubscriptionHandleHandlerFunc(
-		func(params handle.UpdateXappSubscriptionHandleParams) middleware.Responder {
-			err := updateXappSubscriptionHandleImpl(&params.XappList, params.SubscriptionID)
-			if err != nil {
-				return handle.NewUpdateXappSubscriptionHandleBadRequest()
-			} else {
-				return handle.NewUpdateXappSubscriptionHandleCreated()
-			}
-		})
-	api.HandleCreateNewE2tHandleHandler = handle.CreateNewE2tHandleHandlerFunc(
-		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()
-			}
-		})
-
-	api.HandleAssociateRanToE2tHandleHandler = handle.AssociateRanToE2tHandleHandlerFunc(
-		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()
-			}
-		})
-
-	api.HandleDissociateRanHandler = handle.DissociateRanHandlerFunc(
-		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 DisassociateRanToE2T Request Success, E2T = %v", params.DissociateList)
-				return handle.NewDissociateRanCreated()
-			}
-		})
-
-	api.HandleDeleteE2tHandleHandler = handle.DeleteE2tHandleHandlerFunc(
-		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()
-			}
-		})
-	api.DebugGetDebuginfoHandler = debug.GetDebuginfoHandlerFunc(
-		func(params debug.GetDebuginfoParams) middleware.Responder {
-			response, err := dumpDebugData()
-			if err != nil {
-				return debug.NewGetDebuginfoCreated()
-			} else {
-				return debug.NewGetDebuginfoOK().WithPayload(&response)
-			}
-		})
-	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)
-			if err != nil {
-				return handle.NewDelRmrRouteBadRequest()
-			} else {
-				return handle.NewDelRmrRouteCreated()
-			}
-		})
-
-	// start to serve API
-	xapp.Logger.Info("Starting the HTTP Rest service")
-	if err := server.Serve(); err != nil {
-		xapp.Logger.Error(err.Error())
-	}
-}
-
 func httpGetXApps(xmurl string) (*[]rtmgr.XApp, error) {
 	xapp.Logger.Info("Invoked httprestful.httpGetXApps: " + xmurl)
 	r, err := myClient.Get(xmurl)
@@ -751,9 +602,6 @@
 		xapp.Logger.Error("Exiting as nbi failed to get the initial startup data from the xapp manager: " + err.Error())
 		return err
 	}
-	go func() {
-		r.LaunchRest(&nbiif)
-	}()
 
 	return nil
 }
@@ -852,7 +700,7 @@
 	}
 }
 
-func adddelrmrroute(routelist models.Routelist, rtflag bool) error {
+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
diff --git a/pkg/nbi/httprestful_test.go b/pkg/nbi/httprestful_test.go
index 13a90ea..16ffb38 100644
--- a/pkg/nbi/httprestful_test.go
+++ b/pkg/nbi/httprestful_test.go
@@ -141,7 +141,7 @@
 	/*err = validateE2tData(&data2)*/
 
 	//e2tchannel := make(chan *models.E2tData, 10)
-	_ = createNewE2tHandleHandlerImpl(&data2)
+	_ = CreateNewE2tHandleHandlerImpl(&data2)
 	//defer close(e2tchannel)
 
 	//test case for provideXappSubscriptionHandleImp
@@ -149,23 +149,23 @@
 	sdlEngine, _ = sdl.GetSdl("file")
 	sbiEngine, _ = sbi.GetSbi("rmrpush")
 	rpeEngine, _ = rpe.GetRpe("rmrpush")
-	_ = provideXappSubscriptionHandleImpl(&data1)
+	_ = ProvideXappSubscriptionHandleImpl(&data1)
 	//defer close(datachannel)
 
 	//test case for deleteXappSubscriptionHandleImpl
-	_ = deleteXappSubscriptionHandleImpl(&data1)
+	_ = DeleteXappSubscriptionHandleImpl(&data1)
 
 	data3 := models.XappSubscriptionData{
 		Address:        swag.String("10.55.55.5"),
 		Port:           &p,
 		SubscriptionID: swag.Int32(123456)}
 	//test case for deleteXappSubscriptionHandleImpl
-	_ = deleteXappSubscriptionHandleImpl(&data3)
+	_ = DeleteXappSubscriptionHandleImpl(&data3)
 	data4 := models.XappSubscriptionData{
 		Address:        swag.String("1.5.5.5"),
 		Port:           &p,
 		SubscriptionID: swag.Int32(1236)}
-	_ = deleteXappSubscriptionHandleImpl(&data4)
+	_ = DeleteXappSubscriptionHandleImpl(&data4)
 
 }
 
@@ -204,7 +204,7 @@
 	err, _ := validateE2tData(&data)
 	t.Log(err)
 
-	_ = createNewE2tHandleHandlerImpl(&data)
+	_ = CreateNewE2tHandleHandlerImpl(&data)
 
 }
 
@@ -357,7 +357,7 @@
 			E2TAddress: swag.String("10.101.01.1:8098"),
 		},
 	}
-	err := associateRanToE2THandlerImpl(data)
+	err := AssociateRanToE2THandlerImpl(data)
 	if err != nil {
 		t.Log(err)
 	}
@@ -375,7 +375,7 @@
 			E2TAddress: swag.String("10.101.01.1:8098"),
 		},
 	}
-	err = associateRanToE2THandlerImpl(data)
+	err = AssociateRanToE2THandlerImpl(data)
 	if err != nil {
 		t.Log(err)
 	}
@@ -392,7 +392,7 @@
 			E2TAddress: swag.String("10.101.01.1:8098"),
 		},
 	}
-	err := disassociateRanToE2THandlerImpl(data)
+	err := DisassociateRanToE2THandlerImpl(data)
 	if err != nil {
 		t.Log(err)
 	}
@@ -409,7 +409,7 @@
 			E2TAddress: swag.String("10.101.01.1:8098"),
 		},
 	}
-	err = disassociateRanToE2THandlerImpl(data)
+	err = DisassociateRanToE2THandlerImpl(data)
 	if err != nil {
 		t.Log(err)
 	}
@@ -424,7 +424,7 @@
 	data := models.E2tDeleteData{
 		E2TAddress: swag.String(""),
 	}
-	err := deleteE2tHandleHandlerImpl(&data)
+	err := DeleteE2tHandleHandlerImpl(&data)
 	if err != nil {
 		t.Log(err)
 	}
@@ -440,7 +440,7 @@
 	data = models.E2tDeleteData{
 		E2TAddress: swag.String("10.101.01.1:8098"),
 	}
-	err = deleteE2tHandleHandlerImpl(&data)
+	err = DeleteE2tHandleHandlerImpl(&data)
 	if err != nil {
 		t.Log(err)
 	}
@@ -527,7 +527,7 @@
 		Address:        swag.String("10.0.0.0"),
 		Port:           &p,
 		SubscriptionID: swag.Int32(1234)}
-	_ = provideXappSubscriptionHandleImpl(&data)
+	_ = ProvideXappSubscriptionHandleImpl(&data)
 }
 
 func createMockAppmgrWithData(url string, g []byte, p []byte, t []byte) *httptest.Server {
@@ -592,11 +592,11 @@
 		Version: *swag.Int64(1),
 		Event:   *swag.String("someevent"),
 		ID:      *swag.String("123456")}
-	err := provideXappHandleHandlerImpl(&data)
+	err := ProvideXappHandleHandlerImpl(&data)
 
 	//Empty XappCallbackdata
 	data1 := models.XappCallbackData{}
-	err = provideXappHandleHandlerImpl(&data1)
+	err = ProvideXappHandleHandlerImpl(&data1)
 	t.Log(err)
 }
 
@@ -723,7 +723,7 @@
 
 	var b models.XappList
 	b = append(b, &xapp)
-	_ = updateXappSubscriptionHandleImpl(&b, 10)
+	_ = UpdateXappSubscriptionHandleImpl(&b, 10)
 
 	//Test case when subscriptions already exist
 	data := models.XappSubscriptionData{
@@ -735,12 +735,12 @@
 
 	subscriptionExists(&data)
 	addSubscription(&rtmgr.Subs, &data)
-	_ = updateXappSubscriptionHandleImpl(&b, 10)
+	_ = UpdateXappSubscriptionHandleImpl(&b, 10)
 
 }
 
 func TestDumpDebugdata(t *testing.T) {
-	_, _ = dumpDebugData()
+	_, _ = DumpDebugData()
 }
 
 func TestManagerRequest(t *testing.T) {
@@ -798,14 +798,14 @@
 	listofroutes := models.AddRmrRoute{SubscriptionID: 0, SenderEndPoint: "nokia.com", MessageType: &mtype, TargetEndPoint: &tendpoint}
 	listofroutes2 := models.AddRmrRoute{SubscriptionID: 1, SenderEndPoint: "", MessageType: &mtype, TargetEndPoint: &tendpoint}
 	listofroutes3 := models.AddRmrRoute{MessageType: &mtype, TargetEndPoint: &tendpoint}
-	adddelrmrroute(routelist, false)
+	Adddelrmrroute(routelist, false)
 	routelist = append(routelist, &listofroutes)
 	routelist = append(routelist, &listofroutes2)
 	routelist = append(routelist, &listofroutes3)
 	routelist = append(routelist, &listofroutes3)
-	adddelrmrroute(routelist, true)
+	Adddelrmrroute(routelist, true)
 
-	adddelrmrroute(routelist, false)
+	Adddelrmrroute(routelist, false)
 }
 
 func TestPopulateSubscription(t *testing.T) {
diff --git a/pkg/nbi/restful/restful.go b/pkg/nbi/restful/restful.go
new file mode 100644
index 0000000..764a143
--- /dev/null
+++ b/pkg/nbi/restful/restful.go
@@ -0,0 +1,164 @@
+package restful
+
+import (
+        "gerrit.o-ran-sc.org/r/ric-plt/xapp-frame/pkg/xapp"
+        "github.com/go-openapi/loads"
+        "github.com/go-openapi/runtime/middleware"
+        "net/url"
+        "os"
+        "routing-manager/pkg/nbi"
+        "routing-manager/pkg/restapi"
+        "routing-manager/pkg/restapi/operations"
+        "routing-manager/pkg/restapi/operations/debug"
+        "routing-manager/pkg/restapi/operations/handle"
+        "strconv"
+)
+
+func LaunchRest(nbiif string) {
+    swaggerSpec, err := loads.Embedded(restapi.SwaggerJSON, restapi.FlatSwaggerJSON)
+    if err != nil {
+        //log.Fatalln(err)
+        xapp.Logger.Error(err.Error())
+        os.Exit(1)
+    }
+    nbiUrl, err := url.Parse(nbiif)
+    if err != nil {
+        xapp.Logger.Error(err.Error())
+        os.Exit(1)
+    }
+    api := operations.NewRoutingManagerAPI(swaggerSpec)
+    server := restapi.NewServer(api)
+    defer server.Shutdown()
+
+    server.Port, err = strconv.Atoi(nbiUrl.Port())
+    if err != nil {
+        xapp.Logger.Error("Invalid NBI RestAPI port")
+        os.Exit(1)
+    }
+    server.Host = "0.0.0.0"
+   // set handlers
+    api.HandleProvideXappHandleHandler = handle.ProvideXappHandleHandlerFunc(
+        func(params handle.ProvideXappHandleParams) middleware.Responder {
+            xapp.Logger.Info("Data received on Http interface")
+            err := nbi.ProvideXappHandleHandlerImpl(params.XappCallbackData)
+            if err != nil {
+                xapp.Logger.Error("RoutingManager->AppManager request Failed: " + err.Error())
+                return handle.NewProvideXappHandleBadRequest()
+            } else {
+                xapp.Logger.Info("RoutingManager->AppManager request Success")
+                return handle.NewGetHandlesOK()
+            }
+        })
+    api.HandleProvideXappSubscriptionHandleHandler = handle.ProvideXappSubscriptionHandleHandlerFunc(
+        func(params handle.ProvideXappSubscriptionHandleParams) middleware.Responder {
+            err := nbi.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()
+            }
+        })
+    api.HandleDeleteXappSubscriptionHandleHandler = handle.DeleteXappSubscriptionHandleHandlerFunc(
+        func(params handle.DeleteXappSubscriptionHandleParams) middleware.Responder {
+            err := nbi.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()
+            }
+        })
+    api.HandleUpdateXappSubscriptionHandleHandler = handle.UpdateXappSubscriptionHandleHandlerFunc(
+        func(params handle.UpdateXappSubscriptionHandleParams) middleware.Responder {
+            err := nbi.UpdateXappSubscriptionHandleImpl(&params.XappList, params.SubscriptionID)
+            if err != nil {
+                return handle.NewUpdateXappSubscriptionHandleBadRequest()
+            } else {
+                return handle.NewUpdateXappSubscriptionHandleCreated()
+            }
+        })
+    api.HandleCreateNewE2tHandleHandler = handle.CreateNewE2tHandleHandlerFunc(
+        func(params handle.CreateNewE2tHandleParams) middleware.Responder {
+            err := nbi.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()
+            }
+        })
+
+    api.HandleAssociateRanToE2tHandleHandler = handle.AssociateRanToE2tHandleHandlerFunc(
+        func(params handle.AssociateRanToE2tHandleParams) middleware.Responder {
+            err := nbi.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()
+            }
+        })
+
+    api.HandleDissociateRanHandler = handle.DissociateRanHandlerFunc(
+        func(params handle.DissociateRanParams) middleware.Responder {
+            err := nbi.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 DisassociateRanToE2T Request Success, E2T = %v", params.DissociateList)
+                return handle.NewDissociateRanCreated()
+            }
+        })
+   api.HandleDeleteE2tHandleHandler = handle.DeleteE2tHandleHandlerFunc(
+        func(params handle.DeleteE2tHandleParams) middleware.Responder {
+            err := nbi.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()
+            }
+        })
+    api.DebugGetDebuginfoHandler = debug.GetDebuginfoHandlerFunc(
+        func(params debug.GetDebuginfoParams) middleware.Responder {
+            response, err := nbi.DumpDebugData()
+            if err != nil {
+                return debug.NewGetDebuginfoCreated()
+            } else {
+                return debug.NewGetDebuginfoOK().WithPayload(&response)
+            }
+        })
+    api.HandleAddRmrRouteHandler = handle.AddRmrRouteHandlerFunc(
+        func(params handle.AddRmrRouteParams) middleware.Responder {
+            err := nbi.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 := nbi.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")
+    if err := server.Serve(); err != nil {
+        xapp.Logger.Error(err.Error())
+    }
+}
+
diff --git a/pkg/nbi/types.go b/pkg/nbi/types.go
index 722289e..8625d1c 100644
--- a/pkg/nbi/types.go
+++ b/pkg/nbi/types.go
@@ -41,7 +41,8 @@
 type RecvXappCallbackDataHandler func(<-chan *models.XappCallbackData) (*[]rtmgr.XApp, error)
 type RecvNewE2TdataHandler func(<-chan *models.E2tData) (*rtmgr.E2TInstance, string, error)
 type LaunchRestHandler func(*string)
-type ProvideXappHandleHandlerImpl func(chan<- *models.XappCallbackData, *models.XappCallbackData) error
+
+//type ProvideXappHandleHandlerImpl func(chan<- *models.XappCallbackData, *models.XappCallbackData) error
 type RetrieveStartupDataHandler func(string, string, string, string, string, sdl.Engine) error
 
 type EngineConfig struct {