blob: 41c1c4c19a7d67c1aec644a782f31b99f4df4d1b [file] [log] [blame]
/*
==================================================================================
Copyright (c) 2019 AT&T Intellectual Property.
Copyright (c) 2019 Nokia
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
==================================================================================
*/
/*
Mnemonic: rmr.go
Abstract: RMR Route Policy implementation
Produces RMR (RIC Management Routing) formatted route messages
Date: 16 March 2019
*/
package rpe
import (
"routing-manager/pkg/rtmgr"
"strconv"
)
type Rmr struct {
Rpe
}
type RmrPub struct {
Rmr
}
type RmrPush struct {
Rmr
}
func NewRmrPub() *RmrPub {
instance := new(RmrPub)
return instance
}
func NewRmrPush() *RmrPush {
instance := new(RmrPush)
return instance
}
/*
Produces the raw route message consumable by RMR
*/
func (r *Rmr) generateRMRPolicies(eps rtmgr.Endpoints, key string) *[]string {
rawrt := []string{key + "newrt|start\n"}
rt := r.getRouteTable(eps)
for _, rte := range *rt {
rawrte := key //+ "rte|" + rte.MessageType
if rte.SubID == -1 {
rawrte += "rte|"
} else {
rawrte += "mse|"
}
rawrte += rte.MessageType
for _, tx := range rte.TxList {
rawrte += "," + tx.Ip + ":" + strconv.Itoa(int(tx.Port))
}
rawrte += "|" + strconv.Itoa(int(rte.SubID)) + "|"
group := ""
for _, rxg := range rte.RxGroups {
member := ""
for _, rx := range rxg {
if member == "" {
member += rx.Ip + ":" + strconv.Itoa(int(rx.Port))
} else {
member += "," + rx.Ip + ":" + strconv.Itoa(int(rx.Port))
}
}
if group == "" {
group += member
} else {
group += ";" + member
}
}
rawrte += group
rawrt = append(rawrt, rawrte+"\n")
}
rawrt = append(rawrt, key+"newrt|end\n")
rtmgr.Logger.Debug("rmr.GeneratePolicies returns: %v", rawrt)
return &rawrt
}
func (r *RmrPub) GeneratePolicies(eps rtmgr.Endpoints) *[]string {
rtmgr.Logger.Debug("Invoked rmr.GeneratePolicies, args: %v: ", eps)
return r.generateRMRPolicies(eps, "00000 ")
}
func (r *RmrPush) GeneratePolicies(eps rtmgr.Endpoints) *[]string {
rtmgr.Logger.Debug("Invoked rmr.GeneratePolicies, args: %v: ", eps)
return r.generateRMRPolicies(eps, "")
}
func (r *RmrPub) GetRouteTable(eps rtmgr.Endpoints) *rtmgr.RouteTable {
return r.getRouteTable(eps)
}
func (r *RmrPush) GetRouteTable(eps rtmgr.Endpoints) *rtmgr.RouteTable {
return r.getRouteTable(eps)
}