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.
18 This source code is part of the near-RT RIC (RAN Intelligent Controller)
19 platform project (RICP).
21 ==================================================================================
29 "gerrit.o-ran-sc.org/r/ric-plt/xapp-frame/pkg/xapp"
30 "routing-manager/pkg/rpe"
31 "routing-manager/pkg/rtmgr"
32 "routing-manager/pkg/sbi"
33 "routing-manager/pkg/sdl"
38 func NewControl() Control {
40 return Control{make(chan *xapp.RMRParams)}
44 rcChan chan *xapp.RMRParams
47 func (c *Control) Run(sbiEngine sbi.Engine, sdlEngine sdl.Engine, rpeEngine rpe.Engine, m *sync.Mutex) {
48 go c.controlLoop(sbiEngine, sdlEngine, rpeEngine, m)
52 func (c *Control) Consume(rp *xapp.RMRParams) (err error) {
57 func (c *Control) controlLoop(sbiEngine sbi.Engine, sdlEngine sdl.Engine, rpeEngine rpe.Engine, m *sync.Mutex) {
60 xapp_msg := sbi.RMRParams{msg}
62 case xapp.RICMessageTypes["RMRRM_REQ_TABLE"]:
63 if rtmgr.Rtmgr_ready == false {
64 xapp.Logger.Info("Update Route Table Request(RMR to RM), message discarded as routing manager is not ready")
66 xapp.Logger.Info("Update Route Table Request(RMR to RM)")
67 go c.handleUpdateToRoutingManagerRequest(msg, sbiEngine, sdlEngine, rpeEngine, m)
69 case xapp.RICMessageTypes["RMRRM_TABLE_STATE"]:
70 xapp.Logger.Info("state of table to route mgr %s,payload %s", xapp_msg.String(), msg.Payload)
73 err := errors.New("Message Type " + strconv.Itoa(msg.Mtype) + " is discarded")
74 xapp.Logger.Error("Unknown message type: %v", err)
79 func (c *Control) handleUpdateToRoutingManagerRequest(params *xapp.RMRParams, sbiEngine sbi.Engine, sdlEngine sdl.Engine, rpeEngine rpe.Engine, m *sync.Mutex) {
81 msg := sbi.RMRParams{params}
83 xapp.Logger.Info("Update Route Table Request, msg.String() : %s", msg.String())
84 xapp.Logger.Info("Update Route Table Request, params.Payload : %s", string(params.Payload))
87 data, err := sdlEngine.ReadAll(xapp.Config.GetString("rtfile"))
89 if err != nil || data == nil {
90 xapp.Logger.Error("Cannot get data from sdl interface due to: " + err.Error())
94 ep := sbiEngine.CreateEndpoint(string(params.Payload))
96 xapp.Logger.Error("Update Routing Table Request can't handle due to end point %s is not avail in complete ep list: ", string(params.Payload))
100 policies := rpeEngine.GeneratePolicies(rtmgr.Eps, data)
101 err = sbiEngine.DistributeToEp(policies, ep)
103 xapp.Logger.Error("Routing table cannot be published due to: " + err.Error())