blob: cb311a8f0a5d2797f4f968a354f618ff21605b5f [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 (
kalnagy92162652019-07-02 15:15:49 +020034 "routing-manager/pkg/rtmgr"
Peter Szilagyi16d84d62019-04-24 14:51:02 +000035 "strconv"
36)
Balint Uveges871fa392019-04-02 20:31:11 +000037
kalnagy92162652019-07-02 15:15:49 +020038type Rmr struct {
39 Rpe
40}
41
kalnagy92162652019-07-02 15:15:49 +020042type RmrPush struct {
43 Rmr
44}
45
kalnagy92162652019-07-02 15:15:49 +020046func NewRmrPush() *RmrPush {
47 instance := new(RmrPush)
48 return instance
49}
50
Balint Uveges871fa392019-04-02 20:31:11 +000051/*
52Produces the raw route message consumable by RMR
53*/
kalnagy92162652019-07-02 15:15:49 +020054func (r *Rmr) generateRMRPolicies(eps rtmgr.Endpoints, key string) *[]string {
Balint Uveges871fa392019-04-02 20:31:11 +000055 rawrt := []string{key + "newrt|start\n"}
zkoczkaeb2ff0d2019-09-26 16:59:54 +020056 rt := r.generateRouteTable(eps)
Balint Uveges871fa392019-04-02 20:31:11 +000057 for _, rte := range *rt {
1000044e90ddda2019-08-01 09:58:52 +020058 rawrte := key + "mse|" + rte.MessageType
Balint Uveges871fa392019-04-02 20:31:11 +000059 for _, tx := range rte.TxList {
Peter Szilagyi16d84d62019-04-24 14:51:02 +000060 rawrte += "," + tx.Ip + ":" + strconv.Itoa(int(tx.Port))
Balint Uveges871fa392019-04-02 20:31:11 +000061 }
kalnagy92162652019-07-02 15:15:49 +020062 rawrte += "|" + strconv.Itoa(int(rte.SubID)) + "|"
Balint Uveges871fa392019-04-02 20:31:11 +000063 group := ""
64 for _, rxg := range rte.RxGroups {
65 member := ""
66 for _, rx := range rxg {
67 if member == "" {
Peter Szilagyi16d84d62019-04-24 14:51:02 +000068 member += rx.Ip + ":" + strconv.Itoa(int(rx.Port))
Balint Uveges871fa392019-04-02 20:31:11 +000069 } else {
Peter Szilagyi16d84d62019-04-24 14:51:02 +000070 member += "," + rx.Ip + ":" + strconv.Itoa(int(rx.Port))
Balint Uveges871fa392019-04-02 20:31:11 +000071 }
72 }
73 if group == "" {
74 group += member
75 } else {
76 group += ";" + member
77 }
78 }
79 rawrte += group
80 rawrt = append(rawrt, rawrte+"\n")
81 }
82 rawrt = append(rawrt, key+"newrt|end\n")
kalnagy92162652019-07-02 15:15:49 +020083 rtmgr.Logger.Debug("rmr.GeneratePolicies returns: %v", rawrt)
Balint Uveges871fa392019-04-02 20:31:11 +000084 return &rawrt
85}
Peter Szilagyi16d84d62019-04-24 14:51:02 +000086
kalnagy92162652019-07-02 15:15:49 +020087func (r *RmrPush) GeneratePolicies(eps rtmgr.Endpoints) *[]string {
88 rtmgr.Logger.Debug("Invoked rmr.GeneratePolicies, args: %v: ", eps)
89 return r.generateRMRPolicies(eps, "")
Peter Szilagyi16d84d62019-04-24 14:51:02 +000090}
kalnagy92162652019-07-02 15:15:49 +020091
zkoczkaeb2ff0d2019-09-26 16:59:54 +020092func (r *RmrPush) GenerateRouteTable(eps rtmgr.Endpoints) *rtmgr.RouteTable {
93 return r.generateRouteTable(eps)
kalnagy92162652019-07-02 15:15:49 +020094}