Skip to content

Commit

Permalink
feat: modify for indirect communication
Browse files Browse the repository at this point in the history
  • Loading branch information
mamie1031 committed Jan 17, 2025
1 parent 9341e44 commit dfdc927
Show file tree
Hide file tree
Showing 3 changed files with 90 additions and 0 deletions.
12 changes: 12 additions & 0 deletions internal/context/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,11 @@ type NRFContext struct {
NrfCert *x509.Certificate
NfRegistNum int
nfRegistNumLock sync.RWMutex
ScpUri string
ScpIp string
ScpPortInt int
ScpHasRegister bool
ScpRegisterLock sync.RWMutex
}

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

nrfContext.ModifyScpHasRegister(false)
nrfContext.NrfNfProfile.NfInstanceId = uuid.New().String()
nrfContext.NrfNfProfile.NfType = models.NfType_NRF
nrfContext.NrfNfProfile.NfStatus = models.NfStatus_REGISTERED
Expand Down Expand Up @@ -226,3 +232,9 @@ func (ctx *NRFContext) DelNfRegister() {
defer ctx.nfRegistNumLock.Unlock()
ctx.NfRegistNum -= 1
}

func (ctx *NRFContext) ModifyScpHasRegister(value bool) {
ctx.nfRegistNumLock.Lock()
defer ctx.nfRegistNumLock.Unlock()
ctx.ScpHasRegister = value
}
61 changes: 61 additions & 0 deletions internal/sbi/processor/nf_discovery.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ func validateQueryParameters(queryParameters url.Values) bool {
"BSF": true,
"CHF": true,
"NWDAF": true,
"SCP": true,
}
var tgt, req string
if queryParameters["target-nf-type"] != nil {
Expand Down Expand Up @@ -173,6 +174,66 @@ func (p *Processor) NFDiscoveryProcedure(c *gin.Context, queryParameters url.Val
}
validityPeriod := 100

// Indirect Communication, only the following NF pairs support indirect communication
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"},
}
sourceNF := ""
targetNF := ""
if values, exists := queryParameters["requester-nf-type"]; exists && len(values) > 0 {
sourceNF = values[0]
}
if values, exists := queryParameters["target-nf-type"]; exists && len(values) > 0 {
targetNF = values[0]
}

if validTargets, exists := npPairs[sourceNF]; exists {
for _, validTarget := range validTargets {
if validTarget == targetNF {
supportNFPairForIndirectCommunication = true
}
}
}
if supportNFPairForIndirectCommunication {
logger.DiscLog.Infof(
"Discovery with indirect communication, the message will pass to SCP: [%v]",
ScpUri
)
if len(nfProfilesStruct) > 0 {
for i := range nfProfilesStruct {
nfProfilesStruct[i].Ipv4Addresses[0] = ScpUri

if nfProfilesStruct[i].NfServices != nil {
for j := range *nfProfilesStruct[i].NfServices {
nfService := &(*nfProfilesStruct[i].NfServices)[j]

if nfService.IpEndPoints != nil {
for k := range *nfService.IpEndPoints {
ipEndPoint := &(*nfService.IpEndPoints)[k]
ipEndPoint.Ipv4Address = nrfSelf.ScpIp
ipEndPoint.Port = nrfSelf.ScpPortInt
}
}
// for UDM search
if nfService.ApiPrefix != "" {
nfService.ApiPrefix = nrfSelf.ScpUri
}
}
}
}
}
}
}

// Build SearchResult model
searchResult := &models.SearchResult{
ValidityPeriod: int32(validityPeriod),
Expand Down
17 changes: 17 additions & 0 deletions internal/sbi/processor/nf_management.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,20 @@ 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)
}

p.NFRegisterProcedure(c, nfProfile)
}

Expand Down Expand Up @@ -320,6 +334,9 @@ func (p *Processor) NFDeregisterProcedure(nfInstanceID string) *models.ProblemDe
logger.NfmLog.Warningf("Can not delete NFCertPem file: %v: %v", nfCertPath, removeErr)
}
}
if nfInstanceType == models.NfType_SCP {
nrf_context.GetSelf().ModifyScpHasRegister(false)
}
// Minus NF Register Conter
p.Context().DelNfRegister()
logger.NfmLog.Infof("NfDeregister Success: %v [%v]", nfInstanceType, nfInstanceID)
Expand Down

0 comments on commit dfdc927

Please sign in to comment.