Seed code for Routing Manager (ric-plt/rtmgr).
[ric-plt/rtmgr.git] / pkg / sbi / sbi.go
1 /*
2 ==================================================================================
3   Copyright (c) 2019 AT&T Intellectual Property.
4   Copyright (c) 2019 Nokia
5
6    Licensed under the Apache License, Version 2.0 (the "License");
7    you may not use this file except in compliance with the License.
8    You may obtain a copy of the License at
9
10        http://www.apache.org/licenses/LICENSE-2.0
11
12    Unless required by applicable law or agreed to in writing, software
13    distributed under the License is distributed on an "AS IS" BASIS,
14    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15    See the License for the specific language governing permissions and
16    limitations under the License.
17 ==================================================================================
18 */
19 /*
20   Mnemonic:     sbi.go
21   Abstract:     Contains SBI (SouthBound Interface) module definitions and generic SBI components
22   Date:         16 March 2019
23 */
24
25 package sbi
26
27 import (
28         "errors"
29         "fmt"
30         "rtmgr"
31 )
32
33 var (
34         SupportedSbis = []*SbiEngineConfig{
35                 &SbiEngineConfig{
36                         SbiEngine{
37                                 Name:     "nngpub",
38                                 Version:  "v1",
39                                 Protocol: "nngpubsub",
40                         },
41                         openSocket(openNngPub),
42                         closeSocket(closeNngPub),
43                         distributeAll(publishAll),
44                         true,
45                 },
46                 &SbiEngineConfig{
47                         SbiEngine{
48                                 Name:     "nngpush",
49                                 Version:  "v1",
50                                 Protocol: "nngpipeline",
51                         },
52                         openSocket(nil),
53                         closeSocket(nil),
54                         distributeAll(nil),
55                         false,
56                 },
57         }
58 )
59
60 func ListSbis() {
61         fmt.Printf("SBI:\n")
62         for _, sbi := range SupportedSbis {
63                 if sbi.IsAvailable {
64                         rtmgr.Logger.Info(sbi.Engine.Name + "/" + sbi.Engine.Version)
65                 }
66         }
67 }
68
69 func GetSbi(sbiName string) (*SbiEngineConfig, error) {
70         for _, sbi := range SupportedSbis {
71                 if sbi.Engine.Name == sbiName && sbi.IsAvailable {
72                         return sbi, nil
73                 }
74         }
75         return nil, errors.New("SBI:" + sbiName + "is not supported or still not a available")
76 }