blob: ca16772dbe8ea3b041a1bc135405100c0e5c3cac [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 (
29 "rtmgr"
30 "strconv"
31)
Balint Uveges871fa392019-04-02 20:31:11 +000032
33/*
34Produces the raw route message consumable by RMR
35*/
Peter Szilagyi16d84d62019-04-24 14:51:02 +000036func generateRMRPolicies(eps rtmgr.Endpoints, key string) *[]string {
Balint Uveges871fa392019-04-02 20:31:11 +000037 rtmgr.Logger.Debug("Invoked rmr.generateRMRPolicies")
Peter Szilagyi16d84d62019-04-24 14:51:02 +000038 rtmgr.Logger.Debug("args: %v", eps)
Balint Uveges871fa392019-04-02 20:31:11 +000039 rawrt := []string{key + "newrt|start\n"}
Peter Szilagyi16d84d62019-04-24 14:51:02 +000040 rt := getRouteTable(eps)
Balint Uveges871fa392019-04-02 20:31:11 +000041 for _, rte := range *rt {
42 rawrte := key + "rte|" + rte.MessageType
43 for _, tx := range rte.TxList {
Peter Szilagyi16d84d62019-04-24 14:51:02 +000044 rawrte += "," + tx.Ip + ":" + strconv.Itoa(int(tx.Port))
Balint Uveges871fa392019-04-02 20:31:11 +000045 }
46 rawrte += "|"
47 group := ""
48 for _, rxg := range rte.RxGroups {
49 member := ""
50 for _, rx := range rxg {
51 if member == "" {
Peter Szilagyi16d84d62019-04-24 14:51:02 +000052 member += rx.Ip + ":" + strconv.Itoa(int(rx.Port))
Balint Uveges871fa392019-04-02 20:31:11 +000053 } else {
Peter Szilagyi16d84d62019-04-24 14:51:02 +000054 member += "," + rx.Ip + ":" + strconv.Itoa(int(rx.Port))
Balint Uveges871fa392019-04-02 20:31:11 +000055 }
56 }
57 if group == "" {
58 group += member
59 } else {
60 group += ";" + member
61 }
62 }
63 rawrte += group
64 rawrt = append(rawrt, rawrte+"\n")
65 }
66 rawrt = append(rawrt, key+"newrt|end\n")
67 rtmgr.Logger.Debug("rmr.generateRMRPolicies returns: %v", rawrt)
68 return &rawrt
69}
Peter Szilagyi16d84d62019-04-24 14:51:02 +000070
71func generateRMRPubPolicies(eps rtmgr.Endpoints) *[]string {
72 return generateRMRPolicies(eps, "00000 ")
73}
74
75func generateRMRPushPolicies(eps rtmgr.Endpoints) *[]string {
76 return generateRMRPolicies(eps, "")
77}