-
Notifications
You must be signed in to change notification settings - Fork 97
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for UECM Registration and Deregistration for a PDU Session (
#92) * Add support for UECM Registration and Deregistration for a PDU Session * Addressed the suggested comments to change the state in UeCmDeregistration() * fix: ci linter error --------- Co-authored-by: Ian Chen <iancodinghtml@gmail.com>
- Loading branch information
1 parent
4a4b6f4
commit 05c55bb
Showing
4 changed files
with
207 additions
and
4 deletions.
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 | ||
} |