[RIC-306] Fix globalRicId properties type
[ric-plt/e2mgr.git] / E2Manager / handlers / rmrmsghandlers / e2_setup_request_notification_handler.go
index 9ea0ef5..d65516c 100644 (file)
@@ -133,14 +133,12 @@ func (h E2SetupRequestNotificationHandler) handleNewRan(ranName string, e2tIpAdd
 }
 
 func (h E2SetupRequestNotificationHandler) setGnbFunctions(nodebInfo *entities.NodebInfo, setupRequest *models.E2SetupRequestMessage) error {
-       ranFunctions, err := setupRequest.ExtractRanFunctionsList()
+       ranFunctions := setupRequest.ExtractRanFunctionsList()
 
-       if err != nil {
-               h.logger.Errorf("#E2SetupRequestNotificationHandler.setGnbFunctions - RAN name: %s - failed to update nodebInfo entity. Error: %s", nodebInfo.GetRanName(), err)
-               return err
+       if ranFunctions != nil {
+               nodebInfo.GetGnb().RanFunctions = ranFunctions
        }
 
-       nodebInfo.GetGnb().RanFunctions = ranFunctions
        return nil
 }
 
@@ -165,6 +163,8 @@ func (h E2SetupRequestNotificationHandler) handleUnsuccessfulResponse(nodebInfo
 
        responsePayload = replaceEmptyTagsWithSelfClosing(responsePayload)
 
+       h.logger.Infof("#E2SetupRequestNotificationHandler.handleUnsuccessfulResponse - payload: %s", responsePayload)
+
        msg := models.NewRmrMessage(rmrCgo.RIC_E2_SETUP_FAILURE, nodebInfo.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", nodebInfo.RanName, msg)
        _ = h.rmrSender.WhSend(msg)
@@ -173,12 +173,13 @@ func (h E2SetupRequestNotificationHandler) handleUnsuccessfulResponse(nodebInfo
 
 func (h E2SetupRequestNotificationHandler) handleSuccessfulResponse(ranName string, req *models.NotificationRequest, setupRequest *models.E2SetupRequestMessage) {
 
-       ricNearRtId, err := convertTo20BitString(h.config.GlobalRicId.RicNearRtId)
+       plmnId := buildPlmnId(h.config.GlobalRicId.Mcc, h.config.GlobalRicId.Mnc)
+
+       ricNearRtId, err := convertTo20BitString(h.config.GlobalRicId.RicId)
        if err != nil {
-               h.logger.Errorf("#E2SetupRequestNotificationHandler.handleSuccessfulResponse - RAN name: %s - failed to convert RicNearRtId value %s to 20 bit string . Error: %s", ranName, h.config.GlobalRicId.RicNearRtId, err)
                return
        }
-       successResponse := models.NewE2SetupSuccessResponseMessage(h.config.GlobalRicId.PlmnId, ricNearRtId, setupRequest)
+       successResponse := models.NewE2SetupSuccessResponseMessage(plmnId, ricNearRtId, setupRequest)
        h.logger.Debugf("#E2SetupRequestNotificationHandler.handleSuccessfulResponse - E2_SETUP_RESPONSE has been built successfully %+v", successResponse)
 
        responsePayload, err := xml.Marshal(&successResponse.E2APPDU)
@@ -188,11 +189,30 @@ func (h E2SetupRequestNotificationHandler) handleSuccessfulResponse(ranName stri
 
        responsePayload = replaceEmptyTagsWithSelfClosing(responsePayload)
 
+       h.logger.Infof("#E2SetupRequestNotificationHandler.handleSuccessfulResponse - payload: %s", responsePayload)
+
        msg := models.NewRmrMessage(rmrCgo.RIC_E2_SETUP_RESP, ranName, responsePayload, req.TransactionId, req.GetMsgSrc())
        h.logger.Infof("#E2SetupRequestNotificationHandler.handleSuccessfulResponse - RAN name: %s - RIC_E2_SETUP_RESP message has been built successfully. Message: %x", ranName, msg)
        _ = h.rmrSender.Send(msg)
 }
 
+func buildPlmnId(mmc string, mnc string) string{
+       var b strings.Builder
+
+       b.WriteByte(mmc[1])
+       b.WriteByte(mmc[0])
+       if len(mnc) == 2 {
+               b.WriteString("F")
+       } else {
+               b.WriteByte(mnc[2])
+       }
+       b.WriteByte(mmc[2])
+       b.WriteByte(mnc[1])
+       b.WriteByte(mnc[0])
+
+       return b.String()
+}
+
 func replaceEmptyTagsWithSelfClosing(responsePayload []byte) []byte {
        responseString := strings.NewReplacer(
                "<reject></reject>", "<reject/>",
@@ -231,7 +251,7 @@ func (h E2SetupRequestNotificationHandler) parseSetupRequest(payload []byte) (*m
        h.logger.Infof("#E2SetupRequestNotificationHandler.parseSetupRequest - payload: %s", payload[pipInd+1:])
 
        setupRequest := &models.E2SetupRequestMessage{}
-       err := xml.Unmarshal(payload[pipInd+1:], &setupRequest.E2APPDU)
+       err := xml.Unmarshal(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))
        }
@@ -239,6 +259,12 @@ func (h E2SetupRequestNotificationHandler) parseSetupRequest(payload []byte) (*m
        return setupRequest, e2tIpAddress, nil
 }
 
+func normalizeXml(payload []byte) []byte {
+       xmlStr := string(payload)
+       normalized := strings.NewReplacer("&lt;", "<", "&gt;", ">").Replace(xmlStr)
+       return []byte(normalized)
+}
+
 func (h E2SetupRequestNotificationHandler) buildNodebInfo(ranName string, e2tAddress string, request *models.E2SetupRequestMessage) (*entities.NodebInfo, error) {
 
        var err error
@@ -248,7 +274,7 @@ func (h E2SetupRequestNotificationHandler) buildNodebInfo(ranName string, e2tAdd
                RanName:                      ranName,
                NodeType:                     entities.Node_GNB,
                Configuration:                &entities.NodebInfo_Gnb{Gnb: &entities.Gnb{}},
-               GlobalNbId: h.buildGlobalNbId(request),
+               GlobalNbId:                   h.buildGlobalNbId(request),
        }
 
        err = h.setGnbFunctions(nodebInfo, request)
@@ -265,6 +291,6 @@ func (h E2SetupRequestNotificationHandler) buildGlobalNbId(setupRequest *models.
 func (h E2SetupRequestNotificationHandler) buildNbIdentity(ranName string, setupRequest *models.E2SetupRequestMessage) *entities.NbIdentity {
        return &entities.NbIdentity{
                InventoryName: ranName,
-               GlobalNbId: h.buildGlobalNbId(setupRequest),
+               GlobalNbId:    h.buildGlobalNbId(setupRequest),
        }
 }