2 ==================================================================================
3 Copyright (c) 2019 AT&T Intellectual Property.
4 Copyright (c) 2019 Nokia
6 Licensed under the Apache License, Version 2.0 (the "License");
7 you may not use this file except in compliance with the License.
8 You may obtain a copy of the License at
10 http://www.apache.org/licenses/LICENSE-2.0
12 Unless required by applicable law or agreed to in writing, software
13 distributed under the License is distributed on an "AS IS" BASIS,
14 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 See the License for the specific language governing permissions and
16 limitations under the License.
19 This source code is part of the near-RT RIC (RAN Intelligent Controller)
20 platform project (RICP).
22 ==================================================================================
26 Abstract: RMR Route Policy implementation
27 Produces RMR (RIC Management Routing) formatted route messages
34 "gerrit.o-ran-sc.org/r/ric-plt/xapp-frame/pkg/xapp"
35 "routing-manager/pkg/models"
36 "routing-manager/pkg/rtmgr"
49 func NewRmrPush() *RmrPush {
50 instance := new(RmrPush)
55 Produces the raw route message consumable by RMR
57 func (r *Rmr) generateRMRPolicies(eps rtmgr.Endpoints, rcs *rtmgr.RicComponents, key string) *[]string {
58 rawrt := []string{key + "newrt|start\n"}
59 rt := r.generateRouteTable(eps)
60 for _, rte := range *rt {
61 rawrte := key + "mse|" + rte.MessageType
62 for _, tx := range rte.TxList {
63 rawrte += "," + tx.Ip + ":" + strconv.Itoa(int(tx.Port))
65 rawrte += "|" + strconv.Itoa(int(rte.SubID)) + "|"
67 for _, rxg := range rte.RxGroups {
69 for _, rx := range rxg {
71 member += rx.Ip + ":" + strconv.Itoa(int(rx.Port))
73 member += "," + rx.Ip + ":" + strconv.Itoa(int(rx.Port))
83 if rte.RouteType == "%meid" {
84 rawrte += "%" + "meid"
89 rawrt = append(rawrt, rawrte+"\n")
91 for _, val := range rtmgr.DynamicRouteList {
92 rawrt = append(rawrt, val)
95 rawrt = append(rawrt, key+"newrt|end\n")
98 rawrt = append(rawrt, key+"meid_map|start\n")
100 keys := make(map[string]MeidEntry)
104 for _, value := range rcs.MeidMap {
105 if strings.Contains(value, "mme_ar") {
106 tmpstr := strings.Split(value, "|")
107 //MEID entry for mme_ar must always contain 3 strings speartred by | i.e "mme_ar|<string1>|<string2>"
108 MEID = strings.TrimSuffix(tmpstr[2], "\n")
109 E2TIP = strings.TrimSuffix(tmpstr[1], "\n")
111 } else if strings.Contains(value, "mme_del") {
112 tmpstr := strings.Split(value, "|")
113 MEID = strings.TrimSuffix(tmpstr[1], "\n")
117 keys[MEID] = MeidEntry{RECTYP, E2TIP}
120 for k, v := range keys {
121 if v.recordtype == "mme_ar" {
122 rawrt = append(rawrt, key+v.recordtype+"|"+v.e2tip+"|"+k+"\n")
127 rawrt = removeEmptyStrings(rawrt)
128 rawrt = append(rawrt, key+"meid_map|end|"+strconv.Itoa(count)+"\n")
130 xapp.Logger.Debug("rmr.GeneratePolicies returns: %v", rawrt)
131 xapp.Logger.Debug("rmr.GeneratePolicies returns: %v", rcs)
136 Produces the raw route message consumable by RMR
138 func (r *Rmr) generatePartialRMRPolicies(eps rtmgr.Endpoints, xappSubData *models.XappSubscriptionData, key string, updatetype rtmgr.RMRUpdateType) *[]string {
139 rawrt := []string{key + "updatert|start\n"}
140 rt := r.generatePartialRouteTable(eps, xappSubData, updatetype)
141 for _, rte := range *rt {
142 rawrte := key + "mse|" + rte.MessageType
143 for _, tx := range rte.TxList {
144 rawrte += "," + tx.Ip + ":" + strconv.Itoa(int(tx.Port))
146 rawrte += "|" + strconv.Itoa(int(rte.SubID)) + "|"
148 for _, rxg := range rte.RxGroups {
150 for _, rx := range rxg {
152 member += rx.Ip + ":" + strconv.Itoa(int(rx.Port))
154 member += "," + rx.Ip + ":" + strconv.Itoa(int(rx.Port))
160 group += ";" + member
164 if rte.RouteType == "%meid" {
165 rawrte += "%" + "meid"
170 rawrt = append(rawrt, rawrte+"\n")
173 rawrt = append(rawrt, key+"updatert|end\n")
176 xapp.Logger.Debug("rmr.GeneratePolicies returns: %v", rawrt)
179 func (r *RmrPush) GeneratePolicies(eps rtmgr.Endpoints, rcs *rtmgr.RicComponents) *[]string {
180 xapp.Logger.Debug("Invoked rmr.GeneratePolicies, args: %v: ", eps)
181 return r.generateRMRPolicies(eps, rcs, "")
184 func (r *RmrPush) GenerateRouteTable(eps rtmgr.Endpoints) *rtmgr.RouteTable {
185 return r.generateRouteTable(eps)
188 func (r *RmrPush) GeneratePartialPolicies(eps rtmgr.Endpoints, xappSubData *models.XappSubscriptionData, updatetype rtmgr.RMRUpdateType) *[]string {
189 xapp.Logger.Debug("Invoked rmr.GeneratePartialPolicies, args: %v: ", eps)
190 return r.generatePartialRMRPolicies(eps, xappSubData, "", updatetype)
193 func removeEmptyStrings(s []string) []string {
195 for _, str := range s {