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 rtmgr.Eps[ep.Uuid].Keepalive = false
83 func (s *Sbi) updateEndpoints(rcs *rtmgr.RicComponents, sbi Engine) {
84 for _, xapps := range (*rcs).XApps {
85 for _, instance := range xapps.Instances {
86 uuid := instance.Ip + ":" + strconv.Itoa(int(instance.Port))
87 if _, ok := rtmgr.Eps[uuid]; ok {
88 rtmgr.Eps[uuid].Keepalive = true
90 ep := &rtmgr.Endpoint{
96 TxMessages: instance.TxMessages,
97 RxMessages: instance.RxMessages,
98 Policies: instance.Policies,
103 if err := sbi.AddEndpoint(ep); err != nil {
104 xapp.Logger.Error("can't create socket for endpoint: " + ep.Name + " due to:" + err.Error())
111 s.updatePlatformEndpoints(&((*rcs).Pcs), sbi)
112 s.updateE2TEndpoints(&((*rcs).E2Ts), sbi)
113 s.pruneEndpointList(sbi)
116 func (s *Sbi) updatePlatformEndpoints(pcs *rtmgr.PlatformComponents, sbi Engine) {
117 xapp.Logger.Debug("updatePlatformEndpoints invoked. PCS: %v", *pcs)
118 for _, pc := range *pcs {
119 uuid := pc.Fqdn + ":" + strconv.Itoa(int(pc.Port))
120 if _, ok := rtmgr.Eps[uuid]; ok {
121 rtmgr.Eps[uuid].Keepalive = true
123 ep := &rtmgr.Endpoint{
126 XAppType: PlatformType,
129 TxMessages: rtmgr.PLATFORMMESSAGETYPES[pc.Name]["tx"],
130 RxMessages: rtmgr.PLATFORMMESSAGETYPES[pc.Name]["rx"],
135 xapp.Logger.Debug("ep created: %v", ep)
136 if err := sbi.AddEndpoint(ep); err != nil {
137 xapp.Logger.Error("can't create socket for endpoint: " + ep.Name + " due to:" + err.Error())
145 func (s *Sbi) updateE2TEndpoints(E2Ts *map[string]rtmgr.E2TInstance, sbi Engine) {
146 xapp.Logger.Debug("updateE2TEndpoints invoked. E2T: %v", *E2Ts)
147 for _, e2t := range *E2Ts {
149 stringSlice := strings.Split(e2t.Fqdn, ":")
150 ipaddress := stringSlice[0]
151 port, _ := strconv.Atoi(stringSlice[1])
152 if _, ok := rtmgr.Eps[uuid]; ok {
153 rtmgr.Eps[uuid].Keepalive = true
155 ep := &rtmgr.Endpoint{
158 XAppType: PlatformType,
161 TxMessages: rtmgr.PLATFORMMESSAGETYPES[e2t.Name]["tx"],
162 RxMessages: rtmgr.PLATFORMMESSAGETYPES[e2t.Name]["rx"],
167 xapp.Logger.Debug("ep created: %v", ep)
168 if err := sbi.AddEndpoint(ep); err != nil {
169 xapp.Logger.Error("can't create socket for endpoint: " + ep.Name + " due to:" + err.Error())
177 func (s *Sbi) createEndpoint(payload string, sbi Engine) *rtmgr.Endpoint {
178 xapp.Logger.Debug("CreateEndPoint %v", payload)
179 stringSlice := strings.Split(payload, " ")
180 uuid := stringSlice[0]
181 xapp.Logger.Debug(">>> uuid %v", stringSlice[0])
183 if _, ok := rtmgr.Eps[uuid]; ok {
184 ep := rtmgr.Eps[uuid]
188 /* incase the stored Endpoint list is in the form of IP:port*/
189 stringsubsplit := strings.Split(uuid, ":")
190 addr, err := net.LookupIP(stringsubsplit[0])
192 convertedUuid := fmt.Sprintf("%s:%s", addr[0], stringsubsplit[1])
193 xapp.Logger.Info(" IP:Port received is %s", convertedUuid)
194 if _, ok := rtmgr.Eps[convertedUuid]; ok {
195 ep := rtmgr.Eps[convertedUuid]