blob: 41c1c4c19a7d67c1aec644a782f31b99f4df4d1b [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.
17==================================================================================
18*/
19/*
20 Mnemonic: rmr.go
21 Abstract: RMR Route Policy implementation
22 Produces RMR (RIC Management Routing) formatted route messages
23 Date: 16 March 2019
24*/
25
26package rpe
27
Peter Szilagyi16d84d62019-04-24 14:51:02 +000028import (
kalnagy92162652019-07-02 15:15:49 +020029 "routing-manager/pkg/rtmgr"
Peter Szilagyi16d84d62019-04-24 14:51:02 +000030 "strconv"
31)
Balint Uveges871fa392019-04-02 20:31:11 +000032
kalnagy92162652019-07-02 15:15:49 +020033type Rmr struct {
34 Rpe
35}
36
37type RmrPub struct {
38 Rmr
39}
40
41type RmrPush struct {
42 Rmr
43}
44
45func NewRmrPub() *RmrPub {
46 instance := new(RmrPub)
47 return instance
48}
49
50func NewRmrPush() *RmrPush {
51 instance := new(RmrPush)
52 return instance
53}
54
Balint Uveges871fa392019-04-02 20:31:11 +000055/*
56Produces the raw route message consumable by RMR
57*/
kalnagy92162652019-07-02 15:15:49 +020058func (r *Rmr) generateRMRPolicies(eps rtmgr.Endpoints, key string) *[]string {
Balint Uveges871fa392019-04-02 20:31:11 +000059 rawrt := []string{key + "newrt|start\n"}
kalnagy92162652019-07-02 15:15:49 +020060 rt := r.getRouteTable(eps)
Balint Uveges871fa392019-04-02 20:31:11 +000061 for _, rte := range *rt {
kalnagy92162652019-07-02 15:15:49 +020062 rawrte := key //+ "rte|" + rte.MessageType
63 if rte.SubID == -1 {
64 rawrte += "rte|"
65 } else {
66 rawrte += "mse|"
67 }
68 rawrte += rte.MessageType
Balint Uveges871fa392019-04-02 20:31:11 +000069 for _, tx := range rte.TxList {
Peter Szilagyi16d84d62019-04-24 14:51:02 +000070 rawrte += "," + tx.Ip + ":" + strconv.Itoa(int(tx.Port))
Balint Uveges871fa392019-04-02 20:31:11 +000071 }
kalnagy92162652019-07-02 15:15:49 +020072 rawrte += "|" + strconv.Itoa(int(rte.SubID)) + "|"
Balint Uveges871fa392019-04-02 20:31:11 +000073 group := ""
74 for _, rxg := range rte.RxGroups {
75 member := ""
76 for _, rx := range rxg {
77 if member == "" {
Peter Szilagyi16d84d62019-04-24 14:51:02 +000078 member += rx.Ip + ":" + strconv.Itoa(int(rx.Port))
Balint Uveges871fa392019-04-02 20:31:11 +000079 } else {
Peter Szilagyi16d84d62019-04-24 14:51:02 +000080 member += "," + rx.Ip + ":" + strconv.Itoa(int(rx.Port))
Balint Uveges871fa392019-04-02 20:31:11 +000081 }
82 }
83 if group == "" {
84 group += member
85 } else {
86 group += ";" + member
87 }
88 }
89 rawrte += group
90 rawrt = append(rawrt, rawrte+"\n")
91 }
92 rawrt = append(rawrt, key+"newrt|end\n")
kalnagy92162652019-07-02 15:15:49 +020093 rtmgr.Logger.Debug("rmr.GeneratePolicies returns: %v", rawrt)
Balint Uveges871fa392019-04-02 20:31:11 +000094 return &rawrt
95}
Peter Szilagyi16d84d62019-04-24 14:51:02 +000096
kalnagy92162652019-07-02 15:15:49 +020097func (r *RmrPub) GeneratePolicies(eps rtmgr.Endpoints) *[]string {
98 rtmgr.Logger.Debug("Invoked rmr.GeneratePolicies, args: %v: ", eps)
99 return r.generateRMRPolicies(eps, "00000 ")
Peter Szilagyi16d84d62019-04-24 14:51:02 +0000100}
101
kalnagy92162652019-07-02 15:15:49 +0200102func (r *RmrPush) GeneratePolicies(eps rtmgr.Endpoints) *[]string {
103 rtmgr.Logger.Debug("Invoked rmr.GeneratePolicies, args: %v: ", eps)
104 return r.generateRMRPolicies(eps, "")
Peter Szilagyi16d84d62019-04-24 14:51:02 +0000105}
kalnagy92162652019-07-02 15:15:49 +0200106
107func (r *RmrPub) GetRouteTable(eps rtmgr.Endpoints) *rtmgr.RouteTable {
108 return r.getRouteTable(eps)
109}
110
111func (r *RmrPush) GetRouteTable(eps rtmgr.Endpoints) *rtmgr.RouteTable {
112 return r.getRouteTable(eps)
113}
114