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