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.
17 ==================================================================================
21 Abstract: Routing Manager Main file. Implemets the following functions:
22 - parseArgs: reading command line arguments
23 - init:Rtmgr initializing the service modules
24 - serve: running the loop
40 const SERVICENAME = "rtmgr"
41 const INTERVAL time.Duration = 2
44 args *map[string]string
48 a := make(map[string]string)
49 xmgeturl := flag.String("nbi-httpget", "http://localhost:3000/xapps", "xApp Manager URL")
50 nngpubsock := flag.String("sbi-nngsub", "tcp://0.0.0.0:4560", "NNG Subsciption Socket URI")
51 file := flag.String("sdl-file", "/db/rt.json", "Local file store location")
52 rpename := flag.String("rpe", "rmr", "Policy Engine Module name")
53 loglevel := flag.String("loglevel", "INFO", "INFO | WARN | ERROR | DEBUG")
55 if (*xmgeturl) != "" {
56 a["xmurl"] = (*xmgeturl)
57 a["nbiname"] = "httpGetter"
59 if (*nngpubsock) != "" {
60 a["socketuri"] = (*nngpubsock)
61 a["sbiname"] = "nngpub"
67 a["rpename"] = (*rpename)
68 a["loglevel"] = (*loglevel)
72 func initRtmgr() (*nbi.NbiEngineConfig, *sbi.SbiEngineConfig, *sdl.SdlEngineConfig, *rpe.RpeEngineConfig, error) {
74 if nbi, err := nbi.GetNbi((*args)["nbiname"]); err == nil && nbi != nil {
75 if sbi, err := sbi.GetSbi((*args)["sbiname"]); err == nil && sbi != nil {
76 if sdl, err := sdl.GetSdl((*args)["sdlname"]); err == nil && sdl != nil {
77 if rpe, err := rpe.GetRpe((*args)["rpename"]); err == nil && rpe != nil {
78 return nbi, sbi, sdl, rpe, nil
83 return nil, nil, nil, nil, err
86 func serve(nbi *nbi.NbiEngineConfig, sbi *sbi.SbiEngineConfig, sdl *sdl.SdlEngineConfig, rpe *rpe.RpeEngineConfig) {
87 err := sbi.OpenSocket((*args)["socketuri"])
89 rtmgr.Logger.Info("fail to open pub socket due to: " + err.Error())
92 defer sbi.CloseSocket()
94 time.Sleep(INTERVAL * time.Second)
95 data, err := nbi.BatchFetch((*args)["xmurl"])
97 rtmgr.Logger.Error("cannot get data from " + nbi.Engine.Name + " interface dute to: " + err.Error())
99 sdl.WriteAll((*args)["file"], data)
101 data, err = sdl.ReadAll((*args)["file"])
102 if err != nil || data == nil {
103 rtmgr.Logger.Error("cannot get data from " + sdl.Engine.Name + " interface dute to: " + err.Error())
106 policies := rpe.GeneratePolicies(data)
107 err = sbi.DistributeAll(policies)
109 rtmgr.Logger.Error("routing rable cannot be published due to: " + err.Error())
116 rtmgr.SetLogLevel((*args)["loglevel"])
117 nbi, sbi, sdl, rpe, err := initRtmgr()
119 rtmgr.Logger.Error(err.Error())
122 rtmgr.Logger.Info("Start " + SERVICENAME + " service")
123 serve(nbi, sbi, sdl, rpe)