Removed Book Keeping of RMR CTL ports. Route Distribution only on demand
[ric-plt/rtmgr.git] / pkg / rtmgr / rtmgr.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    This source code is part of the near-RT RIC (RAN Intelligent Controller)
19    platform project (RICP).
20
21 ==================================================================================
22 */
23 /*
24   Mnemonic:     rtmgr/rtmgr.go
25   Abstract:     Contains RTMGR (Routing Manager) module's generic variables and functions
26   Date:         26 March 2019
27 */
28
29 package rtmgr
30
31 import (
32         "encoding/json"
33         "errors"
34         "gerrit.o-ran-sc.org/r/ric-plt/xapp-frame/pkg/xapp"
35         "github.com/ghodss/yaml"
36         "io/ioutil"
37         "os"
38         "strings"
39 )
40
41 var (
42         Eps  Endpoints
43         Subs SubscriptionList
44         PrsCfg  *PlatformRoutes
45         Mtype MessageTypeList
46         DynamicRouteList []string
47 )
48
49 func GetPlatformComponents(configfile string) (*PlatformComponents, error) {
50         xapp.Logger.Debug("Invoked rtmgr.GetPlatformComponents(" + configfile + ")")
51         var rcfg ConfigRtmgr
52         var rtroutes RtmgrRoutes
53         var mtypes MessageTypeIdentifier
54         yamlFile, err := os.Open(configfile)
55         if err != nil {
56                 return nil, errors.New("cannot open the file due to: " + err.Error())
57         }
58         defer yamlFile.Close()
59         byteValue, err := ioutil.ReadAll(yamlFile)
60         if err != nil {
61                 return nil, errors.New("cannot read the file due to: " + err.Error())
62         }
63         jsonByteValue, err := yaml.YAMLToJSON(byteValue)
64         if err != nil {
65                 return nil, errors.New("cannot read the file due to: " + err.Error())
66         }
67         err = json.Unmarshal(jsonByteValue,&rtroutes)
68         if err != nil {
69                return nil, errors.New("cannot parse data due to: " + err.Error())
70         }
71         PrsCfg = &(rtroutes.Prs)
72
73         err = json.Unmarshal(jsonByteValue,&mtypes)
74         if err != nil {
75                return nil, errors.New("cannot parse data due to: " + err.Error())
76         } else {
77                 xapp.Logger.Debug("Messgaetypes = %v", mtypes)
78                 for _,m := range mtypes.Mit {
79                         splitstr := strings.Split(m,"=")
80                         Mtype[splitstr[0]] = splitstr[1]
81                 }
82         }
83         err = json.Unmarshal(jsonByteValue, &rcfg)
84         if err != nil {
85                 return nil, errors.New("cannot parse data due to: " + err.Error())
86         }
87         xapp.Logger.Debug("Platform components read from the configfile:  %v", rcfg.Pcs)
88         return &(rcfg.Pcs), nil
89 }