3 ==================================================================================
4 Copyright (c) 2019 AT&T Intellectual Property.
5 Copyright (c) 2019 Nokia
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
11 http://www.apache.org/licenses/LICENSE-2.0
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.
19 This source code is part of the near-RT RIC (RAN Intelligent Controller)
20 platform project (RICP).
22 ==================================================================================
26 Abstract: Contains SBI (SouthBound Interface) module definitions and generic SBI components
35 "gerrit.o-ran-sc.org/r/ric-plt/xapp-frame/pkg/xapp"
37 "routing-manager/pkg/rtmgr"
42 const DefaultRmrPipelineSocketPrefix = "tcp://"
43 const DefaultRmrPipelineSocketNumber = 4561
44 const PlatformType = "platform"
47 SupportedSbis = []*EngineConfig{
51 Protocol: "rmrpipeline",
52 Instance: NewRmrPush(),
58 func GetSbi(sbiName string) (Engine, error) {
59 for _, sbi := range SupportedSbis {
60 if sbi.Name == sbiName && sbi.IsAvailable {
61 return sbi.Instance, nil
64 return nil, errors.New("SBI:" + sbiName + " is not supported or still not available")
70 func (s *Sbi) pruneEndpointList(sbi Engine) {
71 xapp.Logger.Debug("pruneEndpointList invoked.")
72 for _, ep := range rtmgr.Eps {
74 xapp.Logger.Debug("deleting %v", ep)
75 sbi.DeleteEndpoint(ep)
76 delete(rtmgr.Eps, ep.Uuid)
78 if rtmgr.Eps[ep.Uuid] != nil {
79 rtmgr.Eps[ep.Uuid].Keepalive = false
85 func (s *Sbi) updateEndpoints(rcs *rtmgr.RicComponents, sbi Engine) {
86 for _, xapps := range (*rcs).XApps {
87 for _, instance := range xapps.Instances {
88 uuid := instance.Ip + ":" + strconv.Itoa(int(instance.Port))
89 if _, ok := rtmgr.Eps[uuid]; ok {
90 rtmgr.Eps[uuid].Keepalive = true
92 ep := &rtmgr.Endpoint{
98 TxMessages: instance.TxMessages,
99 RxMessages: instance.RxMessages,
100 Policies: instance.Policies,
105 if err := sbi.AddEndpoint(ep); err != nil {
106 xapp.Logger.Error("can't create socket for endpoint: " + ep.Name + " due to:" + err.Error())
113 s.updatePlatformEndpoints(&((*rcs).Pcs), sbi)
114 s.updateE2TEndpoints(&((*rcs).E2Ts), sbi)
115 s.pruneEndpointList(sbi)
118 func (s *Sbi) updatePlatformEndpoints(pcs *rtmgr.PlatformComponents, sbi Engine) {
119 xapp.Logger.Debug("updatePlatformEndpoints invoked. PCS: %v", *pcs)
120 for _, pc := range *pcs {
121 uuid := pc.Fqdn + ":" + strconv.Itoa(int(pc.Port))
122 if _, ok := rtmgr.Eps[uuid]; ok {
123 rtmgr.Eps[uuid].Keepalive = true
125 ep := &rtmgr.Endpoint{
128 XAppType: PlatformType,
131 //TxMessages: rtmgr.PLATFORMMESSAGETYPES[pc.Name]["tx"],
132 //RxMessages: rtmgr.PLATFORMMESSAGETYPES[pc.Name]["rx"],
137 xapp.Logger.Debug("ep created: %v", ep)
138 if err := sbi.AddEndpoint(ep); err != nil {
139 xapp.Logger.Error("can't create socket for endpoint: " + ep.Name + " due to:" + err.Error())
147 func (s *Sbi) updateE2TEndpoints(E2Ts *map[string]rtmgr.E2TInstance, sbi Engine) {
148 xapp.Logger.Debug("updateE2TEndpoints invoked. E2T: %v", *E2Ts)
149 for _, e2t := range *E2Ts {
151 stringSlice := strings.Split(e2t.Fqdn, ":")
152 ipaddress := stringSlice[0]
153 port, _ := strconv.Atoi(stringSlice[1])
154 if _, ok := rtmgr.Eps[uuid]; ok {
155 rtmgr.Eps[uuid].Keepalive = true
157 ep := &rtmgr.Endpoint{
160 XAppType: PlatformType,
163 //TxMessages: rtmgr.PLATFORMMESSAGETYPES[e2t.Name]["tx"],
164 //RxMessages: rtmgr.PLATFORMMESSAGETYPES[e2t.Name]["rx"],
169 xapp.Logger.Debug("ep created: %v", ep)
170 if err := sbi.AddEndpoint(ep); err != nil {
171 xapp.Logger.Error("can't create socket for endpoint: " + ep.Name + " due to:" + err.Error())
179 func (s *Sbi) createEndpoint(payload string, sbi Engine) *rtmgr.Endpoint {
180 xapp.Logger.Debug("CreateEndPoint %v", payload)
181 stringSlice := strings.Split(payload, " ")
182 uuid := stringSlice[0]
183 xapp.Logger.Debug(">>> uuid %v", stringSlice[0])
185 if _, ok := rtmgr.Eps[uuid]; ok {
186 ep := rtmgr.Eps[uuid]
190 /* incase the stored Endpoint list is in the form of IP:port*/
191 stringsubsplit := strings.Split(uuid, ":")
192 addr, err := net.LookupIP(stringsubsplit[0])
194 convertedUuid := fmt.Sprintf("%s:%s", addr[0], stringsubsplit[1])
195 xapp.Logger.Info(" IP:Port received is %s", convertedUuid)
196 if _, ok := rtmgr.Eps[convertedUuid]; ok {
197 ep := rtmgr.Eps[convertedUuid]