blob: 7d3d6c5d2f8f43a17bdf5f6e5fdcf35f2deb8438 [file] [log] [blame]
ss412gde190682019-10-24 09:29:26 +03001//
2// Copyright 2019 AT&T Intellectual Property
3// Copyright 2019 Nokia
4//
5// Licensed under the Apache License, Version 2.0 (the "License");
6// you may not use this file except in compliance with the License.
7// You may obtain a copy of the License at
8//
9// http://www.apache.org/licenses/LICENSE-2.0
10//
11// Unless required by applicable law or agreed to in writing, software
12// distributed under the License is distributed on an "AS IS" BASIS,
13// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14// See the License for the specific language governing permissions and
15// limitations under the License.
nm755n15d39822019-11-28 16:56:00 +000016
17// This source code is part of the near-RT RIC (RAN Intelligent Controller)
18// platform project (RICP).
19
Amichaie3623cf2019-09-11 16:59:16 +030020package services
21
22import (
23 "e2mgr/configuration"
24 "e2mgr/logger"
25 "e2mgr/rNibWriter"
ss412gefcb4522019-12-02 16:59:19 +020026 "gerrit.o-ran-sc.org/r/ric-plt/nodeb-rnib.git/common"
Amichaie3623cf2019-09-11 16:59:16 +030027 "gerrit.o-ran-sc.org/r/ric-plt/nodeb-rnib.git/entities"
28 "gerrit.o-ran-sc.org/r/ric-plt/nodeb-rnib.git/reader"
29 "net"
30 "time"
31)
32
33type RNibDataService interface {
idanshaldc8932a2020-07-14 07:31:02 +000034 SaveNodeb(nodebInfo *entities.NodebInfo) error
Amichaie3623cf2019-09-11 16:59:16 +030035 UpdateNodebInfo(nodebInfo *entities.NodebInfo) error
36 SaveRanLoadInformation(inventoryName string, ranLoadInformation *entities.RanLoadInformation) error
37 GetNodeb(ranName string) (*entities.NodebInfo, error)
38 GetListNodebIds() ([]*entities.NbIdentity, error)
ss412gde190682019-10-24 09:29:26 +030039 PingRnib() bool
ss412gefcb4522019-12-02 16:59:19 +020040 GetE2TInstance(address string) (*entities.E2TInstance, error)
41 GetE2TInstances(addresses []string) ([]*entities.E2TInstance, error)
42 GetE2TAddresses() ([]string, error)
43 SaveE2TInstance(e2tInstance *entities.E2TInstance) error
44 SaveE2TAddresses(addresses []string) error
45 GetE2TInstanceNoLogs(address string) (*entities.E2TInstance, error)
46 GetE2TInstancesNoLogs(addresses []string) ([]*entities.E2TInstance, error)
47 SaveE2TInstanceNoLogs(e2tInstance *entities.E2TInstance) error
48 GetE2TAddressesNoLogs() ([]string, error)
Amichaif846c592020-01-08 16:45:07 +020049 RemoveE2TInstance(e2tAddress string) error
idanshal08bbf912020-04-20 17:11:33 +030050 UpdateGnbCells(nodebInfo *entities.NodebInfo, servedNrCells []*entities.ServedNRCell) error
idanshald916e2a2020-04-22 15:56:43 +030051 RemoveServedNrCells(inventoryName string, servedNrCells []*entities.ServedNRCell) error
ss412ga07b8592020-06-16 21:51:33 +030052 GetGeneralConfiguration() (*entities.GeneralConfiguration, error)
53 UpdateNodebInfoOnConnectionStatusInversion(nodebInfo *entities.NodebInfo, event string) error
54 SaveGeneralConfiguration(config *entities.GeneralConfiguration) error
Amichai7e2e4932020-07-07 15:49:07 +000055 RemoveEnb(nodebInfo *entities.NodebInfo) error
Irina5830d4d2020-07-08 18:11:04 +000056 RemoveServedCells(inventoryName string, servedCells []*entities.ServedCellInfo) error
57 UpdateEnb(nodebInfo *entities.NodebInfo, servedCells []*entities.ServedCellInfo) error
idanshaldc8932a2020-07-14 07:31:02 +000058 AddNbIdentity(nodeType entities.Node_Type, nbIdentity *entities.NbIdentity) error
Amichai1bf79dd2020-07-16 21:15:32 +000059 RemoveNbIdentity(nodeType entities.Node_Type, nbIdentity *entities.NbIdentity) error
Amichai7ec48b22020-07-23 11:28:40 +000060 AddEnb(nodebInfo *entities.NodebInfo) error
Amichaie3623cf2019-09-11 16:59:16 +030061}
62
63type rNibDataService struct {
idanshaldc8932a2020-07-14 07:31:02 +000064 logger *logger.Logger
65 rnibReader reader.RNibReader
66 rnibWriter rNibWriter.RNibWriter
67 maxAttempts int
68 retryInterval time.Duration
Amichaie3623cf2019-09-11 16:59:16 +030069}
70
ss412gefcb4522019-12-02 16:59:19 +020071func NewRnibDataService(logger *logger.Logger, config *configuration.Configuration, rnibReader reader.RNibReader, rnibWriter rNibWriter.RNibWriter) *rNibDataService {
Amichaie3623cf2019-09-11 16:59:16 +030072 return &rNibDataService{
idanshaldc8932a2020-07-14 07:31:02 +000073 logger: logger,
74 rnibReader: rnibReader,
75 rnibWriter: rnibWriter,
76 maxAttempts: config.MaxRnibConnectionAttempts,
77 retryInterval: time.Duration(config.RnibRetryIntervalMs) * time.Millisecond,
Amichaie3623cf2019-09-11 16:59:16 +030078 }
79}
80
idanshaldc8932a2020-07-14 07:31:02 +000081func (w *rNibDataService) AddNbIdentity(nodeType entities.Node_Type, nbIdentity *entities.NbIdentity) error {
82 w.logger.Infof("#RnibDataService.AddNbIdentity - nbIdentity: %s", nbIdentity)
83
84 err := w.retry("AddNbIdentity", func() (err error) {
85 err = w.rnibWriter.AddNbIdentity(nodeType, nbIdentity)
86 return
87 })
88
89 return err
90}
91
Amichai1bf79dd2020-07-16 21:15:32 +000092func (w *rNibDataService) RemoveNbIdentity(nodeType entities.Node_Type, nbIdentity *entities.NbIdentity) error{
93 w.logger.Infof("#RnibDataService.RemoveNbIdentity - nbIdentity: %s", nbIdentity)
94
95 err := w.retry("RemoveNbIdentity", func() (err error) {
96 err = w.rnibWriter.RemoveNbIdentity(nodeType, nbIdentity)
97 return
98 })
99
100 return err
101}
102
idanshald916e2a2020-04-22 15:56:43 +0300103func (w *rNibDataService) RemoveServedNrCells(inventoryName string, servedNrCells []*entities.ServedNRCell) error {
104 err := w.retry("RemoveServedNrCells", func() (err error) {
105 err = w.rnibWriter.RemoveServedNrCells(inventoryName, servedNrCells)
106 return
107 })
108
109 return err
110}
111
Amichai7e2e4932020-07-07 15:49:07 +0000112func (w *rNibDataService) RemoveEnb(nodebInfo *entities.NodebInfo) error {
Amichaic7018fe2020-07-09 10:18:52 +0000113 w.logger.Infof("#RnibDataService.RemoveEnb - nodebInfo: %s", nodebInfo)
114
Amichai7e2e4932020-07-07 15:49:07 +0000115 err := w.retry("RemoveEnb", func() (err error) {
116 err = w.rnibWriter.RemoveEnb(nodebInfo)
117 return
118 })
119
120 return err
121}
122
idanshal08bbf912020-04-20 17:11:33 +0300123func (w *rNibDataService) UpdateGnbCells(nodebInfo *entities.NodebInfo, servedNrCells []*entities.ServedNRCell) error {
124 w.logger.Infof("#RnibDataService.UpdateGnbCells - nodebInfo: %s, servedNrCells: %s", nodebInfo, servedNrCells)
125
126 err := w.retry("UpdateGnbCells", func() (err error) {
127 err = w.rnibWriter.UpdateGnbCells(nodebInfo, servedNrCells)
128 return
129 })
130
131 return err
132}
133
Amichaie3623cf2019-09-11 16:59:16 +0300134func (w *rNibDataService) UpdateNodebInfo(nodebInfo *entities.NodebInfo) error {
135 w.logger.Infof("#RnibDataService.UpdateNodebInfo - nodebInfo: %s", nodebInfo)
136
137 err := w.retry("UpdateNodebInfo", func() (err error) {
ss412gefcb4522019-12-02 16:59:19 +0200138 err = w.rnibWriter.UpdateNodebInfo(nodebInfo)
Amichaie3623cf2019-09-11 16:59:16 +0300139 return
140 })
141
142 return err
143}
144
idanshaldc8932a2020-07-14 07:31:02 +0000145func (w *rNibDataService) SaveNodeb(nodebInfo *entities.NodebInfo) error {
146 w.logger.Infof("#RnibDataService.SaveNodeb - nodebInfo: %s", nodebInfo)
Amichaie3623cf2019-09-11 16:59:16 +0300147
148 err := w.retry("SaveNodeb", func() (err error) {
idanshaldc8932a2020-07-14 07:31:02 +0000149 err = w.rnibWriter.SaveNodeb(nodebInfo)
Amichaie3623cf2019-09-11 16:59:16 +0300150 return
151 })
152
153 return err
154}
155
156func (w *rNibDataService) SaveRanLoadInformation(inventoryName string, ranLoadInformation *entities.RanLoadInformation) error {
157 w.logger.Infof("#RnibDataService.SaveRanLoadInformation - inventoryName: %s, ranLoadInformation: %s", inventoryName, ranLoadInformation)
158
159 err := w.retry("SaveRanLoadInformation", func() (err error) {
ss412gefcb4522019-12-02 16:59:19 +0200160 err = w.rnibWriter.SaveRanLoadInformation(inventoryName, ranLoadInformation)
Amichaie3623cf2019-09-11 16:59:16 +0300161 return
162 })
163
164 return err
165}
166
167func (w *rNibDataService) GetNodeb(ranName string) (*entities.NodebInfo, error) {
Amichaie3623cf2019-09-11 16:59:16 +0300168
169 var nodeb *entities.NodebInfo = nil
170
171 err := w.retry("GetNodeb", func() (err error) {
ss412gefcb4522019-12-02 16:59:19 +0200172 nodeb, err = w.rnibReader.GetNodeb(ranName)
Amichaie3623cf2019-09-11 16:59:16 +0300173 return
174 })
175
is005q5c953322020-01-05 16:22:47 +0200176 if err == nil {
Amichai380b7a22020-01-14 16:38:06 +0200177 w.logger.Infof("#RnibDataService.GetNodeb - RAN name: %s, connection status: %s, associated E2T: %s", nodeb.RanName, nodeb.ConnectionStatus, nodeb.AssociatedE2TInstanceAddress)
is005q5c953322020-01-05 16:22:47 +0200178 }
179
Amichaie3623cf2019-09-11 16:59:16 +0300180 return nodeb, err
181}
182
183func (w *rNibDataService) GetListNodebIds() ([]*entities.NbIdentity, error) {
Amichaie3623cf2019-09-11 16:59:16 +0300184 var nodeIds []*entities.NbIdentity = nil
185
186 err := w.retry("GetListNodebIds", func() (err error) {
ss412gefcb4522019-12-02 16:59:19 +0200187 nodeIds, err = w.rnibReader.GetListNodebIds()
Amichaie3623cf2019-09-11 16:59:16 +0300188 return
189 })
190
is005q5c953322020-01-05 16:22:47 +0200191 if err == nil {
192 w.logger.Infof("#RnibDataService.GetListNodebIds - RANs count: %d", len(nodeIds))
193 }
194
Amichaie3623cf2019-09-11 16:59:16 +0300195 return nodeIds, err
196}
197
ss412gefcb4522019-12-02 16:59:19 +0200198func (w *rNibDataService) GetE2TInstance(address string) (*entities.E2TInstance, error) {
199 var e2tInstance *entities.E2TInstance = nil
200
201 err := w.retry("GetE2TInstance", func() (err error) {
202 e2tInstance, err = w.rnibReader.GetE2TInstance(address)
203 return
204 })
205
206 if err == nil {
207 w.logger.Infof("#RnibDataService.GetE2TInstance - E2T instance address: %s, state: %s, associated RANs count: %d, keep Alive ts: %d", e2tInstance.Address, e2tInstance.State, len(e2tInstance.AssociatedRanList), e2tInstance.KeepAliveTimestamp)
208 }
209
210 return e2tInstance, err
211}
212
213func (w *rNibDataService) GetE2TInstanceNoLogs(address string) (*entities.E2TInstance, error) {
214 var e2tInstance *entities.E2TInstance = nil
215
216 err := w.retry("GetE2TInstance", func() (err error) {
217 e2tInstance, err = w.rnibReader.GetE2TInstance(address)
218 return
219 })
220
221 return e2tInstance, err
222}
223
224func (w *rNibDataService) GetE2TInstances(addresses []string) ([]*entities.E2TInstance, error) {
225 w.logger.Infof("#RnibDataService.GetE2TInstances - addresses: %s", addresses)
226 var e2tInstances []*entities.E2TInstance = nil
227
228 err := w.retry("GetE2TInstance", func() (err error) {
229 e2tInstances, err = w.rnibReader.GetE2TInstances(addresses)
230 return
231 })
232
233 return e2tInstances, err
234}
235
236func (w *rNibDataService) GetE2TInstancesNoLogs(addresses []string) ([]*entities.E2TInstance, error) {
237
238 var e2tInstances []*entities.E2TInstance = nil
239
240 err := w.retry("GetE2TInstance", func() (err error) {
241 e2tInstances, err = w.rnibReader.GetE2TInstances(addresses)
242 return
243 })
244
245 return e2tInstances, err
246}
247
248func (w *rNibDataService) GetE2TAddresses() ([]string, error) {
249
250 var e2tAddresses []string = nil
251
252 err := w.retry("GetE2TAddresses", func() (err error) {
253 e2tAddresses, err = w.rnibReader.GetE2TAddresses()
254 return
255 })
256
257 if err == nil {
258 w.logger.Infof("#RnibDataService.GetE2TAddresses - addresses: %s", e2tAddresses)
259 }
260
261 return e2tAddresses, err
262}
263
264func (w *rNibDataService) GetE2TAddressesNoLogs() ([]string, error) {
265
266 var e2tAddresses []string = nil
267
268 err := w.retry("GetE2TAddresses", func() (err error) {
269 e2tAddresses, err = w.rnibReader.GetE2TAddresses()
270 return
271 })
272
273 return e2tAddresses, err
274}
275
276func (w *rNibDataService) SaveE2TInstance(e2tInstance *entities.E2TInstance) error {
Irina49144462020-04-07 16:37:20 +0300277 w.logger.Infof("#RnibDataService.SaveE2TInstance - E2T instance address: %s, podName: %s, state: %s, associated RANs count: %d, keep Alive ts: %d", e2tInstance.Address, e2tInstance.PodName, e2tInstance.State, len(e2tInstance.AssociatedRanList), e2tInstance.KeepAliveTimestamp)
ss412gefcb4522019-12-02 16:59:19 +0200278
279 return w.SaveE2TInstanceNoLogs(e2tInstance)
280}
281
282func (w *rNibDataService) SaveE2TInstanceNoLogs(e2tInstance *entities.E2TInstance) error {
283
284 err := w.retry("SaveE2TInstance", func() (err error) {
285 err = w.rnibWriter.SaveE2TInstance(e2tInstance)
286 return
287 })
288
289 return err
290}
291
292func (w *rNibDataService) SaveE2TAddresses(addresses []string) error {
293 w.logger.Infof("#RnibDataService.SaveE2TAddresses - addresses: %s", addresses)
294
295 err := w.retry("SaveE2TAddresses", func() (err error) {
296 err = w.rnibWriter.SaveE2TAddresses(addresses)
297 return
298 })
299
300 return err
301}
302
Amichaif846c592020-01-08 16:45:07 +0200303func (w *rNibDataService) RemoveE2TInstance(e2tAddress string) error {
304 w.logger.Infof("#RnibDataService.RemoveE2TInstance - e2tAddress: %s", e2tAddress)
305
306 err := w.retry("RemoveE2TInstance", func() (err error) {
307 err = w.rnibWriter.RemoveE2TInstance(e2tAddress)
308 return
309 })
310
311 return err
312}
313
ss412ga07b8592020-06-16 21:51:33 +0300314func (w *rNibDataService) GetGeneralConfiguration() (*entities.GeneralConfiguration, error) {
315 var generalConfiguration *entities.GeneralConfiguration = nil
316
317 err := w.retry("GetGeneralConfiguration", func() (err error) {
318 generalConfiguration, err = w.rnibReader.GetGeneralConfiguration()
319 return
320 })
321
ss412ga07b8592020-06-16 21:51:33 +0300322 return generalConfiguration, err
323}
324
325func (w *rNibDataService) SaveGeneralConfiguration(config *entities.GeneralConfiguration) error {
ss412ga07b8592020-06-16 21:51:33 +0300326 err := w.retry("SaveGeneralConfiguration", func() (err error) {
327 err = w.rnibWriter.SaveGeneralConfiguration(config)
328 return
329 })
330
331 return err
332}
333
Irina5830d4d2020-07-08 18:11:04 +0000334func (w *rNibDataService) RemoveServedCells(inventoryName string, servedCells []*entities.ServedCellInfo) error {
335 err := w.retry("RemoveServedCells", func() (err error) {
336 err = w.rnibWriter.RemoveServedCells(inventoryName, servedCells)
337 return
338 })
339
340 return err
341}
342
343func (w *rNibDataService) UpdateEnb(nodebInfo *entities.NodebInfo, servedCells []*entities.ServedCellInfo) error {
344 err := w.retry("UpdateEnb", func() (err error) {
345 err = w.rnibWriter.UpdateEnb(nodebInfo, servedCells)
346 return
347 })
348
349 return err
350}
351
ss412gde190682019-10-24 09:29:26 +0300352func (w *rNibDataService) PingRnib() bool {
353 err := w.retry("GetListNodebIds", func() (err error) {
ss412gefcb4522019-12-02 16:59:19 +0200354 _, err = w.rnibReader.GetListNodebIds()
ss412gde190682019-10-24 09:29:26 +0300355 return
356 })
357
358 return !isRnibConnectionError(err)
359}
360
ss412ga07b8592020-06-16 21:51:33 +0300361func (w *rNibDataService) UpdateNodebInfoOnConnectionStatusInversion(nodebInfo *entities.NodebInfo, event string) error {
Amichai7e2e4932020-07-07 15:49:07 +0000362 w.logger.Infof("#RnibDataService.UpdateNodebInfoOnConnectionStatusInversion - event: %s, nodebInfo: %s", event, nodebInfo)
ss412ga07b8592020-06-16 21:51:33 +0300363
364 err := w.retry("UpdateNodebInfoOnConnectionStatusInversion", func() (err error) {
Amichai7e2e4932020-07-07 15:49:07 +0000365 err = w.rnibWriter.UpdateNodebInfoOnConnectionStatusInversion(nodebInfo, event)
ss412ga07b8592020-06-16 21:51:33 +0300366 return
367 })
368
369 return err
370}
371
Amichai7ec48b22020-07-23 11:28:40 +0000372func (w *rNibDataService) AddEnb(nodebInfo *entities.NodebInfo) error {
373 w.logger.Infof("#RnibDataService.AddEnb - nodebInfo: %s", nodebInfo)
374
375 err := w.retry("AddEnb", func() (err error) {
376 err = w.rnibWriter.AddEnb(nodebInfo)
377 return
378 })
379
380 return err
381}
382
Amichaie3623cf2019-09-11 16:59:16 +0300383func (w *rNibDataService) retry(rnibFunc string, f func() error) (err error) {
384 attempts := w.maxAttempts
385
386 for i := 1; ; i++ {
387 err = f()
388 if err == nil {
389 return
390 }
ss412gde190682019-10-24 09:29:26 +0300391 if !isRnibConnectionError(err) {
Amichaie3623cf2019-09-11 16:59:16 +0300392 return err
393 }
394 if i >= attempts {
395 w.logger.Errorf("#RnibDataService.retry - after %d attempts of %s, last error: %s", attempts, rnibFunc, err)
396 return err
397 }
398 time.Sleep(w.retryInterval)
399
400 w.logger.Infof("#RnibDataService.retry - retrying %d %s after error: %s", i, rnibFunc, err)
401 }
402}
403
ss412gde190682019-10-24 09:29:26 +0300404func isRnibConnectionError(err error) bool {
405 internalErr, ok := err.(*common.InternalError)
Amichaie3623cf2019-09-11 16:59:16 +0300406 if !ok {
407 return false
408 }
409 _, ok = internalErr.Err.(*net.OpError)
410
411 return ok
412}