2 ==================================================================================
3 Copyright (c) 2019 AT&T Intellectual Property.
4 Copyright (c) 2019 Nokia
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
10 http://www.apache.org/licenses/LICENSE-2.0
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 ==================================================================================
23 rnibentities "gerrit.o-ran-sc.org/r/ric-plt/nodeb-rnib.git/entities"
24 rnibreader "gerrit.o-ran-sc.org/r/ric-plt/nodeb-rnib.git/reader"
25 sdl "gerrit.o-ran-sc.org/r/ric-plt/sdlgo"
26 rnibwriter "gerrit.o-ran-sc.org/r/ric-plt/xapp-frame/pkg/rnib"
31 // To be removed later
32 type SDLStatistics struct{}
34 var SDLCounterOpts = []CounterOpts{
35 {Name: "Stored", Help: "The total number of stored SDL transactions"},
36 {Name: "StoreError", Help: "The total number of SDL store errors"},
39 type SDLClient struct {
41 stat map[string]Counter
47 type RNIBNodeType = rnibentities.Node_Type
48 type RNIBGlobalNbId = rnibentities.GlobalNbId
49 type RNIBNodebInfo = rnibentities.NodebInfo
50 type RNIBIRNibError = error
51 type RNIBCells = rnibentities.Cells
52 type RNIBNbIdentity = rnibentities.NbIdentity
53 type RNIBCellType = rnibentities.Cell_Type
54 type RNIBCell = rnibentities.Cell
55 type RNIBEnb = rnibentities.Enb
56 type RNIBGnb = rnibentities.Gnb
58 const RNIBNodeENB = rnibentities.Node_ENB
59 const RNIBNodeGNB = rnibentities.Node_GNB
61 type RNIBServedCellInfo = rnibentities.ServedCellInfo
62 type RNIBNodebInfoEnb = rnibentities.NodebInfo_Enb
63 type RNIBNodebInfoGnb = rnibentities.NodebInfo_Gnb
64 type RNIBServedNRCell = rnibentities.ServedNRCell
65 type RNIBServedNRCellInformation = rnibentities.ServedNRCellInformation
66 type RNIBNrNeighbourInformation = rnibentities.NrNeighbourInformation
68 type RNIBClient struct {
69 reader rnibreader.RNibReader
70 writer rnibwriter.RNibWriter
73 // NewSDLClient returns a new SDLClient.
74 func NewSDLClient(ns string) *SDLClient {
76 db: sdl.NewSdlInstance(ns, sdl.NewDatabase()),
77 stat: Metric.RegisterCounterGroup(SDLCounterOpts, "SDL"),
82 func (s *SDLClient) TestConnection() {
83 // Test DB connection, and wait until ready!
85 if _, err := s.db.GetAll(); err == nil {
88 Logger.Warn("Database connection not ready, waiting ...")
89 time.Sleep(time.Duration(5 * time.Second))
92 Logger.Info("Connection to database established!")
95 func (s *SDLClient) IsReady() bool {
99 func (s *SDLClient) doSet(pairs ...interface{}) (err error) {
100 err = s.db.Set(pairs)
102 s.UpdateStatCounter("StoreError")
104 s.UpdateStatCounter("Stored")
109 func (s *SDLClient) Store(key string, value interface{}) (err error) {
110 return s.doSet(key, value)
113 func (s *SDLClient) MStore(pairs ...interface{}) (err error) {
114 return s.doSet(pairs)
117 func (s *SDLClient) Read(key string) (value map[string]interface{}, err error) {
118 return s.db.Get([]string{key})
121 func (s *SDLClient) MRead(key []string) (value map[string]interface{}, err error) {
125 func (s *SDLClient) ReadAllKeys(key string) (value []string, err error) {
129 func (s *SDLClient) Subscribe(cb func(string, ...string), channel string) error {
130 return s.db.SubscribeChannel(cb, channel)
133 func (s *SDLClient) MSubscribe(cb func(string, ...string), channels ...string) error {
134 return s.db.SubscribeChannel(cb, channels...)
137 func (s *SDLClient) StoreAndPublish(channel string, event string, pairs ...interface{}) error {
138 return s.db.SetAndPublish([]string{channel, event}, pairs...)
141 func (s *SDLClient) MStoreAndPublish(channelsAndEvents []string, pairs ...interface{}) error {
142 return s.db.SetAndPublish(channelsAndEvents, pairs...)
145 func (s *SDLClient) Delete(keys []string) (err error) {
146 return s.db.Remove(keys)
149 func (s *SDLClient) Clear() {
153 func (s *SDLClient) RegisterMetrics() {
154 s.stat = Metric.RegisterCounterGroup(SDLCounterOpts, "SDL")
157 func (s *SDLClient) UpdateStatCounter(name string) {
163 func (c *SDLClient) GetStat() (t SDLStatistics) {
167 func NewRNIBClient(ns string) *RNIBClient {
168 rnibreader.Init("e2Manager", 1)
169 rnibwriter.InitWriter("e2Manager", 1)
176 func (r *RNIBClient) GetNodeb(invName string) (*RNIBNodebInfo, RNIBIRNibError) {
177 return rnibreader.GetRNibReader().GetNodeb(invName)
180 func (r *RNIBClient) GetNodebByGlobalNbId(t RNIBNodeType, gid *RNIBGlobalNbId) (*RNIBNodebInfo, RNIBIRNibError) {
181 return rnibreader.GetRNibReader().GetNodebByGlobalNbId(t, gid)
184 func (r *RNIBClient) GetCellList(invName string) (*RNIBCells, RNIBIRNibError) {
185 return rnibreader.GetRNibReader().GetCellList(invName)
188 func (r *RNIBClient) GetListGnbIds() ([]*RNIBNbIdentity, RNIBIRNibError) {
189 return rnibreader.GetRNibReader().GetListGnbIds()
192 func (r *RNIBClient) GetListEnbIds() ([]*RNIBNbIdentity, RNIBIRNibError) {
193 return rnibreader.GetRNibReader().GetListEnbIds()
196 func (r *RNIBClient) GetCountGnbList() (int, RNIBIRNibError) {
197 return rnibreader.GetRNibReader().GetCountGnbList()
200 func (r *RNIBClient) GetCell(invName string, pci uint32) (*RNIBCell, RNIBIRNibError) {
201 return rnibreader.GetRNibReader().GetCell(invName, pci)
204 func (r *RNIBClient) GetCellById(cellType RNIBCellType, cellId string) (*RNIBCell, RNIBIRNibError) {
205 return rnibreader.GetRNibReader().GetCellById(cellType, cellId)
208 func (r *RNIBClient) SaveNodeb(nbIdentity *RNIBNbIdentity, entity *RNIBNodebInfo) RNIBIRNibError {
209 return rnibwriter.GetRNibWriter().SaveNodeb(nbIdentity, entity)