-
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
Merged
Changes from all commits
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,103 @@ | ||
package consumer | ||
|
||
import ( | ||
"context" | ||
|
||
"github.com/pkg/errors" | ||
|
||
"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" | ||
) | ||
|
||
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 { | ||
smCtx.UeCmRegistered = false | ||
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
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 | ||
} |
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()