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).
24 "e2mgr/e2managererrors"
30 "e2mgr/services/rmrsender"
31 "gerrit.o-ran-sc.org/r/ric-plt/nodeb-rnib.git/entities"
34 type RanSetupManager struct {
36 rnibDataService services.RNibDataService
37 rmrSender *rmrsender.RmrSender
40 func NewRanSetupManager(logger *logger.Logger, rmrSender *rmrsender.RmrSender, rnibDataService services.RNibDataService) *RanSetupManager {
41 return &RanSetupManager{
43 rnibDataService: rnibDataService,
48 // Update retries and connection status
49 func (m *RanSetupManager) updateConnectionStatus(nodebInfo *entities.NodebInfo, status entities.ConnectionStatus) error {
50 // Update retries and connection status
51 nodebInfo.ConnectionStatus = status
52 nodebInfo.ConnectionAttempts++
53 err := m.rnibDataService.UpdateNodebInfo(nodebInfo)
55 m.logger.Errorf("#RanSetupManager.updateConnectionStatus - Ran name: %s - Failed updating RAN's connection status to %v : %s", nodebInfo.RanName, status, err)
57 m.logger.Infof("#RanSetupManager.updateConnectionStatus - Ran name: %s - Successfully updated rNib. RAN's current connection status: %v, RAN's current connection attempts: %d", nodebInfo.RanName, status, nodebInfo.ConnectionAttempts)
62 // Decrement retries and connection status (disconnected)
63 func (m *RanSetupManager) updateConnectionStatusDisconnected(nodebInfo *entities.NodebInfo) error {
64 // Update retries and connection status
65 nodebInfo.ConnectionStatus = entities.ConnectionStatus_DISCONNECTED
66 nodebInfo.ConnectionAttempts--
67 err := m.rnibDataService.UpdateNodebInfo(nodebInfo)
69 m.logger.Errorf("#RanSetupManager.updateConnectionStatusDisconnected - Ran name: %s - Failed updating RAN's connection status to DISCONNECTED : %s", nodebInfo.RanName, err)
71 m.logger.Infof("#RanSetupManager.updateConnectionStatusDisconnected - Ran name: %s - Successfully updated rNib. RAN's current connection status: DISCONNECTED, RAN's current connection attempts: %d", nodebInfo.RanName, nodebInfo.ConnectionAttempts)
76 func (m *RanSetupManager) prepareSetupRequest(nodebInfo *entities.NodebInfo) (int, *models.E2RequestMessage, error) {
77 // Build the endc/x2 setup request
78 switch nodebInfo.E2ApplicationProtocol {
79 case entities.E2ApplicationProtocol_X2_SETUP_REQUEST:
80 rmrMsgType := rmrCgo.RIC_X2_SETUP_REQ
81 request := models.NewE2RequestMessage(nodebInfo.RanName /*tid*/, nodebInfo.Ip, uint16(nodebInfo.Port), nodebInfo.RanName, e2pdus.PackedX2setupRequest)
82 return rmrMsgType, request, nil
83 case entities.E2ApplicationProtocol_ENDC_X2_SETUP_REQUEST:
84 rmrMsgType := rmrCgo.RIC_ENDC_X2_SETUP_REQ
85 request := models.NewE2RequestMessage(nodebInfo.RanName /*tid*/, nodebInfo.Ip, uint16(nodebInfo.Port), nodebInfo.RanName, e2pdus.PackedEndcX2setupRequest)
86 return rmrMsgType, request, nil
89 m.logger.Errorf("#RanSetupManager.prepareSetupRequest - Unsupported nodebInfo.E2ApplicationProtocol %d ", nodebInfo.E2ApplicationProtocol)
90 return 0, nil, e2managererrors.NewInternalError()
93 // ExecuteSetup updates the connection status and number of attempts in the nodebInfo and send an endc/x2 setup request to establish a connection with the RAN
94 func (m *RanSetupManager) ExecuteSetup(nodebInfo *entities.NodebInfo, status entities.ConnectionStatus) error {
96 // Update retries and connection status
97 if err := m.updateConnectionStatus(nodebInfo, status); err != nil {
98 return e2managererrors.NewRnibDbError()
101 // Build the endc/x2 setup request
102 rmrMsgType, request, err := m.prepareSetupRequest(nodebInfo)
107 // Send the endc/x2 setup request
108 msg := models.NewRmrMessage(rmrMsgType, nodebInfo.RanName, request.GetMessageAsBytes(m.logger))
110 err = m.rmrSender.Send(msg)
113 m.logger.Errorf("#RanSetupManager.ExecuteSetup - failed sending setup request to RMR: %s", err)
115 err := m.updateConnectionStatusDisconnected(nodebInfo)
117 // Decrement retries and connection status (disconnected)
119 return e2managererrors.NewRnibDbError()
122 return e2managererrors.NewRmrError()