+
+ h.handleSuccessfulResponse(ranName, request, setupRequest)
+}
+
+func (h *E2SetupRequestNotificationHandler) handleUpdateAndPublishNodebInfo(functionsModified bool, ranStatusChangePublished bool, nodebInfo *entities.NodebInfo) error {
+
+ if ranStatusChangePublished || !functionsModified {
+ return nil
+ }
+
+ err := h.rNibDataService.UpdateNodebInfoAndPublish(nodebInfo)
+
+ if err != nil {
+ h.logger.Errorf("#E2SetupRequestNotificationHandler.handleUpdateAndPublishNodebInfo - RAN name: %s - Failed at UpdateNodebInfoAndPublish. error: %s", nodebInfo.RanName, err)
+ return err
+ }
+
+ h.logger.Infof("#E2SetupRequestNotificationHandler.handleUpdateAndPublishNodebInfo - RAN name: %s - Successfully executed UpdateNodebInfoAndPublish", nodebInfo.RanName)
+ return nil
+
+}
+
+func (h *E2SetupRequestNotificationHandler) handleNewRan(ranName string, e2tIpAddress string, setupRequest *models.E2SetupRequestMessage) (*entities.NodebInfo, error) {
+
+ nodebInfo, err := h.buildNodebInfo(ranName, e2tIpAddress, setupRequest)
+ if err != nil {
+ h.logger.Errorf("#E2SetupRequestNotificationHandler.handleNewRan - RAN name: %s - failed building nodebInfo. Error: %s", ranName, err)
+ return nil, err
+ }
+
+ err = h.rNibDataService.SaveNodeb(nodebInfo)
+ if err != nil {
+ h.logger.Errorf("#E2SetupRequestNotificationHandler.handleNewRan - RAN name: %s - failed saving nodebInfo. Error: %s", ranName, err)
+ return nil, err
+ }
+
+ nbIdentity := h.buildNbIdentity(ranName, setupRequest)
+
+ err = h.ranListManager.AddNbIdentity(nodebInfo.GetNodeType(), nbIdentity)
+
+ if err != nil {
+ return nil, err
+ }
+
+ return nodebInfo, nil
+}
+
+func (h *E2SetupRequestNotificationHandler) handleExistingRan(ranName string, nodebInfo *entities.NodebInfo, setupRequest *models.E2SetupRequestMessage) (bool, error) {
+ if nodebInfo.GetConnectionStatus() == entities.ConnectionStatus_SHUTTING_DOWN {
+ h.logger.Errorf("#E2SetupRequestNotificationHandler.Handle - RAN name: %s, connection status: %s - nodeB entity in incorrect state", ranName, nodebInfo.ConnectionStatus)
+ return false, errors.New("nodeB entity in incorrect state")
+ }
+
+ nodebInfo.SetupFromNetwork = true
+
+ if nodebInfo.NodeType == entities.Node_ENB {
+ return false, nil
+ }
+
+ setupMessageRanFuncs := setupRequest.ExtractRanFunctionsList()
+
+ if setupMessageRanFuncs == nil || (len(setupMessageRanFuncs) == 0 && len(nodebInfo.GetGnb().RanFunctions) == 0) {
+ return false, nil
+ }
+
+ nodebInfo.GetGnb().RanFunctions = setupMessageRanFuncs
+ return true, nil
+}
+
+func (h *E2SetupRequestNotificationHandler) handleUnsuccessfulResponse(ranName string, req *models.NotificationRequest, cause models.Cause) {
+ failureResponse := models.NewE2SetupFailureResponseMessage(models.TimeToWaitEnum.V60s, cause)
+ h.logger.Debugf("#E2SetupRequestNotificationHandler.handleUnsuccessfulResponse - E2_SETUP_RESPONSE has been built successfully %+v", failureResponse)
+
+ responsePayload, err := xml.Marshal(&failureResponse.E2APPDU)
+ if err != nil {
+ h.logger.Warnf("#E2SetupRequestNotificationHandler.handleUnsuccessfulResponse - RAN name: %s - Error marshalling RIC_E2_SETUP_RESP. Payload: %s", ranName, responsePayload)
+ }
+
+ responsePayload = utils.ReplaceEmptyTagsWithSelfClosing(responsePayload,emptyTagsToReplaceToSelfClosingTags)
+
+ h.logger.Infof("#E2SetupRequestNotificationHandler.handleUnsuccessfulResponse - payload: %s", responsePayload)
+ msg := models.NewRmrMessage(rmrCgo.RIC_E2_SETUP_FAILURE, ranName, responsePayload, req.TransactionId, req.GetMsgSrc())
+ h.logger.Infof("#E2SetupRequestNotificationHandler.handleUnsuccessfulResponse - RAN name: %s - RIC_E2_SETUP_RESP message has been built successfully. Message: %x", ranName, msg)
+ _ = h.rmrSender.WhSend(msg)
+
+}
+
+func (h *E2SetupRequestNotificationHandler) handleSuccessfulResponse(ranName string, req *models.NotificationRequest, setupRequest *models.E2SetupRequestMessage) {
+
+ plmnId := buildPlmnId(h.config.GlobalRicId.Mcc, h.config.GlobalRicId.Mnc)
+
+ ricNearRtId, err := convertTo20BitString(h.config.GlobalRicId.RicId)
+ if err != nil {
+ return
+ }
+ successResponse := models.NewE2SetupSuccessResponseMessage(plmnId, ricNearRtId, setupRequest)
+ h.logger.Debugf("#E2SetupRequestNotificationHandler.handleSuccessfulResponse - E2_SETUP_RESPONSE has been built successfully %+v", successResponse)