2 // Copyright 2019 AT&T Intellectual Property
3 // Copyright 2019 Nokia
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
9 // http://www.apache.org/licenses/LICENSE-2.0
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.
25 "gerrit.o-ran-sc.org/r/ric-plt/nodeb-rnib.git/common"
26 "gerrit.o-ran-sc.org/r/ric-plt/nodeb-rnib.git/entities"
27 "gerrit.o-ran-sc.org/r/ric-plt/nodeb-rnib.git/reader"
30 type IRanReconnectionManager interface {
31 ReconnectRan(inventoryName string) error
34 type RanReconnectionManager struct {
36 config *configuration.Configuration
37 rnibReaderProvider func() reader.RNibReader
38 rnibWriterProvider func() rNibWriter.RNibWriter
39 ranSetupManager *RanSetupManager
42 func NewRanReconnectionManager(logger *logger.Logger, config *configuration.Configuration, rnibReaderProvider func() reader.RNibReader, rnibWriterProvider func() rNibWriter.RNibWriter, rmrService *services.RmrService) *RanReconnectionManager {
43 return &RanReconnectionManager{
46 rnibReaderProvider: rnibReaderProvider,
47 rnibWriterProvider: rnibWriterProvider,
48 ranSetupManager: NewRanSetupManager(logger,rmrService,rnibWriterProvider),
52 func (m *RanReconnectionManager) ReconnectRan(inventoryName string) error {
53 nodebInfo, rnibErr := m.rnibReaderProvider().GetNodeb(inventoryName)
56 m.logger.Errorf("#RanReconnectionManager.ReconnectRan - RAN name: %s - Failed fetching RAN from rNib. Error: %v", inventoryName, rnibErr)
60 if !m.canReconnectRan(nodebInfo) {
61 m.logger.Warnf("#RanReconnectionManager.ReconnectRan - RAN name: %s - Cannot reconnect RAN", inventoryName)
62 return m.setConnectionStatusOfUnconnectableRan(nodebInfo)
65 err := m.ranSetupManager.ExecuteSetup(nodebInfo)
68 m.logger.Errorf("#RanReconnectionManager.ReconnectRan - RAN name: %s - Failed executing setup. Error: %v", inventoryName, err)
72 m.logger.Infof("#RanReconnectionManager.ReconnectRan - RAN name: %s - Successfully done executing setup. RAN's connection attempts: %d", inventoryName, nodebInfo.ConnectionAttempts)
76 func (m *RanReconnectionManager) canReconnectRan(nodebInfo *entities.NodebInfo) bool {
77 connectionStatus := nodebInfo.GetConnectionStatus()
78 return connectionStatus != entities.ConnectionStatus_SHUT_DOWN && connectionStatus != entities.ConnectionStatus_SHUTTING_DOWN &&
79 int(nodebInfo.GetConnectionAttempts()) < m.config.MaxConnectionAttempts
82 func (m *RanReconnectionManager) updateNodebInfoStatus(nodebInfo *entities.NodebInfo, connectionStatus entities.ConnectionStatus) common.IRNibError {
83 if nodebInfo.ConnectionStatus == connectionStatus {
87 nodebInfo.ConnectionStatus = connectionStatus;
88 err := m.rnibWriterProvider().UpdateNodebInfo(nodebInfo)
91 m.logger.Errorf("#RanReconnectionManager.updateNodebInfoStatus - RAN name: %s - Failed updating RAN's connection status to %s in rNib. Error: %v", nodebInfo.RanName, connectionStatus, err)
95 m.logger.Infof("#RanReconnectionManager.updateNodebInfoStatus - RAN name: %s - Successfully updated RAN's connection status to %s in rNib", nodebInfo.RanName, connectionStatus)
99 func (m *RanReconnectionManager) setConnectionStatusOfUnconnectableRan(nodebInfo *entities.NodebInfo) common.IRNibError {
100 connectionStatus := nodebInfo.GetConnectionStatus()
101 m.logger.Warnf("#RanReconnectionManager.setConnectionStatusOfUnconnectableRan - RAN name: %s, RAN's connection status: %s, RAN's connection attempts: %d", nodebInfo.RanName, nodebInfo.ConnectionStatus, nodebInfo.ConnectionAttempts)
103 if connectionStatus == entities.ConnectionStatus_SHUTTING_DOWN {
104 return m.updateNodebInfoStatus(nodebInfo, entities.ConnectionStatus_SHUT_DOWN)
107 if int(nodebInfo.GetConnectionAttempts()) >= m.config.MaxConnectionAttempts {
108 m.logger.Warnf("#RanReconnectionManager.setConnectionStatusOfUnconnectableRan - RAN name: %s - RAN's connection attempts are greater than %d", nodebInfo.RanName, m.config.MaxConnectionAttempts)
109 return m.updateNodebInfoStatus(nodebInfo, entities.ConnectionStatus_DISCONNECTED)