Open RMR connection in a new thread 90/5990/2
authorwahidw <abdulwahid.w@nokia.com>
Fri, 30 Apr 2021 13:58:07 +0000 (13:58 +0000)
committerwahidw <abdulwahid.w@nokia.com>
Fri, 30 Apr 2021 14:09:14 +0000 (14:09 +0000)
Signed-off-by: wahidw <abdulwahid.w@nokia.com>
Change-Id: I62c33224bc34748759f646ec527da94129ac0a94

RELNOTES
cmd/rtmgr.go
container-tag.yaml
pkg/nbi/control.go
pkg/nbi/httprestful.go
pkg/rpe/rmr.go
pkg/rtmgr/rtmgr.go
pkg/rtmgr/types.go
pkg/sbi/nngpush.go
pkg/sdl/file.go

index ffdc47a..dc34000 100644 (file)
--- a/RELNOTES
+++ b/RELNOTES
@@ -1,3 +1,6 @@
+### v0.7.5
+* Open RMR connection in a a new thread
+
 ### v0.7.4
 * Overwrite duplicate E2T address instead of sending error to E2Manager
 
index 1234622..c8ad5c6 100644 (file)
@@ -67,6 +67,7 @@ func main() {
        rtmgr.Eps = make(rtmgr.Endpoints)
        rtmgr.Mtype = make(rtmgr.MessageTypeList)
        rtmgr.Rtmgr_ready = false
+       rtmgr.RMRConnStatus = make(map[string]bool)
 
        // RMR thread is starting port: 4560
        c := nbi.NewControl()
index b3f65d6..4381920 100644 (file)
@@ -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.4
+tag: 0.7.5
index a1e9c77..d88f5b0 100644 (file)
@@ -27,8 +27,8 @@ import "C"
 import (
        "errors"
        //"fmt"
-       "net/http"
        "gerrit.o-ran-sc.org/r/ric-plt/xapp-frame/pkg/xapp"
+       "net/http"
        "os"
        "routing-manager/pkg/rpe"
        "routing-manager/pkg/rtmgr"
@@ -97,24 +97,6 @@ func (c *Control) controlLoop() {
        for {
                msg := <-c.rcChan
                c.recievermr(msg)
-               /*
-                       xapp_msg := sbi.RMRParams{msg}
-                       switch msg.Mtype {
-                       case xapp.RICMessageTypes["RMRRM_REQ_TABLE"]:
-                               if rtmgr.Rtmgr_ready == false {
-                                       xapp.Logger.Info("Update Route Table Request(RMR to RM), message discarded as routing manager is not ready")
-                               } else {
-                                       xapp.Logger.Info("Update Route Table Request(RMR to RM)")
-                                       go c.handleUpdateToRoutingManagerRequest(msg)
-                               }
-                       case xapp.RICMessageTypes["RMRRM_TABLE_STATE"]:
-                               xapp.Logger.Info("state of table to route mgr %s,payload %s", xapp_msg.String(), msg.Payload)
-
-                       default:
-                               err := errors.New("Message Type " + strconv.Itoa(msg.Mtype) + " is discarded")
-                               xapp.Logger.Error("Unknown message type: %v", err)
-                       }
-                       xapp.Rmr.Free(msg.Mbuf)*/
        }
 }
 
@@ -179,25 +161,41 @@ func (c *Control) handleUpdateToRoutingManagerRequest(params *xapp.RMRParams) {
        }
 }
 
-func sendRoutesToAll() (err error) {
-
+func getConfigData() (*rtmgr.RicComponents, error) {
+       var data *rtmgr.RicComponents
        m.Lock()
        data, err := sdlEngine.ReadAll(xapp.Config.GetString("rtfile"))
-       //fmt.Printf("data = %v,%v,%v",data,sdlEngine,sbiEngine)
+
        m.Unlock()
        if data == nil {
                if err != nil {
-                       return errors.New("Cannot get data from sdl interface due to: " + err.Error())
+                       return nil, errors.New("Cannot get data from sdl interface due to: " + err.Error())
                } else {
                        xapp.Logger.Debug("Cannot get data from sdl interface, data is null")
-                       return errors.New("Cannot get data from sdl interface")
+                       return nil, errors.New("Cannot get data from sdl interface")
                }
        }
 
-       /*      if sbiEngine == nil {
-               fmt.Printf("SBI is nil")
-       }*/
+       return data, nil
+}
+
+func updateEp() (err error) {
+       data, err := getConfigData()
+       if err != nil {
+               return errors.New("Routing table cannot be published due to: " + err.Error())
+       }
        sbiEngine.UpdateEndpoints(data)
+
+       return nil
+}
+
+func sendRoutesToAll() (err error) {
+
+       data, err := getConfigData()
+       if err != nil {
+               return errors.New("Routing table cannot be published due to: " + err.Error())
+       }
+
        policies := rpeEngine.GeneratePolicies(rtmgr.Eps, data)
        err = sbiEngine.DistributeAll(policies)
        if err != nil {
@@ -223,6 +221,10 @@ func Serve() {
        defer nbiEngine.Terminate()
        defer sbiEngine.Terminate()
 
+       /* used for rtmgr restart case to connect to Endpoints */
+       go updateEp()
+       time.Sleep(5 * time.Second)
+
        for {
                sendRoutesToAll()
 
index f505b63..5393dc9 100644 (file)
@@ -144,6 +144,7 @@ func provideXappHandleHandlerImpl(data *models.XappCallbackData) error {
                                m.Lock()
                                sdlEngine.WriteXApps(xapp.Config.GetString("rtfile"), alldata)
                                m.Unlock()
+                               updateEp()
                                return sendRoutesToAll()
                        }
                }
@@ -225,6 +226,7 @@ func provideXappSubscriptionHandleImpl(data *models.XappSubscriptionData) error
        xapp.Logger.Debug("received XApp subscription data")
        addSubscription(&rtmgr.Subs, data)
        xapp.Logger.Debug("Endpoints: %v", rtmgr.Eps)
+       updateEp()
        return sendRoutesToAll()
 }
 
@@ -256,6 +258,7 @@ func deleteXappSubscriptionHandleImpl(data *models.XappSubscriptionData) error {
 
        xapp.Logger.Debug("received XApp subscription delete data")
        delSubscription(&rtmgr.Subs, data)
+       updateEp()
        return sendRoutesToAll()
 
 }
@@ -283,6 +286,7 @@ func updateXappSubscriptionHandleImpl(data *models.XappList, subid uint16) error
        }
        xapp.Logger.Debug("received XApp subscription Merge data")
        updateSubscription(&xapplist)
+       updateEp()
        return sendRoutesToAll()
 }
 
@@ -290,6 +294,7 @@ func createNewE2tHandleHandlerImpl(data *models.E2tData) error {
        xapp.Logger.Debug("Invoked createNewE2tHandleHandlerImpl")
        err, IsDuplicate := validateE2tData(data)
        if IsDuplicate == true {
+               updateEp()
                return sendRoutesToAll()
        }
 
@@ -303,7 +308,16 @@ func createNewE2tHandleHandlerImpl(data *models.E2tData) error {
        m.Lock()
        sdlEngine.WriteNewE2TInstance(xapp.Config.GetString("rtfile"), e2data, meiddata)
        m.Unlock()
-       return sendRoutesToAll()
+       updateEp()
+       sendRoutesToAll()
+       time.Sleep(10 * time.Second)
+       for ep, value := range rtmgr.RMRConnStatus {
+               if ep == *data.E2TAddress && value == true {
+                       return nil
+               }
+       }
+
+       return errors.New("Error while adding new E2T " + *data.E2TAddress)
 
 }
 
@@ -336,6 +350,7 @@ func associateRanToE2THandlerImpl(data models.RanE2tMap) error {
        m.Lock()
        sdlEngine.WriteAssRANToE2TInstance(xapp.Config.GetString("rtfile"), data)
        m.Unlock()
+       updateEp()
        return sendRoutesToAll()
 
 }
@@ -351,6 +366,7 @@ func disassociateRanToE2THandlerImpl(data models.RanE2tMap) error {
        m.Lock()
        sdlEngine.WriteDisAssRANFromE2TInstance(xapp.Config.GetString("rtfile"), data)
        m.Unlock()
+       updateEp()
        return sendRoutesToAll()
 
 }
@@ -366,6 +382,7 @@ func deleteE2tHandleHandlerImpl(data *models.E2tDeleteData) error {
        m.Lock()
        sdlEngine.WriteDeleteE2TInstance(xapp.Config.GetString("rtfile"), data)
        m.Unlock()
+       updateEp()
        return sendRoutesToAll()
 
 }
@@ -489,7 +506,7 @@ func launchRest(nbiif *string) {
                                xapp.Logger.Error("RoutingManager->E2Manager DisassociateRanToE2T Request Failed: " + err.Error())
                                return handle.NewDissociateRanBadRequest()
                        } else {
-                               xapp.Logger.Info("RoutingManager->E2Manager DisiassociateRanToE2T Request Success, E2T = %v", params.DissociateList)
+                               xapp.Logger.Info("RoutingManager->E2Manager DisassociateRanToE2T Request Success, E2T = %v", params.DissociateList)
                                return handle.NewDissociateRanCreated()
                        }
                })
@@ -870,6 +887,7 @@ func adddelrmrroute(routelist models.Routelist, rtflag bool) error {
 
                }
        }
+       updateEp()
        return sendRoutesToAll()
 }
 
index 446d7ec..eb7d7ed 100644 (file)
@@ -80,27 +80,35 @@ func (r *Rmr) generateRMRPolicies(eps rtmgr.Endpoints, rcs *rtmgr.RicComponents,
                }
                rawrte += group
 
-                if (rte.RouteType == "%meid") {
-                        rawrte += group + rte.RouteType
-                }
+               if rte.RouteType == "%meid" {
+                       rawrte += group + rte.RouteType
+               }
 
                rawrt = append(rawrt, rawrte+"\n")
        }
-       for _,val := range rtmgr.DynamicRouteList {
-               rawrt = append(rawrt,val)
+       for _, val := range rtmgr.DynamicRouteList {
+               rawrt = append(rawrt, val)
        }
 
        rawrt = append(rawrt, key+"newrt|end\n")
-        count := 0
+       count := 0
+
+       //meidrt := key + "meid_map|start\n"
+       //meidrt := []string{key + "meid_map|start\n"}
+       rawrt = append(rawrt, key+"meid_map|start\n")
+       for _, value := range rcs.MeidMap {
+               //meidrt += key + value + "\n"
+               rawrt = append(rawrt, key+value+"\n")
+               count++
+       }
+       rawrt = append(rawrt, key+"meid_map|end|"+strconv.Itoa(count)+"\n")
+       //meidrt += key+"meid_map|end|" + strconv.Itoa(count) +"\n"
 
-       meidrt := key +"meid_map|start\n"
-        for _, value := range rcs.MeidMap {
-            meidrt += key + value + "\n"
-            count++
-        }
-        meidrt += key+"meid_map|end|" + strconv.Itoa(count) +"\n"
+       /*for _, value := range meidrt {
+               rawrt = append(meidrt, value)
+       }*/
 
-       rawrt = append(rawrt, meidrt)
+       //rawrt = append(rawrt, meidrt)
        xapp.Logger.Debug("rmr.GeneratePolicies returns: %v", rawrt)
        xapp.Logger.Debug("rmr.GeneratePolicies returns: %v", rcs)
        return &rawrt
index de7db00..3c4f4e5 100644 (file)
@@ -39,11 +39,12 @@ import (
 )
 
 var (
-       Eps  Endpoints
-       Subs SubscriptionList
-       PrsCfg  *PlatformRoutes
-       Mtype MessageTypeList
+       Eps              Endpoints
+       Subs             SubscriptionList
+       PrsCfg           *PlatformRoutes
+       Mtype            MessageTypeList
        DynamicRouteList []string
+       RMRConnStatus    map[string]bool
 )
 
 func GetPlatformComponents(configfile string) (*PlatformComponents, error) {
@@ -64,19 +65,19 @@ func GetPlatformComponents(configfile string) (*PlatformComponents, error) {
        if err != nil {
                return nil, errors.New("cannot read the file due to: " + err.Error())
        }
-       err = json.Unmarshal(jsonByteValue,&rtroutes)
-        if err != nil {
-               return nil, errors.New("cannot parse data due to: " + err.Error())
-        }
-        PrsCfg = &(rtroutes.Prs)
+       err = json.Unmarshal(jsonByteValue, &rtroutes)
+       if err != nil {
+               return nil, errors.New("cannot parse data due to: " + err.Error())
+       }
+       PrsCfg = &(rtroutes.Prs)
 
-       err = json.Unmarshal(jsonByteValue,&mtypes)
-        if err != nil {
-               return nil, errors.New("cannot parse data due to: " + err.Error())
-        } else {
+       err = json.Unmarshal(jsonByteValue, &mtypes)
+       if err != nil {
+               return nil, errors.New("cannot parse data due to: " + err.Error())
+       } else {
                xapp.Logger.Debug("Messgaetypes = %v", mtypes)
-               for _,m := range mtypes.Mit {
-                       splitstr := strings.Split(m,"=")
+               for _, m := range mtypes.Mit {
+                       splitstr := strings.Split(m, "=")
                        Mtype[splitstr[0]] = splitstr[1]
                }
        }
index 4501bb8..41e8cf0 100644 (file)
@@ -92,59 +92,57 @@ type PlatformComponents []struct {
 }
 
 type E2TInstance struct {
-        Name string `json:"name"`
-        Fqdn string `json:"fqdn"`
-        Ranlist []string `json:"ranlist"`
+       Name    string   `json:"name"`
+       Fqdn    string   `json:"fqdn"`
+       Ranlist []string `json:"ranlist"`
 }
 
 type E2tIdentity struct {
-        E2taddress string `json:"e2tAddress"`
-        Rannames []string `json:"ranNames"`
+       E2taddress string   `json:"e2tAddress"`
+       Rannames   []string `json:"ranNames"`
 }
 
 type ConfigRtmgr struct {
        Pcs PlatformComponents `json:"PlatformComponents"`
 }
 
-
 type MessageTypeIdentifier struct {
        Mit []string `json:"messagetypes"`
 }
 
-
 type RicComponents struct {
-       XApps []XApp
-       E2Ts  map [string]E2TInstance
-       MeidMap  []string
-       Pcs   PlatformComponents
+       XApps   []XApp
+       E2Ts    map[string]E2TInstance
+       MeidMap []string
+       Pcs     PlatformComponents
 }
 
 type Subscription struct {
        SubID int32
-       Fqdn string
-       Port uint16
+       Fqdn  string
+       Port  uint16
 }
 
 type PlatformRoutes []struct {
-       MessageType     string `json:"messagetype"`
-       SenderEndPoint  string `json:"senderendpoint"`
-       SubscriptionId  int32  `json:"subscriptionid"`
-       EndPoint        string `json:"endpoint"`
-       Meid            string `json:"meid"`
+       MessageType    string `json:"messagetype"`
+       SenderEndPoint string `json:"senderendpoint"`
+       SubscriptionId int32  `json:"subscriptionid"`
+       EndPoint       string `json:"endpoint"`
+       Meid           string `json:"meid"`
 }
 
 type RtmgrRoutes struct {
-       Prs PlatformRoutes      `json:"PlatformRoutes"`
+       Prs PlatformRoutes `json:"PlatformRoutes"`
 }
 
 type FqDn struct {
        Address *string
-        Port *uint16
+       Port    *uint16
 }
 
 type XappList struct {
-        SubscriptionID  uint16
-       FqdnList []FqDn
+       SubscriptionID uint16
+       FqdnList       []FqDn
 }
 
 var (
index 4b7f871..16545cb 100644 (file)
@@ -37,15 +37,20 @@ import (
        "bytes"
        "crypto/md5"
        "errors"
+       "fmt"
        "gerrit.o-ran-sc.org/r/ric-plt/xapp-frame/pkg/xapp"
        "routing-manager/pkg/rtmgr"
        "strconv"
        "strings"
-       "fmt"
+       "sync"
+       "time"
 )
 
 var rmrcallid = 1
 var rmrdynamiccallid = 201
+var addendpointct = 1
+
+var conn sync.Mutex
 
 type RmrPush struct {
        Sbi
@@ -53,8 +58,8 @@ type RmrPush struct {
 }
 
 type EPStatus struct {
-        endpoint string
-        status   bool
+       endpoint string
+       status   bool
 }
 
 type RMRParams struct {
@@ -82,12 +87,16 @@ func (c *RmrPush) Terminate() error {
 }
 
 func (c *RmrPush) AddEndpoint(ep *rtmgr.Endpoint) error {
-
-       xapp.Logger.Debug("Invoked sbi.AddEndpoint")
+       count := addendpointct + 1
+       xapp.Logger.Debug("Invoked sbi.AddEndpoint for %s with count = %d", ep.Ip, count)
        endpoint := ep.Ip + ":" + strconv.Itoa(DefaultRmrPipelineSocketNumber)
        ep.Whid = int(xapp.Rmr.Openwh(endpoint))
        if ep.Whid < 0 {
-               return errors.New("can't open warmhole connection for endpoint:" + ep.Uuid + " due to invalid Wormhole ID: " + string(ep.Whid))
+               time.Sleep(time.Duration(10) * time.Second)
+               ep.Whid = int(xapp.Rmr.Openwh(endpoint))
+               if ep.Whid < 0 {
+                       return errors.New("can't open warmhole connection for endpoint:" + ep.Uuid + " due to invalid Wormhole ID: " + string(ep.Whid) + " count: " + strconv.Itoa(count))
+               }
        } else {
                xapp.Logger.Debug("Wormhole ID is %v and EP is %v", ep.Whid, endpoint)
        }
@@ -114,83 +123,89 @@ func (c *RmrPush) DistributeAll(policies *[]string) error {
        /*for _, ep := range rtmgr.Eps {
                go c.send(ep, policies)
        }*/
-       channel := make(chan EPStatus)
+       //channel := make(chan EPStatus)
 
        if rmrcallid == 200 {
                rmrcallid = 1
        }
 
-        for _, ep := range rtmgr.Eps {
-                go c.send_sync(ep,  policies, channel, rmrcallid)
-        }
+       for _, ep := range rtmgr.Eps {
+               go c.send_sync(ep, policies, rmrcallid)
+       }
 
        rmrcallid++
 
-        count := 0
-        result := make([]EPStatus, len(rtmgr.Eps))
-        for i, _ := range result {
-                result[i] = <-channel
-                if result[i].status == true {
-                        count++
-                } else {
-                        xapp.Logger.Error("RMR send failed for endpoint %v", result[i].endpoint)
-                }
-        }
-
-        if count < len(rtmgr.Eps) {
-                return errors.New(" RMR response count " + string(count) + " is less than half of endpoint list " + string(len(rtmgr.Eps)))
-        }
-
+       /*
+                               count := 0
+                       result := make([]EPStatus, len(rtmgr.Eps))
+                       for i, _ := range result {
+                               result[i] = <-channel
+                               if result[i].status == true {
+                                       count++
+                               } else {
+                                       xapp.Logger.Error("RMR send failed for endpoint %v", result[i].endpoint)
+                               }
+                       }
+
+                       if count < len(rtmgr.Eps) {
+                               return errors.New(" RMR response count " + string(count) + " is less than half of endpoint list " + string(len(rtmgr.Eps)))
+                       }*/
 
        return nil
 }
 
-func (c *RmrPush) send_sync(ep *rtmgr.Endpoint, policies *[]string, channel chan EPStatus, call_id int) {
-        xapp.Logger.Debug("Push policy to endpoint: " + ep.Uuid)
+//func (c *RmrPush) send_sync(ep *rtmgr.Endpoint, policies *[]string, channel chan EPStatus, call_id int) {
+func (c *RmrPush) send_sync(ep *rtmgr.Endpoint, policies *[]string, call_id int) {
+       xapp.Logger.Debug("Push policy to endpoint: " + ep.Uuid)
 
        ret := c.send_data(ep, policies, call_id)
+       xapp.Logger.Debug("return value is %v", ret)
+       conn.Lock()
+       rtmgr.RMRConnStatus[ep.Uuid] = ret
+       conn.Unlock()
+       // Handling per connection .. may be updating global map
 
-        channel <- EPStatus{ep.Uuid, ret}
+       //channel <- EPStatus{ep.Uuid, ret}
 
 }
 
 func (c *RmrPush) send_data(ep *rtmgr.Endpoint, policies *[]string, call_id int) bool {
-        xapp.Logger.Debug("Invoked send_data to endpoint: " + ep.Uuid + " call_id: " + strconv.Itoa(call_id))
-        var state int
-        var retstr string
+       xapp.Logger.Debug("Invoked send_data to endpoint: " + ep.Uuid + " call_id: " + strconv.Itoa(call_id))
+       var state int
+       var retstr string
 
-        var policy = []byte{}
+       var policy = []byte{}
 
-        for _, pe := range *policies {
-                b:= []byte(pe)
-                for j:=0; j<len(b); j++{
-                        policy = append(policy,b[j])
-                }
+       for _, pe := range *policies {
+               := []byte(pe)
+               for j := 0; j < len(b); j++ {
+                       policy = append(policy, b[j])
+               }
        }
-        params := &RMRParams{&xapp.RMRParams{}}
-        params.Mtype = 20
-        params.PayloadLen = len(policy)
-        params.Payload =[]byte(policy)
-        params.Mbuf = nil
-        params.Whid = ep.Whid
-        params.Callid = call_id
-        params.Timeout = 200
-        state, retstr = xapp.Rmr.SendCallMsg(params.RMRParams)
-       routestatus := strings.Split(retstr," ")
-        if state != C.RMR_OK && routestatus[0] != "OK" {
-              xapp.Logger.Error("Updating Routes to Endpoint: " + ep.Uuid + " failed, call_id: " + strconv.Itoa(call_id) + " for xapp.Rmr.SendCallMsg " + " Route Update Status: " + routestatus[0])
-              return false
-        } else {
+       params := &RMRParams{&xapp.RMRParams{}}
+       params.Mtype = 20
+       params.PayloadLen = len(policy)
+       params.Payload = []byte(policy)
+       params.Mbuf = nil
+       params.Whid = ep.Whid
+       params.Callid = call_id
+       params.Timeout = 200
+       state, retstr = xapp.Rmr.SendCallMsg(params.RMRParams)
+       routestatus := strings.Split(retstr, " ")
+       if state != C.RMR_OK && routestatus[0] != "OK" {
+               xapp.Logger.Error("Updating Routes to Endpoint: " + ep.Uuid + " failed, call_id: " + strconv.Itoa(call_id) + " for xapp.Rmr.SendCallMsg " + " Route Update Status: " + routestatus[0])
+               return false
+       } else {
                xapp.Logger.Info("Update Routes to Endpoint: " + ep.Uuid + " successful, call_id: " + strconv.Itoa(call_id) + ", Payload length: " + strconv.Itoa(params.PayloadLen) + ", Route Update Status: " + routestatus[0] + "(# of Entries:" + strconv.Itoa(len(*policies)))
-              return true
-        }
+               return true
+       }
 }
 
-func (c *RmrPush) CheckEndpoint(payload string)(ep *rtmgr.Endpoint)  {
+func (c *RmrPush) CheckEndpoint(payload string) (ep *rtmgr.Endpoint) {
        return c.checkEndpoint(payload)
 }
 
-func (c *RmrPush) CreateEndpoint(rmrsrc string)(ep *string,whid int)  {
+func (c *RmrPush) CreateEndpoint(rmrsrc string) (ep *string, whid int) {
        return c.createEndpoint(rmrsrc)
 }
 
@@ -199,44 +214,43 @@ func (c *RmrPush) DistributeToEp(policies *[]string, ep string, whid int) error
        xapp.Logger.Debug("args: %v", *policies)
 
        if rmrdynamiccallid == 255 {
-                rmrdynamiccallid = 201
-        }
+               rmrdynamiccallid = 201
+       }
 
-       go c.sendDynamicRoutes(ep, whid, policies,rmrdynamiccallid)
+       go c.sendDynamicRoutes(ep, whid, policies, rmrdynamiccallid)
        rmrdynamiccallid++
 
        return nil
 }
 
-func (c *RmrPush) sendDynamicRoutes(ep string,whid int, policies *[]string, call_id int) bool {
-        xapp.Logger.Debug("Invoked send_rt_process to endpoint: " + ep + " call_id: " + strconv.Itoa(call_id) + "whid: " + strconv.Itoa(whid))
-        var state int
-        var retstr string
-
-        var policy = []byte{}
-
-        for _, pe := range *policies {
-                b:= []byte(pe)
-                for j:=0; j<len(b); j++{
-                        policy = append(policy,b[j])
-                }
-        }
-        params := &RMRParams{&xapp.RMRParams{}}
-        params.Mtype = 20
-        params.PayloadLen = len(policy)
-        params.Payload =[]byte(policy)
-        params.Mbuf = nil
-        params.Whid = whid
-        params.Callid = call_id
-        params.Timeout = 200
-        state, retstr = xapp.Rmr.SendCallMsg(params.RMRParams)
-        routestatus := strings.Split(retstr," ")
-        if state != C.RMR_OK && routestatus[0] != "OK" {
-                xapp.Logger.Error("Updating Routes to Endpoint: " + ep + " failed, call_id: " + strconv.Itoa(call_id) + ",whi_id: " + strconv.Itoa(whid) + " for xapp.Rmr.SendCallMsg " + " Route Update Status: " + routestatus[0])
-              return false
-        } else {
-                xapp.Logger.Info("Update Routes to Endpoint: " + ep + " successful, call_id: " + strconv.Itoa(call_id) + ", Payload length: " + strconv.Itoa(params.PayloadLen) + ",whid: " + strconv.Itoa(whid) + ", Route Update Status: " + routestatus[0] + "(# of Entries:" + strconv.Itoa(len(*policies)))
-      return true
-        }
-}
+func (c *RmrPush) sendDynamicRoutes(ep string, whid int, policies *[]string, call_id int) bool {
+       xapp.Logger.Debug("Invoked send_rt_process to endpoint: " + ep + " call_id: " + strconv.Itoa(call_id) + "whid: " + strconv.Itoa(whid))
+       var state int
+       var retstr string
+
+       var policy = []byte{}
 
+       for _, pe := range *policies {
+               b := []byte(pe)
+               for j := 0; j < len(b); j++ {
+                       policy = append(policy, b[j])
+               }
+       }
+       params := &RMRParams{&xapp.RMRParams{}}
+       params.Mtype = 20
+       params.PayloadLen = len(policy)
+       params.Payload = []byte(policy)
+       params.Mbuf = nil
+       params.Whid = whid
+       params.Callid = call_id
+       params.Timeout = 200
+       state, retstr = xapp.Rmr.SendCallMsg(params.RMRParams)
+       routestatus := strings.Split(retstr, " ")
+       if state != C.RMR_OK && routestatus[0] != "OK" {
+               xapp.Logger.Error("Updating Routes to Endpoint: " + ep + " failed, call_id: " + strconv.Itoa(call_id) + ",whi_id: " + strconv.Itoa(whid) + " for xapp.Rmr.SendCallMsg " + " Route Update Status: " + routestatus[0])
+               return false
+       } else {
+               xapp.Logger.Info("Update Routes to Endpoint: " + ep + " successful, call_id: " + strconv.Itoa(call_id) + ", Payload length: " + strconv.Itoa(params.PayloadLen) + ",whid: " + strconv.Itoa(whid) + ", Route Update Status: " + routestatus[0] + "(# of Entries:" + strconv.Itoa(len(*policies)))
+               return true
+       }
+}
index 7ac6594..28274fc 100644 (file)
@@ -34,9 +34,9 @@ import (
        "gerrit.o-ran-sc.org/r/ric-plt/xapp-frame/pkg/xapp"
        "io/ioutil"
        "os"
-       "strings"
-       "routing-manager/pkg/rtmgr"
        "routing-manager/pkg/models"
+       "routing-manager/pkg/rtmgr"
+       "strings"
 )
 
 /*
@@ -113,101 +113,104 @@ func (f *File) WriteXApps(file string, xApps *[]rtmgr.XApp) error {
        return nil
 }
 
-func (f *File) WriteNewE2TInstance(file string, E2TInst *rtmgr.E2TInstance,meiddata string) error {
-        xapp.Logger.Debug("Invoked sdl.WriteNewE2TInstance")
-        xapp.Logger.Debug("file.WriteNewE2TInstance writes into file: " + file)
-        xapp.Logger.Debug("file.WriteNewE2TInstance writes data: %v", *E2TInst)
-
-        ricData, err := NewFile().ReadAll(file)
-        if err != nil {
-                xapp.Logger.Error("cannot get data from sdl interface due to: " + err.Error())
-                return errors.New("cannot read full ric data to modify xApps data, due to:  " + err.Error())
-        }
-        ricData.E2Ts[E2TInst.Fqdn] = *E2TInst
-       if (len(meiddata) > 0){
-           ricData.MeidMap = []string {meiddata}
-        } else {
-           ricData.MeidMap = []string {}
-       }
+func (f *File) WriteNewE2TInstance(file string, E2TInst *rtmgr.E2TInstance, meiddata string) error {
+       xapp.Logger.Debug("Invoked sdl.WriteNewE2TInstance")
+       xapp.Logger.Debug("file.WriteNewE2TInstance writes into file: " + file)
+       xapp.Logger.Debug("file.WriteNewE2TInstance writes data: %v", *E2TInst)
 
+       ricData, err := NewFile().ReadAll(file)
+       if err != nil {
+               xapp.Logger.Error("cannot get data from sdl interface due to: " + err.Error())
+               return errors.New("cannot read full ric data to modify xApps data, due to:  " + err.Error())
+       }
+       ricData.E2Ts[E2TInst.Fqdn] = *E2TInst
+       if len(meiddata) > 0 {
+               ricData.MeidMap = append(ricData.MeidMap, meiddata)
+       }
+       /*{
+                   ricData.MeidMap = []string {meiddata}
+               }
+                       else {
+                   ricData.MeidMap = []string {}
+               }*/
 
-        byteValue, err := json.Marshal(ricData)
-        if err != nil {
-                return errors.New("cannot convert data due to: " + err.Error())
-        }
-        err = ioutil.WriteFile(file, byteValue, 0644)
-        if err != nil {
-                return errors.New("cannot write file due to: " + err.Error())
-        }
-        return nil
+       byteValue, err := json.Marshal(ricData)
+       if err != nil {
+               return errors.New("cannot convert data due to: " + err.Error())
+       }
+       err = ioutil.WriteFile(file, byteValue, 0644)
+       if err != nil {
+               return errors.New("cannot write file due to: " + err.Error())
+       }
+       return nil
 }
 
 func (f *File) WriteAssRANToE2TInstance(file string, rane2tmap models.RanE2tMap) error {
-        xapp.Logger.Debug("Invoked sdl.WriteAssRANToE2TInstance")
-        xapp.Logger.Debug("file.WriteAssRANToE2TInstance writes into file: " + file)
-        xapp.Logger.Debug("file.WriteAssRANToE2TInstance writes data: %v", rane2tmap)
+       xapp.Logger.Debug("Invoked sdl.WriteAssRANToE2TInstance")
+       xapp.Logger.Debug("file.WriteAssRANToE2TInstance writes into file: " + file)
+       xapp.Logger.Debug("file.WriteAssRANToE2TInstance writes data: %v", rane2tmap)
 
-        ricData, err := NewFile().ReadAll(file)
-        if err != nil {
-                xapp.Logger.Error("cannot get data from sdl interface due to: " + err.Error())
-                return errors.New("cannot read full ric data to modify xApps data, due to:  " + err.Error())
-        }
+       ricData, err := NewFile().ReadAll(file)
+       if err != nil {
+               xapp.Logger.Error("cannot get data from sdl interface due to: " + err.Error())
+               return errors.New("cannot read full ric data to modify xApps data, due to:  " + err.Error())
+       }
 
-       ricData.MeidMap = []string{}
+       //ricData.MeidMap = []string{}
        for _, element := range rane2tmap {
                xapp.Logger.Info("data received")
-               var str,meidar string
+               var str, meidar string
                for _, meid := range element.RanNamelist {
-                   meidar += meid + " "
+                       meidar += meid + " "
                }
-               str = "mme_ar|" + *element.E2TAddress + "|" + strings.TrimSuffix(meidar," ")
-               ricData.MeidMap = append(ricData.MeidMap,str)
+               str = "mme_ar|" + *element.E2TAddress + "|" + strings.TrimSuffix(meidar, " ")
+               ricData.MeidMap = append(ricData.MeidMap, str)
 
                for key, _ := range ricData.E2Ts {
                        if key == *element.E2TAddress {
                                var estObj rtmgr.E2TInstance
                                estObj = ricData.E2Ts[key]
                                estObj.Ranlist = append(ricData.E2Ts[key].Ranlist, element.RanNamelist...)
-                               ricData.E2Ts[key]= estObj
+                               ricData.E2Ts[key] = estObj
                        }
                }
        }
 
        byteValue, err := json.Marshal(ricData)
-        if err != nil {
-                return errors.New("cannot convert data due to: " + err.Error())
-        }
-        err = ioutil.WriteFile(file, byteValue, 0644)
-        if err != nil {
-                return errors.New("cannot write file due to: " + err.Error())
-        }
-        return nil
+       if err != nil {
+               return errors.New("cannot convert data due to: " + err.Error())
+       }
+       err = ioutil.WriteFile(file, byteValue, 0644)
+       if err != nil {
+               return errors.New("cannot write file due to: " + err.Error())
+       }
+       return nil
 }
 
 func (f *File) WriteDisAssRANFromE2TInstance(file string, disassranmap models.RanE2tMap) error {
-        xapp.Logger.Debug("Invoked sdl.WriteDisAssRANFromE2TInstance")
-        xapp.Logger.Debug("file.WriteDisAssRANFromE2TInstance writes into file: " + file)
-        xapp.Logger.Debug("file.WriteDisAssRANFromE2TInstance writes data: %v", disassranmap)
-
-        ricData, err := NewFile().ReadAll(file)
-        if err != nil {
-                xapp.Logger.Error("cannot get data from sdl interface due to: " + err.Error())
-                return errors.New("cannot read full ric data to modify xApps data, due to:  " + err.Error())
-        }
-
-       var str,meiddel,meiddisdel string
-       ricData.MeidMap = []string{}
+       xapp.Logger.Debug("Invoked sdl.WriteDisAssRANFromE2TInstance")
+       xapp.Logger.Debug("file.WriteDisAssRANFromE2TInstance writes into file: " + file)
+       xapp.Logger.Debug("file.WriteDisAssRANFromE2TInstance writes data: %v", disassranmap)
+
+       ricData, err := NewFile().ReadAll(file)
+       if err != nil {
+               xapp.Logger.Error("cannot get data from sdl interface due to: " + err.Error())
+               return errors.New("cannot read full ric data to modify xApps data, due to:  " + err.Error())
+       }
+
+       var str, meiddel, meiddisdel string
+       //ricData.MeidMap = []string{}
        for _, element := range disassranmap {
                xapp.Logger.Info("data received")
                for _, meid := range element.RanNamelist {
-                   meiddisdel += meid + " "
+                       meiddisdel += meid + " "
+               }
+               if len(element.RanNamelist) > 0 {
+                       str = "mme_del|" + strings.TrimSuffix(meiddisdel, " ")
+                       ricData.MeidMap = append(ricData.MeidMap, str)
                }
-               if ( len(element.RanNamelist) > 0 ) {
-                   str = "mme_del|" + strings.TrimSuffix(meiddisdel," ")
-                   ricData.MeidMap = append(ricData.MeidMap,str)
-               }
                e2taddress_key := *element.E2TAddress
-               //Check whether the provided E2T Address is available in SDL as a key. 
+               //Check whether the provided E2T Address is available in SDL as a key.
                //If exist, proceed further to check RAN list, Otherwise move to next E2T Instance
                if _, exist := ricData.E2Ts[e2taddress_key]; exist {
                        var estObj rtmgr.E2TInstance
@@ -215,13 +218,13 @@ func (f *File) WriteDisAssRANFromE2TInstance(file string, disassranmap models.Ra
                        // If RAN list is empty, then routing manager assumes that all RANs attached associated to the particular E2T Instance to be removed.
                        if len(element.RanNamelist) == 0 {
                                xapp.Logger.Debug("RAN List is empty. So disassociating all RANs from the E2T Instance: %v ", *element.E2TAddress)
-                       for _, meid := range estObj.Ranlist {
-                       meiddel += meid + " "
-                       }
-                       str = "mme_del|" + strings.TrimSuffix(meiddel," ")
-                       ricData.MeidMap = append(ricData.MeidMap,str)
+                               for _, meid := range estObj.Ranlist {
+                                       meiddel += meid + " "
+                               }
+                               str = "mme_del|" + strings.TrimSuffix(meiddel, " ")
+                               ricData.MeidMap = append(ricData.MeidMap, str)
 
-                       estObj.Ranlist = []string{}
+                               estObj.Ranlist = []string{}
                        } else {
                                xapp.Logger.Debug("Remove only selected rans from E2T Instance: %v and %v ", ricData.E2Ts[e2taddress_key].Ranlist, element.RanNamelist)
                                for _, disRanValue := range element.RanNamelist {
@@ -234,20 +237,20 @@ func (f *File) WriteDisAssRANFromE2TInstance(file string, disassranmap models.Ra
                                        }
                                }
                        }
-                       ricData.E2Ts[e2taddress_key]= estObj
+                       ricData.E2Ts[e2taddress_key] = estObj
                }
        }
 
        xapp.Logger.Debug("Final data after disassociate: %v", ricData)
 
        byteValue, err := json.Marshal(ricData)
-        if err != nil {
-                return errors.New("cannot convert data due to: " + err.Error())
-        }
-        err = ioutil.WriteFile(file, byteValue, 0644)
-        if err != nil {
-                return errors.New("cannot write file due to: " + err.Error())
-        }
+       if err != nil {
+               return errors.New("cannot convert data due to: " + err.Error())
+       }
+       err = ioutil.WriteFile(file, byteValue, 0644)
+       if err != nil {
+               return errors.New("cannot write file due to: " + err.Error())
+       }
        return nil
 }
 
@@ -258,46 +261,45 @@ func (f *File) WriteDeleteE2TInstance(file string, E2TInst *models.E2tDeleteData
 
        ricData, err := NewFile().ReadAll(file)
        if err != nil {
-               xapp.Logger.Error("cannot get data from sdl interface due to: " + err.Error())
-               return errors.New("cannot read full ric data to modify xApps data, due to:  " + err.Error())
+               xapp.Logger.Error("cannot get data from sdl interface due to: " + err.Error())
+               return errors.New("cannot read full ric data to modify xApps data, due to:  " + err.Error())
        }
 
-
-       ricData.MeidMap = []string {}
-       var delrow,meiddel string
-       if(len(E2TInst.RanNamelistTobeDissociated)>0) {
-           for _, meid := range E2TInst.RanNamelistTobeDissociated {
+       //ricData.MeidMap = []string{}
+       var delrow, meiddel string
+       if len(E2TInst.RanNamelistTobeDissociated) > 0 {
+               for _, meid := range E2TInst.RanNamelistTobeDissociated {
                        meiddel += meid + " "
                }
-           delrow = "mme_del|" + strings.TrimSuffix(meiddel," ")
-           ricData.MeidMap = append(ricData.MeidMap,delrow)
+               delrow = "mme_del|" + strings.TrimSuffix(meiddel, " ")
+               ricData.MeidMap = append(ricData.MeidMap, delrow)
        } else {
-             if(len(ricData.E2Ts[*E2TInst.E2TAddress].Ranlist) > 0) {
-                 for _, meid := range ricData.E2Ts[*E2TInst.E2TAddress].Ranlist {
-                       meiddel += meid + " "
-                 }
-                 delrow = "mme_del|" + strings.TrimSuffix(meiddel," ")
-                 ricData.MeidMap = append(ricData.MeidMap,delrow)
-             }
+               if len(ricData.E2Ts[*E2TInst.E2TAddress].Ranlist) > 0 {
+                       for _, meid := range ricData.E2Ts[*E2TInst.E2TAddress].Ranlist {
+                               meiddel += meid + " "
+                       }
+                       delrow = "mme_del|" + strings.TrimSuffix(meiddel, " ")
+                       ricData.MeidMap = append(ricData.MeidMap, delrow)
+               }
        }
 
        delete(ricData.E2Ts, *E2TInst.E2TAddress)
 
        for _, element := range E2TInst.RanAssocList {
-               var str,meidar string
+               var str, meidar string
                xapp.Logger.Info("data received")
                for _, meid := range element.RanNamelist {
                        meidar = meid + " "
                }
-               str = "mme_ar|" + *element.E2TAddress + "|" + strings.TrimSuffix(meidar," ")
-               ricData.MeidMap = append(ricData.MeidMap,str)
+               str = "mme_ar|" + *element.E2TAddress + "|" + strings.TrimSuffix(meidar, " ")
+               ricData.MeidMap = append(ricData.MeidMap, str)
                key := *element.E2TAddress
 
                if val, ok := ricData.E2Ts[key]; ok {
                        var estObj rtmgr.E2TInstance
                        estObj = val
                        estObj.Ranlist = append(ricData.E2Ts[key].Ranlist, element.RanNamelist...)
-                       ricData.E2Ts[key]= estObj
+                       ricData.E2Ts[key] = estObj
                } else {
                        xapp.Logger.Error("file.WriteDeleteE2TInstance E2T instance is not found for provided E2TAddress : %v", errors.New(key).Error())
                }
@@ -306,11 +308,11 @@ func (f *File) WriteDeleteE2TInstance(file string, E2TInst *models.E2tDeleteData
 
        byteValue, err := json.Marshal(ricData)
        if err != nil {
-               return errors.New("cannot convert data due to: " + err.Error())
+               return errors.New("cannot convert data due to: " + err.Error())
        }
        err = ioutil.WriteFile(file, byteValue, 0644)
        if err != nil {
-               return errors.New("cannot write file due to: " + err.Error())
+               return errors.New("cannot write file due to: " + err.Error())
        }
        return nil
 }