Added config and logger module from xapp-fwk. Added Routes related to A1Mediator...
[ric-plt/rtmgr.git] / pkg / rpe / rmr.go
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    This source code is part of the near-RT RIC (RAN Intelligent Controller)
20    platform project (RICP).
21
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
33 import (
34         "gerrit.o-ran-sc.org/r/ric-plt/xapp-frame/pkg/xapp"
35         "routing-manager/pkg/rtmgr"
36         "strconv"
37 )
38
39 type Rmr struct {
40         Rpe
41 }
42
43 type RmrPush struct {
44         Rmr
45 }
46
47 func NewRmrPush() *RmrPush {
48         instance := new(RmrPush)
49         return instance
50 }
51
52 /*
53 Produces the raw route message consumable by RMR
54 */
55 func (r *Rmr) generateRMRPolicies(eps rtmgr.Endpoints, key string) *[]string {
56         rawrt := []string{key + "newrt|start\n"}
57         rt := r.generateRouteTable(eps)
58         for _, rte := range *rt {
59                 rawrte := key + "mse|" + rte.MessageType
60                 for _, tx := range rte.TxList {
61                         rawrte += "," + tx.Ip + ":" + strconv.Itoa(int(tx.Port))
62                 }
63                 rawrte += "|" + strconv.Itoa(int(rte.SubID)) + "|"
64                 group := ""
65                 for _, rxg := range rte.RxGroups {
66                         member := ""
67                         for _, rx := range rxg {
68                                 if member == "" {
69                                         member += rx.Ip + ":" + strconv.Itoa(int(rx.Port))
70                                 } else {
71                                         member += "," + rx.Ip + ":" + strconv.Itoa(int(rx.Port))
72                                 }
73                         }
74                         if group == "" {
75                                 group += member
76                         } else {
77                                 group += ";" + member
78                         }
79                 }
80                 rawrte += group
81                 rawrt = append(rawrt, rawrte+"\n")
82         }
83         rawrt = append(rawrt, key+"newrt|end\n")
84         xapp.Logger.Debug("rmr.GeneratePolicies returns: %v", rawrt)
85         return &rawrt
86 }
87
88 func (r *RmrPush) GeneratePolicies(eps rtmgr.Endpoints) *[]string {
89         xapp.Logger.Debug("Invoked rmr.GeneratePolicies, args: %v: ", eps)
90         return r.generateRMRPolicies(eps, "")
91 }
92
93 func (r *RmrPush) GenerateRouteTable(eps rtmgr.Endpoints) *rtmgr.RouteTable {
94         return r.generateRouteTable(eps)
95 }