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.
17 // This source code is part of the near-RT RIC (RAN Intelligent Controller)
18 // platform project (RICP).
26 "gerrit.o-ran-sc.org/r/ric-plt/nodeb-rnib.git/entities"
29 type IRanDisconnectionManager interface {
30 DisconnectRan(inventoryName string) error
33 type RanDisconnectionManager struct {
35 config *configuration.Configuration
36 rnibDataService services.RNibDataService
37 ranSetupManager *RanSetupManager
38 e2tAssociationManager *E2TAssociationManager
41 func NewRanDisconnectionManager(logger *logger.Logger, config *configuration.Configuration, rnibDataService services.RNibDataService, e2tAssociationManager *E2TAssociationManager) *RanDisconnectionManager {
42 return &RanDisconnectionManager{
45 rnibDataService: rnibDataService,
46 e2tAssociationManager: e2tAssociationManager,
50 func (m *RanDisconnectionManager) DisconnectRan(inventoryName string) error {
51 nodebInfo, err := m.rnibDataService.GetNodeb(inventoryName)
54 m.logger.Errorf("#RanDisconnectionManager.DisconnectRan - RAN name: %s - Failed fetching RAN from rNib. Error: %v", inventoryName, err)
58 connectionStatus := nodebInfo.GetConnectionStatus()
59 m.logger.Infof("#RanDisconnectionManager.DisconnectRan - RAN name: %s - RAN's connection status: %s", nodebInfo.RanName, connectionStatus)
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)
67 if connectionStatus == entities.ConnectionStatus_SHUTTING_DOWN {
68 return m.updateNodebInfo(nodebInfo, entities.ConnectionStatus_SHUT_DOWN)
71 err = m.updateNodebInfo(nodebInfo, entities.ConnectionStatus_DISCONNECTED)
77 e2tAddress := nodebInfo.AssociatedE2TInstanceAddress
78 return m.e2tAssociationManager.DissociateRan(e2tAddress, nodebInfo.RanName)
81 func (m *RanDisconnectionManager) updateNodebInfo(nodebInfo *entities.NodebInfo, connectionStatus entities.ConnectionStatus) error {
83 nodebInfo.ConnectionStatus = connectionStatus;
84 err := m.rnibDataService.UpdateNodebInfo(nodebInfo)
87 m.logger.Errorf("#RanDisconnectionManager.updateNodebInfo - RAN name: %s - Failed updating RAN's connection status to %s in rNib. Error: %v", nodebInfo.RanName, connectionStatus, err)
91 m.logger.Infof("#RanDisconnectionManager.updateNodebInfo - RAN name: %s - Successfully updated rNib. RAN's current connection status: %s", nodebInfo.RanName, nodebInfo.ConnectionStatus)