diff --git a/consumer/sm_policy.go b/consumer/sm_policy.go index 612d8a64..3dd5cc46 100644 --- a/consumer/sm_policy.go +++ b/consumer/sm_policy.go @@ -44,7 +44,7 @@ func SendSMPolicyAssociationCreate(smContext *smf_context.SMContext) (*models.Sm var smPolicyDecision *models.SmPolicyDecision if smPolicyDecisionFromPCF, _, err := smContext.SMPolicyClient. DefaultApi.SmPoliciesPost(context.Background(), smPolicyData); err != nil { - return nil, fmt.Errorf("setup sm policy association failed: %s", err) + return nil, err } else { smPolicyDecision = &smPolicyDecisionFromPCF } diff --git a/go.mod b/go.mod index 5030bbae..91c8a10c 100644 --- a/go.mod +++ b/go.mod @@ -12,9 +12,9 @@ require ( github.com/free5gc/idgenerator v1.0.0 github.com/free5gc/logger_conf v1.0.0 github.com/free5gc/logger_util v1.0.0 - github.com/free5gc/nas v1.0.0 + github.com/free5gc/nas v1.0.1 github.com/free5gc/ngap v1.0.2 - github.com/free5gc/openapi v1.0.0 + github.com/free5gc/openapi v1.0.1 github.com/free5gc/path_util v1.0.0 github.com/free5gc/pfcp v1.0.1 github.com/free5gc/util_3gpp v1.0.0 diff --git a/go.sum b/go.sum index ea539181..9a9e1390 100644 --- a/go.sum +++ b/go.sum @@ -73,11 +73,15 @@ github.com/free5gc/logger_util v1.0.0 h1:hLTCTnKlEqJURrBwooNFQLavWPdJzS0o9KGIYUN github.com/free5gc/logger_util v1.0.0/go.mod h1:TK/bAJbm/l2TMNmbsKn83+xUmDNqts69IEir/nCa8w0= github.com/free5gc/nas v1.0.0 h1:OO4klCGRhflBrOUMyKfFXwxGu5Sz4B8vYrWtIXA1G9Q= github.com/free5gc/nas v1.0.0/go.mod h1:aZkA9pzIy6D1I4mTYExoUsr1pBwC81+aLvhs382TlD0= +github.com/free5gc/nas v1.0.1 h1:3qOweTX4Ws7y/xKMq7FJ3Is+TlxaXZJCC2qyJ04ITZg= +github.com/free5gc/nas v1.0.1/go.mod h1:XYUq6xLU3iuDxZHZI6vz5MMTBewmOWpJLCtevWW6JfA= github.com/free5gc/ngap v1.0.0/go.mod h1:FIAFElkAuJzusN2kXrCNJlSuCcQid8RZd5qZaf4N7pI= github.com/free5gc/ngap v1.0.2 h1:/89OIJVR0AWdMfiUuoe325RnjlF45UvIFdAxWrrbiYU= github.com/free5gc/ngap v1.0.2/go.mod h1:n9BWKtM58fxSSjvGFbsYlGiB9B3FAqMAi8ckkOP/X4Q= github.com/free5gc/openapi v1.0.0 h1:DaGVt05b1pSDBOailKAlLj6hAk6vunN0Nhzvl/xcWCY= github.com/free5gc/openapi v1.0.0/go.mod h1:7OzxoWBj6KQgznMW2ZiUtZdCGY+t89v4wtgKLhluKgU= +github.com/free5gc/openapi v1.0.1 h1:1KwbQ6/D8U3FEwYv3yr4O4PWpHluXRHj2OOg3TK6dG0= +github.com/free5gc/openapi v1.0.1/go.mod h1:oP4YVkZkJ0KrFnaVjT0XfRPBJdD7O6m4/PEyGtt5l1U= github.com/free5gc/path_util v1.0.0 h1:vJPGTymaWtavz6fJ/7k6WKEYv5BQLAq/O04RP54sab0= github.com/free5gc/path_util v1.0.0/go.mod h1:OpmcebEKrMPnH7Jg5lZ8y9ZWJNAjQ4l9FGWXUv58Mo0= github.com/free5gc/pfcp v1.0.1 h1:btAMuCjUqDjQr+5FBv+3+ZbIouKAZkKeh0MF/TdZ1kc= diff --git a/producer/pdu_session.go b/producer/pdu_session.go index 156c092d..c18d3fe2 100644 --- a/producer/pdu_session.go +++ b/producer/pdu_session.go @@ -105,36 +105,8 @@ func HandlePDUSessionSMContextCreate(request models.PostSmContextsRequest) *http logger.PduSessLog.Warnf("Data Path not found\n") logger.PduSessLog.Warnln("Selection Parameter: ", upfSelectionParams.String()) - var httpResponse *http_wrapper.Response - if buf, err := smf_context. - BuildGSMPDUSessionEstablishmentReject( - smContext, - nasMessage.Cause5GSMInsufficientResourcesForSpecificSliceAndDNN); err != nil { - httpResponse = &http_wrapper.Response{ - Header: nil, - Status: http.StatusForbidden, - Body: models.PostSmContextsErrorResponse{ - JsonData: &models.SmContextCreateError{ - Error: &Nsmf_PDUSession.InsufficientResourceSliceDnn, - N1SmMsg: &models.RefToBinaryData{ContentId: "n1SmMsg"}, - }, - }, - } - } else { - httpResponse = &http_wrapper.Response{ - Header: nil, - Status: http.StatusForbidden, - Body: models.PostSmContextsErrorResponse{ - JsonData: &models.SmContextCreateError{ - Error: &Nsmf_PDUSession.InsufficientResourceSliceDnn, - N1SmMsg: &models.RefToBinaryData{ContentId: "n1SmMsg"}, - }, - BinaryDataN1SmMessage: buf, - }, - } - } - - return httpResponse + return makeErrorResponse(smContext, nasMessage.Cause5GSMInsufficientResourcesForSpecificSliceAndDNN, + &Nsmf_PDUSession.InsufficientResourceSliceDnn) } smContext.PDUAddress = ip smContext.SelectedUPF = selectedUPF @@ -177,7 +149,18 @@ func HandlePDUSessionSMContextCreate(request models.PostSmContextsRequest) *http var smPolicyDecision *models.SmPolicyDecision if smPolicyDecisionRsp, err := consumer.SendSMPolicyAssociationCreate(smContext); err != nil { - logger.PduSessLog.Errorf("") + openapiError := err.(openapi.GenericOpenAPIError) + problemDetails := openapiError.Model().(models.ProblemDetails) + logger.PduSessLog.Errorln("setup sm policy association failed:", err, problemDetails) + smContext.SMContextState = smf_context.InActive + logger.CtxLog.Traceln("SMContextState Change State: ", smContext.SMContextState.String()) + + if problemDetails.Cause == "USER_UNKNOWN" { + return makeErrorResponse(smContext, nasMessage.Cause5GSMRequestRejectedUnspecified, + &Nsmf_PDUSession.SubscriptionDenied) + } else { + return makeErrorResponse(smContext, nasMessage.Cause5GSMNetworkFailure, &Nsmf_PDUSession.NetworkFailure) + } } else { smPolicyDecision = smPolicyDecisionRsp } @@ -217,36 +200,8 @@ func HandlePDUSessionSMContextCreate(request models.PostSmContextsRequest) *http logger.PduSessLog.Warnf("Data Path not found\n") logger.PduSessLog.Warnln("Selection Parameter: ", upfSelectionParams.String()) - var httpResponse *http_wrapper.Response - if buf, err := smf_context. - BuildGSMPDUSessionEstablishmentReject( - smContext, - nasMessage.Cause5GSMInsufficientResourcesForSpecificSliceAndDNN); err != nil { - httpResponse = &http_wrapper.Response{ - Header: nil, - Status: http.StatusForbidden, - Body: models.PostSmContextsErrorResponse{ - JsonData: &models.SmContextCreateError{ - Error: &Nsmf_PDUSession.InsufficientResourceSliceDnn, - N1SmMsg: &models.RefToBinaryData{ContentId: "n1SmMsg"}, - }, - }, - } - } else { - httpResponse = &http_wrapper.Response{ - Header: nil, - Status: http.StatusForbidden, - Body: models.PostSmContextsErrorResponse{ - JsonData: &models.SmContextCreateError{ - Error: &Nsmf_PDUSession.InsufficientResourceSliceDnn, - N1SmMsg: &models.RefToBinaryData{ContentId: "n1SmMsg"}, - }, - BinaryDataN1SmMessage: buf, - }, - } - } - - return httpResponse + return makeErrorResponse(smContext, nasMessage.Cause5GSMInsufficientResourcesForSpecificSliceAndDNN, + &Nsmf_PDUSession.InsufficientResourceSliceDnn) } if problemDetails, err := consumer.SendNFDiscoveryServingAMF(smContext); err != nil { @@ -946,3 +901,37 @@ func releaseTunnel(smContext *smf_context.SMContext) { } } } + +func makeErrorResponse(smContext *smf_context.SMContext, nasErrorCause uint8, + sbiError *models.ProblemDetails) *http_wrapper.Response { + var httpResponse *http_wrapper.Response + + if buf, err := smf_context. + BuildGSMPDUSessionEstablishmentReject( + smContext, + nasErrorCause); err != nil { + httpResponse = &http_wrapper.Response{ + Header: nil, + Status: int(sbiError.Status), + Body: models.PostSmContextsErrorResponse{ + JsonData: &models.SmContextCreateError{ + Error: sbiError, + N1SmMsg: &models.RefToBinaryData{ContentId: "n1SmMsg"}, + }, + }, + } + } else { + httpResponse = &http_wrapper.Response{ + Header: nil, + Status: int(sbiError.Status), + Body: models.PostSmContextsErrorResponse{ + JsonData: &models.SmContextCreateError{ + Error: sbiError, + N1SmMsg: &models.RefToBinaryData{ContentId: "n1SmMsg"}, + }, + BinaryDataN1SmMessage: buf, + }, + } + } + return httpResponse +}