+ err := h.setGnbFunctions(nodebInfo, setupRequest)
+ return err
+}
+
+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 = replaceEmptyTagsWithSelfClosing(responsePayload)
+
+ 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)
+
+ responsePayload, err := xml.Marshal(&successResponse.E2APPDU)
+ if err != nil {
+ h.logger.Warnf("#E2SetupRequestNotificationHandler.handleSuccessfulResponse - RAN name: %s - Error marshalling RIC_E2_SETUP_RESP. Payload: %s", ranName, responsePayload)
+ }
+
+ 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 {
+
+ emptyTagVsSelfClosingTagPairs := make([]string, len(emptyTagsToReplaceToSelfClosingTags)*2)
+
+ j := 0
+
+ for i := 0; i < len(emptyTagsToReplaceToSelfClosingTags); i++ {
+ emptyTagVsSelfClosingTagPairs[j] = fmt.Sprintf("<%[1]s></%[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 {
+ return "", err
+ }
+ return fmt.Sprintf("%020b", r)[:20], nil
+}
+
+func (h *E2SetupRequestNotificationHandler) parseSetupRequest(payload []byte) (*models.E2SetupRequestMessage, string, error) {
+