SVC address support for rmr stubs.

Have seen that if used may cause netlink errno 9. Maybe
due we have several rmr instances inside one procedure?

Change-Id: Ia52ae40bc05592179e3fc9143cd6c398af46adba
Signed-off-by: Juha Hyttinen <juha.hyttinen@nokia.com>
diff --git a/Dockerfile b/Dockerfile
index 34f5252..71d2130 100644
--- a/Dockerfile
+++ b/Dockerfile
@@ -170,6 +170,9 @@
 COPY test/uta_rtg.rt test/uta_rtg.rt
 ENV RMR_SEED_RT=/opt/submgr/test/uta_rtg.rt 
 
+#ENV CGO_LDFLAGS="-fsanitize=address"
+#ENV CGO_CFLAGS="-fsanitize=address"
+
 RUN go test -test.coverprofile /tmp/submgr_cover.out -count=1 -v ./pkg/control 
 RUN go tool cover -html=/tmp/submgr_cover.out -o /tmp/submgr_cover.html
 
diff --git a/pkg/control/ut_ctrl_submgr_test.go b/pkg/control/ut_ctrl_submgr_test.go
index 9fb852a..3a57177 100644
--- a/pkg/control/ut_ctrl_submgr_test.go
+++ b/pkg/control/ut_ctrl_submgr_test.go
@@ -34,9 +34,9 @@
 	c *Control
 }
 
-func createSubmgrControl(rtfile string, port string) *testingSubmgrControl {
+func createSubmgrControl(rtfile string, port uint16, rtport uint16) *testingSubmgrControl {
 	mainCtrl = &testingSubmgrControl{}
-	mainCtrl.RmrControl.Init("SUBMGRCTL", rtfile, port)
+	mainCtrl.RmrControl.Init("SUBMGRCTL", rtfile, port, rtport)
 	mainCtrl.c = NewControl()
 	xapp.SetReadyCB(mainCtrl.ReadyCB, nil)
 	go xapp.RunWithParams(mainCtrl.c, false)
diff --git a/pkg/control/ut_test.go b/pkg/control/ut_test.go
index 7d27412..05d34b8 100644
--- a/pkg/control/ut_test.go
+++ b/pkg/control/ut_test.go
@@ -110,7 +110,8 @@
 	//
 	// NOTE3: Ports per entity:
 	//
-	// Port    Entity
+	// DataPort Entity
+	// RoutePort (svc) will be DataPort+1
 	// -------------------
 	// 14560   submgr
 	// 15560   e2term1 stub
@@ -149,37 +150,37 @@
 	//
 	//---------------------------------
 	tent.Logger.Info("### submgr ctrl run ###")
-	mainCtrl = createSubmgrControl(rtfilename, "14560")
+	mainCtrl = createSubmgrControl(rtfilename, 14560, 0)
 
 	//---------------------------------
 	//
 	//---------------------------------
 	tent.Logger.Info("### xapp1 stub run ###")
-	xappConn1 = teststube2ap.CreateNewE2Stub("xappstub1", rtfilename, "13560", "RMRXAPP1STUB", 55555)
+	xappConn1 = teststube2ap.CreateNewE2Stub("xappstub1", rtfilename, 13560, 0, "RMRXAPP1STUB", 55555)
 
 	//---------------------------------
 	//
 	//---------------------------------
 	tent.Logger.Info("### xapp2 stub run ###")
-	xappConn2 = teststube2ap.CreateNewE2Stub("xappstub2", rtfilename, "13660", "RMRXAPP2STUB", 55555)
+	xappConn2 = teststube2ap.CreateNewE2Stub("xappstub2", rtfilename, 13660, 0, "RMRXAPP2STUB", 55555)
 
 	//---------------------------------
 	//
 	//---------------------------------
 	tent.Logger.Info("### e2term1 stub run ###")
-	e2termConn1 = teststube2ap.CreateNewE2termStub("e2termstub1", rtfilename, "15560", "RMRE2TERMSTUB1", 55555)
+	e2termConn1 = teststube2ap.CreateNewE2termStub("e2termstub1", rtfilename, 15560, 0, "RMRE2TERMSTUB1", 55555)
 
 	//---------------------------------
 	//
 	//---------------------------------
 	tent.Logger.Info("### e2term2 stub run ###")
-	e2termConn2 = teststube2ap.CreateNewE2termStub("e2termstub2", rtfilename, "15660", "RMRE2TERMSTUB2", 55555)
+	e2termConn2 = teststube2ap.CreateNewE2termStub("e2termstub2", rtfilename, 15660, 0, "RMRE2TERMSTUB2", 55555)
 
 	//---------------------------------
 	// Just to test dummy stub
 	//---------------------------------
 	tent.Logger.Info("### dummy stub run ###")
-	dummystub = teststubdummy.CreateNewRmrDummyStub("dummystub", rtfilename, "16560", "DUMMYSTUB", 55555)
+	dummystub = teststubdummy.CreateNewRmrDummyStub("dummystub", rtfilename, 16560, 0, "DUMMYSTUB", 55555)
 
 	//---------------------------------
 	// Testing message sending
diff --git a/pkg/teststub/controlRmr.go b/pkg/teststub/controlRmr.go
index 06c434b..41a6606 100644
--- a/pkg/teststub/controlRmr.go
+++ b/pkg/teststub/controlRmr.go
@@ -22,6 +22,7 @@
 	"fmt"
 	"gerrit.o-ran-sc.org/r/ric-plt/xapp-frame/pkg/xapp"
 	"os"
+	"strconv"
 	"testing"
 )
 
@@ -30,7 +31,9 @@
 //-----------------------------------------------------------------------------
 type RmrControl struct {
 	TestWrapper
-	syncChan chan struct{}
+	syncChan  chan struct{}
+	DataPort  uint16
+	RoutePort uint16
 }
 
 func (tc *RmrControl) ReadyCB(data interface{}) {
@@ -42,14 +45,20 @@
 	<-tc.syncChan
 }
 
-func (tc *RmrControl) Init(desc string, rtfile string, port string) {
+func (tc *RmrControl) Init(desc string, rtfile string, port uint16, rtport uint16) {
 	tc.TestWrapper.Init(desc)
+	tc.DataPort = port
+	tc.RoutePort = rtport
 	os.Setenv("RMR_SEED_RT", rtfile)
-	os.Setenv("RMR_SRC_ID", "localhost:"+port)
-	//os.Setenv("RMR_RTG_SVC", "localhost:"+rtport)
 	xapp.Logger.Info("Using rt file %s", os.Getenv("RMR_SEED_RT"))
-	xapp.Logger.Info("Using src id  %s", os.Getenv("RMR_SRC_ID"))
-	//xapp.Logger.Info("Using rtg svc  %s", os.Getenv("RMR_RTG_SVC"))
+	if tc.DataPort > 0 {
+		os.Setenv("RMR_SRC_ID", "localhost:"+strconv.FormatUint(uint64(tc.DataPort), 10))
+		xapp.Logger.Info("Using src id  %s", os.Getenv("RMR_SRC_ID"))
+	}
+	if tc.RoutePort > 0 {
+		os.Setenv("RMR_RTG_SVC", "localhost:"+strconv.FormatUint(uint64(tc.RoutePort), 10))
+		xapp.Logger.Info("Using rtg svc  %s", os.Getenv("RMR_RTG_SVC"))
+	}
 	tc.syncChan = make(chan struct{})
 }
 
diff --git a/pkg/teststub/controlRmrStub.go b/pkg/teststub/controlRmrStub.go
index 05a8e32..f14bd1f 100644
--- a/pkg/teststub/controlRmrStub.go
+++ b/pkg/teststub/controlRmrStub.go
@@ -21,6 +21,7 @@
 import (
 	"gerrit.o-ran-sc.org/r/ric-plt/submgr/pkg/xapptweaks"
 	"gerrit.o-ran-sc.org/r/ric-plt/xapp-frame/pkg/xapp"
+	"strconv"
 	"strings"
 	"testing"
 	"time"
@@ -67,14 +68,14 @@
 	}
 }
 
-func (tc *RmrStubControl) Init(desc string, rtfile string, port string, stat string, initMsg int) {
+func (tc *RmrStubControl) Init(desc string, rtfile string, port uint16, rtport uint16, stat string, initMsg int) {
 	tc.InitMsg = initMsg
 	tc.Active = false
 	tc.RecvChan = make(chan *xapptweaks.RMRParams)
-	tc.RmrControl.Init(desc, rtfile, port)
+	tc.RmrControl.Init(desc, rtfile, port, rtport)
 	tc.RmrWrapper.Init()
 
-	tc.Rmr = xapp.NewRMRClientWithParams("tcp:"+port, 65534, 1, 0, stat)
+	tc.Rmr = xapp.NewRMRClientWithParams("tcp:"+strconv.FormatUint(uint64(port), 10), 65534, 1, 0, stat)
 	tc.Rmr.SetReadyCB(tc.ReadyCB, nil)
 	go tc.Rmr.Start(tc)
 
diff --git a/pkg/teststub/rmrroutetable.go b/pkg/teststub/rmrroutetable.go
index cb7adeb..281110c 100644
--- a/pkg/teststub/rmrroutetable.go
+++ b/pkg/teststub/rmrroutetable.go
@@ -74,12 +74,10 @@
 		allrt += val + "\n"
 	}
 	allrt += "newrt|end\n"
-	if len(rrt.meids) > 0 {
-		allrt += "meid_map | start\n"
-		for _, val := range rrt.meids {
-			allrt += val + "\n"
-		}
-		allrt += "meid_map | end | " + strconv.FormatInt(int64(len(rrt.meids)), 10) + "\n"
+	allrt += "meid_map | start\n"
+	for _, val := range rrt.meids {
+		allrt += val + "\n"
 	}
+	allrt += "meid_map | end | " + strconv.FormatInt(int64(len(rrt.meids)), 10) + "\n"
 	return allrt
 }
diff --git a/pkg/teststubdummy/stubRmrDummy.go b/pkg/teststubdummy/stubRmrDummy.go
index c08036f..c4745ba 100644
--- a/pkg/teststubdummy/stubRmrDummy.go
+++ b/pkg/teststubdummy/stubRmrDummy.go
@@ -42,9 +42,9 @@
 //-----------------------------------------------------------------------------
 //
 //-----------------------------------------------------------------------------
-func CreateNewRmrDummyStub(desc string, rtfile string, port string, stat string, mtypeseed int) *RmrDummyStub {
+func CreateNewRmrDummyStub(desc string, rtfile string, port uint16, rtport uint16, stat string, mtypeseed int) *RmrDummyStub {
 	dummyStub := &RmrDummyStub{}
-	dummyStub.RmrStubControl.Init(desc, rtfile, port, stat, mtypeseed)
+	dummyStub.RmrStubControl.Init(desc, rtfile, port, rtport, stat, mtypeseed)
 	dummyStub.reqMsg = mtypeseed + 1
 	dummyStub.respMsg = mtypeseed + 2
 	return dummyStub
diff --git a/pkg/teststube2ap/stubE2.go b/pkg/teststube2ap/stubE2.go
index 292f964..576a954 100644
--- a/pkg/teststube2ap/stubE2.go
+++ b/pkg/teststube2ap/stubE2.go
@@ -54,9 +54,9 @@
 //-----------------------------------------------------------------------------
 //
 //-----------------------------------------------------------------------------
-func CreateNewE2Stub(desc string, rtfile string, port string, stat string, mtypeseed int) *E2Stub {
+func CreateNewE2Stub(desc string, rtfile string, port uint16, rtport uint16, stat string, mtypeseed int) *E2Stub {
 	tc := &E2Stub{}
-	tc.RmrStubControl.Init(desc, rtfile, port, stat, mtypeseed)
+	tc.RmrStubControl.Init(desc, rtfile, port, rtport, stat, mtypeseed)
 	tc.xid_seq = 1
 	tc.SetCheckXid(true)
 	return tc
@@ -65,9 +65,9 @@
 //-----------------------------------------------------------------------------
 //
 //-----------------------------------------------------------------------------
-func CreateNewE2termStub(desc string, rtfile string, port string, stat string, mtypeseed int) *E2Stub {
+func CreateNewE2termStub(desc string, rtfile string, port uint16, rtport uint16, stat string, mtypeseed int) *E2Stub {
 	tc := &E2Stub{}
-	tc.RmrStubControl.Init(desc, rtfile, port, stat, mtypeseed)
+	tc.RmrStubControl.Init(desc, rtfile, port, rtport, stat, mtypeseed)
 	tc.xid_seq = 1
 	tc.SetCheckXid(false)
 	return tc