Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for UECM Registration and Deregistration for a PDU Session #92

Merged
merged 3 commits into from
Jan 17, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions internal/context/sm_context.go
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,8 @@ type SMContext struct {
// State
state SMContextState

UeCmRegistered bool

// Loggers
Log *logrus.Entry

Expand Down
98 changes: 98 additions & 0 deletions internal/sbi/consumer/ue_context_management.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
package consumer

import (
"context"

"github.com/free5gc/openapi"

Check failure on line 6 in internal/sbi/consumer/ue_context_management.go

View workflow job for this annotation

GitHub Actions / lint (1.18)

Expected 'p', Found 'f' at internal/sbi/consumer/ue_context_management.go[line 6,col 14] (gci)
"github.com/free5gc/openapi/Nudm_UEContextManagement"
"github.com/free5gc/openapi/models"
smf_context "github.com/free5gc/smf/internal/context"
"github.com/free5gc/smf/internal/logger"
"github.com/free5gc/smf/internal/util"
"github.com/pkg/errors"
)

func UeCmRegistration(smCtx *smf_context.SMContext) (
*models.ProblemDetails, error,
) {
uecmUri := util.SearchNFServiceUri(smf_context.GetSelf().UDMProfile, models.ServiceName_NUDM_UECM, models.NfServiceStatus_REGISTERED)

Check failure on line 18 in internal/sbi/consumer/ue_context_management.go

View workflow job for this annotation

GitHub Actions / lint (1.18)

line is 134 characters (lll)
if uecmUri == "" {
return nil, errors.Errorf("SMF can not select an UDM by NRF: SearchNFServiceUri failed")
}

configuration := Nudm_UEContextManagement.NewConfiguration()
configuration.SetBasePath(uecmUri)
client := Nudm_UEContextManagement.NewAPIClient(configuration)

registrationData := models.SmfRegistration{
SmfInstanceId: smf_context.GetSelf().NfInstanceID,
SupportedFeatures: "",
PduSessionId: smCtx.PduSessionId,
SingleNssai: smCtx.SNssai,
Dnn: smCtx.Dnn,
EmergencyServices: false,
PcscfRestorationCallbackUri: "",
PlmnId: smCtx.Guami.PlmnId,
PgwFqdn: "",
}

logger.PduSessLog.Infoln("UECM Registration SmfInstanceId:", registrationData.SmfInstanceId, " PduSessionId:", registrationData.PduSessionId,

Check failure on line 39 in internal/sbi/consumer/ue_context_management.go

View workflow job for this annotation

GitHub Actions / lint (1.18)

line is 142 characters (lll)
" SNssai:", registrationData.SingleNssai, " Dnn:", registrationData.Dnn, " PlmnId:", registrationData.PlmnId)

_, httpResp, localErr := client.SMFRegistrationApi.SmfRegistrationsPduSessionId(context.Background(),
smCtx.Supi, smCtx.PduSessionId, registrationData)
defer func() {
if httpResp != nil {
if rspCloseErr := httpResp.Body.Close(); rspCloseErr != nil {
logger.PduSessLog.Errorf("UeCmRegistration response body cannot close: %+v",
rspCloseErr)
}
}
}()

if localErr == nil {
smCtx.UeCmRegistered = true
return nil, nil
} else if httpResp != nil {
if httpResp.Status != localErr.Error() {
return nil, localErr
}
problem := localErr.(openapi.GenericOpenAPIError).Model().(models.ProblemDetails)
return &problem, nil
} else {
return nil, openapi.ReportError("server no response")
}
}

func UeCmDeregistration(smCtx *smf_context.SMContext) (*models.ProblemDetails, error) {
uecmUri := util.SearchNFServiceUri(smf_context.GetSelf().UDMProfile, models.ServiceName_NUDM_UECM, models.NfServiceStatus_REGISTERED)

Check failure on line 68 in internal/sbi/consumer/ue_context_management.go

View workflow job for this annotation

GitHub Actions / lint (1.18)

line is 134 characters (lll)
if uecmUri == "" {
return nil, errors.Errorf("SMF can not select an UDM by NRF: SearchNFServiceUri failed")
}

configuration := Nudm_UEContextManagement.NewConfiguration()
configuration.SetBasePath(uecmUri)
client := Nudm_UEContextManagement.NewAPIClient(configuration)

httpResp, localErr := client.SMFDeregistrationApi.Deregistration(context.Background(),
smCtx.Supi, smCtx.PduSessionId)
defer func() {
if httpResp != nil {
if rspCloseErr := httpResp.Body.Close(); rspCloseErr != nil {
logger.ConsumerLog.Errorf("UeCmDeregistration response body cannot close: %+v",
rspCloseErr)
}
}
}()
if localErr == nil {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

smCtx.UeCmRegistered = false

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, As suggested, updated the state in the UeCmDeregistration()

return nil, nil
} else if httpResp != nil {
if httpResp.Status != localErr.Error() {
return nil, localErr
}
problem := localErr.(openapi.GenericOpenAPIError).Model().(models.ProblemDetails)
return &problem, nil
} else {
return nil, openapi.ReportError("server no response")
}
}
53 changes: 52 additions & 1 deletion internal/sbi/producer/pdu_session.go
Original file line number Diff line number Diff line change
Expand Up @@ -184,14 +184,14 @@
smContext.SMPolicyID = smPolicyID

// Update SessionRule from decision
if err := smContext.ApplySessionRules(smPolicyDecision); err != nil {

Check failure on line 187 in internal/sbi/producer/pdu_session.go

View workflow job for this annotation

GitHub Actions / lint (1.18)

shadow: declaration of "err" shadows declaration at line 168 (govet)
smContext.Log.Errorf("PDUSessionSMContextCreate err: %v", err)
return makeEstRejectResAndReleaseSMContext(smContext,
nasMessage.Cause5GSMRequestRejectedUnspecified,
&Nsmf_PDUSession.SubscriptionDenied)
}

if err := smContext.SelectDefaultDataPath(); err != nil {

Check failure on line 194 in internal/sbi/producer/pdu_session.go

View workflow job for this annotation

GitHub Actions / lint (1.18)

shadow: declaration of "err" shadows declaration at line 168 (govet)
smContext.SetState(smf_context.InActive)
smContext.Log.Errorf("PDUSessionSMContextCreate err: %v", err)
return makeEstRejectResAndReleaseSMContext(smContext,
Expand All @@ -199,10 +199,20 @@
&Nsmf_PDUSession.InsufficientResourceSliceDnn)
}

if err := smContext.ApplyPccRules(smPolicyDecision); err != nil {

Check failure on line 202 in internal/sbi/producer/pdu_session.go

View workflow job for this annotation

GitHub Actions / lint (1.18)

shadow: declaration of "err" shadows declaration at line 168 (govet)
smContext.Log.Errorf("apply sm policy decision error: %+v", err)
}

// UECM registration
problemDetails, err := consumer.UeCmRegistration(smContext)
if problemDetails != nil {
smContext.Log.Errorf("UECM_Registration Error: %+v", problemDetails)
} else if err != nil {
smContext.Log.Errorf("UECM_Registration Error: %+v", err)
} else {
smContext.Log.Traceln("UECM Registration Successful")
}

// generate goroutine to handle PFCP and
// reply PDUSessionSMContextCreate rsp immediately
needUnlock = false
Expand Down Expand Up @@ -230,7 +240,6 @@
Status: http.StatusCreated,
Body: response,
}
// TODO: UECM registration
}

func HandlePDUSessionSMContextUpdate(smContextRef string, body models.UpdateSmContextRequest) *httpwrapper.Response {
Expand Down Expand Up @@ -314,6 +323,20 @@
}
}

if smContext.UeCmRegistered {
problemDetails, err := consumer.UeCmDeregistration(smContext)
if problemDetails != nil {
if problemDetails.Cause != "CONTEXT_NOT_FOUND" {
logger.PduSessLog.Errorf("UECM_DeRegistration Failed Problem[%+v]", problemDetails)
}
} else if err != nil {
logger.PduSessLog.Errorf("UECM_DeRegistration Error[%+v]", err)
} else {
logger.PduSessLog.Traceln("UECM_DeRegistration successful")
}
smContext.UeCmRegistered = false
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should change the state in UeCmDeregistration()

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks. Removed the code duplication and set the state inside UeCmDeregistration()

}

cause := nasMessage.Cause5GSMRegularDeactivation
if m.PDUSessionReleaseRequest.Cause5GSM != nil {
cause = m.PDUSessionReleaseRequest.Cause5GSM.GetCauseValue()
Expand Down Expand Up @@ -859,6 +882,20 @@
}
}

if smContext.UeCmRegistered {
problemDetails, err := consumer.UeCmDeregistration(smContext)
if problemDetails != nil {
if problemDetails.Cause != "CONTEXT_NOT_FOUND" {
logger.PduSessLog.Errorf("UECM_DeRegistration Failed Problem[%+v]", problemDetails)
}
} else if err != nil {
logger.PduSessLog.Errorf("UECM_DeRegistration Error[%+v]", err)
} else {
logger.PduSessLog.Traceln("UECM_DeRegistration successful")
}
smContext.UeCmRegistered = false
}

if !smContext.CheckState(smf_context.InActive) {
smContext.SetState(smf_context.PFCPModification)
}
Expand Down Expand Up @@ -945,6 +982,20 @@
}
}

if smContext.UeCmRegistered {
problemDetails, err := consumer.UeCmDeregistration(smContext)
if problemDetails != nil {
if problemDetails.Cause != "CONTEXT_NOT_FOUND" {
logger.PduSessLog.Errorf("UECM_DeRegistration Failed Problem[%+v]", problemDetails)
}
} else if err != nil {
logger.PduSessLog.Errorf("UECM_DeRegistration Error[%+v]", err)
} else {
logger.PduSessLog.Traceln("UECM_DeRegistration successful")
}
smContext.UeCmRegistered = false
}

smContext.SetState(smf_context.PFCPModification)

pfcpResponseStatus := releaseSession(smContext)
Expand Down
50 changes: 50 additions & 0 deletions internal/util/search_nf_service.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
package util

import (
"fmt"

"github.com/free5gc/openapi/models"
)

func SearchNFServiceUri(nfProfile models.NfProfile, serviceName models.ServiceName,
nfServiceStatus models.NfServiceStatus,
) (nfUri string) {
if nfProfile.NfServices != nil {
for _, service := range *nfProfile.NfServices {
if service.ServiceName == serviceName && service.NfServiceStatus == nfServiceStatus {
if nfProfile.Fqdn != "" {
nfUri = nfProfile.Fqdn
} else if service.Fqdn != "" {
nfUri = service.Fqdn
} else if service.ApiPrefix != "" {
nfUri = service.ApiPrefix
} else if service.IpEndPoints != nil {
point := (*service.IpEndPoints)[0]
if point.Ipv4Address != "" {
nfUri = getSbiUri(service.Scheme, point.Ipv4Address, point.Port)
} else if len(nfProfile.Ipv4Addresses) != 0 {
nfUri = getSbiUri(service.Scheme, nfProfile.Ipv4Addresses[0], point.Port)
}
}
}
if nfUri != "" {
break
}
}
}
return
}

func getSbiUri(scheme models.UriScheme, ipv4Address string, port int32) (uri string) {
if port != 0 {
uri = fmt.Sprintf("%s://%s:%d", scheme, ipv4Address, port)
} else {
switch scheme {
case models.UriScheme_HTTP:
uri = fmt.Sprintf("%s://%s:80", scheme, ipv4Address)
case models.UriScheme_HTTPS:
uri = fmt.Sprintf("%s://%s:443", scheme, ipv4Address)
}
}
return
}
Loading