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=b71129f3b59e346d662938e553e395230a0b84cb;hb=refs%2Fchanges%2F83%2F3383%2F1;hp=603458e7e5013b41d882ba91791c29aef4f5ad79;hpb=a75da9a56d61ca4754650d44a54bbf0b04f610d1;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 603458e..b71129f 100644
--- a/E2Manager/handlers/rmrmsghandlers/e2_setup_request_notification_handler.go
+++ b/E2Manager/handlers/rmrmsghandlers/e2_setup_request_notification_handler.go
@@ -21,6 +21,8 @@ package rmrmsghandlers
import (
"bytes"
+ "e2mgr/configuration"
+ "e2mgr/e2managererrors"
"e2mgr/logger"
"e2mgr/managers"
"e2mgr/models"
@@ -33,19 +35,23 @@ import (
"fmt"
"gerrit.o-ran-sc.org/r/ric-plt/nodeb-rnib.git/common"
"gerrit.o-ran-sc.org/r/ric-plt/nodeb-rnib.git/entities"
+ "strconv"
+ "strings"
)
type E2SetupRequestNotificationHandler struct {
logger *logger.Logger
+ config *configuration.Configuration
e2tInstancesManager managers.IE2TInstancesManager
rmrSender *rmrsender.RmrSender
rNibDataService services.RNibDataService
e2tAssociationManager *managers.E2TAssociationManager
}
-func NewE2SetupRequestNotificationHandler(logger *logger.Logger, e2tInstancesManager managers.IE2TInstancesManager, rmrSender *rmrsender.RmrSender, rNibDataService services.RNibDataService, e2tAssociationManager *managers.E2TAssociationManager) E2SetupRequestNotificationHandler {
+func NewE2SetupRequestNotificationHandler(logger *logger.Logger, config *configuration.Configuration, e2tInstancesManager managers.IE2TInstancesManager, rmrSender *rmrsender.RmrSender, rNibDataService services.RNibDataService, e2tAssociationManager *managers.E2TAssociationManager) E2SetupRequestNotificationHandler {
return E2SetupRequestNotificationHandler{
logger: logger,
+ config: config,
e2tInstancesManager: e2tInstancesManager,
rmrSender: rmrSender,
rNibDataService: rNibDataService,
@@ -55,7 +61,7 @@ func NewE2SetupRequestNotificationHandler(logger *logger.Logger, e2tInstancesMan
func (h E2SetupRequestNotificationHandler) Handle(request *models.NotificationRequest){
ranName := request.RanName
- h.logger.Infof("#E2SetupRequestNotificationHandler.Handle - RAN name: %s - received E2 Setup Request. Payload: %x", ranName, request.Payload)
+ h.logger.Infof("#E2SetupRequestNotificationHandler.Handle - RAN name: %s - received E2_SETUP_REQUEST. Payload: %x", ranName, request.Payload)
setupRequest, e2tIpAddress, err := h.parseSetupRequest(request.Payload)
if err != nil {
@@ -64,6 +70,7 @@ func (h E2SetupRequestNotificationHandler) Handle(request *models.NotificationRe
}
h.logger.Infof("#E2SetupRequestNotificationHandler.Handle - E2T Address: %s - handling E2_SETUP_REQUEST", e2tIpAddress)
+ h.logger.Debugf("#E2SetupRequestNotificationHandler.Handle - E2_SETUP_REQUEST has been parsed successfully %+v", setupRequest)
_, err = h.e2tInstancesManager.GetE2TInstance(e2tIpAddress)
@@ -76,7 +83,11 @@ func (h E2SetupRequestNotificationHandler) Handle(request *models.NotificationRe
if err != nil{
if _, ok := err.(*common.ResourceNotFoundError); ok{
nbIdentity := h.buildNbIdentity(ranName, setupRequest)
- nodebInfo = h.buildNodebInfo(ranName, e2tIpAddress, setupRequest)
+ nodebInfo, err = h.buildNodebInfo(ranName, e2tIpAddress, setupRequest)
+ if err != nil{
+ h.logger.Errorf("#E2SetupRequestNotificationHandler.Handle - RAN name: %s - failed to build nodebInfo entity. Error: %s", ranName, err)
+ return
+ }
err = h.rNibDataService.SaveNodeb(nbIdentity, nodebInfo)
if err != nil{
h.logger.Errorf("#E2SetupRequestNotificationHandler.Handle - RAN name: %s - failed to save nodebInfo entity. Error: %s", ranName, err)
@@ -93,66 +104,121 @@ func (h E2SetupRequestNotificationHandler) Handle(request *models.NotificationRe
h.logger.Infof("#E2SetupRequestNotificationHandler.Handle - Summary: elapsed time for receiving and handling setup request message from E2 terminator: %f ms", utils.ElapsedTime(request.StartTime))
return
}
- h.updateNodeBFunctions(nodebInfo, setupRequest)
+ nodebInfo.GetGnb().RanFunctions, err = setupRequest.GetExtractRanFunctionsList()
+ if err != nil{
+ h.logger.Errorf("#E2SetupRequestNotificationHandler.Handle - RAN name: %s - failed to update nodebInfo entity. Error: %s", ranName, err)
+ return
+ }
}
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{
+ h.handleUnsuccessfulResponse(nodebInfo, request)
+ }
return
}
- successResponse := &models.E2SetupSuccessResponseMessage{}
- successResponse.SetPlmnId(setupRequest.GetPlmnId())
- successResponse.SetNbId("&" + fmt.Sprintf("%020b", 0xf0))
- responsePayload, err := xml.Marshal(successResponse)
+ h.handleSuccessfulResponse(ranName, request, setupRequest)
+}
+
+func (h E2SetupRequestNotificationHandler) handleUnsuccessfulResponse(nodebInfo *entities.NodebInfo, req *models.NotificationRequest){
+ failureResponse := models.NewE2SetupFailureResponseMessage(models.TimeToWaitEnum.V60s)
+ 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.Handle - RAN name: %s - Error marshalling E2 Setup Response. Response: %x", ranName, responsePayload)
+ h.logger.Warnf("#E2SetupRequestNotificationHandler.handleUnsuccessfulResponse - RAN name: %s - Error marshalling RIC_E2_SETUP_RESP. Payload: %s", nodebInfo.RanName, responsePayload)
}
- msg := models.NewRmrMessage(rmrCgo.RIC_E2_SETUP_RESP, ranName, responsePayload, request.TransactionId)
- h.logger.Infof("#E2SetupRequestNotificationHandler.Handle - RAN name: %s - E2 Setup Request has been built. Message: %x", ranName, msg)
- //TODO err = h.rmrSender.Send(msg)
+
+ responsePayload = replaceEmptyTagsWithSelfClosing(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)
}
-func (h E2SetupRequestNotificationHandler) parseSetupRequest(payload []byte)(*models.E2SetupRequestMessage, string, error){
+func (h E2SetupRequestNotificationHandler) handleSuccessfulResponse(ranName string, req *models.NotificationRequest, setupRequest *models.E2SetupRequestMessage){
- colonInd := bytes.IndexByte(payload, ':')
- if colonInd < 0 {
- return nil, "", errors.New("#E2SetupRequestNotificationHandler.parseSetupRequest - Error parsing E2 Setup Request, failed extract E2T IP Address: no ':' separator found")
+ ricNearRtId, err := convertTo20BitString(h.config.GlobalRicId.RicNearRtId)
+ 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)
+ h.logger.Debugf("#E2SetupRequestNotificationHandler.handleSuccessfulResponse - E2_SETUP_RESPONSE has been built successfully %+v", successResponse)
- e2tIpAddress := string(payload[:colonInd])
- if len(e2tIpAddress) == 0 {
- return nil, "", errors.New("#E2SetupRequestNotificationHandler.parseSetupRequest - Empty E2T Address received")
+ 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)
+
+ 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 replaceEmptyTagsWithSelfClosing(responsePayload []byte) []byte {
+ responseString := strings.NewReplacer(
+ "", "",
+ "", "",
+ "", "",
+ "", "",
+ "", "",
+ "", "",
+ "", "",
+ "", "",
+ "", "",
+ ).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){
+
pipInd := bytes.IndexByte(payload, '|')
if pipInd < 0 {
return nil, "", errors.New( "#E2SetupRequestNotificationHandler.parseSetupRequest - Error parsing E2 Setup Request failed extract Payload: no | separator found")
}
+ e2tIpAddress := string(payload[:pipInd])
+ if len(e2tIpAddress) == 0 {
+ return nil, "", errors.New("#E2SetupRequestNotificationHandler.parseSetupRequest - Empty E2T Address received")
+ }
setupRequest := &models.E2SetupRequestMessage{}
- err := xml.Unmarshal(payload[pipInd + 1:], &setupRequest)
+ err := xml.Unmarshal(payload[pipInd + 1:], &setupRequest.E2APPDU)
if err != nil {
- return nil, "", errors.New("#E2SetupRequestNotificationHandler.parseSetupRequest - Error unmarshalling E2 Setup Request payload: %s")
+ return nil, "", errors.New(fmt.Sprintf("#E2SetupRequestNotificationHandler.parseSetupRequest - Error unmarshalling E2 Setup Request payload: %x", payload))
}
return setupRequest, e2tIpAddress, nil
}
-func (h E2SetupRequestNotificationHandler) updateNodeBFunctions(nodeB *entities.NodebInfo, request *models.E2SetupRequestMessage){
- //TODO the function should be implemented in the scope of the US 192 "Save the entire Setup request in RNIB"
-}
-
-func (h E2SetupRequestNotificationHandler) buildNodebInfo(ranName string, e2tAddress string, request *models.E2SetupRequestMessage) *entities.NodebInfo{
+func (h E2SetupRequestNotificationHandler) buildNodebInfo(ranName string, e2tAddress string, request *models.E2SetupRequestMessage) (*entities.NodebInfo, error){
+ var err error
nodebInfo := &entities.NodebInfo{
AssociatedE2TInstanceAddress: e2tAddress,
ConnectionStatus: entities.ConnectionStatus_CONNECTED,
RanName: ranName,
NodeType: entities.Node_GNB,
Configuration: &entities.NodebInfo_Gnb{Gnb: &entities.Gnb{}},
+ GlobalNbId: &entities.GlobalNbId{
+ PlmnId: request.GetPlmnId(),
+ NbId: request.GetNbId(),
+ },
}
- h.updateNodeBFunctions(nodebInfo, request)
- return nodebInfo
+ nodebInfo.GetGnb().RanFunctions, err = request.GetExtractRanFunctionsList()
+ return nodebInfo, err
}
func (h E2SetupRequestNotificationHandler) buildNbIdentity(ranName string, setupRequest *models.E2SetupRequestMessage)*entities.NbIdentity{