X-Git-Url: https://gerrit.o-ran-sc.org/r/gitweb?a=blobdiff_plain;f=E2Manager%2Fhandlers%2Frmrmsghandlers%2Fe2_setup_request_notification_handler.go;h=b2e1633c43522809297721eec752170f46f8ac3f;hb=1de6ad01ae4a10222b07f144509e496eab99da9d;hp=55655134fe793a3304652d072413ad15721dd3d7;hpb=78b376831653b270b743dfccd375e154a4c7a1a7;p=ric-plt%2Fe2mgr.git diff --git a/E2Manager/handlers/rmrmsghandlers/e2_setup_request_notification_handler.go b/E2Manager/handlers/rmrmsghandlers/e2_setup_request_notification_handler.go index 5565513..b2e1633 100644 --- a/E2Manager/handlers/rmrmsghandlers/e2_setup_request_notification_handler.go +++ b/E2Manager/handlers/rmrmsghandlers/e2_setup_request_notification_handler.go @@ -1,6 +1,7 @@ // // Copyright 2019 AT&T Intellectual Property // Copyright 2019 Nokia +// Copyright (c) 2020 Samsung Electronics Co., Ltd. All Rights Reserved. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -29,6 +30,7 @@ import ( "e2mgr/rmrCgo" "e2mgr/services" "e2mgr/services/rmrsender" + "e2mgr/utils" "encoding/xml" "errors" "fmt" @@ -42,17 +44,17 @@ var ( emptyTagsToReplaceToSelfClosingTags = []string{"reject", "ignore", "transport-resource-unavailable", "om-intervention", "request-id-unknown", "v60s", "v20s", "v10s", "v5s", "v2s", "v1s"} gnbTypesMap = map[string]entities.GnbType{ - "gnb":entities.GnbType_GNB, - "en_gnb":entities.GnbType_EN_GNB, + "gnb": entities.GnbType_GNB, + "en_gnb": entities.GnbType_EN_GNB, } enbTypesMap = map[string]entities.EnbType{ - "enB_macro":entities.EnbType_MACRO_ENB, - "enB_home":entities.EnbType_HOME_ENB, - "enB_shortmacro":entities.EnbType_SHORT_MACRO_ENB, - "enB_longmacro":entities.EnbType_LONG_MACRO_ENB, - "ng_enB_macro":entities.EnbType_MACRO_NG_ENB, - "ng_enB_shortmacro":entities.EnbType_SHORT_MACRO_NG_ENB, - "ng_enB_longmacro":entities.EnbType_LONG_MACRO_NG_ENB, + "enB_macro": entities.EnbType_MACRO_ENB, + "enB_home": entities.EnbType_HOME_ENB, + "enB_shortmacro": entities.EnbType_SHORT_MACRO_ENB, + "enB_longmacro": entities.EnbType_LONG_MACRO_ENB, + "ng_enB_macro": entities.EnbType_MACRO_NG_ENB, + "ng_enB_shortmacro": entities.EnbType_SHORT_MACRO_NG_ENB, + "ng_enB_longmacro": entities.EnbType_LONG_MACRO_NG_ENB, } ) @@ -64,7 +66,7 @@ type E2SetupRequestNotificationHandler struct { rNibDataService services.RNibDataService e2tAssociationManager *managers.E2TAssociationManager ranConnectStatusChangeManager managers.IRanConnectStatusChangeManager - ranListManager managers.RanListManager + ranListManager managers.RanListManager } func NewE2SetupRequestNotificationHandler(logger *logger.Logger, config *configuration.Configuration, e2tInstancesManager managers.IE2TInstancesManager, rmrSender *rmrsender.RmrSender, rNibDataService services.RNibDataService, e2tAssociationManager *managers.E2TAssociationManager, ranConnectStatusChangeManager managers.IRanConnectStatusChangeManager, ranListManager managers.RanListManager) *E2SetupRequestNotificationHandler { @@ -76,7 +78,7 @@ func NewE2SetupRequestNotificationHandler(logger *logger.Logger, config *configu rNibDataService: rNibDataService, e2tAssociationManager: e2tAssociationManager, ranConnectStatusChangeManager: ranConnectStatusChangeManager, - ranListManager: ranListManager, + ranListManager: ranListManager, } } @@ -117,12 +119,13 @@ func (h *E2SetupRequestNotificationHandler) Handle(request *models.NotificationR nodebInfo, err := h.rNibDataService.GetNodeb(ranName) + var functionsModified bool + if err != nil { if _, ok := err.(*common.ResourceNotFoundError); !ok { h.logger.Errorf("#E2SetupRequestNotificationHandler.Handle - RAN name: %s - failed to retrieve nodebInfo entity. Error: %s", ranName, err) return - } if nodebInfo, err = h.handleNewRan(ranName, e2tIpAddress, setupRequest); err != nil { @@ -134,26 +137,56 @@ func (h *E2SetupRequestNotificationHandler) Handle(request *models.NotificationR } } else { - if err = h.handleExistingRan(ranName, nodebInfo, setupRequest); err != nil { + + functionsModified, err = h.handleExistingRan(ranName, nodebInfo, setupRequest) + + if err != nil { return } } - err = h.e2tAssociationManager.AssociateRan(e2tIpAddress, nodebInfo) + ranStatusChangePublished, err := h.e2tAssociationManager.AssociateRan(e2tIpAddress, nodebInfo) if err != nil { h.logger.Errorf("#E2SetupRequestNotificationHandler.Handle - RAN name: %s - failed to associate E2T to nodeB entity. Error: %s", ranName, err) if _, ok := err.(*e2managererrors.RoutingManagerError); ok { + + if err = h.handleUpdateAndPublishNodebInfo(functionsModified, ranStatusChangePublished, nodebInfo); err != nil { + return + } + cause := models.Cause{Transport: &models.CauseTransport{TransportResourceUnavailable: &struct{}{}}} h.handleUnsuccessfulResponse(nodebInfo.RanName, request, cause) } return } + if err = h.handleUpdateAndPublishNodebInfo(functionsModified, ranStatusChangePublished, nodebInfo); err != nil { + return + } + 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) @@ -179,26 +212,26 @@ func (h *E2SetupRequestNotificationHandler) handleNewRan(ranName string, e2tIpAd return nodebInfo, nil } -func (h *E2SetupRequestNotificationHandler) setGnbFunctions(nodebInfo *entities.NodebInfo, setupRequest *models.E2SetupRequestMessage) { - if nodebInfo.GetNodeType() == entities.Node_ENB { - return +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") } - ranFunctions := setupRequest.ExtractRanFunctionsList() - if ranFunctions != nil { - nodebInfo.GetGnb().RanFunctions = ranFunctions - } -} + nodebInfo.SetupFromNetwork = true -func (h *E2SetupRequestNotificationHandler) handleExistingRan(ranName string, nodebInfo *entities.NodebInfo, setupRequest *models.E2SetupRequestMessage) 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 errors.New("nodeB entity in incorrect state") + if nodebInfo.NodeType == entities.Node_ENB { + return false, nil } - h.setGnbFunctions(nodebInfo, setupRequest) + setupMessageRanFuncs := setupRequest.ExtractRanFunctionsList() - return h.rNibDataService.UpdateNodebInfo(nodebInfo) + 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) { @@ -210,7 +243,7 @@ func (h *E2SetupRequestNotificationHandler) handleUnsuccessfulResponse(ranName s h.logger.Warnf("#E2SetupRequestNotificationHandler.handleUnsuccessfulResponse - RAN name: %s - Error marshalling RIC_E2_SETUP_RESP. Payload: %s", ranName, responsePayload) } - responsePayload = replaceEmptyTagsWithSelfClosing(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()) @@ -235,7 +268,7 @@ func (h *E2SetupRequestNotificationHandler) handleSuccessfulResponse(ranName str h.logger.Warnf("#E2SetupRequestNotificationHandler.handleSuccessfulResponse - RAN name: %s - Error marshalling RIC_E2_SETUP_RESP. Payload: %s", ranName, responsePayload) } - responsePayload = replaceEmptyTagsWithSelfClosing(responsePayload) + responsePayload = utils.ReplaceEmptyTagsWithSelfClosing(responsePayload,emptyTagsToReplaceToSelfClosingTags) h.logger.Infof("#E2SetupRequestNotificationHandler.handleSuccessfulResponse - payload: %s", responsePayload) @@ -261,21 +294,6 @@ func buildPlmnId(mmc string, mnc string) string { return b.String() } -func replaceEmptyTagsWithSelfClosing(responsePayload []byte) []byte { - - emptyTagVsSelfClosingTagPairs := make([]string, len(emptyTagsToReplaceToSelfClosingTags)*2) - - j := 0 - - for i := 0; i < len(emptyTagsToReplaceToSelfClosingTags); i++ { - emptyTagVsSelfClosingTagPairs[j] = fmt.Sprintf("<%[1]s>", emptyTagsToReplaceToSelfClosingTags[i]) - emptyTagVsSelfClosingTagPairs[j+1] = fmt.Sprintf("<%s/>", emptyTagsToReplaceToSelfClosingTags[i]) - j += 2 - } - responseString := strings.NewReplacer(emptyTagVsSelfClosingTagPairs...).Replace(string(responsePayload)) - return []byte(responseString) -} - func convertTo20BitString(ricNearRtId string) (string, error) { r, err := strconv.ParseUint(ricNearRtId, 16, 32) if err != nil { @@ -299,7 +317,7 @@ func (h *E2SetupRequestNotificationHandler) parseSetupRequest(payload []byte) (* h.logger.Infof("#E2SetupRequestNotificationHandler.parseSetupRequest - payload: %s", payload[pipInd+1:]) setupRequest := &models.E2SetupRequestMessage{} - err := xml.Unmarshal(normalizeXml(payload[pipInd+1:]), &setupRequest.E2APPDU) + err := xml.Unmarshal(utils.NormalizeXml(payload[pipInd+1:]), &setupRequest.E2APPDU) if err != nil { return nil, "", errors.New(fmt.Sprintf("#E2SetupRequestNotificationHandler.parseSetupRequest - Error unmarshalling E2 Setup Request payload: %x", payload)) } @@ -307,24 +325,28 @@ func (h *E2SetupRequestNotificationHandler) parseSetupRequest(payload []byte) (* return setupRequest, e2tIpAddress, nil } -func normalizeXml(payload []byte) []byte { - xmlStr := string(payload) - normalized := strings.NewReplacer("<", "<", ">", ">").Replace(xmlStr) - return []byte(normalized) -} - func (h *E2SetupRequestNotificationHandler) buildNodebInfo(ranName string, e2tAddress string, request *models.E2SetupRequestMessage) (*entities.NodebInfo, error) { nodebInfo := &entities.NodebInfo{ AssociatedE2TInstanceAddress: e2tAddress, RanName: ranName, GlobalNbId: h.buildGlobalNbId(request), - SetupFromNetwork: true, + SetupFromNetwork: true, } err := h.setNodeTypeAndConfiguration(nodebInfo) if err != nil { return nil, err } - h.setGnbFunctions(nodebInfo, request) + + if nodebInfo.NodeType == entities.Node_ENB { + return nodebInfo, nil + } + + ranFuncs := request.ExtractRanFunctionsList() + + if ranFuncs != nil { + nodebInfo.GetGnb().RanFunctions = ranFuncs + } + return nodebInfo, nil }