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 { |
kalnagy | 9216265 | 2019-07-02 15:15:49 +0200 | [diff] [blame^] | 62 | rawrte := key //+ "rte|" + rte.MessageType |
| 63 | if rte.SubID == -1 { |
| 64 | rawrte += "rte|" |
| 65 | } else { |
| 66 | rawrte += "mse|" |
| 67 | } |
| 68 | rawrte += rte.MessageType |
Balint Uveges | 871fa39 | 2019-04-02 20:31:11 +0000 | [diff] [blame] | 69 | for _, tx := range rte.TxList { |
Peter Szilagyi | 16d84d6 | 2019-04-24 14:51:02 +0000 | [diff] [blame] | 70 | rawrte += "," + tx.Ip + ":" + strconv.Itoa(int(tx.Port)) |
Balint Uveges | 871fa39 | 2019-04-02 20:31:11 +0000 | [diff] [blame] | 71 | } |
kalnagy | 9216265 | 2019-07-02 15:15:49 +0200 | [diff] [blame^] | 72 | rawrte += "|" + strconv.Itoa(int(rte.SubID)) + "|" |
Balint Uveges | 871fa39 | 2019-04-02 20:31:11 +0000 | [diff] [blame] | 73 | group := "" |
| 74 | for _, rxg := range rte.RxGroups { |
| 75 | member := "" |
| 76 | for _, rx := range rxg { |
| 77 | if member == "" { |
Peter Szilagyi | 16d84d6 | 2019-04-24 14:51:02 +0000 | [diff] [blame] | 78 | member += rx.Ip + ":" + strconv.Itoa(int(rx.Port)) |
Balint Uveges | 871fa39 | 2019-04-02 20:31:11 +0000 | [diff] [blame] | 79 | } else { |
Peter Szilagyi | 16d84d6 | 2019-04-24 14:51:02 +0000 | [diff] [blame] | 80 | member += "," + rx.Ip + ":" + strconv.Itoa(int(rx.Port)) |
Balint Uveges | 871fa39 | 2019-04-02 20:31:11 +0000 | [diff] [blame] | 81 | } |
| 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") |
kalnagy | 9216265 | 2019-07-02 15:15:49 +0200 | [diff] [blame^] | 93 | rtmgr.Logger.Debug("rmr.GeneratePolicies returns: %v", rawrt) |
Balint Uveges | 871fa39 | 2019-04-02 20:31:11 +0000 | [diff] [blame] | 94 | return &rawrt |
| 95 | } |
Peter Szilagyi | 16d84d6 | 2019-04-24 14:51:02 +0000 | [diff] [blame] | 96 | |
kalnagy | 9216265 | 2019-07-02 15:15:49 +0200 | [diff] [blame^] | 97 | func (r *RmrPub) GeneratePolicies(eps rtmgr.Endpoints) *[]string { |
| 98 | rtmgr.Logger.Debug("Invoked rmr.GeneratePolicies, args: %v: ", eps) |
| 99 | return r.generateRMRPolicies(eps, "00000 ") |
Peter Szilagyi | 16d84d6 | 2019-04-24 14:51:02 +0000 | [diff] [blame] | 100 | } |
| 101 | |
kalnagy | 9216265 | 2019-07-02 15:15:49 +0200 | [diff] [blame^] | 102 | func (r *RmrPush) GeneratePolicies(eps rtmgr.Endpoints) *[]string { |
| 103 | rtmgr.Logger.Debug("Invoked rmr.GeneratePolicies, args: %v: ", eps) |
| 104 | return r.generateRMRPolicies(eps, "") |
Peter Szilagyi | 16d84d6 | 2019-04-24 14:51:02 +0000 | [diff] [blame] | 105 | } |
kalnagy | 9216265 | 2019-07-02 15:15:49 +0200 | [diff] [blame^] | 106 | |
| 107 | func (r *RmrPub) GetRouteTable(eps rtmgr.Endpoints) *rtmgr.RouteTable { |
| 108 | return r.getRouteTable(eps) |
| 109 | } |
| 110 | |
| 111 | func (r *RmrPush) GetRouteTable(eps rtmgr.Endpoints) *rtmgr.RouteTable { |
| 112 | return r.getRouteTable(eps) |
| 113 | } |
| 114 | |