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. |
wahidw | 761934a | 2019-11-27 06:07:26 +0000 | [diff] [blame] | 17 | |
| 18 | |
| 19 | This source code is part of the near-RT RIC (RAN Intelligent Controller) |
| 20 | platform project (RICP). |
| 21 | |
Balint Uveges | 871fa39 | 2019-04-02 20:31:11 +0000 | [diff] [blame] | 22 | ================================================================================== |
| 23 | */ |
| 24 | /* |
| 25 | Mnemonic: rmr.go |
| 26 | Abstract: RMR Route Policy implementation |
| 27 | Produces RMR (RIC Management Routing) formatted route messages |
| 28 | Date: 16 March 2019 |
| 29 | */ |
| 30 | |
| 31 | package rpe |
| 32 | |
Peter Szilagyi | 16d84d6 | 2019-04-24 14:51:02 +0000 | [diff] [blame] | 33 | import ( |
wahidw | a8596ec | 2019-12-05 06:30:42 +0000 | [diff] [blame] | 34 | "gerrit.o-ran-sc.org/r/ric-plt/xapp-frame/pkg/xapp" |
kalnagy | 9216265 | 2019-07-02 15:15:49 +0200 | [diff] [blame] | 35 | "routing-manager/pkg/rtmgr" |
Peter Szilagyi | 16d84d6 | 2019-04-24 14:51:02 +0000 | [diff] [blame] | 36 | "strconv" |
| 37 | ) |
Balint Uveges | 871fa39 | 2019-04-02 20:31:11 +0000 | [diff] [blame] | 38 | |
kalnagy | 9216265 | 2019-07-02 15:15:49 +0200 | [diff] [blame] | 39 | type Rmr struct { |
| 40 | Rpe |
| 41 | } |
| 42 | |
kalnagy | 9216265 | 2019-07-02 15:15:49 +0200 | [diff] [blame] | 43 | type RmrPush struct { |
| 44 | Rmr |
| 45 | } |
| 46 | |
kalnagy | 9216265 | 2019-07-02 15:15:49 +0200 | [diff] [blame] | 47 | func NewRmrPush() *RmrPush { |
| 48 | instance := new(RmrPush) |
| 49 | return instance |
| 50 | } |
| 51 | |
Balint Uveges | 871fa39 | 2019-04-02 20:31:11 +0000 | [diff] [blame] | 52 | /* |
| 53 | Produces the raw route message consumable by RMR |
| 54 | */ |
kalnagy | 9216265 | 2019-07-02 15:15:49 +0200 | [diff] [blame] | 55 | func (r *Rmr) generateRMRPolicies(eps rtmgr.Endpoints, key string) *[]string { |
Balint Uveges | 871fa39 | 2019-04-02 20:31:11 +0000 | [diff] [blame] | 56 | rawrt := []string{key + "newrt|start\n"} |
zkoczka | eb2ff0d | 2019-09-26 16:59:54 +0200 | [diff] [blame] | 57 | rt := r.generateRouteTable(eps) |
Balint Uveges | 871fa39 | 2019-04-02 20:31:11 +0000 | [diff] [blame] | 58 | for _, rte := range *rt { |
1000044 | e90ddda | 2019-08-01 09:58:52 +0200 | [diff] [blame] | 59 | rawrte := key + "mse|" + rte.MessageType |
Balint Uveges | 871fa39 | 2019-04-02 20:31:11 +0000 | [diff] [blame] | 60 | for _, tx := range rte.TxList { |
Peter Szilagyi | 16d84d6 | 2019-04-24 14:51:02 +0000 | [diff] [blame] | 61 | rawrte += "," + tx.Ip + ":" + strconv.Itoa(int(tx.Port)) |
Balint Uveges | 871fa39 | 2019-04-02 20:31:11 +0000 | [diff] [blame] | 62 | } |
kalnagy | 9216265 | 2019-07-02 15:15:49 +0200 | [diff] [blame] | 63 | rawrte += "|" + strconv.Itoa(int(rte.SubID)) + "|" |
Balint Uveges | 871fa39 | 2019-04-02 20:31:11 +0000 | [diff] [blame] | 64 | group := "" |
| 65 | for _, rxg := range rte.RxGroups { |
| 66 | member := "" |
| 67 | for _, rx := range rxg { |
| 68 | if member == "" { |
Peter Szilagyi | 16d84d6 | 2019-04-24 14:51:02 +0000 | [diff] [blame] | 69 | member += rx.Ip + ":" + strconv.Itoa(int(rx.Port)) |
Balint Uveges | 871fa39 | 2019-04-02 20:31:11 +0000 | [diff] [blame] | 70 | } else { |
Peter Szilagyi | 16d84d6 | 2019-04-24 14:51:02 +0000 | [diff] [blame] | 71 | member += "," + rx.Ip + ":" + strconv.Itoa(int(rx.Port)) |
Balint Uveges | 871fa39 | 2019-04-02 20:31:11 +0000 | [diff] [blame] | 72 | } |
| 73 | } |
| 74 | if group == "" { |
| 75 | group += member |
| 76 | } else { |
| 77 | group += ";" + member |
| 78 | } |
| 79 | } |
| 80 | rawrte += group |
rangajal | 749099b | 2019-12-10 09:37:08 +0000 | [diff] [blame] | 81 | |
| 82 | if (rte.RouteType == "%meid") { |
| 83 | rawrte += group + rte.RouteType |
| 84 | } |
| 85 | |
Balint Uveges | 871fa39 | 2019-04-02 20:31:11 +0000 | [diff] [blame] | 86 | rawrt = append(rawrt, rawrte+"\n") |
| 87 | } |
| 88 | rawrt = append(rawrt, key+"newrt|end\n") |
rangajal | 749099b | 2019-12-10 09:37:08 +0000 | [diff] [blame] | 89 | |
| 90 | count := 0 |
| 91 | rawrt = append(rawrt, key+"meid_map|start\n") |
| 92 | rawrt = append(rawrt, key+"meid_map|end|" + strconv.Itoa(count) +"\n") |
| 93 | |
wahidw | a8596ec | 2019-12-05 06:30:42 +0000 | [diff] [blame] | 94 | xapp.Logger.Debug("rmr.GeneratePolicies returns: %v", rawrt) |
Balint Uveges | 871fa39 | 2019-04-02 20:31:11 +0000 | [diff] [blame] | 95 | return &rawrt |
| 96 | } |
Peter Szilagyi | 16d84d6 | 2019-04-24 14:51:02 +0000 | [diff] [blame] | 97 | |
kalnagy | 9216265 | 2019-07-02 15:15:49 +0200 | [diff] [blame] | 98 | func (r *RmrPush) GeneratePolicies(eps rtmgr.Endpoints) *[]string { |
wahidw | a8596ec | 2019-12-05 06:30:42 +0000 | [diff] [blame] | 99 | xapp.Logger.Debug("Invoked rmr.GeneratePolicies, args: %v: ", eps) |
kalnagy | 9216265 | 2019-07-02 15:15:49 +0200 | [diff] [blame] | 100 | return r.generateRMRPolicies(eps, "") |
Peter Szilagyi | 16d84d6 | 2019-04-24 14:51:02 +0000 | [diff] [blame] | 101 | } |
kalnagy | 9216265 | 2019-07-02 15:15:49 +0200 | [diff] [blame] | 102 | |
zkoczka | eb2ff0d | 2019-09-26 16:59:54 +0200 | [diff] [blame] | 103 | func (r *RmrPush) GenerateRouteTable(eps rtmgr.Endpoints) *rtmgr.RouteTable { |
| 104 | return r.generateRouteTable(eps) |
kalnagy | 9216265 | 2019-07-02 15:15:49 +0200 | [diff] [blame] | 105 | } |