Skip to content

Commit

Permalink
fix: get client check not nil
Browse files Browse the repository at this point in the history
  • Loading branch information
andy89923 committed Apr 25, 2024
1 parent 3a37c66 commit bc8b9c7
Show file tree
Hide file tree
Showing 9 changed files with 114 additions and 30 deletions.
7 changes: 3 additions & 4 deletions internal/gmm/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,10 @@ import (
"github.com/pkg/errors"

"github.com/free5gc/amf/internal/context"
gmm_common "github.com/free5gc/amf/internal/gmm/common"
gmm_message "github.com/free5gc/amf/internal/gmm/message"
"github.com/free5gc/amf/internal/logger"
ngap_message "github.com/free5gc/amf/internal/ngap/message"
"github.com/free5gc/amf/internal/sbi/producer/callback"
"github.com/free5gc/amf/internal/util"
"github.com/free5gc/amf/pkg/factory"
Expand All @@ -33,10 +36,6 @@ import (
"github.com/free5gc/openapi/Nnrf_NFDiscovery"
"github.com/free5gc/openapi/models"
"github.com/free5gc/util/fsm"

gmm_common "github.com/free5gc/amf/internal/gmm/common"
gmm_message "github.com/free5gc/amf/internal/gmm/message"
ngap_message "github.com/free5gc/amf/internal/ngap/message"
)

const psiArraySize = 16
Expand Down
16 changes: 15 additions & 1 deletion internal/sbi/consumer/amf_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,9 @@ func (s *namfService) BuildUeContextModel(ue *amf_context.AmfUe) (ueContext mode
return ueContext
}

func (s *namfService) buildAmPolicyReqTriggers(triggers []models.RequestTrigger) (amPolicyReqTriggers []models.AmPolicyReqTrigger) {
func (s *namfService) buildAmPolicyReqTriggers(
triggers []models.RequestTrigger,
) (amPolicyReqTriggers []models.AmPolicyReqTrigger) {
for _, trigger := range triggers {
switch trigger {
case models.RequestTrigger_LOC_CH:
Expand All @@ -148,6 +150,9 @@ func (s *namfService) CreateUEContextRequest(ue *amf_context.AmfUe, ueContextCre
ueContextCreatedData *models.UeContextCreatedData, problemDetails *models.ProblemDetails, err error,
) {
client := s.getComClient(ue.TargetAmfUri)
if client == nil {
return nil, nil, openapi.ReportError("amf not found")
}

req := models.CreateUeContextRequest{
JsonData: &ueContextCreateData,
Expand Down Expand Up @@ -185,6 +190,9 @@ func (s *namfService) ReleaseUEContextRequest(ue *amf_context.AmfUe, ngapCause m
problemDetails *models.ProblemDetails, err error,
) {
client := s.getComClient(ue.TargetAmfUri)
if client == nil {
return nil, openapi.ReportError("amf not found")
}

var ueContextId string
if ue.Supi != "" {
Expand Down Expand Up @@ -234,6 +242,9 @@ func (s *namfService) UEContextTransferRequest(
ueContextTransferRspData *models.UeContextTransferRspData, problemDetails *models.ProblemDetails, err error,
) {
client := s.getComClient(ue.TargetAmfUri)
if client == nil {
return nil, nil, openapi.ReportError("amf not found")
}

ueContextTransferReqData := models.UeContextTransferReqData{
Reason: transferReason,
Expand Down Expand Up @@ -289,6 +300,9 @@ func (s *namfService) RegistrationStatusUpdate(ue *amf_context.AmfUe, request mo
regStatusTransferComplete bool, problemDetails *models.ProblemDetails, err error,
) {
client := s.getComClient(ue.TargetAmfUri)
if client == nil {
return false, nil, openapi.ReportError("amf not found")
}

ueContextId := fmt.Sprintf("5g-guti-%s", ue.Guti)

Expand Down
6 changes: 6 additions & 0 deletions internal/sbi/consumer/ausf_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,9 @@ func (s *nausfService) SendAuth5gAkaConfirmRequest(ue *amf_context.AmfUe, resSta
}

client := s.getUEAuthenticationClient(ausfUri)
if client == nil {
return nil, nil, openapi.ReportError("ausf not found")
}

confirmData := &Nausf_UEAuthentication.UeAuthenticationsAuthCtxId5gAkaConfirmationPutParamOpts{
ConfirmationData: optional.NewInterface(models.ConfirmationData{
Expand Down Expand Up @@ -154,6 +157,9 @@ func (s *nausfService) SendEapAuthConfirmRequest(ue *amf_context.AmfUe, eapMsg n
ausfUri := fmt.Sprintf("%s://%s", confirmUri.Scheme, confirmUri.Host)

client := s.getUEAuthenticationClient(ausfUri)
if client == nil {
return nil, nil, openapi.ReportError("ausf not found")
}

eapSessionReq := &Nausf_UEAuthentication.EapAuthMethodParamOpts{
EapSession: optional.NewInterface(models.EapSession{
Expand Down
16 changes: 12 additions & 4 deletions internal/sbi/consumer/nrf_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,9 @@ func (s *nnrfService) SendSearchNFInstances(nrfUri string, targetNfType, request
) (*models.SearchResult, error) {
// Set client and set url
client := s.getNFDiscClient(nrfUri)
if client == nil {
return nil, openapi.ReportError("nrf not found")
}

ctx, _, err := amf_context.GetSelf().GetTokenCtx(models.ServiceName_NNRF_DISC, models.NfType_NRF)
if err != nil {
Expand Down Expand Up @@ -238,6 +241,9 @@ func (s *nnrfService) SendRegisterNFInstance(nrfUri, nfInstanceId string, profil
) {
// Set client and set url
client := s.getNFManagementClient(nrfUri)
if client == nil {
return "", "", openapi.ReportError("nrf not found")
}

var res *http.Response
var nf models.NfProfile
Expand Down Expand Up @@ -290,16 +296,18 @@ func (s *nnrfService) SendRegisterNFInstance(nrfUri, nfInstanceId string, profil

func (s *nnrfService) SendDeregisterNFInstance() (problemDetails *models.ProblemDetails, err error) {
logger.ConsumerLog.Infof("[AMF] Send Deregister NFInstance")
amfContext := s.consumer.amf.Context()

client := s.getNFManagementClient(amfContext.NrfUri)
if client == nil {
return nil, openapi.ReportError("nrf not found")
}

ctx, pd, err := amf_context.GetSelf().GetTokenCtx(models.ServiceName_NNRF_NFM, models.NfType_NRF)
if err != nil {
return pd, err
}

amfContext := s.consumer.amf.Context()
// Set client and set url
client := s.getNFManagementClient(amfContext.NrfUri)

var res *http.Response

res, err = client.NFInstanceIDDocumentApi.DeregisterNFInstance(ctx, amfContext.NfId)
Expand Down
6 changes: 6 additions & 0 deletions internal/sbi/consumer/nssf_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,9 @@ func (s *nssfService) NSSelectionGetForRegistration(ue *amf_context.AmfUe, reque
*models.ProblemDetails, error,
) {
client := s.getNSSelectionClient(ue.NssfUri)
if client == nil {
return nil, openapi.ReportError("nssf not found")
}

amfSelf := amf_context.GetSelf()
ctx, _, err := amf_context.GetSelf().GetTokenCtx(models.ServiceName_NNSSF_NSSELECTION, models.NfType_NSSF)
Expand Down Expand Up @@ -107,6 +110,9 @@ func (s *nssfService) NSSelectionGetForPduSession(ue *amf_context.AmfUe, snssai
*models.AuthorizedNetworkSliceInfo, *models.ProblemDetails, error,
) {
client := s.getNSSelectionClient(ue.NssfUri)
if client == nil {
return nil, nil, openapi.ReportError("nssf not found")
}

amfSelf := amf_context.GetSelf()
sliceInfoForPduSession := models.SliceInfoForPduSession{
Expand Down
22 changes: 17 additions & 5 deletions internal/sbi/consumer/pcf_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,13 @@ func (s *npcfService) getAMPolicyClient(uri string) *Npcf_AMPolicy.APIClient {
return client
}

func (s *npcfService) AMPolicyControlCreate(ue *amf_context.AmfUe, anType models.AccessType) (*models.ProblemDetails, error) {
func (s *npcfService) AMPolicyControlCreate(
ue *amf_context.AmfUe, anType models.AccessType,
) (*models.ProblemDetails, error) {
client := s.getAMPolicyClient(ue.PcfUri)

if client == nil {
return nil, openapi.ReportError("pcf not found")
}
amfSelf := amf_context.GetSelf()
ctx, _, err := amf_context.GetSelf().GetTokenCtx(models.ServiceName_NPCF_AM_POLICY_CONTROL, models.NfType_PCF)
if err != nil {
Expand Down Expand Up @@ -112,10 +116,14 @@ func (s *npcfService) AMPolicyControlCreate(ue *amf_context.AmfUe, anType models
return nil, nil
}

func (s *npcfService) AMPolicyControlUpdate(ue *amf_context.AmfUe, updateRequest models.PolicyAssociationUpdateRequest) (
problemDetails *models.ProblemDetails, err error,
) {
func (s *npcfService) AMPolicyControlUpdate(
ue *amf_context.AmfUe, updateRequest models.PolicyAssociationUpdateRequest,
) (problemDetails *models.ProblemDetails, err error) {
client := s.getAMPolicyClient(ue.PcfUri)
if client == nil {
return nil, openapi.ReportError("pcf not found")
}

ctx, _, err := amf_context.GetSelf().GetTokenCtx(models.ServiceName_NPCF_AM_POLICY_CONTROL, models.NfType_PCF)
if err != nil {
return nil, err
Expand Down Expand Up @@ -164,6 +172,10 @@ func (s *npcfService) AMPolicyControlUpdate(ue *amf_context.AmfUe, updateRequest

func (s *npcfService) AMPolicyControlDelete(ue *amf_context.AmfUe) (problemDetails *models.ProblemDetails, err error) {
client := s.getAMPolicyClient(ue.PcfUri)
if client == nil {
return nil, openapi.ReportError("pcf not found")
}

ctx, _, err := amf_context.GetSelf().GetTokenCtx(models.ServiceName_NPCF_AM_POLICY_CONTROL, models.NfType_PCF)
if err != nil {
return nil, err
Expand Down
11 changes: 10 additions & 1 deletion internal/sbi/consumer/smf_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import (
"github.com/free5gc/amf/internal/logger"
"github.com/free5gc/amf/internal/util"
"github.com/free5gc/amf/pkg/factory"

"github.com/free5gc/nas/nasMessage"
"github.com/free5gc/openapi"
"github.com/free5gc/openapi/Nnrf_NFDiscovery"
Expand Down Expand Up @@ -159,6 +158,10 @@ func (s *nsmfService) SendCreateSmContextRequest(ue *amf_context.AmfUe, smContex
}

client := s.getPDUSessionClient(smContext.SmfUri())
if client == nil {
return nil, "", nil, nil, openapi.ReportError("smf not found")
}

ctx, _, err := amf_context.GetSelf().GetTokenCtx(models.ServiceName_NSMF_PDUSESSION, models.NfType_SMF)
if err != nil {
return nil, "", nil, nil, err
Expand Down Expand Up @@ -459,6 +462,9 @@ func (s *nsmfService) SendUpdateSmContextRequest(smContext *amf_context.SmContex
problemDetail *models.ProblemDetails, err1 error,
) {
client := s.getPDUSessionClient(smContext.SmfUri())
if client == nil {
return nil, nil, nil, openapi.ReportError("smf not found")
}

var updateSmContextRequest models.UpdateSmContextRequest
updateSmContextRequest.JsonData = &updateData
Expand Down Expand Up @@ -508,6 +514,9 @@ func (s *nsmfService) SendReleaseSmContextRequest(ue *amf_context.AmfUe, smConte
n2Info []byte,
) (detail *models.ProblemDetails, err error) {
client := s.getPDUSessionClient(smContext.SmfUri())
if client == nil {
return nil, openapi.ReportError("smf not found")
}

releaseData := s.buildReleaseSmContextRequest(ue, cause, n2SmInfoType, n2Info)
releaseSmContextRequest := models.ReleaseSmContextRequest{
Expand Down
47 changes: 39 additions & 8 deletions internal/sbi/consumer/udm_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,9 @@ func (s *nudmService) getUEContextMngmntClient(uri string) *Nudm_UEContextManage

func (s *nudmService) PutUpuAck(ue *amf_context.AmfUe, upuMacIue string) error {
client := s.getSubscriberDMngmntClients(ue.NudmSDMUri)
if client == nil {
return openapi.ReportError("udm not found")
}

ctx, _, err := amf_context.GetSelf().GetTokenCtx(models.ServiceName_NUDM_SDM, models.NfType_UDM)
if err != nil {
Expand Down Expand Up @@ -98,6 +101,9 @@ func (s *nudmService) PutUpuAck(ue *amf_context.AmfUe, upuMacIue string) error {

func (s *nudmService) SDMGetAmData(ue *amf_context.AmfUe) (problemDetails *models.ProblemDetails, err error) {
client := s.getSubscriberDMngmntClients(ue.NudmSDMUri)
if client == nil {
return nil, openapi.ReportError("udm not found")
}

getAmDataParamOpt := Nudm_SubscriberDataManagement.GetAmDataParamOpts{
PlmnId: optional.NewInterface(openapi.MarshToJsonString(ue.PlmnId)),
Expand Down Expand Up @@ -136,6 +142,9 @@ func (s *nudmService) SDMGetAmData(ue *amf_context.AmfUe) (problemDetails *model

func (s *nudmService) SDMGetSmfSelectData(ue *amf_context.AmfUe) (problemDetails *models.ProblemDetails, err error) {
client := s.getSubscriberDMngmntClients(ue.NudmSDMUri)
if client == nil {
return nil, openapi.ReportError("udm not found")
}

paramOpt := Nudm_SubscriberDataManagement.GetSmfSelectDataParamOpts{
PlmnId: optional.NewInterface(openapi.MarshToJsonString(ue.PlmnId)),
Expand Down Expand Up @@ -172,8 +181,13 @@ func (s *nudmService) SDMGetSmfSelectData(ue *amf_context.AmfUe) (problemDetails
return problemDetails, err
}

func (s *nudmService) SDMGetUeContextInSmfData(ue *amf_context.AmfUe) (problemDetails *models.ProblemDetails, err error) {
func (s *nudmService) SDMGetUeContextInSmfData(
ue *amf_context.AmfUe,
) (problemDetails *models.ProblemDetails, err error) {
client := s.getSubscriberDMngmntClients(ue.NudmSDMUri)
if client == nil {
return nil, openapi.ReportError("udm not found")
}

ctx, _, err := amf_context.GetSelf().GetTokenCtx(models.ServiceName_NUDM_SDM, models.NfType_UDM)
if err != nil {
Expand Down Expand Up @@ -208,6 +222,9 @@ func (s *nudmService) SDMGetUeContextInSmfData(ue *amf_context.AmfUe) (problemDe

func (s *nudmService) SDMSubscribe(ue *amf_context.AmfUe) (problemDetails *models.ProblemDetails, err error) {
client := s.getSubscriberDMngmntClients(ue.NudmSDMUri)
if client == nil {
return nil, openapi.ReportError("udm not found")
}

amfSelf := amf_context.GetSelf()
sdmSubscription := models.SdmSubscription{
Expand Down Expand Up @@ -246,8 +263,13 @@ func (s *nudmService) SDMSubscribe(ue *amf_context.AmfUe) (problemDetails *model
return problemDetails, err
}

func (s *nudmService) SDMGetSliceSelectionSubscriptionData(ue *amf_context.AmfUe) (problemDetails *models.ProblemDetails, err error) {
func (s *nudmService) SDMGetSliceSelectionSubscriptionData(
ue *amf_context.AmfUe,
) (problemDetails *models.ProblemDetails, err error) {
client := s.getSubscriberDMngmntClients(ue.NudmSDMUri)
if client == nil {
return nil, openapi.ReportError("udm not found")
}

paramOpt := Nudm_SubscriberDataManagement.GetNssaiParamOpts{
PlmnId: optional.NewInterface(openapi.MarshToJsonString(ue.PlmnId)),
Expand Down Expand Up @@ -304,6 +326,9 @@ func (s *nudmService) SDMGetSliceSelectionSubscriptionData(ue *amf_context.AmfUe

func (s *nudmService) SDMUnsubscribe(ue *amf_context.AmfUe) (problemDetails *models.ProblemDetails, err error) {
client := s.getSubscriberDMngmntClients(ue.NudmSDMUri)
if client == nil {
return nil, openapi.ReportError("udm not found")
}

ctx, _, err := amf_context.GetSelf().GetTokenCtx(models.ServiceName_NUDM_SDM, models.NfType_UDM)
if err != nil {
Expand Down Expand Up @@ -334,10 +359,13 @@ func (s *nudmService) SDMUnsubscribe(ue *amf_context.AmfUe) (problemDetails *mod
return problemDetails, err
}

func (s *nudmService) UeCmRegistration(ue *amf_context.AmfUe, accessType models.AccessType, initialRegistrationInd bool) (
*models.ProblemDetails, error,
) {
func (s *nudmService) UeCmRegistration(
ue *amf_context.AmfUe, accessType models.AccessType, initialRegistrationInd bool,
) (*models.ProblemDetails, error) {
client := s.getUEContextMngmntClient(ue.NudmUECMUri)
if client == nil {
return nil, openapi.ReportError("udm not found")
}

amfSelf := amf_context.GetSelf()
ctx, _, err := amf_context.GetSelf().GetTokenCtx(models.ServiceName_NUDM_UEAU, models.NfType_UDM)
Expand Down Expand Up @@ -419,10 +447,13 @@ func (s *nudmService) UeCmRegistration(ue *amf_context.AmfUe, accessType models.
return nil, nil
}

func (s *nudmService) UeCmDeregistration(ue *amf_context.AmfUe, accessType models.AccessType) (
*models.ProblemDetails, error,
) {
func (s *nudmService) UeCmDeregistration(
ue *amf_context.AmfUe, accessType models.AccessType,
) (*models.ProblemDetails, error) {
client := s.getUEContextMngmntClient(ue.NudmUECMUri)
if client == nil {
return nil, openapi.ReportError("udm not found")
}

amfSelf := amf_context.GetSelf()
ctx, _, err := amf_context.GetSelf().GetTokenCtx(models.ServiceName_NUDM_UECM, models.NfType_UDM)
Expand Down
13 changes: 6 additions & 7 deletions pkg/service/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,8 @@ type AmfApp struct {

consumer *consumer.Consumer

// ngap
start func(*AmfApp)
stop func(*AmfApp)
start func(*AmfApp)
terminate func(*AmfApp)
}

var AMF App
Expand All @@ -45,9 +44,9 @@ func GetApp() App {

func NewApp(cfg *factory.Config, startFunc, terminateFunc func(*AmfApp)) (*AmfApp, error) {
amf := &AmfApp{
cfg: cfg,
start: startFunc,
stop: terminateFunc,
cfg: cfg,
start: startFunc,
terminate: terminateFunc,
}
amf.SetLogEnable(cfg.GetLogEnable())
amf.SetLogLevel(cfg.GetLogLevel())
Expand Down Expand Up @@ -119,7 +118,7 @@ func (a *AmfApp) Start(tlsKeyLogPath string) {
func (a *AmfApp) Terminate() {
logger.InitLog.Infof("Terminating AMF...")
a.cancel()
a.stop(a)
a.terminate(a)
logger.InitLog.Infof("AMF terminated")
}

Expand Down

0 comments on commit bc8b9c7

Please sign in to comment.