From d036aa7e847bc03f0ed4d4cccf98e6f8a4bfe333 Mon Sep 17 00:00:00 2001 From: donald1218 Date: Thu, 19 Sep 2024 07:30:08 +0000 Subject: [PATCH] fix: remove unuse import and fix return error and type assertion smf err response --- internal/gmm/handler.go | 2 +- internal/sbi/consumer/amf_service.go | 3 +-- internal/sbi/consumer/ausf_service.go | 4 ++-- internal/sbi/consumer/nrf_service.go | 7 ++----- internal/sbi/consumer/smf_service.go | 19 ++++++++++++------- internal/util/convert.go | 4 ++-- 6 files changed, 20 insertions(+), 19 deletions(-) diff --git a/internal/gmm/handler.go b/internal/gmm/handler.go index abf82f3..e40d7a6 100644 --- a/internal/gmm/handler.go +++ b/internal/gmm/handler.go @@ -266,7 +266,7 @@ func CreatePDUSession(ulNasTransport *nasMessage.ULNASTransport, ue.Lock.Lock() defer ue.Lock.Unlock() - _, smContextRef, errResponse, problemDetail, errSendReq := consumer.GetConsumer().SendCreateSmContextRequest( + smContextRef, errResponse, problemDetail, errSendReq := consumer.GetConsumer().SendCreateSmContextRequest( ue, newSmContext, nil, smMessage) if errSendReq != nil { ue.GmmLog.Errorf("CreateSmContextRequest Error: %+v", errSendReq) diff --git a/internal/sbi/consumer/amf_service.go b/internal/sbi/consumer/amf_service.go index 5fab487..164b3b8 100644 --- a/internal/sbi/consumer/amf_service.go +++ b/internal/sbi/consumer/amf_service.go @@ -8,7 +8,6 @@ import ( "github.com/free5gc/amf/internal/logger" "github.com/free5gc/nas/nasMessage" "github.com/free5gc/openapi" - // "github.com/free5gc/openapi/Namf_Communication" Namf_Communication "github.com/free5gc/openapi/amf/Communication" "github.com/free5gc/openapi/models" ) @@ -303,7 +302,7 @@ func (s *namfService) RegistrationStatusUpdate(ue *amf_context.AmfUe, request mo res, localErr := client.IndividualUeContextDocumentApi. RegistrationStatusUpdate(ctx, ®StatusUpdateReq) - if err == nil { + if localErr == nil { regStatusTransferComplete = res.UeRegStatusUpdateRspData.RegStatusTransferComplete } else { if apiErr, ok := localErr.(openapi.GenericOpenAPIError); ok { diff --git a/internal/sbi/consumer/ausf_service.go b/internal/sbi/consumer/ausf_service.go index 181ac2f..8646b0a 100644 --- a/internal/sbi/consumer/ausf_service.go +++ b/internal/sbi/consumer/ausf_service.go @@ -77,7 +77,7 @@ func (s *nausfService) SendUEAuthenticationAuthenticateRequest(ue *amf_context.A } res, localErr := client.DefaultApi.UeAuthenticationsPost(ctx, &authreq) - if err == nil { + if localErr == nil { return &res.UeAuthenticationCtx, nil, nil } else { if apiErr, ok := localErr.(openapi.GenericOpenAPIError); ok { @@ -92,7 +92,7 @@ func (s *nausfService) SendAuth5gAkaConfirmRequest(ue *amf_context.AmfUe, resSta *models.ConfirmationDataResponse, *models.ProblemDetails, error, ) { var ausfUri string - confirmUri, err := url.Parse(ue.AuthenticationCtx.Links["5g-aka"].Href) + confirmUri, err := url.Parse(ue.AuthenticationCtx.Links["5g-aka"][0].Href) if err != nil { return nil, nil, err } else { diff --git a/internal/sbi/consumer/nrf_service.go b/internal/sbi/consumer/nrf_service.go index 9f5e4b3..7c94f86 100644 --- a/internal/sbi/consumer/nrf_service.go +++ b/internal/sbi/consumer/nrf_service.go @@ -14,7 +14,6 @@ import ( "github.com/free5gc/openapi" "github.com/free5gc/openapi/models" Nnrf_NFDiscovery "github.com/free5gc/openapi/nrf/NFDiscovery" - "github.com/free5gc/openapi/nrf/NFManagement" Nnrf_NFManagement "github.com/free5gc/openapi/nrf/NFManagement" ) @@ -87,12 +86,10 @@ func (s *nnrfService) SendSearchNFInstances(nrfUri string, targetNfType, request } res, err := client.NFInstancesStoreApi.SearchNFInstances(ctx, param) var result *models.SearchResult - if res != nil { - result = &res.SearchResult - } if err != nil { logger.ConsumerLog.Errorf("SearchNFInstances failed: %+v", err) } + result = &res.SearchResult return result, err } @@ -309,7 +306,7 @@ func (s *nnrfService) SendDeregisterNFInstance() (problemDetails *models.Problem return pd, err } - request := &NFManagement.DeregisterNFInstanceRequest{ + request := &Nnrf_NFManagement.DeregisterNFInstanceRequest{ NfInstanceID: &amfContext.NfId, } diff --git a/internal/sbi/consumer/smf_service.go b/internal/sbi/consumer/smf_service.go index 41b7c59..0988ed5 100644 --- a/internal/sbi/consumer/smf_service.go +++ b/internal/sbi/consumer/smf_service.go @@ -149,7 +149,7 @@ func (s *nsmfService) SelectSmf( func (s *nsmfService) SendCreateSmContextRequest(ue *amf_context.AmfUe, smContext *amf_context.SmContext, requestType *models.RequestType, nasPdu []byte) ( - response *models.PostSmContextsResponse201, smContextRef string, errorResponse *models.PostSmContextsError, + smContextRef string, errorResponse *models.PostSmContextsError, problemDetail *models.ProblemDetails, err1 error, ) { smContextCreateData := s.buildCreateSmContextRequest(ue, smContext, nil) @@ -163,26 +163,28 @@ func (s *nsmfService) SendCreateSmContextRequest(ue *amf_context.AmfUe, smContex client := s.getPDUSessionClient(smContext.SmfUri()) if client == nil { - return nil, "", nil, nil, openapi.ReportError("smf not found") + return "", nil, nil, openapi.ReportError("smf not found") } ctx, _, err := amf_context.GetSelf().GetTokenCtx(models.ServiceName_NSMF_PDUSESSION, models.NrfNfManagementNfType_SMF) if err != nil { - return nil, "", nil, nil, err + return "", nil, nil, err } postSmContextReponse, localErr := client.SMContextsCollectionApi. PostSmContexts(ctx, &postSmContextsRequest) if localErr == nil { - response = &postSmContextReponse.PostSmContextsResponse201 smContextRef = postSmContextReponse.Location } else { err1 = localErr if apiErr, ok := localErr.(openapi.GenericOpenAPIError); ok { // API error - problemDetail = apiErr.Model().(*models.ProblemDetails) + problemDetail, ok = apiErr.Model().(*models.ProblemDetails) + if !ok { + errorResponse = apiErr.Model().(*models.PostSmContextsError) + } } } - return response, smContextRef, errorResponse, problemDetail, err1 + return smContextRef, errorResponse, problemDetail, err1 } func (s *nsmfService) buildCreateSmContextRequest(ue *amf_context.AmfUe, smContext *amf_context.SmContext, @@ -473,7 +475,10 @@ func (s *nsmfService) SendUpdateSmContextRequest(smContext *amf_context.SmContex err1 = localErr if apiErr, ok := localErr.(openapi.GenericOpenAPIError); ok { // API error - problemDetail = apiErr.Model().(*models.ProblemDetails) + problemDetail, ok = apiErr.Model().(*models.ProblemDetails) + if !ok { + errorResponse = apiErr.Model().(*models.UpdateSmContextResponse400) + } } } return response, errorResponse, problemDetail, err1 diff --git a/internal/util/convert.go b/internal/util/convert.go index 936a9be..794197b 100644 --- a/internal/util/convert.go +++ b/internal/util/convert.go @@ -60,8 +60,8 @@ func PlmnIdStringToModels(plmnId string) (plmnID models.PlmnId) { } func PlmnIdNidToModelsPlmnId(plmnIdNid models.PlmnIdNid) (plmnId models.PlmnId) { - plmnIdNid.Mcc = plmnId.Mcc - plmnIdNid.Mnc = plmnId.Mnc + plmnId.Mcc = plmnIdNid.Mcc + plmnId.Mnc = plmnIdNid.Mnc return }