Skip to content

Commit

Permalink
fix: SearchNFInstances failed and AUSF terminate problem
Browse files Browse the repository at this point in the history
  • Loading branch information
TYuan0816 committed Oct 24, 2024
1 parent 4e6d3b2 commit d7c12e2
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 33 deletions.
41 changes: 28 additions & 13 deletions internal/sbi/consumer/nrf_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,29 +100,35 @@ func (s *nnrfService) SendSearchNFInstances(
return &result, err
}

func (s *nnrfService) SendDeregisterNFInstance() (err error) {
logger.ConsumerLog.Infof("Send Deregister NFInstance")
func (s *nnrfService) SendDeregisterNFInstance() (*models.ProblemDetails, error) {
logger.ConsumerLog.Infof("[AUSF] Send Deregister NFInstance")

ctx, _, err := ausf_context.GetSelf().GetTokenCtx(models.ServiceName_NNRF_NFM, models.NrfNfManagementNfType_NRF)
ctx, pd, err := ausf_context.GetSelf().GetTokenCtx(models.ServiceName_NNRF_NFM, models.NrfNfManagementNfType_NRF)
if err != nil {
return err
return pd, err
}

ausfContext := s.consumer.Context()
client := s.getNFManagementClient(ausfContext.NrfUri)
request := &Nnrf_NFManagement.DeregisterNFInstanceRequest{
NfInstanceID: &ausfContext.NfId,
}

var derigisterNfInstanceRequest Nnrf_NFManagement.DeregisterNFInstanceRequest
derigisterNfInstanceRequest.NfInstanceID = &ausfContext.NfId
_, err = client.NFInstanceIDDocumentApi.DeregisterNFInstance(ctx, &derigisterNfInstanceRequest)

return err
_, err = client.NFInstanceIDDocumentApi.DeregisterNFInstance(ctx, request)
if apiErr, ok := err.(openapi.GenericOpenAPIError); ok {
// API error
if deregNfError, okDeg := apiErr.Model().(Nnrf_NFManagement.DeregisterNFInstanceError); okDeg {
return &deregNfError.ProblemDetails, err
}
return nil, err
}
return nil, err
}

func (s *nnrfService) RegisterNFInstance(ctx context.Context) (
resouceNrfUri string, retrieveNfInstanceID string, err error,
) {
ausfContext := s.consumer.Context()

client := s.getNFManagementClient(ausfContext.NrfUri)
nfProfile, err := s.buildNfProfile(ausfContext)
if err != nil {
Expand All @@ -136,6 +142,11 @@ func (s *nnrfService) RegisterNFInstance(ctx context.Context) (
NrfNfManagementNfProfile: &nfProfile,
}
for {
select {
case <-ctx.Done():
return "", "", errors.Errorf("Context Cancel before RegisterNFInstance")
default:
}
res, err = client.NFInstanceIDDocumentApi.RegisterNFInstance(ctx, registerNFInstanceRequest)
if err != nil || res == nil {
logger.ConsumerLog.Errorf("AUSF register to NRF Error[%v]", err)
Expand Down Expand Up @@ -204,14 +215,18 @@ func (s *nnrfService) buildNfProfile(ausfContext *ausf_context.AUSFContext) (

func (s *nnrfService) GetUdmUrl(nrfUri string) string {
udmUrl := "https://localhost:29503" // default
nfDiscoverParam := &Nnrf_NFDiscovery.SearchNFInstancesRequest{
ServiceNames: []models.ServiceName{models.ServiceName_NUDM_UEAU},
targetNfType := models.NrfNfManagementNfType_UDM
requestNfType := models.NrfNfManagementNfType_AUSF
nfDiscoverParam := Nnrf_NFDiscovery.SearchNFInstancesRequest{
RequesterNfType: &requestNfType,
TargetNfType: &targetNfType,
ServiceNames: []models.ServiceName{models.ServiceName_NUDM_UEAU},
}
res, err := s.SendSearchNFInstances(
nrfUri,
models.NrfNfManagementNfType_UDM,
models.NrfNfManagementNfType_AUSF,
*nfDiscoverParam,
nfDiscoverParam,
)
if err != nil {
logger.ConsumerLog.Errorln("[Search UDM UEAU] ", err.Error(), "use defalt udmUrl", udmUrl)
Expand Down
28 changes: 8 additions & 20 deletions pkg/service/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@ import (
"github.com/free5gc/ausf/internal/sbi/processor"
"github.com/free5gc/ausf/pkg/app"
"github.com/free5gc/ausf/pkg/factory"
"github.com/free5gc/openapi"
"github.com/free5gc/openapi/nrf/NFManagement"
)

var AUSF *AusfApp
Expand Down Expand Up @@ -166,25 +164,15 @@ func (a *AusfApp) terminateProcedure() {
a.CallServerStop()

// deregister with NRF
err := a.Consumer().SendDeregisterNFInstance()
if err != nil {
switch apiErr := err.(type) {
case openapi.GenericOpenAPIError:
switch errModel := apiErr.Model().(type) {
case NFManagement.DeregisterNFInstanceError:
pd := &errModel.ProblemDetails
logger.InitLog.Errorf("Deregister NF instance Failed Problem[%+v]", pd)
case error:
logger.InitLog.Errorf("Deregister NF instance Error[%+v]", err)
}
case error:
logger.InitLog.Errorf("Deregister NF instance Error[%+v]", err)
}
problemDetails, err := a.Consumer().SendDeregisterNFInstance()
if problemDetails != nil {
logger.MainLog.Errorf("Deregister NF instance Failed Problem[%+v]", problemDetails)
} else if err != nil {
logger.MainLog.Errorf("Deregister NF instance Error[%+v]", err)
} else {
logger.MainLog.Infof("Deregister from NRF successfully")
}

logger.MainLog.Infof("Deregister from NRF successfully")

logger.MainLog.Infof("AUSF SBI Server terminated")
logger.MainLog.Infof("CHF SBI Server terminated")
}

func (a *AusfApp) CallServerStop() {
Expand Down

0 comments on commit d7c12e2

Please sign in to comment.