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.
24 "gerrit.o-ran-sc.org/r/ric-plt/nodeb-rnib.git/entities"
25 "gerrit.o-ran-sc.org/r/ric-plt/nodeb-rnib.git/reader"
28 type IRanReconnectionManager interface {
29 ReconnectRan(inventoryName string) error
32 type RanReconnectionManager struct {
34 config *configuration.Configuration
35 rnibReaderProvider func() reader.RNibReader
36 rnibWriterProvider func() rNibWriter.RNibWriter
37 ranSetupManager *RanSetupManager
40 func NewRanReconnectionManager(logger *logger.Logger, config *configuration.Configuration, rnibReaderProvider func() reader.RNibReader,
41 rnibWriterProvider func() rNibWriter.RNibWriter, ranSetupManager *RanSetupManager) *RanReconnectionManager {
42 return &RanReconnectionManager{
45 rnibReaderProvider: rnibReaderProvider,
46 rnibWriterProvider: rnibWriterProvider,
47 ranSetupManager: ranSetupManager,
51 func (m *RanReconnectionManager) ReconnectRan(inventoryName string) error {
52 nodebInfo, rnibErr := m.rnibReaderProvider().GetNodeb(inventoryName)
55 m.logger.Errorf("#RanReconnectionManager.ReconnectRan - RAN name: %s - Failed fetching RAN from rNib. Error: %v", inventoryName, rnibErr)
59 m.logger.Infof("#RanReconnectionManager.ReconnectRan - RAN name: %s - RAN's connection status: %s, RAN's connection attempts: %d", nodebInfo.RanName, nodebInfo.ConnectionStatus, nodebInfo.ConnectionAttempts)
61 if !m.canReconnectRan(nodebInfo) {
62 return m.setConnectionStatusOfUnconnectableRan(nodebInfo)
65 err := m.ranSetupManager.ExecuteSetup(nodebInfo, entities.ConnectionStatus_CONNECTING)
68 m.logger.Errorf("#RanReconnectionManager.ReconnectRan - RAN name: %s - Failed executing setup. Error: %v", inventoryName, err)
75 func (m *RanReconnectionManager) canReconnectRan(nodebInfo *entities.NodebInfo) bool {
76 connectionStatus := nodebInfo.GetConnectionStatus()
77 return connectionStatus != entities.ConnectionStatus_SHUT_DOWN && connectionStatus != entities.ConnectionStatus_SHUTTING_DOWN &&
78 int(nodebInfo.GetConnectionAttempts()) < m.config.MaxConnectionAttempts
81 func (m *RanReconnectionManager) updateNodebInfoStatus(nodebInfo *entities.NodebInfo, connectionStatus entities.ConnectionStatus) error {
82 if nodebInfo.ConnectionStatus == connectionStatus {
86 nodebInfo.ConnectionStatus = connectionStatus;
87 err := m.rnibWriterProvider().UpdateNodebInfo(nodebInfo)
90 m.logger.Errorf("#RanReconnectionManager.updateNodebInfoStatus - RAN name: %s - Failed updating RAN's connection status to %s in rNib. Error: %v", nodebInfo.RanName, connectionStatus, err)
94 m.logger.Infof("#RanReconnectionManager.updateNodebInfoStatus - RAN name: %s - Successfully updated rNib. RAN's current connection status: %s", nodebInfo.RanName, nodebInfo.ConnectionStatus)
98 func (m *RanReconnectionManager) setConnectionStatusOfUnconnectableRan(nodebInfo *entities.NodebInfo) error {
99 connectionStatus := nodebInfo.GetConnectionStatus()
101 if connectionStatus == entities.ConnectionStatus_SHUT_DOWN {
102 m.logger.Warnf("#RanReconnectionManager.ReconnectRan - RAN name: %s - Cannot reconnect RAN. Reason: connection status is SHUT_DOWN", nodebInfo.RanName)
106 if connectionStatus == entities.ConnectionStatus_SHUTTING_DOWN {
107 m.logger.Warnf("#RanReconnectionManager.ReconnectRan - RAN name: %s - Cannot reconnect RAN. Reason: connection status is SHUTTING_DOWN", nodebInfo.RanName)
108 return m.updateNodebInfoStatus(nodebInfo, entities.ConnectionStatus_SHUT_DOWN)
111 if int(nodebInfo.GetConnectionAttempts()) >= m.config.MaxConnectionAttempts {
112 m.logger.Warnf("#RanReconnectionManager.ReconnectRan - RAN name: %s - Cannot reconnect RAN. Reason: RAN's connection attempts exceeded the limit (%d)", nodebInfo.RanName, m.config.MaxConnectionAttempts)
113 return m.updateNodebInfoStatus(nodebInfo, entities.ConnectionStatus_DISCONNECTED)