blob: 6fc8c9f60751399b71199d151b02b956aa0697a4 [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"
37)
Balint Uveges871fa392019-04-02 20:31:11 +000038
kalnagy92162652019-07-02 15:15:49 +020039type Rmr struct {
40 Rpe
41}
42
kalnagy92162652019-07-02 15:15:49 +020043type RmrPush struct {
44 Rmr
45}
46
kalnagy92162652019-07-02 15:15:49 +020047func NewRmrPush() *RmrPush {
48 instance := new(RmrPush)
49 return instance
50}
51
Balint Uveges871fa392019-04-02 20:31:11 +000052/*
53Produces the raw route message consumable by RMR
54*/
kalnagy92162652019-07-02 15:15:49 +020055func (r *Rmr) generateRMRPolicies(eps rtmgr.Endpoints, key string) *[]string {
Balint Uveges871fa392019-04-02 20:31:11 +000056 rawrt := []string{key + "newrt|start\n"}
zkoczkaeb2ff0d2019-09-26 16:59:54 +020057 rt := r.generateRouteTable(eps)
Balint Uveges871fa392019-04-02 20:31:11 +000058 for _, rte := range *rt {
1000044e90ddda2019-08-01 09:58:52 +020059 rawrte := key + "mse|" + rte.MessageType
Balint Uveges871fa392019-04-02 20:31:11 +000060 for _, tx := range rte.TxList {
Peter Szilagyi16d84d62019-04-24 14:51:02 +000061 rawrte += "," + tx.Ip + ":" + strconv.Itoa(int(tx.Port))
Balint Uveges871fa392019-04-02 20:31:11 +000062 }
kalnagy92162652019-07-02 15:15:49 +020063 rawrte += "|" + strconv.Itoa(int(rte.SubID)) + "|"
Balint Uveges871fa392019-04-02 20:31:11 +000064 group := ""
65 for _, rxg := range rte.RxGroups {
66 member := ""
67 for _, rx := range rxg {
68 if member == "" {
Peter Szilagyi16d84d62019-04-24 14:51:02 +000069 member += rx.Ip + ":" + strconv.Itoa(int(rx.Port))
Balint Uveges871fa392019-04-02 20:31:11 +000070 } else {
Peter Szilagyi16d84d62019-04-24 14:51:02 +000071 member += "," + rx.Ip + ":" + strconv.Itoa(int(rx.Port))
Balint Uveges871fa392019-04-02 20:31:11 +000072 }
73 }
74 if group == "" {
75 group += member
76 } else {
77 group += ";" + member
78 }
79 }
80 rawrte += group
rangajal749099b2019-12-10 09:37:08 +000081
82 if (rte.RouteType == "%meid") {
83 rawrte += group + rte.RouteType
84 }
85
Balint Uveges871fa392019-04-02 20:31:11 +000086 rawrt = append(rawrt, rawrte+"\n")
87 }
88 rawrt = append(rawrt, key+"newrt|end\n")
rangajal749099b2019-12-10 09:37:08 +000089
90 count := 0
91 rawrt = append(rawrt, key+"meid_map|start\n")
92 rawrt = append(rawrt, key+"meid_map|end|" + strconv.Itoa(count) +"\n")
93
wahidwa8596ec2019-12-05 06:30:42 +000094 xapp.Logger.Debug("rmr.GeneratePolicies returns: %v", rawrt)
Balint Uveges871fa392019-04-02 20:31:11 +000095 return &rawrt
96}
Peter Szilagyi16d84d62019-04-24 14:51:02 +000097
kalnagy92162652019-07-02 15:15:49 +020098func (r *RmrPush) GeneratePolicies(eps rtmgr.Endpoints) *[]string {
wahidwa8596ec2019-12-05 06:30:42 +000099 xapp.Logger.Debug("Invoked rmr.GeneratePolicies, args: %v: ", eps)
kalnagy92162652019-07-02 15:15:49 +0200100 return r.generateRMRPolicies(eps, "")
Peter Szilagyi16d84d62019-04-24 14:51:02 +0000101}
kalnagy92162652019-07-02 15:15:49 +0200102
zkoczkaeb2ff0d2019-09-26 16:59:54 +0200103func (r *RmrPush) GenerateRouteTable(eps rtmgr.Endpoints) *rtmgr.RouteTable {
104 return r.generateRouteTable(eps)
kalnagy92162652019-07-02 15:15:49 +0200105}