Upgraded to RMR 4.7.4 and some improvements
[ric-plt/rtmgr.git] / cmd / 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
19    This source code is part of the near-RT RIC (RAN Intelligent Controller)
20    platform project (RICP).
21
22
23 ==================================================================================
24 */
25 /*
26         Mnemonic:       rtmgr.go
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
31         Date:           12 March 2019
32 */
33 package main
34
35 //TODO: change flag to pflag (won't need any argument parse)
36
37 import (
38         "gerrit.o-ran-sc.org/r/ric-plt/xapp-frame/pkg/xapp"
39         "os"
40         "os/signal"
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"
46         "syscall"
47         "time"
48 )
49
50 const SERVICENAME = "rtmgr"
51
52 /*type RMRUpdateType int
53
54 const (
55         XappType = iota
56         SubsType
57         E2Type
58 )*/
59
60 func SetupCloseHandler() {
61         c := make(chan os.Signal, 2)
62         signal.Notify(c, os.Interrupt, syscall.SIGTERM)
63         go func() {
64                 <-c
65                 xapp.Logger.Info("\r- Ctrl+C pressed in Terminal")
66                 os.Exit(0)
67         }()
68 }
69
70 func main() {
71
72         SetupCloseHandler()
73
74         xapp.Logger.Info("Start " + SERVICENAME + " service")
75         rtmgr.Eps = make(rtmgr.Endpoints)
76         rtmgr.Mtype = make(rtmgr.MessageTypeList)
77         rtmgr.Rtmgr_ready = false
78         rtmgr.RMRConnStatus = make(map[string]bool)
79
80         // RMR thread is starting port: 4560
81         c := nbi.NewControl()
82         go c.Run()
83
84         // Waiting for RMR to be ready
85         time.Sleep(time.Duration(2) * time.Second)
86         for xapp.Rmr.IsReady() == false {
87                 time.Sleep(time.Duration(2) * time.Second)
88         }
89
90         dummy_whid := int(xapp.Rmr.Openwh("rtmgr:4560"))
91         xapp.Logger.Info("created dummy Wormhole ID for routingmanager and dummy_whid :%d", dummy_whid)
92
93         nbi.Serve()
94         os.Exit(0)
95 }