blob: ae63034ec0c76287742384fe9ef4c7e0fed78d26 [file] [log] [blame]
Balint Uveges871fa392019-04-02 20:31:11 +00001/*
Peter Szilagyi16d84d62019-04-24 14:51:02 +00002w
Balint Uveges871fa392019-04-02 20:31:11 +00003==================================================================================
4 Copyright (c) 2019 AT&T Intellectual Property.
5 Copyright (c) 2019 Nokia
6
7 Licensed under the Apache License, Version 2.0 (the "License");
8 you may not use this file except in compliance with the License.
9 You may obtain a copy of the License at
10
11 http://www.apache.org/licenses/LICENSE-2.0
12
13 Unless required by applicable law or agreed to in writing, software
14 distributed under the License is distributed on an "AS IS" BASIS,
15 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 See the License for the specific language governing permissions and
17 limitations under the License.
wahidw761934a2019-11-27 06:07:26 +000018
19 This source code is part of the near-RT RIC (RAN Intelligent Controller)
20 platform project (RICP).
21
Balint Uveges871fa392019-04-02 20:31:11 +000022==================================================================================
23*/
24/*
25 Mnemonic: sbi.go
26 Abstract: Contains SBI (SouthBound Interface) module definitions and generic SBI components
27 Date: 16 March 2019
28*/
29
30package sbi
31
32import (
33 "errors"
wahidwa8596ec2019-12-05 06:30:42 +000034 "gerrit.o-ran-sc.org/r/ric-plt/xapp-frame/pkg/xapp"
kalnagy92162652019-07-02 15:15:49 +020035 "routing-manager/pkg/rtmgr"
zkoczkaeb2ff0d2019-09-26 16:59:54 +020036 "strconv"
Balint Uveges871fa392019-04-02 20:31:11 +000037)
38
zkoczkaaaf8d392019-10-02 17:16:06 +020039const DefaultNngPipelineSocketPrefix = "tcp://"
40const DefaultNngPipelineSocketNumber = 4561
41const PlatformType = "platform"
Peter Szilagyi16d84d62019-04-24 14:51:02 +000042
Balint Uveges871fa392019-04-02 20:31:11 +000043var (
zkoczkaaaf8d392019-10-02 17:16:06 +020044 SupportedSbis = []*EngineConfig{
45 {
zkoczkaeb2ff0d2019-09-26 16:59:54 +020046 Name: "nngpush",
47 Version: "v1",
48 Protocol: "nngpipeline",
49 Instance: NewNngPush(),
50 IsAvailable: true,
51 },
Balint Uveges871fa392019-04-02 20:31:11 +000052 }
53)
54
zkoczkaaaf8d392019-10-02 17:16:06 +020055func GetSbi(sbiName string) (Engine, error) {
Balint Uveges871fa392019-04-02 20:31:11 +000056 for _, sbi := range SupportedSbis {
kalnagy92162652019-07-02 15:15:49 +020057 if sbi.Name == sbiName && sbi.IsAvailable {
58 return sbi.Instance, nil
Balint Uveges871fa392019-04-02 20:31:11 +000059 }
60 }
Peter Szilagyi16d84d62019-04-24 14:51:02 +000061 return nil, errors.New("SBI:" + sbiName + " is not supported or still not available")
62}
63
kalnagy92162652019-07-02 15:15:49 +020064type Sbi struct {
kalnagy92162652019-07-02 15:15:49 +020065}
66
zkoczkaaaf8d392019-10-02 17:16:06 +020067func (s *Sbi) pruneEndpointList(sbi Engine) {
wahidwa8596ec2019-12-05 06:30:42 +000068 xapp.Logger.Debug("pruneEndpointList invoked.")
zkoczkaeb2ff0d2019-09-26 16:59:54 +020069 for _, ep := range rtmgr.Eps {
70 if !ep.Keepalive {
wahidwa8596ec2019-12-05 06:30:42 +000071 xapp.Logger.Debug("deleting %v", ep)
zkoczkaeb2ff0d2019-09-26 16:59:54 +020072 sbi.DeleteEndpoint(ep)
73 delete(rtmgr.Eps, ep.Uuid)
74 } else {
75 rtmgr.Eps[ep.Uuid].Keepalive = false
76 }
77 }
Peter Szilagyi16d84d62019-04-24 14:51:02 +000078}
79
zkoczkaaaf8d392019-10-02 17:16:06 +020080func (s *Sbi) updateEndpoints(rcs *rtmgr.RicComponents, sbi Engine) {
wahidwa8596ec2019-12-05 06:30:42 +000081 for _, xapps := range (*rcs).XApps {
82 for _, instance := range xapps.Instances {
zkoczkaeb2ff0d2019-09-26 16:59:54 +020083 uuid := instance.Ip + ":" + strconv.Itoa(int(instance.Port))
84 if _, ok := rtmgr.Eps[uuid]; ok {
85 rtmgr.Eps[uuid].Keepalive = true
86 } else {
87 ep := &rtmgr.Endpoint{
zkoczkaaaf8d392019-10-02 17:16:06 +020088 Uuid: uuid,
89 Name: instance.Name,
wahidwa8596ec2019-12-05 06:30:42 +000090 XAppType: xapps.Name,
zkoczkaaaf8d392019-10-02 17:16:06 +020091 Ip: instance.Ip,
92 Port: instance.Port,
93 TxMessages: instance.TxMessages,
94 RxMessages: instance.RxMessages,
wahidwa8596ec2019-12-05 06:30:42 +000095 Policies: instance.Policies,
zkoczkaaaf8d392019-10-02 17:16:06 +020096 Socket: nil,
97 IsReady: false,
98 Keepalive: true,
zkoczkaeb2ff0d2019-09-26 16:59:54 +020099 }
zkoczkaaaf8d392019-10-02 17:16:06 +0200100 if err := sbi.AddEndpoint(ep); err != nil {
wahidwa8596ec2019-12-05 06:30:42 +0000101 xapp.Logger.Error("can't create socket for endpoint: " + ep.Name + " due to:" + err.Error())
zkoczkaeb2ff0d2019-09-26 16:59:54 +0200102 continue
103 }
104 rtmgr.Eps[uuid] = ep
105 }
106 }
107 }
zkoczkaaaf8d392019-10-02 17:16:06 +0200108 s.updatePlatformEndpoints(&((*rcs).Pcs), sbi)
109 s.pruneEndpointList(sbi)
Balint Uveges871fa392019-04-02 20:31:11 +0000110}
kalnagy92162652019-07-02 15:15:49 +0200111
zkoczkaaaf8d392019-10-02 17:16:06 +0200112func (s *Sbi) updatePlatformEndpoints(pcs *rtmgr.PlatformComponents, sbi Engine) {
wahidwa8596ec2019-12-05 06:30:42 +0000113 xapp.Logger.Debug("updatePlatformEndpoints invoked. PCS: %v", *pcs)
zkoczkaeb2ff0d2019-09-26 16:59:54 +0200114 for _, pc := range *pcs {
115 uuid := pc.Fqdn + ":" + strconv.Itoa(int(pc.Port))
116 if _, ok := rtmgr.Eps[uuid]; ok {
117 rtmgr.Eps[uuid].Keepalive = true
118 } else {
119 ep := &rtmgr.Endpoint{
zkoczkaaaf8d392019-10-02 17:16:06 +0200120 Uuid: uuid,
121 Name: pc.Name,
122 XAppType: PlatformType,
123 Ip: pc.Fqdn,
124 Port: pc.Port,
125 TxMessages: rtmgr.PLATFORMMESSAGETYPES[pc.Name]["tx"],
126 RxMessages: rtmgr.PLATFORMMESSAGETYPES[pc.Name]["rx"],
127 Socket: nil,
128 IsReady: false,
129 Keepalive: true,
zkoczkaeb2ff0d2019-09-26 16:59:54 +0200130 }
wahidwa8596ec2019-12-05 06:30:42 +0000131 xapp.Logger.Debug("ep created: %v", ep)
zkoczkaaaf8d392019-10-02 17:16:06 +0200132 if err := sbi.AddEndpoint(ep); err != nil {
wahidwa8596ec2019-12-05 06:30:42 +0000133 xapp.Logger.Error("can't create socket for endpoint: " + ep.Name + " due to:" + err.Error())
zkoczkaeb2ff0d2019-09-26 16:59:54 +0200134 continue
135 }
136 rtmgr.Eps[uuid] = ep
137 }
138 }
kalnagy92162652019-07-02 15:15:49 +0200139}