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