blob: 70acee0a7ad6737f4916b5515fac7bbefdcd2dae [file] [log] [blame]
is005q2151d812019-08-27 17:43:59 +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.
16//
17
is005q19e72a52019-08-26 17:56:18 +030018package managers
19
20import (
21 "e2mgr/configuration"
22 "e2mgr/logger"
23 "e2mgr/rNibWriter"
is005q2151d812019-08-27 17:43:59 +030024 "e2mgr/services"
is005q19e72a52019-08-26 17:56:18 +030025 "gerrit.o-ran-sc.org/r/ric-plt/nodeb-rnib.git/entities"
26 "gerrit.o-ran-sc.org/r/ric-plt/nodeb-rnib.git/reader"
27)
28
is005q2151d812019-08-27 17:43:59 +030029type IRanReconnectionManager interface {
30 ReconnectRan(inventoryName string) error
31}
32
is005q19e72a52019-08-26 17:56:18 +030033type RanReconnectionManager struct {
34 logger *logger.Logger
35 config *configuration.Configuration
36 rnibReaderProvider func() reader.RNibReader
37 rnibWriterProvider func() rNibWriter.RNibWriter
38 ranSetupManager *RanSetupManager
39}
40
is005q2151d812019-08-27 17:43:59 +030041func NewRanReconnectionManager(logger *logger.Logger, config *configuration.Configuration, rnibReaderProvider func() reader.RNibReader, rnibWriterProvider func() rNibWriter.RNibWriter, rmrService *services.RmrService) *RanReconnectionManager {
is005q19e72a52019-08-26 17:56:18 +030042 return &RanReconnectionManager{
43 logger: logger,
44 config: config,
45 rnibReaderProvider: rnibReaderProvider,
46 rnibWriterProvider: rnibWriterProvider,
rh362jce7bdb12019-08-28 15:13:48 +030047 ranSetupManager: NewRanSetupManager(logger,rmrService,rnibWriterProvider),
is005q19e72a52019-08-26 17:56:18 +030048 }
49}
50
51func (m *RanReconnectionManager) ReconnectRan(inventoryName string) error {
52 nodebInfo, rnibErr := m.rnibReaderProvider().GetNodeb(inventoryName)
53
54 if rnibErr != nil {
is005q26473192019-08-28 17:51:37 +030055 m.logger.Errorf("#RanReconnectionManager.ReconnectRan - RAN name: %s - Failed fetching RAN from rNib. Error: %v", inventoryName, rnibErr)
is005q19e72a52019-08-26 17:56:18 +030056 return rnibErr
57 }
58
is005q6101f932019-08-29 18:15:03 +030059 m.logger.Infof("#RanReconnectionManager.ReconnectRan - RAN name: %s - RAN's connection status: %s, RAN's connection attempts: %d", nodebInfo.RanName, nodebInfo.ConnectionStatus, nodebInfo.ConnectionAttempts)
60
is005q19e72a52019-08-26 17:56:18 +030061 if !m.canReconnectRan(nodebInfo) {
is005q19e72a52019-08-26 17:56:18 +030062 return m.setConnectionStatusOfUnconnectableRan(nodebInfo)
63 }
64
is005q6101f932019-08-29 18:15:03 +030065
is005q19e72a52019-08-26 17:56:18 +030066 err := m.ranSetupManager.ExecuteSetup(nodebInfo)
67
68 if err != nil {
is005q26473192019-08-28 17:51:37 +030069 m.logger.Errorf("#RanReconnectionManager.ReconnectRan - RAN name: %s - Failed executing setup. Error: %v", inventoryName, err)
is005q19e72a52019-08-26 17:56:18 +030070 return err
71 }
72
is005q19e72a52019-08-26 17:56:18 +030073 return nil
74}
75
76func (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
80}
81
irina006fbce2019-09-05 16:11:02 +030082func (m *RanReconnectionManager) updateNodebInfoStatus(nodebInfo *entities.NodebInfo, connectionStatus entities.ConnectionStatus) error {
is005q26473192019-08-28 17:51:37 +030083 if nodebInfo.ConnectionStatus == connectionStatus {
84 return nil
85 }
86
is005q19e72a52019-08-26 17:56:18 +030087 nodebInfo.ConnectionStatus = connectionStatus;
88 err := m.rnibWriterProvider().UpdateNodebInfo(nodebInfo)
89
90 if err != nil {
is005q26473192019-08-28 17:51:37 +030091 m.logger.Errorf("#RanReconnectionManager.updateNodebInfoStatus - RAN name: %s - Failed updating RAN's connection status to %s in rNib. Error: %v", nodebInfo.RanName, connectionStatus, err)
is005q19e72a52019-08-26 17:56:18 +030092 return err
93 }
94
is005q6101f932019-08-29 18:15:03 +030095 m.logger.Infof("#RanReconnectionManager.updateNodebInfoStatus - RAN name: %s - Successfully updated rNib. RAN's current connection status: %s", nodebInfo.RanName, nodebInfo.ConnectionStatus)
is005q19e72a52019-08-26 17:56:18 +030096 return nil
97}
98
irina006fbce2019-09-05 16:11:02 +030099func (m *RanReconnectionManager) setConnectionStatusOfUnconnectableRan(nodebInfo *entities.NodebInfo) error {
is005q19e72a52019-08-26 17:56:18 +0300100 connectionStatus := nodebInfo.GetConnectionStatus()
is005q6101f932019-08-29 18:15:03 +0300101
102 if connectionStatus == entities.ConnectionStatus_SHUT_DOWN {
103 m.logger.Warnf("#RanReconnectionManager.ReconnectRan - RAN name: %s - Cannot reconnect RAN. Reason: connection status is SHUT_DOWN", nodebInfo.RanName)
104 return nil
105 }
is005q19e72a52019-08-26 17:56:18 +0300106
107 if connectionStatus == entities.ConnectionStatus_SHUTTING_DOWN {
is005q6101f932019-08-29 18:15:03 +0300108 m.logger.Warnf("#RanReconnectionManager.ReconnectRan - RAN name: %s - Cannot reconnect RAN. Reason: connection status is SHUTTING_DOWN", nodebInfo.RanName)
is005q19e72a52019-08-26 17:56:18 +0300109 return m.updateNodebInfoStatus(nodebInfo, entities.ConnectionStatus_SHUT_DOWN)
110 }
111
112 if int(nodebInfo.GetConnectionAttempts()) >= m.config.MaxConnectionAttempts {
is005q6101f932019-08-29 18:15:03 +0300113 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)
is005q19e72a52019-08-26 17:56:18 +0300114 return m.updateNodebInfoStatus(nodebInfo, entities.ConnectionStatus_DISCONNECTED)
115 }
116
117 return nil
118}