ss412g | 011bb91 | 2020-03-17 18:34:42 +0200 | [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 | // This source code is part of the near-RT RIC (RAN Intelligent Controller) |
| 18 | // platform project (RICP). |
| 19 | |
| 20 | package managers |
| 21 | |
| 22 | import ( |
| 23 | "e2mgr/configuration" |
| 24 | "e2mgr/logger" |
| 25 | "e2mgr/services" |
| 26 | "gerrit.o-ran-sc.org/r/ric-plt/nodeb-rnib.git/entities" |
| 27 | ) |
| 28 | |
| 29 | type IRanDisconnectionManager interface { |
| 30 | DisconnectRan(inventoryName string) error |
| 31 | } |
| 32 | |
| 33 | type RanDisconnectionManager struct { |
| 34 | logger *logger.Logger |
| 35 | config *configuration.Configuration |
| 36 | rnibDataService services.RNibDataService |
| 37 | ranSetupManager *RanSetupManager |
| 38 | e2tAssociationManager *E2TAssociationManager |
| 39 | } |
| 40 | |
| 41 | func NewRanDisconnectionManager(logger *logger.Logger, config *configuration.Configuration, rnibDataService services.RNibDataService, e2tAssociationManager *E2TAssociationManager) *RanDisconnectionManager { |
| 42 | return &RanDisconnectionManager{ |
| 43 | logger: logger, |
| 44 | config: config, |
| 45 | rnibDataService: rnibDataService, |
| 46 | e2tAssociationManager: e2tAssociationManager, |
| 47 | } |
| 48 | } |
| 49 | |
| 50 | func (m *RanDisconnectionManager) DisconnectRan(inventoryName string) error { |
| 51 | nodebInfo, err := m.rnibDataService.GetNodeb(inventoryName) |
| 52 | |
| 53 | if err != nil { |
| 54 | m.logger.Errorf("#RanDisconnectionManager.DisconnectRan - RAN name: %s - Failed fetching RAN from rNib. Error: %v", inventoryName, err) |
| 55 | return err |
| 56 | } |
| 57 | |
| 58 | connectionStatus := nodebInfo.GetConnectionStatus() |
| 59 | m.logger.Infof("#RanDisconnectionManager.DisconnectRan - RAN name: %s - RAN's connection status: %s", nodebInfo.RanName, connectionStatus) |
| 60 | |
| 61 | |
| 62 | if connectionStatus == entities.ConnectionStatus_SHUT_DOWN { |
| 63 | m.logger.Warnf("#RanDisconnectionManager.DisconnectRan - RAN name: %s - quit. RAN's connection status is SHUT_DOWN", nodebInfo.RanName) |
| 64 | return nil |
| 65 | } |
| 66 | |
| 67 | nodebInfo.ConnectionAttempts = 0; |
| 68 | |
| 69 | if connectionStatus == entities.ConnectionStatus_SHUTTING_DOWN { |
| 70 | return m.updateNodebInfo(nodebInfo, entities.ConnectionStatus_SHUT_DOWN) |
| 71 | } |
| 72 | |
| 73 | err = m.updateNodebInfo(nodebInfo, entities.ConnectionStatus_DISCONNECTED) |
| 74 | |
| 75 | if err != nil { |
| 76 | return err |
| 77 | } |
| 78 | |
| 79 | e2tAddress := nodebInfo.AssociatedE2TInstanceAddress |
| 80 | return m.e2tAssociationManager.DissociateRan(e2tAddress, nodebInfo.RanName) |
| 81 | } |
| 82 | |
| 83 | func (m *RanDisconnectionManager) updateNodebInfo(nodebInfo *entities.NodebInfo, connectionStatus entities.ConnectionStatus) error { |
| 84 | |
| 85 | nodebInfo.ConnectionStatus = connectionStatus; |
| 86 | err := m.rnibDataService.UpdateNodebInfo(nodebInfo) |
| 87 | |
| 88 | if err != nil { |
| 89 | m.logger.Errorf("#RanDisconnectionManager.updateNodebInfo - RAN name: %s - Failed updating RAN's connection status to %s in rNib. Error: %v", nodebInfo.RanName, connectionStatus, err) |
| 90 | return err |
| 91 | } |
| 92 | |
| 93 | m.logger.Infof("#RanDisconnectionManager.updateNodebInfo - RAN name: %s - Successfully updated rNib. RAN's current connection status: %s", nodebInfo.RanName, nodebInfo.ConnectionStatus) |
| 94 | return nil |
| 95 | } |