Skip to content

Commit

Permalink
fix: remove unuse import and fix return error and type assertion smf …
Browse files Browse the repository at this point in the history
…err response
  • Loading branch information
donald1218 committed Sep 19, 2024
1 parent 40e5d97 commit d036aa7
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 19 deletions.
2 changes: 1 addition & 1 deletion internal/gmm/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
3 changes: 1 addition & 2 deletions internal/sbi/consumer/amf_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand Down Expand Up @@ -303,7 +302,7 @@ func (s *namfService) RegistrationStatusUpdate(ue *amf_context.AmfUe, request mo

res, localErr := client.IndividualUeContextDocumentApi.
RegistrationStatusUpdate(ctx, &regStatusUpdateReq)
if err == nil {
if localErr == nil {
regStatusTransferComplete = res.UeRegStatusUpdateRspData.RegStatusTransferComplete
} else {
if apiErr, ok := localErr.(openapi.GenericOpenAPIError); ok {
Expand Down
4 changes: 2 additions & 2 deletions internal/sbi/consumer/ausf_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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 {
Expand Down
7 changes: 2 additions & 5 deletions internal/sbi/consumer/nrf_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

Expand Down Expand Up @@ -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
}

Expand Down Expand Up @@ -309,7 +306,7 @@ func (s *nnrfService) SendDeregisterNFInstance() (problemDetails *models.Problem
return pd, err
}

request := &NFManagement.DeregisterNFInstanceRequest{
request := &Nnrf_NFManagement.DeregisterNFInstanceRequest{
NfInstanceID: &amfContext.NfId,
}

Expand Down
19 changes: 12 additions & 7 deletions internal/sbi/consumer/smf_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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,
Expand Down Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions internal/util/convert.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down

0 comments on commit d036aa7

Please sign in to comment.