Balint Uveges | 871fa39 | 2019-04-02 20:31:11 +0000 | [diff] [blame] | 1 | /* |
| 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 | |
| 26 | package rpe |
| 27 | |
Peter Szilagyi | 16d84d6 | 2019-04-24 14:51:02 +0000 | [diff] [blame] | 28 | import ( |
| 29 | "rtmgr" |
| 30 | "strconv" |
| 31 | ) |
Balint Uveges | 871fa39 | 2019-04-02 20:31:11 +0000 | [diff] [blame] | 32 | |
| 33 | /* |
| 34 | Produces the raw route message consumable by RMR |
| 35 | */ |
Peter Szilagyi | 16d84d6 | 2019-04-24 14:51:02 +0000 | [diff] [blame] | 36 | func generateRMRPolicies(eps rtmgr.Endpoints, key string) *[]string { |
Balint Uveges | 871fa39 | 2019-04-02 20:31:11 +0000 | [diff] [blame] | 37 | rtmgr.Logger.Debug("Invoked rmr.generateRMRPolicies") |
Peter Szilagyi | 16d84d6 | 2019-04-24 14:51:02 +0000 | [diff] [blame] | 38 | rtmgr.Logger.Debug("args: %v", eps) |
Balint Uveges | 871fa39 | 2019-04-02 20:31:11 +0000 | [diff] [blame] | 39 | rawrt := []string{key + "newrt|start\n"} |
Peter Szilagyi | 16d84d6 | 2019-04-24 14:51:02 +0000 | [diff] [blame] | 40 | rt := getRouteTable(eps) |
Balint Uveges | 871fa39 | 2019-04-02 20:31:11 +0000 | [diff] [blame] | 41 | for _, rte := range *rt { |
| 42 | rawrte := key + "rte|" + rte.MessageType |
| 43 | for _, tx := range rte.TxList { |
Peter Szilagyi | 16d84d6 | 2019-04-24 14:51:02 +0000 | [diff] [blame] | 44 | rawrte += "," + tx.Ip + ":" + strconv.Itoa(int(tx.Port)) |
Balint Uveges | 871fa39 | 2019-04-02 20:31:11 +0000 | [diff] [blame] | 45 | } |
| 46 | rawrte += "|" |
| 47 | group := "" |
| 48 | for _, rxg := range rte.RxGroups { |
| 49 | member := "" |
| 50 | for _, rx := range rxg { |
| 51 | if member == "" { |
Peter Szilagyi | 16d84d6 | 2019-04-24 14:51:02 +0000 | [diff] [blame] | 52 | member += rx.Ip + ":" + strconv.Itoa(int(rx.Port)) |
Balint Uveges | 871fa39 | 2019-04-02 20:31:11 +0000 | [diff] [blame] | 53 | } else { |
Peter Szilagyi | 16d84d6 | 2019-04-24 14:51:02 +0000 | [diff] [blame] | 54 | member += "," + rx.Ip + ":" + strconv.Itoa(int(rx.Port)) |
Balint Uveges | 871fa39 | 2019-04-02 20:31:11 +0000 | [diff] [blame] | 55 | } |
| 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 Szilagyi | 16d84d6 | 2019-04-24 14:51:02 +0000 | [diff] [blame] | 70 | |
| 71 | func generateRMRPubPolicies(eps rtmgr.Endpoints) *[]string { |
| 72 | return generateRMRPolicies(eps, "00000 ") |
| 73 | } |
| 74 | |
| 75 | func generateRMRPushPolicies(eps rtmgr.Endpoints) *[]string { |
| 76 | return generateRMRPolicies(eps, "") |
| 77 | } |