blob: 80323a3131096ed2785010e33d49735804270130 [file] [log] [blame]
Balint Uveges871fa392019-04-02 20:31:11 +00001/*
2==================================================================================
3 Copyright (c) 2019 AT&T Intellectual Property.
4 Copyright (c) 2019 Nokia
5
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
9
10 http://www.apache.org/licenses/LICENSE-2.0
11
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.
wahidw761934a2019-11-27 06:07:26 +000017
18
19 This source code is part of the near-RT RIC (RAN Intelligent Controller)
20 platform project (RICP).
21
Balint Uveges871fa392019-04-02 20:31:11 +000022==================================================================================
23*/
24/*
25 Mnemonic: rmr.go
26 Abstract: RMR Route Policy implementation
27 Produces RMR (RIC Management Routing) formatted route messages
28 Date: 16 March 2019
29*/
30
31package rpe
32
Peter Szilagyi16d84d62019-04-24 14:51:02 +000033import (
wahidwa8596ec2019-12-05 06:30:42 +000034 "gerrit.o-ran-sc.org/r/ric-plt/xapp-frame/pkg/xapp"
kalnagy92162652019-07-02 15:15:49 +020035 "routing-manager/pkg/rtmgr"
Peter Szilagyi16d84d62019-04-24 14:51:02 +000036 "strconv"
prabhukaliswamye110ee02019-12-23 09:51:01 +000037 "strings"
Peter Szilagyi16d84d62019-04-24 14:51:02 +000038)
Balint Uveges871fa392019-04-02 20:31:11 +000039
kalnagy92162652019-07-02 15:15:49 +020040type Rmr struct {
41 Rpe
42}
43
kalnagy92162652019-07-02 15:15:49 +020044type RmrPush struct {
45 Rmr
46}
47
kalnagy92162652019-07-02 15:15:49 +020048func NewRmrPush() *RmrPush {
49 instance := new(RmrPush)
50 return instance
51}
52
Balint Uveges871fa392019-04-02 20:31:11 +000053/*
54Produces the raw route message consumable by RMR
55*/
prabhukaliswamye110ee02019-12-23 09:51:01 +000056func (r *Rmr) generateRMRPolicies(eps rtmgr.Endpoints, rcs *rtmgr.RicComponents, key string) *[]string {
Balint Uveges871fa392019-04-02 20:31:11 +000057 rawrt := []string{key + "newrt|start\n"}
zkoczkaeb2ff0d2019-09-26 16:59:54 +020058 rt := r.generateRouteTable(eps)
Balint Uveges871fa392019-04-02 20:31:11 +000059 for _, rte := range *rt {
1000044e90ddda2019-08-01 09:58:52 +020060 rawrte := key + "mse|" + rte.MessageType
Balint Uveges871fa392019-04-02 20:31:11 +000061 for _, tx := range rte.TxList {
Peter Szilagyi16d84d62019-04-24 14:51:02 +000062 rawrte += "," + tx.Ip + ":" + strconv.Itoa(int(tx.Port))
Balint Uveges871fa392019-04-02 20:31:11 +000063 }
kalnagy92162652019-07-02 15:15:49 +020064 rawrte += "|" + strconv.Itoa(int(rte.SubID)) + "|"
Balint Uveges871fa392019-04-02 20:31:11 +000065 group := ""
66 for _, rxg := range rte.RxGroups {
67 member := ""
68 for _, rx := range rxg {
69 if member == "" {
Peter Szilagyi16d84d62019-04-24 14:51:02 +000070 member += rx.Ip + ":" + strconv.Itoa(int(rx.Port))
Balint Uveges871fa392019-04-02 20:31:11 +000071 } else {
Peter Szilagyi16d84d62019-04-24 14:51:02 +000072 member += "," + rx.Ip + ":" + strconv.Itoa(int(rx.Port))
Balint Uveges871fa392019-04-02 20:31:11 +000073 }
74 }
75 if group == "" {
76 group += member
77 } else {
78 group += ";" + member
79 }
80 }
81 rawrte += group
rangajal749099b2019-12-10 09:37:08 +000082
83 if (rte.RouteType == "%meid") {
84 rawrte += group + rte.RouteType
85 }
86
Balint Uveges871fa392019-04-02 20:31:11 +000087 rawrt = append(rawrt, rawrte+"\n")
88 }
89 rawrt = append(rawrt, key+"newrt|end\n")
rangajal749099b2019-12-10 09:37:08 +000090 count := 0
prabhukaliswamye110ee02019-12-23 09:51:01 +000091 meidrt := key +"meid_map|start\n"
92 for e2tkey, value := range rcs.E2Ts {
93 xapp.Logger.Debug("rmr.E2T Key: %v", e2tkey)
94 xapp.Logger.Debug("rmr.E2T Value: %v", value)
95 xapp.Logger.Debug("rmr.E2T RAN List: %v", rcs.E2Ts[e2tkey].Ranlist)
96 if ( len(rcs.E2Ts[e2tkey].Ranlist) != 0 ) {
97 ranList := strings.Join(rcs.E2Ts[e2tkey].Ranlist, " ")
98 meidrt += key + "mme_ar|" + e2tkey + "|" + ranList + "\n"
99 count++
100 } else {
101 xapp.Logger.Debug("rmr.E2T Empty RAN LIST for FQDN: %v", e2tkey)
102 }
103 }
104 meidrt += key+"meid_map|end|" + strconv.Itoa(count) +"\n"
rangajal749099b2019-12-10 09:37:08 +0000105
prabhukaliswamye110ee02019-12-23 09:51:01 +0000106 rawrt = append(rawrt, meidrt)
wahidwa8596ec2019-12-05 06:30:42 +0000107 xapp.Logger.Debug("rmr.GeneratePolicies returns: %v", rawrt)
prabhukaliswamye110ee02019-12-23 09:51:01 +0000108 xapp.Logger.Debug("rmr.GeneratePolicies returns: %v", rcs)
Balint Uveges871fa392019-04-02 20:31:11 +0000109 return &rawrt
110}
Peter Szilagyi16d84d62019-04-24 14:51:02 +0000111
prabhukaliswamye110ee02019-12-23 09:51:01 +0000112func (r *RmrPush) GeneratePolicies(eps rtmgr.Endpoints, rcs *rtmgr.RicComponents) *[]string {
wahidwa8596ec2019-12-05 06:30:42 +0000113 xapp.Logger.Debug("Invoked rmr.GeneratePolicies, args: %v: ", eps)
prabhukaliswamye110ee02019-12-23 09:51:01 +0000114 return r.generateRMRPolicies(eps, rcs, "")
Peter Szilagyi16d84d62019-04-24 14:51:02 +0000115}
kalnagy92162652019-07-02 15:15:49 +0200116
zkoczkaeb2ff0d2019-09-26 16:59:54 +0200117func (r *RmrPush) GenerateRouteTable(eps rtmgr.Endpoints) *rtmgr.RouteTable {
118 return r.generateRouteTable(eps)
kalnagy92162652019-07-02 15:15:49 +0200119}