-
Notifications
You must be signed in to change notification settings - Fork 97
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
+207
−4
Merged
Changes from 1 commit
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
package consumer | ||
|
||
import ( | ||
"context" | ||
|
||
"github.com/free5gc/openapi" | ||
"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) | ||
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, | ||
" 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) | ||
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 { | ||
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") | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -184,14 +184,14 @@ | |
smContext.SMPolicyID = smPolicyID | ||
|
||
// Update SessionRule from decision | ||
if err := smContext.ApplySessionRules(smPolicyDecision); err != nil { | ||
smContext.Log.Errorf("PDUSessionSMContextCreate err: %v", err) | ||
return makeEstRejectResAndReleaseSMContext(smContext, | ||
nasMessage.Cause5GSMRequestRejectedUnspecified, | ||
&Nsmf_PDUSession.SubscriptionDenied) | ||
} | ||
|
||
if err := smContext.SelectDefaultDataPath(); err != nil { | ||
smContext.SetState(smf_context.InActive) | ||
smContext.Log.Errorf("PDUSessionSMContextCreate err: %v", err) | ||
return makeEstRejectResAndReleaseSMContext(smContext, | ||
|
@@ -199,10 +199,20 @@ | |
&Nsmf_PDUSession.InsufficientResourceSliceDnn) | ||
} | ||
|
||
if err := smContext.ApplyPccRules(smPolicyDecision); err != nil { | ||
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 | ||
|
@@ -230,7 +240,6 @@ | |
Status: http.StatusCreated, | ||
Body: response, | ||
} | ||
// TODO: UECM registration | ||
} | ||
|
||
func HandlePDUSessionSMContextUpdate(smContextRef string, body models.UpdateSmContextRequest) *httpwrapper.Response { | ||
|
@@ -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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. should change the state in There was a problem hiding this comment. Choose a reason for hiding this commentThe 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() | ||
|
@@ -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) | ||
} | ||
|
@@ -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) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
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()