is005q | 2151d81 | 2019-08-27 17:43:59 +0300 | [diff] [blame] | 1 | // |
| 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 | |
is005q | 19e72a5 | 2019-08-26 17:56:18 +0300 | [diff] [blame] | 18 | package managers |
| 19 | |
| 20 | import ( |
| 21 | "e2mgr/configuration" |
| 22 | "e2mgr/logger" |
| 23 | "e2mgr/rNibWriter" |
is005q | 19e72a5 | 2019-08-26 17:56:18 +0300 | [diff] [blame] | 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" |
| 26 | ) |
| 27 | |
is005q | 2151d81 | 2019-08-27 17:43:59 +0300 | [diff] [blame] | 28 | type IRanReconnectionManager interface { |
| 29 | ReconnectRan(inventoryName string) error |
| 30 | } |
| 31 | |
is005q | 19e72a5 | 2019-08-26 17:56:18 +0300 | [diff] [blame] | 32 | type RanReconnectionManager struct { |
| 33 | logger *logger.Logger |
| 34 | config *configuration.Configuration |
| 35 | rnibReaderProvider func() reader.RNibReader |
| 36 | rnibWriterProvider func() rNibWriter.RNibWriter |
| 37 | ranSetupManager *RanSetupManager |
| 38 | } |
| 39 | |
irina | 33f84e1 | 2019-09-10 12:40:37 +0300 | [diff] [blame] | 40 | func NewRanReconnectionManager(logger *logger.Logger, config *configuration.Configuration, rnibReaderProvider func() reader.RNibReader, |
| 41 | rnibWriterProvider func() rNibWriter.RNibWriter, ranSetupManager *RanSetupManager) *RanReconnectionManager { |
is005q | 19e72a5 | 2019-08-26 17:56:18 +0300 | [diff] [blame] | 42 | return &RanReconnectionManager{ |
| 43 | logger: logger, |
| 44 | config: config, |
| 45 | rnibReaderProvider: rnibReaderProvider, |
| 46 | rnibWriterProvider: rnibWriterProvider, |
irina | 33f84e1 | 2019-09-10 12:40:37 +0300 | [diff] [blame] | 47 | ranSetupManager: ranSetupManager, |
is005q | 19e72a5 | 2019-08-26 17:56:18 +0300 | [diff] [blame] | 48 | } |
| 49 | } |
| 50 | |
| 51 | func (m *RanReconnectionManager) ReconnectRan(inventoryName string) error { |
| 52 | nodebInfo, rnibErr := m.rnibReaderProvider().GetNodeb(inventoryName) |
| 53 | |
| 54 | if rnibErr != nil { |
is005q | 2647319 | 2019-08-28 17:51:37 +0300 | [diff] [blame] | 55 | m.logger.Errorf("#RanReconnectionManager.ReconnectRan - RAN name: %s - Failed fetching RAN from rNib. Error: %v", inventoryName, rnibErr) |
is005q | 19e72a5 | 2019-08-26 17:56:18 +0300 | [diff] [blame] | 56 | return rnibErr |
| 57 | } |
| 58 | |
is005q | 6101f93 | 2019-08-29 18:15:03 +0300 | [diff] [blame] | 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) |
| 60 | |
is005q | 19e72a5 | 2019-08-26 17:56:18 +0300 | [diff] [blame] | 61 | if !m.canReconnectRan(nodebInfo) { |
is005q | 19e72a5 | 2019-08-26 17:56:18 +0300 | [diff] [blame] | 62 | return m.setConnectionStatusOfUnconnectableRan(nodebInfo) |
| 63 | } |
| 64 | |
irina | 33f84e1 | 2019-09-10 12:40:37 +0300 | [diff] [blame] | 65 | err := m.ranSetupManager.ExecuteSetup(nodebInfo, entities.ConnectionStatus_CONNECTING) |
is005q | 19e72a5 | 2019-08-26 17:56:18 +0300 | [diff] [blame] | 66 | |
| 67 | if err != nil { |
is005q | 2647319 | 2019-08-28 17:51:37 +0300 | [diff] [blame] | 68 | m.logger.Errorf("#RanReconnectionManager.ReconnectRan - RAN name: %s - Failed executing setup. Error: %v", inventoryName, err) |
is005q | 19e72a5 | 2019-08-26 17:56:18 +0300 | [diff] [blame] | 69 | return err |
| 70 | } |
| 71 | |
is005q | 19e72a5 | 2019-08-26 17:56:18 +0300 | [diff] [blame] | 72 | return nil |
| 73 | } |
| 74 | |
| 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 |
| 79 | } |
| 80 | |
irina | 006fbce | 2019-09-05 16:11:02 +0300 | [diff] [blame] | 81 | func (m *RanReconnectionManager) updateNodebInfoStatus(nodebInfo *entities.NodebInfo, connectionStatus entities.ConnectionStatus) error { |
is005q | 2647319 | 2019-08-28 17:51:37 +0300 | [diff] [blame] | 82 | if nodebInfo.ConnectionStatus == connectionStatus { |
| 83 | return nil |
| 84 | } |
| 85 | |
is005q | 19e72a5 | 2019-08-26 17:56:18 +0300 | [diff] [blame] | 86 | nodebInfo.ConnectionStatus = connectionStatus; |
| 87 | err := m.rnibWriterProvider().UpdateNodebInfo(nodebInfo) |
| 88 | |
| 89 | if err != nil { |
is005q | 2647319 | 2019-08-28 17:51:37 +0300 | [diff] [blame] | 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) |
is005q | 19e72a5 | 2019-08-26 17:56:18 +0300 | [diff] [blame] | 91 | return err |
| 92 | } |
| 93 | |
is005q | 6101f93 | 2019-08-29 18:15:03 +0300 | [diff] [blame] | 94 | m.logger.Infof("#RanReconnectionManager.updateNodebInfoStatus - RAN name: %s - Successfully updated rNib. RAN's current connection status: %s", nodebInfo.RanName, nodebInfo.ConnectionStatus) |
is005q | 19e72a5 | 2019-08-26 17:56:18 +0300 | [diff] [blame] | 95 | return nil |
| 96 | } |
| 97 | |
irina | 006fbce | 2019-09-05 16:11:02 +0300 | [diff] [blame] | 98 | func (m *RanReconnectionManager) setConnectionStatusOfUnconnectableRan(nodebInfo *entities.NodebInfo) error { |
is005q | 19e72a5 | 2019-08-26 17:56:18 +0300 | [diff] [blame] | 99 | connectionStatus := nodebInfo.GetConnectionStatus() |
is005q | 6101f93 | 2019-08-29 18:15:03 +0300 | [diff] [blame] | 100 | |
| 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) |
| 103 | return nil |
| 104 | } |
is005q | 19e72a5 | 2019-08-26 17:56:18 +0300 | [diff] [blame] | 105 | |
| 106 | if connectionStatus == entities.ConnectionStatus_SHUTTING_DOWN { |
is005q | 6101f93 | 2019-08-29 18:15:03 +0300 | [diff] [blame] | 107 | m.logger.Warnf("#RanReconnectionManager.ReconnectRan - RAN name: %s - Cannot reconnect RAN. Reason: connection status is SHUTTING_DOWN", nodebInfo.RanName) |
is005q | 19e72a5 | 2019-08-26 17:56:18 +0300 | [diff] [blame] | 108 | return m.updateNodebInfoStatus(nodebInfo, entities.ConnectionStatus_SHUT_DOWN) |
| 109 | } |
| 110 | |
| 111 | if int(nodebInfo.GetConnectionAttempts()) >= m.config.MaxConnectionAttempts { |
is005q | 6101f93 | 2019-08-29 18:15:03 +0300 | [diff] [blame] | 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) |
is005q | 19e72a5 | 2019-08-26 17:56:18 +0300 | [diff] [blame] | 113 | return m.updateNodebInfoStatus(nodebInfo, entities.ConnectionStatus_DISCONNECTED) |
| 114 | } |
| 115 | |
| 116 | return nil |
| 117 | } |