Skip to content

Commit

Permalink
refactor: add comments based on PR feedback and improve code structure
Browse files Browse the repository at this point in the history
  • Loading branch information
mamie1031 committed Jan 30, 2025
1 parent eeead1e commit a4a63fb
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 24 deletions.
17 changes: 10 additions & 7 deletions internal/context/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,11 @@ type NRFContext struct {
NrfCert *x509.Certificate
NfRegistNum int
nfRegistNumLock sync.RWMutex
ScpUri string
ScpUri string
ScpIp string
ScpPortInt int
ScpHasRegister bool
ScpRegisterLock sync.RWMutex
ScpInfoLock sync.RWMutex
}

const (
Expand All @@ -53,7 +53,7 @@ func InitNrfContext() error {
config.Info.Version, config.Info.Description)
configuration := config.Configuration

nrfContext.ModifyScpHasRegister(false)
nrfContext.ModifyScpIpInfo(false, "", "", -1) // Initiation for SCP info
nrfContext.NrfNfProfile.NfInstanceId = uuid.New().String()
nrfContext.NrfNfProfile.NfType = models.NfType_NRF
nrfContext.NrfNfProfile.NfStatus = models.NfStatus_REGISTERED
Expand Down Expand Up @@ -233,8 +233,11 @@ func (ctx *NRFContext) DelNfRegister() {
ctx.NfRegistNum -= 1
}

func (ctx *NRFContext) ModifyScpHasRegister(value bool) {
ctx.nfRegistNumLock.Lock()
defer ctx.nfRegistNumLock.Unlock()
ctx.ScpHasRegister = value
func (ctx *NRFContext) ModifyScpIpInfo(hasRegister bool, uri string, ip string, port int) {
ctx.ScpInfoLock.Lock()
defer ctx.ScpInfoLock.Unlock()
ctx.ScpHasRegister = hasRegister
ctx.ScpUri = uri
ctx.ScpIp = ip
ctx.ScpPortInt = port
}
19 changes: 10 additions & 9 deletions internal/sbi/processor/nf_discovery.go
Original file line number Diff line number Diff line change
Expand Up @@ -174,18 +174,19 @@ func (p *Processor) NFDiscoveryProcedure(c *gin.Context, queryParameters url.Val
}
validityPeriod := 100

// Indirect Communication, only the following NF pairs support indirect communication
// Indirect communication implementation
nrfSelf := nrf_context.GetSelf()
scpEnable := nrfSelf.ScpHasRegister
if scpEnable {
supportNFPairForIndirectCommunication := false
npPairs := map[string][]string{
"AMF": {"AUSF", "SMF"},
"AUSF": {"UDM", "AMF"},
"UDM": {"UDR", "AUSF"},
"UDR": {"UDM", "NEF"},
"SMF": {"AMF"},
"NEF": {"UDR"},
// Only the following NF pairs support indirect communication
nfPairs := map[string][]string{
"AMF": {"AUSF", "SMF"}, // AMF consumes AUSF, SMF (via SCP)
"AUSF": {"UDM", "AMF"}, // AUSF consumes UDM, AMF
"UDM": {"UDR", "AUSF"}, // UDM consumes UDR, AUSF
"UDR": {"UDM", "NEF"}, // UDR consumes UDM, NEF
"SMF": {"AMF"}, // SMF consumes AMF
"NEF": {"UDR"}, // NEF consumes UDR
}
sourceNF := ""
targetNF := ""
Expand All @@ -196,7 +197,7 @@ func (p *Processor) NFDiscoveryProcedure(c *gin.Context, queryParameters url.Val
targetNF = values[0]
}

if validTargets, exists := npPairs[sourceNF]; exists {
if validTargets, exists := nfPairs[sourceNF]; exists {
for _, validTarget := range validTargets {
if validTarget == targetNF {
supportNFPairForIndirectCommunication = true
Expand Down
11 changes: 3 additions & 8 deletions internal/sbi/processor/nf_management.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,19 +41,14 @@ func (p *Processor) HandleGetNFInstanceRequest(c *gin.Context, nfInstanceId stri

func (p *Processor) HandleNFRegisterRequest(c *gin.Context, nfProfile models.NfProfile) {
logger.NfmLog.Infoln("Handle NFRegisterRequest")

logger.NfmLog.Infof("NfProfile: %v", nfProfile)
// Set ScpUri for support indirect communication
// TODO: Support multiple SCP situation (This version only support for a single SCP)
if nfProfile.NfType == models.NfType_SCP {
nrfSelf := nrf_context.GetSelf()
nrfSelf.ModifyScpHasRegister(true)
ScpIp := nfProfile.Ipv4Addresses[0]
ScpUri := "http://" + ScpIp + ":8000" // default port
nrfSelf.ScpUri = ScpUri
nrfSelf.ScpIp = ScpIp
nrfSelf.ScpPortInt = 8000
logger.NfmLog.Infof("Recieve SCP register request, ScpUri: %v", ScpUri)
nrfSelf.ModifyScpIpInfo(true, ScpUri, ScpIp, 8000)
logger.NfmLog.Infof("Receive SCP register request, ScpUri: %v", ScpUri)
}

p.NFRegisterProcedure(c, nfProfile)
Expand Down Expand Up @@ -335,7 +330,7 @@ func (p *Processor) NFDeregisterProcedure(nfInstanceID string) *models.ProblemDe
}
}
if nfInstanceType == models.NfType_SCP {
nrf_context.GetSelf().ModifyScpHasRegister(false)
nrf_context.GetSelf().ModifyScpIpInfo(false, "", "", -1)
}
// Minus NF Register Conter
p.Context().DelNfRegister()
Expand Down

0 comments on commit a4a63fb

Please sign in to comment.