blob: 58fe7d8e64b94046071652f78ca2ec8033948c8e [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"
rangajal749099b2019-12-10 09:37:08 +000037 "strings"
Balint Uveges871fa392019-04-02 20:31:11 +000038)
39
zkoczkaaaf8d392019-10-02 17:16:06 +020040const DefaultNngPipelineSocketPrefix = "tcp://"
41const DefaultNngPipelineSocketNumber = 4561
42const PlatformType = "platform"
Peter Szilagyi16d84d62019-04-24 14:51:02 +000043
Balint Uveges871fa392019-04-02 20:31:11 +000044var (
zkoczkaaaf8d392019-10-02 17:16:06 +020045 SupportedSbis = []*EngineConfig{
46 {
zkoczkaeb2ff0d2019-09-26 16:59:54 +020047 Name: "nngpush",
48 Version: "v1",
49 Protocol: "nngpipeline",
50 Instance: NewNngPush(),
51 IsAvailable: true,
52 },
Balint Uveges871fa392019-04-02 20:31:11 +000053 }
54)
55
zkoczkaaaf8d392019-10-02 17:16:06 +020056func GetSbi(sbiName string) (Engine, error) {
Balint Uveges871fa392019-04-02 20:31:11 +000057 for _, sbi := range SupportedSbis {
kalnagy92162652019-07-02 15:15:49 +020058 if sbi.Name == sbiName && sbi.IsAvailable {
59 return sbi.Instance, nil
Balint Uveges871fa392019-04-02 20:31:11 +000060 }
61 }
Peter Szilagyi16d84d62019-04-24 14:51:02 +000062 return nil, errors.New("SBI:" + sbiName + " is not supported or still not available")
63}
64
kalnagy92162652019-07-02 15:15:49 +020065type Sbi struct {
kalnagy92162652019-07-02 15:15:49 +020066}
67
zkoczkaaaf8d392019-10-02 17:16:06 +020068func (s *Sbi) pruneEndpointList(sbi Engine) {
wahidwa8596ec2019-12-05 06:30:42 +000069 xapp.Logger.Debug("pruneEndpointList invoked.")
zkoczkaeb2ff0d2019-09-26 16:59:54 +020070 for _, ep := range rtmgr.Eps {
71 if !ep.Keepalive {
wahidwa8596ec2019-12-05 06:30:42 +000072 xapp.Logger.Debug("deleting %v", ep)
zkoczkaeb2ff0d2019-09-26 16:59:54 +020073 sbi.DeleteEndpoint(ep)
74 delete(rtmgr.Eps, ep.Uuid)
75 } else {
76 rtmgr.Eps[ep.Uuid].Keepalive = false
77 }
78 }
Peter Szilagyi16d84d62019-04-24 14:51:02 +000079}
80
zkoczkaaaf8d392019-10-02 17:16:06 +020081func (s *Sbi) updateEndpoints(rcs *rtmgr.RicComponents, sbi Engine) {
wahidwa8596ec2019-12-05 06:30:42 +000082 for _, xapps := range (*rcs).XApps {
83 for _, instance := range xapps.Instances {
zkoczkaeb2ff0d2019-09-26 16:59:54 +020084 uuid := instance.Ip + ":" + strconv.Itoa(int(instance.Port))
85 if _, ok := rtmgr.Eps[uuid]; ok {
86 rtmgr.Eps[uuid].Keepalive = true
87 } else {
88 ep := &rtmgr.Endpoint{
zkoczkaaaf8d392019-10-02 17:16:06 +020089 Uuid: uuid,
90 Name: instance.Name,
wahidwa8596ec2019-12-05 06:30:42 +000091 XAppType: xapps.Name,
zkoczkaaaf8d392019-10-02 17:16:06 +020092 Ip: instance.Ip,
93 Port: instance.Port,
94 TxMessages: instance.TxMessages,
95 RxMessages: instance.RxMessages,
wahidwa8596ec2019-12-05 06:30:42 +000096 Policies: instance.Policies,
zkoczkaaaf8d392019-10-02 17:16:06 +020097 Socket: nil,
98 IsReady: false,
99 Keepalive: true,
zkoczkaeb2ff0d2019-09-26 16:59:54 +0200100 }
zkoczkaaaf8d392019-10-02 17:16:06 +0200101 if err := sbi.AddEndpoint(ep); err != nil {
wahidwa8596ec2019-12-05 06:30:42 +0000102 xapp.Logger.Error("can't create socket for endpoint: " + ep.Name + " due to:" + err.Error())
zkoczkaeb2ff0d2019-09-26 16:59:54 +0200103 continue
104 }
105 rtmgr.Eps[uuid] = ep
106 }
107 }
108 }
zkoczkaaaf8d392019-10-02 17:16:06 +0200109 s.updatePlatformEndpoints(&((*rcs).Pcs), sbi)
rangajal749099b2019-12-10 09:37:08 +0000110 s.updateE2TEndpoints(&((*rcs).E2Ts), sbi)
zkoczkaaaf8d392019-10-02 17:16:06 +0200111 s.pruneEndpointList(sbi)
Balint Uveges871fa392019-04-02 20:31:11 +0000112}
kalnagy92162652019-07-02 15:15:49 +0200113
zkoczkaaaf8d392019-10-02 17:16:06 +0200114func (s *Sbi) updatePlatformEndpoints(pcs *rtmgr.PlatformComponents, sbi Engine) {
wahidwa8596ec2019-12-05 06:30:42 +0000115 xapp.Logger.Debug("updatePlatformEndpoints invoked. PCS: %v", *pcs)
zkoczkaeb2ff0d2019-09-26 16:59:54 +0200116 for _, pc := range *pcs {
117 uuid := pc.Fqdn + ":" + strconv.Itoa(int(pc.Port))
118 if _, ok := rtmgr.Eps[uuid]; ok {
119 rtmgr.Eps[uuid].Keepalive = true
120 } else {
121 ep := &rtmgr.Endpoint{
zkoczkaaaf8d392019-10-02 17:16:06 +0200122 Uuid: uuid,
123 Name: pc.Name,
124 XAppType: PlatformType,
125 Ip: pc.Fqdn,
126 Port: pc.Port,
127 TxMessages: rtmgr.PLATFORMMESSAGETYPES[pc.Name]["tx"],
128 RxMessages: rtmgr.PLATFORMMESSAGETYPES[pc.Name]["rx"],
129 Socket: nil,
130 IsReady: false,
131 Keepalive: true,
zkoczkaeb2ff0d2019-09-26 16:59:54 +0200132 }
wahidwa8596ec2019-12-05 06:30:42 +0000133 xapp.Logger.Debug("ep created: %v", ep)
zkoczkaaaf8d392019-10-02 17:16:06 +0200134 if err := sbi.AddEndpoint(ep); err != nil {
wahidwa8596ec2019-12-05 06:30:42 +0000135 xapp.Logger.Error("can't create socket for endpoint: " + ep.Name + " due to:" + err.Error())
zkoczkaeb2ff0d2019-09-26 16:59:54 +0200136 continue
137 }
138 rtmgr.Eps[uuid] = ep
139 }
140 }
kalnagy92162652019-07-02 15:15:49 +0200141}
rangajal749099b2019-12-10 09:37:08 +0000142
143func (s *Sbi) updateE2TEndpoints(E2Ts *map[string]rtmgr.E2TInstance, sbi Engine) {
144 xapp.Logger.Debug("updateE2TEndpoints invoked. E2T: %v", *E2Ts)
145 for _, e2t := range *E2Ts {
146 uuid := e2t.Fqdn
147 stringSlice := strings.Split(e2t.Fqdn, ":")
148 ipaddress := stringSlice[0]
149 port, _ := strconv.Atoi(stringSlice[1])
150 if _, ok := rtmgr.Eps[uuid]; ok {
151 rtmgr.Eps[uuid].Keepalive = true
152 } else {
153 ep := &rtmgr.Endpoint{
154 Uuid: uuid,
155 Name: e2t.Name,
156 XAppType: PlatformType,
157 Ip: ipaddress,
158 Port: uint16(port),
159 TxMessages: rtmgr.PLATFORMMESSAGETYPES[e2t.Name]["tx"],
160 RxMessages: rtmgr.PLATFORMMESSAGETYPES[e2t.Name]["rx"],
161 Socket: nil,
162 IsReady: false,
163 Keepalive: true,
164 }
165 xapp.Logger.Debug("ep created: %v", ep)
166 if err := sbi.AddEndpoint(ep); err != nil {
167 xapp.Logger.Error("can't create socket for endpoint: " + ep.Name + " due to:" + err.Error())
168 continue
169 }
170 rtmgr.Eps[uuid] = ep
171 }
172 }
173}
wahidwdd6b0562020-03-31 03:09:45 +0000174
175func (s *Sbi) createEndpoint(payload string, sbi Engine) (*rtmgr.Endpoint) {
176 xapp.Logger.Debug("CreateEndPoint %v", payload)
177 stringSlice := strings.Split(payload, " ")
178 uuid := stringSlice[0]
179 xapp.Logger.Debug(">>> uuid %v", stringSlice[0])
180
181
182 if _, ok := rtmgr.Eps[uuid]; ok {
183 ep := rtmgr.Eps[uuid]
184 return ep
185 }
186
187 return nil
188}