RmrSrcId and RmrRtgSvc handling improved
[ric-plt/submgr.git] / pkg / teststub / rmrenv.go
similarity index 54%
rename from pkg/teststub/rmrroutetable.go
rename to pkg/teststub/rmrenv.go
index 281110c..5a57b56 100644 (file)
@@ -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")
+}