return rnibErr
}
+ m.logger.Infof("#RanReconnectionManager.ReconnectRan - RAN name: %s - RAN's connection status: %s, RAN's connection attempts: %d", nodebInfo.RanName, nodebInfo.ConnectionStatus, nodebInfo.ConnectionAttempts)
+
if !m.canReconnectRan(nodebInfo) {
- m.logger.Warnf("#RanReconnectionManager.ReconnectRan - RAN name: %s - Cannot reconnect RAN", inventoryName)
return m.setConnectionStatusOfUnconnectableRan(nodebInfo)
}
+
err := m.ranSetupManager.ExecuteSetup(nodebInfo)
if err != nil {
return err
}
- m.logger.Infof("#RanReconnectionManager.ReconnectRan - RAN name: %s - Successfully done executing setup. RAN's connection attempts: %d", inventoryName, nodebInfo.ConnectionAttempts)
return nil
}
return err
}
- m.logger.Infof("#RanReconnectionManager.updateNodebInfoStatus - RAN name: %s - Successfully updated RAN's connection status to %s in rNib", nodebInfo.RanName, connectionStatus)
+ m.logger.Infof("#RanReconnectionManager.updateNodebInfoStatus - RAN name: %s - Successfully updated rNib. RAN's current connection status: %s", nodebInfo.RanName, nodebInfo.ConnectionStatus)
return nil
}
func (m *RanReconnectionManager) setConnectionStatusOfUnconnectableRan(nodebInfo *entities.NodebInfo) common.IRNibError {
connectionStatus := nodebInfo.GetConnectionStatus()
- m.logger.Warnf("#RanReconnectionManager.setConnectionStatusOfUnconnectableRan - RAN name: %s, RAN's connection status: %s, RAN's connection attempts: %d", nodebInfo.RanName, nodebInfo.ConnectionStatus, nodebInfo.ConnectionAttempts)
+
+ if connectionStatus == entities.ConnectionStatus_SHUT_DOWN {
+ m.logger.Warnf("#RanReconnectionManager.ReconnectRan - RAN name: %s - Cannot reconnect RAN. Reason: connection status is SHUT_DOWN", nodebInfo.RanName)
+ return nil
+ }
if connectionStatus == entities.ConnectionStatus_SHUTTING_DOWN {
+ m.logger.Warnf("#RanReconnectionManager.ReconnectRan - RAN name: %s - Cannot reconnect RAN. Reason: connection status is SHUTTING_DOWN", nodebInfo.RanName)
return m.updateNodebInfoStatus(nodebInfo, entities.ConnectionStatus_SHUT_DOWN)
}
if int(nodebInfo.GetConnectionAttempts()) >= m.config.MaxConnectionAttempts {
- m.logger.Warnf("#RanReconnectionManager.setConnectionStatusOfUnconnectableRan - RAN name: %s - RAN's connection attempts are greater than %d", nodebInfo.RanName, m.config.MaxConnectionAttempts)
+ 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)
return m.updateNodebInfoStatus(nodebInfo, entities.ConnectionStatus_DISCONNECTED)
}
"gerrit.o-ran-sc.org/r/ric-plt/nodeb-rnib.git/reader"
"github.com/pkg/errors"
"github.com/stretchr/testify/assert"
+ "github.com/stretchr/testify/mock"
"testing"
)
-func initRanLostConnectionTest(t *testing.T) (*logger.Logger, *mocks.RnibReaderMock, *mocks.RnibWriterMock, *RanReconnectionManager) {
+func initRanLostConnectionTest(t *testing.T) (*logger.Logger,*mocks.RmrMessengerMock, *mocks.RnibReaderMock, *mocks.RnibWriterMock, *RanReconnectionManager) {
logger, err := logger.InitLogger(logger.DebugLevel)
if err != nil {
t.Errorf("#... - failed to initialize logger, error: %s", err)
}
- rmrService := getRmrService(&mocks.RmrMessengerMock{}, logger)
+ rmrMessengerMock := &mocks.RmrMessengerMock{}
+ rmrService := getRmrService(rmrMessengerMock, logger)
readerMock := &mocks.RnibReaderMock{}
rnibReaderProvider := func() reader.RNibReader {
}
ranReconnectionManager := NewRanReconnectionManager(logger, configuration.ParseConfiguration(), rnibReaderProvider, rnibWriterProvider, rmrService)
- return logger, readerMock, writerMock, ranReconnectionManager
+ return logger,rmrMessengerMock, readerMock, writerMock, ranReconnectionManager
}
func TestRanReconnectionGetNodebFailure(t *testing.T) {
- _, readerMock, writerMock, ranReconnectionManager := initRanLostConnectionTest(t)
+ _,_, readerMock, writerMock, ranReconnectionManager := initRanLostConnectionTest(t)
ranName := "test"
var nodebInfo *entities.NodebInfo
readerMock.On("GetNodeb", ranName).Return(nodebInfo, common.NewInternalError(errors.New("Error")))
}
func TestShutdownRanReconnection(t *testing.T) {
- _, readerMock, writerMock, ranReconnectionManager := initRanLostConnectionTest(t)
+ _,_, readerMock, writerMock, ranReconnectionManager := initRanLostConnectionTest(t)
ranName := "test"
origNodebInfo := &entities.NodebInfo{RanName: ranName, GlobalNbId: &entities.GlobalNbId{PlmnId: "xxx", NbId: "yyy"}, ConnectionStatus: entities.ConnectionStatus_SHUT_DOWN}
var rnibErr common.IRNibError
}
func TestShuttingdownRanReconnection(t *testing.T) {
- _, readerMock, writerMock, ranReconnectionManager := initRanLostConnectionTest(t)
+ _,_, readerMock, writerMock, ranReconnectionManager := initRanLostConnectionTest(t)
ranName := "test"
origNodebInfo := &entities.NodebInfo{RanName: ranName, GlobalNbId: &entities.GlobalNbId{PlmnId: "xxx", NbId: "yyy"}, ConnectionStatus: entities.ConnectionStatus_SHUTTING_DOWN}
var rnibErr common.IRNibError
}
func TestConnectingRanWithMaxAttemptsReconnection(t *testing.T) {
- _, readerMock, writerMock, ranReconnectionManager := initRanLostConnectionTest(t)
+ _,_, readerMock, writerMock, ranReconnectionManager := initRanLostConnectionTest(t)
ranName := "test"
origNodebInfo := &entities.NodebInfo{RanName: ranName, GlobalNbId: &entities.GlobalNbId{PlmnId: "xxx", NbId: "yyy"}, ConnectionStatus: entities.ConnectionStatus_CONNECTING, ConnectionAttempts: 20}
var rnibErr common.IRNibError
}
func TestUnconnectableRanUpdateNodebInfoFailure(t *testing.T) {
- _, readerMock, writerMock, ranReconnectionManager := initRanLostConnectionTest(t)
+ _,_, readerMock, writerMock, ranReconnectionManager := initRanLostConnectionTest(t)
ranName := "test"
origNodebInfo := &entities.NodebInfo{RanName: ranName, GlobalNbId: &entities.GlobalNbId{PlmnId: "xxx", NbId: "yyy"}, ConnectionStatus: entities.ConnectionStatus_SHUTTING_DOWN}
var rnibErr common.IRNibError
writerMock.AssertNumberOfCalls(t, "UpdateNodebInfo", 1)
}
+func TestConnectedRanExecuteSetupSuccess(t *testing.T) {
+ _,rmrMessengerMock, readerMock, writerMock, ranReconnectionManager := initRanLostConnectionTest(t)
+ ranName := "test"
+ origNodebInfo := &entities.NodebInfo{RanName: ranName, GlobalNbId: &entities.GlobalNbId{PlmnId: "xxx", NbId: "yyy"}, ConnectionStatus: entities.ConnectionStatus_CONNECTED, E2ApplicationProtocol:entities.E2ApplicationProtocol_ENDC_X2_SETUP_REQUEST}
+ var rnibErr common.IRNibError
+ readerMock.On("GetNodeb", ranName).Return(origNodebInfo, rnibErr)
+ updatedNodebInfo := *origNodebInfo
+ updatedNodebInfo.ConnectionStatus = entities.ConnectionStatus_CONNECTING
+ updatedNodebInfo.ConnectionAttempts++
+ writerMock.On("UpdateNodebInfo", &updatedNodebInfo).Return(nil)
+ rmrMessengerMock.On("SendMsg",mock.Anything, mock.AnythingOfType("int")).Return(&rmrCgo.MBuf{},nil)
+ err := ranReconnectionManager.ReconnectRan(ranName)
+ assert.Nil(t, err)
+ readerMock.AssertCalled(t, "GetNodeb", ranName)
+ writerMock.AssertNumberOfCalls(t, "UpdateNodebInfo", 1)
+ rmrMessengerMock.AssertNumberOfCalls(t, "SendMsg", 1)
+}
+
+func TestConnectedRanExecuteSetupFailure(t *testing.T) {
+ _,_, readerMock, writerMock, ranReconnectionManager := initRanLostConnectionTest(t)
+ ranName := "test"
+ origNodebInfo := &entities.NodebInfo{RanName: ranName, GlobalNbId: &entities.GlobalNbId{PlmnId: "xxx", NbId: "yyy"}, ConnectionStatus: entities.ConnectionStatus_CONNECTED}
+ var rnibErr common.IRNibError
+ readerMock.On("GetNodeb", ranName).Return(origNodebInfo, rnibErr)
+ updatedNodebInfo := *origNodebInfo
+ updatedNodebInfo.ConnectionStatus = entities.ConnectionStatus_CONNECTING
+ updatedNodebInfo.ConnectionAttempts++
+ writerMock.On("UpdateNodebInfo", &updatedNodebInfo).Return(common.NewInternalError(errors.New("Error")))
+ err := ranReconnectionManager.ReconnectRan(ranName)
+ assert.NotNil(t, err)
+ readerMock.AssertCalled(t, "GetNodeb", ranName)
+ writerMock.AssertNumberOfCalls(t, "UpdateNodebInfo", 1)
+}
+
// TODO: should extract to test_utils
func getRmrService(rmrMessengerMock *mocks.RmrMessengerMock, log *logger.Logger) *services.RmrService {
rmrMessenger := rmrCgo.RmrMessenger(rmrMessengerMock)
nodebInfo.ConnectionAttempts++
err := m.rnibWriterProvider().UpdateNodebInfo(nodebInfo)
if err != nil {
- m.logger.Errorf("#RanSetupManager.updateConnectionStatusConnecting - failed to update RAN's connection status to CONNECTING: %s", err)
+ m.logger.Errorf("#RanSetupManager.updateConnectionStatusConnecting - Ran name: %s - Failed updating RAN's connection status to CONNECTING : %s", nodebInfo.RanName, err)
} else {
- m.logger.Infof("#RanSetupManager.updateConnectionStatusConnecting - successfully updated RAN's connection status to CONNECTING")
+ m.logger.Errorf("#RanSetupManager.updateConnectionStatusConnecting - Ran name: %s - Successfully updated rNib. RAN's current connection status: CONNECTING, RAN's current connection attempts: %d", nodebInfo.RanName, nodebInfo.ConnectionAttempts)
}
return err
}
nodebInfo.ConnectionAttempts--
err := m.rnibWriterProvider().UpdateNodebInfo(nodebInfo)
if err != nil {
- m.logger.Errorf("#RanSetupManager.updateConnectionStatusDisconnected - failed to update RAN's connection status to DISCONNECTED : %s", err)
+ m.logger.Errorf("#RanSetupManager.updateConnectionStatusDisconnected - Ran name: %s - Failed updating RAN's connection status to DISCONNECTED : %s", nodebInfo.RanName, err)
} else {
- m.logger.Errorf("#RanSetupManager.updateConnectionStatusDisconnected - successfully updated RAN's connection status to DISCONNECTED")
+ m.logger.Errorf("#RanSetupManager.updateConnectionStatusDisconnected - Ran name: %s - Successfully updated rNib. RAN's current connection status: DISCONNECTED, RAN's current connection attempts: %d", nodebInfo.RanName, nodebInfo.ConnectionAttempts)
}
return err
}
return rmrMsgType, request, nil
}
- m.logger.Errorf("#RanSetupManager.ExecuteSetup - unsupported nodebInfo.E2ApplicationProtocol %d ", nodebInfo.E2ApplicationProtocol)
+ m.logger.Errorf("#RanSetupManager.ExecuteSetup - Unsupported nodebInfo.E2ApplicationProtocol %d ", nodebInfo.E2ApplicationProtocol)
return 0, nil, e2managererrors.NewInternalError()
}
// Update retries and connection status (connecting)
if err := m.updateConnectionStatusConnecting(nodebInfo); err != nil {
- delete(m.rmrService.E2sessions,nodebInfo.RanName)
+ delete(m.rmrService.E2sessions, nodebInfo.RanName)
return e2managererrors.NewRnibDbError()
}
// Build the endc/x2 setup request
rmrMsgType, request, err := m.prepareSetupRequest(nodebInfo)
if err != nil {
- delete(m.rmrService.E2sessions,nodebInfo.RanName)
+ delete(m.rmrService.E2sessions, nodebInfo.RanName)
return err
}
// Send the endc/x2 setup request
response := &models.NotificationResponse{MgsType: rmrMsgType, RanName: nodebInfo.RanName, Payload: request.GetMessageAsBytes(m.logger)}
if err := m.rmrService.SendRmrMessage(response); err != nil {
- m.logger.Errorf("#RanSetupManager.ExecuteSetup - failed to send setup request to RMR: %s", err)
+ m.logger.Errorf("#RanSetupManager.ExecuteSetup - failed sending setup request to RMR: %s", err)
- delete(m.rmrService.E2sessions,nodebInfo.RanName)
+ delete(m.rmrService.E2sessions, nodebInfo.RanName)
// Decrement retries and connection status (disconnected)
if err := m.updateConnectionStatusDisconnected(nodebInfo); err != nil {