Balint Uveges | 871fa39 | 2019-04-02 20:31:11 +0000 | [diff] [blame] | 1 | /* |
Peter Szilagyi | 16d84d6 | 2019-04-24 14:51:02 +0000 | [diff] [blame] | 2 | w |
Balint Uveges | 871fa39 | 2019-04-02 20:31:11 +0000 | [diff] [blame] | 3 | ================================================================================== |
| 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. |
wahidw | 761934a | 2019-11-27 06:07:26 +0000 | [diff] [blame] | 18 | |
| 19 | This source code is part of the near-RT RIC (RAN Intelligent Controller) |
| 20 | platform project (RICP). |
| 21 | |
Balint Uveges | 871fa39 | 2019-04-02 20:31:11 +0000 | [diff] [blame] | 22 | ================================================================================== |
| 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 | |
| 30 | package sbi |
| 31 | |
| 32 | import ( |
| 33 | "errors" |
rangajal | 2037469 | 2020-08-11 06:51:17 +0000 | [diff] [blame] | 34 | //"fmt" |
wahidw | a8596ec | 2019-12-05 06:30:42 +0000 | [diff] [blame] | 35 | "gerrit.o-ran-sc.org/r/ric-plt/xapp-frame/pkg/xapp" |
rangajal | 2037469 | 2020-08-11 06:51:17 +0000 | [diff] [blame] | 36 | //"net" |
kalnagy | 9216265 | 2019-07-02 15:15:49 +0200 | [diff] [blame] | 37 | "routing-manager/pkg/rtmgr" |
zkoczka | eb2ff0d | 2019-09-26 16:59:54 +0200 | [diff] [blame] | 38 | "strconv" |
rangajal | 749099b | 2019-12-10 09:37:08 +0000 | [diff] [blame] | 39 | "strings" |
Balint Uveges | 871fa39 | 2019-04-02 20:31:11 +0000 | [diff] [blame] | 40 | ) |
| 41 | |
wahidw | bce6747 | 2020-06-15 13:52:55 +0000 | [diff] [blame] | 42 | const DefaultRmrPipelineSocketPrefix = "tcp://" |
| 43 | const DefaultRmrPipelineSocketNumber = 4561 |
zkoczka | aaf8d39 | 2019-10-02 17:16:06 +0200 | [diff] [blame] | 44 | const PlatformType = "platform" |
Peter Szilagyi | 16d84d6 | 2019-04-24 14:51:02 +0000 | [diff] [blame] | 45 | |
Balint Uveges | 871fa39 | 2019-04-02 20:31:11 +0000 | [diff] [blame] | 46 | var ( |
zkoczka | aaf8d39 | 2019-10-02 17:16:06 +0200 | [diff] [blame] | 47 | SupportedSbis = []*EngineConfig{ |
| 48 | { |
wahidw | bce6747 | 2020-06-15 13:52:55 +0000 | [diff] [blame] | 49 | Name: "rmrpush", |
zkoczka | eb2ff0d | 2019-09-26 16:59:54 +0200 | [diff] [blame] | 50 | Version: "v1", |
wahidw | bce6747 | 2020-06-15 13:52:55 +0000 | [diff] [blame] | 51 | Protocol: "rmrpipeline", |
| 52 | Instance: NewRmrPush(), |
zkoczka | eb2ff0d | 2019-09-26 16:59:54 +0200 | [diff] [blame] | 53 | IsAvailable: true, |
| 54 | }, |
Balint Uveges | 871fa39 | 2019-04-02 20:31:11 +0000 | [diff] [blame] | 55 | } |
| 56 | ) |
| 57 | |
zkoczka | aaf8d39 | 2019-10-02 17:16:06 +0200 | [diff] [blame] | 58 | func GetSbi(sbiName string) (Engine, error) { |
Balint Uveges | 871fa39 | 2019-04-02 20:31:11 +0000 | [diff] [blame] | 59 | for _, sbi := range SupportedSbis { |
kalnagy | 9216265 | 2019-07-02 15:15:49 +0200 | [diff] [blame] | 60 | if sbi.Name == sbiName && sbi.IsAvailable { |
| 61 | return sbi.Instance, nil |
Balint Uveges | 871fa39 | 2019-04-02 20:31:11 +0000 | [diff] [blame] | 62 | } |
| 63 | } |
Peter Szilagyi | 16d84d6 | 2019-04-24 14:51:02 +0000 | [diff] [blame] | 64 | return nil, errors.New("SBI:" + sbiName + " is not supported or still not available") |
| 65 | } |
| 66 | |
kalnagy | 9216265 | 2019-07-02 15:15:49 +0200 | [diff] [blame] | 67 | type Sbi struct { |
kalnagy | 9216265 | 2019-07-02 15:15:49 +0200 | [diff] [blame] | 68 | } |
| 69 | |
zkoczka | aaf8d39 | 2019-10-02 17:16:06 +0200 | [diff] [blame] | 70 | func (s *Sbi) pruneEndpointList(sbi Engine) { |
wahidw | a8596ec | 2019-12-05 06:30:42 +0000 | [diff] [blame] | 71 | xapp.Logger.Debug("pruneEndpointList invoked.") |
zkoczka | eb2ff0d | 2019-09-26 16:59:54 +0200 | [diff] [blame] | 72 | for _, ep := range rtmgr.Eps { |
| 73 | if !ep.Keepalive { |
wahidw | a8596ec | 2019-12-05 06:30:42 +0000 | [diff] [blame] | 74 | xapp.Logger.Debug("deleting %v", ep) |
zkoczka | eb2ff0d | 2019-09-26 16:59:54 +0200 | [diff] [blame] | 75 | sbi.DeleteEndpoint(ep) |
| 76 | delete(rtmgr.Eps, ep.Uuid) |
| 77 | } else { |
wahidw | 8f7ca65 | 2020-07-08 18:59:53 +0530 | [diff] [blame] | 78 | if rtmgr.Eps[ep.Uuid] != nil { |
| 79 | rtmgr.Eps[ep.Uuid].Keepalive = false |
| 80 | } |
zkoczka | eb2ff0d | 2019-09-26 16:59:54 +0200 | [diff] [blame] | 81 | } |
| 82 | } |
Peter Szilagyi | 16d84d6 | 2019-04-24 14:51:02 +0000 | [diff] [blame] | 83 | } |
| 84 | |
zkoczka | aaf8d39 | 2019-10-02 17:16:06 +0200 | [diff] [blame] | 85 | func (s *Sbi) updateEndpoints(rcs *rtmgr.RicComponents, sbi Engine) { |
wahidw | a8596ec | 2019-12-05 06:30:42 +0000 | [diff] [blame] | 86 | for _, xapps := range (*rcs).XApps { |
| 87 | for _, instance := range xapps.Instances { |
zkoczka | eb2ff0d | 2019-09-26 16:59:54 +0200 | [diff] [blame] | 88 | uuid := instance.Ip + ":" + strconv.Itoa(int(instance.Port)) |
| 89 | if _, ok := rtmgr.Eps[uuid]; ok { |
| 90 | rtmgr.Eps[uuid].Keepalive = true |
| 91 | } else { |
| 92 | ep := &rtmgr.Endpoint{ |
zkoczka | aaf8d39 | 2019-10-02 17:16:06 +0200 | [diff] [blame] | 93 | Uuid: uuid, |
| 94 | Name: instance.Name, |
wahidw | a8596ec | 2019-12-05 06:30:42 +0000 | [diff] [blame] | 95 | XAppType: xapps.Name, |
zkoczka | aaf8d39 | 2019-10-02 17:16:06 +0200 | [diff] [blame] | 96 | Ip: instance.Ip, |
| 97 | Port: instance.Port, |
| 98 | TxMessages: instance.TxMessages, |
| 99 | RxMessages: instance.RxMessages, |
wahidw | a8596ec | 2019-12-05 06:30:42 +0000 | [diff] [blame] | 100 | Policies: instance.Policies, |
zkoczka | aaf8d39 | 2019-10-02 17:16:06 +0200 | [diff] [blame] | 101 | Socket: nil, |
| 102 | IsReady: false, |
| 103 | Keepalive: true, |
zkoczka | eb2ff0d | 2019-09-26 16:59:54 +0200 | [diff] [blame] | 104 | } |
zkoczka | aaf8d39 | 2019-10-02 17:16:06 +0200 | [diff] [blame] | 105 | if err := sbi.AddEndpoint(ep); err != nil { |
wahidw | a8596ec | 2019-12-05 06:30:42 +0000 | [diff] [blame] | 106 | xapp.Logger.Error("can't create socket for endpoint: " + ep.Name + " due to:" + err.Error()) |
zkoczka | eb2ff0d | 2019-09-26 16:59:54 +0200 | [diff] [blame] | 107 | continue |
| 108 | } |
| 109 | rtmgr.Eps[uuid] = ep |
| 110 | } |
| 111 | } |
| 112 | } |
zkoczka | aaf8d39 | 2019-10-02 17:16:06 +0200 | [diff] [blame] | 113 | s.updatePlatformEndpoints(&((*rcs).Pcs), sbi) |
wahidw | 6ddad90 | 2020-04-01 16:39:15 +0000 | [diff] [blame] | 114 | s.updateE2TEndpoints(&((*rcs).E2Ts), sbi) |
zkoczka | aaf8d39 | 2019-10-02 17:16:06 +0200 | [diff] [blame] | 115 | s.pruneEndpointList(sbi) |
Balint Uveges | 871fa39 | 2019-04-02 20:31:11 +0000 | [diff] [blame] | 116 | } |
kalnagy | 9216265 | 2019-07-02 15:15:49 +0200 | [diff] [blame] | 117 | |
zkoczka | aaf8d39 | 2019-10-02 17:16:06 +0200 | [diff] [blame] | 118 | func (s *Sbi) updatePlatformEndpoints(pcs *rtmgr.PlatformComponents, sbi Engine) { |
wahidw | a8596ec | 2019-12-05 06:30:42 +0000 | [diff] [blame] | 119 | xapp.Logger.Debug("updatePlatformEndpoints invoked. PCS: %v", *pcs) |
zkoczka | eb2ff0d | 2019-09-26 16:59:54 +0200 | [diff] [blame] | 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 |
| 124 | } else { |
| 125 | ep := &rtmgr.Endpoint{ |
zkoczka | aaf8d39 | 2019-10-02 17:16:06 +0200 | [diff] [blame] | 126 | Uuid: uuid, |
| 127 | Name: pc.Name, |
| 128 | XAppType: PlatformType, |
| 129 | Ip: pc.Fqdn, |
| 130 | Port: pc.Port, |
wahidw | 82c7266 | 2020-07-15 20:22:50 +0530 | [diff] [blame] | 131 | //TxMessages: rtmgr.PLATFORMMESSAGETYPES[pc.Name]["tx"], |
| 132 | //RxMessages: rtmgr.PLATFORMMESSAGETYPES[pc.Name]["rx"], |
zkoczka | aaf8d39 | 2019-10-02 17:16:06 +0200 | [diff] [blame] | 133 | Socket: nil, |
| 134 | IsReady: false, |
| 135 | Keepalive: true, |
zkoczka | eb2ff0d | 2019-09-26 16:59:54 +0200 | [diff] [blame] | 136 | } |
wahidw | a8596ec | 2019-12-05 06:30:42 +0000 | [diff] [blame] | 137 | xapp.Logger.Debug("ep created: %v", ep) |
zkoczka | aaf8d39 | 2019-10-02 17:16:06 +0200 | [diff] [blame] | 138 | if err := sbi.AddEndpoint(ep); err != nil { |
wahidw | a8596ec | 2019-12-05 06:30:42 +0000 | [diff] [blame] | 139 | xapp.Logger.Error("can't create socket for endpoint: " + ep.Name + " due to:" + err.Error()) |
zkoczka | eb2ff0d | 2019-09-26 16:59:54 +0200 | [diff] [blame] | 140 | continue |
| 141 | } |
| 142 | rtmgr.Eps[uuid] = ep |
| 143 | } |
| 144 | } |
kalnagy | 9216265 | 2019-07-02 15:15:49 +0200 | [diff] [blame] | 145 | } |
rangajal | 749099b | 2019-12-10 09:37:08 +0000 | [diff] [blame] | 146 | |
| 147 | func (s *Sbi) updateE2TEndpoints(E2Ts *map[string]rtmgr.E2TInstance, sbi Engine) { |
wahidw | 6ddad90 | 2020-04-01 16:39:15 +0000 | [diff] [blame] | 148 | xapp.Logger.Debug("updateE2TEndpoints invoked. E2T: %v", *E2Ts) |
| 149 | for _, e2t := range *E2Ts { |
| 150 | uuid := e2t.Fqdn |
| 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 |
| 156 | } else { |
| 157 | ep := &rtmgr.Endpoint{ |
| 158 | Uuid: uuid, |
| 159 | Name: e2t.Name, |
| 160 | XAppType: PlatformType, |
| 161 | Ip: ipaddress, |
| 162 | Port: uint16(port), |
wahidw | 82c7266 | 2020-07-15 20:22:50 +0530 | [diff] [blame] | 163 | //TxMessages: rtmgr.PLATFORMMESSAGETYPES[e2t.Name]["tx"], |
| 164 | //RxMessages: rtmgr.PLATFORMMESSAGETYPES[e2t.Name]["rx"], |
wahidw | 6ddad90 | 2020-04-01 16:39:15 +0000 | [diff] [blame] | 165 | Socket: nil, |
| 166 | IsReady: false, |
| 167 | Keepalive: true, |
| 168 | } |
| 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()) |
| 172 | continue |
| 173 | } |
| 174 | rtmgr.Eps[uuid] = ep |
| 175 | } |
| 176 | } |
rangajal | 749099b | 2019-12-10 09:37:08 +0000 | [diff] [blame] | 177 | } |
wahidw | dd6b056 | 2020-03-31 03:09:45 +0000 | [diff] [blame] | 178 | |
wahidw | 6a9ce49 | 2020-08-15 11:29:43 +0530 | [diff] [blame^] | 179 | func (s *Sbi) createEndpoint(payload string,rmrsrc string, sbi Engine) (*string,int) { |
wahidw | dd6b056 | 2020-03-31 03:09:45 +0000 | [diff] [blame] | 180 | xapp.Logger.Debug("CreateEndPoint %v", payload) |
rangajal | 2037469 | 2020-08-11 06:51:17 +0000 | [diff] [blame] | 181 | // stringSlice := strings.Split(payload, " ") |
| 182 | // uuid := stringSlice[0] |
| 183 | // xapp.Logger.Debug(">>> uuid %v", stringSlice[0]) |
wahidw | dd6b056 | 2020-03-31 03:09:45 +0000 | [diff] [blame] | 184 | |
rangajal | 2037469 | 2020-08-11 06:51:17 +0000 | [diff] [blame] | 185 | /* if _, ok := rtmgr.Eps[uuid]; ok { |
wahidw | dd6b056 | 2020-03-31 03:09:45 +0000 | [diff] [blame] | 186 | ep := rtmgr.Eps[uuid] |
| 187 | return ep |
rangajal | 2037469 | 2020-08-11 06:51:17 +0000 | [diff] [blame] | 188 | }*/ |
wahidw | dd6b056 | 2020-03-31 03:09:45 +0000 | [diff] [blame] | 189 | |
wahidw | 6ddad90 | 2020-04-01 16:39:15 +0000 | [diff] [blame] | 190 | /* incase the stored Endpoint list is in the form of IP:port*/ |
rangajal | 2037469 | 2020-08-11 06:51:17 +0000 | [diff] [blame] | 191 | /* stringsubsplit := strings.Split(uuid, ":") |
wahidw | 6ddad90 | 2020-04-01 16:39:15 +0000 | [diff] [blame] | 192 | addr, err := net.LookupIP(stringsubsplit[0]) |
| 193 | if err == nil { |
| 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] |
| 198 | return ep |
| 199 | } |
rangajal | 2037469 | 2020-08-11 06:51:17 +0000 | [diff] [blame] | 200 | }*/ |
| 201 | |
| 202 | /* Create a new mapping, this case is assumed for multiple process sending RMR request from a container */ |
| 203 | srcString := strings.Split(rmrsrc," ") |
| 204 | srcStringSlice := strings.Split(srcString[0],"=") |
| 205 | Whid := int(xapp.Rmr.Openwh(srcStringSlice[1])) |
| 206 | |
| 207 | xapp.Logger.Info("Wormhole Id created is %d for EndPoint %s",Whid,srcStringSlice[1]) |
| 208 | if Whid > 0 { |
wahidw | 6a9ce49 | 2020-08-15 11:29:43 +0530 | [diff] [blame^] | 209 | // rtmgr.RmrEp[srcStringSlice[1]] = Whid |
rangajal | 2037469 | 2020-08-11 06:51:17 +0000 | [diff] [blame] | 210 | xapp.Logger.Info("received %s and mapped to Whid = %d",srcStringSlice[1],Whid) |
wahidw | 6a9ce49 | 2020-08-15 11:29:43 +0530 | [diff] [blame^] | 211 | return &srcStringSlice[1],Whid |
wahidw | 6ddad90 | 2020-04-01 16:39:15 +0000 | [diff] [blame] | 212 | } |
| 213 | |
wahidw | 6a9ce49 | 2020-08-15 11:29:43 +0530 | [diff] [blame^] | 214 | return nil,Whid |
rangajal | 2037469 | 2020-08-11 06:51:17 +0000 | [diff] [blame] | 215 | } |