From cd78aeeae3212fa722be4ba9768cac711305badf Mon Sep 17 00:00:00 2001 From: Juha Hyttinen Date: Tue, 7 Apr 2020 17:49:08 +0300 Subject: [PATCH] RmrSrcId and RmrRtgSvc handling improved Change-Id: I9f68e9d6c7e4a1c7e2aa71256de9efcfdf4ec405 Signed-off-by: Juha Hyttinen --- pkg/control/ut_ctrl_submgr_test.go | 4 +- pkg/control/ut_test.go | 80 ++++++++++++++-------------- pkg/teststub/controlRmr.go | 30 ++++------- pkg/teststub/controlRmrStub.go | 6 +-- pkg/teststub/{rmrroutetable.go => rmrenv.go} | 71 ++++++++++++++++++++++-- pkg/teststubdummy/stubRmrDummy.go | 78 ++++++++++++++++----------- pkg/teststube2ap/stubE2.go | 8 +-- 7 files changed, 177 insertions(+), 100 deletions(-) rename pkg/teststub/{rmrroutetable.go => rmrenv.go} (54%) diff --git a/pkg/control/ut_ctrl_submgr_test.go b/pkg/control/ut_ctrl_submgr_test.go index 3a57177..45147c8 100644 --- a/pkg/control/ut_ctrl_submgr_test.go +++ b/pkg/control/ut_ctrl_submgr_test.go @@ -34,9 +34,9 @@ type testingSubmgrControl struct { c *Control } -func createSubmgrControl(rtfile string, port uint16, rtport uint16) *testingSubmgrControl { +func createSubmgrControl(srcId teststub.RmrSrcId, rtgSvc teststub.RmrRtgSvc) *testingSubmgrControl { mainCtrl = &testingSubmgrControl{} - mainCtrl.RmrControl.Init("SUBMGRCTL", rtfile, port, rtport) + mainCtrl.RmrControl.Init("SUBMGRCTL", srcId, rtgSvc) 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 05d34b8..b1f9889 100644 --- a/pkg/control/ut_test.go +++ b/pkg/control/ut_test.go @@ -23,6 +23,7 @@ import ( "gerrit.o-ran-sc.org/r/ric-plt/submgr/pkg/teststub" "gerrit.o-ran-sc.org/r/ric-plt/submgr/pkg/teststubdummy" "gerrit.o-ran-sc.org/r/ric-plt/submgr/pkg/teststube2ap" + "gerrit.o-ran-sc.org/r/ric-plt/submgr/pkg/xapptweaks" "os" "testing" ) @@ -110,77 +111,78 @@ func ut_test_init() { // // NOTE3: Ports per entity: // - // DataPort Entity - // RoutePort (svc) will be DataPort+1 + // Entity // ------------------- - // 14560 submgr - // 15560 e2term1 stub - // 15660 e2term2 stub - // 13560 xapp1 stub - // 13660 xapp2 stub - // 16560 dummy stub - // + + mainsrc := teststub.RmrSrcId{xapptweaks.RmrEndpoint{"localhost", 14560}} + xapp1src := teststub.RmrSrcId{xapptweaks.RmrEndpoint{"localhost", 13560}} + xapp2src := teststub.RmrSrcId{xapptweaks.RmrEndpoint{"localhost", 13660}} + e2term1src := teststub.RmrSrcId{xapptweaks.RmrEndpoint{"localhost", 15560}} + e2term2src := teststub.RmrSrcId{xapptweaks.RmrEndpoint{"localhost", 15660}} + dummysrc := teststub.RmrSrcId{xapptweaks.RmrEndpoint{"localhost", 16560}} + //--------------------------------- rt := &teststub.RmrRouteTable{} - rt.AddRoute(12010, "", -1, "localhost:14560") - rt.AddRoute(12010, "localhost:14560", -1, "%meid") - rt.AddRoute(12011, "localhost:15560", -1, "localhost:14560") - rt.AddRoute(12012, "localhost:15560", -1, "localhost:14560") - rt.AddRoute(12011, "localhost:15660", -1, "localhost:14560") - rt.AddRoute(12012, "localhost:15660", -1, "localhost:14560") - rt.AddRoute(12011, "localhost:14560", -1, "localhost:13660;localhost:13560") - rt.AddRoute(12012, "localhost:14560", -1, "localhost:13660;localhost:13560") - rt.AddRoute(12020, "", -1, "localhost:14560") - rt.AddRoute(12020, "localhost:14560", -1, "%meid") - rt.AddRoute(12021, "localhost:15560", -1, "localhost:14560") - rt.AddRoute(12022, "localhost:15560", -1, "localhost:14560") - rt.AddRoute(12021, "localhost:15660", -1, "localhost:14560") - rt.AddRoute(12022, "localhost:15660", -1, "localhost:14560") - rt.AddRoute(12021, "localhost:14560", -1, "localhost:13660;localhost:13560") - rt.AddRoute(12022, "localhost:14560", -1, "localhost:13660;localhost:13560") - rt.AddRoute(55555, "", -1, "localhost:13660;localhost:13560;localhost:15560;localhost:15660;localhost:16560") - - rt.AddMeid("localhost:15560", []string{"RAN_NAME_1", "RAN_NAME_2"}) - rt.AddMeid("localhost:15660", []string{"RAN_NAME_11", "RAN_NAME_12"}) - - rtfilename, _ := teststub.CreateTmpFile(rt.GetTable()) - defer os.Remove(rtfilename) - tent.Logger.Info("table[%s]", rt.GetTable()) + rt.AddRoute(12010, "", -1, mainsrc.String()) + rt.AddRoute(12010, mainsrc.String(), -1, "%meid") + rt.AddRoute(12011, e2term1src.String(), -1, mainsrc.String()) + rt.AddRoute(12012, e2term1src.String(), -1, mainsrc.String()) + rt.AddRoute(12011, e2term2src.String(), -1, mainsrc.String()) + rt.AddRoute(12012, e2term2src.String(), -1, mainsrc.String()) + rt.AddRoute(12011, mainsrc.String(), -1, xapp2src.String()+";"+xapp1src.String()) + rt.AddRoute(12012, mainsrc.String(), -1, xapp2src.String()+";"+xapp1src.String()) + rt.AddRoute(12020, "", -1, mainsrc.String()) + rt.AddRoute(12020, mainsrc.String(), -1, "%meid") + rt.AddRoute(12021, e2term1src.String(), -1, mainsrc.String()) + rt.AddRoute(12022, e2term1src.String(), -1, mainsrc.String()) + rt.AddRoute(12021, e2term2src.String(), -1, mainsrc.String()) + rt.AddRoute(12022, e2term2src.String(), -1, mainsrc.String()) + rt.AddRoute(12021, mainsrc.String(), -1, xapp2src.String()+";"+xapp1src.String()) + rt.AddRoute(12022, mainsrc.String(), -1, xapp2src.String()+";"+xapp1src.String()) + rt.AddRoute(55555, "", -1, xapp2src.String()+";"+xapp1src.String()+";"+e2term1src.String()+";"+e2term2src.String()+";"+dummysrc.String()) + + rt.AddMeid(e2term1src.String(), []string{"RAN_NAME_1", "RAN_NAME_2"}) + rt.AddMeid(e2term2src.String(), []string{"RAN_NAME_11", "RAN_NAME_12"}) + + rt.Enable() + defer rt.Disable() + tent.Logger.Info("rttable[%s]", rt.Table()) + //--------------------------------- // //--------------------------------- tent.Logger.Info("### submgr ctrl run ###") - mainCtrl = createSubmgrControl(rtfilename, 14560, 0) + mainCtrl = createSubmgrControl(mainsrc, teststub.RmrRtgSvc{}) //--------------------------------- // //--------------------------------- tent.Logger.Info("### xapp1 stub run ###") - xappConn1 = teststube2ap.CreateNewE2Stub("xappstub1", rtfilename, 13560, 0, "RMRXAPP1STUB", 55555) + xappConn1 = teststube2ap.CreateNewE2Stub("xappstub1", xapp1src, teststub.RmrRtgSvc{}, "RMRXAPP1STUB", 55555) //--------------------------------- // //--------------------------------- tent.Logger.Info("### xapp2 stub run ###") - xappConn2 = teststube2ap.CreateNewE2Stub("xappstub2", rtfilename, 13660, 0, "RMRXAPP2STUB", 55555) + xappConn2 = teststube2ap.CreateNewE2Stub("xappstub2", xapp2src, teststub.RmrRtgSvc{}, "RMRXAPP2STUB", 55555) //--------------------------------- // //--------------------------------- tent.Logger.Info("### e2term1 stub run ###") - e2termConn1 = teststube2ap.CreateNewE2termStub("e2termstub1", rtfilename, 15560, 0, "RMRE2TERMSTUB1", 55555) + e2termConn1 = teststube2ap.CreateNewE2termStub("e2termstub1", e2term1src, teststub.RmrRtgSvc{}, "RMRE2TERMSTUB1", 55555) //--------------------------------- // //--------------------------------- tent.Logger.Info("### e2term2 stub run ###") - e2termConn2 = teststube2ap.CreateNewE2termStub("e2termstub2", rtfilename, 15660, 0, "RMRE2TERMSTUB2", 55555) + e2termConn2 = teststube2ap.CreateNewE2termStub("e2termstub2", e2term2src, teststub.RmrRtgSvc{}, "RMRE2TERMSTUB2", 55555) //--------------------------------- // Just to test dummy stub //--------------------------------- tent.Logger.Info("### dummy stub run ###") - dummystub = teststubdummy.CreateNewRmrDummyStub("dummystub", rtfilename, 16560, 0, "DUMMYSTUB", 55555) + dummystub = teststubdummy.CreateNewRmrDummyStub("dummystub", dummysrc, teststub.RmrRtgSvc{}, "DUMMYSTUB", 55555) //--------------------------------- // Testing message sending diff --git a/pkg/teststub/controlRmr.go b/pkg/teststub/controlRmr.go index 41a6606..18b821e 100644 --- a/pkg/teststub/controlRmr.go +++ b/pkg/teststub/controlRmr.go @@ -20,9 +20,6 @@ package teststub import ( "fmt" - "gerrit.o-ran-sc.org/r/ric-plt/xapp-frame/pkg/xapp" - "os" - "strconv" "testing" ) @@ -31,9 +28,9 @@ import ( //----------------------------------------------------------------------------- type RmrControl struct { TestWrapper - syncChan chan struct{} - DataPort uint16 - RoutePort uint16 + RmrSrcId + RmrRtgSvc + syncChan chan struct{} } func (tc *RmrControl) ReadyCB(data interface{}) { @@ -45,20 +42,15 @@ func (tc *RmrControl) WaitCB() { <-tc.syncChan } -func (tc *RmrControl) Init(desc string, rtfile string, port uint16, rtport uint16) { +func (tc *RmrControl) Init(desc string, srcId RmrSrcId, rtgSvc RmrRtgSvc) { tc.TestWrapper.Init(desc) - tc.DataPort = port - tc.RoutePort = rtport - os.Setenv("RMR_SEED_RT", rtfile) - xapp.Logger.Info("Using rt file %s", os.Getenv("RMR_SEED_RT")) - 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.RmrSrcId = srcId + tc.RmrSrcId.Enable() + + tc.RmrRtgSvc = rtgSvc + tc.RmrRtgSvc.Enable() + tc.syncChan = make(chan struct{}) } diff --git a/pkg/teststub/controlRmrStub.go b/pkg/teststub/controlRmrStub.go index f14bd1f..0f207e8 100644 --- a/pkg/teststub/controlRmrStub.go +++ b/pkg/teststub/controlRmrStub.go @@ -68,14 +68,14 @@ func (tc *RmrStubControl) TestMsgChanEmpty(t *testing.T) { } } -func (tc *RmrStubControl) Init(desc string, rtfile string, port uint16, rtport uint16, stat string, initMsg int) { +func (tc *RmrStubControl) Init(desc string, srcId RmrSrcId, rtgSvc RmrRtgSvc, stat string, initMsg int) { tc.InitMsg = initMsg tc.Active = false tc.RecvChan = make(chan *xapptweaks.RMRParams) - tc.RmrControl.Init(desc, rtfile, port, rtport) + tc.RmrControl.Init(desc, srcId, rtgSvc) tc.RmrWrapper.Init() - tc.Rmr = xapp.NewRMRClientWithParams("tcp:"+strconv.FormatUint(uint64(port), 10), 65534, 1, 0, stat) + tc.Rmr = xapp.NewRMRClientWithParams("tcp:"+strconv.FormatUint(uint64(srcId.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/rmrenv.go similarity index 54% rename from pkg/teststub/rmrroutetable.go rename to pkg/teststub/rmrenv.go index 281110c..5a57b56 100644 --- a/pkg/teststub/rmrroutetable.go +++ b/pkg/teststub/rmrenv.go @@ -20,6 +20,9 @@ package teststub import ( + "gerrit.o-ran-sc.org/r/ric-plt/submgr/pkg/xapptweaks" + "gerrit.o-ran-sc.org/r/ric-plt/xapp-frame/pkg/xapp" + "os" "strconv" ) @@ -28,8 +31,9 @@ import ( //----------------------------------------------------------------------------- type RmrRouteTable struct { - routes []string - meids []string + tmpfile string + routes []string + meids []string } func (rrt *RmrRouteTable) AddRoute(mtype int, src string, subid int, trg string) { @@ -68,7 +72,11 @@ func (rrt *RmrRouteTable) DelMeid(meids []string) { rrt.meids = append(rrt.meids, line) } -func (rrt *RmrRouteTable) GetTable() string { +func (rrt *RmrRouteTable) FileName() string { + return rrt.tmpfile +} + +func (rrt *RmrRouteTable) Table() string { allrt := "newrt|start\n" for _, val := range rrt.routes { allrt += val + "\n" @@ -81,3 +89,60 @@ func (rrt *RmrRouteTable) GetTable() string { allrt += "meid_map | end | " + strconv.FormatInt(int64(len(rrt.meids)), 10) + "\n" return allrt } + +func (rrt *RmrRouteTable) Enable() { + if len(rrt.tmpfile) > 0 { + os.Remove(rrt.tmpfile) + } + rrt.tmpfile, _ = CreateTmpFile(rrt.Table()) + os.Setenv("RMR_SEED_RT", rrt.tmpfile) + xapp.Logger.Info("Using rt file %s", os.Getenv("RMR_SEED_RT")) +} + +func (rrt *RmrRouteTable) Disable() { + if len(rrt.tmpfile) > 0 { + os.Remove(rrt.tmpfile) + os.Unsetenv("RMR_SEED_RT") + rrt.tmpfile = "" + xapp.Logger.Info("Not using rt file ") + } +} + +//----------------------------------------------------------------------------- +// +//----------------------------------------------------------------------------- + +type RmrSrcId struct { + xapptweaks.RmrEndpoint +} + +func (rsi *RmrSrcId) Enable() { + if rsi.Port > 0 { + os.Setenv("RMR_SRC_ID", rsi.String()) + xapp.Logger.Info("Using src id %s", os.Getenv("RMR_SRC_ID")) + } +} + +func (rsi *RmrSrcId) Disable() { + os.Unsetenv("RMR_SRC_ID") + xapp.Logger.Info("Not using Using src id") +} + +//----------------------------------------------------------------------------- +// +//----------------------------------------------------------------------------- +type RmrRtgSvc struct { + xapptweaks.RmrEndpoint +} + +func (rrs *RmrRtgSvc) Enable() { + if rrs.Port > 0 { + os.Setenv("RMR_RTG_SVC", rrs.String()) + xapp.Logger.Info("Using rtg svc %s", os.Getenv("RMR_SRC_ID")) + } +} + +func (rrs *RmrRtgSvc) Disable() { + os.Unsetenv("RMR_RTG_SVC") + xapp.Logger.Info("Not using Using rtg svc") +} diff --git a/pkg/teststubdummy/stubRmrDummy.go b/pkg/teststubdummy/stubRmrDummy.go index c4745ba..b3b4352 100644 --- a/pkg/teststubdummy/stubRmrDummy.go +++ b/pkg/teststubdummy/stubRmrDummy.go @@ -42,9 +42,9 @@ type RmrDummyStub struct { //----------------------------------------------------------------------------- // //----------------------------------------------------------------------------- -func CreateNewRmrDummyStub(desc string, rtfile string, port uint16, rtport uint16, stat string, mtypeseed int) *RmrDummyStub { +func CreateNewRmrDummyStub(desc string, srcId teststub.RmrSrcId, rtgSvc teststub.RmrRtgSvc, stat string, mtypeseed int) *RmrDummyStub { dummyStub := &RmrDummyStub{} - dummyStub.RmrStubControl.Init(desc, rtfile, port, rtport, stat, mtypeseed) + dummyStub.RmrStubControl.Init(desc, srcId, rtgSvc, stat, mtypeseed) dummyStub.reqMsg = mtypeseed + 1 dummyStub.respMsg = mtypeseed + 2 return dummyStub @@ -54,14 +54,18 @@ func CreateNewRmrDummyStub(desc string, rtfile string, port uint16, rtport uint1 // //----------------------------------------------------------------------------- -func (tc *RmrDummyStub) SendReq(t *testing.T) { +func (tc *RmrDummyStub) SendReq(t *testing.T, plen int) { tc.Logger.Info("SendReq") - var dummyBuf []byte = make([]byte, 100) + len := plen + if len == 0 { + len = 100 + } params := xapptweaks.NewParams(nil) params.Mtype = tc.reqMsg params.SubId = -1 - params.Payload = dummyBuf - params.PayloadLen = 100 + + params.Payload = make([]byte, len) + params.PayloadLen = 0 params.Meid = &xapp.RMRMeid{RanName: "TEST"} params.Xid = "TEST" params.Mbuf = nil @@ -73,13 +77,35 @@ func (tc *RmrDummyStub) SendReq(t *testing.T) { return } -func (tc *RmrDummyStub) RecvResp(t *testing.T) bool { - tc.Logger.Info("RecvResp") +func (tc *RmrDummyStub) SendResp(t *testing.T, plen int) { + tc.Logger.Info("SendReq") + len := plen + if len == 0 { + len = 100 + } + params := xapptweaks.NewParams(nil) + params.Mtype = tc.respMsg + params.SubId = -1 + params.Payload = make([]byte, len) + params.PayloadLen = 0 + params.Meid = &xapp.RMRMeid{RanName: "TEST"} + params.Xid = "TEST" + params.Mbuf = nil + + snderr := tc.RmrSend(params, 5) + if snderr != nil { + tc.TestError(t, "%s", snderr.Error()) + } + return +} + +func (tc *RmrDummyStub) RecvReq(t *testing.T) bool { + tc.Logger.Info("RecvReq") msg := tc.WaitMsg(15) if msg != nil { - if msg.Mtype != tc.respMsg { - tc.TestError(t, "Received wrong mtype expected %d got %d, error", tc.respMsg, msg.Mtype) + if msg.Mtype != tc.reqMsg { + tc.TestError(t, "Received wrong mtype expected %d got %d, error", tc.reqMsg, msg.Mtype) return false } return true @@ -89,26 +115,18 @@ func (tc *RmrDummyStub) RecvResp(t *testing.T) bool { return false } -//----------------------------------------------------------------------------- -// -//----------------------------------------------------------------------------- -func RmrDummyHandleMessage(msg *xapptweaks.RMRParams, mtypeseed int, rmr xapptweaks.XAppWrapperIf) (bool, error) { - if msg.Mtype == mtypeseed+1 { - var dummyBuf []byte = make([]byte, 100) - params := xapptweaks.NewParams(nil) - params.Mtype = mtypeseed + 2 - params.SubId = msg.SubId - params.Payload = dummyBuf - params.PayloadLen = 100 - params.Meid = msg.Meid - params.Xid = msg.Xid - params.Mbuf = nil - rmr.GetLogger().Info("SEND DUMMY RESP: %s", params.String()) - err := rmr.RmrSend(params, 5) - if err != nil { - rmr.GetLogger().Error("RmrDummyHandleMessage: err(%s)", err.Error()) +func (tc *RmrDummyStub) RecvResp(t *testing.T) bool { + tc.Logger.Info("RecvResp") + + msg := tc.WaitMsg(15) + if msg != nil { + if msg.Mtype != tc.respMsg { + tc.TestError(t, "Received wrong mtype expected %d got %d, error", tc.respMsg, msg.Mtype) + return false } - return true, err + return true + } else { + tc.TestError(t, "Not Received msg within %d secs", 15) } - return false, nil + return false } diff --git a/pkg/teststube2ap/stubE2.go b/pkg/teststube2ap/stubE2.go index c99df73..5804f74 100644 --- a/pkg/teststube2ap/stubE2.go +++ b/pkg/teststube2ap/stubE2.go @@ -54,9 +54,9 @@ type E2Stub struct { //----------------------------------------------------------------------------- // //----------------------------------------------------------------------------- -func CreateNewE2Stub(desc string, rtfile string, port uint16, rtport uint16, stat string, mtypeseed int) *E2Stub { +func CreateNewE2Stub(desc string, srcId teststub.RmrSrcId, rtgSvc teststub.RmrRtgSvc, stat string, mtypeseed int) *E2Stub { tc := &E2Stub{} - tc.RmrStubControl.Init(desc, rtfile, port, rtport, stat, mtypeseed) + tc.RmrStubControl.Init(desc, srcId, rtgSvc, stat, mtypeseed) tc.xid_seq = 1 tc.SetCheckXid(true) return tc @@ -65,9 +65,9 @@ func CreateNewE2Stub(desc string, rtfile string, port uint16, rtport uint16, sta //----------------------------------------------------------------------------- // //----------------------------------------------------------------------------- -func CreateNewE2termStub(desc string, rtfile string, port uint16, rtport uint16, stat string, mtypeseed int) *E2Stub { +func CreateNewE2termStub(desc string, srcId teststub.RmrSrcId, rtgSvc teststub.RmrRtgSvc, stat string, mtypeseed int) *E2Stub { tc := &E2Stub{} - tc.RmrStubControl.Init(desc, rtfile, port, rtport, stat, mtypeseed) + tc.RmrStubControl.Init(desc, srcId, rtgSvc, stat, mtypeseed) tc.xid_seq = 1 tc.SetCheckXid(false) return tc -- 2.16.6