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 uenibprotobuf "gerrit.o-ran-sc.org/r/ric-plt/ue-nib/uenibprotobuf"
27 uenibreader "gerrit.o-ran-sc.org/r/ric-plt/ue-nib/uenibreader"
28 uenibwriter "gerrit.o-ran-sc.org/r/ric-plt/ue-nib/uenibwriter"
29 rnibwriter "gerrit.o-ran-sc.org/r/ric-plt/xapp-frame/pkg/rnib"
34 // To be removed later
35 type SDLStatistics struct{}
37 var SDLCounterOpts = []CounterOpts{
38 {Name: "Stored", Help: "The total number of stored SDL transactions"},
39 {Name: "StoreError", Help: "The total number of SDL store errors"},
42 type SDLClient struct {
44 stat map[string]Counter
50 type EventCategory = uenibreader.EventCategory
51 type EventCallback = uenibreader.EventCallback
52 type MeasResultNR = uenibprotobuf.MeasResultNR
53 type MeasQuantityResults = uenibprotobuf.MeasResultNR_MeasQuantityResults
54 type MeasResultServMO = uenibprotobuf.MeasResults_MeasResultServMO
55 type MeasResults = uenibprotobuf.MeasResults
57 type UENIBClient struct {
58 reader *uenibreader.Reader
59 writer *uenibwriter.Writer
63 type RNIBNodeType = rnibentities.Node_Type
64 type RNIBGlobalNbId = rnibentities.GlobalNbId
65 type RNIBNodebInfo = rnibentities.NodebInfo
66 type RNIBIRNibError = error
67 type RNIBCells = rnibentities.Cells
68 type RNIBNbIdentity = rnibentities.NbIdentity
69 type RNIBCellType = rnibentities.Cell_Type
70 type RNIBCell = rnibentities.Cell
71 type RNIBEnb = rnibentities.Enb
72 type RNIBGnb = rnibentities.Gnb
74 const RNIBNodeENB = rnibentities.Node_ENB
75 const RNIBNodeGNB = rnibentities.Node_GNB
77 type RNIBServedCellInfo = rnibentities.ServedCellInfo
78 type RNIBNodebInfoEnb = rnibentities.NodebInfo_Enb
79 type RNIBNodebInfoGnb = rnibentities.NodebInfo_Gnb
80 type RNIBServedNRCell = rnibentities.ServedNRCell
81 type RNIBServedNRCellInformation = rnibentities.ServedNRCellInformation
82 type RNIBNrNeighbourInformation = rnibentities.NrNeighbourInformation
84 type RNIBClient struct {
85 reader rnibreader.RNibReader
86 writer rnibwriter.RNibWriter
89 // NewSDLClient returns a new SDLClient.
90 func NewSDLClient(ns string) *SDLClient {
92 db: sdl.NewSdlInstance(ns, sdl.NewDatabase()),
93 stat: Metric.RegisterCounterGroup(SDLCounterOpts, "SDL"),
98 func (s *SDLClient) TestConnection() {
99 // Test DB connection, and wait until ready!
101 if _, err := s.db.GetAll(); err == nil {
104 Logger.Warn("Database connection not ready, waiting ...")
105 time.Sleep(time.Duration(5 * time.Second))
108 Logger.Info("Connection to database established!")
111 func (s *SDLClient) IsReady() bool {
115 func (s *SDLClient) doSet(pairs ...interface{}) (err error) {
116 err = s.db.Set(pairs)
118 s.UpdateStatCounter("StoreError")
120 s.UpdateStatCounter("Stored")
125 func (s *SDLClient) Store(key string, value interface{}) (err error) {
126 return s.doSet(key, value)
129 func (s *SDLClient) MStore(pairs ...interface{}) (err error) {
130 return s.doSet(pairs)
133 func (s *SDLClient) Read(key string) (value map[string]interface{}, err error) {
134 return s.db.Get([]string{key})
137 func (s *SDLClient) MRead(key []string) (value map[string]interface{}, err error) {
141 func (s *SDLClient) ReadAllKeys(key string) (value []string, err error) {
145 func (s *SDLClient) Subscribe(cb func(string, ...string), channel string) error {
146 return s.db.SubscribeChannel(cb, channel)
149 func (s *SDLClient) MSubscribe(cb func(string, ...string), channels ...string) error {
150 return s.db.SubscribeChannel(cb, channels...)
153 func (s *SDLClient) StoreAndPublish(channel string, event string, pairs ...interface{}) error {
154 return s.db.SetAndPublish([]string{channel, event}, pairs...)
157 func (s *SDLClient) MStoreAndPublish(channelsAndEvents []string, pairs ...interface{}) error {
158 return s.db.SetAndPublish(channelsAndEvents, pairs...)
161 func (s *SDLClient) Delete(keys []string) (err error) {
162 return s.db.Remove(keys)
165 func (s *SDLClient) Clear() {
169 func (s *SDLClient) RegisterMetrics() {
170 s.stat = Metric.RegisterCounterGroup(SDLCounterOpts, "SDL")
173 func (s *SDLClient) UpdateStatCounter(name string) {
179 func (c *SDLClient) GetStat() (t SDLStatistics) {
183 func NewUENIBClient() *UENIBClient {
185 reader: uenibreader.NewReader(),
186 writer: uenibwriter.NewWriter(),
190 func (u *UENIBClient) StoreUeMeasurement(gNbId string, gNbUeX2ApId string, data *uenibprotobuf.MeasResults) error {
191 return u.writer.UpdateUeMeasurement(gNbId, gNbUeX2ApId, data)
194 func (u *UENIBClient) CreateUeContext(gNbId string, gNbUeX2ApId string) error {
195 return u.writer.UeContextAddComplete(gNbId, gNbUeX2ApId)
198 func (u *UENIBClient) ReleaseUeContext(gNbId string, gNbUeX2ApId string) error {
199 return u.writer.RemoveUeContext(gNbId, gNbUeX2ApId)
202 func (u *UENIBClient) ReadUeMeasurement(gNbId string, gNbUeX2ApId string) (*uenibprotobuf.MeasResults, error) {
203 return u.reader.GetUeMeasurement(gNbId, gNbUeX2ApId)
206 func (u *UENIBClient) SubscribeEvents(gNbIDs []string, eventCategories []EventCategory, cb EventCallback) error {
207 return u.reader.SubscribeEvents(gNbIDs, eventCategories, cb)
210 func NewRNIBClient(ns string) *RNIBClient {
211 rnibreader.Init("e2Manager", 1)
212 rnibwriter.InitWriter("e2Manager", 1)
219 func (r *RNIBClient) GetNodeb(invName string) (*RNIBNodebInfo, RNIBIRNibError) {
220 return rnibreader.GetRNibReader().GetNodeb(invName)
223 func (r *RNIBClient) GetNodebByGlobalNbId(t RNIBNodeType, gid *RNIBGlobalNbId) (*RNIBNodebInfo, RNIBIRNibError) {
224 return rnibreader.GetRNibReader().GetNodebByGlobalNbId(t, gid)
227 func (r *RNIBClient) GetCellList(invName string) (*RNIBCells, RNIBIRNibError) {
228 return rnibreader.GetRNibReader().GetCellList(invName)
231 func (r *RNIBClient) GetListGnbIds() ([]*RNIBNbIdentity, RNIBIRNibError) {
232 return rnibreader.GetRNibReader().GetListGnbIds()
235 func (r *RNIBClient) GetListEnbIds() ([]*RNIBNbIdentity, RNIBIRNibError) {
236 return rnibreader.GetRNibReader().GetListEnbIds()
239 func (r *RNIBClient) GetCountGnbList() (int, RNIBIRNibError) {
240 return rnibreader.GetRNibReader().GetCountGnbList()
243 func (r *RNIBClient) GetCell(invName string, pci uint32) (*RNIBCell, RNIBIRNibError) {
244 return rnibreader.GetRNibReader().GetCell(invName, pci)
247 func (r *RNIBClient) GetCellById(cellType RNIBCellType, cellId string) (*RNIBCell, RNIBIRNibError) {
248 return rnibreader.GetRNibReader().GetCellById(cellType, cellId)
251 func (r *RNIBClient) SaveNodeb(nbIdentity *RNIBNbIdentity, entity *RNIBNodebInfo) RNIBIRNibError {
252 return rnibwriter.GetRNibWriter().SaveNodeb(nbIdentity, entity)