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 rnibcommon "gerrit.o-ran-sc.org/r/ric-plt/nodeb-rnib.git/common"
24 rnibentities "gerrit.o-ran-sc.org/r/ric-plt/nodeb-rnib.git/entities"
25 rnibreader "gerrit.o-ran-sc.org/r/ric-plt/nodeb-rnib.git/reader"
26 sdl "gerrit.o-ran-sc.org/r/ric-plt/sdlgo"
27 uenibprotobuf "gerrit.o-ran-sc.org/r/ric-plt/ue-nib/uenibprotobuf"
28 uenibreader "gerrit.o-ran-sc.org/r/ric-plt/ue-nib/uenibreader"
29 uenibwriter "gerrit.o-ran-sc.org/r/ric-plt/ue-nib/uenibwriter"
30 rnibwriter "gerrit.o-ran-sc.org/r/ric-plt/xapp-frame/pkg/rnib"
35 // To be removed later
36 type SDLStatistics struct{}
38 var SDLCounterOpts = []CounterOpts{
39 {Name: "Stored", Help: "The total number of stored SDL transactions"},
40 {Name: "StoreError", Help: "The total number of SDL store errors"},
43 type SDLClient struct {
45 stat map[string]Counter
51 type EventCategory = uenibreader.EventCategory
52 type EventCallback = uenibreader.EventCallback
53 type MeasResultNR = uenibprotobuf.MeasResultNR
54 type MeasQuantityResults = uenibprotobuf.MeasResultNR_MeasQuantityResults
55 type MeasResultServMO = uenibprotobuf.MeasResults_MeasResultServMO
56 type MeasResults = uenibprotobuf.MeasResults
58 type UENIBClient struct {
59 reader *uenibreader.Reader
60 writer *uenibwriter.Writer
64 type RNIBNodeType = rnibentities.Node_Type
65 type RNIBGlobalNbId = rnibentities.GlobalNbId
66 type RNIBNodebInfo = rnibentities.NodebInfo
67 type RNIBIRNibError = rnibcommon.IRNibError
68 type RNIBCells = rnibentities.Cells
69 type RNIBNbIdentity = rnibentities.NbIdentity
70 type RNIBCellType = rnibentities.Cell_Type
71 type RNIBCell = rnibentities.Cell
72 type RNIBEnb = rnibentities.Enb
73 type RNIBGnb = rnibentities.Gnb
75 const RNIBNodeENB = rnibentities.Node_ENB
76 const RNIBNodeGNB = rnibentities.Node_GNB
78 type RNIBServedCellInfo = rnibentities.ServedCellInfo
79 type RNIBNodebInfoEnb = rnibentities.NodebInfo_Enb
80 type RNIBNodebInfoGnb = rnibentities.NodebInfo_Gnb
81 type RNIBServedNRCell = rnibentities.ServedNRCell
82 type RNIBServedNRCellInformation = rnibentities.ServedNRCellInformation
83 type RNIBNrNeighbourInformation = rnibentities.NrNeighbourInformation
85 type RNIBClient struct {
86 reader rnibreader.RNibReader
87 writer rnibwriter.RNibWriter
90 // NewSDLClient returns a new SDLClient.
91 func NewSDLClient(ns string) *SDLClient {
93 db: sdl.NewSdlInstance(ns, sdl.NewDatabase()),
94 stat: Metric.RegisterCounterGroup(SDLCounterOpts, "SDL"),
99 func (s *SDLClient) TestConnection() {
100 // Test DB connection, and wait until ready!
102 if _, err := s.db.GetAll(); err == nil {
105 Logger.Warn("Database connection not ready, waiting ...")
106 time.Sleep(time.Duration(5 * time.Second))
109 Logger.Info("Connection to database established!")
112 func (s *SDLClient) IsReady() bool {
116 func (s *SDLClient) doSet(pairs ...interface{}) (err error) {
117 err = s.db.Set(pairs)
119 s.UpdateStatCounter("StoreError")
121 s.UpdateStatCounter("Stored")
126 func (s *SDLClient) Store(key string, value interface{}) (err error) {
127 return s.doSet(key, value)
130 func (s *SDLClient) MStore(pairs ...interface{}) (err error) {
131 return s.doSet(pairs)
134 func (s *SDLClient) Read(key string) (value map[string]interface{}, err error) {
135 return s.db.Get([]string{key})
138 func (s *SDLClient) MRead(key []string) (value map[string]interface{}, err error) {
142 func (s *SDLClient) ReadAllKeys(key string) (value []string, err error) {
146 func (s *SDLClient) Subscribe(cb func(string, ...string), channel string) error {
147 return s.db.SubscribeChannel(cb, channel)
150 func (s *SDLClient) MSubscribe(cb func(string, ...string), channels ...string) error {
151 return s.db.SubscribeChannel(cb, channels...)
154 func (s *SDLClient) StoreAndPublish(channel string, event string, pairs ...interface{}) error {
155 return s.db.SetAndPublish([]string{channel, event}, pairs...)
158 func (s *SDLClient) MStoreAndPublish(channelsAndEvents []string, pairs ...interface{}) error {
159 return s.db.SetAndPublish(channelsAndEvents, pairs...)
162 func (s *SDLClient) Delete(keys []string) (err error) {
163 return s.db.Remove(keys)
166 func (s *SDLClient) Clear() {
170 func (s *SDLClient) RegisterMetrics() {
171 s.stat = Metric.RegisterCounterGroup(SDLCounterOpts, "SDL")
174 func (s *SDLClient) UpdateStatCounter(name string) {
180 func (c *SDLClient) GetStat() (t SDLStatistics) {
184 func NewUENIBClient() *UENIBClient {
186 reader: uenibreader.NewReader(),
187 writer: uenibwriter.NewWriter(),
191 func (u *UENIBClient) StoreUeMeasurement(gNbId string, gNbUeX2ApId string, data *uenibprotobuf.MeasResults) error {
192 return u.writer.UpdateUeMeasurement(gNbId, gNbUeX2ApId, data)
195 func (u *UENIBClient) CreateUeContext(gNbId string, gNbUeX2ApId string) error {
196 return u.writer.UeContextAddComplete(gNbId, gNbUeX2ApId)
199 func (u *UENIBClient) ReleaseUeContext(gNbId string, gNbUeX2ApId string) error {
200 return u.writer.RemoveUeContext(gNbId, gNbUeX2ApId)
203 func (u *UENIBClient) ReadUeMeasurement(gNbId string, gNbUeX2ApId string) (*uenibprotobuf.MeasResults, error) {
204 return u.reader.GetUeMeasurement(gNbId, gNbUeX2ApId)
207 func (u *UENIBClient) SubscribeEvents(gNbIDs []string, eventCategories []EventCategory, cb EventCallback) error {
208 return u.reader.SubscribeEvents(gNbIDs, eventCategories, cb)
211 func NewRNIBClient(ns string) *RNIBClient {
212 rnibreader.Init("e2Manager", 1)
213 rnibwriter.InitWriter("e2Manager", 1)
220 func (r *RNIBClient) GetNodeb(invName string) (*RNIBNodebInfo, RNIBIRNibError) {
221 return rnibreader.GetRNibReader().GetNodeb(invName)
224 func (r *RNIBClient) GetNodebByGlobalNbId(t RNIBNodeType, gid *RNIBGlobalNbId) (*RNIBNodebInfo, RNIBIRNibError) {
225 return rnibreader.GetRNibReader().GetNodebByGlobalNbId(t, gid)
228 func (r *RNIBClient) GetCellList(invName string) (*RNIBCells, RNIBIRNibError) {
229 return rnibreader.GetRNibReader().GetCellList(invName)
232 func (r *RNIBClient) GetListGnbIds() (*[]*RNIBNbIdentity, RNIBIRNibError) {
233 return rnibreader.GetRNibReader().GetListGnbIds()
236 func (r *RNIBClient) GetListEnbIds() (*[]*RNIBNbIdentity, RNIBIRNibError) {
237 return rnibreader.GetRNibReader().GetListEnbIds()
240 func (r *RNIBClient) GetCountGnbList() (int, RNIBIRNibError) {
241 return rnibreader.GetRNibReader().GetCountGnbList()
244 func (r *RNIBClient) GetCell(invName string, pci uint32) (*RNIBCell, RNIBIRNibError) {
245 return rnibreader.GetRNibReader().GetCell(invName, pci)
248 func (r *RNIBClient) GetCellById(cellType RNIBCellType, cellId string) (*RNIBCell, RNIBIRNibError) {
249 return rnibreader.GetRNibReader().GetCellById(cellType, cellId)
252 func (r *RNIBClient) SaveNodeb(nbIdentity *RNIBNbIdentity, entity *RNIBNodebInfo) RNIBIRNibError {
253 return rnibwriter.GetRNibWriter().SaveNodeb(nbIdentity, entity)