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).
20 package rmrmsghandlers
30 "gerrit.o-ran-sc.org/r/ric-plt/nodeb-rnib.git/entities"
33 type SetupResponseNotificationHandler struct {
35 rnibDataService services.RNibDataService
36 setupResponseManager managers.ISetupResponseManager
37 ranStatusChangeManager managers.IRanStatusChangeManager
41 var msgTypeToMsgName = map[int]string{
42 rmrCgo.RIC_X2_SETUP_RESP: "X2 Setup Response",
43 rmrCgo.RIC_X2_SETUP_FAILURE: "X2 Setup Failure Response",
44 rmrCgo.RIC_ENDC_X2_SETUP_RESP: "ENDC Setup Response",
45 rmrCgo.RIC_ENDC_X2_SETUP_FAILURE: "ENDC Setup Failure Response",
48 func NewSetupResponseNotificationHandler(logger *logger.Logger, rnibDataService services.RNibDataService, setupResponseManager managers.ISetupResponseManager, ranStatusChangeManager managers.IRanStatusChangeManager, msgType int) SetupResponseNotificationHandler {
49 return SetupResponseNotificationHandler{
51 rnibDataService: rnibDataService,
52 setupResponseManager: setupResponseManager,
53 ranStatusChangeManager: ranStatusChangeManager,
58 func (h SetupResponseNotificationHandler) Handle(request *models.NotificationRequest) {
59 msgName := msgTypeToMsgName[h.msgType]
60 h.logger.Infof("#SetupResponseNotificationHandler - RAN name: %s - Received %s notification", request.RanName, msgName)
62 inventoryName := request.RanName
64 nodebInfo, rnibErr := h.rnibDataService.GetNodeb(inventoryName)
67 h.logger.Errorf("#SetupResponseNotificationHandler - RAN name: %s - Error fetching RAN from rNib: %v", request.RanName, rnibErr)
71 if !isConnectionStatusValid(nodebInfo.ConnectionStatus) {
72 h.logger.Errorf("#SetupResponseNotificationHandler - RAN name: %s - Invalid RAN connection status: %s", request.RanName, nodebInfo.ConnectionStatus)
76 nbIdentity := &entities.NbIdentity{InventoryName: inventoryName}
77 err := h.setupResponseManager.PopulateNodebByPdu(h.logger, nbIdentity, nodebInfo, request.Payload)
83 rnibErr = h.rnibDataService.SaveNodeb(nbIdentity, nodebInfo)
86 h.logger.Errorf("#SetupResponseNotificationHandler - RAN name: %s - Error saving RAN to rNib: %v", request.RanName, rnibErr)
90 h.logger.Infof("#SetupResponseNotificationHandler - RAN name: %s - Successfully saved RAN to rNib", request.RanName)
91 h.logger.Infof("#SetupResponseNotificationHandler - Summary: elapsed time for receiving and handling setup response message from E2 terminator: %f ms", utils.ElapsedTime(request.StartTime))
93 if !isSuccessSetupResponseMessage(h.msgType) {
97 _ = h.ranStatusChangeManager.Execute(rmrCgo.RAN_CONNECTED, enums.RIC_TO_RAN, nodebInfo)
100 func isConnectionStatusValid(connectionStatus entities.ConnectionStatus) bool {
101 return connectionStatus == entities.ConnectionStatus_CONNECTING || connectionStatus == entities.ConnectionStatus_CONNECTED
104 func isSuccessSetupResponseMessage(msgType int) bool {
105 return msgType == rmrCgo.RIC_X2_SETUP_RESP || msgType == rmrCgo.RIC_ENDC_X2_SETUP_RESP