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 ( |
kalnagy | 9216265 | 2019-07-02 15:15:49 +0200 | [diff] [blame] | 29 | "routing-manager/pkg/rtmgr" |
Peter Szilagyi | 16d84d6 | 2019-04-24 14:51:02 +0000 | [diff] [blame] | 30 | "strconv" |
| 31 | ) |
Balint Uveges | 871fa39 | 2019-04-02 20:31:11 +0000 | [diff] [blame] | 32 | |
kalnagy | 9216265 | 2019-07-02 15:15:49 +0200 | [diff] [blame] | 33 | type Rmr struct { |
| 34 | Rpe |
| 35 | } |
| 36 | |
| 37 | type RmrPub struct { |
| 38 | Rmr |
| 39 | } |
| 40 | |
| 41 | type RmrPush struct { |
| 42 | Rmr |
| 43 | } |
| 44 | |
| 45 | func NewRmrPub() *RmrPub { |
| 46 | instance := new(RmrPub) |
| 47 | return instance |
| 48 | } |
| 49 | |
| 50 | func NewRmrPush() *RmrPush { |
| 51 | instance := new(RmrPush) |
| 52 | return instance |
| 53 | } |
| 54 | |
Balint Uveges | 871fa39 | 2019-04-02 20:31:11 +0000 | [diff] [blame] | 55 | /* |
| 56 | Produces the raw route message consumable by RMR |
| 57 | */ |
kalnagy | 9216265 | 2019-07-02 15:15:49 +0200 | [diff] [blame] | 58 | func (r *Rmr) generateRMRPolicies(eps rtmgr.Endpoints, key string) *[]string { |
Balint Uveges | 871fa39 | 2019-04-02 20:31:11 +0000 | [diff] [blame] | 59 | rawrt := []string{key + "newrt|start\n"} |
kalnagy | 9216265 | 2019-07-02 15:15:49 +0200 | [diff] [blame] | 60 | rt := r.getRouteTable(eps) |
Balint Uveges | 871fa39 | 2019-04-02 20:31:11 +0000 | [diff] [blame] | 61 | for _, rte := range *rt { |
1000044 | e90ddda | 2019-08-01 09:58:52 +0200 | [diff] [blame^] | 62 | rawrte := key + "mse|" + rte.MessageType |
Balint Uveges | 871fa39 | 2019-04-02 20:31:11 +0000 | [diff] [blame] | 63 | for _, tx := range rte.TxList { |
Peter Szilagyi | 16d84d6 | 2019-04-24 14:51:02 +0000 | [diff] [blame] | 64 | rawrte += "," + tx.Ip + ":" + strconv.Itoa(int(tx.Port)) |
Balint Uveges | 871fa39 | 2019-04-02 20:31:11 +0000 | [diff] [blame] | 65 | } |
kalnagy | 9216265 | 2019-07-02 15:15:49 +0200 | [diff] [blame] | 66 | rawrte += "|" + strconv.Itoa(int(rte.SubID)) + "|" |
Balint Uveges | 871fa39 | 2019-04-02 20:31:11 +0000 | [diff] [blame] | 67 | group := "" |
| 68 | for _, rxg := range rte.RxGroups { |
| 69 | member := "" |
| 70 | for _, rx := range rxg { |
| 71 | if member == "" { |
Peter Szilagyi | 16d84d6 | 2019-04-24 14:51:02 +0000 | [diff] [blame] | 72 | member += rx.Ip + ":" + strconv.Itoa(int(rx.Port)) |
Balint Uveges | 871fa39 | 2019-04-02 20:31:11 +0000 | [diff] [blame] | 73 | } else { |
Peter Szilagyi | 16d84d6 | 2019-04-24 14:51:02 +0000 | [diff] [blame] | 74 | member += "," + rx.Ip + ":" + strconv.Itoa(int(rx.Port)) |
Balint Uveges | 871fa39 | 2019-04-02 20:31:11 +0000 | [diff] [blame] | 75 | } |
| 76 | } |
| 77 | if group == "" { |
| 78 | group += member |
| 79 | } else { |
| 80 | group += ";" + member |
| 81 | } |
| 82 | } |
| 83 | rawrte += group |
| 84 | rawrt = append(rawrt, rawrte+"\n") |
| 85 | } |
| 86 | rawrt = append(rawrt, key+"newrt|end\n") |
kalnagy | 9216265 | 2019-07-02 15:15:49 +0200 | [diff] [blame] | 87 | rtmgr.Logger.Debug("rmr.GeneratePolicies returns: %v", rawrt) |
Balint Uveges | 871fa39 | 2019-04-02 20:31:11 +0000 | [diff] [blame] | 88 | return &rawrt |
| 89 | } |
Peter Szilagyi | 16d84d6 | 2019-04-24 14:51:02 +0000 | [diff] [blame] | 90 | |
kalnagy | 9216265 | 2019-07-02 15:15:49 +0200 | [diff] [blame] | 91 | func (r *RmrPub) GeneratePolicies(eps rtmgr.Endpoints) *[]string { |
| 92 | rtmgr.Logger.Debug("Invoked rmr.GeneratePolicies, args: %v: ", eps) |
| 93 | return r.generateRMRPolicies(eps, "00000 ") |
Peter Szilagyi | 16d84d6 | 2019-04-24 14:51:02 +0000 | [diff] [blame] | 94 | } |
| 95 | |
kalnagy | 9216265 | 2019-07-02 15:15:49 +0200 | [diff] [blame] | 96 | func (r *RmrPush) GeneratePolicies(eps rtmgr.Endpoints) *[]string { |
| 97 | rtmgr.Logger.Debug("Invoked rmr.GeneratePolicies, args: %v: ", eps) |
| 98 | return r.generateRMRPolicies(eps, "") |
Peter Szilagyi | 16d84d6 | 2019-04-24 14:51:02 +0000 | [diff] [blame] | 99 | } |
kalnagy | 9216265 | 2019-07-02 15:15:49 +0200 | [diff] [blame] | 100 | |
| 101 | func (r *RmrPub) GetRouteTable(eps rtmgr.Endpoints) *rtmgr.RouteTable { |
| 102 | return r.getRouteTable(eps) |
| 103 | } |
| 104 | |
| 105 | func (r *RmrPush) GetRouteTable(eps rtmgr.Endpoints) *rtmgr.RouteTable { |
| 106 | return r.getRouteTable(eps) |
| 107 | } |
| 108 | |