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).
27 "gerrit.o-ran-sc.org/r/ric-plt/nodeb-rnib.git/entities"
31 CONNECTED_RAW_EVENT = "CONNECTED"
32 DISCONNECTED_RAW_EVENT = "DISCONNECTED"
33 UNDER_RESET_RAW_EVENT = "UNDER_RESET"
34 NONE_RAW_EVENT = "NONE"
37 type IRanConnectStatusChangeManager interface {
38 ChangeStatus(nodebInfo *entities.NodebInfo, nextStatus entities.ConnectionStatus) (bool, error)
41 type RanConnectStatusChangeManager struct {
43 rnibDataService services.RNibDataService
44 ranListManager RanListManager
45 ranAlarmService services.RanAlarmService
48 func NewRanConnectStatusChangeManager(logger *logger.Logger, rnibDataService services.RNibDataService, ranListManager RanListManager, ranAlarmService services.RanAlarmService) *RanConnectStatusChangeManager {
49 return &RanConnectStatusChangeManager{
51 rnibDataService: rnibDataService,
52 ranListManager: ranListManager,
53 ranAlarmService: ranAlarmService,
57 func (m *RanConnectStatusChangeManager) ChangeStatus(nodebInfo *entities.NodebInfo, nextStatus entities.ConnectionStatus) (bool, error) {
58 m.logger.Infof("#RanConnectStatusChangeManager.ChangeStatus - RAN name: %s, currentStatus: %s, nextStatus: %s", nodebInfo.RanName, nodebInfo.GetConnectionStatus(), nextStatus)
60 var ranStatusChangePublished bool
62 // set the proper event
63 event := m.setEvent(nodebInfo, nextStatus)
64 isConnectivityEvent := event != NONE_RAW_EVENT
66 // only after determining event we set next status
67 nodebInfo.ConnectionStatus = nextStatus
68 // filling the timeStamp for the last Connection Status update
69 nodebInfo.StatusUpdateTimeStamp = uint64(time.Now().UnixNano())
70 if !isConnectivityEvent {
71 err := m.updateNodebInfo(nodebInfo)
73 return ranStatusChangePublished, err
76 err := m.updateNodebInfoOnConnectionStatusInversion(nodebInfo, event)
78 return ranStatusChangePublished, err
80 ranStatusChangePublished = true
83 // in any case, update RanListManager
84 connectionStatus := nodebInfo.GetConnectionStatus()
85 m.logger.Infof("#RanConnectStatusChangeManager.ChangeStatus - RAN name: %s, updating RanListManager... status: %s", nodebInfo.RanName, connectionStatus)
86 err := m.ranListManager.UpdateNbIdentityConnectionStatus(nodebInfo.GetNodeType(), nodebInfo.RanName, connectionStatus)
88 m.logger.Errorf("#RanConnectStatusChangeManager.ChangeStatus - RAN name: %s - Failed updating RAN's connection status by RanListManager. Error: %v", nodebInfo.RanName, err)
92 if isConnectivityEvent {
93 m.logger.Infof("#RanConnectStatusChangeManager.ChangeStatus - RAN name: %s, setting alarm at RanAlarmService... event: %s", nodebInfo.RanName, event)
94 err := m.ranAlarmService.SetConnectivityChangeAlarm(nodebInfo)
96 m.logger.Errorf("#RanConnectStatusChangeManager.ChangeStatus - RAN name: %s - Failed setting an alarm by RanAlarmService. Error: %v", nodebInfo.RanName, err)
101 return ranStatusChangePublished, nil
104 func (m *RanConnectStatusChangeManager) updateNodebInfoOnConnectionStatusInversion(nodebInfo *entities.NodebInfo, event string) error {
106 err := m.rnibDataService.UpdateNodebInfoOnConnectionStatusInversion(nodebInfo, event)
109 m.logger.Errorf("#RanConnectStatusChangeManager.updateNodebInfoOnConnectionStatusInversion - RAN name: %s - Failed updating RAN's connection status in rNib. Error: %v", nodebInfo.RanName, err)
113 m.logger.Infof("#RanConnectStatusChangeManager.updateNodebInfoOnConnectionStatusInversion - RAN name: %s - Successfully updated rNib.", nodebInfo.RanName)
117 func (m *RanConnectStatusChangeManager) updateNodebInfo(nodebInfo *entities.NodebInfo) error {
119 err := m.rnibDataService.UpdateNodebInfo(nodebInfo)
122 m.logger.Errorf("#RanConnectStatusChangeManager.updateNodebInfo - RAN name: %s - Failed updating RAN's connection status in rNib. Error: %v", nodebInfo.RanName, err)
126 m.logger.Infof("#RanConnectStatusChangeManager.updateNodebInfo - RAN name: %s - Successfully updated rNib.", nodebInfo.RanName)
130 func (m *RanConnectStatusChangeManager) setEvent(nodebInfo *entities.NodebInfo, nextState entities.ConnectionStatus) string {
131 currentConnectionStatus := nodebInfo.GetConnectionStatus()
134 if currentConnectionStatus != entities.ConnectionStatus_CONNECTED && nextState == entities.ConnectionStatus_CONNECTED {
135 event = nodebInfo.RanName + "_" + CONNECTED_RAW_EVENT
136 } else if currentConnectionStatus == entities.ConnectionStatus_CONNECTED && nextState != entities.ConnectionStatus_CONNECTED {
137 event = nodebInfo.RanName + "_" + DISCONNECTED_RAW_EVENT
138 } else if nextState == entities.ConnectionStatus_UNDER_RESET {
139 event = nodebInfo.RanName + "_" + UNDER_RESET_RAW_EVENT
141 event = NONE_RAW_EVENT
144 m.logger.Infof("#RanConnectStatusChangeManager.setEvent - Connectivity Event for RAN %s is: %s", nodebInfo.RanName, event)