2 ==================================================================================
3 Copyright (c) 2019 AT&T Intellectual Property.
4 Copyright (c) 2019 Nokia
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
10 http://www.apache.org/licenses/LICENSE-2.0
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.
19 This source code is part of the near-RT RIC (RAN Intelligent Controller)
20 platform project (RICP).
23 ==================================================================================
27 Abstract: Routing Manager Main file. Implemets the following functions:
28 - parseArgs: reading command line arguments
29 - init:Rtmgr initializing the service modules
30 - serve: running the loop
35 //TODO: change flag to pflag (won't need any argument parse)
38 "gerrit.o-ran-sc.org/r/ric-plt/xapp-frame/pkg/xapp"
41 "routing-manager/pkg/nbi"
42 "routing-manager/pkg/rpe"
43 "routing-manager/pkg/rtmgr"
44 "routing-manager/pkg/sbi"
45 "routing-manager/pkg/sdl"
51 const SERVICENAME = "rtmgr"
52 const INTERVAL time.Duration = 60
54 func initRtmgr() (nbiEngine nbi.Engine, sbiEngine sbi.Engine, sdlEngine sdl.Engine, rpeEngine rpe.Engine, err error) {
55 if nbiEngine, err = nbi.GetNbi(xapp.Config.GetString("nbi")); err == nil && nbiEngine != nil {
56 if sbiEngine, err = sbi.GetSbi(xapp.Config.GetString("sbi")); err == nil && sbiEngine != nil {
57 if sdlEngine, err = sdl.GetSdl(xapp.Config.GetString("sdl")); err == nil && sdlEngine != nil {
58 if rpeEngine, err = rpe.GetRpe(xapp.Config.GetString("rpe")); err == nil && rpeEngine != nil {
59 return nbiEngine, sbiEngine, sdlEngine, rpeEngine, nil
64 return nil, nil, nil, nil, err
67 func serveSBI(triggerSBI <-chan bool, sbiEngine sbi.Engine, sdlEngine sdl.Engine, rpeEngine rpe.Engine, m *sync.Mutex) {
71 data, err := sdlEngine.ReadAll(xapp.Config.GetString("rtfile"))
73 if err != nil || data == nil {
74 xapp.Logger.Error("Cannot get data from sdl interface due to: " + err.Error())
77 sbiEngine.UpdateEndpoints(data)
78 policies := rpeEngine.GeneratePolicies(rtmgr.Eps, data)
79 err = sbiEngine.DistributeAll(policies)
81 xapp.Logger.Error("Routing table cannot be published due to: " + err.Error())
87 func serve(nbiEngine nbi.Engine, sbiEngine sbi.Engine, sdlEngine sdl.Engine, rpeEngine rpe.Engine, m *sync.Mutex) {
89 triggerSBI := make(chan bool)
91 nbiErr := nbiEngine.Initialize(xapp.Config.GetString("xmurl"), xapp.Config.GetString("nbiurl"), xapp.Config.GetString("rtfile"), xapp.Config.GetString("cfgfile"), xapp.Config.GetString("e2murl"),
92 sdlEngine, rpeEngine, triggerSBI, m)
94 xapp.Logger.Error("Failed to initialize nbi due to: " + nbiErr.Error())
98 err := sbiEngine.Initialize(xapp.Config.GetString("sbiurl"))
100 xapp.Logger.Info("Failed to open push socket due to: " + err.Error())
103 defer nbiEngine.Terminate()
104 defer sbiEngine.Terminate()
106 // This SBI Go routine is trtiggered by periodic main loop and when data is recieved on REST interface.
107 go serveSBI(triggerSBI, sbiEngine, sdlEngine, rpeEngine, m)
110 if xapp.Config.GetString("nbi") == "httpGetter" {
111 data, err := nbiEngine.(*nbi.HttpGetter).FetchAllXApps(xapp.Config.GetString("xmurl"))
113 xapp.Logger.Error("Cannot fetch xapp data due to: " + err.Error())
114 } else if data != nil {
115 sdlEngine.WriteXApps(xapp.Config.GetString("rtfile"), data)
121 time.Sleep(INTERVAL * time.Second)
122 xapp.Logger.Debug("Periodic loop timed out. Setting triggerSBI flag to distribute updated routes.")
126 func SetupCloseHandler() {
127 c := make(chan os.Signal, 2)
128 signal.Notify(c, os.Interrupt, syscall.SIGTERM)
131 xapp.Logger.Info("\r- Ctrl+C pressed in Terminal")
137 nbiEngine, sbiEngine, sdlEngine, rpeEngine, err := initRtmgr()
139 xapp.Logger.Error(err.Error())
143 xapp.Logger.Info("Start " + SERVICENAME + " service")
144 rtmgr.Eps = make(rtmgr.Endpoints)
148 c := sbi.NewControl()
151 serve(nbiEngine, sbiEngine, sdlEngine, rpeEngine, &m)