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" |
wahidw | a8596ec | 2019-12-05 06:30:42 +0000 | [diff] [blame] | 34 | "gerrit.o-ran-sc.org/r/ric-plt/xapp-frame/pkg/xapp" |
kalnagy | 9216265 | 2019-07-02 15:15:49 +0200 | [diff] [blame] | 35 | "routing-manager/pkg/rtmgr" |
zkoczka | eb2ff0d | 2019-09-26 16:59:54 +0200 | [diff] [blame] | 36 | "strconv" |
rangajal | 749099b | 2019-12-10 09:37:08 +0000 | [diff] [blame] | 37 | "strings" |
Balint Uveges | 871fa39 | 2019-04-02 20:31:11 +0000 | [diff] [blame] | 38 | ) |
| 39 | |
zkoczka | aaf8d39 | 2019-10-02 17:16:06 +0200 | [diff] [blame] | 40 | const DefaultNngPipelineSocketPrefix = "tcp://" |
| 41 | const DefaultNngPipelineSocketNumber = 4561 |
| 42 | const PlatformType = "platform" |
Peter Szilagyi | 16d84d6 | 2019-04-24 14:51:02 +0000 | [diff] [blame] | 43 | |
Balint Uveges | 871fa39 | 2019-04-02 20:31:11 +0000 | [diff] [blame] | 44 | var ( |
zkoczka | aaf8d39 | 2019-10-02 17:16:06 +0200 | [diff] [blame] | 45 | SupportedSbis = []*EngineConfig{ |
| 46 | { |
zkoczka | eb2ff0d | 2019-09-26 16:59:54 +0200 | [diff] [blame] | 47 | Name: "nngpush", |
| 48 | Version: "v1", |
| 49 | Protocol: "nngpipeline", |
| 50 | Instance: NewNngPush(), |
| 51 | IsAvailable: true, |
| 52 | }, |
Balint Uveges | 871fa39 | 2019-04-02 20:31:11 +0000 | [diff] [blame] | 53 | } |
| 54 | ) |
| 55 | |
zkoczka | aaf8d39 | 2019-10-02 17:16:06 +0200 | [diff] [blame] | 56 | func GetSbi(sbiName string) (Engine, error) { |
Balint Uveges | 871fa39 | 2019-04-02 20:31:11 +0000 | [diff] [blame] | 57 | for _, sbi := range SupportedSbis { |
kalnagy | 9216265 | 2019-07-02 15:15:49 +0200 | [diff] [blame] | 58 | if sbi.Name == sbiName && sbi.IsAvailable { |
| 59 | return sbi.Instance, nil |
Balint Uveges | 871fa39 | 2019-04-02 20:31:11 +0000 | [diff] [blame] | 60 | } |
| 61 | } |
Peter Szilagyi | 16d84d6 | 2019-04-24 14:51:02 +0000 | [diff] [blame] | 62 | return nil, errors.New("SBI:" + sbiName + " is not supported or still not available") |
| 63 | } |
| 64 | |
kalnagy | 9216265 | 2019-07-02 15:15:49 +0200 | [diff] [blame] | 65 | type Sbi struct { |
kalnagy | 9216265 | 2019-07-02 15:15:49 +0200 | [diff] [blame] | 66 | } |
| 67 | |
zkoczka | aaf8d39 | 2019-10-02 17:16:06 +0200 | [diff] [blame] | 68 | func (s *Sbi) pruneEndpointList(sbi Engine) { |
wahidw | a8596ec | 2019-12-05 06:30:42 +0000 | [diff] [blame] | 69 | xapp.Logger.Debug("pruneEndpointList invoked.") |
zkoczka | eb2ff0d | 2019-09-26 16:59:54 +0200 | [diff] [blame] | 70 | for _, ep := range rtmgr.Eps { |
| 71 | if !ep.Keepalive { |
wahidw | a8596ec | 2019-12-05 06:30:42 +0000 | [diff] [blame] | 72 | xapp.Logger.Debug("deleting %v", ep) |
zkoczka | eb2ff0d | 2019-09-26 16:59:54 +0200 | [diff] [blame] | 73 | sbi.DeleteEndpoint(ep) |
| 74 | delete(rtmgr.Eps, ep.Uuid) |
| 75 | } else { |
| 76 | rtmgr.Eps[ep.Uuid].Keepalive = false |
| 77 | } |
| 78 | } |
Peter Szilagyi | 16d84d6 | 2019-04-24 14:51:02 +0000 | [diff] [blame] | 79 | } |
| 80 | |
zkoczka | aaf8d39 | 2019-10-02 17:16:06 +0200 | [diff] [blame] | 81 | func (s *Sbi) updateEndpoints(rcs *rtmgr.RicComponents, sbi Engine) { |
wahidw | a8596ec | 2019-12-05 06:30:42 +0000 | [diff] [blame] | 82 | for _, xapps := range (*rcs).XApps { |
| 83 | for _, instance := range xapps.Instances { |
zkoczka | eb2ff0d | 2019-09-26 16:59:54 +0200 | [diff] [blame] | 84 | 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{ |
zkoczka | aaf8d39 | 2019-10-02 17:16:06 +0200 | [diff] [blame] | 89 | Uuid: uuid, |
| 90 | Name: instance.Name, |
wahidw | a8596ec | 2019-12-05 06:30:42 +0000 | [diff] [blame] | 91 | XAppType: xapps.Name, |
zkoczka | aaf8d39 | 2019-10-02 17:16:06 +0200 | [diff] [blame] | 92 | Ip: instance.Ip, |
| 93 | Port: instance.Port, |
| 94 | TxMessages: instance.TxMessages, |
| 95 | RxMessages: instance.RxMessages, |
wahidw | a8596ec | 2019-12-05 06:30:42 +0000 | [diff] [blame] | 96 | Policies: instance.Policies, |
zkoczka | aaf8d39 | 2019-10-02 17:16:06 +0200 | [diff] [blame] | 97 | Socket: nil, |
| 98 | IsReady: false, |
| 99 | Keepalive: true, |
zkoczka | eb2ff0d | 2019-09-26 16:59:54 +0200 | [diff] [blame] | 100 | } |
zkoczka | aaf8d39 | 2019-10-02 17:16:06 +0200 | [diff] [blame] | 101 | if err := sbi.AddEndpoint(ep); err != nil { |
wahidw | a8596ec | 2019-12-05 06:30:42 +0000 | [diff] [blame] | 102 | 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] | 103 | continue |
| 104 | } |
| 105 | rtmgr.Eps[uuid] = ep |
| 106 | } |
| 107 | } |
| 108 | } |
zkoczka | aaf8d39 | 2019-10-02 17:16:06 +0200 | [diff] [blame] | 109 | s.updatePlatformEndpoints(&((*rcs).Pcs), sbi) |
rangajal | 749099b | 2019-12-10 09:37:08 +0000 | [diff] [blame] | 110 | s.updateE2TEndpoints(&((*rcs).E2Ts), sbi) |
zkoczka | aaf8d39 | 2019-10-02 17:16:06 +0200 | [diff] [blame] | 111 | s.pruneEndpointList(sbi) |
Balint Uveges | 871fa39 | 2019-04-02 20:31:11 +0000 | [diff] [blame] | 112 | } |
kalnagy | 9216265 | 2019-07-02 15:15:49 +0200 | [diff] [blame] | 113 | |
zkoczka | aaf8d39 | 2019-10-02 17:16:06 +0200 | [diff] [blame] | 114 | func (s *Sbi) updatePlatformEndpoints(pcs *rtmgr.PlatformComponents, sbi Engine) { |
wahidw | a8596ec | 2019-12-05 06:30:42 +0000 | [diff] [blame] | 115 | xapp.Logger.Debug("updatePlatformEndpoints invoked. PCS: %v", *pcs) |
zkoczka | eb2ff0d | 2019-09-26 16:59:54 +0200 | [diff] [blame] | 116 | 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{ |
zkoczka | aaf8d39 | 2019-10-02 17:16:06 +0200 | [diff] [blame] | 122 | 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, |
zkoczka | eb2ff0d | 2019-09-26 16:59:54 +0200 | [diff] [blame] | 132 | } |
wahidw | a8596ec | 2019-12-05 06:30:42 +0000 | [diff] [blame] | 133 | xapp.Logger.Debug("ep created: %v", ep) |
zkoczka | aaf8d39 | 2019-10-02 17:16:06 +0200 | [diff] [blame] | 134 | if err := sbi.AddEndpoint(ep); err != nil { |
wahidw | a8596ec | 2019-12-05 06:30:42 +0000 | [diff] [blame] | 135 | 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] | 136 | continue |
| 137 | } |
| 138 | rtmgr.Eps[uuid] = ep |
| 139 | } |
| 140 | } |
kalnagy | 9216265 | 2019-07-02 15:15:49 +0200 | [diff] [blame] | 141 | } |
rangajal | 749099b | 2019-12-10 09:37:08 +0000 | [diff] [blame] | 142 | |
| 143 | func (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 | } |
wahidw | dd6b056 | 2020-03-31 03:09:45 +0000 | [diff] [blame] | 174 | |
| 175 | func (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 | } |